Skip to content

Commit

Permalink
ResourceSystem: Ensure sprite sets are accessed in const mode
Browse files Browse the repository at this point in the history
Only the ResourceSystem should have write access to the sprite sets.
Creating a new set should happen through the public API only.
  • Loading branch information
danij-deng committed Nov 21, 2013
1 parent 63864cd commit 51e7f8d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -138,7 +138,7 @@ class ResourceSystem : public de::System
* @see hasSprite()
*/
inline Sprite *spritePtr(spritenum_t spriteId, int frame) {
return hasSprite(spriteId, frame)? spriteSet(spriteId)[frame] : 0;
return hasSprite(spriteId, frame)? spriteSet(spriteId).at(frame) : 0;
}

/**
Expand All @@ -147,7 +147,7 @@ class ResourceSystem : public de::System
* @param spriteId Unique identifier of the sprite set.
* @return The identified SpriteSet.
*/
SpriteSet &spriteSet(spritenum_t spriteId);
SpriteSet const &spriteSet(spritenum_t spriteId);

#ifdef __CLIENT__
/**
Expand Down
4 changes: 3 additions & 1 deletion doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -679,7 +679,7 @@ bool ResourceSystem::hasSprite(spritenum_t spriteId, int frame)
return false;
}

ResourceSystem::SpriteSet &ResourceSystem::spriteSet(spritenum_t spriteId)
ResourceSystem::SpriteSet const &ResourceSystem::spriteSet(spritenum_t spriteId)
{
if(Instance::SpriteGroup *group = d->spriteGroup(spriteId))
{
Expand Down Expand Up @@ -1451,6 +1451,7 @@ void ResourceSystem::initSprites()
foreach(SpriteFrameDef const &frameDef, def.frames)
{
int frame = frameDef.frame[0] - 1;
DENG2_ASSERT(frame >= 0);
if(frame < 128)
{
sprTemp[frame].newViewAngle(frameDef.mat, frameDef.rotation[0], false);
Expand All @@ -1463,6 +1464,7 @@ void ResourceSystem::initSprites()
if(frameDef.frame[1])
{
frame = frameDef.frame[1] - 1;
DENG2_ASSERT(frame >= 0);
if(frame < 128)
{
sprTemp[frame].newViewAngle(frameDef.mat, frameDef.rotation[1], true);
Expand Down

0 comments on commit 51e7f8d

Please sign in to comment.