Skip to content
Permalink
Browse files

Add `GetCurrentCamera`, tableless `GetCameraState` (#454)

* Add `GetCurrentCamera`, tableless `GetCameraState`

`Spring.GetCurrentCamera` returns the name of the current camera,
for example "ta" or "spring" (currently available under the `name`
key in the table returned by `Spring.GetCameraState`).

`Spring.GetCameraState` now accepts a boolean parameter; if it is
false then instead of allocating a table, it returns cam-specific
values onto the stack (use `GetCurrentCamera` first to know how to
interpret them; use `GetCamera{Position,Direction,FOV}` to get the
non-specific values from the base class). The returned values are:
  fps, rot -> oldHeight
  ta -> height, angle, flipped
  spring -> rx, ry, rz, dist
  free -> rx, ry, rz, vx, vy, vz, avx, avy, avz
  ov -> (nil)

* `Spring.GetCameraState(false)` also pushes camname

* changelog++

* rm `GetCurrentCamera`, header

* rm `GetCurrentCamera`, cpp part

* rm `GetCurrentCamera`, txt part
  • Loading branch information...
sprunk authored and ashdnazg committed May 14, 2019
1 parent 52b1816 commit b0ebe8e04ffd7be1862af2212606376c2ac7a16b
Showing with 53 additions and 3 deletions.
  1. +7 −0 doc/changelog.txt
  2. +46 −3 rts/Lua/LuaUnsyncedRead.cpp
@@ -148,6 +148,13 @@ Lua:
the (now) last return value, the customKeys table (allocation optimisation)
! Spring.GetUnit{Armored,IsActive} now works on enemies in LoS
! Spring.GetUnitMass no longer works on enemies outside of LoS
- Added a boolean parameter to Spring.GetCameraState, if set to false it will return the current camera name
and then the following camera-specific values on the stack:
fps, rot -> oldHeight
ta -> height, angle, flipped
spring -> rx, ry, rz, dist
free -> rx, ry, rz, vx, vy, vz, avx, avy, avz
ov -> (nil)

AI:
- reveal unit's captureProgress, buildProgress and paralyzeDamage params through
@@ -1429,15 +1429,58 @@ int LuaUnsyncedRead::GetCameraNames(lua_State* L)

int LuaUnsyncedRead::GetCameraState(lua_State* L)
{
CCameraController::StateMap camState;
camHandler->GetState(camState);

if (!luaL_optboolean(L, 1, true)) {
// table-less version; pushes just the name and the cam-specific values
// use GetCamera{Position,Direction,FOV} for the common fields from the base class
lua_pushsstring(L, camHandler->GetCurrentController().GetName());

switch (camHandler->GetCurrentControllerNum()) {
case CCameraHandler::CAMERA_MODE_FIRSTPERSON:
case CCameraHandler::CAMERA_MODE_ROTOVERHEAD: // happens to have the same set of values as FPS
lua_pushnumber(L, camState["oldHeight"]);
return 1 + 1;

case CCameraHandler::CAMERA_MODE_OVERHEAD:
lua_pushnumber(L, camState["height"]);
lua_pushnumber(L, camState["angle"]);
lua_pushnumber(L, camState["flipped"]);
return 1 + 3;

case CCameraHandler::CAMERA_MODE_SPRING:
lua_pushnumber(L, camState["rx"]);
lua_pushnumber(L, camState["ry"]);
lua_pushnumber(L, camState["rz"]);
lua_pushnumber(L, camState["dist"]);
return 1 + 4;

case CCameraHandler::CAMERA_MODE_FREE:
lua_pushnumber(L, camState["rx"]);
lua_pushnumber(L, camState["ry"]);
lua_pushnumber(L, camState["rz"]);
lua_pushnumber(L, camState["vx"]);
lua_pushnumber(L, camState["vy"]);
lua_pushnumber(L, camState["vz"]);
lua_pushnumber(L, camState["avx"]);
lua_pushnumber(L, camState["avy"]);
lua_pushnumber(L, camState["avz"]);
return 1 + 9;

case CCameraHandler::CAMERA_MODE_OVERVIEW:
default:
// overview has no extra values
return 1 + 0;
}
}

lua_newtable(L);

lua_pushliteral(L, "name");
lua_pushsstring(L, (camHandler->GetCurrentController()).GetName());
lua_rawset(L, -3);

CCameraController::StateMap camState;
camHandler->GetState(camState);

for (const auto& s: camState) {
lua_pushsstring(L, s.first);
lua_pushnumber(L, s.second);

0 comments on commit b0ebe8e

Please sign in to comment.
You can’t perform that action at this time.