Fumofumotris/source/fumoengine/fumoengine.c

62 lines
1.4 KiB
C
Raw Normal View History

2024-05-02 22:17:37 +00:00
#include "fumoengine.h"
#include "platform.h"
2024-04-30 21:41:31 +00:00
2024-03-25 05:34:59 +00:00
2024-05-06 05:52:30 +00:00
void Panic(char *message)
2024-04-19 20:23:11 +00:00
{
printf(message);
exit(1);
}
2024-05-07 22:10:15 +00:00
bool CreateFumoInstance(struct FumoInstance *instance)
2024-04-09 07:00:48 +00:00
{
2024-04-19 20:23:11 +00:00
if (!PlatformInit())
2024-05-06 05:52:30 +00:00
Panic("Platform failed to initialize");
2024-04-19 20:23:11 +00:00
2024-05-07 22:10:15 +00:00
if (!CreateController(&instance->ctrl))
2024-05-06 05:52:30 +00:00
Panic("Out of memory");
2024-04-03 23:31:47 +00:00
2024-05-07 22:10:15 +00:00
if (!CreateInputThread(&instance->input_hand))
Panic("Input handle failed to initialize");
if (!CreateTerminal(&instance->term, 20, 10))
2024-05-06 05:52:30 +00:00
Panic("Out of memory");
2024-04-22 22:13:13 +00:00
2024-05-07 22:10:15 +00:00
if (!CreateEvent(&instance->on_start))
Panic("Out of memory");
2024-05-08 12:47:46 +00:00
if (!CreateEvent(&instance->on_update))
2024-05-07 22:10:15 +00:00
Panic("Out of memory");
instance->time = TimeNow();
return true;
}
2024-05-08 12:47:46 +00:00
bool FumoInstanceRun(struct FumoInstance *inst)
2024-05-07 22:10:15 +00:00
{
2024-05-08 12:47:46 +00:00
EventInvoke(&inst->on_start, inst);
usize buf_n = TerminalMaxOut(&inst->term);
2024-05-07 22:10:15 +00:00
char *buf = malloc(buf_n);
while (true) {
2024-05-08 12:47:46 +00:00
if (!InputAquire(&inst->input_hand))
2024-05-07 22:10:15 +00:00
Panic("Aquire failed");
2024-05-08 12:47:46 +00:00
ControllerPoll(&inst->ctrl, &inst->input_hand.recs);
2024-05-07 22:10:15 +00:00
2024-05-08 12:47:46 +00:00
if (!InputRelease(&inst->input_hand))
2024-05-07 22:10:15 +00:00
Panic("Release failed");
nsec now = TimeNow();
2024-05-08 12:47:46 +00:00
inst->frametime = now - inst->time;
EventInvoke(&inst->on_update, inst);
inst->time = now;
2024-05-07 22:10:15 +00:00
2024-05-08 12:47:46 +00:00
TerminalPrint(&inst->term, buf, buf_n);
2024-05-07 22:10:15 +00:00
puts(buf);
2024-04-03 23:31:47 +00:00
2024-05-08 12:47:46 +00:00
//_sleep(100);
2024-05-07 22:10:15 +00:00
}
2024-03-25 05:34:59 +00:00
}