renderiranje - nazaj na singlethreaded ker me SDL ne mara :(
This commit is contained in:
68
src/object/entity.cpp
Normal file
68
src/object/entity.cpp
Normal 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,
|
||||
¢er,
|
||||
SDL_FLIP_NONE
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user