Skip to content

Commit

Permalink
Refactor|Fonts|Resources|Client: Continued remodeling Fonts collection
Browse files Browse the repository at this point in the history
Now builds without error. Testing begins...
  • Loading branch information
danij-deng committed Nov 15, 2013
1 parent 66ce9a3 commit d0d211a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 86 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/include/dd_main.h
Expand Up @@ -142,15 +142,15 @@ namespace de
* @param name Symbolic name of the type.
* @return FileType associated with @a name. May return a null-object.
*/
de::FileType& DD_FileTypeByName(de::String name);
de::FileType &DD_FileTypeByName(de::String name);

/**
* Attempts to determine which "type" should be attributed to a resource, solely
* by examining the name (e.g., a file name/path).
*
* @return Type determined for this resource. May return a null-object.
*/
de::FileType& DD_GuessFileTypeFromFileName(de::String name);
de::FileType &DD_GuessFileTypeFromFileName(de::String name);

/// Returns the registered file types for efficient traversal.
de::FileTypes const& DD_FileTypes();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/resource/compositebitmapfont.h
Expand Up @@ -60,7 +60,7 @@ class CompositeBitmapFont : public AbstractFont
*
* @todo Should observe engine reset.
*/
void rebuildFromDef(ded_compositefont_t *def);
void rebuildFromDef(ded_compositefont_t const &def);

int ascent();
int descent();
Expand Down
4 changes: 0 additions & 4 deletions doomsday/client/include/resource/fonts.h
Expand Up @@ -21,11 +21,7 @@
#ifndef DENG_RESOURCE_FONTS_H
#define DENG_RESOURCE_FONTS_H

#include "dd_share.h" // fontschemeid_t
#include "def_data.h"
#include "AbstractFont"
#include "BitmapFont"
#include "CompositeBitmapFont"
#include "uri.hh"
#include <de/Error>
#include <de/String>
Expand Down
6 changes: 4 additions & 2 deletions doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -19,13 +19,15 @@
#ifndef DENG_RESOURCESYSTEM_H
#define DENG_RESOURCESYSTEM_H

#include "def_data.h"
#include "resourceclass.h"
#include "Textures"
#ifdef __CLIENT__
# include "Fonts"
#endif
#include <de/System>
#include <de/Error>
#include <de/String>
#include <de/System>

/**
* Logical resources; materials, packages, textures, etc... @ingroup resource
Expand Down Expand Up @@ -89,7 +91,7 @@ class ResourceSystem : public de::System
void clearSystemFontSchemes();

AbstractFont *createFontFromDef(ded_compositefont_t const &def);
AbstractFont *createFontFromFile(de::Uri const &uri, char const *resourcePath);
AbstractFont *createFontFromFile(de::Uri const &uri, de::String filePath);

#endif

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/def_main.cpp
Expand Up @@ -1460,7 +1460,7 @@ void Def_Read()
// Composite fonts.
for(int i = 0; i < defs.count.compositeFonts.num; ++i)
{
App_ResourceSystem().createFontFromDef(defs.compositeFonts + i);
App_ResourceSystem().createFontFromDef(defs.compositeFonts[i]);
}
#endif

Expand Down
14 changes: 7 additions & 7 deletions doomsday/client/src/resource/compositebitmapfont.cpp
Expand Up @@ -231,21 +231,21 @@ void CompositeBitmapFont::setDefinition(ded_compositefont_t *newDef)
d->def = newDef;
}

void CompositeBitmapFont::rebuildFromDef(ded_compositefont_t *newDef)
void CompositeBitmapFont::rebuildFromDef(ded_compositefont_t const &newDef)
{
LOG_AS("CompositeBitmapFont::rebuildFromDef");

setDefinition(newDef);
if(!newDef) return;
setDefinition(const_cast<ded_compositefont_t *>(&newDef));
if(!d->def) return;

for(int i = 0; i < newDef->charMapCount.num; ++i)
for(int i = 0; i < d->def->charMapCount.num; ++i)
{
if(!newDef->charMap[i].path) continue;
if(!d->def->charMap[i].path) continue;

try
{
QByteArray path = reinterpret_cast<de::Uri &>(*newDef->charMap[i].path).resolved().toUtf8();
glyphSetPatch(newDef->charMap[i].ch, path.constData());
String glyphPatchPath = reinterpret_cast<de::Uri &>(*d->def->charMap[i].path).resolved();
glyphSetPatch(d->def->charMap[i].ch, glyphPatchPath);
}
catch(de::Uri::ResolveError const& er)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/fonts.cpp
Expand Up @@ -210,7 +210,7 @@ bool FontManifest::setUniqueId(int newUniqueId)
_uniqueId = newUniqueId;

// Notify interested parties that the uniqueId has changed.
DENG2_FOR_AUDIENCE(UniqueIdChanged, i) i->fontManifestUniqueIdChanged(*this);
DENG2_FOR_AUDIENCE(UniqueIdChanged, i) i->manifestUniqueIdChanged(*this);

return true;
}
Expand Down
107 changes: 39 additions & 68 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -104,10 +104,12 @@ DENG2_PIMPL(ResourceSystem)
textures.createScheme("Lightmaps");
textures.createScheme("Flaremaps");

#ifdef __CLIENT__
LOG_VERBOSE("Initializing Font collection...");
/// @note Order here defines the ambigious-URI search order.
fonts.createScheme("System");
fonts.createScheme("Game");
#endif
}

~Instance()
Expand Down Expand Up @@ -1003,13 +1005,11 @@ AbstractFont *ResourceSystem::createFontFromDef(ded_compositefont_t const &def)
/// @todo Do not update fonts here (not enough knowledge). We should
/// instead return an invalid reference/signal and force the caller
/// to implement the necessary update logic.
#ifdef DENG_DEBUG
LOG_DEBUG("A Font with uri \"%s\" already exists, returning existing.")
<< manifest.composeUri();
#endif

compFont->rebuildFromDef(def);
}

return &manifest.font();
}

Expand All @@ -1019,7 +1019,8 @@ AbstractFont *ResourceSystem::createFontFromDef(ded_compositefont_t const &def)
{
if(verbose >= 1)
{
LOG_VERBOSE("New font \"%s\"") << manifest.composeUri(id);
LOG_VERBOSE("New font \"%s\"")
<< manifest.composeUri();
}
return &manifest.font();
}
Expand All @@ -1042,92 +1043,62 @@ AbstractFont *ResourceSystem::createFontFromDef(ded_compositefont_t const &def)
}

AbstractFont *ResourceSystem::createFontFromFile(de::Uri const &uri,
char const *resourcePath)
String filePath)
{
LOG_AS("ResourceSystem::createFontFromFile");

if(!resourcePath || !resourcePath[0] ||
!App_FileSystem().accessFile(de::Uri::fromNativePath(resourcePath)))
if(!App_FileSystem().accessFile(de::Uri::fromNativePath(filePath)))
{
LOG_WARNING("Invalid ResourcePath reference, ignoring.");
LOG_WARNING("Invalid resourcePath reference, ignoring.");
return 0;
}

fontschemeid_t schemeId = parseScheme(uri.schemeCStr());
if(!VALID_FONTSCHEMEID(schemeId))
try
{
LOG_WARNING("Invalid font scheme in Font Uri \"%s\", ignoring.")
<< NativePath(uri.asText()).pretty();
return 0;
}

FontScheme &fs = scheme(uri.scheme());
int uniqueId = fs.count() + 1; // 1-based index.
fontid_t id = fs.declare(uri.path(), uniqueId);
if(id == NOFONTID) return 0; // Invalid URI?
FontManifest &manifest = d->fonts.scheme(uri.scheme()).declare(uri.path());

// Have we already encountered this name?
AbstractFont *font = toFont(id);
if(font)
{
if(BitmapFont *bmapFont = font->maybeAs<BitmapFont>())
if(manifest.hasFont())
{
bmapFont->setFilePath(resourcePath);
}

return font;
}

// A new font.
FontManifest *manifest = findDirectoryNodeForBindId(id);
if(!manifest)
{
LOG_WARNING("Failed creating Font #%u (invalid id), ignoring.") << id;
return 0;
}
if(BitmapFont *bmapFont = manifest.font().maybeAs<BitmapFont>())
{
/// @todo Do not update fonts here (not enough knowledge). We should
/// instead return an invalid reference/signal and force the caller
/// to implement the necessary update logic.
LOG_DEBUG("A Font with uri \"%s\" already exists, returning existing.")
<< manifest.composeUri();

if(!resourcePath || !resourcePath[0])
{
LOG_WARNING("Failed creating Font #%u (resourcePath = NULL), ignoring.") << id;
return 0;
}
bmapFont->setFilePath(filePath);
}
return &manifest.font();
}

if(manifest->hasFont())
{
if(BitmapFont *bmapFont = manifest->font().maybeAs<BitmapFont>())
// A new font.
manifest.setFont(BitmapFont::fromFile(manifest, filePath));
if(manifest.hasFont())
{
/// @todo Do not update fonts here (not enough knowledge). We should
/// instead return an invalid reference/signal and force the caller
/// to implement the necessary update logic.
#ifdef DENG_DEBUG
LOG_DEBUG("A Font with uri \"%s\" already exists, returning existing.")
<< manifest->composeUri(id);
#endif
bmapFont->setFilePath(resourcePath);
if(verbose >= 1)
{
LOG_VERBOSE("New font \"%s\"")
<< manifest.composeUri();
}
return &manifest.font();
}

return &manifest->font();
LOG_WARNING("Failed defining new Font for \"%s\", ignoring.")
<< NativePath(uri.asText()).pretty();
}

// A new font.
manifest->setFont(BitmapFont::fromFile(id, resourcePath));
if(manifest->hasFont())
catch(Fonts::UnknownSchemeError const &er)
{
if(verbose >= 1)
{
LOG_VERBOSE("New font \"%s\"") << manifest->composeUri(id);
}

return &manifest->font();
LOG_WARNING(er.asText() + ". Failed declaring font \"%s\", ignoring.")
<< NativePath(uri.asText()).pretty();
}

if(!font)
catch(FontScheme::InvalidPathError const &er)
{
LOG_WARNING("Failed defining new Font for \"%s\", ignoring.")
LOG_WARNING(er.asText() + ". Failed declaring font \"%s\", ignoring.")
<< NativePath(uri.asText()).pretty();
}

return font;
return 0;
}

#endif // __CLIENT__

0 comments on commit d0d211a

Please sign in to comment.