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

main
Zed A. Shaw 2 days ago
parent 8dc70ad1ed
commit f3f2e90cd2
  1. 12
      demos/calc.cpp
  2. 16
      include/constants.hpp
  3. 20
      include/guecs.hpp
  4. 16
      include/sfml/backend.hpp
  5. 9
      include/sfml/components.hpp
  6. 0
      include/sfml/config.hpp
  7. 30
      meson.build
  8. 38
      src/sfml/backend.cpp
  9. 26
      src/sfml/components.cpp
  10. 2
      src/sfml/config.cpp
  11. 3
      src/sfml/shaders.cpp
  12. 2
      src/sfml/sound.cpp
  13. 3
      src/sfml/textures.cpp
  14. 23
      tests/guecs.cpp
  15. 4
      wraps/sfml.wrap

@ -1,14 +1,13 @@
#include "sfml/backend.hpp"
#include "sfml/components.hpp"
#include "sfml/sound.hpp"
#include "sfml/shaders.hpp"
#include "sfml/textures.hpp"
#include "guecs.hpp"
#include "constants.hpp"
#include <fmt/xchar.h>
#include <deque>
constexpr const int WINDOW_WIDTH=300;
constexpr const int WINDOW_HEIGHT=400;
constexpr const int FRAME_LIMIT=60;
constexpr const bool VSYNC=true;
using std::string, std::wstring;
@ -193,9 +192,8 @@ struct CalculatorUI {
};
int main() {
sound::init();
shaders::init();
textures::init();
sfml::Backend backend;
guecs::init(&backend);
sf::RenderWindow window(sf::VideoMode({WINDOW_WIDTH, WINDOW_HEIGHT}), "LEL-GUECS Calculator");
window.setFramerateLimit(FRAME_LIMIT);

@ -1,16 +0,0 @@
#pragma once
#include <string>
#include <array>
constexpr const int SCREEN_WIDTH=1280;
constexpr const int SCREEN_HEIGHT=720;
constexpr const bool VSYNC=false;
constexpr const int FRAME_LIMIT=60;
#ifdef NDEBUG
constexpr const bool DEBUG_BUILD=false;
#else
constexpr const bool DEBUG_BUILD=true;
#endif

@ -38,6 +38,26 @@ namespace guecs {
string name;
};
struct SpriteTexture {
std::shared_ptr<sf::Sprite> sprite = nullptr;
std::shared_ptr<sf::Texture> texture = nullptr;
};
class Backend {
public:
virtual SpriteTexture texture_get(const string& name) = 0;
virtual void sound_play(const string& name) = 0;
virtual void sound_stop(const string& name) = 0;
virtual std::shared_ptr<sf::Shader> shader_get(const std::string& name) = 0;
virtual bool shader_updated() = 0;
};
void init(Backend* backend);
class UI {
public:
Entity MAIN = 0;

@ -0,0 +1,16 @@
#include "guecs.hpp"
namespace sfml {
class Backend : public guecs::Backend {
int $shaders_version = 0;
public:
Backend();
guecs::SpriteTexture texture_get(const string& name);
void sound_play(const string& name);
void sound_stop(const string& name);
std::shared_ptr<sf::Shader> shader_get(const std::string& name);
bool shader_updated();
};
}

@ -1,10 +1,11 @@
#pragma once
#include <SFML/Graphics.hpp>
#include "dbc.hpp"
#include "sfml/color.hpp"
#include "lel.hpp"
#include <string>
#include <memory>
#include <SFML/Graphics.hpp>
#include <functional>
#include <any>
@ -48,6 +49,12 @@ namespace guecs {
};
struct Sprite {
// either you set a filename here,
// or some kind of config,
// or a callback that does the loading,
// or a virtual function and you subclass
// or there's a static config function you call once,
// that's passed an object with all the necessary gear
string name;
int padding = PADDING;
std::shared_ptr<sf::Sprite> sprite = nullptr;

@ -69,14 +69,18 @@ dependencies += [
]
sources = [
'src/config.cpp',
'src/dbc.cpp',
'src/guecs.cpp',
'src/lel.cpp',
'src/sfml/components.cpp',
]
sfml_impl = [
'src/sfml/config.cpp',
'src/sfml/backend.cpp',
'src/sfml/shaders.cpp',
'src/sfml/sound.cpp',
'src/sfml/textures.cpp',
'src/sfml/components.cpp',
]
lel_guecs_inc = include_directories('include')
@ -94,11 +98,9 @@ lel_guecs_dep = declare_dependency(
include_directories: lel_guecs_inc)
executable('runtests', [
'src/sfml/config.cpp',
'tests/lel.cpp',
'tests/guecs.cpp',
'tests/shaders.cpp',
'tests/sound.cpp',
'tests/textures.cpp',
],
cpp_args: cpp_args,
link_args: link_args,
@ -107,12 +109,12 @@ executable('runtests', [
link_with: [lel_guecs_lib],
dependencies: dependencies + [catch2])
executable('calc', [
'demos/calc.cpp',
],
cpp_args: cpp_args,
link_args: link_args,
override_options: exe_defaults,
include_directories: lel_guecs_inc,
link_with: [lel_guecs_lib],
dependencies: dependencies)
#executable('calc', sfml_impl + [
# 'demos/calc.cpp',
# ],
# cpp_args: cpp_args,
# link_args: link_args,
# override_options: exe_defaults,
# include_directories: lel_guecs_inc,
# link_with: [lel_guecs_lib],
# dependencies: dependencies)

@ -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;
}
}
}

@ -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;

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

@ -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 {

@ -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;

@ -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 {

@ -1,32 +1,9 @@
#include <catch2/catch_test_macros.hpp>
#include <fmt/core.h>
#include "constants.hpp"
#include "guecs.hpp"
#include "sfml/textures.hpp"
#include <fmt/xchar.h>
using namespace guecs;
TEST_CASE("prototype one gui", "[ecs-gui]") {
guecs::UI gui;
textures::init();
gui.position(0, 0, 1000, 500);
gui.layout("[test1|test2|test3][test4|_|test5]");
for(auto& [name, cell] : gui.cells()) {
auto button = gui.entity(name);
gui.set<lel::Cell>(button, cell);
gui.set<Rectangle>(button, {});
gui.set<Clickable>(button, {});
gui.set<Textual>(button, {L"whatever"});
}
gui.init();
// at this point it's mostly ready but I'd need to render it to a window real quick
sf::RenderWindow window;
window.setSize({SCREEN_WIDTH, SCREEN_HEIGHT});
gui.render(window);
window.display();
}

@ -1,7 +1,7 @@
[wrap-git]
directory=SFML-3.0.0
directory=SFML-3.0.1
url=https://github.com/SFML/SFML.git
revision=3.0.0
revision=3.0.1
depth=1
method=cmake

Loading…
Cancel
Save