2022-02-06 10:14:57 -06:00
|
|
|
#include "render.h"
|
2022-02-04 11:36:24 -06:00
|
|
|
#include "camera.h"
|
|
|
|
#include "window.h"
|
2022-01-19 16:43:21 -06:00
|
|
|
#include "engine.h"
|
2022-02-04 11:36:24 -06:00
|
|
|
#include "input.h"
|
|
|
|
#include "openglrender.h"
|
|
|
|
|
2022-08-14 14:19:36 -05:00
|
|
|
#include "string.h"
|
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
int physOn = 0;
|
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
double renderlag = 0;
|
2022-08-12 14:03:56 -05:00
|
|
|
double physlag = 0;
|
|
|
|
double updatelag = 0;
|
|
|
|
|
|
|
|
double renderMS = 1/60.f;
|
|
|
|
double physMS = 1/120.f;
|
|
|
|
double updateMS = 1/60.f;
|
2022-02-04 11:36:24 -06:00
|
|
|
|
2022-08-14 14:19:36 -05:00
|
|
|
static int ed = 1;
|
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
|
2022-08-07 01:43:45 -05:00
|
|
|
int main(int argc, char **args) {
|
2022-08-14 14:19:36 -05:00
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (args[i][0] == '-') {
|
|
|
|
if (strncmp(args[i][1], "play", 4) == 0) {
|
|
|
|
ed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-19 16:43:21 -06:00
|
|
|
engine_init();
|
|
|
|
|
2022-08-07 01:43:45 -05:00
|
|
|
window_set_icon("icon.png");
|
|
|
|
|
2022-08-14 14:19:36 -05:00
|
|
|
if (ed) {
|
|
|
|
editor_init(MakeSDLWindow("Editor", 600, 600, 0));
|
|
|
|
} else {
|
|
|
|
script_dofile("game.rb");
|
|
|
|
}
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
openglInit();
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2022-08-07 01:43:45 -05:00
|
|
|
renderMS = 0.033;
|
2022-02-03 09:16:22 -06:00
|
|
|
|
2022-08-07 01:43:45 -05:00
|
|
|
double lastTick;
|
2022-01-19 16:43:21 -06:00
|
|
|
|
|
|
|
while (!quit) {
|
2022-08-07 01:43:45 -05:00
|
|
|
double elapsed;
|
2022-08-12 14:03:56 -05:00
|
|
|
elapsed = glfwGetTime() - lastTick;
|
|
|
|
lastTick = glfwGetTime();
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2022-08-07 01:43:45 -05:00
|
|
|
renderlag += elapsed;
|
2022-08-12 14:03:56 -05:00
|
|
|
physlag += elapsed;
|
2022-01-19 16:43:21 -06:00
|
|
|
|
|
|
|
|
2022-08-07 01:43:45 -05:00
|
|
|
if (renderlag >= renderMS) {
|
|
|
|
renderlag -= renderMS;
|
|
|
|
window_renderall();
|
|
|
|
}
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2022-08-12 14:03:56 -05:00
|
|
|
input_poll(updateMS - elapsed < 0 ? 0 : updateMS - elapsed);
|
|
|
|
window_all_handle_events();
|
2022-08-14 14:19:36 -05:00
|
|
|
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-01-19 16:43:21 -06:00
|
|
|
}
|
|
|
|
}
|