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 {
}
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();
clicked_tab := Tabs.None;
active_index := -1;
+
+ editor_grid_shown := false;
+ editor_grid_size := 16.0f; @TODO // This should be configurable
}
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);
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);
vertex_count = 0;
rendering_type = .Plain;
+ immediate_mesh.primitive = GL_TRIANGLES;
}
immediate_clear :: (color: Color) {
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);
Rendering_Type :: enum {
Plain;
+ Line;
Image;
}
rendering_type := Rendering_Type.Plain;
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);
// 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;
}
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