This is the first step to getting rid of lol::array in favour of std::vector.legacy
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine — BtPhys tutorial | |||
| // | |||
| // Copyright © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2012—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -258,7 +258,7 @@ void BtPhysTest::InitApp() | |||
| vec3(2.f , 1.f , 2.f) + | |||
| #endif //CAT_MODE | |||
| vec3(8.f * (float)x, 8.f * (float)y, 8.f * (float)z)); | |||
| m_physobj_list.push(new_physobj, ZERO_TIME); | |||
| m_physobj_list.push(animated_object { new_physobj, ZERO_TIME }); | |||
| Ticker::Ref(new_physobj); | |||
| } | |||
| } | |||
| @@ -322,7 +322,7 @@ BtPhysTest::~BtPhysTest() | |||
| + m_platform_list; | |||
| while (m_physobj_list.count()) | |||
| { | |||
| objects << m_physobj_list.last().m1; | |||
| objects << m_physobj_list.last().obj; | |||
| m_physobj_list.pop(); | |||
| } | |||
| m_ground_list.clear(); | |||
| @@ -367,7 +367,7 @@ BtPhysTest::~BtPhysTest() | |||
| //} | |||
| //while (m_physobj_list.count()) | |||
| //{ | |||
| // PhysicsObject* CurPop = m_physobj_list.last().m1; | |||
| // PhysicsObject* CurPop = m_physobj_list.last().obj; | |||
| // m_physobj_list.pop(); | |||
| // CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); | |||
| // Ticker::Unref(CurPop); | |||
| @@ -426,8 +426,8 @@ void BtPhysTest::tick_game(float seconds) | |||
| for (int i = 0; i < m_physobj_list.count(); i++) | |||
| { | |||
| PhysicsObject* PhysObj = m_physobj_list[i].m1; | |||
| float &obj_timer = m_physobj_list[i].m2; | |||
| PhysicsObject* PhysObj = m_physobj_list[i].obj; | |||
| float &obj_timer = m_physobj_list[i].anim; | |||
| vec3 obj_loc = PhysObj->GetPhysic()->GetTransform()[3].xyz; | |||
| @@ -629,7 +629,7 @@ void BtPhysTest::tick_game(float seconds) | |||
| PhysObjBarycenter = vec3(.0f); | |||
| for (int i = 0; i < m_physobj_list.count(); i++) | |||
| { | |||
| PhysicsObject* PhysObj = m_physobj_list[i].m1; | |||
| PhysicsObject* PhysObj = m_physobj_list[i].obj; | |||
| mat4 GroundMat = PhysObj->GetTransform(); | |||
| PhysObjBarycenter += GroundMat[3].xyz; | |||
| @@ -661,7 +661,7 @@ void BtPhysTest::tick_draw(float seconds, Scene &scene) | |||
| #if USE_BODIES | |||
| for (int i = 0; i < m_physobj_list.count(); i++) | |||
| { | |||
| PhysicsObject* PhysObj = m_physobj_list[i].m1; | |||
| PhysicsObject* PhysObj = m_physobj_list[i].obj; | |||
| m_cat_sdata = new CatShaderData(((1 << VertexUsage::Position) | | |||
| (1 << VertexUsage::Color) | | |||
| (1 << VertexUsage::TexCoord) | | |||
| @@ -683,7 +683,7 @@ void BtPhysTest::tick_draw(float seconds, Scene &scene) | |||
| #if CAT_MODE | |||
| for (int i = 0; i < m_physobj_list.count(); i++) | |||
| { | |||
| PhysicsObject* PhysObj = m_physobj_list[i].m1; | |||
| PhysicsObject* PhysObj = m_physobj_list[i].obj; | |||
| CatShaderData* ShaderData = (CatShaderData*)PhysObj->GetCustomShaderData(); | |||
| ShaderData->m_sprite_orientation = damp(ShaderData->m_sprite_orientation, | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine — Bullet physics test | |||
| // | |||
| // Copyright © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2012—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -100,7 +100,8 @@ private: | |||
| lol::phys::Simulation* m_simulation; | |||
| array<EasyConstraint*> m_constraint_list; | |||
| array<PhysicsObject*, float> m_physobj_list; | |||
| struct animated_object { PhysicsObject* obj; float anim; }; | |||
| array<animated_object> m_physobj_list; | |||
| array<PhysicsObject*> m_ground_list; | |||
| array<PhysicsObject*> m_platform_list; | |||
| array<PhysicsObject*> m_character_list; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine — EasyMesh tutorial | |||
| // | |||
| // Copyright © 2011—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2011—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2012—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -39,23 +39,23 @@ public: | |||
| EasyMeshLuaObject* gears3 = EzMhLoader.GetPtr<EasyMeshLuaObject>("g3"); | |||
| EasyMeshLuaObject* gears4 = EzMhLoader.GetPtr<EasyMeshLuaObject>("g4"); | |||
| m_gears.push(gears0->GetMesh(), mat4(1.0f), 0.0f); | |||
| m_gears.push(gears1->GetMesh(), mat4(1.0f), 0.0f); | |||
| m_gears.push(gears2->GetMesh(), mat4(1.0f), 180.0f / 18); | |||
| m_gears.push(gears3->GetMesh(), mat4(1.0f), 180.0f / 18); | |||
| m_gears.push(gears4->GetMesh(), mat4(1.0f), 180.0f / 18); | |||
| m_gears.push(gear { gears0->GetMesh(), mat4(1.0f), 0.0f }); | |||
| m_gears.push(gear { gears1->GetMesh(), mat4(1.0f), 0.0f }); | |||
| m_gears.push(gear { gears2->GetMesh(), mat4(1.0f), 180.0f / 18 }); | |||
| m_gears.push(gear { gears3->GetMesh(), mat4(1.0f), 180.0f / 18 }); | |||
| m_gears.push(gear { gears4->GetMesh(), mat4(1.0f), 180.0f / 18 }); | |||
| /* | |||
| m_gears[0].m1.Compile("[sc#00f ab 8 1 8 ty -.25]" | |||
| "[sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0 s .1 .1 .1 ty -.1 csgu]" | |||
| "[sc#fff scb#000 acg 12 10 10 10 20 20 5 5 0.1 0 s .05 .05 .05 tx -1.5 ty .3 csgu]" | |||
| "[sc#00f ab 5 3 9 tx 2.5 csgs]" | |||
| "[[ sc#fff ab 3 1.4 2 tx -2 tz -2 " | |||
| "[sc#fff ab 2.1 .7 1.1 ty .5 tx -1.4 tz -1.4 csgs] mz] csgu]"); | |||
| m_gears[1].m1.Compile("sc#ff9 scb#ff9 acg 54 10 95 95 90 90 -5 -5 0.1 0 s .1 .1 .1"); | |||
| m_gears[2].m1.Compile("[sc#0f0 ab 2 2 2 t .8 .8 .8 rx 20 ry 20 [sc#00f ab 2 2 2 tx 0 csgu]]"); | |||
| m_gears[3].m1.Compile("[sc#0f0 ab 2 2 2 t .8 .8 .8 rx 20 ry 20 [sc#00f ab 2 2 2 tx 0 csgs]]"); | |||
| m_gears[4].m1.Compile("[sc#0f0 ab 2 2 2 t .8 .8 .8 rx 20 ry 20 [sc#00f ab 2 2 2 tx 0 csga]]"); | |||
| m_gears[0].mesh.Compile("[sc#00f ab 8 1 8 ty -.25]" | |||
| "[sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0 s .1 .1 .1 ty -.1 csgu]" | |||
| "[sc#fff scb#000 acg 12 10 10 10 20 20 5 5 0.1 0 s .05 .05 .05 tx -1.5 ty .3 csgu]" | |||
| "[sc#00f ab 5 3 9 tx 2.5 csgs]" | |||
| "[[ sc#fff ab 3 1.4 2 tx -2 tz -2 " | |||
| "[sc#fff ab 2.1 .7 1.1 ty .5 tx -1.4 tz -1.4 csgs] mz] csgu]"); | |||
| m_gears[1].mesh.Compile("sc#ff9 scb#ff9 acg 54 10 95 95 90 90 -5 -5 0.1 0 s .1 .1 .1"); | |||
| m_gears[2].mesh.Compile("[sc#0f0 ab 2 2 2 t .8 .8 .8 rx 20 ry 20 [sc#00f ab 2 2 2 tx 0 csgu]]"); | |||
| m_gears[3].mesh.Compile("[sc#0f0 ab 2 2 2 t .8 .8 .8 rx 20 ry 20 [sc#00f ab 2 2 2 tx 0 csgs]]"); | |||
| m_gears[4].mesh.Compile("[sc#0f0 ab 2 2 2 t .8 .8 .8 rx 20 ry 20 [sc#00f ab 2 2 2 tx 0 csga]]"); | |||
| */ | |||
| m_angle = 0; | |||
| @@ -96,25 +96,25 @@ public: | |||
| * mat4::rotate(radians(100.f), vec3(0, 1, 0)); | |||
| // * mat4::rotate(m_angle, vec3(0, 1, 0)); | |||
| m_gears[0].m3 += seconds * radians(20.0f); | |||
| m_gears[1].m3 += seconds * radians(20.0f) * -2 / 9; | |||
| m_gears[2].m3 += seconds * radians(20.0f) * -2 / 3; | |||
| m_gears[3].m3 += seconds * radians(20.0f) * -2 / 3; | |||
| m_gears[4].m3 += seconds * radians(20.0f) * -2 / 3; | |||
| m_gears[0].m2 = mat4::translate(vec3(0, -1, 0)) | |||
| * mat4::rotate(m_gears[0].m3 - 130.0f, vec3(0, 1, 0)) | |||
| * mat4::rotate(40.0f, vec3(0, 0, 1)); | |||
| m_gears[1].m2 = mat4::translate(vec3(0, 0, 0)) | |||
| * mat4::rotate(m_gears[1].m3, vec3(0, 1, 0)); | |||
| m_gears[2].m2 = mat4::translate(vec3(0, 0, 5.5f)) | |||
| * mat4::rotate(m_gears[2].m3 - 40.0f, vec3(0, 1, 0)) | |||
| * mat4::rotate(90.0f, vec3(0, 0, 1)); | |||
| m_gears[3].m2 = mat4::translate(vec3(5.5f * lol::sqrt(3.f) * 0.5f, 0, -5.5f * 0.5f)) | |||
| * mat4::rotate(m_gears[3].m3 - 140.0f, vec3(0, 1, 0)) | |||
| * mat4::rotate(-70.0f, vec3(0, 0, 1)); | |||
| m_gears[4].m2 = mat4::translate(vec3(-5.5f * lol::sqrt(3.f) * 0.5f, 0, -5.5f * 0.5f)) | |||
| * mat4::rotate(m_gears[4].m3 - 80.0f, vec3(0, 1, 0)); | |||
| m_gears[0].anim += seconds * radians(20.0f); | |||
| m_gears[1].anim += seconds * radians(20.0f) * -2 / 9; | |||
| m_gears[2].anim += seconds * radians(20.0f) * -2 / 3; | |||
| m_gears[3].anim += seconds * radians(20.0f) * -2 / 3; | |||
| m_gears[4].anim += seconds * radians(20.0f) * -2 / 3; | |||
| m_gears[0].mat = mat4::translate(vec3(0, -1, 0)) | |||
| * mat4::rotate(m_gears[0].anim - 130.0f, vec3(0, 1, 0)) | |||
| * mat4::rotate(40.0f, vec3(0, 0, 1)); | |||
| m_gears[1].mat = mat4::translate(vec3(0, 0, 0)) | |||
| * mat4::rotate(m_gears[1].anim, vec3(0, 1, 0)); | |||
| m_gears[2].mat = mat4::translate(vec3(0, 0, 5.5f)) | |||
| * mat4::rotate(m_gears[2].anim - 40.0f, vec3(0, 1, 0)) | |||
| * mat4::rotate(90.0f, vec3(0, 0, 1)); | |||
| m_gears[3].mat = mat4::translate(vec3(5.5f * lol::sqrt(3.f) * 0.5f, 0, -5.5f * 0.5f)) | |||
| * mat4::rotate(m_gears[3].anim - 140.0f, vec3(0, 1, 0)) | |||
| * mat4::rotate(-70.0f, vec3(0, 0, 1)); | |||
| m_gears[4].mat = mat4::translate(vec3(-5.5f * lol::sqrt(3.f) * 0.5f, 0, -5.5f * 0.5f)) | |||
| * mat4::rotate(m_gears[4].anim - 80.0f, vec3(0, 1, 0)); | |||
| } | |||
| virtual bool init_draw() override | |||
| @@ -125,7 +125,7 @@ public: | |||
| /* Upload vertex data to GPU */ | |||
| for (int i = 0; i < m_gears.count(); i++) | |||
| m_gears[i].m1.MeshConvert(); | |||
| m_gears[i].mesh.MeshConvert(); | |||
| #if USE_CUSTOM_SHADER | |||
| /* Custom Shader: Init the shader */ | |||
| @@ -133,7 +133,7 @@ public: | |||
| // any other shader stuf here (Get uniform, mostly, and set texture) | |||
| for (int i = 0; i < m_gears.count(); i++) | |||
| m_gears[i].m1.SetMaterial(custom_shader); | |||
| m_gears[i].mesh.SetMaterial(custom_shader); | |||
| #endif | |||
| return true; | |||
| @@ -144,7 +144,7 @@ public: | |||
| WorldEntity::tick_draw(seconds, scene); | |||
| for (int i = 0; i < m_gears.count(); i++) | |||
| m_gears[i].m1.Render(scene, m_mat * m_gears[i].m2); | |||
| m_gears[i].mesh.Render(scene, m_mat * m_gears[i].mat); | |||
| } | |||
| virtual bool release_draw() override | |||
| @@ -156,7 +156,9 @@ public: | |||
| } | |||
| private: | |||
| array<EasyMesh, mat4, float> m_gears; | |||
| struct gear { EasyMesh mesh; mat4 mat; float anim; }; | |||
| array<gear> m_gears; | |||
| float m_angle; | |||
| mat4 m_mat; | |||
| Camera *m_camera; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine — Sprite tutorial | |||
| // | |||
| // Copyright © 2011—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2011—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2012 Daniel Stephens (artwork) | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -35,8 +35,8 @@ public: | |||
| for (int i = 0; i < SPRITE_COUNT; ++i) | |||
| { | |||
| m_sprites.push(vec3((float)rand(-96, 640), (float)rand(-96, 480), 0.f), | |||
| rand(0.f, 1.f)); | |||
| m_sprites.push(sprite { vec3((float)rand(-96, 640), (float)rand(-96, 480), 0.f), | |||
| rand(0.f, 1.f) }); | |||
| } | |||
| } | |||
| @@ -50,10 +50,10 @@ public: | |||
| { | |||
| for (int i = 0; i < SPRITE_COUNT; ++i) | |||
| { | |||
| m_sprites[i].m1.y += 50.f * seconds; | |||
| m_sprites[i].m2 = lol::fmod(m_sprites[i].m2 + seconds, 1.f); | |||
| if (m_sprites[i].m1.y > 480 + 48) | |||
| m_sprites[i].m1.y = (float)rand(-96, -48); | |||
| m_sprites[i].pos.y += 50.f * seconds; | |||
| m_sprites[i].anim = lol::fmod(m_sprites[i].anim + seconds, 1.f); | |||
| if (m_sprites[i].pos.y > 480 + 48) | |||
| m_sprites[i].pos.y = (float)rand(-96, -48); | |||
| } | |||
| WorldEntity::tick_game(seconds); | |||
| @@ -73,10 +73,10 @@ public: | |||
| for (int i = 0; i < SPRITE_COUNT; ++i) | |||
| { | |||
| int frame = (int)(m_sprites[i].m2 * FRAME_COUNT); | |||
| // m_sprites[i].m1.z = frame; | |||
| int frame = (int)(m_sprites[i].anim * FRAME_COUNT); | |||
| // m_sprites[i].pos.z = frame; | |||
| scene.AddTile(m_tileset, frame, | |||
| m_sprites[i].m1, vec2(2.f), 0.f); | |||
| m_sprites[i].pos, vec2(2.f), 0.f); | |||
| } | |||
| } | |||
| @@ -93,7 +93,9 @@ private: | |||
| static int const SPRITE_COUNT = 192; | |||
| static int const FRAME_COUNT = 16; | |||
| array<vec3, float> m_sprites; | |||
| struct sprite { vec3 pos; float anim; }; | |||
| array<sprite> m_sprites; | |||
| }; | |||
| int main(int argc, char **argv) | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine — Voronoi diagram tutorial | |||
| // | |||
| // Copyright © 2015—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2015—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2011—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -95,41 +95,47 @@ public: | |||
| for (int i = 0; i < MaxFboType; ++i) | |||
| { | |||
| m_fbos.push(std::make_shared<Framebuffer>(Video::GetSize()), 0, array<ShaderUniform>(), array<ShaderAttrib>() ); | |||
| m_fbos.push(fbo | |||
| { | |||
| std::make_shared<Framebuffer>(Video::GetSize()), | |||
| 0, | |||
| array<ShaderUniform>(), | |||
| array<ShaderAttrib>(), | |||
| }); | |||
| if (i == SrcVoronoiFbo) | |||
| { | |||
| m_fbos[i].m2 = Shader::Create(LOLFX_RESOURCE_NAME(12_voronoi_setup)); | |||
| m_fbos[i].m3 << m_fbos[i].m2->GetUniformLocation("u_texture"); | |||
| m_fbos[i].m3 << m_fbos[i].m2->GetUniformLocation("u_source_point"); | |||
| m_fbos[i].m3 << m_fbos[i].m2->GetUniformLocation("u_screen_res"); | |||
| m_fbos[i].m4 << m_fbos[i].m2->GetAttribLocation(VertexUsage::Position, 0); | |||
| m_fbos[i].shader = Shader::Create(LOLFX_RESOURCE_NAME(12_voronoi_setup)); | |||
| m_fbos[i].uni << m_fbos[i].shader->GetUniformLocation("u_texture"); | |||
| m_fbos[i].uni << m_fbos[i].shader->GetUniformLocation("u_source_point"); | |||
| m_fbos[i].uni << m_fbos[i].shader->GetUniformLocation("u_screen_res"); | |||
| m_fbos[i].attr << m_fbos[i].shader->GetAttribLocation(VertexUsage::Position, 0); | |||
| } | |||
| else if (i == VoronoiFbo) | |||
| { | |||
| m_fbos[i].m2 = Shader::Create(LOLFX_RESOURCE_NAME(12_voronoi)); | |||
| m_fbos[i].m3 << m_fbos[i].m2->GetUniformLocation("u_texture"); | |||
| m_fbos[i].m3 << m_fbos[i].m2->GetUniformLocation("u_step"); | |||
| m_fbos[i].m3 << m_fbos[i].m2->GetUniformLocation("u_screen_res"); | |||
| m_fbos[i].m4 << m_fbos[i].m2->GetAttribLocation(VertexUsage::Position, 0); | |||
| m_fbos[i].shader = Shader::Create(LOLFX_RESOURCE_NAME(12_voronoi)); | |||
| m_fbos[i].uni << m_fbos[i].shader->GetUniformLocation("u_texture"); | |||
| m_fbos[i].uni << m_fbos[i].shader->GetUniformLocation("u_step"); | |||
| m_fbos[i].uni << m_fbos[i].shader->GetUniformLocation("u_screen_res"); | |||
| m_fbos[i].attr << m_fbos[i].shader->GetAttribLocation(VertexUsage::Position, 0); | |||
| } | |||
| else if (i == DistanceVoronoiFbo) | |||
| { | |||
| m_fbos[i].m2 = Shader::Create(LOLFX_RESOURCE_NAME(12_voronoi_distance)); | |||
| m_fbos[i].shader = Shader::Create(LOLFX_RESOURCE_NAME(12_voronoi_distance)); | |||
| } | |||
| else if (i == DistanceFbo) | |||
| { | |||
| m_fbos[i].m2 = Shader::Create(LOLFX_RESOURCE_NAME(12_distance)); | |||
| m_fbos[i].shader = Shader::Create(LOLFX_RESOURCE_NAME(12_distance)); | |||
| } | |||
| m_fbos.last().m1->Bind(); | |||
| m_fbos.last().framebuffer->Bind(); | |||
| { | |||
| render_context rc(scene.get_renderer()); | |||
| rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
| rc.clear_depth(1.f); | |||
| scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
| } | |||
| m_fbos.last().m1->Unbind(); | |||
| m_fbos.last().framebuffer->Unbind(); | |||
| } | |||
| temp_buffer = std::make_shared<Framebuffer>(Video::GetSize()); | |||
| @@ -154,8 +160,11 @@ public: | |||
| if (keyboard->key_released(input::key::SC_O)) | |||
| voronoi_points.pop(); | |||
| else if (keyboard->key_released(input::key::SC_P)) | |||
| voronoi_points.push(vec3(rand<float>(512.f), rand<float>(512.f), .0f), | |||
| vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f))); | |||
| voronoi_points.push(point | |||
| { | |||
| vec3(rand<float>(512.f), rand<float>(512.f), .0f), | |||
| vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f)) | |||
| }); | |||
| else if (keyboard->key_released(input::key::SC_F1)) | |||
| m_cur_fbo = SrcVoronoiFbo; | |||
| else if (keyboard->key_released(input::key::SC_F2)) | |||
| @@ -167,10 +176,12 @@ public: | |||
| { | |||
| int i = 4; | |||
| while (i-- > 0) | |||
| voronoi_points.push(vec3(rand<float>(512.f), rand<float>(512.f), .0f), | |||
| vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f)) | |||
| //vec2::zero | |||
| ); | |||
| voronoi_points.push(point | |||
| { | |||
| vec3(rand<float>(512.f), rand<float>(512.f), .0f), | |||
| vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f)) | |||
| //vec2::zero | |||
| }); | |||
| mode = 1; | |||
| } | |||
| else | |||
| @@ -188,12 +199,12 @@ public: | |||
| float mi = (float)maxi; | |||
| float j = (float)i; | |||
| float f_time = (float)m_time; | |||
| voronoi_points.push(vec3(256.f) + 196.f * vec3(lol::cos( f_time + j * 2.f * F_PI / mi), lol::sin( f_time + j * 2.f * F_PI / mi), .0f), vec2(.0f)); | |||
| voronoi_points.push(vec3(256.f) + 128.f * vec3(lol::cos(-f_time + j * 2.f * F_PI / mi), lol::sin(-f_time + j * 2.f * F_PI / mi), .0f), vec2(.0f)); | |||
| voronoi_points.push(vec3(256.f) + 64.f * vec3(lol::cos( f_time + j * 2.f * F_PI / mi), lol::sin( f_time + j * 2.f * F_PI / mi), .0f), vec2(.0f)); | |||
| voronoi_points.push(vec3(256.f) + 32.f * vec3(lol::cos(-f_time + j * 2.f * F_PI / mi), lol::sin(-f_time + j * 2.f * F_PI / mi), .0f), vec2(.0f)); | |||
| voronoi_points.push(point { vec3(256.f) + 196.f * vec3(lol::cos( f_time + j * 2.f * F_PI / mi), lol::sin( f_time + j * 2.f * F_PI / mi), .0f), vec2(.0f) }); | |||
| voronoi_points.push(point { vec3(256.f) + 128.f * vec3(lol::cos(-f_time + j * 2.f * F_PI / mi), lol::sin(-f_time + j * 2.f * F_PI / mi), .0f), vec2(.0f) }); | |||
| voronoi_points.push(point { vec3(256.f) + 64.f * vec3(lol::cos( f_time + j * 2.f * F_PI / mi), lol::sin( f_time + j * 2.f * F_PI / mi), .0f), vec2(.0f) }); | |||
| voronoi_points.push(point { vec3(256.f) + 32.f * vec3(lol::cos(-f_time + j * 2.f * F_PI / mi), lol::sin(-f_time + j * 2.f * F_PI / mi), .0f), vec2(.0f) }); | |||
| } | |||
| voronoi_points.push(vec3(256.f), vec2(0.f)); | |||
| voronoi_points.push(point { vec3(256.f), vec2(0.f) }); | |||
| } | |||
| temp_buffer->Bind(); | |||
| @@ -210,30 +221,30 @@ public: | |||
| //SRC SETUP | |||
| for (int j = 0; j < voronoi_points.count(); ++j) | |||
| { | |||
| voronoi_points[j].m1 = vec3(voronoi_points[j].m1.xy + voronoi_points[j].m2 * seconds, voronoi_points[j].m1.z); | |||
| if (voronoi_points[j].m1.x >= limit.y || voronoi_points[j].m1.x <= limit.x) | |||
| voronoi_points[j].pos = vec3(voronoi_points[j].pos.xy + voronoi_points[j].speed * seconds, voronoi_points[j].pos.z); | |||
| if (voronoi_points[j].pos.x >= limit.y || voronoi_points[j].pos.x <= limit.x) | |||
| { | |||
| voronoi_points[j].m2.x *= -1.f; | |||
| voronoi_points[j].m1.x = clamp(voronoi_points[j].m1.x, limit.x, limit.y); | |||
| voronoi_points[j].speed.x *= -1.f; | |||
| voronoi_points[j].pos.x = clamp(voronoi_points[j].pos.x, limit.x, limit.y); | |||
| } | |||
| if (voronoi_points[j].m1.y >= limit.y || voronoi_points[j].m1.y <= limit.x) | |||
| if (voronoi_points[j].pos.y >= limit.y || voronoi_points[j].pos.y <= limit.x) | |||
| { | |||
| voronoi_points[j].m2.y *= -1.f; | |||
| voronoi_points[j].m1.y = clamp(voronoi_points[j].m1.y, limit.x, limit.y); | |||
| voronoi_points[j].speed.y *= -1.f; | |||
| voronoi_points[j].pos.y = clamp(voronoi_points[j].pos.y, limit.x, limit.y); | |||
| } | |||
| voronoi_points[j].m1.z = ((float)j + 1) / ((float)voronoi_points.count()); | |||
| voronoi_points[j].pos.z = ((float)j + 1) / ((float)voronoi_points.count()); | |||
| } | |||
| int f = SrcVoronoiFbo; | |||
| m_fbos[f].m1->Bind(); | |||
| m_fbos[f].framebuffer->Bind(); | |||
| { | |||
| render_context rc(scene.get_renderer()); | |||
| rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
| rc.clear_depth(1.f); | |||
| scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
| } | |||
| m_fbos[f].m1->Unbind(); | |||
| m_fbos[f].framebuffer->Unbind(); | |||
| int buf = voronoi_points.count() % 2; | |||
| for (int j = 0; j < voronoi_points.count(); ++j) | |||
| @@ -242,30 +253,30 @@ public: | |||
| if (buf) | |||
| { | |||
| dst_buf = m_fbos[f].m1; | |||
| dst_buf = m_fbos[f].framebuffer; | |||
| src_buf = temp_buffer; | |||
| } | |||
| else | |||
| { | |||
| src_buf = m_fbos[f].m1; | |||
| src_buf = m_fbos[f].framebuffer; | |||
| dst_buf = temp_buffer; | |||
| } | |||
| dst_buf->Bind(); | |||
| /* FIXME: we should just disable depth test in the shader */ | |||
| scene.get_renderer()->clear(ClearMask::Depth); | |||
| m_fbos[f].m2->Bind(); | |||
| m_fbos[f].shader->Bind(); | |||
| int i = 0; | |||
| m_fbos[f].m2->SetUniform(m_fbos[f].m3[i++], src_buf->GetTextureUniform(), 0); //"u_texture" | |||
| m_fbos[f].m2->SetUniform(m_fbos[f].m3[i++], voronoi_points[j].m1); //"u_source_point" | |||
| m_fbos[f].m2->SetUniform(m_fbos[f].m3[i++], vec2(512.f, 512.f)); //"u_screen_res" | |||
| m_fbos[f].shader->SetUniform(m_fbos[f].uni[i++], src_buf->GetTextureUniform(), 0); //"u_texture" | |||
| m_fbos[f].shader->SetUniform(m_fbos[f].uni[i++], voronoi_points[j].pos); //"u_source_point" | |||
| m_fbos[f].shader->SetUniform(m_fbos[f].uni[i++], vec2(512.f, 512.f)); //"u_screen_res" | |||
| m_vdecl->Bind(); | |||
| m_vdecl->SetStream(m_vbo, m_fbos[f].m4.last()); | |||
| m_vdecl->SetStream(m_vbo, m_fbos[f].attr.last()); | |||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | |||
| m_vdecl->Unbind(); | |||
| m_fbos[f].m2->Unbind(); | |||
| m_fbos[f].shader->Unbind(); | |||
| dst_buf->Unbind(); | |||
| buf = 1 - buf; | |||
| @@ -279,14 +290,14 @@ public: | |||
| if (m_timer < .0f && m_cur_fbo != SrcVoronoiFbo) | |||
| { | |||
| //m_timer = 1.0f; | |||
| m_fbos[m_cur_fbo].m1->Bind(); | |||
| m_fbos[m_cur_fbo].framebuffer->Bind(); | |||
| { | |||
| render_context rc(scene.get_renderer()); | |||
| rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
| rc.clear_depth(1.f); | |||
| scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
| } | |||
| m_fbos[m_cur_fbo].m1->Unbind(); | |||
| m_fbos[m_cur_fbo].framebuffer->Unbind(); | |||
| ivec2 curres = ivec2(512, 512) / 2; | |||
| int buf = 0; | |||
| @@ -298,19 +309,19 @@ public: | |||
| if (curres == ivec2::zero) | |||
| shader = m_screen_shader; | |||
| else | |||
| shader = m_fbos[m_cur_fbo].m2; | |||
| shader = m_fbos[m_cur_fbo].shader; | |||
| if (curres.x == 256) | |||
| src_buf = m_fbos[SrcVoronoiFbo].m1; | |||
| src_buf = m_fbos[SrcVoronoiFbo].framebuffer; | |||
| else if (buf) | |||
| src_buf = m_fbos[m_cur_fbo].m1; | |||
| src_buf = m_fbos[m_cur_fbo].framebuffer; | |||
| else | |||
| src_buf = temp_buffer; | |||
| if (buf) | |||
| dst_buf = temp_buffer; | |||
| else | |||
| dst_buf = m_fbos[m_cur_fbo].m1; | |||
| dst_buf = m_fbos[m_cur_fbo].framebuffer; | |||
| dst_buf->Bind(); | |||
| /* FIXME: we should just disable depth test in the shader */ | |||
| @@ -322,16 +333,16 @@ public: | |||
| m_screen_shader->SetUniform(m_screen_texture, src_buf->GetTextureUniform(), 0); | |||
| else if (m_cur_fbo == VoronoiFbo) | |||
| { | |||
| shader->SetUniform(m_fbos[m_cur_fbo].m3[i++], src_buf->GetTextureUniform(), 0); //"u_texture" | |||
| shader->SetUniform(m_fbos[m_cur_fbo].m3[i++], ((float)curres.x) / 512.f); //"u_step" | |||
| shader->SetUniform(m_fbos[m_cur_fbo].m3[i++], vec2(512.f, 512.f)); //"u_screen_res" | |||
| shader->SetUniform(m_fbos[m_cur_fbo].uni[i++], src_buf->GetTextureUniform(), 0); //"u_texture" | |||
| shader->SetUniform(m_fbos[m_cur_fbo].uni[i++], ((float)curres.x) / 512.f); //"u_step" | |||
| shader->SetUniform(m_fbos[m_cur_fbo].uni[i++], vec2(512.f, 512.f)); //"u_screen_res" | |||
| } | |||
| m_vdecl->Bind(); | |||
| m_vdecl->SetStream(m_vbo, m_fbos[m_cur_fbo].m4.last()); | |||
| m_vdecl->SetStream(m_vbo, m_fbos[m_cur_fbo].attr.last()); | |||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | |||
| m_vdecl->Unbind(); | |||
| m_fbos[m_cur_fbo].m2->Unbind(); | |||
| m_fbos[m_cur_fbo].shader->Unbind(); | |||
| dst_buf->Unbind(); | |||
| if (curres == ivec2::zero) | |||
| @@ -350,7 +361,7 @@ public: | |||
| //SCREEN DRAW | |||
| m_screen_shader->Bind(); | |||
| m_screen_shader->SetUniform(m_screen_texture, m_fbos[m_cur_fbo].m1->GetTextureUniform(), 0); | |||
| m_screen_shader->SetUniform(m_screen_texture, m_fbos[m_cur_fbo].framebuffer->GetTextureUniform(), 0); | |||
| m_vdecl->Bind(); | |||
| m_vdecl->SetStream(m_vbo, m_screen_coord); | |||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | |||
| @@ -359,7 +370,8 @@ public: | |||
| } | |||
| private: | |||
| array<vec3, vec2> voronoi_points; | |||
| struct point { vec3 pos; vec2 speed; }; | |||
| array<point> voronoi_points; | |||
| array<vec2> m_vertices; | |||
| std::shared_ptr<Shader> m_screen_shader; | |||
| ShaderAttrib m_screen_coord; | |||
| @@ -368,7 +380,14 @@ private: | |||
| std::shared_ptr<VertexDeclaration> m_vdecl; | |||
| std::shared_ptr<VertexBuffer> m_vbo; | |||
| array<std::shared_ptr<Framebuffer>, std::shared_ptr<Shader>, array<ShaderUniform>, array<ShaderAttrib> > m_fbos; | |||
| struct fbo | |||
| { | |||
| std::shared_ptr<Framebuffer> framebuffer; | |||
| std::shared_ptr<Shader> shader; | |||
| array<ShaderUniform> uni; | |||
| array<ShaderAttrib> attr; | |||
| }; | |||
| array<fbo> m_fbos; | |||
| std::shared_ptr<Framebuffer> temp_buffer; | |||
| int mode; | |||
| @@ -1 +1 @@ | |||
| Subproject commit ecc3aee6e152e91dc58b1c1498d6fc5a346a0ab3 | |||
| Subproject commit 4446947aec179186e165d36f36425ee568a71a34 | |||
| @@ -31,7 +31,7 @@ liblol_core_headers = \ | |||
| lol/lua.h \ | |||
| \ | |||
| lol/base/all.h \ | |||
| lol/base/tuple.h lol/base/array.h lol/base/map.h lol/base/enum.h \ | |||
| lol/base/array.h lol/base/map.h lol/base/enum.h \ | |||
| lol/base/log.h \ | |||
| \ | |||
| lol/algorithm/all.h \ | |||
| @@ -1,21 +1,25 @@ | |||
| // | |||
| // Lol Engine | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
| // (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; 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 Sam Hocevar. See | |||
| // http://www.wtfpl.net/ for more details. | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2013 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. | |||
| // | |||
| #pragma once | |||
| // | |||
| // The CommandStack struct | |||
| // ------------------ | |||
| // ——————————————————————— | |||
| // | |||
| #include <tuple> // std::get | |||
| namespace lol | |||
| { | |||
| @@ -35,9 +39,9 @@ public: | |||
| int GetCmd(int i) | |||
| { | |||
| ASSERT(0 <= i && i < m_commands.count()); | |||
| m_f_cur = m_commands[i].m2; | |||
| m_i_cur = m_commands[i].m3; | |||
| return m_commands[i].m1; | |||
| m_f_cur = std::get<1>(m_commands[i]); | |||
| m_i_cur = std::get<2>(m_commands[i]); | |||
| return std::get<0>(m_commands[i]); | |||
| } | |||
| //cmd storage | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // EasyMesh-Csg: The code belonging to CSG operations | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2010—2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -77,8 +77,10 @@ void CsgBsp::AddTriangleToTree(int const &tri_idx, vec3 const &tri_p0, vec3 cons | |||
| while (tri_to_process.count()) | |||
| { | |||
| int leaf_idx = tri_to_process.last().m1; | |||
| vec3 v[3] = { tri_to_process.last().m2, tri_to_process.last().m3, tri_to_process.last().m4 }; | |||
| int leaf_idx = std::get<0>(tri_to_process.last()); | |||
| vec3 v[3] = { std::get<1>(tri_to_process.last()), | |||
| std::get<2>(tri_to_process.last()), | |||
| std::get<3>(tri_to_process.last()) }; | |||
| int res_nb[3] = { 0, 0, 0 }; | |||
| int res_side[3] = { -1, -1, -1 }; | |||
| @@ -176,7 +178,7 @@ void CsgBsp::AddTriangleToTree(int const &tri_idx, vec3 const &tri_p0, vec3 cons | |||
| Leaf_to_add.push(new_leaf_type, leaf_idx, v[0], v[1], v[2], -1); | |||
| } | |||
| else | |||
| tri_to_process.last().m1 = new_leaf; | |||
| std::get<0>(tri_to_process.last()) = new_leaf; | |||
| } | |||
| //All points are on the current leaf, add the tri_idx to the list of this leaf. | |||
| else | |||
| @@ -185,7 +187,7 @@ void CsgBsp::AddTriangleToTree(int const &tri_idx, vec3 const &tri_p0, vec3 cons | |||
| bool already_exist = false; | |||
| for (int i = 0; !already_exist && i < m_tree[leaf_idx].m_tri_list.count(); i++) | |||
| already_exist = (m_tree[leaf_idx].m_tri_list[i].m1 == tri_idx); | |||
| already_exist = (std::get<0>(m_tree[leaf_idx].m_tri_list[i]) == tri_idx); | |||
| if (!already_exist) | |||
| m_tree[leaf_idx].m_tri_list.push(tri_idx, tri_p0, tri_p1, tri_p2); | |||
| } | |||
| @@ -195,20 +197,20 @@ void CsgBsp::AddTriangleToTree(int const &tri_idx, vec3 const &tri_p0, vec3 cons | |||
| for (int i = 0; i < Leaf_to_add.count(); i++) | |||
| { | |||
| //If we had it to an already existing leaf. | |||
| if (Leaf_to_add[i].m2 < m_tree.count() && m_tree[Leaf_to_add[i].m2].m_leaves[Leaf_to_add[i].m1] == LEAF_CURRENT) | |||
| if (std::get<1>(Leaf_to_add[i]) < m_tree.count() && m_tree[std::get<1>(Leaf_to_add[i])].m_leaves[std::get<0>(Leaf_to_add[i])] == LEAF_CURRENT) | |||
| { | |||
| AddLeaf(Leaf_to_add[i].m1, tri_p0, cross(normalize(tri_p1 - tri_p0), normalize(tri_p2 - tri_p1)), Leaf_to_add[i].m2); | |||
| AddLeaf(std::get<0>(Leaf_to_add[i]), tri_p0, cross(normalize(tri_p1 - tri_p0), normalize(tri_p2 - tri_p1)), std::get<1>(Leaf_to_add[i])); | |||
| m_tree.last().m_tri_list.push(tri_idx, tri_p0, tri_p1, tri_p2); | |||
| } | |||
| /* | |||
| if (Leaf_to_add[i].m6 == -1) | |||
| if (std::get<5>(Leaf_to_add[i]) == -1) | |||
| { | |||
| AddLeaf(Leaf_to_add[i].m1, tri_p0, cross(normalize(tri_p1 - tri_p0), normalize(tri_p2 - tri_p1)), Leaf_to_add[i].m2); | |||
| AddLeaf(std::get<0>(Leaf_to_add[i]), tri_p0, cross(normalize(tri_p1 - tri_p0), normalize(tri_p2 - tri_p1)), std::get<1>(Leaf_to_add[i])); | |||
| m_tree.last().m_tri_list.push(tri_idx, tri_p0, tri_p1, tri_p2); | |||
| } | |||
| else | |||
| m_tree[Leaf_to_add[i].m6].m_tri_list.push(tri_idx, tri_p0, tri_p1, tri_p2); | |||
| m_tree[std::get<5>(Leaf_to_add[i])].m_tri_list.push(tri_idx, tri_p0, tri_p1, tri_p2); | |||
| */ | |||
| } | |||
| } | |||
| @@ -240,19 +242,19 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| //Let's push the triangle in here. | |||
| tri_to_process.reserve(20); | |||
| tri_to_process.push( array< int >(), 0, 1, 2, 0); | |||
| tri_to_process.last().m1.push(0); | |||
| std::get<0>(tri_to_process.last()).push(0); | |||
| while (tri_to_process.count()) | |||
| { | |||
| while (tri_to_process.count()) | |||
| { | |||
| int leaf_idx = tri_to_process.last().m1.last(); | |||
| int t[3] = { tri_to_process.last().m2, | |||
| tri_to_process.last().m3, | |||
| tri_to_process.last().m4 }; | |||
| vec3 v[3] = { vert_list[t[0]].m1, | |||
| vert_list[t[1]].m1, | |||
| vert_list[t[2]].m1 }; | |||
| int leaf_idx = std::get<0>(tri_to_process.last()).last(); | |||
| int t[3] = { std::get<1>(tri_to_process.last()), | |||
| std::get<2>(tri_to_process.last()), | |||
| std::get<3>(tri_to_process.last()) }; | |||
| vec3 v[3] = { std::get<0>(vert_list[t[0]]), | |||
| std::get<0>(vert_list[t[1]]), | |||
| std::get<0>(vert_list[t[2]]) }; | |||
| int res_nb[3] = { 0, 0, 0 }; | |||
| int res_side[3] = { -1, -1, -1 }; | |||
| @@ -280,8 +282,10 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| for (; i < m_tree[leaf_idx].m_tri_list.count(); i++) | |||
| { | |||
| if (TestTriangleVsTriangle(v[0], v[1], v[2], | |||
| m_tree[leaf_idx].m_tri_list[i].m2, m_tree[leaf_idx].m_tri_list[i].m3, m_tree[leaf_idx].m_tri_list[i].m4, | |||
| isec_v[0], isec_v[1])) | |||
| std::get<1>(m_tree[leaf_idx].m_tri_list[i]), | |||
| std::get<2>(m_tree[leaf_idx].m_tri_list[i]), | |||
| std::get<3>(m_tree[leaf_idx].m_tri_list[i]), | |||
| isec_v[0], isec_v[1])) | |||
| break; | |||
| } | |||
| @@ -290,23 +294,26 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| { | |||
| if (m_tree[leaf_idx].m_leaves[LEAF_FRONT] == LEAF_CURRENT && | |||
| m_tree[leaf_idx].m_leaves[LEAF_BACK] == LEAF_CURRENT && | |||
| tri_to_process.last().m1.count() == 1) | |||
| std::get<0>(tri_to_process.last()).count() == 1) | |||
| { | |||
| tri_list.push(LEAF_CURRENT, tri_to_process.last().m2, tri_to_process.last().m3, tri_to_process.last().m4); | |||
| tri_list.push(LEAF_CURRENT, | |||
| std::get<1>(tri_to_process.last()), | |||
| std::get<2>(tri_to_process.last()), | |||
| std::get<3>(tri_to_process.last())); | |||
| tri_to_process.pop(); | |||
| } | |||
| else | |||
| { | |||
| tri_to_process.last().m1.pop(); | |||
| std::get<0>(tri_to_process.last()).pop(); | |||
| //Register the triangle as needing to intersect with Front & back leaves. | |||
| if (m_tree[leaf_idx].m_leaves[LEAF_FRONT] != LEAF_CURRENT) | |||
| tri_to_process.last().m1.push(m_tree[leaf_idx].m_leaves[LEAF_FRONT]); | |||
| std::get<0>(tri_to_process.last()).push(m_tree[leaf_idx].m_leaves[LEAF_FRONT]); | |||
| if (m_tree[leaf_idx].m_leaves[LEAF_BACK] != LEAF_CURRENT) | |||
| tri_to_process.last().m1.push(m_tree[leaf_idx].m_leaves[LEAF_BACK]); | |||
| std::get<0>(tri_to_process.last()).push(m_tree[leaf_idx].m_leaves[LEAF_BACK]); | |||
| //Mark the triangle as needing point by point test | |||
| tri_to_process.last().m5 = 1; | |||
| std::get<4>(tri_to_process.last()) = 1; | |||
| } | |||
| } | |||
| //there was an intersection, so let's split the triangle. | |||
| @@ -340,8 +347,9 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| continue; | |||
| #endif | |||
| new_v_idx[k] = vert_list.count(); | |||
| vec3 PmV0 = (isec_v[k] - vert_list[t[isec_i[k]]].m1); | |||
| vec3 V1mV0 = (vert_list[t[(isec_i[k] + 1) % 3]].m1 - vert_list[t[isec_i[k]]].m1); | |||
| vec3 PmV0 = (isec_v[k] - std::get<0>(vert_list[t[isec_i[k]]])); | |||
| vec3 V1mV0 = (std::get<0>(vert_list[t[(isec_i[k] + 1) % 3]]) | |||
| - std::get<0>(vert_list[t[isec_i[k]]])); | |||
| float alpha = length(PmV0) / length(V1mV0); | |||
| vert_list.push(isec_v[k], | |||
| t[isec_i[k]], t[(isec_i[k] + 1) % 3], | |||
| @@ -356,28 +364,28 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| //Leaf_type is the type for the triangle that is alone on its side. | |||
| int leaf_type = res_side[(isec_base + 2) % 3]; | |||
| if (m_tree[leaf_idx].m_leaves[leaf_type] == LEAF_CURRENT && tri_to_process.last().m1.last() == 1) | |||
| if (m_tree[leaf_idx].m_leaves[leaf_type] == LEAF_CURRENT && std::get<0>(tri_to_process.last()).last() == 1) | |||
| tri_list.push(leaf_type, | |||
| t[(isec_base + 2) % 3], new_v_idx[v_idx1], new_v_idx[v_idx0]); | |||
| else | |||
| { | |||
| tri_to_process.push(array< int >(), t[(isec_base + 2) % 3], new_v_idx[v_idx1], new_v_idx[v_idx0], 0); | |||
| tri_to_process.last().m1.push(0); | |||
| std::get<0>(tri_to_process.last()).push(0); | |||
| } | |||
| if (m_tree[leaf_idx].m_leaves[1 - leaf_type] == LEAF_CURRENT && tri_to_process.last().m1.last() == 1) | |||
| if (m_tree[leaf_idx].m_leaves[1 - leaf_type] == LEAF_CURRENT && std::get<0>(tri_to_process.last()).last() == 1) | |||
| { | |||
| tri_list.push((tri_to_process.last().m5)?(LEAF_CURRENT):(1 - leaf_type), | |||
| tri_list.push((std::get<4>(tri_to_process.last()))?(LEAF_CURRENT):(1 - leaf_type), | |||
| t[isec_base], new_v_idx[((isec_base + 1) % 3)], new_v_idx[v_idx0]); | |||
| tri_list.push((tri_to_process.last().m5)?(LEAF_CURRENT):(1 - leaf_type), | |||
| tri_list.push((std::get<4>(tri_to_process.last()))?(LEAF_CURRENT):(1 - leaf_type), | |||
| t[isec_base], new_v_idx[v_idx0], new_v_idx[v_idx1]); | |||
| } | |||
| else | |||
| { | |||
| tri_to_process.push(array< int >(), t[isec_base], t[((isec_base + 1) % 3)], new_v_idx[v_idx0], 0); | |||
| tri_to_process.last().m1.push(0); | |||
| std::get<0>(tri_to_process.last()).push(0); | |||
| tri_to_process.push(array< int >(), t[isec_base], new_v_idx[v_idx0], new_v_idx[v_idx1], 0); | |||
| tri_to_process.last().m1.push(0); | |||
| std::get<0>(tri_to_process.last()).push(0); | |||
| } | |||
| #else | |||
| int new_t[9] = { t[(isec_base + 2) % 3], new_v_idx[v_idx1], new_v_idx[v_idx0], | |||
| @@ -396,7 +404,7 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| bool skip_tri = false; | |||
| for(int l = 0; l < 3; l++) | |||
| { | |||
| if (length(vert_list[new_t[k + l]].m1 - vert_list[new_t[k + (l + 1) % 3]].m1) < TestEpsilon::Get()) | |||
| if (length(std::get<0>(vert_list[new_t[k + l]]) - std::get<0>(vert_list[new_t[k + (l + 1) % 3]])) < TestEpsilon::Get()) | |||
| { | |||
| skip_tri = true; | |||
| break; | |||
| @@ -408,18 +416,18 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| #endif | |||
| #if 0 //Send the newly created triangle back to the beginning | |||
| tri_to_process.push(array< int >(), new_t[k], new_t[k + 1], new_t[k + 2], 0); | |||
| tri_to_process.last().m1.push(0); | |||
| std::get<0>(tri_to_process.last()).push(0); | |||
| #else //Inherit parent tree | |||
| if (m_tree[leaf_idx].m_leaves[new_side[k / 3]] == LEAF_CURRENT && tri_to_process[tri_to_remove].m1.count() == 1) | |||
| if (m_tree[leaf_idx].m_leaves[new_side[k / 3]] == LEAF_CURRENT && std::get<0>(tri_to_process[tri_to_remove]).count() == 1) | |||
| tri_list.push(new_side[k / 3], new_t[k], new_t[k + 1], new_t[k + 2]); | |||
| else | |||
| { | |||
| tri_to_process.push(array< int >(), new_t[k], new_t[k + 1], new_t[k + 2], 0); | |||
| tri_to_process.last().m1 = tri_to_process[tri_to_remove].m1; | |||
| std::get<0>(tri_to_process.last()) = std::get<0>(tri_to_process[tri_to_remove]); | |||
| if (m_tree[leaf_idx].m_leaves[new_side[k / 3]] == LEAF_CURRENT) | |||
| tri_to_process.last().m1.pop(); | |||
| std::get<0>(tri_to_process.last()).pop(); | |||
| else | |||
| tri_to_process.last().m1.last() = m_tree[leaf_idx].m_leaves[new_side[k / 3]]; | |||
| std::get<0>(tri_to_process.last()).last() = m_tree[leaf_idx].m_leaves[new_side[k / 3]]; | |||
| } | |||
| #endif | |||
| } | |||
| @@ -440,23 +448,26 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| if (new_leaf == LEAF_CURRENT) | |||
| { | |||
| //We still need to test other leaves. | |||
| if (tri_to_process.last().m1.count() > 1) | |||
| tri_to_process.last().m1.pop(); | |||
| if (std::get<0>(tri_to_process.last()).count() > 1) | |||
| std::get<0>(tri_to_process.last()).pop(); | |||
| else | |||
| { | |||
| tri_list.push((tri_to_process.last().m5)?(LEAF_CURRENT):(new_leaf_type), | |||
| tri_to_process.last().m2, tri_to_process.last().m3, tri_to_process.last().m4); | |||
| tri_list.push((std::get<4>(tri_to_process.last()))?(LEAF_CURRENT):(new_leaf_type), | |||
| std::get<1>(tri_to_process.last()), std::get<2>(tri_to_process.last()), std::get<3>(tri_to_process.last())); | |||
| tri_to_process.pop(); | |||
| } | |||
| } | |||
| else | |||
| tri_to_process.last().m1.last() = new_leaf; | |||
| std::get<0>(tri_to_process.last()).last() = new_leaf; | |||
| } | |||
| //All points are on the current leaf, add the tri_idx to the list of this leaf. | |||
| else | |||
| { | |||
| //TODO : Special case, handle coplanar cut. | |||
| tri_list.push(LEAF_CURRENT, tri_to_process.last().m2, tri_to_process.last().m3, tri_to_process.last().m4); | |||
| tri_list.push(LEAF_CURRENT, | |||
| std::get<1>(tri_to_process.last()), | |||
| std::get<2>(tri_to_process.last()), | |||
| std::get<3>(tri_to_process.last())); | |||
| tri_to_process.pop(); | |||
| } | |||
| } | |||
| @@ -465,15 +476,15 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| for (int i = 0; i < tri_list.count(); i++) | |||
| { | |||
| #define TEST_MAX 4 | |||
| int t[3] = { tri_list[i].m2, | |||
| tri_list[i].m3, | |||
| tri_list[i].m4 }; | |||
| vec3 v[4] = { vert_list[t[0]].m1, | |||
| vert_list[t[1]].m1, | |||
| vert_list[t[2]].m1, | |||
| (vert_list[t[0]].m1 + | |||
| vert_list[t[1]].m1 + | |||
| vert_list[t[2]].m1) / 3.0f }; | |||
| int t[3] = { std::get<1>(tri_list[i]), | |||
| std::get<2>(tri_list[i]), | |||
| std::get<3>(tri_list[i]) }; | |||
| vec3 v[4] = { std::get<0>(vert_list[t[0]]), | |||
| std::get<0>(vert_list[t[1]]), | |||
| std::get<0>(vert_list[t[2]]), | |||
| (std::get<0>(vert_list[t[0]]) + | |||
| std::get<0>(vert_list[t[1]]) + | |||
| std::get<0>(vert_list[t[2]])) / 3.0f }; | |||
| int res_total = 0; | |||
| int res_nb[3] = { 0, 0, 0 }; | |||
| @@ -512,10 +523,13 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| #if 0 | |||
| res_total = res_total; | |||
| #endif | |||
| tri_list[i].m1 = LEAF_BACK; | |||
| std::get<0>(tri_list[i]) = LEAF_BACK; | |||
| #if 0 | |||
| tri_to_process.push( array< int >(), tri_list[i].m2, tri_list[i].m3, tri_list[i].m4, 0); | |||
| tri_to_process.last().m1.push(0); | |||
| tri_to_process.push(array< int >(), | |||
| std::get<1>(tri_list[i]), | |||
| std::get<2>(tri_list[i]), | |||
| std::get<3>(tri_list[i]), 0); | |||
| std::get<0>(tri_to_process.last()).push(0); | |||
| tri_list.remove(i--); | |||
| break; | |||
| #endif | |||
| @@ -526,12 +540,12 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||
| { | |||
| if (res_side[k] != LEAF_CURRENT) | |||
| { | |||
| tri_list[i].m1 = res_side[k]; | |||
| std::get<0>(tri_list[i]) = res_side[k]; | |||
| break; | |||
| } | |||
| } | |||
| if (k == TEST_MAX) | |||
| tri_list[i].m1 = LEAF_FRONT; | |||
| std::get<0>(tri_list[i]) = LEAF_FRONT; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,8 +1,8 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2010—2017 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2009—2013 Cédric Lecacheur <jordx@free.fr> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -22,8 +22,8 @@ int VertexDictionnary::FindVertexMaster(const int search_idx) | |||
| { | |||
| //Resolve current vertex idx in the dictionnary (if exist) | |||
| for (int j = 0; j < vertex_list.count(); j++) | |||
| if (vertex_list[j].m1 == search_idx) | |||
| return vertex_list[j].m3; | |||
| if (std::get<0>(vertex_list[j]) == search_idx) | |||
| return std::get<2>(vertex_list[j]); | |||
| return VDictType::DoesNotExist; | |||
| } | |||
| @@ -39,11 +39,11 @@ bool VertexDictionnary::FindMatchingVertices(const int search_idx, array<int> &m | |||
| if (cur_mast == VDictType::Master) | |||
| cur_mast = search_idx; | |||
| else | |||
| matching_ids << vertex_list[cur_mast].m1; | |||
| matching_ids << std::get<0>(vertex_list[cur_mast]); | |||
| for (int j = 0; j < vertex_list.count(); j++) | |||
| if (vertex_list[j].m3 == cur_mast && vertex_list[j].m1 != search_idx) | |||
| matching_ids << vertex_list[j].m1; | |||
| if (std::get<2>(vertex_list[j]) == cur_mast && std::get<0>(vertex_list[j]) != search_idx) | |||
| matching_ids << std::get<0>(vertex_list[j]); | |||
| return (matching_ids.count() > 0); | |||
| } | |||
| @@ -143,7 +143,7 @@ bool VertexDictionnary::FindConnectedTriangles(const ivec3 &search_idx, const ar | |||
| void VertexDictionnary::RegisterVertex(const int vert_id, const vec3 vert_coord) | |||
| { | |||
| for (int j = 0; j < vertex_list.count(); j++) | |||
| if (vertex_list[j].m1 == vert_id) | |||
| if (std::get<0>(vertex_list[j]) == vert_id) | |||
| return; | |||
| //First, build the vertex Dictionnary | |||
| @@ -151,9 +151,9 @@ void VertexDictionnary::RegisterVertex(const int vert_id, const vec3 vert_coord) | |||
| for (; i < master_list.count(); i++) | |||
| { | |||
| int cur_mast = master_list[i]; | |||
| int cur_id = vertex_list[cur_mast].m1; | |||
| vec3 cur_loc = vertex_list[cur_mast].m2; | |||
| int &cur_type = vertex_list[cur_mast].m3; | |||
| int cur_id = std::get<0>(vertex_list[cur_mast]); | |||
| vec3 cur_loc = std::get<1>(vertex_list[cur_mast]); | |||
| int &cur_type = std::get<2>(vertex_list[cur_mast]); | |||
| if (cur_id == vert_id) | |||
| return; | |||
| @@ -178,24 +178,24 @@ void VertexDictionnary::RemoveVertex(const int vert_id) | |||
| { | |||
| int j = 0; | |||
| for (; j < vertex_list.count(); j++) | |||
| if (vertex_list[j].m1 == vert_id) | |||
| if (std::get<0>(vertex_list[j]) == vert_id) | |||
| break; | |||
| if (vertex_list[j].m3 == VDictType::Master) | |||
| if (std::get<2>(vertex_list[j]) == VDictType::Master) | |||
| { | |||
| int jf = -1; | |||
| //change all the master ref in the list | |||
| for (int i = 0; i < vertex_list.count(); i++) | |||
| { | |||
| if (vertex_list[i].m3 == j) | |||
| if (std::get<2>(vertex_list[i]) == j) | |||
| { | |||
| if (jf < 0) | |||
| { | |||
| jf = i; | |||
| vertex_list[i].m3 = VDictType::Master; | |||
| std::get<2>(vertex_list[i]) = VDictType::Master; | |||
| } | |||
| else | |||
| vertex_list[i].m3 = jf; | |||
| std::get<2>(vertex_list[i]) = jf; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,9 +1,9 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2009—2013 Cédric Lecacheur <jordx@free.fr> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2013 Cédric Lecacheur <jordx@free.fr> | |||
| // © 2009—2013 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 | |||
| @@ -318,8 +318,8 @@ public: | |||
| { | |||
| if (face.ToScalar() >= m_texcoord_custom_build[mt.ToScalar()].count()) | |||
| m_texcoord_custom_build[mt.ToScalar()].resize(face.ToScalar() + 1); | |||
| m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()].m1 = BL; | |||
| m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()].m2 = TR; | |||
| std::get<0>(m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()]) = BL; | |||
| std::get<1>(m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()]) = TR; | |||
| m_texcoord_build_type[mt.ToScalar()] |= 1; | |||
| } | |||
| void ClearTexCoordCustomBuild(MeshType mt) { m_texcoord_build_type[mt.ToScalar()] &= ~1; } | |||
| @@ -331,8 +331,8 @@ public: | |||
| if (m_texcoord_build_type[mt.ToScalar()] & 1 | |||
| && face.ToScalar() < m_texcoord_custom_build[mt.ToScalar()].count()) | |||
| { | |||
| BL = m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()].m1; | |||
| TR = m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()].m2; | |||
| BL = std::get<0>(m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()]); | |||
| TR = std::get<1>(m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()]); | |||
| } | |||
| else | |||
| { | |||
| @@ -410,8 +410,8 @@ public: | |||
| { | |||
| if (face.ToScalar() >= m_texcoord_custom_build2[mt.ToScalar()].count()) | |||
| m_texcoord_custom_build2[mt.ToScalar()].resize(face.ToScalar() + 1); | |||
| m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()].m1 = BL; | |||
| m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()].m2 = TR; | |||
| std::get<0>(m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()]) = BL; | |||
| std::get<1>(m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()]) = TR; | |||
| m_texcoord_build_type2[mt.ToScalar()] |= 1; | |||
| } | |||
| void ClearTexCoordCustomBuild2(MeshType mt) { m_texcoord_build_type2[mt.ToScalar()] &= ~1; } | |||
| @@ -422,8 +422,8 @@ public: | |||
| if (m_texcoord_build_type2[mt.ToScalar()] & 1 | |||
| && face.ToScalar() < m_texcoord_custom_build2[mt.ToScalar()].count()) | |||
| { | |||
| BL = m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()].m1; | |||
| TR = m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()].m2; | |||
| BL = std::get<0>(m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()]); | |||
| TR = std::get<1>(m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()]); | |||
| } | |||
| else | |||
| { | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // EasyMesh-Csg: The code belonging to CSG operations | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2015 Cédric Lecacheur <jordx@free.fr> | |||
| // © 2009—2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
| // | |||
| @@ -53,11 +53,11 @@ void EasyMesh::MeshCsg(CSGUsage csg_operation) | |||
| return; | |||
| //BSP BUILD : We use the brace logic, csg should be used as : "[ exp .... [exp .... csg]]" | |||
| int cursor_start = (m_cursors.count() < 2)?(0):(m_cursors[(m_cursors.count() - 2)].m2); | |||
| int cursor_start = (m_cursors.count() < 2)?(0):(std::get<1>(m_cursors[(m_cursors.count() - 2)])); | |||
| for (int mesh_id = 0; mesh_id < 2; mesh_id++) | |||
| { | |||
| int start_point = (mesh_id == 0) ? (cursor_start) : (m_cursors.last().m2); | |||
| int end_point = (mesh_id == 0) ? (m_cursors.last().m2) : (m_indices.count()); | |||
| int start_point = (mesh_id == 0) ? (cursor_start) : (std::get<1>(m_cursors.last())); | |||
| int end_point = (mesh_id == 0) ? (std::get<1>(m_cursors.last())) : (m_indices.count()); | |||
| CsgBsp &mesh_bsp = (mesh_id == 0) ? (mesh_bsp_0) : (mesh_bsp_1); | |||
| for (int i = start_point; i < end_point; i += 3) | |||
| mesh_bsp.AddTriangleToTree(i, m_vert[m_indices[i]].m_coord, | |||
| @@ -69,8 +69,8 @@ void EasyMesh::MeshCsg(CSGUsage csg_operation) | |||
| int indices_count = m_indices.count(); | |||
| for (int mesh_id = 0; mesh_id < 2; mesh_id++) | |||
| { | |||
| int start_point = (mesh_id == 0) ? (cursor_start) : (m_cursors.last().m2); | |||
| int end_point = (mesh_id == 0) ? (m_cursors.last().m2) : (indices_count); | |||
| int start_point = (mesh_id == 0) ? (cursor_start) : (std::get<1>(m_cursors.last())); | |||
| int end_point = (mesh_id == 0) ? (std::get<1>(m_cursors.last())) : (indices_count); | |||
| CsgBsp &mesh_bsp = (mesh_id == 0) ? (mesh_bsp_1) : (mesh_bsp_0); | |||
| array< vec3, int, int, float > vert_list; | |||
| array< int, int, int, int > tri_list; | |||
| @@ -96,21 +96,21 @@ void EasyMesh::MeshCsg(CSGUsage csg_operation) | |||
| int base_idx = m_vert.count(); | |||
| for (int k = 3; k < vert_list.count(); k++) | |||
| { | |||
| int P0 = (vert_list[k].m2 < 3) ? (m_indices[i + vert_list[k].m2]) : (base_idx + vert_list[k].m2 - 3); | |||
| int P1 = (vert_list[k].m3 < 3) ? (m_indices[i + vert_list[k].m3]) : (base_idx + vert_list[k].m3 - 3); | |||
| int P0 = (std::get<1>(vert_list[k]) < 3) ? (m_indices[i + std::get<1>(vert_list[k])]) : (base_idx + std::get<1>(vert_list[k]) - 3); | |||
| int P1 = (std::get<2>(vert_list[k]) < 3) ? (m_indices[i + std::get<2>(vert_list[k])]) : (base_idx + std::get<2>(vert_list[k]) - 3); | |||
| AddVertex(vert_list[k].m1); | |||
| AddVertex(std::get<0>(vert_list[k])); | |||
| //Normal : bad calculations there. | |||
| n0 = m_vert[P0].m_normal; | |||
| n1 = m_vert[P1].m_normal; | |||
| SetCurVertNormal(normalize(n0 + (n1 - n0) * vert_list[k].m4)); | |||
| SetCurVertNormal(normalize(n0 + (n1 - n0) * std::get<3>(vert_list[k]))); | |||
| #if 1 | |||
| //Color | |||
| c0 = m_vert[P0].m_color; | |||
| c1 = m_vert[P1].m_color; | |||
| vec4 res = c0 + ((c1 - c0) * vert_list[k].m4); | |||
| vec4 res = c0 + ((c1 - c0) * std::get<3>(vert_list[k])); | |||
| SetCurVertColor(res); | |||
| #else | |||
| if (mesh_id == 0) | |||
| @@ -121,9 +121,9 @@ void EasyMesh::MeshCsg(CSGUsage csg_operation) | |||
| } | |||
| for (int k = 0; k < tri_list.count(); k++) | |||
| { | |||
| int P0 = (tri_list[k].m2 < 3) ? (m_indices[i + tri_list[k].m2]) : (base_idx + (tri_list[k].m2 - 3)); | |||
| int P1 = (tri_list[k].m3 < 3) ? (m_indices[i + tri_list[k].m3]) : (base_idx + (tri_list[k].m3 - 3)); | |||
| int P2 = (tri_list[k].m4 < 3) ? (m_indices[i + tri_list[k].m4]) : (base_idx + (tri_list[k].m4 - 3)); | |||
| int P0 = (std::get<1>(tri_list[k]) < 3) ? (m_indices[i + std::get<1>(tri_list[k])]) : (base_idx + (std::get<1>(tri_list[k]) - 3)); | |||
| int P1 = (std::get<2>(tri_list[k]) < 3) ? (m_indices[i + std::get<2>(tri_list[k])]) : (base_idx + (std::get<2>(tri_list[k]) - 3)); | |||
| int P2 = (std::get<3>(tri_list[k]) < 3) ? (m_indices[i + std::get<3>(tri_list[k])]) : (base_idx + (std::get<3>(tri_list[k]) - 3)); | |||
| AddTriangle(P0, P1, P2, 0); | |||
| } | |||
| #endif | |||
| @@ -134,29 +134,30 @@ void EasyMesh::MeshCsg(CSGUsage csg_operation) | |||
| { | |||
| for (int k = 0; k < tri_list.count(); k++) | |||
| { | |||
| auto const type = std::get<0>(tri_list[k]); | |||
| int tri_idx = (tri_list.count() == 1) ? (i) : (tri_base_idx + k * 3); | |||
| //Triangle Kill Test | |||
| if (//csgu : CSGUnion() -> m0_Outside + m1_Outside | |||
| (csg_operation == CSGUsage::Union && tri_list[k].m1 == LEAF_BACK) || | |||
| (csg_operation == CSGUsage::Union && type == LEAF_BACK) || | |||
| //csgs : CsgSub() -> m0_Outside + m1_Inside-inverted | |||
| (csg_operation == CSGUsage::Substract && | |||
| ((mesh_id == 0 && tri_list[k].m1 == LEAF_BACK) || | |||
| (mesh_id == 1 && tri_list[k].m1 == LEAF_FRONT))) || | |||
| ((mesh_id == 0 && type == LEAF_BACK) || | |||
| (mesh_id == 1 && type == LEAF_FRONT))) || | |||
| //csgs : CsgSubL() -> m0_Outside | |||
| (csg_operation == CSGUsage::SubstractLoss && | |||
| ((mesh_id == 0 && tri_list[k].m1 == LEAF_BACK) || mesh_id == 1)) || | |||
| ((mesh_id == 0 && type == LEAF_BACK) || mesh_id == 1)) || | |||
| //csga : CSGAnd() -> m0_Inside + m1_Inside | |||
| (csg_operation == CSGUsage::And && tri_list[k].m1 == LEAF_FRONT)) | |||
| (csg_operation == CSGUsage::And && type == LEAF_FRONT)) | |||
| { | |||
| triangle_to_kill.push(tri_idx); | |||
| } | |||
| //Triangle Invert Test | |||
| if (//csgs : CsgSub() -> m0_Outside + m1_Inside-inverted | |||
| (csg_operation == CSGUsage::Substract && mesh_id == 1 && tri_list[k].m1 == LEAF_BACK) || | |||
| (csg_operation == CSGUsage::Substract && mesh_id == 1 && type == LEAF_BACK) || | |||
| //csgx : CSGXor() -> m0_Outside/m0_Inside-inverted + m1_Outside/m1_Inside-inverted | |||
| (csg_operation == CSGUsage::Xor && tri_list[k].m1 == LEAF_BACK)) | |||
| (csg_operation == CSGUsage::Xor && type == LEAF_BACK)) | |||
| { | |||
| //a Xor means we will share vertices with the outside, so duplicate the vertices. | |||
| //TODO : This operation disconnect all triangle, in some cases, not a good thing. | |||
| @@ -209,8 +210,8 @@ void EasyMesh::MeshCsg(CSGUsage csg_operation) | |||
| for (int i = triangle_to_kill.count() - 1; i >= 0; i--) | |||
| m_indices.remove(triangle_to_kill[i], 3); | |||
| m_cursors.last().m1 = m_vert.count(); | |||
| m_cursors.last().m2 = m_indices.count(); | |||
| std::get<0>(m_cursors.last()) = m_vert.count(); | |||
| std::get<1>(m_cursors.last()) = m_indices.count(); | |||
| VerticesCleanup(); | |||
| //DONE for the splitting ! | |||
| @@ -30,7 +30,7 @@ void EasyMesh::LoopStart(int loopnb) | |||
| else if (BD()->IsEnabled(MeshBuildOperation::CommandExecution)) | |||
| { | |||
| //Only register if we're not the current loop command | |||
| if (!BD()->LoopStack().count() || BD()->LoopStack().last().m1 != BD()->Cmdi()) | |||
| if (!BD()->LoopStack().count() || std::get<0>(BD()->LoopStack().last()) != BD()->Cmdi()) | |||
| BD()->LoopStack().push(BD()->Cmdi(), loopnb); | |||
| } | |||
| } | |||
| @@ -49,9 +49,9 @@ void EasyMesh::LoopEnd() | |||
| //Only register if we're not the current loop command | |||
| if (BD()->LoopStack().count()) | |||
| { | |||
| BD()->LoopStack().last().m2--; | |||
| if (BD()->LoopStack().last().m2 > 0) | |||
| BD()->Cmdi() = BD()->LoopStack().last().m1 - 1; | |||
| std::get<1>(BD()->LoopStack().last())--; | |||
| if (std::get<1>(BD()->LoopStack().last()) > 0) | |||
| BD()->Cmdi() = std::get<0>(BD()->LoopStack().last()) - 1; | |||
| else | |||
| BD()->LoopStack().pop(); | |||
| } | |||
| @@ -173,7 +173,7 @@ void EasyMesh::SetVertColor(vec4 const &col) | |||
| return; | |||
| } | |||
| for (int i = m_cursors.last().m1; i < m_vert.count(); i++) | |||
| for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | |||
| m_vert[i].m_color = col; | |||
| } | |||
| @@ -216,7 +216,7 @@ void EasyMesh::VerticesMerge() | |||
| //1: Crunch all vertices in the dictionnary | |||
| VertexDictionnary vert_dict; | |||
| for (int i = m_cursors.last().m1; i < m_vert.count(); i++) | |||
| for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | |||
| vert_dict.RegisterVertex(i, m_vert[i].m_coord); | |||
| //2: Update the indices | |||
| @@ -249,7 +249,7 @@ void EasyMesh::VerticesSeparate() | |||
| vert_ids[m_indices[i]]++; | |||
| //2: Update the vertices | |||
| int vbase = m_cursors.last().m1; | |||
| int vbase = std::get<0>(m_cursors.last()); | |||
| int vcount = m_vert.count(); | |||
| new_ids.resize(vcount); | |||
| for (int i = vbase; i < vcount; i++) | |||
| @@ -285,8 +285,8 @@ void EasyMesh::ComputeTexCoord(float uv_scale, int uv_offset) | |||
| VertexDictionnary vert_dict; | |||
| array<int> tri_list; | |||
| tri_list.Reserve(m_indices.count() - m_cursors.last().m2); | |||
| for (int i = m_cursors.last().m2; i < m_indices.count(); i++) | |||
| tri_list.Reserve(m_indices.count() - std::get<1>(m_cursors.last())); | |||
| for (int i = std::get<1>(m_cursors.last()); i < m_indices.count(); i++) | |||
| { | |||
| vert_dict.RegisterVertex(m_indices[i], m_vert[m_indices[i]].m_coord); | |||
| tri_list << m_indices[i]; | |||
| @@ -295,7 +295,7 @@ void EasyMesh::ComputeTexCoord(float uv_scale, int uv_offset) | |||
| //full triangle count | |||
| array<int> tri_done; | |||
| array<int> tri_check; | |||
| int tri_count = (m_indices.count() - m_cursors.last().m2) / 3; | |||
| int tri_count = (m_indices.count() - std::get<1>(m_cursors.last())) / 3; | |||
| tri_check << tri_list[0]; | |||
| @@ -326,7 +326,7 @@ void EasyMesh::ComputeTexCoord(float uv_scale, int uv_offset) | |||
| { | |||
| if (uv[j] != vec2(-1.0f)) | |||
| { | |||
| uv[(j + 1) % 2] = uv[j] + vec2(.0f, uv_scale * length(m_vert[v[j]].m1 - m_vert[v[(j + 1) % 3]].m1)); | |||
| uv[(j + 1) % 2] = uv[j] + vec2(.0f, uv_scale * length(std::get<0>(m_vert[v[j]]) - std::get<0>(m_vert[v[(j + 1) % 3]]))); | |||
| uv_set = 2; | |||
| break; | |||
| } | |||
| @@ -1,8 +1,8 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2009—2013 Cédric Lecacheur <jordx@free.fr> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -108,8 +108,8 @@ void GpuShaderData::AddAttribute(VertexUsage usage, int index) | |||
| ShaderUniform const *GpuShaderData::GetUniform(std::string const &uniform) | |||
| { | |||
| for (int i = 0; i < m_shader_uniform.count(); ++i) | |||
| if (m_shader_uniform[i].m1 == uniform) | |||
| return &m_shader_uniform[i].m2; | |||
| if (std::get<0>(m_shader_uniform[i]) == uniform) | |||
| return &std::get<1>(m_shader_uniform[i]); | |||
| return nullptr; | |||
| } | |||
| @@ -292,7 +292,7 @@ void GpuEasyMeshData::AddGpuData(std::shared_ptr<GpuShaderData> gpudata, std::sh | |||
| void GpuEasyMeshData::SetupVertexData(uint16_t vflags, std::shared_ptr<EasyMesh> src_mesh) | |||
| { | |||
| for (int i = 0; i < m_vdata.count(); ++i) | |||
| if (m_vdata[i].m1 == vflags) | |||
| if (std::get<0>(m_vdata[i]) == vflags) | |||
| return; | |||
| std::shared_ptr<VertexDeclaration> new_vdecl; | |||
| @@ -417,15 +417,15 @@ void GpuEasyMeshData::RenderMeshData(mat4 const &model, int render_mode) | |||
| int vdecl_idx = 0; | |||
| for (; vdecl_idx < m_vdata.count(); ++vdecl_idx) | |||
| if (m_vdata[vdecl_idx].m1 == gpu_sd.m_vert_decl_flags) | |||
| if (std::get<0>(m_vdata[vdecl_idx]) == gpu_sd.m_vert_decl_flags) | |||
| break; | |||
| if (vdecl_idx >= m_vdata.count()) | |||
| return; | |||
| uint16_t vflags = m_vdata[vdecl_idx].m1; | |||
| auto vdecl = m_vdata[vdecl_idx].m2; | |||
| auto vbo = m_vdata[vdecl_idx].m3; | |||
| uint16_t vflags = std::get<0>(m_vdata[vdecl_idx]); | |||
| auto vdecl = std::get<1>(m_vdata[vdecl_idx]); | |||
| auto vbo = std::get<2>(m_vdata[vdecl_idx]); | |||
| gpu_sd.m_shader->Bind(); | |||
| gpu_sd.SetupShaderDatas(model); | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2015 Cédric Lecacheur <jordx@free.fr> | |||
| // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| @@ -34,7 +34,7 @@ void EasyMesh::Translate(vec3 const &v) | |||
| return; | |||
| } | |||
| for (int i = m_cursors.last().m1; i < m_vert.count(); i++) | |||
| for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | |||
| m_vert[i].m_coord += v; | |||
| } | |||
| @@ -54,7 +54,7 @@ void EasyMesh::Rotate(float degrees, vec3 const &axis) | |||
| } | |||
| mat3 m = mat3::rotate(radians(degrees), axis); | |||
| for (int i = m_cursors.last().m1; i < m_vert.count(); i++) | |||
| for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | |||
| { | |||
| m_vert[i].m_coord = m * m_vert[i].m_coord; | |||
| m_vert[i].m_normal = m * m_vert[i].m_normal; | |||
| @@ -73,10 +73,10 @@ void EasyMesh::RadialJitter(float r) | |||
| array<int> welded; | |||
| welded.push(-1); | |||
| for (int i = m_cursors.last().m1 + 1; i < m_vert.count(); i++) | |||
| for (int i = std::get<0>(m_cursors.last()) + 1; i < m_vert.count(); i++) | |||
| { | |||
| int j, k; | |||
| for (j = m_cursors.last().m1, k = 0; j < i; j++, k++) | |||
| for (j = std::get<0>(m_cursors.last()), k = 0; j < i; j++, k++) | |||
| { | |||
| if(welded[k] < 0) | |||
| { | |||
| @@ -99,7 +99,7 @@ void EasyMesh::RadialJitter(float r) | |||
| } | |||
| int i, j; | |||
| for (i = m_cursors.last().m1, j = 0; i < m_vert.count(); i++, j++) | |||
| for (i = std::get<0>(m_cursors.last()), j = 0; i < m_vert.count(); i++, j++) | |||
| { | |||
| if(welded[j] == -1) | |||
| m_vert[i].m_coord *= 1.0f + rand(r); | |||
| @@ -107,7 +107,7 @@ void EasyMesh::RadialJitter(float r) | |||
| m_vert[i].m_coord = m_vert[welded[j]].m_coord; | |||
| } | |||
| ComputeNormals(m_cursors.last().m2, m_indices.count() - m_cursors.last().m2); | |||
| ComputeNormals(std::get<1>(m_cursors.last()), m_indices.count() - std::get<1>(m_cursors.last())); | |||
| } | |||
| //----------------------------------------------------------------------------- | |||
| @@ -148,7 +148,7 @@ void EasyMesh::DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n | |||
| return; | |||
| } | |||
| for (int i = m_cursors.last().m1; i < m_vert.count(); i++) | |||
| for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | |||
| { | |||
| switch (ct.ToScalar()) | |||
| { | |||
| @@ -176,9 +176,9 @@ void EasyMesh::DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n | |||
| } | |||
| case MeshTransform::Stretch: | |||
| { | |||
| //float value = abs(m_vert[i].m1[axis0.ToScalar()]); | |||
| //m_vert[i].m1[(axis0.ToScalar() + 1) % 3] += (lol::pow(value, n0) + noff); | |||
| //m_vert[i].m1[(axis0.ToScalar() + 2) % 3] += (lol::pow(value, n1) + noff); | |||
| //float value = abs(std::get<0>(m_vert[i])[axis0.ToScalar()]); | |||
| //std::get<0>(m_vert[i])[(axis0.ToScalar() + 1) % 3] += (lol::pow(value, n0) + noff); | |||
| //std::get<0>(m_vert[i])[(axis0.ToScalar() + 2) % 3] += (lol::pow(value, n1) + noff); | |||
| break; | |||
| } | |||
| case MeshTransform::Bend: | |||
| @@ -189,7 +189,7 @@ void EasyMesh::DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n | |||
| } | |||
| } | |||
| } | |||
| ComputeNormals(m_cursors.last().m2, m_indices.count() - m_cursors.last().m2); | |||
| ComputeNormals(std::get<1>(m_cursors.last()), m_indices.count() - std::get<1>(m_cursors.last())); | |||
| } | |||
| //----------------------------------------------------------------------------- | |||
| @@ -208,7 +208,7 @@ void EasyMesh::Scale(vec3 const &s) | |||
| vec3 const invs = vec3(1) / s; | |||
| for (int i = m_cursors.last().m1; i < m_vert.count(); i++) | |||
| for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | |||
| { | |||
| m_vert[i].m_coord *= s; | |||
| m_vert[i].m_normal = normalize(m_vert[i].m_normal * invs); | |||
| @@ -217,7 +217,7 @@ void EasyMesh::Scale(vec3 const &s) | |||
| /* Flip winding if the scaling involves mirroring */ | |||
| if (!BD()->IsEnabled(MeshBuildOperation::ScaleWinding) && s.x * s.y * s.z < 0) | |||
| { | |||
| for (int i = m_cursors.last().m2; i < m_indices.count(); i += 3) | |||
| for (int i = std::get<1>(m_cursors.last()); i < m_indices.count(); i += 3) | |||
| { | |||
| uint16_t tmp = m_indices[i + 0]; | |||
| m_indices[i + 0] = m_indices[i + 1]; | |||
| @@ -241,26 +241,26 @@ void EasyMesh::DupAndScale(vec3 const &s, bool open_brace) | |||
| return; | |||
| } | |||
| int vlen = m_vert.count() - m_cursors.last().m1; | |||
| int tlen = m_indices.count() - m_cursors.last().m2; | |||
| int vlen = m_vert.count() - std::get<0>(m_cursors.last()); | |||
| int tlen = m_indices.count() - std::get<1>(m_cursors.last()); | |||
| for (int i = 0; i < vlen; i++) | |||
| AddDupVertex(m_cursors.last().m1++); | |||
| AddDupVertex(std::get<0>(m_cursors.last())++); | |||
| for (int i = 0; i < tlen; i++) | |||
| m_indices << m_indices[m_cursors.last().m2++] + vlen; | |||
| m_indices << m_indices[std::get<1>(m_cursors.last())++] + vlen; | |||
| Scale(s); | |||
| m_cursors.last().m1 -= vlen; | |||
| m_cursors.last().m2 -= tlen; | |||
| std::get<0>(m_cursors.last()) -= vlen; | |||
| std::get<1>(m_cursors.last()) -= tlen; | |||
| if (open_brace) | |||
| { | |||
| OpenBrace(); | |||
| m_cursors.last().m1 -= vlen; | |||
| m_cursors.last().m2 -= tlen; | |||
| std::get<0>(m_cursors.last()) -= vlen; | |||
| std::get<1>(m_cursors.last()) -= tlen; | |||
| } | |||
| } | |||
| @@ -274,8 +274,8 @@ void EasyMesh::Chamfer(float f) | |||
| return; | |||
| } | |||
| int vlen = m_vert.count() - m_cursors.last().m1; | |||
| int ilen = m_indices.count() - m_cursors.last().m2; | |||
| int vlen = m_vert.count() - std::get<0>(m_cursors.last()); | |||
| int ilen = m_indices.count() - std::get<1>(m_cursors.last()); | |||
| /* Step 1: enumerate all faces. This is done by merging triangles | |||
| * that are coplanar and share an edge. */ | |||
| @@ -336,7 +336,7 @@ void EasyMesh::SplitTriangles(int pass, VertexDictionnary *vert_dict) | |||
| while (pass--) | |||
| { | |||
| int trimax = m_indices.count(); | |||
| for (int i = m_cursors.last().m2; i < trimax; i += 3) | |||
| for (int i = std::get<1>(m_cursors.last()); i < trimax; i += 3) | |||
| { | |||
| int vbase = m_vert.count(); | |||
| int j = -1; | |||
| @@ -355,7 +355,7 @@ void EasyMesh::SplitTriangles(int pass, VertexDictionnary *vert_dict) | |||
| m_indices[i + 2] = vbase + 2; | |||
| } | |||
| } | |||
| ComputeNormals(m_cursors.last().m2, m_indices.count() - m_cursors.last().m2); | |||
| ComputeNormals(std::get<1>(m_cursors.last()), m_indices.count() - std::get<1>(m_cursors.last())); | |||
| } | |||
| //----------------------------------------------------------------------------- | |||
| @@ -377,7 +377,7 @@ void EasyMesh::SmoothMesh(int main_pass, int split_per_main_pass, int smooth_per | |||
| array<int> connected_vert; | |||
| int smbuf = 0; | |||
| for (int i = m_cursors.last().m1; i < m_vert.count(); i++) | |||
| for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | |||
| vert_dict.RegisterVertex(i, m_vert[i].m_coord); | |||
| while (main_pass--) | |||
| @@ -387,13 +387,13 @@ void EasyMesh::SmoothMesh(int main_pass, int split_per_main_pass, int smooth_per | |||
| SplitTriangles(split_pass, &vert_dict); | |||
| matching_ids.reserve(m_vert.count() - m_cursors.last().m1); | |||
| connected_vert.reserve(m_vert.count() - m_cursors.last().m1); | |||
| smooth_buf[0].resize(m_vert.count() - m_cursors.last().m1); | |||
| smooth_buf[1].resize(m_vert.count() - m_cursors.last().m1); | |||
| matching_ids.reserve(m_vert.count() - std::get<0>(m_cursors.last())); | |||
| connected_vert.reserve(m_vert.count() - std::get<0>(m_cursors.last())); | |||
| smooth_buf[0].resize(m_vert.count() - std::get<0>(m_cursors.last())); | |||
| smooth_buf[1].resize(m_vert.count() - std::get<0>(m_cursors.last())); | |||
| for (int i = m_cursors.last().m1; i < m_vert.count(); i++) | |||
| smooth_buf[smbuf][i - m_cursors.last().m1] = m_vert[i].m_coord; | |||
| for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | |||
| smooth_buf[smbuf][i - std::get<0>(m_cursors.last())] = m_vert[i].m_coord; | |||
| while (smooth_pass--) | |||
| { | |||
| @@ -403,12 +403,12 @@ void EasyMesh::SmoothMesh(int main_pass, int split_per_main_pass, int smooth_per | |||
| for (int i = 0; i < master_list.count(); i++) | |||
| { | |||
| connected_vert.clear(); | |||
| if (vert_dict.FindConnectedVertices(master_list[i], m_indices, m_cursors.last().m2, connected_vert)) | |||
| if (vert_dict.FindConnectedVertices(master_list[i], m_indices, std::get<1>(m_cursors.last()), connected_vert)) | |||
| { | |||
| //Calculate vertices sum | |||
| vec3 vert_sum = vec3(.0f); | |||
| for (int j = 0; j < connected_vert.count(); j++) | |||
| vert_sum += smooth_buf[smbuf][connected_vert[j] - m_cursors.last().m1]; | |||
| vert_sum += smooth_buf[smbuf][connected_vert[j] - std::get<0>(m_cursors.last())]; | |||
| //Calculate new master vertex | |||
| float n = (float)connected_vert.count(); | |||
| @@ -418,14 +418,14 @@ void EasyMesh::SmoothMesh(int main_pass, int split_per_main_pass, int smooth_per | |||
| //a(n) = n * (1 - b(n)) / b(n) | |||
| float alpha = (n * (1 - beta)) / beta; | |||
| //V = (a(n) * v + v1 + ... + vn) / (a(n) + n) | |||
| vec3 new_vert = (alpha * smooth_buf[smbuf][master_list[i] - m_cursors.last().m1] + vert_sum) / (alpha + n); | |||
| vec3 new_vert = (alpha * smooth_buf[smbuf][master_list[i] - std::get<0>(m_cursors.last())] + vert_sum) / (alpha + n); | |||
| //Set all matching vertices to new value | |||
| matching_ids.clear(); | |||
| matching_ids << master_list[i]; | |||
| vert_dict.FindMatchingVertices(master_list[i], matching_ids); | |||
| for (int j = 0; j < matching_ids.count(); j++) | |||
| smooth_buf[1 - smbuf][matching_ids[j] - m_cursors.last().m1] = new_vert; | |||
| smooth_buf[1 - smbuf][matching_ids[j] - std::get<0>(m_cursors.last())] = new_vert; | |||
| } | |||
| } | |||
| } | |||
| @@ -433,7 +433,7 @@ void EasyMesh::SmoothMesh(int main_pass, int split_per_main_pass, int smooth_per | |||
| } | |||
| for (int i = 0; i < smooth_buf[smbuf].count(); i++) | |||
| m_vert[i + m_cursors.last().m1].m_coord = smooth_buf[smbuf][i]; | |||
| m_vert[i + std::get<0>(m_cursors.last())].m_coord = smooth_buf[smbuf][i]; | |||
| } | |||
| } | |||
| @@ -1,8 +1,8 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2009—2014 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||
| // 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 | |||
| @@ -253,8 +253,8 @@ ResourceCodecData* ZedImageCodec::Load(std::string const &path) | |||
| compacter.m_primary[j].m_count--; | |||
| int i = compacter.m_primary[j].m_secondary[k].m_tiles.pop(); | |||
| int32_t file_off = tiles[i].m1[0]; | |||
| ivec2 t_size = tiles[i].m2; | |||
| 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); | |||
| @@ -275,7 +275,7 @@ ResourceCodecData* ZedImageCodec::Load(std::string const &path) | |||
| } | |||
| //Register new pos and move to next | |||
| tiles[i].m1 = pos; | |||
| std::get<0>(tiles[i]) = pos; | |||
| pos.x += t_size.x; | |||
| } | |||
| } | |||
| @@ -245,7 +245,6 @@ | |||
| <ClInclude Include="lol\base\array.h" /> | |||
| <ClInclude Include="lol\base\enum.h" /> | |||
| <ClInclude Include="lol\base\log.h" /> | |||
| <ClInclude Include="lol\base\tuple.h" /> | |||
| <ClInclude Include="lol\debug\all.h" /> | |||
| <ClInclude Include="lol\debug\lines.h" /> | |||
| <ClInclude Include="lol\engine\all.h" /> | |||
| @@ -323,9 +323,6 @@ | |||
| <ClInclude Include="lol\base\log.h"> | |||
| <Filter>lol\base</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="lol\base\tuple.h"> | |||
| <Filter>lol\base</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="lol\debug\all.h"> | |||
| <Filter>lol\debug</Filter> | |||
| </ClInclude> | |||
| @@ -15,7 +15,6 @@ | |||
| #include <../legacy/lol/base/types.h> | |||
| #include <lol/base/log.h> | |||
| #include <../legacy/lol/base/assert.h> | |||
| #include <lol/base/tuple.h> | |||
| #include <lol/base/array.h> | |||
| #include <../legacy/lol/base/avl_tree.h> | |||
| #include <lol/base/utils.h> | |||
| @@ -20,11 +20,10 @@ | |||
| // additional features, eg. array<int,float> for automatic arrays of tuples. | |||
| // | |||
| #include <lol/base/tuple.h> | |||
| #include <cassert> // assert() | |||
| #include <new> // placement new | |||
| #include <algorithm> // std::swap | |||
| #include <tuple> // std::tuple | |||
| #include <stdint.h> | |||
| #include <initializer_list> | |||
| @@ -463,15 +462,15 @@ protected: | |||
| */ | |||
| template<typename... T> | |||
| class array : public array_base<tuple<T...>, array<T...>> | |||
| class array : public array_base<std::tuple<T...>, array<T...>> | |||
| { | |||
| public: | |||
| /* GCC needs this but Clang doesn’t */ | |||
| typedef tuple<T...> element_t; | |||
| typedef std::tuple<T...> element_t; | |||
| #if LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS | |||
| private: | |||
| using array_base<tuple<T...>, array<T...>>::array_base; | |||
| using array_base<std::tuple<T...>, array<T...>>::array_base; | |||
| #else | |||
| public: | |||
| inline array() | |||
| @@ -488,13 +487,13 @@ public: | |||
| { | |||
| if (this->m_count >= this->m_reserved) | |||
| { | |||
| tuple<T...> tmp = { args... }; | |||
| std::tuple<T...> tmp = { args... }; | |||
| this->grow(); | |||
| new (&this->m_data[this->m_count]) tuple<T...>(tmp); | |||
| new (&this->m_data[this->m_count]) std::tuple<T...>(tmp); | |||
| } | |||
| else | |||
| { | |||
| new (&this->m_data[this->m_count]) tuple<T...>({ args... }); | |||
| new (&this->m_data[this->m_count]) std::tuple<T...>({ args... }); | |||
| } | |||
| ++this->m_count; | |||
| } | |||
| @@ -511,7 +510,7 @@ public: | |||
| new (&this->m_data[i]) element_t(this->m_data[i - 1]); | |||
| this->m_data[i - 1].~element_t(); | |||
| } | |||
| new (&this->m_data[pos]) tuple<T...>({ args... }); | |||
| new (&this->m_data[pos]) std::tuple<T...>({ args... }); | |||
| ++this->m_count; | |||
| } | |||
| }; | |||
| @@ -1,92 +0,0 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2013—2015 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. | |||
| // | |||
| #pragma once | |||
| // | |||
| // The tuple class | |||
| // --------------- | |||
| // A very simple tuple class. | |||
| // | |||
| #include <tuple> | |||
| namespace lol | |||
| { | |||
| template<typename... T> | |||
| class tuple : public std::tuple<T...> | |||
| { | |||
| }; | |||
| template<typename T1, typename T2, typename T3, typename T4, typename T5, | |||
| typename T6, typename T7, typename T8> | |||
| class tuple<T1, T2, T3, T4, T5, T6, T7, T8> | |||
| { | |||
| public: | |||
| T1 m1; T2 m2; T3 m3; T4 m4; T5 m5; T6 m6; T7 m7; T8 m8; | |||
| }; | |||
| template<typename T1, typename T2, typename T3, typename T4, typename T5, | |||
| typename T6, typename T7> | |||
| class tuple<T1, T2, T3, T4, T5, T6, T7> | |||
| { | |||
| public: | |||
| T1 m1; T2 m2; T3 m3; T4 m4; T5 m5; T6 m6; T7 m7; | |||
| }; | |||
| template<typename T1, typename T2, typename T3, typename T4, typename T5, | |||
| typename T6> | |||
| class tuple<T1, T2, T3, T4, T5, T6> | |||
| { | |||
| public: | |||
| T1 m1; T2 m2; T3 m3; T4 m4; T5 m5; T6 m6; | |||
| }; | |||
| template<typename T1, typename T2, typename T3, typename T4, typename T5> | |||
| class tuple<T1, T2, T3, T4, T5> | |||
| { | |||
| public: | |||
| T1 m1; T2 m2; T3 m3; T4 m4; T5 m5; | |||
| }; | |||
| template<typename T1, typename T2, typename T3, typename T4> | |||
| class tuple<T1, T2, T3, T4> | |||
| { | |||
| public: | |||
| T1 m1; T2 m2; T3 m3; T4 m4; | |||
| }; | |||
| template<typename T1, typename T2, typename T3> | |||
| class tuple<T1, T2, T3> | |||
| { | |||
| public: | |||
| T1 m1; T2 m2; T3 m3; | |||
| }; | |||
| template<typename T1, typename T2> | |||
| class tuple<T1, T2> | |||
| { | |||
| public: | |||
| T1 m1; T2 m2; | |||
| }; | |||
| template<typename T1> | |||
| class tuple<T1> | |||
| { | |||
| public: | |||
| T1 m1; | |||
| }; | |||
| } /* namespace lol */ | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2017—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2017—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -121,6 +121,7 @@ Loader::~Loader() | |||
| } | |||
| //Store loader ------------------------------------------------------------ | |||
| // FIXME: change this to a map? | |||
| static array<lua_State*, Lolua::Loader*> g_loaders; | |||
| void Loader::Store(lua_State* l, Lolua::Loader* loader) | |||
| @@ -132,7 +133,7 @@ void Loader::Release(lua_State* l, Lolua::Loader* loader) | |||
| { | |||
| for (int i = 0; i < g_loaders.count(); ++i) | |||
| { | |||
| if (g_loaders[i].m1 == l && g_loaders[i].m2 == loader) | |||
| if (std::get<0>(g_loaders[i]) == l && std::get<1>(g_loaders[i]) == loader) | |||
| { | |||
| g_loaders.remove(i); | |||
| return; | |||
| @@ -145,9 +146,9 @@ void Loader::StoreObject(lua_State* l, Object* obj) | |||
| { | |||
| for (auto loader : g_loaders) | |||
| { | |||
| if (loader.m1 == l) | |||
| if (std::get<0>(loader) == l) | |||
| { | |||
| loader.m2->Store(obj); | |||
| std::get<1>(loader)->Store(obj); | |||
| return; | |||
| } | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 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 | |||
| @@ -140,8 +140,8 @@ void SubMesh::Render() | |||
| for (int i = 0; i < m_textures.count(); ++i) | |||
| { | |||
| // TODO: might be good to cache this | |||
| ShaderUniform u_tex = m_shader->GetUniformLocation(m_textures[i].m1); | |||
| m_shader->SetUniform(u_tex, m_textures[i].m2->GetTextureUniform(), i); | |||
| ShaderUniform u_tex = m_shader->GetUniformLocation(std::get<0>(m_textures[i])); | |||
| m_shader->SetUniform(u_tex, std::get<1>(m_textures[i])->GetTextureUniform(), i); | |||
| } | |||
| m_ibo->Bind(); | |||
| @@ -410,12 +410,14 @@ void Scene::AddTile(TileSet *tileset, int id, mat4 model) | |||
| void Scene::AddLine(vec3 a, vec3 b, vec4 col) | |||
| { | |||
| m_line_api.m_lines.push(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); | |||
| } | |||
| void Scene::AddLine(vec3 a, vec3 b, vec4 col, float duration, int mask) | |||
| { | |||
| m_line_api.m_lines.push(a, b, col, duration, mask, false, false); | |||
| struct line l { a, b, col, duration, mask, false, false }; | |||
| m_line_api.m_lines.push(l); | |||
| } | |||
| void Scene::AddLight(Light *l) | |||
| @@ -716,16 +718,16 @@ void Scene::render_lines(float seconds) | |||
| UNUSED(inv_view_proj); | |||
| for (int i = 0; i < linecount; i++) | |||
| { | |||
| if (m_line_api.m_lines[i].m5 & m_line_api.m_debug_mask) | |||
| if (m_line_api.m_lines[i].mask & m_line_api.m_debug_mask) | |||
| { | |||
| buff[real_linecount].m1 = vec4(m_line_api.m_lines[i].m1, (float)m_line_api.m_lines[i].m6); | |||
| buff[real_linecount].m2 = m_line_api.m_lines[i].m3; | |||
| buff[real_linecount].m3 = vec4(m_line_api.m_lines[i].m2, (float)m_line_api.m_lines[i].m7); | |||
| buff[real_linecount].m4 = m_line_api.m_lines[i].m3; | |||
| std::get<0>(buff[real_linecount]) = vec4(m_line_api.m_lines[i].a, (float)m_line_api.m_lines[i].wtf1); | |||
| std::get<1>(buff[real_linecount]) = m_line_api.m_lines[i].col; | |||
| std::get<2>(buff[real_linecount]) = vec4(m_line_api.m_lines[i].b, (float)m_line_api.m_lines[i].wtf2); | |||
| std::get<3>(buff[real_linecount]) = m_line_api.m_lines[i].col; | |||
| real_linecount++; | |||
| } | |||
| m_line_api.m_lines[i].m4 -= seconds; | |||
| if (m_line_api.m_lines[i].m4 < 0.f) | |||
| m_line_api.m_lines[i].duration -= seconds; | |||
| if (m_line_api.m_lines[i].duration < 0.f) | |||
| { | |||
| m_line_api.m_lines.remove_swap(i--); | |||
| linecount--; | |||
| @@ -310,12 +310,21 @@ private: | |||
| Camera *m_default_cam; | |||
| array<Camera *> m_camera_stack; | |||
| struct line | |||
| { | |||
| vec3 a, b; | |||
| vec4 col; | |||
| float duration; | |||
| uint32_t mask; | |||
| bool wtf1, wtf2; // FIXME: document this | |||
| }; | |||
| /* Old line API <P0, P1, COLOR, TIME, MASK> */ | |||
| struct line_api | |||
| { | |||
| //float m_duration, m_segment_size; | |||
| //vec4 m_color; | |||
| array<vec3, vec3, vec4, float, int, bool, bool> m_lines; | |||
| array<line> m_lines; | |||
| int /*m_mask,*/ m_debug_mask; | |||
| std::shared_ptr<Shader> m_shader; | |||
| std::shared_ptr<VertexDeclaration> m_vdecl; | |||
| @@ -66,12 +66,12 @@ lolunit_declare_fixture(array_test) | |||
| { 4, 5.0f }, | |||
| { 6, 7.0f } }; | |||
| lolunit_assert_equal(c[0].m1, 2); | |||
| lolunit_assert_equal(c[0].m2, 3.0f); | |||
| lolunit_assert_equal(c[1].m1, 4); | |||
| lolunit_assert_equal(c[1].m2, 5.0f); | |||
| lolunit_assert_equal(c[2].m1, 6); | |||
| lolunit_assert_equal(c[2].m2, 7.0f); | |||
| lolunit_assert_equal(std::get<0>(c[0]), 2); | |||
| lolunit_assert_equal(std::get<1>(c[0]), 3.0f); | |||
| lolunit_assert_equal(std::get<0>(c[1]), 4); | |||
| lolunit_assert_equal(std::get<1>(c[1]), 5.0f); | |||
| lolunit_assert_equal(std::get<0>(c[2]), 6); | |||
| lolunit_assert_equal(std::get<1>(c[2]), 7.0f); | |||
| } | |||
| lolunit_declare_test(array_push_with_shift) | |||
| @@ -144,14 +144,14 @@ lolunit_declare_fixture(array_test) | |||
| array<int, long, float, double, unsigned, char, bool, void *> a; | |||
| a.push(1, 2, 3.f, 4.0, 5, 'a', true, 0); | |||
| lolunit_assert_equal(a[0].m1, 1); | |||
| lolunit_assert_equal(a[0].m2, 2); | |||
| lolunit_assert_equal(a[0].m3, 3.f); | |||
| lolunit_assert_equal(a[0].m4, 4.0); | |||
| lolunit_assert_equal(a[0].m5, 5); | |||
| lolunit_assert_equal(a[0].m6, 'a'); | |||
| lolunit_assert_equal(a[0].m7, true); | |||
| lolunit_assert_equal(a[0].m8, 0); | |||
| lolunit_assert_equal(std::get<0>(a[0]), 1); | |||
| lolunit_assert_equal(std::get<1>(a[0]), 2); | |||
| lolunit_assert_equal(std::get<2>(a[0]), 3.f); | |||
| lolunit_assert_equal(std::get<3>(a[0]), 4.0); | |||
| lolunit_assert_equal(std::get<4>(a[0]), 5); | |||
| lolunit_assert_equal(std::get<5>(a[0]), 'a'); | |||
| lolunit_assert_equal(std::get<6>(a[0]), true); | |||
| lolunit_assert_equal(std::get<7>(a[0]), 0); | |||
| } | |||
| lolunit_declare_test(array_swap) | |||
| @@ -162,10 +162,10 @@ lolunit_declare_fixture(array_test) | |||
| a.swap(0, 1); | |||
| lolunit_assert_equal(30, a[0].m1); | |||
| lolunit_assert_equal(40, a[0].m2); | |||
| lolunit_assert_equal(10, a[1].m1); | |||
| lolunit_assert_equal(20, a[1].m2); | |||
| lolunit_assert_equal(30, std::get<0>(a[0])); | |||
| lolunit_assert_equal(40, std::get<1>(a[0])); | |||
| lolunit_assert_equal(10, std::get<0>(a[1])); | |||
| lolunit_assert_equal(20, std::get<1>(a[1])); | |||
| } | |||
| lolunit_declare_test(array_insert) | |||
| @@ -196,22 +196,22 @@ lolunit_declare_fixture(array_test) | |||
| { | |||
| array<int, float, std::string> b; | |||
| b.insert(0, 5, 6.f, "lol"); | |||
| lolunit_assert_equal(5, b[0].m1); | |||
| lolunit_assert_equal(6.f, b[0].m2); | |||
| lolunit_assert_equal(5, std::get<0>(b[0])); | |||
| lolunit_assert_equal(6.f, std::get<1>(b[0])); | |||
| b.insert(1, 8, 9.f, "hi there"); | |||
| lolunit_assert_equal(5, b[0].m1); | |||
| lolunit_assert_equal(6.f, b[0].m2); | |||
| lolunit_assert_equal(8, b[1].m1); | |||
| lolunit_assert_equal(9.f, b[1].m2); | |||
| lolunit_assert_equal(5, std::get<0>(b[0])); | |||
| lolunit_assert_equal(6.f, std::get<1>(b[0])); | |||
| lolunit_assert_equal(8, std::get<0>(b[1])); | |||
| lolunit_assert_equal(9.f, std::get<1>(b[1])); | |||
| b.insert(1, 4, 5.f, "anyone home?"); | |||
| lolunit_assert_equal(5, b[0].m1); | |||
| lolunit_assert_equal(6.f, b[0].m2); | |||
| lolunit_assert_equal(4, b[1].m1); | |||
| lolunit_assert_equal(5.f, b[1].m2); | |||
| lolunit_assert_equal(8, b[2].m1); | |||
| lolunit_assert_equal(9.f, b[2].m2); | |||
| lolunit_assert_equal(5, std::get<0>(b[0])); | |||
| lolunit_assert_equal(6.f, std::get<1>(b[0])); | |||
| lolunit_assert_equal(4, std::get<0>(b[1])); | |||
| lolunit_assert_equal(5.f, std::get<1>(b[1])); | |||
| lolunit_assert_equal(8, std::get<0>(b[2])); | |||
| lolunit_assert_equal(9.f, std::get<1>(b[2])); | |||
| } | |||
| lolunit_declare_test(array_concat) | |||
| @@ -21,6 +21,8 @@ | |||
| #include <../legacy/lol/math/functions.h> // radians() | |||
| #include <cstring> // memset | |||
| #include <tuple> // std::tuple | |||
| #include <vector> // std::vector | |||
| namespace lol | |||
| { | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 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 | |||
| @@ -219,7 +219,11 @@ void TileSet::define_tile(array<ibox2>& tiles) | |||
| void TileSet::define_tile(array<ivec2, ivec2>& tiles) | |||
| { | |||
| for (int i = 0; i < tiles.count(); i++) | |||
| define_tile(ibox2(tiles[i].m1, tiles[i].m1 + tiles[i].m2)); | |||
| { | |||
| auto const &a = std::get<0>(tiles[i]); | |||
| auto const &b = std::get<1>(tiles[i]); | |||
| define_tile(ibox2(a, a + b)); | |||
| } | |||
| } | |||
| int TileSet::GetTileCount() const | |||
| @@ -229,17 +233,17 @@ int TileSet::GetTileCount() const | |||
| ivec2 TileSet::GetTileSize(int tileid) const | |||
| { | |||
| return m_tileset_data->m_tiles[tileid].m1.extent(); | |||
| return std::get<0>(m_tileset_data->m_tiles[tileid]).extent(); | |||
| } | |||
| ibox2 TileSet::GetTilePixel(int tileid) const | |||
| { | |||
| return m_tileset_data->m_tiles[tileid].m1; | |||
| return std::get<0>(m_tileset_data->m_tiles[tileid]); | |||
| } | |||
| box2 TileSet::GetTileTexel(int tileid) const | |||
| { | |||
| return m_tileset_data->m_tiles[tileid].m2; | |||
| return std::get<1>(m_tileset_data->m_tiles[tileid]); | |||
| } | |||
| //Palette --------------------------------------------------------------------- | |||
| @@ -260,8 +264,8 @@ TileSet const* TileSet::GetPalette() const | |||
| void TileSet::BlitTile(uint32_t id, mat4 model, vec3 *vertex, vec2 *texture) | |||
| { | |||
| ibox2 pixels = m_tileset_data->m_tiles[id].m1; | |||
| box2 texels = m_tileset_data->m_tiles[id].m2; | |||
| ibox2 pixels = std::get<0>(m_tileset_data->m_tiles[id]); | |||
| box2 texels = std::get<1>(m_tileset_data->m_tiles[id]); | |||
| float dtx = texels.extent().x; | |||
| float dty = texels.extent().y; | |||
| float tx = texels.aa.x; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 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 | |||
| @@ -94,10 +94,10 @@ void D3d9Input::tick_game(float seconds) | |||
| for (int i = 0; i < m_data->m_joysticks.count(); i++) | |||
| { | |||
| XINPUT_STATE state; | |||
| if (XInputGetState(m_data->m_joysticks[i].m1, &state) != ERROR_SUCCESS) | |||
| if (XInputGetState(std::get<0>(m_data->m_joysticks[i]), &state) != ERROR_SUCCESS) | |||
| continue; | |||
| auto stick = m_data->m_joysticks[i].m2; | |||
| auto stick = std::get<1>(m_data->m_joysticks[i]); | |||
| stick->internal_begin_frame(); | |||
| stick->internal_set_axis(input::axis::LeftX, state.Gamepad.sThumbLX / 32768.f); | |||
| stick->internal_set_axis(input::axis::LeftY, -state.Gamepad.sThumbLY / 32768.f); | |||
| @@ -114,7 +114,7 @@ void D3d9Input::tick_game(float seconds) | |||
| int key_index = (1 << b) > XINPUT_GAMEPAD_RIGHT_SHOULDER ? b - 2 : b; | |||
| m_data->m_joysticks[i].m2->internal_set_button((input::button)key_index, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1); | |||
| std::get<1>(m_data->m_joysticks[i])->internal_set_button((input::button)key_index, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1); | |||
| } | |||
| } | |||
| #endif | |||
| @@ -104,7 +104,7 @@ SdlInput::~SdlInput() | |||
| /* Unregister all the joysticks we added */ | |||
| while (m_joysticks.count()) | |||
| { | |||
| SDL_JoystickClose(m_joysticks[0].m1); | |||
| SDL_JoystickClose(std::get<0>(m_joysticks[0])); | |||
| m_joysticks.remove(0); | |||
| } | |||
| #endif | |||
| @@ -150,17 +150,17 @@ void SdlInput::tick(float seconds) | |||
| keyboard->internal_begin_frame(); | |||
| mouse->internal_begin_frame(); | |||
| for (int j = 0; j < m_joysticks.count(); j++) | |||
| m_joysticks[j].m2->internal_begin_frame(); | |||
| std::get<1>(m_joysticks[j])->internal_begin_frame(); | |||
| /* Pump all joystick events because no event is coming to us. */ | |||
| # if SDL_FORCE_POLL_JOYSTICK && !__EMSCRIPTEN__ | |||
| SDL_JoystickUpdate(); | |||
| for (int j = 0; j < m_joysticks.count(); j++) | |||
| { | |||
| for (int i = 0; i < SDL_JoystickNumButtons(m_joysticks[j].m1); i++) | |||
| m_joysticks[j].m2->internal_set_button((input::button)i, SDL_JoystickGetButton(m_joysticks[j].m1, i) != 0); | |||
| for (int i = 0; i < SDL_JoystickNumAxes(m_joysticks[j].m1); i++) | |||
| m_joysticks[j].m2->internal_set_axis((input::axis)i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f); | |||
| for (int i = 0; i < SDL_JoystickNumButtons(std::get<0>(m_joysticks[j])); i++) | |||
| std::get<1>(m_joysticks[j])->internal_set_button((input::button)i, SDL_JoystickGetButton(std::get<0>(m_joysticks[j]), i) != 0); | |||
| for (int i = 0; i < SDL_JoystickNumAxes(std::get<0>(m_joysticks[j])); i++) | |||
| std::get<1>(m_joysticks[j])->internal_set_axis((input::axis)i, (float)SDL_JoystickGetAxis(std::get<0>(m_joysticks[j]), i) / 32768.f); | |||
| } | |||
| # endif | |||
| @@ -253,12 +253,12 @@ void SdlInput::tick(float seconds) | |||
| # if !SDL_FORCE_POLL_JOYSTICK | |||
| case SDL_JOYAXISMOTION: | |||
| m_joysticks[event.jaxis.which].m2->internal_set_axis(event.jaxis.axis, (float)event.jaxis.value / 32768.f); | |||
| std::get<1>(m_joysticks[event.jaxis.which])->internal_set_axis(event.jaxis.axis, (float)event.jaxis.value / 32768.f); | |||
| break; | |||
| case SDL_JOYBUTTONUP: | |||
| case SDL_JOYBUTTONDOWN: | |||
| m_joysticks[event.jbutton.which].m2->internal_set_key(event.jbutton.button, event.jbutton.state); | |||
| std::get<1>(m_joysticks[event.jbutton.which])->internal_set_key(event.jbutton.button, event.jbutton.state); | |||
| break; | |||
| # endif | |||
| } | |||