RioEngine  0.1
My first attempt to create a 3D WYSIWYG Game Engine
classetsrepository.cpp
Go to the documentation of this file.
1 //--------------------------------------------------------------- @License begins
2 // RioEngine: The late night Coke -without whores- debugging sessions
3 // 2012-2015 Leopoldo Lomas Flores. Torreon, Coahuila. MEXICO
4 // leopoldolomas [at] gmail
5 // www.rioengine.com
6 // www.leopoldolomas.info
7 // "You have a problem, you face it like a man."
8 //
9 // This is free and unencumbered software released into the public domain.
10 //
11 // Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
12 // software, either in source code form or as a compiled binary, for any purpose,
13 // commercial or non-commercial, and by any means.
14 //
15 // In jurisdictions that recognize copyright laws, the author or authors of this
16 // software dedicate any and all copyright interest in the software to the public
17 // domain. We make this dedication for the benefit of the public at large and to
18 // the detriment of our heirs and successors. We intend this dedication to be
19 // an overt act of relinquishment in perpetuity of all present and future
20 // rights to this software under copyright law.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS
24 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //--------------------------------------------------------------- @License ends
29 
30 #include "misc/directoryhelper.hpp"
32 
33 //-----------------------------------------------------------------------------
34 
36  std::string resources_dir = DirectoryHelper::getProjectDirectory();
37  resources_dir.append("assets\\");
38 
39  m_resourcesDir = resources_dir;
40 }
41 
42 //-----------------------------------------------------------------------------
43 
45  CLASSETSREPOSITORY; // instantiates the shared instance if needed
46 
47  std::vector<std::string> collada_files = DirectoryHelper::getFileList(m_resourcesDir, "dae");
48 
49  for (std::vector<std::string>::iterator it = collada_files.begin();
50  it != collada_files.end();
51  ++it) {
52  std::string file = *it;
53  std::string file_path = m_resourcesDir;
54  file_path.append(file);
55 
56  CLScene* scene = new CLScene((char*)file_path.c_str());
57  CLASSETSREPOSITORY->addScene(scene);
58  SAFE_RELEASE(scene);
59  }
60 }
61 
62 //-----------------------------------------------------------------------------
63 
65  addImagesFromScene(scene);
66  addMaterialsFromScene(scene);
67  addEffectsFromScene(scene);
69  addNodesFromScene(scene);
70 }
71 
72 //-----------------------------------------------------------------------------
73 
75  auto it = scene->images()->begin();
76 
77  for (; it != scene->images()->end(); it++) {
78  std::string image_id = it->first;
79  if (getImageDetailsHavingId(image_id)) {
80  // TODO rename the image if needed
81  }
82 
83  CLImageDetails* copy_obj = new CLImageDetails(*it->second);
84  insertImagePair(image_id, copy_obj);
85  }
86 }
87 
88 //-----------------------------------------------------------------------------
89 
91  auto it = scene->materials()->begin();
92 
93  for (; it != scene->materials()->end(); it++) {
94  std::string material_id = it->first;
95  if (getMaterialHavingId(material_id)) {
96  // TODO rename the material if needed
97  }
98 
99  CLMaterial* copy_obj = new CLMaterial(*it->second);
100  insertMaterialPair(material_id, copy_obj);
101  }
102 }
103 
104 //-----------------------------------------------------------------------------
105 
107  auto it = scene->effects()->begin();
108 
109  for (; it != scene->effects()->end(); it++) {
110  std::string effect_id = it->first;
111  if (getEffectHavingId(effect_id)) {
112  // TODO rename the effect if needed
113  }
114 
115  CLEffect* copy_obj = new CLEffect(*it->second);
116  insertEffectPair(effect_id, copy_obj);
117  }
118 }
119 
120 //-----------------------------------------------------------------------------
121 
123  auto it = scene->geometries()->begin();
124 
125  for (; it != scene->geometries()->end(); it++) {
126  std::string geometry_id = it->first;
127  if (getGeometryObjHavingId(geometry_id)) {
128  // TODO rename the geometry if needed
129  }
130 
131  CLGeometry* original_obj = static_cast<CLGeometry*>(it->second);
132  CLGeometry* copy_obj = new CLGeometry(*original_obj);
133  insertGeometryPair(geometry_id, copy_obj);
134  }
135 }
136 
137 //-----------------------------------------------------------------------------
138 
140  auto it = scene->nodes()->begin();
141 
142  for (; it != scene->nodes()->end(); it++) {
143  std::string node_id = it->first;
144  if (getNodeHavingId(node_id)) {
145  // TODO rename the node if needed
146  }
147 
148  CLNode* copy_obj = new CLNode(*it->second);
149  insertNodesPair(node_id, copy_obj);
150  }
151 }
const GeometriesMapType * geometries() const
Definition: clscene.cpp:378
const EffectsMapType * effects() const
Definition: clscene.cpp:372
const ImagesMapType * images() const
Definition: clscene.cpp:360
void insertImagePair(const std::string &image_id, CLImageDetails *image_details)
Definition: clscene.cpp:141
Definition: clnode.h:37
void insertMaterialPair(const std::string &material_id, CLMaterial *material)
Definition: clscene.cpp:147
static std::vector< std::string > getFileList(std::string dir)
void insertNodesPair(const std::string &node_id, CLNode *node)
Definition: clscene.cpp:165
const MaterialsMapType * materials() const
Definition: clscene.cpp:366
CLScene()
Definition: clscene.cpp:54
CLGeometry * getGeometryObjHavingId(const std::string &geometry_obj_id)
Definition: clscene.cpp:135
CLNode * getNodeHavingId(const std::string &node_id)
Definition: clscene.cpp:111
#define SAFE_RELEASE(x)
Definition: cobject.h:36
void addImagesFromScene(CLScene *scene)
CLEffect * getEffectHavingId(const std::string &effect_id)
Definition: clscene.cpp:123
CLMaterial * getMaterialHavingId(const std::string &material_id)
Definition: clscene.cpp:117
void addEffectsFromScene(CLScene *scene)
static std::string getProjectDirectory()
void addGeometriesFromScene(CLScene *scene)
void addMaterialsFromScene(CLScene *scene)
#define CLASSETSREPOSITORY
void insertGeometryPair(const std::string &geometry_id, CLGeometry *geometry)
Definition: clscene.cpp:159
void insertEffectPair(const std::string &effect_id, CLEffect *effect)
Definition: clscene.cpp:153
void addNodesFromScene(CLScene *scene)
const NodesMapType * nodes() const
Definition: clscene.cpp:354
CLImageDetails * getImageDetailsHavingId(const std::string &image_id)
Definition: clscene.cpp:129
void addScene(CLScene *scene)