CCOBJ=$(CC) -c -o $@ $< $(CFLAGS) $(LDFLAGS)
-all: bin test
+all: bin btest
release:
make DBGCFLAGS="" DBGLDFLAGS=""
bin: main.o $(OBJS)
$(CC) -o $(NAME) main.o $(OBJS) $(CFLAGS) $(LDFLAGS)
-test: test.o $(OBJS)
+btest: test.o $(OBJS)
$(CC) -o $(TEST_NAME) test.o $(OBJS) $(CFLAGS) $(LDFLAGS) -fsanitize=address
+
+.PHONY: test
+test: $(TEST_NAME)
+ ./$(TEST_NAME)
+
+.PHONY: run
+run: $(NAME)
+ ./$(NAME)
+
.PHONY: clean
clean:
rm -f ./*.o
/**
* The default render size
*/
-#define U_RENDER_W 640
-#define U_RENDER_H 640
+#define U_RENDER_W 896
+#define U_RENDER_H 504
struct u_vec2 lrts_get_render_res(void) {
struct lrts_config *cfg = lrts_cfg();
#include "t_camera.c"
#include "r_render.c"
#include "r_color.c"
+#include "r_assets.c"
#endif
--- /dev/null
+#include "r_assets.h"
+#include "r_render.h"
+
+#define R_SOLID_TILE_OUTLINE_COLOR 0xFF0000FF
+
+void r_draw_solid_isometric_tile(i32 x, i32 y, r_color color, r_color outline_color) {
+ u32 i = 0;
+ u32 j = 0;
+
+ LRTS_UNUSED(outline_color);
+ LRTS_UNUSED(x);
+ LRTS_UNUSED(y);
+
+ for (i = 0; i < R_TILE_W; i++) {
+ for (j = 1; j < R_TILE_H-1; j++) {
+ r_draw_pixel(&r_framebuffer, x+i, y+j, color);
+ }
+ }
+}
+
+void r_draw_tile(struct t_tile *t, i32 x, i32 y) {
+ switch (t->type) {
+ case T_TILE_TYPE_NONE:
+ break;
+ case T_TILE_TYPE_GRASS:
+ r_draw_solid_isometric_tile(x, y, 0x44FF00FF, R_SOLID_TILE_OUTLINE_COLOR);
+ break;
+ }
+}
+
--- /dev/null
+#ifndef R_ASSETS_H__
+#define R_ASSETS_H__
+
+#define R_TILE_W 32
+#define R_TILE_H 16
+
+/**
+ * This module contains asset descriptions
+ * for all in-game asset types
+ * It provides an interface to obtain e.g. tile gfx based on the tile type.
+ *
+ * Gfx assets:
+ * all gfx assets have a built-in representation that does not require loading any
+ * resources. They serve as a fallback in case an image cannot be loaded.
+ */
+
+#include "t_tile.h"
+#include "u_defs.h"
+
+/*
+ * Draws a tile to the frame buffer at x, y.
+ * Attempts to load the tile from the tile sheet
+ * if no tile sheet is availabel a fallback is drawn instead
+ */
+void r_draw_tile(struct t_tile *t, i32 x, i32 y);
+
+
+#endif
#include "r_render.h"
#include "r_color.h"
#include "p_draw.h"
-
+#include "t_tile.h"
+#include "r_assets.h"
struct r_framebuffer r_framebuffer;
}
void r_render_frame() {
- p_draw_begin();
+ struct t_tile t;
- r_draw_pixel(&r_framebuffer, 0, 0, 0xFF0000FF);
- r_draw_pixel(&r_framebuffer, 1, 1, 0xFF0000FF);
- r_draw_pixel(&r_framebuffer, 2, 2, 0xFF0000FF);
- r_draw_pixel(&r_framebuffer, r_framebuffer.width-1, r_framebuffer.height-1, 0xFF0000FF);
+ p_draw_begin();
+
+ /* draw test tile */
+ t.type = T_TILE_TYPE_GRASS;
+ r_draw_tile(&t, 128, 128);
p_draw_end();
p_draw_present();
#include "u_defs.h"
enum t_tile_types {
- T_TILE_TYPE_NONE = 0
+ T_TILE_TYPE_NONE = 0,
+ T_TILE_TYPE_GRASS
};
enum t_tile_flags {
lrts_todo("");
return c;
}
+
+struct u_vec2 u_vec2_mul(i32 n, struct u_vec2 v) {
+ struct u_vec2 r;
+
+ r.x = v.x * n;
+ r.y = v.y * n;
+
+ return r;
+}
* A simple 2d vector
*/
struct u_vec2 {
- u32 x;
- u32 y;
+ i32 x;
+ i32 y;
};
/*
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);
+/*
+ * Multiplies an integer with a vec2 reutnrs the resulting vector
+ */
+struct u_vec2 u_vec2_mul(i32 n, struct u_vec2 v);
+
/* Clamps an integer value between min and max */
#define U_CLAMP(v, min, max) if (v < min) { v = min; } if (v > max) { v = max; }