/
api_player.h
208 lines (178 loc) · 7.05 KB
/
api_player.h
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
/** @file api_player.h Public API for players.
* @ingroup playsim
*
* @authors Copyright © 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef DOOMSDAY_API_PLAYER_H
#define DOOMSDAY_API_PLAYER_H
#include "apis.h"
#include <de/smoother.h>
/**
* @defgroup player Player
* @ingroup playsim
*/
/// Built-in control identifiers. @ingroup player
enum {
CTL_WALK = 1, ///< Forward/backwards.
CTL_SIDESTEP = 2, ///< Left/right sideways movement.
CTL_ZFLY = 3, ///< Up/down movement.
CTL_TURN = 4, ///< Turning horizontally.
CTL_LOOK = 5, ///< Turning up and down.
CTL_MODIFIER_1 = 6,
CTL_MODIFIER_2 = 7,
CTL_MODIFIER_3 = 8,
CTL_MODIFIER_4 = 9,
CTL_FIRST_GAME_CONTROL = 1000
};
/// Control type.
typedef enum controltype_e {
CTLT_NUMERIC, ///< Control with a numeric value determined by current device state.
CTLT_NUMERIC_TRIGGERED, ///< Numeric, but accepts triggered states as well.
CTLT_IMPULSE ///< Always accepts triggered states.
} controltype_t;
/**
* @defgroup playerFlags Player Flags
* @ingroup player apiFlags
* @{
*/
#define DDPF_FIXANGLES 0x0001 ///< Server: send angle/pitch to client.
#define DDPF_FIXORIGIN 0x0004 ///< Server: send coords to client.
#define DDPF_DEAD 0x0008 ///< Cl & Sv: player is dead.
#define DDPF_CAMERA 0x0010 ///< Player is a cameraman.
#define DDPF_LOCAL 0x0020 ///< Player is local (e.g. player zero).
#define DDPF_FIXMOM 0x0040 ///< Server: send momentum to client.
#define DDPF_NOCLIP 0x0080 ///< Client: don't clip movement.
#define DDPF_CHASECAM 0x0100 ///< Chase camera mode (third person view).
#define DDPF_INTERYAW 0x0200 ///< Interpolate view yaw angles (used with locking).
#define DDPF_INTERPITCH 0x0400 ///< Interpolate view pitch angles (used with locking).
#define DDPF_VIEW_FILTER 0x0800 ///< Cl & Sv: Draw the current view filter.
#define DDPF_REMOTE_VIEW_FILTER 0x1000 ///< Client: Draw the view filter (has been set remotely).
#define DDPF_USE_VIEW_FILTER (DDPF_VIEW_FILTER | DDPF_REMOTE_VIEW_FILTER)
#define DDPF_UNDEFINED_ORIGIN 0x2000 ///< Origin of the player is undefined (view not drawn).
#define DDPF_UNDEFINED_WEAPON 0x4000 ///< Weapon of the player is undefined (not sent yet).
///@}
/// Maximum length of a player name.
#define PLAYERNAMELEN 81
/// Normally one for the weapon and one for the muzzle flash.
#define DDMAXPSPRITES 2
/// Psprite states. @ingroup player
enum {
DDPSP_BOBBING,
DDPSP_FIRE,
DDPSP_DOWN,
DDPSP_UP
};
/**
* @defgroup pspriteFlags PSprite Flags
* @ingroup player apiFlags
*/
///@{
#define DDPSPF_FULLBRIGHT 0x1
///@}
/// Player sprite. @ingroup player
typedef struct {
state_t* statePtr;
int tics;
float alpha;
float pos[2];
byte flags; /// @ref pspriteFlags
int state;
float offset[2];
} ddpsprite_t;
#define LOOKDIRMAX 110.0f // 85 degrees
/// Player lookdir (view pitch) conversion to degrees. @ingroup player
#define LOOKDIR2DEG(x) ((x) * 85.0f/LOOKDIRMAX)
/// Player lookdir (view pitch) conversion to radians. @ingroup player
#define LOOKDIR2RAD(x) (LOOKDIR2DEG(x)/180*DD_PI)
struct mobj_s;
struct polyobj_s;
typedef struct fixcounters_s {
int angles;
int origin;
int mom;
} fixcounters_t;
typedef struct ddplayer_s {
float forwardMove; // Copied from player brain (read only).
float sideMove; // Copied from player brain (read only).
struct mobj_s* mo; // Pointer to a (game specific) mobj.
angle_t appliedBodyYaw; // Body yaw currently applied
float lookDir; // For mouse look.
int fixedColorMap; // Can be set to REDCOLORMAP, etc.
int extraLight; // So gun flashes light up areas.
int inGame; // Is this player in game?
int inVoid; // True if player is in the void
// (not entirely accurate so it shouldn't
// be used for anything critical).
int flags;
float filterColor[4]; // RGBA filter for the camera.
fixcounters_t fixCounter;
fixcounters_t fixAcked;
angle_t lastAngle; // For calculating turndeltas.
ddpsprite_t pSprites[DDMAXPSPRITES]; // Player sprites.
void* extraData; // Pointer to any game-specific data.
} ddplayer_t;
DENG_API_TYPEDEF(Player)
{
de_api_t api;
/**
* @return The name of player @a player.
*/
const char* (*GetPlayerName)(int player);
/**
* @return Client identifier for player @a player.
*/
ident_t (*GetPlayerID)(int player);
/**
* Provides access to the player's movement smoother.
*/
Smoother* (*GetSmoother)(int player);
/**
* Gets the data of a player.
*
* @param number Console/player number.
*
* @return Player data.
*/
ddplayer_t* (*GetPlayer)(int number);
void (*NewControl)(int id, controltype_t type, const char* name, const char* bindContext);
/**
* Determines if a control has been bound to anything.
*
* @param playerNum Console/player number.
* @param control Control id.
*/
int (*IsControlBound)(int playerNum, int control);
void (*GetControlState)(int playerNum, int control, float* pos, float* relativeOffset);
int (*GetImpulseControlState)(int playerNum, int control);
void (*Impulse)(int playerNum, int control);
}
DENG_API_T(Player);
#ifndef DENG_NO_API_MACROS_PLAYER
#define Net_GetPlayerName _api_Player.GetPlayerName
#define Net_GetPlayerID _api_Player.GetPlayerID
#define Net_PlayerSmoother _api_Player.GetSmoother
#define DD_GetPlayer _api_Player.GetPlayer
#define P_NewPlayerControl _api_Player.NewControl
#define P_GetControlState _api_Player.GetControlState
#define P_IsControlBound _api_Player.IsControlBound
#define P_GetImpulseControlState _api_Player.GetImpulseControlState
#define P_Impulse _api_Player.Impulse
#endif
#ifdef __DOOMSDAY__
DENG_USING_API(Player);
#endif
#endif // DOOMSDAY_API_PLAYER_H