├── .gitignore ├── CMakeLists.txt ├── Doxyfile ├── LICENSE ├── README.md ├── compile_commands.json ├── data └── tile_data.json ├── dox └── doc │ ├── Camera.dox │ ├── FastboiCore.dox │ └── Gameobject.dox ├── examples ├── FastboiCore.cpp └── Gameobject.cpp ├── inc ├── SDL │ ├── SDL.h │ ├── SDL_assert.h │ ├── SDL_atomic.h │ ├── SDL_audio.h │ ├── SDL_bits.h │ ├── SDL_blendmode.h │ ├── SDL_clipboard.h │ ├── SDL_config.h │ ├── SDL_cpuinfo.h │ ├── SDL_egl.h │ ├── SDL_endian.h │ ├── SDL_error.h │ ├── SDL_events.h │ ├── SDL_filesystem.h │ ├── SDL_gamecontroller.h │ ├── SDL_gesture.h │ ├── SDL_haptic.h │ ├── SDL_hints.h │ ├── SDL_image.h │ ├── SDL_joystick.h │ ├── SDL_keyboard.h │ ├── SDL_keycode.h │ ├── SDL_loadso.h │ ├── SDL_log.h │ ├── SDL_main.h │ ├── SDL_messagebox.h │ ├── SDL_mouse.h │ ├── SDL_mutex.h │ ├── SDL_name.h │ ├── SDL_opengl.h │ ├── SDL_opengl_glext.h │ ├── SDL_opengles.h │ ├── SDL_opengles2.h │ ├── SDL_opengles2_gl2.h │ ├── SDL_opengles2_gl2ext.h │ ├── SDL_opengles2_gl2platform.h │ ├── SDL_opengles2_khrplatform.h │ ├── SDL_pixels.h │ ├── SDL_platform.h │ ├── SDL_power.h │ ├── SDL_quit.h │ ├── SDL_rect.h │ ├── SDL_render.h │ ├── SDL_revision.h │ ├── SDL_rwops.h │ ├── SDL_scancode.h │ ├── SDL_sensor.h │ ├── SDL_shape.h │ ├── SDL_stdinc.h │ ├── SDL_surface.h │ ├── SDL_system.h │ ├── SDL_syswm.h │ ├── SDL_test.h │ ├── SDL_test_assert.h │ ├── SDL_test_common.h │ ├── SDL_test_compare.h │ ├── SDL_test_crc32.h │ ├── SDL_test_font.h │ ├── SDL_test_fuzzer.h │ ├── SDL_test_harness.h │ ├── SDL_test_images.h │ ├── SDL_test_log.h │ ├── SDL_test_md5.h │ ├── SDL_test_memory.h │ ├── SDL_test_random.h │ ├── SDL_thread.h │ ├── SDL_timer.h │ ├── SDL_touch.h │ ├── SDL_types.h │ ├── SDL_version.h │ ├── SDL_video.h │ ├── SDL_vulkan.h │ ├── begin_code.h │ └── close_code.h ├── Utility.h ├── ctti │ ├── detail │ │ ├── algorithm.hpp │ │ ├── cstring.hpp │ │ ├── entity_name.hpp │ │ ├── hash.hpp │ │ ├── language_features.hpp │ │ ├── meta.hpp │ │ ├── name_filters.hpp │ │ ├── nlohmann_json.hpp │ │ ├── preprocessor.hpp │ │ └── pretty_function.hpp │ ├── detailed_nameof.hpp │ ├── hash_literal.hpp │ ├── map.hpp │ ├── model.hpp │ ├── name.hpp │ ├── nameof.hpp │ ├── serialization.hpp │ ├── static_value.hpp │ ├── symbol.hpp │ ├── symbol_from_hash.hpp │ ├── tie.hpp │ ├── type_id.hpp │ └── type_tag.hpp ├── json │ └── json.hpp ├── nano_ss │ ├── LICENSE │ ├── nano_function.hpp │ ├── nano_mutex.hpp │ ├── nano_observer.hpp │ └── nano_signal_slot.hpp └── soloud │ ├── soloud.h │ ├── soloud_audiosource.h │ ├── soloud_bassboostfilter.h │ ├── soloud_biquadresonantfilter.h │ ├── soloud_bus.h │ ├── soloud_c.h │ ├── soloud_dcremovalfilter.h │ ├── soloud_echofilter.h │ ├── soloud_error.h │ ├── soloud_fader.h │ ├── soloud_fft.h │ ├── soloud_fftfilter.h │ ├── soloud_file.h │ ├── soloud_file_hack_off.h │ ├── soloud_file_hack_on.h │ ├── soloud_filter.h │ ├── soloud_flangerfilter.h │ ├── soloud_freeverbfilter.h │ ├── soloud_internal.h │ ├── soloud_lofifilter.h │ ├── soloud_misc.h │ ├── soloud_monotone.h │ ├── soloud_noise.h │ ├── soloud_openmpt.h │ ├── soloud_queue.h │ ├── soloud_robotizefilter.h │ ├── soloud_sfxr.h │ ├── soloud_speech.h │ ├── soloud_tedsid.h │ ├── soloud_thread.h │ ├── soloud_vic.h │ ├── soloud_vizsn.h │ ├── soloud_wav.h │ ├── soloud_waveshaperfilter.h │ └── soloud_wavstream.h ├── makefile ├── res ├── Sprite-0001.aseprite ├── images │ ├── all_sprites.png │ ├── brick.png │ ├── bridge.png │ ├── button.png │ ├── castle.png │ ├── chalise.png │ ├── gate.png │ ├── ground.jpeg │ ├── grundle.png │ ├── keys.png │ ├── magnet.png │ ├── mc_blocks.png │ ├── pallette.png │ ├── penguin.png │ ├── rhindle.png │ ├── spritemap.png │ ├── sword.png │ ├── tiles.png │ ├── units.png │ └── yorgle.png └── sound │ ├── chomp.mp3 │ ├── death.mp3 │ ├── drop.mp3 │ ├── pickup.mp3 │ ├── slay.mp3 │ ├── win-bad.mp3 │ └── win-good.mp3 └── src ├── AABBTree.cpp ├── AABBTree.h ├── Angles.cpp ├── Angles.h ├── Application.cpp ├── Application.h ├── Archetype.h ├── BoundingBoxRenderer.cpp ├── BoundingBoxRenderer.h ├── BoxColorRenderer.cpp ├── BoxColorRenderer.h ├── CacheLineSize.c ├── CacheLineSize.h ├── Camera.cpp ├── Camera.h ├── ChangeObserver.h ├── ClickTarget.cpp ├── ClickTarget.h ├── Collider.cpp ├── Collider.h ├── Collision.cpp ├── Collision.h ├── CollisionMask.cpp ├── CollisionMask.h ├── ColorComp.h ├── Component.h ├── ComponentReqs.h ├── Events.h ├── Exceptions.h ├── Fastboi.h ├── FastboiComps.h ├── FastboiCore.cpp ├── FastboiCore.h ├── GORef.cpp ├── GORef.h ├── Gameobject.cpp ├── Gameobject.h ├── GameobjectAllocator.cpp ├── GameobjectAllocator.h ├── Input.cpp ├── Input.h ├── Rect.h ├── RectUI.cpp ├── RectUI.h ├── RenderOrder.h ├── Renderer.cpp ├── Renderer.h ├── Rendering.cpp ├── Rendering.h ├── RepeatRenderer.cpp ├── RepeatRenderer.h ├── Resources.cpp ├── Resources.h ├── Rigidbody.cpp ├── Rigidbody.h ├── ScreenElement.cpp ├── ScreenElement.h ├── Shape.cpp ├── Shape.h ├── Slowboi ├── Button.cpp ├── Button.h ├── Game.cpp ├── Game.h ├── GroundBG.cpp ├── GroundBG.h ├── Player.cpp ├── Player.h ├── RequiresTest.cpp └── RequiresTest.h ├── Speaker.cpp ├── Speaker.h ├── SpriteRenderer.cpp ├── SpriteRenderer.h ├── Spritesheet.h ├── Texture.cpp ├── Texture.h ├── Timer.h ├── Transform.cpp ├── Transform.h ├── UI ├── Button.cpp ├── Button.h ├── CommonLayouts.h ├── Screen.cpp ├── Screen.h └── ScreenspaceExpression.h ├── UITexture.cpp ├── UITexture.h ├── Utility.cpp ├── Vec.h ├── WireframeRenderer.cpp ├── WireframeRenderer.h ├── adventure ├── Bridge.cpp ├── Bridge.h ├── Chalise.cpp ├── Chalise.h ├── Dragon.cpp ├── Dragon.h ├── Game.cpp ├── Game.h ├── GameManager.cpp ├── GameManager.h ├── Gate.cpp ├── Gate.h ├── Item.cpp ├── Item.h ├── Layouts.cpp ├── Layouts.h ├── Level.cpp ├── Level.h ├── Magnet.cpp ├── Magnet.h ├── Player.cpp ├── Player.h ├── Room.cpp ├── Room.h ├── RoomCamera.h ├── TestSystem.cpp ├── TestSystem.h └── main.cpp ├── circular_vector.h ├── containmentsimulator ├── Button.cpp ├── Button.h ├── CameraController.cpp ├── CameraController.h ├── Game.cpp ├── Game.h ├── Tile.cpp ├── Tile.h ├── TileData.cpp ├── TileData.h ├── TileManager.cpp ├── TileManager.h ├── WorldEditor.cpp └── WorldEditor.h ├── cute_c2.h ├── minecraft ├── Block.cpp ├── Block.h ├── BlockHighlighter.h ├── Game.cpp ├── Game.h ├── Inventory.cpp ├── Inventory.h ├── Item.h ├── Player.cpp ├── Player.h ├── World.cpp ├── World.h └── main.cpp └── test ├── Collider.cpp ├── Transform.cpp ├── Vec.cpp ├── catch.hpp └── test_main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Cmake 2 | CMakeFiles/ 3 | pkg/ 4 | cmake_install.cmake 5 | CMakeCache.txt 6 | 7 | # deps 8 | deps/ 9 | 10 | 11 | *.exe 12 | *.ilk 13 | *.pdb 14 | *.exp 15 | *.d.lib 16 | *.lib 17 | 18 | clangd_output.json 19 | times.* 20 | 21 | .clangd/ 22 | .cache/ 23 | 24 | # lib/dll files 25 | *.dll 26 | lib/* 27 | 28 | # config files 29 | sdl2-config 30 | 31 | # doxygen 32 | dox/html/ 33 | dox/latex/ 34 | 35 | # vscode 36 | .vscode/ 37 | workspace.code-workspace 38 | 39 | # visual studio debugging 40 | .vs/ 41 | Debug/ 42 | fastboi.sln 43 | fastboi.vcxproj 44 | fastboi.vcxproj.* 45 | src/.vs/ 46 | src/CppProperties.json 47 | x64/ 48 | 49 | # cmake 50 | build/ 51 | cmake/ 52 | .ninja_deps 53 | .ninja_log 54 | *.ninja 55 | Makefile 56 | makefile -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | 3 | if(NOT CMAKE_BUILD_TYPE) 4 | set(CMAKE_BUILD_TYPE Release) 5 | endif() 6 | 7 | set(CMAKE_C_COMPILER clang) 8 | set(CMAKE_CXX_COMPILER clang++) 9 | set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-parentheses-equality -Wno-unused-variable -Wno-unused-function") 10 | set(CMAKE_CXX_FLAGS_DEBUG "-g") 11 | set(CMAKE_CXX_FLAGS_RELEASE "-O3") 12 | 13 | project(FastBoi) 14 | 15 | file(GLOB SRC CONFIGURE_DEPENDS src/*.cpp src/*.hpp src/UI/*.cpp) 16 | 17 | set(CMAKE_CXX_STANDARD 20) 18 | set(CMAKE_EXPORT_COMPILE_COMMANDS True) 19 | 20 | file(GLOB SOLOUD_CORE_SRC deps/soloud/src/core/*.cpp deps/soloud/src/audiosource/wav/*.cpp deps/soloud/src/audiosource/wav/*.c) 21 | set(THIRDPARTY_SRC ${SOLOUD_CORE_SRC} deps/soloud/src/backend/sdl2_static/soloud_sdl2_static.cpp) 22 | 23 | file(GLOB APP_SRC src/adventure/*.cpp) 24 | 25 | link_directories(${CMAKE_SOURCE_DIR}/lib) 26 | 27 | add_executable(adventure ${SRC} ${THIRDPARTY_SRC} ${APP_SRC}) 28 | set_target_properties(adventure PROPERTIES EXCLUDE_FROM_ALL TRUE) 29 | 30 | target_compile_options(adventure PRIVATE -flto=thin) 31 | target_link_options(adventure PRIVATE -fuse-ld=lld -flto=thin) 32 | target_include_directories(adventure PRIVATE inc src inc/soloud inc/SDL) 33 | 34 | target_link_libraries(adventure PRIVATE SDL2 SDL2main SDL2_image) 35 | 36 | target_compile_definitions(adventure PRIVATE WITH_SDL2_STATIC __cpp_lib_ranges) 37 | 38 | 39 | file(GLOB MC_SRC src/minecraft/*.cpp) 40 | add_executable(minecraft ${SRC} ${THIRDPARTY_SRC} ${MC_SRC}) 41 | 42 | target_compile_options(minecraft PRIVATE -flto=thin) 43 | target_link_options(minecraft PRIVATE -fuse-ld=lld -flto=thin) 44 | target_include_directories(minecraft PRIVATE inc src inc/soloud inc/SDL) 45 | 46 | target_link_libraries(minecraft PRIVATE SDL2 SDL2main SDL2_image) 47 | 48 | target_compile_definitions(minecraft PRIVATE WITH_SDL2_STATIC __cpp_lib_ranges) 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /data/tile_data.json: -------------------------------------------------------------------------------- 1 | { 2 | "tiles": [ 3 | { "id": 0, "name": "white_marble", "size": [64, 64], "corner": [1408, 512 ] }, 4 | { "id": 1, "name": "grey_squares", "size": [64, 64], "corner": [1472, 512 ] }, 5 | { "id": 2, "name": "orange_fur", "size": [64, 64], "corner": [1536, 512 ] }, 6 | { "id": 3, "name": "white_squares", "size": [64, 64], "corner": [1408, 576 ] }, 7 | { "id": 4, "name": "blue_squares", "size": [64, 64], "corner": [1472, 576 ] }, 8 | { "id": 5, "name": "tan_swirls", "size": [64, 64], "corner": [1536, 576 ] } 9 | ] 10 | } 11 | 12 | -------------------------------------------------------------------------------- /dox/doc/Camera.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @struct Fastboi::Camera 3 | * @brief Defines the viewport of Fastboi rendering. It does this by keeping track of a transform in either an owning 4 | * or watching manner. 5 | * 6 | * The camera only uses the position of the transform for its viewport calculations. 7 | */ 8 | 9 | /** 10 | * @fn Fastboi::~Camera 11 | * @brief Deletes the transform from memory iff type == Camera::OWNING 12 | */ 13 | /** 14 | * @fn Fastboi::Camera Fastboi::Camera::Camera(const Transform& target, CameraTarget type) 15 | * 16 | * @param target The transform to focus on 17 | * @param type Determines the owning behavior over the target transform. If type == Camera::OWNING, then 18 | * the transform will be deleted from memory upon destruction of the camera, or on Camera::SetTarget(). 19 | * If type == Camera::WATCHING, then the transform will @b not be deleted. 20 | * 21 | */ 22 | 23 | /** 24 | * @fn Position Camera::ScreenToWorldPos(const Position& screenPos) const 25 | * @brief Converts a given position relative to the screen (top-left corner) to its equivalent in the world. 26 | */ 27 | 28 | /** 29 | * @fn Position Camera::WorldToScreenPos(const Position& worldPos) const 30 | * @brief Converts a given world positiontoits equivalent position relative to the screen (top-left corner) 31 | */ 32 | 33 | /** 34 | * @fn bool Camera::IsPointVisible(const Position& worldPos) const 35 | * @brief Returns whether a given point is visible in the camera's viewport. 36 | */ 37 | /** 38 | * @fn void Fastboi::SetCamera(Camera&& camera) 39 | * @brief Sets the global camera 40 | * @param camera This is moved into Fastboi::camera 41 | */ 42 | 43 | /** 44 | * @var Fastboi::Camera Fastboi::camera 45 | * @brief The global camera object. 46 | * 47 | * This is defaulted to a nullptr for target. Trying to render anything in the world or get the targe will cause 48 | * a crash, as there are no checks for nullptr. 49 | */ 50 | -------------------------------------------------------------------------------- /examples/FastboiCore.cpp: -------------------------------------------------------------------------------- 1 | #include "src/Fastboi.h" 2 | #include "src/Slowboi/Game.h" 3 | #include "src/BoxColorRenderer.h" 4 | 5 | using namespace Slowboi; 6 | using namespace Fastboi; 7 | using namespace Slowboi::Componenets; 8 | using namespace Fastboi::Components; 9 | 10 | "Example Instantiate"; 11 | Gameobject& go = Fastboi::Instantiate(); 12 | Bullet& bullet = Fastboi::Instantiate(Position(175, 50), Size(200, 10)); 13 | 14 | "Example Destroy"; 15 | Gameobject& go = Fastboi::Instantiate(); 16 | go.AddComponent(Position(25, 50), Size(30, 30)); 17 | go.AddComponent(go); 18 | 19 | Fastboi::Destroy(go); // When go is destroyed, its Transform and BoxColorRenderer will also be destroyed 20 | -------------------------------------------------------------------------------- /examples/Gameobject.cpp: -------------------------------------------------------------------------------- 1 | #include "FastboiCore.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace Fastboi; 7 | using namespace Fastboi::Components; 8 | 9 | "Example AddComponent" 10 | Gameobject gameobject; 11 | 12 | Transform& transform = gameobject.AddComponent(Position(25, 35), Size(70, 80)); 13 | transform.rotation += 50_deg; 14 | 15 | gameobject.AddComponent(0, 0, 255, 255); 16 | 17 | struct Printer { 18 | GORef go; 19 | std::string s; 20 | 21 | Printer(GORef&& go, std::string s) : go(std::move(go)), s(s) { } 22 | 23 | void Start() { 24 | printf("Starting %s with message '%s'\n", go().name.c_str(), s.c_str()); 25 | } 26 | 27 | void Update() { 28 | printf("Updating %s with message '%s'\n", go().name.c_str(), s.c_str()); 29 | } 30 | }; 31 | 32 | gameobject.AddComponent("A custom component"); 33 | 34 | "Example GetComponent" 35 | Gameobject go; 36 | 37 | go.AddComponent(100, 100, 0, 255); 38 | ColorComp& color = go.GetComponent(); 39 | 40 | 41 | "Example Gameobject" 42 | // The instantiation function for a bullet 43 | void BulletInst(Gameobject& go, const Position& pos, const Vecf& dir) { 44 | go.AddComponent(pos, Size(100.f, 50.f), 0_deg); // Add a transform at the given position, with Size 100, 50 and a rotation of 0 degrees 45 | go.AddComponent(250.f * dir.normalized(), 0_deg); // Give the gameobject a velocity of 250 in the given direction, and 0 rotational velocity 46 | 47 | // Add a collider with a trigger flag of the mask layer PARTICLES. 48 | // Then, only allow it to collide with colliders in the PLAYER or UNITS mask layers. 49 | go.AddComponent(Collider::TRIGGER, CollisionLayer::PARTICLES).mask.Include(CollisionLayer::PLAYER, CollisionLayer::UNITS); 50 | 51 | go.AddComponent(RenderData(RenderOrder::PARTICLES)); // Add a wireframe renderer in the PARTICLES layer 52 | go.AddComponent(255, 0, 0, 255); // Add the color red 53 | } 54 | 55 | // Instantiate a Gameobject following the steps in BulletInst 56 | Gameobject& bullet = Fastboi::Instantiate(Position(500, 350), Vecf(4.f, 1.5f)); 57 | 58 | // And to destroy the bullet, simply do: 59 | Fastboi::Destroy(bullet); -------------------------------------------------------------------------------- /inc/SDL/SDL_clipboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_clipboard.h 24 | * 25 | * Include file for SDL clipboard handling 26 | */ 27 | 28 | #ifndef SDL_clipboard_h_ 29 | #define SDL_clipboard_h_ 30 | 31 | #include "SDL_stdinc.h" 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* Function prototypes */ 40 | 41 | /** 42 | * \brief Put UTF-8 text into the clipboard 43 | * 44 | * \sa SDL_GetClipboardText() 45 | */ 46 | extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text); 47 | 48 | /** 49 | * \brief Get UTF-8 text from the clipboard, which must be freed with SDL_free() 50 | * 51 | * \sa SDL_SetClipboardText() 52 | */ 53 | extern DECLSPEC char * SDLCALL SDL_GetClipboardText(void); 54 | 55 | /** 56 | * \brief Returns a flag indicating whether the clipboard exists and contains a text string that is non-empty 57 | * 58 | * \sa SDL_GetClipboardText() 59 | */ 60 | extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void); 61 | 62 | 63 | /* Ends C function definitions when using C++ */ 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | #include "close_code.h" 68 | 69 | #endif /* SDL_clipboard_h_ */ 70 | 71 | /* vi: set ts=4 sw=4 expandtab: */ 72 | -------------------------------------------------------------------------------- /inc/SDL/SDL_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_error.h 24 | * 25 | * Simple error message routines for SDL. 26 | */ 27 | 28 | #ifndef SDL_error_h_ 29 | #define SDL_error_h_ 30 | 31 | #include "SDL_stdinc.h" 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* Public functions */ 40 | /* SDL_SetError() unconditionally returns -1. */ 41 | extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1); 42 | extern DECLSPEC const char *SDLCALL SDL_GetError(void); 43 | extern DECLSPEC void SDLCALL SDL_ClearError(void); 44 | 45 | /** 46 | * \name Internal error functions 47 | * 48 | * \internal 49 | * Private error reporting function - used internally. 50 | */ 51 | /* @{ */ 52 | #define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM) 53 | #define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED) 54 | #define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param)) 55 | typedef enum 56 | { 57 | SDL_ENOMEM, 58 | SDL_EFREAD, 59 | SDL_EFWRITE, 60 | SDL_EFSEEK, 61 | SDL_UNSUPPORTED, 62 | SDL_LASTERROR 63 | } SDL_errorcode; 64 | /* SDL_Error() unconditionally returns -1. */ 65 | extern DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code); 66 | /* @} *//* Internal error functions */ 67 | 68 | /* Ends C function definitions when using C++ */ 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | #include "close_code.h" 73 | 74 | #endif /* SDL_error_h_ */ 75 | 76 | /* vi: set ts=4 sw=4 expandtab: */ 77 | -------------------------------------------------------------------------------- /inc/SDL/SDL_gesture.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_gesture.h 24 | * 25 | * Include file for SDL gesture event handling. 26 | */ 27 | 28 | #ifndef SDL_gesture_h_ 29 | #define SDL_gesture_h_ 30 | 31 | #include "SDL_stdinc.h" 32 | #include "SDL_error.h" 33 | #include "SDL_video.h" 34 | 35 | #include "SDL_touch.h" 36 | 37 | 38 | #include "begin_code.h" 39 | /* Set up for C function definitions, even when using C++ */ 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | typedef Sint64 SDL_GestureID; 45 | 46 | /* Function prototypes */ 47 | 48 | /** 49 | * \brief Begin Recording a gesture on the specified touch, or all touches (-1) 50 | * 51 | * 52 | */ 53 | extern DECLSPEC int SDLCALL SDL_RecordGesture(SDL_TouchID touchId); 54 | 55 | 56 | /** 57 | * \brief Save all currently loaded Dollar Gesture templates 58 | * 59 | * 60 | */ 61 | extern DECLSPEC int SDLCALL SDL_SaveAllDollarTemplates(SDL_RWops *dst); 62 | 63 | /** 64 | * \brief Save a currently loaded Dollar Gesture template 65 | * 66 | * 67 | */ 68 | extern DECLSPEC int SDLCALL SDL_SaveDollarTemplate(SDL_GestureID gestureId,SDL_RWops *dst); 69 | 70 | 71 | /** 72 | * \brief Load Dollar Gesture templates from a file 73 | * 74 | * 75 | */ 76 | extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src); 77 | 78 | 79 | /* Ends C function definitions when using C++ */ 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | #include "close_code.h" 84 | 85 | #endif /* SDL_gesture_h_ */ 86 | 87 | /* vi: set ts=4 sw=4 expandtab: */ 88 | -------------------------------------------------------------------------------- /inc/SDL/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef SDLname_h_ 23 | #define SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /inc/SDL/SDL_opengles.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_opengles.h 24 | * 25 | * This is a simple file to encapsulate the OpenGL ES 1.X API headers. 26 | */ 27 | #include "SDL_config.h" 28 | 29 | #ifdef __IPHONEOS__ 30 | #include 31 | #include 32 | #else 33 | #include 34 | #include 35 | #endif 36 | 37 | #ifndef APIENTRY 38 | #define APIENTRY 39 | #endif 40 | -------------------------------------------------------------------------------- /inc/SDL/SDL_opengles2.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_opengles2.h 24 | * 25 | * This is a simple file to encapsulate the OpenGL ES 2.0 API headers. 26 | */ 27 | #include "SDL_config.h" 28 | 29 | #ifndef _MSC_VER 30 | 31 | #ifdef __IPHONEOS__ 32 | #include 33 | #include 34 | #else 35 | #include 36 | #include 37 | #include 38 | #endif 39 | 40 | #else /* _MSC_VER */ 41 | 42 | /* OpenGL ES2 headers for Visual Studio */ 43 | #include "SDL_opengles2_khrplatform.h" 44 | #include "SDL_opengles2_gl2platform.h" 45 | #include "SDL_opengles2_gl2.h" 46 | #include "SDL_opengles2_gl2ext.h" 47 | 48 | #endif /* _MSC_VER */ 49 | 50 | #ifndef APIENTRY 51 | #define APIENTRY GL_APIENTRY 52 | #endif 53 | -------------------------------------------------------------------------------- /inc/SDL/SDL_opengles2_gl2platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl2platform_h_ 2 | #define __gl2platform_h_ 3 | 4 | /* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* Platform-specific types and definitions for OpenGL ES 2.X gl2.h 12 | * 13 | * Adopters may modify khrplatform.h and this file to suit their platform. 14 | * You are encouraged to submit all modifications to the Khronos group so that 15 | * they can be included in future versions of this file. Please submit changes 16 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) 17 | * by filing a bug against product "OpenGL-ES" component "Registry". 18 | */ 19 | 20 | /*#include */ 21 | 22 | #ifndef GL_APICALL 23 | #define GL_APICALL KHRONOS_APICALL 24 | #endif 25 | 26 | #ifndef GL_APIENTRY 27 | #define GL_APIENTRY KHRONOS_APIENTRY 28 | #endif 29 | 30 | #endif /* __gl2platform_h_ */ 31 | -------------------------------------------------------------------------------- /inc/SDL/SDL_quit.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_quit.h 24 | * 25 | * Include file for SDL quit event handling. 26 | */ 27 | 28 | #ifndef SDL_quit_h_ 29 | #define SDL_quit_h_ 30 | 31 | #include "SDL_stdinc.h" 32 | #include "SDL_error.h" 33 | 34 | /** 35 | * \file SDL_quit.h 36 | * 37 | * An ::SDL_QUIT event is generated when the user tries to close the application 38 | * window. If it is ignored or filtered out, the window will remain open. 39 | * If it is not ignored or filtered, it is queued normally and the window 40 | * is allowed to close. When the window is closed, screen updates will 41 | * complete, but have no effect. 42 | * 43 | * SDL_Init() installs signal handlers for SIGINT (keyboard interrupt) 44 | * and SIGTERM (system termination request), if handlers do not already 45 | * exist, that generate ::SDL_QUIT events as well. There is no way 46 | * to determine the cause of an ::SDL_QUIT event, but setting a signal 47 | * handler in your application will override the default generation of 48 | * quit events for that signal. 49 | * 50 | * \sa SDL_Quit() 51 | */ 52 | 53 | /* There are no functions directly affecting the quit event */ 54 | 55 | #define SDL_QuitRequested() \ 56 | (SDL_PumpEvents(), (SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUIT,SDL_QUIT) > 0)) 57 | 58 | #endif /* SDL_quit_h_ */ 59 | -------------------------------------------------------------------------------- /inc/SDL/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-12952:bc90ce38f1e2" 2 | #define SDL_REVISION_NUMBER 12952 3 | -------------------------------------------------------------------------------- /inc/SDL/SDL_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_h_ 31 | #define SDL_test_h_ 32 | 33 | #include "SDL.h" 34 | #include "SDL_test_assert.h" 35 | #include "SDL_test_common.h" 36 | #include "SDL_test_compare.h" 37 | #include "SDL_test_crc32.h" 38 | #include "SDL_test_font.h" 39 | #include "SDL_test_fuzzer.h" 40 | #include "SDL_test_harness.h" 41 | #include "SDL_test_images.h" 42 | #include "SDL_test_log.h" 43 | #include "SDL_test_md5.h" 44 | #include "SDL_test_memory.h" 45 | #include "SDL_test_random.h" 46 | 47 | #include "begin_code.h" 48 | /* Set up for C function definitions, even when using C++ */ 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | /* Global definitions */ 54 | 55 | /* 56 | * Note: Maximum size of SDLTest log message is less than SDL's limit 57 | * to ensure we can fit additional information such as the timestamp. 58 | */ 59 | #define SDLTEST_MAX_LOGMESSAGE_LENGTH 3584 60 | 61 | /* Ends C function definitions when using C++ */ 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | #include "close_code.h" 66 | 67 | #endif /* SDL_test_h_ */ 68 | 69 | /* vi: set ts=4 sw=4 expandtab: */ 70 | -------------------------------------------------------------------------------- /inc/SDL/SDL_test_compare.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_compare.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | 32 | Defines comparison functions (i.e. for surfaces). 33 | 34 | */ 35 | 36 | #ifndef SDL_test_compare_h_ 37 | #define SDL_test_compare_h_ 38 | 39 | #include "SDL.h" 40 | 41 | #include "SDL_test_images.h" 42 | 43 | #include "begin_code.h" 44 | /* Set up for C function definitions, even when using C++ */ 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /** 50 | * \brief Compares a surface and with reference image data for equality 51 | * 52 | * \param surface Surface used in comparison 53 | * \param referenceSurface Test Surface used in comparison 54 | * \param allowable_error Allowable difference (=sum of squared difference for each RGB component) in blending accuracy. 55 | * 56 | * \returns 0 if comparison succeeded, >0 (=number of pixels for which the comparison failed) if comparison failed, -1 if any of the surfaces were NULL, -2 if the surface sizes differ. 57 | */ 58 | int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error); 59 | 60 | 61 | /* Ends C function definitions when using C++ */ 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | #include "close_code.h" 66 | 67 | #endif /* SDL_test_compare_h_ */ 68 | 69 | /* vi: set ts=4 sw=4 expandtab: */ 70 | -------------------------------------------------------------------------------- /inc/SDL/SDL_test_images.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_images.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | 32 | Defines some images for tests. 33 | 34 | */ 35 | 36 | #ifndef SDL_test_images_h_ 37 | #define SDL_test_images_h_ 38 | 39 | #include "SDL.h" 40 | 41 | #include "begin_code.h" 42 | /* Set up for C function definitions, even when using C++ */ 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /** 48 | *Type for test images. 49 | */ 50 | typedef struct SDLTest_SurfaceImage_s { 51 | int width; 52 | int height; 53 | unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ 54 | const char *pixel_data; 55 | } SDLTest_SurfaceImage_t; 56 | 57 | /* Test images */ 58 | SDL_Surface *SDLTest_ImageBlit(void); 59 | SDL_Surface *SDLTest_ImageBlitColor(void); 60 | SDL_Surface *SDLTest_ImageBlitAlpha(void); 61 | SDL_Surface *SDLTest_ImageBlitBlendAdd(void); 62 | SDL_Surface *SDLTest_ImageBlitBlend(void); 63 | SDL_Surface *SDLTest_ImageBlitBlendMod(void); 64 | SDL_Surface *SDLTest_ImageBlitBlendNone(void); 65 | SDL_Surface *SDLTest_ImageBlitBlendAll(void); 66 | SDL_Surface *SDLTest_ImageFace(void); 67 | SDL_Surface *SDLTest_ImagePrimitives(void); 68 | SDL_Surface *SDLTest_ImagePrimitivesBlend(void); 69 | 70 | /* Ends C function definitions when using C++ */ 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | #include "close_code.h" 75 | 76 | #endif /* SDL_test_images_h_ */ 77 | 78 | /* vi: set ts=4 sw=4 expandtab: */ 79 | -------------------------------------------------------------------------------- /inc/SDL/SDL_test_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_log.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | * 32 | * Wrapper to log in the TEST category 33 | * 34 | */ 35 | 36 | #ifndef SDL_test_log_h_ 37 | #define SDL_test_log_h_ 38 | 39 | #include "begin_code.h" 40 | /* Set up for C function definitions, even when using C++ */ 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /** 46 | * \brief Prints given message with a timestamp in the TEST category and INFO priority. 47 | * 48 | * \param fmt Message to be logged 49 | */ 50 | void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1); 51 | 52 | /** 53 | * \brief Prints given message with a timestamp in the TEST category and the ERROR priority. 54 | * 55 | * \param fmt Message to be logged 56 | */ 57 | void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1); 58 | 59 | /* Ends C function definitions when using C++ */ 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #include "close_code.h" 64 | 65 | #endif /* SDL_test_log_h_ */ 66 | 67 | /* vi: set ts=4 sw=4 expandtab: */ 68 | -------------------------------------------------------------------------------- /inc/SDL/SDL_test_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_memory.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef SDL_test_memory_h_ 31 | #define SDL_test_memory_h_ 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /** 41 | * \brief Start tracking SDL memory allocations 42 | * 43 | * \note This should be called before any other SDL functions for complete tracking coverage 44 | */ 45 | int SDLTest_TrackAllocations(void); 46 | 47 | /** 48 | * \brief Print a log of any outstanding allocations 49 | * 50 | * \note This can be called after SDL_Quit() 51 | */ 52 | void SDLTest_LogAllocations(void); 53 | 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* SDL_test_memory_h_ */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /inc/SDL/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /inc/SDL/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2019 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #ifndef _begin_code_h 30 | #error close_code.h included without matching begin_code.h 31 | #endif 32 | #undef _begin_code_h 33 | 34 | /* Reset structure packing at previous byte alignment */ 35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | #ifdef __BORLANDC__ 37 | #pragma nopackwarning 38 | #endif 39 | #pragma pack(pop) 40 | #endif /* Compiler needs structure packing set */ 41 | -------------------------------------------------------------------------------- /inc/Utility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | inline size_t hash_cstring(const char* p) { 7 | size_t result = 0; 8 | constexpr size_t prime = 31; 9 | 10 | for (size_t i = 0; p[i] != '\0'; i++) { 11 | result = p[i] + (result * prime); 12 | } 13 | 14 | return result; 15 | } 16 | 17 | struct cstring_hasher { 18 | std::size_t __attribute__((flatten)) operator()(const char* const& p) const { 19 | return hash_cstring(p); 20 | }; 21 | }; 22 | 23 | struct cstring_eq { 24 | bool operator()(const char* const& lhs, const char* const& rhs) const { 25 | return std::strcmp(lhs, rhs) == 0; 26 | } 27 | }; 28 | 29 | struct SDL_Rect; 30 | struct SDL_FRect; 31 | 32 | void print_rect(const SDL_Rect& rect); 33 | void print_rect(const SDL_FRect& rect); -------------------------------------------------------------------------------- /inc/ctti/detail/algorithm.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_DETAIL_ALGORITHM_HPP 2 | #define CTTI_DETAIL_ALGORITHM_HPP 3 | 4 | #include 5 | 6 | namespace ctti 7 | { 8 | 9 | namespace detail 10 | { 11 | 12 | template 13 | constexpr const T* begin(const T(&array)[N]) 14 | { 15 | return &array[0]; 16 | } 17 | 18 | template 19 | constexpr const T* end(const T(&array)[N]) 20 | { 21 | return &array[N]; 22 | } 23 | 24 | template 25 | constexpr bool equal_range(LhsIt lhsBegin, LhsIt lhsEnd, RhsIt rhsBegin, RhsIt rhsEnd) 26 | { 27 | return (lhsBegin != lhsEnd && rhsBegin != rhsEnd) ? *lhsBegin == *rhsBegin && 28 | equal_range(lhsBegin + 1, lhsEnd, rhsBegin + 1, rhsEnd) : (lhsBegin == lhsEnd && rhsBegin == rhsEnd); 29 | } 30 | 31 | template 32 | constexpr const T& max(const T& lhs, const T& rhs) 33 | { 34 | return (lhs >= rhs) ? lhs : rhs; 35 | } 36 | 37 | template 38 | constexpr const T& min(const T& lhs, const T& rhs) 39 | { 40 | return (lhs <= rhs) ? lhs : rhs; 41 | } 42 | 43 | } 44 | 45 | } 46 | 47 | #endif // CTTI_DETAIL_ALGORITHM_HPP 48 | -------------------------------------------------------------------------------- /inc/ctti/detail/entity_name.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_DETAIL_ENTITY_NAME_HPP 2 | #define CTTI_DETAIL_ENTITY_NAME_HPP 3 | 4 | #include "cstring.hpp" 5 | 6 | namespace ctti 7 | { 8 | 9 | namespace detail 10 | { 11 | 12 | class entity_name 13 | { 14 | public: 15 | constexpr entity_name(const ctti::detail::cstring& str) : 16 | _str{str} 17 | {} 18 | 19 | constexpr ctti::detail::cstring str() const 20 | { 21 | return _str; 22 | } 23 | 24 | constexpr ctti::detail::cstring operator[](std::size_t i) const 25 | { 26 | return colon_scan(_str.begin(), _str.end(), i); 27 | } 28 | 29 | private: 30 | ctti::detail::cstring _str; 31 | 32 | constexpr ctti::detail::cstring colon_scan(const char* begin, const char* end, std::size_t i) const 33 | { 34 | return (begin == end) ? {begin, end} : 35 | (i == 0) ? {begin, end} 36 | (colon_count == 0 && *begin == ':') ? colon_scan(++begin, end, i, ++colon_count) : 37 | (colon_count == 1 && *begin == ':') ? colon_scan(++begin, end, i - 1, 0) 38 | ( 39 | } 40 | }; 41 | 42 | } 43 | 44 | } 45 | 46 | #endif // CTTI_DETAIL_ENTITY_NAME_HPP 47 | -------------------------------------------------------------------------------- /inc/ctti/detail/hash.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_DETAIL_HASH_HPP 2 | #define CTTI_DETAIL_HASH_HPP 3 | 4 | #include 5 | 6 | namespace ctti 7 | { 8 | namespace detail 9 | { 10 | // From https://github.com/foonathan/string_id. As usually, thanks Jonathan. 11 | 12 | using hash_t = std::uint64_t; 13 | 14 | // See http://www.isthe.com/chongo/tech/comp/fnv/#FNV-param 15 | constexpr hash_t fnv_basis = 14695981039346656037ull; 16 | constexpr hash_t fnv_prime = 1099511628211ull; 17 | 18 | // FNV-1a 64 bit hash 19 | constexpr hash_t fnv1a_hash(std::size_t n, const char *str, hash_t hash = fnv_basis) 20 | { 21 | return n > 0 ? fnv1a_hash(n - 1, str + 1, (hash ^ *str) * fnv_prime) : hash; 22 | } 23 | 24 | template 25 | constexpr hash_t fnv1a_hash(const char (&array)[N]) 26 | { 27 | return fnv1a_hash(N - 1, &array[0]); 28 | } 29 | } 30 | } 31 | 32 | #endif /* CTTI_DETAIL_HASH_HPP */ 33 | -------------------------------------------------------------------------------- /inc/ctti/detail/language_features.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_LANGUAGE_FEATURES_HPP 2 | #define CTTI_LANGUAGE_FEATURES_HPP 3 | 4 | #ifdef __cpp_variable_templates 5 | #define CTTI_HAS_VARIABLE_TEMPLATES 6 | #endif // __cpp_variable_templates 7 | 8 | #define CTTI_HAS_CONSTEXPR_PRETTY_FUNCTION 9 | 10 | #if defined(__GCC__) && __GCC__ < 5 11 | #undef CTTI_HAS_CONSTEXPR_PRETTY_FUNCTION 12 | #endif // GCC 4.x 13 | 14 | #ifdef __clang__ 15 | #define CTTI_HAS_ENUM_AWARE_PRETTY_FUNCTION 16 | #endif // __clang__ 17 | 18 | #endif // CTTI_LANGUAGE_FEATURES_HPP 19 | -------------------------------------------------------------------------------- /inc/ctti/detail/name_filters.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_DETAIL_NAMEFILTERS_HPP 2 | #define CTTI_DETAIL_NAMEFILTERS_HPP 3 | 4 | #include "cstring.hpp" 5 | 6 | namespace ctti 7 | { 8 | 9 | namespace detail 10 | { 11 | 12 | constexpr ctti::detail::cstring filter_prefix(const ctti::detail::cstring& str, const ctti::detail::cstring& prefix) 13 | { 14 | return str.size() >= prefix.size() ? (str(0, prefix.size()) == prefix ? str(prefix.size(), str.size()) : str) : str; 15 | } 16 | 17 | constexpr ctti::detail::cstring leftpad(const ctti::detail::cstring& str) 18 | { 19 | return (str.size() > 0 && str[0] == ' ') ? leftpad(str(1, str.size())) : str; 20 | } 21 | 22 | constexpr ctti::detail::cstring filter_class(const ctti::detail::cstring& type_name) 23 | { 24 | return leftpad(filter_prefix(leftpad(type_name), "class")); 25 | } 26 | 27 | constexpr ctti::detail::cstring filter_struct(const ctti::detail::cstring& type_name) 28 | { 29 | return leftpad(filter_prefix(leftpad(type_name), "struct")); 30 | } 31 | 32 | constexpr ctti::detail::cstring filter_typename_prefix(const ctti::detail::cstring& type_name) 33 | { 34 | return filter_struct(filter_class(type_name)); 35 | } 36 | 37 | namespace 38 | { 39 | 40 | constexpr const char* find_ith_impl(const ctti::detail::cstring& name, const ctti::detail::cstring& substring, const char* res, std::size_t i, bool infinite = false) 41 | { 42 | return (name.length() >= substring.length()) ? 43 | ((name(0, substring.length()) == substring) ? 44 | ((i == 0) ? 45 | name.begin() 46 | : 47 | find_ith_impl(name(substring.length(), name.length()), substring, name.begin(), i - 1, infinite)) 48 | : 49 | find_ith_impl(name(1, name.length()), substring, res, i, infinite)) 50 | : 51 | (!infinite) ? name.end() : res; 52 | } 53 | 54 | } 55 | 56 | constexpr const char* find_ith(const ctti::detail::cstring& name, const ctti::detail::cstring& substring, std::size_t i) 57 | { 58 | return find_ith_impl(name, substring, name.end(), i); 59 | } 60 | 61 | constexpr const char* find_last(const ctti::detail::cstring& name, const ctti::detail::cstring& substring) 62 | { 63 | return find_ith_impl(name, substring, name.end(), -1, true); 64 | } 65 | 66 | constexpr const char* find(const ctti::detail::cstring& name, const ctti::detail::cstring& substring) 67 | { 68 | return find_ith(name, substring, 0); 69 | } 70 | 71 | 72 | 73 | } 74 | 75 | } 76 | 77 | #endif // CTTI_DETAIL_NAMEFILTERS_HPP 78 | -------------------------------------------------------------------------------- /inc/ctti/detail/preprocessor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_DETAIL_PREPROCESSOR_HPP 2 | #define CTTI_DETAIL_PREPROCESSOR_HPP 3 | 4 | #define CTTI_PP_STR_IMPL(x) #x 5 | #define CTTI_PP_STR(x) CTTI_PP_STR_IMPL(x) 6 | 7 | #endif // CTTI_DETAIL_PREPROCESSOR_HPP 8 | -------------------------------------------------------------------------------- /inc/ctti/detailed_nameof.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_DETAILED_NAMEOF_HPP 2 | #define CTTI_DETAILED_NAMEOF_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace ctti 9 | { 10 | 11 | 12 | template 13 | constexpr name_t detailed_nameof() 14 | { 15 | return {ctti::nameof()}; 16 | } 17 | 18 | template 19 | constexpr name_t detailed_nameof() 20 | { 21 | return {ctti::nameof()}; 22 | } 23 | 24 | #ifdef CTTI_HAS_VARIABLE_TEMPLATES 25 | template 26 | constexpr ctti::name_t detailed_nameof_v = ctti::detailed_nameof(); 27 | 28 | // CONSIDER USING detailed_nameof_v INSTEAD 29 | template 30 | constexpr ctti::name_t detailed_nameof_value_v = ctti::detailed_nameof(); 31 | #endif // CTTI_HAS_VARIABLE_TEMPLATES 32 | 33 | } 34 | 35 | #endif // CTTI_DETAILED_NAMEOF_HPP 36 | -------------------------------------------------------------------------------- /inc/ctti/hash_literal.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_HASH_LITERAL_HPP 2 | #define CTTI_HASH_LITERAL_HPP 3 | 4 | #include 5 | 6 | #ifdef CTI_HASH_LITERAL_NAMESPACE 7 | namespace CTTI_HASH_LITERAL_NAMESPACE 8 | { 9 | #endif // CTTI_HASH_LITERAL_NAMESPACE 10 | 11 | constexpr std::uint64_t operator"" _sh(const char* str, std::size_t length) 12 | { 13 | return ctti::detail::cstring{str, length}.hash(); 14 | } 15 | 16 | #ifdef CTTI_HASH_LITERAL_NAMESPACE 17 | } 18 | #endif // CTTI_HASH_LITERAL_NAMESPACE 19 | 20 | #endif // CTTI_HASH_LITERAL_HPP 21 | -------------------------------------------------------------------------------- /inc/ctti/model.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_MODEL_HPP 2 | #define CTTI_MODEL_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace ctti 9 | { 10 | 11 | template 12 | struct model 13 | { 14 | using symbols = ctti::meta::list; 15 | }; 16 | 17 | template 18 | ctti::model<> ctti_model(ctti::type_tag); 19 | 20 | namespace detail 21 | { 22 | template 23 | struct get_model 24 | { 25 | using type = decltype(ctti_model(ctti::type_tag())); 26 | }; 27 | 28 | template 29 | struct get_model> 30 | { 31 | using type = typename T::ctti_model; 32 | }; 33 | } 34 | 35 | template 36 | using get_model = typename ctti::detail::get_model::type; 37 | 38 | template 39 | struct has_model : public ctti::meta::bool_< 40 | (ctti::meta::list_size>() > 0) 41 | > {}; 42 | 43 | } 44 | 45 | #endif // CTTI_MODEL_HPP 46 | -------------------------------------------------------------------------------- /inc/ctti/static_value.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_DETAIL_STATIC_VALUE_HPP 2 | #define CTTI_DETAIL_STATIC_VALUE_HPP 3 | 4 | namespace ctti 5 | { 6 | 7 | template 8 | struct static_value 9 | { 10 | constexpr static_value() = default; 11 | using value_type = T; 12 | static constexpr value_type value = Value; 13 | 14 | constexpr operator value_type() const 15 | { 16 | return Value; 17 | } 18 | 19 | constexpr value_type get() const 20 | { 21 | return Value; 22 | } 23 | 24 | friend constexpr bool operator==(const static_value& lhs, const value_type rhs) 25 | { 26 | return lhs.get() == rhs; 27 | } 28 | 29 | friend constexpr bool operator==(const value_type lhs, const static_value& rhs) 30 | { 31 | return rhs == lhs; 32 | } 33 | 34 | friend constexpr bool operator!=(const static_value& lhs, const value_type rhs) 35 | { 36 | return !(lhs == rhs); 37 | } 38 | 39 | friend constexpr bool operator!=(const value_type lhs, const static_value& rhs) 40 | { 41 | return !(lhs == rhs); 42 | } 43 | }; 44 | 45 | template 46 | constexpr T static_value::value; 47 | 48 | } 49 | 50 | #define CTTI_STATIC_VALUE(x) ::ctti::static_value 51 | 52 | #endif // CTTI_DETAIL_STATIC_VALUE_HPP 53 | -------------------------------------------------------------------------------- /inc/ctti/symbol_from_hash.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_SYMBOL_FROM_HASH_HPP 2 | #define CTTI_SYMBOL_FROM_HASH_HPP 3 | 4 | #include 5 | 6 | namespace ctti 7 | { 8 | 9 | template 10 | using symbol_from_hash = decltype(ctti_symbol_from_hash(ctti::meta::uint64_t())); 11 | 12 | } 13 | 14 | 15 | #endif // CTTI_SYMBOL_FROM_HASH_HPP 16 | -------------------------------------------------------------------------------- /inc/ctti/tie.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_TIE_HPP 2 | #define CTTI_TIE_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace ctti 9 | { 10 | 11 | namespace detail 12 | { 13 | 14 | template 15 | struct tie_t; 16 | 17 | template 18 | struct tie_t, ctti::meta::list> 19 | { 20 | constexpr tie_t(Refs&... refs) : 21 | _refs{refs...} 22 | {} 23 | 24 | template 25 | void operator=(const T& object) 26 | { 27 | assign(object, ctti::meta::make_index_sequence_for()); 28 | } 29 | 30 | private: 31 | template 32 | using Symbol = ctti::meta::pack_get_t; 33 | 34 | 35 | template::template is_member_of() 37 | >::type> 38 | void assign_member(const T& object) 39 | { 40 | std::get(_refs) = ctti::get_member_value>(object); 41 | } 42 | 43 | template::template is_member_of() 45 | >::type> 46 | void assign_member(const T& object) 47 | {} 48 | 49 | template 50 | void assign(const T& object, ctti::meta::index_sequence) 51 | { 52 | [](...){}((tie_t::assign_member(object), 42)...); 53 | } 54 | 55 | std::tuple _refs; 56 | }; 57 | 58 | } 59 | 60 | template 61 | constexpr ctti::detail::tie_t< 62 | ctti::meta::list, ctti::meta::list 63 | > tie(Refs&... refs) 64 | { 65 | return {refs...}; 66 | } 67 | 68 | } 69 | 70 | #endif // CTTI_TIE_HPP 71 | -------------------------------------------------------------------------------- /inc/ctti/type_tag.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CTTI_TYPE_TAG_HPP 2 | #define CTTI_TYPE_TAG_HPP 3 | 4 | namespace ctti 5 | { 6 | 7 | template 8 | struct type_tag 9 | { 10 | constexpr type_tag() = default; 11 | using type = T; 12 | }; 13 | 14 | } 15 | 16 | #endif // CTTI_TYPE_TAG_HPP 17 | -------------------------------------------------------------------------------- /inc/nano_ss/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2012-2019 ApEk, NoAvailableAlias, Nano-signal-slot Contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /inc/nano_ss/nano_function.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Nano 7 | { 8 | 9 | using Delegate_Key = std::array; 10 | 11 | template class Function; 12 | template 13 | class Function final 14 | { 15 | // Only Nano::Observer is allowed private access 16 | template friend class Observer; 17 | 18 | using Thunk = RT(*)(void*, Args&&...); 19 | 20 | static inline Function bind(Delegate_Key const& delegate_key) 21 | { 22 | return 23 | { 24 | reinterpret_cast(delegate_key[0]), 25 | reinterpret_cast(delegate_key[1]) 26 | }; 27 | } 28 | 29 | public: 30 | 31 | void* const instance_pointer; 32 | const Thunk function_pointer; 33 | 34 | template 35 | static inline Function bind() 36 | { 37 | return 38 | { 39 | nullptr, [](void* /*NULL*/, Args&&... args) 40 | { 41 | return (*fun_ptr)(std::forward(args)...); 42 | } 43 | }; 44 | } 45 | 46 | template 47 | static inline Function bind(T* pointer) 48 | { 49 | return 50 | { 51 | pointer, [](void* this_ptr, Args&&... args) 52 | { 53 | return (static_cast(this_ptr)->*mem_ptr)(std::forward(args)...); 54 | } 55 | }; 56 | } 57 | 58 | template 59 | static inline Function bind(L* pointer) 60 | { 61 | return 62 | { 63 | pointer, [](void *this_ptr, Args&&... args) 64 | { 65 | return static_cast(this_ptr)->operator()(std::forward(args)...); 66 | } 67 | }; 68 | } 69 | 70 | inline RT operator() (Args... args) 71 | { 72 | return (*function_pointer)(instance_pointer, std::forward(args)...); 73 | } 74 | 75 | inline operator Delegate_Key() const 76 | { 77 | return 78 | { 79 | reinterpret_cast(instance_pointer), 80 | reinterpret_cast(function_pointer) 81 | }; 82 | } 83 | }; 84 | 85 | } // namespace Nano ------------------------------------------------------------ 86 | -------------------------------------------------------------------------------- /inc/soloud/soloud_bassboostfilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2015 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_BASSBOOSTFILTER_H 26 | #define SOLOUD_BASSBOOSTFILTER_H 27 | 28 | #include "soloud.h" 29 | #include "soloud_fftfilter.h" 30 | 31 | namespace SoLoud 32 | { 33 | class BassboostFilter; 34 | 35 | class BassboostFilterInstance : public FFTFilterInstance 36 | { 37 | enum FILTERATTRIBUTE 38 | { 39 | WET = 0, 40 | BOOST = 1 41 | }; 42 | BassboostFilter *mParent; 43 | public: 44 | virtual void fftFilterChannel(float *aFFTBuffer, unsigned int aSamples, float aSamplerate, time aTime, unsigned int aChannel, unsigned int aChannels); 45 | BassboostFilterInstance(BassboostFilter *aParent); 46 | }; 47 | 48 | class BassboostFilter : public FFTFilter 49 | { 50 | public: 51 | enum FILTERATTRIBUTE 52 | { 53 | WET = 0, 54 | BOOST = 1 55 | }; 56 | virtual int getParamCount(); 57 | virtual const char* getParamName(unsigned int aParamIndex); 58 | virtual unsigned int getParamType(unsigned int aParamIndex); 59 | virtual float getParamMax(unsigned int aParamIndex); 60 | virtual float getParamMin(unsigned int aParamIndex); 61 | float mBoost; 62 | result setParams(float aBoost); 63 | virtual FilterInstance *createInstance(); 64 | BassboostFilter(); 65 | }; 66 | } 67 | 68 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_dcremovalfilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2015 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_DCREMOVAL_H 26 | #define SOLOUD_DCREMOVAL_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | class DCRemovalFilter; 33 | 34 | class DCRemovalFilterInstance : public FilterInstance 35 | { 36 | float *mBuffer; 37 | float *mTotals; 38 | int mBufferLength; 39 | DCRemovalFilter *mParent; 40 | int mOffset; 41 | 42 | public: 43 | virtual void filter(float *aBuffer, unsigned int aSamples, unsigned int aChannels, float aSamplerate, time aTime); 44 | virtual ~DCRemovalFilterInstance(); 45 | DCRemovalFilterInstance(DCRemovalFilter *aParent); 46 | }; 47 | 48 | class DCRemovalFilter : public Filter 49 | { 50 | public: 51 | float mLength; 52 | virtual FilterInstance *createInstance(); 53 | DCRemovalFilter(); 54 | result setParams(float aLength = 0.1f); 55 | }; 56 | } 57 | 58 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_echofilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2020 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_ECHOFILTER_H 26 | #define SOLOUD_ECHOFILTER_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | class EchoFilter; 33 | 34 | class EchoFilterInstance : public FilterInstance 35 | { 36 | float *mBuffer; 37 | int mBufferLength; 38 | int mBufferMaxLength; 39 | int mOffset; 40 | 41 | public: 42 | virtual void filter(float *aBuffer, unsigned int aSamples, unsigned int aChannels, float aSamplerate, time aTime); 43 | virtual ~EchoFilterInstance(); 44 | EchoFilterInstance(EchoFilter *aParent); 45 | }; 46 | 47 | class EchoFilter : public Filter 48 | { 49 | public: 50 | enum FILTERATTRIBUTE 51 | { 52 | WET = 0, 53 | DELAY, 54 | DECAY, 55 | FILTER 56 | }; 57 | float mDelay; 58 | float mDecay; 59 | float mFilter; 60 | virtual int getParamCount(); 61 | virtual const char* getParamName(unsigned int aParamIndex); 62 | virtual unsigned int getParamType(unsigned int aParamIndex); 63 | virtual float getParamMax(unsigned int aParamIndex); 64 | virtual float getParamMin(unsigned int aParamIndex); 65 | virtual FilterInstance *createInstance(); 66 | EchoFilter(); 67 | result setParams(float aDelay, float aDecay = 0.7f, float aFilter = 0.0f); 68 | }; 69 | } 70 | 71 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2014 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | #ifndef SOLOUD_ERROR_H 25 | #define SOLOUD_ERROR_H 26 | 27 | namespace SoLoud 28 | { 29 | enum SOLOUD_ERRORS 30 | { 31 | SO_NO_ERROR = 0, // No error 32 | INVALID_PARAMETER = 1, // Some parameter is invalid 33 | FILE_NOT_FOUND = 2, // File not found 34 | FILE_LOAD_FAILED = 3, // File found, but could not be loaded 35 | DLL_NOT_FOUND = 4, // DLL not found, or wrong DLL 36 | OUT_OF_MEMORY = 5, // Out of memory 37 | NOT_IMPLEMENTED = 6, // Feature not implemented 38 | UNKNOWN_ERROR = 7 // Other error 39 | }; 40 | }; 41 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_fader.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2014 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_FADER_H 26 | #define SOLOUD_FADER_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | // Helper class to process faders 33 | class Fader 34 | { 35 | public: 36 | // Value to fade from 37 | float mFrom; 38 | // Value to fade to 39 | float mTo; 40 | // Delta between from and to 41 | float mDelta; 42 | // Total time to fade 43 | time mTime; 44 | // Time fading started 45 | time mStartTime; 46 | // Time fading will end 47 | time mEndTime; 48 | // Current value. Used in case time rolls over. 49 | float mCurrent; 50 | // Active flag; 0 means disabled, 1 is active, 2 is LFO, -1 means was active, but stopped 51 | int mActive; 52 | // Ctor 53 | Fader(); 54 | // Set up LFO 55 | void setLFO(float aFrom, float aTo, time aTime, time aStartTime); 56 | // Set up fader 57 | void set(float aFrom, float aTo, time aTime, time aStartTime); 58 | // Get the current fading value 59 | float get(time aCurrentTime); 60 | }; 61 | }; 62 | 63 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_fft.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2015 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_FFT_H 26 | #define SOLOUD_FFT_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | namespace FFT 33 | { 34 | // Perform 1024 unit FFT. Buffer must have 1024 floats, and will be overwritten 35 | void fft1024(float *aBuffer); 36 | 37 | // Perform 256 unit FFT. Buffer must have 256 floats, and will be overwritten 38 | void fft256(float *aBuffer); 39 | 40 | // Perform 256 unit IFFT. Buffer must have 256 floats, and will be overwritten 41 | void ifft256(float *aBuffer); 42 | 43 | // Generic (slower) power of two FFT. Buffer is overwritten. 44 | void fft(float *aBuffer, unsigned int aBufferLength); 45 | 46 | // Generic (slower) power of two IFFT. Buffer is overwritten. 47 | void ifft(float *aBuffer, unsigned int aBufferLength); 48 | }; 49 | }; 50 | 51 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_fftfilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2015 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_FFTFILTER_H 26 | #define SOLOUD_FFTFILTER_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | class FFTFilter; 33 | 34 | class FFTFilterInstance : public FilterInstance 35 | { 36 | float *mTemp; 37 | float *mInputBuffer; 38 | float *mMixBuffer; 39 | unsigned int mOffset[MAX_CHANNELS]; 40 | FFTFilter *mParent; 41 | public: 42 | virtual void fftFilterChannel(float *aFFTBuffer, unsigned int aSamples, float aSamplerate, time aTime, unsigned int aChannel, unsigned int aChannels); 43 | virtual void filterChannel(float *aBuffer, unsigned int aSamples, float aSamplerate, time aTime, unsigned int aChannel, unsigned int aChannels); 44 | virtual ~FFTFilterInstance(); 45 | FFTFilterInstance(FFTFilter *aParent); 46 | FFTFilterInstance(); 47 | }; 48 | 49 | class FFTFilter : public Filter 50 | { 51 | public: 52 | virtual FilterInstance *createInstance(); 53 | FFTFilter(); 54 | }; 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_file_hack_off.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2020 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | /* 26 | See soloud_file_hack_on.h 27 | */ 28 | 29 | #undef FILE 30 | #undef fgetc 31 | #undef fread 32 | #undef fseek 33 | #undef ftell 34 | #undef fclose 35 | #undef fopen 36 | #undef fopen_s 37 | -------------------------------------------------------------------------------- /inc/soloud/soloud_file_hack_on.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2020 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | /* 26 | This is a "hack" header to fool third party code to use our File stuff instead 27 | of stdio FILE* stuff. 28 | You can use soloud_file_hack_off.h to undef the stuff defined here. 29 | */ 30 | 31 | #ifndef SEEK_SET 32 | #error soloud_file_hack_on must be included after stdio, otherwise the #define hacks will break stdio. 33 | #endif 34 | 35 | typedef void* Soloud_Filehack; 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | extern int Soloud_Filehack_fgetc(Soloud_Filehack *f); 42 | extern int Soloud_Filehack_fread(void *dst, int s, int c, Soloud_Filehack *f); 43 | extern int Soloud_Filehack_fseek(Soloud_Filehack *f, int idx, int base); 44 | extern int Soloud_Filehack_ftell(Soloud_Filehack *f); 45 | extern int Soloud_Filehack_fclose(Soloud_Filehack *f); 46 | extern Soloud_Filehack * Soloud_Filehack_fopen(const char *aFilename, char *aMode); 47 | extern int Soloud_Filehack_fopen_s(Soloud_Filehack **f, const char* aFilename, char* aMode); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #define FILE Soloud_Filehack 54 | #define fgetc Soloud_Filehack_fgetc 55 | #define fread Soloud_Filehack_fread 56 | #define fseek Soloud_Filehack_fseek 57 | #define ftell Soloud_Filehack_ftell 58 | #define fclose Soloud_Filehack_fclose 59 | #define fopen Soloud_Filehack_fopen 60 | #define fopen_s Soloud_Filehack_fopen_s 61 | -------------------------------------------------------------------------------- /inc/soloud/soloud_flangerfilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2020 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_FLANGERFILTER_H 26 | #define SOLOUD_FLANGERFILTER_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | class FlangerFilter; 33 | 34 | class FlangerFilterInstance : public FilterInstance 35 | { 36 | float *mBuffer; 37 | unsigned int mBufferLength; 38 | FlangerFilter *mParent; 39 | unsigned int mOffset; 40 | double mIndex; 41 | 42 | public: 43 | virtual void filter(float *aBuffer, unsigned int aSamples, unsigned int aChannels, float aSamplerate, time aTime); 44 | virtual ~FlangerFilterInstance(); 45 | FlangerFilterInstance(FlangerFilter *aParent); 46 | }; 47 | 48 | class FlangerFilter : public Filter 49 | { 50 | public: 51 | enum FILTERPARAMS 52 | { 53 | WET, 54 | DELAY, 55 | FREQ 56 | }; 57 | float mDelay; 58 | float mFreq; 59 | virtual int getParamCount(); 60 | virtual const char* getParamName(unsigned int aParamIndex); 61 | virtual unsigned int getParamType(unsigned int aParamIndex); 62 | virtual float getParamMax(unsigned int aParamIndex); 63 | virtual float getParamMin(unsigned int aParamIndex); 64 | virtual FilterInstance *createInstance(); 65 | FlangerFilter(); 66 | result setParams(float aDelay, float aFreq); 67 | }; 68 | } 69 | 70 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_freeverbfilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2020 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_FREEVERBFILTER_H 26 | #define SOLOUD_FREEVERBFILTER_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | class FreeverbFilter; 33 | namespace FreeverbImpl 34 | { 35 | class Revmodel; 36 | } 37 | 38 | class FreeverbFilterInstance : public FilterInstance 39 | { 40 | enum FILTERPARAM { 41 | WET = 0, 42 | FREEZE, 43 | ROOMSIZE, 44 | DAMP, 45 | WIDTH 46 | }; 47 | 48 | FreeverbFilter *mParent; 49 | FreeverbImpl::Revmodel *mModel; 50 | public: 51 | virtual void filter(float* aBuffer, unsigned int aSamples, unsigned int aChannels, float aSamplerate, time aTime); 52 | virtual ~FreeverbFilterInstance(); 53 | FreeverbFilterInstance(FreeverbFilter *aParent); 54 | }; 55 | 56 | class FreeverbFilter : public Filter 57 | { 58 | public: 59 | enum FILTERPARAM { 60 | WET = 0, 61 | FREEZE, 62 | ROOMSIZE, 63 | DAMP, 64 | WIDTH 65 | }; 66 | virtual int getParamCount(); 67 | virtual const char* getParamName(unsigned int aParamIndex); 68 | virtual unsigned int getParamType(unsigned int aParamIndex); 69 | virtual float getParamMax(unsigned int aParamIndex); 70 | virtual float getParamMin(unsigned int aParamIndex); 71 | 72 | float mMode; 73 | float mRoomSize; 74 | float mDamp; 75 | float mWidth; 76 | virtual FreeverbFilterInstance *createInstance(); 77 | FreeverbFilter(); 78 | result setParams(float aMode, float aRoomSize, float aDamp, float aWidth); 79 | virtual ~FreeverbFilter(); 80 | }; 81 | } 82 | 83 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_lofifilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2020 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_LOFIFILTER_H 26 | #define SOLOUD_LOFIFILTER_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | class LofiFilter; 33 | 34 | struct LofiChannelData 35 | { 36 | float mSample; 37 | float mSamplesToSkip; 38 | }; 39 | 40 | class LofiFilterInstance : public FilterInstance 41 | { 42 | enum FILTERPARAMS 43 | { 44 | WET, 45 | SAMPLERATE, 46 | BITDEPTH 47 | }; 48 | LofiChannelData mChannelData[2]; 49 | 50 | LofiFilter *mParent; 51 | public: 52 | virtual void filterChannel(float *aBuffer, unsigned int aSamples, float aSamplerate, time aTime, unsigned int aChannel, unsigned int aChannels); 53 | virtual ~LofiFilterInstance(); 54 | LofiFilterInstance(LofiFilter *aParent); 55 | }; 56 | 57 | class LofiFilter : public Filter 58 | { 59 | public: 60 | enum FILTERPARAMS 61 | { 62 | WET, 63 | SAMPLERATE, 64 | BITDEPTH 65 | }; 66 | float mSampleRate; 67 | float mBitdepth; 68 | virtual LofiFilterInstance *createInstance(); 69 | virtual int getParamCount(); 70 | virtual const char* getParamName(unsigned int aParamIndex); 71 | virtual unsigned int getParamType(unsigned int aParamIndex); 72 | virtual float getParamMax(unsigned int aParamIndex); 73 | virtual float getParamMin(unsigned int aParamIndex); 74 | LofiFilter(); 75 | result setParams(float aSampleRate, float aBitdepth); 76 | virtual ~LofiFilter(); 77 | }; 78 | } 79 | 80 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2020 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_MISC_H 26 | #define SOLOUD_MISC_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | namespace Misc 33 | { 34 | enum WAVEFORM 35 | { 36 | WAVE_SQUARE = 0, 37 | WAVE_SAW, 38 | WAVE_SIN, 39 | WAVE_TRIANGLE, 40 | WAVE_BOUNCE, 41 | WAVE_JAWS, 42 | WAVE_HUMPS, 43 | WAVE_FSQUARE, 44 | WAVE_FSAW 45 | }; 46 | // Generate a waveform. 47 | float generateWaveform(int aWaveform, float p); 48 | 49 | // WELL512 random 50 | class Prg 51 | { 52 | public: 53 | // random generator 54 | Prg(); 55 | unsigned int mState[16]; 56 | unsigned int mIndex; 57 | unsigned int rand(); 58 | float rand_float(); 59 | void srand(int aSeed); 60 | }; 61 | 62 | }; 63 | }; 64 | 65 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_noise.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2020 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_NOISE_H 26 | #define SOLOUD_NOISE_H 27 | 28 | #include "soloud.h" 29 | #include "soloud_misc.h" 30 | 31 | namespace SoLoud 32 | { 33 | class Noise; 34 | 35 | class NoiseInstance : public AudioSourceInstance 36 | { 37 | public: 38 | NoiseInstance(Noise *aParent); 39 | ~NoiseInstance(); 40 | 41 | virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize); 42 | virtual bool hasEnded(); 43 | 44 | public: 45 | float mOctaveScale[10]; 46 | Misc::Prg mPrg; 47 | }; 48 | 49 | class Noise : public AudioSource 50 | { 51 | public: 52 | 53 | enum NOISETYPES 54 | { 55 | WHITE = 0, 56 | PINK, 57 | BROWNISH, 58 | BLUEISH 59 | }; 60 | 61 | Noise(); 62 | 63 | void setOctaveScale(float aOct0, float aOct1, float aOct2, float aOct3, float aOct4, float aOct5, float aOct6, float aOct7, float aOct8, float aOct9); 64 | void setType(int aType); 65 | 66 | virtual ~Noise(); 67 | 68 | public: 69 | virtual AudioSourceInstance *createInstance(); 70 | float mOctaveScale[10]; 71 | }; 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /inc/soloud/soloud_openmpt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Openmpt module for SoLoud audio engine 3 | Copyright (c) 2016 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef OPENMPT_H 26 | #define OPENMPT_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | class Openmpt; 33 | class File; 34 | 35 | class OpenmptInstance : public AudioSourceInstance 36 | { 37 | Openmpt *mParent; 38 | void *mModfile; 39 | int mPlaying; 40 | 41 | public: 42 | OpenmptInstance(Openmpt *aParent); 43 | virtual ~OpenmptInstance(); 44 | virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize); 45 | virtual bool hasEnded(); 46 | }; 47 | 48 | class Openmpt : public AudioSource 49 | { 50 | public: 51 | char *mData; 52 | unsigned int mDataLen; 53 | Openmpt(); 54 | virtual ~Openmpt(); 55 | result load(const char* aFilename); 56 | result loadMem(const unsigned char *aMem, unsigned int aLength, bool aCopy = false, bool aTakeOwnership = true); 57 | result loadFile(File *aFile); 58 | virtual AudioSourceInstance *createInstance(); 59 | }; 60 | }; 61 | 62 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2018 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_QUEUE_H 26 | #define SOLOUD_QUEUE_H 27 | 28 | #include "soloud.h" 29 | 30 | #define SOLOUD_QUEUE_MAX 32 31 | 32 | namespace SoLoud 33 | { 34 | class Queue; 35 | 36 | class QueueInstance : public AudioSourceInstance 37 | { 38 | Queue *mParent; 39 | public: 40 | QueueInstance(Queue *aParent); 41 | virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize); 42 | virtual bool hasEnded(); 43 | virtual ~QueueInstance(); 44 | }; 45 | 46 | class Queue : public AudioSource 47 | { 48 | public: 49 | Queue(); 50 | virtual QueueInstance *createInstance(); 51 | // Play sound through the queue 52 | result play(AudioSource &aSound); 53 | // Number of audio sources queued for replay 54 | unsigned int getQueueCount(); 55 | // Is this audio source currently playing? 56 | bool isCurrentlyPlaying(AudioSource &aSound); 57 | // Set params by reading them from an audio source 58 | result setParamsFromAudioSource(AudioSource &aSound); 59 | // Set params manually 60 | result setParams(float aSamplerate, unsigned int aChannels = 2); 61 | 62 | public: 63 | unsigned int mReadIndex, mWriteIndex, mCount; 64 | AudioSourceInstance *mSource[SOLOUD_QUEUE_MAX]; 65 | QueueInstance *mInstance; 66 | handle mQueueHandle; 67 | void findQueueHandle(); 68 | 69 | }; 70 | }; 71 | 72 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_robotizefilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2020 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_ROBOTIZEFILTER_H 26 | #define SOLOUD_ROBOTIZEFILTER_H 27 | 28 | #include "soloud.h" 29 | #include "soloud_filter.h" 30 | #include "soloud_misc.h" 31 | 32 | namespace SoLoud 33 | { 34 | class RobotizeFilter; 35 | 36 | class RobotizeFilterInstance : public FilterInstance 37 | { 38 | enum FILTERATTRIBUTE 39 | { 40 | WET = 0, 41 | FREQ, 42 | WAVE 43 | }; 44 | RobotizeFilter *mParent; 45 | public: 46 | virtual void filterChannel(float *aBuffer, unsigned int aSamples, float aSamplerate, time aTime, unsigned int aChannel, unsigned int aChannels); 47 | RobotizeFilterInstance(RobotizeFilter *aParent); 48 | }; 49 | 50 | class RobotizeFilter : public Filter 51 | { 52 | public: 53 | enum FILTERATTRIBUTE 54 | { 55 | WET = 0, 56 | FREQ, 57 | WAVE 58 | }; 59 | float mFreq; 60 | int mWave; 61 | virtual int getParamCount(); 62 | virtual const char* getParamName(unsigned int aParamIndex); 63 | virtual unsigned int getParamType(unsigned int aParamIndex); 64 | virtual float getParamMax(unsigned int aParamIndex); 65 | virtual float getParamMin(unsigned int aParamIndex); 66 | void setParams(float aFreq, int aWaveform); 67 | virtual FilterInstance *createInstance(); 68 | RobotizeFilter(); 69 | }; 70 | } 71 | 72 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_speech.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2015 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | #ifndef SOLOUD_SPEECH_H 25 | #define SOLOUD_SPEECH_H 26 | 27 | #include "soloud.h" 28 | #include "../src/audiosource/speech/darray.h" 29 | #include "../src/audiosource/speech/klatt.h" 30 | #include "../src/audiosource/speech/tts.h" 31 | 32 | namespace SoLoud 33 | { 34 | class Speech; 35 | 36 | class Speech : public AudioSource 37 | { 38 | // copy of the enum in klatt.h for codegen purposes 39 | enum KLATT_WAVEFORM 40 | { 41 | KW_SAW, 42 | KW_TRIANGLE, 43 | KW_SIN, 44 | KW_SQUARE, 45 | KW_PULSE, 46 | KW_NOISE, 47 | KW_WARBLE 48 | }; 49 | public: 50 | int mBaseFrequency; 51 | float mBaseSpeed; 52 | float mBaseDeclination; 53 | int mBaseWaveform; 54 | int mFrames; 55 | darray mElement; 56 | Speech(); 57 | result setText(const char *aText); 58 | result setParams(unsigned int aBaseFrequency = 1330, float aBaseSpeed = 10.0f, float aBaseDeclination = 0.5f, int aBaseWaveform = KW_TRIANGLE); 59 | virtual ~Speech(); 60 | virtual AudioSourceInstance *createInstance(); 61 | }; 62 | 63 | class SpeechInstance : public AudioSourceInstance 64 | { 65 | klatt mSynth; 66 | Speech *mParent; 67 | short *mSample; 68 | int mSampleCount; 69 | int mOffset; 70 | public: 71 | SpeechInstance(Speech *aParent); 72 | virtual ~SpeechInstance(); 73 | virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize); 74 | virtual result rewind(); 75 | virtual bool hasEnded(); 76 | }; 77 | }; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /inc/soloud/soloud_tedsid.h: -------------------------------------------------------------------------------- 1 | /* 2 | TED/SID module for SoLoud audio engine 3 | Copyright (c) 2013-2015 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef TEDSID_H 26 | #define TEDSID_H 27 | 28 | #include "soloud.h" 29 | 30 | class SIDsound; 31 | class TED; 32 | 33 | namespace SoLoud 34 | { 35 | class TedSid; 36 | class File; 37 | 38 | class TedSidInstance : public AudioSourceInstance 39 | { 40 | TedSid *mParent; 41 | SIDsound *mSID; 42 | TED *mTED; 43 | unsigned int mSampleCount; 44 | int mNextReg; 45 | int mNextVal; 46 | int mRegValues[128]; 47 | public: 48 | 49 | TedSidInstance(TedSid *aParent); 50 | ~TedSidInstance(); 51 | virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize); 52 | virtual void tick(); 53 | virtual bool hasEnded(); 54 | virtual float getInfo(unsigned int aInfoKey); 55 | }; 56 | 57 | class TedSid : public AudioSource 58 | { 59 | public: 60 | File *mFile; 61 | int mModel; 62 | bool mFileOwned; 63 | TedSid(); 64 | ~TedSid(); 65 | result load(const char *aFilename); 66 | result loadToMem(const char *aFilename); 67 | result loadMem(const unsigned char *aMem, unsigned int aLength, bool aCopy = false, bool aTakeOwnership = true); 68 | result loadFileToMem(File *aFile); 69 | result loadFile(File *aFile); 70 | virtual AudioSourceInstance *createInstance(); 71 | }; 72 | }; 73 | 74 | #endif -------------------------------------------------------------------------------- /inc/soloud/soloud_vizsn.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2018 Jari Komppa 4 | 5 | vizsn speech synthesizer (c) by Ville-Matias Heikkilä, 6 | released under WTFPL, http://www.wtfpl.net/txt/copying/ 7 | (in short, "do whatever you want to") 8 | 9 | Integration and changes to work with SoLoud by Jari Komppa, 10 | released under same license. 11 | */ 12 | 13 | #ifndef SOLOUD_VIZSN_H 14 | #define SOLOUD_VIZSN_H 15 | 16 | #include "soloud.h" 17 | 18 | namespace SoLoud 19 | { 20 | class Vizsn; 21 | 22 | struct VizsnResonator 23 | { 24 | public: 25 | float a, b, c, p1, p2; 26 | 27 | float resonate(float i); 28 | float antiresonate(float i); 29 | }; 30 | 31 | struct VizsnBank 32 | { 33 | VizsnResonator r[10]; 34 | float pitch; 35 | float frica, voice, aspir, bypas, breth; 36 | }; 37 | 38 | class VizsnInstance : public AudioSourceInstance 39 | { 40 | public: 41 | VizsnInstance(Vizsn *aParent); 42 | ~VizsnInstance(); 43 | 44 | virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize); 45 | virtual bool hasEnded(); 46 | 47 | public: 48 | Vizsn *mParent; 49 | VizsnBank mBank0, mBank1, mBank0to1; 50 | int mNper, mNmod, mNopen; 51 | int mEchobuf[1024], mPtr; 52 | int mCurrentVoiceType; 53 | float mPitch; 54 | char *mS; 55 | float mBuf[2048]; 56 | unsigned int mBufwrite; 57 | unsigned int mBufread; 58 | float vcsrc(int aPitch, int aVoicetype); 59 | float noisrc(); 60 | float genwave(); 61 | void setphone(VizsnBank *aB, char aP, float aPitch); 62 | void slidePrepare(int aNumtix); 63 | void slideTick(); 64 | int mA; 65 | int mB; 66 | int mOrgv; 67 | float mGlotlast; 68 | }; 69 | 70 | class Vizsn : public AudioSource 71 | { 72 | public: 73 | char *mText; 74 | Vizsn(); 75 | virtual ~Vizsn(); 76 | void setText(char *aText); 77 | public: 78 | virtual AudioSourceInstance *createInstance(); 79 | }; 80 | }; 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /inc/soloud/soloud_waveshaperfilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoLoud audio engine 3 | Copyright (c) 2013-2018 Jari Komppa 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #ifndef SOLOUD_WAVESHAPERFILTER_H 26 | #define SOLOUD_WAVESHAPERFILTER_H 27 | 28 | #include "soloud.h" 29 | 30 | namespace SoLoud 31 | { 32 | class WaveShaperFilter; 33 | 34 | class WaveShaperFilterInstance : public FilterInstance 35 | { 36 | WaveShaperFilter *mParent; 37 | public: 38 | virtual void filterChannel(float *aBuffer, unsigned int aSamples, float aSamplerate, time aTime, unsigned int aChannel, unsigned int aChannels); 39 | virtual ~WaveShaperFilterInstance(); 40 | WaveShaperFilterInstance(WaveShaperFilter *aParent); 41 | }; 42 | 43 | class WaveShaperFilter : public Filter 44 | { 45 | public: 46 | enum FILTERPARAMS { 47 | WET = 0, 48 | AMOUNT 49 | }; 50 | float mAmount; 51 | virtual WaveShaperFilterInstance *createInstance(); 52 | result setParams(float aAmount); 53 | WaveShaperFilter(); 54 | virtual ~WaveShaperFilter(); 55 | virtual int getParamCount(); 56 | virtual const char* getParamName(unsigned int aParamIndex); 57 | virtual unsigned int getParamType(unsigned int aParamIndex); 58 | virtual float getParamMax(unsigned int aParamIndex); 59 | virtual float getParamMin(unsigned int aParamIndex); 60 | }; 61 | } 62 | 63 | #endif -------------------------------------------------------------------------------- /res/Sprite-0001.aseprite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/Sprite-0001.aseprite -------------------------------------------------------------------------------- /res/images/all_sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/all_sprites.png -------------------------------------------------------------------------------- /res/images/brick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/brick.png -------------------------------------------------------------------------------- /res/images/bridge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/bridge.png -------------------------------------------------------------------------------- /res/images/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/button.png -------------------------------------------------------------------------------- /res/images/castle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/castle.png -------------------------------------------------------------------------------- /res/images/chalise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/chalise.png -------------------------------------------------------------------------------- /res/images/gate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/gate.png -------------------------------------------------------------------------------- /res/images/ground.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/ground.jpeg -------------------------------------------------------------------------------- /res/images/grundle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/grundle.png -------------------------------------------------------------------------------- /res/images/keys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/keys.png -------------------------------------------------------------------------------- /res/images/magnet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/magnet.png -------------------------------------------------------------------------------- /res/images/mc_blocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/mc_blocks.png -------------------------------------------------------------------------------- /res/images/pallette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/pallette.png -------------------------------------------------------------------------------- /res/images/penguin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/penguin.png -------------------------------------------------------------------------------- /res/images/rhindle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/rhindle.png -------------------------------------------------------------------------------- /res/images/spritemap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/spritemap.png -------------------------------------------------------------------------------- /res/images/sword.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/sword.png -------------------------------------------------------------------------------- /res/images/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/tiles.png -------------------------------------------------------------------------------- /res/images/units.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/units.png -------------------------------------------------------------------------------- /res/images/yorgle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/images/yorgle.png -------------------------------------------------------------------------------- /res/sound/chomp.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/sound/chomp.mp3 -------------------------------------------------------------------------------- /res/sound/death.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/sound/death.mp3 -------------------------------------------------------------------------------- /res/sound/drop.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/sound/drop.mp3 -------------------------------------------------------------------------------- /res/sound/pickup.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/sound/pickup.mp3 -------------------------------------------------------------------------------- /res/sound/slay.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/sound/slay.mp3 -------------------------------------------------------------------------------- /res/sound/win-bad.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/sound/win-bad.mp3 -------------------------------------------------------------------------------- /res/sound/win-good.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/res/sound/win-good.mp3 -------------------------------------------------------------------------------- /src/Angles.cpp: -------------------------------------------------------------------------------- 1 | #include "Angles.h" 2 | 3 | using namespace Fastboi; 4 | 5 | // Degree::Degree(const Radian& rad) noexcept : value(FromRadians((double) rad)) { }; 6 | 7 | // Degree::operator Radian() const noexcept { 8 | // return Radian(ToRadians(value)); 9 | // } 10 | 11 | void TestComp() { 12 | constexpr Degree a = 30_deg; 13 | Degree b = 40_deg; 14 | 15 | b += a; 16 | b += 20_deg; 17 | 18 | b = 20_deg + 45_deg; 19 | } -------------------------------------------------------------------------------- /src/Application.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Vec.h" 5 | #include "Exceptions.h" 6 | 7 | struct SDL_Window; 8 | struct SDL_Renderer; 9 | struct SDL_Surface; 10 | struct SDL_WindowEvent; 11 | 12 | namespace Application { 13 | using GRenderer = SDL_Renderer; 14 | 15 | extern SDL_Window* gWindow; 16 | extern GRenderer* gRenderer; 17 | 18 | bool InitApplication(); 19 | void Cleanup(); 20 | 21 | void ToggleFullscreen(); 22 | bool IsFullscreen(); 23 | 24 | const Fastboi::Vec& GetWindowSize(); 25 | void WindowSizeChanged(const Fastboi::Vec& newSize); 26 | 27 | void ThrowRuntimeException(std::string_view err, Exception code, std::string_view msg) __attribute__((noreturn)); 28 | void ThrowRuntimeException(std::string_view err, Exception code) __attribute__((noreturn)); 29 | void ThrowRuntimeException(Exception code) __attribute__((noreturn)); 30 | } -------------------------------------------------------------------------------- /src/BoundingBoxRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "BoundingBoxRenderer.h" 2 | #include "Fastboi.h" 3 | 4 | using namespace Fastboi; 5 | 6 | void BoundingBoxRenderer::Render() { 7 | BoundingBox bounds = gameobject().transform->GetBounds(); 8 | 9 | Transform t(gameobject().transform->position, bounds.upperBounds - bounds.lowerBounds, 0_deg); 10 | 11 | Rendering::SetColor(0, 255, 0, 255); 12 | Rendering::Render_Rect(t); 13 | Rendering::SetColor(255, 0, 0, 255); 14 | 15 | for (auto vertex : gameobject().transform->GetVertices()) { 16 | Transform p(vertex, Size(10.f, 10.f), 0_deg); 17 | Rendering::Render_Rect(p); 18 | } 19 | } 20 | 21 | BoundingBoxRenderer& BoundingBoxRenderer::Duplicate() const { 22 | return *(new BoundingBoxRenderer(*this)); 23 | } 24 | -------------------------------------------------------------------------------- /src/BoundingBoxRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Renderer.h" 4 | 5 | namespace Fastboi { 6 | struct BoundingBoxRenderer final : public Renderer { 7 | BoundingBoxRenderer(GORef&& go, const RenderData& rd) : Renderer(std::move(go), rd) { }; 8 | 9 | void Render() override; 10 | 11 | protected: 12 | BoundingBoxRenderer(const BoundingBoxRenderer& copy) = default; 13 | BoundingBoxRenderer& Duplicate() const override; 14 | }; 15 | } -------------------------------------------------------------------------------- /src/BoxColorRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "BoxColorRenderer.h" 2 | #include "Rendering.h" 3 | 4 | using namespace Fastboi; 5 | using namespace Fastboi::Components; 6 | 7 | BoxColorRenderer::BoxColorRenderer(GORef&& go, RenderData data) : Renderer(std::move(go), data) { } 8 | 9 | BoxColorRenderer::~BoxColorRenderer() { 10 | 11 | } 12 | 13 | void BoxColorRenderer::Start() { 14 | Renderer::Start(); 15 | 16 | if (!Reqs::HasRequiredComponents(gameobject())) { 17 | Application::ThrowRuntimeException("BoxColorRenderer missing components!", Application::REQUIREMENTS_NOT_FULFILLED); 18 | } 19 | 20 | color = &gameobject().GetComponent(); 21 | } 22 | 23 | void BoxColorRenderer::Render() { 24 | Rendering::SetColor(color->r, color->g, color->b, color->a); 25 | 26 | if (screen.has_value()) { 27 | Rendering::RenderScreen_Rect(screen->RelativizeTransform(*gameobject().transform)); 28 | } else { 29 | Rendering::Render_Rect(gameobject().transform); 30 | } 31 | } 32 | 33 | Renderer& BoxColorRenderer::Duplicate() const { 34 | return *(new BoxColorRenderer(*this)); 35 | } -------------------------------------------------------------------------------- /src/BoxColorRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | #include "ColorComp.h" 5 | 6 | namespace Fastboi { 7 | namespace Components { 8 | struct BoxColorRenderer final : public Fastboi::Renderer { 9 | using Reqs = RequiredComponents; 10 | 11 | const ColorComp* color; 12 | 13 | BoxColorRenderer(GORef&& go, RenderData data); 14 | ~BoxColorRenderer(); 15 | 16 | void Start() override; 17 | void Render() override; 18 | 19 | protected: 20 | BoxColorRenderer(const BoxColorRenderer& copy) = default; 21 | Renderer& Duplicate() const override; 22 | }; 23 | }; 24 | }; -------------------------------------------------------------------------------- /src/CacheLineSize.c: -------------------------------------------------------------------------------- 1 | // https://github.com/NickStrupat/CacheLineSize 2 | #include "CacheLineSize.h" 3 | 4 | #if defined(__APPLE__) 5 | 6 | #include 7 | size_t CacheLineSize() { 8 | size_t lineSize = 0; 9 | size_t sizeOfLineSize = sizeof(lineSize); 10 | sysctlbyname("hw.cachelinesize", &lineSize, &sizeOfLineSize, 0, 0); 11 | return lineSize; 12 | } 13 | 14 | #elif defined(_WIN32) 15 | 16 | #include 17 | #include 18 | size_t CacheLineSize() { 19 | size_t lineSize = 0; 20 | DWORD bufferSize = 0; 21 | DWORD i = 0; 22 | SYSTEM_LOGICAL_PROCESSOR_INFORMATION * buffer = 0; 23 | 24 | GetLogicalProcessorInformation(0, &bufferSize); 25 | buffer = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION *) malloc(bufferSize); 26 | GetLogicalProcessorInformation(&buffer[0], &bufferSize); 27 | 28 | for (i = 0; i != bufferSize / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); ++i) { 29 | if (buffer[i].Relationship == RelationCache && buffer[i].Cache.Level == 1) { 30 | lineSize = buffer[i].Cache.LineSize; 31 | break; 32 | } 33 | } 34 | 35 | free(buffer); 36 | return lineSize; 37 | } 38 | 39 | #elif defined(__linux__) 40 | 41 | #include 42 | size_t CacheLineSize() { 43 | FILE * p = 0; 44 | p = fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", "r"); 45 | unsigned int lineSize = 0; 46 | if (p) { 47 | fscanf(p, "%d", &lineSize); 48 | fclose(p); 49 | } 50 | return lineSize; 51 | } 52 | 53 | #else 54 | #error Unrecognized platform 55 | #endif -------------------------------------------------------------------------------- /src/CacheLineSize.h: -------------------------------------------------------------------------------- 1 | // https://github.com/NickStrupat/CacheLineSize 2 | 3 | #ifndef CACHELINESIZE_H_INCLUDED 4 | #define CACHELINESIZE_H_INCLUDED 5 | 6 | // Author: Nick Strupat 7 | // Date: October 29, 2010 8 | // Returns the cache line size (in bytes) of the processor, or 0 on failure 9 | 10 | #include 11 | size_t CacheLineSize(); 12 | 13 | #endif -------------------------------------------------------------------------------- /src/Camera.cpp: -------------------------------------------------------------------------------- 1 | #include "Camera.h" 2 | #include "Application.h" 3 | 4 | using namespace Fastboi; 5 | 6 | namespace Fastboi { 7 | const Transform nullTransform; 8 | const Camera nullCamera(nullTransform ); 9 | 10 | const Camera* mainCamera = &nullCamera; 11 | } 12 | 13 | void Fastboi::SetCamera(const Camera& cam) { 14 | mainCamera = &cam; 15 | } 16 | 17 | const Camera& Fastboi::GetCamera() { 18 | return *mainCamera; 19 | } 20 | 21 | static void CameraDestroyed(const Camera& cam) { 22 | if (mainCamera == &cam && &cam != &nullCamera) 23 | Application::ThrowRuntimeException("Main camera destroyed", Application::NO_CAMERA); 24 | } 25 | 26 | Camera::Camera(GORef&& go) : gameobject(std::move(go)), target(nullptr) { }; 27 | 28 | Camera::Camera(GORef&& go, float zoom) : gameobject(std::move(go)), zoom(zoom) { }; 29 | Camera::Camera(const Transform& target, float zoom) : target(&target), zoom(zoom) { }; 30 | 31 | Camera::~Camera() { 32 | CameraDestroyed(*this); 33 | } 34 | 35 | void Camera::Start() { 36 | if (target == nullptr) 37 | this->target = &gameobject().GetComponent(); 38 | } 39 | 40 | Position Camera::WorldToScreenPos(const Position& worldPos) const { 41 | return (worldPos - target->position) * zoom + (Vecf) (Application::GetWindowSize() / 2); 42 | }; 43 | 44 | Position Camera::ScreenToWorldPos(const Position& screenPos) const { 45 | return (screenPos - (Vecf) (Application::GetWindowSize() / 2)) / zoom + target->position; 46 | }; 47 | 48 | bool Camera::IsPointVisible(const Position& worldPos) const { 49 | Position screenPos = WorldToScreenPos(worldPos); 50 | return screenPos.x >= 0 && screenPos.x < Application::GetWindowSize().x 51 | && screenPos.y >= 0 && screenPos.y < Application::GetWindowSize().y; 52 | } 53 | 54 | BoundingBox Camera::GetVisibleBounds() const { 55 | BoundingBox bounds; 56 | 57 | bounds.lowerBounds = ScreenToWorldPos(Position(0, 0)); 58 | bounds.upperBounds = ScreenToWorldPos((Position) Application::GetWindowSize()); 59 | 60 | return bounds; 61 | } 62 | -------------------------------------------------------------------------------- /src/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Gameobject.h" 4 | #include "Vec.h" 5 | #include "Application.h" 6 | #include 7 | #include 8 | 9 | namespace Fastboi { 10 | struct Camera; 11 | 12 | void SetCamera(const Camera& camera); 13 | const Camera& GetCamera(); 14 | 15 | struct Camera final { 16 | GORef gameobject; 17 | const Transform* target = nullptr; 18 | float zoom = 1.f; 19 | 20 | Camera(GORef&& go); 21 | Camera(GORef&& go, float zoom = 1.f); 22 | Camera(const Transform& target, float zoom = 1.f); 23 | ~Camera(); 24 | 25 | void Start(); 26 | 27 | Position WorldToScreenPos(const Position& worldPos) const; 28 | Position ScreenToWorldPos(const Position& screenPos) const; 29 | bool IsPointVisible(const Position& worldPos) const; 30 | 31 | BoundingBox GetVisibleBounds() const; 32 | }; 33 | }; -------------------------------------------------------------------------------- /src/ChangeObserver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Events.h" 3 | #include 4 | #include 5 | #include 6 | 7 | #define likely(x) __builtin_expect(!!(x), 1) 8 | #define unlikely(x) __builtin_expect(!!(x), 0) 9 | 10 | namespace Fastboi { 11 | namespace Components { 12 | template 13 | class ChangeObserver { 14 | private: 15 | const Watch* watch; 16 | Watch prevValue; 17 | 18 | public: 19 | using Signal_f_t = void(const Watch&); 20 | Signal signal; 21 | 22 | ChangeObserver(const Watch* ptr) : watch(ptr) { 23 | prevValue = *ptr; 24 | }; 25 | 26 | ~ChangeObserver() { 27 | signal.disconnect_all(); 28 | } 29 | 30 | void Fire() { 31 | signal.fire(*watch); 32 | } 33 | 34 | void Update() { 35 | if (unlikely(prevValue != *watch)) { 36 | Fire(); 37 | 38 | prevValue = *watch; 39 | } 40 | } 41 | }; 42 | }; 43 | }; 44 | 45 | #undef likely 46 | #undef unlikely -------------------------------------------------------------------------------- /src/ClickTarget.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DXPower/Fastboi/8a52fe37e0e02f05b7a2f327fb8b19468e9da376/src/ClickTarget.cpp -------------------------------------------------------------------------------- /src/ClickTarget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GORef.h" 4 | #include "Input.h" 5 | #include "Gameobject.h" 6 | 7 | namespace Fastboi { 8 | namespace Components { 9 | struct ClickTarget { 10 | private: 11 | Input::TargetedClickListener listener; 12 | 13 | public: 14 | void Start(Gameobject& go) { 15 | listener.Init(*go.transform, *go.renderer); 16 | } 17 | 18 | auto& Signal() { 19 | return listener.signal; 20 | } 21 | }; 22 | } 23 | } -------------------------------------------------------------------------------- /src/CollisionMask.cpp: -------------------------------------------------------------------------------- 1 | #include "CollisionMask.h" 2 | 3 | using namespace Fastboi; 4 | 5 | bool CollisionMask::CanCollide(const CollisionMask& a, const CollisionMask& b) { 6 | return a.CanCollide(b.layer) && b.CanCollide(a.layer); 7 | } 8 | 9 | bool CollisionMask::CanCollide(const CollisionMask& a, UT b) { 10 | if ((b & static_cast(CollisionLayer::ALL)) == static_cast(CollisionLayer::ALL)) 11 | return true; 12 | 13 | if ((b & static_cast(CollisionLayer::NONE)) == static_cast(CollisionLayer::NONE)) 14 | return false; 15 | 16 | return (static_cast(a.layer) & b) != 0; 17 | } 18 | 19 | bool CollisionMask::CanCollide(CollisionLayer layer) const { 20 | if (inclusions == static_cast(CollisionLayer::NONE)) return false; 21 | 22 | return inclusions == static_cast(CollisionLayer::ALL) 23 | || (inclusions & static_cast(layer)) == static_cast(layer); 24 | } -------------------------------------------------------------------------------- /src/ColorComp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Gameobject.h" 3 | #include "GORef.h" 4 | #include "Transform.h" 5 | #include "stdint.h" 6 | 7 | namespace Fastboi { 8 | namespace Components { 9 | struct ColorComp final { 10 | public: 11 | uint8_t r, g, b, a; 12 | 13 | constexpr ColorComp() : ColorComp(0, 0, 0, 0) { }; 14 | constexpr ColorComp(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : r(r), g(g), b(b), a(a) { }; 15 | 16 | void set(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { 17 | this->r = r; 18 | this->g = g; 19 | this->b = b; 20 | this->a = a; 21 | }; 22 | }; 23 | 24 | struct ColorShiftComp final { 25 | GORef gameobject; 26 | 27 | uint8_t count = 0; 28 | ColorComp* color; 29 | 30 | ColorShiftComp(GORef&& go) : gameobject(std::move(go)), color(nullptr) { }; 31 | 32 | void Start() { 33 | color = &gameobject().GetComponent(); 34 | } 35 | 36 | void Update() { 37 | if (color != nullptr) { 38 | color->r += 1; 39 | color->g -= 4; 40 | color->b += 2; 41 | } 42 | } 43 | }; 44 | }; 45 | }; -------------------------------------------------------------------------------- /src/ComponentReqs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Gameobject.h" 4 | #include "ctti/type_id.hpp" 5 | #include 6 | #include 7 | 8 | namespace Fastboi { 9 | template 10 | struct RequiredComponents final { 11 | public: 12 | RequiredComponents() = delete; // Not constructible 13 | 14 | static bool HasRequiredComponents(const Gameobject& go) { 15 | if constexpr (sizeof...(Types) == 0) 16 | return true; 17 | 18 | return (go.HasComponent() && ...); // Fold expression over each required component 19 | }; 20 | 21 | 22 | private: 23 | template 24 | static void WalkTypes(const Gameobject& go, std::vector& missing) { 25 | if (!go.HasComponent()) 26 | missing.push_back(ctti::type_id().name().str()); 27 | } 28 | 29 | public: 30 | static std::vector GetMissingNamesList(const Gameobject& go) { 31 | std::vector missing; 32 | 33 | if constexpr (sizeof...(Types) == 0) 34 | return missing; 35 | 36 | (WalkTypes(go, missing), ...); 37 | 38 | return missing; 39 | } 40 | 41 | static std::string GetMissingNamesString(const Gameobject& go) { 42 | std::stringstream s; 43 | 44 | auto missing = GetMissingNamesList(go); 45 | 46 | for (unsigned int i = 0; i < missing.size(); i++) { 47 | s << missing[i]; 48 | 49 | if (i != missing.size() - 1) 50 | s << ' '; 51 | } 52 | 53 | return s.str(); 54 | } 55 | 56 | static void StandardThrowingCheck(const Gameobject& go) { 57 | if (!HasRequiredComponents(go)) { 58 | const std::string msg = " missing reqs"; 59 | char* buffer = new char[msg.size() + go.name.size() + 1]; 60 | sprintf(buffer, "%s%s", go.name.c_str(), msg.c_str()); 61 | 62 | Application::ThrowRuntimeException( 63 | msg.c_str() 64 | , Application::REQUIREMENTS_NOT_FULFILLED 65 | , GetMissingNamesString(go).c_str() 66 | ); 67 | } 68 | } 69 | }; 70 | 71 | }; 72 | 73 | -------------------------------------------------------------------------------- /src/Exceptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Application { 4 | enum Exception { 5 | COPY_NONTARGET_TEXTURE = 1 6 | , COMPONENT_NO_EXIST = 2 7 | , COMPONENT_ALREADY_EXISTS = 3 8 | , REQUIREMENTS_NOT_FULFILLED = 4 9 | , GJK_TOO_MANY_VERTICES = 5 10 | , DEALLOCATE_UNSTARTED_GO = 6 11 | , COPY_COMP_NO_DUPE = 7 12 | , INVALID_COL_LAYER = 8 13 | , CANNOT_DUPE = 9 14 | , NO_CAMERA = 10 15 | , GAME_ERROR = 11 16 | , SYSTEM_DIFFERING_PARAMETER_ORDER = 12 17 | , LOAD_FAILURE = 13 18 | }; 19 | } -------------------------------------------------------------------------------- /src/Fastboi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ComponentReqs.h" 4 | #include "Collider.h" 5 | #include "ColorComp.h" 6 | #include "Events.h" 7 | #include "Gameobject.h" 8 | #include "GORef.h" 9 | #include "Input.h" 10 | #include "Rect.h" 11 | #include "Rendering.h" 12 | #include "Renderer.h" 13 | #include "Resources.h" 14 | #include "Rigidbody.h" 15 | #include "Texture.h" 16 | -------------------------------------------------------------------------------- /src/FastboiComps.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Helper components 4 | #include "BoxColorRenderer.h" 5 | #include "ChangeObserver.h" 6 | #include "ColorComp.h" 7 | #include "RectUI.h" 8 | #include "RepeatRenderer.h" 9 | #include "SpriteRenderer.h" 10 | #include "Spritesheet.h" 11 | #include "UITexture.h" 12 | #include "WireframeRenderer.h" -------------------------------------------------------------------------------- /src/GORef.cpp: -------------------------------------------------------------------------------- 1 | #include "GORef.h" 2 | #include "Gameobject.h" 3 | 4 | using namespace Fastboi; 5 | 6 | GORef::GORef(Gameobject& go) : go(&go) { } 7 | GORef::GORef(Gameobject& go, detail::ComponentBase& owner) : go(&go), owningComp(&owner) { } 8 | 9 | GORef::GORef(const GORef& copy) : go(copy.go), owningComp(copy.owningComp) { 10 | if (owningComp != nullptr && !owningComp->isDuplicating) 11 | Application::ThrowRuntimeException("Attempt to copy-construct component in non-duplicating context" 12 | , Application::COPY_COMP_NO_DUPE 13 | , "Hint: use std::move(GORef) when storing GORef in component cstr"); 14 | } 15 | 16 | GORef::GORef(const GORef&& mv) : go(mv.go), owningComp(mv.owningComp) { 17 | if (owningComp != nullptr) 18 | owningComp->internalGORef = this; 19 | }; 20 | 21 | GORef::~GORef() { 22 | if (owningComp != nullptr && owningComp->internalGORef == this) 23 | owningComp->internalGORef = nullptr; 24 | } 25 | 26 | GORef& GORef::operator=(Gameobject& rebind) { 27 | go = &rebind; 28 | 29 | return *this; 30 | } 31 | -------------------------------------------------------------------------------- /src/GORef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Fastboi { 6 | namespace detail { 7 | struct ComponentBase; 8 | } 9 | 10 | struct Gameobject; 11 | 12 | class GORef final{ 13 | public: 14 | Gameobject* go = nullptr; 15 | detail::ComponentBase* owningComp = nullptr; 16 | 17 | public: 18 | GORef() = default; 19 | GORef(Gameobject& go); 20 | GORef(Gameobject& go, detail::ComponentBase& owner); 21 | GORef(const GORef& copy); 22 | GORef(const GORef&& mv); 23 | ~GORef(); 24 | 25 | GORef& operator=(const GORef&& mv) = delete; 26 | GORef& operator=(Gameobject& rebind); 27 | 28 | // inline const Gameobject& operator()() const { return *go; }; 29 | inline Gameobject& operator()() const { return *go; }; 30 | 31 | template 32 | friend struct Component; 33 | 34 | friend struct Gameobject; 35 | }; 36 | } -------------------------------------------------------------------------------- /src/GameobjectAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Fastboi { 6 | struct Gameobject; 7 | 8 | class GameobjectAllocator { 9 | struct Chunk; 10 | struct Block; 11 | 12 | std::size_t chunksPerBlock; 13 | Chunk* allocChunk = nullptr; 14 | Chunk* unstartedHead = nullptr; 15 | Chunk* unstartedTail = nullptr; 16 | Block* blockHead = nullptr; 17 | Block* blockTail = nullptr; 18 | 19 | 20 | public: 21 | GameobjectAllocator(); 22 | 23 | void* Allocate(); 24 | void Deallocate(void* del); 25 | void StartAll(); 26 | 27 | 28 | private: 29 | void MarkUnstarted(Chunk& chunk); 30 | Block* AllocateBlock(); 31 | 32 | public: 33 | class iterator { 34 | Block* block; 35 | std::size_t cn = 0; 36 | 37 | public: 38 | iterator(Block* block) : block(block) { }; 39 | 40 | iterator operator++(int _); 41 | Gameobject& operator*() const; 42 | 43 | bool operator==(const iterator& other) const { return block == other.block; }; 44 | bool operator!=(const iterator& other) const { return !(*this == other); }; 45 | }; 46 | 47 | iterator GO_Begin() { return iterator(blockHead); }; 48 | iterator GO_End() { return iterator(nullptr); }; 49 | }; 50 | } -------------------------------------------------------------------------------- /src/Rect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SDL/SDL.h" 4 | #include 5 | 6 | namespace Fastboi { 7 | struct Rect final : SDL_Rect { 8 | Rect(int x, int y, int w, int h) { 9 | this->x = x; 10 | this->y = y; 11 | this->w = w; 12 | this->h = h; 13 | }; 14 | }; 15 | 16 | struct RectF final : SDL_FRect { 17 | RectF(float x, float y, float w, float h) { 18 | this->x = x; 19 | this->y = y; 20 | this->w = w; 21 | this->h = h; 22 | }; 23 | }; 24 | 25 | template 26 | auto ToRect(const R& rect) { 27 | if constexpr (std::is_same_v) { 28 | return Rect(rect.x, rect.y, rect.w, rect.h); 29 | } else if constexpr (std::is_same_v) { 30 | return RectF(rect.x, rect.y, rect.w, rect.h); 31 | } 32 | } 33 | }; -------------------------------------------------------------------------------- /src/RectUI.cpp: -------------------------------------------------------------------------------- 1 | #include "RectUI.h" 2 | #include "Gameobject.h" 3 | #include "Rendering.h" 4 | #include "ColorComp.h" 5 | #include "Input.h" 6 | 7 | using namespace Fastboi; 8 | using namespace Fastboi::Components; 9 | 10 | RectUI::RectUI(GORef&& go) : Renderer(std::move(go), { RenderOrder::UI, 0 }) { } 11 | RectUI::RectUI(GORef&& go, int z) : Renderer(std::move(go), { RenderOrder::UI, z }) { } 12 | 13 | void RectUI::Start() { 14 | Renderer::Start(); 15 | 16 | color = &gameobject().GetComponent(); 17 | 18 | clickListener.signal.connect<&RectUI::Click>(this); 19 | clickListener.Init(*gameobject().transform, *this); 20 | } 21 | 22 | void RectUI::Render() { 23 | Rendering::SetColor(color->r, color->g, color->b, color->a); 24 | Rendering::RenderScreen_Rect(gameobject().transform); 25 | } 26 | 27 | void RectUI::Click(const Fastboi::TargetedClickEvent& e) { 28 | if (e.type == Fastboi::ClickEvent::DOWN) { 29 | printf("Click!: Pos: %f %f\n", gameobject().transform->position.x, gameobject().transform->position.y); 30 | gameobject().transform->position += 35; 31 | } 32 | } 33 | 34 | Renderer& RectUI::Duplicate() const { 35 | return *(new RectUI(*this)); 36 | } -------------------------------------------------------------------------------- /src/RectUI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Renderer.h" 4 | #include "Events.h" 5 | #include "Input.h" 6 | #include 7 | 8 | namespace Fastboi { 9 | namespace Components { 10 | struct ColorComp; 11 | 12 | struct RectUI final : public Fastboi::Renderer { 13 | private: 14 | const ColorComp* color; 15 | Fastboi::Input::TargetedClickListener clickListener; 16 | 17 | public: 18 | RectUI(GORef&& go); 19 | RectUI(GORef&& go, int z); 20 | 21 | void Start() override; 22 | void Render() override; 23 | 24 | void Click(const Fastboi::TargetedClickEvent& e); 25 | 26 | protected: 27 | RectUI(const RectUI& copy) = default; 28 | Renderer& Duplicate() const override; 29 | }; 30 | }; 31 | }; -------------------------------------------------------------------------------- /src/RenderOrder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Fastboi { 6 | enum class RenderOrder { 7 | SKYBOX, 8 | GROUND, 9 | OBJECTS_UNDER, 10 | UNITS, 11 | PARTICLES, 12 | OBJECTS_OVER, 13 | UI 14 | }; 15 | 16 | struct RenderData { 17 | RenderOrder order; 18 | int zindex; 19 | 20 | constexpr RenderData(RenderOrder o) : RenderData(o, 0) { }; 21 | constexpr RenderData(RenderOrder o, int z) : order(o), zindex(z) { }; 22 | 23 | constexpr bool operator==(const RenderData& other) const = default; 24 | 25 | constexpr std::strong_ordering operator<=>(const RenderData& rhs) const { 26 | if (order != rhs.order) 27 | return order <=> rhs.order; 28 | else 29 | return zindex <=> rhs.zindex; 30 | } 31 | }; 32 | }; -------------------------------------------------------------------------------- /src/Renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "Renderer.h" 2 | #include "FastboiCore.h" 3 | #include "Gameobject.h" 4 | #include "GORef.h" 5 | 6 | using namespace Fastboi; 7 | 8 | Renderer::Renderer(GORef&& go) : Renderer(std::move(go), { RenderOrder::GROUND, 0 }) { } 9 | 10 | Renderer::Renderer(GORef&& go, RenderData data) : gameobject(std::move(go)), data(data) { 11 | Fastboi::RegisterRenderer(this); 12 | } 13 | 14 | Renderer::Renderer(const Renderer& copy) : Renderer(GORef(copy.gameobject), copy.data) {} // Nope, I'm dumb, should be copy.data 15 | 16 | Renderer::~Renderer() { 17 | Fastboi::UnregisterRenderer(this); 18 | } 19 | 20 | RenderOrder Renderer::GetOrder() const { 21 | return data.order; 22 | } 23 | 24 | void Renderer::SetOrder(RenderOrder order) { 25 | Fastboi::ChangeRenderOrder(this, data.order, order); // Register change in render order 26 | data.order = order; 27 | } 28 | 29 | int Renderer::GetZ() const{ 30 | return data.zindex; 31 | } 32 | 33 | void Renderer::SetZ(int z) { 34 | data.zindex = z; 35 | } -------------------------------------------------------------------------------- /src/Renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "RenderOrder.h" 5 | #include "GORef.h" 6 | #include "UI/Screen.h" 7 | 8 | namespace Fastboi { 9 | struct Gameobject; 10 | 11 | void Render(); 12 | 13 | struct Renderer { 14 | private: 15 | bool isStarted = false; 16 | bool isDeleted = false; 17 | bool isEnabled = true; 18 | 19 | public: 20 | GORef gameobject; 21 | RenderData data; 22 | 23 | std::optional screen; 24 | 25 | public: 26 | Renderer(GORef&& go); 27 | Renderer(GORef&& go, RenderData data); 28 | virtual ~Renderer(); 29 | 30 | public: 31 | virtual void Start() { isStarted = true; }; 32 | virtual void Render() = 0; 33 | 34 | inline void SetEnabled(bool f) { isEnabled = f; }; 35 | inline bool IsEnabled() const { return isEnabled; }; 36 | 37 | RenderOrder GetOrder() const; 38 | void SetOrder(RenderOrder order); 39 | 40 | int GetZ() const; 41 | void SetZ(int z); 42 | 43 | RenderData GetRenderData() const { return data; }; 44 | void SetRenderData(RenderData data) { SetOrder(data.order); SetZ(data.zindex); } 45 | 46 | void Destroy() { isDeleted = true; }; 47 | 48 | protected: 49 | Renderer(const Renderer& copy); 50 | virtual Renderer& Duplicate() const = 0; 51 | 52 | friend void Fastboi::Render(); 53 | friend struct Gameobject; 54 | }; 55 | }; -------------------------------------------------------------------------------- /src/RepeatRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | #include "ChangeObserver.h" 5 | 6 | namespace Fastboi { 7 | namespace Components { 8 | struct RepeatRenderer : Fastboi::Renderer { 9 | private: 10 | Size lastSize; 11 | 12 | public: 13 | CTexturePtr baseTexture; 14 | Texture repeatTexture; 15 | Size tileSize; 16 | 17 | RepeatRenderer(GORef&& gameobject, RenderData data, const char* textureName, const Size& tileSize); 18 | ~RepeatRenderer(); 19 | 20 | void Start() override; 21 | void Render() override; 22 | 23 | protected: 24 | // RepeatRenderer(const RepeatRenderer& copy) = default; 25 | // Renderer& Duplicate() const override; 26 | 27 | private: 28 | void CreateRepeatTexture(const Size& newSize); 29 | void WindowSizeChanged(const Fastboi::WindowResizeEvent& e); 30 | }; 31 | }; 32 | }; -------------------------------------------------------------------------------- /src/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Texture.h" 5 | #include "Vec.h" 6 | 7 | struct SDL_Surface; 8 | struct SDL_Texture; 9 | 10 | namespace SoLoud { 11 | class Wav; 12 | class Soloud; 13 | } 14 | 15 | namespace Fastboi { 16 | struct WindowResizeEvent; 17 | 18 | using SoLoud::Wav; 19 | using SoLoud::Soloud; 20 | 21 | namespace Resources { 22 | // Stores image file as texture to be used later 23 | void LoadImage(std::string_view key, std::string_view filename); 24 | CTextureRef GetTexture(std::string_view key); 25 | 26 | void LoadSound(std::string_view key, std::string_view filename); 27 | Wav& GetSound(std::string_view key); 28 | 29 | Soloud& GetSoloud(); 30 | 31 | void Cleanup(); 32 | } 33 | } -------------------------------------------------------------------------------- /src/Rigidbody.cpp: -------------------------------------------------------------------------------- 1 | #include "Rigidbody.h" 2 | #include "FastboiCore.h" 3 | #include "Transform.h" 4 | 5 | using namespace Fastboi; 6 | 7 | template 8 | T clamp(T low, T val, T high) { 9 | return std::max(low, std::min(val, high)); 10 | } 11 | 12 | void Rigidbody::ApplyParameters(Transform& t) { 13 | t.position += velocity * Fastboi::physicsDelta; 14 | t.rotation += rotVelocity * Fastboi::physicsDelta; 15 | 16 | velocity += acceleration * Fastboi::physicsDelta; 17 | 18 | velocity.x = clamp(-maxVelocity.x, velocity.x, maxVelocity.x); 19 | velocity.y = clamp(-maxVelocity.y, velocity.y, maxVelocity.y); 20 | 21 | rotVelocity += rotAcceleration * Fastboi::physicsDelta; 22 | 23 | const Vec scaledDrag = drag * Fastboi::physicsDelta; 24 | 25 | // Absolute value of the new velocity 26 | const Velocity newAbsVel(std::max(0.f, std::abs(velocity.x) - scaledDrag.x), std::max(0.f, std::abs(velocity.y) - scaledDrag.y)); 27 | // Create a vector with magnitudes of newAbsVel but signs of velocity 28 | velocity = Velocity(std::copysign(newAbsVel.x, velocity.x), std::copysign(newAbsVel.y, velocity.y)); 29 | 30 | const double newAbsRV = std::max(0., std::abs(rotVelocity.Value()) - rotDrag.Value() * Fastboi::physicsDelta); 31 | rotVelocity = Degree(std::copysign(newAbsRV, rotVelocity.Value())); 32 | } -------------------------------------------------------------------------------- /src/Rigidbody.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Angles.h" 4 | #include "Vec.h" 5 | 6 | namespace Fastboi { 7 | struct Transform; 8 | 9 | namespace Collision { 10 | void ProgressRigidbodies(); 11 | } 12 | 13 | struct Rigidbody { 14 | Velocity velocity = Velocity::zero(); 15 | Velocity maxVelocity = Velocity(std::numeric_limits::infinity(), std::numeric_limits::infinity()); 16 | Velocity acceleration = Velocity::zero(); 17 | Vec drag{}; 18 | 19 | Degree rotVelocity = 0_deg; 20 | Degree rotAcceleration = 0_deg; 21 | Degree rotDrag = 0_deg; 22 | 23 | Rigidbody() = default; 24 | Rigidbody(Velocity v) : velocity(v) { }; 25 | Rigidbody(Velocity v, Degree rv) : velocity(v), rotVelocity(rv) { }; 26 | 27 | bool operator==(const Rigidbody& rb) const = default; 28 | 29 | private: 30 | void ApplyParameters(Transform& t); 31 | 32 | friend void Collision::ProgressRigidbodies(); 33 | }; 34 | } -------------------------------------------------------------------------------- /src/ScreenElement.cpp: -------------------------------------------------------------------------------- 1 | #include "ScreenElement.h" 2 | #include "Application.h" 3 | #include "Gameobject.h" 4 | #include "GORef.h" 5 | 6 | using namespace Fastboi; 7 | 8 | ScreenElement::ScreenElement(GORef&& go, Position anchor, Size relSize) : go(std::move(go)), anchor(anchor), relativeSize(relSize) { } 9 | 10 | Transform ScreenElement::GetScreenTransform() const { 11 | Transform screenT = *go().transform; 12 | 13 | screenT.position += anchor * (Position) Application::GetWindowSize(); // Treat transform.position as offset from anchor 14 | screenT.size += relativeSize * (Position) Application::GetWindowSize(); // Treat transform.size as margin of relative screen size 15 | 16 | return screenT; 17 | } -------------------------------------------------------------------------------- /src/ScreenElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Transform.h" 4 | #include "GORef.h" 5 | #include "Vec.h" 6 | 7 | namespace Fastboi { 8 | struct ScreenElement { 9 | GORef go; 10 | Position anchor = Vecf::zero(); 11 | Size relativeSize = Vecf::zero(); 12 | 13 | ScreenElement(GORef&& go, Position anchor, Size relSize); 14 | 15 | Transform GetScreenTransform() const; 16 | 17 | }; 18 | } -------------------------------------------------------------------------------- /src/Shape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Angles.h" 4 | #include "circular_vector.h" 5 | #include "Vec.h" 6 | 7 | namespace Fastboi { 8 | struct Transform; 9 | struct RectF; 10 | 11 | struct BoundingBox { 12 | Vecf lowerBounds; // Lower bounds in x and y dirs 13 | Vecf upperBounds; // Upper bounds in x and y dirs 14 | 15 | bool ContainsBox(const BoundingBox& box) const; 16 | bool ContainsPoint(const Position& pos) const; 17 | bool Overlaps(const BoundingBox& other) const; 18 | inline static bool Overlaps(const BoundingBox& a, const BoundingBox& b) { return a.Overlaps(b); }; 19 | 20 | BoundingBox Fattened(float factor) const; 21 | 22 | static BoundingBox Union(const BoundingBox& a, const BoundingBox& b); 23 | float Area() const; 24 | 25 | RectF ToRect() const; 26 | }; 27 | 28 | class Shape { 29 | protected: 30 | mutable circular_vector vertices; 31 | mutable BoundingBox bounds; 32 | 33 | // Store the last known position, size, and rotation so we only have to recalculate vertices when they are changed 34 | mutable Position lastPosVerts; 35 | mutable Size lastSizeVerts; 36 | mutable Degree lastRotationVerts = 0_deg; 37 | 38 | // Store last known pos, size, and rots for bounds calcs 39 | mutable Position lastPosBounds; 40 | mutable Size lastSizeBounds; 41 | mutable Degree lastRotationBounds = 0_deg; 42 | 43 | const Transform& transform; 44 | 45 | public: 46 | //! Does not calculate vertices. Must be done by derived class (due to C++ polymorphistic restrictions) 47 | Shape(const Transform& transform); 48 | virtual ~Shape() { }; 49 | 50 | const circular_vector& GetVertices() const; // Lazy: Vertices are calculated/retrieved from cache on request 51 | BoundingBox GetBounds() const; // Lazy: Bounds are calculated/retrieved from cache on request 52 | 53 | bool ContainsPoint(const Position& p); 54 | 55 | protected: 56 | virtual BoundingBox CalculateBounds() const; 57 | virtual circular_vector CalculateVertices() const = 0; 58 | }; 59 | 60 | class Rectangle final : public Shape { 61 | public: 62 | 63 | Rectangle(const Transform& transform); 64 | ~Rectangle() { }; 65 | 66 | protected: 67 | circular_vector CalculateVertices() const override; 68 | }; 69 | }; -------------------------------------------------------------------------------- /src/Slowboi/Button.cpp: -------------------------------------------------------------------------------- 1 | #include "Button.h" 2 | #include "UITexture.h" 3 | 4 | using namespace Slowboi; 5 | using namespace Fastboi; 6 | using namespace Input; 7 | 8 | struct ButtonClickComp { 9 | Fastboi::GORef go; 10 | TargetedClickListener listener; 11 | 12 | ButtonClickComp(Fastboi::GORef&& go) : go(std::move(go)), listener(*go().transform, *go().renderer) { 13 | listener.signal.connect<&ButtonClickComp::Click>(this); 14 | }; 15 | 16 | void Click(const TargetedClickEvent& e) { 17 | if (e.type == ClickEvent::DOWN) { 18 | go().transform->size -= 5.f; 19 | } else if (e.type == ClickEvent::UP) { 20 | go().transform->size += 5.f; 21 | } 22 | } 23 | }; 24 | 25 | void Button(Gameobject& go, const Position& p, const Size& s) { 26 | go.AddComponent(p, s, 0); 27 | go.AddComponent("Button"); 28 | go.AddComponent(); 29 | } 30 | -------------------------------------------------------------------------------- /src/Slowboi/Button.h: -------------------------------------------------------------------------------- 1 | #include "Fastboi.h" 2 | 3 | using namespace Fastboi; 4 | 5 | namespace Slowboi { 6 | void Button(Gameobject& go, const Position& pos, const Size& size); 7 | // struct Button final : public Gameobject { 8 | // Input::TargetedClickListener clickListener; 9 | 10 | // Button(const Position& pos, const Size& size); 11 | 12 | // private: 13 | // void Click(const TargetedClickEvent& e) const; 14 | // }; 15 | } -------------------------------------------------------------------------------- /src/Slowboi/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Fastboi.h" 3 | #include "FastboiComps.h" 4 | 5 | using namespace Fastboi; 6 | using namespace Fastboi::Components; 7 | 8 | namespace Slowboi { 9 | namespace Components { 10 | struct Player; 11 | }; 12 | 13 | void InitGame(); 14 | 15 | void Bullet(Gameobject& go, const Position& p, const Velocity& v, Components::Player& player); 16 | void Brick(Gameobject& go, const Position& p); 17 | void UISquare(Gameobject& go, const Position& p, const Size& s, const ColorComp& color, int zindex); 18 | void PlayerGO(Gameobject& go, const Position& p); 19 | // struct Brick final : public Gameobject { 20 | // Fastboi::Input::KeyListener expandListener; 21 | 22 | // Brick(const Position& p); 23 | // ~Brick() = default; 24 | 25 | // void Expand(const Fastboi::KeyEvent& e); 26 | // }; 27 | 28 | // struct UISquare final : public Gameobject { 29 | // UISquare(const Position& p, const Size& s, const ColorComp& color, int zindex); 30 | // ~UISquare() { }; 31 | // }; 32 | } -------------------------------------------------------------------------------- /src/Slowboi/GroundBG.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Fastboi.h" 5 | 6 | using namespace Fastboi; 7 | 8 | namespace Slowboi { 9 | void GroundBG(Gameobject& go, const Position& pos, const Size& size, const Texture& spritesheet, const Size& tileSize, const std::vector& sprites); 10 | } -------------------------------------------------------------------------------- /src/Slowboi/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | #include "Spritesheet.h" 5 | 6 | using namespace Fastboi; 7 | using namespace Fastboi::Components; 8 | 9 | namespace Slowboi { 10 | namespace Components { 11 | struct Player final { 12 | private: 13 | Rigidbody* rigidbody = nullptr; 14 | Spritesheet* spritesheet = nullptr; 15 | 16 | Input::KeyListener spacebarListener; 17 | Input::ClickListener clickListener; 18 | 19 | Input::KeyListener enableListener; 20 | 21 | Vecf lastDirection; 22 | Vecf facingDirection; 23 | 24 | public: 25 | GORef gameobject; 26 | float_t speed = 200.0f; 27 | 28 | Player(GORef&& go); 29 | ~Player(); 30 | 31 | void EnablePressed(const KeyEvent& e); 32 | void Spacebar(const KeyEvent& e); 33 | void VelocityChanged(const Velocity& velocity) const; 34 | void Fire(const ClickEvent& event); 35 | void Start(); 36 | void Update(); 37 | void Collision(const CollisionEvent& e) const; 38 | }; 39 | }; 40 | }; -------------------------------------------------------------------------------- /src/Slowboi/RequiresTest.cpp: -------------------------------------------------------------------------------- 1 | #include "RequiresTest.h" 2 | 3 | void RequiresTest(Gameobject& go) { 4 | go.AddComponent(Position(75, 75), Size(250, 100), 0); 5 | go.AddComponent(); 6 | go.AddComponent(RenderData(RenderOrder::GROUND, 10)); 7 | 8 | go.AddComponent(); 9 | go.AddComponent(); 10 | } 11 | 12 | RedShifter::RedShifter(GORef&& go) : go(std::move(go)) { 13 | Fastboi::Print("RedShifter made!\n"); 14 | } 15 | 16 | void RedShifter::Start() { 17 | Fastboi::Print("Checking requirements...\n"); 18 | 19 | if (!Reqs::HasRequiredComponents(go())) 20 | Application::ThrowRuntimeException("RedShifter requirements not fulfilled\n", Application::REQUIREMENTS_NOT_FULFILLED); 21 | 22 | color = &go().GetComponent(); 23 | } 24 | 25 | void RedShifter::Update() { 26 | color->r += 1; 27 | } 28 | 29 | SizeOnRed::SizeOnRed(GORef&& go) : go(std::move(go)) { } 30 | 31 | void SizeOnRed::Start() { 32 | if (!Reqs::HasRequiredComponents(go())) 33 | Application::ThrowRuntimeException("SizeOnRed reqs not met\n", Application::REQUIREMENTS_NOT_FULFILLED); 34 | 35 | color = &go().GetComponent(); 36 | } 37 | 38 | void SizeOnRed::Update() { 39 | go().transform->size.x = color->r; 40 | } -------------------------------------------------------------------------------- /src/Slowboi/RequiresTest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | #include "FastboiComps.h" 5 | #include "ComponentReqs.h" 6 | 7 | using namespace Fastboi; 8 | 9 | void RequiresTest(Gameobject& go); 10 | 11 | struct RedShifter final { 12 | using Reqs = RequiredComponents; 13 | 14 | GORef go; 15 | Fastboi::Components::ColorComp* color; 16 | 17 | RedShifter(GORef&& go); 18 | 19 | void Start(); 20 | void Update(); 21 | }; 22 | 23 | struct SizeOnRed final { 24 | using Reqs = RequiredComponents; 25 | 26 | const GORef go; 27 | const Fastboi::Components::ColorComp* color; 28 | 29 | SizeOnRed(GORef&& go); 30 | 31 | void Start(); 32 | void Update(); 33 | }; -------------------------------------------------------------------------------- /src/SpriteRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "SpriteRenderer.h" 2 | #include "Rendering.h" 3 | 4 | using namespace Fastboi; 5 | using namespace Fastboi::Components; 6 | 7 | SpriteRenderer::SpriteRenderer(GORef&& gameobject, RenderData data, std::string_view textureName, const Rect& cutout) 8 | : Renderer(std::move(gameobject), data) 9 | , texture(&Resources::GetTexture(textureName)) 10 | , cutout(cutout) { 11 | } 12 | 13 | SpriteRenderer::SpriteRenderer(GORef&& gameobject, RenderData data, CTextureRef texture, const Rect& cutout) 14 | : Renderer(std::move(gameobject), data) 15 | , texture(&texture) 16 | , cutout(cutout) { 17 | } 18 | 19 | SpriteRenderer::~SpriteRenderer() { } 20 | 21 | void SpriteRenderer::Render() { 22 | if (screen.has_value()) { 23 | Rendering::RenderScreen_Texture(screen->RelativizeTransform(*gameobject().transform), *texture, cutout); 24 | } else { 25 | Rendering::Render_Texture(gameobject().transform, *texture, cutout); 26 | } 27 | } 28 | 29 | Renderer& SpriteRenderer::Duplicate() const { 30 | return *(new SpriteRenderer(*this)); 31 | } -------------------------------------------------------------------------------- /src/SpriteRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include 5 | #include "Fastboi.h" 6 | 7 | namespace Fastboi { 8 | namespace Components { 9 | struct SpriteRenderer : public Fastboi::Renderer { 10 | CTexturePtr texture; 11 | Rect cutout; 12 | 13 | SpriteRenderer(GORef&& gameobject, RenderData data); 14 | SpriteRenderer(GORef&& gameobject, RenderData data, std::string_view textureName, const Rect& cutout); 15 | SpriteRenderer(GORef&& gameobject, RenderData data, CTextureRef texture, const Rect& cutout); 16 | ~SpriteRenderer(); 17 | 18 | void Render() override; 19 | 20 | protected: 21 | SpriteRenderer(const SpriteRenderer& copy) = default; 22 | Renderer& Duplicate() const override; 23 | }; 24 | }; 25 | }; -------------------------------------------------------------------------------- /src/Texture.cpp: -------------------------------------------------------------------------------- 1 | #include "Texture.h" 2 | #include "Application.h" 3 | #include "FastboiCore.h" 4 | #include 5 | #include "Rect.h" 6 | #include "SDL/SDL.h" 7 | 8 | using namespace Fastboi; 9 | 10 | // void CopyTexture(const Texture& src, Texture& dst); // Does no exception checks. Only used 11 | 12 | Texture::Texture(const Vec& size, int access, uint32_t format) 13 | : size(size), access(access), format(format) 14 | , sdl_texture(CreateSDL_Texture(size, format, access)) 15 | { } 16 | 17 | Texture::Texture(SDL_Texture* sdlt) { 18 | if (sdlt == nullptr) 19 | return; 20 | 21 | sdl_texture = PointerStore_t(sdlt, {}); 22 | 23 | SDL_QueryTexture(sdlt, &format, &access, &size.x, &size.y); 24 | } 25 | 26 | auto Texture::CreateSDL_Texture(const Vec& size, int access, uint32_t format) -> PointerStore_t { 27 | // SDL_Texture must always be made/handled by Rendering thread 28 | SDL_Texture* t = SDL_CreateTexture(Application::gRenderer, format, access, size.x, size.y); 29 | 30 | return PointerStore_t(t, {}); 31 | } 32 | 33 | static void CopyTexture(const Texture& src, Texture& dest) { 34 | // if (access != SDL_TEXTUREACCESS_TARGET) 35 | // Application::ThrowRuntimeException("Copy nontarget texture", Application::COPY_NONTARGET_TEXTURE); 36 | 37 | Rect rect(0, 0, src.GetSize().x, src.GetSize().y); 38 | 39 | SDL_SetRenderTarget(Application::gRenderer, dest.GetSDL_Texture()); 40 | 41 | SDL_RenderCopy(Application::gRenderer, src.GetSDL_Texture(), &rect, &rect); 42 | SDL_SetRenderTarget(Application::gRenderer, nullptr); 43 | } 44 | 45 | void Texture::Deleter::operator()(SDL_Texture* t) { 46 | SDL_DestroyTexture(t); 47 | } -------------------------------------------------------------------------------- /src/Texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Vec.h" 6 | 7 | struct SDL_Texture; 8 | 9 | namespace Fastboi { 10 | void Render(); 11 | 12 | class Texture final { 13 | struct Deleter { 14 | void operator()(SDL_Texture* t); 15 | }; 16 | 17 | Vec size{}; 18 | int access{}; 19 | uint32_t format{}; 20 | 21 | using PointerStore_t = std::unique_ptr; 22 | PointerStore_t sdl_texture{}; 23 | 24 | public: 25 | Texture() = default;; 26 | Texture(const Vec& size, int access, uint32_t format); 27 | Texture(SDL_Texture* sdlt); 28 | 29 | const Vec& GetSize() const { return size; } 30 | int GetAccess() const { return access; } 31 | uint32_t GetFormat() const { return format; } 32 | SDL_Texture* GetSDL_Texture() const { return sdl_texture.get(); } 33 | 34 | private: 35 | static PointerStore_t CreateSDL_Texture(const Vec& size, int access, uint32_t format); 36 | }; 37 | 38 | using TextureRef = Texture&; 39 | using CTextureRef = const Texture&; 40 | 41 | using TexturePtr = Texture*; 42 | using CTexturePtr = const Texture*; 43 | } -------------------------------------------------------------------------------- /src/Timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define ch std::chrono 6 | 7 | namespace Fastboi { 8 | struct Timer 9 | { 10 | ch::steady_clock::time_point lastTick = ch::steady_clock::now(); 11 | ch::duration elapsed_seconds{0}; 12 | 13 | void Tick() { 14 | auto t2 = ch::steady_clock::now(); 15 | elapsed_seconds = ch::duration(t2 - lastTick); 16 | lastTick = t2; 17 | } 18 | 19 | decltype(elapsed_seconds) TimeSinceLastTick() { 20 | auto t2 = ch::steady_clock::now(); 21 | 22 | return ch::duration(t2 - lastTick); 23 | } 24 | }; 25 | }; 26 | 27 | #undef ch -------------------------------------------------------------------------------- /src/UI/Button.cpp: -------------------------------------------------------------------------------- 1 | #include "Button.h" 2 | #include "Gameobject.h" 3 | #include "BoxColorRenderer.h" 4 | #include "SpriteRenderer.h" 5 | #include "CommonLayouts.h" 6 | #include "ClickTarget.h" 7 | 8 | using namespace Fastboi; 9 | using namespace Components; 10 | using namespace Fastboi::UI; 11 | 12 | void Components::ColorButton(Gameobject& go, const ColorComp& color) { 13 | go.AddComponent(Position(0, 0), Size(1, 1), 0_deg); 14 | 15 | auto& renderer = go.AddComponent(RenderData(RenderOrder::UI)); 16 | go.AddComponent(color); 17 | 18 | renderer.screen = Screen( 19 | Layouts::Centered::Screen, 20 | Scale{ScreenConst(100.f), ScreenConst(100.f)} 21 | ); 22 | 23 | 24 | go.AddComponent(); 25 | } 26 | 27 | void Components::TextureButton(Gameobject& go, const Texture& texture) { 28 | go.AddComponent(Position(0, 0), Size(1, 1), 0_deg); 29 | 30 | const auto [sx, sy] = texture.GetSize(); 31 | auto& renderer = go.AddComponent(RenderData(RenderOrder::UI), texture, Rect(0, 0, sx, sy)); 32 | 33 | renderer.screen = Screen( 34 | Layouts::Centered::Screen, 35 | Scale{ScreenConst(100.f), ScreenConst(100.f)} 36 | ); 37 | 38 | go.AddComponent(); 39 | } -------------------------------------------------------------------------------- /src/UI/Button.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vec.h" 4 | 5 | namespace Fastboi { 6 | struct Gameobject; 7 | struct Rect; 8 | class Texture; 9 | 10 | namespace Components { 11 | struct ColorComp; 12 | 13 | void ColorButton(Gameobject& go, const ColorComp& color); 14 | void TextureButton(Gameobject& go, const Texture& texture); 15 | } 16 | } -------------------------------------------------------------------------------- /src/UI/Screen.cpp: -------------------------------------------------------------------------------- 1 | #include "Screen.h" 2 | #include "Transform.h" 3 | #include "Gameobject.h" 4 | #include "Renderer.h" 5 | 6 | using namespace Fastboi; 7 | using namespace UI; 8 | 9 | Transform Screen::RelativizeTransform(const Transform& self) const { 10 | Transform parentRelative; 11 | 12 | if (self.HasParent()) { 13 | const Transform& parent = self.Parent(); 14 | const Screen& parentScreen = parent.gameobject().renderer->screen.value(); 15 | 16 | parentRelative = parentScreen.RelativizeTransform(parent); 17 | } 18 | 19 | Vec scale = CalculateScale(self.size, parentRelative); 20 | Size newSize = self.size * scale; 21 | 22 | Vec anchor = CalculateAnchor(newSize, parentRelative); 23 | 24 | return Transform(anchor + self.position, newSize, self.rotation); 25 | } -------------------------------------------------------------------------------- /src/UI/Screen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ScreenspaceExpression.h" 4 | 5 | namespace Fastboi { 6 | struct Transform; 7 | 8 | namespace UI { 9 | using RelativeFunc_t = std::function; 10 | 11 | struct ScreenspaceCoord { 12 | RelativeFunc_t x; 13 | RelativeFunc_t y; 14 | }; 15 | 16 | using Anchor = ScreenspaceCoord; 17 | using Scale = ScreenspaceCoord; 18 | 19 | struct Screen { 20 | constexpr static auto DefaultAnchorX = ScreenWidth / 2.f; ; 21 | constexpr static auto DefaultAnchorY = ScreenHeight / 2.f; ; 22 | constexpr static auto DefaultScale = ScreenConst(1.f); 23 | 24 | inline static const Transform nullTransform; 25 | 26 | ScreenspaceCoord anchor { DefaultAnchorX, DefaultAnchorY }; 27 | ScreenspaceCoord scale { DefaultScale, DefaultScale }; 28 | 29 | Screen(const ScreenspaceCoord& anchor) : anchor(anchor) { } 30 | Screen(const ScreenspaceCoord& anchor, const ScreenspaceCoord& scale) : anchor(anchor), scale(scale) { } 31 | 32 | Vec CalculateAnchor(Size selfSize, const Transform& parent) const { return { anchor.x(selfSize, parent), anchor.y(selfSize, parent) }; } 33 | Vec CalculateScale(Size selfSize, const Transform& parent) const { return { scale.x(selfSize, parent), scale.y(selfSize, parent) }; } 34 | 35 | /* 36 | * New transform is: 37 | * Size: self.size * scale(self.size, self.parent) 38 | * Position: self.position + anchor(newSize, self.parent) 39 | */ 40 | Transform RelativizeTransform(const Transform& self) const; 41 | }; 42 | } 43 | } -------------------------------------------------------------------------------- /src/UITexture.cpp: -------------------------------------------------------------------------------- 1 | #include "UITexture.h" 2 | 3 | using namespace Fastboi; 4 | using namespace Components; 5 | 6 | UITexture::UITexture(GORef&& go, const char* textureName) 7 | : Renderer(std::move(go), RenderOrder::UI) 8 | , texture(Resources::GetTexture(textureName)) 9 | , cutout(0, 0, texture.GetSize().x, texture.GetSize().y) 10 | { } 11 | 12 | UITexture::UITexture(GORef&& go, const char* textureName, const Rect& cutout) 13 | : Renderer(std::move(go), RenderOrder::UI) 14 | , texture(Resources::GetTexture(textureName)) 15 | , cutout(cutout) 16 | { } 17 | 18 | void UITexture::Render() { 19 | Rendering::RenderScreen_Texture(gameobject().transform, texture, cutout); 20 | } 21 | 22 | Renderer& UITexture::Duplicate() const { 23 | return *(new UITexture(*this)); 24 | } -------------------------------------------------------------------------------- /src/UITexture.h: -------------------------------------------------------------------------------- 1 | #include "Fastboi.h" 2 | 3 | namespace Fastboi { 4 | namespace Components { 5 | struct UITexture final : public Renderer { 6 | const Texture& texture; 7 | Rect cutout; 8 | 9 | UITexture(GORef&& go, const char* textureName); 10 | UITexture(GORef&& go, const char* textureName, const Rect& cutout); 11 | 12 | void Render() override; 13 | 14 | protected: 15 | UITexture(const UITexture& copy) = default; 16 | Renderer& Duplicate() const override; 17 | }; 18 | } 19 | } -------------------------------------------------------------------------------- /src/Utility.cpp: -------------------------------------------------------------------------------- 1 | #include "Utility.h" 2 | #include 3 | #include "SDL/SDL.h" 4 | 5 | 6 | void print_rect(const SDL_Rect& rect) { 7 | printf("(x,y) (%i,%i) : (w, h) (%i,%i)", rect.x, rect.y, rect.w, rect.h); 8 | } 9 | 10 | void print_rect(const SDL_FRect& rect) { 11 | printf("(x,y) (%f,%f) : (w, h) (%f,%f)", rect.x, rect.y, rect.w, rect.h); 12 | } -------------------------------------------------------------------------------- /src/WireframeRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "WireframeRenderer.h" 2 | #include "ColorComp.h" 3 | 4 | using namespace Fastboi; 5 | using namespace Fastboi::Components; 6 | 7 | WireframeRenderer::WireframeRenderer(GORef&& go, RenderData rd) : Renderer(std::move(go), rd) { }; 8 | WireframeRenderer::~WireframeRenderer() { }; 9 | 10 | void WireframeRenderer::Start() { 11 | Renderer::Start(); 12 | 13 | using Reqs = RequiredComponents; 14 | 15 | if (!Reqs::HasRequiredComponents(gameobject())) 16 | Application::ThrowRuntimeException("WireframeRenderer missing reqs!", 17 | Application::REQUIREMENTS_NOT_FULFILLED, 18 | Reqs::GetMissingNamesString(gameobject()).c_str()); 19 | } 20 | 21 | void WireframeRenderer::Render() { 22 | // printf("Rendering wireframe renderer! GO Name: %s\n", gameobject().name.c_str()); 23 | Rendering::SetColor(gameobject().GetComponent()); 24 | 25 | auto& vertices = gameobject().transform->GetVertices(); 26 | 27 | for (auto pit = vertices.pair_begin(); pit != vertices.pair_end(); pit++) { 28 | Rendering::Render_Line(*pit.first, *pit.second); 29 | } 30 | } 31 | 32 | Renderer& WireframeRenderer::Duplicate() const { 33 | return *(new WireframeRenderer(*this)); 34 | } -------------------------------------------------------------------------------- /src/WireframeRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | 5 | namespace Fastboi { 6 | namespace Components { 7 | struct WireframeRenderer final : public Renderer{ 8 | WireframeRenderer(GORef&& go, RenderData rd); 9 | ~WireframeRenderer(); 10 | 11 | void Start() override; 12 | void Render() override; 13 | 14 | protected: 15 | WireframeRenderer(const WireframeRenderer& copy) = default; 16 | Renderer& Duplicate() const override; 17 | }; 18 | } 19 | } -------------------------------------------------------------------------------- /src/adventure/Bridge.h: -------------------------------------------------------------------------------- 1 | #include "Fastboi.h" 2 | 3 | using namespace Fastboi; 4 | 5 | namespace Adventure { 6 | struct Bridge { 7 | GORef go; 8 | 9 | Bridge(GORef&& go); 10 | 11 | void Start(); 12 | void Update(); 13 | 14 | void EnterBridge(const CollisionEvent& e); 15 | 16 | static void Inst(Gameobject& go, const Position& pos); 17 | }; 18 | } -------------------------------------------------------------------------------- /src/adventure/Chalise.cpp: -------------------------------------------------------------------------------- 1 | #include "Chalise.h" 2 | #include "FastboiComps.h" 3 | #include "Item.h" 4 | #include "Level.h" 5 | #include "GameManager.h" 6 | 7 | using namespace Adventure; 8 | using namespace Fastboi::Components; 9 | 10 | 11 | Chalise::Chalise(GORef&& go, ColorComp& color) : go(std::move(go)), c(color) { 12 | Level::roomChangeSignal.connect<&Chalise::RoomChanged>(this); 13 | } 14 | 15 | void Chalise::Update() { 16 | static int s = 0; 17 | static int n = 0; 18 | static uint8_t rollingShift = 0; 19 | 20 | if (s == 0) 21 | c.g += 5, c.b += 5; 22 | else if (s == 1) 23 | c.r += 5, c.g += 5; 24 | 25 | else if (s == 2) 26 | c.r += 5, c.b += 5; 27 | 28 | n += 5; 29 | if (n >= 255) { 30 | n = 0; 31 | s++; 32 | rollingShift += 25; 33 | 34 | if (s == 3) 35 | s = 0; 36 | 37 | if (s == 0) 38 | c.g = 0, c.b = 0, c.r = rollingShift; 39 | else if (s == 1) 40 | c.r = 0, c.g = 0, c.b = rollingShift; 41 | else if (s == 2) 42 | c.r = 0, c.b = 0, c.g = rollingShift; 43 | } 44 | 45 | CTexturePtr tex = go().GetComponent().texture; 46 | 47 | SDL_SetTextureColorMod(tex->GetSDL_Texture(), c.r, c.g, c.b); 48 | 49 | if (playWinSequence) { 50 | Level::GetRoom(go().transform->Parent().position).SetColor(c); 51 | go().transform->Parent().gameobject().GetComponent() = c; 52 | } 53 | 54 | } 55 | 56 | void Chalise::RoomChanged(const RoomChangeEvent& e) { 57 | if (go().GetComponent().isHeld && &e.room == manager.goldCastleInside) { 58 | manager.WinGame(); 59 | 60 | playWinSequence = true; 61 | } 62 | } 63 | 64 | void Chalise::Inst(Gameobject& go, const Position& pos) { 65 | constexpr Vec chaliseSpriteSize{16, 18}; 66 | constexpr Size chaliseSize{Room::GetTileSize().x, (float) chaliseSpriteSize.y / (float) chaliseSpriteSize.x * Room::GetTileSize().x}; 67 | 68 | go.AddComponent(pos, chaliseSize, 0_deg); 69 | go.AddComponent(Collider::TRIGGER, CollisionLayer::ITEMS).mask.Include(CollisionLayer::PLAYER); 70 | 71 | ColorComp& color = go.AddComponent(0, 0, 0, 255); 72 | go.AddComponent(RenderData(RenderOrder::OBJECTS_OVER), "Chalise", Rect(0, 0, chaliseSpriteSize.x, chaliseSpriteSize.y)); 73 | 74 | go.AddComponent(); 75 | go.AddComponent(color); 76 | } -------------------------------------------------------------------------------- /src/adventure/Chalise.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | 5 | using namespace Fastboi; 6 | using namespace Fastboi::Components; 7 | 8 | namespace Fastboi::Components { 9 | struct ColorComp; 10 | } 11 | 12 | namespace Adventure { 13 | struct RoomChangeEvent; 14 | 15 | struct Chalise { 16 | private: 17 | bool playWinSequence = false; 18 | 19 | public: 20 | GORef go; 21 | ColorComp& c; 22 | 23 | Chalise(GORef&& go, ColorComp& color); 24 | 25 | void Update(); 26 | void RoomChanged(const RoomChangeEvent& e); 27 | 28 | static void Inst(Gameobject& go, const Position& pos); 29 | }; 30 | 31 | } -------------------------------------------------------------------------------- /src/adventure/Dragon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Fastboi.h" 5 | #include "Timer.h" 6 | 7 | using namespace Fastboi; 8 | using namespace Fastboi::Components; 9 | 10 | namespace Fastboi::Components { 11 | struct SpriteRenderer; 12 | } 13 | 14 | namespace Adventure { 15 | struct Room; 16 | struct GameManager; 17 | 18 | struct DragonStats { 19 | int health = 0; 20 | float speed = 0; 21 | 22 | DragonStats(int health, float speed) : health(health), speed(speed) { } 23 | }; 24 | 25 | struct Yorgle; 26 | struct Grundle; 27 | 28 | struct Dragon { 29 | using Reqs = RequiredComponents; 30 | 31 | GORef go; 32 | const Room* room; 33 | 34 | private: 35 | struct Jaws { 36 | GORef go; 37 | 38 | Jaws(GORef&& go); 39 | }; 40 | 41 | DragonStats stats; 42 | 43 | Gameobject& player; 44 | Rigidbody* rb; 45 | 46 | Gameobject* jaws; 47 | Gameobject* belly; 48 | std::array mouthPieces; 49 | 50 | Timer biteTimer; 51 | bool isBiting = false; 52 | bool giveChase = false; 53 | 54 | public: 55 | Dragon(GORef&& go, Gameobject& player, const Room& room, const DragonStats& stats); 56 | 57 | void Start(); 58 | void Update(); 59 | 60 | void CloseJaws(); 61 | void Bite(); 62 | void SwordHit(); 63 | Position GetBiteLocation() const; 64 | 65 | inline void SetChase(bool f) { giveChase = f; rb->velocity = Velocity::zero(); }; 66 | inline bool IsDead() const { return stats.health <= 0; }; 67 | 68 | void Collision(const CollisionEvent& e); 69 | 70 | private: 71 | static void InstDelegate(Gameobject& go, Gameobject& player, const Room& room, const Position& pos, const DragonStats& stats); 72 | 73 | friend struct Yorgle; 74 | friend struct Grundle; 75 | // friend struct GameManager; 76 | }; 77 | 78 | struct Yorgle : DragonStats { 79 | static void Inst(Gameobject& go, Gameobject& player, const Room& room, const Position& pos); 80 | 81 | private: 82 | Yorgle(); 83 | }; 84 | 85 | struct Grundle : DragonStats { 86 | static void Inst(Gameobject& go, Gameobject& player, const Room& room, const Position& pos); 87 | 88 | private: 89 | Grundle(); 90 | }; 91 | } -------------------------------------------------------------------------------- /src/adventure/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Fastboi.h" 3 | #include "FastboiComps.h" 4 | 5 | using namespace Fastboi; 6 | using namespace Fastboi::Components; 7 | 8 | namespace Adventure { 9 | void InitGame(); 10 | 11 | void LoadLevel1(); 12 | } -------------------------------------------------------------------------------- /src/adventure/GameManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | #include "Level.h" 5 | #include "Dragon.h" 6 | #include "Item.h" 7 | #include "Player.h" 8 | 9 | using namespace Fastboi; 10 | 11 | 12 | namespace Adventure { 13 | struct GameManager { 14 | Dragon* yorgle = nullptr; 15 | Dragon* grundle = nullptr; 16 | Dragon* rhindle = nullptr; 17 | 18 | Item* blackKey = nullptr; 19 | Room* goldCastleInside = nullptr; 20 | 21 | private: 22 | bool hasSeenYorgle = false; 23 | 24 | public: 25 | void MoveDragons(const Room& room); 26 | void RoomChanged(const RoomChangeEvent& e); 27 | void WinGame() const; 28 | }; 29 | 30 | inline GameManager manager; 31 | } 32 | 33 | // inline Adventure::GameManager Adventure::manager{}; -------------------------------------------------------------------------------- /src/adventure/Gate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | 5 | using namespace Fastboi; 6 | using namespace Fastboi::Components; 7 | 8 | namespace Fastboi::Components { 9 | struct SpriteRenderer; 10 | } 11 | 12 | namespace Adventure { 13 | enum class KeyColor; 14 | struct Key; 15 | struct Room; 16 | 17 | struct Gate { 18 | using Reqs = RequiredComponents; 19 | 20 | Fastboi::GORef go; 21 | 22 | private: 23 | enum class GateState { 24 | OPEN, CLOSED 25 | }; 26 | 27 | GateState curState = GateState::CLOSED; 28 | float timeElapsed = 10.0f; 29 | 30 | Gameobject* holder = nullptr; 31 | Gameobject* key = nullptr; 32 | 33 | SpriteRenderer* renderer = nullptr; 34 | 35 | constexpr static unsigned char MIN_PROGRESS = 0; 36 | constexpr static unsigned char MAX_PROGRESS = 6; 37 | unsigned char curProgress = MAX_PROGRESS; 38 | 39 | const Room& inside; 40 | bool hasEntered = false; 41 | 42 | 43 | public: 44 | const KeyColor color; 45 | 46 | Gate(GORef&& go, KeyColor color, const Room& inside); 47 | 48 | void Start(); 49 | void Update(); 50 | 51 | void TryOpen(const Key& key); 52 | void TryEnterGate(Gameobject& pl); 53 | 54 | void EnterTriggerHit(const CollisionEvent& e); 55 | void Collision(const CollisionEvent& e); 56 | 57 | static void Inst(Gameobject& go, const Position& pos, KeyColor color, const Room& inside); 58 | 59 | private: 60 | void SetProgress(unsigned char progress); 61 | }; 62 | 63 | struct Castle { 64 | static void Inst(Gameobject& go, const Position& pos, KeyColor color); 65 | }; 66 | } -------------------------------------------------------------------------------- /src/adventure/Item.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | 5 | using namespace Fastboi; 6 | 7 | namespace Fastboi::Components { 8 | struct SpriteRenderer; 9 | } 10 | 11 | namespace Adventure { 12 | struct RoomChangeEvent; 13 | struct Room; 14 | 15 | struct Item { 16 | private: 17 | inline static std::vector globalItems; 18 | 19 | public: 20 | GORef go; 21 | Input::KeyListener releaseLsn{SDL_SCANCODE_SPACE}; 22 | const Room* room = nullptr; 23 | bool isHeld = false; 24 | 25 | Item(GORef&& go); 26 | 27 | void Start(); 28 | 29 | void Release(); 30 | void TryPickup(const CollisionEvent& e); 31 | 32 | void ReleasePressed(const KeyEvent& e); 33 | void Collision(const CollisionEvent& e); 34 | void RoomChanged(const RoomChangeEvent& e); 35 | 36 | inline static const std::vector& GetAllItems() { return globalItems; }; 37 | }; 38 | 39 | enum class KeyColor { 40 | GOLD = 0, 41 | WHITE = 1, 42 | BLACK = 2 43 | }; 44 | 45 | struct Key { 46 | using Reqs = RequiredComponents; 47 | 48 | Fastboi::GORef go; 49 | const KeyColor color; 50 | 51 | Key(GORef&& go, KeyColor color); 52 | 53 | void Start(); 54 | 55 | static void Inst(Gameobject& go, const Position& pos, KeyColor color); 56 | }; 57 | 58 | struct Sword { 59 | static void Inst(Gameobject& go, const Position& pos); 60 | }; 61 | } -------------------------------------------------------------------------------- /src/adventure/Layouts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "ColorComp.h" 5 | #include 6 | #include 7 | #include "Vec.h" 8 | 9 | namespace Adventure::Layouts { 10 | struct Layout_t { 11 | std::initializer_list tiles; 12 | Fastboi::Vec gcOffset; 13 | Fastboi::Components::ColorComp color; 14 | 15 | enum Dirs { 16 | UP = 0, RIGHT = 1, DOWN = 2, LEFT = 3 17 | }; 18 | 19 | using VI = Fastboi::Vec; 20 | inline static constexpr VI dfltUp{0, -1}; 21 | inline static constexpr VI dfltRight{1, 0}; 22 | inline static constexpr VI dfltDown{0, 1}; 23 | inline static constexpr VI dfltLeft{-1, 0}; 24 | std::array neighbors = { dfltUp, dfltRight, dfltDown, dfltLeft }; 25 | 26 | Fastboi::Vec GetCoords(const Fastboi::Vec& goldCastleCoords) const; 27 | }; 28 | 29 | extern const Layout_t goldCastle; 30 | extern const Layout_t goldCastleInside; 31 | extern const Layout_t gcSouth; 32 | extern const Layout_t gcSoutheast; 33 | extern const Layout_t gcSouthwest; 34 | extern const Layout_t greenDragonRm; 35 | extern const Layout_t mazeU; 36 | extern const Layout_t mazeSwirls; 37 | extern const Layout_t mazeHumps; 38 | extern const Layout_t mazeBase; 39 | extern const Layout_t mazeGrail; 40 | extern const Layout_t blackCastle; 41 | extern const Layout_t blackCastleInsideBot; 42 | extern const Layout_t blackCastleInsideTop; 43 | 44 | extern const Fastboi::Vec gcCenterL1; 45 | extern const Fastboi::Vec gcCenterL2; 46 | } -------------------------------------------------------------------------------- /src/adventure/Level.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Room.h" 4 | #include 5 | 6 | namespace Adventure { 7 | struct RoomObserver { 8 | GORef go; 9 | Room* curRoom = nullptr; 10 | Rigidbody* rb = nullptr; 11 | 12 | RoomObserver(GORef&& go) : go(std::move(go)) { } 13 | 14 | void Start(); 15 | void Update(); 16 | 17 | void ForceTeleport(const Position& pos); 18 | 19 | private: 20 | void ChangeRoom(Room& room); 21 | }; 22 | 23 | struct RoomChangeEvent { 24 | Room& room; 25 | Gameobject& player; 26 | };; 27 | 28 | struct Level { 29 | private: 30 | static inline std::vector>> rooms; 31 | static inline Gameobject* player; 32 | 33 | public: 34 | static inline constexpr Position origin = Position::zero(); 35 | static inline Vec gcCoords = Vec::zero(); 36 | 37 | using Signal_t_g = void(const RoomChangeEvent&); 38 | inline static Signal roomChangeSignal; 39 | 40 | static Room& AddRoom(const Layouts::Layout_t& layout); 41 | 42 | inline static Room& GetRoom(int x, int y) { return *rooms[y][x]; }; 43 | inline static Room& GetRoom(const Vec& coords) { return GetRoom(coords.x, coords.y); }; 44 | 45 | inline static void Clear() { rooms.clear(); }; 46 | 47 | inline static void SetPlayer(Gameobject& p) { player = &p; p.AddComponent(); }; 48 | inline static Gameobject& GetPlayer() { return *player; }; 49 | 50 | static Room& GetRoom(const Position& pos); 51 | static Room& GetRoomMovement(const Position& pos, const Velocity& v, Vec& dirMovedOut); 52 | 53 | static void SetLevelSize(size_t x, size_t y); 54 | 55 | friend struct RoomObserver; // In charge of watching player and firing roomChangeSignal 56 | }; 57 | } -------------------------------------------------------------------------------- /src/adventure/Magnet.cpp: -------------------------------------------------------------------------------- 1 | #include "Magnet.h" 2 | #include "FastboiComps.h" 3 | #include "Item.h" 4 | #include "Room.h" 5 | #include "Chalise.h" 6 | 7 | using namespace Adventure; 8 | 9 | Magnet::Magnet(GORef&& go) : go(std::move(go)) { } 10 | 11 | void Magnet::Start() { 12 | itemSelf = &go().GetComponent(); 13 | } 14 | 15 | static constexpr float pullSpeed = 100.f; 16 | 17 | void Magnet::Update() { 18 | // Pull other items in 19 | for (const Item* item : Item::GetAllItems()) { 20 | if (item->room == itemSelf->room // Only pull items in the same room 21 | && !item->isHeld // Don't pull any item the player is holding 22 | && item != itemSelf // Don't pull itself 23 | && !item->go().HasComponent()) { // Chalise isn't magnetic 24 | 25 | Transform& pull = *item->go().transform; 26 | const Transform& magnet = *go().transform; 27 | 28 | Position pullDest = magnet.position; 29 | pullDest.y += magnet.size.y / 2.f + pull.size.y / 2.f; 30 | 31 | Vecf dir = pullDest - pull.position; 32 | 33 | if (dir.magnitude() < 0.9f) continue; 34 | 35 | pull.position += dir.normalized() * pullSpeed * Fastboi::tickDelta; 36 | } 37 | } 38 | } 39 | 40 | void Magnet::Inst(Gameobject& go, const Position& pos) { 41 | constexpr Vec magnetSpriteSize{ 16, 16 }; 42 | 43 | go.AddComponent(pos, Room::GetTileSize(), 0_deg); 44 | go.AddComponent(RenderData(RenderOrder::OBJECTS_OVER), "Magnet", Rect(0, 0, magnetSpriteSize.x, magnetSpriteSize.y)); 45 | go.AddComponent(Collider::TRIGGER, CollisionLayer::ITEMS).mask.Include(CollisionLayer::PLAYER); 46 | 47 | go.AddComponent(); 48 | go.AddComponent(); 49 | } -------------------------------------------------------------------------------- /src/adventure/Magnet.h: -------------------------------------------------------------------------------- 1 | #include "Fastboi.h" 2 | 3 | using namespace Fastboi; 4 | 5 | namespace Adventure { 6 | struct Item; 7 | 8 | struct Magnet { 9 | GORef go; 10 | Item* itemSelf = nullptr; 11 | 12 | Magnet(GORef&& go); 13 | 14 | void Start(); 15 | void Update(); 16 | 17 | static void Inst(Gameobject& go, const Position& pos); 18 | }; 19 | } -------------------------------------------------------------------------------- /src/adventure/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Events.h" 4 | #include "Fastboi.h" 5 | #include "Input.h" 6 | 7 | using namespace Fastboi; 8 | using namespace Fastboi::Components; 9 | 10 | namespace Adventure { 11 | struct RoomChangeEvent; 12 | 13 | struct Player final { 14 | inline static const float speed = 760.f; 15 | 16 | private: 17 | bool isEaten = false; 18 | bool isInBridge = false; 19 | 20 | public: 21 | GORef gameobject; 22 | bool isPhasing = false; 23 | 24 | Player(GORef&& go); 25 | ~Player(); 26 | 27 | void Start(); 28 | static void System(Gameobject& go, Player& player, Collider& col, Rigidbody& rb); 29 | 30 | void Eat(); 31 | void RoomChanged(const RoomChangeEvent& e); 32 | 33 | void EnterBridge(); 34 | void ExitBridge(); 35 | void Collision(const CollisionEvent& e); 36 | 37 | static void Inst(Gameobject& go, const Position& pos); 38 | }; 39 | 40 | }; -------------------------------------------------------------------------------- /src/adventure/Room.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fastboi.h" 4 | #include "Layouts.h" 5 | #include 6 | #include 7 | 8 | namespace Adventure { 9 | using namespace Fastboi; 10 | using namespace Fastboi::Components; 11 | 12 | struct Room { 13 | private: 14 | const ColorComp originalColor; 15 | ColorComp currentColor; 16 | 17 | std::vector> tiles; 18 | 19 | static inline constexpr Size tileSize{100.f, 100.f}; 20 | static inline constexpr Veci roomTileCount{20, 12}; 21 | static inline constexpr Size size{tileSize * (Size) roomTileCount}; 22 | 23 | public: 24 | bool banYorgle = false; 25 | bool banGrundle = false; 26 | bool banRhindle = false; 27 | 28 | const Vec coords; 29 | const Position origin; 30 | const decltype(Layouts::Layout_t::neighbors) neighbors; 31 | 32 | Room(const Layouts::Layout_t& layout); 33 | 34 | void SetColor(const ColorComp& color);\ 35 | inline const ColorComp& GetColor() const { return currentColor; }; 36 | 37 | inline Position GetTilePos(int x, int y) const { return GetTilePos(Vec(x, y)); }; 38 | Position GetTilePos(const Vec& coords) const; 39 | Position GetCenter() const; 40 | 41 | BoundingBox GetBounds() const; 42 | 43 | //TODO: Replace constexpr with consteval once intellisense shuts up 44 | inline static constexpr Size GetSize() { return size; }; 45 | inline static constexpr Size GetTileSize() { return tileSize; }; 46 | inline static constexpr Vec GetTileCount() { return roomTileCount; }; 47 | 48 | static Position GetRoomCenter(const Vec& roomCoords); 49 | static Position GetRoomCenterFromWorldPos(const Position& worldPos); 50 | 51 | public: 52 | enum TILE_TYPES { 53 | WALL = 'W', 54 | AIR = 'O' 55 | }; 56 | }; 57 | 58 | void Tile(Gameobject& go, const Room& room, const Veci index, const ColorComp& color); 59 | } -------------------------------------------------------------------------------- /src/adventure/RoomCamera.h: -------------------------------------------------------------------------------- 1 | #include "Fastboi.h" 2 | #include "Level.h" 3 | #include "Room.h" 4 | #include 5 | 6 | namespace Adventure { 7 | struct RoomCamera { 8 | GORef gameobject; 9 | 10 | RoomCamera(GORef&& go) : gameobject(std::move(go)) { 11 | Level::roomChangeSignal.connect<&RoomCamera::RoomChanged>(*this); 12 | } 13 | 14 | void Start() { 15 | Camera& camera = gameobject().AddComponent(*gameobject().transform, 0.8f); 16 | Fastboi::SetCamera(camera); 17 | 18 | std::cout << "Starting room camera"; 19 | } 20 | 21 | void RoomChanged(const RoomChangeEvent& e) const { 22 | std::cout << "Room camera changed"; 23 | gameobject().transform->position = e.room.GetCenter(); 24 | }; 25 | }; 26 | } -------------------------------------------------------------------------------- /src/adventure/TestSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSystem.h" 2 | #include "Item.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace Fastboi; 8 | 9 | void Fastboi::TestPhysicsSystem(Gameobject& go, Collider& col [[maybe_unused]]) { 10 | if (go.name != "") { 11 | std::cout << go.name; 12 | } 13 | } 14 | 15 | static void Timer(std::atomic& t) { 16 | namespace ch = std::chrono; 17 | using namespace std::chrono_literals; 18 | 19 | auto start = ch::steady_clock::now(); 20 | auto end = start; 21 | 22 | while (true) { 23 | auto dur = ch::duration(end - start); 24 | t += dur.count(); 25 | 26 | std::this_thread::sleep_for(10ms); 27 | end = ch::steady_clock::now(); 28 | } 29 | } 30 | 31 | void Adventure::TestKeySystem(Gameobject& go [[maybe_unused]], Key& key [[maybe_unused]], Item& item, Transform& transform) { 32 | // static std::atomic t = 0; 33 | // static std::thread thr(Timer, std::ref(t)); 34 | 35 | // std::cout << t << "\n"; 36 | 37 | // if (!item.isHeld) 38 | // transform; 39 | } 40 | -------------------------------------------------------------------------------- /src/adventure/TestSystem.h: -------------------------------------------------------------------------------- 1 | #include "Gameobject.h" 2 | #include "Collider.h" 3 | 4 | namespace Fastboi { 5 | void TestPhysicsSystem(Gameobject& go, Collider& col); 6 | } 7 | 8 | namespace Adventure { 9 | struct Key; 10 | struct Item; 11 | 12 | void TestKeySystem(Fastboi::Gameobject& go, Key& key, Item& item, Fastboi::Transform& transform); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/adventure/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Application.h" 2 | #include "FastboiCore.h" 3 | #include "Resources.h" 4 | #include "Game.h" 5 | #include 6 | 7 | #include "AABBTree.h" 8 | #include "Shape.h" 9 | 10 | using namespace Fastboi; 11 | using namespace Collision; 12 | 13 | int main([[maybe_unused]] int argc, [[maybe_unused]] char* args[]) { 14 | std::cout << "Starting..." << std::endl; 15 | 16 | // AABBTree tree(0.f); 17 | 18 | // // BoundingBox a{Position(0, 0), Position(10, 10)}; 19 | // // BoundingBox b{Position(100, 100), Position(110, 110)}; 20 | // // BoundingBox c{Position(20, 20), Position(30, 30)}; 21 | // // BoundingBox d{Position(-10, -10), Position(0, 0)}; 22 | // // BoundingBox e{Position(30, 30), Position(40, 40)}; 23 | // // BoundingBox f{Position(110, 110), Position(120, 120)}; 24 | // // BoundingBox g{Position(-20, -20), Position(-10, -10)}; 25 | 26 | // // tree.InsertLeaf(a); 27 | // // tree.InsertLeaf(b); 28 | // // tree.InsertLeaf(c); 29 | // // tree.InsertLeaf(d); 30 | // // tree.InsertLeaf(e); 31 | // // tree.InsertLeaf(f); 32 | // // tree.InsertLeaf(g); 33 | 34 | // BoundingBox a{Position(0, 0), Position(10, 10) }; 35 | // BoundingBox b{Position(10, 10), Position(20, 20) }; 36 | // BoundingBox c{Position(20, 20), Position(30, 30) }; 37 | // BoundingBox d{Position(30, 30), Position(40, 40) }; 38 | // BoundingBox e{Position(40, 40), Position(50, 50) }; 39 | 40 | // auto handlea = tree.InsertLeaf(a); 41 | // auto handleb = tree.InsertLeaf(b); 42 | // auto handlec = tree.InsertLeaf(c); 43 | // auto handled = tree.InsertLeaf(d); 44 | // auto handlee = tree.InsertLeaf(e); 45 | 46 | // // handlea.Reset(); 47 | // // handleb.Reset(); 48 | // // handlec.Reset(); 49 | // // handled.Reset(); 50 | // handlee.Reset(); 51 | 52 | if (Application::InitApplication()) { 53 | std::cout << "Application started" << std::endl; 54 | Adventure::InitGame(); 55 | Fastboi::GameLoop(); 56 | Fastboi::Resources::Cleanup(); 57 | } 58 | 59 | Application::Cleanup(); 60 | 61 | return 0; 62 | } -------------------------------------------------------------------------------- /src/containmentsimulator/Button.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Events.h" 4 | #include "Fastboi.h" 5 | #include "Input.h" 6 | #include 7 | #include 8 | 9 | namespace CS { 10 | using namespace Fastboi; 11 | using namespace Input; 12 | 13 | class Button; 14 | 15 | class ButtonEvent { 16 | public: 17 | enum ButtonEventType { 18 | DEPRESS, 19 | UNPRESS 20 | }; 21 | 22 | using Signal_t_g = void(const ButtonEvent&); 23 | 24 | Button& button; 25 | ButtonEventType type; 26 | bool isToggle; 27 | 28 | ButtonEvent(Button& button); 29 | ButtonEvent(Button& button, ButtonEventType type, bool isToggle); 30 | }; 31 | 32 | class Button { 33 | public: 34 | enum class Toggle { 35 | NONE, 36 | OFF, 37 | ON 38 | }; 39 | 40 | private: 41 | TargetedClickListener internalListener; 42 | Toggle toggle; 43 | 44 | public: 45 | GORef go; 46 | Signal signal; 47 | 48 | Button(Fastboi::GORef&& go, Toggle toggle); 49 | 50 | void SetToggle(Toggle t); 51 | 52 | private: 53 | void Click(const TargetedClickEvent& e); 54 | 55 | public: 56 | static void Blueprint(Gameobject& go, const std::string& textureName, const Position& anchor, const Size& size); 57 | static void BlueprintC(Gameobject& go, const std::string& textureName, const Position& anchor, const Size& size, const Rect& cutout); 58 | static void ToggleBlueprint(Gameobject& go, const std::string& textureName, const Position& anchor, const Size& size); 59 | static void ToggleBlueprintC(Gameobject& go, const std::string& textureName, const Position& anchor, const Size& size, const Rect& cutout); 60 | }; 61 | 62 | class ButtonRenderer final : public Renderer { 63 | private: 64 | bool isDepressed = false; 65 | const Texture& depressedTexture; 66 | const Rect depressedCutout = Rect(0, 640, 64, 64); 67 | 68 | public: 69 | const Texture& texture; 70 | Rect cutout; 71 | 72 | ButtonRenderer(GORef&& go, const char* textureName); 73 | ButtonRenderer(GORef&& go, const char* textureName, const Rect& cutout); 74 | 75 | void Render() override; 76 | void Click(const ButtonEvent& e); 77 | 78 | protected: 79 | ButtonRenderer(const ButtonRenderer& copy) = default; 80 | Renderer& Duplicate() const override; 81 | }; 82 | } -------------------------------------------------------------------------------- /src/containmentsimulator/CameraController.cpp: -------------------------------------------------------------------------------- 1 | #include "CameraController.h" 2 | #include "Camera.h" 3 | #include "FastboiCore.h" 4 | #include "Input.h" 5 | 6 | using namespace CS; 7 | using namespace Fastboi; 8 | using namespace Input; 9 | 10 | CameraController::CameraController(GORef&& go) : go(std::move(go)), clickListener(ClickListener()) { 11 | clickListener.signal.connect<&CameraController::OnClick>(this); 12 | wheelListener.signal.connect<&CameraController::OnScroll>(this); 13 | } 14 | 15 | void CameraController::Start() { 16 | Fastboi::camera.SetTarget(*go().transform, Camera::WATCHING); 17 | Fastboi::camera.zoom = 1.f; 18 | } 19 | 20 | void CameraController::Update() { 21 | if (isMouseHeld) { 22 | const Vec& movedPos = GetMousePosition(); 23 | Vecf delta = static_cast(dragOrigin - movedPos) * (2 - Fastboi::camera.zoom); 24 | 25 | go().transform->position = camOrigin + delta; 26 | } 27 | } 28 | 29 | void CameraController::OnClick(const ClickEvent& e) { 30 | if (e.button == 3) { 31 | if (e.type == ClickEvent::DOWN) { 32 | dragOrigin = GetMousePosition(); 33 | isMouseHeld = true; 34 | 35 | Input::BlockTargetedMouseUp(); // Don't let buttons absorb the mouse up 36 | } else if (e.type == ClickEvent::UP) { 37 | isMouseHeld = false; 38 | camOrigin = go().transform->position; 39 | } 40 | } 41 | } 42 | 43 | void CameraController::OnScroll(const MouseWheelEvent& e) { 44 | printf("Scroll: %i %i\n", e.scroll.x, e.scroll.y); 45 | 46 | Fastboi::camera.zoom += (float) e.scroll.y / 10.f; 47 | } 48 | 49 | void CameraController::Blueprint(Gameobject& go) { 50 | go.name = "Camera"; 51 | 52 | go.AddComponent(Position::zero()); 53 | go.AddComponent(); 54 | } -------------------------------------------------------------------------------- /src/containmentsimulator/CameraController.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Events.h" 4 | #include "Fastboi.h" 5 | #include "Input.h" 6 | 7 | namespace CS { 8 | using namespace Fastboi; 9 | 10 | class CameraController { 11 | private: 12 | GORef go; 13 | 14 | Vec dragOrigin; 15 | Position camOrigin; 16 | 17 | bool isMouseHeld = false; 18 | 19 | Input::ClickListener clickListener; 20 | Input::MouseWheelListener wheelListener; 21 | 22 | public: 23 | CameraController(GORef&& go); 24 | 25 | void Start(); 26 | void Update(); 27 | 28 | void OnClick(const ClickEvent& event); 29 | void OnScroll(const MouseWheelEvent& event); 30 | 31 | static void Blueprint(Gameobject& go); 32 | }; 33 | } -------------------------------------------------------------------------------- /src/containmentsimulator/Game.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | #include "Button.h" 3 | #include "CameraController.h" 4 | #include "Fastboi.h" 5 | #include "FastboiComps.h" 6 | #include 7 | #include "FastboiCore.h" 8 | #include "Resources.h" 9 | #include "Tile.h" 10 | #include "TileData.h" 11 | #include "WorldEditor.h" 12 | 13 | using namespace Fastboi; 14 | using namespace Fastboi::Components; 15 | using namespace CS; 16 | 17 | std::random_device rd; 18 | 19 | void CreateLayers(); 20 | 21 | void CS::LoadResources() { 22 | Resources::LoadImage("TileSpritesheet", "tiles.png"); 23 | 24 | const Texture& tiles = Resources::GetTexture("TileSpritesheet"); 25 | SDL_SetTextureBlendMode(tiles.GetSDL_Texture(), SDL_BLENDMODE_BLEND); 26 | 27 | InitTileData(); 28 | } 29 | 30 | void CS::InitGame() { 31 | Fastboi::Print("Hello, world!\n"); 32 | 33 | LoadResources(); 34 | 35 | Gameobject& mainCamera = Instantiate(); 36 | 37 | CreateLayers(); 38 | Gameobject& worldEditor = Instantiate(Position(0.25, 0.9)); 39 | 40 | } 41 | 42 | void CreateLayers() { 43 | std::uniform_int_distribution grassRotDist(0, 3); 44 | std::uniform_int_distribution grassDistX(0, 4); 45 | std::uniform_int_distribution grassDistY(0, 1); 46 | 47 | Gameobject& groundGO = Instantiate(Position(25, 20), Veci(15, 10), Veci(64, 64)); 48 | TileLayer& ground = groundGO.GetComponent(); 49 | Rect grassOrigin = Rect(960, 640, 64, 64); 50 | 51 | ground.LockTexture(); 52 | 53 | for (Tile& tile : ground.GetTiles()) { 54 | tile.SetCutout(Rect(grassOrigin.x + grassDistX(rd) * 64, grassOrigin.y + grassDistY(rd) * 64, 64, 64)); 55 | tile.SetRotation(90_deg * grassRotDist(rd)); 56 | } 57 | 58 | ground.UnlockTexture(); 59 | ground.UpdateTexture(); 60 | } -------------------------------------------------------------------------------- /src/containmentsimulator/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CS { 4 | void InitGame(); 5 | void LoadResources(); 6 | } -------------------------------------------------------------------------------- /src/containmentsimulator/TileData.cpp: -------------------------------------------------------------------------------- 1 | #include "TileData.h" 2 | #include "json/json.hpp" 3 | #include 4 | 5 | using namespace Fastboi; 6 | using namespace CS; 7 | using nlohmann::json; 8 | 9 | std::vector tileData; 10 | 11 | namespace CS { 12 | void from_json(const json& j, TileData& td) { 13 | unsigned int tempId; 14 | std::vector size; 15 | std::vector corner; 16 | 17 | j.at("id").get_to(tempId); 18 | j.at("size").get_to(size); 19 | j.at("corner").get_to(corner); 20 | 21 | td.id = static_cast(tempId); 22 | td.cutout = Rect(corner[0], corner[1], size[0], size[1]); 23 | } 24 | } 25 | 26 | const TileData& TileData::Get(TileID id) { 27 | return tileData[static_cast(id)]; 28 | } 29 | 30 | void CS::InitTileData() { 31 | std::ifstream file("data/tile_data.json"); 32 | json js; 33 | 34 | file >> js; 35 | 36 | auto& tiles = js["tiles"]; 37 | 38 | tileData = std::vector(tiles.size()); 39 | 40 | for (auto& x : tiles.items()) { 41 | std::string name = x.value()["name"]; 42 | printf("Name: %s\n", name.c_str()); 43 | 44 | TileData td = x.value().get(); 45 | 46 | tileData[static_cast(td.id)] = td; 47 | } 48 | } -------------------------------------------------------------------------------- /src/containmentsimulator/TileData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Rect.h" 4 | 5 | namespace CS { 6 | enum class TileID { 7 | WHITE_MARBLE = 0 8 | , GREY_SQUARES = 1 9 | , ORANGE_FUR = 2 10 | , WHITE_SQUARES = 3 11 | , BLUE_SQUARES = 4 12 | , TAN_SWIRLS = 5 13 | , NONE 14 | }; 15 | 16 | struct TileData { 17 | TileID id = TileID::WHITE_MARBLE; 18 | Fastboi::Rect cutout = Fastboi::Rect(0, 0, 0, 0); 19 | 20 | 21 | static const TileData& Get(TileID id); 22 | }; 23 | 24 | void InitTileData(); 25 | } -------------------------------------------------------------------------------- /src/containmentsimulator/TileManager.cpp: -------------------------------------------------------------------------------- 1 | #include "TileManager.h" 2 | #include 3 | 4 | using namespace CS; 5 | using namespace Fastboi; 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/containmentsimulator/TileManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Tile.h" 3 | 4 | namespace CS { 5 | 6 | } -------------------------------------------------------------------------------- /src/containmentsimulator/WorldEditor.cpp: -------------------------------------------------------------------------------- 1 | #include "WorldEditor.h" 2 | #include "Button.h" 3 | #include "ScreenElement.h" 4 | #include "TileData.h" 5 | 6 | using namespace Fastboi; 7 | using namespace CS; 8 | 9 | WorldEditor::WorldEditor(GORef&& go) : go(std::move(go)) { 10 | groundTileButtons.reserve(4); 11 | 12 | constexpr Size buttonSize{100, 100}; 13 | const ScreenElement& se = this->go().GetComponent(); 14 | 15 | for (int i = 0; i < 6; i++) { 16 | TileData td = TileData::Get(static_cast(i)); 17 | 18 | Gameobject& buttonGO = Instantiate( 19 | "TileSpritesheet" 20 | , se.anchor 21 | , buttonSize 22 | , td.cutout 23 | ); 24 | 25 | buttonGO.transform->Parent(go().transform); 26 | buttonGO.transform->position = buttonSize * Size(i, 0); 27 | 28 | Button& button = buttonGO.GetComponent