forked from archive/yeti3dpro
sdl3: speed limiter and cmdline map selection
This commit is contained in:
parent
35e58e9e13
commit
5ec96d087a
1 changed files with 37 additions and 5 deletions
|
@ -7,6 +7,8 @@
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "maps.h"
|
#include "maps.h"
|
||||||
|
|
||||||
|
#define MAXFPS (60)
|
||||||
|
|
||||||
static yeti_t yeti;
|
static yeti_t yeti;
|
||||||
static u16 backbuffer[YETI_FRAMEBUFFER_WIDTH * YETI_FRAMEBUFFER_HEIGHT];
|
static u16 backbuffer[YETI_FRAMEBUFFER_WIDTH * YETI_FRAMEBUFFER_HEIGHT];
|
||||||
|
|
||||||
|
@ -18,6 +20,10 @@ static SDL_Surface *back = NULL;
|
||||||
|
|
||||||
static bool focused = true;
|
static bool focused = true;
|
||||||
|
|
||||||
|
static Sint64 now = 0, then = 0;
|
||||||
|
|
||||||
|
static int requested_map = 0;
|
||||||
|
|
||||||
static void die(const char *fmt, ...)
|
static void die(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
static char error[1024];
|
static char error[1024];
|
||||||
|
@ -78,14 +84,29 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv)
|
||||||
yeti_init(&yeti, backbuffer, backbuffer, textures, palette);
|
yeti_init(&yeti, backbuffer, backbuffer, textures, palette);
|
||||||
yeti_init_lua(&yeti, YETI_GAMMA);
|
yeti_init_lua(&yeti, YETI_GAMMA);
|
||||||
game_init(&yeti);
|
game_init(&yeti);
|
||||||
game_load_map(&yeti, &map_e1m1);
|
|
||||||
|
/* get requested map */
|
||||||
|
if (argc > 1)
|
||||||
|
requested_map = SDL_atoi(argv[1]);
|
||||||
|
|
||||||
|
SDL_Log("Loading map %d", requested_map);
|
||||||
|
|
||||||
|
if (requested_map >= 0)
|
||||||
|
game_load_map(&yeti, maps[requested_map]);
|
||||||
|
else
|
||||||
|
game_load_map(&yeti, &map_e1m1);
|
||||||
|
|
||||||
game_goto(&yeti.game, GAME_MODE_PLAY);
|
game_goto(&yeti.game, GAME_MODE_PLAY);
|
||||||
|
|
||||||
|
/* start counting time */
|
||||||
|
then = SDL_GetTicks();
|
||||||
|
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
void do_frame(Sint64 dt)
|
||||||
{
|
{
|
||||||
|
static Sint64 frame_delta = 1000;
|
||||||
const bool *keys = SDL_GetKeyboardState(NULL);
|
const bool *keys = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
yeti.keyboard.state.up = keys[SDL_SCANCODE_UP] || keys[SDL_SCANCODE_W];
|
yeti.keyboard.state.up = keys[SDL_SCANCODE_UP] || keys[SDL_SCANCODE_W];
|
||||||
|
@ -98,10 +119,21 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||||
yeti.keyboard.state.r = keys[SDL_SCANCODE_Z];
|
yeti.keyboard.state.r = keys[SDL_SCANCODE_Z];
|
||||||
yeti.keyboard.state.select = keys[SDL_SCANCODE_ESCAPE];
|
yeti.keyboard.state.select = keys[SDL_SCANCODE_ESCAPE];
|
||||||
|
|
||||||
SDL_FillSurfaceRect(back, NULL, 0);
|
frame_delta += dt;
|
||||||
SDL_FillSurfaceRect(front, NULL, 0);
|
|
||||||
|
|
||||||
game_loop(&yeti);
|
if (frame_delta > (1000 / MAXFPS))
|
||||||
|
{
|
||||||
|
game_loop(&yeti);
|
||||||
|
frame_delta = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||||
|
{
|
||||||
|
/* speed limiter */
|
||||||
|
now = SDL_GetTicks();
|
||||||
|
do_frame(now - then);
|
||||||
|
then = now;
|
||||||
|
|
||||||
SDL_BlitSurface(back, NULL, front, NULL);
|
SDL_BlitSurface(back, NULL, front, NULL);
|
||||||
SDL_UpdateTexture(texture, NULL, front->pixels, front->pitch);
|
SDL_UpdateTexture(texture, NULL, front->pixels, front->pitch);
|
||||||
|
|
Loading…
Reference in a new issue