animated tiles support

isolation_bkp/dynres
Dominik Madarász 2021-11-04 13:34:15 +01:00
parent 4e9255528a
commit d85919855e
7 changed files with 169 additions and 112 deletions

View File

@ -18,6 +18,11 @@ typedef struct {
#include "assets_list.c"
#define ASSET_FRAME_RENDER_MS (1.0/10.0)
#define ASSET_FRAME_SKIP 2
static int64_t assets_frame_counter = 1;
static double assets_frame_next_draw = 0.0;
int32_t assets_setup(void) {
for (uint32_t i=0; i<ASSETS_COUNT; i++) {
asset *b = &assets[i];
@ -27,21 +32,48 @@ int32_t assets_setup(void) {
b->tex = texgen_build_sprite(b->id);
}break;
case AKIND_ANIM: {
b->tex = texgen_build_anim(b->id, 0);
}break;
case AKIND_SOUND: {
// TODO(zaklaus): soundgen
}break;
default: {
// TODO(zaklaus): assert
default: break;
}
}
assets_frame_next_draw = zpl_time_rel() + ASSET_FRAME_RENDER_MS;
return 0;
}
int32_t assets_frame(void) {
if (assets_frame_next_draw < zpl_time_rel()) {
for (uint32_t i=0; i<ASSETS_COUNT; i++) {
asset *b = &assets[i];
switch (b->kind) {
case AKIND_ANIM: {
UnloadTexture(b->tex);
b->tex = texgen_build_anim(b->id, assets_frame_counter);
}break;
default: break;
}
}
assets_frame_next_draw = zpl_time_rel() + ASSET_FRAME_RENDER_MS;
assets_frame_counter += ASSET_FRAME_SKIP;
}
return 0;
}
void assets_destroy(void) {
for (uint32_t i=0; i<ASSETS_COUNT; i++) {
switch (assets[i].kind) {
case AKIND_ANIM:
case AKIND_TEXTURE: {
UnloadTexture(assets[i].tex);
}break;
@ -50,11 +82,8 @@ void assets_destroy(void) {
// TODO(zaklaus): soundgen
}break;
default: {
// TODO(zaklaus): assert
}break;
default: break;
}
}
}

View File

@ -41,12 +41,14 @@ typedef enum {
typedef enum {
AKIND_TEXTURE,
AKIND_ANIM,
AKIND_SOUND,
FORCE_AKIND_UINT8 = UINT8_MAX
} asset_kind;
int32_t assets_setup(void);
int32_t assets_frame(void);
void assets_destroy(void);
uint16_t assets_find(asset_id id);

View File

@ -8,6 +8,7 @@
#define ASSET_SND(asset) ASSET_ENTRY(asset, AKIND_SOUND)
#define ASSET_TEX(asset) ASSET_ENTRY(asset, AKIND_TEXTURE)
#define ASSET_ANI(asset) ASSET_ENTRY(asset, AKIND_ANIM)
static asset assets[] = {
ASSET_TEX(ASSET_EMPTY),
@ -19,7 +20,7 @@ static asset assets[] = {
ASSET_TEX(ASSET_DEV),
ASSET_TEX(ASSET_GROUND),
ASSET_TEX(ASSET_DIRT),
ASSET_TEX(ASSET_WATER),
ASSET_ANI(ASSET_WATER),
ASSET_TEX(ASSET_LAVA),
ASSET_TEX(ASSET_WALL),
ASSET_TEX(ASSET_HILL),

View File

@ -1,51 +1,72 @@
#include "gen/texgen.h"
#include "world/world.h"
#include "texgen_data.c"
#define ZPL_NANO
#include "zpl.h"
static inline
Texture2D LoadImageEco(const char *name) {
Texture2D LoadTexEco(const char *name) {
static char filename[128];
zpl_snprintf(filename, 128, "art/gen/%s.png", name);
return LoadTexture(filename);
}
Texture2D texgen_build_sprite(asset_id id) {
static inline
Image LoadImageEco(const char *name) {
static char filename[128];
zpl_snprintf(filename, 128, "art/gen/%s.png", name);
return LoadImage(filename);
}
static inline
Texture2D Image2TexEco(Image image) {
Texture2D tex = LoadTextureFromImage(image);
UnloadImage(image);
return tex;
}
static inline
Texture2D GenColorEco(Color color) {
Image img = GenImageColor(1, 1, color);
return Image2TexEco(img);
}
Texture2D texgen_build_anim(asset_id id, int64_t counter) {
(void)counter;
switch (id) {
case ASSET_EMPTY: {
Image img = GenImageColor(1, 1, PINK);
Texture2D tex = LoadTextureFromImage(img);
UnloadImage(img);
return tex;
case ASSET_WATER: {
Image img = LoadImageEco("water");
ImageColorBrightness(&img, zpl_abs((counter % 64 - 32)*2));
return Image2TexEco(img);
}break;
case ASSET_DEMO_ICEMAKER: return LoadImageEco("demo_icemaker");
// NOTE(zaklaus): blocks
case ASSET_FENCE: return LoadImageEco("fence");
case ASSET_GROUND: return LoadImageEco("grass");
case ASSET_DIRT: return LoadImageEco("dirt");
case ASSET_WALL: return LoadImageEco("asphalt");
case ASSET_HILL_SNOW:
case ASSET_HILL: return LoadImageEco("rock");
case ASSET_WATER: return LoadImageEco("water");
case ASSET_LAVA: return LoadImageEco("lava");
case ASSET_WOOD: return LoadImageEco("wood");
case ASSET_TREE: return LoadImageEco("tree");
case ASSET_BELT:
case ASSET_BELT_RIGHT: return LoadImageEco("belt_right");
case ASSET_BELT_LEFT: return LoadImageEco("belt_left");
case ASSET_BELT_UP: return LoadImageEco("belt_up");
case ASSET_BELT_DOWN: return LoadImageEco("belt_down");
default: {
Image img = GenImageColor(1, 1, RAYWHITE);
Texture2D tex = LoadTextureFromImage(img);
UnloadImage(img);
return tex;
}break;
default: return GenColorEco(PINK); break;
}
}
Texture2D texgen_build_sprite(asset_id id) {
switch (id) {
case ASSET_BUILDMODE_HIGHLIGHT: return GenColorEco(WHITE); break;
// NOTE(zaklaus): items
case ASSET_DEMO_ICEMAKER: return LoadTexEco("demo_icemaker");
// NOTE(zaklaus): blocks
case ASSET_FENCE: return LoadTexEco("fence");
case ASSET_GROUND: return LoadTexEco("grass");
case ASSET_DIRT: return LoadTexEco("dirt");
case ASSET_WALL: return LoadTexEco("asphalt");
case ASSET_HILL_SNOW:
case ASSET_HILL: return LoadTexEco("rock");
case ASSET_LAVA: return LoadTexEco("lava");
case ASSET_WOOD: return LoadTexEco("wood");
case ASSET_TREE: return LoadTexEco("tree");
case ASSET_BELT:
case ASSET_BELT_RIGHT: return LoadTexEco("belt_right");
case ASSET_BELT_LEFT: return LoadTexEco("belt_left");
case ASSET_BELT_UP: return LoadTexEco("belt_up");
case ASSET_BELT_DOWN: return LoadTexEco("belt_down");
default: return GenColorEco(PINK); break;
}
}

View File

@ -4,4 +4,5 @@
#include "world/blocks.h"
#include "assets.h"
Texture2D texgen_build_anim(asset_id id, int64_t counter);
Texture2D texgen_build_sprite(asset_id id);

View File

@ -172,6 +172,8 @@ void platform_render() {
game_world_view_active_entity_map(do_entity_fadeinout);
}
assets_frame();
BeginDrawing();
{
profile (PROF_RENDER) {

View File

@ -16,6 +16,7 @@ patterns =
"*.4coder",
"*.txt",
"*.cmake",
"*.md",
};
blacklist_patterns =