Merge remote-tracking branch 'origin/master' into MSAA

Conflicts:
	resources/Schema/Entities/CP_Rocky2.xml
This commit is contained in:
Teejoon
2016-03-13 21:28:38 +01:00
11 changed files with 11116 additions and 8906 deletions
-162
View File
@@ -1,162 +0,0 @@
#include "Core/TransformSystem.h"
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::PositionCache;
std::unordered_map<EntityWrapper, glm::quat> TransformSystem::OrientationCache;
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::ScaleCache;
std::unordered_map<EntityWrapper, glm::mat4> TransformSystem::MatrixCache;
int TransformSystem::RecalculatedPositions = 0;
int TransformSystem::RecalculatedOrientations = 0;
int TransformSystem::RecalculatedScales = 0;
TransformSystem::TransformSystem(SystemParams params)
: System(params)
{
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &TransformSystem::OnEntityDeleted);
}
bool TransformSystem::OnEntityDeleted(const Events::EntityDeleted& e)
{
// Clean up deleted entity
PositionCache.erase(e.DeletedEntity);
OrientationCache.erase(e.DeletedEntity);
ScaleCache.erase(e.DeletedEntity);
MatrixCache.erase(e.DeletedEntity);
return true;
}
//glm::mat4 Transform::AbsoluteTransformation(EntityWrapper entity)
//{
// glm::mat4 t = glm::mat4(1.f);
//
// while (entity.Valid()) {
// t = glm::translate((const glm::vec3&)entity["Transform"]["Position"]) * glm::toMat4(glm::quat((const glm::vec3&)entity["Transform"]["Orientation"])) * glm::scale((const glm::vec3&)entity["Transform"]["Scale"]) * t;
// entity = entity.Parent();
// }
//
// return t;
//}
glm::vec3 TransformSystem::AbsolutePosition(World* world, EntityID entity)
{
return TransformSystem::AbsolutePosition(EntityWrapper(world, entity));
}
glm::vec3 TransformSystem::AbsolutePosition(EntityWrapper entity)
{
if (!entity.Valid()) {
return glm::vec3();
}
auto cacheIt = PositionCache.find(entity);
ComponentWrapper cTransform = entity["Transform"];
ComponentWrapper::SubscriptProxy cTransformPosition = cTransform["Position"];
if (cacheIt != PositionCache.end() && !cTransformPosition.Dirty(DirtySetType::Transform)) {
return cacheIt->second;
} else {
EntityWrapper parent = entity.Parent();
// Calculate position
glm::vec3 position = AbsolutePosition(parent) + TransformSystem::AbsoluteOrientation(parent) * (TransformSystem::AbsoluteScale(parent) * (const glm::vec3&)cTransformPosition);
// Cache it
PositionCache[entity] = position;
RecalculatedPositions++;
// Unset dirty flag
cTransformPosition.SetDirty(DirtySetType::Transform, false);
return position;
}
}
glm::vec3 TransformSystem::AbsoluteOrientationEuler(EntityWrapper entity)
{
glm::vec3 orientation;
while (entity.Valid()) {
ComponentWrapper transform = entity["Transform"];
orientation += (Field<glm::vec3>)transform["Orientation"];
entity = entity.Parent();
}
return orientation;
}
glm::quat TransformSystem::AbsoluteOrientation(World* world, EntityID entity)
{
return TransformSystem::AbsoluteOrientation(EntityWrapper(world, entity));
}
glm::quat TransformSystem::AbsoluteOrientation(EntityWrapper entity)
{
if (!entity.Valid()) {
return glm::quat();
}
auto cacheIt = OrientationCache.find(entity);
ComponentWrapper cTransform = entity["Transform"];
ComponentWrapper::SubscriptProxy cTransformOrientation = cTransform["Orientation"];
if (cacheIt != OrientationCache.end() && !cTransformOrientation.Dirty(DirtySetType::Transform)) {
return cacheIt->second;
} else {
EntityWrapper parent = entity.Parent();
// Calculate orientation
glm::quat orientation = AbsoluteOrientation(parent) * glm::quat((const glm::vec3&)cTransformOrientation);
// Cache it
OrientationCache[entity] = orientation;
RecalculatedOrientations++;
// Unset dirty flag
cTransformOrientation.SetDirty(DirtySetType::Transform, false);
return orientation;
}
}
glm::vec3 TransformSystem::AbsoluteScale(World* world, EntityID entity)
{
return TransformSystem::AbsoluteScale(EntityWrapper(world, entity));
}
glm::vec3 TransformSystem::AbsoluteScale(EntityWrapper entity)
{
if (!entity.Valid()) {
return glm::vec3(1.f);
}
auto cacheIt = ScaleCache.find(entity);
ComponentWrapper cTransform = entity["Transform"];
ComponentWrapper::SubscriptProxy cTransformScale = cTransform["Scale"];
if (cacheIt != ScaleCache.end() && !cTransformScale.Dirty(DirtySetType::Transform)) {
return cacheIt->second;
} else {
EntityWrapper parent = entity.Parent();
// Calculate scale
glm::vec3 scale = AbsoluteScale(parent) * (const glm::vec3&)cTransformScale;
// Cache it
ScaleCache[entity] = scale;
RecalculatedPositions++;
// Unset dirty flag
cTransformScale.SetDirty(DirtySetType::Transform, false);
return scale;
}
}
glm::mat4 TransformSystem::ModelMatrix(EntityID entityID, World* world)
{
return ModelMatrix(EntityWrapper(world, entityID));
}
glm::mat4 TransformSystem::ModelMatrix(EntityWrapper entity)
{
auto cacheIt = MatrixCache.find(entity);
ComponentWrapper cTransform = entity["Transform"];
bool isDirty = cTransform["Position"].Dirty(DirtySetType::Transform) || cTransform["Orientation"].Dirty(DirtySetType::Transform) || cTransform["Scale"].Dirty(DirtySetType::Transform);
if (cacheIt != MatrixCache.end() && !isDirty) {
return cacheIt->second;
} else {
glm::mat4 matrix = glm::translate(AbsolutePosition(entity)) * glm::toMat4(AbsoluteOrientation(entity)) * glm::scale(AbsoluteScale(entity));
MatrixCache[entity] = matrix;
return matrix;
}
}
glm::vec3 TransformSystem::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
{
return glm::vec3(matrix * glm::vec4(point.x, point.y, point.z, 1));
}
+11 -2
View File
@@ -108,7 +108,15 @@ void Client::Update(double dt)
hasServerTimedOut();
}
//Network::Update();
if (ImGui::BeginPopupModal("Disconnected", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("You have been disconnected from server.\n\n");
ImGui::SetCursorPosX(ImGui::GetContentRegionAvailWidth() - 120);
if (ImGui::Button("OK", ImVec2(120, 0))) {
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
void Client::parseMessageType(Packet& packet)
@@ -196,7 +204,7 @@ void Client::parseTCPConnect(Packet& packet)
packet.WritePrimitive(m_PlayerID);
m_Unreliable.Send(packet);
// LOG_INFO("Sent UDP Connect Server");
// LOG_INFO("Sent UDP Connect Server");
}
void Client::parsePlayerConnected(Packet & packet)
@@ -676,6 +684,7 @@ void Client::hasServerTimedOut()
if (timeSincePing > m_TimeoutMs) {
// Clear everything and go to menu.
LOG_INFO("Server has timed out, returning to menu, Beep Boop.");
ImGui::OpenPopup("Disconnected");
disconnect();
}
}
+5
View File
@@ -362,6 +362,11 @@ void RenderSystem::fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs,
continue;
}
EntityWrapper entity(world, pointlightC.EntityID);
if (!isEntityVisible(entity)) {
continue;
}
std::shared_ptr<PointLightJob> pointLightJob = std::shared_ptr<PointLightJob>(new PointLightJob(transformC, pointlightC, m_World));
jobs.push_back(pointLightJob);
}
+38 -21
View File
@@ -30,10 +30,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM);
Events::ChangeBGM e;
e.FilePath = "Audio/bgm/MenuMusic.wav";
m_EventBroker->Publish(e);
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &SoundManager::OnSetCamera);
}
SoundManager::~SoundManager()
@@ -67,8 +64,7 @@ void SoundManager::Update(double dt)
deleteInactiveEmitters();
updateEmitters(dt);
updateListener(dt);
if (m_DrumLoopHasBeenStarted)
matchBGMLoop();
matchBGMLoop();
}
void SoundManager::deleteInactiveEmitters()
@@ -363,15 +359,6 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e)
{
if (e.PlayerID == -1) { // Local player
m_LocalPlayer = e.Player;
if (m_DrumLoopHasBeenStarted) {
return true;
}
m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav");
m_CurrentBGMCombo->Type = SoundType::BGM;
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
setGain(m_CurrentBGMCombo, 0);
playSound(m_CurrentBGMCombo);
m_DrumLoopHasBeenStarted = true;
return true;
}
return false;
@@ -394,7 +381,9 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
{
if (m_CurrentBGM != nullptr) {
stopSound(m_CurrentBGM);
if (getSourceState(m_CurrentBGM->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGM);
}
}
m_CurrentBGM = createSource(e.FilePath);
m_CurrentBGM->Type = SoundType::BGM;
@@ -403,6 +392,34 @@ bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
return true;
}
bool SoundManager::OnSetCamera(const Events::SetCamera& e)
{
if (e.CameraEntity.Name() == "Overview_Camera_Start_Menu") {
if (m_CurrentBGMCombo != nullptr) {
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGMCombo);
}
}
Events::ChangeBGM changeBGM;
changeBGM.FilePath = "Audio/BGM/MenuMusic.wav";
m_EventBroker->Publish(changeBGM);
} else if (e.CameraEntity.Name() == "PickTeamCamera") {
Events::ChangeBGM changeBGM;
changeBGM.FilePath = "Audio/BGM/Layer1.wav";
m_EventBroker->Publish(changeBGM);
if (m_CurrentBGMCombo != nullptr) {
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGMCombo);
}
}
m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav");
m_CurrentBGMCombo->Type = SoundType::BGM;
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
setGain(m_CurrentBGMCombo, 0);
playSound(m_CurrentBGMCombo);
}
}
ALenum SoundManager::getSourceState(ALuint source)
{
ALenum state;
@@ -419,14 +436,14 @@ void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundCom
{
float gain;
switch (source->Type) {
case SoundType::SFX:
gain = m_SFXVolumeChannel;
case SoundType::SFX:
gain = m_SFXVolumeChannel;
break;
case SoundType::BGM:
case SoundType::BGM:
gain = m_BGMVolumeChannel;
break;
case SoundType::Announcer:
gain = m_AnnouncerVolumeChannel;
case SoundType::Announcer:
gain = m_AnnouncerVolumeChannel;
break;
default:
gain = 1.f;
-5
View File
@@ -30,11 +30,6 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
Events::PlayAnonuncerVoice go;
go.FilePath = "Audio/Announcer/" + m_Announcer + "/Go.wav";
m_EventBroker->Publish(go);
{
Events::ChangeBGM ev;
ev.FilePath = "Audio/BGM/Layer1.wav";
m_EventBroker->Publish(ev);
}
}
return true;
}
+5 -1
View File
@@ -61,7 +61,11 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
// TODO: 1 Signifies spectator, should probably have real enum here later.
// Spectators should never end up at the class select, instead put them at the SpectatorCamera.
if (swapToClass && m_PickedTeam != 1) {
camName = "PickClassCamera";
if (m_PickedTeam == 2) {
camName = "PickClassCameraRed";
} else if (m_PickedTeam == 3) {
camName = "PickClassCameraBlue";
}
} else if (e.Command == "SwapToTeamPick") {
camName = "PickTeamCamera";
} else {