New IO structure, unexpexted error in C code

This commit is contained in:
Nitload
2023-06-22 03:33:24 +08:00
parent 50b4965e54
commit ee8132c149
172 changed files with 1344 additions and 4023 deletions
-107
View File
@@ -1,107 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlTypes;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace StgSharp
{
public abstract class INode<T> where T : INode<T>
{
[NotNull]
protected ContainerNode<T> _id;
internal ContainerNode<T> ID
{
get { return _id; }
}
internal ContainerNode<T> Previous
{
get { return _id._previous; }
set { _id._previous = value; }
}
internal ContainerNode<T> Next
{
get { return _id._next; }
set { _id._next = value; }
}
public INode()
{
_id = new ContainerNode<T>(this as T);
}
internal void SetId(ContainerNode<T> tContainer)
{
_id = tContainer;
}
internal void SelfDestrcut()
{
_id._previous._next = _id._next;
_id._next._previous = _id._previous;
_id._next = null;
_id._previous = null;
GC.Collect();
}
}
public class ContainerNode<T> : INullable where T : INode<T>
{
internal readonly T _value;
[AllowNull]
internal ContainerNode<T> _previous;
[AllowNull]
internal ContainerNode<T> _next;
internal ContainerNode()
{
}
public ContainerNode(T t)
{
_value = t;
_previous = new ContainerNode<T>();
_next = new ContainerNode<T>();
}
public virtual ContainerNode<T> Previous
{
get { return _previous; }
set { _previous = value; }
}
public ContainerNode<T> Next
{
get { return _next; }
set { _next = value; }
}
public T Value
{
get { return _value; }
}
public bool IsNull
{
get;
}
public void Remove()
{
_previous.Next = _next;
_next.Previous = _previous;
_next = default(ContainerNode<T>);
_previous = default(ContainerNode<T>);
}
}
}
+16 -7
View File
@@ -1,11 +1,8 @@
using Microsoft.CSharp;
using System;
using System.Collections.Generic;
using System.Text;
using System;
namespace StgSharp
{
public class Counter<T> where T:struct, IConvertible, IFormattable, IComparable
public class Counter<T> where T : struct, IConvertible, IFormattable, IComparable
{
internal readonly dynamic _defualtValue;
internal readonly dynamic _defualtAddValue;
@@ -19,7 +16,7 @@ namespace StgSharp
set { _value = value; }
}
public Counter(T defualtValue,T defualtAddValue,T defualtSubValue)
public Counter(T defualtValue, T defualtAddValue, T defualtSubValue)
{
var type = Type.GetTypeCode(defualtValue.GetType());
switch (type)
@@ -53,7 +50,7 @@ namespace StgSharp
_defualtSubValue = defualtSubValue;
}
public void Add(T value)
{
_value += value;
@@ -78,5 +75,17 @@ namespace StgSharp
{
_value = _defualtValue;
}
public static Counter<T> operator ++(Counter<T> counter)
{
counter.QuickAdd();
return counter;
}
public static Counter<T> operator --(Counter<T> counter)
{
counter.QuickSub();
return counter;
}
}
}
+88 -34
View File
@@ -1,34 +1,41 @@
using StgSharp.Graphics;
using StgSharp.Logic;
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp
{
public class LinkedList<T>:INode<LinkedList<T>>,IEnumerable where T: INode<T>
public class LinkedList<T> : IEnumerable
{
internal readonly ContainerNode<T> _heading;
private ContainerNode<T> _cache;
internal readonly LinkedListNode<T> _heading;
private LinkedListNode<T> _cache;
private bool isEmpty;
public Counter<uint> count = new Counter<uint>(0, 1, 1);
public LinkedList()
{
_heading = new ContainerNode<T>(null);
_heading = new LinkedListNode<T>();
isEmpty = true;
}
public T First
{
get { return _heading._next._value; }
private set { _heading._next = value.ID; }
/*
* This setter is ued to reset the First node,
* be careful when use this setter to avoid
* unexpected risk of this List lose all nodes.
*/
private set { _heading._next = default; }
}
public T Tail
{
get { return _heading._previous._value; }
private set { _heading._previous = value.ID; }
/*
* This setter is ued to reset the Last node,
* be careful when use this setter to avoid
* unexpected risk of this List lose all nodes.
*/
private set { _heading._previous = default; }
}
/// <summary>
@@ -40,54 +47,101 @@ namespace StgSharp
//checkout if the linkedlist is null
if (isEmpty)
{
_heading._next = t.ID;
_heading._previous = t.ID;
t.Next = _heading;
t.Previous = _heading;
LinkedListNode<T> node = new LinkedListNode<T>(t);
_heading._next = node;
_heading._previous = node;
node.Next = _heading;
node.Previous = _heading;
isEmpty = false;
}
else
{
t.Next = _heading;
t.Previous = _heading.Previous;
_heading._previous._next = t.ID;
_heading._previous = t.ID;
LinkedListNode<T> node = new LinkedListNode<T>(t);
node.Next = _heading;
node.Previous = _heading.Previous;
_heading._previous._next = node;
_heading._previous = node;
}
count++;
}
public void Remove(T node)
public void Remove(T value)
{
foreach (INode<T> item in this)
{
if (item == node)
{
node.SelfDestrcut();
break;
}
}
LinkedListNode<T> node = Find(value);
node._next._previous = node._previous;
node._previous._next = node._next;
node._previous = null;
node._next = null;
count--;
}
public void RemoveTail()
{
//check out if the list has only one member
if (Tail == First)
if (count._value == 1)
{
First = default;
isEmpty = true;
}
else
{
Tail.Previous.Next = _heading;
Tail.Next = null;
_heading.Previous.Next = _heading;
}
count--;
}
internal LinkedListNode<T> Find(T value)
{
foreach (LinkedListNode<T> node in this)
{
if (node._value.Equals(value))
{
return node;
}
}
throw new Exception("Value not found in this LinkedList");
}
public void Clear()
{
_heading._previous = null;
_heading._next = null;
count.Reset();
}
IEnumerator IEnumerable.GetEnumerator()
{
return new LinkedListEnumrator<T>(this);
}
internal struct LinkedListEnumrator<T> : IEnumerator
{
private LinkedList<T> _target;
LinkedListNode<T> enumrator;
public LinkedListEnumrator(LinkedList<T> target)
{
_target = target;
enumrator = target._heading;
}
object IEnumerator.Current
{
get { return enumrator._value; }
}
bool IEnumerator.MoveNext()
{
enumrator = enumrator._next;
return enumrator == default(LinkedListNode<T>);
}
void IEnumerator.Reset()
{
enumrator = _target._heading;
}
}
}
}
@@ -1,35 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Logic
{
internal class LinkedListEnumrator<T> : IEnumerator where T : INode<T>
{
private LinkedList<T> _target;
ContainerNode<T> enumrator;
public LinkedListEnumrator(LinkedList<T> target)
{
_target = target;
enumrator = target._heading;
}
object IEnumerator.Current
{
get { return enumrator._value; }
}
bool IEnumerator.MoveNext()
{
enumrator = enumrator._next;
return enumrator == default(ContainerNode<T>);
}
void IEnumerator.Reset()
{
enumrator = _target._heading;
}
}
}
@@ -0,0 +1,53 @@
using System.Diagnostics.CodeAnalysis;
namespace StgSharp
{
internal class LinkedListNode<T>
{
internal readonly T _value;
[AllowNull]
internal LinkedListNode<T> _previous;
[AllowNull]
internal LinkedListNode<T> _next;
internal LinkedList<T> list;
internal LinkedListNode()
{
}
public LinkedListNode(T t)
{
_value = t;
_previous = new LinkedListNode<T>();
_next = new LinkedListNode<T>();
}
public virtual LinkedListNode<T> Previous
{
get { return _previous; }
set { _previous = value; }
}
public LinkedListNode<T> Next
{
get { return _next; }
set { _next = value; }
}
public T Value
{
get { return _value; }
}
public void Remove()
{
_previous.Next = _next;
_next.Previous = _previous;
_next = default(LinkedListNode<T>);
_previous = default(LinkedListNode<T>);
}
}
}
+5 -12
View File
@@ -1,15 +1,9 @@
using Steamworks;
using StgSharp.Math;
using StgSharp.Entities;
using StgSharp.Entities;
using StgSharp.Geometries;
using System;
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Text;
namespace StgSharp
{
public class Pool:INode<Pool>
public class Pool
{
internal LinkedList<Point> _pointContainer;
internal LinkedList<IPlainGeometry> geometryContainer;
@@ -27,14 +21,13 @@ namespace StgSharp
public Line TopBoarder => topBoader;
public Line BottomBoarder => bottomBoader;
internal Pool()
internal Pool()
{
initContainers();
}
private void initContainers()
{
_id = new ContainerNode<Pool>(this);
_pointContainer = new LinkedList<Point>();
_bulletContainer = new LinkedList<IEntity>();
_awardContainer = new LinkedList<IEntity>();
@@ -46,11 +39,11 @@ namespace StgSharp
{
foreach (Enemy e in _enemyContainer)
{
}
}
}
}
@@ -0,0 +1,23 @@
namespace StgSharp.Logic
{
public abstract class QuickClearNode<T> where T : QuickClearNode<T>
{
internal LinkedList<LinkedListNode<T>> _idList
= new LinkedList<LinkedListNode<T>>();
internal void QuickDestruct(LinkedList<T> list)
{
foreach (LinkedListNode<T> id in _idList)
{
if (id.list == list)
{
RecycleBin.Add(id);
break;
}
}
}
internal static LinkedList<LinkedListNode<T>> RecycleBin
= new LinkedList<LinkedListNode<T>>();
}
}
+2 -7
View File
@@ -1,21 +1,16 @@
using StgSharp.Geometries;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
namespace StgSharp
{
public delegate bool SensorRuleHandler(IPlainGeometry target, IPlainGeometry boarder);
public class Sensor<T>
public class Sensor<T>
{
internal IPlainGeometry _boarder;
internal IPlainGeometry _target;
internal SensorRuleHandler _rule;
public IPlainGeometry boarder
{