[BROKEN] This build is totally broken. DONOT USE.

This commit is contained in:
Zed A. Shaw 2025-05-08 01:12:12 -04:00
parent 8dc70ad1ed
commit f3f2e90cd2
15 changed files with 123 additions and 81 deletions

38
src/sfml/backend.cpp Normal file
View file

@ -0,0 +1,38 @@
#include "sfml/backend.hpp"
#include "sfml/shaders.hpp"
#include "sfml/sound.hpp"
#include "sfml/textures.hpp"
namespace sfml {
guecs::SpriteTexture Backend::texture_get(const string& name) {
auto sp = textures::get(name);
return {sp.sprite, sp.texture};
}
Backend::Backend() {
sound::init();
shaders::init();
textures::init();
}
void Backend::sound_play(const string& name) {
sound::play(name);
}
void Backend::sound_stop(const string& name) {
sound::stop(name);
}
std::shared_ptr<sf::Shader> Backend::shader_get(const std::string& name) {
return shaders::get(name);
}
bool Backend::shader_updated() {
if(shaders::updated($shaders_version)) {
$shaders_version = shaders::version();
return true;
} else {
return false;
}
}
}

View file

@ -1,11 +1,15 @@
#include "guecs.hpp"
#include "sfml/shaders.hpp"
#include "sfml/sound.hpp"
#include "sfml/textures.hpp"
#include "sfml/backend.hpp"
namespace guecs {
static Backend* BACKEND = nullptr;
using std::make_shared;
void init(Backend* backend) {
BACKEND = backend;
}
void Textual::init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
dbc::check(font_ptr != nullptr, "you failed to initialize this WideText");
if(font == nullptr) font = font_ptr;
@ -32,14 +36,14 @@ namespace guecs {
void Sprite::update(const string& new_name) {
if(new_name != name) {
name = new_name;
auto sprite_texture = textures::get(name);
auto sprite_texture = BACKEND->texture_get(name);
sprite->setTexture(*sprite_texture.texture);
sprite->setTextureRect(sprite_texture.sprite->getTextureRect());
}
}
void Sprite::init(lel::Cell &cell) {
auto sprite_texture = textures::get(name);
auto sprite_texture = BACKEND->texture_get(name);
sprite = make_shared<sf::Sprite>(
*sprite_texture.texture,
@ -78,13 +82,13 @@ namespace guecs {
void Sound::play(bool hover) {
if(!hover) {
sound::play(on_click);
BACKEND->sound_play(on_click);
}
}
void Sound::stop(bool hover) {
if(!hover) {
sound::stop(on_click);
BACKEND->sound_stop(on_click);
}
}
@ -96,8 +100,7 @@ namespace guecs {
}
void Effect::init(lel::Cell &cell) {
$shader_version = shaders::version();
$shader = shaders::get(name);
$shader = BACKEND->shader_get(name);
$shader->setUniform("u_resolution", sf::Vector2f({float(cell.w), float(cell.h)}));
$clock = std::make_shared<sf::Clock>();
}
@ -122,9 +125,8 @@ namespace guecs {
}
shared_ptr<sf::Shader> Effect::checkout_ptr() {
if(shaders::updated($shader_version)) {
$shader = shaders::get(name);
$shader_version = shaders::version();
if(BACKEND->shader_updated()) {
$shader = BACKEND->shader_get(name);
}
return $shader;

View file

@ -1,4 +1,4 @@
#include "config.hpp"
#include "sfml/config.hpp"
#include "dbc.hpp"
#include <fmt/core.h>

View file

@ -2,8 +2,7 @@
#include <SFML/Graphics/Image.hpp>
#include "dbc.hpp"
#include <fmt/core.h>
#include "config.hpp"
#include "constants.hpp"
#include "sfml/config.hpp"
#include <memory>
namespace shaders {

View file

@ -1,7 +1,7 @@
#include "sfml/sound.hpp"
#include "dbc.hpp"
#include <fmt/core.h>
#include "config.hpp"
#include "sfml/config.hpp"
namespace sound {
static SoundManager SMGR;

View file

@ -2,8 +2,7 @@
#include <SFML/Graphics/Image.hpp>
#include "dbc.hpp"
#include <fmt/core.h>
#include "config.hpp"
#include "constants.hpp"
#include "sfml/config.hpp"
#include <memory>
namespace textures {