Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Moved AnimGroups from ClientResources to libdoomsday
- Loading branch information
Showing
10 changed files
with
194 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
doomsday/apps/libdoomsday/include/doomsday/resource/animgroups.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** @file animgroups.h | ||
* | ||
* @authors Copyright © 2005-2015 Daniel Swanson <danij@dengine.net> | ||
* @authors Copyright © 2016 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBDOOMSDAY_RESOURCE_ANIMGROUPS_H | ||
#define LIBDOOMSDAY_RESOURCE_ANIMGROUPS_H | ||
|
||
#include "../libdoomsday.h" | ||
#include <de/libcore.h> | ||
#include "animgroup.h" | ||
|
||
namespace res { | ||
|
||
class AnimGroup; | ||
class TextureManifest; | ||
|
||
class LIBDOOMSDAY_PUBLIC AnimGroups | ||
{ | ||
public: | ||
static AnimGroups &get(); | ||
|
||
public: | ||
AnimGroups(); | ||
|
||
/** | ||
* Returns the total number of animation/precache groups. | ||
*/ | ||
de::dint animGroupCount(); | ||
|
||
/** | ||
* Destroys all the animation groups. | ||
*/ | ||
void clearAllAnimGroups(); | ||
|
||
/** | ||
* Construct a new animation group. | ||
* | ||
* @param flags @ref animationGroupFlags | ||
*/ | ||
AnimGroup &newAnimGroup(de::dint flags); | ||
|
||
/** | ||
* Returns the AnimGroup associated with @a uniqueId (1-based); otherwise @c 0. | ||
*/ | ||
AnimGroup *animGroup(de::dint uniqueId); | ||
|
||
AnimGroup *animGroupForTexture(TextureManifest const &textureManifest); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace res | ||
|
||
#endif // LIBDOOMSDAY_RESOURCE_ANIMGROUPS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** @file animgroups.cpp | ||
* | ||
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#include "doomsday/resource/animgroups.h" | ||
#include "doomsday/resource/resources.h" | ||
|
||
#include <de/Log> | ||
#include <QList> | ||
|
||
namespace res { | ||
|
||
using namespace de; | ||
|
||
DENG2_PIMPL_NOREF(AnimGroups) | ||
{ | ||
QList<res::AnimGroup *> animGroups; | ||
|
||
~Impl() | ||
{ | ||
clearAllAnimGroups(); | ||
} | ||
|
||
void clearAllAnimGroups() | ||
{ | ||
qDeleteAll(animGroups); | ||
animGroups.clear(); | ||
} | ||
}; | ||
|
||
AnimGroups &AnimGroups::get() | ||
{ | ||
return Resources::get().animGroups(); | ||
} | ||
|
||
AnimGroups::AnimGroups() : d(new Impl) | ||
{} | ||
|
||
dint AnimGroups::animGroupCount() | ||
{ | ||
return d->animGroups.count(); | ||
} | ||
|
||
void AnimGroups::clearAllAnimGroups() | ||
{ | ||
d->clearAllAnimGroups(); | ||
} | ||
|
||
res::AnimGroup &AnimGroups::newAnimGroup(dint flags) | ||
{ | ||
LOG_AS("AnimGroups"); | ||
dint const uniqueId = d->animGroups.count() + 1; // 1-based. | ||
// Allocating one by one is inefficient but it doesn't really matter. | ||
d->animGroups.append(new res::AnimGroup(uniqueId, flags)); | ||
return *d->animGroups.last(); | ||
} | ||
|
||
res::AnimGroup *AnimGroups::animGroup(dint uniqueId) | ||
{ | ||
LOG_AS("AnimGroups::animGroup"); | ||
if (uniqueId > 0 && uniqueId <= d->animGroups.count()) | ||
{ | ||
return d->animGroups.at(uniqueId - 1); | ||
} | ||
LOGDEV_RES_WARNING("Invalid group #%i, returning NULL") << uniqueId; | ||
return nullptr; | ||
} | ||
|
||
res::AnimGroup *AnimGroups::animGroupForTexture(res::TextureManifest const &textureManifest) | ||
{ | ||
// Group ids are 1-based. | ||
// Search backwards to allow patching. | ||
for (dint i = animGroupCount(); i > 0; i--) | ||
{ | ||
res::AnimGroup *group = animGroup(i); | ||
if (group->hasFrameFor(textureManifest)) | ||
{ | ||
return group; | ||
} | ||
} | ||
return nullptr; // Not found. | ||
} | ||
|
||
} // namespace res |
Oops, something went wrong.