Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Formation.js
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | Formation.prototype.variablesToSerialize = [ | ||||
"columnar", | "columnar", | ||||
"rearrange", | "rearrange", | ||||
"formationMembersWithAura", | "formationMembersWithAura", | ||||
"width", | "width", | ||||
"depth", | "depth", | ||||
"oldOrientation", | "oldOrientation", | ||||
"twinFormations", | "twinFormations", | ||||
"formationSeparation", | "formationSeparation", | ||||
"offsets" | "offsets", | ||||
"currentSpeedMultiplier" | |||||
Silier: need to add `currentSpeedMultiplier` here | |||||
Not Done Inline ActionsThis might be why a "don't serialize this" exception list is a better idea. wraitii: This might be why a "don't serialize this" exception list is a better idea. | |||||
Not Done Inline ActionsSo that one can add new member variables without making an error if one didnt check whether or not its getting serialized? elexis: So that one can add new member variables without making an error if one didnt check whether or… | |||||
Not Done Inline ActionsWell that's currently the case with implicit serialization :) Stan: Well that's currently the case with implicit serialization :) | |||||
Not Done Inline Actions
Yes, the serialisation-list is an optimisation, so it should be safe-by-default imo. wraitii: > So that one can add new member variables without making an error if one didnt check whether… | |||||
]; | ]; | ||||
Formation.prototype.Init = function(deserialized = false) | Formation.prototype.Init = function(deserialized = false) | ||||
{ | { | ||||
this.sortingClasses = this.template.SortingClasses.split(/\s+/g); | this.sortingClasses = this.template.SortingClasses.split(/\s+/g); | ||||
this.shiftRows = this.template.ShiftRows == "true"; | this.shiftRows = this.template.ShiftRows == "true"; | ||||
this.separationMultiplier = { | this.separationMultiplier = { | ||||
"width": +this.template.UnitSeparationWidthMultiplier, | "width": +this.template.UnitSeparationWidthMultiplier, | ||||
▲ Show 20 Lines • Show All 786 Lines • ▼ Show 20 Lines | else | ||||
var rot = cmpPosition.GetRotation().y; | var rot = cmpPosition.GetRotation().y; | ||||
r.sin = Math.sin(rot); | r.sin = Math.sin(rot); | ||||
r.cos = Math.cos(rot); | r.cos = Math.cos(rot); | ||||
} | } | ||||
return r; | return r; | ||||
}; | }; | ||||
/** | /** | ||||
* Get the formation controller's speed based on its current members. | |||||
*/ | |||||
Formation.prototype.GetCurrentSpeedMultiplier = function() | |||||
{ | |||||
return this.currentSpeedMultiplier; | |||||
}; | |||||
/** | |||||
* Set formation controller's speed based on its current members. | * Set formation controller's speed based on its current members. | ||||
*/ | */ | ||||
Formation.prototype.ComputeMotionParameters = function() | Formation.prototype.ComputeMotionParameters = function() | ||||
Not Done Inline ActionsResult of this function does not change unless member is removed or added. Computing it with every call from unitai is wasteful, because it needs to loop over every member. Silier: Result of this function does not change unless member is removed or added. Computing it with… | |||||
Done Inline ActionsAlso changes (or at least should change) onValueModification, can be subject of a new patch bb: Also changes (or at least should change) onValueModification, can be subject of a new patch | |||||
{ | { | ||||
var maxRadius = 0; | let minSpeed = Infinity; | ||||
var minSpeed = Infinity; | |||||
for (var ent of this.members) | for (let ent of this.members) | ||||
{ | { | ||||
var cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion); | let cmpMemberUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion); | ||||
Done Inline ActionsStrange that doesn't throw a warning that it's defined in the outer scope, I guess js doesn't care. Maybe it could be defined before and reused. Stan: Strange that doesn't throw a warning that it's defined in the outer scope, I guess js doesn't… | |||||
Done Inline Actionsthe one in the outer scope is different though (this are the members, outer scope is the formation ent), probably doesn't error since that is defined later (thus this one forgotten), bb: the one in the outer scope is different though (this are the members, outer scope is the… | |||||
if (cmpUnitMotion) | if (cmpMemberUnitMotion) | ||||
minSpeed = Math.min(minSpeed, cmpUnitMotion.GetWalkSpeed()); | minSpeed = Math.min(minSpeed, cmpMemberUnitMotion.GetWalkSpeed()); | ||||
} | } | ||||
minSpeed *= this.GetSpeedMultiplier(); | let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | ||||
this.currentSpeedMultiplier = minSpeed * this.GetSpeedMultiplier() / cmpUnitMotion.GetWalkSpeed(); | |||||
Not Done Inline Actionscheck for unitmotion? Stan: check for unitmotion?
Can we use this.member instead of functions? | |||||
Done Inline ActionsI guess a formation is assumed to have a unitMotion, it is never checked in this component. What member function you want to use? bb: I guess a formation is assumed to have a unitMotion, it is never checked in this component. | |||||
Done Inline Actions+this.template.SpeedMultiplier; But I guess it should be cached first so meh (I believe member access is faster than function call. Dunno how often this is called. Stan: +this.template.SpeedMultiplier; But I guess it should be cached first so meh (I believe member… | |||||
Done Inline ActionsIt is called every time a walk of a formation is started/ended and when members leave/join/update speed etc. Though I did be in favour of the function call, since this.template.SpeedMultiplier should probably be exposed to OnValueModifications (some tech speeding up all formations, or even a hero speeding up his own formation) bb: It is called every time a walk of a formation is started/ended and when members… | |||||
var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | cmpUnitMotion.SetSpeedMultiplier(this.currentSpeedMultiplier); | ||||
cmpUnitMotion.SetSpeedMultiplier(minSpeed / cmpUnitMotion.GetWalkSpeed()); | |||||
}; | }; | ||||
Formation.prototype.ShapeUpdate = function() | Formation.prototype.ShapeUpdate = function() | ||||
{ | { | ||||
// Check the distance to twin formations, and merge if when | // Check the distance to twin formations, and merge if when | ||||
// the formations could collide | // the formations could collide | ||||
for (var i = this.twinFormations.length - 1; i >= 0; --i) | for (var i = this.twinFormations.length - 1; i >= 0; --i) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |
need to add currentSpeedMultiplier here