aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sword25/kernel')
-rw-r--r--engines/sword25/kernel/kernel.cpp9
-rw-r--r--engines/sword25/kernel/kernel.h4
-rw-r--r--engines/sword25/kernel/kernel_script.cpp16
-rw-r--r--engines/sword25/kernel/resmanager.cpp25
-rw-r--r--engines/sword25/kernel/resmanager.h37
5 files changed, 19 insertions, 72 deletions
diff --git a/engines/sword25/kernel/kernel.cpp b/engines/sword25/kernel/kernel.cpp
index 45ec492bc9..6b99b0a115 100644
--- a/engines/sword25/kernel/kernel.cpp
+++ b/engines/sword25/kernel/kernel.cpp
@@ -152,15 +152,6 @@ uint Kernel::getMilliTicks() {
}
/**
- * Returns how much memory is being used
- */
-size_t Kernel::getUsedMemory() {
- // TODO: Actually monitor how much memory is being used, so that the game
- // doesn't keep allocating resources without ever deleting them.
- return 0;
-}
-
-/**
* Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active.
*/
GraphicEngine *Kernel::getGfx() {
diff --git a/engines/sword25/kernel/kernel.h b/engines/sword25/kernel/kernel.h
index 252de64e80..9e7ee0fdd9 100644
--- a/engines/sword25/kernel/kernel.h
+++ b/engines/sword25/kernel/kernel.h
@@ -93,10 +93,6 @@ public:
return _resourceManager;
}
/**
- * Returns how much memory is being used
- */
- size_t getUsedMemory();
- /**
* Returns a random number
* @param Min The minimum allowed value
* @param Max The maximum allowed value
diff --git a/engines/sword25/kernel/kernel_script.cpp b/engines/sword25/kernel/kernel_script.cpp
index e5586a513b..458f6b2deb 100644
--- a/engines/sword25/kernel/kernel_script.cpp
+++ b/engines/sword25/kernel/kernel_script.cpp
@@ -168,7 +168,9 @@ static int getSubversionRevision(lua_State *L) {
}
static int getUsedMemory(lua_State *L) {
- lua_pushnumber(L, Kernel::getInstance()->getUsedMemory());
+ // It doesn't really matter what this call returns,
+ // as it's used in a debug function.
+ lua_pushnumber(L, 0);
return 1;
}
@@ -404,7 +406,9 @@ static int getMaxMemoryUsage(lua_State *L) {
ResourceManager *pResource = pKernel->getResourceManager();
assert(pResource);
- lua_pushnumber(L, pResource->getMaxMemoryUsage());
+ // This is used for debugging, so it doesn't really matter.
+ // The default value set by the scripts is 256000000 bytes
+ lua_pushnumber(L, 256000000);
return 1;
}
@@ -415,7 +419,8 @@ static int setMaxMemoryUsage(lua_State *L) {
ResourceManager *pResource = pKernel->getResourceManager();
assert(pResource);
- pResource->setMaxMemoryUsage(static_cast<uint>(lua_tonumber(L, 1)));
+ // This call is ignored, we set a limit on the number of
+ // simultaneous resources loaded instead.
return 0;
}
@@ -437,7 +442,8 @@ static int isLogCacheMiss(lua_State *L) {
ResourceManager *pResource = pKernel->getResourceManager();
assert(pResource);
- lua_pushbooleancpp(L, pResource->isLogCacheMiss());
+ // This isn't used in any script
+ lua_pushbooleancpp(L, false);
return 1;
}
@@ -448,7 +454,7 @@ static int setLogCacheMiss(lua_State *L) {
ResourceManager *pResource = pKernel->getResourceManager();
assert(pResource);
- pResource->setLogCacheMiss(lua_tobooleancpp(L, 1));
+ // This isn't used in any script
return 0;
}
diff --git a/engines/sword25/kernel/resmanager.cpp b/engines/sword25/kernel/resmanager.cpp
index 3b0dbcf5eb..19da68d4bf 100644
--- a/engines/sword25/kernel/resmanager.cpp
+++ b/engines/sword25/kernel/resmanager.cpp
@@ -40,6 +40,11 @@
namespace Sword25 {
+// Sets the amount of resources that are simultaneously loaded.
+// This needs to be a relatively high number, as all the animation
+// frames in each scene are loaded as separate resources.
+#define SWORD25_RESOURCECACHE_MAX 100
+
ResourceManager::~ResourceManager() {
// Clear all unlocked resources
emptyCache();
@@ -80,7 +85,7 @@ bool ResourceManager::registerResourceService(ResourceService *pService) {
*/
void ResourceManager::deleteResourcesIfNecessary() {
// If enough memory is available, or no resources are loaded, then the function can immediately end
- if (_kernelPtr->getUsedMemory() < _maxMemoryUsage || _resources.empty())
+ if (_resources.size() < SWORD25_RESOURCECACHE_MAX)
return;
// Keep deleting resources until the memory usage of the process falls below the set maximum limit.
@@ -93,7 +98,7 @@ void ResourceManager::deleteResourcesIfNecessary() {
// The resource may be released only if it isn't locked
if ((*iter)->getLockCount() == 0)
iter = deleteResource(*iter);
- } while (iter != _resources.begin() && _kernelPtr->getUsedMemory() > _maxMemoryUsage);
+ } while (iter != _resources.begin() && _resources.size() >= SWORD25_RESOURCECACHE_MAX);
}
/**
@@ -135,10 +140,6 @@ Resource *ResourceManager::requestResource(const Common::String &fileName) {
}
}
- // The resource was not found, therefore, must not be loaded yet
- if (_logCacheMiss)
- warning("\"%s\" was not precached.", uniqueFileName.c_str());
-
Resource *pResource = loadResource(uniqueFileName);
if (pResource) {
pResource->addReference();
@@ -296,16 +297,4 @@ void ResourceManager::dumpLockedResources() {
}
}
-/**
- * Specifies the maximum amount of memory the engine is allowed to use.
- * If this value is exceeded, resources will be unloaded to make room. This value is meant
- * as a guideline, and not as a fixed boundary. It is not guaranteed not to be exceeded;
- * the whole game engine may still use more memory than any amount specified.
- */
-void ResourceManager::setMaxMemoryUsage(uint maxMemoryUsage) {
- // TODO: Game scripts set this to 256000000. Set it to a more conservative value
- _maxMemoryUsage = maxMemoryUsage;
- deleteResourcesIfNecessary();
-}
-
} // End of namespace Sword25
diff --git a/engines/sword25/kernel/resmanager.h b/engines/sword25/kernel/resmanager.h
index c097ca7024..5b2bfd395f 100644
--- a/engines/sword25/kernel/resmanager.h
+++ b/engines/sword25/kernel/resmanager.h
@@ -82,37 +82,6 @@ public:
void emptyCache();
/**
- * Returns the maximum memory the kernel has used
- */
- int getMaxMemoryUsage() const {
- return _maxMemoryUsage;
- }
-
- /**
- * Specifies the maximum amount of memory the engine is allowed to use.
- * If this value is exceeded, resources will be unloaded to make room. This value is meant
- * as a guideline, and not as a fixed boundary. It is not guaranteed not to be exceeded;
- * the whole game engine may still use more memory than any amount specified.
- */
- void setMaxMemoryUsage(uint maxMemoryUsage);
-
- /**
- * Specifies whether a warning is written to the log when a cache miss occurs.
- * THe default value is "false".
- */
- bool isLogCacheMiss() const {
- return _logCacheMiss;
- }
-
- /**
- * Sets whether warnings are written to the log if a cache miss occurs.
- * @param Flag If "true", then future warnings will be logged
- */
- void setLogCacheMiss(bool flag) {
- _logCacheMiss = flag;
- }
-
- /**
* Writes the names of all currently locked resources to the log file
*/
void dumpLockedResources();
@@ -123,9 +92,7 @@ private:
* Only the BS_Kernel class can generate copies this class. Thus, the constructor is private
*/
ResourceManager(Kernel *pKernel) :
- _kernelPtr(pKernel),
- _maxMemoryUsage(100000000),
- _logCacheMiss(false)
+ _kernelPtr(pKernel)
{}
virtual ~ResourceManager();
@@ -166,12 +133,10 @@ private:
void deleteResourcesIfNecessary();
Kernel *_kernelPtr;
- uint _maxMemoryUsage;
Common::Array<ResourceService *> _resourceServices;
Common::List<Resource *> _resources;
typedef Common::HashMap<Common::String, Resource *> ResMap;
ResMap _resourceHashMap;
- bool _logCacheMiss;
};
} // End of namespace Sword25