From: Brendan Hansen Date: Wed, 23 Feb 2022 03:46:40 +0000 (-0600) Subject: random little updates X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=9e8d00d6e0cad3cf01fe4160ca814ee8ee2d2973;p=bar-game.git random little updates --- diff --git a/run_tree/assets/images/base.png b/run_tree/assets/images/base.png new file mode 100644 index 0000000..985ae76 Binary files /dev/null and b/run_tree/assets/images/base.png differ diff --git a/run_tree/assets/images/beer-1.png b/run_tree/assets/images/beer-1.png index 72a5ce1..4c5ee38 100644 Binary files a/run_tree/assets/images/beer-1.png and b/run_tree/assets/images/beer-1.png differ diff --git a/run_tree/assets/images/player_sheet.png b/run_tree/assets/images/player_sheet.png new file mode 100644 index 0000000..906a86c Binary files /dev/null and b/run_tree/assets/images/player_sheet.png differ diff --git a/src/entity/editor.onyx b/src/entity/editor.onyx index 93cf791..27d98bd 100644 --- a/src/entity/editor.onyx +++ b/src/entity/editor.onyx @@ -34,6 +34,7 @@ editor_update :: (dt: f32) { if is_key_just_up(GLFW_KEY_1) do clicked_tab = .Create; if is_key_just_up(GLFW_KEY_2) do clicked_tab = .Edit; + if is_key_just_up(GLFW_KEY_G) do editor_grid_shown = !editor_grid_shown; handle_clicking_tab(dt); switch active_tab { @@ -117,6 +118,24 @@ editor_update :: (dt: f32) { } editor_draw :: () { + if editor_grid_shown { + width := cast(f32) window_width; + height := cast(f32) window_height; + xcount := cast(i32) math.ceil(height / editor_grid_size); + ycount := cast(i32) math.ceil(width / editor_grid_size); + + immediate_set_color(.{1,1,0}); + for xcount { + y := ~~it * editor_grid_size; + immediate_line(0, y, width, y); + } + + for ycount { + x := ~~it * editor_grid_size; + immediate_line(x, 0, x, height); + } + } + scene->draw(); immediate_flush(); @@ -388,4 +407,7 @@ editor_draw :: () { clicked_tab := Tabs.None; active_index := -1; + + editor_grid_shown := false; + editor_grid_size := 16.0f; @TODO // This should be configurable } diff --git a/src/entity/items.onyx b/src/entity/items.onyx index 26870f8..c2a648f 100644 --- a/src/entity/items.onyx +++ b/src/entity/items.onyx @@ -106,10 +106,16 @@ Item_Entity :: struct { get_rect :: Entity.get_rect draw :: (use this: ^Item_Entity) { + r := this->get_rect(); item_data := item_store->get_item(item); + if item_data == null { + immediate_set_color(.{1,0,0}); + immediate_rectangle(r.x, r.y, r.w, r.h); + return; + } + immediate_set_color(item_data.color); - r := this->get_rect(); texture, loaded := texture_lookup(item_data.texture_path); if !loaded { immediate_rectangle(r.x, r.y, r.w, r.h); diff --git a/src/game.onyx b/src/game.onyx index 97613eb..b48cb02 100644 --- a/src/game.onyx +++ b/src/game.onyx @@ -10,8 +10,6 @@ scene: Entity_Manager; item_store: Item_Store; game_init :: () { - // player_texture = texture_lookup(#cstr "./assets/images/player.png"); - // This process of queueing the asset bucket should // be made automatic somehow... queue_assets(^player_assets); diff --git a/src/gfx/immediate.onyx b/src/gfx/immediate.onyx index 231b97d..2d9d67a 100644 --- a/src/gfx/immediate.onyx +++ b/src/gfx/immediate.onyx @@ -30,6 +30,7 @@ immediate_flush :: () { vertex_count = 0; rendering_type = .Plain; + immediate_mesh.primitive = GL_TRIANGLES; } immediate_clear :: (color: Color) { @@ -48,6 +49,16 @@ immediate_vertex :: (x, y: f32, t_x := 0.0f, t_y := 0.0f) { vertex_data[vertex_count] = .{ .{x, y}, .{t_x, t_y}, immediate_color }; } +immediate_line :: (x1, y1, x2, y2: f32) { + if vertex_count >= Maximum_Vertex_Count do immediate_flush(); + set_rendering_type(.Line); + immediate_mesh.primitive = GL_LINES; + + vertex_data[vertex_count + 0] = .{ .{x1, y1}, .{0, 0}, immediate_color }; + vertex_data[vertex_count + 1] = .{ .{x2, y2}, .{0, 0}, immediate_color }; + vertex_count += 2; +} + immediate_triangle :: (x1, x2, x3: Vector2) { if vertex_count + 3 > Maximum_Vertex_Count do immediate_flush(); set_rendering_type(.Plain); @@ -159,6 +170,7 @@ Immediate_Vertex :: struct { Rendering_Type :: enum { Plain; + Line; Image; } rendering_type := Rendering_Type.Plain; diff --git a/src/gfx/texture.onyx b/src/gfx/texture.onyx index 8586b40..2ceb980 100644 --- a/src/gfx/texture.onyx +++ b/src/gfx/texture.onyx @@ -33,6 +33,7 @@ texture_lookup :: #match {} tex.filename = filename; pixels := stbi_load(path, ^tex.width, ^tex.height, ^tex.channels, 4); if pixels == null { + debug_log(.Warning, "Failed to load texture: {}", filename); return Zero(Texture), false; } defer stbi_image_free(pixels); @@ -52,6 +53,7 @@ texture_lookup :: #match {} // This assumes that the filename data is going to be persistant forever. // Not a great assumption to make but is it really worth copying it? texture_cache[filename] = tex; + debug_log(.Info, "Loaded texture: {}", filename); return tex, true; } diff --git a/src/utils/logger.onyx b/src/utils/logger.onyx index 529ddee..4947e53 100644 --- a/src/utils/logger.onyx +++ b/src/utils/logger.onyx @@ -12,24 +12,32 @@ Log_Level :: enum { Critical; } +debug_set_level :: (level: Log_Level) { + log_level = level; +} + debug_log :: (level: Log_Level, format: str, args: ..any) { debug_log_va(level, format, ~~args); } debug_log_va :: (level: Log_Level, format: str, args: [] any) { + if level < log_level do return; + buf: [2048] u8; output := conv.format_va(buf, format, args); - printf("[{}] {}\n", level_string(level), output); + printf("[{w5}] {}\n", level_string(level), output); } #local level_string :: (level: Log_Level) => { switch level { case .Debug do return "DEBUG"; - case .Info do return "INFO "; - case .Warning do return "WARN "; + case .Info do return "INFO"; + case .Warning do return "WARN"; case .Error do return "ERROR"; - case .Critical do return "CRIT "; + case .Critical do return "CRIT"; } - return " "; + return ""; } + +#local log_level := Log_Level.Debug; \ No newline at end of file