30 typedef RndObject *(*ClassFactory)(
const char *pszName);
97 std::unique_ptr<File> mFile;
177 std::unique_ptr<RndLoader>
233 const char *pszPrefix,
234 std::list<RndObject *> *pClones,
369 const std::map<const char *, RndObject *, StrLess> &
GetObjects()
const {
380 mObjects[pszName] = pObject;
389 mObjects.erase(pszName);
399 mClasses[pszClass] = factory;
411 std::map<const char *, RndObject *, StrLess> mObjects;
412 std::map<const char *, ClassFactory, StrLess> mClasses;
413 std::map<FilePath, std::unique_ptr<ResourceLoader>> mResources;
414 std::list<RndLoader *> mLoaders;
445 const int nSize =
static_cast<int>(list.size());
447 for (T *pElement : list) {
480 list.resize(nSize,
nullptr);
481 for (T *&pElement : list) {
509 const int nSize =
static_cast<int>(objects.size());
511 for (T *pElement : objects) {
536 objects.resize(nSize,
nullptr);
537 for (T *&pElement : objects) {
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
void ReadEndian(void *pData, int nBytes)
Read a value of 2, 4, 8, or 16 bytes, reversing its bytes unless the stream is little endian.
BinStream & WriteString(const char *pszText)
Write a string with its length first.
void WriteEndian(const void *pData, int nBytes)
Write a value of 2, 4, 8, or 16 bytes, reversing its bytes unless the stream is little endian.
Path of a file, kept relative to a shared root directory.
Definition filepath.h:14
Interface a loader consults before it creates each object of its file.
Definition rndloader.h:35
Loader of one .rnd file, which reads the file over several frames.
Definition rndloader.h:21
ResourceLoader(std::unique_ptr< File > pFile, const char *pszTag)
Start reading a file.
void AddRef()
Take one more reference, for one more GetData().
Definition rndmanager.h:92
int GetData(void **ppData, int *pnSize)
Wait for the data and hand it out, dropping one reference.
bool Poll()
Finish the read when the file reports it complete.
~ResourceLoader()
Release the buffer and the file.
Registry of every live renderer object, of every class a .rnd file may instantiate,...
Definition rndmanager.h:22
void SetClassFactory(const char *pszClass, ClassFactory factory)
Register the factory that Create() calls for a class.
Definition rndmanager.h:398
void Write(BinStream &stream)
Write every object that is not internal as a .rnd file.
void PollLoaders(float fBudgetMs)
Advance the queued loaders until a time budget is spent.
const char * ResourcePath(const char *pszFile)
Report the file to read for a resource.
void Init()
Register the factory of every class a .rnd file may instantiate.
void SaveFile(const char *pszFile)
Write the objects to a .rnd file.
TextureState
Results of IsTextureLoaded().
Definition rndmanager.h:33
@ kTextureLoading
Definition rndmanager.h:34
@ kTextureLoaded
Definition rndmanager.h:35
@ kTextureUnknown
Definition rndmanager.h:36
void SortObjects(std::list< RndObject * > &objects)
Order a list of objects for writing, the textures first and sorted by file, followed by the animation...
void LoadFile(const char *pszFile)
Load a .rnd file before the call returns.
void GetResource(const FilePath &path, void **ppData, int *pnSize)
Wait for a resource file and hand out its data, dropping one reference.
void ReleaseTexture(const FilePath &path)
Release the read of a texture file whatever its references.
RndObject * Find(const char *pszName)
Resolve a live object by name.
RndObject *(* ClassFactory)(const char *pszName)
Builds one instance of a registered class.
Definition rndmanager.h:30
bool AcquireTexture(const FilePath &path)
Take a reference on a texture file, starting to read it on the first reference.
std::unique_ptr< RndLoader > AddLoader(const char *pszFile, int nFlags, RndLoader::Callback *pCallback, BinStream *pStream)
Create a loader for a .rnd file and queue it.
void DeleteLoadedObjects()
Delete every object a file created, leaving the internal objects.
RndManager()
Construct an empty registry.
void SetObject(const char *pszName, RndObject *pObject)
Register an object under a name, replacing any object registered under it.
Definition rndmanager.h:379
RndObject * Create(const char *pszClass, const char *pszName)
Create an instance of a registered class.
void Clone(RndObject *pSource, const char *pszPrefix, std::list< RndObject * > *pClones, int nFlags, int bRecurse, int bLink)
Clone an object under a prefixed name, optionally with its descendants and its parents.
static int sRev
The format version Write() writes and the newest a loader accepts.
Definition rndmanager.h:408
static const char * ResourceTag(const char *pszFile)
Report the tag a resource file's buffer is billed to, from the file's extension.
~RndManager()
Destroy the registry.
static RndObject * NewTunnel(const char *pszName)
Create a view in place of a tunnel, the factory registered for the class Tunnel.
int IsTextureLoaded(const FilePath &path)
Report whether a texture file finished reading.
void ClearResources()
Release every resource read.
void RemoveLoader(RndLoader *pLoader)
Remove a loader from the queue.
void RemoveObject(const char *pszName)
Remove the registration of a name.
Definition rndmanager.h:388
const std::map< const char *, RndObject *, StrLess > & GetObjects() const
Definition rndmanager.h:369
Base of every object the renderer can load, resolve by name, and serialise.
Definition rndobject.h:20
const char * GetName() const
Definition rndobject.h:133
Growable text buffer that is also a PrnStream.
Definition string.h:19
int GetLength() const
Definition string.h:374
const char * c_str() const
Report the text.
Definition string.h:369
RndManager TheManager
The renderer's registry.
BinStream & operator<<(BinStream &stream, const std::list< T * > &list)
Write a list of objects as its size followed by each object's name.
Definition rndmanager.h:444
BinStream & operator>>(BinStream &stream, std::list< T * > &list)
Read a list of objects the list writer wrote, resolving each name in TheManager.
Definition rndmanager.h:477