@@ -58,7 +58,7 @@ namespace RType {
58
58
ApplicationCommandLineArgs commandLine = Application::Get ().GetSpecification ().CommandLineArgs ;
59
59
60
60
// TODO: Temp port ./r-type_client {port} {ip} {port}
61
- int port = 8083 ; // Default port
61
+ int port = 8082 ; // Default port
62
62
if (commandLine.Count > 3 ) {
63
63
port = std::stoi (commandLine[3 ]);
64
64
@@ -71,11 +71,9 @@ namespace RType {
71
71
}
72
72
73
73
void RTypeLayer::ConnectToServer (int port, std::string ip, int serverPort) {
74
- _Network = CreateScope<Network::Network>(_WorldNetwork, _IOContextManager, port);
75
-
74
+ (void )port;
76
75
_Network->Loop ();
77
76
_Network->SendAskConnect (ip, (short )serverPort);
78
- // TODO: change ip and port when the server is on a different machine
79
77
}
80
78
81
79
void RTypeLayer::OnAttach () {
@@ -84,52 +82,26 @@ namespace RType {
84
82
int port = GetPort ();
85
83
std::string ip = GetIp ();
86
84
int serverPort = GetServerPort ();
85
+ _Network = CreateScope<Network::Network>(_WorldNetwork, _IOContextManager, port);
87
86
88
87
if (port == -1 )
89
88
return ;
90
89
91
- ConnectToServer (port, ip, serverPort);
92
-
93
90
// Create world
94
91
CurrentScene = GAME;
95
92
96
- // Scenes[MENU] = CreateRef<Scene>();
97
- // Scenes[MENU]->RegisterSystem(new AnimationSystem());
98
- // Scenes[MENU]->RegisterSystem(new MovingSystem(1.5f));
99
- // Scenes[MENU]->OnViewportResize(Application::Get().GetWindow().GetWidth(),
100
- // Application::Get().GetWindow().GetHeight());
101
-
102
- // RType::EntityEventSubscriber *subscribe = new RType::EntityEventSubscriber(_Network);
103
93
CollisionSystem *collisionSystem = new CollisionSystem ();
104
94
105
95
Scenes[GAME] = CreateRef<Scene>();
106
96
Scenes[GAME]->RegisterSystem (new AnimationSystem ());
107
97
Scenes[GAME]->RegisterSystem (new MovingSystem (1 .5f ));
108
98
Scenes[GAME]->RegisterSystem (collisionSystem);
109
- // Scenes[GAME]->Subscribe<Events::OnEntityCreated>(subscribe );
110
- // Scenes[GAME]->Subscribe<Events::OnEntityDestroyed>(subscribe);
99
+ Scenes[GAME]->RegisterSystem ( new ClockSystem () );
100
+
111
101
Scenes[GAME]->Subscribe <Exodia::Events::OnCollisionEntered>(collisionSystem);
112
102
Scenes[GAME]->OnViewportResize (Application::Get ().GetWindow ().GetWidth (),
113
103
Application::Get ().GetWindow ().GetHeight ());
114
104
115
- // Entity *music = Scenes[GAME]->CreateEntity("Background");
116
-
117
- // music->AddComponent<MusicComponent>(124013371145915, 0.5f, true);
118
-
119
- // Entity *text = Scenes[GAME]->CreateEntity("Text");
120
-
121
- // auto txt = text->AddComponent<TextRendererComponent>("\"From the dark regions of space they\n came...Waging
122
- // war upon us.\n One saviour stood his ground while all\n others were crushed under the alien\n assaul t...\n\n
123
- // The Prototype Markl .\"");
124
-
125
- // txt.Get().Font = UUID(4521854574125);
126
- // txt.Get().Font = UUID(45121874124124);
127
-
128
- // auto transform = text->GetComponent<TransformComponent>();
129
-
130
- // transform.Get().Translation = {-10.0f, 3.0f, 0.0f};
131
- // transform.Get().Scale = {0.50f, 0.50f, 1.0f};
132
-
133
105
_Network->SetWorld (Scenes[CurrentScene]->GetWorldPtr ());
134
106
135
107
// TODO: Temp code
@@ -143,41 +115,22 @@ namespace RType {
143
115
camera.Camera .SetViewportSize (Application::Get ().GetWindow ().GetWidth (),
144
116
Application::Get ().GetWindow ().GetHeight ());
145
117
146
- /* RType::EntityEventSubscriber *subscribe = new RType::EntityEventSubscriber(*_Network);
147
-
148
- Scenes[GAME]->Subscribe<Events::OnEntityCreated>(subscribe);
149
- Scenes[GAME]->Subscribe<Events::OnEntityDestroyed>(subscribe);*/
150
-
151
- /* Removing rigid body for static camera
152
- auto body_camera = cameraEntity->AddComponent<RigidBody2DComponent>();
153
- body_camera.Get().Type = RigidBody2DComponent::BodyType::Dynamic;
154
- body_camera.Get().Mass = 0.0f;
155
- body_camera.Get().GravityScale = 0.0f;
156
- body_camera.Get().Velocity = glm::vec2{ 1.5f, 0.0f };
157
- */
158
-
159
- // Create the entities
160
- // TODO: Ask server for playerID
161
- // int playerID = 0;
162
- // Entity *entity = Scenes[GAME]->CreateEntity("Player_" + std::to_string(playerID));
163
- // entity->AddComponent<ScriptComponent>().Get().Bind("Player");
164
-
165
- // Create pata-pata
166
- // Entity *patata = Scenes[GAME]->CreateEntity("Pata-pata");
167
- // patata->AddComponent<ScriptComponent>().Get().Bind("PataPata");
168
-
169
- // Create stars
170
- // CreateStars(Scenes);
171
118
for (int i = 0 ; i < 60 ; i++) {
172
119
Entity *star = Scenes[GAME]->CreateEntity (" Star" + std::to_string (i));
173
120
star->AddComponent <ScriptComponent>().Get ().Bind (" Star" );
174
121
}
175
122
176
123
// Create the camera
177
124
Scenes[CurrentScene]->OnRuntimeStart ();
125
+
126
+ ConnectToServer (port, ip, serverPort);
178
127
}
179
128
180
- void RTypeLayer::OnDetach () { EXODIA_PROFILE_FUNCTION (); }
129
+ void RTypeLayer::OnDetach () {
130
+ EXODIA_PROFILE_FUNCTION ();
131
+ _Network->SendDisconnect ();
132
+ EXODIA_CORE_ERROR (" RTypeLayer::OnDetach()" );
133
+ }
181
134
182
135
void RTypeLayer::OnUpdate (Exodia::Timestep ts) {
183
136
EXODIA_PROFILE_FUNCTION ();
@@ -193,6 +146,11 @@ namespace RType {
193
146
if (CurrentScene == GAME) {
194
147
};
195
148
149
+ _packetTimer += ts;
150
+ if (_packetTimer >= 1 ) {
151
+ _Network->SendPacketInfo ();
152
+ _packetTimer = 0 ;
153
+ }
196
154
// Update the world
197
155
Scenes[CurrentScene]->OnUpdateRuntime (ts);
198
156
}
@@ -218,16 +176,27 @@ namespace RType {
218
176
TagComponent &tc = tag.Get ();
219
177
220
178
std::ostringstream oss;
221
- oss << _Network->GetId ();
179
+ oss << _Network->GetIdPlayer ();
222
180
std::string player = " Player_" + oss.str ();
223
181
224
182
if ((tc.Tag .compare (player) == 0 ) && sc.Instance != nullptr ) {
225
- // sc.Instance->OnKeyPressed(key);
183
+ sc.Instance ->OnKeyPressed (key);
226
184
227
185
_Network->SendEvent (false , key, true );
228
186
}
229
187
(void )entity;
230
188
});
189
+ if (key == Key::ESCAPE) {
190
+ NetworkInfo info = _Network->GetNetworkInfo ();
191
+ EXODIA_CORE_ERROR (" PACKET info" );
192
+ EXODIA_CORE_ERROR (" Send packet: {0}" , info.sendPacket );
193
+ EXODIA_CORE_ERROR (" Received packet: {0}" , info.receivedPacket );
194
+ EXODIA_CORE_ERROR (" KiloByte sent: {0}" , info.kiloByteSent );
195
+ EXODIA_CORE_ERROR (" KiloByte received: {0}" , info.kiloByteReceived );
196
+ EXODIA_CORE_ERROR (" Packet loss sent: {0}" , info.sendPacketLost );
197
+ EXODIA_CORE_ERROR (" Packet loss received: {0}" , info.receivePacketLost );
198
+ EXODIA_CORE_ERROR (" PING sent: {0}" , info.ping );
199
+ }
231
200
Scenes[CurrentScene]->GetWorld ().UnlockMutex ();
232
201
233
202
return true ;
@@ -243,7 +212,7 @@ namespace RType {
243
212
TagComponent &tc = tag.Get ();
244
213
245
214
std::ostringstream oss;
246
- oss << _Network->GetId ();
215
+ oss << _Network->GetIdPlayer ();
247
216
std::string player = " Player_" + oss.str ();
248
217
249
218
if ((tc.Tag .compare (player) == 0 ) && sc.Instance != nullptr ) {
@@ -264,4 +233,4 @@ namespace RType {
264
233
265
234
return true ;
266
235
}
267
- }; // namespace RType
236
+ }; // namespace RType
0 commit comments