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

main
Zed A. Shaw 2 months ago
parent b8a0d9bbd1
commit a3eaf78fd3
  1. 10
      flecs.wrap
  2. 4
      gui.cpp
  3. 9
      meson.build
  4. 10
      rand.cpp
  5. 6
      rand.hpp
  6. 39
      scratchpad/flecs.cpp
  7. 1
      status.txt

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

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

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

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

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

@ -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();
}

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

Loading…
Cancel
Save