44 lines
1.1 KiB
C
44 lines
1.1 KiB
C
#include "ok_game.h"
|
|
#include "ok_render.h"
|
|
#include <stdio.h>
|
|
#include <SDL.h>
|
|
|
|
#ifndef OPENKKND_VERSION
|
|
#define OPENKKND_VERSION "dev"
|
|
#endif
|
|
|
|
int main(int argc, char **argv) {
|
|
(void)argc;
|
|
(void)argv;
|
|
printf("OpenKKND %s — original genre RTS (MIT). No commercial IP assets.\n", OPENKKND_VERSION);
|
|
|
|
const int tw = 12;
|
|
if (!ok_render_init(OK_MAP_W * tw, OK_MAP_H * tw)) {
|
|
fprintf(stderr, "render init failed\n");
|
|
return 1;
|
|
}
|
|
|
|
OkGame game;
|
|
ok_game_init(&game);
|
|
|
|
Uint64 prev = SDL_GetPerformanceCounter();
|
|
const Uint64 freq = SDL_GetPerformanceFrequency();
|
|
|
|
while (game.running || true) {
|
|
SDL_Event e;
|
|
while (SDL_PollEvent(&e)) {
|
|
if (e.type == SDL_QUIT) goto done;
|
|
if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) goto done;
|
|
if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_r) ok_game_init(&game);
|
|
}
|
|
Uint64 now = SDL_GetPerformanceCounter();
|
|
float dt = (float)(now - prev) / (float)freq;
|
|
prev = now;
|
|
if (dt > 0.05f) dt = 0.05f;
|
|
if (game.running) ok_game_update(&game, dt);
|
|
ok_render_draw(&game);
|
|
}
|
|
done:
|
|
ok_render_shutdown();
|
|
return 0;
|
|
}
|