src/spritecache.cpp
branch0.6
changeset 11128 b62a7b45babf
parent 9058 b9c3fec968b8
child 11150 4e3726a46a72
equal deleted inserted replaced
11127:5e9620220703 11128:b62a7b45babf
    26  	void *ptr;
    26  	void *ptr;
    27 	uint32 id;
    27 	uint32 id;
    28  	uint32 file_pos;
    28  	uint32 file_pos;
    29 	uint16 file_slot;
    29 	uint16 file_slot;
    30  	int16 lru;
    30  	int16 lru;
       
    31 	bool real_sprite; ///< In some cases a single sprite is misused by two NewGRFs. Once as real sprite and once as non-real sprite. If the non-real sprite gets into the cache it might be drawn as real sprite which causes enormous trouble.
    31 };
    32 };
    32 
    33 
    33 
    34 
    34 static uint _spritecache_items = 0;
    35 static uint _spritecache_items = 0;
    35 static SpriteCache *_spritecache = NULL;
    36 static SpriteCache *_spritecache = NULL;
   174 		}
   175 		}
   175 
   176 
   176 		byte *dest = (byte *)AllocSprite(num);
   177 		byte *dest = (byte *)AllocSprite(num);
   177 
   178 
   178 		sc->ptr = dest;
   179 		sc->ptr = dest;
       
   180 		sc->real_sprite = false;
   179 		FioReadBlock(dest, num);
   181 		FioReadBlock(dest, num);
   180 
   182 
   181 		return sc->ptr;
   183 		return sc->ptr;
   182 	}
   184 	}
   183 	/* Ugly hack to work around the problem that the old landscape
   185 	/* Ugly hack to work around the problem that the old landscape
   215 				num -= i;
   217 				num -= i;
   216 				for (; i > 0; --i) *dest++ = *rel++;
   218 				for (; i > 0; --i) *dest++ = *rel++;
   217 			}
   219 			}
   218 		}
   220 		}
   219 
   221 
       
   222 		sc->real_sprite = false;
       
   223 
   220 		return sc->ptr;
   224 		return sc->ptr;
   221 	}
   225 	}
       
   226 
       
   227 	sc->real_sprite = true;
   222 
   228 
   223 	if (!real_sprite) {
   229 	if (!real_sprite) {
   224 		static byte warning_level = 0;
   230 		static byte warning_level = 0;
   225 		DEBUG(sprite, warning_level, "Tried to load real sprite #%d as a non sprite. Probable cause: NewGRF interference", id);
   231 		DEBUG(sprite, warning_level, "Tried to load real sprite #%d as a non sprite. Probable cause: NewGRF interference", id);
   226 		warning_level = 6;
   232 		warning_level = 6;
   253 	sc->file_slot = file_slot;
   259 	sc->file_slot = file_slot;
   254 	sc->file_pos = file_pos;
   260 	sc->file_pos = file_pos;
   255 	sc->ptr = NULL;
   261 	sc->ptr = NULL;
   256 	sc->lru = 0;
   262 	sc->lru = 0;
   257 	sc->id = file_sprite_id;
   263 	sc->id = file_sprite_id;
       
   264 	sc->real_sprite = false;
   258 
   265 
   259 	return true;
   266 	return true;
   260 }
   267 }
   261 
   268 
   262 
   269 
   267 
   274 
   268 	scnew->file_slot = scold->file_slot;
   275 	scnew->file_slot = scold->file_slot;
   269 	scnew->file_pos = scold->file_pos;
   276 	scnew->file_pos = scold->file_pos;
   270 	scnew->ptr = NULL;
   277 	scnew->ptr = NULL;
   271 	scnew->id = scold->id;
   278 	scnew->id = scold->id;
       
   279 	scnew->real_sprite = scold->real_sprite;
   272 }
   280 }
   273 
   281 
   274 
   282 
   275 #define S_FREE_MASK 1
   283 #define S_FREE_MASK 1
   276 
   284 
   452 	sc->lru = ++_sprite_lru_counter;
   460 	sc->lru = ++_sprite_lru_counter;
   453 
   461 
   454 	p = sc->ptr;
   462 	p = sc->ptr;
   455 
   463 
   456 	/* Load the sprite, if it is not loaded, yet */
   464 	/* Load the sprite, if it is not loaded, yet */
   457 	if (p == NULL) p = ReadSprite(sc, sprite, real_sprite);
   465 	if (p == NULL || sc->real_sprite != real_sprite) p = ReadSprite(sc, sprite, real_sprite);
   458 
   466 
   459 	return p;
   467 	return p;
   460 }
   468 }
   461 
   469 
   462 
   470