示例#1
0
void GameSession::SimulateLateElement(MR_FreeElementHandle pElement,
                                      MR_SimulationTime pDuration, int pRoom)
{
    MR_SimulationTime lTimeToSimulate = pDuration;

    if(lTimeToSimulate < 0) {
        return;
    }

    if(mSimulationTime <= lTimeToSimulate) {
        // can't backtrack below 0
        return;
    }
    // clock back
    MR_SimulationTime lOriginalTime = mSimulationTime;
    mSimulationTime -= lTimeToSimulate;

    while((pRoom >= 0) && (lTimeToSimulate >= MR_SIMULATION_SLICE)) {
        pRoom = SimulateOneFreeElem(MR_SIMULATION_SLICE, pElement, pRoom);
        lTimeToSimulate -= MR_SIMULATION_SLICE;
        mSimulationTime += MR_SIMULATION_SLICE;
    }

    if((pRoom >= 0) && (lTimeToSimulate >= MR_MINIMUM_SIMULATION_SLICE)) {
        pRoom = SimulateOneFreeElem(lTimeToSimulate, pElement, pRoom);
        SimulateFreeElems(mSimulationTime < 0 ? 0 : lTimeToSimulate);
    }
    // return to good time
    mSimulationTime = lOriginalTime;
}
示例#2
0
void GameSession::Simulate()
{
	Level *mCurrentLevel = track->GetLevel();
	ASSERT(mCurrentLevel != nullptr);

	Util::OS::timestamp_t lSimulateCallTime = Util::OS::Time();
	MR_SimulationTime lTimeToSimulate;

	// Determine the duration of the simulation step
	lTimeToSimulate = static_cast<MR_SimulationTime>(
		lSimulateCallTime - mLastSimulateCallTime);

	if(lTimeToSimulate < 0)
		lTimeToSimulate = 0;

	/*
	   if( (lTimeToSimulate < 0 )||(lTimeToSimulate>500) )
	   {
	   // There is someting wrong with the calculated duration
	   // This is probably because the game have been paused
	   // (or the refresh rate is extrenemly slow, less than 2 frames sec)

	   // Use a relativly small time step
	   lTimeToSimulate = 20; // 2/100 of second
	   }
	 */

	while(lTimeToSimulate >= MR_SIMULATION_SLICE) {
		SimulateFreeElems(mSimulationTime < 0 ? 0 : MR_SIMULATION_SLICE);
		lTimeToSimulate -= MR_SIMULATION_SLICE;
		mSimulationTime += MR_SIMULATION_SLICE;
	}

	if(lTimeToSimulate >= MR_MINIMUM_SIMULATION_SLICE) {
		SimulateFreeElems(mSimulationTime < 0 ? 0 : lTimeToSimulate);
		mSimulationTime += lTimeToSimulate;
		lTimeToSimulate = 0;
	}

	SimulateSurfaceElems(static_cast<MR_SimulationTime>(
		lSimulateCallTime - lTimeToSimulate - mLastSimulateCallTime));

	mLastSimulateCallTime = lSimulateCallTime - lTimeToSimulate;
}