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.legacy
| @@ -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<PhysicsObject*> RopeElements; | |||
| std::vector<PhysicsObject*> 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<PhysicsObject*> objects | |||
| = m_ground_list | |||
| + m_stairs_list | |||
| + m_character_list | |||
| + m_platform_list; | |||
| while (m_physobj_list.count()) | |||
| std::vector<PhysicsObject*> 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(); | |||
| @@ -15,6 +15,7 @@ | |||
| #include <memory> | |||
| #include <string> | |||
| #include <vector> | |||
| #include <map> | |||
| class CatShaderData : public GpuShaderData | |||
| @@ -89,28 +90,28 @@ private: | |||
| typedef SafeEnum<BtPhysTestKeyInputBase> BtPhysTestKeyInput; | |||
| TileSet* m_cat_texture; | |||
| std::shared_ptr<Shader> 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<Shader> 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<EasyConstraint*> m_constraint_list; | |||
| lol::phys::Simulation *m_simulation; | |||
| std::vector<EasyConstraint*> m_constraint_list; | |||
| struct animated_object { PhysicsObject* obj; float anim; }; | |||
| array<animated_object> m_physobj_list; | |||
| array<PhysicsObject*> m_ground_list; | |||
| array<PhysicsObject*> m_platform_list; | |||
| array<PhysicsObject*> m_character_list; | |||
| array<PhysicsObject*> 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<animated_object> m_physobj_list; | |||
| std::vector<PhysicsObject*> m_ground_list; | |||
| std::vector<PhysicsObject*> m_platform_list; | |||
| std::vector<PhysicsObject*> m_character_list; | |||
| std::vector<PhysicsObject*> m_stairs_list; | |||
| float m_loop_value; | |||
| float m_target_timer; | |||
| int m_cam_target; | |||
| float m_fov_dp; | |||
| float m_loc_dp; | |||
| }; | |||
| @@ -17,6 +17,7 @@ | |||
| /* FIXME: this file is pure crap; it's only a test. */ | |||
| #include <lol/engine.h> | |||
| #include <vector> | |||
| #include "easymesh/easymesh.h" | |||
| #include "physics/easyphysics.h" | |||
| @@ -165,23 +166,24 @@ public: | |||
| m_is_character(false), | |||
| m_is_phys(false) | |||
| { | |||
| static array<EasyMesh> MeshRand; | |||
| static array<int> MeshLimit; | |||
| static array<int> MeshType; | |||
| static std::vector<EasyMesh> MeshRand; | |||
| static std::vector<int> MeshLimit; | |||
| static std::vector<int> MeshType; | |||
| if (!MeshRand.count()) | |||
| if (!MeshRand.size()) | |||
| { | |||
| array<std::string> colors_base = { "#add", "#dad", "#dda", "#daa", "#ada", "#aad" }; | |||
| std::vector<std::string> colors_base = { "#add", "#dad", "#dda", "#daa", "#ada", "#aad" }; | |||
| MeshLimit << 0; | |||
| MeshLimit.push_back(0); | |||
| #if USE_BOX | |||
| { | |||
| array<std::string> colors = colors_base; | |||
| while (colors.count()) | |||
| std::vector<std::string> 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<std::string> colors = colors_base; | |||
| while (colors.count()) | |||
| std::vector<std::string> 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<std::string> colors = colors_base; | |||
| while (colors.count()) | |||
| std::vector<std::string> 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<std::string> colors = colors_base; | |||
| while (colors.count()) | |||
| std::vector<std::string> 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<std::string> colors = colors_base; | |||
| while (colors.count()) | |||
| std::vector<std::string> 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); | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2013 Cédric Lecacheur <jordx@free.fr> | |||
| // © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| @@ -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--); | |||
| } | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // This library is free software. It comes without any warranty, to | |||
| @@ -19,6 +19,7 @@ | |||
| // | |||
| #include <lol/engine.h> | |||
| #include <vector> | |||
| #include <btBulletDynamicsCommon.h> | |||
| #include <btBulletCollisionCommon.h> | |||
| @@ -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<EasyPhysic*> 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<EasyPhysic*> 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<EasyPhysic*> m_touching_physic; //Maintained by ghost objects | |||
| std::vector<EasyPhysic*> m_touching_physic; //Maintained by ghost objects | |||
| }; | |||
| } /* namespace phys */ | |||
| @@ -1,8 +1,8 @@ | |||
| // | |||
| // Lol Engine — Bullet physics test | |||
| // | |||
| // Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2012—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -14,6 +14,7 @@ | |||
| #pragma once | |||
| #include <cstring> | |||
| #include <vector> | |||
| #include <btBulletDynamicsCommon.h> | |||
| #include <btBulletCollisionCommon.h> | |||
| @@ -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<EasyPhysic*> m_collider_list; | |||
| array<vec3> m_hit_normal_list; | |||
| array<vec3> m_hit_point_list; | |||
| array<float> m_hit_fraction_list; | |||
| std::vector<EasyPhysic*> m_collider_list; | |||
| std::vector<vec3> m_hit_normal_list; | |||
| std::vector<vec3> m_hit_point_list; | |||
| std::vector<float> 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<EasyPhysic*>* SearchList = nullptr; | |||
| std::vector<EasyPhysic*>* 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<EasyConstraint*>* SearchList = nullptr; | |||
| std::vector<EasyConstraint*>* 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<EasyPhysic*> m_dynamic_list; | |||
| array<EasyPhysic*> m_static_list; | |||
| array<EasyPhysic*> m_ghost_list; | |||
| array<EasyPhysic*> m_collision_object_list; | |||
| array<EasyPhysic*> m_character_controller_list; | |||
| array<EasyConstraint*> m_constraint_list; | |||
| std::vector<EasyPhysic*> m_dynamic_list; | |||
| std::vector<EasyPhysic*> m_static_list; | |||
| std::vector<EasyPhysic*> m_ghost_list; | |||
| std::vector<EasyPhysic*> m_collision_object_list; | |||
| std::vector<EasyPhysic*> m_character_controller_list; | |||
| std::vector<EasyConstraint*> 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 */ | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine — Triangle tutorial | |||
| // | |||
| // Copyright © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2012—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -28,7 +28,7 @@ class Triangle : public WorldEntity | |||
| public: | |||
| virtual bool init_draw() override | |||
| { | |||
| array<vec2> vertices | |||
| std::vector<vec2> vertices | |||
| { | |||
| vec2( 0.0f, 0.8f), | |||
| vec2(-0.8f, -0.8f), | |||
| @@ -40,8 +40,8 @@ public: | |||
| m_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec2>(VertexUsage::Position)); | |||
| m_vbo = std::make_shared<VertexBuffer>(vertices.bytes()); | |||
| m_vbo->set_data(vertices.data(), vertices.bytes()); | |||
| m_vbo = std::make_shared<VertexBuffer>(vertices.size() * sizeof(vertices[0])); | |||
| m_vbo->set_data(vertices.data(), vertices.size() * sizeof(vertices[0])); | |||
| return true; | |||
| } | |||
| @@ -48,7 +48,7 @@ public: | |||
| virtual bool init_draw() override | |||
| { | |||
| array<vertex> mesh | |||
| std::vector<vertex> 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<uint16_t> lines_indices | |||
| std::vector<uint16_t> 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<uint16_t> faces_indices | |||
| std::vector<uint16_t> 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<vec3,vec3>(VertexUsage::Position, | |||
| VertexUsage::Color)); | |||
| m_vbo = std::make_shared<VertexBuffer>(mesh.bytes()); | |||
| m_vbo->set_data(mesh.data(), mesh.bytes()); | |||
| m_vbo = std::make_shared<VertexBuffer>(mesh.size() * sizeof(mesh[0])); | |||
| m_vbo->set_data(mesh.data(), mesh.size() * sizeof(mesh[0])); | |||
| m_lines_ibo = std::make_shared<IndexBuffer>(lines_indices.bytes()); | |||
| m_lines_ibo->set_data(lines_indices.data(), lines_indices.bytes()); | |||
| m_lines_ibo = std::make_shared<IndexBuffer>(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<IndexBuffer>(faces_indices.bytes()); | |||
| m_faces_ibo->set_data(faces_indices.data(), faces_indices.bytes()); | |||
| m_faces_ibo = std::make_shared<IndexBuffer>(faces_indices.size() * sizeof(faces_indices[0])); | |||
| m_faces_ibo->set_data(faces_indices.data(), faces_indices.size() * sizeof(faces_indices[0])); | |||
| return true; | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine — Noise tutorial | |||
| // | |||
| // Copyright © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2012—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -28,7 +28,7 @@ class NoiseDemo : public WorldEntity | |||
| public: | |||
| virtual bool init_draw() override | |||
| { | |||
| array<vec2> vertices | |||
| std::vector<vec2> vertices | |||
| { | |||
| vec2(-1.0, 1.0), | |||
| vec2(-1.0, -1.0), | |||
| @@ -44,8 +44,8 @@ public: | |||
| m_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec2>(VertexUsage::Position)); | |||
| m_vbo = std::make_shared<VertexBuffer>(vertices.bytes()); | |||
| m_vbo->set_data(vertices.data(), vertices.bytes()); | |||
| m_vbo = std::make_shared<VertexBuffer>(vertices.size() * sizeof(vertices[0])); | |||
| m_vbo->set_data(vertices.data(), vertices.size() * sizeof(vertices[0])); | |||
| return true; | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine — Graphing tutorial | |||
| // | |||
| // Copyright © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2012—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -15,6 +15,7 @@ | |||
| #endif | |||
| #include <lol/engine.h> | |||
| #include <vector> | |||
| #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<vec2> vertices | |||
| std::vector<vec2> vertices | |||
| { | |||
| vec2(-1.0, 1.0), | |||
| vec2(-1.0, -1.0), | |||
| @@ -72,8 +73,8 @@ public: | |||
| m_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec2>(VertexUsage::Position)); | |||
| m_vbo = std::make_shared<VertexBuffer>(vertices.bytes()); | |||
| m_vbo->set_data(vertices.data(), vertices.bytes()); | |||
| m_vbo = std::make_shared<VertexBuffer>(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<VertexDeclaration> m_vdecl; | |||
| std::shared_ptr<VertexBuffer> m_vbo; | |||
| array<uint8_t> m_heightmap; | |||
| std::vector<uint8_t> m_heightmap; | |||
| int m_frames = 0; | |||
| }; | |||
| @@ -39,11 +39,11 @@ public: | |||
| EasyMeshLuaObject* gears3 = EzMhLoader.GetPtr<EasyMeshLuaObject>("g3"); | |||
| EasyMeshLuaObject* gears4 = EzMhLoader.GetPtr<EasyMeshLuaObject>("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<gear> m_gears; | |||
| std::vector<gear> m_gears; | |||
| float m_angle; | |||
| mat4 m_mat; | |||
| @@ -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<sprite> m_sprites; | |||
| std::vector<sprite> m_sprites; | |||
| }; | |||
| int main(int argc, char **argv) | |||
| @@ -104,7 +104,7 @@ public: | |||
| virtual bool init_draw() override | |||
| { | |||
| array<vertex> mesh | |||
| std::vector<vertex> 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<uint16_t> faces_indices | |||
| std::vector<uint16_t> 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<uint16_t> lines_indices | |||
| std::vector<uint16_t> lines_indices | |||
| { | |||
| 0, 1, 1, 2, 2, 3, 3, 0, | |||
| 4, 5, 5, 6, 6, 7, 7, 4, | |||
| @@ -142,14 +142,14 @@ public: | |||
| VertexStream<vec3,vec3>(VertexUsage::Position, | |||
| VertexUsage::Color)); | |||
| m_vbo = std::make_shared<VertexBuffer>(mesh.bytes()); | |||
| m_vbo->set_data(mesh.data(), mesh.bytes()); | |||
| m_vbo = std::make_shared<VertexBuffer>(mesh.size() * sizeof(mesh[0])); | |||
| m_vbo->set_data(mesh.data(), mesh.size() * sizeof(mesh[0])); | |||
| m_lines_ibo = std::make_shared<IndexBuffer>(lines_indices.bytes()); | |||
| m_lines_ibo->set_data(lines_indices.data(), lines_indices.bytes()); | |||
| m_lines_ibo = std::make_shared<IndexBuffer>(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<IndexBuffer>(faces_indices.bytes()); | |||
| m_faces_ibo->set_data(faces_indices.data(), faces_indices.bytes()); | |||
| m_faces_ibo = std::make_shared<IndexBuffer>(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(); | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine — Framebuffer Object tutorial | |||
| // | |||
| // Copyright © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2012—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -44,7 +44,7 @@ public: | |||
| virtual bool init_draw() override | |||
| { | |||
| array<vec2> vertices | |||
| std::vector<vec2> vertices | |||
| { | |||
| vec2( 1.0, 1.0), | |||
| vec2(-1.0, -1.0), | |||
| @@ -63,8 +63,8 @@ public: | |||
| m_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec2>(VertexUsage::Position)); | |||
| m_vbo = std::make_shared<VertexBuffer>(vertices.bytes()); | |||
| m_vbo->set_data(vertices.data(), vertices.bytes()); | |||
| m_vbo = std::make_shared<VertexBuffer>(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<Framebuffer>(Video::GetSize()); | |||
| @@ -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<u8vec4> m_pixels, m_palette; | |||
| std::vector<u8vec4> m_pixels, m_palette; | |||
| std::shared_ptr<Shader> m_shader; | |||
| ShaderAttrib m_vertexattrib, m_texattrib; | |||
| @@ -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<VertexDeclaration>(VertexStream<vec2>(VertexUsage::Position)); | |||
| m_vbo = std::make_shared<VertexBuffer>(m_vertices.bytes()); | |||
| m_vbo->set_data(m_vertices.data(), m_vertices.bytes()); | |||
| m_vbo = std::make_shared<VertexBuffer>(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<Framebuffer>(Video::GetSize()), | |||
| 0, | |||
| array<ShaderUniform>(), | |||
| array<ShaderAttrib>(), | |||
| std::vector<ShaderUniform>(), | |||
| std::vector<ShaderAttrib>(), | |||
| }); | |||
| 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<Framebuffer>(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<float>(512.f), rand<float>(512.f), .0f), | |||
| vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f)) | |||
| @@ -176,7 +176,7 @@ public: | |||
| { | |||
| int i = 4; | |||
| while (i-- > 0) | |||
| voronoi_points.push(point | |||
| voronoi_points.push_back(point | |||
| { | |||
| vec3(rand<float>(512.f), rand<float>(512.f), .0f), | |||
| vec2(64.f + rand<float>(64.f), 64.f + rand<float>(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<Framebuffer> 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<point> voronoi_points; | |||
| array<vec2> m_vertices; | |||
| std::vector<point> voronoi_points; | |||
| std::vector<vec2> m_vertices; | |||
| std::shared_ptr<Shader> m_screen_shader; | |||
| ShaderAttrib m_screen_coord; | |||
| ShaderUniform m_screen_texture; | |||
| @@ -384,10 +384,10 @@ private: | |||
| { | |||
| std::shared_ptr<Framebuffer> framebuffer; | |||
| std::shared_ptr<Shader> shader; | |||
| array<ShaderUniform> uni; | |||
| array<ShaderAttrib> attr; | |||
| std::vector<ShaderUniform> uni; | |||
| std::vector<ShaderAttrib> attr; | |||
| }; | |||
| array<fbo> m_fbos; | |||
| std::vector<fbo> m_fbos; | |||
| std::shared_ptr<Framebuffer> temp_buffer; | |||
| int mode; | |||
| @@ -1 +1 @@ | |||
| Subproject commit c1645f5e8b30961419485e8b3f28092900a99148 | |||
| Subproject commit 7eb81936e277f0c7bb171fddf3632896144e3ac7 | |||
| @@ -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 \ | |||
| @@ -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<WCHAR> widechar; | |||
| std::vector<WCHAR> 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]); | |||
| @@ -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<int, int, int> m_commands; | |||
| array<float> m_floats; | |||
| array<int> m_ints; | |||
| int m_f_cur; | |||
| int m_i_cur; | |||
| struct cmd_def { int cmd, nfloats, nints; }; | |||
| std::vector<cmd_def> m_commands; | |||
| std::vector<float> m_floats; | |||
| std::vector<int> 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<DEF> &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); } | |||
| @@ -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) | |||
| { | |||
| //<Leaf_Id, v0, v1, v2> | |||
| array< int, vec3, vec3, vec3 > tri_to_process; | |||
| easy_array< int, vec3, vec3, vec3 > tri_to_process; | |||
| //<FW/BW, Leaf_Id, v0, v1, v2, twin_leaf> | |||
| 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. | |||
| //<Point_Loc, Src_V0, Src_V1, 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. | |||
| //<Leaf_Id_List, v0, v1, v2, Should_Point_Test> | |||
| 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); | |||
| @@ -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 <sam@hocevar.net> | |||
| // (c) 2010-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://www.wtfpl.net/ for more details. | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2010—2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||
| // See http://www.wtfpl.net/ for more details. | |||
| // | |||
| #pragma once | |||
| #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. | |||
| //<Point_Loc, Src_V0, Src_V1, 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<CsgBspLeaf> m_tree; | |||
| easy_array<CsgBspLeaf> m_tree; | |||
| }; | |||
| } /* namespace lol */ | |||
| @@ -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<int,float> for automatic arrays of tuples. | |||
| // additional features, eg. easy_array<int,float> for automatic arrays of tuples. | |||
| // | |||
| #include <cassert> // 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<typename... T> | |||
| class array : public array_base<std::tuple<T...>, array<T...>> | |||
| class easy_array : public array_base<std::tuple<T...>, easy_array<T...>> | |||
| { | |||
| private: | |||
| using array_base<std::tuple<T...>, array<T...>>::array_base; | |||
| using array_base<std::tuple<T...>, easy_array<T...>>::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<typename T> | |||
| class array<T> | |||
| : public array_base<T, array<T>> | |||
| class easy_array<T> | |||
| : public array_base<T, easy_array<T>> | |||
| { | |||
| using array_base<T, array<T>>::array_base; | |||
| using array_base<T, easy_array<T>>::array_base; | |||
| }; | |||
| /* | |||
| @@ -500,27 +489,27 @@ class array<T> | |||
| */ | |||
| template<typename... T> | |||
| typename array<T...>::iterator begin(array<T...> &a) | |||
| typename easy_array<T...>::iterator begin(easy_array<T...> &a) | |||
| { | |||
| return typename array<T...>::iterator(&a, 0); | |||
| return typename easy_array<T...>::iterator(&a, 0); | |||
| } | |||
| template<typename... T> | |||
| typename array<T...>::iterator end(array<T...> &a) | |||
| typename easy_array<T...>::iterator end(easy_array<T...> &a) | |||
| { | |||
| return typename array<T...>::iterator(&a, a.count()); | |||
| return typename easy_array<T...>::iterator(&a, a.count()); | |||
| } | |||
| template<typename... T> | |||
| typename array<T...>::const_iterator begin(array<T...> const &a) | |||
| typename easy_array<T...>::const_iterator begin(easy_array<T...> const &a) | |||
| { | |||
| return typename array<T...>::const_iterator(&a, 0); | |||
| return typename easy_array<T...>::const_iterator(&a, 0); | |||
| } | |||
| template<typename... T> | |||
| typename array<T...>::const_iterator end(array<T...> const &a) | |||
| typename easy_array<T...>::const_iterator end(easy_array<T...> const &a) | |||
| { | |||
| return typename array<T...>::const_iterator(&a, a.count()); | |||
| return typename easy_array<T...>::const_iterator(&a, a.count()); | |||
| } | |||
| } /* namespace lol */ | |||
| @@ -1,9 +1,9 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2009—2013 Cédric Lecacheur <jordx@free.fr> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2013 Cédric Lecacheur <jordx@free.fr> | |||
| // © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -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<uint16_t> m_indices; | |||
| array<VertexData> m_vert; | |||
| easy_array<uint16_t> m_indices; | |||
| easy_array<VertexData> m_vert; | |||
| //<vert count, indices count> | |||
| array<int, int> m_cursors; | |||
| easy_array<int, int> m_cursors; | |||
| MeshRender m_state; | |||
| @@ -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<int> &matching_ids) | |||
| bool VertexDictionnary::FindMatchingVertices(const int search_idx, easy_array<int> &matching_ids) | |||
| { | |||
| int cur_mast = FindVertexMaster(search_idx); | |||
| @@ -50,9 +50,9 @@ bool VertexDictionnary::FindMatchingVertices(const int search_idx, array<int> &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<uint16_t> &tri_list, const int tri0, array<int> &connected_vert, array<int> const *ignored_tri) | |||
| bool VertexDictionnary::FindConnectedVertices(const int search_idx, const easy_array<uint16_t> &tri_list, const int tri0, easy_array<int> &connected_vert, easy_array<int> const *ignored_tri) | |||
| { | |||
| array<int> connected_tri; | |||
| easy_array<int> 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<uint16_t> &tri_list, const int tri0, array<int> &connected_tri, array<int> const *ignored_tri) | |||
| bool VertexDictionnary::FindConnectedTriangles(const int search_idx, const easy_array<uint16_t> &tri_list, const int tri0, easy_array<int> &connected_tri, easy_array<int> 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<uint16_t> &tri_list, const int tri0, array<int> &connected_tri, array<int> const *ignored_tri) | |||
| bool VertexDictionnary::FindConnectedTriangles(const ivec2 &search_idx, const easy_array<uint16_t> &tri_list, const int tri0, easy_array<int> &connected_tri, easy_array<int> 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<uint16_t> &tri_list, const int tri0, array<int> &connected_tri, array<int> const *ignored_tri) | |||
| bool VertexDictionnary::FindConnectedTriangles(const ivec3 &search_idx, const easy_array<uint16_t> &tri_list, const int tri0, easy_array<int> &connected_tri, easy_array<int> const *ignored_tri) | |||
| { | |||
| int needed_validation = 0; | |||
| array<int> vert_list[3]; | |||
| easy_array<int> vert_list[3]; | |||
| for (int i = 0; i < 3; i++) | |||
| { | |||
| //Small optim since above func will use this one | |||
| @@ -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<int, int> &LoopStack(){ return m_loop_stack; } | |||
| inline easy_array<int, int> &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<int, int> m_loop_stack; | |||
| easy_array<int, int> 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<vec2, vec2> m_texcoord_custom_build[MeshType::MAX]; | |||
| array<vec2, vec2> m_texcoord_custom_build2[MeshType::MAX]; | |||
| easy_array<vec2, vec2> m_texcoord_custom_build[MeshType::MAX]; | |||
| easy_array<vec2, vec2> 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<int> &matching_ids); | |||
| bool FindConnectedVertices(const int search_idx, const array<uint16_t> &tri_list, const int tri0, array<int> &connected_vert, array<int> const *ignored_tri = nullptr); | |||
| bool FindConnectedTriangles(const int search_idx, const array<uint16_t> &tri_list, const int tri0, array<int> &connected_tri, array<int> const *ignored_tri = nullptr); | |||
| bool FindConnectedTriangles(const ivec2 &search_idx, const array<uint16_t> &tri_list, const int tri0, array<int> &connected_tri, array<int> const *ignored_tri = nullptr); | |||
| bool FindConnectedTriangles(const ivec3 &search_idx, const array<uint16_t> &tri_list, const int tri0, array<int> &connected_tri, array<int> const *ignored_tri = nullptr); | |||
| bool FindMatchingVertices(const int search_idx, easy_array<int> &matching_ids); | |||
| bool FindConnectedVertices(const int search_idx, const easy_array<uint16_t> &tri_list, const int tri0, easy_array<int> &connected_vert, easy_array<int> const *ignored_tri = nullptr); | |||
| bool FindConnectedTriangles(const int search_idx, const easy_array<uint16_t> &tri_list, const int tri0, easy_array<int> &connected_tri, easy_array<int> const *ignored_tri = nullptr); | |||
| bool FindConnectedTriangles(const ivec2 &search_idx, const easy_array<uint16_t> &tri_list, const int tri0, easy_array<int> &connected_tri, easy_array<int> const *ignored_tri = nullptr); | |||
| bool FindConnectedTriangles(const ivec3 &search_idx, const easy_array<uint16_t> &tri_list, const int tri0, easy_array<int> &connected_tri, easy_array<int> const *ignored_tri = nullptr); | |||
| void RegisterVertex(int vert_id, vec3 vert_coord); | |||
| void RemoveVertex(int vert_id); | |||
| bool GetMasterList(array<int> &ret_master_list) { ret_master_list = master_list; return ret_master_list.count() > 0; } | |||
| bool GetMasterList(easy_array<int> &ret_master_list) { ret_master_list = master_list; return ret_master_list.count() > 0; } | |||
| void Clear() { vertex_list.clear(); } | |||
| private: | |||
| //<VertexId, VertexLocation, VertexMasterId> | |||
| array<int, vec3, int> vertex_list; | |||
| easy_array<int, vec3, int> vertex_list; | |||
| //List of the master_ vertices | |||
| array<int> master_list; | |||
| easy_array<int> master_list; | |||
| }; | |||
| } /* namespace lol */ | |||
| @@ -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. <tri_Id, <Point0, Point1, tri_isec_Normal>> | |||
| 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. <pos, side_id> | |||
| 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); | |||
| @@ -127,7 +127,7 @@ void EasyMesh::ComputeNormals(int start, int vcount) | |||
| BD()->IsEnabled(MeshBuildOperation::PostBuildComputeNormals)) | |||
| return; | |||
| array< array<vec3> > normals; | |||
| easy_array< easy_array<vec3> > 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<int> vert_ids; | |||
| easy_array<int> 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<VertexData> old_vert = m_vert; | |||
| easy_array<VertexData> 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<int> > new_ids; | |||
| array<int> vert_ids; | |||
| easy_array< easy_array<int> > new_ids; | |||
| easy_array<int> 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<int> tri_list; | |||
| easy_array<int> 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<int> tri_done; | |||
| array<int> tri_check; | |||
| easy_array<int> tri_done; | |||
| easy_array<int> 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<int> matching_vert; | |||
| easy_array<int> matching_vert; | |||
| for (int i = 0; i < 3; i++) | |||
| { | |||
| #if 1 | |||
| @@ -1,8 +1,8 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2017—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2017—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -46,7 +46,7 @@ EasyMeshLuaLoader::~EasyMeshLuaLoader() | |||
| } | |||
| //----------------------------------------------------------------------------- | |||
| static array<EasyMeshLuaObject*> g_instances; | |||
| static easy_array<EasyMeshLuaObject*> g_instances; | |||
| void EasyMeshLuaLoader::Store(LuaObject* obj) | |||
| { | |||
| EasyMeshLuaObject* ezm = static_cast<EasyMeshLuaObject*>(obj); | |||
| @@ -54,7 +54,7 @@ void EasyMeshLuaLoader::Store(LuaObject* obj) | |||
| } | |||
| //----------------------------------------------------------------------------- | |||
| array<EasyMeshLuaObject*>& EasyMeshLuaLoader::GetInstances() | |||
| easy_array<EasyMeshLuaObject*>& EasyMeshLuaLoader::GetInstances() | |||
| { | |||
| return g_instances; | |||
| } | |||
| @@ -1,8 +1,8 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2017—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2017—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // 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<EasyMeshLuaObject*>& GetInstances(); | |||
| easy_array<EasyMeshLuaObject*>& GetInstances(); | |||
| //------------------------------------------------------------------------- | |||
| protected: | |||
| @@ -141,7 +141,7 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float d) | |||
| int ibase = m_indices.count(); | |||
| array<vec3> vertices; | |||
| easy_array<vec3> vertices; | |||
| float uv_h = 0; | |||
| float uv_r = 0; | |||
| @@ -94,8 +94,8 @@ protected: | |||
| std::shared_ptr<Shader> m_shader; | |||
| int m_render_mode; | |||
| uint16_t m_vert_decl_flags; | |||
| array<std::string, ShaderUniform> m_shader_uniform; | |||
| array<ShaderAttrib> m_shader_attrib; | |||
| easy_array<std::string, ShaderUniform> m_shader_uniform; | |||
| easy_array<ShaderAttrib> m_shader_attrib; | |||
| }; | |||
| class DefaultShaderData : public GpuShaderData | |||
| @@ -110,7 +110,7 @@ public: | |||
| void SetupDefaultData(bool with_UV); | |||
| virtual void SetupShaderDatas(mat4 const &model); | |||
| //-- | |||
| array<std::string> m_uniform_names; | |||
| easy_array<std::string> m_uniform_names; | |||
| }; | |||
| class GpuEasyMeshData | |||
| @@ -129,9 +129,9 @@ public: | |||
| private: | |||
| void SetupVertexData(uint16_t vdecl_flags, std::shared_ptr<EasyMesh> src_mesh); | |||
| array<std::shared_ptr<GpuShaderData>> m_gpudata; | |||
| easy_array<std::shared_ptr<GpuShaderData>> m_gpudata; | |||
| //uint16_t are the vdecl/vbo flags to avoid copy same vdecl several times. | |||
| array<uint16_t, std::shared_ptr<VertexDeclaration>, std::shared_ptr<VertexBuffer>> m_vdata; | |||
| easy_array<uint16_t, std::shared_ptr<VertexDeclaration>, std::shared_ptr<VertexBuffer>> m_vdata; | |||
| size_t m_vertexcount; | |||
| //We only need only one ibo for the whole mesh | |||
| std::shared_ptr<IndexBuffer> m_ibo; | |||
| @@ -71,7 +71,7 @@ void EasyMesh::RadialJitter(float r) | |||
| return; | |||
| } | |||
| array<int> welded; | |||
| easy_array<int> 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<vec3> smooth_buf[2]; | |||
| array<int> master_list; | |||
| array<int> matching_ids; | |||
| array<int> connected_vert; | |||
| easy_array<vec3> smooth_buf[2]; | |||
| easy_array<int> master_list; | |||
| easy_array<int> matching_ids; | |||
| easy_array<int> connected_vert; | |||
| int smbuf = 0; | |||
| for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | |||
| @@ -15,6 +15,7 @@ | |||
| #include <unordered_set> // std::unordered_set | |||
| #include <cstdlib> | |||
| #include <functional> | |||
| #include <vector> // std::vector | |||
| #include <stdint.h> | |||
| 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<std::shared_ptr<tickable>> m_tickables; | |||
| /* Entity management */ | |||
| array<entity *> DEPRECATED_m_todolist, DEPRECATED_m_todolist_delayed, DEPRECATED_m_autolist; | |||
| array<entity *> DEPRECATED_m_list[(int)tickable::group::all::end]; | |||
| std::vector<entity *> DEPRECATED_m_todolist, DEPRECATED_m_todolist_delayed, DEPRECATED_m_autolist; | |||
| std::vector<entity *> DEPRECATED_m_list[(int)tickable::group::all::end]; | |||
| std::vector<int> 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<entity*> 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; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -39,7 +39,7 @@ public: | |||
| private: | |||
| static std::string ReadScreen(std::string const &name); | |||
| static void WriteScreen(image &image, array<uint8_t> &result); | |||
| static void WriteScreen(image &image, std::vector<uint8_t> &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<uint8_t> result; | |||
| std::vector<uint8_t> 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<uint8_t> &result) | |||
| void OricImageCodec::WriteScreen(image &img, std::vector<uint8_t> &result) | |||
| { | |||
| ivec2 size = img.size(); | |||
| vec4 *pixels = img.lock<PixelFormat::RGBA_F32>(); | |||
| @@ -525,7 +526,7 @@ void OricImageCodec::WriteScreen(image &img, array<uint8_t> &result) | |||
| /* Iterate */ | |||
| bgfg = domove(command, bgfg); | |||
| /* Write byte to file */ | |||
| result << command; | |||
| result.push_back(command); | |||
| } | |||
| } | |||
| @@ -12,6 +12,8 @@ | |||
| #include <lol/engine-internal.h> | |||
| #include <vector> | |||
| /* | |||
| * Generic convolution functions | |||
| */ | |||
| @@ -19,8 +21,8 @@ | |||
| namespace lol | |||
| { | |||
| static image SepConv(image &src, array<float> const &hvec, | |||
| array<float> const &vvec); | |||
| static image SepConv(image &src, std::vector<float> const &hvec, | |||
| std::vector<float> const &vvec); | |||
| static image NonSepConv(image &src, array2d<float> const &in_kernel); | |||
| image image::Convolution(array2d<float> const &in_kernel) | |||
| @@ -65,13 +67,13 @@ image image::Convolution(array2d<float> const &in_kernel) | |||
| if (separable) | |||
| { | |||
| /* Matrix rank is 1! Separate the filter. */ | |||
| array<float> hvec, vvec; | |||
| std::vector<float> 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<float> const &in_kernel) | |||
| } | |||
| template<PixelFormat FORMAT, int WRAP_X, int WRAP_Y> | |||
| static image SepConv(image &src, array<float> const &hvec, | |||
| array<float> const &vvec) | |||
| static image SepConv(image &src, std::vector<float> const &hvec, | |||
| std::vector<float> const &vvec) | |||
| { | |||
| typedef typename PixelType<FORMAT>::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<pixel_t> const &srcp = src.lock2d<FORMAT>(); | |||
| @@ -252,8 +254,8 @@ static image SepConv(image &src, array<float> const &hvec, | |||
| return dst; | |||
| } | |||
| static image SepConv(image &src, array<float> const &hvec, | |||
| array<float> const &vvec) | |||
| static image SepConv(image &src, std::vector<float> const &hvec, | |||
| std::vector<float> const &vvec) | |||
| { | |||
| bool const wrap_x = src.GetWrapX() == WrapMode::Repeat; | |||
| bool const wrap_y = src.GetWrapY() == WrapMode::Repeat; | |||
| @@ -186,7 +186,7 @@ array2d<float> image::kernel::normalize(array2d<float> const &kernel) | |||
| { | |||
| ivec2 size = kernel.sizes(); | |||
| array<Dot> tmp; | |||
| std::vector<Dot> tmp; | |||
| tmp.resize(size.x * size.y); | |||
| for (int y = 0; y < size.y; y++) | |||
| @@ -196,6 +196,7 @@ array2d<float> image::kernel::normalize(array2d<float> 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<float> dst(size); | |||
| @@ -12,6 +12,8 @@ | |||
| #include <lol/engine-internal.h> | |||
| #include <vector> // std::vector | |||
| /* | |||
| * Image resizing functions | |||
| */ | |||
| @@ -145,16 +147,16 @@ static image ResizeBresenham(image &src, ivec2 size) | |||
| vec4 const *srcp = src.lock<PixelFormat::RGBA_F32>(); | |||
| vec4 *dstp = dst.lock<PixelFormat::RGBA_F32>(); | |||
| array<vec4> aline, line; | |||
| std::vector<vec4> 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; ) | |||
| { | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2016—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -13,6 +13,9 @@ | |||
| #pragma once | |||
| #include <lol/utils> | |||
| #include <vector> | |||
| // | |||
| // 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) \ | |||
| @@ -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<ResourceCodec *> &codeclist) | |||
| static bool RegisterAllCodecs(std::vector<ResourceCodec *> &codeclist) | |||
| { | |||
| #if defined __ANDROID__ | |||
| REGISTER_IMAGE_CODEC(AndroidImageCodec) | |||
| @@ -69,7 +69,7 @@ public: | |||
| } | |||
| private: | |||
| array<ResourceCodec *> m_codecs; | |||
| std::vector<ResourceCodec *> m_codecs; | |||
| } | |||
| g_resource_loader; | |||
| @@ -215,6 +215,7 @@ | |||
| <ClInclude Include="debug\record.h" /> | |||
| <ClInclude Include="debug\stats.h" /> | |||
| <ClInclude Include="easymesh\csgbsp.h" /> | |||
| <ClInclude Include="easymesh\easyarray.h" /> | |||
| <ClInclude Include="easymesh\easymesh.h" /> | |||
| <ClInclude Include="easymesh\easymeshbuild.h" /> | |||
| <ClInclude Include="easymesh\easymeshlua.h" /> | |||
| @@ -236,7 +237,6 @@ | |||
| <ClInclude Include="lol\audio\audio.h" /> | |||
| <ClInclude Include="lol\audio\sample.h" /> | |||
| <ClInclude Include="lol\base\all.h" /> | |||
| <ClInclude Include="lol\base\array.h" /> | |||
| <ClInclude Include="lol\base\enum.h" /> | |||
| <ClInclude Include="lol\base\log.h" /> | |||
| <ClInclude Include="lol\debug\all.h" /> | |||
| @@ -296,7 +296,6 @@ | |||
| <ClInclude Include="ui\sdl-input.h"> | |||
| <ExcludedFromBuild Condition="'$(enable_sdl)'=='no'">true</ExcludedFromBuild> | |||
| </ClInclude> | |||
| <ClInclude Include="utils.h" /> | |||
| <ClInclude Include="video.h" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| @@ -260,6 +260,9 @@ | |||
| <ClInclude Include="easymesh\easymesh.h"> | |||
| <Filter>easymesh</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="easymesh\easyarray.h"> | |||
| <Filter>easymesh</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="easymesh\easymeshbuild.h"> | |||
| <Filter>easymesh</Filter> | |||
| </ClInclude> | |||
| @@ -296,9 +299,6 @@ | |||
| <ClInclude Include="lolua\baselua.h"> | |||
| <Filter>lolua</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="lol\base\array.h"> | |||
| <Filter>lol\base</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="lol\base\enum.h"> | |||
| <Filter>lol\base</Filter> | |||
| </ClInclude> | |||
| @@ -423,7 +423,6 @@ | |||
| <ClInclude Include="ui\sdl-input.h"> | |||
| <Filter>ui</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="utils.h" /> | |||
| <ClInclude Include="video.h" /> | |||
| <ClInclude Include="lol\base\all.h"> | |||
| <Filter>lol\base</Filter> | |||
| @@ -17,7 +17,6 @@ | |||
| #include <../legacy/lol/base/types.h> | |||
| #include <lol/base/log.h> | |||
| #include <../legacy/lol/base/assert.h> | |||
| #include <lol/base/array.h> | |||
| #include <../legacy/lol/base/avl_tree.h> | |||
| #include <lol/base/enum.h> | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -17,7 +17,6 @@ | |||
| // -------------------------------------------------------- | |||
| // | |||
| #include <lol/../utils.h> | |||
| #include <lol/../numeric.h> | |||
| // Static classes | |||
| @@ -122,20 +122,20 @@ Loader::~Loader() | |||
| //Store loader ------------------------------------------------------------ | |||
| // FIXME: change this to a map? | |||
| static array<lua_State*, Lolua::Loader*> g_loaders; | |||
| static std::vector<std::tuple<lua_State*, Lolua::Loader*>> 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; | |||
| } | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2017—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2017—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -19,7 +19,9 @@ extern "C" { | |||
| #include "3rdparty/lua/lauxlib.h" | |||
| } | |||
| #include <string> | |||
| #include <vector> // std::vector | |||
| #include <string> // std::string | |||
| #include <cstdlib> // tolower | |||
| // | |||
| // Base Lua class for Lua script loading | |||
| @@ -65,45 +67,45 @@ public: | |||
| } ClassVarStr; | |||
| Library(std::string const &class_name, | |||
| array<ClassMethod> const& statics, | |||
| array<ClassMethod> const& methods, | |||
| array<ClassVar> const& variables) | |||
| std::vector<ClassMethod> const& statics, | |||
| std::vector<ClassMethod> const& methods, | |||
| std::vector<ClassVar> 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<ClassMethod> m_statics; | |||
| array<ClassMethod> m_methods; | |||
| array<ClassVarStr> m_variables; | |||
| std::vector<ClassMethod> m_statics; | |||
| std::vector<ClassMethod> m_methods; | |||
| std::vector<ClassVarStr> m_variables; | |||
| }; | |||
| public: | |||
| @@ -173,7 +175,7 @@ public: | |||
| lua_setfield(l, -1, "__index"); | |||
| //Create variables Get/Set | |||
| const array<Object::Library::ClassVarStr>& variables = GetVariables<TLuaClass>(); | |||
| const std::vector<Object::Library::ClassVarStr>& variables = GetVariables<TLuaClass>(); | |||
| for (const Object::Library::ClassVarStr& var : variables) | |||
| { | |||
| if (!var.m_get || !var.m_set) | |||
| @@ -215,7 +217,7 @@ public: | |||
| template <typename TLuaClass> | |||
| static const ClassMethod* GetInstanceMethods() { return GetLibrary<TLuaClass>()->m_methods.data(); } | |||
| template <typename TLuaClass> | |||
| static const array<Object::Library::ClassVarStr>& GetVariables() { return GetLibrary<TLuaClass>()->m_variables; } | |||
| static const std::vector<Object::Library::ClassVarStr>& GetVariables() { return GetLibrary<TLuaClass>()->m_variables; } | |||
| protected: | |||
| //------------------------------------------------------------------------- | |||
| @@ -387,6 +389,16 @@ protected: | |||
| template<typename T> 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<class T> 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<typename E> SafeEnum<E> InnerDefaultSafeEnum() { return SafeEnum<E>(); } | |||
| template<typename E> bool InnerIsValidSafeEnum() { return InnerIsValid<std::string>(); } | |||
| template<typename E> SafeEnum<E> InnerGetSafeEnum(SafeEnum<E> value) { return FindValue<SafeEnum<E> >(InnerGet<std::string>(value.tostring())); } | |||
| @@ -12,7 +12,8 @@ | |||
| #include <lol/engine-internal.h> | |||
| #include <memory> | |||
| #include <memory> // std::shared_ptr | |||
| #include <tuple> // std::make_tuple | |||
| #include <cstring> | |||
| #include <cstdlib> | |||
| @@ -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<PrimitiveMesh>(submesh, matrix)); | |||
| @@ -89,8 +90,8 @@ void SubMesh::SetVertexDeclaration(std::shared_ptr<VertexDeclaration> vdecl) | |||
| void SubMesh::SetVertexBuffer(int index, std::shared_ptr<VertexBuffer> 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<IndexBuffer> ibo) | |||
| void SubMesh::AddTexture(std::string const &name, std::shared_ptr<Texture> 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])); | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -105,11 +105,11 @@ protected: | |||
| MeshPrimitive m_mesh_prim; | |||
| std::shared_ptr<Shader> m_shader; | |||
| std::shared_ptr<VertexDeclaration> m_vdecl; | |||
| array<std::shared_ptr<VertexBuffer>> m_vbos; | |||
| std::vector<std::shared_ptr<VertexBuffer>> m_vbos; | |||
| std::shared_ptr<IndexBuffer> m_ibo; | |||
| array<std::string, std::shared_ptr<Texture>> m_textures; | |||
| std::vector<std::tuple<std::string, std::shared_ptr<Texture>>> m_textures; | |||
| }; | |||
| } /* namespace lol */ | |||
| } // namespace lol | |||
| @@ -1,8 +1,8 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2013—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2017—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2017—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2013—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -67,8 +67,8 @@ bool MessageService::Send(MessageBucket id, const std::string& message) | |||
| if (g_messageservice) | |||
| { | |||
| MessageService& g = *g_messageservice; | |||
| array<MessageList>& 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<MessageList>& 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<MessageList>& 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 | |||
| @@ -1,8 +1,8 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2013—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2017—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2017—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2013—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -103,7 +103,7 @@ public: | |||
| static bool FetchAll(MessageBucket id, std::string& message, time_t &first_timestamp); | |||
| private: | |||
| array<array<MessageList> > m_bucket; | |||
| std::vector<std::vector<MessageList> > m_bucket; | |||
| }; | |||
| extern MessageService *g_messageservice; | |||
| @@ -17,7 +17,8 @@ | |||
| // ------------------ | |||
| // | |||
| #include <lol/math> | |||
| #include <lol/math> // lol::lerp, lol::clamp | |||
| #include <algorithm> // std::swap | |||
| #include <cstdlib> | |||
| #include <stdint.h> | |||
| @@ -49,7 +50,7 @@ template <typename T1, typename T2, typename Tf> 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; | |||
| @@ -15,7 +15,7 @@ | |||
| #endif | |||
| #include <lol/unit_test> | |||
| #include <lol/base/array.h> | |||
| #include <lol/../easymesh/easyarray.h> | |||
| namespace lol | |||
| { | |||
| @@ -36,7 +36,7 @@ lolunit_declare_fixture(array_test) | |||
| { | |||
| lolunit_declare_test(array_push) | |||
| { | |||
| array<int> a; | |||
| easy_array<int> 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<int> a({ 2, 4, 6 }); | |||
| easy_array<int> a({ 2, 4, 6 }); | |||
| lolunit_assert_equal(a[0], 2); | |||
| lolunit_assert_equal(a[1], 4); | |||
| lolunit_assert_equal(a[2], 6); | |||
| array<int> b = { 2, 4, 6 }; | |||
| easy_array<int> b = { 2, 4, 6 }; | |||
| lolunit_assert_equal(b[0], 2); | |||
| lolunit_assert_equal(b[1], 4); | |||
| lolunit_assert_equal(b[2], 6); | |||
| array<int, float> c = { { 2, 3.0f }, | |||
| { 4, 5.0f }, | |||
| { 6, 7.0f } }; | |||
| easy_array<int, float> 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<int> a; | |||
| easy_array<int> 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<int> a; | |||
| easy_array<int> a; | |||
| a << 0 << 1 << 2 << 3; | |||
| array<int> b = a; | |||
| easy_array<int> 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<int> a; | |||
| easy_array<int> 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<int> b; | |||
| easy_array<int> 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<int> a; | |||
| easy_array<int> 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<int> b; | |||
| easy_array<int> 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<int, long, float, double, unsigned, char, bool, void *> a; | |||
| easy_array<int, long, float, double, unsigned, char, bool, void *> a; | |||
| a.push(1, 2, 3.f, 4.0, 5, 'a', true, 0); | |||
| lolunit_assert_equal(std::get<0>(a[0]), 1); | |||
| @@ -156,7 +156,7 @@ lolunit_declare_fixture(array_test) | |||
| lolunit_declare_test(array_swap) | |||
| { | |||
| array<int, int> a; | |||
| easy_array<int, int> a; | |||
| a.push(10, 20); | |||
| a.push(30, 40); | |||
| @@ -170,7 +170,7 @@ lolunit_declare_fixture(array_test) | |||
| lolunit_declare_test(array_insert) | |||
| { | |||
| array<int> a; | |||
| easy_array<int> a; | |||
| a << 1 << 2; | |||
| a.insert(5, 0); | |||
| @@ -194,7 +194,7 @@ lolunit_declare_fixture(array_test) | |||
| lolunit_declare_test(array_insert_tuple) | |||
| { | |||
| array<int, float, std::string> b; | |||
| easy_array<int, float, std::string> 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<int> a, b; | |||
| easy_array<int> a, b; | |||
| a << 0 << 1; | |||
| b << 2 << 3; | |||
| array<int> c = a + b; | |||
| easy_array<int> 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<int> a, b; | |||
| easy_array<int> 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<tracked_object> a; | |||
| easy_array<tracked_object> 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<tracked_object> a; | |||
| easy_array<tracked_object> a; | |||
| a.resize(2); | |||
| a.resize(4); | |||
| @@ -20,6 +20,8 @@ | |||
| #endif | |||
| #include <memory> | |||
| #include <vector> // std::vector | |||
| #include <tuple> // std::tuple | |||
| #include <lol/engine-internal.h> | |||
| @@ -39,7 +41,8 @@ class D3d9InputData | |||
| private: | |||
| #if defined LOL_USE_XINPUT | |||
| array<int, std::shared_ptr<input::device::joystick>> m_joysticks; | |||
| // FIXME: use std::map here! | |||
| std::vector<std::tuple<int, std::shared_ptr<input::device::joystick>>> 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 | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2017—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2017—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -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<VertexDeclaration>( | |||
| VertexStream<vec2, vec2, u8vec4>( | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2017—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2017—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -87,7 +87,7 @@ protected: | |||
| std::shared_ptr<Shader> m_shader = nullptr; | |||
| Uniform m_ortho; | |||
| Uniform m_texture; | |||
| array<ShaderAttrib> m_attribs; | |||
| std::vector<ShaderAttrib> m_attribs; | |||
| std::shared_ptr<VertexDeclaration> m_vdecl; | |||
| std::string m_clipboard; | |||
| @@ -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 | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| @@ -28,6 +28,8 @@ | |||
| #endif | |||
| #include <memory> | |||
| #include <vector> | |||
| #include <tuple> | |||
| namespace lol | |||
| { | |||
| @@ -49,7 +51,7 @@ private: | |||
| void tick(float seconds); | |||
| #if LOL_USE_SDL | |||
| array<SDL_Joystick *, std::shared_ptr<class input::device::joystick>> m_joysticks; | |||
| std::vector<std::tuple<SDL_Joystick *, std::shared_ptr<class input::device::joystick>>> m_joysticks; | |||
| #endif | |||
| vec2 m_app; | |||
| @@ -1,76 +0,0 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2012—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||
| // See http://www.wtfpl.net/ for more details. | |||
| // | |||
| #pragma once | |||
| // | |||
| // Various basic convenience functions | |||
| // ----------------------------------- | |||
| // | |||
| #include <lol/utils> | |||
| #include <lol/math> // lol::rand | |||
| #include <string> | |||
| 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<T>, 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<T> 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<class T> 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 */ | |||