/* ======================== idParallelJobList_Threads::InsertSyncPoint ======================== */ ID_INLINE void idParallelJobList_Threads::InsertSyncPoint( jobSyncType_t syncType ) { assert( done ); switch( syncType ) { case SYNC_SIGNAL: { assert( !hasSignal ); if( jobList.Num() ) { assert( !hasSignal ); signalJobCount.Alloc(); signalJobCount[signalJobCount.Num() - 1].SetValue( jobList.Num() - lastSignalJob ); lastSignalJob = jobList.Num(); job_t& job = jobList.Alloc(); job.function = Nop; job.data = & JOB_SIGNAL; hasSignal = true; } break; } case SYNC_SYNCHRONIZE: { if( hasSignal ) { job_t& job = jobList.Alloc(); job.function = Nop; job.data = & JOB_SYNCHRONIZE; hasSignal = false; numSyncs++; } break; } } }
/* ======================== idParallelJobList_Threads::Submit ======================== */ void idParallelJobList_Threads::Submit( idParallelJobList_Threads* waitForJobList, int parallelism ) { assert( done ); assert( numSyncs <= maxSyncs ); assert( ( unsigned int ) jobList.Num() <= maxJobs + numSyncs * 2 ); assert( fetchLock.GetValue() == 0 ); done = false; currentJob.SetValue( 0 ); memset( &deferredThreadStats, 0, sizeof( deferredThreadStats ) ); deferredThreadStats.numExecutedJobs = jobList.Num() - numSyncs * 2; deferredThreadStats.numExecutedSyncs = numSyncs; deferredThreadStats.submitTime = Sys_Microseconds(); deferredThreadStats.startTime = 0; deferredThreadStats.endTime = 0; deferredThreadStats.waitTime = 0; if( jobList.Num() == 0 ) { return; } if( waitForJobList != NULL ) { waitForGuard = & waitForJobList->doneGuards[waitForJobList->currentDoneGuard]; } else { waitForGuard = NULL; } currentDoneGuard = ( currentDoneGuard + 1 ) & ( NUM_DONE_GUARDS - 1 ); doneGuards[currentDoneGuard].SetValue( 1 ); signalJobCount.Alloc(); signalJobCount[signalJobCount.Num() - 1].SetValue( jobList.Num() - lastSignalJob ); job_t& job = jobList.Alloc(); job.function = Nop; job.data = & JOB_LIST_DONE; if( threaded ) { // hand over to the manager void SubmitJobList( idParallelJobList_Threads * jobList, int parallelism ); SubmitJobList( this, parallelism ); } else { // run all the jobs right here threadJobListState_t state( GetVersion() ); RunJobs( 0, state, false ); } }
/* ======================== idParallelJobList_Threads::AddJob ======================== */ ID_INLINE void idParallelJobList_Threads::AddJob( jobRun_t function, void* data ) { assert( done ); #if defined( _DEBUG ) // make sure there isn't already a job with the same function and data in the list if( jobList.Num() < 1000 ) // don't do this N^2 slow check on big lists { for( int i = 0; i < jobList.Num(); i++ ) { assert( jobList[i].function != function || jobList[i].data != data ); } } #endif if( 1 ) // JDC: this never worked in tech5! !jobList.IsFull() ) { { job_t& job = jobList.Alloc(); job.function = function; job.data = data; job.executed = 0; } else { // debug output to show us what is overflowing int currentJobCount[MAX_REGISTERED_JOBS] = {}; for( int i = 0; i < jobList.Num(); ++i ) { const char* jobName = GetJobName( jobList[ i ].function ); for( int j = 0; j < numRegisteredJobs; ++j ) { if( jobName == registeredJobs[ j ].name ) { currentJobCount[ j ]++; break; } } } // print the quantity of each job type for( int i = 0; i < numRegisteredJobs; ++i ) { if( currentJobCount[ i ] > 0 ) { idLib::Printf( "Job: %s, # %d", registeredJobs[ i ].name, currentJobCount[ i ] ); } } idLib::Error( "Can't add job '%s', too many jobs %d", GetJobName( function ), jobList.Num() ); } }
/* ======================== idConsoleLocal::PrintOverlay ======================== */ void idConsoleLocal::PrintOverlay( idOverlayHandle& handle, justify_t justify, const char* text, ... ) { if( handle.index >= 0 && handle.index < overlayText.Num() ) { if( overlayText[handle.index].time == handle.time ) { return; } } char string[MAX_PRINT_MSG]; va_list argptr; va_start( argptr, text ); idStr::vsnPrintf( string, sizeof( string ), text, argptr ); va_end( argptr ); overlayText_t& overlay = overlayText.Alloc(); overlay.text = string; overlay.justify = justify; overlay.time = Sys_Milliseconds(); handle.index = overlayText.Num() - 1; handle.time = overlay.time; }
/* ================ sdVehiclePathGrid::SetupPath ================ */ void sdVehiclePathGrid::SetupPath( const idVec3& position, idList< splineSection_t >& inSpline, idList< splineSection_t >& outSpline, int seed ) const { int x, y; int xmin, ymin; GetCoordsForPoint( x, y, xmin, ymin, position ); int nx, ny; GetEdgePoint( x, y, nx, ny, seed, 0, 0 ); idVec3 edgePos; GetPointInternal( nx, ny, edgePos ); AdjustTargetForStart( edgePos, position, x, y, xmin, ymin ); bool ymainaxis = abs( ny - y ) > abs( nx - x ); int loopPos; int loopDir; int loopStart; int loopEnd; float loopLen; if ( ymainaxis ) { loopPos = ny; loopStart = ny; loopDir = ny > y ? -1 : 1; loopLen = ny - y; loopEnd = y; } else { loopPos = nx; loopStart = nx; loopDir = nx > x ? -1 : 1; loopLen = nx - x; loopEnd = x; } idVec3 endPoint; GetPoint( x, y, endPoint ); idVec3 lastPos; GetPoint( nx, ny, lastPos ); idVec3 inVector = ( endPoint - lastPos ); inVector[ 2 ] = 0.f; inVector.Normalize(); float scale = 64.f; // inVector.Normalize(); inSpline.Clear(); while ( loopPos != loopEnd ) { int currentPos[ 2 ]; loopPos += loopDir; float frac = ( loopPos - loopStart ) / loopLen; if ( ymainaxis ) { currentPos[ 0 ] = nx + ( ( nx - x ) * frac ); currentPos[ 1 ] = loopPos; } else { currentPos[ 0 ] = loopPos; currentPos[ 1 ] = ny + ( ( ny - y ) * frac ); } idVec3 newPos; GetPointInternal( currentPos[ 0 ], currentPos[ 1 ], newPos ); AddSection( lastPos, inVector, newPos, endPoint, loopPos != loopEnd, inSpline ); } { idVec3 hoverPos = position; hoverPos[ 2 ] = lastPos[ 2 ]; idVec3 temp = ( hoverPos - lastPos ); scale = temp.Normalize() * 0.125f; idVec3 newInVector( 0.f, 0.f, -1.f ); newInVector += temp * 0.2f; newInVector.Normalize(); splineSection_t& section = inSpline.Alloc(); section.AddValue( 0.f, lastPos ); section.AddValue( 1.f / 3.f, lastPos + ( inVector * ( scale ) ) ); section.AddValue( 2.f / 3.f, hoverPos - ( newInVector * ( scale ) ) ); section.AddValue( 1.f, hoverPos ); lastPos = hoverPos; inVector = newInVector; } { GetCoordsForPoint( nx, ny, xmin, ymin, lastPos ); idVec3 startPoint; GetPoint( nx, ny, startPoint ); idVec3 temp = startPoint - lastPos; scale = temp.Normalize() * 0.125f; inVector[ 2 ] = 0.f; inVector.Normalize(); inVector *= 0.2f; inVector += idVec3( 0.f, 0.f, 1.f ); inVector.Normalize(); GetEdgePoint( nx, ny, x, y, seed, 0, 0 ); GetPoint( x, y, endPoint ); } ymainaxis = abs( ny - y ) > abs( nx - x ); if ( ymainaxis ) { loopPos = ny; loopStart = ny; loopDir = ny > y ? -1 : 1; loopLen = ny - y; loopEnd = y; } else { loopPos = nx; loopStart = nx; loopDir = nx > x ? -1 : 1; loopLen = nx - x; loopEnd = x; } outSpline.Clear(); while ( loopPos != loopEnd ) { int currentPos[ 2 ]; loopPos += loopDir; float frac = ( loopPos - loopStart ) / loopLen; if ( ymainaxis ) { currentPos[ 0 ] = nx + ( ( nx - x ) * frac ); currentPos[ 1 ] = loopPos; } else { currentPos[ 0 ] = loopPos; currentPos[ 1 ] = ny + ( ( ny - y ) * frac ); } idVec3 newPos; GetPointInternal( currentPos[ 0 ], currentPos[ 1 ], newPos ); AddSection( lastPos, inVector, newPos, endPoint, loopPos != loopEnd, outSpline ); } }
/* ================ sdVehiclePathGrid::AddSection ================ */ void sdVehiclePathGrid::AddSection( idVec3& lastPos, idVec3& inVector, const idVec3& newPos, const idVec3& finalPos, bool canSkip, idList< splineSection_t >& spline ) const { idVec3 dist = newPos - lastPos; idAngles pathAngles = dist.ToAngles(); float pitch = idMath::AngleNormalize180( pathAngles.pitch ); if ( fabs( pitch ) > 30 ) { idVec3 newInVector; splineSection_t& section1 = spline.Alloc(); idVec3 verticalPos; if ( pitch < -30 ) { verticalPos[ 0 ] = lastPos[ 0 ] + ( ( newPos[ 0 ] - lastPos[ 0 ] ) * 0.3f ); verticalPos[ 1 ] = lastPos[ 1 ] + ( ( newPos[ 1 ] - lastPos[ 1 ] ) * 0.3f ); verticalPos[ 2 ] = lastPos[ 2 ] + ( ( newPos[ 2 ] - lastPos[ 2 ] ) * 0.9f ); } else if ( pitch > 30 ) { verticalPos[ 0 ] = newPos[ 0 ] + ( ( lastPos[ 0 ] - newPos[ 0 ] ) * 0.3f ); verticalPos[ 1 ] = newPos[ 1 ] + ( ( lastPos[ 1 ] - newPos[ 1 ] ) * 0.3f ); verticalPos[ 2 ] = newPos[ 2 ] + ( ( lastPos[ 2 ] - newPos[ 2 ] ) * 0.9f ); } newInVector = ( verticalPos - lastPos ); float scale = inVector.Normalize(); section1.AddValue( 0.f, lastPos ); section1.AddValue( 1.f / 3.f, lastPos + ( inVector * ( scale * 0.5f ) ) ); section1.AddValue( 2.f / 3.f, verticalPos - ( newInVector * ( scale * 0.5f ) ) ); section1.AddValue( 1.f, verticalPos ); splineSection_t& section2 = spline.Alloc(); newInVector = ( newPos - verticalPos ); scale = newInVector.Normalize(); section2.AddValue( 0.f, verticalPos ); section2.AddValue( 1.f / 3.f, verticalPos + ( inVector * ( scale * 0.5f ) ) ); section2.AddValue( 2.f / 3.f, newPos - ( newInVector * ( scale * 0.5f ) ) ); section2.AddValue( 1.f, newPos ); lastPos = newPos; inVector = newInVector; return; } if ( canSkip ) { idVec3 dist; dist = newPos - lastPos; dist[ 2 ] = 0; idAngles angles1 = dist.ToAngles(); dist = finalPos - lastPos; dist[ 2 ] = 0; idAngles angles2 = dist.ToAngles(); float yawdiff = idMath::AngleDelta( angles1.yaw, angles2.yaw ); if ( fabs( yawdiff ) > 10.f ) { return; } } idVec3 newInVector = ( newPos - lastPos ); float scale = newInVector.Normalize(); splineSection_t& section = spline.Alloc(); section.AddValue( 0.f, lastPos ); section.AddValue( 1.f / 3.f, lastPos + ( inVector * ( scale * 0.5f ) ) ); section.AddValue( 2.f / 3.f, newPos - ( newInVector * ( scale * 0.5f ) ) ); section.AddValue( 1.f, newPos ); lastPos = newPos; inVector = newInVector; }