Cogs.Core
|
Font manager responsible for loading, processing and lifetime of Font resources. More...
#include <FontManager.h>
Public Member Functions | |
FontManager (Context *context) | |
Constructs a FontManager in the given context. | |
~FontManager () override | |
Destructs the FontManaer. | |
void | initialize () override |
Initialize the FontManager, creating default Font resources. | |
void | clear () override |
Clear the FontManager, releasing all default Font resources. | |
COGSCORE_DLL_API FontHandle | loadFont (const std::string &name, float size, ResourceId resourceId, ResourceLoadFlags flags=ResourceLoadFlags::None) |
Load a Font resource from the file resource with the given name. | |
FontHandle | loadFont (const FontDefinition &definition, const ResourceId id, ResourceLoadFlags flags=ResourceLoadFlags::None) |
Load a Font resource from the given definition. | |
void | getBakedCharacter (const Font *font, int characterIndex, float &x, float &y, Font::BakedCharacter &bakedCharacter) const |
Retrieve baked character information for rendering. | |
void | handleLoad (FontLoadInfo *loadInfo) override |
Overridden to load Font resources. | |
ActivationResult | handleActivation (FontHandle handle, Font *font) override |
Overridden to activate loaded font resources, triggering loading of the font Texture. | |
void | handleDeletion (Font *font) override |
Handler for deletion of resources. | |
void | handleFailedLoad (const FontLoadInfo *loadInfo) override |
Handle failed Font loads, logging and cleaning up. | |
virtual bool | shouldMergeBySource () const override |
Checking unique handle should not be performed using resource path only. Handled in FontManager. | |
![]() | |
ResourceManager (Context *context, Collections::ElementOffset capacity=1024) | |
Constructs a resource manager with the given context. | |
~ResourceManager () override | |
Destructs a resource manager, provided for destruction via base pointer. | |
void | clear () override |
Clear the resource manager, cleaning up resources held by member handles. | |
void | clearSwapping () override |
Clear the swap queue, ensuring indirect resource references are released. | |
ResourceHandle | create () |
Create a new resource. | |
ResourceHandle | release (ResourceId resourceId) |
ResourceHandle | loadResource (FontLoadInfo *loadInfo) |
ResourceProxy | createLocked () |
Creates a new resource, but returns a ResourceProxy for thread safe editing instead of a handle to the actual resource. | |
ResourceProxy | lock (const ResourceHandle &handle) |
Takes the handle given and returns a resource proxy to edit the contents of the held resource safely on other threads than the main thread. | |
void | unlockProxy (const ResourceHandle &handle, const ResourceHandle &proxy) |
Unlock the given resource proxy. | |
ResourceHandle | generateHandle (ResourceBase *resource) |
Generate a handle to the given resource. | |
virtual void | handleLoad (FontLoadInfo *) |
Handler for resource loading. | |
virtual void | handleFailedLoad (const FontLoadInfo *) |
Handler for failed resource loads using the given loadInfo. | |
virtual ActivationResult | handleActivation (ResourceHandle, Font *) |
Handler for activation of resources. | |
virtual void | handleDeletion (Font *) |
Handler for deletion of resources. | |
Font * | get (const ResourceHandleBase &handle) |
Resolve the given handle to a resource. | |
void | processSwapping () override |
Process queued swap operations, exchanging resource contents of the destination resources by those indicated in the operation data. | |
ResourceHandle | getHandle (const ResourceId id) const |
Get a resource handle to the resource with the given id. | |
void | registerLoader (IResourceLoader< Font, FontLoadInfo > *loader) |
Register a resource loader capable of handling resources of the template type. | |
void | destroyLoadInfoInternal (ResourceLoadInfoBase *loadInfo) override |
FontLoadInfo * | createLoadInfo () |
![]() | |
ResourceManagerBase (Context *context) | |
void | initialize () override |
void | clear () override |
void | reportLeaks (std::string_view typeName) |
std::string | getReport () |
Return a string with current resource usage. | |
bool | checkPreloaded (ResourceLoadInfoBase *loadInfo) |
ResourceHandleBase | releaseInternal (ResourceId resourceId) |
Releases a resourceId -> ResourceHandle mapping. | |
ResourceHandleBase | loadResourceInternal (ResourceLoadInfoBase *loadInfo) |
Load a resource using the given loadInfo. | |
void | processLoading () final |
Process loading resources. | |
void | setProcessed (ResourceLoadInfoBase *loadInfo, bool swapping=false) |
Signal the resource being loaded as done loading and ready for activation etc. | |
void | activateResources () final |
virtual void | processDeletion () override |
Process resources pending deallocation. | |
void | fillDeletionQueue (std::vector< ResourceBase * > &deletion) |
void | destroyLocked (ResourceBase *resource) |
void | safeDestroy (ResourceBase *resource) |
ResourceId | getNextResourceId () override |
Get the next unique resource id. | |
void | resourceChanged (ResourceBase *resource) override |
void | resourceDeleted (ResourceBase *resource) override |
void | setResourceId (ResourceBase *resource, ResourceId id) override |
Assign the given id to a previously created resource. | |
void | queueResource (ResourceLoadInfoBase *loadInfo) |
Re-queue the given loadInfo to defer loading to the next time the processLoading() phase is performed. | |
virtual void | handleLoadInternal (ResourceLoadInfoBase *loadInfo)=0 |
virtual ActivationResult | handleActivationInternal (ResourceHandleBase r, ResourceBase *resource)=0 |
virtual void | handleDeletionInternal (ResourceBase *resource)=0 |
virtual void | handleFailedLoadInternal (ResourceLoadInfoBase *loadInfo)=0 |
virtual void | destroyLoadInfoInternal (ResourceLoadInfoBase *loadInfo)=0 |
virtual bool | shouldAutoReload () const |
virtual bool | shouldMergeBySource () const |
virtual void | handleReload (ResourceHandleBase) |
std::vector< ResourceBase * > | getAllocatedResources () const |
ResourceHandleBase | getOrCreate (ResourceId id) |
ResourceHandleBase | getByName (std::string_view name) const |
ResourceHandleBase | getBySource (std::string_view source) const |
ResourceHandleBase | createResource () |
virtual ResourceBase * | createInternal ()=0 |
virtual void | destroyInternal (ResourceBase *resource)=0 |
virtual void | destroyInternalLocked (ResourceBase *resource)=0 |
ResourceHandleBase | generateHandle (ResourceBase *resource) |
void | clearUpdated () |
virtual int | getUpdateQuota () const |
size_t | updatedResourceCount () |
size_t | orphanedResourceCount () |
size_t | allocatedResourceCount () |
virtual void | initialize ()=0 |
virtual void | clear ()=0 |
virtual void | clearSwapping ()=0 |
virtual void | processLoading ()=0 |
virtual void | processSwapping ()=0 |
virtual void | activateResources ()=0 |
virtual void | processDeletion ()=0 |
virtual void | resourceChanged (ResourceBase *resource)=0 |
virtual void | resourceDeleted (ResourceBase *resource)=0 |
virtual ResourceId | getNextResourceId ()=0 |
virtual void | setResourceId (ResourceBase *resource, ResourceId id)=0 |
Public Attributes | |
ResourceId | DefaultMonospaceFont = NoResourceId |
Id of the default monospace font. | |
ResourceId | DefaultRegularFont = NoResourceId |
Id of the default font. | |
ResourceId | DefaultBoldFont = NoResourceId |
Id of the default bold font. | |
FontHandle | regularFont = FontHandle::NoHandle |
Handle to the regular font. | |
FontHandle | boldFont = FontHandle::NoHandle |
Handle to the bold font. | |
std::unordered_map< FontDefinition, FontHandle > | sharedFonts |
Additional Inherited Members | |
![]() | |
using | ResourceHandle = ResourceHandle_t< Font > |
Type of handle used to hold resources. | |
using | ResourceProxy = ResourceProxy< Font, ResourceManager > |
Type of resource proxy objects, specialized on the type of resource. | |
![]() | |
Font * | createInternal () override |
void | destroyInternal (ResourceBase *resource) override |
void | handleLoadInternal (ResourceLoadInfoBase *loadInfo) override |
ActivationResult | handleActivationInternal (ResourceHandleBase r, ResourceBase *resource) override |
void | handleDeletionInternal (ResourceBase *resource) override |
void | handleFailedLoadInternal (ResourceLoadInfoBase *loadInfo) override |
IResourceLoader< Font, FontLoadInfo > * | findLoader (const FontLoadInfo *loadInfo) |
Find a loader capable of loading the resource given by loadInfo. | |
![]() | |
ResourceHandleBase | getResourceHandle (ResourceId id) const |
Get existing resource handle. | |
bool | isValidResource (ResourceId id) const |
Check if resource handle points to. | |
virtual void | postProcessLoading () |
Hook for resource managers to run code at the tail of processLoading. | |
![]() | |
Mutex | swapMutex |
Collections::Pool< Font > | resources |
std::vector< IResourceLoader< Font, FontLoadInfo > * > | loaders |
std::deque< SwapOperation > | swapQueue |
ResourceHandle | defaultResource |
![]() | |
std::unique_ptr< ResourceManagerBaseStorage > | storage |
Context * | context = nullptr |
ResourceTypes | resourceType = ResourceTypes::Unknown |
Font manager responsible for loading, processing and lifetime of Font resources.
Definition at line 39 of file FontManager.h.
|
inlineexplicit |
Constructs a FontManager in the given context.
Definition at line 43 of file FontManager.h.
|
override |
Destructs the FontManaer.
Definition at line 20 of file FontManager.cpp.
|
overridevirtual |
Clear the FontManager, releasing all default Font resources.
Implements Cogs::Core::IResourceManager.
Definition at line 44 of file FontManager.cpp.
References Cogs::Core::ResourceManager< ResourceType, LoadInfoType >::clear(), and Cogs::Core::ResourceHandle_t< Font >::NoHandle.
void Cogs::Core::FontManager::getBakedCharacter | ( | const Font * | font, |
int | characterIndex, | ||
float & | x, | ||
float & | y, | ||
Font::BakedCharacter & | bakedCharacter | ||
) | const |
Retrieve baked character information for rendering.
Definition at line 165 of file FontManager.cpp.
|
overridevirtual |
Overridden to activate loaded font resources, triggering loading of the font Texture.
Reimplemented from Cogs::Core::ResourceManager< Font, FontLoadInfo >.
Definition at line 181 of file FontManager.cpp.
References Cogs::Core::Dependency, Cogs::Core::Failure, Cogs::Core::HandleIsValid(), Cogs::Core::None, and Cogs::Core::Success.
|
overridevirtual |
Handler for deletion of resources.
Should be overridden by derived resource managers to handle resource deletion, for example Textures needing to be removed from the renderer when the texture is no longer used by any materials or fonts.
This handler is invoked for all orphaned resources during the processDeletion() processing phase.
processDeletion() will invoke the destroy() function, which in turn invokes the deletion handler.
resource | Pointer to the resource being deleted. |
Reimplemented from Cogs::Core::ResourceManager< Font, FontLoadInfo >.
Definition at line 210 of file FontManager.cpp.
References Cogs::Core::Resident.
|
overridevirtual |
Handle failed Font loads, logging and cleaning up.
Reimplemented from Cogs::Core::ResourceManager< Font, FontLoadInfo >.
Definition at line 176 of file FontManager.cpp.
References Cogs::Core::ResourceLoadInfoBase::resourcePath.
|
overridevirtual |
Overridden to load Font resources.
Reimplemented from Cogs::Core::ResourceManager< Font, FontLoadInfo >.
Definition at line 103 of file FontManager.cpp.
References Cogs::Core::ResourceLoadInfoBase::handle, Cogs::Core::ResourceLoadInfoBase::resourceName, and Cogs::Core::TaskManager::ResourceQueue.
|
overridevirtual |
Initialize the FontManager, creating default Font resources.
Implements Cogs::Core::IResourceManager.
Definition at line 25 of file FontManager.cpp.
Cogs::Core::FontHandle Cogs::Core::FontManager::loadFont | ( | const FontDefinition & | definition, |
const ResourceId | id, | ||
ResourceLoadFlags | flags = ResourceLoadFlags::None |
||
) |
Load a Font resource from the given definition.
definition | Definition of the Font to load. |
resourceId | Resource identifier to assign to the Font. If a Font resource with the same identifier already exists, the contents will be loaded into the existing resource. |
flags | Optional loading flags |
Definition at line 61 of file FontManager.cpp.
References Cogs::Core::FontLoadInfo::definition, Cogs::Core::Dependency, Cogs::Core::FontDefinition::fontFamily, Cogs::Core::FontDefinition::fontSize, Cogs::Core::ResourceLoadInfoBase::loadFlags, Cogs::Core::ResourceLoadInfoBase::resourceId, Cogs::Core::ResourceLoadInfoBase::resourceName, and Cogs::Core::ResourceLoadInfoBase::resourcePath.
Cogs::Core::FontHandle Cogs::Core::FontManager::loadFont | ( | const std::string & | name, |
float | size, | ||
ResourceId | resourceId, | ||
ResourceLoadFlags | flags = ResourceLoadFlags::None |
||
) |
Load a Font resource from the file resource with the given name.
name | Name of a Font file resource to load from. |
size | Size of the Font resource in points. |
resourceId | Resource identifier to assign to the Font. If a Font resource with the same identifier already exists, the contents will be loaded into the existing resource. |
flags | Optional loading flags |
Definition at line 56 of file FontManager.cpp.
References Cogs::Core::FontDefinition::fontFamily.
|
inlineoverridevirtual |
Checking unique handle should not be performed using resource path only. Handled in FontManager.
Reimplemented from Cogs::Core::ResourceManagerBase.
Definition at line 94 of file FontManager.h.
FontHandle Cogs::Core::FontManager::boldFont = FontHandle::NoHandle |
Handle to the bold font.
Definition at line 110 of file FontManager.h.
ResourceId Cogs::Core::FontManager::DefaultBoldFont = NoResourceId |
Id of the default bold font.
Definition at line 104 of file FontManager.h.
ResourceId Cogs::Core::FontManager::DefaultMonospaceFont = NoResourceId |
Id of the default monospace font.
Definition at line 98 of file FontManager.h.
ResourceId Cogs::Core::FontManager::DefaultRegularFont = NoResourceId |
Id of the default font.
Definition at line 101 of file FontManager.h.
Referenced by Cogs::Core::Text3DSystem::update().
FontHandle Cogs::Core::FontManager::regularFont = FontHandle::NoHandle |
Handle to the regular font.
Definition at line 107 of file FontManager.h.
std::unordered_map<FontDefinition, FontHandle> Cogs::Core::FontManager::sharedFonts |
Map of shared font resources, since Fonts with the same definition can share the same underlying resource.
Definition at line 114 of file FontManager.h.