Skip to content

Commit

Permalink
Cleanup: Return a reference from App_Materials()
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jan 18, 2013
1 parent 9d06380 commit eb5e771
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 82 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/include/dd_main.h
Expand Up @@ -198,7 +198,7 @@ de::ResourceClass& DD_ResourceClassByName(de::String name);
de::String DD_MaterialSchemeNameForTextureScheme(de::String textureSchemeName);

/// @return The application's global Material collection.
de::Materials *App_Materials();
de::Materials &App_Materials();

extern "C" {
#endif // __cplusplus
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/src/dd_main.cpp
Expand Up @@ -576,15 +576,15 @@ void DD_ClearSystemTextureSchemes()
GL_PruneTextureVariantSpecifications();
}

Materials *App_Materials()
Materials &App_Materials()
{
if(!materials) throw Error("App_Materials", "Materials collection not yet initialized");
return materials;
return *materials;
}

void DD_CreateMaterialSchemes()
{
Materials &materials = *App_Materials();
Materials &materials = App_Materials();

materials.createScheme("System");
materials.createScheme("Flats");
Expand Down Expand Up @@ -2274,7 +2274,7 @@ void DD_UpdateEngineState(void)
gx.UpdateState(DD_POST);

// Reset the material animations.
App_Materials()->resetAllMaterialAnimations();
App_Materials().resetAllMaterialAnimations();
}

/* *INDENT-OFF* */
Expand Down
9 changes: 7 additions & 2 deletions doomsday/engine/src/dd_pinit.cpp
Expand Up @@ -181,10 +181,15 @@ void DD_ShutdownAll(void)
P_ControlShutdown();
Sv_Shutdown();
R_Shutdown();
if(de::Materials *materials = App_Materials())

// Ensure the global material collection is destroyed.
try
{
delete materials;
delete &App_Materials();
}
catch(de::Error const &)
{} // Ignore this error.

Def_Destroy();
F_Shutdown();
DD_ClearResourceClasses();
Expand Down
26 changes: 13 additions & 13 deletions doomsday/engine/src/def_main.cpp
Expand Up @@ -1030,7 +1030,7 @@ void Def_Read()
FS1::Scheme &scheme = App_FileSystem()->scheme(DD_ResourceClassByName("RC_MODEL").defaultScheme());
scheme.reset();

App_Materials()->clearDefinitionLinks();
App_Materials().clearDefinitionLinks();
Fonts_ClearDefinitionLinks();

Def_Destroy();
Expand Down Expand Up @@ -1202,17 +1202,17 @@ void Def_Read()

try
{
MaterialManifest &bind = App_Materials()->find(*reinterpret_cast<de::Uri *>(def->uri));
MaterialManifest &bind = App_Materials().find(*reinterpret_cast<de::Uri *>(def->uri));
if(Material *mat = bind.material())
{
// Update existing.
App_Materials()->rebuild(*mat, def);
App_Materials().rebuild(*mat, def);
}
}
catch(Materials::NotFoundError const &)
{
// A new Material.
App_Materials()->newFromDef(*def);
App_Materials().newFromDef(*def);
}
}

Expand Down Expand Up @@ -1436,28 +1436,28 @@ static void initMaterialGroup(ded_group_t *def)

try
{
Material *mat = App_Materials()->find(*reinterpret_cast<de::Uri *>(gm->material)).material();
Material *mat = App_Materials().find(*reinterpret_cast<de::Uri *>(gm->material)).material();

if(def->flags & AGF_PRECACHE) // A precache group.
{
// Only create the group once the first material has been found.
if(groupNumber == -1)
{
groupNumber = App_Materials()->newGroup();
groupNumber = App_Materials().newGroup();
}

App_Materials()->group(groupNumber).addMaterial(*mat);
App_Materials().group(groupNumber).addMaterial(*mat);
}
#if 0 /// @todo $revise-texture-animation
else // An animation group.
{
// Only create the group once the first material has been found.
if(animNumber == -1)
{
animNumber = App_Materials()->newAnimGroup(def->flags & ~AGF_PRECACHE);
animNumber = App_Materials().newAnimGroup(def->flags & ~AGF_PRECACHE);
}

App_Materials()->animGroup(animNumber).addFrame(*mat, gm->tics, gm->randomTics);
App_Materials().animGroup(animNumber).addFrame(*mat, gm->tics, gm->randomTics);
}
#endif
}
Expand Down Expand Up @@ -1602,7 +1602,7 @@ void Def_PostInit(void)
}

// Material groups (e.g., for precaching).
App_Materials()->clearAllGroups();
App_Materials().clearAllGroups();
for(int i = 0; i < defs.count.groups.num; ++i)
{
initMaterialGroup(&defs.groups[i]);
Expand Down Expand Up @@ -1692,14 +1692,14 @@ void Def_CopyLineType(linetype_t* l, ded_linetype_t* def)

try
{
l->actMaterial = App_Materials()->find(*reinterpret_cast<de::Uri *>(def->actMaterial)).id();
l->actMaterial = App_Materials().find(*reinterpret_cast<de::Uri *>(def->actMaterial)).id();
}
catch(Materials::NotFoundError const &)
{} // Ignore this error.

try
{
l->deactMaterial = App_Materials()->find(*reinterpret_cast<de::Uri *>(def->deactMaterial)).id();
l->deactMaterial = App_Materials().find(*reinterpret_cast<de::Uri *>(def->deactMaterial)).id();
}
catch(Materials::NotFoundError const &)
{} // Ignore this error.
Expand Down Expand Up @@ -1737,7 +1737,7 @@ void Def_CopyLineType(linetype_t* l, ded_linetype_t* def)
{
try
{
l->iparm[k] = App_Materials()->find(de::Uri(def->iparmStr[k], RC_NULL)).id();
l->iparm[k] = App_Materials().find(de::Uri(def->iparmStr[k], RC_NULL)).id();
}
catch(Materials::NotFoundError const &)
{} // Ignore this error.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/edit_map.cpp
Expand Up @@ -1809,15 +1809,15 @@ static void assignSurfaceMaterial(Surface *suf, ddstring_t const *materialUriStr
// First try the preferred scheme, then any.
try
{
material = App_Materials()->find(materialUri).material();
material = App_Materials().find(materialUri).material();
}
catch(Materials::NotFoundError const &)
{
// Try any scheme.
try
{
materialUri.setScheme("");
material = App_Materials()->find(materialUri).material();
material = App_Materials().find(materialUri).material();
}
catch(Materials::NotFoundError const &)
{}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/gl/gl_main.cpp
Expand Up @@ -746,7 +746,7 @@ void GL_SetMaterialUI2(Material *mat, int wrapS, int wrapT)
if(!mat) return; // @todo we need a "NULL material".

MaterialVariantSpec const &spec =
App_Materials()->variantSpecForContext(MC_UI, 0, 1, 0, 0, wrapS, wrapT,
App_Materials().variantSpecForContext(MC_UI, 0, 1, 0, 0, wrapS, wrapT,
0, 1, 0, false, false, false, false);
GL_BindTexture(reinterpret_cast<texturevariant_s *>(&mat->prepare(spec).texture(MTU_PRIMARY)));
}
Expand All @@ -761,7 +761,7 @@ void GL_SetPSprite(Material *mat, int tClass, int tMap)
if(!mat) return; // @todo we need a "NULL material".

MaterialVariantSpec const &spec =
App_Materials()->variantSpecForContext(MC_PSPRITE, 0, 1, tClass, tMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
App_Materials().variantSpecForContext(MC_PSPRITE, 0, 1, tClass, tMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
0, 1, 0, false, true, true, false);
GL_BindTexture(reinterpret_cast<texturevariant_s *>(&mat->prepare(spec).texture(MTU_PRIMARY)));
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/map/p_data.cpp
Expand Up @@ -178,7 +178,7 @@ DENG_EXTERN_C boolean P_LoadMap(char const* uriCString)
R_ResetViewer();

// Material animations should begin from their first step.
App_Materials()->resetAllMaterialAnimations();
App_Materials().resetAllMaterialAnimations();

R_InitObjlinkBlockmapForMap();

Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/map/p_dmu.cpp
Expand Up @@ -360,7 +360,7 @@ void *P_ToPtr(int type, uint index)
return 0; /* Unreachable. */ }

case DMU_MATERIAL:
if(Materials::Manifest *manifest = App_Materials()->toManifest(index))
if(Materials::Manifest *manifest = App_Materials().toManifest(index))
{
return manifest->material();
}
Expand Down Expand Up @@ -527,7 +527,7 @@ int P_Callback(int type, uint index, void *context, int (*callback)(void *p, voi
return 0; /* Unreachable */ }

case DMU_MATERIAL:
if(Materials::Manifest *manifest = App_Materials()->toManifest(index))
if(Materials::Manifest *manifest = App_Materials().toManifest(index))
{
return callback(manifest->material(), context);
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/map/p_particle.cpp
Expand Up @@ -1395,7 +1395,7 @@ static int findDefForGenerator(ptcgen_t *gen, void *parameters)
{
try
{
Material *defMat = App_Materials()->find(*reinterpret_cast<de::Uri const *>(def->material)).material();
Material *defMat = App_Materials().find(*reinterpret_cast<de::Uri const *>(def->material)).material();

Material *mat = gen->plane->PS_material;
if(def->flags & PGF_FLOOR_SPAWN)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/map/p_ticker.cpp
Expand Up @@ -122,7 +122,7 @@ int P_MobjTicker(thinker_t* th, void* context)
void P_Ticker(timespan_t time)
{
P_ControlTicker(time);
App_Materials()->ticker(time);
App_Materials().ticker(time);

if(!theMap || !GameMap_ThinkerListInited(theMap)) return; // Not initialized yet.

Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/src/map/r_world.cpp
Expand Up @@ -1133,7 +1133,7 @@ DENG_EXTERN_C void R_SetupMap(int mode, int flags)
// A new map is about to be setup.
ddMapSetup = true;

App_Materials()->purgeCacheQueue();
App_Materials().purgeCacheQueue();
return;

case DDSMM_AFTER_LOADING:
Expand Down Expand Up @@ -1175,7 +1175,7 @@ DENG_EXTERN_C void R_SetupMap(int mode, int flags)

float startTime = Timer_Seconds();
Rend_CacheForMap();
App_Materials()->processCacheQueue();
App_Materials().processCacheQueue();
VERBOSE( Con_Message("Precaching took %.2f seconds.\n", Timer_Seconds() - startTime) )

S_SetupForChangedMap();
Expand Down Expand Up @@ -1409,7 +1409,7 @@ static Material *chooseFixMaterial(SideDef *s, SideDefSection section)
if(choice2) return choice2;

// We'll assign the special "missing" material...
return App_Materials()->find(de::Uri("System", Path("missing"))).material();
return App_Materials().find(de::Uri("System", Path("missing"))).material();
}

static void addMissingMaterial(SideDef *s, SideDefSection section)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/render/r_draw.cpp
Expand Up @@ -176,7 +176,7 @@ void R_DrawPatchTiled(struct texture_s *_tex, int x, int y, int w, int h, int wr

MaterialVariantSpec const &Ui_MaterialSpec()
{
return App_Materials()->variantSpecForContext(MC_UI, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT,
return App_Materials().variantSpecForContext(MC_UI, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT,
0, -3, 0, false, false, false, false);
}

Expand Down Expand Up @@ -215,7 +215,7 @@ void R_DrawViewBorder()
glColor4f(1, 1, 1, 1);

// View background.
Material *mat = App_Materials()->find(*reinterpret_cast<de::Uri *>(borderGraphicsNames[BG_BACKGROUND])).material();
Material *mat = App_Materials().find(*reinterpret_cast<de::Uri *>(borderGraphicsNames[BG_BACKGROUND])).material();
if(mat)
{
MaterialSnapshot const &ms = mat->prepare(Ui_MaterialSpec());
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/src/render/r_main.cpp
Expand Up @@ -1308,7 +1308,7 @@ static void cacheSpritesForState(int stateIndex, MaterialVariantSpec const &spec
spriteframe_t *sprFrame = &sprDef->spriteFrames[i];
for(int k = 0; k < 8; ++k)
{
App_Materials()->cache(*sprFrame->mats[k], spec);
App_Materials().cache(*sprFrame->mats[k], spec);
}
}
}
Expand Down Expand Up @@ -1357,13 +1357,13 @@ void Rend_CacheForMap()
SideDef *side = SIDE_PTR(i);

if(side->SW_middlematerial)
App_Materials()->cache(*side->SW_middlematerial, spec);
App_Materials().cache(*side->SW_middlematerial, spec);

if(side->SW_topmaterial)
App_Materials()->cache(*side->SW_topmaterial, spec);
App_Materials().cache(*side->SW_topmaterial, spec);

if(side->SW_bottommaterial)
App_Materials()->cache(*side->SW_bottommaterial, spec);
App_Materials().cache(*side->SW_bottommaterial, spec);
}

for(uint i = 0; i < NUM_SECTORS; ++i)
Expand All @@ -1374,7 +1374,7 @@ void Rend_CacheForMap()
for(uint k = 0; k < sec->planeCount; ++k)
{
if(sec->SP_planematerial(k))
App_Materials()->cache(*sec->SP_planematerial(k), spec);
App_Materials().cache(*sec->SP_planematerial(k), spec);
}
}
}
Expand All @@ -1399,7 +1399,7 @@ void Rend_CacheForMap()
spriteframe_t *sprFrame = &sprDef->spriteFrames[k];
for(int m = 0; m < 8; ++m)
{
App_Materials()->cache(*sprFrame->mats[m], spec);
App_Materials().cache(*sprFrame->mats[m], spec);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/render/r_things.cpp
Expand Up @@ -212,7 +212,7 @@ static void buildSprite(TextureManifest &manifest)
link = true;
}

frame->mat = App_Materials()->find(de::Uri("Sprites", manifest.path())).material();
frame->mat = App_Materials().find(de::Uri("Sprites", manifest.path())).material();
frame->frame[0] = frameNumber;
frame->rotation[0] = rotationNumber;

Expand Down Expand Up @@ -456,7 +456,7 @@ DENG_EXTERN_C boolean R_GetSpriteInfo(int sprite, int frame, spriteinfo_t *info)

/// @todo fixme: We should not be using the PSprite spec here. -ds
MaterialVariantSpec const &spec =
App_Materials()->variantSpecForContext(MC_PSPRITE, 0, 1, 0, 0,
App_Materials().variantSpecForContext(MC_PSPRITE, 0, 1, 0, 0,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, 1, -1,
false, true, true, false);
MaterialSnapshot const &ms = mat->prepare(spec);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/render/rend_console.cpp
Expand Up @@ -292,7 +292,7 @@ void Rend_ConsoleUpdateBackground()

try
{
consoleBackgroundMaterial = App_Materials()->find(*reinterpret_cast<de::Uri *>(consoleBackgroundMaterialUri)).material();
consoleBackgroundMaterial = App_Materials().find(*reinterpret_cast<de::Uri *>(consoleBackgroundMaterialUri)).material();
}
catch(Materials::NotFoundError const &)
{
Expand Down Expand Up @@ -556,7 +556,7 @@ static void drawConsoleBackground(Point2Raw const *origin, Size2Raw const *size,
if(consoleBackgroundMaterial)
{
MaterialVariantSpec const &spec =
App_Materials()->variantSpecForContext(MC_UI, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT,
App_Materials().variantSpecForContext(MC_UI, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT,
0, 1, 0, false, false, false, false);
MaterialSnapshot const &ms = consoleBackgroundMaterial->prepare(spec);

Expand Down

0 comments on commit eb5e771

Please sign in to comment.