Formatted VehicleSoundEntity source files

This commit is contained in:
smallmodel 2024-01-25 21:54:44 +01:00
parent adaeaea596
commit dd768ec9ef
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 106 additions and 143 deletions

View file

@ -26,159 +26,128 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "vehicle.h"
Event EV_VehicleSoundEntity_PostSpawn
(
"vehiclesoundentity_post",
EV_DEFAULT,
NULL,
NULL,
"PostSpawn of a Vehicle Sound Entity"
);
(
"vehiclesoundentity_post",
EV_DEFAULT,
NULL,
NULL,
"PostSpawn of a Vehicle Sound Entity"
);
Event EV_VehicleSoundEntity_UpdateTraces
(
"vehiclesoudnentity_updatetraces",
EV_DEFAULT,
NULL,
NULL,
"Updates the traces of a Vehicle Sound Entity"
);
(
"vehiclesoudnentity_updatetraces",
EV_DEFAULT,
NULL,
NULL,
"Updates the traces of a Vehicle Sound Entity"
);
CLASS_DECLARATION( Entity, VehicleSoundEntity, NULL )
{
{ &EV_VehicleSoundEntity_PostSpawn, &VehicleSoundEntity::EventPostSpawn },
{ &EV_VehicleSoundEntity_UpdateTraces, &VehicleSoundEntity::EventUpdateTraces },
{ NULL, NULL }
CLASS_DECLARATION(Entity, VehicleSoundEntity, NULL) {
{&EV_VehicleSoundEntity_PostSpawn, &VehicleSoundEntity::EventPostSpawn },
{&EV_VehicleSoundEntity_UpdateTraces, &VehicleSoundEntity::EventUpdateTraces},
{NULL, NULL }
};
VehicleSoundEntity::VehicleSoundEntity()
{
if( LoadingSavegame )
{
return;
}
if (LoadingSavegame) {
return;
}
gi.Error( ERR_DROP, "VehicleSoundEntity Created with no parameters!\n" );
gi.Error(ERR_DROP, "VehicleSoundEntity Created with no parameters!\n");
}
VehicleSoundEntity::VehicleSoundEntity( Vehicle *owner )
VehicleSoundEntity::VehicleSoundEntity(Vehicle *owner)
{
m_pVehicle = owner;
m_bDoSoundStuff = false;
m_iTraceSurfaceFlags = 0;
m_pVehicle = owner;
m_bDoSoundStuff = false;
m_iTraceSurfaceFlags = 0;
PostEvent( EV_VehicleSoundEntity_PostSpawn, EV_POSTSPAWN );
PostEvent(EV_VehicleSoundEntity_PostSpawn, EV_POSTSPAWN);
}
void VehicleSoundEntity::Start
(
void
)
void VehicleSoundEntity::Start(void)
{
m_bDoSoundStuff = true;
m_bDoSoundStuff = true;
}
void VehicleSoundEntity::Stop
(
void
)
void VehicleSoundEntity::Stop(void)
{
m_bDoSoundStuff = false;
m_bDoSoundStuff = false;
}
void VehicleSoundEntity::Think
(
void
)
void VehicleSoundEntity::Think(void)
{
DoSoundStuff();
DoSoundStuff();
}
void VehicleSoundEntity::EventPostSpawn
(
Event *ev
)
void VehicleSoundEntity::EventPostSpawn(Event *ev)
{
setModel( "models/vehicles/vehiclesoundentity.tik" );
setModel("models/vehicles/vehiclesoundentity.tik");
PostEvent( EV_VehicleSoundEntity_UpdateTraces, 1.0f );
flags |= FL_THINK;
PostEvent(EV_VehicleSoundEntity_UpdateTraces, 1.0f);
flags |= FL_THINK;
}
void VehicleSoundEntity::EventUpdateTraces
(
Event *ev
)
void VehicleSoundEntity::EventUpdateTraces(Event *ev)
{
if( m_bDoSoundStuff )
{
m_pVehicle->SetSlotsNonSolid();
if (m_bDoSoundStuff) {
m_pVehicle->SetSlotsNonSolid();
trace_t trace = G_Trace(
origin,
vec3_origin,
vec3_origin,
Vector( origin[ 0 ], origin[ 1 ], origin[ 2 ] - 256.0f ),
m_pVehicle->edict,
MASK_SOUND,
qfalse,
"VehicleSoundEntity::DoSoundStuff"
);
trace_t trace = G_Trace(
origin,
vec3_origin,
vec3_origin,
Vector(origin[0], origin[1], origin[2] - 256.0f),
m_pVehicle->edict,
MASK_SOUND,
qfalse,
"VehicleSoundEntity::DoSoundStuff"
);
if( trace.fraction >= 1.0f )
m_iTraceSurfaceFlags = 0;
else
m_iTraceSurfaceFlags = trace.surfaceFlags;
if (trace.fraction >= 1.0f) {
m_iTraceSurfaceFlags = 0;
} else {
m_iTraceSurfaceFlags = trace.surfaceFlags;
}
m_pVehicle->SetSlotsSolid();
}
m_pVehicle->SetSlotsSolid();
}
PostEvent( EV_VehicleSoundEntity_UpdateTraces, 1.0f );
PostEvent(EV_VehicleSoundEntity_UpdateTraces, 1.0f);
}
void VehicleSoundEntity::DoSoundStuff
(
void
)
void VehicleSoundEntity::DoSoundStuff(void)
{
float pitch;
float pitch;
if( !m_bDoSoundStuff )
{
StopLoopSound();
return;
}
if (!m_bDoSoundStuff) {
StopLoopSound();
return;
}
pitch = ( velocity.length() - m_pVehicle->m_fSoundMinSpeed ) / ( m_pVehicle->m_fSoundMaxSpeed - m_pVehicle->m_fSoundMinSpeed );
if( pitch > 1.0f ) {
pitch = 1.0f;
} else if( pitch < 0.0f ) {
pitch = 0.0f;
}
pitch = (velocity.length() - m_pVehicle->m_fSoundMinSpeed)
/ (m_pVehicle->m_fSoundMaxSpeed - m_pVehicle->m_fSoundMinSpeed);
if (pitch > 1.0f) {
pitch = 1.0f;
} else if (pitch < 0.0f) {
pitch = 0.0f;
}
pitch *= m_pVehicle->m_fSoundMinPitch + ( m_pVehicle->m_fSoundMaxPitch - m_pVehicle->m_fSoundMinPitch );
pitch *= m_pVehicle->m_fSoundMinPitch + (m_pVehicle->m_fSoundMaxPitch - m_pVehicle->m_fSoundMinPitch);
if( m_iTraceSurfaceFlags & SURF_DIRT )
{
LoopSound( m_pVehicle->m_sSoundSet + "treat_snd_dirt", -1.0f, -1.0f, -1.0f, pitch );
}
else if( m_iTraceSurfaceFlags & SURF_GRASS )
{
LoopSound( m_pVehicle->m_sSoundSet + "treat_snd_grass", -1.0f, -1.0f, -1.0f, pitch );
}
else if( m_iTraceSurfaceFlags & SURF_WOOD )
{
LoopSound( m_pVehicle->m_sSoundSet + "treat_snd_wood", -1.0f, -1.0f, -1.0f, pitch );
}
else if( m_iTraceSurfaceFlags & SURF_MUD )
{
LoopSound( m_pVehicle->m_sSoundSet + "treat_snd_mud", -1.0f, -1.0f, -1.0f, pitch );
}
else if( m_iTraceSurfaceFlags & ( SURF_GRAVEL | SURF_ROCK ) )
{
LoopSound( m_pVehicle->m_sSoundSet + "treat_snd_stone", -1.0f, -1.0f, -1.0f, pitch );
}
else
{
StopLoopSound();
}
if (m_iTraceSurfaceFlags & SURF_DIRT) {
LoopSound(m_pVehicle->m_sSoundSet + "treat_snd_dirt", -1.0f, -1.0f, -1.0f, pitch);
} else if (m_iTraceSurfaceFlags & SURF_GRASS) {
LoopSound(m_pVehicle->m_sSoundSet + "treat_snd_grass", -1.0f, -1.0f, -1.0f, pitch);
} else if (m_iTraceSurfaceFlags & SURF_WOOD) {
LoopSound(m_pVehicle->m_sSoundSet + "treat_snd_wood", -1.0f, -1.0f, -1.0f, pitch);
} else if (m_iTraceSurfaceFlags & SURF_MUD) {
LoopSound(m_pVehicle->m_sSoundSet + "treat_snd_mud", -1.0f, -1.0f, -1.0f, pitch);
} else if (m_iTraceSurfaceFlags & (SURF_GRAVEL | SURF_ROCK)) {
LoopSound(m_pVehicle->m_sSoundSet + "treat_snd_stone", -1.0f, -1.0f, -1.0f, pitch);
} else {
StopLoopSound();
}
}

View file

@ -21,47 +21,41 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// VehicleSoundEntity.h : Sound helper for vehicles
#ifndef __VEHICLESOUNDENTITY_H__
#define __VEHICLESOUNDENTITY_H__
#pragma once
#include "entity.h"
class Vehicle;
class VehicleSoundEntity : public Entity {
class VehicleSoundEntity : public Entity
{
private:
SafePtr<Vehicle> m_pVehicle;
bool m_bDoSoundStuff;
int m_iTraceSurfaceFlags;
SafePtr<Vehicle> m_pVehicle;
bool m_bDoSoundStuff;
int m_iTraceSurfaceFlags;
public:
CLASS_PROTOTYPE( VehicleSoundEntity );
CLASS_PROTOTYPE(VehicleSoundEntity);
VehicleSoundEntity();
VehicleSoundEntity( Vehicle *owner );
VehicleSoundEntity();
VehicleSoundEntity(Vehicle *owner);
void Start( void );
void Stop( void );
void Think( void ) override;
void Archive( Archiver& arc ) override;
void Start(void);
void Stop(void);
void Think(void) override;
void Archive(Archiver& arc) override;
private:
void EventPostSpawn( Event *ev );
void EventUpdateTraces( Event *ev );
void DoSoundStuff( void );
void EventPostSpawn(Event *ev);
void EventUpdateTraces(Event *ev);
void DoSoundStuff(void);
};
inline
void VehicleSoundEntity::Archive
(
Archiver& arc
)
inline void VehicleSoundEntity::Archive(Archiver& arc)
{
Entity::Archive( arc );
Entity::Archive(arc);
arc.ArchiveSafePointer( &m_pVehicle );
arc.ArchiveBool( &m_bDoSoundStuff );
arc.ArchiveInteger( &m_iTraceSurfaceFlags );
arc.ArchiveSafePointer(&m_pVehicle);
arc.ArchiveBool(&m_bDoSoundStuff);
arc.ArchiveInteger(&m_iTraceSurfaceFlags);
}
#endif // __VEHICLECOLLISIONENTITY_H__