diff options
author | quou <quou@disroot.org> | 2025-01-18 16:19:41 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2025-01-18 16:19:41 +1100 |
commit | cf2abfcfe34a9b3e4cf5af193d1f320374416267 (patch) | |
tree | c0f209ac730fa8a8b4564c818b3ce44fec59ffeb /c2.cpp | |
parent | 025510f2928e123d12a7d6d3574ca70fdd9d7717 (diff) |
convert models and editor to use ecs
Diffstat (limited to 'c2.cpp')
-rw-r--r-- | c2.cpp | 49 |
1 files changed, 34 insertions, 15 deletions
@@ -3,8 +3,10 @@ #include "debugdraw.hpp" #include "editor.hpp" #include "model.hpp" +#include "scene.hpp" #include "ui.hpp" #include "video.hpp" +#include "world.hpp" extern "C" { #include "plat.h" #include "memory.h" @@ -571,7 +573,7 @@ struct C2 : public App { Texture* texture; Texture* texture2; Texture_Id default_texture; - Model_Instance* monkey, * monkey2; + Entity_Id monkey, monkey2; Model_Scene scene; Orbit_Cam camera; Fullscreen_Quad quad; @@ -580,6 +582,7 @@ struct C2 : public App { Buffer_Id vbo, cbuf; Sampler_Id clamped_linear; Line_Renderer lr; + World* world; UI* ui; UI::Label* fps_label; void* per_frame; @@ -643,17 +646,27 @@ struct C2 : public App { ui->layout(w, h); fps_label = ui->create_element<UI::Label>(ui->root, ""); scene.init(&scene_arena, 32, clamped_linear); - monkey = scene.instantiate( - dev, - (Model*)assets.load("monkey.mdl") - ); - monkey2 = scene.instantiate( - dev, - (Model*)assets.load("monkey.mdl") - ); sky.init(dev, &assets); eprobe.init(dev, &assets, 256); camera.init(); + world = (World*)arena_alloc(arena, sizeof *world); + world->init(arena); + { + monkey = world->create_entity(); + auto [_, mod] = world->add<Transform, C_Model>(monkey); + mod.i = scene.instantiate( + dev, + (Model*)assets.load("monkey.mdl") + ); + } + { + monkey2 = world->create_entity(); + auto [_, mod] = world->add<Transform, C_Model>(monkey2); + mod.i = scene.instantiate( + dev, + (Model*)assets.load("monkey.mdl") + ); + } } void on_update() override { @@ -738,7 +751,7 @@ struct C2 : public App { ctx.debug_pop(); Texture& bb = dev->get_texture(dev->get_backbuffer()); - monkey->transform = m4f::translate( + world->get<Transform>(monkey).mat = m4f::translate( m4f::identity(), v3f(0.0f, 0.0f, 0.0f) ) * m4f::rotate( @@ -746,7 +759,7 @@ struct C2 : public App { rot, raxis ); - monkey2->transform = m4f::translate( + world->get<Transform>(monkey2).mat = m4f::translate( m4f::identity(), v3f(2.0f, 0.0f, 2.0f) ) * m4f::rotate( @@ -757,7 +770,7 @@ struct C2 : public App { camera.asp = (float)bb.w / (float)bb.h; camera.update_orbit(*this); camera.update(); - scene.update(camera, dev); + update_scene(scene, dev, camera, *world); ctx.debug_push("scene"); ctx.debug_push("depth prepass"); scene.render(dev, &frame_arena, depth_prepass, 0, clamped_linear); @@ -783,8 +796,15 @@ struct C2 : public App { ctx.debug_pop(); if (mjp(mbtn_left)) { - auto [a, b] = scene.pick(camera, w, h, mx, my); - editor_on_select(a, b); + auto [a, b] = scene_pick( + *world, + camera, + w, + h, + mx, + my + ); + editor_on_select(*world, a, b); } lr.colour(v3f(1.0f, 0.0f, 0.0f)); @@ -830,7 +850,6 @@ struct C2 : public App { } }; - extern "C" App* entrypoint(Arena* mem) { C2* a = (C2*)arena_alloc(mem, sizeof *a); new(a) C2(); |