diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-10-22 12:15:03 +0200 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-10-22 12:15:03 +0200 |
commit | 9037aca03bfa4312794a6954752628381256f777 (patch) | |
tree | b5402ae6552ca84bb4cdf9a2f1507dc460a399ac /src/crepe | |
parent | 176ac90fce318334f1377d94d6e637e1eff84c3c (diff) |
merged further and changed to standard
Diffstat (limited to 'src/crepe')
27 files changed, 2 insertions, 431 deletions
diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index addb9dd..d85aef0 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -30,7 +30,4 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES add_subdirectory(api) add_subdirectory(util) -add_subdirectory(fabricator) -add_subdirectory(facade) -add_subdirectory(core) diff --git a/src/crepe/facade/SdlContext.cpp b/src/crepe/SdlContext.cpp index 44d1bdf..44d1bdf 100644 --- a/src/crepe/facade/SdlContext.cpp +++ b/src/crepe/SdlContext.cpp diff --git a/src/crepe/facade/SdlContext.h b/src/crepe/SdlContext.h index c8f1304..c8f1304 100644 --- a/src/crepe/facade/SdlContext.h +++ b/src/crepe/SdlContext.h diff --git a/src/crepe/api/resource_manager.cpp b/src/crepe/api/AssetManager.cpp index 0ecdae5..0ecdae5 100644 --- a/src/crepe/api/resource_manager.cpp +++ b/src/crepe/api/AssetManager.cpp diff --git a/src/crepe/api/resource_manager.h b/src/crepe/api/AssetManager.h index a646d95..a646d95 100644 --- a/src/crepe/api/resource_manager.h +++ b/src/crepe/api/AssetManager.h diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index cecc2f1..9a02580 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -1,9 +1,11 @@ target_sources(crepe PUBLIC # AudioSource.cpp BehaviorScript.cpp + Script.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES # AudioSource.h BehaviorScript.h + Script.h ) diff --git a/src/crepe/facade/Texture.cpp b/src/crepe/api/Texture.cpp index b4e3aa8..b4e3aa8 100644 --- a/src/crepe/facade/Texture.cpp +++ b/src/crepe/api/Texture.cpp diff --git a/src/crepe/facade/Texture.h b/src/crepe/api/Texture.h index db2f1f9..db2f1f9 100644 --- a/src/crepe/facade/Texture.h +++ b/src/crepe/api/Texture.h diff --git a/src/crepe/api/baseResource.h b/src/crepe/api/baseResource.h deleted file mode 100644 index 2513f4d..0000000 --- a/src/crepe/api/baseResource.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -namespace crepe::api { - -class BaseResource { -public: - virtual ~BaseResource() = default; -}; - -} - diff --git a/src/crepe/api/game.cpp b/src/crepe/api/game.cpp deleted file mode 100644 index 01920a9..0000000 --- a/src/crepe/api/game.cpp +++ /dev/null @@ -1,30 +0,0 @@ - - - -#include "game.h" -#include "core/renderSystem.h" -#include "facade/SdlContext.h" - - -Engine::Engine(int windowHeight, int window_with){ - crepe::SdlContext& ctx = crepe::SdlContext::get_instance(); -} - - - -void Engine::loop() { - - bool running = true; - crepe::SdlContext& ctx = crepe::SdlContext::get_instance(); - RenderSystem rendering; - - while (running) { - ctx.handleEvents(running); - - ctx.clearScreen(); - - rendering.render(); - - ctx.presentScreen(); - } -} diff --git a/src/crepe/api/game.h b/src/crepe/api/game.h deleted file mode 100644 index 64027fa..0000000 --- a/src/crepe/api/game.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - - - -class Engine{ - -public: - Engine(int windowWith, int windowHeight); - ~Engine() = default; - - void loop(); - - -private: - int window_height; - int window_width; -}; diff --git a/src/crepe/api/map_asset.cpp b/src/crepe/api/map_asset.cpp deleted file mode 100644 index bbabe2b..0000000 --- a/src/crepe/api/map_asset.cpp +++ /dev/null @@ -1,12 +0,0 @@ - - - - -#include "map_asset.h" - -Map::Map(const std::string& content){ - this->m_content = content; -} - -Map::~Map(){ -} diff --git a/src/crepe/api/map_asset.h b/src/crepe/api/map_asset.h deleted file mode 100644 index a4f3df7..0000000 --- a/src/crepe/api/map_asset.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "Resource.h" -#include <string> - - -using namespace crepe::api; - -class Map : public Resource { - -public: - Map(const std::string& ); - ~Map(); -}; diff --git a/src/crepe/api/spritesheet.cpp b/src/crepe/api/spritesheet.cpp deleted file mode 100644 index 7f5da38..0000000 --- a/src/crepe/api/spritesheet.cpp +++ /dev/null @@ -1,38 +0,0 @@ - - -#include "spritesheet.h" -#include "SDL_rect.h" -#include "SDL_render.h" -#include "api/Resource.h" -#include "facade/SdlContext.h" -#include <memory> - - -using namespace crepe::api; - -Spritesheet::Spritesheet(const char* src, const int row, const int col){ - this->load(std::make_unique<api::Resource>(src), row, col); -} - -Spritesheet::Spritesheet(std::unique_ptr<api::Resource> res, const int row, const int col){ - this->load(std::move(res), row, col); -} - -Spritesheet::~Spritesheet(){ - - if (this->m_spritesheet) { - SDL_DestroyTexture(this->m_spritesheet); - } -} - -void Spritesheet::select_sprite(const int x, const int y){ - m_clip.x = x * m_clip.w; - m_clip.y = y * m_clip.h; -} - -void Spritesheet::load(std::unique_ptr<api::Resource> res, const int row, const int col){ - auto& ctx = SdlContext::get_instance(); - - this->m_spritesheet = ctx.setTextureFromPath(res->canonical(), this->m_clip, row, col); -} - diff --git a/src/crepe/api/spritesheet.h b/src/crepe/api/spritesheet.h deleted file mode 100644 index 503dcef..0000000 --- a/src/crepe/api/spritesheet.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - - - - -#include "Resource.h" -#include "SDL_rect.h" -#include "SDL_render.h" -#include <memory> - - -namespace crepe::api { - -class Spritesheet{ - -public: - Spritesheet(const char * src, const int row , const int col); - Spritesheet(std::unique_ptr<api::Resource> res, const int row, const int col); - ~Spritesheet(); - - void select_sprite(const int x, const int y); - void draw_selected_sprite(const int x, const int y); -private: - void load(std::unique_ptr<api::Resource> res, const int row, const int col);; - SDL_Texture* get_texture() const; - -private: - - SDL_Texture* m_spritesheet; - SDL_Rect m_clip; -}; - -} - diff --git a/src/crepe/core/CMakeLists.txt b/src/crepe/core/CMakeLists.txt deleted file mode 100644 index c44f0f6..0000000 --- a/src/crepe/core/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -target_sources(crepe PUBLIC - renderSystem.cpp -) - -target_sources(crepe PUBLIC FILE_SET HEADERS FILES - renderSystem.h -) - diff --git a/src/crepe/fabricator/CMakeLists.txt b/src/crepe/fabricator/CMakeLists.txt deleted file mode 100644 index 4fd7eea..0000000 --- a/src/crepe/fabricator/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -target_sources(crepe PUBLIC - resource_fabricator.cpp -) - -target_sources(crepe PUBLIC FILE_SET HEADERS FILES - resource_fabricator.h -) - diff --git a/src/crepe/fabricator/resource_fabricator.cpp b/src/crepe/fabricator/resource_fabricator.cpp deleted file mode 100644 index 0633a40..0000000 --- a/src/crepe/fabricator/resource_fabricator.cpp +++ /dev/null @@ -1,26 +0,0 @@ - - -#include "resource_fabricator.h" -#include <fstream> -#include <iostream> -#include <string> -#include <vector> - - - - -std::string ResourceFactory::convert_file_to_string(const std::string& path){ - std::ifstream file(path, std::ios::binary | std::ios::ate); - if (!file.is_open()) { - std::cerr << "Failed to open file: " << path << std::endl; - return ""; - } - - std::ifstream::pos_type fileSize = file.tellg(); - file.seekg(0, std::ios::beg); - - std::vector<char> bytes(fileSize); - file.read(bytes.data(), fileSize); - - return std::string(bytes.begin(), bytes.end()); -} diff --git a/src/crepe/fabricator/resource_fabricator.h b/src/crepe/fabricator/resource_fabricator.h deleted file mode 100644 index 2b0030d..0000000 --- a/src/crepe/fabricator/resource_fabricator.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - - - -#include "api/Resource.h" -#include <memory> -#include <string> - - - - -class ResourceFactory { - -public: - - template<typename T> - static std::unique_ptr<crepe::api::Resource> create_resource(const std::string& file_path){ - - return std::make_unique<T>(convert_file_to_string(file_path)); - } - -private: - static std::string convert_file_to_string(const std::string& path); - -}; - - - - diff --git a/src/crepe/facade/CMakeLists.txt b/src/crepe/facade/CMakeLists.txt deleted file mode 100644 index 1263683..0000000 --- a/src/crepe/facade/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -target_sources(crepe PUBLIC - Sound.cpp - SoundContext.cpp - Texture.cpp - SdlContext.cpp -) - -target_sources(crepe PUBLIC FILE_SET HEADERS FILES - Sound.h - SoundContext.h - Texture.h - SdlContext.h -) diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp deleted file mode 100644 index 64fa281..0000000 --- a/src/crepe/facade/Sound.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "util/log.h" - -#include "Sound.h" -#include "SoundContext.h" - -using namespace crepe; - -Sound::Sound(std::unique_ptr<Asset> res) { - dbg_trace(); - this->load(std::move(res)); -} - -Sound::Sound(const char * src) { - dbg_trace(); - this->load(std::make_unique<Asset>(src)); -} - -void Sound::load(std::unique_ptr<Asset> res) { - this->sample.load(res->canonical()); -} - -void Sound::play() { - SoundContext & ctx = SoundContext::get_instance(); - if (ctx.engine.getPause(this->handle)) { - // resume if paused - ctx.engine.setPause(this->handle, false); - } else { - // or start new sound - this->handle = ctx.engine.play(this->sample, this->volume); - ctx.engine.setLooping(this->handle, this->looping); - } -} - -void Sound::pause() { - SoundContext & ctx = SoundContext::get_instance(); - if (ctx.engine.getPause(this->handle)) return; - ctx.engine.setPause(this->handle, true); -} - -void Sound::rewind() { - SoundContext & ctx = SoundContext::get_instance(); - if (!ctx.engine.isValidVoiceHandle(this->handle)) return; - ctx.engine.seek(this->handle, 0); -} - -void Sound::set_volume(float volume) { - this->volume = volume; - - SoundContext & ctx = SoundContext::get_instance(); - if (!ctx.engine.isValidVoiceHandle(this->handle)) return; - ctx.engine.setVolume(this->handle, this->volume); -} - -void Sound::set_looping(bool looping) { - this->looping = looping; - - SoundContext & ctx = SoundContext::get_instance(); - if (!ctx.engine.isValidVoiceHandle(this->handle)) return; - ctx.engine.setLooping(this->handle, this->looping); -} diff --git a/src/crepe/facade/Sound.h b/src/crepe/facade/Sound.h deleted file mode 100644 index b11f871..0000000 --- a/src/crepe/facade/Sound.h +++ /dev/null @@ -1,82 +0,0 @@ -#pragma once - -#include <soloud/soloud.h> -#include <soloud/soloud_wav.h> - -#include <memory> - -#include "Asset.h" - -namespace crepe { - -class Sound{ -public: - /** - * \brief Pause this sample - * - * Pauses this sound if it is playing, or does nothing if it is already - * paused. The playhead position is saved, such that calling \c play() after - * this function makes the sound resume. - */ - void pause(); - /** - * \brief Play this sample - * - * Resume playback if this sound is paused, or start from the beginning of - * the sample. - * - * \note This class only saves a reference to the most recent 'voice' of this - * sound. Calling \c play() while the sound is already playing causes - * multiple instances of the sample to play simultaniously. The sample - * started last is the one that is controlled afterwards. - */ - void play(); - /** - * \brief Reset playhead position - * - * Resets the playhead position so that calling \c play() after this function - * makes it play from the start of the sample. If the sound is not paused - * before calling this function, this function will stop playback. - */ - void rewind(); - /** - * \brief Set playback volume / gain - * - * \param volume Volume (0 = muted, 1 = full volume) - */ - void set_volume(float volume); - /** - * \brief Get playback volume / gain - * - * \return Volume - */ - float get_volume() const { return this->volume; } - /** - * \brief Set looping behavior for this sample - * - * \param looping Looping behavior (false = one-shot, true = loop) - */ - void set_looping(bool looping); - /** - * \brief Get looping behavior - * - * \return true if looping, false if one-shot - */ - bool get_looping() const { return this->looping; } - -public: - Sound(const char * src); - Sound(std::unique_ptr<Asset> res); - -private: - void load(std::unique_ptr<Asset> res); - -private: - SoLoud::Wav sample; - SoLoud::handle handle; - - float volume = 1.0f; - bool looping = false; -}; - -} // namespace crepe diff --git a/src/crepe/facade/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp deleted file mode 100644 index 72047d2..0000000 --- a/src/crepe/facade/SoundContext.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "util/log.h" - -#include "SoundContext.h" - -using namespace crepe; - -SoundContext & SoundContext::get_instance() { - static SoundContext instance; - return instance; -} - -SoundContext::SoundContext() { - dbg_trace(); - engine.init(); -} - -SoundContext::~SoundContext() { - dbg_trace(); - engine.deinit(); -} diff --git a/src/crepe/facade/SoundContext.h b/src/crepe/facade/SoundContext.h deleted file mode 100644 index d3123d2..0000000 --- a/src/crepe/facade/SoundContext.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include <soloud/soloud.h> - -#include "Sound.h" - -namespace crepe { - -class SoundContext { -private: - SoundContext(); - virtual ~SoundContext(); - - // singleton - static SoundContext & get_instance(); - SoundContext(const SoundContext &) = delete; - SoundContext(SoundContext &&) = delete; - SoundContext & operator=(const SoundContext &) = delete; - SoundContext & operator=(SoundContext &&) = delete; - -private: - SoLoud::Soloud engine; - friend class Sound; -}; - -} // namespace crepe diff --git a/src/crepe/facade/touch b/src/crepe/facade/touch deleted file mode 100644 index e69de29..0000000 --- a/src/crepe/facade/touch +++ /dev/null diff --git a/src/crepe/core/renderSystem.cpp b/src/crepe/renderSystem.cpp index a06aeba..a06aeba 100644 --- a/src/crepe/core/renderSystem.cpp +++ b/src/crepe/renderSystem.cpp diff --git a/src/crepe/core/renderSystem.h b/src/crepe/renderSystem.h index 9011b30..9011b30 100644 --- a/src/crepe/core/renderSystem.h +++ b/src/crepe/renderSystem.h |