From a3eaf78fd39eb75e2b6379076cb83a0b22c55efc Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 5 Oct 2024 18:15:14 -0400 Subject: [PATCH] Brought in FLECS to play with, tomorrow we learn it. --- flecs.wrap | 10 ++++++++++ gui.cpp | 4 ++-- meson.build | 11 +++++++++-- rand.cpp | 10 ++++++++++ rand.hpp | 6 ++++++ scratchpad/flecs.cpp | 39 +++++++++++++++++++++++++++++++++++++++ status.txt | 1 - 7 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 flecs.wrap create mode 100644 rand.cpp create mode 100644 rand.hpp create mode 100644 scratchpad/flecs.cpp diff --git a/flecs.wrap b/flecs.wrap new file mode 100644 index 0000000..ce91fa1 --- /dev/null +++ b/flecs.wrap @@ -0,0 +1,10 @@ +[wrap-git] +url = https://github.com/SanderMertens/flecs.git +revision = v4.0.2 +depth = 1 +method = cmake +# patch_filename = +# patch_hash = + +[provide] +flecs = flecs_dep diff --git a/gui.cpp b/gui.cpp index 3ff318e..aa91313 100644 --- a/gui.cpp +++ b/gui.cpp @@ -65,7 +65,7 @@ GUI::GUI() : $game_map(GAME_MAP_X, GAME_MAP_Y), $map_text.setFont($font); $map_text.setPosition(GAME_MAP_POS,0); $map_text.setCharacterSize(MAP_FONT_SIZE); - $map_text.setFillColor(color(Value::LIGHT_DARK)); + $map_text.setFillColor(color(Value::MID)); $game_map.generate(); $player.location = $game_map.place_entity(0); @@ -174,7 +174,7 @@ void GUI::burn() { std::this_thread::sleep_for(2ms); } - $map_text.setFillColor(color(Value::LIGHT_DARK)); + $map_text.setFillColor(color(Value::MID)); } void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) { diff --git a/meson.build b/meson.build index 9055988..f240aed 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('lcthw-utilities', 'cpp', - default_options: ['cpp_std=c++20']) + default_options: [ 'cpp_std=c++20' ]) catch2 = dependency('catch2-with-main') fmt = dependency('fmt') @@ -8,10 +8,11 @@ ftxui_screen = dependency('ftxui-screen') ftxui_dom = dependency('ftxui-dom') ftxui_component = dependency('ftxui-component') sfml = dependency('sfml') +flecs = dependency('flecs') dependencies = [catch2, fmt, ftxui_screen, ftxui_dom, ftxui_component, - json, sfml] + json, sfml, flecs] runtests = executable('runtests', [ 'dbc.cpp', @@ -34,4 +35,10 @@ roguish = executable('roguish', [ ], dependencies: dependencies) +runtests = executable('flecstest', [ + './scratchpad/flecs.cpp' + ], + dependencies: dependencies) + + test('tests', runtests) diff --git a/rand.cpp b/rand.cpp new file mode 100644 index 0000000..7c7a833 --- /dev/null +++ b/rand.cpp @@ -0,0 +1,10 @@ +#include "rand.hpp" + +std::random_device RNG; +std::mt19937 GENERATOR(RNG()); + +int Random::rand_int(int from, int to) { + std::uniform_int_distribution rand(from, to); + + return rand(GENERATOR); +} diff --git a/rand.hpp b/rand.hpp new file mode 100644 index 0000000..b5e3031 --- /dev/null +++ b/rand.hpp @@ -0,0 +1,6 @@ +#pragma once +#include + +namespace Random { + int rand_int(int from, int to); +} diff --git a/scratchpad/flecs.cpp b/scratchpad/flecs.cpp new file mode 100644 index 0000000..ab20b8e --- /dev/null +++ b/scratchpad/flecs.cpp @@ -0,0 +1,39 @@ +#include +#include + +struct Position { + double x, y; +}; + +struct Velocity { + double x, y; +}; + +int main() { + flecs::world ecs; + + // Create a system for Position, Velocity. Systems are like queries (see + // queries) with a function that can be ran or scheduled (see pipeline). + flecs::system s = ecs.system() + .each([](flecs::entity e, Position& p, const Velocity& v) { + p.x += v.x; + p.y += v.y; + std::cerr << e.name() << ": {" << p.x << ", " << p.y << "}\n"; + }); + + // Create a few test entities for a Position, Velocity query + ecs.entity("e1") + .set({10, 20}) + .set({1, 2}); + + ecs.entity("e2") + .set({10, 20}) + .set({3, 4}); + + // This entity will not match as it does not have Position, Velocity + ecs.entity("e3") + .set({10, 20}); + + // Run the system + s.run(); +} diff --git a/status.txt b/status.txt index 48d4293..6bec22e 100644 --- a/status.txt +++ b/status.txt @@ -5,5 +5,4 @@ TODO: * Write a test that generates a ton of maps then confirms there's a path from one room to every other room? * If the player is trapped in a room the enemy just travles through walls. * Add FLECS. -* Render a different screen for the map to use a different font size. * Lua integration?