Skip to content

Commit

Permalink
Refactor|Resources: Moved Rend_CacheForMap() into ResourceSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 21, 2013
1 parent 4cb513c commit bffe4dd
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 164 deletions.
9 changes: 6 additions & 3 deletions doomsday/client/include/def_main.h
Expand Up @@ -88,9 +88,12 @@ void Def_ReadProcessDED(const char* fileName);
int Def_GetMobjNum(const char* id);
int Def_GetMobjNumForName(const char* name);
const char* Def_GetMobjName(int num);
int Def_GetStateNum(const char* id);
const char* Def_GetStateName(state_t* state);
int Def_GetActionNum(const char* id);

state_t *Def_GetState(int num);
int Def_GetStateNum(char const *id);
char const *Def_GetStateName(state_t *state);

int Def_GetActionNum(char const *id);

/**
* Returns the unique sprite number associated with the specified sprite @a name;
Expand Down
5 changes: 0 additions & 5 deletions doomsday/client/include/render/r_main.h
Expand Up @@ -224,11 +224,6 @@ char const *R_ChooseFixedFont(void);
char const *R_ChooseVariableFont(fontstyle_t style, int resX, int resY);
#endif

/**
* Prepare resources for the current Map.
*/
void Rend_CacheForMap(void);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
14 changes: 0 additions & 14 deletions doomsday/client/include/resource/materials.h
Expand Up @@ -229,20 +229,6 @@ class Materials
All const &all() const;

#ifdef __CLIENT__
/**
* Rewind all material animations back to their initial/starting state.
*
* @see all(), MaterialVariant::restartAnimation()
*/
inline void restartAllAnimations() const
{
foreach(Material *material, all())
foreach(MaterialAnimation *animation, material->animations())
{
animation->restart();
}
}

/**
* Prepare a material variant specification in accordance to the specified
* usage context. If incomplete context information is supplied, suitable
Expand Down
26 changes: 26 additions & 0 deletions doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -273,6 +273,32 @@ class ResourceSystem : public de::System
*/
void setDefaultColorPalette(ColorPalette *newDefaultPalette);

#ifdef __CLIENT__

/**
* Rewind all material animations back to their initial/starting state.
*
* @see Materials::all(), MaterialVariant::restartAnimation()
*/
void restartAllMaterialAnimations();

/**
* Prepare resources for the current Map.
*/
void cacheForCurrentMap();

/**
* Process all queued cache tasks.
*/
void processCacheQueue();

/**
* Cancel all queued cache tasks.
*/
void purgeCacheQueue();

#endif // __CLIENT__

public: /// @todo Should be private:
void initCompositeTextures();
void initFlatTextures();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/resource/sprite.h
Expand Up @@ -55,7 +55,7 @@ class Sprite
static int const max_angles = 8;

/**
* One depiction of the sprite as if viewed from the associated angle.
* One depiction of the entity as if viewed from the associated angle.
*/
struct ViewAngle {
Material *material;
Expand Down
9 changes: 9 additions & 0 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -218,6 +218,15 @@ const char* Def_GetMobjName(int num)
return defs.mobjs[num].id;
}

state_t *Def_GetState(int num)
{
if(num >= 0 && num < defs.count.states.num)
{
return states + num;
}
return 0; // Not found.
}

int Def_GetStateNum(const char* id)
{
int idx = -1;
Expand Down
37 changes: 35 additions & 2 deletions doomsday/client/src/render/api_render.cpp
Expand Up @@ -2,13 +2,19 @@

#include "de_base.h"
#include "de_console.h"
#include "de_defs.h"

#include "api_render.h"
#include "render/r_main.h"
#include "render/billboard.h" // Rend_SpriteMaterialSpec

#include "resource/models.h"
#include "resource/sprite.h"
#ifdef __CLIENT__
# include "MaterialSnapshot"
# include "MaterialVariantSpec"
#endif
#include <de/Log>

// m_misc.c
DENG_EXTERN_C int M_ScreenShot(const char* name, int bits);
Expand All @@ -19,8 +25,35 @@ DENG_EXTERN_C void Models_CacheForState(int stateIndex);
// r_draw.cpp
DENG_EXTERN_C void R_SetBorderGfx(struct uri_s const *const *paths);

#undef Rend_CacheForMobjType
DENG_EXTERN_C void Rend_CacheForMobjType(int num)
{
LOG_AS("Rend.CacheForMobjType");

if(novideo || !((useModels && precacheSkins) || precacheSprites)) return;
if(num < 0 || num >= defs.count.mobjs.num) return;

de::MaterialVariantSpec const &spec = Rend_SpriteMaterialSpec();

/// @todo Optimize: Traverses the entire state list!
for(int i = 0; i < defs.count.states.num; ++i)
{
if(stateOwners[i] != &mobjInfo[num]) continue;

Models_CacheForState(i);

if(precacheSprites)
{
state_t *state = Def_GetState(i);
DENG2_ASSERT(state != 0);

App_ResourceSystem().cacheSpriteSet(state->sprite, spec);
}
/// @todo What about sounds?
}
}

// r_main.cpp
DENG_EXTERN_C void Rend_CacheForMobjType(int mobjtypeNum);
DENG_EXTERN_C void R_RenderPlayerView(int num);
DENG_EXTERN_C void R_SetViewOrigin(int consoleNum, coord_t const origin[3]);
DENG_EXTERN_C void R_SetViewAngle(int consoleNum, angle_t angle);
Expand All @@ -40,7 +73,7 @@ DENG_EXTERN_C void R_SkyParams(int layer, int param, void *data);
#undef R_GetSpriteInfo
DENG_EXTERN_C boolean R_GetSpriteInfo(int spriteId, int frame, spriteinfo_t *info)
{
LOG_AS("R_GetSpriteInfo");
LOG_AS("Rend.GetSpriteInfo");

if(!info) return false;

Expand Down
135 changes: 0 additions & 135 deletions doomsday/client/src/render/r_main.cpp
Expand Up @@ -1516,141 +1516,6 @@ void R_ViewerClipLumobjBySight(Lumobj *lum, BspLeaf *bspLeaf)
}
}

static state_t *toState(int index)
{
if(index >= 0 && index < defs.count.states.num)
{
return states + index;
}
return 0; // Not found.
}

static int findSpriteOwner(thinker_t *th, void *context)
{
mobj_t *mo = reinterpret_cast<mobj_t *>(th);
int const sprite = *static_cast<int *>(context);

if(mo->type >= 0 && mo->type < defs.count.mobjs.num)
{
/// @todo optimize: traverses the entire state list!
for(int i = 0; i < defs.count.states.num; ++i)
{
if(stateOwners[i] != &mobjInfo[mo->type])
{
continue;
}

state_t *state = toState(i);
DENG2_ASSERT(state != 0);

if(state->sprite == sprite)
{
return true; // Found one.
}
}
}

return false; // Continue iteration.
}

#undef Rend_CacheForMobjType
DENG_EXTERN_C void Rend_CacheForMobjType(int num)
{
if(novideo || !((useModels && precacheSkins) || precacheSprites)) return;
if(num < 0 || num >= defs.count.mobjs.num) return;

MaterialVariantSpec const &spec = Rend_SpriteMaterialSpec();

/// @todo Optimize: Traverses the entire state list!
for(int i = 0; i < defs.count.states.num; ++i)
{
if(stateOwners[i] != &mobjInfo[num]) continue;

Models_CacheForState(i);

if(precacheSprites)
{
state_t *state = toState(i);
DENG2_ASSERT(state != 0);

App_ResourceSystem().cacheSpriteSet(state->sprite, spec);
}
/// @todo What about sounds?
}
}

void Rend_CacheForMap()
{
// Don't precache when playing a demo (why not? -ds).
if(playback) return;

// Precaching from 100 to 200.
Con_SetProgress(100);

/// @todo fixme: Do not assume the current map.
Map &map = App_World().map();

if(precacheMapMaterials)
{
MaterialVariantSpec const &spec = Rend_MapSurfaceMaterialSpec();

foreach(Line *line, map.lines())
for(int i = 0; i < 2; ++i)
{
LineSide &side = line->side(i);
if(!side.hasSections()) continue;

if(side.middle().hasMaterial())
App_Materials().cache(side.middle().material(), spec);

if(side.top().hasMaterial())
App_Materials().cache(side.top().material(), spec);

if(side.bottom().hasMaterial())
App_Materials().cache(side.bottom().material(), spec);
}

foreach(Sector *sector, map.sectors())
{
// Skip sectors with no line sides as their planes will never be drawn.
if(!sector->sideCount()) continue;

foreach(Plane *plane, sector->planes())
{
if(plane->surface().hasMaterial())
App_Materials().cache(plane->surface().material(), spec);
}
}
}

if(precacheSprites)
{
MaterialVariantSpec const &spec = Rend_SpriteMaterialSpec();

for(int i = 0; i < App_ResourceSystem().spriteCount(); ++i)
{
if(map.thinkers().iterate(reinterpret_cast<thinkfunc_t>(gx.MobjThinker),
0x1/*mobjs are public*/,
findSpriteOwner, &i))
{
// This sprite is used by some state of at least one mobj.
App_ResourceSystem().cacheSpriteSet(i, spec);
}
}
}

// Sky models usually have big skins.
Sky_Cache();

// Precache model skins?
if(useModels && precacheSkins)
{
// All mobjs are public.
map.thinkers().iterate(reinterpret_cast<thinkfunc_t>(gx.MobjThinker), 0x1,
Models_CacheForMobj);
}
}

#endif // __CLIENT__

D_CMD(ViewGrid)
Expand Down

0 comments on commit bffe4dd

Please sign in to comment.