Cafu Engine
ServerWorld.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_CASERVERWORLD_HPP_INCLUDED
8 #define CAFU_CASERVERWORLD_HPP_INCLUDED
9 
10 #include "../Ca3DEWorld.hpp"
11 #include "../../Games/PlayerCommand.hpp"
12 
13 
14 namespace cf { namespace ClipSys { class CollisionModelT; } }
15 struct ClientInfoT;
16 class NetDataT;
17 
18 
20 {
21  public:
22 
23  // Erstellt eine neue ServerWorld anhand des World-Files 'FileName', wobei 'FileName' den kompletten (wenn auch relativen) Pfad und Namen enthält.
24  CaServerWorldT(const char* FileName, ModelManagerT& ModelMan, cf::GuiSys::GuiResourcesT& GuiRes);
25 
26  /// Removes the entity identified by 'EntityID' from the (server) world.
27  void RemoveEntity(unsigned long EntityID);
28 
29  // Fügt einen neuen HumanPlayer-Entity zum NÄCHSTEN Frame in die World ein (idR nach Client-Join oder World-Change),
30  // NICHT ins aktuelle (bzgl. der BaseLineFrameNr). Ziel: Erreiche gleiches Verhalten wie z.B. das des MonsterMakers.
31  // Gibt bei Erfolg die ID des neuen Entities zurück, sonst 0xFFFFFFFF.
32  unsigned long InsertHumanPlayerEntityForNextFrame(const char* PlayerName, const char* ModelName, unsigned long ClientInfoNr);
33 
34  // Informiert den (HumanPlayer-)Entity mit der ID 'HumanPlayerEntityID' über das 'PlayerCommand' (zur Verarbeitung beim nächsten 'Think()en'.
35  void NotifyHumanPlayerEntityOfClientCommand(unsigned long HumanPlayerEntityID, const PlayerCommandT& PlayerCommand);
36 
37  // Falls es neue Entities (und damit neue BaseLine-Messages) gibt, die jünger sind als 'OldBaseLineFrameNr',
38  // schreibe entsprechende BaseLine-Messages nach 'OutDatas'.
39  // Schreibt für alle EngineEntities, die seit 'SentClientBaseLineFrameNr' (=='OldBaseLineFrameNr') neu erschaffen wurden, SC1_EntityBaseLine Messages nach 'OutDatas'
40  // (d.h. für solche, deren 'BaseLineFrameNr' größer (d.h. jünger) als die 'SentClientBaseLineFrameNr' ist).
41  unsigned long WriteClientNewBaseLines(unsigned long OldBaseLineFrameNr, ArrayT< ArrayT<char> >& OutDatas) const;
42 
43  /// This method writes a delta update message for the given client into the given `OutData`.
44  /// Note that this method must only be called *after* UpdateFrameInfo() has been called,
45  /// because it relies on the client's frame info being up-to-date for the current frame!
46  ///
47  /// The message consist of an SC1_FrameInfo header and all SC1_EntityUpdate and
48  /// SC1_EntityRemove (sub-)messages as required for the client to reconstruct the current
49  /// frame.
50  void WriteClientDeltaUpdateMessages(const ClientInfoT& ClientInfo, NetDataT& OutData) const;
51 
52  /// This method advances the world over the given time `FrameTime` into the next state.
53  /// That is, time `FrameTime` is applied to all entities in `m_EngineEntities` in order
54  /// to compute the next state, advancing the `m_ServerFrameNr` by one.
55  void Think(float FrameTime);
56 
57  /// This method *must* be called after Think() for each client:
58  /// It updates the client's frame info corresponding to the the new/current server frame.
59  ///
60  /// The previous call to Think() brought the entire world (all m_EngineEntities) into the
61  /// new state with number m_ServerFrameNr. The ClientInfoT instances however know at this
62  /// time nothing about the new state. Calling this method updates a client's frame info
63  /// (the list of entities that are relevant for the client in the new frame) accordingly.
64  void UpdateFrameInfo(ClientInfoT& ClientInfo) const;
65 
66 
67  private:
68 
69  CaServerWorldT(const CaServerWorldT&); ///< Use of the Copy Constructor is not allowed.
70  void operator = (const CaServerWorldT&); ///< Use of the Assignment Operator is not allowed.
71 
72  unsigned long m_ServerFrameNr; ///< Nummer des aktuellen Frames/Zustands
73  bool m_IsThinking; ///< Set to true while we're thinking, so that our methods can detect recursive calls.
74  ArrayT<unsigned long> m_EntityRemoveList; ///< List of entity IDs that were scheduled for removal while thinking.
75 };
76 
77 #endif
void RemoveEntity(unsigned long EntityID)
Removes the entity identified by 'EntityID' from the (server) world.
Definition: ServerWorld.cpp:38
void WriteClientDeltaUpdateMessages(const ClientInfoT &ClientInfo, NetDataT &OutData) const
This method writes a delta update message for the given client into the given OutData.
Definition: ServerWorld.cpp:321
Definition: Ca3DEWorld.hpp:22
This struct represents per-frame player inputs for controlling human player entities.
Definition: PlayerCommand.hpp:32
Definition: ServerWorld.hpp:19
Class that allows easy and portable handling, sending and receiving of data over a network...
Definition: Network.hpp:181
Definition: ClientInfo.hpp:13
This class is used for managing model instances.
Definition: ModelManager.hpp:31
void UpdateFrameInfo(ClientInfoT &ClientInfo) const
This method must be called after Think() for each client: It updates the client's frame info correspo...
Definition: ServerWorld.cpp:283
Definition: Renderer.hpp:16
void Think(float FrameTime)
This method advances the world over the given time FrameTime into the next state. ...
Definition: ServerWorld.cpp:177
This class manages and provides resources (fonts and models) for GuiImplT instances.
Definition: GuiResources.hpp:26