Index: source/i18n/StringBuffer.cpp =================================================================== --- source/i18n/StringBuffer.cpp (revision 7327) +++ source/i18n/StringBuffer.cpp (working copy) @@ -21,10 +21,6 @@ #include "TSComponent.h" #include "StringBuffer.h" -// Vaguely useful utility function for deleting stuff -template void delete_fn(T* v) { delete v; } - - #include #include "ps/CLogger.h" Index: source/i18n/CLocale.cpp =================================================================== --- source/i18n/CLocale.cpp (revision 7327) +++ source/i18n/CLocale.cpp (working copy) @@ -29,9 +29,6 @@ using namespace I18n; -// Vaguely useful utility function for deleting stuff -template void delete_fn(T* v) { delete v; } - // These could be optimised for little-endian sizeof(wchar_t)==2 systems: static inline void ReadWString8_(const char*& data, Str& str) { Index: source/i18n/TSComponent.cpp =================================================================== --- source/i18n/TSComponent.cpp (revision 7327) +++ source/i18n/TSComponent.cpp (working copy) @@ -22,9 +22,6 @@ using namespace I18n; -// Vaguely useful utility function for deleting stuff -template void delete_fn(T* v) { delete v; } - const StrImW TSComponentString::ToString(CLocale* UNUSED(locale), std::vector& UNUSED(vars)) const { return String; Index: source/i18n/Common.h =================================================================== --- source/i18n/Common.h (revision 7327) +++ source/i18n/Common.h (working copy) @@ -32,6 +32,9 @@ ERROR_GROUP(I18n); +// Vaguely useful utility function for deleting stuff +template void delete_fn(T* v) { delete v; } + // That was exciting. #endif // INCLUDED_I18N_COMMON Index: source/graphics/ObjectManager.cpp =================================================================== --- source/graphics/ObjectManager.cpp (revision 7327) +++ source/graphics/ObjectManager.cpp (working copy) @@ -27,20 +27,6 @@ #define LOG_CATEGORY L"graphics" -template -static void delete_pair_2nd(std::pair v) -{ - delete v.second; -} - -template -struct second_equals -{ - T x; - second_equals(const T& x) : x(x) {} - template bool operator()(const S& v) { return v.second == x; } -}; - bool CObjectManager::ObjectKey::operator< (const CObjectManager::ObjectKey& a) const { if (ActorName < a.ActorName) Index: source/graphics/ObjectManager.h =================================================================== --- source/graphics/ObjectManager.h (revision 7327) +++ source/graphics/ObjectManager.h (working copy) @@ -81,4 +81,20 @@ std::map m_ObjectBases; }; +// TODO Better place? ps/Util.h? graphics/Util.h? +template +static void delete_pair_2nd(std::pair v) +{ + delete v.second; +} + +template +struct second_equals +{ + T x; + second_equals(const T& x) : x(x) {} + template bool operator()(const S& v) { return v.second == x; } +}; + + #endif Index: source/graphics/ObjectEntry.cpp =================================================================== --- source/graphics/ObjectEntry.cpp (revision 7327) +++ source/graphics/ObjectEntry.cpp (working copy) @@ -45,8 +45,6 @@ { } -template static void delete_pair_2nd(std::pair v) { delete v.second; } - CObjectEntry::~CObjectEntry() { std::for_each(m_Animations.begin(), m_Animations.end(), delete_pair_2nd); Index: source/tools/atlas/GameInterface/View.cpp =================================================================== --- source/tools/atlas/GameInterface/View.cpp (revision 7327) +++ source/tools/atlas/GameInterface/View.cpp (working copy) @@ -32,15 +32,16 @@ #include "lib/wchar.h" #include "ps/Game.h" #include "ps/GameSetup/GameSetup.h" +#include "ps/GameSetup/Config.h" #include "ps/World.h" #include "renderer/Renderer.h" #include "simulation/Simulation.h" #include "simulation2/Simulation2.h" +#include "graphics/ObjectManager.h" // XXX Just for delete_pair_2nd ... + extern void (*Atlas_GLSwapBuffers)(void* context); -extern int g_xres, g_yres; - ////////////////////////////////////////////////////////////////////////// void View::SetParam(const std::wstring& UNUSED(name), bool UNUSED(value)) @@ -138,12 +139,6 @@ extern void AtlasRenderSelection(); } -template -static void delete_pair_2nd(std::pair v) -{ - delete v.second; -} - ViewGame::ViewGame() : m_SpeedMultiplier(0.f) { Index: source/scripting/ScriptableComplex.h =================================================================== --- source/scripting/ScriptableComplex.h (revision 7327) +++ source/scripting/ScriptableComplex.h (working copy) @@ -202,8 +202,8 @@ JSObject* GetScript() { if( !m_JS ) - CreateScriptObject(); - return( m_JS ); + CreateScriptObject(); + return( m_JS ); } CJSComplex(); Index: source/renderer/Renderer.cpp =================================================================== --- source/renderer/Renderer.cpp (revision 7327) +++ source/renderer/Renderer.cpp (working copy) @@ -25,6 +25,7 @@ #include #include #include +#include #include "lib/bits.h" // is_pow2 #include "lib/res/graphics/ogl_tex.h" #include "Renderer.h" @@ -1589,12 +1590,12 @@ textures[i] = ogl_tex_load(path/fnames[i]); RETURN_ERR(textures[i]); -// quick hack: we require plain RGB(A) format, so convert to that. -// ideally the texture would be in uncompressed form; then this wouldn't -// be necessary. -size_t flags; -ogl_tex_get_format(textures[i], &flags, 0); -ogl_tex_transform_to(textures[i], flags & ~TEX_DXT); + // quick hack: we require plain RGB(A) format, so convert to that. + // ideally the texture would be in uncompressed form; then this wouldn't + // be necessary. + size_t flags; + ogl_tex_get_format(textures[i], &flags, 0); + ogl_tex_transform_to(textures[i], flags & ~TEX_DXT); // get its size and make sure they are all equal. // (the packing algo assumes this) Index: source/lib/frequency_filter.cpp =================================================================== --- source/lib/frequency_filter.cpp (revision 7327) +++ source/lib/frequency_filter.cpp (working copy) @@ -152,7 +152,7 @@ private: bool WasOnSameSide(double value) const { - int sum = 0; + ssize_t sum = 0; for(size_t i = 0; i < m_historySize; i++) { const int vote = (value >= m_history[i])? 1 : -1; Index: source/lib/res/graphics/ogl_shader.cpp =================================================================== --- source/lib/res/graphics/ogl_shader.cpp (revision 7327) +++ source/lib/res/graphics/ogl_shader.cpp (working copy) @@ -38,10 +38,8 @@ #include "lib/file/vfs/vfs.h" extern PIVFS g_VFS; - #define LOG_CATEGORY L"shaders" - ERROR_ASSOCIATE(ERR::SHDR_CREATE, L"Shader creation failed", -1); ERROR_ASSOCIATE(ERR::SHDR_COMPILE, L"Shader compile failed", -1); ERROR_ASSOCIATE(ERR::SHDR_NO_SHADER, L"Invalid shader reference", -1); Index: source/lib/res/h_mgr.cpp =================================================================== --- source/lib/res/h_mgr.cpp (revision 7327) +++ source/lib/res/h_mgr.cpp (working copy) @@ -799,19 +799,18 @@ return hd->refs; } +static ModuleInitState h_mgr_initState; -static ModuleInitState initState; - void h_mgr_init() { - if(!ModuleShouldInitialize(&initState)) + if(!ModuleShouldInitialize(&h_mgr_initState)) return; } void h_mgr_shutdown() { - if(!ModuleShouldShutdown(&initState)) + if(!ModuleShouldShutdown(&h_mgr_initState)) return; debug_printf(L"H_MGR| shutdown. any handle frees after this are leaks!\n"); Index: source/simulation2/serialization/BinarySerializer.cpp =================================================================== --- source/simulation2/serialization/BinarySerializer.cpp (revision 7327) +++ source/simulation2/serialization/BinarySerializer.cpp (working copy) @@ -18,6 +18,7 @@ #include "precompiled.h" #include "BinarySerializer.h" +#include "RootWrapper.h" #include "SerializedScriptTypes.h" @@ -126,25 +127,6 @@ } }; -class RootWrapper -{ - JSContext* m_cx; - void* m_obj; -public: - // obj must be a JSObject** or JSString** or jsval* etc - RootWrapper(JSContext* cx, void* obj) : - m_cx(cx), m_obj(obj) - { - if (!JS_AddRoot(m_cx, m_obj)) - throw PSERROR_Serialize_ScriptError("JS_AddRoot failed"); - } - ~RootWrapper() - { - if (!JS_RemoveRoot(m_cx, m_obj)) - throw PSERROR_Serialize_ScriptError("JS_RemoveRoot failed"); - } -}; - void CBinarySerializer::HandleScriptVal(jsval val) { JSContext* cx = m_ScriptInterface.GetContext(); Index: source/simulation2/serialization/RootWrapper.h =================================================================== --- source/simulation2/serialization/RootWrapper.h (revision 0) +++ source/simulation2/serialization/RootWrapper.h (revision 0) @@ -0,0 +1,27 @@ +#ifndef ROOTWRAPPER_H +#define ROOTWRAPPER_H + +#include "ISerializer.h" +#include "scriptinterface/ScriptInterface.h" +#include "js/jsapi.h" + +class RootWrapper +{ + JSContext* m_cx; + void* m_obj; +public: + // obj must be a JSObject** or JSString** or jsval* etc + RootWrapper(JSContext* cx, void* obj) : + m_cx(cx), m_obj(obj) + { + if (!JS_AddRoot(m_cx, m_obj)) + throw PSERROR_Serialize_ScriptError("JS_AddRoot failed"); + } + ~RootWrapper() + { + if (!JS_RemoveRoot(m_cx, m_obj)) + throw PSERROR_Serialize_ScriptError("JS_RemoveRoot failed"); + } +}; + +#endif // ROOTWRAPPER_H Index: source/simulation2/serialization/StdDeserializer.cpp =================================================================== --- source/simulation2/serialization/StdDeserializer.cpp (revision 7327) +++ source/simulation2/serialization/StdDeserializer.cpp (working copy) @@ -18,6 +18,7 @@ #include "precompiled.h" #include "StdDeserializer.h" +#include "RootWrapper.h" #include "SerializedScriptTypes.h" @@ -73,26 +74,6 @@ //////////////////////////////////////////////////////////////// -class RootWrapper -{ - JSContext* m_cx; - void* m_obj; -public: - // obj must be a JSObject** or JSString** or jsval* etc - RootWrapper(JSContext* cx, void* obj) : - m_cx(cx), m_obj(obj) - { - if (!JS_AddRoot(m_cx, m_obj)) - throw PSERROR_Deserialize_ScriptError("JS_AddRoot failed"); - } - ~RootWrapper() - { - if (!JS_RemoveRoot(m_cx, m_obj)) - throw PSERROR_Deserialize_ScriptError("JS_RemoveRoot failed"); - } -}; - - jsval CStdDeserializer::ReadScriptVal(JSObject* appendParent) { JSContext* cx = m_ScriptInterface.GetContext(); Index: build/premake/functions.lua =================================================================== --- build/premake/functions.lua (revision 7327) +++ build/premake/functions.lua (working copy) @@ -25,3 +25,7 @@ table.insert(list, v) end end + +function string.ends(String,End) + return End=='' or string.sub(String,-string.len(End))==End +end Index: build/premake/premake.lua =================================================================== --- build/premake/premake.lua (revision 7327) +++ build/premake/premake.lua (working copy) @@ -8,6 +8,7 @@ addoption("without-pch", "Disable generation and usage of precompiled headers") addoption("with-valgrind", "Enable using valgrind for debugging functionality") addoption("with-spidermonkey-tip", "Use SpiderMonkey from mozilla-central tip instead of the 1.6 release") +addoption("unity", "Create and use unity-build units instead of per-file compilation") use_dcdt = false -- disable it since it's a non-Free library @@ -286,8 +287,38 @@ -- 'trimprefix' (with Premake altered to recognise that) so the project -- will still point to the correct filenames. package.trimprefix = source_root - package.files = sourcesfromdirs(source_root, rel_source_dirs) + files = sourcesfromdirs(source_root, rel_source_dirs) + if options["unity"] then + unit = source_root .. package.name .. "_unity_unit.cpp" + -- TODO Should make sure that the file is only modified if the contents + -- changed. Should be pretty easy to write the "file" to a string, + -- compare that to the current contents (if any) and only output if + -- modified. + + -- Add src/ here since the source_root is not relative to the current working directory (which is build/premake/) but rather relative to build/workspaces/{gcc,vsX}/ + local f = io.open("src/" .. unit, "w") + package.files = { unit } + if f then + for i,v in pairs(files) do + -- FIXME Errors.cpp could be generated so as not to create conflicts, but for now let's just take the easy way out... + if string.ends(v, ".cpp") and not string.ends(v, "ps/Errors.cpp") then + f:write("#define LINE_ F"..i.."_LINE_\n") + f:write("#include \""..v.."\"\n") + f:write("#undef LINE_\n") + f:write("#undef LOG_CATEGORY\n") + else + tinsert(package.files, v) + end + end + f:close() + else + print("Whoops...") + end + else + package.files = files + end + -- Put the project-specific PCH directory at the start of the -- include path, so '#include "precompiled.h"' will look in -- there first