IsoWorld refactoring wip

This commit is contained in:
2016-12-23 03:28:07 +07:00
parent 780d0391aa
commit 72c0850445
4 changed files with 189 additions and 172 deletions

View File

@@ -177,7 +177,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2} - target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 1 value: 1.2
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2} - target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
@@ -592,7 +592,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2} - target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 1.2 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2} - target: {fileID: 417424, guid: 185575a05f87743c0b2ddb83dd39c6cd, type: 2}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x

View File

@@ -1,16 +1,15 @@
using UnityEngine; using UnityEngine;
using IsoTools.Internal;
using System.Collections.Generic; using System.Collections.Generic;
#if UNITY_5_5_OR_NEWER #if UNITY_5_5_OR_NEWER
using UnityEngine.Profiling; using UnityEngine.Profiling;
#endif #endif
namespace IsoTools { namespace IsoTools.Internal {
public class IsoScreenSolver { public class IsoScreenSolver {
public Vector2 minXY = Vector2.zero; Vector2 _minIsoXY = Vector2.zero;
public IsoAssocList<IsoObject> curVisibles = new IsoAssocList<IsoObject>(); IsoAssocList<IsoObject> _curVisibles = new IsoAssocList<IsoObject>();
public IsoAssocList<IsoObject> oldVisibles = new IsoAssocList<IsoObject>(); IsoAssocList<IsoObject> _oldVisibles = new IsoAssocList<IsoObject>();
class Sector { class Sector {
public IsoList<IsoObject> objects = new IsoList<IsoObject>(); public IsoList<IsoObject> objects = new IsoList<IsoObject>();
@@ -27,6 +26,24 @@ namespace IsoTools {
List<Renderer> _tmpRenderers = new List<Renderer>(); List<Renderer> _tmpRenderers = new List<Renderer>();
// ---------------------------------------------------------------------
//
// Properties
//
// ---------------------------------------------------------------------
public Vector2 minIsoXY {
get { return _minIsoXY; }
}
public IsoAssocList<IsoObject> curVisibles {
get { return _curVisibles; }
}
public IsoAssocList<IsoObject> oldVisibles {
get { return _oldVisibles; }
}
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// //
// Callbacks // Callbacks
@@ -37,13 +54,13 @@ namespace IsoTools {
} }
public void OnRemoveInstance(IsoObject iso_object) { public void OnRemoveInstance(IsoObject iso_object) {
oldVisibles.Remove(iso_object); _oldVisibles.Remove(iso_object);
curVisibles.Remove(iso_object); _curVisibles.Remove(iso_object);
ClearIsoObjectDepends(iso_object); ClearIsoObjectDepends(iso_object);
} }
public bool OnMarkDirtyInstance(IsoObject iso_object) { public bool OnMarkDirtyInstance(IsoObject iso_object) {
if ( !iso_object.Internal.Dirty && curVisibles.Contains(iso_object) ) { if ( !iso_object.Internal.Dirty && _curVisibles.Contains(iso_object) ) {
iso_object.Internal.Dirty = true; iso_object.Internal.Dirty = true;
return true; return true;
} }
@@ -57,8 +74,8 @@ namespace IsoTools {
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
public void StepSortingAction(IsoWorld iso_world, IsoAssocList<IsoObject> instances) { public void StepSortingAction(IsoWorld iso_world, IsoAssocList<IsoObject> instances) {
Profiler.BeginSample("ResolveNewVisibles"); Profiler.BeginSample("ResolveVisibles");
ResolveNewVisibles(instances); ResolveVisibles(instances);
Profiler.EndSample(); Profiler.EndSample();
Profiler.BeginSample("ResolveSectors"); Profiler.BeginSample("ResolveSectors");
ResolveSectors(iso_world); ResolveSectors(iso_world);
@@ -70,29 +87,52 @@ namespace IsoTools {
} }
public void Clear() { public void Clear() {
curVisibles.Clear(); _curVisibles.Clear();
oldVisibles.Clear(); _oldVisibles.Clear();
_sectors.Clear(); _sectors.Clear();
} }
public void SetupIsoObjectDepends(IsoObject obj_a) {
ClearIsoObjectDepends(obj_a);
var min = obj_a.Internal.MinSector;
var max = obj_a.Internal.MaxSector;
for ( var y = min.y; y < max.y; ++y ) {
for ( var x = min.x; x < max.x; ++x ) {
LookUpSectorDepends(x, y, obj_a);
LookUpSectorRDepends(x, y, obj_a);
}}
}
public void ClearIsoObjectDepends(IsoObject iso_object) {
var their_depends = iso_object.Internal.TheirDepends;
for ( int i = 0, e = their_depends.Count; i < e; ++i ) {
var their_iso_object = their_depends[i];
if ( !their_iso_object.Internal.Dirty ) {
their_iso_object.Internal.SelfDepends.Remove(iso_object);
}
}
iso_object.Internal.SelfDepends.Clear();
iso_object.Internal.TheirDepends.Clear();
}
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// //
// // ResolveVisibles
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
void ResolveNewVisibles(IsoAssocList<IsoObject> instances) { void ResolveVisibles(IsoAssocList<IsoObject> instances) {
oldVisibles.Clear(); _oldVisibles.Clear();
if ( instances.Count > 0 ) { if ( instances.Count > 0 ) {
minXY.Set(float.MaxValue, float.MaxValue); _minIsoXY.Set(float.MaxValue, float.MaxValue);
for ( int i = 0, e = instances.Count; i < e; ++i ) { for ( int i = 0, e = instances.Count; i < e; ++i ) {
var iso_object = instances[i]; var iso_object = instances[i];
var object_pos = iso_object.position; var object_pos = iso_object.position;
if ( minXY.x > object_pos.x ) { if ( _minIsoXY.x > object_pos.x ) {
minXY.x = object_pos.x; _minIsoXY.x = object_pos.x;
} }
if ( minXY.y > object_pos.y ) { if ( _minIsoXY.y > object_pos.y ) {
minXY.y = object_pos.y; _minIsoXY.y = object_pos.y;
} }
if ( !IsoUtils.Vec2Approximately( if ( !IsoUtils.Vec2Approximately(
iso_object.Internal.LastTrans, iso_object.Internal.LastTrans,
@@ -102,21 +142,34 @@ namespace IsoTools {
} }
if ( IsIsoObjectVisible(iso_object) ) { if ( IsIsoObjectVisible(iso_object) ) {
iso_object.Internal.Placed = false; iso_object.Internal.Placed = false;
oldVisibles.Add(iso_object); _oldVisibles.Add(iso_object);
} }
} }
} else { } else {
minXY.Set(0.0f, 0.0f); _minIsoXY.Set(0.0f, 0.0f);
} }
var temp_visibles = curVisibles; var temp_visibles = _curVisibles;
curVisibles = oldVisibles; _curVisibles = _oldVisibles;
oldVisibles = temp_visibles; _oldVisibles = temp_visibles;
} }
void ResolveSectors(IsoWorld iso_world) { bool IsIsoObjectVisible(IsoObject iso_object) {
SetupSectorSize(iso_world); var renderers = GetIsoObjectRenderers(iso_object);
SetupObjectsSectors(); for ( int i = 0, e = renderers.Count; i < e; ++i ) {
SetupSectors(); if ( renderers[i].isVisible ) {
return true;
}
}
return false;
}
List<Renderer> GetIsoObjectRenderers(IsoObject iso_object) {
if ( iso_object.cacheRenderers ) {
return iso_object.Internal.Renderers;
} else {
iso_object.GetComponentsInChildren<Renderer>(_tmpRenderers);
return _tmpRenderers;
}
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@@ -125,27 +178,34 @@ namespace IsoTools {
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
void ResolveSectors(IsoWorld iso_world) {
SetupSectorSize(iso_world);
SetupObjectSectors();
SetupSectors();
}
void SetupSectorSize(IsoWorld iso_world) { void SetupSectorSize(IsoWorld iso_world) {
_sectorsSize = 0.0f; _sectorsSize = 0.0f;
for ( int i = 0, e = curVisibles.Count; i < e; ++i ) { for ( int i = 0, e = _curVisibles.Count; i < e; ++i ) {
var iso_internal = curVisibles[i].Internal; var iso_internal = _curVisibles[i].Internal;
_sectorsSize += IsoUtils.Vec2MaxF(iso_internal.ScreenBounds.size); var size_x = iso_internal.ScreenBounds.x.max - iso_internal.ScreenBounds.x.min;
var size_y = iso_internal.ScreenBounds.y.max - iso_internal.ScreenBounds.y.min;
_sectorsSize += size_x > size_y ? size_x : size_y;
} }
var min_sector_size_xy = iso_world.IsoToScreen(IsoUtils.vec3OneXY) - iso_world.IsoToScreen(Vector3.zero); var min_sector_size = IsoUtils.Vec2MaxF(
var min_sector_size = Mathf.Max(min_sector_size_xy.x, min_sector_size_xy.y); iso_world.IsoToScreen(IsoUtils.vec3OneXY) -
_sectorsSize = curVisibles.Count > 0 iso_world.IsoToScreen(Vector3.zero));
? Mathf.Round(Mathf.Max(min_sector_size, _sectorsSize / curVisibles.Count)) _sectorsSize = _curVisibles.Count > 0
? Mathf.Round(Mathf.Max(min_sector_size, _sectorsSize / _curVisibles.Count))
: min_sector_size; : min_sector_size;
} }
void SetupObjectsSectors() { void SetupObjectSectors() {
if ( curVisibles.Count > 0 ) { if ( _curVisibles.Count > 0 ) {
_sectorsMinNumPos.Set(float.MaxValue, float.MaxValue); _sectorsMinNumPos.Set(float.MaxValue, float.MaxValue);
_sectorsMaxNumPos.Set(float.MinValue, float.MinValue); _sectorsMaxNumPos.Set(float.MinValue, float.MinValue);
for ( int i = 0, e = curVisibles.Count; i < e; ++i ) { for ( int i = 0, e = _curVisibles.Count; i < e; ++i ) {
var iso_internal = curVisibles[i].Internal; var iso_internal = _curVisibles[i].Internal;
// high performance tricks
var min_x = iso_internal.ScreenBounds.x.min / _sectorsSize; var min_x = iso_internal.ScreenBounds.x.min / _sectorsSize;
var min_y = iso_internal.ScreenBounds.y.min / _sectorsSize; var min_y = iso_internal.ScreenBounds.y.min / _sectorsSize;
var max_x = iso_internal.ScreenBounds.x.max / _sectorsSize; var max_x = iso_internal.ScreenBounds.x.max / _sectorsSize;
@@ -174,12 +234,17 @@ namespace IsoTools {
_sectorsNumPosCount = _sectorsMaxNumPos - _sectorsMinNumPos; _sectorsNumPosCount = _sectorsMaxNumPos - _sectorsMinNumPos;
} }
void SetupSectors() {
ResizeSectors((int)(_sectorsNumPosCount.x * _sectorsNumPosCount.y));
FillSectors();
}
void ResizeSectors(int count) { void ResizeSectors(int count) {
if ( _sectors.Count < count ) { if ( _sectors.Count < count ) {
if ( _sectors.Capacity < count ) { if ( _sectors.Capacity < count ) {
_sectors.Capacity = count; _sectors.Capacity = count * 2;
} }
while ( _sectors.Count < _sectors.Capacity ) { while ( _sectors.Count < count ) {
_sectors.Add(new Sector()); _sectors.Add(new Sector());
} }
} }
@@ -188,9 +253,9 @@ namespace IsoTools {
} }
} }
void TuneSectors() { void FillSectors() {
for ( int i = 0, e = curVisibles.Count; i < e; ++i ) { for ( int i = 0, e = _curVisibles.Count; i < e; ++i ) {
var iso_object = curVisibles[i]; var iso_object = _curVisibles[i];
iso_object.Internal.MinSector -= _sectorsMinNumPos; iso_object.Internal.MinSector -= _sectorsMinNumPos;
iso_object.Internal.MaxSector -= _sectorsMinNumPos; iso_object.Internal.MaxSector -= _sectorsMinNumPos;
var min = iso_object.Internal.MinSector; var min = iso_object.Internal.MinSector;
@@ -205,13 +270,8 @@ namespace IsoTools {
} }
} }
void SetupSectors() {
ResizeSectors((int)(_sectorsNumPosCount.x * _sectorsNumPosCount.y));
TuneSectors();
}
Sector FindSector(float num_pos_x, float num_pos_y) { Sector FindSector(float num_pos_x, float num_pos_y) {
if ( num_pos_x < 0 || num_pos_y < 0 ) { if ( num_pos_x < 0.0f || num_pos_y < 0.0f ) {
return null; return null;
} }
if ( num_pos_x >= _sectorsNumPosCount.x || num_pos_y >= _sectorsNumPosCount.y ) { if ( num_pos_x >= _sectorsNumPosCount.x || num_pos_y >= _sectorsNumPosCount.y ) {
@@ -221,6 +281,44 @@ namespace IsoTools {
return _sectors[sector_index]; return _sectors[sector_index];
} }
// ---------------------------------------------------------------------
//
// LookUpSectorDepends
//
// ---------------------------------------------------------------------
void LookUpSectorDepends(float num_pos_x, float num_pos_y, IsoObject obj_a) {
var sec = FindSector(num_pos_x, num_pos_y);
if ( sec != null ) {
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
var obj_b = sec.objects[i];
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_a, obj_b) ) {
obj_a.Internal.SelfDepends.Add(obj_b);
obj_b.Internal.TheirDepends.Add(obj_a);
}
}
}
}
void LookUpSectorRDepends(float num_pos_x, float num_pos_y, IsoObject obj_a) {
var sec = FindSector(num_pos_x, num_pos_y);
if ( sec != null ) {
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
var obj_b = sec.objects[i];
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_b, obj_a) ) {
obj_b.Internal.SelfDepends.Add(obj_a);
obj_a.Internal.TheirDepends.Add(obj_b);
}
}
}
}
bool IsIsoObjectDepends(IsoObject a, IsoObject b) {
return
a.Internal.ScreenBounds.Overlaps(b.Internal.ScreenBounds) &&
IsIsoObjectDepends(a.position, a.size, b.position, b.size);
}
bool IsIsoObjectDepends(Vector3 a_min, Vector3 a_size, Vector3 b_min, Vector3 b_size) { bool IsIsoObjectDepends(Vector3 a_min, Vector3 a_size, Vector3 b_min, Vector3 b_size) {
var a_max = a_min + a_size; var a_max = a_min + a_size;
var b_max = b_min + b_size; var b_max = b_min + b_size;
@@ -256,85 +354,5 @@ namespace IsoTools {
} }
return a_yesno; return a_yesno;
} }
bool IsIsoObjectDepends(IsoObject a, IsoObject b) {
return
a.Internal.ScreenBounds.Overlaps(b.Internal.ScreenBounds) &&
IsIsoObjectDepends(a.position, a.size, b.position, b.size);
}
void LookUpSectorDepends(float num_pos_x, float num_pos_y, IsoObject obj_a) {
var sec = FindSector(num_pos_x, num_pos_y);
if ( sec != null ) {
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
var obj_b = sec.objects[i];
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_a, obj_b) ) {
obj_a.Internal.SelfDepends.Add(obj_b);
obj_b.Internal.TheirDepends.Add(obj_a);
}
}
}
}
void LookUpSectorRDepends(float num_pos_x, float num_pos_y, IsoObject obj_a) {
var sec = FindSector(num_pos_x, num_pos_y);
if ( sec != null ) {
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
var obj_b = sec.objects[i];
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_b, obj_a) ) {
obj_b.Internal.SelfDepends.Add(obj_a);
obj_a.Internal.TheirDepends.Add(obj_b);
}
}
}
}
public void SetupIsoObjectDepends(IsoObject obj_a) {
ClearIsoObjectDepends(obj_a);
var min = obj_a.Internal.MinSector;
var max = obj_a.Internal.MaxSector;
for ( var y = min.y; y < max.y; ++y ) {
for ( var x = min.x; x < max.x; ++x ) {
LookUpSectorDepends(x, y, obj_a);
LookUpSectorRDepends(x, y, obj_a);
}}
}
public void ClearIsoObjectDepends(IsoObject iso_object) {
var their_depends = iso_object.Internal.TheirDepends;
for ( int i = 0, e = their_depends.Count; i < e; ++i ) {
var their_iso_object = their_depends[i];
if ( !their_iso_object.Internal.Dirty ) {
their_iso_object.Internal.SelfDepends.Remove(iso_object);
}
}
iso_object.Internal.SelfDepends.Clear();
iso_object.Internal.TheirDepends.Clear();
}
// ---------------------------------------------------------------------
//
// Private
//
// ---------------------------------------------------------------------
public bool IsIsoObjectVisible(IsoObject iso_object) {
var renderers = GetIsoObjectRenderers(iso_object);
for ( int i = 0, e = renderers.Count; i < e; ++i ) {
if ( renderers[i].isVisible ) {
return true;
}
}
return false;
}
List<Renderer> GetIsoObjectRenderers(IsoObject iso_object) {
if ( iso_object.cacheRenderers ) {
return iso_object.Internal.Renderers;
} else {
iso_object.GetComponentsInChildren<Renderer>(_tmpRenderers);
return _tmpRenderers;
}
}
} }
} }

View File

@@ -1,16 +1,12 @@
using UnityEngine; using UnityEngine;
using IsoTools.Internal;
using System.Collections.Generic; using System.Collections.Generic;
#if UNITY_5_5_OR_NEWER #if UNITY_5_5_OR_NEWER
using UnityEngine.Profiling; using UnityEngine.Profiling;
#endif #endif
namespace IsoTools { namespace IsoTools.Internal {
public class IsoSortingSolver { public class IsoSortingSolver {
public float stepDepth = IsoWorld.DefStepDepth;
public float startDepth = IsoWorld.DefStartDepth;
List<Renderer> _tmpRenderers = new List<Renderer>(); List<Renderer> _tmpRenderers = new List<Renderer>();
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@@ -41,13 +37,13 @@ namespace IsoTools {
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
public bool StepSortingAction(IsoScreenSolver screen_solver){ public bool StepSortingAction(IsoWorld iso_world, IsoScreenSolver screen_solver) {
Profiler.BeginSample("CalculateSectors"); Profiler.BeginSample("ResolveVisibles");
var dirty = ResolveVisibles(screen_solver); var dirty = ResolveVisibles(screen_solver);
Profiler.EndSample(); Profiler.EndSample();
if ( dirty ) { if ( dirty ) {
Profiler.BeginSample("PlaceAllVisibles"); Profiler.BeginSample("PlaceAllVisibles");
PlaceAllVisibles(screen_solver.curVisibles); PlaceAllVisibles(iso_world, screen_solver);
Profiler.EndSample(); Profiler.EndSample();
} }
return dirty; return dirty;
@@ -57,6 +53,9 @@ namespace IsoTools {
_tmpRenderers.Clear(); _tmpRenderers.Clear();
} }
public void Clear() {
}
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// //
// ResolveVisibles // ResolveVisibles
@@ -64,10 +63,10 @@ namespace IsoTools {
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
bool ResolveVisibles(IsoScreenSolver screen_solver) { bool ResolveVisibles(IsoScreenSolver screen_solver) {
var mark_dirty = false;
var old_visibles = screen_solver.oldVisibles; var old_visibles = screen_solver.oldVisibles;
var cur_visibles = screen_solver.curVisibles; var cur_visibles = screen_solver.curVisibles;
var mark_dirty = false;
for ( int i = 0, e = cur_visibles.Count; i < e; ++i ) { for ( int i = 0, e = cur_visibles.Count; i < e; ++i ) {
var iso_object = cur_visibles[i]; var iso_object = cur_visibles[i];
if ( iso_object.Internal.Dirty || !old_visibles.Contains(iso_object) ) { if ( iso_object.Internal.Dirty || !old_visibles.Contains(iso_object) ) {
@@ -79,6 +78,7 @@ namespace IsoTools {
mark_dirty = true; mark_dirty = true;
} }
} }
for ( int i = 0, e = old_visibles.Count; i < e; ++i ) { for ( int i = 0, e = old_visibles.Count; i < e; ++i ) {
var iso_object = old_visibles[i]; var iso_object = old_visibles[i];
if ( !cur_visibles.Contains(iso_object) ) { if ( !cur_visibles.Contains(iso_object) ) {
@@ -86,12 +86,13 @@ namespace IsoTools {
screen_solver.ClearIsoObjectDepends(iso_object); screen_solver.ClearIsoObjectDepends(iso_object);
} }
} }
_tmpRenderers.Clear(); _tmpRenderers.Clear();
return mark_dirty; return mark_dirty;
} }
bool UpdateIsoObjectBounds3d(IsoObject iso_object) { bool UpdateIsoObjectBounds3d(IsoObject iso_object) {
if ( iso_object.mode == IsoObject.Mode.Mode3d ) { if ( iso_object.mode != IsoObject.Mode.Mode3d ) {
var minmax3d = IsoObjectMinMax3D(iso_object); var minmax3d = IsoObjectMinMax3D(iso_object);
var offset3d = iso_object.Internal.Transform.position.z - minmax3d.center; var offset3d = iso_object.Internal.Transform.position.z - minmax3d.center;
if ( iso_object.Internal.MinMax3d.Approximately(minmax3d) || if ( iso_object.Internal.MinMax3d.Approximately(minmax3d) ||
@@ -117,15 +118,15 @@ namespace IsoTools {
var minbounds = center - extents.z; var minbounds = center - extents.z;
var maxbounds = center + extents.z; var maxbounds = center + extents.z;
if ( inited ) { if ( inited ) {
if ( minbounds < result.min ) { if ( result.min > minbounds ) {
result.min = minbounds; result.min = minbounds;
} }
if ( maxbounds > result.max ) { if ( result.max < maxbounds ) {
result.max = maxbounds; result.max = maxbounds;
} }
} else { } else {
inited = true; inited = true;
result = new IsoMinMax(minbounds, maxbounds); result.Set(minbounds, maxbounds);
} }
} }
} }
@@ -147,30 +148,32 @@ namespace IsoTools {
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
void PlaceAllVisibles(IsoAssocList<IsoObject> cur_visibles) { void PlaceAllVisibles(IsoWorld iso_world, IsoScreenSolver screen_solver) {
var depth = startDepth; var start_depth = iso_world.startDepth;
var cur_visibles = screen_solver.curVisibles;
for ( int i = 0, e = cur_visibles.Count; i < e; ++i ) { for ( int i = 0, e = cur_visibles.Count; i < e; ++i ) {
depth = RecursivePlaceIsoObject(cur_visibles[i], depth); start_depth = RecursivePlaceIsoObject(
cur_visibles[i], start_depth, iso_world.stepDepth);
} }
} }
float RecursivePlaceIsoObject(IsoObject iso_object, float depth) { float RecursivePlaceIsoObject(IsoObject iso_object, float depth, float step_depth) {
if ( iso_object.Internal.Placed ) { if ( iso_object.Internal.Placed ) {
return depth; return depth;
} }
iso_object.Internal.Placed = true; iso_object.Internal.Placed = true;
var self_depends = iso_object.Internal.SelfDepends; var self_depends = iso_object.Internal.SelfDepends;
for ( int i = 0, e = self_depends.Count; i < e; ++i ) { for ( int i = 0, e = self_depends.Count; i < e; ++i ) {
depth = RecursivePlaceIsoObject(self_depends[i], depth); depth = RecursivePlaceIsoObject(self_depends[i], depth, step_depth);
} }
if ( iso_object.mode == IsoObject.Mode.Mode3d ) { if ( iso_object.mode == IsoObject.Mode.Mode3d ) {
var zoffset = iso_object.Internal.Offset3d; var zoffset = iso_object.Internal.Offset3d;
var extents = iso_object.Internal.MinMax3d.size; var extents = iso_object.Internal.MinMax3d.size;
PlaceIsoObject(iso_object, depth + extents * 0.5f + zoffset); PlaceIsoObject(iso_object, depth + extents * 0.5f + zoffset);
return depth + extents + stepDepth; return depth + extents + step_depth;
} else { } else {
PlaceIsoObject(iso_object, depth); PlaceIsoObject(iso_object, depth);
return depth + stepDepth; return depth + step_depth;
} }
} }

View File

@@ -159,8 +159,8 @@ namespace IsoTools {
public Ray RayFromIsoCameraToIsoPoint(Vector3 iso_pnt) { public Ray RayFromIsoCameraToIsoPoint(Vector3 iso_pnt) {
var screen_pnt = IsoToScreen(iso_pnt); var screen_pnt = IsoToScreen(iso_pnt);
var min_xy = _screenSolver.minXY; var min_iso_xy = _screenSolver.minIsoXY;
var min_screen_pnt = IsoToScreen(min_xy - Vector2.one); var min_screen_pnt = IsoToScreen(min_iso_xy - Vector2.one);
var max_screen_dist = screen_pnt.y - min_screen_pnt.y; var max_screen_dist = screen_pnt.y - min_screen_pnt.y;
var screen_down_pnt = new Vector2(screen_pnt.x, screen_pnt.y - max_screen_dist); var screen_down_pnt = new Vector2(screen_pnt.x, screen_pnt.y - max_screen_dist);
@@ -358,21 +358,15 @@ namespace IsoTools {
} }
} }
void UpdateSolverProperties() {
_sortingSolver.stepDepth = stepDepth;
_sortingSolver.startDepth = startDepth;
}
void ChangeSortingProperty() { void ChangeSortingProperty() {
MarkDirty(); MarkDirty();
UpdateIsoMatrix(); UpdateIsoMatrix();
FixInstanceTransforms(); FixInstanceTransforms();
UpdateSolverProperties();
} }
void StepSortingProcess() { void StepSortingProcess() {
_screenSolver.StepSortingAction(this, GetInstances()); _screenSolver.StepSortingAction(this, GetInstances());
if ( _sortingSolver.StepSortingAction(_screenSolver) ) { if ( _sortingSolver.StepSortingAction(this, _screenSolver) ) {
MarkDirty(); MarkDirty();
} }
_screenSolver.PostStepSortingAction(); _screenSolver.PostStepSortingAction();
@@ -397,11 +391,13 @@ namespace IsoTools {
protected override void OnEnable() { protected override void OnEnable() {
base.OnEnable(); base.OnEnable();
_screenSolver.Clear(); _screenSolver.Clear();
_sortingSolver.Clear();
} }
protected override void OnDisable() { protected override void OnDisable() {
base.OnDisable(); base.OnDisable();
_screenSolver.Clear(); _screenSolver.Clear();
_sortingSolver.Clear();
} }
protected override void OnAddInstanceToHolder(IsoObject instance) { protected override void OnAddInstanceToHolder(IsoObject instance) {