From 15f0a0d220a0ab760ebaed241695655c4fd5bb3d Mon Sep 17 00:00:00 2001 From: XProger Date: Sat, 21 Jul 2018 03:20:44 +0300 Subject: [PATCH] add/remove second player; fix dozy reset --- src/game.h | 4 ++-- src/input.h | 11 +++++++++-- src/inventory.h | 16 +++++++--------- src/lara.h | 5 +++-- src/level.h | 10 +++++++--- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/game.h b/src/game.h index 6125ae1..52d78a5 100644 --- a/src/game.h +++ b/src/game.h @@ -166,8 +166,8 @@ namespace Game { } */ if (!level->level.isTitle()) { - if (Input::state[0][cStart]) level->addPlayer(0); - if (Input::state[1][cStart]) level->addPlayer(1); + if (Input::lastState[0] == cStart) level->addPlayer(0); + if (Input::lastState[1] == cStart) level->addPlayer(1); } if (!level->level.isCutsceneLevel()) diff --git a/src/input.h b/src/input.h index 6c1c009..1601163 100644 --- a/src/input.h +++ b/src/input.h @@ -5,11 +5,13 @@ #include "utils.h" #define INPUT_JOY_COUNT 4 +#define MAX_PLAYERS COUNT(Core::settings.controls) namespace Input { InputKey lastKey; bool down[ikMAX]; - bool state[2][cMAX]; + bool state[MAX_PLAYERS][cMAX]; + ControlKey lastState[MAX_PLAYERS]; struct Mouse { vec2 pos; @@ -195,10 +197,15 @@ namespace Input { void update() { for (int j = 0; j < COUNT(Core::settings.controls); j++) { + lastState[j] = cMAX; + Core::Settings::Controls &ctrl = Core::settings.controls[j]; for (int i = 0; i < cMAX; i++) { KeySet &c = ctrl.keys[i]; - state[j][i] = (c.key != ikNone && down[c.key]) || (c.joy != jkNone && joy[ctrl.joyIndex].down[c.joy]); + bool active = (c.key != ikNone && down[c.key]) || (c.joy != jkNone && joy[ctrl.joyIndex].down[c.joy]); + if (active && !state[j][i]) + lastState[j] = ControlKey(i); + state[j][i] = active; } } diff --git a/src/inventory.h b/src/inventory.h index b3ba5a1..29510f5 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -960,16 +960,14 @@ struct Inventory { } void update() { - if (titleTimer > 1.0f && ( - Input::state[0][cInventory] || Input::state[0][cAction] || - Input::state[1][cInventory] || Input::state[1][cAction] || - Input::down[ikCtrl])) + if (Input::lastState[0] == cInventory || Input::lastState[0] == cAction || + Input::lastState[1] == cInventory || Input::lastState[1] == cAction) { if (video) { - if (video->time > 0.75f) - skipVideo(); - } else if (titleTimer > 1.0f && titleTimer < 2.5f) + skipVideo(); + } else if (titleTimer > 1.0f && titleTimer < 2.5f) { titleTimer = 1.0f; + } } if (video) { @@ -1018,9 +1016,9 @@ struct Inventory { Input::Joystick &joy = Input::joy[Core::settings.controls[playerIndex].joyIndex]; ControlKey key = cMAX; - if (Input::down[ikCtrl] || Input::down[ikEnter] || Input::state[playerIndex][cAction] || joy.down[jkA]) + if (Input::down[ikCtrl] || Input::down[ikEnter] || Input::lastState[playerIndex] == cAction || joy.down[jkA]) key = cAction; - else if (Input::down[ikAlt] || joy.down[jkB] || Input::state[playerIndex][cInventory]) + else if (Input::down[ikAlt] || joy.down[jkB] || Input::lastState[playerIndex] == cInventory) key = cInventory; else if (Input::down[ikLeft] || joy.down[jkLeft] || joy.L.x < -0.5f) key = cLeft; diff --git a/src/lara.h b/src/lara.h index f310a3d..75c680e 100644 --- a/src/lara.h +++ b/src/lara.h @@ -614,7 +614,8 @@ struct Lara : Character { visibleMask = 0xFFFFFFFF; health = LARA_MAX_HEALTH; oxygen = LARA_MAX_OXYGEN; - + dozy = false; + keyHole = NULL; keyItem = NULL; @@ -2583,8 +2584,8 @@ struct Lara : Character { int pid = camera->cameraIndex; if (!dozy && ((Input::state[pid][cAction] && Input::state[pid][cJump] && Input::state[pid][cLook] && Input::state[pid][cDash]) || Input::down[ikO])) { - dozy = true; reset(getRoomIndex(), pos - vec3(0, 512, 0), angle.y, STAND_UNDERWATER); + dozy = true; return input; } diff --git a/src/level.h b/src/level.h index ad86383..553455d 100644 --- a/src/level.h +++ b/src/level.h @@ -770,6 +770,11 @@ struct Level : IGame { players[index] = (Lara*)addEntity(TR::Entity::LARA, 0, vec3(0.0f), 0.0f); players[index]->camera->cameraIndex = index; Sound::listenersCount = 2; + } else if (index == 1) { + removeEntity(players[index]); + players[index] = NULL; + Sound::listenersCount = 1; + return; } Lara *lead = players[index ^ 1]; @@ -783,7 +788,6 @@ struct Level : IGame { c = next; } - players[index]->dozy = false; players[index]->reset(lead->getRoomIndex(), lead->pos, lead->angle.y, lead->stand); } @@ -1535,8 +1539,8 @@ struct Level : IGame { } } - if ((Input::state[0][cInventory] || Input::state[1][cInventory]) && !level.isTitle() && inventory->titleTimer < 1.0f && !inventory->active && inventory->lastKey == cMAX) { - int playerIndex = Input::state[0][cInventory] ? 0 : 1; + if ((Input::lastState[0] == cInventory || Input::lastState[1] == cInventory) && !level.isTitle() && inventory->titleTimer < 1.0f && !inventory->active) { + int playerIndex = (Input::lastState[0] == cInventory) ? 0 : 1; if (level.isCutsceneLevel()) { loadNextLevel();