From f03551b714c66c11b46a879d4adefafc8d00da74 Mon Sep 17 00:00:00 2001 From: Robear Selwans Date: Tue, 6 Apr 2021 14:38:31 +0200 Subject: [PATCH] Tons of changes through time --- src/main.c | 59 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 3b15ffb..fcd6fd4 100644 --- a/src/main.c +++ b/src/main.c @@ -1,27 +1,28 @@ #include #include +#include #define TYPE_MODULE evmod_glfw #include -#define TYPE_MODULE evmod_ecs -#include -#define TYPE_MODULE evmod_physics -#include - #define NAMESPACE_MODULE evmod_glfw #include -#define NAMESPACE_MODULE evmod_ecs -#include -#define NAMESPACE_MODULE evmod_physics -#include - #define EVENT_MODULE evmod_glfw #include +#define TYPE_MODULE evmod_ecs +#include +#define NAMESPACE_MODULE evmod_ecs +#include + +#define TYPE_MODULE evmod_physics +#include +#define NAMESPACE_MODULE evmod_physics +#include + // Close window when Q is pressed DECLARE_EVENT_LISTENER(keyPressedListener, (KeyPressedEvent *event) { if(event->keyCode == 81) // tests if Q was pressed - Window->close(); + Window->setShouldClose(event->handle, true); }) #define IMPORT_NAMESPACES do { \ @@ -39,14 +40,16 @@ typedef struct Cmp2 { F32 dummy_f32; } Component2; -void TestSystem(ECSQuery query) +void +TestSystem( + ECSQuery query) { Component1 *cmp1 = ECS->getQueryColumn(query, sizeof(Component1), 1); Component2 *cmp2 = ECS->getQueryColumn(query, sizeof(Component2), 2); U32 count = ECS->getQueryMatchCount(query); for(int i = 1; i <= count; ++i) { - ev_log_trace("Iteration #%d, cmp1: {%d}", i, cmp1[i-1].dummy_i32); + // ev_log_trace("Iteration #%d, cmp1: {%d}", i, cmp1[i-1].dummy_i32); } } @@ -63,6 +66,8 @@ int main(int argc, char **argv) IMPORT_NAMESPACES; IMPORT_EVENTS_evmod_glfw(window_module); + WindowHandle windowHandle = Window->create(800, 600, "Main Window"); + ACTIVATE_EVENT_LISTENER(keyPressedListener, KeyPressedEvent); ECS->newScene(); @@ -85,12 +90,34 @@ int main(int argc, char **argv) ECS->registerSystem("Component1, Component2", EV_ECS_PIPELINE_STAGE_UPDATE, TestSystem, "TestSystem"); - bool result = 0; + CollisionShape boxCollider = Physics->createBoxShape(1., 1., 1.); + RigidBodyInfo rbInfo = { + .type = EV_RIGIDBODY_DYNAMIC, + .collisionShape = boxCollider, + .mass = 1.0, + .restitution = 1.0 + }; + RigidBody box = Physics->createRigidBody(&rbInfo); + Physics->setRigidBodyPosition(box, Vec3(0, 10, -10)); + + CollisionShape groundCollider = Physics->createBoxShape(5., 5., 5.); + RigidBodyInfo groundRbInfo = { + .type = EV_RIGIDBODY_STATIC, + .collisionShape = groundCollider, + .restitution = 1.0 + }; + RigidBody ground = Physics->createRigidBody(&groundRbInfo); + Physics->setRigidBodyPosition(ground, Vec3(0, -10, -10)); + + U32 result = 0; while(result == 0) { + ev_BeginCPUSample(NewFrame, 0); result |= EventSystem.progress(); - result |= Window->update(0.0); + result |= Window->update(windowHandle); result |= ECS->update(0.0); - result |= Physics->update(0.0); + result |= Physics->update(0.017); + Sleep(17); + ev_EndCPUSample(); } evol_unloadmodule(physics_module);