UFO: Alien Invasion
Loading...
Searching...
No Matches
r_model.cpp File Reference

model loading and caching More...

#include "r_local.h"
Include dependency graph for r_model.cpp:

Go to the source code of this file.

Macros

#define MEM_TAG_STATIC_MODELS   1

Functions

void R_ModModellist_f (void)
 Prints all loaded models.
model_tR_AllocModelSlot (void)
static void R_LoadModelAsync (model_t *mod, byte *buf, int modfilelen)
static bool R_LoadModel (model_t *mod, const char *filename)
 Loads in a model for the given name.
bool R_ModelExists (const char *name)
model_tR_FindModel (const char *name)
 Tries to load a model.
model_tR_GetModel (const char *name)
 Get a model for the given name already loaded.
void R_SwitchModelMemPoolTag (void)
 After all static models are loaded, switch the pool tag for these models to not free them everytime R_ShutdownModels is called.
int R_ModAllocateActorSkin (const char *name)
 Register an actorskin name.
bool R_UseActorSkin (void)
static const char * R_GetActorSkin (int id)
void R_LoadActorSkinsFromModel (mAliasMesh_t *outMesh, image_t *defaultSkin)
 Load actor skins from a default skin to a a mesh.
void R_ShutdownModels (bool complete)
 Frees the model pool.
void R_ModelInit ()
void R_ModelShutdown ()

Variables

static model_t r_models [MAX_MOD_KNOWN]
static int r_numModels
static int r_numModelsStatic
model_tr_mapTiles [MAX_MAPTILES]
 The world model(s).
int r_numMapTiles
model_t r_modelsInline [MAX_MOD_KNOWN]
int r_numModelsInline
static char * r_actorSkinNames [MAX_ACTORSKINNAME]
static int r_numActorSkinName
static char const *const mod_extensions []
 all supported model formats

Detailed Description

model loading and caching

Definition in file r_model.cpp.

Macro Definition Documentation

◆ MEM_TAG_STATIC_MODELS

#define MEM_TAG_STATIC_MODELS   1

Definition at line 292 of file r_model.cpp.

Referenced by R_SwitchModelMemPoolTag().

Function Documentation

◆ R_AllocModelSlot()

model_t * R_AllocModelSlot ( void )

Definition at line 100 of file r_model.cpp.

References Com_Error(), ERR_DROP, MAX_MOD_KNOWN, r_models, and r_numModels.

Referenced by R_ModAddMapTile().

◆ R_FindModel()

model_t * R_FindModel ( const char * name)

Tries to load a model.

Parameters
[in]nameThe model path or name (with or without extension) - see notes this parameter is always relative to the game base dir - it can also be relative to the models/ dir in the game folder
Note
trying all supported model formats is only supported when you are using a name without extension and relative to models/ dir
if first char of name is a '*' - this is an inline model
if there is not extension in the given filename the function will try to load one of the supported model formats
Returns
nullptr if no model could be found with the given name, model_t otherwise
Todo
this case should be useless, do we ever use extension?

Definition at line 203 of file r_model.cpp.

References Com_Error(), Com_GetExtension(), Com_Printf(), Com_sprintf(), ERR_FATAL, i, MAX_MOD_KNOWN, MAX_QPATH, mod_extensions, model_t::name, name, Q_strncpyz(), R_GetModel(), R_LoadModel(), r_models, and r_numModels.

Referenced by CL_AddBrushModel(), CL_CameraAppear(), CL_ParseConfigString(), CL_ParticleLoadArt(), CL_PrecacheCharacterModels(), CL_ViewLoadMedia(), CL_ViewPrecacheModels(), LM_Register(), R_Draw2DMapMarkers(), R_Draw3DMapMarkers(), R_DrawModelDirect(), SEQ_ExecuteModel(), SEQ_ExecutePrecache(), UI_DrawModelNode(), and UI_DrawModelNodeWithUIModel().

◆ R_GetActorSkin()

const char * R_GetActorSkin ( int id)
static

Definition at line 347 of file r_model.cpp.

References id, r_actorSkinNames, and r_numActorSkinName.

Referenced by R_LoadActorSkinsFromModel().

◆ R_GetModel()

model_t * R_GetModel ( const char * name)

Get a model for the given name already loaded.

Returns
A model for the given name, else nullptr.
See also
R_FindModel
Parameters
[in]nameShort name of the model relative to base dir without (models/model)

Definition at line 269 of file r_model.cpp.

References Com_Error(), ERR_FATAL, i, model_t::name, name, Q_streq, r_models, r_modelsInline, r_numModels, and r_numModelsInline.

Referenced by R_FindModel().

◆ R_LoadActorSkinsFromModel()

void R_LoadActorSkinsFromModel ( mAliasMesh_t * outMesh,
image_t * defaultSkin )

Load actor skins from a default skin to a a mesh.

Parameters
outMeshMesh target of skins
defaultSkinDefault skin of the mesh
Todo
should we add warning here?

Definition at line 358 of file r_model.cpp.

References Com_Printf(), i, Mem_PoolAllocTypeN, image_t::name, mAliasMesh_t::name, mAliasSkin_t::name, mAliasMesh_t::num_skins, Q_strncpyz(), R_AliasModelGetSkin(), R_GetActorSkin(), r_noTexture, r_numActorSkinName, mAliasSkin_t::skin, mAliasMesh_t::skins, va(), and vid_modelPool.

Referenced by R_ModLoadAliasMD2MeshUnindexed().

◆ R_LoadModel()

bool R_LoadModel ( model_t * mod,
const char * filename )
static

Loads in a model for the given name.

Parameters
[in]filenameFilename relative to base dir and with extension (models/model.md2)
[in,out]modStructure to initialize
Returns
True if the loading was succeed. True or false structure mod was edited.

Definition at line 157 of file r_model.cpp.

References Com_Error(), ERR_FATAL, FS_LoadFile(), model_t::name, OBJZERO, Q_strncpyz(), and R_LoadModelAsync().

Referenced by R_FindModel().

◆ R_LoadModelAsync()

◆ R_ModAllocateActorSkin()

int R_ModAllocateActorSkin ( const char * name)

Register an actorskin name.

Returns
The id where the actorskin is registered

Definition at line 332 of file r_model.cpp.

References lengthof, Mem_StrDup, name, r_actorSkinNames, and r_numActorSkinName.

Referenced by CL_AllocateActorSkin().

◆ R_ModelExists()

bool R_ModelExists ( const char * name)

Definition at line 177 of file r_model.cpp.

References Com_GetExtension(), FS_CheckFile(), i, mod_extensions, and name.

Referenced by GAME_LoadCharacter().

◆ R_ModelInit()

void R_ModelInit ( )

Definition at line 436 of file r_model.cpp.

Referenced by R_Init().

◆ R_ModelShutdown()

void R_ModelShutdown ( )

Definition at line 440 of file r_model.cpp.

References R_ShutdownModels().

Referenced by R_Shutdown().

◆ R_ModModellist_f()

◆ R_ShutdownModels()

◆ R_SwitchModelMemPoolTag()

void R_SwitchModelMemPoolTag ( void )

After all static models are loaded, switch the pool tag for these models to not free them everytime R_ShutdownModels is called.

See also
CL_InitAfter
R_FreeWorldImages

Definition at line 299 of file r_model.cpp.

References model_t::alias, Com_Printf(), i, it_static, Mem_ChangeTag, MEM_TAG_STATIC_MODELS, mAliasModel_t::meshes, model_t::name, mAliasModel_t::num_meshes, mAliasMesh_t::num_skins, r_models, r_noTexture, r_numModels, r_numModelsStatic, mAliasSkin_t::skin, mAliasMesh_t::skins, image_t::type, and vid_modelPool.

Referenced by CL_ViewPrecacheModels().

◆ R_UseActorSkin()

bool R_UseActorSkin ( void )

Definition at line 342 of file r_model.cpp.

References r_numActorSkinName.

Referenced by R_ModLoadAliasMD2MeshUnindexed().

Variable Documentation

◆ mod_extensions

char const* const mod_extensions[]
static
Initial value:
= {
"md2", "md3", "obj", nullptr
}

all supported model formats

See also
modtype_t

Definition at line 46 of file r_model.cpp.

Referenced by R_FindModel(), R_ModelExists(), and SV_LoadModelAABB().

◆ r_actorSkinNames

char* r_actorSkinNames[MAX_ACTORSKINNAME]
static

Definition at line 39 of file r_model.cpp.

Referenced by R_GetActorSkin(), and R_ModAllocateActorSkin().

◆ r_mapTiles

◆ r_models

◆ r_modelsInline

◆ r_numActorSkinName

int r_numActorSkinName
static

◆ r_numMapTiles

◆ r_numModels

int r_numModels
static

◆ r_numModelsInline

◆ r_numModelsStatic

int r_numModelsStatic
static

Definition at line 30 of file r_model.cpp.

Referenced by R_ModModellist_f(), R_ShutdownModels(), and R_SwitchModelMemPoolTag().