Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
modelmanager.h
1 #pragma once
2 
3 #include "common/singleton.h"
4 
6 
7 #include <string>
8 #include <vector>
9 #include <map>
10 
11 namespace Gfx {
12 
13 class CEngine;
14 class CModelFile;
15 
35 class CModelManager : public CSingleton<CModelManager>
36 {
37 public:
38  CModelManager(CEngine* engine);
39  ~CModelManager();
40 
42  bool LoadModel(const std::string& fileName, bool mirrored);
43 
45  bool AddModelReference(const std::string& fileName, bool mirrored, int objRank);
46 
48  bool AddModelCopy(const std::string& fileName, bool mirrored, int objRank);
49 
51  bool IsModelLoaded(const std::string& fileName, bool mirrored);
52 
54  int GetModelBaseObjRank(const std::string& fileName, bool mirrored);
55 
57  void DeleteAllModelCopies();
58 
60  void UnloadModel(const std::string& fileName, bool mirrored);
62  void UnloadAllModels();
63 
64 protected:
66  float GetHeight(std::vector<ModelTriangle>& triangles, Math::Vector pos);
67 
69  void Mirror(std::vector<ModelTriangle>& triangles);
70 
71 private:
72  struct ModelInfo
73  {
74  std::vector<ModelTriangle> triangles;
75  int baseObjRank;
76  };
77  struct FileInfo
78  {
79  std::string fileName;
80  bool mirrored;
81 
82  inline FileInfo(const std::string& _fileName, bool _mirrored)
83  : fileName(_fileName)
84  , mirrored(_mirrored)
85  {}
86 
87  inline bool operator<(const FileInfo& other) const
88  {
89  int compare = fileName.compare(other.fileName);
90  if (compare < 0)
91  return true;
92  if (compare > 0)
93  return false;
94 
95  return !mirrored && mirrored != other.mirrored;
96  }
97  };
98  std::map<FileInfo, ModelInfo> m_models;
99  std::vector<int> m_copiesBaseRanks;
100  CEngine* m_engine;
101 };
102 
103 } // namespace Gfx
104 
CSingleton base class for singletons.
float GetHeight(std::vector< ModelTriangle > &triangles, Math::Vector pos)
Returns the height of model – closest point to X and Z coords of pos.
Definition: modelmanager.cpp:183
Definition: singleton.h:27
void DeleteAllModelCopies()
Deletes all copied objects.
Definition: modelmanager.cpp:136
bool LoadModel(const std::string &fileName, bool mirrored)
Loads a model from given file.
Definition: modelmanager.cpp:24
bool IsModelLoaded(const std::string &fileName, bool mirrored)
Returns true if given model is loaded.
Definition: modelmanager.cpp:122
Model loading - CModelFile class (aka modfile)
int GetModelBaseObjRank(const std::string &fileName, bool mirrored)
Returns the rank of base engine object of given loaded model.
Definition: modelmanager.cpp:127
bool AddModelCopy(const std::string &fileName, bool mirrored, int objRank)
Adds an instance of model to the given object rank as a copy (copied base object) ...
Definition: modelmanager.cpp:102
void UnloadAllModels()
Unloads all models.
Definition: modelmanager.cpp:157
Manager for static models.
Definition: modelmanager.h:35
The graphics engine.
Definition: engine.h:681
3D (3x1) vector
Definition: vector.h:49
void UnloadModel(const std::string &fileName, bool mirrored)
Unloads the given model.
Definition: modelmanager.cpp:146
void Mirror(std::vector< ModelTriangle > &triangles)
Mirrors the model along the Z axis.
Definition: modelmanager.cpp:165
bool AddModelReference(const std::string &fileName, bool mirrored, int objRank)
Adds an instance of model to the given object rank as a reference to base object. ...
Definition: modelmanager.cpp:86