diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/CdStream.h | 2 | ||||
-rw-r--r-- | src/core/CdStreamPosix.cpp | 29 | ||||
-rw-r--r-- | src/core/ControllerConfig.cpp | 7 | ||||
-rw-r--r-- | src/core/Streaming.cpp | 86 | ||||
-rw-r--r-- | src/core/Streaming.h | 4 | ||||
-rw-r--r-- | src/core/World.cpp | 8 | ||||
-rw-r--r-- | src/core/ZoneCull.cpp | 120 | ||||
-rw-r--r-- | src/core/config.h | 11 |
8 files changed, 158 insertions, 109 deletions
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/ControllerConfig.cpp b/src/core/ControllerConfig.cpp index 6e9db6e3..4115cd38 100644 --- a/src/core/ControllerConfig.cpp +++ b/src/core/ControllerConfig.cpp @@ -2784,9 +2784,10 @@ wchar *CControllerConfigManager::GetButtonComboText(e_ControllerAction action) void CControllerConfigManager::SetControllerKeyAssociatedWithAction(e_ControllerAction action, int32 key, eControllerType type) { ResetSettingOrder(action); + int numOfSettings = GetNumOfSettingsForAction(action); m_aSettings[action][type].m_Key = key; - m_aSettings[action][type].m_ContSetOrder = GetNumOfSettingsForAction(action) + 1; + m_aSettings[action][type].m_ContSetOrder = numOfSettings + 1; } int32 CControllerConfigManager::GetMouseButtonAssociatedWithAction(e_ControllerAction action) @@ -2796,8 +2797,10 @@ int32 CControllerConfigManager::GetMouseButtonAssociatedWithAction(e_ControllerA void CControllerConfigManager::SetMouseButtonAssociatedWithAction(e_ControllerAction action, int32 button) { + int numOfSettings = GetNumOfSettingsForAction(action); + m_aSettings[action][MOUSE].m_Key = button; - m_aSettings[action][MOUSE].m_ContSetOrder = GetNumOfSettingsForAction(action) + 1; + m_aSettings[action][MOUSE].m_ContSetOrder = numOfSettings + 1; } void CControllerConfigManager::ResetSettingOrder(e_ControllerAction action) diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index 7b4218ba..9ac22096 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -202,11 +202,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); @@ -1932,9 +1936,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) { @@ -1952,14 +1957,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<ARRAY_SIZE(ms_pStreamingBuffer); i++) { + + // Channel has file to load if (!first && streamIds[i] != -1) { - processI = i; continue; } @@ -1972,12 +1981,16 @@ CStreaming::LoadAllRequestedModels(bool priority) if (ms_aInfoForModel[streamId].GetCdPosnAndSize(posn, size)) { streamIds[i] = -1; + + // Big file, needs 2 buffer if (size > (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; } @@ -1987,8 +2000,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); @@ -1996,33 +2019,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]); - } - 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]); - - if(streamIds[processI] < STREAM_OFFSET_TXD){ - CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(streamIds[processI]); + while (CdStreamSync(nextChannel) != STREAM_NONE) { + CdStreamRead(nextChannel, ms_pStreamingBuffer[nextChannel], imgOffset+streamPoses[nextChannel], streamSizes[nextChannel]); + } + 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[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; @@ -2061,7 +2091,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) @@ -2118,7 +2148,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; } @@ -2798,4 +2828,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 0e2e89be..3294a88e 100644 --- a/src/core/Streaming.h +++ b/src/core/Streaming.h @@ -85,7 +85,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/World.cpp b/src/core/World.cpp index 6ecc294a..62162dcd 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -431,10 +431,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; @@ -451,8 +451,8 @@ CWorld::ProcessVerticalLineSectorList(CPtrList &list, const CColLine &line, CCol } } - if(mindist < dist) { - dist = mindist; + if(dist < mindist) { + mindist = dist; return true; } else return false; diff --git a/src/core/ZoneCull.cpp b/src/core/ZoneCull.cpp index 075a13bc..33586a4e 100644 --- a/src/core/ZoneCull.cpp +++ b/src/core/ZoneCull.cpp @@ -855,66 +855,66 @@ CCullZone::PointFallsWithinZone(CVector pos, float radius) CVector ExtraFudgePointsCoors[] = { - CVector(978.0, -394.0, 18.0), - CVector(1189.7, -414.6, 27.0), - CVector(978.8, -391.0, 19.0), - CVector(1199.0, -502.3, 28.0), - CVector(1037.0, -391.9, 18.4), - CVector(1140.0, -608.7, 16.0), - CVector(1051.0, -26.0, 11.0), - CVector(951.5, -345.1, 12.0), - CVector(958.2, -394.6, 16.0), - CVector(1036.5, -390.0, 15.2), - CVector(960.6, -390.5, 20.9), - CVector(1061.0, -640.6, 16.3), - CVector(1034.5, -388.96, 14.78), - CVector(1038.4, -13.98, 12.2), - CVector(1047.2, -16.7, 10.6), - CVector(1257.9, -333.3, 40.0), - CVector(885.6, -424.9, 17.0), - CVector(1127.5, -795.8, 17.7), - CVector(1133.0, -716.0, 19.0), - CVector(1125.0, -694.0, 18.5), - CVector(1125.0, -670.0, 16.3), - CVector(1051.6, 36.3, 17.9), - CVector(1054.6, -11.4, 15.0), - CVector(1058.9, -278.0, 15.0), - CVector(1059.4, -261.0, 10.9), - CVector(1051.5, -638.5, 16.5), - CVector(1058.2, -643.4, 15.5), - CVector(1058.2, -643.4, 18.0), - CVector(826.0, -260.0, 7.0), - CVector(826.0, -260.0, 11.0), - CVector(833.0, -603.6, 16.4), - CVector(833.0, -603.6, 20.0), - CVector(1002.0, -318.5, 10.5), - CVector(998.0, -318.0, 9.8), - CVector(1127.0, -183.0, 18.1), - CVector(1123.0, -331.5, 23.8), - CVector(1123.8, -429.0, 24.0), - CVector(1197.0, -30.0, 13.7), - CVector(1117.5, -230.0, 17.3), - CVector(1117.5, -230.0, 20.0), - CVector(1120.0, -281.6, 21.5), - CVector(1120.0, -281.6, 24.0), - CVector(1084.5, -1022.7, 17.0), - CVector(1071.5, 5.4, 4.6), - CVector(1177.2, -215.7, 27.6), - CVector(841.6, -460.0, 19.7), - CVector(874.8, -456.6, 16.6), - CVector(918.3, -451.8, 17.8), - CVector(844.0, -495.7, 16.7), - CVector(842.0, -493.4, 21.0), - CVector(1433.5, -774.4, 16.9), - CVector(1051.0, -205.0, 7.5), - CVector(885.5, -425.6, 15.6), - CVector(182.6, -470.4, 27.8), - CVector(132.5, -930.2, 29.0), - CVector(124.7, -904.0, 28.0), - CVector(-50.0, -686.0, 22.0), - CVector(-49.1, -694.5, 22.5), - CVector(1063.8, -404.45, 16.2), - CVector(1062.2, -405.5, 17.0) + CVector(978.0f, -394.0f, 18.0f), + CVector(1189.7f, -414.6f, 27.0f), + CVector(978.8f, -391.0f, 19.0f), + CVector(1199.0f, -502.3f, 28.0f), + CVector(1037.0f, -391.9f, 18.4f), + CVector(1140.0f, -608.7f, 16.0f), + CVector(1051.0f, -26.0f, 11.0f), + CVector(951.5f, -345.1f, 12.0f), + CVector(958.2f, -394.6f, 16.0f), + CVector(1036.5f, -390.0f, 15.2f), + CVector(960.6f, -390.5f, 20.9f), + CVector(1061.0f, -640.6f, 16.3f), + CVector(1034.5f, -388.96f, 14.78f), + CVector(1038.4f, -13.98f, 12.2f), + CVector(1047.2f, -16.7f, 10.6f), + CVector(1257.9f, -333.3f, 40.0f), + CVector(885.6f, -424.9f, 17.0f), + CVector(1127.5f, -795.8f, 17.7f), + CVector(1133.0f, -716.0f, 19.0f), + CVector(1125.0f, -694.0f, 18.5f), + CVector(1125.0f, -670.0f, 16.3f), + CVector(1051.6f, 36.3f, 17.9f), + CVector(1054.6f, -11.4f, 15.0f), + CVector(1058.9f, -278.0f, 15.0f), + CVector(1059.4f, -261.0f, 10.9f), + CVector(1051.5f, -638.5f, 16.5f), + CVector(1058.2f, -643.4f, 15.5f), + CVector(1058.2f, -643.4f, 18.0f), + CVector(826.0f, -260.0f, 7.0f), + CVector(826.0f, -260.0f, 11.0f), + CVector(833.0f, -603.6f, 16.4f), + CVector(833.0f, -603.6f, 20.0f), + CVector(1002.0f, -318.5f, 10.5f), + CVector(998.0f, -318.0f, 9.8f), + CVector(1127.0f, -183.0f, 18.1f), + CVector(1123.0f, -331.5f, 23.8f), + CVector(1123.8f, -429.0f, 24.0f), + CVector(1197.0f, -30.0f, 13.7f), + CVector(1117.5f, -230.0f, 17.3f), + CVector(1117.5f, -230.0f, 20.0f), + CVector(1120.0f, -281.6f, 21.5f), + CVector(1120.0f, -281.6f, 24.0f), + CVector(1084.5f, -1022.7f, 17.0f), + CVector(1071.5f, 5.4f, 4.6f), + CVector(1177.2f, -215.7f, 27.6f), + CVector(841.6f, -460.0f, 19.7f), + CVector(874.8f, -456.6f, 16.6f), + CVector(918.3f, -451.8f, 17.8f), + CVector(844.0f, -495.7f, 16.7f), + CVector(842.0f, -493.4f, 21.0f), + CVector(1433.5f, -774.4f, 16.9f), + CVector(1051.0f, -205.0f, 7.5f), + CVector(885.5f, -425.6f, 15.6f), + CVector(182.6f, -470.4f, 27.8f), + CVector(132.5f, -930.2f, 29.0f), + CVector(124.7f, -904.0f, 28.0f), + CVector(-50.0f, -686.0f, 22.0f), + CVector(-49.1f, -694.5f, 22.5f), + CVector(1063.8f, -404.45f, 16.2f), + CVector(1062.2f, -405.5f, 17.0f) }; int32 NumTestPoints; int32 aTestPointsX[100]; diff --git a/src/core/config.h b/src/core/config.h index b2c7135a..bb1ca5e3 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -392,8 +392,13 @@ enum Config { #endif #endif -// IMG -#define BIG_IMG // allows to read larger img files + +// 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 +#define BIG_IMG // Not complete - allows to read larger img files //#define SQUEEZE_PERFORMANCE #ifdef SQUEEZE_PERFORMANCE @@ -404,6 +409,8 @@ enum Config { #define VC_RAIN_NERF // Reduces number of rain particles #endif +// ------- + #if defined __MWERKS__ || defined VANILLA_DEFINES #define FINAL #undef CHATTYSPLASH |