World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
AssetsManager.cpp
См. документацию.
1 #include "Engine/AssetsManager.h"
2 
3 #include <algorithm>
4 
5 #include "Engine/Engine.h"
6 #include "Engine/LOD.h"
7 
11 
13 
14 bool AssetsManager::ReleaseAllImages() { return true; }
15 
17  auto filename = name;
18  std::transform(filename.begin(), filename.end(), filename.begin(),
19  ::tolower);
20 
21  auto i = images.find(filename);
22  if (i == images.end()) {
23  return false;
24  }
25 
26  images.erase(filename);
27 
28  return true;
29 }
30 
31 
32 
33 
35  auto filename = name;
36  std::transform(filename.begin(), filename.end(), filename.begin(),
37  ::tolower);
38 
39  auto i = images.find(filename);
40  if (i == images.end()) {
41  auto image = render->CreateTexture_ColorKey(name, colorkey);
42  images[filename] = image;
43  return image;
44  }
45 
46  return i->second;
47 }
48 
49 
50 
52  auto filename = name;
53  std::transform(filename.begin(), filename.end(), filename.begin(),
54  ::tolower);
55 
56  auto i = images.find(filename);
57  if (i == images.end()) {
58  auto image = render->CreateTexture_Solid(name);
59  images[filename] = image;
60  return image;
61  }
62 
63  return i->second;
64 }
65 
67  auto filename = name;
68  std::transform(filename.begin(), filename.end(), filename.begin(),
69  ::tolower);
70 
71  auto i = images.find(filename);
72  if (i == images.end()) {
73  auto image = render->CreateTexture_Alpha(name);
74  images[filename] = image;
75  return image;
76  }
77 
78  return i->second;
79 }
80 
82  auto filename = name;
83  std::transform(filename.begin(), filename.end(), filename.begin(),
84  ::tolower);
85 
86  auto i = images.find(filename);
87  if (i == images.end()) {
88  auto image = render->CreateTexture_PCXFromIconsLOD(name);
89  images[filename] = image;
90  return image;
91  }
92 
93  return i->second;
94 }
95 
97  auto filename = name;
98  std::transform(filename.begin(), filename.end(), filename.begin(),
99  ::tolower);
100 
101  auto i = images.find(filename);
102  if (i == images.end()) {
103  auto image = render->CreateTexture_PCXFromNewLOD(name);
104  images[filename] = image;
105  return image;
106  }
107 
108  return i->second;
109 }
110 
112  auto filename = name;
113  std::transform(filename.begin(), filename.end(), filename.begin(),
114  ::tolower);
115 
116  auto i = images.find(filename);
117  if (i == images.end()) {
118  auto image = render->CreateTexture_PCXFromFile(name);
119  images[filename] = image;
120  return image;
121  }
122 
123  return i->second;
124 }
125 
127  auto filename = name;
128  std::transform(filename.begin(), filename.end(), filename.begin(),
129  ::tolower);
130 
131  auto i = bitmaps.find(filename);
132  if (i == bitmaps.end()) {
133  auto texture = render->CreateTexture(filename);
134  bitmaps[filename] = texture;
135  return texture;
136  }
137 
138  return i->second;
139 }
140 
141 Texture *AssetsManager::GetSprite(const String &name, unsigned int palette_id,
142  unsigned int lod_sprite_id) {
143  auto filename = name;
144  std::transform(filename.begin(), filename.end(), filename.begin(),
145  ::tolower);
146 
147  auto i = sprites.find(filename);
148  if (i == sprites.end()) {
149  auto texture =
150  render->CreateSprite(filename, palette_id, lod_sprite_id);
151  sprites[filename] = texture;
152  return texture;
153  }
154 
155  return i->second;
156 }
uint16_t
unsigned __int16 uint16_t
Definition: SDL_config.h:37
AssetsManager::GetImage_PCXFromNewLOD
Texture * GetImage_PCXFromNewLOD(const String &name)
Definition: AssetsManager.cpp:96
LOD.h
AssetsManager
Definition: AssetsManager.h:10
AssetsManager::GetImage_Solid
Texture * GetImage_Solid(const String &name)
Definition: AssetsManager.cpp:51
AssetsManager::images
std::map< String, Texture * > images
Definition: AssetsManager.h:33
AssetsManager::sprites
std::map< String, Texture * > sprites
Definition: AssetsManager.h:32
Texture
Definition: Texture.h:4
AssetsManager::ReleaseAllImages
bool ReleaseAllImages()
Definition: AssetsManager.cpp:14
AssetsManager::GetImage_PCXFromIconsLOD
Texture * GetImage_PCXFromIconsLOD(const String &name)
Definition: AssetsManager.cpp:81
texture
GLenum GLenum GLuint texture
Definition: SDL_opengl_glext.h:1181
ImageLoader.h
AssetsManager.h
AssetsManager::GetImage_PCXFromFile
Texture * GetImage_PCXFromFile(const String &name)
Definition: AssetsManager.cpp:111
Engine.h
AssetsManager::bitmaps
std::map< String, Texture * > bitmaps
Definition: AssetsManager.h:31
IRender.h
AssetsManager::GetSprite
Texture * GetSprite(const String &name, unsigned int palette_id, unsigned int lod_sprite_id)
Definition: AssetsManager.cpp:141
AssetsManager::GetImage_ColorKey
Texture * GetImage_ColorKey(const String &name, uint16_t colorkey)
Definition: AssetsManager.cpp:34
AssetsManager::GetBitmap
Texture * GetBitmap(const String &name)
Definition: AssetsManager.cpp:126
transform
GLuint GLenum GLenum transform
Definition: SDL_opengl_glext.h:9999
AssetsManager::ReleaseImage
bool ReleaseImage(const String &name)
Definition: AssetsManager.cpp:16
name
EGLImageKHR EGLint * name
Definition: SDL_egl.h:1497
Texture.h
assets
AssetsManager * assets
Definition: AssetsManager.cpp:12
AssetsManager::GetImage_Alpha
Texture * GetImage_Alpha(const String &name)
Definition: AssetsManager.cpp:66
image
EGLImageKHR image
Definition: SDL_egl.h:953
String
std::string String
Definition: Strings.h:10
render
std::shared_ptr< IRender > render
Definition: RenderOpenGL.cpp:52