Switching to Linux to find a memory bug and I want to keep a record of what caused it.
This commit is contained in:
parent
be3eef7082
commit
e51fb8627c
7 changed files with 23 additions and 42 deletions
|
@ -39,10 +39,12 @@ namespace gui {
|
|||
$gui.set<guecs::Sprite>(button, { sprite_name});
|
||||
}
|
||||
|
||||
void DebugUI::spawn(std::string enemy_key) {
|
||||
auto ent = $level_mgr.spawn_enemy(enemy_key);
|
||||
auto& level = $level_mgr.current();
|
||||
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, ent, {});
|
||||
void DebugUI::spawn(const std::string& enemy_key) {
|
||||
(void)enemy_key;
|
||||
dbc::log("THIS FUNCTION NEEDS A REWRITE");
|
||||
// auto ent = $level_mgr.spawn_enemy(enemy_key);
|
||||
// auto& level = $level_mgr.current();
|
||||
// level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, ent, {});
|
||||
}
|
||||
|
||||
void DebugUI::render(sf::RenderWindow& window) {
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace gui {
|
|||
void render(sf::RenderWindow& window);
|
||||
bool mouse(float x, float y, bool hover);
|
||||
void debug();
|
||||
void spawn(std::string enemy_key);
|
||||
void spawn(const std::string& enemy_key);
|
||||
void add_spawn_button(std::string enemy_key, std::string sprite_name, std::string region);
|
||||
|
||||
Stats::TimeBullshit time_start();
|
||||
|
|
|
@ -60,34 +60,10 @@ shared_ptr<gui::BossFightUI> LevelManager::create_bossfight(shared_ptr<DinkyECS:
|
|||
return make_shared<gui::BossFightUI>(world, boss_id);
|
||||
}
|
||||
|
||||
DinkyECS::Entity LevelManager::spawn_enemy(std::string named) {
|
||||
DinkyECS::Entity LevelManager::spawn_enemy(const std::string& named) {
|
||||
(void)named;
|
||||
auto& level = current();
|
||||
|
||||
auto &config = level.world->get_the<GameConfig>();
|
||||
auto entity_data = config.enemies[named];
|
||||
|
||||
WorldBuilder builder(*level.map);
|
||||
|
||||
auto entity_id = builder.configure_entity_in_room(*level.world, entity_data, 0);
|
||||
|
||||
auto& entity_pos = level.world->get<Position>(entity_id);
|
||||
auto player_pos = level.world->get<Position>(level.player);
|
||||
|
||||
for(matrix::box it{level.map->walls(),
|
||||
player_pos.location.x, player_pos.location.y, 1}; it.next();)
|
||||
{
|
||||
if(level.map->can_move({it.x, it.y})) {
|
||||
// this is where we move it closer to the player
|
||||
entity_pos.location.x = it.x;
|
||||
entity_pos.location.y = it.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
level.collision->insert(entity_pos.location, entity_id, true);
|
||||
|
||||
return entity_id;
|
||||
dbc::log("THIS FUNCTION NEEDS A REWRITE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
|
||||
|
@ -96,7 +72,9 @@ size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
|
|||
auto scaling = scale_level();
|
||||
|
||||
auto map = make_shared<Map>(scaling.map_width, scaling.map_height);
|
||||
WorldBuilder builder(*map);
|
||||
auto collision = std::make_shared<SpatialMap>();
|
||||
|
||||
WorldBuilder builder(*map, *collision);
|
||||
builder.generate(*world);
|
||||
|
||||
size_t index = $levels.size();
|
||||
|
@ -104,7 +82,7 @@ size_t LevelManager::create_level(shared_ptr<DinkyECS::World> prev_world) {
|
|||
auto player = world->get_the<Player>();
|
||||
|
||||
$levels.emplace_back(index, player.entity, map, world,
|
||||
make_shared<LightRender>(map->tiles()), builder.$collision);
|
||||
make_shared<LightRender>(map->tiles()), collision);
|
||||
|
||||
dbc::check(index == $levels.size() - 1, "Level index is not the same as $levels.size() - 1, off by one error");
|
||||
return index;
|
||||
|
|
|
@ -41,5 +41,5 @@ class LevelManager {
|
|||
GameLevel &get(size_t index);
|
||||
LevelScaling scale_level();
|
||||
|
||||
DinkyECS::Entity spawn_enemy(std::string named);
|
||||
DinkyECS::Entity spawn_enemy(const std::string& named);
|
||||
};
|
||||
|
|
|
@ -437,8 +437,9 @@ void Raycaster::update_level(GameLevel level) {
|
|||
|
||||
$level.world->query<components::Sprite>([&](const auto ent, auto& sprite) {
|
||||
// player doesn't need a sprite
|
||||
if($level.player == ent) return;
|
||||
update_sprite(ent, sprite);
|
||||
if($level.player != ent) {
|
||||
update_sprite(ent, sprite);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ bool WorldBuilder::find_open_spot(Point& pos_out) {
|
|||
for(matrix::rando_box it{$map.walls(), pos_out.x, pos_out.y, i}; it.next();) {
|
||||
Point test{size_t(it.x), size_t(it.y)};
|
||||
|
||||
if($map.can_move(test) && !$collision->occupied(test)) {
|
||||
if($map.can_move(test) && !$collision.occupied(test)) {
|
||||
pos_out = test;
|
||||
return true;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ DinkyECS::Entity WorldBuilder::configure_entity_in_map(DinkyECS::World &world, j
|
|||
components::configure_entity(world, item, entity_data["components"]);
|
||||
}
|
||||
|
||||
$collision->insert(pos, item, has_collision);
|
||||
$collision.insert(pos, item, has_collision);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
class WorldBuilder {
|
||||
public:
|
||||
Map& $map;
|
||||
std::shared_ptr<SpatialMap> $collision;
|
||||
SpatialMap& $collision;
|
||||
|
||||
WorldBuilder(Map &map) :
|
||||
WorldBuilder(Map &map, SpatialMap& collision) :
|
||||
$map(map),
|
||||
$collision(std::make_shared<SpatialMap>())
|
||||
$collision(collision)
|
||||
{ }
|
||||
|
||||
void generate_map();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue