diff --git a/.gitmodules b/.gitmodules index 84e7c1b..0781886 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,19 +1,15 @@ [submodule "SDL"] path = extern/SDL url = https://github.com/libsdl-org/SDL.git - branch = release-2.28.x [submodule "SDL_image"] path = extern/SDL_image url = https://github.com/libsdl-org/SDL_image.git - branch = release-2.8.x [submodule "extern/SDL_mixer"] path = extern/SDL_mixer url = https://github.com/libsdl-org/SDL_mixer.git - branch = release-2.8.x [submodule "extern/SDL_ttf"] path = extern/SDL_ttf url = https://github.com/libsdl-org/SDL_ttf.git - branch = release-2.22.x [submodule "extern/tmxlite"] path = extern/tmxlite url = https://github.com/fallahn/tmxlite.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8934839..8bc9a02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,11 +31,10 @@ add_library(${PROJECT_NAME} ${SOURCES}) target_include_directories(${PROJECT_NAME} PUBLIC ${ENGINE_INCLUDE_DIR}) target_link_libraries(${PROJECT_NAME} PUBLIC # should be private when all SDL functionality has a wrapper - SDL2::SDL2main - SDL2::SDL2-static - SDL2_image::SDL2_image-static - SDL2_mixer::SDL2_mixer-static - SDL2_ttf::SDL2_ttf-static + SDL3::SDL3-static + SDL3_image::SDL3_image-static + SDL3_mixer::SDL3_mixer-static + SDL3_ttf::SDL3_ttf-static tmxlite ) diff --git a/engine.sublime-project b/engine.sublime-project index 1466f8e..a2490fa 100644 --- a/engine.sublime-project +++ b/engine.sublime-project @@ -2,12 +2,12 @@ "folders": [ { - "path": "." + "path": ".", } - ], + ], "settings": { - "tab_size": 4 + "tab_size": 4, }, "build_systems": [ { @@ -23,7 +23,7 @@ "name": "Release", "shell_cmd": "cmake -DCMAKE_BUILD_TYPE=Release build && cmake --build build", }, - ] + ], }, { "name": "Generate CMake", @@ -43,7 +43,10 @@ "name": "Generate documentation", "shell_cmd": "docker run --rm -v \"$project_path:/source\" -v \"$project_path/docs:/output\" -v \"$project_path/docs/Doxyfile:/Doxyfile\" vego_engine-docker", }, - ] + ], } - ] + ], + "debugger_configurations": + [ + ], } diff --git a/extern/SDL b/extern/SDL index 05eb080..e027b85 160000 --- a/extern/SDL +++ b/extern/SDL @@ -1 +1 @@ -Subproject commit 05eb08053d48fea9052ad02b3d619244aeb868d3 +Subproject commit e027b85cc457556071cbb2f3f1bcf8803c1bc001 diff --git a/extern/SDL_image b/extern/SDL_image index abcf63a..b1c8ec7 160000 --- a/extern/SDL_image +++ b/extern/SDL_image @@ -1 +1 @@ -Subproject commit abcf63aa71b4e3ac32120fa9870a6500ddcdcc89 +Subproject commit b1c8ec7d75e3d8398940c9e04a8b82886ae6163d diff --git a/extern/SDL_mixer b/extern/SDL_mixer index 5bcd40a..5e2a705 160000 --- a/extern/SDL_mixer +++ b/extern/SDL_mixer @@ -1 +1 @@ -Subproject commit 5bcd40ad962dc72a3c051084ce128d78f7656566 +Subproject commit 5e2a70519294bc6ec44f1870b019ecd4760fde7d diff --git a/extern/SDL_ttf b/extern/SDL_ttf index 4a318f8..4a8bda9 160000 --- a/extern/SDL_ttf +++ b/extern/SDL_ttf @@ -1 +1 @@ -Subproject commit 4a318f8dfaa1bb6f10e0c5e54052e25d3c7f3440 +Subproject commit 4a8bda9197cc4d6fafd188bc9df6c7e8749a43a2 diff --git a/include/AssetManager.h b/include/AssetManager.h index 1d3c97a..212828c 100644 --- a/include/AssetManager.h +++ b/include/AssetManager.h @@ -1,6 +1,6 @@ #pragma once -#include -#include +#include +#include #include #include #include diff --git a/include/ColliderComponent.h b/include/ColliderComponent.h index ef4d5c8..b49fd33 100644 --- a/include/ColliderComponent.h +++ b/include/ColliderComponent.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "Component.h" #include "Vector2D.h" diff --git a/include/CollisionHandler.h b/include/CollisionHandler.h index 9802f7d..43aa0ae 100644 --- a/include/CollisionHandler.h +++ b/include/CollisionHandler.h @@ -7,7 +7,7 @@ #include "ColliderComponent.h" #include "Constants.h" #include "Entity.h" -#include "SDL_rect.h" +#include #include "SpriteComponent.h" #include "Vector2D.h" #include "Manager.h" diff --git a/include/GameInternal.h b/include/GameInternal.h index 44cec2d..57b9aac 100644 --- a/include/GameInternal.h +++ b/include/GameInternal.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include #include #include diff --git a/include/InputComponent.h b/include/InputComponent.h index 9382cf1..8d62202 100644 --- a/include/InputComponent.h +++ b/include/InputComponent.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include "Component.h" @@ -99,7 +99,7 @@ public: bool isKeyDown(Key key); private: - const Uint8* m_keyStates; + const bool* m_keyStates; SDL_Scancode mapKeyToSDL(Key key); std::map m_keyMappings; void InitKeyMappings(); diff --git a/include/Map.h b/include/Map.h index 244322e..58ebf4d 100644 --- a/include/Map.h +++ b/include/Map.h @@ -34,7 +34,7 @@ private: struct TileSetData { std::string texturePath{}; - tmx::Vector2i textureSize; + tmx::Vector2f textureSize; uint32_t tileCount{}; tmx::Vector2u tileCount2D; uint32_t firstGID{}; diff --git a/include/SoundManager.h b/include/SoundManager.h index 8663d34..38a6b2c 100644 --- a/include/SoundManager.h +++ b/include/SoundManager.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/include/SpriteComponent.h b/include/SpriteComponent.h index 0676549..f8077cd 100644 --- a/include/SpriteComponent.h +++ b/include/SpriteComponent.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -22,7 +22,7 @@ public: private: TransformComponent* transform; SDL_Texture* texture; - SDL_Rect srcRect, destRect; + SDL_FRect srcRect, destRect; const char* texturePath; diff --git a/include/TextureManager.h b/include/TextureManager.h index 3e4f1c4..22f19ed 100644 --- a/include/TextureManager.h +++ b/include/TextureManager.h @@ -1,7 +1,8 @@ #pragma once #include "ECS.h" -#include +#include "SDL3/SDL_surface.h" +#include #include #include #include @@ -21,7 +22,10 @@ class TextureManager SDL_Texture* loadTexture(const char* fileName); static std::vector splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet); - static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped = false); + static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_FRect src, SDL_FRect dest, bool flipped = false); + + void setScaleMode(SDL_ScaleMode scaleMode) { this->scaleMode = scaleMode; } private: + SDL_ScaleMode scaleMode = SDL_SCALEMODE_NEAREST; Manager* manager; }; \ No newline at end of file diff --git a/include/TileComponent.h b/include/TileComponent.h index 8844daa..ecdbfc6 100644 --- a/include/TileComponent.h +++ b/include/TileComponent.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/include/Vector2D.h b/include/Vector2D.h index bc2d652..9b38e18 100644 --- a/include/Vector2D.h +++ b/include/Vector2D.h @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include class Vector2D { diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 25ce8ad..e4b1cf4 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -86,7 +86,7 @@ Vector2D AssetManager::calculateSpawnPosition() conflict = false; for (auto cc : this->man->getGame()->collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES })) { - if (SDL_HasIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile")) + if (SDL_HasRectIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile")) { conflict = true; break; diff --git a/src/CollisionHandler.cpp b/src/CollisionHandler.cpp index 5477c6c..5821303 100644 --- a/src/CollisionHandler.cpp +++ b/src/CollisionHandler.cpp @@ -6,7 +6,7 @@ #include "Manager.h" #include "Vector2D.h" -#include +#include #include #include #include @@ -26,7 +26,7 @@ IntersectionBitSet CollisionHandler::getIntersection(Entity* entityA, Entity* en colliderB.x += posModB.x; colliderB.y += posModB.y; - if (!SDL_HasIntersection( + if (!SDL_HasRectIntersection( &colliderA, &colliderB)) return std::bitset(); @@ -152,7 +152,7 @@ Entity* CollisionHandler::getAnyIntersection( if (!entity->hasComponent()) return nullptr; for (auto& collider : getColliders(groupLabels, excludedEntities)) { SDL_Rect rect = entity->getComponent().collider + posMod; - if (SDL_HasIntersection(&rect, &collider->collider)) { + if (SDL_HasRectIntersection(&rect, &collider->collider)) { return collider->entity; } } @@ -175,7 +175,7 @@ bool CollisionHandler::getAnyIntersection( if (!entity->hasComponent()) return false; for (auto& collider : getColliders(groupLabels, excludedEntities)) { SDL_Rect rect = entity->getComponent().collider + posMod; - if (SDL_HasIntersection(&rect, &collider->collider)) { + if (SDL_HasRectIntersection(&rect, &collider->collider)) { return true; } } diff --git a/src/GameInternal.cpp b/src/GameInternal.cpp index 0ef8c69..d3a65dc 100644 --- a/src/GameInternal.cpp +++ b/src/GameInternal.cpp @@ -1,20 +1,15 @@ #include "GameInternal.h" -#include - #include "CollisionHandler.h" #include "AssetManager.h" #include "RenderManager.h" -#include "SDL_mixer.h" +#include +#include "SDL3/SDL_init.h" #include "SoundManager.h" -#include "TileComponent.h" -#include "Direction.h" #include "Entity.h" #include "HealthComponent.h" #include "Map.h" #include "TextureManager.h" -#include "StatEffectsComponent.h" -#include "Constants.h" #include "Game.h" #include "GameFactory.h" @@ -43,7 +38,7 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he flags = SDL_WINDOW_FULLSCREEN; } - if (SDL_Init(SDL_INIT_EVERYTHING) != 0) + if (!SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO)) { std::cout << "ERROR. Subsystem couldnt be initialized! " << SDL_GetError() << std::endl; SDL_ClearError(); @@ -55,7 +50,7 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he return; } - window = SDL_CreateWindow(title, xpos, ypos, width, height, flags); + window = SDL_CreateWindow(title, width, height, flags); if (!window) { std::cout << "ERROR: Window couldnt be created! " << SDL_GetError() << std::endl; @@ -72,7 +67,7 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he SDL_SetWindowIcon(window, icon); - renderer = SDL_CreateRenderer(window, -1, 0); + renderer = SDL_CreateRenderer(window, NULL); if (!renderer) { std::cout << "ERROR: Renderer couldnt be created! " << SDL_GetError() << std::endl; @@ -81,7 +76,7 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he } SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); - if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) + if (!Mix_OpenAudio(0, NULL)) { std::cout << "ERROR: Mixer couldnt be initialized! " << SDL_GetError() << std::endl; SDL_ClearError(); @@ -108,7 +103,7 @@ void GameInternal::handleEvents() switch (event.type) { - case SDL_QUIT: this->setRunning(false); + case SDL_EVENT_QUIT: this->setRunning(false); break; default: diff --git a/src/Map.cpp b/src/Map.cpp index dab109b..467a7a2 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -9,8 +9,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -102,16 +102,14 @@ void Map::loadTileLayer(const tmx::TileLayer& layer) | std::views::transform([&](uint16_t i) { const char* texturePath = this->mapData.texturePaths->at(i).c_str(); - tmx::Vector2i textureSize; - SDL_QueryTexture( + tmx::Vector2f textureSize; + SDL_GetTextureSize( VEGO_Game().textureManager->loadTexture(texturePath), - nullptr, - nullptr, &(textureSize.x), &(textureSize.y) ); - tmx::Vector2u tileCount2D = { textureSize.x / this->mapData.mapTileSize->x, textureSize.y / this->mapData.mapTileSize->y }; + tmx::Vector2u tileCount2D = { static_cast(textureSize.x / this->mapData.mapTileSize->x), static_cast(textureSize.y / this->mapData.mapTileSize->y) }; uint32_t tileCount = this->mapData.tileSets->at(i).getTileCount(); uint32_t firstGID = this->mapData.tileSets->at(i).getFirstGID(); diff --git a/src/SoundManager.cpp b/src/SoundManager.cpp index 2954b9f..3f101e2 100644 --- a/src/SoundManager.cpp +++ b/src/SoundManager.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include "GameInternal.h" #include "AssetManager.h" @@ -65,12 +67,12 @@ void SoundManager::playSound(GameInternal* game, std::string sound, bool canOver if(Mix_VolumeChunk(game->assets->getSound(sound), volume) == -1) { - std::cerr << "Error adjusting volume: " << Mix_GetError() << std::endl; + std::cerr << "Error adjusting volume: " /*<< Mix_GetError()*/ << std::endl; } if (Mix_PlayChannel(channel, game->assets->getSound(sound), loops) == -1) { - std::cerr << "Error playing sound '" << sound << "': " << Mix_GetError() << std::endl; + std::cerr << "Error playing sound '" << sound << "': " /*<< Mix_GetError()*/ << std::endl; } } @@ -87,12 +89,12 @@ void SoundManager::playMusic(GameInternal* game, std::string music, int loops, i if(Mix_VolumeMusic(volume) == -1) { - std::cerr << "Error adjusting volume: " << Mix_GetError() << std::endl; + std::cerr << "Error adjusting volume: " /*<< Mix_GetError()*/ << std::endl; } if (Mix_PlayMusic(game->assets->getMusic(music), loops) == -1) { - std::cerr << "Error playing music '" << music << "': " << Mix_GetError() << std::endl; + std::cerr << "Error playing music '" << music << "': " /*<< Mix_GetError()*/ << std::endl; } } diff --git a/src/SpriteComponent.cpp b/src/SpriteComponent.cpp index ae27ea7..026f8dc 100644 --- a/src/SpriteComponent.cpp +++ b/src/SpriteComponent.cpp @@ -1,6 +1,6 @@ #include "SpriteComponent.h" -#include +#include #include #include diff --git a/src/TextureManager.cpp b/src/TextureManager.cpp index 3e46d46..b31ee25 100644 --- a/src/TextureManager.cpp +++ b/src/TextureManager.cpp @@ -1,6 +1,5 @@ #include "TextureManager.h" -#include #include #include @@ -14,13 +13,14 @@ SDL_Texture* TextureManager::loadTexture(const char* fileName) } auto texture = IMG_LoadTexture(this->manager->getGame()->renderer, fileName); if (texture == NULL) throw std::runtime_error(std::string("Couldn't load texture '") + fileName + "'"); + SDL_SetTextureScaleMode(texture, this->scaleMode); // linear scaling results in blurry images this->texture_cache.emplace(std::string(fileName), texture); printf("Loaded texture at '%s'\n", fileName); return texture; } -void TextureManager::draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped) +void TextureManager::draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_FRect src, SDL_FRect dest, bool flipped) { - SDL_RendererFlip flip = flipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE; - SDL_RenderCopyEx(renderer, texture, &src, &dest, 0, NULL, flip); + SDL_FlipMode flip = flipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE; + SDL_RenderTextureRotated(renderer, texture, &src, &dest, 0, NULL, flip); } \ No newline at end of file diff --git a/src/Vector2D.cpp b/src/Vector2D.cpp index 6368ff3..530e316 100644 --- a/src/Vector2D.cpp +++ b/src/Vector2D.cpp @@ -1,5 +1,5 @@ #include "Vector2D.h" -#include "SDL_rect.h" +#include Vector2D::Vector2D() { diff --git a/src/main.cpp b/src/main.cpp index da7f8a6..33bccd7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "VEGO.h" #include "Entity.h"