/*
Copyright (C) 2003, 2010 - Wolfire Games
-Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
This file is part of Lugaru.
int closest = -1;
float closestdist = std::numeric_limits<float>::max();
- for (unsigned i = 1; i < Person::players.size(); i++) {
+ for (unsigned int i = 1; i < Person::players.size(); i++) {
float distance = distsq(&Person::players[i]->coords, &Person::players[0]->coords);
if (distance < closestdist) {
closestdist = distance;
- closest = i;
+ closest = (int)i;
}
}
return closest;
return true;
}
-void doDevKeys()
+/* Process input events that impact settings, console, devtools, etc.
+ * Gameplay-related input processing is still done in Game::Tick() for now
+ * as it is tightly coupled to the game logic.
+ */
+void Game::ProcessInput()
{
- float headprop, bodyprop, armprop, legprop;
- if (!devtools) {
+ /* Pump SDL input events */
+ Input::Tick();
+
+ /* Menu handling (main menu, leave game) */
+ if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) &&
+ (gameon || mainmenu == 0)) {
+ selected = -1;
+ if (mainmenu == 0 && !winfreeze) {
+ mainmenu = 2; // Pause
+ } else if (mainmenu == 1 || mainmenu == 2) {
+ mainmenu = 0; // Unpause
+ }
+ // Play menu theme
+ if (musictoggle && (mainmenu == 1 || mainmenu == 2)) {
+ OPENAL_SetFrequency(OPENAL_ALL);
+ emit_stream_np(stream_menutheme);
+ pause_sound(leveltheme);
+ }
+ // On resume, play level music
+ if (!mainmenu) {
+ pause_sound(stream_menutheme);
+ resume_stream(leveltheme);
+ }
+ }
+
+ /* Challenge mode */
+ if (!campaign && !mainmenu) {
+ if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE))) {
+ if (winfreeze) {
+ winfreeze = 0;
+ }
+ }
+
+ if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && gameon) {
+ if (console) {
+ console = false;
+ freeze = 0;
+ } else if (winfreeze) {
+ mainmenu = 9;
+ gameon = 0;
+ }
+ }
+ }
+
+
+ /* Tutorial mode hotkeys */
+ if (Tutorial::active) {
+ // Skip current tutorial stage
+ if (Input::isKeyPressed(SDL_SCANCODE_TAB)) {
+ if (Tutorial::stage != 51) {
+ Tutorial::stagetime = Tutorial::maxtime;
+ }
+ emit_sound_np(consolefailsound, 128.);
+ }
+ }
+
+
+ /* Screenshot */
+ if (Input::isKeyPressed(SDL_SCANCODE_F1)) {
+ Screenshot();
+ }
+
+
+ /* Stereo video mode hotkeys */
+ if (Input::isKeyPressed(SDL_SCANCODE_F6)) {
+ if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
+ stereoreverse = true;
+ } else {
+ stereoreverse = false;
+ }
+
+ if (stereoreverse) {
+ printf("Stereo reversed\n");
+ } else {
+ printf("Stereo unreversed\n");
+ }
+ }
+
+ if (Input::isKeyDown(SDL_SCANCODE_F7)) {
+ if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
+ stereoseparation -= 0.001;
+ } else {
+ stereoseparation -= 0.010;
+ }
+ printf("Stereo decreased increased to %f\n", stereoseparation);
+ }
+
+ if (Input::isKeyDown(SDL_SCANCODE_F8)) {
+ if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
+ stereoseparation += 0.001;
+ } else {
+ stereoseparation += 0.010;
+ }
+ printf("Stereo separation increased to %f\n", stereoseparation);
+ }
+
+
+ /* Devtools */
+ if (devtools && !mainmenu) {
+ ProcessDevInput();
+ }
+}
+
+void Game::ProcessDevInput()
+{
+ if (!devtools || mainmenu) {
return;
}
+ float headprop, bodyprop, armprop, legprop;
+
+ if (!mainmenu) {
+ // Console
+ if (Input::isKeyPressed(consolekey)) {
+ console = !console;
+ if (console) {
+ OPENAL_SetFrequency(OPENAL_ALL);
+ } else {
+ freeze = 0;
+ waiting = false;
+ }
+ }
+
+ // Freeze
+ if (Input::isKeyDown(SDL_SCANCODE_LALT) && Input::isKeyPressed(SDL_SCANCODE_V)) {
+ freeze = !freeze;
+ if (freeze) {
+ OPENAL_SetFrequency(OPENAL_ALL);
+ }
+ }
+ }
+
if (Input::isKeyDown(SDL_SCANCODE_LALT)) {
/* Invicible */
if (Input::isKeyPressed(SDL_SCANCODE_H)) {
}
if (editorenabled) {
+ /* Closest player deletion */
if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
int closest = findClosestPlayer();
- if (closest >= 0) {
+ if (closest > 0) {
Person::players.erase(Person::players.begin() + closest);
}
}
- if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
+ /* Closest object deletion */
+ if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
int closest = findClosestObject();
if (closest >= 0) {
- Object::objects[closest]->position.y -= 500;
+ Object::DeleteObject(closest);
}
}
- if (Input::isKeyPressed(SDL_SCANCODE_M) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
+ /* Add object */
+ if (Input::isKeyPressed(SDL_SCANCODE_O) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
if (Object::objects.size() < max_objects - 1) {
XYZ scenecoords;
scenecoords.x = Person::players[0]->coords.x;
}
}
- if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
+ /* Add player */
+ if (Input::isKeyPressed(SDL_SCANCODE_P) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
Person::players.push_back(shared_ptr<Person>(new Person()));
Person::players.back()->id = Person::players.size() - 1;
Person::players.back()->loaded = true;
}
+ /* Add waypoint */
if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
if (Person::players.back()->numwaypoints < 90) {
Person::players.back()->waypoints[Person::players.back()->numwaypoints] = Person::players[0]->coords;
}
}
+ /* Connect waypoint */
if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
if (numpathpoints < 30) {
bool connected, alreadyconnected;
editorpitch = -.01;
}
}
-
- if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Object::objects.size() && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
- int closest = findClosestObject();
- if (closest >= 0) {
- Object::DeleteObject(closest);
- }
- }
}
}
static XYZ facing, flatfacing;
static int target;
- Input::Tick();
-
- if (Input::isKeyPressed(SDL_SCANCODE_F6)) {
- if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
- stereoreverse = true;
- } else {
- stereoreverse = false;
- }
-
- if (stereoreverse) {
- printf("Stereo reversed\n");
- } else {
- printf("Stereo unreversed\n");
- }
- }
-
- if (Input::isKeyDown(SDL_SCANCODE_F7)) {
- if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
- stereoseparation -= 0.001;
- } else {
- stereoseparation -= 0.010;
- }
- printf("Stereo decreased increased to %f\n", stereoseparation);
- }
-
- if (Input::isKeyDown(SDL_SCANCODE_F8)) {
- if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
- stereoseparation += 0.001;
- } else {
- stereoseparation += 0.010;
- }
- printf("Stereo separation increased to %f\n", stereoseparation);
- }
-
- if (Input::isKeyPressed(SDL_SCANCODE_TAB) && Tutorial::active) {
- if (Tutorial::stage != 51) {
- Tutorial::stagetime = Tutorial::maxtime;
- }
- emit_sound_np(consolefailsound, 128.);
- }
+ /* Pump SDL input events and process non-gameplay related ones */
+ ProcessInput();
/*
Values of mainmenu :
}
Menu::Load();
}
- //escape key pressed
- if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) &&
- (gameon || mainmenu == 0)) {
- selected = -1;
- if (mainmenu == 0 && !winfreeze) {
- mainmenu = 2; //pause
- } else if (mainmenu == 1 || mainmenu == 2) {
- mainmenu = 0; //unpause
- }
- //play menu theme
- if (musictoggle && (mainmenu == 1 || mainmenu == 2)) {
- OPENAL_SetFrequency(OPENAL_ALL);
- emit_stream_np(stream_menutheme);
- pause_sound(leveltheme);
- }
- //on resume, play level music
- if (!mainmenu) {
- pause_sound(stream_menutheme);
- resume_stream(leveltheme);
- }
- }
}
if (mainmenu) {
leveltime += multiplier;
}
- //keys
- if (Input::isKeyDown(SDL_SCANCODE_LALT) && Input::isKeyPressed(SDL_SCANCODE_V) && devtools) {
- freeze = !freeze;
- if (freeze) {
- OPENAL_SetFrequency(OPENAL_ALL);
- }
- }
-
- if (Input::isKeyPressed(consolekey) && devtools) {
- console = !console;
- if (console) {
- OPENAL_SetFrequency(OPENAL_ALL);
- } else {
- freeze = 0;
- waiting = false;
- }
- }
-
if (console) {
freeze = 1;
- }
- if (console && !Input::isKeyDown(SDL_SCANCODE_LGUI)) {
+
inputText(consoletext[0], &consoleselected);
if (!waiting) {
if (!consoletext[0].empty()) {
oldwinfreeze++;
}
- if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE)) && !campaign) {
- if (winfreeze) {
- winfreeze = 0;
- }
- }
- if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && !campaign && gameon) {
- if (console) {
- console = false;
- freeze = 0;
- } else if (winfreeze) {
- mainmenu = 9;
- gameon = 0;
- }
- }
-
if (!freeze && !winfreeze && !(mainmenu && gameon) && (gameon || !gamestarted)) {
//dialogues
hawkcalldelay = 16 + abs(Random() % 8);
}
- doDevKeys();
-
doAttacks();
doPlayerCollisions();
oldviewer = viewer;
}
}
-
- if (Input::isKeyPressed(SDL_SCANCODE_F1)) {
- Screenshot();
- }
}
void Game::TickOnce()