@@ -23,19 +23,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
23
23
#include " util/string.h"
24
24
#include " util/container.h"
25
25
#include " util/thread.h"
26
- #include " util/numeric.h"
27
- #include " irrlichttypes_extrabloated.h"
28
- #include " debug.h"
29
26
#include " filesys.h"
30
27
#include " settings.h"
31
28
#include " mesh.h"
32
- #include " log.h"
33
29
#include " gamedef.h"
34
30
#include " util/strfnd.h"
35
- #include " util/string.h" // for parseColorString()
36
31
#include " imagefilters.h"
37
32
#include " guiscalingfilter.h"
38
- #include " nodedef.h"
39
33
#include " renderingengine.h"
40
34
41
35
@@ -96,13 +90,13 @@ std::string getImagePath(std::string path)
96
90
NULL
97
91
};
98
92
// If there is no extension, add one
99
- if (removeStringEnd (path, extensions) == " " )
93
+ if (removeStringEnd (path, extensions). empty () )
100
94
path = path + " .png" ;
101
95
// Check paths until something is found to exist
102
96
const char **ext = extensions;
103
97
do {
104
98
bool r = replace_ext (path, *ext);
105
- if (r == false )
99
+ if (!r )
106
100
return " " ;
107
101
if (fs::PathExists (path))
108
102
return path;
@@ -124,7 +118,7 @@ std::string getImagePath(std::string path)
124
118
*/
125
119
std::string getTexturePath (const std::string &filename)
126
120
{
127
- std::string fullpath = " " ;
121
+ std::string fullpath;
128
122
/*
129
123
Check from cache
130
124
*/
@@ -136,7 +130,7 @@ std::string getTexturePath(const std::string &filename)
136
130
Check from texture_path
137
131
*/
138
132
const std::string &texture_path = g_settings->get (" texture_path" );
139
- if (texture_path != " " ) {
133
+ if (!texture_path. empty () ) {
140
134
std::string testpath = texture_path + DIR_DELIM + filename;
141
135
// Check all filename extensions. Returns "" if not found.
142
136
fullpath = getImagePath (testpath);
@@ -145,7 +139,7 @@ std::string getTexturePath(const std::string &filename)
145
139
/*
146
140
Check from default data directory
147
141
*/
148
- if (fullpath == " " )
142
+ if (fullpath. empty () )
149
143
{
150
144
std::string base_path = porting::path_share + DIR_DELIM + " textures"
151
145
+ DIR_DELIM + " base" + DIR_DELIM + " pack" ;
@@ -193,9 +187,8 @@ class SourceImageCache
193
187
{
194
188
public:
195
189
~SourceImageCache () {
196
- for (std::map<std::string, video::IImage*>::iterator iter = m_images.begin ();
197
- iter != m_images.end (); ++iter) {
198
- iter->second ->drop ();
190
+ for (auto &m_image : m_images) {
191
+ m_image.second ->drop ();
199
192
}
200
193
m_images.clear ();
201
194
}
@@ -216,7 +209,7 @@ class SourceImageCache
216
209
// Try to use local texture instead if asked to
217
210
if (prefer_local){
218
211
std::string path = getTexturePath (name);
219
- if (path != " " ) {
212
+ if (!path. empty ()) {
220
213
video::IImage *img2 = RenderingEngine::get_video_driver ()->
221
214
createImageFromFile (path.c_str ());
222
215
if (img2){
@@ -249,7 +242,7 @@ class SourceImageCache
249
242
}
250
243
video::IVideoDriver *driver = RenderingEngine::get_video_driver ();
251
244
std::string path = getTexturePath (name);
252
- if (path == " " ) {
245
+ if (path. empty ()) {
253
246
infostream<<" SourceImageCache::getOrLoad(): No path found for \" "
254
247
<<name<<" \" " <<std::endl;
255
248
return NULL ;
@@ -351,7 +344,7 @@ class TextureSource : public IWritableTextureSource
351
344
if (cache_found)
352
345
return is_known;
353
346
// Not found in cache; find out if a local file exists
354
- is_known = (getTexturePath (name) != " " );
347
+ is_known = (! getTexturePath (name). empty () );
355
348
m_source_image_existence.set (name, is_known);
356
349
return is_known;
357
350
}
@@ -438,7 +431,7 @@ TextureSource::TextureSource()
438
431
m_main_thread = std::this_thread::get_id ();
439
432
440
433
// Add a NULL TextureInfo as the first index, named ""
441
- m_textureinfo_cache.push_back ( TextureInfo ( " " ) );
434
+ m_textureinfo_cache.emplace_back ( " " );
442
435
m_name_to_id[" " ] = 0 ;
443
436
444
437
// Cache some settings
@@ -455,21 +448,14 @@ TextureSource::~TextureSource()
455
448
456
449
unsigned int textures_before = driver->getTextureCount ();
457
450
458
- for (std::vector<TextureInfo>::iterator iter =
459
- m_textureinfo_cache.begin ();
460
- iter != m_textureinfo_cache.end (); ++iter)
461
- {
451
+ for (const auto &iter : m_textureinfo_cache) {
462
452
// cleanup texture
463
- if (iter-> texture )
464
- driver->removeTexture (iter-> texture );
453
+ if (iter. texture )
454
+ driver->removeTexture (iter. texture );
465
455
}
466
456
m_textureinfo_cache.clear ();
467
457
468
- for (std::vector<video::ITexture*>::iterator iter =
469
- m_texture_trash.begin (); iter != m_texture_trash.end ();
470
- ++iter) {
471
- video::ITexture *t = *iter;
472
-
458
+ for (auto t : m_texture_trash) {
473
459
// cleanup trashed texture
474
460
driver->removeTexture (t);
475
461
}
@@ -586,7 +572,7 @@ u32 TextureSource::generateTexture(const std::string &name)
586
572
// infostream << "generateTexture(): name=\"" << name << "\"" << std::endl;
587
573
588
574
// Empty name means texture 0
589
- if (name == " " ) {
575
+ if (name. empty () ) {
590
576
infostream<<" generateTexture(): name is empty" <<std::endl;
591
577
return 0 ;
592
578
}
@@ -690,7 +676,7 @@ Palette* TextureSource::getPalette(const std::string &name)
690
676
if (name == " " )
691
677
return NULL ;
692
678
693
- std::unordered_map<std::string, Palette>::iterator it = m_palettes.find (name);
679
+ auto it = m_palettes.find (name);
694
680
if (it == m_palettes.end ()) {
695
681
// Create palette
696
682
video::IImage *img = generateImage (name);
@@ -728,7 +714,7 @@ Palette* TextureSource::getPalette(const std::string &name)
728
714
img->drop ();
729
715
// Fill in remaining elements
730
716
while (new_palette.size () < 256 )
731
- new_palette.push_back ( video::SColor ( 0xFFFFFFFF ) );
717
+ new_palette.emplace_back ( 0xFFFFFFFF );
732
718
m_palettes[name] = new_palette;
733
719
it = m_palettes.find (name);
734
720
}
@@ -775,22 +761,21 @@ void TextureSource::rebuildImagesAndTextures()
775
761
sanity_check (driver);
776
762
777
763
// Recreate textures
778
- for (u32 i=0 ; i<m_textureinfo_cache.size (); i++){
779
- TextureInfo *ti = &m_textureinfo_cache[i];
780
- video::IImage *img = generateImage (ti->name );
764
+ for (TextureInfo &ti : m_textureinfo_cache) {
765
+ video::IImage *img = generateImage (ti.name );
781
766
#ifdef __ANDROID__
782
767
img = Align2Npot2 (img, driver);
783
768
#endif
784
769
// Create texture from resulting image
785
770
video::ITexture *t = NULL ;
786
771
if (img) {
787
- t = driver->addTexture (ti-> name .c_str (), img);
788
- guiScalingCache (io::path (ti-> name .c_str ()), driver, img);
772
+ t = driver->addTexture (ti. name .c_str (), img);
773
+ guiScalingCache (io::path (ti. name .c_str ()), driver, img);
789
774
img->drop ();
790
775
}
791
- video::ITexture *t_old = ti-> texture ;
776
+ video::ITexture *t_old = ti. texture ;
792
777
// Replace texture
793
- ti-> texture = t;
778
+ ti. texture = t;
794
779
795
780
if (t_old)
796
781
m_texture_trash.push_back (t_old);
@@ -1185,14 +1170,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
1185
1170
sanity_check (driver);
1186
1171
1187
1172
// Stuff starting with [ are special commands
1188
- if (part_of_name.size () == 0 || part_of_name[0 ] != ' [' )
1189
- {
1173
+ if (part_of_name.empty () || part_of_name[0 ] != ' [' ) {
1190
1174
video::IImage *image = m_sourcecache.getOrLoad (part_of_name);
1191
1175
#ifdef __ANDROID__
1192
1176
image = Align2Npot2 (image, driver);
1193
1177
#endif
1194
1178
if (image == NULL ) {
1195
- if (part_of_name != " " ) {
1179
+ if (!part_of_name. empty () ) {
1196
1180
1197
1181
// Do not create normalmap dummies
1198
1182
if (part_of_name.find (" _normal.png" ) != std::string::npos) {
@@ -1343,7 +1327,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
1343
1327
baseimg = driver->createImage (video::ECF_A8R8G8B8, dim);
1344
1328
baseimg->fill (video::SColor (0 ,0 ,0 ,0 ));
1345
1329
}
1346
- while (sf.at_end () == false ) {
1330
+ while (! sf.at_end ()) {
1347
1331
u32 x = stoi (sf.next (" ," ));
1348
1332
u32 y = stoi (sf.next (" =" ));
1349
1333
std::string filename = unescape_string (sf.next_esc (" :" , escape), escape);
@@ -1896,13 +1880,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
1896
1880
1897
1881
std::string mode = sf.next (" " );
1898
1882
u32 mask = 0 ;
1899
- if (mode.find (" a " ) != std::string::npos)
1883
+ if (mode.find (' a ' ) != std::string::npos)
1900
1884
mask |= 0xff000000UL ;
1901
- if (mode.find (" r " ) != std::string::npos)
1885
+ if (mode.find (' r ' ) != std::string::npos)
1902
1886
mask |= 0x00ff0000UL ;
1903
- if (mode.find (" g " ) != std::string::npos)
1887
+ if (mode.find (' g ' ) != std::string::npos)
1904
1888
mask |= 0x0000ff00UL ;
1905
- if (mode.find (" b " ) != std::string::npos)
1889
+ if (mode.find (' b ' ) != std::string::npos)
1906
1890
mask |= 0x000000ffUL ;
1907
1891
1908
1892
core::dimension2d<u32> dim = baseimg->getDimension ();
@@ -2240,9 +2224,8 @@ u32 parseImageTransform(const std::string& s)
2240
2224
pos++;
2241
2225
break ;
2242
2226
}
2243
- else if (!(name_i.empty ()) &&
2244
- lowercase (s.substr (pos, name_i.size ())) == name_i)
2245
- {
2227
+
2228
+ if (!(name_i.empty ()) && lowercase (s.substr (pos, name_i.size ())) == name_i) {
2246
2229
transform = i;
2247
2230
pos += name_i.size ();
2248
2231
break ;
@@ -2269,8 +2252,8 @@ core::dimension2d<u32> imageTransformDimension(u32 transform, core::dimension2d<
2269
2252
{
2270
2253
if (transform % 2 == 0 )
2271
2254
return dim;
2272
- else
2273
- return core::dimension2d<u32>(dim.Height , dim.Width );
2255
+
2256
+ return core::dimension2d<u32>(dim.Height , dim.Width );
2274
2257
}
2275
2258
2276
2259
void imageTransform (u32 transform, video::IImage *src, video::IImage *dst)
@@ -2325,12 +2308,12 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name)
2325
2308
std::string fname_base = name;
2326
2309
static const char *normal_ext = " _normal.png" ;
2327
2310
static const u32 normal_ext_size = strlen (normal_ext);
2328
- size_t pos = fname_base.find (" . " );
2311
+ size_t pos = fname_base.find (' . ' );
2329
2312
std::string fname_normal = fname_base.substr (0 , pos) + normal_ext;
2330
2313
if (isKnownSourceImage (fname_normal)) {
2331
2314
// look for image extension and replace it
2332
2315
size_t i = 0 ;
2333
- while ((i = fname_base.find (" . " , i)) != std::string::npos) {
2316
+ while ((i = fname_base.find (' . ' , i)) != std::string::npos) {
2334
2317
fname_base.replace (i, 4 , normal_ext);
2335
2318
i += normal_ext_size;
2336
2319
}
@@ -2384,15 +2367,16 @@ video::ITexture *TextureSource::getShaderFlagsTexture(bool normalmap_present)
2384
2367
2385
2368
if (isKnownSourceImage (tname)) {
2386
2369
return getTexture (tname);
2387
- } else {
2388
- video::IVideoDriver *driver = RenderingEngine::get_video_driver ();
2389
- video::IImage *flags_image = driver->createImage (
2390
- video::ECF_A8R8G8B8, core::dimension2d<u32>(1 , 1 ));
2391
- sanity_check (flags_image != NULL );
2392
- video::SColor c (255 , normalmap_present ? 255 : 0 , 0 , 0 );
2393
- flags_image->setPixel (0 , 0 , c);
2394
- insertSourceImage (tname, flags_image);
2395
- flags_image->drop ();
2396
- return getTexture (tname);
2397
2370
}
2371
+
2372
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver ();
2373
+ video::IImage *flags_image = driver->createImage (
2374
+ video::ECF_A8R8G8B8, core::dimension2d<u32>(1 , 1 ));
2375
+ sanity_check (flags_image != NULL );
2376
+ video::SColor c (255 , normalmap_present ? 255 : 0 , 0 , 0 );
2377
+ flags_image->setPixel (0 , 0 , c);
2378
+ insertSourceImage (tname, flags_image);
2379
+ flags_image->drop ();
2380
+ return getTexture (tname);
2381
+
2398
2382
}
0 commit comments