[Add] 2x speed modifier by manipulating dt modifier.
[Fix] Fixed double free on keybindings opening.
This commit is contained in:
parent
ee57228de5
commit
355ccfd65e
14
src/input.c
14
src/input.c
@ -48,7 +48,7 @@ const char* keybindNames[] = {
|
||||
/* Communication. */
|
||||
"hail",
|
||||
/* Misc. */
|
||||
"mapzoomin", "mapzoomout", "screenshot", "pause", "menu", "info",
|
||||
"mapzoomin", "mapzoomout", "screenshot", "pause", "speed", "menu", "info",
|
||||
"end" /* Must terminate at the end. */
|
||||
};
|
||||
|
||||
@ -79,17 +79,19 @@ const char* keybindDescription[] = {
|
||||
"Clears your escorts commands.",
|
||||
/* Space navigation. */
|
||||
"Initializes the autonavigation system.",
|
||||
"Cycles through hyperspace targets.",
|
||||
"Cycles through planet targets.",
|
||||
"Attempt to land on your targetted planet or targets nearest landable planet. \
|
||||
Requests for landing if you don't have permission yet.",
|
||||
"Cycles through hyperspace targets.",
|
||||
"Opens the Star Map.",
|
||||
"Attempt to jump to your hyperspace target.",
|
||||
/* Communication. */
|
||||
"Attempts to initialize communication with your taretted ship.",
|
||||
/* Misc. */
|
||||
"Zooms in on your radar.",
|
||||
"Zooms out on your radar.",
|
||||
"Takes a screenshot.",
|
||||
"Toggles 2x speed modifier.",
|
||||
"Pauses the game.",
|
||||
"Opens the small ingame 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("screenshot", KEYBIND_KEYBOARD, SDLK_KP_MULTIPLY, 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("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();
|
||||
}
|
||||
}
|
||||
/* 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. */
|
||||
else if(KEY("menu")) {
|
||||
if(value == KEY_PRESS) menu_small();
|
||||
|
@ -452,9 +452,11 @@ static void fps_control(void) {
|
||||
unsigned int t;
|
||||
double delay;
|
||||
|
||||
/* dt in ms/1000. */
|
||||
/* dt in s. */
|
||||
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;
|
||||
|
||||
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) {
|
||||
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.);
|
||||
return;
|
||||
}
|
||||
@ -578,8 +580,12 @@ static void display_fps(const double dt) {
|
||||
|
||||
x = 10.;
|
||||
y = (double)(gl_screen.h - 20);
|
||||
if(show_fps)
|
||||
if(show_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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ void opt_menuKeybinds(void) {
|
||||
|
||||
/* Create the list. */
|
||||
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++) {
|
||||
str[j] = malloc(sizeof(char) * 64);
|
||||
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",
|
||||
str, i-1, 0, menuKeybinds_update);
|
||||
str, i, 0, menuKeybinds_update);
|
||||
|
||||
/* Update the list. */
|
||||
menuKeybinds_update(wid, NULL);
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "pause.h"
|
||||
|
||||
int paused = 0; /* Are we paused. */
|
||||
double dt_mod = 1.; /**< dt modifier. */
|
||||
|
||||
/* From pilot.c */
|
||||
extern Pilot** pilot_stack;
|
||||
@ -46,6 +47,13 @@ void pause_delay(unsigned int delay) {
|
||||
pilot_delay(delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adjust the game's dt modifier.
|
||||
*/
|
||||
void pause_setSpeed(double mod) {
|
||||
dt_mod = mod;
|
||||
}
|
||||
|
||||
/* Pilots pausing/unpausing. */
|
||||
static void pilot_pause(void) {
|
||||
int i, j;
|
||||
|
@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
extern int paused;
|
||||
extern double dt_mod;
|
||||
|
||||
void pause_setSpeed(double mod);
|
||||
|
||||
void pause_game(void);
|
||||
void unpause_game(void);
|
||||
|
@ -1551,6 +1551,10 @@ void player_abortAutonav(char* reason) {
|
||||
/* Get rid of acceleration. */
|
||||
player_accelOver();
|
||||
|
||||
/* Drop out of possible different speed modes. */
|
||||
if(dt_mod != 1.)
|
||||
pause_setSpeed(1.);
|
||||
|
||||
/* Break possible hyperspacing. */
|
||||
if(pilot_isFlag(player, PILOT_HYP_PREP)) {
|
||||
pilot_hyperspaceAbort(player);
|
||||
|
Loading…
Reference in New Issue
Block a user