diff options
author | Henry Wilson <m3henry@googlemail.com> | 2019-04-10 22:07:06 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-10 23:22:20 +0200 |
commit | 7c8e7c6b6e16d4a26259a676db32d8776b99817e (patch) | |
tree | 99f134b7e66367cf11e10bc5061896eab4a3264f /src/spritecache.cpp | |
parent | 3b4f224c0bc50e7248050d4bcbb6d83fd510c1cc (diff) | |
download | openttd-7c8e7c6b6e16d4a26259a676db32d8776b99817e.tar.xz |
Codechange: Use null pointer literal instead of the NULL macro
Diffstat (limited to 'src/spritecache.cpp')
-rw-r--r-- | src/spritecache.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 8a5a25ac0..bed8c42e3 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -44,7 +44,7 @@ struct SpriteCache { static uint _spritecache_items = 0; -static SpriteCache *_spritecache = NULL; +static SpriteCache *_spritecache = nullptr; static inline SpriteCache *GetSpriteCache(uint index) @@ -424,7 +424,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty } if (sprite_avail == 0) { - if (sprite_type == ST_MAPGEN) return NULL; + if (sprite_type == ST_MAPGEN) return nullptr; if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't load the fallback sprite. What should I do?"); return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator); } @@ -535,7 +535,7 @@ bool LoadNextSprite(int load_index, byte file_slot, uint file_sprite_id, byte co byte grf_type = FioReadByte(); SpriteType type; - void *data = NULL; + void *data = nullptr; if (grf_type == 0xFF) { /* Some NewGRF files have "empty" pseudo-sprites which are 1 * byte long. Catch these so the sprites won't be displayed. */ @@ -595,7 +595,7 @@ void DupSprite(SpriteID old_spr, SpriteID new_spr) scnew->file_slot = scold->file_slot; scnew->file_pos = scold->file_pos; - scnew->ptr = NULL; + scnew->ptr = nullptr; scnew->id = scold->id; scnew->type = scold->type; scnew->warned = false; @@ -643,7 +643,7 @@ void IncreaseSpriteLRU() for (i = 0; i != _spritecache_items; i++) { SpriteCache *sc = GetSpriteCache(i); - if (sc->ptr != NULL) { + if (sc->ptr != nullptr) { if (sc->lru >= 0) { sc->lru = -1; } else if (sc->lru != -32768) { @@ -715,7 +715,7 @@ static void DeleteEntryFromSpriteCache(uint item) MemBlock *s = (MemBlock*)GetSpriteCache(item)->ptr - 1; assert(!(s->size & S_FREE_MASK)); s->size |= S_FREE_MASK; - GetSpriteCache(item)->ptr = NULL; + GetSpriteCache(item)->ptr = nullptr; /* And coalesce adjacent free blocks */ for (s = _spritecache_ptr; s->size != 0; s = NextBlock(s)) { @@ -737,7 +737,7 @@ static void DeleteEntryFromSpriteCache() cur_lru = 0xffff; for (SpriteID i = 0; i != _spritecache_items; i++) { SpriteCache *sc = GetSpriteCache(i); - if (sc->type != ST_RECOLOUR && sc->ptr != NULL && sc->lru < cur_lru) { + if (sc->type != ST_RECOLOUR && sc->ptr != nullptr && sc->lru < cur_lru) { cur_lru = sc->lru; best = i; } @@ -807,7 +807,7 @@ static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, S SpriteType available = sc->type; if (requested == ST_FONT && available == ST_NORMAL) { - if (sc->ptr == NULL) sc->type = ST_FONT; + if (sc->ptr == nullptr) sc->type = ST_FONT; return GetRawSprite(sprite, sc->type, allocator); } @@ -837,7 +837,7 @@ static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, S * If the sprite is not available or of wrong type, a fallback sprite is returned. * @param sprite Sprite to read. * @param type Expected sprite type. - * @param allocator Allocator function to use. Set to NULL to use the usual sprite cache. + * @param allocator Allocator function to use. Set to nullptr to use the usual sprite cache. * @return Sprite raw data */ void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator) @@ -856,14 +856,14 @@ void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator) if (sc->type != type) return HandleInvalidSpriteRequest(sprite, type, sc, allocator); - if (allocator == NULL) { + if (allocator == nullptr) { /* Load sprite into/from spritecache */ /* Update LRU */ sc->lru = ++_sprite_lru_counter; /* Load the sprite, if it is not loaded, yet */ - if (sc->ptr == NULL) sc->ptr = ReadSprite(sc, sprite, type, AllocSprite); + if (sc->ptr == nullptr) sc->ptr = ReadSprite(sc, sprite, type, AllocSprite); return sc->ptr; } else { @@ -882,7 +882,7 @@ static void GfxInitSpriteCache() /* Remember 'target_size' from the previous allocation attempt, so we do not try to reach the target_size multiple times in case of failure. */ static uint last_alloc_attempt = 0; - if (_spritecache_ptr == NULL || (_allocated_sprite_cache_size != target_size && target_size != last_alloc_attempt)) { + if (_spritecache_ptr == nullptr || (_allocated_sprite_cache_size != target_size && target_size != last_alloc_attempt)) { delete[] reinterpret_cast<byte *>(_spritecache_ptr); last_alloc_attempt = target_size; @@ -893,10 +893,10 @@ static void GfxInitSpriteCache() /* Try to allocate 50% more to make sure we do not allocate almost all available. */ _spritecache_ptr = reinterpret_cast<MemBlock *>(new byte[_allocated_sprite_cache_size + _allocated_sprite_cache_size / 2]); } catch (std::bad_alloc &) { - _spritecache_ptr = NULL; + _spritecache_ptr = nullptr; } - if (_spritecache_ptr != NULL) { + if (_spritecache_ptr != nullptr) { /* Allocation succeeded, but we wanted less. */ delete[] reinterpret_cast<byte *>(_spritecache_ptr); _spritecache_ptr = reinterpret_cast<MemBlock *>(new byte[_allocated_sprite_cache_size]); @@ -906,7 +906,7 @@ static void GfxInitSpriteCache() /* Try again to allocate half. */ _allocated_sprite_cache_size >>= 1; } - } while (_spritecache_ptr == NULL); + } while (_spritecache_ptr == nullptr); if (_allocated_sprite_cache_size != target_size) { DEBUG(misc, 0, "Not enough memory to allocate %d MiB of spritecache. Spritecache was reduced to %d MiB.", target_size / 1024 / 1024, _allocated_sprite_cache_size / 1024 / 1024); @@ -931,7 +931,7 @@ void GfxInitSpriteMem() /* Reset the spritecache 'pool' */ free(_spritecache); _spritecache_items = 0; - _spritecache = NULL; + _spritecache = nullptr; _compact_cache_counter = 0; } @@ -945,7 +945,7 @@ void GfxClearSpriteCache() /* Clear sprite ptr for all cached items */ for (uint i = 0; i != _spritecache_items; i++) { SpriteCache *sc = GetSpriteCache(i); - if (sc->type != ST_RECOLOUR && sc->ptr != NULL) DeleteEntryFromSpriteCache(i); + if (sc->type != ST_RECOLOUR && sc->ptr != nullptr) DeleteEntryFromSpriteCache(i); } } |