Skip to content

Commit ec9330c

Browse files
dont bork the server
1 parent 7381583 commit ec9330c

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

include/MultiPlayer/Client.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ class Client
2020
void startUpdateThread();
2121
void updateThreadLoop();
2222
void poll();
23+
bool shouldSendPlayerPacket();
24+
void justSentPlayerPacket();
2325

2426
private:
2527
ENetHost* client;
2628
ENetPeer* peer;
2729
bool _isConnected = false;
2830
double lastUpdate = 0;
29-
double UPDATE_EVERY = 1.0 / 20.0;
31+
double UPDATE_EVERY = 1.0 / 5.0;
3032
std::shared_ptr<EntityRegistry> registry;
3133
};
3234

readme.md

+8
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,16 @@ Once the libraries are installed, you can compile and run the program as describ
151151

152152
Right now this is the only way to install the project.
153153

154+
#### Tracy submodule
154155
Clone the project (with submodules `git clone --recurse-submodules`), navigate to the project directory and run `make`:
155156

157+
or
158+
159+
if you have already cloned the project, use
160+
```
161+
git submodule update --init
162+
```
163+
156164
The build process will generate the `matrix` executable in the current directory.
157165

158166
## Running

src/MultiPlayer/Client.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <glm/glm.hpp>
44
#include "camera.h"
55
#include <GLFW/glfw3.h>
6+
#include <type_traits>
67
#include "systems/Player.h"
8+
#include <GLFW/glfw3.h>
79

810
namespace MultiPlayer {
911

@@ -151,11 +153,19 @@ Client::isConnected()
151153
return _isConnected;
152154
}
153155

156+
bool
157+
Client::shouldSendPlayerPacket() {
158+
return glfwGetTime()-lastUpdate >= UPDATE_EVERY;
159+
}
160+
161+
void Client::justSentPlayerPacket() {
162+
lastUpdate = glfwGetTime();
163+
}
164+
154165
bool
155166
Client::sendPlayer(glm::vec3 position, glm::vec3 front)
156167
{
157-
if (_isConnected) {
158-
168+
if (_isConnected && shouldSendPlayerPacket()) {
159169
ENetPacket* packet = enet_packet_create(
160170
NULL, sizeof(glm::vec3) * 2, ENET_PACKET_FLAG_UNSEQUENCED);
161171

@@ -168,6 +178,7 @@ Client::sendPlayer(glm::vec3 position, glm::vec3 front)
168178
enet_peer_send(peer, 1, packet);
169179
enet_host_flush(client);
170180

181+
justSentPlayerPacket();
171182
return true;
172183
}
173184

0 commit comments

Comments
 (0)