From 0f2975883ee34df042dbd25dbce2d5a385b9df18 Mon Sep 17 00:00:00 2001 From: kdx Date: Sun, 16 Jul 2023 06:35:02 +0200 Subject: soloud integration --- .gitmodules | 3 +++ Makefile | 12 +++++++++--- compile_flags.txt | 2 ++ create_FLD.cpp.sh | 4 ++-- src/FLD.hpp | 3 +++ src/destructor.cpp | 1 + src/init.cpp | 14 +++++++++++++- vendors/soloud | 1 + 8 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 .gitmodules create mode 160000 vendors/soloud diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..02c5a12 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendors/soloud"] + path = vendors/soloud + url = https://github.com/jarikomppa/soloud diff --git a/Makefile b/Makefile index bada565..bc8c029 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,12 @@ -CFLAGS = -O3 -std=c++20 -Wall -Wextra -Wno-c99-designator -iquotesrc +SOLOUD = vendors/soloud +CFLAGS = -O3 -std=c++20 \ + -iquotesrc -iquote$(SOLOUD)/include -iquote/usr/include/SDL2 \ + -DWITH_SDL2_STATIC= # -Wall -Wextra -Wno-c99-designator LIBS = -lSDL2 -SRC = FLD.cpp demo.cpp +SRC = FLD.cpp demo.cpp \ + $(wildcard $(SOLOUD)/src/core/*.c*) \ + $(wildcard $(SOLOUD)/src/audiosource/wav/*.c*) \ + $(wildcard $(SOLOUD)/src/backend/sdl2_static/*.c*) all: demo @@ -8,7 +14,7 @@ FLD.cpp: ./create_FLD.cpp.sh demo: $(SRC) - clang++ $(CFLAGS) -o $@ $(SRC) $(LIBS) + g++ $(CFLAGS) -o $@ $(SRC) $(LIBS) clean: rm -rf FLD.cpp demo build_FLD.cpp diff --git a/compile_flags.txt b/compile_flags.txt index 24c61c8..b339b18 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -4,3 +4,5 @@ -std=c++20 -fprebuilt-module-path=. -iquotesrc +-iquotevendors/soloud/include +-DWITH_SDL2_STATIC= diff --git a/create_FLD.cpp.sh b/create_FLD.cpp.sh index e6bce11..f08f33d 100755 --- a/create_FLD.cpp.sh +++ b/create_FLD.cpp.sh @@ -3,8 +3,8 @@ BUILDDIR=build_FLD.cpp rm -Rf "$BUILDDIR" mkdir -p "$BUILDDIR" -for FILE in src/FLD.hpp src/*.cpp; do - grep "^#include <" "$FILE" >>"$BUILDDIR/includes" +for FILE in src/*.cpp; do + grep "^#include " "$FILE" >>"$BUILDDIR/includes" printf '/* %s */\n' "$FILE" >>"$BUILDDIR/sources" grep -v '^#include' "$FILE" \ | grep -v "^#pragma" \ diff --git a/src/FLD.hpp b/src/FLD.hpp index 329cc72..1a08a72 100644 --- a/src/FLD.hpp +++ b/src/FLD.hpp @@ -4,6 +4,7 @@ #include #include #include +#include "soloud.h" #define READONLY(T, X, V) private: T _##X = V; public: decltype(_##X) const& X = _##X @@ -78,6 +79,7 @@ public: Point viewport = {0, 0}; const Config config; + SoLoud::Soloud soloud = {}; READONLY(SDL_Window *, window, nullptr); READONLY(SDL_Renderer *, renderer, nullptr); READONLY(SDL_Texture *, target, nullptr); @@ -120,5 +122,6 @@ private: [[nodiscard]] Error initWindow(); [[nodiscard]] Error initRenderer(); [[nodiscard]] Error initTarget(); + [[nodiscard]] Error initSoloud(); void cycleEvents(); }; diff --git a/src/destructor.cpp b/src/destructor.cpp index 1adcb65..4ee6549 100644 --- a/src/destructor.cpp +++ b/src/destructor.cpp @@ -3,6 +3,7 @@ FLD::~FLD() { + soloud.deinit(); for (auto [_, e] : images) if (e.ptr != nullptr) SDL_DestroyTexture(e.ptr); diff --git a/src/init.cpp b/src/init.cpp index 2cd1b2f..062f9b5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -14,7 +14,7 @@ FLD::init(MainLoop main_loop, void *udata) FLD::Error FLD::init() { - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) return sdlError(); if (auto err = initBasepath()) return err; @@ -24,6 +24,8 @@ FLD::init() return err; if (auto err = initTarget()) return err; + if (auto err = initSoloud()) + return err; SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); @@ -93,3 +95,13 @@ FLD::initTarget() return sdlError(); return 0; } + +FLD::Error +FLD::initSoloud() +{ + if (auto err = soloud.init()) { + SDL_Log("soloud runtime error: %s", soloud.getErrorString(err)); + return err; + } + return 0; +} diff --git a/vendors/soloud b/vendors/soloud new file mode 160000 index 0000000..1157475 --- /dev/null +++ b/vendors/soloud @@ -0,0 +1 @@ +Subproject commit 1157475881da0d7f76102578255b937c7d4e8f57 -- cgit v1.2.3