diff --git a/source/lib/allocators.h b/source/lib/allocators.h deleted file mode 100644 index 1d2fd37de8..0000000000 --- a/source/lib/allocators.h +++ /dev/null @@ -1,10 +0,0 @@ -// temporary "bridge" header to new lib/allocators location until -// all source files are adapted to match the new headers. - -#include "lib/allocators/allocators.h" -#include "lib/allocators/bucket.h" -#include "lib/allocators/dynarray.h" -#include "lib/allocators/headerless.h" -#include "lib/allocators/mem_util.h" -#include "lib/allocators/pool.h" - diff --git a/source/lib/file/path.cpp b/source/lib/file/path.cpp index 86ec90d9ee..5346afc0a8 100644 --- a/source/lib/file/path.cpp +++ b/source/lib/file/path.cpp @@ -21,6 +21,12 @@ ERROR_ASSOCIATE(ERR::PATH_ROOT_DIR_ALREADY_SET, "Attempting to set FS root dir more than once", -1); ERROR_ASSOCIATE(ERR::PATH_NOT_IN_ROOT_DIR, "Accessing a file that's outside of the root dir", -1); +bool exists(const Path& path) +{ + return fs::exists(path.external_directory_string()); +} + + // security check: only allow path_SetRoot once so that malicious code // cannot circumvent the VFS checks that disallow access to anything above diff --git a/source/lib/file/path.h b/source/lib/file/path.h index 847698b0da..6a83a013dd 100644 --- a/source/lib/file/path.h +++ b/source/lib/file/path.h @@ -32,6 +32,8 @@ struct PathTraits static internal_string_type to_internal(const external_string_type& src); }; +extern bool exists(const Path& path); + namespace ERR { diff --git a/source/lib/res/graphics/tests/test_tex.h b/source/lib/res/graphics/tests/test_tex.h index fd9d930ca1..783f9c0433 100644 --- a/source/lib/res/graphics/tests/test_tex.h +++ b/source/lib/res/graphics/tests/test_tex.h @@ -1,8 +1,8 @@ #include "lib/self_test.h" #include "lib/tex/tex.h" -#include "lib/res/graphics/tex_codec.h" -#include "lib/res/graphics/tex_internal.h" // tex_encode +#include "lib/tex/tex_codec.h" +#include "lib/allocators/allocators.h" // DummyDeleter class TestTex : public CxxTest::TestSuite { @@ -10,13 +10,12 @@ class TestTex : public CxxTest::TestSuite { // generate test data const size_t size = w*h*bpp/8; - u8* img = new u8[size]; - for(size_t i = 0; i < size; i++) - img[i] = rand() & 0xFF; + shared_ptr img(new u8[size]); + std::generate(img.get(), img.get()+size, rand); // wrap in Tex Tex t; - TS_ASSERT_OK(tex_wrap(w, h, bpp, flags, img, &t)); + TS_ASSERT_OK(tex_wrap(w, h, bpp, flags, img, 0, &t)); // encode to file format DynArray da; @@ -24,19 +23,18 @@ class TestTex : public CxxTest::TestSuite memset(&t, 0, sizeof(t)); // decode from file format - shared_ptr ptr(&da.base, DummyDeleter()); - TS_ASSERT_OK(tex_decode(ptr, da.cur_size, 0, &t)); + shared_ptr ptr(da.base, DummyDeleter()); + TS_ASSERT_OK(tex_decode(ptr, da.cur_size, &t)); // make sure pixel format gets converted completely to plain TS_ASSERT_OK(tex_transform_to(&t, 0)); // compare img - TS_ASSERT_SAME_DATA(tex_get_data(&t), img, size); + TS_ASSERT_SAME_DATA(tex_get_data(&t), img.get(), size); // cleanup tex_free(&t); TS_ASSERT_OK(da_free(&da)); - delete[] img; } public: @@ -57,7 +55,7 @@ public: char extension[30] = {'.'}; strcpy_s(extension+1, 29, c->name); // .. make sure the c->name hack worked - const TexCodecVTbl* correct_c; + const TexCodecVTbl* correct_c = 0; TS_ASSERT_OK(tex_codec_for_filename(extension, &correct_c)); TS_ASSERT_EQUALS(c, correct_c); @@ -105,29 +103,31 @@ public: // have mipmaps be created for a test image; check resulting size and pixels void test_mipmap_create() { - u8 img[] = { 0x10,0x20,0x30, 0x40,0x60,0x80, 0xA0,0xA4,0xA8, 0xC0,0xC1,0xC2 }; + u8 imgData[] = { 0x10,0x20,0x30, 0x40,0x60,0x80, 0xA0,0xA4,0xA8, 0xC0,0xC1,0xC2 }; + shared_ptr img(imgData, DummyDeleter()); // assumes 2x2 box filter algorithm with rounding - const u8 mipmap[] = { 0x6C,0x79,0x87 }; + static const u8 mipmap[] = { 0x6C,0x79,0x87 }; Tex t; - TS_ASSERT_OK(tex_wrap(2, 2, 24, 0, img, &t)); + TS_ASSERT_OK(tex_wrap(2, 2, 24, 0, img, 0, &t)); TS_ASSERT_OK(tex_transform_to(&t, TEX_MIPMAPS)); const u8* const out_img = tex_get_data(&t); TS_ASSERT_EQUALS((int)tex_img_size(&t), 12+3); - TS_ASSERT_SAME_DATA(out_img, img, 12); + TS_ASSERT_SAME_DATA(out_img, imgData, 12); TS_ASSERT_SAME_DATA(out_img+12, mipmap, 3); } void test_img_size() { - char dummy_img[100*100*4]; // required + u8 imgStorage[100*100*4]; // (prevent a needless heap alloc) + shared_ptr img(imgStorage, DummyDeleter()); Tex t; - TS_ASSERT_OK(tex_wrap(100, 100, 32, TEX_ALPHA, dummy_img, &t)); + TS_ASSERT_OK(tex_wrap(100, 100, 32, TEX_ALPHA, img, 0, &t)); TS_ASSERT_EQUALS((int)tex_img_size(&t), 40000); // DXT rounds up to 4x4 blocks; DXT1a is 4bpp Tex t2; - TS_ASSERT_OK(tex_wrap(97, 97, 4, DXT1A, dummy_img, &t2)); + TS_ASSERT_OK(tex_wrap(97, 97, 4, DXT1A, img, 0, &t2)); TS_ASSERT_EQUALS((int)tex_img_size(&t2), 5000); } }; diff --git a/source/lib/res/h_mgr.cpp b/source/lib/res/h_mgr.cpp index 054714d2a3..5dc58af109 100644 --- a/source/lib/res/h_mgr.cpp +++ b/source/lib/res/h_mgr.cpp @@ -17,7 +17,7 @@ #include // std::bad_alloc #include "lib/fnv_hash.h" -#include "lib/allocators.h" +#include "lib/allocators/allocators.h" // OverrunProtector #include "lib/module_init.h" diff --git a/source/lib/sysdep/win/wdir_watch.cpp b/source/lib/sysdep/win/wdir_watch.cpp index aee7f9c165..19933c00f8 100644 --- a/source/lib/sysdep/win/wdir_watch.cpp +++ b/source/lib/sysdep/win/wdir_watch.cpp @@ -16,7 +16,7 @@ #include #include "lib/path_util.h" -#include "lib/allocators.h" +#include "lib/allocators/allocators.h" // HACK, get rid of STATIC_STORAGE #include "lib/path_util.h" // path_is_subpath #include "win.h" #include "winit.h" diff --git a/source/lib/sysdep/win/whrt/counter.cpp b/source/lib/sysdep/win/whrt/counter.cpp index b54a45b7ac..f138f5ffc1 100644 --- a/source/lib/sysdep/win/whrt/counter.cpp +++ b/source/lib/sysdep/win/whrt/counter.cpp @@ -12,7 +12,7 @@ #include "counter.h" #include "lib/bits.h" -#include "lib/allocators.h" +#include "lib/sysdep/cpu.h" // cpu_CAS #include "tsc.h" #include "hpet.h" diff --git a/source/lib/sysdep/win/wposix/wfilesystem.cpp b/source/lib/sysdep/win/wposix/wfilesystem.cpp index e4df6a3220..ec42e5659d 100644 --- a/source/lib/sysdep/win/wposix/wfilesystem.cpp +++ b/source/lib/sysdep/win/wposix/wfilesystem.cpp @@ -1,7 +1,7 @@ #include "precompiled.h" #include "wfilesystem.h" -#include "lib/allocators.h" // single_calloc +#include "lib/allocators/allocators.h" // single_calloc #include "wposix_internal.h" #include "wtime_internal.h" // wtime_utc_filetime_to_time_t #include "crt_posix.h" // _rmdir, _access diff --git a/source/lib/tex/tex_internal.h b/source/lib/tex/tex_internal.h index 1d2d54df94..cbb5f835b9 100644 --- a/source/lib/tex/tex_internal.h +++ b/source/lib/tex/tex_internal.h @@ -11,7 +11,7 @@ #ifndef INCLUDED_TEX_INTERNAL #define INCLUDED_TEX_INTERNAL -#include "lib/allocators.h" // DynArray +#include "lib/allocators/dynarray.h" #include "lib/file/io/io.h" // io_Allocate /** diff --git a/source/main.cpp b/source/main.cpp index c661903455..425a8cdd47 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -45,8 +45,6 @@ that of Atlas depending on commandline parameters. extern bool g_TerrainModified; extern bool g_GameRestarted; -PIFrequencyFilter g_frequencyFilter; - void kill_mainloop(); diff --git a/source/network/Client.cpp b/source/network/Client.cpp index 7e114779e4..e4f435ae99 100644 --- a/source/network/Client.cpp +++ b/source/network/Client.cpp @@ -9,15 +9,12 @@ #include "ps/CLogger.h" #include "ps/CConsole.h" #include "ps/Game.h" +#include "ps/Globals.h" // g_frequencyFilter #include "ps/GameAttributes.h" #include "simulation/Simulation.h" #define LOG_CAT_NET "net" -#include "lib/frequency_filter.h" -extern PIFrequencyFilter g_frequencyFilter; - - CNetClient *g_NetClient=NULL; CNetClient::CServerSession::CServerSession(int sessionID, const CStrW& name): @@ -448,7 +445,7 @@ int CNetClient::StartGame() debug_printf("Client StartGame - sending end-of-batch ack\n"); // Send an end-of-batch message for turn 0 to signal that we're ready. CEndCommandBatch *pMsg=new CEndCommandBatch(); - pMsg->m_TurnLength=1000/g_frequencyFilter->SmoothedFrequency(); + pMsg->m_TurnLength=1000/g_frequencyFilter->StableFrequency(); Push(pMsg); return 0; } @@ -474,7 +471,7 @@ void CNetClient::NewTurn() //debug_printf("In NewTurn - sending ack\n"); CEndCommandBatch *pMsg=new CEndCommandBatch(); - pMsg->m_TurnLength=1000/g_frequencyFilter->SmoothedFrequency(); + pMsg->m_TurnLength=1000/g_frequencyFilter->StableFrequency(); // JW: it'd probably be nicer to get the FPS as a parameter Push(pMsg); } diff --git a/source/ps/Globals.cpp b/source/ps/Globals.cpp index 12c676a3e7..f71b0e37f2 100644 --- a/source/ps/Globals.cpp +++ b/source/ps/Globals.cpp @@ -1,8 +1,8 @@ #include "precompiled.h" - -#include "lib/input.h" #include "Globals.h" +#include "lib/external_libraries/sdl.h" + bool g_app_minimized = false; bool g_app_has_focus = true; @@ -14,6 +14,7 @@ int g_mouse_x = 50, g_mouse_y = 50; // (order is given by SDL_BUTTON_* constants). bool g_mouse_buttons[6] = {0}; +PIFrequencyFilter g_frequencyFilter; // updates the state of the above; never swallows messages. InReaction GlobalsInputHandler(const SDL_Event_* ev) diff --git a/source/ps/Globals.h b/source/ps/Globals.h index af1efdd999..2d6275fcf7 100644 --- a/source/ps/Globals.h +++ b/source/ps/Globals.h @@ -1,5 +1,5 @@ #include "lib/input.h" -#include "lib/external_libraries/sdl.h" +#include "lib/frequency_filter.h" // thin abstraction layer on top of SDL. // game code should use it instead of SDL_GetMouseState etc. because @@ -15,7 +15,7 @@ extern int g_mouse_x, g_mouse_y; * it represents a pressed key. * Updated by GlobalsInputHandler in response to key press/release events. */ -extern bool g_keys[SDLK_LAST]; +extern bool g_keys[]; /** * g_mouse_buttons: Mouse buttons states, indexed by SDL_BUTTON_* constants. @@ -29,3 +29,5 @@ extern bool g_keys[SDLK_LAST]; extern bool g_mouse_buttons[6]; extern InReaction GlobalsInputHandler(const SDL_Event_* ev); + +extern PIFrequencyFilter g_frequencyFilter; diff --git a/source/ps/XML/tests/test_Xeromyces.h b/source/ps/XML/tests/test_Xeromyces.h index a125e13f35..34a308b56d 100644 --- a/source/ps/XML/tests/test_Xeromyces.h +++ b/source/ps/XML/tests/test_Xeromyces.h @@ -1,21 +1,18 @@ #include "lib/self_test.h" #include "ps/XML/Xeromyces.h" -#include "lib/res/file/vfs.h" -#include "lib/res/file/path.h" -#include "lib/res/h_mgr.h" +#include "lib/file/vfs/vfs.h" +#include "lib/file/path.h" class TestXeromyces : public CxxTest::TestSuite { public: void test_paths() { - TS_ASSERT_OK(file_init()); - TS_ASSERT_OK(file_set_root_dir(0, "../data")); - vfs_init(); + TS_ASSERT_OK(path_SetRoot(0, "../data")); + PIVFS vfs = CreateVfs(); - TS_ASSERT_OK(vfs_mount("", "mods/_test.xero", VFS_MOUNT_RECURSIVE)); - TS_ASSERT_OK(vfs_set_write_target("mods/_test.xero")); + TS_ASSERT_OK(vfs->Mount("", "mods/_test.xero")); char xmbPath[PATH_MAX]; @@ -25,8 +22,6 @@ public: CXeromyces::GetXMBPath("a/b/test1.xml", "a/b/test1.xmb", xmbPath); TS_ASSERT_STR_EQUALS(xmbPath, "cache/mods/_test.xero/xmb/a/b/test1.xmb"); - vfs_shutdown(); - path_reset_root_dir(); - TS_ASSERT_OK(file_shutdown()); + path_ResetRootDir(); } }; diff --git a/source/ps/tests/test_CLogger.h b/source/ps/tests/test_CLogger.h index 601dd8f121..36d896d247 100644 --- a/source/ps/tests/test_CLogger.h +++ b/source/ps/tests/test_CLogger.h @@ -7,8 +7,8 @@ class TestCLogger : public CxxTest::TestSuite public: void test_basic() { - logger->Log(NORMAL, "", "Test 1"); - logger->Log(NORMAL, "", "Test 2"); + logger->Log(CLogger::Normal, "", "Test 1"); + logger->Log(CLogger::Normal, "", "Test 2"); ParseOutput(); @@ -29,15 +29,15 @@ public: std::string clipped (buflen-4, '*'); clipped += "..."; - logger->Log(NORMAL, "", msg0.c_str()); - logger->Log(NORMAL, "", msg1.c_str()); - logger->Log(NORMAL, "", msg2.c_str()); - logger->Log(NORMAL, "", msg3.c_str()); + logger->Log(CLogger::Normal, "", msg0.c_str()); + logger->Log(CLogger::Normal, "", msg1.c_str()); + logger->Log(CLogger::Normal, "", msg2.c_str()); + logger->Log(CLogger::Normal, "", msg3.c_str()); - logger->LogOnce(NORMAL, "", msg0.c_str()); - logger->LogOnce(NORMAL, "", msg1.c_str()); - logger->LogOnce(NORMAL, "", msg2.c_str()); - logger->LogOnce(NORMAL, "", msg3.c_str()); + logger->LogOnce(CLogger::Normal, "", msg0.c_str()); + logger->LogOnce(CLogger::Normal, "", msg1.c_str()); + logger->LogOnce(CLogger::Normal, "", msg2.c_str()); + logger->LogOnce(CLogger::Normal, "", msg3.c_str()); ParseOutput(); diff --git a/source/scripting/ScriptGlue.cpp b/source/scripting/ScriptGlue.cpp index c582a178d2..df0d79f763 100644 --- a/source/scripting/ScriptGlue.cpp +++ b/source/scripting/ScriptGlue.cpp @@ -27,6 +27,7 @@ #include "ps/CLogger.h" #include "ps/CStr.h" #include "ps/Game.h" +#include "ps/Globals.h" // g_frequencyFilter #include "ps/GameSetup/GameSetup.h" #include "ps/Hotkey.h" #include "ps/Interact.h" @@ -913,8 +914,6 @@ JSBool ResetGui(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) JSBool GetFps( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); - - extern PIFrequencyFilter g_frequencyFilter; *rval = INT_TO_JSVAL(g_frequencyFilter->StableFrequency()); return JS_TRUE; } diff --git a/source/scripting/ScriptableComplex.cpp b/source/scripting/ScriptableComplex.cpp index e31f44ba26..856ddb340a 100644 --- a/source/scripting/ScriptableComplex.cpp +++ b/source/scripting/ScriptableComplex.cpp @@ -2,7 +2,7 @@ #include "ScriptableComplex.h" #include "ScriptableComplex.inl" -#include "lib/allocators.h" +#include "lib/allocators/bucket.h" //----------------------------------------------------------------------------- // suballocator for CJSComplex.m_Properties elements diff --git a/source/simulation/LOSManager.cpp b/source/simulation/LOSManager.cpp index a1f6d847e6..fabf628ca8 100644 --- a/source/simulation/LOSManager.cpp +++ b/source/simulation/LOSManager.cpp @@ -11,7 +11,7 @@ #include "graphics/Unit.h" #include "maths/Bound.h" #include "graphics/Model.h" -#include "lib/allocators.h" +#include "lib/allocators/allocators.h" // matrix_alloc #include "lib/timer.h" diff --git a/source/simulation/TerritoryManager.cpp b/source/simulation/TerritoryManager.cpp index 6cc10216ed..832e68b0c4 100644 --- a/source/simulation/TerritoryManager.cpp +++ b/source/simulation/TerritoryManager.cpp @@ -8,7 +8,7 @@ #include "graphics/Model.h" #include "graphics/Terrain.h" #include "graphics/Unit.h" -#include "lib/allocators.h" +#include "lib/allocators/allocators.h" // matrix_alloc #include "lib/ogl.h" #include "lib/timer.h" #include "maths/Bound.h"