Brought in FLECS to play with, tomorrow we learn it.

This commit is contained in:
Zed A. Shaw 2024-10-05 18:15:14 -04:00
parent b8a0d9bbd1
commit a3eaf78fd3
7 changed files with 76 additions and 5 deletions

10
flecs.wrap Normal file
View file

@ -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

View file

@ -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) {

View file

@ -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)

10
rand.cpp Normal file
View file

@ -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<int> rand(from, to);
return rand(GENERATOR);
}

6
rand.hpp Normal file
View file

@ -0,0 +1,6 @@
#pragma once
#include <random>
namespace Random {
int rand_int(int from, int to);
}

39
scratchpad/flecs.cpp Normal file
View file

@ -0,0 +1,39 @@
#include <flecs.h>
#include <iostream>
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<Position, const Velocity>()
.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<Position>({10, 20})
.set<Velocity>({1, 2});
ecs.entity("e2")
.set<Position>({10, 20})
.set<Velocity>({3, 4});
// This entity will not match as it does not have Position, Velocity
ecs.entity("e3")
.set<Position>({10, 20});
// Run the system
s.run();
}

View file

@ -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?