Fix codestyle since CSM Camera API

master
Loic Blot 2017-05-06 21:30:27 +02:00
parent 07c17db114
commit a024042bf5
No known key found for this signature in database
GPG Key ID: EFAA458E8C153987
2 changed files with 42 additions and 48 deletions

View File

@ -12,16 +12,16 @@ LuaCamera::LuaCamera(Camera *m)
void LuaCamera::create(lua_State *L, Camera *m) void LuaCamera::create(lua_State *L, Camera *m)
{ {
LuaCamera *o = new LuaCamera(m); LuaCamera *o = new LuaCamera(m);
*(void **) (lua_newuserdata(L, sizeof(void *))) = o; *(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, className); luaL_getmetatable(L, className);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
int camera_object = lua_gettop(L); int camera_object = lua_gettop(L);
lua_getglobal(L, "core"); lua_getglobal(L, "core");
luaL_checktype(L, -1, LUA_TTABLE); luaL_checktype(L, -1, LUA_TTABLE);
int coretable = lua_gettop(L); int coretable = lua_gettop(L);
lua_pushvalue(L, camera_object); lua_pushvalue(L, camera_object);
lua_setfield(L, coretable, "camera"); lua_setfield(L, coretable, "camera");
} }
@ -35,7 +35,7 @@ int LuaCamera::l_set_camera_mode(lua_State *L)
sanity_check(playercao); sanity_check(playercao);
if (!lua_isnumber(L, 2)) if (!lua_isnumber(L, 2))
return 0; return 0;
camera->setCameraMode((CameraMode)((int)lua_tonumber(L, 2))); camera->setCameraMode((CameraMode)((int)lua_tonumber(L, 2)));
playercao->setVisible(camera->getCameraMode() > CAMERA_MODE_FIRST); playercao->setVisible(camera->getCameraMode() > CAMERA_MODE_FIRST);
playercao->setChildrenVisible(camera->getCameraMode() > CAMERA_MODE_FIRST); playercao->setChildrenVisible(camera->getCameraMode() > CAMERA_MODE_FIRST);
@ -47,9 +47,9 @@ int LuaCamera::l_get_camera_mode(lua_State *L)
Camera *camera = getobject(L, 1); Camera *camera = getobject(L, 1);
if (!camera) if (!camera)
return 0; return 0;
lua_pushnumber(L, (int)camera->getCameraMode()); lua_pushnumber(L, (int)camera->getCameraMode());
return 1; return 1;
} }
@ -58,7 +58,7 @@ int LuaCamera::l_get_fov(lua_State *L)
Camera *camera = getobject(L, 1); Camera *camera = getobject(L, 1);
if (!camera) if (!camera)
return 0; return 0;
lua_newtable(L); lua_newtable(L);
lua_pushnumber(L, camera->getFovX() * core::DEGTORAD); lua_pushnumber(L, camera->getFovX() * core::DEGTORAD);
lua_setfield(L, -2, "x"); lua_setfield(L, -2, "x");
@ -76,7 +76,7 @@ int LuaCamera::l_get_pos(lua_State *L)
Camera *camera = getobject(L, 1); Camera *camera = getobject(L, 1);
if (!camera) if (!camera)
return 0; return 0;
push_v3f(L, camera->getPosition()); push_v3f(L, camera->getPosition());
return 1; return 1;
} }
@ -86,7 +86,7 @@ int LuaCamera::l_get_offset(lua_State *L)
Camera *camera = getobject(L, 1); Camera *camera = getobject(L, 1);
if (!camera) if (!camera)
return 0; return 0;
push_v3s16(L, camera->getOffset()); push_v3s16(L, camera->getOffset());
return 1; return 1;
} }
@ -127,7 +127,7 @@ int LuaCamera::l_get_aspect_ratio(lua_State *L)
Camera *camera = getobject(L, 1); Camera *camera = getobject(L, 1);
if (!camera) if (!camera)
return 0; return 0;
lua_pushnumber(L, camera->getCameraNode()->getAspectRatio()); lua_pushnumber(L, camera->getCameraNode()->getAspectRatio());
return 1; return 1;
} }
@ -135,12 +135,12 @@ int LuaCamera::l_get_aspect_ratio(lua_State *L)
LuaCamera *LuaCamera::checkobject(lua_State *L, int narg) LuaCamera *LuaCamera::checkobject(lua_State *L, int narg)
{ {
luaL_checktype(L, narg, LUA_TUSERDATA); luaL_checktype(L, narg, LUA_TUSERDATA);
void *ud = luaL_checkudata(L, narg, className); void *ud = luaL_checkudata(L, narg, className);
if (!ud) if (!ud)
luaL_typerror(L, narg, className); luaL_typerror(L, narg, className);
return *(LuaCamera **) ud; return *(LuaCamera **)ud;
} }
Camera *LuaCamera::getobject(LuaCamera *ref) Camera *LuaCamera::getobject(LuaCamera *ref)
@ -160,7 +160,7 @@ Camera *LuaCamera::getobject(lua_State *L, int narg)
int LuaCamera::gc_object(lua_State *L) int LuaCamera::gc_object(lua_State *L)
{ {
LuaCamera *o = *(LuaCamera **) (lua_touserdata(L, 1)); LuaCamera *o = *(LuaCamera **)(lua_touserdata(L, 1));
delete o; delete o;
return 0; return 0;
} }
@ -171,36 +171,32 @@ void LuaCamera::Register(lua_State *L)
int methodtable = lua_gettop(L); int methodtable = lua_gettop(L);
luaL_newmetatable(L, className); luaL_newmetatable(L, className);
int metatable = lua_gettop(L); int metatable = lua_gettop(L);
lua_pushliteral(L, "__metatable"); lua_pushliteral(L, "__metatable");
lua_pushvalue(L, methodtable); lua_pushvalue(L, methodtable);
lua_settable(L, metatable); lua_settable(L, metatable);
lua_pushliteral(L, "__index"); lua_pushliteral(L, "__index");
lua_pushvalue(L, methodtable); lua_pushvalue(L, methodtable);
lua_settable(L, metatable); lua_settable(L, metatable);
lua_pushliteral(L, "__gc"); lua_pushliteral(L, "__gc");
lua_pushcfunction(L, gc_object); lua_pushcfunction(L, gc_object);
lua_settable(L, metatable); lua_settable(L, metatable);
lua_pop(L, 1); lua_pop(L, 1);
luaL_openlib(L, 0, methods, 0); luaL_openlib(L, 0, methods, 0);
lua_pop(L, 1); lua_pop(L, 1);
} }
const char LuaCamera::className[] = "Camera"; const char LuaCamera::className[] = "Camera";
const luaL_reg LuaCamera::methods[] = { const luaL_reg LuaCamera::methods[] = {luamethod(LuaCamera, set_camera_mode),
luamethod(LuaCamera, set_camera_mode), luamethod(LuaCamera, get_camera_mode), luamethod(LuaCamera, get_fov),
luamethod(LuaCamera, get_camera_mode), luamethod(LuaCamera, get_pos), luamethod(LuaCamera, get_offset),
luamethod(LuaCamera, get_fov), luamethod(LuaCamera, get_look_dir),
luamethod(LuaCamera, get_pos), luamethod(LuaCamera, get_look_vertical),
luamethod(LuaCamera, get_offset), luamethod(LuaCamera, get_look_horizontal),
luamethod(LuaCamera, get_look_dir), luamethod(LuaCamera, get_aspect_ratio),
luamethod(LuaCamera, get_look_vertical),
luamethod(LuaCamera, get_look_horizontal), {0, 0}};
luamethod(LuaCamera, get_aspect_ratio),
{0, 0}
};

View File

@ -5,42 +5,40 @@
class Camera; class Camera;
class LuaCamera : public ModApiBase { class LuaCamera : public ModApiBase
private: {
private:
static const char className[]; static const char className[];
static const luaL_Reg methods[]; static const luaL_Reg methods[];
// garbage collector // garbage collector
static int gc_object(lua_State *L); static int gc_object(lua_State *L);
static int l_set_camera_mode(lua_State *L); static int l_set_camera_mode(lua_State *L);
static int l_get_camera_mode(lua_State *L); static int l_get_camera_mode(lua_State *L);
static int l_get_fov(lua_State *L); static int l_get_fov(lua_State *L);
static int l_get_pos(lua_State *L); static int l_get_pos(lua_State *L);
static int l_get_offset(lua_State *L); static int l_get_offset(lua_State *L);
static int l_get_look_dir(lua_State *L); static int l_get_look_dir(lua_State *L);
static int l_get_look_vertical(lua_State *L); static int l_get_look_vertical(lua_State *L);
static int l_get_look_horizontal(lua_State *L); static int l_get_look_horizontal(lua_State *L);
static int l_get_aspect_ratio(lua_State *L); static int l_get_aspect_ratio(lua_State *L);
Camera *m_camera;
public:
Camera *m_camera;
public:
LuaCamera(Camera *m); LuaCamera(Camera *m);
~LuaCamera() {} ~LuaCamera() {}
static void create(lua_State *L, Camera *m); static void create(lua_State *L, Camera *m);
static LuaCamera *checkobject(lua_State *L, int narg); static LuaCamera *checkobject(lua_State *L, int narg);
static Camera *getobject(LuaCamera *ref); static Camera *getobject(LuaCamera *ref);
static Camera *getobject(lua_State *L, int narg); static Camera *getobject(lua_State *L, int narg);
static void Register(lua_State *L); static void Register(lua_State *L);
}; };
#endif // L_CAMERA_H #endif // L_CAMERA_H