From d89283ddab7e12ed345561758fa21bf92840b8e4 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Sat, 12 Jan 2019 22:42:24 +0100 Subject: [PATCH] [ServerLoadingState] Added. --- client/include/core/ClientApplication.hpp | 3 ++ client/include/states/GameState.hpp | 4 +- client/include/states/ServerLoadingState.hpp | 42 ++++++++++++++++ client/source/core/ClientApplication.cpp | 4 +- client/source/states/GameState.cpp | 2 +- client/source/states/ServerLoadingState.cpp | 53 ++++++++++++++++++++ 6 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 client/include/states/ServerLoadingState.hpp create mode 100644 client/source/states/ServerLoadingState.cpp diff --git a/client/include/core/ClientApplication.hpp b/client/include/core/ClientApplication.hpp index 95363634..328af647 100644 --- a/client/include/core/ClientApplication.hpp +++ b/client/include/core/ClientApplication.hpp @@ -16,6 +16,7 @@ #include +#include "Client.hpp" #include "KeyboardHandler.hpp" #include "Registry.hpp" #include "ScriptEngine.hpp" @@ -34,6 +35,8 @@ class ClientApplication : public gk::CoreApplication { ScriptEngine m_scriptEngine; Registry m_registry; + + Client m_client; }; #endif // CLIENTAPPLICATION_HPP_ diff --git a/client/include/states/GameState.hpp b/client/include/states/GameState.hpp index 4a52063b..fc1213c0 100644 --- a/client/include/states/GameState.hpp +++ b/client/include/states/GameState.hpp @@ -30,7 +30,7 @@ class GameState : public gk::ApplicationState { public: - GameState(); + GameState(Client &client); void testLuaAPI(); @@ -55,7 +55,7 @@ class GameState : public gk::ApplicationState { LuaCore m_luaCore; - Client m_client; + Client &m_client; bool m_hasGameStarted = false; }; diff --git a/client/include/states/ServerLoadingState.hpp b/client/include/states/ServerLoadingState.hpp new file mode 100644 index 00000000..4574a324 --- /dev/null +++ b/client/include/states/ServerLoadingState.hpp @@ -0,0 +1,42 @@ +/* + * ===================================================================================== + * + * Filename: ServerLoadingState.hpp + * + * Description: + * + * Created: 12/01/2019 21:57:24 + * + * Author: Quentin Bazin, + * + * ===================================================================================== + */ +#ifndef SERVERLOADINGSTATE_HPP_ +#define SERVERLOADINGSTATE_HPP_ + +#include +#include +#include + +class Client; + +class ServerLoadingState : public gk::ApplicationState { + public: + ServerLoadingState(Client &client); + + void update() override; + + private: + void draw(gk::RenderTarget &target, gk::RenderStates states) const override; + + gk::Shader m_shader; + + Client &m_client; + + gk::Text m_text; + gk::Text m_textShadow; + + mutable bool m_hasBeenDrawn = false; +}; + +#endif // SERVERLOADINGSTATE_HPP_ diff --git a/client/source/core/ClientApplication.cpp b/client/source/core/ClientApplication.cpp index 4c6864ff..1b4b6b29 100644 --- a/client/source/core/ClientApplication.cpp +++ b/client/source/core/ClientApplication.cpp @@ -19,6 +19,7 @@ #include "Config.hpp" #include "GameState.hpp" #include "TextureLoader.hpp" +#include "ServerLoadingState.hpp" void ClientApplication::init() { gk::CoreApplication::init(); @@ -41,7 +42,8 @@ void ClientApplication::init() { m_scriptEngine.init(); - m_stateStack.push(); + // m_stateStack.push(m_client); + m_stateStack.push(m_client); } void ClientApplication::initOpenGL() { diff --git a/client/source/states/GameState.cpp b/client/source/states/GameState.cpp index f26b3852..5963b823 100644 --- a/client/source/states/GameState.cpp +++ b/client/source/states/GameState.cpp @@ -30,7 +30,7 @@ #include "PlayerInventoryWidget.hpp" #include "ScriptEngine.hpp" -GameState::GameState() { +GameState::GameState(Client &client) : m_client(client) { try { m_client.connect("localhost", 4242); } diff --git a/client/source/states/ServerLoadingState.cpp b/client/source/states/ServerLoadingState.cpp new file mode 100644 index 00000000..99f2e9a9 --- /dev/null +++ b/client/source/states/ServerLoadingState.cpp @@ -0,0 +1,53 @@ +/* + * ===================================================================================== + * + * Filename: ServerLoadingState.cpp + * + * Description: + * + * Created: 12/01/2019 21:58:21 + * + * Author: Quentin Bazin, + * + * ===================================================================================== + */ +#include +#include + +#include "Config.hpp" +#include "GameState.hpp" +#include "ServerLoadingState.hpp" + +ServerLoadingState::ServerLoadingState(Client &client) : m_client(client) { + m_shader.createProgram(); + m_shader.addShader(GL_VERTEX_SHADER, "resources/shaders/basic.v.glsl"); + m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/basic.f.glsl"); + m_shader.linkProgram(); + + m_text.setFont(gk::ResourceHandler::getInstance().get("font-default")); + m_text.setCharacterSize(8 * 6); + m_text.setText("Loading world..."); + m_text.setColor(gk::Color::White); + m_text.setPosition(SCREEN_WIDTH / 2.0 - m_text.getLocalBounds().width / 2.0, 200); + + m_textShadow.setFont(gk::ResourceHandler::getInstance().get("font-default")); + m_textShadow.setCharacterSize(8 * 6); + m_textShadow.setText(m_text.text()); + m_textShadow.setColor(gk::Color{70, 70, 70, 255}); + m_textShadow.setPosition(m_text.getPosition().x + 6, m_text.getPosition().y + 6); +} + +void ServerLoadingState::update() { + if (m_hasBeenDrawn) + m_stateStack->push(m_client); +} + +void ServerLoadingState::draw(gk::RenderTarget &target, gk::RenderStates states) const { + states.shader = &m_shader; + target.setView(target.getDefaultView()); + target.draw(m_textShadow, states); + target.draw(m_text, states); + + m_hasBeenDrawn = true; +} +