More code added, EntityContainer switched to a LinkedList
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp_Logic
|
||||
{
|
||||
public class Counter<T>
|
||||
{
|
||||
private T _value;
|
||||
|
||||
public T Value
|
||||
{
|
||||
get { return _value; }
|
||||
set { _value = value; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Counter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Increase(T deltaValue)
|
||||
{
|
||||
//_value += deltaValue;
|
||||
}
|
||||
|
||||
public void Decrease(T deltaValue)
|
||||
{
|
||||
//_value -= deltaValue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using StgSharp_Entity;
|
||||
using StgSharp_Game;
|
||||
using StgSharp_Game;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,16 +7,16 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp_Logic
|
||||
{
|
||||
public class EntityContainer<T>
|
||||
public class EntityContainer
|
||||
{
|
||||
readonly int _limit;
|
||||
private Counter<int> _limit;
|
||||
private float _leftBorder;
|
||||
private float _rightBorder;
|
||||
private float _topBorder;
|
||||
private float _bottomBorder;
|
||||
private T[] _container;
|
||||
private LinkedList _container;
|
||||
|
||||
public T[] Container
|
||||
public LinkedList Container
|
||||
{
|
||||
get { return _container; }
|
||||
set { _container = value; }
|
||||
@@ -43,41 +42,48 @@ namespace StgSharp_Logic
|
||||
get { return _bottomBorder; }
|
||||
set { _bottomBorder = value; }
|
||||
}
|
||||
|
||||
public EntityContainer(T sample)
|
||||
{
|
||||
_limit = 2048;
|
||||
this.Container = new T[_limit];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Add(T target)
|
||||
public EntityContainer(Counter<int> counter)
|
||||
{
|
||||
for (int i = 0; i < _limit; i++)
|
||||
this._limit = counter;
|
||||
this.Container = new LinkedList(_limit);
|
||||
}
|
||||
|
||||
public void Add(LinkedTarget target)
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
if (Container[i].Equals(default(T)))
|
||||
{
|
||||
Container[i] = target;
|
||||
}
|
||||
|
||||
}
|
||||
_container.Add(target);
|
||||
}
|
||||
|
||||
public void Remove(int id)
|
||||
public void RemoveAt(int id)
|
||||
{
|
||||
Container[id] = default(T);
|
||||
_container.Remove(id);
|
||||
}
|
||||
|
||||
//Move an entity from one container to another one
|
||||
public void Move(T target, EntityContainer<T> targetContainer)
|
||||
public void Move(LinkedTarget target, EntityContainer targetContainer)
|
||||
{
|
||||
target.Previous = target.Next;
|
||||
target.Next = target.Previous;
|
||||
targetContainer.Add(target);
|
||||
|
||||
}
|
||||
|
||||
//What should a container do on each rendering frame
|
||||
//This method should be overriden
|
||||
public void OnRender()
|
||||
{
|
||||
//坐标刷新
|
||||
//边界判定
|
||||
//碰撞判定
|
||||
}
|
||||
|
||||
public void ReportCapacity()
|
||||
{
|
||||
Console.WriteLine(_limit.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp_Logic
|
||||
{
|
||||
public class LinkedList
|
||||
{
|
||||
private LinkedTarget _heading;
|
||||
private LinkedTarget _ending;
|
||||
private LinkedTarget _cache;
|
||||
private Counter<int> _amountCounter;
|
||||
|
||||
public LinkedTarget Heading
|
||||
{
|
||||
get { return _heading; }
|
||||
set { _heading = value; }
|
||||
}
|
||||
|
||||
public LinkedTarget Ending
|
||||
{
|
||||
get { return _ending; }
|
||||
set { _ending = value; }
|
||||
}
|
||||
public LinkedTarget Cache
|
||||
{
|
||||
get { return _cache; }
|
||||
set { _cache = value; }
|
||||
}
|
||||
public Counter<int> AmountCounter
|
||||
{
|
||||
get { return _amountCounter; }
|
||||
set { _amountCounter = value; }
|
||||
}
|
||||
|
||||
//构造器
|
||||
public LinkedList(Counter<int> counter)
|
||||
{
|
||||
this._amountCounter = counter;
|
||||
_amountCounter.Value = 0;
|
||||
_ending = null;
|
||||
_heading = null;
|
||||
}
|
||||
|
||||
|
||||
public void Add(LinkedTarget target)
|
||||
{
|
||||
if (_ending != null)
|
||||
{
|
||||
_ending.Next = target;
|
||||
target.Previous = _ending;
|
||||
_ending = target;
|
||||
_amountCounter.Value++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_heading = target;
|
||||
_heading.Previous = null;
|
||||
_ending = target;
|
||||
_ending.Next = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据序号删除一个链表成员。
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
public void Remove(int id)
|
||||
{
|
||||
_cache = null;
|
||||
for (int i = 1; i < id; i++)
|
||||
{
|
||||
_cache = _cache.Next;
|
||||
}
|
||||
_cache.Previous = _cache.Next;
|
||||
_cache.Next = _cache.Previous;
|
||||
_cache.Next = null;
|
||||
_cache.Previous = null;
|
||||
_cache = null;
|
||||
_amountCounter.Value--;
|
||||
}
|
||||
/// <summary>
|
||||
/// 快速删除链表中已知名称的一个实例。由于不能判别实例是否存在于链表中故安全性较低。在对安全性有要求的情况下应当使用Remove_s方法。
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
public void Remove(LinkedTarget target)
|
||||
{
|
||||
target.Previous = target.Next;
|
||||
target.Next = target.Previous;
|
||||
target.Previous = null;
|
||||
target.Next = null;
|
||||
_amountCounter.Value--;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 该方法用于防止传入不属于该链表的实例。
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public void Remove_s(LinkedTarget target)
|
||||
{
|
||||
bool a = true;
|
||||
_cache = _heading;
|
||||
for (int i = 0; _cache.Next != null ; i++)
|
||||
{
|
||||
if (_cache==target)
|
||||
{
|
||||
Remove(target);
|
||||
a = true;
|
||||
_amountCounter.Value--;
|
||||
}
|
||||
}
|
||||
if (a)
|
||||
{
|
||||
throw new Exception("Target can not be found in this List!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp_Logic
|
||||
{
|
||||
public class LinkedTarget
|
||||
{
|
||||
private LinkedTarget _previous;
|
||||
|
||||
public LinkedTarget Previous
|
||||
{
|
||||
get { return _previous; }
|
||||
set {
|
||||
//if (this.GetType().FullName == value.GetType().FullName)
|
||||
{
|
||||
_previous = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LinkedTarget _next;
|
||||
|
||||
public LinkedTarget Next
|
||||
{
|
||||
get { return _next; }
|
||||
set {
|
||||
//if (this.GetType().FullName==value.GetType().FullName)
|
||||
{
|
||||
_next = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,9 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="LinkedList.cs" />
|
||||
<Compile Include="LinkedTarget.cs" />
|
||||
<Compile Include="Counter.cs" />
|
||||
<Compile Include="EntityContainer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
@@ -56,10 +59,6 @@
|
||||
<Project>{57017f07-7412-4b61-b912-b1d36c3af16f}</Project>
|
||||
<Name>StgSharp_Game</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\StgSharp_Entity\StgSharp_Entity.csproj">
|
||||
<Project>{a7275572-a4e7-4863-b326-f09bfa241334}</Project>
|
||||
<Name>StgSharp_Entity</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+1
@@ -0,0 +1 @@
|
||||
84e8b54631a157cd484f38b0f77768efef40e58b
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\bin\Debug\StgSharp_Logic.dll
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\bin\Debug\StgSharp_Logic.pdb
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\bin\Debug\Game.dll
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\bin\Debug\OpenTK.dll
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\bin\Debug\Game.pdb
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\bin\Debug\OpenTK.pdb
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\bin\Debug\OpenTK.xml
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\obj\Debug\StgSharp_Logic.csproj.AssemblyReference.cache
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\obj\Debug\StgSharp_Logic.csproj.CoreCompileInputs.cache
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\obj\Debug\StgSharp_Logic.csproj.CopyComplete
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\obj\Debug\StgSharp_Logic.dll
|
||||
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net Framework\STGSharp\StgSharp_Logic\obj\Debug\StgSharp_Logic.pdb
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
obj\Debug\\_IsIncrementalBuild
|
||||
Reference in New Issue
Block a user