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-07 22:10:15 +00:00
|
|
|
VectorT FUMOSYS_VEC_T = VECTOR_T(struct FumoHook);
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
if (!CreateEvent(FUMOSYS_VEC_T, &instance->on_update))
|
|
|
|
Panic("Out of memory");
|
|
|
|
|
|
|
|
instance->time = TimeNow();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FumoInstanceRun(struct FumoInstance *instance)
|
|
|
|
{
|
|
|
|
usize buf_n = TerminalMaxOut(&instance->term);
|
|
|
|
char *buf = malloc(buf_n);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (!InputAquire(&instance->input_hand))
|
|
|
|
Panic("Aquire failed");
|
|
|
|
|
|
|
|
ControllerPoll(&instance->ctrl, &instance->input_hand.recs);
|
|
|
|
|
|
|
|
if (!InputRelease(&instance->input_hand))
|
|
|
|
Panic("Release failed");
|
|
|
|
|
|
|
|
nsec now = TimeNow();
|
|
|
|
instance->frametime = now - instance->time;
|
|
|
|
FumoInvoke(instance, &instance->on_update);
|
|
|
|
instance->time = now;
|
|
|
|
|
|
|
|
TerminalPrint(&instance->term, buf, buf_n);
|
|
|
|
puts(buf);
|
2024-04-03 23:31:47 +00:00
|
|
|
|
2024-05-07 22:10:15 +00:00
|
|
|
_sleep(100);
|
|
|
|
}
|
2024-03-25 05:34:59 +00:00
|
|
|
}
|