From 0c099af4e8190f2b37bf7d630d4b2e6358991758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sat, 15 Oct 2022 13:48:05 +0200 Subject: [PATCH] texgen overrides --- code/foundation/CMakeLists.txt | 2 + code/foundation/src/gen/texgen.h | 4 ++ code/foundation/src/gen/texgen_fallback.c | 52 +++++++++++++++++++++++ code/games/sandbox/src/texgen.c | 39 +---------------- 4 files changed, 60 insertions(+), 37 deletions(-) create mode 100644 code/foundation/src/gen/texgen_fallback.c diff --git a/code/foundation/CMakeLists.txt b/code/foundation/CMakeLists.txt index fda4b84..e475bc6 100644 --- a/code/foundation/CMakeLists.txt +++ b/code/foundation/CMakeLists.txt @@ -22,6 +22,8 @@ add_library(eco2d-foundation STATIC src/pkt/packet.c + src/gen/texgen_fallback.c + src/debug/debug_ui.c src/debug/debug_draw.c diff --git a/code/foundation/src/gen/texgen.h b/code/foundation/src/gen/texgen.h index 0a7fb5f..7f42be1 100644 --- a/code/foundation/src/gen/texgen.h +++ b/code/foundation/src/gen/texgen.h @@ -6,3 +6,7 @@ Texture2D texgen_build_anim(asset_id id, int64_t counter); Texture2D texgen_build_sprite(asset_id id); + +// NOTE(zak): this is a fallback for when the asset is not defined by the game +Texture2D texgen_build_anim_fallback(asset_id id, int64_t counter); +Texture2D texgen_build_sprite_fallback(asset_id id); diff --git a/code/foundation/src/gen/texgen_fallback.c b/code/foundation/src/gen/texgen_fallback.c new file mode 100644 index 0000000..5615ea7 --- /dev/null +++ b/code/foundation/src/gen/texgen_fallback.c @@ -0,0 +1,52 @@ +#include "gen/texgen.h" +#include "world/world.h" +#include "zpl.h" +#include "utils/raylib_helpers.h" + +Texture2D texgen_build_anim_fallback(asset_id id, int64_t counter) { + (void)counter; + switch (id) { + case ASSET_WATER: { + Image img = LoadImageEco("water"); + ImageColorBrightness(&img, zpl_abs((counter % 64 - 32)*2)); + return Image2TexEco(img); + }break; + + default: return GenColorEco(PINK); break; + } +} + +Texture2D texgen_build_sprite_fallback(asset_id id) { + switch (id) { + case ASSET_BLANK: return GenColorEco(WHITE); break; + case ASSET_BUILDMODE_HIGHLIGHT: return GenColorEco(WHITE); break; + case ASSET_BLOCK_FRAME: return GenFrameRect(); break; + + // NOTE(zaklaus): items + case ASSET_COAL: return LoadTexEco("coal"); + case ASSET_BLUEPRINT: return LoadTexEco("blueprint"); + + // 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_WATER: return LoadTexEco("water"); + + 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"); + + // NOTE(zaklaus): devices + case ASSET_CHEST: return LoadTexEco("chest"); + + default: return GenColorEco(PINK); break; + } +} diff --git a/code/games/sandbox/src/texgen.c b/code/games/sandbox/src/texgen.c index 7172ca3..d3483b8 100644 --- a/code/games/sandbox/src/texgen.c +++ b/code/games/sandbox/src/texgen.c @@ -6,47 +6,12 @@ Texture2D texgen_build_anim(asset_id id, int64_t counter) { (void)counter; switch (id) { - case ASSET_WATER: { - Image img = LoadImageEco("water"); - ImageColorBrightness(&img, zpl_abs((counter % 64 - 32)*2)); - return Image2TexEco(img); - }break; - - default: return GenColorEco(PINK); break; + default: return texgen_build_anim_fallback(id, counter); break; } } Texture2D texgen_build_sprite(asset_id id) { switch (id) { - case ASSET_BLANK: return GenColorEco(WHITE); break; - case ASSET_BUILDMODE_HIGHLIGHT: return GenColorEco(WHITE); break; - case ASSET_BLOCK_FRAME: return GenFrameRect(); break; - - // NOTE(zaklaus): items - case ASSET_COAL: return LoadTexEco("coal"); - case ASSET_BLUEPRINT: return LoadTexEco("blueprint"); - - // 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_WATER: return LoadTexEco("water"); - - 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"); - - // NOTE(zaklaus): devices - case ASSET_CHEST: return LoadTexEco("chest"); - - default: return GenColorEco(PINK); break; + default: return texgen_build_sprite_fallback(id); break; } }