Working on local and websocket client
This commit is contained in:
1 parent
483757f8ca
commit
ea26d6fb23
8 files changed
+178
-37
No files matched your search
+25
-27
@@ -13,6 +13,12 @@
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
#ifdef NETWORK
|
||||
#include "network/WebSocketClient.h"
|
||||
#else
|
||||
#include "network/LocalClient.h"
|
||||
#endif
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
#ifdef EMSCRIPTEN
|
||||
@@ -375,6 +381,14 @@ namespace ZL
|
||||
//rockTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/rock.png", CONST_ZIP_FILE));
|
||||
|
||||
std::cout << "Init step 8 " << std::endl;
|
||||
|
||||
#ifdef NETWORK
|
||||
networkClient = std::make_unique<WebSocketClient>(taskManager.getIOContext());
|
||||
networkClient->Connect("127.0.0.1", 8080);
|
||||
#else
|
||||
networkClient = std::make_unique<LocalClient>();
|
||||
networkClient->Connect("", 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Game::drawCubemap(float skyPercent)
|
||||
@@ -626,6 +640,13 @@ namespace ZL
|
||||
sparkEmitter.update(static_cast<float>(delta));
|
||||
planetObject.update(static_cast<float>(delta));
|
||||
|
||||
static float pingTimer = 0.0f;
|
||||
pingTimer += delta;
|
||||
if (pingTimer >= 1000.0f) {
|
||||
networkClient->Send("PING");
|
||||
pingTimer = 0.0f;
|
||||
}
|
||||
|
||||
if (Environment::tapDownHold) {
|
||||
|
||||
float diffx = Environment::tapDownCurrentPos(0) - Environment::tapDownStartPos(0);
|
||||
@@ -765,7 +786,6 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
uiManager.update(static_cast<float>(delta));
|
||||
//#endif
|
||||
lastTickCount = newTickCount;
|
||||
}
|
||||
}
|
||||
@@ -844,31 +864,6 @@ namespace ZL
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
int mx = event.button.x;
|
||||
int my = event.button.y;
|
||||
|
||||
uiManager.onMouseDown(mx, my);
|
||||
|
||||
bool uiHandled = false;
|
||||
|
||||
for (const auto& button : uiManager.findButton("") ? std::vector<std::shared_ptr<UiButton>>{} : std::vector<std::shared_ptr<UiButton>>{}) {
|
||||
(void)button;
|
||||
}
|
||||
|
||||
auto pressedSlider = [&]() -> std::shared_ptr<UiSlider> {
|
||||
for (const auto& slider : uiManager.findSlider("") ? std::vector<std::shared_ptr<UiSlider>>{} : std::vector<std::shared_ptr<UiSlider>>{}) {
|
||||
(void)slider;
|
||||
}
|
||||
return nullptr;
|
||||
}();
|
||||
|
||||
if (!uiManager.isUiInteraction()) {
|
||||
Environment::tapDownHold = true;
|
||||
|
||||
Environment::tapDownStartPos(0) = mx;
|
||||
Environment::tapDownStartPos(1) = my;
|
||||
|
||||
Environment::tapDownCurrentPos(0) = mx;
|
||||
Environment::tapDownCurrentPos(1) = my;
|
||||
}
|
||||
handleDown(mx, my);
|
||||
}
|
||||
if (event.type == SDL_MOUSEBUTTONUP) {
|
||||
@@ -884,6 +879,7 @@ namespace ZL
|
||||
handleMotion(mx, my);
|
||||
|
||||
}
|
||||
/*
|
||||
if (event.type == SDL_MOUSEWHEEL) {
|
||||
static const float zoomstep = 2.0f;
|
||||
if (event.wheel.y > 0) {
|
||||
@@ -916,11 +912,12 @@ namespace ZL
|
||||
Environment::shipVelocity -= 50.f;
|
||||
//x = x - 2.0;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
render();
|
||||
mainThreadHandler.processMainThreadTasks();
|
||||
networkClient->Poll();
|
||||
}
|
||||
|
||||
void Game::handleDown(int mx, int my)
|
||||
@@ -953,6 +950,7 @@ namespace ZL
|
||||
Environment::tapDownCurrentPos(1) = my;
|
||||
}
|
||||
}
|
||||
|
||||
void Game::handleUp(int mx, int my)
|
||||
{
|
||||
int uiX = mx;
|
||||
|
||||
Reference in new issue
Block a user