overloads, tutorial 04 init
This commit is contained in:
@@ -20,7 +20,7 @@ void Renderer2D::init(RendererCore* t_rendererCore) { core = t_rendererCore; }
|
||||
void Renderer2D::render(const Sprite* sprite) { render(*sprite); }
|
||||
|
||||
void Renderer2D::render(const Sprite& sprite) {
|
||||
auto* texture = core->texture.repository.getBySpriteOrMesh(sprite.id);
|
||||
auto* texture = core->texture.repository.getBySpriteId(sprite.id);
|
||||
|
||||
TYRA_ASSERT(
|
||||
texture, "Texture for sprite with id: ", sprite.id,
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
DynamicMesh::DynamicMesh(const MeshBuilderData& data) : Mesh(data) {
|
||||
if (data.materials[0]->frames.size() == 1) {
|
||||
DynamicMesh::DynamicMesh(const MeshBuilderData* data) : Mesh(data) {
|
||||
if (data->materials[0]->frames.size() == 1) {
|
||||
TYRA_WARN(
|
||||
"Frames count should be greater than 1 for DynamicMesh! Maybe you "
|
||||
"should use StaticMesh?");
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < data.materials[0]->frames.size(); i++) {
|
||||
frames.push_back(new MeshFrame(data, i));
|
||||
for (u32 i = 0; i < data->materials[0]->frames.size(); i++) {
|
||||
frames.push_back(new MeshFrame(*data, i));
|
||||
}
|
||||
|
||||
animation.resetAll(frames);
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
Mesh::Mesh(const MeshBuilderData& data) {
|
||||
Mesh::Mesh(const MeshBuilderData* data) {
|
||||
init();
|
||||
|
||||
TYRA_ASSERT(data.materials.size() > 0,
|
||||
TYRA_ASSERT(data->materials.size() > 0,
|
||||
"Materials count must be greater than 0");
|
||||
|
||||
for (u32 i = 0; i < data.materials.size(); i++) {
|
||||
auto* material = new MeshMaterial(data, i);
|
||||
for (u32 i = 0; i < data->materials.size(); i++) {
|
||||
auto* material = new MeshMaterial(*data, i);
|
||||
|
||||
if (material->frames.size() == 0) {
|
||||
TYRA_WARN("Found empty material: ", material->name, ". Skipping...");
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
StaticMesh::StaticMesh(const MeshBuilderData& data) : Mesh(data) {
|
||||
if (data.materials[0]->frames.size() > 1)
|
||||
StaticMesh::StaticMesh(const MeshBuilderData* data) : Mesh(data) {
|
||||
if (data->materials[0]->frames.size() > 1)
|
||||
TYRA_WARN("Static meshes should have only one frame, but ",
|
||||
data.materials[0]->frames.size(), " frames were found");
|
||||
data->materials[0]->frames.size(), " frames were found");
|
||||
|
||||
frame = new MeshFrame(data, 0);
|
||||
frame = new MeshFrame(*data, 0);
|
||||
}
|
||||
|
||||
StaticMesh::StaticMesh(const StaticMesh& mesh) : Mesh(mesh) {
|
||||
|
||||
@@ -106,7 +106,7 @@ void DynamicPipeline::render(const DynamicMesh* mesh,
|
||||
u8 isPartInitialized = false;
|
||||
|
||||
auto* texture =
|
||||
rendererCore->texture.repository.getBySpriteOrMesh(material->id);
|
||||
rendererCore->texture.repository.getByMeshMaterialId(material->id);
|
||||
|
||||
TYRA_ASSERT(
|
||||
texture, "Texture for material: ", material->name, "Id: ", material->id,
|
||||
|
||||
@@ -143,7 +143,7 @@ StaPipTextureBag* StaticPipeline::getTextureBag(
|
||||
auto* result = new StaPipTextureBag();
|
||||
|
||||
result->texture =
|
||||
rendererCore->texture.repository.getBySpriteOrMesh(material->id);
|
||||
rendererCore->texture.repository.getByMeshMaterialId(material->id);
|
||||
|
||||
TYRA_ASSERT(
|
||||
result->texture, "Texture for material: ", material->name,
|
||||
|
||||
@@ -22,7 +22,14 @@ TextureRepository::~TextureRepository() {
|
||||
}
|
||||
}
|
||||
|
||||
Texture* TextureRepository::getBySpriteOrMesh(const u32& t_id) const {
|
||||
Texture* TextureRepository::getBySpriteId(const u32& t_id) const {
|
||||
for (u32 i = 0; i < textures.size(); i++) {
|
||||
if (textures[i]->isLinkedWith(t_id)) return textures[i];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Texture* TextureRepository::getByMeshMaterialId(const u32& t_id) const {
|
||||
for (u32 i = 0; i < textures.size(); i++) {
|
||||
if (textures[i]->isLinkedWith(t_id)) return textures[i];
|
||||
}
|
||||
@@ -56,6 +63,26 @@ void TextureRepository::removeById(const u32& t_texId) {
|
||||
removeByIndex(index);
|
||||
}
|
||||
|
||||
void TextureRepository::freeByMesh(const Mesh& mesh) {
|
||||
for (auto* material : mesh.materials) {
|
||||
auto* texture = getByMeshMaterialId(material->id);
|
||||
|
||||
if (texture != nullptr) {
|
||||
free(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextureRepository::freeByMesh(const Mesh* mesh) { freeByMesh(*mesh); }
|
||||
|
||||
void TextureRepository::freeBySprite(const Sprite& sprite) {
|
||||
auto* texture = getBySpriteId(sprite.id);
|
||||
|
||||
if (texture != nullptr) {
|
||||
free(texture);
|
||||
}
|
||||
}
|
||||
|
||||
void TextureRepository::free(const Texture* t_tex) { free(t_tex->id); }
|
||||
|
||||
void TextureRepository::free(const Texture& t_tex) { free(t_tex.id); }
|
||||
@@ -81,7 +108,7 @@ Texture* TextureRepository::add(const char* fullpath) {
|
||||
return texture;
|
||||
}
|
||||
|
||||
void TextureRepository::addByMesh(Mesh* mesh, const char* directory,
|
||||
void TextureRepository::addByMesh(const Mesh* mesh, const char* directory,
|
||||
const char* extension) {
|
||||
auto& loader = texLoaderSelector.getLoaderByExtension(extension);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user