diff --git a/build/workspaces/required-libraries-linux.txt b/build/workspaces/required-libraries-linux.txt index e605b1c0f7..d8e3814e46 100755 --- a/build/workspaces/required-libraries-linux.txt +++ b/build/workspaces/required-libraries-linux.txt @@ -24,8 +24,7 @@ $GL := directory containing OpenGL headers. $binaries := directory containing system/ and data/ - OpenGL extensions: - download http://www.wildfiregames.com/~code/libraries/glext.h - ... and put it in $GL. + copy libraries/opengl/include/GL/glext.h to $GL. - SpiderMonkey [javascript] The source is *not* compatible with the mozjs libraries included in mozilla diff --git a/source/graphics/ObjectBase.cpp b/source/graphics/ObjectBase.cpp index 60f8485791..f43102a217 100644 --- a/source/graphics/ObjectBase.cpp +++ b/source/graphics/ObjectBase.cpp @@ -9,6 +9,7 @@ #include "ps/XML/Xeromyces.h" #include "ps/CLogger.h" #include "lib/timer.h" +#include "lib/rand.h" #include "maths/MathUtil.h" #define LOG_CATEGORY "graphics" diff --git a/source/graphics/ObjectEntry.cpp b/source/graphics/ObjectEntry.cpp index 378c5b8bc9..f32348da50 100644 --- a/source/graphics/ObjectEntry.cpp +++ b/source/graphics/ObjectEntry.cpp @@ -17,6 +17,7 @@ #include "ps/XML/XMLWriter.h" #include "lib/res/file/vfs.h" +#include "lib/rand.h" #include diff --git a/source/gui/CGUIScrollBarStyle.cpp b/source/gui/CGUIScrollBarStyle.cpp deleted file mode 100644 index b372e6df02..0000000000 --- a/source/gui/CGUIScrollBarStyle.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* -SGUIScrollBarStyle -*/ - -#include "precompiled.h" -#include "GUI.h" - -using namespace std; diff --git a/source/lib/external_libraries/openal.h b/source/lib/external_libraries/openal.h new file mode 100644 index 0000000000..bf8be14d28 --- /dev/null +++ b/source/lib/external_libraries/openal.h @@ -0,0 +1,26 @@ +/** + * ========================================================================= + * File : openal.h + * Project : 0 A.D. + * Description : bring in OpenAL header+library, with compatibility fixes + * ========================================================================= + */ + +// license: GPL; see lib/license.txt + +#ifndef INCLUDED_OPENAL +#define INCLUDED_OPENAL + +#ifdef __APPLE__ +# include +# include +#else +# include +# include +#endif + +#if MSC_VERSION +# pragma comment(lib, "openal32.lib") +#endif + +#endif // #ifndef INCLUDED_OPENAL diff --git a/source/lib/external_libraries/wxwidgets.h b/source/lib/external_libraries/wxwidgets.h index 1578bb22d7..c3efc873f0 100644 --- a/source/lib/external_libraries/wxwidgets.h +++ b/source/lib/external_libraries/wxwidgets.h @@ -23,55 +23,19 @@ struct HINSTANCE__ typedef struct HINSTANCE__* HINSTANCE; // definition as if STRICT were #defined -#include "wx/wx.h" +#include "wx/wxprec.h" #include "wx/file.h" #include "wx/ffile.h" #include "wx/filename.h" #include "wx/mimetype.h" - #include "wx/statline.h" - #include "wx/debugrpt.h" #ifdef __WXMSW__ #include "wx/evtloop.h" // for SetCriticalWindow() #endif // __WXMSW__ - -// automatically link against the required library -#if MSC_VERSION -# ifdef NDEBUG -# else -# pragma comment(lib, "wxmsw28ud_core.lib") -# pragma comment(lib, "wxmsw28ud_qa.lib") -# pragma comment(lib, "wxbase28ud.lib") -# pragma comment(lib, "wxbase28ud_xml.lib") - - -//# pragma comment(lib, "wxbase28ud_net.lib") -//# pragma comment(lib, "wxbase28ud_odbc.lib") -//# pragma comment(lib, "wxmsw28ud_adv.lib") -//# pragma comment(lib, "wxmsw28ud_aui.lib") -//# pragma comment(lib, "wxmsw28ud_dbgrid.lib") -//# pragma comment(lib, "wxmsw28ud_gl.lib") -//# pragma comment(lib, "wxmsw28ud_html.lib") -//# pragma comment(lib, "wxmsw28ud_media.lib") -//# pragma comment(lib, "wxmsw28ud_richtext.lib") -//# pragma comment(lib, "wxmsw28ud_xrc.lib") -//# pragma comment(lib, "wxexpatd.lib") -//# pragma comment(lib, "wxpngd.lib") -//# pragma comment(lib, "wxjpegd.lib") -//# pragma comment(lib, "wxtiffd.lib") -//# pragma comment(lib, "wxzlibd.lib") -//# pragma comment(lib, "wxregexd.lib") - -# pragma comment(lib, "Rpcrt4.lib") // Uuid -# pragma comment(lib, "comctl32.lib") // ImageList_* - - -# endif // NDEBUG -#endif // MSC_VERSION - +// note: wxWidgets already does #pragma comment(lib) to add link targets. #endif // #ifndef INCLUDED_WXWIDGETS diff --git a/source/lib/lib.cpp b/source/lib/lib.cpp index 80d6907ddc..40004308df 100644 --- a/source/lib/lib.cpp +++ b/source/lib/lib.cpp @@ -35,57 +35,6 @@ u16 subusw(u16 x, u16 y) //----------------------------------------------------------------------------- // rand -// return random integer in [min, max). -// avoids several common pitfalls; see discussion at -// http://www.azillionmonkeys.com/qed/random.html - -// rand() is poorly implemented (e.g. in VC7) and only returns < 16 bits; -// double that amount by concatenating 2 random numbers. -// this is not to fix poor rand() randomness - the number returned will be -// folded down to a much smaller interval anyway. instead, a larger XRAND_MAX -// decreases the probability of having to repeat the loop. -#if RAND_MAX < 65536 -static const uint XRAND_MAX = (RAND_MAX+1)*(RAND_MAX+1) - 1; -static uint xrand() -{ - return rand()*(RAND_MAX+1) + rand(); -} -// rand() is already ok; no need to do anything. -#else -static const uint XRAND_MAX = RAND_MAX; -static uint xrand() -{ - return rand(); -} -#endif - -uint rand(uint min_inclusive, uint max_exclusive) -{ - const uint range = (max_exclusive-min_inclusive); - // huge interval or min >= max - if(range == 0 || range > XRAND_MAX) - { - WARN_ERR(ERR::INVALID_PARAM); - return 0; - } - - const uint inv_range = XRAND_MAX / range; - - // generate random number in [0, range) - // idea: avoid skewed distributions when doesn't evenly divide - // XRAND_MAX by simply discarding values in the "remainder". - // not expected to run often since XRAND_MAX is large. - uint x; - do - x = xrand(); - while(x >= range * inv_range); - x /= inv_range; - - x += min_inclusive; - debug_assert(x < max_exclusive); - return x; -} - //----------------------------------------------------------------------------- // type conversion diff --git a/source/lib/lib.h b/source/lib/lib.h index 69970adda2..b58a9b5e8f 100644 --- a/source/lib/lib.h +++ b/source/lib/lib.h @@ -207,14 +207,6 @@ inline bool feqf(float f1, float f2, float epsilon = 0.001f) } -/** - * return random integer in [min, max). - * avoids several common pitfalls; see discussion at - * http://www.azillionmonkeys.com/qed/random.html - **/ -extern uint rand(uint min_inclusive, uint max_exclusive); - - //----------------------------------------------------------------------------- // type conversion diff --git a/source/lib/rand.cpp b/source/lib/rand.cpp new file mode 100644 index 0000000000..57cd37c065 --- /dev/null +++ b/source/lib/rand.cpp @@ -0,0 +1,62 @@ +/** + * ========================================================================= + * File : rand.cpp + * Project : 0 A.D. + * Description : pseudorandom number generator + * ========================================================================= + */ + +// license: GPL; see lib/license.txt + +#include "precompiled.h" +#include "rand.h" + +// avoids several common pitfalls; see discussion at +// http://www.azillionmonkeys.com/qed/random.html + +// rand() is poorly implemented (e.g. in VC7) and only returns < 16 bits; +// double that amount by concatenating 2 random numbers. +// this is not to fix poor rand() randomness - the number returned will be +// folded down to a much smaller interval anyway. instead, a larger XRAND_MAX +// decreases the probability of having to repeat the loop. +#if RAND_MAX < 65536 +static const uint XRAND_MAX = (RAND_MAX+1)*(RAND_MAX+1) - 1; +static uint xrand() +{ + return rand()*(RAND_MAX+1) + rand(); +} +// rand() is already ok; no need to do anything. +#else +static const uint XRAND_MAX = RAND_MAX; +static uint xrand() +{ + return rand(); +} +#endif + +uint rand(uint min_inclusive, uint max_exclusive) +{ + const uint range = (max_exclusive-min_inclusive); + // huge interval or min >= max + if(range == 0 || range > XRAND_MAX) + { + WARN_ERR(ERR::INVALID_PARAM); + return 0; + } + + const uint inv_range = XRAND_MAX / range; + + // generate random number in [0, range) + // idea: avoid skewed distributions when doesn't evenly divide + // XRAND_MAX by simply discarding values in the "remainder". + // not expected to run often since XRAND_MAX is large. + uint x; + do + x = xrand(); + while(x >= range * inv_range); + x /= inv_range; + + x += min_inclusive; + debug_assert(x < max_exclusive); + return x; +} diff --git a/source/lib/rand.h b/source/lib/rand.h new file mode 100644 index 0000000000..3d3d9e248e --- /dev/null +++ b/source/lib/rand.h @@ -0,0 +1,21 @@ +/** + * ========================================================================= + * File : rand.h + * Project : 0 A.D. + * Description : pseudorandom number generator + * ========================================================================= + */ + +// license: GPL; see lib/license.txt + +#ifndef INCLUDED_RAND +#define INCLUDED_RAND + +/** + * return random integer in [min, max). + * avoids several common pitfalls; see discussion at + * http://www.azillionmonkeys.com/qed/random.html + **/ +extern uint rand(uint min_inclusive, uint max_exclusive); + +#endif // #ifndef INCLUDED_RAND diff --git a/source/lib/res/file/path.cpp b/source/lib/res/file/path.cpp index 5980f5e722..388190b94e 100644 --- a/source/lib/res/file/path.cpp +++ b/source/lib/res/file/path.cpp @@ -15,6 +15,7 @@ #include "lib/posix/posix_filesystem.h" #include "lib/adts.h" +#include "lib/rand.h" #include "lib/allocators.h" #include "lib/sysdep/sysdep.h" #include "file_internal.h" diff --git a/source/lib/res/file/tests/test_archive_builder.h b/source/lib/res/file/tests/test_archive_builder.h index 23fddb010e..e95ccb4144 100644 --- a/source/lib/res/file/tests/test_archive_builder.h +++ b/source/lib/res/file/tests/test_archive_builder.h @@ -9,6 +9,7 @@ #include "lib/res/file/archive_builder.h" #include "lib/res/h_mgr.h" #include "lib/res/mem.h" +#include "lib/rand.h" class TestArchiveBuilder : public CxxTest::TestSuite { diff --git a/source/lib/res/file/tests/test_file_cache.h b/source/lib/res/file/tests/test_file_cache.h index 1ca476541d..4ad849b5a3 100644 --- a/source/lib/res/file/tests/test_file_cache.h +++ b/source/lib/res/file/tests/test_file_cache.h @@ -1,6 +1,7 @@ #include "lib/self_test.h" #include "lib/res/file/file_cache.h" +#include "lib/rand.h" class TestFileCache : public CxxTest::TestSuite { diff --git a/source/lib/res/sound/snd_mgr.cpp b/source/lib/res/sound/snd_mgr.cpp index 588b7120bd..d6f7eaf168 100644 --- a/source/lib/res/sound/snd_mgr.cpp +++ b/source/lib/res/sound/snd_mgr.cpp @@ -19,15 +19,7 @@ #include #include -#include "maths/MathUtil.h" - -#ifdef __APPLE__ -# include -# include -#else -# include -# include -#endif +#include "maths/MathUtil.h" // PI // for DLL-load hack in alc_init #if OS_WIN @@ -37,15 +29,11 @@ #include "lib/res/res.h" #include "lib/timer.h" #include "lib/app_hooks.h" +#include "lib/external_libraries/openal.h" #define OGG_HACK #include "ogghack.h" - -#if MSC_VERSION -# pragma comment(lib, "openal32.lib") -#endif - // HACK: OpenAL loads and unloads certain DLLs several times on Windows. // that looks unnecessary and wastes 100..400 ms on startup. // we hold a reference to prevent the actual unload. everything works ATM; diff --git a/source/lib/sysdep/cpu.cpp b/source/lib/sysdep/cpu.cpp index c41faefc3e..8722c88b84 100644 --- a/source/lib/sysdep/cpu.cpp +++ b/source/lib/sysdep/cpu.cpp @@ -17,7 +17,7 @@ # include "lib/sysdep/ia32/ia32.h" # include "lib/sysdep/ia32/ia32_memcpy.h" #endif -#if OS_BSD || OS_MACOSX +#if OS_BSD # include "lib/sysdep/unix/bsd.h" #endif #if OS_WIN diff --git a/source/lib/sysdep/unix/bsd.cpp b/source/lib/sysdep/unix/bsd.cpp index b0dc01e854..8ae1b97e18 100644 --- a/source/lib/sysdep/unix/bsd.cpp +++ b/source/lib/sysdep/unix/bsd.cpp @@ -1,7 +1,7 @@ #include "precompiled.h" #include "bsd.h" -#if OS_BSD || OS_MACOSX +#if OS_BSD #include diff --git a/source/lib/tests/test_adts.h b/source/lib/tests/test_adts.h index 74ba8d7e09..b76d696359 100644 --- a/source/lib/tests/test_adts.h +++ b/source/lib/tests/test_adts.h @@ -1,6 +1,7 @@ #include "lib/self_test.h" #include "lib/adts.h" +#include "lib/rand.h" class TestRingbuf : public CxxTest::TestSuite { diff --git a/source/lib/tests/test_cache_adt.h b/source/lib/tests/test_cache_adt.h index d4365a4f42..4f1c179bba 100644 --- a/source/lib/tests/test_cache_adt.h +++ b/source/lib/tests/test_cache_adt.h @@ -1,6 +1,7 @@ #include "lib/self_test.h" #include "lib/cache_adt.h" +#include "lib/rand.h" class TestCache: public CxxTest::TestSuite { diff --git a/source/lib/tests/test_lib.h b/source/lib/tests/test_lib.h index 066486a128..1bce91ce41 100644 --- a/source/lib/tests/test_lib.h +++ b/source/lib/tests/test_lib.h @@ -43,33 +43,4 @@ public: } // fp_to_u?? already validate the result. - - void test_rand() - { - // complain if huge interval or min > max - debug_skip_next_err(ERR::INVALID_PARAM); - TS_ASSERT_EQUALS(rand(1, 0), 0); - debug_skip_next_err(ERR::INVALID_PARAM); - TS_ASSERT_EQUALS(rand(2, ~0u), 0); - - // returned number must be in [min, max) - for(int i = 0; i < 100; i++) - { - uint min = rand(), max = min+rand(); - uint x = rand(min, max); - TS_ASSERT(min <= x && x < max); - } - - // make sure both possible values are hit - uint ones = 0, twos = 0; - for(int i = 0; i < 100; i++) - { - uint x = rand(1, 3); - // paranoia: don't use array (x might not be 1 or 2 - checked below) - if(x == 1) ones++; - if(x == 2) twos++; - } - TS_ASSERT_EQUALS(ones+twos, 100); - TS_ASSERT(ones > 10 && twos > 10); - } }; diff --git a/source/lib/tests/test_lockfree.h b/source/lib/tests/test_lockfree.h index b2d3c0e459..2b63575715 100644 --- a/source/lib/tests/test_lockfree.h +++ b/source/lib/tests/test_lockfree.h @@ -3,6 +3,7 @@ #include "lib/lockfree.h" #include "lib/sysdep/cpu.h" // atomic_add #include "lib/timer.h" +#include "lib/rand.h" // make sure the data structures work at all; doesn't test thread-safety. class TestLockfreeBasic : public CxxTest::TestSuite diff --git a/source/lib/tests/test_rand.h b/source/lib/tests/test_rand.h new file mode 100644 index 0000000000..a0c635f755 --- /dev/null +++ b/source/lib/tests/test_rand.h @@ -0,0 +1,42 @@ +#include "lib/self_test.h" + +#include "lib/rand.h" + +class TestRand : public CxxTest::TestSuite +{ +public: + // complain if huge interval or min > max + void TestParam() + { + debug_skip_next_err(ERR::INVALID_PARAM); + TS_ASSERT_EQUALS(rand(1, 0), 0); + debug_skip_next_err(ERR::INVALID_PARAM); + TS_ASSERT_EQUALS(rand(2, ~0u), 0); + } + + // returned number must be in [min, max) + void TestReturnedRange() + { + for(int i = 0; i < 100; i++) + { + uint min = rand(), max = min+rand(); + uint x = rand(min, max); + TS_ASSERT(min <= x && x < max); + } + } + + // make sure both possible values are hit + void TestTwoValues() + { + uint ones = 0, twos = 0; + for(int i = 0; i < 100; i++) + { + uint x = rand(1, 3); + // paranoia: don't use array (x might not be 1 or 2 - checked below) + if(x == 1) ones++; + if(x == 2) twos++; + } + TS_ASSERT_EQUALS(ones+twos, 100); + TS_ASSERT(ones > 10 && twos > 10); + } +}; diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index bb422ecb3c..5e71d4f169 100644 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -21,6 +21,8 @@ #include "ps/Game.h" #include "ps/World.h" +#include "lib/rand.h" + enum EGotoSituation { NORMAL = 0, diff --git a/source/sound/SoundGroup.cpp b/source/sound/SoundGroup.cpp index ee708b5151..3cbeeeb643 100644 --- a/source/sound/SoundGroup.cpp +++ b/source/sound/SoundGroup.cpp @@ -16,6 +16,7 @@ #include "ps/XML/Xeromyces.h" #include "ps/CLogger.h" +#include "lib/rand.h" #define LOG_CATEGORY "audio"