0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 04:43:41 +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"]
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

View File

@ -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
)

View File

@ -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":
[
],
}

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
#include <SDL_render.h>
#include <SDL_mixer.h>
#include <SDL3/SDL_render.h>
#include <SDL3_mixer/SDL_mixer.h>
#include <map>
#include <string>
#include <functional>

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
#pragma once
#include <SDL.h>
#include <SDL3/SDL.h>
#include <map>
#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<Key, SDL_Scancode> m_keyMappings;
void InitKeyMappings();

View File

@ -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{};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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;

View File

@ -6,7 +6,7 @@
#include "Manager.h"
#include "Vector2D.h"
#include <SDL_rect.h>
#include <SDL3/SDL_rect.h>
#include <bitset>
#include <cstdio>
#include <memory>
@ -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<DIRECTION_C>();
@ -152,7 +152,7 @@ Entity* CollisionHandler::getAnyIntersection<Entity*>(
if (!entity->hasComponent<ColliderComponent>()) return nullptr;
for (auto& collider : getColliders(groupLabels, excludedEntities)) {
SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod;
if (SDL_HasIntersection(&rect, &collider->collider)) {
if (SDL_HasRectIntersection(&rect, &collider->collider)) {
return collider->entity;
}
}
@ -175,7 +175,7 @@ bool CollisionHandler::getAnyIntersection<bool>(
if (!entity->hasComponent<ColliderComponent>()) return false;
for (auto& collider : getColliders(groupLabels, excludedEntities)) {
SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod;
if (SDL_HasIntersection(&rect, &collider->collider)) {
if (SDL_HasRectIntersection(&rect, &collider->collider)) {
return true;
}
}

View File

@ -1,20 +1,15 @@
#include "GameInternal.h"
#include <SDL_error.h>
#include "CollisionHandler.h"
#include "AssetManager.h"
#include "RenderManager.h"
#include "SDL_mixer.h"
#include <SDL3_mixer/SDL_mixer.h>
#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:

View File

@ -9,8 +9,8 @@
#include <ranges>
#include <vector>
#include <SDL_error.h>
#include <SDL_render.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_render.h>
#include <tmxlite/Layer.hpp>
#include <tmxlite/Map.hpp>
@ -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<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 firstGID = this->mapData.tileSets->at(i).getFirstGID();

View File

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

View File

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

View File

@ -1,6 +1,5 @@
#include "TextureManager.h"
#include <memory>
#include <stdexcept>
#include <string>
@ -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);
}

View File

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

View File

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