SpaceCadetPinball/SpaceCadetPinball/TPinballComponent.h

176 lines
4.2 KiB
C
Raw Normal View History

#pragma once
2020-12-19 15:49:31 +01:00
2021-01-30 12:19:25 +01:00
struct zmap_header_type;
struct gdrv_bitmap8;
2020-12-25 14:46:06 +01:00
struct render_sprite_type_struct;
struct component_control;
2022-05-30 10:23:47 +02:00
struct vector2;
class TPinballTable;
2020-12-25 14:46:06 +01:00
enum class MessageCode
2020-12-25 14:46:06 +01:00
{
// Private codes <1000, different meaning for each component
TFlipperExtend = 1,
TFlipperRetract = 2,
TLightTurnOff = 0,
TLightTurnOn = 1,
TLightGetLightOnFlag = 2,
TLightGetFlasherOnFlag = 3,
TLightFlasherStart = 4,
TLightApplyMultDelay = 5,
TLightApplyDelay = 6,
TLightFlasherStartTimed = 7,
TLightTurnOffTimed = 8,
TLightTurnOnTimed = 9,
TLightSetOnStateBmpIndex = 11,
TLightIncOnStateBmpIndex = 12,
TLightDecOnStateBmpIndex = 13,
TLightResetTimed = 14,
TLightFlasherStartTimedThenStayOn = 15,
TLightFlasherStartTimedThenStayOff = 16,
TLightToggleValue = 17,
TLightResetAndToggleValue = 18,
TLightResetAndTurnOn = 19,
TLightResetAndTurnOff = 20,
TLightToggle = 21,
TLightResetAndToggle = 22,
TLightSetMessageField = 23,
TLightFtTmpOverrideOn = -24,
TLightFtTmpOverrideOff = -25,
TLightFtResetOverride = -26,
TLightGroupStepBackward = 24,
TLightGroupStepForward = 25,
TLightGroupAnimationBackward = 26,
TLightGroupAnimationForward = 27,
TLightGroupRandomAnimation1 = 28,
TLightGroupRandomAnimation2 = 29,
TLightGroupRandomAnimationSaturation = 30,
TLightGroupRandomAnimationDesaturation = 31,
TLightGroupOffsetAnimationForward = 32,
TLightGroupOffsetAnimationBackward = 33,
TLightGroupReset = 34,
TLightGroupTurnOnAtIndex = 35,
TLightGroupTurnOffAtIndex = 36,
TLightGroupGetOnCount = 37,
TLightGroupGetLightCount = 38,
TLightGroupGetMessage2 = 39,
TLightGroupGetAnimationFlag = 40,
TLightGroupResetAndTurnOn = 41,
TLightGroupResetAndTurnOff = 42,
TLightGroupRestartNotifyTimer = 43,
TLightGroupFlashWhenOn = 44,
TLightGroupToggleSplitIndex = 45,
TLightGroupStartFlasher = 46,
TBlockerDisable = 51,
TBlockerEnable = 52,
TBlockerRestartTimeout = 59,
TBumperSetBmpIndex = 11,
TBumperIncBmpIndex = 12,
TBumperDecBmpIndex = 13,
TComponentGroupResetNotifyTimer = 48,
TGateDisable = 53,
TGateEnable = 54,
TKickoutRestartTimer = 55,
TPopupTargetDisable = 49,
TPopupTargetEnable = 50,
TSinkUnknown7 = 7,
TSinkResetTimer = 56,
TSoloTargetDisable = 49,
TSoloTargetEnable = 50,
TTimerResetTimer = 59,
// Public codes 1000+, apply to all components
LeftFlipperInputPressed = 1000,
LeftFlipperInputReleased = 1001,
RightFlipperInputPressed = 1002,
RightFlipperInputReleased = 1003,
PlungerInputPressed = 1004,
PlungerInputReleased = 1005,
Pause = 1008,
Resume = 1009,
LooseFocus = 1010,
SetTiltLock = 1011,
ClearTiltLock = 1012,
StartGamePlayer1 = 1013,
NewGame = 1014,
PlungerFeedBall = 1015,
PlungerStartFeedTimer = 1016,
PlungerLaunchBall = 1017,
PlungerRelaunchBall = 1018,
PlayerChanged = 1020,
SwitchToNextPlayer = 1021,
GameOver = 1022,
Reset = 1024,
2020-12-25 14:46:06 +01:00
};
// Temporary hacks for int -> enum class migration.
template <typename T, typename X = typename std::underlying_type<T>::type>
constexpr typename std::enable_if<std::is_enum<T>::value, X>::type operator~(T value)
{
return static_cast<X>(value);
}
#if defined(__GNUC__) || defined(__clang__)
#define DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED __declspec(deprecated)
#else
#define DEPRECATED
#endif
class TPinballComponent
2020-11-04 14:22:52 +01:00
{
public:
TPinballComponent(TPinballTable* table, int groupIndex, bool loadVisuals);
2020-11-04 14:22:52 +01:00
virtual ~TPinballComponent();
virtual int Message(int code, float value);
virtual int Message2(MessageCode code, float value)
{
return Message(~code, value);
}
virtual void port_draw();
int get_scoring(unsigned int index) const;
Implement stereo sound. (#138) * Implement stereo sound. Original Space Cadet has mono sound. To achieve stereo, the following steps were accomplished: - Add a game option to turn on/off stereo sound. Default is on. - TPinballComponent objects were extended with a method called get_coordinates() that returns a single 2D point, approximating the on-screen position of the object, re-mapped between 0 and 1 vertically and horizontally, {0, 0} being at the top-left. - For static objects like bumpers and lights, the coordinate refers to the geometric center of the corresponding graphic sprite, and is precalculated at initialization. - For ball objects, the coordinate refers to the geometric center of the ball, calculated during play when requested. - Extend all calls to sound-playing methods so that they include a TPinballComponent* argument that refers to the sound source, e.g. where the sound comes from. For instance, when a flipper is activated, its method call to emit a sound now includes a reference to the flipper object; when a ball goes under a SkillShotGate, its method call to emit a sound now includes a reference to the corresponding light; and so on. For some cases, like light rollovers, the sound source is taken from the ball that triggered the light rollover. For other cases, like holes, flags and targets, the sound source is taken from the object itself. For some special cases like ramp activation, sound source is taken from the nearest light position that makes sense. For all game-progress sounds, like mission completion sounds or ball drain sounds, the sound source is undefined (set to nullptr), and the Sound::PlaySound() method takes care of positioning them at a default location, where speakers on a pinball machine normally are. - Make the Sound::PlaySound() method accept a new argument, a TPinballComponent reference, as described above. If the stereo option is turned on, the Sound::PlaySound() method calls the get_coordinates() method of the TPinballComponent reference to get the sound position. This project uses SDL_mixer and there is a function called Mix_SetPosition() that allows placing a sound in the stereo field, by giving it a distance and an angle. We arbitrarily place the player's ears at the bottom of the table; we set the ears' height to half a table's length. Intensity of the stereo effect is directly related to this value; the farther the player's ears from the table, the narrowest the stereo picture gets, and vice-versa. From there we have all we need to calculate distance and angle; we do just that and position all the sounds. * Copy-paste typo fix.
2022-05-30 09:35:29 +02:00
virtual vector2 get_coordinates();
char UnusedBaseFlag;
char ActiveFlag;
2020-11-04 14:22:52 +01:00
int MessageField;
char* GroupName;
2020-12-19 15:49:31 +01:00
component_control* Control;
int GroupIndex;
2020-11-08 16:37:59 +01:00
render_sprite_type_struct* RenderSprite;
TPinballTable* PinballTable;
std::vector<gdrv_bitmap8*>* ListBitmap;
std::vector<zmap_header_type*>* ListZMap;
2022-05-30 10:23:47 +02:00
private:
float VisualPosNormX;
float VisualPosNormY;
};
class TPinballComponent2 : public TPinballComponent
{
public:
TPinballComponent2(TPinballTable* table, int group_index, bool load_visuals)
: TPinballComponent(table, group_index, load_visuals)
{
}
DEPRECATED int Message(int code, float value) override
{
return Message2(static_cast<MessageCode>(code), value);
}
};