2014-12-15 16:47:30 +01:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
2019-01-09 20:44:58 +01:00
|
|
|
* Filename: ClientApplication.cpp
|
2014-12-15 16:47:30 +01:00
|
|
|
*
|
2018-06-05 01:24:54 +02:00
|
|
|
* Description:
|
2014-12-15 16:47:30 +01:00
|
|
|
*
|
2019-01-09 20:44:58 +01:00
|
|
|
* Created: 09/01/2019 19:33:52
|
2014-12-15 16:47:30 +01:00
|
|
|
*
|
2018-06-12 09:24:43 +02:00
|
|
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
2014-12-15 16:47:30 +01:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
2018-12-29 02:23:23 +01:00
|
|
|
#include <gk/core/input/GamePad.hpp>
|
|
|
|
#include <gk/core/Mouse.hpp>
|
2019-01-05 18:37:59 +01:00
|
|
|
#include <gk/graphics/Font.hpp>
|
2018-12-29 02:23:23 +01:00
|
|
|
|
2019-01-09 20:44:58 +01:00
|
|
|
#include "ClientApplication.hpp"
|
2014-12-15 16:47:30 +01:00
|
|
|
#include "Config.hpp"
|
2018-06-21 00:55:38 +02:00
|
|
|
#include "GameState.hpp"
|
2018-12-29 02:23:23 +01:00
|
|
|
#include "TextureLoader.hpp"
|
2019-01-12 22:42:24 +01:00
|
|
|
#include "ServerLoadingState.hpp"
|
2014-12-15 16:47:30 +01:00
|
|
|
|
2019-01-16 22:40:29 +01:00
|
|
|
using namespace std::literals::string_literals;
|
|
|
|
|
|
|
|
ClientApplication::ClientApplication(int argc, char **argv) : gk::CoreApplication(argc, argv) {
|
|
|
|
}
|
|
|
|
|
2019-01-09 20:44:58 +01:00
|
|
|
void ClientApplication::init() {
|
2019-01-22 00:08:04 +01:00
|
|
|
m_argumentParser.addArgument("host", {"-h", "--host", true});
|
2019-01-21 23:59:43 +01:00
|
|
|
m_argumentParser.addArgument("port", {"-p", "--port", true});
|
|
|
|
|
2018-12-29 02:23:23 +01:00
|
|
|
gk::CoreApplication::init();
|
|
|
|
|
2019-01-22 00:08:04 +01:00
|
|
|
if (m_argumentParser.getArgument("host").isFound)
|
|
|
|
m_host = m_argumentParser.getArgument("host").parameter;
|
2019-01-21 23:59:43 +01:00
|
|
|
if (m_argumentParser.getArgument("port").isFound)
|
|
|
|
m_port = std::stoi(m_argumentParser.getArgument("port").parameter);
|
|
|
|
|
2018-12-29 02:23:23 +01:00
|
|
|
gk::GamePad::init(m_keyboardHandler);
|
2018-06-05 01:24:54 +02:00
|
|
|
|
2018-06-14 02:38:02 +02:00
|
|
|
createWindow(SCREEN_WIDTH, SCREEN_HEIGHT, APP_NAME);
|
2014-12-18 07:02:48 +01:00
|
|
|
m_window.setVerticalSyncEnabled(true);
|
2019-01-02 01:44:12 +01:00
|
|
|
m_window.disableView();
|
2018-06-05 01:24:54 +02:00
|
|
|
|
2018-12-29 23:24:38 +01:00
|
|
|
initOpenGL();
|
|
|
|
|
2018-12-29 02:23:23 +01:00
|
|
|
gk::Mouse::setCursorVisible(false);
|
|
|
|
gk::Mouse::setCursorGrabbed(true);
|
2018-06-21 00:55:38 +02:00
|
|
|
|
2018-06-21 05:45:17 +02:00
|
|
|
m_resourceHandler.loadConfigFile<TextureLoader>("resources/config/textures.xml");
|
2018-12-31 04:12:22 +01:00
|
|
|
m_resourceHandler.add<gk::Font>("font-default", "resources/fonts/default.ttf");
|
2018-06-05 01:24:54 +02:00
|
|
|
|
2018-06-23 23:05:36 +02:00
|
|
|
Registry::setInstance(m_registry);
|
2019-01-07 03:55:37 +01:00
|
|
|
|
2019-01-22 00:08:04 +01:00
|
|
|
m_stateStack.push<GameState>(m_client, m_host, m_port);
|
2019-01-16 22:40:29 +01:00
|
|
|
// m_stateStack.push<ServerLoadingState>(m_client);
|
2015-07-17 17:08:53 +02:00
|
|
|
}
|
|
|
|
|
2019-01-09 20:44:58 +01:00
|
|
|
void ClientApplication::initOpenGL() {
|
2019-01-07 03:55:37 +01:00
|
|
|
// Enable transparency
|
2018-12-29 23:24:38 +01:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2019-01-07 03:55:37 +01:00
|
|
|
// Enable depth and hide backside of faces
|
2018-12-29 23:24:38 +01:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
|
|
|
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
glPolygonOffset(1, 1);
|
|
|
|
|
2019-01-07 03:55:37 +01:00
|
|
|
// Set best quality for mipmaps
|
2018-12-29 23:24:38 +01:00
|
|
|
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
|
|
|
|
|
2019-01-07 03:55:37 +01:00
|
|
|
// Set clear color to skyblue
|
|
|
|
glClearColor(0.196078, 0.6, 0.8, 1.0);
|
2018-12-29 23:24:38 +01:00
|
|
|
}
|
|
|
|
|