|
@@ -1,16 +1,28 @@
|
|
#include "client/Game.h"
|
|
#include "client/Game.h"
|
|
|
|
+#include "common/network/Packets.h"
|
|
#include "gaming-core/utils/Utils.h"
|
|
#include "gaming-core/utils/Utils.h"
|
|
|
|
|
|
Game::Game(const Controller& controller, const Clock& fps, const Clock& tps,
|
|
Game::Game(const Controller& controller, const Clock& fps, const Clock& tps,
|
|
- RenderSettings& settings, const Size& size)
|
|
|
|
|
|
+ RenderSettings& settings, const Size& size, Client& client)
|
|
: controller(controller), fps(fps), tps(tps), renderSettings(settings),
|
|
: controller(controller), fps(fps), tps(tps), renderSettings(settings),
|
|
- size(size), world(blockRegistry), worldRenderer(world) {
|
|
|
|
|
|
+ size(size), client(client), world(blockRegistry), worldRenderer(world),
|
|
|
|
+ connected(false) {
|
|
pos = Vector3(16.0f, 30.0f, -10.0f);
|
|
pos = Vector3(16.0f, 30.0f, -10.0f);
|
|
rotation = Quaternion(Vector3(1.0f, 0.0f, 0.0f), 30) * rotation;
|
|
rotation = Quaternion(Vector3(1.0f, 0.0f, 0.0f), 30) * rotation;
|
|
rotation = Quaternion(Vector3(0.0f, 1.0f, 0.0f), 30) * rotation;
|
|
rotation = Quaternion(Vector3(0.0f, 1.0f, 0.0f), 30) * rotation;
|
|
}
|
|
}
|
|
|
|
|
|
void Game::tick() {
|
|
void Game::tick() {
|
|
|
|
+ if(!connected && controller.down.wasReleased()) {
|
|
|
|
+ if(client.connect("127.0.0.1", 11196, 3000)) {
|
|
|
|
+ std::cout << client.getError() << '\n';
|
|
|
|
+ } else {
|
|
|
|
+ std::cout << "connected\n";
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ client.consumeEvents(*this);
|
|
|
|
+ }
|
|
|
|
+
|
|
lastRotation = rotation;
|
|
lastRotation = rotation;
|
|
lastPos = pos;
|
|
lastPos = pos;
|
|
|
|
|
|
@@ -72,4 +84,24 @@ void Game::renderTextOverlay(float lag, Renderer& renderer, FontRenderer& fr) {
|
|
|
|
|
|
bool Game::isRunning() const {
|
|
bool Game::isRunning() const {
|
|
return true;
|
|
return true;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Game::onConnect() {
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Game::onDisconnect() {
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Game::onPacket(InPacket& in) {
|
|
|
|
+ uint16 id;
|
|
|
|
+ if(in.readU16(id)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ switch(id) {
|
|
|
|
+ case ServerPacket::CHAT:
|
|
|
|
+ StringBuffer<256> s;
|
|
|
|
+ in.readString(s);
|
|
|
|
+ std::cout << s << '\n';
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|