Merged master into LevelSystemAndSuch. Now let's see if it works.
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
# Blender MTL File: 'Brick.blend'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Brick
|
||||||
|
Ns 17.647059
|
||||||
|
Ka 0.000000 0.000000 0.000000
|
||||||
|
Kd 0.640000 0.154050 0.039202
|
||||||
|
Ks 0.000000 0.000000 0.000000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 1
|
||||||
|
map_Kd Brick_d.jpg
|
||||||
|
map_Bump Brick_n.jpg
|
||||||
|
map_Ks Brick_s.jpg
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1010 KiB |
@@ -0,0 +1,14 @@
|
|||||||
|
# Blender MTL File: 'None'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Material.001
|
||||||
|
Ns 96.078431
|
||||||
|
Ka 0.000000 0.000000 0.000000
|
||||||
|
Kd 0.640000 0.640000 0.640000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
||||||
|
map_Kd Test/Brick_Diffuse.png
|
||||||
|
map_Bump Test/Brick_Normal.png
|
||||||
|
map_Ks Test/Brick_Specular.png
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
# Blender v2.75 (sub 0) OBJ File: ''
|
||||||
|
# www.blender.org
|
||||||
|
mtllib Halfpipe.mtl
|
||||||
|
o Cylinder
|
||||||
|
v 0.000000 -2.908792 -1.000000
|
||||||
|
v 0.000000 2.908792 -1.000000
|
||||||
|
v 0.195090 -2.908792 -0.980785
|
||||||
|
v 0.195090 2.908792 -0.980785
|
||||||
|
v 0.382683 -2.908792 -0.923880
|
||||||
|
v 0.382683 2.908792 -0.923880
|
||||||
|
v 0.555570 -2.908792 -0.831470
|
||||||
|
v 0.555570 2.908792 -0.831470
|
||||||
|
v 0.707107 -2.908792 -0.707107
|
||||||
|
v 0.707107 2.908792 -0.707107
|
||||||
|
v 0.831470 -2.908792 -0.555570
|
||||||
|
v 0.831470 2.908792 -0.555570
|
||||||
|
v 0.923880 -2.908792 -0.382683
|
||||||
|
v 0.923880 2.908792 -0.382683
|
||||||
|
v 0.980785 -2.908792 -0.195090
|
||||||
|
v 0.980785 2.908792 -0.195090
|
||||||
|
v 1.000000 -2.908792 -0.000000
|
||||||
|
v 1.000000 2.908792 -0.000000
|
||||||
|
v -1.000000 -2.908792 -0.000001
|
||||||
|
v -1.000000 2.908792 -0.000001
|
||||||
|
v -0.980785 -2.908792 -0.195091
|
||||||
|
v -0.980785 2.908792 -0.195091
|
||||||
|
v -0.923879 -2.908792 -0.382684
|
||||||
|
v -0.923879 2.908792 -0.382684
|
||||||
|
v -0.831469 -2.908792 -0.555571
|
||||||
|
v -0.831469 2.908792 -0.555571
|
||||||
|
v -0.707106 -2.908792 -0.707108
|
||||||
|
v -0.707106 2.908792 -0.707108
|
||||||
|
v -0.555569 -2.908792 -0.831470
|
||||||
|
v -0.555569 2.908792 -0.831470
|
||||||
|
v -0.382682 -2.908792 -0.923880
|
||||||
|
v -0.382682 2.908792 -0.923880
|
||||||
|
v -0.195089 -2.908792 -0.980786
|
||||||
|
v -0.195089 2.908792 -0.980786
|
||||||
|
vt -1.156714 -1.419990
|
||||||
|
vt -1.158346 2.336063
|
||||||
|
vt -1.031779 2.336118
|
||||||
|
vt -1.283288 -1.420045
|
||||||
|
vt -1.284913 2.336008
|
||||||
|
vt -1.409862 -1.420100
|
||||||
|
vt -1.411480 2.335954
|
||||||
|
vt -1.536436 -1.420155
|
||||||
|
vt -1.538048 2.335899
|
||||||
|
vt 2.387354 -1.418355
|
||||||
|
vt 2.385534 2.337692
|
||||||
|
vt 2.512101 2.337753
|
||||||
|
vt 2.260782 -1.418416
|
||||||
|
vt 2.258967 2.337631
|
||||||
|
vt 2.134208 -1.418478
|
||||||
|
vt 2.132400 2.337570
|
||||||
|
vt 2.007634 -1.418538
|
||||||
|
vt 2.005832 2.337510
|
||||||
|
vt -0.144122 -1.419541
|
||||||
|
vt -0.145809 2.336510
|
||||||
|
vt -0.019241 2.336567
|
||||||
|
vt -0.270696 -1.419598
|
||||||
|
vt -0.272376 2.336454
|
||||||
|
vt -0.397270 -1.419654
|
||||||
|
vt -0.398943 2.336397
|
||||||
|
vt -0.523844 -1.419711
|
||||||
|
vt -0.525511 2.336341
|
||||||
|
vt -0.650418 -1.419767
|
||||||
|
vt -0.652078 2.336285
|
||||||
|
vt -0.776992 -1.419823
|
||||||
|
vt -0.778645 2.336229
|
||||||
|
vt -1.030140 -1.419935
|
||||||
|
vt -0.905212 2.336174
|
||||||
|
vt -0.903566 -1.419879
|
||||||
|
vt 2.513929 -1.418293
|
||||||
|
vt -0.017548 -1.419484
|
||||||
|
vn -0.098000 0.000000 0.995200
|
||||||
|
vn -0.290300 0.000000 0.956900
|
||||||
|
vn -0.471400 0.000000 0.881900
|
||||||
|
vn -0.634400 0.000000 0.773000
|
||||||
|
vn -0.773000 0.000000 0.634400
|
||||||
|
vn -0.881900 0.000000 0.471400
|
||||||
|
vn -0.956900 0.000000 0.290300
|
||||||
|
vn -0.995200 0.000000 0.098000
|
||||||
|
vn 0.995200 0.000000 0.098000
|
||||||
|
vn 0.956900 0.000000 0.290300
|
||||||
|
vn 0.881900 0.000000 0.471400
|
||||||
|
vn 0.773000 0.000000 0.634400
|
||||||
|
vn 0.634400 0.000000 0.773000
|
||||||
|
vn 0.471400 0.000000 0.881900
|
||||||
|
vn 0.098000 0.000000 0.995200
|
||||||
|
vn 0.290300 0.000000 0.956900
|
||||||
|
usemtl Material.001
|
||||||
|
s off
|
||||||
|
f 3/1/1 4/2/1 2/3/1
|
||||||
|
f 5/4/2 6/5/2 4/2/2
|
||||||
|
f 7/6/3 8/7/3 6/5/3
|
||||||
|
f 9/8/4 10/9/4 8/7/4
|
||||||
|
f 11/10/5 12/11/5 10/12/5
|
||||||
|
f 13/13/6 14/14/6 12/11/6
|
||||||
|
f 15/15/7 16/16/7 14/14/7
|
||||||
|
f 17/17/8 18/18/8 16/16/8
|
||||||
|
f 21/19/9 22/20/9 20/21/9
|
||||||
|
f 23/22/10 24/23/10 22/20/10
|
||||||
|
f 25/24/11 26/25/11 24/23/11
|
||||||
|
f 27/26/12 28/27/12 26/25/12
|
||||||
|
f 29/28/13 30/29/13 28/27/13
|
||||||
|
f 31/30/14 32/31/14 30/29/14
|
||||||
|
f 1/32/15 2/3/15 34/33/15
|
||||||
|
f 33/34/16 34/33/16 32/31/16
|
||||||
|
f 1/32/1 3/1/1 2/3/1
|
||||||
|
f 3/1/2 5/4/2 4/2/2
|
||||||
|
f 5/4/3 7/6/3 6/5/3
|
||||||
|
f 7/6/4 9/8/4 8/7/4
|
||||||
|
f 9/35/5 11/10/5 10/12/5
|
||||||
|
f 11/10/6 13/13/6 12/11/6
|
||||||
|
f 13/13/7 15/15/7 14/14/7
|
||||||
|
f 15/15/8 17/17/8 16/16/8
|
||||||
|
f 19/36/9 21/19/9 20/21/9
|
||||||
|
f 21/19/10 23/22/10 22/20/10
|
||||||
|
f 23/22/11 25/24/11 24/23/11
|
||||||
|
f 25/24/12 27/26/12 26/25/12
|
||||||
|
f 27/26/13 29/28/13 28/27/13
|
||||||
|
f 29/28/14 31/30/14 30/29/14
|
||||||
|
f 33/34/15 1/32/15 34/33/15
|
||||||
|
f 31/30/16 33/34/16 32/31/16
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 3.2 MiB |
+12
-21
@@ -44,6 +44,7 @@
|
|||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
#include "Game/CPad.h"
|
#include "Game/CPad.h"
|
||||||
#include "Game/CBrick.h"
|
#include "Game/CBrick.h"
|
||||||
|
#include "Game/BallSystem.h"
|
||||||
#include "Game/Bricks/CPowerUpBrick.h"
|
#include "Game/Bricks/CPowerUpBrick.h"
|
||||||
|
|
||||||
#include "Physics/PhysicsSystem.h"
|
#include "Physics/PhysicsSystem.h"
|
||||||
@@ -51,6 +52,7 @@
|
|||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CBoxShape.h"
|
||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -104,6 +106,8 @@ public:
|
|||||||
m_World->AddSystem<Systems::LevelSystem>();
|
m_World->AddSystem<Systems::LevelSystem>();
|
||||||
m_World->SystemFactory.Register<Systems::PadSystem>([this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
|
m_World->SystemFactory.Register<Systems::PadSystem>([this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::PadSystem>();
|
m_World->AddSystem<Systems::PadSystem>();
|
||||||
|
m_World->SystemFactory.Register<Systems::BallSystem>([this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
|
||||||
|
m_World->AddSystem<Systems::BallSystem>();
|
||||||
|
|
||||||
m_World->ComponentFactory.Register<Components::Model>();
|
m_World->ComponentFactory.Register<Components::Model>();
|
||||||
m_World->ComponentFactory.Register<Components::Template>();
|
m_World->ComponentFactory.Register<Components::Template>();
|
||||||
@@ -119,15 +123,16 @@ public:
|
|||||||
{
|
{
|
||||||
auto ent = m_World->CreateEntity();
|
auto ent = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
transform->Position = glm::vec3(0.5f, 0.f, -9.9f);
|
transform->Position = glm::vec3(-0.f, 0.f, -10.f);
|
||||||
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
|
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||||
|
transform->Velocity = glm::vec3(0.0f, -10.f, 0.f);
|
||||||
|
|
||||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||||
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||||
|
|
||||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||||
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
||||||
|
ball->Speed = 10.f;
|
||||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
physics->Static = false;
|
physics->Static = false;
|
||||||
|
|
||||||
@@ -136,11 +141,7 @@ public:
|
|||||||
|
|
||||||
m_World->CommitEntity(ent);
|
m_World->CommitEntity(ent);
|
||||||
|
|
||||||
Events::SetImpulse e;
|
|
||||||
e.Entity = ent;
|
|
||||||
e.Impulse = glm::vec2(0.f, -2.f);
|
|
||||||
e.Point = glm::vec2(0.5f, 0.f);
|
|
||||||
m_EventBroker->Publish(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//PointLightTest
|
//PointLightTest
|
||||||
@@ -162,22 +163,11 @@ public:
|
|||||||
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Brick test model
|
|
||||||
{
|
|
||||||
/*auto t_Brick = m_World->CreateEntity();
|
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(t_Brick);
|
|
||||||
transform->Position = glm::vec3(0.f, 0.f, -12.f);
|
|
||||||
transform->Orientation = glm::rotate(glm::quat(), 0.5f, glm::vec3(0,-1,-1));
|
|
||||||
auto model = m_World->AddComponent<Components::Model>(t_Brick);
|
|
||||||
model->ModelFile = "Models/Test/Brick/Brick.obj";*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto topWall = m_World->CreateEntity();
|
auto topWall = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
|
||||||
transform->Position = glm::vec3(0.f, 5.5f, -10.f);
|
transform->Position = glm::vec3(0.f, 5.5f, -10.f);
|
||||||
transform->Scale = glm::vec3(18.f, 0.5f, 1.f);
|
transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
@@ -193,7 +183,7 @@ public:
|
|||||||
auto leftWall = m_World->CreateEntity();
|
auto leftWall = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(leftWall);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(leftWall);
|
||||||
transform->Position = glm::vec3(-4.f, 1.f, -10.f);
|
transform->Position = glm::vec3(-4.f, 1.f, -10.f);
|
||||||
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
@@ -209,7 +199,7 @@ public:
|
|||||||
auto rightWall = m_World->CreateEntity();
|
auto rightWall = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(rightWall);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(rightWall);
|
||||||
transform->Position = glm::vec3(4.f, 1.f, -10.f);
|
transform->Position = glm::vec3(4.f, 1.f, -10.f);
|
||||||
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
transform->Scale = glm::vec3(0.5f, 20.f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
@@ -230,6 +220,7 @@ public:
|
|||||||
ctransform->Scale = glm::vec3(1.6, 0.4, 0.);
|
ctransform->Scale = glm::vec3(1.6, 0.4, 0.);
|
||||||
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
|
physics->Static = false;
|
||||||
auto csprite = m_World->AddComponent<Components::Sprite>(ent);
|
auto csprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||||
auto pad = m_World->AddComponent<Components::Pad>(ent);
|
auto pad = m_World->AddComponent<Components::Pad>(ent);
|
||||||
csprite->SpriteFile = "Textures/Pad.png";
|
csprite->SpriteFile = "Textures/Pad.png";
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#ifndef DAYDREAM_BALLSYSTEM_H
|
||||||
|
#define DAYDREAM_BALLSYSTEM_H
|
||||||
|
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/World.h"
|
||||||
|
#include "Core/CTransform.h"
|
||||||
|
#include "Physics/EContact.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Game/CBall.h"
|
||||||
|
|
||||||
|
namespace dd {
|
||||||
|
|
||||||
|
namespace Systems {
|
||||||
|
|
||||||
|
class BallSystem : public System {
|
||||||
|
public:
|
||||||
|
BallSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
|
: System(world, eventBroker) { }
|
||||||
|
|
||||||
|
~BallSystem();
|
||||||
|
|
||||||
|
EventRelay<BallSystem, Events::Contact> m_Contact;
|
||||||
|
bool Contact(const Events::Contact &event);
|
||||||
|
|
||||||
|
void RegisterComponents(ComponentFactory *cf) override;
|
||||||
|
|
||||||
|
void Initialize() override;
|
||||||
|
|
||||||
|
// Called once per system every tick
|
||||||
|
void Update(double dt) override;
|
||||||
|
|
||||||
|
// Called once for every entity in the world every tick
|
||||||
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
|
// Called when components are committed to an entity
|
||||||
|
void OnEntityCommit(EntityID entity) override;
|
||||||
|
|
||||||
|
// Called when an entity is removed
|
||||||
|
void OnEntityRemoved(EntityID entity) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -16,6 +16,7 @@ namespace Components
|
|||||||
struct Ball : Component
|
struct Ball : Component
|
||||||
{
|
{
|
||||||
int Number = 0;
|
int Number = 0;
|
||||||
|
float Speed = 5.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ struct Contact : Event
|
|||||||
{
|
{
|
||||||
EntityID Entity1;
|
EntityID Entity1;
|
||||||
EntityID Entity2;
|
EntityID Entity2;
|
||||||
glm::vec2 ContactPoint;
|
glm::vec2 Normal;
|
||||||
|
glm::vec2 SignificantNormal;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
#include "Physics/CCircleShape.h"
|
#include "Physics/CCircleShape.h"
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Game/CPad.h"
|
||||||
|
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
@@ -22,7 +23,6 @@ namespace dd
|
|||||||
namespace Systems
|
namespace Systems
|
||||||
{
|
{
|
||||||
|
|
||||||
//KOLLA http://box2d.org/manual.pdf p52 Pre-Solve Event
|
|
||||||
|
|
||||||
class PhysicsSystem : public System
|
class PhysicsSystem : public System
|
||||||
{
|
{
|
||||||
@@ -65,6 +65,16 @@ private:
|
|||||||
void CreateBody(EntityID entity);
|
void CreateBody(EntityID entity);
|
||||||
|
|
||||||
|
|
||||||
|
struct Impulse
|
||||||
|
{
|
||||||
|
b2Body* Body;
|
||||||
|
b2Vec2 Impulse;
|
||||||
|
b2Vec2 Point;
|
||||||
|
};
|
||||||
|
std::list<Impulse> m_Impulses;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ContactListener : public b2ContactListener
|
class ContactListener : public b2ContactListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -73,22 +83,40 @@ private:
|
|||||||
|
|
||||||
void BeginContact(b2Contact* contact)
|
void BeginContact(b2Contact* contact)
|
||||||
{
|
{
|
||||||
b2Vec2 contactPoint = contact->GetManifold()->localPoint;
|
b2WorldManifold worldManifold;
|
||||||
|
|
||||||
|
contact->GetWorldManifold(&worldManifold);
|
||||||
|
|
||||||
Events::Contact e;
|
Events::Contact e;
|
||||||
e.ContactPoint = glm::vec2(contactPoint.x, contactPoint.y);
|
|
||||||
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||||
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
||||||
|
e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y));
|
||||||
|
e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y));
|
||||||
|
|
||||||
m_PhysicsSystem->EventBroker->Publish(e);
|
m_PhysicsSystem->EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
void EndContact(b2Contact* contact)
|
void EndContact(b2Contact* contact)
|
||||||
{ /* handle end event */ }
|
{
|
||||||
|
|
||||||
|
}
|
||||||
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
|
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
|
||||||
{ /* handle pre-solve event */ }
|
{
|
||||||
|
EntityID entityA = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||||
|
EntityID entityB = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||||
|
|
||||||
|
auto physicsComponentA = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityA);
|
||||||
|
auto physicsComponentB = m_PhysicsSystem->m_World->GetComponent<Components::Physics>(entityB);
|
||||||
|
|
||||||
|
if (physicsComponentA != nullptr || physicsComponentB != nullptr) {
|
||||||
|
// Turn of collisions
|
||||||
|
contact->SetEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||||
{ /* handle post-solve event */ }
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PhysicsSystem* m_PhysicsSystem;
|
PhysicsSystem* m_PhysicsSystem;
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of Daydream Engine.
|
|
||||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
|
||||||
|
|
||||||
Daydream Engine is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Daydream Engine is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public License
|
|
||||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef Events_PlaySFX_h__
|
|
||||||
#define Events_PlaySFX_h__
|
|
||||||
|
|
||||||
#include "Core/EventBroker.h"
|
|
||||||
|
|
||||||
namespace dd
|
|
||||||
{
|
|
||||||
|
|
||||||
namespace Events
|
|
||||||
{
|
|
||||||
|
|
||||||
struct PlaySFX : Event
|
|
||||||
{
|
|
||||||
std::string path;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // Events_PlaySFX_h__
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef Events_PlaySFX_h__
|
||||||
|
#define Events_PlaySFX_h__
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct PlaySound : Event
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
float volume = 1.f;
|
||||||
|
float pitch = 1.f;
|
||||||
|
bool loop = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef EVENTS_ESTOPSOUND_H__
|
||||||
|
#define EVENTS_ESTOPSOUND_H__
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct StopSound : public Event
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -14,6 +14,7 @@ class Sound : public Resource
|
|||||||
friend class ResourceManager;
|
friend class ResourceManager;
|
||||||
public:
|
public:
|
||||||
ALuint Buffer() { return m_Buffer; };
|
ALuint Buffer() { return m_Buffer; };
|
||||||
|
std::string Path() { return m_Path; };
|
||||||
private:
|
private:
|
||||||
Sound(std::string path);
|
Sound(std::string path);
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ private:
|
|||||||
ALuint LoadFile(std::string path);
|
ALuint LoadFile(std::string path);
|
||||||
|
|
||||||
ALuint m_Buffer;
|
ALuint m_Buffer;
|
||||||
|
std::string m_Path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,11 @@
|
|||||||
#include "AL/alc.h"
|
#include "AL/alc.h"
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Sound.h"
|
|
||||||
#include "Sound/EPlaySFX.h"
|
|
||||||
#include "Physics/EContact.h"
|
|
||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Sound.h"
|
||||||
|
#include "Sound/EPlaySound.h"
|
||||||
|
#include "Sound/EStopSound.h"
|
||||||
|
#include "Physics/EContact.h"
|
||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
#include "Game/CBrick.h"
|
#include "Game/CBrick.h"
|
||||||
#include "Game/CPad.h"
|
#include "Game/CPad.h"
|
||||||
@@ -34,17 +35,20 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//Events
|
//Events
|
||||||
dd::EventRelay<SoundSystem, dd::Events::PlaySFX> m_EPlaySFX;
|
dd::EventRelay<SoundSystem, dd::Events::PlaySound> m_EPlaySFX;
|
||||||
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
|
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
|
||||||
bool OnPlaySFX(const dd::Events::PlaySFX &event);
|
dd::EventRelay<SoundSystem, dd::Events::StopSound> m_EStopSound;
|
||||||
|
bool OnPlaySound(const dd::Events::PlaySound &event);
|
||||||
bool OnContact(const dd::Events::Contact &event);
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
|
bool OnStopSound(const dd::Events::StopSound &event);
|
||||||
|
|
||||||
ALuint CreateSource();
|
ALuint CreateSource();
|
||||||
|
|
||||||
std::map<Component*, ALuint> m_Sources;
|
std::map<ALuint, Sound*> m_SourcesToBuffers;
|
||||||
|
|
||||||
|
ALCdevice* m_Device;
|
||||||
|
|
||||||
//std::list<ALuint>
|
|
||||||
//Temp
|
//Temp
|
||||||
ALuint m_Source;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
#include "PrecompiledHeader.h"
|
||||||
|
#include "Game/BallSystem.h"
|
||||||
|
|
||||||
|
dd::Systems::BallSystem::~BallSystem() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::Initialize()
|
||||||
|
{
|
||||||
|
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_Contact, BallSystem::Contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::Update(double dt)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
|
{
|
||||||
|
auto ballComponent = m_World->GetComponent<Components::Ball>(entity);
|
||||||
|
if (ballComponent != nullptr) {
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y));
|
||||||
|
glm::vec2 up = glm::vec2(0.f, 1.f);
|
||||||
|
float angle = glm::acos(glm::dot<float>(dir, up)) * glm::sign(dir.x);
|
||||||
|
transform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, -1.f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::OnEntityCommit(EntityID entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::BallSystem::OnEntityRemoved(EntityID entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
Components::Ball* ballComponent1 = m_World->GetComponent<Components::Ball>(event.Entity1);
|
||||||
|
Components::Ball* ballComponent2 = m_World->GetComponent<Components::Ball>(event.Entity2);
|
||||||
|
Components::Ball* ballComponent;
|
||||||
|
//Which is the ball?
|
||||||
|
EntityID ballEntity, otherEntitiy;
|
||||||
|
|
||||||
|
if (ballComponent1 != nullptr) {
|
||||||
|
ballEntity = event.Entity1;
|
||||||
|
otherEntitiy = event.Entity2;
|
||||||
|
ballComponent = ballComponent1;
|
||||||
|
}
|
||||||
|
else if (ballComponent2 != nullptr) {
|
||||||
|
ballEntity = event.Entity2;
|
||||||
|
otherEntitiy = event.Entity1;
|
||||||
|
ballComponent = ballComponent2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
//TODO: Add support for power-up collisions
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ballTransform = m_World->GetComponent<Components::Transform>(ballEntity);
|
||||||
|
glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y);
|
||||||
|
|
||||||
|
if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Pad"){
|
||||||
|
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
|
||||||
|
float x = ballTransform->Position.x - padTransform->Position.x;
|
||||||
|
|
||||||
|
float movementMultiplier = 5.0f;
|
||||||
|
float y = glm::cos((abs(x) / ((1.6f) * movementMultiplier)) * glm::pi<float>() / 2.f) + 1.f;
|
||||||
|
|
||||||
|
ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal);
|
||||||
|
ballTransform->Velocity = glm::vec3(reflectedVelocity, 0.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
+14
-25
@@ -37,19 +37,11 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
|||||||
if (ReplaceBall() == true) {
|
if (ReplaceBall() == true) {
|
||||||
SetReplaceBall(false);
|
SetReplaceBall(false);
|
||||||
|
|
||||||
auto transformEntity = m_World->GetComponent<Components::Transform>(entity);
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
transformEntity->Position = glm::vec3(0, 20, -10);
|
transform->Position = glm::vec3(0.0f, 0.f, -10.f);
|
||||||
|
transform->Velocity = glm::vec3(0.0f, -ball->Speed, 0.f);
|
||||||
m_World->RemoveEntity(entity);
|
|
||||||
|
|
||||||
auto ent = CreateBall();
|
auto ent = CreateBall();
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(ent);
|
auto transform = m_World->GetComponent<Components::Transform>(ent);
|
||||||
|
|
||||||
Events::SetImpulse e;
|
|
||||||
e.Entity = ent;
|
|
||||||
e.Impulse = glm::vec2(0.f, -1.f);
|
|
||||||
e.Point = glm::vec2(transform->Position.x, transform->Position.y);
|
|
||||||
EventBroker->Publish(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +70,7 @@ void dd::Systems::PadSystem::Update(double dt)
|
|||||||
transform->Velocity.x = pad->MaxSpeed;
|
transform->Velocity.x = pad->MaxSpeed;
|
||||||
}
|
}
|
||||||
transform->Position += transform->Velocity * (float)dt;
|
transform->Position += transform->Velocity * (float)dt;
|
||||||
transform->Velocity += acceleration * (float)dt;
|
transform->Velocity += acceleration * (float)dt;
|
||||||
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
|
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
|
||||||
|
|
||||||
if (Left()) {
|
if (Left()) {
|
||||||
@@ -163,6 +155,7 @@ bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
|
|||||||
|
|
||||||
bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
EntityID entityBall = event.Entity2;
|
EntityID entityBall = event.Entity2;
|
||||||
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
|
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
|
||||||
if (ball == NULL) {
|
if (ball == NULL) {
|
||||||
@@ -178,8 +171,8 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
|
|
||||||
float movementMultiplier = 0.5f;
|
float movementMultiplier = 0.5f;
|
||||||
|
|
||||||
float whatX = transformBall->Position.x - transformPad->Position.x;
|
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
|
||||||
float movementX;
|
//float movementY = glm::cos((abs(movementX) / (3.2f * movementMultiplier)) * 3.14159265359f / 2) * 2.f;
|
||||||
if (whatX > 0) {
|
if (whatX > 0) {
|
||||||
movementX = movementMultiplier * whatX;
|
movementX = movementMultiplier * whatX;
|
||||||
//std::cout << "Right!" << std::endl;
|
//std::cout << "Right!" << std::endl;
|
||||||
@@ -188,26 +181,22 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
//std::cout << "Left!" << std::endl;
|
//std::cout << "Left!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//float movementY = 1;
|
// std::cout << movementX << " " << movementY << std::endl;
|
||||||
|
|
||||||
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
|
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
|
||||||
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2)+ 0.2;
|
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2)+ 0.2;
|
||||||
|
|
||||||
//std::cout << movementX << " " << movementY << std::endl;
|
//std::cout << movementX << " " << movementY << std::endl;
|
||||||
|
|
||||||
//Temporary solution. Add a new ball and delete the old one.
|
float len = glm::length<float>(transformBall->Velocity);
|
||||||
auto ent = CreateBall();
|
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(ent);
|
|
||||||
|
|
||||||
transform->Position = glm::vec3(transformBall->Position.x, transformBall->Position.y + 0.01f, -10.f);
|
|
||||||
|
|
||||||
m_World->RemoveEntity(entityBall);
|
transformBall->Velocity += glm::vec3(transformPad->Velocity.x, 0, 0);
|
||||||
|
transformBall->Velocity = glm::normalize(transformBall->Velocity) * len;
|
||||||
|
|
||||||
Events::SetImpulse e;
|
|
||||||
e.Entity = ent;
|
//transform->Velocity = glm::vec3(movementX, movementY, 0.f);
|
||||||
e.Impulse = glm::vec2(movementX, movementY);
|
*/
|
||||||
e.Point = glm::vec2(transform->Position.x, transform->Position.y);
|
|
||||||
EventBroker->Publish(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
|
bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
|
||||||
|
|||||||
@@ -37,7 +37,13 @@ bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
|||||||
point.x = event.Point.x;
|
point.x = event.Point.x;
|
||||||
point.y = event.Point.y;
|
point.y = event.Point.y;
|
||||||
|
|
||||||
body->ApplyLinearImpulse(impulse, point, true);
|
|
||||||
|
Impulse i;
|
||||||
|
i.Body = body;
|
||||||
|
i.Impulse = impulse;
|
||||||
|
i.Point = point;
|
||||||
|
|
||||||
|
m_Impulses.push_back(i);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -57,8 +63,7 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_World->GetEntityParent(entity) == 0) { //TODO: Make this work with childs too
|
||||||
if (m_World->GetEntityParent(entity) == 0) {
|
|
||||||
b2Vec2 position;
|
b2Vec2 position;
|
||||||
position.x = transformComponent->Position.x;
|
position.x = transformComponent->Position.x;
|
||||||
position.y = transformComponent->Position.y;
|
position.y = transformComponent->Position.y;
|
||||||
@@ -66,10 +71,17 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
float angle = -glm::eulerAngles(transformComponent->Orientation).z;
|
float angle = -glm::eulerAngles(transformComponent->Orientation).z;
|
||||||
|
|
||||||
body->SetTransform(position, angle);
|
body->SetTransform(position, angle);
|
||||||
|
|
||||||
|
body->SetLinearVelocity(b2Vec2(transformComponent->Velocity.x, transformComponent->Velocity.y));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto i : m_Impulses) {
|
||||||
|
i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true);
|
||||||
|
}
|
||||||
|
m_Impulses.clear();
|
||||||
|
|
||||||
|
|
||||||
m_Accumulator += dt;
|
m_Accumulator += dt;
|
||||||
@@ -80,13 +92,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (auto i : m_EntitiesToBodies) {
|
for (auto i : m_EntitiesToBodies) {
|
||||||
EntityID entity = i.first;
|
EntityID entity = i.first;
|
||||||
b2Body* body = i.second;
|
b2Body* body = i.second;
|
||||||
@@ -99,7 +104,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||||
if (! transformComponent)
|
if (! transformComponent)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (m_World->GetEntityParent(entity) == 0) {
|
if (m_World->GetEntityParent(entity) == 0) {
|
||||||
b2Vec2 position = body->GetPosition();
|
b2Vec2 position = body->GetPosition();
|
||||||
transformComponent->Position.x = position.x;
|
transformComponent->Position.x = position.x;
|
||||||
@@ -107,8 +111,13 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
|
|
||||||
float angle = body->GetAngle();
|
float angle = body->GetAngle();
|
||||||
|
|
||||||
//TODO: CHECK IF THIS IS CORRECT
|
|
||||||
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
|
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
|
||||||
|
|
||||||
|
b2Vec2 velocity = body->GetLinearVelocity();
|
||||||
|
transformComponent->Velocity.x = velocity.x;
|
||||||
|
transformComponent->Velocity.y = velocity.y;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,6 +178,7 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
|||||||
bodyDef.type = b2_staticBody;
|
bodyDef.type = b2_staticBody;
|
||||||
} else {
|
} else {
|
||||||
bodyDef.type = b2_dynamicBody;
|
bodyDef.type = b2_dynamicBody;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -205,7 +215,7 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
|||||||
fixtureDef.shape = pShape;
|
fixtureDef.shape = pShape;
|
||||||
fixtureDef.density = 1.f;
|
fixtureDef.density = 1.f;
|
||||||
fixtureDef.restitution = 1.0f;
|
fixtureDef.restitution = 1.0f;
|
||||||
fixtureDef.friction = 0.3f;
|
fixtureDef.friction = 0.0f;
|
||||||
body->CreateFixture(&fixtureDef);
|
body->CreateFixture(&fixtureDef);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
dd::Sound::Sound(std::string path)
|
dd::Sound::Sound(std::string path)
|
||||||
{
|
{
|
||||||
m_Buffer = LoadFile(path);
|
m_Buffer = LoadFile(path);
|
||||||
|
m_Path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALuint dd::Sound::LoadFile(std::string path)
|
ALuint dd::Sound::LoadFile(std::string path)
|
||||||
|
|||||||
+102
-39
@@ -3,17 +3,17 @@
|
|||||||
|
|
||||||
dd::Systems::SoundSystem::~SoundSystem()
|
dd::Systems::SoundSystem::~SoundSystem()
|
||||||
{
|
{
|
||||||
alSourcei(m_Source, AL_BUFFER, 0);
|
alcCloseDevice(m_Device);
|
||||||
alDeleteSources(1, &m_Source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::SoundSystem::Initialize()
|
void dd::Systems::SoundSystem::Initialize()
|
||||||
{ //initialize OpenAL
|
{
|
||||||
ALCdevice* device = alcOpenDevice(NULL);
|
//initialize OpenAL
|
||||||
|
m_Device = alcOpenDevice(NULL);
|
||||||
ALCcontext* context;
|
ALCcontext* context;
|
||||||
|
|
||||||
if (device) {
|
if (m_Device) {
|
||||||
context = alcCreateContext(device, NULL);
|
context = alcCreateContext(m_Device, NULL);
|
||||||
alcMakeContextCurrent(context);
|
alcMakeContextCurrent(context);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -22,52 +22,49 @@ void dd::Systems::SoundSystem::Initialize()
|
|||||||
|
|
||||||
alGetError();
|
alGetError();
|
||||||
|
|
||||||
//Create source
|
|
||||||
m_Source = CreateSource();
|
|
||||||
|
|
||||||
alSpeedOfSound(340.29f); // Speed of sound m/s
|
|
||||||
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
|
||||||
|
|
||||||
const ALfloat pos[3] = {0, 0, 0};
|
const ALfloat pos[3] = {0, 0, 0};
|
||||||
alListenerfv(AL_POSITION, pos);
|
alListenerfv(AL_POSITION, pos);
|
||||||
alSourcefv(m_Source, AL_POSITION, pos);
|
|
||||||
|
|
||||||
//Subscribe to events
|
//Subscribe to events
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySFX);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
|
||||||
|
|
||||||
|
//Todo: Move this
|
||||||
|
{
|
||||||
|
dd::Events::PlaySound e;
|
||||||
|
e.path = "Sounds/BGM/soft-guitar.wav";
|
||||||
|
e.loop = true;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
dd::Events::PlaySound e;
|
||||||
|
e.path = "Sounds/BGM/water-flowing.wav";
|
||||||
|
e.volume = 0.3f;
|
||||||
|
e.loop = true;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::SoundSystem::Update(double dt)
|
void dd::Systems::SoundSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
|
//LOG_INFO("Sources : %i", m_SourcesToBuffers.size());
|
||||||
|
|
||||||
}
|
std::vector<ALuint> deleteList;
|
||||||
|
for (auto item : m_SourcesToBuffers) {
|
||||||
bool dd::Systems::SoundSystem::OnPlaySFX(const dd::Events::PlaySFX &event)
|
ALint sourceState;
|
||||||
{
|
alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState);
|
||||||
//m_Source = CreateSource();
|
if (sourceState == AL_STOPPED) {
|
||||||
Sound *sound = ResourceManager::Load<Sound>(event.path);
|
deleteList.push_back(item.first);
|
||||||
ALuint buffer = sound->Buffer();
|
|
||||||
alSourcei(m_Source, AL_BUFFER, buffer);
|
|
||||||
alSourcePlay(m_Source);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
|
||||||
{
|
|
||||||
//Check which entity has the collisionSound component.
|
|
||||||
auto collisionSound = m_World->GetComponent<Components::CollisionSound>(event.Entity1);
|
|
||||||
if (collisionSound == NULL) {
|
|
||||||
collisionSound = m_World->GetComponent<Components::CollisionSound>(event.Entity2);
|
|
||||||
if (collisionSound == NULL) {
|
|
||||||
//None of the entities had a collisionSound component.
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send play-sound event
|
for (int i = 0; i < deleteList.size(); i++) {
|
||||||
dd::Events::PlaySFX e;
|
alDeleteSources(1, &deleteList[i]);
|
||||||
e.path = collisionSound->filePath;
|
//alDeleteBuffers(1, &m_SourcesToBuffers[deleteList[i]]);
|
||||||
EventBroker->Publish(e);
|
m_SourcesToBuffers.erase(deleteList[i]);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ALuint dd::Systems::SoundSystem::CreateSource()
|
ALuint dd::Systems::SoundSystem::CreateSource()
|
||||||
@@ -77,3 +74,69 @@ ALuint dd::Systems::SoundSystem::CreateSource()
|
|||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
|
||||||
|
{
|
||||||
|
//Loading and binding sound buffer to source
|
||||||
|
Sound *sound = ResourceManager::Load<Sound>(event.path);
|
||||||
|
if (sound == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ALuint source = CreateSource();
|
||||||
|
m_SourcesToBuffers[source] = sound;
|
||||||
|
ALuint buffer = sound->Buffer();
|
||||||
|
alSourcei(source, AL_BUFFER, buffer);
|
||||||
|
|
||||||
|
//Sound settings
|
||||||
|
alSourcef(source, AL_GAIN, event.volume);
|
||||||
|
alSourcef(source, AL_PITCH, event.pitch);
|
||||||
|
if (event.loop) {
|
||||||
|
alSourcei(source, AL_LOOPING, AL_TRUE);
|
||||||
|
}
|
||||||
|
else if (!event.loop)
|
||||||
|
{
|
||||||
|
alSourcei(source, AL_LOOPING, AL_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Play
|
||||||
|
alSourcePlay(source);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event)
|
||||||
|
{
|
||||||
|
for (auto item : m_SourcesToBuffers) {
|
||||||
|
if (item.second->Path() == event.path) {
|
||||||
|
alSourceStop(item.first);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
||||||
|
{
|
||||||
|
//Check which entity has the collisionSound component.
|
||||||
|
auto collisionSound = m_World->GetComponent<Components::CollisionSound>(event.Entity1);
|
||||||
|
if (collisionSound == nullptr) {
|
||||||
|
collisionSound = m_World->GetComponent<Components::CollisionSound>(event.Entity2);
|
||||||
|
if (collisionSound == nullptr) {
|
||||||
|
//None of the entities had a collisionSound component.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
dd::Events::StopSound e;
|
||||||
|
e.path = "Sounds/BGM/soft-guitar.wav";
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
//Send play-sound event
|
||||||
|
dd::Events::PlaySound e;
|
||||||
|
e.path = collisionSound->filePath;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user