summaryrefslogtreecommitdiffstats
path: root/game/code/sound/avatar/carsoundparameters.h
blob: d5c4ef17390397e59416b11ab3b545a6dcadab32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
//=============================================================================
// Copyright (C) 2002 Radical Entertainment Ltd.  All rights reserved.
//
// File:        carsoundparameters.h
//
// Description: Declaration for RadScript-created class for tunable car sound
//              parameters
//
// History:     30/06/2002 + Created -- Darren
//
//=============================================================================

#ifndef CARSOUNDPARAMETERS_H
#define CARSOUNDPARAMETERS_H

//========================================
// Nested Includes
//========================================

#include <radobject.hpp>
#include <radlinkedclass.hpp>

#include <sound/avatar/icarsoundparameters.h>

//========================================
// Forward References
//========================================

//=============================================================================
//
// Synopsis:    carSoundParameters
//
//=============================================================================

class carSoundParameters: public ICarSoundParameters,
                          public radLinkedClass< carSoundParameters >,
                          public radRefCount
{
    public:
        IMPLEMENT_REFCOUNTED( "carSoundParameters" );

        static const int REVERSE_GEAR = -1;
        
        carSoundParameters();
        virtual ~carSoundParameters();

        void SetWatcherName( const char* name );

        void SetClipRPM( float rpm ) { m_clipRPM = rpm; }
        float GetClipRPM() { return( m_clipRPM ); }

        void SetEngineClipName( const char* clipName );
        const char* GetEngineClipName() { return( m_engineClipName ); }

        void SetEngineIdleClipName( const char* clipName );
        const char* GetEngineIdleClipName() { return( m_idleClipName ); }

        void SetDamagedEngineClipName( const char* clipName );
        const char* GetDamagedEngineClipName() { return( m_damagedClipName ); }

        void SetHornClipName( const char* clipName );
        const char* GetHornClipName() { return( m_hornClipName ); }

        void SetCarDoorOpenClipName( const char* clipName );
        const char* GetCarDoorOpenClipName() { return( m_carOpenClipName ); }

        void SetCarDoorCloseClipName( const char* clipName );
        const char* GetCarDoorCloseClipName() { return( m_carCloseClipName ); }

        void SetOverlayClipName( const char* clipName );
        const char* GetOverlayClipName() { return( m_overlayClipName ); }

        void SetRoadSkidClipName( const char* clipName );
        const char* GetRoadSkidClipName() { return( m_roadSkidClipName ); }

        void SetDirtSkidClipName( const char* clipName );
        const char* GetDirtSkidClipName() { return( m_dirtSkidClipName ); }

        void SetBackupClipName( const char* clipName );
        const char* GetBackupClipName() { return( m_backupClipName ); }

        void SetShiftPoint( unsigned int gear, float percent );
        float GetShiftPoint( int gear );

        void SetDownshiftDamperSize( float percent );
        float GetDownshiftDamperSize() { return( m_downshiftDamper ); }

        void SetGearPitchRange( unsigned int gear, float min, float max );

        void SetNumberOfGears( unsigned int gear );

        float GetMsecsPerOctaveCap() { return( m_msecsPerOctave ); }

        //
        // Attack/delay/decay
        //
        void SetAttackTimeMsecs( float msecs );
        float GetAttackTimeMsecs() { return( m_attackTime ); }

        void SetDelayTimeMsecs( unsigned int msecs );
        unsigned int GetDelayTimeMsecs() { return( m_delayTime ); }

        void SetDecayTimeMsecs( float msecs );
        float GetDecayTimeMsecs() { return( m_decayTime ); }

        void SetDecayFinishTrim( float trim );
        float GetDecayFinishTrim() { return( m_decayFinishTrim ); }

        //
        // Reverse
        //
        void SetReversePitchCapKmh( float speed );
        float GetReversePitchCapKmh() { return( m_maxReverseKmh ); }

        void SetReversePitchRange( float min, float max );
        void GetReversePitchRange( float& min, float& max ) 
            { min = m_minReversePitch; max = m_maxReversePitch; }

        //
        // Gear shifts
        //
        void SetGearShiftPitchDrop( unsigned int gear, float drop );
        float GetGearShiftPitchDrop( unsigned int gear );

        //
        // Damage
        //
        void SetDamageStartPcnt( float damagePercent );
        float GetDamageStartPcnt() { return( m_damageStartPcnt ); }

        void SetDamageMaxVolPcnt( float percent );
        float GetDamageVolumeRange() { return( m_damageVolumeRange ); }

        void SetDamageStartTrim( float trim );
        float GetDamageStartTrim() { return( m_damageStartTrim ); }
        void SetDamageMaxTrim( float trim );
        float GetDamageMaxTrim() { return( m_damageMaxTrim ); }

        //
        // Idle
        //
        void SetIdleEnginePitch( float pitch );
        float GetIdleEnginePitch() { return( m_idleEnginePitch ); }

        //
        // In-air sound characteristics
        //
        void SetInAirThrottlePitch( float pitch );
        float GetInAirThrottlePitch();

        void SetInAirIdlePitch( float pitch );
        float GetInAirIdlePitch();

        void SetInAirThrottleResponseTimeMsecs( unsigned int msecs );
        unsigned int GetInAirThrottleResponseTimeMsecs() { return( m_inAirResponseMsecs ); }

        //
        // Burnout sound characteristics
        //
        void SetBurnoutMinPitch( float pitch );
        float GetBurnoutMinPitch() { return( m_burnoutMinPitch ); }

        void SetBurnoutMaxPitch( float pitch );
        float GetBurnoutMaxPitch() { return( m_burnoutMaxPitch ); }

        //
        // Powerslide sound characteristics
        //
        void SetPowerslideMinPitch( float pitch );
        float GetPowerslideMinPitch();

        void SetPowerslideMaxPitch( float pitch );
        float GetPowerslideMaxPitch();

        //
        // Given a vehicle's current speed and max speed, figure out the
        // gear it's in
        //
        int CalculateCurrentGear( float currentSpeed, float previousSpeed, 
                                  float topSpeed, int previousGear );

        //
        // Given a vehicle's current gear, speed, and max speed, figure out the
        // pitch for the engine clip
        //
        float CalculateEnginePitch( int gear, float currentSpeed, float topSpeed );

        float GetRevLimit();

    private:
        //Prevent wasteful constructor creation.
        carSoundParameters( const carSoundParameters& original );
        carSoundParameters& operator=( const carSoundParameters& rhs );

        static const unsigned int MAX_GEARS = 6;

        float m_clipRPM;

        float m_minPitch[MAX_GEARS];
        float m_maxPitch[MAX_GEARS];

        char* m_engineClipName;
        char* m_idleClipName;
        char* m_damagedClipName;
        char* m_hornClipName;
        char* m_carOpenClipName;
        char* m_carCloseClipName;
        char* m_overlayClipName;
        char* m_roadSkidClipName;
        char* m_dirtSkidClipName;
        char* m_backupClipName;

        //
        // Percentages of top speed at which we shift gears.
        // E.g. m_shiftPoints[0] == 0.01f means that we shift from idle
        // to first at 1% of top speed.  m_shiftPoints[MAX_GEARS+1] is
        // 1.0f to simplify math.
        //

        // Used for shifting
        float m_shiftPoints[MAX_GEARS+1];
        float m_downshiftDamper;

        //
        // Attack/delay/decay
        //
        float m_attackTime;
        unsigned int m_delayTime;
        float m_decayTime;

        float m_decayFinishTrim;

        //
        // Reverse
        //
        float m_maxReverseKmh;
        float m_minReversePitch;
        float m_maxReversePitch;

        //
        // Gear shifts
        //
        float m_gearShiftPitchDrop[MAX_GEARS];
        unsigned int m_gearShiftTimeMsecs[MAX_GEARS];

        //
        // Damage
        //
        float m_damageStartPcnt;
        float m_damageVolumeRange;

        float m_damageStartTrim;
        float m_damageMaxTrim;

        //
        // Idle
        //
        float m_idleEnginePitch;

        //
        // Airborne
        //
        float m_inAirThrottlePitch;
        float m_inAirIdlePitch;
        unsigned int m_inAirResponseMsecs;

        //
        // Burnout
        //
        float m_burnoutMinPitch;
        float m_burnoutMaxPitch;

        //
        // Powerslide
        //
        float m_powerslideMinPitch;
        float m_powerslideMaxPitch;

        //
        // Makes transitions a little less abrupt
        //
        float m_msecsPerOctave;
};

//=============================================================================
// Factory Functions
//=============================================================================

//
// Create a CarSoundParameters object
//
void CarSoundParameterObjCreate
(
    ICarSoundParameters** ppSoundResource,
    radMemoryAllocator allocator
);




#endif // CARSOUNDPARAMETERS_H