Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/GameInterface/ActorViewer.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 33 Lines | |||||
#include "ps/ProfileViewer.h" | #include "ps/ProfileViewer.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/RenderingOptions.h" | #include "renderer/RenderingOptions.h" | ||||
#include "renderer/Scene.h" | #include "renderer/Scene.h" | ||||
#include "renderer/SkyManager.h" | #include "renderer/SkyManager.h" | ||||
#include "renderer/WaterManager.h" | #include "renderer/WaterManager.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpAttack.h" | |||||
#include "simulation2/components/ICmpOwnership.h" | #include "simulation2/components/ICmpOwnership.h" | ||||
#include "simulation2/components/ICmpPosition.h" | #include "simulation2/components/ICmpPosition.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | #include "simulation2/components/ICmpRangeManager.h" | ||||
#include "simulation2/components/ICmpTerrain.h" | #include "simulation2/components/ICmpTerrain.h" | ||||
#include "simulation2/components/ICmpUnitMotion.h" | #include "simulation2/components/ICmpUnitMotion.h" | ||||
#include "simulation2/components/ICmpVisual.h" | #include "simulation2/components/ICmpVisual.h" | ||||
#include "simulation2/components/ICmpWaterManager.h" | #include "simulation2/components/ICmpWaterManager.h" | ||||
#include "simulation2/helpers/Render.h" | #include "simulation2/helpers/Render.h" | ||||
▲ Show 20 Lines • Show All 313 Lines • ▼ Show 20 Lines | if (m.Entity == INVALID_ENTITY || id != m.CurrentUnitID) | ||||
needsAnimReload = true; | needsAnimReload = true; | ||||
} | } | ||||
if (animation != m.CurrentUnitAnim) | if (animation != m.CurrentUnitAnim) | ||||
needsAnimReload = true; | needsAnimReload = true; | ||||
if (needsAnimReload) | if (needsAnimReload) | ||||
{ | { | ||||
// Emulate the typical simulation animation behaviour. | |||||
CStr anim = animation.LowerCase(); | CStr anim = animation.LowerCase(); | ||||
CStr sound = anim; | |||||
// Emulate the typical simulation animation behaviour | // Speed will be ignored if we have a repeat time. | ||||
float speed; | float repeattime = 0.0f; | ||||
float repeattime = 0.f; | m.CurrentSpeed = 0.0f; | ||||
if (anim == "walk") | if (anim == "walk") | ||||
Silier: needs to be 0 when no moving animation is selected else unit will slide when `Move` button is… | |||||
{ | { | ||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(m.Simulation2, m.Entity); | CmpPtr<ICmpUnitMotion> cmpUnitMotion(m.Simulation2, m.Entity); | ||||
if (cmpUnitMotion) | if (cmpUnitMotion) | ||||
speed = cmpUnitMotion->GetWalkSpeed().ToFloat(); | m.CurrentSpeed = cmpUnitMotion->GetWalkSpeed().ToFloat(); | ||||
else | else | ||||
speed = 7.f; // typical unit speed | m.CurrentSpeed = 7.f; // Typical unit walk speed. | ||||
Done Inline Actions(excess space) elexis: (excess space) | |||||
m.CurrentSpeed = speed; | |||||
} | } | ||||
else if (anim == "run") | else if (anim == "run") | ||||
{ | { | ||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(m.Simulation2, m.Entity); | CmpPtr<ICmpUnitMotion> cmpUnitMotion(m.Simulation2, m.Entity); | ||||
if (cmpUnitMotion) | if (cmpUnitMotion) | ||||
speed = cmpUnitMotion->GetWalkSpeed().ToFloat() * cmpUnitMotion->GetRunMultiplier().ToFloat(); | m.CurrentSpeed = cmpUnitMotion->GetWalkSpeed().ToFloat() * cmpUnitMotion->GetRunMultiplier().ToFloat(); | ||||
else | else | ||||
speed = 12.f; // typical unit speed | m.CurrentSpeed = 12.f; // Typical unit run speed. | ||||
m.CurrentSpeed = speed; | |||||
} | |||||
else if (anim == "melee") | |||||
{ | |||||
speed = 1.f; // speed will be ignored if we have a repeattime | |||||
m.CurrentSpeed = 0.f; | |||||
CStr code = "var cmp = Engine.QueryInterface("+CStr::FromUInt(m.Entity)+", IID_Attack); " + | |||||
"if (cmp) cmp.GetTimers(cmp.GetBestAttack()).repeat; else 0;"; | |||||
m.Simulation2.GetScriptInterface().Eval(code.c_str(), repeattime); | |||||
Done Inline Actions(good!) elexis: (good!) | |||||
} | } | ||||
else if (anim == "attack_melee") | |||||
repeattime = GetRepeatTimeByAttackType("Melee"); | |||||
else if (anim == "attack_ranged") | |||||
repeattime = GetRepeatTimeByAttackType("Ranged"); | |||||
else if (anim == "attack_slaughter") | |||||
repeattime = GetRepeatTimeByAttackType("Slaughter"); | |||||
else if (anim == "attack_capture") | |||||
repeattime = GetRepeatTimeByAttackType("Capture"); | |||||
else | else | ||||
{ | m.CurrentSpeed = 1.0f; | ||||
SilierUnsubmitted Done Inline Actions^ this is wrong Silier: ^ this is wrong | |||||
// Play the animation at normal speed, but movement speed is zero | |||||
speed = 1.f; | |||||
m.CurrentSpeed = 0.f; | |||||
} | |||||
CStr sound; | |||||
if (anim == "melee") | |||||
sound = "attack"; | |||||
Done Inline Actionsso this was bugged whole time ? Silier: so this was bugged whole time ? | |||||
Done Inline ActionsYep. Stan: Yep. | |||||
Done Inline ActionsWhat does bugged mean? Is it an unused variable and the variable is still unused after this patch? elexis: What does bugged mean? Is it an unused variable and the variable is still unused after this… | |||||
Done Inline Actionsblame rP21359 for usage removal and not tiding up Silier: blame rP21359 for usage removal and not tiding up
I did not read code yet when i asked that… | |||||
Done Inline ActionsBugged mean it selected the attack sound always and was not updated when more attack types were added. Stan: Bugged mean it selected the attack sound always and was not updated when more attack types were… | |||||
else if (anim == "build") | |||||
sound = "build"; | |||||
else if (anim.Find("gather_") == 0) | |||||
sound = anim; | |||||
CmpPtr<ICmpVisual> cmpVisual(m.Simulation2, m.Entity); | CmpPtr<ICmpVisual> cmpVisual(m.Simulation2, m.Entity); | ||||
if (cmpVisual) | if (cmpVisual) | ||||
{ | { | ||||
// TODO: SetEntitySelection(anim) | // TODO: SetEntitySelection(anim) | ||||
cmpVisual->SelectAnimation(anim, false, fixed::FromFloat(speed)); | cmpVisual->SelectAnimation(anim, false, fixed::FromFloat(m.CurrentSpeed)); | ||||
SilierUnsubmitted Done Inline Actionsalso this, because animation like build, promotion etc will get movement or with fix to L413 movement Silier: also this, because animation like build, promotion etc will get movement or with fix to L413… | |||||
SilierUnsubmitted Done Inline Actions
Silier: * with fix to L413 no animation speed | |||||
if (repeattime) | if (repeattime) | ||||
Done Inline Actions(would be good to remove the hardcoding without substring construction, but can be done elsewhere) elexis: (would be good to remove the hardcoding without substring construction, but can be done… | |||||
Done Inline ActionsShould be done if/when attack types are made generic. Stan: Should be done if/when attack types are made generic. | |||||
cmpVisual->SetAnimationSyncRepeat(fixed::FromFloat(repeattime)); | cmpVisual->SetAnimationSyncRepeat(fixed::FromFloat(repeattime)); | ||||
} | } | ||||
// update prop list for new entity/animation (relies on needsAnimReload also getting called for entire entity changes) | // update prop list for new entity/animation (relies on needsAnimReload also getting called for entire entity changes) | ||||
m.UpdatePropList(); | m.UpdatePropList(); | ||||
} | } | ||||
m.CurrentUnitID = id; | m.CurrentUnitID = id; | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
void ActorViewer::SetStatsEnabled(bool enabled) | void ActorViewer::SetStatsEnabled(bool enabled) | ||||
{ | { | ||||
if (enabled) | if (enabled) | ||||
g_ProfileViewer.ShowTable("renderer"); | g_ProfileViewer.ShowTable("renderer"); | ||||
else | else | ||||
g_ProfileViewer.ShowTable(""); | g_ProfileViewer.ShowTable(""); | ||||
} | } | ||||
float ActorViewer::GetRepeatTimeByAttackType(std::string type) const | |||||
Done Inline Actionsconst ref? (perhaps one can avoid std::string construction and pass the char*, but probably not so important here) elexis: const ref? (perhaps one can avoid std::string construction and pass the char*, but probably not… | |||||
{ | |||||
CmpPtr<ICmpAttack> cmpAttack(m.Simulation2, m.Entity); | |||||
if (cmpAttack) | |||||
return cmpAttack->GetRepeatTime(type); | |||||
return 0.0f; | |||||
} | |||||
void ActorViewer::Render() | void ActorViewer::Render() | ||||
{ | { | ||||
m.Terrain.MakeDirty(RENDERDATA_UPDATE_COLOR); | m.Terrain.MakeDirty(RENDERDATA_UPDATE_COLOR); | ||||
g_Renderer.SetClearColor(m.Background); | g_Renderer.SetClearColor(m.Background); | ||||
// Set simulation context for rendering purposes | // Set simulation context for rendering purposes | ||||
g_Renderer.SetSimulation(&m.Simulation2); | g_Renderer.SetSimulation(&m.Simulation2); | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
needs to be 0 when no moving animation is selected else unit will slide when Move button is activated in atlas