Navigation Menu

Skip to content

Commit

Permalink
Refactor|ResourceSystem: Moved mobj visualization resource selection …
Browse files Browse the repository at this point in the history
…out of ResourceSystem

Sprite and model selection logic is now handled by Mobj_Sprite() and
Mobj_ModelDef() respectively. Sprite radius calculation was moved to
Sprite::visualRadius().

Plus some general resource system cleanup.
  • Loading branch information
danij-deng committed Dec 7, 2013
1 parent 74de24c commit 6e9d013
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 266 deletions.
53 changes: 29 additions & 24 deletions doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -37,9 +37,13 @@
#include "Sprite"
#include "Texture"
#include "TextureScheme"
#include "uri.hh"
#include <de/Error>
#include <de/String>
#include <de/System>
#include <QList>
#include <QMap>
#include <QSet>

/**
* Logical resources; materials, packages, textures, etc...
Expand Down Expand Up @@ -95,8 +99,8 @@ class ResourceSystem : public de::System
DENG2_ERROR(UnknownMaterialIdError);

#ifdef __CLIENT__
/// An unknown model def was referenced. @ingroup errors
DENG2_ERROR(UnknownModelDefError);
/// The referenced model def was not found. @ingroup errors
DENG2_ERROR(MissingModelDefError);

/// The specified font id was invalid (out of range). @ingroup errors
DENG2_ERROR(UnknownFontIdError);
Expand All @@ -122,7 +126,7 @@ class ResourceSystem : public de::System
public:
/**
* Construct a new resource system, configuring all resource classes and
* their collections.
* the associated resource collection schemes.
*/
ResourceSystem();

Expand Down Expand Up @@ -174,10 +178,9 @@ class ResourceSystem : public de::System
*/
int spriteCount();

patchid_t declarePatch(de::String encodedName);

/**
* Determines if a material exists for a @a path.
*
* @return @c true if a material exists; otherwise @a false.
*
* @see hasMaterialManifest(), MaterialManifest::hasMaterial()
Expand Down Expand Up @@ -210,6 +213,7 @@ class ResourceSystem : public de::System

/**
* Determines if a manifest exists for a material on @a path.
*
* @return @c true if a manifest exists; otherwise @a false.
*/
bool hasMaterialManifest(de::Uri const &path) const;
Expand Down Expand Up @@ -269,10 +273,8 @@ class ResourceSystem : public de::System
*
* @see allMaterialSchemes(), MaterialScheme::clear().
*/
inline void clearAllMaterialSchemes()
{
foreach(de::MaterialScheme *scheme, allMaterialSchemes())
{
inline void clearAllMaterialSchemes() {
foreach(de::MaterialScheme *scheme, allMaterialSchemes()) {
scheme->clear();
}
}
Expand Down Expand Up @@ -311,8 +313,7 @@ class ResourceSystem : public de::System
*
* @return Manifest for this URI.
*/
inline de::MaterialManifest &declareMaterial(de::Uri const &uri)
{
inline de::MaterialManifest &declareMaterial(de::Uri const &uri) {
return materialScheme(uri.scheme()).declare(uri.path());
}

Expand All @@ -324,6 +325,7 @@ class ResourceSystem : public de::System

/**
* Determines if a texture exists for @a path.
*
* @return @c true, if a texture exists; otherwise @a false.
*
* @see hasTextureManifest(), TextureManifest::hasTexture()
Expand Down Expand Up @@ -367,6 +369,7 @@ class ResourceSystem : public de::System

/**
* Determines if a texture manifest exists for a declared texture on @a path.
*
* @return @c true, if a manifest exists; otherwise @a false.
*/
bool hasTextureManifest(de::Uri const &path) const;
Expand Down Expand Up @@ -455,9 +458,12 @@ class ResourceSystem : public de::System
de::Texture *defineTexture(de::String schemeName, de::Uri const &resourceUri,
de::Vector2i const &dimensions = de::Vector2i());

patchid_t declarePatch(de::String encodedName);

#ifdef __CLIENT__
/**
* Determines if a manifest exists for a resource on @a path.
*
* @return @c true, if a manifest exists; otherwise @a false.
*/
bool hasFont(de::Uri const &path) const;
Expand Down Expand Up @@ -568,7 +574,8 @@ class ResourceSystem : public de::System
Model &model(modelid_t id);

/**
* Determines if a model definition exists with the given @a id.
* Determines if a model definition exists with the given @a id. O(n)
*
* @return @c true, if a definition exists; otherwise @a false.
*
* @see modelDef()
Expand Down Expand Up @@ -597,21 +604,14 @@ class ResourceSystem : public de::System
* Lookup a model definition for the specified mobj @a stateIndex.
*
* @param stateIndex Index of the mobj state.
* @param select Model selector argument. There may be multiple models for
* a given mobj state. The selector determines which is used
* according to some external selection criteria.
* @param select Model selector argument. There may be multiple models
* for a given mobj state. The selector determines which
* is used according to some external selection criteria.
*
* @return Found model definition; otherwise @c 0.
*/
ModelDef *modelDefForState(int stateIndex, int select = 0);

/**
* Is there a model for this mobj? The decision is made based on the state and tics
* of the mobj. Returns the modeldefs that are in effect at the moment (interlinks
* checked appropriately).
*/
float modelDefForMobj(struct mobj_s const *mo, ModelDef **mdef, ModelDef **nextmdef);

/**
* Returns the total number of model definitions in the system.
*
Expand Down Expand Up @@ -787,9 +787,14 @@ class ResourceSystem : public de::System
/**
* Rewind all material animations back to their initial/starting state.
*
* @see Materials::all(), MaterialVariant::restartAnimation()
* @see allMaterials(), MaterialAnimation::restart()
*/
void restartAllMaterialAnimations();
inline void restartAllMaterialAnimations() {
foreach(Material *material, allMaterials())
foreach(MaterialAnimation *animation, material->animations()) {
animation->restart();
}
}

/**
* Prepare resources for the current Map.
Expand Down
7 changes: 7 additions & 0 deletions doomsday/client/include/resource/sprite.h
Expand Up @@ -112,6 +112,13 @@ class Sprite
ViewAngles const &viewAngles() const;

#ifdef __CLIENT__
/**
* Returns the radius of the sprite as it would visually appear to be.
*
* @note Presently considers rotation 0 only!
*/
double visualRadius() const;

/**
* Produce a luminous object from the sprite configuration. The properties
* of any resultant lumobj are configured in "sprite-local" space. This means
Expand Down
30 changes: 26 additions & 4 deletions doomsday/client/include/world/p_object.h
Expand Up @@ -25,11 +25,13 @@
# error Attempted to include internal Doomsday p_object.h from a game
#endif

#include <de/aabox.h>

#include <de/Vector>

#ifdef __CLIENT__
# include "ModelDef"
# include "Sprite"
#endif
#include "Sector"
#include <de/Vector>
#include <de/aabox.h>

class BspLeaf;
class Plane;
Expand Down Expand Up @@ -161,6 +163,26 @@ void Mobj_GenerateLumobjs(mobj_t *mobj);
*/
float Mobj_ShadowStrength(mobj_t *mobj);

/**
* Determines which of the available sprites is in effect for the current mobj
* state and frame. May return @c 0 if the state and/or frame is not valid.
*/
Sprite *Mobj_Sprite(mobj_t const &mobj);

/**
* Determines which of the available model definitions (if any), are in effect
* for the current mobj state and frame. (Interlinks are resolved).
*
* @param nextModef If non-zero the model definition for the @em next frame is
* written here.
* @param interp If non-zero and both model definitions are found the current
* interpolation point between the two is written here.
*
* @return Active model definition for the current frame (if any).
*/
ModelDef *Mobj_ModelDef(mobj_t const &mobj, ModelDef **nextModef = 0,
float *interp = 0);

#endif // __CLIENT__

coord_t Mobj_ApproxPointDistance(mobj_t *start, coord_t const *point);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/def_main.cpp
Expand Up @@ -1926,7 +1926,7 @@ void Def_PostInit()
st->endFrame = -1;
}
}
catch(ResourceSystem::UnknownModelDefError const &)
catch(ResourceSystem::MissingModelDefError const &)
{} // Ignore this error.
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/r_main.cpp
Expand Up @@ -1021,7 +1021,7 @@ void R_SetupPlayerSprites()
dummy.state = psp->statePtr;
dummy.tics = psp->tics;

inter = App_ResourceSystem().modelDefForMobj(&dummy, &mf, &nextmf);
mf = Mobj_ModelDef(dummy, &nextmf, &inter);
if(mf) isModel = true;
}

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/r_things.cpp
Expand Up @@ -175,7 +175,7 @@ void R_ProjectSprite(mobj_t *mo)
// ...in an invalid state?
if(!mo->state || mo->state == states) return;
// ...no sprite frame is defined?
Sprite *sprite = App_ResourceSystem().spritePtr(mo->sprite, mo->frame);
Sprite *sprite = Mobj_Sprite(*mo);
if(!sprite) return;
// ...fully transparent?
float const alpha = Mobj_Alpha(mo);
Expand All @@ -193,7 +193,7 @@ void R_ProjectSprite(mobj_t *mo)
float interp = 0;
if(useModels)
{
interp = App_ResourceSystem().modelDefForMobj(mo, &mf, &nextmf);
mf = Mobj_ModelDef(*mo, &nextmf, &interp);
if(mf)
{
// Use a sprite if the object is beyond the maximum model distance.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2843,7 +2843,7 @@ static int projectSpriteWorker(mobj_t &mo, void * /*context*/)

if(cluster.visCeiling().surface().hasSkyMaskedMaterial())
{
if(Sprite *sprite = App_ResourceSystem().spritePtr(mo.sprite, mo.frame))
if(Sprite *sprite = Mobj_Sprite(mo))
{
if(sprite->hasViewAngle(0))
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/sky.cpp
Expand Up @@ -355,7 +355,7 @@ static void setupSkyModels(ded_sky_t *def)
sm->yaw = modef->yaw;
sm->frame = sm->model->subModelDef(0).frame;
}
catch(ResourceSystem::UnknownModelDefError const &)
catch(ResourceSystem::MissingModelDefError const &)
{} // Ignore this error.
}
}
Expand Down

0 comments on commit 6e9d013

Please sign in to comment.