Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ddb969f1f0 | |||
| 06ea99a769 |
@@ -0,0 +1,18 @@
|
||||
#ifndef EAmmoPickup_h__
|
||||
#define EAmmoPickup_h__
|
||||
|
||||
#include "EventBroker.h"
|
||||
#include "../Core/EntityWrapper.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct AmmoPickup : Event
|
||||
{
|
||||
EntityWrapper Player;
|
||||
int AmmoGain;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,13 +1,14 @@
|
||||
#ifndef ECaptured_h__
|
||||
#define ECaptured_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/Entity.h"
|
||||
#include "EventBroker.h"
|
||||
#include "../Core/Entity.h"
|
||||
#include "Engine/GLM.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
//triggers when a capturePoint has been taken over
|
||||
//triggers when a capturePoint has been taken over
|
||||
struct Captured : Event
|
||||
{
|
||||
int TeamNumberThatCapturedCapturePoint;
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef EPlayerHealthPickup_h__
|
||||
#define EPlayerHealthPickup_h__
|
||||
|
||||
#include "EventBroker.h"
|
||||
#include "../Core/EntityWrapper.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct PlayerHealthPickup : Event
|
||||
{
|
||||
EntityWrapper Player;
|
||||
double HealthAmount;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef EWin_h__
|
||||
#define EWin_h__
|
||||
|
||||
#include "EventBroker.h"
|
||||
#include "../Core/Entity.h"
|
||||
#include "Engine/GLM.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
//triggers when a team has captured all capturePoints
|
||||
struct Win : Event
|
||||
{
|
||||
//can be 0 = none, 1,2
|
||||
int TeamThatWon;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,19 +0,0 @@
|
||||
#ifndef EntitySystem_h__
|
||||
#define EntitySystem_h__
|
||||
|
||||
#include "World.h"
|
||||
#include "SystemPipeline.h"
|
||||
|
||||
// An "EntitySystem" is defined as the combination of a World with a SystemPipeline
|
||||
template <typename WorldType>
|
||||
class EntitySystem : public WorldType, public SystemPipeline
|
||||
{
|
||||
static_assert(std::is_base_of<World, WorldType>::value, "WorldType must inherit from World");
|
||||
public:
|
||||
EntitySystem(EventBroker* eventBroker, bool isClient, bool isServer)
|
||||
: WorldType(eventBroker)
|
||||
, SystemPipeline(this, eventBroker, isClient, isServer)
|
||||
{ }
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -29,8 +29,6 @@ private:
|
||||
void InitializeShaderProgram();
|
||||
void InitializeBuffer();
|
||||
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
void ComputeAO(GLuint depthBuffer, Camera* camera);
|
||||
//void blurHorizontal(GLuint depthBuffer);
|
||||
//void blurVertical(GLuint depthBuffer);
|
||||
@@ -38,7 +36,7 @@ private:
|
||||
Model* m_ScreenQuad;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
|
||||
static const GLint MAX_MIP_LEVEL = 5;
|
||||
float m_Radius;
|
||||
float m_Bias;
|
||||
float m_Contrast;
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "Core/EntitySystem.h"
|
||||
#include "Rendering/IRenderer.h"
|
||||
#include "Core/Octree.h"
|
||||
#include "Collision/EntityAABB.h"
|
||||
|
||||
class CapturePointsEntitySystem : public EntitySystem<World>
|
||||
{
|
||||
public:
|
||||
CapturePointsEntitySystem(EventBroker* eventBroker, bool isClient, bool isServer, IRenderer* renderer, RenderFrame* renderFrame);
|
||||
~CapturePointsEntitySystem();
|
||||
|
||||
private:
|
||||
IRenderer* m_Renderer;
|
||||
RenderFrame* m_RenderFrame;
|
||||
Octree<EntityAABB>* m_OctreeCollision = nullptr;
|
||||
Octree<EntityAABB>* m_OctreeTrigger = nullptr;
|
||||
Octree<EntityAABB>* m_OctreeFrustrumCulling = nullptr;
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef EAmmoPickup_h__
|
||||
#define EAmmoPickup_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/EntityWrapper.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct AmmoPickup : Event
|
||||
{
|
||||
EntityWrapper Player;
|
||||
int AmmoGain;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef EGameEnd_h__
|
||||
#define EGameEnd_h__
|
||||
|
||||
#include "Core/Event.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct GameEnd : Event
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef EGameStart_h__
|
||||
#define EGameStart_h__
|
||||
|
||||
#include "Core/Event.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct GameStart : Event
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef EPlayerHealthPickup_h__
|
||||
#define EPlayerHealthPickup_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/EntityWrapper.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct PlayerHealthPickup : Event
|
||||
{
|
||||
EntityWrapper Player;
|
||||
double HealthAmount;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,19 +0,0 @@
|
||||
#ifndef EWin_h__
|
||||
#define EWin_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/Entity.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
//triggers when a team has captured all capturePoints
|
||||
struct Win : Event
|
||||
{
|
||||
// The winning team corresponding to TeamEnum
|
||||
ComponentInfo::EnumType Team;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
-3
@@ -12,16 +12,18 @@
|
||||
#include "Input/InputProxy.h"
|
||||
#include "Input/KeyboardInputHandler.h"
|
||||
#include "Input/MouseInputHandler.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EntityFilePreprocessor.h"
|
||||
#include "Core/EntitySystem.h"
|
||||
#include "Core/SystemPipeline.h"
|
||||
#include "Systems/ExplosionEffectSystem.h"
|
||||
#include "Editor/EditorSystem.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Rendering/RenderSystem.h"
|
||||
#include "Core/EntityFileParser.h"
|
||||
#include "Core/Octree.h"
|
||||
#include "Rendering/Font.h"
|
||||
#include "Systems/InterpolationSystem.h"
|
||||
#include "Collision/EntityAABB.h"
|
||||
|
||||
// Network
|
||||
#include <boost/thread.hpp>
|
||||
#include "Network/Network.h"
|
||||
@@ -53,7 +55,11 @@ private:
|
||||
IRenderer* m_Renderer;
|
||||
InputManager* m_InputManager;
|
||||
InputProxy* m_InputProxy;
|
||||
EntitySystem<World>* m_EntitySystem;
|
||||
World* m_World;
|
||||
Octree<EntityAABB>* m_OctreeCollision;
|
||||
Octree<EntityAABB>* m_OctreeTrigger;
|
||||
Octree<EntityAABB>* m_OctreeFrustrumCulling;
|
||||
SystemPipeline* m_SystemPipeline;
|
||||
RenderFrame* m_RenderFrame;
|
||||
Client* m_NetworkClient = nullptr;
|
||||
Server* m_NetworkServer = nullptr;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/EntityFileParser.h"
|
||||
#include "Events/EPickupSpawned.h"
|
||||
#include "Events/EAmmoPickup.h"
|
||||
#include "Core/EPickupSpawned.h"
|
||||
#include "Core/EAmmoPickup.h"
|
||||
#include "Engine/Collision/ETrigger.h"
|
||||
#include "Common.h"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
#include "Engine/Collision/ETrigger.h"
|
||||
#include "Events/ECaptured.h"
|
||||
#include "Core/ECaptured.h"
|
||||
#include "Core/EWin.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#include "Core/System.h"
|
||||
#include "Events/EGameStart.h"
|
||||
#include "Events/EGameEnd.h"
|
||||
#include "Events/ECaptured.h"
|
||||
#include "Events/EWin.h"
|
||||
|
||||
class CapturePointsGamemode : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
CapturePointsGamemode(SystemParams params);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
bool m_GameRuning = false;
|
||||
double m_GameTime = 0.0;
|
||||
|
||||
EventRelay<CapturePointsGamemode, Events::GameStart> m_EGameStart;
|
||||
bool OnGameStart(const Events::GameStart& e);
|
||||
EventRelay<CapturePointsGamemode, Events::Captured> m_ECaptured;
|
||||
bool OnCaptured(const Events::Captured& e);
|
||||
|
||||
boost::optional<ComponentWrapper> currentGamemode();
|
||||
bool isCurrentGamemode();
|
||||
boost::optional<ComponentInfo::EnumType> winCondition();
|
||||
void setRunning(bool running);
|
||||
};
|
||||
@@ -7,8 +7,8 @@
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/EPlayerDamage.h"
|
||||
#include "Core/EPlayerHealthPickup.h"
|
||||
#include "Core/EPlayerDeath.h"
|
||||
#include "Events/EPlayerHealthPickup.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
#include "Input/EInputCommand.h"
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/EntityFileParser.h"
|
||||
#include "Events/EPickupSpawned.h"
|
||||
#include "Events/EPlayerHealthPickup.h"
|
||||
#include "Core/EPickupSpawned.h"
|
||||
#include "Core/EPlayerHealthPickup.h"
|
||||
#include "Engine/Collision/ETrigger.h"
|
||||
#include "Common.h"
|
||||
#include <tuple>
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
#include "../Engine/Core/EShoot.h"
|
||||
#include "../Engine/Core/EPlayerSpawned.h"
|
||||
#include "../Engine/Input/EInputCommand.h"
|
||||
#include "Events/ECaptured.h"
|
||||
#include "../Engine/Core/ECaptured.h"
|
||||
#include "../Engine/Core/EPlayerDamage.h"
|
||||
#include "../Engine/Core/EPlayerDeath.h"
|
||||
#include "Events/EPlayerHealthPickup.h"
|
||||
#include "../Engine/Core/EPlayerHealthPickup.h"
|
||||
#include "../Engine/Collision/ETrigger.h"
|
||||
#include "../Engine/Sound/EPlaySoundOnEntity.h"
|
||||
#include "../Engine/Sound/EPlayBackgroundMusic.h"
|
||||
|
||||
@@ -45,5 +45,4 @@
|
||||
<xs:include schemaLocation="Components/KillFeed.xsd"/>
|
||||
<xs:include schemaLocation="Components/Page.xsd"/>
|
||||
<xs:include schemaLocation="Components/Button.xsd"/>
|
||||
<xs:include schemaLocation="Components/Gamemode.xsd"/>
|
||||
</xs:schema>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Gamemode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Gamemode.xsd">
|
||||
<Gamemode><CapturePoints/></Gamemode>
|
||||
<RoundTime>0</RoundTime>
|
||||
<Running>false</Running>
|
||||
</Gamemode>
|
||||
@@ -1,25 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||
|
||||
<xs:complexType name="GamemodeEnum" mixed="true">
|
||||
<xs:complexContent>
|
||||
<xs:extension base="t:enum">
|
||||
<xs:choice>
|
||||
<xs:element name="CapturePoints" type="t:int" fixed="1" minOccurs="0"/>
|
||||
</xs:choice>
|
||||
</xs:extension>
|
||||
</xs:complexContent>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:element name="Gamemode">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Gamemode" type="GamemodeEnum" minOccurs="0"/>
|
||||
<xs:element name="RoundTime" type="t:double" minOccurs="0"/>
|
||||
<xs:element name="Running" type="t:bool" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@@ -50,7 +50,6 @@
|
||||
<xs:element ref="c:Menu" minOccurs="0"/>
|
||||
<xs:element ref="c:Page" minOccurs="0"/>
|
||||
<xs:element ref="c:Button" minOccurs="0"/>
|
||||
<xs:element ref="c:Gamemode" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
#version 430
|
||||
|
||||
#define MIP_MAPS_LEVELS (3)
|
||||
|
||||
#define MAX_PIXEL_BEFOR_LOWER_MIP_LEVEL (3)
|
||||
//Number of samples per pixel
|
||||
uniform int uNumOfSamples;
|
||||
//#define NUM_SAMPLES (11)
|
||||
//#define uNumOfSamples (11)
|
||||
|
||||
//Number of turns around the cirle
|
||||
uniform int uNumOfTurns;
|
||||
//#define NUM_TURNS (7)
|
||||
//#define uNumOfTurns (7)
|
||||
|
||||
layout (binding = 0) uniform sampler2D ViewSpaceZ;
|
||||
|
||||
@@ -42,42 +45,41 @@ vec3 getVSFaceNormal(vec3 ViewSpacePosition) {
|
||||
|
||||
|
||||
vec3 getSampleViewSpacePos(ivec2 ScreenSpaceCoord, int SampleIndex, float RotationAngle, float ScreenSpaceSampleRadius){
|
||||
// Pure Magic...
|
||||
float alpha = float(SampleIndex) * (1.0 / uNumOfSamples);
|
||||
// SampleIndex + 0.5f so that we alpha != 0, since if alpha = 0 then screenSpaceSampleTexel will be the same texel as origin.
|
||||
float alpha = float(SampleIndex + 0.5f) * (1.0f / uNumOfSamples);
|
||||
|
||||
// Angle to where to sample
|
||||
float angle = alpha * (uNumOfTurns * 6.28) + RotationAngle;
|
||||
float angle = alpha * (uNumOfTurns * 6.28f) + RotationAngle;
|
||||
|
||||
//Lenght to were to sample
|
||||
ScreenSpaceSampleRadius = ScreenSpaceSampleRadius * alpha;
|
||||
|
||||
vec2 screenSpaceSampleOffsetVecor = vec2(cos(angle), sin(angle));
|
||||
|
||||
//int mipmapLevel = clamp(int(floor(log2(-ScreenSpaceSampleRadius))) - MAX_PIXEL_BEFOR_LOWER_MIP_LEVEL, 0, MIP_MAPS_LEVELS);
|
||||
|
||||
// Get texel coordinate on where to sample by going screenSpaceSampleOffsetVecor direction in ScreenSpaceSampleRadius units from ScreenSpaceCoord (the point being shaded);
|
||||
ivec2 screenSpaceSampleTexel = ivec2(ScreenSpaceSampleRadius * screenSpaceSampleOffsetVecor) + ScreenSpaceCoord;
|
||||
ivec2 screenSpaceSampleTexel = (ivec2(ScreenSpaceSampleRadius * screenSpaceSampleOffsetVecor) + ScreenSpaceCoord);// >> mipmapLevel;
|
||||
|
||||
return getVSPosition(screenSpaceSampleTexel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float sampleAO(ivec2 ScreenSpaceCoord, vec3 Origin, vec3 OriginNormal, float ScreenSpaceSampleRadius, int SampleIndex, float RotationAngle, float Radius) {
|
||||
float radius2 = Radius * Radius;
|
||||
float sampleAO(ivec2 ScreenSpaceCoord, vec3 Origin, vec3 OriginNormal, float ScreenSpaceSampleRadius, int SampleIndex, float RotationAngle, float Radius, float Radius2) {
|
||||
vec3 sampleViewSpacePosition = getSampleViewSpacePos(ScreenSpaceCoord, SampleIndex, RotationAngle, ScreenSpaceSampleRadius);
|
||||
|
||||
vec3 sampleVector = Origin - sampleViewSpacePosition;
|
||||
|
||||
// vv = sampleVectorLenght ^ 2
|
||||
float vv = dot(sampleVector, sampleVector);
|
||||
// vn = angle between sampleVector and Normal
|
||||
float vn = dot(sampleVector, OriginNormal);
|
||||
|
||||
const float epsilon = 0.0001f;
|
||||
const float epsilon = 0.01f;
|
||||
|
||||
// vv < radius2 if the vector is shorter then the radius;
|
||||
// vn - bias, offset the angle to reduse self occlusion.
|
||||
// epsilon is here to make divison by 0 impossible.
|
||||
return float(vv < radius2) * max((vn - uBias) / (epsilon + vv), 0.0);
|
||||
return float(vv < Radius2) * max((vn - uBias) / (epsilon + vv), 0.0);
|
||||
//float f = max(radius2 - vv, 0.0);
|
||||
//return f * f * f * max((vn - uBias) / (epsilon + vv), 0.0);
|
||||
}
|
||||
@@ -86,9 +88,11 @@ float sampleAO(ivec2 ScreenSpaceCoord, vec3 Origin, vec3 OriginNormal, float Scr
|
||||
void main() {
|
||||
ivec2 originScreenCoord = ivec2(gl_FragCoord.xy);
|
||||
|
||||
// We always get the Orginin from the level 0 of the mipmaps
|
||||
vec3 origin = getVSPosition(originScreenCoord);
|
||||
|
||||
float radius;
|
||||
|
||||
if(origin.z < uRadius){
|
||||
radius = origin.z;
|
||||
} else {
|
||||
@@ -96,19 +100,24 @@ void main() {
|
||||
}
|
||||
|
||||
|
||||
float radius2 = radius * radius;
|
||||
|
||||
vec3 originNormal = getVSFaceNormal(origin);
|
||||
|
||||
//screenSpaceSampleRadius is in pixels
|
||||
float screenSpaceSampleRadius = -uProjScale * radius / origin.z;
|
||||
//screenSpaceSampleRadius = clamp(screenSpaceSampleRadius, 0.0f, -uProjScale * radius);
|
||||
|
||||
float rotationAngleOffset = 30 * originScreenCoord.x ^ originScreenCoord.y + 10 * originScreenCoord.x * originScreenCoord.y;
|
||||
|
||||
float sum = 0.0;
|
||||
for (int i = 0; i < uNumOfSamples; i++) {
|
||||
sum += sampleAO(originScreenCoord, origin, originNormal, screenSpaceSampleRadius, i, rotationAngleOffset, radius);
|
||||
float sum = 0.0f;
|
||||
for(int i = 0; i < uNumOfSamples; i++) {
|
||||
sum += sampleAO(originScreenCoord, origin, originNormal, screenSpaceSampleRadius, i, rotationAngleOffset, radius, radius2);
|
||||
}
|
||||
|
||||
//float A = max(0.0, 1.0 - sum * (2.0f / uNumOfSamples));
|
||||
float A = 1.0 - sum * (2.0f * uIntensityScale / float(uNumOfSamples));
|
||||
float A = 1.0f - sum * (2.0f * uIntensityScale / float(uNumOfSamples));
|
||||
AO = clamp(pow(A, uContrast), 0.0f, 1.0f);
|
||||
//AO = screenSpaceSampleRadius;
|
||||
//AO = vec4(originNormal, 1.0f);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
#version 430
|
||||
|
||||
#define MIP_MAPS_LEVELS (5)
|
||||
|
||||
#define LOWER_MIP_LEVEL (2)
|
||||
//Number of samples per pixel
|
||||
uniform int uNumOfSamples;
|
||||
//#define uNumOfSamples (11)
|
||||
|
||||
//Number of turns around the cirle
|
||||
uniform int uNumOfTurns;
|
||||
//#define uNumOfTurns (7)
|
||||
|
||||
layout (binding = 0) uniform sampler2D ViewSpaceZ;
|
||||
|
||||
uniform vec4 uProjInfo;
|
||||
|
||||
uniform float uProjScale;
|
||||
//#define ProjScale 500
|
||||
|
||||
uniform float uRadius;
|
||||
//#define Radius 1.0f
|
||||
|
||||
uniform float uBias;
|
||||
//#define Bias 0.012f
|
||||
|
||||
uniform float uContrast;
|
||||
//#define IntensityDivR6 1
|
||||
|
||||
uniform float uIntensityScale;
|
||||
|
||||
out float AO;
|
||||
|
||||
vec3 getVSPosition(ivec2 ScreenSpaceCoord, int mipmaplevel) {
|
||||
float z = texelFetch(ViewSpaceZ, ScreenSpaceCoord, mipmaplevel).r;
|
||||
//Get the xy view space coordinates and add the z value from ViewSpaceZ buffer.
|
||||
return vec3((uProjInfo[0] + (ScreenSpaceCoord.x * uProjInfo[1])) * z, (uProjInfo[2] + (ScreenSpaceCoord.y * uProjInfo[3])) * z, z);
|
||||
}
|
||||
|
||||
vec3 getVSFaceNormal(vec3 ViewSpacePosition) {
|
||||
// Get tangets vector for the plane and ViewSpacePositin... don't ask how this functions works. It's pure magic.
|
||||
// They do this and it just works... I would guess that they approximate the function of a plane from pixels close to the pixel were on now.
|
||||
return normalize(cross(dFdx(ViewSpacePosition), dFdy(ViewSpacePosition)));
|
||||
}
|
||||
|
||||
|
||||
vec3 getSampleViewSpacePos(ivec2 ScreenSpaceCoord, int SampleIndex, float RotationAngle, float ScreenSpaceSampleRadius){
|
||||
// SampleIndex + 0.5f so that we alpha != 0, since if alpha = 0 then screenSpaceSampleTexel will be the same texel as origin.
|
||||
float alpha = float(SampleIndex + 0.5f) * (1.0f / uNumOfSamples);
|
||||
|
||||
// Angle to where to sample
|
||||
float angle = alpha * (uNumOfTurns * 6.28f) + RotationAngle;
|
||||
|
||||
//Lenght to were to sample
|
||||
ScreenSpaceSampleRadius = ScreenSpaceSampleRadius * alpha;
|
||||
|
||||
vec2 screenSpaceSampleOffsetVecor = vec2(cos(angle), sin(angle));
|
||||
|
||||
int mipmapLevel = clamp(int(floor(log2(-ScreenSpaceSampleRadius))) - LOWER_MIP_LEVEL, 0, MIP_MAPS_LEVELS);
|
||||
// Get texel coordinate on where to sample by going screenSpaceSampleOffsetVecor direction in ScreenSpaceSampleRadius units from ScreenSpaceCoord (the point being shaded);
|
||||
ivec2 screenSpaceSampleTexel = (ivec2(ScreenSpaceSampleRadius * screenSpaceSampleOffsetVecor) + ScreenSpaceCoord) >> mipmapLevel;
|
||||
|
||||
return getVSPosition(screenSpaceSampleTexel, mipmapLevel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float sampleAO(ivec2 ScreenSpaceCoord, vec3 Origin, vec3 OriginNormal, float ScreenSpaceSampleRadius, int SampleIndex, float RotationAngle, float Radius, float Radius2) {
|
||||
vec3 sampleViewSpacePosition = getSampleViewSpacePos(ScreenSpaceCoord, SampleIndex, RotationAngle, ScreenSpaceSampleRadius);
|
||||
vec3 sampleVector = Origin - sampleViewSpacePosition;
|
||||
// vv = sampleVectorLenght ^ 2
|
||||
float vv = dot(sampleVector, sampleVector);
|
||||
// vn = angle between sampleVector and Normal
|
||||
float vn = dot(sampleVector, OriginNormal);
|
||||
|
||||
const float epsilon = 0.01f;
|
||||
|
||||
// vv < radius2 if the vector is shorter then the radius;
|
||||
// vn - bias, offset the angle to reduse self occlusion.
|
||||
// epsilon is here to make divison by 0 impossible.
|
||||
return float(vv < Radius2) * max((vn - uBias) / (epsilon + vv), 0.0);
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
ivec2 originScreenCoord = ivec2(gl_FragCoord.xy);
|
||||
|
||||
// We always get the Orginin from the level 0 of the mipmaps
|
||||
vec3 origin = getVSPosition(originScreenCoord, 0);
|
||||
|
||||
float radius;
|
||||
|
||||
if(origin.z < uRadius){
|
||||
radius = origin.z;
|
||||
} else {
|
||||
radius = uRadius;
|
||||
}
|
||||
|
||||
float radius2 = radius * radius;
|
||||
|
||||
vec3 originNormal = getVSFaceNormal(origin);
|
||||
//AO = originNormal;
|
||||
//return;
|
||||
|
||||
//screenSpaceSampleRadius is in pixels
|
||||
float screenSpaceSampleRadius = -uProjScale * radius / origin.z;
|
||||
|
||||
//screenSpaceSampleRadius = clamp(screenSpaceSampleRadius, 0.0f, pow(2, MIP_MAPS_LEVELS * LOWER_MIP_LEVEL + 1));
|
||||
//AO = clamp(int(floor(log2(screenSpaceSampleRadius))) - LOWER_MIP_LEVEL, 0, MIP_MAPS_LEVELS);
|
||||
//return;
|
||||
|
||||
float rotationAngleOffset = 30 * originScreenCoord.x ^ originScreenCoord.y + 10 * originScreenCoord.x * originScreenCoord.y;
|
||||
|
||||
float sum = 0.0f;
|
||||
for(int i = 0; i < uNumOfSamples; i++) {
|
||||
sum += sampleAO(originScreenCoord, origin, originNormal, screenSpaceSampleRadius, i, rotationAngleOffset, radius, radius2);
|
||||
}
|
||||
|
||||
//float A = max(0.0, 1.0 - sum * (2.0f / uNumOfSamples));
|
||||
float A = 1.0f - sum * (2.0f * uIntensityScale / float(uNumOfSamples));
|
||||
AO = clamp(pow(A, uContrast), 0.0f, 1.0f);
|
||||
//AO = vec4(originNormal, 1.0f);
|
||||
}
|
||||
@@ -31,12 +31,30 @@ void SSAOPass::InitializeShaderProgram()
|
||||
|
||||
void SSAOPass::InitializeBuffer()
|
||||
{
|
||||
GenerateTexture(&m_SSAOTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_R8, GL_RED, GL_FLOAT);
|
||||
glGenTextures(1, &m_SSAOTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_SSAOTexture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RED, GL_FLOAT, nullptr);
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_R32I, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RED_INTEGER, GL_INT, nullptr);
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RGB, GL_FLOAT, nullptr);
|
||||
|
||||
m_SSAOFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_SSAOFramBuffer.Generate();
|
||||
|
||||
GenerateTexture(&m_SSAOViewSpaceZTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_R32F, GL_RED, GL_FLOAT);
|
||||
glGenTextures(1, &m_SSAOViewSpaceZTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_SSAOViewSpaceZTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RED, GL_FLOAT, nullptr);
|
||||
//glTexStorage2D(GL_TEXTURE_2D, MAX_MIP_LEVEL, GL_R32F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);;
|
||||
//glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, GL_RED, GL_FLOAT, nullptr);
|
||||
//glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
||||
|
||||
m_SSAOViewSpaceZFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOViewSpaceZTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_SSAOViewSpaceZFramBuffer.Generate();
|
||||
@@ -45,12 +63,12 @@ void SSAOPass::InitializeBuffer()
|
||||
void SSAOPass::ClearBuffer()
|
||||
{
|
||||
m_SSAOFramBuffer.Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_SSAOFramBuffer.Unbind();
|
||||
|
||||
m_SSAOViewSpaceZFramBuffer.Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_SSAOViewSpaceZFramBuffer.Unbind();
|
||||
}
|
||||
@@ -64,17 +82,6 @@ void SSAOPass::Setting(float radius, float bias, float contrast, float intensity
|
||||
m_NumOfTurns = NumOfTurns;
|
||||
}
|
||||
|
||||
void SSAOPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
|
||||
{
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, nullptr);
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
void SSAOPass::Draw(GLuint depthBuffer, Camera* camera)
|
||||
{
|
||||
@@ -111,6 +118,11 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera)
|
||||
(-2.0 / (m_Renderer->GetViewportSize().Height * camera->ProjectionMatrix()[1][1]))
|
||||
);
|
||||
|
||||
m_SSAOViewSpaceZFramBuffer.Unbind();
|
||||
|
||||
//glBindTexture(GL_TEXTURE_2D, m_SSAOViewSpaceZTexture);
|
||||
//glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, GL_RED, GL_FLOAT, &m_SSAOViewSpaceZTexture);
|
||||
//glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
m_SSAOFramBuffer.Bind();
|
||||
m_SSAOProgram->Bind();
|
||||
@@ -119,7 +131,7 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera)
|
||||
glBindTexture(GL_TEXTURE_2D, m_SSAOViewSpaceZTexture);
|
||||
|
||||
// How many pixel there are in a 1m long object 1m away from the camera
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uProjScale"), m_Renderer->GetViewportSize().Height / (-2.0f * glm::tan(camera->FOV() * 0.5f)));
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uProjScale"), m_Renderer->GetViewportSize().Height / (-2.0f * glm::tan(glm::radians(camera->FOV()) * 0.5f)));
|
||||
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uRadius"), m_Radius);
|
||||
glUniform1f(glGetUniformLocation(SSAOShaderHandle, "uBias"), m_Bias);
|
||||
@@ -135,7 +147,3 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera)
|
||||
m_DrawBloomPass->ClearBuffer();
|
||||
m_DrawBloomPass->Draw(m_SSAOTexture);
|
||||
}
|
||||
|
||||
void ComputeAO(GLuint depthBuffer, Camera* camera) {
|
||||
|
||||
}
|
||||
@@ -33,16 +33,10 @@ file(GLOB SOURCE_FILES_Network
|
||||
"Network/*.cpp"
|
||||
)
|
||||
source_group(Network FILES ${SOURCE_FILES_Network})
|
||||
|
||||
file(GLOB SOURCE_FILES
|
||||
"${INCLUDE_PATH}/*.h"
|
||||
"*.cpp"
|
||||
)
|
||||
list(REMOVE_ITEM SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")
|
||||
source_group(Game FILES ${SOURCE_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${SOURCE_FILES}
|
||||
"Game.cpp"
|
||||
"MiniDump.cpp"
|
||||
${SOURCE_FILES_Systems}
|
||||
${SOURCE_FILES_Systems_Weapon}
|
||||
${SOURCE_FILES_Events}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
#include "CapturePointsEntitySystem.h"
|
||||
#include "Systems/InterpolationSystem.h"
|
||||
#include "Systems/SoundSystem.h"
|
||||
#include "Systems/RaptorCopterSystem.h"
|
||||
#include "Systems/ExplosionEffectSystem.h"
|
||||
#include "Systems/HealthSystem.h"
|
||||
#include "Systems/PlayerMovementSystem.h"
|
||||
#include "Systems/SpawnerSystem.h"
|
||||
#include "Systems/PlayerSpawnSystem.h"
|
||||
#include "Systems/Weapon/WeaponSystem.h"
|
||||
#include "Systems/LifetimeSystem.h"
|
||||
#include "Systems/CapturePointSystem.h"
|
||||
#include "Systems/CapturePointHUDSystem.h"
|
||||
#include "Systems/PickupSpawnSystem.h"
|
||||
#include "Systems/AmmoPickupSystem.h"
|
||||
#include "Systems/DamageIndicatorSystem.h"
|
||||
#include "Systems/AmmunitionHUDSystem.h"
|
||||
#include "Systems/KillFeedSystem.h"
|
||||
#include "GUI/ButtonSystem.h"
|
||||
#include "GUI/MainMenuSystem.h"
|
||||
#include "Collision/FillOctreeSystem.h"
|
||||
#include "Collision/FillFrustumOctreeSystem.h"
|
||||
#include "Rendering/AnimationSystem.h"
|
||||
#include "Core/UniformScaleSystem.h"
|
||||
#include "Systems/HealthHUDSystem.h"
|
||||
#include "Systems/PlayerDeathSystem.h"
|
||||
#include "Rendering/BoneAttachmentSystem.h"
|
||||
#include "Collision/CollisionSystem.h"
|
||||
#include "Collision/TriggerSystem.h"
|
||||
#include "Rendering/RenderSystem.h"
|
||||
#include "Editor/EditorSystem.h"
|
||||
|
||||
CapturePointsEntitySystem::CapturePointsEntitySystem(EventBroker* eventBroker, bool isClient, bool isServer, IRenderer* renderer, RenderFrame* renderFrame)
|
||||
: EntitySystem(eventBroker, isClient, isServer)
|
||||
, m_Renderer(renderer)
|
||||
, m_RenderFrame(renderFrame)
|
||||
{
|
||||
// Create Octrees
|
||||
// TODO: Perhaps the world bounds should be set in some non-arbitrary way instead of this.
|
||||
AABB boxContainingTheWorld(glm::vec3(-300), glm::vec3(300));
|
||||
m_OctreeCollision = new Octree<EntityAABB>(boxContainingTheWorld, 4);
|
||||
m_OctreeTrigger = new Octree<EntityAABB>(boxContainingTheWorld, 4);
|
||||
m_OctreeFrustrumCulling = new Octree<EntityAABB>(boxContainingTheWorld, 4);
|
||||
|
||||
// All systems with orderlevel 0 will be updated first.
|
||||
unsigned int updateOrderLevel = 0;
|
||||
AddSystem<InterpolationSystem>(updateOrderLevel);
|
||||
++updateOrderLevel;
|
||||
AddSystem<SoundSystem>(updateOrderLevel);
|
||||
AddSystem<RaptorCopterSystem>(updateOrderLevel);
|
||||
AddSystem<ExplosionEffectSystem>(updateOrderLevel);
|
||||
AddSystem<HealthSystem>(updateOrderLevel);
|
||||
AddSystem<PlayerMovementSystem>(updateOrderLevel);
|
||||
AddSystem<SpawnerSystem>(updateOrderLevel);
|
||||
AddSystem<PlayerSpawnSystem>(updateOrderLevel);
|
||||
AddSystem<WeaponSystem>(updateOrderLevel, m_Renderer, m_OctreeCollision);
|
||||
AddSystem<LifetimeSystem>(updateOrderLevel);
|
||||
AddSystem<CapturePointSystem>(updateOrderLevel);
|
||||
AddSystem<CapturePointHUDSystem>(updateOrderLevel);
|
||||
AddSystem<PickupSpawnSystem>(updateOrderLevel);
|
||||
AddSystem<AmmoPickupSystem>(updateOrderLevel);
|
||||
AddSystem<DamageIndicatorSystem>(updateOrderLevel);
|
||||
AddSystem<AmmunitionHUDSystem>(updateOrderLevel);
|
||||
AddSystem<KillFeedSystem>(updateOrderLevel);
|
||||
AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
|
||||
AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
|
||||
// Populate Octree with collidables
|
||||
++updateOrderLevel;
|
||||
AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
|
||||
AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeTrigger, "Player");
|
||||
AddSystem<FillFrustumOctreeSystem>(updateOrderLevel, m_OctreeFrustrumCulling);
|
||||
AddSystem<AnimationSystem>(updateOrderLevel);
|
||||
AddSystem<UniformScaleSystem>(updateOrderLevel);
|
||||
AddSystem<HealthHUDSystem>(updateOrderLevel);
|
||||
AddSystem<PlayerDeathSystem>(updateOrderLevel);
|
||||
// Collision and TriggerSystem should update after player.
|
||||
++updateOrderLevel;
|
||||
AddSystem<BoneAttachmentSystem>(updateOrderLevel);
|
||||
AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);
|
||||
AddSystem<TriggerSystem>(updateOrderLevel, m_OctreeTrigger);
|
||||
++updateOrderLevel;
|
||||
AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame, m_OctreeFrustrumCulling);
|
||||
++updateOrderLevel;
|
||||
AddSystem<EditorSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
|
||||
}
|
||||
|
||||
CapturePointsEntitySystem::~CapturePointsEntitySystem()
|
||||
{
|
||||
if (m_OctreeFrustrumCulling != nullptr) {
|
||||
delete m_OctreeFrustrumCulling;
|
||||
}
|
||||
if (m_OctreeCollision != nullptr) {
|
||||
delete m_OctreeCollision;
|
||||
}
|
||||
if (m_OctreeTrigger != nullptr) {
|
||||
delete m_OctreeTrigger;
|
||||
}
|
||||
}
|
||||
+101
-14
@@ -1,8 +1,34 @@
|
||||
#include "Game.h"
|
||||
#include "Core/EntityFileWriter.h"
|
||||
#include "Network/MultiplayerSnapshotFilter.h"
|
||||
#include "Collision/FillOctreeSystem.h"
|
||||
#include "Collision/FillFrustumOctreeSystem.h"
|
||||
#include "Collision/EntityAABB.h"
|
||||
#include "Collision/TriggerSystem.h"
|
||||
#include "Collision/CollisionSystem.h"
|
||||
#include "Systems/RaptorCopterSystem.h"
|
||||
#include "Systems/HealthSystem.h"
|
||||
#include "Systems/PlayerMovementSystem.h"
|
||||
#include "Systems/SpawnerSystem.h"
|
||||
#include "Systems/PlayerSpawnSystem.h"
|
||||
#include "CapturePointsEntitySystem.h"
|
||||
#include "Systems/PlayerDeathSystem.h"
|
||||
#include "Core/EntityFileWriter.h"
|
||||
#include "Game/Systems/CapturePointSystem.h"
|
||||
#include "Game/Systems/CapturePointHUDSystem.h"
|
||||
#include "Game/Systems/PickupSpawnSystem.h"
|
||||
#include "Game/Systems/AmmoPickupSystem.h"
|
||||
#include "Game/Systems/DamageIndicatorSystem.h"
|
||||
#include "Game/Systems/Weapon/WeaponSystem.h"
|
||||
#include "Rendering/AnimationSystem.h"
|
||||
#include "Game/Systems/HealthHUDSystem.h"
|
||||
#include "Rendering/BoneAttachmentSystem.h"
|
||||
#include "Game/Systems/LifetimeSystem.h"
|
||||
#include "../Engine/Core/UniformScaleSystem.h"
|
||||
#include "Rendering/AnimationSystem.h"
|
||||
#include "Network/MultiplayerSnapshotFilter.h"
|
||||
#include "Game/Systems/AmmunitionHUDSystem.h"
|
||||
#include "Game/Systems/KillFeedSystem.h"
|
||||
#include "GUI/ButtonSystem.h"
|
||||
#include "GUI/MainMenuSystem.h"
|
||||
|
||||
|
||||
Game::Game(int argc, char* argv[])
|
||||
{
|
||||
@@ -22,7 +48,6 @@ Game::Game(int argc, char* argv[])
|
||||
ResourceManager::UseThreading = m_Config->Get<bool>("Multithreading.ResourceLoading", true);
|
||||
DisableMemoryPool::Value = m_Config->Get<bool>("Debug.DisableMemoryPool", false);
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
||||
// HACK: This shouldn't be a config variable
|
||||
PlayerSpawnSystem::SetRespawnTime(m_Config->Get<float>("Debug.RespawnTime", 15.0f));
|
||||
|
||||
// Create the core event broker
|
||||
@@ -49,30 +74,91 @@ Game::Game(int argc, char* argv[])
|
||||
m_InputProxy->AddHandler<MouseInputHandler>();
|
||||
m_InputProxy->LoadBindings("Input.ini");
|
||||
|
||||
// Create the sound manager
|
||||
//m_SoundManager = new SoundManager(m_World, m_EventBroker);
|
||||
// Create a world
|
||||
m_World = new World(m_EventBroker);
|
||||
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
|
||||
if (!mapToLoad.empty()) {
|
||||
auto file = ResourceManager::Load<EntityFile>(mapToLoad);
|
||||
EntityFilePreprocessor fpp(file);
|
||||
fpp.RegisterComponents(m_World);
|
||||
EntityFileParser fp(file);
|
||||
fp.MergeEntities(m_World);
|
||||
}
|
||||
|
||||
// Create an entity system
|
||||
m_EntitySystem = new CapturePointsEntitySystem(m_EventBroker, m_IsClient, m_IsServer, m_Renderer, m_RenderFrame);
|
||||
// Create the sound manager
|
||||
m_SoundManager = new SoundManager(m_World, m_EventBroker);
|
||||
|
||||
// Initialize network
|
||||
if (m_Config->Get<bool>("Networking.StartNetwork", false)) {
|
||||
if (m_IsServer) {
|
||||
m_NetworkServer = new Server(m_EntitySystem, m_EventBroker, m_NetworkPort);
|
||||
m_NetworkServer = new Server(m_World, m_EventBroker, m_NetworkPort);
|
||||
m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " SERVER");
|
||||
} else if (m_IsClient) {
|
||||
m_NetworkClient = new Client(m_EntitySystem, m_EventBroker, std::make_unique<MultiplayerSnapshotFilter>(m_EventBroker));
|
||||
m_NetworkClient = new Client(m_World, m_EventBroker, std::make_unique<MultiplayerSnapshotFilter>(m_EventBroker));
|
||||
m_NetworkClient->Connect(m_NetworkAddress, m_NetworkPort);
|
||||
m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " CLIENT");
|
||||
}
|
||||
}
|
||||
|
||||
// Create Octrees
|
||||
// TODO: Perhaps the world bounds should be set in some non-arbitrary way instead of this.
|
||||
AABB boxContainingTheWorld(glm::vec3(-300), glm::vec3(300));
|
||||
m_OctreeCollision = new Octree<EntityAABB>(boxContainingTheWorld, 4);
|
||||
m_OctreeTrigger = new Octree<EntityAABB>(boxContainingTheWorld, 4);
|
||||
m_OctreeFrustrumCulling = new Octree<EntityAABB>(boxContainingTheWorld, 4);
|
||||
// Create system pipeline
|
||||
m_SystemPipeline = new SystemPipeline(m_World, m_EventBroker, m_IsClient, m_IsServer);
|
||||
|
||||
// All systems with orderlevel 0 will be updated first.
|
||||
unsigned int updateOrderLevel = 0;
|
||||
m_SystemPipeline->AddSystem<InterpolationSystem>(updateOrderLevel);
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<SoundSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<RaptorCopterSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<ExplosionEffectSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<HealthSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<PlayerMovementSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<SpawnerSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<PlayerSpawnSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<WeaponSystem>(updateOrderLevel, m_Renderer, m_OctreeCollision);
|
||||
m_SystemPipeline->AddSystem<LifetimeSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CapturePointHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<AmmoPickupSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<AmmunitionHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
|
||||
m_SystemPipeline->AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
|
||||
// Populate Octree with collidables
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
|
||||
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeTrigger, "Player");
|
||||
m_SystemPipeline->AddSystem<FillFrustumOctreeSystem>(updateOrderLevel, m_OctreeFrustrumCulling);
|
||||
m_SystemPipeline->AddSystem<AnimationSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<UniformScaleSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<HealthHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<PlayerDeathSystem>(updateOrderLevel);
|
||||
// Collision and TriggerSystem should update after player.
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<BoneAttachmentSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);
|
||||
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel, m_OctreeTrigger);
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame, m_OctreeFrustrumCulling);
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<EditorSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
|
||||
|
||||
m_LastTime = glfwGetTime();
|
||||
}
|
||||
|
||||
Game::~Game()
|
||||
{
|
||||
delete m_EntitySystem;
|
||||
delete m_SystemPipeline;
|
||||
delete m_OctreeFrustrumCulling;
|
||||
delete m_OctreeCollision;
|
||||
delete m_OctreeTrigger;
|
||||
delete m_SoundManager;
|
||||
if (m_NetworkClient != nullptr) {
|
||||
delete m_NetworkClient;
|
||||
@@ -80,6 +166,7 @@ Game::~Game()
|
||||
if (m_NetworkServer != nullptr) {
|
||||
delete m_NetworkServer;
|
||||
}
|
||||
delete m_World;
|
||||
delete m_InputProxy;
|
||||
delete m_InputManager;
|
||||
delete m_RenderFrame;
|
||||
@@ -108,7 +195,7 @@ void Game::Tick()
|
||||
m_EventBroker->Swap();
|
||||
|
||||
PerformanceTimer::StartTimerAndStopPrevious("SoundManager");
|
||||
//m_SoundManager->Update(dt);
|
||||
m_SoundManager->Update(dt);
|
||||
|
||||
// Update network
|
||||
PerformanceTimer::StartTimerAndStopPrevious("Network");
|
||||
@@ -122,9 +209,9 @@ void Game::Tick()
|
||||
//m_SoundManager->Update(dt);
|
||||
|
||||
// Iterate through systems and update world!
|
||||
PerformanceTimer::StartTimerAndStopPrevious("EntitySystem");
|
||||
PerformanceTimer::StartTimerAndStopPrevious("SystemPipeline");
|
||||
m_EventBroker->Process<SystemPipeline>();
|
||||
m_EntitySystem->Update(dt);
|
||||
m_SystemPipeline->Update(dt);
|
||||
PerformanceTimer::StartTimerAndStopPrevious("RendererUpdate");
|
||||
m_Renderer->Update(dt);
|
||||
PerformanceTimer::StartTimerAndStopPrevious("RendererDraw");
|
||||
|
||||
@@ -192,6 +192,27 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
|
||||
//NextPossibleCapturePoint will be calculated in the next update...
|
||||
}
|
||||
}
|
||||
|
||||
//check for possible winCondition = check if the homebase is owned by the other team
|
||||
bool checkForWinner = false;
|
||||
if (capturePointNumber == m_RedTeamHomeCapturePoint && ownedBy != redTeam)
|
||||
{
|
||||
checkForWinner = true;
|
||||
}
|
||||
if (capturePointNumber == m_BlueTeamHomeCapturePoint && ownedBy != blueTeam)
|
||||
{
|
||||
checkForWinner = true;
|
||||
}
|
||||
|
||||
if (checkForWinner && !m_WinnerWasFound)
|
||||
{
|
||||
//publish Win event
|
||||
Events::Win e;
|
||||
e.TeamThatWon = ownedBy;
|
||||
m_EventBroker->Publish(e);
|
||||
m_WinnerWasFound = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e)
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
#include "Systems/CapturePointsGamemode.h"
|
||||
|
||||
CapturePointsGamemode::CapturePointsGamemode(SystemParams params)
|
||||
: System(params)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointsGamemode::OnCaptured);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &CapturePointsGamemode::OnGameStart);
|
||||
}
|
||||
|
||||
void CapturePointsGamemode::Update(double dt)
|
||||
{
|
||||
if (!m_GameRuning) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto cGamemode = currentGamemode();
|
||||
if (!cGamemode) {
|
||||
setRunning(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_GameTime += dt;
|
||||
(double&)(*cGamemode)["RoundTime"] = m_GameTime;
|
||||
}
|
||||
|
||||
bool CapturePointsGamemode::OnGameStart(const Events::GameStart& e)
|
||||
{
|
||||
if (!isCurrentGamemode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setRunning(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CapturePointsGamemode::OnCaptured(const Events::Captured& e)
|
||||
{
|
||||
if (!m_GameRuning) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto cGamemode = currentGamemode();
|
||||
if (!cGamemode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto winningTeam = winCondition();
|
||||
if (winningTeam) {
|
||||
setRunning(false);
|
||||
|
||||
Events::Win e;
|
||||
e.Team = *winningTeam;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
boost::optional<ComponentWrapper> CapturePointsGamemode::currentGamemode()
|
||||
{
|
||||
auto cGamemodes = m_World->GetComponents("Gamemode");
|
||||
if (cGamemodes->begin() == cGamemodes->end()) {
|
||||
return boost::none;
|
||||
}
|
||||
return *cGamemodes->begin();
|
||||
}
|
||||
|
||||
bool CapturePointsGamemode::isCurrentGamemode()
|
||||
{
|
||||
auto cGamemode = currentGamemode();
|
||||
if (!cGamemode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that we're the current gamemode
|
||||
if ((ComponentInfo::EnumType)(*cGamemode)["Gamemode"] == (*cGamemode)["Gamemode"].Enum("CapturePoints")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boost::optional<ComponentInfo::EnumType> CapturePointsGamemode::winCondition()
|
||||
{
|
||||
auto cCapturePoints = m_World->GetComponents("CapturePoint");
|
||||
|
||||
// If all capture points are owned by the same team, they won
|
||||
ComponentInfo::EnumType winningTeam = -1;
|
||||
for (auto& c : *cCapturePoints) {
|
||||
EntityWrapper e(m_World, c.EntityID);
|
||||
ComponentInfo::EnumType team = e["Team"]["Team"];
|
||||
if (winningTeam != -1 && winningTeam != team) {
|
||||
return boost::none;
|
||||
} else {
|
||||
winningTeam = team;
|
||||
}
|
||||
}
|
||||
|
||||
return winningTeam;
|
||||
}
|
||||
|
||||
void CapturePointsGamemode::setRunning(bool running)
|
||||
{
|
||||
m_GameRuning = running;
|
||||
if (running) {
|
||||
m_GameTime = 0.0;
|
||||
}
|
||||
|
||||
auto cGamemode = currentGamemode();
|
||||
if (cGamemode) {
|
||||
m_GameRuning = running;
|
||||
if (running) {
|
||||
(*cGamemode)["RoundTime"] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ SoundSystem::SoundSystem(SystemParams params)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerHealthPickup, &SoundSystem::OnPlayerHealthPickup);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user