97 Commits

Author SHA1 Message Date
PlatinumSkink 58407203fc Refinements in Niklas code 2015-10-05 13:09:02 +02:00
PlatinumSkink 06c7245421 Removed my unnecessary RemoveComponents. 2015-10-02 14:28:35 +02:00
PlatinumSkink 0cffdadd33 Removed some couts. 2015-10-02 14:20:53 +02:00
PlatinumSkink 754356da1d Commit to enable pulling. 2015-10-02 13:06:44 +02:00
PlatinumSkink cf6f9866e7 Merge branch 'bugfix' of https://github.com/teamfisk/AgileBreakOut into bugfix 2015-10-01 15:47:12 +02:00
PlatinumSkink f45908647c Quick-Fix for Score Error when additional frames appeared 2015-10-01 15:46:58 +02:00
viktorljung a1e49d75fb Merge branch 'Physics' into bugfix
Conflicts:
	include/Core/Engine.h
	include/Physics/PhysicsSystem.h
	src/game/Physics/PhysicsSystem.cpp
2015-10-01 15:15:10 +02:00
Jace 0743d882b9 Merge branch 'gui' into bugfix 2015-10-01 14:42:39 +02:00
PlatinumSkink 4c7714dd21 Merge branch 'LevelSystemAndSuch' into bugfix 2015-10-01 14:41:58 +02:00
Jace c821fbfc25 Futile attempts to fix memory corruption bug 2015-10-01 16:12:53 +02:00
Jace 45f1d882ad Adding these two additional frames make the event broker break 2015-10-01 14:41:55 +02:00
PlatinumSkink e120b09b84 Merge branch 'master' into LevelSystemAndSuch 2015-10-01 14:36:12 +02:00
PlatinumSkink a4065f734b Merge branch 'master' of https://github.com/teamfisk/AgileBreakOut 2015-10-01 14:26:25 +02:00
tleety 45711500f7 Merged 2015-10-01 14:24:06 +02:00
tleety 52dec86925 Particle system up and running, but with bugged rendering 2015-10-01 14:14:51 +02:00
PlatinumSkink 074c53a82b Merge branch 'master' of https://github.com/teamfisk/AgileBreakOut 2015-10-01 14:14:36 +02:00
PlatinumSkink 4d3428f125 HitLag has types in strings to send along to affect what systems lag. 2015-10-01 14:14:07 +02:00
viktorljung 39f4215c2b Merge remote-tracking branch 'origin/master' into Physics
Conflicts:
	include/Physics/PhysicsSystem.h
	src/game/Physics/PhysicsSystem.cpp
2015-10-01 14:13:51 +02:00
viktorljung cbaca42a3c Changed SquidModel 2015-10-01 14:04:21 +02:00
Jace ff27eafccf WORKING number frame 2015-10-01 13:09:27 +02:00
Jace b42a09fce1 Semi-working number frame 2015-10-01 11:01:33 +02:00
Jace d1dde9459f Added FPS counter 2015-10-01 11:01:18 +02:00
Jace cc1bc25914 Merge branch 'master' of github.com:teamfisk/AgileBreakOut 2015-10-01 10:55:04 +02:00
Jace e1ff3825ee Fixed type error in sound loading 2015-10-01 12:51:29 +02:00
Jace 842a112be8 Added Frame tests 2015-10-01 10:53:46 +02:00
Jace ba67f6ea37 Tests fixed into working order 2015-10-01 10:53:29 +02:00
PlatinumSkink c63ec035a7 HitLagSystem implemented. 2015-09-30 16:42:35 +02:00
PlatinumSkink c31ff4cfcb P-button pauses, H-button does 0.3 second HitLag. 2015-09-30 15:19:45 +02:00
PlatinumSkink 2fb16357fa Moved pad-creation to PadSystem. Pad now stops at sides. 2015-09-30 10:32:17 +02:00
tleety 2491dd8b74 Fixed some things, code up to styleguide 2015-09-30 10:29:56 +02:00
PlatinumSkink 45e68c51a3 Merge remote-tracking branch 'origin/master' into LevelSystemAndSuch 2015-09-29 14:44:50 +02:00
PlatinumSkink c3b54ef030 Implemented Combos which multiply score. Adjusted pad a bit. 2015-09-29 14:42:01 +02:00
viktorljung 7733a44d53 Refactoring and starting to write test for PhysicsSystem 2015-09-29 12:08:13 +02:00
Stiffly cb70cdfc5d Merge remote-tracking branch 'origin/master' into Sound 2015-09-29 12:04:52 +02:00
PlatinumSkink 94fc7c1ce6 Merge remote-tracking branch 'origin/master' into LevelSystemAndSuch. 2015-09-29 11:21:35 +02:00
tleety a1c709a2db Removed wierd glow on water 2015-09-29 11:10:08 +02:00
Stiffly 3ab6c0c5ba Sound channel volume not overriding individual volume for sounds. 2015-09-29 11:09:43 +02:00
tleety 38d3a8c990 Fixed a bug where you could not have more than one particle group 2015-09-29 10:27:57 +02:00
Jace 5e7e5ec8bb Fixed precision loss in physics accumulator 2015-09-28 22:55:39 +02:00
Jace 5e0b0f920a Fixed your asset loading fuckups 2015-09-28 22:46:35 +02:00
Jace d472e2ae88 Added ignore rule for .orig files, since nobody seem to be able to look at what they commit... 2015-09-28 21:56:11 +02:00
Jace edd87ddf58 Fixed critical warnings for Linux build 2015-09-28 20:40:28 +02:00
Stiffly a97dae542d Merge remote-tracking branch 'origin/master' into Sound
Conflicts:
	src/game/Sound/SoundSystem.cpp
2015-09-28 18:14:06 +02:00
PlatinumSkink 7b7277509e CreateBall clones the original ball rather than create new balls. 2015-09-28 18:09:55 +02:00
Stiffly f10749d220 Refactoring SoundSystem and its events, components 2015-09-28 17:59:57 +02:00
PlatinumSkink fc41727a5d Transferred Ball-stuff into BallSystem. 2015-09-28 17:24:58 +02:00
viktorljung 22c7663cc5 Merge branch 'master' into Physics 2015-09-28 17:21:08 +02:00
viktorljung 1a0201ee98 Style guide fixes 2015-09-28 17:20:23 +02:00
Jace 2d7703afad Header definitions added to style guide 2015-09-28 17:17:24 +02:00
PlatinumSkink 90424b8d68 Merge branch 'master' into LevelSystemAndSuch 2015-09-28 15:06:37 +02:00
Jace 7d9e3e00a4 Fixed out-of-range error in NumberFrame 2015-09-25 08:23:41 +02:00
Jace be60464bb5 Merge branch 'master' of github.com:teamfisk/AgileBreakOut 2015-09-25 05:47:37 +02:00
Jace 17f8905696 Removed the HUD from the menu screen 2015-09-25 05:47:20 +02:00
viktorljung c459560bfa Fixed score not accumulating correctly 2015-09-25 05:39:09 +02:00
viktorljung ad299ad2e5 Merge remote-tracking branch 'origin/master' into Physics 2015-09-25 05:34:00 +02:00
viktorljung cb48b881b7 cool fixes and stuff 2015-09-25 05:33:10 +02:00
Jace 7b47385674 Working NumberFrame and score indicator 2015-09-25 05:30:59 +02:00
viktorljung a730a1ce16 Merge remote-tracking branch 'origin/master' into Physics 2015-09-25 05:16:58 +02:00
viktorljung 96511c63b1 Merge remote-tracking branch 'origin/master' into Physics
Conflicts:
	include/Core/Engine.h
	include/Physics/PhysicsSystem.h
	src/game/Game/LevelSystem.cpp
	src/game/Physics/PhysicsSystem.cpp
2015-09-25 05:16:32 +02:00
tleety 2af9567722 Merge branch 'master' of github.com:teamfisk/AgileBreakOut 2015-09-25 04:40:51 +02:00
viktorljung cfb6d1e4b5 Falling bricks and collision filters 2015-09-25 04:28:46 +02:00
tleety b77c357990 Changed some lighting and the background pipe scale 2015-09-25 03:33:30 +02:00
Jace 186e06bc22 Fixed bug where render queue wouldn't get cleared if the world wasn't running 2015-09-25 03:23:42 +02:00
Jace c0f77dd32a fixup! Merge branch 'master' of github.com:teamfisk/AgileBreakOut 2015-09-25 03:10:47 +02:00
Jace 8b3d9eb842 WIP HUD 2015-09-25 03:04:37 +02:00
Jace ecfa666a22 Merge branch 'master' of github.com:teamfisk/AgileBreakOut
# Conflicts:
#	include/Core/Engine.h
2015-09-25 03:04:13 +02:00
Stiffly b0c19c74f2 Merge remote-tracking branch 'origin/master' into EGameStart
Conflicts:
	include/Core/Engine.h
2015-09-25 02:49:50 +02:00
Stiffly 650c7ec47c EStartGame up and running. Moved BGM-play from soundsystem init to EGameStart. 2015-09-25 02:43:34 +02:00
Jace d2bc91be48 Merge remote-tracking branch 'origin/master' into gui
Conflicts:
	include/Core/Engine.h
	include/Core/RenderQueue.h
	include/Core/Renderer.h
	src/game/Core/Renderer.cpp
2015-09-25 02:27:00 +02:00
Jace c9854d2b83 Working volume sliders! 2015-09-25 02:19:37 +02:00
tleety f79d5ec68b Merge remote-tracking branch 'origin/water' 2015-09-25 01:51:33 +02:00
tleety effc9ff781 Merge and some small fixes 2015-09-25 01:49:08 +02:00
Jace 5f1963b8bc Complete main menu without event bindings. 2015-09-25 01:29:14 +02:00
Jace b83de44715 Working GUI Button 2015-09-25 01:29:14 +02:00
Jace 8e00b76036 Error texture for texture frames when texture is missing 2015-09-25 01:29:13 +02:00
Jace e0b1747ca9 EventBroker::Clear renamed to Swap to cause less confusion 2015-09-25 01:29:13 +02:00
Jace 1d500eb4f6 First iteration of GUI code. GUI is rendered on top of everything, world still separate. 2015-09-25 01:29:13 +02:00
Stiffly 0e6fcfb2ba Merge remote-tracking branch 'origin/master' into Sound 2015-09-25 01:03:28 +02:00
tleety c624c5bcf3 Merge master 2015-09-25 00:03:28 +02:00
viktorljung d2301594ce Gravity scale per entity 2015-09-25 00:01:24 +02:00
Stiffly 181ac60bd0 MasterVolume now working due to previous refactoring.
TODO: Make it depend on individual volume value.
2015-09-24 23:41:41 +02:00
PlatinumSkink 118c0b3a24 Merge branch 'LevelSystemAndSuch' of https://github.com/teamfisk/AgileBreakOut into LevelSystemAndSuch 2015-09-24 23:23:48 +02:00
Stiffly 0d521cdcc9 Refactoring. Splitting up storage and handling into SFX- and BGM sources. 2015-09-24 23:21:55 +02:00
tleety fa198cf953 Water now rendered in forward rendering 2015-09-24 23:21:46 +02:00
Stiffly e867722d9a Added logic for mastervolume. And a coresponding event.
(sources need to be updated for it to be fully working)
2015-09-24 22:55:24 +02:00
Stiffly 1f73201943 Merge remote-tracking branch 'origin/master' into Sound 2015-09-24 21:03:57 +02:00
viktorljung bc6b037923 Added submarine pad 2015-09-24 20:54:57 +02:00
viktorljung e7806165b4 Merged Master into Sound. 2015-09-24 20:54:32 +02:00
PlatinumSkink 8bf10d4517 Removed Stage Reset and Life Display. 2015-09-24 18:58:34 +02:00
tleety ef3591ba46 Water threshhold added, now it's actually waterlike 2015-09-24 16:23:57 +02:00
tleety a1215d71e9 Water now blurred and looking kinda water like 2015-09-24 16:10:13 +02:00
tleety d473e3711c Now render water through it's own buffer. Not currently visable through finaltexture. Also added a white texture to render the water. 2015-09-23 18:01:15 +02:00
tleety 8e2eb63c5e Added renderQueue for water and created buffers for the water to use. 2015-09-23 12:07:28 +02:00
tleety 94401a10ee Water working, might not work for several bodies 2015-09-22 16:06:47 +02:00
tleety 1e70e151ee Continued work on water, can now get 1 particle? maybe? Gotta get rendering to work so i can test it. 2015-09-21 16:00:20 +02:00
tleety b32934dba6 Merge remote-tracking branch 'origin/physics' into water
# Conflicts:
#	include/Core/Engine.h
#	include/Physics/PhysicsSystem.h
#	src/game/Game/PadSystem.cpp
#	src/game/Physics/PhysicsSystem.cpp
2015-09-17 17:37:58 +02:00
tleety b69413d9c9 Base water set up 2015-09-17 17:35:17 +02:00
109 changed files with 12275 additions and 1669 deletions
+2 -1
View File
@@ -2,4 +2,5 @@
/bin/
/lib/
# CLion
.idea/
.idea/
.orig
Regular → Executable
+833 -835
View File
File diff suppressed because it is too large Load Diff
+12
View File
@@ -0,0 +1,12 @@
# Blender MTL File: 'submarine.blend'
# Material Count: 1
newmtl Material
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 SubmarineTexture.png
File diff suppressed because it is too large Load Diff
+21
View File
@@ -0,0 +1,21 @@
# Blender MTL File: 'Sid.blend'
# Material Count: 2
newmtl Derp
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd SquidTexture.png
newmtl None
Ns 0
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2
map_Kd SquidTexture.png
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
View File
Binary file not shown.
Regular → Executable
+267 -117
View File
@@ -45,51 +45,67 @@
#include "Game/CPad.h"
#include "Game/CBrick.h"
#include "Game/BallSystem.h"
#include "Game/HitLagSystem.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/PhysicsSystem.h"
#include "Physics/CPhysics.h"
#include "Physics/CBoxShape.h"
#include "Physics/CRectangleShape.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CWaterVolume.h"
#include "Physics/CParticle.h"
#include "Physics/CParticleEmitter.h"
#include "Game/EGameStart.h"
#include "Sound/EPlaySound.h"
#include "GUI/Frame.h"
#include "GUI/Button.h"
#include "Game/MainMenu.h"
#include "Game/HUD.h"
namespace dd
{
class Engine
{
public:
Engine(int argc, char* argv[]) {
m_EventBroker = std::make_shared<EventBroker>();
m_EventBroker = std::make_shared<EventBroker>();
m_Renderer = std::make_shared<Renderer>();
m_Renderer->SetFullscreen(false);
//m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
m_Renderer->SetResolution(Rectangle(0, 0, 675, 1080));
m_Renderer = std::make_shared<Renderer>();
m_Renderer->SetFullscreen(false);
//m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
m_Renderer->SetResolution(Rectangle(0, 0, 675, 1080));
m_Renderer->Initialize();
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
m_FrameStack = new GUI::Frame(m_EventBroker.get());
m_FrameStack->Width = 675;
m_FrameStack->Height = 1080;
auto menu = new GUI::MainMenu(m_FrameStack, "MainMenu");
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
m_World = std::make_shared<World>(m_EventBroker);
//TODO: Move this out of engine.h
m_World->ComponentFactory.Register<Components::Transform>();
m_World->SystemFactory.Register<Systems::TransformSystem>(
[this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::TransformSystem>();
//TODO: Move this out of engine.h
m_World->ComponentFactory.Register<Components::Transform>();
m_World->SystemFactory.Register<Systems::TransformSystem>(
[this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::TransformSystem>();
m_World->ComponentFactory.Register<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>();
m_World->ComponentFactory.Register<Components::CollisionSound>();
m_World->SystemFactory.Register<Systems::SoundSystem>([this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); });
m_World->SystemFactory.Register<Systems::SoundSystem>(
[this]() { return new Systems::SoundSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::SoundSystem>();
m_World->ComponentFactory.Register<Components::Sprite>();
m_World->ComponentFactory.Register<Components::Sprite>();
m_World->ComponentFactory.Register<Components::RectangleShape>();
m_World->ComponentFactory.Register<Components::Physics>();
m_World->ComponentFactory.Register<Components::RectangleShape>();
m_World->ComponentFactory.Register<Components::Physics>();
m_World->ComponentFactory.Register<Components::Ball>();
m_World->ComponentFactory.Register<Components::Brick>();
m_World->ComponentFactory.Register<Components::Pad>();
@@ -98,136 +114,242 @@ public:
m_World->ComponentFactory.Register<Components::PowerUp>();
m_World->ComponentFactory.Register<Components::PowerUpBrick>();
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>();
m_World->SystemFactory.Register<Systems::LevelSystem>([this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
m_World->SystemFactory.Register<Systems::LevelSystem>(
[this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
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->SystemFactory.Register<Systems::BallSystem>([this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
m_World->SystemFactory.Register<Systems::BallSystem>(
[this]() { return new Systems::BallSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::BallSystem>();
m_World->SystemFactory.Register<Systems::HitLagSystem>(
[this]() { return new Systems::HitLagSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::HitLagSystem>();
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>();
m_World->ComponentFactory.Register<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>();
m_World->ComponentFactory.Register<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>();
m_World->ComponentFactory.Register<Components::PointLight>();
m_World->Initialize();
m_World->ComponentFactory.Register<Components::WaterVolume>();
m_World->ComponentFactory.Register<Components::Particle>();
m_World->ComponentFactory.Register<Components::ParticleEmitter>();
m_World->Initialize();
//TODO: Remove tobias light-test code.
/*{
}*/
//OctoBall
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(-0.f, 0.26f, -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;
auto plight = m_World->AddComponent<Components::PointLight>(ent);
plight->Radius = 2.f;
m_World->CommitEntity(ent);
}
//PointLightTest
{
auto t_Light = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_Light);
transform->Position = glm::vec3(2.f, 1.5f, -9.f);
transform->Position = glm::vec3(-3.f, 6.f, -5.f);
auto pl = m_World->AddComponent<Components::PointLight>(t_Light);
pl->Radius = 8.f;
pl->Radius = 20.f;
pl->Diffuse = glm::vec3(0.8f, 0.7f, 0.05f);
auto model = m_World->AddComponent<Components::Model>(t_Light);
model->ModelFile = "Models/Core/UnitSphere.obj";
m_World->CommitEntity(t_Light);
}
{
auto t_Light = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_Light);
transform->Position = glm::vec3(3.f, -5.f, -5.f);
auto pl = m_World->AddComponent<Components::PointLight>(t_Light);
pl->Radius = 15.f;
pl->Diffuse = glm::vec3(0.1f, 0.5f, 0.8f);
auto model = m_World->AddComponent<Components::Model>(t_Light);
model->ModelFile = "Models/Core/UnitSphere.obj";
m_World->CommitEntity(t_Light);
}
//Halfpipe background test model.
{
auto t_halfPipe = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_halfPipe);
transform->Position = glm::vec3(0.f, 0.f, -13.f);
transform->Scale = glm::vec3(5.f);
transform->Position = glm::vec3(0.f, 0.f, -15.f);
transform->Scale = glm::vec3(6.f, 6.f, 10.f);
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
model->Color = glm::vec4(1.f, 0.f, 0.f, 0.3f);
m_World->CommitEntity(t_halfPipe);
}
//Background
{
auto background = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(background);
transform->Position = glm::vec3(0.f, 0.f, -30.f);
transform->Scale = glm::vec3(2681.f / 50.f, 1080.f / 50.f, 1.f);
auto sprite = m_World->AddComponent<Components::Sprite>(background);
sprite->SpriteFile = "Textures/Background.png";
m_World->CommitEntity(background);
}
//ParticleTest
// {
// auto Pe = m_World->CreateEntity();
// auto transform = m_World->AddComponent<Components::Transform>(Pe);
// auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(Pe);
//
// transform->Position = glm::vec3(0.f, -5.f, -10.f);
// particleEmitter->GravityScale = 0.0f;
// particleEmitter->SpawnRate = 1.0f;
//
// {
// auto Pt = m_World->CreateEntity(Pe);
// auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
// auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
// //auto PtModel = m_World->AddComponent<Components::Model>(Pt);
// auto PtParticle = m_World->AddComponent<Components::Particle>(Pt);
// auto PtTemplate = m_World->AddComponent<Components::Template>(Pt);
//
// PtTransform->Velocity = glm::vec3(1.0f, 0.f, 0.f);
// PtTransform->Position = transform->Position;
// PtSprite->SpriteFile = "Textures/Ball.png";
//
// //PtModel->ModelFile = "Models/Brick/Brick.obj";
// PtParticle->LifeTime = 1000.f;
// PtParticle->Flags = ParticleFlags::Type::powderParticle;
// }
// m_World->CommitEntity(Pe);
// }
{
auto Pt = m_World->CreateEntity();
auto PtTransform = m_World->AddComponent<Components::Transform>(Pt);
auto PtSprite = m_World->AddComponent<Components::Sprite>(Pt);
PtTransform->Position = glm::vec3(2.f, 0.f, -10.f);
PtSprite->SpriteFile = "Textures/Ball.png";
}
//Water test
{
float amount = 1.5f;
auto t_waterBody = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_waterBody);
transform->Position = glm::vec3(0.f, -6.25f + (amount / 2), -10.f);
transform->Scale = glm::vec3(7.f, amount, 1.f);
auto water = m_World->AddComponent<Components::WaterVolume>(t_waterBody);
auto body = m_World->AddComponent<Components::RectangleShape>(t_waterBody);
m_World->CommitEntity(t_waterBody);
}
//TODO: Why does the ball not collide with these bricks?
//BottomBox
{
auto topWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
auto transform = m_World->AddComponent<Components::Transform>(topWall);
transform->Position = glm::vec3(0.f, -6.f, -9.9f);
transform->Scale = glm::vec3(10.f, 0.5f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
topWall);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
physics->Static = true;
m_World->CommitEntity(topWall);
}
//SideBox
// {
// auto topWall = m_World->CreateEntity();
// std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
// transform->Position = glm::vec3(3.f, -3.0f, -9.9f);
// transform->Scale = glm::vec3(0.5f, 3.f, 1.f);
// std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
// sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
// std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
// topWall);
// std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
// physics->Static = true;
// m_World->CommitEntity(topWall);
// }
// //OtherSideBox
// {
// auto topWall = m_World->CreateEntity();
// std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
// transform->Position = glm::vec3(-4.f, -3.0f, -9.9f);
// transform->Scale = glm::vec3(0.5f, 3.0f, 1.f);
// std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
// sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
// std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
// topWall);
// std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
// physics->Static = true;
// m_World->CommitEntity(topWall);
// }
/*{
auto topWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(
topWall);
transform->Position = glm::vec3(0.f, 6.f, -10.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";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(topWall);
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
topWall);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
physics->Static = true;
physics->Category = CollisionLayer::Type::Wall;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
m_World->CommitEntity(topWall);
}
}*/
{
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->Scale = glm::vec3(0.5f, 20.f, 1.f);
transform->Scale = glm::vec3(0.5f, 35.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(leftWall);
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
leftWall);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(leftWall);
physics->Static = true;
physics->Category = CollisionLayer::Type::Wall;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
m_World->CommitEntity(leftWall);
}
{
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->Scale = glm::vec3(0.5f, 20.f, 1.f);
transform->Scale = glm::vec3(0.5f, 35.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(rightWall);
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
rightWall);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(rightWall);
physics->Static = true;
physics->Category = CollisionLayer::Type::Wall;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
m_World->CommitEntity(rightWall);
}
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Pad");
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
ctransform->Position = glm::vec3(0.f, -5.f, -10.f);
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";
m_World->CommitEntity(ent);
}
m_LastTime = glfwGetTime();
//EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart);
m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1));
m_EventBroker->Subscribe(m_EGameStart);
m_LastTime = glfwGetTime();
}
bool Running() const { return !glfwWindowShouldClose(m_Renderer->Window()); }
@@ -238,39 +360,32 @@ public:
double dt = currentTime - m_LastTime;
m_LastTime = currentTime;
ResourceManager::Update();
// Update input
m_InputManager->Update(dt);
// Swap event queues to get fresh input data in the read queue
//m_EventBroker->Swap();
m_World->Update(dt);
//
// if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) {
// ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
// }
//
//TODO Fill up the renderQueue with models (Temp fix)
// TEMPAddToRenderQueue();
// Render scene
//TODO send renderqueue to draw.
// m_Renderer->Draw(m_RendererQueue);
if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) {
ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
//ResourceManager::Update();
if (m_GameIsRunning) {
m_World->Update(dt);
}
m_EventBroker->Process<GUI::Frame>();
m_FrameStack->UpdateLayered(dt);
m_RendererQueue.Clear();
m_FrameStack->DrawLayered(m_RendererQueue);
//TODO Fill up the renderQueue with models (Temp fix)
TEMPAddToRenderQueue();
if (m_GameIsRunning) {
TEMPAddToRenderQueue();
}
// Render scene
//TODO send renderqueue to draw.
m_Renderer->Draw(m_RendererQueue);
m_EventBroker->Process<Engine>();
// Swap event queues
m_EventBroker->Clear();
m_EventBroker->Swap();
glfwPollEvents();
}
@@ -281,12 +396,9 @@ public:
//TODO: Get this out of engine.h
void TEMPAddToRenderQueue()
{
if (!m_TransformSystem)
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
m_RendererQueue.Clear();
for (auto &pair : *m_World->GetEntities())
{
EntityID entity = pair.first;
@@ -315,8 +427,6 @@ public:
}
}
//TODO: Add LightLoadShit
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
if (pointLightComponent)
{
@@ -327,11 +437,23 @@ public:
pointLightComponent->Radius);
}
auto parent = m_World->GetEntityParent(entity);
if(parent != 0) {
auto waterParticleComponent = m_World->GetComponent<Components::WaterVolume>(parent);
if (waterParticleComponent) {
//TODO: Remove hardcoded color.
//TODO: Do i even need modelMatrix?
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
* glm::scale(absoluteTransform.Scale);
EnqueueWaterParticles(absoluteTransform.Position, glm::vec4(1.f, 1.f, 1.f, 1.f), modelMatrix, absoluteTransform.Position.z);
}
}
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
if (spriteComponent)
{
std::string normal = spriteComponent->NormalTexture;
std::string spec = spriteComponent->SpecularTexture;
@@ -354,8 +476,6 @@ public:
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
}
}
m_RendererQueue.Sort();
}
//TODO: Get this out of engine.h
@@ -374,7 +494,6 @@ public:
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
job.Color = color;
job.fileName = fileName;
m_RendererQueue.Deferred.Add(job);
}
@@ -408,15 +527,46 @@ public:
}
void EnqueueWaterParticles(glm::vec3 position, glm::vec4 color, glm::mat4 modelMatrix, float depth)
{
WaterParticleJob job;
job.Position = position;
job.Color = color;
job.ModelMatrix = modelMatrix;
job.Depth = depth;
m_RendererQueue.Forward.Add(job);
}
private:
std::shared_ptr<ResourceManager> m_ResourceManager;
std::shared_ptr<EventBroker> m_EventBroker;
GUI::Frame* m_FrameStack = nullptr;
std::shared_ptr<Renderer> m_Renderer;
RenderQueueCollection m_RendererQueue;
std::shared_ptr<InputManager> m_InputManager;
std::shared_ptr<World> m_World;
//TODO: Redo
bool m_GameIsRunning = false;
dd::EventRelay<Engine, dd::Events::GameStart> m_EGameStart;
bool OnGameStart(const dd::Events::GameStart &event)
{
m_GameIsRunning = true;
//Todo: Move this
{
dd::Events::PlaySound e;
e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav";
e.IsAmbient = true;
m_EventBroker->Publish(e);
}
{
dd::Events::PlaySound e;
e.FilePath = "Sounds/BGM/water-flowing.wav";
e.Gain = 0.3f;
e.IsAmbient = true;
m_EventBroker->Publish(e);
}
};
double m_LastTime;
};
+1 -1
View File
@@ -119,7 +119,7 @@ public:
template <typename ContextType>
int Process();
int Process(std::string contextTypeName);
void Clear();
void Swap();
void Unsubscribe(BaseEventRelay &relay);
private:
-3
View File
@@ -33,9 +33,6 @@ class PNG : public Image
public:
PNG(std::string path);
~PNG();
private:
};
}
+44 -8
View File
@@ -22,8 +22,9 @@
#include <cstdint>
#include <forward_list>
#include "Texture.h"
#include "Model.h"
#include "Core/Util/Rectangle.h"
#include "Core/Texture.h"
#include "Core/Model.h"
namespace dd
{
@@ -52,8 +53,8 @@ struct ModelJob : RenderJob
unsigned int ShaderID;
unsigned int TextureID;
std::string fileName;
glm::mat4 ProjectionMatrix;
glm::mat4 ViewMatrix;
glm::mat4 ModelMatrix;
GLuint DiffuseTexture;
GLuint NormalTexture;
@@ -90,6 +91,8 @@ struct SpriteJob : RenderJob
unsigned int ShaderID;
unsigned int TextureID;
glm::mat4 ProjectionMatrix;
glm::mat4 ViewMatrix;
glm::mat4 ModelMatrix;
GLuint DiffuseTexture;
GLuint NormalTexture;
@@ -115,6 +118,30 @@ struct PointLightJob : RenderJob
}
};
struct FrameJob : SpriteJob
{
Rectangle Scissor;
Rectangle Viewport;
std::string Name;
void CalculateHash() override
{
Hash = 0;
}
};
struct WaterParticleJob : RenderJob
{
glm::vec3 Position;
glm::vec4 Color;
glm::mat4 ModelMatrix;
void CalculateHash() override
{
Hash = 0;
}
};
class RenderQueue
{
public:
@@ -122,7 +149,8 @@ public:
void Add(T &job)
{
job.CalculateHash();
Jobs.push_front(std::shared_ptr<T>(new T(job)));
Jobs.push_back(std::shared_ptr<T>(new T(job)));
m_Size++;
}
void Sort()
@@ -133,19 +161,24 @@ public:
void Clear()
{
Jobs.clear();
m_Size = 0;
}
std::forward_list<std::shared_ptr<RenderJob>>::const_iterator begin()
int Size() const { return m_Size; }
std::list<std::shared_ptr<RenderJob>>::const_iterator begin()
{
return Jobs.begin();
}
std::forward_list<std::shared_ptr<RenderJob>>::const_iterator end()
std::list<std::shared_ptr<RenderJob>>::const_iterator end()
{
return Jobs.end();
}
std::forward_list<std::shared_ptr<RenderJob>> Jobs;
std::list<std::shared_ptr<RenderJob>> Jobs;
private:
int m_Size = 0;
};
struct RenderQueueCollection
@@ -153,12 +186,14 @@ struct RenderQueueCollection
RenderQueue Deferred;
RenderQueue Forward;
RenderQueue Lights;
RenderQueue GUI;
void Clear()
{
Deferred.Clear();
Forward.Clear();
Lights.Clear();
GUI.Clear();
}
void Sort()
@@ -166,6 +201,7 @@ struct RenderQueueCollection
Deferred.Sort();
Forward.Sort();
Lights.Sort();
GUI.Sort();
}
};
+29 -24
View File
@@ -16,8 +16,8 @@
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Renderer_h__
#define Renderer_h__
#ifndef DD_RENDERER_H__
#define DD_RENDERER_H__
#include "Util/Rectangle.h"
#include "Camera.h"
@@ -30,8 +30,6 @@ namespace dd
class Renderer
{
public:
//Render();
GLFWwindow* Window() const { return m_Window; }
Rectangle Resolution() const { return m_Resolution; }
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
@@ -39,8 +37,6 @@ public:
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
bool VSYNC() const { return m_VSYNC; }
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
//void SetViewport(const Rectangle& viewport) { m_Viewport = viewport; }
//void SetScissor(const Rectangle& scissor) { m_Scissor = scissor; }
const dd::Camera* Camera() const { return m_Camera; }
void SetCamera(const dd::Camera* camera)
{
@@ -50,7 +46,6 @@ public:
m_Camera = camera;
}
}
void Initialize();
void Draw(RenderQueueCollection& rq);
@@ -58,8 +53,6 @@ private:
Rectangle m_Resolution = Rectangle(1280, 720);
bool m_Fullscreen = false;
bool m_VSYNC = false;
//Rectangle m_Viewport;
//Rectangle m_Scissor;
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
const dd::Camera* m_Camera = nullptr;
@@ -67,33 +60,43 @@ private:
std::string m_GLVendor;
GLFWwindow* m_Window = nullptr;
ShaderProgram* m_spDeferred1;
ShaderProgram* m_spDeferred2;
ShaderProgram* m_spDeferred3;
ShaderProgram* m_spForward;
ShaderProgram* m_spScreen;
ShaderProgram* m_SpDeferred1;
ShaderProgram* m_SpDeferred2;
ShaderProgram* m_SpDeferred3;
ShaderProgram* m_SpForward;
ShaderProgram* m_SpScreen;
ShaderProgram* m_SpWater;
ShaderProgram* m_SpWater2;
GLuint m_ScreenQuad = 0;
Model* m_UnitSphere = nullptr;
Model* m_UnitQuad = nullptr;
Texture* m_StandardNormal;
Texture* m_StandardSpecular;
Texture* m_WhiteSphereTexture;
GLuint m_rbDepthBuffer = 0;
GLuint m_fbDeferred1 = 0;
GLuint m_GDiffuse = 0;
GLuint m_GPosition = 0;
GLuint m_GNormal = 0;
GLuint m_GSpecular = 0;
GLuint m_fbDeferred2 = 0;
GLuint m_tLighting = 0;
GLuint m_fbDeferred3 = 0;
GLuint m_tFinal = 0;
GLuint m_RbDepthBuffer = 0; //DepthBuffer Texture
GLuint m_FbDeferred1 = 0; //Framebuffer for first pass
GLuint m_GDiffuse = 0; //Texture for diffuseColors
GLuint m_GPosition = 0; //Texture for positions
GLuint m_GNormal = 0; //Texture for normals
GLuint m_GSpecular = 0; //Texture for specular
GLuint m_FbDeferred2 = 0; //Framebuffer that handles the lighting pass
GLuint m_TLighting = 0; //Texture for the lighting pass
GLuint m_FbDeferred3 = 0; //Frambuffer for handling the last pass.
GLuint m_TFinal = 0; //Final Texture to be printed to screen
GLuint m_Gwater = 0; //Water Color Texture
GLuint m_BWater; //Water blur texture
GLuint m_BWater2; //Water blur texture
GLuint m_FbWater; //Waterpass Framebuffer
GLuint m_FbWaterBlur; //Waterpass Framebuffer
GLuint m_FbWaterBlur2; //Waterpass Framebuffer
GLuint m_CurrentScreenBuffer = 0;
void LoadShaders();
void CreateBuffers();
GLuint CreateQuad();
GLuint CreateWaterParticleVAO(RenderQueue &particles);
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
@@ -101,6 +104,8 @@ private:
void DrawForward(RenderQueue &objects, RenderQueue &lights);
void DrawScene(RenderQueue &objects, ShaderProgram &program);
void DrawLightSpheres(RenderQueue &lights);
void DrawWater(RenderQueue &objects);
void DrawGUI(RenderQueue& rq);
void DebugKeys();
};
+3
View File
@@ -43,6 +43,9 @@ public:
operator GLuint() const { return m_Texture; }
unsigned int Width = 0;
unsigned int Height = 0;
private:
GLuint m_Texture = 0;
};
+8 -7
View File
@@ -44,29 +44,30 @@ struct Rectangle
int Height;
virtual int Left() const { return X; }
void SetLeft(int left)
virtual void SetLeft(int left)
{
Width += X - left;
//Width += X - left;
X = left;
}
virtual int Right() const { return X + Width; }
void SetRight(int right)
virtual void SetRight(int right)
{
Width = right - X;
}
virtual int Top() const { return Y; }
void SetTop(int top)
virtual void SetTop(int top)
{
Height += Y - top;
//Height += Y - top;
Y = top;
}
virtual int Bottom() const { return Y + Height; }
int SetBottom(int bottom)
virtual void SetBottom(int bottom)
{
Height = bottom - Y;
}
Rectangle& operator+=(const Rectangle &rhs) {
Rectangle& operator+=(const Rectangle &rhs)
{
SetLeft(std::min(Left(), rhs.Left()));
SetRight(std::max(Right(), rhs.Right()));
SetTop(std::min(Top(), rhs.Top()));
+147
View File
@@ -0,0 +1,147 @@
#ifndef GUI_BUTTON_H__
#define GUI_BUTTON_H__
#include "GUI/TextureFrame.h"
#include "GUI/EButtonEnter.h"
#include "GUI/EButtonLeave.h"
#include "GUI/EButtonPress.h"
#include "GUI/EButtonRelease.h"
#include "Core/EMouseMove.h"
#include "Core/EMousePress.h"
#include "Core/EMouseRelease.h"
namespace dd
{
namespace GUI
{
class Button : public TextureFrame
{
public:
Button(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &Button::OnMouseMove);
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Button::OnMousePress);
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Button::OnMouseRelease);
}
void SetTextureHover(std::string resourceName)
{
m_TextureHover = resourceName;
}
void SetTextureReleased(std::string resourceName)
{
m_TextureReleased = resourceName;
SetTexture(resourceName);
}
void SetTexturePressed(std::string resourceName)
{
m_TexturePressed = resourceName;
}
void Draw(RenderQueueCollection& rq) override
{
if (m_Texture == nullptr && !m_TextureReleased.empty()) {
SetTexture(m_TextureReleased);
}
TextureFrame::Draw(rq);
}
virtual void OnEnter() { }
virtual void OnLeave() { }
virtual void OnPress() { }
virtual void OnRelease() { }
protected:
bool m_MouseIsOver = false;
bool m_IsDown = false;
virtual bool OnMouseMove(const Events::MouseMove& event)
{
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
if (isOver && !m_MouseIsOver) { // Enter
if (!m_IsDown) {
if (!m_TextureHover.empty()) {
SetTexture(m_TextureHover);
}
}
OnEnter();
Events::ButtonEnter e;
e.FrameName = m_Name;
EventBroker->Publish(e);
} else if (!isOver && m_MouseIsOver) { // Leave
if (!m_IsDown) {
if (!m_TextureReleased.empty()) {
SetTexture(m_TextureReleased);
}
}
OnLeave();
Events::ButtonLeave e;
e.FrameName = m_Name;
EventBroker->Publish(e);
}
m_MouseIsOver = isOver;
return true;
}
virtual bool OnMousePress(const Events::MousePress& event)
{
if (!Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1))) {
return false;
}
if (!m_TexturePressed.empty()) {
SetTexture(m_TexturePressed);
}
m_IsDown = true;
OnPress();
Events::ButtonPress e;
e.FrameName = m_Name;
e.Button = this;
EventBroker->Publish(e);
return true;
}
virtual bool OnMouseRelease(const Events::MouseRelease& event)
{
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
if (!isOver && !m_IsDown) {
return false;
}
if (m_MouseIsOver) {
if (!m_TextureHover.empty()) {
SetTexture(m_TextureHover);
}
} else {
if (!m_TextureReleased.empty()) {
SetTexture(m_TextureReleased);
}
}
m_IsDown = false;
OnRelease();
Events::ButtonRelease e;
e.FrameName = m_Name;
e.Button = this;
EventBroker->Publish(e);
return true;
}
private:
EventRelay<Frame, Events::MouseMove> m_EMouseMove;
EventRelay<Frame, Events::MousePress> m_EMousePress;
EventRelay<Frame, Events::MouseRelease> m_EMouseRelease;
std::string m_TextureHover;
std::string m_TexturePressed;
std::string m_TextureReleased;
};
}
}
#endif
+40
View File
@@ -0,0 +1,40 @@
/*
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_ButtonEnter_h__
#define Events_ButtonEnter_h__
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
/** Thrown on GUI button hover. */
struct ButtonEnter : Event
{
std::string FrameName;
};
}
}
#endif // Events_ButtonEnter_h__
+40
View File
@@ -0,0 +1,40 @@
/*
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_ButtonLeave_h__
#define Events_ButtonLeave_h__
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
/** Thrown on GUI button hover. */
struct ButtonLeave : Event
{
std::string FrameName;
};
}
}
#endif // Events_ButtonLeave_h__
+43
View File
@@ -0,0 +1,43 @@
/*
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_ButtonPress_h__
#define Events_ButtonPress_h__
#include "Core/EventBroker.h"
namespace dd
{
namespace GUI { class Button; }
namespace Events
{
/** Thrown on GUI button press. */
struct ButtonPress : Event
{
std::string FrameName;
GUI::Button* Button;
};
}
}
#endif // Events_ButtonPress_h__
+43
View File
@@ -0,0 +1,43 @@
/*
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_ButtonRelease_h__
#define Events_ButtonRelease_h__
#include "Core/EventBroker.h"
namespace dd
{
namespace GUI { class Button; }
namespace Events
{
/** Thrown on GUI button release. */
struct ButtonRelease : Event
{
std::string FrameName;
GUI::Button* Button;
};
}
}
#endif // Events_ButtonRelease_h__
+45
View File
@@ -0,0 +1,45 @@
/*
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_SliderUpdate_h__
#define Events_SliderUpdate_h__
#include "Core/EventBroker.h"
namespace dd
{
namespace GUI { class Slider; }
namespace Events
{
/** Thrown when GUI slider is moved. */
struct SliderUpdate : Event
{
std::string FrameName;
GUI::Slider* Slider;
float Percentage;
float DeltaPercentage;
};
}
}
#endif // Events_SliderUpdate_h__
+264
View File
@@ -0,0 +1,264 @@
#ifndef GUI_Frame_h__
#define GUI_Frame_h__
#include <memory>
#include <map>
#include "Core/Util/Rectangle.h"
#include "Core/EventBroker.h"
#include "Core/EKeyDown.h"
#include "Core/EKeyUp.h"
#include "Core/ResourceManager.h"
#include "Core/Renderer.h"
#include "Core/RenderQueue.h"
#include "Core/Texture.h"
#include "Input/EInputCommand.h"
namespace dd
{
namespace GUI
{
class Frame : public Rectangle
{
public:
enum class Anchor
{
Left,
Right,
Top,
Bottom
};
static const int BaseWidth = 1280;
static const int BaseHeight = 720;
// Set up a base frame with an event broker
Frame(dd::EventBroker* eventBroker)
: EventBroker(eventBroker)
, BaseFrame(this)
, Rectangle() { }
// Create a frame as a child
Frame(Frame* parent, std::string name)
: m_Name(name)
{
SetParent(parent);
//EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
//EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
//EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
}
~Frame()
{
/*for (auto layer : m_Children)
{
for (auto child : layer.second)
{
delete child.second;
}
}
if (m_Parent)
{
m_Parent->RemoveChild(this);
}*/
}
Frame* Parent() const { return m_Parent; }
void SetParent(Frame* parent)
{
if (parent == nullptr) {
LOG_ERROR("Failed to parent frame \"%s\": Invalid parent", m_Name.c_str());
return;
}
m_Layer = parent->Layer() + 1;
parent->AddChild(this);
m_Parent = parent;
EventBroker = parent->EventBroker;
BaseFrame = parent->BaseFrame;
}
void AddChild(Frame* child)
{
m_Children[child->m_Layer].insert(std::make_pair(child->Name(), child));
if (m_Parent) {
m_Parent->AddChild(child);
}
}
void RemoveChild(Frame* child)
{
auto it = m_Children.find(child->m_Layer);
if (it != m_Children.end()) {
m_Children.erase(it);
}
if (m_Parent) {
m_Parent->RemoveChild(child);
}
}
std::string Name() const { return m_Name; }
void SetName(std::string val) { m_Name = val; }
int Layer() const { return m_Layer; }
bool Hidden() const
{
if (m_Parent)
return m_Parent->Hidden() || m_Hidden;
else
return m_Hidden;
}
bool Visible() const
{
return !Hidden();
}
virtual void Hide() { m_Hidden = true; }
virtual void Show() { m_Hidden = false; }
int Left() const override
{
if (m_Parent)
return m_Parent->Left() + X;
else
return X;
}
void SetLeft(int absLeft) override
{
if (m_Parent) {
X = absLeft - m_Parent->Left();
} else {
X = absLeft;
}
}
int Right() const override
{
return Left() + Width;
}
void SetRight(int absRight) override
{
if (m_Parent) {
X = absRight - Width - m_Parent->Left();
} else {
X = absRight - Width;
}
}
int Top() const override
{
if (m_Parent)
return m_Parent->Top() + Y;
else
return Y;
}
void SetTop(int absTop) override
{
if (m_Parent) {
Y = absTop - m_Parent->Top();
} else {
Y = absTop;
}
}
int Bottom() const override
{
return Top() + Height;
}
void SetBottom(int absBottom) override
{
if (m_Parent) {
Y = absBottom - Height - m_Parent->Top();
} else {
Y = absBottom - Height;
}
}
glm::vec2 Scale()
{
if (m_Parent)
return m_Parent->Scale();
else
return glm::vec2(Width, Height) / glm::vec2(BaseWidth, BaseHeight);
}
Rectangle AbsoluteRectangle()
{
int left = Left();
if (m_Parent)
left = std::max(left, m_Parent->Left());
int top = Top();
if (m_Parent)
top = std::max(top, m_Parent->Top());
int width = Right() - left;
int height = Bottom() - top;
return Rectangle(left, top, width, height);
}
void UpdateLayered(double dt)
{
// Update ourselves
this->Update(dt);
// Update children
for (auto& pairLayer : m_Children) {
auto children = pairLayer.second;
for (auto& pairChild : children) {
auto child = pairChild.second;
child->Update(dt);
}
}
}
virtual void Update(double dt) { }
void DrawLayered(RenderQueueCollection& rq)
{
if (this->Hidden())
return;
// Draw ourselves
this->Draw(rq);
// Draw children
for (auto& pairLayer : m_Children) {
auto children = pairLayer.second;
for (auto& pairChild : children) {
auto child = pairChild.second;
if (child->Hidden())
continue;
child->Draw(rq);
}
}
}
virtual void Draw(RenderQueueCollection& rq) { }
protected:
dd::EventBroker* EventBroker;
Frame* BaseFrame = nullptr;
std::string m_Name = "UIParent";
int m_Layer = 0;
bool m_Hidden = false;
Frame* m_Parent = nullptr;
typedef std::multimap<std::string, Frame*> Children_t; // name -> frame
std::map<int, Children_t> m_Children; // layer -> Children_t
virtual bool OnKeyDown(const Events::KeyDown& event) { return false; }
virtual bool OnKeyUp(const Events::KeyUp& event) { return false; }
virtual bool OnCommand(const Events::InputCommand& event) { return false; }
private:
//EventRelay<Frame, Events::KeyDown> m_EKeyDown;
//EventRelay<Frame, Events::KeyUp> m_EKeyUp;
//EventRelay<Frame, Events::InputCommand> m_EInputCommand;
};
}
}
#endif // GUI_Frame_h__
+94
View File
@@ -0,0 +1,94 @@
#ifndef GUI_NUMBERFRAME_H__
#define GUI_NUMBERFRAME_H__
#include <unordered_map>
#include "GUI/TextureFrame.h"
namespace dd
{
namespace GUI
{
class NumberFrame : public Frame
{
public:
NumberFrame(Frame* parent, std::string name)
: Frame(parent, name)
{
m_CharacterTextures['0'] = "Textures/GUI/Numbers/N0.png";
m_CharacterTextures['1'] = "Textures/GUI/Numbers/N1.png";
m_CharacterTextures['2'] = "Textures/GUI/Numbers/N2.png";
m_CharacterTextures['3'] = "Textures/GUI/Numbers/N3.png";
m_CharacterTextures['4'] = "Textures/GUI/Numbers/N4.png";
m_CharacterTextures['5'] = "Textures/GUI/Numbers/N5.png";
m_CharacterTextures['6'] = "Textures/GUI/Numbers/N6.png";
m_CharacterTextures['7'] = "Textures/GUI/Numbers/N7.png";
m_CharacterTextures['8'] = "Textures/GUI/Numbers/N8.png";
m_CharacterTextures['9'] = "Textures/GUI/Numbers/N9.png";
SetNumber(0);
}
int Number() const { return m_Number; }
void SetNumber(int number)
{
m_Number = number;
// Clear number textures
for (auto& frame : m_NumberFrames) {
frame->SetTexture("");
}
Width = 0;
Height = 0;
std::string digits = std::to_string(number);
int i = 0;
for (char& c : digits) {
// Create number frame if missing
if (i >= m_NumberFrames.size()) {
auto frame = new GUI::TextureFrame(this, "NumberFrameDigit");
if (i > 0) {
frame->SetLeft(m_NumberFrames[i - 1]->Right());
}
frame->DisableScissor();
m_NumberFrames.push_back(frame);
}
// Update value
std::string texture = "Textures/Core/ErrorTexture.png";
if (m_CharacterTextures.find(c) != m_CharacterTextures.end()) {
texture = m_CharacterTextures.at(c);
}
m_NumberFrames[i]->SetTexture(m_CharacterTextures.at(c));
Width += m_NumberFrames[i]->Width;
if (Height < m_NumberFrames[i]->Height) {
Height = m_NumberFrames[i]->Height;
}
i++;
}
}
void SetLeftAlign() { m_LeftAligned = true; }
void SetRightAlign() { m_LeftAligned = false; }
virtual void Update(double dt) override
{
}
private:
int m_Number = 0;
bool m_LeftAligned = true;
std::unordered_map<char, std::string> m_CharacterTextures;
std::deque<TextureFrame*> m_NumberFrames;
};
}
}
#endif
+124
View File
@@ -0,0 +1,124 @@
#ifndef GUI_SLIDER_H__
#define GUI_SLIDER_H__
#include "GUI/TextureFrame.h"
#include "GUI/Button.h"
#include "GUI/EButtonPress.h"
#include "GUI/EButtonRelease.h"
#include "GUI/ESliderUpdate.h"
#include "Core/EMouseMove.h"
namespace dd
{
namespace GUI
{
class Slider : public TextureFrame
{
public:
Slider(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
m_SliderButton = new GUI::Button(this, "SliderButton");
m_SliderButton->DisableScissor();
EVENT_SUBSCRIBE_MEMBER(m_EButtonPress, &Slider::OnButtonPress);
EVENT_SUBSCRIBE_MEMBER(m_EButtonRelease, &Slider::OnButtonRelease);
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &Slider::OnMouseMove);
}
float Percentage() const { return m_Percentage; }
void SetPercentage(const float percentage)
{
m_Percentage = percentage;
m_SliderButton->X = percentage * (Width - m_SliderButton->Width);
}
void SetTextureHover(std::string resourceName)
{
m_SliderButton->SetTextureHover(resourceName);
}
void SetTextureReleased(std::string resourceName)
{
m_SliderButton->SetTextureReleased(resourceName);
}
void SetTexturePressed(std::string resourceName)
{
m_SliderButton->SetTexturePressed(resourceName);
}
void AlignVertically()
{
m_SliderButton->Y = (Height / 2) - (m_SliderButton->Height / 2);
}
~Slider()
{
if (m_SliderButton != nullptr) {
delete m_SliderButton;
m_SliderButton = nullptr;
}
}
virtual void Update(double dt) override
{
}
private:
Button* m_SliderButton = nullptr;
bool m_IsGrabbed = false;
float m_Percentage = 0.f;
EventRelay<Frame, Events::ButtonPress> m_EButtonPress;
EventRelay<Frame, Events::ButtonRelease> m_EButtonRelease;
EventRelay<Frame, Events::MouseMove> m_EMouseMove;
virtual bool OnButtonPress(const Events::ButtonPress& event)
{
if (event.Button == m_SliderButton) {
m_IsGrabbed = true;
}
return true;
}
virtual bool OnButtonRelease(const Events::ButtonRelease& event)
{
if (event.Button == m_SliderButton) {
m_IsGrabbed = false;
}
return true;
}
virtual bool OnMouseMove(const Events::MouseMove& event)
{
if (m_IsGrabbed) {
// Set horizontal position
m_SliderButton->X += event.DeltaX;
if (m_SliderButton->Left() < Left()) {
m_SliderButton->SetLeft(Left());
} else if (m_SliderButton->Right() > Right()) {
m_SliderButton->SetRight(Right());
}
// Update percentage
float newPercentage = m_SliderButton->X / (float)(Width - m_SliderButton->Width);
Events::SliderUpdate e;
e.FrameName = Name();
e.Slider = this;
e.Percentage = newPercentage;
e.DeltaPercentage = newPercentage - m_Percentage;
EventBroker->Publish(e);
m_Percentage = newPercentage;
}
return true;
}
};
}
}
#endif
+111
View File
@@ -0,0 +1,111 @@
#ifndef GUI_TextureFrame_h__
#define GUI_TextureFrame_h__
#include "GUI/Frame.h"
#include "Core/Texture.h"
namespace dd
{
namespace GUI
{
class TextureFrame : public Frame
{
public:
TextureFrame(Frame* parent, std::string name)
: Frame(parent, name) { }
void EnableScissor() { m_ScissorEnabled = true; }
void DisableScissor() { m_ScissorEnabled = false; }
void Draw(RenderQueueCollection& rq) override
{
if (m_Texture == nullptr)
return;
// Main texture
{
FrameJob job;
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
job.Viewport = Rectangle(Left(), Top(), Width, Height);
job.TextureID = m_Texture->ResourceID;
job.DiffuseTexture = *m_Texture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade);
job.Name = Name();
rq.GUI.Add(job);
}
// Texture while fading
if (m_FadeTexture && m_CurrentFade < 1) {
FrameJob job;
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
job.Viewport = Rectangle(Left(), Top(), Width, Height);
job.TextureID = m_FadeTexture->ResourceID;
job.DiffuseTexture = *m_FadeTexture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
job.Name = Name();
rq.GUI.Add(job);
}
}
dd::Texture* Texture() const { return m_Texture; }
void SetTexture(std::string resourceName)
{
if (resourceName.empty()) {
m_Texture = nullptr;
return;
}
m_Texture = ResourceManager::Load<dd::Texture>(resourceName);
if (m_Texture == nullptr) {
m_Texture = ResourceManager::Load<dd::Texture>("Textures/Core/ErrorTexture.png");
}
SizeToTexture();
}
void SizeToTexture()
{
if (m_Texture != nullptr) {
this->Width = m_Texture->Width;
this->Height = m_Texture->Height;
}
}
void FadeToTexture(std::string resourceName, double duration)
{
m_FadeTexture = m_Texture;
SetTexture(resourceName);
m_FadeDuration = duration;
m_CurrentFade = 0.f;
}
void Update(double dt) override
{
if (m_CurrentFade < 1) {
m_CurrentFade += dt / m_FadeDuration;
if (m_CurrentFade > 1) {
m_FadeTexture = nullptr;
m_CurrentFade = 1;
m_FadeDuration = 0;
}
}
}
glm::vec4 Color() const { return m_Color; }
void SetColor(glm::vec4 val) { m_Color = val; }
protected:
bool m_ScissorEnabled = true;
dd::Texture* m_Texture = nullptr;
dd::Texture* m_FadeTexture = nullptr;
glm::vec4 m_Color = glm::vec4(1.f, 1.f, 1.f, 1.f);
float m_FadeDuration = 0.f;
float m_CurrentFade = 1.f;
};
}
}
#endif // GUI_TextureFrame_h__
+70 -4
View File
@@ -5,15 +5,31 @@
#include "Core/World.h"
#include "Core/EventBroker.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/EContact.h"
#include "Rendering/CModel.h"
#include "Rendering/CPointLight.h"
#include "Game/CBall.h"
#include "Game/CPowerUp.h"
#include "Game/CLife.h"
#include "Game/ELifeLost.h"
#include "Game/EComboEvent.h"
#include "Game/EResetBall.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EGameOver.h"
#include "Game/EPause.h"
namespace dd {
namespace dd
{
namespace Systems {
namespace Systems
{
class BallSystem : public System {
class BallSystem : public System
{
public:
BallSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker) { }
@@ -39,11 +55,61 @@ public:
// Called when an entity is removed
void OnEntityRemoved(EntityID entity) override;
private:
EntityID CreateBall();
void CreateLife(int);
EntityID Ball() { return m_Ball; };
void SetBall(const EntityID& ball) { m_Ball = ball; }
float& XMovementMultiplier() { return m_XMovementMultiplier; }
void SetXMovementMultiplier(const float& xMovementMultiplier) { m_XMovementMultiplier = xMovementMultiplier; }
float& EdgeX() { return m_EdgeX; }
void SetEdgeX(const float& edgeX) { m_EdgeX = edgeX; }
float& EdgeY() { return m_EdgeY; }
void SetEdgeY(const float& edgeY) { m_EdgeY = edgeY; }
int& MultiBalls() { return m_MultiBalls; }
void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
int& Lives() { return m_Lives; }
void SetLives(const int& lives) { m_Lives = lives; }
int& PastLives() { return m_PastLives; }
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
bool ReplaceBall() const { return m_ReplaceBall; }
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
bool MultiBall() const { return m_MultiBall; }
void SetMultiBall(const bool& multiBall) { m_MultiBall = multiBall; }
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
private:
float m_XMovementMultiplier = 2.f;
float m_EdgeX = 3.2f;
float m_EdgeY = 5.2f;
int m_MultiBalls = 0;
int m_Lives = 3;
int m_PastLives = 3;
bool m_ReplaceBall = false;
bool m_MultiBall = false;
bool m_Pause = false;
glm::vec3 m_SavedSpeed;
bool m_InitializePause = false;
EntityID m_Ball;
dd::EventRelay<BallSystem, dd::Events::LifeLost> m_ELifeLost;
dd::EventRelay<BallSystem, dd::Events::MultiBallLost> m_EMultiBallLost;
dd::EventRelay<BallSystem, dd::Events::ResetBall> m_EResetBall;
dd::EventRelay<BallSystem, dd::Events::MultiBall> m_EMultiBall;
dd::EventRelay<BallSystem, dd::Events::Pause> m_EPause;
bool OnLifeLost(const dd::Events::LifeLost &event);
bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
bool OnResetBall(const dd::Events::ResetBall &event);
bool OnMultiBall(const dd::Events::MultiBall &event);
bool OnPause(const dd::Events::Pause &event);
};
}
}
#endif
+3
View File
@@ -17,6 +17,9 @@ struct Ball : Component
{
int Number = 0;
float Speed = 5.f;
int Combo = 0;
bool Paused = false;
glm::vec3 SavedSpeed = glm::vec3(0, 0, 0);
};
}
-2
View File
@@ -15,10 +15,8 @@ namespace Components
struct Brick : Component
{
int Points = 10;
int Hits = 1;
int Score = 50;
bool Removed = false;
};
}
+1 -4
View File
@@ -17,12 +17,9 @@ namespace Components
struct Pad : Component
{
int Lives;
int Points;
float SlowdownModifier = 5.f;
float AccelerationSpeed = 40.f;
float MaxSpeed = 20.f;
float MaxSpeed = 5.f;
};
}
+27
View File
@@ -0,0 +1,27 @@
//
// Created by Adniklastrator on 2015-09-29.
//
#ifndef DAYDREAM_ECOMBOEVENT_H
#define DAYDREAM_ECOMBOEVENT_H
#include "Core/Entity.h"
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct ComboEvent : Event
{
EntityID Ball;
int Combo;
};
}
}
#endif //DAYDREAM_ECOMBOEVENT_H
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adam on 2015-09-25.
//
#ifndef EVENTS_EGAMESTART_H__
#define EVENTS_EGAMESTART_H__
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct GameStart : public Event
{
};
}
}
#endif
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Administrator on 2015-09-30.
//
#ifndef DAYDREAM_EHITLAG_H
#define DAYDREAM_EHITLAG_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct HitLag : Event
{
float Time;
std::string Type;
};
}
}
#endif //DAYDREAM_EHITLAG_H
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Adniklastrator on 2015-09-28.
//
#ifndef DAYDREAM_EMULTIBALLLOST_H
#define DAYDREAM_EMULTIBALLLOST_H
#include "Core/EventBroker.h"
#include "Core/Entity.h"
namespace dd
{
namespace Events
{
struct MultiBallLost : Event
{
};
}
}
#endif //DAYDREAM_EMULTIBALLLOST_H
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Adniklastrator on 2015-09-30.
//
#ifndef DAYDREAM_EPAUSE_H
#define DAYDREAM_EPAUSE_H
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct Pause : Event
{
std::string Type;
};
}
}
#endif //DAYDREAM_EPAUSE_H
+42
View File
@@ -0,0 +1,42 @@
#ifndef GUI_FPSCOUNTER_H__
#define GUI_FPSCOUNTER_H__
#include "GUI/Frame.h"
#include "GUI/NumberFrame.h"
namespace dd
{
namespace GUI
{
class FPSCounter : public Frame
{
public:
FPSCounter(Frame* parent, std::string name)
: Frame(parent, name)
{
m_Numbers = new GUI::NumberFrame(this, "FPSCounterNumberFrame");
}
virtual void Update(double dt)
{
m_NumFrames++;
m_Accum += dt;
m_Numbers->SetNumber(1.0/(m_Accum/m_NumFrames));
if (m_NumFrames % 20) {
//LOG_INFO("FPS: %f", 1.0/(m_Accum/m_NumFrames));
}
}
private:
NumberFrame* m_Numbers = nullptr;
double m_Accum = 0.0;
int m_NumFrames = 0;
};
}
}
#endif
+70
View File
@@ -0,0 +1,70 @@
#ifndef GUI_HUD_H__
#define GUI_HUD_H__
#include "GUI/Frame.h"
#include "GUI/TextureFrame.h"
#include "GUI/NumberFrame.h"
#include "Core/EKeyUp.h"
#include "Game/EScoreEvent.h"
#include "Game/FPSCounter.h"
namespace dd
{
namespace GUI
{
class HUD : public Frame
{
public:
HUD(Frame* parent, std::string name)
: Frame(parent, name)
{
Width = parent->Width;
Height = parent->Height;
m_LevelIndicator = new GUI::TextureFrame(this, "HUDLevelIndicator");
m_LevelIndicator->SetTexture("Textures/GUI/HUD/LevelIndicatorBG.png");
m_A1 = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
m_A1->X = 40;
m_A1->SetNumber(1);
m_A2 = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
m_A2->X = 60;
m_A2->SetNumber(1);
//m_A3 = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
//m_A3->X = 80;
//m_A3->SetNumber(123);
m_ScoreIndicator = new GUI::TextureFrame(this, "HUDScoreIndicator");
m_ScoreIndicator->SetTexture("Textures/GUI/HUD/ScoreIndicatorBG.png");
m_ScoreIndicator->SetRight(Right());
m_ScoreNumberFrame = new GUI::NumberFrame(m_ScoreIndicator, "HUDScoreNumberFrame");
m_ScoreNumberFrame->X = 15;
m_ScoreNumberFrame->Y = 21;
//m_FPSCounter = new GUI::FPSCounter(this, "FPSCounter");
EVENT_SUBSCRIBE_MEMBER(m_EScore, &HUD::OnScore);
}
private:
TextureFrame* m_LevelIndicator = nullptr;
TextureFrame* m_ScoreIndicator = nullptr;
NumberFrame* m_A1 = nullptr;
NumberFrame* m_A2 = nullptr;
//NumberFrame* m_A3 = nullptr;
NumberFrame* m_ScoreNumberFrame = nullptr;
FPSCounter* m_FPSCounter = nullptr;
EventRelay<Frame, Events::ScoreEvent> m_EScore;
bool OnScore(const Events::ScoreEvent& event)
{
m_ScoreNumberFrame->SetNumber(m_ScoreNumberFrame->Number() + event.Score);
}
};
}
}
#endif
+91
View File
@@ -0,0 +1,91 @@
//
// Created by Adniklastrator on 2015-09-30.
//
#ifndef DAYDREAM_HITLAGSYSTEM_H
#define DAYDREAM_HITLAGSYSTEM_H
#include "Core/System.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Rendering/CSprite.h"
#include "Rendering/CModel.h"
#include "Game/CBrick.h"
#include "Game/CBall.h"
#include "Game/CLife.h"
#include "Game/CPowerUp.h"
#include "Game/EStageCleared.h"
#include "Game/ELifeLost.h"
#include "Game/EResetBall.h"
#include "Game/EScoreEvent.h"
#include "Game/EComboEvent.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EPause.h"
#include "Game/EHitLag.h"
#include "Game/EGameOver.h"
#include "Game/ECreatePowerUp.h"
#include "Game/EPowerUpTaken.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/CRectangleShape.h"
#include "Physics/ESetImpulse.h"
#include "Physics/EContact.h"
#include "Sound/CCollisionSound.h"
#include "Game/PadSystem.h"
#include <fstream>
#include <iostream>
namespace dd
{
namespace Systems
{
class HitLagSystem : public System
{
public:
HitLagSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker)
{ }
void Initialize() override;
void Update(double dt) override;
void FlipPause();
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
bool HitLag() const { return m_HitLag; }
void SetHitLag(const bool& hitLag) { m_HitLag = hitLag; }
float& HitLagDuration() { return m_HitLagDuration; }
void SetHitLagDuration(const float& hitLagDuration) { m_HitLagDuration = hitLagDuration; }
float& HitLagTimer() { return m_HitLagTimer; }
void SetHitLagTimer(const float& hitLagTimer) { m_HitLagTimer = hitLagTimer; }
std::string& CurrentType() { return m_CurrentType; }
void SetCurrentType(const std::string& currentType) { m_CurrentType = currentType; }
private:
bool m_Pause;
bool m_HitLag;
float m_HitLagDuration;
float m_HitLagTimer;
std::string m_CurrentType;
dd::EventRelay<HitLagSystem, dd::Events::Pause> m_EPause;
dd::EventRelay<HitLagSystem, dd::Events::HitLag> m_EHitLag;
bool OnPause(const dd::Events::Pause &event);
bool OnHitLag(const dd::Events::HitLag &event);
};
}
}
#endif //DAYDREAM_HITLAGSYSTEM_H
+15 -20
View File
@@ -7,6 +7,7 @@
#include "Core/System.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Rendering/CSprite.h"
@@ -19,21 +20,23 @@
#include "Game/ELifeLost.h"
#include "Game/EResetBall.h"
#include "Game/EScoreEvent.h"
#include "Game/EComboEvent.h"
#include "Game/EMultiBall.h"
#include "Game/EMultiBallLost.h"
#include "Game/EPause.h"
#include "Game/EGameOver.h"
#include "Game/ECreatePowerUp.h"
#include "Game/EPowerUpTaken.h"
#include "Game/Bricks/CPowerUpBrick.h"
#include "Physics/CBoxShape.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/CRectangleShape.h"
#include "Physics/ESetImpulse.h"
#include "Physics/EContact.h"
#include "Sound/CCollisionSound.h"
#include "Game/PadSystem.h"
#include <fstream>
#include <iostream>
#include <intrin.h>
namespace dd
{
@@ -62,11 +65,7 @@ public:
void Initialize() override;
void CreateBasicLevel(int, int, glm::vec2, float);
void CreateLife(int);
void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting.
void LoadLevel(char[20]);
void CreateBrick(int, int, glm::vec2, float, int);
void ProcessCollision();
void OnEntityRemoved(EntityID entity);
@@ -79,10 +78,8 @@ public:
void SetRestarting(const bool& restarting) { m_Restarting = restarting; }
bool Initialized() const { return m_Initialized; }
void SetInitialized(const bool& initialized) { m_Initialized = initialized; }
int& Lives() { return m_Lives; }
void SetLives(const int& lives) { m_Lives = lives; }
int& PastLives() { return m_PastLives; }
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
int& MultiBalls() { return m_MultiBalls; }
void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; }
int& PowerUps() { return m_PowerUps; }
@@ -100,16 +97,13 @@ public:
glm::vec2& SpaceBetweenBricks() { return m_SpaceBetweenBricks; }
void SetSpaceBetweenBricks(const glm::vec2& spaceBetweenBricks) { m_SpaceBetweenBricks = spaceBetweenBricks; }
float& EdgeX() { return m_EdgeX; }
void SetEdgeX(const float& edgeX) { m_EdgeX = edgeX; }
float& EdgeY() { return m_EdgeY; }
void SetEdgeY(const float& edgeY) { m_EdgeY = edgeY; }
float& NotResettingTheStage() { return m_NotResettingTheStage; }
void SetNotResettingTheStage(const float& notResettingTheStage) { m_NotResettingTheStage = notResettingTheStage; }
private:
bool m_Restarting = false;
bool m_Initialized = false;
int m_Lives = 3;
int m_PastLives = 3;
bool m_Pause = false;
int m_MultiBalls = 0;
int m_PowerUps = 0;
int m_Score = 0;
@@ -118,24 +112,25 @@ private:
int m_Lines = 7;
float m_SpaceToEdge = 0.25f;
glm::vec2 m_SpaceBetweenBricks = glm::vec2(1, 0.4);
float m_EdgeX = 3.2f;
float m_EdgeY = 5.2f;
float m_NotResettingTheStage = 5.f;
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<LevelSystem, dd::Events::LifeLost> m_ELifeLost;
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
dd::EventRelay<LevelSystem, dd::Events::MultiBall> m_EMultiBall;
dd::EventRelay<LevelSystem, dd::Events::MultiBallLost> m_EMultiBallLost;
dd::EventRelay<LevelSystem, dd::Events::CreatePowerUp> m_ECreatePowerUp;
dd::EventRelay<LevelSystem, dd::Events::PowerUpTaken> m_EPowerUpTaken;
dd::EventRelay<LevelSystem, dd::Events::StageCleared> m_EStageCleared;
dd::EventRelay<LevelSystem, dd::Events::Pause> m_EPause;
bool OnContact(const dd::Events::Contact &event);
bool OnLifeLost(const dd::Events::LifeLost &event);
bool OnScoreEvent(const dd::Events::ScoreEvent &event);
bool OnMultiBall(const dd::Events::MultiBall &event);
bool OnMultiBallLost(const dd::Events::MultiBallLost &event);
bool OnCreatePowerUp(const dd::Events::CreatePowerUp &event);
bool OnPowerUpTaken(const dd::Events::PowerUpTaken &event);
bool OnStageCleared(const dd::Events::StageCleared &event);
bool OnPause(const dd::Events::Pause &event);
};
}
+59
View File
@@ -0,0 +1,59 @@
#ifndef GUI_MAINMENU_H__
#define GUI_MAINMENU_H__
#include "GUI/TextureFrame.h"
#include "Game/MainMenuMain.h"
#include "Game/MainMenuOptions.h"
#include "Core/EKeyUp.h"
namespace dd
{
namespace GUI
{
class MainMenu : public TextureFrame
{
public:
MainMenu(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
SetTexture("Textures/GUI/Menu/Background.png");
Width = 675;
Height = 1080;
m_LeftBanner = new GUI::TextureFrame(this, "MainMenuLeftBanner");
m_LeftBanner->SetTexture("Textures/GUI/Menu/Left.png");
m_LeftBanner->Width = 231;
m_LeftBanner->Height = 1080;
m_MainMenuMain = new GUI::MainMenuMain(this, "MainMenuMain");
m_MainMenuMain->SetLeft(m_LeftBanner->Right());
m_MainMenuMain->SetTop(60);
m_MainMenuOptions = new GUI::MainMenuOptions(this, "MainMenuOptions");
m_MainMenuOptions->SetLeft(m_LeftBanner->Right());
m_MainMenuOptions->SetTop(m_MainMenuMain->Bottom());
//EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &MainMenu::OnKeyUp);
}
private:
TextureFrame* m_LeftBanner;
MainMenuMain* m_MainMenuMain;
MainMenuOptions* m_MainMenuOptions;
//EventRelay<Frame, Events::KeyUp> m_EKeyUp;
bool OnKeyUp(const Events::KeyUp& event)
{
if (event.KeyCode == GLFW_KEY_ESCAPE) {
Show();
}
return true;
}
};
}
}
#endif
+72
View File
@@ -0,0 +1,72 @@
#ifndef GUI_MAINMENUMAIN_H__
#define GUI_MAINMENUMAIN_H__
#include "GUI/TextureFrame.h"
#include "GUI/Button.h"
#include "Game/EGameStart.h"
#include "Game/HUD.h"
namespace dd
{
namespace GUI
{
class MainMenuMain : public TextureFrame
{
public:
MainMenuMain(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
Width = 409;
Height = 543;
m_Title = new GUI::TextureFrame(this, "MainMenuMainTitle");
m_Title->SetTexture("Textures/GUI/Menu/MainTitle.png");
m_SquidoutButton = new GUI::Button(this, "MainMenuMainSquidoutButton");
m_SquidoutButton->SetTop(m_Title->Bottom());
m_SquidoutButton->SetTextureReleased("Textures/GUI/Menu/MainSquidout.png");
m_SquidoutButton->SetTextureHover("Textures/GUI/Menu/MainSquidoutHover.png");
m_SquidoutButton->SetTexturePressed("Textures/GUI/Menu/MainSquidoutClick.png");
m_SquidoutButton->SizeToTexture();
m_TimeAttackButton = new GUI::Button(this, "MainMenuMainTimeAttackButton");
m_TimeAttackButton->SetTop(m_SquidoutButton->Bottom());
m_TimeAttackButton->SetTextureReleased("Textures/GUI/Menu/MainTimeAttack.png");
m_TimeAttackButton->SetTextureHover("Textures/GUI/Menu/MainTimeAttackHover.png");
m_TimeAttackButton->SetTexturePressed("Textures/GUI/Menu/MainTimeAttackClick.png");
m_TimeAttackButton->SizeToTexture();
m_OptionsButton = new GUI::Button(this, "MainMenuMainOptionsButton");
m_OptionsButton->SetTop(m_TimeAttackButton->Bottom());
m_OptionsButton->SetTextureReleased("Textures/GUI/Menu/MainOptions.png");
m_OptionsButton->SetTextureHover("Textures/GUI/Menu/MainOptionsHover.png");
m_OptionsButton->SetTexturePressed("Textures/GUI/Menu/MainOptionsClick.png");
m_OptionsButton->SizeToTexture();
EVENT_SUBSCRIBE_MEMBER(m_EButtonRelease, &MainMenuMain::OnButtonRelease);
}
private:
TextureFrame* m_Title;
Button* m_SquidoutButton;
Button* m_TimeAttackButton;
Button* m_OptionsButton;
EventRelay<Frame, Events::ButtonRelease> m_EButtonRelease;
virtual bool OnButtonRelease(const Events::ButtonRelease& event)
{
if (event.Button == m_SquidoutButton) {
Events::GameStart e;
EventBroker->Publish(e);
m_Parent->Hide();
auto hud = new GUI::HUD(BaseFrame, "HUD");
}
return true;
}
};
}
}
#endif
+82
View File
@@ -0,0 +1,82 @@
#ifndef GUI_MAINMENUOPTIONS_H__
#define GUI_MAINMENUOPTIONS_H__
#include "GUI/TextureFrame.h"
#include "GUI/Button.h"
#include "GUI/Slider.h"
#include "GUI/ESliderUpdate.h"
#include "Sound/EMasterVolume.h"
namespace dd
{
namespace GUI
{
class MainMenuOptions : public TextureFrame
{
public:
MainMenuOptions(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
Width = 409;
Height = 1080;
m_Title = new GUI::TextureFrame(this, "MainMenuOptionsTitle");
m_Title->SetTexture("Textures/GUI/Menu/OptionsTitle.png");
m_TitleSFX = new GUI::TextureFrame(this, "MainMenuOptionsSFXTitle");
m_TitleSFX->SetTop(m_Title->Bottom() + 20);
m_TitleSFX->SetTexture("Textures/GUI/Menu/OptionsSFXTitle.png");
m_SFXSlider = new GUI::Slider(this, "MainMenuOptionsSFXSlider");
m_SFXSlider->X = 66;
m_SFXSlider->SetTop(m_TitleSFX->Bottom() + 10);
m_SFXSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
m_SFXSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
m_SFXSlider->AlignVertically();
m_SFXSlider->SetPercentage(1.f);
m_TitleBGM = new GUI::TextureFrame(this, "MainMenuOptionsBGMTitle");
m_TitleBGM->SetTop(m_SFXSlider->Bottom() + 20);
m_TitleBGM->SetTexture("Textures/GUI/Menu/OptionsBGMTitle.png");
m_BGMSlider = new GUI::Slider(this, "MainMenuOptionsBGMSlider");
m_BGMSlider->X = 66;
m_BGMSlider->SetTop(m_TitleBGM->Bottom() + 10);
m_BGMSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
m_BGMSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
m_BGMSlider->AlignVertically();
m_BGMSlider->SetPercentage(1.f);
EVENT_SUBSCRIBE_MEMBER(m_ESliderUpdate, &MainMenuOptions::OnSliderUpdate);
}
private:
TextureFrame* m_Title = nullptr;
TextureFrame* m_TitleSFX = nullptr;
Slider* m_SFXSlider = nullptr;
Slider* m_BGMSlider = nullptr;
TextureFrame* m_TitleBGM = nullptr;
EventRelay<Frame, Events::SliderUpdate> m_ESliderUpdate;
bool OnSliderUpdate(const Events::SliderUpdate& event)
{
if (event.Slider == m_SFXSlider) {
Events::MasterVolume e;
e.IsAmbient = false;
e.Gain = event.Percentage;
EventBroker->Publish(e);
}
if (event.Slider == m_BGMSlider) {
Events::MasterVolume e;
e.IsAmbient = true;
e.Gain = event.Percentage;
EventBroker->Publish(e);
}
return true;
}
};
}
}
#endif
+19 -15
View File
@@ -9,12 +9,13 @@
#include "Core/System.h"
#include "Core/Component.h"
#include "Core/CTransform.h"
#include "Core/CTemplate.h"
#include "Core/EventBroker.h"
#include "Core/EKeyDown.h"
#include "Core/EKeyUp.h"
#include "Input/EBindKey.h"
#include "Physics/EContact.h"
#include "Physics/CBoxShape.h"
#include "Physics/CRectangleShape.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/ESetImpulse.h"
@@ -27,6 +28,8 @@
#include "Game/EMultiBall.h"
#include "Game/EPowerUpTaken.h"
#include "Game/EStageCleared.h"
#include "Game/EPause.h"
#include "Game/EHitLag.h"
namespace dd
@@ -45,8 +48,6 @@ public:
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
EntityID CreateBall();
EntityID& Entity() { return m_Entity; }
void SetEntity(const EntityID& ent) { m_Entity = ent; }
glm::vec3 Acceleration() const { return m_Acceleration; }
@@ -56,39 +57,42 @@ public:
void SetLeft(const bool& left) { m_Left = left; }
bool Right() const { return m_Right; }
void SetRight(const bool& right) { m_Right = right; }
bool ReplaceBall() const { return m_ReplaceBall; }
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
bool MultiBall() const { return m_MultiBall; }
void SetMultiBall(const bool& multiBall) { m_MultiBall = multiBall; }
float Edge() const { return m_Edge; }
void SetEdge(const float& edge) { m_Edge = edge; }
Components::Transform* Transform() const { return m_Transform; }
void SetTransform(Components::Transform* transform) { m_Transform = transform; }
Components::Pad* Pad() const { return m_Pad; }
void SetPad(Components::Pad* pad) { m_Pad = pad; }
bool IsPaused() const { return m_Pause; }
void SetPause(const bool& pause) { m_Pause = pause; }
private:
EntityID m_Entity = 0;
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
bool m_Left = false, m_Right = false, m_ReplaceBall = false, m_MultiBall = false;
Components::Transform* m_Transform;
Components::Pad* m_Pad;
bool m_Left = false;
bool m_Right = false;
float m_Edge = 2.8f;
bool m_MultiBall = false;
Components::Transform* m_Transform = nullptr;
Components::Pad* m_Pad = nullptr;
bool m_Pause = false;
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContactPowerUp;
dd::EventRelay<PadSystem, dd::Events::ResetBall> m_EResetBall;
dd::EventRelay<PadSystem, dd::Events::MultiBall> m_EMultiBall;
dd::EventRelay<PadSystem, dd::Events::StageCleared> m_EStageCleared;
dd::EventRelay<PadSystem, dd::Events::Pause> m_EPause;
bool OnKeyDown(const dd::Events::KeyDown &event);
bool OnKeyUp(const dd::Events::KeyUp &event);
bool OnContact(const dd::Events::Contact &event);
bool OnContactPowerUp(const dd::Events::Contact &event);
bool OnResetBall(const dd::Events::ResetBall &event);
bool OnMultiBall(const dd::Events::MultiBall &event);
bool OnStageCleared(const dd::Events::StageCleared &event);
bool OnPause(const dd::Events::Pause &event);
class PadSteeringInputController;
std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers;
+65
View File
@@ -0,0 +1,65 @@
#ifndef COMPONENTS_PARTICLE_H__
#define COMPONENTS_PARTICLE_H__
#include "Core/Component.h"
namespace dd {
namespace ParticleFlags {
enum Type {
waterParticle = 0,
zombieParticle = 1 << 1,
wallParticle = 1 << 2,
springParticle = 1 << 3,
elasticParticle = 1 << 4,
viscousParticle = 1 << 5,
powderParticle = 1 << 6,
tensileParticle = 1 << 7,
colorMixingParticle = 1 << 8,
destructionListenerParticle = 1 << 9,
barrierParticle = 1 << 10,
staticPressureParticle = 1 << 11,
reactiveParticle = 1 << 12,
repulsiveParticle = 1 << 13,
fixtureContactListenerParticle = 1 << 14,
particleContactListenerParticle = 1 << 15,
fixtureContactFilterParticle = 1 << 16,
particleContactFilterParticle = 1 << 17
};
}
namespace Components
{
struct Particle : public Component
{
float Radius = 0.5f;
float LifeTime = 5.0f;
ParticleFlags::Type Flags =
ParticleFlags::Type::waterParticle |
ParticleFlags::Type::zombieParticle |
ParticleFlags::Type::wallParticle |
ParticleFlags::Type::springParticle |
ParticleFlags::Type::elasticParticle |
ParticleFlags::Type::viscousParticle |
ParticleFlags::Type::powderParticle |
ParticleFlags::Type::tensileParticle |
ParticleFlags::Type::colorMixingParticle |
ParticleFlags::Type::destructionListenerParticle |
ParticleFlags::Type::barrierParticle |
ParticleFlags::Type::staticPressureParticle |
ParticleFlags::Type::reactiveParticle |
ParticleFlags::Type::repulsiveParticle |
ParticleFlags::Type::fixtureContactListenerParticle |
ParticleFlags::Type::particleContactListenerParticle |
ParticleFlags::Type::fixtureContactFilterParticle |
ParticleFlags::Type::particleContactFilterParticle;
};
}
}
#endif
+25
View File
@@ -0,0 +1,25 @@
#ifndef COMPONENTS_PARTICLEEMITTER_H__
#define COMPONENTS_PARTICLEEMITTER_H__
#include "Core/Component.h"
namespace dd
{
namespace Components
{
struct ParticleEmitter : public Component
{
int Amount = 10.f;
float InitialSpeed = 1.f;
double SpawnRate = 1.f;
double TimeSinceLastSpawn = 0;
//ParticleSystem variables
float GravityScale = 1.0f;
};
}
}
#endif
+25 -2
View File
@@ -4,17 +4,40 @@
namespace dd
{
namespace CollisionLayer
{
enum Type
{
Pad = 1 << 0,
Ball = 1 << 1,
Brick = 1 << 2,
Water = 1 << 3,
PowerUp = 1 << 4,
Other = 1 << 5,
Wall = 1 << 6
};
}
namespace Components
{
struct Physics: public Component
{
//idk if anything should be here :)
bool Static = true;
bool Calculate = false;
float GravityScale = 0.f;
CollisionLayer::Type Category = CollisionLayer::Type::Other;
CollisionLayer::Type Mask =
CollisionLayer::Type::Pad |
CollisionLayer::Type::Ball |
CollisionLayer::Type::Brick |
CollisionLayer::Type::Water |
CollisionLayer::Type::PowerUp |
CollisionLayer::Type::Wall |
CollisionLayer::Type::Other;
};
}
}
#endif //DAYDREAM_CPHYSICS_H
+19
View File
@@ -0,0 +1,19 @@
#ifndef CWATERVOLUME_H
#define CWATERVOLUME_H
#include "Core/Component.h"
namespace dd
{
namespace Components
{
struct WaterVolume : public Component
{
float Radius;
};
}
}
#endif
+70 -66
View File
@@ -3,19 +3,33 @@
#include <unordered_map>
#include <Box2D/Box2D.h>
#include "Core/System.h"
#include "Core/World.h"
#include "Physics/CBoxShape.h"
#include "Core/EventBroker.h"
#include "Core/CTemplate.h"
#include "Physics/CRectangleShape.h"
#include "Physics/CCircleShape.h"
#include "Physics/CPhysics.h"
#include <Box2D/Box2D.h>
#include "Physics/CWaterVolume.h"
#include "Core/CTransform.h"
#include "Transform/TransformSystem.h"
#include "CRectangleShape.h"
#include "Physics/CPhysics.h"
#include "Physics/EContact.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CParticle.h"
#include "Physics/CCircleShape.h"
#include "Core/EventBroker.h"
#include "Physics/CParticleEmitter.h"
#include "Game/EPause.h"
#include "Game/CPad.h"
#include "Game/CPad.h"
#include "Game/CBall.h"
#include "Transform/TransformSystem.h"
#include "Rendering/CSprite.h"
#include "Core/CTemplate.h"
namespace dd
{
@@ -23,54 +37,75 @@ namespace dd
namespace Systems
{
class PhysicsSystem : public System
{
friend class ContractListener;
public:
PhysicsSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker) {}
: System(world, eventBroker) { }
~PhysicsSystem();
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &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:
b2Vec2 m_Gravity;
b2World* m_PhysicsWorld;
float m_TimeStep;
float m_Accumulator;
int m_VelocityIterations, m_PositionIterations;
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
void CreateBody(EntityID entity);
struct Impulse
{
b2Body* Body;
b2Vec2 Impulse;
b2Vec2 Point;
};
bool m_Pause = false;
b2Vec2 m_Gravity = b2Vec2(0.f, -9.82f);
b2World* m_PhysicsWorld = nullptr;
float m_TimeStep = 1.f/60.f;
float m_Accumulator = 0.f;
int m_VelocityIterations = 6;
int m_PositionIterations = 2;
std::vector<b2ParticleSystem*> m_ParticleSystem;
std::vector<b2ParticleGroup*> t_ParticleGroup;
std::vector<std::unordered_map<EntityID, const b2ParticleHandle*>> m_EntitiesToParticleHandle;
std::vector<std::unordered_map<const b2ParticleHandle*, EntityID>> m_ParticleHandleToEntities;
std::unordered_map<EntityID, b2Body*> m_EntitiesToBodies;
std::unordered_map<b2Body*, EntityID> m_BodiesToEntities;
void CreateBody(EntityID entity);
void SyncEntitiesWithBodies();
void SyncBodiesWithEntities();
void InitializeWater();
void CreateParticleGroup(EntityID entity);
b2ParticleSystem* CreateParticleSystem(float radius, float gravityScale);
void CreateParticleEmitter(EntityID entity);
void UpdateParticleEmitters(double dt); //TODO: Remove them and particles if needed.
EventRelay<PhysicsSystem, Events::SetImpulse> m_SetImpulse;
bool SetImpulse(const Events::SetImpulse &event);
dd::EventRelay<PhysicsSystem, dd::Events::Pause> m_EPause;
bool OnPause(const dd::Events::Pause &event);
//TODO: Fill struct with info needed.
struct ParticleEmitter
{
std::vector<b2ParticleSystem*> ParticleSystem;
std::vector<EntityID> ParticleEmitter;
std::vector<EntityID> ParticleTemplate;
};
ParticleEmitter m_ParticleEmitters;
std::list<Impulse> m_Impulses;
@@ -81,42 +116,10 @@ private:
ContactListener(PhysicsSystem* physicsSystem)
: m_PhysicsSystem(physicsSystem) { }
void BeginContact(b2Contact* contact)
{
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
Events::Contact e;
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)
{
}
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
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 BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
private:
PhysicsSystem* m_PhysicsSystem;
@@ -126,6 +129,7 @@ private:
};
}
}
#endif //DAYDREAM_PHYSICSSYSTEM_H
#endif
+1 -7
View File
@@ -1,7 +1,3 @@
//
// Created by Adam on 2015-09-17.
//
#ifndef COMPONENTS_CCOLLISIONSOUND_H__
#define COMPONENTS_CCOLLISIONSOUND_H__
@@ -9,17 +5,15 @@
namespace dd
{
namespace Components
{
struct CollisionSound : public Component
{
std::string filePath;
std::string FilePath;
};
}
}
#endif
+21
View File
@@ -0,0 +1,21 @@
#ifndef EVENTS_EMASTERVOLUME_H__
#define EVENTS_EMASTERVOLUME_H__
#include "Core/EventBroker.h"
namespace dd
{
namespace Events
{
struct MasterVolume : public Event
{
float Gain = 1;
//To determine what channel group to apply the change to.
bool IsAmbient = false;
};
}
}
#endif
+6 -8
View File
@@ -1,24 +1,22 @@
#ifndef Events_PlaySFX_h__
#define Events_PlaySFX_h__
#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;
std::string FilePath;
float Gain = 1.f;
float Pitch = 1.f;
bool IsAmbient = false;
};
}
}
#endif
+1 -5
View File
@@ -8,16 +8,12 @@ namespace dd
namespace Events
{
struct StopSound : public Event
{
std::string path;
std::string FilePath;
};
}
}
#endif
+9 -5
View File
@@ -12,27 +12,31 @@ namespace dd
class Sound : public Resource
{
friend class ResourceManager;
public:
ALuint Buffer() { return m_Buffer; };
std::string Path() { return m_Path; };
float Gain() { return m_Gain; };
void SetGain(const float Gain) { m_Gain = Gain; };
private:
Sound(std::string path);
float m_Gain = 1;
ALuint m_Buffer;
std::string m_Path;
//File-info
char m_Type[4];
unsigned long m_Size, m_ChunkSize;
short m_FormatType, m_Channels;
unsigned long m_SampleRate, m_AvgBytesPerSec;
short m_BytesPerSample, m_BitsPerSample;
unsigned long m_DataSize;
unsigned int m_DataSize;
std::map<std::string, ALuint> m_BufferCache;
ALuint LoadFile(std::string path);
ALuint m_Buffer;
std::string m_Path;
};
}
#endif
+22 -19
View File
@@ -1,57 +1,60 @@
#ifndef DAYDREAM_SOUND_H
#define DAYDREAM_SOUND_H
#ifndef SYSTEMS_SOUNDSYSTEM_H__
#define SYSTEMS_SOUNDSYSTEM_H__
#include "AL/al.h"
#include "AL/alc.h"
#include "Core/System.h"
#include "Core/World.h"
#include "Core/EventBroker.h"
#include "Core/ResourceManager.h"
#include "Sound.h"
#include "Sound/EPlaySound.h"
#include "Sound/EStopSound.h"
#include "Sound/EMasterVolume.h"
#include "Sound/CCollisionSound.h"
#include "Physics/EContact.h"
#include "Game/CBall.h"
#include "Game/CBrick.h"
#include "Game/CPad.h"
#include "Sound/CCollisionSound.h"
#include "Core/ResourceManager.h"
namespace dd
{
namespace Systems
{
class SoundSystem : public System {
public:
SoundSystem(World *world, std::shared_ptr<dd::EventBroker> eventBroker)
: System(world, eventBroker) { }
~SoundSystem();
void Initialize() override;
void Update(double dt) override;
private:
float m_BGMMasterVolume = 1.f;
float m_SFXMasterVolume = 1.f;
std::map<ALuint, Sound*> m_BGMSourcesToBuffers;
std::map<ALuint, Sound*> m_SFXSourcesToBuffers;
ALCdevice* m_Device = nullptr;
//Events
dd::EventRelay<SoundSystem, dd::Events::PlaySound> m_EPlaySFX;
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<SoundSystem, dd::Events::StopSound> m_EStopSound;
bool OnPlaySound(const dd::Events::PlaySound &event);
//On contact: play the sound given in the CCOllisionSound.
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
bool OnContact(const dd::Events::Contact &event);
dd::EventRelay<SoundSystem, dd::Events::StopSound> m_EStopSound;
bool OnStopSound(const dd::Events::StopSound &event);
dd::EventRelay<SoundSystem, dd::Events::MasterVolume> m_EMasterVolume;
bool OnMasterVolume(const dd::Events::MasterVolume &event);
ALuint CreateSource();
std::map<ALuint, Sound*> m_SourcesToBuffers;
ALCdevice* m_Device;
//Temp
};
}
}
#endif //DAYDREAM_SOUND_H
#endif
+10 -2
View File
@@ -79,6 +79,12 @@ file(GLOB SOURCE_FILES_Sound
)
source_group(Sound FILES ${SOURCE_FILES_Sound})
file(GLOB SOURCE_FILES_GUI
"${INCLUDE_PATH}/GUI/*.h"
"GUI/*.cpp"
)
source_group(GUI FILES ${SOURCE_FILES_GUI})
set(SOURCE_FILES
${SOURCE_FILES_Core}
${SOURCE_FILES_Core_Util}
@@ -87,11 +93,13 @@ set(SOURCE_FILES
${SOURCE_FILES_Transform}
${SOURCE_FILES_Physics}
${SOURCE_FILES_Game}
${SOURCE_FILES_Sound} ../../include/Game/EGameOver.h ../../include/Game/Bricks/CPowerUpBrick.h ../../include/Game/CPowerUp.h ../../include/Game/ECreatePowerUp.h ../../include/Game/EPowerUpTaken.h)
${SOURCE_FILES_Sound}
${SOURCE_FILES_GUI})
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(STATIC_LIBRARY_FLAGS "${STATIC_LIBRARY_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
set(STATIC_LIBRARY_FLAGS "${STATIC_LIBRARY_FLAGS}")
endif()
add_library(game ${SOURCE_FILES})
-38
View File
@@ -1,38 +0,0 @@
project(game)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLFW REQUIRED)
find_package(Boost REQUIRED)
find_package(assimp REQUIRED)
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
include_directories(
${CMAKE_SOURCE_DIR}/include/dd
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS}
${GLFW_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${assimp_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
)
set(SOURCE_FILES
main.cpp
)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
add_executable(game ${SOURCE_FILES})
target_link_libraries(game
daydream
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${GLFW_LIBRARIES}
${Boost_LIBRARIES}
${assimp_LIBRARIES}
${PNG_LIBRARIES}
)
+4 -3
View File
@@ -68,9 +68,10 @@ int dd::EventBroker::Process(std::string contextTypeName)
std::shared_ptr<Event> event = pair.second;
auto itpair = relays.equal_range(eventTypeName);
for (auto it2 = itpair.first; it2 != itpair.second; ++it2)
for (auto it2 = itpair.first; it2 != itpair.second; it2++)
{
auto relay = it2->second;
std::string name = it2->first;
BaseEventRelay* relay = it2->second;
relay->Receive(event);
eventsProcessed++;
}
@@ -79,7 +80,7 @@ int dd::EventBroker::Process(std::string contextTypeName)
return eventsProcessed;
}
void dd::EventBroker::Clear()
void dd::EventBroker::Swap()
{
std::swap(m_EventQueueRead, m_EventQueueWrite);
m_EventQueueWrite->clear();
+3 -3
View File
@@ -263,7 +263,7 @@ void dd::OBJ::ParseMaterial()
ParseColorMap(currentLine, ss, prefix, arg, colorMap);
}
// HACK: Should we really have to specify the full path here?
// HACK: Should we really have to specify the full FilePath here?
colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string();
currentMaterial->DiffuseTexture = colorMap;
continue;
@@ -280,7 +280,7 @@ void dd::OBJ::ParseMaterial()
ParseColorMap(currentLine, ss, prefix, arg, colorMap);
}
// HACK: Should we really have to specify the full path here?
// HACK: Should we really have to specify the full FilePath here?
colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string();
currentMaterial->SpecularMap = colorMap;
continue;
@@ -297,7 +297,7 @@ void dd::OBJ::ParseMaterial()
ParseBumpMap(currentLine, ss, prefix, arg, bumpMap);
}
// HACK: Should we really have to specify the full path here?
// HACK: Should we really have to specify the full FilePath here?
bumpMap.FileName = (m_MaterialPath.branch_path() / bumpMap.FileName).string();
currentMaterial->NormalMap = bumpMap;
continue;
+283 -60
View File
@@ -70,7 +70,7 @@ void dd::Renderer::Initialize()
LoadShaders();
CreateBuffers();
m_CurrentScreenBuffer = m_tFinal;
m_CurrentScreenBuffer = m_TFinal;
}
void dd::Renderer::LoadShaders()
{
@@ -79,45 +79,53 @@ void dd::Renderer::LoadShaders()
*/
// Pass #1: Fill G-buffers
m_spDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/1/");
m_spDeferred1->BindFragDataLocation(0, "GDiffuse");
m_spDeferred1->BindFragDataLocation(1, "GPosition");
m_spDeferred1->BindFragDataLocation(2, "GNormal");
m_spDeferred1->BindFragDataLocation(3, "GSpecular");
m_spDeferred1->Link();
m_SpDeferred1 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/1/");
m_SpDeferred1->BindFragDataLocation(0, "GDiffuse");
m_SpDeferred1->BindFragDataLocation(1, "GPosition");
m_SpDeferred1->BindFragDataLocation(2, "GNormal");
m_SpDeferred1->BindFragDataLocation(3, "GSpecular");
m_SpDeferred1->Link();
// Pass #2: Lighting
m_spDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/2/");
m_SpDeferred2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/2/");
//glBindFragDataLocation(m_SPDeferred2, 0, "FragmentLighting");
m_spDeferred2->Link();
m_SpDeferred2->Link();
//Water Pass
m_SpWater = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water/");
m_SpWater->Link();
m_SpWater2 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/water2/");
m_SpWater2->Link();
// Pass #3: Combining into final image
m_spDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
m_spDeferred3->Link();
m_SpDeferred3 = ResourceManager::Load<ShaderProgram>("Shaders/Deferred/3/");
m_SpDeferred3->Link();
/*
Forward rendering
*/
m_spForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
m_spForward->Link();
m_SpForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
m_SpForward->Link();
/*
Screen draw
*/
m_spScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
m_spScreen->Link();
m_SpScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
m_SpScreen->Link();
}
void dd::Renderer::CreateBuffers()
{
//TODO: Make the most common cases of texture create and FBO create into a function so it's not so cluttered in here.
m_ScreenQuad = CreateQuad();
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
m_StandardNormal = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
m_StandardSpecular = ResourceManager::Load<Texture>("Textures/Core/NeutralSpecularMap.png");
m_WhiteSphereTexture = ResourceManager::Load<Texture>("Textures/Test/Water.png");
glGenRenderbuffers(1, &m_rbDepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_rbDepthBuffer);
glGenRenderbuffers(1, &m_RbDepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_RbDepthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Resolution.Width, m_Resolution.Height);
// Generate G-buffer textures
@@ -149,11 +157,18 @@ void dd::Renderer::CreateBuffers()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glGenTextures(1, &m_Gwater);
glBindTexture(GL_TEXTURE_2D, m_Gwater);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// Create first pass framebuffer
glGenFramebuffers(1, &m_fbDeferred1);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_rbDepthBuffer);
glGenFramebuffers(1, &m_FbDeferred1);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RbDepthBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_GDiffuse, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_GPosition, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_GNormal, 0);
@@ -161,13 +176,13 @@ void dd::Renderer::CreateBuffers()
GLenum firstPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, firstPassDrawBuffers);
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
LOG_ERROR("m_fbDeferred1 incomplete: 0x%x\n", fbStatus);
LOG_ERROR("m_FbDeferred1 incomplete: 0x%x\n", fbStatus);
exit(EXIT_FAILURE);
}
// Generate lighting texture
glGenTextures(1, &m_tLighting);
glBindTexture(GL_TEXTURE_2D, m_tLighting);
glGenTextures(1, &m_TLighting);
glBindTexture(GL_TEXTURE_2D, m_TLighting);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -175,54 +190,115 @@ void dd::Renderer::CreateBuffers()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// Create second pass framebuffer
glGenFramebuffers(1, &m_fbDeferred2);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred2);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tLighting, 0);
glGenFramebuffers(1, &m_FbDeferred2);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred2);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TLighting, 0);
GLenum secondPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, secondPassDrawBuffers);
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
LOG_ERROR("m_fbDeferred2 incomplete: 0x%x\n", fbStatus);
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
exit(EXIT_FAILURE);
}
// Generate final deferred texture
glGenTextures(1, &m_tFinal);
glBindTexture(GL_TEXTURE_2D, m_tFinal);
//Fill Water Texture
glGenTextures(1, &m_Gwater);
glBindTexture(GL_TEXTURE_2D, m_Gwater);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//Fill water pass
glGenFramebuffers(1, &m_FbWater);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWater);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_Gwater, 0);
GLenum waterPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, waterPassDrawBuffers);
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
exit(EXIT_FAILURE);
}
//water Blur texture
glGenTextures(1, &m_BWater);
glBindTexture(GL_TEXTURE_2D, m_BWater);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//Fill waterBlur pass
glGenFramebuffers(1, &m_FbWaterBlur);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWaterBlur);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_BWater, 0);
GLenum waterBlurDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, waterBlurDrawBuffers);
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
exit(EXIT_FAILURE);
}
//water Blur texture2
glGenTextures(1, &m_BWater2);
glBindTexture(GL_TEXTURE_2D, m_BWater2);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RbDepthBuffer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//Fill waterBlur pass2
glGenFramebuffers(1, &m_FbWaterBlur2);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWaterBlur2);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_BWater2, 0);
GLenum waterBlur2DrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, waterBlur2DrawBuffers);
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
LOG_ERROR("m_FbDeferred2 incomplete: 0x%x\n", fbStatus);
exit(EXIT_FAILURE);
}
// Generate final deferred texture
glGenTextures(1, &m_TFinal);
glBindTexture(GL_TEXTURE_2D, m_TFinal);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Resolution.Width, m_Resolution.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Create third pass framebuffer
glGenFramebuffers(1, &m_fbDeferred3);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_rbDepthBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tFinal, 0);
glGenFramebuffers(1, &m_FbDeferred3);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RbDepthBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TFinal, 0);
GLenum thirdPassDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, thirdPassDrawBuffers);
if (GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
LOG_ERROR("m_fbDeferred3 incomplete: 0x%x\n", fbStatus);
LOG_ERROR("m_FbDeferred3 incomplete: 0x%x\n", fbStatus);
exit(EXIT_FAILURE);
}
}
void dd::Renderer::Draw(RenderQueueCollection& rq)
{
DrawDeferred(rq.Deferred, rq.Lights);
rq.Forward.Jobs.sort(dd::Renderer::DepthSort);
DrawDeferred(rq.Deferred, rq.Lights);
DrawForward(rq.Forward, rq.Lights);
DrawGUI(rq.GUI);
// Finally: Draw the deferred+forward combined texture to the screen
glCullFace(GL_BACK);
glDisable(GL_CULL_FACE);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
m_spScreen->Bind();
m_SpScreen->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_CurrentScreenBuffer);
glBindVertexArray(m_ScreenQuad);
@@ -236,17 +312,17 @@ void dd::Renderer::Draw(RenderQueueCollection& rq)
void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
{
// Pass #1: Fill G-buffers
glDisable(GL_CULL_FACE);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred1);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred1);
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_spDeferred1->Bind();
DrawScene(objects, *m_spDeferred1);
m_SpDeferred1->Bind();
DrawScene(objects, *m_SpDeferred1);
// Pass #2: Lighting
glEnable(GL_CULL_FACE);
@@ -256,31 +332,30 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE);
glDepthMask(GL_FALSE);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred2);
glClearColor(0, 0, 0, 1);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred2);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
m_spDeferred2->Bind();
m_SpDeferred2->Bind();
DrawLightSpheres(lights);
// Pass #3: Combine into final deferred image
glCullFace(GL_BACK);
glDisable(GL_BLEND);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
glClearColor(0, 0, 0, 1);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
m_spDeferred3->Bind();
glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f)));
m_SpDeferred3->Bind();
glUniform3fv(glGetUniformLocation(*m_SpDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f)));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_GDiffuse);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_tLighting);
glBindTexture(GL_TEXTURE_2D, m_TLighting);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
{
// Forward-render semi-transparent objects on top of the current framebuffer
glDisable(GL_CULL_FACE);
glCullFace(GL_BACK);
@@ -290,12 +365,25 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
// glClearColor(1, 0.9, 0.8f, 1);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_spForward->Bind();
DrawScene(objects, *m_spForward);
m_SpForward->Bind();
DrawScene(objects, *m_SpForward);
//WaterPass
glDisable(GL_CULL_FACE);
glCullFace(GL_BACK);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWater);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
m_SpWater->Bind();
DrawWater(objects);
}
void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
@@ -311,6 +399,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
if (modelJob) {
glm::mat4 modelMatrix = modelJob->ModelMatrix;
MVP = PV * modelMatrix;
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
@@ -318,7 +407,6 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightSpecular"), 1, glm::value_ptr(glm::vec3(1.f)));
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightDiffuse"), 1, glm::value_ptr(glm::vec3(1.f)));
glUniform1f(glGetUniformLocation(shaderProgramHandle, "LightRadius"), 40.0f);
glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess);
glActiveTexture(GL_TEXTURE0);
@@ -339,7 +427,6 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
glBindTexture(GL_TEXTURE_2D, *m_StandardSpecular);
}
glBindVertexArray(modelJob->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
@@ -355,6 +442,8 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
@@ -374,7 +463,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
void dd::Renderer::DrawLightSpheres(RenderQueue &lights)
{
GLuint shaderProgramHandle = *m_spDeferred2;
GLuint shaderProgramHandle = *m_SpDeferred2;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_GPosition);
@@ -409,6 +498,80 @@ void dd::Renderer::DrawLightSpheres(RenderQueue &lights)
}
}
void dd::Renderer::DrawWater(RenderQueue &rq)
{
GLuint shaderProgramHandle = *m_SpWater;
glm::mat4 projectionMatrix = m_Camera->ProjectionMatrix();
glm::mat4 viewMatrix = m_Camera->ViewMatrix();
glm::mat4 PV = projectionMatrix * viewMatrix;
glm::mat4 MVP;
for ( auto &job : rq ) {
auto waterJob = std::dynamic_pointer_cast<WaterParticleJob>(job);
if (waterJob) {
glm::mat4 modelMatrix = waterJob->ModelMatrix;
MVP = PV * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE,
glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE,
glm::value_ptr(viewMatrix));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *m_WhiteSphereTexture);
glBindVertexArray(m_UnitQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_UnitQuad->m_Indices.size(), GL_UNSIGNED_INT, 0, 0);
}
}
//blur1
shaderProgramHandle = *m_SpWater2;
glDisable(GL_CULL_FACE);
glDepthMask(GL_FALSE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbWaterBlur);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
m_SpWater2->Bind();
//TODO: Add this in water particle component. Blurradius
float radius = 3.f;
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(1.0f, 0.0f)));
glUniform1f(glGetUniformLocation(shaderProgramHandle, "res"), m_Resolution.Width);
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_Gwater);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
//blur2
shaderProgramHandle = *m_SpWater2;
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
m_SpWater2->Bind();
glUniform2fv(glGetUniformLocation(shaderProgramHandle, "dir"), 1, glm::value_ptr(glm::vec2(0.0f, 1.0f)));
glUniform1f(glGetUniformLocation(shaderProgramHandle, "res"), m_Resolution.Height);
glUniform1f(glGetUniformLocation(shaderProgramHandle, "radius"), radius);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_BWater);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
GLuint dd::Renderer::CreateQuad()
{
float quadVertices[] =
@@ -455,7 +618,7 @@ GLuint dd::Renderer::CreateQuad()
void dd::Renderer::DebugKeys()
{
if (glfwGetKey(m_Window, GLFW_KEY_F1)) {
m_CurrentScreenBuffer = m_tFinal;
m_CurrentScreenBuffer = m_TFinal;
}
if (glfwGetKey(m_Window, GLFW_KEY_F2)) {
m_CurrentScreenBuffer = m_GDiffuse;
@@ -470,6 +633,66 @@ void dd::Renderer::DebugKeys()
m_CurrentScreenBuffer = m_GSpecular;
}
if (glfwGetKey(m_Window, GLFW_KEY_F6)) {
m_CurrentScreenBuffer = m_tLighting;
m_CurrentScreenBuffer = m_TLighting;
}
if (glfwGetKey(m_Window, GLFW_KEY_F7)) {
m_CurrentScreenBuffer = m_Gwater;
}
if (glfwGetKey(m_Window, GLFW_KEY_F8)) {
m_CurrentScreenBuffer = m_BWater;
}
}
void dd::Renderer::DrawGUI(dd::RenderQueue& rq)
{
glBindFramebuffer(GL_FRAMEBUFFER, m_FbDeferred3);
glDisable(GL_CULL_FACE);
glCullFace(GL_BACK);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
m_SpScreen->Bind();
glm::mat4 MVP;
for (auto &job : rq) {
auto frameJob = std::dynamic_pointer_cast<FrameJob>(job);
if (frameJob) {
FrameJob jobCopy = *(frameJob.get());
glm::mat4 viewMatrix = glm::mat4(1); //frameJob->ViewMatrix;
glm::mat4 PV = glm::mat4(1); //frameJob->ProjectionMatrix * viewMatrix;
glm::mat4 modelMatrix = glm::mat4(1); //frameJob->ModelMatrix;
MVP = PV * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(*m_SpScreen, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(*m_SpScreen, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(*m_SpScreen, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture);
//glActiveTexture(GL_TEXTURE1);
//glBindTexture(GL_TEXTURE_2D, frameJob->NormalTexture);
//glActiveTexture(GL_TEXTURE2);
//glBindTexture(GL_TEXTURE_2D, frameJob->SpecularTexture);
Rectangle& vp = frameJob->Viewport;
glViewport(vp.X, m_Resolution.Height - vp.Y - vp.Height, vp.Width, vp.Height);
Rectangle& sc = frameJob->Scissor;
if (sc == Rectangle()) {
glDisable(GL_SCISSOR_TEST);
} else {
glEnable(GL_SCISSOR_TEST);
glScissor(sc.X, m_Resolution.Height - sc.Y - sc.Height, sc.Width, sc.Height);
}
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
continue;
}
}
glDisable(GL_SCISSOR_TEST);
glViewport(0, 0, m_Resolution.Width, m_Resolution.Height);
}
+2
View File
@@ -24,6 +24,7 @@ layout (binding = 2) uniform sampler2D SpecularMap;
uniform mat4 V;
uniform float MaterialShininess;
uniform vec4 Color;
in VertexData
{
@@ -49,6 +50,7 @@ void main()
{
// Diffuse Texture
GDiffuse = texture(DiffuseTexture, Input.TextureCoord) * Input.DiffuseColor;
GDiffuse = GDiffuse * Color;
// G-buffer Position
GPosition = vec4(Input.Position.xyz, 1.0);
+90
View File
@@ -0,0 +1,90 @@
/*
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/>.
*/
#version 440
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D NormalMap;
layout (binding=2) uniform sampler2D SpecularMap;
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec3 LightPosition;
uniform float LightRadius;
uniform vec3 LightSpecular;
uniform vec3 LightDiffuse;
in VertexData
{
vec3 Position;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoord;
vec4 DiffuseColor;
vec4 SpecularColor;
vec4 BoneIndices1;
vec4 BoneIndices2;
vec4 BoneWeights1;
vec4 BoneWeights2;
} Input;
out vec4 frag_Diffuse;
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
{
// Diffuse
vec3 lightPos = vec3(V * vec4(LightPosition, 1.0));
vec3 distanceToLight = lightPos - position;
vec3 directionToLight = normalize(distanceToLight);
float dotProd = dot(directionToLight, normal);
dotProd = max(dotProd, 0.0);
vec3 Idiffuse = LightDiffuse * dotProd;
// Specular
//vec3 reflection = reflect(-directionToLight, normal);
vec3 surfaceToViewer = normalize(-position);
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0);
float specularFactor = pow(dotSpecular, specularExponent);
vec3 Ispecular = specular * LightSpecular * specularFactor;
//Attenuation
float dist = distance(lightPos, position);
//float attenuation = 1.0 - pow(dist / LightRadius, 2);
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
return vec4((Idiffuse + Ispecular) * attenuation, 1.0);
}
void main()
{
vec4 normalTexel = texture(NormalMap, Input.TextureCoord);
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
vec3 normal = normalize(vec4(TBN * normalTexel.xyz, 0.0).xyz);
vec4 specularTexel = texture(SpecularMap, Input.TextureCoord);
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
//frag_Diffuse = light;
frag_Diffuse = diffuseTexel;
}
+83
View File
@@ -0,0 +1,83 @@
/*
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/>.
*/
#version 440
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 Bones[100];
layout (location = 0) in vec3 Position;
layout (location = 1) in vec3 Normal;
layout (location = 2) in vec3 Tangent;
layout (location = 3) in vec3 BiTangent;
layout (location = 4) in vec2 TextureCoord;
layout (location = 5) in vec4 DiffuseColor;
layout (location = 6) in vec4 SpecularColor;
layout (location = 7) in vec4 BoneIndices1;
layout (location = 8) in vec4 BoneIndices2;
layout (location = 9) in vec4 BoneWeights1;
layout (location = 10) in vec4 BoneWeights2;
out VertexData
{
vec3 Position;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoord;
vec4 DiffuseColor;
vec4 SpecularColor;
vec4 BoneIndices1;
vec4 BoneIndices2;
vec4 BoneWeights1;
vec4 BoneWeights2;
} Output;
void main()
{
mat4 boneTransform = mat4(1);
if (length(BoneWeights1 + BoneWeights2) > 0) {
boneTransform = BoneWeights1[0] * Bones[int(BoneIndices1[0])]
+ BoneWeights1[1] * Bones[int(BoneIndices1[1])]
+ BoneWeights1[2] * Bones[int(BoneIndices1[2])]
+ BoneWeights1[3] * Bones[int(BoneIndices1[3])]
+ BoneWeights2[0] * Bones[int(BoneIndices2[0])]
+ BoneWeights2[1] * Bones[int(BoneIndices2[1])]
+ BoneWeights2[2] * Bones[int(BoneIndices2[2])]
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
}
//gl_Position = MVP * boneTransform * vec4(Position, 1.0);
gl_Position = MVP * vec4(Position, 1.0);
//TODO: Make sure that boneTransform works here.
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
Output.Tangent = Tangent;
Output.BiTangent = BiTangent;
Output.TextureCoord = TextureCoord;
Output.DiffuseColor = DiffuseColor;
Output.SpecularColor = SpecularColor;
Output.BoneIndices1 = BoneIndices1;
Output.BoneIndices2 = BoneIndices2;
Output.BoneWeights1 = BoneWeights1;
Output.BoneWeights2 = BoneWeights2;
}
+70
View File
@@ -0,0 +1,70 @@
/*
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/>.
*/
#version 440
uniform vec2 dir;
uniform float res;
uniform float radius;
layout (binding=0) uniform sampler2D WaterTexture;
in VertexData
{
vec3 Position;
vec2 TextureCoord;
} Input;
out vec4 frag_Diffuse;
void main()
{
vec4 WaterTexel = texture(WaterTexture, Input.TextureCoord);
vec4 sum = vec4(0.0);
vec2 tc = Input.TextureCoord;
//How much blur, 1 = blur by one pixel.
float blur = radius/res;
float hstep = dir.x;
float vstep = dir.y;
float Threshhold = 0.1;
//apply filter using a 9 tap filter with predefined gaussian weights
sum += texture(WaterTexture, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;
sum += texture(WaterTexture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;
sum += texture(WaterTexture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;
sum += texture(WaterTexture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;
sum += texture(WaterTexture, vec2(tc.x, tc.y)) * 0.2270270270;
sum += texture(WaterTexture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;
sum += texture(WaterTexture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;
sum += texture(WaterTexture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
sum += texture(WaterTexture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
float avgColor = sum.r + sum.g + sum.b;
avgColor = avgColor/3;
frag_Diffuse = vec4(sum.r, sum.g, sum.b, 1.0);
if ( avgColor*dir.y > Threshhold ){
frag_Diffuse = vec4(0.0, 0.3, 1.0, 1.0);
}
}
+34
View File
@@ -0,0 +1,34 @@
/*
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/>.
*/
#version 440
layout (location = 0) in vec3 Position;
out VertexData
{
vec3 Position;
vec2 TextureCoord;
} Output;
void main()
{
gl_Position = vec4(Position, 1.0);
Output.Position = Position;
Output.TextureCoord = (vec2(Position) + 1) / 2;
}
+3
View File
@@ -31,6 +31,9 @@ dd::Texture::Texture(std::string path)
}
}
this->Width = image->Width;
this->Height = image->Height;
GLint format;
switch (image->Format) {
case Image::ImageFormat::RGB:
+240 -5
View File
@@ -13,17 +13,154 @@ void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf)
void dd::Systems::BallSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_Contact, BallSystem::Contact);
EVENT_SUBSCRIBE_MEMBER(m_Contact, &BallSystem::Contact);
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, &BallSystem::OnLifeLost);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &BallSystem::OnMultiBallLost);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &BallSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &BallSystem::OnPause);
//OctoBall
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(-0.f, 50.26f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
transform->Velocity = glm::vec3(0.f, 0.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 = 5.f;
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
std::shared_ptr<Components::Template> ballTemplate = m_World->AddComponent<Components::Template>(ent);
physics->Static = false;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
//auto plight = m_World->AddComponent<Components::PointLight>(ent);
//plight->Radius = 2.f;
m_World->CommitEntity(ent);
SetBall(ent);
auto ent2 = CreateBall();
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
transform2->Position = glm::vec3(-0.f, 0.26f, -10.f);
transform2->Velocity = glm::vec3(0.0f, -10.f, 0.f);
m_World->CommitEntity(ent2);
}
for (int i = 0; i < Lives(); i++) {
CreateLife(i);
}
}
void dd::Systems::BallSystem::Update(double dt)
{
if (Lives() < 0)
{
SetLives(3);
Events::GameOver e;
EventBroker->Publish(e);
}
}
void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ballComponent = m_World->GetComponent<Components::Ball>(entity);
if (IsPaused()) {
if (ballComponent != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!ballComponent->Paused) {
ballComponent->Paused = true;
ballComponent->SavedSpeed = transform->Velocity;
transform->Velocity = glm::vec3(0, 0, 0);
}
}
return;
} else {
if (ballComponent != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (ballComponent->Paused) {
transform->Velocity = ballComponent->SavedSpeed;
ballComponent->Paused = false;
}
}
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
if (ballComponent != nullptr) {
if (ReplaceBall()) {
SetReplaceBall(false);
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(0.0f, 0.26f, -10.f);
transform->Velocity = glm::vec3(0.0f, -ballComponent->Speed, 0.f);
}
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (glm::abs(transformBall->Velocity.y) < 2) {
if (transformBall->Velocity.y > 0) {
transformBall->Velocity.y = 2;
} else {
transformBall->Velocity.y = -2;
}
}
if (transformBall->Position.y < -EdgeY() - 4) {
if (MultiBalls() != 0) {
// m_World->RemoveComponent<Components::Ball>(entity);
// m_World->RemoveComponent<Components::Transform>(entity);
// m_World->RemoveComponent<Components::CircleShape>(entity);
// m_World->RemoveComponent<Components::Physics>(entity);
transformBall->Velocity = glm::vec3(0, 0, 0);
ballComponent->SavedSpeed = glm::vec3(0, 0, 0);
m_World->RemoveEntity(entity);
Events::MultiBallLost e;
EventBroker->Publish(e);
} else if (Lives() == PastLives()) {
Events::ResetBall be;
EventBroker->Publish(be);
Events::LifeLost e;
e.Entity = entity;
EventBroker->Publish(e);
return;
}
} else if (transformBall->Position.x > EdgeX()) {
if (transformBall->Velocity.x > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.x < -EdgeX()) {
if (transformBall->Velocity.x < 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(-1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.y > EdgeY()) {
if (transformBall->Velocity.y > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(0, 1));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
}
}
if (Lives() != PastLives()) {
auto life = m_World->GetComponent<Components::Life>(entity);
if (life != nullptr) {
if (life->Number + 1 == PastLives()) {
m_World->RemoveEntity(entity);
SetPastLives(Lives());
}
}
}
if (ballComponent != nullptr) {
auto transform = m_World->GetComponent<Components::Transform>(entity);
glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y));
@@ -33,6 +170,20 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
}
}
bool dd::Systems::BallSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "BallSystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
void dd::Systems::BallSystem::OnEntityCommit(EntityID entity)
{
@@ -60,9 +211,10 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
return false;
}
//Which is the ball?
EntityID ballEntity, otherEntitiy;
//Which is the ball?
if (ballComponent1 != nullptr) {
ballEntity = event.Entity1;
otherEntitiy = event.Entity2;
@@ -78,17 +230,24 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
//TODO: Add support for power-up collisions
}
//if this is a brick thats dead do not collide :)
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 x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier();
float movementMultiplier = 5.0f;
float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f;
ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed;
ballComponent->Combo = 0;
Events::ComboEvent ec;
ec.Combo = ballComponent->Combo;
ec.Ball = ballEntity;
EventBroker->Publish(ec);
//std::cout << "Combo: " << ballComponent->Combo << std::endl;
}
else {
glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal);
@@ -97,3 +256,79 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
return true;
}
EntityID dd::Systems::BallSystem::CreateBall()
{
auto ent = m_World->CloneEntity(Ball());
m_World->RemoveComponent<Components::Template>(ent);
m_World->CommitEntity(ent);
return ent;
}
void dd::Systems::BallSystem::CreateLife(int number)
{
auto life = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->Number = number;
auto model = m_World->AddComponent<Components::Model>(life);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
m_World->CommitEntity(life);
}
bool dd::Systems::BallSystem::OnLifeLost(const dd::Events::LifeLost &event)
{
SetLives(Lives() - 1);
return true;
}
bool dd::Systems::BallSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event)
{
SetMultiBalls(MultiBalls()-1);
return true;
}
bool dd::Systems::BallSystem::OnResetBall(const dd::Events::ResetBall &event)
{
SetReplaceBall(true);
return true;
}
bool dd::Systems::BallSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
auto ent1 = CreateBall();
auto ent2 = CreateBall();
auto transform1 = m_World->GetComponent<Components::Transform>(ent1);
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
auto ball1 = m_World->GetComponent<Components::Ball>(ent1);
auto ball2 = m_World->GetComponent<Components::Ball>(ent2);
auto padTransform = event.padTransform;
float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2;
if (x1 < -3.1) {
x1 = 3;
}
if (x2 > 3.1) {
x2 = -3;
}
transform1->Position = glm::vec3(x1, -5.5, -10);
transform2->Position = glm::vec3(x2, -5.5, -10);
transform1->Velocity = glm::normalize(glm::vec3(5, 5 ,0.f)) * ball1->Speed;
transform2->Velocity = glm::normalize(glm::vec3(-5, 5 ,0.f)) * ball2->Speed;
//std::cout << "1: " <<transform1->Velocity.x << " " << transform1->Velocity.y << std::endl;
//std::cout << "2: " <<transform2->Velocity.x << " " << transform2->Velocity.y << std::endl;
SetMultiBalls(MultiBalls() + 2);
return true;
}
+56
View File
@@ -0,0 +1,56 @@
//
// Created by Adniklastrator on 2015-09-30.
//
#include "PrecompiledHeader.h"
#include "Game/HitLagSystem.h"
void dd::Systems::HitLagSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EPause, &HitLagSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EHitLag, &HitLagSystem::OnHitLag);
}
void dd::Systems::HitLagSystem::Update(double dt)
{
if (IsPaused()) {
if (HitLag()) {
SetHitLagTimer(HitLagTimer() += dt);
if (HitLagDuration() < HitLagTimer()) {
SetHitLagTimer(0);
SetHitLag(false);
FlipPause();
}
}
return;
}
}
void dd::Systems::HitLagSystem::FlipPause()
{
Events::Pause e;
e.Type = CurrentType();
EventBroker->Publish(e);
}
bool dd::Systems::HitLagSystem::OnPause(const dd::Events::Pause &event)
{
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
bool dd::Systems::HitLagSystem::OnHitLag(const dd::Events::HitLag &event)
{
if (HitLag()) {
FlipPause();
}
SetHitLag(true);
SetCurrentType(event.Type);
FlipPause();
SetHitLagDuration(event.Time);
return true;
}
+99 -156
View File
@@ -9,137 +9,51 @@
void dd::Systems::LevelSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::OnLifeLost);
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::OnScoreEvent);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, LevelSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, LevelSystem::OnCreatePowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, LevelSystem::OnPowerUpTaken);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, LevelSystem::OnStageCleared);
for (int i = 0; i < Lives(); i++) {
CreateLife(i);
}
EVENT_SUBSCRIBE_MEMBER(m_EContact, &LevelSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, &LevelSystem::OnScoreEvent);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &LevelSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_ECreatePowerUp, &LevelSystem::OnCreatePowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &LevelSystem::OnMultiBallLost);
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, &LevelSystem::OnPowerUpTaken);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &LevelSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &LevelSystem::OnPause);
return;
}
void dd::Systems::LevelSystem::CreateLife(int number)
{
auto life = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->Number = number;
auto model = m_World->AddComponent<Components::Model>(life);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
m_World->CommitEntity(life);
}
void dd::Systems::LevelSystem::Update(double dt)
{
if (!m_Initialized) {
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
m_Initialized = true;
}
if (Lives() < 0)
{
SetLives(3);
Events::GameOver e;
EventBroker->Publish(e);
}
}
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
if (IsPaused()) {
return;
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (ball != nullptr) {
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (glm::abs(transformBall->Velocity.y) < 2) {
if (transformBall->Velocity.y > 0) {
transformBall->Velocity.y = 2;
} else {
transformBall->Velocity.y = -2;
}
}
if (transformBall->Position.y < -EdgeY() - 4) {
if (MultiBalls() != 0) {
SetMultiBalls(MultiBalls() - 1);
m_World->RemoveComponent<Components::Ball>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveComponent<Components::CircleShape>(entity);
m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity);
} else if (Lives() == PastLives()) {
Events::ResetBall be;
EventBroker->Publish(be);
Events::LifeLost e;
e.Entity = entity;
EventBroker->Publish(e);
return;
}
} else if (transformBall->Position.x > EdgeX()) {
if (transformBall->Velocity.x > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.x < -EdgeX()) {
if (transformBall->Velocity.x < 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(-1, 0));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
} else if (transformBall->Position.y > EdgeY()) {
if (transformBall->Velocity.y > 0) {
glm::vec2 reflectedVelocity = glm::reflect(glm::vec2(transformBall->Velocity.x, transformBall->Velocity.y), glm::vec2(0, 1));
transformBall->Velocity = glm::vec3(reflectedVelocity, 0.f);
}
}
}
if (Lives() != PastLives()) {
auto life = m_World->GetComponent<Components::Life>(entity);
if (life != nullptr) {
if (life->Number + 1 == PastLives()) {
m_World->RemoveComponent<Components::Life>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
SetPastLives(Lives());
}
}
}
if (NumberOfBricks() <= 0) {
/*SetRestarting(true);
if (MultiBalls() <= 0 && PowerUps() <= 0) {
Events::ResetBall e;
EventBroker->Publish(e);
Events::ScoreEvent es;
es.Score = 500;
EventBroker->Publish(es);
Events::StageCleared ec;
EventBroker->Publish(ec);
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
if (NumberOfBricks() <= 0 && Restarting() == false) {
/*if (MultiBalls() <= 0 && PowerUps() <= 0) {
//Events::StageCleared ec;
//EventBroker->Publish(ec);
} else {
if (ball != nullptr && MultiBalls() > 0) {
SetMultiBalls(MultiBalls() - 1);
m_World->RemoveComponent<Components::Ball>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveComponent<Components::CircleShape>(entity);
m_World->RemoveComponent<Components::Physics>(entity);
m_World->RemoveEntity(entity);
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
SetMultiBalls(MultiBalls()-1);
transformBall->Velocity = glm::vec3(0, 0, 0);
ball->SavedSpeed = glm::vec3(0, 0, 0);
m_World->RemoveEntity(entity);
} else {
auto powerUp = m_World->GetComponent<Components::PowerUp>(entity);
if (powerUp != nullptr) {
SetPowerUps(PowerUps() - 1);
m_World->RemoveComponent<Components::PowerUp>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
}
}
@@ -147,18 +61,31 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
}
}
bool dd::Systems::LevelSystem::OnPause(const dd::Events::Pause &event)
{
if (event.Type != "LevelSystem" && event.Type != "All") {
return false;
}
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, float spaceToEdge)
{
SetNumberOfBricks(rows * lines);
std::cout << "You're only doing this once, right?" << std::endl;
int num = 0;
int num = Lines();
for (int i = 0; i < rows; i++) {
num++;
num--;
for (int j = 0; j < Lines(); j++) {
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num);
}
if (num == 7)
num = 0;
if (num == 1)
num = Lines();
}
SetNumberOfBricks(rows * lines);
@@ -170,17 +97,17 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
{
auto brick = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(brick);
auto model = m_World->AddComponent<Components::Model>(brick);
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick);
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(brick);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
std::string fileName = "Textures/Bricks/";
fileName.append(std::to_string(num));
fileName.append(".png");
//sprite->SpriteFile = fileName;
cPhys->Static = false;
cPhys->GravityScale = 0.f;
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
model->ModelFile = "Models/Test/Brick/Brick.obj";
if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 6 && row == 6)) {
if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 5 && row == 2)) {
std::shared_ptr<Components::PowerUpBrick> cPow = m_World->AddComponent<Components::PowerUpBrick>(brick);
}
float x = line * spacesBetweenBricks.x;
@@ -191,31 +118,15 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
//sound
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(brick);
collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav";
collisionSound->FilePath = "Sounds/Brick/shortbrickbreak.wav";
m_World->CommitEntity(brick);
return;
}
void dd::Systems::LevelSystem::ProcessCollision()
{
// Like, go into brick component and check what it does upon collision. Maybe not done here?
return;
}
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
{
auto brick = m_World->GetComponent<Components::Brick>(entity);
if (brick != nullptr) {
SetNumberOfBricks(NumberOfBricks() - 1);
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
/*if (numberOfBricks < 1) {
EndLevel();
}*/
}
return;
}
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
@@ -224,6 +135,8 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
EntityID entityBall;
auto ball = m_World->GetComponent<Components::Ball>(event.Entity2);
auto brick = m_World->GetComponent<Components::Brick>(event.Entity1);
//This code ensures that it is a brick and a ball that has come into contact.
if (brick != nullptr) {
entityBrick = event.Entity1;
} else {
@@ -251,7 +164,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
}
auto power = m_World->GetComponent<Components::PowerUpBrick>(entityBrick);
if (power != nullptr) {
if (power != nullptr && NumberOfBricks() > 1) {
Events::CreatePowerUp e;
auto transform = m_World->GetComponent<Components::Transform>(entityBrick);
e.Position = transform->Position;
@@ -259,36 +172,47 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
}
if (ball != nullptr && Restarting() == false) {
ball->Combo += 1;
Events::ComboEvent ec;
ec.Combo = ball->Combo;
ec.Ball = entityBall;
EventBroker->Publish(ec);
auto ballTransform = m_World->GetComponent<Components::Transform>(entityBall);
m_World->RemoveComponent<Components::Brick>(entityBrick);
m_World->RemoveComponent<Components::Transform>(entityBrick);
m_World->RemoveComponent<Components::RectangleShape>(entityBrick);
m_World->RemoveComponent<Components::Physics>(entityBrick);
m_World->RemoveEntity(entityBrick);
auto physicsComponent = m_World->GetComponent<Components::Physics>(entityBrick);
physicsComponent->GravityScale = 1.f;
physicsComponent->Mask = CollisionLayer::Type::Water | CollisionLayer::Type::Wall;
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
Events::SetImpulse e;
e.Entity = entityBrick;
glm::vec2 point = glm::vec2(transformComponentBrick->Position.x + ((transformComponentBall->Position.x - transformComponentBrick->Position.x )/4),
transformComponentBrick->Position.y + ((transformComponentBall->Position.y - transformComponentBrick->Position.y)/4));
e.Impulse = glm::normalize(point)*5.f;///2.f;
e.Point = point;
EventBroker->Publish(e);
//TODO: Bricks dont collide with walls D=
SetNumberOfBricks(NumberOfBricks() - 1);
if (NumberOfBricks() <= 0) {
SetMultiBalls(MultiBalls() + 1);
}
Events::ScoreEvent es;
es.Score = brick->Score;
es.Score = brick->Score * ball->Combo;
EventBroker->Publish(es);
std::cout << NumberOfBricks() << std::endl;
//std::cout << "Combo: " << ball->Combo << std::endl;
//std::cout << NumberOfBricks() << std::endl;
//std::cout << "Brick Score: " << brick->Score << std::endl;
//std::cout << "Score: " << Score() << std::endl;
}
return true;
}
bool dd::Systems::LevelSystem::OnLifeLost(const dd::Events::LifeLost &event)
{
SetLives(Lives() - 1);
return true;
}
bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
{
SetScore(Score() += event.Score);
@@ -299,6 +223,15 @@ bool dd::Systems::LevelSystem::OnScoreEvent(const dd::Events::ScoreEvent &event)
bool dd::Systems::LevelSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
SetMultiBalls(MultiBalls()+2);
//std::cout << MultiBalls() << std::endl;
return true;
}
bool dd::Systems::LevelSystem::OnMultiBallLost(const dd::Events::MultiBallLost &event)
{
SetMultiBalls(MultiBalls()-1);
//std::cout << MultiBalls() << std::endl;
return true;
}
bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &event)
@@ -309,8 +242,12 @@ bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &
auto model = m_World->AddComponent<Components::Model>(powerUp);
std::shared_ptr<Components::CircleShape> cRec = m_World->AddComponent<Components::CircleShape>(powerUp);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(powerUp);
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
cPhys->Static = false;
cPhys->Category = CollisionLayer::Type::PowerUp;
cPhys->Mask = CollisionLayer::Type::Pad;
std::shared_ptr<Components::PowerUp> cPow = m_World->AddComponent<Components::PowerUp>(powerUp);
transform->Position = event.Position;
transform->Scale = glm::vec3(0.2, 0.2, 0.2);
@@ -331,6 +268,12 @@ bool dd::Systems::LevelSystem::OnPowerUpTaken(const dd::Events::PowerUpTaken &ev
bool dd::Systems::LevelSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
SetRestarting(true);
Events::ResetBall e;
EventBroker->Publish(e);
Events::ScoreEvent es;
es.Score = 500;
EventBroker->Publish(es);
return true;
}
+60 -116
View File
@@ -26,27 +26,42 @@ void dd::Systems::PadSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PadSystem::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EContact, &PadSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EContactPowerUp, &PadSystem::OnContactPowerUp);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &PadSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &PadSystem::OnMultiBall);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &PadSystem::OnStageCleared);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &PadSystem::OnPause);
{
auto ent = m_World->CreateEntity();
m_World->SetProperty(ent, "Name", "Pad");
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
ctransform->Position = glm::vec3(0.f, -3.5f, -10.f);
ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f);
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
auto physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
physics->Category = CollisionLayer::Type::Pad;
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::PowerUp;
physics->Calculate = true;
auto cModel = m_World->AddComponent<Components::Model>(ent);
cModel->ModelFile = "Models/Submarine2.obj";
auto pad = m_World->AddComponent<Components::Pad>(ent);
m_World->CommitEntity(ent);
SetEdge(3.2 - (ctransform->Scale.x / 2));
}
}
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (ball != nullptr) {
if (ReplaceBall() == true) {
SetReplaceBall(false);
auto transform = m_World->GetComponent<Components::Transform>(entity);
transform->Position = glm::vec3(0.0f, 0.26f, -10.f);
transform->Velocity = glm::vec3(0.0f, -ball->Speed, 0.f);
}
}
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
}
void dd::Systems::PadSystem::Update(double dt)
{
if (IsPaused()) {
return;
}
if (Entity() == 0) {
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") {
@@ -69,8 +84,15 @@ void dd::Systems::PadSystem::Update(double dt)
transform->Velocity.x = pad->MaxSpeed;
}
transform->Position += transform->Velocity * (float)dt;
if (transform->Position.x > Edge()) {
transform->Position.x = Edge();
} else if (transform->Position.x < -Edge()) {
transform->Position.x = -Edge();
}
transform->Velocity += acceleration * (float)dt;
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
if (glm::abs(transform->Velocity.x) > 1 || (!Left() && !Right())) {
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float) dt;
}
if (Left()) {
acceleration.x = -pad->AccelerationSpeed;
@@ -84,36 +106,21 @@ void dd::Systems::PadSystem::Update(double dt)
SetPad(pad);
SetAcceleration(acceleration);
if (MultiBall() == true) {
SetMultiBall(false);
Events::MultiBall e;
e.padTransform = transform;
EventBroker->Publish(e);
}
return;
}
EntityID dd::Systems::PadSystem::CreateBall()
bool dd::Systems::PadSystem::OnPause(const dd::Events::Pause &event)
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.5f, 0.26f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
if (event.Type != "PadSystem" && event.Type != "All") {
return false;
}
cball->Speed = 10;
m_World->CommitEntity(ent);
return ent;
if (IsPaused()) {
SetPause(false);
} else {
SetPause(true);
}
return true;
}
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
@@ -132,9 +139,21 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
//acceleration.x = 0.01f;
SetRight(true);
} else if (val == GLFW_KEY_R) {
SetReplaceBall(true);
Events::ResetBall e;
EventBroker->Publish(e);
} else if (val == GLFW_KEY_M) {
SetMultiBall(true);
Events::MultiBall e;
e.padTransform = Transform();
EventBroker->Publish(e);
} else if (val == GLFW_KEY_P) {
Events::Pause e;
e.Type = "All";
EventBroker->Publish(e);
} else if (val == GLFW_KEY_H) {
Events::HitLag e;
e.Time = 0.2;
e.Type = "All";
EventBroker->Publish(e);
} else if (val == GLFW_KEY_D) {
return false;
}
@@ -158,48 +177,7 @@ bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
{
/*
EntityID entityBall = event.Entity2;
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
if (ball == NULL) {
return false;
}
EntityID entityPad = event.Entity1;
auto pad = m_World->GetComponent<Components::Pad>(entityPad);
if (pad == NULL) {
return false;
}
auto transformBall = m_World->GetComponent<Components::Transform>(entityBall);
auto transformPad = m_World->GetComponent<Components::Transform>(entityPad);
float movementMultiplier = 0.5f;
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
//float movementY = glm::cos((abs(movementX) / (3.2f * movementMultiplier)) * 3.14159265359f / 2) * 2.f;
if (whatX > 0) {
movementX = movementMultiplier * whatX;
//std::cout << "Right!" << std::endl;
} else {
movementX = movementMultiplier * whatX;
//std::cout << "Left!" << std::endl;
}
// std::cout << movementX << " " << movementY << std::endl;
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2)+ 0.2;
//std::cout << movementX << " " << movementY << std::endl;
float len = glm::length<float>(transformBall->Velocity);
transformBall->Velocity += glm::vec3(transformPad->Velocity.x, 0, 0);
transformBall->Velocity = glm::normalize(transformBall->Velocity) * len;
//transform->Velocity = glm::vec3(movementX, movementY, 0.f);
*/
}
bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
@@ -234,9 +212,6 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
return false;
}
m_World->RemoveComponent<Components::PowerUp>(entityPower);
m_World->RemoveComponent<Components::CircleShape>(entityPower);
m_World->RemoveComponent<Components::Physics>(entityPower);
m_World->RemoveEntity(entityPower);
Events::PowerUpTaken ep;
ep.Name = "Something";
@@ -249,40 +224,9 @@ bool dd::Systems::PadSystem::OnContactPowerUp(const dd::Events::Contact &event)
return true;
}
bool dd::Systems::PadSystem::OnResetBall(const dd::Events::ResetBall &event)
{
SetReplaceBall(true);
return true;
}
bool dd::Systems::PadSystem::OnMultiBall(const dd::Events::MultiBall &event)
{
auto ent1 = CreateBall();
auto ent2 = CreateBall();
auto transform1 = m_World->GetComponent<Components::Transform>(ent1);
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
auto ball1 = m_World->GetComponent<Components::Ball>(ent1);
auto ball2 = m_World->GetComponent<Components::Ball>(ent2);
auto padTransform = event.padTransform;
float x1 = padTransform->Position.x - 2, x2 = padTransform->Position.x + 2;
if (x1 < -3.1) {
x1 = 3;
}
if (x2 > 3.1) {
x2 = -3;
}
transform1->Position = glm::vec3(x1, -5.5, -10);
transform2->Position = glm::vec3(x2, -5.5, -10);
transform1->Velocity = glm::normalize(glm::vec3(5, 5 ,0.f)) * ball1->Speed;
transform2->Velocity = glm::normalize(glm::vec3(-5, 5 ,0.f)) * ball2->Speed;
return true;
}
bool dd::Systems::PadSystem::OnStageCleared(const dd::Events::StageCleared &event)
{
auto entity = CreateBall();
//auto entity = CreateBall();
return true;
}

Some files were not shown because too many files have changed in this diff Show More