From ab939e059b4263fec4e26425bce6a12ecf88d2e6 Mon Sep 17 00:00:00 2001 From: erorcun Date: Wed, 27 Jan 2021 18:26:08 +0300 Subject: Clean up POSIX streaming code --- src/core/CdStream.h | 2 +- src/core/CdStreamPosix.cpp | 29 +++++++++------- src/core/Streaming.cpp | 82 +++++++++++++++++++++++++++++++--------------- src/core/Streaming.h | 4 +++ src/core/config.h | 11 ++++--- 5 files changed, 85 insertions(+), 43 deletions(-) (limited to 'src/core') diff --git a/src/core/CdStream.h b/src/core/CdStream.h index d0f9a855..516cef48 100644 --- a/src/core/CdStream.h +++ b/src/core/CdStream.h @@ -43,6 +43,6 @@ char *CdStreamGetImageName(int32 cd); void CdStreamRemoveImages(void); int32 CdStreamGetNumImages(void); -#ifndef _WIN32 +#ifdef FLUSHABLE_STREAMING extern bool flushStream[MAX_CDCHANNELS]; #endif diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index 0854d850..8a27665a 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -21,9 +21,9 @@ #define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) #define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) -// #define ONE_THREAD_PER_CHANNEL // Don't use if you're not on SSD/Flash. (Also you may want to benefit from this via using all channels in Streaming.cpp) - +#ifdef FLUSHABLE_STREAMING bool flushStream[MAX_CDCHANNELS]; +#endif struct CdReadInfo { @@ -99,6 +99,7 @@ CdStreamInitThread(void) ASSERT(0); return; } + #ifdef ONE_THREAD_PER_CHANNEL sprintf(semName,"/semaphore_start%d",i); gpReadInfo[i].pStartSemaphore = sem_open(semName, O_CREAT, 0644, 1); @@ -245,10 +246,12 @@ CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size) if ( pChannel->nSectorsToRead != 0 || pChannel->bReading ) { if (pChannel->hFile == hImage - 1 && pChannel->nSectorOffset == _GET_OFFSET(offset) && pChannel->nSectorsToRead >= size) return STREAM_SUCCESS; - +#ifdef FLUSHABLE_STREAMING flushStream[channel] = 1; CdStreamSync(channel); - //return STREAM_NONE; +#else + return STREAM_NONE; +#endif } pChannel->hFile = hImage - 1; @@ -316,34 +319,34 @@ CdStreamSync(int32 channel) CdReadInfo *pChannel = &gpReadInfo[channel]; ASSERT( pChannel != nil ); +#ifdef FLUSHABLE_STREAMING if (flushStream[channel]) { -#ifdef ONE_THREAD_PER_CHANNEL pChannel->nSectorsToRead = 0; +#ifdef ONE_THREAD_PER_CHANNEL pthread_kill(pChannel->pChannelThread, SIGUSR1); if (pChannel->bReading) { pChannel->bLocked = true; - while (pChannel->bLocked) - sem_wait(pChannel->pDoneSemaphore); - } #else - pChannel->nSectorsToRead = 0; if (pChannel->bReading) { pChannel->bLocked = true; pthread_kill(_gCdStreamThread, SIGUSR1); +#endif while (pChannel->bLocked) sem_wait(pChannel->pDoneSemaphore); } -#endif pChannel->bReading = false; flushStream[channel] = false; return STREAM_NONE; } +#endif if ( pChannel->nSectorsToRead != 0 ) { pChannel->bLocked = true; - while (pChannel->bLocked) + while (pChannel->bLocked && pChannel->nSectorsToRead != 0){ sem_wait(pChannel->pDoneSemaphore); + } + pChannel->bLocked = false; } pChannel->bReading = false; @@ -447,7 +450,7 @@ void *CdStreamThread(void *param) if ( pChannel->bLocked ) { pChannel->bLocked = 0; - sem_post(pChannel->pDoneSemaphore); + sem_post(pChannel->pDoneSemaphore); } pChannel->bReading = false; } @@ -524,7 +527,9 @@ void CdStreamRemoveImages(void) { for ( int32 i = 0; i < gNumChannels; i++ ) { +#ifdef FLUSHABLE_STREAMING flushStream[i] = 1; +#endif CdStreamSync(i); } diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index 6f0e3153..b28a99fc 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -207,11 +207,15 @@ CStreaming::Init2(void) // allocate streaming buffers if(ms_streamingBufferSize & 1) ms_streamingBufferSize++; +#ifndef ONE_THREAD_PER_CHANNEL ms_pStreamingBuffer[0] = (int8*)RwMallocAlign(ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE, CDSTREAM_SECTOR_SIZE); ms_streamingBufferSize /= 2; ms_pStreamingBuffer[1] = ms_pStreamingBuffer[0] + ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE; -#ifdef ONE_THREAD_PER_CHANNEL - ms_pStreamingBuffer[2] = (int8*)RwMallocAlign(ms_streamingBufferSize*2*CDSTREAM_SECTOR_SIZE, CDSTREAM_SECTOR_SIZE); +#else + ms_pStreamingBuffer[0] = (int8*)RwMallocAlign(ms_streamingBufferSize*2*CDSTREAM_SECTOR_SIZE, CDSTREAM_SECTOR_SIZE); + ms_streamingBufferSize /= 2; + ms_pStreamingBuffer[1] = ms_pStreamingBuffer[0] + ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE; + ms_pStreamingBuffer[2] = ms_pStreamingBuffer[1] + ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE; ms_pStreamingBuffer[3] = ms_pStreamingBuffer[2] + ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE; #endif debug("Streaming buffer size is %d sectors", ms_streamingBufferSize); @@ -2305,9 +2309,10 @@ CStreaming::LoadRequestedModels(void) } -// Let's load models first, then process it. Unfortunately processing models are still single-threaded. +// Let's load models in 4 threads; when one of them becomes idle, process the file, and fill thread with another file. Unfortunately processing models are still single-threaded. // Currently only supported on POSIX streamer. -#ifdef ONE_THREAD_PER_CHANNEL +// WIP - some files are loaded swapped (CdStreamPosix problem?) +#if 0 //def ONE_THREAD_PER_CHANNEL void CStreaming::LoadAllRequestedModels(bool priority) { @@ -2326,14 +2331,18 @@ CStreaming::LoadAllRequestedModels(bool priority) int streamIds[ARRAY_SIZE(ms_pStreamingBuffer)]; int streamSizes[ARRAY_SIZE(ms_pStreamingBuffer)]; int streamPoses[ARRAY_SIZE(ms_pStreamingBuffer)]; - bool first = true; + int readOrder[4] = {-1}; // Channel IDs ordered by read time + int readI = 0; int processI = 0; + bool first = true; + + // All those "first" checks are because of variables aren't initialized in first pass. while (true) { - // Enumerate files and start reading for (int i=0; i (uint32)ms_streamingBufferSize) { if (i + 1 == ARRAY_SIZE(ms_pStreamingBuffer)) - continue; + break; else if (!first && streamIds[i+1] != -1) continue; + } else { + // Buffer of current channel is part of a "big file", pass if (i != 0 && streamIds[i-1] != -1 && streamSizes[i-1] > (uint32)ms_streamingBufferSize) continue; } @@ -2361,8 +2374,18 @@ CStreaming::LoadAllRequestedModels(bool priority) streamIds[i] = streamId; streamSizes[i] = size; streamPoses[i] = posn; + + if (!first) + assert(readOrder[readI] == -1); + + //printf("read: order %d, ch %d, id %d, size %d\n", readI, i, streamId, size); + CdStreamRead(i, ms_pStreamingBuffer[i], imgOffset+posn, size); - processI = i; + readOrder[readI] = i; + if (first && readI+1 != ARRAY_SIZE(readOrder)) + readOrder[readI+1] = -1; + + readI = (readI + 1) % ARRAY_SIZE(readOrder); } else { ms_aInfoForModel[streamId].RemoveFromList(); DecrementRef(streamId); @@ -2370,33 +2393,40 @@ CStreaming::LoadAllRequestedModels(bool priority) ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_LOADED; streamIds[i] = -1; } - } else + } else { streamIds[i] = -1; + break; + } } first = false; + int nextChannel = readOrder[processI]; - // Now process - if (streamIds[processI] == -1) + // Now start processing + if (nextChannel == -1 || streamIds[nextChannel] == -1) break; + //printf("process: order %d, ch %d, id %d\n", processI, nextChannel, streamIds[nextChannel]); + // Try again on error - while (CdStreamSync(processI) != STREAM_NONE) { - CdStreamRead(processI, ms_pStreamingBuffer[processI], imgOffset+streamPoses[processI], streamSizes[processI]); + while (CdStreamSync(nextChannel) != STREAM_NONE) { + CdStreamRead(nextChannel, ms_pStreamingBuffer[nextChannel], imgOffset+streamPoses[nextChannel], streamSizes[nextChannel]); } - ms_aInfoForModel[streamIds[processI]].m_loadState = STREAMSTATE_READING; - - MakeSpaceFor(streamSizes[processI] * CDSTREAM_SECTOR_SIZE); - ConvertBufferToObject(ms_pStreamingBuffer[processI], streamIds[processI]); - if(ms_aInfoForModel[streamIds[processI]].m_loadState == STREAMSTATE_STARTED) - FinishLoadingLargeFile(ms_pStreamingBuffer[processI], streamIds[processI]); + ms_aInfoForModel[streamIds[nextChannel]].m_loadState = STREAMSTATE_READING; + + MakeSpaceFor(streamSizes[nextChannel] * CDSTREAM_SECTOR_SIZE); + ConvertBufferToObject(ms_pStreamingBuffer[nextChannel], streamIds[nextChannel]); + if(ms_aInfoForModel[streamIds[nextChannel]].m_loadState == STREAMSTATE_STARTED) + FinishLoadingLargeFile(ms_pStreamingBuffer[nextChannel], streamIds[nextChannel]); - if(streamIds[processI] < STREAM_OFFSET_TXD){ - CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(streamIds[processI]); + if(streamIds[nextChannel] < STREAM_OFFSET_TXD){ + CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(streamIds[nextChannel]); if(mi->IsSimple()) mi->m_alpha = 255; } - streamIds[processI] = -1; + streamIds[nextChannel] = -1; + readOrder[processI] = -1; + processI = (processI + 1) % ARRAY_SIZE(readOrder); } ms_bLoadingBigModel = false; @@ -2443,7 +2473,7 @@ CStreaming::LoadAllRequestedModels(bool priority) status = CdStreamRead(0, ms_pStreamingBuffer[0], imgOffset+posn, size); while(CdStreamSync(0) || status == STREAM_NONE); ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_READING; - + MakeSpaceFor(size * CDSTREAM_SECTOR_SIZE); ConvertBufferToObject(ms_pStreamingBuffer[0], streamId); if(ms_aInfoForModel[streamId].m_loadState == STREAMSTATE_STARTED) @@ -2500,7 +2530,7 @@ CStreaming::FlushRequestList(void) next = si->m_next; RemoveModel(si - ms_aInfoForModel); } -#ifndef _WIN32 +#ifdef FLUSHABLE_STREAMING if(ms_channel[0].state == CHANNELSTATE_READING) { flushStream[0] = 1; } @@ -3216,4 +3246,4 @@ CStreaming::PrintStreamingBufferState() DoRWStuffEndOfFrame(); } CTimer::Update(); -} \ No newline at end of file +} diff --git a/src/core/Streaming.h b/src/core/Streaming.h index a67384f6..4ddf0b3b 100644 --- a/src/core/Streaming.h +++ b/src/core/Streaming.h @@ -88,7 +88,11 @@ public: static int32 ms_oldSectorX; static int32 ms_oldSectorY; static int32 ms_streamingBufferSize; +#ifndef ONE_THREAD_PER_CHANNEL static int8 *ms_pStreamingBuffer[2]; +#else + static int8 *ms_pStreamingBuffer[4]; +#endif static size_t ms_memoryUsed; static CStreamingChannel ms_channel[2]; static int32 ms_channelError; diff --git a/src/core/config.h b/src/core/config.h index 7e039ef6..329d70b9 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -393,11 +393,12 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually #endif -#ifdef LIBRW -// these are not supported with librw yet +// Streaming +#if !defined(_WIN32) && !defined(__SWITCH__) + //#define ONE_THREAD_PER_CHANNEL // Don't use if you're not on SSD/Flash - also not utilized too much right now(see commented LoadAllRequestedModels in Streaming.cpp) + #define FLUSHABLE_STREAMING // Make it possible to interrupt reading when processing file isn't needed anymore. #endif -// IMG -#define BIG_IMG // allows to read larger img files +#define BIG_IMG // Not complete - allows to read larger img files //#define SQUEEZE_PERFORMANCE #ifdef SQUEEZE_PERFORMANCE @@ -405,6 +406,8 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually #undef NO_ISLAND_LOADING #endif +// ------- + #if defined __MWERKS__ || defined VANILLA_DEFINES #define FINAL #undef CHATTYSPLASH -- cgit v1.2.3 From be88a42bad207a2c723c3cdb152a872e1a7f14af Mon Sep 17 00:00:00 2001 From: erorcun Date: Thu, 28 Jan 2021 00:51:43 +0300 Subject: Fix some Collision NaN/inf's --- src/core/World.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/World.cpp b/src/core/World.cpp index bc698c83..9da36e7a 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -452,10 +452,10 @@ CWorld::ProcessVerticalLineSector(CSector §or, const CColLine &line, CColPoi } bool -CWorld::ProcessVerticalLineSectorList(CPtrList &list, const CColLine &line, CColPoint &point, float &dist, +CWorld::ProcessVerticalLineSectorList(CPtrList &list, const CColLine &line, CColPoint &point, float &mindist, CEntity *&entity, bool ignoreSeeThrough, CStoredCollPoly *poly) { - float mindist = dist; + float dist = mindist; CPtrNode *node; CEntity *e; CColModel *colmodel; @@ -472,8 +472,8 @@ CWorld::ProcessVerticalLineSectorList(CPtrList &list, const CColLine &line, CCol } } - if(mindist < dist) { - dist = mindist; + if(dist < mindist) { + mindist = dist; return true; } else return false; -- cgit v1.2.3 From e1e4be9017246cc6b4d14d5b5d346c5c142941c0 Mon Sep 17 00:00:00 2001 From: erorcun Date: Thu, 28 Jan 2021 03:49:50 +0300 Subject: Use previous naming & fix LineOfSightSectorList too --- src/core/World.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/World.cpp b/src/core/World.cpp index 9da36e7a..ef1cc948 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -367,7 +367,7 @@ CWorld::ProcessLineOfSightSectorList(CPtrList &list, const CColLine &line, CColP } else if(e->bUsesCollision) colmodel = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); - if(colmodel && CCollision::ProcessLineOfSight(line, e->GetMatrix(), *colmodel, point, dist, + if(colmodel && CCollision::ProcessLineOfSight(line, e->GetMatrix(), *colmodel, point, mindist, ignoreSeeThrough, ignoreShootThrough)) entity = e; if(carTyres && ((CVehicle*)e)->SetUpWheelColModel(&tyreCol) && CCollision::ProcessLineOfSight(line, e->GetMatrix(), tyreCol, tyreColPoint, tyreDist, false, ignoreShootThrough)){ @@ -452,10 +452,10 @@ CWorld::ProcessVerticalLineSector(CSector §or, const CColLine &line, CColPoi } bool -CWorld::ProcessVerticalLineSectorList(CPtrList &list, const CColLine &line, CColPoint &point, float &mindist, +CWorld::ProcessVerticalLineSectorList(CPtrList &list, const CColLine &line, CColPoint &point, float &dist, CEntity *&entity, bool ignoreSeeThrough, CStoredCollPoly *poly) { - float dist = mindist; + float mindist = dist; CPtrNode *node; CEntity *e; CColModel *colmodel; @@ -466,14 +466,14 @@ CWorld::ProcessVerticalLineSectorList(CPtrList &list, const CColLine &line, CCol e->m_scanCode = GetCurrentScanCode(); colmodel = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); - if(CCollision::ProcessVerticalLine(line, e->GetMatrix(), *colmodel, point, dist, + if(CCollision::ProcessVerticalLine(line, e->GetMatrix(), *colmodel, point, mindist, ignoreSeeThrough, false, poly)) entity = e; } } - if(dist < mindist) { - mindist = dist; + if(mindist < dist) { + dist = mindist; return true; } else return false; -- cgit v1.2.3 From 810bad9fd8cf344f7d73b82f042910a4c443b0f7 Mon Sep 17 00:00:00 2001 From: erorcun Date: Fri, 29 Jan 2021 01:44:33 +0300 Subject: Fix some UBs --- src/core/Frontend.cpp | 25 ++++++++++++++++--------- src/core/main.cpp | 5 +++++ 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 5fe3d6be..f38efb66 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -5567,33 +5567,40 @@ void CMenuManager::DrawQuitGameScreen(void) { static int32 exitSignalTimer = 0; + +#ifdef FIX_BUGS + int alpha = clamp(m_nMenuFadeAlpha, 0, 255); +#else + int alpha = m_nMenuFadeAlpha; +#endif + #ifndef MUCH_SHORTER_OUTRO_SCREEN static PauseModeTime lastTickIncrease = 0; - if (m_nMenuFadeAlpha == 255 && CTimer::GetTimeInMillisecondsPauseMode() - lastTickIncrease > 10) { + if (alpha == 255 && CTimer::GetTimeInMillisecondsPauseMode() - lastTickIncrease > 10) { exitSignalTimer++; lastTickIncrease = CTimer::GetTimeInMillisecondsPauseMode(); } #else - static PauseModeTime sincePress = 0; - sincePress += frameTime; - if (sincePress > 500) + static PauseModeTime firstTick = CTimer::GetTimeInMillisecondsPauseMode(); + if (alpha == 255 && CTimer::GetTimeInMillisecondsPauseMode() - firstTick > 1000) { exitSignalTimer = 150; + } #endif static CSprite2d *splash = nil; if (splash == nil) splash = LoadSplash("OUTRO"); - m_aFrontEndSprites[MENUSPRITE_VCLOGO].Draw(CRect(MENU_X(28.0f), MENU_Y(8.0f), MENU_X(157.0f), MENU_Y(138.0f)), CRGBA(255, 255, 255, -(m_nMenuFadeAlpha + 1))); + m_aFrontEndSprites[MENUSPRITE_VCLOGO].Draw(CRect(MENU_X(28.0f), MENU_Y(8.0f), MENU_X(157.0f), MENU_Y(138.0f)), CRGBA(255, 255, 255, 255 - alpha)); // Or we can see menu background from sides #ifdef ASPECT_RATIO_SCALE - CSprite2d::DrawRect(CRect(0, 0, MENU_X_LEFT_ALIGNED(0.f), SCREEN_HEIGHT), CRGBA(0, 0, 0, m_nMenuFadeAlpha)); - CSprite2d::DrawRect(CRect(MENU_X_RIGHT_ALIGNED(0.f), 0, SCREEN_WIDTH, SCREEN_HEIGHT), CRGBA(0, 0, 0, m_nMenuFadeAlpha)); + CSprite2d::DrawRect(CRect(0, 0, MENU_X_LEFT_ALIGNED(0.f), SCREEN_HEIGHT), CRGBA(0, 0, 0, alpha)); + CSprite2d::DrawRect(CRect(MENU_X_RIGHT_ALIGNED(0.f), 0, SCREEN_WIDTH, SCREEN_HEIGHT), CRGBA(0, 0, 0, alpha)); #endif - splash->Draw(CRect(MENU_X_LEFT_ALIGNED(0.f), 0, MENU_X_RIGHT_ALIGNED(0.f), SCREEN_HEIGHT), CRGBA(255, 255, 255, m_nMenuFadeAlpha)); - if (m_nMenuFadeAlpha == 255 && exitSignalTimer == 150) + splash->Draw(CRect(MENU_X_LEFT_ALIGNED(0.f), 0, MENU_X_RIGHT_ALIGNED(0.f), SCREEN_HEIGHT), CRGBA(255, 255, 255, alpha)); + if (alpha == 255 && exitSignalTimer == 150) RsEventHandler(rsQUITAPP, nil); m_bShowMouse = false; diff --git a/src/core/main.cpp b/src/core/main.cpp index 9a0308dd..a08a9535 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -1065,8 +1065,13 @@ DisplayGameDebugText() #endif FrameSamples++; +#ifdef FIX_HIGH_FPS_BUGS_ON_FRONTEND + FramesPerSecondCounter += frameTime / 1000.f; // convert to seconds + FramesPerSecond = FrameSamples / FramesPerSecondCounter; +#else FramesPerSecondCounter += 1000.0f / (CTimer::GetTimeStepNonClippedInSeconds() * 1000.0f); FramesPerSecond = FramesPerSecondCounter / FrameSamples; +#endif if ( FrameSamples > 30 ) { -- cgit v1.2.3 From 595a000f6a72a0bf376f5c019a76bcec9dc98c2f Mon Sep 17 00:00:00 2001 From: aap Date: Fri, 29 Jan 2021 13:43:50 +0100 Subject: fix shutdown --- src/core/Game.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/Game.cpp b/src/core/Game.cpp index 83d30bb4..ed9d67f4 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -591,7 +591,6 @@ bool CGame::ShutDown(void) gPhoneInfo.Shutdown(); CWeapon::ShutdownWeapons(); CPedType::Shutdown(); - CMBlur::MotionBlurClose(); for (int32 i = 0; i < NUMPLAYERS; i++) { @@ -617,7 +616,7 @@ bool CGame::ShutDown(void) CStreaming::Shutdown(); CTxdStore::GameShutdown(); CCollision::Shutdown(); - CWaterLevel::DestroyWavyAtomic(); + CWaterLevel::Shutdown(); CRubbish::Shutdown(); CClouds::Shutdown(); CShadows::Shutdown(); @@ -626,6 +625,7 @@ bool CGame::ShutDown(void) CWeaponEffects::Shutdown(); CParticle::Shutdown(); CPools::ShutDown(); + CHud::ReInitialise(); CTxdStore::RemoveTxdSlot(gameTxdSlot); CMBlur::MotionBlurClose(); CdStreamRemoveImages(); -- cgit v1.2.3 From 982b024c5c7564251358293e160bc674e555d9cd Mon Sep 17 00:00:00 2001 From: erorcun Date: Fri, 29 Jan 2021 16:25:32 +0300 Subject: CdStreamPosix fixes --- src/core/CdStreamPosix.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index 8a27665a..e18280e5 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -76,7 +76,7 @@ CdStreamInitThread(void) gChannelRequestQ.tail = 0; gChannelRequestQ.size = gNumChannels + 1; ASSERT(gChannelRequestQ.items != nil ); - gCdStreamSema = sem_open("/semaphore_cd_stream", O_CREAT, 0644, 1); + gCdStreamSema = sem_open("/semaphore_cd_stream", O_CREAT, 0644, 0); if (gCdStreamSema == SEM_FAILED) { @@ -91,7 +91,7 @@ CdStreamInitThread(void) for ( int32 i = 0; i < gNumChannels; i++ ) { sprintf(semName,"/semaphore_done%d",i); - gpReadInfo[i].pDoneSemaphore = sem_open(semName, O_CREAT, 0644, 1); + gpReadInfo[i].pDoneSemaphore = sem_open(semName, O_CREAT, 0644, 0); if (gpReadInfo[i].pDoneSemaphore == SEM_FAILED) { @@ -102,7 +102,7 @@ CdStreamInitThread(void) #ifdef ONE_THREAD_PER_CHANNEL sprintf(semName,"/semaphore_start%d",i); - gpReadInfo[i].pStartSemaphore = sem_open(semName, O_CREAT, 0644, 1); + gpReadInfo[i].pStartSemaphore = sem_open(semName, O_CREAT, 0644, 0); if (gpReadInfo[i].pStartSemaphore == SEM_FAILED) { @@ -171,6 +171,7 @@ CdStreamInit(int32 numChannels) gNumImages = 0; gNumChannels = numChannels; + ASSERT( gNumChannels != 0 ); gpReadInfo = (CdReadInfo *)calloc(numChannels, sizeof(CdReadInfo)); ASSERT( gpReadInfo != nil ); @@ -398,7 +399,12 @@ void *CdStreamThread(void *param) #ifndef ONE_THREAD_PER_CHANNEL while (gCdStreamThreadStatus != 2) { sem_wait(gCdStreamSema); + int32 channel = GetFirstInQueue(&gChannelRequestQ); + + // spurious wakeup + if (channel == -1) + continue; #else int channel = *((int*)param); while (gpReadInfo[channel].nThreadStatus != 2){ -- cgit v1.2.3 From 934aa92a9b9c2bfd2bf4af8316bf12fb83416902 Mon Sep 17 00:00:00 2001 From: withmorten Date: Fri, 29 Jan 2021 16:41:34 +0100 Subject: add NewRenderer ini read/write, fix backfaceculling read --- src/core/re3.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/core') diff --git a/src/core/re3.cpp b/src/core/re3.cpp index d0006fd3..83ef7c88 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -406,6 +406,10 @@ bool LoadINISettings() ReadIniIfExists("CustomPipesValues", "LightmapMult", &CustomPipes::LightmapMult); ReadIniIfExists("CustomPipesValues", "GlossMult", &CustomPipes::GlossMult); #endif + ReadIniIfExists("Rendering", "BackfaceCulling", &gBackfaceCulling); +#ifdef NEW_RENDERER + ReadIniIfExists("Rendering", "NewRender", &gbNewRenderer); +#endif #ifdef PROPER_SCALING ReadIniIfExists("Draw", "ProperScaling", &CDraw::ms_bProperScaling); @@ -495,6 +499,9 @@ void SaveINISettings() StoreIni("CustomPipesValues", "GlossMult", CustomPipes::GlossMult); #endif StoreIni("Rendering", "BackfaceCulling", gBackfaceCulling); +#ifdef NEW_RENDERER + StoreIni("Rendering", "NewRenderer", gbNewRenderer); +#endif #ifdef PROPER_SCALING StoreIni("Draw", "ProperScaling", CDraw::ms_bProperScaling); -- cgit v1.2.3 From 7db28f9f7f46431fcad9d977275f540e3cbc5a6f Mon Sep 17 00:00:00 2001 From: withmorten Date: Fri, 29 Jan 2021 16:43:17 +0100 Subject: fix NewRender typo --- src/core/re3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/re3.cpp b/src/core/re3.cpp index 83ef7c88..87aca59c 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -408,7 +408,7 @@ bool LoadINISettings() #endif ReadIniIfExists("Rendering", "BackfaceCulling", &gBackfaceCulling); #ifdef NEW_RENDERER - ReadIniIfExists("Rendering", "NewRender", &gbNewRenderer); + ReadIniIfExists("Rendering", "NewRenderer", &gbNewRenderer); #endif #ifdef PROPER_SCALING -- cgit v1.2.3 From c4328afce7e2a0b48b9d0d2b225496e29fff1c0a Mon Sep 17 00:00:00 2001 From: erorcun Date: Fri, 29 Jan 2021 03:44:12 +0300 Subject: Even more fixes & shorten quit screen --- src/core/Frontend.cpp | 2 +- src/core/Radar.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index f38efb66..16a70697 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -5582,7 +5582,7 @@ CMenuManager::DrawQuitGameScreen(void) } #else static PauseModeTime firstTick = CTimer::GetTimeInMillisecondsPauseMode(); - if (alpha == 255 && CTimer::GetTimeInMillisecondsPauseMode() - firstTick > 1000) { + if (alpha == 255 && CTimer::GetTimeInMillisecondsPauseMode() - firstTick > 750) { exitSignalTimer = 150; } #endif diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index 8cd86344..4bb9c966 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -824,7 +824,7 @@ int32 CRadar::GetNewUniqueBlipIndex(int32 i) uint32 CRadar::GetRadarTraceColour(uint32 color, bool bright) { - int32 c; + uint32 c; switch (color) { case RADAR_TRACE_RED: if (bright) -- cgit v1.2.3 From dbf5c06144d6ccc74fce696ea20571939be3ad4a Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 30 Jan 2021 14:53:51 +0300 Subject: fixed bike bomb --- src/core/World.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/World.cpp b/src/core/World.cpp index ef1cc948..40c060c0 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -2239,8 +2239,12 @@ CWorld::UseDetonator(CEntity *pEntity) { int32 i = CPools::GetVehiclePool()->GetSize(); while(--i >= 0) { +#ifdef FIX_BUGS + CVehicle* pVehicle = CPools::GetVehiclePool()->GetSlot(i); +#else CAutomobile *pVehicle = (CAutomobile *)CPools::GetVehiclePool()->GetSlot(i); - if(pVehicle && !pVehicle->m_vehType && pVehicle->m_bombType == CARBOMB_REMOTE && +#endif + if(pVehicle && pVehicle->m_bombType == CARBOMB_REMOTE && pVehicle->m_pBombRigger == pEntity) { pVehicle->m_bombType = CARBOMB_NONE; pVehicle->m_nBombTimer = 500; -- cgit v1.2.3 From 264d7d98d72dd89f8259fbedad56c42b5bdefd55 Mon Sep 17 00:00:00 2001 From: shfil Date: Sun, 31 Jan 2021 15:01:46 +0100 Subject: fix realloc --- src/core/re3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/re3.cpp b/src/core/re3.cpp index 87aca59c..4b828171 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -713,7 +713,7 @@ void CTweakVars::Add(CTweakVar *var) TweakVarsListSize = 0; } if(TweakVarsListSize > 63) - TweakVarsList = (CTweakVar**) realloc(TweakVarsList, (TweakVarsListSize + 1) * sizeof(*var)); + TweakVarsList = (CTweakVar**) realloc(TweakVarsList, (TweakVarsListSize + 1) * sizeof(CTweakVar*)); TweakVarsList[TweakVarsListSize++] = var; // TweakVarsList.push_back(var); -- cgit v1.2.3 From 902e539c0d25ec418cd36c735079561f378c712c Mon Sep 17 00:00:00 2001 From: erorcun Date: Sat, 30 Jan 2021 14:52:48 +0300 Subject: Overhaul MusicManager - fix radio bugs, scroll to prev station, radio off text --- src/core/Camera.cpp | 2 +- src/core/ControllerConfig.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ src/core/ControllerConfig.h | 4 ++++ src/core/config.h | 6 +++++- 4 files changed, 55 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 25d2e5c3..5b3f9aa5 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -1768,7 +1768,7 @@ CCamera::CamControl(void) (m_bLookingAtPlayer || WhoIsInControlOfTheCamera == CAMCONTROL_OBBE) && !m_WideScreenOn && (WhoIsInControlOfTheCamera != CAMCONTROL_OBBE || bSwitchedToObbeCam)) - DMAudio.PlayFrontEndSound(SOUND_HUD_SOUND, 0); + DMAudio.PlayFrontEndSound(SOUND_HUD, 0); } // What a mess! diff --git a/src/core/ControllerConfig.cpp b/src/core/ControllerConfig.cpp index 23e86a79..7f634619 100644 --- a/src/core/ControllerConfig.cpp +++ b/src/core/ControllerConfig.cpp @@ -1765,6 +1765,51 @@ void CControllerConfigManager::DeleteMatching1rstPersonControls(e_ControllerActi #undef CLEAR_ACTION_IF_NEEDED +#ifdef RADIO_SCROLL_TO_PREV_STATION +#define CHECK_ACTION(action) \ +if (key == GetControllerKeyAssociatedWithAction(action, type))\ + return true; + +bool CControllerConfigManager::IsAnyVehicleActionAssignedToMouseKey(int32 key) +{ + const eControllerType type = MOUSE; + if (!GetIsKeyBlank(key, type)) + { +#ifdef BIND_VEHICLE_FIREWEAPON + CHECK_ACTION(VEHICLE_FIREWEAPON); +#endif + CHECK_ACTION(VEHICLE_LOOKBEHIND); + CHECK_ACTION(VEHICLE_LOOKLEFT); + CHECK_ACTION(VEHICLE_LOOKRIGHT); + CHECK_ACTION(VEHICLE_HORN); + CHECK_ACTION(VEHICLE_HANDBRAKE); + CHECK_ACTION(VEHICLE_ACCELERATE); + CHECK_ACTION(VEHICLE_BRAKE); + CHECK_ACTION(VEHICLE_CHANGE_RADIO_STATION); + CHECK_ACTION(TOGGLE_SUBMISSIONS); + CHECK_ACTION(VEHICLE_TURRETLEFT); + CHECK_ACTION(VEHICLE_TURRETRIGHT); + CHECK_ACTION(VEHICLE_TURRETUP); + CHECK_ACTION(VEHICLE_TURRETDOWN); + CHECK_ACTION(VEHICLE_ENTER_EXIT); + CHECK_ACTION(CAMERA_CHANGE_VIEW_ALL_SITUATIONS); +#ifndef BIND_VEHICLE_FIREWEAPON + CHECK_ACTION(PED_FIREWEAPON); +#endif + CHECK_ACTION(GO_LEFT); + CHECK_ACTION(GO_RIGHT); + CHECK_ACTION(NETWORK_TALK); + CHECK_ACTION(SWITCH_DEBUG_CAM_ON); + CHECK_ACTION(TOGGLE_DPAD); + CHECK_ACTION(TAKE_SCREEN_SHOT); + CHECK_ACTION(SHOW_MOUSE_POINTER_TOGGLE); + } + return false; +} + +#undef CHECK_ACTION +#endif + void CControllerConfigManager::DeleteMatchingActionInitiators(e_ControllerAction action, int32 key, eControllerType type) { if (!GetIsKeyBlank(key, type)) diff --git a/src/core/ControllerConfig.h b/src/core/ControllerConfig.h index 604fb5cc..d61e23e6 100644 --- a/src/core/ControllerConfig.h +++ b/src/core/ControllerConfig.h @@ -195,6 +195,10 @@ public: void DeleteMatching1rstPersonControls (e_ControllerAction action, int32 key, eControllerType type); void DeleteMatchingActionInitiators (e_ControllerAction action, int32 key, eControllerType type); +#ifdef RADIO_SCROLL_TO_PREV_STATION + bool IsAnyVehicleActionAssignedToMouseKey(int32 key); +#endif + bool GetIsKeyBlank(int32 key, eControllerType type); e_ControllerActionType GetActionType(e_ControllerAction action); diff --git a/src/core/config.h b/src/core/config.h index 329d70b9..f64a7602 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -306,8 +306,8 @@ enum Config { // Hud, frontend and radar #define PC_MENU - #define FIX_RADAR // use radar size from early version before R* broke it +#define RADIO_OFF_TEXT // Won't work without FIX_BUGS #ifndef PC_MENU # define PS2_MENU @@ -376,6 +376,7 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually #define FREE_CAM // Rotating cam // Audio +#define RADIO_SCROLL_TO_PREV_STATION // Won't work without FIX_BUGS #define AUDIO_CACHE // cache sound lengths to speed up the cold boot //#define PS2_AUDIO_PATHS // changes audio paths for cutscenes and radio to PS2 paths (needs vbdec on MSS builds) //#define AUDIO_OAL_USE_SNDFILE // use libsndfile to decode WAVs instead of our internal decoder @@ -462,6 +463,7 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually #undef BUTTON_ICONS #undef FIX_RADAR +#undef RADIO_OFF_TEXT #undef MAP_ENHANCEMENTS #undef MUCH_SHORTER_OUTRO_SCREEN @@ -490,4 +492,6 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually #undef IMPROVED_CAMERA #undef FREE_CAM #undef BIG_IMG + +#undef RADIO_SCROLL_TO_PREV_STATION #endif -- cgit v1.2.3 From 1b293a3cfb914748a217f36a98ac650d28424697 Mon Sep 17 00:00:00 2001 From: withmorten Date: Tue, 2 Feb 2021 11:32:20 +0100 Subject: no advanced script log when log level is 0 --- src/core/config.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core') diff --git a/src/core/config.h b/src/core/config.h index f64a7602..e75cdfb0 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -347,6 +347,10 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually #define USE_ADVANCED_SCRIPT_DEBUG_OUTPUT #define SCRIPT_LOG_FILE_LEVEL 0 // 0 == no log, 1 == overwrite every frame, 2 == full log +#if SCRIPT_LOG_FILE_LEVEL == 0 +#undef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT +#endif + #ifndef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT #define USE_BASIC_SCRIPT_DEBUG_OUTPUT #endif -- cgit v1.2.3 From 713562685a89578ae5e4008f0a283c39175429fc Mon Sep 17 00:00:00 2001 From: erorcun Date: Tue, 2 Feb 2021 16:39:08 +0300 Subject: OAL Loops, fixes --- src/core/Frontend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 16a70697..4eae64b7 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -5591,7 +5591,7 @@ CMenuManager::DrawQuitGameScreen(void) if (splash == nil) splash = LoadSplash("OUTRO"); - m_aFrontEndSprites[MENUSPRITE_VCLOGO].Draw(CRect(MENU_X(28.0f), MENU_Y(8.0f), MENU_X(157.0f), MENU_Y(138.0f)), CRGBA(255, 255, 255, 255 - alpha)); + m_aFrontEndSprites[MENUSPRITE_VCLOGO].Draw(CRect(SCREEN_STRETCH_X(28.0f), MENU_Y(8.0f), SCREEN_STRETCH_X(27.0f) + MENU_X(130.f), MENU_Y(138.0f)), CRGBA(255, 255, 255, 255 - alpha)); // Or we can see menu background from sides #ifdef ASPECT_RATIO_SCALE -- cgit v1.2.3 From 8553120fdbfd74eb2d1609326acbdd8aaa382bea Mon Sep 17 00:00:00 2001 From: withmorten Date: Thu, 4 Feb 2021 19:47:47 +0100 Subject: add missing ASCII_STRCMP stuff --- src/core/config.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/core') diff --git a/src/core/config.h b/src/core/config.h index e75cdfb0..cc82f8d6 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -251,6 +251,12 @@ enum Config { #define FIX_BUGS_64 // Must have fixes to be able to run 64 bit build #endif +#define ASCII_STRCMP // use faster ascii str comparisons + +#if !defined _WIN32 || defined __MWERKS__ || defined __MINGW32__ || defined VANILLA_DEFINES +#undef ASCII_STRCMP +#endif + // Just debug menu entries #ifdef DEBUGMENU #define RELOADABLES // some debug menu options to reload TXD files -- cgit v1.2.3 From a78212ea800fe1919d5380beb25514e3887bcdea Mon Sep 17 00:00:00 2001 From: withmorten Date: Thu, 4 Feb 2021 23:43:04 +0100 Subject: fix MASTER crashes --- src/core/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/common.h b/src/core/common.h index 75ba8863..d39531cc 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -355,7 +355,7 @@ __inline__ void TRACE(char *f, ...) { } // this is re3 only, and so the function #ifndef MASTER #define assert(_Expression) (void)( (!!(_Expression)) || (re3_assert(#_Expression, __FILE__, __LINE__, __FUNCTION__), 0) ) #else -#define assert(_Expression) +#define assert(_Expression) (_Expression) #endif #define ASSERT assert -- cgit v1.2.3 From 9125e604b9225a9cb5efd4a615f10b3c73c1d104 Mon Sep 17 00:00:00 2001 From: aap Date: Fri, 5 Feb 2021 10:58:01 +0100 Subject: fix generic.txd crash --- src/core/Game.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/Game.cpp b/src/core/Game.cpp index ed9d67f4..43bd3d11 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -381,6 +381,11 @@ bool CGame::Initialise(const char* datFile) CTxdStore::Create(gameTxdSlot); CTxdStore::AddRef(gameTxdSlot); +#ifdef EXTENDED_PIPELINES + // for generic fallback + CustomPipes::SetTxdFindCallback(); +#endif + LoadingScreen("Loading the Game", "Loading particles", nil); int particleTxdSlot = CTxdStore::AddTxdSlot("particle"); CTxdStore::LoadTxd(particleTxdSlot, "MODELS/PARTICLE.TXD"); @@ -440,10 +445,7 @@ bool CGame::Initialise(const char* datFile) CFileLoader::LoadLevel("DATA\\DEFAULT.DAT"); CFileLoader::LoadLevel(datFile); -#ifdef EXTENDED_PIPELINES - // for generic fallback - CustomPipes::SetTxdFindCallback(); -#endif + LoadingScreen("Loading the Game", "Add Particles", nil); CWorld::AddParticles(); CVehicleModelInfo::LoadVehicleColours(); -- cgit v1.2.3