prosperon/source/engine/yugine.c

165 lines
3.4 KiB
C
Raw Normal View History

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 18:10:29 -05:00
#include "script.h"
#include "editor.h"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef __linux__
#include <execinfo.h>
#endif
#include <signal.h>
#include <time.h>
2022-02-04 11:36:24 -06:00
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;
void seghandle(int sig) {
void *ents[512];
size_t size;
size = backtrace(ents, 512);
if (strsignal(sig)) {
YughCritical("CRASH! Signal: %s.", strsignal(sig));
}
else {
YughCritical("CRASH! Signal: %d.", sig);
}
YughCritical("====================BACKTRACE====================");
char **stackstr = backtrace_symbols(ents, size);
for (int i = 0; i < size; i++) {
YughCritical(stackstr[i]);
}
exit(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] == '-') {
switch(args[i][1]) {
case 'p':
if (strncmp(&args[i][2], "lay", 3))
continue;
ed = 0;
break;
case 'l':
if (i+1 < argc && args[i+1][0] != '-') {
log_setfile(args[i+1]);
i++;
continue;
}
else {
YughError("Expected a file for command line arg '-l'.");
exit(1);
}
case 'v':
printf("Yugine version %s, %s build.\n", VER, INFO);
printf("Copyright 2022 odplot productions LLC.\n");
exit(1);
break;
2022-08-14 14:19:36 -05:00
}
}
}
if (DBG) {
time_t now = time(NULL);
char fname[100];
snprintf(fname, 100, "yugine-%d.log", now);
log_setfile(fname);
}
YughInfo("Starting yugine version %s.", VER);
signal(SIGSEGV, seghandle);
FILE *sysinfo = NULL;
sysinfo = popen("uname -a", "r");
if (!sysinfo) {
YughWarn("Failed to get sys info.");
} else {
log_cat(sysinfo);
pclose(sysinfo);
}
2022-08-14 14:19:36 -05:00
FILE *gameinfo = NULL;
gameinfo = fopen("game.info", "w");
fprintf(gameinfo, "Yugine v. %s, sys %s.", VER, INFO);
fclose(gameinfo);
2022-01-19 16:43:21 -06:00
engine_init();
2022-08-15 16:38:21 -05:00
const GLFWvidmode *vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
YughInfo("Refresh rate is %d", vidmode->refreshRate);
2022-08-15 16:38:21 -05:00
renderMS = 1.0/vidmode->refreshRate;
double framet = fmin(fmin(renderMS,physMS),updateMS);
2022-11-20 15:50:14 -06:00
script_dofile("scripts/engine.rb");
2022-08-14 16:01:29 -05:00
script_dofile("config.rb");
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
//timer_update(lastTick);
2022-08-22 08:55:54 -05:00
2022-08-15 16:38:21 -05:00
//renderlag += elapsed;
//physlag += elapsed;
2022-01-19 16:43:21 -06:00
2022-08-07 01:43:45 -05:00
if (renderlag >= renderMS) {
renderlag -= renderMS;
}
2022-01-19 16:43:21 -06:00
2022-08-15 16:38:21 -05:00
window_renderall();
input_poll(renderMS- elapsed < 0 ? 0 : renderMS - elapsed);
2022-08-12 14:03:56 -05:00
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
}
return 0;
2022-01-19 16:43:21 -06:00
}