Skip to content

Commit

Permalink
fix #6331
Browse files Browse the repository at this point in the history
add /camtime{factor,exponent} commands
parse optional factor (#3) and exponent (#4) camera
state-transition parameters in Spring.SetCameraState
  • Loading branch information
rtri committed Nov 11, 2019
1 parent 7318ff0 commit 266b51a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
22 changes: 19 additions & 3 deletions rts/Game/CameraHandler.cpp
Expand Up @@ -137,6 +137,9 @@ void CCameraHandler::Init()
RegisterAction("viewsave");
RegisterAction("viewload");

RegisterAction("camtimefactor");
RegisterAction("camtimeexponent");

SortRegisteredActions();
}

Expand Down Expand Up @@ -505,12 +508,12 @@ void CCameraHandler::PushAction(const Action& action)
case hashString("viewsave"): {
if (!action.extra.empty()) {
SaveView(action.extra);
LOG("Saved view: %s", action.extra.c_str());
LOG("[CamHandler::%s] saved view \"%s\"", __func__, action.extra.c_str());
}
} break;
case hashString("viewload"): {
if (!LoadView(action.extra))
LOG_L(L_WARNING, "Loading view failed!");
if (LoadView(action.extra))
LOG("[CamHandler::%s] loaded view \"%s\"", __func__, action.extra.c_str());

} break;

Expand All @@ -520,6 +523,19 @@ void CCameraHandler::PushAction(const Action& action)
case hashString("togglecammode"): {
ToggleState();
} break;

case hashString("camtimefactor"): {
if (!action.extra.empty())
camTransState.timeFactor = std::atof(action.extra.c_str());

LOG("[CamHandler::%s] set transition-time factor to %f", __func__, camTransState.timeFactor);
} break;
case hashString("camtimeexponent"): {
if (!action.extra.empty())
camTransState.timeExponent = std::atof(action.extra.c_str());

LOG("[CamHandler::%s] set transition-time exponent to %f", __func__, camTransState.timeExponent);
} break;
}
}

Expand Down
8 changes: 8 additions & 0 deletions rts/Game/CameraHandler.h
Expand Up @@ -59,6 +59,10 @@ class CCameraHandler : public CommandReceiver
void PushMode();
void PopMode();

void SetTransitionParams(float factor, float expon) {
camTransState.timeFactor = factor;
camTransState.timeExponent = expon;
}
void CameraTransition(float nsecs);
void UpdateTransition();

Expand All @@ -73,6 +77,9 @@ class CCameraHandler : public CommandReceiver
int GetModeIndex(const std::string& modeName) const;
unsigned int GetCurrentControllerNum() const { return currCamCtrlNum; }

float GetTransitionTimeFactor() const { return camTransState.timeFactor; }
float GetTransitionTimeExponent() const { return camTransState.timeExponent; }


/**
* @brief write current camera settings in a vector
Expand Down Expand Up @@ -110,6 +117,7 @@ class CCameraHandler : public CommandReceiver

float timeStart = 0.0f;
float timeEnd = 0.0f;
// configurable parameters
float timeFactor = 0.0f;
float timeExponent = 0.0f;
};
Expand Down
3 changes: 2 additions & 1 deletion rts/Lua/LuaUnsyncedCtrl.cpp
Expand Up @@ -852,8 +852,9 @@ int LuaUnsyncedCtrl::SetCameraState(lua_State* L)
return 0;

if (!lua_istable(L, 1))
luaL_error(L, "Incorrect arguments to SetCameraState(table[, camTime])");
luaL_error(L, "[%s(stateTable[, camTransTime[, transTimeFactor[, transTimeExpon] ] ])] incorrect arguments", __func__);

camHandler->SetTransitionParams(luaL_optfloat(L, 3, camHandler->GetTransitionTimeFactor()), luaL_optfloat(L, 4, camHandler->GetTransitionTimeExponent()));
camHandler->CameraTransition(luaL_optfloat(L, 2, 0.0f));

const bool retval = camHandler->SetState(ParseCamStateMap(L, 1));
Expand Down

0 comments on commit 266b51a

Please sign in to comment.