Enabled Multi-Threading (as an option) + OpenPandora specific changes (for Shoulder As Mouse Buttons)

This commit is contained in:
ptitSeb 2016-04-12 22:29:39 +02:00
parent df6199de70
commit 9678ec3e58
11 changed files with 145 additions and 29 deletions

View File

@ -139,7 +139,10 @@ endif()
# !!! FIXME: I currently force this, but you shouldn't _have_ to. # !!! FIXME: I currently force this, but you shouldn't _have_ to.
add_definitions(-DSINGLE_THREADED=1) option(USE_SINGLE_THREAD "Use Single Threaded version" TRUE)
if(USE_SINGLE_THREAD)
add_definitions(-DSINGLE_THREADED=1)
endif()
include_directories( include_directories(
@ -572,6 +575,22 @@ if (USE_I386_ASM)
list(APPEND ADDITIONAL_ENGINE_SRCS SoundMixer386.o) list(APPEND ADDITIONAL_ENGINE_SRCS SoundMixer386.o)
endif() endif()
if(USE_SINGLE_THREAD)
set(SYNCHRO_SRCS
Engine/Base/NullSynchronization.cpp # single threaded.
)
else()
#!! TODO Win32/Linux case
set(SYNCHRO_SRCS
Engine/Base/Unix/UnixSynchronization.cpp # multithreaded Unix.
#Engine/Base/SDL/SDLSynchronization.cpp
#Engine/Base/SDL/SDLThreadLocalStorage.cpp # multithreaded Unix.
)
#Engine/Base/Registry.cpp # Windows only.
#Engine/Base/StackDump.cpp # Windows only.
#Engine/Base/Win32/Win32Synchronization.cpp # Windows only.
endif()
set(ENGINE_SRCS set(ENGINE_SRCS
${ENGINE_ENTITIES_CPP} ${ENGINE_ENTITIES_CPP}
Engine/Engine.cpp Engine/Engine.cpp
@ -610,12 +629,7 @@ set(ENGINE_SRCS
Engine/Base/SDL/SDLTimer.cpp Engine/Base/SDL/SDLTimer.cpp
Engine/Base/SDL/SDLInput.cpp Engine/Base/SDL/SDLInput.cpp
Engine/Base/SDL/SDLEvents.cpp Engine/Base/SDL/SDLEvents.cpp
Engine/Base/NullSynchronization.cpp # single threaded. ${SYNCHRO_SRCS}
#Engine/Base/Unix/UnixSynchronization.cpp # multithreaded Unix.
#Engine/Base/SDL/SDLThreadLocalStorage.cpp # multithreaded Unix.
#Engine/Base/Registry.cpp # Windows only.
#Engine/Base/StackDump.cpp # Windows only.
#Engine/Base/Win32/Win32Synchronization.cpp # Windows only.
Engine/Brushes/Brush.cpp Engine/Brushes/Brush.cpp
Engine/Brushes/BrushIO.cpp Engine/Brushes/BrushIO.cpp
Engine/Brushes/BrushShadows.cpp Engine/Brushes/BrushShadows.cpp

View File

@ -234,7 +234,8 @@ void CListNode::Remove(void)
ASSERT(next.IsTailMarker() || next.IsLinked()); ASSERT(next.IsTailMarker() || next.IsLinked());
ASSERT(prev.IsHeadMarker() || prev.IsLinked()); ASSERT(prev.IsHeadMarker() || prev.IsLinked());
next.ln_Pred = &prev; if(ln_Succ)
next.ln_Pred = &prev;
prev.ln_Succ = &next; prev.ln_Succ = &next;
// make a non-linked node // make a non-linked node
ln_Succ = NULL; ln_Succ = NULL;

22
Sources/Engine/Base/SDL/SDLEvents.cpp Normal file → Executable file
View File

@ -50,6 +50,13 @@ BOOL PeekMessage(MSG *msg, void *hwnd, UINT wMsgFilterMin,
case SDL_KEYUP: case SDL_KEYUP:
if (sdlevent.key.keysym.sym == SDLK_BACKQUOTE) if (sdlevent.key.keysym.sym == SDLK_BACKQUOTE)
msg->unicode = '~'; // !!! FIXME: this is all a hack. msg->unicode = '~'; // !!! FIXME: this is all a hack.
#ifdef PLATFORM_PANDORA
if(sdlevent.key.keysym.sym == SDLK_RCTRL) {
msg->message = (sdlevent.type==SDL_KEYDOWN)?WM_RBUTTONDOWN:WM_RBUTTONUP;
} else if(sdlevent.key.keysym.sym == SDLK_RSHIFT) {
msg->message = (sdlevent.type==SDL_KEYDOWN)?WM_LBUTTONDOWN:WM_LBUTTONUP;
} else
#endif
msg->wParam = sdlevent.key.keysym.sym; msg->wParam = sdlevent.key.keysym.sym;
return TRUE; return TRUE;
@ -107,17 +114,28 @@ void DispatchMessage(MSG *msg)
SHORT GetKeyState(int vk) SHORT GetKeyState(int vk)
{ {
SHORT retval = 0; SHORT retval = 0;
#ifdef PLATFORM_PANDORA
Uint8 *keystate = SDL_GetKeyboardState(NULL);
#endif
switch (vk) switch (vk)
{ {
case VK_LBUTTON: case VK_LBUTTON:
if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LMASK) if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LMASK)
retval = 0x8000; retval = 0x8000;
#ifdef PLATFORM_PANDORA
if(keystate[SDL_SCANCODE_RSHIFT])
retval = 0x8000;
#endif
break; break;
case VK_RBUTTON: case VK_RBUTTON:
if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_RMASK) if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_RMASK)
retval = 0x8000; retval = 0x8000;
#ifdef PLATFORM_PANDORA
if(keystate[SDL_SCANCODE_RCTRL])
retval = 0x8000;
#endif
break; break;
case VK_MBUTTON: case VK_MBUTTON:
@ -127,7 +145,11 @@ SHORT GetKeyState(int vk)
default: default:
STUBBED("this can't possibly be right, yeah?"); STUBBED("this can't possibly be right, yeah?");
#ifdef PLATFORM_PANDORA
if (keystate[SDL_GetScancodeFromKey((SDL_Keycode)vk)])
#else
if (SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey((SDL_Keycode)vk)]) if (SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey((SDL_Keycode)vk)])
#endif
retval = 0x8000; retval = 0x8000;
break; break;
} // switch } // switch

View File

@ -49,6 +49,8 @@ INDEX inp_bMsgDebugger = FALSE;
INDEX inp_bForceJoystickPolling = 0; INDEX inp_bForceJoystickPolling = 0;
INDEX inp_bAutoDisableJoysticks = 0; INDEX inp_bAutoDisableJoysticks = 0;
static CTCriticalSection sl_csInput;
extern INDEX inp_ctJoysticksAllowed; extern INDEX inp_ctJoysticksAllowed;
/* /*
@ -281,6 +283,16 @@ static void SetKeyFromEvent(const SDL_Event *event, const BOOL bDown)
return; return;
} // if } // if
#ifdef PLATFORM_PANDORA
if(event->key.keysym.sym==SDLK_RSHIFT) {
_abKeysPressed[KID_MOUSE1] = bDown;
return;
} else if(event->key.keysym.sym==SDLK_RCTRL) {
_abKeysPressed[KID_MOUSE2] = bDown;
return;
}
#endif
// convert virtualkey to kid // convert virtualkey to kid
const INDEX iKID = _aiScancodeToKid[event->key.keysym.scancode]; const INDEX iKID = _aiScancodeToKid[event->key.keysym.scancode];
@ -333,10 +345,14 @@ static void sdl_event_handler(const SDL_Event *event)
int SE_SDL_InputEventPoll(SDL_Event *sdlevent) int SE_SDL_InputEventPoll(SDL_Event *sdlevent)
{ {
ASSERT(sdlevent != NULL); ASSERT(sdlevent != NULL);
const int retval = SDL_PollEvent(sdlevent); CTSingleLock slInput(&sl_csInput, FALSE);
if (retval) if(slInput.TryToLock()) {
sdl_event_handler(sdlevent); const int retval = SDL_PollEvent(sdlevent);
return retval; if (retval)
sdl_event_handler(sdlevent);
return retval;
}
return 0;
} // SE_SDL_InputEventPoll } // SE_SDL_InputEventPoll
@ -495,6 +511,9 @@ BOOL CInput::PlatformInit(void)
_pShell->DeclareSymbol("persistent user INDEX inp_bSDLPermitCtrlG;", (void*)&inp_bSDLPermitCtrlG); _pShell->DeclareSymbol("persistent user INDEX inp_bSDLPermitCtrlG;", (void*)&inp_bSDLPermitCtrlG);
_pShell->DeclareSymbol("persistent user INDEX inp_bSDLGrabInput;", (void*)&inp_bSDLGrabInput); _pShell->DeclareSymbol("persistent user INDEX inp_bSDLGrabInput;", (void*)&inp_bSDLGrabInput);
MakeConversionTables(); MakeConversionTables();
sl_csInput.cs_iIndex = 3000;
return(TRUE); return(TRUE);
} }
@ -697,12 +716,25 @@ void CInput::GetInput(BOOL bPreScan)
// get codes // get codes
INDEX iKID = kc.kc_iKID; INDEX iKID = kc.kc_iKID;
//INDEX iScan = kc.kc_iScanCode; //INDEX iScan = kc.kc_iScanCode;
//INDEX iVirt = kc.kc_iVirtKey; INDEX iVirt = kc.kc_iVirtKey;
// if reading async keystate
// if snooped that key is pressed if (inp_iKeyboardReadingMethod==0) {
if (_abKeysPressed[iKID]) { // if there is a valid virtkey
// mark it as pressed if (iVirt>=0) {
inp_ubButtonsBuffer[iKID] = 0xFF; // is state is pressed
if (SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey((SDL_Keycode)iVirt)]) {
// mark it as pressed
inp_ubButtonsBuffer[iKID] = 0xFF;
}
}
}
else
{
// if snooped that key is pressed
if (_abKeysPressed[iKID]) {
// mark it as pressed
inp_ubButtonsBuffer[iKID] = 0xFF;
}
} }
} }
} }
@ -712,7 +744,16 @@ void CInput::GetInput(BOOL bPreScan)
_abKeysPressed[KID_MOUSEWHEELDOWN] = FALSE; _abKeysPressed[KID_MOUSEWHEELDOWN] = FALSE;
// read mouse position // read mouse position
if ((mouse_relative_x != 0) || (mouse_relative_y != 0)) { //#define USE_MOUSEWARP 1
#ifdef USE_MOUSEWARP
int iMx, iMy;
SDL_GetRelativeMouseState(&iMx, &iMy);
mouse_relative_x = iMx;
mouse_relative_y = iMy;
#else
if ((mouse_relative_x != 0) || (mouse_relative_y != 0))
#endif
{
FLOAT fDX = FLOAT( mouse_relative_x ); FLOAT fDX = FLOAT( mouse_relative_x );
FLOAT fDY = FLOAT( mouse_relative_y ); FLOAT fDY = FLOAT( mouse_relative_y );
@ -762,11 +803,14 @@ void CInput::GetInput(BOOL bPreScan)
inp_caiAllAxisInfo[1].cai_fReading = fMouseRelX; inp_caiAllAxisInfo[1].cai_fReading = fMouseRelX;
inp_caiAllAxisInfo[2].cai_fReading = fMouseRelY; inp_caiAllAxisInfo[2].cai_fReading = fMouseRelY;
inp_caiAllAxisInfo[3].cai_fReading = fMouseRelZ; inp_caiAllAxisInfo[3].cai_fReading = fMouseRelZ;
} else { }
#ifndef USE_MOUSEWARP
else {
inp_caiAllAxisInfo[1].cai_fReading = 0.0; inp_caiAllAxisInfo[1].cai_fReading = 0.0;
inp_caiAllAxisInfo[2].cai_fReading = 0.0; inp_caiAllAxisInfo[2].cai_fReading = 0.0;
inp_caiAllAxisInfo[3].cai_fReading = 0.0; inp_caiAllAxisInfo[3].cai_fReading = 0.0;
} }
#endif
/* /*
// if not pre-scanning // if not pre-scanning

View File

@ -12,7 +12,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#pragma GCC optimize 0
#include "Engine/StdH.h" #include "Engine/StdH.h"
#include <sys/types.h> #include <sys/types.h>

9
Sources/Engine/Base/Timer.cpp Normal file → Executable file
View File

@ -190,8 +190,9 @@ void __stdcall CTimer_TimerFunc(UINT uID, UINT uMsg, ULONG dwUser, ULONG dw1, UL
} }
#elif (defined PLATFORM_UNIX) #elif (defined PLATFORM_UNIX)
#include "SDL.h" #include "SDL.h"
Uint32 CTimer_TimerFunc_SDL(Uint32 interval) Uint32 CTimer_TimerFunc_SDL(Uint32 interval, void* param)
{ {
(void)param;
// access to the list of handlers must be locked // access to the list of handlers must be locked
CTSingleLock slHooks(&_pTimer->tm_csHooks, TRUE); CTSingleLock slHooks(&_pTimer->tm_csHooks, TRUE);
// handle all timers // handle all timers
@ -421,8 +422,8 @@ CTimer::CTimer(BOOL bInterrupt /*=TRUE*/)
#else #else
if (SDL_Init(SDL_INIT_TIMER) == -1) FatalError(TRANS("Cannot initialize multimedia timer!")); if (SDL_Init(SDL_INIT_TIMER) == -1) FatalError(TRANS("Cannot initialize multimedia timer!"));
SDL_SetTimer(ULONG(TickQuantum*1000.0f), CTimer_TimerFunc_SDL); tm_TimerID = SDL_AddTimer(ULONG(TickQuantum*1000.0f), CTimer_TimerFunc_SDL, NULL);
if( tm_TimerID==NULL) FatalError(TRANS("Cannot initialize multimedia timer!"));
#endif #endif
// make sure that timer interrupt is ticking // make sure that timer interrupt is ticking
@ -461,7 +462,7 @@ CTimer::~CTimer(void)
ASSERT(tm_lhHooks.IsEmpty()); ASSERT(tm_lhHooks.IsEmpty());
#else #else
SDL_SetTimer(0, NULL); SDL_RemoveTimer(tm_TimerID);
#endif #endif
#endif #endif

4
Sources/Engine/Base/Timer.h Normal file → Executable file
View File

@ -82,7 +82,11 @@ public:
FLOAT tm_fLerpFactor; // factor used for lerping between frames FLOAT tm_fLerpFactor; // factor used for lerping between frames
FLOAT tm_fLerpFactor2; // secondary lerp-factor used for unpredicted movement FLOAT tm_fLerpFactor2; // secondary lerp-factor used for unpredicted movement
#ifdef PLATFORM_WIN32
ULONG tm_TimerID; // windows timer ID ULONG tm_TimerID; // windows timer ID
#else
int tm_TimerID; // SDL_TimerID in fact
#endif
CTCriticalSection tm_csHooks; // access to timer hooks CTCriticalSection tm_csHooks; // access to timer hooks
CListHead tm_lhHooks; // a list head for timer hooks CListHead tm_lhHooks; // a list head for timer hooks

View File

@ -6,7 +6,7 @@
#include "Engine/StdH.h" #include "Engine/StdH.h"
#include <Engine/Base/Synchronization.h> #include <Engine/Base/Synchronization.h>
//#pragma GCC optimize 0
CTCriticalSection::CTCriticalSection(void) CTCriticalSection::CTCriticalSection(void)
{ {
cs_pvObject = (void *) new pthread_mutex_t; cs_pvObject = (void *) new pthread_mutex_t;
@ -25,7 +25,14 @@ INDEX CTCriticalSection::Lock(void)
{ {
if (owner == pthread_self()) if (owner == pthread_self())
return(++LockCounter); return(++LockCounter);
if(owner==0 && LockCounter) {
//printf("Warning, suspicious mutex state, force unlocking...\n");
pthread_mutex_unlock((pthread_mutex_t *) cs_pvObject);
LockCounter=0;
}
if(owner!=0) {
// do something???
}
pthread_mutex_lock((pthread_mutex_t *) cs_pvObject); pthread_mutex_lock((pthread_mutex_t *) cs_pvObject);
owner = pthread_self(); owner = pthread_self();
return(++LockCounter); return(++LockCounter);
@ -51,7 +58,7 @@ INDEX CTCriticalSection::Unlock(void)
{ {
if (--LockCounter == 0) if (--LockCounter == 0)
{ {
pthread_mutex_unlock((pthread_mutex_t *) cs_pvObject); int ret = pthread_mutex_unlock((pthread_mutex_t *) cs_pvObject);
owner = 0; owner = 0;
} }
} }

View File

@ -648,7 +648,12 @@ ENGINE_API void SE_InitEngine(const char *argv0, CTString strGameID)
ReleaseDC( NULL, hdc); ReleaseDC( NULL, hdc);
#else #else
// !!! FIXME : rcg01072002 This CAN be done with SDL, actually. Move this somewhere. // !!! FIXME : rcg01072002 This CAN be done with SDL, actually. Move this somewhere.
#ifdef PLATFORM_PANDORA
// hacked gamma support
_pGfx->gl_ulFlags |= GLF_ADJUSTABLEGAMMA;
#else
CPrintF( TRANS("\nWARNING: Gamma, brightness and contrast are not adjustable!\n\n")); CPrintF( TRANS("\nWARNING: Gamma, brightness and contrast are not adjustable!\n\n"));
#endif
#endif #endif
// !!! FIXME : rcg12072001 Move this somewhere else. // !!! FIXME : rcg12072001 Move this somewhere else.
@ -688,6 +693,9 @@ ENGINE_API void SE_EndEngine(void)
//ASSERT(bOK); //ASSERT(bOK);
ReleaseDC( NULL, hdc); ReleaseDC( NULL, hdc);
} }
#elif defined(PLATFORM_PANDORA)
// restore default gamma
system("sudo /usr/pandora/scripts/op_gamma.sh 0");
#endif #endif
// free stocks // free stocks

View File

@ -1992,6 +1992,18 @@ void CGfxLibrary::SwapBuffers(CViewPort *pvp)
} }
} }
else else
#elif defined(PLATFORM_PANDORA)
if( gl_ulFlags & GLF_ADJUSTABLEGAMMA) {
//hacky Gamma only (no Contrast/Brightness) support.
static float old_pandora_gamma = 0.0f;
if (old_pandora_gamma!=gfx_fGamma) {
char buf[50];
sprintf(buf,"sudo /usr/pandora/scripts/op_gamma.sh %.2f", gfx_fGamma);
system(buf);
old_pandora_gamma = gfx_fGamma;
}
}
else
#endif #endif
// if not supported // if not supported
{ {

View File

@ -2224,7 +2224,10 @@ void CGame::GameRedrawView( CDrawPort *pdpDrawPort, ULONG ulFlags)
_pInput->GetInput(TRUE); _pInput->GetInput(TRUE);
} }
// timer must not occur during prescanning // timer must not occur during prescanning
{ CTSingleLock csTimer(&_pTimer->tm_csHooks, TRUE); {
#if defined(PLATFORM_UNIX) && !defined(SINGLE_THREADED)
CTSingleLock csTimer(&_pTimer->tm_csHooks, TRUE);
#endif
// for each local player // for each local player
for( INDEX i=0; i<4; i++) { for( INDEX i=0; i<4; i++) {
// if local player // if local player