Now runs with SFML 3.0

main
Zed A. Shaw 3 days ago
parent 2fa68351fc
commit 713dd9212f
  1. 1
      .vimrc_proj
  2. 100
      main.cpp
  3. 89
      meson.build
  4. 11
      wraps/catch2.wrap
  5. 18
      wraps/fmt.wrap
  6. 13
      wraps/imgui-sfml.wrap
  7. 13
      wraps/imgui.wrap
  8. 18
      wraps/libpng.wrap
  9. 11
      wraps/nlohmann_json.wrap
  10. 13
      wraps/openal-soft.wrap
  11. 23
      wraps/sfml.wrap
  12. 13
      wraps/zlib.wrap

@ -0,0 +1 @@
set makeprg=meson\ compile\ -C\ .

@ -11,9 +11,9 @@
#include "dbc.hpp"
void Window_update(sf::RenderWindow &window, sf::Sprite &player) {
window.clear();
window.draw(player);
window.display();
window.clear();
window.draw(player);
window.display();
}
struct BoxTest {
@ -51,48 +51,40 @@ struct BoxTest Box2d_setup(b2World &world) {
void Handle_events(sf::RenderWindow &window, BoxTest &box, sf::Sound &click) {
sf::Event event;
// is this a main event loop
while (window.pollEvent(event)) {
switch(event.type) {
case sf::Event::Closed:
fmt::print("Exiting...\n");
window.close();
break;
case sf::Event::KeyPressed:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
b2Vec2 force(-200, 1000);
box.body->ApplyForceToCenter(force, true);
box.body->ApplyTorque(100.0f, true);
click.play();
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
b2Vec2 force(200, 1000);
box.body->ApplyForceToCenter(force, true);
box.body->ApplyTorque(-100.0f, true);
click.play();
}
break;
case sf::Event::MouseButtonPressed:
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
b2Vec2 force(-200, 1000);
box.body->ApplyForceToCenter(force, true);
box.body->ApplyTorque(100.0f, true);
click.play();
} else if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
b2Vec2 force(200, 1000);
box.body->ApplyForceToCenter(force, true);
box.body->ApplyTorque(-100.0f, true);
click.play();
}
break;
default:
return; // just here to shutup warnings
while (const auto event = window.pollEvent()) {
if(event->is<sf::Event::Closed>()) {
fmt::print("Exiting...\n");
window.close();
} else if (const auto* key = event->getIf<sf::Event::KeyPressed>()) {
if(key->scancode == sf::Keyboard::Scan::Left) {
b2Vec2 force(-200, 1000);
box.body->ApplyForceToCenter(force, true);
box.body->ApplyTorque(100.0f, true);
click.play();
} else if(key->scancode == sf::Keyboard::Scan::Right) {
b2Vec2 force(200, 1000);
box.body->ApplyForceToCenter(force, true);
box.body->ApplyTorque(-100.0f, true);
click.play();
}
} else if(const auto* mouse = event->getIf<sf::Event::MouseButtonPressed>()) {
if(mouse->button == sf::Mouse::Button::Left) {
b2Vec2 force(-200, 1000);
box.body->ApplyForceToCenter(force, true);
box.body->ApplyTorque(100.0f, true);
click.play();
} else if(mouse->button == sf::Mouse::Button::Right) {
b2Vec2 force(200, 1000);
box.body->ApplyForceToCenter(force, true);
box.body->ApplyTorque(-100.0f, true);
click.play();
}
}
}
}
sf::Time Update_entities(sf::RenderWindow &window, b2World &world, sf::Clock &clock, sf::Clock &deltaClock, sf::Time &tick, BoxTest &box, sf::Sprite &player) {
sf::Time Update_entities(sf::RenderWindow &window, b2World &world, sf::Clock &clock, sf::Time &tick, BoxTest &box, sf::Sprite &player) {
sf::Vector2u winSize = window.getSize();
float timeStep = 1.0f / 60.0f;
int velocityIterations = 6;
@ -104,8 +96,8 @@ sf::Time Update_entities(sf::RenderWindow &window, b2World &world, sf::Clock &cl
b2Vec2 position = box.body->GetPosition();
float angle = box.body->GetAngle();
player.setPosition(position.x * 100.0f, winSize.y - position.y * 100.0f);
player.setRotation(angle * 180.0f / M_PI);
player.setPosition({position.x * 100.0f, winSize.y - position.y * 100.0f});
player.setRotation(sf::degrees(angle * 180.0f / M_PI));
Window_update(window, player);
@ -113,28 +105,30 @@ sf::Time Update_entities(sf::RenderWindow &window, b2World &world, sf::Clock &cl
}
void Create_player(sf::RenderWindow &window, sf::Sprite &player, sf::Texture &texture) {
sf::Sprite Create_player(sf::RenderWindow &window, sf::Texture &texture) {
if(!texture.loadFromFile("sprite.png")) {
fmt::print("Error loading sprite!");
}
texture.setSmooth(true);
sf::Sprite player(texture);
player.setTexture(texture);
// position the prite
sf::Vector2u winSize = window.getSize();
player.setPosition(winSize.x / 2, winSize.y / 2);
player.setOrigin(50.f, 50.f);
player.setPosition({float(winSize.x) / 2, float(winSize.y) / 2});
player.setOrigin({50.f, 50.f});
return player;
}
int main() {
fmt::print("Setting up a window for you...\n");
sf::ContextSettings settings;
settings.antialiasingLevel = 8;
sf::RenderWindow window(sf::VideoMode(1280, 720), "Simple Game Demo", sf::Style::Default, settings);
sf::RenderWindow window(sf::VideoMode({1280, 720}), "Simple Game Demo");
window.setFramerateLimit(60);
window.setVerticalSyncEnabled(true);
@ -142,16 +136,14 @@ int main() {
if(!buffer.loadFromFile("click.mp3")) {
fmt::print("Failed to load click.ogg!\n");
}
sf::Sound click;
click.setBuffer(buffer);
sf::Sound click(buffer);
sf::Clock deltaClock;
sf::Clock clock;
sf::Time tick = clock.getElapsedTime();
sf::Sprite player;
sf::Texture texture;
Create_player(window, player, texture);
auto player = Create_player(window, texture);
b2Vec2 gravity(0.0f, -10.0f);
b2World world(gravity);
@ -160,6 +152,6 @@ int main() {
while (window.isOpen()) {
Handle_events(window, box, click);
// preparing for refactoring this into a class or struct for everything
tick = Update_entities(window, world, clock, deltaClock, tick, box, player);
tick = Update_entities(window, world, clock, tick, box, player);
}
}

@ -1,19 +1,88 @@
project('sfmldemo', 'cpp',
default_options: ['cpp_std=c++20'])
version: '0.1.0',
default_options: [
'cpp_std=c++20',
'cpp_args=-D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1',
])
dependencies = [
dependency('sfml'),
subproject('fmt').get_variable('fmt_dep'),
dependency('box2d'),
# use this for common options only for our executables
cpp_args=[]
link_args=[]
# these are passed as override_defaults
exe_defaults = [ 'warning_level=2' ]
cc = meson.get_compiler('cpp')
dependencies = []
if build_machine.system() == 'windows'
add_global_link_arguments(
'-static-libgcc',
'-static-libstdc++',
'-static',
language: 'cpp',
)
sfml_main = dependency('sfml_main')
opengl32 = cc.find_library('opengl32', required: true)
winmm = cc.find_library('winmm', required: true)
gdi32 = cc.find_library('gdi32', required: true)
dependencies += [
opengl32, winmm, gdi32, sfml_main
]
exe_defaults += ['werror=true']
elif build_machine.system() == 'darwin'
add_global_link_arguments(
language: 'cpp',
)
opengl = dependency('OpenGL')
corefoundation = dependency('CoreFoundation')
carbon = dependency('Carbon')
cocoa = dependency('Cocoa')
iokit = dependency('IOKit')
corevideo = dependency('CoreVideo')
link_args += ['-ObjC']
exe_defaults += ['werror=false']
dependencies += [
opengl, corefoundation, carbon, cocoa, iokit, corevideo
]
endif
catch2 = dependency('catch2-with-main')
fmt = subproject('fmt').get_variable('fmt_dep')
freetype2 = dependency('freetype2')
flac = dependency('flac')
box2d = dependency('box2d')
ogg = dependency('ogg')
vorbis = dependency('vorbis')
vorbisfile = dependency('vorbisfile')
vorbisenc = dependency('vorbisenc')
sfml_audio = dependency('sfml_audio')
sfml_graphics = dependency('sfml_graphics')
sfml_network = dependency('sfml_network')
sfml_system = dependency('sfml_system')
sfml_window = dependency('sfml_window',
default_options: ['default_library=shared'])
dependencies += [
fmt, freetype2,
flac, ogg, vorbis, vorbisfile, vorbisenc,
sfml_audio, sfml_graphics,
sfml_network, sfml_system,
sfml_window, box2d
]
source = [
sources = [
'dbc.cpp',
'main.cpp'
]
executable('sfmldemo',
source,
win_subsystem: 'windows',
cpp_args: '-DFMT_HEADER_ONLY',
sources + [ 'main.cpp' ],
cpp_args: cpp_args,
link_args: link_args,
override_options: exe_defaults,
dependencies: dependencies)

@ -0,0 +1,11 @@
[wrap-file]
directory = Catch2-3.7.1
source_url = https://github.com/catchorg/Catch2/archive/v3.7.1.tar.gz
source_filename = Catch2-3.7.1.tar.gz
source_hash = c991b247a1a0d7bb9c39aa35faf0fe9e19764213f28ffba3109388e62ee0269c
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.7.1-1/Catch2-3.7.1.tar.gz
wrapdb_version = 3.7.1-1
[provide]
catch2 = catch2_dep
catch2-with-main = catch2_with_main_dep

@ -1,13 +1,13 @@
[wrap-file]
directory = fmt-11.0.1
source_url = https://github.com/fmtlib/fmt/archive/11.0.1.tar.gz
source_filename = fmt-11.0.1.tar.gz
source_hash = 7d009f7f89ac84c0a83f79ed602463d092fbf66763766a907c97fd02b100f5e9
patch_filename = fmt_11.0.1-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/fmt_11.0.1-1/get_patch
patch_hash = 0a8b93d1ee6d84a82d3872a9bfb4c3977d8a53f7f484d42d1f7ed63ed496d549
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/fmt_11.0.1-1/fmt-11.0.1.tar.gz
wrapdb_version = 11.0.1-1
directory = fmt-11.0.2
source_url = https://github.com/fmtlib/fmt/archive/11.0.2.tar.gz
source_filename = fmt-11.0.2.tar.gz
source_hash = 6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f
patch_filename = fmt_11.0.2-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/fmt_11.0.2-1/get_patch
patch_hash = 90c9e3b8e8f29713d40ca949f6f93ad115d78d7fb921064112bc6179e6427c5e
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/fmt_11.0.2-1/fmt-11.0.2.tar.gz
wrapdb_version = 11.0.2-1
[provide]
fmt = fmt_dep

@ -1,13 +0,0 @@
[wrap-file]
directory = imgui-sfml-2.6
source_url = https://github.com/eliasdaler/imgui-sfml/archive/refs/tags/v2.6.tar.gz
source_filename = v2.6.tar.gz
source_hash = b1195ca1210dd46c8049cfc8cae7f31cd34f1591da7de1c56297b277ac9c5cc0
patch_filename = imgui-sfml_2.6-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/imgui-sfml_2.6-1/get_patch
patch_hash = a804978cf015af2db13476eefd2ed16e64c2c5142eb4e4a93be5f19e0c7cbdbb
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/imgui-sfml_2.6-1/v2.6.tar.gz
wrapdb_version = 2.6-1
[provide]
imgui-sfml = imgui_sfml_dep

@ -1,13 +0,0 @@
[wrap-file]
directory = imgui-1.89.9
source_url = https://github.com/ocornut/imgui/archive/refs/tags/v1.89.9.tar.gz
source_filename = imgui-1.89.9.tar.gz
source_hash = 1acc27a778b71d859878121a3f7b287cd81c29d720893d2b2bf74455bf9d52d6
patch_filename = imgui_1.89.9-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/imgui_1.89.9-2/get_patch
patch_hash = 3b99f0f7e039b05926e7a5c45f383210d5d933276701368e4885ea691d3e68e6
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/imgui_1.89.9-2/imgui-1.89.9.tar.gz
wrapdb_version = 1.89.9-2
[provide]
imgui = imgui_dep

@ -1,13 +1,13 @@
[wrap-file]
directory = libpng-1.6.43
source_url = https://github.com/glennrp/libpng/archive/v1.6.43.tar.gz
source_filename = libpng-1.6.43.tar.gz
source_hash = fecc95b46cf05e8e3fc8a414750e0ba5aad00d89e9fdf175e94ff041caf1a03a
patch_filename = libpng_1.6.43-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/libpng_1.6.43-2/get_patch
patch_hash = 49951297edf03e81d925ab03726555f09994ad1ed78fb539a269216430eef3da
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/libpng_1.6.43-2/libpng-1.6.43.tar.gz
wrapdb_version = 1.6.43-2
directory = libpng-1.6.44
source_url = https://github.com/glennrp/libpng/archive/v1.6.44.tar.gz
source_filename = libpng-1.6.44.tar.gz
source_hash = 0ef5b633d0c65f780c4fced27ff832998e71478c13b45dfb6e94f23a82f64f7c
patch_filename = libpng_1.6.44-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/libpng_1.6.44-1/get_patch
patch_hash = 394b07614c45fbd1beac8b660386216a490fe12f841a1a445799b676c9c892fb
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/libpng_1.6.44-1/libpng-1.6.44.tar.gz
wrapdb_version = 1.6.44-1
[provide]
libpng = libpng_dep

@ -0,0 +1,11 @@
[wrap-file]
directory = nlohmann_json-3.11.3
lead_directory_missing = true
source_url = https://github.com/nlohmann/json/releases/download/v3.11.3/include.zip
source_filename = nlohmann_json-3.11.3.zip
source_hash = a22461d13119ac5c78f205d3df1db13403e58ce1bb1794edc9313677313f4a9d
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/nlohmann_json_3.11.3-1/nlohmann_json-3.11.3.zip
wrapdb_version = 3.11.3-1
[provide]
nlohmann_json = nlohmann_json_dep

@ -1,13 +0,0 @@
[wrap-file]
directory = openal-soft-1.23.1
source_url = https://github.com/kcat/openal-soft/archive/refs/tags/1.23.1.tar.gz
source_filename = openal-soft-1.23.1.tar.gz
source_hash = dfddf3a1f61059853c625b7bb03de8433b455f2f79f89548cbcbd5edca3d4a4a
patch_filename = openal-soft_1.23.1-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/openal-soft_1.23.1-1/get_patch
patch_hash = dec7316b7258ebf47e6e0436fb4be39297d86d2aa8c098903055dd85c7144501
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/openal-soft_1.23.1-1/openal-soft-1.23.1.tar.gz
wrapdb_version = 1.23.1-1
[provide]
openal = openal_dep

@ -1,13 +1,14 @@
[wrap-file]
directory = SFML-2.6.1
source_url = https://github.com/SFML/SFML/archive/refs/tags/2.6.1.tar.gz
source_filename = 2.6.1.tar.gz
source_hash = 82535db9e57105d4f3a8aedabd138631defaedc593cab589c924b7d7a11ffb9d
patch_filename = sfml_2.6.1-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/sfml_2.6.1-1/get_patch
patch_hash = 10367d927ec489dc575491de0059945a63ba08eef3f6fc146e6ba339176c9f18
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/sfml_2.6.1-1/2.6.1.tar.gz
wrapdb_version = 2.6.1-1
[wrap-git]
directory=SFML-3.0.0
url=https://github.com/SFML/SFML.git
revision=3.0.0
depth=1
method=cmake
[provide]
sfml = sfml_dep
sfml_audio = sfml_audio_dep
sfml_graphics = sfml_graphics_dep
sfml_main = sfml_main_dep
sfml_network = sfml_network_dep
sfml_system = sfml_system_dep
sfml_window = sfml_window_dep

@ -1,13 +0,0 @@
[wrap-file]
directory = zlib-1.3.1
source_url = http://zlib.net/fossils/zlib-1.3.1.tar.gz
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/zlib_1.3.1-1/zlib-1.3.1.tar.gz
source_filename = zlib-1.3.1.tar.gz
source_hash = 9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23
patch_filename = zlib_1.3.1-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/zlib_1.3.1-1/get_patch
patch_hash = e79b98eb24a75392009cec6f99ca5cdca9881ff20bfa174e8b8926d5c7a47095
wrapdb_version = 1.3.1-1
[provide]
zlib = zlib_dep
Loading…
Cancel
Save