From f9fc588d64a20d2d8a4815ea17d99a423e60ddf3 Mon Sep 17 00:00:00 2001 From: husho Date: Fri, 8 Jun 2018 08:41:32 +0300 Subject: [PATCH] Fixed: tests weren't working Fixed: mission timer Timer was going crazy due to missing 02d9 opcode, update timer 25 times per second Fixed: mission timer Don't beep on every timer update --- rwengine/src/objects/PickupObject.cpp | 8 ++++---- rwengine/src/script/modules/GTA3ModuleImpl.inl | 3 +-- rwgame/RWGame.cpp | 15 +++++++++++---- tests/test_Pickup.cpp | 10 +++++++--- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/rwengine/src/objects/PickupObject.cpp b/rwengine/src/objects/PickupObject.cpp index bdd52d7c..11d8fff0 100644 --- a/rwengine/src/objects/PickupObject.cpp +++ b/rwengine/src/objects/PickupObject.cpp @@ -314,7 +314,7 @@ bool ItemPickup::onPlayerTouch() { totalRounds /= 5; } - const auto& character = engine->getPlayer()->getCharacter(); + auto character = engine->getPlayer()->getCharacter(); character->addToInventory(item->inventorySlot, totalRounds); @@ -353,7 +353,7 @@ HealthPickup::HealthPickup(GameWorld* world, const glm::vec3& position, } bool HealthPickup::onPlayerTouch() { - const auto& character = engine->getPlayer()->getCharacter(); + auto character = engine->getPlayer()->getCharacter(); if (character->getCurrentState().health >= 100.f) { return false; @@ -370,7 +370,7 @@ ArmourPickup::ArmourPickup(GameWorld* world, const glm::vec3& position, } bool ArmourPickup::onPlayerTouch() { - const auto& character = engine->getPlayer()->getCharacter(); + auto character = engine->getPlayer()->getCharacter(); if (character->getCurrentState().armour >= 100.f) { return false; @@ -388,7 +388,7 @@ CollectablePickup::CollectablePickup(GameWorld* world, } bool CollectablePickup::onPlayerTouch() { - const auto& state = engine->state; + auto state = engine->state; if (state->playerInfo.hiddenPackagesCollected == state->playerInfo.hiddenPackageCount) { diff --git a/rwengine/src/script/modules/GTA3ModuleImpl.inl b/rwengine/src/script/modules/GTA3ModuleImpl.inl index 76e05460..b2212b83 100644 --- a/rwengine/src/script/modules/GTA3ModuleImpl.inl +++ b/rwengine/src/script/modules/GTA3ModuleImpl.inl @@ -7685,8 +7685,7 @@ bool opcode_02d8(const ScriptArguments& args, const ScriptCharacter character, c opcode 02d9 */ void opcode_02d9(const ScriptArguments& args) { - RW_UNIMPLEMENTED_OPCODE(0x02d9); - RW_UNUSED(args); + args.getState()->bigNVeinyPickupsCollected = 0; } /** diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index 6aadb4be..81fd39cf 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -482,6 +482,7 @@ void RWGame::tick(float dt) { static float clockAccumulator = 0.f; static float scriptTimerAccumulator = 0.f; + static ScriptInt beepTime = std::numeric_limits::max(); if (currState->shouldWorldUpdate()) { world->chase.update(dt); @@ -503,19 +504,25 @@ void RWGame::tick(float dt) { clockAccumulator -= 1.f; } + constexpr float timerClockRate = 1.f / 30.f; + if (state.scriptTimerVariable && !state.scriptTimerPaused) { scriptTimerAccumulator += dt; - while (scriptTimerAccumulator >= 1.f) { - (*state.scriptTimerVariable) -= 1000; + while (scriptTimerAccumulator >= timerClockRate) { + // Original game uses milliseconds + (*state.scriptTimerVariable) -= timerClockRate * 1000; if (*state.scriptTimerVariable <= 0) { (*state.scriptTimerVariable) = 0; state.scriptTimerVariable = nullptr; } // 11 seconds - if (*state.scriptTimerVariable <= 11000) { + if (*state.scriptTimerVariable <= 11000 && + beepTime - *state.scriptTimerVariable >= 1000) { + beepTime = *state.scriptTimerVariable; + // @todo beep } - scriptTimerAccumulator -= 1.f; + scriptTimerAccumulator -= timerClockRate; } } diff --git a/tests/test_Pickup.cpp b/tests/test_Pickup.cpp index c4b0270b..7109e50b 100644 --- a/tests/test_Pickup.cpp +++ b/tests/test_Pickup.cpp @@ -14,7 +14,7 @@ public: OnStreet) { } - bool onCharacterTouch(CharacterObject*) { + bool onPlayerTouch() { picked_up = true; return true; } @@ -24,9 +24,11 @@ BOOST_AUTO_TEST_SUITE(PickupTests) BOOST_AUTO_TEST_CASE(test_pickup_interaction) { { + auto objectID = 9999; auto character = - Global::get().e->createPedestrian(1, {30.1f, 0.f, 0.f}); + Global::get().e->createPlayer({30.1f, 0.f, 0.f}, {1.f, 0.f, 0.f, 0.f}, objectID); BOOST_REQUIRE(character != nullptr); + Global::get().e->state->playerObject = objectID; TestPickup* p = new TestPickup(Global::get().e, {30.f, 0.f, 0.f}); @@ -60,9 +62,11 @@ BOOST_AUTO_TEST_CASE(test_pickup_interaction) { BOOST_AUTO_TEST_CASE(test_item_pickup) { { + auto objectID = 9999; auto character = - Global::get().e->createPedestrian(1, {30.1f, 0.f, 0.f}); + Global::get().e->createPlayer({30.1f, 0.f, 0.f}, {1.f, 0.f, 0.f, 0.f}, objectID); BOOST_REQUIRE(character != nullptr); + Global::get().e->state->playerObject = objectID; auto pistol = Global::get().d->weaponData[1].get(); auto model = Global::get().d->modelinfo[pistol->modelID].get();