1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

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
This commit is contained in:
husho 2018-06-08 08:41:32 +03:00 committed by husho
parent 363840396a
commit f9fc588d64
4 changed files with 23 additions and 13 deletions

View File

@ -314,7 +314,7 @@ bool ItemPickup::onPlayerTouch() {
totalRounds /= 5; totalRounds /= 5;
} }
const auto& character = engine->getPlayer()->getCharacter(); auto character = engine->getPlayer()->getCharacter();
character->addToInventory(item->inventorySlot, totalRounds); character->addToInventory(item->inventorySlot, totalRounds);
@ -353,7 +353,7 @@ HealthPickup::HealthPickup(GameWorld* world, const glm::vec3& position,
} }
bool HealthPickup::onPlayerTouch() { bool HealthPickup::onPlayerTouch() {
const auto& character = engine->getPlayer()->getCharacter(); auto character = engine->getPlayer()->getCharacter();
if (character->getCurrentState().health >= 100.f) { if (character->getCurrentState().health >= 100.f) {
return false; return false;
@ -370,7 +370,7 @@ ArmourPickup::ArmourPickup(GameWorld* world, const glm::vec3& position,
} }
bool ArmourPickup::onPlayerTouch() { bool ArmourPickup::onPlayerTouch() {
const auto& character = engine->getPlayer()->getCharacter(); auto character = engine->getPlayer()->getCharacter();
if (character->getCurrentState().armour >= 100.f) { if (character->getCurrentState().armour >= 100.f) {
return false; return false;
@ -388,7 +388,7 @@ CollectablePickup::CollectablePickup(GameWorld* world,
} }
bool CollectablePickup::onPlayerTouch() { bool CollectablePickup::onPlayerTouch() {
const auto& state = engine->state; auto state = engine->state;
if (state->playerInfo.hiddenPackagesCollected == if (state->playerInfo.hiddenPackagesCollected ==
state->playerInfo.hiddenPackageCount) { state->playerInfo.hiddenPackageCount) {

View File

@ -7685,8 +7685,7 @@ bool opcode_02d8(const ScriptArguments& args, const ScriptCharacter character, c
opcode 02d9 opcode 02d9
*/ */
void opcode_02d9(const ScriptArguments& args) { void opcode_02d9(const ScriptArguments& args) {
RW_UNIMPLEMENTED_OPCODE(0x02d9); args.getState()->bigNVeinyPickupsCollected = 0;
RW_UNUSED(args);
} }
/** /**

View File

@ -482,6 +482,7 @@ void RWGame::tick(float dt) {
static float clockAccumulator = 0.f; static float clockAccumulator = 0.f;
static float scriptTimerAccumulator = 0.f; static float scriptTimerAccumulator = 0.f;
static ScriptInt beepTime = std::numeric_limits<ScriptInt>::max();
if (currState->shouldWorldUpdate()) { if (currState->shouldWorldUpdate()) {
world->chase.update(dt); world->chase.update(dt);
@ -503,19 +504,25 @@ void RWGame::tick(float dt) {
clockAccumulator -= 1.f; clockAccumulator -= 1.f;
} }
constexpr float timerClockRate = 1.f / 30.f;
if (state.scriptTimerVariable && !state.scriptTimerPaused) { if (state.scriptTimerVariable && !state.scriptTimerPaused) {
scriptTimerAccumulator += dt; scriptTimerAccumulator += dt;
while (scriptTimerAccumulator >= 1.f) { while (scriptTimerAccumulator >= timerClockRate) {
(*state.scriptTimerVariable) -= 1000; // Original game uses milliseconds
(*state.scriptTimerVariable) -= timerClockRate * 1000;
if (*state.scriptTimerVariable <= 0) { if (*state.scriptTimerVariable <= 0) {
(*state.scriptTimerVariable) = 0; (*state.scriptTimerVariable) = 0;
state.scriptTimerVariable = nullptr; state.scriptTimerVariable = nullptr;
} }
// 11 seconds // 11 seconds
if (*state.scriptTimerVariable <= 11000) { if (*state.scriptTimerVariable <= 11000 &&
beepTime - *state.scriptTimerVariable >= 1000) {
beepTime = *state.scriptTimerVariable;
// @todo beep // @todo beep
} }
scriptTimerAccumulator -= 1.f; scriptTimerAccumulator -= timerClockRate;
} }
} }

View File

@ -14,7 +14,7 @@ public:
OnStreet) { OnStreet) {
} }
bool onCharacterTouch(CharacterObject*) { bool onPlayerTouch() {
picked_up = true; picked_up = true;
return true; return true;
} }
@ -24,9 +24,11 @@ BOOST_AUTO_TEST_SUITE(PickupTests)
BOOST_AUTO_TEST_CASE(test_pickup_interaction) { BOOST_AUTO_TEST_CASE(test_pickup_interaction) {
{ {
auto objectID = 9999;
auto character = 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); BOOST_REQUIRE(character != nullptr);
Global::get().e->state->playerObject = objectID;
TestPickup* p = new TestPickup(Global::get().e, {30.f, 0.f, 0.f}); 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) { BOOST_AUTO_TEST_CASE(test_item_pickup) {
{ {
auto objectID = 9999;
auto character = 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); BOOST_REQUIRE(character != nullptr);
Global::get().e->state->playerObject = objectID;
auto pistol = Global::get().d->weaponData[1].get(); auto pistol = Global::get().d->weaponData[1].get();
auto model = Global::get().d->modelinfo[pistol->modelID].get(); auto model = Global::get().d->modelinfo[pistol->modelID].get();