Cleanup changes

Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
2021-03-31 06:37:45 +02:00
parent 34e7514276
commit 8289c34652

View File

@@ -1,6 +1,5 @@
#include <evol/evol.h> #include <evol/evol.h>
#include <evol/common/ev_log.h> #include <evol/common/ev_log.h>
#include <assert.h>
#define TYPE_MODULE evmod_glfw #define TYPE_MODULE evmod_glfw
#include <evol/meta/type_import.h> #include <evol/meta/type_import.h>
@@ -16,6 +15,15 @@
#define NAMESPACE_MODULE evmod_physics #define NAMESPACE_MODULE evmod_physics
#include <evol/meta/namespace_import.h> #include <evol/meta/namespace_import.h>
#define EVENT_MODULE evmod_glfw
#include <evol/meta/event_include.h>
// Close window when Q is pressed
DECLARE_EVENT_LISTENER(keyPressedListener, (KeyPressedEvent *event) {
if(event->keyCode == 81) // tests if Q was pressed
Window->close();
})
#define IMPORT_NAMESPACES do { \ #define IMPORT_NAMESPACES do { \
IMPORT_NAMESPACE(ECS, ecs_module); \ IMPORT_NAMESPACE(ECS, ecs_module); \
IMPORT_NAMESPACE(Window, window_module); \ IMPORT_NAMESPACE(Window, window_module); \
@@ -31,7 +39,7 @@ typedef struct Cmp2 {
F32 dummy_f32; F32 dummy_f32;
} Component2; } Component2;
int cmp12(ECSQuery query) void TestSystem(ECSQuery query)
{ {
Component1 *cmp1 = ECS->getQueryColumn(query, sizeof(Component1), 1); Component1 *cmp1 = ECS->getQueryColumn(query, sizeof(Component1), 1);
Component2 *cmp2 = ECS->getQueryColumn(query, sizeof(Component2), 2); Component2 *cmp2 = ECS->getQueryColumn(query, sizeof(Component2), 2);
@@ -53,6 +61,9 @@ int main(int argc, char **argv)
evolmodule_t physics_module = evol_loadmodule("physics"); DEBUG_ASSERT(physics_module); evolmodule_t physics_module = evol_loadmodule("physics"); DEBUG_ASSERT(physics_module);
IMPORT_NAMESPACES; IMPORT_NAMESPACES;
IMPORT_EVENTS_evmod_glfw(window_module);
ACTIVATE_EVENT_LISTENER(keyPressedListener, KeyPressedEvent);
ECS->newScene(); ECS->newScene();
@@ -72,15 +83,14 @@ int main(int argc, char **argv)
ECS->addComponent(ent2, Cmp1_ID, sizeof(Component1), &c12); ECS->addComponent(ent2, Cmp1_ID, sizeof(Component1), &c12);
ECS->addComponent(ent2, Cmp2_ID, sizeof(Component2), &c2); ECS->addComponent(ent2, Cmp2_ID, sizeof(Component2), &c2);
ECS->registerSystem("Component1, Component2", EV_ECS_PIPELINE_STAGE_UPDATE, cmp12, "cmp12"); ECS->registerSystem("Component1, Component2", EV_ECS_PIPELINE_STAGE_UPDATE, TestSystem, "TestSystem");
bool result = 0; bool result = 0;
while(true) { while(result == 0) {
result |= EventSystem.progress();
result |= Window->update(0.0); result |= Window->update(0.0);
result |= ECS->update(0.0); result |= ECS->update(0.0);
result |= Physics->update(0.0); result |= Physics->update(0.0);
if(result) break;
} }
evol_unloadmodule(physics_module); evol_unloadmodule(physics_module);