From 70bc90154b7f68b8b044bc5b0385b9212a5e11ec Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 15 May 2017 23:02:08 -0600 Subject: [PATCH] World; --- src/api/lovr.h | 1 + src/api/physics.c | 7 +++++++ src/api/types/world.c | 6 ++++++ src/physics/physics.c | 15 +++++++++++++++ src/physics/physics.h | 8 ++++++++ 5 files changed, 37 insertions(+) create mode 100644 src/api/types/world.c diff --git a/src/api/lovr.h b/src/api/lovr.h index 191f68f8..544fc49e 100644 --- a/src/api/lovr.h +++ b/src/api/lovr.h @@ -31,6 +31,7 @@ extern const luaL_Reg lovrSource[]; extern const luaL_Reg lovrTexture[]; extern const luaL_Reg lovrTimer[]; extern const luaL_Reg lovrTransform[]; +extern const luaL_Reg lovrWorld[]; extern map_int_t BlendAlphaModes; extern map_int_t BlendModes; diff --git a/src/api/physics.c b/src/api/physics.c index 5e03e541..9243daa6 100644 --- a/src/api/physics.c +++ b/src/api/physics.c @@ -4,10 +4,17 @@ int l_lovrPhysicsInit(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrPhysics); + luax_registertype(L, "World", lovrWorld); lovrPhysicsInit(); return 1; } +int l_lovrPhysicsNewWorld(lua_State* L) { + luax_pushtype(L, World, lovrWorldCreate()); + return 1; +} + const luaL_Reg lovrPhysics[] = { + { "newWorld", l_lovrPhysicsNewWorld }, { NULL, NULL } }; diff --git a/src/api/types/world.c b/src/api/types/world.c new file mode 100644 index 00000000..d0950c8c --- /dev/null +++ b/src/api/types/world.c @@ -0,0 +1,6 @@ +#include "api/lovr.h" +#include "physics/physics.h" + +const luaL_Reg lovrWorld[] = { + { NULL, NULL } +}; diff --git a/src/physics/physics.c b/src/physics/physics.c index dddf3c05..49e723ab 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -14,3 +14,18 @@ void lovrPhysicsInit() { void lovrPhysicsDestroy() { dCloseODE(); } + +World* lovrWorldCreate() { + World* world = lovrAlloc(sizeof(World), lovrWorldDestroy); + if (!world) return NULL; + + world->id = dWorldCreate(); + + return world; +} + +void lovrWorldDestroy(const Ref* ref) { + World* world = containerof(ref, World); + dWorldDestroy(world->id); + free(world); +} diff --git a/src/physics/physics.h b/src/physics/physics.h index a3904b5b..7bc2a615 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -1,5 +1,13 @@ #include "util.h" #include +typedef struct { + Ref ref; + dWorldID id; +} World; + void lovrPhysicsInit(); void lovrPhysicsDestroy(); + +World* lovrWorldCreate(); +void lovrWorldDestroy(const Ref* ref);