1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Sandu Liviu Catalin
6419fc0f4d Add Elapsed and Remaining properties to routine.
Some checks reported errors
continuous-integration/drone/push Build was killed
2021-11-10 17:30:21 +02:00
Sandu Liviu Catalin
0213ffe632 Update Official.cpp 2021-11-10 16:58:13 +02:00
Sandu Liviu Catalin
5f364605ab Update Official.cpp 2021-11-10 16:50:38 +02:00
3 changed files with 43 additions and 12 deletions

View File

@ -549,6 +549,8 @@ void Register_Routine(HSQUIRRELVM vm)
.Prop(_SC("Inactive"), &Routine::GetInactive) .Prop(_SC("Inactive"), &Routine::GetInactive)
.Prop(_SC("Persistent"), &Routine::GetPersistent, &Routine::SetPersistent) .Prop(_SC("Persistent"), &Routine::GetPersistent, &Routine::SetPersistent)
.Prop(_SC("Yields"), &Routine::GetYields, &Routine::SetYields) .Prop(_SC("Yields"), &Routine::GetYields, &Routine::SetYields)
.Prop(_SC("Elapsed"), &Routine::GetElapsed)
.Prop(_SC("Remaining"), &Routine::GetRemaining)
.Prop(_SC("Terminated"), &Routine::GetTerminated) .Prop(_SC("Terminated"), &Routine::GetTerminated)
.Prop(_SC("Arguments"), &Routine::GetArguments) .Prop(_SC("Arguments"), &Routine::GetArguments)
// Member Methods // Member Methods

View File

@ -408,7 +408,6 @@ public:
} }
// Unable to find such routine // Unable to find such routine
STHROWF("Unable to fetch a routine with tag ({}). No such routine", tag.mPtr); STHROWF("Unable to fetch a routine with tag ({}). No such routine", tag.mPtr);
SQ_UNREACHABLE
// Should not reach this point but if it did, we have to return something // Should not reach this point but if it did, we have to return something
#ifdef __clang__ #ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
@ -418,6 +417,7 @@ public:
#ifdef __clang__ #ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif #endif
SQ_UNREACHABLE
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
@ -804,6 +804,32 @@ public:
return (m_Slot == SQMOD_MAX_ROUTINES); return (m_Slot == SQMOD_MAX_ROUTINES);
} }
/* --------------------------------------------------------------------------------------------
* Retrieve the time elapsed since the routine was created or invoked.
*/
SQMOD_NODISCARD SQInteger GetElapsed() const
{
if (m_Slot >= SQMOD_MAX_ROUTINES)
{
STHROWF("This instance does not reference a valid routine");
}
// We know it's valid so let's return it
return s_Instances[m_Slot].mInterval - s_Intervals[m_Slot];
}
/* --------------------------------------------------------------------------------------------
* Retrieve the time remaining until the routine is invoked.
*/
SQMOD_NODISCARD SQInteger GetRemaining() const
{
if (m_Slot >= SQMOD_MAX_ROUTINES)
{
STHROWF("This instance does not reference a valid routine");
}
// We know it's valid so let's return it
return s_Intervals[m_Slot];
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the number of arguments to be forwarded. * Retrieve the number of arguments to be forwarded.
*/ */

View File

@ -1547,7 +1547,7 @@ SQMOD_NODISCARD SQInteger LgGetObjectCount() {
} }
SQMOD_NODISCARD SQInteger LgGetPlayers() { return ForeachConnectedPlayerCount([](int32_t) { return true; }); } SQMOD_NODISCARD SQInteger LgGetPlayers() { return ForeachConnectedPlayerCount([](int32_t) { return true; }); }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
static void LgSetVehiclesForcedRespawnHeight(SQFloat height) { _Func->SetVehiclesForcedRespawnHeight(height); } static void LgSetVehiclesForcedRespawnHeight(SQFloat height) { _Func->SetVehiclesForcedRespawnHeight(static_cast< float >(height)); }
SQMOD_NODISCARD static SQFloat LgGetVehiclesForcedRespawnHeight() { return _Func->GetVehiclesForcedRespawnHeight(); } SQMOD_NODISCARD static SQFloat LgGetVehiclesForcedRespawnHeight() { return _Func->GetVehiclesForcedRespawnHeight(); }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQMOD_NODISCARD static SQInteger LgFindPlayer(HSQUIRRELVM vm) { SQMOD_NODISCARD static SQInteger LgFindPlayer(HSQUIRRELVM vm) {
@ -1634,10 +1634,11 @@ SQMOD_NODISCARD static SQInteger LgInPolyProcStack(HSQUIRRELVM vm) {
points.reserve(static_cast<unsigned long long int>((top - 1) / 2)); points.reserve(static_cast<unsigned long long int>((top - 1) / 2));
for (SQInteger idx = 4; idx < top;) { for (SQInteger idx = 4; idx < top;) {
points.emplace_back(); points.emplace_back();
points.back().x = PopStackFloat(vm, idx++); points.back().x = SQMOD_DOUBLE_OR(static_cast< Vector2::Value >(PopStackFloat(vm, idx++)), PopStackFloat(vm, idx++));
points.back().y = PopStackFloat(vm, idx++); points.back().y = SQMOD_DOUBLE_OR(static_cast< Vector2::Value >(PopStackFloat(vm, idx++)), PopStackFloat(vm, idx++));
} }
sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(x, y, points.size(), points.data()))); sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(SQMOD_DOUBLE_OR(static_cast< float >(x), x),
SQMOD_DOUBLE_OR(static_cast< float >(y), y), points.size(), points.data())));
return 1; return 1;
} }
SQMOD_NODISCARD static SQInteger LgInPolyProcString(HSQUIRRELVM vm) { SQMOD_NODISCARD static SQInteger LgInPolyProcString(HSQUIRRELVM vm) {
@ -1654,7 +1655,8 @@ SQMOD_NODISCARD static SQInteger LgInPolyProcString(HSQUIRRELVM vm) {
ss >> points.back().y >> c; ss >> points.back().y >> c;
else break; else break;
} }
sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(x, y, points.size(), points.data()))); sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(SQMOD_DOUBLE_OR(static_cast< float >(x), x),
SQMOD_DOUBLE_OR(static_cast< float >(y), y), points.size(), points.data())));
return 1; return 1;
} }
SQMOD_NODISCARD static SQInteger LgInPolyProcArray(HSQUIRRELVM vm) { SQMOD_NODISCARD static SQInteger LgInPolyProcArray(HSQUIRRELVM vm) {
@ -1665,13 +1667,14 @@ SQMOD_NODISCARD static SQInteger LgInPolyProcArray(HSQUIRRELVM vm) {
arr.Foreach([&](HSQUIRRELVM vm, SQInteger i) -> SQRESULT { arr.Foreach([&](HSQUIRRELVM vm, SQInteger i) -> SQRESULT {
if ((i & 1) == 0) { if ((i & 1) == 0) {
points.emplace_back(); points.emplace_back();
points.back().x = PopStackFloat(vm, -1); points.back().x = SQMOD_DOUBLE_OR(static_cast< Vector2::Value >(PopStackFloat(vm, -1)), PopStackFloat(vm, -1));
} else { } else {
points.back().y = PopStackFloat(vm, -1); points.back().y = SQMOD_DOUBLE_OR(static_cast< Vector2::Value >(PopStackFloat(vm, -1)), PopStackFloat(vm, -1));
} }
return SQ_OK; return SQ_OK;
}); });
sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(x, y, points.size(), points.data()))); sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(SQMOD_DOUBLE_OR(static_cast< float >(x), x),
SQMOD_DOUBLE_OR(static_cast< float >(y), y), points.size(), points.data())));
return 1; return 1;
} }
SQMOD_NODISCARD static SQInteger LgInPoly(HSQUIRRELVM vm) { SQMOD_NODISCARD static SQInteger LgInPoly(HSQUIRRELVM vm) {
@ -1752,10 +1755,10 @@ void Register_Official_Functions(HSQUIRRELVM vm)
.Func(_SC("SetMaxHeight"), LgSetMaxHeight) .Func(_SC("SetMaxHeight"), LgSetMaxHeight)
.Func(_SC("SetFallTimer"), LgSetFallTimer) .Func(_SC("SetFallTimer"), LgSetFallTimer)
.Func(_SC("GetServerName"), LgGetServerName) .SquirrelFunc(_SC("GetServerName"), LgGetServerName)
.Func(_SC("GetMaxPlayers"), LgGetMaxPlayers) .Func(_SC("GetMaxPlayers"), LgGetMaxPlayers)
.Func(_SC("GetPassword"), LgGetServerPassword) .SquirrelFunc(_SC("GetPassword"), LgGetServerPassword)
.Func(_SC("GetGameModeName"), LgGetGameModeText) .SquirrelFunc(_SC("GetGameModeName"), LgGetGameModeText)
.Func(_SC("GetTimeRate"), LgGetTimeRate) .Func(_SC("GetTimeRate"), LgGetTimeRate)
.Func(_SC("GetHour"), LgGetHour) .Func(_SC("GetHour"), LgGetHour)
.Func(_SC("GetMinute"), LgGetMinute) .Func(_SC("GetMinute"), LgGetMinute)