Fumofumotris/source/fumoengine/fumoengine.c
Julia 582b157454 gdf
dfg
2024-05-13 23:20:20 -05:00

63 lines
1.4 KiB
C

#include "fumoengine.h"
#include "platform.h"
void Panic(char *message)
{
printf(message);
exit(1);
}
bool CreateFumoInstance(struct FumoInstance *instance)
{
if (!PlatformInit())
Panic("Platform failed to initialize");
if (!CreateController(&instance->ctrl))
Panic("Out of memory");
if (!CreateInputThread(&instance->input_hand))
Panic("Input handle failed to initialize");
if (!CreateTerminal(&instance->term, 20, 10))
Panic("Out of memory");
if (!CreateEvent(&instance->on_start))
Panic("Out of memory");
if (!CreateEvent(&instance->on_update))
Panic("Out of memory");
instance->time = TimeNow();
return true;
}
bool FumoInstanceRun(struct FumoInstance *inst)
{
EventInvoke(&inst->on_start, inst);
usize buf_n = TerminalMaxOut(&inst->term);
char *buf = malloc(buf_n);
while (true) {
if (!InputAquire(&inst->input_hand))
Panic("Aquire failed");
ControllerPoll(&inst->ctrl, &inst->input_hand.recs);
if (!InputRelease(&inst->input_hand))
Panic("Release failed");
nsec now = TimeNow();
inst->frametime = now - inst->time;
inst->time = now;
EventInvoke(&inst->on_update, inst);
TerminalPrint(&inst->term, buf, buf_n);
puts(buf);
//_sleep(100);
}
}