Skip to content
Merged
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
9 changes: 5 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CPM_SOURCE_CACHE": "${sourceDir}/out/.cache/cpm/"
"CPM_SOURCE_CACHE": "${sourceDir}/out/.cache/cpm/",
//"ENABLE_SANDBOXES": "ON"
}
},
{
Expand Down Expand Up @@ -101,8 +102,7 @@
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_BUILD_TYPE": "Debug",
"ENABLE_DEVELOPER_MODE": "OFF",
"ENABLE_SANDBOXES": "ON"
"ENABLE_DEVELOPER_MODE": "OFF"
}
},
{
Expand All @@ -114,7 +114,8 @@
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_BUILD_TYPE": "Release",
"ENABLE_DEVELOPER_MODE": "OFF"
"ENABLE_DEVELOPER_MODE": "OFF",

}
},
{
Expand Down
12 changes: 11 additions & 1 deletion apps/asteroids/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ target_link_libraries(${PROJECT_NAME}
pgEngine::pgEngine
pgGame::pgGame
soundEngine::soundEngine
pybind11::embed
pybind11::pybind11
pybind11::headers

pgf::pgf
EnTT::EnTT
INTERFACE
pgFoundation::pgFoundation

)
target_include_directories(${PROJECT_NAME}
PRIVATE
Expand All @@ -30,5 +34,11 @@ target_include_directories(${PROJECT_NAME}
if (ENABLE_COVERAGE)
enable_coverage(${PROJECT_NAME})
endif()

install(DIRECTORY
data/
DESTINATION
data
COMPONENT
${RUNTIME_COMPONENT}
)
install(TARGETS ${PROJECT_NAME})
1 change: 1 addition & 0 deletions apps/asteroids/data/scripts/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello")
6 changes: 5 additions & 1 deletion apps/asteroids/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <systems/Player.h>
#include <systems/RenderSystem.hpp>
#include <systems/SoundSystem.hpp>
#include <systems/ScriptSystem.hpp>

#include <pgGame/events/GameEvents.hpp>
#include <pgGame/systems/SystemsRegistry.hpp>
Expand All @@ -28,6 +29,8 @@ try
pg::game::SystemsFactory::registerSystem<asteroids::RenderSystem>("renderSystem");
pg::game::SystemsFactory::registerSystem<asteroids::DynamicsSystem>("dynamicsSystem");
pg::game::SystemsFactory::registerSystem<asteroids::SoundSystem>("soundSystem");
pg::game::SystemsFactory::registerSystem<asteroids::ScriptSystem>("scriptSystem");

game.createScene({.scene_id = "start",
.systems{"lasers",
"player",
Expand All @@ -36,7 +39,8 @@ try
"collisions",
"renderSystem",
"dynamicsSystem",
"soundSystem"}});
"soundSystem",
"scriptSystem"}});
game.switchScene("start");
// send start event
game.getGlobalDispatcher().enqueue<pg::game::events::PlayPauseEvent>(
Expand Down
9 changes: 9 additions & 0 deletions apps/asteroids/scripting/ScriptBinding.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <pybind11/embed.h>

Check notice on line 1 in apps/asteroids/scripting/ScriptBinding.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on apps/asteroids/scripting/ScriptBinding.cpp

File apps/asteroids/scripting/ScriptBinding.cpp does not conform to Custom style guidelines. (lines 8)

namespace py = pybind11;

// embedded module: mymodule
PYBIND11_EMBEDDED_MODULE(mymodule, m)
{
m.def("add", [](int a, int b) { return a + b; }, "A function that adds two numbers");
}
29 changes: 29 additions & 0 deletions apps/asteroids/systems/ScriptSystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include <entt/entt.hpp>
#include <pgGame/systems/SystemInterface.hpp>
#include <pgEngine/scripting/PythonScripter.hpp>

namespace asteroids {

using entt::literals::operator""_hs;

class ScriptSystem : public pg::game::SystemInterface
{
public:
using SystemInterface::SystemInterface;

virtual ~ScriptSystem() = default;

void setup(std::string_view scene_id) override
{
_scripter = std::make_unique<pg::scripting::PythonScripter>(
pg::scripting::PythonScripter::scriptFromFile("../data/scripts/test.py"));
_scripter->addModule("mymodule");
}

void handle(const pg::FrameStamp& frameStamp) override { _scripter->run(); }

private:
std::unique_ptr<pg::scripting::PythonScripter> _scripter;
};
} // namespace asteroids
10 changes: 7 additions & 3 deletions apps/galaxy/Galaxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <systems/UpdateCurrentSystem.hpp>
#include <scenes/SystemScene.hpp>

#include <systems/EventLoggingSystem.hpp>

#include <systems/DroneSystem.hpp>
#include <systems/LifetimeSystem.hpp>
#include <systems/BehaviorSystem.hpp>
Expand Down Expand Up @@ -38,13 +40,13 @@ void galaxy::GalacticCore::setup()
// e.g. sounds, markov-chains, etc
// we also need some loader abstraction/way to report progress -> LoaderProgressInterface

game->getConfig().addPerSceneConfig<galaxy::SceneSoundScape>(
game->getGenericConfig().addPerContextConfig<galaxy::SceneSoundScape>(
"mainMenu",
"soundScape",
{.background_music{.music_list{{"data/music/dead-space-style-ambient-music-184793.mp3"}}},
.event_sounds = {event_sound_cfg}});

game->getConfig().addPerSceneConfig<galaxy::SceneSoundScape>(
game->getGenericConfig().addPerContextConfig<galaxy::SceneSoundScape>(
"galaxy",
"soundScape",
// {.background_music{.music_list{{"data/music/a-meditation-through-time-amp-space-11947.mp3"}}},
Expand Down Expand Up @@ -72,6 +74,7 @@ void galaxy::GalacticCore::setup()
pg::game::SystemsFactory::registerSystem<galaxy::LifetimeSystem>("lifeTimeSystem");
pg::game::SystemsFactory::registerSystem<galaxy::BehaviorSystem>("behaviorSystem");
pg::game::SystemsFactory::registerSystem<galaxy::StatsSystem>("statsSystem");
pg::game::SystemsFactory::registerSystem<galaxy::EventLoggingSystem>("eventLoggingSystem");

// scenes
game->createScene<galaxy::MainMenuScene>(
Expand All @@ -87,7 +90,8 @@ void galaxy::GalacticCore::setup()
"droneSystem",
"lifeTimeSystem",
"behaviorSystem",
"statsSystem"}});
"statsSystem",
"eventLoggingSystem"}});

game->createScene<galaxy::SystemScene>(
{.scene_id = "system", .systems = {"soundSystem", "systemRenderSystem", "guiSystem", "updateCurrentSystem"}});
Expand Down
4 changes: 3 additions & 1 deletion apps/galaxy/behaviors/FindNextSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class FindNextSystem : public BehaviorActionNode
sys_faction = faction;
starsystem.colonizationStatus = galaxy::ColonizationStatus::Planned;
game().getDispatcher().enqueue<galaxy::events::SystemOwnerChangedEvent>(
{.system_entity = drone.targetId, .owner_faction = faction.name});
{.system_entity = drone.targetId,
.owner_faction = faction.name,
.status = galaxy::ColonizationStatus::Planned});

return BT::NodeStatus::SUCCESS;
}
Expand Down
15 changes: 11 additions & 4 deletions apps/galaxy/behaviors/GetTargetsAvailable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,23 @@ class GetTargetsAvailable : public BehaviorActionNode
};

const auto& drone_conf = galaxy::getFactionConfig(game(), faction.name).droneParams;
const auto range = pg::fVec2{drone_conf.max_range * 0.5f, drone_conf.max_range * 0.5f};
//clang-format off
const auto range = 0.5f * pg::fVec2{drone_conf.max_range, drone_conf.max_range};
// TODO: assert result.data is always of size 1

auto result_systems = quadtree.rangeQuery(pg::fBox::fromMidpoint(transform.pos, range)) |
std::views::filter(filterOutOwnSystem) | std::views::filter(onlyUnexplored) |
// take only .data member of the result
std::views::transform([](auto result) { return (result.data.front()); }) |
std::ranges::to<std::deque<entt::entity>>();
//clang-format on
if (result_systems.empty()) { return BT::NodeStatus::FAILURE; }
if (result_systems.empty())
{
// log
// TODO: event
spdlog::warn("Couldn't find a target system for Drone {} within {} ly",
config().blackboard->get<std::string>("ID"),
drone_conf.max_range);
return BT::NodeStatus::FAILURE;
}
else
{
std::string id = config().blackboard->get<std::string>("ID");
Expand Down
2 changes: 1 addition & 1 deletion apps/galaxy/behaviors/MakeDrone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MakeDrone : public BehaviorActionNode
auto behavior_tree = ctx()->setupTree("Drone", entity, blackboard);

pg::game::addComponent<galaxy::Behavior>(
game.getGlobalRegistry(), entity, galaxy::Behavior{std::move(behavior_tree)});
game.getGlobalRegistry(), entity, galaxy::Behavior{std::move(behavior_tree), {}});

game.getDispatcher().trigger<galaxy::events::DroneCreatedEvent>({.entity = entity, .transform = transform.pos});
return BT::NodeStatus::SUCCESS;
Expand Down
4 changes: 3 additions & 1 deletion apps/galaxy/components/Behavior.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once
#include "behaviortree_cpp/bt_factory.h"
#include "behaviortree_cpp/loggers/groot2_publisher.h"

namespace galaxy {

struct Behavior
{
BT::Tree tree;
BT::Tree tree;
std::shared_ptr<BT::Groot2Publisher> publisher;
};

} // namespace galaxy
14 changes: 13 additions & 1 deletion apps/galaxy/events/DroneEvents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <pgEngine/math/Transform.hpp>
#include <pgFoundation/NamedTypeRegistrar.hpp>

#include <components/Faction.hpp>

namespace galaxy::events {
struct FactionActivatedEvent : pgf::TypeRegistrar<FactionActivatedEvent, "FactionCreatedEvent">
{
Expand All @@ -13,12 +15,22 @@ struct FactionActivatedEvent : pgf::TypeRegistrar<FactionActivatedEvent, "Factio
struct DroneCreatedEvent : pgf::TypeRegistrar<DroneCreatedEvent, "DroneCreatedEvent">
{
entt::entity entity;
galaxy::Faction faction;
pg::Transform2D transform;
};

struct DroneFailedEvent : pgf::TypeRegistrar<DroneFailedEvent, "DroneFailedEvent">
{
entt::entity entity;
entt::entity entity;
galaxy::Faction faction;
std::string reason;
};

struct DroneDestroyedEvent : pgf::TypeRegistrar<DroneDestroyedEvent, "DroneDestroyedEvent">
{
entt::entity entity;
galaxy::Faction faction;
std::string reason;
};

// NOT YET USED- currently using DroneFailedEvent
Expand Down
8 changes: 6 additions & 2 deletions apps/galaxy/events/SystemEvents.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#pragma once
#include <entt/entt.hpp>
#include <pgFoundation/NamedTypeRegistrar.hpp>
#include <components/StarSystem.hpp>

namespace galaxy::events {

struct SystemOwnerChangedEvent : pgf::TypeRegistrar<SystemOwnerChangedEvent, "SystemOwnerChangedEvent">
{
entt::entity system_entity;
std::string owner_faction;
entt::entity system_entity;
std::string previous_owner;
std::string owner_faction;
galaxy::ColonizationStatus status;
galaxy::ColonizationStatus old_status;
};

} // namespace galaxy::events
23 changes: 23 additions & 0 deletions apps/galaxy/gui/menus/OptionsMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <pgEngine/core/Gui.hpp>
#include <pgEngine/gui/GuiElements.hpp>
#include <pgEngine/gui/ImGuiScopedWrappers.hpp>
#include <pgEngine/math/Random.hpp>

#include <string>
#include <functional>
Expand Down Expand Up @@ -88,21 +89,43 @@ static bool optionsMenu(galaxy::config::Galaxy& galaxy_config,
{
ImGui::SeparatorText("View");
// slider for opacity

ImGui::PushItemWidth(-1); // Use -1 to make it fill the available width
if (ImGui::SliderFloat("Background opacity", &galaxy_config.background.opacity, 0.0f, 1.0f))
{
changes = true;
}
ImGui::PopItemWidth();
{
// this needs to span only the width of the previous element
if (ImGui::Button("Generate Seed"))
{
galaxy_config.creation.stars_seed = pg::randomBetween(0u, std::numeric_limits<uint32_t>::max());
changes = true;
}
ImGui::SameLine();
ImGui::PushItemWidth(-1);
// seed
if (ImGui::InputScalar("Galaxy Seed", ImGuiDataType_U32, &galaxy_config.creation.stars_seed))
{
changes = true;
}
ImGui::PopItemWidth();
}

// number of stars as small (1000), medium (5000), large (15000)
auto current_item = getIndexFromStarCount(galaxy_config.creation.num_stars);
// string from names
// const char* data = galaxy_star_sizes.data();
// horizontal line with name
ImGui::SeparatorText("Galaxy");

if (ImGui::Combo("Number of stars", &current_item, getNullSeparatedNames().data()))
{
changes = true;
galaxy_config.creation.num_stars = galaxy_star_sizes_counts.at(current_item);
}

ImGui::SameLine();
// star count as text
ImGui::Text(": %d", galaxy_config.creation.num_stars);
Expand Down
1 change: 1 addition & 0 deletions apps/galaxy/scenes/GalaxyScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class GalaxyScene : public pg::game::Scene

void setupStars()
{
// TODO: the length/and the quadtree are dependent on the size of the galaxy
galaxyQuadtree = std::make_unique<pg::Quadtree<entt::entity>>(pg::fBox{{-750, -750}, {1500, 1500}});
std::normal_distribution<float> d(0.0f, 200.0f);

Expand Down
13 changes: 11 additions & 2 deletions apps/galaxy/systems/BehaviorSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ class BehaviorSystem : public pg::game::SystemInterface
public:
using SystemInterface::SystemInterface;

void setup(std::string_view /*scene_id*/) {}
void setup(std::string_view /*scene_id*/) { auto view = _game.getGlobalRegistry().view<galaxy::Behavior>(); }

void handle(const pg::FrameStamp&)
{
auto view = _game.getGlobalRegistry().view<galaxy::Behavior>();

for (auto entity : view)
{
auto& behavior = view.get<galaxy::Behavior>(entity);
auto res = behavior.tree.tickExactlyOnce();

static bool once = false;
if (!once)
{
once = true;
behavior.publisher = std::make_shared<BT::Groot2Publisher>(behavior.tree);
}
auto res = behavior.tree.tickExactlyOnce();

if (res == BT::NodeStatus::SUCCESS || res == BT::NodeStatus::FAILURE)
{
_game.getGlobalRegistry().remove<galaxy::Behavior>(entity);
Expand Down
Loading
Loading