Compare commits
1 Commits
45501f153d
...
769bbd4261
| Author | SHA256 | Date | |
|---|---|---|---|
| 769bbd4261 |
@@ -1,9 +1,21 @@
|
||||
#include "IdGenerator.hpp"
|
||||
|
||||
std::mt19937 rnd = std::mt19937();
|
||||
bool init = false;
|
||||
std::mt19937 rnd;
|
||||
auto gen = uuids::uuid_random_generator(rnd);
|
||||
|
||||
uuids::uuid TSE::GenerateRandomUUID()
|
||||
{
|
||||
if(!init)
|
||||
{
|
||||
InitRandomIDs();
|
||||
init = true;
|
||||
}
|
||||
return gen();
|
||||
}
|
||||
}
|
||||
|
||||
void TSE::InitRandomIDs()
|
||||
{
|
||||
rnd = std::mt19937();
|
||||
gen = uuids::uuid_random_generator(rnd);
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@
|
||||
namespace TSE
|
||||
{
|
||||
uuids::uuid GenerateRandomUUID();
|
||||
void InitRandomIDs();
|
||||
} // namespace TSE
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Camera.hpp"
|
||||
#include "elements/Transformable.hpp"
|
||||
#include "interfaces/IRenderer.hpp"
|
||||
#include "uuid.h"
|
||||
|
||||
TSE::Camera* TSE::Camera::mainCamera = nullptr;
|
||||
TSE::ICameraHelper* TSE::Camera::helper = nullptr;
|
||||
@@ -30,6 +31,11 @@ float TSE::Camera::GetFov() const
|
||||
return fov;
|
||||
}
|
||||
|
||||
const TSE::Vector2 &TSE::Camera::GetRenderTargetSize() const
|
||||
{
|
||||
return lastRtSize;
|
||||
}
|
||||
|
||||
TSE::Vector3 TSE::Camera::SceenPositionToGamePosition(Vector2 screenPos)
|
||||
{
|
||||
float x = 2.0f * screenPos.x / lastRtSize.x -1.0f;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Vector3.hpp"
|
||||
#include "interfaces/IRenderTarget.hpp"
|
||||
#include "elements/BehaviourScript.hpp"
|
||||
#include "uuid.h"
|
||||
|
||||
namespace TSE
|
||||
{
|
||||
@@ -31,16 +32,17 @@ namespace TSE
|
||||
ProjectionType projection = ProjectionType::Orthographic;
|
||||
Matrix4x4* projectionMatrix = nullptr;
|
||||
Matrix4x4 viewMatrix;
|
||||
|
||||
|
||||
float nearClippingPlane = 0;
|
||||
float farClippingPlane = 100;
|
||||
|
||||
|
||||
//perspective
|
||||
float fov = 60;
|
||||
|
||||
|
||||
Vector2 lastRtSize = {0, 0};
|
||||
|
||||
|
||||
public:
|
||||
std::vector<uuids::uuid> layersNotToRender;
|
||||
static ICameraHelper* helper;
|
||||
static Camera* mainCamera;
|
||||
|
||||
@@ -50,6 +52,7 @@ namespace TSE
|
||||
float GetNearClippingPlane() const;
|
||||
float GetFarClippingPlane() const;
|
||||
float GetFov() const;
|
||||
const Vector2& GetRenderTargetSize() const;
|
||||
|
||||
// Setter
|
||||
Vector3 SceenPositionToGamePosition(Vector2 screenPos);
|
||||
|
||||
@@ -7,9 +7,14 @@ TSE::TileMapChunk::TileMapChunk(int _chunksize, const Vector2 &_pos, SortingOrde
|
||||
order = _order;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::SetTile(const Vector2& p, const Vector2& Spriteindex, TileSet* set)
|
||||
void TSE::TileMapChunk::SetTile(const Vector2& p, const Vector2& Spriteindex, const Vector2& Normalindex, TileSet* set)
|
||||
{
|
||||
sprites[p] = set->GetSpriteIdAt(Spriteindex.x, Spriteindex.y);
|
||||
int normalid = -1;
|
||||
if(Normalindex != Vector2(-1,-1))
|
||||
normalid = set->GetSpriteIdAt(Normalindex.x, Normalindex.y);
|
||||
sprites[p] = {set->GetSpriteIdAt(Spriteindex.x, Spriteindex.y), normalid};
|
||||
dirtyPositions = true;
|
||||
dirtySpriteIds = true;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::RemoveTile(Vector2 p)
|
||||
@@ -22,118 +27,130 @@ void TSE::TileMapChunk::SetOrdering(SortingOrder _order)
|
||||
order = _order;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::GetOrderedPositions(Vector2 *array)
|
||||
const std::vector<TSE::Vector2>* TSE::TileMapChunk::GetOrderedPositions()
|
||||
{
|
||||
switch (order)
|
||||
if(dirtyPositions)
|
||||
{
|
||||
case TopLeft:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
orderedPositions.clear();
|
||||
switch (order)
|
||||
{
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
case TopLeft:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->first - offset;
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedPositions.push_back(v->first - offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->first - offset;
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedPositions.push_back(v->first - offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->first - offset;
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedPositions.push_back(v->first - offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->first - offset;
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedPositions.push_back(v->first - offset);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
dirtyPositions = false;
|
||||
}
|
||||
return &orderedPositions;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::GetOrderedSpriteIds(int *array)
|
||||
const std::vector<TSE::Vector2i>* TSE::TileMapChunk::GetOrderedSpriteIds()
|
||||
{
|
||||
switch (order)
|
||||
if(dirtySpriteIds)
|
||||
{
|
||||
case TopLeft:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
orderedSpriteIDs.clear();
|
||||
switch (order)
|
||||
{
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
case TopLeft:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->second;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedSpriteIDs.push_back(v->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->second;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedSpriteIDs.push_back(v->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->second;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedSpriteIDs.push_back(v->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->second;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedSpriteIDs.push_back(v->second);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
dirtySpriteIds = false;
|
||||
}
|
||||
return &orderedSpriteIDs;
|
||||
}
|
||||
|
||||
int TSE::TileMapChunk::GetChunksize()
|
||||
@@ -154,17 +171,18 @@ void TSE::TileMap::RemoveTile(Vector2 p)
|
||||
chunks[chunkIndex].RemoveTile(chunkInnerPos);
|
||||
}
|
||||
|
||||
void TSE::TileMap::SetTile(Vector2 p, Vector2 Spriteindex)
|
||||
void TSE::TileMap::SetTile(Vector2 p, Vector2 Spriteindex, Vector2 Normalindex)
|
||||
{
|
||||
Vector2 chunkInnerPos = LocalToChunkPos(p);
|
||||
Vector2 chunkIndex = p - chunkInnerPos;
|
||||
if(!chunks.contains(chunkIndex))
|
||||
{
|
||||
dirty = true;
|
||||
chunks[chunkIndex] = TileMapChunk(chunkSize, chunkIndex, order);
|
||||
chunks[chunkIndex].nextLine = nextLine;
|
||||
CheckBounds(chunkIndex);
|
||||
}
|
||||
chunks[chunkIndex].SetTile(chunkInnerPos, Spriteindex, set);
|
||||
chunks[chunkIndex].SetTile(chunkInnerPos, Spriteindex, Normalindex, set);
|
||||
}
|
||||
|
||||
TSE::TileMapChunk* TSE::TileMap::GetChunk(const Vector2 &pos)
|
||||
@@ -175,60 +193,65 @@ TSE::TileMapChunk* TSE::TileMap::GetChunk(const Vector2 &pos)
|
||||
return &chunks[pos];
|
||||
}
|
||||
|
||||
void TSE::TileMap::GetChunkPositionsInOrder(Vector2 *arr)
|
||||
const std::vector<TSE::Vector2>* TSE::TileMap::GetChunkPositionsInOrder()
|
||||
{
|
||||
|
||||
switch (order)
|
||||
if(dirty)
|
||||
{
|
||||
case TopLeft:
|
||||
for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++)
|
||||
orderedChunks.clear();
|
||||
switch (order)
|
||||
{
|
||||
for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++)
|
||||
case TopLeft:
|
||||
for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
*arr++ = v->first;
|
||||
for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
orderedChunks.push_back(v->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++)
|
||||
{
|
||||
for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--)
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
*arr++ = v->first;
|
||||
for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
orderedChunks.push_back(v->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--)
|
||||
{
|
||||
for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++)
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
*arr++ = v->first;
|
||||
for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
orderedChunks.push_back(v->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--)
|
||||
{
|
||||
for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--)
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
*arr++ = v->first;
|
||||
for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
orderedChunks.push_back(v->first);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
dirty = false;
|
||||
}
|
||||
return &orderedChunks;
|
||||
}
|
||||
|
||||
int TSE::TileMap::GetChunkCount()
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <unordered_map>
|
||||
#include "elements/BehaviourScript.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "Vector2i.hpp"
|
||||
#include "elements/Sprite.hpp"
|
||||
#include "elements/TileSet.hpp"
|
||||
|
||||
@@ -21,19 +22,23 @@ namespace TSE
|
||||
struct TileMapChunk
|
||||
{
|
||||
private:
|
||||
bool dirtyPositions = true;
|
||||
bool dirtySpriteIds = true;
|
||||
std::vector<Vector2> orderedPositions;
|
||||
std::vector<Vector2i> orderedSpriteIDs;
|
||||
SortingOrder order;
|
||||
int chunksize;
|
||||
std::unordered_map<Vector2, int> sprites;
|
||||
std::unordered_map<Vector2, Vector2i> sprites;
|
||||
public:
|
||||
Vector2 nextLine;
|
||||
Vector2 pos;
|
||||
TileMapChunk(int _chunksize = 16, const Vector2& _pos = {0,0}, SortingOrder _order = TopRight);
|
||||
|
||||
void SetTile(const Vector2& p, const Vector2& Spriteindex, TileSet* set);
|
||||
void SetTile(const Vector2& p, const Vector2& Spriteindex, const Vector2& Normalindex, TileSet* set);
|
||||
void RemoveTile(Vector2 p);
|
||||
void SetOrdering(SortingOrder _order);
|
||||
void GetOrderedPositions(Vector2* array);
|
||||
void GetOrderedSpriteIds(int* array);
|
||||
const std::vector<Vector2>* GetOrderedPositions();
|
||||
const std::vector<Vector2i>* GetOrderedSpriteIds();
|
||||
int GetChunksize();
|
||||
int GetSpriteCount();
|
||||
|
||||
@@ -42,6 +47,8 @@ namespace TSE
|
||||
class TileMap : public BehaviourScript
|
||||
{
|
||||
private:
|
||||
bool dirty = true;
|
||||
std::vector<Vector2> orderedChunks;
|
||||
Rect bounds = Rect(0,0,0,0);
|
||||
Vector2 nextLine = Vector2(-0.5f, 1.25f);
|
||||
public:
|
||||
@@ -52,9 +59,9 @@ namespace TSE
|
||||
std::unordered_map<Vector2, TileMapChunk> chunks;
|
||||
|
||||
void RemoveTile(Vector2 p);
|
||||
void SetTile(Vector2 p, Vector2 Spriteindex);
|
||||
void SetTile(Vector2 p, Vector2 Spriteindex, Vector2 Normalindex = {-1,-1});
|
||||
TileMapChunk* GetChunk(const Vector2& pos);
|
||||
void GetChunkPositionsInOrder(Vector2* arr);
|
||||
const std::vector<Vector2>* GetChunkPositionsInOrder();
|
||||
int GetChunkCount();
|
||||
TileSet* GetTileSet();
|
||||
const Rect& GetBounds() const { return bounds; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Layer.hpp"
|
||||
#include "BehaviourScripts/Renderable.hpp"
|
||||
#include "elements/BehaviourScript.hpp"
|
||||
#include "IdGenerator.hpp"
|
||||
|
||||
void HandleObject(TSE::Transformable* trans, TSE::TransformationStack& stack, TSE::IRenderer& rnd)
|
||||
{
|
||||
@@ -24,6 +25,7 @@ void HandleObject(TSE::Transformable* trans, TSE::TransformationStack& stack, TS
|
||||
|
||||
TSE::Layer::Layer(const string &n)
|
||||
{
|
||||
ID = GenerateRandomUUID();
|
||||
name = n;
|
||||
}
|
||||
|
||||
@@ -94,3 +96,13 @@ void TSE::Layer::Update()
|
||||
trans->Update();
|
||||
}
|
||||
}
|
||||
|
||||
void TSE::Layer::SetNonVisual(bool v)
|
||||
{
|
||||
nonVisual = v;
|
||||
}
|
||||
|
||||
bool TSE::Layer::IsVisual()
|
||||
{
|
||||
return !nonVisual;
|
||||
}
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
#include "Types.hpp"
|
||||
#include "interfaces/IRenderer.hpp"
|
||||
#include <vector>
|
||||
#include "interfaces/IIdentifyable.hpp"
|
||||
|
||||
namespace TSE
|
||||
{
|
||||
class Layer
|
||||
class Layer : public IIdentifyable
|
||||
{
|
||||
private:
|
||||
string name;
|
||||
std::vector<Transformable*> objectsToRender;
|
||||
bool nonVisual = false;
|
||||
|
||||
public:
|
||||
Layer(const string& name);
|
||||
@@ -27,5 +29,7 @@ namespace TSE
|
||||
void SetName(const string& name);
|
||||
std::vector<Transformable*>& GetAllObjects();
|
||||
void Update();
|
||||
void SetNonVisual(bool v);
|
||||
bool IsVisual();
|
||||
};
|
||||
} // namespace TSE
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace TSE
|
||||
}
|
||||
|
||||
template void Material::SetValue<int>(const string&, const int&);
|
||||
template void Material::SetValue<uint>(const string&, const uint&);
|
||||
template void Material::SetValue<float>(const string&, const float&);
|
||||
template void Material::SetValue<Vector2>(const string&, const Vector2&);
|
||||
template void Material::SetValue<Vector3>(const string&, const Vector3&);
|
||||
@@ -70,6 +71,7 @@ namespace TSE
|
||||
template void Material::SetValue<ITexture>(const string&, const ITexture*);
|
||||
|
||||
template int Material::GetValue<int>(const string&) const;
|
||||
template uint Material::GetValue<uint>(const string&) const;
|
||||
template float Material::GetValue<float>(const string&) const;
|
||||
template Vector2 Material::GetValue<Vector2>(const string&) const;
|
||||
template Vector3 Material::GetValue<Vector3>(const string&) const;
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
#include "Scene.hpp"
|
||||
#include "BehaviourScripts/Camera.hpp"
|
||||
#include <algorithm>
|
||||
#include "Debug.hpp"
|
||||
|
||||
void TSE::Scene::Render(IRenderer &rnd, const IWindow &wnd)
|
||||
{
|
||||
auto camerasBackup = std::vector<Camera*>(IRenderer::camerasToRenderWith);
|
||||
int counter = 1;
|
||||
for(auto l : layers)
|
||||
{
|
||||
IRenderer::camerasToRenderWith.clear();
|
||||
if(!l.second->IsVisual()) continue;
|
||||
for(auto camera : camerasBackup)
|
||||
{
|
||||
auto it = std::find(camera->layersNotToRender.begin(), camera->layersNotToRender.end(), l.second->GetID());
|
||||
if(it == camera->layersNotToRender.end())
|
||||
{
|
||||
IRenderer::camerasToRenderWith.push_back(camera);
|
||||
}
|
||||
}
|
||||
|
||||
l.second->Render(rnd);
|
||||
if(counter++ != layers.size())
|
||||
{
|
||||
|
||||
13
TSE_Core/src/interfaces/IIdentifyable.hpp
Normal file
13
TSE_Core/src/interfaces/IIdentifyable.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "uuid.h"
|
||||
|
||||
namespace TSE
|
||||
{
|
||||
class IIdentifyable
|
||||
{
|
||||
protected:
|
||||
uuids::uuid ID;
|
||||
public:
|
||||
inline const uuids::uuid& GetID() { return ID;};
|
||||
};
|
||||
} // namespace TSE
|
||||
35
TSE_Core/src/interfaces/IObservable.hpp
Normal file
35
TSE_Core/src/interfaces/IObservable.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "IObserver.hpp"
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace TSE
|
||||
{
|
||||
class IObservable
|
||||
{
|
||||
private:
|
||||
std::vector<IObserver*> objectsToNotify;
|
||||
|
||||
public:
|
||||
inline void Observe(IObserver* observer)
|
||||
{
|
||||
objectsToNotify.push_back(observer);
|
||||
};
|
||||
inline void StopObserve(IObserver* observer)
|
||||
{
|
||||
auto it = std::find(objectsToNotify.begin(), objectsToNotify.end(), observer);
|
||||
if(it != objectsToNotify.end())
|
||||
objectsToNotify.erase(it);
|
||||
};
|
||||
|
||||
protected:
|
||||
inline void TriggerObserver(void* data)
|
||||
{
|
||||
for (auto &&observer : objectsToNotify)
|
||||
{
|
||||
observer->OnObserved(data);
|
||||
}
|
||||
};
|
||||
};
|
||||
} // namespace TSE
|
||||
10
TSE_Core/src/interfaces/IObserver.hpp
Normal file
10
TSE_Core/src/interfaces/IObserver.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace TSE
|
||||
{
|
||||
class IObserver
|
||||
{
|
||||
public:
|
||||
virtual void OnObserved(void* data) = 0;
|
||||
};
|
||||
} // namespace TSE
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "version.h"
|
||||
#include "IInputManager.hpp"
|
||||
#include "elements/AudioEngine.hpp"
|
||||
#include "IdGenerator.hpp"
|
||||
|
||||
#define FREEIMAGE_LIB
|
||||
#include "FI/FreeImage.h"
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace TSE
|
||||
virtual void Clear() const = 0;
|
||||
virtual void ClearDepthBuffer() const = 0;
|
||||
virtual bool ShouldClose() const = 0;
|
||||
virtual void DoneSetup() = 0;
|
||||
|
||||
bool BaseInit() const;
|
||||
void BaseUpdate() const;
|
||||
|
||||
@@ -40,6 +40,7 @@ TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), editorLayer("")
|
||||
|
||||
editorLayer = Layer(".editor");
|
||||
editorLayer.AddTransformable(editorCamera);
|
||||
editorLayer.SetNonVisual(true);
|
||||
|
||||
#pragma endregion
|
||||
}
|
||||
@@ -439,6 +439,14 @@ namespace TSE::EDITOR
|
||||
Texture* value = element->GetValue<Texture*>(name);
|
||||
Draw(value, debug, name , true);
|
||||
}
|
||||
if (type == typeid(uint).name())
|
||||
{
|
||||
int value = element->GetValue<uint>(name);
|
||||
if(ImGui::InputInt(name.c_str(), &value))
|
||||
{
|
||||
element->SetValue(name, value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextDisabled(("Not Implemented: " + type).c_str());
|
||||
|
||||
@@ -149,3 +149,13 @@ bool TSE::GLFW::WindowGlfw::ShouldClose() const
|
||||
{
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
void TSE::GLFW::WindowGlfw::DoneSetup()
|
||||
{
|
||||
renderingBackend->onResize(width, height);
|
||||
|
||||
for (auto const& i : objectsToResize)
|
||||
{
|
||||
i->OnResize(width, height, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,5 +36,6 @@ namespace TSE::GLFW
|
||||
bool ShouldClose() const override;
|
||||
inline void Bind() override { };
|
||||
inline void Unbind() override { };
|
||||
void DoneSetup() override;
|
||||
};
|
||||
} // namespace TSE::GLFW
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "DefaultRendererOpenGL.hpp"
|
||||
#include "BehaviourScripts/Camera.hpp"
|
||||
#include "BehaviourScripts/Renderable.hpp"
|
||||
#include "Debug.hpp"
|
||||
|
||||
#define RENDERER_MAX_SPRITES 20000
|
||||
#define RENDERER_MAX_INDECIES 60000
|
||||
@@ -77,6 +78,8 @@ void TSE::GLFW::DefaultRendererOpenGL::Flush()
|
||||
|
||||
camerasToRenderWith[i]->PostDraw();
|
||||
}
|
||||
|
||||
lastShader->PostDraw();
|
||||
|
||||
if(ibobound)
|
||||
{
|
||||
|
||||
@@ -96,6 +96,8 @@ void TSE::GLFW::FrameBuffer::LoadFBTexture()
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depthRboID);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
|
||||
|
||||
@@ -39,6 +39,11 @@ void TSE::GLFW::Shader::DrawCall(int indexCount)
|
||||
OnDrawCall(indexCount);
|
||||
}
|
||||
|
||||
void TSE::GLFW::Shader::PostDraw()
|
||||
{
|
||||
OnPostDraw();
|
||||
}
|
||||
|
||||
void TSE::GLFW::Shader::Submit(const Transformable &t, float *&target, TransformationStack &stack, void (*restartDrawcall)(IRenderer &), IRenderer &rnd)
|
||||
{
|
||||
OnSubmit(t, target, stack, restartDrawcall, rnd);
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace TSE::GLFW
|
||||
virtual void OnDisable() const {};
|
||||
virtual void OnFlush() {};
|
||||
virtual void OnDrawCall(int indexCount) {};
|
||||
virtual void OnPostDraw() {};
|
||||
virtual void OnSubmit(const Transformable& t, float*& target, TransformationStack& stack, void (*restartDrawcall)(IRenderer&), IRenderer& rnd) {};
|
||||
|
||||
public:
|
||||
@@ -33,6 +34,7 @@ namespace TSE::GLFW
|
||||
void Disable(bool notify = false) const;
|
||||
void Flush();
|
||||
void DrawCall(int indexCount);
|
||||
void PostDraw();
|
||||
void Submit(const Transformable& t, float*& target, TransformationStack& stack, void (*restartDrawcall)(IRenderer&), IRenderer& rnd);
|
||||
bool IsEnabled() const;
|
||||
int packageSize();
|
||||
|
||||
@@ -171,9 +171,7 @@ void TSE::GLFW::BasicTileMapShader::OnSubmit(const Transformable &t, float *&tar
|
||||
SpriteCount = tileSet->GetCount();
|
||||
SpriteScale = tm->SpriteScale;
|
||||
|
||||
const int chunkcount = tm->GetChunkCount();
|
||||
Vector2 orderedChunks[chunkcount];
|
||||
tm->GetChunkPositionsInOrder(orderedChunks);
|
||||
const std::vector<Vector2> orderedChunks = *tm->GetChunkPositionsInOrder();
|
||||
|
||||
Matrix4x4 matr = t.GetLocalMatrix();
|
||||
|
||||
@@ -183,10 +181,8 @@ void TSE::GLFW::BasicTileMapShader::OnSubmit(const Transformable &t, float *&tar
|
||||
{
|
||||
auto chunk = tm->GetChunk(chunkPos);
|
||||
const int spriteCount = chunk->GetSpriteCount();
|
||||
Vector2 spritePositions[spriteCount];
|
||||
int spriteIds[spriteCount];
|
||||
chunk->GetOrderedPositions(spritePositions);
|
||||
chunk->GetOrderedSpriteIds(spriteIds);
|
||||
const std::vector<Vector2> spritePositions = *chunk->GetOrderedPositions();
|
||||
const std::vector<Vector2i> spriteIds = *chunk->GetOrderedSpriteIds();
|
||||
int chunkSize = chunk->GetChunksize();
|
||||
|
||||
for (int i = 0; i < spriteCount; i++)
|
||||
@@ -198,7 +194,7 @@ void TSE::GLFW::BasicTileMapShader::OnSubmit(const Transformable &t, float *&tar
|
||||
*target++ = pos.x;
|
||||
*target++ = pos.y;
|
||||
*target++ = pos.z;
|
||||
*target++ = spriteIds[i];
|
||||
*target++ = spriteIds[i].x;
|
||||
|
||||
++instanceCount;
|
||||
stack.Pop();
|
||||
|
||||
138
TSE_Math/src/Vector2i.cpp
Normal file
138
TSE_Math/src/Vector2i.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
#include "Vector2i.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "Vector3.hpp"
|
||||
#include "Vector4.hpp"
|
||||
#include <cmath>
|
||||
|
||||
TSE::Vector2i::Vector2i() { }
|
||||
|
||||
TSE::Vector2i::Vector2i(int _x, int _y)
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
}
|
||||
|
||||
TSE::Vector2i::Vector2i(const Vector2i &other)
|
||||
{
|
||||
x = other.x;
|
||||
y = other.y;
|
||||
}
|
||||
|
||||
TSE::Vector2i::Vector2i(const Vector2 &other)
|
||||
{
|
||||
x = other.x;
|
||||
y = other.y;
|
||||
}
|
||||
|
||||
TSE::Vector2i::Vector2i(const Vector3 &other)
|
||||
{
|
||||
x = other.x;
|
||||
y = other.y;
|
||||
}
|
||||
|
||||
TSE::Vector2i::Vector2i(const Vector4 &other)
|
||||
{
|
||||
x = other.x;
|
||||
y = other.y;
|
||||
}
|
||||
|
||||
bool TSE::Vector2i::IsValid() const
|
||||
{
|
||||
return !std::isnan(x) && !std::isnan(y);
|
||||
}
|
||||
|
||||
TSE::string TSE::Vector2i::ToString() const
|
||||
{
|
||||
return "(" + std::to_string(x) + "|" + std::to_string(y) + ")";
|
||||
}
|
||||
|
||||
TSE::Vector2 TSE::Vector2i::ToVector2() const
|
||||
{
|
||||
return Vector2();
|
||||
}
|
||||
|
||||
TSE::Vector3 TSE::Vector2i::ToVector3() const
|
||||
{
|
||||
return Vector3(x,y,0);
|
||||
}
|
||||
|
||||
TSE::Vector4 TSE::Vector2i::ToVector4() const
|
||||
{
|
||||
return Vector4(x,y,0,0);
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator+(const Vector2i &other) const
|
||||
{
|
||||
return Vector2i(x + other.x, y + other.y);
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator+=(const Vector2i &other)
|
||||
{
|
||||
*this = *this + other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator-(const Vector2i &other) const
|
||||
{
|
||||
return Vector2i(x - other.x, y - other.y);
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator-=(const Vector2i &other)
|
||||
{
|
||||
*this = *this - other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator*(const Vector2i &other) const
|
||||
{
|
||||
return Vector2i(x * other.x, y * other.y);
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator*=(const Vector2i &other)
|
||||
{
|
||||
*this = *this * other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator/(const Vector2i &other) const
|
||||
{
|
||||
return Vector2i(x / other.x, y / other.y);
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator/=(const Vector2i &other)
|
||||
{
|
||||
*this = *this / other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator*(const float other) const
|
||||
{
|
||||
return Vector2i(x * other, y * other);
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator*=(const float other)
|
||||
{
|
||||
*this = *this * other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator/(const float other) const
|
||||
{
|
||||
return Vector2i(x / other, y / other);
|
||||
}
|
||||
|
||||
TSE::Vector2i TSE::Vector2i::operator/=(const float other)
|
||||
{
|
||||
*this = *this / other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool TSE::Vector2i::operator==(const Vector2i &other) const
|
||||
{
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
bool TSE::Vector2i::operator!=(const Vector2i &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
85
TSE_Math/src/Vector2i.hpp
Normal file
85
TSE_Math/src/Vector2i.hpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.hpp"
|
||||
#include "MathF.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace TSE
|
||||
{
|
||||
class Vector2;
|
||||
class Vector3;
|
||||
class Vector4;
|
||||
|
||||
class Vector2i
|
||||
{
|
||||
public:
|
||||
#pragma region members
|
||||
int x = 0, y = 0;
|
||||
#pragma endregion members
|
||||
|
||||
#pragma region consts
|
||||
static const Vector2i left;
|
||||
static const Vector2i right;
|
||||
static const Vector2i up;
|
||||
static const Vector2i down;
|
||||
static const Vector2i one;
|
||||
static const Vector2i zero;
|
||||
#pragma endregion
|
||||
|
||||
#pragma region ctor
|
||||
/// @brief enpty constructor defined as (0,0)
|
||||
Vector2i();
|
||||
/// @brief constructs a Vector2i with custom values
|
||||
/// @param _x the x component
|
||||
/// @param _y the y component
|
||||
Vector2i(int _x, int _y);
|
||||
/// @brief copy constructor
|
||||
/// @param other the Vector2i to be copied from
|
||||
Vector2i(const Vector2i& other);
|
||||
/// @brief copy constructor
|
||||
/// @param other the Vector2i to be copied from
|
||||
Vector2i(const Vector2& other);
|
||||
/// @brief converter constructor. it converts a Vector3 to a Vector2i without encointing for the z component
|
||||
/// @param other the Vector3 to convert
|
||||
Vector2i(const Vector3& other);
|
||||
/// @brief converter constructor. it converts a Vector4 to a Vector2i without encointing for the z, and w component
|
||||
/// @param other the Vector4 to convert
|
||||
Vector2i(const Vector4& other);
|
||||
#pragma endregion ctor
|
||||
|
||||
#pragma region methods
|
||||
/// @brief checks if the individual components have valid values aka are not nan
|
||||
/// @return are the values valid
|
||||
bool IsValid() const;
|
||||
/// @brief gives you the Vector2i as a string representation. mostly for debugging
|
||||
/// @return the Vector2i in a format like (x|y)
|
||||
string ToString() const;
|
||||
/// @brief creates a Vector3 with the same values as the Vector2i, the y component gets the value 0
|
||||
/// @return the Vector2i as a Vector3
|
||||
Vector2 ToVector2() const;
|
||||
/// @brief creates a Vector3 with the same values as the Vector2i, the y component gets the value 0
|
||||
/// @return the Vector2i as a Vector3
|
||||
Vector3 ToVector3() const;
|
||||
/// @brief creates a Vector4 with the same values as the Vector2i, the y and w components get the value 0
|
||||
/// @return the Vector2i as a Vector4
|
||||
Vector4 ToVector4() const;
|
||||
|
||||
#pragma region operators
|
||||
Vector2i operator+(const Vector2i& other) const;
|
||||
Vector2i operator+=(const Vector2i& other);
|
||||
Vector2i operator-(const Vector2i& other) const;
|
||||
Vector2i operator-=(const Vector2i& other);
|
||||
Vector2i operator*(const Vector2i& other) const;
|
||||
Vector2i operator*=(const Vector2i& other);
|
||||
Vector2i operator/(const Vector2i& other) const;
|
||||
Vector2i operator/=(const Vector2i& other);
|
||||
Vector2i operator*(const float other) const;
|
||||
Vector2i operator*=(const float other);
|
||||
Vector2i operator/(const float other) const;
|
||||
Vector2i operator/=(const float other);
|
||||
bool operator==(const Vector2i& other) const;
|
||||
bool operator!=(const Vector2i& other) const;
|
||||
#pragma endregion operators
|
||||
#pragma endregion methods
|
||||
};
|
||||
} // namespace TSE
|
||||
Reference in New Issue
Block a user