mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
cleanup
reduce dependency on PCH. move KiB constants to alignment, ARRAY_SIZE to code_annotation.h. move glext_funcs.h to external_libraries/glext_funcs.h, move part of ogl.h to external_libraries/opengl.h remove unused saturating arithmetic functions This was SVN commit r9363.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "graphics/TextureConverter.h"
|
||||
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
#include "lib/res/h_mgr.h"
|
||||
#include "lib/tex/tex.h"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "lib/self_test.h"
|
||||
|
||||
#include "graphics/TextureManager.h"
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/external_libraries/sdl.h"
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
#include "lib/res/h_mgr.h"
|
||||
|
||||
+10
-3
@@ -18,9 +18,6 @@ inline size_t Align(size_t n)
|
||||
}
|
||||
|
||||
|
||||
static const size_t allocationAlignment = ARCH_AMD64? 16 : 8;
|
||||
|
||||
|
||||
//
|
||||
// SIMD vector
|
||||
//
|
||||
@@ -54,6 +51,16 @@ static const size_t pageSize = 0x1000; // 4 KB
|
||||
static const size_t largePageSize = 0x200000; // 2 MB
|
||||
|
||||
|
||||
//
|
||||
// misc
|
||||
//
|
||||
|
||||
static const size_t allocationAlignment = ARCH_AMD64? 16 : 8;
|
||||
|
||||
static const size_t KiB = size_t(1) << 10;
|
||||
static const size_t MiB = size_t(1) << 20;
|
||||
static const size_t GiB = size_t(1) << 30;
|
||||
|
||||
// waio opens files with FILE_FLAG_NO_BUFFERING, so Windows requires
|
||||
// file offsets / buffers and sizes to be sector-aligned. querying the
|
||||
// actual sector size via GetDiskFreeSpace is inconvenient and slow.
|
||||
|
||||
@@ -134,8 +134,12 @@ switch(x % 2)
|
||||
#define UID__ PASTE3__(LINE_, __LINE__, _)
|
||||
#define UID2__ PASTE3__(LINE_, __LINE__, _2)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// cassert
|
||||
|
||||
/**
|
||||
* Compile-time ENSURE. Causes a compile error if the expression
|
||||
* Compile-time assertion. Causes a compile error if the expression
|
||||
* evaluates to zero/false.
|
||||
*
|
||||
* No runtime overhead; may be used anywhere, including file scope.
|
||||
@@ -164,7 +168,8 @@ template<> struct static_assert_<true>
|
||||
* This version has a less helpful error message, but redefinition doesn't
|
||||
* trigger warnings.
|
||||
**/
|
||||
#define cassert2(expr) extern u8 CASSERT_FAILURE[1][(expr)]
|
||||
#define cassert2(expr) extern char CASSERT_FAILURE[1][(expr)]
|
||||
|
||||
|
||||
// indicate a class is noncopyable (usually due to const or reference members).
|
||||
// example:
|
||||
@@ -281,6 +286,33 @@ private:\
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// number of array elements
|
||||
//
|
||||
|
||||
#if GCC_VERSION
|
||||
|
||||
// The function trick below does not work in GCC. Instead use the old fashioned
|
||||
// divide-by-sizeof-element. This causes problems when the argument to
|
||||
// ARRAY_SIZE is a pointer and not an array, but we will catch those when we
|
||||
// compile on something other than GCC.
|
||||
|
||||
#define ARRAY_SIZE(name) (sizeof(name) / (sizeof((name)[0])))
|
||||
|
||||
#else
|
||||
|
||||
// (function taking a reference to an array and returning a pointer to
|
||||
// an array of characters. it's only declared and never defined; we just
|
||||
// need it to determine n, the size of the array that was passed.)
|
||||
template<typename T, size_t n> char (*ArraySizeDeducer(T (&)[n]))[n];
|
||||
|
||||
// (although requiring C++, this method is much better than the standard
|
||||
// sizeof(name) / sizeof(name[0]) because it doesn't compile when a
|
||||
// pointer is passed, which can easily happen under maintenance.)
|
||||
#define ARRAY_SIZE(name) (sizeof(*ArraySizeDeducer(name)))
|
||||
|
||||
#endif // GCC_VERSION
|
||||
|
||||
// C99-style __func__
|
||||
// .. newer GCC already have it
|
||||
#if GCC_VERSION >= 300
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/app_hooks.h"
|
||||
#include "lib/allocators/page_aligned.h"
|
||||
#include "lib/fnv_hash.h"
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/* Copyright (c) 2011 Wildfire Games
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* bring in OpenGL header+library, with compatibility fixes
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_OPENGL
|
||||
#define INCLUDED_OPENGL
|
||||
|
||||
#if OS_WIN
|
||||
// wgl.h is a private header and should only be included from here.
|
||||
// if this isn't defined, it'll complain.
|
||||
#define WGL_HEADER_NEEDED
|
||||
#include "lib/sysdep/os/win/wgl.h"
|
||||
#endif
|
||||
|
||||
#if OS_MACOSX || OS_MAC
|
||||
# include <OpenGL/gl.h>
|
||||
#else
|
||||
# include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
// if gl.h provides real prototypes for 1.2 / 1.3 functions,
|
||||
// exclude the corresponding function pointers in glext_funcs.h
|
||||
#ifdef GL_VERSION_1_2
|
||||
#define REAL_GL_1_2
|
||||
#endif
|
||||
#ifdef GL_VERSION_1_3
|
||||
#define REAL_GL_1_3
|
||||
#endif
|
||||
|
||||
// this must come after GL/gl.h include, so we can't combine the
|
||||
// including GL/glext.h.
|
||||
#undef GL_GLEXT_PROTOTYPES
|
||||
|
||||
#if OS_MACOSX || OS_MAC
|
||||
# include <OpenGL/glext.h>
|
||||
#else
|
||||
# include <GL/glext.h>
|
||||
# if OS_WIN
|
||||
# include <GL/wglext.h>
|
||||
# define GL_TEXTURE_IMAGE_SIZE_ARB 0x86A0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif // #ifndef INCLUDED_OPENGL
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/file/archive/codec_zlib.h"
|
||||
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/file/archive/codec.h"
|
||||
#include "lib/external_libraries/zlib.h"
|
||||
|
||||
|
||||
@@ -35,19 +35,6 @@
|
||||
#include "lib/sysdep/sysdep.h"
|
||||
|
||||
|
||||
u16 addusw(u16 x, u16 y)
|
||||
{
|
||||
u32 t = x;
|
||||
return (u16)std::min(t+y, 0xFFFFu);
|
||||
}
|
||||
|
||||
u16 subusw(u16 x, u16 y)
|
||||
{
|
||||
long t = x;
|
||||
return (u16)(std::max(t-y, 0l));
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// type conversion
|
||||
|
||||
|
||||
+2
-46
@@ -60,49 +60,10 @@ scope
|
||||
#ifndef INCLUDED_LIB
|
||||
#define INCLUDED_LIB
|
||||
|
||||
#include <math.h> // fabsf
|
||||
#include <cmath> // fabsf
|
||||
#include <limits> // numeric_limits
|
||||
#include <stdexcept> // out_of_range
|
||||
|
||||
#include "lib/config.h"
|
||||
#include "lib/debug.h"
|
||||
|
||||
|
||||
const size_t KiB = size_t(1) << 10;
|
||||
const size_t MiB = size_t(1) << 20;
|
||||
const size_t GiB = size_t(1) << 30;
|
||||
|
||||
|
||||
//
|
||||
// number of array elements
|
||||
//
|
||||
|
||||
#if GCC_VERSION
|
||||
|
||||
// The function trick below does not work in GCC. Instead use the old fashioned
|
||||
// divide-by-sizeof-element. This causes problems when the argument to
|
||||
// ARRAY_SIZE is a pointer and not an array, but we will catch those when we
|
||||
// compile on something other than GCC.
|
||||
|
||||
#define ARRAY_SIZE(name) (sizeof(name) / (sizeof((name)[0])))
|
||||
|
||||
#else
|
||||
|
||||
// (function taking a reference to an array and returning a pointer to
|
||||
// an array of characters. it's only declared and never defined; we just
|
||||
// need it to determine n, the size of the array that was passed.)
|
||||
template<typename T, size_t n> u8 (*ArraySizeDeducer(T (&)[n]))[n];
|
||||
|
||||
// (although requiring C++, this method is much better than the standard
|
||||
// sizeof(name) / sizeof(name[0]) because it doesn't compile when a
|
||||
// pointer is passed, which can easily happen under maintenance.)
|
||||
#define ARRAY_SIZE(name) (sizeof(*ArraySizeDeducer(name)))
|
||||
|
||||
#endif // GCC_VERSION
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
T Clamp(T val, T min, T max)
|
||||
{
|
||||
@@ -117,11 +78,6 @@ T DivideRoundUp(T dividend, T divisor)
|
||||
return (dividend + divisor-1) / divisor;
|
||||
}
|
||||
|
||||
/// 16-bit saturating (does not overflow) addition.
|
||||
extern u16 addusw(u16 x, u16 y);
|
||||
/// 16-bit saturating (does not underflow) subtraction.
|
||||
extern u16 subusw(u16 x, u16 y);
|
||||
|
||||
/**
|
||||
* are the given floats nearly "equal"?
|
||||
*
|
||||
@@ -134,7 +90,7 @@ extern u16 subusw(u16 x, u16 y);
|
||||
* - floating-point numbers don't magically lose precision. addition,
|
||||
* subtraction and multiplication results are precise up to the mantissa's
|
||||
* least-significant bit. only division, sqrt, sin/cos and other
|
||||
* trancendental operations introduce error.
|
||||
* transcendental operations introduce error.
|
||||
**/
|
||||
inline bool feq(double d1, double d2, double epsilon = 0.00001)
|
||||
{
|
||||
|
||||
+2
-2
@@ -51,7 +51,7 @@ extern "C"
|
||||
#define FUNC(ret, name, params) ret (GL_CALL_CONV *p##name) params;
|
||||
#define FUNC2(ret, nameARB, nameCore, version, params) ret (GL_CALL_CONV *p##nameARB) params;
|
||||
#define FUNC3(ret, nameARB, nameCore, version, params) ret (GL_CALL_CONV *p##nameCore) params;
|
||||
#include "lib/glext_funcs.h"
|
||||
#include "lib/external_libraries/glext_funcs.h"
|
||||
#undef FUNC3
|
||||
#undef FUNC2
|
||||
#undef FUNC
|
||||
@@ -325,7 +325,7 @@ static void importExtensionFunctions()
|
||||
pname = (ret (GL_CALL_CONV*) params)SDL_GL_GetProcAddress(#nameARB);
|
||||
#define FUNC2(ret, nameARB, nameCore, version, params) FUNC23(p##nameARB, ret, nameARB, nameCore, version, params)
|
||||
#define FUNC3(ret, nameARB, nameCore, version, params) FUNC23(p##nameCore, ret, nameARB, nameCore, version, params)
|
||||
#include "lib/glext_funcs.h"
|
||||
#include "lib/external_libraries/glext_funcs.h"
|
||||
#undef FUNC3
|
||||
#undef FUNC2
|
||||
#undef FUNC23
|
||||
|
||||
+2
-41
@@ -27,46 +27,7 @@
|
||||
#ifndef INCLUDED_OGL
|
||||
#define INCLUDED_OGL
|
||||
|
||||
#if OS_WIN
|
||||
// wgl.h is a private header and should only be included from here.
|
||||
// if this isn't defined, it'll complain.
|
||||
#define WGL_HEADER_NEEDED
|
||||
#include "lib/sysdep/os/win/wgl.h"
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// bring in the platform's OpenGL headers (with fixes, if necessary)
|
||||
//
|
||||
|
||||
#if OS_MACOSX || OS_MAC
|
||||
# include <OpenGL/gl.h>
|
||||
#else
|
||||
# include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
// if gl.h provides real prototypes for 1.2 / 1.3 functions,
|
||||
// exclude the corresponding function pointers in glext_funcs.h
|
||||
#ifdef GL_VERSION_1_2
|
||||
#define REAL_GL_1_2
|
||||
#endif
|
||||
#ifdef GL_VERSION_1_3
|
||||
#define REAL_GL_1_3
|
||||
#endif
|
||||
|
||||
// this must come after GL/gl.h include, so we can't combine the
|
||||
// including GL/glext.h.
|
||||
#undef GL_GLEXT_PROTOTYPES
|
||||
|
||||
#if OS_MACOSX || OS_MAC
|
||||
# include <OpenGL/glext.h>
|
||||
#else
|
||||
# include <GL/glext.h>
|
||||
# if OS_WIN
|
||||
# include <GL/wglext.h>
|
||||
# define GL_TEXTURE_IMAGE_SIZE_ARB 0x86A0
|
||||
# endif
|
||||
#endif
|
||||
#include "lib/external_libraries/opengl.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -131,7 +92,7 @@ extern const char* ogl_ExtensionString();
|
||||
#define FUNC(ret, name, params) EXTERN_C ret (GL_CALL_CONV *p##name) params;
|
||||
#define FUNC2(ret, nameARB, nameCore, version, params) EXTERN_C ret (GL_CALL_CONV *p##nameARB) params;
|
||||
#define FUNC3(ret, nameARB, nameCore, version, params) EXTERN_C ret (GL_CALL_CONV *p##nameCore) params;
|
||||
#include "lib/glext_funcs.h"
|
||||
#include "lib/external_libraries/glext_funcs.h"
|
||||
#undef FUNC3
|
||||
#undef FUNC2
|
||||
#undef FUNC
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <cstdio>
|
||||
#include <cfloat>
|
||||
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/res/h_mgr.h"
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "lib/sysdep/arch/x86_x64/cache.h"
|
||||
|
||||
#include "lib/bits.h"
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/module_init.h"
|
||||
#include "lib/sysdep/os_cpu.h"
|
||||
#include "lib/sysdep/arch/x86_x64/x86_x64.h"
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "lib/sysdep/os_cpu.h"
|
||||
|
||||
#include "lib/bits.h"
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/module_init.h"
|
||||
#include "lib/sysdep/os/win/wutil.h"
|
||||
#include "lib/sysdep/arch/x86_x64/x86_x64.h"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "lib/sysdep/numa.h"
|
||||
|
||||
#include "lib/bits.h" // PopulationCount
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/timer.h"
|
||||
#include "lib/module_init.h"
|
||||
#include "lib/allocators/page_aligned.h"
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/sysdep/sysdep.h"
|
||||
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/sysdep/os/win/win.h" // includes windows.h; must come before shlobj
|
||||
#include <shlobj.h> // pick_dir
|
||||
#include <shellapi.h> // open_url
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/sysdep/os_cpu.h"
|
||||
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/sysdep/smbios.h"
|
||||
|
||||
#if OS_WIN
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "lib/sysdep/smbios.h"
|
||||
|
||||
#include "lib/bits.h"
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/byte_order.h" // FOURCC_BE
|
||||
#include "lib/module_init.h"
|
||||
|
||||
|
||||
@@ -27,25 +27,6 @@
|
||||
class TestLib : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
// 16-bit saturating arithmetic
|
||||
void test_addusw()
|
||||
{
|
||||
TS_ASSERT_EQUALS(addusw(4u, 0x100u), 0x0104u);
|
||||
TS_ASSERT_EQUALS(addusw(0u, 0xFFFFu), 0xFFFFu);
|
||||
TS_ASSERT_EQUALS(addusw(0x8000u, 0x8000u), 0xFFFFu);
|
||||
TS_ASSERT_EQUALS(addusw(0xFFF0u, 0x0004u), 0xFFF4u);
|
||||
TS_ASSERT_EQUALS(addusw(0xFFFFu, 0xFFFFu), 0xFFFFu);
|
||||
}
|
||||
|
||||
void test_subusw()
|
||||
{
|
||||
TS_ASSERT_EQUALS(subusw(4u, 0x100u), 0u);
|
||||
TS_ASSERT_EQUALS(subusw(100u, 90u), 10u);
|
||||
TS_ASSERT_EQUALS(subusw(0x8000u, 0x8000u), 0u);
|
||||
TS_ASSERT_EQUALS(subusw(0x0FFFu, 0xFFFFu), 0u);
|
||||
TS_ASSERT_EQUALS(subusw(0xFFFFu, 0x0FFFu), 0xF000u);
|
||||
}
|
||||
|
||||
void test_hi_lo()
|
||||
{
|
||||
TS_ASSERT_EQUALS(u64_hi(0x0123456789ABCDEFull), 0x01234567u);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "graphics/LightEnv.h"
|
||||
#include "graphics/Patch.h"
|
||||
#include "graphics/Terrain.h"
|
||||
#include "lib/alignment.h"
|
||||
#include "lib/allocators/pool.h"
|
||||
#include "lib/res/graphics/unifont.h"
|
||||
#include "maths/MathUtil.h"
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "SerializedScriptTypes.h"
|
||||
|
||||
#include "lib/alignment.h"
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
|
||||
Reference in New Issue
Block a user