From f5bed6ff6973a4b6ea7730c9b1600dc0ddfebdb8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 18 Jun 2024 17:00:41 +1000 Subject: [PATCH] Save 32kb from custom_models array by avoiding pointless padding --- src/Model.c | 60 ++++++++++++++++++++++++-------------------------- src/Model.h | 4 ++-- src/Protocol.c | 4 ++-- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/Model.c b/src/Model.c index e6bcf25ec..0e0d54ff5 100644 --- a/src/Model.c +++ b/src/Model.c @@ -581,13 +581,8 @@ static float EuclidianMod(float x, float y) { } static struct ModelVertex oldVertices[MODEL_BOX_VERTICES]; -static float CustomModel_GetAnimationValue( - struct CustomModelAnim* anim, - struct CustomModelPart* part, - struct CustomModel* cm, - struct Entity* e -) { - switch (anim->type) { +static float CustomModel_GetAnimValue(cc_uint8 type, struct CustomModelAnim* anim, struct Entity* e) { + switch (type) { case CustomModelAnimType_Head: return -e->Pitch * MATH_DEG2RAD; @@ -670,6 +665,7 @@ static void CustomModel_DrawPart( float rotX, rotY, rotZ; cc_bool head = false; cc_bool modifiedVertices = false; + cc_uint8 type, axis; float value = 0.0f; if (part->fullbright) { @@ -690,20 +686,22 @@ static void CustomModel_DrawPart( for (animIndex = 0; animIndex < MAX_CUSTOM_MODEL_ANIMS; animIndex++) { struct CustomModelAnim* anim = &part->anims[animIndex]; - if (anim->type == CustomModelAnimType_None) continue; + type = part->animType[animIndex]; + axis = part->animAxis[animIndex]; - value = CustomModel_GetAnimationValue(anim, part, cm, e); + if (type == CustomModelAnimType_None) continue; + value = CustomModel_GetAnimValue(type, anim, e); if ( !modifiedVertices && - (anim->type == CustomModelAnimType_SinTranslate || - anim->type == CustomModelAnimType_SinTranslateVelocity || - anim->type == CustomModelAnimType_SinSize || - anim->type == CustomModelAnimType_SinSizeVelocity || - anim->type == CustomModelAnimType_FlipTranslate || - anim->type == CustomModelAnimType_FlipTranslateVelocity || - anim->type == CustomModelAnimType_FlipSize || - anim->type == CustomModelAnimType_FlipSizeVelocity) + (type == CustomModelAnimType_SinTranslate || + type == CustomModelAnimType_SinTranslateVelocity || + type == CustomModelAnimType_SinSize || + type == CustomModelAnimType_SinSizeVelocity || + type == CustomModelAnimType_FlipTranslate || + type == CustomModelAnimType_FlipTranslateVelocity || + type == CustomModelAnimType_FlipSize || + type == CustomModelAnimType_FlipSizeVelocity) ) { modifiedVertices = true; Mem_Copy( @@ -714,14 +712,14 @@ static void CustomModel_DrawPart( } if ( - anim->type == CustomModelAnimType_SinTranslate || - anim->type == CustomModelAnimType_SinTranslateVelocity || - anim->type == CustomModelAnimType_FlipTranslate || - anim->type == CustomModelAnimType_FlipTranslateVelocity + type == CustomModelAnimType_SinTranslate || + type == CustomModelAnimType_SinTranslateVelocity || + type == CustomModelAnimType_FlipTranslate || + type == CustomModelAnimType_FlipTranslateVelocity ) { for (i = 0; i < MODEL_BOX_VERTICES; i++) { struct ModelVertex* vertex = &cm->model.vertices[part->modelPart.offset + i]; - switch (anim->axis) { + switch (axis) { case CustomModelAnimAxis_X: vertex->x += value; break; @@ -736,14 +734,14 @@ static void CustomModel_DrawPart( } } } else if ( - anim->type == CustomModelAnimType_SinSize || - anim->type == CustomModelAnimType_SinSizeVelocity || - anim->type == CustomModelAnimType_FlipSize || - anim->type == CustomModelAnimType_FlipSizeVelocity + type == CustomModelAnimType_SinSize || + type == CustomModelAnimType_SinSizeVelocity || + type == CustomModelAnimType_FlipSize || + type == CustomModelAnimType_FlipSizeVelocity ) { for (i = 0; i < MODEL_BOX_VERTICES; i++) { struct ModelVertex* vertex = &cm->model.vertices[part->modelPart.offset + i]; - switch (anim->axis) { + switch (axis) { case CustomModelAnimAxis_X: vertex->x = Math_Lerp(part->modelPart.rotX, vertex->x, value); break; @@ -758,11 +756,11 @@ static void CustomModel_DrawPart( } } } else { - if (anim->type == CustomModelAnimType_Head) { + if (type == CustomModelAnimType_Head) { head = true; } - switch (anim->axis) { + switch (axis) { case CustomModelAnimAxis_X: rotX += value; break; @@ -2317,8 +2315,8 @@ static void RecalcProperties(struct Entity* e) { } static void DrawBlockTransform(struct Entity* e, float dispX, float dispY, float dispZ, float scale) { - static Vec3 pos; - static struct Matrix m, temp; + struct Matrix m, temp; + Vec3 pos; pos = e->Position; pos.y += e->Anim.BobbingModel; diff --git a/src/Model.h b/src/Model.h index 2992270fa..343c92288 100644 --- a/src/Model.h +++ b/src/Model.h @@ -252,8 +252,6 @@ enum CustomModelAnimAxis { }; struct CustomModelAnim { - cc_uint8 type; - cc_uint8 axis; float a, b, c, d; }; @@ -269,6 +267,8 @@ struct CustomModelPart { struct ModelPart modelPart; Vec3 rotation; /* rotation angles */ struct CustomModelAnim anims[MAX_CUSTOM_MODEL_ANIMS]; + cc_uint8 animType[MAX_CUSTOM_MODEL_ANIMS]; + cc_uint8 animAxis[MAX_CUSTOM_MODEL_ANIMS]; cc_bool fullbright; cc_bool firstPersonArm; }; diff --git a/src/Protocol.c b/src/Protocol.c index 31324f58b..63c08be85 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -1707,8 +1707,8 @@ static void CPE_DefineModelPart(cc_uint8* data) { for (i = 0; i < MAX_CUSTOM_MODEL_ANIMS; i++) { cc_uint8 tmp = *data++; - part->anims[i].type = tmp & 0x3F; - part->anims[i].axis = tmp >> 6; + part->animType[i] = tmp & 0x3F; + part->animAxis[i] = tmp >> 6; part->anims[i].a = GetFloat(data); data += 4;