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

# Conflicts:
#	include/Game/Systems/Weapon/DefenderWeaponBehaviour.h
#	resources/Schema/Components.xsd
#	resources/Schema/Entities/CP_Rocky2.xml
#	resources/Schema/Entities/MuzzleFlashBlue.xml
#	resources/Schema/Entities/MuzzleFlashFire.xml
#	resources/Schema/Entities/MuzzleFlashRed.xml
#	resources/Schema/Types/Entity.xsd
#	resources/Shaders/Sprite.frag.glsl
#	src/Game/Systems/AbilityCooldownHUDSystem.cpp
#	src/Game/Systems/BoostIconsHUDSystem.cpp
#	src/Game/Systems/PlayerMovementSystem.cpp
#	src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp
#	src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp
#	src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp
This commit is contained in:
viktorljung
2016-03-13 15:17:15 +01:00
156 changed files with 25815 additions and 19649 deletions
+42 -36
View File
@@ -31,7 +31,7 @@ void PlayerMovementSystem::Update(double dt)
return;
}
m_SprintEffectTimer = 0.f;
const ComponentPool* pool = m_World->GetComponents("SprintAbility");
auto pool = m_World->GetComponents("SprintAbility");
if (pool == nullptr) {
return;
}
@@ -56,7 +56,7 @@ void PlayerMovementSystem::Update(double dt)
playerEntityModel.Copy(sprintEffect["Model"]);
playerEntityAnimation.Copy(sprintEffect["Animation"]);
sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"];
((glm::vec4&)sprintEffect["ExplosionEffect"]["EndColor"]).w = 0.f;
((Field<glm::vec4>)sprintEffect["ExplosionEffect"]["EndColor"]).w(0.f);
sprintEffect["Animation"]["Speed1"] = 0.0;
sprintEffect["Animation"]["Speed2"] = 0.0;
sprintEffect["Animation"]["Speed3"] = 0.0;
@@ -79,10 +79,10 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
// Aim pitch
EntityWrapper cameraEntity = player.FirstChildByName("Camera");
if (cameraEntity.Valid()) {
glm::vec3& cameraOrientation = cameraEntity["Transform"]["Orientation"];
cameraOrientation.x += controller->Rotation().x;
Field<glm::vec3> cameraOrientation = cameraEntity["Transform"]["Orientation"];
cameraOrientation.x(cameraOrientation.x() + controller->Rotation().x);
// Limit camera pitch so we don't break our necks
cameraOrientation.x = glm::clamp(cameraOrientation.x, -glm::half_pi<float>(), glm::half_pi<float>());
cameraOrientation.x(glm::clamp(cameraOrientation.x(), -glm::half_pi<float>(), glm::half_pi<float>()));
float pitch = cameraOrientation.x;
double time = ((pitch + glm::half_pi<float>()) / glm::pi<float>());
@@ -97,12 +97,12 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
}
ComponentWrapper& cTransform = player["Transform"];
glm::vec3& ori = cTransform["Orientation"];
ori.y += controller->Rotation().y;
Field<glm::vec3> ori = cTransform["Orientation"];
ori.y(ori.y() + controller->Rotation().y);
float playerMovementSpeed = player["Player"]["MovementSpeed"];
float playerCrouchSpeed = player["Player"]["CrouchSpeed"];
glm::vec3& wishDirection = player["Player"]["CurrentWishDirection"];
Field<glm::vec3> wishDirection = player["Player"]["CurrentWishDirection"];
auto playerBoostAssaultEntity = player.FirstChildByName("BoostAssault");
if (playerBoostAssaultEntity.Valid()) {
playerMovementSpeed *= (double)playerBoostAssaultEntity["BoostAssault"]["StrengthOfEffect"];
@@ -122,7 +122,8 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
ComponentWrapper cPhysics = player["Physics"];
//Assault Dash Check
if (player.HasComponent("DashAbility")) {
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"], player.ID);
Field<double> coolDownTimer = player["DashAbility"]["CoolDownTimer"];
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], coolDownTimer, player.ID);
}
wishDirection = controller->Movement() * glm::inverse(glm::quat(ori));
//this makes sure you can only dash in the 4 directions: forw,backw,left,right
@@ -136,21 +137,21 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
wishSpeed = playerMovementSpeed;
}
if (player.ID == m_LocalPlayer.ID) {
if (glm::length(wishDirection) == 0) {
if (glm::length((glm::vec3)wishDirection) == 0) {
// If no key is pressed, reset the distance moved since last step.
m_DistanceMoved = 0;
}
}
glm::vec3& velocity = cPhysics["Velocity"];
Field<glm::vec3> velocity = cPhysics["Velocity"];
bool isOnGround = (bool)cPhysics["IsOnGround"];
//ImGui::Text(isOnGround ? "On ground" : "In air");
//ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
glm::vec3 groundVelocity(0.f, 0.f, 0.f);
groundVelocity.x = velocity.x;
groundVelocity.z = velocity.z;
groundVelocity.x = velocity.x();
groundVelocity.z = velocity.z();
//ImGui::Text("groundVelocity: (%f, %f, %f) |%f|", groundVelocity.x, groundVelocity.y, groundVelocity.z, glm::length(groundVelocity));
//ImGui::Text("wishDirection: (%f, %f, %f) |%f|", wishDirection.x, wishDirection.y, wishDirection.z, glm::length(wishDirection));
float currentSpeedProj = glm::dot(groundVelocity, wishDirection);
float currentSpeedProj = glm::dot(groundVelocity, (glm::vec3)wishDirection);
float addSpeed = wishSpeed - currentSpeedProj;
//ImGui::Text("currentSpeedProj: %f", currentSpeedProj);
//ImGui::Text("wishSpeed: %f", wishSpeed);
@@ -175,8 +176,8 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
if (sniperSprinting) {
accelerationSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"];
}
velocity += accelerationSpeed * wishDirection;
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
velocity += accelerationSpeed * (glm::vec3)wishDirection;
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x(), velocity.y(), velocity.z(), glm::length((glm::vec3)velocity));
}
if (isOnGround) {
@@ -186,7 +187,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
if (controller->Jumping() && !controller->Crouching()) {
if (isOnGround) {
(bool)cPhysics["IsOnGround"] = false;
velocity.y = player["Player"]["JumpSpeed"];
velocity.y(player["Player"]["JumpSpeed"]);
if (player.Valid()) {
@@ -218,7 +219,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
} else if (player.HasComponent("DoubleJump") && !controller->DoubleJumping()) {
//Enter here if player can double jump and is doing so.
(bool)cPhysics["IsOnGround"] = false;
velocity.y = player["DoubleJump"]["DoubleJumpSpeed"];
velocity.y(player["DoubleJump"]["DoubleJumpSpeed"]);
if (player.Valid()) {
EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
@@ -259,20 +260,25 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
}
if (player.HasComponent("AABB")) {
glm::vec3& size = player["AABB"]["Size"];
Field<glm::vec3> size = player["AABB"]["Size"];
if (controller->Crouching()) {
size = glm::vec3(1.f, 1.f, 1.f);
} else {
size = glm::vec3(1.f, 1.6f, 1.f);
if (controller->CrouchingLastFrame() && isOnGround) {
// The collision should resolve this anyway, but
// this is more reliable, since the box gets larger.
Field<glm::vec3> pos = cTransform["Position"];
pos.y(pos.y() + 0.3f);
}
}
}
// TODO: Animations
}
playerStep(dt, player);
controller->Reset();
}
playerStep(dt);
}
@@ -281,11 +287,11 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
// Only apply velocity to local player
ComponentWrapper& cTransform = player["Transform"];
ComponentWrapper& cPhysics = player["Physics"];
glm::vec3& velocity = cPhysics["Velocity"];
Field<glm::vec3> velocity = cPhysics["Velocity"];
bool isOnGround = (bool)cPhysics["IsOnGround"];
// Ground friction
float speed = glm::length(velocity);
float speed = glm::length((glm::vec3)velocity);
static float groundFriction = 7.f;
ImGui::InputFloat("groundFriction", &groundFriction);
static float airFriction = 2.f;
@@ -295,16 +301,16 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
if (speed > 0) {
float drop = speed * friction * (float)dt;
float multiplier = glm::max(speed - drop, 0.f) / speed;
velocity.x *= multiplier;
velocity.z *= multiplier;
velocity.x(velocity.x() * multiplier);
velocity.z(velocity.z() * multiplier);
}
// Gravity
if (cPhysics["Gravity"]) {
velocity.y -= 9.82f * (float)dt;
velocity.y(velocity.y() - (9.82f * (float)dt));
}
glm::vec3& position = cTransform["Position"];
Field<glm::vec3> position = cTransform["Position"];
position += velocity * (float)dt;
}
@@ -327,12 +333,12 @@ void PlayerMovementSystem::setAim(EntityWrapper root, std::string weaponNodeName
}
}
void PlayerMovementSystem::playerStep(double dt)
void PlayerMovementSystem::playerStep(double dt, EntityWrapper player)
{
if (!m_LocalPlayer.Valid()) {
// Position of the local player, used see how far a player has moved.
if(!IsClient) {
return;
}
// Position of the local player, used see how far a player has moved.
glm::vec3 pos = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Transform")["Position"];
// Used to see if a player is airborne.
bool grounded = (bool)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["IsOnGround"];
@@ -343,8 +349,8 @@ void PlayerMovementSystem::playerStep(double dt)
// Player moved a step's distance
// Create footstep sound
Events::PlaySoundOnEntity e;
e.EmitterID = m_LocalPlayer.ID;
e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav";
e.Emitter = m_LocalPlayer;
e.FilePath = m_LeftFoot ? "Audio/Footstep/Footstep2.wav" : "Audio/Footstep/Footstep3.wav";
m_LeftFoot = !m_LeftFoot;
m_EventBroker->Publish(e);
m_DistanceMoved = 0.f;
@@ -500,9 +506,9 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
dashEffectModel.AttachComponent("ExplosionEffect");
dashEffectModel["ExplosionEffect"]["EndColor"] = (glm::vec4)playerModel["Model"]["Color"];
((glm::vec4&)dashEffectModel["ExplosionEffect"]["EndColor"]).w = 0.f;
(double&)dashEffectModel["ExplosionEffect"]["ExplosionDuration"] = dashEffect["Lifetime"]["Lifetime"];
(glm::vec3&)dashEffectModel["ExplosionEffect"]["ExplosionOrigin"] = glm::vec3(0, 1, 0) + (0.2f * controller->Movement());
((Field<glm::vec4>)dashEffectModel["ExplosionEffect"]["EndColor"]).w = 0.f;
(Field<double>)dashEffectModel["ExplosionEffect"]["ExplosionDuration"] = dashEffect["Lifetime"]["Lifetime"];
(Field<glm::vec3>)dashEffectModel["ExplosionEffect"]["ExplosionOrigin"] = glm::vec3(0, 1, 0) + (0.2f * controller->Movement());
@@ -510,7 +516,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
auto animationChildren = dashEffectModel.ChildrenWithComponent("Animation");
for (auto animationEntity : animationChildren) {
(bool&)animationEntity["Animation"]["Play"] = false;
(Field<bool>)animationEntity["Animation"]["Play"] = false;
}
*/
}