Fixed a bunch of random little bugs everywhere.
This commit is contained in:
parent
f946d46936
commit
6b3ce5eb3d
9 changed files with 64 additions and 38 deletions
|
@ -9,3 +9,6 @@ const int WALL_VALUE = 1;
|
||||||
const int SPACE_VALUE = 0;
|
const int SPACE_VALUE = 0;
|
||||||
const int WALL_PATH_LIMIT = 1000;
|
const int WALL_PATH_LIMIT = 1000;
|
||||||
const int WALL_LIGHT_LEVEL = 3;
|
const int WALL_LIGHT_LEVEL = 3;
|
||||||
|
const int WORLDBUILD_DIVISION = 4;
|
||||||
|
const int WORLDBUILD_SHRINK = 2;
|
||||||
|
const int WORLDBUILD_MAX_PATH = 200;
|
||||||
|
|
21
gui.cpp
21
gui.cpp
|
@ -168,6 +168,10 @@ void GUI::handle_world_events() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GUI::shutdown() {
|
||||||
|
$renderer.close();
|
||||||
|
}
|
||||||
|
|
||||||
bool GUI::handle_ui_events() {
|
bool GUI::handle_ui_events() {
|
||||||
using KB = sf::Keyboard;
|
using KB = sf::Keyboard;
|
||||||
using MOUSE = sf::Mouse;
|
using MOUSE = sf::Mouse;
|
||||||
|
@ -179,8 +183,7 @@ bool GUI::handle_ui_events() {
|
||||||
|
|
||||||
while($renderer.poll_event(event)) {
|
while($renderer.poll_event(event)) {
|
||||||
if(event.type == sf::Event::Closed) {
|
if(event.type == sf::Event::Closed) {
|
||||||
// BUG: This should call a GUI::shutdown so I can do saves and stuff.
|
shutdown();
|
||||||
$renderer.close();
|
|
||||||
} else if(event.type == sf::Event::KeyPressed) {
|
} else if(event.type == sf::Event::KeyPressed) {
|
||||||
|
|
||||||
if(KB::isKeyPressed(KB::Left)) {
|
if(KB::isKeyPressed(KB::Left)) {
|
||||||
|
@ -207,14 +210,12 @@ bool GUI::handle_ui_events() {
|
||||||
$status_ui.$component->OnEvent(Event::Return);
|
$status_ui.$component->OnEvent(Event::Return);
|
||||||
}
|
}
|
||||||
} else if(MOUSE::isButtonPressed(MOUSE::Left)) {
|
} else if(MOUSE::isButtonPressed(MOUSE::Left)) {
|
||||||
sf::Vector2i pos = MOUSE::getPosition($renderer.$window);
|
Point pos = $renderer.mouse_position();
|
||||||
Mouse mev;
|
Mouse mev{
|
||||||
mev.button = Mouse::Button::Left,
|
.button=Mouse::Button::Left,
|
||||||
// BUG: renderer should have a function that handles mouse coordinates
|
.x=int(pos.x), .y=int(pos.y)
|
||||||
// BUG: optionally maybe have it in panel? Seems to work though.
|
};
|
||||||
mev.x=pos.x / $renderer.$ui_bounds.width;
|
|
||||||
mev.y=pos.y / $renderer.$ui_bounds.height;
|
|
||||||
// BUG: maybe also handle mouse motion events?
|
|
||||||
$status_ui.$component->OnEvent(Event::Mouse("", mev));
|
$status_ui.$component->OnEvent(Event::Mouse("", mev));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
gui.hpp
2
gui.hpp
|
@ -68,6 +68,6 @@ public:
|
||||||
void run_systems();
|
void run_systems();
|
||||||
void save_world();
|
void save_world();
|
||||||
void shake();
|
void shake();
|
||||||
|
void shutdown();
|
||||||
int main(bool run_once=false);
|
int main(bool run_once=false);
|
||||||
};
|
};
|
||||||
|
|
17
pathing.cpp
17
pathing.cpp
|
@ -5,9 +5,7 @@
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x) {
|
inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x, size_t w, size_t h) {
|
||||||
size_t h = closed.size();
|
|
||||||
size_t w = closed[0].size();
|
|
||||||
vector<size_t> rows{y - 1, y, y + 1};
|
vector<size_t> rows{y - 1, y, y + 1};
|
||||||
vector<size_t> cols{x - 1, x, x + 1};
|
vector<size_t> cols{x - 1, x, x + 1};
|
||||||
|
|
||||||
|
@ -17,7 +15,6 @@ inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t
|
||||||
(0 <= col && col < w) &&
|
(0 <= col && col < w) &&
|
||||||
closed[row][col] == 0)
|
closed[row][col] == 0)
|
||||||
{
|
{
|
||||||
// BUG: maybe value here?
|
|
||||||
closed[row][col] = 1;
|
closed[row][col] = 1;
|
||||||
neighbors.push_back({.x=col, .y=row});
|
neighbors.push_back({.x=col, .y=row});
|
||||||
}
|
}
|
||||||
|
@ -39,18 +36,18 @@ void Pathing::compute_paths(Matrix &walls) {
|
||||||
|
|
||||||
// First pass: Add starting pixels and put them in closed
|
// First pass: Add starting pixels and put them in closed
|
||||||
for(size_t counter = 0; counter < $height * $width; counter++) {
|
for(size_t counter = 0; counter < $height * $width; counter++) {
|
||||||
size_t x = counter % $width; // BUG: is this right?
|
size_t x = counter % $width;
|
||||||
size_t y = counter / $width;
|
size_t y = counter / $width;
|
||||||
if($input[y][x] == 0) {
|
if($input[y][x] == 0) {
|
||||||
$paths[y][x] = 0;
|
$paths[y][x] = 0;
|
||||||
closed[y][x] = 1; // BUG: value here?
|
closed[y][x] = 1;
|
||||||
starting_pixels.push_back({x,y});
|
starting_pixels.push_back({x,y});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second pass: Add border to open
|
// Second pass: Add border to open
|
||||||
for(auto sp : starting_pixels) {
|
for(auto sp : starting_pixels) {
|
||||||
add_neighbors(open_pixels, closed, sp.y, sp.x);
|
add_neighbors(open_pixels, closed, sp.y, sp.x, $width, $height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Third pass: Iterate filling in the open list
|
// Third pass: Iterate filling in the open list
|
||||||
|
@ -59,7 +56,7 @@ void Pathing::compute_paths(Matrix &walls) {
|
||||||
PointList next_open;
|
PointList next_open;
|
||||||
for(auto sp : open_pixels) {
|
for(auto sp : open_pixels) {
|
||||||
$paths[sp.y][sp.x] = counter;
|
$paths[sp.y][sp.x] = counter;
|
||||||
add_neighbors(next_open, closed, sp.y, sp.x);
|
add_neighbors(next_open, closed, sp.y, sp.x, $width, $height);
|
||||||
}
|
}
|
||||||
open_pixels = next_open;
|
open_pixels = next_open;
|
||||||
}
|
}
|
||||||
|
@ -71,8 +68,8 @@ void Pathing::compute_paths(Matrix &walls) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pathing::set_target(const Point &at, int value) {
|
void Pathing::set_target(const Point &at, int value) {
|
||||||
// BUG: not using value here but it can be < 0 for deeper slopes
|
// FUTURE: I'll eventually allow setting this to negatives for priority
|
||||||
$input[at.y][at.x] = 0;
|
$input[at.y][at.x] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pathing::clear_target(const Point &at) {
|
void Pathing::clear_target(const Point &at) {
|
||||||
|
|
10
render.cpp
10
render.cpp
|
@ -83,7 +83,6 @@ void SFMLRender::render_grid(const std::wstring &text, sf::Color default_fg, sf:
|
||||||
float height_delta = 0;
|
float height_delta = 0;
|
||||||
sf::Sprite &sprite = get_text_sprite(last_tile);
|
sf::Sprite &sprite = get_text_sprite(last_tile);
|
||||||
const float start_x = x;
|
const float start_x = x;
|
||||||
// BUG: get default_fg from panel too
|
|
||||||
sf::Color cur_fg = default_fg;
|
sf::Color cur_fg = default_fg;
|
||||||
sf::Color cur_bg = default_bg;
|
sf::Color cur_bg = default_bg;
|
||||||
|
|
||||||
|
@ -230,6 +229,15 @@ void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Point SFMLRender::mouse_position() {
|
||||||
|
sf::Vector2i pos = sf::Mouse::getPosition($window);
|
||||||
|
|
||||||
|
return {
|
||||||
|
size_t(pos.x / $ui_bounds.width),
|
||||||
|
size_t(pos.y / $ui_bounds.height)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void SFMLRender::init_terminal() {
|
void SFMLRender::init_terminal() {
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
_setmode(_fileno(stdout), _O_U16TEXT);
|
_setmode(_fileno(stdout), _O_U16TEXT);
|
||||||
|
|
|
@ -67,5 +67,6 @@ struct SFMLRender {
|
||||||
int font_size() { return $map_font_size; }
|
int font_size() { return $map_font_size; }
|
||||||
void clear() { $window.clear(); }
|
void clear() { $window.clear(); }
|
||||||
void display() { $window.display(); }
|
void display() { $window.display(); }
|
||||||
|
Point mouse_position();
|
||||||
static void init_terminal();
|
static void init_terminal();
|
||||||
};
|
};
|
||||||
|
|
10
status.txt
10
status.txt
|
@ -1,11 +1,6 @@
|
||||||
TODAY'S GOAL:
|
TODAY'S GOAL:
|
||||||
* Pathing::compute_paths can take a starting level to implement lower directions, or possibly setting a value lower?
|
|
||||||
|
|
||||||
* Fix " room should always be found"
|
* Fix " room should always be found"
|
||||||
|
|
||||||
* Pathing::set_target isn't using value, but that implements the above.
|
|
||||||
https://www.roguebasin.com/index.php/Dijkstra_Maps_Visualized
|
|
||||||
|
|
||||||
* Fix BUG markers as much as possible.
|
* Fix BUG markers as much as possible.
|
||||||
|
|
||||||
* Make room generation have "texture" or state like mossy, flooded, etc.
|
* Make room generation have "texture" or state like mossy, flooded, etc.
|
||||||
|
@ -13,6 +8,10 @@ https://www.roguebasin.com/index.php/Dijkstra_Maps_Visualized
|
||||||
TODO:
|
TODO:
|
||||||
* Lua integration
|
* Lua integration
|
||||||
|
|
||||||
|
* Save file needs work, it's not saving gold and lights.
|
||||||
|
|
||||||
|
* Move all keyboard and mouse events into SFMLRender so it's completely abstracted away and can be changed to a different backend if I want.
|
||||||
|
|
||||||
* When fighting two enemies with lots of attacks it crashes because one dies and isn't there. Test by making enemies immortal.
|
* When fighting two enemies with lots of attacks it crashes because one dies and isn't there. Test by making enemies immortal.
|
||||||
* LightRender can just use the Dijkstra map paths to calculate light strenght from the point rather than doing the box thing.
|
* LightRender can just use the Dijkstra map paths to calculate light strenght from the point rather than doing the box thing.
|
||||||
* $paths.$paths is annoying.
|
* $paths.$paths is annoying.
|
||||||
|
@ -22,7 +21,6 @@ TODO:
|
||||||
* Think up an enemy system.
|
* Think up an enemy system.
|
||||||
* Write a method for renderer that can translate coordinates.
|
* Write a method for renderer that can translate coordinates.
|
||||||
* Can std::any be defaulted to a noop in the events?
|
* Can std::any be defaulted to a noop in the events?
|
||||||
* Save file isn't saving gold.
|
|
||||||
* Inventory needs to be better, but need some kinds of "weapons" or other loot to get and not just gold.
|
* Inventory needs to be better, but need some kinds of "weapons" or other loot to get and not just gold.
|
||||||
* Create a few more enemy types to fight.
|
* Create a few more enemy types to fight.
|
||||||
* Devise a more complete map/world generator that can use the loot and enemies better.
|
* Devise a more complete map/world generator that can use the loot and enemies better.
|
||||||
|
|
|
@ -36,4 +36,25 @@
|
||||||
[1, 0, 1000, 2],
|
[1, 0, 1000, 2],
|
||||||
[1, 1, 1000, 3]
|
[1, 1, 1000, 3]
|
||||||
]
|
]
|
||||||
}]
|
},
|
||||||
|
{
|
||||||
|
"input": [
|
||||||
|
[1, 1, 1, 0],
|
||||||
|
[1, 1, 1, 1],
|
||||||
|
[1, 0, 1, 1],
|
||||||
|
[1, 1, 1, 1]
|
||||||
|
],
|
||||||
|
"walls": [
|
||||||
|
[0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0],
|
||||||
|
[0, 0, 1, 0],
|
||||||
|
[0, 0, 1, 0]
|
||||||
|
],
|
||||||
|
"expected": [
|
||||||
|
[2, 2, 1, 0],
|
||||||
|
[1, 1, 1, 1],
|
||||||
|
[1, 0, 1000, 2],
|
||||||
|
[1, 1, 1000, 3]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
|
@ -6,8 +6,7 @@ using namespace fmt;
|
||||||
|
|
||||||
inline int make_split(Room &cur, bool horiz) {
|
inline int make_split(Room &cur, bool horiz) {
|
||||||
size_t dimension = horiz ? cur.height : cur.width;
|
size_t dimension = horiz ? cur.height : cur.width;
|
||||||
// BUG: this might be better as a configurable 4 number
|
int min = dimension / WORLDBUILD_DIVISION;
|
||||||
int min = dimension / 4;
|
|
||||||
int max = dimension - min;
|
int max = dimension - min;
|
||||||
|
|
||||||
return Random::uniform<int>(min, max);
|
return Random::uniform<int>(min, max);
|
||||||
|
@ -156,13 +155,11 @@ void WorldBuilder::make_room(size_t origin_x, size_t origin_y, size_t w, size_t
|
||||||
|
|
||||||
void WorldBuilder::place_rooms() {
|
void WorldBuilder::place_rooms() {
|
||||||
for(auto &cur : $map.$rooms) {
|
for(auto &cur : $map.$rooms) {
|
||||||
cur.x += 2;
|
cur.x += WORLDBUILD_SHRINK;
|
||||||
cur.y += 2;
|
cur.y += WORLDBUILD_SHRINK;
|
||||||
cur.width -= 4;
|
cur.width -= WORLDBUILD_SHRINK * 2;
|
||||||
cur.height -= 4;
|
cur.height -= WORLDBUILD_SHRINK * 2;
|
||||||
|
|
||||||
// BUG: should I do this each time I connect rooms
|
|
||||||
// BUG: rather than once when the room is created?
|
|
||||||
add_door(cur);
|
add_door(cur);
|
||||||
make_room(cur.x, cur.y, cur.width, cur.height);
|
make_room(cur.x, cur.y, cur.width, cur.height);
|
||||||
}
|
}
|
||||||
|
@ -187,7 +184,7 @@ bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
|
||||||
if(paths[out.y][out.x] == 0) {
|
if(paths[out.y][out.x] == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} while(found && ++count < 200);
|
} while(found && ++count < WORLDBUILD_MAX_PATH);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue