TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GameObjectModel.cpp File Reference
#include "VMapFactory.h"
#include "VMapManager2.h"
#include "VMapDefinitions.h"
#include "WorldModel.h"
#include "GameObjectModel.h"
#include "Log.h"
#include "Timer.h"
+ Include dependency graph for GameObjectModel.cpp:

Classes

struct  GameobjectModelData
 

Typedefs

typedef std::unordered_map
< uint32, GameobjectModelData
ModelList
 

Functions

void LoadGameObjectModelList (std::string const &dataPath)
 

Variables

ModelList model_list
 

Typedef Documentation

typedef std::unordered_map<uint32, GameobjectModelData> ModelList

Function Documentation

void LoadGameObjectModelList ( std::string const dataPath)
44 {
45 #ifndef NO_CORE_FUNCS
46  uint32 oldMSTime = getMSTime();
47 #endif
48 
49  FILE* model_list_file = fopen((dataPath + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb");
50  if (!model_list_file)
51  {
52  VMAP_ERROR_LOG("misc", "Unable to open '%s' file.", VMAP::GAMEOBJECT_MODELS);
53  return;
54  }
55 
56  uint32 name_length, displayId;
57  char buff[500];
58  while (true)
59  {
60  Vector3 v1, v2;
61  if (fread(&displayId, sizeof(uint32), 1, model_list_file) != 1)
62  if (feof(model_list_file)) // EOF flag is only set after failed reading attempt
63  break;
64 
65  if (fread(&name_length, sizeof(uint32), 1, model_list_file) != 1
66  || name_length >= sizeof(buff)
67  || fread(&buff, sizeof(char), name_length, model_list_file) != name_length
68  || fread(&v1, sizeof(Vector3), 1, model_list_file) != 1
69  || fread(&v2, sizeof(Vector3), 1, model_list_file) != 1)
70  {
71  VMAP_ERROR_LOG("misc", "File '%s' seems to be corrupted!", VMAP::GAMEOBJECT_MODELS);
72  break;
73  }
74 
75  if (v1.isNaN() || v2.isNaN())
76  {
77  VMAP_ERROR_LOG("misc", "File '%s' Model '%s' has invalid v1%s v2%s values!", VMAP::GAMEOBJECT_MODELS, std::string(buff, name_length).c_str(), v1.toString().c_str(), v2.toString().c_str());
78  continue;
79  }
80 
81  model_list.insert
82  (
83  ModelList::value_type(displayId, GameobjectModelData(std::string(buff, name_length), AABox(v1, v2)))
84  );
85  }
86 
87  fclose(model_list_file);
88  VMAP_INFO_LOG("server.loading", ">> Loaded %u GameObject models in %u ms", uint32(model_list.size()), GetMSTimeDiffToNow(oldMSTime));
89 }
uint32 getMSTime()
Definition: Timer.h:24
Definition: Vector3.h:58
ModelList model_list
Definition: GameObjectModel.cpp:41
uint32_t uint32
Definition: Define.h:150
Definition: AABox.h:32
Definition: GameObjectModel.cpp:31
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
#define VMAP_INFO_LOG(FILTER,...)
Definition: VMapDefinitions.h:40
const char GAMEOBJECT_MODELS[]
Definition: VMapDefinitions.h:30
#define VMAP_ERROR_LOG(FILTER,...)
Definition: VMapDefinitions.h:38
uint32_t uint32
Definition: g3dmath.h:168
bool isNaN() const
Definition: Vector3.cpp:83
std::string toString() const
Definition: Vector3.cpp:386

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

ModelList model_list