equal
deleted
inserted
replaced
23 |
23 |
24 |
24 |
25 struct SpriteCache { |
25 struct SpriteCache { |
26 void *ptr; |
26 void *ptr; |
27 uint32 id; |
27 uint32 id; |
28 uint32 file_pos; |
28 size_t file_pos; |
29 uint16 file_slot; |
29 uint16 file_slot; |
30 int16 lru; |
30 int16 lru; |
31 }; |
31 }; |
32 |
32 |
33 |
33 |
121 void* AllocSprite(size_t); |
121 void* AllocSprite(size_t); |
122 |
122 |
123 static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) |
123 static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) |
124 { |
124 { |
125 uint8 file_slot = sc->file_slot; |
125 uint8 file_slot = sc->file_slot; |
126 uint32 file_pos = sc->file_pos; |
126 size_t file_pos = sc->file_pos; |
127 |
127 |
128 DEBUG(sprite, 9, "Load sprite %d", id); |
128 DEBUG(sprite, 9, "Load sprite %d", id); |
129 |
129 |
130 if (!SpriteExists(id)) { |
130 if (!SpriteExists(id)) { |
131 DEBUG(sprite, 1, "Tried to load non-existing sprite #%d. Probable cause: Wrong/missing NewGRFs", id); |
131 DEBUG(sprite, 1, "Tried to load non-existing sprite #%d. Probable cause: Wrong/missing NewGRFs", id); |
167 if (type == 0xFF) { |
167 if (type == 0xFF) { |
168 if (real_sprite) { |
168 if (real_sprite) { |
169 static byte warning_level = 0; |
169 static byte warning_level = 0; |
170 DEBUG(sprite, warning_level, "Tried to load non sprite #%d as a real sprite. Probable cause: NewGRF interference", id); |
170 DEBUG(sprite, warning_level, "Tried to load non sprite #%d as a real sprite. Probable cause: NewGRF interference", id); |
171 warning_level = 6; |
171 warning_level = 6; |
172 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?"); |
172 if (id == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non- sprite?"); |
173 return (void*)GetSprite(SPR_IMG_QUERY); |
173 return (void*)GetSprite(SPR_IMG_QUERY); |
174 } |
174 } |
175 |
175 |
176 byte *dest = (byte *)AllocSprite(num); |
176 byte *dest = (byte *)AllocSprite(num); |
177 |
177 |
239 |
239 |
240 |
240 |
241 bool LoadNextSprite(int load_index, byte file_slot, uint file_sprite_id) |
241 bool LoadNextSprite(int load_index, byte file_slot, uint file_sprite_id) |
242 { |
242 { |
243 SpriteCache *sc; |
243 SpriteCache *sc; |
244 uint32 file_pos = FioGetPos(); |
244 size_t file_pos = FioGetPos(); |
245 |
245 |
246 if (!ReadSpriteHeaderSkipData()) return false; |
246 if (!ReadSpriteHeaderSkipData()) return false; |
247 |
247 |
248 if (load_index >= MAX_SPRITES) { |
248 if (load_index >= MAX_SPRITES) { |
249 error("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES); |
249 usererror("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES); |
250 } |
250 } |
251 |
251 |
252 sc = AllocateSpriteCache(load_index); |
252 sc = AllocateSpriteCache(load_index); |
253 sc->file_slot = file_slot; |
253 sc->file_slot = file_slot; |
254 sc->file_pos = file_pos; |
254 sc->file_pos = file_pos; |
277 static inline MemBlock* NextBlock(MemBlock* block) |
277 static inline MemBlock* NextBlock(MemBlock* block) |
278 { |
278 { |
279 return (MemBlock*)((byte*)block + (block->size & ~S_FREE_MASK)); |
279 return (MemBlock*)((byte*)block + (block->size & ~S_FREE_MASK)); |
280 } |
280 } |
281 |
281 |
282 static uint32 GetSpriteCacheUsage() |
282 static size_t GetSpriteCacheUsage() |
283 { |
283 { |
284 uint32 tot_size = 0; |
284 size_t tot_size = 0; |
285 MemBlock* s; |
285 MemBlock* s; |
286 |
286 |
287 for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) { |
287 for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) { |
288 if (!(s->size & S_FREE_MASK)) tot_size += s->size; |
288 if (!(s->size & S_FREE_MASK)) tot_size += s->size; |
289 } |
289 } |