Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tox based multiplayer #1

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
# TODO: cache

- name: Install Dependencies
run: sudo apt update && sudo apt -y install libsdl2-dev
run: sudo apt update && sudo apt -y install libsdl2-dev libsodium-dev

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "external/fx_draw"]
path = external/fx_draw
url = https://github.com/Green-Sky/fx_draw.git
[submodule "external/mm_tox"]
path = external/mm_tox
url = https://github.com/Green-Sky/mm_tox.git
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ add_subdirectory("external/MushMachine" EXCLUDE_FROM_ALL)

add_subdirectory("external/fx_draw" EXCLUDE_FROM_ALL)

add_subdirectory("external/mm_tox" EXCLUDE_FROM_ALL)

# Bump up warning levels appropriately for clang, gcc & msvc
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
Expand Down
1 change: 1 addition & 0 deletions external/mm_tox
Submodule mm_tox added at 94e4bc
149 changes: 149 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,152 @@ target_link_libraries(generate_spawn_schedule PUBLIC
common_components_serialize_json
engine # engine_fwd.hpp
)

########################################

add_executable(miniTDTox
./setup_services.hpp
./setup_services_tox.cpp

./screens/main_menu.hpp
./screens/main_menu.cpp
./screens/game_sp.hpp
./screens/game_sp.cpp
./screens/game_mp.hpp
./screens/game_mp.cpp
./screens/debug.hpp
./screens/debug.cpp
./screens/end_screen.hpp
./screens/end_screen.cpp

./services/main_menu.hpp
./services/main_menu.cpp
./services/game_hud.hpp
./services/game_hud.cpp

./services/lobby_host.hpp
./services/lobby_host.cpp
./services/lobby_client.hpp
./services/lobby_client.cpp

./mission.hpp
./mission.cpp

./game_scene.hpp
./game_scene.cpp

./components/game_constants.hpp
./components/enemy.hpp
./components/path_progress.hpp
./components/player_lives.hpp
./components/path.hpp
./components/path.cpp
./components/wave.hpp
./components/spawn_group.hpp
./components/spawn_schedule.hpp
./components/spawn_schedule.cpp
./components/projectile.hpp
./components/damage.hpp
./components/target.hpp
./components/tower_cooldown.hpp
./components/tower_projectile_spawner.hpp
./components/tower_ray.hpp
./components/tower_art.hpp
./components/tower_preview.hpp
./components/camera_trauma.hpp

./systems/successful_enemies.hpp
./systems/successful_enemies.cpp
./systems/progress_enemies.hpp
./systems/progress_enemies.cpp
./systems/progress_to_position.hpp
./systems/progress_to_position.cpp
./systems/spawn_group_update.hpp
./systems/spawn_group_update.cpp
./systems/projectile_velocity.hpp
./systems/projectile_velocity.cpp
./systems/projectile_collision.hpp
./systems/projectile_collision.cpp
./systems/projectile_bounds_check.hpp
./systems/projectile_bounds_check.cpp
./systems/damage.hpp
./systems/damage.cpp
./systems/target_first_best.hpp
./systems/target_first_best.cpp
./systems/target_first.hpp
./systems/target_first.cpp
./systems/tower_cooldown.hpp
./systems/tower_cooldown.cpp
./systems/tower_projectile_spawner.hpp
./systems/tower_projectile_spawner.cpp
./systems/tower_ray_shooter.hpp
./systems/tower_ray_shooter.cpp
./systems/wave_logic.hpp
./systems/wave_logic.cpp
./systems/play_sound_on_damage.hpp
./systems/play_sound_on_damage.cpp
./systems/camera_trauma_update.hpp
./systems/camera_trauma_update.cpp
./systems/player_death.hpp
./systems/player_death.cpp

./entities/enemy.hpp
./entities/enemy.cpp
./entities/spawn_group.hpp
./entities/spawn_group.cpp
./entities/projectile.hpp
./entities/projectile.cpp
./entities/tower.hpp
./entities/tower.cpp

./opengl/render_tasks/map.hpp
./opengl/render_tasks/map.cpp
./opengl/render_tasks/enemies.hpp
./opengl/render_tasks/enemies.cpp
./opengl/render_tasks/projectiles.hpp
./opengl/render_tasks/projectiles.cpp
./opengl/render_tasks/towers.hpp
./opengl/render_tasks/towers.cpp

./setup_meta.hpp
./setup_meta.cpp
./comp_meta.hpp
./comp_meta.cpp

./main_tox.cpp
)

target_link_libraries(miniTDTox PUBLIC
imgui_service
screen_director

opengl_renderer_s
imgui_render_task
#simple_rect_render_task
clear_render_task
bloom
composition_render_task

sound_service
filesystem_soloud_file

imgui_tools
imgui_sound
imgui_opengl_renderer_tools

random

transform_system

simple_velocity_system

fx_draw

mm_logo_screen

mm_tox
mm_tox_imgui
)

########################################

40 changes: 40 additions & 0 deletions src/comp_meta.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "./comp_meta.hpp"

#include <entt/meta/resolve.hpp>
#include <entt/entity/registry.hpp>

#include <nlohmann/json.hpp>

#include <mm/logger.hpp>

namespace mini_td {

void meta_component_emplace(
entt::registry& scene,
const entt::id_type comp_type,
const entt::entity e,
const nlohmann::json& comp_j
) {
using namespace entt::literals;

auto type = entt::resolve(comp_type);
if (!type) {
SPDLOG_ERROR("unregistred component type");
return;
}

auto fn = type.func("component_emplace_json"_hs);
if (!fn) {
SPDLOG_ERROR("component type with missing 'component_emplace_json' function");
return;
}

auto ret = fn.invoke({}, entt::forward_as_meta(scene), entt::forward_as_meta(comp_j), e);
if (!ret) {
SPDLOG_ERROR("'component_emplace_json' function invoke failed");
return;
}
}

} // mini_td

16 changes: 16 additions & 0 deletions src/comp_meta.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <nlohmann/json_fwd.hpp>
#include <entt/entity/fwd.hpp>

namespace mini_td {

void meta_component_emplace(
entt::registry& scene,
const entt::id_type comp_type,
const entt::entity e,
const nlohmann::json& comp_j
);

} // mini_td

4 changes: 4 additions & 0 deletions src/components/enemy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

#include <cstdint>

#include <nlohmann/json.hpp>

namespace mini_td::Components {

struct Enemy {
int64_t level {1};
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Enemy, level)

} // mini_td::Components

4 changes: 4 additions & 0 deletions src/components/path_progress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

#include <cstdint>

#include <nlohmann/json.hpp>

namespace mini_td::Components {

struct PathProgress {
float progress {0.f}; // [0,1]
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(PathProgress, progress)

} // mini_td::Components

118 changes: 118 additions & 0 deletions src/main_tox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include <mm/engine.hpp>
#include <mm/logger.hpp>
#include <spdlog/cfg/env.h>

#include "./setup_services.hpp"

#include <mm/services/sound_service.hpp>
#include <mm/services/opengl_renderer.hpp>
#include <mm/services/screen_director.hpp>
#include <mm/services/imgui_s.hpp>
#include <mm/services/organizer_scene.hpp>
#include "./services/main_menu.hpp"
#include "./services/game_hud.hpp"
#include "./services/lobby_host.hpp"
#include "./services/lobby_client.hpp"

#include <mm/services/imgui_menu_bar.hpp>
#include <mm/services/engine_tools.hpp>
#include <mm/services/opengl_renderer_tools.hpp>
#include <mm/services/screen_director_tools.hpp>
#include <mm/services/scene_tools.hpp>
#include <mm/services/sound_tools.hpp>

#include <mm_tox/services/tox_service.hpp>
#include <mm_tox/services/tox_chat.hpp>
#include <mm_tox/services/tox_net_channeled.hpp>

#include "./setup_meta.hpp"

#include <entt/entity/registry.hpp>

template<>
bool setup_service<MM::Tox::Services::ToxService>(MM::Engine& engine, [[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
auto& tox_service = engine.addService<MM::Tox::Services::ToxService>(engine, "save.tox");

tox_service._app_name = "miniTD";

if (!engine.enableService<MM::Tox::Services::ToxService>()) {
SPDLOG_ERROR("failed to enable service {}", engine.getService<MM::Tox::Services::ToxService>().name());
return false;
}

return true;
}

template<>
bool setup_service<Services::LobbyClient>(MM::Engine& engine, [[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
auto& service = engine.addService<Services::LobbyClient>();

// ???
service.registerHandler<MM::Tox::Services::ToxNetChanneled>("tox", engine);

// dont auto enable
//if (!engine.enableService<Services::LobbyClient>()) {
//SPDLOG_ERROR("failed to enable service {}", ((MM::Services::Service*)engine.tryService<Services::LobbyClient>())->name());
//return false;
//}

return true;
}

bool setup_engine(MM::Engine& engine, int argc, char** argv) {
return setup_engine_t<
MM::Services::SDLService, // enabled by default
MM::Services::FilesystemService, // enabled by default

MM::Services::SoundService,

MM::Services::OpenGLRenderer,

MM::Services::ImGuiService,
MM::Services::ImGuiMenuBar,
MM::Services::ImGuiEngineTools,
MM::Services::ImGuiOpenGLRendererTools,
MM::Services::ImGuiScreenDirectorTools,
MM::Services::ImGuiSceneToolsService,
MM::Services::ImGuiSoundTools,

MM::Services::OrganizerSceneService,

MM::Tox::Services::ToxService,
MM::Tox::Services::ToxChat,
MM::Tox::Services::ToxNetChanneled,

Services::LobbyHost,
Services::LobbyClient,

mini_td::Services::MainMenu,
mini_td::Services::GameHUD,

// sd is allways the last, since it kicks of the first screen
MM::Services::ScreenDirector
>(engine, argc, argv);
}

static MM::Engine engine;

int main(int argc, char** argv) {
spdlog::cfg::load_env_levels();

if (!setup_engine(engine, argc, argv)) {
SPDLOG_ERROR("SETUP FAILED!");
return 1;
}

mini_td::setup_meta_comps();

// queue first screen

engine.run();

#ifndef __EMSCRIPTEN__
engine.cleanup();
#endif

return 0;
}

Loading