fixes for VC6 build problems reported by Stu.

This was SVN commit r239.
This commit is contained in:
janwas 2004-05-18 00:38:39 +00:00
parent 556afb4a5c
commit 34c3c12934
8 changed files with 122 additions and 25 deletions

View File

@ -124,6 +124,8 @@ int file_rel_chdir(const char* argv0, const char* rel_path)
}
already_attempted = true;
{
// get full path to executable
if(access(argv0, X_OK) < 0)
goto fail;
@ -148,6 +150,8 @@ int file_rel_chdir(const char* argv0, const char* rel_path)
return 0;
}
fail:
debug_warn("file_rel_chdir failed");
if(msg)
@ -971,6 +975,9 @@ debug_out("file_wait_io: hio=%I64x\n", hio);
size = io->user_size;
void* transfer_buf;
ssize_t bytes_transferred;
// block's tag is in cache. need to check if its read is still pending.
if(io->cached)
{
@ -985,8 +992,7 @@ debug_out("file_wait_io: hio=%I64x\n", hio);
cb = cache_io->cb;
}
void* transfer_buf;
ssize_t bytes_transferred = ll_wait_io(cb, transfer_buf);
bytes_transferred = ll_wait_io(cb, transfer_buf);
skip_wait:

View File

@ -78,7 +78,7 @@ enum FILE_CB_FLAGS
extern int file_rel_chdir(const char* argv0, const char* rel_path);
typedef int(*FileCB)(const char* name, uint flags, ssize_t size, uintptr_t user);
typedef int(*FileCB)(const char* const name, const uint flags, const ssize_t size, const uintptr_t user);
// not recursive - only the files in <dir>!
extern int file_enum(const char* dir, FileCB cb, uintptr_t user);

View File

@ -88,6 +88,7 @@ static int zip_find_ecdr(const void* const file, const size_t size, const u8*& e
if(*(u32*)ecdr == *(u32*)&ecdr_id)
goto found_ecdr;
{
// scan the last 66000 bytes of file for ecdr_id signature
// (zip comment <= 65535 bytes, sizeof(ECDR) = 22, add some for safety)
@ -110,6 +111,8 @@ static int zip_find_ecdr(const void* const file, const size_t size, const u8*& e
ecdr_ = 0;
return -1;
}
found_ecdr:
ecdr_ = ecdr;
return 0;
@ -164,6 +167,8 @@ static int zip_read_cdfh(const u8*& cdfh, const char*& fn, size_t& fn_len, ZFile
goto skip_file;
}
{
const u8 method = cdfh[10];
const u32 csize_ = read_le32(cdfh+20);
const u32 ucsize_ = read_le32(cdfh+24);
@ -202,6 +207,8 @@ static int zip_read_cdfh(const u8*& cdfh, const char*& fn, size_t& fn_len, ZFile
cdfh += CDFH_SIZE + fn_len + e_len + c_len;
return 0;
}
// file was invalid somehow; try to seek forward to the next CDFH
skip_file:
// scan for next CDFH (look for signature)
@ -223,7 +230,7 @@ found_next_cdfh:
// fn (filename) is not necessarily 0-terminated!
// loc is only valid during the callback! must be copied or saved.
typedef int(*ZipCdfhCB)(const uintptr_t user, const i32 idx, const char* fn, const size_t fn_len, const ZFileLoc* const loc);
typedef int(*ZipCdfhCB)(const uintptr_t user, const i32 idx, const char* const fn, const size_t fn_len, const ZFileLoc* const loc);
// go through central directory of the Zip file (loaded or mapped into memory);
// call back for each file.

View File

@ -65,6 +65,13 @@
#include <windows.h>
///////////////////////////////////////////////////////////////////////////////
//
// fixes for VC6 platform SDK
//
///////////////////////////////////////////////////////////////////////////////
// VC6 windows.h doesn't define these
#ifndef DWORD_PTR
#define DWORD_PTR DWORD
@ -78,10 +85,34 @@
#define PROCESSOR_ARCHITECTURE_AMD64 9
#endif
// end VC6 fixes
#if WINVER < 0x500
// can't test for macro definition -
// actual definitions in winnt.h are typedefs.
typedef u64 DWORDLONG;
typedef DWORD ULONG_PTR;
typedef struct _MEMORYSTATUSEX
{
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
#endif // #if WINVER < 0x500
///////////////////////////////////////////////////////////////////////////////
//
// powrprof.h (not there at all in VC6, missing some parts in VC7)
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NTSTATUS
#define NTSTATUS long
@ -202,7 +233,7 @@ typedef struct _SYSTEM_POWER_INFORMATION
// or there is no thermal zone defined [..]
// end powrprof.h fixes
///////////////////////////////////////////////////////////////////////////////
#include "types.h" // intptr_t

View File

@ -607,36 +607,77 @@ int uname(struct utsname* un)
}
long sysconf(int name)
{
// used by _SC_*_PAGES
static DWORD page_size;
static BOOL (WINAPI *pGlobalMemoryStatusEx)(MEMORYSTATUSEX*);
ONCE(
{
// get page size
// (used by _SC_PAGESIZE and _SC_*_PAGES)
SYSTEM_INFO si;
GetSystemInfo(&si); // can't fail => page_size always > 0.
page_size = si.dwPageSize;
// import GlobalMemoryStatusEx
// (used by _SC_*_PAGES if available -
// it's not defined in the VC6 Platform SDK)
const HMODULE hKernel32Dll = LoadLibrary("kernel32.dll");
*(void**)&pGlobalMemoryStatusEx = GetProcAddress(hKernel32Dll, "GlobalMemoryStatusEx");
FreeLibrary(hKernel32Dll);
// make sure the reference is released so BoundsChecker
// doesn't complain. it won't actually be unloaded anyway -
// there is at least one other reference.
}
);
switch(name)
{
case _SC_PAGESIZE:
if(page_size)
return page_size;
SYSTEM_INFO si;
GetSystemInfo(&si); // can't fail => page_size always > 0.
return page_size = si.dwPageSize;
return page_size;
case _SC_PHYS_PAGES:
case _SC_AVPHYS_PAGES:
if(!page_size)
sysconf(_SC_PAGESIZE); // sets page_size
{
MEMORYSTATUSEX ms = { sizeof(ms) };
GlobalMemoryStatusEx(&ms);
u64 total_phys_mem;
u64 avail_phys_mem;
// first try GlobalMemoryStatus - cannot fail.
// override its results if GlobalMemoryStatusEx is available.
MEMORYSTATUS ms;
GlobalMemoryStatus(&ms);
// can't fail.
total_phys_mem = ms.dwTotalPhys;
avail_phys_mem = ms.dwAvailPhys;
// newer API is available: use it to report correct results
// (no overflow or wraparound) on systems with > 4 GB of memory.
MEMORYSTATUSEX mse = { sizeof(mse) };
if(pGlobalMemoryStatusEx(&mse))
{
total_phys_mem = mse.ullTotalPhys;
avail_phys_mem = mse.ullAvailPhys;
}
else
// no matter though, we have the results from GlobalMemoryStatus.
debug_warn("GlobalMemoryStatusEx failed - why?");
if(name == _SC_PHYS_PAGES)
return (long)(round_up((uintptr_t)ms.ullTotalPhys, 2*MB) / page_size);
return (long)(round_up((uintptr_t)total_phys_mem, 2*MB) / page_size);
// Richter, "Programming Applications for Windows":
// reported value doesn't include non-paged pool reserved
// during boot; it's not considered available to kernel.
// it's 528 KB on my 512 MB machine (WinXP and Win2k).
else
return (long)(ms.ullAvailPhys / page_size);
return (long)(avail_phys_mem / page_size);
}
default:

View File

@ -209,7 +209,10 @@ extern int open(const char* fn, int mode, ...);
extern int close(int);
extern int access(const char*, int);
extern int chdir(const char*);
#define getcwd _getcwd
extern unsigned int sleep(unsigned int sec);
extern int usleep(useconds_t us);

View File

@ -270,6 +270,12 @@ static void Render()
font_bind(font);
glprintf("%d FPS", fps);
// view params
glLoadIdentity();
glTranslatef(10, 90, 0);
extern float ViewFOV;
glprintf("FOV=%.1f", RADTODEG(ViewFOV));
#ifndef NO_GUI
// Temp GUI message GeeTODO
glLoadIdentity();
@ -334,6 +340,8 @@ int main(int argc, char* argv[])
const int ERR_MSG_SIZE = 1000;
wchar_t err_msg[ERR_MSG_SIZE];
// display_startup_error(argv[0]);
// set current directory to "$game_dir/data".
// this is necessary because it is otherwise unknown,

View File

@ -35,6 +35,7 @@ int mouse_x=50, mouse_y=50;
float ViewScrollSpeed = 60.0f;
float ViewZoomFactor = 1.0f;
float ViewFOV = 0.0f;
void terr_init()
@ -79,21 +80,21 @@ void terr_update(const float DeltaTime)
const float s60 = sin(DEGTORAD(60.0f));
const float c60 = cos(DEGTORAD(60.0f));
const CVector3D vert (c30*c45, s45*0, -s30*c45*0);
const CVector3D vert (c30*c45, s45, -s30*c45);
float fov = g_Camera.GetFOV();
float d = DEGTORAD(0.4f);
if(keys[SDLK_KP_MINUS])
// g_Camera.m_Orientation.Translate(vert);
if (fov < DEGTORAD(90.f))
if (fov < DEGTORAD(60.f))
fov += d;
g_Camera.SetProjection(1, 1000, fov + d);
if(keys[SDLK_KP_PLUS])
// g_Camera.m_Orientation.Translate(vert*-1);
if (fov-d > DEGTORAD(20))
g_Camera.SetProjection(1, 1000, fov - d);
if (fov-d > DEGTORAD(10))
fov -= d;
g_Camera.SetProjection(1, 1000, fov);
ViewFOV = fov;
g_Camera.UpdateFrustum ();
}