Cleaned up all the places I was doing push_back({constructorvar1, constructorvar2}) to use emplace_back(constructorvar1, constructorvar2) every other use should be only for actually copying.

main
Zed A. Shaw 2 weeks ago
parent 18a5f6bfa9
commit 3344181a47
  1. 22
      levelmanager.cpp
  2. 8
      levelmanager.hpp
  3. 2
      lights.cpp
  4. 3
      map.cpp
  5. 4
      pathing.cpp
  6. 2
      worldbuilder.cpp

@ -10,22 +10,20 @@ LevelManager::LevelManager() {
} }
size_t LevelManager::create_level() { size_t LevelManager::create_level() {
GameLevel level; auto world = make_shared<DinkyECS::World>();
level.index = $levels.size(); save::load_configs(*world);
level.world = make_shared<DinkyECS::World>(); auto map = make_shared<Map>(GAME_MAP_X, GAME_MAP_Y);
save::load_configs(*level.world); WorldBuilder builder(*map);
builder.generate(*world);
level.map = make_shared<Map>(GAME_MAP_X, GAME_MAP_Y); size_t index = $levels.size();
WorldBuilder builder(*level.map);
builder.generate(*level.world);
level.lights = make_shared<LightRender>(level.map->width(), level.map->height()); $levels.emplace_back(index, map, world,
make_shared<LightRender>(map->width(), map->height()));
$levels.push_back(level); dbc::check(index == $levels.size() - 1, "Level index is not the same as $levels.size() - 1, off by one error");
return index;
dbc::check(level.index == $levels.size() - 1, "Level index is not the same as $levels.size() - 1, off by one error");
return level.index;
} }
GameLevel &LevelManager::next() { GameLevel &LevelManager::next() {

@ -8,10 +8,10 @@
struct GameLevel { struct GameLevel {
size_t index = 0; size_t index;
std::shared_ptr<Map> map = nullptr; std::shared_ptr<Map> map;
std::shared_ptr<DinkyECS::World> world = nullptr; std::shared_ptr<DinkyECS::World> world;
std::shared_ptr<lighting::LightRender> lights = nullptr; std::shared_ptr<lighting::LightRender> lights;
}; };
class LevelManager { class LevelManager {

@ -9,7 +9,7 @@ namespace lighting {
for(matrix::box it{$lightmap, at.x, at.y, (size_t)floor(source.radius)}; it.next();) { for(matrix::box it{$lightmap, at.x, at.y, (size_t)floor(source.radius)}; it.next();) {
if($paths.$paths[it.y][it.x] != WALL_PATH_LIMIT) { if($paths.$paths[it.y][it.x] != WALL_PATH_LIMIT) {
$lightmap[it.y][it.x] = light_level(source.strength, it.distance(), it.x, it.y); $lightmap[it.y][it.x] = light_level(source.strength, it.distance(), it.x, it.y);
has_light.push_back({it.x, it.y}); has_light.emplace_back(it.x, it.y);
} }
} }
} }

@ -209,9 +209,6 @@ void Map::expand() {
} }
void Map::add_room(Room &room) { void Map::add_room(Room &room) {
// println(">>ADDING ROOM x/y={},{}; w/h={},{}; map={},{}",
// room.x, room.y, room.width, room.height, $width, $height);
room.x++; room.x++;
room.y++; room.y++;
room.width--; room.width--;

@ -9,7 +9,7 @@ inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t
for(matrix::box it{closed, x, y, 1}; it.next();) { for(matrix::box it{closed, x, y, 1}; it.next();) {
if(closed[it.y][it.x] == 0) { if(closed[it.y][it.x] == 0) {
closed[it.y][it.x] = 1; closed[it.y][it.x] = 1;
neighbors.push_back({.x=it.x, .y=it.y}); neighbors.emplace_back(it.x, it.y);
} }
} }
} }
@ -39,7 +39,7 @@ void Pathing::compute_paths(Matrix &walls) {
if($input[y][x] == 0) { if($input[y][x] == 0) {
$paths[y][x] = 0; $paths[y][x] = 0;
closed[y][x] = 1; closed[y][x] = 1;
starting_pixels.push_back({x,y}); starting_pixels.emplace_back(x,y);
} }
} }

@ -286,7 +286,7 @@ inline bool random_path(Map &map, PointList &holes, Point src, Point target) {
inline void straight_path(Map &map, PointList &holes, Point src, Point target) { inline void straight_path(Map &map, PointList &holes, Point src, Point target) {
for(matrix::line dig{src, target}; dig.next();) { for(matrix::line dig{src, target}; dig.next();) {
holes.push_back({size_t(dig.x), size_t(dig.y)}); holes.emplace_back(size_t(dig.x), size_t(dig.y));
Point expand{(size_t)dig.x+1, (size_t)dig.y}; Point expand{(size_t)dig.x+1, (size_t)dig.y};
if(map.inmap(expand.x, expand.y)) { if(map.inmap(expand.x, expand.y)) {

Loading…
Cancel
Save