painfull-success-cg/src/main.c

67 lines
1.7 KiB
C

/* SPDX-License-Identifier: MIT
* Copyright (c) 2021 KikooDX
* This file is part of
* [Painfull Success CG](https://git.sr.ht/~kikoodx/painfull-success-cg),
* which is MIT licensed. The MIT license requires this copyright notice to be
* included in all copies and substantial portions of the software. */
#include <gint/display.h>
#include <gint/timer.h>
#include <gint/clock.h>
#include <gint/std/string.h>
#include <stdint.h>
#include <stdbool.h>
#include "conf.h"
#include "input.h"
#include "level.h"
#include "player.h"
void load_level(Level *level, Player *player, uint8_t id) {
extern Level levels[LEVEL_SIZE];
memcpy(level->content, levels[id].content, LEVEL_SIZE);
level->start_pos = levels[id].start_pos;
player->pos = levels[id].start_pos;
}
int callback(volatile void *arg) {
volatile bool *has_ticked = arg;
*has_ticked = true;
return 0;
}
int main(void) {
/* Initialize player. */
Player player = player_init();
/* Initialize level. */
Level level = (Level){};
uint8_t level_id = 0;
load_level(&level, &player, level_id);
/* Initialize input. */
Input input = (Input){};
input_init(&input);
/* UPS control. */
volatile bool has_ticked = true;
int timer = timer_setup(TIMER_ANY, 1000000/TARGET_UPS, callback, &has_ticked);
timer_start(timer);
/* Core loop. */
while (!input_is_down(&input, K_EXIT)) {
/* Repeat step event so the UPS is constant. */
for (uint8_t i = 0; i < TARGET_UPS / TARGET_FPS; i += 1) {
/* UPS control. */
while (!has_ticked) sleep();
has_ticked = false;
/* Update. */
input_update(&input);
/* player_update(&player, &level, &level_id); */
}
/* Draw. */
dclear(C_BLACK);
/* player_draw(player); */
level_draw(level);
dupdate();
}
return 1;
}