mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Refactor texture pack entry extraction to be more uniform
This commit is contained in:
parent
1bec4922f9
commit
2532940c49
@ -351,6 +351,30 @@ static void Animations_Tick(struct ScheduledTask* task) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*--------------------------------------------------Animations component---------------------------------------------------*
|
*--------------------------------------------------Animations component---------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
static void AnimationsPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
cc_result res = Png_Decode(&anims_bmp, stream);
|
||||||
|
if (!res) return;
|
||||||
|
|
||||||
|
Logger_SysWarn2(res, "decoding", name);
|
||||||
|
Mem_Free(anims_bmp.scan0);
|
||||||
|
anims_bmp.scan0 = NULL;
|
||||||
|
}
|
||||||
|
static struct TextureEntry animations_entry = { "animations.png", AnimationsPngProcess };
|
||||||
|
static struct TextureEntry animations_txt = { "animations.txt", Animations_ReadDescription };
|
||||||
|
|
||||||
|
static void UseWaterProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
useWaterAnim = true;
|
||||||
|
alwaysWaterAnim = true;
|
||||||
|
}
|
||||||
|
static struct TextureEntry water_entry = { "usewateranim", UseWaterProcess };
|
||||||
|
|
||||||
|
static void UseLavaProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
useLavaAnim = true;
|
||||||
|
alwaysLavaAnim = true;
|
||||||
|
}
|
||||||
|
static struct TextureEntry lava_entry = { "uselavaanim", UseLavaProcess };
|
||||||
|
|
||||||
|
|
||||||
static void OnPackChanged(void* obj) {
|
static void OnPackChanged(void* obj) {
|
||||||
Animations_Clear();
|
Animations_Clear();
|
||||||
useLavaAnim = Animations_IsDefaultZip();
|
useLavaAnim = Animations_IsDefaultZip();
|
||||||
@ -358,31 +382,14 @@ static void OnPackChanged(void* obj) {
|
|||||||
alwaysLavaAnim = false;
|
alwaysLavaAnim = false;
|
||||||
alwaysWaterAnim = false;
|
alwaysWaterAnim = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFileChanged(void* obj, struct Stream* stream, const cc_string* name) {
|
|
||||||
cc_result res;
|
|
||||||
if (String_CaselessEqualsConst(name, "animations.png")) {
|
|
||||||
res = Png_Decode(&anims_bmp, stream);
|
|
||||||
if (!res) return;
|
|
||||||
|
|
||||||
Logger_SysWarn2(res, "decoding", name);
|
|
||||||
Mem_Free(anims_bmp.scan0);
|
|
||||||
anims_bmp.scan0 = NULL;
|
|
||||||
} else if (String_CaselessEqualsConst(name, "animations.txt")) {
|
|
||||||
Animations_ReadDescription(stream, name);
|
|
||||||
} else if (String_CaselessEqualsConst(name, "uselavaanim")) {
|
|
||||||
useLavaAnim = true;
|
|
||||||
alwaysLavaAnim = true;
|
|
||||||
} else if (String_CaselessEqualsConst(name, "usewateranim")) {
|
|
||||||
useWaterAnim = true;
|
|
||||||
alwaysWaterAnim = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnInit(void) {
|
static void OnInit(void) {
|
||||||
|
TextureEntry_Register(&animations_entry);
|
||||||
|
TextureEntry_Register(&animations_txt);
|
||||||
|
TextureEntry_Register(&water_entry);
|
||||||
|
TextureEntry_Register(&lava_entry);
|
||||||
|
|
||||||
ScheduledTask_Add(GAME_DEF_TICKS, Animations_Tick);
|
ScheduledTask_Add(GAME_DEF_TICKS, Animations_Tick);
|
||||||
Event_Register_(&TextureEvents.PackChanged, NULL, OnPackChanged);
|
Event_Register_(&TextureEvents.PackChanged, NULL, OnPackChanged);
|
||||||
Event_Register_(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IGameComponent Animations_Component = {
|
struct IGameComponent Animations_Component = {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
#include "TexturePack.h"
|
||||||
|
|
||||||
struct _Drawer2DData Drawer2D;
|
struct _Drawer2DData Drawer2D;
|
||||||
#define Font_IsBitmap(font) (!(font)->handle)
|
#define Font_IsBitmap(font) (!(font)->handle)
|
||||||
@ -633,6 +634,22 @@ void Drawer2D_DrawClippedText(struct Context2D* ctx, struct DrawTextArgs* args,
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------Drawer2D component----------------------------------------------------*
|
*---------------------------------------------------Drawer2D component----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
static void DefaultPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
struct Bitmap bmp;
|
||||||
|
cc_result res;
|
||||||
|
|
||||||
|
if ((res = Png_Decode(&bmp, stream))) {
|
||||||
|
Logger_SysWarn2(res, "decoding", name);
|
||||||
|
Mem_Free(bmp.scan0);
|
||||||
|
} else if (Font_SetBitmapAtlas(&bmp)) {
|
||||||
|
Event_RaiseVoid(&ChatEvents.FontChanged);
|
||||||
|
} else {
|
||||||
|
Mem_Free(bmp.scan0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static struct TextureEntry default_entry = { "default.png", DefaultPngProcess };
|
||||||
|
|
||||||
|
|
||||||
static void InitHexEncodedColor(int i, int hex, cc_uint8 lo, cc_uint8 hi) {
|
static void InitHexEncodedColor(int i, int hex, cc_uint8 lo, cc_uint8 hi) {
|
||||||
Drawer2D.Colors[i] = BitmapColor_RGB(
|
Drawer2D.Colors[i] = BitmapColor_RGB(
|
||||||
lo * ((hex >> 2) & 1) + hi * (hex >> 3),
|
lo * ((hex >> 2) & 1) + hi * (hex >> 3),
|
||||||
@ -655,21 +672,6 @@ static void OnReset(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFileChanged(void* obj, struct Stream* src, const cc_string* name) {
|
|
||||||
struct Bitmap bmp;
|
|
||||||
cc_result res;
|
|
||||||
if (!String_CaselessEqualsConst(name, "default.png")) return;
|
|
||||||
|
|
||||||
if ((res = Png_Decode(&bmp, src))) {
|
|
||||||
Logger_SysWarn2(res, "decoding", name);
|
|
||||||
Mem_Free(bmp.scan0);
|
|
||||||
} else if (Font_SetBitmapAtlas(&bmp)) {
|
|
||||||
Event_RaiseVoid(&ChatEvents.FontChanged);
|
|
||||||
} else {
|
|
||||||
Mem_Free(bmp.scan0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnInit(void) {
|
static void OnInit(void) {
|
||||||
OnReset();
|
OnReset();
|
||||||
Drawer2D.BitmappedText = Game_ClassicMode || !Options_GetBool(OPT_USE_CHAT_FONT, false);
|
Drawer2D.BitmappedText = Game_ClassicMode || !Options_GetBool(OPT_USE_CHAT_FONT, false);
|
||||||
@ -677,7 +679,7 @@ static void OnInit(void) {
|
|||||||
|
|
||||||
Options_Get(OPT_FONT_NAME, &font_default, "");
|
Options_Get(OPT_FONT_NAME, &font_default, "");
|
||||||
if (Game_ClassicMode) font_default.length = 0;
|
if (Game_ClassicMode) font_default.length = 0;
|
||||||
Event_Register_(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
TextureEntry_Register(&default_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
static void OnFree(void) {
|
||||||
|
@ -745,6 +745,27 @@ static void UpdateMapEdges(void) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------General---------------------------------------------------------*
|
*---------------------------------------------------------General---------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
static void CloudsPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
Game_UpdateTexture(&clouds_tex, stream, name, NULL);
|
||||||
|
}
|
||||||
|
static struct TextureEntry clouds_entry = { "clouds.png", CloudsPngProcess };
|
||||||
|
|
||||||
|
static void SkyboxPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
Game_UpdateTexture(&skybox_tex, stream, name, NULL);
|
||||||
|
}
|
||||||
|
static struct TextureEntry skybox_entry = { "skybox.png", SkyboxPngProcess };
|
||||||
|
|
||||||
|
static void SnowPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
Game_UpdateTexture(&snow_tex, stream, name, NULL);
|
||||||
|
}
|
||||||
|
static struct TextureEntry snow_entry = { "snow.png", SnowPngProcess };
|
||||||
|
|
||||||
|
static void RainPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
Game_UpdateTexture(&rain_tex, stream, name, NULL);
|
||||||
|
}
|
||||||
|
static struct TextureEntry rain_entry = { "rain.png", RainPngProcess };
|
||||||
|
|
||||||
|
|
||||||
static void DeleteVbs(void) {
|
static void DeleteVbs(void) {
|
||||||
Gfx_DeleteVb(&sky_vb);
|
Gfx_DeleteVb(&sky_vb);
|
||||||
Gfx_DeleteVb(&clouds_vb);
|
Gfx_DeleteVb(&clouds_vb);
|
||||||
@ -803,18 +824,6 @@ int EnvRenderer_CalcFlags(const cc_string* mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void OnFileChanged(void* obj, struct Stream* src, const cc_string* name) {
|
|
||||||
if (String_CaselessEqualsConst(name, "clouds.png")) {
|
|
||||||
Game_UpdateTexture(&clouds_tex, src, name, NULL);
|
|
||||||
} else if (String_CaselessEqualsConst(name, "skybox.png")) {
|
|
||||||
Game_UpdateTexture(&skybox_tex, src, name, NULL);
|
|
||||||
} else if (String_CaselessEqualsConst(name, "snow.png")) {
|
|
||||||
Game_UpdateTexture(&snow_tex, src, name, NULL);
|
|
||||||
} else if (String_CaselessEqualsConst(name, "rain.png")) {
|
|
||||||
Game_UpdateTexture(&rain_tex, src, name, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnTexturePackChanged(void* obj) {
|
static void OnTexturePackChanged(void* obj) {
|
||||||
/* TODO: Find better way, really should delete them all here */
|
/* TODO: Find better way, really should delete them all here */
|
||||||
Gfx_DeleteTexture(&skybox_tex);
|
Gfx_DeleteTexture(&skybox_tex);
|
||||||
@ -864,7 +873,11 @@ static void OnInit(void) {
|
|||||||
EnvRenderer_Legacy = flags & ENV_LEGACY;
|
EnvRenderer_Legacy = flags & ENV_LEGACY;
|
||||||
EnvRenderer_Minimal = flags & ENV_MINIMAL;
|
EnvRenderer_Minimal = flags & ENV_MINIMAL;
|
||||||
|
|
||||||
Event_Register_(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
TextureEntry_Register(&clouds_entry);
|
||||||
|
TextureEntry_Register(&skybox_entry);
|
||||||
|
TextureEntry_Register(&snow_entry);
|
||||||
|
TextureEntry_Register(&rain_entry);
|
||||||
|
|
||||||
Event_Register_(&TextureEvents.PackChanged, NULL, OnTexturePackChanged);
|
Event_Register_(&TextureEvents.PackChanged, NULL, OnTexturePackChanged);
|
||||||
Event_Register_(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged);
|
Event_Register_(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged);
|
||||||
|
|
||||||
|
38
src/Gui.c
38
src/Gui.c
@ -16,6 +16,7 @@
|
|||||||
#include "Menus.h"
|
#include "Menus.h"
|
||||||
#include "Funcs.h"
|
#include "Funcs.h"
|
||||||
#include "Server.h"
|
#include "Server.h"
|
||||||
|
#include "TexturePack.h"
|
||||||
|
|
||||||
struct _GuiData Gui;
|
struct _GuiData Gui;
|
||||||
struct Screen* Gui_Screens[GUI_MAX_SCREENS];
|
struct Screen* Gui_Screens[GUI_MAX_SCREENS];
|
||||||
@ -495,19 +496,28 @@ void Screen_PointerUp(void* s, int id, int x, int y) { }
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*------------------------------------------------------Gui component------------------------------------------------------*
|
*------------------------------------------------------Gui component------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void OnFontChanged(void* obj) { Gui_RefreshAll(); }
|
static void GuiPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
|
||||||
static void OnFileChanged(void* obj, struct Stream* stream, const cc_string* name) {
|
|
||||||
if (String_CaselessEqualsConst(name, "gui.png")) {
|
|
||||||
Game_UpdateTexture(&Gui.GuiTex, stream, name, NULL);
|
Game_UpdateTexture(&Gui.GuiTex, stream, name, NULL);
|
||||||
} else if (String_CaselessEqualsConst(name, "gui_classic.png")) {
|
|
||||||
Game_UpdateTexture(&Gui.GuiClassicTex, stream, name, NULL);
|
|
||||||
} else if (String_CaselessEqualsConst(name, "icons.png")) {
|
|
||||||
Game_UpdateTexture(&Gui.IconsTex, stream, name, NULL);
|
|
||||||
} else if (String_CaselessEqualsConst(name, "touch.png")) {
|
|
||||||
Game_UpdateTexture(&Gui.TouchTex, stream, name, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
static struct TextureEntry gui_entry = { "gui.png", GuiPngProcess };
|
||||||
|
|
||||||
|
static void GuiClassicPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
Game_UpdateTexture(&Gui.GuiClassicTex, stream, name, NULL);
|
||||||
|
}
|
||||||
|
static struct TextureEntry guiClassic_entry = { "gui_classic.png", GuiClassicPngProcess };
|
||||||
|
|
||||||
|
static void IconsPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
Game_UpdateTexture(&Gui.IconsTex, stream, name, NULL);
|
||||||
|
}
|
||||||
|
static struct TextureEntry icons_entry = { "icons.png", IconsPngProcess };
|
||||||
|
|
||||||
|
static void TouchPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
Game_UpdateTexture(&Gui.TouchTex, stream, name, NULL);
|
||||||
|
}
|
||||||
|
static struct TextureEntry touch_entry = { "touch.png", TouchPngProcess };
|
||||||
|
|
||||||
|
|
||||||
|
static void OnFontChanged(void* obj) { Gui_RefreshAll(); }
|
||||||
|
|
||||||
static void OnKeyPress(void* obj, int cp) {
|
static void OnKeyPress(void* obj, int cp) {
|
||||||
struct Screen* s;
|
struct Screen* s;
|
||||||
@ -545,8 +555,12 @@ static void OnContextLost(void* obj) {
|
|||||||
|
|
||||||
static void OnInit(void) {
|
static void OnInit(void) {
|
||||||
Gui.Screens = Gui_Screens; /* for plugins */
|
Gui.Screens = Gui_Screens; /* for plugins */
|
||||||
|
TextureEntry_Register(&gui_entry);
|
||||||
|
TextureEntry_Register(&guiClassic_entry);
|
||||||
|
TextureEntry_Register(&icons_entry);
|
||||||
|
TextureEntry_Register(&touch_entry);
|
||||||
|
|
||||||
Event_Register_(&ChatEvents.FontChanged, NULL, OnFontChanged);
|
Event_Register_(&ChatEvents.FontChanged, NULL, OnFontChanged);
|
||||||
Event_Register_(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
|
||||||
Event_Register_(&GfxEvents.ContextLost, NULL, OnContextLost);
|
Event_Register_(&GfxEvents.ContextLost, NULL, OnContextLost);
|
||||||
Event_Register_(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
Event_Register_(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
||||||
Event_Register_(&InputEvents.Press, NULL, OnKeyPress);
|
Event_Register_(&InputEvents.Press, NULL, OnKeyPress);
|
||||||
|
@ -570,6 +570,12 @@ void Particles_CustomEffect(int effectID, float x, float y, float z, float origi
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------Particles component---------------------------------------------------*
|
*---------------------------------------------------Particles component---------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
static void ParticlesPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
|
Game_UpdateTexture(&Particles_TexId, stream, name, NULL);
|
||||||
|
}
|
||||||
|
static struct TextureEntry particles_entry = { "particles.png", ParticlesPngProcess };
|
||||||
|
|
||||||
|
|
||||||
static void OnContextLost(void* obj) {
|
static void OnContextLost(void* obj) {
|
||||||
Gfx_DeleteDynamicVb(&Particles_VB);
|
Gfx_DeleteDynamicVb(&Particles_VB);
|
||||||
|
|
||||||
@ -583,19 +589,13 @@ static void OnBreakBlockEffect_Handler(void* obj, IVec3 coords, BlockID old, Blo
|
|||||||
Particles_BreakBlockEffect(coords, old, now);
|
Particles_BreakBlockEffect(coords, old, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFileChanged(void* obj, struct Stream* stream, const cc_string* name) {
|
|
||||||
if (String_CaselessEqualsConst(name, "particles.png")) {
|
|
||||||
Game_UpdateTexture(&Particles_TexId, stream, name, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnInit(void) {
|
static void OnInit(void) {
|
||||||
ScheduledTask_Add(GAME_DEF_TICKS, Particles_Tick);
|
ScheduledTask_Add(GAME_DEF_TICKS, Particles_Tick);
|
||||||
Random_SeedFromCurrentTime(&rnd);
|
Random_SeedFromCurrentTime(&rnd);
|
||||||
OnContextRecreated(NULL);
|
OnContextRecreated(NULL);
|
||||||
|
TextureEntry_Register(&particles_entry);
|
||||||
|
|
||||||
Event_Register_(&UserEvents.BlockChanged, NULL, OnBreakBlockEffect_Handler);
|
Event_Register_(&UserEvents.BlockChanged, NULL, OnBreakBlockEffect_Handler);
|
||||||
Event_Register_(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
|
||||||
Event_Register_(&GfxEvents.ContextLost, NULL, OnContextLost);
|
Event_Register_(&GfxEvents.ContextLost, NULL, OnContextLost);
|
||||||
Event_Register_(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
Event_Register_(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,6 @@
|
|||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
#define QUOTE(x) #x
|
|
||||||
#define STRINGIFY(val) QUOTE(val)
|
|
||||||
struct _ProtocolData Protocol;
|
struct _ProtocolData Protocol;
|
||||||
|
|
||||||
/* Classic state */
|
/* Classic state */
|
||||||
@ -1461,15 +1459,8 @@ static void CPE_DefineModel(cc_uint8* data) {
|
|||||||
numParts = data[114];
|
numParts = data[114];
|
||||||
|
|
||||||
if (numParts > MAX_CUSTOM_MODEL_PARTS) {
|
if (numParts > MAX_CUSTOM_MODEL_PARTS) {
|
||||||
cc_string msg; char msgBuffer[256];
|
int maxParts = MAX_CUSTOM_MODEL_PARTS;
|
||||||
String_InitArray(msg, msgBuffer);
|
Chat_Add2("&cCustom Model '%s' exceeds parts limit of %i", &name, &maxParts);
|
||||||
|
|
||||||
String_Format1(
|
|
||||||
&msg,
|
|
||||||
"&cCustom Model '%s' exceeds parts limit of " STRINGIFY(MAX_CUSTOM_MODEL_PARTS),
|
|
||||||
&name
|
|
||||||
);
|
|
||||||
Logger_WarnFunc(&msg);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,16 +440,20 @@ void TexturePack_Extract(const cc_string* url) {
|
|||||||
TexturePack_ExtractCurrent(false);
|
TexturePack_ExtractCurrent(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct TextureEntry* entries_head;
|
||||||
|
static struct TextureEntry* entries_tail;
|
||||||
|
|
||||||
|
void TextureEntry_Register(struct TextureEntry* entry) {
|
||||||
|
LinkedList_Append(entry, entries_head, entries_tail);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------Textures component----------------------------------------------------*
|
*---------------------------------------------------Textures component----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void OnFileChanged(void* obj, struct Stream* stream, const cc_string* name) {
|
static void TerrainPngProcess(struct Stream* stream, const cc_string* name) {
|
||||||
struct Bitmap bmp;
|
struct Bitmap bmp;
|
||||||
cc_result res;
|
cc_result res = Png_Decode(&bmp, stream);
|
||||||
|
|
||||||
if (!String_CaselessEqualsConst(name, "terrain.png")) return;
|
|
||||||
res = Png_Decode(&bmp, stream);
|
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
Logger_SysWarn2(res, "decoding", name);
|
Logger_SysWarn2(res, "decoding", name);
|
||||||
@ -458,6 +462,19 @@ static void OnFileChanged(void* obj, struct Stream* stream, const cc_string* nam
|
|||||||
Mem_Free(bmp.scan0);
|
Mem_Free(bmp.scan0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static struct TextureEntry terrain_entry = { "terrain.png", TerrainPngProcess };
|
||||||
|
|
||||||
|
|
||||||
|
static void OnFileChanged(void* obj, struct Stream* stream, const cc_string* name) {
|
||||||
|
struct TextureEntry* e;
|
||||||
|
|
||||||
|
for (e = entries_head; e; e = e->next) {
|
||||||
|
if (!String_CaselessEqualsConst(name, e->filename)) continue;
|
||||||
|
|
||||||
|
e->Callback(stream, name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void OnContextLost(void* obj) {
|
static void OnContextLost(void* obj) {
|
||||||
if (!Gfx.ManagedTextures) Atlas1D_Free();
|
if (!Gfx.ManagedTextures) Atlas1D_Free();
|
||||||
@ -482,6 +499,7 @@ static void OnInit(void) {
|
|||||||
String_AppendString(&TexturePack_Path, &defaultPath);
|
String_AppendString(&TexturePack_Path, &defaultPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextureEntry_Register(&terrain_entry);
|
||||||
Utils_EnsureDirectory("texpacks");
|
Utils_EnsureDirectory("texpacks");
|
||||||
Utils_EnsureDirectory("texturecache");
|
Utils_EnsureDirectory("texturecache");
|
||||||
TextureCache_Init();
|
TextureCache_Init();
|
||||||
@ -497,6 +515,7 @@ static void OnFree(void) {
|
|||||||
OnContextLost(NULL);
|
OnContextLost(NULL);
|
||||||
Atlas2D_Free();
|
Atlas2D_Free();
|
||||||
TexturePack_Url.length = 0;
|
TexturePack_Url.length = 0;
|
||||||
|
entries_head = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IGameComponent Textures_Component = {
|
struct IGameComponent Textures_Component = {
|
||||||
|
@ -99,4 +99,12 @@ void TexturePack_CheckPending(void);
|
|||||||
/* Else tries extracting cached texture pack for the given URL, */
|
/* Else tries extracting cached texture pack for the given URL, */
|
||||||
/* then asynchronously downloads the texture pack from the given URL. */
|
/* then asynchronously downloads the texture pack from the given URL. */
|
||||||
CC_API void TexturePack_Extract(const cc_string* url);
|
CC_API void TexturePack_Extract(const cc_string* url);
|
||||||
|
|
||||||
|
struct TextureEntry;
|
||||||
|
struct TextureEntry {
|
||||||
|
const char* filename;
|
||||||
|
void (*Callback)(struct Stream* stream, const cc_string* name);
|
||||||
|
struct TextureEntry* next;
|
||||||
|
};
|
||||||
|
void TextureEntry_Register(struct TextureEntry* entry);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user