Colobot
oldmodelmanager.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, 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 
55 {
56 public:
57  COldModelManager(CEngine* engine);
59 
61  bool LoadModel(const std::string& fileName, bool mirrored, int variant = 0);
62 
64  bool AddModelReference(const std::string& fileName, bool mirrored, int objRank, int variant = 0);
65 
67  bool AddModelCopy(const std::string& fileName, bool mirrored, int objRank, int variant = 0);
68 
70  bool IsModelLoaded(const std::string& fileName, bool mirrored, int variant = 0);
71 
73  int GetModelBaseObjRank(const std::string& fileName, bool mirrored, int variant = 0);
74 
76  void DeleteAllModelCopies();
77 
79  void UnloadModel(const std::string& fileName, bool mirrored, int variant = 0);
81  void UnloadAllModels();
82 
83 protected:
85  void Mirror(std::vector<ModelTriangle>& triangles);
87  void ChangeVariant(std::vector<ModelTriangle>& triangles, int variant);
88 
89 private:
90  struct ModelInfo
91  {
92  std::vector<ModelTriangle> triangles;
93  int baseObjRank = -1;
94  };
95  struct FileInfo
96  {
97  std::string fileName;
98  bool mirrored;
99  int variant;
100 
101  inline FileInfo(const std::string& _fileName, bool _mirrored, int _variant = 0)
102  : fileName(_fileName)
103  , mirrored(_mirrored)
104  , variant(_variant)
105  {}
106 
107  inline bool operator<(const FileInfo& other) const
108  {
109  int compare = fileName.compare(other.fileName);
110  if (compare < 0)
111  return true;
112  if (compare > 0)
113  return false;
114 
115  if (variant < other.variant)
116  return true;
117 
118  return !mirrored && mirrored != other.mirrored;
119  }
120  };
121  std::map<FileInfo, ModelInfo> m_models;
122  std::vector<int> m_copiesBaseRanks;
123  CEngine* m_engine;
124 };
125 
126 } // 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:54
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:585
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