From 0f5913edce570011eefcb7e13f490e490cfdf9ad Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 9 Mar 2020 13:55:54 +0100 Subject: [PATCH] base: deprecate lol::array. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unfortunately, easymesh code still relies heavily on its specifics, so I’m letting it live as lol::easy_array for the near future. But it’s going away. --- doc/samples/btphystest.cpp | 116 +++++++++--------- doc/samples/btphystest.h | 43 +++---- doc/samples/physicobject.h | 90 +++++++------- doc/samples/physics/easyphysics.cpp | 6 +- doc/samples/physics/easyphysics.h | 49 ++++---- doc/samples/physics/lolphysics.h | 88 ++++++------- doc/tutorial/01_triangle.cpp | 8 +- doc/tutorial/02_cube.cpp | 18 +-- doc/tutorial/03_noise.cpp | 8 +- doc/tutorial/04_texture.cpp | 19 +-- doc/tutorial/05_easymesh.cpp | 18 +-- doc/tutorial/06_sprite.cpp | 6 +- doc/tutorial/07_input.cpp | 18 +-- doc/tutorial/08_fbo.cpp | 8 +- doc/tutorial/11_fractal.cpp | 4 +- doc/tutorial/12_voronoi.cpp | 80 ++++++------ lol-core | 2 +- src/Makefile.am | 11 +- src/base/log.cpp | 4 +- src/commandstack.h | 29 ++--- src/easymesh/csgbsp.cpp | 24 ++-- src/easymesh/csgbsp.h | 26 ++-- .../base/array.h => easymesh/easyarray.h} | 43 +++---- src/easymesh/easymesh.h | 13 +- src/easymesh/easymeshbuild.cpp | 14 +-- src/easymesh/easymeshbuild.h | 24 ++-- src/easymesh/easymeshcsg.cpp | 12 +- src/easymesh/easymeshinternal.cpp | 18 +-- src/easymesh/easymeshlua.cpp | 8 +- src/easymesh/easymeshlua.h | 6 +- src/easymesh/easymeshprimitive.cpp | 2 +- src/easymesh/easymeshrender.h | 10 +- src/easymesh/easymeshtransform.cpp | 10 +- src/engine/ticker.cpp | 49 ++++---- src/image/codec/oric-image.cpp | 21 ++-- src/image/filter/convolution.cpp | 22 ++-- src/image/kernel.cpp | 3 +- src/image/resample.cpp | 8 +- src/image/resource-private.h | 13 +- src/image/resource.cpp | 4 +- src/lol-core.vcxproj | 3 +- src/lol-core.vcxproj.filters | 7 +- src/lol/base/all.h | 1 - src/lol/extras.h | 3 +- src/lolua/baselua.cpp | 8 +- src/lolua/baselua.h | 60 +++++---- src/mesh/mesh.cpp | 15 +-- src/mesh/mesh.h | 8 +- src/messageservice.cpp | 26 ++-- src/messageservice.h | 6 +- src/numeric.h | 5 +- src/t/base/array.cpp | 46 +++---- src/ui/d3d9-input.cpp | 18 +-- src/ui/gui.cpp | 8 +- src/ui/gui.h | 4 +- src/ui/sdl-input.cpp | 24 ++-- src/ui/sdl-input.h | 6 +- src/utils.h | 76 ------------ 58 files changed, 615 insertions(+), 664 deletions(-) rename src/{lol/base/array.h => easymesh/easyarray.h} (92%) delete mode 100644 src/utils.h diff --git a/doc/samples/btphystest.cpp b/doc/samples/btphystest.cpp index 8bb4dc91..f77e2867 100644 --- a/doc/samples/btphystest.cpp +++ b/doc/samples/btphystest.cpp @@ -135,7 +135,7 @@ void BtPhysTest::InitApp() PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3); Ticker::Ref(NewPhyobj); - m_stairs_list << NewPhyobj; + m_stairs_list.push_back(NewPhyobj); } { NewRotation = quat::fromeuler_xyz(0.f, 0.f, radians(40.f)); @@ -143,7 +143,7 @@ void BtPhysTest::InitApp() PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3); Ticker::Ref(NewPhyobj); - m_stairs_list << NewPhyobj; + m_stairs_list.push_back(NewPhyobj); } NewPosition = pos_offset + vec3(5.0f, -29.5f, 15.0f); NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f); @@ -153,7 +153,7 @@ void BtPhysTest::InitApp() PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3); Ticker::Ref(NewPhyobj); - m_stairs_list << NewPhyobj; + m_stairs_list.push_back(NewPhyobj); } } #endif //USE_STAIRS @@ -181,7 +181,7 @@ void BtPhysTest::InitApp() NewPhyobj->SetTransform(NewPosition, NewRotation); Ticker::Ref(NewPhyobj); - m_ground_list << NewPhyobj; + m_ground_list.push_back(NewPhyobj); } } #endif //USE_WALL @@ -194,7 +194,7 @@ void BtPhysTest::InitApp() PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); - m_platform_list << NewPhyobj; + m_platform_list.push_back(NewPhyobj); Ticker::Ref(NewPhyobj); NewPosition = pos_offset + vec3(-15.0f, -25.0f, 5.0f); @@ -202,7 +202,7 @@ void BtPhysTest::InitApp() NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); BasePhyobj = NewPhyobj; - m_platform_list << NewPhyobj; + m_platform_list.push_back(NewPhyobj); Ticker::Ref(NewPhyobj); NewRotation = quat::fromeuler_xyz(0.f, 0.f, radians(90.f)); @@ -211,21 +211,21 @@ void BtPhysTest::InitApp() NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, true); - m_platform_list << NewPhyobj; + m_platform_list.push_back(NewPhyobj); Ticker::Ref(NewPhyobj); //NewPosition += vec3(-0.0f, .0f, .0f); //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, false); - //m_platform_list << NewPhyobj; + //m_platform_list.push_back(NewPhyobj); //Ticker::Ref(NewPhyobj); //NewPosition += vec3(-2.0f, .0f, .0f); //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), false, false); - //m_platform_list << NewPhyobj; + //m_platform_list.push_back(NewPhyobj); //Ticker::Ref(NewPhyobj); } #endif //USE_PLATFORM @@ -237,7 +237,7 @@ void BtPhysTest::InitApp() PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2); - m_character_list << NewPhyobj; + m_character_list.push_back(NewPhyobj); Ticker::Ref(NewPhyobj); //NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true); @@ -259,7 +259,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(animated_object { new_physobj, ZERO_TIME }); + m_physobj_list.push_back(animated_object { new_physobj, ZERO_TIME }); Ticker::Ref(new_physobj); } } @@ -269,16 +269,16 @@ void BtPhysTest::InitApp() #if USE_ROPE { - array RopeElements; + std::vector RopeElements; for (int i = 0; i < 14; i++) { PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 1000.f, vec3(0.f, 15.f, -20.f) + vec3(0.f, 0.f, 2.f * (float)i), 1); - RopeElements << new_physobj; - m_physobj_list.push(new_physobj, ZERO_TIME); + RopeElements.push_back(new_physobj); + m_physobj_list.push_back(animated_object { new_physobj, ZERO_TIME }); Ticker::Ref(new_physobj); - if (RopeElements.count() > 1) + if (RopeElements.size() > 1) { EasyConstraint* new_constraint = new EasyConstraint(); @@ -289,7 +289,7 @@ void BtPhysTest::InitApp() new_constraint->InitConstraintToPoint2Point(); new_constraint->DisableCollisionBetweenObjs(true); new_constraint->AddToSimulation(m_simulation); - m_constraint_list << new_constraint; + m_constraint_list.push_back(new_constraint); } } } @@ -309,67 +309,73 @@ BtPhysTest::~BtPhysTest() Tiler::Deregister(m_cat_texture); #endif //CAT_MODE - while (m_constraint_list.count()) + while (m_constraint_list.size()) { - EasyConstraint* CurPop = m_constraint_list.last(); - m_constraint_list.pop(); + EasyConstraint* CurPop = m_constraint_list.back(); + m_constraint_list.pop_back(); CurPop->RemoveFromSimulation(m_simulation); delete CurPop; } - array objects - = m_ground_list - + m_stairs_list - + m_character_list - + m_platform_list; - while (m_physobj_list.count()) + std::vector objects; + for (auto *obj : m_ground_list) + objects.push_back(obj); + for (auto *obj : m_stairs_list) + objects.push_back(obj); + for (auto *obj : m_character_list) + objects.push_back(obj); + for (auto *obj : m_platform_list) + objects.push_back(obj); + // Back insertion; is this really necessary? + while (m_physobj_list.size()) { - objects << m_physobj_list.last().obj; - m_physobj_list.pop(); + objects.push_back(m_physobj_list.back().obj); + m_physobj_list.pop_back(); } m_ground_list.clear(); m_stairs_list.clear(); m_character_list.clear(); m_platform_list.clear(); - while (objects.count()) + while (objects.size()) { - PhysicsObject* CurPop = objects.pop(); + PhysicsObject* CurPop = objects.back(); + objects.pop_back(); CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); Ticker::Unref(CurPop); } - //while (m_ground_list.count()) + //while (m_ground_list.size()) //{ - // PhysicsObject* CurPop = m_ground_list.last(); - // m_ground_list.pop(); + // PhysicsObject* CurPop = m_ground_list.back(); + // m_ground_list.pop_back(); // CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); // Ticker::Unref(CurPop); //} - //while (m_stairs_list.count()) + //while (m_stairs_list.size()) //{ - // PhysicsObject* CurPop = m_stairs_list.last(); - // m_stairs_list.pop(); + // PhysicsObject* CurPop = m_stairs_list.back(); + // m_stairs_list.pop_back(); // CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); // Ticker::Unref(CurPop); //} - //while (m_character_list.count()) + //while (m_character_list.size()) //{ - // PhysicsObject* CurPop = m_character_list.last(); - // m_character_list.pop(); + // PhysicsObject* CurPop = m_character_list.back(); + // m_character_list.pop_back(); // CurPop->GetCharacter()->RemoveFromSimulation(m_simulation); // Ticker::Unref(CurPop); //} - //while (m_platform_list.count()) + //while (m_platform_list.size()) //{ - // PhysicsObject* CurPop = m_platform_list.last(); - // m_platform_list.pop(); + // PhysicsObject* CurPop = m_platform_list.back(); + // m_platform_list.pop_back(); // CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); // Ticker::Unref(CurPop); //} - //while (m_physobj_list.count()) + //while (m_physobj_list.size()) //{ - // PhysicsObject* CurPop = m_physobj_list.last().obj; - // m_physobj_list.pop(); + // PhysicsObject* CurPop = m_physobj_list.back().obj; + // m_physobj_list.pop_back(); // CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); // Ticker::Unref(CurPop); //} @@ -420,12 +426,12 @@ void BtPhysTest::tick_game(float seconds) { m_target_timer = TARGET_TIMER; if (m_cam_target == -1) - m_cam_target = rand(m_physobj_list.count()); + m_cam_target = rand(m_physobj_list.size()); else m_cam_target = -1; } - for (int i = 0; i < m_physobj_list.count(); i++) + for (size_t i = 0; i < m_physobj_list.size(); i++) { PhysicsObject* PhysObj = m_physobj_list[i].obj; float &obj_timer = m_physobj_list[i].anim; @@ -503,7 +509,7 @@ void BtPhysTest::tick_game(float seconds) #if USE_WALL { - for (int i = 0; i < m_ground_list.count(); i++) + for (size_t i = 0; i < m_ground_list.size(); i++) { PhysicsObject* PhysObj = m_ground_list[i]; mat4 GroundMat = PhysObj->GetTransform(); @@ -514,7 +520,7 @@ void BtPhysTest::tick_game(float seconds) GroundBarycenter /= factor; - for (int i = 0; i < m_ground_list.count(); i++) + for (size_t i = 0; i < m_ground_list.size(); i++) { PhysicsObject* PhysObj = m_ground_list[i]; @@ -533,7 +539,7 @@ void BtPhysTest::tick_game(float seconds) #if USE_ROTATION { - for (int i = 0; i < m_ground_list.count(); i++) + for (size_t i = 0; i < m_ground_list.size(); i++) { PhysicsObject* PhysObj = m_ground_list[i]; @@ -550,7 +556,7 @@ void BtPhysTest::tick_game(float seconds) #if USE_PLATFORM { - for (int i = 0; i < m_platform_list.count(); i++) + for (size_t i = 0; i < m_platform_list.size(); i++) { PhysicsObject* PhysObj = m_platform_list[i]; @@ -575,7 +581,7 @@ void BtPhysTest::tick_game(float seconds) { auto keyboard = input::keyboard(); - for (int i = 0; i < m_character_list.count(); i++) + for (size_t i = 0; i < m_character_list.size(); i++) { PhysicsObject* PhysObj = m_character_list[i]; EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter(); @@ -608,7 +614,7 @@ void BtPhysTest::tick_game(float seconds) PhysObjBarycenter = vec3(.0f); factor = .0f; - for (int i = 0; i < m_character_list.count(); i++) + for (size_t i = 0; i < m_character_list.size(); i++) { PhysicsObject* PhysObj = m_character_list[i]; mat4 GroundMat = PhysObj->GetTransform(); @@ -628,7 +634,7 @@ void BtPhysTest::tick_game(float seconds) #else { PhysObjBarycenter = vec3(.0f); - for (int i = 0; i < m_physobj_list.count(); i++) + for (size_t i = 0; i < m_physobj_list.size(); i++) { PhysicsObject* PhysObj = m_physobj_list[i].obj; mat4 GroundMat = PhysObj->GetTransform(); @@ -660,7 +666,7 @@ void BtPhysTest::tick_draw(float seconds, Scene &scene) /* cat datas setup */ m_cat_shader = Shader::Create(LOLFX_RESOURCE_NAME(front_camera_sprite)); #if USE_BODIES - for (int i = 0; i < m_physobj_list.count(); i++) + for (size_t i = 0; i < m_physobj_list.size(); i++) { PhysicsObject* PhysObj = m_physobj_list[i].obj; m_cat_sdata = new CatShaderData(((1 << VertexUsage::Position) | @@ -682,7 +688,7 @@ void BtPhysTest::tick_draw(float seconds, Scene &scene) else { #if CAT_MODE - for (int i = 0; i < m_physobj_list.count(); i++) + for (size_t i = 0; i < m_physobj_list.size(); i++) { PhysicsObject* PhysObj = m_physobj_list[i].obj; CatShaderData* ShaderData = (CatShaderData*)PhysObj->GetCustomShaderData(); diff --git a/doc/samples/btphystest.h b/doc/samples/btphystest.h index 8b3dbed4..29ae31ff 100644 --- a/doc/samples/btphystest.h +++ b/doc/samples/btphystest.h @@ -15,6 +15,7 @@ #include #include +#include #include class CatShaderData : public GpuShaderData @@ -89,28 +90,28 @@ private: typedef SafeEnum BtPhysTestKeyInput; - TileSet* m_cat_texture; - std::shared_ptr m_cat_shader; - CatShaderData* m_cat_sdata; - Camera* m_camera; - Light* m_light1; - Light* m_light2; - int m_init_status; - bool m_ready; + TileSet *m_cat_texture; + std::shared_ptr m_cat_shader; + CatShaderData *m_cat_sdata; + Camera *m_camera; + Light *m_light1; + Light *m_light2; + int m_init_status; + bool m_ready; - lol::phys::Simulation* m_simulation; - array m_constraint_list; + lol::phys::Simulation *m_simulation; + std::vector m_constraint_list; struct animated_object { PhysicsObject* obj; float anim; }; - array m_physobj_list; - array m_ground_list; - array m_platform_list; - array m_character_list; - array m_stairs_list; - - float m_loop_value; - float m_target_timer; - int m_cam_target; - float m_fov_dp; - float m_loc_dp; + std::vector m_physobj_list; + std::vector m_ground_list; + std::vector m_platform_list; + std::vector m_character_list; + std::vector m_stairs_list; + + float m_loop_value; + float m_target_timer; + int m_cam_target; + float m_fov_dp; + float m_loc_dp; }; diff --git a/doc/samples/physicobject.h b/doc/samples/physicobject.h index 9b7f843b..8dfdf0b0 100644 --- a/doc/samples/physicobject.h +++ b/doc/samples/physicobject.h @@ -17,6 +17,7 @@ /* FIXME: this file is pure crap; it's only a test. */ #include +#include #include "easymesh/easymesh.h" #include "physics/easyphysics.h" @@ -165,23 +166,24 @@ public: m_is_character(false), m_is_phys(false) { - static array MeshRand; - static array MeshLimit; - static array MeshType; + static std::vector MeshRand; + static std::vector MeshLimit; + static std::vector MeshType; - if (!MeshRand.count()) + if (!MeshRand.size()) { - array colors_base = { "#add", "#dad", "#dda", "#daa", "#ada", "#aad" }; + std::vector colors_base = { "#add", "#dad", "#dda", "#daa", "#ada", "#aad" }; - MeshLimit << 0; + MeshLimit.push_back(0); #if USE_BOX { - array colors = colors_base; - while (colors.count()) + std::vector colors = colors_base; + while (colors.size()) { EasyMesh m; - vec4 color = hex_to_color(colors.pop()); + vec4 color = hex_to_color(colors.back()); + colors.pop_back(); m.SetCurColor(color); m.AppendFlatChamfBox(vec3(1.7f), .4f); m.OpenBrace(); @@ -194,7 +196,7 @@ public: m.ScaleZ(-1.f); } m.CloseBrace(); - MeshRand << m; + MeshRand.push_back(m); } } //MeshRand << "[sc#add afcb1.7 1.7 1.7 0.4][sc#000 tsw afcb1.9 1.9 1.9 0.4 sx-1 sy-1 sz-1]"; @@ -204,8 +206,8 @@ public: //MeshRand << "[sc#ada afcb1.7 1.7 1.7 0.4][sc#000 tsw afcb1.9 1.9 1.9 0.4 sx-1 sy-1 sz-1]"; //MeshRand << "[sc#aad afcb1.7 1.7 1.7 0.4][sc#000 tsw afcb1.9 1.9 1.9 0.4 sx-1 sy-1 sz-1]"; - MeshLimit << MeshRand.count(); - MeshType << 0; + MeshLimit.push_back(int(MeshRand.size())); + MeshType.push_back(0); #endif //USE_BOX @@ -220,20 +222,21 @@ public: start_point, start_point + size); m_mesh.BD()->SetTexCoordCustomBuild2(MeshType::Quad, MeshFaceType::QuadDefault, vec2(-PARTICLE_SIZE), vec2(PARTICLE_SIZE)); - MeshRand << "[tpbn tvnc sc#ffff aq 0 0]"; - MeshRand << "[tpbn tvnc sc#faaf aq 0 0]"; - MeshRand << "[tpbn tvnc sc#afaf aq 0 0]"; - MeshRand << "[tpbn tvnc sc#aaff aq 0 0]"; + MeshRand.push_back("[tpbn tvnc sc#ffff aq 0 0]"); + MeshRand.push_back("[tpbn tvnc sc#faaf aq 0 0]"); + MeshRand.push_back("[tpbn tvnc sc#afaf aq 0 0]"); + MeshRand.push_back("[tpbn tvnc sc#aaff aq 0 0]"); #else { - array colors = colors_base; - while (colors.count()) + std::vector colors = colors_base; + while (colors.size()) { EasyMesh m; - vec4 color = hex_to_color(colors.pop()); + vec4 color = hex_to_color(colors.back()); + colors.pop_back(); m.SetCurColor(color); m.AppendSphere(1, 2.f); - MeshRand << m; + MeshRand.push_back(m); } } //MeshRand << "[sc#add asph1 2]"; @@ -244,24 +247,25 @@ public: //MeshRand << "[sc#aad asph1 2]"; #endif - MeshLimit << MeshRand.count(); - MeshType << 1; + MeshLimit.push_back(int(MeshRand.size())); + MeshType.push_back(1); #endif //USE_SPHERE #if USE_CONE { - array colors = colors_base; - while (colors.count()) + std::vector colors = colors_base; + while (colors.size()) { EasyMesh m; - vec4 color = hex_to_color(colors.pop()); + vec4 color = hex_to_color(colors.back()); + colors.pop_back(); m.SetCurColor(color); m.SetCurColorB(color); m.AppendDisc(8, 2.f); m.RotateX(180.f); m.TranslateY(-1.f); m.AppendCylinder(8, 2.f, 2.f, 0.f); - MeshRand << m; + MeshRand.push_back(m); } } //MeshRand << "[sc#add scb#add ad8 2 0 rx180 ty-1 ac8 2 2 0 0 0]"; @@ -271,17 +275,18 @@ public: //MeshRand << "[sc#ada scb#ada ad8 2 0 rx180 ty-1 ac8 2 2 0 0 0]"; //MeshRand << "[sc#aad scb#aad ad8 2 0 rx180 ty-1 ac8 2 2 0 0 0]"; - MeshLimit << MeshRand.count(); - MeshType << 2; + MeshLimit.push_back(int(MeshRand.size())); + MeshType.push_back(2); #endif //USE_CONE #if USE_CYLINDER { - array colors = colors_base; - while (colors.count()) + std::vector colors = colors_base; + while (colors.size()) { EasyMesh m; - vec4 color = hex_to_color(colors.pop()); + vec4 color = hex_to_color(colors.back()); + colors.pop_back(); m.SetCurColor(color); m.SetCurColorB(color); m.AppendDisc(8, 2.f); @@ -289,7 +294,7 @@ public: m.TranslateY(-1.f); m.MirrorY(); m.AppendCylinder(8.f, 2.f, 2.f, 2.f); - MeshRand << m; + MeshRand.push_back(m); } } //MeshRand << "[sc#add scb#add ad8 2 0 rx180 ty-1 my ac8 2 2 2 0 0]"; @@ -299,21 +304,22 @@ public: //MeshRand << "[sc#ada scb#ada ad8 2 0 rx180 ty-1 my ac8 2 2 2 0 0]"; //MeshRand << "[sc#aad scb#aad ad8 2 0 rx180 ty-1 my ac8 2 2 2 0 0]"; - MeshLimit << MeshRand.count(); - MeshType << 3; + MeshLimit.push_back(int(MeshRand.size())); + MeshType.push_back(3); #endif //USE_CYLINDER #if USE_CAPSULE { - array colors = colors_base; - while (colors.count()) + std::vector colors = colors_base; + while (colors.size()) { EasyMesh m; - vec4 color = hex_to_color(colors.pop()); + vec4 color = hex_to_color(colors.back()); + colors.pop_back(); m.SetCurColor(color); m.SetCurColorB(color); m.AppendCapsule(1, 2.f, 1.f); - MeshRand << m; + MeshRand.push_back(m); } } //MeshRand << "[sc#add scb#add acap1 2 1]"; @@ -323,14 +329,14 @@ public: //MeshRand << "[sc#ada scb#ada acap1 2 1]"; //MeshRand << "[sc#aad scb#aad acap1 2 1]"; - MeshLimit << MeshRand.count(); - MeshType << 4; + MeshLimit.push_back(int(MeshRand.size())); + MeshType.push_back(4); #endif //USE_CAPSULE } int RandLimit = RandValue; - if (MeshLimit.count() <= RandValue || RandValue < 0) - RandLimit = rand((int)MeshLimit.count() - 1); + if (MeshLimit.size() <= RandValue || RandValue < 0) + RandLimit = rand((int)MeshLimit.size() - 1); RandValue = rand(MeshLimit[RandLimit], MeshLimit[RandLimit + 1]); m_physics = new EasyPhysic(this); diff --git a/doc/samples/physics/easyphysics.cpp b/doc/samples/physics/easyphysics.cpp index 232634f4..5259f28e 100644 --- a/doc/samples/physics/easyphysics.cpp +++ b/doc/samples/physics/easyphysics.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // © 2009—2013 Cédric Lecacheur // © 2009—2013 Benjamin “Touky” Huet // @@ -147,12 +147,12 @@ void EasyPhysic::SetTransform(const lol::vec3& base_location, const lol::quat& b m_motion_state = new btDefaultMotionState(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(LOL2BT_UNIT * base_location))); } - for (int i = 0; i < m_based_physic_list.count(); i++) + for (size_t i = 0; i < m_based_physic_list.size(); i++) { if (m_based_physic_list[i]) m_based_physic_list[i]->BaseTransformChanged(PreviousMatrix, m_local_to_world); else - m_based_physic_list.remove(i--); + remove_at(m_based_physic_list, i--); } } diff --git a/doc/samples/physics/easyphysics.h b/doc/samples/physics/easyphysics.h index 367bd473..dd7a1a11 100644 --- a/doc/samples/physics/easyphysics.h +++ b/doc/samples/physics/easyphysics.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // © 2009—2013 Benjamin “Touky” Huet // // This library is free software. It comes without any warranty, to @@ -19,6 +19,7 @@ // #include +#include #include #include @@ -80,16 +81,16 @@ protected: virtual btGhostObject* GetGhostObjectInstance(); - btCollisionObject* m_collision_object; + btCollisionObject *m_collision_object; - btGhostObject* m_ghost_object; + btGhostObject *m_ghost_object; - btRigidBody* m_rigid_body; - btVector3 m_local_inertia; + btRigidBody *m_rigid_body; + btVector3 m_local_inertia; - btCollisionShape* m_collision_shape; - btConvexShape* m_convex_shape; - btMotionState* m_motion_state; + btCollisionShape *m_collision_shape; + btConvexShape *m_convex_shape; + btMotionState *m_motion_state; public: //Sets the collision Group & Mask. @@ -116,41 +117,41 @@ public: if (NewBase) { bool bAlreadyExists = false; - for (int i = 0; i < NewBase->m_based_physic_list.count(); ++i) + for (size_t i = 0; i < NewBase->m_based_physic_list.size(); ++i) if (NewBase->m_based_physic_list[i] == this) bAlreadyExists = true; if (!bAlreadyExists) - NewBase->m_based_physic_list << this; + NewBase->m_based_physic_list.push_back(this); m_base_physic = NewBase; m_base_lock_location = NewBaseLockLocation; m_base_lock_rotation = NewBaseLockRotation; } else if (m_base_physic) { - for (int i = 0; i < m_base_physic->m_based_physic_list.count(); ++i) + for (size_t i = 0; i < m_base_physic->m_based_physic_list.size(); ++i) if (m_base_physic->m_based_physic_list[i] == this) - m_base_physic->m_based_physic_list.remove(i--); + remove_at(m_base_physic->m_based_physic_list, i--); m_base_physic = nullptr; } } protected: - lol::mat4 m_local_to_world; - float m_mass; - float m_hit_restitution; - int m_collision_group; - int m_collision_mask; - WorldEntity* m_owner_entity; - Simulation* m_owner_simulation; + lol::mat4 m_local_to_world; + float m_mass; + float m_hit_restitution; + int m_collision_group; + int m_collision_mask; + WorldEntity *m_owner_entity; + Simulation *m_owner_simulation; //Base/Attachment logic - array m_based_physic_list; //List of objects based on this : this object moves, its based object MoveStep with it. - EasyPhysic* m_base_physic; //Base for this object : The base moves, the object moves with it. - bool m_base_lock_location; //when this is TRUE, location moves with rotation change. - bool m_base_lock_rotation; //when this is TRUE, rotation moves with rotation change. + std::vector m_based_physic_list; //List of objects based on this : this object moves, its based object MoveStep with it. + EasyPhysic *m_base_physic; //Base for this object : The base moves, the object moves with it. + bool m_base_lock_location; //when this is TRUE, location moves with rotation change. + bool m_base_lock_rotation; //when this is TRUE, rotation moves with rotation change. //Touch logic - array m_touching_physic; //Maintained by ghost objects + std::vector m_touching_physic; //Maintained by ghost objects }; } /* namespace phys */ diff --git a/doc/samples/physics/lolphysics.h b/doc/samples/physics/lolphysics.h index d6bdc3ff..c2d72e67 100644 --- a/doc/samples/physics/lolphysics.h +++ b/doc/samples/physics/lolphysics.h @@ -1,8 +1,8 @@ // // Lol Engine — Bullet physics test // -// Copyright © 2009—2013 Benjamin “Touky” Huet -// © 2012—2019 Sam Hocevar +// Copyright © 2012—2020 Sam Hocevar +// © 2009—2013 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -14,6 +14,7 @@ #pragma once #include +#include #include #include @@ -41,12 +42,11 @@ enum eRaycastType struct RayCastResult { RayCastResult(int CollisionFilterGroup=1, int CollisionFilterMask=(0xFF)) + : m_collision_filter_group(CollisionFilterGroup), + m_collision_filter_mask(CollisionFilterMask) { - memset(this, 0, sizeof(RayCastResult)); - - m_collision_filter_group = CollisionFilterGroup; - m_collision_filter_mask = CollisionFilterMask; } + void Reset() { m_collider_list.clear(); @@ -55,14 +55,14 @@ struct RayCastResult m_hit_fraction_list.clear(); } - array m_collider_list; - array m_hit_normal_list; - array m_hit_point_list; - array m_hit_fraction_list; + std::vector m_collider_list; + std::vector m_hit_normal_list; + std::vector m_hit_point_list; + std::vector m_hit_fraction_list; - short int m_collision_filter_group; - short int m_collision_filter_mask; - unsigned int m_flags; //??? + int16_t m_collision_filter_group; + int16_t m_collision_filter_mask; + uint32_t m_flags = 0; //??? }; class Simulation : public entity @@ -207,20 +207,20 @@ public: { case ERT_Closest: { - HitResult.m_collider_list << (EasyPhysic*)BtRayResult_Closest->m_collisionObject->getUserPointer(); - HitResult.m_hit_normal_list << BT2LOLU_VEC3(BtRayResult_Closest->m_hitNormalWorld); - HitResult.m_hit_point_list << BT2LOLU_VEC3(BtRayResult_Closest->m_hitPointWorld); - HitResult.m_hit_fraction_list << BtRayResult_Closest->m_closestHitFraction; + HitResult.m_collider_list.push_back((EasyPhysic*)BtRayResult_Closest->m_collisionObject->getUserPointer()); + HitResult.m_hit_normal_list.push_back(BT2LOLU_VEC3(BtRayResult_Closest->m_hitNormalWorld)); + HitResult.m_hit_point_list.push_back(BT2LOLU_VEC3(BtRayResult_Closest->m_hitPointWorld)); + HitResult.m_hit_fraction_list.push_back(BtRayResult_Closest->m_closestHitFraction); break; } case ERT_AllHit: { for (int i = 0; i < BtRayResult_AllHits->m_collisionObjects.size(); i++) { - HitResult.m_collider_list << (EasyPhysic*)BtRayResult_AllHits->m_collisionObjects[i]->getUserPointer(); - HitResult.m_hit_normal_list << BT2LOLU_VEC3(BtRayResult_AllHits->m_hitNormalWorld[i]); - HitResult.m_hit_point_list << BT2LOLU_VEC3(BtRayResult_AllHits->m_hitPointWorld[i]); - HitResult.m_hit_fraction_list << BtRayResult_AllHits->m_hitFractions[i]; + HitResult.m_collider_list.push_back((EasyPhysic*)BtRayResult_AllHits->m_collisionObjects[i]->getUserPointer()); + HitResult.m_hit_normal_list.push_back(BT2LOLU_VEC3(BtRayResult_AllHits->m_hitNormalWorld[i])); + HitResult.m_hit_point_list.push_back(BT2LOLU_VEC3(BtRayResult_AllHits->m_hitPointWorld[i])); + HitResult.m_hit_fraction_list.push_back(BtRayResult_AllHits->m_hitFractions[i]); } break; } @@ -273,15 +273,15 @@ private: void CustomSetTimestep(float NewTimestep) { } //broadphase - btBroadphaseInterface* m_broadphase; - btAxisSweep3* m_Sweep_broadphase; + btBroadphaseInterface *m_broadphase; + btAxisSweep3 *m_Sweep_broadphase; // Set up the collision configuration and dispatc - btDefaultCollisionConfiguration* m_collision_configuration; - btCollisionDispatcher* m_dispatcher; + btDefaultCollisionConfiguration *m_collision_configuration; + btCollisionDispatcher *m_dispatcher; // The actual physics solver - btSequentialImpulseConstraintSolver* m_solver; + btSequentialImpulseConstraintSolver *m_solver; // The world. - btDiscreteDynamicsWorld* m_dynamics_world; + btDiscreteDynamicsWorld *m_dynamics_world; public: //Main logic : @@ -341,7 +341,7 @@ private: //Adds the given EasyPhysic to the correct list. void ObjectRegistration(bool AddObject, EasyPhysic* NewEP, eEasyPhysicType CurType) { - array* SearchList = nullptr; + std::vector* SearchList = nullptr; switch(CurType) { case EEPT_Dynamic: @@ -378,45 +378,45 @@ private: if (AddObject) { NewEP->m_owner_simulation = this; - (*SearchList) << NewEP; + SearchList->push_back(NewEP); } else { NewEP->m_owner_simulation = nullptr; - SearchList->remove_item(NewEP); + remove_item(*SearchList, NewEP); } } void ObjectRegistration(bool AddObject, EasyConstraint* NewEC) { - array* SearchList = nullptr; + std::vector* SearchList = nullptr; SearchList = &m_constraint_list; if (AddObject) { NewEC->m_owner_simulation = this; - (*SearchList) << NewEC; + SearchList->push_back(NewEC); } else { NewEC->m_owner_simulation = nullptr; - SearchList->remove_item(NewEC); + remove_item(*SearchList, NewEC); } } //Easy Physics body List - array m_dynamic_list; - array m_static_list; - array m_ghost_list; - array m_collision_object_list; - array m_character_controller_list; - array m_constraint_list; + std::vector m_dynamic_list; + std::vector m_static_list; + std::vector m_ghost_list; + std::vector m_collision_object_list; + std::vector m_character_controller_list; + std::vector m_constraint_list; //Easy Physics data storage - float m_timestep; - bool m_using_CCD; - vec3 m_gravity; - vec3 m_world_min; - vec3 m_world_max; + float m_timestep; + bool m_using_CCD; + vec3 m_gravity; + vec3 m_world_min; + vec3 m_world_max; }; } /* namespace phys */ diff --git a/doc/tutorial/01_triangle.cpp b/doc/tutorial/01_triangle.cpp index a7c2e4c9..fc20057f 100644 --- a/doc/tutorial/01_triangle.cpp +++ b/doc/tutorial/01_triangle.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Triangle tutorial // -// Copyright © 2012—2019 Sam Hocevar +// Copyright © 2012—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -28,7 +28,7 @@ class Triangle : public WorldEntity public: virtual bool init_draw() override { - array vertices + std::vector vertices { vec2( 0.0f, 0.8f), vec2(-0.8f, -0.8f), @@ -40,8 +40,8 @@ public: m_vdecl = std::make_shared(VertexStream(VertexUsage::Position)); - m_vbo = std::make_shared(vertices.bytes()); - m_vbo->set_data(vertices.data(), vertices.bytes()); + m_vbo = std::make_shared(vertices.size() * sizeof(vertices[0])); + m_vbo->set_data(vertices.data(), vertices.size() * sizeof(vertices[0])); return true; } diff --git a/doc/tutorial/02_cube.cpp b/doc/tutorial/02_cube.cpp index 8beaae6d..936680a5 100644 --- a/doc/tutorial/02_cube.cpp +++ b/doc/tutorial/02_cube.cpp @@ -48,7 +48,7 @@ public: virtual bool init_draw() override { - array mesh + std::vector mesh { // Front vertices/colors { vec3(-1.0, -1.0, 1.0), vec3(1.0, 0.0, 1.0) }, @@ -62,14 +62,14 @@ public: { vec3(-1.0, 1.0, -1.0), vec3(0.0, 0.0, 1.0) }, }; - array lines_indices + std::vector lines_indices { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7, }; - array faces_indices + std::vector faces_indices { 0, 1, 2, 2, 3, 0, 1, 5, 6, 6, 2, 1, 7, 6, 5, 5, 4, 7, 4, 0, 3, 3, 7, 4, @@ -86,14 +86,14 @@ public: VertexStream(VertexUsage::Position, VertexUsage::Color)); - m_vbo = std::make_shared(mesh.bytes()); - m_vbo->set_data(mesh.data(), mesh.bytes()); + m_vbo = std::make_shared(mesh.size() * sizeof(mesh[0])); + m_vbo->set_data(mesh.data(), mesh.size() * sizeof(mesh[0])); - m_lines_ibo = std::make_shared(lines_indices.bytes()); - m_lines_ibo->set_data(lines_indices.data(), lines_indices.bytes()); + m_lines_ibo = std::make_shared(lines_indices.size() * sizeof(lines_indices[0])); + m_lines_ibo->set_data(lines_indices.data(), lines_indices.size() * sizeof(lines_indices[0])); - m_faces_ibo = std::make_shared(faces_indices.bytes()); - m_faces_ibo->set_data(faces_indices.data(), faces_indices.bytes()); + m_faces_ibo = std::make_shared(faces_indices.size() * sizeof(faces_indices[0])); + m_faces_ibo->set_data(faces_indices.data(), faces_indices.size() * sizeof(faces_indices[0])); return true; } diff --git a/doc/tutorial/03_noise.cpp b/doc/tutorial/03_noise.cpp index af01a0f1..4cc281d6 100644 --- a/doc/tutorial/03_noise.cpp +++ b/doc/tutorial/03_noise.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Noise tutorial // -// Copyright © 2012—2019 Sam Hocevar +// Copyright © 2012—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -28,7 +28,7 @@ class NoiseDemo : public WorldEntity public: virtual bool init_draw() override { - array vertices + std::vector vertices { vec2(-1.0, 1.0), vec2(-1.0, -1.0), @@ -44,8 +44,8 @@ public: m_vdecl = std::make_shared(VertexStream(VertexUsage::Position)); - m_vbo = std::make_shared(vertices.bytes()); - m_vbo->set_data(vertices.data(), vertices.bytes()); + m_vbo = std::make_shared(vertices.size() * sizeof(vertices[0])); + m_vbo->set_data(vertices.data(), vertices.size() * sizeof(vertices[0])); return true; } diff --git a/doc/tutorial/04_texture.cpp b/doc/tutorial/04_texture.cpp index 46c14699..142d1354 100644 --- a/doc/tutorial/04_texture.cpp +++ b/doc/tutorial/04_texture.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Graphing tutorial // -// Copyright © 2012—2019 Sam Hocevar +// Copyright © 2012—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -15,6 +15,7 @@ #endif #include +#include #include "loldebug.h" using namespace lol; @@ -30,7 +31,7 @@ public: { /* Generate a new heightmap at the beginning */ m_heightmap.resize(TEXTURE_WIDTH * 1); - memset(m_heightmap.data(), 255, m_heightmap.bytes()); + memset(m_heightmap.data(), 255, m_heightmap.size() * sizeof(m_heightmap[0])); return true; } @@ -40,13 +41,13 @@ public: WorldEntity::tick_game(seconds); /* Scroll left */ - for (int i = 0; i < m_heightmap.count() - 1; i++) + for (size_t i = 0; i + 1 < m_heightmap.size(); i++) m_heightmap[i] = m_heightmap[i + 1]; - int height = m_heightmap.last(); + int height = m_heightmap.back(); height = (int)(height + 127 + 40 * lol::sin(m_frames * 0.03) + rand() % 97 - 38) / 2; height = std::max(15, std::min(height, 240)); - m_heightmap.last() = height; + m_heightmap.back() = height; /* Update frame counter */ ++m_frames; @@ -54,7 +55,7 @@ public: virtual bool init_draw() override { - array vertices + std::vector vertices { vec2(-1.0, 1.0), vec2(-1.0, -1.0), @@ -72,8 +73,8 @@ public: m_vdecl = std::make_shared(VertexStream(VertexUsage::Position)); - m_vbo = std::make_shared(vertices.bytes()); - m_vbo->set_data(vertices.data(), vertices.bytes()); + m_vbo = std::make_shared(vertices.size() * sizeof(vertices[0])); + m_vbo->set_data(vertices.data(), vertices.size() * sizeof(vertices[0])); return true; } @@ -110,7 +111,7 @@ private: ShaderUniform m_texture_uni; std::shared_ptr m_vdecl; std::shared_ptr m_vbo; - array m_heightmap; + std::vector m_heightmap; int m_frames = 0; }; diff --git a/doc/tutorial/05_easymesh.cpp b/doc/tutorial/05_easymesh.cpp index 66276585..9ff01900 100644 --- a/doc/tutorial/05_easymesh.cpp +++ b/doc/tutorial/05_easymesh.cpp @@ -39,11 +39,11 @@ public: EasyMeshLuaObject* gears3 = EzMhLoader.GetPtr("g3"); EasyMeshLuaObject* gears4 = EzMhLoader.GetPtr("g4"); - 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.push_back(gear { gears0->GetMesh(), mat4(1.0f), 0.0f }); + m_gears.push_back(gear { gears1->GetMesh(), mat4(1.0f), 0.0f }); + m_gears.push_back(gear { gears2->GetMesh(), mat4(1.0f), 180.0f / 18 }); + m_gears.push_back(gear { gears3->GetMesh(), mat4(1.0f), 180.0f / 18 }); + m_gears.push_back(gear { gears4->GetMesh(), mat4(1.0f), 180.0f / 18 }); /* m_gears[0].mesh.Compile("[sc#00f ab 8 1 8 ty -.25]" @@ -124,7 +124,7 @@ public: scene.get_renderer()->clear_color(vec4(0.0f, 0.0f, 0.0f, 1.0f)); /* Upload vertex data to GPU */ - for (int i = 0; i < m_gears.count(); i++) + for (size_t i = 0; i < m_gears.size(); i++) m_gears[i].mesh.MeshConvert(); #if USE_CUSTOM_SHADER @@ -132,7 +132,7 @@ public: auto custom_shader = Shader::Create(LOLFX_RESOURCE_NAME(easymesh_shiny)); // any other shader stuf here (Get uniform, mostly, and set texture) - for (int i = 0; i < m_gears.count(); i++) + for (size_t i = 0; i < m_gears.size(); i++) m_gears[i].mesh.SetMaterial(custom_shader); #endif @@ -143,7 +143,7 @@ public: { WorldEntity::tick_draw(seconds, scene); - for (int i = 0; i < m_gears.count(); i++) + for (size_t i = 0; i < m_gears.size(); i++) m_gears[i].mesh.Render(scene, m_mat * m_gears[i].mat); } @@ -157,7 +157,7 @@ public: private: struct gear { EasyMesh mesh; mat4 mat; float anim; }; - array m_gears; + std::vector m_gears; float m_angle; mat4 m_mat; diff --git a/doc/tutorial/06_sprite.cpp b/doc/tutorial/06_sprite.cpp index 45df87a9..7e94458a 100644 --- a/doc/tutorial/06_sprite.cpp +++ b/doc/tutorial/06_sprite.cpp @@ -35,8 +35,8 @@ public: for (int i = 0; i < SPRITE_COUNT; ++i) { - m_sprites.push(sprite { vec3((float)rand(-96, 640), (float)rand(-96, 480), 0.f), - rand(0.f, 1.f) }); + m_sprites.push_back(sprite { vec3((float)rand(-96, 640), (float)rand(-96, 480), 0.f), + rand(0.f, 1.f) }); } } @@ -95,7 +95,7 @@ private: static int const FRAME_COUNT = 16; struct sprite { vec3 pos; float anim; }; - array m_sprites; + std::vector m_sprites; }; int main(int argc, char **argv) diff --git a/doc/tutorial/07_input.cpp b/doc/tutorial/07_input.cpp index 3cd1a202..cf024e16 100644 --- a/doc/tutorial/07_input.cpp +++ b/doc/tutorial/07_input.cpp @@ -104,7 +104,7 @@ public: virtual bool init_draw() override { - array mesh + std::vector mesh { // Front vertices/colors { vec3(-1.0, -1.0, 1.0), vec3(1.0, 0.0, 1.0) }, @@ -118,14 +118,14 @@ public: { vec3(-1.0, 1.0, -1.0), vec3(0.0, 0.0, 1.0) }, }; - array faces_indices + std::vector faces_indices { 0, 1, 2, 2, 3, 0, 1, 5, 6, 6, 2, 1, 7, 6, 5, 5, 4, 7, 4, 0, 3, 3, 7, 4, 4, 5, 1, 1, 0, 4, 3, 2, 6, 6, 7, 3, }; - array lines_indices + std::vector lines_indices { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, @@ -142,14 +142,14 @@ public: VertexStream(VertexUsage::Position, VertexUsage::Color)); - m_vbo = std::make_shared(mesh.bytes()); - m_vbo->set_data(mesh.data(), mesh.bytes()); + m_vbo = std::make_shared(mesh.size() * sizeof(mesh[0])); + m_vbo->set_data(mesh.data(), mesh.size() * sizeof(mesh[0])); - m_lines_ibo = std::make_shared(lines_indices.bytes()); - m_lines_ibo->set_data(lines_indices.data(), lines_indices.bytes()); + m_lines_ibo = std::make_shared(lines_indices.size() * sizeof(lines_indices[0])); + m_lines_ibo->set_data(lines_indices.data(), lines_indices.size() * sizeof(lines_indices[0])); - m_faces_ibo = std::make_shared(faces_indices.bytes()); - m_faces_ibo->set_data(faces_indices.data(), faces_indices.bytes()); + m_faces_ibo = std::make_shared(faces_indices.size() * sizeof(faces_indices[0])); + m_faces_ibo->set_data(faces_indices.data(), faces_indices.size() * sizeof(faces_indices[0])); return WorldEntity::init_draw(); } diff --git a/doc/tutorial/08_fbo.cpp b/doc/tutorial/08_fbo.cpp index 492643a1..6f476200 100644 --- a/doc/tutorial/08_fbo.cpp +++ b/doc/tutorial/08_fbo.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Framebuffer Object tutorial // -// Copyright © 2012—2019 Sam Hocevar +// Copyright © 2012—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -44,7 +44,7 @@ public: virtual bool init_draw() override { - array vertices + std::vector vertices { vec2( 1.0, 1.0), vec2(-1.0, -1.0), @@ -63,8 +63,8 @@ public: m_vdecl = std::make_shared(VertexStream(VertexUsage::Position)); - m_vbo = std::make_shared(vertices.bytes()); - m_vbo->set_data(vertices.data(), vertices.bytes()); + m_vbo = std::make_shared(vertices.size() * sizeof(vertices[0])); + m_vbo->set_data(vertices.data(), vertices.size() * sizeof(vertices[0])); // Create the back buffer and clear it m_backbuffer = std::make_shared(Video::GetSize()); diff --git a/doc/tutorial/11_fractal.cpp b/doc/tutorial/11_fractal.cpp index 76f4fc7d..5af2daad 100644 --- a/doc/tutorial/11_fractal.cpp +++ b/doc/tutorial/11_fractal.cpp @@ -85,7 +85,7 @@ public: uint8_t red = (uint8_t)(rgb.r * 256); uint8_t green = (uint8_t)(rgb.g * 256); uint8_t blue = (uint8_t)(rgb.b * 256); - m_palette.push(u8vec4(blue, green, red, 255)); + m_palette.push_back(u8vec4(blue, green, red, 255)); } m_zoomtext = new Text("", "data/font/ascii.png"); @@ -530,7 +530,7 @@ private: ivec2 m_size, m_window_size, m_oldmouse; double m_window2world; dvec2 m_texel2world; - array m_pixels, m_palette; + std::vector m_pixels, m_palette; std::shared_ptr m_shader; ShaderAttrib m_vertexattrib, m_texattrib; diff --git a/doc/tutorial/12_voronoi.cpp b/doc/tutorial/12_voronoi.cpp index 94610979..0ef9677c 100644 --- a/doc/tutorial/12_voronoi.cpp +++ b/doc/tutorial/12_voronoi.cpp @@ -43,12 +43,12 @@ class Voronoi : public WorldEntity public: Voronoi() { - m_vertices << vec2( 1.0, 1.0); - m_vertices << vec2(-1.0, -1.0); - m_vertices << vec2( 1.0, -1.0); - m_vertices << vec2(-1.0, -1.0); - m_vertices << vec2( 1.0, 1.0); - m_vertices << vec2(-1.0, 1.0); + m_vertices.push_back(vec2( 1.0, 1.0)); + m_vertices.push_back(vec2(-1.0, -1.0)); + m_vertices.push_back(vec2( 1.0, -1.0)); + m_vertices.push_back(vec2(-1.0, -1.0)); + m_vertices.push_back(vec2( 1.0, 1.0)); + m_vertices.push_back(vec2(-1.0, 1.0)); m_ready = false; m_cur_fbo = 0; m_time = .0f; @@ -86,8 +86,8 @@ public: { m_vdecl = std::make_shared(VertexStream(VertexUsage::Position)); - m_vbo = std::make_shared(m_vertices.bytes()); - m_vbo->set_data(m_vertices.data(), m_vertices.bytes()); + m_vbo = std::make_shared(m_vertices.size() * sizeof(m_vertices[0])); + m_vbo->set_data(m_vertices.data(), m_vertices.size() * sizeof(m_vertices[0])); m_screen_shader = Shader::Create(LOLFX_RESOURCE_NAME(12_texture_to_screen)); m_screen_coord = m_screen_shader->GetAttribLocation(VertexUsage::Position, 0); @@ -95,29 +95,29 @@ public: for (int i = 0; i < MaxFboType; ++i) { - m_fbos.push(fbo + m_fbos.push_back(fbo { std::make_shared(Video::GetSize()), 0, - array(), - array(), + std::vector(), + std::vector(), }); if (i == SrcVoronoiFbo) { 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); + m_fbos[i].uni.push_back(m_fbos[i].shader->GetUniformLocation("u_texture")); + m_fbos[i].uni.push_back(m_fbos[i].shader->GetUniformLocation("u_source_point")); + m_fbos[i].uni.push_back(m_fbos[i].shader->GetUniformLocation("u_screen_res")); + m_fbos[i].attr.push_back(m_fbos[i].shader->GetAttribLocation(VertexUsage::Position, 0)); } else if (i == VoronoiFbo) { 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); + m_fbos[i].uni.push_back(m_fbos[i].shader->GetUniformLocation("u_texture")); + m_fbos[i].uni.push_back(m_fbos[i].shader->GetUniformLocation("u_step")); + m_fbos[i].uni.push_back(m_fbos[i].shader->GetUniformLocation("u_screen_res")); + m_fbos[i].attr.push_back(m_fbos[i].shader->GetAttribLocation(VertexUsage::Position, 0)); } else if (i == DistanceVoronoiFbo) { @@ -128,14 +128,14 @@ public: m_fbos[i].shader = Shader::Create(LOLFX_RESOURCE_NAME(12_distance)); } - m_fbos.last().framebuffer->Bind(); + m_fbos.back().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().framebuffer->Unbind(); + m_fbos.back().framebuffer->Unbind(); } temp_buffer = std::make_shared(Video::GetSize()); @@ -158,9 +158,9 @@ public: auto keyboard = input::keyboard(); if (keyboard->key_released(input::key::SC_O)) - voronoi_points.pop(); + voronoi_points.pop_back(); else if (keyboard->key_released(input::key::SC_P)) - voronoi_points.push(point + voronoi_points.push_back(point { vec3(rand(512.f), rand(512.f), .0f), vec2(64.f + rand(64.f), 64.f + rand(64.f)) @@ -176,7 +176,7 @@ public: { int i = 4; while (i-- > 0) - voronoi_points.push(point + voronoi_points.push_back(point { vec3(rand(512.f), rand(512.f), .0f), vec2(64.f + rand(64.f), 64.f + rand(64.f)) @@ -199,12 +199,12 @@ public: float mi = (float)maxi; float j = (float)i; float f_time = (float)m_time; - 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_back(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_back(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_back(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_back(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(point { vec3(256.f), vec2(0.f) }); + voronoi_points.push_back(point { vec3(256.f), vec2(0.f) }); } temp_buffer->Bind(); @@ -219,7 +219,7 @@ public: { vec2 limit(1.f, 511.f); //SRC SETUP - for (int j = 0; j < voronoi_points.count(); ++j) + for (size_t j = 0; j < voronoi_points.size(); ++j) { 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) @@ -232,7 +232,7 @@ public: 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].pos.z = ((float)j + 1) / ((float)voronoi_points.count()); + voronoi_points[j].pos.z = ((float)j + 1) / ((float)voronoi_points.size()); } int f = SrcVoronoiFbo; @@ -246,8 +246,8 @@ public: } m_fbos[f].framebuffer->Unbind(); - int buf = voronoi_points.count() % 2; - for (int j = 0; j < voronoi_points.count(); ++j) + int buf = int(voronoi_points.size()) % 2; + for (size_t j = 0; j < voronoi_points.size(); ++j) { std::shared_ptr dst_buf, src_buf; @@ -273,7 +273,7 @@ public: 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].attr.last()); + m_vdecl->SetStream(m_vbo, m_fbos[f].attr.back()); m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); m_vdecl->Unbind(); m_fbos[f].shader->Unbind(); @@ -339,7 +339,7 @@ public: } m_vdecl->Bind(); - m_vdecl->SetStream(m_vbo, m_fbos[m_cur_fbo].attr.last()); + m_vdecl->SetStream(m_vbo, m_fbos[m_cur_fbo].attr.back()); m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); m_vdecl->Unbind(); m_fbos[m_cur_fbo].shader->Unbind(); @@ -371,8 +371,8 @@ public: private: struct point { vec3 pos; vec2 speed; }; - array voronoi_points; - array m_vertices; + std::vector voronoi_points; + std::vector m_vertices; std::shared_ptr m_screen_shader; ShaderAttrib m_screen_coord; ShaderUniform m_screen_texture; @@ -384,10 +384,10 @@ private: { std::shared_ptr framebuffer; std::shared_ptr shader; - array uni; - array attr; + std::vector uni; + std::vector attr; }; - array m_fbos; + std::vector m_fbos; std::shared_ptr temp_buffer; int mode; diff --git a/lol-core b/lol-core index c1645f5e..7eb81936 160000 --- a/lol-core +++ b/lol-core @@ -1 +1 @@ -Subproject commit c1645f5e8b30961419485e8b3f28092900a99148 +Subproject commit 7eb81936e277f0c7bb171fddf3632896144e3ac7 diff --git a/src/Makefile.am b/src/Makefile.am index 9b87bfb2..165095e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,7 @@ liblol_core_a_SOURCES = \ textureimage.cpp textureimage.h textureimage-private.h \ tileset.cpp tileset.h video.cpp video.h \ profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.h \ - numeric.h utils.h messageservice.cpp messageservice.h \ + numeric.h messageservice.cpp messageservice.h \ gradient.cpp gradient.h gradient.lolfx \ platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ light.cpp light.h \ @@ -31,8 +31,7 @@ liblol_core_headers = \ lol/lua.h \ \ lol/base/all.h \ - lol/base/array.h lol/base/map.h lol/base/enum.h \ - lol/base/log.h \ + lol/base/enum.h lol/base/log.h \ \ lol/audio/all.h \ lol/audio/audio.h lol/audio/sample.h \ @@ -67,11 +66,11 @@ liblol_core_sources = \ commandstack.h \ easymesh/easymeshbuild.cpp easymesh/easymeshbuild.h \ easymesh/easymeshrender.cpp easymesh/easymeshrender.h \ - easymesh/easymesh.cpp \ + easymesh/easymesh.cpp easymesh/easymesh.h \ easymesh/easymeshinternal.cpp easymesh/easymeshcsg.cpp \ easymesh/easymeshprimitive.cpp easymesh/easymeshtransform.cpp \ - easymesh/easymeshcursor.cpp easymesh/easymesh.h \ - easymesh/easymeshlua.cpp easymesh/easymeshlua.h \ + easymesh/easymeshcursor.cpp easymesh/easymeshlua.cpp \ + easymesh/easymeshlua.h easymesh/easyarray.h \ easymesh/csgbsp.cpp easymesh/csgbsp.h \ easymesh/shiny.lolfx easymesh/shinyflat.lolfx \ easymesh/shinydebugwireframe.lolfx \ diff --git a/src/base/log.cpp b/src/base/log.cpp index b60db560..c3380b14 100644 --- a/src/base/log.cpp +++ b/src/base/log.cpp @@ -112,9 +112,9 @@ void msg::helper(message_type type, char const *fmt, va_list ap) # if defined _WIN32 std::string buf = std::string(prefix[(int)type]) + ": " + vformat(fmt, ap); - array widechar; + std::vector widechar; widechar.resize(buf.length() + 1); - MultiByteToWideChar(CP_UTF8, 0, buf.c_str(), (int)buf.length() + 1, widechar.data(), widechar.count()); + MultiByteToWideChar(CP_UTF8, 0, buf.c_str(), (int)buf.length() + 1, widechar.data(), widechar.size()); OutputDebugStringW(widechar.data()); # elif defined __EMSCRIPTEN__ fprintf(stdout, "%s: ", prefix[(int)type]); diff --git a/src/commandstack.h b/src/commandstack.h index c002407d..ff5ac509 100644 --- a/src/commandstack.h +++ b/src/commandstack.h @@ -23,29 +23,30 @@ namespace lol { -//Utility struct to convert command code to pseudo-bytecode +// Utility struct to convert command code to pseudo-bytecode struct CommandStack { private: - array m_commands; - array m_floats; - array m_ints; - int m_f_cur; - int m_i_cur; + struct cmd_def { int cmd, nfloats, nints; }; + + std::vector m_commands; + std::vector m_floats; + std::vector m_ints; + int m_f_cur; + int m_i_cur; public: //GET/SET exec - int GetCmdNb() { return m_commands.count(); } + int GetCmdNb() { return int(m_commands.size()); } int GetCmd(int i) { - ASSERT(0 <= i && i < m_commands.count()); - 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]); + m_f_cur = m_commands[i].nfloats; + m_i_cur = m_commands[i].nints; + return m_commands[i].cmd; } //cmd storage - void AddCmd(int cmd) { m_commands.push(cmd, m_floats.count(), m_ints.count()); } + void AddCmd(int cmd) { m_commands.push_back(cmd_def{ cmd, int(m_floats.size()), int(m_ints.size()) }); } //GETTER inline float F() { return m_floats[m_f_cur++]; } @@ -74,8 +75,8 @@ public: void GetValue(SafeEnum &i) { i = typename DEF::Type(I()); } //SETTER - CommandStack &operator<<(int i) { m_ints << i; return *this; } - CommandStack &operator<<(float f) { m_floats << f; return *this; } + CommandStack &operator<<(int i) { m_ints.push_back(i); return *this; } + CommandStack &operator<<(float f) { m_floats.push_back(f); return *this; } CommandStack &operator<<(bool b) { return (*this << (int)b); } CommandStack &operator<<(vec2 v) { return (*this << v.x << v.y); } CommandStack &operator<<(vec3 v) { return (*this << v.xy << v.z); } diff --git a/src/easymesh/csgbsp.cpp b/src/easymesh/csgbsp.cpp index 91523e6e..362744c7 100644 --- a/src/easymesh/csgbsp.cpp +++ b/src/easymesh/csgbsp.cpp @@ -60,9 +60,9 @@ int CsgBsp::TestPoint(int leaf_idx, vec3 point) void CsgBsp::AddTriangleToTree(int const &tri_idx, vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2) { // - array< int, vec3, vec3, vec3 > tri_to_process; + easy_array< int, vec3, vec3, vec3 > tri_to_process; // - array< int, int, vec3, vec3, vec3, int > Leaf_to_add; + easy_array< int, int, vec3, vec3, vec3, int > Leaf_to_add; //Tree is empty, so this leaf is the first if (m_tree.count() == 0) @@ -221,14 +221,14 @@ void CsgBsp::AddTriangleToTree(int const &tri_idx, vec3 const &tri_p0, vec3 cons int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2, //In order to easily build the actual vertices list afterward, this list stores each Vertices location and its source vertices & Alpha. // as { Point_Loc = Src_V0 + (Src_V1 - Src_V0) * Alpha; } - array< vec3, int, int, float > &vert_list, + easy_array< vec3, int, int, float > &vert_list, //This is the final triangle list : If Side_Status is LEAF_CURRENT, a new test will be done point by point. //<{IN|OUT}side_status, v0, v1, v2> - array< int, int, int, int > &tri_list) + easy_array< int, int, int, int > &tri_list) { //This list stores the current triangles to process. // - array< array< int >, int, int, int, int > tri_to_process; + easy_array< easy_array< int >, int, int, int, int > tri_to_process; //Tree is empty, ABORT ! if (m_tree.count() == 0) @@ -241,7 +241,7 @@ 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.push( easy_array< int >(), 0, 1, 2, 0); std::get<0>(tri_to_process.last()).push(0); while (tri_to_process.count()) @@ -369,7 +369,7 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons 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.push(easy_array< int >(), t[(isec_base + 2) % 3], new_v_idx[v_idx1], new_v_idx[v_idx0], 0); std::get<0>(tri_to_process.last()).push(0); } @@ -382,9 +382,9 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons } else { - tri_to_process.push(array< int >(), t[isec_base], t[((isec_base + 1) % 3)], new_v_idx[v_idx0], 0); + tri_to_process.push(easy_array< int >(), t[isec_base], t[((isec_base + 1) % 3)], new_v_idx[v_idx0], 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.push(easy_array< int >(), t[isec_base], new_v_idx[v_idx0], new_v_idx[v_idx1], 0); std::get<0>(tri_to_process.last()).push(0); } #else @@ -415,14 +415,14 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons continue; #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.push(easy_array< int >(), new_t[k], new_t[k + 1], new_t[k + 2], 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 && 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.push(easy_array< int >(), new_t[k], new_t[k + 1], new_t[k + 2], 0); 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) std::get<0>(tri_to_process.last()).pop(); @@ -525,7 +525,7 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons #endif std::get<0>(tri_list[i]) = LEAF_BACK; #if 0 - tri_to_process.push(array< int >(), + tri_to_process.push(easy_array< int >(), std::get<1>(tri_list[i]), std::get<2>(tri_list[i]), std::get<3>(tri_list[i]), 0); diff --git a/src/easymesh/csgbsp.h b/src/easymesh/csgbsp.h index aa3e4d59..a2844992 100644 --- a/src/easymesh/csgbsp.h +++ b/src/easymesh/csgbsp.h @@ -1,16 +1,20 @@ // -// EasyMesh-Csg: The code belonging to CSG operations +// EasyMesh-Csg: The code belonging to CSG operations // -// Copyright: (c) 2010-2013 Sam Hocevar -// (c) 2010-2013 Benjamin "Touky" Huet -// 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 +// © 2010—2015 Benjamin "Touky" Huet +// +// 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 +#include "easyarray.h" + namespace lol { @@ -38,7 +42,7 @@ public: private: vec3 m_origin; vec3 m_normal; - array< int, vec3, vec3, vec3 > m_tri_list; + easy_array< int, vec3, vec3, vec3 > m_tri_list; ivec3 m_leaves; }; @@ -54,16 +58,16 @@ public: int TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2, //In order to easily build the actual vertices list afterward, this list stores each Vertices location and its source vertices & Alpha. // as { Point_Loc = Src_V0 + (Src_V1 - Src_V0) * Alpha; } - array< vec3, int, int, float > &vert_list, + easy_array< vec3, int, int, float > &vert_list, //This is the final triangle list : If Side_Status is LEAF_CURRENT, a new test will be done point by point. //<{IN|OUT}side_status, v0, v1, v2> - array< int, int, int, int > &tri_list); + easy_array< int, int, int, int > &tri_list); private: int AddLeaf(int leaf_type, vec3 origin, vec3 normal, int above_idx); int TestPoint(int leaf_idx, vec3 point); - array m_tree; + easy_array m_tree; }; } /* namespace lol */ diff --git a/src/lol/base/array.h b/src/easymesh/easyarray.h similarity index 92% rename from src/lol/base/array.h rename to src/easymesh/easyarray.h index 98002a95..01c10b05 100644 --- a/src/lol/base/array.h +++ b/src/easymesh/easyarray.h @@ -14,10 +14,10 @@ #pragma once // -// The array class -// ——————————————— +// The easyarray class +// ——————————————————— // A very simple array class not unlike the std::vector, with some nice -// additional features, eg. array for automatic arrays of tuples. +// additional features, eg. easy_array for automatic arrays of tuples. // #include // assert() @@ -229,17 +229,6 @@ public: ++m_count; } - inline bool insert_unique(T const &x, ptrdiff_t pos) - { - assert(pos >= 0 && pos <= m_count); - - if (find(x) != INDEX_NONE) - return false; - - insert(x, pos); - return true; - } - inline ptrdiff_t find(T const &x) { for (ptrdiff_t i = 0; i < m_count; ++i) @@ -439,10 +428,10 @@ protected: */ template -class array : public array_base, array> +class easy_array : public array_base, easy_array> { private: - using array_base, array>::array_base; + using array_base, easy_array>::array_base; // Mark these as private: it’s dangerous to use data() with arrays of // tuples because no assumption should be made about the tuple layout, @@ -489,10 +478,10 @@ public: }; template -class array - : public array_base> +class easy_array + : public array_base> { - using array_base>::array_base; + using array_base>::array_base; }; /* @@ -500,27 +489,27 @@ class array */ template -typename array::iterator begin(array &a) +typename easy_array::iterator begin(easy_array &a) { - return typename array::iterator(&a, 0); + return typename easy_array::iterator(&a, 0); } template -typename array::iterator end(array &a) +typename easy_array::iterator end(easy_array &a) { - return typename array::iterator(&a, a.count()); + return typename easy_array::iterator(&a, a.count()); } template -typename array::const_iterator begin(array const &a) +typename easy_array::const_iterator begin(easy_array const &a) { - return typename array::const_iterator(&a, 0); + return typename easy_array::const_iterator(&a, 0); } template -typename array::const_iterator end(array const &a) +typename easy_array::const_iterator end(easy_array const &a) { - return typename array::const_iterator(&a, a.count()); + return typename easy_array::const_iterator(&a, a.count()); } } /* namespace lol */ diff --git a/src/easymesh/easymesh.h b/src/easymesh/easymesh.h index 145c92d8..5f5041ed 100644 --- a/src/easymesh/easymesh.h +++ b/src/easymesh/easymesh.h @@ -1,9 +1,9 @@ // // Lol Engine // -// Copyright © 2009—2013 Cédric Lecacheur +// Copyright © 2010—2020 Sam Hocevar +// © 2009—2013 Cédric Lecacheur // © 2009—2013 Benjamin “Touky” Huet -// © 2010—2018 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -15,6 +15,7 @@ #pragma once #include "commandstack.h" +#include "easyarray.h" #include "easymeshrender.h" #include "easymeshbuild.h" @@ -100,7 +101,7 @@ public: void ExecuteCmdStack(bool ExecAllStack = true); private: - void UpdateVertexDict(array< int, int > &vertex_dict); + void UpdateVertexDict(easy_array< int, int > &vertex_dict); //------------------------------------------------------------------------- //Mesh CSG operations @@ -417,11 +418,11 @@ public: vec3 const &GetVertexLocation(int i) { return m_vert[i].m_coord; } //private: - array m_indices; - array m_vert; + easy_array m_indices; + easy_array m_vert; // - array m_cursors; + easy_array m_cursors; MeshRender m_state; diff --git a/src/easymesh/easymeshbuild.cpp b/src/easymesh/easymeshbuild.cpp index 0d419fc4..08ff3bf5 100644 --- a/src/easymesh/easymeshbuild.cpp +++ b/src/easymesh/easymeshbuild.cpp @@ -29,7 +29,7 @@ int VertexDictionnary::FindVertexMaster(const int search_idx) //----------------------------------------------------------------------------- //retrieve a list of matching vertices, doesn't include search_idx. -bool VertexDictionnary::FindMatchingVertices(const int search_idx, array &matching_ids) +bool VertexDictionnary::FindMatchingVertices(const int search_idx, easy_array &matching_ids) { int cur_mast = FindVertexMaster(search_idx); @@ -50,9 +50,9 @@ bool VertexDictionnary::FindMatchingVertices(const int search_idx, array &m //----------------------------------------------------------------------------- //Will return connected vertices (through triangles), if returned vertex has matching ones, it only returns the master. -bool VertexDictionnary::FindConnectedVertices(const int search_idx, const array &tri_list, const int tri0, array &connected_vert, array const *ignored_tri) +bool VertexDictionnary::FindConnectedVertices(const int search_idx, const easy_array &tri_list, const int tri0, easy_array &connected_vert, easy_array const *ignored_tri) { - array connected_tri; + easy_array connected_tri; FindConnectedTriangles(search_idx, tri_list, tri0, connected_tri, ignored_tri); for (int i = 0; i < connected_tri.count(); i++) @@ -80,20 +80,20 @@ bool VertexDictionnary::FindConnectedVertices(const int search_idx, const array< return (connected_vert.count() > 0); } //----------------------------------------------------------------------------- -bool VertexDictionnary::FindConnectedTriangles(const int search_idx, const array &tri_list, const int tri0, array &connected_tri, array const *ignored_tri) +bool VertexDictionnary::FindConnectedTriangles(const int search_idx, const easy_array &tri_list, const int tri0, easy_array &connected_tri, easy_array const *ignored_tri) { return FindConnectedTriangles(ivec3(search_idx, search_idx, search_idx), tri_list, tri0, connected_tri, ignored_tri); } //----------------------------------------------------------------------------- -bool VertexDictionnary::FindConnectedTriangles(const ivec2 &search_idx, const array &tri_list, const int tri0, array &connected_tri, array const *ignored_tri) +bool VertexDictionnary::FindConnectedTriangles(const ivec2 &search_idx, const easy_array &tri_list, const int tri0, easy_array &connected_tri, easy_array const *ignored_tri) { return FindConnectedTriangles(ivec3(search_idx, search_idx.x), tri_list, tri0, connected_tri, ignored_tri); } //----------------------------------------------------------------------------- -bool VertexDictionnary::FindConnectedTriangles(const ivec3 &search_idx, const array &tri_list, const int tri0, array &connected_tri, array const *ignored_tri) +bool VertexDictionnary::FindConnectedTriangles(const ivec3 &search_idx, const easy_array &tri_list, const int tri0, easy_array &connected_tri, easy_array const *ignored_tri) { int needed_validation = 0; - array vert_list[3]; + easy_array vert_list[3]; for (int i = 0; i < 3; i++) { //Small optim since above func will use this one diff --git a/src/easymesh/easymeshbuild.h b/src/easymesh/easymeshbuild.h index 376f69a0..d30cfbdb 100644 --- a/src/easymesh/easymeshbuild.h +++ b/src/easymesh/easymeshbuild.h @@ -296,7 +296,7 @@ public: inline CommandStack &CmdStack() { return m_stack; } inline int &Cmdi() { return m_i_cmd; } inline int &CmdExecNb() { return m_exec_nb; } - inline array &LoopStack(){ return m_loop_stack; } + inline easy_array &LoopStack(){ return m_loop_stack; } inline vec4 &ColorA() { return m_color_a; } inline vec4 &ColorB() { return m_color_b; } inline vec2 &TexCoordOffset() { return m_texcoord_offset; } @@ -496,15 +496,15 @@ public: CommandStack m_stack; int m_i_cmd; int m_exec_nb; - array m_loop_stack; + easy_array m_loop_stack; vec4 m_color_a; vec4 m_color_b; vec2 m_texcoord_offset; vec2 m_texcoord_offset2; vec2 m_texcoord_scale; vec2 m_texcoord_scale2; - array m_texcoord_custom_build[MeshType::MAX]; - array m_texcoord_custom_build2[MeshType::MAX]; + easy_array m_texcoord_custom_build[MeshType::MAX]; + easy_array m_texcoord_custom_build2[MeshType::MAX]; uint32_t m_texcoord_build_type[MeshType::MAX]; uint32_t m_texcoord_build_type2[MeshType::MAX]; uint32_t m_build_flags = MeshBuildOperation::PreventVertCleanup; @@ -536,20 +536,20 @@ class VertexDictionnary { public: int FindVertexMaster(const int search_idx); - bool FindMatchingVertices(const int search_idx, array &matching_ids); - bool FindConnectedVertices(const int search_idx, const array &tri_list, const int tri0, array &connected_vert, array const *ignored_tri = nullptr); - bool FindConnectedTriangles(const int search_idx, const array &tri_list, const int tri0, array &connected_tri, array const *ignored_tri = nullptr); - bool FindConnectedTriangles(const ivec2 &search_idx, const array &tri_list, const int tri0, array &connected_tri, array const *ignored_tri = nullptr); - bool FindConnectedTriangles(const ivec3 &search_idx, const array &tri_list, const int tri0, array &connected_tri, array const *ignored_tri = nullptr); + bool FindMatchingVertices(const int search_idx, easy_array &matching_ids); + bool FindConnectedVertices(const int search_idx, const easy_array &tri_list, const int tri0, easy_array &connected_vert, easy_array const *ignored_tri = nullptr); + bool FindConnectedTriangles(const int search_idx, const easy_array &tri_list, const int tri0, easy_array &connected_tri, easy_array const *ignored_tri = nullptr); + bool FindConnectedTriangles(const ivec2 &search_idx, const easy_array &tri_list, const int tri0, easy_array &connected_tri, easy_array const *ignored_tri = nullptr); + bool FindConnectedTriangles(const ivec3 &search_idx, const easy_array &tri_list, const int tri0, easy_array &connected_tri, easy_array const *ignored_tri = nullptr); void RegisterVertex(int vert_id, vec3 vert_coord); void RemoveVertex(int vert_id); - bool GetMasterList(array &ret_master_list) { ret_master_list = master_list; return ret_master_list.count() > 0; } + bool GetMasterList(easy_array &ret_master_list) { ret_master_list = master_list; return ret_master_list.count() > 0; } void Clear() { vertex_list.clear(); } private: // - array vertex_list; + easy_array vertex_list; //List of the master_ vertices - array master_list; + easy_array master_list; }; } /* namespace lol */ diff --git a/src/easymesh/easymeshcsg.cpp b/src/easymesh/easymeshcsg.cpp index e701d9c9..0408e678 100644 --- a/src/easymesh/easymeshcsg.cpp +++ b/src/easymesh/easymeshcsg.cpp @@ -35,13 +35,13 @@ void EasyMesh::MeshCsg(CSGUsage csg_operation) } //A vertex dictionnary for vertices on the same spot. - array< int, int > vertex_dict; + easy_array< int, int > vertex_dict; //This list keeps track of the triangle that will need deletion at the end. - array< int > triangle_to_kill; + easy_array< int > triangle_to_kill; //Listing for each triangle of the vectors intersecting it. > - array< int, array< vec3, vec3, vec3 > > triangle_isec; + easy_array< int, easy_array< vec3, vec3, vec3 > > triangle_isec; //keep a track of the intersection point on the triangle. - array< vec3, int > triangle_vertex; + easy_array< vec3, int > triangle_vertex; for (int k = 0; k < 10; k++) triangle_vertex.push(vec3(.0f), 0); @@ -72,8 +72,8 @@ void EasyMesh::MeshCsg(CSGUsage csg_operation) 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; + easy_array< vec3, int, int, float > vert_list; + easy_array< int, int, int, int > tri_list; vec3 n0(.0f); vec3 n1(.0f); vec4 c0(.0f); vec4 c1(.0f); diff --git a/src/easymesh/easymeshinternal.cpp b/src/easymesh/easymeshinternal.cpp index 5e8518e0..f79ae72d 100644 --- a/src/easymesh/easymeshinternal.cpp +++ b/src/easymesh/easymeshinternal.cpp @@ -127,7 +127,7 @@ void EasyMesh::ComputeNormals(int start, int vcount) BD()->IsEnabled(MeshBuildOperation::PostBuildComputeNormals)) return; - array< array > normals; + easy_array< easy_array > normals; normals.resize(m_vert.count()); for (int i = 0; i < vcount; i += 3) { @@ -162,7 +162,7 @@ void EasyMesh::ComputeNormals(int start, int vcount) //----------------------------------------------------------------------------- void EasyMesh::VerticesCleanup() { - array vert_ids; + easy_array vert_ids; vert_ids.resize(m_vert.count(), 0); //1: Remove triangles with two vertices on each other @@ -186,7 +186,7 @@ void EasyMesh::VerticesCleanup() } //2: Remove all unused vertices - array old_vert = m_vert; + easy_array old_vert = m_vert; int shift = 0; m_vert.clear(); for (int i = 0; i < vert_ids.count(); ++i) @@ -240,8 +240,8 @@ void EasyMesh::VerticesSeparate() return; } - array< array > new_ids; - array vert_ids; + easy_array< easy_array > new_ids; + easy_array vert_ids; vert_ids.resize(m_vert.count(), 0); //1: Mark all used vertices @@ -283,7 +283,7 @@ void EasyMesh::ComputeTexCoord(float uv_scale, int uv_offset) UNUSED(uv_scale, uv_offset); #if 0 VertexDictionnary vert_dict; - array tri_list; + easy_array tri_list; 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++) @@ -293,8 +293,8 @@ void EasyMesh::ComputeTexCoord(float uv_scale, int uv_offset) } //full triangle count - array tri_done; - array tri_check; + easy_array tri_done; + easy_array tri_check; int tri_count = (m_indices.count() - std::get<1>(m_cursors.last())) / 3; tri_check << tri_list[0]; @@ -390,7 +390,7 @@ void EasyMesh::ComputeTexCoord(float uv_scale, int uv_offset) uv[2] = texu_dir * dot(v01, v02) + texv_dir * dot(v_dir, v02); //Set UV on ALL matching vertices! - array matching_vert; + easy_array matching_vert; for (int i = 0; i < 3; i++) { #if 1 diff --git a/src/easymesh/easymeshlua.cpp b/src/easymesh/easymeshlua.cpp index 30fdf7fe..d527482e 100644 --- a/src/easymesh/easymeshlua.cpp +++ b/src/easymesh/easymeshlua.cpp @@ -1,8 +1,8 @@ // // Lol Engine // -// Copyright © 2009—2015 Benjamin “Touky” Huet -// © 2017—2018 Sam Hocevar +// Copyright © 2017—2020 Sam Hocevar +// © 2009—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -46,7 +46,7 @@ EasyMeshLuaLoader::~EasyMeshLuaLoader() } //----------------------------------------------------------------------------- -static array g_instances; +static easy_array g_instances; void EasyMeshLuaLoader::Store(LuaObject* obj) { EasyMeshLuaObject* ezm = static_cast(obj); @@ -54,7 +54,7 @@ void EasyMeshLuaLoader::Store(LuaObject* obj) } //----------------------------------------------------------------------------- -array& EasyMeshLuaLoader::GetInstances() +easy_array& EasyMeshLuaLoader::GetInstances() { return g_instances; } diff --git a/src/easymesh/easymeshlua.h b/src/easymesh/easymeshlua.h index 1a5e3dee..cff691eb 100644 --- a/src/easymesh/easymeshlua.h +++ b/src/easymesh/easymeshlua.h @@ -1,8 +1,8 @@ // // Lol Engine // -// Copyright © 2009—2015 Benjamin “Touky” Huet -// © 2017—2018 Sam Hocevar +// Copyright © 2017—2020 Sam Hocevar +// © 2009—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -141,7 +141,7 @@ public: virtual ~EasyMeshLuaLoader(); //Virtual Store lua object ------------------------------------------------ virtual void Store(LuaObject* obj); - array& GetInstances(); + easy_array& GetInstances(); //------------------------------------------------------------------------- protected: diff --git a/src/easymesh/easymeshprimitive.cpp b/src/easymesh/easymeshprimitive.cpp index c3587741..ae700340 100644 --- a/src/easymesh/easymeshprimitive.cpp +++ b/src/easymesh/easymeshprimitive.cpp @@ -141,7 +141,7 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float d) int ibase = m_indices.count(); - array vertices; + easy_array vertices; float uv_h = 0; float uv_r = 0; diff --git a/src/easymesh/easymeshrender.h b/src/easymesh/easymeshrender.h index 8f92017d..d809e2dd 100644 --- a/src/easymesh/easymeshrender.h +++ b/src/easymesh/easymeshrender.h @@ -94,8 +94,8 @@ protected: std::shared_ptr m_shader; int m_render_mode; uint16_t m_vert_decl_flags; - array m_shader_uniform; - array m_shader_attrib; + easy_array m_shader_uniform; + easy_array m_shader_attrib; }; class DefaultShaderData : public GpuShaderData @@ -110,7 +110,7 @@ public: void SetupDefaultData(bool with_UV); virtual void SetupShaderDatas(mat4 const &model); //-- - array m_uniform_names; + easy_array m_uniform_names; }; class GpuEasyMeshData @@ -129,9 +129,9 @@ public: private: void SetupVertexData(uint16_t vdecl_flags, std::shared_ptr src_mesh); - array> m_gpudata; + easy_array> m_gpudata; //uint16_t are the vdecl/vbo flags to avoid copy same vdecl several times. - array, std::shared_ptr> m_vdata; + easy_array, std::shared_ptr> m_vdata; size_t m_vertexcount; //We only need only one ibo for the whole mesh std::shared_ptr m_ibo; diff --git a/src/easymesh/easymeshtransform.cpp b/src/easymesh/easymeshtransform.cpp index bf53d2dd..dc0b325c 100644 --- a/src/easymesh/easymeshtransform.cpp +++ b/src/easymesh/easymeshtransform.cpp @@ -71,7 +71,7 @@ void EasyMesh::RadialJitter(float r) return; } - array welded; + easy_array welded; welded.push(-1); for (int i = std::get<0>(m_cursors.last()) + 1; i < m_vert.count(); i++) { @@ -371,10 +371,10 @@ void EasyMesh::SmoothMesh(int main_pass, int split_per_main_pass, int smooth_per } VertexDictionnary vert_dict; - array smooth_buf[2]; - array master_list; - array matching_ids; - array connected_vert; + easy_array smooth_buf[2]; + easy_array master_list; + easy_array matching_ids; + easy_array connected_vert; int smbuf = 0; for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) diff --git a/src/engine/ticker.cpp b/src/engine/ticker.cpp index 0af9e28b..a6f5c31f 100644 --- a/src/engine/ticker.cpp +++ b/src/engine/ticker.cpp @@ -15,6 +15,7 @@ #include // std::unordered_set #include #include +#include // std::vector #include namespace lol @@ -45,8 +46,8 @@ public: { ASSERT(DEPRECATED_nentities == 0, "still %d entities in ticker\n", DEPRECATED_nentities); - ASSERT(DEPRECATED_m_autolist.count() == 0, - "still %d autoreleased entities\n", DEPRECATED_m_autolist.count()); + ASSERT(DEPRECATED_m_autolist.size() == 0, + "still %d autoreleased entities\n", int(DEPRECATED_m_autolist.size())); msg::debug("%d frames required to quit\n", m_frame - m_quitframe); if (thread::has_threads()) @@ -69,8 +70,8 @@ private: std::unordered_set> m_tickables; /* Entity management */ - array DEPRECATED_m_todolist, DEPRECATED_m_todolist_delayed, DEPRECATED_m_autolist; - array DEPRECATED_m_list[(int)tickable::group::all::end]; + std::vector DEPRECATED_m_todolist, DEPRECATED_m_todolist_delayed, DEPRECATED_m_autolist; + std::vector DEPRECATED_m_list[(int)tickable::group::all::end]; std::vector DEPRECATED_m_scenes[(int)tickable::group::all::end]; int DEPRECATED_nentities = 0; @@ -124,10 +125,10 @@ void Ticker::Register(entity *entity) /* If we are called from its constructor, the object's vtable is not * ready yet, so we do not know which group this entity belongs to. Wait * until the first tick. */ - data->DEPRECATED_m_todolist_delayed.push(entity); + data->DEPRECATED_m_todolist_delayed.push_back(entity); /* Objects are autoreleased by default. Put them in a list. */ - data->DEPRECATED_m_autolist.push(entity); + data->DEPRECATED_m_autolist.push_back(entity); entity->add_flags(entity::flags::autorelease); entity->m_ref = 1; @@ -146,11 +147,11 @@ void Ticker::Ref(entity *entity) /* Get the entity out of the autorelease list. This is usually * very fast since the last entry in autolist is the last * registered entity. */ - for (int i = data->DEPRECATED_m_autolist.count(); i--; ) + for (size_t i = data->DEPRECATED_m_autolist.size(); i--; ) { if (data->DEPRECATED_m_autolist[i] == entity) { - data->DEPRECATED_m_autolist.remove_swap(i); + remove_at(data->DEPRECATED_m_autolist, i); break; } } @@ -238,7 +239,7 @@ void ticker_data::GameThreadTick() msg::debug("%s Group %d\n", (g < (int)tickable::group::game::end) ? "Game" : "Draw", g); - for (int i = 0; i < data->DEPRECATED_m_list[g].count(); ++i) + for (size_t i = 0; i < data->DEPRECATED_m_list[g].size(); ++i) { entity *e = data->DEPRECATED_m_list[g][i]; msg::debug(" \\-- [%p] %s (m_ref %d, destroy %d)\n", @@ -283,9 +284,9 @@ void ticker_data::GameThreadTick() data->collect_garbage(); /* Insert waiting objects into the appropriate lists */ - while (data->DEPRECATED_m_todolist.count()) + while (data->DEPRECATED_m_todolist.size()) { - entity *e = data->DEPRECATED_m_todolist.last(); + entity *e = data->DEPRECATED_m_todolist.back(); //If the entity has no mask, default it if (e->m_scene_mask == 0) @@ -293,8 +294,8 @@ void ticker_data::GameThreadTick() Scene::GetScene().Link(e); } - data->DEPRECATED_m_todolist.remove(-1); - data->DEPRECATED_m_list[(int)e->m_gamegroup].push(e); + data->DEPRECATED_m_todolist.pop_back(); + data->DEPRECATED_m_list[(int)e->m_gamegroup].push_back(e); if (e->m_drawgroup != tickable::group::draw::none) { if (data->DEPRECATED_m_scenes[(int)e->m_drawgroup].size() < Scene::GetCount()) @@ -306,7 +307,7 @@ void ticker_data::GameThreadTick() //If entity is concerned by this scene, add it in the list if (Scene::GetScene(i).IsRelevant(e)) { - data->DEPRECATED_m_list[(int)e->m_drawgroup].insert(e, data->DEPRECATED_m_scenes[(int)e->m_drawgroup][i]); + insert_at(data->DEPRECATED_m_list[(int)e->m_drawgroup], data->DEPRECATED_m_scenes[(int)e->m_drawgroup][i], e); added_count++; } //Update scene index @@ -320,7 +321,7 @@ void ticker_data::GameThreadTick() for (int g = (int)tickable::group::game::begin; g < (int)tickable::group::game::end; ++g) { - for (int i = 0; i < data->DEPRECATED_m_list[g].count(); ++i) + for (size_t i = 0; i < data->DEPRECATED_m_list[g].size(); ++i) { entity *e = data->DEPRECATED_m_list[g][i]; @@ -342,7 +343,7 @@ void ticker_data::GameThreadTick() /* Tick objects for the game loop */ for (int g = (int)tickable::group::game::begin; g < (int)tickable::group::game::end && !data->m_quit /* Stop as soon as required */; ++g) { - for (int i = 0; i < data->DEPRECATED_m_list[g].count() && !data->m_quit /* Stop as soon as required */; ++i) + for (size_t i = 0; i < data->DEPRECATED_m_list[g].size() && !data->m_quit /* Stop as soon as required */; ++i) { entity *e = data->DEPRECATED_m_list[g][i]; @@ -376,7 +377,7 @@ void ticker_data::DrawThreadTick() for (int g = (int)tickable::group::draw::begin; g < (int)tickable::group::draw::end; ++g) { - for (int i = 0; i < data->DEPRECATED_m_list[g].count(); ++i) + for (size_t i = 0; i < data->DEPRECATED_m_list[g].size(); ++i) { entity *e = data->DEPRECATED_m_list[g][i]; @@ -417,7 +418,7 @@ void ticker_data::DrawThreadTick() break; } - for (int i = 0; i < data->DEPRECATED_m_list[g].count() && !data->m_quit /* Stop as soon as required */; ++i) + for (size_t i = 0; i < data->DEPRECATED_m_list[g].size() && !data->m_quit /* Stop as soon as required */; ++i) { entity *e = data->DEPRECATED_m_list[g][i]; @@ -465,7 +466,7 @@ void ticker_data::handle_shutdown() m_panic = 2 * (m_panic + 1); for (int g = 0; g < (int)tickable::group::all::end && n < m_panic; ++g) - for (int i = 0; i < DEPRECATED_m_list[g].count() && n < m_panic; ++i) + for (size_t i = 0; i < DEPRECATED_m_list[g].size() && n < m_panic; ++i) { entity * e = DEPRECATED_m_list[g][i]; if (e->m_ref) @@ -496,7 +497,7 @@ void ticker_data::collect_garbage() std::unordered_set destroy_list; for (int g = 0; g < (int)tickable::group::all::end; ++g) { - for (int i = DEPRECATED_m_list[g].count(); i--;) + for (size_t i = DEPRECATED_m_list[g].size(); i--;) { entity *e = DEPRECATED_m_list[g][i]; @@ -513,7 +514,7 @@ void ticker_data::collect_garbage() continue; // If entity is to be destroyed, remove it. - DEPRECATED_m_list[g].remove_swap(i); + remove_at(DEPRECATED_m_list[g], i); // Draw group specific logic if (g >= (int)tickable::group::game::end) @@ -626,10 +627,10 @@ int Ticker::GetFrameNum() void Ticker::Shutdown() { /* We're bailing out. Release all autorelease objects. */ - while (data->DEPRECATED_m_autolist.count()) + while (data->DEPRECATED_m_autolist.size()) { - data->DEPRECATED_m_autolist.last()->m_ref--; - data->DEPRECATED_m_autolist.remove(-1); + --data->DEPRECATED_m_autolist.back()->m_ref; + data->DEPRECATED_m_autolist.pop_back(); } data->m_quit = 1; diff --git a/src/image/codec/oric-image.cpp b/src/image/codec/oric-image.cpp index d092786c..295afe8d 100644 --- a/src/image/codec/oric-image.cpp +++ b/src/image/codec/oric-image.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2019 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -39,7 +39,7 @@ public: private: static std::string ReadScreen(std::string const &name); - static void WriteScreen(image &image, array &result); + static void WriteScreen(image &image, std::vector &result); }; DECLARE_IMAGE_CODEC(OricImageCodec, 100) @@ -122,15 +122,16 @@ bool OricImageCodec::Save(std::string const &path, ResourceCodecData* data) || std::toupper(path[len - 1]) != 'P') return false; - array result; + std::vector result; - result << 0x16 << 0x16 << 0x16 << 0x16 << 0x24; - result << 0 << 0xff << 0x80 << 0 << 0xbf << 0x3f << 0xa0 << 0; + for (auto b : { 0x16, 0x16, 0x16, 0x16, 0x24, 0, 0xff, + 0x80, 0, 0xbf, 0x3f, 0xa0, 0 }) + result.push_back(b); /* Add filename, except the last 4 characters */ for (char const *name = path.c_str(); name[4]; ++name) - result << (uint8_t)name[0]; - result << 0; + result.push_back(uint8_t(name[0])); + result.push_back(0); auto img = data_image->m_image; image tmp; @@ -147,7 +148,7 @@ bool OricImageCodec::Save(std::string const &path, ResourceCodecData* data) File f; f.Open(path, FileAccess::Write); - f.Write(result.data(), result.bytes()); + f.Write(result.data(), result.size()); f.Close(); return true; @@ -472,7 +473,7 @@ static uint8_t bestmove(ivec3 const *in, u8vec2 bgfg, return bestcommand; } -void OricImageCodec::WriteScreen(image &img, array &result) +void OricImageCodec::WriteScreen(image &img, std::vector &result) { ivec2 size = img.size(); vec4 *pixels = img.lock(); @@ -525,7 +526,7 @@ void OricImageCodec::WriteScreen(image &img, array &result) /* Iterate */ bgfg = domove(command, bgfg); /* Write byte to file */ - result << command; + result.push_back(command); } } diff --git a/src/image/filter/convolution.cpp b/src/image/filter/convolution.cpp index 43ba845a..a8efd81e 100644 --- a/src/image/filter/convolution.cpp +++ b/src/image/filter/convolution.cpp @@ -12,6 +12,8 @@ #include +#include + /* * Generic convolution functions */ @@ -19,8 +21,8 @@ namespace lol { -static image SepConv(image &src, array const &hvec, - array const &vvec); +static image SepConv(image &src, std::vector const &hvec, + std::vector const &vvec); static image NonSepConv(image &src, array2d const &in_kernel); image image::Convolution(array2d const &in_kernel) @@ -65,13 +67,13 @@ image image::Convolution(array2d const &in_kernel) if (separable) { /* Matrix rank is 1! Separate the filter. */ - array hvec, vvec; + std::vector hvec, vvec; float norm = 1.0f / lol::sqrt(lol::fabs(in_kernel[bestx][besty])); for (int dx = 0; dx < ksize.x; dx++) - hvec << norm * in_kernel[dx][besty]; + hvec.push_back(norm * in_kernel[dx][besty]); for (int dy = 0; dy < ksize.y; dy++) - vvec << norm * in_kernel[bestx][dy]; + vvec.push_back(norm * in_kernel[bestx][dy]); return SepConv(*this, hvec, vvec); } @@ -190,13 +192,13 @@ static image NonSepConv(image &src, array2d const &in_kernel) } template -static image SepConv(image &src, array const &hvec, - array const &vvec) +static image SepConv(image &src, std::vector const &hvec, + std::vector const &vvec) { typedef typename PixelType::type pixel_t; ivec2 const size = src.size(); - ivec2 const ksize(hvec.count(), vvec.count()); + ivec2 const ksize(int(hvec.size()), int(vvec.size())); image dst(size); array2d const &srcp = src.lock2d(); @@ -252,8 +254,8 @@ static image SepConv(image &src, array const &hvec, return dst; } -static image SepConv(image &src, array const &hvec, - array const &vvec) +static image SepConv(image &src, std::vector const &hvec, + std::vector const &vvec) { bool const wrap_x = src.GetWrapX() == WrapMode::Repeat; bool const wrap_y = src.GetWrapY() == WrapMode::Repeat; diff --git a/src/image/kernel.cpp b/src/image/kernel.cpp index 707e18b2..d5a5e2ec 100644 --- a/src/image/kernel.cpp +++ b/src/image/kernel.cpp @@ -186,7 +186,7 @@ array2d image::kernel::normalize(array2d const &kernel) { ivec2 size = kernel.sizes(); - array tmp; + std::vector tmp; tmp.resize(size.x * size.y); for (int y = 0; y < size.y; y++) @@ -196,6 +196,7 @@ array2d image::kernel::normalize(array2d const &kernel) tmp[y * size.x + x].y = y; tmp[y * size.x + x].val = kernel[x][y]; } + // FIXME: get rid of qsort and use proper C++ algorithms std::qsort(tmp.data(), size.x * size.y, sizeof(Dot), cmpdot); array2d dst(size); diff --git a/src/image/resample.cpp b/src/image/resample.cpp index efe169b7..cd84370b 100644 --- a/src/image/resample.cpp +++ b/src/image/resample.cpp @@ -12,6 +12,8 @@ #include +#include // std::vector + /* * Image resizing functions */ @@ -145,16 +147,16 @@ static image ResizeBresenham(image &src, ivec2 size) vec4 const *srcp = src.lock(); vec4 *dstp = dst.lock(); - array aline, line; + std::vector aline, line; aline.resize(size.x); line.resize(size.x); - memset((void *)line.data(), 0, line.bytes()); + memset((void *)line.data(), 0, line.size() * sizeof(line[0])); int remy = 0; for (int y = 0, y0 = 0; y < size.y; y++) { - memset((void *)aline.data(), 0, aline.bytes()); + memset((void *)aline.data(), 0, aline.size() * sizeof(aline[0])); for (int toty = 0; toty < oldsize.y; ) { diff --git a/src/image/resource-private.h b/src/image/resource-private.h index 616fdb0a..f584e561 100644 --- a/src/image/resource-private.h +++ b/src/image/resource-private.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2018 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // © 2016—2017 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to @@ -13,6 +13,9 @@ #pragma once +#include +#include + // // The ResourceCodecData class // ------------------------ @@ -29,7 +32,7 @@ namespace lol virtual bool Save(std::string const &path, ResourceCodecData* data) = 0; /* TODO: this should become more fine-grained */ - int m_priority; + size_t m_priority; }; #define REGISTER_IMAGE_CODEC(name) \ @@ -37,13 +40,13 @@ namespace lol { \ /* Insert image codecs in a sorted list */ \ ResourceCodec *codec = Register##name(); \ - int i = 0, prio = codec->m_priority; \ - for ( ; i < codeclist.count(); ++i) \ + size_t i = 0, prio = codec->m_priority; \ + for ( ; i < codeclist.size(); ++i) \ { \ if (codeclist[i]->m_priority <= prio) \ break; \ } \ - codeclist.insert(codec, i); \ + insert_at(codeclist, i, codec); \ } #define DECLARE_IMAGE_CODEC(name, priority) \ diff --git a/src/image/resource.cpp b/src/image/resource.cpp index eda0264a..3bd782bc 100644 --- a/src/image/resource.cpp +++ b/src/image/resource.cpp @@ -30,7 +30,7 @@ namespace lol * The bug was reported to Microsoft and fixed by them, but the fix * is not yet available. * https://connect.microsoft.com/VisualStudio/feedback/details/730878/ */ -static bool RegisterAllCodecs(array &codeclist) +static bool RegisterAllCodecs(std::vector &codeclist) { #if defined __ANDROID__ REGISTER_IMAGE_CODEC(AndroidImageCodec) @@ -69,7 +69,7 @@ public: } private: - array m_codecs; + std::vector m_codecs; } g_resource_loader; diff --git a/src/lol-core.vcxproj b/src/lol-core.vcxproj index 6a7ca04f..27b69c99 100644 --- a/src/lol-core.vcxproj +++ b/src/lol-core.vcxproj @@ -215,6 +215,7 @@ + @@ -236,7 +237,6 @@ - @@ -296,7 +296,6 @@ true - diff --git a/src/lol-core.vcxproj.filters b/src/lol-core.vcxproj.filters index 48329e3a..2e301086 100644 --- a/src/lol-core.vcxproj.filters +++ b/src/lol-core.vcxproj.filters @@ -260,6 +260,9 @@ easymesh + + easymesh + easymesh @@ -296,9 +299,6 @@ lolua - - lol\base - lol\base @@ -423,7 +423,6 @@ ui - lol\base diff --git a/src/lol/base/all.h b/src/lol/base/all.h index 5f1da973..27a75fa6 100644 --- a/src/lol/base/all.h +++ b/src/lol/base/all.h @@ -17,7 +17,6 @@ #include <../legacy/lol/base/types.h> #include #include <../legacy/lol/base/assert.h> -#include #include <../legacy/lol/base/avl_tree.h> #include diff --git a/src/lol/extras.h b/src/lol/extras.h index 9d684f44..1b4146c0 100644 --- a/src/lol/extras.h +++ b/src/lol/extras.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2019 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -17,7 +17,6 @@ // -------------------------------------------------------- // -#include #include // Static classes diff --git a/src/lolua/baselua.cpp b/src/lolua/baselua.cpp index 12bfea5e..1544f1e9 100644 --- a/src/lolua/baselua.cpp +++ b/src/lolua/baselua.cpp @@ -122,20 +122,20 @@ Loader::~Loader() //Store loader ------------------------------------------------------------ // FIXME: change this to a map? -static array g_loaders; +static std::vector> g_loaders; void Loader::Store(lua_State* l, Lolua::Loader* loader) { - g_loaders.push(l, loader); + g_loaders.push_back(std::make_tuple(l, loader)); } void Loader::Release(lua_State* l, Lolua::Loader* loader) { - for (int i = 0; i < g_loaders.count(); ++i) + for (size_t i = 0; i < g_loaders.size(); ++i) { if (std::get<0>(g_loaders[i]) == l && std::get<1>(g_loaders[i]) == loader) { - g_loaders.remove(i); + remove_at(g_loaders, i); return; } } diff --git a/src/lolua/baselua.h b/src/lolua/baselua.h index ebb986a0..a44528c0 100644 --- a/src/lolua/baselua.h +++ b/src/lolua/baselua.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2017—2018 Sam Hocevar +// Copyright © 2017—2020 Sam Hocevar // © 2009—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to @@ -19,7 +19,9 @@ extern "C" { #include "3rdparty/lua/lauxlib.h" } -#include +#include // std::vector +#include // std::string +#include // tolower // // Base Lua class for Lua script loading @@ -65,45 +67,45 @@ public: } ClassVarStr; Library(std::string const &class_name, - array const& statics, - array const& methods, - array const& variables) + std::vector const& statics, + std::vector const& methods, + std::vector const& variables) { m_class_name = class_name; m_static_name = class_name + "_lib"; m_method_name = class_name + "_inst"; m_statics = statics; - if (m_statics.count() == 0 - || m_statics.last().name != nullptr - || m_statics.last().func != nullptr) - m_statics.push({ nullptr, nullptr }); + if (m_statics.empty() + || m_statics.back().name != nullptr + || m_statics.back().func != nullptr) + m_statics.push_back({ nullptr, nullptr }); m_methods = methods; - if (m_methods.count() == 0 - || m_methods.last().name != nullptr - || m_methods.last().func != nullptr) - m_methods.push({ nullptr, nullptr }); + if (m_methods.empty() + || m_methods.back().name != nullptr + || m_methods.back().func != nullptr) + m_methods.push_back({ nullptr, nullptr }); for (ClassVar const& cv : variables) { if (cv.name && cv.get && cv.set) { - m_variables.push({ cv.name, cv.get, cv.set }); + m_variables.push_back({ cv.name, cv.get, cv.set }); } } - if (m_variables.count() == 0 - || variables.last().name != nullptr - || variables.last().get != nullptr - || variables.last().set != nullptr) - m_variables.push(ClassVarStr()); + if (m_variables.empty() + || variables.back().name != nullptr + || variables.back().get != nullptr + || variables.back().set != nullptr) + m_variables.push_back(ClassVarStr()); } std::string m_class_name = ""; std::string m_static_name = ""; std::string m_method_name = ""; - array m_statics; - array m_methods; - array m_variables; + std::vector m_statics; + std::vector m_methods; + std::vector m_variables; }; public: @@ -173,7 +175,7 @@ public: lua_setfield(l, -1, "__index"); //Create variables Get/Set - const array& variables = GetVariables(); + const std::vector& variables = GetVariables(); for (const Object::Library::ClassVarStr& var : variables) { if (!var.m_get || !var.m_set) @@ -215,7 +217,7 @@ public: template static const ClassMethod* GetInstanceMethods() { return GetLibrary()->m_methods.data(); } template - static const array& GetVariables() { return GetLibrary()->m_variables; } + static const std::vector& GetVariables() { return GetLibrary()->m_variables; } protected: //------------------------------------------------------------------------- @@ -387,6 +389,16 @@ protected: template int InnerPush(T value) { UNUSED(value); ASSERT(false, INNER_ERROR); return 0; } #ifndef INNER_SAFE_ENUM + // Gets the value for the given enum type. + template static inline T FindValue(std::string const& name) + { + std::string needle = tolower(name); + for (int i = 0; i < T::Max; ++i) + if (tolower(T(i).tostring()).find(needle) != std::string::npos) + return T(i); + return T::Max; + } + template SafeEnum InnerDefaultSafeEnum() { return SafeEnum(); } template bool InnerIsValidSafeEnum() { return InnerIsValid(); } template SafeEnum InnerGetSafeEnum(SafeEnum value) { return FindValue >(InnerGet(value.tostring())); } diff --git a/src/mesh/mesh.cpp b/src/mesh/mesh.cpp index a58f9438..e7e36198 100644 --- a/src/mesh/mesh.cpp +++ b/src/mesh/mesh.cpp @@ -12,7 +12,8 @@ #include -#include +#include // std::shared_ptr +#include // std::make_tuple #include #include @@ -33,7 +34,7 @@ Mesh::~Mesh() void Mesh::Render(Scene& scene, mat4 const &matrix) { - //if (scene.HasPrimitiveRenderer(this) < m_submeshes.count()) + //if (scene.HasPrimitiveRenderer(this) < m_submeshes.size()) { for (auto submesh : m_submeshes) scene.AddPrimitiveRenderer(this, std::make_shared(submesh, matrix)); @@ -89,8 +90,8 @@ void SubMesh::SetVertexDeclaration(std::shared_ptr vdecl) void SubMesh::SetVertexBuffer(int index, std::shared_ptr vbo) { - while (index >= m_vbos.count()) - m_vbos.push(nullptr); + while (index >= int(m_vbos.size())) + m_vbos.push_back(nullptr); m_vbos[index] = vbo; } @@ -102,7 +103,7 @@ void SubMesh::SetIndexBuffer(std::shared_ptr ibo) void SubMesh::AddTexture(std::string const &name, std::shared_ptr texture) { - m_textures.push(name, texture); + m_textures.push_back(std::make_tuple(name, texture)); } void SubMesh::Render() @@ -111,7 +112,7 @@ void SubMesh::Render() m_vdecl->Bind(); - for (int i = 0; i < m_vbos.count(); ++i) + for (size_t i = 0; i < m_vbos.size(); ++i) { ShaderAttrib attribs[12]; @@ -137,7 +138,7 @@ void SubMesh::Render() UNUSED(vertex_count); - for (int i = 0; i < m_textures.count(); ++i) + for (size_t i = 0; i < m_textures.size(); ++i) { // TODO: might be good to cache this ShaderUniform u_tex = m_shader->GetUniformLocation(std::get<0>(m_textures[i])); diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 11e7f656..8b8c9570 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2019 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -105,11 +105,11 @@ protected: MeshPrimitive m_mesh_prim; std::shared_ptr m_shader; std::shared_ptr m_vdecl; - array> m_vbos; + std::vector> m_vbos; std::shared_ptr m_ibo; - array> m_textures; + std::vector>> m_textures; }; -} /* namespace lol */ +} // namespace lol diff --git a/src/messageservice.cpp b/src/messageservice.cpp index a2a10629..a9ab5415 100644 --- a/src/messageservice.cpp +++ b/src/messageservice.cpp @@ -1,8 +1,8 @@ // // Lol Engine // -// Copyright © 2013—2015 Benjamin “Touky” Huet -// © 2017—2019 Sam Hocevar +// Copyright © 2017—2020 Sam Hocevar +// © 2013—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -67,8 +67,8 @@ bool MessageService::Send(MessageBucket id, const std::string& message) if (g_messageservice) { MessageService& g = *g_messageservice; - array& bucket = g.m_bucket[id.ToScalar()]; - bucket << MessageList(time(nullptr), message); + auto& bucket = g.m_bucket[id.ToScalar()]; + bucket.push_back(MessageList(time(nullptr), message)); return true; } return false; @@ -79,7 +79,6 @@ bool MessageService::FetchFirst(MessageBucket id, std::string& message) { if (g_messageservice) { - ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); time_t timestamp; return g_messageservice->FetchFirst(id, message, timestamp); } @@ -90,15 +89,14 @@ bool MessageService::FetchFirst(MessageBucket id, std::string& message, time_t& { if (g_messageservice) { - ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); MessageService& g = *g_messageservice; - array& bucket = g.m_bucket[id.ToScalar()]; + auto& bucket = g.m_bucket[id.ToScalar()]; - if (bucket.count()) + if (bucket.size()) { message = bucket[0].m_message; timestamp = bucket[0].m_timestamp; - bucket.remove(0); + remove_at(bucket, 0); return true; } } @@ -110,7 +108,6 @@ bool MessageService::FetchAll(MessageBucket id, std::string& message) { if (g_messageservice) { - ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); time_t timestamp; return g_messageservice->FetchAll(id, message, timestamp); } @@ -121,15 +118,14 @@ bool MessageService::FetchAll(MessageBucket id, std::string& message, time_t& fi { if (g_messageservice) { - ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); MessageService& g = *g_messageservice; - array& bucket = g.m_bucket[id.ToScalar()]; + auto& bucket = g.m_bucket[id.ToScalar()]; message = ""; - if (bucket.count()) + if (bucket.size()) { first_timestamp = bucket[0].m_timestamp; - for (int i = 0; i < bucket.count(); ++i) + for (size_t i = 0; i < bucket.size(); ++i) message += bucket[i].m_message; bucket.clear(); return true; @@ -138,5 +134,5 @@ bool MessageService::FetchAll(MessageBucket id, std::string& message, time_t& fi return false; } -} /* namespace lol */ +} // namespace lol diff --git a/src/messageservice.h b/src/messageservice.h index dae9bfb0..19a92cf1 100644 --- a/src/messageservice.h +++ b/src/messageservice.h @@ -1,8 +1,8 @@ // // Lol Engine // -// Copyright © 2013—2015 Benjamin “Touky” Huet -// © 2017—2018 Sam Hocevar +// Copyright © 2017—2020 Sam Hocevar +// © 2013—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -103,7 +103,7 @@ public: static bool FetchAll(MessageBucket id, std::string& message, time_t &first_timestamp); private: - array > m_bucket; + std::vector > m_bucket; }; extern MessageService *g_messageservice; diff --git a/src/numeric.h b/src/numeric.h index e68220d1..922094ce 100644 --- a/src/numeric.h +++ b/src/numeric.h @@ -17,7 +17,8 @@ // ------------------ // -#include +#include // lol::lerp, lol::clamp +#include // std::swap #include #include @@ -49,7 +50,7 @@ template static inline T1 damp(const T1 static inline float SmoothClamp(float &x, float a, float b, float sd) { if (b < a) - Swap(a, b); + std::swap(a, b); float tx = x; float ta = a - sd; diff --git a/src/t/base/array.cpp b/src/t/base/array.cpp index 1533041c..4f0469d9 100644 --- a/src/t/base/array.cpp +++ b/src/t/base/array.cpp @@ -15,7 +15,7 @@ #endif #include -#include +#include namespace lol { @@ -36,7 +36,7 @@ lolunit_declare_fixture(array_test) { lolunit_declare_test(array_push) { - array a; + easy_array a; a.push(0); a.push(1); a.push(2); @@ -50,21 +50,21 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_initializer) { - array a({ 2, 4, 6 }); + easy_array a({ 2, 4, 6 }); lolunit_assert_equal(a[0], 2); lolunit_assert_equal(a[1], 4); lolunit_assert_equal(a[2], 6); - array b = { 2, 4, 6 }; + easy_array b = { 2, 4, 6 }; lolunit_assert_equal(b[0], 2); lolunit_assert_equal(b[1], 4); lolunit_assert_equal(b[2], 6); - array c = { { 2, 3.0f }, - { 4, 5.0f }, - { 6, 7.0f } }; + easy_array c = { { 2, 3.0f }, + { 4, 5.0f }, + { 6, 7.0f } }; lolunit_assert_equal(std::get<0>(c[0]), 2); lolunit_assert_equal(std::get<1>(c[0]), 3.0f); @@ -76,7 +76,7 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_push_with_shift) { - array a; + easy_array a; a << 0 << 1 << 2 << 3; lolunit_assert_equal(a[0], 0); @@ -87,10 +87,10 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_copy) { - array a; + easy_array a; a << 0 << 1 << 2 << 3; - array b = a; + easy_array b = a; lolunit_assert_equal(b[0], 0); lolunit_assert_equal(b[1], 1); @@ -100,7 +100,7 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_remove) { - array a; + easy_array a; a << 0 << 1 << 2 << 3; a.remove(1); @@ -109,7 +109,7 @@ lolunit_declare_fixture(array_test) lolunit_assert_equal(a[1], 2); lolunit_assert_equal(a[2], 3); - array b; + easy_array b; b << 0 << 1 << 2 << 3; b.remove(-2); @@ -121,7 +121,7 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_remove_swap) { - array a; + easy_array a; a << 0 << 1 << 2 << 3; a.remove_swap(1); @@ -130,7 +130,7 @@ lolunit_declare_fixture(array_test) lolunit_assert_equal(a[1], 3); lolunit_assert_equal(a[2], 2); - array b; + easy_array b; b << 0 << 1 << 2 << 3; b.remove(1, 2); @@ -141,7 +141,7 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(eight_element_arrays) { - array a; + easy_array a; a.push(1, 2, 3.f, 4.0, 5, 'a', true, 0); lolunit_assert_equal(std::get<0>(a[0]), 1); @@ -156,7 +156,7 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_swap) { - array a; + easy_array a; a.push(10, 20); a.push(30, 40); @@ -170,7 +170,7 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_insert) { - array a; + easy_array a; a << 1 << 2; a.insert(5, 0); @@ -194,7 +194,7 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_insert_tuple) { - array b; + easy_array b; b.insert(0, 5, 6.f, "lol"); lolunit_assert_equal(5, std::get<0>(b[0])); lolunit_assert_equal(6.f, std::get<1>(b[0])); @@ -216,11 +216,11 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_concat) { - array a, b; + easy_array a, b; a << 0 << 1; b << 2 << 3; - array c = a + b; + easy_array c = a + b; lolunit_assert_equal(c[0], 0); lolunit_assert_equal(c[1], 1); lolunit_assert_equal(c[2], 2); @@ -229,7 +229,7 @@ lolunit_declare_fixture(array_test) lolunit_declare_test(array_append) { - array a, b; + easy_array a, b; a << 0 << 1; b << 2 << 3; @@ -253,7 +253,7 @@ lolunit_declare_fixture(array_test) tracked_object::m_ctor = 0; tracked_object::m_dtor = 0; { - array a; + easy_array a; a.push(tracked_object()); } @@ -262,7 +262,7 @@ lolunit_declare_fixture(array_test) tracked_object::m_ctor = 0; tracked_object::m_dtor = 0; { - array a; + easy_array a; a.resize(2); a.resize(4); diff --git a/src/ui/d3d9-input.cpp b/src/ui/d3d9-input.cpp index 09b8189d..32bb6515 100644 --- a/src/ui/d3d9-input.cpp +++ b/src/ui/d3d9-input.cpp @@ -20,6 +20,8 @@ #endif #include +#include // std::vector +#include // std::tuple #include @@ -39,7 +41,8 @@ class D3d9InputData private: #if defined LOL_USE_XINPUT - array> m_joysticks; + // FIXME: use std::map here! + std::vector>> m_joysticks; #endif // LOL_USE_XINPUT }; @@ -69,7 +72,7 @@ D3d9Input::D3d9Input() #define _BTN(id, name) stick->internal_add_button(input::button::BTN_##name, #name); #include "ui/buttons.inc" // FIXME: ignore mouse buttons here - m_data->m_joysticks.push(i, stick); + m_data->m_joysticks.push_back(std::make_tuple(i, stick)); } #endif @@ -80,8 +83,7 @@ D3d9Input::~D3d9Input() { #if defined LOL_USE_XINPUT /* Unregister all the joysticks we added (FIXME: this code seems unnecessary) */ - while (m_data->m_joysticks.count()) - m_data->m_joysticks.remove(0); + m_data->m_joysticks.clear(); #endif delete m_data; } @@ -91,13 +93,13 @@ void D3d9Input::tick_game(float seconds) entity::tick_game(seconds); #if defined LOL_USE_XINPUT - for (int i = 0; i < m_data->m_joysticks.count(); i++) + for (auto &joy : m_data->m_joysticks) { XINPUT_STATE state; - if (XInputGetState(std::get<0>(m_data->m_joysticks[i]), &state) != ERROR_SUCCESS) + if (XInputGetState(std::get<0>(joy), &state) != ERROR_SUCCESS) continue; - auto stick = std::get<1>(m_data->m_joysticks[i]); + auto stick = std::get<1>(joy); 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 +116,7 @@ void D3d9Input::tick_game(float seconds) int key_index = (1 << b) > XINPUT_GAMEPAD_RIGHT_SHOULDER ? b - 2 : b; - std::get<1>(m_data->m_joysticks[i])->internal_set_button((input::button)key_index, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1); + std::get<1>(joy)->internal_set_button((input::button)key_index, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1); } } #endif diff --git a/src/ui/gui.cpp b/src/ui/gui.cpp index 2fc04a07..f7e54bdf 100644 --- a/src/ui/gui.cpp +++ b/src/ui/gui.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2017—2019 Sam Hocevar +// Copyright © 2017—2020 Sam Hocevar // © 2009—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to @@ -264,9 +264,9 @@ bool gui::init_draw() m_ortho.m_uniform = m_shader->GetUniformLocation(m_ortho.m_var.tostring()); m_texture.m_uniform = m_shader->GetUniformLocation(m_texture.m_var.tostring()); - m_attribs << m_shader->GetAttribLocation(VertexUsage::Position, 0) - << m_shader->GetAttribLocation(VertexUsage::TexCoord, 0) - << m_shader->GetAttribLocation(VertexUsage::Color, 0); + m_attribs.push_back(m_shader->GetAttribLocation(VertexUsage::Position, 0)); + m_attribs.push_back(m_shader->GetAttribLocation(VertexUsage::TexCoord, 0)); + m_attribs.push_back(m_shader->GetAttribLocation(VertexUsage::Color, 0)); m_vdecl = std::make_shared( VertexStream( diff --git a/src/ui/gui.h b/src/ui/gui.h index cc834106..248e3d63 100644 --- a/src/ui/gui.h +++ b/src/ui/gui.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2017—2019 Sam Hocevar +// Copyright © 2017—2020 Sam Hocevar // © 2009—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to @@ -87,7 +87,7 @@ protected: std::shared_ptr m_shader = nullptr; Uniform m_ortho; Uniform m_texture; - array m_attribs; + std::vector m_attribs; std::shared_ptr m_vdecl; std::string m_clipboard; diff --git a/src/ui/sdl-input.cpp b/src/ui/sdl-input.cpp index 3acc8d9a..c468e458 100644 --- a/src/ui/sdl-input.cpp +++ b/src/ui/sdl-input.cpp @@ -91,7 +91,7 @@ SdlInput::SdlInput(int screen_w, int screen_h) for (int j = 0; j < SDL_JoystickNumButtons(sdlstick); ++j) stick->internal_add_button((input::button)(j + 1), format("Button%d", j + 1).c_str()); - m_joysticks.push(sdlstick, stick); + m_joysticks.push_back(std::make_tuple(sdlstick, stick)); } #endif @@ -102,11 +102,9 @@ SdlInput::~SdlInput() { #if LOL_USE_SDL && !__EMSCRIPTEN__ /* Unregister all the joysticks we added */ - while (m_joysticks.count()) - { - SDL_JoystickClose(std::get<0>(m_joysticks[0])); - m_joysticks.remove(0); - } + for (auto &joy : m_joysticks) + SDL_JoystickClose(std::get<0>(joy)); + m_joysticks.clear(); #endif } @@ -149,18 +147,18 @@ void SdlInput::tick(float seconds) keyboard->internal_begin_frame(); mouse->internal_begin_frame(); - for (int j = 0; j < m_joysticks.count(); j++) - std::get<1>(m_joysticks[j])->internal_begin_frame(); + for (auto &joy : m_joysticks) + std::get<1>(joy)->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 (auto &joy : m_joysticks) { - 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); + for (int i = 0; i < SDL_JoystickNumButtons(std::get<0>(joy)); i++) + std::get<1>(joy)->internal_set_button((input::button)i, SDL_JoystickGetButton(std::get<0>(joy), i) != 0); + for (int i = 0; i < SDL_JoystickNumAxes(std::get<0>(joy)); i++) + std::get<1>(joy)->internal_set_axis((input::axis)i, (float)SDL_JoystickGetAxis(std::get<0>(joy), i) / 32768.f); } # endif diff --git a/src/ui/sdl-input.h b/src/ui/sdl-input.h index b4bdbf27..203210a9 100644 --- a/src/ui/sdl-input.h +++ b/src/ui/sdl-input.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2019 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -28,6 +28,8 @@ #endif #include +#include +#include namespace lol { @@ -49,7 +51,7 @@ private: void tick(float seconds); #if LOL_USE_SDL - array> m_joysticks; + std::vector>> m_joysticks; #endif vec2 m_app; diff --git a/src/utils.h b/src/utils.h deleted file mode 100644 index 2bb30e72..00000000 --- a/src/utils.h +++ /dev/null @@ -1,76 +0,0 @@ -// -// Lol Engine -// -// Copyright © 2010—2020 Sam Hocevar -// © 2012—2015 Benjamin “Touky” Huet -// -// 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 - -// -// Various basic convenience functions -// ----------------------------------- -// - -#include -#include // lol::rand - -#include - -namespace lol -{ - -//Swaps two given values. -template< class T > inline void Swap( T& A, T& B ) -{ - const T Temp = A; - A = B; - B = Temp; -} - -//TODO: random struct -//Gets a random Element from the given array, considering you have implemented what follows : -//NEEDS : float T::m_weight; //if m_weight is 0, it automatically assumes that this step is ignored. -template< class T > inline int GetRandom(array src) -{ - float r_total = 0.f; - float r_alpha = rand(1.f); - float r_value = 0.f; - int r_j = 0; - - for (int i = 0; i < src.count(); ++i) - { - T& tmp = src[i]; - if (tmp.m_weight > .0f) - { - r_total += tmp.m_weight; - float r_tmp = r_alpha * r_total; - while (r_tmp > r_value + src[r_j].m_weight && r_j < i) - { - r_value += src[r_j].m_weight; - r_j++; - } - } - } - - return (r_total > .0f)?(r_j):(-1); -} - -// Gets the value for the given enum type. -template inline T FindValue(std::string const& name) -{ - std::string needle = tolower(name); - for (int i = 0; i < T::Max; ++i) - if (tolower(T(i).tostring()).find(needle) != std::string::npos) - return T(i); - return T::Max; -} - -} /* namespace lol */ -