#include "u_stdio.h"
#include "u_defs.h"
#include "p_platform.h"
+#include "r_render.h"
struct lrts_config lrts_global_cfg;
while (!lrts_cfg()->exit) {
p_poll_events();
+ r_render_frame();
}
p_renderer_finish();
/**
* System includes
*/
+#include "config.h"
#include "u_assert.h"
#include "u_defs.h"
-#include "config.h"
#ifdef LRTS_RENDERER_SDL
#include "p_r_sdl/p_init.c"
+#include "p_r_sdl/p_draw.c"
#endif
#ifdef LRTS_RENDERER_CLI
#include "t_tile.c"
#include "u_log.c"
#include "u_arena.c"
+#include "t_map.c"
+#include "t_camera.c"
+#include "r_render.c"
+#include "r_color.c"
#endif
--- /dev/null
+#ifndef P_DRAW_H__
+#define P_DRAW_H__
+
+#include "u_defs.h"
+#include "r_color.h"
+
+
+/* draws a singel pixel directly to the screen */
+void p_draw_pixel(i32 x, i32 y, struct r_color color);
+
+#endif
--- /dev/null
+#include "../p_draw.h"
+
+void p_draw_pixel(i32 x, i32 y, struct r_color color) {
+ LRTS_UNUSED(x);
+ LRTS_UNUSED(y);
+ LRTS_UNUSED(color);
+}
--- /dev/null
+
+struct r_color r_color(u8 r, u8 g, u8 b, u8 a) {
+ struct r_color c;
+ c.r = r;
+ c.g = g;
+ c.b = b;
+ c.a = a;
+ return c;
+}
--- /dev/null
+#ifndef R_COLOR_H__
+#define R_COLOR_H__
+
+#include "u_defs.h"
+
+struct r_color {
+ u8 r;
+ u8 g;
+ u8 b;
+ u8 a;
+};
+
+struct r_color r_color(u8 r, u8 g, u8 b, u8 a);
+
+#endif
--- /dev/null
+#include "r_render.h"
+#include "r_color.h"
+#include "p_draw.h"
+
+void r_render_frame() {
+ struct r_color c = r_color(0, 0, 0, 0xFF);
+
+ p_draw_pixel(0, 0, c);
+}
--- /dev/null
+#ifndef R_RENDER_H__
+#define R_RENDER_H__
+
+void r_render_frame();
+
+#endif
--- /dev/null
+#include "t_camera.h"
+
+struct t_camera t_camera_init(i32 viewport_x, i32 viewport_y) {
+ struct t_camera c;
+ c.x = 0;
+ c.y = 0;
+ c.viewport_x = viewport_x;
+ c.viewport_y = viewport_y;
+
+ return c;
+}
+
+void t_camera_scroll(struct t_camera *c, i32 by_x, i32 by_y) {
+ c->x += by_x;
+ c->y += by_y;
+ U_CLAMP(c->x, 0, c->viewport_x);
+ U_CLAMP(c->y, 0, c->viewport_y);
+}
--- /dev/null
+#ifndef T_CAMERA_H__
+#define T_CAMERA_H__
+
+#include "u_defs.h"
+
+struct t_camera {
+ i32 x;
+ i32 y;
+
+ i32 viewport_x;
+ i32 viewport_y;
+};
+
+struct t_camera t_camera_init(i32 viewport_x, i32 viewport_y);
+
+void t_camera_scroll(struct t_camera *c, i32 by_x, i32 by_y);
+
+#endif
--- /dev/null
+#include "t_map.h"
--- /dev/null
+#ifndef T_MAP_H__
+#define T_MAP_H__
+
+#include "u_defs.h"
+#include "t_tile.h"
+
+#define T_MAP_MAX_W 256
+#define T_MAP_MAX_H 256
+
+struct t_map {
+ u16 width;
+ u16 height;
+
+ struct t_tile tiles[T_MAP_MAX_W * T_MAP_MAX_H];
+};
+
+#endif
void *p = NULL;
lrts_assert(a);
- lrts_assert(a.err == U_ERRNO_OK);
- lrts_assert(a.data);
+ lrts_assert(a->err == U_ERRNO_OK);
+ lrts_assert(a->data);
if (new_o_index >= a->o_max) {
u_log(U_LOG_ERR, "Unable to allocate %d objects from arena\n", n);
#define U_ASSERT_H__
-#ifdef DEBUG
+#ifdef LRTS_DEBUG
#include <assert.h>
struct u_fp u_fp_div(struct u_fp a, struct u_fp b);
struct u_fp u_fp_mod(struct u_fp a, struct u_fp b);
+/* Clamps an integer value between min and max */
+#define U_CLAMP(v, min, max) if (v < min) { v = min; } if (v > max) { v = max; }
+
#endif