Compare commits

...

5 Commits

  1. 2
      Makefile
  2. 12
      README.md
  3. BIN
      assets/axe_ranger-256.png
  4. 2
      assets/config.json
  5. BIN
      assets/evil_eye-sprites.png
  6. BIN
      assets/undead_peasant-spritesheet.png
  7. 13
      lel.cpp
  8. 62
      main.cpp
  9. 6
      main_ui.cpp
  10. 2
      matrix.cpp
  11. 79
      meson.build
  12. 2
      scripts/reset_build.sh
  13. BIN
      scripts/win_installer.ifp
  14. 110
      tests/goap.cpp

@ -22,7 +22,7 @@ tracy_build:
meson compile -j 10 -C builddir
test: build
./builddir/runtests
./builddir/runtests "[goap]"
run: build test
powershell "cp ./builddir/zedcaster.exe ."

@ -127,6 +127,18 @@ I would also like statistics that show it's better, not just your word.
It's early so probably a bunch of bugs.
## Linux Build Notes
Libraries Needed:
* libxi-dev
* libfreetype-dev
It uses c++ so you may need to install a libg++ or libc++ for your system. Usually this is all you
need:
apt install build-essential
## OSX Build Notes
* Quite a bad experience. Need to install Python, cmake, meson, and ninja all which are in homebrew but if you don't use homebrew then this is a problem.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 38 KiB

@ -54,7 +54,7 @@
"tunnel_with_rocks_stage": "assets/tunnel_with_rocks_stage.png"
},
"worldgen": {
"enemy_probability": 80,
"enemy_probability": 30,
"empty_room_probability": 10,
"device_probability": 10
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 316 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 KiB

After

Width:  |  Height:  |  Size: 52 KiB

@ -43,18 +43,14 @@ namespace lel {
for(auto& row : grid) {
size_t columns = row.size();
int cell_width = grid_w / columns;
dbc::check(cell_width > 0, "invalid cell width calc");
dbc::check(cell_height > 0, "invalid cell height calc");
for(auto& name : row) {
if(name == "_") continue;
auto& cell = cells.at(name);
int cell_width = grid_w / columns;
dbc::check(cell_width > 0, "invalid cell width calc");
dbc::check(cell_height > 0, "invalid cell height calc");
cell.x = grid_x + (cell.col * cell_width);
cell.y = grid_y + (cell.row * cell_height);
// ZED: getting a bit hairy but this should work
if(cell.percent) {
// when percent mode we have to take unset to 100%
@ -73,6 +69,9 @@ namespace lel {
dbc::check(cell.h > 0, fmt::format("invalid height cell {}", name));
dbc::check(cell.w > 0, fmt::format("invalid width cell {}", name));
cell.x = grid_x + (cell.col * cell_width);
cell.y = grid_y + (cell.row * cell_height);
// keep the midpoint since it is used a lot
cell.mid_x = std::midpoint(cell.x, cell.x + cell.w);
cell.mid_y = std::midpoint(cell.y, cell.y + cell.h);

@ -2,41 +2,49 @@
#include "textures.hpp"
#include "sound.hpp"
#include "autowalker.hpp"
#include <iostream>
int main(int argc, char* argv[]) {
textures::init();
sound::init();
sound::mute(false);
gui::FSM main;
main.event(gui::Event::STARTED);
Autowalker walker(main);
try {
textures::init();
sound::init();
sound::mute(true);
gui::FSM main;
main.event(gui::Event::STARTED);
Autowalker walker(main);
sound::play("ambient_1", true);
sound::play("ambient_1", true);
if(argc > 1 && argv[1][0] == 't') {
walker.start_autowalk();
}
if(argc > 1 && argv[1][0] == 't') {
walker.start_autowalk();
}
while(main.active()) {
main.render();
while(main.active()) {
main.render();
// ZED: need to sort out how to deal with this in the FSM
if(main.in_state(gui::State::IDLE)
|| main.in_state(gui::State::NEXT_LEVEL)
|| main.in_state(gui::State::MAPPING)
|| main.in_state(gui::State::IN_COMBAT))
{
if(main.autowalking) {
walker.autowalk();
} else {
main.keyboard_mouse();
// ZED: need to sort out how to deal with this in the FSM
if(main.in_state(gui::State::IDLE)
|| main.in_state(gui::State::NEXT_LEVEL)
|| main.in_state(gui::State::MAPPING)
|| main.in_state(gui::State::IN_COMBAT))
{
if(main.autowalking) {
walker.autowalk();
} else {
main.keyboard_mouse();
}
} else{
main.event(gui::Event::TICK);
}
} else{
main.event(gui::Event::TICK);
main.handle_world_events();
}
main.handle_world_events();
return 0;
} catch(const std::system_error& e) {
std::cout << "WARNING: On OSX you'll get this error on shutdown.\n";
std::cout << "Caught system_error with code "
"[" << e.code() << "] meaning "
"[" << e.what() << "]\n";
}
return 0;
}

@ -128,9 +128,11 @@ namespace gui {
std::optional<Point> MainUI::play_move() {
if($camera.play_move($rayview)) {
$needs_render = false;
return std::make_optional<Point>({
Point pos{
size_t($camera.target_x),
size_t($camera.target_y)});
size_t($camera.target_y)};
return std::make_optional<Point>(pos);
} else {
$needs_render = true;
return std::nullopt;

@ -20,7 +20,7 @@ namespace matrix {
} else if(cell == WALL_PATH_LIMIT) {
print("# ");
} else if(cell > 15) {
print("* ");
print("[{:x}]", cell);
} else {
print("{:x} ", cell);
}

@ -5,19 +5,51 @@ project('raycaster', 'cpp',
'cpp_args=-D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1',
])
add_global_link_arguments(
'-static-libgcc',
'-static-libstdc++',
'-static',
language: 'cpp',
)
# use this for common options only for our executables
cpp_args=[]
link_args=[]
# these are passed as override_defaults
exe_defaults = ['warning_level=2', 'werror=true']
exe_defaults = [ 'warning_level=2' ]
cc = meson.get_compiler('cpp')
dependencies = []
if build_machine.system() == 'windows'
add_global_link_arguments(
'-static-libgcc',
'-static-libstdc++',
'-static',
language: 'cpp',
)
sfml_main = dependency('sfml_main')
opengl32 = cc.find_library('opengl32', required: true)
winmm = cc.find_library('winmm', required: true)
gdi32 = cc.find_library('gdi32', required: true)
dependencies += [
opengl32, winmm, gdi32, sfml_main
]
exe_defaults += ['werror=true']
elif build_machine.system() == 'darwin'
add_global_link_arguments(
language: 'cpp',
)
opengl = dependency('OpenGL')
corefoundation = dependency('CoreFoundation')
carbon = dependency('Carbon')
cocoa = dependency('Cocoa')
iokit = dependency('IOKit')
corevideo = dependency('CoreVideo')
link_args += ['-ObjC']
exe_defaults += ['werror=false']
dependencies += [
opengl, corefoundation, carbon, cocoa, iokit, corevideo
]
endif
catch2 = dependency('catch2-with-main')
fmt = subproject('fmt').get_variable('fmt_dep')
@ -33,12 +65,14 @@ sfml_audio = dependency('sfml_audio')
sfml_graphics = dependency('sfml_graphics')
sfml_network = dependency('sfml_network')
sfml_system = dependency('sfml_system')
sfml_window = dependency('sfml_window')
sfml_window = dependency('sfml_window',
default_options: ['default_library=shared'])
ftxui_screen = dependency('ftxui-screen')
ftxui_dom = dependency('ftxui-dom')
ftxui_component = dependency('ftxui-component')
dependencies = [
dependencies += [
fmt, json, freetype2,
flac, ogg, vorbis, vorbisfile, vorbisenc,
sfml_audio, sfml_graphics,
@ -46,16 +80,6 @@ dependencies = [
sfml_window, ftxui_screen, ftxui_dom, ftxui_component
]
if build_machine.system() == 'windows'
sfml_main = dependency('sfml_main')
opengl32 = cc.find_library('opengl32', required: true)
winmm = cc.find_library('winmm', required: true)
gdi32 = cc.find_library('gdi32', required: true)
dependencies += [
opengl32, winmm, gdi32, sfml_main
]
endif
sources = [
@ -96,6 +120,14 @@ sources = [
'textures.cpp',
'tilemap.cpp',
'worldbuilder.cpp',
'goap2/Action.cpp',
'goap2/Action.h',
'goap2/Node.cpp',
'goap2/Node.h',
'goap2/Planner.cpp',
'goap2/Planner.h',
'goap2/WorldState.cpp',
'goap2/WorldState.h',
]
executable('runtests', sources + [
@ -106,6 +138,7 @@ executable('runtests', sources + [
'tests/dbc.cpp',
'tests/dinkyecs.cpp',
'tests/fsm.cpp',
'tests/goap.cpp',
'tests/guecs.cpp',
'tests/inventory.cpp',
'tests/lel.cpp',
@ -118,12 +151,16 @@ executable('runtests', sources + [
'tests/spatialmap.cpp',
'tests/textures.cpp',
'tests/tilemap.cpp',
], override_options: exe_defaults,
],
cpp_args: cpp_args,
link_args: link_args,
override_options: exe_defaults,
dependencies: dependencies + [catch2])
executable('zedcaster',
sources + [ 'main.cpp' ],
cpp_args: cpp_args,
link_args: link_args,
override_options: exe_defaults,
dependencies: dependencies)

@ -7,4 +7,4 @@ mv -f packagecache ./subprojects/ && true
mkdir builddir
cp wraps/*.wrap subprojects/
# on OSX you can't do this with static
meson setup builddir
meson setup --default-library=static --prefer-static builddir

@ -0,0 +1,110 @@
#include <catch2/catch_test_macros.hpp>
#include "dbc.hpp"
#include <iostream>
#include <vector>
#include "levelmanager.hpp"
#include "matrix.hpp"
#include "components.hpp"
#include <bitset>
using namespace dbc;
using namespace components;
using AStarPath = std::deque<Point>;
void update_map(Matrix& map, std::deque<Point>& total_path) {
for(auto &point : total_path) {
map[point.y][point.x] = 10;
}
}
AStarPath reconstruct_path(std::unordered_map<Point, Point>& came_from, Point current) {
std::deque<Point> total_path{current};
while(came_from.contains(current)) {
current = came_from[current];
total_path.push_front(current);
}
return total_path;
}
inline h(Point from, Point to) {
return std::hypot(float(from.x) - float(to.x),
float(from.y) - float(to.y));
}
inline d(Point current, Point neighbor) {
return std::hypot(float(current.x) - float(neighbor.x),
float(current.y) - float(neighbor.y));
}
inline Point find_lowest(std::unordered_map<Point, float>& open_set) {
dbc::check(!open_set.empty(), "open set can't be empty in find_lowest");
Point result;
float lowest_score = 10000;
for(auto [point, score] : open_set) {
if(score < lowest_score) {
lowest_score = score;
result = point;
}
}
return result;
}
std::optional<AStarPath> path_to_player(Matrix& map, Point start, Point goal) {
std::unordered_map<Point, float> open_set;
std::unordered_map<Point, Point> came_from;
std::unordered_map<Point, float> g_score;
g_score[start] = 0;
open_set[start] = g_score[start] + h(start, goal);
while(!open_set.empty()) {
auto current = find_lowest(open_set);
if(current == goal) {
return std::make_optional<AStarPath>(reconstruct_path(came_from, current));
}
open_set.erase(current);
for(matrix::compass it{map, current.x, current.y}; it.next();) {
Point neighbor{it.x, it.y};
float d_score = d(current, neighbor) + map[it.y][it.x] * 1000;
float tentative_g_score = g_score[current] + d_score;
float neighbor_g_score = g_score.contains(neighbor) ? g_score[neighbor] : 10000.0f;
if(tentative_g_score < neighbor_g_score) {
came_from[neighbor] = current;
g_score[neighbor] = tentative_g_score;
// open_set gets the fScore
open_set[neighbor] = tentative_g_score + h(neighbor, goal);
}
}
}
return std::nullopt;
}
TEST_CASE("basic feature tests", "[goap]") {
for(int i = 0; i < 10; i++) {
LevelManager levels;
GameLevel level = levels.current();
auto &map = *level.map;
auto& player_at = level.world->get<Position>(level.player);
// matrix::dump("A* PLAYER", map.walls(), player_at.location.x, player_at.location.y);
level.world->query<Position, Combat>([&](const auto ent, auto& enemy_at, auto&) {
if(ent != level.player) {
auto result = path_to_player(map.walls(), enemy_at.location, player_at.location);
REQUIRE(result != std::nullopt);
}
});
}
}
Loading…
Cancel
Save