From 27f8a68de321d223ffb52dcf07bebc94562bc93f Mon Sep 17 00:00:00 2001 From: janwas Date: Sat, 29 May 2004 12:04:42 +0000 Subject: [PATCH] some smaller fixes This was SVN commit r293. --- source/lib/config.h | 9 -------- source/lib/endian.cpp | 32 +++++++++++++++++++++++++++- source/lib/endian.h | 2 ++ source/lib/lib.h | 13 +++++++++++ source/lib/misc.cpp | 29 +------------------------ source/lib/misc.h | 9 ++------ source/lib/sysdep/win/wdetect.cpp | 10 +++++---- source/lib/sysdep/win/win_internal.h | 2 +- source/lib/sysdep/win/wsdl.cpp | 1 + source/terrain/Renderer.cpp | 2 +- 10 files changed, 58 insertions(+), 51 deletions(-) diff --git a/source/lib/config.h b/source/lib/config.h index c3f734ed70..0a2646efc4 100755 --- a/source/lib/config.h +++ b/source/lib/config.h @@ -25,12 +25,3 @@ #undef CONFIG_DISABLE_EXCEPTIONS - -// TODO: where does this belong? -#ifdef CONFIG_DISABLE_EXCEPTIONS -# ifdef _WIN32 -# define _HAS_EXCEPTIONS 0 -# else -# define STL_NO_EXCEPTIONS -# endif -#endif \ No newline at end of file diff --git a/source/lib/endian.cpp b/source/lib/endian.cpp index 9a6912136d..ce6fe355b1 100755 --- a/source/lib/endian.cpp +++ b/source/lib/endian.cpp @@ -1,5 +1,7 @@ #include "precompiled.h" +#include "lib.h" + // don't need to implement on VC - header maps bswap* to instrinsics #ifndef _MSC_VER @@ -36,5 +38,33 @@ u64 bswap64(u64 x) return x; } +#endif // #ifndef _MSC_VER -#endif // #ifndef _MSC_VER \ No newline at end of file + +void bswap32(const u8* data, int cnt) +{ +#ifdef _M_IX86 + + UNUSED(data) + UNUSED(cnt) + + __asm + { + mov edx, [data] + mov ecx, [cnt] +$loop: mov eax, [edx] + bswap eax + mov [edx], eax + add edx, 4 + dec ecx + jnz $loop + } + +#else + + u32* p = (u32*)data; + for(int i = 0; i < cnt; i++, p++) + *p = bswap32(*p); + +#endif +} \ No newline at end of file diff --git a/source/lib/endian.h b/source/lib/endian.h index 0dd1a998b6..4671115374 100755 --- a/source/lib/endian.h +++ b/source/lib/endian.h @@ -15,3 +15,5 @@ extern u32 bswap32(u32); extern u64 bswap64(u64); #endif + +extern void bswap32(const u8* data, int cnt); \ No newline at end of file diff --git a/source/lib/lib.h b/source/lib/lib.h index ee28f46731..f875327bbc 100755 --- a/source/lib/lib.h +++ b/source/lib/lib.h @@ -22,6 +22,7 @@ #include "config.h" #include "misc.h" +#include "types.h" #include "sysdep/sysdep.h" @@ -32,6 +33,18 @@ #endif +// tell STL not to generate exceptions, if compiling without exceptions +// (usually done for performance reasons). +#ifdef CONFIG_DISABLE_EXCEPTIONS +# ifdef _WIN32 +# define _HAS_EXCEPTIONS 0 +# else +# define STL_NO_EXCEPTIONS +# endif +#endif + + + #define STMT(STMT_code__) do { STMT_code__; } while(0) // must not be used before main entered! (i.e. not from NLS constructors / functions) diff --git a/source/lib/misc.cpp b/source/lib/misc.cpp index cded7d27be..70228b2c57 100755 --- a/source/lib/misc.cpp +++ b/source/lib/misc.cpp @@ -63,7 +63,7 @@ u32 fnv_hash(const void* buf, const size_t len) // otherwise, hash bytes of buf. u64 fnv_hash64(const void* buf, const size_t len) { - u64 h = 0xCBF29CE484222325; + u64 h = 0xCBF29CE484222325ull; // give distinct values for different length 0 buffers. // value taken from FNV; it has no special significance. @@ -94,33 +94,6 @@ u64 fnv_hash64(const void* buf, const size_t len) } -void bswap32(const u8* data, int cnt) -{ -#ifdef _M_IX86 - - UNUSED(data) - UNUSED(cnt) - - __asm - { - mov edx, [data] - mov ecx, [cnt] -$loop: mov eax, [edx] - bswap eax - mov [edx], eax - add edx, 4 - dec ecx - jnz $loop - } - -#else - - u32* p = (u32*)data; - for(int i = 0; i < cnt; i++, p++) - *p = bswap32(*p); - -#endif -} bool is_pow2(const long n) diff --git a/source/lib/misc.h b/source/lib/misc.h index 0db44b6810..ac6a25ef75 100755 --- a/source/lib/misc.h +++ b/source/lib/misc.h @@ -22,9 +22,8 @@ #include "types.h" #include "config.h" -// bswap32 is overloaded! #ifdef __cplusplus -//extern "C" { +extern "C" { #endif @@ -55,10 +54,6 @@ extern u16 subusw(u16 x, u16 y); -extern u16 bswap16(u16); -extern u32 bswap32(u32); - -extern void bswap32(const u8* data, int cnt); static inline u16 read_le16(const void* p) { @@ -128,7 +123,7 @@ char *_ltoa(long, char *, int radix); #ifdef __cplusplus -//} +} #endif #endif // #ifndef __MISC_H__ diff --git a/source/lib/sysdep/win/wdetect.cpp b/source/lib/sysdep/win/wdetect.cpp index 058fd7740f..a4f5b7a312 100755 --- a/source/lib/sysdep/win/wdetect.cpp +++ b/source/lib/sysdep/win/wdetect.cpp @@ -100,9 +100,7 @@ static int win_get_gfx_card() // get the name of the OpenGL driver DLL (used to determine driver version). -// -// the current implementation doens't -// doesn't require OpenGL to be initialized, but +// implementation doesn't currently require OpenGL to be ready for use. // // an alternative would be to enumerate all DLLs loaded into the process, // and check for a glBegin export. this requires OpenGL to be initialized, @@ -110,6 +108,7 @@ static int win_get_gfx_card() // to sort out MCD, ICD, and opengl32.dll. static int get_ogl_drv_name(char* const ogl_drv_name, const size_t max_name_len) { + // need single point of exit so that we can close all keys; return this. int ret = -1; HKEY hkOglDrivers; @@ -117,6 +116,9 @@ static int get_ogl_drv_name(char* const ogl_drv_name, const size_t max_name_len) if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_ENUMERATE_SUB_KEYS, &hkOglDrivers) != 0) return -1; + // we just use the first entry. it might be wrong on dual-graphics card + // systems, but I don't see a better way to do it. there's no other + // occurence of the OpenGL driver name in the registry on my system. char key_name[32]; DWORD key_name_len = sizeof(key_name); if(RegEnumKeyEx(hkOglDrivers, 0, key_name, &key_name_len, 0, 0, 0, 0) == 0) @@ -127,7 +129,7 @@ static int get_ogl_drv_name(char* const ogl_drv_name, const size_t max_name_len) DWORD size = (DWORD)max_name_len-5; // -5 for ".dll" if(RegQueryValueEx(hkClass, "Dll", 0, 0, (LPBYTE)ogl_drv_name, &size) == 0) { - // add .dll to filename, if necessary + // add .dll to filename, if not already there char* ext = strrchr(ogl_drv_name, '.'); if(!ext || stricmp(ext, ".dll") != 0) strcat(ogl_drv_name, ".dll"); diff --git a/source/lib/sysdep/win/win_internal.h b/source/lib/sysdep/win/win_internal.h index 19dc1b1382..ae766d5257 100755 --- a/source/lib/sysdep/win/win_internal.h +++ b/source/lib/sysdep/win/win_internal.h @@ -89,7 +89,7 @@ // can't test for macro definition - // actual definitions in winnt.h are typedefs. -typedef u64 DWORDLONG; +typedef unsigned __int64 DWORDLONG; typedef DWORD ULONG_PTR; typedef struct _MEMORYSTATUSEX diff --git a/source/lib/sysdep/win/wsdl.cpp b/source/lib/sysdep/win/wsdl.cpp index 5cb1b24d01..48d2d5faf4 100755 --- a/source/lib/sysdep/win/wsdl.cpp +++ b/source/lib/sysdep/win/wsdl.cpp @@ -376,6 +376,7 @@ static int wsdl_init() FILE* const ret = freopen("stdout.txt", "w", stdout); if(!ret) debug_warn("stdout freopen failed"); + setvbuf(stdout, 0, _IONBF, 0); return 0; } diff --git a/source/terrain/Renderer.cpp b/source/terrain/Renderer.cpp index 8f8c688d6b..b3e45aa500 100755 --- a/source/terrain/Renderer.cpp +++ b/source/terrain/Renderer.cpp @@ -542,7 +542,7 @@ bool CRenderer::LoadTexture(CTexture* texture) return h==0xfffffff ? true : false; } else { h=tex_load(texture->GetName()); - if (!h) { + if (h <= 0) { texture->SetHandle(0xffffffff); return false; } else {