1 /** @file player.h Base class for player state. 2 * 3 * @authors Copyright (c) 2015-2017 Jaakko Keränen <jaakko.keranen@iki.fi> 4 * 5 * @par License 6 * GPL: http://www.gnu.org/licenses/gpl.html 7 * 8 * <small>This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by the 10 * Free Software Foundation; either version 2 of the License, or (at your 11 * option) any later version. This program is distributed in the hope that it 12 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 14 * Public License for more details. You should have received a copy of the GNU 15 * General Public License along with this program; if not, see: 16 * http://www.gnu.org/licenses</small> 17 */ 18 19 #ifndef LIBDOOMSDAY_PLAYER_H 20 #define LIBDOOMSDAY_PLAYER_H 21 22 #include "libdoomsday.h" 23 #include "network/pinger.h" 24 #include <de/types.h> 25 #include <de/smoother.h> 26 27 /// Maximum length of a player name. 28 #define PLAYERNAMELEN 81 29 30 /// Normally one for the weapon and one for the muzzle flash. 31 #define DDMAXPSPRITES 2 32 33 /// Psprite states. @ingroup player 34 enum { 35 DDPSP_BOBBING, 36 DDPSP_FIRE, 37 DDPSP_DOWN, 38 DDPSP_UP 39 }; 40 41 /** 42 * @defgroup pspriteFlags PSprite Flags 43 * @ingroup player apiFlags 44 */ 45 ///@{ 46 #define DDPSPF_FULLBRIGHT 0x1 47 ///@} 48 49 /// Player sprite. @ingroup player 50 typedef struct { 51 struct state_s *statePtr; 52 int tics; 53 float alpha; 54 float pos[2]; 55 byte flags; /// @ref pspriteFlags 56 int state; 57 float offset[2]; 58 } ddpsprite_t; 59 60 #define LOOKDIRMAX 110.0f // 85 degrees 61 62 /// Player lookdir (view pitch) conversion to degrees. @ingroup player 63 #define LOOKDIR2DEG(x) ((x) * 85.0f/LOOKDIRMAX) 64 65 /// Player lookdir (view pitch) conversion to radians. @ingroup player 66 #define LOOKDIR2RAD(x) (LOOKDIR2DEG(x)/180*DD_PI) 67 68 LIBDOOMSDAY_EXTERN_C LIBDOOMSDAY_PUBLIC short P_LookDirToShort(float lookDir); 69 LIBDOOMSDAY_EXTERN_C LIBDOOMSDAY_PUBLIC float P_ShortToLookDir(short s); 70 71 struct mobj_s; 72 73 typedef struct fixcounters_s { 74 int angles; 75 int origin; 76 int mom; 77 } fixcounters_t; 78 79 typedef struct ddplayer_s { 80 float forwardMove; // Copied from player brain (read only). 81 float sideMove; // Copied from player brain (read only). 82 struct mobj_s *mo; // Pointer to a (game specific) mobj. 83 angle_t appliedBodyYaw; // Body yaw currently applied 84 float lookDir; // For mouse look. 85 int fixedColorMap; // Can be set to REDCOLORMAP, etc. 86 int extraLight; // So gun flashes light up areas. 87 int inGame; // Is this player in game? 88 int flags; 89 float filterColor[4]; // RGBA filter for the camera. 90 fixcounters_t fixCounter; 91 fixcounters_t fixAcked; 92 angle_t lastAngle; // For calculating turndeltas. 93 ddpsprite_t pSprites[DDMAXPSPRITES]; // Player sprites. 94 void* extraData; // Pointer to any game-specific data. 95 } ddplayer_t; 96 97 #ifdef __cplusplus 98 99 #include <de/IObject> 100 #include <de/Record> 101 102 class World; 103 104 /** 105 * Base class for player state: common functionality shared by both the server 106 * and the client. 107 * 108 * @todo Revise: this entire class is public as part of libdoomday, and therefore 109 * can be accessed by plugins, too. Previously only ddplayer_t has been made 110 * public. Some members could be moved into an internal, engine-only private class, 111 * if necessary. -jk 112 */ 113 class LIBDOOMSDAY_PUBLIC Player : public de::IObject 114 { 115 public: 116 // ID number. Each client has a unique ID number. 117 ident_t id; 118 119 // The name of the player. 120 char name[PLAYERNAMELEN]; 121 122 byte extraLightCounter; ///< Num tics to go till extraLight is disabled. 123 int extraLight; 124 int targetExtraLight; 125 126 // View console. Which player this client is viewing? 127 int viewConsole; 128 129 public: 130 Player(); 131 132 virtual ~Player(); 133 134 void initBindings(); 135 136 virtual void setWorld(World *world); 137 138 ddplayer_t &publicData(); 139 ddplayer_t const &publicData() const; 140 141 /** 142 * Determines if the player is in the game and has a mobj. 143 */ 144 bool isInGame() const; 145 146 /** 147 * Returns the player's namespace. 148 */ 149 de::Record const &info() const; 150 151 /** 152 * Returns the player's namespace. 153 */ 154 de::Record &info(); 155 156 Smoother *smoother(); 157 158 Pinger &pinger(); 159 Pinger const &pinger() const; 160 161 /** 162 * Called once on every tick. 163 * 164 * @param elapsed Amount of time elapsed since the previous call. 165 */ 166 virtual void tick(timespan_t elapsed); 167 168 DENG2_CAST_METHODS() 169 170 // Implements IObject. 171 de::Record &objectNamespace(); 172 const de::Record &objectNamespace() const; 173 174 private: 175 DENG2_PRIVATE(d) 176 }; 177 178 #endif // __cplusplus 179 180 #endif // LIBDOOMSDAY_PLAYER_H 181