diff --git a/config.lib b/config.lib --- a/config.lib +++ b/config.lib @@ -1243,7 +1243,6 @@ make_cflags_and_ldflags() { CFLAGS="$CFLAGS -D_SQ64" fi CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR" - CFLAGS="$CFLAGS -DNO_GARBAGE_COLLECTOR" if [ -n "$png_config" ]; then CFLAGS="$CFLAGS -DWITH_PNG" diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -60,7 +60,7 @@ FavorSizeOrSpeed="2" OmitFramePointers="true" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;WITH_ASSERT" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT" StringPooling="true" ExceptionHandling="1" RuntimeLibrary="0" @@ -167,7 +167,7 @@ AdditionalOptions="/MP" Optimization="0" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="0" @@ -269,7 +269,7 @@ FavorSizeOrSpeed="2" OmitFramePointers="true" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64;WITH_ASSERT" StringPooling="true" ExceptionHandling="1" RuntimeLibrary="0" @@ -377,7 +377,7 @@ AdditionalOptions="/MP" Optimization="0" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="0" diff --git a/projects/openttd_vs80.vcproj.in b/projects/openttd_vs80.vcproj.in --- a/projects/openttd_vs80.vcproj.in +++ b/projects/openttd_vs80.vcproj.in @@ -60,7 +60,7 @@ FavorSizeOrSpeed="2" OmitFramePointers="true" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;WITH_ASSERT" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT" StringPooling="true" ExceptionHandling="1" RuntimeLibrary="0" @@ -167,7 +167,7 @@ AdditionalOptions="/MP" Optimization="0" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="0" @@ -269,7 +269,7 @@ FavorSizeOrSpeed="2" OmitFramePointers="true" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64;WITH_ASSERT" StringPooling="true" ExceptionHandling="1" RuntimeLibrary="0" @@ -377,7 +377,7 @@ AdditionalOptions="/MP" Optimization="0" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="0" diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -61,7 +61,7 @@ FavorSizeOrSpeed="2" OmitFramePointers="true" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;WITH_ASSERT" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT" StringPooling="true" ExceptionHandling="1" RuntimeLibrary="0" @@ -166,7 +166,7 @@ AdditionalOptions="/MP" Optimization="0" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="0" @@ -267,7 +267,7 @@ FavorSizeOrSpeed="2" OmitFramePointers="true" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64;WITH_ASSERT" StringPooling="true" ExceptionHandling="1" RuntimeLibrary="0" @@ -374,7 +374,7 @@ AdditionalOptions="/MP" Optimization="0" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="0" diff --git a/projects/openttd_vs90.vcproj.in b/projects/openttd_vs90.vcproj.in --- a/projects/openttd_vs90.vcproj.in +++ b/projects/openttd_vs90.vcproj.in @@ -61,7 +61,7 @@ FavorSizeOrSpeed="2" OmitFramePointers="true" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;WITH_ASSERT" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT" StringPooling="true" ExceptionHandling="1" RuntimeLibrary="0" @@ -166,7 +166,7 @@ AdditionalOptions="/MP" Optimization="0" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="0" @@ -267,7 +267,7 @@ FavorSizeOrSpeed="2" OmitFramePointers="true" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64;WITH_ASSERT" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64;WITH_ASSERT" StringPooling="true" ExceptionHandling="1" RuntimeLibrary="0" @@ -374,7 +374,7 @@ AdditionalOptions="/MP" Optimization="0" AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include" - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";NO_GARBAGE_COLLECTOR;_SQ64" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;WITH_ICU;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";_SQ64" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="0" diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -3,6 +3,7 @@ /** @file ai_core.cpp Implementation of AI. */ #include "../stdafx.h" +#include "../core/bitmath_func.hpp" #include "../company_base.h" #include "../company_func.h" #include "../debug.h" @@ -68,6 +69,13 @@ } } + /* Occasionally collect garbage; every 255 ticks do one company. + * Effectively collecting garbage once every two months per AI. */ + if ((AI::frame_counter & 255) == 0) { + CompanyID cid = (CompanyID)GB(AI::frame_counter, 8, 4); + if (IsValidCompanyID(cid) && !IsHumanCompany(cid)) GetCompany(cid)->ai_instance->CollectGarbage(); + } + _current_company = OWNER_NONE; } diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -296,6 +296,11 @@ void AIInstance::GameLoop() } } +void AIInstance::CollectGarbage() +{ + if (this->is_started && !this->is_dead) this->engine->CollectGarbage(); +} + /* static */ void AIInstance::DoCommandReturn(AIInstance *instance) { instance->engine->InsertResult(AIObject::GetLastCommandRes()); diff --git a/src/ai/ai_instance.hpp b/src/ai/ai_instance.hpp --- a/src/ai/ai_instance.hpp +++ b/src/ai/ai_instance.hpp @@ -45,6 +45,11 @@ public: void GameLoop(); /** + * Let the VM collect any garbage. + */ + void CollectGarbage(); + + /** * Get the storage of this AI. */ static class AIStorage *GetStorage(); diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -175,6 +175,11 @@ bool Squirrel::Resume(int suspend) return this->vm->_suspended != 0; } +void Squirrel::CollectGarbage() +{ + sq_collectgarbage(this->vm); +} + bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend) { /* Store the stack-location for the return value. We need to diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp --- a/src/script/squirrel.hpp +++ b/src/script/squirrel.hpp @@ -101,6 +101,11 @@ public: */ bool Resume(int suspend = -1); + /** + * Tell the VM to do a garbage collection run. + */ + void CollectGarbage(); + void InsertResult(bool result); void InsertResult(int result);