Cafu Engine
ClientWorld.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_CACLIENTWORLD_HPP_INCLUDED
8 #define CAFU_CACLIENTWORLD_HPP_INCLUDED
9 
10 #include "../Ca3DEWorld.hpp"
11 #include "GameSys/CompTransform.hpp"
12 
13 #if defined(_WIN32) && _MSC_VER<1600
14 #include "pstdint.h" // Paul Hsieh's portable implementation of the stdint.h header.
15 #else
16 #include <stdint.h>
17 #endif
18 
19 
20 struct PlayerCommandT;
21 class NetDataT;
22 
23 
24 /// This class reflects which entities are relevant for this client at the given server frame.
26 {
27  public:
28 
29  FrameInfoT() : IsValid(false) { }
30 
31  bool IsValid; ///< Is this a properly received and thus usable frame info at all?
32  unsigned long ServerFrameNr; ///< The number of the server frame that this info is about.
33  ArrayT<unsigned long> EntityIDsInPVS; ///< The IDs of the entities that are relevant for this client at the given server frame.
34 };
35 
36 
38 {
39  public:
40 
41  // Constructor
42  CaClientWorldT(const char* FileName, ModelManagerT& ModelMan, cf::GuiSys::GuiResourcesT& GuiRes, WorldT::ProgressFunctionT ProgressFunction, unsigned long OurEntityID_) /*throw (WorldT::LoadErrorT)*/;
43 
44  unsigned long GetOurEntityID() const { return OurEntityID; } // AUFLÖSEN!?
45 
46  // Erzeugt einen neuen Entity durch das zu Ende Lesen einer SC1_EntityBaseLine Message. Gibt 'true' zurück bei Erfolg, sonst 'false'.
47  // Letzteres passiert nur nach einem fatalen Fehler, nämlich wenn 'InData' einen unbekannten Entity-Typ beschreibt (Entity-TypeID).
48  bool ReadEntityBaseLineMessage(NetDataT& InData);
49 
50  unsigned long ReadServerFrameMessage(NetDataT& InData);
51 
52  void OurEntity_Predict(const PlayerCommandT& PlayerCommand, unsigned int PlayerCommandNr);
53 
54  /// Returns the camera details of "our" entity that the client should use to render the world.
55  /// This is typically called for the local human player from whose perspective the world is rendered.
56  ///
57  /// @returns `NULL` if "our" entity was not available (or no camera details could be retrieved),
58  /// the Transform component of the camera entity on success.
60 
61  void ComputeBFSPath(const VectorT& Start, const VectorT& End);
62  void Draw(float FrameTime) const;
63 
64 
65  private:
66 
67  CaClientWorldT(const CaClientWorldT&); // Use of the Copy Constructor is not allowed.
68  void operator = (const CaClientWorldT&); // Use of the Assignment Operator is not allowed.
69 
70  // Ruft 'EngineEntityT::ParseServerDeltaUpdateMessage()' für den EngineEntityT mit der ID 'EntityID' auf (siehe Dokumentation dieser Funktion!).
71  // Das Rückgabeergebnis entspricht dem dieser Funktion, ein Scheitern kann nun aber zusätzlich vorkommen, falls 'EntityID' nicht existiert.
72  bool ParseServerDeltaUpdateMessage(unsigned long EntityID, unsigned long DeltaFrameNr, unsigned long ServerFrameNr,
73  const ArrayT<uint8_t>* DeltaMessage);
74 
75  // Please see the corresponding function in EngineEntityT for documentation.
76  bool GetLightSourceInfo(unsigned long EntityID, unsigned long& DiffuseColor, unsigned long& SpecularColor, VectorT& Position, float& Radius, bool& CastsShadows) const;
77 
78  // Draws all entities whose ID is contained in the 'EntityIDs' array.
79  // The entity with ID 'OurEntityID' specifies "our" entity.
80  // (Everything else is drawn from the viewpoint from this entity, and it is necessary to let the
81  // render code know that, such that (for example) it can prevent that we see the inside of our own body!)
82  // Note that the Material Systems global per-lightsource lighting parameters (light-source and eye position etc.)
83  // should have been set before calling this function. Ambient light color is however set within this function (per entity).
84  void DrawEntities(unsigned long OurEntityID, bool SkipOurEntity, const VectorT& ViewerPos, const ArrayT<unsigned long>& EntityIDs) const;
85 
86  // Calls the 'PostDraw()' methods of all entities whose ID is contained in the 'EntityIDs' array.
87  // The calls are ordered such that the call to the entity with ID 'OurEntityID' is made last.
88  // The 'FrameTime' is passed to each call of 'PostDraw()'.
89  // All this provides opportunities for entities to render HUDs, employ simple "mini-prediction",
90  // triggers sounds, register particles, do other server-independent eye-candy, and so on.
91  void PostDrawEntities(float FrameTime, const ArrayT<unsigned long>& EntityIDs) const;
92 
93 
94  const unsigned long OurEntityID;
95 
96  ArrayT<FrameInfoT> m_FrameInfos; ///< The last frame infos as received from the server. Past frame infos are kept for the delta decompression.
97  unsigned long m_ServerFrameNr; ///< The number of the latest server frame that we have been updated to (received an SC1_FrameInfo message for).
98 
99  ArrayT<PlayerCommandT> m_PlayerCommands; ///< The last player commands, kept for the reprediction that is applied after each frame update from the server.
100  unsigned int m_PlayerCommandNr; ///< The number of the latest player command in m_PlayerCommands.
101 
102  ArrayT<unsigned long> BFS_Tree;
103  ArrayT<VectorT> BFS_TreePoints;
104  unsigned long BFS_EndLeafNr;
105 };
106 
107 #endif
unsigned long ServerFrameNr
The number of the server frame that this info is about.
Definition: ClientWorld.hpp:32
This class implements smart (reference-counted) pointers.
Definition: Pointer.hpp:43
Definition: Ca3DEWorld.hpp:22
This struct represents per-frame player inputs for controlling human player entities.
Definition: PlayerCommand.hpp:32
This class reflects which entities are relevant for this client at the given server frame...
Definition: ClientWorld.hpp:25
Definition: ClientWorld.hpp:37
Class that allows easy and portable handling, sending and receiving of data over a network...
Definition: Network.hpp:181
ArrayT< unsigned long > EntityIDsInPVS
The IDs of the entities that are relevant for this client at the given server frame.
Definition: ClientWorld.hpp:33
This class is used for managing model instances.
Definition: ModelManager.hpp:31
bool IsValid
Is this a properly received and thus usable frame info at all?
Definition: ClientWorld.hpp:31
IntrusivePtrT< const cf::GameSys::ComponentTransformT > OurEntity_GetCamera() const
Returns the camera details of "our" entity that the client should use to render the world...
Definition: ClientWorld.cpp:330
This class manages and provides resources (fonts and models) for GuiImplT instances.
Definition: GuiResources.hpp:26