Tried to refactor for but #42 but nothing worked. I'll try later.
This commit is contained in:
parent
05fc9062a7
commit
a1c3f4df5a
5 changed files with 17 additions and 19 deletions
|
|
@ -95,14 +95,12 @@ void Raycaster::draw_pixel_buffer() {
|
|||
$view_texture.update((uint8_t *)$pixels.get(), {(unsigned int)$width, (unsigned int)$height}, {0, 0});
|
||||
}
|
||||
|
||||
|
||||
void Raycaster::apply_sprite_effect(shared_ptr<sf::Shader> effect, float width, float height) {
|
||||
effect->setUniform("u_time", $clock.getElapsedTime().asSeconds());
|
||||
sf::Vector2f u_resolution{width, height};
|
||||
effect->setUniform("u_resolution", u_resolution);
|
||||
}
|
||||
|
||||
|
||||
void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
||||
auto& lights = $level.lights->lighting();
|
||||
auto world = $level.world;
|
||||
|
|
@ -192,17 +190,10 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
|||
sf::Vector2f position{x + origin.x * scale.x, y + origin.y * scale.y};
|
||||
sf::IntRect in_texture{ {tex_x, tex_y}, {tex_render_width, texture_height}};
|
||||
|
||||
animation::step_animation(*world, rec.entity, scale, position, in_texture);
|
||||
|
||||
sf_sprite->setOrigin(origin);
|
||||
sf_sprite->setScale(scale);
|
||||
sf_sprite->setTextureRect(in_texture);
|
||||
sf_sprite->setPosition(position);
|
||||
shared_ptr<sf::Shader> effect = System::sprite_effect(rec.entity);
|
||||
|
||||
float level = lights[sprite_pos.location.y][sprite_pos.location.x] * PERCENT;
|
||||
|
||||
shared_ptr<sf::Shader> effect = System::sprite_effect(rec.entity);
|
||||
|
||||
if(effect) {
|
||||
apply_sprite_effect(effect, sprite_width, sprite_height);
|
||||
} else {
|
||||
|
|
@ -211,6 +202,13 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
|||
effect->setUniform("darkness", level);
|
||||
}
|
||||
|
||||
animation::step_animation(*world, rec.entity, scale, position, in_texture);
|
||||
|
||||
sf_sprite->setOrigin(origin);
|
||||
sf_sprite->setScale(scale);
|
||||
sf_sprite->setTextureRect(in_texture);
|
||||
sf_sprite->setPosition(position);
|
||||
|
||||
target.draw(*sf_sprite, effect.get());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ struct Raycaster {
|
|||
void update_level(GameDB::Level& level);
|
||||
void update_sprite(DinkyECS::Entity ent, components::Sprite& sprite);
|
||||
void init_shaders();
|
||||
void apply_sprite_effect(std::shared_ptr<sf::Shader> effect, float width, float height);
|
||||
|
||||
// camera things?
|
||||
void position_camera(float player_x, float player_y);
|
||||
|
|
@ -87,4 +86,7 @@ struct Raycaster {
|
|||
void abort_plan();
|
||||
bool is_target(DinkyECS::Entity entity);
|
||||
void update_camera_aiming();
|
||||
|
||||
// BUG: these should go away when Bug #42 is solved
|
||||
void apply_sprite_effect(std::shared_ptr<sf::Shader> effect, float width, float height);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ namespace scene {
|
|||
actor.anim.apply(*actor.st.sprite, actor.pos);
|
||||
actor.anim.apply(actor.text, actor.pos);
|
||||
if(actor.effect) {
|
||||
actor.effect->setUniform("u_time", actor.anim.subframe);
|
||||
actor.effect->setUniform("u_time", $clock.getElapsedTime().asSeconds());
|
||||
sf::Vector2f u_resolution{float(actor.anim.frame_width), float(actor.anim.frame_height)};
|
||||
actor.effect->setUniform("u_resolution", u_resolution);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace scene {
|
|||
};
|
||||
|
||||
struct Engine {
|
||||
sf::Clock $clock;
|
||||
guecs::UI $ui;
|
||||
components::AnimatedScene& $scene;
|
||||
std::string $layout;
|
||||
|
|
|
|||
11
systems.cpp
11
systems.cpp
|
|
@ -423,12 +423,10 @@ void System::player_status() {
|
|||
|
||||
std::shared_ptr<sf::Shader> System::sprite_effect(Entity entity) {
|
||||
auto world = GameDB::current_world();
|
||||
if(world->has<SpriteEffect>(entity)) {
|
||||
auto& se = world->get<SpriteEffect>(entity);
|
||||
|
||||
if(se.frames > 0) {
|
||||
se.frames--;
|
||||
return se.effect;
|
||||
if(auto se = world->get_if<SpriteEffect>(entity)) {
|
||||
if(se->frames > 0) {
|
||||
se->frames--;
|
||||
return se->effect;
|
||||
} else {
|
||||
world->remove<SpriteEffect>(entity);
|
||||
return nullptr;
|
||||
|
|
@ -597,7 +595,6 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture
|
|||
sprite.setPosition({float(point.x * tile_sprite_dim.x), float(point.y * tile_sprite_dim.y)});
|
||||
}
|
||||
|
||||
|
||||
render.draw(sprite);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue