| @@ -1 +1 @@ | |||||
| Subproject commit e7984246c375a93755c74fe78e4c254a8931533d | |||||
| Subproject commit c1d74196da4b2d9b50d1047dd521a29b81c78e7c | |||||
| @@ -110,7 +110,6 @@ liblol_core_sources = \ | |||||
| image/crop.cpp image/resample.cpp image/noise.cpp image/combine.cpp \ | image/crop.cpp image/resample.cpp image/noise.cpp image/combine.cpp \ | ||||
| image/codec/gdiplus-image.cpp image/codec/imlib2-image.cpp \ | image/codec/gdiplus-image.cpp image/codec/imlib2-image.cpp \ | ||||
| image/codec/sdl-image.cpp image/codec/ios-image.cpp \ | image/codec/sdl-image.cpp image/codec/ios-image.cpp \ | ||||
| image/codec/zed-image.cpp image/codec/zed-palette-image.cpp \ | |||||
| image/codec/oric-image.cpp image/codec/dummy-image.cpp \ | image/codec/oric-image.cpp image/codec/dummy-image.cpp \ | ||||
| image/dither/random.cpp image/dither/ediff.cpp image/dither/dbs.cpp \ | image/dither/random.cpp image/dither/ediff.cpp image/dither/dbs.cpp \ | ||||
| image/dither/ostromoukhov.cpp image/dither/ordered.cpp \ | image/dither/ostromoukhov.cpp image/dither/ordered.cpp \ | ||||
| @@ -193,17 +193,24 @@ void DefaultShaderData::SetupShaderDatas(mat4 const &model) | |||||
| mat4 modelview = view * model; | mat4 modelview = view * model; | ||||
| mat3 normalmat = transpose(inverse(mat3(modelview))); | mat3 normalmat = transpose(inverse(mat3(modelview))); | ||||
| /* FIXME: this should be hidden in the shader */ | /* FIXME: this should be hidden in the shader */ | ||||
| array<Light *> const &lights = scene.GetLights(); | |||||
| array<vec4> light_data; | |||||
| std::vector<Light *> const &lights = scene.GetLights(); | |||||
| std::vector<vec4> light_data; | |||||
| //This is not very nice, but necessary for emscripten WebGL generation. | //This is not very nice, but necessary for emscripten WebGL generation. | ||||
| float f = 0.f; | float f = 0.f; | ||||
| /* FIXME: the 4th component of the position can be used for other things */ | /* FIXME: the 4th component of the position can be used for other things */ | ||||
| /* FIXME: GetUniform("blabla") is costly */ | /* FIXME: GetUniform("blabla") is costly */ | ||||
| for (int i = 0; i < lights.count(); ++i) | |||||
| light_data << vec4(lights[i]->GetPosition(), (float)lights[i]->GetType()) << lights[i]->GetColor(); | |||||
| while (light_data.count() < LOL_MAX_LIGHT_COUNT) | |||||
| light_data << vec4::zero << vec4::zero; | |||||
| for (auto *l : lights) | |||||
| { | |||||
| light_data.push_back(vec4(l->GetPosition(), (float)l->GetType())); | |||||
| light_data.push_back(l->GetColor()); | |||||
| } | |||||
| while (light_data.size() < LOL_MAX_LIGHT_COUNT) | |||||
| { | |||||
| light_data.push_back(vec4::zero); | |||||
| light_data.push_back(vec4::zero); | |||||
| } | |||||
| int i = 0; | int i = 0; | ||||
| m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), light_data); | m_shader->SetUniform(*GetUniform(DefaultUniforms[i++]), light_data); | ||||
| @@ -262,18 +269,18 @@ void GpuEasyMeshData::AddGpuData(std::shared_ptr<GpuShaderData> gpudata, std::sh | |||||
| if (!m_ibo) | if (!m_ibo) | ||||
| { | { | ||||
| array<uint16_t> indexlist; | |||||
| std::vector<uint16_t> indexlist; | |||||
| for (int i = 0; i < src_mesh->m_indices.count(); i += 3) | for (int i = 0; i < src_mesh->m_indices.count(); i += 3) | ||||
| { | { | ||||
| indexlist << src_mesh->m_indices[i + 0]; | |||||
| indexlist << src_mesh->m_indices[i + 1]; | |||||
| indexlist << src_mesh->m_indices[i + 2]; | |||||
| indexlist.push_back(src_mesh->m_indices[i + 0]); | |||||
| indexlist.push_back(src_mesh->m_indices[i + 1]); | |||||
| indexlist.push_back(src_mesh->m_indices[i + 2]); | |||||
| } | } | ||||
| m_ibo = std::make_shared<IndexBuffer>(indexlist.bytes()); | |||||
| m_ibo->set_data(indexlist.data(), indexlist.bytes()); | |||||
| m_ibo = std::make_shared<IndexBuffer>(indexlist.size() * sizeof(indexlist[0])); | |||||
| m_ibo->set_data(indexlist.data(), indexlist.size() * sizeof(indexlist[0])); | |||||
| m_indexcount = indexlist.count(); | |||||
| m_indexcount = indexlist.size(); | |||||
| } | } | ||||
| //init to a minimum of gpudata->m_render_mode size | //init to a minimum of gpudata->m_render_mode size | ||||
| @@ -302,8 +309,8 @@ void GpuEasyMeshData::SetupVertexData(uint16_t vflags, std::shared_ptr<EasyMesh> | |||||
| #define COPY_VBO \ | #define COPY_VBO \ | ||||
| vbo_data = &vertexlist[0]; \ | vbo_data = &vertexlist[0]; \ | ||||
| vbo_bytes = vertexlist.bytes(); \ | |||||
| m_vertexcount = vertexlist.count(); \ | |||||
| vbo_bytes = vertexlist.size() * sizeof(vertexlist[0]); \ | |||||
| m_vertexcount = vertexlist.size(); \ | |||||
| new_vbo = std::make_shared<VertexBuffer>(vbo_bytes); \ | new_vbo = std::make_shared<VertexBuffer>(vbo_bytes); \ | ||||
| new_vbo->set_data(vbo_data, vbo_bytes); | new_vbo->set_data(vbo_data, vbo_bytes); | ||||
| @@ -326,12 +333,13 @@ void GpuEasyMeshData::SetupVertexData(uint16_t vflags, std::shared_ptr<EasyMesh> | |||||
| VertexUsage::Color, | VertexUsage::Color, | ||||
| VertexUsage::TexCoord)); | VertexUsage::TexCoord)); | ||||
| array<vec3, vec3, u8vec4, vec4> vertexlist; | |||||
| std::vector<std::tuple<vec3, vec3, u8vec4, vec4>> vertexlist; | |||||
| for (int i = 0; i < src_mesh->m_vert.count(); i++) | for (int i = 0; i < src_mesh->m_vert.count(); i++) | ||||
| vertexlist.push(src_mesh->m_vert[i].m_coord, | |||||
| src_mesh->m_vert[i].m_normal, | |||||
| (u8vec4)(src_mesh->m_vert[i].m_color * 255.f), | |||||
| src_mesh->m_vert[i].m_texcoord); | |||||
| vertexlist.push_back(std::make_tuple( | |||||
| src_mesh->m_vert[i].m_coord, | |||||
| src_mesh->m_vert[i].m_normal, | |||||
| (u8vec4)(src_mesh->m_vert[i].m_color * 255.f), | |||||
| src_mesh->m_vert[i].m_texcoord)); | |||||
| COPY_VBO; | COPY_VBO; | ||||
| } | } | ||||
| else if (flagnb == 4 && has_position && has_normal && has_color && has_texcoord) | else if (flagnb == 4 && has_position && has_normal && has_color && has_texcoord) | ||||
| @@ -343,21 +351,25 @@ void GpuEasyMeshData::SetupVertexData(uint16_t vflags, std::shared_ptr<EasyMesh> | |||||
| VertexUsage::Color, | VertexUsage::Color, | ||||
| VertexUsage::TexCoord)); | VertexUsage::TexCoord)); | ||||
| array<vec3, vec3, u8vec4, vec2> vertexlist; | |||||
| std::vector<std::tuple<vec3, vec3, u8vec4, vec2>> vertexlist; | |||||
| for (int i = 0; i < src_mesh->m_vert.count(); i++) | for (int i = 0; i < src_mesh->m_vert.count(); i++) | ||||
| vertexlist.push(src_mesh->m_vert[i].m_coord, | |||||
| src_mesh->m_vert[i].m_normal, | |||||
| (u8vec4)(src_mesh->m_vert[i].m_color * 255.f), | |||||
| src_mesh->m_vert[i].m_texcoord.xy); | |||||
| vertexlist.push_back(std::make_tuple( | |||||
| src_mesh->m_vert[i].m_coord, | |||||
| src_mesh->m_vert[i].m_normal, | |||||
| u8vec4(src_mesh->m_vert[i].m_color * 255.f), | |||||
| vec2(src_mesh->m_vert[i].m_texcoord.xy))); | |||||
| COPY_VBO; | COPY_VBO; | ||||
| } | } | ||||
| else if (flagnb == 4 && has_position && has_color && has_texcoord && has_texcoordExt) | else if (flagnb == 4 && has_position && has_color && has_texcoord && has_texcoordExt) | ||||
| { | { | ||||
| new_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec3,vec4,vec4>(VertexUsage::Position, VertexUsage::Color, VertexUsage::TexCoord)); | new_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec3,vec4,vec4>(VertexUsage::Position, VertexUsage::Color, VertexUsage::TexCoord)); | ||||
| array<vec3, vec4, vec4> vertexlist; | |||||
| std::vector<std::tuple<vec3, vec4, vec4>> vertexlist; | |||||
| for (int i = 0; i < src_mesh->m_vert.count(); i++) | for (int i = 0; i < src_mesh->m_vert.count(); i++) | ||||
| vertexlist.push(src_mesh->m_vert[i].m_coord, src_mesh->m_vert[i].m_color, src_mesh->m_vert[i].m_texcoord); | |||||
| vertexlist.push_back(std::make_tuple( | |||||
| src_mesh->m_vert[i].m_coord, | |||||
| src_mesh->m_vert[i].m_color, | |||||
| src_mesh->m_vert[i].m_texcoord)); | |||||
| COPY_VBO; | COPY_VBO; | ||||
| } | } | ||||
| else if (flagnb == 3 && has_position && has_normal && has_color) | else if (flagnb == 3 && has_position && has_normal && has_color) | ||||
| @@ -368,38 +380,45 @@ void GpuEasyMeshData::SetupVertexData(uint16_t vflags, std::shared_ptr<EasyMesh> | |||||
| VertexUsage::Normal, | VertexUsage::Normal, | ||||
| VertexUsage::Color)); | VertexUsage::Color)); | ||||
| array<vec3,vec3,u8vec4> vertexlist; | |||||
| std::vector<std::tuple<vec3,vec3,u8vec4>> vertexlist; | |||||
| for (int i = 0; i < src_mesh->m_vert.count(); i++) | for (int i = 0; i < src_mesh->m_vert.count(); i++) | ||||
| vertexlist.push(src_mesh->m_vert[i].m_coord, | |||||
| src_mesh->m_vert[i].m_normal, | |||||
| (u8vec4)(src_mesh->m_vert[i].m_color * 255.f)); | |||||
| vertexlist.push_back(std::make_tuple( | |||||
| src_mesh->m_vert[i].m_coord, | |||||
| src_mesh->m_vert[i].m_normal, | |||||
| (u8vec4)(src_mesh->m_vert[i].m_color * 255.f))); | |||||
| COPY_VBO; | COPY_VBO; | ||||
| } | } | ||||
| else if (flagnb == 3 && has_position && has_texcoord && has_texcoordExt) | else if (flagnb == 3 && has_position && has_texcoord && has_texcoordExt) | ||||
| { | { | ||||
| new_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec3,vec4>(VertexUsage::Position, VertexUsage::TexCoord)); | new_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec3,vec4>(VertexUsage::Position, VertexUsage::TexCoord)); | ||||
| array<vec3, vec4> vertexlist; | |||||
| std::vector<std::tuple<vec3, vec4>> vertexlist; | |||||
| for (int i = 0; i < src_mesh->m_vert.count(); i++) | for (int i = 0; i < src_mesh->m_vert.count(); i++) | ||||
| vertexlist.push(src_mesh->m_vert[i].m_coord, src_mesh->m_vert[i].m_texcoord); | |||||
| vertexlist.push_back(std::make_tuple( | |||||
| src_mesh->m_vert[i].m_coord, | |||||
| src_mesh->m_vert[i].m_texcoord)); | |||||
| COPY_VBO; | COPY_VBO; | ||||
| } | } | ||||
| else if (flagnb == 2 && has_position && has_texcoord) | else if (flagnb == 2 && has_position && has_texcoord) | ||||
| { | { | ||||
| new_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec3,vec2>(VertexUsage::Position, VertexUsage::TexCoord)); | new_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec3,vec2>(VertexUsage::Position, VertexUsage::TexCoord)); | ||||
| array<vec3, vec2> vertexlist; | |||||
| std::vector<std::tuple<vec3, vec2>> vertexlist; | |||||
| for (int i = 0; i < src_mesh->m_vert.count(); i++) | for (int i = 0; i < src_mesh->m_vert.count(); i++) | ||||
| vertexlist.push(src_mesh->m_vert[i].m_coord, src_mesh->m_vert[i].m_texcoord.xy); | |||||
| vertexlist.push_back(std::make_tuple( | |||||
| src_mesh->m_vert[i].m_coord, | |||||
| vec2(src_mesh->m_vert[i].m_texcoord.xy))); | |||||
| COPY_VBO; | COPY_VBO; | ||||
| } | } | ||||
| else if (flagnb == 2 && has_position && has_color) | else if (flagnb == 2 && has_position && has_color) | ||||
| { | { | ||||
| new_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec3,u8vec4>(VertexUsage::Position, VertexUsage::Color)); | new_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec3,u8vec4>(VertexUsage::Position, VertexUsage::Color)); | ||||
| array<vec3, u8vec4> vertexlist; | |||||
| std::vector<std::tuple<vec3, u8vec4>> vertexlist; | |||||
| for (int i = 0; i < src_mesh->m_vert.count(); i++) | for (int i = 0; i < src_mesh->m_vert.count(); i++) | ||||
| vertexlist.push(src_mesh->m_vert[i].m_coord, (u8vec4)(src_mesh->m_vert[i].m_color * 255.f)); | |||||
| vertexlist.push_back(std::make_tuple( | |||||
| src_mesh->m_vert[i].m_coord, | |||||
| u8vec4(src_mesh->m_vert[i].m_color * 255.f))); | |||||
| COPY_VBO; | COPY_VBO; | ||||
| } | } | ||||
| else | else | ||||
| @@ -132,10 +132,10 @@ private: | |||||
| array<std::shared_ptr<GpuShaderData>> m_gpudata; | array<std::shared_ptr<GpuShaderData>> m_gpudata; | ||||
| //uint16_t are the vdecl/vbo flags to avoid copy same vdecl several times. | //uint16_t are the vdecl/vbo flags to avoid copy same vdecl several times. | ||||
| array<uint16_t, std::shared_ptr<VertexDeclaration>, std::shared_ptr<VertexBuffer>> m_vdata; | array<uint16_t, std::shared_ptr<VertexDeclaration>, std::shared_ptr<VertexBuffer>> m_vdata; | ||||
| int m_vertexcount; | |||||
| size_t m_vertexcount; | |||||
| //We only need only one ibo for the whole mesh | //We only need only one ibo for the whole mesh | ||||
| std::shared_ptr<IndexBuffer> m_ibo; | std::shared_ptr<IndexBuffer> m_ibo; | ||||
| int m_indexcount; | |||||
| size_t m_indexcount; | |||||
| }; | }; | ||||
| } /* namespace lol */ | } /* namespace lol */ | ||||
| @@ -12,6 +12,7 @@ | |||||
| #include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
| #include <unordered_set> // std::unordered_set | |||||
| #include <cstdlib> | #include <cstdlib> | ||||
| #include <functional> | #include <functional> | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| @@ -492,7 +493,7 @@ void ticker_data::collect_garbage() | |||||
| /* Garbage collect objects that can be destroyed. We can do this | /* Garbage collect objects that can be destroyed. We can do this | ||||
| * before inserting awaiting objects, because only objects already | * before inserting awaiting objects, because only objects already | ||||
| * in the tick lists can be marked for destruction. */ | * in the tick lists can be marked for destruction. */ | ||||
| array<entity*> destroy_list; | |||||
| std::unordered_set<entity*> destroy_list; | |||||
| for (int g = 0; g < (int)tickable::group::all::end; ++g) | for (int g = 0; g < (int)tickable::group::all::end; ++g) | ||||
| { | { | ||||
| for (int i = DEPRECATED_m_list[g].count(); i--;) | for (int i = DEPRECATED_m_list[g].count(); i--;) | ||||
| @@ -528,15 +529,14 @@ void ticker_data::collect_garbage() | |||||
| } | } | ||||
| } | } | ||||
| destroy_list.push_unique(e); | |||||
| destroy_list.insert(e); | |||||
| } | } | ||||
| } | } | ||||
| if (!!destroy_list.count()) | |||||
| for (entity* e : destroy_list) | |||||
| { | { | ||||
| DEPRECATED_nentities -= destroy_list.count(); | |||||
| for (entity* e : destroy_list) | |||||
| delete e; | |||||
| delete e; | |||||
| --DEPRECATED_nentities; | |||||
| } | } | ||||
| } | } | ||||
| @@ -465,24 +465,24 @@ void Shader::SetUniform(ShaderUniform const &uni, TextureUniform tex, int index) | |||||
| * Uniform setters for arrays | * Uniform setters for arrays | ||||
| */ | */ | ||||
| void Shader::SetUniform(ShaderUniform const &uni, array<float> const &v) | |||||
| void Shader::SetUniform(ShaderUniform const &uni, std::vector<float> const &v) | |||||
| { | { | ||||
| glUniform1fv((GLint)uni.frag, (GLsizei)v.count(), &v[0]); | |||||
| glUniform1fv((GLint)uni.frag, (GLsizei)v.size(), &v[0]); | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, array<vec2> const &v) | |||||
| void Shader::SetUniform(ShaderUniform const &uni, std::vector<vec2> const &v) | |||||
| { | { | ||||
| glUniform2fv((GLint)uni.frag, (GLsizei)v.count(), &v[0][0]); | |||||
| glUniform2fv((GLint)uni.frag, (GLsizei)v.size(), &v[0][0]); | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, array<vec3> const &v) | |||||
| void Shader::SetUniform(ShaderUniform const &uni, std::vector<vec3> const &v) | |||||
| { | { | ||||
| glUniform3fv((GLint)uni.frag, (GLsizei)v.count(), &v[0][0]); | |||||
| glUniform3fv((GLint)uni.frag, (GLsizei)v.size(), &v[0][0]); | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, array<vec4> const &v) | |||||
| void Shader::SetUniform(ShaderUniform const &uni, std::vector<vec4> const &v) | |||||
| { | { | ||||
| glUniform4fv((GLint)uni.frag, (GLsizei)v.count(), &v[0][0]); | |||||
| glUniform4fv((GLint)uni.frag, (GLsizei)v.size(), &v[0][0]); | |||||
| } | } | ||||
| void Shader::Bind() const | void Shader::Bind() const | ||||
| @@ -892,10 +892,13 @@ ShaderBuilder& ShaderBuilder::operator<<(const ShaderProgram program) | |||||
| } | } | ||||
| //---- | //---- | ||||
| ShaderBuilder& ShaderBuilder::operator<<(ShaderBlock* block) | |||||
| ShaderBuilder& ShaderBuilder::operator<<(ShaderBlock* new_block) | |||||
| { | { | ||||
| ASSERT(m_current_program != ShaderProgram::MAX); | ASSERT(m_current_program != ShaderProgram::MAX); | ||||
| m_blocks[m_current_program.ToScalar()].push_unique(block); | |||||
| for (auto const block : m_blocks[m_current_program.ToScalar()]) | |||||
| if (block == new_block) | |||||
| return *this; | |||||
| m_blocks[m_current_program.ToScalar()].push_back(new_block); | |||||
| return *this; | return *this; | ||||
| } | } | ||||
| @@ -903,7 +906,7 @@ ShaderBuilder& ShaderBuilder::operator<<(ShaderBlock* block) | |||||
| ShaderBuilder& ShaderBuilder::operator<<(ShaderBlock const& block) | ShaderBuilder& ShaderBuilder::operator<<(ShaderBlock const& block) | ||||
| { | { | ||||
| ASSERT(m_current_program != ShaderProgram::MAX); | ASSERT(m_current_program != ShaderProgram::MAX); | ||||
| m_blocks[m_current_program.ToScalar()].push_unique(new ShaderBlock(block)); | |||||
| m_blocks[m_current_program.ToScalar()].push_back(new ShaderBlock(block)); | |||||
| return *this; | return *this; | ||||
| } | } | ||||
| @@ -976,8 +979,8 @@ std::string ShaderBuilder::Build() | |||||
| //Merge all variables | //Merge all variables | ||||
| for (int var = 0; var < ShaderVariable::MAX; var++) | for (int var = 0; var < ShaderVariable::MAX; var++) | ||||
| for (int block = 0; block < m_blocks[prog].count(); block++) | |||||
| MergeParameters(m_blocks[prog][block]->m_parameters[var], m_parameters[prog][var]); | |||||
| for (auto *block : m_blocks[prog]) | |||||
| MergeParameters(block->m_parameters[var], m_parameters[prog][var]); | |||||
| //Actually write code | //Actually write code | ||||
| code += Shader::GetProgramQualifier((ShaderProgram)prog) + "\n"; | code += Shader::GetProgramQualifier((ShaderProgram)prog) + "\n"; | ||||
| @@ -1007,19 +1010,19 @@ std::string ShaderBuilder::Build() | |||||
| code += "\n"; | code += "\n"; | ||||
| //Build Blocks code and add it | //Build Blocks code and add it | ||||
| array<std::string> calls; | |||||
| for (int block = 0; block < m_blocks[prog].count(); block++) | |||||
| std::vector<std::string> calls; | |||||
| for (auto *block : m_blocks[prog]) | |||||
| { | { | ||||
| std::string call; | std::string call; | ||||
| std::string function; | std::string function; | ||||
| m_blocks[prog][block]->Build(ShaderProgram(prog), call, function); | |||||
| calls << call; | |||||
| if (m_blocks[prog][block]->m_code_custom.length()) | |||||
| block->Build(ShaderProgram(prog), call, function); | |||||
| calls.push_back(call); | |||||
| if (block->m_code_custom.length()) | |||||
| { | { | ||||
| code += std::string("//- ") + m_blocks[prog][block]->GetName() + " custom code ----\n"; | |||||
| code += m_blocks[prog][block]->m_code_custom + "\n\n"; | |||||
| code += std::string("//- ") + block->GetName() + " custom code ----\n"; | |||||
| code += block->m_code_custom + "\n\n"; | |||||
| } | } | ||||
| code += std::string("//- ") + m_blocks[prog][block]->GetName() + " main code ----\n"; | |||||
| code += std::string("//- ") + block->GetName() + " main code ----\n"; | |||||
| code += function + "\n\n"; | code += function + "\n\n"; | ||||
| } | } | ||||
| @@ -1,306 +0,0 @@ | |||||
| // | |||||
| // Lol Engine | |||||
| // | |||||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||||
| // © 2009—2014 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||||
| // | |||||
| // Lol Engine is free software. It comes without any warranty, to | |||||
| // the extent permitted by applicable law. You can redistribute it | |||||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||||
| // See http://www.wtfpl.net/ for more details. | |||||
| // | |||||
| #include <lol/engine-internal.h> | |||||
| #include <string> | |||||
| #include "../../image/resource-private.h" | |||||
| namespace lol | |||||
| { | |||||
| /* | |||||
| * Image implementation class | |||||
| */ | |||||
| class ZedImageCodec : public ResourceCodec | |||||
| { | |||||
| public: | |||||
| virtual std::string GetName() { return "<ZedImageCodec>"; } | |||||
| virtual ResourceCodecData* Load(std::string const &path); | |||||
| virtual bool Save(std::string const &path, ResourceCodecData* data); | |||||
| }; | |||||
| DECLARE_IMAGE_CODEC(ZedImageCodec, 10) | |||||
| /* | |||||
| * Public Image class | |||||
| */ | |||||
| ResourceCodecData* ZedImageCodec::Load(std::string const &path) | |||||
| { | |||||
| if (!ends_with(path, ".RSC")) | |||||
| return nullptr; | |||||
| // Compacter definition | |||||
| struct CompactSecondary | |||||
| { | |||||
| CompactSecondary(int32_t size) { m_size = size; } | |||||
| int32_t m_size; | |||||
| array<int32_t> m_tiles; | |||||
| }; | |||||
| struct CompactMain | |||||
| { | |||||
| CompactMain(int32_t size) { m_size = size; m_count = 0; } | |||||
| int32_t m_size; | |||||
| int32_t m_count; | |||||
| array<CompactSecondary> m_secondary; | |||||
| }; | |||||
| struct Compacter2d | |||||
| { | |||||
| void PowSetup(int32_t start, int32_t count) | |||||
| { | |||||
| for (int i = 0; i < count; i++) | |||||
| { | |||||
| m_primary << CompactMain(start << i); | |||||
| for (int j = 0; j < count; j++) | |||||
| m_primary.last().m_secondary << CompactSecondary(start << j); | |||||
| } | |||||
| } | |||||
| void StepSetup(int32_t start, int32_t interval, int32_t count) | |||||
| { | |||||
| for (int i = 0; i < count; i++) | |||||
| { | |||||
| m_primary << CompactMain(start + interval * i); | |||||
| for (int j = 0; j < count; j++) | |||||
| m_primary.last().m_secondary << CompactSecondary(start + interval * j); | |||||
| } | |||||
| } | |||||
| void CustomSetup(array<int32_t> custom_list) | |||||
| { | |||||
| for (int i = 0; i < custom_list.count(); i++) | |||||
| { | |||||
| m_primary << CompactMain(custom_list[i]); | |||||
| for (int j = 0; j < custom_list.count(); j++) | |||||
| m_primary.last().m_secondary << CompactSecondary(custom_list[j]); | |||||
| } | |||||
| } | |||||
| void Store(int32_t tile, ivec2 size) | |||||
| { | |||||
| for (int i = 0; i < m_primary.count(); i++) | |||||
| { | |||||
| if (size.y <= m_primary[i].m_size || i == m_primary.count() - 1) | |||||
| { | |||||
| for (int j = 0; j < m_primary[i].m_secondary.count(); j++) | |||||
| { | |||||
| if (size.x <= m_primary[i].m_secondary[j].m_size || j == m_primary[i].m_secondary.count() - 1) | |||||
| { | |||||
| m_primary[i].m_secondary[j].m_tiles << tile; | |||||
| m_primary[i].m_count++; | |||||
| break; | |||||
| } | |||||
| } | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| array<CompactMain> m_primary; | |||||
| }; | |||||
| File file; | |||||
| file.Open(path, FileAccess::Read, true); | |||||
| //Put file in memory | |||||
| long file_size = file.size(); | |||||
| array<uint8_t> file_buffer; | |||||
| file_buffer.resize(file_size); | |||||
| file.Read((uint8_t*)&file_buffer[0], file_size); | |||||
| file.Close(); | |||||
| //Get FileCount | |||||
| uint32_t file_pos = 0; | |||||
| uint16_t file_count = 0; | |||||
| memcpy(&file_count, &file_buffer[file_pos], sizeof(uint16_t)); | |||||
| file_pos += sizeof(uint16_t); | |||||
| array<uint32_t> file_offset; | |||||
| file_offset.resize(file_count); | |||||
| //Get all the file offsets | |||||
| for (int i = 0; i < file_count; i++) | |||||
| { | |||||
| memcpy(&file_offset[i], &file_buffer[file_pos], sizeof(uint32_t)); | |||||
| file_pos += sizeof(uint32_t); | |||||
| } | |||||
| file_offset << file_size; | |||||
| //<Pos, Size> | |||||
| array<ivec2, ivec2> tiles; | |||||
| tiles.reserve(file_count); | |||||
| Compacter2d compacter; | |||||
| compacter.StepSetup(8, 8, 10); | |||||
| uint32_t total_size = 0; | |||||
| array<uint8_t> file_convert; | |||||
| file_convert.reserve(file_size); | |||||
| array<ivec2> available_sizes; | |||||
| //got through all the files and store them | |||||
| for (int i = 0; i < file_count; i++) | |||||
| { | |||||
| file_pos = file_offset[i]; | |||||
| //Get image size | |||||
| uint8_t size_x = 0; | |||||
| uint8_t size_y = 0; | |||||
| size_y = file_buffer[file_pos++]; | |||||
| size_x = file_buffer[file_pos++]; | |||||
| //special tweak | |||||
| size_x *= 8; | |||||
| total_size += (size_x * size_y); | |||||
| //Prepare read | |||||
| uint32_t header_length = (size_y + 5) & 0xFC; | |||||
| uint32_t data_length = (file_offset[i+1] - file_offset[i]) - header_length; | |||||
| uint32_t data_pos = file_offset[i] + header_length; | |||||
| /* Seems useless in the end | |||||
| //Retrieve Header & footer | |||||
| array<uint8_t> header_data; | |||||
| header_data.resize(header_length); | |||||
| memcpy(&header_data[0], &file_buffer[file_offset[i]], header_length); | |||||
| array<uint8_t> footer_data; | |||||
| uint32_t footer_length = lol::min((uint32_t)file_buffer.count(), data_pos + data_length + header_length) - (data_pos + data_length); | |||||
| if (footer_length > 0) | |||||
| { | |||||
| footer_data.resize(footer_length); | |||||
| memcpy(&footer_data[0], &file_buffer[data_pos + data_length], footer_length); | |||||
| } | |||||
| */ | |||||
| //Prepare buffer and tiles infos | |||||
| int32_t convert_pos = file_convert.count(); | |||||
| ivec2 size = ivec2(size_x, size_y); | |||||
| //store tile in compacter | |||||
| compacter.Store(tiles.count(), ivec2(size_x, size_y)); | |||||
| //push tile on the stack | |||||
| tiles.push(ivec2(file_convert.count(), data_length), ivec2(size_x, size_y)); | |||||
| file_convert.resize(convert_pos + data_length); | |||||
| //Retrieve actual datas | |||||
| file_pos = data_pos; | |||||
| memcpy(&file_convert[convert_pos], &file_buffer[file_pos], data_length); | |||||
| file_pos += data_length; | |||||
| //Store size type | |||||
| { | |||||
| ivec2 size_16 = size; | |||||
| int32_t s_16 = 8; | |||||
| while (1) | |||||
| { | |||||
| if (size_16.x < s_16) | |||||
| { | |||||
| size_16.x = s_16; | |||||
| break; | |||||
| } | |||||
| s_16 <<= 1; | |||||
| } | |||||
| s_16 = 8; | |||||
| while (1) | |||||
| { | |||||
| if (size_16.y < s_16) | |||||
| { | |||||
| size_16.y = s_16; | |||||
| break; | |||||
| } | |||||
| s_16 <<= 1; | |||||
| } | |||||
| int j = 0; | |||||
| for (; j < available_sizes.count(); j++) | |||||
| if (available_sizes[j] == size_16) | |||||
| break; | |||||
| if (j >= available_sizes.count()) | |||||
| available_sizes << size_16; | |||||
| } | |||||
| } | |||||
| int32_t tex_sqrt = (int32_t)lol::sqrt((float)total_size); | |||||
| int32_t tex_size = 2; | |||||
| while (tex_size < tex_sqrt) | |||||
| tex_size <<= 1; | |||||
| //Prepare final image | |||||
| auto data = new ResourceTilesetData(new image(ivec2(tex_size))); | |||||
| auto image = data->m_image; | |||||
| uint8_t *pixels = image->lock<PixelFormat::Y_8>(); | |||||
| //Data refactor stage | |||||
| ivec2 pos = ivec2(0); | |||||
| for (int j = compacter.m_primary.count() - 1; j >= 0; j--) | |||||
| { | |||||
| for (int k = compacter.m_primary[j].m_secondary.count() - 1; k >= 0; k--) | |||||
| { | |||||
| //Try something smaller | |||||
| if (pos.x + compacter.m_primary[j].m_secondary[k].m_size >= tex_size) | |||||
| continue; | |||||
| while (compacter.m_primary[j].m_secondary[k].m_tiles.count() > 0) | |||||
| { | |||||
| //Try something smaller | |||||
| if (pos.x + compacter.m_primary[j].m_secondary[k].m_size >= tex_size) | |||||
| break; | |||||
| compacter.m_primary[j].m_count--; | |||||
| int i = compacter.m_primary[j].m_secondary[k].m_tiles.pop(); | |||||
| int32_t file_off = std::get<0>(tiles[i])[0]; | |||||
| ivec2 t_size = std::get<1>(tiles[i]); | |||||
| ASSERT(pos.y + t_size.y < tex_size); | |||||
| //Move image to texture | |||||
| int32_t img_off = pos.x + pos.y * tex_size; | |||||
| //At this stage image data consists of 4 vertical interlaced blocks | |||||
| for (int pass = 0; pass < 4; pass++) | |||||
| { | |||||
| for (int y_cur = 0; y_cur < t_size.y; y_cur++) | |||||
| { | |||||
| for (int x_cur = 0; x_cur < t_size.x / 4; x_cur++) | |||||
| { | |||||
| int32_t img_pos = img_off + pass + 4 * x_cur + y_cur * (int32_t)tex_size; | |||||
| pixels[img_pos] = file_convert[file_off++]; | |||||
| } | |||||
| } | |||||
| } | |||||
| //Register new pos and move to next | |||||
| std::get<0>(tiles[i]) = pos; | |||||
| pos.x += t_size.x; | |||||
| } | |||||
| } | |||||
| //Do another loop | |||||
| if (compacter.m_primary[j].m_count > 0) | |||||
| { | |||||
| pos.x = 0; | |||||
| pos.y += compacter.m_primary[j].m_size; | |||||
| j++; | |||||
| } | |||||
| } | |||||
| image->unlock(pixels); | |||||
| data->m_tiles = tiles; | |||||
| return data; | |||||
| } | |||||
| bool ZedImageCodec::Save(std::string const &path, ResourceCodecData* data) | |||||
| { | |||||
| UNUSED(path, data); | |||||
| /* FIXME: do we need to implement this? */ | |||||
| return true; | |||||
| } | |||||
| } /* namespace lol */ | |||||
| @@ -1,94 +0,0 @@ | |||||
| // | |||||
| // Lol Engine | |||||
| // | |||||
| // Copyright © 2009—2014 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||||
| // © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
| // | |||||
| // Lol Engine is free software. It comes without any warranty, to | |||||
| // the extent permitted by applicable law. You can redistribute it | |||||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||||
| // See http://www.wtfpl.net/ for more details. | |||||
| // | |||||
| #include <lol/engine-internal.h> | |||||
| #include <string> | |||||
| #include "../../image/resource-private.h" | |||||
| namespace lol | |||||
| { | |||||
| /* | |||||
| * Image implementation class | |||||
| */ | |||||
| class ZedPaletteImageCodec : public ResourceCodec | |||||
| { | |||||
| public: | |||||
| virtual std::string GetName() { return "<ZedPaletteImageCodec>"; } | |||||
| virtual ResourceCodecData* Load(std::string const &path); | |||||
| virtual bool Save(std::string const &path, ResourceCodecData* data); | |||||
| }; | |||||
| DECLARE_IMAGE_CODEC(ZedPaletteImageCodec, 10) | |||||
| /* | |||||
| * Public Image class | |||||
| */ | |||||
| ResourceCodecData* ZedPaletteImageCodec::Load(std::string const &path) | |||||
| { | |||||
| if (!ends_with(path, ".pal")) | |||||
| return nullptr; | |||||
| File file; | |||||
| file.Open(path, FileAccess::Read, true); | |||||
| // Put file in memory | |||||
| long file_size = file.size(); | |||||
| array<uint8_t> file_buffer; | |||||
| file_buffer.resize(file_size); | |||||
| file.Read((uint8_t*)&file_buffer[0], file_size); | |||||
| file.Close(); | |||||
| #if 0 //2D PALETTE | |||||
| int32_t tex_sqrt = (int32_t)lol::sqrt((float)file_size / 3); | |||||
| int32_t tex_size = 2; | |||||
| while (tex_size < tex_sqrt) | |||||
| tex_size <<= 1; | |||||
| auto data = new ResourceImageData(new image(ivec2(tex_size))); | |||||
| auto image = data->m_image; | |||||
| #else | |||||
| int32_t tex_sqrt = file_size / 3; | |||||
| int32_t tex_size = 2; | |||||
| while (tex_size < tex_sqrt) | |||||
| tex_size <<= 1; | |||||
| auto data = new ResourceImageData(new image(ivec2(tex_size, 1))); | |||||
| auto image = data->m_image; | |||||
| #endif | |||||
| u8vec4 *pixels = image->lock<PixelFormat::RGBA_8>(); | |||||
| for (int i = 0; i < file_buffer.count();) | |||||
| { | |||||
| pixels->r = file_buffer[i++]; | |||||
| pixels->g = file_buffer[i++]; | |||||
| pixels->b = file_buffer[i++]; | |||||
| pixels->a = (i == 0) ? 0 : 255; | |||||
| ++pixels; | |||||
| } | |||||
| image->unlock(pixels); | |||||
| return data; | |||||
| } | |||||
| bool ZedPaletteImageCodec::Save(std::string const &path, ResourceCodecData* data) | |||||
| { | |||||
| UNUSED(path, data); | |||||
| /* FIXME: do we need to implement this? */ | |||||
| return true; | |||||
| } | |||||
| } /* namespace lol */ | |||||
| @@ -47,8 +47,6 @@ static bool RegisterAllCodecs(array<ResourceCodec *> &codeclist) | |||||
| #if defined LOL_USE_IMLIB2 | #if defined LOL_USE_IMLIB2 | ||||
| REGISTER_IMAGE_CODEC(Imlib2ImageCodec) | REGISTER_IMAGE_CODEC(Imlib2ImageCodec) | ||||
| #endif | #endif | ||||
| REGISTER_IMAGE_CODEC(ZedImageCodec) | |||||
| REGISTER_IMAGE_CODEC(ZedPaletteImageCodec) | |||||
| REGISTER_IMAGE_CODEC(OricImageCodec) | REGISTER_IMAGE_CODEC(OricImageCodec) | ||||
| REGISTER_IMAGE_CODEC(DummyImageCodec) | REGISTER_IMAGE_CODEC(DummyImageCodec) | ||||
| @@ -148,8 +148,6 @@ | |||||
| </ClCompile> | </ClCompile> | ||||
| <ClCompile Include="image\codec\oric-image.cpp" /> | <ClCompile Include="image\codec\oric-image.cpp" /> | ||||
| <ClCompile Include="image\codec\sdl-image.cpp" /> | <ClCompile Include="image\codec\sdl-image.cpp" /> | ||||
| <ClCompile Include="image\codec\zed-image.cpp" /> | |||||
| <ClCompile Include="image\codec\zed-palette-image.cpp" /> | |||||
| <ClCompile Include="image\filter\colors.cpp" /> | <ClCompile Include="image\filter\colors.cpp" /> | ||||
| <ClCompile Include="image\filter\convolution.cpp" /> | <ClCompile Include="image\filter\convolution.cpp" /> | ||||
| <ClCompile Include="image\filter\dilate.cpp" /> | <ClCompile Include="image\filter\dilate.cpp" /> | ||||
| @@ -122,12 +122,6 @@ | |||||
| <ClCompile Include="image\codec\sdl-image.cpp"> | <ClCompile Include="image\codec\sdl-image.cpp"> | ||||
| <Filter>image\codec</Filter> | <Filter>image\codec</Filter> | ||||
| </ClCompile> | </ClCompile> | ||||
| <ClCompile Include="image\codec\zed-image.cpp"> | |||||
| <Filter>image\codec</Filter> | |||||
| </ClCompile> | |||||
| <ClCompile Include="image\codec\zed-palette-image.cpp"> | |||||
| <Filter>image\codec</Filter> | |||||
| </ClCompile> | |||||
| <ClCompile Include="image\filter\colors.cpp"> | <ClCompile Include="image\filter\colors.cpp"> | ||||
| <Filter>image\filter</Filter> | <Filter>image\filter</Filter> | ||||
| </ClCompile> | </ClCompile> | ||||
| @@ -223,15 +223,6 @@ public: | |||||
| *this << x; | *this << x; | ||||
| } | } | ||||
| inline bool push_unique(T const &x) | |||||
| { | |||||
| if (find(x) != INDEX_NONE) | |||||
| return false; | |||||
| push(x); | |||||
| return true; | |||||
| } | |||||
| inline void insert(T const &x, ptrdiff_t pos) | inline void insert(T const &x, ptrdiff_t pos) | ||||
| { | { | ||||
| assert(pos >= 0 && pos <= m_count); | assert(pos >= 0 && pos <= m_count); | ||||
| @@ -19,6 +19,7 @@ | |||||
| #include <string> // std::string | #include <string> // std::string | ||||
| #include <map> // std::map | #include <map> // std::map | ||||
| #include <vector> // std::vector | |||||
| #include <memory> // std::shared_ptr | #include <memory> // std::shared_ptr | ||||
| #include <stdint.h> // int64_t | #include <stdint.h> // int64_t | ||||
| @@ -337,10 +338,10 @@ public: | |||||
| void SetUniform(ShaderUniform const &uni, mat4 const &m); | void SetUniform(ShaderUniform const &uni, mat4 const &m); | ||||
| void SetUniform(ShaderUniform const &uni, TextureUniform tex, int index); | void SetUniform(ShaderUniform const &uni, TextureUniform tex, int index); | ||||
| void SetUniform(ShaderUniform const &uni, array<float> const &v); | |||||
| void SetUniform(ShaderUniform const &uni, array<vec2> const &v); | |||||
| void SetUniform(ShaderUniform const &uni, array<vec3> const &v); | |||||
| void SetUniform(ShaderUniform const &uni, array<vec4> const &v); | |||||
| void SetUniform(ShaderUniform const &uni, std::vector<float> const &v); | |||||
| void SetUniform(ShaderUniform const &uni, std::vector<vec2> const &v); | |||||
| void SetUniform(ShaderUniform const &uni, std::vector<vec3> const &v); | |||||
| void SetUniform(ShaderUniform const &uni, std::vector<vec4> const &v); | |||||
| void Bind() const; | void Bind() const; | ||||
| void Unbind() const; | void Unbind() const; | ||||
| @@ -444,7 +445,7 @@ protected: | |||||
| ShaderProgram m_current_program = ShaderProgram::MAX; | ShaderProgram m_current_program = ShaderProgram::MAX; | ||||
| //Blocks | //Blocks | ||||
| array<ShaderBlock*> m_blocks[ShaderProgram::MAX]; | |||||
| std::vector<ShaderBlock*> m_blocks[ShaderProgram::MAX]; | |||||
| //Final shader parameters | //Final shader parameters | ||||
| std::map<std::string, std::string> m_parameters[ShaderProgram::MAX][ShaderVariable::MAX]; | std::map<std::string, std::string> m_parameters[ShaderProgram::MAX][ShaderVariable::MAX]; | ||||
| @@ -18,12 +18,14 @@ | |||||
| // —————————————————— | // —————————————————— | ||||
| // | // | ||||
| #include <../legacy/lol/math/arraynd.h> | |||||
| #include <lol/math/vector.h> | #include <lol/math/vector.h> | ||||
| #include <../legacy/lol/math/geometry.h> | #include <../legacy/lol/math/geometry.h> | ||||
| #include <lol/image/image.h> | #include <lol/image/image.h> | ||||
| #include <../legacy/lol/image/pixel.h> | #include <../legacy/lol/image/pixel.h> | ||||
| #include <vector> // std::vector | |||||
| #include <string> // std::string | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| //ResourceCodecData ----------------------------------------------------------- | //ResourceCodecData ----------------------------------------------------------- | ||||
| @@ -60,7 +62,7 @@ namespace lol | |||||
| : ResourceImageData(img) | : ResourceImageData(img) | ||||
| { } | { } | ||||
| array<ivec2, ivec2> m_tiles; | |||||
| std::vector<ibox2> m_tiles; | |||||
| }; | }; | ||||
| //ResourceLoader -------------------------------------------------------------- | //ResourceLoader -------------------------------------------------------------- | ||||
| @@ -18,6 +18,7 @@ | |||||
| // | // | ||||
| #include <string> // std::string | #include <string> // std::string | ||||
| #include <vector> // std::vector | |||||
| #include <map> // std::map | #include <map> // std::map | ||||
| #include <stdint.h> // int64_t | #include <stdint.h> // int64_t | ||||
| @@ -105,11 +106,11 @@ public: | |||||
| void Close(); | void Close(); | ||||
| private: | private: | ||||
| bool GetContent(array<std::string>* files, array<Directory>* directories); | |||||
| bool GetContent(std::vector<std::string>* files, std::vector<Directory>* directories); | |||||
| public: | public: | ||||
| bool GetContent(array<std::string>& files, array<Directory>& directories); | |||||
| bool GetContent(array<Directory>& directories); | |||||
| bool GetContent(array<std::string>& files); | |||||
| bool GetContent(std::vector<std::string>& files, std::vector<Directory>& directories); | |||||
| bool GetContent(std::vector<Directory>& directories); | |||||
| bool GetContent(std::vector<std::string>& files); | |||||
| std::string GetName(); | std::string GetName(); | ||||
| long int GetModificationTime(); | long int GetModificationTime(); | ||||
| @@ -18,7 +18,7 @@ | |||||
| // | // | ||||
| #include <string> // std::string | #include <string> // std::string | ||||
| #include <cstdlib> // std::getenv | |||||
| #include <vector> // std::vector | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -54,7 +54,7 @@ extern void init(int argc, char *argv[], | |||||
| std::string const &sourcesubdir = LOL_CONFIG_SOURCESUBDIR); | std::string const &sourcesubdir = LOL_CONFIG_SOURCESUBDIR); | ||||
| extern void add_data_dir(std::string const &dir); | extern void add_data_dir(std::string const &dir); | ||||
| extern array<std::string> get_path_list(std::string const &file); | |||||
| extern std::vector<std::string> get_path_list(std::string const &file); | |||||
| } /* namespace sys */ | } /* namespace sys */ | ||||
| @@ -71,15 +71,21 @@ void PrimitiveMesh::Render(Scene& scene, std::shared_ptr<PrimitiveSource> primit | |||||
| u_normalmat = shader->GetUniformLocation("u_normalmat"); | u_normalmat = shader->GetUniformLocation("u_normalmat"); | ||||
| /* Per-scene environment */ | /* Per-scene environment */ | ||||
| array<Light *> const &lights = scene.GetLights(); | |||||
| array<vec4> light_data; | |||||
| std::vector<Light *> const &lights = scene.GetLights(); | |||||
| std::vector<vec4> light_data; | |||||
| /* FIXME: the 4th component of the position can be used for other things */ | /* FIXME: the 4th component of the position can be used for other things */ | ||||
| /* FIXME: GetUniform("blabla") is costly */ | /* FIXME: GetUniform("blabla") is costly */ | ||||
| for (auto l : lights) | for (auto l : lights) | ||||
| light_data << vec4(l->GetPosition(), (float)l->GetType()) << l->GetColor(); | |||||
| while (light_data.count() < LOL_MAX_LIGHT_COUNT) | |||||
| light_data << vec4::zero << vec4::zero; | |||||
| { | |||||
| light_data.push_back(vec4(l->GetPosition(), (float)l->GetType())); | |||||
| light_data.push_back(l->GetColor()); | |||||
| } | |||||
| while (light_data.size() < LOL_MAX_LIGHT_COUNT) | |||||
| { | |||||
| light_data.push_back(vec4::zero); | |||||
| light_data.push_back(vec4::zero); | |||||
| } | |||||
| ShaderUniform u_lights = shader->GetUniformLocation("u_lights"); | ShaderUniform u_lights = shader->GetUniformLocation("u_lights"); | ||||
| shader->SetUniform(u_lights, light_data); | shader->SetUniform(u_lights, light_data); | ||||
| @@ -38,9 +38,9 @@ namespace lol | |||||
| * The global g_scenes object, initialised by Video::Init | * The global g_scenes object, initialised by Video::Init | ||||
| */ | */ | ||||
| array<Scene*> Scene::g_scenes; | |||||
| std::vector<Scene*> Scene::g_scenes; | |||||
| static array<SceneDisplay*> g_scene_displays; | |||||
| static std::vector<SceneDisplay*> g_scene_displays; | |||||
| static inline void gpu_marker(char const *message) | static inline void gpu_marker(char const *message) | ||||
| { | { | ||||
| @@ -58,18 +58,16 @@ static inline void gpu_marker(char const *message) | |||||
| void SceneDisplay::Add(SceneDisplay* display) | void SceneDisplay::Add(SceneDisplay* display) | ||||
| { | { | ||||
| g_scene_displays << display; | |||||
| g_scene_displays.push_back(display); | |||||
| } | } | ||||
| int SceneDisplay::GetCount() | |||||
| size_t SceneDisplay::GetCount() | |||||
| { | { | ||||
| return g_scene_displays.count(); | |||||
| return g_scene_displays.size(); | |||||
| } | } | ||||
| SceneDisplay* SceneDisplay::GetDisplay(int index) | SceneDisplay* SceneDisplay::GetDisplay(int index) | ||||
| { | { | ||||
| ASSERT(0 <= index && index < g_scene_displays.count(), | |||||
| "invalid display index %d", index); | |||||
| return g_scene_displays[index]; | return g_scene_displays[index]; | ||||
| } | } | ||||
| @@ -108,7 +106,7 @@ void PrimitiveRenderer::Render(Scene& scene, std::shared_ptr<PrimitiveSource> pr | |||||
| uint64_t Scene::g_used_id = 1; | uint64_t Scene::g_used_id = 1; | ||||
| mutex Scene::g_prim_mutex; | mutex Scene::g_prim_mutex; | ||||
| std::map<uintptr_t, array<std::shared_ptr<PrimitiveSource>>> Scene::g_prim_sources; | |||||
| std::map<uintptr_t, std::vector<std::shared_ptr<PrimitiveSource>>> Scene::g_prim_sources; | |||||
| /* | /* | ||||
| * Public Scene class | * Public Scene class | ||||
| @@ -135,11 +133,11 @@ Scene::Scene(ivec2 size) | |||||
| m_pp.m_buffer_uni[1][1] = m_pp.pp_shader->GetUniformLocation("u_prev_buffer"); | m_pp.m_buffer_uni[1][1] = m_pp.pp_shader->GetUniformLocation("u_prev_buffer"); | ||||
| m_pp.m_buffer_uni[1][2] = m_pp.pp_shader->GetUniformLocation("u_prev_final"); | m_pp.m_buffer_uni[1][2] = m_pp.pp_shader->GetUniformLocation("u_prev_final"); | ||||
| array<vec2> quad { vec2( 1.0, 1.0), vec2(-1.0, -1.0), vec2( 1.0, -1.0), | |||||
| vec2(-1.0, -1.0), vec2( 1.0, 1.0), vec2(-1.0, 1.0), }; | |||||
| std::vector<vec2> quad { vec2( 1.0, 1.0), vec2(-1.0, -1.0), vec2( 1.0, -1.0), | |||||
| vec2(-1.0, -1.0), vec2( 1.0, 1.0), vec2(-1.0, 1.0), }; | |||||
| m_pp.quad_vbo = std::make_shared<VertexBuffer>(quad.bytes()); | |||||
| m_pp.quad_vbo->set_data(quad.data(), quad.bytes()); | |||||
| m_pp.quad_vbo = std::make_shared<VertexBuffer>(quad.size() * sizeof(vec2)); | |||||
| m_pp.quad_vbo->set_data(quad.data(), quad.size() * sizeof(vec2)); | |||||
| /* Create a default orthographic camera, in case the user doesn’t. */ | /* Create a default orthographic camera, in case the user doesn’t. */ | ||||
| m_default_cam = new Camera(); | m_default_cam = new Camera(); | ||||
| @@ -177,35 +175,36 @@ Scene::~Scene() | |||||
| void Scene::AddNew(ivec2 size) | void Scene::AddNew(ivec2 size) | ||||
| { | { | ||||
| Scene::g_scenes << new Scene(size); | |||||
| Scene::g_scenes.push_back(new Scene(size)); | |||||
| } | } | ||||
| void Scene::DestroyScene(Scene* scene) | void Scene::DestroyScene(Scene* scene) | ||||
| { | { | ||||
| Scene::g_scenes.remove_item(scene); | |||||
| remove_item(Scene::g_scenes, scene); | |||||
| delete scene; | delete scene; | ||||
| } | } | ||||
| void Scene::DestroyAll() | void Scene::DestroyAll() | ||||
| { | { | ||||
| while (Scene::g_scenes.count()) | |||||
| delete Scene::g_scenes.pop(); | |||||
| while (Scene::g_scenes.size()) | |||||
| { | |||||
| delete Scene::g_scenes.back(); | |||||
| Scene::g_scenes.pop_back(); | |||||
| } | |||||
| } | } | ||||
| int Scene::GetCount() | |||||
| size_t Scene::GetCount() | |||||
| { | { | ||||
| return g_scenes.count(); | |||||
| return g_scenes.size(); | |||||
| } | } | ||||
| bool Scene::IsReady(int index) | bool Scene::IsReady(int index) | ||||
| { | { | ||||
| return 0 <= index && index < g_scenes.count() && !!g_scenes[index]; | |||||
| return 0 <= index && index < int(g_scenes.size()) && !!g_scenes[index]; | |||||
| } | } | ||||
| Scene& Scene::GetScene(int index) | Scene& Scene::GetScene(int index) | ||||
| { | { | ||||
| ASSERT(0 <= index && index < g_scenes.count() && !!g_scenes[index], | |||||
| "Trying to get a non-existent scene %d", index); | |||||
| return *g_scenes[index]; | return *g_scenes[index]; | ||||
| } | } | ||||
| @@ -221,28 +220,28 @@ bool Scene::IsRelevant(entity* entity) | |||||
| Camera* Scene::GetCamera(int cam_idx) | Camera* Scene::GetCamera(int cam_idx) | ||||
| { | { | ||||
| return (0 <= cam_idx && cam_idx < m_camera_stack.count()) ? | |||||
| return (0 <= cam_idx && cam_idx < int(m_camera_stack.size())) ? | |||||
| m_camera_stack[cam_idx] : | m_camera_stack[cam_idx] : | ||||
| m_camera_stack.last(); | |||||
| m_camera_stack.back(); | |||||
| } | } | ||||
| int Scene::PushCamera(Camera *cam) | int Scene::PushCamera(Camera *cam) | ||||
| { | { | ||||
| Ticker::Ref(cam); | Ticker::Ref(cam); | ||||
| m_camera_stack.push(cam); | |||||
| return (int)m_camera_stack.count() - 1; | |||||
| m_camera_stack.push_back(cam); | |||||
| return int(m_camera_stack.size()) - 1; | |||||
| } | } | ||||
| void Scene::PopCamera(Camera *cam) | void Scene::PopCamera(Camera *cam) | ||||
| { | { | ||||
| /* Parse from the end because that’s probably where we’ll find | /* Parse from the end because that’s probably where we’ll find | ||||
| * our camera first. */ | * our camera first. */ | ||||
| for (int i = m_camera_stack.count(); i--;) | |||||
| for (size_t i = m_camera_stack.size(); i--;) | |||||
| { | { | ||||
| if (m_camera_stack[i] == cam) | if (m_camera_stack[i] == cam) | ||||
| { | { | ||||
| Ticker::Unref(cam); | Ticker::Unref(cam); | ||||
| m_camera_stack.remove(i); | |||||
| remove_at(m_camera_stack, i); | |||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| @@ -260,7 +259,7 @@ void Scene::Reset() | |||||
| /* New scenegraph: Release fire&forget primitives */ | /* New scenegraph: Release fire&forget primitives */ | ||||
| for (uintptr_t key : keys(m_prim_renderers)) | for (uintptr_t key : keys(m_prim_renderers)) | ||||
| { | { | ||||
| for (int idx = 0; idx < m_prim_renderers[key].count(); ++idx) | |||||
| for (size_t idx = 0; idx < m_prim_renderers[key].size(); ++idx) | |||||
| if (m_prim_renderers[key][idx]->m_fire_and_forget) | if (m_prim_renderers[key][idx]->m_fire_and_forget) | ||||
| ReleasePrimitiveRenderer(idx--, key); | ReleasePrimitiveRenderer(idx--, key); | ||||
| } | } | ||||
| @@ -278,7 +277,7 @@ int Scene::HasPrimitiveSource(uintptr_t key) | |||||
| int count; | int count; | ||||
| g_prim_mutex.lock(); | g_prim_mutex.lock(); | ||||
| { | { | ||||
| count = g_prim_sources[key].count(); | |||||
| count = int(g_prim_sources[key].size()); | |||||
| } | } | ||||
| g_prim_mutex.unlock(); | g_prim_mutex.unlock(); | ||||
| return count; | return count; | ||||
| @@ -289,8 +288,8 @@ int Scene::AddPrimitiveSource(uintptr_t key, std::shared_ptr<PrimitiveSource> so | |||||
| int count; | int count; | ||||
| g_prim_mutex.lock(); | g_prim_mutex.lock(); | ||||
| { | { | ||||
| count = g_prim_sources[key].count(); | |||||
| g_prim_sources[key].push(source); | |||||
| count = int(g_prim_sources[key].size()); | |||||
| g_prim_sources[key].push_back(source); | |||||
| } | } | ||||
| g_prim_mutex.unlock(); | g_prim_mutex.unlock(); | ||||
| return count; | return count; | ||||
| @@ -306,7 +305,7 @@ void Scene::SetPrimitiveSource(int index, uintptr_t key, std::shared_ptr<Primiti | |||||
| g_prim_mutex.lock(); | g_prim_mutex.lock(); | ||||
| { | { | ||||
| if (index < g_prim_sources[key].count()) | |||||
| if (index < int(g_prim_sources[key].size())) | |||||
| old = g_prim_sources[key][index]; | old = g_prim_sources[key][index]; | ||||
| else | else | ||||
| g_prim_sources[key].resize(index + 1); | g_prim_sources[key].resize(index + 1); | ||||
| @@ -320,9 +319,9 @@ void Scene::ReleasePrimitiveSource(int index, uintptr_t key) | |||||
| std::shared_ptr<PrimitiveSource> old; | std::shared_ptr<PrimitiveSource> old; | ||||
| g_prim_mutex.lock(); | g_prim_mutex.lock(); | ||||
| { | { | ||||
| ASSERT(0 <= index && index < g_prim_sources[key].count()); | |||||
| ASSERT(0 <= index && index < int(g_prim_sources[key].size())); | |||||
| old = g_prim_sources[key][index]; | old = g_prim_sources[key][index]; | ||||
| g_prim_sources[key].remove(index); | |||||
| remove_at(g_prim_sources[key], index); | |||||
| } | } | ||||
| g_prim_mutex.unlock(); | g_prim_mutex.unlock(); | ||||
| } | } | ||||
| @@ -330,13 +329,13 @@ void Scene::ReleasePrimitiveSource(int index, uintptr_t key) | |||||
| void Scene::ReleaseAllPrimitiveSources(uintptr_t key) | void Scene::ReleaseAllPrimitiveSources(uintptr_t key) | ||||
| { | { | ||||
| // Delete oldies AFTER having released the lock | // Delete oldies AFTER having released the lock | ||||
| array<std::shared_ptr<PrimitiveSource>> oldies; | |||||
| std::vector<std::shared_ptr<PrimitiveSource>> oldies; | |||||
| g_prim_mutex.lock(); | g_prim_mutex.lock(); | ||||
| { | { | ||||
| oldies.reserve(g_prim_sources[key].count()); | |||||
| oldies.reserve(g_prim_sources[key].size()); | |||||
| for (auto source : g_prim_sources[key]) | for (auto source : g_prim_sources[key]) | ||||
| oldies << source; | |||||
| oldies.push_back(source); | |||||
| g_prim_sources[key].clear(); | g_prim_sources[key].clear(); | ||||
| } | } | ||||
| g_prim_mutex.unlock(); | g_prim_mutex.unlock(); | ||||
| @@ -348,13 +347,13 @@ void Scene::ReleaseAllPrimitiveSources(uintptr_t key) | |||||
| int Scene::HasPrimitiveRenderer(uintptr_t key) | int Scene::HasPrimitiveRenderer(uintptr_t key) | ||||
| { | { | ||||
| return m_prim_renderers[key].count(); | |||||
| return int(m_prim_renderers[key].size()); | |||||
| } | } | ||||
| void Scene::AddPrimitiveRenderer(uintptr_t key, std::shared_ptr<PrimitiveRenderer> renderer) | void Scene::AddPrimitiveRenderer(uintptr_t key, std::shared_ptr<PrimitiveRenderer> renderer) | ||||
| { | { | ||||
| renderer->m_fire_and_forget = true; | renderer->m_fire_and_forget = true; | ||||
| m_prim_renderers[key].push(renderer); | |||||
| m_prim_renderers[key].push_back(renderer); | |||||
| } | } | ||||
| void Scene::SetPrimitiveRenderer(int index, uintptr_t key, std::shared_ptr<PrimitiveRenderer> renderer) | void Scene::SetPrimitiveRenderer(int index, uintptr_t key, std::shared_ptr<PrimitiveRenderer> renderer) | ||||
| @@ -362,16 +361,14 @@ void Scene::SetPrimitiveRenderer(int index, uintptr_t key, std::shared_ptr<Primi | |||||
| ASSERT(renderer); | ASSERT(renderer); | ||||
| ASSERT(index >= 0); | ASSERT(index >= 0); | ||||
| if (index >= m_prim_renderers[key].count()) | |||||
| if (index >= int(m_prim_renderers[key].size())) | |||||
| m_prim_renderers[key].resize(index + 1); | m_prim_renderers[key].resize(index + 1); | ||||
| m_prim_renderers[key][index] = renderer; | m_prim_renderers[key][index] = renderer; | ||||
| } | } | ||||
| void Scene::ReleasePrimitiveRenderer(int index, uintptr_t key) | void Scene::ReleasePrimitiveRenderer(int index, uintptr_t key) | ||||
| { | { | ||||
| ASSERT(0 <= index && index < m_prim_renderers[key].count()); | |||||
| m_prim_renderers[key].remove(index); | |||||
| remove_at(m_prim_renderers[key], index); | |||||
| } | } | ||||
| void Scene::ReleaseAllPrimitiveRenderers(uintptr_t key) | void Scene::ReleaseAllPrimitiveRenderers(uintptr_t key) | ||||
| @@ -403,29 +400,29 @@ void Scene::AddTile(TileSet *tileset, int id, mat4 model) | |||||
| t.m_id = id; | t.m_id = id; | ||||
| if (tileset->GetPalette()) | if (tileset->GetPalette()) | ||||
| m_tile_api.m_palettes.push(t); | |||||
| m_tile_api.m_palettes.push_back(t); | |||||
| else | else | ||||
| m_tile_api.m_tiles.push(t); | |||||
| m_tile_api.m_tiles.push_back(t); | |||||
| } | } | ||||
| void Scene::AddLine(vec3 a, vec3 b, vec4 col) | void Scene::AddLine(vec3 a, vec3 b, vec4 col) | ||||
| { | { | ||||
| struct line l { a, b, col, -1.f, 0xFFFFFFFF, false, false }; | struct line l { a, b, col, -1.f, 0xFFFFFFFF, false, false }; | ||||
| m_line_api.m_lines.push(l); | |||||
| m_line_api.m_lines.push_back(l); | |||||
| } | } | ||||
| void Scene::AddLine(vec3 a, vec3 b, vec4 col, float duration, uint32_t mask) | void Scene::AddLine(vec3 a, vec3 b, vec4 col, float duration, uint32_t mask) | ||||
| { | { | ||||
| struct line l { a, b, col, duration, mask, false, false }; | struct line l { a, b, col, duration, mask, false, false }; | ||||
| m_line_api.m_lines.push(l); | |||||
| m_line_api.m_lines.push_back(l); | |||||
| } | } | ||||
| void Scene::AddLight(Light *l) | void Scene::AddLight(Light *l) | ||||
| { | { | ||||
| m_tile_api.m_lights.push(l); | |||||
| m_tile_api.m_lights.push_back(l); | |||||
| } | } | ||||
| array<Light *> const &Scene::GetLights() | |||||
| std::vector<Light *> const &Scene::GetLights() | |||||
| { | { | ||||
| return m_tile_api.m_lights; | return m_tile_api.m_lights; | ||||
| } | } | ||||
| @@ -570,11 +567,11 @@ void Scene::render_primitives() | |||||
| /* new scenegraph */ | /* new scenegraph */ | ||||
| for (uintptr_t key : keys(m_prim_renderers)) | for (uintptr_t key : keys(m_prim_renderers)) | ||||
| { | { | ||||
| for (int idx = 0; idx < m_prim_renderers[key].count(); ++idx) | |||||
| for (size_t idx = 0; idx < m_prim_renderers[key].size(); ++idx) | |||||
| { | { | ||||
| /* TODO: Not sure if thread compliant */ | /* TODO: Not sure if thread compliant */ | ||||
| std::shared_ptr<PrimitiveSource> source; | std::shared_ptr<PrimitiveSource> source; | ||||
| if (idx < g_prim_sources[key].count()) | |||||
| if (idx < g_prim_sources[key].size()) | |||||
| source = g_prim_sources[key][idx]; | source = g_prim_sources[key][idx]; | ||||
| m_prim_renderers[key][idx]->Render(*this, source); | m_prim_renderers[key][idx]->Render(*this, source); | ||||
| } | } | ||||
| @@ -586,7 +583,7 @@ void Scene::render_tiles() // XXX: rename to Blit() | |||||
| render_context rc(m_renderer); | render_context rc(m_renderer); | ||||
| /* Early test if nothing needs to be rendered */ | /* Early test if nothing needs to be rendered */ | ||||
| if (!m_tile_api.m_tiles.count() && !m_tile_api.m_palettes.count()) | |||||
| if (m_tile_api.m_tiles.empty() && m_tile_api.m_palettes.empty()) | |||||
| return; | return; | ||||
| /* FIXME: we disable culling for now because we don’t have a reliable | /* FIXME: we disable culling for now because we don’t have a reliable | ||||
| @@ -600,7 +597,7 @@ void Scene::render_tiles() // XXX: rename to Blit() | |||||
| if (!m_tile_api.m_shader) | if (!m_tile_api.m_shader) | ||||
| m_tile_api.m_shader = Shader::Create(LOLFX_RESOURCE_NAME(gpu_tile)); | m_tile_api.m_shader = Shader::Create(LOLFX_RESOURCE_NAME(gpu_tile)); | ||||
| if (!m_tile_api.m_palette_shader && m_tile_api.m_palettes.count()) | |||||
| if (!m_tile_api.m_palette_shader && !m_tile_api.m_palettes.empty()) | |||||
| m_tile_api.m_palette_shader = Shader::Create(LOLFX_RESOURCE_NAME(gpu_palette)); | m_tile_api.m_palette_shader = Shader::Create(LOLFX_RESOURCE_NAME(gpu_palette)); | ||||
| for (int p = 0; p < 2; p++) | for (int p = 0; p < 2; p++) | ||||
| @@ -608,7 +605,7 @@ void Scene::render_tiles() // XXX: rename to Blit() | |||||
| auto shader = (p == 0) ? m_tile_api.m_shader : m_tile_api.m_palette_shader; | auto shader = (p == 0) ? m_tile_api.m_shader : m_tile_api.m_palette_shader; | ||||
| auto &tiles = (p == 0) ? m_tile_api.m_tiles : m_tile_api.m_palettes; | auto &tiles = (p == 0) ? m_tile_api.m_tiles : m_tile_api.m_palettes; | ||||
| if (tiles.count() == 0) | |||||
| if (tiles.empty()) | |||||
| continue; | continue; | ||||
| ShaderUniform uni_mat, uni_tex, uni_pal, uni_texsize; | ShaderUniform uni_mat, uni_tex, uni_pal, uni_texsize; | ||||
| @@ -629,10 +626,10 @@ void Scene::render_tiles() // XXX: rename to Blit() | |||||
| uni_pal = m_tile_api.m_palette_shader ? m_tile_api.m_palette_shader->GetUniformLocation("u_palette") : ShaderUniform(); | uni_pal = m_tile_api.m_palette_shader ? m_tile_api.m_palette_shader->GetUniformLocation("u_palette") : ShaderUniform(); | ||||
| uni_texsize = shader->GetUniformLocation("u_texsize"); | uni_texsize = shader->GetUniformLocation("u_texsize"); | ||||
| for (int buf = 0, i = 0, n; i < tiles.count(); i = n, buf += 2) | |||||
| for (size_t buf = 0, i = 0, n; i < tiles.size(); i = n, buf += 2) | |||||
| { | { | ||||
| /* Count how many quads will be needed */ | /* Count how many quads will be needed */ | ||||
| for (n = i + 1; n < tiles.count(); n++) | |||||
| for (n = i + 1; n < tiles.size(); n++) | |||||
| if (tiles[i].m_tileset != tiles[n].m_tileset) | if (tiles[i].m_tileset != tiles[n].m_tileset) | ||||
| break; | break; | ||||
| @@ -642,10 +639,10 @@ void Scene::render_tiles() // XXX: rename to Blit() | |||||
| auto vb2 = std::make_shared<VertexBuffer>(6 * (n - i) * sizeof(vec2)); | auto vb2 = std::make_shared<VertexBuffer>(6 * (n - i) * sizeof(vec2)); | ||||
| vec2 *texture = (vec2 *)vb2->lock(0, 0); | vec2 *texture = (vec2 *)vb2->lock(0, 0); | ||||
| m_tile_api.m_bufs.push(vb1); | |||||
| m_tile_api.m_bufs.push(vb2); | |||||
| m_tile_api.m_bufs.push_back(vb1); | |||||
| m_tile_api.m_bufs.push_back(vb2); | |||||
| for (int j = i; j < n; j++) | |||||
| for (size_t j = i; j < n; j++) | |||||
| { | { | ||||
| tiles[i].m_tileset->BlitTile(tiles[j].m_id, tiles[j].m_model, | tiles[i].m_tileset->BlitTile(tiles[j].m_id, tiles[j].m_model, | ||||
| vertex + 6 * (j - i), texture + 6 * (j - i)); | vertex + 6 * (j - i), texture + 6 * (j - i)); | ||||
| @@ -698,7 +695,7 @@ void Scene::render_lines(float seconds) | |||||
| { | { | ||||
| render_context rc(m_renderer); | render_context rc(m_renderer); | ||||
| if (!m_line_api.m_lines.count()) | |||||
| if (m_line_api.m_lines.empty()) | |||||
| return; | return; | ||||
| rc.depth_func(DepthFunc::LessOrEqual); | rc.depth_func(DepthFunc::LessOrEqual); | ||||
| @@ -706,17 +703,17 @@ void Scene::render_lines(float seconds) | |||||
| rc.blend_equation(BlendEquation::Add, BlendEquation::Max); | rc.blend_equation(BlendEquation::Add, BlendEquation::Max); | ||||
| rc.alpha_func(AlphaFunc::GreaterOrEqual, 0.01f); | rc.alpha_func(AlphaFunc::GreaterOrEqual, 0.01f); | ||||
| int linecount = (int)m_line_api.m_lines.count(); | |||||
| size_t linecount = m_line_api.m_lines.size(); | |||||
| if (!m_line_api.m_shader) | if (!m_line_api.m_shader) | ||||
| m_line_api.m_shader = Shader::Create(LOLFX_RESOURCE_NAME(gpu_line)); | m_line_api.m_shader = Shader::Create(LOLFX_RESOURCE_NAME(gpu_line)); | ||||
| array<vec4, vec4, vec4, vec4> buff; | |||||
| std::vector<std::tuple<vec4, vec4, vec4, vec4>> buff; | |||||
| buff.resize(linecount); | buff.resize(linecount); | ||||
| int real_linecount = 0; | int real_linecount = 0; | ||||
| mat4 const inv_view_proj = inverse(GetCamera()->GetProjection() * GetCamera()->GetView()); | mat4 const inv_view_proj = inverse(GetCamera()->GetProjection() * GetCamera()->GetView()); | ||||
| UNUSED(inv_view_proj); | UNUSED(inv_view_proj); | ||||
| for (int i = 0; i < linecount; i++) | |||||
| for (size_t i = 0; i < linecount; i++) | |||||
| { | { | ||||
| if (m_line_api.m_lines[i].mask & m_line_api.m_debug_mask) | if (m_line_api.m_lines[i].mask & m_line_api.m_debug_mask) | ||||
| { | { | ||||
| @@ -729,12 +726,12 @@ void Scene::render_lines(float seconds) | |||||
| m_line_api.m_lines[i].duration -= seconds; | m_line_api.m_lines[i].duration -= seconds; | ||||
| if (m_line_api.m_lines[i].duration < 0.f) | if (m_line_api.m_lines[i].duration < 0.f) | ||||
| { | { | ||||
| m_line_api.m_lines.remove_swap(i--); | |||||
| remove_at(m_line_api.m_lines, i--); | |||||
| linecount--; | linecount--; | ||||
| } | } | ||||
| } | } | ||||
| auto vb = std::make_shared<VertexBuffer>(buff.bytes()); | |||||
| vb->set_data(buff.data(), buff.bytes()); | |||||
| auto vb = std::make_shared<VertexBuffer>(buff.size() * sizeof(buff[0])); | |||||
| vb->set_data(buff.data(), buff.size() * sizeof(buff[0])); | |||||
| m_line_api.m_shader->Bind(); | m_line_api.m_shader->Bind(); | ||||
| @@ -18,9 +18,6 @@ | |||||
| // --------------- | // --------------- | ||||
| // | // | ||||
| #include <memory> | |||||
| #include <stdint.h> | |||||
| #include "light.h" | #include "light.h" | ||||
| #include "camera.h" | #include "camera.h" | ||||
| #include "mesh/mesh.h" | #include "mesh/mesh.h" | ||||
| @@ -29,6 +26,10 @@ | |||||
| #include <lol/gpu/framebuffer.h> | #include <lol/gpu/framebuffer.h> | ||||
| #include <lol/base/thread.h> | #include <lol/base/thread.h> | ||||
| #include <vector> // std::vector | |||||
| #include <memory> // std::shared_ptr | |||||
| #include <stdint.h> // uintptr_t | |||||
| #define LOL_MAX_LIGHT_COUNT 8 | #define LOL_MAX_LIGHT_COUNT 8 | ||||
| namespace lol | namespace lol | ||||
| @@ -87,7 +88,7 @@ public: | |||||
| /* TODO: Should that be there or in Video ? */ | /* TODO: Should that be there or in Video ? */ | ||||
| static void Add(SceneDisplay* display); | static void Add(SceneDisplay* display); | ||||
| static int GetCount(); | |||||
| static size_t GetCount(); | |||||
| static SceneDisplay* GetDisplay(int index = 0); | static SceneDisplay* GetDisplay(int index = 0); | ||||
| static void DestroyAll(); | static void DestroyAll(); | ||||
| @@ -105,7 +106,7 @@ class Scene | |||||
| friend class Video; | friend class Video; | ||||
| private: | private: | ||||
| static array<Scene*> g_scenes; | |||||
| static std::vector<Scene*> g_scenes; | |||||
| Scene(ivec2 size); | Scene(ivec2 size); | ||||
| ~Scene(); | ~Scene(); | ||||
| @@ -117,7 +118,7 @@ private: //Private because I don't know if we should have it | |||||
| private: | private: | ||||
| static void DestroyAll(); | static void DestroyAll(); | ||||
| public: | public: | ||||
| static int GetCount(); | |||||
| static size_t GetCount(); | |||||
| static bool IsReady(int index = 0); | static bool IsReady(int index = 0); | ||||
| static Scene& GetScene(int index = 0); | static Scene& GetScene(int index = 0); | ||||
| @@ -248,7 +249,7 @@ public: | |||||
| void AddLine(vec3 a, vec3 b, vec4 color, float duration, uint32_t mask); | void AddLine(vec3 a, vec3 b, vec4 color, float duration, uint32_t mask); | ||||
| void AddLight(Light *light); | void AddLight(Light *light); | ||||
| array<Light *> const &GetLights(); | |||||
| std::vector<Light *> const &GetLights(); | |||||
| /* === Render stuff === */ | /* === Render stuff === */ | ||||
| void SetDisplay(SceneDisplay* display); | void SetDisplay(SceneDisplay* display); | ||||
| @@ -303,12 +304,12 @@ private: | |||||
| * - Updated by entity | * - Updated by entity | ||||
| * - Marked Fire&Forget | * - Marked Fire&Forget | ||||
| * - Scene is destroyed */ | * - Scene is destroyed */ | ||||
| std::map<uintptr_t, array<std::shared_ptr<PrimitiveRenderer>>> m_prim_renderers; | |||||
| static std::map<uintptr_t, array<std::shared_ptr<PrimitiveSource>>> g_prim_sources; | |||||
| std::map<uintptr_t, std::vector<std::shared_ptr<PrimitiveRenderer>>> m_prim_renderers; | |||||
| static std::map<uintptr_t, std::vector<std::shared_ptr<PrimitiveSource>>> g_prim_sources; | |||||
| static mutex g_prim_mutex; | static mutex g_prim_mutex; | ||||
| Camera *m_default_cam; | Camera *m_default_cam; | ||||
| array<Camera *> m_camera_stack; | |||||
| std::vector<Camera *> m_camera_stack; | |||||
| struct line | struct line | ||||
| { | { | ||||
| @@ -324,7 +325,7 @@ private: | |||||
| { | { | ||||
| //float m_duration, m_segment_size; | //float m_duration, m_segment_size; | ||||
| //vec4 m_color; | //vec4 m_color; | ||||
| array<line> m_lines; | |||||
| std::vector<line> m_lines; | |||||
| int /*m_mask,*/ m_debug_mask; | int /*m_mask,*/ m_debug_mask; | ||||
| std::shared_ptr<Shader> m_shader; | std::shared_ptr<Shader> m_shader; | ||||
| std::shared_ptr<VertexDeclaration> m_vdecl; | std::shared_ptr<VertexDeclaration> m_vdecl; | ||||
| @@ -335,15 +336,15 @@ private: | |||||
| struct tile_api | struct tile_api | ||||
| { | { | ||||
| int m_cam; | int m_cam; | ||||
| array<Tile> m_tiles; | |||||
| array<Tile> m_palettes; | |||||
| array<Light *> m_lights; | |||||
| std::vector<Tile> m_tiles; | |||||
| std::vector<Tile> m_palettes; | |||||
| std::vector<Light *> m_lights; | |||||
| std::shared_ptr<Shader> m_shader; | std::shared_ptr<Shader> m_shader; | ||||
| std::shared_ptr<Shader> m_palette_shader; | std::shared_ptr<Shader> m_palette_shader; | ||||
| std::shared_ptr<VertexDeclaration> m_vdecl; | std::shared_ptr<VertexDeclaration> m_vdecl; | ||||
| array<std::shared_ptr<VertexBuffer>> m_bufs; | |||||
| std::vector<std::shared_ptr<VertexBuffer>> m_bufs; | |||||
| } | } | ||||
| m_tile_api; | m_tile_api; | ||||
| }; | }; | ||||
| @@ -125,12 +125,12 @@ class FileData | |||||
| std::string ReadString() | std::string ReadString() | ||||
| { | { | ||||
| array<uint8_t> buf; | |||||
| std::vector<uint8_t> buf; | |||||
| buf.resize(BUFSIZ); | buf.resize(BUFSIZ); | ||||
| std::string ret; | std::string ret; | ||||
| while (IsValid()) | while (IsValid()) | ||||
| { | { | ||||
| int done = Read(&buf[0], buf.count()); | |||||
| int done = Read(&buf[0], buf.size()); | |||||
| if (done <= 0) | if (done <= 0) | ||||
| break; | break; | ||||
| @@ -139,7 +139,7 @@ class FileData | |||||
| ret.resize(oldsize + done); | ret.resize(oldsize + done); | ||||
| memcpy(&ret[oldsize], &buf[0], done); | memcpy(&ret[oldsize], &buf[0], done); | ||||
| buf.resize(buf.count() * 3 / 2); | |||||
| buf.resize(buf.size() * 3 / 2); | |||||
| } | } | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -393,7 +393,8 @@ class DirectoryData | |||||
| #endif | #endif | ||||
| } | } | ||||
| bool GetContentList(array<std::string>* files, array<std::string>* directories) | |||||
| bool GetContentList(std::vector<std::string>* files, | |||||
| std::vector<std::string>* directories) | |||||
| { | { | ||||
| if (!IsValid()) | if (!IsValid()) | ||||
| return false; | return false; | ||||
| @@ -415,12 +416,12 @@ class DirectoryData | |||||
| if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) | if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) | ||||
| { | { | ||||
| if (directories) | if (directories) | ||||
| *directories << std::string(find_data.cFileName); | |||||
| directories->push_back(std::string(find_data.cFileName)); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| if (files) | if (files) | ||||
| *files << std::string(find_data.cFileName); | |||||
| files->push_back(std::string(find_data.cFileName)); | |||||
| } | } | ||||
| } | } | ||||
| //Go for next one | //Go for next one | ||||
| @@ -429,7 +430,7 @@ class DirectoryData | |||||
| #elif HAVE_STDIO_H | #elif HAVE_STDIO_H | ||||
| /* FIXME: not implemented */ | /* FIXME: not implemented */ | ||||
| #endif | #endif | ||||
| return ((files && files->count()) || (directories && directories->count())); | |||||
| return ((files && !files->empty()) || (directories && !directories->empty())); | |||||
| } | } | ||||
| inline bool IsValid() const | inline bool IsValid() const | ||||
| @@ -536,37 +537,39 @@ void Directory::Close() | |||||
| } | } | ||||
| //-- | //-- | ||||
| bool Directory::GetContent(array<std::string>* files, array<Directory>* directories) | |||||
| bool Directory::GetContent(std::vector<std::string>* files, | |||||
| std::vector<Directory>* directories) | |||||
| { | { | ||||
| array<std::string> sfiles, sdirectories; | |||||
| std::vector<std::string> sfiles, sdirectories; | |||||
| bool found_some = m_data->GetContentList(&sfiles, &sdirectories); | bool found_some = m_data->GetContentList(&sfiles, &sdirectories); | ||||
| UNUSED(found_some); | UNUSED(found_some); | ||||
| if (directories) | if (directories) | ||||
| for (int i = 0; i < sdirectories.count(); i++) | |||||
| directories->push(Directory(m_name + sdirectories[i])); | |||||
| for (auto const &sdir : sdirectories) | |||||
| directories->push_back(Directory(m_name + sdir)); | |||||
| if (files) | if (files) | ||||
| for (int i = 0; i < sfiles.count(); i++) | |||||
| files->push(m_name + sfiles[i]); | |||||
| for (auto const &sfile : sfiles) | |||||
| files->push_back(m_name + sfile); | |||||
| return (files && files->count()) || (directories || directories->count()); | |||||
| return (files && !files->empty()) || (directories && !directories->size()); | |||||
| } | } | ||||
| //-- | //-- | ||||
| bool Directory::GetContent(array<std::string>& files, array<Directory>& directories) | |||||
| bool Directory::GetContent(std::vector<std::string>& files, | |||||
| std::vector<Directory>& directories) | |||||
| { | { | ||||
| return GetContent(&files, &directories); | return GetContent(&files, &directories); | ||||
| } | } | ||||
| //-- | //-- | ||||
| bool Directory::GetContent(array<Directory>& directories) | |||||
| bool Directory::GetContent(std::vector<Directory>& directories) | |||||
| { | { | ||||
| return GetContent(nullptr, &directories); | return GetContent(nullptr, &directories); | ||||
| } | } | ||||
| //-- | //-- | ||||
| bool Directory::GetContent(array<std::string>& files) | |||||
| bool Directory::GetContent(std::vector<std::string>& files) | |||||
| { | { | ||||
| return GetContent(&files, nullptr); | return GetContent(&files, nullptr); | ||||
| } | } | ||||
| @@ -12,6 +12,8 @@ | |||||
| #include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
| #include <vector> // std::vector | |||||
| #include <string> // std::string | |||||
| #include <cctype> | #include <cctype> | ||||
| #if HAVE_UNISTD_H | #if HAVE_UNISTD_H | ||||
| @@ -36,7 +38,7 @@ namespace sys | |||||
| # define SEPARATOR '/' | # define SEPARATOR '/' | ||||
| #endif | #endif | ||||
| static array<std::string> data_dir; | |||||
| static std::vector<std::string> data_dir; | |||||
| void init(int argc, char *argv[], | void init(int argc, char *argv[], | ||||
| std::string const &projectdir, | std::string const &projectdir, | ||||
| @@ -151,8 +153,8 @@ void init(int argc, char *argv[], | |||||
| } | } | ||||
| msg::debug("binary dir: “%s”\n", binarydir.c_str()); | msg::debug("binary dir: “%s”\n", binarydir.c_str()); | ||||
| for (int i = 0; i < data_dir.count(); ++i) | |||||
| msg::debug("data dir %d/%d: “%s”\n", i + 1, data_dir.count(), | |||||
| for (int i = 0; i < int(data_dir.size()); ++i) | |||||
| msg::debug("data dir %d/%d: “%s”\n", i + 1, int(data_dir.size()), | |||||
| data_dir[i].c_str()); | data_dir[i].c_str()); | ||||
| } | } | ||||
| @@ -162,22 +164,20 @@ void init(int argc, char *argv[], | |||||
| void add_data_dir(std::string const &dir) | void add_data_dir(std::string const &dir) | ||||
| { | { | ||||
| data_dir << dir; | |||||
| data_dir.push_back(dir); | |||||
| } | } | ||||
| array<std::string> get_path_list(std::string const &file) | |||||
| std::vector<std::string> get_path_list(std::string const &file) | |||||
| { | { | ||||
| array<std::string> ret; | |||||
| std::vector<std::string> ret; | |||||
| /* If not an absolute path, look through known data directories */ | /* If not an absolute path, look through known data directories */ | ||||
| if (file[0] != '/') | if (file[0] != '/') | ||||
| { | |||||
| for (int i = 0; i < data_dir.count(); ++i) | |||||
| ret << data_dir[i] + file; | |||||
| } | |||||
| for (auto const &dir : data_dir) | |||||
| ret.push_back(dir + file); | |||||
| #if !__NX__ | #if !__NX__ | ||||
| ret << file; | |||||
| ret.push_back(file); | |||||
| #endif | #endif | ||||
| return ret; | return ret; | ||||
| @@ -41,7 +41,7 @@ class TileSetData | |||||
| protected: | protected: | ||||
| /* Pixels, then texture coordinates */ | /* Pixels, then texture coordinates */ | ||||
| array<ibox2, box2> m_tiles; | |||||
| std::vector<std::tuple<ibox2, box2>> m_tiles; | |||||
| ivec2 m_tile_size; | ivec2 m_tile_size; | ||||
| }; | }; | ||||
| @@ -61,13 +61,13 @@ TileSet *TileSet::create(std::string const &path, image* img) | |||||
| return ret ? ret : tileset_cache.set(path, new TileSet(path, img)); | return ret ? ret : tileset_cache.set(path, new TileSet(path, img)); | ||||
| } | } | ||||
| TileSet *TileSet::create(std::string const &path, image* img, array<ivec2, ivec2>& tiles) | |||||
| TileSet *TileSet::create(std::string const &path, image* img, std::vector<ibox2>& tiles) | |||||
| { | { | ||||
| auto ret = tileset_cache.get(path); | auto ret = tileset_cache.get(path); | ||||
| if (!ret) | if (!ret) | ||||
| { | { | ||||
| ret = tileset_cache.set(path, new TileSet(path, img)); | ret = tileset_cache.set(path, new TileSet(path, img)); | ||||
| ret->define_tile(tiles); | |||||
| ret->define_tiles_by_box(tiles); | |||||
| } | } | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -163,7 +163,7 @@ void TileSet::Init(std::string const &path, ResourceCodecData* loaded_data) | |||||
| auto tileset_data = dynamic_cast<ResourceTilesetData*>(loaded_data); | auto tileset_data = dynamic_cast<ResourceTilesetData*>(loaded_data); | ||||
| if (tileset_data != nullptr) | if (tileset_data != nullptr) | ||||
| { | { | ||||
| define_tile(tileset_data->m_tiles); | |||||
| define_tiles_by_box(tileset_data->m_tiles); | |||||
| } | } | ||||
| m_data->m_name = "<tileset> " + path; | m_data->m_name = "<tileset> " + path; | ||||
| @@ -192,10 +192,10 @@ void TileSet::clear_all() | |||||
| int TileSet::define_tile(ibox2 rect) | int TileSet::define_tile(ibox2 rect) | ||||
| { | { | ||||
| m_tileset_data->m_tiles.push(rect, | |||||
| m_tileset_data->m_tiles.push_back(std::make_tuple(rect, | |||||
| box2((vec2)rect.aa / (vec2)m_data->m_texture_size, | box2((vec2)rect.aa / (vec2)m_data->m_texture_size, | ||||
| (vec2)rect.bb / (vec2)m_data->m_texture_size)); | |||||
| return m_tileset_data->m_tiles.count() - 1; | |||||
| (vec2)rect.bb / (vec2)m_data->m_texture_size))); | |||||
| return int(m_tileset_data->m_tiles.size()) - 1; | |||||
| } | } | ||||
| void TileSet::define_tile(ivec2 count) | void TileSet::define_tile(ivec2 count) | ||||
| @@ -210,25 +210,15 @@ void TileSet::define_tile(ivec2 count) | |||||
| } | } | ||||
| } | } | ||||
| void TileSet::define_tile(array<ibox2>& tiles) | |||||
| void TileSet::define_tiles_by_box(std::vector<ibox2>& tiles) | |||||
| { | { | ||||
| for (int i = 0; i < tiles.count(); i++) | |||||
| define_tile(tiles[i]); | |||||
| } | |||||
| void TileSet::define_tile(array<ivec2, ivec2>& tiles) | |||||
| { | |||||
| for (int i = 0; i < tiles.count(); i++) | |||||
| { | |||||
| auto const &a = std::get<0>(tiles[i]); | |||||
| auto const &b = std::get<1>(tiles[i]); | |||||
| define_tile(ibox2(a, a + b)); | |||||
| } | |||||
| for (auto const &t : tiles) | |||||
| define_tile(t); | |||||
| } | } | ||||
| int TileSet::GetTileCount() const | int TileSet::GetTileCount() const | ||||
| { | { | ||||
| return m_tileset_data->m_tiles.count(); | |||||
| return int(m_tileset_data->m_tiles.size()); | |||||
| } | } | ||||
| ivec2 TileSet::GetTileSize(int tileid) const | ivec2 TileSet::GetTileSize(int tileid) const | ||||
| @@ -30,6 +30,8 @@ | |||||
| */ | */ | ||||
| #include "textureimage.h" | #include "textureimage.h" | ||||
| #include <vector> // std::vector | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -43,7 +45,7 @@ class TileSet : public TextureImage | |||||
| public: | public: | ||||
| static TileSet *create(std::string const &path); | static TileSet *create(std::string const &path); | ||||
| static TileSet *create(std::string const &path, image* img); | static TileSet *create(std::string const &path, image* img); | ||||
| static TileSet *create(std::string const &path, image* img, array<ivec2, ivec2>& tiles); | |||||
| static TileSet *create(std::string const &path, image* img, std::vector<ibox2>& tiles); | |||||
| /* Old style: path to PNG file */ | /* Old style: path to PNG file */ | ||||
| static TileSet *create(std::string const &path, ivec2 size, ivec2 count); | static TileSet *create(std::string const &path, ivec2 size, ivec2 count); | ||||
| @@ -69,8 +71,7 @@ public: | |||||
| void clear_all(); | void clear_all(); | ||||
| int define_tile(ibox2 rect); | int define_tile(ibox2 rect); | ||||
| void define_tile(ivec2 count); | void define_tile(ivec2 count); | ||||
| void define_tile(array<ibox2>& tiles); | |||||
| void define_tile(array<ivec2, ivec2>& tiles); | |||||
| void define_tiles_by_box(std::vector<ibox2>& tiles); | |||||
| int GetTileCount() const; | int GetTileCount() const; | ||||
| ivec2 GetTileSize(int tileid) const; | ivec2 GetTileSize(int tileid) const; | ||||
| ibox2 GetTilePixel(int tileid) const; | ibox2 GetTilePixel(int tileid) const; | ||||