Refactor to allow for the new screen flow.
This commit is contained in:
parent
e7b6b42698
commit
6f9e8a3ed4
10 changed files with 59 additions and 52 deletions
|
|
@ -79,8 +79,8 @@ constexpr int SCENE_VIEW_Y=0;
|
||||||
constexpr int INITIAL_MAP_W = 21;
|
constexpr int INITIAL_MAP_W = 21;
|
||||||
constexpr int INITIAL_MAP_H = 21;
|
constexpr int INITIAL_MAP_H = 21;
|
||||||
|
|
||||||
constexpr float DEFAULT_ROTATE=0.25f;
|
constexpr float DEFAULT_ROTATE=0.5f;
|
||||||
constexpr float DEFAULT_ROTATE_SPEED=DEFAULT_ROTATE / 2.0f;
|
constexpr float DEFAULT_ROTATE_SPEED=DEFAULT_ROTATE / 5.0f;
|
||||||
constexpr float DEFAULT_MOVE_SPEED=0.1f;
|
constexpr float DEFAULT_MOVE_SPEED=0.1f;
|
||||||
|
|
||||||
// for the panels/renderer
|
// for the panels/renderer
|
||||||
|
|
|
||||||
|
|
@ -121,11 +121,10 @@ inline void set_scale_position(sf::Sprite& sprite, sf::Vector2f& position, sf::V
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Raycaster::sprite_casting() {
|
void Raycaster::sprite_casting(sf::RenderTarget& target) {
|
||||||
auto& lights = $level.lights->lighting();
|
auto& lights = $level.lights->lighting();
|
||||||
auto world = $level.world;
|
auto world = $level.world;
|
||||||
$level.collision->distance_sorted($sprite_order, {(size_t)$pos_x, (size_t)$pos_y}, RENDER_DISTANCE);
|
$level.collision->distance_sorted($sprite_order, {(size_t)$pos_x, (size_t)$pos_y}, RENDER_DISTANCE);
|
||||||
$sprites_to_render.clear();
|
|
||||||
|
|
||||||
// BUG: shaders are shared between sprites
|
// BUG: shaders are shared between sprites
|
||||||
// BUG: sprites seem to be shared too? Put a torch on the floor in a room then another to its left and only one is visible at a time.
|
// BUG: sprites seem to be shared too? Put a torch on the floor in a room then another to its left and only one is visible at a time.
|
||||||
|
|
@ -226,12 +225,13 @@ void Raycaster::sprite_casting() {
|
||||||
auto anim = world->get_if<animation::Animation>(rec.entity);
|
auto anim = world->get_if<animation::Animation>(rec.entity);
|
||||||
|
|
||||||
if(anim != nullptr && anim->playing) {
|
if(anim != nullptr && anim->playing) {
|
||||||
|
// BUG: why use refs for sf_sprite? Can it just be pointer?
|
||||||
step_animation(*anim, *sf_sprite, position, scale, in_texture, origin);
|
step_animation(*anim, *sf_sprite, position, scale, in_texture, origin);
|
||||||
} else {
|
} else {
|
||||||
set_scale_position(*sf_sprite, position, scale, in_texture, origin);
|
set_scale_position(*sf_sprite, position, scale, in_texture, origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sprites_to_render.emplace_back(sf_sprite, effect);
|
target.draw(*sf_sprite, effect.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -438,16 +438,13 @@ void Raycaster::update() {
|
||||||
draw_ceiling_floor();
|
draw_ceiling_floor();
|
||||||
cast_rays();
|
cast_rays();
|
||||||
draw_pixel_buffer();
|
draw_pixel_buffer();
|
||||||
sprite_casting();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BUG: if target is a rendertarget then I can say it has to be the viewport only, then I can get rid of $screen_pos_x/y
|
// BUG: if target is a rendertarget then I can say it has to be the viewport only, then I can get rid of $screen_pos_x/y
|
||||||
void Raycaster::render(sf::RenderTarget& target) {
|
void Raycaster::render(sf::RenderTarget& target) {
|
||||||
target.draw($view_sprite);
|
target.draw($view_sprite);
|
||||||
|
|
||||||
for(auto [sprite, effect] : $sprites_to_render) {
|
sprite_casting(target);
|
||||||
target.draw(*sprite, effect.get());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Raycaster::update_sprite(DinkyECS::Entity ent, components::Sprite& sprite) {
|
void Raycaster::update_sprite(DinkyECS::Entity ent, components::Sprite& sprite) {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ struct CameraLOL {
|
||||||
double target_plane_y = 0.0;
|
double target_plane_y = 0.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
using SpriteRender = std::pair<std::shared_ptr<sf::Sprite>, std::shared_ptr<sf::Shader>>;
|
using SpriteRender = std::pair<sf::Sprite, std::shared_ptr<sf::Shader>>;
|
||||||
|
|
||||||
struct Raycaster {
|
struct Raycaster {
|
||||||
sf::Texture $view_texture;
|
sf::Texture $view_texture;
|
||||||
|
|
@ -52,7 +52,6 @@ struct Raycaster {
|
||||||
|
|
||||||
std::unordered_map<DinkyECS::Entity, textures::SpriteTexture> $sprites;
|
std::unordered_map<DinkyECS::Entity, textures::SpriteTexture> $sprites;
|
||||||
// BUG: this can be way better I think
|
// BUG: this can be way better I think
|
||||||
std::vector<SpriteRender> $sprites_to_render;
|
|
||||||
SortedEntities $sprite_order;
|
SortedEntities $sprite_order;
|
||||||
|
|
||||||
GameDB::Level $level;
|
GameDB::Level $level;
|
||||||
|
|
@ -64,7 +63,7 @@ struct Raycaster {
|
||||||
void cast_rays();
|
void cast_rays();
|
||||||
void draw_ceiling_floor();
|
void draw_ceiling_floor();
|
||||||
void draw_pixel_buffer();
|
void draw_pixel_buffer();
|
||||||
void sprite_casting();
|
void sprite_casting(sf::RenderTarget& target);
|
||||||
void update();
|
void update();
|
||||||
void render(sf::RenderTarget& target);
|
void render(sf::RenderTarget& target);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ namespace gui {
|
||||||
using namespace components;
|
using namespace components;
|
||||||
using game::Event;
|
using game::Event;
|
||||||
|
|
||||||
FSM::FSM() :
|
FSM::FSM(sf::RenderWindow& window) :
|
||||||
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"),
|
$window(window),
|
||||||
$main_ui($window),
|
$main_ui($window),
|
||||||
$combat_ui(false),
|
$combat_ui(false),
|
||||||
$dnd_loot($status_ui, $loot_ui, $window, $router)
|
$dnd_loot($status_ui, $loot_ui, $window, $router)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
#include "gui/event_router.hpp"
|
#include "gui/event_router.hpp"
|
||||||
#include "gui/dnd_loot.hpp"
|
#include "gui/dnd_loot.hpp"
|
||||||
#include "storyboard/ui.hpp"
|
#include "storyboard.hpp"
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
#include "game/registry.hpp"
|
#include "game/registry.hpp"
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace gui {
|
||||||
|
|
||||||
class FSM : public DeadSimpleFSM<State, game::Event> {
|
class FSM : public DeadSimpleFSM<State, game::Event> {
|
||||||
public:
|
public:
|
||||||
sf::RenderWindow $window;
|
sf::RenderWindow& $window;
|
||||||
bool $draw_stats = false;
|
bool $draw_stats = false;
|
||||||
bool autowalking = false;
|
bool autowalking = false;
|
||||||
bool $map_open = false;
|
bool $map_open = false;
|
||||||
|
|
@ -47,7 +47,7 @@ namespace gui {
|
||||||
DNDLoot $dnd_loot;
|
DNDLoot $dnd_loot;
|
||||||
System::Registry $systems;
|
System::Registry $systems;
|
||||||
|
|
||||||
FSM();
|
FSM(sf::RenderWindow& window);
|
||||||
|
|
||||||
void event(game::Event ev, std::any data={});
|
void event(game::Event ev, std::any data={});
|
||||||
void autowalk();
|
void autowalk();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "storyboard/ui.hpp"
|
#include "gui/storyboard.hpp"
|
||||||
#include "game/components.hpp"
|
#include "game/components.hpp"
|
||||||
#include "game/sound.hpp"
|
#include "game/sound.hpp"
|
||||||
#include "game/config.hpp"
|
#include "game/config.hpp"
|
||||||
|
|
@ -47,6 +47,10 @@ namespace storyboard {
|
||||||
window.draw($view_sprite);
|
window.draw($view_sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UI::stop() {
|
||||||
|
$audio->stop();
|
||||||
|
}
|
||||||
|
|
||||||
bool UI::playing() {
|
bool UI::playing() {
|
||||||
return $audio->getStatus() == sf::SoundSource::Status::Playing;
|
return $audio->getStatus() == sf::SoundSource::Status::Playing;
|
||||||
}
|
}
|
||||||
|
|
@ -29,6 +29,7 @@ namespace storyboard {
|
||||||
void reset();
|
void reset();
|
||||||
void track_audio();
|
void track_audio();
|
||||||
bool playing();
|
bool playing();
|
||||||
|
void stop();
|
||||||
void config_camera(cinematic::Camera &camera);
|
void config_camera(cinematic::Camera &camera);
|
||||||
};
|
};
|
||||||
|
|
||||||
68
src/main.cpp
68
src/main.cpp
|
|
@ -9,6 +9,34 @@
|
||||||
#include "game/level.hpp"
|
#include "game/level.hpp"
|
||||||
#include "graphics/camera.hpp"
|
#include "graphics/camera.hpp"
|
||||||
|
|
||||||
|
void play_game(std::shared_ptr<gui::FSM> main) {
|
||||||
|
sound::play("ambient_1", true);
|
||||||
|
sound::mute(false);
|
||||||
|
main->event(game::Event::START);
|
||||||
|
|
||||||
|
while(main->active()) {
|
||||||
|
main->update();
|
||||||
|
main->render();
|
||||||
|
|
||||||
|
if(main->in_state(gui::State::BOSS_FIGHT)) {
|
||||||
|
main->handle_boss_fight_events();
|
||||||
|
} else {
|
||||||
|
// BUG: need to sort out how to deal with this in the FSM
|
||||||
|
if(main->in_state(gui::State::IDLE)
|
||||||
|
|| main->in_state(gui::State::LOOTING)
|
||||||
|
|| main->in_state(gui::State::CUT_SCENE_PLAYING))
|
||||||
|
{
|
||||||
|
main->handle_keyboard_mouse();
|
||||||
|
} else{
|
||||||
|
main->event(game::Event::TICK);
|
||||||
|
}
|
||||||
|
|
||||||
|
main->handle_world_events();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
try {
|
try {
|
||||||
gui::Backend backend;
|
gui::Backend backend;
|
||||||
|
|
@ -19,41 +47,21 @@ int main(int argc, char* argv[]) {
|
||||||
ai::init("ai");
|
ai::init("ai");
|
||||||
GameDB::init();
|
GameDB::init();
|
||||||
cinematic::init();
|
cinematic::init();
|
||||||
|
|
||||||
sound::mute(true);
|
sound::mute(true);
|
||||||
|
|
||||||
gui::FSM main;
|
sf::RenderWindow window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing");
|
||||||
main.event(game::Event::START);
|
window.setVerticalSyncEnabled(VSYNC);
|
||||||
Autowalker walker(main);
|
if(FRAME_LIMIT) window.setFramerateLimit(FRAME_LIMIT);
|
||||||
|
window.setPosition({0,0});
|
||||||
|
|
||||||
sound::play("ambient_1", true);
|
auto main = std::make_shared<gui::FSM>(window);
|
||||||
|
|
||||||
if(argc > 1 && argv[1][0] == 't') {
|
while(true) {
|
||||||
walker.start_autowalk();
|
play_game(main);
|
||||||
}
|
|
||||||
|
|
||||||
while(main.active()) {
|
if(!main->active()) {
|
||||||
main.update();
|
// TODO: this is where we handle the restarts
|
||||||
main.render();
|
break;
|
||||||
|
|
||||||
if(main.in_state(gui::State::BOSS_FIGHT)) {
|
|
||||||
main.handle_boss_fight_events();
|
|
||||||
} else {
|
|
||||||
// BUG: need to sort out how to deal with this in the FSM
|
|
||||||
if(main.in_state(gui::State::IDLE)
|
|
||||||
|| main.in_state(gui::State::LOOTING)
|
|
||||||
|| main.in_state(gui::State::CUT_SCENE_PLAYING))
|
|
||||||
{
|
|
||||||
if(main.autowalking) {
|
|
||||||
walker.autowalk();
|
|
||||||
} else {
|
|
||||||
main.handle_keyboard_mouse();
|
|
||||||
}
|
|
||||||
} else{
|
|
||||||
main.event(game::Event::TICK);
|
|
||||||
}
|
|
||||||
|
|
||||||
main.handle_world_events();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,7 @@ sources = files(
|
||||||
'gui/ritual_ui.cpp',
|
'gui/ritual_ui.cpp',
|
||||||
'gui/status_ui.cpp',
|
'gui/status_ui.cpp',
|
||||||
'gui/scene_ui.cpp',
|
'gui/scene_ui.cpp',
|
||||||
|
'gui/storyboard.cpp',
|
||||||
# storyboard
|
|
||||||
'storyboard/ui.cpp',
|
|
||||||
|
|
||||||
# graphics
|
# graphics
|
||||||
'graphics/animation.cpp',
|
'graphics/animation.cpp',
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include "gui/backend.hpp"
|
#include "gui/backend.hpp"
|
||||||
#include "gui/event_router.hpp"
|
#include "gui/event_router.hpp"
|
||||||
#include "graphics/camera.hpp"
|
#include "graphics/camera.hpp"
|
||||||
#include "storyboard/ui.hpp"
|
#include "gui/storyboard.hpp"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
components::init();
|
components::init();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue