mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-17 05:55:47 +01:00
make basic header files.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "SDL_messagebox.h"
|
||||
#include "main.h"
|
||||
|
||||
#define PRINT_BUFFER_SIZE 128 // defines the buffer size for printing
|
||||
|
||||
@@ -17,9 +16,10 @@
|
||||
(void)vsnprintf(buf, PRINT_BUFFER_SIZE, fmt, args); \
|
||||
va_end(args);
|
||||
|
||||
// sets the game status (in turn exiting (if not set to STATUS_RUNNING))
|
||||
static void stop(gamestatus status) {
|
||||
set_gamestatus(status);
|
||||
static gamestatus status = STATUS_RUNNING;
|
||||
|
||||
gamestatus get_gamestatus(void) {
|
||||
return status;
|
||||
}
|
||||
|
||||
void debug(char const* fmt, ...) {
|
||||
@@ -45,10 +45,10 @@ void warn(char const* fmt, ...) {
|
||||
(void)fprintf(stderr, "\033[93mW: %s\033[0m\n", buf);
|
||||
}
|
||||
|
||||
void error(gamestatus status, char const* fmt, ...) {
|
||||
void error(gamestatus error_code, char const* fmt, ...) {
|
||||
char buf[PRINT_BUFFER_SIZE] = {0};
|
||||
write_args(buf, fmt);
|
||||
(void)fprintf(stderr, "\033[91mE: %s\033[0m\n", buf);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buf, NULL);
|
||||
stop(status);
|
||||
status = error_code;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ enum {
|
||||
};
|
||||
typedef int8_t gamestatus;
|
||||
|
||||
gamestatus get_gamestatus(void); // gets the current status of the game
|
||||
void debug(char const*, ...); // prints a debug message to stdout if the DEBUG environment variable is set, otherwise the call is ignored.
|
||||
void info(char const*, ...); // prints an info message to stdout
|
||||
void warn(char const*, ...); // prints a warning message to stderr
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "game.h"
|
||||
|
||||
#include "../error_handling.h"
|
||||
|
||||
void game_init(game_data* dat) {
|
||||
(void)dat;
|
||||
error(STATUS_ERROR, "function not defined");
|
||||
}
|
||||
|
||||
void game_update(game_data* dat) {
|
||||
(void)dat;
|
||||
error(STATUS_ERROR, "function not defined");
|
||||
}
|
||||
|
||||
void game_free(game_data* dat) {
|
||||
(void)dat;
|
||||
error(STATUS_ERROR, "function not defined");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t tmp;
|
||||
} game_data;
|
||||
|
||||
void game_init(game_data*); // initializes everything needed to start the game; outputs to game_data
|
||||
void game_update(game_data*); // causes an update to occur within the game
|
||||
void game_free(game_data*); // frees the resources associated with the game
|
||||
|
||||
27
src/main.c
27
src/main.c
@@ -1,17 +1,30 @@
|
||||
#include "main.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "error_handling.h"
|
||||
#include "game/game.h"
|
||||
#include "window/render.h"
|
||||
|
||||
static gamestatus status = STATUS_RUNNING;
|
||||
static game_data gdat; // initialized in init(), reading beforehand is undefined behaviour
|
||||
static render_data rdat; // initialized in init(), reading beforehand is undefined behaviour
|
||||
|
||||
void set_gamestatus(gamestatus new_status) {
|
||||
status = new_status;
|
||||
static void init(void) {
|
||||
game_init(&gdat);
|
||||
render_init(&rdat, &gdat);
|
||||
}
|
||||
|
||||
static void update(void) {
|
||||
// perform updates
|
||||
game_update(&gdat);
|
||||
render_update(&rdat);
|
||||
}
|
||||
|
||||
int32_t main(int32_t argc, char** argv) {
|
||||
(void)argc, (void)argv;
|
||||
debug("%s", "Hello, World!");
|
||||
return status;
|
||||
|
||||
init();
|
||||
|
||||
while (get_gamestatus() == STATUS_RUNNING)
|
||||
update();
|
||||
|
||||
return get_gamestatus();
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "error_handling.h"
|
||||
|
||||
void set_gamestatus(gamestatus); // sets the status of the game (allows for quitting the game)
|
||||
19
src/window/render.c
Normal file
19
src/window/render.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "render.h"
|
||||
|
||||
#include "../error_handling.h"
|
||||
#include "../game/game.h"
|
||||
|
||||
void render_init(render_data* const rdat, game_data const* const gdat) {
|
||||
(void)rdat, (void)gdat;
|
||||
error(STATUS_ERROR, "function not implemented");
|
||||
}
|
||||
|
||||
void render_update(render_data const* const rdat) {
|
||||
(void)rdat;
|
||||
error(STATUS_ERROR, "function not implemented");
|
||||
}
|
||||
|
||||
void render_free(render_data* const rdat) {
|
||||
(void)rdat;
|
||||
error(STATUS_ERROR, "function not implemented");
|
||||
}
|
||||
17
src/window/render.h
Normal file
17
src/window/render.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL_render.h>
|
||||
#include <SDL_video.h>
|
||||
|
||||
#include "../game/game.h"
|
||||
|
||||
// contains the data necessary for rendering
|
||||
typedef struct {
|
||||
SDL_Window* window;
|
||||
SDL_Renderer* renderer;
|
||||
game_data const* gdat;
|
||||
} render_data;
|
||||
|
||||
void render_init(render_data*, game_data const*); // initializes the renderer, outputs to render_data
|
||||
void render_update(render_data const*); // causes a draw to occur, will also determine update rate
|
||||
void render_free(render_data*); // frees the memory allocated to the renderer in render_data
|
||||
Reference in New Issue
Block a user