#include_file "vecmath"
#include_file "aabb"
#include_file "quad_tree"
+#include_file "globals"
use package core
use package gfx
use package event as event
use package input as input { Key }
use package vecmath
-use package ttf_font
+use package globals
use package quad_tree
use package aabb
-NUM_QUADS :: 1 << 14
+NUM_QUADS :: 1 << 17
RenderContext :: struct {
quad_renderer: ^QuadRenderer;
-// @Cleanup
-window_width := 0
-window_height := 0
-half_window_width := 0
-half_window_height := 0
-
-renderer : RenderContext
-input_state : input.InputState
-atlas : Atlas
-dudes : [..] Dude
-dude_tree : QuadTree(Dude)
-
poll_events :: proc () {
use event.DomEventKind;
if input.key_just_down(^input_state, Key.Space) do simulating = !simulating;
- if input.key_down(^input_state, Key.ArrowUp) do renderer.trans_y += 10.0f;
- if input.key_down(^input_state, Key.ArrowDown) do renderer.trans_y -= 10.0f;
- if input.key_down(^input_state, Key.ArrowLeft) do renderer.trans_x += 10.0f;
- if input.key_down(^input_state, Key.ArrowRight) do renderer.trans_x -= 10.0f;
+ if input.key_down(^input_state, Key.ArrowUp) do renderer.trans_y += 15.0f / renderer.scale;
+ if input.key_down(^input_state, Key.ArrowDown) do renderer.trans_y -= 15.0f / renderer.scale;
+ if input.key_down(^input_state, Key.ArrowLeft) do renderer.trans_x += 15.0f / renderer.scale;
+ if input.key_down(^input_state, Key.ArrowRight) do renderer.trans_x -= 15.0f / renderer.scale;
if input_state.mouse.wheel_ups > ~~0 do renderer.scale *= 1.125f;
if input_state.mouse.wheel_downs > ~~0 do renderer.scale /= 1.125f;
texture_use(^textures.tilemap);
- // draw_quad_tree(^dude_tree);
+ tilemap_draw(^tilemap, ^renderer);
dude_sprite := atlas_lookup(^atlas, 0);
for ^d: dudes {
render_context_flush(^renderer);
}
-draw_quad_tree :: proc (qt: ^QuadTree($T)) {
- col := cast(f32) (0.0f + ~~ qt.points_count * 0.25f);
- if col > 1.0f do col = 1.0f;
-
- color := Color4f32.{ col, col, col, 1.0f };
-
- quad := Quad.{
- pos = V2f.{ qt.region.x, qt.region.y },
- size = V2f.{ qt.region.w, qt.region.h },
- color = color,
-
- tex_pos = V2f.{ -1.0f, -1.0f },
- };
- draw_quad(^renderer, ^quad);
-
- if qt.nw != null {
- draw_quad_tree(qt.nw);
- draw_quad_tree(qt.ne);
- draw_quad_tree(qt.sw);
- draw_quad_tree(qt.se);
- }
-}
debugger :: proc () #foreign "dummy" "breakable" ---
array_push(^dudes, dude_create_random());
}
+ tilemap_init(^tilemap, 150, 80);
+
game_launch :: proc () #foreign "game" "launch" ---;
game_launch();
}
dude_get_aabb :: proc (use dude: ^Dude) -> AABB {
return AABB.{ x = pos.x - size, y = pos.y - size, w = size * 2.0f, h = size * 2.0f };
}
+
+TILE_SIZE :: 10.0f;
+
+Tilemap :: struct {
+ width : u32;
+ height : u32;
+
+ tiles : [] Tile;
+}
+
+Tile :: struct {
+ r : u8 = ~~0;
+ g : u8 = ~~0;
+ b : u8 = ~~0;
+}
+
+tilemap_init :: proc (use tm: ^Tilemap, w := 10, h := 10) {
+ width = w;
+ height = h;
+ alloc_slice(^tiles, width * height);
+
+ for ^t: tiles {
+ t.r = ~~random_between(0, 255);
+ t.g = ~~random_between(0, 255);
+ t.b = ~~random_between(0, 255);
+ }
+}
+
+tilemap_free :: proc (use tm: ^Tilemap) {
+ cfree(tiles.data);
+ width = 0;
+ height = 0;
+}
+
+tilemap_draw :: proc (use tm: ^Tilemap, renderer: ^RenderContext) {
+ for y: 0 .. height do for x: 0 .. width {
+ renderer.color = tile_to_color4f32(tiles[y * width + x]);
+ draw_rect(renderer, ~~x * TILE_SIZE, ~~y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
+ }
+}
+
+tilemap_get_tile :: proc (use tm: ^Tilemap, x: u32, y: u32) -> Tile {
+ if x < 0 || y < 0 || x >= width || y >= height do return Tile.{};
+ return tiles[x + y * width];
+}
+
+tile_to_color4f32 :: proc (t: Tile) -> Color4f32 {
+ return Color4f32.{
+ r = ~~cast(u32) t.r / 255.0f,
+ g = ~~cast(u32) t.g / 255.0f,
+ b = ~~cast(u32) t.b / 255.0f,
+ a = 1.0f,
+ };
+}
+
+
+/*
+draw_quad_tree :: proc (qt: ^QuadTree($T)) {
+ col := cast(f32) (0.0f + ~~ qt.points_count * 0.25f);
+ if col > 1.0f do col = 1.0f;
+
+ color := Color4f32.{ col, col, col, 1.0f };
+
+ quad := Quad.{
+ pos = V2f.{ qt.region.x, qt.region.y },
+ size = V2f.{ qt.region.w, qt.region.h },
+ color = color,
+
+ tex_pos = V2f.{ -1.0f, -1.0f },
+ };
+ draw_quad(^renderer, ^quad);
+
+ if qt.nw != null {
+ draw_quad_tree(qt.nw);
+ draw_quad_tree(qt.ne);
+ draw_quad_tree(qt.sw);
+ draw_quad_tree(qt.se);
+ }
+}
+*/
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 << 14$/
+NUM_QUADS src/main.onyx /^NUM_QUADS :: 1 << 17$/
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$/
TEXTURE_WRAP_R /usr/share/onyx/core/js/webgl.onyx /^TEXTURE_WRAP_R :: 0x8072$/
TEXTURE_WRAP_S /usr/share/onyx/core/js/webgl.onyx /^TEXTURE_WRAP_S :: 0x2802$/
TEXTURE_WRAP_T /usr/share/onyx/core/js/webgl.onyx /^TEXTURE_WRAP_T :: 0x2803$/
+TILE_SIZE src/main.onyx /^TILE_SIZE :: 10.0f;$/
TIMEOUT_EXPIRED /usr/share/onyx/core/js/webgl.onyx /^TIMEOUT_EXPIRED :: 0x911B$/
TIMEOUT_IGNORED /usr/share/onyx/core/js/webgl.onyx /^TIMEOUT_IGNORED :: -1$/
TRANSFORM_FEEDBACK /usr/share/onyx/core/js/webgl.onyx /^TRANSFORM_FEEDBACK :: 0x8E22$/
TTTableInfo src/font.onyx /^TTTableInfo :: struct {$/
Texture src/gfx/texture.onyx /^Texture :: struct {$/
TextureDataMode src/gfx/texture.onyx /^TextureDataMode :: enum {$/
+Tile src/main.onyx /^Tile :: struct {$/
+Tilemap src/main.onyx /^Tilemap :: struct {$/
TrueTypeFont src/font.onyx /^TrueTypeFont :: struct {$/
UNIFORM_ARRAY_STRIDE /usr/share/onyx/core/js/webgl.onyx /^UNIFORM_ARRAY_STRIDE :: 0x8A3C$/
UNIFORM_BLOCK_ACTIVE_UNIFORMS /usr/share/onyx/core/js/webgl.onyx /^UNIFORM_BLOCK_ACTIVE_UNIFORMS :: 0x8A42$/
array_remove /usr/share/onyx/core/array.onyx /^array_remove :: proc (arr: ^[..] $T, elem: T) {$/
array_sort /usr/share/onyx/core/array.onyx /^array_sort :: proc (arr: ^[..] $T, cmp: proc (T, T) -> i32) {$/
array_to_slice /usr/share/onyx/core/array.onyx /^array_to_slice :: proc (arr: ^[..] $T) -> [] T {$/
-atlas src/main.onyx /^atlas : Atlas$/
+atlas src/globals.onyx /^atlas : Atlas$/
atlas_apply_to_quad src/gfx/atlas.onyx /^atlas_apply_to_quad :: proc (use atlas: ^Atlas, id: i32, quad: ^Quad) {$/
atlas_create src/gfx/atlas.onyx /^atlas_create :: proc (tex: ^Texture) -> Atlas {$/
atlas_lookup src/gfx/atlas.onyx /^atlas_lookup :: proc (use atlas: ^Atlas, id: i32) -> AtlasSprite {$/
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)) {$/
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 {$/
dude_get_aabb src/main.onyx /^dude_get_aabb :: proc (use dude: ^Dude) -> AABB {$/
-dude_tree src/main.onyx /^dude_tree : QuadTree(Dude)$/
+dude_tree src/globals.onyx /^dude_tree : QuadTree(Dude)$/
dude_try_move src/main.onyx /^dude_try_move :: proc (use dude: ^Dude, other_dudes: ^QuadTree(Dude)) {$/
dude_update src/main.onyx /^dude_update :: proc (use dude: ^Dude, other_dudes: ^QuadTree(Dude)) {$/
-dudes src/main.onyx /^dudes : [..] Dude$/
+dudes src/globals.onyx /^dudes : [..] Dude$/
enable /usr/share/onyx/core/js/webgl.onyx /^enable :: proc (cap: GLenum) #foreign "gl" "enable" ---$/
enableVertexAttribArray /usr/share/onyx/core/js/webgl.onyx /^enableVertexAttribArray :: proc (index: GLuint) #foreign "gl" "enableVertexAttribArray" ---$/
f64_to_string /usr/share/onyx/core/string.onyx /^f64_to_string :: proc (f: f64, buf: [] u8) -> string {$/
getShaderParameter /usr/share/onyx/core/js/webgl.onyx /^getShaderParameter :: proc (shader: GLShader, pname: GLenum) -> GLenum #foreign "gl" "getShaderParameter" ---$/
getUniformLocation /usr/share/onyx/core/js/webgl.onyx /^getUniformLocation :: proc (program: GLProgram, name: string) -> GLUniformLocation #foreign "gl" "getUniformLocation" ---$/
getVertexAttribOffset /usr/share/onyx/core/js/webgl.onyx /^getVertexAttribOffset :: proc (index: GLuint, pname: GLenum) #foreign "gl" "getVertexAttribOffset" ---$/
-half_window_height src/main.onyx /^half_window_height := 0$/
-half_window_width src/main.onyx /^half_window_width := 0$/
+half_window_height src/globals.onyx /^half_window_height := 0$/
+half_window_width src/globals.onyx /^half_window_width := 0$/
heap_alloc /usr/share/onyx/core/alloc.onyx /^heap_alloc :: proc (size_: u32, align: u32) -> rawptr {$/
heap_alloc_proc /usr/share/onyx/core/alloc.onyx /^heap_alloc_proc :: proc (data: rawptr, aa: AllocAction, size: u32, align: u32, oldptr: rawptr) -> rawptr {$/
heap_allocator /usr/share/onyx/core/alloc.onyx /^heap_allocator : Allocator;$/
init src/events.onyx /^init :: proc () {$/
init /usr/share/onyx/core/js/webgl.onyx /^init :: proc (canvasname: string) -> GLboolean #foreign "gl" "init" ---$/
init src/input.onyx /^init :: proc (use state: ^InputState) {$/
-input_state src/main.onyx /^input_state : input.InputState$/
+input_state src/globals.onyx /^input_state : input.InputState$/
invalidateFramebuffer /usr/share/onyx/core/js/webgl.onyx /^invalidateFramebuffer :: proc (target: GLenum, attachments: string) #foreign "gl" "invalidateFramebuffer" ---$/
invalidateSubFramebuffer /usr/share/onyx/core/js/webgl.onyx /^invalidateSubFramebuffer :: proc (target: GLenum, attachments: string, x: GLint, y: GLint, width: GLsizei, height: GLsizei) #foreign "gl" "invalidateSubFramebuffer" ---$/
isEnabled /usr/share/onyx/core/js/webgl.onyx /^isEnabled :: proc (cap: GLenum) -> GLboolean #foreign "gl" "isEnabled" ---$/
render_context_flush src/main.onyx /^render_context_flush :: proc (use rc: ^RenderContext) {$/
render_context_init src/main.onyx /^render_context_init :: proc (use rc: ^RenderContext, qr: ^QuadRenderer = null) {$/
renderbufferStorageMultisample /usr/share/onyx/core/js/webgl.onyx /^renderbufferStorageMultisample :: proc (target: GLenum, samples: GLsizei, internalforamt: GLenum, width: GLsizei, height: GLsizei) #foreign "gl" "renderbufferStorageMultisample" ---$/
-renderer src/main.onyx /^renderer : RenderContext$/
+renderer src/globals.onyx /^renderer : RenderContext$/
resize /usr/share/onyx/core/builtin.onyx /^resize :: proc (use a: Allocator, ptr: rawptr, size: u32) -> rawptr {$/
rotl_i32 /usr/share/onyx/core/intrinsics.onyx /^rotl_i32 :: proc (lhs: i32, rhs: i32) -> i32 #intrinsic ---$/
rotl_i64 /usr/share/onyx/core/intrinsics.onyx /^rotl_i64 :: proc (lhs: i64, rhs: i64) -> i64 #intrinsic ---$/
texture_use src/gfx/texture.onyx /^texture_use :: proc (use tex: ^Texture) {$/
textures src/gfx/texture.onyx /^textures : struct {$/
textures_init src/gfx/texture.onyx /^textures_init :: proc () {$/
+tile_to_color4f32 src/main.onyx /^tile_to_color4f32 :: proc (t: Tile) -> Color4f32 {$/
+tilemap src/globals.onyx /^tilemap : Tilemap$/
+tilemap_draw src/main.onyx /^tilemap_draw :: proc (use tm: ^Tilemap, renderer: ^RenderContext) {$/
+tilemap_free src/main.onyx /^tilemap_free :: proc (use tm: ^Tilemap) {$/
+tilemap_init src/main.onyx /^tilemap_init :: proc (use tm: ^Tilemap, w := 10, h := 10) {$/
trunc_f32 /usr/share/onyx/core/intrinsics.onyx /^trunc_f32 :: proc (val: f32) -> f32 #intrinsic ---$/
trunc_f64 /usr/share/onyx/core/intrinsics.onyx /^trunc_f64 :: proc (val: f64) -> f64 #intrinsic ---$/
ttf_create src/font.onyx /^ttf_create :: proc (ttf_data: [] u8) -> TrueTypeFont {$/
vertexAttribDivisor /usr/share/onyx/core/js/webgl.onyx /^vertexAttribDivisor :: proc (idx: GLuint, divisor: GLuint) #foreign "gl" "vertexAttribDivisor" ---$/
vertexAttribPointer /usr/share/onyx/core/js/webgl.onyx /^vertexAttribPointer :: proc (idx: GLuint, size: GLint, type: GLenum, normalized: GLboolean, stride: GLsizei, offset: GLint) #foreign "gl" "vertexAttribPointer" ---$/
viewport /usr/share/onyx/core/js/webgl.onyx /^viewport :: proc (x: GLint, y: GLint, width: GLsizei, height: GLsizei) #foreign "gl" "viewport" --- $/
-window_height src/main.onyx /^window_height := 0$/
-window_width src/main.onyx /^window_width := 0$/
+window_height src/globals.onyx /^window_height := 0$/
+window_width src/globals.onyx /^window_width := 0$/
xor_i32 /usr/share/onyx/core/intrinsics.onyx /^xor_i32 :: proc (lhs: i32, rhs: i32) -> i32 #intrinsic ---$/
xor_i64 /usr/share/onyx/core/intrinsics.onyx /^xor_i64 :: proc (lhs: i64, rhs: i64) -> i64 #intrinsic ---$/