Colobot
oldmodelmanager.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
22 #include "common/singleton.h"
23 
24 #include "graphics/model/model_triangle.h"
25 
26 #include <string>
27 #include <vector>
28 #include <map>
29 
30 namespace Gfx
31 {
32 
33 class CEngine;
34 class CModelFile;
35 
56 {
57 public:
58  COldModelManager(CEngine* engine);
60 
62  bool LoadModel(const std::string& fileName, bool mirrored, int variant = 0);
63 
65  bool AddModelReference(const std::string& fileName, bool mirrored, int objRank, int variant = 0);
66 
68  bool AddModelCopy(const std::string& fileName, bool mirrored, int objRank, int variant = 0);
69 
71  bool IsModelLoaded(const std::string& fileName, bool mirrored, int variant = 0);
72 
74  int GetModelBaseObjRank(const std::string& fileName, bool mirrored, int variant = 0);
75 
77  void DeleteAllModelCopies();
78 
80  void UnloadModel(const std::string& fileName, bool mirrored, int variant = 0);
82  void UnloadAllModels();
83 
84 protected:
86  void Mirror(std::vector<ModelTriangle>& triangles);
88  void ChangeVariant(std::vector<ModelTriangle>& triangles, int variant);
89 
90 private:
91  struct ModelInfo
92  {
93  std::vector<ModelTriangle> triangles;
94  int baseObjRank = -1;
95  };
96  struct FileInfo
97  {
98  std::string fileName;
99  bool mirrored;
100  int variant;
101 
102  inline FileInfo(const std::string& _fileName, bool _mirrored, int _variant = 0)
103  : fileName(_fileName)
104  , mirrored(_mirrored)
105  , variant(_variant)
106  {}
107 
108  inline bool operator<(const FileInfo& other) const
109  {
110  int compare = fileName.compare(other.fileName);
111  if (compare < 0)
112  return true;
113  if (compare > 0)
114  return false;
115 
116  if (variant < other.variant)
117  return true;
118 
119  return !mirrored && mirrored != other.mirrored;
120  }
121  };
122  std::map<FileInfo, ModelInfo> m_models;
123  std::vector<int> m_copiesBaseRanks;
124  CEngine* m_engine;
125 };
126 
127 } // namespace Gfx
void ChangeVariant(std::vector< ModelTriangle > &triangles, int variant)
Changes variant.
Definition: oldmodelmanager.cpp:186
bool AddModelCopy(const std::string &fileName, bool mirrored, int objRank, int variant=0)
Adds an instance of model to the given object rank as a copy (copied base object) ...
Definition: oldmodelmanager.cpp:105
void UnloadModel(const std::string &fileName, bool mirrored, int variant=0)
Unloads the given model.
Definition: oldmodelmanager.cpp:149
CSingleton base class for singletons.
int GetModelBaseObjRank(const std::string &fileName, bool mirrored, int variant=0)
Returns the rank of base engine object of given loaded model.
Definition: oldmodelmanager.cpp:130
void Mirror(std::vector< ModelTriangle > &triangles)
Mirrors the model along the Z axis.
Definition: oldmodelmanager.cpp:168
Manager for static models.
Definition: oldmodelmanager.h:55
void UnloadAllModels()
Unloads all models.
Definition: oldmodelmanager.cpp:160
void DeleteAllModelCopies()
Deletes all copied objects.
Definition: oldmodelmanager.cpp:139
bool IsModelLoaded(const std::string &fileName, bool mirrored, int variant=0)
Returns true if given model is loaded.
Definition: oldmodelmanager.cpp:125
Namespace for (new) graphics code.
Definition: app.h:49
The graphics engine.
Definition: engine.h:620
bool LoadModel(const std::string &fileName, bool mirrored, int variant=0)
Loads a model from given file.
Definition: oldmodelmanager.cpp:48
bool AddModelReference(const std::string &fileName, bool mirrored, int objRank, int variant=0)
Adds an instance of model to the given object rank as a reference to base object. ...
Definition: oldmodelmanager.cpp:89