mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-01 06:00:45 +00:00
Allow Lua write access to camera_t variables & expose the cameras globally
This commit is contained in:
parent
e24fe29114
commit
366b1f65a1
2 changed files with 64 additions and 0 deletions
|
@ -384,6 +384,59 @@ static int camera_get(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int camera_set(lua_State *L)
|
||||
{
|
||||
camera_t *cam = *((camera_t **)luaL_checkudata(L, 1, META_CAMERA));
|
||||
enum cameraf field = luaL_checkoption(L, 2, NULL, camera_opt);
|
||||
|
||||
I_Assert(cam != NULL);
|
||||
|
||||
switch(field)
|
||||
{
|
||||
case camera_subsector:
|
||||
case camera_floorz:
|
||||
case camera_ceilingz:
|
||||
case camera_height:
|
||||
case camera_radius:
|
||||
return luaL_error(L, LUA_QL("camera_t") " field " LUA_QS " should not be set directly.", camera_opt[field]);
|
||||
case camera_chase:
|
||||
if (cam == &camera)
|
||||
CV_SetValue(&cv_chasecam, (INT32)luaL_checkboolean(L, 3));
|
||||
else if (cam == &camera2)
|
||||
CV_SetValue(&cv_chasecam2, (INT32)luaL_checkboolean(L, 3));
|
||||
else // ??? this should never happen, but ok
|
||||
cam->chase = luaL_checkboolean(L, 3);
|
||||
break;
|
||||
case camera_aiming:
|
||||
cam->aiming = luaL_checkangle(L, 3);
|
||||
break;
|
||||
case camera_x:
|
||||
cam->x = luaL_checkfixed(L, 3);
|
||||
break;
|
||||
case camera_y:
|
||||
cam->y = luaL_checkfixed(L, 3);
|
||||
break;
|
||||
case camera_z:
|
||||
cam->z = luaL_checkfixed(L, 3);
|
||||
break;
|
||||
case camera_angle:
|
||||
cam->angle = luaL_checkangle(L, 3);
|
||||
break;
|
||||
case camera_momx:
|
||||
cam->momx = luaL_checkfixed(L, 3);
|
||||
break;
|
||||
case camera_momy:
|
||||
cam->momy = luaL_checkfixed(L, 3);
|
||||
break;
|
||||
case camera_momz:
|
||||
cam->momz = luaL_checkfixed(L, 3);
|
||||
break;
|
||||
default:
|
||||
return luaL_error(L, LUA_QL("camera_t") " has no field named " LUA_QS, camera_opt[field]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// lib_draw
|
||||
//
|
||||
|
@ -1283,6 +1336,9 @@ int LUA_HudLib(lua_State *L)
|
|||
luaL_newmetatable(L, META_CAMERA);
|
||||
lua_pushcfunction(L, camera_get);
|
||||
lua_setfield(L, -2, "__index");
|
||||
|
||||
lua_pushcfunction(L, camera_set);
|
||||
lua_setfield(L, -2, "__newindex");
|
||||
lua_pop(L,1);
|
||||
|
||||
luaL_register(L, "hud", lib_hud);
|
||||
|
|
|
@ -393,6 +393,14 @@ int LUA_PushGlobals(lua_State *L, const char *word)
|
|||
} else if (fastcmp(word, "mouse2")) {
|
||||
LUA_PushUserdata(L, &mouse2, META_MOUSE);
|
||||
return 1;
|
||||
} else if (fastcmp(word, "camera")) {
|
||||
LUA_PushUserdata(L, &camera, META_CAMERA);
|
||||
return 1;
|
||||
} else if (fastcmp(word, "camera2")) {
|
||||
if (!splitscreen)
|
||||
return 0;
|
||||
LUA_PushUserdata(L, &camera2, META_CAMERA);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue