Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / snowballs2 / client / src / entities.h
blob797fac870fbed962baa8c018b835a6a6636dbd89
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef ENTITIES_H
21 #define ENTITIES_H
24 // Includes
27 #include <string>
28 #include <map>
29 #include <queue>
31 #include <nel/misc/vector.h>
32 #include <nel/misc/time_nl.h>
34 #include <nel/3d/animation_time.h>
35 #include <nel/3d/u_instance.h>
36 #include <nel/3d/u_skeleton.h>
38 #include "physics.h"
39 #include "animation.h"
42 // External definitions
45 namespace NLSOUND
47 class USource;
50 namespace NLPACS
52 class UMovePrimitive;
55 namespace NL3D
57 class UVisualCollisionEntity;
58 class UPlayList;
61 namespace SBCLIENT {
64 // External classes
67 // An entity that will move through the landscape.
68 // The possible entities are the Self (the player's avatar), the Other and the Snowball
69 class CEntity
71 public:
73 // Create a default entity
74 CEntity () :
75 Id(0xffffffff), Name("<Unknown>"), Angle(0.0f), AuxiliaryAngle(0.0f), InterpolatedAuxiliaryAngle(0.0f),
76 AutoMove(false), Instance(NULL), Skeleton(NULL),
77 Particule(NULL), Source(NULL), IsWalking(false), WasWalking(false), IsAiming(false), WasAiming(false),
78 /*CurrentAnim(NoAnim), */NextEmptySlot(0), PlayList(NULL), BotState(0)
79 { }
82 // The id of the entity
83 uint32 Id;
85 // The name of the entity
86 std::string Name;
88 // Contain the target position for this entity
89 NLMISC::CVector ServerPosition;
91 // Contain the current position of the entity
92 NLMISC::CVector Position;
94 // The immediate speed of the entity
95 NLMISC::CVector ImmediateSpeed;
97 // The maximum speed of the entity
98 float Speed,
99 // The angle of the entity
100 Angle,
101 // Various angle controls for the interpolation
102 AuxiliaryAngle, InterpolatedAuxiliaryAngle;
104 // The trajectory (only for snowballs, defined in physics.h)
105 CTrajectory Trajectory;
108 // The state enum of the entity
109 enum TState { Appear, Normal, Disappear };
111 // The state of this entity
112 TState State;
113 // The date of the beginning of this state
114 NLMISC::TLocalTime StateStartTime;
116 // The type enum of the entity
117 enum TType { Self, Other, Snowball };
119 // The type of this entity
120 TType Type;
122 // Is it an auto-moving entity
123 bool AutoMove;
125 // The PACS move primitive
126 NLPACS::UMovePrimitive *MovePrimitive;
127 // The collision entity (for ground snapping)
128 NL3D::UVisualCollisionEntity *VisualCollisionEntity;
129 // The mesh instance associated to this entity
130 NL3D::UInstance Instance;
131 // The skeleton binded to the instance
132 NL3D::USkeleton Skeleton;
133 // The particle system (for appear and disappear effects)
134 NL3D::UInstance Particule;
136 // The sound source associated to the entity
137 NLSOUND::USource *Source;
139 void setState (TState state);
141 bool IsWalking;
142 bool WasWalking;
143 bool IsAiming;
144 bool WasAiming;
146 // Playlist linked to this entity
147 // EAnim CurrentAnim;
148 uint NextEmptySlot;
149 NL3D::UPlayList *PlayList;
150 std::queue<EAnim> AnimQueue;
151 NL3D::CAnimationTime StartAnimationTime;
153 uint BotState;
154 NLMISC::TLocalTime BotStateStart;
158 // Enums
161 // The collision bits used by pacs (dynamic collisions)
162 enum
164 SelfCollisionBit = 1,
165 OtherCollisionBit = 2,
166 SnowballCollisionBit = 4,
167 StaticCollisionBit = 8
171 // External variables
174 // The entity representing the player avatar
175 extern CEntity *Self;
177 // The speed of the player
178 extern float PlayerSpeed;
179 // The speed of the snowball
180 extern float SnowballSpeed;
182 // The entities storage
183 extern std::map<uint32, CEntity> Entities;
184 typedef std::map<uint32, CEntity>::iterator EIT;
186 extern uint32 NextEID;
189 // External functions
192 EIT findEntity (uint32 eid, bool needAssert = true);
194 void addEntity (uint32 eid, std::string name, CEntity::TType type, const NLMISC::CVector &startPosition, const NLMISC::CVector &serverPosition);
195 void removeEntity (uint32 eid);
197 // when we turn online, we need to clear all offline entities
198 void removeAllEntitiesExceptUs ();
199 void deleteAllEntities();
201 void initEntities();
202 void updateEntities();
203 void releaseEntities();
205 // Reset the pacs position of an entity (in case pacs went wrong)
206 void resetEntityPosition(uint32 eid);
207 // Process the event when an entity shoots a snowball
208 void shotSnowball(uint32 sid, uint32 eid, const NLMISC::CVector &start, const NLMISC::CVector &target, float speed, float deflagRadius);
210 void renderEntitiesNames ();
212 } /* namespace SBCLIENT */
214 #endif // ENTITIES_H
216 /* End of entities.h */