[Add] 2x speed modifier by manipulating dt modifier.

[Fix] Fixed double free on keybindings opening.
This commit is contained in:
Allanis 2014-03-17 01:56:39 +00:00
parent ee57228de5
commit 355ccfd65e
6 changed files with 40 additions and 9 deletions

View File

@ -48,7 +48,7 @@ const char* keybindNames[] = {
/* Communication. */ /* Communication. */
"hail", "hail",
/* Misc. */ /* Misc. */
"mapzoomin", "mapzoomout", "screenshot", "pause", "menu", "info", "mapzoomin", "mapzoomout", "screenshot", "pause", "speed", "menu", "info",
"end" /* Must terminate at the end. */ "end" /* Must terminate at the end. */
}; };
@ -79,17 +79,19 @@ const char* keybindDescription[] = {
"Clears your escorts commands.", "Clears your escorts commands.",
/* Space navigation. */ /* Space navigation. */
"Initializes the autonavigation system.", "Initializes the autonavigation system.",
"Cycles through hyperspace targets.", "Cycles through planet targets.",
"Attempt to land on your targetted planet or targets nearest landable planet. \ "Attempt to land on your targetted planet or targets nearest landable planet. \
Requests for landing if you don't have permission yet.", Requests for landing if you don't have permission yet.",
"Cycles through hyperspace targets.", "Cycles through hyperspace targets.",
"Opens the Star Map.", "Opens the Star Map.",
"Attempt to jump to your hyperspace target.",
/* Communication. */ /* Communication. */
"Attempts to initialize communication with your taretted ship.", "Attempts to initialize communication with your taretted ship.",
/* Misc. */ /* Misc. */
"Zooms in on your radar.", "Zooms in on your radar.",
"Zooms out on your radar.", "Zooms out on your radar.",
"Takes a screenshot.", "Takes a screenshot.",
"Toggles 2x speed modifier.",
"Pauses the game.", "Pauses the game.",
"Opens the small ingame menu.", "Opens the small ingame menu.",
"Opens the information menu." "Opens the information menu."
@ -145,6 +147,7 @@ void input_setDefault(void) {
input_setKeybind("mapzoomout", KEYBIND_KEYBOARD, SDLK_KP_MINUS, KMOD_NONE, 0); input_setKeybind("mapzoomout", KEYBIND_KEYBOARD, SDLK_KP_MINUS, KMOD_NONE, 0);
input_setKeybind("screenshot", KEYBIND_KEYBOARD, SDLK_KP_MULTIPLY, KMOD_NONE, 0); input_setKeybind("screenshot", KEYBIND_KEYBOARD, SDLK_KP_MULTIPLY, KMOD_NONE, 0);
input_setKeybind("pause", KEYBIND_KEYBOARD, SDLK_F1, KMOD_NONE, 0); input_setKeybind("pause", KEYBIND_KEYBOARD, SDLK_F1, KMOD_NONE, 0);
input_setKeybind("speed", KEYBIND_KEYBOARD, SDLK_BACKQUOTE, KMOD_NONE, 0);
input_setKeybind("menu", KEYBIND_KEYBOARD, SDLK_ESCAPE, KMOD_NONE, 0); input_setKeybind("menu", KEYBIND_KEYBOARD, SDLK_ESCAPE, KMOD_NONE, 0);
input_setKeybind("info", KEYBIND_KEYBOARD, SDLK_i, KMOD_NONE, 0); input_setKeybind("info", KEYBIND_KEYBOARD, SDLK_i, KMOD_NONE, 0);
} }
@ -447,6 +450,13 @@ static void input_key(int keynum, double value, int kabs) {
} else pause_game(); } else pause_game();
} }
} }
/* Toggle speed mode. */
else if(KEY("speed")) {
if(value == KEY_PRESS) {
if(dt_mod == 1.) pause_setSpeed(2.);
else pause_setSpeed(1.);
}
}
/* Opens a menu. */ /* Opens a menu. */
else if(KEY("menu")) { else if(KEY("menu")) {
if(value == KEY_PRESS) menu_small(); if(value == KEY_PRESS) menu_small();

View File

@ -452,9 +452,11 @@ static void fps_control(void) {
unsigned int t; unsigned int t;
double delay; double delay;
/* dt in ms/1000. */ /* dt in s. */
t = SDL_GetTicks(); t = SDL_GetTicks();
cur_dt = (double)(t-time)/1000.; cur_dt = (double)(t - time); /* Get the elapsed ms. */
cur_dt *= dt_mod; /* Apply the modifier. */
cur_dt /= 1000.; /* Convert to seconds. */
time = t; time = t;
if(paused) SDL_Delay(10); /* Drop paused FPS to be nice to the CPU. */ if(paused) SDL_Delay(10); /* Drop paused FPS to be nice to the CPU. */
@ -476,7 +478,7 @@ static const double fps_min = 1./50.0;
static void update_all(void) { static void update_all(void) {
double tmpdt; double tmpdt;
if(cur_dt > 0.25) { /* Slow timers down and rerun calculations */ if(cur_dt > 0.25*dt_mod) { /* Slow timers down and rerun calculations */
pause_delay((unsigned int)cur_dt*1000.); pause_delay((unsigned int)cur_dt*1000.);
return; return;
} }
@ -578,8 +580,12 @@ static void display_fps(const double dt) {
x = 10.; x = 10.;
y = (double)(gl_screen.h - 20); y = (double)(gl_screen.h - 20);
if(show_fps) if(show_fps) {
gl_print(NULL, x, y, NULL, "%3.2f", fps); gl_print(NULL, x, y, NULL, "%3.2f", fps);
y -= gl_defFont.h + 5.;
}
if(dt_mod != 1.)
gl_print(NULL, x, y, NULL, "%3.1fx", dt_mod);
} }
/** /**

View File

@ -51,7 +51,7 @@ void opt_menuKeybinds(void) {
/* Create the list. */ /* Create the list. */
for(i = 0; strcmp(keybindNames[i], "end"); i++); for(i = 0; strcmp(keybindNames[i], "end"); i++);
str = malloc(sizeof(char*) * (i-1)); str = malloc(sizeof(char*) * i);
for(j = 0; j < i; j++) { for(j = 0; j < i; j++) {
str[j] = malloc(sizeof(char) * 64); str[j] = malloc(sizeof(char) * 64);
key = input_getKeybind(keybindNames[j], &type, &mod, &reverse); key = input_getKeybind(keybindNames[j], &type, &mod, &reverse);
@ -75,7 +75,7 @@ void opt_menuKeybinds(void) {
} }
} }
window_addList(wid, 20, -40, 200, KEYBINDS_HEIGHT-60, "lstKeybinds", window_addList(wid, 20, -40, 200, KEYBINDS_HEIGHT-60, "lstKeybinds",
str, i-1, 0, menuKeybinds_update); str, i, 0, menuKeybinds_update);
/* Update the list. */ /* Update the list. */
menuKeybinds_update(wid, NULL); menuKeybinds_update(wid, NULL);

View File

@ -12,7 +12,8 @@
#include "pilot.h" #include "pilot.h"
#include "pause.h" #include "pause.h"
int paused = 0; /* Are we paused. */ int paused = 0; /* Are we paused. */
double dt_mod = 1.; /**< dt modifier. */
/* From pilot.c */ /* From pilot.c */
extern Pilot** pilot_stack; extern Pilot** pilot_stack;
@ -46,6 +47,13 @@ void pause_delay(unsigned int delay) {
pilot_delay(delay); pilot_delay(delay);
} }
/**
* @brief Adjust the game's dt modifier.
*/
void pause_setSpeed(double mod) {
dt_mod = mod;
}
/* Pilots pausing/unpausing. */ /* Pilots pausing/unpausing. */
static void pilot_pause(void) { static void pilot_pause(void) {
int i, j; int i, j;

View File

@ -1,6 +1,9 @@
#pragma once #pragma once
extern int paused; extern int paused;
extern double dt_mod;
void pause_setSpeed(double mod);
void pause_game(void); void pause_game(void);
void unpause_game(void); void unpause_game(void);

View File

@ -1551,6 +1551,10 @@ void player_abortAutonav(char* reason) {
/* Get rid of acceleration. */ /* Get rid of acceleration. */
player_accelOver(); player_accelOver();
/* Drop out of possible different speed modes. */
if(dt_mod != 1.)
pause_setSpeed(1.);
/* Break possible hyperspacing. */ /* Break possible hyperspacing. */
if(pilot_isFlag(player, PILOT_HYP_PREP)) { if(pilot_isFlag(player, PILOT_HYP_PREP)) {
pilot_hyperspaceAbort(player); pilot_hyperspaceAbort(player);