Cafu Engine
Client.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_CLIENT_HPP_INCLUDED
8 #define CAFU_CLIENT_HPP_INCLUDED
9 
10 #include "Network/Network.hpp"
11 #include "Templates/Pointer.hpp"
12 
13 
14 namespace cf { namespace GuiSys { class GuiImplT; } }
15 namespace cf { namespace GuiSys { class GuiResourcesT; } }
16 struct CaKeyboardEventT;
17 struct CaMouseEventT;
18 class ClientStateT;
19 class GameInfoT;
20 class ModelManagerT;
21 struct lua_State;
22 
23 
24 class ClientT
25 {
26  public:
27 
28  ClientT(const GameInfoT& GameInfo, ModelManagerT& ModelMan, cf::GuiSys::GuiResourcesT& GuiRes);
29  ~ClientT();
30 
31  void SetMainMenuGui(IntrusivePtrT<cf::GuiSys::GuiImplT> MainMenuGui_);
32 
33  // These methods are driven (called) by the GUI window that "owns" this client.
34  bool ProcessInputEvent(const CaKeyboardEventT& KE);
35  bool ProcessInputEvent(const CaMouseEventT& ME);
36  void Render(float FrameTime);
37  void MainLoop(float FrameTime);
38 
39 
40  static int ConFunc_rcon_Callback(lua_State* LuaState);
41  static int ConFunc_connect_Callback(lua_State* LuaState);
42  static int ConFunc_disconnect_Callback(lua_State* LuaState);
43 
44 
45  private:
46 
47  friend class ClientStateIdleT;
48  friend class ClientStateConnectingT;
49  friend class ClientStateInGameT;
50 
51  enum StateIDT
52  {
53  IDLE=0, ///< Client is in idle state, sitting around, doing nothing. This state is explicitly required (and cannot be implied by a NULL ClientT instance in user code) because the client may want to enter it on own discretion, especially after errors (e.g. unable to connect, disconnect from server, etc.).
54  CONNECTING, ///< Client is connecting to server.
55  // W4WORLD, ///< Client is waiting for "SC1_WorldInfo" message.
56  INGAME, ///< Client is fully joined into a game.
57  // DISCONNECTING ///< Client is disconnecting from server (not really used now, but with TCP or SCTP connections we might want to implement a graceful shutdown).
58  };
59 
60 
61  StateIDT GetStateID() const; ///< Returns the ID of CurrentState.
62  void UpdateCurrentState(); ///< Implements the transition to a new state.
63 
64  ClientT(const ClientT&); ///< Use of the Copy Constructor is not allowed.
65  void operator = (const ClientT&); ///< Use of the Assignment Operator is not allowed.
66 
67 
68  ClientStateT* CurrentState; ///< The state that the client is currently in.
69  StateIDT NextState; ///< The (ID of the) state that will become the current state before the next call to any of the methods of CurrentState.
70 
71  // Private data that is used in all (or at least multiple) states.
72  const GameInfoT& m_GameInfo; ///< The info for the game that we're running.
73  SOCKET Socket; ///< The socket that we're using for the connection to the server. This is a native socket that is managed by this class.
74  NetAddressT ServerAddress; ///< The server address we're using for the connection. Copied from the related ConVar whenever a new connection is established.
75  unsigned long PacketIDConnLess; ///< The ever increasing (and thus unique) PacketID for outgoing connection-less packets (e.g. connection requests, rcon commands, etc.).
76  IntrusivePtrT<cf::GuiSys::GuiImplT> MainMenuGui; ///< We inform the MainMenuGui whenever we enter a new state (a mini-implementation of the MVC pattern).
77  ModelManagerT& m_ModelMan; ///< The model manager that our client worlds load their models from.
78  cf::GuiSys::GuiResourcesT& m_GuiRes; ///< The GUI resources that are commonly used in our client worlds.
79 };
80 
81 #endif
Network address consisting of an IP4 address and port number.
Definition: Network.hpp:98
This class implements the "connecting-to-server" state of the client.
Definition: ClientStateConnecting.hpp:20
This struct describes a mouse event.
Definition: OpenGLWindow.hpp:185
This class implements the state of the client when it is fully connected and thus "in-game"...
Definition: ClientStateInGame.hpp:27
This struct describes a keyboard event.
Definition: OpenGLWindow.hpp:20
This class encapsulates information about a game.
Definition: GameInfo.hpp:14
Definition: Client.hpp:24
This class is used for managing model instances.
Definition: ModelManager.hpp:31
This is the base class for the concrete classes that implement the states of the client.
Definition: ClientState.hpp:18
This class implements the idle state of the client.
Definition: ClientStateIdle.hpp:18
This class manages and provides resources (fonts and models) for GuiImplT instances.
Definition: GuiResources.hpp:26