This commit is contained in:
bjorn 2017-05-15 23:02:08 -06:00
parent 7597e71ff3
commit 70bc90154b
5 changed files with 37 additions and 0 deletions

View File

@ -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;

View File

@ -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 }
};

6
src/api/types/world.c Normal file
View File

@ -0,0 +1,6 @@
#include "api/lovr.h"
#include "physics/physics.h"
const luaL_Reg lovrWorld[] = {
{ NULL, NULL }
};

View File

@ -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);
}

View File

@ -1,5 +1,13 @@
#include "util.h"
#include <ode/ode.h>
typedef struct {
Ref ref;
dWorldID id;
} World;
void lovrPhysicsInit();
void lovrPhysicsDestroy();
World* lovrWorldCreate();
void lovrWorldDestroy(const Ref* ref);