Fix issue in Rocket.lua script.
[cafu-Engine.git] / Ca3DE / Client / ClientWorld.hpp
blobb1670b20155e8221730260e247a8871421f8d2d8
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 */
7 #ifndef CAFU_CACLIENTWORLD_HPP_INCLUDED
8 #define CAFU_CACLIENTWORLD_HPP_INCLUDED
10 #include "../Ca3DEWorld.hpp"
11 #include "GameSys/CompTransform.hpp"
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
20 struct PlayerCommandT;
21 class NetDataT;
24 /// This class reflects which entities are relevant for this client at the given server frame.
25 class FrameInfoT
27 public:
29 FrameInfoT() : IsValid(false) { }
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.
37 class CaClientWorldT : public Ca3DEWorldT
39 public:
41 // Constructor
42 CaClientWorldT(const char* FileName, ModelManagerT& ModelMan, cf::GuiSys::GuiResourcesT& GuiRes, WorldT::ProgressFunctionT ProgressFunction, unsigned long OurEntityID_) /*throw (WorldT::LoadErrorT)*/;
44 unsigned long GetOurEntityID() const { return OurEntityID; } // AUFLÖSEN!?
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);
50 unsigned long ReadServerFrameMessage(NetDataT& InData);
52 void OurEntity_Predict(const PlayerCommandT& PlayerCommand, unsigned int PlayerCommandNr);
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.
59 IntrusivePtrT<const cf::GameSys::ComponentTransformT> OurEntity_GetCamera() const;
61 void ComputeBFSPath(const VectorT& Start, const VectorT& End);
62 void Draw(float FrameTime) const;
65 private:
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.
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);
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;
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;
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;
94 const unsigned long OurEntityID;
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).
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.
102 ArrayT<unsigned long> BFS_Tree;
103 ArrayT<VectorT> BFS_TreePoints;
104 unsigned long BFS_EndLeafNr;
107 #endif