Add IRenderer::ClearCache
This commit is contained in:
parent
bb4675ca00
commit
ed508fadd5
@ -43,6 +43,13 @@ namespace spades {
|
||||
*/
|
||||
Model @RegisterModel(const string @path) {}
|
||||
|
||||
/**
|
||||
* Clear the cache of models and images loaded via `RegisterModel`
|
||||
* and `RegisterImage`. This method is merely a hint - the
|
||||
* implementation may partially or completely ignore the request.
|
||||
*/
|
||||
void ClearCache() {}
|
||||
|
||||
/** Creates an image from the specified bitmap. */
|
||||
Image @CreateImage(Bitmap @bitmap) {}
|
||||
|
||||
|
@ -98,6 +98,13 @@ namespace spades {
|
||||
virtual IImage *RegisterImage(const char *filename) = 0;
|
||||
virtual IModel *RegisterModel(const char *filename) = 0;
|
||||
|
||||
/**
|
||||
* Clear the cache of models and images loaded via `RegisterModel`
|
||||
* and `RegisterImage`. This method is merely a hint - the
|
||||
* implementation may partially or completely ignore the request.
|
||||
*/
|
||||
virtual void ClearCache() {}
|
||||
|
||||
virtual IImage *CreateImage(Bitmap *) = 0;
|
||||
virtual IModel *CreateModel(VoxelModel *) = 0;
|
||||
|
||||
|
@ -19,13 +19,13 @@
|
||||
*/
|
||||
|
||||
#include "GLImageManager.h"
|
||||
#include "GLImage.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Bitmap.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/FileManager.h>
|
||||
#include <Core/IStream.h>
|
||||
#include "GLImage.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -102,5 +102,7 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLImageManager::ClearCache() { images.clear(); }
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -45,6 +45,8 @@ namespace spades {
|
||||
GLImage *GetWhiteImage();
|
||||
|
||||
void DrawAllImages(GLRenderer *);
|
||||
|
||||
void ClearCache();
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -66,5 +66,7 @@ namespace spades {
|
||||
|
||||
return static_cast<GLModel *>(renderer->CreateModelOptimized(voxelModel));
|
||||
}
|
||||
|
||||
void GLModelManager::ClearCache() { models.clear(); }
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -38,6 +38,8 @@ namespace spades {
|
||||
GLModelManager(GLRenderer *);
|
||||
~GLModelManager();
|
||||
GLModel *RegisterModel(const char *);
|
||||
|
||||
void ClearCache();
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -251,6 +251,12 @@ namespace spades {
|
||||
return modelManager->RegisterModel(filename);
|
||||
}
|
||||
|
||||
void GLRenderer::ClearCache() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
modelManager->ClearCache();
|
||||
imageManager->ClearCache();
|
||||
}
|
||||
|
||||
client::IImage *GLRenderer::CreateImage(spades::Bitmap *bmp) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
return GLImage::FromBitmap(bmp, device);
|
||||
|
@ -153,6 +153,8 @@ namespace spades {
|
||||
client::IImage *RegisterImage(const char *filename) override;
|
||||
client::IModel *RegisterModel(const char *filename) override;
|
||||
|
||||
void ClearCache() override;
|
||||
|
||||
client::IImage *CreateImage(Bitmap *) override;
|
||||
client::IModel *CreateModel(VoxelModel *) override;
|
||||
client::IModel *CreateModelOptimized(VoxelModel *);
|
||||
|
@ -127,5 +127,9 @@ namespace spades {
|
||||
}
|
||||
|
||||
SWImage *SWImageManager::CreateImage(Bitmap *vm) { return new SWImage(vm); }
|
||||
|
||||
void SWImageManager::ClearCache() {
|
||||
images.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,8 @@ namespace spades {
|
||||
|
||||
SWImage *RegisterImage(const std::string &);
|
||||
SWImage *CreateImage(Bitmap *);
|
||||
|
||||
void ClearCache();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -147,5 +147,9 @@ namespace spades {
|
||||
}
|
||||
|
||||
SWModel *SWModelManager::CreateModel(spades::VoxelModel *vm) { return new SWModel(vm); }
|
||||
|
||||
void SWModelManager::ClearCache() {
|
||||
models.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ namespace spades {
|
||||
|
||||
SWModel *RegisterModel(const std::string &);
|
||||
SWModel *CreateModel(VoxelModel *);
|
||||
|
||||
void ClearCache();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +152,13 @@ namespace spades {
|
||||
return modelManager->RegisterModel(filename);
|
||||
}
|
||||
|
||||
void SWRenderer::ClearCache() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
EnsureValid();
|
||||
imageManager->ClearCache();
|
||||
modelManager->ClearCache();
|
||||
}
|
||||
|
||||
client::IImage *SWRenderer::CreateImage(spades::Bitmap *bmp) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
EnsureValid();
|
||||
@ -1186,5 +1193,5 @@ namespace spades {
|
||||
|
||||
flatMapRenderer->SetNeedsUpdate(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -159,6 +159,8 @@ namespace spades {
|
||||
|
||||
client::IImage *CreateImage(Bitmap *) override;
|
||||
client::IModel *CreateModel(VoxelModel *) override;
|
||||
|
||||
void ClearCache() override;
|
||||
/*
|
||||
GLProgram *RegisterProgram(const std::string& name) override;
|
||||
GLShader *RegisterShader(const std::string& name) override;
|
||||
|
@ -394,6 +394,11 @@ namespace spades {
|
||||
asFUNCTION(RegisterModel),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod("Renderer",
|
||||
"void ClearCache()",
|
||||
asMETHOD(IRenderer, ClearCache),
|
||||
asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
// OpenSpades' C++ functions increase the reference count of a passed object
|
||||
// when storing it (just like the convention of Objective C), so we must
|
||||
// use "auto handles" (`@+`). Otherwise, a memory leak would occur
|
||||
|
Loading…
x
Reference in New Issue
Block a user