2024-03-25 05:34:59 +00:00
|
|
|
#include <iso646.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-04-15 19:29:51 +00:00
|
|
|
#include "ctrl.h"
|
2024-04-18 05:04:44 +00:00
|
|
|
#include "input.h"
|
2024-03-25 05:34:59 +00:00
|
|
|
#include "fumotris.h"
|
|
|
|
#include "term.h"
|
2024-04-03 23:31:47 +00:00
|
|
|
#include "event.h"
|
2024-04-16 22:14:53 +00:00
|
|
|
#include "platform.h"
|
2024-03-25 05:34:59 +00:00
|
|
|
|
2024-04-19 20:23:11 +00:00
|
|
|
void ErrorExit(char *message)
|
|
|
|
{
|
|
|
|
printf(message);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2024-04-22 22:13:13 +00:00
|
|
|
struct Game {
|
|
|
|
struct Event Start;
|
|
|
|
struct Event Draw;
|
|
|
|
struct Event Update;
|
|
|
|
|
|
|
|
Time time;
|
|
|
|
};
|
|
|
|
|
2024-04-09 07:00:48 +00:00
|
|
|
int main()
|
|
|
|
{
|
2024-04-19 20:23:11 +00:00
|
|
|
if (!PlatformInit())
|
|
|
|
ErrorExit("Platform failed to initialize");
|
|
|
|
|
|
|
|
struct Controller ctrl;
|
|
|
|
if (!CreateCtrl(&ctrl))
|
|
|
|
ErrorExit("Out of memory");
|
2024-04-03 23:31:47 +00:00
|
|
|
|
2024-04-22 22:13:13 +00:00
|
|
|
struct Game game;
|
|
|
|
CreateEvent(&game.Update);
|
|
|
|
|
|
|
|
struct InputThreadHandle input_hand;
|
|
|
|
if (!BeginInputThread(&input_hand, &ctrl.buf))
|
2024-04-19 20:23:11 +00:00
|
|
|
ErrorExit("Input handle failed to initialize");
|
2024-04-03 23:31:47 +00:00
|
|
|
|
2024-04-22 05:19:54 +00:00
|
|
|
CtrlMap(&ctrl, 0, BUTTON, 'A');
|
|
|
|
|
|
|
|
while (true) {
|
2024-04-22 22:13:13 +00:00
|
|
|
if(!CtrlPoll(&ctrl, &input_hand))
|
|
|
|
ErrorExit("Poll failed");
|
2024-04-22 05:19:54 +00:00
|
|
|
|
2024-04-22 22:13:13 +00:00
|
|
|
EventInvokeUpdate(&game.Update, nullptr);
|
2024-04-22 05:19:54 +00:00
|
|
|
}
|
2024-04-03 23:31:47 +00:00
|
|
|
|
2024-03-25 05:34:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|