Exemplo n.º 1
0
void
SimUpdateSingleCar(int index, double deltaTime,tSituation *s)
{
	int i;
	//int ncar;
	tCarElt *carElt;
	tCar *car;
	
	SimDeltaTime = (tdble) deltaTime;
	SimCarTable[index].collision = 0;
	SimCarTable[index].blocked = 0;
	
	car = &(SimCarTable[index]);
	carElt = car->carElt;

	CHECK(car);
	ctrlCheck(car);
	CHECK(car);
	SimSteerUpdate(car);
	CHECK(car);
	SimGearboxUpdate(car);
	CHECK(car);
	SimEngineUpdateTq(car);
	CHECK(car);
	
	SimCarUpdateWheelPos(car);
	CHECK(car);
	SimBrakeSystemUpdate(car);
	CHECK(car);
	SimAeroUpdate(car, s);
	CHECK(car);
	for (i = 0; i < 2; i++){
		SimWingUpdate(car, i, s);
	}
	CHECK(car);
	for (i = 0; i < 4; i++){
		SimWheelUpdateRide(car, i);
	}
	CHECK(car);
	for (i = 0; i < 2; i++){
		SimAxleUpdate(car, i);
	}
	CHECK(car);
	for (i = 0; i < 4; i++){
		SimWheelUpdateForce(car, i);
	}
	CHECK(car);
	SimTransmissionUpdate(car);
	CHECK(car);
	SimWheelUpdateRotation(car);
	CHECK(car);
	SimCarUpdate(car, s);
	CHECK(car);
	
	/* copy back the data to carElt */

	carElt->pub.DynGC = car->DynGC;
	carElt->pub.DynGCg = car->DynGCg;
	sgMakeCoordMat4(carElt->pub.posMat, carElt->_pos_X, carElt->_pos_Y, carElt->_pos_Z - carElt->_statGC_z,
					(float) RAD2DEG(carElt->_yaw), (float) RAD2DEG(carElt->_roll), (float) RAD2DEG(carElt->_pitch));
	carElt->_trkPos = car->trkPos;
	for (i = 0; i < 4; i++) {
		carElt->priv.wheel[i].relPos = car->wheel[i].relPos;
		carElt->_wheelSeg(i) = car->wheel[i].trkPos.seg;
		carElt->_brakeTemp(i) = car->wheel[i].brake.temp;
		carElt->pub.corner[i] = car->corner[i].pos;
	}
	carElt->_gear = car->transmission.gearbox.gear;
	carElt->_enginerpm = car->engine.rads;
	carElt->_fuel = car->fuel;
	carElt->priv.collision |= car->collision;
	carElt->_dammage = car->dammage;
}
Exemplo n.º 2
0
void
SimUpdate(tSituation *s, double deltaTime, int telemetry)
{
    int		i;
    int		ncar;
    tCarElt 	*carElt;
    tCar 	*car;
    sgVec3	P;
	static const float UPSIDE_DOWN_TIMEOUT = 5.0f;

	double timestamp_start = GfTimeClock();
    SimDeltaTime = deltaTime;
    SimTelemetry = 0;//telemetry;
    for (ncar = 0; ncar < s->_ncars; ncar++) {
		SimCarTable[ncar].collision = 0;
		SimCarTable[ncar].blocked = 0;
    }
    
    for (ncar = 0; ncar < s->_ncars; ncar++) {
		car = &(SimCarTable[ncar]);
		carElt = car->carElt;

		if (carElt->_state & RM_CAR_STATE_NO_SIMU) {
			RemoveCar(car, s);
			continue;
		} else if (((s->_maxDammage) && (car->dammage > s->_maxDammage)) ||
				   (car->fuel == 0) ||
				   (car->upside_down_timer > UPSIDE_DOWN_TIMEOUT) ||
				   (car->carElt->_state & RM_CAR_STATE_ELIMINATED))  {
			RemoveCar(car, s);
			if (carElt->_state & RM_CAR_STATE_NO_SIMU) {
				continue;
			}
		}
	
		if (s->_raceState & RM_RACE_PRESTART) {
			car->ctrl->gear = 0;
		}
	



		CHECK(car);
		ctrlCheck(car);
		CHECK(car);
		SimSteerUpdate(car);
		CHECK(car);
		SimGearboxUpdate(car);
		CHECK(car);
		SimEngineUpdateTq(car);
		CHECK(car);


		if (!(s->_raceState & RM_RACE_PRESTART)) {

				SimCarUpdateWheelPos(car);
			CHECK(car);
				SimBrakeSystemUpdate(car);
			CHECK(car);
				SimAeroUpdate(car, s);
			CHECK(car);
				for (i = 0; i < 2; i++){
				SimWingUpdate(car, i, s);
			}
			CHECK(car);
				for (i = 0; i < 4; i++){
				SimWheelUpdateRide(car, i);
			}
			CHECK(car);
				for (i = 0; i < 2; i++){
				SimAxleUpdate(car, i);
			}
			CHECK(car);
				for (i = 0; i < 4; i++){
				SimWheelUpdateForce(car, i);
			}
			CHECK(car);
		}
		SimTransmissionUpdate(car);
		CHECK(car);

		if (!(s->_raceState & RM_RACE_PRESTART)) {
				SimWheelUpdateRotation(car);
			CHECK(car);
				SimCarUpdate(car, s);
			CHECK(car);
		}
    }

    SimCarCollideCars(s);

    /* printf ("%f - ", s->currentTime); */
    
    for (ncar = 0; ncar < s->_ncars; ncar++) {
		car = &(SimCarTable[ncar]);
		CHECK(car);
		carElt = car->carElt;

		if (carElt->_state & RM_CAR_STATE_NO_SIMU) {
			continue;
		}

		CHECK(car);
		SimCarUpdate2(car, s);

		/* copy back the data to carElt */

		carElt->pub.DynGC = car->DynGC;
		carElt->pub.DynGCg = car->DynGCg;
#if 0
		sgMakeCoordMat4(carElt->pub.posMat, carElt->_pos_X, carElt->_pos_Y, carElt->_pos_Z - carElt->_statGC_z,
						RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_roll), RAD2DEG(carElt->_pitch));
#else
		sgQuatToMatrix (carElt->pub.posMat, car->posQuat);
		carElt->pub.posMat[3][0] = car->DynGCg.pos.x;
		carElt->pub.posMat[3][1] = car->DynGCg.pos.y;
		carElt->pub.posMat[3][2] = car->DynGCg.pos.z - carElt->_statGC_z;
		carElt->pub.posMat[0][3] =  SG_ZERO ;
		carElt->pub.posMat[1][3] =  SG_ZERO ;
		carElt->pub.posMat[2][3] =  SG_ZERO ;
		carElt->pub.posMat[3][3] =  SG_ONE ;
#endif
		carElt->_trkPos = car->trkPos;
		for (i = 0; i < 4; i++) {
			carElt->priv.wheel[i].relPos = car->wheel[i].relPos;
			carElt->_wheelSeg(i) = car->wheel[i].trkPos.seg;
			carElt->_brakeTemp(i) = car->wheel[i].brake.temp;
			carElt->pub.corner[i] = car->corner[i].pos;
		}
		carElt->_gear = car->transmission.gearbox.gear;
		carElt->_enginerpm = car->engine.rads;
		carElt->_fuel = car->fuel;
		carElt->priv.collision |= car->collision;
		carElt->_dammage = car->dammage;

		P[0] = -carElt->_statGC_x;
		P[1] = -carElt->_statGC_y;
		P[2] = -carElt->_statGC_z;
		sgXformPnt3(P, carElt->_posMat);
		carElt->_pos_X = P[0];
		carElt->_pos_Y = P[1];
		carElt->_pos_Z = P[2];
	}
	simu_total_time +=  GfTimeClock() - timestamp_start;
}
Exemplo n.º 3
0
void
SimUpdate(tSituation *s, double deltaTime)
{
	int i;
	int ncar;
	tCarElt *carElt;
	tCar *car;
	
	SimDeltaTime = (tdble) deltaTime;
	for (ncar = 0; ncar < s->_ncars; ncar++) {
		SimCarTable[ncar].collision = 0;
		SimCarTable[ncar].blocked = 0;
	}
	
	for (ncar = 0; ncar < s->_ncars; ncar++) {
		car = &(SimCarTable[ncar]);
		carElt = car->carElt;
	
		if (carElt->_state & RM_CAR_STATE_NO_SIMU) {
			RemoveCar(car, s);
			continue;
		} else if (((s->_maxDammage) && (car->dammage > s->_maxDammage)) ||
			(car->fuel == 0) ||
			(car->carElt->_state & RM_CAR_STATE_ELIMINATED))  {
			RemoveCar(car, s);
			if (carElt->_state & RM_CAR_STATE_NO_SIMU) {
				continue;
			}
		}
	
		if (s->_raceState & RM_RACE_PRESTART && 
				(car->carElt->_skillLevel < 3 || !(s->_features & RM_FEATURE_PENALTIES))) {
			car->ctrl->brakeCmd = 1.0;
			car->ctrl->clutchCmd = 1.0;
		}
	
		CHECK(car);
		ctrlCheck(car);
		CHECK(car);
		SimSteerUpdate(car);
		CHECK(car);
		SimGearboxUpdate(car);
		CHECK(car);
		SimEngineUpdateTq(car);
		CHECK(car);
	
		if (!(s->_raceState & RM_RACE_PRESTART) || car->carElt->_skillLevel == 3) {
	
			SimCarUpdateWheelPos(car);
			CHECK(car);
			SimBrakeSystemUpdate(car);
			CHECK(car);
			SimAeroUpdate(car, s);
			CHECK(car);
			for (i = 0; i < 2; i++){
				SimWingUpdate(car, i, s);
			}
			CHECK(car);
			for (i = 0; i < 4; i++){
				SimWheelUpdateRide(car, i);
			}
			CHECK(car);
			for (i = 0; i < 2; i++){
				SimAxleUpdate(car, i);
			}
			CHECK(car);
			for (i = 0; i < 4; i++){
				SimWheelUpdateForce(car, i);
			}
			CHECK(car);
			SimTransmissionUpdate(car);
			CHECK(car);
			SimWheelUpdateRotation(car);
			CHECK(car);
			SimCarUpdate(car, s);
			CHECK(car);
		} else {
			SimTransmissionUpdate(car);
			SimEngineUpdateRpm(car, 0.0);
		}
	}
	
	SimCarCollideCars(s);
	
	/* printf ("%f - ", s->currentTime); */
	
	for (ncar = 0; ncar < s->_ncars; ncar++) {
		car = &(SimCarTable[ncar]);
		CHECK(car);
		carElt = car->carElt;
	
		if (carElt->_state & RM_CAR_STATE_NO_SIMU) {
			continue;
		}
	
		CHECK(car);
		SimCarUpdate2(car, s); /* telemetry */
	
		/* copy back the data to carElt */
	
		carElt->pub.DynGC = car->DynGC;
		carElt->pub.DynGCg = car->DynGCg;
		sgMakeCoordMat4(carElt->pub.posMat, carElt->_pos_X, carElt->_pos_Y, carElt->_pos_Z - carElt->_statGC_z,
				(float) RAD2DEG(carElt->_yaw), (float) RAD2DEG(carElt->_roll), (float) RAD2DEG(carElt->_pitch));
		carElt->_trkPos = car->trkPos;
		for (i = 0; i < 4; i++) {
			carElt->priv.wheel[i].relPos = car->wheel[i].relPos;
			carElt->_wheelSeg(i) = car->wheel[i].trkPos.seg;
			carElt->_brakeTemp(i) = car->wheel[i].brake.temp;
			carElt->pub.corner[i] = car->corner[i].pos;
		}
		carElt->_gear = car->transmission.gearbox.gear;
		carElt->_enginerpm = car->engine.rads;
		carElt->_fuel = car->fuel;
		carElt->priv.collision |= car->collision;
		carElt->_dammage = car->dammage;
	}
}