diff --git a/src/Factory.h b/src/Factory.h index adcfbbf..80649ee 100755 --- a/src/Factory.h +++ b/src/Factory.h @@ -10,12 +10,18 @@ template class Factory { public: - void Register(std::string name, std::function factoryFunction) + /*void Register(std::string name, std::function factoryFunction) { m_FactoryFunctions[name] = factoryFunction; + }*/ + + template + void Register(std::function factoryFunction) + { + m_FactoryFunctions[typeid(T2).name()] = factoryFunction; } - T Create(std::string name) + /*T Create(std::string name) { auto it = m_FactoryFunctions.find(name); if (it != m_FactoryFunctions.end()) @@ -26,6 +32,20 @@ public: { return nullptr; } + }*/ + + template + T Create() + { + auto it = m_FactoryFunctions.find(typeid(T2).name()); + if (it != m_FactoryFunctions.end()) + { + return it->second(); + } + else + { + return nullptr; + } } private: diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index f0c5999..85a2869 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -47,35 +47,35 @@ void GameWorld::Initialize() //{ // auto camera = CreateEntity(); - // auto transform = AddComponent(camera, "Transform"); + // auto transform = AddComponent(camera); // transform->Position.z = 20.f; // transform->Position.y = 20.f; // //transform->Orientation = glm::quat(glm::vec3(glm::pi() / 8.f, 0.f, 0.f)); - // auto cameraComp = AddComponent(camera, "Camera"); + // auto cameraComp = AddComponent(camera); // cameraComp->FarClip = 2000.f; - // auto freeSteering = AddComponent(camera, "FreeSteering"); + // auto freeSteering = AddComponent(camera); // CommitEntity(camera); //} { auto ground = CreateEntity(); - auto transform = AddComponent(ground, "Transform"); + auto transform = AddComponent(ground); transform->Position = glm::vec3(0, 0, 0); //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); - auto model = AddComponent(ground, "Model"); + auto model = AddComponent(ground); //model->ModelFile = "Models/TestScene/testScene.obj"; model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj"; - auto physics = AddComponent(ground, "Physics"); + auto physics = AddComponent(ground); physics->Mass = 10; physics->Static = true; auto groundshape = CreateEntity(ground); - auto transformshape = AddComponent(groundshape, "Transform"); - auto meshShape = AddComponent(groundshape, "MeshShape"); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj"; //meshShape->ResourceName = "Models/TestScene/testScene.obj"; @@ -88,23 +88,23 @@ void GameWorld::Initialize() /*{ auto jeep = CreateEntity(); - auto transform = AddComponent(jeep, "Transform"); + auto transform = AddComponent(jeep); transform->Position = glm::vec3(0, 5, 0); transform->Orientation = glm::angleAxis(glm::pi()/2, glm::vec3(0, 1, 0)); - auto physics = AddComponent(jeep, "Physics"); + auto physics = AddComponent(jeep); physics->Mass = 1800; physics->Static = false; - auto vehicle = AddComponent(jeep, "Vehicle"); - AddComponent(jeep, "Input"); + auto vehicle = AddComponent(jeep); + AddComponent(jeep); { auto shape = CreateEntity(jeep); - auto transform = AddComponent(shape, "Transform"); - auto meshShape = AddComponent(shape, "MeshShape"); + auto transform = AddComponent(shape); + auto meshShape = AddComponent(shape); meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj"; CommitEntity(shape); - // auto box = AddComponent(jeep, "Box"); + // auto box = AddComponent(jeep); // box->Width = 1.487f; // box->Height = 0.727f; // box->Depth = 2.594f; @@ -113,17 +113,17 @@ void GameWorld::Initialize() { auto chassis = CreateEntity(jeep); - auto transform = AddComponent(chassis, "Transform"); + auto transform = AddComponent(chassis); transform->Position = glm::vec3(0, 0, 0); // 0.6577f - auto model = AddComponent(chassis, "Model"); + auto model = AddComponent(chassis); model->ModelFile = "Models/Jeep/Chassi/chassi.obj"; } { auto lightentity = CreateEntity(jeep); - auto transform = AddComponent(lightentity, "Transform"); + auto transform = AddComponent(lightentity); transform->Position = glm::vec3(0, 15, 0); - auto light = AddComponent(lightentity, "PointLight"); + auto light = AddComponent(lightentity); light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f); light->Specular = glm::vec3(1.f); light->constantAttenuation = 0.3f; @@ -138,12 +138,12 @@ void GameWorld::Initialize() float suspensionStrength = 35.f; { auto wheel = CreateEntity(jeep); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 50; @@ -157,13 +157,13 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(-1.9f, 0.5546f - wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 50; @@ -177,11 +177,11 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(0.2726f, 0.2805f - wheelOffset, 1.9307f); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 50; @@ -195,12 +195,12 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(-0.2726f, 0.2805f - wheelOffset, 1.9307f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 50; @@ -218,25 +218,25 @@ void GameWorld::Initialize() { auto tank = CreateEntity(); - auto transform = AddComponent(tank, "Transform"); + auto transform = AddComponent(tank); transform->Position = glm::vec3(0, 5, 0); //transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0)); - auto physics = AddComponent(tank, "Physics"); + auto physics = AddComponent(tank); physics->Mass = 45000; physics->Static = false; - auto vehicle = AddComponent(tank, "Vehicle"); + auto vehicle = AddComponent(tank); vehicle->MaxTorque = 5200.f; - AddComponent(tank, "TankSteering"); - AddComponent(tank, "Input"); + AddComponent(tank); + AddComponent(tank); { auto shape = CreateEntity(tank); - auto transform = AddComponent(shape, "Transform"); - auto meshShape = AddComponent(shape, "MeshShape"); + auto transform = AddComponent(shape); + auto meshShape = AddComponent(shape); meshShape->ResourceName = "Models/Tank/Fix/ChassiCollision.obj"; CommitEntity(shape); - // auto box = AddComponent(jeep, "Box"); + // auto box = AddComponent(jeep); // box->Width = 1.487f; // box->Height = 0.727f; // box->Depth = 2.594f; @@ -245,48 +245,48 @@ void GameWorld::Initialize() { auto chassis = CreateEntity(tank); - auto transform = AddComponent(chassis, "Transform"); + auto transform = AddComponent(chassis); transform->Position = glm::vec3(0, 0, 0); - auto model = AddComponent(chassis, "Model"); + auto model = AddComponent(chassis); model->ModelFile = "Models/Tank/Fix/Chassi.obj"; } { auto tower = CreateEntity(tank); SetProperty(tower, "Name", "tower"); - auto transform = AddComponent(tower, "Transform"); + auto transform = AddComponent(tower); transform->Position = glm::vec3(0.f, 1.2f, 1.8f); - auto model = AddComponent(tower, "Model"); + auto model = AddComponent(tower); model->ModelFile = "Models/Tank/Fix/Top.obj"; - auto towerSteering = AddComponent(tower, "TowerSteering"); + auto towerSteering = AddComponent(tower); towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f); towerSteering->TurnSpeed = glm::pi()/4.f; { auto barrel = CreateEntity(tower); - auto transform = AddComponent(barrel, "Transform"); + auto transform = AddComponent(barrel); transform->Position = glm::vec3(-0.018f, -0.2, -1.3f); - auto model = AddComponent(barrel, "Model"); + auto model = AddComponent(barrel); model->ModelFile = "Models/Tank/Fix/Barrel.obj"; - auto barrelSteering = AddComponent(barrel, "BarrelSteering"); + auto barrelSteering = AddComponent(barrel); barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f); barrelSteering->TurnSpeed = glm::pi()/4.f; barrelSteering->ShotSpeed = 70.f; { auto shot = CreateEntity(barrel); - auto transform = AddComponent(shot, "Transform"); + auto transform = AddComponent(shot); transform->Position = glm::vec3(0.35f, 0.f, -2.f); transform->Orientation = glm::angleAxis(-glm::pi()/2.f, glm::vec3(1, 0, 0)); transform->Scale = glm::vec3(3.f); - AddComponent(shot, "Template"); - auto physics = AddComponent(shot, "Physics"); + AddComponent(shot); + auto physics = AddComponent(shot); physics->Mass = 10.f; physics->Static = false; - auto modelComponent = AddComponent(shot, "Model"); + auto modelComponent = AddComponent(shot); modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; { auto shape = CreateEntity(shot); - auto transform = AddComponent(shape, "Transform"); - auto boxShape = AddComponent(shape, "BoxShape"); + auto transform = AddComponent(shape); + auto boxShape = AddComponent(shape); boxShape->Width = 0.5f; boxShape->Height = 0.5f; boxShape->Depth = 0.5f; @@ -300,24 +300,24 @@ void GameWorld::Initialize() { auto camera = CreateEntity(tower); - auto transform = AddComponent(camera, "Transform"); + auto transform = AddComponent(camera); transform->Position.z = 30.f; transform->Position.y = 5.f; //transform->Orientation = glm::quat(glm::vec3(-glm::pi() / 8.f, 0.f, 0.f)); transform->Orientation = glm::angleAxis(glm::pi() / 100, glm::vec3(1, 0, 0)); - auto cameraComp = AddComponent(camera, "Camera"); + auto cameraComp = AddComponent(camera); cameraComp->FarClip = 2000.f; - AddComponent(camera, "Input"); - //auto freeSteering = AddComponent(camera, "FreeSteering"); + AddComponent(camera); + //auto freeSteering = AddComponent(camera); CommitEntity(camera); } } { auto lightentity = CreateEntity(tank); - auto transform = AddComponent(lightentity, "Transform"); + auto transform = AddComponent(lightentity); transform->Position = glm::vec3(0, 0, 0); - auto light = AddComponent(lightentity, "PointLight"); + auto light = AddComponent(lightentity); //light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f); //light->Specular = glm::vec3(1.f); /*light->ConstantAttenuation = 0.3f; @@ -336,12 +336,12 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 2000; @@ -354,9 +354,9 @@ void GameWorld::Initialize() Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape, "Transform"); + auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape, "BoxShape"); + auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; @@ -366,12 +366,12 @@ void GameWorld::Initialize() } { auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 2000; @@ -384,9 +384,9 @@ void GameWorld::Initialize() Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape, "Transform"); + auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape, "BoxShape"); + auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; @@ -397,12 +397,12 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -2.6f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 2000; @@ -415,9 +415,9 @@ void GameWorld::Initialize() Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape, "Transform"); + auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape, "BoxShape"); + auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; @@ -427,12 +427,12 @@ void GameWorld::Initialize() } { auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -0.83f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 2000; @@ -445,9 +445,9 @@ void GameWorld::Initialize() Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape, "Transform"); + auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape, "BoxShape"); + auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; @@ -460,11 +460,11 @@ void GameWorld::Initialize() //Back { auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 2000; @@ -477,9 +477,9 @@ void GameWorld::Initialize() Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape, "Transform"); + auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape, "BoxShape"); + auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; @@ -489,11 +489,11 @@ void GameWorld::Initialize() } { auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 2000; @@ -506,9 +506,9 @@ void GameWorld::Initialize() Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape, "Transform"); + auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape, "BoxShape"); + auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; @@ -517,11 +517,11 @@ void GameWorld::Initialize() CommitEntity(wheel); auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity, "Transform"); + auto transformComponent = AddComponent(entity); transformComponent->Position = glm::vec3(2,-1.7,2.0); transformComponent->Scale = glm::vec3(3,3,3); transformComponent->Orientation = glm::angleAxis(glm::pi()/2, glm::vec3(1,0,0)); - auto emitterComponent = AddComponent(entity, "ParticleEmitter"); + auto emitterComponent = AddComponent(entity); emitterComponent->SpawnCount = 2; emitterComponent->SpawnFrequency = 0.005; emitterComponent->SpreadAngle = glm::pi(); @@ -532,9 +532,9 @@ void GameWorld::Initialize() CommitEntity(entity); auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity, "Transform"); + auto TEMP = AddComponent(particleEntity); TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity, "Sprite"); + auto spriteComponent = AddComponent(particleEntity); spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; emitterComponent->ParticleTemplate = particleEntity; @@ -543,12 +543,12 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 1.f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 2000; @@ -561,9 +561,9 @@ void GameWorld::Initialize() Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape, "Transform"); + auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape, "BoxShape"); + auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; @@ -573,11 +573,11 @@ void GameWorld::Initialize() } { auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel, "Transform"); + auto transform = AddComponent(wheel); transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f); - auto model = AddComponent(wheel, "Model"); + auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel, "Wheel"); + auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 2000; @@ -590,9 +590,9 @@ void GameWorld::Initialize() Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape, "Transform"); + auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape, "BoxShape"); + auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; @@ -601,11 +601,11 @@ void GameWorld::Initialize() CommitEntity(wheel); auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity, "Transform"); + auto transformComponent = AddComponent(entity); transformComponent->Position = glm::vec3(-2,-1.7,2.0); transformComponent->Scale = glm::vec3(3,3,3); transformComponent->Orientation = glm::angleAxis(glm::pi()/2, glm::vec3(1,0,0)); - auto emitterComponent = AddComponent(entity, "ParticleEmitter"); + auto emitterComponent = AddComponent(entity); emitterComponent->SpawnCount = 2; emitterComponent->SpawnFrequency = 0.005; emitterComponent->SpreadAngle = glm::pi(); @@ -616,9 +616,9 @@ void GameWorld::Initialize() CommitEntity(entity); auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity, "Transform"); + auto TEMP = AddComponent(particleEntity); TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity, "Sprite"); + auto spriteComponent = AddComponent(particleEntity); spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; emitterComponent->ParticleTemplate = particleEntity; @@ -634,7 +634,7 @@ void GameWorld::Initialize() for(int i = 0; i < 10; i++) { auto entity = CreateEntity(); - auto transform = AddComponent(entity, "Transform"); + auto transform = AddComponent(entity); transform->Position = glm::vec3(30 + i*0.1f, 0 + i*0.1f, 10 + i*0.1f); transform->Scale = glm::vec3(0); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); @@ -642,13 +642,13 @@ void GameWorld::Initialize() std::stringstream ss; ss << "Models/Placeholders/ShatterTest/" << i+1 << ".obj"; - auto model = AddComponent(entity, "Model"); + auto model = AddComponent(entity); model->ModelFile = ss.str(); - auto physics = AddComponent(entity, "Physics"); + auto physics = AddComponent(entity); physics->Mass = 100; physics->Static = true; - auto meshShape = AddComponent(entity, "MeshShape"); + auto meshShape = AddComponent(entity); meshShape->ResourceName = ss.str(); CommitEntity(entity); @@ -661,22 +661,22 @@ void GameWorld::Initialize() for (int x = -5; x < 5; x++) { auto brick = CreateEntity(); - auto transform = AddComponent(brick, "Transform"); + auto transform = AddComponent(brick); transform->Position = glm::vec3(x + 0.01f, y * 0.3f + 0.01f, -20); transform->Position.x += (y % 2)*0.5f; transform->Scale = glm::vec3(1, 0.3f, 0.4f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); - auto model = AddComponent(brick, "Model"); + auto model = AddComponent(brick); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; - auto physics = AddComponent(brick, "Physics"); + auto physics = AddComponent(brick); physics->Mass = 3; auto shape = CreateEntity(brick); - auto transformshape = AddComponent(shape, "Transform"); - auto box = AddComponent(shape, "BoxShape"); + auto transformshape = AddComponent(shape); + auto box = AddComponent(shape); box->Width = 0.5f; box->Height = 0.15f; box->Depth = 0.3f; @@ -690,16 +690,16 @@ void GameWorld::Initialize() for (int y = 0; y < 5; y++) { auto cube = CreateEntity(); - auto transform = AddComponent(cube, "Transform"); + auto transform = AddComponent(cube); transform->Position = glm::vec3(3 * x + 0.1f + -20.f, 3 * y + 0.1f + 1.f, 0); transform->Scale = glm::vec3(3); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); - auto model = AddComponent(cube, "Model"); + auto model = AddComponent(cube); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; - auto physics = AddComponent(cube, "Physics"); + auto physics = AddComponent(cube); physics->Mass = 100; - auto box = AddComponent(cube, "BoxShape"); + auto box = AddComponent(cube); box->Width = 1.5f; box->Height = 1.5f; box->Depth = 1.5f; @@ -711,7 +711,7 @@ void GameWorld::Initialize() /*{ auto entity = CreateEntity(); AddComponent(entity, "Transform"); - auto emitter = AddComponent(entity, "SoundEmitter"); + auto emitter = AddComponent(entity); emitter->Path = "Sounds/korvring.wav"; emitter->Loop = true; GetSystem("SoundSystem")->PlaySound(emitter); @@ -727,40 +727,40 @@ void GameWorld::Update(double dt) void GameWorld::RegisterComponents() { - m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); }); - m_ComponentFactory.Register("Template", []() { return new Components::Template(); }); + m_ComponentFactory.Register([]() { return new Components::Transform(); }); + m_ComponentFactory.Register([]() { return new Components::Template(); }); } void GameWorld::RegisterSystems() { - m_SystemFactory.Register("TransformSystem", [this]() { return new Systems::TransformSystem(this, m_EventBroker); }); - //m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); }); - m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_EventBroker); }); - m_SystemFactory.Register("DebugSystem", [this]() { return new Systems::DebugSystem(this, m_EventBroker); }); - //m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); }); - m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this, m_EventBroker); }); - //m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); }); - m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this, m_EventBroker); }); - m_SystemFactory.Register("TankSteeringSystem", [this]() { return new Systems::TankSteeringSystem(this, m_EventBroker); }); - m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this, m_EventBroker); }); - m_SystemFactory.Register("PhysicsSystem", [this]() { return new Systems::PhysicsSystem(this, m_EventBroker); }); - m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_EventBroker, m_Renderer); }); + m_SystemFactory.Register([this]() { return new Systems::TransformSystem(this, m_EventBroker); }); + //m_SystemFactory.Register([this]() { return new Systems::LevelGenerationSystem(this); }); + m_SystemFactory.Register([this]() { return new Systems::InputSystem(this, m_EventBroker); }); + m_SystemFactory.Register([this]() { return new Systems::DebugSystem(this, m_EventBroker); }); + //m_SystemFactory.Register([this]() { return new Systems::CollisionSystem(this); }); + m_SystemFactory.Register([this]() { return new Systems::ParticleSystem(this, m_EventBroker); }); + //m_SystemFactory.Register([this]() { return new Systems::PlayerSystem(this); }); + m_SystemFactory.Register([this]() { return new Systems::FreeSteeringSystem(this, m_EventBroker); }); + m_SystemFactory.Register([this]() { return new Systems::TankSteeringSystem(this, m_EventBroker); }); + m_SystemFactory.Register([this]() { return new Systems::SoundSystem(this, m_EventBroker); }); + m_SystemFactory.Register([this]() { return new Systems::PhysicsSystem(this, m_EventBroker); }); + m_SystemFactory.Register([this]() { return new Systems::RenderSystem(this, m_EventBroker, m_Renderer); }); } void GameWorld::AddSystems() { - AddSystem("TransformSystem"); - //AddSystem("LevelGenerationSystem"); - AddSystem("InputSystem"); - AddSystem("DebugSystem"); - //AddSystem("CollisionSystem"); - AddSystem("ParticleSystem"); - //AddSystem("PlayerSystem"); - AddSystem("FreeSteeringSystem"); - AddSystem("TankSteeringSystem"); - AddSystem("SoundSystem"); - AddSystem("PhysicsSystem"); - AddSystem("RenderSystem"); + AddSystem(); + //AddSystem(); + AddSystem(); + AddSystem(); + //AddSystem(); + AddSystem(); + //AddSystem(); + AddSystem(); + AddSystem(); + AddSystem(); + AddSystem(); + AddSystem(); } void GameWorld::BindKey(int keyCode, std::string command, float value) diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index 90e65dc..7db47af 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -7,13 +7,13 @@ void VehicleSetup::buildVehicle(World *world, const hkpWorld* physicsWorld, hkpVehicleInstance& vehicle, EntityID vehicleEntity, std::vector wheelEntities) { - auto vehicleComponent = world->GetComponent(vehicleEntity, "Vehicle"); + auto vehicleComponent = world->GetComponent(vehicleEntity); WheelData wheelData; for (int i = 0; i < wheelEntities.size(); i++) { - wheelData.WheelComponent = world->GetComponent(wheelEntities[i], "Wheel"); - wheelData.TransformComponent = world->GetComponent(wheelEntities[i], "Transform"); + wheelData.WheelComponent = world->GetComponent(wheelEntities[i]); + wheelData.TransformComponent = world->GetComponent(wheelEntities[i]); m_Wheels.push_back(wheelData); } diff --git a/src/Systems/FreeSteeringSystem.cpp b/src/Systems/FreeSteeringSystem.cpp index edf24d0..8a5d638 100755 --- a/src/Systems/FreeSteeringSystem.cpp +++ b/src/Systems/FreeSteeringSystem.cpp @@ -4,7 +4,7 @@ void Systems::FreeSteeringSystem::RegisterComponents(ComponentFactory* cf) { - cf->Register("FreeSteering", []() { return new Components::FreeSteering(); }); + cf->Register([]() { return new Components::FreeSteering(); }); } void Systems::FreeSteeringSystem::Initialize() @@ -19,10 +19,10 @@ void Systems::FreeSteeringSystem::Update(double dt) void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { - auto steering = m_World->GetComponent(entity, "FreeSteering"); + auto steering = m_World->GetComponent(entity); if (steering) { - auto transform = m_World->GetComponent(entity, "Transform"); + auto transform = m_World->GetComponent(entity); glm::vec3 cameraRight = glm::vec3(transform->Orientation * glm::vec4(1, 0, 0, 0)); glm::vec3 cameraForward = glm::vec3(transform->Orientation * glm::vec4(0, 0, -1, 0)); diff --git a/src/Systems/InputSystem.cpp b/src/Systems/InputSystem.cpp index 4c5fa6f..dbb9ba6 100755 --- a/src/Systems/InputSystem.cpp +++ b/src/Systems/InputSystem.cpp @@ -4,7 +4,7 @@ void Systems::InputSystem::RegisterComponents(ComponentFactory* cf) { - cf->Register("Input", []() { return new Components::Input(); }); + cf->Register([]() { return new Components::Input(); }); } void Systems::InputSystem::Initialize() diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 0882f9d..5bcd97f 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -6,7 +6,7 @@ void Systems::ParticleSystem::Initialize() { - m_TransformSystem = m_World->GetSystem("TransformSystem"); + m_TransformSystem = m_World->GetSystem(); } void Systems::ParticleSystem::Update(double dt) @@ -16,15 +16,15 @@ void Systems::ParticleSystem::Update(double dt) void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { - auto transformComponent = m_World->GetComponent(entity, "Transform"); + auto transformComponent = m_World->GetComponent(entity); if(!transformComponent) return; - auto emitterComponent = m_World->GetComponent(entity, "ParticleEmitter"); + auto emitterComponent = m_World->GetComponent(entity); if(emitterComponent) { emitterComponent->TimeSinceLastSpawn += dt; - auto emitterTransformComponent = m_World->GetComponent(entity, "Transform"); + auto emitterTransformComponent = m_World->GetComponent(entity); if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency) { SpawnParticles(entity); @@ -35,8 +35,8 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();) { EntityID particleID = (it)->ParticleID; - auto transformComponent = m_World->GetComponent(particleID, "Transform"); - auto particleComponent = m_World->GetComponent(particleID, "Particle"); + auto transformComponent = m_World->GetComponent(particleID); + auto particleComponent = m_World->GetComponent(particleID); double timeLived = glfwGetTime() - it->SpawnTime; if(timeLived > particleComponent->LifeTime) @@ -94,15 +94,15 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID void Systems::ParticleSystem::RegisterComponents(ComponentFactory* cf) { - cf->Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); }); - cf->Register("Particle", []() { return new Components::Particle(); }); + cf->Register([]() { return new Components::ParticleEmitter(); }); + cf->Register([]() { return new Components::Particle(); }); } void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) { - auto emitterComponent = m_World->GetComponent(emitterID, "ParticleEmitter"); - auto emitterTransform = m_World->GetComponent(emitterID, "Transform"); + auto emitterComponent = m_World->GetComponent(emitterID); + auto emitterTransform = m_World->GetComponent(emitterID); glm::vec3 emitterPos = m_TransformSystem->AbsolutePosition(emitterID); glm::quat emitterOrientation = emitterTransform->Orientation; @@ -113,7 +113,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) { auto ent = m_World->CloneEntity(emitterComponent->ParticleTemplate); - auto particleTransform = m_World->GetComponent(ent, "Transform"); + auto particleTransform = m_World->GetComponent(ent); particleTransform->Position = emitterPos; particleTransform->Orientation = emitterOrientation; @@ -124,7 +124,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 1, 0))) * glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 0, 1))); - auto particle = m_World->AddComponent(ent, "Particle"); + auto particle = m_World->AddComponent(ent); particle->LifeTime = emitterComponent->LifeTime; particle->ScaleSpectrum = emitterComponent->ScaleSpectrum; particle->VelocitySpectrum.push_back(particleTransform->Velocity); diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 8efa4bb..1fd737b 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -108,14 +108,14 @@ void Systems::PhysicsSystem::Initialize() void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) { - cf->Register("Physics", []() { return new Components::Physics(); }); - cf->Register("BoxShape", []() { return new Components::BoxShape(); }); - cf->Register("SphereShape", []() { return new Components::SphereShape(); }); - cf->Register("Vehicle", []() { return new Components::Vehicle(); }); - cf->Register("Wheel", []() { return new Components::Wheel(); }); - cf->Register("MeshShape", []() { return new Components::MeshShape(); }); - cf->Register("HingeConstraint", []() { return new Components::HingeConstraint(); }); - cf->Register("WheelPair", []() { return new Components::WheelPair(); }); + cf->Register([]() { return new Components::Physics(); }); + cf->Register([]() { return new Components::BoxShape(); }); + cf->Register([]() { return new Components::SphereShape(); }); + cf->Register([]() { return new Components::Vehicle(); }); + cf->Register([]() { return new Components::Wheel(); }); + cf->Register([]() { return new Components::MeshShape(); }); + cf->Register([]() { return new Components::HingeConstraint(); }); + cf->Register([]() { return new Components::WheelPair(); }); } void Systems::PhysicsSystem::Update(double dt) @@ -128,7 +128,7 @@ void Systems::PhysicsSystem::Update(double dt) if (m_RigidBodies.find(entity) == m_RigidBodies.end()) continue; - auto transformComponent = m_World->GetComponent(entity, "Transform"); + auto transformComponent = m_World->GetComponent(entity); if (!transformComponent) continue; @@ -139,7 +139,7 @@ void Systems::PhysicsSystem::Update(double dt) if (parent) { - auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); + auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); position = ConvertPosition(absoluteTransform.Position); rotation = ConvertRotation(absoluteTransform.Orientation); } @@ -180,11 +180,11 @@ void Systems::PhysicsSystem::Update(double dt) void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { - auto transformComponent = m_World->GetComponent(entity, "Transform"); + auto transformComponent = m_World->GetComponent(entity); if (!transformComponent) return; - auto wheelComponent = m_World->GetComponent(entity, "Wheel"); + auto wheelComponent = m_World->GetComponent(entity); if (wheelComponent) { EntityID car = m_World->GetEntityParent(entity); @@ -208,7 +208,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p } else if(m_RigidBodies.find(entity) != m_RigidBodies.end()) { - auto transformComponentParent = m_World->GetComponent(parent, "Transform"); + auto transformComponentParent = m_World->GetComponent(parent); transformComponent->Position = ConvertPosition(m_RigidBodies[entity]->getPosition()); transformComponent->Orientation = ConvertRotation(m_RigidBodies[entity]->getRotation()); @@ -227,11 +227,11 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) { - auto transformComponent = m_World->GetComponent(entity, "Transform"); + auto transformComponent = m_World->GetComponent(entity); if (!transformComponent) return; - auto wheelComponent = m_World->GetComponent(entity, "Wheel"); + auto wheelComponent = m_World->GetComponent(entity); if (wheelComponent) { wheelComponent->ID = m_Wheels.size(); @@ -241,9 +241,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) EntityID entityParent = m_World->GetEntityBaseParent(entity); - auto sphereComponent = m_World->GetComponent(entity, "SphereShape"); - auto boxComponent = m_World->GetComponent(entity, "BoxShape"); - auto meshShapeComponent = m_World->GetComponent(entity, "MeshShape"); + auto sphereComponent = m_World->GetComponent(entity); + auto boxComponent = m_World->GetComponent(entity); + auto meshShapeComponent = m_World->GetComponent(entity); if(entityParent == entity && (sphereComponent || boxComponent || meshShapeComponent)) { @@ -251,7 +251,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) return; } - auto physicsComponent = m_World->GetComponent(entity, "Physics"); + auto physicsComponent = m_World->GetComponent(entity); if (physicsComponent) { hkpShape* shape; @@ -292,7 +292,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) { rigidBodyInfo.m_shape = shape; rigidBodyInfo.m_motionType = hkpMotion::MOTION_DYNAMIC; - auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); + auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); hkVector4 position = ConvertPosition(absoluteTransform.Position); hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation); rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3)); @@ -305,7 +305,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); - auto vehicleComponent = m_World->GetComponent(entity, "Vehicle"); + auto vehicleComponent = m_World->GetComponent(entity); if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end()) { for (int i = 0; i < m_Wheels.size(); i++) @@ -357,7 +357,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) for (auto &shapeData : m_Shapes[entity]) { - auto childTransformComponent = m_World->GetComponent(shapeData.Entity, "Transform"); + auto childTransformComponent = m_World->GetComponent(shapeData.Entity); hkVector4 position = ConvertPosition(childTransformComponent->Position); hkQuaternion rotation = ConvertRotation(childTransformComponent->Orientation); @@ -378,7 +378,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) { rigidBodyInfo.m_shape = shape; rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; - auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); + auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); hkVector4 position = ConvertPosition(absoluteTransform.Position); hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation); rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3)); @@ -567,7 +567,7 @@ const hkVector4& Systems::PhysicsSystem::ConvertScale(glm::vec3 glmScale) bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) { - auto vehicleComponent = m_World->GetComponent(event.Entity, "Vehicle"); + auto vehicleComponent = m_World->GetComponent(event.Entity); if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end()) { m_PhysicsWorld->markForWrite(); diff --git a/src/Systems/RenderSystem.cpp b/src/Systems/RenderSystem.cpp index 4f0e727..1166531 100755 --- a/src/Systems/RenderSystem.cpp +++ b/src/Systems/RenderSystem.cpp @@ -12,12 +12,12 @@ void Systems::RenderSystem::OnComponentCreated(std::string type, std::shared_ptr void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { - auto transformComponent = m_World->GetComponent(entity, "Transform"); + auto transformComponent = m_World->GetComponent(entity); if (transformComponent == nullptr) return; // Draw models - auto modelComponent = m_World->GetComponent(entity, "Model"); + auto modelComponent = m_World->GetComponent(entity); if (modelComponent != nullptr) { auto model = m_World->GetResourceManager()->Load("Model", modelComponent->ModelFile); @@ -31,7 +31,7 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa } } - auto pointLightComponent = m_World->GetComponent(entity, "PointLight"); + auto pointLightComponent = m_World->GetComponent(entity); if (pointLightComponent != nullptr) { glm::vec3 position = m_TransformSystem->AbsolutePosition(entity); @@ -46,7 +46,7 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa ); } - auto cameraComponent = m_World->GetComponent(entity, "Camera"); + auto cameraComponent = m_World->GetComponent(entity); if (cameraComponent != nullptr) { m_Renderer->GetCamera()->Position(m_TransformSystem->AbsolutePosition(entity)); @@ -57,13 +57,13 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip); } - auto spriteComponent = m_World->GetComponent(entity, "Sprite"); + auto spriteComponent = m_World->GetComponent(entity); if(spriteComponent != nullptr) { //TEMP Texture* texture = m_World->GetResourceManager()->Load("Texture", spriteComponent->SpriteFile); //glBindTexture(GL_TEXTURE_2D, texture); - auto transform = m_World->GetComponent(spriteComponent->Entity, "Transform"); + auto transform = m_World->GetComponent(spriteComponent->Entity); glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1)); m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale); } @@ -71,18 +71,18 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa void Systems::RenderSystem::Initialize() { - m_TransformSystem = m_World->GetSystem("TransformSystem"); + m_TransformSystem = m_World->GetSystem(); m_Renderer->SetSphereModel(m_World->GetResourceManager()->Load("Model", "Models/Placeholders/PhysicsTest/Sphere.obj")); } void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf) { - cf->Register("Camera", []() { return new Components::Camera(); }); - cf->Register("Model", []() { return new Components::Model(); }); - cf->Register("Sprite", []() { return new Components::Sprite(); }); - cf->Register("PointLight", []() { return new Components::PointLight(); }); - cf->Register("DirectionalLight", []() { return new Components::DirectionalLight(); }); + cf->Register([]() { return new Components::Camera(); }); + cf->Register([]() { return new Components::Model(); }); + cf->Register([]() { return new Components::Sprite(); }); + cf->Register([]() { return new Components::PointLight(); }); + cf->Register([]() { return new Components::DirectionalLight(); }); } void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm) diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index 02a665e..b36bf47 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -29,7 +29,7 @@ void Systems::SoundSystem::Initialize() void Systems::SoundSystem::RegisterComponents(ComponentFactory* cf) { - cf->Register("SoundEmitter", []() { return new Components::SoundEmitter(); }); + cf->Register([]() { return new Components::SoundEmitter(); }); } void Systems::SoundSystem::RegisterResourceTypes(ResourceManager* rm) @@ -44,7 +44,7 @@ void Systems::SoundSystem::Update(double dt) void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { - auto transformComponent = m_World->GetComponent(entity, "Transform"); + auto transformComponent = m_World->GetComponent(entity); if (transformComponent == nullptr) return; @@ -68,7 +68,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par alListenerfv(AL_ORIENTATION, listenerOri); } - auto soundEmitter = m_World->GetComponent(entity, "SoundEmitter"); + auto soundEmitter = m_World->GetComponent(entity); if(soundEmitter != nullptr) { ALuint source = m_Sources[soundEmitter]; diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 6ecbfb9..dca3441 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -4,9 +4,9 @@ void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf ) { - cf->Register("TankSteering", []() { return new Components::TankSteering(); }); - cf->Register("TowerSteering", []() { return new Components::TowerSteering(); }); - cf->Register("BarrelSteering", []() { return new Components::BarrelSteering(); }); + cf->Register([]() { return new Components::TankSteering(); }); + cf->Register([]() { return new Components::TowerSteering(); }); + cf->Register([]() { return new Components::BarrelSteering(); }); } void Systems::TankSteeringSystem::Initialize() @@ -23,7 +23,7 @@ void Systems::TankSteeringSystem::Update(double dt) void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { - auto tankSteeringComponent = m_World->GetComponent(entity, "TankSteering"); + auto tankSteeringComponent = m_World->GetComponent(entity); if(tankSteeringComponent) { Events::TankSteer e; @@ -34,27 +34,27 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit EventBroker->Publish(e); } - auto towerSteeringComponent = m_World->GetComponent(entity, "TowerSteering"); + auto towerSteeringComponent = m_World->GetComponent(entity); if(towerSteeringComponent) { - auto transformComponent = m_World->GetComponent(entity, "Transform"); + auto transformComponent = m_World->GetComponent(entity); glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis); transformComponent->Orientation *= orientation; } - auto barrelSteeringComponent = m_World->GetComponent(entity, "BarrelSteering"); + auto barrelSteeringComponent = m_World->GetComponent(entity); if(barrelSteeringComponent) { - auto transformComponent = m_World->GetComponent(entity, "Transform"); - auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); + auto transformComponent = m_World->GetComponent(entity); + auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis); transformComponent->Orientation *= orientation; if(m_TowerInputController->Shoot && m_TimeSinceLastShot[entity] > 1.0) { EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate); - auto templateAbsoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(barrelSteeringComponent->ShotTemplate); - auto cloneTransform = m_World->GetComponent(clone, "Transform"); + auto templateAbsoluteTransform = m_World->GetSystem()->AbsoluteTransform(barrelSteeringComponent->ShotTemplate); + auto cloneTransform = m_World->GetComponent(clone); cloneTransform->Position = templateAbsoluteTransform.Position; cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation; Events::SetVelocity e; diff --git a/src/Systems/TransformSystem.cpp b/src/Systems/TransformSystem.cpp index 3eccc26..69ec6fb 100755 --- a/src/Systems/TransformSystem.cpp +++ b/src/Systems/TransformSystem.cpp @@ -7,8 +7,8 @@ // if (parent == 0) // return; // -// auto transform = m_World->GetComponent(entity, "Transform"); -// auto parentTransform = m_World->GetComponent(parent, "Transform"); +// auto transform = m_World->GetComponent(entity); +// auto parentTransform = m_World->GetComponent(parent); // // transform->Position = parentTransform->Position + transform->RelativePosition; //} @@ -20,10 +20,10 @@ glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity) do { - auto transform = m_World->GetComponent(entity, "Transform"); + auto transform = m_World->GetComponent(entity); //absPosition += transform->Position; entity = m_World->GetEntityParent(entity); - auto transform2 = m_World->GetComponent(entity, "Transform"); + auto transform2 = m_World->GetComponent(entity); if (entity == 0) absPosition += transform->Position; else @@ -39,7 +39,7 @@ glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity) do { - auto transform = m_World->GetComponent(entity, "Transform"); + auto transform = m_World->GetComponent(entity); absOrientation = transform->Orientation * absOrientation; entity = m_World->GetEntityParent(entity); } while (entity != 0); @@ -53,7 +53,7 @@ glm::vec3 Systems::TransformSystem::AbsoluteScale(EntityID entity) do { - auto transform = m_World->GetComponent(entity, "Transform"); + auto transform = m_World->GetComponent(entity); absScale *= transform->Scale; entity = m_World->GetEntityParent(entity); } while (entity != 0); @@ -69,9 +69,9 @@ Components::Transform Systems::TransformSystem::AbsoluteTransform(EntityID entit do { - auto transform = m_World->GetComponent(entity, "Transform"); + auto transform = m_World->GetComponent(entity); entity = m_World->GetEntityParent(entity); - auto transform2 = m_World->GetComponent(entity, "Transform"); + auto transform2 = m_World->GetComponent(entity); // Position if (entity == 0) diff --git a/src/World.cpp b/src/World.cpp index c84a2bd..2a25856 100755 --- a/src/World.cpp +++ b/src/World.cpp @@ -132,11 +132,6 @@ void World::Initialize() } } -std::shared_ptr World::AddComponent(EntityID entity, std::string componentType) -{ - return AddComponent(entity, componentType); -} - void World::CommitEntity(EntityID entity) { for (auto pair : m_Systems) @@ -158,11 +153,6 @@ void World::AddComponent(EntityID entity, std::string componentType, std::shared } } -void World::AddSystem(std::string systemType) -{ - m_Systems[systemType] = std::shared_ptr(m_SystemFactory.Create(systemType)); -} - EntityID World::CloneEntity(EntityID entity, EntityID parent /* = 0 */) { int clone = CreateEntity(parent); @@ -170,7 +160,7 @@ EntityID World::CloneEntity(EntityID entity, EntityID parent /* = 0 */) for (auto pair : m_EntityComponents[entity]) { auto type = pair.first; - if (type == "Template") + if (type == typeid(Components::Template).name()) continue; auto component = std::shared_ptr(pair.second->Clone()); if (component != nullptr) diff --git a/src/World.h b/src/World.h index 0c4d76e..87bfecf 100755 --- a/src/World.h +++ b/src/World.h @@ -13,6 +13,7 @@ #include "Factory.h" #include "Entity.h" #include "Component.h" +#include "Components/Template.h" #include "System.h" #include "EventBroker.h" #include "ResourceManager.h" @@ -31,10 +32,14 @@ public: virtual void AddSystems() = 0; virtual void RegisterComponents() = 0; + template + void AddSystem() + { + m_Systems[typeid(T).name()] = std::shared_ptr(m_SystemFactory.Create()); + } - void AddSystem(std::string systemType); - template - std::shared_ptr GetSystem(std::string systemType); + template + std::shared_ptr GetSystem(); EntityID CreateEntity(EntityID parent = 0); EntityID CloneEntity(EntityID entity, EntityID parent = 0); @@ -69,10 +74,9 @@ public: } template - std::shared_ptr AddComponent(EntityID entity, std::string componentType); - std::shared_ptr AddComponent(EntityID entity, std::string componentType); + std::shared_ptr AddComponent(EntityID entity); template - T* GetComponent(EntityID entity, std::string componentType); + T* GetComponent(EntityID entity); // Triggers commit events in systems void CommitEntity(EntityID entity); @@ -117,11 +121,13 @@ protected: }; template -std::shared_ptr World::GetSystem(std::string systemType) +std::shared_ptr World::GetSystem() { + const char* systemType = typeid(T).name(); + if (m_Systems.find(systemType) == m_Systems.end()) { - LOG_WARNING("Tried to get pointer to unregistered system \"%s\"!", systemType.c_str()); + LOG_WARNING("Tried to get pointer to unregistered system \"%s\"!", systemType); return nullptr; } @@ -129,12 +135,14 @@ std::shared_ptr World::GetSystem(std::string systemType) } template -std::shared_ptr World::AddComponent(EntityID entity, std::string componentType) +std::shared_ptr World::AddComponent(EntityID entity) { - std::shared_ptr component = std::shared_ptr(static_cast(m_ComponentFactory.Create(componentType))); + const char* componentType = typeid(T).name(); + + std::shared_ptr component = std::shared_ptr(static_cast(m_ComponentFactory.Create())); if (component == nullptr) { - LOG_ERROR("Failed to attach invalid component \"%s\" to entity #%i", componentType.c_str(), entity); + LOG_ERROR("Failed to attach invalid component \"%s\" to entity #%i", componentType, entity); return nullptr; } @@ -145,17 +153,11 @@ std::shared_ptr World::AddComponent(EntityID entity, std::string componentTyp template -T* World::GetComponent(EntityID entity, std::string componentType) +T* World::GetComponent(EntityID entity) { - - /*auto it0 = m_EntityComponents.find(entity); - - if (it0 == m_EntityComponents.end()) - return nullptr;*/ - auto components = m_EntityComponents[entity]; - auto it = components.find(componentType); + auto it = components.find(typeid(T).name()); if (it != components.end()) { return static_cast(it->second.get());