renderiranje - nazaj na singlethreaded ker me SDL ne mara :(

This commit is contained in:
2026-03-11 20:19:15 +01:00
parent d748ca63a0
commit 834f0b29c3
18 changed files with 230 additions and 75 deletions

68
src/object/entity.cpp Normal file
View File

@@ -0,0 +1,68 @@
#include <object/entity.hpp>
#include <renderer/renderer.hpp>
#include <renderer/texture.hpp>
namespace Game::Object {
Entity::~Entity() {
LOG("Destroyed Entity: " << mName);
}
Entity::Entity(const Entity& other) : mName(other.mName), mTex(other.mTex), mTransform(other.mTransform), mIsActive(other.mIsActive) {
LOG("Copied Entity: " << mName);
}
Entity& Entity::operator=(const Entity& other) {
if (this != &other) {
mName = other.mName;
mTex = other.mTex;
mTransform = other.mTransform;
mIsActive = other.mIsActive;
}
return *this;
}
Entity::Entity(Entity&& other) noexcept : mName(std::move(other.mName)), mTex(other.mTex), mTransform(other.mTransform), mIsActive(other.mIsActive) {
other.mTex = nullptr;
LOG("Moved Entity: " << mName);
}
Entity& Entity::operator=(Entity&& other) noexcept {
if (this != &other) {
mName = std::move(other.mName);
mTex = other.mTex;
mTransform = other.mTransform;
mIsActive = other.mIsActive;
other.mTex = nullptr;
}
return *this;
}
void Entity::render(Game::Renderer::Renderer* renderer) {
if (!mIsActive || !mTex) return; // Don't render if not active or if there's no texture
float w, h;
SDL_GetTextureSize(mTex->getSDLTexture(), &w, &h);
SDL_FRect dst;
dst.w = w * mTransform.scaleX * mScaleConstant; // 1.f is HUGE, so this is just a constant to make the default scale more reasonable
dst.h = h * mTransform.scaleY * mScaleConstant;
// Top-left origin
dst.x = mTransform.x;
dst.y = mTransform.y;
SDL_FPoint center;
center.x = dst.w / 2.f;
center.y = dst.h / 2.f;
SDL_RenderTextureRotated(
renderer->getSDLRenderer(),
mTex->getSDLTexture(),
nullptr,
&dst,
mTransform.rotation,
&center,
SDL_FLIP_NONE
);
}
}