Use void instead of C4Void for engine functions that always return nil

This allows the removal of quite a few return C4Void();.

Also stop pretending that Nillable<void> is the same class as Nillable<T>.
Its only function was as an implementation detail for C4Void, which doesn't
need any implementation details anymore.
epoxy
Günther Brammer 2016-01-03 02:39:11 +01:00
parent f78d7712a5
commit 5287121d86
5 changed files with 64 additions and 118 deletions

View File

@ -50,10 +50,9 @@ static bool FnIncinerateLandscape(C4PropList * _this, long iX, long iY, long cau
return !!::Landscape.Incinerate(iX, iY, caused_by_plr);
}
static C4Void FnSetGravity(C4PropList * _this, long iGravity)
static void FnSetGravity(C4PropList * _this, long iGravity)
{
::Landscape.Gravity = C4REAL100(Clamp<long>(iGravity,-1000,1000));
return C4Void();
}
static long FnGetGravity(C4PropList * _this)
@ -483,13 +482,12 @@ static long FnExtractMaterialAmount(C4PropList * _this, long x, long y, long mat
return extracted;
}
static C4Void FnBlastFree(C4PropList * _this, long iX, long iY, long iLevel, Nillable<long> iCausedBy, Nillable<long> iMaxDensity)
static void FnBlastFree(C4PropList * _this, long iX, long iY, long iLevel, Nillable<long> iCausedBy, Nillable<long> iMaxDensity)
{
if (iCausedBy.IsNil() && Object(_this)) iCausedBy = Object(_this)->Controller;
if (iMaxDensity.IsNil()) iMaxDensity = C4M_Vehicle;
::Landscape.BlastFree(iX, iY, iLevel, iCausedBy, Object(_this), iMaxDensity);
return C4Void();
}
static bool FnSoundAt(C4PropList * _this, C4String *szSound, long iX, long iY, Nillable<long> iLevel, Nillable<long> iAtPlayer, long iCustomFalloffDistance, long iPitch, C4PropList *modifier_props)
@ -815,11 +813,10 @@ static long FnGetPlrViewMode(C4PropList * _this, long iPlr)
return ::Players.Get(iPlr)->ViewMode;
}
static C4Void FnResetCursorView(C4PropList * _this, long plr, bool immediate_position)
static void FnResetCursorView(C4PropList * _this, long plr, bool immediate_position)
{
C4Player *pplr = ::Players.Get(plr);
if (pplr) pplr->ResetCursorView(immediate_position);
return C4Void();
}
static C4Object *FnGetPlrView(C4PropList * _this, long iPlr)
@ -1215,16 +1212,14 @@ static long FnGetWind(C4PropList * _this, long x, long y, bool fGlobal)
return ::Weather.GetWind(x,y);
}
static C4Void FnSetWind(C4PropList * _this, long iWind)
static void FnSetWind(C4PropList * _this, long iWind)
{
::Weather.SetWind(iWind);
return C4Void();
}
static C4Void FnSetTemperature(C4PropList * _this, long iTemperature)
static void FnSetTemperature(C4PropList * _this, long iTemperature)
{
::Weather.SetTemperature(iTemperature);
return C4Void();
}
static long FnGetTemperature(C4PropList * _this)
@ -1232,11 +1227,10 @@ static long FnGetTemperature(C4PropList * _this)
return ::Weather.GetTemperature();
}
static C4Void FnSetAmbientBrightness(C4PropList * _this, long iBrightness)
static void FnSetAmbientBrightness(C4PropList * _this, long iBrightness)
{
if (::Landscape.pFoW)
::Landscape.pFoW->Ambient.SetBrightness(iBrightness / 100.);
return C4Void();
}
static long FnGetAmbientBrightness(C4PropList * _this)
@ -1246,10 +1240,9 @@ static long FnGetAmbientBrightness(C4PropList * _this)
return static_cast<long>(::Landscape.pFoW->Ambient.GetBrightness() * 100. + 0.5);
}
static C4Void FnSetSeason(C4PropList * _this, long iSeason)
static void FnSetSeason(C4PropList * _this, long iSeason)
{
::Weather.SetSeason(iSeason);
return C4Void();
}
static long FnGetSeason(C4PropList * _this)
@ -1257,10 +1250,9 @@ static long FnGetSeason(C4PropList * _this)
return ::Weather.GetSeason();
}
static C4Void FnSetClimate(C4PropList * _this, long iClimate)
static void FnSetClimate(C4PropList * _this, long iClimate)
{
::Weather.SetClimate(iClimate);
return C4Void();
}
static long FnGetClimate(C4PropList * _this)
@ -1278,10 +1270,9 @@ static long FnLandscapeHeight(C4PropList * _this)
return GBackHgt;
}
static C4Void FnShakeFree(C4PropList * _this, long x, long y, long rad)
static void FnShakeFree(C4PropList * _this, long x, long y, long rad)
{
::Landscape.ShakeFree(x,y,rad);
return C4Void();
}
static long FnDigFree(C4PropList * _this, long x, long y, long rad, bool no_dig2objects, bool no_instability_check)
@ -1294,10 +1285,9 @@ static long FnDigFreeRect(C4PropList * _this, long iX, long iY, long iWdt, long
return ::Landscape.DigFreeRect(iX,iY,iWdt,iHgt,Object(_this),no_dig2objects,no_instability_check);
}
static C4Void FnClearFreeRect(C4PropList * _this, long iX, long iY, long iWdt, long iHgt)
static void FnClearFreeRect(C4PropList * _this, long iX, long iY, long iWdt, long iHgt)
{
::Landscape.ClearFreeRect(iX,iY,iWdt,iHgt);
return C4Void();
}
static bool FnPathFree(C4PropList * _this, long X1, long Y1, long X2, long Y2)
@ -1420,14 +1410,12 @@ static bool FnAbortMessageBoard(C4PropList * _this, C4Object *pObj, long iForPlr
return pPlr->RemoveMessageBoardQuery(pObj);
}
static C4Void FnSetFoW(C4PropList * _this, bool fEnabled, long iPlr)
static void FnSetFoW(C4PropList * _this, bool fEnabled, long iPlr)
{
// safety
if (!ValidPlr(iPlr)) return C4Void();
if (!ValidPlr(iPlr)) return;
// set enabled
::Players.Get(iPlr)->SetFoW(!!fEnabled);
// success
return C4Void();
}
static long FnSetMaxPlayer(C4PropList * _this, long iTo)
@ -2464,10 +2452,9 @@ static bool FnAddEvaluationData(C4PropList * _this, C4String *pText, long idPlay
}
// undocumented!
static C4Void FnHideSettlementScoreInEvaluation(C4PropList * _this, bool fHide)
static void FnHideSettlementScoreInEvaluation(C4PropList * _this, bool fHide)
{
Game.RoundResults.HideSettlementScore(fHide);
return C4Void();
}
static bool FnCustomMessage(C4PropList * _this, C4String *pMsg, C4Object *pObj, Nillable<long> iOwner, long iOffX, long iOffY, long dwClr, C4ID idDeco, C4PropList *pSrc, long dwFlags, long iHSize)

View File

@ -69,23 +69,21 @@ static bool FnChangeDef(C4Object *Obj, C4ID to_id)
return !!Obj->ChangeDef(to_id);
}
static C4Void FnSetSolidMask(C4Object *Obj, long iX, long iY, long iWdt, long iHgt, long iTX, long iTY)
static void FnSetSolidMask(C4Object *Obj, long iX, long iY, long iWdt, long iHgt, long iTX, long iTY)
{
Obj->SetSolidMask(iX,iY,iWdt,iHgt,iTX,iTY);
return C4Void();
}
static C4Void FnSetHalfVehicleSolidMask(C4Object *Obj, bool set)
static void FnSetHalfVehicleSolidMask(C4Object *Obj, bool set)
{
Obj->SetHalfVehicleSolidMask(set);
return C4Void();
}
static C4Void FnDeathAnnounce(C4Object *Obj)
static void FnDeathAnnounce(C4Object *Obj)
{
const long MaxDeathMsg=7;
if (Game.C4S.Head.Film)
return C4Void();
return;
// Check if crew member has an own death message
if (Obj->Info && *(Obj->Info->DeathMessage))
{
@ -96,7 +94,6 @@ static C4Void FnDeathAnnounce(C4Object *Obj)
char idDeathMsg[128+1]; sprintf(idDeathMsg, "IDS_OBJ_DEATH%d", 1 + SafeRandom(MaxDeathMsg));
GameMsgObject(FormatString(LoadResStr(idDeathMsg), Obj->GetName()).getData(), Obj);
}
return C4Void();
}
static bool FnGrabContents(C4Object *Obj, C4Object *from)
@ -125,14 +122,13 @@ static bool FnKill(C4PropList * _this, C4Object *pObj, bool fForced)
return true;
}
static C4Void FnFling(C4Object *Obj, long iXDir, long iYDir, long iPrec, bool fAddSpeed)
static void FnFling(C4Object *Obj, long iXDir, long iYDir, long iPrec, bool fAddSpeed)
{
if (!iPrec) iPrec=1;
Obj->Fling(itofix(iXDir, iPrec),itofix(iYDir, iPrec),fAddSpeed);
// unstick from ground, because Fling command may be issued in an Action-callback,
// where attach-values have already been determined for that frame
Obj->Action.t_attach=0;
return C4Void();
}
static bool FnJump(C4Object *Obj)
@ -169,13 +165,12 @@ static bool FnCollect(C4Object *Obj, C4Object *pItem, bool ignoreOCF)
return false;
}
static C4Void FnRemoveObject(C4Object *Obj, bool fEjectContents)
static void FnRemoveObject(C4Object *Obj, bool fEjectContents)
{
Obj->AssignRemoval(fEjectContents);
return C4Void();
}
static C4Void FnSetPosition(C4Object *Obj, long iX, long iY, bool fCheckBounds, long iPrec)
static void FnSetPosition(C4Object *Obj, long iX, long iY, bool fCheckBounds, long iPrec)
{
if (!iPrec) iPrec = 1;
C4Real i_x = itofix(iX, iPrec), i_y = itofix(iY, iPrec);
@ -187,14 +182,12 @@ static C4Void FnSetPosition(C4Object *Obj, long iX, long iY, bool fCheckBounds,
Obj->ForcePosition(i_x, i_y);
// update liquid
Obj->UpdateInLiquid();
return C4Void();
}
static C4Void FnDoCon(C4Object *Obj, long iChange, long iPrec, bool bGrowFromCenter)
static void FnDoCon(C4Object *Obj, long iChange, long iPrec, bool bGrowFromCenter)
{
if (!iPrec) iPrec = 100;
Obj->DoCon(FullCon*iChange / iPrec, bGrowFromCenter);
return C4Void();
}
static long FnGetCon(C4Object *Obj, long iPrec)
@ -313,75 +306,63 @@ static C4Value FnGetCrewExtraData(C4Object *Obj, C4String * DataName)
return pInfo->ExtraData[ival];
}
static C4Void FnDoEnergy(C4Object *Obj, long iChange, bool fExact, Nillable<long> iEngType, Nillable<long> iCausedBy)
static void FnDoEnergy(C4Object *Obj, long iChange, bool fExact, Nillable<long> iEngType, Nillable<long> iCausedBy)
{
if (iEngType.IsNil()) iEngType = C4FxCall_EngScript;
if (iCausedBy.IsNil())
iCausedBy = NO_OWNER;
Obj->DoEnergy(iChange, fExact, iEngType, iCausedBy);
return C4Void();
}
static C4Void FnDoBreath(C4Object *Obj, long iChange)
static void FnDoBreath(C4Object *Obj, long iChange)
{
Obj->DoBreath(iChange);
return C4Void();
}
static C4Void FnDoDamage(C4Object *Obj, long iChange, Nillable<long> iDmgType, Nillable<long> iCausedBy)
static void FnDoDamage(C4Object *Obj, long iChange, Nillable<long> iDmgType, Nillable<long> iCausedBy)
{
if (iDmgType.IsNil()) iDmgType = C4FxCall_DmgScript;
if (iCausedBy.IsNil())
iCausedBy = NO_OWNER;
Obj->DoDamage(iChange, iCausedBy, iDmgType);
return C4Void();
}
static C4Void FnSetEntrance(C4Object *Obj, bool e_status)
static void FnSetEntrance(C4Object *Obj, bool e_status)
{
Obj->EntranceStatus = e_status;
return C4Void();
}
static C4Void FnSetXDir(C4Object *Obj, long nxdir, long iPrec)
static void FnSetXDir(C4Object *Obj, long nxdir, long iPrec)
{
// precision (default 10.0)
if (!iPrec) iPrec=10;
// update xdir
Obj->xdir=itofix(nxdir, iPrec);
Obj->Mobile=1;
// success
return C4Void();
}
static C4Void FnSetRDir(C4Object *Obj, long nrdir, long iPrec)
static void FnSetRDir(C4Object *Obj, long nrdir, long iPrec)
{
// precision (default 10.0)
if (!iPrec) iPrec=10;
// update rdir
Obj->rdir=itofix(nrdir, iPrec);
Obj->Mobile=1;
// success
return C4Void();
}
static C4Void FnSetYDir(C4Object *Obj, long nydir, long iPrec)
static void FnSetYDir(C4Object *Obj, long nydir, long iPrec)
{
// precision (default 10.0)
if (!iPrec) iPrec=10;
// update ydir
Obj->ydir=itofix(nydir, iPrec);
Obj->Mobile=1;
return C4Void();
}
static C4Void FnSetR(C4Object *Obj, long nr)
static void FnSetR(C4Object *Obj, long nr)
{
// set rotation
Obj->SetRotation(nr);
// success
return C4Void();
}
static bool FnSetAction(C4Object *Obj, C4String *szAction,
@ -420,28 +401,24 @@ static bool FnSetActionData(C4Object *Obj, long iData)
return true;
}
static C4Void FnSetComDir(C4Object *Obj, long ncomdir)
static void FnSetComDir(C4Object *Obj, long ncomdir)
{
Obj->Action.ComDir=ncomdir;
return C4Void();
}
static C4Void FnSetDir(C4Object *Obj, long ndir)
static void FnSetDir(C4Object *Obj, long ndir)
{
Obj->SetDir(ndir);
return C4Void();
}
static C4Void FnSetCategory(C4Object *Obj, long iCategory)
static void FnSetCategory(C4Object *Obj, long iCategory)
{
Obj->SetCategory(iCategory);
return C4Void();
}
static C4Void FnSetAlive(C4Object *Obj, bool nalv)
static void FnSetAlive(C4Object *Obj, bool nalv)
{
Obj->SetAlive(nalv);
return C4Void();
}
static bool FnSetOwner(C4Object *Obj, long iOwner)
@ -564,12 +541,11 @@ static C4Object *FnGetActionTarget(C4Object *Obj, long target_index)
return NULL;
}
static C4Void FnSetActionTargets(C4Object *Obj, C4Object *pTarget1, C4Object *pTarget2)
static void FnSetActionTargets(C4Object *Obj, C4Object *pTarget1, C4Object *pTarget2)
{
// set targets
Obj->Action.Target=pTarget1;
Obj->Action.Target2=pTarget2;
return C4Void();
}
static long FnGetDir(C4Object *Obj)
@ -722,10 +698,9 @@ static bool FnRemoveVertex(C4Object *Obj, long iIndex)
return !!Obj->Shape.RemoveVertex(iIndex);
}
static C4Void FnSetContactDensity(C4Object *Obj, long iDensity)
static void FnSetContactDensity(C4Object *Obj, long iDensity)
{
Obj->Shape.ContactDensity = iDensity;
return C4Void();
}
static bool FnGetAlive(C4Object *Obj)
@ -1334,11 +1309,10 @@ static long FnShowInfo(C4Object *Obj, C4Object *pObj)
return Obj->ActivateMenu(C4MN_Info,0,0,0,pObj);
}
static C4Void FnSetMass(C4Object *Obj, long iValue)
static void FnSetMass(C4Object *Obj, long iValue)
{
Obj->OwnMass=iValue-Obj->Def->Mass;
Obj->UpdateMass();
return C4Void();
}
static long FnGetColor(C4Object *Obj)
@ -1346,15 +1320,14 @@ static long FnGetColor(C4Object *Obj)
return Obj->Color;
}
static C4Void FnSetColor(C4Object *Obj, long iValue)
static void FnSetColor(C4Object *Obj, long iValue)
{
Obj->Color=iValue;
Obj->UpdateGraphics(false);
Obj->UpdateFace(false);
return C4Void();
}
static C4Void FnSetLightRange(C4Object *Obj, long iRange, Nillable<long> iFadeoutRange)
static void FnSetLightRange(C4Object *Obj, long iRange, Nillable<long> iFadeoutRange)
{
if (iFadeoutRange.IsNil())
{
@ -1365,8 +1338,6 @@ static C4Void FnSetLightRange(C4Object *Obj, long iRange, Nillable<long> iFadeou
}
// set range
Obj->SetLightRange(iRange, iFadeoutRange);
// success
return C4Void();
}
static long FnGetLightColor(C4Object *Obj)
@ -1376,18 +1347,15 @@ static long FnGetLightColor(C4Object *Obj)
}
static C4Void FnSetLightColor(C4Object *Obj, long iValue)
static void FnSetLightColor(C4Object *Obj, long iValue)
{
Obj->SetLightColor(iValue);
return C4Void();
}
static C4Void FnSetPicture(C4Object *Obj, long iX, long iY, long iWdt, long iHgt)
static void FnSetPicture(C4Object *Obj, long iX, long iY, long iWdt, long iHgt)
{
// set new picture rect
Obj->PictureRect.Set(iX, iY, iWdt, iHgt);
// success
return C4Void();
}
static C4String *FnGetProcedure(C4Object *Obj)
@ -1580,7 +1548,7 @@ static bool FnGetCrewEnabled(C4Object *Obj)
return !Obj->CrewDisabled;
}
static C4Void FnSetCrewEnabled(C4Object *Obj, bool fEnabled)
static void FnSetCrewEnabled(C4Object *Obj, bool fEnabled)
{
bool change = (Obj->CrewDisabled == fEnabled) ? true : false;
@ -1609,17 +1577,12 @@ static C4Void FnSetCrewEnabled(C4Object *Obj, bool fEnabled)
else
Obj->Call(PSF_CrewDisabled);
}
// success
return C4Void();
}
static C4Void FnDoCrewExp(C4Object *Obj, long iChange)
static void FnDoCrewExp(C4Object *Obj, long iChange)
{
// do exp
Obj->DoExperience(iChange);
// success
return C4Void();
}
static bool FnClearMenuItems(C4Object *Obj)
@ -1638,7 +1601,7 @@ static C4Object *FnGetObjectLayer(C4Object *Obj)
return Obj->Layer;
}
static C4Void FnSetObjectLayer(C4Object *Obj, C4Object *pNewLayer)
static void FnSetObjectLayer(C4Object *Obj, C4Object *pNewLayer)
{
// set layer object
Obj->Layer = pNewLayer;
@ -1646,11 +1609,9 @@ static C4Void FnSetObjectLayer(C4Object *Obj, C4Object *pNewLayer)
for (C4Object* contentObj : Obj->Contents)
if (contentObj && contentObj->Status)
contentObj->Layer = pNewLayer;
// success
return C4Void();
}
static C4Void FnSetShape(C4Object *Obj, long iX, long iY, long iWdt, long iHgt)
static void FnSetShape(C4Object *Obj, long iX, long iY, long iWdt, long iHgt)
{
// update shape
Obj->Shape.x = iX;
@ -1659,8 +1620,6 @@ static C4Void FnSetShape(C4Object *Obj, long iX, long iY, long iWdt, long iHgt)
Obj->Shape.Hgt = iHgt;
// section list needs refresh
Obj->UpdatePos();
// done, success
return C4Void();
}
static bool FnSetObjDrawTransform(C4Object *Obj, long iA, long iB, long iC, long iD, long iE, long iF, long iOverlayID)

View File

@ -38,10 +38,12 @@ inline C4Object * Object(C4PropList * _this)
}
StdStrBuf FnStringFormat(C4PropList * _this, C4String *szFormatPar, C4Value * Pars, int ParCount);
template <typename T> struct C4ValueConv;
// Allow integer and boolean parameters to be nil
// Nillable: Allow integer and boolean parameters to be nil
// pointer parameters represent nil via plain NULL
template<typename T>
// other types can use C4Void
class C4Void { };
template <typename T> struct C4ValueConv;
template <typename T>
class Nillable
{
bool _nil;
@ -51,7 +53,7 @@ public:
inline Nillable() : _nil(true), _val(T()) {}
inline Nillable(std::nullptr_t) : _nil(true), _val(T()) {}
template <typename T2> inline Nillable(const Nillable<T2> & n2) : _nil(n2._nil), _val(n2._val) {}
inline Nillable(const Nillable<void> & n2) : _nil(true), _val(T()) {}
inline Nillable(const C4Void &) : _nil(true), _val(T()) {}
inline bool IsNil() const { return _nil; }
inline operator T() const { return _val; }
inline Nillable<T> &operator =(const T &val)
@ -73,14 +75,6 @@ public:
inline T operator --(int) { T v(_val--); return v; }
};
template<>
class Nillable<void>
{
public:
inline Nillable() {}
inline bool IsNil() const { return true; }
};
// Other functions are callable in object context only.
// This exception gets thrown if they are called from anywhere else.
class NeedObjectContext : public C4AulExecError
@ -97,9 +91,6 @@ public:
NeedNonGlobalContext(const char *function) : C4AulExecError(FormatString("%s: call must not be from global context", function).getData()) {}
};
// return type of functions returning nil
typedef Nillable<void> C4Void;
// For functions taking a C4Object as this, check that they got one
template <typename ThisType> struct ThisImpl;
template <> struct ThisImpl<C4Object>
@ -132,6 +123,17 @@ struct ExecImpl
(void) pPars;
}
};
template <typename ThisType, typename ...ParTypes>
struct ExecImpl<void, ThisType, ParTypes...>
{
template <std::size_t... Is>
static C4Value Exec(void (*pFunc)(ThisType *, ParTypes...), ThisType * _this, C4Value pPars[], std::index_sequence<Is...>)
{
pFunc(_this, C4ValueConv<ParTypes>::_FromC4V(pPars[Is])...);
return C4Value();
(void) pPars;
}
};
// converter templates
template <typename T>
@ -140,7 +142,7 @@ struct C4ValueConv<Nillable<T> >
inline static Nillable<T> _FromC4V(C4Value &v) { if (v.GetType() == C4V_Nil) return C4Void(); else return C4ValueConv<T>::_FromC4V(v); }
inline static C4V_Type Type() { return C4ValueConv<T>::Type(); }
};
template <> struct C4ValueConv<Nillable<void> >
template <> struct C4ValueConv<void>
{
inline static C4V_Type Type() { return C4V_Nil; }
};

View File

@ -555,7 +555,7 @@ static bool FnDeepEqual(C4PropList * _this, const C4Value & v1, const C4Value &
return v1 == v2;
}
static C4Void FnSetLength(C4PropList * _this, C4ValueArray *pArray, int iNewSize)
static void FnSetLength(C4PropList * _this, C4ValueArray *pArray, int iNewSize)
{
// safety
if (iNewSize<0 || iNewSize > C4ValueArray::MaxSize)
@ -563,7 +563,6 @@ static C4Void FnSetLength(C4PropList * _this, C4ValueArray *pArray, int iNewSize
// set new size
pArray->SetSize(iNewSize);
return C4Void();
}
static Nillable<long> FnGetChar(C4PropList * _this, C4String *pString, long iIndex)

View File

@ -92,7 +92,6 @@ public:
{ Data.Fn = pFn; AddDataRef(); }
explicit C4Value(C4PropList *p): NextRef(NULL), Type(p ? C4V_PropList : C4V_Nil)
{ Data.PropList = p; AddDataRef(); }
C4Value(const Nillable<void> & x): C4Value() {}
C4Value(C4ObjectPtr p): C4Value(p.operator C4Object *()) {}
template<typename T> C4Value(Nillable<T> v): C4Value(v.IsNil() ? C4Value() : C4Value(v.operator T())) {}
@ -205,7 +204,7 @@ public:
// Compilation
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *);
static inline bool IsNullableType(C4V_Type Type)
static inline constexpr bool IsNullableType(C4V_Type Type)
{ return Type == C4V_Int || Type == C4V_Bool; }
private: