ArrowRight :: 0x27;
ArrowDown :: 0x28;
- Space :: 0x32;
+ Space :: 0x20;
A :: 0x41; B; C; D; E; F; G; H; I; J; K; L; M; N; O; P; Q; R; S; T; U; V; W; X; Y; Z;
}
use package quad_tree
use package aabb
-NUM_QUADS :: 1 << 17
+NUM_QUADS :: 1 << 14
RenderContext :: struct {
quad_renderer: ^QuadRenderer;
quad_scratch_buffer : [512 * 1024] u8;
+simulating := true;
update :: proc () {
input.preupdate(^input_state);
defer input.postupdate(^input_state);
poll_events();
- quad_scratch : ScratchState;
- quad_alloc : Allocator;
- scratch_state_init(^quad_scratch, ~~quad_scratch_buffer, 128 * 1024);
- scratch_alloc_init(^quad_alloc, ^quad_scratch);
+ if input.key_just_down(^input_state, Key.Space) do simulating = !simulating;
- quadtree_init(^dude_tree, AABB.{ 0.0f, 0.0f, ~~window_width, ~~window_height });
- for ^d: dudes do quadtree_insert(^dude_tree, d, quad_alloc);
+ if simulating {
+ quad_scratch : ScratchState;
+ quad_alloc : Allocator;
+ scratch_state_init(^quad_scratch, ~~quad_scratch_buffer, 512 * 1024);
+ scratch_alloc_init(^quad_alloc, ^quad_scratch);
- for ^d: dudes do dude_update(d, ^dude_tree);
- for ^d: dudes {
- if d.can_move_x do d.pos.x += d.vel.x;
- else do d.vel.x = -d.vel.x;
- if d.can_move_y do d.pos.y += d.vel.y;
- else do d.vel.y = -d.vel.y;
+ quadtree_init(^dude_tree, AABB.{ 0.0f, 0.0f, ~~window_width, ~~window_height });
+ for ^d: dudes do quadtree_insert(^dude_tree, d, quad_alloc);
+
+ for ^d: dudes do dude_update(d, ^dude_tree);
+ for ^d: dudes {
+ if !d.can_move_x do d.vel.x = -d.vel.x;
+ if !d.can_move_y do d.vel.y = -d.vel.y;
+
+ d.pos.x += d.vel.x;
+ d.pos.y += d.vel.y;
+ }
}
}
}
draw_quad_tree :: proc (qt: ^QuadTree($T), level := 0, corner := 0) {
- col := cast(f32) (0.2f + 0.15f * ~~level);
+ col := cast(f32) (0.0f + ~~ qt.points_count * 0.25f);
if col > 1.0f do col = 1.0f;
color := Color4f32.{ 0.0f, 0.0f, 0.0f, 1.0f };
input.init(^input_state);
array_init(^dudes);
- for i: 0 .. 500 {
+ for i: 0 .. 2500 {
array_push(^dudes, dude_create_random());
}
dude_create_random :: proc () -> Dude {
return Dude.{
- pos = V2f.{ random_float(0.0f, 300.0f), random_float(0.0f, 300.0f) },
+ pos = V2f.{ random_float(0.0f, 1000.0f), random_float(0.0f, 1000.0f) },
vel = V2f.{ random_float(-3.0f, 3.0f), random_float(-3.0f, 3.0f) },
size = random_float(2.0f, 3.0f),
color = Dude_Color_Table[random_between(0, 3)],
other_aabb := dude_get_aabb(other);
if aabb_intersects(dude_aabb, other_aabb) {
- // printf("COLLISION\n");
collided = true;
break;
}
use package aabb
#private_file
-QUAD_TREE_ENTITY_STORAGE :: 2;
+QUAD_TREE_MAX_POINTS :: 4;
QuadTree :: struct ($T) {
region : AABB;
- points : [QUAD_TREE_ENTITY_STORAGE] ^T;
+ points : [QUAD_TREE_MAX_POINTS] ^T;
points_count : u32 = 0;
nw: ^QuadTree(T) = null;
for ^p: qt.points do *p = null;
}
-// quadtree_free :: proc (qt: ^QuadTree($T), initial := true) {
-// if qt.nw != null {
-// quadtree_free(qt.nw, false);
-// quadtree_free(qt.ne, false);
-// quadtree_free(qt.sw, false);
-// quadtree_free(qt.se, false);
-// }
-//
-// if !initial {
-// cfree(qt);
-// }
-// }
+quadtree_free :: proc (qt: ^QuadTree($T), initial := true) {
+ if qt.nw != null {
+ quadtree_free(qt.nw, false);
+ quadtree_free(qt.ne, false);
+ quadtree_free(qt.sw, false);
+ quadtree_free(qt.se, false);
+ }
+
+ if !initial {
+ cfree(qt);
+ }
+}
quadtree_subdivide :: proc (use qt: ^QuadTree($T), a: Allocator) {
if nw != null do return;
qt.se = alloc(a, sizeof QuadTree(T));
quadtree_init(qt.nw, AABB.{ region.x, region.y, hw, hh });
- quadtree_init(qt.ne, AABB.{ region.x + hw, region.y, hw, hh });
+ quadtree_init(qt.ne, AABB.{ region.x + hw, region.y, hw, hh });
quadtree_init(qt.sw, AABB.{ region.x, region.y + hh, hw, hh });
quadtree_init(qt.se, AABB.{ region.x + hw, region.y + hh, hw, hh });
}
if !aabb_contains(region, pos) do return false;
- if points_count < QUAD_TREE_ENTITY_STORAGE && nw == null {
+ if points_count < QUAD_TREE_MAX_POINTS && nw == null {
points[points_count] = t;
points_count += 1;
return true;
NONE /usr/share/onyx/core/js/webgl.onyx /^NONE :: 0$/
NOTEQUAL /usr/share/onyx/core/js/webgl.onyx /^NOTEQUAL :: 0x0205$/
NO_ERROR /usr/share/onyx/core/js/webgl.onyx /^NO_ERROR :: 0$/
-NUM_QUADS src/main.onyx /^NUM_QUADS :: 1 << 10$/
+NUM_QUADS src/main.onyx /^NUM_QUADS :: 1 << 14$/
OBJECT_TYPE /usr/share/onyx/core/js/webgl.onyx /^OBJECT_TYPE :: 0x9112$/
ONE /usr/share/onyx/core/js/webgl.onyx /^ONE :: 1$/
ONE_MINUS_CONSTANT_ALPHA /usr/share/onyx/core/js/webgl.onyx /^ONE_MINUS_CONSTANT_ALPHA :: 0x8004$/
ctz_i32 /usr/share/onyx/core/intrinsics.onyx /^ctz_i32 :: proc (val: i32) -> i32 #intrinsic ---$/
ctz_i64 /usr/share/onyx/core/intrinsics.onyx /^ctz_i64 :: proc (val: i64) -> i64 #intrinsic ---$/
cullFace /usr/share/onyx/core/js/webgl.onyx /^cullFace :: proc (mode: GLenum) #foreign "gl" "cullFace" ---$/
+debugger src/main.onyx /^debugger :: proc () #foreign "dummy" "breakable" ---$/
deleteBuffer /usr/share/onyx/core/js/webgl.onyx /^deleteBuffer :: proc (buffer: GLBuffer) #foreign "gl" "deleteBuffer" ---$/
deleteFramebuffer /usr/share/onyx/core/js/webgl.onyx /^deleteFramebuffer :: proc (framebuffer: GLFramebuffer) #foreign "gl" "deleteFramebuffer" ---$/
deleteProgram /usr/share/onyx/core/js/webgl.onyx /^deleteProgram :: proc (program: GLProgram) #foreign "gl" "deleteProgram" ---$/
drawElements /usr/share/onyx/core/js/webgl.onyx /^drawElements :: proc (mode: GLenum, count: GLsizei, type: GLenum, offset: GLint) #foreign "gl" "drawElements" ---$/
drawElementsInstanced /usr/share/onyx/core/js/webgl.onyx /^drawElementsInstanced :: proc (mode: GLenum, count: GLsizei, type: GLenum, offset: GLint, instanceCount: GLsizei) #foreign "gl" "drawElementsInstanced" ---$/
draw_quad src/main.onyx /^draw_quad :: proc (use rc: ^RenderContext, quad: ^Quad) {$/
-draw_quad_tree src/main.onyx /^draw_quad_tree :: proc (qt: ^QuadTree($T), level := 0, corner := 4) {$/
+draw_quad_tree src/main.onyx /^draw_quad_tree :: proc (qt: ^QuadTree($T), level := 0, corner := 0) {$/
draw_rect src/main.onyx /^draw_rect :: proc (use rc: ^RenderContext, x: f32, y: f32, w: f32, h: f32) {$/
draw_textured_rect src/main.onyx /^draw_textured_rect :: proc (use rc: ^RenderContext, x: f32, y: f32, w: f32, h: f32, tx: f32, ty: f32, tw: f32, th: f32) {$/
dude_create_random src/main.onyx /^dude_create_random :: proc () -> Dude {$/
quad_renderer_draw src/gfx/quad_renderer.onyx /^quad_renderer_draw :: proc (use qr: ^QuadRenderer, count := -1) {$/
quad_renderer_init src/gfx/quad_renderer.onyx /^quad_renderer_init :: proc (use qr: ^QuadRenderer, initial_quads := 10) {$/
quad_renderer_update_view src/gfx/quad_renderer.onyx /^quad_renderer_update_view :: proc (use qr: ^QuadRenderer) {$/
-quad_scratch_buffer src/main.onyx /^quad_scratch_buffer : [128 * 1024] u8;$/
+quad_scratch_buffer src/main.onyx /^quad_scratch_buffer : [512 * 1024] u8;$/
quad_update_at_index src/gfx/quad_renderer.onyx /^quad_update_at_index :: proc (use qr: ^QuadRenderer, idx: i32, quad: Quad) {$/
+quadtree_free src/quad_tree.onyx /^quadtree_free :: proc (qt: ^QuadTree($T), initial := true) {$/
quadtree_init src/quad_tree.onyx /^quadtree_init :: proc (qt: ^QuadTree($T), initial_region: AABB) {$/
quadtree_insert src/quad_tree.onyx /^quadtree_insert :: proc (use qt: ^QuadTree($T), t: ^T, alloc := context.allocator) -> bool {$/
quadtree_query src/quad_tree.onyx /^quadtree_query :: proc (use qt: ^QuadTree($T), r: AABB, p: ^[..] ^T) {$/
shaderSource /usr/share/onyx/core/js/webgl.onyx /^shaderSource :: proc (shader: GLShader, source: string) #foreign "gl" "shaderSource" ---$/
shl_i32 /usr/share/onyx/core/intrinsics.onyx /^shl_i32 :: proc (lhs: i32, rhs: i32) -> i32 #intrinsic ---$/
shl_i64 /usr/share/onyx/core/intrinsics.onyx /^shl_i64 :: proc (lhs: i64, rhs: i64) -> i64 #intrinsic ---$/
+simulating src/main.onyx /^simulating := true;$/
sin /usr/share/onyx/core/math.onyx /^sin :: proc (t_: f32) -> f32 {$/
slr_i32 /usr/share/onyx/core/intrinsics.onyx /^slr_i32 :: proc (lhs: i32, rhs: i32) -> i32 #intrinsic ---$/
slr_i64 /usr/share/onyx/core/intrinsics.onyx /^slr_i64 :: proc (lhs: i64, rhs: i64) -> i64 #intrinsic ---$/