diff options
| -rw-r--r-- | app.c | 39 | ||||
| -rw-r--r-- | editor.c | 27 | ||||
| -rw-r--r-- | ent.c | 75 |
3 files changed, 68 insertions, 73 deletions
@@ -34,35 +34,6 @@ app_init(void) { game_init(); editor_init(); cam_init(); - - // for (int i = 0; i < 10000; ++i) { - // u64 id = entity_create(false); - // Entity *ent = entity_get(id); - - // char name[16]; - // snprintf(name, 16, "Entity %i", i); - // free(ent->name); - // ent->name = strdup(name); - - // ent->tr.pos = (Vec3){ - // GetRandomValue(-50, 50), - // GetRandomValue(-10, 10), - // GetRandomValue(-50, 50), - // }; - // } - - // for (int i = 0; i < entity_count(); ++i) { - // u64 id = entity_id_at(i); - - // if (i == 5) { - // u64 parent_id = entity_id_at(4); - // entity_set_parent(id, parent_id); - // } - - // if (i == 10) { - // entity_delete(id); - // } - // } } static void @@ -95,16 +66,6 @@ app_loop(void) { BeginMode3D(main_cam.cam); entity_system_draw_3d(); - - // delete this shit later - for (u32 i = 0; i < entity_count(); ++i) { - Matrix world = entity_world_matrix(entity_id_at(i)); - - rlPushMatrix(); - rlMultMatrixf(MatrixToFloatV(world).v); - DrawCubeWiresV(Vector3Zero(), Vector3One(), GREEN); - rlPopMatrix(); - } EndMode3D(); if (FLAG_CHECK(app.flags, BIT(APP_FLAG_DEBUG)) || @@ -1267,7 +1267,7 @@ panel_bool(Rect row, cstr label, bool *value, bool mixed) { row.x + 40, row.y + (row.height - 20) * 0.5f, 20, 20, - }, NULL, value); + }, "", value); } static bool @@ -1528,6 +1528,29 @@ panel_properties(EditorPanelContainer container, bool input) { 20, }; + GuiSetStyle(DEFAULT, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); + if (GuiButton((Rect){ + group.x, group.y + group.height + pad, + 120, 20 + }, "Remove Model")) { + edit.focus = 0; + + EditorAction action = action_begin(ED_ACTION_MODEL, false); + + for (u32 i = 0; i < action.item_cnt; ++i) { + Entity *target = entity_get( + entity_id_from_pid(action.item[i].pid) + ); + + free(target->mdl.key); + target->mdl = (ModelCmp){0}; + } + + action_commit(&action); + goto reset; + } + GuiSetStyle(DEFAULT, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); + GuiLabel((Rect){row.x, row.y, 32, row.height}, "Key"); if (GuiButton( @@ -1555,7 +1578,7 @@ panel_properties(EditorPanelContainer container, bool input) { action_commit(&action); } - row.y = group.y + group.height - 20; + row.y = group.y + group.height + 20; comp_add: GuiUnlock(); @@ -1,4 +1,5 @@ #include "ent.h" +#include "res.h" typedef struct { u32 gen, dense_id, next_free; @@ -246,33 +247,43 @@ entity_system_clear(void) { } -// static void -// entity_draw_mdl(Entity *ent) { -// Matrix T = MatrixTranslate( -// ent->tr.pos.x, -// ent->tr.pos.y, -// ent->tr.pos.z); - -// Matrix R = MatrixRotateXYZ((Vec3) { -// ent->tr.rot.x * DEG2RAD, -// ent->tr.rot.y * DEG2RAD, -// ent->tr.rot.z * DEG2RAD, -// }); - -// Matrix S = MatrixScale( -// ent->tr.scale.x, -// ent->tr.scale.y, -// ent->tr.scale.z); +static void +entity_draw_mdl(Entity *ent) { + Matrix T = MatrixTranslate( + ent->tr.pos.x, + ent->tr.pos.y, + ent->tr.pos.z); + + // Matrix R = MatrixRotateXYZ((Vec3) { + // ent->tr.rot.x * DEG2RAD, + // ent->tr.rot.y * DEG2RAD, + // ent->tr.rot.z * DEG2RAD, + // }); + + Matrix R = QuaternionToMatrix(ent->tr.rot); + + Matrix S = MatrixScale( + ent->tr.scale.x, + ent->tr.scale.y, + ent->tr.scale.z); + + if (!ent->mdl.mdl) { + Asset *asset = asset_get(ent->mdl.key); + if (!asset) { + return; + } + ent->mdl.mdl = &asset->mdl; + } -// Model mdl = *ent->mdl.mdl; -// mdl.transform = MatrixMultiply(S, MatrixMultiply(R, T)); + Model mdl = *ent->mdl.mdl; + mdl.transform = MatrixMultiply(S, MatrixMultiply(R, T)); -// Color tint = ent->ed.selected ? -// (Color){ 100, 100, 100, 255 } : -// BLACK; + Color tint = ent->ed.selected ? + (Color){ 100, 100, 100, 255 } : + BLACK; -// DrawModel(mdl, (Vec3) {0}, 1, tint); -// } + DrawModel(mdl, (Vec3) {0}, 1, tint); +} // static void // entity_draw_col(u64 id) { @@ -371,14 +382,14 @@ entity_system_update(void) { void entity_system_draw_3d(void) { - // for (u32 i = 0; i < entity_count(); ++i) { - // u64 id = entity_id_at(i); - // Entity *ent = entity_get(id); - - // if (ent->mdl.has && ent->mdl.draw) { - // entity_draw_mdl(ent); - // } - // } + for (u32 i = 0; i < entity_count(); ++i) { + u64 id = entity_id_at(i); + Entity *ent = entity_get(id); + + if (ent->mdl.has && ent->mdl.draw) { + entity_draw_mdl(ent); + } + } } void |
