From 8821f62b0c37d7f60d49bd6ae7471fb03dd84405 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 27 Dec 2022 21:10:15 -0600 Subject: [PATCH] misc fixes utilize specialty case soundarray macros. slim duplicate entries in vehicle already hand;ed by rigidshape. create a gamebasedata::onnewdatablock which calls onremove and onadd for the db for those classes like wheeledvehicle that expect mounting logic to occur --- Engine/source/T3D/assets/SoundAsset.h | 8 +- Engine/source/T3D/fx/lightning.cpp | 6 +- Engine/source/T3D/player.cpp | 22 +- Engine/source/T3D/rigidShape.cpp | 47 ++- Engine/source/T3D/rigidShape.h | 1 - Engine/source/T3D/shapeBase.cpp | 2 +- Engine/source/T3D/vehicles/flyingVehicle.cpp | 6 +- Engine/source/T3D/vehicles/hoverVehicle.cpp | 12 +- Engine/source/T3D/vehicles/vehicle.cpp | 322 +----------------- Engine/source/T3D/vehicles/vehicle.h | 56 +-- Engine/source/T3D/vehicles/wheeledVehicle.cpp | 24 +- Engine/source/sfx/sfxPlayList.cpp | 6 +- .../scripts/gameObjectManagement.tscript | 6 + 13 files changed, 98 insertions(+), 420 deletions(-) diff --git a/Engine/source/T3D/assets/SoundAsset.h b/Engine/source/T3D/assets/SoundAsset.h index 43e424c30..272fa1726 100644 --- a/Engine/source/T3D/assets/SoundAsset.h +++ b/Engine/source/T3D/assets/SoundAsset.h @@ -486,15 +486,15 @@ if (m##name##AssetId[index] != StringTable->EmptyString())\ const char* enumString = castConsoleTypeToString(static_cast(itter));\ if (enumString && enumString[0])\ {\ - addField(assetEnumNameConcat(enumString, File), TypeSoundFilename, Offset(m##name##Name[0], consoleClass) + sizeof(m##name##Name[0])*i, assetText(name, docs), AbstractClassRep::FIELD_HideInInspectors); \ - addField(assetEnumNameConcat(enumString, Asset), TypeSoundAssetId, Offset(m##name##AssetId[0], consoleClass) + sizeof(m##name##AssetId[0])*i, assetText(name, asset reference.));\ + addField(assetEnumNameConcat(enumString, File), TypeSoundFilename, Offset(m##name##Name[i], consoleClass), assetText(name, docs), AbstractClassRep::FIELD_HideInInspectors); \ + addField(assetEnumNameConcat(enumString, Asset), TypeSoundAssetId, Offset(m##name##AssetId[i], consoleClass), assetText(name, asset reference.));\ }\ } #define PACKDATA_SOUNDASSET_ARRAY(name, index)\ - if (stream->writeFlag(m##name##Asset[index].notNull()))\ + if (stream->writeFlag(AssetDatabase.isDeclaredAsset(m##name##AssetId[index])))\ {\ - stream->writeString(m##name##Asset[index].getAssetId());\ + stream->writeString(m##name##AssetId[index]);\ }\ else\ {\ diff --git a/Engine/source/T3D/fx/lightning.cpp b/Engine/source/T3D/fx/lightning.cpp index 8d9e20183..9fb30f625 100644 --- a/Engine/source/T3D/fx/lightning.cpp +++ b/Engine/source/T3D/fx/lightning.cpp @@ -242,7 +242,7 @@ LightningData::LightningData() for (S32 i = 0; i < MaxThunders; i++) { - INIT_ASSET_ARRAY(ThunderSound, i); + INIT_SOUNDASSET_ARRAY(ThunderSound, i); } for (S32 i = 0; i < MaxTextures; i++) @@ -335,7 +335,7 @@ void LightningData::packData(BitStream* stream) U32 i; for (i = 0; i < MaxThunders; i++) { - PACKDATA_ASSET_ARRAY(ThunderSound, i); + PACKDATA_SOUNDASSET_ARRAY(ThunderSound, i); } stream->writeInt(mNumStrikeTextures, 4); @@ -353,7 +353,7 @@ void LightningData::unpackData(BitStream* stream) U32 i; for (i = 0; i < MaxThunders; i++) { - UNPACKDATA_ASSET_ARRAY(ThunderSound, i); + UNPACKDATA_SOUNDASSET_ARRAY(ThunderSound, i); } mNumStrikeTextures = stream->readInt(4); diff --git a/Engine/source/T3D/player.cpp b/Engine/source/T3D/player.cpp index 9dd153574..32b0b0d22 100644 --- a/Engine/source/T3D/player.cpp +++ b/Engine/source/T3D/player.cpp @@ -423,7 +423,7 @@ PlayerData::PlayerData() boxHeadFrontPercentage = 1; for (S32 i = 0; i < MaxSounds; i++) - INIT_ASSET_ARRAY(PlayerSound, i); + INIT_SOUNDASSET_ARRAY(PlayerSound, i); footPuffEmitter = NULL; footPuffID = 0; @@ -469,17 +469,17 @@ bool PlayerData::preload(bool server, String &errorStr) { if(!Parent::preload(server, errorStr)) return false; - - for (U32 i = 0; i < MaxSounds; ++i) - { - _setPlayerSound(getPlayerSound(i), i); - if (getPlayerSound(i) != StringTable->EmptyString()) + if (!server) { + for (U32 i = 0; i < MaxSounds; ++i) { - if (!getPlayerSoundProfile(i)) - Con::errorf("PlayerData::Preload() - unable to find sfxProfile for asset %d %s", i, mPlayerSoundAssetId[i]); + _setPlayerSound(getPlayerSound(i), i); + if (getPlayerSound(i) != StringTable->EmptyString()) + { + if (!getPlayerSoundProfile(i)) + Con::errorf("PlayerData::Preload() - unable to find sfxProfile for asset %d %s", i, mPlayerSoundAssetId[i]); + } } } - // runSurfaceCos = mCos(mDegToRad(runSurfaceAngle)); jumpSurfaceCos = mCos(mDegToRad(jumpSurfaceAngle)); @@ -1271,7 +1271,7 @@ void PlayerData::packData(BitStream* stream) stream->write(minLateralImpactSpeed); for (U32 i = 0; i < MaxSounds; i++) - PACKDATA_ASSET_ARRAY(PlayerSound, i); + PACKDATA_SOUNDASSET_ARRAY(PlayerSound, i); mathWrite(*stream, boxSize); mathWrite(*stream, crouchBoxSize); @@ -1452,7 +1452,7 @@ void PlayerData::unpackData(BitStream* stream) stream->read(&minLateralImpactSpeed); for (U32 i = 0; i < MaxSounds; i++) - UNPACKDATA_ASSET_ARRAY(PlayerSound, i); + UNPACKDATA_SOUNDASSET_ARRAY(PlayerSound, i); mathRead(*stream, &boxSize); mathRead(*stream, &crouchBoxSize); diff --git a/Engine/source/T3D/rigidShape.cpp b/Engine/source/T3D/rigidShape.cpp index 42e16b94d..3fe833824 100644 --- a/Engine/source/T3D/rigidShape.cpp +++ b/Engine/source/T3D/rigidShape.cpp @@ -207,6 +207,27 @@ TriggerObjectType | CorpseObjectType; +typedef RigidShapeData::Body::Sounds bodySounds; +DefineEnumType(bodySounds); + +ImplementEnumType(bodySounds, "enum types.\n" + "@ingroup VehicleData\n\n") + { bodySounds::SoftImpactSound, "SoftImpactSound", "..." }, + { bodySounds::HardImpactSound, "HardImpactSound", "..." }, +EndImplementEnumType; + +typedef RigidShapeData::Sounds waterSounds; +DefineEnumType(waterSounds); + +ImplementEnumType(waterSounds, "enum types.\n" + "@ingroup RigidShapeData\n\n") + { waterSounds::ExitWater, "ExitWater", "..." }, + { waterSounds::ImpactSoft, "ImpactSoft", "..." }, + { waterSounds::ImpactMedium, "ImpactMedium", "..." }, + { waterSounds::ImpactHard, "ImpactHard", "..." }, + { waterSounds::Wake, "Wake", "..." }, +EndImplementEnumType; + //---------------------------------------------------------------------------- RigidShapeData::RigidShapeData() @@ -238,7 +259,7 @@ RigidShapeData::RigidShapeData() density = 4; for (S32 i = 0; i < Body::MaxSounds; i++) - INIT_ASSET_ARRAY(BodySounds, i); + INIT_SOUNDASSET_ARRAY(BodySounds, i); dustEmitter = NULL; dustID = 0; @@ -257,7 +278,7 @@ RigidShapeData::RigidShapeData() enablePhysicsRep = true; for (S32 i = 0; i < Sounds::MaxSounds; i++) - INIT_ASSET_ARRAY(WaterSounds, i); + INIT_SOUNDASSET_ARRAY(WaterSounds, i); dragForce = 0; vertFactor = 0.25; @@ -301,7 +322,7 @@ bool RigidShapeData::preload(bool server, String &errorStr) if (!server) { for (S32 i = 0; i < Body::MaxSounds; i++) { - if (mBodySounds[i]) + if (getBodySounds(i) != StringTable->EmptyString()) { _setBodySounds(getBodySounds(i), i); } @@ -309,7 +330,7 @@ bool RigidShapeData::preload(bool server, String &errorStr) for (S32 j = 0; j < Sounds::MaxSounds; j++) { - if (mWaterSounds[j]) + if (getWaterSounds(j) != StringTable->EmptyString()) { _setWaterSounds(getWaterSounds(j), j); } @@ -371,7 +392,7 @@ void RigidShapeData::packData(BitStream* stream) stream->write(body.friction); for (U32 i = 0; i < Body::MaxSounds; ++i) { - PACKDATA_ASSET_ARRAY(BodySounds, i); + PACKDATA_SOUNDASSET_ARRAY(BodySounds, i); } stream->write(minImpactSpeed); @@ -391,8 +412,9 @@ void RigidShapeData::packData(BitStream* stream) stream->write(cameraLag); stream->write(cameraDecay); stream->write(cameraOffset); - - stream->write( dustHeight ); + + stream->write(triggerDustHeight); + stream->write(dustHeight); stream->write(exitSplashSoundVel); stream->write(softSplashSoundVel); @@ -403,7 +425,7 @@ void RigidShapeData::packData(BitStream* stream) // write the water sound profiles for (U32 i = 0; i < Sounds::MaxSounds; ++i) { - PACKDATA_ASSET_ARRAY(WaterSounds, i); + PACKDATA_SOUNDASSET_ARRAY(WaterSounds, i); } if (stream->writeFlag( dustEmitter )) @@ -434,7 +456,7 @@ void RigidShapeData::unpackData(BitStream* stream) for (U32 i = 0; i < Body::Sounds::MaxSounds; i++) { - UNPACKDATA_ASSET_ARRAY(BodySounds, i); + UNPACKDATA_SOUNDASSET_ARRAY(BodySounds, i); } stream->read(&minImpactSpeed); @@ -455,6 +477,7 @@ void RigidShapeData::unpackData(BitStream* stream) stream->read(&cameraDecay); stream->read(&cameraOffset); + stream->read(&triggerDustHeight); stream->read( &dustHeight ); stream->read(&exitSplashSoundVel); @@ -466,7 +489,7 @@ void RigidShapeData::unpackData(BitStream* stream) // write the water sound profiles for (U32 i = 0; i < Sounds::MaxSounds; ++i) { - UNPACKDATA_ASSET_ARRAY(WaterSounds, i); + UNPACKDATA_SOUNDASSET_ARRAY(WaterSounds, i); } if( stream->readFlag() ) @@ -539,14 +562,14 @@ void RigidShapeData::initPersistFields() addGroup( "Sounds" ); - INITPERSISTFIELD_SOUNDASSET_ARRAY(BodySounds, Body::Sounds::MaxSounds, RigidShapeData, "Sounds for body."); + INITPERSISTFIELD_SOUNDASSET_ENUMED(BodySounds, bodySounds, Body::Sounds::MaxSounds, RigidShapeData, "Sounds for body."); addField("exitSplashSoundVelocity", TypeF32, Offset(exitSplashSoundVel, RigidShapeData), "The minimum velocity at which the exit splash sound will be played when emerging from water.\n"); addField("softSplashSoundVelocity", TypeF32, Offset(softSplashSoundVel, RigidShapeData),"The minimum velocity at which the soft splash sound will be played when impacting water.\n"); addField("mediumSplashSoundVelocity", TypeF32, Offset(medSplashSoundVel, RigidShapeData), "The minimum velocity at which the medium splash sound will be played when impacting water.\n"); addField("hardSplashSoundVelocity", TypeF32, Offset(hardSplashSoundVel, RigidShapeData), "The minimum velocity at which the hard splash sound will be played when impacting water.\n"); - INITPERSISTFIELD_SOUNDASSET_ARRAY(WaterSounds, Sounds::MaxSounds, RigidShapeData, "Sounds for interacting with water."); + INITPERSISTFIELD_SOUNDASSET_ENUMED(WaterSounds, waterSounds, Sounds::MaxSounds, RigidShapeData, "Sounds for interacting with water."); endGroup( "Sounds" ); diff --git a/Engine/source/T3D/rigidShape.h b/Engine/source/T3D/rigidShape.h index c96c10c50..fe5d3623a 100644 --- a/Engine/source/T3D/rigidShape.h +++ b/Engine/source/T3D/rigidShape.h @@ -64,7 +64,6 @@ class RigidShapeData : public ShapeBaseData } body; DECLARE_SOUNDASSET_ARRAY(RigidShapeData, BodySounds, Body::Sounds::MaxSounds) - DECLARE_ASSET_ARRAY_SETGET(RigidShapeData, BodySounds); enum RigidShapeConsts { diff --git a/Engine/source/T3D/shapeBase.cpp b/Engine/source/T3D/shapeBase.cpp index dab20b693..1d2ca3502 100644 --- a/Engine/source/T3D/shapeBase.cpp +++ b/Engine/source/T3D/shapeBase.cpp @@ -1572,7 +1572,7 @@ void ShapeBase::setControllingClient( GameConnection* client ) gSFX3DWorld->setListener( NULL ); } - else if( client && client->isConnectionToServer() && !getControllingObject() ) + else if( client && client->isConnectionToServer() && (getControllingObject() != this) ) { // We're on the local client and not controlled by another object, so make // us the current SFX listener. diff --git a/Engine/source/T3D/vehicles/flyingVehicle.cpp b/Engine/source/T3D/vehicles/flyingVehicle.cpp index 075b62bbc..6cbf6d2b3 100644 --- a/Engine/source/T3D/vehicles/flyingVehicle.cpp +++ b/Engine/source/T3D/vehicles/flyingVehicle.cpp @@ -116,7 +116,7 @@ FlyingVehicleData::FlyingVehicleData() jetEmitter[j] = 0; for (S32 i = 0; i < MaxSounds; i++) - INIT_ASSET_ARRAY(FlyingSounds, i); + INIT_SOUNDASSET_ARRAY(FlyingSounds, i); vertThrustMultiple = 1.0; } @@ -241,7 +241,7 @@ void FlyingVehicleData::packData(BitStream* stream) for (S32 i = 0; i < MaxSounds; i++) { - PACKDATA_ASSET_ARRAY(FlyingSounds, i); + PACKDATA_SOUNDASSET_ARRAY(FlyingSounds, i); } for (S32 j = 0; j < MaxJetEmitters; j++) @@ -276,7 +276,7 @@ void FlyingVehicleData::unpackData(BitStream* stream) for (S32 i = 0; i < MaxSounds; i++) { - UNPACKDATA_ASSET_ARRAY(FlyingSounds, i); + UNPACKDATA_SOUNDASSET_ARRAY(FlyingSounds, i); } for (S32 j = 0; j < MaxJetEmitters; j++) { diff --git a/Engine/source/T3D/vehicles/hoverVehicle.cpp b/Engine/source/T3D/vehicles/hoverVehicle.cpp index 03ba6a855..83292cb88 100644 --- a/Engine/source/T3D/vehicles/hoverVehicle.cpp +++ b/Engine/source/T3D/vehicles/hoverVehicle.cpp @@ -73,9 +73,9 @@ DefineEnumType(hoverSoundsEnum); ImplementEnumType(hoverSoundsEnum, "enum types.\n" "@ingroup HoverVehicleData\n\n") - { HoverVehicleData::JetSound, "JetSound", "..." }, - { HoverVehicleData::EngineSound, "EngineSound", "..." }, - { HoverVehicleData::FloatSound, "FloatSound", "..." }, + { hoverSoundsEnum::JetSound, "JetSound", "..." }, + { hoverSoundsEnum::EngineSound, "EngineSound", "..." }, + { hoverSoundsEnum::FloatSound, "FloatSound", "..." }, EndImplementEnumType; namespace { @@ -162,7 +162,7 @@ HoverVehicleData::HoverVehicleData() jetEmitter[j] = 0; for (S32 i = 0; i < MaxSounds; i++) - INIT_ASSET_ARRAY(HoverSounds, i); + INIT_SOUNDASSET_ARRAY(HoverSounds, i); } HoverVehicleData::~HoverVehicleData() @@ -370,7 +370,7 @@ void HoverVehicleData::packData(BitStream* stream) for (S32 i = 0; i < MaxSounds; i++) { - PACKDATA_ASSET_ARRAY(HoverSounds, i); + PACKDATA_SOUNDASSET_ARRAY(HoverSounds, i); } for (S32 j = 0; j < MaxJetEmitters; j++) @@ -419,7 +419,7 @@ void HoverVehicleData::unpackData(BitStream* stream) for (S32 i = 0; i < MaxSounds; i++) { - UNPACKDATA_ASSET_ARRAY(HoverSounds, i); + UNPACKDATA_SOUNDASSET_ARRAY(HoverSounds, i); } for (S32 j = 0; j < MaxJetEmitters; j++) { diff --git a/Engine/source/T3D/vehicles/vehicle.cpp b/Engine/source/T3D/vehicles/vehicle.cpp index 327c3e1ab..2509ab291 100644 --- a/Engine/source/T3D/vehicles/vehicle.cpp +++ b/Engine/source/T3D/vehicles/vehicle.cpp @@ -80,28 +80,6 @@ static U32 sTriggerMask = ItemObjectType | IMPLEMENT_CONOBJECT(VehicleData); -typedef VehicleData::Body::Sounds bodySounds; -DefineEnumType(bodySounds); - -ImplementEnumType(bodySounds, "enum types.\n" - "@ingroup VehicleData\n\n") - { VehicleData::Body::SoftImpactSound, "SoftImpactSound", "..." }, - { VehicleData::Body::HardImpactSound, "HardImpactSound", "..." }, -EndImplementEnumType; - - -typedef VehicleData::Sounds vehSoundsEnum; -DefineEnumType(vehSoundsEnum); - -ImplementEnumType(vehSoundsEnum, "enum types.\n" - "@ingroup VehicleData\n\n") - { VehicleData::ExitWater, "ExitWater", "..." }, - { VehicleData::ImpactSoft, "ImpactSoft", "..." }, - { VehicleData::ImpactMedium, "ImpactMedium", "..." }, - { VehicleData::ImpactHard, "ImpactHard", "..." }, - { VehicleData::Wake, "Wake", "..." }, -EndImplementEnumType; - ConsoleDocClass( VehicleData, "@brief Base properties shared by all Vehicles (FlyingVehicle, HoverVehicle, " "WheeledVehicle).\n\n" @@ -152,70 +130,21 @@ VehicleData::VehicleData() shadowEnable = true; shadowSize = 256; shadowProjectionDistance = 14.0f; - - - body.friction = 0; - body.restitution = 1; - - minImpactSpeed = 25; - softImpactSpeed = 25; - hardImpactSpeed = 50; - minRollSpeed = 0; maxSteeringAngle = M_PI_F/4.0f; // 45 deg. - - cameraRoll = true; - cameraLag = 0; - cameraDecay = 0; - cameraOffset = 0; - - minDrag = 0; - maxDrag = 0; - integration = 1; - collisionTol = 0.1f; - contactTol = 0.1f; - massCenter.set(0,0,0); - massBox.set(0,0,0); - - drag = 0.7f; - density = 4; - jetForce = 500; jetEnergyDrain = 0.8f; minJetEnergy = 1; - steeringReturn = 0.0f; steeringReturnSpeedScale = 0.01f; powerSteering = false; - for (S32 i = 0; i < Body::MaxSounds; i++) - { - INIT_ASSET_ARRAY(VehicleBodySounds, i); - } - - dustEmitter = NULL; - dustID = 0; - triggerDustHeight = 3.0; - dustHeight = 1.0; - dMemset( damageEmitterList, 0, sizeof( damageEmitterList ) ); dMemset( damageEmitterOffset, 0, sizeof( damageEmitterOffset ) ); dMemset( damageEmitterIDList, 0, sizeof( damageEmitterIDList ) ); dMemset( damageLevelTolerance, 0, sizeof( damageLevelTolerance ) ); - dMemset( splashEmitterList, 0, sizeof( splashEmitterList ) ); - dMemset( splashEmitterIDList, 0, sizeof( splashEmitterIDList ) ); numDmgEmitterAreas = 0; - splashFreqMod = 300.0; - splashVelEpsilon = 0.50; - exitSplashSoundVel = 2.0; - softSplashSoundVel = 1.0; - medSplashSoundVel = 2.0; - hardSplashSoundVel = 3.0; - - for (S32 i = 0; i < Sounds::MaxSounds; i++) - INIT_ASSET_ARRAY(VehicleWaterSounds, i); - collDamageThresholdVel = 20; collDamageMultiplier = 0.05f; enablePhysicsRep = true; @@ -237,33 +166,6 @@ bool VehicleData::preload(bool server, String &errorStr) return false; } - // Resolve objects transmitted from server - if (!server) { - for (S32 i = 0; i < Body::MaxSounds; i++) - { - if (getVehicleBodySounds(i) != StringTable->EmptyString() ) - { - _setVehicleBodySounds(getVehicleBodySounds(i), i); - } - } - - for (S32 j = 0; j < Sounds::MaxSounds; j++) - { - if (getVehicleWaterSounds(j) != StringTable->EmptyString()) - { - _setVehicleWaterSounds(getVehicleWaterSounds(j), j); - } - } - } - - if( !dustEmitter && dustID != 0 ) - { - if( !Sim::findObject( dustID, dustEmitter ) ) - { - Con::errorf( ConsoleLogEntry::General, "VehicleData::preload Invalid packet, bad datablockId(dustEmitter): 0x%x", dustID ); - } - } - U32 i; for( i=0; iwrite(body.restitution); - stream->write(body.friction); - for (i = 0; i < Body::MaxSounds; i++) - { - PACKDATA_ASSET_ARRAY(VehicleBodySounds, i); - } - - stream->write(minImpactSpeed); - stream->write(softImpactSpeed); - stream->write(hardImpactSpeed); - stream->write(minRollSpeed); stream->write(maxSteeringAngle); - stream->write(maxDrag); - stream->write(minDrag); - stream->write(integration); - stream->write(collisionTol); - stream->write(contactTol); - mathWrite(*stream,massCenter); - mathWrite(*stream,massBox); - stream->write(jetForce); stream->write(jetEnergyDrain); stream->write(minJetEnergy); @@ -327,33 +199,10 @@ void VehicleData::packData(BitStream* stream) stream->write(steeringReturnSpeedScale); stream->writeFlag(powerSteering); - stream->writeFlag(cameraRoll); - stream->write(cameraLag); - stream->write(cameraDecay); - stream->write(cameraOffset); - - stream->write( triggerDustHeight ); - stream->write( dustHeight ); - stream->write( numDmgEmitterAreas ); - stream->write(exitSplashSoundVel); - stream->write(softSplashSoundVel); - stream->write(medSplashSoundVel); - stream->write(hardSplashSoundVel); stream->write(enablePhysicsRep); - // write the water sound profiles - for (i = 0; i < MaxSounds; i++) - { - PACKDATA_ASSET_ARRAY(VehicleWaterSounds, i); - } - - if (stream->writeFlag( dustEmitter )) - { - stream->writeRangedU32( dustEmitter->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast ); - } - for (i = 0; i < VC_NUM_DAMAGE_EMITTERS; i++) { if( stream->writeFlag( damageEmitterList[i] != NULL ) ) @@ -362,14 +211,6 @@ void VehicleData::packData(BitStream* stream) } } - for (i = 0; i < VC_NUM_SPLASH_EMITTERS; i++) - { - if( stream->writeFlag( splashEmitterList[i] != NULL ) ) - { - stream->writeRangedU32( splashEmitterList[i]->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast ); - } - } - for (S32 j = 0; j < VC_NUM_DAMAGE_EMITTER_AREAS; j++) { stream->write( damageEmitterOffset[j].x ); @@ -382,9 +223,6 @@ void VehicleData::packData(BitStream* stream) stream->write( damageLevelTolerance[k] ); } - stream->write(splashFreqMod); - stream->write(splashVelEpsilon); - stream->write(collDamageThresholdVel); stream->write(collDamageMultiplier); } @@ -393,28 +231,9 @@ void VehicleData::unpackData(BitStream* stream) { Parent::unpackData(stream); - stream->read(&body.restitution); - stream->read(&body.friction); S32 i; - for (i = 0; i < Body::MaxSounds; i++) - { - UNPACKDATA_ASSET_ARRAY(VehicleBodySounds, i); - } - - stream->read(&minImpactSpeed); - stream->read(&softImpactSpeed); - stream->read(&hardImpactSpeed); - stream->read(&minRollSpeed); stream->read(&maxSteeringAngle); - stream->read(&maxDrag); - stream->read(&minDrag); - stream->read(&integration); - stream->read(&collisionTol); - stream->read(&contactTol); - mathRead(*stream,&massCenter); - mathRead(*stream,&massBox); - stream->read(&jetForce); stream->read(&jetEnergyDrain); stream->read(&minJetEnergy); @@ -423,33 +242,10 @@ void VehicleData::unpackData(BitStream* stream) stream->read(&steeringReturnSpeedScale); powerSteering = stream->readFlag(); - cameraRoll = stream->readFlag(); - stream->read(&cameraLag); - stream->read(&cameraDecay); - stream->read(&cameraOffset); - - stream->read( &triggerDustHeight ); - stream->read( &dustHeight ); - stream->read( &numDmgEmitterAreas ); - stream->read(&exitSplashSoundVel); - stream->read(&softSplashSoundVel); - stream->read(&medSplashSoundVel); - stream->read(&hardSplashSoundVel); stream->read(&enablePhysicsRep); - // write the water sound profiles - for (i = 0; i < Sounds::MaxSounds; i++) - { - UNPACKDATA_ASSET_ARRAY(VehicleWaterSounds, i); - } - - if( stream->readFlag() ) - { - dustID = (S32) stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast); - } - for (i = 0; i < VC_NUM_DAMAGE_EMITTERS; i++) { if( stream->readFlag() ) @@ -458,14 +254,6 @@ void VehicleData::unpackData(BitStream* stream) } } - for (i = 0; i < VC_NUM_SPLASH_EMITTERS; i++) - { - if( stream->readFlag() ) - { - splashEmitterIDList[i] = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast ); - } - } - for( S32 j=0; jread( &damageEmitterOffset[j].x ); @@ -478,9 +266,6 @@ void VehicleData::unpackData(BitStream* stream) stream->read( &damageLevelTolerance[k] ); } - stream->read(&splashFreqMod); - stream->read(&splashVelEpsilon); - stream->read(&collDamageThresholdVel); stream->read(&collDamageMultiplier); } @@ -511,69 +296,9 @@ void VehicleData::initPersistFields() "Amount of effect the vehicle's speed has on its rate of steering return." ); addField( "powerSteering", TypeBool, Offset(powerSteering, VehicleData), "If true, steering does not auto-centre while the vehicle is being steered by its driver." ); - - addField( "massCenter", TypePoint3F, Offset(massCenter, VehicleData), - "Defines the vehicle's center of mass (offset from the origin of the model)." ); - addField( "massBox", TypePoint3F, Offset(massBox, VehicleData), - "@brief Define the box used to estimate the vehicle's moment of inertia.\n\n" - "Currently only used by WheeledVehicle; other vehicle types use a " - "unit sphere to compute inertia." ); - addField( "bodyRestitution", TypeF32, Offset(body.restitution, VehicleData), - "Collision 'bounciness'.\nNormally in the range 0 (not bouncy at all) to " - "1 (100% bounciness)." ); - addField( "bodyFriction", TypeF32, Offset(body.friction, VehicleData), - "Collision friction coefficient.\nHow well this object will slide against " - "objects it collides with." ); - - INITPERSISTFIELD_SOUNDASSET_ENUMED(VehicleBodySounds, bodySounds, Body::Sounds::MaxSounds, VehicleData, "Sounds for vehicle body impacts."); - - addField( "minImpactSpeed", TypeF32, Offset(minImpactSpeed, VehicleData), - "Minimum collision speed for the onImpact callback to be invoked." ); - addField( "softImpactSpeed", TypeF32, Offset(softImpactSpeed, VehicleData), - "Minimum collision speed for the softImpactSound to be played." ); - addField( "hardImpactSpeed", TypeF32, Offset(hardImpactSpeed, VehicleData), - "Minimum collision speed for the hardImpactSound to be played." ); - addField( "minRollSpeed", TypeF32, Offset(minRollSpeed, VehicleData), - "Unused" ); addField( "maxSteeringAngle", TypeF32, Offset(maxSteeringAngle, VehicleData), "Maximum yaw (horizontal) and pitch (vertical) steering angle in radians." ); - addField( "maxDrag", TypeF32, Offset(maxDrag, VehicleData), - "Maximum drag coefficient.\nCurrently unused." ); - addField( "minDrag", TypeF32, Offset(minDrag, VehicleData), - "Minimum drag coefficient.\nCurrently only used by FlyingVehicle." ); - addField( "integration", TypeS32, Offset(integration, VehicleData), - "Number of integration steps per tick.\nIncrease this to improve simulation " - "stability (also increases simulation processing time)." ); - addField( "collisionTol", TypeF32, Offset(collisionTol, VehicleData), - "Minimum distance between objects for them to be considered as colliding." ); - addField( "contactTol", TypeF32, Offset(contactTol, VehicleData), - "Maximum relative velocity between objects for collisions to be resolved " - "as contacts.\nVelocities greater than this are handled as collisions." ); - - addField( "cameraRoll", TypeBool, Offset(cameraRoll, VehicleData), - "If true, the camera will roll with the vehicle. If false, the camera will " - "always have the positive Z axis as up." ); - addField( "cameraLag", TypeF32, Offset(cameraLag, VehicleData), - "@brief How much the camera lags behind the vehicle depending on vehicle speed.\n\n" - "Increasing this value will make the camera fall further behind the vehicle " - "as it accelerates away.\n\n@see cameraDecay." ); - addField("cameraDecay", TypeF32, Offset(cameraDecay, VehicleData), - "How quickly the camera moves back towards the vehicle when stopped.\n\n" - "@see cameraLag." ); - addField("cameraOffset", TypeF32, Offset(cameraOffset, VehicleData), - "Vertical (Z axis) height of the camera above the vehicle." ); - - addField( "dustEmitter", TYPEID< ParticleEmitterData >(), Offset(dustEmitter, VehicleData), - "Dust particle emitter.\n\n@see triggerDustHeight\n\n@see dustHeight"); - addField( "triggerDustHeight", TypeF32, Offset(triggerDustHeight, VehicleData), - "@brief Maximum height above surface to emit dust particles.\n\n" - "If the vehicle is less than triggerDustHeight above a static surface " - "with a material that has 'showDust' set to true, the vehicle will emit " - "particles from the dustEmitter." ); - addField( "dustHeight", TypeF32, Offset(dustHeight, VehicleData), - "Height above ground at which to emit particles from the dustEmitter." ); - addField( "damageEmitter", TYPEID< ParticleEmitterData >(), Offset(damageEmitterList, VehicleData), VC_NUM_DAMAGE_EMITTERS, "@brief Array of particle emitters used to generate damage (dust, smoke etc) " "effects.\n\n" @@ -601,30 +326,6 @@ void VehicleData::initPersistFields() addField( "numDmgEmitterAreas", TypeF32, Offset(numDmgEmitterAreas, VehicleData), "Number of damageEmitterOffset values to use for each damageEmitter.\n\n" "@see damageEmitterOffset" ); - - addField( "splashEmitter", TYPEID< ParticleEmitterData >(), Offset(splashEmitterList, VehicleData), VC_NUM_SPLASH_EMITTERS, - "Array of particle emitters used to generate splash effects." ); - addField( "splashFreqMod", TypeF32, Offset(splashFreqMod, VehicleData), - "@brief Number of splash particles to generate based on vehicle speed.\n\n" - "This value is multiplied by the current speed to determine how many " - "particles to generate each frame." ); - addField( "splashVelEpsilon", TypeF32, Offset(splashVelEpsilon, VehicleData), - "Minimum speed when moving through water to generate splash particles." ); - - addField( "exitSplashSoundVelocity", TypeF32, Offset(exitSplashSoundVel, VehicleData), - "Minimum velocity when leaving the water for the exitingWater sound to play." ); - addField( "softSplashSoundVelocity", TypeF32, Offset(softSplashSoundVel, VehicleData), - "Minimum velocity when entering the water for the imapactWaterEasy sound " - "to play.\n\n@see impactWaterEasy" ); - addField( "mediumSplashSoundVelocity", TypeF32, Offset(medSplashSoundVel, VehicleData), - "Minimum velocity when entering the water for the imapactWaterMedium sound " - "to play.\n\n@see impactWaterMedium" ); - addField( "hardSplashSoundVelocity", TypeF32, Offset(hardSplashSoundVel, VehicleData), - "Minimum velocity when entering the water for the imapactWaterHard sound " - "to play.\n\n@see impactWaterHard" ); - - INITPERSISTFIELD_SOUNDASSET_ENUMED(WaterSounds, vehSoundsEnum, VehicleData::Sounds::MaxSounds, VehicleData, "Sounds for interacting with water."); - addField( "collDamageThresholdVel", TypeF32, Offset(collDamageThresholdVel, VehicleData), "Minimum collision velocity to cause damage to this vehicle.\nCurrently unused." ); addField( "collDamageMultiplier", TypeF32, Offset(collDamageMultiplier, VehicleData), @@ -891,9 +592,6 @@ bool Vehicle::onNewDataBlock(GameBaseData* dptr,bool reload) // Create the sound ahead of time. This reduces runtime // costs and makes the system easier to understand. SFX_DELETE( mWakeSound ); - - if ( mDataBlock->getVehicleWaterSounds(VehicleData::Wake) != NULL ) - mWakeSound = SFX->createSource( mDataBlock->getVehicleWaterSoundsProfile(VehicleData::Wake), &getTransform() ); } return true; @@ -1151,32 +849,32 @@ void Vehicle::updatePos(F32 dt) F32 collSpeed = (mRigid.linVelocity - origVelocity).len(); S32 impactSound = -1; if (collSpeed >= mDataBlock->hardImpactSpeed) - impactSound = VehicleData::Body::HardImpactSound; + impactSound = RigidShapeData::Body::HardImpactSound; else if (collSpeed >= mDataBlock->softImpactSpeed) - impactSound = VehicleData::Body::SoftImpactSound; + impactSound = RigidShapeData::Body::SoftImpactSound; - if (impactSound != -1 && mDataBlock->getVehicleBodySoundsProfile(impactSound) != NULL) - SFX->playOnce( mDataBlock->getVehicleBodySoundsProfile(impactSound), &getTransform() ); + if (impactSound != -1 && mDataBlock->getBodySoundsProfile(impactSound) != NULL) + SFX->playOnce( mDataBlock->getBodySoundsProfile(impactSound), &getTransform() ); } // Water volume sounds F32 vSpeed = getVelocity().len(); if (!inLiquid && mWaterCoverage >= 0.8f) { if (vSpeed >= mDataBlock->hardSplashSoundVel) - SFX->playOnce( mDataBlock->getVehicleWaterSoundsProfile(VehicleData::ImpactHard), &getTransform() ); + SFX->playOnce( mDataBlock->getWaterSoundsProfile(RigidShapeData::ImpactHard), &getTransform() ); else if (vSpeed >= mDataBlock->medSplashSoundVel) - SFX->playOnce( mDataBlock->getVehicleWaterSoundsProfile(VehicleData::ImpactMedium), &getTransform() ); + SFX->playOnce( mDataBlock->getWaterSoundsProfile(RigidShapeData::ImpactMedium), &getTransform() ); else if (vSpeed >= mDataBlock->softSplashSoundVel) - SFX->playOnce( mDataBlock->getVehicleWaterSoundsProfile(VehicleData::ImpactSoft), &getTransform() ); + SFX->playOnce( mDataBlock->getWaterSoundsProfile(RigidShapeData::ImpactSoft), &getTransform() ); inLiquid = true; } else if(inLiquid && mWaterCoverage < 0.8f) { if (vSpeed >= mDataBlock->exitSplashSoundVel) - SFX->playOnce( mDataBlock->getVehicleWaterSoundsProfile(VehicleData::ExitWater), &getTransform() ); + SFX->playOnce( mDataBlock->getWaterSoundsProfile(RigidShapeData::ExitWater), &getTransform() ); inLiquid = false; } } @@ -1376,6 +1074,10 @@ void Vehicle::unpackUpdate(NetConnection *con, BitStream *stream) setEnergyLevel(stream->readFloat(8) * mDataBlock->maxEnergy); } +void Vehicle::setControllingClient(GameConnection* client) +{ + ShapeBase::setControllingClient(client); +} //---------------------------------------------------------------------------- diff --git a/Engine/source/T3D/vehicles/vehicle.h b/Engine/source/T3D/vehicles/vehicle.h index a0ce918c7..ff6b29817 100644 --- a/Engine/source/T3D/vehicles/vehicle.h +++ b/Engine/source/T3D/vehicles/vehicle.h @@ -39,18 +39,6 @@ struct VehicleData : public RigidShapeData { typedef RigidShapeData Parent; - struct Body { - enum Sounds { - SoftImpactSound, - HardImpactSound, - MaxSounds, - }; - F32 restitution; - F32 friction; - } body; - - DECLARE_SOUNDASSET_ARRAY(VehicleData, VehicleBodySounds, Body::Sounds::MaxSounds) - enum VehicleConsts { VC_NUM_DUST_EMITTERS = 1, @@ -62,44 +50,11 @@ struct VehicleData : public RigidShapeData VC_BUBBLE_EMITTER = VC_NUM_DAMAGE_EMITTERS - VC_NUM_BUBBLE_EMITTERS, }; - enum Sounds { - ExitWater, - ImpactSoft, - ImpactMedium, - ImpactHard, - Wake, - MaxSounds - }; - - DECLARE_SOUNDASSET_ARRAY(VehicleData, VehicleWaterSounds, Sounds::MaxSounds) - - F32 exitSplashSoundVel; - F32 softSplashSoundVel; - F32 medSplashSoundVel; - F32 hardSplashSoundVel; - - F32 minImpactSpeed; - F32 softImpactSpeed; - F32 hardImpactSpeed; - F32 minRollSpeed; F32 maxSteeringAngle; F32 collDamageThresholdVel; F32 collDamageMultiplier; - bool cameraRoll; ///< Roll the 3rd party camera - F32 cameraLag; ///< Amount of camera lag (lag += car velocity * lag) - F32 cameraDecay; ///< Rate at which camera returns to target pos. - F32 cameraOffset; ///< Vertical offset - - F32 minDrag; - F32 maxDrag; - S32 integration; ///< # of physics steps per tick - F32 collisionTol; ///< Collision distance tolerance - F32 contactTol; ///< Contact velocity tolerance - Point3F massCenter; ///< Center of mass for rigid body - Point3F massBox; ///< Size of inertial box - F32 jetForce; F32 jetEnergyDrain; ///< Energy drain/tick F32 minJetEnergy; @@ -108,22 +63,12 @@ struct VehicleData : public RigidShapeData F32 steeringReturnSpeedScale; bool powerSteering; - ParticleEmitterData * dustEmitter; - S32 dustID; - F32 triggerDustHeight; ///< height vehicle has to be under to kick up dust - F32 dustHeight; ///< dust height above ground - ParticleEmitterData * damageEmitterList[ VC_NUM_DAMAGE_EMITTERS ]; Point3F damageEmitterOffset[ VC_NUM_DAMAGE_EMITTER_AREAS ]; S32 damageEmitterIDList[ VC_NUM_DAMAGE_EMITTERS ]; F32 damageLevelTolerance[ VC_NUM_DAMAGE_LEVELS ]; F32 numDmgEmitterAreas; - ParticleEmitterData* splashEmitterList[VC_NUM_SPLASH_EMITTERS]; - S32 splashEmitterIDList[VC_NUM_SPLASH_EMITTERS]; - F32 splashFreqMod; - F32 splashVelEpsilon; - bool enablePhysicsRep; // @@ -171,6 +116,7 @@ class Vehicle : public RigidShape void readPacketData (GameConnection * conn, BitStream *stream); U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream); void unpackUpdate(NetConnection *conn, BitStream *stream); + void setControllingClient(GameConnection* connection); void updateLiftoffDust( F32 dt ); void updateDamageSmoke( F32 dt ); diff --git a/Engine/source/T3D/vehicles/wheeledVehicle.cpp b/Engine/source/T3D/vehicles/wheeledVehicle.cpp index 02f848714..fc7ed88ae 100644 --- a/Engine/source/T3D/vehicles/wheeledVehicle.cpp +++ b/Engine/source/T3D/vehicles/wheeledVehicle.cpp @@ -289,15 +289,15 @@ ConsoleDocClass( WheeledVehicleData, "@ingroup Vehicles\n" ); -typedef WheeledVehicleData::Sounds wheelSoundsEnum; -DefineEnumType(wheelSoundsEnum); +typedef WheeledVehicleData::Sounds WheeledVehicleSoundsEnum; +DefineEnumType(WheeledVehicleSoundsEnum); -ImplementEnumType(wheelSoundsEnum, "enum types.\n" +ImplementEnumType(WheeledVehicleSoundsEnum, "enum types.\n" "@ingroup WheeledVehicleData\n\n") - {WheeledVehicleData::JetSound, "JetSound", "..." }, - {WheeledVehicleData::EngineSound, "EngineSound", "..." }, - {WheeledVehicleData::SquealSound, "SquealSound", "..." }, - {WheeledVehicleData::WheelImpactSound, "WheelImpactSound", "..." }, + { WheeledVehicleSoundsEnum::JetSound, "JetSound", "..." }, + { WheeledVehicleSoundsEnum::EngineSound, "EngineSound", "..." }, + { WheeledVehicleSoundsEnum::SquealSound, "SquealSound", "..." }, + { WheeledVehicleSoundsEnum::WheelImpactSound, "WheelImpactSound", "..." }, EndImplementEnumType; WheeledVehicleData::WheeledVehicleData() @@ -312,7 +312,7 @@ WheeledVehicleData::WheeledVehicleData() wheelCount = 0; dMemset(&wheel, 0, sizeof(wheel)); for (S32 i = 0; i < MaxSounds; i++) - INIT_ASSET_ARRAY(WheeledVehicleSounds, i); + INIT_SOUNDASSET_ARRAY(WheeledVehicleSounds, i); } @@ -448,7 +448,9 @@ bool WheeledVehicleData::mirrorWheel(Wheel* we) void WheeledVehicleData::initPersistFields() { - INITPERSISTFIELD_SOUNDASSET_ENUMED(WheeledVehicleSounds, wheelSoundsEnum, MaxSounds, WheeledVehicleData, "Sounds related to wheeled vehicle."); + addGroup("Sounds"); + INITPERSISTFIELD_SOUNDASSET_ENUMED(WheeledVehicleSounds, WheeledVehicleSoundsEnum, MaxSounds, WheeledVehicleData, "Sounds related to wheeled vehicle."); + endGroup("Sounds"); addField("tireEmitter",TYPEID< ParticleEmitterData >(), Offset(tireEmitter, WheeledVehicleData), "ParticleEmitterData datablock used to generate particles from each wheel " @@ -483,7 +485,7 @@ void WheeledVehicleData::packData(BitStream* stream) for (S32 i = 0; i < MaxSounds; i++) { - PACKDATA_ASSET_ARRAY(WheeledVehicleSounds, i); + PACKDATA_SOUNDASSET_ARRAY(WheeledVehicleSounds, i); } stream->write(maxWheelSpeed); @@ -502,7 +504,7 @@ void WheeledVehicleData::unpackData(BitStream* stream) for (S32 i = 0; i < MaxSounds; i++) { - UNPACKDATA_ASSET_ARRAY(WheeledVehicleSounds, i); + UNPACKDATA_SOUNDASSET_ARRAY(WheeledVehicleSounds, i); } stream->read(&maxWheelSpeed); diff --git a/Engine/source/sfx/sfxPlayList.cpp b/Engine/source/sfx/sfxPlayList.cpp index ea186c125..e0da33835 100644 --- a/Engine/source/sfx/sfxPlayList.cpp +++ b/Engine/source/sfx/sfxPlayList.cpp @@ -221,7 +221,7 @@ SFXPlayList::SFXPlayList() mNumSlotsToPlay( NUM_SLOTS ) { for (U32 i=0;iwrite( mSlots.mRepeatCount[ i ] ); FOR_EACH_SLOT sfxWrite( stream, mSlots.mState[ i ] ); - FOR_EACH_SLOT PACKDATA_ASSET_ARRAY(Track, i); + FOR_EACH_SLOT PACKDATA_SOUNDASSET_ARRAY(Track, i); } //----------------------------------------------------------------------------- @@ -468,7 +468,7 @@ void SFXPlayList::unpackData( BitStream* stream ) FOR_EACH_SLOT if(stream->readFlag()){ stream->read( &mSlots.mRepeatCount[ i ] );} FOR_EACH_SLOT sfxRead( stream, &mSlots.mState[ i ] ); - FOR_EACH_SLOT UNPACKDATA_ASSET_ARRAY(Track, i); + FOR_EACH_SLOT UNPACKDATA_SOUNDASSET_ARRAY(Track, i); #undef FOR_EACH_SLOT } diff --git a/Templates/BaseGame/game/core/utility/scripts/gameObjectManagement.tscript b/Templates/BaseGame/game/core/utility/scripts/gameObjectManagement.tscript index 44ec46555..275c088f9 100644 --- a/Templates/BaseGame/game/core/utility/scripts/gameObjectManagement.tscript +++ b/Templates/BaseGame/game/core/utility/scripts/gameObjectManagement.tscript @@ -78,6 +78,12 @@ function spawnGameObject(%name, %addToScene) return 0; } +function GameBaseData::onNewDataBlock(%this, %obj) +{ + %this.onRemove(%obj); + %this.onAdd(%obj); +} + function saveGameObject(%name, %tamlPath, %scriptPath) { %gameObjectAsset = findGameObject(%name);