feat: add android support

This commit is contained in:
2021-11-01 15:24:33 +01:00
parent 8f0e0c48ed
commit 0c68512caf
15 changed files with 38 additions and 29 deletions

View File

@@ -5,6 +5,7 @@
#include <map> #include <map>
#include <unordered_map> #include <unordered_map>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <array>
#include "Mobs.h" #include "Mobs.h"
#include "Team.h" #include "Team.h"

View File

@@ -14,9 +14,9 @@ private:
public: public:
WorldClient(ClientGame* game); WorldClient(ClientGame* game);
virtual void HandlePacket(protocol::WorldBeginDataPacket* packet); virtual void HandlePacket(protocol::WorldBeginDataPacket* packet) override;
virtual void HandlePacket(protocol::WorldDataPacket* packet); virtual void HandlePacket(protocol::WorldDataPacket* packet) override;
virtual void HandlePacket(protocol::SpawnMobPacket* packet); virtual void HandlePacket(protocol::SpawnMobPacket* packet) override;
virtual void OnArrowShot(game::MobPtr target, game::Tower* shooter) override; virtual void OnArrowShot(game::MobPtr target, game::Tower* shooter) override;
}; };

View File

@@ -1,3 +1,8 @@
#pragma once #pragma once
#ifdef ANDROID
#include <GLES3/gl3.h>
#else
#include "glbinding/gl/gl.h" #include "glbinding/gl/gl.h"
using namespace gl;
#endif

View File

@@ -10,10 +10,7 @@
#include <string> #include <string>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "render/GL.h"
namespace gl {
enum class GLenum : unsigned int;
}
class ShaderProgram { class ShaderProgram {
public: public:
@@ -40,8 +37,8 @@ private:
unsigned int programID; unsigned int programID;
unsigned int vertexShaderID; unsigned int vertexShaderID;
unsigned int fragmentShaderID; unsigned int fragmentShaderID;
int loadShaderFromFile(const std::string& file, gl::GLenum type); int loadShaderFromFile(const std::string& file, GLenum type);
int loadShader(const std::string& source, gl::GLenum type); int loadShader(const std::string& source, GLenum type);
}; };
#endif /* RENDER_SHADERS_SHADERPROGRAM_H_ */ #endif /* RENDER_SHADERS_SHADERPROGRAM_H_ */

View File

@@ -3,6 +3,7 @@
#include <iomanip> #include <iomanip>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream>
namespace td { namespace td {

View File

@@ -5,15 +5,15 @@
* Author: simon * Author: simon
*/ */
#ifndef ANDROID
#include <glbinding/Binding.h>
#endif
#include "render/Renderer.h" #include "render/Renderer.h"
#include "render/GL.h" #include "render/GL.h"
#include <glbinding/Binding.h>
#include <stdio.h> #include <stdio.h>
#include "misc/Time.h" #include "misc/Time.h"
#include "misc/Easing.h" #include "misc/Easing.h"
using namespace gl;
namespace td { namespace td {
namespace render { namespace render {
@@ -43,7 +43,9 @@ void Renderer::initShader() {
} }
bool Renderer::init() { bool Renderer::init() {
#ifndef ANDROID
glbinding::Binding::initialize(); glbinding::Binding::initialize();
#endif
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

View File

@@ -134,7 +134,7 @@ void WorldRenderer::renderPopups() const {
break; break;
} }
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(game::getTowerInfo(towerType).getDescription().c_str()); ImGui::SetTooltip(game::getTowerInfo(towerType).getDescription().c_str(), "%s");
} }
} }
} }

View File

@@ -136,7 +136,7 @@ void renderMainMenu() {
static std::string worldFilePath; static std::string worldFilePath;
ImGui::InputInt("Server Port", &port, -1); ImGui::InputInt("Server Port", &port, -1);
ImGui::Text(std::string("Fichier de monde sélectionné : " + (worldFilePath.empty() ? std::string("Aucun") : worldFilePath)).c_str()); ImGui::Text("%s", std::string("Fichier de monde sélectionné : " + (worldFilePath.empty() ? std::string("Aucun") : worldFilePath)).c_str());
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Ouvrir un fichier")) { if (ImGui::Button("Ouvrir un fichier")) {
ImGui::OpenPopup("WorldFileDialog"); ImGui::OpenPopup("WorldFileDialog");
@@ -178,7 +178,7 @@ void showPlayers() {
for (auto pair : client->getGame().getPlayers()) { for (auto pair : client->getGame().getPlayers()) {
const td::game::Player& player = pair.second; const td::game::Player& player = pair.second;
ImGui::PushStyleColor(ImGuiCol_Text, getImGuiTeamColor(player.getTeamColor())); ImGui::PushStyleColor(ImGuiCol_Text, getImGuiTeamColor(player.getTeamColor()));
ImGui::Text(player.getName().c_str()); ImGui::Text("%s", player.getName().c_str());
ImGui::PopStyleColor(); ImGui::PopStyleColor();
} }
ImGui::TreePop(); ImGui::TreePop();
@@ -321,8 +321,16 @@ void tick() {
lastTime = td::utils::getTime(); lastTime = td::utils::getTime();
} }
void pollEvents(){
SDL_Event event;
while(SDL_PollEvent(&event)){
ImGui_ImplSDL2_ProcessEvent(&event);
}
}
void render() { void render() {
tick(); tick();
pollEvents();
beginFrame(); beginFrame();
client->render(); client->render();
if (client->isConnected()) if (client->isConnected())

View File

@@ -107,4 +107,8 @@ namespace ImGui
} }
*/ */
#ifdef ANDROID
#define IMGUI_IMPL_OPENGL_ES3
#else
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2 #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
#endif

View File

@@ -9,8 +9,6 @@
#include "render/loader/GLLoader.h" #include "render/loader/GLLoader.h"
#include "render/GL.h" #include "render/GL.h"
using namespace gl;
namespace GL { namespace GL {
VertexArray::~VertexArray() { VertexArray::~VertexArray() {

View File

@@ -9,9 +9,7 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "render/loader/stb_image.h" #include "render/loader/stb_image.h"
#include <iostream> #include <iostream>
#include <glbinding/gl/gl.h> #include "render/GL.h"
using namespace gl;
namespace TextureLoader { namespace TextureLoader {
const unsigned int loadGLTexture(const char* fileName) { const unsigned int loadGLTexture(const char* fileName) {

View File

@@ -7,14 +7,11 @@
#include "render/shaders/ShaderProgram.h" #include "render/shaders/ShaderProgram.h"
#include <glbinding/gl/gl.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
using namespace gl;
ShaderProgram::ShaderProgram() : ShaderProgram::ShaderProgram() :
programID(0), vertexShaderID(0), fragmentShaderID(0) { programID(0), vertexShaderID(0), fragmentShaderID(0) {
} }

View File

@@ -12,9 +12,9 @@
#include <SDL2/SDL_video.h> #include <SDL2/SDL_video.h>
#include <iostream> #include <iostream>
#include "game/GameManager.h" #include "game/GameManager.h"
#include "imgui/imgui_impl_sdl.h"
#include "render/Renderer.h" #include "render/Renderer.h"
#include "render/WorldRenderer.h" #include "render/WorldRenderer.h"
#include "../render/gui/imgui/imgui.h"
#define WINDOW_NAME "Tower Defense" #define WINDOW_NAME "Tower Defense"
#define WINDOW_WIDTH 800 #define WINDOW_WIDTH 800
@@ -138,7 +138,6 @@ void destroy() {
void pollEvents() { void pollEvents() {
SDL_Event event; SDL_Event event;
while(SDL_PollEvent(&event)){ while(SDL_PollEvent(&event)){
if(event.type == SDL_WINDOWEVENT){ if(event.type == SDL_WINDOWEVENT){
switch(event.window.event){ switch(event.window.event){
case SDL_WINDOWEVENT_CLOSE:{ case SDL_WINDOWEVENT_CLOSE:{
@@ -155,7 +154,6 @@ void pollEvents() {
break; break;
} }
} }
ImGui_ImplSDL2_ProcessEvent(&event);
} }
} }

View File

@@ -1,8 +1,8 @@
add_rules("mode.debug", "mode.release") add_rules("mode.debug", "mode.release")
--add_requires("glbinding", "glfw", "zlib", "glm") --add_requires("SDL2", "glfw", "zlib", "glm")
target("Tower Defense") target("TowerDefense")
set_kind("binary") set_kind("binary")
add_includedirs("include", "src/render/gui") add_includedirs("include", "src/render/gui")
add_files("src/*.cpp", "src/*/*.cpp", "src/*/*/*.cpp", "src/*/*/*/*.cpp") add_files("src/*.cpp", "src/*/*.cpp", "src/*/*/*.cpp", "src/*/*/*/*.cpp")