Merged master into LevelSystemAndSuch. Now let's see if it works.

This commit is contained in:
PlatinumSkink
2015-09-23 16:05:07 +02:00
26 changed files with 47248 additions and 154 deletions
+12 -21
View File
@@ -44,6 +44,7 @@
#include "Game/CBall.h"
#include "Game/CPad.h"
#include "Game/CBrick.h"
#include "Game/BallSystem.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/PhysicsSystem.h"
@@ -51,6 +52,7 @@
#include "Physics/CBoxShape.h"
#include "Physics/ESetImpulse.h"
namespace dd
{
@@ -104,6 +106,8 @@ public:
m_World->AddSystem<Systems::LevelSystem>();
m_World->SystemFactory.Register<Systems::PadSystem>([this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
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::Template>();
@@ -119,15 +123,16 @@ public:
{
auto ent = m_World->CreateEntity();
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->Velocity = glm::vec3(0.0f, -10.f, 0.f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(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);
physics->Static = false;
@@ -136,11 +141,7 @@ public:
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
@@ -162,22 +163,11 @@ public:
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();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
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);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
@@ -193,7 +183,7 @@ public:
auto leftWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(leftWall);
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);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
@@ -209,7 +199,7 @@ public:
auto rightWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(rightWall);
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);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
@@ -230,6 +220,7 @@ public:
ctransform->Scale = glm::vec3(1.6, 0.4, 0.);
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
auto physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
auto csprite = m_World->AddComponent<Components::Sprite>(ent);
auto pad = m_World->AddComponent<Components::Pad>(ent);
csprite->SpriteFile = "Textures/Pad.png";
+48
View File
@@ -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
+1
View File
@@ -16,6 +16,7 @@ namespace Components
struct Ball : Component
{
int Number = 0;
float Speed = 5.f;
};
}
+2 -1
View File
@@ -19,7 +19,8 @@ struct Contact : Event
{
EntityID Entity1;
EntityID Entity2;
glm::vec2 ContactPoint;
glm::vec2 Normal;
glm::vec2 SignificantNormal;
};
}
+35 -7
View File
@@ -14,6 +14,7 @@
#include "Physics/ESetImpulse.h"
#include "Physics/CCircleShape.h"
#include "Core/EventBroker.h"
#include "Game/CPad.h"
namespace dd
@@ -22,7 +23,6 @@ namespace dd
namespace Systems
{
//KOLLA http://box2d.org/manual.pdf p52 Pre-Solve Event
class PhysicsSystem : public System
{
@@ -65,6 +65,16 @@ private:
void CreateBody(EntityID entity);
struct Impulse
{
b2Body* Body;
b2Vec2 Impulse;
b2Vec2 Point;
};
std::list<Impulse> m_Impulses;
class ContactListener : public b2ContactListener
{
public:
@@ -73,22 +83,40 @@ private:
void BeginContact(b2Contact* contact)
{
b2Vec2 contactPoint = contact->GetManifold()->localPoint;
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
Events::Contact e;
e.ContactPoint = glm::vec2(contactPoint.x, contactPoint.y);
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->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);
}
void EndContact(b2Contact* contact)
{ /* handle end event */ }
{
}
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)
{ /* handle post-solve event */ }
{
}
private:
PhysicsSystem* m_PhysicsSystem;
-39
View File
@@ -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__
+24
View File
@@ -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
+23
View File
@@ -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
+2
View File
@@ -14,6 +14,7 @@ class Sound : public Resource
friend class ResourceManager;
public:
ALuint Buffer() { return m_Buffer; };
std::string Path() { return m_Path; };
private:
Sound(std::string path);
@@ -28,6 +29,7 @@ private:
ALuint LoadFile(std::string path);
ALuint m_Buffer;
std::string m_Path;
};
+12 -8
View File
@@ -6,10 +6,11 @@
#include "AL/alc.h"
#include "Core/System.h"
#include "Core/World.h"
#include "Sound.h"
#include "Sound/EPlaySFX.h"
#include "Physics/EContact.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/CBrick.h"
#include "Game/CPad.h"
@@ -34,17 +35,20 @@ public:
private:
//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;
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 OnStopSound(const dd::Events::StopSound &event);
ALuint CreateSource();
std::map<Component*, ALuint> m_Sources;
std::map<ALuint, Sound*> m_SourcesToBuffers;
ALCdevice* m_Device;
//std::list<ALuint>
//Temp
ALuint m_Source;
};
}