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" #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) { int32_t assets_setup(void) {
for (uint32_t i=0; i<ASSETS_COUNT; i++) { for (uint32_t i=0; i<ASSETS_COUNT; i++) {
asset *b = &assets[i]; asset *b = &assets[i];
@ -27,21 +32,48 @@ int32_t assets_setup(void) {
b->tex = texgen_build_sprite(b->id); b->tex = texgen_build_sprite(b->id);
}break; }break;
case AKIND_ANIM: {
b->tex = texgen_build_anim(b->id, 0);
}break;
case AKIND_SOUND: { case AKIND_SOUND: {
// TODO(zaklaus): soundgen // TODO(zaklaus): soundgen
}break; }break;
default: { default: break;
// TODO(zaklaus): assert
}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; return 0;
} }
void assets_destroy(void) { void assets_destroy(void) {
for (uint32_t i=0; i<ASSETS_COUNT; i++) { for (uint32_t i=0; i<ASSETS_COUNT; i++) {
switch (assets[i].kind) { switch (assets[i].kind) {
case AKIND_ANIM:
case AKIND_TEXTURE: { case AKIND_TEXTURE: {
UnloadTexture(assets[i].tex); UnloadTexture(assets[i].tex);
}break; }break;
@ -50,11 +82,8 @@ void assets_destroy(void) {
// TODO(zaklaus): soundgen // TODO(zaklaus): soundgen
}break; }break;
default: { default: break;
// TODO(zaklaus): assert
}break;
} }
} }
} }

View File

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

View File

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

View File

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

View File

@ -1,69 +1,70 @@
version(1); version(1);
project_name = "eco2d"; project_name = "eco2d";
patterns = patterns =
{ {
"*.c", "*.c",
"*.cpp", "*.cpp",
"*.jai", "*.jai",
"*.odin", "*.odin",
"*.zig", "*.zig",
"*.h", "*.h",
"*.inc", "*.inc",
"*.bat", "*.bat",
"*.sh", "*.sh",
"*.4coder", "*.4coder",
"*.txt", "*.txt",
"*.cmake", "*.cmake",
}; "*.md",
};
blacklist_patterns =
{ blacklist_patterns =
".*", {
}; ".*",
};
load_paths =
{ load_paths =
{{ {
{ ".", .recursive = false, .relative = true }, {{
{ "code/game", .recursive = true, .relative = true }, { ".", .recursive = false, .relative = true },
{ "code/common", .recursive = true, .relative = true }, { "code/game", .recursive = true, .relative = true },
{ "code/modules", .recursive = true, .relative = true }, { "code/common", .recursive = true, .relative = true },
{ "code/vendors", .recursive = true, .relative = true }, { "code/modules", .recursive = true, .relative = true },
{ "cmake", .recursive = true, .relative = true }, { "code/vendors", .recursive = true, .relative = true },
{ "build/_deps/raylib-src/src", .recursive = true, .relative = true } { "cmake", .recursive = true, .relative = true },
}, .os = "win"} { "build/_deps/raylib-src/src", .recursive = true, .relative = true }
}; }, .os = "win"}
};
command_list =
{ command_list =
{
{
.name = "build", {
.out = "*compilation*", .name = "build",
.footer_panel = true, .out = "*compilation*",
.save_dirty_files = true, .footer_panel = true,
.cursor_at_end = false, .save_dirty_files = true,
.cmd = .cursor_at_end = false,
{ .cmd =
{ "cmake --build build", .os = "win" }, {
}, { "cmake --build build", .os = "win" },
}, },
},
{
.name = "run", {
.out = "*console*", .name = "run",
.footer_panel = false, .out = "*console*",
.save_dirty_files = true, .footer_panel = false,
.cursor_at_end = true, .save_dirty_files = true,
.cmd = .cursor_at_end = true,
{ .cmd =
{ "run.bat", .os = "win" }, {
}, { "run.bat", .os = "win" },
}, },
},
};
};
fkey_command[1] = "build";
fkey_command[2] = "run"; fkey_command[1] = "build";
fkey_command[2] = "run";