#include "u_defs.h"
#include "p_platform.h"
#include "r_render.h"
+#include "r_assets.h"
struct lrts_config lrts_global_cfg;
}
void lrts_init(void) {
+ /* init the fallback tile mask */
+ r_asset_init_fallback_tile();
}
int lrts_main(int argc, char **argv) {
int p_render_init_framebuffer(void) {
struct u_vec2 target_res = lrts_get_render_res();
- r_target = SDL_CreateSurface(target_res.x, target_res.y, SDL_PIXELFORMAT_RGBX8888);
+ r_target = SDL_CreateSurface(target_res.x, target_res.y, SDL_PIXELFORMAT_RGBA8888);
if (r_target == LRTS_NULL) {
u_log(U_LOG_ERR, "Failed to create surface: %s\n", SDL_GetError());
exit(-1);
#include "r_assets.h"
#include "r_render.h"
+#include "u_mem.h"
-#define R_SOLID_TILE_OUTLINE_COLOR 0xFF0000FF
+i32 r_asset_fallback_tile[R_TILE_W * R_TILE_H];
-void r_draw_solid_isometric_tile(i32 x, i32 y, r_color color, r_color outline_color) {
+void r_asset_init_fallback_tile(void) {
+ u_memset(r_asset_fallback_tile, 0, R_TILE_W * R_TILE_H);
+}
+
+void r_draw_solid_isometric_tile(i32 x, i32 y, r_color color) {
u32 i = 0;
u32 j = 0;
- i32 ox = 0;
- i32 oy = 0;
+ r_color final_color;
+ struct u_vec2 t = u_tile_to_screen(x, y);
/* converted origin point in isometric space */
- ox = (x * R_TILE_W / 2) + (y * R_TILE_W / 2);;
- oy = (y * R_TILE_H / 2) - (x * R_TILE_H / 2);
- LRTS_UNUSED(outline_color);
LRTS_UNUSED(x);
LRTS_UNUSED(y);
/* draw a tile texture from origin */
for (i = 0; i < R_TILE_W; i++) {
for (j = 1; j < R_TILE_H-1; j++) {
- r_draw_pixel(&r_framebuffer, ox, oy, color);
+ final_color = r_asset_fallback_tile[i + j * R_TILE_W] & color;
+ r_draw_pixel(&r_framebuffer, t.x + i, t.y + j, final_color);
}
}
}
case T_TILE_TYPE_NONE:
break;
case T_TILE_TYPE_GRASS:
- r_draw_solid_isometric_tile(x, y, 0x44FF00FF, R_SOLID_TILE_OUTLINE_COLOR);
+ r_draw_solid_isometric_tile(x, y, 0x44FF00FF);
break;
}
}
#include "u_defs.h"
/*
- * Draws a tile to the frame buffer at x, y.
+ * Draws a tile to the frame buffer at tile position 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);
+void r_asset_init_fallback_tile(void);
+
#endif
#include "u_math.h"
+#include "r_assets.h"
struct u_fp u_fp_add(struct u_fp a, struct u_fp b) {
struct u_fp c = U_FP(0, 0);
return r;
}
+
+struct u_vec2 u_tile_to_screen(i32 x, i32 y) {
+ struct u_vec2 r;
+
+ r.x = (x * R_TILE_W / 2) + (y * R_TILE_W / 2);;
+ r.y = (y * R_TILE_H / 2) - (x * R_TILE_H / 2);
+
+ return r;
+}
*/
struct u_vec2 u_vec2_mul(i32 n, struct u_vec2 v);
+/*
+ * converts a tile position to
+ * a screen position
+ */
+struct u_vec2 u_tile_to_screen(i32 x, i32 y);
+
/* Clamps an integer value between min and max */
#define U_CLAMP(v, min, max) if (v < min) { v = min; } if (v > max) { v = max; }