Make models/textures list a linked list, instead of hardcoding fixed maximum number.

This commit is contained in:
UnknownShadow200 2018-11-23 13:59:11 +11:00
parent 9bbcdb2e68
commit c5e5cb3b2b
8 changed files with 353 additions and 372 deletions

View File

@ -413,7 +413,7 @@ static struct ChatCommand ModelCommand_Instance = {
{
"&a/client model [name]",
"&bnames: &echibi, chicken, creeper, human, pig, sheep",
"&e skeleton, spider, zombie, sitting, <numerical block id>",
"&e skeleton, spider, zombie, sit, <numerical block id>",
}
};

View File

@ -79,7 +79,7 @@ void Drawer2D_SetFontBitmap(Bitmap* bmp) {
}
void Drawer2D_HexEncodedCol(int i, int hex, uint8_t lo, uint8_t hi) {
static void Drawer2D_HexEncodedCol(int i, int hex, uint8_t lo, uint8_t hi) {
Drawer2D_Cols[i].R = (uint8_t)(lo * ((hex >> 2) & 1) + hi * (hex >> 3));
Drawer2D_Cols[i].G = (uint8_t)(lo * ((hex >> 1) & 1) + hi * (hex >> 3));
Drawer2D_Cols[i].B = (uint8_t)(lo * ((hex >> 0) & 1) + hi * (hex >> 3));

View File

@ -122,7 +122,7 @@ static void Entity_SetBlockModel(struct Entity* e, const String* model) {
if (raw == -1) {
/* use default humanoid model */
e->Model = ModelCache_Models[0].Instance;
e->Model = Human_ModelPtr;
} else {
e->ModelBlock = (BlockID)raw;
e->Model = ModelCache_Get(&block);
@ -139,7 +139,6 @@ void Entity_SetModel(struct Entity* e, const String* model) {
name = String_FromReadonly("humanoid");
e->ModelScale = Vector3_Create1(2.0f);
}
e->_ModelIsSheepNoFur = String_CaselessEqualsConst(&name, "sheep_nofur");
e->ModelBlock = BLOCK_AIR;
e->Model = ModelCache_Get(&name);
@ -841,7 +840,7 @@ static void LocalPlayer_SetLocation(struct Entity* e, struct LocationUpdate* upd
LocalInterpComp_SetLocation(&p->Interp, update, interpolate);
}
void LocalPlayer_Tick(struct Entity* e, double delta) {
static void LocalPlayer_Tick(struct Entity* e, double delta) {
struct LocalPlayer* p = (struct LocalPlayer*)e;
struct HacksComp* hacks = &p->Hacks;
float xMoving = 0, zMoving = 0;

View File

@ -75,7 +75,6 @@ struct Entity {
struct Model* Model;
BlockID ModelBlock; /* BlockID, if model name was originally a vaid block id. */
bool _ModelIsSheepNoFur; /* Hacky, but only sheep model relies on model name. So use just 1 byte. */
struct AABB ModelAABB;
Vector3 ModelScale, Size;
float StepSize;

View File

@ -152,7 +152,7 @@ void Model_UpdateVB(void) {
void Model_ApplyTexture(struct Entity* entity) {
struct Model* model = Model_ActiveModel;
struct CachedTexture* data;
struct ModelTex* data;
GfxResourceID tex;
bool _64x64;
@ -160,7 +160,7 @@ void Model_ApplyTexture(struct Entity* entity) {
if (tex) {
Model_skinType = entity->SkinType;
} else {
data = &ModelCache_Textures[model->defaultTexIndex];
data = model->defaultTex;
tex = data->TexID;
Model_skinType = data->SkinType;
}

View File

@ -8,6 +8,8 @@
*/
struct Entity;
struct AABB;
struct Model;
struct ModelTex;
#define MODEL_QUAD_VERTICES 4
#define MODEL_BOX_VERTICES (FACE_COUNT * MODEL_QUAD_VERTICES)
@ -25,12 +27,14 @@ void ModelPart_Init(struct ModelPart* part, int offset, int count, float rotX, f
/* Contains a set of quads and/or boxes that describe a 3D object as well as
the bounding boxes that contain the entire set of quads and/or boxes. */
struct Model {
/* Name of this model */
const char* Name;
/* Pointer to the raw vertices of the model */
struct ModelVertex* vertices;
struct ModelVertex* vertices;
/* Pointer to default texture for this model */
struct ModelTex* defaultTex;
/* Count of assigned vertices within the raw vertices array */
int index;
/* Index within ModelCache's textures of the default texture for this model */
int8_t defaultTexIndex;
uint8_t armX, armY; /* these translate arm model part back to (0, 0) */
bool initalised;
@ -55,6 +59,7 @@ struct Model {
void (*DrawArm)(struct Entity* entity);
float NameYOffset, MaxScale, ShadowScale, NameScale;
struct Model* Next;
};
PackedCol Model_Cols[FACE_COUNT];
@ -67,12 +72,12 @@ uint8_t Model_Rotation, Model_skinType;
struct Model* Model_ActiveModel;
void Model_Init(struct Model* model);
#define Model_SetPointers(typeName)\
typeName.GetEyeY = typeName ## _GetEyeY;\
typeName.GetCollisionSize = typeName ## _GetCollisionSize; \
typeName.GetPickingBounds = typeName ## _GetPickingBounds;\
typeName.CreateParts = typeName ## _CreateParts;\
typeName.DrawModel = typeName ## _DrawModel;
#define Model_SetPointers(instance, typeName)\
instance.GetEyeY = typeName ## _GetEyeY;\
instance.GetCollisionSize = typeName ## _GetCollisionSize; \
instance.GetPickingBounds = typeName ## _GetPickingBounds;\
instance.CreateParts = typeName ## _CreateParts;\
instance.DrawModel = typeName ## _DrawModel;
bool Model_ShouldRender(struct Entity* entity);
float Model_RenderDistance(struct Entity* entity);

File diff suppressed because it is too large Load Diff

View File

@ -6,33 +6,28 @@
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
struct Model;
struct CachedModel { struct Model* Instance; String Name; };
struct CachedTexture { uint8_t SkinType; GfxResourceID TexID; String Name; };
struct ModelTex;
struct ModelTex { const char* Name; uint8_t SkinType; GfxResourceID TexID; struct ModelTex* Next; };
#if 0
public CustomModel[] CustomModels = new CustomModel[256];
#endif
#define MODELCACHE_MAX_MODELS 24
struct CachedModel ModelCache_Models[MODELCACHE_MAX_MODELS];
struct CachedTexture ModelCache_Textures[MODELCACHE_MAX_MODELS];
/* Maximum number of vertices a model can have */
#define MODELCACHE_MAX_VERTICES (24 * 12)
GfxResourceID ModelCache_Vb;
VertexP3fT2fC4b ModelCache_Vertices[MODELCACHE_MAX_VERTICES];
struct Model* Human_ModelPtr;
void ModelCache_Init(void);
void ModelCache_Free(void);
/* Returns pointer to model whose name caselessly matches given name. */
CC_EXPORT struct Model* ModelCache_Get(const String* name);
/* Returns index of cached texture whose name caselessly matches given name. */
CC_EXPORT int ModelCache_GetTextureIndex(const String* texName);
/* Adds a model to the list of cached models. (e.g. "skeleton") */
/* Cached models can be applied to entities to change their appearance. Use Entity_SetModel for that. */
/* NOTE: defaultTexName can be NULL, and is for some models. (such as the "block" model) */
CC_EXPORT void ModelCache_Register(STRING_REF const char* name, const char* defaultTexName, struct Model* instance);
/* Adds a texture to the list of cached textures. (e.g. "skeleton.png") */
/* Cached textures are automatically loaded from texture packs. Used as a 'default skin' for models. */
/* NOTE: Textures should be registered BEFORE models are registered. */
CC_EXPORT void ModelCache_RegisterTexture(STRING_REF const char* texName);
CC_EXPORT struct ModelTex* ModelCache_GetTexture(const String* name);
/* Adds a model to the list of models. (e.g. "skeleton") */
/* Models can be applied to entities to change their appearance. Use Entity_SetModel for that. */
CC_EXPORT void ModelCache_Register(struct Model* model);
/* Adds a texture to the list of model textures. (e.g. "skeleton.png") */
/* Model textures are automatically loaded from texture packs. Used as a 'default skin' for models. */
CC_EXPORT void ModelCache_RegisterTexture(struct ModelTex* tex);
#endif