updates
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 3 Feb 2022 15:11:45 +0000 (09:11 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 3 Feb 2022 15:11:45 +0000 (09:11 -0600)
src/entity/editor.onyx
src/entity/manager.onyx
src/entity/player.onyx
src/main.onyx

index 19ea6b45dc747f6c66720907672f6c15f7ef0999..d723eb5fb7875d99c7b4710da23d00c85e232e5e 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Editor features to be added:
 //
-// - [ ] Create new entity
+// - [x] Create new entity
 // - [ ] Edit entity properties in UI
 // - [ ] Serialize / Deserialize a scene
 //
@@ -47,14 +47,13 @@ editor_update :: (dt: f32) {
 
 #local handle_placing_entities :: () {
     if active_index < 0 do return;
+    mouse_pos := mouse_get_position_vector();
 
-    if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) {
+    if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) && mouse_pos.x < ~~window_width - sidebar_width && mouse_pos.y > menubar_height {
         entity_type := ^scene.entity_types.entries[active_index].value;
-        printf("ADDING {}\n", entity_type);
 
-        pos := mouse_get_position_vector();
-        entity := entity_type.make(^scene); // scene->make(entity_type);
-        entity.pos = pos;
+        entity := entity_type.create_default(^scene);
+        entity.pos = mouse_pos;
     }
 }
 
index 68119d5b67f81bfc3ba556b753f6dd94993418fa..84ff8b044c5f8d291b65cd2640a497c4817427c4 100644 (file)
@@ -31,7 +31,7 @@ IsEntity :: interface (e: $E) {
 }
 
 Entity_Info :: struct {
-    make : (scene: ^Entity_Manager) -> ^Entity = null_proc;
+    create_default : (scene: ^Entity_Manager) -> ^Entity = null_proc;
 
     update   : (entity: ^Entity, dt: f32) -> void             = null_proc;
     draw     : (entity: ^Entity) -> void                      = null_proc;
@@ -53,7 +53,6 @@ Entity_Manager :: struct {
     register       :: entity_manager_register;
     add            :: entity_manager_add;
     make           :: entity_manager_make;
-    make_old       :: entity_manager_make_old;
     update         :: entity_manager_update;
     draw           :: entity_manager_draw;
     get            :: entity_manager_get;
@@ -99,7 +98,7 @@ entity_manager_register :: (use this: ^Entity_Manager, $entity_type: type_expr)
 
 
         info := Entity_Info.{};
-        info.make = #solidify entity_manager_make { entity_type=entity_type };
+        info.create_default = #solidify entity_manager_create_default { entity_type=entity_type };
 
         @CompilerFeatures // Maybe there should be data stored in the Type_Info_Struct about
         // the functions/methods that are defined in the structs scope. I don't know if that
@@ -125,14 +124,14 @@ entity_manager_add :: (use this: ^Entity_Manager, entity: ^$T) -> Entity_ID wher
     return entity.id;
 }
 
-entity_manager_make :: (use this: ^Entity_Manager, $entity_type: type_expr) -> ^entity_type where IsEntity(^entity_type) {
+#local entity_manager_create_default :: (use this: ^Entity_Manager, $entity_type: type_expr) -> ^entity_type where IsEntity(^entity_type) {
     entity := new(entity_type, allocator=entity_allocator);
     entity_type.init(entity, entity_type.init_data.{});
     this->add(entity);
     return entity;
 }
 
-entity_manager_make_old :: (use this: ^Entity_Manager, $entity_type: type_expr, data: entity_type.init_data = .{}) -> ^entity_type where IsEntity(^entity_type) {
+entity_manager_make :: (use this: ^Entity_Manager, $entity_type: type_expr, data: entity_type.init_data = .{}) -> ^entity_type where IsEntity(^entity_type) {
     entity := new(entity_type, allocator=entity_allocator);
     entity_type.init(entity, data);
     this->add(entity);
index 736b4b88107a673ab75af81dd57410d0ee228656..7d4d26fb36f168c26a411be814c9ab2976b34e9a 100644 (file)
@@ -171,8 +171,8 @@ Wall :: struct {
     size: Vector2;
 
     init_data :: struct {
-        pos  := Vector2.{0, 0};
-        size := Vector2.{0, 0};
+        pos  := Vector2.{0,  0};
+        size := Vector2.{10, 10};
     }
 
     init :: (use this: ^Wall, data: init_data) {
index 28656eae0182046de7133ec27dc38b04410ed581..8c401231ae735be3e7af213ff3ecf0960c553365 100644 (file)
@@ -45,22 +45,22 @@ init :: () {
     #if DEBUG { debug_font = font_lookup(.{"./assets/fonts/calibri.ttf", 16}); }
 
     scene = entity_manager_create();
-    scene->make_old(Player, .{ pos = .{300, 300}, controls=player_1_controls });
-    scene->make_old(Player, .{ pos = .{400, 300}, controls=player_2_controls, color=.{1,0,0} });
-
-    scene->make_old(Wall, .{ .{100, 100}, .{400, 50} });
-    // scene->make_old(Wall, .{ .{100, 100}, .{50, 400} });
-    // scene->make_old(Wall, .{ .{450, 100}, .{50, 400} });
-    // scene->make_old(Wall, .{ .{100, 450}, .{400, 50} });
-
-    scene->make_old(Door, .{ .{150, 150}, .{50, 50} });
-    scene->make_old(Door, .{ .{400, 150}, .{50, 50} });
-    scene->make_old(Door, .{ .{400, 400}, .{50, 50} });
-    scene->make_old(Door, .{ .{150, 400}, .{50, 50} });
-
-    scene->make_old(Item, .{ pos=.{ 250, 250 }, color=.{1,0,0} });
-    scene->make_old(Item, .{ pos=.{ 275, 250 }, color=.{0,1,0} });
-    scene->make_old(Item, .{ pos=.{ 300, 250 }, color=.{0,0,1} });
+    scene->make(Player, .{ pos = .{300, 300}, controls=player_1_controls });
+    scene->make(Player, .{ pos = .{400, 300}, controls=player_2_controls, color=.{1,0,0} });
+
+    scene->make(Wall, .{ .{100, 100}, .{400, 50} });
+    // scene->make(Wall, .{ .{100, 100}, .{50, 400} });
+    // scene->make(Wall, .{ .{450, 100}, .{50, 400} });
+    // scene->make(Wall, .{ .{100, 450}, .{400, 50} });
+
+    scene->make(Door, .{ .{150, 150}, .{50, 50} });
+    scene->make(Door, .{ .{400, 150}, .{50, 50} });
+    scene->make(Door, .{ .{400, 400}, .{50, 50} });
+    scene->make(Door, .{ .{150, 400}, .{50, 50} });
+
+    scene->make(Item, .{ pos=.{ 250, 250 }, color=.{1,0,0} });
+    scene->make(Item, .{ pos=.{ 275, 250 }, color=.{0,1,0} });
+    scene->make(Item, .{ pos=.{ 300, 250 }, color=.{0,0,1} });
     
     #if DEBUG {
         println("Registered Entity types:");