TDME2  1.9.200
ApplicationClient.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
15 
16 using std::vector;
17 using std::unique_ptr;
18 
27 
28 /**
29  * Application client
30  * @author Andreas Drewke
31  */
33 public:
34  // forbid class copy
36 
37  /**
38  * Public constructor
39  * @param context context
40  * @param udpClient UDP client
41  */
43 
44  /**
45  * Public constructor
46  */
47  virtual ~ApplicationClient();
48 
49  /**
50  * @return mutex
51  */
52  inline Mutex* getMutex() {
53  return &mutex;
54  }
55 
56  /**
57  * @return audio gain
58  */
59  inline float getAudioGain() {
60  return audioGain;
61  }
62 
63  /**
64  * Set audio gain
65  * @param gain gain
66  */
67  void setAudioGain(float gain) {
68  this->audioGain = gain;
69  }
70 
71  /**
72  * @return context
73  */
74  inline Context* getContext() {
75  return context.get();
76  }
77 
78  /**
79  * Collect HID events to pass to logics that have handling HID events enabled
80  * @param mouseEvents mouse events
81  * @param keyEvents keyboard events
82  */
83  void handleHIDEvents(vector<GUIMouseEvent>& mouseEvents, vector<GUIKeyboardEvent>& keyEvents);
84 
85  /**
86  * Updates engine and audio to context engine and audio instances
87  */
88  void update();
89 
90 private:
91  struct QueuedSound {
93  const string& gameLogicId,
94  const string& id,
95  float gain,
96  float pitch,
97  bool ignoreIfPlaying,
98  bool attachedToLogic,
99  const Vector3& position,
100  float distanceFromCamera
101  ):
103  id(id),
104  gain(gain),
105  pitch(pitch),
110  {}
111  string gameLogicId;
112  string id;
113  float gain;
114  float pitch;
119  };
120 
121  struct ActiveSound {
122  string id;
124  string gameLogicId;
125  };
126 
127  vector<QueuedSound> queuedSounds;
128  unordered_map<string, ActiveSound> activeSounds;
129 
130  // overridden methods
131  virtual void run() override;
132 
133  /**
134  * Handle in logic network packets
135  * @param logics logics
136  * @param inGameNetworkPackets incoming logic network packets
137  */
138  void handleInNetworkPackets(const vector<Logic*>& logics, vector<LogicNetworkPacket>& inLogicNetworkPackets);
139 
140 private:
141  unique_ptr<Context> context;
143  unique_ptr<UDPClient> udpClient;
144  float audioGain { 1.0f };
145 };
virtual ~ApplicationClient()
Public constructor.
void setAudioGain(float gain)
Set audio gain.
ApplicationClient(Context *context, UDPClient *udpClient=nullptr)
Public constructor.
void handleInNetworkPackets(const vector< Logic * > &logics, vector< LogicNetworkPacket > &inLogicNetworkPackets)
Handle in logic network packets.
unordered_map< string, ActiveSound > activeSounds
void update()
Updates engine and audio to context engine and audio instances.
void handleHIDEvents(vector< GUIMouseEvent > &mouseEvents, vector< GUIKeyboardEvent > &keyEvents)
Collect HID events to pass to logics that have handling HID events enabled.
virtual void run() override
Abstract run() method, should be implemented by subclassed class, will be called after spawn by start...
Dynamic physics world class.
Definition: World.h:38
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Mutex implementation.
Definition: Mutex.h:19
Base class for threads.
Definition: Thread.h:20
QueuedSound(const string &gameLogicId, const string &id, float gain, float pitch, bool ignoreIfPlaying, bool attachedToLogic, const Vector3 &position, float distanceFromCamera)
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6