slight refactoring
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 11 Feb 2022 19:53:49 +0000 (13:53 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 11 Feb 2022 19:53:49 +0000 (13:53 -0600)
docs/todo.txt
src/build.onyx
src/entity/editor.onyx
src/entity/items.onyx [new file with mode: 0644]
src/entity/player.onyx
src/game.onyx [new file with mode: 0644]
src/gfx/ui.onyx
src/main.onyx

index 4c7bb0edce997cb9833f29483194598f89a87b80..24dbb2104dde500e6c9594c9d4ce7fa8313d70d0 100644 (file)
@@ -17,4 +17,4 @@ Automated asset loader for:
     - Sounds
     - Shaders?
 
-
+// Draw the cursor on textboxes
index 5fd8821c3d3e9b636fbcd74ed44f523bd7bbba9b..013b443f8e30ef9fd97bda3459f8a67e4b23cc0f 100644 (file)
@@ -14,9 +14,11 @@ DEBUG :: false
 #load "core/std"
 
 #load "config"
+#load "game"
 #load "main"
 
 #load "entity/editor"
+#load "entity/items"
 #load "entity/manager"
 #load "entity/player"
 #load "entity/store"
index 0450ae28ba4b1caea8b697b0824a0b6f5d38c6fa..7e2ae90f6bd67b0d06b5b60c82f18ec15d63cf92 100644 (file)
@@ -228,6 +228,8 @@ editor_draw :: () {
         member_any := any.{cast(^u8) v.data + it.offset, it.type};
 
         if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) {
+            @TODO // This should query if this field has Editor_Disabled in its tags.
+
             if Rect.contains(.{x, y + 2, w, Field_Height + 2}, mouse_get_position_vector()) {
                 if active_index < 0 do sidebar_width += w;
                 active_index = i - 1;
@@ -329,7 +331,7 @@ editor_draw :: () {
                         }
                     }
                 } else {
-
+                    @TODO // Add radio buttons for enum type.
                 }
             }
         }
diff --git a/src/entity/items.onyx b/src/entity/items.onyx
new file mode 100644 (file)
index 0000000..e0fa2e2
--- /dev/null
@@ -0,0 +1,29 @@
+
+use package core
+
+Item :: struct {
+    use entity: Entity;
+
+    color: Color;
+
+    init_data :: struct {
+        pos   := Vector2.{0, 0};
+        color := Color.{1, 0, 1, 1};
+    }
+
+    init :: (use this: ^Item, data: init_data) {
+        this.pos   = data.pos;
+        this.size  = .{16, 16};
+        this.color = data.color;
+        this.flags |= .Carryable;
+    }
+
+    get_rect :: Entity.get_rect
+
+    draw :: (use this: ^Item) {
+        immediate_set_color(this.color);
+
+        r := this->get_rect();
+        immediate_rectangle(r.x, r.y, r.w, r.h);
+    }
+}
index 9592a30d78a39772097e3d2840f7f11cac48c5ba..d6279f181614efe1adb67b415b9661b04437ce43 100644 (file)
@@ -259,33 +259,6 @@ Door :: struct {
 }
 
 
-Item :: struct {
-    use entity: Entity;
-
-    color: Color;
-
-    init_data :: struct {
-        pos   := Vector2.{0, 0};
-        color := Color.{1, 0, 1, 1};
-    }
-
-    init :: (use this: ^Item, data: init_data) {
-        this.pos   = data.pos;
-        this.size  = .{16, 16};
-        this.color = data.color;
-        this.flags |= .Carryable;
-    }
-
-    get_rect :: Entity.get_rect
-
-    draw :: (use this: ^Item) {
-        immediate_set_color(this.color);
-
-        r := this->get_rect();
-        immediate_rectangle(r.x, r.y, r.w, r.h);
-    }
-}
-
 
 
 @Relocate
diff --git a/src/game.onyx b/src/game.onyx
new file mode 100644 (file)
index 0000000..5f6c872
--- /dev/null
@@ -0,0 +1,57 @@
+
+use package core
+use package glfw3
+
+//
+// Game Global Variables
+//
+
+scene: Entity_Manager;
+
+game_init :: () {
+    player_texture = texture_make(#cstr "./assets/images/player.png");
+
+    scene = entity_manager_create();
+    scene->register(Player);
+    scene->register(Wall);
+    scene->register(Door);
+    scene->register(Item);
+    scene->load_from_file("scenes/quick_save.scene");
+
+    #if DEBUG {
+        println("Registered Entity types:");
+        for scene.entity_types.entries {
+            info := cast(^type_info.Type_Info_Struct) type_info.get_type_info(it.key);
+            printf("    {}\n", info.name);
+        }
+    }
+}
+
+game_update :: (dt: f32) {
+    if is_key_just_up(GLFW_KEY_F8) {
+        scene->save_to_file("scenes/quick_save.scene");
+    }
+
+    if is_key_just_up(GLFW_KEY_F9) {
+        scene->load_from_file("scenes/quick_save.scene");
+    }
+
+    if editor_shown() {
+        editor_update(dt);
+        return;
+    }
+
+    scene->update(dt);
+}
+
+game_draw :: () {
+    update_world_matrix();
+    update_model_matrix(.{0,0});
+
+    if editor_shown() {
+        editor_draw();
+        return;
+    }
+
+    scene->draw();
+}
index 112706b0ec88c6be9f5a076752a6f7774c59f211..6d74b1001df96984b49bc7318a16df8eddcaf39d 100644 (file)
@@ -239,6 +239,8 @@ draw_textbox :: (use r: Rect, text_buffer: ^[..] u8, placeholder := null_str, th
     immediate_set_color(surface_color);
     immediate_rectangle(x + border_width, y + border_width, w - border_width * 2, h - border_width * 2);
 
+    // Draw the cursor on textboxes
+
     font_set_color(theme.text_color);
     font_draw(font, text_x, text_y, text); // This is technically a frame late for updating the text?
 
index ad85974a2c14f99b185c9cd791ebab1fef8cf1c4..c4044b16ca7996d5a9f292fd6a7f330471a0dd12 100644 (file)
@@ -9,18 +9,14 @@ DEBUG :: #defined(runtime.vars.DEBUG)
 @GlobalVariable
 window: GLFWwindow_p
 
-@GlobalVariable
-scene: Entity_Manager;
-
 @GlobalVariable
 window_width: u32
 window_height: u32
 
 #if DEBUG { debug_font: Font; }
 
-
 init :: () {
-    create_window();
+    window = create_window();
     input_bind_glfw_events(window);
     glInit(glfwGetLoadProcAddress());
 
@@ -35,29 +31,13 @@ init :: () {
     fonts_init();
     immediate_init();
     editor_init();
+    game_init();
 
     glfwGetWindowSize(window, ^window_width, ^window_height);
     glViewport(0, 0, window_width, window_height);
     update_view_matrix();
 
-    player_texture = texture_make(#cstr "./assets/images/player.png");
-
     #if DEBUG { debug_font = font_lookup(.{"./assets/fonts/calibri.ttf", 16}); }
-
-    scene = entity_manager_create();
-    scene->register(Player);
-    scene->register(Wall);
-    scene->register(Door);
-    scene->register(Item);
-    scene->load_from_file("scenes/quick_save.scene");
-
-    #if DEBUG {
-        println("Registered Entity types:");
-        for scene.entity_types.entries {
-            info := cast(^type_info.Type_Info_Struct) type_info.get_type_info(it.key);
-            printf("    {}\n", info.name);
-        }
-    }
 }
 
 update :: (dt: f32) {
@@ -72,20 +52,7 @@ update :: (dt: f32) {
         editor_toggle();
     }
 
-    if is_key_just_up(GLFW_KEY_F8) {
-        scene->save_to_file("scenes/quick_save.scene");
-    }
-
-    if is_key_just_up(GLFW_KEY_F9) {
-        scene->load_from_file("scenes/quick_save.scene");
-    }
-
-    if editor_shown() {
-        editor_update(dt);
-        return;
-    }
-
-    scene->update(dt);
+    game_update(dt);
 }
 
 draw :: () {
@@ -109,15 +76,7 @@ draw :: () {
         glfwSwapBuffers(window);
     }
 
-    update_world_matrix();
-    update_model_matrix(.{0,0});
-
-    if editor_shown() {
-        editor_draw();
-        return;
-    }
-
-    scene->draw();
+    game_draw();
 
     #if false {
         mx, my := mouse_get_position();
@@ -159,7 +118,7 @@ run :: () {
     }
 }
 
-create_window :: () {
+create_window :: () => {
     #if runtime.compiler_os == .Linux {
         glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
         glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
@@ -168,11 +127,12 @@ create_window :: () {
         glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
         glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
     }
-    window = glfwCreateWindow(800, 600, #cstr "Bar simulator");
+    window := glfwCreateWindow(800, 600, #cstr "Bar simulator");
 
     glfwMakeContextCurrent(window);
     glfwSwapInterval(1);
     glfwSetWindowSizeCallback(window, "on_resize");
+    return window;
 }
 
 #export "on_resize" (window: GLFWwindow_p, width, height: u32) {