HLSF use long as aloloc size
This commit is contained in:
@@ -1,194 +1,194 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="BidirectionalDictionary"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public sealed class BidirectionalDictionary<TFirst, TSecond> : IBidirectionalDictionary<TFirst, TSecond>
|
||||
where TFirst: notnull
|
||||
where TSecond: notnull
|
||||
{
|
||||
|
||||
private readonly Dictionary<TFirst, TSecond> _forward;
|
||||
private readonly Dictionary<TSecond, TFirst> _reverse;
|
||||
|
||||
public BidirectionalDictionary()
|
||||
{
|
||||
_forward = [];
|
||||
_reverse = [];
|
||||
}
|
||||
|
||||
public TFirst this[TSecond key]
|
||||
{
|
||||
get => _reverse.TryGetValue(key, out TFirst value) ?
|
||||
value :
|
||||
throw new ArgumentException($"Cannot find key {key} in dictionary.");
|
||||
set
|
||||
{
|
||||
if (_reverse.TryGetValue(key, out TFirst origin))
|
||||
{
|
||||
_reverse[key] = value;
|
||||
_ = _forward.Remove(origin);
|
||||
} else
|
||||
{
|
||||
_reverse.Add(key, value);
|
||||
}
|
||||
_forward.Add(value, key);
|
||||
}
|
||||
}
|
||||
|
||||
public TSecond this[TFirst key]
|
||||
{
|
||||
get => _forward.TryGetValue(key, out TSecond value) ?
|
||||
value :
|
||||
throw new ArgumentException($"Cannot find key {key} in dictionary.");
|
||||
set
|
||||
{
|
||||
if (_forward.TryGetValue(key, out TSecond origin))
|
||||
{
|
||||
_forward[key] = value;
|
||||
_ = _reverse.Remove(origin);
|
||||
} else
|
||||
{
|
||||
_forward.Add(key, value);
|
||||
}
|
||||
_reverse.Add(value, key);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public ICollection<TFirst> FirstIndex => _forward.Keys;
|
||||
|
||||
public ICollection<TSecond> SecondIndex => _reverse.Keys;
|
||||
|
||||
public int Count => _forward.Count;
|
||||
|
||||
public IReadOnlyDictionary<TFirst, TSecond> Forward => new ReadOnlyDictionary<TFirst, TSecond>(
|
||||
_forward);
|
||||
|
||||
public IReadOnlyDictionary<TSecond, TFirst> Reverse => new ReadOnlyDictionary<TSecond, TFirst>(
|
||||
_reverse);
|
||||
|
||||
public void Add(KeyValuePair<TFirst, TSecond> item)
|
||||
{
|
||||
if (_forward.ContainsKey(item.Key) || _reverse.ContainsKey(item.Value)) {
|
||||
throw new ArgumentException("Duplicate key or value.");
|
||||
}
|
||||
_forward.Add(item.Key, item.Value);
|
||||
_reverse.Add(item.Value, item.Key);
|
||||
}
|
||||
|
||||
public void Add(TFirst key, TSecond value)
|
||||
{
|
||||
if (_forward.ContainsKey(key) || _reverse.ContainsKey(value)) {
|
||||
throw new ArgumentException("Duplicate key or value.");
|
||||
}
|
||||
_forward.Add(key, value);
|
||||
_reverse.Add(value, key);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_forward.Clear();
|
||||
_reverse.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(KeyValuePair<TFirst, TSecond> item)
|
||||
{
|
||||
return _forward.Contains(item) && _reverse.TryGetValue(item.Value, out TFirst var) && var!.Equals(item.Key);
|
||||
}
|
||||
|
||||
public bool Contains(TSecond key)
|
||||
{
|
||||
return _reverse.ContainsKey(key);
|
||||
}
|
||||
|
||||
public bool Contains(TFirst key)
|
||||
{
|
||||
return _forward.ContainsKey(key);
|
||||
}
|
||||
|
||||
public void CopyTo(KeyValuePair<TFirst, TSecond>[] array, int arrayIndex)
|
||||
{
|
||||
if (array == null) {
|
||||
throw new ArgumentNullException(nameof(array));
|
||||
}
|
||||
if (arrayIndex < 0 || arrayIndex > array.Length) {
|
||||
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
|
||||
}
|
||||
if (array.Length - arrayIndex < _forward.Count) {
|
||||
throw new ArgumentException("The array is too small to copy the elements.");
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<TFirst, TSecond> pair in _forward) {
|
||||
array[arrayIndex++] = pair;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<TFirst, TSecond>> GetEnumerator()
|
||||
{
|
||||
foreach (KeyValuePair<TFirst, TSecond> pair in _forward) {
|
||||
yield return pair;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove(TFirst key)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Remove(KeyValuePair<TFirst, TSecond> item)
|
||||
{
|
||||
if (_forward.Remove(item.Key)) {
|
||||
return _reverse.Remove(item.Value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetValue(TFirst key, out TSecond value)
|
||||
{
|
||||
return _forward.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
public bool TryGetValue(TSecond key, out TFirst value)
|
||||
{
|
||||
return _reverse.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="BidirectionalDictionary"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public sealed class BidirectionalDictionary<TFirst, TSecond> : IBidirectionalDictionary<TFirst, TSecond>
|
||||
where TFirst: notnull
|
||||
where TSecond: notnull
|
||||
{
|
||||
|
||||
private readonly Dictionary<TFirst, TSecond> _forward;
|
||||
private readonly Dictionary<TSecond, TFirst> _reverse;
|
||||
|
||||
public BidirectionalDictionary()
|
||||
{
|
||||
_forward = [];
|
||||
_reverse = [];
|
||||
}
|
||||
|
||||
public TFirst this[TSecond key]
|
||||
{
|
||||
get => _reverse.TryGetValue(key, out TFirst value) ?
|
||||
value :
|
||||
throw new ArgumentException($"Cannot find key {key} in dictionary.");
|
||||
set
|
||||
{
|
||||
if (_reverse.TryGetValue(key, out TFirst origin))
|
||||
{
|
||||
_reverse[key] = value;
|
||||
_ = _forward.Remove(origin);
|
||||
} else
|
||||
{
|
||||
_reverse.Add(key, value);
|
||||
}
|
||||
_forward.Add(value, key);
|
||||
}
|
||||
}
|
||||
|
||||
public TSecond this[TFirst key]
|
||||
{
|
||||
get => _forward.TryGetValue(key, out TSecond value) ?
|
||||
value :
|
||||
throw new ArgumentException($"Cannot find key {key} in dictionary.");
|
||||
set
|
||||
{
|
||||
if (_forward.TryGetValue(key, out TSecond origin))
|
||||
{
|
||||
_forward[key] = value;
|
||||
_ = _reverse.Remove(origin);
|
||||
} else
|
||||
{
|
||||
_forward.Add(key, value);
|
||||
}
|
||||
_reverse.Add(value, key);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public ICollection<TFirst> FirstIndex => _forward.Keys;
|
||||
|
||||
public ICollection<TSecond> SecondIndex => _reverse.Keys;
|
||||
|
||||
public int Count => _forward.Count;
|
||||
|
||||
public IReadOnlyDictionary<TFirst, TSecond> Forward => new ReadOnlyDictionary<TFirst, TSecond>(
|
||||
_forward);
|
||||
|
||||
public IReadOnlyDictionary<TSecond, TFirst> Reverse => new ReadOnlyDictionary<TSecond, TFirst>(
|
||||
_reverse);
|
||||
|
||||
public void Add(KeyValuePair<TFirst, TSecond> item)
|
||||
{
|
||||
if (_forward.ContainsKey(item.Key) || _reverse.ContainsKey(item.Value)) {
|
||||
throw new ArgumentException("Duplicate key or value.");
|
||||
}
|
||||
_forward.Add(item.Key, item.Value);
|
||||
_reverse.Add(item.Value, item.Key);
|
||||
}
|
||||
|
||||
public void Add(TFirst key, TSecond value)
|
||||
{
|
||||
if (_forward.ContainsKey(key) || _reverse.ContainsKey(value)) {
|
||||
throw new ArgumentException("Duplicate key or value.");
|
||||
}
|
||||
_forward.Add(key, value);
|
||||
_reverse.Add(value, key);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_forward.Clear();
|
||||
_reverse.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(KeyValuePair<TFirst, TSecond> item)
|
||||
{
|
||||
return _forward.Contains(item) && _reverse.TryGetValue(item.Value, out TFirst var) && var!.Equals(item.Key);
|
||||
}
|
||||
|
||||
public bool Contains(TSecond key)
|
||||
{
|
||||
return _reverse.ContainsKey(key);
|
||||
}
|
||||
|
||||
public bool Contains(TFirst key)
|
||||
{
|
||||
return _forward.ContainsKey(key);
|
||||
}
|
||||
|
||||
public void CopyTo(KeyValuePair<TFirst, TSecond>[] array, int arrayIndex)
|
||||
{
|
||||
if (array == null) {
|
||||
throw new ArgumentNullException(nameof(array));
|
||||
}
|
||||
if (arrayIndex < 0 || arrayIndex > array.Length) {
|
||||
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
|
||||
}
|
||||
if (array.Length - arrayIndex < _forward.Count) {
|
||||
throw new ArgumentException("The array is too small to copy the elements.");
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<TFirst, TSecond> pair in _forward) {
|
||||
array[arrayIndex++] = pair;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<TFirst, TSecond>> GetEnumerator()
|
||||
{
|
||||
foreach (KeyValuePair<TFirst, TSecond> pair in _forward) {
|
||||
yield return pair;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove(TFirst key)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Remove(KeyValuePair<TFirst, TSecond> item)
|
||||
{
|
||||
if (_forward.Remove(item.Key)) {
|
||||
return _reverse.Remove(item.Value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetValue(TFirst key, out TSecond value)
|
||||
{
|
||||
return _forward.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
public bool TryGetValue(TSecond key, out TFirst value)
|
||||
{
|
||||
return _reverse.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,92 +1,92 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CapacityFixedBag"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public sealed class CapacityFixedBag<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
private readonly T[] _buffer;
|
||||
|
||||
public CapacityFixedBag(int capacity)
|
||||
{
|
||||
_buffer = new T[capacity];
|
||||
}
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public int Capacity => _buffer.Length;
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (Count >= _buffer.Length) {
|
||||
throw new InvalidOperationException("Bag capacity exceeded.");
|
||||
}
|
||||
_buffer[Count] = item;
|
||||
Count++;
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < Count; i++) {
|
||||
yield return _buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(T item)
|
||||
{
|
||||
int index = Array.IndexOf(_buffer, item, 0, Count);
|
||||
if (index >= 0)
|
||||
{
|
||||
_buffer[index] = _buffer[Count - 1];
|
||||
_buffer[Count - 1] = default!;
|
||||
Count--;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (index >= 0)
|
||||
{
|
||||
_buffer[index] = _buffer[Count - 1];
|
||||
_buffer[Count - 1] = default!;
|
||||
Count--;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CapacityFixedBag"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public sealed class CapacityFixedBag<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
private readonly T[] _buffer;
|
||||
|
||||
public CapacityFixedBag(int capacity)
|
||||
{
|
||||
_buffer = new T[capacity];
|
||||
}
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public int Capacity => _buffer.Length;
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (Count >= _buffer.Length) {
|
||||
throw new InvalidOperationException("Bag capacity exceeded.");
|
||||
}
|
||||
_buffer[Count] = item;
|
||||
Count++;
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < Count; i++) {
|
||||
yield return _buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(T item)
|
||||
{
|
||||
int index = Array.IndexOf(_buffer, item, 0, Count);
|
||||
if (index >= 0)
|
||||
{
|
||||
_buffer[index] = _buffer[Count - 1];
|
||||
_buffer[Count - 1] = default!;
|
||||
Count--;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (index >= 0)
|
||||
{
|
||||
_buffer[index] = _buffer[Count - 1];
|
||||
_buffer[Count - 1] = default!;
|
||||
Count--;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,183 +1,183 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CapacityFixedList"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public static class CapacityFixedListBuilder
|
||||
{
|
||||
|
||||
internal static CapacityFixedList<T> Create<T>(ReadOnlySpan<T> values)
|
||||
{
|
||||
return new CapacityFixedList<T>(values);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[CollectionBuilder(typeof(CapacityFixedListBuilder), nameof(CapacityFixedListBuilder.Create))]
|
||||
public class CapacityFixedList<T> : IList<T>
|
||||
{
|
||||
|
||||
private T[] _values;
|
||||
private int capacity, _index;
|
||||
|
||||
public CapacityFixedList(int size)
|
||||
{
|
||||
_values = new T[size];
|
||||
}
|
||||
|
||||
public CapacityFixedList(ReadOnlySpan<T> values)
|
||||
{
|
||||
_values = values.ToArray();
|
||||
}
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get => index < _index ? _values[index] : throw new ArgumentOutOfRangeException(nameof(index));
|
||||
set
|
||||
{
|
||||
if (index < _index)
|
||||
{
|
||||
_values[index] = value;
|
||||
} else
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public int Count => _index + 1;
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (_index < capacity - 1)
|
||||
{
|
||||
_index++;
|
||||
this[_index] = item;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_values = new T[capacity];
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
for (int i = 0; i <= _index; i++)
|
||||
{
|
||||
if (item.Equals(_values[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
_values.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i <= _index; i++) {
|
||||
yield return _values[i];
|
||||
}
|
||||
}
|
||||
|
||||
public int IndexOf(T item)
|
||||
{
|
||||
T v;
|
||||
for (int i = 0; i <= _index; i++)
|
||||
{
|
||||
if ((v = _values[i]) != null && v.Equals(item)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Remove(T item)
|
||||
{
|
||||
T v;
|
||||
for (int i = 0; i <= _index; i++)
|
||||
{
|
||||
if ((v = _values[i]) != null && v.Equals(item))
|
||||
{
|
||||
_values[i] = _values[_index];
|
||||
_index--;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveAll(Predicate<T> predicate)
|
||||
{
|
||||
for (int i = _index; i > 0; i--)
|
||||
{
|
||||
if (predicate(_values[i]))
|
||||
{
|
||||
_values[i] = _values[_index];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (index <= _index)
|
||||
{
|
||||
_values[index] = _values[_index];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
|
||||
public void Resize(int newSize)
|
||||
{
|
||||
Array.Resize(ref _values, newSize);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
yield return GetEnumerator();
|
||||
}
|
||||
|
||||
void IList<T>.Insert(int index, T item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
}//------------------------------------- End of Class ------------------------------------------
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CapacityFixedList"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public static class CapacityFixedListBuilder
|
||||
{
|
||||
|
||||
internal static CapacityFixedList<T> Create<T>(ReadOnlySpan<T> values)
|
||||
{
|
||||
return new CapacityFixedList<T>(values);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[CollectionBuilder(typeof(CapacityFixedListBuilder), nameof(CapacityFixedListBuilder.Create))]
|
||||
public class CapacityFixedList<T> : IList<T>
|
||||
{
|
||||
|
||||
private T[] _values;
|
||||
private int capacity, _index;
|
||||
|
||||
public CapacityFixedList(int size)
|
||||
{
|
||||
_values = new T[size];
|
||||
}
|
||||
|
||||
public CapacityFixedList(ReadOnlySpan<T> values)
|
||||
{
|
||||
_values = values.ToArray();
|
||||
}
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get => index < _index ? _values[index] : throw new ArgumentOutOfRangeException(nameof(index));
|
||||
set
|
||||
{
|
||||
if (index < _index)
|
||||
{
|
||||
_values[index] = value;
|
||||
} else
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public int Count => _index + 1;
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (_index < capacity - 1)
|
||||
{
|
||||
_index++;
|
||||
this[_index] = item;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_values = new T[capacity];
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
for (int i = 0; i <= _index; i++)
|
||||
{
|
||||
if (item.Equals(_values[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
_values.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i <= _index; i++) {
|
||||
yield return _values[i];
|
||||
}
|
||||
}
|
||||
|
||||
public int IndexOf(T item)
|
||||
{
|
||||
T v;
|
||||
for (int i = 0; i <= _index; i++)
|
||||
{
|
||||
if ((v = _values[i]) != null && v.Equals(item)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Remove(T item)
|
||||
{
|
||||
T v;
|
||||
for (int i = 0; i <= _index; i++)
|
||||
{
|
||||
if ((v = _values[i]) != null && v.Equals(item))
|
||||
{
|
||||
_values[i] = _values[_index];
|
||||
_index--;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveAll(Predicate<T> predicate)
|
||||
{
|
||||
for (int i = _index; i > 0; i--)
|
||||
{
|
||||
if (predicate(_values[i]))
|
||||
{
|
||||
_values[i] = _values[_index];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (index <= _index)
|
||||
{
|
||||
_values[index] = _values[_index];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
|
||||
public void Resize(int newSize)
|
||||
{
|
||||
Array.Resize(ref _values, newSize);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
yield return GetEnumerator();
|
||||
}
|
||||
|
||||
void IList<T>.Insert(int index, T item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
}//------------------------------------- End of Class ------------------------------------------
|
||||
}
|
||||
|
||||
@@ -1,170 +1,170 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CapacityFixedStack"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
[CollectionBuilder(typeof(CapacityFixedStackBuilder), nameof(CapacityFixedStackBuilder.Create))]
|
||||
public class CapacityFixedStack<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
private readonly T[] _values;
|
||||
|
||||
// _index points to the next free slot (top empty position). Therefore Count == _index.
|
||||
private int _index;
|
||||
|
||||
public CapacityFixedStack(int size)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(size);
|
||||
_values = new T[size];
|
||||
_index = 0; // empty stack
|
||||
}
|
||||
|
||||
public T? First => Volatile.Read(ref _index) > 0 ? _values[0] : default;
|
||||
|
||||
public bool IsEmpty => Volatile.Read(ref _index) == 0;
|
||||
|
||||
public int Count => Volatile.Read(ref _index);
|
||||
|
||||
public int Capacity => _values.Length;
|
||||
|
||||
public ReadOnlySpan<T> AsSpan() => _values.AsSpan(0, _index);
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (_index > 0)
|
||||
{
|
||||
Array.Clear(_values, 0, _index);
|
||||
_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = _index - 1; i >= 0; i--) {
|
||||
yield return _values[i];
|
||||
}
|
||||
}
|
||||
|
||||
public T Peek()
|
||||
{
|
||||
if (_index == 0) {
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
return _values[_index - 1];
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
{
|
||||
if (_index == 0) {
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
_index--;
|
||||
T item = _values[_index];
|
||||
_values[_index] = default!; // Clear reference for GC
|
||||
return item;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public T[] PopRange(int count)
|
||||
{
|
||||
if (count <= 0 || _index == 0) {
|
||||
return Array.Empty<T>();
|
||||
}
|
||||
int n = Math.Min(count, _index);
|
||||
int start = _index - n;
|
||||
T[] ret = new T[n];
|
||||
Array.Copy(_values, start, ret, 0, n);
|
||||
Array.Clear(_values, start, n);
|
||||
_index -= n;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Push(T item)
|
||||
{
|
||||
if (_index >= _values.Length) {
|
||||
throw new InvalidOperationException("Stack is full.");
|
||||
}
|
||||
_values[_index] = item;
|
||||
_index++;
|
||||
}
|
||||
|
||||
public void PushRange(ReadOnlySpan<T> span)
|
||||
{
|
||||
if (span.Length == 0) {
|
||||
return;
|
||||
}
|
||||
if (_index + span.Length > _values.Length) {
|
||||
throw new InvalidOperationException("Not enough space in the stack to push the entire span.");
|
||||
}
|
||||
span.CopyTo(_values.AsSpan(_index, span.Length));
|
||||
_index += span.Length;
|
||||
}
|
||||
|
||||
public bool TryPop(out T value)
|
||||
{
|
||||
if (_index == 0)
|
||||
{
|
||||
value = default!;
|
||||
return false;
|
||||
}
|
||||
_index--;
|
||||
value = _values[_index];
|
||||
_values[_index] = default!;
|
||||
return true;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal Span<T> GetValueLayout()
|
||||
{
|
||||
return _values.AsSpan();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class CapacityFixedStackBuilder
|
||||
{
|
||||
|
||||
public static CapacityFixedStack<T> Create<T>(ReadOnlySpan<T> values)
|
||||
{
|
||||
CapacityFixedStack<T> stack = new(values.Length);
|
||||
stack.PushRange(values); // Push in order
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CapacityFixedStack"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
[CollectionBuilder(typeof(CapacityFixedStackBuilder), nameof(CapacityFixedStackBuilder.Create))]
|
||||
public class CapacityFixedStack<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
private readonly T[] _values;
|
||||
|
||||
// _index points to the next free slot (top empty position). Therefore Count == _index.
|
||||
private int _index;
|
||||
|
||||
public CapacityFixedStack(int size)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(size);
|
||||
_values = new T[size];
|
||||
_index = 0; // empty stack
|
||||
}
|
||||
|
||||
public T? First => Volatile.Read(ref _index) > 0 ? _values[0] : default;
|
||||
|
||||
public bool IsEmpty => Volatile.Read(ref _index) == 0;
|
||||
|
||||
public int Count => Volatile.Read(ref _index);
|
||||
|
||||
public int Capacity => _values.Length;
|
||||
|
||||
public ReadOnlySpan<T> AsSpan() => _values.AsSpan(0, _index);
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (_index > 0)
|
||||
{
|
||||
Array.Clear(_values, 0, _index);
|
||||
_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = _index - 1; i >= 0; i--) {
|
||||
yield return _values[i];
|
||||
}
|
||||
}
|
||||
|
||||
public T Peek()
|
||||
{
|
||||
if (_index == 0) {
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
return _values[_index - 1];
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
{
|
||||
if (_index == 0) {
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
_index--;
|
||||
T item = _values[_index];
|
||||
_values[_index] = default!; // Clear reference for GC
|
||||
return item;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public T[] PopRange(int count)
|
||||
{
|
||||
if (count <= 0 || _index == 0) {
|
||||
return Array.Empty<T>();
|
||||
}
|
||||
int n = Math.Min(count, _index);
|
||||
int start = _index - n;
|
||||
T[] ret = new T[n];
|
||||
Array.Copy(_values, start, ret, 0, n);
|
||||
Array.Clear(_values, start, n);
|
||||
_index -= n;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Push(T item)
|
||||
{
|
||||
if (_index >= _values.Length) {
|
||||
throw new InvalidOperationException("Stack is full.");
|
||||
}
|
||||
_values[_index] = item;
|
||||
_index++;
|
||||
}
|
||||
|
||||
public void PushRange(ReadOnlySpan<T> span)
|
||||
{
|
||||
if (span.Length == 0) {
|
||||
return;
|
||||
}
|
||||
if (_index + span.Length > _values.Length) {
|
||||
throw new InvalidOperationException("Not enough space in the stack to push the entire span.");
|
||||
}
|
||||
span.CopyTo(_values.AsSpan(_index, span.Length));
|
||||
_index += span.Length;
|
||||
}
|
||||
|
||||
public bool TryPop(out T value)
|
||||
{
|
||||
if (_index == 0)
|
||||
{
|
||||
value = default!;
|
||||
return false;
|
||||
}
|
||||
_index--;
|
||||
value = _values[_index];
|
||||
_values[_index] = default!;
|
||||
return true;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal Span<T> GetValueLayout()
|
||||
{
|
||||
return _values.AsSpan();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class CapacityFixedStackBuilder
|
||||
{
|
||||
|
||||
public static CapacityFixedStack<T> Create<T>(ReadOnlySpan<T> values)
|
||||
{
|
||||
CapacityFixedStack<T> stack = new(values.Length);
|
||||
stack.PushRange(values); // Push in order
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,287 +1,287 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ConcurrentCapacityFixedStack"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Lock-free, fixed-capacity stack implemented on top of an array using atomic index
|
||||
/// operations. - No linked list; only array slots - Uses CAS on a shared top index to
|
||||
/// reserve/release slots - Per-slot state flag to safely publish/consume values under races
|
||||
/// </summary>
|
||||
public class ConcurrentCapacityFixedStack<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
private readonly int[] _states; // 0 = empty, 1 = full
|
||||
private readonly T[] _values;
|
||||
private readonly int _capacity;
|
||||
|
||||
// Number of full slots (observable count)
|
||||
private int _count;
|
||||
|
||||
// Next push position (0.._capacity). Only modified via CAS.
|
||||
private int _top;
|
||||
|
||||
public ConcurrentCapacityFixedStack(int capacity)
|
||||
{
|
||||
if (capacity <= 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(capacity));
|
||||
}
|
||||
|
||||
_capacity = capacity;
|
||||
_values = new T[capacity];
|
||||
_states = new int[capacity];
|
||||
_top = 0;
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
public bool IsEmpty => Count == 0;
|
||||
|
||||
public int Capacity => _capacity;
|
||||
|
||||
public int Count => Volatile.Read(ref _count);
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
// Pop all elements to return slots to empty state
|
||||
while (TryPop(out _)) { }
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
T[] snap = ToArraySnapshot();
|
||||
for (int i = 0; i < snap.Length; i++) {
|
||||
yield return snap[i];
|
||||
}
|
||||
}
|
||||
|
||||
public T Peek()
|
||||
{
|
||||
if (TryPeek(out T? v)) {
|
||||
return v;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
{
|
||||
if (TryPop(out T value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
|
||||
public T[] PopRange(int count)
|
||||
{
|
||||
if (count <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
T[] result = new T[count];
|
||||
int i = 0;
|
||||
for (; i < count; i++)
|
||||
{
|
||||
if (!TryPop(out result[i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == count) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
T[] trimmed = new T[i];
|
||||
Array.Copy(result, trimmed, i);
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
public void Push(T item)
|
||||
{
|
||||
SpinWait sw = default;
|
||||
while (true)
|
||||
{
|
||||
int oldTop = Volatile.Read(ref _top);
|
||||
if (oldTop >= _capacity) {
|
||||
throw new InvalidOperationException("Stack is full.");
|
||||
}
|
||||
|
||||
if (Interlocked.CompareExchange(ref _top, oldTop + 1, oldTop) != oldTop)
|
||||
{
|
||||
sw.SpinOnce();
|
||||
continue; // failed to reserve slot
|
||||
}
|
||||
|
||||
// We exclusively own slot oldTop. Publish value then state.
|
||||
_values[oldTop] = item;
|
||||
Volatile.Write(ref _states[oldTop], 1); // publish
|
||||
_ = Interlocked.Increment(ref _count);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void PushRange(ReadOnlySpan<T> span)
|
||||
{
|
||||
for (int i = 0; i < span.Length; i++) {
|
||||
Push(span[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Best-effort snapshot for enumeration; not strongly consistent under concurrent
|
||||
/// mutations.
|
||||
/// </summary>
|
||||
public T[] ToArraySnapshot()
|
||||
{
|
||||
int expected = Math.Min(Volatile.Read(ref _count), _capacity);
|
||||
if (expected == 0) {
|
||||
return Array.Empty<T>();
|
||||
}
|
||||
|
||||
T[] snap = new T[expected];
|
||||
int copied = 0;
|
||||
int idx = Volatile.Read(ref _top) - 1;
|
||||
while (idx >= 0 && copied < expected)
|
||||
{
|
||||
if (Volatile.Read(ref _states[idx]) == 1) {
|
||||
snap[copied++] = _values[idx];
|
||||
}
|
||||
idx--;
|
||||
}
|
||||
|
||||
if (copied == snap.Length) {
|
||||
return snap;
|
||||
}
|
||||
|
||||
T[] trimmed = new T[copied];
|
||||
Array.Copy(snap, trimmed, copied);
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
public bool TryPeek(out T value)
|
||||
{
|
||||
value = default!;
|
||||
SpinWait sw = default;
|
||||
|
||||
while (true)
|
||||
{
|
||||
int top = Volatile.Read(ref _top);
|
||||
if (top <= 0) {
|
||||
return false;
|
||||
}
|
||||
int idx = top - 1;
|
||||
|
||||
// If not yet published or racing, retry/spin
|
||||
if (Volatile.Read(ref _states[idx]) == 0)
|
||||
{
|
||||
if (Volatile.Read(ref _top) != top)
|
||||
{
|
||||
continue; // head moved, retry
|
||||
}
|
||||
sw.SpinOnce();
|
||||
continue;
|
||||
}
|
||||
|
||||
T v = _values[idx];
|
||||
|
||||
// Validate consistency
|
||||
if (Volatile.Read(ref _top) == top && Volatile.Read(ref _states[idx]) == 1)
|
||||
{
|
||||
value = v;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryPop(out T value)
|
||||
{
|
||||
value = default!;
|
||||
SpinWait sw = default;
|
||||
|
||||
while (true)
|
||||
{
|
||||
int oldTop = Volatile.Read(ref _top);
|
||||
if (oldTop <= 0)
|
||||
{
|
||||
return false; // empty
|
||||
}
|
||||
|
||||
int newTop = oldTop - 1; // index to consume
|
||||
if (Interlocked.CompareExchange(ref _top, newTop, oldTop) != oldTop)
|
||||
{
|
||||
sw.SpinOnce();
|
||||
continue; // failed to reserve element
|
||||
}
|
||||
|
||||
// If producer hasn't published yet, roll back our reservation and retry.
|
||||
if (Volatile.Read(ref _states[newTop]) == 0)
|
||||
{
|
||||
// attempt to restore top; ok if it fails due to concurrent operations
|
||||
_ = Interlocked.CompareExchange(ref _top, newTop + 1, newTop);
|
||||
sw.SpinOnce();
|
||||
continue;
|
||||
}
|
||||
|
||||
value = _values[newTop];
|
||||
_values[newTop] = default!; // avoid ref retention
|
||||
Volatile.Write(ref _states[newTop], 0); // mark empty
|
||||
_ = Interlocked.Decrement(ref _count);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public int TryPopRange(Span<T> destination)
|
||||
{
|
||||
if (destination.IsEmpty) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (; i < destination.Length; i++)
|
||||
{
|
||||
if (!TryPop(out destination[i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ConcurrentCapacityFixedStack"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Lock-free, fixed-capacity stack implemented on top of an array using atomic index
|
||||
/// operations. - No linked list; only array slots - Uses CAS on a shared top index to
|
||||
/// reserve/release slots - Per-slot state flag to safely publish/consume values under races
|
||||
/// </summary>
|
||||
public class ConcurrentCapacityFixedStack<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
private readonly int[] _states; // 0 = empty, 1 = full
|
||||
private readonly T[] _values;
|
||||
private readonly int _capacity;
|
||||
|
||||
// Number of full slots (observable count)
|
||||
private int _count;
|
||||
|
||||
// Next push position (0.._capacity). Only modified via CAS.
|
||||
private int _top;
|
||||
|
||||
public ConcurrentCapacityFixedStack(int capacity)
|
||||
{
|
||||
if (capacity <= 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(capacity));
|
||||
}
|
||||
|
||||
_capacity = capacity;
|
||||
_values = new T[capacity];
|
||||
_states = new int[capacity];
|
||||
_top = 0;
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
public bool IsEmpty => Count == 0;
|
||||
|
||||
public int Capacity => _capacity;
|
||||
|
||||
public int Count => Volatile.Read(ref _count);
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
// Pop all elements to return slots to empty state
|
||||
while (TryPop(out _)) { }
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
T[] snap = ToArraySnapshot();
|
||||
for (int i = 0; i < snap.Length; i++) {
|
||||
yield return snap[i];
|
||||
}
|
||||
}
|
||||
|
||||
public T Peek()
|
||||
{
|
||||
if (TryPeek(out T? v)) {
|
||||
return v;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
{
|
||||
if (TryPop(out T value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
|
||||
public T[] PopRange(int count)
|
||||
{
|
||||
if (count <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
T[] result = new T[count];
|
||||
int i = 0;
|
||||
for (; i < count; i++)
|
||||
{
|
||||
if (!TryPop(out result[i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == count) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
T[] trimmed = new T[i];
|
||||
Array.Copy(result, trimmed, i);
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
public void Push(T item)
|
||||
{
|
||||
SpinWait sw = default;
|
||||
while (true)
|
||||
{
|
||||
int oldTop = Volatile.Read(ref _top);
|
||||
if (oldTop >= _capacity) {
|
||||
throw new InvalidOperationException("Stack is full.");
|
||||
}
|
||||
|
||||
if (Interlocked.CompareExchange(ref _top, oldTop + 1, oldTop) != oldTop)
|
||||
{
|
||||
sw.SpinOnce();
|
||||
continue; // failed to reserve slot
|
||||
}
|
||||
|
||||
// We exclusively own slot oldTop. Publish value then state.
|
||||
_values[oldTop] = item;
|
||||
Volatile.Write(ref _states[oldTop], 1); // publish
|
||||
_ = Interlocked.Increment(ref _count);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void PushRange(ReadOnlySpan<T> span)
|
||||
{
|
||||
for (int i = 0; i < span.Length; i++) {
|
||||
Push(span[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Best-effort snapshot for enumeration; not strongly consistent under concurrent
|
||||
/// mutations.
|
||||
/// </summary>
|
||||
public T[] ToArraySnapshot()
|
||||
{
|
||||
int expected = Math.Min(Volatile.Read(ref _count), _capacity);
|
||||
if (expected == 0) {
|
||||
return Array.Empty<T>();
|
||||
}
|
||||
|
||||
T[] snap = new T[expected];
|
||||
int copied = 0;
|
||||
int idx = Volatile.Read(ref _top) - 1;
|
||||
while (idx >= 0 && copied < expected)
|
||||
{
|
||||
if (Volatile.Read(ref _states[idx]) == 1) {
|
||||
snap[copied++] = _values[idx];
|
||||
}
|
||||
idx--;
|
||||
}
|
||||
|
||||
if (copied == snap.Length) {
|
||||
return snap;
|
||||
}
|
||||
|
||||
T[] trimmed = new T[copied];
|
||||
Array.Copy(snap, trimmed, copied);
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
public bool TryPeek(out T value)
|
||||
{
|
||||
value = default!;
|
||||
SpinWait sw = default;
|
||||
|
||||
while (true)
|
||||
{
|
||||
int top = Volatile.Read(ref _top);
|
||||
if (top <= 0) {
|
||||
return false;
|
||||
}
|
||||
int idx = top - 1;
|
||||
|
||||
// If not yet published or racing, retry/spin
|
||||
if (Volatile.Read(ref _states[idx]) == 0)
|
||||
{
|
||||
if (Volatile.Read(ref _top) != top)
|
||||
{
|
||||
continue; // head moved, retry
|
||||
}
|
||||
sw.SpinOnce();
|
||||
continue;
|
||||
}
|
||||
|
||||
T v = _values[idx];
|
||||
|
||||
// Validate consistency
|
||||
if (Volatile.Read(ref _top) == top && Volatile.Read(ref _states[idx]) == 1)
|
||||
{
|
||||
value = v;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryPop(out T value)
|
||||
{
|
||||
value = default!;
|
||||
SpinWait sw = default;
|
||||
|
||||
while (true)
|
||||
{
|
||||
int oldTop = Volatile.Read(ref _top);
|
||||
if (oldTop <= 0)
|
||||
{
|
||||
return false; // empty
|
||||
}
|
||||
|
||||
int newTop = oldTop - 1; // index to consume
|
||||
if (Interlocked.CompareExchange(ref _top, newTop, oldTop) != oldTop)
|
||||
{
|
||||
sw.SpinOnce();
|
||||
continue; // failed to reserve element
|
||||
}
|
||||
|
||||
// If producer hasn't published yet, roll back our reservation and retry.
|
||||
if (Volatile.Read(ref _states[newTop]) == 0)
|
||||
{
|
||||
// attempt to restore top; ok if it fails due to concurrent operations
|
||||
_ = Interlocked.CompareExchange(ref _top, newTop + 1, newTop);
|
||||
sw.SpinOnce();
|
||||
continue;
|
||||
}
|
||||
|
||||
value = _values[newTop];
|
||||
_values[newTop] = default!; // avoid ref retention
|
||||
Volatile.Write(ref _states[newTop], 0); // mark empty
|
||||
_ = Interlocked.Decrement(ref _count);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public int TryPopRange(Span<T> destination)
|
||||
{
|
||||
if (destination.IsEmpty) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (; i < destination.Length; i++)
|
||||
{
|
||||
if (!TryPop(out destination[i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +1,84 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IBidirectionalDictionary"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public interface IBidirectionalDictionary<TFirst, TSecond> : IDictionary<TFirst, TSecond>
|
||||
{
|
||||
|
||||
TFirst this[
|
||||
TSecond key
|
||||
] { get; set; }
|
||||
|
||||
ICollection<TFirst> FirstIndex { get; }
|
||||
|
||||
ICollection<TSecond> SecondIndex { get; }
|
||||
|
||||
IReadOnlyDictionary<TFirst, TSecond> Forward { get; }
|
||||
|
||||
IReadOnlyDictionary<TSecond, TFirst> Reverse { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
|
||||
/// specified key.
|
||||
/// </summary>
|
||||
/// <param _label="key">
|
||||
/// The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
|
||||
/// the specified key; otherwise, false.
|
||||
/// </returns>
|
||||
bool Contains(
|
||||
TSecond key
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
|
||||
/// specified key.
|
||||
/// </summary>
|
||||
/// <param _label="key">
|
||||
/// The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
|
||||
/// the specified key; otherwise, false.
|
||||
/// </returns>
|
||||
bool Contains(
|
||||
TFirst key
|
||||
);
|
||||
|
||||
bool TryGetValue(
|
||||
TSecond key,
|
||||
out TFirst value
|
||||
);
|
||||
|
||||
#pragma warning disable CA1033
|
||||
ICollection<TFirst> IDictionary<TFirst, TSecond>.Keys => FirstIndex;
|
||||
|
||||
ICollection<TSecond> IDictionary<TFirst, TSecond>.Values => SecondIndex;
|
||||
|
||||
bool IDictionary<TFirst, TSecond>.ContainsKey(
|
||||
TFirst key
|
||||
)
|
||||
{
|
||||
return Contains(key);
|
||||
}
|
||||
#pragma warning restore CA1033
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IBidirectionalDictionary"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public interface IBidirectionalDictionary<TFirst, TSecond> : IDictionary<TFirst, TSecond>
|
||||
{
|
||||
|
||||
TFirst this[TSecond key] { get; set; }
|
||||
|
||||
ICollection<TFirst> FirstIndex { get; }
|
||||
|
||||
ICollection<TSecond> SecondIndex { get; }
|
||||
|
||||
IReadOnlyDictionary<TFirst, TSecond> Forward { get; }
|
||||
|
||||
IReadOnlyDictionary<TSecond, TFirst> Reverse { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
|
||||
/// specified key.
|
||||
/// </summary>
|
||||
/// <param _label="key">
|
||||
/// The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
|
||||
/// the specified key; otherwise, false.
|
||||
/// </returns>
|
||||
bool Contains(TSecond key);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
|
||||
/// specified key.
|
||||
/// </summary>
|
||||
/// <param _label="key">
|
||||
/// The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
|
||||
/// the specified key; otherwise, false.
|
||||
/// </returns>
|
||||
bool Contains(TFirst key);
|
||||
|
||||
bool TryGetValue(TSecond key, out TFirst value);
|
||||
|
||||
#pragma warning disable CA1033
|
||||
ICollection<TFirst> IDictionary<TFirst, TSecond>.Keys => FirstIndex;
|
||||
|
||||
ICollection<TSecond> IDictionary<TFirst, TSecond>.Values => SecondIndex;
|
||||
|
||||
bool IDictionary<TFirst, TSecond>.ContainsKey(TFirst key)
|
||||
{
|
||||
return Contains(key);
|
||||
}
|
||||
#pragma warning restore CA1033
|
||||
}
|
||||
}
|
||||
@@ -1,53 +1,53 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IHashMultiplexer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public interface IHashMultiplexer<T> : IEqualityComparer<T>
|
||||
{
|
||||
|
||||
int RemainedMultiplexCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cache hash result for obj with counts.
|
||||
/// </summary>
|
||||
/// <param name="obj">
|
||||
///
|
||||
/// </param>
|
||||
/// <param name="count">
|
||||
///
|
||||
/// </param>
|
||||
void CacheHash(T obj, int count);
|
||||
|
||||
void ExtendCache(int count);
|
||||
|
||||
int ForceComputeHash(T count);
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IHashMultiplexer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public interface IHashMultiplexer<T> : IEqualityComparer<T>
|
||||
{
|
||||
|
||||
int RemainedMultiplexCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cache hash result for obj with counts.
|
||||
/// </summary>
|
||||
/// <param name="obj">
|
||||
///
|
||||
/// </param>
|
||||
/// <param name="count">
|
||||
///
|
||||
/// </param>
|
||||
void CacheHash(T obj, int count);
|
||||
|
||||
void ExtendCache(int count);
|
||||
|
||||
int ForceComputeHash(T count);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,131 +1,131 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ListSegment"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Part of a collection. This contains a direct reference to _origin collection, so all
|
||||
/// change to _origin collection will be reflected in this object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
///
|
||||
/// </typeparam>
|
||||
public struct ListSegment<T> : ICollection<T>
|
||||
{
|
||||
|
||||
private int _begin;
|
||||
private int _length;
|
||||
private List<T> _collection;
|
||||
|
||||
public ListSegment(List<T> collection, int begin, int length)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(collection);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(begin, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(length, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(begin + length, collection.Count);
|
||||
_collection = collection;
|
||||
_begin = begin;
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public T this[int indexValue]
|
||||
{
|
||||
get
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(indexValue, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(indexValue, _length);
|
||||
return _collection[indexValue + _begin];
|
||||
}
|
||||
}
|
||||
|
||||
public T this[Index i]
|
||||
{
|
||||
get
|
||||
{
|
||||
int offset = i.IsFromEnd ? _length - i.Value : i.Value;
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(offset, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(offset, _length);
|
||||
return _collection[offset + _begin];
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly => true;
|
||||
|
||||
public int Count => _length;
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
int index = _collection.IndexOf(item);
|
||||
return index >= _begin && index < _length + index;
|
||||
}
|
||||
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(array);
|
||||
Span<T> span = CollectionsMarshal.AsSpan<T>(_collection).Slice(_begin, _length);
|
||||
Span<T> target = new Span<T>(array, arrayIndex, _length);
|
||||
span.CopyTo(target);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = _begin; i < _length; i++) {
|
||||
yield return this[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollection<T>.Add(T item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ICollection<T>.Clear()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
bool ICollection<T>.Remove(T item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ListSegment"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Part of a collection. This contains a direct reference to _origin collection, so all
|
||||
/// change to _origin collection will be reflected in this object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
///
|
||||
/// </typeparam>
|
||||
public struct ListSegment<T> : ICollection<T>
|
||||
{
|
||||
|
||||
private int _begin;
|
||||
private int _length;
|
||||
private List<T> _collection;
|
||||
|
||||
public ListSegment(List<T> collection, int begin, int length)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(collection);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(begin, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(length, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(begin + length, collection.Count);
|
||||
_collection = collection;
|
||||
_begin = begin;
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public T this[int indexValue]
|
||||
{
|
||||
get
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(indexValue, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(indexValue, _length);
|
||||
return _collection[indexValue + _begin];
|
||||
}
|
||||
}
|
||||
|
||||
public T this[Index i]
|
||||
{
|
||||
get
|
||||
{
|
||||
int offset = i.IsFromEnd ? _length - i.Value : i.Value;
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(offset, 0);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(offset, _length);
|
||||
return _collection[offset + _begin];
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly => true;
|
||||
|
||||
public int Count => _length;
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
int index = _collection.IndexOf(item);
|
||||
return index >= _begin && index < _length + index;
|
||||
}
|
||||
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(array);
|
||||
Span<T> span = CollectionsMarshal.AsSpan<T>(_collection).Slice(_begin, _length);
|
||||
Span<T> target = new Span<T>(array, arrayIndex, _length);
|
||||
span.CopyTo(target);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = _begin; i < _length; i++) {
|
||||
yield return this[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollection<T>.Add(T item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
void ICollection<T>.Clear()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
bool ICollection<T>.Remove(T item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,191 +1,191 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="NotEnumerableList"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public static class LinearBagBuilder
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Build a <see cref="LinearBag{T}" /> from a read-only span. Capacity will exactly fit
|
||||
/// the input.
|
||||
/// </summary>
|
||||
public static LinearBag<T> FromSpan<T>(ReadOnlySpan<T> values)
|
||||
{
|
||||
if (values.IsEmpty) {
|
||||
return new LinearBag<T>(4);
|
||||
}
|
||||
LinearBag<T> bag = new(values.Length);
|
||||
for (int i = 0; i < values.Length; i++) {
|
||||
bag.Add(values[i]);
|
||||
}
|
||||
return bag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very lightweight contiguous storage structure: unordered, not enumerable by design.
|
||||
/// Provides O(1) Add and O(1) RemoveAt (by swapping with the tail). Intended for high-
|
||||
/// performance scenarios where element ordering does not matter. NOT thread-safe.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Element type.
|
||||
/// </typeparam>
|
||||
[CollectionBuilder(typeof(LinearBagBuilder), nameof(LinearBagBuilder.FromSpan))]
|
||||
public class LinearBag<T>(int capacity = 4)
|
||||
{
|
||||
|
||||
// Invariant: valid elements occupy indexes [0, Count-1]. Count is the number of live elements.
|
||||
private T[] _items = new T[Math.Max(0, capacity)];
|
||||
|
||||
/// <summary>
|
||||
/// Access element by index (0..Count-1). Throws if out of range.
|
||||
/// </summary>
|
||||
public T this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (uint)index >= (uint)Count ? throw new ArgumentOutOfRangeException(nameof(index)) : _items[index];
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set
|
||||
{
|
||||
if ((uint)index >= (uint)Count) {
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
_items[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Total allocated slots.
|
||||
/// </summary>
|
||||
public int Capacity => _items.Length;
|
||||
|
||||
/// <summary>
|
||||
/// Number of currently stored elements (valid index range 0..Count-1).
|
||||
/// </summary>
|
||||
public int Count { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item (unordered). Expands internal array if needed.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Add(T item)
|
||||
{
|
||||
if (Count == _items.Length) {
|
||||
EnsureCapacity(Count + 1);
|
||||
}
|
||||
|
||||
_items[Count] = item;
|
||||
Count++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a span over the live portion of the bag (0..Count-1).
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Span<T> AsSpan() => new Span<T>(_items, 0, Count);
|
||||
|
||||
/// <summary>
|
||||
/// Clears all elements and zeroes out references to avoid retention. Count becomes 0.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Clear()
|
||||
{
|
||||
Array.Clear(_items, 0, Count);
|
||||
Count = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fast clear: only resets Count (leaves underlying array unchanged). References are NOT
|
||||
/// released. Use only when you are certain old references can remain.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void FastClear() => Count = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Removes the first occurrence of value (unordered). Does nothing if not found.
|
||||
/// </summary>
|
||||
public void Remove(T value)
|
||||
{
|
||||
EqualityComparer<T> comparer = EqualityComparer<T>.Default;
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals(_items[i], value))
|
||||
{
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes element at index by swapping the last element into its slot (unless already
|
||||
/// last). Preserves O(1) removal at cost of ordering.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if ((uint)index >= (uint)Count) {
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
int last = Count - 1;
|
||||
if (index != last) {
|
||||
_items[index] = _items[last];
|
||||
}
|
||||
|
||||
_items[last] = default!; // release reference / reset value
|
||||
Count = last;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures capacity is at least <paramref name="min" />. Doubles size when growing.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void EnsureCapacity(int min)
|
||||
{
|
||||
if (_items.Length >= min) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newCapacity = _items.Length == 0 ? 4 : _items.Length * 2;
|
||||
if (newCapacity < min) {
|
||||
newCapacity = min;
|
||||
}
|
||||
|
||||
Array.Resize(ref _items, newCapacity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="NotEnumerableList"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public static class LinearBagBuilder
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Build a <see cref="LinearBag{T}" /> from a read-only span. Capacity will exactly fit
|
||||
/// the input.
|
||||
/// </summary>
|
||||
public static LinearBag<T> FromSpan<T>(ReadOnlySpan<T> values)
|
||||
{
|
||||
if (values.IsEmpty) {
|
||||
return new LinearBag<T>(4);
|
||||
}
|
||||
LinearBag<T> bag = new(values.Length);
|
||||
for (int i = 0; i < values.Length; i++) {
|
||||
bag.Add(values[i]);
|
||||
}
|
||||
return bag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very lightweight contiguous storage structure: unordered, not enumerable by design.
|
||||
/// Provides O(1) Add and O(1) RemoveAt (by swapping with the tail). Intended for high-
|
||||
/// performance scenarios where element ordering does not matter. NOT thread-safe.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Element type.
|
||||
/// </typeparam>
|
||||
[CollectionBuilder(typeof(LinearBagBuilder), nameof(LinearBagBuilder.FromSpan))]
|
||||
public class LinearBag<T>(int capacity = 4)
|
||||
{
|
||||
|
||||
// Invariant: valid elements occupy indexes [0, Count-1]. Count is the number of live elements.
|
||||
private T[] _items = new T[Math.Max(0, capacity)];
|
||||
|
||||
/// <summary>
|
||||
/// Access element by index (0..Count-1). Throws if out of range.
|
||||
/// </summary>
|
||||
public T this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (uint)index >= (uint)Count ? throw new ArgumentOutOfRangeException(nameof(index)) : _items[index];
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set
|
||||
{
|
||||
if ((uint)index >= (uint)Count) {
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
_items[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Total allocated slots.
|
||||
/// </summary>
|
||||
public int Capacity => _items.Length;
|
||||
|
||||
/// <summary>
|
||||
/// Number of currently stored elements (valid index range 0..Count-1).
|
||||
/// </summary>
|
||||
public int Count { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item (unordered). Expands internal array if needed.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Add(T item)
|
||||
{
|
||||
if (Count == _items.Length) {
|
||||
EnsureCapacity(Count + 1);
|
||||
}
|
||||
|
||||
_items[Count] = item;
|
||||
Count++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a span over the live portion of the bag (0..Count-1).
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Span<T> AsSpan() => new Span<T>(_items, 0, Count);
|
||||
|
||||
/// <summary>
|
||||
/// Clears all elements and zeroes out references to avoid retention. Count becomes 0.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Clear()
|
||||
{
|
||||
Array.Clear(_items, 0, Count);
|
||||
Count = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fast clear: only resets Count (leaves underlying array unchanged). References are NOT
|
||||
/// released. Use only when you are certain old references can remain.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void FastClear() => Count = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Removes the first occurrence of value (unordered). Does nothing if not found.
|
||||
/// </summary>
|
||||
public void Remove(T value)
|
||||
{
|
||||
EqualityComparer<T> comparer = EqualityComparer<T>.Default;
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals(_items[i], value))
|
||||
{
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes element at index by swapping the last element into its slot (unless already
|
||||
/// last). Preserves O(1) removal at cost of ordering.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if ((uint)index >= (uint)Count) {
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
int last = Count - 1;
|
||||
if (index != last) {
|
||||
_items[index] = _items[last];
|
||||
}
|
||||
|
||||
_items[last] = default!; // release reference / reset value
|
||||
Count = last;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures capacity is at least <paramref name="min" />. Doubles size when growing.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void EnsureCapacity(int min)
|
||||
{
|
||||
if (_items.Length >= min) {
|
||||
return;
|
||||
}
|
||||
|
||||
int newCapacity = _items.Length == 0 ? 4 : _items.Length * 2;
|
||||
if (newCapacity < min) {
|
||||
newCapacity = min;
|
||||
}
|
||||
|
||||
Array.Resize(ref _items, newCapacity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,181 +1,181 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RandomAccessibleStack"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public class RandomAccessibleStack<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
private const int DefaultCapacity = 4;
|
||||
|
||||
private T[] _array;
|
||||
private int _size;
|
||||
private int _version;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RandomAccessStack class that is empty and has the
|
||||
/// default initial capacity.
|
||||
/// </summary>
|
||||
public RandomAccessibleStack()
|
||||
{
|
||||
_array = new T[DefaultCapacity];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RandomAccessStack class that is empty and has the
|
||||
/// specified initial capacity.
|
||||
/// </summary>
|
||||
public RandomAccessibleStack(int capacity)
|
||||
{
|
||||
if (capacity < 0) {
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(capacity), "Capacity must be non-negative.");
|
||||
}
|
||||
|
||||
_array = new T[capacity];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the element at the specified index in the stack (0 = bottom, Count-1 =
|
||||
/// top).
|
||||
/// </summary>
|
||||
public T this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index < 0 || index >= _size) {
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
return _array[index];
|
||||
}
|
||||
/*
|
||||
set
|
||||
{
|
||||
if( index < 0 || index >= PrimSize ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( index ) );
|
||||
}
|
||||
_array[ index ] = value;
|
||||
_version++;
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of elements contained in the stack.
|
||||
/// </summary>
|
||||
public int Count => _size;
|
||||
|
||||
/// <summary>
|
||||
/// Removes all objects from the stack.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
Array.Clear(_array, 0, _size);
|
||||
_size = 0;
|
||||
_version++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through the stack from top to bottom. Throws if
|
||||
/// the stack is modified during iteration.
|
||||
/// </summary>
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
int expectedVersion = _version;
|
||||
for (int i = _size - 1; i >= 0; i--)
|
||||
{
|
||||
if (expectedVersion != _version) {
|
||||
throw new InvalidOperationException(
|
||||
"Collection was modified during enumeration.");
|
||||
}
|
||||
|
||||
yield return _array[i];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the object at the top of the stack without removing it.
|
||||
/// </summary>
|
||||
public T Peek()
|
||||
{
|
||||
if (_size == 0) {
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
|
||||
return _array[_size - 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes and returns the object at the top of the stack.
|
||||
/// </summary>
|
||||
public T Pop()
|
||||
{
|
||||
if (_size == 0) {
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
|
||||
T item = _array[--_size];
|
||||
_array[_size] = default!;
|
||||
_version++;
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item to the top of the stack.
|
||||
/// </summary>
|
||||
public void Push(T item)
|
||||
{
|
||||
if (_size == _array.Length) {
|
||||
EnsureCapacity(_size + 1);
|
||||
}
|
||||
|
||||
_array[_size++] = item;
|
||||
_version++;
|
||||
}
|
||||
|
||||
private void EnsureCapacity(int min)
|
||||
{
|
||||
int newCapacity = _array.Length == 0 ? DefaultCapacity : _array.Length * 2;
|
||||
if (newCapacity < min) {
|
||||
newCapacity = min;
|
||||
}
|
||||
|
||||
Array.Resize(ref _array, newCapacity);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RandomAccessibleStack"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public class RandomAccessibleStack<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
private const int DefaultCapacity = 4;
|
||||
|
||||
private T[] _array;
|
||||
private int _size;
|
||||
private int _version;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RandomAccessStack class that is empty and has the
|
||||
/// default initial capacity.
|
||||
/// </summary>
|
||||
public RandomAccessibleStack()
|
||||
{
|
||||
_array = new T[DefaultCapacity];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RandomAccessStack class that is empty and has the
|
||||
/// specified initial capacity.
|
||||
/// </summary>
|
||||
public RandomAccessibleStack(int capacity)
|
||||
{
|
||||
if (capacity < 0) {
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(capacity), "Capacity must be non-negative.");
|
||||
}
|
||||
|
||||
_array = new T[capacity];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the element at the specified index in the stack (0 = bottom, Count-1 =
|
||||
/// top).
|
||||
/// </summary>
|
||||
public T this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index < 0 || index >= _size) {
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
return _array[index];
|
||||
}
|
||||
/*
|
||||
set
|
||||
{
|
||||
if( index < 0 || index >= PrimSize ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( index ) );
|
||||
}
|
||||
_array[ index ] = value;
|
||||
_version++;
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of elements contained in the stack.
|
||||
/// </summary>
|
||||
public int Count => _size;
|
||||
|
||||
/// <summary>
|
||||
/// Removes all objects from the stack.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
Array.Clear(_array, 0, _size);
|
||||
_size = 0;
|
||||
_version++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through the stack from top to bottom. Throws if
|
||||
/// the stack is modified during iteration.
|
||||
/// </summary>
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
int expectedVersion = _version;
|
||||
for (int i = _size - 1; i >= 0; i--)
|
||||
{
|
||||
if (expectedVersion != _version) {
|
||||
throw new InvalidOperationException(
|
||||
"Collection was modified during enumeration.");
|
||||
}
|
||||
|
||||
yield return _array[i];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the object at the top of the stack without removing it.
|
||||
/// </summary>
|
||||
public T Peek()
|
||||
{
|
||||
if (_size == 0) {
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
|
||||
return _array[_size - 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes and returns the object at the top of the stack.
|
||||
/// </summary>
|
||||
public T Pop()
|
||||
{
|
||||
if (_size == 0) {
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
|
||||
T item = _array[--_size];
|
||||
_array[_size] = default!;
|
||||
_version++;
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item to the top of the stack.
|
||||
/// </summary>
|
||||
public void Push(T item)
|
||||
{
|
||||
if (_size == _array.Length) {
|
||||
EnsureCapacity(_size + 1);
|
||||
}
|
||||
|
||||
_array[_size++] = item;
|
||||
_version++;
|
||||
}
|
||||
|
||||
private void EnsureCapacity(int min)
|
||||
{
|
||||
int newCapacity = _array.Length == 0 ? DefaultCapacity : _array.Length * 2;
|
||||
if (newCapacity < min) {
|
||||
newCapacity = min;
|
||||
}
|
||||
|
||||
Array.Resize(ref _array, newCapacity);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,162 +1,162 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="StringHashMultiplexer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public sealed class StringHashMultiplexer : IHashMultiplexer<string>
|
||||
{
|
||||
|
||||
private int _initCount, _remainedCount, _hashCache, _hashLast;
|
||||
private string _source, _sourceLast;
|
||||
|
||||
public int RemainedMultiplexCount
|
||||
{
|
||||
get => _remainedCount;
|
||||
set => _initCount = value;
|
||||
}
|
||||
|
||||
public void CacheHash(string obj, int count)
|
||||
{
|
||||
_hashCache = ForceComputeHash(obj);
|
||||
_initCount = count;
|
||||
_remainedCount = _initCount;
|
||||
_source = obj;
|
||||
}
|
||||
|
||||
public bool Equals(string x, string y)
|
||||
{
|
||||
return x == y;
|
||||
}
|
||||
|
||||
public void ExtendCache(int count)
|
||||
{
|
||||
_initCount += count;
|
||||
_remainedCount += count;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe int ForceComputeHash([NotNull] string obj)
|
||||
{
|
||||
int hash;
|
||||
fixed (char* cPtr = obj.AsSpan()) {
|
||||
hash = NativeIntrinsic.Context.city_hash_simplify(cPtr, obj.Length);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public int GetHashCode(string obj)
|
||||
{
|
||||
if (_remainedCount > 0 && ReferenceEquals(_source, obj))
|
||||
{
|
||||
_remainedCount--;
|
||||
return _hashCache;
|
||||
}
|
||||
if (ReferenceEquals(_sourceLast, obj)) {
|
||||
return _hashLast;
|
||||
}
|
||||
_sourceLast = obj;
|
||||
_hashLast = ForceComputeHash(obj);
|
||||
return _hashLast;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class ConcurrentStringHashMultiplexer : IHashMultiplexer<string>, IDisposable
|
||||
{
|
||||
|
||||
private bool disposedValue;
|
||||
private readonly ThreadLocal<StringHashMultiplexer> _multiplexers =
|
||||
new(() => new StringHashMultiplexer());
|
||||
|
||||
public int RemainedMultiplexCount
|
||||
{
|
||||
get => _multiplexers.Value!.RemainedMultiplexCount;
|
||||
set => _multiplexers.Value!.RemainedMultiplexCount = value;
|
||||
}
|
||||
|
||||
public void CacheHash(string obj, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// ~ConcurrentStringHashMultiplexer()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing:true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public bool Equals(string x, string y)
|
||||
{
|
||||
return x == y;
|
||||
}
|
||||
|
||||
public void ExtendCache(int count)
|
||||
{
|
||||
_multiplexers.Value!.ExtendCache(count);
|
||||
}
|
||||
|
||||
public unsafe int ForceComputeHash([NotNull] string obj)
|
||||
{
|
||||
int hash;
|
||||
fixed (char* cPtr = obj.AsSpan()) {
|
||||
hash = NativeIntrinsic.Context.city_hash_simplify(cPtr, obj.Length);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public int GetHashCode(string obj)
|
||||
{
|
||||
return _multiplexers.Value!.GetHashCode(obj);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing) {
|
||||
_multiplexers.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="StringHashMultiplexer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public sealed class StringHashMultiplexer : IHashMultiplexer<string>
|
||||
{
|
||||
|
||||
private int _initCount, _remainedCount, _hashCache, _hashLast;
|
||||
private string _source, _sourceLast;
|
||||
|
||||
public int RemainedMultiplexCount
|
||||
{
|
||||
get => _remainedCount;
|
||||
set => _initCount = value;
|
||||
}
|
||||
|
||||
public void CacheHash(string obj, int count)
|
||||
{
|
||||
_hashCache = ForceComputeHash(obj);
|
||||
_initCount = count;
|
||||
_remainedCount = _initCount;
|
||||
_source = obj;
|
||||
}
|
||||
|
||||
public bool Equals(string x, string y)
|
||||
{
|
||||
return x == y;
|
||||
}
|
||||
|
||||
public void ExtendCache(int count)
|
||||
{
|
||||
_initCount += count;
|
||||
_remainedCount += count;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe int ForceComputeHash([NotNull] string obj)
|
||||
{
|
||||
int hash;
|
||||
fixed (char* cPtr = obj.AsSpan()) {
|
||||
hash = NativeIntrinsic.Context.city_hash_simplify(cPtr, obj.Length);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public int GetHashCode(string obj)
|
||||
{
|
||||
if (_remainedCount > 0 && ReferenceEquals(_source, obj))
|
||||
{
|
||||
_remainedCount--;
|
||||
return _hashCache;
|
||||
}
|
||||
if (ReferenceEquals(_sourceLast, obj)) {
|
||||
return _hashLast;
|
||||
}
|
||||
_sourceLast = obj;
|
||||
_hashLast = ForceComputeHash(obj);
|
||||
return _hashLast;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class ConcurrentStringHashMultiplexer : IHashMultiplexer<string>, IDisposable
|
||||
{
|
||||
|
||||
private bool disposedValue;
|
||||
private readonly ThreadLocal<StringHashMultiplexer> _multiplexers =
|
||||
new(() => new StringHashMultiplexer());
|
||||
|
||||
public int RemainedMultiplexCount
|
||||
{
|
||||
get => _multiplexers.Value!.RemainedMultiplexCount;
|
||||
set => _multiplexers.Value!.RemainedMultiplexCount = value;
|
||||
}
|
||||
|
||||
public void CacheHash(string obj, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// ~ConcurrentStringHashMultiplexer()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing:true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public bool Equals(string x, string y)
|
||||
{
|
||||
return x == y;
|
||||
}
|
||||
|
||||
public void ExtendCache(int count)
|
||||
{
|
||||
_multiplexers.Value!.ExtendCache(count);
|
||||
}
|
||||
|
||||
public unsafe int ForceComputeHash([NotNull] string obj)
|
||||
{
|
||||
int hash;
|
||||
fixed (char* cPtr = obj.AsSpan()) {
|
||||
hash = NativeIntrinsic.Context.city_hash_simplify(cPtr, obj.Length);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public int GetHashCode(string obj)
|
||||
{
|
||||
return _multiplexers.Value!.GetHashCode(obj);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing) {
|
||||
_multiplexers.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="BattleField"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
// TODO 这玩意如何加载一个渲染流程以获得各个图元还没搞清楚
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class BattleField : ControllingItem
|
||||
{
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="BattleField"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
// TODO 这玩意如何加载一个渲染流程以获得各个图元还没搞清楚
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class BattleField : ControllingItem
|
||||
{
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,149 +1,149 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ButtonGroup"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Transactions;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public abstract class KeyboardButtonGroup : ControllingItem
|
||||
{
|
||||
|
||||
private List<TriggerButton> buttonList;
|
||||
private TriggerButton current;
|
||||
|
||||
public KeyboardButtonGroup()
|
||||
{
|
||||
buttonList = new List<TriggerButton>();
|
||||
}
|
||||
|
||||
public bool IsEntity
|
||||
{
|
||||
get => false;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public TriggerButton CurrentButton
|
||||
{
|
||||
get => current;
|
||||
}
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
protected List<TriggerButton> AllButton
|
||||
{
|
||||
get => buttonList;
|
||||
}
|
||||
|
||||
public void AddButton(TriggerButton button)
|
||||
{
|
||||
buttonList.Add(button);
|
||||
}
|
||||
|
||||
public abstract void Confirm();
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
foreach (TriggerButton item in buttonList) {
|
||||
yield return item.Single();
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveDown()
|
||||
{
|
||||
TriggerButton button = current;
|
||||
while ((button.Down != null) && button.Down.IsDisabled) {
|
||||
button = button.Right;
|
||||
}
|
||||
if (current == button) {
|
||||
return;
|
||||
}
|
||||
current.DeHighlight();
|
||||
button.Enable();
|
||||
current = button;
|
||||
}
|
||||
|
||||
public void MoveLeft()
|
||||
{
|
||||
TriggerButton button = current;
|
||||
while ((button.Left != null) && button.Left.IsDisabled) {
|
||||
button = button.Left;
|
||||
}
|
||||
if (current == button) {
|
||||
return;
|
||||
}
|
||||
current.DeHighlight();
|
||||
button.Enable();
|
||||
current = button;
|
||||
}
|
||||
|
||||
public void MoveRight()
|
||||
{
|
||||
TriggerButton button = current;
|
||||
while ((button.Right != null) && button.Right.IsDisabled) {
|
||||
button = button.Right;
|
||||
}
|
||||
if (current == button) {
|
||||
return;
|
||||
}
|
||||
current.DeHighlight();
|
||||
button.Enable();
|
||||
current = button;
|
||||
}
|
||||
|
||||
public void MoveUp()
|
||||
{
|
||||
TriggerButton button = current;
|
||||
while ((button.Up != null) && button.Up.IsDisabled) {
|
||||
button = button.Right;
|
||||
}
|
||||
if (current == button) {
|
||||
return;
|
||||
}
|
||||
current.DeHighlight();
|
||||
button.Enable();
|
||||
current = button;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ButtonGroup"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Transactions;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public abstract class KeyboardButtonGroup : ControllingItem
|
||||
{
|
||||
|
||||
private List<TriggerButton> buttonList;
|
||||
private TriggerButton current;
|
||||
|
||||
public KeyboardButtonGroup()
|
||||
{
|
||||
buttonList = new List<TriggerButton>();
|
||||
}
|
||||
|
||||
public bool IsEntity
|
||||
{
|
||||
get => false;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public TriggerButton CurrentButton
|
||||
{
|
||||
get => current;
|
||||
}
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
protected List<TriggerButton> AllButton
|
||||
{
|
||||
get => buttonList;
|
||||
}
|
||||
|
||||
public void AddButton(TriggerButton button)
|
||||
{
|
||||
buttonList.Add(button);
|
||||
}
|
||||
|
||||
public abstract void Confirm();
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
foreach (TriggerButton item in buttonList) {
|
||||
yield return item.Single();
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveDown()
|
||||
{
|
||||
TriggerButton button = current;
|
||||
while ((button.Down != null) && button.Down.IsDisabled) {
|
||||
button = button.Right;
|
||||
}
|
||||
if (current == button) {
|
||||
return;
|
||||
}
|
||||
current.DeHighlight();
|
||||
button.Enable();
|
||||
current = button;
|
||||
}
|
||||
|
||||
public void MoveLeft()
|
||||
{
|
||||
TriggerButton button = current;
|
||||
while ((button.Left != null) && button.Left.IsDisabled) {
|
||||
button = button.Left;
|
||||
}
|
||||
if (current == button) {
|
||||
return;
|
||||
}
|
||||
current.DeHighlight();
|
||||
button.Enable();
|
||||
current = button;
|
||||
}
|
||||
|
||||
public void MoveRight()
|
||||
{
|
||||
TriggerButton button = current;
|
||||
while ((button.Right != null) && button.Right.IsDisabled) {
|
||||
button = button.Right;
|
||||
}
|
||||
if (current == button) {
|
||||
return;
|
||||
}
|
||||
current.DeHighlight();
|
||||
button.Enable();
|
||||
current = button;
|
||||
}
|
||||
|
||||
public void MoveUp()
|
||||
{
|
||||
TriggerButton button = current;
|
||||
while ((button.Up != null) && button.Up.IsDisabled) {
|
||||
button = button.Right;
|
||||
}
|
||||
if (current == button) {
|
||||
return;
|
||||
}
|
||||
current.DeHighlight();
|
||||
button.Enable();
|
||||
current = button;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,109 +1,109 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CharacterIndexImage"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class CharacterLineIndexImage : ControllingItem
|
||||
{
|
||||
|
||||
private char[] displayIndex;
|
||||
private char defaultChar;
|
||||
|
||||
private Dictionary<char, PlainGeometryMesh> texIndex;
|
||||
private int length;
|
||||
private PlainGeometryMesh _tittleMesh;
|
||||
|
||||
public CharacterLineIndexImage(
|
||||
int length,
|
||||
char defaultChar,
|
||||
PlainGeometryMesh tittleMesh,
|
||||
IEnumerable<(char, PlainGeometryMesh)> indexEnumeration)
|
||||
{
|
||||
this.length = length;
|
||||
displayIndex = new char[length];
|
||||
_tittleMesh = tittleMesh;
|
||||
texIndex = indexEnumeration.ToDictionary(item => item.Item1, item => item.Item2);
|
||||
}
|
||||
|
||||
public bool IsEntity
|
||||
{
|
||||
get => true;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Vec2 Position
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Display(string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message)) {
|
||||
message = string.Empty;
|
||||
}
|
||||
|
||||
string result = (message.Length >= length) ?
|
||||
message.Substring(message.Length - displayIndex.Length) :
|
||||
message.PadLeft(
|
||||
length, defaultChar);
|
||||
|
||||
displayIndex = result.ToCharArray();
|
||||
}
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return _tittleMesh;
|
||||
foreach (char item in displayIndex) {
|
||||
yield return texIndex[item];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CharacterIndexImage"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class CharacterLineIndexImage : ControllingItem
|
||||
{
|
||||
|
||||
private char[] displayIndex;
|
||||
private char defaultChar;
|
||||
|
||||
private Dictionary<char, PlainGeometryMesh> texIndex;
|
||||
private int length;
|
||||
private PlainGeometryMesh _tittleMesh;
|
||||
|
||||
public CharacterLineIndexImage(
|
||||
int length,
|
||||
char defaultChar,
|
||||
PlainGeometryMesh tittleMesh,
|
||||
IEnumerable<(char, PlainGeometryMesh)> indexEnumeration)
|
||||
{
|
||||
this.length = length;
|
||||
displayIndex = new char[length];
|
||||
_tittleMesh = tittleMesh;
|
||||
texIndex = indexEnumeration.ToDictionary(item => item.Item1, item => item.Item2);
|
||||
}
|
||||
|
||||
public bool IsEntity
|
||||
{
|
||||
get => true;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Vec2 Position
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Display(string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message)) {
|
||||
message = string.Empty;
|
||||
}
|
||||
|
||||
string result = (message.Length >= length) ?
|
||||
message.Substring(message.Length - displayIndex.Length) :
|
||||
message.PadLeft(
|
||||
length, defaultChar);
|
||||
|
||||
displayIndex = result.ToCharArray();
|
||||
}
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return _tittleMesh;
|
||||
foreach (char item in displayIndex) {
|
||||
yield return texIndex[item];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ControllingIntem"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public interface ControllingItem : IEnumerable<PlainGeometryMesh>
|
||||
{
|
||||
|
||||
public abstract bool IsEntity { get; }
|
||||
|
||||
public abstract ReadOnlySpan<Vec4> TextureBox { get; }
|
||||
|
||||
public abstract Rectangle BoundingBox { get; set; }
|
||||
|
||||
public abstract Vec2 Position { get; set; }
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ControllingIntem"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public interface ControllingItem : IEnumerable<PlainGeometryMesh>
|
||||
{
|
||||
|
||||
public abstract bool IsEntity { get; }
|
||||
|
||||
public abstract ReadOnlySpan<Vec4> TextureBox { get; }
|
||||
|
||||
public abstract Rectangle BoundingBox { get; set; }
|
||||
|
||||
public abstract Vec2 Position { get; set; }
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="DecorationBox.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class DecorationBox : ControllingItem
|
||||
{
|
||||
|
||||
private PlainGeometryMesh renderMesh;
|
||||
|
||||
public DecorationBox(Rectangle bound, Image texture, Vec2[] texCoord)
|
||||
{
|
||||
renderMesh = new PlainGeometryMesh(
|
||||
BoundingBox, new TextureProvider(texture, texCoord));
|
||||
}
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => renderMesh.TextureCoord;
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return renderMesh;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="DecorationBox.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class DecorationBox : ControllingItem
|
||||
{
|
||||
|
||||
private PlainGeometryMesh renderMesh;
|
||||
|
||||
public DecorationBox(Rectangle bound, Image texture, Vec2[] texCoord)
|
||||
{
|
||||
renderMesh = new PlainGeometryMesh(
|
||||
BoundingBox, new TextureProvider(texture, texCoord));
|
||||
}
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => renderMesh.TextureCoord;
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return renderMesh;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MarkingLable"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class MarkingLabel : ControllingItem
|
||||
{
|
||||
|
||||
private PlainGeometryMesh marker;
|
||||
|
||||
private Vec2 _currentPosition, _movementVec;
|
||||
|
||||
public MarkingLabel(PlainGeometryMesh marker)
|
||||
{
|
||||
this.marker = marker;
|
||||
}
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => marker.TextureCoord;
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return marker;
|
||||
}
|
||||
|
||||
public void Move(Vec2 movement)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void MoveTo(Vec2 target)
|
||||
{
|
||||
Move(target - Position);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MarkingLable"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class MarkingLabel : ControllingItem
|
||||
{
|
||||
|
||||
private PlainGeometryMesh marker;
|
||||
|
||||
private Vec2 _currentPosition, _movementVec;
|
||||
|
||||
public MarkingLabel(PlainGeometryMesh marker)
|
||||
{
|
||||
this.marker = marker;
|
||||
}
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => marker.TextureCoord;
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return marker;
|
||||
}
|
||||
|
||||
public void Move(Vec2 movement)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void MoveTo(Vec2 target)
|
||||
{
|
||||
Move(target - Position);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,213 +1,213 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TriggerButton"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public delegate void RenderButtonTextureCallback(ButtonStatus status, float beginTime, in TextureProvider texture);
|
||||
|
||||
public enum ButtonStatus
|
||||
{
|
||||
|
||||
Error = 0b0,
|
||||
Disable = 0b1,
|
||||
Enable = 0b10,
|
||||
Highlight = 0b100,
|
||||
Confirm = 0b1000,
|
||||
|
||||
DisableToEnable = Disable | Enable,
|
||||
EnableToDisable = -(Enable | DisableToEnable),
|
||||
|
||||
EnableToHighlight = Enable | Highlight,
|
||||
HighlightToEnable = -(Enable | Highlight),
|
||||
|
||||
HighlightToDisable = -(Highlight | Disable),
|
||||
|
||||
}
|
||||
|
||||
public class TriggerButton : ControllingItem
|
||||
{
|
||||
|
||||
private Action? confirmCallback;
|
||||
private Action? disableCallback;
|
||||
|
||||
#nullable enable
|
||||
private Action? enableCallback;
|
||||
private float _statusBeginTime;
|
||||
|
||||
private RenderButtonTextureCallback _renderButton;
|
||||
private TextureProvider _texture;
|
||||
|
||||
#nullable restore
|
||||
|
||||
public TriggerButton()
|
||||
{
|
||||
CurrentStatus = ButtonStatus.Disable;
|
||||
}
|
||||
|
||||
public event Action ConfirmEvent
|
||||
{
|
||||
add { confirmCallback += value; }
|
||||
remove { confirmCallback -= value; }
|
||||
}
|
||||
|
||||
public event Action DisableEvent
|
||||
{
|
||||
add { disableCallback += value; }
|
||||
remove { disableCallback -= value; }
|
||||
}
|
||||
|
||||
public event Action EnableEvent
|
||||
{
|
||||
add { enableCallback += value; }
|
||||
remove { enableCallback -= value; }
|
||||
}
|
||||
|
||||
public event RenderButtonTextureCallback RenderButtonTexture
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_renderButton == null)
|
||||
{
|
||||
_renderButton = value;
|
||||
} else
|
||||
{
|
||||
_renderButton += value;
|
||||
}
|
||||
}
|
||||
remove
|
||||
{
|
||||
if (_renderButton != null) {
|
||||
_renderButton -= value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsHighLighted { get; internal set; }
|
||||
|
||||
public bool IsDisabled { get; internal set; }
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
get => MemoryMarshal.Cast<Vec2, Vec4>(_texture.TextureCoordinate);
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public TriggerButton Left { get; internal set; }
|
||||
|
||||
public TriggerButton Right { get; internal set; }
|
||||
|
||||
public TriggerButton Up { get; internal set; }
|
||||
|
||||
public TriggerButton Down { get; internal set; }
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
internal TextureProvider Texture
|
||||
{
|
||||
get => _texture;
|
||||
set => _texture = value;
|
||||
}
|
||||
|
||||
protected ButtonStatus CurrentStatus { get; set; }
|
||||
|
||||
public void DeHighlight()
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Highlight) {
|
||||
CurrentStatus = ButtonStatus.HighlightToEnable;
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
CurrentStatus = CurrentStatus switch
|
||||
{
|
||||
ButtonStatus.Enable => ButtonStatus.EnableToDisable,
|
||||
ButtonStatus.Highlight => ButtonStatus.HighlightToDisable,
|
||||
_ => CurrentStatus,
|
||||
};
|
||||
if (disableCallback != null) {
|
||||
disableCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Disable)
|
||||
{
|
||||
CurrentStatus = ButtonStatus.DisableToEnable;
|
||||
} else
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (enableCallback != null) {
|
||||
enableCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
_renderButton(CurrentStatus, _statusBeginTime, in _texture);
|
||||
yield return new PlainGeometryMesh(this.BoundingBox, _texture);
|
||||
}
|
||||
|
||||
public void Highlight()
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Enable)
|
||||
{
|
||||
CurrentStatus |= ButtonStatus.EnableToHighlight;
|
||||
} else
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (confirmCallback != null) {
|
||||
confirmCallback();
|
||||
}
|
||||
}
|
||||
|
||||
internal void Init(ButtonStatus status)
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Error) {
|
||||
CurrentStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
}//----------------------------------- End of class --------------------------------------------
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TriggerButton"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public delegate void RenderButtonTextureCallback(ButtonStatus status, float beginTime, in TextureProvider texture);
|
||||
|
||||
public enum ButtonStatus
|
||||
{
|
||||
|
||||
Error = 0b0,
|
||||
Disable = 0b1,
|
||||
Enable = 0b10,
|
||||
Highlight = 0b100,
|
||||
Confirm = 0b1000,
|
||||
|
||||
DisableToEnable = Disable | Enable,
|
||||
EnableToDisable = -(Enable | DisableToEnable),
|
||||
|
||||
EnableToHighlight = Enable | Highlight,
|
||||
HighlightToEnable = -(Enable | Highlight),
|
||||
|
||||
HighlightToDisable = -(Highlight | Disable),
|
||||
|
||||
}
|
||||
|
||||
public class TriggerButton : ControllingItem
|
||||
{
|
||||
|
||||
private Action? confirmCallback;
|
||||
private Action? disableCallback;
|
||||
|
||||
#nullable enable
|
||||
private Action? enableCallback;
|
||||
private float _statusBeginTime;
|
||||
|
||||
private RenderButtonTextureCallback _renderButton;
|
||||
private TextureProvider _texture;
|
||||
|
||||
#nullable restore
|
||||
|
||||
public TriggerButton()
|
||||
{
|
||||
CurrentStatus = ButtonStatus.Disable;
|
||||
}
|
||||
|
||||
public event Action ConfirmEvent
|
||||
{
|
||||
add { confirmCallback += value; }
|
||||
remove { confirmCallback -= value; }
|
||||
}
|
||||
|
||||
public event Action DisableEvent
|
||||
{
|
||||
add { disableCallback += value; }
|
||||
remove { disableCallback -= value; }
|
||||
}
|
||||
|
||||
public event Action EnableEvent
|
||||
{
|
||||
add { enableCallback += value; }
|
||||
remove { enableCallback -= value; }
|
||||
}
|
||||
|
||||
public event RenderButtonTextureCallback RenderButtonTexture
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_renderButton == null)
|
||||
{
|
||||
_renderButton = value;
|
||||
} else
|
||||
{
|
||||
_renderButton += value;
|
||||
}
|
||||
}
|
||||
remove
|
||||
{
|
||||
if (_renderButton != null) {
|
||||
_renderButton -= value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsHighLighted { get; internal set; }
|
||||
|
||||
public bool IsDisabled { get; internal set; }
|
||||
|
||||
public bool IsEntity => true;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureBox
|
||||
{
|
||||
get => MemoryMarshal.Cast<Vec2, Vec4>(_texture.TextureCoordinate);
|
||||
}
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
|
||||
public TriggerButton Left { get; internal set; }
|
||||
|
||||
public TriggerButton Right { get; internal set; }
|
||||
|
||||
public TriggerButton Up { get; internal set; }
|
||||
|
||||
public TriggerButton Down { get; internal set; }
|
||||
|
||||
public Vec2 Position { get; set; }
|
||||
|
||||
internal TextureProvider Texture
|
||||
{
|
||||
get => _texture;
|
||||
set => _texture = value;
|
||||
}
|
||||
|
||||
protected ButtonStatus CurrentStatus { get; set; }
|
||||
|
||||
public void DeHighlight()
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Highlight) {
|
||||
CurrentStatus = ButtonStatus.HighlightToEnable;
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
CurrentStatus = CurrentStatus switch
|
||||
{
|
||||
ButtonStatus.Enable => ButtonStatus.EnableToDisable,
|
||||
ButtonStatus.Highlight => ButtonStatus.HighlightToDisable,
|
||||
_ => CurrentStatus,
|
||||
};
|
||||
if (disableCallback != null) {
|
||||
disableCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Disable)
|
||||
{
|
||||
CurrentStatus = ButtonStatus.DisableToEnable;
|
||||
} else
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (enableCallback != null) {
|
||||
enableCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
_renderButton(CurrentStatus, _statusBeginTime, in _texture);
|
||||
yield return new PlainGeometryMesh(this.BoundingBox, _texture);
|
||||
}
|
||||
|
||||
public void Highlight()
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Enable)
|
||||
{
|
||||
CurrentStatus |= ButtonStatus.EnableToHighlight;
|
||||
} else
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (confirmCallback != null) {
|
||||
confirmCallback();
|
||||
}
|
||||
}
|
||||
|
||||
internal void Init(ButtonStatus status)
|
||||
{
|
||||
if (CurrentStatus == ButtonStatus.Error) {
|
||||
CurrentStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
}//----------------------------------- End of class --------------------------------------------
|
||||
}
|
||||
|
||||
@@ -1,234 +1,234 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="KeyEnum"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public enum KeyboardKey : int
|
||||
{
|
||||
|
||||
UNKNOWN = -1,
|
||||
None = 0,
|
||||
Space = 32,
|
||||
Apostrophe = 39/*'*/,
|
||||
Comma = 44/*,*/,
|
||||
Minus = 45/*-*/,
|
||||
Period = 46/*.*/,
|
||||
Slash = 47/*/*/,
|
||||
Zero = 48,
|
||||
One = 49,
|
||||
Two = 50,
|
||||
Three = 51,
|
||||
Four = 52,
|
||||
Five = 53,
|
||||
Six = 54,
|
||||
Seven = 55,
|
||||
Eight = 56,
|
||||
Nine = 57,
|
||||
Semicolon = 59/*,*/,
|
||||
Equal = 61/*=*/,
|
||||
A = 65,
|
||||
B = 66,
|
||||
C = 67,
|
||||
D = 68,
|
||||
E = 69,
|
||||
F = 70,
|
||||
G = 71,
|
||||
H = 72,
|
||||
I = 73,
|
||||
J = 74,
|
||||
K = 75,
|
||||
L = 76,
|
||||
M = 77,
|
||||
N = 78,
|
||||
O = 79,
|
||||
P = 80,
|
||||
Q = 81,
|
||||
R = 82,
|
||||
S = 83,
|
||||
T = 84,
|
||||
U = 85,
|
||||
V = 86,
|
||||
W = 87,
|
||||
X = 88,
|
||||
Y = 89,
|
||||
Z = 90,
|
||||
LeftBracket = 91/*[*/,
|
||||
BACKSLASH = 92/*\*/,
|
||||
RightBracket = 93/*]*/,
|
||||
GraveAccent = 96/*`*/,
|
||||
World1 = 161/*non-US#1*/,
|
||||
World2 = 162/*non-US#2*/,
|
||||
Esc = 256,
|
||||
Enter = 257,
|
||||
Tab = 258,
|
||||
Backspace = 259,
|
||||
Insert = 260,
|
||||
Delete = 261,
|
||||
Right = 262,
|
||||
Left = 263,
|
||||
Down = 264,
|
||||
Up = 265,
|
||||
PgUp = 266,
|
||||
PgDown = 267,
|
||||
Home = 268,
|
||||
End = 269,
|
||||
CapsLock = 280,
|
||||
ScrollLock = 281,
|
||||
NumLock = 282,
|
||||
PrintScreen = 283,
|
||||
Pause = 284,
|
||||
F1 = 290,
|
||||
F2 = 291,
|
||||
F3 = 292,
|
||||
F4 = 293,
|
||||
F5 = 294,
|
||||
F6 = 295,
|
||||
F7 = 296,
|
||||
F8 = 297,
|
||||
F9 = 298,
|
||||
F10 = 299,
|
||||
F11 = 300,
|
||||
F12 = 301,
|
||||
F13 = 302,
|
||||
F14 = 303,
|
||||
F15 = 304,
|
||||
F16 = 305,
|
||||
F17 = 306,
|
||||
F18 = 307,
|
||||
F19 = 308,
|
||||
F20 = 309,
|
||||
F21 = 310,
|
||||
F22 = 311,
|
||||
F23 = 312,
|
||||
F24 = 313,
|
||||
F25 = 314,
|
||||
NumPad0 = 320,
|
||||
NumPad1 = 321,
|
||||
NumPad2 = 322,
|
||||
NumPad3 = 323,
|
||||
NumPad4 = 324,
|
||||
NumPad5 = 325,
|
||||
NumPad6 = 326,
|
||||
NumPad7 = 327,
|
||||
NumPad8 = 328,
|
||||
NumPad9 = 329,
|
||||
NumPadDec = 330,
|
||||
NumPadDiv = 331,
|
||||
NumPadMul = 332,
|
||||
NumPadSub = 333,
|
||||
NumPadAdd = 334,
|
||||
NumPadAnter = 335,
|
||||
NumPadEqual = 336,
|
||||
LeftShift = 340,
|
||||
LeftControl = 341,
|
||||
LeftAlt = 342,
|
||||
LeftSuper = 343,
|
||||
RightShift = 344,
|
||||
RightControl = 345,
|
||||
RightAlt = 346,
|
||||
RightSuper = 347,
|
||||
Menu = 348,
|
||||
First = Space,
|
||||
Last = Menu,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1707
|
||||
#pragma warning disable CA1712
|
||||
#pragma warning disable CA1008
|
||||
#pragma warning disable CA1027
|
||||
public enum Joystick : int
|
||||
#pragma warning restore CA1027
|
||||
{
|
||||
|
||||
Joystick_1 = FrameworkConstant. JOYSTICK_1,
|
||||
Joystick_2 = FrameworkConstant. JOYSTICK_2,
|
||||
Joystick_3 = FrameworkConstant. JOYSTICK_3,
|
||||
Joystick_4 = FrameworkConstant. JOYSTICK_4,
|
||||
Joystick_5 = FrameworkConstant. JOYSTICK_5,
|
||||
Joystick_6 = FrameworkConstant. JOYSTICK_6,
|
||||
Joystick_7 = FrameworkConstant. JOYSTICK_7,
|
||||
Joystick_8 = FrameworkConstant. JOYSTICK_8,
|
||||
Joystick_9 = FrameworkConstant. JOYSTICK_9,
|
||||
Joystick_10 = FrameworkConstant.JOYSTICK_10,
|
||||
Joystick_11 = FrameworkConstant.JOYSTICK_11,
|
||||
Joystick_12 = FrameworkConstant.JOYSTICK_12,
|
||||
Joystick_13 = FrameworkConstant.JOYSTICK_13,
|
||||
Joystick_14 = FrameworkConstant.JOYSTICK_14,
|
||||
Joystick_15 = FrameworkConstant.JOYSTICK_15,
|
||||
Joystick_16 = FrameworkConstant.JOYSTICK_16,
|
||||
First = Joystick_1,
|
||||
Last = Joystick_16
|
||||
|
||||
}
|
||||
|
||||
[System.Flags]
|
||||
public enum Mouse : int
|
||||
{
|
||||
|
||||
Button1 = 0,
|
||||
Button2 = 1,
|
||||
Button3 = 2,
|
||||
Button4 = 3,
|
||||
Button5 = 4,
|
||||
Button6 = 5,
|
||||
Button7 = 6,
|
||||
Button8 = 7,
|
||||
First = Button1,
|
||||
Last = Button8,
|
||||
Left = Button1,
|
||||
Right = Button2,
|
||||
Middle = Button3
|
||||
|
||||
}
|
||||
|
||||
#pragma warning restore CA1707
|
||||
#pragma warning restore CA1712
|
||||
#pragma warning restore CA7008
|
||||
|
||||
internal enum InputEquipment
|
||||
{
|
||||
|
||||
Keyboard,
|
||||
Mouse,
|
||||
Joystick
|
||||
|
||||
}
|
||||
|
||||
public enum KeyStatus : int
|
||||
{
|
||||
|
||||
RELEASE = 0,
|
||||
PRESS = 1
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="KeyEnum"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public enum KeyboardKey : int
|
||||
{
|
||||
|
||||
UNKNOWN = -1,
|
||||
None = 0,
|
||||
Space = 32,
|
||||
Apostrophe = 39/*'*/,
|
||||
Comma = 44/*,*/,
|
||||
Minus = 45/*-*/,
|
||||
Period = 46/*.*/,
|
||||
Slash = 47/*/*/,
|
||||
Zero = 48,
|
||||
One = 49,
|
||||
Two = 50,
|
||||
Three = 51,
|
||||
Four = 52,
|
||||
Five = 53,
|
||||
Six = 54,
|
||||
Seven = 55,
|
||||
Eight = 56,
|
||||
Nine = 57,
|
||||
Semicolon = 59/*,*/,
|
||||
Equal = 61/*=*/,
|
||||
A = 65,
|
||||
B = 66,
|
||||
C = 67,
|
||||
D = 68,
|
||||
E = 69,
|
||||
F = 70,
|
||||
G = 71,
|
||||
H = 72,
|
||||
I = 73,
|
||||
J = 74,
|
||||
K = 75,
|
||||
L = 76,
|
||||
M = 77,
|
||||
N = 78,
|
||||
O = 79,
|
||||
P = 80,
|
||||
Q = 81,
|
||||
R = 82,
|
||||
S = 83,
|
||||
T = 84,
|
||||
U = 85,
|
||||
V = 86,
|
||||
W = 87,
|
||||
X = 88,
|
||||
Y = 89,
|
||||
Z = 90,
|
||||
LeftBracket = 91/*[*/,
|
||||
BACKSLASH = 92/*\*/,
|
||||
RightBracket = 93/*]*/,
|
||||
GraveAccent = 96/*`*/,
|
||||
World1 = 161/*non-US#1*/,
|
||||
World2 = 162/*non-US#2*/,
|
||||
Esc = 256,
|
||||
Enter = 257,
|
||||
Tab = 258,
|
||||
Backspace = 259,
|
||||
Insert = 260,
|
||||
Delete = 261,
|
||||
Right = 262,
|
||||
Left = 263,
|
||||
Down = 264,
|
||||
Up = 265,
|
||||
PgUp = 266,
|
||||
PgDown = 267,
|
||||
Home = 268,
|
||||
End = 269,
|
||||
CapsLock = 280,
|
||||
ScrollLock = 281,
|
||||
NumLock = 282,
|
||||
PrintScreen = 283,
|
||||
Pause = 284,
|
||||
F1 = 290,
|
||||
F2 = 291,
|
||||
F3 = 292,
|
||||
F4 = 293,
|
||||
F5 = 294,
|
||||
F6 = 295,
|
||||
F7 = 296,
|
||||
F8 = 297,
|
||||
F9 = 298,
|
||||
F10 = 299,
|
||||
F11 = 300,
|
||||
F12 = 301,
|
||||
F13 = 302,
|
||||
F14 = 303,
|
||||
F15 = 304,
|
||||
F16 = 305,
|
||||
F17 = 306,
|
||||
F18 = 307,
|
||||
F19 = 308,
|
||||
F20 = 309,
|
||||
F21 = 310,
|
||||
F22 = 311,
|
||||
F23 = 312,
|
||||
F24 = 313,
|
||||
F25 = 314,
|
||||
NumPad0 = 320,
|
||||
NumPad1 = 321,
|
||||
NumPad2 = 322,
|
||||
NumPad3 = 323,
|
||||
NumPad4 = 324,
|
||||
NumPad5 = 325,
|
||||
NumPad6 = 326,
|
||||
NumPad7 = 327,
|
||||
NumPad8 = 328,
|
||||
NumPad9 = 329,
|
||||
NumPadDec = 330,
|
||||
NumPadDiv = 331,
|
||||
NumPadMul = 332,
|
||||
NumPadSub = 333,
|
||||
NumPadAdd = 334,
|
||||
NumPadAnter = 335,
|
||||
NumPadEqual = 336,
|
||||
LeftShift = 340,
|
||||
LeftControl = 341,
|
||||
LeftAlt = 342,
|
||||
LeftSuper = 343,
|
||||
RightShift = 344,
|
||||
RightControl = 345,
|
||||
RightAlt = 346,
|
||||
RightSuper = 347,
|
||||
Menu = 348,
|
||||
First = Space,
|
||||
Last = Menu,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1707
|
||||
#pragma warning disable CA1712
|
||||
#pragma warning disable CA1008
|
||||
#pragma warning disable CA1027
|
||||
public enum Joystick : int
|
||||
#pragma warning restore CA1027
|
||||
{
|
||||
|
||||
Joystick_1 = FrameworkConstant. JOYSTICK_1,
|
||||
Joystick_2 = FrameworkConstant. JOYSTICK_2,
|
||||
Joystick_3 = FrameworkConstant. JOYSTICK_3,
|
||||
Joystick_4 = FrameworkConstant. JOYSTICK_4,
|
||||
Joystick_5 = FrameworkConstant. JOYSTICK_5,
|
||||
Joystick_6 = FrameworkConstant. JOYSTICK_6,
|
||||
Joystick_7 = FrameworkConstant. JOYSTICK_7,
|
||||
Joystick_8 = FrameworkConstant. JOYSTICK_8,
|
||||
Joystick_9 = FrameworkConstant. JOYSTICK_9,
|
||||
Joystick_10 = FrameworkConstant.JOYSTICK_10,
|
||||
Joystick_11 = FrameworkConstant.JOYSTICK_11,
|
||||
Joystick_12 = FrameworkConstant.JOYSTICK_12,
|
||||
Joystick_13 = FrameworkConstant.JOYSTICK_13,
|
||||
Joystick_14 = FrameworkConstant.JOYSTICK_14,
|
||||
Joystick_15 = FrameworkConstant.JOYSTICK_15,
|
||||
Joystick_16 = FrameworkConstant.JOYSTICK_16,
|
||||
First = Joystick_1,
|
||||
Last = Joystick_16
|
||||
|
||||
}
|
||||
|
||||
[System.Flags]
|
||||
public enum Mouse : int
|
||||
{
|
||||
|
||||
Button1 = 0,
|
||||
Button2 = 1,
|
||||
Button3 = 2,
|
||||
Button4 = 3,
|
||||
Button5 = 4,
|
||||
Button6 = 5,
|
||||
Button7 = 6,
|
||||
Button8 = 7,
|
||||
First = Button1,
|
||||
Last = Button8,
|
||||
Left = Button1,
|
||||
Right = Button2,
|
||||
Middle = Button3
|
||||
|
||||
}
|
||||
|
||||
#pragma warning restore CA1707
|
||||
#pragma warning restore CA1712
|
||||
#pragma warning restore CA7008
|
||||
|
||||
internal enum InputEquipment
|
||||
{
|
||||
|
||||
Keyboard,
|
||||
Mouse,
|
||||
Joystick
|
||||
|
||||
}
|
||||
|
||||
public enum KeyStatus : int
|
||||
{
|
||||
|
||||
RELEASE = 0,
|
||||
PRESS = 1
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="KeyEventAttribute"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class KeyEventAttribute : Attribute
|
||||
{
|
||||
|
||||
internal int _equipment;
|
||||
internal int _keyStat;
|
||||
internal int _keyTarget;
|
||||
|
||||
public KeyEventAttribute(KeyboardKey key, KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)key;
|
||||
_keyStat = (int)status;
|
||||
}
|
||||
|
||||
public KeyEventAttribute(Joystick joystick, KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)joystick;
|
||||
_keyStat = (int)status;
|
||||
}
|
||||
|
||||
public KeyEventAttribute(Mouse mouse, KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)mouse;
|
||||
_keyStat = (int)status;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="KeyEventAttribute"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class KeyEventAttribute : Attribute
|
||||
{
|
||||
|
||||
internal int _equipment;
|
||||
internal int _keyStat;
|
||||
internal int _keyTarget;
|
||||
|
||||
public KeyEventAttribute(KeyboardKey key, KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)key;
|
||||
_keyStat = (int)status;
|
||||
}
|
||||
|
||||
public KeyEventAttribute(Joystick joystick, KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)joystick;
|
||||
_keyStat = (int)status;
|
||||
}
|
||||
|
||||
public KeyEventAttribute(Mouse mouse, KeyStatus status)
|
||||
{
|
||||
_equipment = (int)InputEquipment.Keyboard;
|
||||
_keyTarget = (int)mouse;
|
||||
_keyStat = (int)status;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IClickTrigger"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public interface IClickTrigger
|
||||
{
|
||||
|
||||
public int TargetKeyOrButtonID { get; }
|
||||
|
||||
public KeyStatus TriggeredStatus { get; }
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IClickTrigger"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public interface IClickTrigger
|
||||
{
|
||||
|
||||
public int TargetKeyOrButtonID { get; }
|
||||
|
||||
public KeyStatus TriggeredStatus { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="JoystickTrigger"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public readonly struct JoystickTrigger : IClickTrigger, IEquatable<JoystickTrigger>
|
||||
{
|
||||
|
||||
private readonly Joystick _stick;
|
||||
private readonly KeyStatus _status;
|
||||
|
||||
public JoystickTrigger(Joystick targetKey, KeyStatus status)
|
||||
{
|
||||
this._stick = targetKey;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
public int TargetKeyOrButtonID => (int)_stick;
|
||||
|
||||
public Joystick Stick
|
||||
{
|
||||
get => _stick;
|
||||
}
|
||||
|
||||
public KeyStatus TriggeredStatus => _status;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((int)_stick) + (17 * ((int)_status));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Key {_stick} triggered when {_status}";
|
||||
}
|
||||
|
||||
public static bool operator !=(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public static bool operator ==(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return (left._status == right._status) && (left._stick == right._stick);
|
||||
}
|
||||
|
||||
bool IEquatable<JoystickTrigger>.Equals(JoystickTrigger other)
|
||||
{
|
||||
return other == this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="JoystickTrigger"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public readonly struct JoystickTrigger : IClickTrigger, IEquatable<JoystickTrigger>
|
||||
{
|
||||
|
||||
private readonly Joystick _stick;
|
||||
private readonly KeyStatus _status;
|
||||
|
||||
public JoystickTrigger(Joystick targetKey, KeyStatus status)
|
||||
{
|
||||
this._stick = targetKey;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
public int TargetKeyOrButtonID => (int)_stick;
|
||||
|
||||
public Joystick Stick
|
||||
{
|
||||
get => _stick;
|
||||
}
|
||||
|
||||
public KeyStatus TriggeredStatus => _status;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((int)_stick) + (17 * ((int)_status));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Key {_stick} triggered when {_status}";
|
||||
}
|
||||
|
||||
public static bool operator !=(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public static bool operator ==(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return (left._status == right._status) && (left._stick == right._stick);
|
||||
}
|
||||
|
||||
bool IEquatable<JoystickTrigger>.Equals(JoystickTrigger other)
|
||||
{
|
||||
return other == this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="KeyTrigger"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public readonly struct KeyTrigger : IClickTrigger, IEquatable<KeyTrigger>
|
||||
{
|
||||
|
||||
private readonly KeyboardKey _targetKey;
|
||||
private readonly KeyStatus _triggerStat;
|
||||
|
||||
public KeyTrigger(KeyboardKey targetKey, KeyStatus targetStat)
|
||||
{
|
||||
this._targetKey = targetKey;
|
||||
this._triggerStat = targetStat;
|
||||
}
|
||||
|
||||
public int TargetKeyOrButtonID => (int)_targetKey;
|
||||
|
||||
public KeyStatus TriggeredStatus => _triggerStat;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((int)_targetKey) + (17 * ((int)_triggerStat));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Key {_targetKey} triggered when {_triggerStat}";
|
||||
}
|
||||
|
||||
public static bool operator !=(KeyTrigger left, KeyTrigger right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public static bool operator ==(KeyTrigger left, KeyTrigger right)
|
||||
{
|
||||
return (left._triggerStat == right._triggerStat) && (left._targetKey == right._targetKey);
|
||||
}
|
||||
|
||||
bool IEquatable<KeyTrigger>.Equals(KeyTrigger other)
|
||||
{
|
||||
return other == this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="KeyTrigger"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public readonly struct KeyTrigger : IClickTrigger, IEquatable<KeyTrigger>
|
||||
{
|
||||
|
||||
private readonly KeyboardKey _targetKey;
|
||||
private readonly KeyStatus _triggerStat;
|
||||
|
||||
public KeyTrigger(KeyboardKey targetKey, KeyStatus targetStat)
|
||||
{
|
||||
this._targetKey = targetKey;
|
||||
this._triggerStat = targetStat;
|
||||
}
|
||||
|
||||
public int TargetKeyOrButtonID => (int)_targetKey;
|
||||
|
||||
public KeyStatus TriggeredStatus => _triggerStat;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((int)_targetKey) + (17 * ((int)_triggerStat));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Key {_targetKey} triggered when {_triggerStat}";
|
||||
}
|
||||
|
||||
public static bool operator !=(KeyTrigger left, KeyTrigger right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public static bool operator ==(KeyTrigger left, KeyTrigger right)
|
||||
{
|
||||
return (left._triggerStat == right._triggerStat) && (left._targetKey == right._targetKey);
|
||||
}
|
||||
|
||||
bool IEquatable<KeyTrigger>.Equals(KeyTrigger other)
|
||||
{
|
||||
return other == this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MouseTrigger"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.SymbolStore;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public readonly struct MouseTrigger : IClickTrigger, IEquatable<MouseTrigger>
|
||||
{
|
||||
|
||||
private readonly KeyStatus _status;
|
||||
private readonly Mouse _mouse;
|
||||
|
||||
public MouseTrigger(Mouse mouse, KeyStatus status)
|
||||
{
|
||||
_mouse = mouse;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
public int TargetKeyOrButtonID => (int)_mouse;
|
||||
|
||||
public KeyStatus TriggeredStatus => _status;
|
||||
|
||||
public bool Equals(MouseTrigger other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
|
||||
public static bool operator !=(MouseTrigger left, MouseTrigger right)
|
||||
{
|
||||
return left._mouse != right._mouse || left._status != right._status;
|
||||
}
|
||||
|
||||
public static bool operator ==(MouseTrigger left, MouseTrigger right)
|
||||
{
|
||||
return left._mouse == right._mouse && left._status == right._status;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MouseTrigger"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.SymbolStore;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public readonly struct MouseTrigger : IClickTrigger, IEquatable<MouseTrigger>
|
||||
{
|
||||
|
||||
private readonly KeyStatus _status;
|
||||
private readonly Mouse _mouse;
|
||||
|
||||
public MouseTrigger(Mouse mouse, KeyStatus status)
|
||||
{
|
||||
_mouse = mouse;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
public int TargetKeyOrButtonID => (int)_mouse;
|
||||
|
||||
public KeyStatus TriggeredStatus => _status;
|
||||
|
||||
public bool Equals(MouseTrigger other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
|
||||
public static bool operator !=(MouseTrigger left, MouseTrigger right)
|
||||
{
|
||||
return left._mouse != right._mouse || left._status != right._status;
|
||||
}
|
||||
|
||||
public static bool operator ==(MouseTrigger left, MouseTrigger right)
|
||||
{
|
||||
return left._mouse == right._mouse && left._status == right._status;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TriggetFactory"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public static class TriggetBuilder
|
||||
{
|
||||
|
||||
private const int JoystickMax = (int)Joystick.Last + 1;
|
||||
private const int JoystickMin = (int)Joystick.First - 1;
|
||||
private const int KeyboardMax = (int)KeyboardKey.Last + 1;
|
||||
private const int KeyboardMin = (int)KeyboardKey.First - 1;
|
||||
private const int MouseMax = (int)Mouse.Last + 1;
|
||||
private const int MouseMin = (int)Mouse.First - 1;
|
||||
|
||||
private static KeyTrigger keyboardtemp;
|
||||
private static MouseTrigger mousetemp;
|
||||
|
||||
public static JoystickTrigger BuildJoystickClickTrigger(int keyCode, KeyStatus status)
|
||||
{
|
||||
if (keyCode > MouseMin && keyCode < MouseMax) {
|
||||
return new JoystickTrigger((Joystick)keyCode, status);
|
||||
}
|
||||
throw new InvalidOperationException("Known key code or key is not on joystick.");
|
||||
}
|
||||
|
||||
public static KeyTrigger BuildKeyboardClickTrigger(int keyCode, KeyStatus status)
|
||||
{
|
||||
if (keyCode > KeyboardMin && keyCode < KeyboardMax) {
|
||||
return new KeyTrigger((KeyboardKey)keyCode, status);
|
||||
}
|
||||
throw new InvalidOperationException("Known key code or kay is not on keyboard.");
|
||||
}
|
||||
|
||||
public static MouseTrigger BuildMouseClickTrigger(int keyCode, KeyStatus status)
|
||||
{
|
||||
if (keyCode >= MouseMin && keyCode <= MouseMax) {
|
||||
return new MouseTrigger((Mouse)keyCode, status);
|
||||
}
|
||||
throw new InvalidOperationException("Known key code or key is not on mouse.");
|
||||
}
|
||||
|
||||
public static IClickTrigger BuildTrigger(int keyCode, KeyStatus status)
|
||||
{
|
||||
if (keyCode > KeyboardMin && keyCode < KeyboardMax) {
|
||||
return new KeyTrigger((KeyboardKey)keyCode, status);
|
||||
}
|
||||
if (keyCode > JoystickMin && keyCode < JoystickMax) {
|
||||
return new JoystickTrigger((Joystick)keyCode, status);
|
||||
}
|
||||
if (keyCode >= MouseMin && keyCode <= MouseMax) {
|
||||
return new MouseTrigger((Mouse)keyCode, status);
|
||||
}
|
||||
throw new InvalidOperationException("Known key code.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TriggetFactory"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public static class TriggetBuilder
|
||||
{
|
||||
|
||||
private const int JoystickMax = (int)Joystick.Last + 1;
|
||||
private const int JoystickMin = (int)Joystick.First - 1;
|
||||
private const int KeyboardMax = (int)KeyboardKey.Last + 1;
|
||||
private const int KeyboardMin = (int)KeyboardKey.First - 1;
|
||||
private const int MouseMax = (int)Mouse.Last + 1;
|
||||
private const int MouseMin = (int)Mouse.First - 1;
|
||||
|
||||
private static KeyTrigger keyboardtemp;
|
||||
private static MouseTrigger mousetemp;
|
||||
|
||||
public static JoystickTrigger BuildJoystickClickTrigger(int keyCode, KeyStatus status)
|
||||
{
|
||||
if (keyCode > MouseMin && keyCode < MouseMax) {
|
||||
return new JoystickTrigger((Joystick)keyCode, status);
|
||||
}
|
||||
throw new InvalidOperationException("Known key code or key is not on joystick.");
|
||||
}
|
||||
|
||||
public static KeyTrigger BuildKeyboardClickTrigger(int keyCode, KeyStatus status)
|
||||
{
|
||||
if (keyCode > KeyboardMin && keyCode < KeyboardMax) {
|
||||
return new KeyTrigger((KeyboardKey)keyCode, status);
|
||||
}
|
||||
throw new InvalidOperationException("Known key code or kay is not on keyboard.");
|
||||
}
|
||||
|
||||
public static MouseTrigger BuildMouseClickTrigger(int keyCode, KeyStatus status)
|
||||
{
|
||||
if (keyCode >= MouseMin && keyCode <= MouseMax) {
|
||||
return new MouseTrigger((Mouse)keyCode, status);
|
||||
}
|
||||
throw new InvalidOperationException("Known key code or key is not on mouse.");
|
||||
}
|
||||
|
||||
public static IClickTrigger BuildTrigger(int keyCode, KeyStatus status)
|
||||
{
|
||||
if (keyCode > KeyboardMin && keyCode < KeyboardMax) {
|
||||
return new KeyTrigger((KeyboardKey)keyCode, status);
|
||||
}
|
||||
if (keyCode > JoystickMin && keyCode < JoystickMax) {
|
||||
return new JoystickTrigger((Joystick)keyCode, status);
|
||||
}
|
||||
if (keyCode >= MouseMin && keyCode <= MouseMax) {
|
||||
return new MouseTrigger((Mouse)keyCode, status);
|
||||
}
|
||||
throw new InvalidOperationException("Known key code.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+124
-124
@@ -1,125 +1,125 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Counter"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class Counter<T> where T : unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
internal dynamic _value;
|
||||
internal readonly T _defaultDecrement;
|
||||
|
||||
internal readonly T _defaultIncrement;
|
||||
internal readonly T _defaultValue;
|
||||
|
||||
public Counter(
|
||||
T defaultValue,
|
||||
T defaultIncrement,
|
||||
T defaultDecrement
|
||||
)
|
||||
{
|
||||
_value = defaultValue;
|
||||
_defaultValue = defaultValue;
|
||||
_defaultIncrement = defaultIncrement;
|
||||
_defaultDecrement = defaultDecrement;
|
||||
}
|
||||
|
||||
public T DecrementSpan => _defaultDecrement;
|
||||
|
||||
public T IncrementSpan => _defaultIncrement;
|
||||
|
||||
public T CurrentSpan => _value - _defaultValue;
|
||||
|
||||
public T Value
|
||||
{
|
||||
get => _value;
|
||||
set => _value = value;
|
||||
}
|
||||
|
||||
public void Add(
|
||||
T value
|
||||
)
|
||||
{
|
||||
_value += value;
|
||||
}
|
||||
|
||||
public void QuickAdd()
|
||||
{
|
||||
_value += _defaultIncrement;
|
||||
}
|
||||
|
||||
public void QuickSub()
|
||||
{
|
||||
_value -= _defaultDecrement;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_value = _defaultValue;
|
||||
}
|
||||
|
||||
public void Sub(
|
||||
T value
|
||||
)
|
||||
{
|
||||
_value -= value;
|
||||
}
|
||||
|
||||
public override string ToString() => Value.ToString();
|
||||
|
||||
public static Counter<T> operator --(
|
||||
Counter<T> counter
|
||||
)
|
||||
{
|
||||
counter?.QuickSub();
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static Counter<T> operator ++(
|
||||
Counter<T> counter
|
||||
)
|
||||
{
|
||||
counter?.QuickAdd();
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static implicit operator T(
|
||||
Counter<T> counter
|
||||
)
|
||||
{
|
||||
return counter switch
|
||||
{
|
||||
null => T.Zero,
|
||||
_ => counter.Value
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Counter"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class Counter<T> where T : unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
internal dynamic _value;
|
||||
internal readonly T _defaultDecrement;
|
||||
|
||||
internal readonly T _defaultIncrement;
|
||||
internal readonly T _defaultValue;
|
||||
|
||||
public Counter(
|
||||
T defaultValue,
|
||||
T defaultIncrement,
|
||||
T defaultDecrement
|
||||
)
|
||||
{
|
||||
_value = defaultValue;
|
||||
_defaultValue = defaultValue;
|
||||
_defaultIncrement = defaultIncrement;
|
||||
_defaultDecrement = defaultDecrement;
|
||||
}
|
||||
|
||||
public T DecrementSpan => _defaultDecrement;
|
||||
|
||||
public T IncrementSpan => _defaultIncrement;
|
||||
|
||||
public T CurrentSpan => _value - _defaultValue;
|
||||
|
||||
public T Value
|
||||
{
|
||||
get => _value;
|
||||
set => _value = value;
|
||||
}
|
||||
|
||||
public void Add(
|
||||
T value
|
||||
)
|
||||
{
|
||||
_value += value;
|
||||
}
|
||||
|
||||
public void QuickAdd()
|
||||
{
|
||||
_value += _defaultIncrement;
|
||||
}
|
||||
|
||||
public void QuickSub()
|
||||
{
|
||||
_value -= _defaultDecrement;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_value = _defaultValue;
|
||||
}
|
||||
|
||||
public void Sub(
|
||||
T value
|
||||
)
|
||||
{
|
||||
_value -= value;
|
||||
}
|
||||
|
||||
public override string ToString() => Value.ToString();
|
||||
|
||||
public static Counter<T> operator --(
|
||||
Counter<T> counter
|
||||
)
|
||||
{
|
||||
counter?.QuickSub();
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static Counter<T> operator ++(
|
||||
Counter<T> counter
|
||||
)
|
||||
{
|
||||
counter?.QuickAdd();
|
||||
return counter;
|
||||
}
|
||||
|
||||
public static implicit operator T(
|
||||
Counter<T> counter
|
||||
)
|
||||
{
|
||||
return counter switch
|
||||
{
|
||||
null => T.Zero,
|
||||
_ => counter.Value
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,39 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="root"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class World { }//------------------ end of class ---------------------
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="root"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class World { }//------------------ end of class ---------------------
|
||||
}
|
||||
|
||||
@@ -1,144 +1,144 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RandomGenerator"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
public unsafe class RandomGenerator
|
||||
{
|
||||
|
||||
private byte[] currentKey;
|
||||
private readonly byte[] originKey;
|
||||
|
||||
public RandomGenerator() : this(DateTime.UtcNow.ToBinary()) { }
|
||||
|
||||
public RandomGenerator(object source)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
XmlSerializer s = new(source.GetType());
|
||||
using (StringWriter sw = new())
|
||||
{
|
||||
s.Serialize(sw, source);
|
||||
string data = sw.ToString();
|
||||
originKey = Encoding.Unicode.GetBytes(data);
|
||||
}
|
||||
currentKey = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
];
|
||||
fixed (byte* o = originKey, c = currentKey) {
|
||||
*(int*)c = UnsafeCompute.CityHashSimplify((char*)o, 0, originKey.Length / 2);
|
||||
}
|
||||
TotalGeneratedRandom = 0;
|
||||
}
|
||||
|
||||
public int TotalGeneratedRandom
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private set;
|
||||
}
|
||||
|
||||
public unsafe int GenRandomInt()
|
||||
{
|
||||
uint source = PrivateRand();
|
||||
TotalGeneratedRandom++;
|
||||
M64 m = new M64();
|
||||
m.Member<uint>(0) = source;
|
||||
m.Member<uint>(1) = source;
|
||||
return (m << (TotalGeneratedRandom % 32)).Member<int>(1);
|
||||
}
|
||||
|
||||
public byte GenRandomInt8()
|
||||
{
|
||||
TotalGeneratedRandom++;
|
||||
if (TotalGeneratedRandom % 4 == 0) {
|
||||
PrivateRand();
|
||||
}
|
||||
return currentKey[TotalGeneratedRandom % 4];
|
||||
}
|
||||
|
||||
public float GenRandomSingle()
|
||||
{
|
||||
TotalGeneratedRandom++;
|
||||
|
||||
while (true)
|
||||
{
|
||||
uint
|
||||
temp0 = PrivateRand(),
|
||||
temp1 = PrivateRand();
|
||||
|
||||
if (temp0 * temp1 != 0)
|
||||
{
|
||||
float ret = temp0 % temp1 * 1.0f / temp1;
|
||||
if (ret < 0.335f)
|
||||
{
|
||||
ret = ret * ((ret * (-0.7811934f)) + 1.4489113f);
|
||||
} else
|
||||
{
|
||||
ret = (ret * ((ret * (-0.1158368f)) + 1.0580600f)) + 0.0590584f;
|
||||
}
|
||||
if (ret > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
currentKey = originKey;
|
||||
TotalGeneratedRandom = 0;
|
||||
}
|
||||
|
||||
private unsafe uint PrivateRand()
|
||||
{
|
||||
uint ret;
|
||||
fixed (byte* bptr = currentKey)
|
||||
{
|
||||
*(int*)bptr = UnsafeCompute.CityHashSimplify((char*)bptr, currentKey.Length / 2);
|
||||
ret = *(uint*)bptr;
|
||||
}
|
||||
|
||||
// Console.WriteLine(ret.ToString(16));
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RandomGenerator"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
public unsafe class RandomGenerator
|
||||
{
|
||||
|
||||
private byte[] currentKey;
|
||||
private readonly byte[] originKey;
|
||||
|
||||
public RandomGenerator() : this(DateTime.UtcNow.ToBinary()) { }
|
||||
|
||||
public RandomGenerator(object source)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
XmlSerializer s = new(source.GetType());
|
||||
using (StringWriter sw = new())
|
||||
{
|
||||
s.Serialize(sw, source);
|
||||
string data = sw.ToString();
|
||||
originKey = Encoding.Unicode.GetBytes(data);
|
||||
}
|
||||
currentKey = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
];
|
||||
fixed (byte* o = originKey, c = currentKey) {
|
||||
*(int*)c = UnsafeCompute.CityHashSimplify((char*)o, 0, originKey.Length / 2);
|
||||
}
|
||||
TotalGeneratedRandom = 0;
|
||||
}
|
||||
|
||||
public int TotalGeneratedRandom
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private set;
|
||||
}
|
||||
|
||||
public unsafe int GenRandomInt()
|
||||
{
|
||||
uint source = PrivateRand();
|
||||
TotalGeneratedRandom++;
|
||||
M64 m = new M64();
|
||||
m.Member<uint>(0) = source;
|
||||
m.Member<uint>(1) = source;
|
||||
return (m << (TotalGeneratedRandom % 32)).Member<int>(1);
|
||||
}
|
||||
|
||||
public byte GenRandomInt8()
|
||||
{
|
||||
TotalGeneratedRandom++;
|
||||
if (TotalGeneratedRandom % 4 == 0) {
|
||||
PrivateRand();
|
||||
}
|
||||
return currentKey[TotalGeneratedRandom % 4];
|
||||
}
|
||||
|
||||
public float GenRandomSingle()
|
||||
{
|
||||
TotalGeneratedRandom++;
|
||||
|
||||
while (true)
|
||||
{
|
||||
uint
|
||||
temp0 = PrivateRand(),
|
||||
temp1 = PrivateRand();
|
||||
|
||||
if (temp0 * temp1 != 0)
|
||||
{
|
||||
float ret = temp0 % temp1 * 1.0f / temp1;
|
||||
if (ret < 0.335f)
|
||||
{
|
||||
ret = ret * ((ret * (-0.7811934f)) + 1.4489113f);
|
||||
} else
|
||||
{
|
||||
ret = (ret * ((ret * (-0.1158368f)) + 1.0580600f)) + 0.0590584f;
|
||||
}
|
||||
if (ret > 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
currentKey = originKey;
|
||||
TotalGeneratedRandom = 0;
|
||||
}
|
||||
|
||||
private unsafe uint PrivateRand()
|
||||
{
|
||||
uint ret;
|
||||
fixed (byte* bptr = currentKey)
|
||||
{
|
||||
*(int*)bptr = UnsafeCompute.CityHashSimplify((char*)bptr, currentKey.Length / 2);
|
||||
ret = *(uint*)bptr;
|
||||
}
|
||||
|
||||
// Console.WriteLine(ret.ToString(16));
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Area"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal.FileIO;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// An independent storage area, used as the only folder type in root folder. Contains several
|
||||
/// <see cref="SSD" /> files reference as virtual disc. Data is actually stored in <see
|
||||
/// cref="SSD" />s in certain RAID mode.
|
||||
/// </summary>
|
||||
public partial class Area { }
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Area"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal.FileIO;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// An independent storage area, used as the only folder type in root folder. Contains several
|
||||
/// <see cref="SSD" /> files reference as virtual disc. Data is actually stored in <see
|
||||
/// cref="SSD" />s in certain RAID mode.
|
||||
/// </summary>
|
||||
public partial class Area { }
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="DataHead"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
public struct SSDSegmentHead
|
||||
{
|
||||
|
||||
[FieldOffset(12)] internal byte size;
|
||||
|
||||
[FieldOffset(0)] internal M128 data;
|
||||
[FieldOffset(13)] public byte selfDefine_1;
|
||||
[FieldOffset(14)] public byte selfDefine_2;
|
||||
[FieldOffset(15)] public byte selfDefine_3;
|
||||
|
||||
[FieldOffset(0)] public int globalID;
|
||||
[FieldOffset(4)] public int nextID;
|
||||
[FieldOffset(8)] public int previousHash;
|
||||
|
||||
public int Size
|
||||
{
|
||||
get => ((int)size) + 1;
|
||||
set
|
||||
{
|
||||
if ((value > 256) || (value < 0)) {
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
size = (byte)(value - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
byte[] ret = new byte[16];
|
||||
fixed (M128* vptr = &data)
|
||||
{
|
||||
byte* bptr = (byte*)vptr;
|
||||
for (int i = 0; i < 15; i++) {
|
||||
ret[i] = *bptr;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="DataHead"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
public struct SSDSegmentHead
|
||||
{
|
||||
|
||||
[FieldOffset(12)] internal byte size;
|
||||
|
||||
[FieldOffset(0)] internal M128 data;
|
||||
[FieldOffset(13)] public byte selfDefine_1;
|
||||
[FieldOffset(14)] public byte selfDefine_2;
|
||||
[FieldOffset(15)] public byte selfDefine_3;
|
||||
|
||||
[FieldOffset(0)] public int globalID;
|
||||
[FieldOffset(4)] public int nextID;
|
||||
[FieldOffset(8)] public int previousHash;
|
||||
|
||||
public int Size
|
||||
{
|
||||
get => ((int)size) + 1;
|
||||
set
|
||||
{
|
||||
if ((value > 256) || (value < 0)) {
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
size = (byte)(value - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
byte[] ret = new byte[16];
|
||||
fixed (M128* vptr = &data)
|
||||
{
|
||||
byte* bptr = (byte*)vptr;
|
||||
for (int i = 0; i < 15; i++) {
|
||||
ret[i] = *bptr;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,186 +1,186 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="DataSegment"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.Internal.Intrinsic;
|
||||
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = World.ssdSegmentLength * 16)]
|
||||
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
|
||||
{
|
||||
|
||||
[FieldOffset(16)] public fixed byte Data[16 * (World.ssdSegmentLength - 1)];
|
||||
[FieldOffset(12)] public int DataHash;
|
||||
[FieldOffset(8)] public int PreviousHash;
|
||||
[FieldOffset(0 * 16)] public SSDSegmentHead Head;
|
||||
|
||||
public SSDSegment(int previousHash)
|
||||
{
|
||||
this.PreviousHash = previousHash;
|
||||
}
|
||||
|
||||
public byte this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index > (16 * (World.ssdSegmentLength - 1)) - 1) {
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return Data[index];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (index > (16 * (World.ssdSegmentLength - 1)) - 1) {
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
Data[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int ID
|
||||
{
|
||||
get { return Head.globalID; }
|
||||
set { Head.globalID = value; }
|
||||
}
|
||||
|
||||
public short Size => Head.size;
|
||||
|
||||
public void FillRandomBytes(int begin)
|
||||
{
|
||||
if (begin > 255) {
|
||||
return;
|
||||
}
|
||||
for (int i = begin; i < 255; i++) {
|
||||
Data[i] = Scalar.Random<byte>();
|
||||
}
|
||||
}
|
||||
|
||||
public static SSDSegment FromStream(byte[] stream)
|
||||
{
|
||||
if (stream.Length != 16 * World.ssdSegmentLength) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
SSDSegment ret = new SSDSegment();
|
||||
fixed (byte* bptr = stream)
|
||||
{
|
||||
ret.Head.data = *(M128*)bptr;
|
||||
for (int i = 1; i < World.ssdSegmentLength; i++) {
|
||||
ret.WriteData<M128>(i - 1, *(M128*)(bptr + (16 * i)));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
byte[] ret = new byte[16 * World.ssdSegmentLength];
|
||||
fixed (M128* mptr = &Head.data)
|
||||
{
|
||||
fixed (byte* aptr = ret)
|
||||
{
|
||||
Vector4* vsptr = (Vector4*)mptr;
|
||||
Vector4* vtptr = (Vector4*)aptr;
|
||||
for (int i = 0; i < 18; i++) {
|
||||
*(vtptr + i) = *(vsptr + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int GetDataHash()
|
||||
{
|
||||
Vector4 v = Vector4.One;
|
||||
fixed (M128* mptr = &Head.data)
|
||||
{
|
||||
Vector4* vptr = (Vector4*)mptr;
|
||||
for (int i = 0; i < World.ssdSegmentLength - 1; i += 1) {
|
||||
v += (*vptr) * 31;
|
||||
}
|
||||
}
|
||||
M128 m = new M128(v);
|
||||
DataHash = m.Vec.GetHashCode();
|
||||
return DataHash;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int ret = 17;
|
||||
fixed (M128* mptr = &Head.data)
|
||||
{
|
||||
Vector4* vptr = (Vector4*)mptr;
|
||||
for (int i = 0; i < World.ssdSegmentLength; i++) {
|
||||
ret = (ret + (*vptr).GetHashCode()) * 31;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public unsafe T ReadData<T>(int index) where T: unmanaged
|
||||
{
|
||||
fixed (byte* bptr = Data)
|
||||
{
|
||||
T* tptr = (T*)bptr;
|
||||
return *(tptr + index);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void WriteData<T>(int index, T value) where T: unmanaged
|
||||
{
|
||||
fixed (byte* bptr = Data)
|
||||
{
|
||||
T* tptr = (T*)bptr;
|
||||
*(tptr + index) = value;
|
||||
}
|
||||
}
|
||||
|
||||
int IComparable<int>.CompareTo(int other)
|
||||
{
|
||||
return ID.CompareTo(other);
|
||||
}
|
||||
|
||||
int IComparable<SSDSegment>.CompareTo(SSDSegment other)
|
||||
{
|
||||
return ID.CompareTo(other.ID);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="DataSegment"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.Internal.Intrinsic;
|
||||
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = World.ssdSegmentLength * 16)]
|
||||
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
|
||||
{
|
||||
|
||||
[FieldOffset(16)] public fixed byte Data[16 * (World.ssdSegmentLength - 1)];
|
||||
[FieldOffset(12)] public int DataHash;
|
||||
[FieldOffset(8)] public int PreviousHash;
|
||||
[FieldOffset(0 * 16)] public SSDSegmentHead Head;
|
||||
|
||||
public SSDSegment(int previousHash)
|
||||
{
|
||||
this.PreviousHash = previousHash;
|
||||
}
|
||||
|
||||
public byte this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index > (16 * (World.ssdSegmentLength - 1)) - 1) {
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return Data[index];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (index > (16 * (World.ssdSegmentLength - 1)) - 1) {
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
Data[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int ID
|
||||
{
|
||||
get { return Head.globalID; }
|
||||
set { Head.globalID = value; }
|
||||
}
|
||||
|
||||
public short Size => Head.size;
|
||||
|
||||
public void FillRandomBytes(int begin)
|
||||
{
|
||||
if (begin > 255) {
|
||||
return;
|
||||
}
|
||||
for (int i = begin; i < 255; i++) {
|
||||
Data[i] = Scalar.Random<byte>();
|
||||
}
|
||||
}
|
||||
|
||||
public static SSDSegment FromStream(byte[] stream)
|
||||
{
|
||||
if (stream.Length != 16 * World.ssdSegmentLength) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
SSDSegment ret = new SSDSegment();
|
||||
fixed (byte* bptr = stream)
|
||||
{
|
||||
ret.Head.data = *(M128*)bptr;
|
||||
for (int i = 1; i < World.ssdSegmentLength; i++) {
|
||||
ret.WriteData<M128>(i - 1, *(M128*)(bptr + (16 * i)));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
byte[] ret = new byte[16 * World.ssdSegmentLength];
|
||||
fixed (M128* mptr = &Head.data)
|
||||
{
|
||||
fixed (byte* aptr = ret)
|
||||
{
|
||||
Vector4* vsptr = (Vector4*)mptr;
|
||||
Vector4* vtptr = (Vector4*)aptr;
|
||||
for (int i = 0; i < 18; i++) {
|
||||
*(vtptr + i) = *(vsptr + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int GetDataHash()
|
||||
{
|
||||
Vector4 v = Vector4.One;
|
||||
fixed (M128* mptr = &Head.data)
|
||||
{
|
||||
Vector4* vptr = (Vector4*)mptr;
|
||||
for (int i = 0; i < World.ssdSegmentLength - 1; i += 1) {
|
||||
v += (*vptr) * 31;
|
||||
}
|
||||
}
|
||||
M128 m = new M128(v);
|
||||
DataHash = m.Vec.GetHashCode();
|
||||
return DataHash;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int ret = 17;
|
||||
fixed (M128* mptr = &Head.data)
|
||||
{
|
||||
Vector4* vptr = (Vector4*)mptr;
|
||||
for (int i = 0; i < World.ssdSegmentLength; i++) {
|
||||
ret = (ret + (*vptr).GetHashCode()) * 31;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public unsafe T ReadData<T>(int index) where T: unmanaged
|
||||
{
|
||||
fixed (byte* bptr = Data)
|
||||
{
|
||||
T* tptr = (T*)bptr;
|
||||
return *(tptr + index);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void WriteData<T>(int index, T value) where T: unmanaged
|
||||
{
|
||||
fixed (byte* bptr = Data)
|
||||
{
|
||||
T* tptr = (T*)bptr;
|
||||
*(tptr + index) = value;
|
||||
}
|
||||
}
|
||||
|
||||
int IComparable<int>.CompareTo(int other)
|
||||
{
|
||||
return ID.CompareTo(other);
|
||||
}
|
||||
|
||||
int IComparable<SSDSegment>.CompareTo(SSDSegment other)
|
||||
{
|
||||
return ID.CompareTo(other.ID);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SSD"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal.FileIO;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
public partial class SSD
|
||||
{
|
||||
|
||||
private Dictionary<string, SSDraw> fileList;
|
||||
|
||||
private FileStream file;
|
||||
private SSDrawHead head;
|
||||
|
||||
public SSD()
|
||||
{
|
||||
fileList = new Dictionary<string, SSDraw>();
|
||||
}
|
||||
|
||||
public SSD(FileStream fileStream)
|
||||
{
|
||||
fileList = new Dictionary<string, SSDraw>();
|
||||
file = fileStream;
|
||||
}
|
||||
|
||||
public static SSD FromFile(string fileRoute)
|
||||
{
|
||||
return new SSD(new FileStream(fileRoute, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SSD"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal.FileIO;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
public partial class SSD
|
||||
{
|
||||
|
||||
private Dictionary<string, SSDraw> fileList;
|
||||
|
||||
private FileStream file;
|
||||
private SSDrawHead head;
|
||||
|
||||
public SSD()
|
||||
{
|
||||
fileList = new Dictionary<string, SSDraw>();
|
||||
}
|
||||
|
||||
public SSD(FileStream fileStream)
|
||||
{
|
||||
fileList = new Dictionary<string, SSDraw>();
|
||||
file = fileStream;
|
||||
}
|
||||
|
||||
public static SSD FromFile(string fileRoute)
|
||||
{
|
||||
return new SSD(new FileStream(fileRoute, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SSDVirtualFolder"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal.FileIO;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
public class SSDFolder : ISSDSerializable
|
||||
{
|
||||
|
||||
internal Dictionary<string, SSDFolder> folders;
|
||||
internal int _folderID;
|
||||
internal string _name;
|
||||
|
||||
internal SSDFolder()
|
||||
{
|
||||
folders = new Dictionary<string, SSDFolder>();
|
||||
}
|
||||
|
||||
internal SSDFolder(string name)
|
||||
{
|
||||
if (name == "root") {
|
||||
throw new ArgumentException(
|
||||
"Name cannot be root," + "it is preserved for root file indexer.");
|
||||
}
|
||||
if (name == "default") {
|
||||
throw new ArgumentException(
|
||||
"Name cannot be default," + "it is preserved for default file id provider.");
|
||||
}
|
||||
_name = name;
|
||||
folders = new Dictionary<string, SSDFolder>();
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// TODO TOUGH TO Get Bytes from virtual folders
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SSDVirtualFolder"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal.FileIO;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
public class SSDFolder : ISSDSerializable
|
||||
{
|
||||
|
||||
internal Dictionary<string, SSDFolder> folders;
|
||||
internal int _folderID;
|
||||
internal string _name;
|
||||
|
||||
internal SSDFolder()
|
||||
{
|
||||
folders = new Dictionary<string, SSDFolder>();
|
||||
}
|
||||
|
||||
internal SSDFolder(string name)
|
||||
{
|
||||
if (name == "root") {
|
||||
throw new ArgumentException(
|
||||
"Name cannot be root," + "it is preserved for root file indexer.");
|
||||
}
|
||||
if (name == "default") {
|
||||
throw new ArgumentException(
|
||||
"Name cannot be default," + "it is preserved for default file id provider.");
|
||||
}
|
||||
_name = name;
|
||||
folders = new Dictionary<string, SSDFolder>();
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// TODO TOUGH TO Get Bytes from virtual folders
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SSDraw"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.ShaderEdit;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Internal.FileIO
|
||||
{
|
||||
public class SSDraw
|
||||
{
|
||||
|
||||
private byte[] data;
|
||||
|
||||
public SSDraw(string name, Stream streamSource)
|
||||
{
|
||||
if ((streamSource == null) || (streamSource.Length == 0)) {
|
||||
throw new ArgumentNullException(nameof(streamSource));
|
||||
}
|
||||
Name = name;
|
||||
data = new byte[streamSource.Length];
|
||||
streamSource.Read(data.AsSpan());
|
||||
}
|
||||
|
||||
public SSDrawHead Head { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 32 * 16)]
|
||||
public unsafe struct SSDrawHead { }
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SSDraw"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.ShaderEdit;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp.Internal.FileIO
|
||||
{
|
||||
public class SSDraw
|
||||
{
|
||||
|
||||
private byte[] data;
|
||||
|
||||
public SSDraw(string name, Stream streamSource)
|
||||
{
|
||||
if ((streamSource == null) || (streamSource.Length == 0)) {
|
||||
throw new ArgumentNullException(nameof(streamSource));
|
||||
}
|
||||
Name = name;
|
||||
data = new byte[streamSource.Length];
|
||||
streamSource.Read(data.AsSpan());
|
||||
}
|
||||
|
||||
public SSDrawHead Head { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 32 * 16)]
|
||||
public unsafe struct SSDrawHead { }
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Define"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// A class contains a sets of methods to serialize several types
|
||||
/// </summary>
|
||||
public static partial class Serializer { }
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Define"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// A class contains a sets of methods to serialize several types
|
||||
/// </summary>
|
||||
public static partial class Serializer { }
|
||||
}
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ISSDSerializable"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
public interface ISSDSerializable
|
||||
{
|
||||
|
||||
public SerializableTypeCode SSDTypeCode { get; }
|
||||
|
||||
public byte[] GetBytes();
|
||||
|
||||
internal void FromBytes(byte[] stream);
|
||||
|
||||
}
|
||||
|
||||
public enum SerializableTypeCode
|
||||
{
|
||||
|
||||
Unknown = 0,
|
||||
IndexTable = 1,
|
||||
PixelImage = 2,
|
||||
VectorImage = 3,
|
||||
Audio = 4,
|
||||
Shader = 5,
|
||||
Text = 6,
|
||||
RawData = 7,
|
||||
VirtualFolder = int.MaxValue,
|
||||
|
||||
}
|
||||
|
||||
public static partial class Serializer
|
||||
{
|
||||
|
||||
public static T Deserialize<T>(byte[] stream) where T: ISSDSerializable
|
||||
{
|
||||
T serializableObject = Activator.CreateInstance<T>();
|
||||
serializableObject.FromBytes(stream);
|
||||
return serializableObject;
|
||||
}
|
||||
|
||||
public static string GetNameTail(SerializableTypeCode typeCode)
|
||||
{
|
||||
switch (typeCode)
|
||||
{
|
||||
case SerializableTypeCode.IndexTable:
|
||||
return "_idt";
|
||||
case SerializableTypeCode.PixelImage:
|
||||
return "_pim";
|
||||
case SerializableTypeCode.VectorImage:
|
||||
return "_vim";
|
||||
case SerializableTypeCode.Audio:
|
||||
return "_wav";
|
||||
case SerializableTypeCode.Shader:
|
||||
return "_gls";
|
||||
case SerializableTypeCode.Text:
|
||||
return "_txt";
|
||||
case SerializableTypeCode.RawData:
|
||||
return "_raw";
|
||||
case SerializableTypeCode.VirtualFolder:
|
||||
return "_fod";
|
||||
default:
|
||||
throw new ArgumentException("Unknown file type");
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] Serialize(ISSDSerializable serializableObject)
|
||||
{
|
||||
return serializableObject.GetBytes();
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ISSDSerializable"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
public interface ISSDSerializable
|
||||
{
|
||||
|
||||
public SerializableTypeCode SSDTypeCode { get; }
|
||||
|
||||
public byte[] GetBytes();
|
||||
|
||||
internal void FromBytes(byte[] stream);
|
||||
|
||||
}
|
||||
|
||||
public enum SerializableTypeCode
|
||||
{
|
||||
|
||||
Unknown = 0,
|
||||
IndexTable = 1,
|
||||
PixelImage = 2,
|
||||
VectorImage = 3,
|
||||
Audio = 4,
|
||||
Shader = 5,
|
||||
Text = 6,
|
||||
RawData = 7,
|
||||
VirtualFolder = int.MaxValue,
|
||||
|
||||
}
|
||||
|
||||
public static partial class Serializer
|
||||
{
|
||||
|
||||
public static T Deserialize<T>(byte[] stream) where T: ISSDSerializable
|
||||
{
|
||||
T serializableObject = Activator.CreateInstance<T>();
|
||||
serializableObject.FromBytes(stream);
|
||||
return serializableObject;
|
||||
}
|
||||
|
||||
public static string GetNameTail(SerializableTypeCode typeCode)
|
||||
{
|
||||
switch (typeCode)
|
||||
{
|
||||
case SerializableTypeCode.IndexTable:
|
||||
return "_idt";
|
||||
case SerializableTypeCode.PixelImage:
|
||||
return "_pim";
|
||||
case SerializableTypeCode.VectorImage:
|
||||
return "_vim";
|
||||
case SerializableTypeCode.Audio:
|
||||
return "_wav";
|
||||
case SerializableTypeCode.Shader:
|
||||
return "_gls";
|
||||
case SerializableTypeCode.Text:
|
||||
return "_txt";
|
||||
case SerializableTypeCode.RawData:
|
||||
return "_raw";
|
||||
case SerializableTypeCode.VirtualFolder:
|
||||
return "_fod";
|
||||
default:
|
||||
throw new ArgumentException("Unknown file type");
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] Serialize(ISSDSerializable serializableObject)
|
||||
{
|
||||
return serializableObject.GetBytes();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,91 +1,91 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ValueBox"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
public interface IValueBox
|
||||
{
|
||||
|
||||
ref object ValueReference { get; }
|
||||
|
||||
static virtual IValueBox<T> AsGeneric<T>(IValueBox box) where T: unmanaged
|
||||
{
|
||||
if (box is not IValueBox<T> genericBox) {
|
||||
return null;
|
||||
}
|
||||
return genericBox;
|
||||
}
|
||||
|
||||
static virtual bool IsGeneric<T>(IValueBox box) where T: unmanaged
|
||||
{
|
||||
return box is IValueBox<T>;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface IValueBox<T> where T: unmanaged
|
||||
{
|
||||
|
||||
T Value { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A class attempt to reduce cost of boxing, though still a bit slower than direct access to
|
||||
/// _origin value type instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of instance to be boxed.
|
||||
/// </typeparam>
|
||||
public class ValueBox<T> : IValueBox, IValueBox<T> where T: unmanaged
|
||||
{
|
||||
|
||||
private T _value;
|
||||
|
||||
public ValueBox(T value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public ref object ValueReference => ref Unsafe.As<T, object>(ref _value);
|
||||
|
||||
public T Value
|
||||
{
|
||||
get => _value;
|
||||
set => _value = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ValueBox"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
public interface IValueBox
|
||||
{
|
||||
|
||||
ref object ValueReference { get; }
|
||||
|
||||
static virtual IValueBox<T> AsGeneric<T>(IValueBox box) where T: unmanaged
|
||||
{
|
||||
if (box is not IValueBox<T> genericBox) {
|
||||
return null;
|
||||
}
|
||||
return genericBox;
|
||||
}
|
||||
|
||||
static virtual bool IsGeneric<T>(IValueBox box) where T: unmanaged
|
||||
{
|
||||
return box is IValueBox<T>;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface IValueBox<T> where T: unmanaged
|
||||
{
|
||||
|
||||
T Value { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A class attempt to reduce cost of boxing, though still a bit slower than direct access to
|
||||
/// _origin value type instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// Type of instance to be boxed.
|
||||
/// </typeparam>
|
||||
public class ValueBox<T> : IValueBox, IValueBox<T> where T: unmanaged
|
||||
{
|
||||
|
||||
private T _value;
|
||||
|
||||
public ValueBox(T value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public ref object ValueReference => ref Unsafe.As<T, object>(ref _value);
|
||||
|
||||
public T Value
|
||||
{
|
||||
get => _value;
|
||||
set => _value = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,190 +1,190 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Dialogue"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static class Dialogue
|
||||
{
|
||||
|
||||
private static Process? _dialogueProcess;
|
||||
private static AnonymousPipeServerStream _dialogueClientPipe,_dialogueServerPipe;
|
||||
private static int _readAndWriteThreadId;
|
||||
private static ProcessStartInfo _dialogueProcessInfo;
|
||||
private static StreamReader _dr;
|
||||
private static StreamWriter _dw;
|
||||
|
||||
public static bool NeedShowWhenStartup { get; set; }
|
||||
|
||||
public static void PostError(
|
||||
Exception ex
|
||||
)
|
||||
{
|
||||
CreateDialogueProcessIfNotExist();
|
||||
|
||||
_dw.WriteLine($"posterror {ex.Message}");
|
||||
|
||||
_dialogueProcess!.Exited -= DialogueProcessExitCallback;
|
||||
}
|
||||
|
||||
public static void SetReadAndWriteThread(
|
||||
Thread thread
|
||||
)
|
||||
{
|
||||
_readAndWriteThreadId = thread.ManagedThreadId;
|
||||
}
|
||||
|
||||
internal static void CreateDialogueProcessIfNotExist()
|
||||
{
|
||||
if (_dialogueProcess != null) {
|
||||
return;
|
||||
}
|
||||
if (!File.Exists(_dialogueProcessInfo.FileName)) {
|
||||
return;
|
||||
}
|
||||
_dialogueProcess = Process.Start(_dialogueProcessInfo);
|
||||
|
||||
_dr = new StreamReader(_dialogueClientPipe);
|
||||
_dw = new StreamWriter(_dialogueServerPipe);
|
||||
|
||||
_dialogueProcess!.Exited += DialogueProcessExitCallback;
|
||||
|
||||
_dialogueServerPipe.DisposeLocalCopyOfClientHandle();
|
||||
_dialogueClientPipe.DisposeLocalCopyOfClientHandle();
|
||||
}
|
||||
|
||||
internal static void LoadDialogue()
|
||||
{
|
||||
_dialogueServerPipe = new AnonymousPipeServerStream(
|
||||
PipeDirection.Out, HandleInheritability.Inheritable);
|
||||
_dialogueClientPipe = new AnonymousPipeServerStream(
|
||||
PipeDirection.In, HandleInheritability.Inheritable);
|
||||
|
||||
string route = Assembly.GetAssembly(typeof(World))?.Location ?? string.Empty;
|
||||
string path = Path.GetDirectoryName(route) ?? string.Empty;
|
||||
|
||||
string exeName;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
exeName = ".exe";
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
exeName = string.Empty;
|
||||
} else
|
||||
{
|
||||
throw new PlatformNotSupportedException("Unknown OS platform");
|
||||
}
|
||||
|
||||
string consoleRoute = Path.Combine(
|
||||
path, @"StgSharp.TerminalDialogue", $@"StgSharp.TerminalDialogue{exeName}");
|
||||
|
||||
_dialogueProcessInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = consoleRoute,
|
||||
Arguments =
|
||||
$"{_dialogueServerPipe.GetClientHandleAsString()} {_dialogueClientPipe.GetClientHandleAsString()}",
|
||||
UseShellExecute = true,
|
||||
RedirectStandardOutput = false,
|
||||
};
|
||||
}
|
||||
|
||||
internal static void PostMessage(
|
||||
string instruction,
|
||||
params string[] operands
|
||||
)
|
||||
{
|
||||
CreateDialogueProcessIfNotExist();
|
||||
|
||||
_dw.WriteLine($"{instruction} {operands}");
|
||||
}
|
||||
|
||||
internal static void UnloadDialogue()
|
||||
{
|
||||
if (_dialogueProcess != null) {
|
||||
_dialogueProcess.Kill();
|
||||
}
|
||||
_dialogueProcess = null;
|
||||
|
||||
_dialogueServerPipe.Dispose();
|
||||
_dialogueClientPipe.Dispose();
|
||||
}
|
||||
|
||||
internal static string WaitCertainReturn(
|
||||
string target
|
||||
)
|
||||
{
|
||||
if (_dialogueProcess == null) {
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string temp = string .Empty;
|
||||
do
|
||||
{
|
||||
temp = _dr.ReadLine();
|
||||
temp = temp ?? string.Empty;
|
||||
if (!temp!.StartsWith(target))
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
int index = temp.IndexOf(' ');
|
||||
return index != -1 ? temp.Substring(index + 1) : string.Empty;
|
||||
}
|
||||
|
||||
private static void AssertThread()
|
||||
{
|
||||
if (_readAndWriteThreadId != Environment.CurrentManagedThreadId) {
|
||||
throw new InvalidOperationException(
|
||||
"Communication with dialogue can only call from certain thread.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void DialogueProcessExitCallback(
|
||||
object? sender,
|
||||
EventArgs e
|
||||
)
|
||||
{
|
||||
_dialogueProcess = null;
|
||||
_dr.Close();
|
||||
_dw.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Dialogue"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static class Dialogue
|
||||
{
|
||||
|
||||
private static Process? _dialogueProcess;
|
||||
private static AnonymousPipeServerStream _dialogueClientPipe,_dialogueServerPipe;
|
||||
private static int _readAndWriteThreadId;
|
||||
private static ProcessStartInfo _dialogueProcessInfo;
|
||||
private static StreamReader _dr;
|
||||
private static StreamWriter _dw;
|
||||
|
||||
public static bool NeedShowWhenStartup { get; set; }
|
||||
|
||||
public static void PostError(
|
||||
Exception ex
|
||||
)
|
||||
{
|
||||
CreateDialogueProcessIfNotExist();
|
||||
|
||||
_dw.WriteLine($"posterror {ex.Message}");
|
||||
|
||||
_dialogueProcess!.Exited -= DialogueProcessExitCallback;
|
||||
}
|
||||
|
||||
public static void SetReadAndWriteThread(
|
||||
Thread thread
|
||||
)
|
||||
{
|
||||
_readAndWriteThreadId = thread.ManagedThreadId;
|
||||
}
|
||||
|
||||
internal static void CreateDialogueProcessIfNotExist()
|
||||
{
|
||||
if (_dialogueProcess != null) {
|
||||
return;
|
||||
}
|
||||
if (!File.Exists(_dialogueProcessInfo.FileName)) {
|
||||
return;
|
||||
}
|
||||
_dialogueProcess = Process.Start(_dialogueProcessInfo);
|
||||
|
||||
_dr = new StreamReader(_dialogueClientPipe);
|
||||
_dw = new StreamWriter(_dialogueServerPipe);
|
||||
|
||||
_dialogueProcess!.Exited += DialogueProcessExitCallback;
|
||||
|
||||
_dialogueServerPipe.DisposeLocalCopyOfClientHandle();
|
||||
_dialogueClientPipe.DisposeLocalCopyOfClientHandle();
|
||||
}
|
||||
|
||||
internal static void LoadDialogue()
|
||||
{
|
||||
_dialogueServerPipe = new AnonymousPipeServerStream(
|
||||
PipeDirection.Out, HandleInheritability.Inheritable);
|
||||
_dialogueClientPipe = new AnonymousPipeServerStream(
|
||||
PipeDirection.In, HandleInheritability.Inheritable);
|
||||
|
||||
string route = Assembly.GetAssembly(typeof(World))?.Location ?? string.Empty;
|
||||
string path = Path.GetDirectoryName(route) ?? string.Empty;
|
||||
|
||||
string exeName;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
exeName = ".exe";
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
exeName = string.Empty;
|
||||
} else
|
||||
{
|
||||
throw new PlatformNotSupportedException("Unknown OS platform");
|
||||
}
|
||||
|
||||
string consoleRoute = Path.Combine(
|
||||
path, @"StgSharp.TerminalDialogue", $@"StgSharp.TerminalDialogue{exeName}");
|
||||
|
||||
_dialogueProcessInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = consoleRoute,
|
||||
Arguments =
|
||||
$"{_dialogueServerPipe.GetClientHandleAsString()} {_dialogueClientPipe.GetClientHandleAsString()}",
|
||||
UseShellExecute = true,
|
||||
RedirectStandardOutput = false,
|
||||
};
|
||||
}
|
||||
|
||||
internal static void PostMessage(
|
||||
string instruction,
|
||||
params string[] operands
|
||||
)
|
||||
{
|
||||
CreateDialogueProcessIfNotExist();
|
||||
|
||||
_dw.WriteLine($"{instruction} {operands}");
|
||||
}
|
||||
|
||||
internal static void UnloadDialogue()
|
||||
{
|
||||
if (_dialogueProcess != null) {
|
||||
_dialogueProcess.Kill();
|
||||
}
|
||||
_dialogueProcess = null;
|
||||
|
||||
_dialogueServerPipe.Dispose();
|
||||
_dialogueClientPipe.Dispose();
|
||||
}
|
||||
|
||||
internal static string WaitCertainReturn(
|
||||
string target
|
||||
)
|
||||
{
|
||||
if (_dialogueProcess == null) {
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string temp = string .Empty;
|
||||
do
|
||||
{
|
||||
temp = _dr.ReadLine();
|
||||
temp = temp ?? string.Empty;
|
||||
if (!temp!.StartsWith(target))
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
int index = temp.IndexOf(' ');
|
||||
return index != -1 ? temp.Substring(index + 1) : string.Empty;
|
||||
}
|
||||
|
||||
private static void AssertThread()
|
||||
{
|
||||
if (_readAndWriteThreadId != Environment.CurrentManagedThreadId) {
|
||||
throw new InvalidOperationException(
|
||||
"Communication with dialogue can only call from certain thread.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void DialogueProcessExitCallback(
|
||||
object? sender,
|
||||
EventArgs e
|
||||
)
|
||||
{
|
||||
_dialogueProcess = null;
|
||||
_dr.Close();
|
||||
_dw.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ErrorDefine"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class UniformEmptyReferenceException : Exception
|
||||
{
|
||||
|
||||
public UniformEmptyReferenceException(string program, string name)
|
||||
: base(
|
||||
$"Location -1 returned when trying to find uniform {name} in shader program {program}") { }
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ErrorDefine"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class UniformEmptyReferenceException : Exception
|
||||
{
|
||||
|
||||
public UniformEmptyReferenceException(string program, string name)
|
||||
: base(
|
||||
$"Location -1 returned when trying to find uniform {name} in shader program {program}") { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,110 +1,110 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GlobalSetting"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class World
|
||||
{
|
||||
|
||||
internal const int ssdSegmentLength = 16;
|
||||
|
||||
private static byte[] _currentHash = [];
|
||||
|
||||
private static bool _inited;
|
||||
|
||||
public static byte[] CurrentAssemblyHash
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentHash == null)
|
||||
{
|
||||
string route = Assembly.GetExecutingAssembly().Location;
|
||||
string time = DateTime.UtcNow.ToString();
|
||||
using (SHA256 sh = SHA256.Create())
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(route);
|
||||
_currentHash = sh.ComputeHash(bytes);
|
||||
}
|
||||
}
|
||||
return _currentHash;
|
||||
}
|
||||
}
|
||||
|
||||
public static int MainThreadID
|
||||
{
|
||||
get => (_mainThreadID == -1) ?
|
||||
throw new InvalidOperationException(
|
||||
"StgSharp environment is not inited. Main thread id is not available") :
|
||||
_mainThreadID;
|
||||
internal set => _mainThreadID = value;
|
||||
}
|
||||
|
||||
private static int _mainThreadID { get; set; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// CustomizeInit an instance of OpenGL program, This method should be called before any
|
||||
/// other World api.
|
||||
/// </summary>
|
||||
public static void InitGL(int majorVersion, int minorVersion)
|
||||
{
|
||||
if (API == default) {
|
||||
API = GraphicAPI.GL;
|
||||
}
|
||||
if (API != GraphicAPI.GL) {
|
||||
return;
|
||||
}
|
||||
GraphicFramework.InternalInitGL(majorVersion, minorVersion);
|
||||
}
|
||||
|
||||
public static class GlobalSetting
|
||||
{
|
||||
|
||||
private static bool vSyncActivated;
|
||||
|
||||
public static bool VSyncActivated
|
||||
{
|
||||
get => vsyncActivated;
|
||||
set
|
||||
{
|
||||
GraphicFramework.glfwSwapInterval(value ? 1 : 0);
|
||||
vsyncActivated = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}//-------------------------------------- End of Class ---------------------------------------//
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GlobalSetting"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class World
|
||||
{
|
||||
|
||||
internal const int ssdSegmentLength = 16;
|
||||
|
||||
private static byte[] _currentHash = [];
|
||||
|
||||
private static bool _inited;
|
||||
|
||||
public static byte[] CurrentAssemblyHash
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentHash == null)
|
||||
{
|
||||
string route = Assembly.GetExecutingAssembly().Location;
|
||||
string time = DateTime.UtcNow.ToString();
|
||||
using (SHA256 sh = SHA256.Create())
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(route);
|
||||
_currentHash = sh.ComputeHash(bytes);
|
||||
}
|
||||
}
|
||||
return _currentHash;
|
||||
}
|
||||
}
|
||||
|
||||
public static int MainThreadID
|
||||
{
|
||||
get => (_mainThreadID == -1) ?
|
||||
throw new InvalidOperationException(
|
||||
"StgSharp environment is not inited. Main thread id is not available") :
|
||||
_mainThreadID;
|
||||
internal set => _mainThreadID = value;
|
||||
}
|
||||
|
||||
private static int _mainThreadID { get; set; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// CustomizeInit an instance of OpenGL program, This method should be called before any
|
||||
/// other World api.
|
||||
/// </summary>
|
||||
public static void InitGL(int majorVersion, int minorVersion)
|
||||
{
|
||||
if (API == default) {
|
||||
API = GraphicAPI.GL;
|
||||
}
|
||||
if (API != GraphicAPI.GL) {
|
||||
return;
|
||||
}
|
||||
GraphicFramework.InternalInitGL(majorVersion, minorVersion);
|
||||
}
|
||||
|
||||
public static class GlobalSetting
|
||||
{
|
||||
|
||||
private static bool vSyncActivated;
|
||||
|
||||
public static bool VSyncActivated
|
||||
{
|
||||
get => vsyncActivated;
|
||||
set
|
||||
{
|
||||
GraphicFramework.glfwSwapInterval(value ? 1 : 0);
|
||||
vsyncActivated = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}//-------------------------------------- End of Class ---------------------------------------//
|
||||
}
|
||||
@@ -1,84 +1,84 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IStaticModule"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public interface IStaticModule
|
||||
{
|
||||
|
||||
string ModuleName { get; }
|
||||
|
||||
void InitializeModule();
|
||||
|
||||
}
|
||||
|
||||
public class ModuleToInitializeCollection : IEnumerable<IStaticModule>, IStaticModule
|
||||
{
|
||||
|
||||
private readonly List<IStaticModule> _modules = [];
|
||||
|
||||
internal ModuleToInitializeCollection(World.Initializer i)
|
||||
{
|
||||
_modules.Add(i);
|
||||
}
|
||||
|
||||
public IEnumerator<IStaticModule> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<IStaticModule>)_modules).GetEnumerator();
|
||||
}
|
||||
|
||||
public void InitializeModule()
|
||||
{
|
||||
foreach (IStaticModule module in _modules) {
|
||||
module.InitializeModule();
|
||||
}
|
||||
}
|
||||
|
||||
public ModuleToInitializeCollection UseModule<T>() where T: IStaticModule, new()
|
||||
{
|
||||
_modules.Add(new T());
|
||||
return this;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable)_modules).GetEnumerator();
|
||||
}
|
||||
|
||||
void IStaticModule.InitializeModule()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
string IStaticModule.ModuleName => "Module Initializer";
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IStaticModule"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public interface IStaticModule
|
||||
{
|
||||
|
||||
string ModuleName { get; }
|
||||
|
||||
void InitializeModule();
|
||||
|
||||
}
|
||||
|
||||
public class ModuleToInitializeCollection : IEnumerable<IStaticModule>, IStaticModule
|
||||
{
|
||||
|
||||
private readonly List<IStaticModule> _modules = [];
|
||||
|
||||
internal ModuleToInitializeCollection(World.Initializer i)
|
||||
{
|
||||
_modules.Add(i);
|
||||
}
|
||||
|
||||
public IEnumerator<IStaticModule> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<IStaticModule>)_modules).GetEnumerator();
|
||||
}
|
||||
|
||||
public void InitializeModule()
|
||||
{
|
||||
foreach (IStaticModule module in _modules) {
|
||||
module.InitializeModule();
|
||||
}
|
||||
}
|
||||
|
||||
public ModuleToInitializeCollection UseModule<T>() where T: IStaticModule, new()
|
||||
{
|
||||
_modules.Add(new T());
|
||||
return this;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable)_modules).GetEnumerator();
|
||||
}
|
||||
|
||||
void IStaticModule.InitializeModule()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
string IStaticModule.ModuleName => "Module Initializer";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Monitors"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static partial class World
|
||||
{
|
||||
|
||||
public static unsafe IntPtr[] MonitorsHandleArray
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MonitorsArray == null)
|
||||
{
|
||||
int count = 0;
|
||||
IntPtr* arrayHandle = GraphicFramework.glfwGetMonitors(&count);
|
||||
MonitorsArray = new IntPtr[count];
|
||||
Marshal.Copy((IntPtr)arrayHandle, MonitorsArray, 0, count);
|
||||
Marshal.FreeHGlobal((IntPtr)arrayHandle);
|
||||
}
|
||||
return MonitorsArray;
|
||||
}
|
||||
}
|
||||
|
||||
public static nint[] MonitorsArray { get; set; } = [];
|
||||
|
||||
public static IntPtr DefaultMonitor => MonitorsHandleArray[0];
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Monitors"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static partial class World
|
||||
{
|
||||
|
||||
public static unsafe IntPtr[] MonitorsHandleArray
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MonitorsArray == null)
|
||||
{
|
||||
int count = 0;
|
||||
IntPtr* arrayHandle = GraphicFramework.glfwGetMonitors(&count);
|
||||
MonitorsArray = new IntPtr[count];
|
||||
Marshal.Copy((IntPtr)arrayHandle, MonitorsArray, 0, count);
|
||||
Marshal.FreeHGlobal((IntPtr)arrayHandle);
|
||||
}
|
||||
return MonitorsArray;
|
||||
}
|
||||
}
|
||||
|
||||
public static nint[] MonitorsArray { get; set; } = [];
|
||||
|
||||
public static IntPtr DefaultMonitor => MonitorsHandleArray[0];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,258 +1,258 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Platform"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal enum GraphicAPI : byte
|
||||
{
|
||||
|
||||
GL,
|
||||
VK
|
||||
|
||||
}
|
||||
|
||||
public static partial class World
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Version of current World platform. Main version represent in hundred's digit, and sub
|
||||
/// version represent in ten's digit.
|
||||
/// </summary>
|
||||
public const long version = 430;
|
||||
|
||||
private static bool vsyncActivated;
|
||||
|
||||
private static uint markCount = 0;
|
||||
internal static GraphicAPI API = default;
|
||||
|
||||
public static unsafe int DefaultSIMDAlignment
|
||||
{
|
||||
get
|
||||
{
|
||||
SIMDID id = NativeIntrinsic.IntrinsicMask;
|
||||
switch (id.MaskByte[0] & 0b_00001111)
|
||||
{
|
||||
case 1:
|
||||
return id.MaskByte[1] switch
|
||||
{
|
||||
1 => 16,
|
||||
2 => 32,
|
||||
3 => 64,
|
||||
4 => 64,
|
||||
5 => 64,
|
||||
_ => 8,
|
||||
};
|
||||
default:
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ModuleToInitializeCollection Initialize()
|
||||
{
|
||||
return new ModuleToInitializeCollection(new Initializer());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LogError(
|
||||
Exception ex
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(ex.Message, LogType.Error);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LogInfo(
|
||||
string log
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(log, LogType.Info);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LogWarning(
|
||||
string log
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(log, LogType.Warning);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LogWarning(
|
||||
Exception notVerySeriesException
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(notVerySeriesException.Message, LogType.Warning);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Mark(
|
||||
bool needConsole
|
||||
)
|
||||
{
|
||||
markCount++;
|
||||
if (needConsole) {
|
||||
Console.WriteLine(markCount);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Terminate(
|
||||
int exitCode
|
||||
)
|
||||
{
|
||||
MainTimeProvider.StopProvidingTime();
|
||||
GraphicFramework.glfwTerminate();
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
|
||||
public static void Track(
|
||||
object target,
|
||||
string message,
|
||||
bool isConsole,
|
||||
[CallerFilePath] string filePath = "",
|
||||
[CallerMemberName] string callerName = "",
|
||||
[CallerLineNumber] int lineNumber = 0
|
||||
)
|
||||
{
|
||||
Type t = target.GetType();
|
||||
string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n";
|
||||
FieldInfo[] fieldInfo = t.GetFields(
|
||||
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
log += "|\tFieldName\t|\tFieldType\t|\tFieldValue\t|\n";
|
||||
foreach (FieldInfo field in fieldInfo) {
|
||||
log += $"|{field.Name}\t\t|{field.FieldType}\t\t|{field.GetValue(target)}\t\t|\n";
|
||||
}
|
||||
log += $"Tracking at:\n{filePath}\t{callerName}\tline {lineNumber}\n";
|
||||
log += $"Additional information:\n{message}\n";
|
||||
if (isConsole)
|
||||
{
|
||||
Console.WriteLine(log);
|
||||
} else
|
||||
{
|
||||
DefaultLog.InternalWriteLog(log, LogType.Info);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a log message to log file, and mark the _level of this message.
|
||||
/// </summary>
|
||||
/// <param _label="message">
|
||||
/// A string contains information of how current evironment runs.
|
||||
/// </param>
|
||||
/// <param _label="logType">
|
||||
/// The severity of current message.
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteLog(
|
||||
string message,
|
||||
LogType logType
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(message, logType);
|
||||
}
|
||||
|
||||
internal static TDele ConvertAPI<TDele>(
|
||||
IntPtr funcPtr
|
||||
)
|
||||
{
|
||||
if (funcPtr == IntPtr.Zero) {
|
||||
throw new InvalidCastException(
|
||||
"Failed to convert api, the function pointer is zero.");
|
||||
}
|
||||
try
|
||||
{
|
||||
return Marshal.GetDelegateForFunctionPointer<TDele>(funcPtr);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Delegate ConvertAPI(
|
||||
IntPtr funcPtr,
|
||||
Type T
|
||||
)
|
||||
{
|
||||
if (funcPtr == IntPtr.Zero) {
|
||||
throw new InvalidCastException(
|
||||
"Failed to convert api, the function pointer is zero.");
|
||||
}
|
||||
try
|
||||
{
|
||||
return Marshal.GetDelegateForFunctionPointer(funcPtr, T);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe void InternalInitialize()
|
||||
{
|
||||
// Initialize time provider and start providing time
|
||||
MainTimeProvider.StartProvidingTime();
|
||||
GraphicFramework.LoadGlfw();
|
||||
if (GraphicFramework.glfwInit() == 0) {
|
||||
throw new Exception("Failed to init system graphic environment.");
|
||||
}
|
||||
DefaultLog.InternalAppendLog("\n\n\n");
|
||||
DefaultLog.InternalWriteLog(
|
||||
$"Program {Assembly.GetEntryAssembly()!.FullName} on {Environment.MachineName} Started.", LogType.Info);
|
||||
MainThreadID = System.Environment.CurrentManagedThreadId;
|
||||
|
||||
/**/
|
||||
Dialogue.NeedShowWhenStartup = false;
|
||||
Dialogue.LoadDialogue();
|
||||
if (Dialogue.NeedShowWhenStartup) {
|
||||
Dialogue.CreateDialogueProcessIfNotExist();
|
||||
}
|
||||
/**/
|
||||
NativeIntrinsic.InitIntrinsicContext();
|
||||
}
|
||||
|
||||
internal class Initializer : IStaticModule
|
||||
{
|
||||
|
||||
public string ModuleName => "StgSharp";
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void InitializeModule()
|
||||
{
|
||||
World.InternalInitialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Platform"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal enum GraphicAPI : byte
|
||||
{
|
||||
|
||||
GL,
|
||||
VK
|
||||
|
||||
}
|
||||
|
||||
public static partial class World
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Version of current World platform. Main version represent in hundred's digit, and sub
|
||||
/// version represent in ten's digit.
|
||||
/// </summary>
|
||||
public const long version = 430;
|
||||
|
||||
private static bool vsyncActivated;
|
||||
|
||||
private static uint markCount = 0;
|
||||
internal static GraphicAPI API = default;
|
||||
|
||||
public static unsafe int DefaultSIMDAlignment
|
||||
{
|
||||
get
|
||||
{
|
||||
SIMDID id = NativeIntrinsic.IntrinsicMask;
|
||||
switch (id.MaskByte[0] & 0b_00001111)
|
||||
{
|
||||
case 1:
|
||||
return id.MaskByte[1] switch
|
||||
{
|
||||
1 => 16,
|
||||
2 => 32,
|
||||
3 => 64,
|
||||
4 => 64,
|
||||
5 => 64,
|
||||
_ => 8,
|
||||
};
|
||||
default:
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ModuleToInitializeCollection Initialize()
|
||||
{
|
||||
return new ModuleToInitializeCollection(new Initializer());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LogError(
|
||||
Exception ex
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(ex.Message, LogType.Error);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LogInfo(
|
||||
string log
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(log, LogType.Info);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LogWarning(
|
||||
string log
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(log, LogType.Warning);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void LogWarning(
|
||||
Exception notVerySeriesException
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(notVerySeriesException.Message, LogType.Warning);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Mark(
|
||||
bool needConsole
|
||||
)
|
||||
{
|
||||
markCount++;
|
||||
if (needConsole) {
|
||||
Console.WriteLine(markCount);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Terminate(
|
||||
int exitCode
|
||||
)
|
||||
{
|
||||
MainTimeProvider.StopProvidingTime();
|
||||
GraphicFramework.glfwTerminate();
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
|
||||
public static void Track(
|
||||
object target,
|
||||
string message,
|
||||
bool isConsole,
|
||||
[CallerFilePath] string filePath = "",
|
||||
[CallerMemberName] string callerName = "",
|
||||
[CallerLineNumber] int lineNumber = 0
|
||||
)
|
||||
{
|
||||
Type t = target.GetType();
|
||||
string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n";
|
||||
FieldInfo[] fieldInfo = t.GetFields(
|
||||
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
log += "|\tFieldName\t|\tFieldType\t|\tFieldValue\t|\n";
|
||||
foreach (FieldInfo field in fieldInfo) {
|
||||
log += $"|{field.Name}\t\t|{field.FieldType}\t\t|{field.GetValue(target)}\t\t|\n";
|
||||
}
|
||||
log += $"Tracking at:\n{filePath}\t{callerName}\tline {lineNumber}\n";
|
||||
log += $"Additional information:\n{message}\n";
|
||||
if (isConsole)
|
||||
{
|
||||
Console.WriteLine(log);
|
||||
} else
|
||||
{
|
||||
DefaultLog.InternalWriteLog(log, LogType.Info);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a log message to log file, and mark the _level of this message.
|
||||
/// </summary>
|
||||
/// <param _label="message">
|
||||
/// A string contains information of how current evironment runs.
|
||||
/// </param>
|
||||
/// <param _label="logType">
|
||||
/// The severity of current message.
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteLog(
|
||||
string message,
|
||||
LogType logType
|
||||
)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(message, logType);
|
||||
}
|
||||
|
||||
internal static TDele ConvertAPI<TDele>(
|
||||
IntPtr funcPtr
|
||||
)
|
||||
{
|
||||
if (funcPtr == IntPtr.Zero) {
|
||||
throw new InvalidCastException(
|
||||
"Failed to convert api, the function pointer is zero.");
|
||||
}
|
||||
try
|
||||
{
|
||||
return Marshal.GetDelegateForFunctionPointer<TDele>(funcPtr);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Delegate ConvertAPI(
|
||||
IntPtr funcPtr,
|
||||
Type T
|
||||
)
|
||||
{
|
||||
if (funcPtr == IntPtr.Zero) {
|
||||
throw new InvalidCastException(
|
||||
"Failed to convert api, the function pointer is zero.");
|
||||
}
|
||||
try
|
||||
{
|
||||
return Marshal.GetDelegateForFunctionPointer(funcPtr, T);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe void InternalInitialize()
|
||||
{
|
||||
// Initialize time provider and start providing time
|
||||
MainTimeProvider.StartProvidingTime();
|
||||
GraphicFramework.LoadGlfw();
|
||||
if (GraphicFramework.glfwInit() == 0) {
|
||||
throw new Exception("Failed to init system graphic environment.");
|
||||
}
|
||||
DefaultLog.InternalAppendLog("\n\n\n");
|
||||
DefaultLog.InternalWriteLog(
|
||||
$"Program {Assembly.GetEntryAssembly()!.FullName} on {Environment.MachineName} Started.", LogType.Info);
|
||||
MainThreadID = System.Environment.CurrentManagedThreadId;
|
||||
|
||||
/**/
|
||||
Dialogue.NeedShowWhenStartup = false;
|
||||
Dialogue.LoadDialogue();
|
||||
if (Dialogue.NeedShowWhenStartup) {
|
||||
Dialogue.CreateDialogueProcessIfNotExist();
|
||||
}
|
||||
/**/
|
||||
NativeIntrinsic.InitIntrinsicContext();
|
||||
}
|
||||
|
||||
internal class Initializer : IStaticModule
|
||||
{
|
||||
|
||||
public string ModuleName => "StgSharp";
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void InitializeModule()
|
||||
{
|
||||
World.InternalInitialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,49 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="globalKeyStat"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static partial class World
|
||||
{
|
||||
|
||||
private static ConcurrentDictionary<int, KeyStatus> keyListener
|
||||
= new ConcurrentDictionary<int, KeyStatus>();
|
||||
|
||||
public static KeyStatus CheckKey(KeyboardKey key)
|
||||
{
|
||||
return keyListener.GetOrAdd((int)key, KeyStatus.RELEASE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="globalKeyStat"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static partial class World
|
||||
{
|
||||
|
||||
private static ConcurrentDictionary<int, KeyStatus> keyListener
|
||||
= new ConcurrentDictionary<int, KeyStatus>();
|
||||
|
||||
public static KeyStatus CheckKey(KeyboardKey key)
|
||||
{
|
||||
return keyListener.GetOrAdd((int)key, KeyStatus.RELEASE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CoordinationBase"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public abstract class CoordinationBase
|
||||
{
|
||||
|
||||
private bool globalCoordAvailable;
|
||||
private CoordinationBase localCoordination;
|
||||
private Matrix44 coordMat;
|
||||
|
||||
public CoordinationBase(CoordinationBase localCoordination)
|
||||
{
|
||||
this.localCoordination = localCoordination;
|
||||
coordMat = new Matrix44();
|
||||
}
|
||||
|
||||
public virtual Point LocalOrigin
|
||||
{
|
||||
get => new Point(coordMat.column[3].XYZ);
|
||||
internal set => coordMat.column[3].XYZ = value.Coord;
|
||||
}
|
||||
|
||||
public virtual Vec3 LocalX
|
||||
{
|
||||
get => coordMat.column[3].XYZ;
|
||||
internal set => coordMat.column[3].XYZ = value;
|
||||
}
|
||||
|
||||
public virtual Vec3 LocalY
|
||||
{
|
||||
get => coordMat.column[3].XYZ;
|
||||
internal set => coordMat.column[3].XYZ = value;
|
||||
}
|
||||
|
||||
public virtual Vec3 LocalZ
|
||||
{
|
||||
get => coordMat.column[3].XYZ;
|
||||
set => coordMat.column[3].XYZ = value;
|
||||
}
|
||||
|
||||
protected ref Matrix44 CoordMat
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref coordMat;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CoordinationBase"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public abstract class CoordinationBase
|
||||
{
|
||||
|
||||
private bool globalCoordAvailable;
|
||||
private CoordinationBase localCoordination;
|
||||
private Matrix44 coordMat;
|
||||
|
||||
public CoordinationBase(CoordinationBase localCoordination)
|
||||
{
|
||||
this.localCoordination = localCoordination;
|
||||
coordMat = new Matrix44();
|
||||
}
|
||||
|
||||
public virtual Point LocalOrigin
|
||||
{
|
||||
get => new Point(coordMat.column[3].XYZ);
|
||||
internal set => coordMat.column[3].XYZ = value.Coord;
|
||||
}
|
||||
|
||||
public virtual Vec3 LocalX
|
||||
{
|
||||
get => coordMat.column[3].XYZ;
|
||||
internal set => coordMat.column[3].XYZ = value;
|
||||
}
|
||||
|
||||
public virtual Vec3 LocalY
|
||||
{
|
||||
get => coordMat.column[3].XYZ;
|
||||
internal set => coordMat.column[3].XYZ = value;
|
||||
}
|
||||
|
||||
public virtual Vec3 LocalZ
|
||||
{
|
||||
get => coordMat.column[3].XYZ;
|
||||
set => coordMat.column[3].XYZ = value;
|
||||
}
|
||||
|
||||
protected ref Matrix44 CoordMat
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref coordMat;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PlainCoordinate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class PlainCoordinate : CoordinationBase
|
||||
{
|
||||
|
||||
public PlainCoordinate(CoordinationBase local, Point origin, Vec3 xAxis, Vec3 yAxis)
|
||||
: base(local)
|
||||
{
|
||||
CoordMat = Matrix44.Unit;
|
||||
|
||||
CoordMat.column[0] = new Vec4(xAxis, 0);
|
||||
CoordMat.column[1] = new Vec4(yAxis, 0);
|
||||
CoordMat.column[2] = new Vec4(Linear.Normalize(Vec3.Cross(xAxis, yAxis)), 0);
|
||||
|
||||
LocalOrigin = origin;
|
||||
}
|
||||
|
||||
public static PlainCoordinate StandardPlainCoordination { get; } = new(null, new Point(0, 0, 0),
|
||||
new Vec3(1, 0, 0), new Vec3(0, 1, 0));
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PlainCoordinate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class PlainCoordinate : CoordinationBase
|
||||
{
|
||||
|
||||
public PlainCoordinate(CoordinationBase local, Point origin, Vec3 xAxis, Vec3 yAxis)
|
||||
: base(local)
|
||||
{
|
||||
CoordMat = Matrix44.Unit;
|
||||
|
||||
CoordMat.column[0] = new Vec4(xAxis, 0);
|
||||
CoordMat.column[1] = new Vec4(yAxis, 0);
|
||||
CoordMat.column[2] = new Vec4(Linear.Normalize(Vec3.Cross(xAxis, yAxis)), 0);
|
||||
|
||||
LocalOrigin = origin;
|
||||
}
|
||||
|
||||
public static PlainCoordinate StandardPlainCoordination { get; } = new(null, new Point(0, 0, 0),
|
||||
new Vec3(1, 0, 0), new Vec3(0, 1, 0));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SpaceCoordinate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class SpaceCoordinate : CoordinationBase
|
||||
{
|
||||
|
||||
public SpaceCoordinate(CoordinationBase localCoordination, Point origin, Vec3 xAxis, Vec3 yAxis, Vec3 zAxis)
|
||||
: base(localCoordination) { }
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SpaceCoordinate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class SpaceCoordinate : CoordinationBase
|
||||
{
|
||||
|
||||
public SpaceCoordinate(CoordinationBase localCoordination, Point origin, Vec3 xAxis, Vec3 yAxis, Vec3 zAxis)
|
||||
: base(localCoordination) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="StreamLocalCoordinate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
/*
|
||||
public class StreamLocalCoordinate : CoordinationBase
|
||||
{
|
||||
}
|
||||
/**/
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="StreamLocalCoordinate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
/*
|
||||
public class StreamLocalCoordinate : CoordinationBase
|
||||
{
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GemoryException"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class ToUpperDimensionException : Exception
|
||||
{
|
||||
|
||||
protected ToUpperDimensionException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
|
||||
public ToUpperDimensionException() { }
|
||||
|
||||
public ToUpperDimensionException(string message) : base(message) { }
|
||||
|
||||
public ToUpperDimensionException(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当几何体调用了过多的CalcVec方法时,产生UnusedVertexException异常
|
||||
/// </summary>
|
||||
public class UnusedVertexException : Exception
|
||||
{
|
||||
|
||||
protected UnusedVertexException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
|
||||
public UnusedVertexException() { }
|
||||
|
||||
public UnusedVertexException(string message) : base(message) { }
|
||||
|
||||
public UnusedVertexException(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GemoryException"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class ToUpperDimensionException : Exception
|
||||
{
|
||||
|
||||
protected ToUpperDimensionException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
|
||||
public ToUpperDimensionException() { }
|
||||
|
||||
public ToUpperDimensionException(string message) : base(message) { }
|
||||
|
||||
public ToUpperDimensionException(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当几何体调用了过多的CalcVec方法时,产生UnusedVertexException异常
|
||||
/// </summary>
|
||||
public class UnusedVertexException : Exception
|
||||
{
|
||||
|
||||
protected UnusedVertexException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
|
||||
public UnusedVertexException() { }
|
||||
|
||||
public UnusedVertexException(string message) : base(message) { }
|
||||
|
||||
public UnusedVertexException(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,113 +1,113 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GeometryOperation"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate Vec3 GeometryMotionDelegate(TimeSpanProvider timeSource, out float rotation);
|
||||
|
||||
public class GeometryMotion
|
||||
{
|
||||
|
||||
private bool isIncrementMode;
|
||||
private bool sourceIsStatic;
|
||||
private GeometryMotionDelegate movement;
|
||||
private IntPtr handle;
|
||||
private TimeSpanProvider time;
|
||||
|
||||
public unsafe GeometryMotion(
|
||||
bool isIncreament,
|
||||
TimeSpanProvider timeSource,
|
||||
GeometryMotionDelegate motionDelegate)
|
||||
{
|
||||
isIncrementMode = isIncreament;
|
||||
time = timeSource;
|
||||
if (motionDelegate == null)
|
||||
{
|
||||
handle = (IntPtr)(delegate*<TimeSpanProvider, out float, Vec3>)&defaultMotion;
|
||||
movement = defaultMotion;
|
||||
} else if (motionDelegate.Method.IsStatic)
|
||||
{
|
||||
sourceIsStatic = true;
|
||||
handle = Marshal.GetFunctionPointerForDelegate(motionDelegate);
|
||||
movement = motionDelegate;
|
||||
} else
|
||||
{
|
||||
movement = motionDelegate;
|
||||
}
|
||||
|
||||
// sourceIsStatic = false;
|
||||
}
|
||||
|
||||
public bool IsIncrement
|
||||
{
|
||||
get => isIncrementMode;
|
||||
}
|
||||
|
||||
public static GeometryMotion DefaultMotion
|
||||
{
|
||||
get => new GeometryMotion(true, null, null);
|
||||
}
|
||||
|
||||
public unsafe void RunMotion(ref Vec3 coord, ref float rotation)
|
||||
{
|
||||
float rot;
|
||||
Vec3 vec;
|
||||
if (sourceIsStatic)
|
||||
{
|
||||
vec = ((delegate* unmanaged[Cdecl]<TimeSpanProvider, out float, Vec3>)handle)(
|
||||
time, out rot);
|
||||
} else
|
||||
{
|
||||
vec = movement(time, out rot);
|
||||
}
|
||||
|
||||
if (isIncrementMode)
|
||||
{
|
||||
coord += vec;
|
||||
rotation += rot;
|
||||
} else
|
||||
{
|
||||
coord = vec;
|
||||
rotation = rot;
|
||||
}
|
||||
}
|
||||
|
||||
private static Vec3 defaultMotion(TimeSpanProvider provider, out float rotation)
|
||||
{
|
||||
rotation = 0;
|
||||
return Vec3.Zero;
|
||||
}
|
||||
|
||||
}//------------------------------- End of Class -------------------------------
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GeometryOperation"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate Vec3 GeometryMotionDelegate(TimeSpanProvider timeSource, out float rotation);
|
||||
|
||||
public class GeometryMotion
|
||||
{
|
||||
|
||||
private bool isIncrementMode;
|
||||
private bool sourceIsStatic;
|
||||
private GeometryMotionDelegate movement;
|
||||
private IntPtr handle;
|
||||
private TimeSpanProvider time;
|
||||
|
||||
public unsafe GeometryMotion(
|
||||
bool isIncreament,
|
||||
TimeSpanProvider timeSource,
|
||||
GeometryMotionDelegate motionDelegate)
|
||||
{
|
||||
isIncrementMode = isIncreament;
|
||||
time = timeSource;
|
||||
if (motionDelegate == null)
|
||||
{
|
||||
handle = (IntPtr)(delegate*<TimeSpanProvider, out float, Vec3>)&defaultMotion;
|
||||
movement = defaultMotion;
|
||||
} else if (motionDelegate.Method.IsStatic)
|
||||
{
|
||||
sourceIsStatic = true;
|
||||
handle = Marshal.GetFunctionPointerForDelegate(motionDelegate);
|
||||
movement = motionDelegate;
|
||||
} else
|
||||
{
|
||||
movement = motionDelegate;
|
||||
}
|
||||
|
||||
// sourceIsStatic = false;
|
||||
}
|
||||
|
||||
public bool IsIncrement
|
||||
{
|
||||
get => isIncrementMode;
|
||||
}
|
||||
|
||||
public static GeometryMotion DefaultMotion
|
||||
{
|
||||
get => new GeometryMotion(true, null, null);
|
||||
}
|
||||
|
||||
public unsafe void RunMotion(ref Vec3 coord, ref float rotation)
|
||||
{
|
||||
float rot;
|
||||
Vec3 vec;
|
||||
if (sourceIsStatic)
|
||||
{
|
||||
vec = ((delegate* unmanaged[Cdecl]<TimeSpanProvider, out float, Vec3>)handle)(
|
||||
time, out rot);
|
||||
} else
|
||||
{
|
||||
vec = movement(time, out rot);
|
||||
}
|
||||
|
||||
if (isIncrementMode)
|
||||
{
|
||||
coord += vec;
|
||||
rotation += rot;
|
||||
} else
|
||||
{
|
||||
coord = vec;
|
||||
rotation = rot;
|
||||
}
|
||||
}
|
||||
|
||||
private static Vec3 defaultMotion(TimeSpanProvider provider, out float rotation)
|
||||
{
|
||||
rotation = 0;
|
||||
return Vec3.Zero;
|
||||
}
|
||||
|
||||
}//------------------------------- End of Class -------------------------------
|
||||
}
|
||||
|
||||
@@ -1,175 +1,175 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Angle"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static partial class GeometryScaler
|
||||
{
|
||||
|
||||
internal const float DegToRad = 180 / Scalar.Pi;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Cos(Radius r)
|
||||
{
|
||||
return MathF.Cos(r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Cos(Degree r)
|
||||
{
|
||||
return MathF.Cos(r._degree / DegToRad);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Sin(Radius r)
|
||||
{
|
||||
return MathF.Sin(r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Sin(Degree r)
|
||||
{
|
||||
return MathF.Sin(r._degree / DegToRad);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Tan(Radius r)
|
||||
{
|
||||
return MathF.Tan(r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Tan(Degree r)
|
||||
{
|
||||
return MathF.Tan(r._degree / DegToRad);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Degree ToDegree(float value)
|
||||
{
|
||||
return new Degree(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct Degree
|
||||
{
|
||||
|
||||
internal float _degree;
|
||||
|
||||
public Degree(float dgree)
|
||||
{
|
||||
_degree = dgree;
|
||||
}
|
||||
|
||||
public static implicit operator Radius(Degree d)
|
||||
{
|
||||
return new Radius(d._degree / GeometryScaler.DegToRad);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct Radius
|
||||
{
|
||||
|
||||
internal float _radius;
|
||||
|
||||
[Obsolete("Unsafe, you may forget this is radius.", true)]
|
||||
public Radius() { }
|
||||
|
||||
public Radius(float radius)
|
||||
{
|
||||
_radius = radius;
|
||||
}
|
||||
|
||||
public static Radius Zero
|
||||
{
|
||||
get => new Radius(0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator -(Radius r)
|
||||
{
|
||||
return new Radius(-r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator -(Radius left, Radius Right)
|
||||
{
|
||||
return new Radius(left._radius - Right._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Radius left, Radius right)
|
||||
{
|
||||
return left._radius != right._radius;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator *(Radius left, float right)
|
||||
{
|
||||
return new Radius(left._radius * right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator /(Radius left, float right)
|
||||
{
|
||||
return new Radius(left._radius / right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float operator /(Radius left, Radius right)
|
||||
{
|
||||
return left._radius / right._radius;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator +(Radius left, Radius Right)
|
||||
{
|
||||
return new Radius(left._radius + Right._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Radius left, Radius right)
|
||||
{
|
||||
return left._radius == right._radius;
|
||||
}
|
||||
|
||||
public static implicit operator Degree(Radius r)
|
||||
{
|
||||
return new Degree((r._radius * 180) / Scalar.Pi);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Angle"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Mathematics
|
||||
{
|
||||
public static partial class GeometryScaler
|
||||
{
|
||||
|
||||
internal const float DegToRad = 180 / Scalar.Pi;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Cos(Radius r)
|
||||
{
|
||||
return MathF.Cos(r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Cos(Degree r)
|
||||
{
|
||||
return MathF.Cos(r._degree / DegToRad);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Sin(Radius r)
|
||||
{
|
||||
return MathF.Sin(r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Sin(Degree r)
|
||||
{
|
||||
return MathF.Sin(r._degree / DegToRad);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Tan(Radius r)
|
||||
{
|
||||
return MathF.Tan(r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Tan(Degree r)
|
||||
{
|
||||
return MathF.Tan(r._degree / DegToRad);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Degree ToDegree(float value)
|
||||
{
|
||||
return new Degree(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct Degree
|
||||
{
|
||||
|
||||
internal float _degree;
|
||||
|
||||
public Degree(float dgree)
|
||||
{
|
||||
_degree = dgree;
|
||||
}
|
||||
|
||||
public static implicit operator Radius(Degree d)
|
||||
{
|
||||
return new Radius(d._degree / GeometryScaler.DegToRad);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct Radius
|
||||
{
|
||||
|
||||
internal float _radius;
|
||||
|
||||
[Obsolete("Unsafe, you may forget this is radius.", true)]
|
||||
public Radius() { }
|
||||
|
||||
public Radius(float radius)
|
||||
{
|
||||
_radius = radius;
|
||||
}
|
||||
|
||||
public static Radius Zero
|
||||
{
|
||||
get => new Radius(0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator -(Radius r)
|
||||
{
|
||||
return new Radius(-r._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator -(Radius left, Radius Right)
|
||||
{
|
||||
return new Radius(left._radius - Right._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Radius left, Radius right)
|
||||
{
|
||||
return left._radius != right._radius;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator *(Radius left, float right)
|
||||
{
|
||||
return new Radius(left._radius * right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator /(Radius left, float right)
|
||||
{
|
||||
return new Radius(left._radius / right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float operator /(Radius left, Radius right)
|
||||
{
|
||||
return left._radius / right._radius;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Radius operator +(Radius left, Radius Right)
|
||||
{
|
||||
return new Radius(left._radius + Right._radius);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Radius left, Radius right)
|
||||
{
|
||||
return left._radius == right._radius;
|
||||
}
|
||||
|
||||
public static implicit operator Degree(Radius r)
|
||||
{
|
||||
return new Degree((r._radius * 180) / Scalar.Pi);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IGeometry"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IGeometry
|
||||
{
|
||||
|
||||
public Point this[int index] { get; set; }
|
||||
|
||||
#pragma warning disable CA1819
|
||||
public Vec4[] VertexStream
|
||||
#pragma warning restore CA1819
|
||||
{ get; }
|
||||
|
||||
public CoordinationBase Coordination { get; }
|
||||
|
||||
public int VertexCount { get; }
|
||||
|
||||
public ReadOnlySpan<int> VertexIndices { get; }
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IGeometry"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IGeometry
|
||||
{
|
||||
|
||||
public Point this[int index] { get; set; }
|
||||
|
||||
#pragma warning disable CA1819
|
||||
public Vec4[] VertexStream
|
||||
#pragma warning restore CA1819
|
||||
{ get; }
|
||||
|
||||
public CoordinationBase Coordination { get; }
|
||||
|
||||
public int VertexCount { get; }
|
||||
|
||||
public ReadOnlySpan<int> VertexIndices { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IGeomtryBuffer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IGeomtryBuffer { }
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IGeomtryBuffer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IGeomtryBuffer { }
|
||||
}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IInstancing"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IInstancing
|
||||
{
|
||||
|
||||
public float Rotation { get { return GlobalBuffer.CoordAndRotationList[BufferId].W; } set
|
||||
{
|
||||
Vec4 temp = GlobalBuffer.CoordAndRotationList[
|
||||
BufferId];
|
||||
temp.W = value;
|
||||
GlobalBuffer.CoordAndRotationList[
|
||||
BufferId] = temp;
|
||||
} }
|
||||
|
||||
public float Scale { get { return GlobalBuffer.ScalingList[BufferId]; } set { GlobalBuffer.ScalingList[BufferId] = value; } }
|
||||
|
||||
public GeometryMotion Motion { get; set; }
|
||||
|
||||
public IInstancingBuffer GlobalBuffer { get; internal set; }
|
||||
|
||||
public int BufferId { get; internal set; }
|
||||
|
||||
public Vec3 CenterPositionGlobal { get; internal set; }
|
||||
|
||||
public Vec3 Coord { get { return GlobalBuffer.CoordAndRotationList[BufferId].XYZ; } set { GlobalBuffer.CoordAndRotationList[BufferId] = new Vec4(value.reg); } }
|
||||
|
||||
public void Move()
|
||||
{
|
||||
(Vec3 coord, float rotation) = (Coord, Rotation);
|
||||
Motion.RunMotion(ref coord, ref rotation);
|
||||
(Coord, Rotation) = (coord, rotation);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IInstancing"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IInstancing
|
||||
{
|
||||
|
||||
public float Rotation { get { return GlobalBuffer.CoordAndRotationList[BufferId].W; } set
|
||||
{
|
||||
Vec4 temp = GlobalBuffer.CoordAndRotationList[
|
||||
BufferId];
|
||||
temp.W = value;
|
||||
GlobalBuffer.CoordAndRotationList[
|
||||
BufferId] = temp;
|
||||
} }
|
||||
|
||||
public float Scale { get { return GlobalBuffer.ScalingList[BufferId]; } set { GlobalBuffer.ScalingList[BufferId] = value; } }
|
||||
|
||||
public GeometryMotion Motion { get; set; }
|
||||
|
||||
public IInstancingBuffer GlobalBuffer { get; internal set; }
|
||||
|
||||
public int BufferId { get; internal set; }
|
||||
|
||||
public Vec3 CenterPositionGlobal { get; internal set; }
|
||||
|
||||
public Vec3 Coord { get { return GlobalBuffer.CoordAndRotationList[BufferId].XYZ; } set { GlobalBuffer.CoordAndRotationList[BufferId] = new Vec4(value.reg); } }
|
||||
|
||||
public void Move()
|
||||
{
|
||||
(Vec3 coord, float rotation) = (Coord, Rotation);
|
||||
Motion.RunMotion(ref coord, ref rotation);
|
||||
(Coord, Rotation) = (coord, rotation);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IInstancingBuffer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IInstancingBuffer
|
||||
{
|
||||
|
||||
public Span<Vec4> CoordAndRotationSpan { get; }
|
||||
|
||||
public Span<float> ScalingSpan { get; }
|
||||
|
||||
internal IGeometry TypicalShape { get; }
|
||||
|
||||
internal List<IInstancing> InstanceList { get; }
|
||||
|
||||
internal List<Vec4> CoordAndRotationList { get; }
|
||||
|
||||
internal List<float> ScalingList { get; }
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IInstancingBuffer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IInstancingBuffer
|
||||
{
|
||||
|
||||
public Span<Vec4> CoordAndRotationSpan { get; }
|
||||
|
||||
public Span<float> ScalingSpan { get; }
|
||||
|
||||
internal IGeometry TypicalShape { get; }
|
||||
|
||||
internal List<IInstancing> InstanceList { get; }
|
||||
|
||||
internal List<Vec4> CoordAndRotationList { get; }
|
||||
|
||||
internal List<float> ScalingList { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Cordinate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PartialPlainCoordinate
|
||||
{
|
||||
/*
|
||||
internal Matrix32 axis;
|
||||
|
||||
/// <summary>
|
||||
/// The _origin of this coordinate.
|
||||
/// </summary>
|
||||
public Vec3 origin;
|
||||
|
||||
public PartialPlainCoordinate( Vec3 origin, Vec3 horiziontial, Vec3 vertical )
|
||||
{
|
||||
this.origin = origin;
|
||||
axis = new Matrix32();
|
||||
Unsafe.SkipInit( out axis.mat );
|
||||
axis.colum0 = horiziontial;
|
||||
axis.colum1 = vertical;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The horizontial axis of the coordinate. Point to the right direction.
|
||||
/// </summary>
|
||||
public Vec3 axis_H => axis.colum0;
|
||||
|
||||
/// <summary>
|
||||
/// The vertical axis of the coordinate. Point to the top direction.
|
||||
/// </summary>
|
||||
public Vec3 axis_V => axis.colum1;
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public Vec3 GetRealLocate( Vec2 raletiveLocation )
|
||||
{
|
||||
return origin + axis.VerticalVecMultiply( raletiveLocation );
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Cordinate"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PartialPlainCoordinate
|
||||
{
|
||||
/*
|
||||
internal Matrix32 axis;
|
||||
|
||||
/// <summary>
|
||||
/// The _origin of this coordinate.
|
||||
/// </summary>
|
||||
public Vec3 origin;
|
||||
|
||||
public PartialPlainCoordinate( Vec3 origin, Vec3 horiziontial, Vec3 vertical )
|
||||
{
|
||||
this.origin = origin;
|
||||
axis = new Matrix32();
|
||||
Unsafe.SkipInit( out axis.mat );
|
||||
axis.colum0 = horiziontial;
|
||||
axis.colum1 = vertical;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The horizontial axis of the coordinate. Point to the right direction.
|
||||
/// </summary>
|
||||
public Vec3 axis_H => axis.colum0;
|
||||
|
||||
/// <summary>
|
||||
/// The vertical axis of the coordinate. Point to the top direction.
|
||||
/// </summary>
|
||||
public Vec3 axis_V => axis.colum1;
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public Vec3 GetRealLocate( Vec2 raletiveLocation )
|
||||
{
|
||||
return origin + axis.VerticalVecMultiply( raletiveLocation );
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GeometryOperation"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public static unsafe class GeometryOperation
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec3 DefaultMotion(int tick)
|
||||
{
|
||||
return default(Vec3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GeometryOperation"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public static unsafe class GeometryOperation
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec3 DefaultMotion(int tick)
|
||||
{
|
||||
return default(Vec3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IPlainEntity"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IPlainEntity
|
||||
{
|
||||
|
||||
public Vec2 CenterPosition { get; set; }
|
||||
|
||||
public bool CollideWith(IPlainEntity entity);
|
||||
|
||||
}
|
||||
|
||||
public class PlainEntity : IPlainEntity
|
||||
{
|
||||
|
||||
private PlainGeometry _shape;
|
||||
|
||||
public PlainEntity(PlainGeometry shape)
|
||||
{
|
||||
_shape = shape;
|
||||
}
|
||||
|
||||
bool IPlainEntity.CollideWith(IPlainEntity entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Vec2 IPlainEntity.CenterPosition
|
||||
{
|
||||
get => _shape.Coordination.LocalOrigin.Coord.XY;
|
||||
set => throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IPlainEntity"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IPlainEntity
|
||||
{
|
||||
|
||||
public Vec2 CenterPosition { get; set; }
|
||||
|
||||
public bool CollideWith(IPlainEntity entity);
|
||||
|
||||
}
|
||||
|
||||
public class PlainEntity : IPlainEntity
|
||||
{
|
||||
|
||||
private PlainGeometry _shape;
|
||||
|
||||
public PlainEntity(PlainGeometry shape)
|
||||
{
|
||||
_shape = shape;
|
||||
}
|
||||
|
||||
bool IPlainEntity.CollideWith(IPlainEntity entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Vec2 IPlainEntity.CenterPosition
|
||||
{
|
||||
get => _shape.Coordination.LocalOrigin.Coord.XY;
|
||||
set => throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ParticleOnPlain"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class ParticleOnPlain : IInstancing, IPlainEntity
|
||||
{
|
||||
|
||||
public ParticleOnPlain(PlainInstancingBuffer<ParticleOnPlain> buffer)
|
||||
{
|
||||
if (buffer == null) {
|
||||
throw new ArgumentNullException(paramName:nameof(buffer));
|
||||
}
|
||||
GlobalBuffer = buffer;
|
||||
BufferId = buffer.CreateInstanceID();
|
||||
((IInstancingBuffer)buffer).InstanceList.Add(this);
|
||||
}
|
||||
|
||||
public GeometryMotion Motion { get; set; }
|
||||
|
||||
public IInstancingBuffer GlobalBuffer { get; set; }
|
||||
|
||||
public int BufferId { get; set; }
|
||||
|
||||
Vec3 IInstancing.CenterPositionGlobal { get; set; }
|
||||
|
||||
bool IPlainEntity.CollideWith(IPlainEntity entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Vec2 IPlainEntity.CenterPosition
|
||||
{
|
||||
get => GlobalBuffer.CoordAndRotationList[BufferId].XY;
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ParticleOnPlain"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class ParticleOnPlain : IInstancing, IPlainEntity
|
||||
{
|
||||
|
||||
public ParticleOnPlain(PlainInstancingBuffer<ParticleOnPlain> buffer)
|
||||
{
|
||||
if (buffer == null) {
|
||||
throw new ArgumentNullException(paramName:nameof(buffer));
|
||||
}
|
||||
GlobalBuffer = buffer;
|
||||
BufferId = buffer.CreateInstanceID();
|
||||
((IInstancingBuffer)buffer).InstanceList.Add(this);
|
||||
}
|
||||
|
||||
public GeometryMotion Motion { get; set; }
|
||||
|
||||
public IInstancingBuffer GlobalBuffer { get; set; }
|
||||
|
||||
public int BufferId { get; set; }
|
||||
|
||||
Vec3 IInstancing.CenterPositionGlobal { get; set; }
|
||||
|
||||
bool IPlainEntity.CollideWith(IPlainEntity entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Vec2 IPlainEntity.CenterPosition
|
||||
{
|
||||
get => GlobalBuffer.CoordAndRotationList[BufferId].XY;
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PlainGeometry"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
/// <summary>
|
||||
/// Plain geometry only contains straight sides.
|
||||
/// </summary>
|
||||
public abstract class PlainGeometry : IGeometry
|
||||
{
|
||||
|
||||
protected Vec4[] vertexMat;
|
||||
internal CoordinationBase coordinate;
|
||||
|
||||
internal PlainGeometry(CoordinationBase coordination)
|
||||
{
|
||||
coordinate = coordination;
|
||||
}
|
||||
|
||||
public Point this[int index]
|
||||
{
|
||||
get => new Point(vertexMat[index]);
|
||||
set => vertexMat[index].vec = value.coordVec;
|
||||
}
|
||||
|
||||
public int VertexCount => this.vertexMat.Length;
|
||||
|
||||
public abstract ReadOnlySpan<int> VertexIndices { get; }
|
||||
|
||||
#pragma warning disable CA1819
|
||||
public Vec4[] VertexStream => vertexMat;
|
||||
|
||||
public CoordinationBase Coordination => this.coordinate;
|
||||
#pragma warning restore CA1819
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PlainGeometry"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
/// <summary>
|
||||
/// Plain geometry only contains straight sides.
|
||||
/// </summary>
|
||||
public abstract class PlainGeometry : IGeometry
|
||||
{
|
||||
|
||||
protected Vec4[] vertexMat;
|
||||
internal CoordinationBase coordinate;
|
||||
|
||||
internal PlainGeometry(CoordinationBase coordination)
|
||||
{
|
||||
coordinate = coordination;
|
||||
}
|
||||
|
||||
public Point this[int index]
|
||||
{
|
||||
get => new Point(vertexMat[index]);
|
||||
set => vertexMat[index].vec = value.coordVec;
|
||||
}
|
||||
|
||||
public int VertexCount => this.vertexMat.Length;
|
||||
|
||||
public abstract ReadOnlySpan<int> VertexIndices { get; }
|
||||
|
||||
#pragma warning disable CA1819
|
||||
public Vec4[] VertexStream => vertexMat;
|
||||
|
||||
public CoordinationBase Coordination => this.coordinate;
|
||||
#pragma warning restore CA1819
|
||||
}
|
||||
}
|
||||
@@ -1,187 +1,187 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PlainInstancingBuffer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class PlainInstancingBuffer<T> : IDisposable, IEnumerable<T>, IInstancingBuffer where T: IInstancing
|
||||
{
|
||||
|
||||
private bool disposedValue;
|
||||
|
||||
private CoordinatePlain globalCoordinate;
|
||||
private List<Vec4> coordList;
|
||||
private List<IInstancing> instanceList;
|
||||
private List<float> scalingList;
|
||||
private Mutex mutex;
|
||||
|
||||
public PlainInstancingBuffer()
|
||||
{
|
||||
coordList = new List<Vec4>(capacity:100);
|
||||
instanceList = new List<IInstancing>(capacity:100);
|
||||
scalingList = new List<float>(capacity:100);
|
||||
coordArray = Array.Empty<Vec4>();
|
||||
scaleArray = Array.Empty<float>();
|
||||
mutex = new Mutex();
|
||||
}
|
||||
|
||||
public List<IInstancing> InstanceList
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => instanceList;
|
||||
}
|
||||
|
||||
public List<Vec4> CoordAndRotationList
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => coordList;
|
||||
}
|
||||
|
||||
public List<float> ScalingList
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => scalingList;
|
||||
}
|
||||
|
||||
public Span<Vec4> CoordAndRotationSpan
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CollectionsMarshal.AsSpan(coordList);
|
||||
}
|
||||
|
||||
public Span<float> ScalingSpan
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CollectionsMarshal.AsSpan(scalingList);
|
||||
}
|
||||
|
||||
public int CreateInstanceID()
|
||||
{
|
||||
mutex.WaitOne();
|
||||
int ret = instanceList.Count;
|
||||
coordList.Add(new Vec4());
|
||||
scalingList.Add(0);
|
||||
mutex.ReleaseMutex();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ~PlainInstancingBuffer()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing:true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
foreach (IInstancing item in instanceList) {
|
||||
yield return (T)item;
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(T instance)
|
||||
{
|
||||
mutex.WaitOne();
|
||||
if (instance.GlobalBuffer != this) {
|
||||
throw new ArgumentException(
|
||||
message:"instance does not belong to current Particle Buffer",
|
||||
paramName:nameof(instance));
|
||||
}
|
||||
int index = instance.BufferId;
|
||||
IInstancing temp = instanceList[^1];
|
||||
instanceList[instance.BufferId] = temp;
|
||||
temp.BufferId = instance.BufferId;
|
||||
|
||||
coordList[instance.BufferId] = coordList[^1];
|
||||
scalingList[instance.BufferId] = scalingList[^1];
|
||||
|
||||
instanceList.RemoveAt(instanceList.Count - 1);
|
||||
coordList.RemoveAt(coordList.Count - 1);
|
||||
scalingList.RemoveAt(scalingList.Count - 1);
|
||||
mutex.ReleaseMutex();
|
||||
}
|
||||
|
||||
public void UpdateAllParticles()
|
||||
{
|
||||
foreach (IInstancing particle in instanceList) {
|
||||
particle.Move();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing) {
|
||||
mutex.Dispose();
|
||||
}
|
||||
|
||||
coordList.Clear();
|
||||
instanceList.Clear();
|
||||
scalingList.Clear();
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
foreach (IInstancing item in instanceList) {
|
||||
yield return (T)item;
|
||||
}
|
||||
}
|
||||
|
||||
IGeometry IInstancingBuffer.TypicalShape => throw new NotImplementedException();
|
||||
|
||||
#region field of mem opt
|
||||
|
||||
private Vec4[] coordArray;
|
||||
private float[] scaleArray;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PlainInstancingBuffer"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class PlainInstancingBuffer<T> : IDisposable, IEnumerable<T>, IInstancingBuffer where T: IInstancing
|
||||
{
|
||||
|
||||
private bool disposedValue;
|
||||
|
||||
private CoordinatePlain globalCoordinate;
|
||||
private List<Vec4> coordList;
|
||||
private List<IInstancing> instanceList;
|
||||
private List<float> scalingList;
|
||||
private Mutex mutex;
|
||||
|
||||
public PlainInstancingBuffer()
|
||||
{
|
||||
coordList = new List<Vec4>(capacity:100);
|
||||
instanceList = new List<IInstancing>(capacity:100);
|
||||
scalingList = new List<float>(capacity:100);
|
||||
coordArray = Array.Empty<Vec4>();
|
||||
scaleArray = Array.Empty<float>();
|
||||
mutex = new Mutex();
|
||||
}
|
||||
|
||||
public List<IInstancing> InstanceList
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => instanceList;
|
||||
}
|
||||
|
||||
public List<Vec4> CoordAndRotationList
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => coordList;
|
||||
}
|
||||
|
||||
public List<float> ScalingList
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => scalingList;
|
||||
}
|
||||
|
||||
public Span<Vec4> CoordAndRotationSpan
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CollectionsMarshal.AsSpan(coordList);
|
||||
}
|
||||
|
||||
public Span<float> ScalingSpan
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CollectionsMarshal.AsSpan(scalingList);
|
||||
}
|
||||
|
||||
public int CreateInstanceID()
|
||||
{
|
||||
mutex.WaitOne();
|
||||
int ret = instanceList.Count;
|
||||
coordList.Add(new Vec4());
|
||||
scalingList.Add(0);
|
||||
mutex.ReleaseMutex();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ~PlainInstancingBuffer()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing:true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
foreach (IInstancing item in instanceList) {
|
||||
yield return (T)item;
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(T instance)
|
||||
{
|
||||
mutex.WaitOne();
|
||||
if (instance.GlobalBuffer != this) {
|
||||
throw new ArgumentException(
|
||||
message:"instance does not belong to current Particle Buffer",
|
||||
paramName:nameof(instance));
|
||||
}
|
||||
int index = instance.BufferId;
|
||||
IInstancing temp = instanceList[^1];
|
||||
instanceList[instance.BufferId] = temp;
|
||||
temp.BufferId = instance.BufferId;
|
||||
|
||||
coordList[instance.BufferId] = coordList[^1];
|
||||
scalingList[instance.BufferId] = scalingList[^1];
|
||||
|
||||
instanceList.RemoveAt(instanceList.Count - 1);
|
||||
coordList.RemoveAt(coordList.Count - 1);
|
||||
scalingList.RemoveAt(scalingList.Count - 1);
|
||||
mutex.ReleaseMutex();
|
||||
}
|
||||
|
||||
public void UpdateAllParticles()
|
||||
{
|
||||
foreach (IInstancing particle in instanceList) {
|
||||
particle.Move();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing) {
|
||||
mutex.Dispose();
|
||||
}
|
||||
|
||||
coordList.Clear();
|
||||
instanceList.Clear();
|
||||
scalingList.Clear();
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
foreach (IInstancing item in instanceList) {
|
||||
yield return (T)item;
|
||||
}
|
||||
}
|
||||
|
||||
IGeometry IInstancingBuffer.TypicalShape => throw new NotImplementedException();
|
||||
|
||||
#region field of mem opt
|
||||
|
||||
private Vec4[] coordArray;
|
||||
private float[] scaleArray;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Parallelogram"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class Parallelogram : Polygon4
|
||||
{
|
||||
|
||||
internal readonly Func<int, Vec3> movCenterOperation = GeometryOperation.DefaultMotion;
|
||||
|
||||
internal Point center;
|
||||
|
||||
public Parallelogram(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
|
||||
: base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
#if DEBUG
|
||||
if (this[0].Coord + this[2].Coord != this[1].Coord + this[3].Coord)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(
|
||||
"Init of geometry item failed, because four vertices cannot form a rectangle.",
|
||||
LogType.Warning);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public Parallelogram(
|
||||
PlainCoordinate coordination,
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y)
|
||||
: base(coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
#if DEBUG
|
||||
if (this[0].Coord + this[2].Coord != this[1].Coord + this[3].Coord)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(
|
||||
"Init of geometry item failed, because four vertices cannot form a rectangle.",
|
||||
LogType.Warning);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Parallelogram"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class Parallelogram : Polygon4
|
||||
{
|
||||
|
||||
internal readonly Func<int, Vec3> movCenterOperation = GeometryOperation.DefaultMotion;
|
||||
|
||||
internal Point center;
|
||||
|
||||
public Parallelogram(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
|
||||
: base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
#if DEBUG
|
||||
if (this[0].Coord + this[2].Coord != this[1].Coord + this[3].Coord)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(
|
||||
"Init of geometry item failed, because four vertices cannot form a rectangle.",
|
||||
LogType.Warning);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public Parallelogram(
|
||||
PlainCoordinate coordination,
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y)
|
||||
: base(coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
#if DEBUG
|
||||
if (this[0].Coord + this[2].Coord != this[1].Coord + this[3].Coord)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(
|
||||
"Init of geometry item failed, because four vertices cannot form a rectangle.",
|
||||
LogType.Warning);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Plain"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class Plain
|
||||
{
|
||||
|
||||
internal readonly float d = -1;
|
||||
internal Vec3 _origin;
|
||||
|
||||
internal Vec3 plainParameter;
|
||||
internal Vec3 vec1;
|
||||
internal Vec3 vec2;
|
||||
|
||||
public Plain(Vec3 o, Vec3 v1, Vec3 v2)
|
||||
{
|
||||
this._origin = o;
|
||||
this.vec1 = v1 - (v2 * (v1.Y / v2.Y)); //xz
|
||||
this.vec2 = v2 - (vec1 * (v2.X / v1.X)); //yz
|
||||
|
||||
// |_origin|-k1*|vec1|-k2*|vec2| --> plainParameter.Z;
|
||||
plainParameter.Z = _origin.Z - (vec1.Z * (_origin.X / vec1.X)) - (vec2.Z * (_origin.Y / vec2.Y));
|
||||
|
||||
// plainParameter.Z -> plainParameter.X, plainParameter.Y
|
||||
plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z);
|
||||
plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z);
|
||||
|
||||
plainParameter.X = 1 / plainParameter.X;
|
||||
plainParameter.Y = 1 / plainParameter.Y;
|
||||
plainParameter.Z = 1 / plainParameter.Z;
|
||||
}
|
||||
|
||||
public Plain(Point p1, Point p2, Point p3)
|
||||
{
|
||||
Vec3 origin = p1.Coord;
|
||||
Vec3 v1 = p2.Coord - origin;
|
||||
Vec3 v2 = p3.Coord - origin;
|
||||
|
||||
|
||||
vec1 = v1 - (v2 * (v1.Y / v2.Y)); //xz
|
||||
vec2 = v2 - (vec1 * (v2.X / v1.X)); //yz
|
||||
|
||||
// |_origin|-k1*|vec1|-k2*|vec2| --> plainParameter.Z;
|
||||
plainParameter.Z = origin.Z - (vec1.Z * (origin.X / vec1.X)) - (vec2.Z * (origin.Y / vec2.Y));
|
||||
|
||||
// plainParameter.Z --> plainParameter.X, plainParameter.Y
|
||||
plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z);
|
||||
plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z);
|
||||
|
||||
plainParameter.X = 1 / plainParameter.X;
|
||||
plainParameter.Y = 1 / plainParameter.Y;
|
||||
plainParameter.Z = 1 / plainParameter.Z;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Plain"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class Plain
|
||||
{
|
||||
|
||||
internal readonly float d = -1;
|
||||
internal Vec3 _origin;
|
||||
|
||||
internal Vec3 plainParameter;
|
||||
internal Vec3 vec1;
|
||||
internal Vec3 vec2;
|
||||
|
||||
public Plain(Vec3 o, Vec3 v1, Vec3 v2)
|
||||
{
|
||||
this._origin = o;
|
||||
this.vec1 = v1 - (v2 * (v1.Y / v2.Y)); //xz
|
||||
this.vec2 = v2 - (vec1 * (v2.X / v1.X)); //yz
|
||||
|
||||
// |_origin|-k1*|vec1|-k2*|vec2| --> plainParameter.Z;
|
||||
plainParameter.Z = _origin.Z - (vec1.Z * (_origin.X / vec1.X)) - (vec2.Z * (_origin.Y / vec2.Y));
|
||||
|
||||
// plainParameter.Z -> plainParameter.X, plainParameter.Y
|
||||
plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z);
|
||||
plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z);
|
||||
|
||||
plainParameter.X = 1 / plainParameter.X;
|
||||
plainParameter.Y = 1 / plainParameter.Y;
|
||||
plainParameter.Z = 1 / plainParameter.Z;
|
||||
}
|
||||
|
||||
public Plain(Point p1, Point p2, Point p3)
|
||||
{
|
||||
Vec3 origin = p1.Coord;
|
||||
Vec3 v1 = p2.Coord - origin;
|
||||
Vec3 v2 = p3.Coord - origin;
|
||||
|
||||
|
||||
vec1 = v1 - (v2 * (v1.Y / v2.Y)); //xz
|
||||
vec2 = v2 - (vec1 * (v2.X / v1.X)); //yz
|
||||
|
||||
// |_origin|-k1*|vec1|-k2*|vec2| --> plainParameter.Z;
|
||||
plainParameter.Z = origin.Z - (vec1.Z * (origin.X / vec1.X)) - (vec2.Z * (origin.Y / vec2.Y));
|
||||
|
||||
// plainParameter.Z --> plainParameter.X, plainParameter.Y
|
||||
plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z);
|
||||
plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z);
|
||||
|
||||
plainParameter.X = 1 / plainParameter.X;
|
||||
plainParameter.Y = 1 / plainParameter.Y;
|
||||
plainParameter.Z = 1 / plainParameter.Z;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,121 +1,121 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Polygon4"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class Polygon4 : PlainGeometry
|
||||
{
|
||||
|
||||
protected static int[] Indices = [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
2,
|
||||
3
|
||||
];
|
||||
|
||||
internal Polygon4()
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[4];
|
||||
}
|
||||
|
||||
internal Polygon4(Vec4[] rawCoord)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
if (rawCoord.Length != 4) {
|
||||
throw new ArgumentOutOfRangeException(nameof(rawCoord));
|
||||
}
|
||||
vertexMat = rawCoord;
|
||||
}
|
||||
|
||||
public Polygon4(Point topLeft, Point topRight, Point bottomRight, Point bottomLeft)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = topLeft;
|
||||
this[1] = topRight;
|
||||
this[2] = bottomRight;
|
||||
this[3] = bottomLeft;
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
CoordinationBase coordinate,
|
||||
PlainCoordinate coordination,
|
||||
Point topLeft,
|
||||
Point topRight,
|
||||
Point bottomRight,
|
||||
Point bottomLeft)
|
||||
: base(coordinate)
|
||||
{
|
||||
this[0] = topLeft;
|
||||
this[1] = topRight;
|
||||
this[2] = bottomRight;
|
||||
this[3] = bottomLeft;
|
||||
}
|
||||
|
||||
public Polygon4(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[4];
|
||||
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
PlainCoordinate coordination,
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y)
|
||||
: base(coordination)
|
||||
{
|
||||
vertexMat = new Vec4[4];
|
||||
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Polygon4"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class Polygon4 : PlainGeometry
|
||||
{
|
||||
|
||||
protected static int[] Indices = [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
2,
|
||||
3
|
||||
];
|
||||
|
||||
internal Polygon4()
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[4];
|
||||
}
|
||||
|
||||
internal Polygon4(Vec4[] rawCoord)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
if (rawCoord.Length != 4) {
|
||||
throw new ArgumentOutOfRangeException(nameof(rawCoord));
|
||||
}
|
||||
vertexMat = rawCoord;
|
||||
}
|
||||
|
||||
public Polygon4(Point topLeft, Point topRight, Point bottomRight, Point bottomLeft)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = topLeft;
|
||||
this[1] = topRight;
|
||||
this[2] = bottomRight;
|
||||
this[3] = bottomLeft;
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
CoordinationBase coordinate,
|
||||
PlainCoordinate coordination,
|
||||
Point topLeft,
|
||||
Point topRight,
|
||||
Point bottomRight,
|
||||
Point bottomLeft)
|
||||
: base(coordinate)
|
||||
{
|
||||
this[0] = topLeft;
|
||||
this[1] = topRight;
|
||||
this[2] = bottomRight;
|
||||
this[3] = bottomLeft;
|
||||
}
|
||||
|
||||
public Polygon4(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[4];
|
||||
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
PlainCoordinate coordination,
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y)
|
||||
: base(coordination)
|
||||
{
|
||||
vertexMat = new Vec4[4];
|
||||
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Polygon5"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class Polygon5 : PlainGeometry
|
||||
{
|
||||
|
||||
internal static int[] Indices = [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
3,
|
||||
4
|
||||
];
|
||||
|
||||
public unsafe Polygon5()
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[5];
|
||||
}
|
||||
|
||||
public Polygon5(
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y,
|
||||
float v4x,
|
||||
float v4y)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[5];
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
this[4] = new Point(v4x, v4y, 0);
|
||||
}
|
||||
|
||||
public Polygon5(
|
||||
PlainCoordinate coordination,
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y,
|
||||
float v4x,
|
||||
float v4y)
|
||||
: base(coordination)
|
||||
{
|
||||
vertexMat = new Vec4[5];
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
this[4] = new Point(v4x, v4y, 0);
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Polygon5"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class Polygon5 : PlainGeometry
|
||||
{
|
||||
|
||||
internal static int[] Indices = [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
3,
|
||||
4
|
||||
];
|
||||
|
||||
public unsafe Polygon5()
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[5];
|
||||
}
|
||||
|
||||
public Polygon5(
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y,
|
||||
float v4x,
|
||||
float v4y)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[5];
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
this[4] = new Point(v4x, v4y, 0);
|
||||
}
|
||||
|
||||
public Polygon5(
|
||||
PlainCoordinate coordination,
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y,
|
||||
float v4x,
|
||||
float v4y)
|
||||
: base(coordination)
|
||||
{
|
||||
vertexMat = new Vec4[5];
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
this[4] = new Point(v4x, v4y, 0);
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +1,84 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Polygon6"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class Polygon6 : PlainGeometry
|
||||
{
|
||||
|
||||
internal static int[] Indices = [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
3,
|
||||
4,
|
||||
0,
|
||||
4,
|
||||
5
|
||||
];
|
||||
|
||||
public Polygon6()
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[6];
|
||||
}
|
||||
|
||||
public Polygon6(
|
||||
PlainCoordinate coordination,
|
||||
Vec2 vert0,
|
||||
Vec2 vert1,
|
||||
Vec2 vert2,
|
||||
Vec2 vert3,
|
||||
Vec2 vert4,
|
||||
Vec2 vert5,
|
||||
Vec2 vert6)
|
||||
: base(coordination)
|
||||
{
|
||||
vertexMat = new Vec4[6];
|
||||
vertexMat[0].reg = vert0.reg;
|
||||
vertexMat[1].reg = vert1.reg;
|
||||
vertexMat[2].reg = vert2.reg;
|
||||
vertexMat[3].reg = vert3.reg;
|
||||
vertexMat[4].reg = vert4.reg;
|
||||
vertexMat[5].reg = vert5.reg;
|
||||
vertexMat[6].reg = vert6.reg;
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Polygon6"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class Polygon6 : PlainGeometry
|
||||
{
|
||||
|
||||
internal static int[] Indices = [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
3,
|
||||
4,
|
||||
0,
|
||||
4,
|
||||
5
|
||||
];
|
||||
|
||||
public Polygon6()
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[6];
|
||||
}
|
||||
|
||||
public Polygon6(
|
||||
PlainCoordinate coordination,
|
||||
Vec2 vert0,
|
||||
Vec2 vert1,
|
||||
Vec2 vert2,
|
||||
Vec2 vert3,
|
||||
Vec2 vert4,
|
||||
Vec2 vert5,
|
||||
Vec2 vert6)
|
||||
: base(coordination)
|
||||
{
|
||||
vertexMat = new Vec4[6];
|
||||
vertexMat[0].reg = vert0.reg;
|
||||
vertexMat[1].reg = vert1.reg;
|
||||
vertexMat[2].reg = vert2.reg;
|
||||
vertexMat[3].reg = vert3.reg;
|
||||
vertexMat[4].reg = vert4.reg;
|
||||
vertexMat[5].reg = vert5.reg;
|
||||
vertexMat[6].reg = vert6.reg;
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,87 +1,87 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Rectangle"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class Rectangle : Parallelogram
|
||||
{
|
||||
|
||||
public Rectangle(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
|
||||
: base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
#if DEBUG
|
||||
Vec2 side0 = (this[0].Coord - this[1].Coord).XY;
|
||||
Vec2 side1 = (this[2].Coord - this[1].Coord).XY;
|
||||
if (side0.Cross(side1) == 0) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public Rectangle(
|
||||
PlainCoordinate coordination,
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y)
|
||||
: base(coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
#if DEBUG
|
||||
Vec2 side0 = (this[0].Coord - this[1].Coord).XY;
|
||||
Vec2 side1 = (this[2].Coord - this[1].Coord).XY;
|
||||
if (side0.Cross(side1) == 0) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate movement to center
|
||||
/// </summary>
|
||||
/// <param _label="tick">
|
||||
/// CurrentPipeline time tick
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public virtual Vec3 MovCenter(uint tick)
|
||||
{
|
||||
return default(Vec3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Rectangle"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class Rectangle : Parallelogram
|
||||
{
|
||||
|
||||
public Rectangle(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
|
||||
: base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
#if DEBUG
|
||||
Vec2 side0 = (this[0].Coord - this[1].Coord).XY;
|
||||
Vec2 side1 = (this[2].Coord - this[1].Coord).XY;
|
||||
if (side0.Cross(side1) == 0) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public Rectangle(
|
||||
PlainCoordinate coordination,
|
||||
float v0x,
|
||||
float v0y,
|
||||
float v1x,
|
||||
float v1y,
|
||||
float v2x,
|
||||
float v2y,
|
||||
float v3x,
|
||||
float v3y)
|
||||
: base(coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
#if DEBUG
|
||||
Vec2 side0 = (this[0].Coord - this[1].Coord).XY;
|
||||
Vec2 side1 = (this[2].Coord - this[1].Coord).XY;
|
||||
if (side0.Cross(side1) == 0) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate movement to center
|
||||
/// </summary>
|
||||
/// <param _label="tick">
|
||||
/// CurrentPipeline time tick
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public virtual Vec3 MovCenter(uint tick)
|
||||
{
|
||||
return default(Vec3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Square"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
/// <summary>
|
||||
/// A square
|
||||
/// </summary>
|
||||
public class Square : Rectangle
|
||||
{
|
||||
|
||||
public Square(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
|
||||
: base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
if (true) { }
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Square"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
/// <summary>
|
||||
/// A square
|
||||
/// </summary>
|
||||
public class Square : Rectangle
|
||||
{
|
||||
|
||||
public Square(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
|
||||
: base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
|
||||
{
|
||||
if (true) { }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,87 +1,87 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Triangle"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class Triangle : PlainGeometry
|
||||
{
|
||||
|
||||
internal static int[] Indices = [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
];
|
||||
|
||||
public Triangle()
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[3];
|
||||
}
|
||||
|
||||
public Triangle(Point vertex01, Point vertex02, Point vertex03)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = vertex01;
|
||||
this[1] = vertex02;
|
||||
this[2] = vertex03;
|
||||
}
|
||||
|
||||
public Triangle(PlainCoordinate coordination, Point vertex01, Point vertex02, Point vertex03)
|
||||
: base(coordination)
|
||||
{
|
||||
this[0] = vertex01;
|
||||
this[1] = vertex02;
|
||||
this[2] = vertex03;
|
||||
}
|
||||
|
||||
public Triangle(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
}
|
||||
|
||||
public Triangle(PlainCoordinate coordination, float v0x, float v0y, float v1x, float v1y, float v2x, float v2y)
|
||||
: base(coordination)
|
||||
{
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Triangle"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class Triangle : PlainGeometry
|
||||
{
|
||||
|
||||
internal static int[] Indices = [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
];
|
||||
|
||||
public Triangle()
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new Vec4[3];
|
||||
}
|
||||
|
||||
public Triangle(Point vertex01, Point vertex02, Point vertex03)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = vertex01;
|
||||
this[1] = vertex02;
|
||||
this[2] = vertex03;
|
||||
}
|
||||
|
||||
public Triangle(PlainCoordinate coordination, Point vertex01, Point vertex02, Point vertex03)
|
||||
: base(coordination)
|
||||
{
|
||||
this[0] = vertex01;
|
||||
this[1] = vertex02;
|
||||
this[2] = vertex03;
|
||||
}
|
||||
|
||||
public Triangle(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y)
|
||||
: base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
}
|
||||
|
||||
public Triangle(PlainCoordinate coordination, float v0x, float v0y, float v1x, float v1y, float v2x, float v2y)
|
||||
: base(coordination)
|
||||
{
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Point"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
public struct Point
|
||||
{
|
||||
|
||||
[FieldOffset(0)] private Vec3 coord;
|
||||
[FieldOffset(0)] internal Vector4 coordVec;
|
||||
|
||||
internal Point(Vec4 vector)
|
||||
{
|
||||
coordVec = vector.vec;
|
||||
coordVec.W = 1;
|
||||
}
|
||||
|
||||
public Point(Vec3 coord)
|
||||
{
|
||||
Coord = coord;
|
||||
coordVec.W = 1;
|
||||
}
|
||||
|
||||
public Point(float x, float y, float z)
|
||||
{
|
||||
coordVec = new Vector4(x, y, z, 1);
|
||||
}
|
||||
|
||||
public Vec3 Coord
|
||||
{
|
||||
get => coord;
|
||||
set { coord = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Point"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
public struct Point
|
||||
{
|
||||
|
||||
[FieldOffset(0)] private Vec3 coord;
|
||||
[FieldOffset(0)] internal Vector4 coordVec;
|
||||
|
||||
internal Point(Vec4 vector)
|
||||
{
|
||||
coordVec = vector.vec;
|
||||
coordVec.W = 1;
|
||||
}
|
||||
|
||||
public Point(Vec3 coord)
|
||||
{
|
||||
Coord = coord;
|
||||
coordVec.W = 1;
|
||||
}
|
||||
|
||||
public Point(float x, float y, float z)
|
||||
{
|
||||
coordVec = new Vector4(x, y, z, 1);
|
||||
}
|
||||
|
||||
public Vec3 Coord
|
||||
{
|
||||
get => coord;
|
||||
set { coord = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Class1"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries.SpaceGeometry
|
||||
{
|
||||
internal class Class1 { }
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Class1"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries.SpaceGeometry
|
||||
{
|
||||
internal class Class1 { }
|
||||
}
|
||||
|
||||
@@ -1,146 +1,146 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TriangulatedSurface"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class TriangulatedSurface
|
||||
{
|
||||
|
||||
private HashSet<(int begin,int end)> _sides;
|
||||
|
||||
private List<List<int>> _sideIndices;
|
||||
private List<int> _triangleIndices;
|
||||
private List<Vec3> _vertices;
|
||||
|
||||
public TriangulatedSurface()
|
||||
{
|
||||
_triangleIndices = new List<int>();
|
||||
_vertices = new List<Vec3>();
|
||||
_sides = new HashSet<(int,int)>();
|
||||
_sideIndices = new List<List<int>>();
|
||||
}
|
||||
|
||||
/**/
|
||||
public IEnumerable<List<int>> SideIndicesEnumeratble
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _sideIndices ;
|
||||
}
|
||||
|
||||
/*
|
||||
public Triangle GetTriangle( int index )
|
||||
{
|
||||
Vec3HP v1,v2,v3;
|
||||
int t = index * 3;
|
||||
v1 = _vertices[ t + 0 ];
|
||||
v2 = _vertices[ t + 1 ];
|
||||
v3 = _vertices[ t + 2 ];
|
||||
return new Triangle( v1, v2, v3 );
|
||||
}
|
||||
/**/
|
||||
|
||||
public Span<Vec3> VertexSpan
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CollectionsMarshal.AsSpan(_vertices);
|
||||
}
|
||||
|
||||
public Span<int> TriangleIndicesSpan
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CollectionsMarshal.AsSpan(_triangleIndices);
|
||||
}
|
||||
|
||||
/**/
|
||||
public void AddIndicesByOrder(int v1, int v2, int v3)
|
||||
{
|
||||
_triangleIndices.Add(v1);
|
||||
_triangleIndices.Add(v2);
|
||||
_triangleIndices.Add(v3);
|
||||
if (!(_sides.Remove((v1,v2)) || _sides.Remove((v2, v1)))) {
|
||||
_ = _sides.Add((v1, v2));
|
||||
}
|
||||
if (!(_sides.Remove((v2, v3)) || _sides.Remove((v3, v2)))) {
|
||||
_ = _sides.Add((v2, v3));
|
||||
}
|
||||
if (!(_sides.Remove((v3, v1)) || _sides.Remove((v1, v3)))) {
|
||||
_ = _sides.Add((v3, v1));
|
||||
}
|
||||
}
|
||||
|
||||
public void AddVertexByOrder(Vec3 vertex)
|
||||
{
|
||||
_vertices.Add(vertex);
|
||||
}
|
||||
|
||||
public int TriangleCount()
|
||||
{
|
||||
return _triangleIndices.Count / 3;
|
||||
}
|
||||
|
||||
public void TrimExcess()
|
||||
{
|
||||
_triangleIndices.TrimExcess();
|
||||
_vertices.TrimExcess();
|
||||
Dictionary<int, int> side_dictionary = _sides.ToDictionary(x => x.begin, x => x.end);
|
||||
int begin = side_dictionary.First().Key;
|
||||
List<int> sideLoop = new(begin);
|
||||
_sideIndices.Add(sideLoop);
|
||||
while (side_dictionary.Count > 0)
|
||||
{
|
||||
if (side_dictionary.Remove(begin, out begin))
|
||||
{
|
||||
sideLoop.Add(begin);
|
||||
} else
|
||||
{
|
||||
begin = side_dictionary.First().Key;
|
||||
sideLoop = new List<int>(begin);
|
||||
_sideIndices.Add(sideLoop);
|
||||
}
|
||||
}
|
||||
_sideIndices.TrimExcess();
|
||||
}
|
||||
|
||||
public int VertexCount()
|
||||
{
|
||||
return _vertices.Count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TriangulatedSurface"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class TriangulatedSurface
|
||||
{
|
||||
|
||||
private HashSet<(int begin,int end)> _sides;
|
||||
|
||||
private List<List<int>> _sideIndices;
|
||||
private List<int> _triangleIndices;
|
||||
private List<Vec3> _vertices;
|
||||
|
||||
public TriangulatedSurface()
|
||||
{
|
||||
_triangleIndices = new List<int>();
|
||||
_vertices = new List<Vec3>();
|
||||
_sides = new HashSet<(int,int)>();
|
||||
_sideIndices = new List<List<int>>();
|
||||
}
|
||||
|
||||
/**/
|
||||
public IEnumerable<List<int>> SideIndicesEnumeratble
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _sideIndices ;
|
||||
}
|
||||
|
||||
/*
|
||||
public Triangle GetTriangle( int index )
|
||||
{
|
||||
Vec3HP v1,v2,v3;
|
||||
int t = index * 3;
|
||||
v1 = _vertices[ t + 0 ];
|
||||
v2 = _vertices[ t + 1 ];
|
||||
v3 = _vertices[ t + 2 ];
|
||||
return new Triangle( v1, v2, v3 );
|
||||
}
|
||||
/**/
|
||||
|
||||
public Span<Vec3> VertexSpan
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CollectionsMarshal.AsSpan(_vertices);
|
||||
}
|
||||
|
||||
public Span<int> TriangleIndicesSpan
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => CollectionsMarshal.AsSpan(_triangleIndices);
|
||||
}
|
||||
|
||||
/**/
|
||||
public void AddIndicesByOrder(int v1, int v2, int v3)
|
||||
{
|
||||
_triangleIndices.Add(v1);
|
||||
_triangleIndices.Add(v2);
|
||||
_triangleIndices.Add(v3);
|
||||
if (!(_sides.Remove((v1,v2)) || _sides.Remove((v2, v1)))) {
|
||||
_ = _sides.Add((v1, v2));
|
||||
}
|
||||
if (!(_sides.Remove((v2, v3)) || _sides.Remove((v3, v2)))) {
|
||||
_ = _sides.Add((v2, v3));
|
||||
}
|
||||
if (!(_sides.Remove((v3, v1)) || _sides.Remove((v1, v3)))) {
|
||||
_ = _sides.Add((v3, v1));
|
||||
}
|
||||
}
|
||||
|
||||
public void AddVertexByOrder(Vec3 vertex)
|
||||
{
|
||||
_vertices.Add(vertex);
|
||||
}
|
||||
|
||||
public int TriangleCount()
|
||||
{
|
||||
return _triangleIndices.Count / 3;
|
||||
}
|
||||
|
||||
public void TrimExcess()
|
||||
{
|
||||
_triangleIndices.TrimExcess();
|
||||
_vertices.TrimExcess();
|
||||
Dictionary<int, int> side_dictionary = _sides.ToDictionary(x => x.begin, x => x.end);
|
||||
int begin = side_dictionary.First().Key;
|
||||
List<int> sideLoop = new(begin);
|
||||
_sideIndices.Add(sideLoop);
|
||||
while (side_dictionary.Count > 0)
|
||||
{
|
||||
if (side_dictionary.Remove(begin, out begin))
|
||||
{
|
||||
sideLoop.Add(begin);
|
||||
} else
|
||||
{
|
||||
begin = side_dictionary.First().Key;
|
||||
sideLoop = new List<int>(begin);
|
||||
_sideIndices.Add(sideLoop);
|
||||
}
|
||||
}
|
||||
_sideIndices.TrimExcess();
|
||||
}
|
||||
|
||||
public int VertexCount()
|
||||
{
|
||||
return _vertices.Count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+98
-98
@@ -1,98 +1,98 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Global"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
global using StgSharp.Internal;
|
||||
global using StgSharp.Internal.Intrinsic;
|
||||
global
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("StgSharp.Mathematics")]
|
||||
[assembly: InternalsVisibleTo("StgSharp.RegularAnalysis")]
|
||||
[assembly: InternalsVisibleTo("StgSharpDebug")]
|
||||
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1008:枚举应具有零值",
|
||||
Justification = "<挂起>",
|
||||
Scope = "type",
|
||||
Target = "~T:StgSharp.Graphics.OpenGL.ShaderStatus")]
|
||||
[assembly: SuppressMessage(
|
||||
"Naming",
|
||||
"CA1715:标识符应具有正确的前缀",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``2(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1}")]
|
||||
[assembly: SuppressMessage(
|
||||
"Naming",
|
||||
"CA1715:标识符应具有正确的前缀",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``3(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2}")]
|
||||
[assembly: SuppressMessage(
|
||||
"Naming",
|
||||
"CA1715:标识符应具有正确的前缀",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``4(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2,``3}")]
|
||||
[assembly: SuppressMessage(
|
||||
"Naming",
|
||||
"CA1715:标识符应具有正确的前缀",
|
||||
Justification = "<挂起>",
|
||||
Scope = "type",
|
||||
Target = "~T:StgSharp.Graphics.OpenGL.Uniform`4")]
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1043:将整型或字符串参数用于索引器",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.MVVM.ViewBase.IViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1043:将整型或字符串参数用于索引器",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.MVVM.ViewBase.ViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
|
||||
[assembly: SuppressMessage(
|
||||
"Performance",
|
||||
"CA1864:首选 \"IDictionary.TryAdd(TKey, TValue)\" 方法",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.MVVM.ViewBase.ViewRender`1.Item(System.String)")]
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1033:接口方法应可由子类型调用",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Keys")]
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1033:接口方法应可由子类型调用",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Values")]
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Global"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
global using StgSharp.Internal;
|
||||
global using StgSharp.Internal.Intrinsic;
|
||||
global
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("StgSharp.Mathematics")]
|
||||
[assembly: InternalsVisibleTo("StgSharp.RegularAnalysis")]
|
||||
[assembly: InternalsVisibleTo("StgSharpDebug")]
|
||||
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1008:枚举应具有零值",
|
||||
Justification = "<挂起>",
|
||||
Scope = "type",
|
||||
Target = "~T:StgSharp.Graphics.OpenGL.ShaderStatus")]
|
||||
[assembly: SuppressMessage(
|
||||
"Naming",
|
||||
"CA1715:标识符应具有正确的前缀",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``2(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1}")]
|
||||
[assembly: SuppressMessage(
|
||||
"Naming",
|
||||
"CA1715:标识符应具有正确的前缀",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``3(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2}")]
|
||||
[assembly: SuppressMessage(
|
||||
"Naming",
|
||||
"CA1715:标识符应具有正确的前缀",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``4(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2,``3}")]
|
||||
[assembly: SuppressMessage(
|
||||
"Naming",
|
||||
"CA1715:标识符应具有正确的前缀",
|
||||
Justification = "<挂起>",
|
||||
Scope = "type",
|
||||
Target = "~T:StgSharp.Graphics.OpenGL.Uniform`4")]
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1043:将整型或字符串参数用于索引器",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.MVVM.ViewBase.IViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1043:将整型或字符串参数用于索引器",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.MVVM.ViewBase.ViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
|
||||
[assembly: SuppressMessage(
|
||||
"Performance",
|
||||
"CA1864:首选 \"IDictionary.TryAdd(TKey, TValue)\" 方法",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.MVVM.ViewBase.ViewRender`1.Item(System.String)")]
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1033:接口方法应可由子类型调用",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Keys")]
|
||||
[assembly: SuppressMessage(
|
||||
"Design",
|
||||
"CA1033:接口方法应可由子类型调用",
|
||||
Justification = "<挂起>",
|
||||
Scope = "member",
|
||||
Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Values")]
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IImageProvider"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IImageProvider
|
||||
{
|
||||
|
||||
Image ProvideImage();
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IImageProvider"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IImageProvider
|
||||
{
|
||||
|
||||
Image ProvideImage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ImageHelper"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public static class ImageHelper
|
||||
{
|
||||
|
||||
public static void Resize(Image i, int width, int height, ImageMovement move)
|
||||
{
|
||||
if (i == null) {
|
||||
throw new ArgumentNullException(nameof(i));
|
||||
}
|
||||
if (i.Size == (width, height)) {
|
||||
return;
|
||||
}
|
||||
if (!Enum.IsDefined(typeof(ImageMovement), move)) {
|
||||
throw new InvalidEnumArgumentException(nameof(move));
|
||||
}
|
||||
byte[] oldData = i.Data;
|
||||
i.Data = new byte[width * height * i.PixelSize];
|
||||
i.Height = height;
|
||||
i.Width = width;
|
||||
i.PixelUpdateCount++;
|
||||
switch (move)
|
||||
{
|
||||
case ImageMovement.Discard:
|
||||
break;
|
||||
case ImageMovement.Top:
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ImageMovement
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
Discard = 0,
|
||||
#pragma warning restore CA1008
|
||||
Top = 1,
|
||||
Bottom = 2,
|
||||
Left = 4,
|
||||
Right = 8,
|
||||
TopLeft = Top | Left,
|
||||
BottomLeft = Bottom | Left,
|
||||
TopRight = Top | Right,
|
||||
BottomRight = Bottom | Right,
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ImageHelper"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public static class ImageHelper
|
||||
{
|
||||
|
||||
public static void Resize(Image i, int width, int height, ImageMovement move)
|
||||
{
|
||||
if (i == null) {
|
||||
throw new ArgumentNullException(nameof(i));
|
||||
}
|
||||
if (i.Size == (width, height)) {
|
||||
return;
|
||||
}
|
||||
if (!Enum.IsDefined(typeof(ImageMovement), move)) {
|
||||
throw new InvalidEnumArgumentException(nameof(move));
|
||||
}
|
||||
byte[] oldData = i.Data;
|
||||
i.Data = new byte[width * height * i.PixelSize];
|
||||
i.Height = height;
|
||||
i.Width = width;
|
||||
i.PixelUpdateCount++;
|
||||
switch (move)
|
||||
{
|
||||
case ImageMovement.Discard:
|
||||
break;
|
||||
case ImageMovement.Top:
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ImageMovement
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
Discard = 0,
|
||||
#pragma warning restore CA1008
|
||||
Top = 1,
|
||||
Bottom = 2,
|
||||
Left = 4,
|
||||
Right = 8,
|
||||
TopLeft = Top | Left,
|
||||
BottomLeft = Bottom | Left,
|
||||
TopRight = Top | Right,
|
||||
BottomRight = Bottom | Right,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="BufferObjectBase"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface of all kinds OpenGL BufferHandle objects
|
||||
/// </summary>
|
||||
public abstract class BufferObjectBase : IDisposable
|
||||
{
|
||||
|
||||
protected GlHandle[] _bufferHandle;
|
||||
protected RenderStream binding;
|
||||
|
||||
/// <summary>
|
||||
/// Get the only handle to one of the Object instance
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
///
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public GlHandle this[int index] => _bufferHandle[index];
|
||||
|
||||
/// <summary>
|
||||
/// Bind a BufferHandle instance to OpenGL
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
/// Index of handle of the object in this instance to be bind
|
||||
/// </param>
|
||||
public abstract void Bind(int index);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing:true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {GetType().FullName}, containing {_bufferHandle.Length} buffer handles: {_bufferHandle.ToString()}.";
|
||||
}
|
||||
|
||||
protected abstract void Dispose(bool disposing);
|
||||
|
||||
~BufferObjectBase()
|
||||
{
|
||||
Dispose(disposing:false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="BufferObjectBase"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface of all kinds OpenGL BufferHandle objects
|
||||
/// </summary>
|
||||
public abstract class BufferObjectBase : IDisposable
|
||||
{
|
||||
|
||||
protected GlHandle[] _bufferHandle;
|
||||
protected RenderStream binding;
|
||||
|
||||
/// <summary>
|
||||
/// Get the only handle to one of the Object instance
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
///
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public GlHandle this[int index] => _bufferHandle[index];
|
||||
|
||||
/// <summary>
|
||||
/// Bind a BufferHandle instance to OpenGL
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
/// Index of handle of the object in this instance to be bind
|
||||
/// </param>
|
||||
public abstract void Bind(int index);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing:true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {GetType().FullName}, containing {_bufferHandle.Length} buffer handles: {_bufferHandle.ToString()}.";
|
||||
}
|
||||
|
||||
protected abstract void Dispose(bool disposing);
|
||||
|
||||
~BufferObjectBase()
|
||||
{
|
||||
Dispose(disposing:false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,336 +1,336 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="FrameworkConstant"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public static class FrameworkConstant
|
||||
{
|
||||
|
||||
#region glfw
|
||||
|
||||
public const int VERSION_MAJOR = 3;
|
||||
public const int VERSION_MINOR = 3;
|
||||
public const int VERSION_REVISION = 8;
|
||||
public const int TRUE = 1;
|
||||
public const int FALSE = 0;
|
||||
public const int RELEASE = 0;
|
||||
public const int PRESS = 1;
|
||||
public const int REPEAT = 2;
|
||||
public const int HAT_CENTERED = 0;
|
||||
public const int HAT_UP = 1;
|
||||
public const int HAT_RIGHT = 2;
|
||||
public const int HAT_DOWN = 4;
|
||||
public const int HAT_LEFT = 8;
|
||||
public const int HAT_RIGHT_UP = HAT_RIGHT | HAT_UP;
|
||||
public const int HAT_RIGHT_DOWN = HAT_RIGHT | HAT_DOWN;
|
||||
public const int HAT_LEFT_UP = HAT_LEFT | HAT_UP;
|
||||
public const int HAT_LEFT_DOWN = HAT_LEFT | HAT_DOWN;
|
||||
public const int KEY_UNKNOWN = -1;
|
||||
public const int KEY_SPACE = 32;
|
||||
public const int KEY_APOSTROPHE = 39;
|
||||
public const int KEY_COMMA = 44;
|
||||
public const int KEY_MINUS = 45;
|
||||
public const int KEY_PERIOD = 46;
|
||||
public const int KEY_SLASH = 47;
|
||||
public const int KEY_0 = 48;
|
||||
public const int KEY_1 = 49;
|
||||
public const int KEY_2 = 50;
|
||||
public const int KEY_3 = 51;
|
||||
public const int KEY_4 = 52;
|
||||
public const int KEY_5 = 53;
|
||||
public const int KEY_6 = 54;
|
||||
public const int KEY_7 = 55;
|
||||
public const int KEY_8 = 56;
|
||||
public const int KEY_9 = 57;
|
||||
public const int KEY_SEMICOLON = 59;
|
||||
public const int KEY_EQUAL = 61;
|
||||
public const int KEY_A = 65;
|
||||
public const int KEY_B = 66;
|
||||
public const int KEY_C = 67;
|
||||
public const int KEY_D = 68;
|
||||
public const int KEY_E = 69;
|
||||
public const int KEY_F = 70;
|
||||
public const int KEY_G = 71;
|
||||
public const int KEY_H = 72;
|
||||
public const int KEY_I = 73;
|
||||
public const int KEY_J = 74;
|
||||
public const int KEY_K = 75;
|
||||
public const int KEY_L = 76;
|
||||
public const int KEY_M = 77;
|
||||
public const int KEY_N = 78;
|
||||
public const int KEY_O = 79;
|
||||
public const int KEY_P = 80;
|
||||
public const int KEY_Q = 81;
|
||||
public const int KEY_R = 82;
|
||||
public const int KEY_S = 83;
|
||||
public const int KEY_T = 84;
|
||||
public const int KEY_U = 85;
|
||||
public const int KEY_V = 86;
|
||||
public const int KEY_W = 87;
|
||||
public const int KEY_X = 88;
|
||||
public const int KEY_Y = 89;
|
||||
public const int KEY_Z = 90;
|
||||
public const int KEY_LEFT_BRACKET = 91;
|
||||
public const int KEY_BACKSLASH = 92;
|
||||
public const int KEY_RIGHT_BRACKET = 93;
|
||||
public const int KEY_GRAVE_ACCENT = 96;
|
||||
public const int KEY_WORLD_1 = 161;
|
||||
public const int KEY_WORLD_2 = 162;
|
||||
public const int KEY_ESCAPE = 256;
|
||||
public const int KEY_ENTER = 257;
|
||||
public const int KEY_TAB = 258;
|
||||
public const int KEY_BACKSPACE = 259;
|
||||
public const int KEY_INSERT = 260;
|
||||
public const int KEY_DELETE = 261;
|
||||
public const int KEY_RIGHT = 262;
|
||||
public const int KEY_LEFT = 263;
|
||||
public const int KEY_DOWN = 264;
|
||||
public const int KEY_UP = 265;
|
||||
public const int KEY_PAGE_UP = 266;
|
||||
public const int KEY_PAGE_DOWN = 267;
|
||||
public const int KEY_HOME = 268;
|
||||
public const int KEY_END = 269;
|
||||
public const int KEY_CAPS_LOCK = 280;
|
||||
public const int KEY_SCROLL_LOCK = 281;
|
||||
public const int KEY_NUM_LOCK = 282;
|
||||
public const int KEY_PRINT_SCREEN = 283;
|
||||
public const int KEY_PAUSE = 284;
|
||||
public const int KEY_F1 = 290;
|
||||
public const int KEY_F2 = 291;
|
||||
public const int KEY_F3 = 292;
|
||||
public const int KEY_F4 = 293;
|
||||
public const int KEY_F5 = 294;
|
||||
public const int KEY_F6 = 295;
|
||||
public const int KEY_F7 = 296;
|
||||
public const int KEY_F8 = 297;
|
||||
public const int KEY_F9 = 298;
|
||||
public const int KEY_F10 = 299;
|
||||
public const int KEY_F11 = 300;
|
||||
public const int KEY_F12 = 301;
|
||||
public const int KEY_F13 = 302;
|
||||
public const int KEY_F14 = 303;
|
||||
public const int KEY_F15 = 304;
|
||||
public const int KEY_F16 = 305;
|
||||
public const int KEY_F17 = 306;
|
||||
public const int KEY_F18 = 307;
|
||||
public const int KEY_F19 = 308;
|
||||
public const int KEY_F20 = 309;
|
||||
public const int KEY_F21 = 310;
|
||||
public const int KEY_F22 = 311;
|
||||
public const int KEY_F23 = 312;
|
||||
public const int KEY_F24 = 313;
|
||||
public const int KEY_F25 = 314;
|
||||
public const int KEY_KP_0 = 320;
|
||||
public const int KEY_KP_1 = 321;
|
||||
public const int KEY_KP_2 = 322;
|
||||
public const int KEY_KP_3 = 323;
|
||||
public const int KEY_KP_4 = 324;
|
||||
public const int KEY_KP_5 = 325;
|
||||
public const int KEY_KP_6 = 326;
|
||||
public const int KEY_KP_7 = 327;
|
||||
public const int KEY_KP_8 = 328;
|
||||
public const int KEY_KP_9 = 329;
|
||||
public const int KEY_KP_DECIMAL = 330;
|
||||
public const int KEY_KP_DIVIDE = 331;
|
||||
public const int KEY_KP_MULTIPLY = 332;
|
||||
public const int KEY_KP_SUBTRACT = 333;
|
||||
public const int KEY_KP_ADD = 334;
|
||||
public const int KEY_KP_ENTER = 335;
|
||||
public const int KEY_KP_EQUAL = 336;
|
||||
public const int KEY_LEFT_SHIFT = 340;
|
||||
public const int KEY_LEFT_CONTROL = 341;
|
||||
public const int KEY_LEFT_ALT = 342;
|
||||
public const int KEY_LEFT_SUPER = 343;
|
||||
public const int KEY_RIGHT_SHIFT = 344;
|
||||
public const int KEY_RIGHT_CONTROL = 345;
|
||||
public const int KEY_RIGHT_ALT = 346;
|
||||
public const int KEY_RIGHT_SUPER = 347;
|
||||
public const int KEY_MENU = 348;
|
||||
public const int KEY_LAST = KEY_MENU;
|
||||
public const int MOD_SHIFT = 0x0001;
|
||||
public const int MOD_CONTROL = 0x0002;
|
||||
public const int MOD_ALT = 0x0004;
|
||||
public const int MOD_SUPER = 0x0008;
|
||||
public const int MOD_CAPS_LOCK = 0x0010;
|
||||
public const int MOD_NUM_LOCK = 0x0020;
|
||||
public const int MOUSE_BUTTON_1 = 0;
|
||||
public const int MOUSE_BUTTON_2 = 1;
|
||||
public const int MOUSE_BUTTON_3 = 2;
|
||||
public const int MOUSE_BUTTON_4 = 3;
|
||||
public const int MOUSE_BUTTON_5 = 4;
|
||||
public const int MOUSE_BUTTON_6 = 5;
|
||||
public const int MOUSE_BUTTON_7 = 6;
|
||||
public const int MOUSE_BUTTON_8 = 7;
|
||||
public const int MOUSE_BUTTON_LAST = MOUSE_BUTTON_8;
|
||||
public const int MOUSE_BUTTON_LEFT = MOUSE_BUTTON_1;
|
||||
public const int MOUSE_BUTTON_RIGHT = MOUSE_BUTTON_2;
|
||||
public const int MOUSE_BUTTON_MIDDLE = MOUSE_BUTTON_3;
|
||||
public const int JOYSTICK_1 = 0;
|
||||
public const int JOYSTICK_2 = 1;
|
||||
public const int JOYSTICK_3 = 2;
|
||||
public const int JOYSTICK_4 = 3;
|
||||
public const int JOYSTICK_5 = 4;
|
||||
public const int JOYSTICK_6 = 5;
|
||||
public const int JOYSTICK_7 = 6;
|
||||
public const int JOYSTICK_8 = 7;
|
||||
public const int JOYSTICK_9 = 8;
|
||||
public const int JOYSTICK_10 = 9;
|
||||
public const int JOYSTICK_11 = 10;
|
||||
public const int JOYSTICK_12 = 11;
|
||||
public const int JOYSTICK_13 = 12;
|
||||
public const int JOYSTICK_14 = 13;
|
||||
public const int JOYSTICK_15 = 14;
|
||||
public const int JOYSTICK_16 = 15;
|
||||
public const int JOYSTICK_LAST = JOYSTICK_16;
|
||||
public const int GAMEPAD_BUTTON_A = 0;
|
||||
public const int GAMEPAD_BUTTON_B = 1;
|
||||
public const int GAMEPAD_BUTTON_X = 2;
|
||||
public const int GAMEPAD_BUTTON_Y = 3;
|
||||
public const int GAMEPAD_BUTTON_LEFT_BUMPER = 4;
|
||||
public const int GAMEPAD_BUTTON_RIGHT_BUMPER = 5;
|
||||
public const int GAMEPAD_BUTTON_BACK = 6;
|
||||
public const int GAMEPAD_BUTTON_START = 7;
|
||||
public const int GAMEPAD_BUTTON_GUIDE = 8;
|
||||
public const int GAMEPAD_BUTTON_LEFT_THUMB = 9;
|
||||
public const int GAMEPAD_BUTTON_RIGHT_THUMB = 10;
|
||||
public const int GAMEPAD_BUTTON_DPAD_UP = 11;
|
||||
public const int GAMEPAD_BUTTON_DPAD_RIGHT = 12;
|
||||
public const int GAMEPAD_BUTTON_DPAD_DOWN = 13;
|
||||
public const int GAMEPAD_BUTTON_DPAD_LEFT = 14;
|
||||
public const int GAMEPAD_BUTTON_LAST = GAMEPAD_BUTTON_DPAD_LEFT;
|
||||
public const int GAMEPAD_BUTTON_CROSS = GAMEPAD_BUTTON_A;
|
||||
public const int GAMEPAD_BUTTON_CIRCLE = GAMEPAD_BUTTON_B;
|
||||
public const int GAMEPAD_BUTTON_SQUARE = GAMEPAD_BUTTON_X;
|
||||
public const int GAMEPAD_BUTTON_TRIANGLE = GAMEPAD_BUTTON_Y;
|
||||
public const int GAMEPAD_AXIS_LEFT_X = 0;
|
||||
public const int GAMEPAD_AXIS_LEFT_Y = 1;
|
||||
public const int GAMEPAD_AXIS_RIGHT_X = 2;
|
||||
public const int GAMEPAD_AXIS_RIGHT_Y = 3;
|
||||
public const int GAMEPAD_AXIS_LEFT_TRIGGER = 4;
|
||||
public const int GAMEPAD_AXIS_RIGHT_TRIGGER = 5;
|
||||
public const int GAMEPAD_AXIS_LAST = GAMEPAD_AXIS_RIGHT_TRIGGER;
|
||||
public const int NO_ERROR = 0;
|
||||
public const int NOT_INITIALIZED = 0x00010001;
|
||||
public const int NO_CURRENT_CONTEXT = 0x00010002;
|
||||
public const int INVALID_ENUM = 0x00010003;
|
||||
public const int INVALID_VALUE = 0x00010004;
|
||||
public const int OUT_OF_MEMORY = 0x00010005;
|
||||
public const int API_UNAVAILABLE = 0x00010006;
|
||||
public const int VERSION_UNAVAILABLE = 0x00010007;
|
||||
public const int PLATFORM_ERROR = 0x00010008;
|
||||
public const int FORMAT_UNAVAILABLE = 0x00010009;
|
||||
public const int NO_WINDOW_CONTEXT = 0x0001000A;
|
||||
public const int FOCUSED = 0x00020001;
|
||||
public const int ICONIFIED = 0x00020002;
|
||||
public const int RESIZABLE = 0x00020003;
|
||||
public const int VISIBLE = 0x00020004;
|
||||
public const int DECORATED = 0x00020005;
|
||||
public const int AUTO_ICONIFY = 0x00020006;
|
||||
public const int FLOATING = 0x00020007;
|
||||
public const int MAXIMIZED = 0x00020008;
|
||||
public const int CENTER_CURSOR = 0x00020009;
|
||||
public const int TRANSPARENT_FRAMEBUFFER = 0x0002000A;
|
||||
public const int HOVERED = 0x0002000B;
|
||||
public const int FOCUS_ON_SHOW = 0x0002000C;
|
||||
public const int RED_BITS = 0x00021001;
|
||||
public const int GREEN_BITS = 0x00021002;
|
||||
public const int BLUE_BITS = 0x00021003;
|
||||
public const int ALPHA_BITS = 0x00021004;
|
||||
public const int DEPTH_BITS = 0x00021005;
|
||||
public const int STENCIL_BITS = 0x00021006;
|
||||
public const int ACCUM_RED_BITS = 0x00021007;
|
||||
public const int ACCUM_GREEN_BITS = 0x00021008;
|
||||
public const int ACCUM_BLUE_BITS = 0x00021009;
|
||||
public const int ACCUM_ALPHA_BITS = 0x0002100A;
|
||||
public const int AUX_BUFFERS = 0x0002100B;
|
||||
public const int STEREO = 0x0002100C;
|
||||
public const int SAMPLES = 0x0002100D;
|
||||
public const int SRGB_CAPABLE = 0x0002100E;
|
||||
public const int REFRESH_RATE = 0x0002100F;
|
||||
public const int DOUBLEBUFFER = 0x00021010;
|
||||
public const int CLIENT_API = 0x00022001;
|
||||
public const int CONTEXT_VERSION_MAJOR = 0x00022002;
|
||||
public const int CONTEXT_VERSION_MINOR = 0x00022003;
|
||||
public const int CONTEXT_REVISION = 0x00022004;
|
||||
public const int CONTEXT_ROBUSTNESS = 0x00022005;
|
||||
public const int OPENGL_FORWARD_COMPAT = 0x00022006;
|
||||
public const int OPENGL_DEBUG_CONTEXT = 0x00022007;
|
||||
public const int OPENGL_PROFILE = 0x00022008;
|
||||
public const int CONTEXT_RELEASE_BEHAVIOR = 0x00022009;
|
||||
public const int CONTEXT_NO_ERROR = 0x0002200A;
|
||||
public const int CONTEXT_CREATION_API = 0x0002200B;
|
||||
public const int SCALE_TO_MONITOR = 0x0002200C;
|
||||
public const int COCOA_RETINA_FRAMEBUFFER = 0x00023001;
|
||||
public const int COCOA_FRAME_NAME = 0x00023002;
|
||||
public const int COCOA_GRAPHICS_SWITCHING = 0x00023003;
|
||||
public const int X11_CLASS_NAME = 0x00024001;
|
||||
public const int X11_INSTANCE_NAME = 0x00024002;
|
||||
public const int NO_API = 0;
|
||||
public const int OPENGL_API = 0x00030001;
|
||||
public const int OPENGL_ES_API = 0x00030002;
|
||||
public const int NO_ROBUSTNESS = 0;
|
||||
public const int NO_RESET_NOTIFICATION = 0x00031001;
|
||||
public const int LOSE_CONTEXT_ON_RESET = 0x00031002;
|
||||
public const int OPENGL_ANY_PROFILE = 0;
|
||||
public const int OPENGL_CORE_PROFILE = 0x00032001;
|
||||
public const int OPENGL_COMPAT_PROFILE = 0x00032002;
|
||||
public const int CURSOR = 0x00033001;
|
||||
public const int STICKY_KEYS = 0x00033002;
|
||||
public const int STICKY_MOUSE_BUTTONS = 0x00033003;
|
||||
public const int LOCK_KEY_MODS = 0x00033004;
|
||||
public const int RAW_MOUSE_MOTION = 0x00033005;
|
||||
public const int CURSOR_NORMAL = 0x00034001;
|
||||
public const int CURSOR_HIDDEN = 0x00034002;
|
||||
public const int CURSOR_DISABLED = 0x00034003;
|
||||
public const int ANY_RELEASE_BEHAVIOR = 0;
|
||||
public const int RELEASE_BEHAVIOR_FLUSH = 0x00035001;
|
||||
public const int RELEASE_BEHAVIOR_NONE = 0x00035002;
|
||||
public const int NATIVE_CONTEXT_API = 0x00036001;
|
||||
public const int EGL_CONTEXT_API = 0x00036002;
|
||||
public const int OSMESA_CONTEXT_API = 0x00036003;
|
||||
public const int ARROW_CURSOR = 0x00036001;
|
||||
public const int IBEAM_CURSOR = 0x00036002;
|
||||
public const int CROSSHAIR_CURSOR = 0x00036003;
|
||||
public const int HAND_CURSOR = 0x00036004;
|
||||
public const int HRESIZE_CURSOR = 0x00036005;
|
||||
public const int VRESIZE_CURSOR = 0x00036006;
|
||||
public const int CONNECTED = 0x00040001;
|
||||
public const int DISCONNECTED = 0x00040002;
|
||||
public const int JOYSTICK_HAT_BUTTONS = 0x00050001;
|
||||
public const int COCOA_CHDIR_RESOURCES = 0x00051001;
|
||||
public const int COCOA_MENUBAR = 0x00051002;
|
||||
public const int DONT_CARE = -1;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="FrameworkConstant"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public static class FrameworkConstant
|
||||
{
|
||||
|
||||
#region glfw
|
||||
|
||||
public const int VERSION_MAJOR = 3;
|
||||
public const int VERSION_MINOR = 3;
|
||||
public const int VERSION_REVISION = 8;
|
||||
public const int TRUE = 1;
|
||||
public const int FALSE = 0;
|
||||
public const int RELEASE = 0;
|
||||
public const int PRESS = 1;
|
||||
public const int REPEAT = 2;
|
||||
public const int HAT_CENTERED = 0;
|
||||
public const int HAT_UP = 1;
|
||||
public const int HAT_RIGHT = 2;
|
||||
public const int HAT_DOWN = 4;
|
||||
public const int HAT_LEFT = 8;
|
||||
public const int HAT_RIGHT_UP = HAT_RIGHT | HAT_UP;
|
||||
public const int HAT_RIGHT_DOWN = HAT_RIGHT | HAT_DOWN;
|
||||
public const int HAT_LEFT_UP = HAT_LEFT | HAT_UP;
|
||||
public const int HAT_LEFT_DOWN = HAT_LEFT | HAT_DOWN;
|
||||
public const int KEY_UNKNOWN = -1;
|
||||
public const int KEY_SPACE = 32;
|
||||
public const int KEY_APOSTROPHE = 39;
|
||||
public const int KEY_COMMA = 44;
|
||||
public const int KEY_MINUS = 45;
|
||||
public const int KEY_PERIOD = 46;
|
||||
public const int KEY_SLASH = 47;
|
||||
public const int KEY_0 = 48;
|
||||
public const int KEY_1 = 49;
|
||||
public const int KEY_2 = 50;
|
||||
public const int KEY_3 = 51;
|
||||
public const int KEY_4 = 52;
|
||||
public const int KEY_5 = 53;
|
||||
public const int KEY_6 = 54;
|
||||
public const int KEY_7 = 55;
|
||||
public const int KEY_8 = 56;
|
||||
public const int KEY_9 = 57;
|
||||
public const int KEY_SEMICOLON = 59;
|
||||
public const int KEY_EQUAL = 61;
|
||||
public const int KEY_A = 65;
|
||||
public const int KEY_B = 66;
|
||||
public const int KEY_C = 67;
|
||||
public const int KEY_D = 68;
|
||||
public const int KEY_E = 69;
|
||||
public const int KEY_F = 70;
|
||||
public const int KEY_G = 71;
|
||||
public const int KEY_H = 72;
|
||||
public const int KEY_I = 73;
|
||||
public const int KEY_J = 74;
|
||||
public const int KEY_K = 75;
|
||||
public const int KEY_L = 76;
|
||||
public const int KEY_M = 77;
|
||||
public const int KEY_N = 78;
|
||||
public const int KEY_O = 79;
|
||||
public const int KEY_P = 80;
|
||||
public const int KEY_Q = 81;
|
||||
public const int KEY_R = 82;
|
||||
public const int KEY_S = 83;
|
||||
public const int KEY_T = 84;
|
||||
public const int KEY_U = 85;
|
||||
public const int KEY_V = 86;
|
||||
public const int KEY_W = 87;
|
||||
public const int KEY_X = 88;
|
||||
public const int KEY_Y = 89;
|
||||
public const int KEY_Z = 90;
|
||||
public const int KEY_LEFT_BRACKET = 91;
|
||||
public const int KEY_BACKSLASH = 92;
|
||||
public const int KEY_RIGHT_BRACKET = 93;
|
||||
public const int KEY_GRAVE_ACCENT = 96;
|
||||
public const int KEY_WORLD_1 = 161;
|
||||
public const int KEY_WORLD_2 = 162;
|
||||
public const int KEY_ESCAPE = 256;
|
||||
public const int KEY_ENTER = 257;
|
||||
public const int KEY_TAB = 258;
|
||||
public const int KEY_BACKSPACE = 259;
|
||||
public const int KEY_INSERT = 260;
|
||||
public const int KEY_DELETE = 261;
|
||||
public const int KEY_RIGHT = 262;
|
||||
public const int KEY_LEFT = 263;
|
||||
public const int KEY_DOWN = 264;
|
||||
public const int KEY_UP = 265;
|
||||
public const int KEY_PAGE_UP = 266;
|
||||
public const int KEY_PAGE_DOWN = 267;
|
||||
public const int KEY_HOME = 268;
|
||||
public const int KEY_END = 269;
|
||||
public const int KEY_CAPS_LOCK = 280;
|
||||
public const int KEY_SCROLL_LOCK = 281;
|
||||
public const int KEY_NUM_LOCK = 282;
|
||||
public const int KEY_PRINT_SCREEN = 283;
|
||||
public const int KEY_PAUSE = 284;
|
||||
public const int KEY_F1 = 290;
|
||||
public const int KEY_F2 = 291;
|
||||
public const int KEY_F3 = 292;
|
||||
public const int KEY_F4 = 293;
|
||||
public const int KEY_F5 = 294;
|
||||
public const int KEY_F6 = 295;
|
||||
public const int KEY_F7 = 296;
|
||||
public const int KEY_F8 = 297;
|
||||
public const int KEY_F9 = 298;
|
||||
public const int KEY_F10 = 299;
|
||||
public const int KEY_F11 = 300;
|
||||
public const int KEY_F12 = 301;
|
||||
public const int KEY_F13 = 302;
|
||||
public const int KEY_F14 = 303;
|
||||
public const int KEY_F15 = 304;
|
||||
public const int KEY_F16 = 305;
|
||||
public const int KEY_F17 = 306;
|
||||
public const int KEY_F18 = 307;
|
||||
public const int KEY_F19 = 308;
|
||||
public const int KEY_F20 = 309;
|
||||
public const int KEY_F21 = 310;
|
||||
public const int KEY_F22 = 311;
|
||||
public const int KEY_F23 = 312;
|
||||
public const int KEY_F24 = 313;
|
||||
public const int KEY_F25 = 314;
|
||||
public const int KEY_KP_0 = 320;
|
||||
public const int KEY_KP_1 = 321;
|
||||
public const int KEY_KP_2 = 322;
|
||||
public const int KEY_KP_3 = 323;
|
||||
public const int KEY_KP_4 = 324;
|
||||
public const int KEY_KP_5 = 325;
|
||||
public const int KEY_KP_6 = 326;
|
||||
public const int KEY_KP_7 = 327;
|
||||
public const int KEY_KP_8 = 328;
|
||||
public const int KEY_KP_9 = 329;
|
||||
public const int KEY_KP_DECIMAL = 330;
|
||||
public const int KEY_KP_DIVIDE = 331;
|
||||
public const int KEY_KP_MULTIPLY = 332;
|
||||
public const int KEY_KP_SUBTRACT = 333;
|
||||
public const int KEY_KP_ADD = 334;
|
||||
public const int KEY_KP_ENTER = 335;
|
||||
public const int KEY_KP_EQUAL = 336;
|
||||
public const int KEY_LEFT_SHIFT = 340;
|
||||
public const int KEY_LEFT_CONTROL = 341;
|
||||
public const int KEY_LEFT_ALT = 342;
|
||||
public const int KEY_LEFT_SUPER = 343;
|
||||
public const int KEY_RIGHT_SHIFT = 344;
|
||||
public const int KEY_RIGHT_CONTROL = 345;
|
||||
public const int KEY_RIGHT_ALT = 346;
|
||||
public const int KEY_RIGHT_SUPER = 347;
|
||||
public const int KEY_MENU = 348;
|
||||
public const int KEY_LAST = KEY_MENU;
|
||||
public const int MOD_SHIFT = 0x0001;
|
||||
public const int MOD_CONTROL = 0x0002;
|
||||
public const int MOD_ALT = 0x0004;
|
||||
public const int MOD_SUPER = 0x0008;
|
||||
public const int MOD_CAPS_LOCK = 0x0010;
|
||||
public const int MOD_NUM_LOCK = 0x0020;
|
||||
public const int MOUSE_BUTTON_1 = 0;
|
||||
public const int MOUSE_BUTTON_2 = 1;
|
||||
public const int MOUSE_BUTTON_3 = 2;
|
||||
public const int MOUSE_BUTTON_4 = 3;
|
||||
public const int MOUSE_BUTTON_5 = 4;
|
||||
public const int MOUSE_BUTTON_6 = 5;
|
||||
public const int MOUSE_BUTTON_7 = 6;
|
||||
public const int MOUSE_BUTTON_8 = 7;
|
||||
public const int MOUSE_BUTTON_LAST = MOUSE_BUTTON_8;
|
||||
public const int MOUSE_BUTTON_LEFT = MOUSE_BUTTON_1;
|
||||
public const int MOUSE_BUTTON_RIGHT = MOUSE_BUTTON_2;
|
||||
public const int MOUSE_BUTTON_MIDDLE = MOUSE_BUTTON_3;
|
||||
public const int JOYSTICK_1 = 0;
|
||||
public const int JOYSTICK_2 = 1;
|
||||
public const int JOYSTICK_3 = 2;
|
||||
public const int JOYSTICK_4 = 3;
|
||||
public const int JOYSTICK_5 = 4;
|
||||
public const int JOYSTICK_6 = 5;
|
||||
public const int JOYSTICK_7 = 6;
|
||||
public const int JOYSTICK_8 = 7;
|
||||
public const int JOYSTICK_9 = 8;
|
||||
public const int JOYSTICK_10 = 9;
|
||||
public const int JOYSTICK_11 = 10;
|
||||
public const int JOYSTICK_12 = 11;
|
||||
public const int JOYSTICK_13 = 12;
|
||||
public const int JOYSTICK_14 = 13;
|
||||
public const int JOYSTICK_15 = 14;
|
||||
public const int JOYSTICK_16 = 15;
|
||||
public const int JOYSTICK_LAST = JOYSTICK_16;
|
||||
public const int GAMEPAD_BUTTON_A = 0;
|
||||
public const int GAMEPAD_BUTTON_B = 1;
|
||||
public const int GAMEPAD_BUTTON_X = 2;
|
||||
public const int GAMEPAD_BUTTON_Y = 3;
|
||||
public const int GAMEPAD_BUTTON_LEFT_BUMPER = 4;
|
||||
public const int GAMEPAD_BUTTON_RIGHT_BUMPER = 5;
|
||||
public const int GAMEPAD_BUTTON_BACK = 6;
|
||||
public const int GAMEPAD_BUTTON_START = 7;
|
||||
public const int GAMEPAD_BUTTON_GUIDE = 8;
|
||||
public const int GAMEPAD_BUTTON_LEFT_THUMB = 9;
|
||||
public const int GAMEPAD_BUTTON_RIGHT_THUMB = 10;
|
||||
public const int GAMEPAD_BUTTON_DPAD_UP = 11;
|
||||
public const int GAMEPAD_BUTTON_DPAD_RIGHT = 12;
|
||||
public const int GAMEPAD_BUTTON_DPAD_DOWN = 13;
|
||||
public const int GAMEPAD_BUTTON_DPAD_LEFT = 14;
|
||||
public const int GAMEPAD_BUTTON_LAST = GAMEPAD_BUTTON_DPAD_LEFT;
|
||||
public const int GAMEPAD_BUTTON_CROSS = GAMEPAD_BUTTON_A;
|
||||
public const int GAMEPAD_BUTTON_CIRCLE = GAMEPAD_BUTTON_B;
|
||||
public const int GAMEPAD_BUTTON_SQUARE = GAMEPAD_BUTTON_X;
|
||||
public const int GAMEPAD_BUTTON_TRIANGLE = GAMEPAD_BUTTON_Y;
|
||||
public const int GAMEPAD_AXIS_LEFT_X = 0;
|
||||
public const int GAMEPAD_AXIS_LEFT_Y = 1;
|
||||
public const int GAMEPAD_AXIS_RIGHT_X = 2;
|
||||
public const int GAMEPAD_AXIS_RIGHT_Y = 3;
|
||||
public const int GAMEPAD_AXIS_LEFT_TRIGGER = 4;
|
||||
public const int GAMEPAD_AXIS_RIGHT_TRIGGER = 5;
|
||||
public const int GAMEPAD_AXIS_LAST = GAMEPAD_AXIS_RIGHT_TRIGGER;
|
||||
public const int NO_ERROR = 0;
|
||||
public const int NOT_INITIALIZED = 0x00010001;
|
||||
public const int NO_CURRENT_CONTEXT = 0x00010002;
|
||||
public const int INVALID_ENUM = 0x00010003;
|
||||
public const int INVALID_VALUE = 0x00010004;
|
||||
public const int OUT_OF_MEMORY = 0x00010005;
|
||||
public const int API_UNAVAILABLE = 0x00010006;
|
||||
public const int VERSION_UNAVAILABLE = 0x00010007;
|
||||
public const int PLATFORM_ERROR = 0x00010008;
|
||||
public const int FORMAT_UNAVAILABLE = 0x00010009;
|
||||
public const int NO_WINDOW_CONTEXT = 0x0001000A;
|
||||
public const int FOCUSED = 0x00020001;
|
||||
public const int ICONIFIED = 0x00020002;
|
||||
public const int RESIZABLE = 0x00020003;
|
||||
public const int VISIBLE = 0x00020004;
|
||||
public const int DECORATED = 0x00020005;
|
||||
public const int AUTO_ICONIFY = 0x00020006;
|
||||
public const int FLOATING = 0x00020007;
|
||||
public const int MAXIMIZED = 0x00020008;
|
||||
public const int CENTER_CURSOR = 0x00020009;
|
||||
public const int TRANSPARENT_FRAMEBUFFER = 0x0002000A;
|
||||
public const int HOVERED = 0x0002000B;
|
||||
public const int FOCUS_ON_SHOW = 0x0002000C;
|
||||
public const int RED_BITS = 0x00021001;
|
||||
public const int GREEN_BITS = 0x00021002;
|
||||
public const int BLUE_BITS = 0x00021003;
|
||||
public const int ALPHA_BITS = 0x00021004;
|
||||
public const int DEPTH_BITS = 0x00021005;
|
||||
public const int STENCIL_BITS = 0x00021006;
|
||||
public const int ACCUM_RED_BITS = 0x00021007;
|
||||
public const int ACCUM_GREEN_BITS = 0x00021008;
|
||||
public const int ACCUM_BLUE_BITS = 0x00021009;
|
||||
public const int ACCUM_ALPHA_BITS = 0x0002100A;
|
||||
public const int AUX_BUFFERS = 0x0002100B;
|
||||
public const int STEREO = 0x0002100C;
|
||||
public const int SAMPLES = 0x0002100D;
|
||||
public const int SRGB_CAPABLE = 0x0002100E;
|
||||
public const int REFRESH_RATE = 0x0002100F;
|
||||
public const int DOUBLEBUFFER = 0x00021010;
|
||||
public const int CLIENT_API = 0x00022001;
|
||||
public const int CONTEXT_VERSION_MAJOR = 0x00022002;
|
||||
public const int CONTEXT_VERSION_MINOR = 0x00022003;
|
||||
public const int CONTEXT_REVISION = 0x00022004;
|
||||
public const int CONTEXT_ROBUSTNESS = 0x00022005;
|
||||
public const int OPENGL_FORWARD_COMPAT = 0x00022006;
|
||||
public const int OPENGL_DEBUG_CONTEXT = 0x00022007;
|
||||
public const int OPENGL_PROFILE = 0x00022008;
|
||||
public const int CONTEXT_RELEASE_BEHAVIOR = 0x00022009;
|
||||
public const int CONTEXT_NO_ERROR = 0x0002200A;
|
||||
public const int CONTEXT_CREATION_API = 0x0002200B;
|
||||
public const int SCALE_TO_MONITOR = 0x0002200C;
|
||||
public const int COCOA_RETINA_FRAMEBUFFER = 0x00023001;
|
||||
public const int COCOA_FRAME_NAME = 0x00023002;
|
||||
public const int COCOA_GRAPHICS_SWITCHING = 0x00023003;
|
||||
public const int X11_CLASS_NAME = 0x00024001;
|
||||
public const int X11_INSTANCE_NAME = 0x00024002;
|
||||
public const int NO_API = 0;
|
||||
public const int OPENGL_API = 0x00030001;
|
||||
public const int OPENGL_ES_API = 0x00030002;
|
||||
public const int NO_ROBUSTNESS = 0;
|
||||
public const int NO_RESET_NOTIFICATION = 0x00031001;
|
||||
public const int LOSE_CONTEXT_ON_RESET = 0x00031002;
|
||||
public const int OPENGL_ANY_PROFILE = 0;
|
||||
public const int OPENGL_CORE_PROFILE = 0x00032001;
|
||||
public const int OPENGL_COMPAT_PROFILE = 0x00032002;
|
||||
public const int CURSOR = 0x00033001;
|
||||
public const int STICKY_KEYS = 0x00033002;
|
||||
public const int STICKY_MOUSE_BUTTONS = 0x00033003;
|
||||
public const int LOCK_KEY_MODS = 0x00033004;
|
||||
public const int RAW_MOUSE_MOTION = 0x00033005;
|
||||
public const int CURSOR_NORMAL = 0x00034001;
|
||||
public const int CURSOR_HIDDEN = 0x00034002;
|
||||
public const int CURSOR_DISABLED = 0x00034003;
|
||||
public const int ANY_RELEASE_BEHAVIOR = 0;
|
||||
public const int RELEASE_BEHAVIOR_FLUSH = 0x00035001;
|
||||
public const int RELEASE_BEHAVIOR_NONE = 0x00035002;
|
||||
public const int NATIVE_CONTEXT_API = 0x00036001;
|
||||
public const int EGL_CONTEXT_API = 0x00036002;
|
||||
public const int OSMESA_CONTEXT_API = 0x00036003;
|
||||
public const int ARROW_CURSOR = 0x00036001;
|
||||
public const int IBEAM_CURSOR = 0x00036002;
|
||||
public const int CROSSHAIR_CURSOR = 0x00036003;
|
||||
public const int HAND_CURSOR = 0x00036004;
|
||||
public const int HRESIZE_CURSOR = 0x00036005;
|
||||
public const int VRESIZE_CURSOR = 0x00036006;
|
||||
public const int CONNECTED = 0x00040001;
|
||||
public const int DISCONNECTED = 0x00040002;
|
||||
public const int JOYSTICK_HAT_BUTTONS = 0x00050001;
|
||||
public const int COCOA_CHDIR_RESOURCES = 0x00051001;
|
||||
public const int COCOA_MENUBAR = 0x00051002;
|
||||
public const int DONT_CARE = -1;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IGraphicAPIs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IGraphicAPIs
|
||||
{
|
||||
|
||||
public IntPtr GraphicApiPackageHandle { get; }
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IGraphicAPIs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IGraphicAPIs
|
||||
{
|
||||
|
||||
public IntPtr GraphicApiPackageHandle { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+190
-190
@@ -1,191 +1,191 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Image"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : ISSDSerializable, IImageProvider
|
||||
{
|
||||
|
||||
private byte[] _data;
|
||||
private ImageInfo _rawInfo;
|
||||
private int _pixelUpdateCount = 0;
|
||||
|
||||
internal unsafe Image()
|
||||
{
|
||||
_rawInfo = new ImageInfo();
|
||||
}
|
||||
|
||||
internal Image(ImageInfo information)
|
||||
{
|
||||
_rawInfo = information;
|
||||
_data = [];
|
||||
|
||||
// int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel;
|
||||
}
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (_rawInfo.Width, _rawInfo.Height);
|
||||
}
|
||||
|
||||
public byte[] PixelBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((_data.Length == 0) || (_data == null))
|
||||
{
|
||||
GetBytes();
|
||||
return _data!;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
public ImageChannel Channel => _rawInfo.Channel;
|
||||
|
||||
/// <summary>
|
||||
/// Hash code of time pixels updated last time.
|
||||
/// </summary>
|
||||
public int PixelUpdateCount
|
||||
{
|
||||
get => _pixelUpdateCount;
|
||||
internal set => _pixelUpdateCount = value;
|
||||
}
|
||||
|
||||
public int ChannelCount => _rawInfo.ChannelCount;
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => _rawInfo.Height;
|
||||
internal set => _rawInfo.Height = value;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => _rawInfo.Width;
|
||||
internal set => _rawInfo.Width = value;
|
||||
}
|
||||
|
||||
public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel);
|
||||
|
||||
public PixelChannelLayout PixelLayout
|
||||
{
|
||||
get => _rawInfo.pixelLayout;
|
||||
private set => _rawInfo.pixelLayout = value;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
|
||||
internal ref byte[] Data => ref _data;
|
||||
|
||||
public void FromBytes(byte[] stream) { }
|
||||
|
||||
public static unsafe Image FromFile(string route, ImageLoader loader)
|
||||
{
|
||||
Image ret = new Image();
|
||||
fixed (ImageInfo* iptr = &ret._rawInfo) {
|
||||
GraphicFramework.InternalLoadImage(route, iptr, loader);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = PixelChannelLayout.Byte;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory(
|
||||
(int width, int height) size,
|
||||
ImageChannel channel,
|
||||
PixelChannelLayout layout,
|
||||
byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = layout;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
if (_data.Length == 0)
|
||||
{
|
||||
int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel);
|
||||
_data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray();
|
||||
fixed (ImageInfo* pptr = &_rawInfo) {
|
||||
GraphicFramework.InternalUnloadImage(pptr);
|
||||
}
|
||||
_rawInfo.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
internal static Image FromMemory(ImageInfo info, byte[] data, int operationCount)
|
||||
{
|
||||
return new Image
|
||||
{
|
||||
_rawInfo = info,
|
||||
_data = data,
|
||||
_pixelUpdateCount = operationCount
|
||||
};
|
||||
}
|
||||
|
||||
byte[] ISSDSerializable.GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Image"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : ISSDSerializable, IImageProvider
|
||||
{
|
||||
|
||||
private byte[] _data;
|
||||
private ImageInfo _rawInfo;
|
||||
private int _pixelUpdateCount = 0;
|
||||
|
||||
internal unsafe Image()
|
||||
{
|
||||
_rawInfo = new ImageInfo();
|
||||
}
|
||||
|
||||
internal Image(ImageInfo information)
|
||||
{
|
||||
_rawInfo = information;
|
||||
_data = [];
|
||||
|
||||
// int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel;
|
||||
}
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (_rawInfo.Width, _rawInfo.Height);
|
||||
}
|
||||
|
||||
public byte[] PixelBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((_data.Length == 0) || (_data == null))
|
||||
{
|
||||
GetBytes();
|
||||
return _data!;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
public ImageChannel Channel => _rawInfo.Channel;
|
||||
|
||||
/// <summary>
|
||||
/// Hash code of time pixels updated last time.
|
||||
/// </summary>
|
||||
public int PixelUpdateCount
|
||||
{
|
||||
get => _pixelUpdateCount;
|
||||
internal set => _pixelUpdateCount = value;
|
||||
}
|
||||
|
||||
public int ChannelCount => _rawInfo.ChannelCount;
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => _rawInfo.Height;
|
||||
internal set => _rawInfo.Height = value;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => _rawInfo.Width;
|
||||
internal set => _rawInfo.Width = value;
|
||||
}
|
||||
|
||||
public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel);
|
||||
|
||||
public PixelChannelLayout PixelLayout
|
||||
{
|
||||
get => _rawInfo.pixelLayout;
|
||||
private set => _rawInfo.pixelLayout = value;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
|
||||
internal ref byte[] Data => ref _data;
|
||||
|
||||
public void FromBytes(byte[] stream) { }
|
||||
|
||||
public static unsafe Image FromFile(string route, ImageLoader loader)
|
||||
{
|
||||
Image ret = new Image();
|
||||
fixed (ImageInfo* iptr = &ret._rawInfo) {
|
||||
GraphicFramework.InternalLoadImage(route, iptr, loader);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = PixelChannelLayout.Byte;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory(
|
||||
(int width, int height) size,
|
||||
ImageChannel channel,
|
||||
PixelChannelLayout layout,
|
||||
byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = layout;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
if (_data.Length == 0)
|
||||
{
|
||||
int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel);
|
||||
_data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray();
|
||||
fixed (ImageInfo* pptr = &_rawInfo) {
|
||||
GraphicFramework.InternalUnloadImage(pptr);
|
||||
}
|
||||
_rawInfo.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
internal static Image FromMemory(ImageInfo info, byte[] data, int operationCount)
|
||||
{
|
||||
return new Image
|
||||
{
|
||||
_rawInfo = info,
|
||||
_data = data,
|
||||
_pixelUpdateCount = operationCount
|
||||
};
|
||||
}
|
||||
|
||||
byte[] ISSDSerializable.GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,162 +1,162 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ImageInfo"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public delegate IntPtr ImageLoader(
|
||||
string name,
|
||||
ref int width,
|
||||
ref int height,
|
||||
ref int definedChannel,
|
||||
int desiredChannel);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ImageInfo
|
||||
{
|
||||
|
||||
private ImageChannel channel;
|
||||
private int height;
|
||||
private int width;
|
||||
private IntPtr pixelPtr;
|
||||
internal PixelChannelLayout pixelLayout;
|
||||
|
||||
public ImageChannel Channel
|
||||
{
|
||||
get => channel;
|
||||
set { channel = value; }
|
||||
}
|
||||
|
||||
public int ChannelCount
|
||||
{
|
||||
get => GetChannelCount(channel);
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
public int StreamSize
|
||||
{
|
||||
get => width * height * GetPixelSize(
|
||||
pixelLayout, channel);
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
public IntPtr StreamPtr
|
||||
{
|
||||
get => pixelPtr;
|
||||
internal set => pixelPtr = value;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = (hash * 17) + width;
|
||||
hash = (hash * 17) + height;
|
||||
hash = (hash * 17) + (int)channel;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
|
||||
}
|
||||
|
||||
internal static int GetChannelCount(ImageChannel channel)
|
||||
{
|
||||
return channel switch
|
||||
{
|
||||
ImageChannel.SingleColor => 1,
|
||||
ImageChannel.DoubleColor => 2,
|
||||
ImageChannel.TripleColor => 3,
|
||||
ImageChannel.WithAlphaChannel => 4,
|
||||
_ => throw new InvalidCastException(
|
||||
"Unknown color channel decoding setting.")
|
||||
};
|
||||
}
|
||||
|
||||
internal static int GetPixelSize(PixelChannelLayout layout, ImageChannel channel)
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.UByte => sizeof(byte) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Byte => sizeof(byte) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UShort => sizeof(short) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Short => sizeof(short) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UInt => sizeof(int) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Int => sizeof(int) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Float => sizeof(float) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UByte332 => sizeof(byte),
|
||||
PixelChannelLayout.UByte233Rev => sizeof(byte),
|
||||
PixelChannelLayout.UShort565 => sizeof(short),
|
||||
PixelChannelLayout.UShort565Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort4444 => sizeof(short),
|
||||
PixelChannelLayout.UShort4444Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort5551 => sizeof(short),
|
||||
PixelChannelLayout.UShort1555Rev => sizeof(short),
|
||||
PixelChannelLayout.UInt8888 => sizeof(int),
|
||||
PixelChannelLayout.UInt8888Rev => sizeof(int),
|
||||
PixelChannelLayout.UInt1010102 => sizeof(int),
|
||||
PixelChannelLayout.UInt2101010Rev => sizeof(int),
|
||||
_ => throw new ArgumentException("Unknown layout type"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ImageChannel : uint
|
||||
{
|
||||
|
||||
SingleColor = glConst.RED,
|
||||
DoubleColor = glConst.RG,
|
||||
TripleColor = glConst.RGB,
|
||||
WithAlphaChannel = glConst.RGBA,
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ImageInfo"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public delegate IntPtr ImageLoader(
|
||||
string name,
|
||||
ref int width,
|
||||
ref int height,
|
||||
ref int definedChannel,
|
||||
int desiredChannel);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ImageInfo
|
||||
{
|
||||
|
||||
private ImageChannel channel;
|
||||
private int height;
|
||||
private int width;
|
||||
private IntPtr pixelPtr;
|
||||
internal PixelChannelLayout pixelLayout;
|
||||
|
||||
public ImageChannel Channel
|
||||
{
|
||||
get => channel;
|
||||
set { channel = value; }
|
||||
}
|
||||
|
||||
public int ChannelCount
|
||||
{
|
||||
get => GetChannelCount(channel);
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
public int StreamSize
|
||||
{
|
||||
get => width * height * GetPixelSize(
|
||||
pixelLayout, channel);
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
public IntPtr StreamPtr
|
||||
{
|
||||
get => pixelPtr;
|
||||
internal set => pixelPtr = value;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = (hash * 17) + width;
|
||||
hash = (hash * 17) + height;
|
||||
hash = (hash * 17) + (int)channel;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
|
||||
}
|
||||
|
||||
internal static int GetChannelCount(ImageChannel channel)
|
||||
{
|
||||
return channel switch
|
||||
{
|
||||
ImageChannel.SingleColor => 1,
|
||||
ImageChannel.DoubleColor => 2,
|
||||
ImageChannel.TripleColor => 3,
|
||||
ImageChannel.WithAlphaChannel => 4,
|
||||
_ => throw new InvalidCastException(
|
||||
"Unknown color channel decoding setting.")
|
||||
};
|
||||
}
|
||||
|
||||
internal static int GetPixelSize(PixelChannelLayout layout, ImageChannel channel)
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.UByte => sizeof(byte) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Byte => sizeof(byte) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UShort => sizeof(short) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Short => sizeof(short) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UInt => sizeof(int) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Int => sizeof(int) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Float => sizeof(float) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UByte332 => sizeof(byte),
|
||||
PixelChannelLayout.UByte233Rev => sizeof(byte),
|
||||
PixelChannelLayout.UShort565 => sizeof(short),
|
||||
PixelChannelLayout.UShort565Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort4444 => sizeof(short),
|
||||
PixelChannelLayout.UShort4444Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort5551 => sizeof(short),
|
||||
PixelChannelLayout.UShort1555Rev => sizeof(short),
|
||||
PixelChannelLayout.UInt8888 => sizeof(int),
|
||||
PixelChannelLayout.UInt8888Rev => sizeof(int),
|
||||
PixelChannelLayout.UInt1010102 => sizeof(int),
|
||||
PixelChannelLayout.UInt2101010Rev => sizeof(int),
|
||||
_ => throw new ArgumentException("Unknown layout type"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ImageChannel : uint
|
||||
{
|
||||
|
||||
SingleColor = glConst.RED,
|
||||
DoubleColor = glConst.RG,
|
||||
TripleColor = glConst.RGB,
|
||||
WithAlphaChannel = glConst.RGBA,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,160 +1,160 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="AutoTexture"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Collections;
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of a sets of OpenGL textures. The collection can automatically select one of
|
||||
/// the texture with minimum costs to upgrade pixels to BufferHandle. Usually <see
|
||||
/// cref="AutoTextureGL" /> is used for <see cref="IImageProvider" /> loading, but not for
|
||||
/// target of <see cref="OpenGLFunction.FrameBufferTexture2d(FrameBufferTarget, uint,
|
||||
/// Texture2DTarget, GlHandle, int)" />.
|
||||
/// </summary>
|
||||
public sealed class AutoTextureGL
|
||||
{
|
||||
|
||||
private TextureProperty[] propertyCache;
|
||||
private BidirectionalDictionary<Image, int> imageIndexMap = new BidirectionalDictionary<Image, int>(
|
||||
);
|
||||
private Dictionary<Image, int> imageUpdateIndex = new Dictionary<Image, int>();
|
||||
|
||||
private int _size, _currentIndex;
|
||||
private LinkedList<int> usedTextureIndex;
|
||||
private Queue<int> unusedTextureUnitIndex;
|
||||
private TextureGL texturePackage;
|
||||
|
||||
private TextureProperty _textureProperty;
|
||||
|
||||
private AutoTextureGL(TextureGL texture)
|
||||
{
|
||||
texturePackage = texture;
|
||||
_size = texture.Count;
|
||||
imageIndexMap = new BidirectionalDictionary<Image, int>();
|
||||
unusedTextureUnitIndex = new Queue<int>(Enumerable.Range(0, _size));
|
||||
usedTextureIndex = new LinkedList<int>();
|
||||
propertyCache = new TextureProperty[_size];
|
||||
}
|
||||
|
||||
public AutoTextureGL(int textureObjectSize, [NotNull]glRender binding)
|
||||
{
|
||||
this._size = textureObjectSize;
|
||||
imageIndexMap = new BidirectionalDictionary<Image, int>();
|
||||
texturePackage = new TextureGL(textureObjectSize, binding);
|
||||
unusedTextureUnitIndex = new Queue<int>(Enumerable.Range(0, _size));
|
||||
usedTextureIndex = new LinkedList<int>();
|
||||
propertyCache = new TextureProperty[_size];
|
||||
}
|
||||
|
||||
public TextureProperty DefaultTextureProperty
|
||||
{
|
||||
get => _textureProperty;
|
||||
set => _textureProperty = value;
|
||||
}
|
||||
|
||||
private OpenGLFunction GL
|
||||
{
|
||||
get => texturePackage.GL;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SelectTextureAndBind(Image i)
|
||||
{
|
||||
TextureProperty property = _textureProperty;
|
||||
|
||||
SelectTextureAndBind(i, property);
|
||||
}
|
||||
|
||||
public void SelectTextureAndBind([NotNull]Image i, TextureProperty property)
|
||||
{
|
||||
// usable texture with image match
|
||||
if (imageIndexMap.TryGetValue(i, out int index))
|
||||
{
|
||||
// prop setting match
|
||||
if (propertyCache[index] == property)
|
||||
{
|
||||
_currentIndex = index; //GL.Assert(true);
|
||||
texturePackage.Bind2D(index); //GL.Assert(true);
|
||||
if (i.PixelUpdateCount != imageUpdateIndex[i])
|
||||
{
|
||||
texturePackage.LoadTexture(index, i); //GL.Assert(true);
|
||||
}
|
||||
} else
|
||||
{
|
||||
_currentIndex = index; //GL.Assert(true);
|
||||
texturePackage.Bind2D(index); //GL.Assert(true);
|
||||
texturePackage.Set2dProperty(index, property); //GL.Assert(true);
|
||||
if (i.PixelUpdateCount != imageUpdateIndex[i])
|
||||
{
|
||||
texturePackage.LoadTexture(index, i); //GL.Assert(true);
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (unusedTextureUnitIndex.TryDequeue(out int newIndex))
|
||||
{
|
||||
// has extra unused texture object
|
||||
imageIndexMap.Add(i, index);
|
||||
texturePackage.Bind2D(index);
|
||||
texturePackage.Set2dProperty(index, property);
|
||||
texturePackage.LoadTexture(index, i);
|
||||
usedTextureIndex.AddLast(newIndex);
|
||||
propertyCache[newIndex] = property;
|
||||
imageUpdateIndex[i] = i.PixelUpdateCount;
|
||||
} else
|
||||
{
|
||||
// recycle from current
|
||||
int reusedIndex = usedTextureIndex.First!.Value;
|
||||
usedTextureIndex.RemoveFirst();
|
||||
usedTextureIndex.AddLast(reusedIndex);
|
||||
imageIndexMap[i] = reusedIndex;
|
||||
propertyCache[newIndex] = property;
|
||||
imageUpdateIndex[i] = i.PixelUpdateCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static AutoTextureGL ToAuto([NotNull]TextureGL texture)
|
||||
{
|
||||
if (texture.IndexOfCurrentTexture != -1) {
|
||||
throw new InvalidOperationException("Texture to be converted has been editted.");
|
||||
}
|
||||
return new AutoTextureGL(texture);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="AutoTexture"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Collections;
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of a sets of OpenGL textures. The collection can automatically select one of
|
||||
/// the texture with minimum costs to upgrade pixels to BufferHandle. Usually <see
|
||||
/// cref="AutoTextureGL" /> is used for <see cref="IImageProvider" /> loading, but not for
|
||||
/// target of <see cref="OpenGLFunction.FrameBufferTexture2d(FrameBufferTarget, uint,
|
||||
/// Texture2DTarget, GlHandle, int)" />.
|
||||
/// </summary>
|
||||
public sealed class AutoTextureGL
|
||||
{
|
||||
|
||||
private TextureProperty[] propertyCache;
|
||||
private BidirectionalDictionary<Image, int> imageIndexMap = new BidirectionalDictionary<Image, int>(
|
||||
);
|
||||
private Dictionary<Image, int> imageUpdateIndex = new Dictionary<Image, int>();
|
||||
|
||||
private int _size, _currentIndex;
|
||||
private LinkedList<int> usedTextureIndex;
|
||||
private Queue<int> unusedTextureUnitIndex;
|
||||
private TextureGL texturePackage;
|
||||
|
||||
private TextureProperty _textureProperty;
|
||||
|
||||
private AutoTextureGL(TextureGL texture)
|
||||
{
|
||||
texturePackage = texture;
|
||||
_size = texture.Count;
|
||||
imageIndexMap = new BidirectionalDictionary<Image, int>();
|
||||
unusedTextureUnitIndex = new Queue<int>(Enumerable.Range(0, _size));
|
||||
usedTextureIndex = new LinkedList<int>();
|
||||
propertyCache = new TextureProperty[_size];
|
||||
}
|
||||
|
||||
public AutoTextureGL(int textureObjectSize, [NotNull]glRender binding)
|
||||
{
|
||||
this._size = textureObjectSize;
|
||||
imageIndexMap = new BidirectionalDictionary<Image, int>();
|
||||
texturePackage = new TextureGL(textureObjectSize, binding);
|
||||
unusedTextureUnitIndex = new Queue<int>(Enumerable.Range(0, _size));
|
||||
usedTextureIndex = new LinkedList<int>();
|
||||
propertyCache = new TextureProperty[_size];
|
||||
}
|
||||
|
||||
public TextureProperty DefaultTextureProperty
|
||||
{
|
||||
get => _textureProperty;
|
||||
set => _textureProperty = value;
|
||||
}
|
||||
|
||||
private OpenGLFunction GL
|
||||
{
|
||||
get => texturePackage.GL;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SelectTextureAndBind(Image i)
|
||||
{
|
||||
TextureProperty property = _textureProperty;
|
||||
|
||||
SelectTextureAndBind(i, property);
|
||||
}
|
||||
|
||||
public void SelectTextureAndBind([NotNull]Image i, TextureProperty property)
|
||||
{
|
||||
// usable texture with image match
|
||||
if (imageIndexMap.TryGetValue(i, out int index))
|
||||
{
|
||||
// prop setting match
|
||||
if (propertyCache[index] == property)
|
||||
{
|
||||
_currentIndex = index; //GL.Assert(true);
|
||||
texturePackage.Bind2D(index); //GL.Assert(true);
|
||||
if (i.PixelUpdateCount != imageUpdateIndex[i])
|
||||
{
|
||||
texturePackage.LoadTexture(index, i); //GL.Assert(true);
|
||||
}
|
||||
} else
|
||||
{
|
||||
_currentIndex = index; //GL.Assert(true);
|
||||
texturePackage.Bind2D(index); //GL.Assert(true);
|
||||
texturePackage.Set2dProperty(index, property); //GL.Assert(true);
|
||||
if (i.PixelUpdateCount != imageUpdateIndex[i])
|
||||
{
|
||||
texturePackage.LoadTexture(index, i); //GL.Assert(true);
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (unusedTextureUnitIndex.TryDequeue(out int newIndex))
|
||||
{
|
||||
// has extra unused texture object
|
||||
imageIndexMap.Add(i, index);
|
||||
texturePackage.Bind2D(index);
|
||||
texturePackage.Set2dProperty(index, property);
|
||||
texturePackage.LoadTexture(index, i);
|
||||
usedTextureIndex.AddLast(newIndex);
|
||||
propertyCache[newIndex] = property;
|
||||
imageUpdateIndex[i] = i.PixelUpdateCount;
|
||||
} else
|
||||
{
|
||||
// recycle from current
|
||||
int reusedIndex = usedTextureIndex.First!.Value;
|
||||
usedTextureIndex.RemoveFirst();
|
||||
usedTextureIndex.AddLast(reusedIndex);
|
||||
imageIndexMap[i] = reusedIndex;
|
||||
propertyCache[newIndex] = property;
|
||||
imageUpdateIndex[i] = i.PixelUpdateCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static AutoTextureGL ToAuto([NotNull]TextureGL texture)
|
||||
{
|
||||
if (texture.IndexOfCurrentTexture != -1) {
|
||||
throw new InvalidOperationException("Texture to be converted has been editted.");
|
||||
}
|
||||
return new AutoTextureGL(texture);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="EBO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of handle to Element BufferHandle Object in OpenglFunc. Each <see
|
||||
/// langword="uint" /> value indexed from instance of this class this is the only handle to
|
||||
/// one Element BufferHandle Object.
|
||||
/// </summary>
|
||||
public sealed unsafe class ElementBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal ElementBuffer(int n, glRender binding)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
|
||||
public sealed override void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage) where T: unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData<T>(BufferType.ElementArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, ReadOnlySpan<T> bufferSpan, BufferUsage usage) where T: unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData<T>(BufferType.ElementArrayBuffer, bufferSpan, usage);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="EBO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of handle to Element BufferHandle Object in OpenglFunc. Each <see
|
||||
/// langword="uint" /> value indexed from instance of this class this is the only handle to
|
||||
/// one Element BufferHandle Object.
|
||||
/// </summary>
|
||||
public sealed unsafe class ElementBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal ElementBuffer(int n, glRender binding)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
|
||||
public sealed override void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage) where T: unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData<T>(BufferType.ElementArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, ReadOnlySpan<T> bufferSpan, BufferUsage usage) where T: unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData<T>(BufferType.ElementArrayBuffer, bufferSpan, usage);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,115 +1,115 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="FBO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
#pragma warning disable CA1028
|
||||
public enum FrameBufferTarget : uint
|
||||
#pragma warning restore CA1028
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Read = glConst.READ_FRAMEBUFFER,
|
||||
All = glConst.FRAMEBUFFER,
|
||||
Draw = glConst.DRAW_FRAMEBUFFER,
|
||||
|
||||
}
|
||||
|
||||
public sealed class FrameBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal unsafe FrameBuffer(
|
||||
int count,
|
||||
glRender binding
|
||||
)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = new GlHandle[count];
|
||||
GL.GenFrameBuffers(_bufferHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame BufferHandle object with _label frame BufferHandle to the frame
|
||||
/// BufferHandle target specified by target. <see langword="FrameBufferTarget.All" /> will
|
||||
/// be set as default target.
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
/// Index of object to be binded in handle set
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override unsafe void Bind(
|
||||
int index
|
||||
)
|
||||
{
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame BufferHandle object with _label frame BufferHandle to the frame
|
||||
/// BufferHandle target specified by target. Target of this frame BufferHandle should be
|
||||
/// set manually.
|
||||
/// </summary>
|
||||
/// <param _label="target">
|
||||
/// The frame BufferHandle target of the binding operation.
|
||||
/// </param>
|
||||
/// <param _label="index">
|
||||
/// Index of object to be binded in handle set
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Bind(
|
||||
FrameBufferTarget target,
|
||||
int index
|
||||
)
|
||||
{
|
||||
GL.BindFrameBuffer(target, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindNull()
|
||||
{
|
||||
OpenGLFunction.CurrentGL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
|
||||
}
|
||||
|
||||
protected override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="FBO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
#pragma warning disable CA1028
|
||||
public enum FrameBufferTarget : uint
|
||||
#pragma warning restore CA1028
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Read = glConst.READ_FRAMEBUFFER,
|
||||
All = glConst.FRAMEBUFFER,
|
||||
Draw = glConst.DRAW_FRAMEBUFFER,
|
||||
|
||||
}
|
||||
|
||||
public sealed class FrameBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal unsafe FrameBuffer(
|
||||
int count,
|
||||
glRender binding
|
||||
)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = new GlHandle[count];
|
||||
GL.GenFrameBuffers(_bufferHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame BufferHandle object with _label frame BufferHandle to the frame
|
||||
/// BufferHandle target specified by target. <see langword="FrameBufferTarget.All" /> will
|
||||
/// be set as default target.
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
/// Index of object to be binded in handle set
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override unsafe void Bind(
|
||||
int index
|
||||
)
|
||||
{
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame BufferHandle object with _label frame BufferHandle to the frame
|
||||
/// BufferHandle target specified by target. Target of this frame BufferHandle should be
|
||||
/// set manually.
|
||||
/// </summary>
|
||||
/// <param _label="target">
|
||||
/// The frame BufferHandle target of the binding operation.
|
||||
/// </param>
|
||||
/// <param _label="index">
|
||||
/// Index of object to be binded in handle set
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Bind(
|
||||
FrameBufferTarget target,
|
||||
int index
|
||||
)
|
||||
{
|
||||
GL.BindFrameBuffer(target, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindNull()
|
||||
{
|
||||
OpenGLFunction.CurrentGL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
|
||||
}
|
||||
|
||||
protected override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GLBufferObjectBase"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract class GlBufferObjectBase : BufferObjectBase
|
||||
{
|
||||
|
||||
private readonly glRender _contextBinding;
|
||||
|
||||
protected GlBufferObjectBase(glRender contextBinding)
|
||||
{
|
||||
binding = contextBinding;
|
||||
_contextBinding = contextBinding;
|
||||
}
|
||||
|
||||
protected OpenGLFunction GL => _contextBinding.GL;
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GLBufferObjectBase"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract class GlBufferObjectBase : BufferObjectBase
|
||||
{
|
||||
|
||||
private readonly glRender _contextBinding;
|
||||
|
||||
protected GlBufferObjectBase(glRender contextBinding)
|
||||
{
|
||||
binding = contextBinding;
|
||||
_contextBinding = contextBinding;
|
||||
}
|
||||
|
||||
protected OpenGLFunction GL => _contextBinding.GL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RBO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class RenderBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
public RenderBuffer(int count, glRender binding)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenRenderBuffer(count);
|
||||
}
|
||||
|
||||
public override void Bind(int index)
|
||||
{
|
||||
GL.BindRenderBuffer(this[index]);
|
||||
}
|
||||
|
||||
public void Store(RenderBufferInternalFormat format, (int width, int height) size)
|
||||
{
|
||||
if ((size.width > binding.Width) || (size.height > binding.Height)) {
|
||||
World.LogWarning("FrameBuffer is larger than current canvas binding");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
foreach (GlHandle item in _bufferHandle)
|
||||
{
|
||||
Console.WriteLine("removing a render buffer");
|
||||
GL.DeleteRenderBuffer(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RBO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class RenderBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
public RenderBuffer(int count, glRender binding)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenRenderBuffer(count);
|
||||
}
|
||||
|
||||
public override void Bind(int index)
|
||||
{
|
||||
GL.BindRenderBuffer(this[index]);
|
||||
}
|
||||
|
||||
public void Store(RenderBufferInternalFormat format, (int width, int height) size)
|
||||
{
|
||||
if ((size.width > binding.Width) || (size.height > binding.Height)) {
|
||||
World.LogWarning("FrameBuffer is larger than current canvas binding");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
foreach (GlHandle item in _bufferHandle)
|
||||
{
|
||||
Console.WriteLine("removing a render buffer");
|
||||
GL.DeleteRenderBuffer(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,311 +1,311 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TextureGL"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class TextureGL
|
||||
{
|
||||
|
||||
private int currentEditingTextureIndex;
|
||||
|
||||
private OpenGLFunction _gl;
|
||||
internal GlHandle[] _textureHandle;
|
||||
|
||||
internal TextureGL(
|
||||
int count,
|
||||
glRender binding
|
||||
)
|
||||
{
|
||||
// sourceList = new Image[count];
|
||||
this._gl = binding.GL;
|
||||
_textureHandle = _gl.GenTextures(count);
|
||||
}
|
||||
|
||||
public GlHandle this[
|
||||
int index
|
||||
]
|
||||
{
|
||||
get => _textureHandle[index];
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get => _textureHandle.Length;
|
||||
}
|
||||
|
||||
// internal Image[] sourceList;
|
||||
|
||||
public int IndexOfCurrentTexture
|
||||
{
|
||||
get => currentEditingTextureIndex;
|
||||
}
|
||||
|
||||
internal OpenGLFunction GL => _gl;
|
||||
|
||||
public void ActivateAs(
|
||||
TextureUnit unit
|
||||
)
|
||||
{
|
||||
_gl.ActiveTextureUnit((uint)unit);
|
||||
}
|
||||
|
||||
public void Bind2D(
|
||||
int index
|
||||
)
|
||||
{
|
||||
currentEditingTextureIndex = index;
|
||||
_gl.BindTexture(glConst.TEXTURE_2D, _textureHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load an <see cref="Image" /> to certain texture.
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
///
|
||||
/// </param>
|
||||
/// <param _label="i">
|
||||
///
|
||||
/// </param>
|
||||
public unsafe void LoadTexture(
|
||||
int index,
|
||||
Image i
|
||||
)
|
||||
{
|
||||
byte[] handle = i.PixelBuffer;
|
||||
_gl.TextureImage2d(Texture2DTarget.Texture2D, 0, i.Channel, i.Width, i.Height,
|
||||
i.Channel, i.PixelLayout, pixels:handle);
|
||||
_gl.GenerateMipmap(Texture2DTarget.Texture2D);
|
||||
}
|
||||
|
||||
#region texture setting
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Set2dFilterProperty(
|
||||
int index,
|
||||
TextureFilter onMinify,
|
||||
TextureFilter onMagnify
|
||||
)
|
||||
{
|
||||
#if DEBUG
|
||||
if (index != currentEditingTextureIndex)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Texture to be editted is not the one being activated.");
|
||||
}
|
||||
#endif
|
||||
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_MAG_FILTER,
|
||||
(int)onMagnify);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Set2dWrapProperty(
|
||||
int index,
|
||||
TextureWrap onHorizontial,
|
||||
TextureWrap onVertical
|
||||
)
|
||||
{
|
||||
#if DEBUG
|
||||
if (index != currentEditingTextureIndex)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Texture to be editted is not the one being activated.");
|
||||
}
|
||||
#endif
|
||||
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_S,
|
||||
(int)onHorizontial);
|
||||
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Set2dProperty(
|
||||
int index,
|
||||
TextureProperty property
|
||||
)
|
||||
{
|
||||
Set2dFilterProperty(index, property.FilterOnMinify, property.FilterOnMagnify);
|
||||
Set2dWrapProperty(index, property.WrapOnHorizontial, property.WrapOnVertical);
|
||||
}
|
||||
|
||||
#endregion texture setting
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct TextureProperty
|
||||
{
|
||||
|
||||
[FieldOffset(0)] private M128 mask;
|
||||
[FieldOffset(0)] private TextureFilter mag;
|
||||
[FieldOffset(4)] private TextureFilter min;
|
||||
|
||||
[FieldOffset(8)] private TextureWrap hori;
|
||||
[FieldOffset(12)] private TextureWrap vert;
|
||||
|
||||
public TextureProperty(
|
||||
TextureFilter onMagnify,
|
||||
TextureFilter onMinify,
|
||||
TextureWrap onHorizontial,
|
||||
TextureWrap onVertical
|
||||
)
|
||||
{
|
||||
FilterOnMagnify = onMagnify;
|
||||
FilterOnMinify = onMinify;
|
||||
WrapOnHorizontial = onHorizontial;
|
||||
WrapOnVertical = onVertical;
|
||||
}
|
||||
|
||||
public TextureFilter FilterOnMagnify
|
||||
{
|
||||
get => mag;
|
||||
set => mag = value;
|
||||
}
|
||||
|
||||
public TextureFilter FilterOnMinify
|
||||
{
|
||||
get => min;
|
||||
set => min = value;
|
||||
}
|
||||
|
||||
public TextureWrap WrapOnHorizontial
|
||||
{
|
||||
get => hori;
|
||||
set => hori = value;
|
||||
}
|
||||
|
||||
public TextureWrap WrapOnVertical
|
||||
{
|
||||
get => vert;
|
||||
set => vert = value;
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
[NotNullWhen(true)] object obj
|
||||
)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial,
|
||||
WrapOnVertical);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"FilterOnMagnify:{FilterOnMagnify}, " + $"FilterOnMagnify:{FilterOnMagnify}, " + $"WrapOnHorizontial:{WrapOnHorizontial}, " + $"WrapOnVertical:{WrapOnVertical}";
|
||||
}
|
||||
|
||||
public static bool operator !=(
|
||||
TextureProperty left,
|
||||
TextureProperty right
|
||||
)
|
||||
{
|
||||
return left.mask != right.mask;
|
||||
}
|
||||
|
||||
public static bool operator ==(
|
||||
TextureProperty left,
|
||||
TextureProperty right
|
||||
)
|
||||
{
|
||||
return left.mask == right.mask;
|
||||
}
|
||||
|
||||
public static implicit operator TextureProperty(
|
||||
(
|
||||
TextureFilter onMagnify, TextureFilter onMinify,
|
||||
TextureWrap onHorizontial, TextureWrap onVertical
|
||||
) propertyValueTuple
|
||||
)
|
||||
{
|
||||
return new TextureProperty(propertyValueTuple.onMagnify, propertyValueTuple.onMinify,
|
||||
propertyValueTuple.onHorizontial,
|
||||
propertyValueTuple.onVertical);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureFilter
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Nearest = glConst.NEAREST,
|
||||
Linear = glConst.LINEAR,
|
||||
NearestLinearMipmap = glConst.NEAREST_MIPMAP_LINEAR,
|
||||
LinearLinearMipmap = glConst.LINEAR_MIPMAP_LINEAR,
|
||||
NearestNearestMipmap = glConst.NEAREST_MIPMAP_NEAREST,
|
||||
LinearNearestMipmap = glConst.LINEAR_MIPMAP_NEAREST,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureUnit
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Unit0 = glConst.TEXTURE0,
|
||||
Unit1 = glConst.TEXTURE1,
|
||||
Unit2 = glConst.TEXTURE2,
|
||||
Unit3 = glConst.TEXTURE3,
|
||||
Unit4 = glConst.TEXTURE4,
|
||||
Unit5 = glConst.TEXTURE5,
|
||||
Unit6 = glConst.TEXTURE6,
|
||||
Unit7 = glConst.TEXTURE7,
|
||||
Unit8 = glConst.TEXTURE8,
|
||||
Unit9 = glConst.TEXTURE9,
|
||||
Unit10 = glConst.TEXTURE10,
|
||||
Unit11 = glConst.TEXTURE11,
|
||||
Unit12 = glConst.TEXTURE12,
|
||||
Unit13 = glConst.TEXTURE13,
|
||||
Unit14 = glConst.TEXTURE14,
|
||||
Unit15 = glConst.TEXTURE15,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureWrap
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Repeat = glConst.REPEAT,
|
||||
MirroredRepeat = glConst.MIRRORED_REPEAT,
|
||||
ClampToEdge = glConst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = glConst.CLAMP_TO_BORDER,
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TextureGL"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class TextureGL
|
||||
{
|
||||
|
||||
private int currentEditingTextureIndex;
|
||||
|
||||
private OpenGLFunction _gl;
|
||||
internal GlHandle[] _textureHandle;
|
||||
|
||||
internal TextureGL(
|
||||
int count,
|
||||
glRender binding
|
||||
)
|
||||
{
|
||||
// sourceList = new Image[count];
|
||||
this._gl = binding.GL;
|
||||
_textureHandle = _gl.GenTextures(count);
|
||||
}
|
||||
|
||||
public GlHandle this[
|
||||
int index
|
||||
]
|
||||
{
|
||||
get => _textureHandle[index];
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get => _textureHandle.Length;
|
||||
}
|
||||
|
||||
// internal Image[] sourceList;
|
||||
|
||||
public int IndexOfCurrentTexture
|
||||
{
|
||||
get => currentEditingTextureIndex;
|
||||
}
|
||||
|
||||
internal OpenGLFunction GL => _gl;
|
||||
|
||||
public void ActivateAs(
|
||||
TextureUnit unit
|
||||
)
|
||||
{
|
||||
_gl.ActiveTextureUnit((uint)unit);
|
||||
}
|
||||
|
||||
public void Bind2D(
|
||||
int index
|
||||
)
|
||||
{
|
||||
currentEditingTextureIndex = index;
|
||||
_gl.BindTexture(glConst.TEXTURE_2D, _textureHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load an <see cref="Image" /> to certain texture.
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
///
|
||||
/// </param>
|
||||
/// <param _label="i">
|
||||
///
|
||||
/// </param>
|
||||
public unsafe void LoadTexture(
|
||||
int index,
|
||||
Image i
|
||||
)
|
||||
{
|
||||
byte[] handle = i.PixelBuffer;
|
||||
_gl.TextureImage2d(Texture2DTarget.Texture2D, 0, i.Channel, i.Width, i.Height,
|
||||
i.Channel, i.PixelLayout, pixels:handle);
|
||||
_gl.GenerateMipmap(Texture2DTarget.Texture2D);
|
||||
}
|
||||
|
||||
#region texture setting
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Set2dFilterProperty(
|
||||
int index,
|
||||
TextureFilter onMinify,
|
||||
TextureFilter onMagnify
|
||||
)
|
||||
{
|
||||
#if DEBUG
|
||||
if (index != currentEditingTextureIndex)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Texture to be editted is not the one being activated.");
|
||||
}
|
||||
#endif
|
||||
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_MAG_FILTER,
|
||||
(int)onMagnify);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Set2dWrapProperty(
|
||||
int index,
|
||||
TextureWrap onHorizontial,
|
||||
TextureWrap onVertical
|
||||
)
|
||||
{
|
||||
#if DEBUG
|
||||
if (index != currentEditingTextureIndex)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Texture to be editted is not the one being activated.");
|
||||
}
|
||||
#endif
|
||||
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_S,
|
||||
(int)onHorizontial);
|
||||
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Set2dProperty(
|
||||
int index,
|
||||
TextureProperty property
|
||||
)
|
||||
{
|
||||
Set2dFilterProperty(index, property.FilterOnMinify, property.FilterOnMagnify);
|
||||
Set2dWrapProperty(index, property.WrapOnHorizontial, property.WrapOnVertical);
|
||||
}
|
||||
|
||||
#endregion texture setting
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct TextureProperty
|
||||
{
|
||||
|
||||
[FieldOffset(0)] private M128 mask;
|
||||
[FieldOffset(0)] private TextureFilter mag;
|
||||
[FieldOffset(4)] private TextureFilter min;
|
||||
|
||||
[FieldOffset(8)] private TextureWrap hori;
|
||||
[FieldOffset(12)] private TextureWrap vert;
|
||||
|
||||
public TextureProperty(
|
||||
TextureFilter onMagnify,
|
||||
TextureFilter onMinify,
|
||||
TextureWrap onHorizontial,
|
||||
TextureWrap onVertical
|
||||
)
|
||||
{
|
||||
FilterOnMagnify = onMagnify;
|
||||
FilterOnMinify = onMinify;
|
||||
WrapOnHorizontial = onHorizontial;
|
||||
WrapOnVertical = onVertical;
|
||||
}
|
||||
|
||||
public TextureFilter FilterOnMagnify
|
||||
{
|
||||
get => mag;
|
||||
set => mag = value;
|
||||
}
|
||||
|
||||
public TextureFilter FilterOnMinify
|
||||
{
|
||||
get => min;
|
||||
set => min = value;
|
||||
}
|
||||
|
||||
public TextureWrap WrapOnHorizontial
|
||||
{
|
||||
get => hori;
|
||||
set => hori = value;
|
||||
}
|
||||
|
||||
public TextureWrap WrapOnVertical
|
||||
{
|
||||
get => vert;
|
||||
set => vert = value;
|
||||
}
|
||||
|
||||
public override bool Equals(
|
||||
[NotNullWhen(true)] object obj
|
||||
)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial,
|
||||
WrapOnVertical);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"FilterOnMagnify:{FilterOnMagnify}, " + $"FilterOnMagnify:{FilterOnMagnify}, " + $"WrapOnHorizontial:{WrapOnHorizontial}, " + $"WrapOnVertical:{WrapOnVertical}";
|
||||
}
|
||||
|
||||
public static bool operator !=(
|
||||
TextureProperty left,
|
||||
TextureProperty right
|
||||
)
|
||||
{
|
||||
return left.mask != right.mask;
|
||||
}
|
||||
|
||||
public static bool operator ==(
|
||||
TextureProperty left,
|
||||
TextureProperty right
|
||||
)
|
||||
{
|
||||
return left.mask == right.mask;
|
||||
}
|
||||
|
||||
public static implicit operator TextureProperty(
|
||||
(
|
||||
TextureFilter onMagnify, TextureFilter onMinify,
|
||||
TextureWrap onHorizontial, TextureWrap onVertical
|
||||
) propertyValueTuple
|
||||
)
|
||||
{
|
||||
return new TextureProperty(propertyValueTuple.onMagnify, propertyValueTuple.onMinify,
|
||||
propertyValueTuple.onHorizontial,
|
||||
propertyValueTuple.onVertical);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureFilter
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Nearest = glConst.NEAREST,
|
||||
Linear = glConst.LINEAR,
|
||||
NearestLinearMipmap = glConst.NEAREST_MIPMAP_LINEAR,
|
||||
LinearLinearMipmap = glConst.LINEAR_MIPMAP_LINEAR,
|
||||
NearestNearestMipmap = glConst.NEAREST_MIPMAP_NEAREST,
|
||||
LinearNearestMipmap = glConst.LINEAR_MIPMAP_NEAREST,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureUnit
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Unit0 = glConst.TEXTURE0,
|
||||
Unit1 = glConst.TEXTURE1,
|
||||
Unit2 = glConst.TEXTURE2,
|
||||
Unit3 = glConst.TEXTURE3,
|
||||
Unit4 = glConst.TEXTURE4,
|
||||
Unit5 = glConst.TEXTURE5,
|
||||
Unit6 = glConst.TEXTURE6,
|
||||
Unit7 = glConst.TEXTURE7,
|
||||
Unit8 = glConst.TEXTURE8,
|
||||
Unit9 = glConst.TEXTURE9,
|
||||
Unit10 = glConst.TEXTURE10,
|
||||
Unit11 = glConst.TEXTURE11,
|
||||
Unit12 = glConst.TEXTURE12,
|
||||
Unit13 = glConst.TEXTURE13,
|
||||
Unit14 = glConst.TEXTURE14,
|
||||
Unit15 = glConst.TEXTURE15,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureWrap
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Repeat = glConst.REPEAT,
|
||||
MirroredRepeat = glConst.MIRRORED_REPEAT,
|
||||
ClampToEdge = glConst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = glConst.CLAMP_TO_BORDER,
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,86 +1,86 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="VAO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class VertexArray : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexArray(
|
||||
int n,
|
||||
glRender binding
|
||||
)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenVertexArrays(n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public sealed override void Bind(
|
||||
int index
|
||||
)
|
||||
{
|
||||
GL.BindVertexArray(_bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindNull()
|
||||
{
|
||||
OpenGLFunction.CurrentGL.BindVertexArray(GlHandle.Zero);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVertexAttribute(
|
||||
uint attributeIndex,
|
||||
int vertexLength,
|
||||
TypeCode dataType,
|
||||
bool isNomalized,
|
||||
int stride,
|
||||
int pointer
|
||||
)
|
||||
{
|
||||
GL.SetVertexAttribute(attributeIndex, vertexLength, dataType, isNomalized, stride,
|
||||
pointer);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteVertexArrays(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="VAO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class VertexArray : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexArray(
|
||||
int n,
|
||||
glRender binding
|
||||
)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenVertexArrays(n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public sealed override void Bind(
|
||||
int index
|
||||
)
|
||||
{
|
||||
GL.BindVertexArray(_bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindNull()
|
||||
{
|
||||
OpenGLFunction.CurrentGL.BindVertexArray(GlHandle.Zero);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVertexAttribute(
|
||||
uint attributeIndex,
|
||||
int vertexLength,
|
||||
TypeCode dataType,
|
||||
bool isNomalized,
|
||||
int stride,
|
||||
int pointer
|
||||
)
|
||||
{
|
||||
GL.SetVertexAttribute(attributeIndex, vertexLength, dataType, isNomalized, stride,
|
||||
pointer);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteVertexArrays(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,181 +1,181 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="VBO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Security;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class VertexBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexBuffer(
|
||||
int n,
|
||||
glRender binding
|
||||
)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
|
||||
public sealed override void Bind(
|
||||
int index
|
||||
)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, GlHandle.Zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="bufferArray">
|
||||
/// Data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteScalerData<T>(
|
||||
int index,
|
||||
T[] bufferArray,
|
||||
BufferUsage usage
|
||||
) where T : unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="scalerSpan">
|
||||
/// A <see cref="Span{T}" /> of _data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteScalerData<T>(
|
||||
int index,
|
||||
ReadOnlySpan<T> scalerSpan,
|
||||
BufferUsage usage
|
||||
) where T : unmanaged,INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex BufferHandle object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="vectorSpan">
|
||||
/// A <see cref="Span{T}" /> of data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteVectorData<T>(
|
||||
int index,
|
||||
ReadOnlySpan<T> vectorSpan,
|
||||
BufferUsage usage
|
||||
) where T : unmanaged, IUnmanagedVector<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="vectorArray">
|
||||
/// A array of _data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteVectorData<T>(
|
||||
int index,
|
||||
T[] vectorArray,
|
||||
BufferUsage usage
|
||||
) where T : unmanaged, IUnmanagedVector<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="VBO"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Security;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class VertexBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexBuffer(
|
||||
int n,
|
||||
glRender binding
|
||||
)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
|
||||
public sealed override void Bind(
|
||||
int index
|
||||
)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, GlHandle.Zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="bufferArray">
|
||||
/// Data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteScalerData<T>(
|
||||
int index,
|
||||
T[] bufferArray,
|
||||
BufferUsage usage
|
||||
) where T : unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="scalerSpan">
|
||||
/// A <see cref="Span{T}" /> of _data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteScalerData<T>(
|
||||
int index,
|
||||
ReadOnlySpan<T> scalerSpan,
|
||||
BufferUsage usage
|
||||
) where T : unmanaged,INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex BufferHandle object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="vectorSpan">
|
||||
/// A <see cref="Span{T}" /> of data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteVectorData<T>(
|
||||
int index,
|
||||
ReadOnlySpan<T> vectorSpan,
|
||||
BufferUsage usage
|
||||
) where T : unmanaged, IUnmanagedVector<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="vectorArray">
|
||||
/// A array of _data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteVectorData<T>(
|
||||
int index,
|
||||
T[] vectorArray,
|
||||
BufferUsage usage
|
||||
) where T : unmanaged, IUnmanagedVector<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,65 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IglConvertable"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public interface IglConvertable
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisplayGLtypeDefinition();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public ShaderStruct GetConvertedGLtype();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void SetAllUniforms();
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IglConvertable"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public interface IglConvertable
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisplayGLtypeDefinition();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public ShaderStruct GetConvertedGLtype();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void SetAllUniforms();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,318 +1,318 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Shader"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Internal;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract partial class glRender : RenderStream
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Create an instance of <see cref="Shader" /> program
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// New instance of <see cref="Shader" /> instance.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override ShaderProgram CreateShaderProgram()
|
||||
{
|
||||
return new ShaderProgram(this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override Shader CreateShaderSegment(
|
||||
ShaderType type,
|
||||
int count
|
||||
)
|
||||
{
|
||||
return new Shader(GL.CreateShaderSet(count, type), type, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Shader : ISSDSerializable
|
||||
{
|
||||
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle[] handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
internal unsafe Shader(
|
||||
GlHandle[] handle,
|
||||
ShaderType usage,
|
||||
glRender stream
|
||||
)
|
||||
{
|
||||
this.handle = handle;
|
||||
GL = stream.GL;
|
||||
type = usage;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
/// <summary>
|
||||
/// Attach one shader code to a shader program.
|
||||
/// </summary>
|
||||
/// <param _label="target">
|
||||
/// Shader program to attach
|
||||
/// </param>
|
||||
/// <param _label="index">
|
||||
/// Index of shader code in current shader code set.
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachTo(
|
||||
int index,
|
||||
[NotNull]ShaderProgram target
|
||||
)
|
||||
{
|
||||
GL.AttachShader(target.handle, handle[index]);
|
||||
}
|
||||
|
||||
public void CheckStatus(
|
||||
int index,
|
||||
ShaderStatus status
|
||||
)
|
||||
{
|
||||
string log = GL.GetShaderStatus(this, index, (int)status);
|
||||
if (!string.IsNullOrEmpty(log)) {
|
||||
throw new InvalidOperationException($"{$"Shader Error \t{status}\n"}{log}");
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(
|
||||
int index,
|
||||
ReadOnlySpan<byte> codeU8Stream
|
||||
)
|
||||
{
|
||||
GL.LoadShaderSource(handle[index], codeU8Stream);
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(
|
||||
int index,
|
||||
byte[] codeStream
|
||||
)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(codeStream);
|
||||
GL.LoadShaderSource(handle[index], codeStream);
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(
|
||||
int index,
|
||||
string codeStream
|
||||
)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(codeStream);
|
||||
GL.LoadShaderSource(handle[index], codeStream.AsSpan());
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
public void FromBytes(
|
||||
byte[] stream
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static byte[] FromCodeFile(
|
||||
string fileRoute
|
||||
)
|
||||
{
|
||||
string str = File.ReadAllText(fileRoute);
|
||||
if (string.IsNullOrEmpty(str)) {
|
||||
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
|
||||
}
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public byte[] GetBytes(
|
||||
out int length
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ShaderStatus : int
|
||||
{
|
||||
|
||||
CompileStatus = glConst.COMPILE_STATUS,
|
||||
|
||||
}
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle handle;
|
||||
|
||||
/// <summary>
|
||||
/// CustomizeInit a program with no shader attached.
|
||||
/// </summary>
|
||||
internal unsafe ShaderProgram(
|
||||
glRender binding
|
||||
)
|
||||
{
|
||||
GL = binding.GL;
|
||||
handle = GL.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe Uniform<T> GetUniform<T>(
|
||||
string name
|
||||
) where T : unmanaged
|
||||
{
|
||||
return new Uniform<T>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public unsafe Uniform<T, U> GetUniform<T, U>(
|
||||
string name
|
||||
) where T : unmanaged where U : struct
|
||||
{
|
||||
return new Uniform<T, U>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(
|
||||
string name
|
||||
) where T : unmanaged where U : struct where V : struct
|
||||
{
|
||||
return new Uniform<T, U, V>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>(
|
||||
string name
|
||||
) where T : unmanaged where U : struct where V : struct where W : struct
|
||||
{
|
||||
return new Uniform<T, U, V, W>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the shader to current viewPortDisplay.
|
||||
/// </summary>
|
||||
public unsafe void Link()
|
||||
{
|
||||
if (GraphicFramework.InternalLinkShaderProgram(
|
||||
(OpenglContext*)this.GL.ContextHandle, handle.Value) == 0)
|
||||
{
|
||||
IntPtr logPtr = GraphicFramework.InternalReadSSCLog();
|
||||
try
|
||||
{
|
||||
byte[] logByte = new byte[512];
|
||||
Marshal.Copy(logPtr, logByte, 0, 512);
|
||||
string log = Encoding.UTF8.GetString(logByte);
|
||||
log = log.Replace("\0", string.Empty);
|
||||
DefaultLog.InternalWriteLog(log, LogType.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(ex.Message, LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Let the current viewPortDisplay use this shader.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
GL.UseProgram(handle);
|
||||
}
|
||||
|
||||
~ShaderProgram()
|
||||
{
|
||||
// handle.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Shader"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Internal;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract partial class glRender : RenderStream
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Create an instance of <see cref="Shader" /> program
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// New instance of <see cref="Shader" /> instance.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override ShaderProgram CreateShaderProgram()
|
||||
{
|
||||
return new ShaderProgram(this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override Shader CreateShaderSegment(
|
||||
ShaderType type,
|
||||
int count
|
||||
)
|
||||
{
|
||||
return new Shader(GL.CreateShaderSet(count, type), type, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Shader : ISSDSerializable
|
||||
{
|
||||
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle[] handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
internal unsafe Shader(
|
||||
GlHandle[] handle,
|
||||
ShaderType usage,
|
||||
glRender stream
|
||||
)
|
||||
{
|
||||
this.handle = handle;
|
||||
GL = stream.GL;
|
||||
type = usage;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
/// <summary>
|
||||
/// Attach one shader code to a shader program.
|
||||
/// </summary>
|
||||
/// <param _label="target">
|
||||
/// Shader program to attach
|
||||
/// </param>
|
||||
/// <param _label="index">
|
||||
/// Index of shader code in current shader code set.
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachTo(
|
||||
int index,
|
||||
[NotNull]ShaderProgram target
|
||||
)
|
||||
{
|
||||
GL.AttachShader(target.handle, handle[index]);
|
||||
}
|
||||
|
||||
public void CheckStatus(
|
||||
int index,
|
||||
ShaderStatus status
|
||||
)
|
||||
{
|
||||
string log = GL.GetShaderStatus(this, index, (int)status);
|
||||
if (!string.IsNullOrEmpty(log)) {
|
||||
throw new InvalidOperationException($"{$"Shader Error \t{status}\n"}{log}");
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(
|
||||
int index,
|
||||
ReadOnlySpan<byte> codeU8Stream
|
||||
)
|
||||
{
|
||||
GL.LoadShaderSource(handle[index], codeU8Stream);
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(
|
||||
int index,
|
||||
byte[] codeStream
|
||||
)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(codeStream);
|
||||
GL.LoadShaderSource(handle[index], codeStream);
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(
|
||||
int index,
|
||||
string codeStream
|
||||
)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(codeStream);
|
||||
GL.LoadShaderSource(handle[index], codeStream.AsSpan());
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
public void FromBytes(
|
||||
byte[] stream
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static byte[] FromCodeFile(
|
||||
string fileRoute
|
||||
)
|
||||
{
|
||||
string str = File.ReadAllText(fileRoute);
|
||||
if (string.IsNullOrEmpty(str)) {
|
||||
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
|
||||
}
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public byte[] GetBytes(
|
||||
out int length
|
||||
)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ShaderStatus : int
|
||||
{
|
||||
|
||||
CompileStatus = glConst.COMPILE_STATUS,
|
||||
|
||||
}
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle handle;
|
||||
|
||||
/// <summary>
|
||||
/// CustomizeInit a program with no shader attached.
|
||||
/// </summary>
|
||||
internal unsafe ShaderProgram(
|
||||
glRender binding
|
||||
)
|
||||
{
|
||||
GL = binding.GL;
|
||||
handle = GL.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe Uniform<T> GetUniform<T>(
|
||||
string name
|
||||
) where T : unmanaged
|
||||
{
|
||||
return new Uniform<T>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public unsafe Uniform<T, U> GetUniform<T, U>(
|
||||
string name
|
||||
) where T : unmanaged where U : struct
|
||||
{
|
||||
return new Uniform<T, U>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(
|
||||
string name
|
||||
) where T : unmanaged where U : struct where V : struct
|
||||
{
|
||||
return new Uniform<T, U, V>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>(
|
||||
string name
|
||||
) where T : unmanaged where U : struct where V : struct where W : struct
|
||||
{
|
||||
return new Uniform<T, U, V, W>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the shader to current viewPortDisplay.
|
||||
/// </summary>
|
||||
public unsafe void Link()
|
||||
{
|
||||
if (GraphicFramework.InternalLinkShaderProgram(
|
||||
(OpenglContext*)this.GL.ContextHandle, handle.Value) == 0)
|
||||
{
|
||||
IntPtr logPtr = GraphicFramework.InternalReadSSCLog();
|
||||
try
|
||||
{
|
||||
byte[] logByte = new byte[512];
|
||||
Marshal.Copy(logPtr, logByte, 0, 512);
|
||||
string log = Encoding.UTF8.GetString(logByte);
|
||||
log = log.Replace("\0", string.Empty);
|
||||
DefaultLog.InternalWriteLog(log, LogType.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DefaultLog.InternalWriteLog(ex.Message, LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Let the current viewPortDisplay use this shader.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
GL.UseProgram(handle);
|
||||
}
|
||||
|
||||
~ShaderProgram()
|
||||
{
|
||||
// handle.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,225 +1,225 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Uniform"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
|
||||
internal GlHandle id;
|
||||
|
||||
public GlHandle Handle => id;
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform where T : unmanaged
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform(
|
||||
GlHandle id
|
||||
)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T> FromHandle(
|
||||
GlHandle handle
|
||||
)
|
||||
{
|
||||
return new Uniform<T>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U> : Uniform where T : unmanaged where U : struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform(
|
||||
GlHandle id
|
||||
)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U> FromHandle(
|
||||
GlHandle handle
|
||||
)
|
||||
{
|
||||
return new Uniform<T, U>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V> : Uniform where T : unmanaged where U : struct
|
||||
where V : struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform(
|
||||
GlHandle id
|
||||
)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V> FromHandle(
|
||||
GlHandle handle
|
||||
)
|
||||
{
|
||||
return new Uniform<T, U, V>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V, W> : Uniform where T : unmanaged where U : struct
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform(
|
||||
GlHandle id
|
||||
)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V, W> FromHandle(
|
||||
GlHandle handle
|
||||
)
|
||||
{
|
||||
return new Uniform<T, U, V, W>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<Matrix44> uniform,
|
||||
Matrix44 mat
|
||||
)
|
||||
{
|
||||
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, (byte)0, (float*)&mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<float, float, float, float> uniform,
|
||||
Vec4 vec
|
||||
)
|
||||
{
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, (float*)&vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<Vec4> uniform,
|
||||
Vec4 vec
|
||||
)
|
||||
{
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, (float*)&vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<float> uniform,
|
||||
float v0
|
||||
)
|
||||
{
|
||||
Context.glUniform1f(uniform.id.SignedValue, v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<int> uniform,
|
||||
int i0
|
||||
)
|
||||
{
|
||||
Context.glUniform1i(uniform.id.SignedValue, i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<float, float> uniform,
|
||||
float v0,
|
||||
float v1
|
||||
)
|
||||
{
|
||||
Context.glUniform2f(uniform.id.SignedValue, v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<float, float, float> uniform,
|
||||
float v0,
|
||||
float v1,
|
||||
float v2
|
||||
)
|
||||
{
|
||||
Context.glUniform3f(uniform.id.SignedValue, v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<float, float, float, float> uniform,
|
||||
float v0,
|
||||
float v1,
|
||||
float v2,
|
||||
float v3
|
||||
)
|
||||
{
|
||||
Context.glUniform4f(uniform.id.SignedValue, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Uniform"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
|
||||
internal GlHandle id;
|
||||
|
||||
public GlHandle Handle => id;
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform where T : unmanaged
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform(
|
||||
GlHandle id
|
||||
)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T> FromHandle(
|
||||
GlHandle handle
|
||||
)
|
||||
{
|
||||
return new Uniform<T>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U> : Uniform where T : unmanaged where U : struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform(
|
||||
GlHandle id
|
||||
)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U> FromHandle(
|
||||
GlHandle handle
|
||||
)
|
||||
{
|
||||
return new Uniform<T, U>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V> : Uniform where T : unmanaged where U : struct
|
||||
where V : struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform(
|
||||
GlHandle id
|
||||
)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V> FromHandle(
|
||||
GlHandle handle
|
||||
)
|
||||
{
|
||||
return new Uniform<T, U, V>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V, W> : Uniform where T : unmanaged where U : struct
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform(
|
||||
GlHandle id
|
||||
)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V, W> FromHandle(
|
||||
GlHandle handle
|
||||
)
|
||||
{
|
||||
return new Uniform<T, U, V, W>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<Matrix44> uniform,
|
||||
Matrix44 mat
|
||||
)
|
||||
{
|
||||
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, (byte)0, (float*)&mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<float, float, float, float> uniform,
|
||||
Vec4 vec
|
||||
)
|
||||
{
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, (float*)&vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<Vec4> uniform,
|
||||
Vec4 vec
|
||||
)
|
||||
{
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, (float*)&vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<float> uniform,
|
||||
float v0
|
||||
)
|
||||
{
|
||||
Context.glUniform1f(uniform.id.SignedValue, v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<int> uniform,
|
||||
int i0
|
||||
)
|
||||
{
|
||||
Context.glUniform1i(uniform.id.SignedValue, i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<float, float> uniform,
|
||||
float v0,
|
||||
float v1
|
||||
)
|
||||
{
|
||||
Context.glUniform2f(uniform.id.SignedValue, v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<float, float, float> uniform,
|
||||
float v0,
|
||||
float v1,
|
||||
float v2
|
||||
)
|
||||
{
|
||||
Context.glUniform3f(uniform.id.SignedValue, v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<float, float, float, float> uniform,
|
||||
float v0,
|
||||
float v1,
|
||||
float v2,
|
||||
float v3
|
||||
)
|
||||
{
|
||||
Context.glUniform4f(uniform.id.SignedValue, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+4563
-4563
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,224 +1,224 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glEnum"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public enum PixelChannelLayout
|
||||
{
|
||||
|
||||
UByte = glConst.UNSIGNED_BYTE,
|
||||
Byte = glConst.BYTE,
|
||||
UShort = glConst.UNSIGNED_SHORT,
|
||||
Short = glConst.SHORT,
|
||||
UInt = glConst.UNSIGNED_INT,
|
||||
Int = glConst.INT,
|
||||
Float = glConst.FLOAT,
|
||||
UByte332 = glConst.UNSIGNED_BYTE_3_3_2,
|
||||
UByte233Rev = glConst.UNSIGNED_BYTE_2_3_3_REV,
|
||||
UShort565 = glConst.UNSIGNED_SHORT_5_6_5,
|
||||
UShort565Rev = glConst.UNSIGNED_SHORT_5_6_5_REV,
|
||||
UShort4444 = glConst.UNSIGNED_SHORT_4_4_4_4,
|
||||
UShort4444Rev = glConst.UNSIGNED_SHORT_4_4_4_4_REV,
|
||||
UShort5551 = glConst.UNSIGNED_SHORT_5_5_5_1,
|
||||
UShort1555Rev = glConst.UNSIGNED_SHORT_1_5_5_5_REV,
|
||||
UInt8888 = glConst.UNSIGNED_INT_8_8_8_8,
|
||||
UInt8888Rev = glConst.UNSIGNED_INT_8_8_8_8_REV,
|
||||
UInt1010102 = glConst.UNSIGNED_INT_10_10_10_2,
|
||||
UInt2101010Rev = glConst.UNSIGNED_INT_2_10_10_10_REV
|
||||
|
||||
}
|
||||
|
||||
public enum FaceMode
|
||||
{
|
||||
|
||||
Point = glConst.POINT,
|
||||
Line = glConst.LINE,
|
||||
Fill = glConst.FILL
|
||||
|
||||
}
|
||||
|
||||
public enum FrameBufferStatus
|
||||
{
|
||||
|
||||
Complete = glConst.FRAMEBUFFER_COMPLETE, // GL_FRAMEBUFFER_COMPLETE
|
||||
IncompleteAttachment = glConst.FRAMEBUFFER_INCOMPLETE_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
|
||||
IncompleteMissingAttachment = glConst.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
|
||||
IncompleteDrawBuffer = glConst.FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
|
||||
IncompleteReadBuffer = glConst.FRAMEBUFFER_INCOMPLETE_READ_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
|
||||
Unsupported = glConst.FRAMEBUFFER_UNSUPPORTED, // GL_FRAMEBUFFER_UNSUPPORTED
|
||||
IncompleteMultiSample = glConst.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, // GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
|
||||
IncompleteLayerTargets = glConst.FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS // GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
|
||||
|
||||
}
|
||||
|
||||
public enum FrameBufferChannel
|
||||
{
|
||||
|
||||
STENCIL_INDEX = glConst.STENCIL_INDEX,
|
||||
DEPTH_COMPONENT = glConst.DEPTH_COMPONENT,
|
||||
DEPTH_STENCIL = glConst.DEPTH_STENCIL,
|
||||
RED = glConst.RED,
|
||||
GREEN = glConst.GREEN,
|
||||
BLUE = glConst.BLUE,
|
||||
RGB = glConst.RGB,
|
||||
BGR = glConst.BGR,
|
||||
RGBA = glConst.RGBA,
|
||||
BGRA = glConst.BGRA
|
||||
|
||||
}
|
||||
|
||||
public enum FrameBufferAttachment
|
||||
{
|
||||
|
||||
Color = glConst.COLOR_ATTACHMENT0,
|
||||
Depth = glConst.DEPTH_ATTACHMENT,
|
||||
Stencil = glConst.STENCIL_ATTACHMENT,
|
||||
DepthAndStencil = glConst.DEPTH_STENCIL_ATTACHMENT,
|
||||
|
||||
}
|
||||
|
||||
public enum Texture2DTarget
|
||||
{
|
||||
|
||||
Texture2D = glConst.TEXTURE_2D,
|
||||
ProxyTexture2D = glConst.PROXY_TEXTURE_2D,
|
||||
Texture1DArray = glConst.TEXTURE_1D_ARRAY,
|
||||
ProxyTexture1DArray = glConst.PROXY_TEXTURE_1D_ARRAY,
|
||||
TextureRectangle = glConst.TEXTURE_RECTANGLE,
|
||||
ProxyTextureRectangle = glConst.PROXY_TEXTURE_RECTANGLE,
|
||||
TextureCubeMapPositiveX = glConst.TEXTURE_CUBE_MAP_POSITIVE_X,
|
||||
TextureCubeMapNegativeX = glConst.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
TextureCubeMapPositiveY = glConst.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||
TextureCubeMapNegativeY = glConst.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
TextureCubeMapPositiveZ = glConst.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||
TextureCubeMapNegativeZ = glConst.TEXTURE_CUBE_MAP_NEGATIVE_Z,
|
||||
ProxyTextureCubeMap = glConst.PROXY_TEXTURE_CUBE_MAP
|
||||
|
||||
}
|
||||
|
||||
public enum RenderBufferInternalFormat : uint
|
||||
{
|
||||
|
||||
RGBA8 = glConst.RGBA8,
|
||||
Depth24_Stencil8 = glConst.DEPTH24_STENCIL8,
|
||||
|
||||
}
|
||||
|
||||
public enum glOperation : uint
|
||||
{
|
||||
|
||||
StencilTest = glConst.STENCIL_TEST,
|
||||
DepthTest = glConst.DEPTH_TEST,
|
||||
PolygonOffsetFill = glConst.POLYGON_OFFSET_FILL,
|
||||
PolygonOffsetLine = glConst.POLYGON_OFFSET_LINE,
|
||||
PolygonOffsetPoint = glConst.POLYGON_OFFSET_POINT,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum ShaderType : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Fragment = glConst.FRAGMENT_SHADER,
|
||||
Vertex = glConst.VERTEX_SHADER,
|
||||
Compute = glConst.COMPUTE_SHADER,
|
||||
Geometry = glConst.GEOMETRY_SHADER,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum BufferType : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
ArrayBuffer = glConst.ARRAY_BUFFER,
|
||||
ElementArrayBuffer = glConst.ELEMENT_ARRAY_BUFFER,
|
||||
AtomicCounterBuffer = glConst.ATOMIC_COUNTER_BUFFER,
|
||||
CopyHeadBuffer = glConst.COPY_READ_BUFFER,
|
||||
COPY_WRITE_BUFFER = glConst.COPY_WRITE_BUFFER,
|
||||
DISPATCH_INDIRECT_BUFFER = glConst.DISPATCH_INDIRECT_BUFFER,
|
||||
DRAW_INDIRECT_BUFFER = glConst.DRAW_INDIRECT_BUFFER,
|
||||
PIXEL_PACK_BUFFER = glConst.PIXEL_PACK_BUFFER,
|
||||
PIXEL_UNPACK_BUFFER = glConst.PIXEL_UNPACK_BUFFER,
|
||||
QUERY_BUFFER = glConst.QUERY_BUFFER,
|
||||
ShaderStorageBuffer = glConst.SHADER_STORAGE_BUFFER,
|
||||
TEXTURE_BUFFER = glConst.TEXTURE_BUFFER,
|
||||
TRANSFORM_FEEDBACK_BUFFER = glConst.TRANSFORM_FEEDBACK_BUFFER,
|
||||
UNIFORM_BUFFER = glConst.UNIFORM_BUFFER,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum BufferUsage : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
StreamDraw = 0x88E0,
|
||||
StreamRead = 0x88E1,
|
||||
StreamCopy = 0x88E2,
|
||||
StaticDraw = 0x88E4,
|
||||
StaticRead = 0x88E5,
|
||||
StaticCopy = 0x88E6,
|
||||
DynamicDraw = 0x88E8,
|
||||
DynamicRead = 0x88E9,
|
||||
DynamicCopy = 0x88EA
|
||||
|
||||
}
|
||||
|
||||
public enum MaskBufferBit
|
||||
{
|
||||
|
||||
COLOR = glConst.COLOR_BUFFER_BIT,
|
||||
DEPTH = glConst.DEPTH_BUFFER_BIT,
|
||||
STENCIL = glConst.STENCIL_BUFFER_BIT,
|
||||
|
||||
}
|
||||
|
||||
public enum GeometryType : uint
|
||||
{
|
||||
|
||||
POINTS = 0x0000,
|
||||
LINES = 0x0001,
|
||||
LINE_LOOP = 0x0002,
|
||||
LINE_STRIP = 0x0003,
|
||||
TRIANGLES = 0x0004,
|
||||
TRIANGLE_STRIP = 0x0005,
|
||||
TRIANGLE_FAN = 0x0006
|
||||
|
||||
}
|
||||
|
||||
public enum TextureFiltering
|
||||
{
|
||||
|
||||
Nearest = 0x2600,
|
||||
Linear = 0x2601
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glEnum"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public enum PixelChannelLayout
|
||||
{
|
||||
|
||||
UByte = glConst.UNSIGNED_BYTE,
|
||||
Byte = glConst.BYTE,
|
||||
UShort = glConst.UNSIGNED_SHORT,
|
||||
Short = glConst.SHORT,
|
||||
UInt = glConst.UNSIGNED_INT,
|
||||
Int = glConst.INT,
|
||||
Float = glConst.FLOAT,
|
||||
UByte332 = glConst.UNSIGNED_BYTE_3_3_2,
|
||||
UByte233Rev = glConst.UNSIGNED_BYTE_2_3_3_REV,
|
||||
UShort565 = glConst.UNSIGNED_SHORT_5_6_5,
|
||||
UShort565Rev = glConst.UNSIGNED_SHORT_5_6_5_REV,
|
||||
UShort4444 = glConst.UNSIGNED_SHORT_4_4_4_4,
|
||||
UShort4444Rev = glConst.UNSIGNED_SHORT_4_4_4_4_REV,
|
||||
UShort5551 = glConst.UNSIGNED_SHORT_5_5_5_1,
|
||||
UShort1555Rev = glConst.UNSIGNED_SHORT_1_5_5_5_REV,
|
||||
UInt8888 = glConst.UNSIGNED_INT_8_8_8_8,
|
||||
UInt8888Rev = glConst.UNSIGNED_INT_8_8_8_8_REV,
|
||||
UInt1010102 = glConst.UNSIGNED_INT_10_10_10_2,
|
||||
UInt2101010Rev = glConst.UNSIGNED_INT_2_10_10_10_REV
|
||||
|
||||
}
|
||||
|
||||
public enum FaceMode
|
||||
{
|
||||
|
||||
Point = glConst.POINT,
|
||||
Line = glConst.LINE,
|
||||
Fill = glConst.FILL
|
||||
|
||||
}
|
||||
|
||||
public enum FrameBufferStatus
|
||||
{
|
||||
|
||||
Complete = glConst.FRAMEBUFFER_COMPLETE, // GL_FRAMEBUFFER_COMPLETE
|
||||
IncompleteAttachment = glConst.FRAMEBUFFER_INCOMPLETE_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
|
||||
IncompleteMissingAttachment = glConst.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
|
||||
IncompleteDrawBuffer = glConst.FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
|
||||
IncompleteReadBuffer = glConst.FRAMEBUFFER_INCOMPLETE_READ_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
|
||||
Unsupported = glConst.FRAMEBUFFER_UNSUPPORTED, // GL_FRAMEBUFFER_UNSUPPORTED
|
||||
IncompleteMultiSample = glConst.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, // GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
|
||||
IncompleteLayerTargets = glConst.FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS // GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
|
||||
|
||||
}
|
||||
|
||||
public enum FrameBufferChannel
|
||||
{
|
||||
|
||||
STENCIL_INDEX = glConst.STENCIL_INDEX,
|
||||
DEPTH_COMPONENT = glConst.DEPTH_COMPONENT,
|
||||
DEPTH_STENCIL = glConst.DEPTH_STENCIL,
|
||||
RED = glConst.RED,
|
||||
GREEN = glConst.GREEN,
|
||||
BLUE = glConst.BLUE,
|
||||
RGB = glConst.RGB,
|
||||
BGR = glConst.BGR,
|
||||
RGBA = glConst.RGBA,
|
||||
BGRA = glConst.BGRA
|
||||
|
||||
}
|
||||
|
||||
public enum FrameBufferAttachment
|
||||
{
|
||||
|
||||
Color = glConst.COLOR_ATTACHMENT0,
|
||||
Depth = glConst.DEPTH_ATTACHMENT,
|
||||
Stencil = glConst.STENCIL_ATTACHMENT,
|
||||
DepthAndStencil = glConst.DEPTH_STENCIL_ATTACHMENT,
|
||||
|
||||
}
|
||||
|
||||
public enum Texture2DTarget
|
||||
{
|
||||
|
||||
Texture2D = glConst.TEXTURE_2D,
|
||||
ProxyTexture2D = glConst.PROXY_TEXTURE_2D,
|
||||
Texture1DArray = glConst.TEXTURE_1D_ARRAY,
|
||||
ProxyTexture1DArray = glConst.PROXY_TEXTURE_1D_ARRAY,
|
||||
TextureRectangle = glConst.TEXTURE_RECTANGLE,
|
||||
ProxyTextureRectangle = glConst.PROXY_TEXTURE_RECTANGLE,
|
||||
TextureCubeMapPositiveX = glConst.TEXTURE_CUBE_MAP_POSITIVE_X,
|
||||
TextureCubeMapNegativeX = glConst.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
TextureCubeMapPositiveY = glConst.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||
TextureCubeMapNegativeY = glConst.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
TextureCubeMapPositiveZ = glConst.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||
TextureCubeMapNegativeZ = glConst.TEXTURE_CUBE_MAP_NEGATIVE_Z,
|
||||
ProxyTextureCubeMap = glConst.PROXY_TEXTURE_CUBE_MAP
|
||||
|
||||
}
|
||||
|
||||
public enum RenderBufferInternalFormat : uint
|
||||
{
|
||||
|
||||
RGBA8 = glConst.RGBA8,
|
||||
Depth24_Stencil8 = glConst.DEPTH24_STENCIL8,
|
||||
|
||||
}
|
||||
|
||||
public enum glOperation : uint
|
||||
{
|
||||
|
||||
StencilTest = glConst.STENCIL_TEST,
|
||||
DepthTest = glConst.DEPTH_TEST,
|
||||
PolygonOffsetFill = glConst.POLYGON_OFFSET_FILL,
|
||||
PolygonOffsetLine = glConst.POLYGON_OFFSET_LINE,
|
||||
PolygonOffsetPoint = glConst.POLYGON_OFFSET_POINT,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum ShaderType : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Fragment = glConst.FRAGMENT_SHADER,
|
||||
Vertex = glConst.VERTEX_SHADER,
|
||||
Compute = glConst.COMPUTE_SHADER,
|
||||
Geometry = glConst.GEOMETRY_SHADER,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum BufferType : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
ArrayBuffer = glConst.ARRAY_BUFFER,
|
||||
ElementArrayBuffer = glConst.ELEMENT_ARRAY_BUFFER,
|
||||
AtomicCounterBuffer = glConst.ATOMIC_COUNTER_BUFFER,
|
||||
CopyHeadBuffer = glConst.COPY_READ_BUFFER,
|
||||
COPY_WRITE_BUFFER = glConst.COPY_WRITE_BUFFER,
|
||||
DISPATCH_INDIRECT_BUFFER = glConst.DISPATCH_INDIRECT_BUFFER,
|
||||
DRAW_INDIRECT_BUFFER = glConst.DRAW_INDIRECT_BUFFER,
|
||||
PIXEL_PACK_BUFFER = glConst.PIXEL_PACK_BUFFER,
|
||||
PIXEL_UNPACK_BUFFER = glConst.PIXEL_UNPACK_BUFFER,
|
||||
QUERY_BUFFER = glConst.QUERY_BUFFER,
|
||||
ShaderStorageBuffer = glConst.SHADER_STORAGE_BUFFER,
|
||||
TEXTURE_BUFFER = glConst.TEXTURE_BUFFER,
|
||||
TRANSFORM_FEEDBACK_BUFFER = glConst.TRANSFORM_FEEDBACK_BUFFER,
|
||||
UNIFORM_BUFFER = glConst.UNIFORM_BUFFER,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum BufferUsage : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
StreamDraw = 0x88E0,
|
||||
StreamRead = 0x88E1,
|
||||
StreamCopy = 0x88E2,
|
||||
StaticDraw = 0x88E4,
|
||||
StaticRead = 0x88E5,
|
||||
StaticCopy = 0x88E6,
|
||||
DynamicDraw = 0x88E8,
|
||||
DynamicRead = 0x88E9,
|
||||
DynamicCopy = 0x88EA
|
||||
|
||||
}
|
||||
|
||||
public enum MaskBufferBit
|
||||
{
|
||||
|
||||
COLOR = glConst.COLOR_BUFFER_BIT,
|
||||
DEPTH = glConst.DEPTH_BUFFER_BIT,
|
||||
STENCIL = glConst.STENCIL_BUFFER_BIT,
|
||||
|
||||
}
|
||||
|
||||
public enum GeometryType : uint
|
||||
{
|
||||
|
||||
POINTS = 0x0000,
|
||||
LINES = 0x0001,
|
||||
LINE_LOOP = 0x0002,
|
||||
LINE_STRIP = 0x0003,
|
||||
TRIANGLES = 0x0004,
|
||||
TRIANGLE_STRIP = 0x0005,
|
||||
TRIANGLE_FAN = 0x0006
|
||||
|
||||
}
|
||||
|
||||
public enum TextureFiltering
|
||||
{
|
||||
|
||||
Nearest = 0x2600,
|
||||
Linear = 0x2601
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,98 +1,98 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glException"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class GlErrorOverflowException : Exception
|
||||
{
|
||||
|
||||
public GlErrorOverflowException(int errorCount, uint errorCode)
|
||||
: base(
|
||||
"Too many opengl error detected at certain position. " + $"The amount of errors exceeds {errorCount}. " + $"Code of the last error is {errorCode}") { }
|
||||
|
||||
}
|
||||
|
||||
public sealed class GlExecutionException : Exception
|
||||
{
|
||||
|
||||
public GlExecutionException(uint errorCode) : base($"Critical OpenGL error: {errorCode}") { }
|
||||
|
||||
}
|
||||
|
||||
public sealed class GlArrayFormatException : Exception
|
||||
{
|
||||
|
||||
internal GlArrayFormatException(string message) : base(message) { }
|
||||
|
||||
internal GlArrayFormatException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
|
||||
internal GlArrayFormatException(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
public GlArrayFormatException(PixelChannelLayout layout, string arrayname)
|
||||
: base($"{arrayname} cannot be used as layout of {layout}") { }
|
||||
|
||||
}
|
||||
|
||||
public static partial class GlHelper
|
||||
{
|
||||
|
||||
public static bool CheckArrayFormat(this Array array, PixelChannelLayout layout)
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.Byte or PixelChannelLayout.UByte332 or PixelChannelLayout.UByte233Rev => (array is byte[]) ||
|
||||
(array is sbyte[]),
|
||||
PixelChannelLayout.Short => array is short[],
|
||||
PixelChannelLayout.UShort => array is ushort[],
|
||||
PixelChannelLayout.Int => array is int[],
|
||||
PixelChannelLayout.Float => array is float[],
|
||||
PixelChannelLayout.UShort4444 => (array is ushort[]) || (array is byte[]),
|
||||
PixelChannelLayout.UByte => (array is byte[]) || (array is sbyte[]),
|
||||
PixelChannelLayout.UInt => array is uint[],
|
||||
PixelChannelLayout.UShort565 or
|
||||
PixelChannelLayout.UShort565Rev or
|
||||
PixelChannelLayout.UShort4444Rev or
|
||||
PixelChannelLayout.UShort5551 or
|
||||
PixelChannelLayout.UShort1555Rev => array is ushort[],
|
||||
PixelChannelLayout.UInt8888Rev or
|
||||
PixelChannelLayout.UInt1010102 or
|
||||
PixelChannelLayout.UInt2101010Rev => array is int[],
|
||||
PixelChannelLayout.UInt8888 => array is uint[] or byte[],
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glException"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class GlErrorOverflowException : Exception
|
||||
{
|
||||
|
||||
public GlErrorOverflowException(int errorCount, uint errorCode)
|
||||
: base(
|
||||
"Too many opengl error detected at certain position. " + $"The amount of errors exceeds {errorCount}. " + $"Code of the last error is {errorCode}") { }
|
||||
|
||||
}
|
||||
|
||||
public sealed class GlExecutionException : Exception
|
||||
{
|
||||
|
||||
public GlExecutionException(uint errorCode) : base($"Critical OpenGL error: {errorCode}") { }
|
||||
|
||||
}
|
||||
|
||||
public sealed class GlArrayFormatException : Exception
|
||||
{
|
||||
|
||||
internal GlArrayFormatException(string message) : base(message) { }
|
||||
|
||||
internal GlArrayFormatException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
|
||||
internal GlArrayFormatException(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
public GlArrayFormatException(PixelChannelLayout layout, string arrayname)
|
||||
: base($"{arrayname} cannot be used as layout of {layout}") { }
|
||||
|
||||
}
|
||||
|
||||
public static partial class GlHelper
|
||||
{
|
||||
|
||||
public static bool CheckArrayFormat(this Array array, PixelChannelLayout layout)
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.Byte or PixelChannelLayout.UByte332 or PixelChannelLayout.UByte233Rev => (array is byte[]) ||
|
||||
(array is sbyte[]),
|
||||
PixelChannelLayout.Short => array is short[],
|
||||
PixelChannelLayout.UShort => array is ushort[],
|
||||
PixelChannelLayout.Int => array is int[],
|
||||
PixelChannelLayout.Float => array is float[],
|
||||
PixelChannelLayout.UShort4444 => (array is ushort[]) || (array is byte[]),
|
||||
PixelChannelLayout.UByte => (array is byte[]) || (array is sbyte[]),
|
||||
PixelChannelLayout.UInt => array is uint[],
|
||||
PixelChannelLayout.UShort565 or
|
||||
PixelChannelLayout.UShort565Rev or
|
||||
PixelChannelLayout.UShort4444Rev or
|
||||
PixelChannelLayout.UShort5551 or
|
||||
PixelChannelLayout.UShort1555Rev => array is ushort[],
|
||||
PixelChannelLayout.UInt8888Rev or
|
||||
PixelChannelLayout.UInt1010102 or
|
||||
PixelChannelLayout.UInt2101010Rev => array is int[],
|
||||
PixelChannelLayout.UInt8888 => array is uint[] or byte[],
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +1,92 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFucntionSourceManager"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class OpenGLFunction
|
||||
{
|
||||
|
||||
private readonly int textureUnitCountGetter;
|
||||
|
||||
public int TextureUnitCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => textureUnitCountGetter;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> UnusedTextureImageUint
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = [];
|
||||
|
||||
internal void ReturnAvailableUnit(IEnumerable<TextureUnit> source)
|
||||
{
|
||||
int v = glConst.TEXTURE0 + TextureUnitCount;
|
||||
foreach (TextureUnit unit in source)
|
||||
{
|
||||
if ((int)unit > v) {
|
||||
throw new InvalidOperationException(
|
||||
"Source contains texture unit beyond context support.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal int TryGetAvailableTextureUnit(int count, out IEnumerable<TextureUnit> result)
|
||||
{
|
||||
result = new Queue<TextureUnit>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (UnusedTextureImageUint.TryDequeue(out TextureUnit unit))
|
||||
{
|
||||
(result as Queue<TextureUnit>)!.Enqueue(unit);
|
||||
} else
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> InitializeUnusedTextureImageUint()
|
||||
{
|
||||
ConcurrentQueue<TextureUnit> result = new ConcurrentQueue<TextureUnit>();
|
||||
for (int index = 0; index < TextureUnitCount; index++) {
|
||||
result.Enqueue((TextureUnit)(glConst.TEXTURE0 + index));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFucntionSourceManager"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class OpenGLFunction
|
||||
{
|
||||
|
||||
private readonly int textureUnitCountGetter;
|
||||
|
||||
public int TextureUnitCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => textureUnitCountGetter;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> UnusedTextureImageUint
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = [];
|
||||
|
||||
internal void ReturnAvailableUnit(IEnumerable<TextureUnit> source)
|
||||
{
|
||||
int v = glConst.TEXTURE0 + TextureUnitCount;
|
||||
foreach (TextureUnit unit in source)
|
||||
{
|
||||
if ((int)unit > v) {
|
||||
throw new InvalidOperationException(
|
||||
"Source contains texture unit beyond context support.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal int TryGetAvailableTextureUnit(int count, out IEnumerable<TextureUnit> result)
|
||||
{
|
||||
result = new Queue<TextureUnit>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (UnusedTextureImageUint.TryDequeue(out TextureUnit unit))
|
||||
{
|
||||
(result as Queue<TextureUnit>)!.Enqueue(unit);
|
||||
} else
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> InitializeUnusedTextureImageUint()
|
||||
{
|
||||
ConcurrentQueue<TextureUnit> result = new ConcurrentQueue<TextureUnit>();
|
||||
for (int index = 0; index < TextureUnitCount; index++) {
|
||||
result.Enqueue((TextureUnit)(glConst.TEXTURE0 + index));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user