[BROKEN] This build is totally broken. DONOT USE.
This commit is contained in:
parent
8dc70ad1ed
commit
f3f2e90cd2
15 changed files with 123 additions and 81 deletions
|
@ -1,14 +1,13 @@
|
||||||
|
#include "sfml/backend.hpp"
|
||||||
#include "sfml/components.hpp"
|
#include "sfml/components.hpp"
|
||||||
#include "sfml/sound.hpp"
|
|
||||||
#include "sfml/shaders.hpp"
|
|
||||||
#include "sfml/textures.hpp"
|
|
||||||
#include "guecs.hpp"
|
#include "guecs.hpp"
|
||||||
#include "constants.hpp"
|
|
||||||
#include <fmt/xchar.h>
|
#include <fmt/xchar.h>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
constexpr const int WINDOW_WIDTH=300;
|
constexpr const int WINDOW_WIDTH=300;
|
||||||
constexpr const int WINDOW_HEIGHT=400;
|
constexpr const int WINDOW_HEIGHT=400;
|
||||||
|
constexpr const int FRAME_LIMIT=60;
|
||||||
|
constexpr const bool VSYNC=true;
|
||||||
|
|
||||||
using std::string, std::wstring;
|
using std::string, std::wstring;
|
||||||
|
|
||||||
|
@ -193,9 +192,8 @@ struct CalculatorUI {
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
sound::init();
|
sfml::Backend backend;
|
||||||
shaders::init();
|
guecs::init(&backend);
|
||||||
textures::init();
|
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode({WINDOW_WIDTH, WINDOW_HEIGHT}), "LEL-GUECS Calculator");
|
sf::RenderWindow window(sf::VideoMode({WINDOW_WIDTH, WINDOW_HEIGHT}), "LEL-GUECS Calculator");
|
||||||
window.setFramerateLimit(FRAME_LIMIT);
|
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;
|
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 {
|
class UI {
|
||||||
public:
|
public:
|
||||||
Entity MAIN = 0;
|
Entity MAIN = 0;
|
||||||
|
|
16
include/sfml/backend.hpp
Normal file
16
include/sfml/backend.hpp
Normal file
|
@ -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
|
#pragma once
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include "sfml/color.hpp"
|
#include "sfml/color.hpp"
|
||||||
#include "lel.hpp"
|
#include "lel.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <any>
|
#include <any>
|
||||||
|
|
||||||
|
@ -48,6 +49,12 @@ namespace guecs {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Sprite {
|
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;
|
string name;
|
||||||
int padding = PADDING;
|
int padding = PADDING;
|
||||||
std::shared_ptr<sf::Sprite> sprite = nullptr;
|
std::shared_ptr<sf::Sprite> sprite = nullptr;
|
||||||
|
|
30
meson.build
30
meson.build
|
@ -69,14 +69,18 @@ dependencies += [
|
||||||
]
|
]
|
||||||
|
|
||||||
sources = [
|
sources = [
|
||||||
'src/config.cpp',
|
|
||||||
'src/dbc.cpp',
|
'src/dbc.cpp',
|
||||||
'src/guecs.cpp',
|
'src/guecs.cpp',
|
||||||
'src/lel.cpp',
|
'src/lel.cpp',
|
||||||
|
'src/sfml/components.cpp',
|
||||||
|
]
|
||||||
|
|
||||||
|
sfml_impl = [
|
||||||
|
'src/sfml/config.cpp',
|
||||||
|
'src/sfml/backend.cpp',
|
||||||
'src/sfml/shaders.cpp',
|
'src/sfml/shaders.cpp',
|
||||||
'src/sfml/sound.cpp',
|
'src/sfml/sound.cpp',
|
||||||
'src/sfml/textures.cpp',
|
'src/sfml/textures.cpp',
|
||||||
'src/sfml/components.cpp',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
lel_guecs_inc = include_directories('include')
|
lel_guecs_inc = include_directories('include')
|
||||||
|
@ -94,11 +98,9 @@ lel_guecs_dep = declare_dependency(
|
||||||
include_directories: lel_guecs_inc)
|
include_directories: lel_guecs_inc)
|
||||||
|
|
||||||
executable('runtests', [
|
executable('runtests', [
|
||||||
|
'src/sfml/config.cpp',
|
||||||
'tests/lel.cpp',
|
'tests/lel.cpp',
|
||||||
'tests/guecs.cpp',
|
'tests/guecs.cpp',
|
||||||
'tests/shaders.cpp',
|
|
||||||
'tests/sound.cpp',
|
|
||||||
'tests/textures.cpp',
|
|
||||||
],
|
],
|
||||||
cpp_args: cpp_args,
|
cpp_args: cpp_args,
|
||||||
link_args: link_args,
|
link_args: link_args,
|
||||||
|
@ -107,12 +109,12 @@ executable('runtests', [
|
||||||
link_with: [lel_guecs_lib],
|
link_with: [lel_guecs_lib],
|
||||||
dependencies: dependencies + [catch2])
|
dependencies: dependencies + [catch2])
|
||||||
|
|
||||||
executable('calc', [
|
#executable('calc', sfml_impl + [
|
||||||
'demos/calc.cpp',
|
# 'demos/calc.cpp',
|
||||||
],
|
# ],
|
||||||
cpp_args: cpp_args,
|
# cpp_args: cpp_args,
|
||||||
link_args: link_args,
|
# link_args: link_args,
|
||||||
override_options: exe_defaults,
|
# override_options: exe_defaults,
|
||||||
include_directories: lel_guecs_inc,
|
# include_directories: lel_guecs_inc,
|
||||||
link_with: [lel_guecs_lib],
|
# link_with: [lel_guecs_lib],
|
||||||
dependencies: dependencies)
|
# dependencies: dependencies)
|
||||||
|
|
38
src/sfml/backend.cpp
Normal file
38
src/sfml/backend.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,15 @@
|
||||||
#include "guecs.hpp"
|
#include "guecs.hpp"
|
||||||
#include "sfml/shaders.hpp"
|
#include "sfml/backend.hpp"
|
||||||
#include "sfml/sound.hpp"
|
|
||||||
#include "sfml/textures.hpp"
|
|
||||||
|
|
||||||
namespace guecs {
|
namespace guecs {
|
||||||
|
static Backend* BACKEND = nullptr;
|
||||||
|
|
||||||
using std::make_shared;
|
using std::make_shared;
|
||||||
|
|
||||||
|
void init(Backend* backend) {
|
||||||
|
BACKEND = backend;
|
||||||
|
}
|
||||||
|
|
||||||
void Textual::init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
|
void Textual::init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
|
||||||
dbc::check(font_ptr != nullptr, "you failed to initialize this WideText");
|
dbc::check(font_ptr != nullptr, "you failed to initialize this WideText");
|
||||||
if(font == nullptr) font = font_ptr;
|
if(font == nullptr) font = font_ptr;
|
||||||
|
@ -32,14 +36,14 @@ namespace guecs {
|
||||||
void Sprite::update(const string& new_name) {
|
void Sprite::update(const string& new_name) {
|
||||||
if(new_name != name) {
|
if(new_name != name) {
|
||||||
name = new_name;
|
name = new_name;
|
||||||
auto sprite_texture = textures::get(name);
|
auto sprite_texture = BACKEND->texture_get(name);
|
||||||
sprite->setTexture(*sprite_texture.texture);
|
sprite->setTexture(*sprite_texture.texture);
|
||||||
sprite->setTextureRect(sprite_texture.sprite->getTextureRect());
|
sprite->setTextureRect(sprite_texture.sprite->getTextureRect());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::init(lel::Cell &cell) {
|
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 = make_shared<sf::Sprite>(
|
||||||
*sprite_texture.texture,
|
*sprite_texture.texture,
|
||||||
|
@ -78,13 +82,13 @@ namespace guecs {
|
||||||
|
|
||||||
void Sound::play(bool hover) {
|
void Sound::play(bool hover) {
|
||||||
if(!hover) {
|
if(!hover) {
|
||||||
sound::play(on_click);
|
BACKEND->sound_play(on_click);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sound::stop(bool hover) {
|
void Sound::stop(bool hover) {
|
||||||
if(!hover) {
|
if(!hover) {
|
||||||
sound::stop(on_click);
|
BACKEND->sound_stop(on_click);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,8 +100,7 @@ namespace guecs {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Effect::init(lel::Cell &cell) {
|
void Effect::init(lel::Cell &cell) {
|
||||||
$shader_version = shaders::version();
|
$shader = BACKEND->shader_get(name);
|
||||||
$shader = shaders::get(name);
|
|
||||||
$shader->setUniform("u_resolution", sf::Vector2f({float(cell.w), float(cell.h)}));
|
$shader->setUniform("u_resolution", sf::Vector2f({float(cell.w), float(cell.h)}));
|
||||||
$clock = std::make_shared<sf::Clock>();
|
$clock = std::make_shared<sf::Clock>();
|
||||||
}
|
}
|
||||||
|
@ -122,9 +125,8 @@ namespace guecs {
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<sf::Shader> Effect::checkout_ptr() {
|
shared_ptr<sf::Shader> Effect::checkout_ptr() {
|
||||||
if(shaders::updated($shader_version)) {
|
if(BACKEND->shader_updated()) {
|
||||||
$shader = shaders::get(name);
|
$shader = BACKEND->shader_get(name);
|
||||||
$shader_version = shaders::version();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $shader;
|
return $shader;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "config.hpp"
|
#include "sfml/config.hpp"
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
#include <SFML/Graphics/Image.hpp>
|
#include <SFML/Graphics/Image.hpp>
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include "config.hpp"
|
#include "sfml/config.hpp"
|
||||||
#include "constants.hpp"
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace shaders {
|
namespace shaders {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "sfml/sound.hpp"
|
#include "sfml/sound.hpp"
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include "config.hpp"
|
#include "sfml/config.hpp"
|
||||||
|
|
||||||
namespace sound {
|
namespace sound {
|
||||||
static SoundManager SMGR;
|
static SoundManager SMGR;
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
#include <SFML/Graphics/Image.hpp>
|
#include <SFML/Graphics/Image.hpp>
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include "config.hpp"
|
#include "sfml/config.hpp"
|
||||||
#include "constants.hpp"
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace textures {
|
namespace textures {
|
||||||
|
|
|
@ -1,32 +1,9 @@
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include "constants.hpp"
|
|
||||||
#include "guecs.hpp"
|
#include "guecs.hpp"
|
||||||
#include "sfml/textures.hpp"
|
|
||||||
#include <fmt/xchar.h>
|
#include <fmt/xchar.h>
|
||||||
|
|
||||||
using namespace guecs;
|
using namespace guecs;
|
||||||
|
|
||||||
TEST_CASE("prototype one gui", "[ecs-gui]") {
|
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]
|
[wrap-git]
|
||||||
directory=SFML-3.0.0
|
directory=SFML-3.0.1
|
||||||
url=https://github.com/SFML/SFML.git
|
url=https://github.com/SFML/SFML.git
|
||||||
revision=3.0.0
|
revision=3.0.1
|
||||||
depth=1
|
depth=1
|
||||||
method=cmake
|
method=cmake
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue