Changeset - r11932:f2bc1b879057
[Not reviewed]
master
0 10 0
rubidium - 15 years ago 2009-05-17 17:17:48
rubidium@openttd.org
(svn r16340) -Codechange: introduce SoundID (uint16) and use that instead of SoundFX, which was used as a byte and uint16 at different places, when the uint16 sound ID is meant.
10 files changed with 27 insertions and 30 deletions:
0 comments (0 inline, 0 general)
src/engine_type.h
Show inline comments
 
@@ -59,13 +59,13 @@ struct ShipVehicleInfo {
 
	byte image_index;
 
	byte cost_factor;
 
	uint16 max_speed;
 
	CargoID cargo_type;
 
	uint16 capacity;
 
	byte running_cost;
 
	SoundFxByte sfx;
 
	SoundID sfx;
 
	bool refittable;
 
};
 

	
 
/* AircraftVehicleInfo subtypes, bitmask type.
 
 * If bit 0 is 0 then it is a helicopter, otherwise it is a plane
 
 * in which case bit 1 tells us whether it's a big(fast) plane or not */
 
@@ -77,25 +77,25 @@ enum {
 

	
 
struct AircraftVehicleInfo {
 
	byte image_index;
 
	byte cost_factor;
 
	byte running_cost;
 
	byte subtype;
 
	SoundFxByte sfx;
 
	SoundID sfx;
 
	byte acceleration;
 
	uint16 max_speed;
 
	byte mail_capacity;
 
	uint16 passenger_capacity;
 
};
 

	
 
struct RoadVehicleInfo {
 
	byte image_index;
 
	byte cost_factor;
 
	byte running_cost;
 
	byte running_cost_class;
 
	SoundFxByte sfx;
 
	SoundID sfx;
 
	uint16 max_speed;        ///< Maximum speed in mph/3.2 units
 
	byte capacity;
 
	CargoID cargo_type;
 
	uint8 weight;            ///< Weight in 1/4t units
 
	uint8 power;             ///< Power in 10hp units
 
	uint8 tractive_effort;   ///< Coefficient of tractive effort
src/newgrf.cpp
Show inline comments
 
@@ -808,13 +808,13 @@ static ChangeInfoResult RoadVehicleChang
 

	
 
			case 0x11: // Cost factor
 
				rvi->cost_factor = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x12: // SFX
 
				rvi->sfx = (SoundFx)grf_load_byte(&buf);
 
				rvi->sfx = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x13: // Power in 10hp
 
				rvi->power = grf_load_byte(&buf);
 
				break;
 

	
 
@@ -934,13 +934,13 @@ static ChangeInfoResult ShipVehicleChang
 

	
 
			case 0x0F: // Running cost factor
 
				svi->running_cost = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x10: // SFX
 
				svi->sfx = (SoundFx)grf_load_byte(&buf);
 
				svi->sfx = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x11: // Cargos available for refitting
 
				ei->refit_mask = grf_load_dword(&buf);
 
				break;
 

	
 
@@ -1050,13 +1050,13 @@ static ChangeInfoResult AircraftVehicleC
 

	
 
			case 0x11: // Mail capacity
 
				avi->mail_capacity = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x12: // SFX
 
				avi->sfx = (SoundFx)grf_load_byte(&buf);
 
				avi->sfx = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x13: // Cargos available for refitting
 
				ei->refit_mask = grf_load_dword(&buf);
 
				break;
 

	
 
@@ -2017,13 +2017,13 @@ static ChangeInfoResult SoundEffectChang
 
	if (_cur_grffile->sound_offset == 0) {
 
		grfmsg(1, "SoundEffectChangeInfo: No effects defined, skipping");
 
		return CIR_INVALID_ID;
 
	}
 

	
 
	for (int i = 0; i < numinfo; i++) {
 
		uint sound = sid + i + _cur_grffile->sound_offset - ORIGINAL_SAMPLE_COUNT;
 
		SoundID sound = sid + i + _cur_grffile->sound_offset - ORIGINAL_SAMPLE_COUNT;
 

	
 
		if (sound >= GetNumSounds()) {
 
			grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
 
			return CIR_INVALID_ID;
 
		}
 

	
 
@@ -2034,13 +2034,13 @@ static ChangeInfoResult SoundEffectChang
 

	
 
			case 0x09: // Priority
 
				GetSound(sound)->priority = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x0A: { // Override old sound
 
				uint orig_sound = grf_load_byte(&buf);
 
				SoundID orig_sound = grf_load_byte(&buf);
 

	
 
				if (orig_sound >= ORIGINAL_SAMPLE_COUNT) {
 
					grfmsg(1, "SoundEffectChangeInfo: Original sound %d not defined (max %d)", orig_sound, ORIGINAL_SAMPLE_COUNT);
 
				} else {
 
					FileEntry *newfe = GetSound(sound);
 
					FileEntry *oldfe = GetSound(orig_sound);
src/newgrf_sound.cpp
Show inline comments
 
@@ -31,13 +31,13 @@ void InitializeSoundPool()
 

	
 
	/* Copy original sound data to the pool */
 
	SndCopyToPool();
 
}
 

	
 

	
 
FileEntry *GetSound(uint index)
 
FileEntry *GetSound(SoundID index)
 
{
 
	if (index >= GetNumSounds()) return NULL;
 
	return GetSoundInternal(index);
 
}
 

	
 

	
src/newgrf_sound.h
Show inline comments
 
@@ -20,12 +20,12 @@ enum VehicleSoundEvent {
 
	VSE_LOAD_UNLOAD  = 9,
 
};
 

	
 

	
 
FileEntry *AllocateFileEntry();
 
void InitializeSoundPool();
 
FileEntry *GetSound(uint index);
 
FileEntry *GetSound(SoundID sound_id);
 
uint GetNumSounds();
 
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event);
 
bool PlayTileSound(const struct GRFFile *file, uint16 sound_id, TileIndex tile);
 
bool PlayTileSound(const struct GRFFile *file, SoundID sound_id, TileIndex tile);
 

	
 
#endif /* NEWGRF_SOUND_H */
src/news_type.h
Show inline comments
 
@@ -2,12 +2,13 @@
 

	
 
/** @file news_type.h Types related to news. */
 

	
 
#ifndef NEWS_TYPE_H
 
#define NEWS_TYPE_H
 

	
 
#include "core/enum_type.hpp"
 
#include "date_type.h"
 
#include "strings_type.h"
 
#include "sound_type.h"
 

	
 
/**
 
 * Type of news.
src/roadveh_cmd.cpp
Show inline comments
 
@@ -687,13 +687,13 @@ TileIndex RoadVehicle::GetOrderStationLo
 
	}
 
}
 

	
 
static void StartRoadVehSound(const Vehicle *v)
 
{
 
	if (!PlayVehicleSound(v, VSE_START)) {
 
		SoundFx s = RoadVehInfo(v->engine_type)->sfx;
 
		SoundID s = RoadVehInfo(v->engine_type)->sfx;
 
		if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0)
 
			s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN;
 
		SndPlayVehicleFx(s, v);
 
	}
 
}
 

	
src/sound.cpp
Show inline comments
 
@@ -120,17 +120,17 @@ bool SoundInitialize(const char *filenam
 
{
 
	OpenBankFile(filename);
 
	return true;
 
}
 

	
 
/* Low level sound player */
 
static void StartSound(uint sound, int panning, uint volume)
 
static void StartSound(SoundID sound_id, int panning, uint volume)
 
{
 
	if (volume == 0) return;
 

	
 
	const FileEntry *fe = GetSound(sound);
 
	const FileEntry *fe = GetSound(sound_id);
 
	if (fe == NULL) return;
 

	
 
	MixerChannel *mc = MxAllocateChannel();
 
	if (mc == NULL) return;
 

	
 
	if (!SetBankSource(mc, fe)) return;
 
@@ -192,13 +192,13 @@ void SndCopyToPool()
 
 * @param sound Sound effect to play
 
 * @param left   Left edge of virtual coordinates where the sound is produced
 
 * @param right  Right edge of virtual coordinates where the sound is produced
 
 * @param top    Top edge of virtual coordinates where the sound is produced
 
 * @param bottom Bottom edge of virtual coordinates where the sound is produced
 
 */
 
static void SndPlayScreenCoordFx(SoundFx sound, int left, int right, int top, int bottom)
 
static void SndPlayScreenCoordFx(SoundID sound, int left, int right, int top, int bottom)
 
{
 
	if (msf.effect_vol == 0) return;
 

	
 
	const Window *w;
 
	FOR_ALL_WINDOWS_FROM_BACK(w) {
 
		const ViewPort *vp = w->viewport;
 
@@ -217,30 +217,30 @@ static void SndPlayScreenCoordFx(SoundFx
 
			);
 
			return;
 
		}
 
	}
 
}
 

	
 
void SndPlayTileFx(SoundFx sound, TileIndex tile)
 
void SndPlayTileFx(SoundID sound, TileIndex tile)
 
{
 
	/* emits sound from center of the tile */
 
	int x = min(MapMaxX() - 1, TileX(tile)) * TILE_SIZE + TILE_SIZE / 2;
 
	int y = min(MapMaxY() - 1, TileY(tile)) * TILE_SIZE - TILE_SIZE / 2;
 
	uint z = (y < 0 ? 0 : GetSlopeZ(x, y));
 
	Point pt = RemapCoords(x, y, z);
 
	y += 2 * TILE_SIZE;
 
	Point pt2 = RemapCoords(x, y, GetSlopeZ(x, y));
 
	SndPlayScreenCoordFx(sound, pt.x, pt2.x, pt.y, pt2.y);
 
}
 

	
 
void SndPlayVehicleFx(SoundFx sound, const Vehicle *v)
 
void SndPlayVehicleFx(SoundID sound, const Vehicle *v)
 
{
 
	SndPlayScreenCoordFx(sound,
 
		v->coord.left, v->coord.right,
 
		v->coord.top, v->coord.bottom
 
	);
 
}
 

	
 
void SndPlayFx(SoundFx sound)
 
void SndPlayFx(SoundID sound)
 
{
 
	StartSound(sound, 0, msf.effect_vol);
 
}
src/sound_func.h
Show inline comments
 
@@ -10,12 +10,12 @@
 
#include "tile_type.h"
 

	
 
extern MusicFileSettings msf;
 

	
 
bool SoundInitialize(const char *filename);
 

	
 
void SndPlayTileFx(SoundFx sound, TileIndex tile);
 
void SndPlayVehicleFx(SoundFx sound, const Vehicle *v);
 
void SndPlayFx(SoundFx sound);
 
void SndPlayTileFx(SoundID sound, TileIndex tile);
 
void SndPlayVehicleFx(SoundID sound, const Vehicle *v);
 
void SndPlayFx(SoundID sound);
 
void SndCopyToPool();
 

	
 
#endif /* SOUND_FUNC_H */
src/sound_type.h
Show inline comments
 
@@ -2,14 +2,12 @@
 

	
 
/** @file sound_type.h Types related to sounds. */
 

	
 
#ifndef SOUND_TYPE_H
 
#define SOUND_TYPE_H
 

	
 
#include "core/enum_type.hpp"
 

	
 
struct MusicFileSettings {
 
	byte playlist;
 
	byte music_vol;
 
	byte effect_vol;
 
	byte custom_1[33];
 
	byte custom_2[33];
 
@@ -103,14 +101,12 @@ enum SoundFx {
 
	SND_46_PLANE_ENGINE_SPUTTERING,
 
	SND_47_MAGLEV_2,
 
	SND_48_DISTANT_BIRD,                    // 72 == 0x48
 
	SND_END
 
};
 

	
 
/** Define basic enum properties */
 
template <> struct EnumPropsT<SoundFx> : MakeEnumPropsT<SoundFx, byte, SND_BEGIN, SND_END, SND_END> {};
 
typedef TinyEnumT<SoundFx> SoundFxByte;
 

	
 
/** The number of sounds in the original sample.cat */
 
static const uint ORIGINAL_SAMPLE_COUNT = 73;
 

	
 
typedef uint16 SoundID;
 

	
 
#endif /* SOUND_TYPE_H */
src/table/engines.h
Show inline comments
 
@@ -515,13 +515,13 @@ static const RailVehicleInfo _orig_rail_
 
 * @param d cargo_type
 
 * @param e cargo_amount
 
 * @param f running_cost
 
 * @param g sound effect
 
 * @param h refittable
 
 */
 
#define SVI(a, b, c, d, e, f, g, h) { a, b, c, d, e, f, {g}, h }
 
#define SVI(a, b, c, d, e, f, g, h) { a, b, c, d, e, f, g, h }
 
static const ShipVehicleInfo _orig_ship_vehicle_info[] = {
 
	/*   image_index  cargo_type     cargo_amount                 refittable
 
	 *   |    base_cost |              |    running_cost          |
 
	 *   |    |    max_speed           |    |  sfx                |
 
	 *   |    |    |    |              |    |  |                  | */
 
	SVI( 1, 160,  48, CT_OIL,        220, 140, SND_06_SHIP_HORN,  0 ), //  0
 
@@ -547,13 +547,13 @@ static const ShipVehicleInfo _orig_ship_
 
 * @param e sound effect
 
 * @param f acceleration
 
 * @param g max_speed
 
 * @param h mail_capacity
 
 * @param i passenger_capacity
 
 */
 
#define AVI(a, b, c, d, e, f, g, h, i) { a, b, c, d, {e}, f, (g * 129) / 10, h, i }
 
#define AVI(a, b, c, d, e, f, g, h, i) { a, b, c, d, e, f, (g * 129) / 10, h, i }
 
#define H AIR_HELI
 
#define P AIR_CTOL
 
#define J AIR_CTOL | AIR_FAST
 
static const AircraftVehicleInfo _orig_aircraft_vehicle_info[] = {
 
	/*    image_index         sfx                         acceleration
 
	 *    |   base_cost       |                           |   max_speed
 
@@ -616,13 +616,13 @@ static const AircraftVehicleInfo _orig_a
 
 * @param e max_speed
 
 * @param f capacity
 
 * @param g cargo_type
 
 * @param h weight (1/4ton)
 
 * @param i power (10hp)
 
 */
 
#define ROV(a, b, c, d, e, f, g, h, i) { a, b, c, RC_R, {d}, e, f, g, h, i, 76, 0 }
 
#define ROV(a, b, c, d, e, f, g, h, i) { a, b, c, RC_R, d, e, f, g, h, i, 76, 0 }
 
static const RoadVehicleInfo _orig_road_vehicle_info[] = {
 
	/*    image_index       sfx                                 max_speed
 
	 *    |    base_cost    |                                   |   capacity
 
	 *    |    |    running_cost                                |   |  cargo_type
 
	 *    |    |    |       |                                   |   |  | */
 
	ROV(  0, 120,  91, SND_19_BUS_START_PULL_AWAY,            112, 31, CT_PASSENGERS   , 42,  9), //  0
0 comments (0 inline, 0 general)