mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-16 14:09:00 +07:00
remove process instances
This commit is contained in:
@@ -21,6 +21,11 @@ namespace IsoTools.Internal {
|
||||
IsoQTDependsLookUpper _qtDependsLU = new IsoQTDependsLookUpper();
|
||||
IsoQTVisibilityLookUpper _qtVisibilityLU = new IsoQTVisibilityLookUpper();
|
||||
|
||||
IsoIPool<ParentInfo> _parentInfoPool = new ParentInfoPool(47);
|
||||
IsoAssocList<ParentInfo> _parentInfoList = new IsoAssocList<ParentInfo>(47);
|
||||
Dictionary<IsoObject, Transform> _isoObjectToParent = new Dictionary<IsoObject, Transform>(47);
|
||||
Dictionary<Transform, ParentInfo> _parentToParentInfo = new Dictionary<Transform, ParentInfo>(47);
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// IsoQTBoundsLookUpper
|
||||
@@ -85,6 +90,7 @@ namespace IsoTools.Internal {
|
||||
|
||||
public void LookUpForVisibility(IsoScreenSolver screen_solver, bool include_scene_view) {
|
||||
_screenSolver = screen_solver;
|
||||
_screenSolver._oldVisibles.Clear();
|
||||
var cam_count = FillLookUpCameras(include_scene_view);
|
||||
for ( var i = 0; i < cam_count; ++i ) {
|
||||
var tmp_cam = _tmpCameras[i];
|
||||
@@ -127,6 +133,38 @@ namespace IsoTools.Internal {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// ParentInfo
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
class ParentInfo {
|
||||
public Transform Parent = null;
|
||||
public Vector3 LastTrans = Vector3.zero;
|
||||
public IsoAssocList<IsoObject> IsoObjects = new IsoAssocList<IsoObject>();
|
||||
|
||||
public ParentInfo Init(Transform parent) {
|
||||
Parent = parent;
|
||||
LastTrans = parent ? parent.position : Vector3.zero;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParentInfo Clear() {
|
||||
IsoObjects.Clear();
|
||||
return Init(null);
|
||||
}
|
||||
}
|
||||
|
||||
class ParentInfoPool : IsoPool<ParentInfo> {
|
||||
public ParentInfoPool(int capacity) : base(capacity) {
|
||||
}
|
||||
|
||||
public override ParentInfo CreateItem() {
|
||||
return new ParentInfo();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Properties
|
||||
@@ -156,6 +194,7 @@ namespace IsoTools.Internal {
|
||||
iso_object.Internal.QTBounds,
|
||||
iso_object);
|
||||
_minIsoXY = IsoUtils.Vec2Min(_minIsoXY, iso_object.position);
|
||||
RegisterIsoObjectParent(iso_object);
|
||||
}
|
||||
|
||||
public void OnRemoveIsoObject(IsoObject iso_object) {
|
||||
@@ -166,6 +205,7 @@ namespace IsoTools.Internal {
|
||||
iso_object.Internal.QTItem = null;
|
||||
}
|
||||
ClearIsoObjectDepends(iso_object);
|
||||
UnregisterIsoObjectParent(iso_object);
|
||||
}
|
||||
|
||||
public bool OnMarkDirtyIsoObject(IsoObject iso_object) {
|
||||
@@ -198,9 +238,9 @@ namespace IsoTools.Internal {
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public void StepSortingAction(IsoWorld iso_world, IsoAssocList<IsoObject> iso_objects) {
|
||||
Profiler.BeginSample("IsoScreenSolver.ProcessIsoObjects");
|
||||
ProcessIsoObjects(iso_objects);
|
||||
public void StepSortingAction(IsoWorld iso_world) {
|
||||
Profiler.BeginSample("IsoScreenSolver.ProcessParents");
|
||||
ProcessParents();
|
||||
Profiler.EndSample();
|
||||
Profiler.BeginSample("IsoScreenSolver.ProcessVisibles");
|
||||
ProcessVisibles(iso_world.isSortInSceneView);
|
||||
@@ -232,18 +272,56 @@ namespace IsoTools.Internal {
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Private
|
||||
// Parents
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void ProcessIsoObjects(IsoAssocList<IsoObject> iso_objects) {
|
||||
if ( iso_objects.Count > 0 ) {
|
||||
for ( int i = 0, e = iso_objects.Count; i < e; ++i ) {
|
||||
var iso_object = iso_objects[i];
|
||||
if ( !IsoUtils.Vec2Approximately(
|
||||
iso_object.Internal.LastTrans,
|
||||
iso_object.Internal.Transform.position) )
|
||||
{
|
||||
void RegisterIsoObjectParent(IsoObject iso_object) {
|
||||
var parent = iso_object ? iso_object.transform.parent : null;
|
||||
if ( parent ) {
|
||||
ParentInfo parent_info;
|
||||
if ( _parentToParentInfo.TryGetValue(parent, out parent_info) ) {
|
||||
parent_info.IsoObjects.Add(iso_object);
|
||||
} else {
|
||||
parent_info = _parentInfoPool.Take().Init(parent);
|
||||
parent_info.IsoObjects.Add(iso_object);
|
||||
_parentToParentInfo.Add(parent, parent_info);
|
||||
_parentInfoList.Add(parent_info);
|
||||
}
|
||||
_isoObjectToParent.Add(iso_object, parent);
|
||||
}
|
||||
}
|
||||
|
||||
void UnregisterIsoObjectParent(IsoObject iso_object) {
|
||||
Transform parent;
|
||||
if ( _isoObjectToParent.TryGetValue(iso_object, out parent) ) {
|
||||
ParentInfo parent_info;
|
||||
if ( _parentToParentInfo.TryGetValue(parent, out parent_info) ) {
|
||||
parent_info.IsoObjects.Remove(iso_object);
|
||||
if ( parent_info.IsoObjects.Count == 0 ) {
|
||||
_parentToParentInfo.Remove(parent);
|
||||
_parentInfoList.Remove(parent_info);
|
||||
_parentInfoPool.Release(parent_info.Clear());
|
||||
}
|
||||
}
|
||||
_isoObjectToParent.Remove(iso_object);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Processes
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void ProcessParents() {
|
||||
for ( int i = 0, ie = _parentInfoList.Count; i < ie; ++i ) {
|
||||
var parent_info = _parentInfoList[i];
|
||||
var parent_trans = parent_info.Parent.position;
|
||||
if ( parent_info.LastTrans != parent_trans ) {
|
||||
parent_info.LastTrans = parent_trans;
|
||||
for ( int j = 0, je = parent_info.IsoObjects.Count; j < je; ++j ) {
|
||||
var iso_object = parent_info.IsoObjects[j];
|
||||
iso_object.FixIsoPosition();
|
||||
}
|
||||
}
|
||||
@@ -251,7 +329,6 @@ namespace IsoTools.Internal {
|
||||
}
|
||||
|
||||
void ProcessVisibles(bool include_scene_view) {
|
||||
_oldVisibles.Clear();
|
||||
_qtVisibilityLU.LookUpForVisibility(this, include_scene_view);
|
||||
SwapCurrentVisibles();
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace IsoTools.Internal {
|
||||
|
||||
void PlaceIsoObject(IsoObject iso_object, float depth) {
|
||||
var iso_internal = iso_object.Internal;
|
||||
var old_position = iso_internal.LastTrans;
|
||||
var old_position = iso_internal.Transform.position;
|
||||
iso_internal.Transform.position =
|
||||
IsoUtils.Vec3FromVec2(old_position, depth);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,12 @@ namespace IsoTools.Internal {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Protected
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
protected IsoAssocList<IsoObject> GetIsoObjects() {
|
||||
return _isoObjects;
|
||||
}
|
||||
|
||||
@@ -194,7 +194,6 @@ namespace IsoTools {
|
||||
public IsoMinMax MinMax3d = IsoMinMax.zero;
|
||||
public float Offset3d = 0.0f;
|
||||
public Transform Transform = null;
|
||||
public Vector2 LastTrans = Vector2.zero;
|
||||
public List<Renderer> Renderers = new List<Renderer>();
|
||||
public IsoAssocList<IsoObject> SelfDepends = new IsoAssocList<IsoObject>(47);
|
||||
public IsoAssocList<IsoObject> TheirDepends = new IsoAssocList<IsoObject>(47);
|
||||
@@ -216,7 +215,6 @@ namespace IsoTools {
|
||||
iso_world.IsoToScreen(position),
|
||||
cached_transform.position.z);
|
||||
FixScreenBounds();
|
||||
FixLastTransform();
|
||||
MartDirtyIsoWorld();
|
||||
}
|
||||
}
|
||||
@@ -266,10 +264,6 @@ namespace IsoTools {
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
void FixLastTransform() {
|
||||
Internal.LastTrans = Internal.Transform.position;
|
||||
}
|
||||
|
||||
void MartDirtyIsoWorld() {
|
||||
var iso_world = isoWorld;
|
||||
if ( iso_world ) {
|
||||
@@ -286,7 +280,6 @@ namespace IsoTools {
|
||||
|
||||
void Awake() {
|
||||
FixCachedTransform();
|
||||
FixLastTransform();
|
||||
FixTransform();
|
||||
}
|
||||
|
||||
@@ -302,7 +295,6 @@ namespace IsoTools {
|
||||
protected override void OnTransformParentChanged() {
|
||||
base.OnTransformParentChanged();
|
||||
FixCachedTransform();
|
||||
FixLastTransform();
|
||||
FixTransform();
|
||||
}
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ namespace IsoTools {
|
||||
}
|
||||
|
||||
void StepSortingProcess() {
|
||||
_screenSolver.StepSortingAction(this, GetIsoObjects());
|
||||
_screenSolver.StepSortingAction(this);
|
||||
if ( _sortingSolver.StepSortingAction(this, _screenSolver) ) {
|
||||
Internal_SetDirtyInEditorMode();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user