equal
deleted
inserted
replaced
116 return GetSpriteCache(id)->file_pos != 0; |
116 return GetSpriteCache(id)->file_pos != 0; |
117 } |
117 } |
118 |
118 |
119 void* AllocSprite(size_t); |
119 void* AllocSprite(size_t); |
120 |
120 |
121 static void* ReadSprite(SpriteCache *sc, SpriteID id) |
121 static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) |
122 { |
122 { |
123 uint32 file_pos = sc->file_pos; |
123 uint32 file_pos = sc->file_pos; |
124 |
124 |
125 DEBUG(sprite, 9, "Load sprite %d", id); |
125 DEBUG(sprite, 9, "Load sprite %d", id); |
126 |
126 |
137 /* Read the size and type */ |
137 /* Read the size and type */ |
138 int num = FioReadWord(); |
138 int num = FioReadWord(); |
139 byte type = FioReadByte(); |
139 byte type = FioReadByte(); |
140 /* Type 0xFF indicates either a colormap or some other non-sprite info */ |
140 /* Type 0xFF indicates either a colormap or some other non-sprite info */ |
141 if (type == 0xFF) { |
141 if (type == 0xFF) { |
|
142 if (real_sprite) { |
|
143 static byte warning_level = 0; |
|
144 DEBUG(sprite, warning_level, "Tried to load non sprite #%d as a real sprite. Probable cause: NewGRF interference", id); |
|
145 warning_level = 6; |
|
146 if (id == SPR_IMG_QUERY) error("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non- sprite?"); |
|
147 return (void*)GetSprite(SPR_IMG_QUERY); |
|
148 } |
|
149 |
142 byte *dest = (byte *)AllocSprite(num); |
150 byte *dest = (byte *)AllocSprite(num); |
143 |
151 |
144 sc->ptr = dest; |
152 sc->ptr = dest; |
145 FioReadBlock(dest, num); |
153 FioReadBlock(dest, num); |
146 |
154 |
184 } |
192 } |
185 |
193 |
186 return sc->ptr; |
194 return sc->ptr; |
187 } |
195 } |
188 |
196 |
|
197 if (!real_sprite) { |
|
198 static byte warning_level = 0; |
|
199 DEBUG(sprite, warning_level, "Tried to load real sprite #%d as a non sprite. Probable cause: NewGRF interference", id); |
|
200 warning_level = 6; |
|
201 } |
|
202 |
189 SpriteLoaderGrf sprite_loader; |
203 SpriteLoaderGrf sprite_loader; |
190 SpriteLoader::Sprite sprite; |
204 SpriteLoader::Sprite sprite; |
191 |
205 |
192 if (!sprite_loader.LoadSprite(&sprite, file_pos)) return NULL; |
206 if (!sprite_loader.LoadSprite(&sprite, file_pos)) return NULL; |
193 if (id == 142) sprite.height = 10; // Compensate for a TTD bug |
207 if (id == 142) sprite.height = 10; // Compensate for a TTD bug |
401 DeleteEntryFromSpriteCache(); |
415 DeleteEntryFromSpriteCache(); |
402 } |
416 } |
403 } |
417 } |
404 |
418 |
405 |
419 |
406 const void *GetRawSprite(SpriteID sprite) |
420 const void *GetRawSprite(SpriteID sprite, bool real_sprite) |
407 { |
421 { |
408 SpriteCache *sc; |
422 SpriteCache *sc; |
409 void* p; |
423 void* p; |
410 |
424 |
411 assert(sprite < _spritecache_items); |
425 assert(sprite < _spritecache_items); |
416 sc->lru = ++_sprite_lru_counter; |
430 sc->lru = ++_sprite_lru_counter; |
417 |
431 |
418 p = sc->ptr; |
432 p = sc->ptr; |
419 |
433 |
420 /* Load the sprite, if it is not loaded, yet */ |
434 /* Load the sprite, if it is not loaded, yet */ |
421 if (p == NULL) p = ReadSprite(sc, sprite); |
435 if (p == NULL) p = ReadSprite(sc, sprite, real_sprite); |
422 return p; |
436 return p; |
423 } |
437 } |
424 |
438 |
425 |
439 |
426 void GfxInitSpriteMem() |
440 void GfxInitSpriteMem() |