Skip to content

Commit

Permalink
C4Script.cpp: Replace some constant-like functions with a generic con…
Browse files Browse the repository at this point in the history
…stant template function
  • Loading branch information
maxmitti committed Jul 30, 2023
1 parent 152bc04 commit 14d5dfb
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/C4Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3250,12 +3250,6 @@ static C4ValueInt FnSetMass(C4ValueInt iValue, Required<C4ObjectOrThis> pObj)
return true;
}

static C4ValueInt FnGetColor(C4Object *pObj)
{
// oldgfx
return 0;
}

static C4ValueInt FnSetColor(C4ValueInt iValue, Required<C4ObjectOrThis> pObj)
{
if (!Inside<C4ValueInt>(iValue, 0, C4MaxColor - 1)) return false;
Expand Down Expand Up @@ -4156,9 +4150,6 @@ static C4Value FnGlobalN(C4String *name)
return pVarN->GetRef();
}

static C4ValueInt FnAnyContainer(C4AulContext *) { return ANY_CONTAINER; }
static C4ValueInt FnNoContainer(C4AulContext *) { return NO_CONTAINER; }

static std::optional<C4ValueInt> FnGetTime(C4AulContext *)
{
// check network, record, etc
Expand Down Expand Up @@ -4424,8 +4415,6 @@ static bool FnClearParticles(C4String *szName, C4Object *pObj)
return true;
}

static bool FnIsNewgfx(C4AulContext *) { return true; }

#define SkyPar_KEEP -163764

static void FnSetSkyParallax(C4ValueInt iMode, C4ValueInt iParX, C4ValueInt iParY, C4ValueInt iXDir, C4ValueInt iYDir, C4ValueInt iX, C4ValueInt iY)
Expand Down Expand Up @@ -6185,6 +6174,12 @@ static constexpr C4ScriptConstDef C4ScriptConstMap[] =
{ "C4PVM_Scrolling", C4V_Int, C4PVM_Scrolling },
};

template <auto val, typename... IgnorePars>
auto Constant(IgnorePars...)
{
return val;
}

void InitFunctionMap(C4AulScriptEngine *pEngine)
{
// add all def constants (all Int)
Expand Down Expand Up @@ -6339,8 +6334,8 @@ void InitFunctionMap(C4AulScriptEngine *pEngine)
AddFunc(pEngine, "AddVertex", FnAddVertex);
AddFunc(pEngine, "RemoveVertex", FnRemoveVertex);
AddFunc(pEngine, "SetContactDensity", FnSetContactDensity, false);
AddFunc(pEngine, "AnyContainer", FnAnyContainer);
AddFunc(pEngine, "NoContainer", FnNoContainer);
AddFunc(pEngine, "AnyContainer", Constant<ANY_CONTAINER>);
AddFunc(pEngine, "NoContainer", Constant<NO_CONTAINER>);
AddFunc(pEngine, "GetController", FnGetController);
AddFunc(pEngine, "SetController", FnSetController);
AddFunc(pEngine, "GetKiller", FnGetKiller);
Expand Down Expand Up @@ -6516,7 +6511,7 @@ void InitFunctionMap(C4AulScriptEngine *pEngine)
AddFunc(pEngine, "OnMessageBoardAnswer", FnOnMessageBoardAnswer, false);
AddFunc(pEngine, "ScriptCounter", Game.Script, &C4GameScriptHost::Counter);
AddFunc(pEngine, "SetMass", FnSetMass);
AddFunc(pEngine, "GetColor", FnGetColor);
AddFunc(pEngine, "GetColor", Constant<0, C4Object *>); // oldgfx
AddFunc(pEngine, "SetColor", FnSetColor);
AddFunc(pEngine, "SetFoW", FnSetFoW);
AddFunc(pEngine, "SetPlrViewRange", FnSetPlrViewRange);
Expand Down Expand Up @@ -6559,7 +6554,7 @@ void InitFunctionMap(C4AulScriptEngine *pEngine)
AddFunc(pEngine, "CastBackParticles", FnCastBackParticles);
AddFunc(pEngine, "PushParticles", FnPushParticles);
AddFunc(pEngine, "ClearParticles", FnClearParticles);
AddFunc(pEngine, "IsNewgfx", FnIsNewgfx, false);
AddFunc(pEngine, "IsNewgfx", Constant<true>, false);
AddFunc(pEngine, "SetSkyAdjust", Game.Landscape.Sky, &C4Sky::SetModulation);
AddFunc(pEngine, "SetMatAdjust", Game.Landscape, &C4Landscape::SetModulation);
AddFunc(pEngine, "GetSkyAdjust", Game.Landscape.Sky, &C4Sky::GetModulation);
Expand Down

0 comments on commit 14d5dfb

Please sign in to comment.