RENDERTYPE=SDL on Windows, part 2.

This introduces winbits.[ch] in the engine, containing layer-independent code migrated from winlayer, including nedmalloc, ebacktrace1, OS version detection, and high-resolution profiling timers.

sdlayer has been expanded to include the code from winbits under _WIN32.

All uses of RENDERTYPEWIN in the source have been examined and changed to _WIN32 (or removed) where the block in question is layer-independent.

git-svn-id: https://svn.eduke32.com/eduke32@3221 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2012-11-25 04:26:37 +00:00
parent 9a75f0b88c
commit 5e0ffb93b3
21 changed files with 421 additions and 274 deletions

View file

@ -121,6 +121,7 @@ endif
ifeq ($(PLATFORM),WINDOWS)
OURCOMMONFLAGS+= -DUNDERSCORES # -I$(ENETROOT)/include
OURASFLAGS+= -DUNDERSCORES -f win32
ENGINEOBJS+= $(OBJ)/winbits.$o
EDITOROBJS+= $(OBJ)/startwin.editor.$o
endif
ifeq ($(PLATFORM),BEOS)

View file

@ -24,12 +24,13 @@ $(OBJ)/osd.$o: $(SRC)/osd.c $(INC)/build.h $(INC)/osd.h $(INC)/compat.h $(INC)/b
$(OBJ)/pragmas.$o: $(SRC)/pragmas.c $(INC)/compat.h
$(OBJ)/scriptfile.$o: $(SRC)/scriptfile.c $(INC)/scriptfile.h $(INC)/cache1d.h $(INC)/compat.h
$(OBJ)/sdlayer.$o: $(SRC)/sdlayer.c $(INC)/compat.h $(INC)/sdlayer.h $(INC)/baselayer.h $(INC)/cache1d.h $(INC)/pragmas.h $(INC)/a.h $(INC)/build.h $(INC)/osd.h $(INC)/glbuild.h
$(OBJ)/winlayer.$o: $(SRC)/winlayer.c $(INC)/compat.h $(INC)/winlayer.h $(INC)/baselayer.h $(INC)/pragmas.h $(INC)/build.h $(INC)/a.h $(INC)/osd.h $(INC)/dxdidf.h $(INC)/glbuild.h $(INC)/rawinput.h
$(OBJ)/winlayer.$o: $(SRC)/winlayer.c $(INC)/compat.h $(INC)/winlayer.h $(INC)/baselayer.h $(INC)/pragmas.h $(INC)/build.h $(INC)/a.h $(INC)/osd.h $(INC)/dxdidf.h $(INC)/glbuild.h $(INC)/rawinput.h $(INC)/winbits.h
$(OBJ)/gtkbits.$o: $(SRC)/gtkbits.c $(INC)/baselayer.h $(INC)/build.h $(INC)/dynamicgtk.h
$(OBJ)/dynamicgtk.$o: $(SRC)/dynamicgtk.c $(INC)/dynamicgtk.h
$(OBJ)/polymer.$o: $(SRC)/polymer.c $(INC)/polymer.h $(INC)/compat.h $(INC)/build.h $(INC)/glbuild.h $(INC)/osd.h $(INC)/pragmas.h $(INC)/mdsprite.h $(INC)/polymost.h
$(OBJ)/mutex.$o: $(SRC)/mutex.c $(INC)/mutex.h
$(OBJ)/rawinput.$o: $(SRC)/rawinput.c $(INC)/rawinput.h
$(OBJ)/winbits.$o: $(SRC)/winbits.c $(INC)/winbits.h
$(OBJ)/lunatic.$o: $(SRC)/lunatic.c $(INC)/lunatic.h $(INC)/cache1d.h $(INC)/osd.h

View file

@ -79,7 +79,8 @@ ENGINEOBJS= \
$(OBJ)\winlayer.$o \
$(OBJ)\polymer.$o \
$(OBJ)\mutex.$o \
$(OBJ)\rawinput.$o
$(OBJ)\rawinput.$o \
$(OBJ)\winbits.$o
EDITOROBJS=$(OBJ)\build.$o \
$(OBJ)\startwin.editor.$o \

View file

@ -21,6 +21,8 @@ extern char quitevent, appactive;
extern int32_t vsync;
extern void app_crashhandler(void);
// NOTE: these are implemented in game-land so they may be overridden in game specific ways
extern int32_t startwin_open(void);
extern int32_t startwin_close(void);

View file

@ -0,0 +1,6 @@
#ifdef RENDERTYPEWIN
# include "winlayer.h"
#else
# include "sdlayer.h"
#endif

View file

@ -0,0 +1,28 @@
// Windows layer-independent code
#include <compat.h>
#define WindowClass "buildapp"
extern int32_t backgroundidle; // set to 1 to tell winlayer to go to idle priority when inactive
extern int64_t win_timerfreq;
extern char silentvideomodeswitch;
extern BOOL CheckWinVersion(void);
extern void win_allowtaskswitching(int32_t onf);
extern int32_t win_checkinstance(void);
extern int32_t win_inittimer(void);
extern uint64_t win_gethiticks(void);
extern void win_open(void);
extern void win_init(void);
extern void win_setvideomode(int32_t c);
extern void win_uninit(void);
extern void win_close(void);
extern void ShowErrorBox(const char *m);
extern LPTSTR GetWindowsErrorMsg(DWORD code);

View file

@ -1,11 +1,9 @@
// Windows DIB/DirectDraw interface layer
// for the Build Engine
// by Jonathon Fowler (jf@jonof.id.au)
// Windows DIB/DirectDraw interface layer for the Build Engine
// Originally by Jonathon Fowler (jf@jonof.id.au)
#ifndef __build_interface_layer__
#define __build_interface_layer__ WIN
extern int32_t backgroundidle; // set to 1 to tell winlayer to go to idle priority when inactive
extern uint32_t maxrefreshfreq;
extern int32_t glusecds;
@ -15,9 +13,6 @@ extern char di_disabled;
int32_t win_gethwnd(void);
int32_t win_gethinstance(void);
void win_allowtaskswitching(int32_t onf);
int32_t win_checkinstance(void);
extern void idle_waitevent_timeout(uint32_t timeout);
static inline void idle_waitevent(void)

View file

@ -3,9 +3,7 @@
#include "build.h"
#include "baselayer.h"
#ifdef RENDERTYPEWIN
#include "winlayer.h"
#endif
#include "renderlayer.h"
#include "polymost.h"

View file

@ -14,12 +14,13 @@
#include "common.h"
#include "baselayer.h"
#ifdef RENDERTYPEWIN
#include "winlayer.h"
#else
#include "sdlayer.h"
#include "renderlayer.h"
#ifdef _WIN32
# include "winbits.h"
#endif
#include "m32script.h"
#define TIMERINTSPERSECOND 120
@ -493,7 +494,7 @@ void M32_DrawRoomsAndMasks(void)
}
#undef STARTUP_SETUP_WINDOW
#if defined RENDERTYPEWIN || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2))
#if defined _WIN32 || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2))
# define STARTUP_SETUP_WINDOW
#endif
@ -520,7 +521,7 @@ int32_t app_main(int32_t argc, const char **argv)
if ((i = ExtPreInit(argc,argv)) < 0) return -1;
#ifdef RENDERTYPEWIN
#ifdef _WIN32
backgroundidle = 1;
#endif

View file

@ -6,10 +6,8 @@
#include "editor.h"
#include "osd.h"
#ifdef RENDERTYPEWIN
#include "winlayer.h"
#endif
#include "baselayer.h"
#include "renderlayer.h"
static int32_t vesares[13][2] = {{320,200},{360,200},{320,240},{360,240},{320,400},
{360,400},{640,350},{640,400},{640,480},{800,600},

View file

@ -27,7 +27,11 @@
# include "glbuild.h"
#endif
#if defined __APPLE__
#if defined _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include "winbits.h"
#elif defined __APPLE__
# include "osxbits.h"
# include <mach/mach.h>
# include <mach/mach_time.h>
@ -211,6 +215,17 @@ int32_t main(int32_t argc, char *argv[])
buildkeytranslationtable();
#ifdef _WIN32
if (!CheckWinVersion())
{
MessageBox(0, "This application requires Windows XP or better to run.",
apptitle, MB_OK|MB_ICONSTOP);
return -1;
}
win_open();
#endif
#ifdef HAVE_GTK2
gtkbuild_init(&argc, &argv);
#endif
@ -250,6 +265,10 @@ int32_t main(int32_t argc, char *argv[])
#ifdef HAVE_GTK2
gtkbuild_exit(r);
#endif
#ifdef _WIN32
win_close();
#endif
return r;
}
@ -291,6 +310,7 @@ static void sighandler(int signum)
// usleep(15000000);
#endif
attach_debugger_here();
app_crashhandler();
uninitsystem();
exit(8);
}
@ -320,6 +340,10 @@ int32_t initsystem(void)
mutex_init(&m_initprintf);
#ifdef _WIN32
win_init();
#endif
initprintf("Initializing SDL system interface "
"(compiled against SDL version %d.%d.%d, found version %d.%d.%d)\n",
compiled.major, compiled.minor, compiled.patch,
@ -438,6 +462,10 @@ void uninitsystem(void)
SDL_Quit();
#ifdef _WIN32
win_uninit();
#endif
#ifdef USE_OPENGL
unloadgldriver();
#endif
@ -728,7 +756,7 @@ void grabmouse(char a)
{
if (a != mousegrab)
{
#if !defined __ANDROID__ && (!defined DEBUGGINGAIDS || defined __APPLE__)
#if !defined __ANDROID__ && (!defined DEBUGGINGAIDS || defined _WIN32 || defined __APPLE__)
SDL_GrabMode g;
g = SDL_WM_GrabInput(a ? SDL_GRAB_ON : SDL_GRAB_OFF);
@ -802,6 +830,14 @@ int32_t inittimer(int32_t tickspersecond)
// initprintf("Initializing timer\n");
#ifdef _WIN32
{
int32_t t = win_inittimer();
if (t < 0)
return t;
}
#endif
timerfreq = 1000;
timerticspersec = tickspersecond;
timerlastsample = SDL_GetTicks() * timerticspersec / timerfreq;
@ -822,6 +858,10 @@ void uninittimer(void)
timerfreq=0;
#ifdef _WIN32
win_timerfreq=0;
#endif
msperhitick = 0;
}
@ -868,6 +908,8 @@ uint64_t gethiticks(void)
ticks *= 1000000000;
ticks += now.tv_nsec;
return (ticks);
# elif defined _WIN32
return win_gethiticks();
# elif defined __APPLE__
return mach_absolute_time();
# else
@ -886,6 +928,8 @@ uint64_t gethitickspersec(void)
#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) // SDL 1.2
# if _POSIX_TIMERS>0 && defined _POSIX_MONOTONIC_CLOCK
return 1000000000;
# elif defined _WIN32
return win_timerfreq;
# elif defined __APPLE__
static mach_timebase_info_data_t ti;
if (ti.denom == 0)
@ -1255,6 +1299,10 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
if (nogl) return -1;
# ifdef _WIN32
win_setvideomode(c);
# endif
initprintf("Setting video mode %dx%d (%d-bpp %s)\n",
x,y,c, ((fs&1) ? "fullscreen" : "windowed"));
do
@ -1967,22 +2015,30 @@ int32_t handleevents(void)
{
case SDL_WINDOWEVENT_FOCUS_GAINED:
appactive = 1;
# ifndef DEBUGGINGAIDS
# if !defined DEBUGGINGAIDS || defined _WIN32
if (mousegrab && moustat)
{
SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(SDL_DISABLE);
}
# endif
# ifdef _WIN32
if (backgroundidle)
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
# endif
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
appactive = 0;
# ifndef DEBUGGINGAIDS
# if !defined DEBUGGINGAIDS || defined _WIN32
if (mousegrab && moustat)
{
SDL_WM_GrabInput(SDL_GRAB_OFF);
SDL_ShowCursor(SDL_ENABLE);
}
# endif
# ifdef _WIN32
if (backgroundidle)
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
# endif
break;
}
@ -2058,7 +2114,7 @@ int32_t handleevents(void)
if (ev.active.state & SDL_APPINPUTFOCUS)
{
appactive = ev.active.gain;
# ifndef DEBUGGINGAIDS
# if !defined DEBUGGINGAIDS || defined _WIN32
if (mousegrab && moustat)
{
if (appactive)
@ -2072,6 +2128,11 @@ int32_t handleevents(void)
SDL_ShowCursor(SDL_ENABLE);
}
}
# endif
# ifdef _WIN32
if (backgroundidle)
SetPriorityClass(GetCurrentProcess(),
appactive ? NORMAL_PRIORITY_CLASS : IDLE_PRIORITY_CLASS);
# endif
rv=-1;
}

View file

@ -0,0 +1,247 @@
// Windows layer-independent code
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "build.h"
#include "baselayer.h"
#include "winbits.h"
int32_t backgroundidle = 1;
int64_t win_timerfreq = 0;
char silentvideomodeswitch = 0;
static char taskswitching = 1;
static HANDLE instanceflag = NULL;
static OSVERSIONINFOEX osv;
static HMODULE nedhandle = NULL;
//
// CheckWinVersion() -- check to see what version of Windows we happen to be running under
//
BOOL CheckWinVersion(void)
{
ZeroMemory(&osv, sizeof(osv));
osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
// we don't like anything older than Windows XP
if (!GetVersionEx((LPOSVERSIONINFOA)&osv)) return FALSE;
if (osv.dwMajorVersion >= 6) return TRUE;
if (osv.dwMajorVersion == 5 && osv.dwMinorVersion >= 1) return TRUE;
return FALSE;
}
static void win_printversion(void)
{
const char *ver = "";
switch (osv.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
if (osv.dwMajorVersion == 5)
{
switch (osv.dwMinorVersion)
{
case 1:
ver = "XP";
break;
case 2:
ver = osv.wProductType == VER_NT_WORKSTATION ? "XP x64" : "Server 2003";
break;
}
break;
}
if (osv.dwMajorVersion == 6)
{
switch (osv.dwMinorVersion)
{
case 0:
ver = osv.wProductType == VER_NT_WORKSTATION ? "Vista" : "Server 2008";
break;
case 1:
ver = osv.wProductType == VER_NT_WORKSTATION ? "7" : "Server 2008 R2";
break;
case 2:
ver = osv.wProductType == VER_NT_WORKSTATION ? "8" : "Server 2012";
break;
}
break;
}
break;
}
initprintf("Windows %s %s (build %lu.%lu.%lu)\n", ver, osv.szCSDVersion,
osv.dwMajorVersion, osv.dwMinorVersion, osv.dwBuildNumber);
}
//
// win_allowtaskswitching() -- captures/releases alt+tab hotkeys
//
void win_allowtaskswitching(int32_t onf)
{
if (onf == taskswitching) return;
if (onf)
{
UnregisterHotKey(0,0);
UnregisterHotKey(0,1);
}
else
{
RegisterHotKey(0,0,MOD_ALT,VK_TAB);
RegisterHotKey(0,1,MOD_ALT|MOD_SHIFT,VK_TAB);
}
taskswitching = onf;
}
//
// win_checkinstance() -- looks for another instance of a Build app
//
int32_t win_checkinstance(void)
{
if (!instanceflag) return 0;
return (WaitForSingleObject(instanceflag,0) == WAIT_TIMEOUT);
}
//
// high-resolution timers for profiling
//
int32_t win_inittimer(void)
{
int64_t t;
if (win_timerfreq) return 0; // already installed
// OpenWatcom seems to want us to query the value into a local variable
// instead of the global 'win_timerfreq' or else it gets pissed with an
// access violation
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&t))
{
ShowErrorBox("Failed fetching timer frequency");
return -1;
}
win_timerfreq = t;
return 0;
}
uint64_t win_gethiticks(void)
{
uint64_t i;
if (win_timerfreq == 0) return 0;
QueryPerformanceCounter((LARGE_INTEGER *)&i);
return i;
}
static void ToggleDesktopComposition(BOOL compEnable)
{
static HMODULE hDWMApiDLL = NULL;
static HRESULT(WINAPI *aDwmEnableComposition)(UINT);
if (!hDWMApiDLL && (hDWMApiDLL = LoadLibrary("DWMAPI.DLL")))
aDwmEnableComposition = (HRESULT(WINAPI *)(UINT))GetProcAddress(hDWMApiDLL, "DwmEnableComposition");
if (aDwmEnableComposition)
{
aDwmEnableComposition(compEnable);
if (!silentvideomodeswitch)
initprintf("%sabling desktop composition...\n", (compEnable) ? "En" : "Dis");
}
}
//
// win_open(), win_init(), win_setvideomode(), win_uninit(), win_close() -- shared code
//
void win_open(void)
{
#ifndef DEBUGGINGAIDS
if ((nedhandle = LoadLibrary("nedmalloc.dll")))
{
#ifdef __cplusplus
nedalloc::nedpool_t *(WINAPI *nedcreatepool)(size_t, int);
if ((nedcreatepool = (nedalloc::nedpool_t *(WINAPI *)(size_t, int))GetProcAddress(nedhandle, "nedcreatepool")))
#else
nedpool *(WINAPI *nedcreatepool)(size_t, int);
if ((nedcreatepool = (void *)GetProcAddress(nedhandle, "nedcreatepool")))
#endif
nedcreatepool(SYSTEM_POOL_SIZE, -1);
}
#else
LoadLibraryA("ebacktrace1.dll");
/*
wm_msgbox("boo","didn't load backtrace DLL (code %d)\n", (int)GetLastError());
else
wm_msgbox("yay","loaded backtrace DLL\n");
*/
#endif
instanceflag = CreateSemaphore(NULL, 1,1, WindowClass);
}
void win_init(void)
{
win_printversion();
if (nedhandle)
initprintf("Initialized nedmalloc\n");
}
void win_setvideomode(int32_t c)
{
if (osv.dwMajorVersion >= 6)
ToggleDesktopComposition(c < 16);
}
void win_uninit(void)
{
win_allowtaskswitching(1);
}
void win_close(void)
{
if (instanceflag) CloseHandle(instanceflag);
}
//
// ShowErrorBox() -- shows an error message box
//
void ShowErrorBox(const char *m)
{
TCHAR msg[1024];
wsprintf(msg, "%s: %s", m, GetWindowsErrorMsg(GetLastError()));
MessageBox(0, msg, apptitle, MB_OK|MB_ICONSTOP);
}
//
// GetWindowsErrorMsg() -- gives a pointer to a static buffer containing the Windows error message
//
LPTSTR GetWindowsErrorMsg(DWORD code)
{
static TCHAR lpMsgBuf[1024];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)lpMsgBuf, 1024, NULL);
return lpMsgBuf;
}

View file

@ -69,6 +69,8 @@
#endif
#include "mutex.h"
#include "winbits.h"
// undefine to restrict windowed resolutions to conventional sizes
#define ANY_WINDOWED_SIZE
@ -79,17 +81,12 @@ int32_t _buildargc = 0;
const char **_buildargv = NULL;
static char *argvbuf = NULL;
extern int32_t app_main(int32_t argc, const char **argv);
extern void app_crashhandler(void);
// Windows crud
static HINSTANCE hInstance = 0;
static HWND hWindow = 0;
#define WINDOW_STYLE (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX)
#define WindowClass "buildapp"
static BOOL window_class_registered = FALSE;
static HANDLE instanceflag = NULL;
int32_t backgroundidle = 1;
static WORD sysgamma[3][256];
extern int32_t curbrightness, gammabrightness;
@ -102,13 +99,10 @@ char nogl=0;
char forcegl=0;
#endif
static LPTSTR GetWindowsErrorMsg(DWORD code);
static const char *GetDDrawError(HRESULT code);
static const char *GetDInputError(HRESULT code);
static void ShowErrorBox(const char *m);
static void ShowDDrawErrorBox(const char *m, HRESULT r);
static void ShowDInputErrorBox(const char *m, HRESULT r);
static inline BOOL CheckWinVersion(void);
static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static BOOL InitDirectDraw(void);
static void UninitDirectDraw(void);
@ -154,7 +148,6 @@ char modechange=1;
char repaintneeded=0;
char offscreenrendering=0;
char videomodereset = 0;
char silentvideomodeswitch = 0;
// input and events
char quitevent=0;
@ -163,12 +156,6 @@ char realfs=0;
char regrabmouse=0;
uint32_t mousewheel[2] = { 0,0 };
static char taskswitching=1;
static OSVERSIONINFOEX osv;
static HMODULE nedhandle = NULL;
//-------------------------------------------------------------------------------------------------
// DINPUT (JOYSTICK)
@ -225,37 +212,6 @@ int32_t win_gethinstance(void)
}
//
// win_allowtaskswitching() -- captures/releases alt+tab hotkeys
//
void win_allowtaskswitching(int32_t onf)
{
if (onf == taskswitching) return;
if (onf)
{
UnregisterHotKey(0,0);
UnregisterHotKey(0,1);
}
else
{
RegisterHotKey(0,0,MOD_ALT,VK_TAB);
RegisterHotKey(0,1,MOD_ALT|MOD_SHIFT,VK_TAB);
}
taskswitching = onf;
}
//
// win_checkinstance() -- looks for another instance of a Build app
//
int32_t win_checkinstance(void)
{
if (!instanceflag) return 0;
return (WaitForSingleObject(instanceflag,0) == WAIT_TIMEOUT);
}
//
// wm_msgbox/wm_ynbox() -- window-manager-provided message boxes
@ -378,26 +334,7 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
return -1;
}
#ifndef DEBUGGINGAIDS
if ((nedhandle = LoadLibrary("nedmalloc.dll")))
{
#ifdef __cplusplus
nedalloc::nedpool_t *(WINAPI *nedcreatepool)(size_t, int);
if ((nedcreatepool = (nedalloc::nedpool_t *(WINAPI *)(size_t, int))GetProcAddress(nedhandle, "nedcreatepool")))
#else
nedpool *(WINAPI *nedcreatepool)(size_t, int);
if ((nedcreatepool = (void *)GetProcAddress(nedhandle, "nedcreatepool")))
#endif
nedcreatepool(SYSTEM_POOL_SIZE, -1);
}
#else
LoadLibraryA("ebacktrace1.dll");
/*
wm_msgbox("boo","didn't load backtrace DLL (code %d)\n", (int)GetLastError());
else
wm_msgbox("yay","loaded backtrace DLL\n");
*/
#endif
win_open();
hdc = GetDC(NULL);
r = GetDeviceCaps(hdc, BITSPIXEL);
@ -518,8 +455,6 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
// atexit(uninitsystem);
instanceflag = CreateSemaphore(NULL, 1,1, WindowClass);
startwin_open();
baselayer_init();
@ -530,7 +465,8 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
if (r) Sleep(3000);
startwin_close();
if (instanceflag) CloseHandle(instanceflag);
win_close();
if (argvbuf) Bfree(argvbuf);
@ -579,51 +515,6 @@ static int32_t set_windowpos(const osdfuncparm_t *parm)
// initsystem() -- init systems
//
static void win_printversion(void)
{
const char *ver = "";
switch (osv.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
if (osv.dwMajorVersion == 5)
{
switch (osv.dwMinorVersion)
{
case 1:
ver = "XP";
break;
case 2:
ver = osv.wProductType == VER_NT_WORKSTATION ? "XP x64" : "Server 2003";
break;
}
break;
}
if (osv.dwMajorVersion == 6)
{
switch (osv.dwMinorVersion)
{
case 0:
ver = osv.wProductType == VER_NT_WORKSTATION ? "Vista" : "Server 2008";
break;
case 1:
ver = osv.wProductType == VER_NT_WORKSTATION ? "7" : "Server 2008 R2";
break;
case 2:
ver = osv.wProductType == VER_NT_WORKSTATION ? "8" : "Server 2012";
break;
}
break;
}
break;
}
initprintf("Windows %s %s (build %lu.%lu.%lu)\n", ver, osv.szCSDVersion,
osv.dwMajorVersion, osv.dwMinorVersion, osv.dwBuildNumber);
}
// http://www.gamedev.net/topic/47021-how-to-determine-video-card-with-win32-api
static void determine_ATI(void)
{
@ -671,10 +562,7 @@ int32_t initsystem(void)
frameplace=0;
lockcount=0;
win_printversion();
if (nedhandle)
initprintf("Initialized nedmalloc\n");
win_init();
#ifdef USE_OPENGL
if (loadgldriver(getenv("BUILD_GLDRV")))
@ -726,7 +614,7 @@ void uninitsystem(void)
uninitinput();
uninittimer();
win_allowtaskswitching(1);
win_uninit();
#ifdef USE_OPENGL
unloadgldriver();
@ -1546,7 +1434,6 @@ static const char *GetDInputError(HRESULT code)
// TIMER
//=================================================================================================
static int64_t timerfreq=0;
static int32_t timerlastsample=0;
int32_t timerticspersec=0;
static double msperhitick = 0;
@ -1575,22 +1462,17 @@ int32_t inittimer(int32_t tickspersecond)
{
int64_t t;
if (timerfreq) return 0; // already installed
if (win_timerfreq) return 0; // already installed
// initprintf("Initializing timer\n");
// OpenWatcom seems to want us to query the value into a local variable
// instead of the global 'timerfreq' or else it gets pissed with an
// access violation
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&t))
{
ShowErrorBox("Failed fetching timer frequency");
return -1;
}
timerfreq = t;
t = win_inittimer();
if (t < 0)
return t;
timerticspersec = tickspersecond;
QueryPerformanceCounter((LARGE_INTEGER *)&t);
timerlastsample = (int32_t)(t*timerticspersec / timerfreq);
timerlastsample = (int32_t)(t*timerticspersec / win_timerfreq);
usertimercallback = NULL;
@ -1604,9 +1486,9 @@ int32_t inittimer(int32_t tickspersecond)
//
void uninittimer(void)
{
if (!timerfreq) return;
if (!win_timerfreq) return;
timerfreq=0;
win_timerfreq=0;
timerticspersec = 0;
msperhitick = 0;
@ -1620,10 +1502,10 @@ inline void sampletimer(void)
int64_t i;
int32_t n;
if (!timerfreq) return;
if (!win_timerfreq) return;
QueryPerformanceCounter((LARGE_INTEGER *)&i);
n = (int32_t)((i*timerticspersec / timerfreq) - timerlastsample);
n = (int32_t)((i*timerticspersec / win_timerfreq) - timerlastsample);
if (n <= 0) return;
@ -1640,23 +1522,20 @@ inline void sampletimer(void)
uint32_t getticks(void)
{
int64_t i;
if (timerfreq == 0) return 0;
if (win_timerfreq == 0) return 0;
QueryPerformanceCounter((LARGE_INTEGER *)&i);
return (uint32_t)(i*longlong(1000)/timerfreq);
return (uint32_t)(i*longlong(1000)/win_timerfreq);
}
// high-resolution timers for profiling
uint64_t gethiticks(void)
{
uint64_t i;
if (timerfreq == 0) return 0;
QueryPerformanceCounter((LARGE_INTEGER *)&i);
return i;
return win_gethiticks();
}
uint64_t gethitickspersec(void)
{
return timerfreq;
return win_timerfreq;
}
// Returns the time since an unspecified starting time in milliseconds.
@ -1701,22 +1580,6 @@ static VOID *lpPixels = NULL;
static int32_t setgammaramp(WORD gt[3][256]);
static int32_t getgammaramp(WORD gt[3][256]);
static void ToggleDesktopComposition(BOOL compEnable)
{
static HMODULE hDWMApiDLL = NULL;
static HRESULT(WINAPI *aDwmEnableComposition)(UINT);
if (!hDWMApiDLL && (hDWMApiDLL = LoadLibrary("DWMAPI.DLL")))
aDwmEnableComposition = (HRESULT(WINAPI *)(UINT))GetProcAddress(hDWMApiDLL, "DwmEnableComposition");
if (aDwmEnableComposition)
{
aDwmEnableComposition(compEnable);
if (!silentvideomodeswitch)
initprintf("%sabling desktop composition...\n", (compEnable) ? "En" : "Dis");
}
}
//
// checkvideomode() -- makes sure the video mode passed is legal
//
@ -1814,8 +1677,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
gammabrightness = 0;
}
if (osv.dwMajorVersion >= 6)
ToggleDesktopComposition(c < 16);
win_setvideomode(c);
if (!silentvideomodeswitch)
initprintf("Setting video mode %dx%d (%d-bit %s)\n",
@ -3631,35 +3493,6 @@ static const char *GetDDrawError(HRESULT code)
// MOSTLY STATIC INTERNAL WINDOWS THINGS
//=================================================================================================
//
// ShowErrorBox() -- shows an error message box
//
static void ShowErrorBox(const char *m)
{
TCHAR msg[1024];
wsprintf(msg, "%s: %s", m, GetWindowsErrorMsg(GetLastError()));
MessageBox(0, msg, apptitle, MB_OK|MB_ICONSTOP);
}
//
// CheckWinVersion() -- check to see what version of Windows we happen to be running under
//
static inline BOOL CheckWinVersion(void)
{
ZeroMemory(&osv, sizeof(osv));
osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
// we don't like anything older than Windows XP
if (!GetVersionEx((LPOSVERSIONINFOA)&osv)) return FALSE;
if (osv.dwMajorVersion >= 6) return TRUE;
if (osv.dwMajorVersion == 5 && osv.dwMinorVersion >= 1) return TRUE;
return FALSE;
}
//
@ -3854,19 +3687,3 @@ static BOOL RegisterWindowClass(void)
return FALSE;
}
//
// GetWindowsErrorMsg() -- gives a pointer to a static buffer containing the Windows error message
//
static LPTSTR GetWindowsErrorMsg(DWORD code)
{
static TCHAR lpMsgBuf[1024];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)lpMsgBuf, 1024, NULL);
return lpMsgBuf;
}

View file

@ -77,6 +77,7 @@
<ClInclude Include="build\include\build.h" />
<ClInclude Include="build\include\cache1d.h" />
<ClInclude Include="build\include\compat.h" />
<ClInclude Include="build\include\common.h" />
<ClInclude Include="build\include\crc32.h" />
<ClInclude Include="build\include\dxdidf.h" />
<ClInclude Include="build\include\dynamicgtk.h" />
@ -108,15 +109,19 @@
<ClInclude Include="build\include\tracker.hpp" />
<ClInclude Include="build\include\tracker_operator.hpp" />
<ClInclude Include="build\include\tracker_operators.hpp" />
<ClInclude Include="build\include\winbits.h" />
<ClInclude Include="build\include\winlayer.h" />
<ClInclude Include="build\include\msvc\inttypes.h" />
<ClInclude Include="build\include\msvc\stdint.h" />
<ClInclude Include="build\src\engine_priv.h" />
<ClInclude Include="source\actors.h" />
<ClInclude Include="source\actors_inline.h" />
<ClInclude Include="source\anim.h" />
<ClInclude Include="source\animvpx.h" />
<ClInclude Include="source\common_game.h" />
<ClInclude Include="source\demo.h" />
<ClInclude Include="source\game.h" />
<ClInclude Include="source\game_inline.h" />
<ClInclude Include="source\gameexec.h" />
<ClInclude Include="source\gamevars.h" />
<ClInclude Include="source\global.h" />
@ -129,6 +134,7 @@
<ClInclude Include="source\quotes.h" />
<ClInclude Include="source\savegame.h" />
<ClInclude Include="source\sector.h" />
<ClInclude Include="source\sector_inline.h" />
<ClInclude Include="source\_functio.h" />
<ClInclude Include="source\_rts.h" />
<ClInclude Include="source\config.h" />
@ -212,15 +218,19 @@
<ClCompile Include="build\src\startgtk.editor.c" />
<ClCompile Include="build\src\startwin.editor.c" />
<ClCompile Include="build\src\textfont.c" />
<ClCompile Include="build\src\winbits.c" />
<ClCompile Include="build\src\winlayer.c" />
<ClCompile Include="source\actors.c" />
<ClCompile Include="source\actors_inline.c" />
<ClCompile Include="source\anim.c" />
<ClCompile Include="source\animvpx.c" />
<ClCompile Include="source\astub.c" />
<ClCompile Include="source\config.c" />
<ClCompile Include="source\common.c" />
<ClCompile Include="source\demo.c" />
<ClCompile Include="source\enet\src\compress.c" />
<ClCompile Include="source\game.c" />
<ClCompile Include="source\game_inline.c" />
<ClCompile Include="source\gamedef.c" />
<ClCompile Include="source\gameexec.c" />
<ClCompile Include="source\gamestructures.c" />
@ -247,6 +257,7 @@
<ClCompile Include="source\savegame.c" />
<ClCompile Include="source\sdlmusic.c" />
<ClCompile Include="source\sector.c" />
<ClCompile Include="source\sector_inline.c" />
<ClCompile Include="source\sounds.c" />
<ClCompile Include="source\sounds_mapster32.c" />
<ClCompile Include="source\startgtk.game.c" />

View file

@ -25,13 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "editor.h"
#include "pragmas.h"
#ifdef RENDERTYPEWIN
#include "winlayer.h"
#else
#include "sdlayer.h"
#endif
#include "baselayer.h"
#include "renderlayer.h"
#include "osd.h"
#include "cache1d.h"
@ -8477,7 +8472,7 @@ static void G_ShowParameterHelp(void)
#endif
"-namesfile [file.h]\t\tLoad a custom NAMES.H for tile names\n"
"-nocheck\t\t\tDisables map pointer checking when saving (default)\n" // kept for script compat
#if defined RENDERTYPEWIN || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2))
#if defined _WIN32 || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2))
"-setup\t\t\tDisplays the configuration dialog\n"
#endif
#if !defined(_WIN32)
@ -10576,7 +10571,6 @@ int32_t ExtInit(void)
return rv;
}
#ifdef RENDERTYPEWIN
void app_crashhandler(void)
{
if (levelname[0])
@ -10590,7 +10584,6 @@ void app_crashhandler(void)
SaveBoard(f, 1);
}
}
#endif
void ExtUnInit(void)
{

View file

@ -22,11 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "duke3d.h"
#ifdef RENDERTYPEWIN
#include "winlayer.h"
#else
#include "sdlayer.h"
#endif
#include "baselayer.h"
#include "renderlayer.h"
#include "scriplib.h"
#include "file_lib.h"
@ -76,17 +73,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
#ifdef _WIN32
#include "winlayer.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shellapi.h>
# include "winlayer.h"
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <shellapi.h>
extern int32_t G_GetVersionFromWebsite(char *buffer);
#define UPDATEINTERVAL 604800 // 1w
# define UPDATEINTERVAL 604800 // 1w
# include "winbits.h"
#else
static int32_t usecwd = 0;
#ifndef GEKKO
#include <sys/ioctl.h>
#endif
# ifndef GEKKO
# include <sys/ioctl.h>
# endif
#endif /* _WIN32 */
int32_t g_quitDeadline = 0;
@ -8115,7 +8113,7 @@ static void G_ShowParameterHelp(void)
"-r\t\tRecord demo\n"
"-s#\t\tSet skill level (1-4)\n"
"-server\t\tStart a multiplayer game for other players to join\n"
#if defined RENDERTYPEWIN || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2))
#if defined _WIN32 || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2))
"-setup/nosetup\tEnables/disables startup window\n"
#endif
"-t#\t\tSet respawn mode: 1 = Monsters, 2 = Items, 3 = Inventory, x = All\n"
@ -8737,7 +8735,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
i++;
continue;
}
#if defined _WIN32 && defined RENDERTYPEWIN
#if defined RENDERTYPEWIN
if (!Bstrcasecmp(c+1,"nodinput"))
{
initprintf("DirectInput (joystick) support disabled\n");
@ -9842,14 +9840,12 @@ static int32_t G_EndOfLevel(void)
}
#ifdef RENDERTYPEWIN
void app_crashhandler(void)
{
G_CloseDemoWrite();
VM_ScriptInfo();
G_GameQuit();
}
#endif
#ifdef _WIN32
// See FILENAME_CASE_CHECK in cache1d.c
@ -9898,7 +9894,7 @@ int32_t app_main(int32_t argc, const char **argv)
fatInit(28, true);
#endif
#ifdef RENDERTYPEWIN
#ifdef _WIN32
if (argc > 1)
{
for (; i<argc; i++)
@ -9920,11 +9916,9 @@ int32_t app_main(int32_t argc, const char **argv)
initprintf("An error occurred while initializing ENet.\n");
else atexit(enet_deinitialize);
#ifdef RENDERTYPEWIN
backgroundidle = 0;
#endif
#ifdef _WIN32
backgroundidle = 0;
{
extern int32_t (*check_filename_casing_fn)(void);
check_filename_casing_fn = check_filename_casing;
@ -10170,7 +10164,7 @@ int32_t app_main(int32_t argc, const char **argv)
else if (!fg) g_gameNamePtr = "Unknown GRP";
}
#if (defined RENDERTYPEWIN || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2)))
#if (defined _WIN32 || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2)))
if (i < 0 || (!g_noSetup && (ud.configversion != BYTEVERSION_JF || ud.config.ForceSetup)) || g_commandSetup)
{
if (quitevent || !startwin_run())

View file

@ -312,12 +312,9 @@ static inline int32_t G_GetTeamPalette(int32_t team)
int32_t G_GetVersionFromWebsite(char *buffer);
#endif
#ifdef RENDERTYPEWIN
void app_crashhandler(void);
#ifdef USE_OPENGL
extern char forcegl;
#endif
#endif
#define minitextshade(x, y, t, s, p, sb) minitext_(x,y,t,s,p,sb)
#define minitext(x, y, t, p, sb) minitext_(x,y,t,0,p,sb)

View file

@ -5992,7 +5992,7 @@ void C_Compile(const char *filenam)
}
else
{
#if (defined RENDERTYPEWIN || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2)))
#if (defined _WIN32 || (defined RENDERTYPESDL && ((defined __APPLE__ && defined OSX_STARTUPWINDOW) || defined HAVE_GTK2)))
while (!quitevent) // keep the window open so people can copy CON errors out of it
handleevents();
#endif

View file

@ -57,7 +57,7 @@ void S_SoundStartup(void)
else return;
#ifdef RENDERTYPEWIN
initdata = (void *) win_gethwnd();
initdata = (void *) win_gethwnd(); // used for DirectSound
#endif
initprintf("Initializing sound... ");

View file

@ -79,7 +79,7 @@ int32_t S_SoundStartup(void)
fxdevicetype = ASS_AutoDetect;
#ifdef RENDERTYPEWIN
initdata = (void *) win_gethwnd();
initdata = (void *) win_gethwnd(); // used for DirectSound
#endif
status = FX_Init(fxdevicetype, NumVoices, NumChannels, NumBits, MixRate, initdata);

View file

@ -32,11 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <winsock2.h>
#include <ws2tcpip.h>
#ifdef RENDERTYPEWIN
#include "winlayer.h"
#else
#include "sdlayer.h"
#endif
#include "renderlayer.h"
int32_t G_GetVersionFromWebsite(char *buffer)
{