mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -04:00
Only load top parts of gui.png and icons.png into GPU textures
This commit is contained in:
parent
cc35e79766
commit
eedea7446d
@ -783,22 +783,22 @@ static void UpdateMapEdges(void) {
|
||||
*---------------------------------------------------------General---------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void CloudsPngProcess(struct Stream* stream, const cc_string* name) {
|
||||
Game_UpdateTexture(&clouds_tex, stream, name, NULL);
|
||||
Game_UpdateTexture(&clouds_tex, stream, name, NULL, 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);
|
||||
Game_UpdateTexture(&skybox_tex, stream, name, NULL, 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);
|
||||
Game_UpdateTexture(&snow_tex, stream, name, NULL, 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);
|
||||
Game_UpdateTexture(&rain_tex, stream, name, NULL, NULL);
|
||||
}
|
||||
static struct TextureEntry rain_entry = { "rain.png", RainPngProcess };
|
||||
|
||||
|
@ -213,13 +213,18 @@ cc_bool Game_CanPick(BlockID block) {
|
||||
return Blocks.Collide[block] != COLLIDE_LIQUID || Game_BreakableLiquids;
|
||||
}
|
||||
|
||||
cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_string* file, cc_uint8* skinType) {
|
||||
cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_string* file,
|
||||
cc_uint8* skinType, int* heightDivisor) {
|
||||
struct Bitmap bmp;
|
||||
cc_bool success;
|
||||
cc_result res;
|
||||
|
||||
res = Png_Decode(&bmp, src);
|
||||
if (res) { Logger_SysWarn2(res, "decoding", file); }
|
||||
|
||||
/* E.g. gui.png, icons.png only need top half of the texture loaded */
|
||||
if (heightDivisor && bmp.height >= *heightDivisor)
|
||||
bmp.height /= *heightDivisor;
|
||||
|
||||
success = !res && Game_ValidateBitmap(file, &bmp);
|
||||
if (success) {
|
||||
|
14
src/Game.h
14
src/Game.h
@ -92,18 +92,20 @@ CC_API void Game_UpdateBlock(int x, int y, int z, BlockID block);
|
||||
CC_API void Game_ChangeBlock(int x, int y, int z, BlockID block);
|
||||
|
||||
cc_bool Game_CanPick(BlockID block);
|
||||
cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_string* file, cc_uint8* skinType);
|
||||
/* Updates Game_Width and Game_Height. */
|
||||
void Game_UpdateDimensions(void);
|
||||
/* Sets the strategy/method used to limit frames per second. */
|
||||
/* See FPS_LIMIT_ for valid strategies/methods */
|
||||
void Game_SetFpsLimit(int method);
|
||||
|
||||
cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_string* file,
|
||||
cc_uint8* skinType, int* heightDivisor);
|
||||
/* Checks that the given bitmap can be loaded into a native gfx texture. */
|
||||
/* (must be power of two size and be <= Gfx_MaxTexWidth/Gfx_MaxHeight) */
|
||||
cc_bool Game_ValidateBitmap(const cc_string* file, struct Bitmap* bmp);
|
||||
/* Checks that the given bitmap is a power of two size */
|
||||
/* NOTE: Game_ValidateBitmap should nearly always be used instead of this */
|
||||
cc_bool Game_ValidateBitmapPow2(const cc_string* file, struct Bitmap* bmp);
|
||||
/* Updates Game_Width and Game_Height. */
|
||||
void Game_UpdateDimensions(void);
|
||||
/* Sets the strategy/method used to limit frames per second. */
|
||||
/* See FPS_LIMIT_ for valid strategies/methods */
|
||||
void Game_SetFpsLimit(int method);
|
||||
|
||||
/* Runs the main game loop until the window is closed. */
|
||||
void Game_Run(int width, int height, const cc_string* title);
|
||||
|
11
src/Gui.c
11
src/Gui.c
@ -546,22 +546,25 @@ void Screen_PointerUp(void* s, int id, int x, int y) { }
|
||||
*------------------------------------------------------Gui component------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void GuiPngProcess(struct Stream* stream, const cc_string* name) {
|
||||
Game_UpdateTexture(&Gui.GuiTex, stream, name, NULL);
|
||||
int heightDivisor = 2; /* only top half of gui png is used */
|
||||
Game_UpdateTexture(&Gui.GuiTex, stream, name, NULL, &heightDivisor);
|
||||
}
|
||||
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);
|
||||
int heightDivisor = 2; /* only top half of gui png is used */
|
||||
Game_UpdateTexture(&Gui.GuiClassicTex, stream, name, NULL, &heightDivisor);
|
||||
}
|
||||
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);
|
||||
int heightDivisor = 4; /* only top quarter of icons png is used */
|
||||
Game_UpdateTexture(&Gui.IconsTex, stream, name, NULL, &heightDivisor);
|
||||
}
|
||||
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);
|
||||
Game_UpdateTexture(&Gui.TouchTex, stream, name, NULL, NULL);
|
||||
}
|
||||
static struct TextureEntry touch_entry = { "touch.png", TouchPngProcess };
|
||||
|
||||
|
@ -512,10 +512,11 @@ void Model_RegisterTexture(struct ModelTex* tex) {
|
||||
static void Models_TextureChanged(void* obj, struct Stream* stream, const cc_string* name) {
|
||||
struct ModelTex* tex;
|
||||
|
||||
for (tex = textures_head; tex; tex = tex->next) {
|
||||
for (tex = textures_head; tex; tex = tex->next)
|
||||
{
|
||||
if (!String_CaselessEqualsConst(name, tex->name)) continue;
|
||||
|
||||
Game_UpdateTexture(&tex->texID, stream, name, &tex->skinType);
|
||||
Game_UpdateTexture(&tex->texID, stream, name, &tex->skinType, NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ void Particles_CustomEffect(int effectID, float x, float y, float z, float origi
|
||||
*---------------------------------------------------Particles component---------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void ParticlesPngProcess(struct Stream* stream, const cc_string* name) {
|
||||
Game_UpdateTexture(&particles_TexId, stream, name, NULL);
|
||||
Game_UpdateTexture(&particles_TexId, stream, name, NULL, NULL);
|
||||
}
|
||||
static struct TextureEntry particles_entry = { "particles.png", ParticlesPngProcess };
|
||||
|
||||
|
@ -334,11 +334,11 @@ static void HUDScreen_Update(void* screen, double delta) {
|
||||
|
||||
#define CH_EXTENT 16
|
||||
static void HUDScreen_BuildCrosshairsMesh(struct VertexTextured** ptr) {
|
||||
static struct Texture tex = { 0, Tex_Rect(0,0,0,0), Tex_UV(0.0f,0.0f, 15/256.0f,15/256.0f) };
|
||||
/* Only top quarter of icons.png is used */
|
||||
static struct Texture tex = { 0, Tex_Rect(0,0,0,0), Tex_UV(0.0f,0.0f, 15/256.0f,15/64.0f) };
|
||||
int extent;
|
||||
|
||||
extent = (int)(CH_EXTENT * Gui_Scale(Window_Main.Height / 480.0f));
|
||||
tex.ID = Gui.IconsTex;
|
||||
tex.x = (Window_Main.Width / 2) - extent;
|
||||
tex.y = (Window_Main.Height / 2) - extent;
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "Block.h"
|
||||
#include "Input.h"
|
||||
|
||||
#define Widget_UV(u1,v1, u2,v2) Tex_UV(u1/256.0f,v1/256.0f, u2/256.0f,v2/256.0f)
|
||||
static void Widget_NullFunc(void* widget) { }
|
||||
static int Widget_Pointer(void* elem, int id, int x, int y) { return false; }
|
||||
static void Widget_InputUp(void* elem, int key) { }
|
||||
@ -98,10 +97,12 @@ void TextWidget_SetConst(struct TextWidget* w, const char* text, struct FontDesc
|
||||
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#define BUTTON_uWIDTH (200.0f / 256.0f)
|
||||
/* Only top half of gui.png is used */
|
||||
#define Button_UV(u1,v1, u2,v2) Tex_UV(u1/256.0f,v1/128.0f, u2/256.0f,v2/128.0f)
|
||||
|
||||
static struct Texture btnShadowTex = { 0, Tex_Rect(0,0, 0,0), Widget_UV(0,66, 200,86) };
|
||||
static struct Texture btnSelectedTex = { 0, Tex_Rect(0,0, 0,0), Widget_UV(0,86, 200,106) };
|
||||
static struct Texture btnDisabledTex = { 0, Tex_Rect(0,0, 0,0), Widget_UV(0,46, 200,66) };
|
||||
static struct Texture btnShadowTex = { 0, Tex_Rect(0,0, 0,0), Button_UV(0,66, 200,86) };
|
||||
static struct Texture btnSelectedTex = { 0, Tex_Rect(0,0, 0,0), Button_UV(0,86, 200,106) };
|
||||
static struct Texture btnDisabledTex = { 0, Tex_Rect(0,0, 0,0), Button_UV(0,46, 200,66) };
|
||||
|
||||
static void ButtonWidget_Free(void* widget) {
|
||||
struct ButtonWidget* w = (struct ButtonWidget*)widget;
|
||||
@ -507,11 +508,13 @@ static void HotbarWidget_Reposition(void* widget) {
|
||||
w->slotWidth = 20.0f * scaleX;
|
||||
|
||||
Tex_SetRect(w->backTex, w->x,w->y, w->width,w->height);
|
||||
Tex_SetUV(w->backTex, 0,0, 182/256.0f,22/256.0f);
|
||||
/* Only top half of gui png is used */
|
||||
Tex_SetUV(w->backTex, 0,0, 182/256.0f,22/128.0f);
|
||||
|
||||
y = w->y + (w->height - (int)(23.0f * scaleY));
|
||||
Tex_SetRect(w->selTex, 0,y, (int)w->selWidth,w->height);
|
||||
Tex_SetUV(w->selTex, 0,22/256.0f, 24/256.0f,44/256.0f);
|
||||
/* Only top half of gui png is used */
|
||||
Tex_SetUV(w->selTex, 0,22/128.0f, 24/256.0f,44/128.0f);
|
||||
}
|
||||
|
||||
static int HotbarWidget_MapKey(int key) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user