1
0
forked from 0ad/0ad

some smaller fixes

This was SVN commit r293.
This commit is contained in:
janwas 2004-05-29 12:04:42 +00:00
parent 1c5a2d8f10
commit 27f8a68de3
10 changed files with 58 additions and 51 deletions

View File

@ -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

View File

@ -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
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
}

View File

@ -15,3 +15,5 @@ extern u32 bswap32(u32);
extern u64 bswap64(u64);
#endif
extern void bswap32(const u8* data, int cnt);

View File

@ -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)

View File

@ -63,7 +63,7 @@ u32 fnv_hash(const void* buf, const size_t len)
// otherwise, hash <len> 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)

View File

@ -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__

View File

@ -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");

View File

@ -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

View File

@ -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;
}

View File

@ -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 {