author | truebrain |
Thu, 12 Jun 2008 21:18:09 +0000 | |
branch | noai |
changeset 10944 | 588393239ac6 |
parent 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
2 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10294
diff
changeset
|
3 |
/** @file newgrf_sound.cpp Handling NewGRF provided sounds. */ |
9505 | 4 |
|
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
6 |
#include "openttd.h" |
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
4975
diff
changeset
|
7 |
#include "oldpool.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9723
diff
changeset
|
8 |
#include "engine_func.h" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10294
diff
changeset
|
9 |
#include "engine_base.h" |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
10 |
#include "newgrf_callbacks.h" |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
11 |
#include "newgrf_engine.h" |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
12 |
#include "newgrf_sound.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
13 |
#include "vehicle_base.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
14 |
#include "sound_func.h" |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
15 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
16 |
static uint _sound_count = 0; |
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
4975
diff
changeset
|
17 |
STATIC_OLD_POOL(SoundInternal, FileEntry, 3, 1000, NULL, NULL) |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
18 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
19 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
20 |
/* Allocate a new FileEntry */ |
6573 | 21 |
FileEntry *AllocateFileEntry() |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
22 |
{ |
4975
3a19f44fb5d4
(svn r6978) Use the pool macros for the SoundInternal pool
tron
parents:
4701
diff
changeset
|
23 |
if (_sound_count == GetSoundInternalPoolSize()) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9505
diff
changeset
|
24 |
if (!_SoundInternal_pool.AddBlockToPool()) return NULL; |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
25 |
} |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
26 |
|
4975
3a19f44fb5d4
(svn r6978) Use the pool macros for the SoundInternal pool
tron
parents:
4701
diff
changeset
|
27 |
return GetSoundInternal(_sound_count++); |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
28 |
} |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
29 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
30 |
|
6573 | 31 |
void InitializeSoundPool() |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
32 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9505
diff
changeset
|
33 |
_SoundInternal_pool.CleanPool(); |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
34 |
_sound_count = 0; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
35 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
36 |
/* Copy original sound data to the pool */ |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
37 |
SndCopyToPool(); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
38 |
} |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
39 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
40 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
41 |
FileEntry *GetSound(uint index) |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
42 |
{ |
6450
1c2016673250
(svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents:
5838
diff
changeset
|
43 |
if (index >= GetNumSounds()) return NULL; |
4975
3a19f44fb5d4
(svn r6978) Use the pool macros for the SoundInternal pool
tron
parents:
4701
diff
changeset
|
44 |
return GetSoundInternal(index); |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
45 |
} |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
46 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
47 |
|
6573 | 48 |
uint GetNumSounds() |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
49 |
{ |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
50 |
return _sound_count; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
51 |
} |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
52 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
53 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
54 |
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event) |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
55 |
{ |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
56 |
const GRFFile *file = GetEngineGRF(v->engine_type); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
57 |
uint16 callback; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
58 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
59 |
/* If the engine has no GRF ID associated it can't ever play any new sounds */ |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
60 |
if (file == NULL) return false; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
61 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
62 |
/* Check that the vehicle type uses the sound effect callback */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9704
diff
changeset
|
63 |
if (!HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_SOUND_EFFECT)) return false; |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
64 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
65 |
callback = GetVehicleCallback(CBID_VEHICLE_SOUND_EFFECT, event, 0, v->engine_type, v); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
66 |
if (callback == CALLBACK_FAILED) return false; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
67 |
if (callback >= GetNumOriginalSounds()) callback += file->sound_offset - GetNumOriginalSounds(); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
68 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
69 |
if (callback < GetNumSounds()) SndPlayVehicleFx((SoundFx)callback, v); |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
70 |
return true; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
diff
changeset
|
71 |
} |
9476 | 72 |
|
10294 | 73 |
bool PlayTileSound(const GRFFile *file, uint16 sound_id, TileIndex tile) |
9476 | 74 |
{ |
10294 | 75 |
if (sound_id >= GetNumOriginalSounds()) sound_id += file->sound_offset - GetNumOriginalSounds(); |
76 |
||
77 |
if (sound_id < GetNumSounds()) { |
|
9476 | 78 |
SndPlayTileFx((SoundFx)sound_id, tile); |
79 |
return true; |
|
80 |
} |
|
81 |
return false; |
|
82 |
} |