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); | PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3); | ||||
Ticker::Ref(NewPhyobj); | Ticker::Ref(NewPhyobj); | ||||
m_stairs_list << NewPhyobj; | |||||
m_stairs_list.push_back(NewPhyobj); | |||||
} | } | ||||
{ | { | ||||
NewRotation = quat::fromeuler_xyz(0.f, 0.f, radians(40.f)); | 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); | PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3); | ||||
Ticker::Ref(NewPhyobj); | Ticker::Ref(NewPhyobj); | ||||
m_stairs_list << NewPhyobj; | |||||
m_stairs_list.push_back(NewPhyobj); | |||||
} | } | ||||
NewPosition = pos_offset + vec3(5.0f, -29.5f, 15.0f); | NewPosition = pos_offset + vec3(5.0f, -29.5f, 15.0f); | ||||
NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f); | 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); | PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3); | ||||
Ticker::Ref(NewPhyobj); | Ticker::Ref(NewPhyobj); | ||||
m_stairs_list << NewPhyobj; | |||||
m_stairs_list.push_back(NewPhyobj); | |||||
} | } | ||||
} | } | ||||
#endif //USE_STAIRS | #endif //USE_STAIRS | ||||
@@ -181,7 +181,7 @@ void BtPhysTest::InitApp() | |||||
NewPhyobj->SetTransform(NewPosition, NewRotation); | NewPhyobj->SetTransform(NewPosition, NewRotation); | ||||
Ticker::Ref(NewPhyobj); | Ticker::Ref(NewPhyobj); | ||||
m_ground_list << NewPhyobj; | |||||
m_ground_list.push_back(NewPhyobj); | |||||
} | } | ||||
} | } | ||||
#endif //USE_WALL | #endif //USE_WALL | ||||
@@ -194,7 +194,7 @@ void BtPhysTest::InitApp() | |||||
PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); | PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); | ||||
m_platform_list << NewPhyobj; | |||||
m_platform_list.push_back(NewPhyobj); | |||||
Ticker::Ref(NewPhyobj); | Ticker::Ref(NewPhyobj); | ||||
NewPosition = pos_offset + vec3(-15.0f, -25.0f, 5.0f); | 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); | NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); | ||||
BasePhyobj = NewPhyobj; | BasePhyobj = NewPhyobj; | ||||
m_platform_list << NewPhyobj; | |||||
m_platform_list.push_back(NewPhyobj); | |||||
Ticker::Ref(NewPhyobj); | Ticker::Ref(NewPhyobj); | ||||
NewRotation = quat::fromeuler_xyz(0.f, 0.f, radians(90.f)); | 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 = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); | ||||
NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, true); | NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, true); | ||||
m_platform_list << NewPhyobj; | |||||
m_platform_list.push_back(NewPhyobj); | |||||
Ticker::Ref(NewPhyobj); | Ticker::Ref(NewPhyobj); | ||||
//NewPosition += vec3(-0.0f, .0f, .0f); | //NewPosition += vec3(-0.0f, .0f, .0f); | ||||
//NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); | //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); | ||||
//NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, false); | //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, false); | ||||
//m_platform_list << NewPhyobj; | |||||
//m_platform_list.push_back(NewPhyobj); | |||||
//Ticker::Ref(NewPhyobj); | //Ticker::Ref(NewPhyobj); | ||||
//NewPosition += vec3(-2.0f, .0f, .0f); | //NewPosition += vec3(-2.0f, .0f, .0f); | ||||
//NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); | //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); | ||||
//NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), false, false); | //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), false, false); | ||||
//m_platform_list << NewPhyobj; | |||||
//m_platform_list.push_back(NewPhyobj); | |||||
//Ticker::Ref(NewPhyobj); | //Ticker::Ref(NewPhyobj); | ||||
} | } | ||||
#endif //USE_PLATFORM | #endif //USE_PLATFORM | ||||
@@ -237,7 +237,7 @@ void BtPhysTest::InitApp() | |||||
PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2); | PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2); | ||||
m_character_list << NewPhyobj; | |||||
m_character_list.push_back(NewPhyobj); | |||||
Ticker::Ref(NewPhyobj); | Ticker::Ref(NewPhyobj); | ||||
//NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true); | //NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true); | ||||
@@ -259,7 +259,7 @@ void BtPhysTest::InitApp() | |||||
vec3(2.f , 1.f , 2.f) + | vec3(2.f , 1.f , 2.f) + | ||||
#endif //CAT_MODE | #endif //CAT_MODE | ||||
vec3(8.f * (float)x, 8.f * (float)y, 8.f * (float)z)); | 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); | Ticker::Ref(new_physobj); | ||||
} | } | ||||
} | } | ||||
@@ -269,16 +269,16 @@ void BtPhysTest::InitApp() | |||||
#if USE_ROPE | #if USE_ROPE | ||||
{ | { | ||||
array<PhysicsObject*> RopeElements; | |||||
std::vector<PhysicsObject*> RopeElements; | |||||
for (int i = 0; i < 14; i++) | for (int i = 0; i < 14; i++) | ||||
{ | { | ||||
PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 1000.f, | PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 1000.f, | ||||
vec3(0.f, 15.f, -20.f) + | vec3(0.f, 15.f, -20.f) + | ||||
vec3(0.f, 0.f, 2.f * (float)i), 1); | 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); | Ticker::Ref(new_physobj); | ||||
if (RopeElements.count() > 1) | |||||
if (RopeElements.size() > 1) | |||||
{ | { | ||||
EasyConstraint* new_constraint = new EasyConstraint(); | EasyConstraint* new_constraint = new EasyConstraint(); | ||||
@@ -289,7 +289,7 @@ void BtPhysTest::InitApp() | |||||
new_constraint->InitConstraintToPoint2Point(); | new_constraint->InitConstraintToPoint2Point(); | ||||
new_constraint->DisableCollisionBetweenObjs(true); | new_constraint->DisableCollisionBetweenObjs(true); | ||||
new_constraint->AddToSimulation(m_simulation); | 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); | Tiler::Deregister(m_cat_texture); | ||||
#endif //CAT_MODE | #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); | CurPop->RemoveFromSimulation(m_simulation); | ||||
delete CurPop; | 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_ground_list.clear(); | ||||
m_stairs_list.clear(); | m_stairs_list.clear(); | ||||
m_character_list.clear(); | m_character_list.clear(); | ||||
m_platform_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); | CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); | ||||
Ticker::Unref(CurPop); | 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); | // CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); | ||||
// Ticker::Unref(CurPop); | // 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); | // CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); | ||||
// Ticker::Unref(CurPop); | // 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); | // CurPop->GetCharacter()->RemoveFromSimulation(m_simulation); | ||||
// Ticker::Unref(CurPop); | // 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); | // CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); | ||||
// Ticker::Unref(CurPop); | // 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); | // CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); | ||||
// Ticker::Unref(CurPop); | // Ticker::Unref(CurPop); | ||||
//} | //} | ||||
@@ -420,12 +426,12 @@ void BtPhysTest::tick_game(float seconds) | |||||
{ | { | ||||
m_target_timer = TARGET_TIMER; | m_target_timer = TARGET_TIMER; | ||||
if (m_cam_target == -1) | if (m_cam_target == -1) | ||||
m_cam_target = rand(m_physobj_list.count()); | |||||
m_cam_target = rand(m_physobj_list.size()); | |||||
else | else | ||||
m_cam_target = -1; | 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; | PhysicsObject* PhysObj = m_physobj_list[i].obj; | ||||
float &obj_timer = m_physobj_list[i].anim; | float &obj_timer = m_physobj_list[i].anim; | ||||
@@ -503,7 +509,7 @@ void BtPhysTest::tick_game(float seconds) | |||||
#if USE_WALL | #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]; | PhysicsObject* PhysObj = m_ground_list[i]; | ||||
mat4 GroundMat = PhysObj->GetTransform(); | mat4 GroundMat = PhysObj->GetTransform(); | ||||
@@ -514,7 +520,7 @@ void BtPhysTest::tick_game(float seconds) | |||||
GroundBarycenter /= factor; | 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]; | PhysicsObject* PhysObj = m_ground_list[i]; | ||||
@@ -533,7 +539,7 @@ void BtPhysTest::tick_game(float seconds) | |||||
#if USE_ROTATION | #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]; | PhysicsObject* PhysObj = m_ground_list[i]; | ||||
@@ -550,7 +556,7 @@ void BtPhysTest::tick_game(float seconds) | |||||
#if USE_PLATFORM | #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]; | PhysicsObject* PhysObj = m_platform_list[i]; | ||||
@@ -575,7 +581,7 @@ void BtPhysTest::tick_game(float seconds) | |||||
{ | { | ||||
auto keyboard = input::keyboard(); | 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]; | PhysicsObject* PhysObj = m_character_list[i]; | ||||
EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter(); | EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter(); | ||||
@@ -608,7 +614,7 @@ void BtPhysTest::tick_game(float seconds) | |||||
PhysObjBarycenter = vec3(.0f); | PhysObjBarycenter = vec3(.0f); | ||||
factor = .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]; | PhysicsObject* PhysObj = m_character_list[i]; | ||||
mat4 GroundMat = PhysObj->GetTransform(); | mat4 GroundMat = PhysObj->GetTransform(); | ||||
@@ -628,7 +634,7 @@ void BtPhysTest::tick_game(float seconds) | |||||
#else | #else | ||||
{ | { | ||||
PhysObjBarycenter = vec3(.0f); | 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; | PhysicsObject* PhysObj = m_physobj_list[i].obj; | ||||
mat4 GroundMat = PhysObj->GetTransform(); | mat4 GroundMat = PhysObj->GetTransform(); | ||||
@@ -660,7 +666,7 @@ void BtPhysTest::tick_draw(float seconds, Scene &scene) | |||||
/* cat datas setup */ | /* cat datas setup */ | ||||
m_cat_shader = Shader::Create(LOLFX_RESOURCE_NAME(front_camera_sprite)); | m_cat_shader = Shader::Create(LOLFX_RESOURCE_NAME(front_camera_sprite)); | ||||
#if USE_BODIES | #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; | PhysicsObject* PhysObj = m_physobj_list[i].obj; | ||||
m_cat_sdata = new CatShaderData(((1 << VertexUsage::Position) | | m_cat_sdata = new CatShaderData(((1 << VertexUsage::Position) | | ||||
@@ -682,7 +688,7 @@ void BtPhysTest::tick_draw(float seconds, Scene &scene) | |||||
else | else | ||||
{ | { | ||||
#if CAT_MODE | #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; | PhysicsObject* PhysObj = m_physobj_list[i].obj; | ||||
CatShaderData* ShaderData = (CatShaderData*)PhysObj->GetCustomShaderData(); | CatShaderData* ShaderData = (CatShaderData*)PhysObj->GetCustomShaderData(); | ||||
@@ -15,6 +15,7 @@ | |||||
#include <memory> | #include <memory> | ||||
#include <string> | #include <string> | ||||
#include <vector> | |||||
#include <map> | #include <map> | ||||
class CatShaderData : public GpuShaderData | class CatShaderData : public GpuShaderData | ||||
@@ -89,28 +90,28 @@ private: | |||||
typedef SafeEnum<BtPhysTestKeyInputBase> BtPhysTestKeyInput; | 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; }; | 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. */ | /* FIXME: this file is pure crap; it's only a test. */ | ||||
#include <lol/engine.h> | #include <lol/engine.h> | ||||
#include <vector> | |||||
#include "easymesh/easymesh.h" | #include "easymesh/easymesh.h" | ||||
#include "physics/easyphysics.h" | #include "physics/easyphysics.h" | ||||
@@ -165,23 +166,24 @@ public: | |||||
m_is_character(false), | m_is_character(false), | ||||
m_is_phys(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 | #if USE_BOX | ||||
{ | { | ||||
array<std::string> colors = colors_base; | |||||
while (colors.count()) | |||||
std::vector<std::string> colors = colors_base; | |||||
while (colors.size()) | |||||
{ | { | ||||
EasyMesh m; | EasyMesh m; | ||||
vec4 color = hex_to_color(colors.pop()); | |||||
vec4 color = hex_to_color(colors.back()); | |||||
colors.pop_back(); | |||||
m.SetCurColor(color); | m.SetCurColor(color); | ||||
m.AppendFlatChamfBox(vec3(1.7f), .4f); | m.AppendFlatChamfBox(vec3(1.7f), .4f); | ||||
m.OpenBrace(); | m.OpenBrace(); | ||||
@@ -194,7 +196,7 @@ public: | |||||
m.ScaleZ(-1.f); | m.ScaleZ(-1.f); | ||||
} | } | ||||
m.CloseBrace(); | 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]"; | //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#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]"; | //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 | #endif //USE_BOX | ||||
@@ -220,20 +222,21 @@ public: | |||||
start_point, start_point + size); | start_point, start_point + size); | ||||
m_mesh.BD()->SetTexCoordCustomBuild2(MeshType::Quad, MeshFaceType::QuadDefault, | m_mesh.BD()->SetTexCoordCustomBuild2(MeshType::Quad, MeshFaceType::QuadDefault, | ||||
vec2(-PARTICLE_SIZE), vec2(PARTICLE_SIZE)); | 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 | #else | ||||
{ | { | ||||
array<std::string> colors = colors_base; | |||||
while (colors.count()) | |||||
std::vector<std::string> colors = colors_base; | |||||
while (colors.size()) | |||||
{ | { | ||||
EasyMesh m; | EasyMesh m; | ||||
vec4 color = hex_to_color(colors.pop()); | |||||
vec4 color = hex_to_color(colors.back()); | |||||
colors.pop_back(); | |||||
m.SetCurColor(color); | m.SetCurColor(color); | ||||
m.AppendSphere(1, 2.f); | m.AppendSphere(1, 2.f); | ||||
MeshRand << m; | |||||
MeshRand.push_back(m); | |||||
} | } | ||||
} | } | ||||
//MeshRand << "[sc#add asph1 2]"; | //MeshRand << "[sc#add asph1 2]"; | ||||
@@ -244,24 +247,25 @@ public: | |||||
//MeshRand << "[sc#aad asph1 2]"; | //MeshRand << "[sc#aad asph1 2]"; | ||||
#endif | #endif | ||||
MeshLimit << MeshRand.count(); | |||||
MeshType << 1; | |||||
MeshLimit.push_back(int(MeshRand.size())); | |||||
MeshType.push_back(1); | |||||
#endif //USE_SPHERE | #endif //USE_SPHERE | ||||
#if USE_CONE | #if USE_CONE | ||||
{ | { | ||||
array<std::string> colors = colors_base; | |||||
while (colors.count()) | |||||
std::vector<std::string> colors = colors_base; | |||||
while (colors.size()) | |||||
{ | { | ||||
EasyMesh m; | EasyMesh m; | ||||
vec4 color = hex_to_color(colors.pop()); | |||||
vec4 color = hex_to_color(colors.back()); | |||||
colors.pop_back(); | |||||
m.SetCurColor(color); | m.SetCurColor(color); | ||||
m.SetCurColorB(color); | m.SetCurColorB(color); | ||||
m.AppendDisc(8, 2.f); | m.AppendDisc(8, 2.f); | ||||
m.RotateX(180.f); | m.RotateX(180.f); | ||||
m.TranslateY(-1.f); | m.TranslateY(-1.f); | ||||
m.AppendCylinder(8, 2.f, 2.f, 0.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]"; | //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#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]"; | //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 | #endif //USE_CONE | ||||
#if USE_CYLINDER | #if USE_CYLINDER | ||||
{ | { | ||||
array<std::string> colors = colors_base; | |||||
while (colors.count()) | |||||
std::vector<std::string> colors = colors_base; | |||||
while (colors.size()) | |||||
{ | { | ||||
EasyMesh m; | EasyMesh m; | ||||
vec4 color = hex_to_color(colors.pop()); | |||||
vec4 color = hex_to_color(colors.back()); | |||||
colors.pop_back(); | |||||
m.SetCurColor(color); | m.SetCurColor(color); | ||||
m.SetCurColorB(color); | m.SetCurColorB(color); | ||||
m.AppendDisc(8, 2.f); | m.AppendDisc(8, 2.f); | ||||
@@ -289,7 +294,7 @@ public: | |||||
m.TranslateY(-1.f); | m.TranslateY(-1.f); | ||||
m.MirrorY(); | m.MirrorY(); | ||||
m.AppendCylinder(8.f, 2.f, 2.f, 2.f); | 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]"; | //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#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]"; | //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 | #endif //USE_CYLINDER | ||||
#if USE_CAPSULE | #if USE_CAPSULE | ||||
{ | { | ||||
array<std::string> colors = colors_base; | |||||
while (colors.count()) | |||||
std::vector<std::string> colors = colors_base; | |||||
while (colors.size()) | |||||
{ | { | ||||
EasyMesh m; | EasyMesh m; | ||||
vec4 color = hex_to_color(colors.pop()); | |||||
vec4 color = hex_to_color(colors.back()); | |||||
colors.pop_back(); | |||||
m.SetCurColor(color); | m.SetCurColor(color); | ||||
m.SetCurColorB(color); | m.SetCurColorB(color); | ||||
m.AppendCapsule(1, 2.f, 1.f); | m.AppendCapsule(1, 2.f, 1.f); | ||||
MeshRand << m; | |||||
MeshRand.push_back(m); | |||||
} | } | ||||
} | } | ||||
//MeshRand << "[sc#add scb#add acap1 2 1]"; | //MeshRand << "[sc#add scb#add acap1 2 1]"; | ||||
@@ -323,14 +329,14 @@ public: | |||||
//MeshRand << "[sc#ada scb#ada acap1 2 1]"; | //MeshRand << "[sc#ada scb#ada acap1 2 1]"; | ||||
//MeshRand << "[sc#aad scb#aad 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 | #endif //USE_CAPSULE | ||||
} | } | ||||
int RandLimit = RandValue; | 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]); | RandValue = rand(MeshLimit[RandLimit], MeshLimit[RandLimit + 1]); | ||||
m_physics = new EasyPhysic(this); | m_physics = new EasyPhysic(this); | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 Cédric Lecacheur <jordx@free.fr> | ||||
// © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // © 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))); | 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]) | if (m_based_physic_list[i]) | ||||
m_based_physic_list[i]->BaseTransformChanged(PreviousMatrix, m_local_to_world); | m_based_physic_list[i]->BaseTransformChanged(PreviousMatrix, m_local_to_world); | ||||
else | else | ||||
m_based_physic_list.remove(i--); | |||||
remove_at(m_based_physic_list, i--); | |||||
} | } | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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> | // © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// This library is free software. It comes without any warranty, to | // This library is free software. It comes without any warranty, to | ||||
@@ -19,6 +19,7 @@ | |||||
// | // | ||||
#include <lol/engine.h> | #include <lol/engine.h> | ||||
#include <vector> | |||||
#include <btBulletDynamicsCommon.h> | #include <btBulletDynamicsCommon.h> | ||||
#include <btBulletCollisionCommon.h> | #include <btBulletCollisionCommon.h> | ||||
@@ -80,16 +81,16 @@ protected: | |||||
virtual btGhostObject* GetGhostObjectInstance(); | 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: | public: | ||||
//Sets the collision Group & Mask. | //Sets the collision Group & Mask. | ||||
@@ -116,41 +117,41 @@ public: | |||||
if (NewBase) | if (NewBase) | ||||
{ | { | ||||
bool bAlreadyExists = false; | 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) | if (NewBase->m_based_physic_list[i] == this) | ||||
bAlreadyExists = true; | bAlreadyExists = true; | ||||
if (!bAlreadyExists) | if (!bAlreadyExists) | ||||
NewBase->m_based_physic_list << this; | |||||
NewBase->m_based_physic_list.push_back(this); | |||||
m_base_physic = NewBase; | m_base_physic = NewBase; | ||||
m_base_lock_location = NewBaseLockLocation; | m_base_lock_location = NewBaseLockLocation; | ||||
m_base_lock_rotation = NewBaseLockRotation; | m_base_lock_rotation = NewBaseLockRotation; | ||||
} | } | ||||
else if (m_base_physic) | 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) | 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; | m_base_physic = nullptr; | ||||
} | } | ||||
} | } | ||||
protected: | 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 | //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 | //Touch logic | ||||
array<EasyPhysic*> m_touching_physic; //Maintained by ghost objects | |||||
std::vector<EasyPhysic*> m_touching_physic; //Maintained by ghost objects | |||||
}; | }; | ||||
} /* namespace phys */ | } /* namespace phys */ | ||||
@@ -1,8 +1,8 @@ | |||||
// | // | ||||
// Lol Engine — Bullet physics test | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -14,6 +14,7 @@ | |||||
#pragma once | #pragma once | ||||
#include <cstring> | #include <cstring> | ||||
#include <vector> | |||||
#include <btBulletDynamicsCommon.h> | #include <btBulletDynamicsCommon.h> | ||||
#include <btBulletCollisionCommon.h> | #include <btBulletCollisionCommon.h> | ||||
@@ -41,12 +42,11 @@ enum eRaycastType | |||||
struct RayCastResult | struct RayCastResult | ||||
{ | { | ||||
RayCastResult(int CollisionFilterGroup=1, int CollisionFilterMask=(0xFF)) | 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() | void Reset() | ||||
{ | { | ||||
m_collider_list.clear(); | m_collider_list.clear(); | ||||
@@ -55,14 +55,14 @@ struct RayCastResult | |||||
m_hit_fraction_list.clear(); | 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 | class Simulation : public entity | ||||
@@ -207,20 +207,20 @@ public: | |||||
{ | { | ||||
case ERT_Closest: | 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; | break; | ||||
} | } | ||||
case ERT_AllHit: | case ERT_AllHit: | ||||
{ | { | ||||
for (int i = 0; i < BtRayResult_AllHits->m_collisionObjects.size(); i++) | 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; | break; | ||||
} | } | ||||
@@ -273,15 +273,15 @@ private: | |||||
void CustomSetTimestep(float NewTimestep) { } | void CustomSetTimestep(float NewTimestep) { } | ||||
//broadphase | //broadphase | ||||
btBroadphaseInterface* m_broadphase; | |||||
btAxisSweep3* m_Sweep_broadphase; | |||||
btBroadphaseInterface *m_broadphase; | |||||
btAxisSweep3 *m_Sweep_broadphase; | |||||
// Set up the collision configuration and dispatc | // 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 | // The actual physics solver | ||||
btSequentialImpulseConstraintSolver* m_solver; | |||||
btSequentialImpulseConstraintSolver *m_solver; | |||||
// The world. | // The world. | ||||
btDiscreteDynamicsWorld* m_dynamics_world; | |||||
btDiscreteDynamicsWorld *m_dynamics_world; | |||||
public: | public: | ||||
//Main logic : | //Main logic : | ||||
@@ -341,7 +341,7 @@ private: | |||||
//Adds the given EasyPhysic to the correct list. | //Adds the given EasyPhysic to the correct list. | ||||
void ObjectRegistration(bool AddObject, EasyPhysic* NewEP, eEasyPhysicType CurType) | void ObjectRegistration(bool AddObject, EasyPhysic* NewEP, eEasyPhysicType CurType) | ||||
{ | { | ||||
array<EasyPhysic*>* SearchList = nullptr; | |||||
std::vector<EasyPhysic*>* SearchList = nullptr; | |||||
switch(CurType) | switch(CurType) | ||||
{ | { | ||||
case EEPT_Dynamic: | case EEPT_Dynamic: | ||||
@@ -378,45 +378,45 @@ private: | |||||
if (AddObject) | if (AddObject) | ||||
{ | { | ||||
NewEP->m_owner_simulation = this; | NewEP->m_owner_simulation = this; | ||||
(*SearchList) << NewEP; | |||||
SearchList->push_back(NewEP); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
NewEP->m_owner_simulation = nullptr; | NewEP->m_owner_simulation = nullptr; | ||||
SearchList->remove_item(NewEP); | |||||
remove_item(*SearchList, NewEP); | |||||
} | } | ||||
} | } | ||||
void ObjectRegistration(bool AddObject, EasyConstraint* NewEC) | void ObjectRegistration(bool AddObject, EasyConstraint* NewEC) | ||||
{ | { | ||||
array<EasyConstraint*>* SearchList = nullptr; | |||||
std::vector<EasyConstraint*>* SearchList = nullptr; | |||||
SearchList = &m_constraint_list; | SearchList = &m_constraint_list; | ||||
if (AddObject) | if (AddObject) | ||||
{ | { | ||||
NewEC->m_owner_simulation = this; | NewEC->m_owner_simulation = this; | ||||
(*SearchList) << NewEC; | |||||
SearchList->push_back(NewEC); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
NewEC->m_owner_simulation = nullptr; | NewEC->m_owner_simulation = nullptr; | ||||
SearchList->remove_item(NewEC); | |||||
remove_item(*SearchList, NewEC); | |||||
} | } | ||||
} | } | ||||
//Easy Physics body List | //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 | //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 */ | } /* namespace phys */ | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — Triangle tutorial | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -28,7 +28,7 @@ class Triangle : public WorldEntity | |||||
public: | public: | ||||
virtual bool init_draw() override | virtual bool init_draw() override | ||||
{ | { | ||||
array<vec2> vertices | |||||
std::vector<vec2> vertices | |||||
{ | { | ||||
vec2( 0.0f, 0.8f), | vec2( 0.0f, 0.8f), | ||||
vec2(-0.8f, -0.8f), | vec2(-0.8f, -0.8f), | ||||
@@ -40,8 +40,8 @@ public: | |||||
m_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec2>(VertexUsage::Position)); | 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; | return true; | ||||
} | } | ||||
@@ -48,7 +48,7 @@ public: | |||||
virtual bool init_draw() override | virtual bool init_draw() override | ||||
{ | { | ||||
array<vertex> mesh | |||||
std::vector<vertex> mesh | |||||
{ | { | ||||
// Front vertices/colors | // Front vertices/colors | ||||
{ vec3(-1.0, -1.0, 1.0), vec3(1.0, 0.0, 1.0) }, | { 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) }, | { 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, | 0, 1, 1, 2, 2, 3, 3, 0, | ||||
4, 5, 5, 6, 6, 7, 7, 4, | 4, 5, 5, 6, 6, 7, 7, 4, | ||||
0, 4, 1, 5, 2, 6, 3, 7, | 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, | 0, 1, 2, 2, 3, 0, 1, 5, 6, 6, 2, 1, | ||||
7, 6, 5, 5, 4, 7, 4, 0, 3, 3, 7, 4, | 7, 6, 5, 5, 4, 7, 4, 0, 3, 3, 7, 4, | ||||
@@ -86,14 +86,14 @@ public: | |||||
VertexStream<vec3,vec3>(VertexUsage::Position, | VertexStream<vec3,vec3>(VertexUsage::Position, | ||||
VertexUsage::Color)); | 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; | return true; | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — Noise tutorial | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -28,7 +28,7 @@ class NoiseDemo : public WorldEntity | |||||
public: | public: | ||||
virtual bool init_draw() override | virtual bool init_draw() override | ||||
{ | { | ||||
array<vec2> vertices | |||||
std::vector<vec2> vertices | |||||
{ | { | ||||
vec2(-1.0, 1.0), | vec2(-1.0, 1.0), | ||||
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_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; | return true; | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — Graphing tutorial | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -15,6 +15,7 @@ | |||||
#endif | #endif | ||||
#include <lol/engine.h> | #include <lol/engine.h> | ||||
#include <vector> | |||||
#include "loldebug.h" | #include "loldebug.h" | ||||
using namespace lol; | using namespace lol; | ||||
@@ -30,7 +31,7 @@ public: | |||||
{ | { | ||||
/* Generate a new heightmap at the beginning */ | /* Generate a new heightmap at the beginning */ | ||||
m_heightmap.resize(TEXTURE_WIDTH * 1); | 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; | return true; | ||||
} | } | ||||
@@ -40,13 +41,13 @@ public: | |||||
WorldEntity::tick_game(seconds); | WorldEntity::tick_game(seconds); | ||||
/* Scroll left */ | /* 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]; | 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 = (int)(height + 127 + 40 * lol::sin(m_frames * 0.03) + rand() % 97 - 38) / 2; | ||||
height = std::max(15, std::min(height, 240)); | height = std::max(15, std::min(height, 240)); | ||||
m_heightmap.last() = height; | |||||
m_heightmap.back() = height; | |||||
/* Update frame counter */ | /* Update frame counter */ | ||||
++m_frames; | ++m_frames; | ||||
@@ -54,7 +55,7 @@ public: | |||||
virtual bool init_draw() override | virtual bool init_draw() override | ||||
{ | { | ||||
array<vec2> vertices | |||||
std::vector<vec2> vertices | |||||
{ | { | ||||
vec2(-1.0, 1.0), | vec2(-1.0, 1.0), | ||||
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_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; | return true; | ||||
} | } | ||||
@@ -110,7 +111,7 @@ private: | |||||
ShaderUniform m_texture_uni; | ShaderUniform m_texture_uni; | ||||
std::shared_ptr<VertexDeclaration> m_vdecl; | std::shared_ptr<VertexDeclaration> m_vdecl; | ||||
std::shared_ptr<VertexBuffer> m_vbo; | std::shared_ptr<VertexBuffer> m_vbo; | ||||
array<uint8_t> m_heightmap; | |||||
std::vector<uint8_t> m_heightmap; | |||||
int m_frames = 0; | int m_frames = 0; | ||||
}; | }; | ||||
@@ -39,11 +39,11 @@ public: | |||||
EasyMeshLuaObject* gears3 = EzMhLoader.GetPtr<EasyMeshLuaObject>("g3"); | EasyMeshLuaObject* gears3 = EzMhLoader.GetPtr<EasyMeshLuaObject>("g3"); | ||||
EasyMeshLuaObject* gears4 = EzMhLoader.GetPtr<EasyMeshLuaObject>("g4"); | 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]" | 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)); | scene.get_renderer()->clear_color(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | ||||
/* Upload vertex data to GPU */ | /* 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(); | m_gears[i].mesh.MeshConvert(); | ||||
#if USE_CUSTOM_SHADER | #if USE_CUSTOM_SHADER | ||||
@@ -132,7 +132,7 @@ public: | |||||
auto custom_shader = Shader::Create(LOLFX_RESOURCE_NAME(easymesh_shiny)); | auto custom_shader = Shader::Create(LOLFX_RESOURCE_NAME(easymesh_shiny)); | ||||
// any other shader stuf here (Get uniform, mostly, and set texture) | // 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); | m_gears[i].mesh.SetMaterial(custom_shader); | ||||
#endif | #endif | ||||
@@ -143,7 +143,7 @@ public: | |||||
{ | { | ||||
WorldEntity::tick_draw(seconds, scene); | 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); | m_gears[i].mesh.Render(scene, m_mat * m_gears[i].mat); | ||||
} | } | ||||
@@ -157,7 +157,7 @@ public: | |||||
private: | private: | ||||
struct gear { EasyMesh mesh; mat4 mat; float anim; }; | struct gear { EasyMesh mesh; mat4 mat; float anim; }; | ||||
array<gear> m_gears; | |||||
std::vector<gear> m_gears; | |||||
float m_angle; | float m_angle; | ||||
mat4 m_mat; | mat4 m_mat; | ||||
@@ -35,8 +35,8 @@ public: | |||||
for (int i = 0; i < SPRITE_COUNT; ++i) | 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; | static int const FRAME_COUNT = 16; | ||||
struct sprite { vec3 pos; float anim; }; | struct sprite { vec3 pos; float anim; }; | ||||
array<sprite> m_sprites; | |||||
std::vector<sprite> m_sprites; | |||||
}; | }; | ||||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
@@ -104,7 +104,7 @@ public: | |||||
virtual bool init_draw() override | virtual bool init_draw() override | ||||
{ | { | ||||
array<vertex> mesh | |||||
std::vector<vertex> mesh | |||||
{ | { | ||||
// Front vertices/colors | // Front vertices/colors | ||||
{ vec3(-1.0, -1.0, 1.0), vec3(1.0, 0.0, 1.0) }, | { 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) }, | { 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, | 0, 1, 2, 2, 3, 0, 1, 5, 6, 6, 2, 1, | ||||
7, 6, 5, 5, 4, 7, 4, 0, 3, 3, 7, 4, | 7, 6, 5, 5, 4, 7, 4, 0, 3, 3, 7, 4, | ||||
4, 5, 1, 1, 0, 4, 3, 2, 6, 6, 7, 3, | 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, | 0, 1, 1, 2, 2, 3, 3, 0, | ||||
4, 5, 5, 6, 6, 7, 7, 4, | 4, 5, 5, 6, 6, 7, 7, 4, | ||||
@@ -142,14 +142,14 @@ public: | |||||
VertexStream<vec3,vec3>(VertexUsage::Position, | VertexStream<vec3,vec3>(VertexUsage::Position, | ||||
VertexUsage::Color)); | 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(); | return WorldEntity::init_draw(); | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — Framebuffer Object tutorial | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -44,7 +44,7 @@ public: | |||||
virtual bool init_draw() override | virtual bool init_draw() override | ||||
{ | { | ||||
array<vec2> vertices | |||||
std::vector<vec2> vertices | |||||
{ | { | ||||
vec2( 1.0, 1.0), | vec2( 1.0, 1.0), | ||||
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_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 | // Create the back buffer and clear it | ||||
m_backbuffer = std::make_shared<Framebuffer>(Video::GetSize()); | m_backbuffer = std::make_shared<Framebuffer>(Video::GetSize()); | ||||
@@ -85,7 +85,7 @@ public: | |||||
uint8_t red = (uint8_t)(rgb.r * 256); | uint8_t red = (uint8_t)(rgb.r * 256); | ||||
uint8_t green = (uint8_t)(rgb.g * 256); | uint8_t green = (uint8_t)(rgb.g * 256); | ||||
uint8_t blue = (uint8_t)(rgb.b * 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"); | m_zoomtext = new Text("", "data/font/ascii.png"); | ||||
@@ -530,7 +530,7 @@ private: | |||||
ivec2 m_size, m_window_size, m_oldmouse; | ivec2 m_size, m_window_size, m_oldmouse; | ||||
double m_window2world; | double m_window2world; | ||||
dvec2 m_texel2world; | dvec2 m_texel2world; | ||||
array<u8vec4> m_pixels, m_palette; | |||||
std::vector<u8vec4> m_pixels, m_palette; | |||||
std::shared_ptr<Shader> m_shader; | std::shared_ptr<Shader> m_shader; | ||||
ShaderAttrib m_vertexattrib, m_texattrib; | ShaderAttrib m_vertexattrib, m_texattrib; | ||||
@@ -43,12 +43,12 @@ class Voronoi : public WorldEntity | |||||
public: | public: | ||||
Voronoi() | 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_ready = false; | ||||
m_cur_fbo = 0; | m_cur_fbo = 0; | ||||
m_time = .0f; | m_time = .0f; | ||||
@@ -86,8 +86,8 @@ public: | |||||
{ | { | ||||
m_vdecl = std::make_shared<VertexDeclaration>(VertexStream<vec2>(VertexUsage::Position)); | 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_shader = Shader::Create(LOLFX_RESOURCE_NAME(12_texture_to_screen)); | ||||
m_screen_coord = m_screen_shader->GetAttribLocation(VertexUsage::Position, 0); | m_screen_coord = m_screen_shader->GetAttribLocation(VertexUsage::Position, 0); | ||||
@@ -95,29 +95,29 @@ public: | |||||
for (int i = 0; i < MaxFboType; ++i) | for (int i = 0; i < MaxFboType; ++i) | ||||
{ | { | ||||
m_fbos.push(fbo | |||||
m_fbos.push_back(fbo | |||||
{ | { | ||||
std::make_shared<Framebuffer>(Video::GetSize()), | std::make_shared<Framebuffer>(Video::GetSize()), | ||||
0, | 0, | ||||
array<ShaderUniform>(), | |||||
array<ShaderAttrib>(), | |||||
std::vector<ShaderUniform>(), | |||||
std::vector<ShaderAttrib>(), | |||||
}); | }); | ||||
if (i == SrcVoronoiFbo) | if (i == SrcVoronoiFbo) | ||||
{ | { | ||||
m_fbos[i].shader = Shader::Create(LOLFX_RESOURCE_NAME(12_voronoi_setup)); | 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) | else if (i == VoronoiFbo) | ||||
{ | { | ||||
m_fbos[i].shader = Shader::Create(LOLFX_RESOURCE_NAME(12_voronoi)); | 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) | else if (i == DistanceVoronoiFbo) | ||||
{ | { | ||||
@@ -128,14 +128,14 @@ public: | |||||
m_fbos[i].shader = Shader::Create(LOLFX_RESOURCE_NAME(12_distance)); | 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()); | render_context rc(scene.get_renderer()); | ||||
rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | ||||
rc.clear_depth(1.f); | rc.clear_depth(1.f); | ||||
scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | 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()); | temp_buffer = std::make_shared<Framebuffer>(Video::GetSize()); | ||||
@@ -158,9 +158,9 @@ public: | |||||
auto keyboard = input::keyboard(); | auto keyboard = input::keyboard(); | ||||
if (keyboard->key_released(input::key::SC_O)) | if (keyboard->key_released(input::key::SC_O)) | ||||
voronoi_points.pop(); | |||||
voronoi_points.pop_back(); | |||||
else if (keyboard->key_released(input::key::SC_P)) | 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), | vec3(rand<float>(512.f), rand<float>(512.f), .0f), | ||||
vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f)) | vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f)) | ||||
@@ -176,7 +176,7 @@ public: | |||||
{ | { | ||||
int i = 4; | int i = 4; | ||||
while (i-- > 0) | while (i-- > 0) | ||||
voronoi_points.push(point | |||||
voronoi_points.push_back(point | |||||
{ | { | ||||
vec3(rand<float>(512.f), rand<float>(512.f), .0f), | vec3(rand<float>(512.f), rand<float>(512.f), .0f), | ||||
vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f)) | vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f)) | ||||
@@ -199,12 +199,12 @@ public: | |||||
float mi = (float)maxi; | float mi = (float)maxi; | ||||
float j = (float)i; | float j = (float)i; | ||||
float f_time = (float)m_time; | 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(); | temp_buffer->Bind(); | ||||
@@ -219,7 +219,7 @@ public: | |||||
{ | { | ||||
vec2 limit(1.f, 511.f); | vec2 limit(1.f, 511.f); | ||||
//SRC SETUP | //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); | 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) | 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].speed.y *= -1.f; | ||||
voronoi_points[j].pos.y = clamp(voronoi_points[j].pos.y, limit.x, limit.y); | 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; | int f = SrcVoronoiFbo; | ||||
@@ -246,8 +246,8 @@ public: | |||||
} | } | ||||
m_fbos[f].framebuffer->Unbind(); | 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; | 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_fbos[f].shader->SetUniform(m_fbos[f].uni[i++], vec2(512.f, 512.f)); //"u_screen_res" | ||||
m_vdecl->Bind(); | 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->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
m_fbos[f].shader->Unbind(); | m_fbos[f].shader->Unbind(); | ||||
@@ -339,7 +339,7 @@ public: | |||||
} | } | ||||
m_vdecl->Bind(); | 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->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
m_fbos[m_cur_fbo].shader->Unbind(); | m_fbos[m_cur_fbo].shader->Unbind(); | ||||
@@ -371,8 +371,8 @@ public: | |||||
private: | private: | ||||
struct point { vec3 pos; vec2 speed; }; | 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; | std::shared_ptr<Shader> m_screen_shader; | ||||
ShaderAttrib m_screen_coord; | ShaderAttrib m_screen_coord; | ||||
ShaderUniform m_screen_texture; | ShaderUniform m_screen_texture; | ||||
@@ -384,10 +384,10 @@ private: | |||||
{ | { | ||||
std::shared_ptr<Framebuffer> framebuffer; | std::shared_ptr<Framebuffer> framebuffer; | ||||
std::shared_ptr<Shader> shader; | 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; | std::shared_ptr<Framebuffer> temp_buffer; | ||||
int mode; | 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 \ | textureimage.cpp textureimage.h textureimage-private.h \ | ||||
tileset.cpp tileset.h video.cpp video.h \ | tileset.cpp tileset.h video.cpp video.h \ | ||||
profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.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 \ | gradient.cpp gradient.h gradient.lolfx \ | ||||
platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ | platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ | ||||
light.cpp light.h \ | light.cpp light.h \ | ||||
@@ -31,8 +31,7 @@ liblol_core_headers = \ | |||||
lol/lua.h \ | lol/lua.h \ | ||||
\ | \ | ||||
lol/base/all.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/all.h \ | ||||
lol/audio/audio.h lol/audio/sample.h \ | lol/audio/audio.h lol/audio/sample.h \ | ||||
@@ -67,11 +66,11 @@ liblol_core_sources = \ | |||||
commandstack.h \ | commandstack.h \ | ||||
easymesh/easymeshbuild.cpp easymesh/easymeshbuild.h \ | easymesh/easymeshbuild.cpp easymesh/easymeshbuild.h \ | ||||
easymesh/easymeshrender.cpp easymesh/easymeshrender.h \ | easymesh/easymeshrender.cpp easymesh/easymeshrender.h \ | ||||
easymesh/easymesh.cpp \ | |||||
easymesh/easymesh.cpp easymesh/easymesh.h \ | |||||
easymesh/easymeshinternal.cpp easymesh/easymeshcsg.cpp \ | easymesh/easymeshinternal.cpp easymesh/easymeshcsg.cpp \ | ||||
easymesh/easymeshprimitive.cpp easymesh/easymeshtransform.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/csgbsp.cpp easymesh/csgbsp.h \ | ||||
easymesh/shiny.lolfx easymesh/shinyflat.lolfx \ | easymesh/shiny.lolfx easymesh/shinyflat.lolfx \ | ||||
easymesh/shinydebugwireframe.lolfx \ | easymesh/shinydebugwireframe.lolfx \ | ||||
@@ -112,9 +112,9 @@ void msg::helper(message_type type, char const *fmt, va_list ap) | |||||
# if defined _WIN32 | # if defined _WIN32 | ||||
std::string buf = std::string(prefix[(int)type]) + ": " + vformat(fmt, ap); | std::string buf = std::string(prefix[(int)type]) + ": " + vformat(fmt, ap); | ||||
array<WCHAR> widechar; | |||||
std::vector<WCHAR> widechar; | |||||
widechar.resize(buf.length() + 1); | 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()); | OutputDebugStringW(widechar.data()); | ||||
# elif defined __EMSCRIPTEN__ | # elif defined __EMSCRIPTEN__ | ||||
fprintf(stdout, "%s: ", prefix[(int)type]); | fprintf(stdout, "%s: ", prefix[(int)type]); | ||||
@@ -23,29 +23,30 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
//Utility struct to convert command code to pseudo-bytecode | |||||
// Utility struct to convert command code to pseudo-bytecode | |||||
struct CommandStack | struct CommandStack | ||||
{ | { | ||||
private: | 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: | public: | ||||
//GET/SET exec | //GET/SET exec | ||||
int GetCmdNb() { return m_commands.count(); } | |||||
int GetCmdNb() { return int(m_commands.size()); } | |||||
int GetCmd(int i) | 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 | //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 | //GETTER | ||||
inline float F() { return m_floats[m_f_cur++]; } | inline float F() { return m_floats[m_f_cur++]; } | ||||
@@ -74,8 +75,8 @@ public: | |||||
void GetValue(SafeEnum<DEF> &i) { i = typename DEF::Type(I()); } | void GetValue(SafeEnum<DEF> &i) { i = typename DEF::Type(I()); } | ||||
//SETTER | //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<<(bool b) { return (*this << (int)b); } | ||||
CommandStack &operator<<(vec2 v) { return (*this << v.x << v.y); } | CommandStack &operator<<(vec2 v) { return (*this << v.x << v.y); } | ||||
CommandStack &operator<<(vec3 v) { return (*this << v.xy << v.z); } | 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) | void CsgBsp::AddTriangleToTree(int const &tri_idx, vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2) | ||||
{ | { | ||||
//<Leaf_Id, v0, v1, v2> | //<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> | //<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 | //Tree is empty, so this leaf is the first | ||||
if (m_tree.count() == 0) | 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, | 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. | //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; } | //<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. | //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> | //<{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. | //This list stores the current triangles to process. | ||||
//<Leaf_Id_List, v0, v1, v2, Should_Point_Test> | //<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 ! | //Tree is empty, ABORT ! | ||||
if (m_tree.count() == 0) | 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. | //Let's push the triangle in here. | ||||
tri_to_process.reserve(20); | 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); | std::get<0>(tri_to_process.last()).push(0); | ||||
while (tri_to_process.count()) | 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]); | t[(isec_base + 2) % 3], new_v_idx[v_idx1], new_v_idx[v_idx0]); | ||||
else | 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); | 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 | 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); | 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); | std::get<0>(tri_to_process.last()).push(0); | ||||
} | } | ||||
#else | #else | ||||
@@ -415,14 +415,14 @@ int CsgBsp::TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 cons | |||||
continue; | continue; | ||||
#endif | #endif | ||||
#if 0 //Send the newly created triangle back to the beginning | #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); | std::get<0>(tri_to_process.last()).push(0); | ||||
#else //Inherit parent tree | #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) | 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]); | tri_list.push(new_side[k / 3], new_t[k], new_t[k + 1], new_t[k + 2]); | ||||
else | 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]); | 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) | if (m_tree[leaf_idx].m_leaves[new_side[k / 3]] == LEAF_CURRENT) | ||||
std::get<0>(tri_to_process.last()).pop(); | 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 | #endif | ||||
std::get<0>(tri_list[i]) = LEAF_BACK; | std::get<0>(tri_list[i]) = LEAF_BACK; | ||||
#if 0 | #if 0 | ||||
tri_to_process.push(array< int >(), | |||||
tri_to_process.push(easy_array< int >(), | |||||
std::get<1>(tri_list[i]), | std::get<1>(tri_list[i]), | ||||
std::get<2>(tri_list[i]), | std::get<2>(tri_list[i]), | ||||
std::get<3>(tri_list[i]), 0); | 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 | #pragma once | ||||
#include "easyarray.h" | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -38,7 +42,7 @@ public: | |||||
private: | private: | ||||
vec3 m_origin; | vec3 m_origin; | ||||
vec3 m_normal; | vec3 m_normal; | ||||
array< int, vec3, vec3, vec3 > m_tri_list; | |||||
easy_array< int, vec3, vec3, vec3 > m_tri_list; | |||||
ivec3 m_leaves; | ivec3 m_leaves; | ||||
}; | }; | ||||
@@ -54,16 +58,16 @@ public: | |||||
int TestTriangleToTree(vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2, | 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. | //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; } | //<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. | //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> | //<{IN|OUT}side_status, v0, v1, v2> | ||||
array< int, int, int, int > &tri_list); | |||||
easy_array< int, int, int, int > &tri_list); | |||||
private: | private: | ||||
int AddLeaf(int leaf_type, vec3 origin, vec3 normal, int above_idx); | int AddLeaf(int leaf_type, vec3 origin, vec3 normal, int above_idx); | ||||
int TestPoint(int leaf_idx, vec3 point); | int TestPoint(int leaf_idx, vec3 point); | ||||
array<CsgBspLeaf> m_tree; | |||||
easy_array<CsgBspLeaf> m_tree; | |||||
}; | }; | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -14,10 +14,10 @@ | |||||
#pragma once | #pragma once | ||||
// | // | ||||
// The array class | |||||
// ——————————————— | |||||
// The easyarray class | |||||
// ——————————————————— | |||||
// A very simple array class not unlike the std::vector, with some nice | // 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() | #include <cassert> // assert() | ||||
@@ -229,17 +229,6 @@ public: | |||||
++m_count; | ++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) | inline ptrdiff_t find(T const &x) | ||||
{ | { | ||||
for (ptrdiff_t i = 0; i < m_count; ++i) | for (ptrdiff_t i = 0; i < m_count; ++i) | ||||
@@ -439,10 +428,10 @@ protected: | |||||
*/ | */ | ||||
template<typename... T> | 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: | 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 | // Mark these as private: it’s dangerous to use data() with arrays of | ||||
// tuples because no assumption should be made about the tuple layout, | // tuples because no assumption should be made about the tuple layout, | ||||
@@ -489,10 +478,10 @@ public: | |||||
}; | }; | ||||
template<typename T> | 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> | 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> | 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> | 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> | 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 */ | } /* namespace lol */ |
@@ -1,9 +1,9 @@ | |||||
// | // | ||||
// Lol Engine | // 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> | // © 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -15,6 +15,7 @@ | |||||
#pragma once | #pragma once | ||||
#include "commandstack.h" | #include "commandstack.h" | ||||
#include "easyarray.h" | |||||
#include "easymeshrender.h" | #include "easymeshrender.h" | ||||
#include "easymeshbuild.h" | #include "easymeshbuild.h" | ||||
@@ -100,7 +101,7 @@ public: | |||||
void ExecuteCmdStack(bool ExecAllStack = true); | void ExecuteCmdStack(bool ExecAllStack = true); | ||||
private: | private: | ||||
void UpdateVertexDict(array< int, int > &vertex_dict); | |||||
void UpdateVertexDict(easy_array< int, int > &vertex_dict); | |||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
//Mesh CSG operations | //Mesh CSG operations | ||||
@@ -417,11 +418,11 @@ public: | |||||
vec3 const &GetVertexLocation(int i) { return m_vert[i].m_coord; } | vec3 const &GetVertexLocation(int i) { return m_vert[i].m_coord; } | ||||
//private: | //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> | //<vert count, indices count> | ||||
array<int, int> m_cursors; | |||||
easy_array<int, int> m_cursors; | |||||
MeshRender m_state; | 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. | //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); | 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. | //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); | FindConnectedTriangles(search_idx, tri_list, tri0, connected_tri, ignored_tri); | ||||
for (int i = 0; i < connected_tri.count(); i++) | 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); | 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); | 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); | 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; | int needed_validation = 0; | ||||
array<int> vert_list[3]; | |||||
easy_array<int> vert_list[3]; | |||||
for (int i = 0; i < 3; i++) | for (int i = 0; i < 3; i++) | ||||
{ | { | ||||
//Small optim since above func will use this one | //Small optim since above func will use this one | ||||
@@ -296,7 +296,7 @@ public: | |||||
inline CommandStack &CmdStack() { return m_stack; } | inline CommandStack &CmdStack() { return m_stack; } | ||||
inline int &Cmdi() { return m_i_cmd; } | inline int &Cmdi() { return m_i_cmd; } | ||||
inline int &CmdExecNb() { return m_exec_nb; } | 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 &ColorA() { return m_color_a; } | ||||
inline vec4 &ColorB() { return m_color_b; } | inline vec4 &ColorB() { return m_color_b; } | ||||
inline vec2 &TexCoordOffset() { return m_texcoord_offset; } | inline vec2 &TexCoordOffset() { return m_texcoord_offset; } | ||||
@@ -496,15 +496,15 @@ public: | |||||
CommandStack m_stack; | CommandStack m_stack; | ||||
int m_i_cmd; | int m_i_cmd; | ||||
int m_exec_nb; | int m_exec_nb; | ||||
array<int, int> m_loop_stack; | |||||
easy_array<int, int> m_loop_stack; | |||||
vec4 m_color_a; | vec4 m_color_a; | ||||
vec4 m_color_b; | vec4 m_color_b; | ||||
vec2 m_texcoord_offset; | vec2 m_texcoord_offset; | ||||
vec2 m_texcoord_offset2; | vec2 m_texcoord_offset2; | ||||
vec2 m_texcoord_scale; | vec2 m_texcoord_scale; | ||||
vec2 m_texcoord_scale2; | 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_type[MeshType::MAX]; | ||||
uint32_t m_texcoord_build_type2[MeshType::MAX]; | uint32_t m_texcoord_build_type2[MeshType::MAX]; | ||||
uint32_t m_build_flags = MeshBuildOperation::PreventVertCleanup; | uint32_t m_build_flags = MeshBuildOperation::PreventVertCleanup; | ||||
@@ -536,20 +536,20 @@ class VertexDictionnary | |||||
{ | { | ||||
public: | public: | ||||
int FindVertexMaster(const int search_idx); | 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 RegisterVertex(int vert_id, vec3 vert_coord); | ||||
void RemoveVertex(int vert_id); | 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(); } | void Clear() { vertex_list.clear(); } | ||||
private: | private: | ||||
//<VertexId, VertexLocation, VertexMasterId> | //<VertexId, VertexLocation, VertexMasterId> | ||||
array<int, vec3, int> vertex_list; | |||||
easy_array<int, vec3, int> vertex_list; | |||||
//List of the master_ vertices | //List of the master_ vertices | ||||
array<int> master_list; | |||||
easy_array<int> master_list; | |||||
}; | }; | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -35,13 +35,13 @@ void EasyMesh::MeshCsg(CSGUsage csg_operation) | |||||
} | } | ||||
//A vertex dictionnary for vertices on the same spot. | //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. | //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>> | //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> | //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++) | for (int k = 0; k < 10; k++) | ||||
triangle_vertex.push(vec3(.0f), 0); | 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 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); | 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); | 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); | vec3 n0(.0f); vec3 n1(.0f); | ||||
vec4 c0(.0f); vec4 c1(.0f); | vec4 c0(.0f); vec4 c1(.0f); | ||||
@@ -127,7 +127,7 @@ void EasyMesh::ComputeNormals(int start, int vcount) | |||||
BD()->IsEnabled(MeshBuildOperation::PostBuildComputeNormals)) | BD()->IsEnabled(MeshBuildOperation::PostBuildComputeNormals)) | ||||
return; | return; | ||||
array< array<vec3> > normals; | |||||
easy_array< easy_array<vec3> > normals; | |||||
normals.resize(m_vert.count()); | normals.resize(m_vert.count()); | ||||
for (int i = 0; i < vcount; i += 3) | for (int i = 0; i < vcount; i += 3) | ||||
{ | { | ||||
@@ -162,7 +162,7 @@ void EasyMesh::ComputeNormals(int start, int vcount) | |||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
void EasyMesh::VerticesCleanup() | void EasyMesh::VerticesCleanup() | ||||
{ | { | ||||
array<int> vert_ids; | |||||
easy_array<int> vert_ids; | |||||
vert_ids.resize(m_vert.count(), 0); | vert_ids.resize(m_vert.count(), 0); | ||||
//1: Remove triangles with two vertices on each other | //1: Remove triangles with two vertices on each other | ||||
@@ -186,7 +186,7 @@ void EasyMesh::VerticesCleanup() | |||||
} | } | ||||
//2: Remove all unused vertices | //2: Remove all unused vertices | ||||
array<VertexData> old_vert = m_vert; | |||||
easy_array<VertexData> old_vert = m_vert; | |||||
int shift = 0; | int shift = 0; | ||||
m_vert.clear(); | m_vert.clear(); | ||||
for (int i = 0; i < vert_ids.count(); ++i) | for (int i = 0; i < vert_ids.count(); ++i) | ||||
@@ -240,8 +240,8 @@ void EasyMesh::VerticesSeparate() | |||||
return; | 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); | vert_ids.resize(m_vert.count(), 0); | ||||
//1: Mark all used vertices | //1: Mark all used vertices | ||||
@@ -283,7 +283,7 @@ void EasyMesh::ComputeTexCoord(float uv_scale, int uv_offset) | |||||
UNUSED(uv_scale, uv_offset); | UNUSED(uv_scale, uv_offset); | ||||
#if 0 | #if 0 | ||||
VertexDictionnary vert_dict; | VertexDictionnary vert_dict; | ||||
array<int> tri_list; | |||||
easy_array<int> tri_list; | |||||
tri_list.Reserve(m_indices.count() - std::get<1>(m_cursors.last())); | 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++) | 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 | //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; | int tri_count = (m_indices.count() - std::get<1>(m_cursors.last())) / 3; | ||||
tri_check << tri_list[0]; | 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); | uv[2] = texu_dir * dot(v01, v02) + texv_dir * dot(v_dir, v02); | ||||
//Set UV on ALL matching vertices! | //Set UV on ALL matching vertices! | ||||
array<int> matching_vert; | |||||
easy_array<int> matching_vert; | |||||
for (int i = 0; i < 3; i++) | for (int i = 0; i < 3; i++) | ||||
{ | { | ||||
#if 1 | #if 1 | ||||
@@ -1,8 +1,8 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // 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) | void EasyMeshLuaLoader::Store(LuaObject* obj) | ||||
{ | { | ||||
EasyMeshLuaObject* ezm = static_cast<EasyMeshLuaObject*>(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; | return g_instances; | ||||
} | } | ||||
@@ -1,8 +1,8 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -141,7 +141,7 @@ public: | |||||
virtual ~EasyMeshLuaLoader(); | virtual ~EasyMeshLuaLoader(); | ||||
//Virtual Store lua object ------------------------------------------------ | //Virtual Store lua object ------------------------------------------------ | ||||
virtual void Store(LuaObject* obj); | virtual void Store(LuaObject* obj); | ||||
array<EasyMeshLuaObject*>& GetInstances(); | |||||
easy_array<EasyMeshLuaObject*>& GetInstances(); | |||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
protected: | protected: | ||||
@@ -141,7 +141,7 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float d) | |||||
int ibase = m_indices.count(); | int ibase = m_indices.count(); | ||||
array<vec3> vertices; | |||||
easy_array<vec3> vertices; | |||||
float uv_h = 0; | float uv_h = 0; | ||||
float uv_r = 0; | float uv_r = 0; | ||||
@@ -94,8 +94,8 @@ protected: | |||||
std::shared_ptr<Shader> m_shader; | std::shared_ptr<Shader> m_shader; | ||||
int m_render_mode; | int m_render_mode; | ||||
uint16_t m_vert_decl_flags; | 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 | class DefaultShaderData : public GpuShaderData | ||||
@@ -110,7 +110,7 @@ public: | |||||
void SetupDefaultData(bool with_UV); | void SetupDefaultData(bool with_UV); | ||||
virtual void SetupShaderDatas(mat4 const &model); | virtual void SetupShaderDatas(mat4 const &model); | ||||
//-- | //-- | ||||
array<std::string> m_uniform_names; | |||||
easy_array<std::string> m_uniform_names; | |||||
}; | }; | ||||
class GpuEasyMeshData | class GpuEasyMeshData | ||||
@@ -129,9 +129,9 @@ public: | |||||
private: | private: | ||||
void SetupVertexData(uint16_t vdecl_flags, std::shared_ptr<EasyMesh> src_mesh); | 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. | //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; | size_t m_vertexcount; | ||||
//We only need only one ibo for the whole mesh | //We only need only one ibo for the whole mesh | ||||
std::shared_ptr<IndexBuffer> m_ibo; | std::shared_ptr<IndexBuffer> m_ibo; | ||||
@@ -71,7 +71,7 @@ void EasyMesh::RadialJitter(float r) | |||||
return; | return; | ||||
} | } | ||||
array<int> welded; | |||||
easy_array<int> welded; | |||||
welded.push(-1); | welded.push(-1); | ||||
for (int i = std::get<0>(m_cursors.last()) + 1; i < m_vert.count(); i++) | 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; | 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; | int smbuf = 0; | ||||
for (int i = std::get<0>(m_cursors.last()); i < m_vert.count(); i++) | 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 <unordered_set> // std::unordered_set | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <functional> | #include <functional> | ||||
#include <vector> // std::vector | |||||
#include <stdint.h> | #include <stdint.h> | ||||
namespace lol | namespace lol | ||||
@@ -45,8 +46,8 @@ public: | |||||
{ | { | ||||
ASSERT(DEPRECATED_nentities == 0, | ASSERT(DEPRECATED_nentities == 0, | ||||
"still %d entities in ticker\n", DEPRECATED_nentities); | "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); | msg::debug("%d frames required to quit\n", m_frame - m_quitframe); | ||||
if (thread::has_threads()) | if (thread::has_threads()) | ||||
@@ -69,8 +70,8 @@ private: | |||||
std::unordered_set<std::shared_ptr<tickable>> m_tickables; | std::unordered_set<std::shared_ptr<tickable>> m_tickables; | ||||
/* Entity management */ | /* 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]; | std::vector<int> DEPRECATED_m_scenes[(int)tickable::group::all::end]; | ||||
int DEPRECATED_nentities = 0; | 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 | /* 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 | * ready yet, so we do not know which group this entity belongs to. Wait | ||||
* until the first tick. */ | * 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. */ | /* 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->add_flags(entity::flags::autorelease); | ||||
entity->m_ref = 1; | entity->m_ref = 1; | ||||
@@ -146,11 +147,11 @@ void Ticker::Ref(entity *entity) | |||||
/* Get the entity out of the autorelease list. This is usually | /* Get the entity out of the autorelease list. This is usually | ||||
* very fast since the last entry in autolist is the last | * very fast since the last entry in autolist is the last | ||||
* registered entity. */ | * 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) | if (data->DEPRECATED_m_autolist[i] == entity) | ||||
{ | { | ||||
data->DEPRECATED_m_autolist.remove_swap(i); | |||||
remove_at(data->DEPRECATED_m_autolist, i); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@@ -238,7 +239,7 @@ void ticker_data::GameThreadTick() | |||||
msg::debug("%s Group %d\n", | msg::debug("%s Group %d\n", | ||||
(g < (int)tickable::group::game::end) ? "Game" : "Draw", g); | (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]; | entity *e = data->DEPRECATED_m_list[g][i]; | ||||
msg::debug(" \\-- [%p] %s (m_ref %d, destroy %d)\n", | msg::debug(" \\-- [%p] %s (m_ref %d, destroy %d)\n", | ||||
@@ -283,9 +284,9 @@ void ticker_data::GameThreadTick() | |||||
data->collect_garbage(); | data->collect_garbage(); | ||||
/* Insert waiting objects into the appropriate lists */ | /* 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 the entity has no mask, default it | ||||
if (e->m_scene_mask == 0) | if (e->m_scene_mask == 0) | ||||
@@ -293,8 +294,8 @@ void ticker_data::GameThreadTick() | |||||
Scene::GetScene().Link(e); | 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 (e->m_drawgroup != tickable::group::draw::none) | ||||
{ | { | ||||
if (data->DEPRECATED_m_scenes[(int)e->m_drawgroup].size() < Scene::GetCount()) | 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 entity is concerned by this scene, add it in the list | ||||
if (Scene::GetScene(i).IsRelevant(e)) | 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++; | added_count++; | ||||
} | } | ||||
//Update scene index | //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 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]; | entity *e = data->DEPRECATED_m_list[g][i]; | ||||
@@ -342,7 +343,7 @@ void ticker_data::GameThreadTick() | |||||
/* Tick objects for the game loop */ | /* 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 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]; | 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 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]; | entity *e = data->DEPRECATED_m_list[g][i]; | ||||
@@ -417,7 +418,7 @@ void ticker_data::DrawThreadTick() | |||||
break; | 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]; | entity *e = data->DEPRECATED_m_list[g][i]; | ||||
@@ -465,7 +466,7 @@ void ticker_data::handle_shutdown() | |||||
m_panic = 2 * (m_panic + 1); | m_panic = 2 * (m_panic + 1); | ||||
for (int g = 0; g < (int)tickable::group::all::end && n < m_panic; ++g) | 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]; | entity * e = DEPRECATED_m_list[g][i]; | ||||
if (e->m_ref) | if (e->m_ref) | ||||
@@ -496,7 +497,7 @@ void ticker_data::collect_garbage() | |||||
std::unordered_set<entity*> destroy_list; | std::unordered_set<entity*> destroy_list; | ||||
for (int g = 0; g < (int)tickable::group::all::end; ++g) | for (int g = 0; g < (int)tickable::group::all::end; ++g) | ||||
{ | { | ||||
for (int i = DEPRECATED_m_list[g].count(); i--;) | |||||
for (size_t i = DEPRECATED_m_list[g].size(); i--;) | |||||
{ | { | ||||
entity *e = DEPRECATED_m_list[g][i]; | entity *e = DEPRECATED_m_list[g][i]; | ||||
@@ -513,7 +514,7 @@ void ticker_data::collect_garbage() | |||||
continue; | continue; | ||||
// If entity is to be destroyed, remove it. | // 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 | // Draw group specific logic | ||||
if (g >= (int)tickable::group::game::end) | if (g >= (int)tickable::group::game::end) | ||||
@@ -626,10 +627,10 @@ int Ticker::GetFrameNum() | |||||
void Ticker::Shutdown() | void Ticker::Shutdown() | ||||
{ | { | ||||
/* We're bailing out. Release all autorelease objects. */ | /* 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; | data->m_quit = 1; | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -39,7 +39,7 @@ public: | |||||
private: | private: | ||||
static std::string ReadScreen(std::string const &name); | 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) | DECLARE_IMAGE_CODEC(OricImageCodec, 100) | ||||
@@ -122,15 +122,16 @@ bool OricImageCodec::Save(std::string const &path, ResourceCodecData* data) | |||||
|| std::toupper(path[len - 1]) != 'P') | || std::toupper(path[len - 1]) != 'P') | ||||
return false; | 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 */ | /* Add filename, except the last 4 characters */ | ||||
for (char const *name = path.c_str(); name[4]; ++name) | 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; | auto img = data_image->m_image; | ||||
image tmp; | image tmp; | ||||
@@ -147,7 +148,7 @@ bool OricImageCodec::Save(std::string const &path, ResourceCodecData* data) | |||||
File f; | File f; | ||||
f.Open(path, FileAccess::Write); | f.Open(path, FileAccess::Write); | ||||
f.Write(result.data(), result.bytes()); | |||||
f.Write(result.data(), result.size()); | |||||
f.Close(); | f.Close(); | ||||
return true; | return true; | ||||
@@ -472,7 +473,7 @@ static uint8_t bestmove(ivec3 const *in, u8vec2 bgfg, | |||||
return bestcommand; | 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(); | ivec2 size = img.size(); | ||||
vec4 *pixels = img.lock<PixelFormat::RGBA_F32>(); | vec4 *pixels = img.lock<PixelFormat::RGBA_F32>(); | ||||
@@ -525,7 +526,7 @@ void OricImageCodec::WriteScreen(image &img, array<uint8_t> &result) | |||||
/* Iterate */ | /* Iterate */ | ||||
bgfg = domove(command, bgfg); | bgfg = domove(command, bgfg); | ||||
/* Write byte to file */ | /* Write byte to file */ | ||||
result << command; | |||||
result.push_back(command); | |||||
} | } | ||||
} | } | ||||
@@ -12,6 +12,8 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <vector> | |||||
/* | /* | ||||
* Generic convolution functions | * Generic convolution functions | ||||
*/ | */ | ||||
@@ -19,8 +21,8 @@ | |||||
namespace lol | 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); | static image NonSepConv(image &src, array2d<float> const &in_kernel); | ||||
image image::Convolution(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) | if (separable) | ||||
{ | { | ||||
/* Matrix rank is 1! Separate the filter. */ | /* 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])); | float norm = 1.0f / lol::sqrt(lol::fabs(in_kernel[bestx][besty])); | ||||
for (int dx = 0; dx < ksize.x; dx++) | 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++) | 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); | 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> | 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; | typedef typename PixelType<FORMAT>::type pixel_t; | ||||
ivec2 const size = src.size(); | ivec2 const size = src.size(); | ||||
ivec2 const ksize(hvec.count(), vvec.count()); | |||||
ivec2 const ksize(int(hvec.size()), int(vvec.size())); | |||||
image dst(size); | image dst(size); | ||||
array2d<pixel_t> const &srcp = src.lock2d<FORMAT>(); | array2d<pixel_t> const &srcp = src.lock2d<FORMAT>(); | ||||
@@ -252,8 +254,8 @@ static image SepConv(image &src, array<float> const &hvec, | |||||
return dst; | 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_x = src.GetWrapX() == WrapMode::Repeat; | ||||
bool const wrap_y = src.GetWrapY() == 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(); | ivec2 size = kernel.sizes(); | ||||
array<Dot> tmp; | |||||
std::vector<Dot> tmp; | |||||
tmp.resize(size.x * size.y); | tmp.resize(size.x * size.y); | ||||
for (int y = 0; y < size.y; 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].y = y; | ||||
tmp[y * size.x + x].val = kernel[x][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); | std::qsort(tmp.data(), size.x * size.y, sizeof(Dot), cmpdot); | ||||
array2d<float> dst(size); | array2d<float> dst(size); | ||||
@@ -12,6 +12,8 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <vector> // std::vector | |||||
/* | /* | ||||
* Image resizing functions | * Image resizing functions | ||||
*/ | */ | ||||
@@ -145,16 +147,16 @@ static image ResizeBresenham(image &src, ivec2 size) | |||||
vec4 const *srcp = src.lock<PixelFormat::RGBA_F32>(); | vec4 const *srcp = src.lock<PixelFormat::RGBA_F32>(); | ||||
vec4 *dstp = dst.lock<PixelFormat::RGBA_F32>(); | vec4 *dstp = dst.lock<PixelFormat::RGBA_F32>(); | ||||
array<vec4> aline, line; | |||||
std::vector<vec4> aline, line; | |||||
aline.resize(size.x); | aline.resize(size.x); | ||||
line.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; | int remy = 0; | ||||
for (int y = 0, y0 = 0; y < size.y; y++) | 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; ) | for (int toty = 0; toty < oldsize.y; ) | ||||
{ | { | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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> | // © 2016—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -13,6 +13,9 @@ | |||||
#pragma once | #pragma once | ||||
#include <lol/utils> | |||||
#include <vector> | |||||
// | // | ||||
// The ResourceCodecData class | // The ResourceCodecData class | ||||
// ------------------------ | // ------------------------ | ||||
@@ -29,7 +32,7 @@ namespace lol | |||||
virtual bool Save(std::string const &path, ResourceCodecData* data) = 0; | virtual bool Save(std::string const &path, ResourceCodecData* data) = 0; | ||||
/* TODO: this should become more fine-grained */ | /* TODO: this should become more fine-grained */ | ||||
int m_priority; | |||||
size_t m_priority; | |||||
}; | }; | ||||
#define REGISTER_IMAGE_CODEC(name) \ | #define REGISTER_IMAGE_CODEC(name) \ | ||||
@@ -37,13 +40,13 @@ namespace lol | |||||
{ \ | { \ | ||||
/* Insert image codecs in a sorted list */ \ | /* Insert image codecs in a sorted list */ \ | ||||
ResourceCodec *codec = Register##name(); \ | 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) \ | if (codeclist[i]->m_priority <= prio) \ | ||||
break; \ | break; \ | ||||
} \ | } \ | ||||
codeclist.insert(codec, i); \ | |||||
insert_at(codeclist, i, codec); \ | |||||
} | } | ||||
#define DECLARE_IMAGE_CODEC(name, priority) \ | #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 | * The bug was reported to Microsoft and fixed by them, but the fix | ||||
* is not yet available. | * is not yet available. | ||||
* https://connect.microsoft.com/VisualStudio/feedback/details/730878/ */ | * https://connect.microsoft.com/VisualStudio/feedback/details/730878/ */ | ||||
static bool RegisterAllCodecs(array<ResourceCodec *> &codeclist) | |||||
static bool RegisterAllCodecs(std::vector<ResourceCodec *> &codeclist) | |||||
{ | { | ||||
#if defined __ANDROID__ | #if defined __ANDROID__ | ||||
REGISTER_IMAGE_CODEC(AndroidImageCodec) | REGISTER_IMAGE_CODEC(AndroidImageCodec) | ||||
@@ -69,7 +69,7 @@ public: | |||||
} | } | ||||
private: | private: | ||||
array<ResourceCodec *> m_codecs; | |||||
std::vector<ResourceCodec *> m_codecs; | |||||
} | } | ||||
g_resource_loader; | g_resource_loader; | ||||
@@ -215,6 +215,7 @@ | |||||
<ClInclude Include="debug\record.h" /> | <ClInclude Include="debug\record.h" /> | ||||
<ClInclude Include="debug\stats.h" /> | <ClInclude Include="debug\stats.h" /> | ||||
<ClInclude Include="easymesh\csgbsp.h" /> | <ClInclude Include="easymesh\csgbsp.h" /> | ||||
<ClInclude Include="easymesh\easyarray.h" /> | |||||
<ClInclude Include="easymesh\easymesh.h" /> | <ClInclude Include="easymesh\easymesh.h" /> | ||||
<ClInclude Include="easymesh\easymeshbuild.h" /> | <ClInclude Include="easymesh\easymeshbuild.h" /> | ||||
<ClInclude Include="easymesh\easymeshlua.h" /> | <ClInclude Include="easymesh\easymeshlua.h" /> | ||||
@@ -236,7 +237,6 @@ | |||||
<ClInclude Include="lol\audio\audio.h" /> | <ClInclude Include="lol\audio\audio.h" /> | ||||
<ClInclude Include="lol\audio\sample.h" /> | <ClInclude Include="lol\audio\sample.h" /> | ||||
<ClInclude Include="lol\base\all.h" /> | <ClInclude Include="lol\base\all.h" /> | ||||
<ClInclude Include="lol\base\array.h" /> | |||||
<ClInclude Include="lol\base\enum.h" /> | <ClInclude Include="lol\base\enum.h" /> | ||||
<ClInclude Include="lol\base\log.h" /> | <ClInclude Include="lol\base\log.h" /> | ||||
<ClInclude Include="lol\debug\all.h" /> | <ClInclude Include="lol\debug\all.h" /> | ||||
@@ -296,7 +296,6 @@ | |||||
<ClInclude Include="ui\sdl-input.h"> | <ClInclude Include="ui\sdl-input.h"> | ||||
<ExcludedFromBuild Condition="'$(enable_sdl)'=='no'">true</ExcludedFromBuild> | <ExcludedFromBuild Condition="'$(enable_sdl)'=='no'">true</ExcludedFromBuild> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="utils.h" /> | |||||
<ClInclude Include="video.h" /> | <ClInclude Include="video.h" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -260,6 +260,9 @@ | |||||
<ClInclude Include="easymesh\easymesh.h"> | <ClInclude Include="easymesh\easymesh.h"> | ||||
<Filter>easymesh</Filter> | <Filter>easymesh</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="easymesh\easyarray.h"> | |||||
<Filter>easymesh</Filter> | |||||
</ClInclude> | |||||
<ClInclude Include="easymesh\easymeshbuild.h"> | <ClInclude Include="easymesh\easymeshbuild.h"> | ||||
<Filter>easymesh</Filter> | <Filter>easymesh</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
@@ -296,9 +299,6 @@ | |||||
<ClInclude Include="lolua\baselua.h"> | <ClInclude Include="lolua\baselua.h"> | ||||
<Filter>lolua</Filter> | <Filter>lolua</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="lol\base\array.h"> | |||||
<Filter>lol\base</Filter> | |||||
</ClInclude> | |||||
<ClInclude Include="lol\base\enum.h"> | <ClInclude Include="lol\base\enum.h"> | ||||
<Filter>lol\base</Filter> | <Filter>lol\base</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
@@ -423,7 +423,6 @@ | |||||
<ClInclude Include="ui\sdl-input.h"> | <ClInclude Include="ui\sdl-input.h"> | ||||
<Filter>ui</Filter> | <Filter>ui</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="utils.h" /> | |||||
<ClInclude Include="video.h" /> | <ClInclude Include="video.h" /> | ||||
<ClInclude Include="lol\base\all.h"> | <ClInclude Include="lol\base\all.h"> | ||||
<Filter>lol\base</Filter> | <Filter>lol\base</Filter> | ||||
@@ -17,7 +17,6 @@ | |||||
#include <../legacy/lol/base/types.h> | #include <../legacy/lol/base/types.h> | ||||
#include <lol/base/log.h> | #include <lol/base/log.h> | ||||
#include <../legacy/lol/base/assert.h> | #include <../legacy/lol/base/assert.h> | ||||
#include <lol/base/array.h> | |||||
#include <../legacy/lol/base/avl_tree.h> | #include <../legacy/lol/base/avl_tree.h> | ||||
#include <lol/base/enum.h> | #include <lol/base/enum.h> | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -17,7 +17,6 @@ | |||||
// -------------------------------------------------------- | // -------------------------------------------------------- | ||||
// | // | ||||
#include <lol/../utils.h> | |||||
#include <lol/../numeric.h> | #include <lol/../numeric.h> | ||||
// Static classes | // Static classes | ||||
@@ -122,20 +122,20 @@ Loader::~Loader() | |||||
//Store loader ------------------------------------------------------------ | //Store loader ------------------------------------------------------------ | ||||
// FIXME: change this to a map? | // 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) | 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) | 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) | 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; | return; | ||||
} | } | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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> | // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -19,7 +19,9 @@ extern "C" { | |||||
#include "3rdparty/lua/lauxlib.h" | #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 | // Base Lua class for Lua script loading | ||||
@@ -65,45 +67,45 @@ public: | |||||
} ClassVarStr; | } ClassVarStr; | ||||
Library(std::string const &class_name, | 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_class_name = class_name; | ||||
m_static_name = class_name + "_lib"; | m_static_name = class_name + "_lib"; | ||||
m_method_name = class_name + "_inst"; | m_method_name = class_name + "_inst"; | ||||
m_statics = statics; | 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; | 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) | for (ClassVar const& cv : variables) | ||||
{ | { | ||||
if (cv.name && cv.get && cv.set) | 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_class_name = ""; | ||||
std::string m_static_name = ""; | std::string m_static_name = ""; | ||||
std::string m_method_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: | public: | ||||
@@ -173,7 +175,7 @@ public: | |||||
lua_setfield(l, -1, "__index"); | lua_setfield(l, -1, "__index"); | ||||
//Create variables Get/Set | //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) | for (const Object::Library::ClassVarStr& var : variables) | ||||
{ | { | ||||
if (!var.m_get || !var.m_set) | if (!var.m_get || !var.m_set) | ||||
@@ -215,7 +217,7 @@ public: | |||||
template <typename TLuaClass> | template <typename TLuaClass> | ||||
static const ClassMethod* GetInstanceMethods() { return GetLibrary<TLuaClass>()->m_methods.data(); } | static const ClassMethod* GetInstanceMethods() { return GetLibrary<TLuaClass>()->m_methods.data(); } | ||||
template <typename TLuaClass> | 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: | protected: | ||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
@@ -387,6 +389,16 @@ protected: | |||||
template<typename T> int InnerPush(T value) { UNUSED(value); ASSERT(false, INNER_ERROR); return 0; } | template<typename T> int InnerPush(T value) { UNUSED(value); ASSERT(false, INNER_ERROR); return 0; } | ||||
#ifndef INNER_SAFE_ENUM | #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> SafeEnum<E> InnerDefaultSafeEnum() { return SafeEnum<E>(); } | ||||
template<typename E> bool InnerIsValidSafeEnum() { return InnerIsValid<std::string>(); } | 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())); } | 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 <lol/engine-internal.h> | ||||
#include <memory> | |||||
#include <memory> // std::shared_ptr | |||||
#include <tuple> // std::make_tuple | |||||
#include <cstring> | #include <cstring> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
@@ -33,7 +34,7 @@ Mesh::~Mesh() | |||||
void Mesh::Render(Scene& scene, mat4 const &matrix) | 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) | for (auto submesh : m_submeshes) | ||||
scene.AddPrimitiveRenderer(this, std::make_shared<PrimitiveMesh>(submesh, matrix)); | 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) | 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; | 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) | 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() | void SubMesh::Render() | ||||
@@ -111,7 +112,7 @@ void SubMesh::Render() | |||||
m_vdecl->Bind(); | 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]; | ShaderAttrib attribs[12]; | ||||
@@ -137,7 +138,7 @@ void SubMesh::Render() | |||||
UNUSED(vertex_count); | 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 | // TODO: might be good to cache this | ||||
ShaderUniform u_tex = m_shader->GetUniformLocation(std::get<0>(m_textures[i])); | ShaderUniform u_tex = m_shader->GetUniformLocation(std::get<0>(m_textures[i])); | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -105,11 +105,11 @@ protected: | |||||
MeshPrimitive m_mesh_prim; | MeshPrimitive m_mesh_prim; | ||||
std::shared_ptr<Shader> m_shader; | std::shared_ptr<Shader> m_shader; | ||||
std::shared_ptr<VertexDeclaration> m_vdecl; | 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; | 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 | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // 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) | if (g_messageservice) | ||||
{ | { | ||||
MessageService& g = *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 true; | ||||
} | } | ||||
return false; | return false; | ||||
@@ -79,7 +79,6 @@ bool MessageService::FetchFirst(MessageBucket id, std::string& message) | |||||
{ | { | ||||
if (g_messageservice) | if (g_messageservice) | ||||
{ | { | ||||
ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); | |||||
time_t timestamp; | time_t timestamp; | ||||
return g_messageservice->FetchFirst(id, message, 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) | if (g_messageservice) | ||||
{ | { | ||||
ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); | |||||
MessageService& g = *g_messageservice; | 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; | message = bucket[0].m_message; | ||||
timestamp = bucket[0].m_timestamp; | timestamp = bucket[0].m_timestamp; | ||||
bucket.remove(0); | |||||
remove_at(bucket, 0); | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
@@ -110,7 +108,6 @@ bool MessageService::FetchAll(MessageBucket id, std::string& message) | |||||
{ | { | ||||
if (g_messageservice) | if (g_messageservice) | ||||
{ | { | ||||
ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); | |||||
time_t timestamp; | time_t timestamp; | ||||
return g_messageservice->FetchAll(id, message, 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) | if (g_messageservice) | ||||
{ | { | ||||
ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); | |||||
MessageService& g = *g_messageservice; | MessageService& g = *g_messageservice; | ||||
array<MessageList>& bucket = g.m_bucket[id.ToScalar()]; | |||||
auto& bucket = g.m_bucket[id.ToScalar()]; | |||||
message = ""; | message = ""; | ||||
if (bucket.count()) | |||||
if (bucket.size()) | |||||
{ | { | ||||
first_timestamp = bucket[0].m_timestamp; | 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; | message += bucket[i].m_message; | ||||
bucket.clear(); | bucket.clear(); | ||||
return true; | return true; | ||||
@@ -138,5 +134,5 @@ bool MessageService::FetchAll(MessageBucket id, std::string& message, time_t& fi | |||||
return false; | return false; | ||||
} | } | ||||
} /* namespace lol */ | |||||
} // namespace lol | |||||
@@ -1,8 +1,8 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // 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); | static bool FetchAll(MessageBucket id, std::string& message, time_t &first_timestamp); | ||||
private: | private: | ||||
array<array<MessageList> > m_bucket; | |||||
std::vector<std::vector<MessageList> > m_bucket; | |||||
}; | }; | ||||
extern MessageService *g_messageservice; | 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 <cstdlib> | ||||
#include <stdint.h> | #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) | static inline float SmoothClamp(float &x, float a, float b, float sd) | ||||
{ | { | ||||
if (b < a) | if (b < a) | ||||
Swap(a, b); | |||||
std::swap(a, b); | |||||
float tx = x; | float tx = x; | ||||
float ta = a - sd; | float ta = a - sd; | ||||
@@ -15,7 +15,7 @@ | |||||
#endif | #endif | ||||
#include <lol/unit_test> | #include <lol/unit_test> | ||||
#include <lol/base/array.h> | |||||
#include <lol/../easymesh/easyarray.h> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -36,7 +36,7 @@ lolunit_declare_fixture(array_test) | |||||
{ | { | ||||
lolunit_declare_test(array_push) | lolunit_declare_test(array_push) | ||||
{ | { | ||||
array<int> a; | |||||
easy_array<int> a; | |||||
a.push(0); | a.push(0); | ||||
a.push(1); | a.push(1); | ||||
a.push(2); | a.push(2); | ||||
@@ -50,21 +50,21 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_declare_test(array_initializer) | 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[0], 2); | ||||
lolunit_assert_equal(a[1], 4); | lolunit_assert_equal(a[1], 4); | ||||
lolunit_assert_equal(a[2], 6); | 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[0], 2); | ||||
lolunit_assert_equal(b[1], 4); | lolunit_assert_equal(b[1], 4); | ||||
lolunit_assert_equal(b[2], 6); | 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<0>(c[0]), 2); | ||||
lolunit_assert_equal(std::get<1>(c[0]), 3.0f); | 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) | lolunit_declare_test(array_push_with_shift) | ||||
{ | { | ||||
array<int> a; | |||||
easy_array<int> a; | |||||
a << 0 << 1 << 2 << 3; | a << 0 << 1 << 2 << 3; | ||||
lolunit_assert_equal(a[0], 0); | lolunit_assert_equal(a[0], 0); | ||||
@@ -87,10 +87,10 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_declare_test(array_copy) | lolunit_declare_test(array_copy) | ||||
{ | { | ||||
array<int> a; | |||||
easy_array<int> a; | |||||
a << 0 << 1 << 2 << 3; | a << 0 << 1 << 2 << 3; | ||||
array<int> b = a; | |||||
easy_array<int> b = a; | |||||
lolunit_assert_equal(b[0], 0); | lolunit_assert_equal(b[0], 0); | ||||
lolunit_assert_equal(b[1], 1); | lolunit_assert_equal(b[1], 1); | ||||
@@ -100,7 +100,7 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_declare_test(array_remove) | lolunit_declare_test(array_remove) | ||||
{ | { | ||||
array<int> a; | |||||
easy_array<int> a; | |||||
a << 0 << 1 << 2 << 3; | a << 0 << 1 << 2 << 3; | ||||
a.remove(1); | a.remove(1); | ||||
@@ -109,7 +109,7 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_assert_equal(a[1], 2); | lolunit_assert_equal(a[1], 2); | ||||
lolunit_assert_equal(a[2], 3); | lolunit_assert_equal(a[2], 3); | ||||
array<int> b; | |||||
easy_array<int> b; | |||||
b << 0 << 1 << 2 << 3; | b << 0 << 1 << 2 << 3; | ||||
b.remove(-2); | b.remove(-2); | ||||
@@ -121,7 +121,7 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_declare_test(array_remove_swap) | lolunit_declare_test(array_remove_swap) | ||||
{ | { | ||||
array<int> a; | |||||
easy_array<int> a; | |||||
a << 0 << 1 << 2 << 3; | a << 0 << 1 << 2 << 3; | ||||
a.remove_swap(1); | a.remove_swap(1); | ||||
@@ -130,7 +130,7 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_assert_equal(a[1], 3); | lolunit_assert_equal(a[1], 3); | ||||
lolunit_assert_equal(a[2], 2); | lolunit_assert_equal(a[2], 2); | ||||
array<int> b; | |||||
easy_array<int> b; | |||||
b << 0 << 1 << 2 << 3; | b << 0 << 1 << 2 << 3; | ||||
b.remove(1, 2); | b.remove(1, 2); | ||||
@@ -141,7 +141,7 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_declare_test(eight_element_arrays) | 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); | a.push(1, 2, 3.f, 4.0, 5, 'a', true, 0); | ||||
lolunit_assert_equal(std::get<0>(a[0]), 1); | lolunit_assert_equal(std::get<0>(a[0]), 1); | ||||
@@ -156,7 +156,7 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_declare_test(array_swap) | lolunit_declare_test(array_swap) | ||||
{ | { | ||||
array<int, int> a; | |||||
easy_array<int, int> a; | |||||
a.push(10, 20); | a.push(10, 20); | ||||
a.push(30, 40); | a.push(30, 40); | ||||
@@ -170,7 +170,7 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_declare_test(array_insert) | lolunit_declare_test(array_insert) | ||||
{ | { | ||||
array<int> a; | |||||
easy_array<int> a; | |||||
a << 1 << 2; | a << 1 << 2; | ||||
a.insert(5, 0); | a.insert(5, 0); | ||||
@@ -194,7 +194,7 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_declare_test(array_insert_tuple) | 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"); | b.insert(0, 5, 6.f, "lol"); | ||||
lolunit_assert_equal(5, std::get<0>(b[0])); | lolunit_assert_equal(5, std::get<0>(b[0])); | ||||
lolunit_assert_equal(6.f, std::get<1>(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) | lolunit_declare_test(array_concat) | ||||
{ | { | ||||
array<int> a, b; | |||||
easy_array<int> a, b; | |||||
a << 0 << 1; | a << 0 << 1; | ||||
b << 2 << 3; | b << 2 << 3; | ||||
array<int> c = a + b; | |||||
easy_array<int> c = a + b; | |||||
lolunit_assert_equal(c[0], 0); | lolunit_assert_equal(c[0], 0); | ||||
lolunit_assert_equal(c[1], 1); | lolunit_assert_equal(c[1], 1); | ||||
lolunit_assert_equal(c[2], 2); | lolunit_assert_equal(c[2], 2); | ||||
@@ -229,7 +229,7 @@ lolunit_declare_fixture(array_test) | |||||
lolunit_declare_test(array_append) | lolunit_declare_test(array_append) | ||||
{ | { | ||||
array<int> a, b; | |||||
easy_array<int> a, b; | |||||
a << 0 << 1; | a << 0 << 1; | ||||
b << 2 << 3; | b << 2 << 3; | ||||
@@ -253,7 +253,7 @@ lolunit_declare_fixture(array_test) | |||||
tracked_object::m_ctor = 0; | tracked_object::m_ctor = 0; | ||||
tracked_object::m_dtor = 0; | tracked_object::m_dtor = 0; | ||||
{ | { | ||||
array<tracked_object> a; | |||||
easy_array<tracked_object> a; | |||||
a.push(tracked_object()); | a.push(tracked_object()); | ||||
} | } | ||||
@@ -262,7 +262,7 @@ lolunit_declare_fixture(array_test) | |||||
tracked_object::m_ctor = 0; | tracked_object::m_ctor = 0; | ||||
tracked_object::m_dtor = 0; | tracked_object::m_dtor = 0; | ||||
{ | { | ||||
array<tracked_object> a; | |||||
easy_array<tracked_object> a; | |||||
a.resize(2); | a.resize(2); | ||||
a.resize(4); | a.resize(4); | ||||
@@ -20,6 +20,8 @@ | |||||
#endif | #endif | ||||
#include <memory> | #include <memory> | ||||
#include <vector> // std::vector | |||||
#include <tuple> // std::tuple | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
@@ -39,7 +41,8 @@ class D3d9InputData | |||||
private: | private: | ||||
#if defined LOL_USE_XINPUT | #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 | #endif // LOL_USE_XINPUT | ||||
}; | }; | ||||
@@ -69,7 +72,7 @@ D3d9Input::D3d9Input() | |||||
#define _BTN(id, name) stick->internal_add_button(input::button::BTN_##name, #name); | #define _BTN(id, name) stick->internal_add_button(input::button::BTN_##name, #name); | ||||
#include "ui/buttons.inc" // FIXME: ignore mouse buttons here | #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 | #endif | ||||
@@ -80,8 +83,7 @@ D3d9Input::~D3d9Input() | |||||
{ | { | ||||
#if defined LOL_USE_XINPUT | #if defined LOL_USE_XINPUT | ||||
/* Unregister all the joysticks we added (FIXME: this code seems unnecessary) */ | /* 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 | #endif | ||||
delete m_data; | delete m_data; | ||||
} | } | ||||
@@ -91,13 +93,13 @@ void D3d9Input::tick_game(float seconds) | |||||
entity::tick_game(seconds); | entity::tick_game(seconds); | ||||
#if defined LOL_USE_XINPUT | #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; | 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; | continue; | ||||
auto stick = std::get<1>(m_data->m_joysticks[i]); | |||||
auto stick = std::get<1>(joy); | |||||
stick->internal_begin_frame(); | stick->internal_begin_frame(); | ||||
stick->internal_set_axis(input::axis::LeftX, state.Gamepad.sThumbLX / 32768.f); | stick->internal_set_axis(input::axis::LeftX, state.Gamepad.sThumbLX / 32768.f); | ||||
stick->internal_set_axis(input::axis::LeftY, -state.Gamepad.sThumbLY / 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; | 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 | #endif | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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> | // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // 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_ortho.m_uniform = m_shader->GetUniformLocation(m_ortho.m_var.tostring()); | ||||
m_texture.m_uniform = m_shader->GetUniformLocation(m_texture.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>( | m_vdecl = std::make_shared<VertexDeclaration>( | ||||
VertexStream<vec2, vec2, u8vec4>( | VertexStream<vec2, vec2, u8vec4>( | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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> | // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -87,7 +87,7 @@ protected: | |||||
std::shared_ptr<Shader> m_shader = nullptr; | std::shared_ptr<Shader> m_shader = nullptr; | ||||
Uniform m_ortho; | Uniform m_ortho; | ||||
Uniform m_texture; | Uniform m_texture; | ||||
array<ShaderAttrib> m_attribs; | |||||
std::vector<ShaderAttrib> m_attribs; | |||||
std::shared_ptr<VertexDeclaration> m_vdecl; | std::shared_ptr<VertexDeclaration> m_vdecl; | ||||
std::string m_clipboard; | 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) | for (int j = 0; j < SDL_JoystickNumButtons(sdlstick); ++j) | ||||
stick->internal_add_button((input::button)(j + 1), format("Button%d", j + 1).c_str()); | 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 | #endif | ||||
@@ -102,11 +102,9 @@ SdlInput::~SdlInput() | |||||
{ | { | ||||
#if LOL_USE_SDL && !__EMSCRIPTEN__ | #if LOL_USE_SDL && !__EMSCRIPTEN__ | ||||
/* Unregister all the joysticks we added */ | /* 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 | #endif | ||||
} | } | ||||
@@ -149,18 +147,18 @@ void SdlInput::tick(float seconds) | |||||
keyboard->internal_begin_frame(); | keyboard->internal_begin_frame(); | ||||
mouse->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. */ | /* Pump all joystick events because no event is coming to us. */ | ||||
# if SDL_FORCE_POLL_JOYSTICK && !__EMSCRIPTEN__ | # if SDL_FORCE_POLL_JOYSTICK && !__EMSCRIPTEN__ | ||||
SDL_JoystickUpdate(); | 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 | # endif | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -28,6 +28,8 @@ | |||||
#endif | #endif | ||||
#include <memory> | #include <memory> | ||||
#include <vector> | |||||
#include <tuple> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -49,7 +51,7 @@ private: | |||||
void tick(float seconds); | void tick(float seconds); | ||||
#if LOL_USE_SDL | #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 | #endif | ||||
vec2 m_app; | 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 */ | |||||