More work on MinGW support.

This commit is contained in:
Robert Beckebans 2012-12-03 23:55:27 +01:00
parent 180cb328a4
commit e0c79bd2d2
13 changed files with 1251 additions and 116 deletions

View file

@ -632,7 +632,28 @@ file(GLOB TIMIDITY_INCLUDES libs/timidity/*.h)
file(GLOB TIMIDITY_SOURCES libs/timidity/*.cpp)
file(GLOB_RECURSE WIN32_INCLUDES sys/win32/*.h)
file(GLOB_RECURSE WIN32_SOURCES sys/win32/*.cpp)
#file(GLOB_RECURSE WIN32_SOURCES sys/win32/*.cpp)
set(WIN32_SOURCES
sys/win32/win_achievements.cpp
sys/win32/win_glimp.cpp
sys/win32/win_input.cpp
sys/win32/win_localuser.cpp
sys/win32/win_main.cpp
sys/win32/win_net.cpp
sys/win32/win_qgl.cpp
sys/win32/win_savegame.cpp
sys/win32/win_session_local.cpp
sys/win32/win_shared.cpp
sys/win32/win_signin.cpp
sys/win32/win_snd.cpp
sys/win32/win_syscon.cpp
sys/win32/win_taskkeyhook.cpp
sys/win32/win_wndproc.cpp)
if(MSVC)
list(APPEND WIN32_SOURCES sys/win32/win_cpu.cpp)
endif()
set(WIN32_RESOURCES
# sys/win32/rc/res/BEVEL.BMP
@ -986,11 +1007,18 @@ if(MSVC)
wsock32.lib
)
else()
include_directories(libs/sdl/include)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/sdl2/libmingw32)
list(APPEND RBDOOM3_SOURCES
${SYS_INCLUDES} ${SYS_SOURCES}
${STUBAUDIO_INCLUDES} ${STUBAUDIO_SOURCES})
# TODO: if WIN32
#list(REMOVE_ITEM WIN32_SOURCES sys/win32/win_cpu.cpp)
list(APPEND WIN32_SOURCES sys/sdl/sdl_cpu.cpp)
list(APPEND RBDOOM3_SOURCES
${WIN32_INCLUDES} ${WIN32_SOURCES} ${WIN32_RESOURCES})
@ -1012,5 +1040,6 @@ else()
iphlpapi
winmm
wsock32.lib
SDL2
)
endif()

View file

@ -44,6 +44,22 @@ If you have questions concerning this license or the applicable additional terms
#include <math.h>
#include <string.h>
// RB begin
#if defined(__MINGW32__)
//#include <sal.h> // RB: missing __analysis_assume
#ifndef __analysis_assume
#define __analysis_assume( x )
#endif
#include <malloc.h> // DG: _alloca16 needs that
// RB: added <stdint.h> for missing uintptr_t with MinGW
#include <stdint.h>
#endif
// RB end
#include <basetsd.h> // for UINT_PTR
#ifdef _MSC_VER
#include <intrin.h>

View file

@ -3,6 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2012 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -26,6 +27,12 @@ If you have questions concerning this license or the applicable additional terms
===========================================================================
*/
// RB: missing __analysis_assume
#if defined(__MINGW32__)
#include <sal.h>
#endif
// RB end
#include "ParallelJobList_JobHeaders.h"
#ifdef _WIN32

View file

@ -40,6 +40,8 @@ If you have questions concerning this license or the applicable additional terms
================================================================================================
*/
// RB: windows specific stuff should only be set on Windows
#if defined(_WIN32)
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // prevent auto literal to string conversion
@ -66,11 +68,16 @@ If you have questions concerning this license or the applicable additional terms
#define MAPVK_VSC_TO_VK_EX 3
#endif
// RB: no available with MinGW
// RB begin
#if defined(__MINGW32__)
//#include <sal.h> // RB: missing __analysis_assume
// including <sal.h> breaks some STL crap ...
#ifndef __analysis_assume
#define __analysis_assume( x )
#endif
#endif
// RB end
#endif
@ -100,6 +107,9 @@ If you have questions concerning this license or the applicable additional terms
#pragma warning(disable : 4996) // unsafe string operations
#endif // _MSC_VER
#endif // #if defined(_WIN32)
// RB end
#include <malloc.h> // no malloc.h on mac or unix
#include <windows.h> // for qgl.h
#undef FindText // fix namespace pollution

View file

@ -31,9 +31,6 @@ If you have questions concerning this license or the applicable additional terms
#include "../../../idlib/sys/sys_intrinsics.h"
#include "../../../idlib/geometry/DrawVert_intrinsics.h"
#ifdef _WIN32
#include <malloc.h> // DG: _alloca16 needs that
#endif
static const __m128i vector_int_neg_one = _mm_set_epi32( -1, -1, -1, -1 );

View file

@ -28,9 +28,6 @@ If you have questions concerning this license or the applicable additional terms
#include "PreLightShadowVolume_local.h"
#ifdef _WIN32 // DG: malloc.h needed for _alloca16
#include <malloc.h>
#endif
/*
===================
PreLightShadowVolumeJob

View file

@ -28,10 +28,6 @@ If you have questions concerning this license or the applicable additional terms
#include "StaticShadowVolume_local.h"
#ifdef _WIN32 // DG: malloc.h needed for _alloca16
#include <malloc.h>
#endif
/*
===================
StaticShadowVolumeJob

1119
neo/sys/sdl/sdl_cpu.cpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -57,6 +57,8 @@ double Sys_GetClockTicks() {
#else
// RB begin
#if defined(_MSC_VER)
unsigned long lo, hi;
__asm {
@ -70,6 +72,24 @@ double Sys_GetClockTicks() {
}
return (double ) lo + (double) 0xFFFFFFFF * hi;
#elif defined(__GNUC__) && defined( __i386__ )
unsigned long lo, hi;
__asm__ __volatile__(
"push %%ebx\n" \
"xor %%eax,%%eax\n" \
"cpuid\n" \
"rdtsc\n" \
"mov %%eax,%0\n" \
"mov %%edx,%1\n" \
"pop %%ebx\n"
: "=r"( lo ), "=r"( hi ) );
return ( double ) lo + ( double ) 0xFFFFFFFF * hi;
#else
#error unsupported CPU
#endif
// RB end
#endif
}

View file

@ -882,6 +882,20 @@ void DumpAllDisplayDevices()
common->Printf( "\n" );
}
// RB: moved out of R_GetModeListForDisplay
class idSort_VidMode : public idSort_Quick< vidMode_t, idSort_VidMode >
{
public:
int Compare( const vidMode_t& a, const vidMode_t& b ) const
{
int wd = a.width - b.width;
int hd = a.height - b.height;
int fd = a.displayHz - b.displayHz;
return ( hd != 0 ) ? hd : ( wd != 0 ) ? wd : fd;
}
};
// RB end
/*
====================
R_GetModeListForDisplay
@ -979,21 +993,9 @@ bool R_GetModeListForDisplay( const int requestedDisplayNum, idList<vidMode_t>&
mode.displayHz = devmode.dmDisplayFrequency;
modeList.AddUnique( mode );
}
if( modeList.Num() > 0 )
{
class idSort_VidMode : public idSort_Quick< vidMode_t, idSort_VidMode >
{
public:
int Compare( const vidMode_t& a, const vidMode_t& b ) const
{
int wd = a.width - b.width;
int hd = a.height - b.height;
int fd = a.displayHz - b.displayHz;
return ( hd != 0 ) ? hd : ( wd != 0 ) ? wd : fd;
}
};
// sort with lowest resolution first
modeList.SortWithTemplate( idSort_VidMode() );

View file

@ -3,6 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2012 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -683,34 +684,37 @@ int Sys_PollMouseInputEvents( int mouseEvents[MAX_MOUSE_EVENTS][2] )
}
else
{
// DG: FIXME: mingw doesn't like using the (rather ugly) DIMOFS_* macros in switch/case..
switch( polled_didod[i].dwOfs )
// RB: replaced switch enum for MinGW
int diaction = polled_didod[i].dwOfs;
if( diaction == DIMOFS_X )
{
case DIMOFS_X:
mouseEvents[i][0] = M_DELTAX;
mouseEvents[i][1] = polled_didod[i].dwData;
Sys_QueEvent( SE_MOUSE, polled_didod[i].dwData, 0, 0, NULL, 0 );
break;
case DIMOFS_Y:
mouseEvents[i][0] = M_DELTAY;
mouseEvents[i][1] = polled_didod[i].dwData;
Sys_QueEvent( SE_MOUSE, 0, polled_didod[i].dwData, 0, NULL, 0 );
break;
case DIMOFS_Z:
mouseEvents[i][0] = M_DELTAZ;
mouseEvents[i][1] = ( int )polled_didod[i].dwData / WHEEL_DELTA;
{
const int value = ( int )polled_didod[i].dwData / WHEEL_DELTA;
const int key = value < 0 ? K_MWHEELDOWN : K_MWHEELUP;
const int iterations = abs( value );
for( int i = 0; i < iterations; i++ )
{
Sys_QueEvent( SE_KEY, key, true, 0, NULL, 0 );
Sys_QueEvent( SE_KEY, key, false, 0, NULL, 0 );
}
}
break;
mouseEvents[i][0] = M_DELTAX;
mouseEvents[i][1] = polled_didod[i].dwData;
Sys_QueEvent( SE_MOUSE, polled_didod[i].dwData, 0, 0, NULL, 0 );
}
else if( diaction == DIMOFS_Y )
{
mouseEvents[i][0] = M_DELTAY;
mouseEvents[i][1] = polled_didod[i].dwData;
Sys_QueEvent( SE_MOUSE, 0, polled_didod[i].dwData, 0, NULL, 0 );
}
else if( diaction == DIMOFS_Z )
{
mouseEvents[i][0] = M_DELTAZ;
mouseEvents[i][1] = ( int )polled_didod[i].dwData / WHEEL_DELTA;
{
const int value = ( int )polled_didod[i].dwData / WHEEL_DELTA;
const int key = value < 0 ? K_MWHEELDOWN : K_MWHEELUP;
const int iterations = abs( value );
for( int i = 0; i < iterations; i++ )
{
Sys_QueEvent( SE_KEY, key, true, 0, NULL, 0 );
Sys_QueEvent( SE_KEY, key, false, 0, NULL, 0 );
}
}
}
// RB end
}
}

View file

@ -1264,34 +1264,6 @@ void Win_Frame() {
}
}
extern "C" { void _chkstk( int size ); };
void clrstk();
/*
====================
TestChkStk
====================
*/
void TestChkStk() {
int buffer[0x1000];
buffer[0] = 1;
}
/*
====================
HackChkStk
====================
*/
void HackChkStk() {
DWORD old;
VirtualProtect( _chkstk, 6, PAGE_EXECUTE_READWRITE, &old );
*(byte *)_chkstk = 0xe9;
*(int *)((int)_chkstk+1) = (int)clrstk - (int)_chkstk - 5;
TestChkStk();
}
/*
====================
GetExceptionCodeInfo
@ -1549,42 +1521,6 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
return 0;
}
/*
====================
clrstk
I tried to get the run time to call this at every function entry, but
====================
*/
static int parmBytes;
__declspec( naked ) void clrstk() {
// eax = bytes to add to stack
__asm {
mov [parmBytes],eax
neg eax ; compute new stack pointer in eax
add eax,esp
add eax,4
xchg eax,esp
mov eax,dword ptr [eax] ; copy the return address
push eax
; clear to zero
push edi
push ecx
mov edi,esp
add edi,12
mov ecx,[parmBytes]
shr ecx,2
xor eax,eax
cld
rep stosd
pop ecx
pop edi
ret
}
}
/*
==================
idSysLocal::OpenURL

View file

@ -29,7 +29,9 @@ If you have questions concerning this license or the applicable additional terms
#include "../../idlib/precompiled.h"
// RB: <DxErr.h> not available on Windows 8 SDK
#if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
#if defined(__MINGW32__)
#include <sal.h>
#elif (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
#include <DxErr.h>
#endif
// RB end