0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 05:43:43 +00:00

first pass - changed function names etc.

This commit is contained in:
Benedikt Galbavy 2024-11-18 13:29:30 +01:00
parent a8052b4bbb
commit 625ac98a57
27 changed files with 69 additions and 71 deletions

4
.gitmodules vendored
View File

@ -1,19 +1,15 @@
[submodule "SDL"] [submodule "SDL"]
path = extern/SDL path = extern/SDL
url = https://github.com/libsdl-org/SDL.git url = https://github.com/libsdl-org/SDL.git
branch = release-2.28.x
[submodule "SDL_image"] [submodule "SDL_image"]
path = extern/SDL_image path = extern/SDL_image
url = https://github.com/libsdl-org/SDL_image.git url = https://github.com/libsdl-org/SDL_image.git
branch = release-2.8.x
[submodule "extern/SDL_mixer"] [submodule "extern/SDL_mixer"]
path = extern/SDL_mixer path = extern/SDL_mixer
url = https://github.com/libsdl-org/SDL_mixer.git url = https://github.com/libsdl-org/SDL_mixer.git
branch = release-2.8.x
[submodule "extern/SDL_ttf"] [submodule "extern/SDL_ttf"]
path = extern/SDL_ttf path = extern/SDL_ttf
url = https://github.com/libsdl-org/SDL_ttf.git url = https://github.com/libsdl-org/SDL_ttf.git
branch = release-2.22.x
[submodule "extern/tmxlite"] [submodule "extern/tmxlite"]
path = extern/tmxlite path = extern/tmxlite
url = https://github.com/fallahn/tmxlite.git url = https://github.com/fallahn/tmxlite.git

View File

@ -31,11 +31,10 @@ add_library(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PUBLIC ${ENGINE_INCLUDE_DIR}) 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 target_link_libraries(${PROJECT_NAME} PUBLIC # should be private when all SDL functionality has a wrapper
SDL2::SDL2main SDL3::SDL3-static
SDL2::SDL2-static SDL3_image::SDL3_image-static
SDL2_image::SDL2_image-static SDL3_mixer::SDL3_mixer-static
SDL2_mixer::SDL2_mixer-static SDL3_ttf::SDL3_ttf-static
SDL2_ttf::SDL2_ttf-static
tmxlite tmxlite
) )

View File

@ -2,12 +2,12 @@
"folders": "folders":
[ [
{ {
"path": "." "path": ".",
} }
], ],
"settings": "settings":
{ {
"tab_size": 4 "tab_size": 4,
}, },
"build_systems": [ "build_systems": [
{ {
@ -23,7 +23,7 @@
"name": "Release", "name": "Release",
"shell_cmd": "cmake -DCMAKE_BUILD_TYPE=Release build && cmake --build build", "shell_cmd": "cmake -DCMAKE_BUILD_TYPE=Release build && cmake --build build",
}, },
] ],
}, },
{ {
"name": "Generate CMake", "name": "Generate CMake",
@ -43,7 +43,10 @@
"name": "Generate documentation", "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", "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":
[
],
} }

2
extern/SDL vendored

@ -1 +1 @@
Subproject commit 05eb08053d48fea9052ad02b3d619244aeb868d3 Subproject commit e027b85cc457556071cbb2f3f1bcf8803c1bc001

2
extern/SDL_image vendored

@ -1 +1 @@
Subproject commit abcf63aa71b4e3ac32120fa9870a6500ddcdcc89 Subproject commit b1c8ec7d75e3d8398940c9e04a8b82886ae6163d

2
extern/SDL_mixer vendored

@ -1 +1 @@
Subproject commit 5bcd40ad962dc72a3c051084ce128d78f7656566 Subproject commit 5e2a70519294bc6ec44f1870b019ecd4760fde7d

2
extern/SDL_ttf vendored

@ -1 +1 @@
Subproject commit 4a318f8dfaa1bb6f10e0c5e54052e25d3c7f3440 Subproject commit 4a8bda9197cc4d6fafd188bc9df6c7e8749a43a2

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL_render.h> #include <SDL3/SDL_render.h>
#include <SDL_mixer.h> #include <SDL3_mixer/SDL_mixer.h>
#include <map> #include <map>
#include <string> #include <string>
#include <functional> #include <functional>

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL.h> #include <SDL3/SDL.h>
#include "Component.h" #include "Component.h"
#include "Vector2D.h" #include "Vector2D.h"

View File

@ -7,7 +7,7 @@
#include "ColliderComponent.h" #include "ColliderComponent.h"
#include "Constants.h" #include "Constants.h"
#include "Entity.h" #include "Entity.h"
#include "SDL_rect.h" #include <SDL3/SDL_rect.h>
#include "SpriteComponent.h" #include "SpriteComponent.h"
#include "Vector2D.h" #include "Vector2D.h"
#include "Manager.h" #include "Manager.h"

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <SDL.h> #include <SDL3/SDL.h>
#include <SDL_image.h> #include <SDL3_image/SDL_image.h>
#include <SDL_mixer.h> #include <SDL3_mixer/SDL_mixer.h>
#include <functional> #include <functional>
#include <vector> #include <vector>

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include <SDL.h> #include <SDL3/SDL.h>
#include <map> #include <map>
#include "Component.h" #include "Component.h"
@ -99,7 +99,7 @@ public:
bool isKeyDown(Key key); bool isKeyDown(Key key);
private: private:
const Uint8* m_keyStates; const bool* m_keyStates;
SDL_Scancode mapKeyToSDL(Key key); SDL_Scancode mapKeyToSDL(Key key);
std::map<Key, SDL_Scancode> m_keyMappings; std::map<Key, SDL_Scancode> m_keyMappings;
void InitKeyMappings(); void InitKeyMappings();

View File

@ -34,7 +34,7 @@ private:
struct TileSetData { struct TileSetData {
std::string texturePath{}; std::string texturePath{};
tmx::Vector2i textureSize; tmx::Vector2f textureSize;
uint32_t tileCount{}; uint32_t tileCount{};
tmx::Vector2u tileCount2D; tmx::Vector2u tileCount2D;
uint32_t firstGID{}; uint32_t firstGID{};

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL_mixer.h> #include <SDL3_mixer/SDL_mixer.h>
#include <map> #include <map>
#include <vector> #include <vector>

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <map> #include <map>
#include <SDL_render.h> #include <SDL3/SDL_render.h>
#include <memory> #include <memory>
#include <string> #include <string>
@ -22,7 +22,7 @@ public:
private: private:
TransformComponent* transform; TransformComponent* transform;
SDL_Texture* texture; SDL_Texture* texture;
SDL_Rect srcRect, destRect; SDL_FRect srcRect, destRect;
const char* texturePath; const char* texturePath;

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include "ECS.h" #include "ECS.h"
#include <SDL_render.h> #include "SDL3/SDL_surface.h"
#include <SDL3/SDL_render.h>
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
@ -21,7 +22,10 @@ class TextureManager
SDL_Texture* loadTexture(const char* fileName); SDL_Texture* loadTexture(const char* fileName);
static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet); static std::vector<SDL_Rect> 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: private:
SDL_ScaleMode scaleMode = SDL_SCALEMODE_NEAREST;
Manager* manager; Manager* manager;
}; };

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL.h> #include <SDL3/SDL.h>
#include <string> #include <string>
#include <map> #include <map>

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <SDL.h> #include <SDL3/SDL.h>
#include <SDL_rect.h> #include <SDL3/SDL_rect.h>
class Vector2D class Vector2D
{ {

View File

@ -86,7 +86,7 @@ Vector2D AssetManager::calculateSpawnPosition()
conflict = false; conflict = false;
for (auto cc : this->man->getGame()->collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES })) 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; conflict = true;
break; break;

View File

@ -6,7 +6,7 @@
#include "Manager.h" #include "Manager.h"
#include "Vector2D.h" #include "Vector2D.h"
#include <SDL_rect.h> #include <SDL3/SDL_rect.h>
#include <bitset> #include <bitset>
#include <cstdio> #include <cstdio>
#include <memory> #include <memory>
@ -26,7 +26,7 @@ IntersectionBitSet CollisionHandler::getIntersection(Entity* entityA, Entity* en
colliderB.x += posModB.x; colliderB.x += posModB.x;
colliderB.y += posModB.y; colliderB.y += posModB.y;
if (!SDL_HasIntersection( if (!SDL_HasRectIntersection(
&colliderA, &colliderA,
&colliderB)) &colliderB))
return std::bitset<DIRECTION_C>(); return std::bitset<DIRECTION_C>();
@ -152,7 +152,7 @@ Entity* CollisionHandler::getAnyIntersection<Entity*>(
if (!entity->hasComponent<ColliderComponent>()) return nullptr; if (!entity->hasComponent<ColliderComponent>()) return nullptr;
for (auto& collider : getColliders(groupLabels, excludedEntities)) { for (auto& collider : getColliders(groupLabels, excludedEntities)) {
SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod; SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod;
if (SDL_HasIntersection(&rect, &collider->collider)) { if (SDL_HasRectIntersection(&rect, &collider->collider)) {
return collider->entity; return collider->entity;
} }
} }
@ -175,7 +175,7 @@ bool CollisionHandler::getAnyIntersection<bool>(
if (!entity->hasComponent<ColliderComponent>()) return false; if (!entity->hasComponent<ColliderComponent>()) return false;
for (auto& collider : getColliders(groupLabels, excludedEntities)) { for (auto& collider : getColliders(groupLabels, excludedEntities)) {
SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod; SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod;
if (SDL_HasIntersection(&rect, &collider->collider)) { if (SDL_HasRectIntersection(&rect, &collider->collider)) {
return true; return true;
} }
} }

View File

@ -1,20 +1,15 @@
#include "GameInternal.h" #include "GameInternal.h"
#include <SDL_error.h>
#include "CollisionHandler.h" #include "CollisionHandler.h"
#include "AssetManager.h" #include "AssetManager.h"
#include "RenderManager.h" #include "RenderManager.h"
#include "SDL_mixer.h" #include <SDL3_mixer/SDL_mixer.h>
#include "SDL3/SDL_init.h"
#include "SoundManager.h" #include "SoundManager.h"
#include "TileComponent.h"
#include "Direction.h"
#include "Entity.h" #include "Entity.h"
#include "HealthComponent.h" #include "HealthComponent.h"
#include "Map.h" #include "Map.h"
#include "TextureManager.h" #include "TextureManager.h"
#include "StatEffectsComponent.h"
#include "Constants.h"
#include "Game.h" #include "Game.h"
#include "GameFactory.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; 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; std::cout << "ERROR. Subsystem couldnt be initialized! " << SDL_GetError() << std::endl;
SDL_ClearError(); SDL_ClearError();
@ -55,7 +50,7 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he
return; return;
} }
window = SDL_CreateWindow(title, xpos, ypos, width, height, flags); window = SDL_CreateWindow(title, width, height, flags);
if (!window) if (!window)
{ {
std::cout << "ERROR: Window couldnt be created! " << SDL_GetError() << std::endl; 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); SDL_SetWindowIcon(window, icon);
renderer = SDL_CreateRenderer(window, -1, 0); renderer = SDL_CreateRenderer(window, NULL);
if (!renderer) if (!renderer)
{ {
std::cout << "ERROR: Renderer couldnt be created! " << SDL_GetError() << std::endl; 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); 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; std::cout << "ERROR: Mixer couldnt be initialized! " << SDL_GetError() << std::endl;
SDL_ClearError(); SDL_ClearError();
@ -108,7 +103,7 @@ void GameInternal::handleEvents()
switch (event.type) switch (event.type)
{ {
case SDL_QUIT: this->setRunning(false); case SDL_EVENT_QUIT: this->setRunning(false);
break; break;
default: default:

View File

@ -9,8 +9,8 @@
#include <ranges> #include <ranges>
#include <vector> #include <vector>
#include <SDL_error.h> #include <SDL3/SDL_error.h>
#include <SDL_render.h> #include <SDL3/SDL_render.h>
#include <tmxlite/Layer.hpp> #include <tmxlite/Layer.hpp>
#include <tmxlite/Map.hpp> #include <tmxlite/Map.hpp>
@ -102,16 +102,14 @@ void Map::loadTileLayer(const tmx::TileLayer& layer)
| std::views::transform([&](uint16_t i) { | std::views::transform([&](uint16_t i) {
const char* texturePath = this->mapData.texturePaths->at(i).c_str(); const char* texturePath = this->mapData.texturePaths->at(i).c_str();
tmx::Vector2i textureSize; tmx::Vector2f textureSize;
SDL_QueryTexture( SDL_GetTextureSize(
VEGO_Game().textureManager->loadTexture(texturePath), VEGO_Game().textureManager->loadTexture(texturePath),
nullptr,
nullptr,
&(textureSize.x), &(textureSize.x),
&(textureSize.y) &(textureSize.y)
); );
tmx::Vector2u tileCount2D = { textureSize.x / this->mapData.mapTileSize->x, textureSize.y / this->mapData.mapTileSize->y }; tmx::Vector2u tileCount2D = { static_cast<unsigned int>(textureSize.x / this->mapData.mapTileSize->x), static_cast<unsigned int>(textureSize.y / this->mapData.mapTileSize->y) };
uint32_t tileCount = this->mapData.tileSets->at(i).getTileCount(); uint32_t tileCount = this->mapData.tileSets->at(i).getTileCount();
uint32_t firstGID = this->mapData.tileSets->at(i).getFirstGID(); uint32_t firstGID = this->mapData.tileSets->at(i).getFirstGID();

View File

@ -4,6 +4,8 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <SDL3_mixer/SDL_mixer.h>
#include "GameInternal.h" #include "GameInternal.h"
#include "AssetManager.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) 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) 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) 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) 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;
} }
} }

View File

@ -1,6 +1,6 @@
#include "SpriteComponent.h" #include "SpriteComponent.h"
#include <SDL_timer.h> #include <SDL3/SDL_timer.h>
#include <cstring> #include <cstring>
#include <memory> #include <memory>

View File

@ -1,6 +1,5 @@
#include "TextureManager.h" #include "TextureManager.h"
#include <memory>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -14,13 +13,14 @@ SDL_Texture* TextureManager::loadTexture(const char* fileName)
} }
auto texture = IMG_LoadTexture(this->manager->getGame()->renderer, fileName); auto texture = IMG_LoadTexture(this->manager->getGame()->renderer, fileName);
if (texture == NULL) throw std::runtime_error(std::string("Couldn't load texture '") + 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); this->texture_cache.emplace(std::string(fileName), texture);
printf("Loaded texture at '%s'\n", fileName); printf("Loaded texture at '%s'\n", fileName);
return texture; 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_FlipMode flip = flipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
SDL_RenderCopyEx(renderer, texture, &src, &dest, 0, NULL, flip); SDL_RenderTextureRotated(renderer, texture, &src, &dest, 0, NULL, flip);
} }

View File

@ -1,5 +1,5 @@
#include "Vector2D.h" #include "Vector2D.h"
#include "SDL_rect.h" #include <SDL3/SDL_rect.h>
Vector2D::Vector2D() Vector2D::Vector2D()
{ {

View File

@ -1,5 +1,6 @@
#include <iostream> #include <iostream>
#include <ctime> #include <ctime>
#include <SDL3/SDL_main.h>
#include "VEGO.h" #include "VEGO.h"
#include "Entity.h" #include "Entity.h"