swiss ok, needs more benchmark
This commit is contained in:
@@ -92,7 +92,10 @@ Toolchain=InProcessEmitToolchain InvocationCount=2048 UnrollFactor=1
|
|||||||
| Hlsf | 76.23 µs | 0.355 µs | 0.315 µs | 0.44 | 0.01 |
|
| Hlsf | 76.23 µs | 0.355 µs | 0.315 µs | 0.44 | 0.01 |
|
||||||
| Libc | 172.98 µs | 3.042 µs | 2.988 µs | 1.00 | 0.02 |
|
| Libc | 172.98 µs | 3.042 µs | 2.988 µs | 1.00 | 0.02 |
|
||||||
|
|
||||||
This run shows HLSF significantly faster than libc under the current configuration. See the HLSF document for details and caveats.
|
This benchmark measures steady-state small-block allocation throughput (64B–4KB),
|
||||||
|
which represents the dominant allocation pattern in StgSharp's matrix computation pipeline.
|
||||||
|
HLSF uses a pre-allocated arena with size-class free lists, avoiding kernel-mode allocation calls.
|
||||||
|
Under this workload, HLSF achieves ~2.3× throughput over system malloc. This is not a general-purpose allocator comparison.
|
||||||
|
|
||||||
### Graphics and Rendering
|
### Graphics and Rendering
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using BenchmarkDotNet.Configs;
|
using BenchmarkDotNet.Configs;
|
||||||
using BenchmarkDotNet.Loggers;
|
|
||||||
using BenchmarkDotNet.Jobs;
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using BenchmarkDotNet.Loggers;
|
||||||
using BenchmarkDotNet.Running;
|
using BenchmarkDotNet.Running;
|
||||||
using BenchmarkDotNet.Toolchains.InProcess.Emit;
|
using BenchmarkDotNet.Toolchains.InProcess.Emit;
|
||||||
using StgSharp.Benchmark;
|
using StgSharp.Benchmark;
|
||||||
@@ -41,10 +41,11 @@ namespace StgSharp.Benchmark
|
|||||||
string[] args
|
string[] args
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
IConfig config = ManualConfig.Create(DefaultConfig.Instance)
|
IConfig config = ManualConfig.Create(DefaultConfig.Instance)
|
||||||
.AddLogger(ConsoleLogger.Default)
|
.AddLogger(ConsoleLogger.Default)
|
||||||
.AddJob(Job.Default.WithToolchain(InProcessEmitToolchain.Instance));
|
.AddJob(Job.Default
|
||||||
BenchmarkRunner.Run<HlsfAllocatorBench>(config);
|
.WithToolchain(InProcessEmitToolchain.Instance));
|
||||||
|
_ = BenchmarkRunner.Run<SwissTableBench>(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<SolutionDir Condition="'$(SolutionDir)'=='' Or '$(SolutionDir)'=='*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
|
<SolutionDir Condition="'$(SolutionDir)'=='' Or '$(SolutionDir)'=='*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -0,0 +1,254 @@
|
|||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
// file="SwissBenchmark"
|
||||||
|
// 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 BenchmarkDotNet.Attributes;
|
||||||
|
using StgSharp.Collections;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace StgSharp.Benchmark
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Benchmark comparing SwissTable (SSE2 SIMD probing, zero-GC, native memory) against <see
|
||||||
|
/// cref="Dictionary{TKey, TValue}" /> for the L4 cache address mapping workload: concentrated
|
||||||
|
/// small-key insert/lookup/remove cycles. <para> SwissTable.Create() performs a 1 MB memset
|
||||||
|
/// (65536 × 16 control bytes), which is separated into IterationSetup to avoid polluting
|
||||||
|
/// insert timings.</para>
|
||||||
|
/// </summary>
|
||||||
|
[MemoryDiagnoser]
|
||||||
|
public class SwissTableBench
|
||||||
|
{
|
||||||
|
|
||||||
|
private const int LookupCount = 4096;
|
||||||
|
|
||||||
|
private nint[] _lookupKeys = null!;
|
||||||
|
|
||||||
|
// ── Pre-generated key arrays ──
|
||||||
|
|
||||||
|
private nint[] _preloadedKeys = null!;
|
||||||
|
private Dictionary<nint, nint> _dictLookup = null!;
|
||||||
|
private Dictionary<nint, nint> _freshDict = null!;
|
||||||
|
|
||||||
|
// ── Fresh instances for insert/mixed (rebuilt each iteration) ──
|
||||||
|
|
||||||
|
private SwissTable _freshSwiss = null!;
|
||||||
|
|
||||||
|
// ── Lookup targets (pre-filled in GlobalSetup) ──
|
||||||
|
|
||||||
|
private SwissTable _swissLookup = null!;
|
||||||
|
|
||||||
|
[Params(500, 2000, 5000)]
|
||||||
|
public int KeyCount;
|
||||||
|
|
||||||
|
[GlobalCleanup]
|
||||||
|
public void Cleanup()
|
||||||
|
{
|
||||||
|
_dictLookup.Clear();
|
||||||
|
_dictLookup.TrimExcess();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ══════════════════════════════════════
|
||||||
|
// Insert: pure write throughput
|
||||||
|
// Empty table → fill N keys
|
||||||
|
// Create() cost excluded via IterationSetup
|
||||||
|
// ══════════════════════════════════════
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void Dictionary_Insert()
|
||||||
|
{
|
||||||
|
Dictionary<nint, nint> dict = _freshDict;
|
||||||
|
nint[] keys = _preloadedKeys;
|
||||||
|
for (int i = 0; i < keys.Length; i++) {
|
||||||
|
dict[keys[i]] = keys[i] * 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ══════════════════════════════════════
|
||||||
|
// Lookup: pure read throughput
|
||||||
|
// Pre-filled table, random key access
|
||||||
|
// ══════════════════════════════════════
|
||||||
|
|
||||||
|
[Benchmark(Baseline = true)]
|
||||||
|
public nint Dictionary_Lookup()
|
||||||
|
{
|
||||||
|
nint sum = 0;
|
||||||
|
nint[] keys = _lookupKeys;
|
||||||
|
Dictionary<nint, nint> dict = _dictLookup;
|
||||||
|
for (int i = 0; i < keys.Length; i++)
|
||||||
|
{
|
||||||
|
if (dict.TryGetValue(keys[i], out nint value)) {
|
||||||
|
sum += value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ══════════════════════════════════════
|
||||||
|
// Mixed: insert all → lookup half → remove half → lookup all
|
||||||
|
// Simulates L4 cache lifecycle:
|
||||||
|
// load working set → compute → evict → recompute
|
||||||
|
// ══════════════════════════════════════
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public nint Dictionary_Mixed()
|
||||||
|
{
|
||||||
|
Dictionary<nint, nint> dict = _freshDict;
|
||||||
|
nint[] keys = _preloadedKeys;
|
||||||
|
nint sum = 0;
|
||||||
|
|
||||||
|
// insert all
|
||||||
|
for (int i = 0; i < keys.Length; i++)
|
||||||
|
{
|
||||||
|
dict[keys[i]] = keys[i] * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lookup first half
|
||||||
|
for (int i = 0; i < keys.Length / 2; i++)
|
||||||
|
{
|
||||||
|
if (dict.TryGetValue(keys[i], out nint value)) {
|
||||||
|
sum += value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove first half (eviction)
|
||||||
|
for (int i = 0; i < keys.Length / 2; i++)
|
||||||
|
{
|
||||||
|
dict.Remove(keys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lookup all (half hit, half miss)
|
||||||
|
for (int i = 0; i < keys.Length; i++)
|
||||||
|
{
|
||||||
|
if (dict.TryGetValue(keys[i], out nint value)) {
|
||||||
|
sum += value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
[IterationSetup(Targets = [
|
||||||
|
nameof(SwissTable_Insert),
|
||||||
|
nameof(SwissTable_Mixed),
|
||||||
|
nameof(Dictionary_Insert),
|
||||||
|
nameof(Dictionary_Mixed)
|
||||||
|
])]
|
||||||
|
public void IterationSetup()
|
||||||
|
{
|
||||||
|
_freshSwiss = SwissTable.Create();
|
||||||
|
_freshDict = new Dictionary<nint, nint>(KeyCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Setup / Teardown ──
|
||||||
|
|
||||||
|
[GlobalSetup]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_preloadedKeys = new nint[KeyCount];
|
||||||
|
_lookupKeys = new nint[LookupCount];
|
||||||
|
|
||||||
|
_swissLookup = SwissTable.Create();
|
||||||
|
_dictLookup = new Dictionary<nint, nint>(KeyCount);
|
||||||
|
|
||||||
|
for (int i = 0; i < KeyCount; i++)
|
||||||
|
{
|
||||||
|
_preloadedKeys[i] = (nint)i;
|
||||||
|
_swissLookup.TryAddOrSet((nint)i, (nint)(i * 2), out _);
|
||||||
|
_dictLookup[(nint)i] = (nint)(i * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Random rng = new Random(42);
|
||||||
|
for (int i = 0; i < LookupCount; i++) {
|
||||||
|
_lookupKeys[i] = (nint)rng.Next(0, KeyCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void SwissTable_Insert()
|
||||||
|
{
|
||||||
|
SwissTable swiss = _freshSwiss;
|
||||||
|
nint[] keys = _preloadedKeys;
|
||||||
|
for (int i = 0; i < keys.Length; i++) {
|
||||||
|
swiss.TryAddOrSet(keys[i], keys[i] * 2, out _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public nint SwissTable_Lookup()
|
||||||
|
{
|
||||||
|
nint sum = 0;
|
||||||
|
nint[] keys = _lookupKeys;
|
||||||
|
SwissTable swiss = _swissLookup;
|
||||||
|
for (int i = 0; i < keys.Length; i++)
|
||||||
|
{
|
||||||
|
if (swiss.TryGet(keys[i], out nint value)) {
|
||||||
|
sum += value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public nint SwissTable_Mixed()
|
||||||
|
{
|
||||||
|
SwissTable swiss = _freshSwiss;
|
||||||
|
nint[] keys = _preloadedKeys;
|
||||||
|
nint sum = 0;
|
||||||
|
|
||||||
|
// insert all
|
||||||
|
for (int i = 0; i < keys.Length; i++)
|
||||||
|
{
|
||||||
|
swiss.TryAddOrSet(keys[i], keys[i] * 2, out _);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lookup first half
|
||||||
|
for (int i = 0; i < keys.Length / 2; i++)
|
||||||
|
{
|
||||||
|
if (swiss.TryGet(keys[i], out nint value)) {
|
||||||
|
sum += value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove first half (eviction)
|
||||||
|
for (int i = 0; i < keys.Length / 2; i++)
|
||||||
|
{
|
||||||
|
swiss.TryRemove(keys[i], out _);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lookup all (half hit, half miss)
|
||||||
|
for (int i = 0; i < keys.Length; i++)
|
||||||
|
{
|
||||||
|
if (swiss.TryGet(keys[i], out nint value)) {
|
||||||
|
sum += value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.Intrinsics;
|
using System.Runtime.Intrinsics;
|
||||||
using System.Runtime.Intrinsics.X86;
|
using System.Runtime.Intrinsics.X86;
|
||||||
@@ -39,29 +40,26 @@ namespace StgSharp.Collections
|
|||||||
|
|
||||||
public bool TryFind(
|
public bool TryFind(
|
||||||
nint key,
|
nint key,
|
||||||
uint Hash,
|
uint hash,
|
||||||
Bucket* bucket,
|
Bucket* bucket,
|
||||||
out nint value
|
out nint value
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
byte ctrl = (byte)(Hash >> 8);
|
byte ctrl = (byte)((hash >> EntryMaskWidth) & 0x7F);
|
||||||
Vector128<byte> ctrlVector = Vector128.Create(ctrl);
|
Vector128<byte> ctrlVector = Vector128.Create(ctrl);
|
||||||
for (int i = 0; i < BucketSize; i += 16)
|
Vector128<byte> bucketCtrlVector = Sse2.LoadVector128((byte*)&bucket->Control);
|
||||||
|
Vector128<byte> cmpResult = Sse2.CompareEqual(ctrlVector, bucketCtrlVector);
|
||||||
|
int mask = Sse2.MoveMask(cmpResult);
|
||||||
|
while (mask != 0)
|
||||||
{
|
{
|
||||||
Vector128<byte> bucketCtrlVector = Sse2.LoadVector128(&bucket->Control.Control + i);
|
int bitPos = BitOperations.TrailingZeroCount(mask);
|
||||||
Vector128<byte> cmpResult = Sse2.CompareEqual(ctrlVector, bucketCtrlVector);
|
int index = bitPos;
|
||||||
int mask = Sse2.MoveMask(cmpResult);
|
if (bucket->Keys[index] == key)
|
||||||
while (mask != 0)
|
|
||||||
{
|
{
|
||||||
int bitPos = BitOperations.TrailingZeroCount(mask);
|
value = bucket->Values[index];
|
||||||
int index = i + bitPos;
|
return true;
|
||||||
if (bucket->Keys.value == key)
|
|
||||||
{
|
|
||||||
value = bucket->Values.value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
mask &= mask - 1;
|
|
||||||
}
|
}
|
||||||
|
mask &= mask - 1;
|
||||||
}
|
}
|
||||||
value = default;
|
value = default;
|
||||||
return false;
|
return false;
|
||||||
@@ -74,29 +72,25 @@ namespace StgSharp.Collections
|
|||||||
out nint value
|
out nint value
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
byte ctrl = (byte)(hash >> 8);
|
byte ctrl = (byte)((hash >> EntryMaskWidth) & 0x7F);
|
||||||
Vector128<byte> ctrlVector = Vector128.Create(ctrl);
|
Vector128<byte> ctrlVector = Vector128.Create(ctrl);
|
||||||
|
|
||||||
for (int i = 0; i < BucketSize; i += 16)
|
Vector128<byte> bucketCtrl = Sse2.LoadVector128((byte*)&bucket->Control);
|
||||||
{
|
Vector128<byte> matchMask = Sse2.CompareEqual(ctrlVector, bucketCtrl);
|
||||||
Vector128<byte> bucketCtrl = Sse2.LoadVector128(
|
int matches = Sse2.MoveMask(matchMask);
|
||||||
&bucket->Control[i]);
|
|
||||||
Vector128<byte> matchMask = Sse2.CompareEqual(ctrlVector, bucketCtrl);
|
|
||||||
int matches = Sse2.MoveMask(matchMask);
|
|
||||||
|
|
||||||
while (matches != 0)
|
while (matches != 0)
|
||||||
|
{
|
||||||
|
int bitPos = BitOperations.TrailingZeroCount(matches);
|
||||||
|
int index = bitPos;
|
||||||
|
if (bucket->Keys[index] == key)
|
||||||
{
|
{
|
||||||
int bitPos = BitOperations.TrailingZeroCount(matches);
|
value = bucket->Values[index];
|
||||||
int index = i + bitPos;
|
bucket->Control[index] = 0xFE; // mark as DELETED
|
||||||
if (bucket->Keys[index] == key)
|
// no need to remove Key/Value
|
||||||
{
|
return true;
|
||||||
value = bucket->Values[index];
|
|
||||||
bucket->Control[index] = 0xFE; // mark as DELETED
|
|
||||||
// no need to remove Key/Value
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
matches &= matches - 1;
|
|
||||||
}
|
}
|
||||||
|
matches &= matches - 1;
|
||||||
}
|
}
|
||||||
value = default;
|
value = default;
|
||||||
return false;
|
return false;
|
||||||
@@ -110,64 +104,44 @@ namespace StgSharp.Collections
|
|||||||
out bool isNewKey
|
out bool isNewKey
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
byte ctrl = (byte)(hash >> 8); // H2: upper 8 bits (highest bit is naturally 0)
|
byte ctrl = (byte)((hash >> EntryMaskWidth) & 0x7F); // H2: upper 8 bits (highest bit is naturally 0)
|
||||||
Vector128<byte> ctrlVector = Vector128.Create(ctrl);
|
Vector128<byte> ctrlVector = Vector128.Create(ctrl);
|
||||||
|
|
||||||
int firstAvailableSlot = -1; // Record the first insertable slot
|
int firstAvailableSlot = -1; // Record the first insertable slot
|
||||||
|
|
||||||
for (int i = 0; i < BucketSize; i += 16)
|
Vector128<byte> bucketCtrl = Sse2.LoadVector128(
|
||||||
|
(byte*)&bucket->Control);
|
||||||
|
|
||||||
|
// === Phase 1: Look up an existing key ===
|
||||||
|
Vector128<byte> matchMask = Sse2.CompareEqual(ctrlVector, bucketCtrl);
|
||||||
|
int matches = Sse2.MoveMask(matchMask);
|
||||||
|
|
||||||
|
while (matches != 0)
|
||||||
{
|
{
|
||||||
Vector128<byte> bucketCtrl = Sse2.LoadVector128(
|
int bitPos = BitOperations.TrailingZeroCount(matches);
|
||||||
&bucket->Control[i]);
|
int index = bitPos;
|
||||||
|
if (bucket->Keys[index] == key)
|
||||||
// === Phase 1: Look up an existing key ===
|
|
||||||
Vector128<byte> matchMask = Sse2.CompareEqual(ctrlVector, bucketCtrl);
|
|
||||||
int matches = Sse2.MoveMask(matchMask);
|
|
||||||
|
|
||||||
while (matches != 0)
|
|
||||||
{
|
{
|
||||||
int bitPos = BitOperations.TrailingZeroCount(matches);
|
// Key already exists -> update value
|
||||||
int index = i + bitPos;
|
bucket->Values[index] = value;
|
||||||
if (bucket->Keys[index] == key)
|
isNewKey = false;
|
||||||
{
|
return true;
|
||||||
// Key already exists -> update value
|
|
||||||
bucket->Values[index] = value;
|
|
||||||
isNewKey = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
matches &= matches - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Phase 2: Track an available insertion slot ===
|
|
||||||
if (firstAvailableSlot == -1)
|
|
||||||
{
|
|
||||||
// Find EMPTY (0xFF) or DELETED (0xFE)
|
|
||||||
// Trick: bytes with high bit set are insertable
|
|
||||||
int emptyOrDeleted = Sse2.MoveMask(bucketCtrl);
|
|
||||||
|
|
||||||
// MoveMask extracts the top bit of each byte
|
|
||||||
// EMPTY/DELETED top bit = 1 -> mask bit = 1
|
|
||||||
// OCCUPIED top bit = 0 -> mask bit = 0
|
|
||||||
|
|
||||||
if (emptyOrDeleted != 0)
|
|
||||||
{
|
|
||||||
int bitPos = BitOperations.TrailingZeroCount(emptyOrDeleted);
|
|
||||||
firstAvailableSlot = i + bitPos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
matches &= matches - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Phase 3: Key not found, try to insert ===
|
// === Phase 2: Track an available insertion slot ===
|
||||||
if (firstAvailableSlot == -1)
|
int emptyOrDeleted = Sse2.MoveMask(bucketCtrl);
|
||||||
|
if (emptyOrDeleted == 0)
|
||||||
{
|
{
|
||||||
// Bucket is full; resize is required
|
|
||||||
isNewKey = false;
|
isNewKey = false;
|
||||||
return false;
|
return false; // bucket full
|
||||||
}
|
}
|
||||||
|
|
||||||
bucket->Control[firstAvailableSlot] = ctrl;
|
int slot = BitOperations.TrailingZeroCount(emptyOrDeleted);
|
||||||
bucket->Keys[firstAvailableSlot] = key;
|
bucket->Control[slot] = ctrl;
|
||||||
bucket->Values[firstAvailableSlot] = value;
|
bucket->Keys[slot] = key;
|
||||||
|
bucket->Values[slot] = value;
|
||||||
isNewKey = true;
|
isNewKey = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="SwissTable"
|
// file="SwissTable"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -41,41 +41,51 @@ namespace StgSharp.Collections
|
|||||||
{
|
{
|
||||||
|
|
||||||
private const int BucketCount = 1 << EntryMaskWidth;
|
private const int BucketCount = 1 << EntryMaskWidth;
|
||||||
private const int BucketSize = 256;
|
private const int BucketSize = 16;
|
||||||
private const int EntryMaskWidth = 10; // 1024 entries total, 256 per bucket
|
private const uint CrcMagic = 0xffff9961; // Magic number for CRC32C, used in hash computation
|
||||||
public const int MaxCapacity = 1024 * BucketSize; // 256 entries per bucket, 1024 buckets
|
private const int EntryMaskWidth = 16; // 65536 entries total, 16 per bucket
|
||||||
|
public const int MaxCapacity = BucketCount * BucketSize; // 256 entries per bucket, 1024 buckets
|
||||||
|
|
||||||
private readonly Entry* _entries;
|
private readonly Entry* _entries;
|
||||||
|
|
||||||
private SwissTable(Entry* buffer)
|
private SwissTable(
|
||||||
|
Entry* buffer
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_entries = buffer;
|
_entries = buffer;
|
||||||
for (int i = 0; i < BucketCount; i++)
|
|
||||||
{
|
|
||||||
// Set all control bytes to 0xFF (empty)
|
|
||||||
Unsafe.InitBlock(&_entries[i].Bucket.Control, 0xFF, BucketSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SwissTable Create()
|
public static SwissTable Create()
|
||||||
{
|
{
|
||||||
Entry* buffer = (Entry*)NativeMemory.AlignedAlloc((nuint)Marshal.SizeOf<Entry>(), 16);
|
Entry* buffer = (Entry*)NativeMemory.AlignedAlloc((nuint)Unsafe.SizeOf<Entry>(), 16);
|
||||||
|
for (int i = 0; i < BucketCount; i++)
|
||||||
|
{
|
||||||
|
// Set all control bytes to 0xFF (empty)
|
||||||
|
Unsafe.InitBlock(&(*buffer)[i].Control, 0xFF, BucketSize);
|
||||||
|
}
|
||||||
return new SwissTable(buffer);
|
return new SwissTable(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryAddOrSet(nint key, nint value, out bool isNewKey)
|
public bool TryAddOrSet(
|
||||||
|
nint key,
|
||||||
|
nint value,
|
||||||
|
out bool isNewKey
|
||||||
|
)
|
||||||
{
|
{
|
||||||
uint hash = BitOperations.Crc32C(0xffff9961, (ulong)key);
|
uint hash = BitOperations.Crc32C(CrcMagic, (ulong)key);
|
||||||
short entry = (short)(hash & ((1 << 11) - 1));
|
ushort entry = (ushort)(hash & (BucketCount - 1));
|
||||||
Bucket* bucket = &_entries[entry].Bucket;
|
Bucket* bucket = &(*_entries)[entry];
|
||||||
return IBucketScanner.Current.TrySet(key, hash, bucket, value, out isNewKey);
|
return IBucketScanner.Current.TrySet(key, hash, bucket, value, out isNewKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGet(nint key, out nint value)
|
public bool TryGet(
|
||||||
|
nint key,
|
||||||
|
out nint value
|
||||||
|
)
|
||||||
{
|
{
|
||||||
uint hash = BitOperations.Crc32C(0xffff9961, (ulong)key);
|
uint hash = BitOperations.Crc32C(CrcMagic, (ulong)key);
|
||||||
short entry = (short)(hash & ((1 << 11) - 1));
|
ushort entry = (ushort)(hash & (BucketCount - 1));
|
||||||
Bucket* bucket = &_entries[entry].Bucket;
|
Bucket* bucket = &(*_entries)[entry];
|
||||||
return IBucketScanner.Current.TryFind(key, hash, bucket, out value);
|
return IBucketScanner.Current.TryFind(key, hash, bucket, out value);
|
||||||
/*
|
/*
|
||||||
* hash = CRC32 of key
|
* hash = CRC32 of key
|
||||||
@@ -86,11 +96,14 @@ namespace StgSharp.Collections
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryRemove(nint key, out nint value)
|
public bool TryRemove(
|
||||||
|
nint key,
|
||||||
|
out nint value
|
||||||
|
)
|
||||||
{
|
{
|
||||||
uint hash = BitOperations.Crc32C(0xffff9961, (ulong)key);
|
uint hash = BitOperations.Crc32C(CrcMagic, (ulong)key);
|
||||||
short entry = (short)(hash & ((1 << 11) - 1));
|
ushort entry = (ushort)(hash & (BucketCount - 1));
|
||||||
Bucket* bucket = &_entries[entry].Bucket;
|
Bucket* bucket = &(*_entries)[entry];
|
||||||
return IBucketScanner.Current.TryRemove(key, hash, bucket, out value);
|
return IBucketScanner.Current.TryRemove(key, hash, bucket, out value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,15 +134,31 @@ namespace StgSharp.Collections
|
|||||||
|
|
||||||
static IBucketScanner Current { get; } = Create();
|
static IBucketScanner Current { get; } = Create();
|
||||||
|
|
||||||
bool TryFind(nint key, uint Hash, Bucket* bucket, out nint value);
|
bool TryFind(
|
||||||
|
nint key,
|
||||||
|
uint Hash,
|
||||||
|
Bucket* bucket,
|
||||||
|
out nint value
|
||||||
|
);
|
||||||
|
|
||||||
unsafe bool TryRemove(nint key, uint hash, Bucket* bucket, out nint value);
|
unsafe bool TryRemove(
|
||||||
|
nint key,
|
||||||
|
uint hash,
|
||||||
|
Bucket* bucket,
|
||||||
|
out nint value
|
||||||
|
);
|
||||||
|
|
||||||
bool TrySet(nint key, uint hash, Bucket* bucket, nint value, out bool isNewKey);
|
bool TrySet(
|
||||||
|
nint key,
|
||||||
|
uint hash,
|
||||||
|
Bucket* bucket,
|
||||||
|
nint value,
|
||||||
|
out bool isNewKey
|
||||||
|
);
|
||||||
|
|
||||||
private static IBucketScanner Create()
|
private static IBucketScanner Create()
|
||||||
{
|
{
|
||||||
if (X86Base.IsSupported)
|
if (Sse42.IsSupported)
|
||||||
{
|
{
|
||||||
return new BucketScannerX86();
|
return new BucketScannerX86();
|
||||||
} else if (ArmBase.IsSupported)
|
} else if (ArmBase.IsSupported)
|
||||||
|
|||||||
+39
-13
@@ -58,7 +58,11 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
_projection = new Matrix44();
|
_projection = new Matrix44();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Camera(Vec3 position, Vec3 target, Vec3 up)
|
public Camera(
|
||||||
|
Vec3 position,
|
||||||
|
Vec3 target,
|
||||||
|
Vec3 up
|
||||||
|
)
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
rotationAtt = Matrix44.Unit;
|
rotationAtt = Matrix44.Unit;
|
||||||
@@ -103,13 +107,16 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
/// Shader program requires this camera.
|
/// Shader program requires this camera.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param _label="uniformName">
|
/// <param _label="uniformName">
|
||||||
/// ContextName of all related uniforms. If you fallow form from <see
|
/// ContextName of all related uniforms. If you fallow form from <see ///
|
||||||
/// cref="IglConvertable.DisplayGLtypeDefinition" />
|
/// cref="IglConvertable.DisplayGLtypeDefinition" />
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <exception cref="ArgumentException">
|
/// <exception cref="ArgumentException">
|
||||||
///
|
///
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public unsafe void GainAllUniforms(ShaderProgram source, params string[] uniformName)
|
public unsafe void GainAllUniforms(
|
||||||
|
ShaderProgram source,
|
||||||
|
params string[] uniformName
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (uniformName is null || uniformName.Length != 1) {
|
if (uniformName is null || uniformName.Length != 1) {
|
||||||
throw new ArgumentException(
|
throw new ArgumentException(
|
||||||
@@ -118,19 +125,25 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
convertedUniform = source.GetUniform<Matrix44>(uniformName[0]);
|
convertedUniform = source.GetUniform<Matrix44>(uniformName[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveNear(float distance)
|
public void MoveNear(
|
||||||
|
float distance
|
||||||
|
)
|
||||||
{
|
{
|
||||||
cameraAtt.column[3].Z -= distance;
|
cameraAtt.column[3].Z -= distance;
|
||||||
_isLookAtAvailable = false;
|
_isLookAtAvailable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveRight(float distance)
|
public void MoveRight(
|
||||||
|
float distance
|
||||||
|
)
|
||||||
{
|
{
|
||||||
cameraAtt.column[3].X -= distance;
|
cameraAtt.column[3].X -= distance;
|
||||||
_isLookAtAvailable = false;
|
_isLookAtAvailable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveUp(float distance)
|
public void MoveUp(
|
||||||
|
float distance
|
||||||
|
)
|
||||||
{
|
{
|
||||||
cameraAtt.column[3].Y -= distance;
|
cameraAtt.column[3].Y -= distance;
|
||||||
_isLookAtAvailable = false;
|
_isLookAtAvailable = false;
|
||||||
@@ -142,7 +155,11 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
OpenGLFunction.CurrentGL.SetUniformValue(convertedUniform, Projection * View);
|
OpenGLFunction.CurrentGL.SetUniformValue(convertedUniform, Projection * View);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetViewDirection(Vec3 position, Vec3 target, Vec3 up)
|
public void SetViewDirection(
|
||||||
|
Vec3 position,
|
||||||
|
Vec3 target,
|
||||||
|
Vec3 up
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Vec3 direction = position - target;
|
Vec3 direction = position - target;
|
||||||
if ((position.reg == cameraAtt.column[3].reg) &&
|
if ((position.reg == cameraAtt.column[3].reg) &&
|
||||||
@@ -181,7 +198,8 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
Radius fovRadius,
|
Radius fovRadius,
|
||||||
Vec2 size,
|
Vec2 size,
|
||||||
Vec2 offset,
|
Vec2 offset,
|
||||||
(float front, float back) depthRange)
|
(float front, float back) depthRange
|
||||||
|
)
|
||||||
{
|
{
|
||||||
float
|
float
|
||||||
distance = _target.GetLength(),
|
distance = _target.GetLength(),
|
||||||
@@ -189,7 +207,7 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
far = distance + depthRange.back,
|
far = distance + depthRange.back,
|
||||||
offsetX = offset.X,
|
offsetX = offset.X,
|
||||||
offsetY = offset.Y,
|
offsetY = offset.Y,
|
||||||
width = Scalar.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
|
width = MathF.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
|
||||||
height = width * size.Y / size.X;
|
height = width * size.Y / size.X;
|
||||||
|
|
||||||
_projection.column[0].X = 2 * near / width;
|
_projection.column[0].X = 2 * near / width;
|
||||||
@@ -201,7 +219,9 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
_projection.column[3].Z = 2 * near * far / (near - far);
|
_projection.column[3].Z = 2 * near * far / (near - far);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Test(params Vec4[] vec)
|
public void Test(
|
||||||
|
params Vec4[] vec
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Console.WriteLine(View);
|
Console.WriteLine(View);
|
||||||
Console.WriteLine(Projection);
|
Console.WriteLine(Projection);
|
||||||
@@ -221,7 +241,9 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
|
|
||||||
#region rotation
|
#region rotation
|
||||||
|
|
||||||
public void Yaw(Radius r)
|
public void Yaw(
|
||||||
|
Radius r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_yaw -= r;
|
_yaw -= r;
|
||||||
|
|
||||||
@@ -230,7 +252,9 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
InternalYaw();
|
InternalYaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Pitch(Radius r)
|
public void Pitch(
|
||||||
|
Radius r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_pitch -= r;
|
_pitch -= r;
|
||||||
|
|
||||||
@@ -239,7 +263,9 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
InternalPitch();
|
InternalPitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Row(Radius r)
|
public void Row(
|
||||||
|
Radius r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_row -= r;
|
_row -= r;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Function"
|
// file="Global"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
@@ -25,7 +25,5 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
namespace StgSharp.Mathematics
|
global using StgSharp.Internal;
|
||||||
{
|
global using System;
|
||||||
public class Function { }
|
|
||||||
}
|
|
||||||
@@ -66,7 +66,7 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Shader : ISSDSerializable
|
public class Shader
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly OpenGLFunction GL;
|
private readonly OpenGLFunction GL;
|
||||||
@@ -84,8 +84,6 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
type = usage;
|
type = usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attach one shader code to a shader program.
|
/// Attach one shader code to a shader program.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="glApiManager"
|
// file="glApiManager"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,11 +25,9 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
using StgSharp.Internal;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.Mathematics;
|
using StgSharp.Mathematics;
|
||||||
using StgSharp.MVVM;
|
|
||||||
using StgSharp.MVVM;
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -52,15 +50,15 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
"OpenGL SC "
|
"OpenGL SC "
|
||||||
};
|
};
|
||||||
|
|
||||||
private static string glExtensionList;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort" />.
|
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param _label="contextHandle">
|
/// <param _label="contextHandle">
|
||||||
/// The handle to current OpenGL viewPortDisplay
|
/// The handle to current OpenGL viewPortDisplay
|
||||||
/// </param>
|
/// </param>
|
||||||
public static unsafe void LoadOpenGLApiTo(IntPtr contextHandle)
|
public static unsafe void LoadOpenGLApiTo(
|
||||||
|
IntPtr contextHandle
|
||||||
|
)
|
||||||
{
|
{
|
||||||
OpenglContext* context = (OpenglContext*)contextHandle;
|
OpenglContext* context = (OpenglContext*)contextHandle;
|
||||||
if (context->glGetString != null) {
|
if (context->glGetString != null) {
|
||||||
@@ -81,12 +79,13 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
if (context->glGetString(glVersion) == null) {
|
if (context->glGetString(glVersion) == null) {
|
||||||
DefaultLog.InternalWriteLog("Failed to call glGetString", LogType.Error);
|
DefaultLog.InternalWriteLog("Failed to call glGetString", LogType.Error);
|
||||||
}
|
}
|
||||||
coreVersion = Marshal.PtrToStringAnsi((nint)context->glGetString(glVersion)) ?? string.Empty;
|
coreVersion = Marshal.PtrToStringAnsi((nint)context->glGetString(glVersion)) ??
|
||||||
|
string.Empty;
|
||||||
|
|
||||||
foreach (string branch in glBranch)
|
foreach (string branch in glBranch)
|
||||||
{
|
{
|
||||||
if (coreVersion.Contains(branch)) {
|
if (coreVersion.Contains(branch, StringComparison.Ordinal)) {
|
||||||
coreVersion.Replace(branch, string.Empty);
|
coreVersion.Replace(branch, string.Empty, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string[] versionSep = coreVersion!.Split('.');
|
string[] versionSep = coreVersion!.Split('.');
|
||||||
@@ -163,182 +162,182 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
if (extensions.Contains("gl_AMD_blend_minmax_factor"))
|
if (extensions.Contains("gl_AMD_blend_minmax_factor"))
|
||||||
{
|
{
|
||||||
AMD_blend_minmax_factor = true;
|
AMD_blend_minmax_factor = true;
|
||||||
extensions.Remove("glAMD_blend_minmax_factor");
|
extensions.Remove("gl_AMD_blend_minmax_factor");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_conservative_depth"))
|
if (extensions.Contains("gl_AMD_conservative_depth"))
|
||||||
{
|
{
|
||||||
AMD_conservative_depth = true;
|
AMD_conservative_depth = true;
|
||||||
extensions.Remove("glAMD_conservative_depth");
|
extensions.Remove("gl_AMD_conservative_depth");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_debug_output"))
|
if (extensions.Contains("gl_AMD_debug_output"))
|
||||||
{
|
{
|
||||||
AMD_debug_output = true;
|
AMD_debug_output = true;
|
||||||
extensions.Remove("glAMD_debug_output");
|
extensions.Remove("gl_AMD_debug_output");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_depth_clamp_separate"))
|
if (extensions.Contains("gl_AMD_depth_clamp_separate"))
|
||||||
{
|
{
|
||||||
AMD_depth_clamp_separate = true;
|
AMD_depth_clamp_separate = true;
|
||||||
extensions.Remove("glAMD_depth_clamp_separate");
|
extensions.Remove("gl_AMD_depth_clamp_separate");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_draw_buffers_blend"))
|
if (extensions.Contains("gl_AMD_draw_buffers_blend"))
|
||||||
{
|
{
|
||||||
AMD_draw_buffers_blend = true;
|
AMD_draw_buffers_blend = true;
|
||||||
extensions.Remove("glAMD_draw_buffers_blend");
|
extensions.Remove("gl_AMD_draw_buffers_blend");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_framebuffer_multisample_advanced"))
|
if (extensions.Contains("gl_AMD_framebuffer_multisample_advanced"))
|
||||||
{
|
{
|
||||||
AMD_framebuffer_multisample_advanced = true;
|
AMD_framebuffer_multisample_advanced = true;
|
||||||
extensions.Remove("glAMD_framebuffer_multisample_advanced");
|
extensions.Remove("gl_AMD_framebuffer_multisample_advanced");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_framebuffer_sample_positions"))
|
if (extensions.Contains("gl_AMD_framebuffer_sample_positions"))
|
||||||
{
|
{
|
||||||
AMD_framebuffer_sample_positions = true;
|
AMD_framebuffer_sample_positions = true;
|
||||||
extensions.Remove("glAMD_framebuffer_sample_positions");
|
extensions.Remove("gl_AMD_framebuffer_sample_positions");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_gcn_shader"))
|
if (extensions.Contains("gl_AMD_gcn_shader"))
|
||||||
{
|
{
|
||||||
AMD_gcn_shader = true;
|
AMD_gcn_shader = true;
|
||||||
extensions.Remove("glAMD_gcn_shader");
|
extensions.Remove("gl_AMD_gcn_shader");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_gpu_shader_half_float"))
|
if (extensions.Contains("gl_AMD_gpu_shader_half_float"))
|
||||||
{
|
{
|
||||||
AMD_gpu_shader_half_float = true;
|
AMD_gpu_shader_half_float = true;
|
||||||
extensions.Remove("glAMD_gpu_shader_half_float");
|
extensions.Remove("gl_AMD_gpu_shader_half_float");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_gpu_shader_int16"))
|
if (extensions.Contains("gl_AMD_gpu_shader_int16"))
|
||||||
{
|
{
|
||||||
AMD_gpu_shader_int16 = true;
|
AMD_gpu_shader_int16 = true;
|
||||||
extensions.Remove("glAMD_gpu_shader_int16");
|
extensions.Remove("gl_AMD_gpu_shader_int16");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_gpu_shader_int64"))
|
if (extensions.Contains("gl_AMD_gpu_shader_int64"))
|
||||||
{
|
{
|
||||||
AMD_gpu_shader_int64 = true;
|
AMD_gpu_shader_int64 = true;
|
||||||
extensions.Remove("glAMD_gpu_shader_int64");
|
extensions.Remove("gl_AMD_gpu_shader_int64");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_interleaved_elements"))
|
if (extensions.Contains("gl_AMD_interleaved_elements"))
|
||||||
{
|
{
|
||||||
AMD_interleaved_elements = true;
|
AMD_interleaved_elements = true;
|
||||||
extensions.Remove("glAMD_interleaved_elements");
|
extensions.Remove("gl_AMD_interleaved_elements");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_multi_draw_indirect"))
|
if (extensions.Contains("gl_AMD_multi_draw_indirect"))
|
||||||
{
|
{
|
||||||
AMD_multi_draw_indirect = true;
|
AMD_multi_draw_indirect = true;
|
||||||
extensions.Remove("glAMD_multi_draw_indirect");
|
extensions.Remove("gl_AMD_multi_draw_indirect");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_name_gen_delete"))
|
if (extensions.Contains("gl_AMD_name_gen_delete"))
|
||||||
{
|
{
|
||||||
AMD_name_gen_delete = true;
|
AMD_name_gen_delete = true;
|
||||||
extensions.Remove("glAMD_name_gen_delete");
|
extensions.Remove("gl_AMD_name_gen_delete");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_occlusion_query_event"))
|
if (extensions.Contains("gl_AMD_occlusion_query_event"))
|
||||||
{
|
{
|
||||||
AMD_occlusion_query_event = true;
|
AMD_occlusion_query_event = true;
|
||||||
extensions.Remove("glAMD_occlusion_query_event");
|
extensions.Remove("gl_AMD_occlusion_query_event");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_performance_monitor"))
|
if (extensions.Contains("gl_AMD_performance_monitor"))
|
||||||
{
|
{
|
||||||
AMD_performance_monitor = true;
|
AMD_performance_monitor = true;
|
||||||
extensions.Remove("glAMD_performance_monitor");
|
extensions.Remove("gl_AMD_performance_monitor");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_pinned_memory"))
|
if (extensions.Contains("gl_AMD_pinned_memory"))
|
||||||
{
|
{
|
||||||
AMD_pinned_memory = true;
|
AMD_pinned_memory = true;
|
||||||
extensions.Remove("glAMD_pinned_memory");
|
extensions.Remove("gl_AMD_pinned_memory");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_query_buffer_object"))
|
if (extensions.Contains("gl_AMD_query_buffer_object"))
|
||||||
{
|
{
|
||||||
AMD_query_buffer_object = true;
|
AMD_query_buffer_object = true;
|
||||||
extensions.Remove("glAMD_query_buffer_object");
|
extensions.Remove("gl_AMD_query_buffer_object");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_sample_positions"))
|
if (extensions.Contains("gl_AMD_sample_positions"))
|
||||||
{
|
{
|
||||||
AMD_sample_positions = true;
|
AMD_sample_positions = true;
|
||||||
extensions.Remove("glAMD_sample_positions");
|
extensions.Remove("gl_AMD_sample_positions");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_seamless_cubemap_per_texture"))
|
if (extensions.Contains("gl_AMD_seamless_cubemap_per_texture"))
|
||||||
{
|
{
|
||||||
AMD_seamless_cubemap_per_texture = true;
|
AMD_seamless_cubemap_per_texture = true;
|
||||||
extensions.Remove("glAMD_seamless_cubemap_per_texture");
|
extensions.Remove("gl_AMD_seamless_cubemap_per_texture");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_shader_atomic_counter_ops"))
|
if (extensions.Contains("gl_AMD_shader_atomic_counter_ops"))
|
||||||
{
|
{
|
||||||
AMD_shader_atomic_counter_ops = true;
|
AMD_shader_atomic_counter_ops = true;
|
||||||
extensions.Remove("glAMD_shader_atomic_counter_ops");
|
extensions.Remove("gl_AMD_shader_atomic_counter_ops");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_shader_ballot"))
|
if (extensions.Contains("gl_AMD_shader_ballot"))
|
||||||
{
|
{
|
||||||
AMD_shader_ballot = true;
|
AMD_shader_ballot = true;
|
||||||
extensions.Remove("glAMD_shader_ballot");
|
extensions.Remove("gl_AMD_shader_ballot");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_shader_explicit_vertex_parameter"))
|
if (extensions.Contains("gl_AMD_shader_explicit_vertex_parameter"))
|
||||||
{
|
{
|
||||||
AMD_shader_explicit_vertex_parameter = true;
|
AMD_shader_explicit_vertex_parameter = true;
|
||||||
extensions.Remove("glAMD_shader_explicit_vertex_parameter");
|
extensions.Remove("gl_AMD_shader_explicit_vertex_parameter");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_shader_gpu_shader_half_float_fetch"))
|
if (extensions.Contains("gl_AMD_shader_gpu_shader_half_float_fetch"))
|
||||||
{
|
{
|
||||||
AMD_shader_gpu_shader_half_float_fetch = true;
|
AMD_shader_gpu_shader_half_float_fetch = true;
|
||||||
extensions.Remove("glAMD_shader_gpu_shader_half_float_fetch");
|
extensions.Remove("gl_AMD_shader_gpu_shader_half_float_fetch");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_shader_image_load_store_lod"))
|
if (extensions.Contains("gl_AMD_shader_image_load_store_lod"))
|
||||||
{
|
{
|
||||||
AMD_shader_image_load_store_lod = true;
|
AMD_shader_image_load_store_lod = true;
|
||||||
extensions.Remove("glAMD_shader_image_load_store_lod");
|
extensions.Remove("gl_AMD_shader_image_load_store_lod");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_shader_stencil_export"))
|
if (extensions.Contains("gl_AMD_shader_stencil_export"))
|
||||||
{
|
{
|
||||||
AMD_shader_stencil_export = true;
|
AMD_shader_stencil_export = true;
|
||||||
extensions.Remove("glAMD_shader_stencil_export");
|
extensions.Remove("gl_AMD_shader_stencil_export");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_shader_trinary_minmax"))
|
if (extensions.Contains("gl_AMD_shader_trinary_minmax"))
|
||||||
{
|
{
|
||||||
AMD_shader_trinary_minmax = true;
|
AMD_shader_trinary_minmax = true;
|
||||||
extensions.Remove("glAMD_shader_trinary_minmax");
|
extensions.Remove("gl_AMD_shader_trinary_minmax");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_sparse_texture"))
|
if (extensions.Contains("gl_AMD_sparse_texture"))
|
||||||
{
|
{
|
||||||
AMD_sparse_texture = true;
|
AMD_sparse_texture = true;
|
||||||
extensions.Remove("glAMD_sparse_texture");
|
extensions.Remove("gl_AMD_sparse_texture");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_stencil_operation_extended"))
|
if (extensions.Contains("gl_AMD_stencil_operation_extended"))
|
||||||
{
|
{
|
||||||
AMD_stencil_operation_extended = true;
|
AMD_stencil_operation_extended = true;
|
||||||
extensions.Remove("glAMD_stencil_operation_extended");
|
extensions.Remove("gl_AMD_stencil_operation_extended");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_texture_gather_bias_lod"))
|
if (extensions.Contains("gl_AMD_texture_gather_bias_lod"))
|
||||||
{
|
{
|
||||||
AMD_texture_gather_bias_lod = true;
|
AMD_texture_gather_bias_lod = true;
|
||||||
extensions.Remove("glAMD_texture_gather_bias_lod");
|
extensions.Remove("gl_AMD_texture_gather_bias_lod");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_texture_texture4"))
|
if (extensions.Contains("gl_AMD_texture_texture4"))
|
||||||
{
|
{
|
||||||
AMD_texture_texture4 = true;
|
AMD_texture_texture4 = true;
|
||||||
extensions.Remove("glAMD_texture_texture4");
|
extensions.Remove("gl_AMD_texture_texture4");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_transform_feedback3_lines_triangles"))
|
if (extensions.Contains("gl_AMD_transform_feedback3_lines_triangles"))
|
||||||
{
|
{
|
||||||
AMD_transform_feedback3_lines_triangles = true;
|
AMD_transform_feedback3_lines_triangles = true;
|
||||||
extensions.Remove("glAMD_transform_feedback3_lines_triangles");
|
extensions.Remove("gl_AMD_transform_feedback3_lines_triangles");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_transform_feedback4"))
|
if (extensions.Contains("gl_AMD_transform_feedback4"))
|
||||||
{
|
{
|
||||||
AMD_transform_feedback4 = true;
|
AMD_transform_feedback4 = true;
|
||||||
extensions.Remove("glAMD_transform_feedback4");
|
extensions.Remove("gl_AMD_transform_feedback4");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_vertex_shader_layer"))
|
if (extensions.Contains("gl_AMD_vertex_shader_layer"))
|
||||||
{
|
{
|
||||||
AMD_vertex_shader_layer = true;
|
AMD_vertex_shader_layer = true;
|
||||||
extensions.Remove("glAMD_vertex_shader_layer");
|
extensions.Remove("gl_AMD_vertex_shader_layer");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_vertex_shader_tessellator"))
|
if (extensions.Contains("gl_AMD_vertex_shader_tessellator"))
|
||||||
{
|
{
|
||||||
AMD_vertex_shader_tessellator = true;
|
AMD_vertex_shader_tessellator = true;
|
||||||
extensions.Remove("glAMD_vertex_shader_tessellator");
|
extensions.Remove("gl_AMD_vertex_shader_tessellator");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_AMD_vertex_shader_viewport_index"))
|
if (extensions.Contains("gl_AMD_vertex_shader_viewport_index"))
|
||||||
{
|
{
|
||||||
AMD_vertex_shader_viewport_index = true;
|
AMD_vertex_shader_viewport_index = true;
|
||||||
extensions.Remove("glAMD_vertex_shader_viewport_index");
|
extensions.Remove("gl_AMD_vertex_shader_viewport_index");
|
||||||
}
|
}
|
||||||
if (extensions.Contains("gl_APPLE_aux_depth_stencil"))
|
if (extensions.Contains("gl_APPLE_aux_depth_stencil"))
|
||||||
{
|
{
|
||||||
@@ -3244,7 +3243,10 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
#endregion checkGLextensions
|
#endregion checkGLextensions
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void CheckCoreVersion(int majorVersion, int minorVersion)
|
internal static void CheckCoreVersion(
|
||||||
|
int majorVersion,
|
||||||
|
int minorVersion
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (majorVersion < 3) {
|
if (majorVersion < 3) {
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
@@ -3410,7 +3412,9 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static unsafe string GetExtensions(this OpenglContext context)
|
internal static unsafe string GetExtensions(
|
||||||
|
this OpenglContext context
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (context.glGetString == null) {
|
if (context.glGetString == null) {
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|||||||
@@ -50,10 +50,7 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
|
|
||||||
private OpenGLFunction _context;
|
private OpenGLFunction _context;
|
||||||
|
|
||||||
protected internal OpenGLFunction GL
|
protected internal OpenGLFunction GL => _context;
|
||||||
{
|
|
||||||
get { return _context; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize an opengl context and load all opengl functions.
|
/// Initialize an opengl context and load all opengl functions.
|
||||||
@@ -169,29 +166,5 @@ namespace StgSharp.Graphics.OpenGL
|
|||||||
NativeCamera.SetViewDirection(position, direction, up);
|
NativeCamera.SetViewDirection(position, direction, up);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Key Control
|
|
||||||
|
|
||||||
protected KeyStatus CheckKey(
|
|
||||||
KeyboardKey key
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected KeyStatus CheckKey(
|
|
||||||
Mouse key
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected KeyStatus CheckKey(
|
|
||||||
Joystick key
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,11 +39,18 @@ namespace StgSharp.Graphics
|
|||||||
public string ModuleName => "Graphic";
|
public string ModuleName => "Graphic";
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void InitializeModule()
|
public void InitializeModule(
|
||||||
|
IModuleInitializeProfile profile
|
||||||
|
)
|
||||||
{
|
{
|
||||||
GraphicFramework.LoadGlfw();
|
GraphicFramework.LoadGlfw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UninitializeModule()
|
||||||
|
{
|
||||||
|
GraphicFramework.glfwTerminate();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static unsafe partial class GraphicFramework
|
internal static unsafe partial class GraphicFramework
|
||||||
@@ -702,12 +709,15 @@ namespace StgSharp.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal static unsafe byte* glfwGetKeyName(
|
internal static unsafe ReadOnlySpan<byte> glfwGetKeyName(
|
||||||
int key,
|
int key,
|
||||||
int scancode
|
int scancode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return _glfw.glfwGetKeyName(key, scancode);
|
byte* ptr = _glfw.glfwGetKeyName(key, scancode);
|
||||||
|
int count = 0;
|
||||||
|
for (; ptr[count] != 0; count++) { }
|
||||||
|
return new ReadOnlySpan<byte>(ptr, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -717,15 +727,17 @@ namespace StgSharp.Graphics
|
|||||||
{
|
{
|
||||||
return _glfw.glfwGetKeyScancode(key);
|
return _glfw.glfwGetKeyScancode(key);
|
||||||
}
|
}
|
||||||
|
/**/
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal static unsafe KeyStatus glfwGetKey(
|
internal static unsafe int glfwGetKey(
|
||||||
IntPtr window,
|
IntPtr window,
|
||||||
int key
|
int key
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return _glfw.glfwGetKey(window, key);
|
return _glfw.glfwGetKey(window, key);
|
||||||
}
|
}
|
||||||
|
/**/
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal static unsafe int glfwGetMouseButton(
|
internal static unsafe int glfwGetMouseButton(
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace StgSharp.Internal
|
|||||||
public delegate* unmanaged[Cdecl]<int, int*, byte*> glfwGetJoystickHats;
|
public delegate* unmanaged[Cdecl]<int, int*, byte*> glfwGetJoystickHats;
|
||||||
public delegate* unmanaged[Cdecl]<int, byte*> glfwGetJoystickName;
|
public delegate* unmanaged[Cdecl]<int, byte*> glfwGetJoystickName;
|
||||||
public delegate* unmanaged[Cdecl]<int, void*> glfwGetJoystickUserPointer;
|
public delegate* unmanaged[Cdecl]<int, void*> glfwGetJoystickUserPointer;
|
||||||
public delegate* unmanaged[Cdecl]<IntPtr, int, KeyStatus> glfwGetKey;
|
public delegate* unmanaged[Cdecl]<IntPtr, int, int> glfwGetKey;
|
||||||
public delegate* unmanaged[Cdecl]<int, int, byte*> glfwGetKeyName;
|
public delegate* unmanaged[Cdecl]<int, int, byte*> glfwGetKeyName;
|
||||||
public delegate* unmanaged[Cdecl]<int, int> glfwGetKeyScancode;
|
public delegate* unmanaged[Cdecl]<int, int> glfwGetKeyScancode;
|
||||||
public delegate* unmanaged[Cdecl]<IntPtr, float*, float*, void> glfwGetMonitorContentScale;
|
public delegate* unmanaged[Cdecl]<IntPtr, float*, float*, void> glfwGetMonitorContentScale;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Angle"
|
// file="Angle"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -37,46 +37,60 @@ namespace StgSharp.Mathematics
|
|||||||
public static partial class GeometryScaler
|
public static partial class GeometryScaler
|
||||||
{
|
{
|
||||||
|
|
||||||
internal const float DegToRad = 180 / Scalar.Pi;
|
internal const float DegToRad = 180 / MathF.PI;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float Cos(Radius r)
|
public static float Cos(
|
||||||
|
Radius r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return MathF.Cos(r._radius);
|
return MathF.Cos(r._radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float Cos(Degree r)
|
public static float Cos(
|
||||||
|
Degree r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return MathF.Cos(r._degree / DegToRad);
|
return MathF.Cos(r._degree / DegToRad);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float Sin(Radius r)
|
public static float Sin(
|
||||||
|
Radius r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return MathF.Sin(r._radius);
|
return MathF.Sin(r._radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float Sin(Degree r)
|
public static float Sin(
|
||||||
|
Degree r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return MathF.Sin(r._degree / DegToRad);
|
return MathF.Sin(r._degree / DegToRad);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float Tan(Radius r)
|
public static float Tan(
|
||||||
|
Radius r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return MathF.Tan(r._radius);
|
return MathF.Tan(r._radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float Tan(Degree r)
|
public static float Tan(
|
||||||
|
Degree r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return MathF.Tan(r._degree / DegToRad);
|
return MathF.Tan(r._degree / DegToRad);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Degree ToDegree(float value)
|
public static Degree ToDegree(
|
||||||
|
float value
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return new Degree(value);
|
return new Degree(value);
|
||||||
}
|
}
|
||||||
@@ -88,12 +102,16 @@ namespace StgSharp.Mathematics
|
|||||||
|
|
||||||
internal float _degree;
|
internal float _degree;
|
||||||
|
|
||||||
public Degree(float dgree)
|
public Degree(
|
||||||
|
float dgree
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_degree = dgree;
|
_degree = dgree;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator Radius(Degree d)
|
public static implicit operator Radius(
|
||||||
|
Degree d
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return new Radius(d._degree / GeometryScaler.DegToRad);
|
return new Radius(d._degree / GeometryScaler.DegToRad);
|
||||||
}
|
}
|
||||||
@@ -108,7 +126,9 @@ namespace StgSharp.Mathematics
|
|||||||
[Obsolete("Unsafe, you may forget this is radius.", true)]
|
[Obsolete("Unsafe, you may forget this is radius.", true)]
|
||||||
public Radius() { }
|
public Radius() { }
|
||||||
|
|
||||||
public Radius(float radius)
|
public Radius(
|
||||||
|
float radius
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_radius = radius;
|
_radius = radius;
|
||||||
}
|
}
|
||||||
@@ -119,56 +139,81 @@ namespace StgSharp.Mathematics
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Radius operator -(Radius r)
|
public static Radius operator -(
|
||||||
|
Radius r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return new Radius(-r._radius);
|
return new Radius(-r._radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Radius operator -(Radius left, Radius Right)
|
public static Radius operator -(
|
||||||
|
Radius left,
|
||||||
|
Radius Right
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return new Radius(left._radius - Right._radius);
|
return new Radius(left._radius - Right._radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool operator !=(Radius left, Radius right)
|
public static bool operator !=(
|
||||||
|
Radius left,
|
||||||
|
Radius right
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return left._radius != right._radius;
|
return left._radius != right._radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Radius operator *(Radius left, float right)
|
public static Radius operator *(
|
||||||
|
Radius left,
|
||||||
|
float right
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return new Radius(left._radius * right);
|
return new Radius(left._radius * right);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Radius operator /(Radius left, float right)
|
public static Radius operator /(
|
||||||
|
Radius left,
|
||||||
|
float right
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return new Radius(left._radius / right);
|
return new Radius(left._radius / right);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float operator /(Radius left, Radius right)
|
public static float operator /(
|
||||||
|
Radius left,
|
||||||
|
Radius right
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return left._radius / right._radius;
|
return left._radius / right._radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static Radius operator +(Radius left, Radius Right)
|
public static Radius operator +(
|
||||||
|
Radius left,
|
||||||
|
Radius Right
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return new Radius(left._radius + Right._radius);
|
return new Radius(left._radius + Right._radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool operator ==(Radius left, Radius right)
|
public static bool operator ==(
|
||||||
|
Radius left,
|
||||||
|
Radius right
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return left._radius == right._radius;
|
return left._radius == right._radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator Degree(Radius r)
|
public static implicit operator Degree(
|
||||||
|
Radius r
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return new Degree((r._radius * 180) / Scalar.Pi);
|
return new Degree(r._radius * 180 / MathF.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Tan"
|
// file="Global"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
@@ -25,19 +25,12 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using System;
|
global using StgSharp.Internal;
|
||||||
|
global using StgSharp.Mathematics.Internal;
|
||||||
|
global using System;
|
||||||
|
|
||||||
|
global using System.Numerics;
|
||||||
|
global using System.Threading;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
[assembly: InternalsVisibleTo("StgSharp.Graphics")]
|
||||||
{
|
|
||||||
public static partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static float Tan(float x)
|
|
||||||
{
|
|
||||||
return MathF.Tan(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixPanel"
|
// file="MatrixPanel"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,14 +25,14 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Internal;
|
|
||||||
using StgSharp.Mathematics.Internal;
|
using StgSharp.Mathematics.Internal;
|
||||||
|
using StgSharp.Mathematics.Numeric;
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public unsafe struct MatrixPanel
|
public unsafe struct MatrixPanel
|
||||||
{
|
{
|
||||||
@@ -42,37 +42,41 @@ namespace StgSharp.Mathematics
|
|||||||
private byte Head;
|
private byte Head;
|
||||||
|
|
||||||
// Allocate aligned memory for one panel; caller must free via Destroy.
|
// Allocate aligned memory for one panel; caller must free via Destroy.
|
||||||
public static unsafe MatrixPanel<T>* Create<T>() where T: unmanaged, INumber<T>
|
public static unsafe MatrixPanel<T>* Create<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
return (MatrixPanel<T>*)NativeMemory.AlignedAlloc(Size<T>(), AlignmentBytes);
|
return (MatrixPanel<T>*)NativeMemory.AlignedAlloc(Size<T>(), AlignmentBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe void Destroy<T>(MatrixPanel<T>* panel) where T: unmanaged, INumber<T>
|
public static unsafe void Destroy<T>(
|
||||||
|
MatrixPanel<T>* panel
|
||||||
|
) where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
NativeMemory.AlignedFree(panel);
|
NativeMemory.AlignedFree(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe Span<T> Elements<T>(ref T head) where T: unmanaged, INumber<T>
|
public static unsafe Span<T> Elements<T>(
|
||||||
|
ref T head
|
||||||
|
) where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
void* p = Unsafe.AsPointer(ref head);
|
void* p = Unsafe.AsPointer(ref head);
|
||||||
return new Span<T>(p, MaxElementCount<T>());
|
return new Span<T>(p, MaxElementCount<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static int ElementSideLength<T>() where T: unmanaged, INumber<T>
|
public static int ElementSideLength<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
return PanelSideLength<T>();
|
return PanelSideLength<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int MaxElementCount<T>() where T: unmanaged, INumber<T>
|
public static int MaxElementCount<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
int side = ElementSideLength<T>();
|
int side = ElementSideLength<T>();
|
||||||
return side * side;
|
return side * side;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static nuint Size<T>() where T: unmanaged, INumber<T>
|
public static nuint Size<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
return (nuint)(MaxElementCount<T>() * sizeof(T));
|
return (nuint)(MaxElementCount<T>() * sizeof(T));
|
||||||
}
|
}
|
||||||
@@ -81,7 +85,7 @@ namespace StgSharp.Mathematics
|
|||||||
/// Number of 4x4 kernels that fit in a panel for the given ISA and element T.
|
/// Number of 4x4 kernels that fit in a panel for the given ISA and element T.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal static int KernelCapacity<T>() where T: unmanaged, INumber<T>
|
internal static int KernelCapacity<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
int perSide = KernelSideCount<T>();
|
int perSide = KernelSideCount<T>();
|
||||||
return perSide * perSide;
|
return perSide * perSide;
|
||||||
@@ -91,9 +95,9 @@ namespace StgSharp.Mathematics
|
|||||||
/// How many 4x4 kernels fit along a single panel dimension for the given ISA.
|
/// How many 4x4 kernels fit along a single panel dimension for the given ISA.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal static int KernelSideCount<T>() where T: unmanaged, INumber<T>
|
internal static int KernelSideCount<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
SIMDID id = NumericalModule.IntrinsicMask;
|
SIMDID id = NumericalModule.GlobalIntrinsicMask;
|
||||||
switch (id.MaskByte[0] & 0b_00001111)
|
switch (id.MaskByte[0] & 0b_00001111)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@@ -110,31 +114,35 @@ namespace StgSharp.Mathematics
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static unsafe nuint Align64(void* p)
|
private static unsafe nuint Align64(
|
||||||
|
void* p
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return ((nuint)p + (AlignmentBytes - 1)) & ~(nuint)(AlignmentBytes - 1);
|
return ((nuint)p + (AlignmentBytes - 1)) & ~(nuint)(AlignmentBytes - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static int KernelSideCountAvx2<T>() where T: unmanaged, INumber<T>
|
private static int KernelSideCountAvx2<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
return PanelSideFromBits<T>(256) / 4;
|
return PanelSideFromBits<T>(256) / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static int KernelSideCountAvx512<T>() where T: unmanaged, INumber<T>
|
private static int KernelSideCountAvx512<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
return PanelSideFromBits<T>(512) / 4;
|
return PanelSideFromBits<T>(512) / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static int KernelSideCountSse<T>() where T: unmanaged, INumber<T>
|
private static int KernelSideCountSse<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
return PanelSideFromBits<T>(128) / 4;
|
return PanelSideFromBits<T>(128) / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static int PanelSideFromBits<T>(int vectorBits) where T: unmanaged, INumber<T>
|
private static int PanelSideFromBits<T>(
|
||||||
|
int vectorBits
|
||||||
|
) where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
int elemBits = sizeof(T) * 8;
|
int elemBits = sizeof(T) * 8;
|
||||||
|
|
||||||
@@ -146,9 +154,9 @@ namespace StgSharp.Mathematics
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static int PanelSideLength<T>() where T: unmanaged, INumber<T>
|
private static int PanelSideLength<T>() where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
SIMDID id = NumericalModule.IntrinsicMask;
|
SIMDID id = NumericalModule.GlobalIntrinsicMask;
|
||||||
switch (id.MaskByte[0] & 0b_00001111)
|
switch (id.MaskByte[0] & 0b_00001111)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@@ -167,12 +175,15 @@ namespace StgSharp.Mathematics
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Single POD-style panel: ZMM-compatible size. Alignment handled by allocator, not by the struct.
|
// Single POD-style panel: ZMM-compatible size. Alignment handled by allocator, not by the struct.
|
||||||
public unsafe struct MatrixPanel<T> where T: unmanaged, INumber<T>
|
public unsafe struct MatrixPanel<T> where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
internal T Head; // first element of the panel buffer
|
internal T Head; // first element of the panel buffer
|
||||||
|
|
||||||
public ref T this[int column, int row]
|
public ref T this[
|
||||||
|
int column,
|
||||||
|
int row
|
||||||
|
]
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => ref Unsafe.Add(ref Head, row * MatrixPanel.ElementSideLength<T>() + column);
|
get => ref Unsafe.Add(ref Head, row * MatrixPanel.ElementSideLength<T>() + column);
|
||||||
|
|||||||
@@ -39,14 +39,20 @@ namespace StgSharp.Mathematics.Internal
|
|||||||
[FieldOffset(0)]public MatrixKernel* Mat1; // 8
|
[FieldOffset(0)]public MatrixKernel* Mat1; // 8
|
||||||
[FieldOffset(8)] public MatrixKernel* Mat2; // 8
|
[FieldOffset(8)] public MatrixKernel* Mat2; // 8
|
||||||
[FieldOffset(16)] public MatrixKernel* Mat3; // 16
|
[FieldOffset(16)] public MatrixKernel* Mat3; // 16
|
||||||
[FieldOffset(32)] public int CommonX;
|
|
||||||
[FieldOffset(40)] public int Common_k;
|
[FieldOffset(40)] public int Common_k;
|
||||||
|
[FieldOffset(32)] public int CommonX;
|
||||||
[FieldOffset(36)] public int CommonY;
|
[FieldOffset(36)] public int CommonY;
|
||||||
[FieldOffset(44)] public int i;
|
[FieldOffset(44)] public int i;
|
||||||
[FieldOffset(48)] public int j;
|
[FieldOffset(48)] public int j;
|
||||||
[FieldOffset(52)] public int k;
|
[FieldOffset(52)] public int k;
|
||||||
[FieldOffset(56)] public MatrixElementType ElementType; // 56
|
[FieldOffset(56)] public MatrixElementType ElementType; // 56
|
||||||
[FieldOffset(24)] public nint Span; // 24
|
[FieldOffset(24)] public nint Span; // 24
|
||||||
|
[FieldOffset(64)] public ScalarPacket Scalar;
|
||||||
|
|
||||||
|
public MatrixParallelTask()
|
||||||
|
{
|
||||||
|
Unsafe.SkipInit(out this);
|
||||||
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Copy(
|
public static void Copy(
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="UnsafeCompute"
|
// file="UnsafeCompute"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
using StgSharp.Mathematics.Numeric;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Internal
|
namespace StgSharp.Mathematics.Internal
|
||||||
@@ -33,19 +34,30 @@ namespace StgSharp.Mathematics.Internal
|
|||||||
{
|
{
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe int CityHashSimplify(char* span, int length)
|
public static unsafe int CityHashSimplify(
|
||||||
|
char* span,
|
||||||
|
int length
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return NumericalModule.GlobalContext.city_hash_simplify(span, length);
|
return NumericalModule.GlobalContext.city_hash_simplify(span, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe int CityHashSimplify(char* span, int begin, int length)
|
public static unsafe int CityHashSimplify(
|
||||||
|
char* span,
|
||||||
|
int begin,
|
||||||
|
int length
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return NumericalModule.GlobalContext.city_hash_simplify(span + begin, length);
|
return NumericalModule.GlobalContext.city_hash_simplify(span + begin, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe int IndexOfCharPair(char* source, int pairValue, int length)
|
public static unsafe int IndexOfCharPair(
|
||||||
|
char* source,
|
||||||
|
int pairValue,
|
||||||
|
int length
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return NumericalModule.GlobalContext.index_pair(source, pairValue, length);
|
return NumericalModule.GlobalContext.index_pair(source, pairValue, length);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,15 +32,21 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
public static unsafe partial class Linear
|
public static unsafe partial class Linear
|
||||||
{
|
{
|
||||||
|
|
||||||
public static float GetAngle(Vec2 vec1, Vec2 vec2)
|
public static float GetAngle(
|
||||||
|
Vec2 vec1,
|
||||||
|
Vec2 vec2
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return Scalar.ACos(
|
return MathF.Acos(
|
||||||
1 / (vec1.GetLength() * vec2.GetLength()));
|
1 / (vec1.GetLength() * vec2.GetLength()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetAngle(Vec3 vec1, Vec3 vec2)
|
public static float GetAngle(
|
||||||
|
Vec3 vec1,
|
||||||
|
Vec3 vec2
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return Scalar.ACos((vec1 * vec2) / (vec1.GetLength() * vec2.GetLength()));
|
return MathF.Acos(vec1 * vec2 / (vec1.GetLength() * vec2.GetLength()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,14 +32,18 @@ namespace StgSharp.Mathematics.Graphics
|
|||||||
public static unsafe partial class Linear
|
public static unsafe partial class Linear
|
||||||
{
|
{
|
||||||
|
|
||||||
public static float GetLength(this Vec3 vec)
|
public static float GetLength(
|
||||||
|
this Vec3 vec
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return Scalar.Sqrt(vec.Dot(vec));
|
return MathF.Sqrt(vec.Dot(vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetLength(this Vec2 vec)
|
public static float GetLength(
|
||||||
|
this Vec2 vec
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return Scalar.Sqrt(vec.Dot(vec));
|
return MathF.Sqrt(vec.Dot(vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-28
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="NewRender"
|
// file="Exception"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,41 +25,41 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Graphics;
|
|
||||||
using StgSharp.Internal;
|
|
||||||
|
|
||||||
using StgSharp.Mathematics;
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public partial class ViewMain
|
public class MatrixDimensionMismatchException<T> : Exception where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
public ParticleRenderStream Stream { get; set; }
|
public MatrixDimensionMismatchException(
|
||||||
|
Matrix<T> right,
|
||||||
|
Matrix<T> ans
|
||||||
|
)
|
||||||
|
: base($"""
|
||||||
|
Matrix dimensions must agree but current:
|
||||||
|
right({right?.ColumnLength ?? 0}×{right?.RowLength ?? 0}),
|
||||||
|
ans({ans?.ColumnLength ?? 0}×{ans?.RowLength ?? 0})
|
||||||
|
"""
|
||||||
|
) { }
|
||||||
|
|
||||||
private class NewRender : ViewRender<ViewMain>
|
public MatrixDimensionMismatchException(
|
||||||
{
|
Matrix<T> left,
|
||||||
|
Matrix<T> right,
|
||||||
public NewRender(ViewMain view) : base(view) { }
|
Matrix<T> ans
|
||||||
|
)
|
||||||
public override void CustomizedInitialize()
|
: base($"""
|
||||||
{
|
Matrix dimensions must agree but current:
|
||||||
Binding.Stream = CreateRenderStream<ParticleRenderStream>();
|
left({left?.ColumnLength ?? 0}×{left?.RowLength ?? 0}),
|
||||||
Render["only".AsLabel()] = Binding.Stream;
|
right({right?.ColumnLength ?? 0}×{right?.RowLength ?? 0}),
|
||||||
}
|
ans({ans?.ColumnLength ?? 0}×{ans?.RowLength ?? 0})
|
||||||
|
"""
|
||||||
public override bool ValidateInitializing()
|
) { }
|
||||||
{
|
|
||||||
return Binding.Stream != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Matrix"
|
// file="Matrix"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -35,7 +35,7 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public unsafe partial class Matrix<T> where T: unmanaged, INumber<T>
|
public unsafe partial class Matrix<T> where T : unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
private protected static readonly int t_count = 16 / sizeof(T);
|
private protected static readonly int t_count = 16 / sizeof(T);
|
||||||
@@ -57,7 +57,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
_buffer = buffer;
|
_buffer = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T this[int x, int y]
|
public T this[
|
||||||
|
int x,
|
||||||
|
int y
|
||||||
|
]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -98,7 +101,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
/// <exception cref="NotImplementedException">
|
/// <exception cref="NotImplementedException">
|
||||||
///
|
///
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public unsafe Matrix<T> this[ReadOnlySpan<MatrixIndex> column, ReadOnlySpan<MatrixIndex> row]
|
public unsafe Matrix<T> this[
|
||||||
|
ReadOnlySpan<MatrixIndex> column,
|
||||||
|
ReadOnlySpan<MatrixIndex> row
|
||||||
|
]
|
||||||
{
|
{
|
||||||
get { throw new NotImplementedException(); }
|
get { throw new NotImplementedException(); }
|
||||||
set { throw new NotImplementedException(); }
|
set { throw new NotImplementedException(); }
|
||||||
@@ -127,14 +133,20 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
protected internal int KernelRowLength => _size.KernelRowLength;
|
protected internal int KernelRowLength => _size.KernelRowLength;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public unsafe ref MatrixKernel<T> GetMatrixKernel(int x, int y)
|
public unsafe ref MatrixKernel<T> GetMatrixKernel(
|
||||||
|
int x,
|
||||||
|
int y
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return ref _boarder.IsInBuffer(x, y, in _size) ?
|
return ref _boarder.IsInBuffer(x, y, in _size) ?
|
||||||
ref _buffer[_boarder.GetIndexOffset(x, y, in _size)] :
|
ref _buffer[_boarder.GetIndexOffset(x, y, in _size)] :
|
||||||
ref Unsafe.NullRef<MatrixKernel<T>>();
|
ref Unsafe.NullRef<MatrixKernel<T>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal long GetElementOffset(int x, int y)
|
internal long GetElementOffset(
|
||||||
|
int x,
|
||||||
|
int y
|
||||||
|
)
|
||||||
{
|
{
|
||||||
int
|
int
|
||||||
k_c = y / 4,
|
k_c = y / 4,
|
||||||
@@ -150,7 +162,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal unsafe ref T GetElementUnsafe(int x, int y)
|
internal unsafe ref T GetElementUnsafe(
|
||||||
|
int x,
|
||||||
|
int y
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Caller guarantees: indices in range, layout is dense square.
|
// Caller guarantees: indices in range, layout is dense square.
|
||||||
int k_c = y / 4;
|
int k_c = y / 4;
|
||||||
@@ -163,13 +178,19 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal unsafe MatrixKernel<T>* GetKernelAddressUnsafe(int x, int y)
|
internal unsafe MatrixKernel<T>* GetKernelAddressUnsafe(
|
||||||
|
int x,
|
||||||
|
int y
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return Buffer + _boarder.GetIndexOffset(x, y, in _size);
|
return Buffer + _boarder.GetIndexOffset(x, y, in _size);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal unsafe ref MatrixKernel<T> GetKernelUnsafe(int x, int y)
|
internal unsafe ref MatrixKernel<T> GetKernelUnsafe(
|
||||||
|
int x,
|
||||||
|
int y
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Caller guarantees: indices in range, layout is dense square.
|
// Caller guarantees: indices in range, layout is dense square.
|
||||||
int k_c = y / 4;
|
int k_c = y / 4;
|
||||||
|
|||||||
+29
-12
@@ -34,6 +34,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using unsafe MkProc = delegate* unmanaged[Cdecl]<StgSharp.Mathematics.Internal.MatrixParallelTask, void>;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
public partial class MatrixCompute
|
public partial class MatrixCompute
|
||||||
@@ -45,12 +47,14 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
Matrix<double> ans
|
Matrix<double> ans
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int f64 = (int)MatrixElementType.F64;
|
MatrixElementType f64 = MatrixElementType.F64;
|
||||||
if (left.ColumnLength != right.ColumnLength ||
|
if (left.ColumnLength != right.ColumnLength ||
|
||||||
left.RowLength != right.RowLength ||
|
left.RowLength != right.RowLength ||
|
||||||
left.ColumnLength != ans.ColumnLength ||
|
left.ColumnLength != ans.ColumnLength ||
|
||||||
left.RowLength != ans.RowLength) {
|
left.RowLength != ans.RowLength) {
|
||||||
throw new IndexOutOfRangeException("Matrix dimensions must agree.");
|
throw new MatrixDimensionMismatchException<double>(
|
||||||
|
left, right, ans
|
||||||
|
);
|
||||||
}
|
}
|
||||||
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
long count = (long)left.KernelColumnLength * left.KernelRowLength;
|
||||||
if (count <= 256)
|
if (count <= 256)
|
||||||
@@ -58,8 +62,21 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixKernel<double>* leftPtr = left.Buffer;
|
MatrixKernel<double>* leftPtr = left.Buffer;
|
||||||
MatrixKernel<double>* rightPtr = right.Buffer;
|
MatrixKernel<double>* rightPtr = right.Buffer;
|
||||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||||
NumericalModule.GlobalContext.mat_sk[f64].buffer_add(leftPtr, rightPtr, ansPtr,
|
MkProc add = (MkProc)NumericalModule.GlobalContext.
|
||||||
count);
|
mat_mk[f64.IntrinsicNode].
|
||||||
|
Get(MatrixIntrinsicHandle.Add);
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
add(new MatrixParallelTask
|
||||||
|
{
|
||||||
|
Mat1 = (MatrixKernel*)(leftPtr + i),
|
||||||
|
Mat2 = (MatrixKernel*)(rightPtr + i),
|
||||||
|
Mat3 = (MatrixKernel*)(ansPtr + i),
|
||||||
|
ElementType = MatrixElementType.F64,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// .buffer_add(leftPtr, rightPtr, ansPtr, count);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (count <= 1024)
|
} else if (count <= 1024)
|
||||||
@@ -70,7 +87,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixKernel<double>* rightPtr = right.Buffer;
|
MatrixKernel<double>* rightPtr = right.Buffer;
|
||||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||||
NumericalModule.GlobalContext.mat_sk[f64].buffer_add(leftPtr, rightPtr, ansPtr,
|
NumericalModule.GlobalContext.mat_sk[f64].buffer_add(leftPtr, rightPtr, ansPtr,
|
||||||
count);
|
count);
|
||||||
|
|
||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
@@ -160,9 +177,9 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
NumericalModule.GlobalContext
|
NumericalModule.GlobalContext
|
||||||
.mat_sk[f64].kernel_tile_fma((MatrixKernel*)left.Buffer,
|
.mat_sk[f64].kernel_tile_fma((MatrixKernel*)left.Buffer,
|
||||||
(MatrixKernel*)right.Buffer,
|
(MatrixKernel*)right.Buffer,
|
||||||
(MatrixKernel*)ans.Buffer,
|
(MatrixKernel*)ans.Buffer,
|
||||||
enumeration);
|
enumeration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count > 256) {
|
if (count > 256) {
|
||||||
@@ -210,7 +227,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixKernel<double>* leftPtr = left.Buffer;
|
MatrixKernel<double>* leftPtr = left.Buffer;
|
||||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||||
NumericalModule.GlobalContext.mat_sk[f64].buffer_scalar_mul(leftPtr, ansPtr, scalar,
|
NumericalModule.GlobalContext.mat_sk[f64].buffer_scalar_mul(leftPtr, ansPtr, scalar,
|
||||||
count);
|
count);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (count <= 1024)
|
} else if (count <= 1024)
|
||||||
@@ -220,7 +237,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixKernel<double>* leftPtr = left.Buffer;
|
MatrixKernel<double>* leftPtr = left.Buffer;
|
||||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||||
NumericalModule.GlobalContext.mat_sk[f64].buffer_scalar_mul(leftPtr, ansPtr, scalar,
|
NumericalModule.GlobalContext.mat_sk[f64].buffer_scalar_mul(leftPtr, ansPtr, scalar,
|
||||||
count);
|
count);
|
||||||
|
|
||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
@@ -267,7 +284,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixKernel<double>* rightPtr = right.Buffer;
|
MatrixKernel<double>* rightPtr = right.Buffer;
|
||||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||||
NumericalModule.GlobalContext.mat_sk[f64].buffer_sub(leftPtr, rightPtr, ansPtr,
|
NumericalModule.GlobalContext.mat_sk[f64].buffer_sub(leftPtr, rightPtr, ansPtr,
|
||||||
count);
|
count);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (count <= 1024)
|
} else if (count <= 1024)
|
||||||
@@ -278,7 +295,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixKernel<double>* rightPtr = right.Buffer;
|
MatrixKernel<double>* rightPtr = right.Buffer;
|
||||||
MatrixKernel<double>* ansPtr = ans.Buffer;
|
MatrixKernel<double>* ansPtr = ans.Buffer;
|
||||||
NumericalModule.GlobalContext.mat_sk[f64].buffer_sub(leftPtr, rightPtr, ansPtr,
|
NumericalModule.GlobalContext.mat_sk[f64].buffer_sub(leftPtr, rightPtr, ansPtr,
|
||||||
count);
|
count);
|
||||||
|
|
||||||
MatrixParallel.ReturnParallelResources(ref pool);
|
MatrixParallel.ReturnParallelResources(ref pool);
|
||||||
return;
|
return;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel.Await"
|
// file="MatrixParallel.Await"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -31,6 +31,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
@@ -43,7 +44,9 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
private static volatile int _createGeneration = 0;
|
private static volatile int _createGeneration = 0;
|
||||||
private static int _sortState;
|
private static int _sortState;
|
||||||
|
|
||||||
public static MatrixParallelThread[] LeadParallel(int recommendCount)
|
public static MatrixParallelThread[] LeadParallel(
|
||||||
|
int recommendCount
|
||||||
|
)
|
||||||
{
|
{
|
||||||
int min = int.Min(recommendCount, _threads.Capacity);
|
int min = int.Min(recommendCount, _threads.Capacity);
|
||||||
min /= 2;
|
min /= 2;
|
||||||
@@ -108,7 +111,9 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
// return ret;
|
// return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ReturnParallelResources(ref MatrixParallelThread[] pool)
|
public static void ReturnParallelResources(
|
||||||
|
ref MatrixParallelThread[] pool
|
||||||
|
)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -123,7 +128,11 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
pool = null!;
|
pool = null!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private record class WaitHandle(int generation, int least, int best)
|
private record class WaitHandle(
|
||||||
|
int generation,
|
||||||
|
int least,
|
||||||
|
int best
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
public int CreateGeneration { get; init; } = generation;
|
public int CreateGeneration { get; init; } = generation;
|
||||||
@@ -135,7 +144,9 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
public int Priority { get; private set; }
|
public int Priority { get; private set; }
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void UpdatePriority(int currentGeneration)
|
public void UpdatePriority(
|
||||||
|
int currentGeneration
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Priority = (currentGeneration - CreateGeneration) * (MatrixParallel._threads.Capacity - LeastCount);
|
Priority = (currentGeneration - CreateGeneration) * (MatrixParallel._threads.Capacity - LeastCount);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel.AwaitingQueue"
|
// file="MatrixParallel.AwaitingQueue"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -51,19 +51,24 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
public AwaitingQueue() { }
|
public AwaitingQueue() { }
|
||||||
|
|
||||||
public void Enqueue(WaitHandle handle)
|
public void Enqueue(
|
||||||
|
WaitHandle handle
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (_count > 7)
|
if (_count > 7)
|
||||||
{
|
{
|
||||||
_fallback.Enqueue(handle);
|
_fallback.Enqueue(handle);
|
||||||
Interlocked.Increment(ref _count);
|
_ = Interlocked.Increment(ref _count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_quickElements[_count] = handle;
|
_quickElements[_count] = handle;
|
||||||
Interlocked.Increment(ref _count);
|
_ = Interlocked.Increment(ref _count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryDequeue(int generation, out WaitHandle handle)
|
public bool TryDequeue(
|
||||||
|
int generation,
|
||||||
|
out WaitHandle handle
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (_count == 0)
|
if (_count == 0)
|
||||||
{
|
{
|
||||||
@@ -83,7 +88,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryPeek(int generation, out WaitHandle handle)
|
public bool TryPeek(
|
||||||
|
int generation,
|
||||||
|
out WaitHandle handle
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (_count == 0)
|
if (_count == 0)
|
||||||
{
|
{
|
||||||
@@ -99,7 +107,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryPopIfRefEqual(int generation, in WaitHandle handle)
|
public bool TryPopIfRefEqual(
|
||||||
|
int generation,
|
||||||
|
in WaitHandle handle
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (_count == 0) {
|
if (_count == 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -127,7 +138,9 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
private WaitHandle value;
|
private WaitHandle value;
|
||||||
|
|
||||||
public static void Sort(ref Element e)
|
public static void Sort(
|
||||||
|
ref Element e
|
||||||
|
)
|
||||||
{
|
{
|
||||||
int maxIdx = 0;
|
int maxIdx = 0;
|
||||||
WaitHandle first = e[0];
|
WaitHandle first = e[0];
|
||||||
|
|||||||
@@ -50,26 +50,22 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallelTask* package
|
MatrixParallelTask* package
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
switch (package->ComputeMode.OperationStyle)
|
return ScheduleBufferTask(package);
|
||||||
{
|
|
||||||
case MatrixIndexStyle.BUFFER_INDEX:
|
|
||||||
return ScheduleBufferTask(package);
|
|
||||||
default:
|
|
||||||
throw new InvalidOperationException($"Unknown mode {package->ComputeMode.OperationStyle}.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static unsafe MatrixParallelWrap ScheduleBufferTask(
|
private static unsafe MatrixParallelWrap ScheduleBufferTask(
|
||||||
MatrixParallelTask* package
|
MatrixParallelTask* package
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
int primCount = package->PrimCount;
|
int primCount = package->PrimCount;
|
||||||
int secCount = package->SecCount;
|
int secCount = package->SecCount;
|
||||||
long count = (long)primCount * secCount;
|
long count = (long)primCount * secCount;
|
||||||
|
/**/
|
||||||
|
|
||||||
// Console.WriteLine($"amount of kernels is {count}");
|
// Console.WriteLine($"amount of kernels is {count}");
|
||||||
|
|
||||||
long recommendCount = count / 1024;
|
long recommendCount = /*count / /**/ 1024;
|
||||||
MatrixParallelThread[] pool = LeadParallel((int)recommendCount);
|
MatrixParallelThread[] pool = LeadParallel((int)recommendCount);
|
||||||
MatrixParallelWrap wrap = new MatrixParallelWrap(pool);
|
MatrixParallelWrap wrap = new MatrixParallelWrap(pool);
|
||||||
wrap.TaskQueue = MatrixParallelQueue.Rent(package);
|
wrap.TaskQueue = MatrixParallelQueue.Rent(package);
|
||||||
|
|||||||
@@ -124,9 +124,11 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
// Bind OS-thread affinity once when the worker starts running
|
// Bind OS-thread affinity once when the worker starts running
|
||||||
SetThreadAffinity(PoolId);
|
SetThreadAffinity(PoolId);
|
||||||
Thread.Yield();
|
_ = Thread.Yield();
|
||||||
SIMDID feature = new();
|
SIMDID feature = new()
|
||||||
feature.Mask = GetSimdId();
|
{
|
||||||
|
Mask = GetSimdId()
|
||||||
|
};
|
||||||
_context = (nint*)MatrixParallel.GetContext(feature);
|
_context = (nint*)MatrixParallel.GetContext(feature);
|
||||||
State = MatrixThreadState.Ready;
|
State = MatrixThreadState.Ready;
|
||||||
while (true)
|
while (true)
|
||||||
@@ -148,6 +150,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
{
|
{
|
||||||
MatrixParallelQueue taskQueue = BindedWrap.TaskQueue;
|
MatrixParallelQueue taskQueue = BindedWrap.TaskQueue;
|
||||||
MatrixParallelTask* p = taskQueue.Package;
|
MatrixParallelTask* p = taskQueue.Package;
|
||||||
|
/*
|
||||||
if (0 > (int)p ->ComputeHandle) {
|
if (0 > (int)p ->ComputeHandle) {
|
||||||
SpecialBufferCompute(p);
|
SpecialBufferCompute(p);
|
||||||
}
|
}
|
||||||
@@ -159,6 +162,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/**/
|
||||||
BindedWrap.ReportThreadAccomplished();
|
BindedWrap.ReportThreadAccomplished();
|
||||||
}
|
}
|
||||||
_managedThread.Priority = AfterWork;
|
_managedThread.Priority = AfterWork;
|
||||||
|
|||||||
@@ -98,9 +98,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
MatrixParallelTask* source
|
MatrixParallelTask* source
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (source->Scalar != null) {
|
|
||||||
_scalarAllocator.Free((nuint)source->Scalar);
|
|
||||||
}
|
|
||||||
_wrapAllocator.Free((nuint)source);
|
_wrapAllocator.Free((nuint)source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,107 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="ACos"
|
|
||||||
// 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.CompilerServices;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static unsafe partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe float ACos(float x)
|
|
||||||
{
|
|
||||||
return MathF.Acos(x);
|
|
||||||
|
|
||||||
/*
|
|
||||||
int sign = 1;
|
|
||||||
float y;
|
|
||||||
|
|
||||||
if (x < 0)
|
|
||||||
{
|
|
||||||
sign = -1;
|
|
||||||
y = -x;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
y = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x > 1)
|
|
||||||
{
|
|
||||||
throw new ArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
float r, s, u, vec = 0.0f;
|
|
||||||
bool transform = (y >= 0.5f);
|
|
||||||
|
|
||||||
if (transform)
|
|
||||||
{
|
|
||||||
r = 0.5f * (1.0f - y);
|
|
||||||
s = Scaler.Sqrt(r);
|
|
||||||
y = s;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = y * y;
|
|
||||||
}
|
|
||||||
u = r * (0.184161606965100694821398249421F +
|
|
||||||
(-0.0565298683201845211985026327361F +
|
|
||||||
(-0.0133819288943925804214011424456F -
|
|
||||||
0.00396137437848476485201154797087F * r) * r) * r) /
|
|
||||||
(1.10496961524520294485512696706F -
|
|
||||||
0.836411276854206731913362287293F * r);
|
|
||||||
/*
|
|
||||||
|
|
||||||
if (transform)
|
|
||||||
{
|
|
||||||
float c, s1, p, q;
|
|
||||||
uint us;
|
|
||||||
|
|
||||||
us = *(uint*)&s;
|
|
||||||
uint uss = us & 0xffff0000;
|
|
||||||
s1 = *(float*)&uss;
|
|
||||||
|
|
||||||
c = (r - s1 * s1) / (s + s1);
|
|
||||||
p = 2.0F * s * u - (piby2_tail - 2.0F * c);
|
|
||||||
q = hpiby2_head - 2.0F * s1;
|
|
||||||
vec = hpiby2_head - (p - q);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vec = y + y * u;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec = sign * vec;
|
|
||||||
|
|
||||||
return piby2 - vec;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="ASin"
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static unsafe partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
private const float
|
|
||||||
piby2_tail = 7.5497894159e-08f, /* 0x33a22168 */
|
|
||||||
hpiby2_head = 7.8539812565e-01f, /* 0x3f490fda */
|
|
||||||
piby2 = 1.5707963705e+00f; /* 0x3fc90fdb */
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reurns the value of ArcSin(x)
|
|
||||||
/// </summary>
|
|
||||||
/// <param _label="x">
|
|
||||||
/// The sine value of the angle
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
///
|
|
||||||
/// </returns>
|
|
||||||
/// <exception cref="ArgumentException">
|
|
||||||
///
|
|
||||||
/// </exception>
|
|
||||||
public static float ASin(float x)
|
|
||||||
{
|
|
||||||
return MathF.Asin(x);
|
|
||||||
/*
|
|
||||||
int sign = 1;
|
|
||||||
float y;
|
|
||||||
|
|
||||||
if (x < 0)
|
|
||||||
{
|
|
||||||
sign = -1;
|
|
||||||
y = -x;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
y = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x > 1)
|
|
||||||
{
|
|
||||||
throw new ArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
float r, s, u, vec = 0.0f;
|
|
||||||
bool transform = (y >= 0.5f);
|
|
||||||
|
|
||||||
if (transform)
|
|
||||||
{
|
|
||||||
r = 0.5f * (1.0f - y);
|
|
||||||
s = Scaler.Sqrt(r);
|
|
||||||
y = s;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = y * y;
|
|
||||||
}
|
|
||||||
u = r * (0.184161606965100694821398249421F +
|
|
||||||
(-0.0565298683201845211985026327361F +
|
|
||||||
(-0.0133819288943925804214011424456F -
|
|
||||||
0.00396137437848476485201154797087F * r) * r) * r) /
|
|
||||||
(1.10496961524520294485512696706F -
|
|
||||||
0.836411276854206731913362287293F * r);
|
|
||||||
/*
|
|
||||||
|
|
||||||
if (transform)
|
|
||||||
{
|
|
||||||
float c, s1, p, q;
|
|
||||||
uint us;
|
|
||||||
|
|
||||||
us = *(uint*)&s;
|
|
||||||
uint uss = us & 0xffff0000;
|
|
||||||
s1 = *(float*)&uss;
|
|
||||||
|
|
||||||
c = (r - s1 * s1) / (s + s1);
|
|
||||||
p = 2.0F * s * u - (piby2_tail - 2.0F * c);
|
|
||||||
q = hpiby2_head - 2.0F * s1;
|
|
||||||
vec = hpiby2_head - (p - q);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vec = y + y * u;
|
|
||||||
}/*
|
|
||||||
|
|
||||||
return sign * vec;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="ATan"
|
|
||||||
// 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.CompilerServices;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static unsafe partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe float ATan(float x)
|
|
||||||
{
|
|
||||||
return MathF.Atan(x);
|
|
||||||
/*
|
|
||||||
float sign = 1, angle = 0;
|
|
||||||
if (x < 0)
|
|
||||||
{
|
|
||||||
sign = -1;
|
|
||||||
x = -x;
|
|
||||||
}
|
|
||||||
uint xBit = *(uint*)&x;
|
|
||||||
int xExp = (int)(xBit >> 23) - 127;
|
|
||||||
if (xExp >= 26)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (xExp <= -15)
|
|
||||||
{
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
if (xExp >= 0)
|
|
||||||
{
|
|
||||||
x = (x - 1) / (x + 1);
|
|
||||||
angle = 0.7853981634f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float vec = 0.7853981634f * x + x * (1 - x) * (0.2447f + 0.0663f * x);
|
|
||||||
vec += angle;
|
|
||||||
vec *= sign;
|
|
||||||
|
|
||||||
return vec;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static unsafe float ATan(float x, float y)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
float z = y / x;
|
|
||||||
|
|
||||||
float sign = 1, angle = 0, angle2 = 0;
|
|
||||||
if (x < 0)
|
|
||||||
{
|
|
||||||
angle = -3.1415926535f;
|
|
||||||
}
|
|
||||||
if (z < 0)
|
|
||||||
{
|
|
||||||
sign = -1;
|
|
||||||
z = -z;
|
|
||||||
}
|
|
||||||
uint zBit = *(uint*)&z;
|
|
||||||
int zExp = (int)(zBit >> 23) - 127;
|
|
||||||
if (zExp >= 26)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (zExp <= -15)
|
|
||||||
{
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
if (zExp >= 0)
|
|
||||||
{
|
|
||||||
z = (z - 1) / (z + 1);
|
|
||||||
angle2 = 0.7853981634f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float vec = 0.7853981634f * z + z * (1 - z) * (0.2447f + 0.0663f * z);
|
|
||||||
vec *= 57.29577951f;
|
|
||||||
vec += angle2;
|
|
||||||
vec += angle;
|
|
||||||
vec *= sign;
|
|
||||||
|
|
||||||
return vec;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="BasicOps"
|
|
||||||
// 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.Globalization;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static unsafe partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe float Abs(float x)
|
|
||||||
{
|
|
||||||
uint* a = (uint*)&x;
|
|
||||||
*a &= 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
|
||||||
return *(float*)a;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe int Abs(int x)
|
|
||||||
{
|
|
||||||
uint* a = (uint*)&x;
|
|
||||||
*a &= 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
|
||||||
return *(int*)a;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string GetListSeparator(IFormatProvider formatProvider)
|
|
||||||
{
|
|
||||||
if (formatProvider is CultureInfo cultureInfo) {
|
|
||||||
return cultureInfo.TextInfo.ListSeparator;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formatProvider?.GetFormat(typeof(TextInfo)) is TextInfo textInfo) {
|
|
||||||
return textInfo.ListSeparator;
|
|
||||||
}
|
|
||||||
|
|
||||||
return CultureInfo.CurrentCulture.TextInfo.ListSeparator;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Compare"
|
|
||||||
// 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.Mathematics
|
|
||||||
{
|
|
||||||
public static partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
public static float MaxOf(params float[] stream)
|
|
||||||
{
|
|
||||||
float ret = stream[0];
|
|
||||||
foreach (float num in stream)
|
|
||||||
{
|
|
||||||
if (ret < num) {
|
|
||||||
ret = num;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float MinOf(params float[] stream)
|
|
||||||
{
|
|
||||||
float ret = stream[0];
|
|
||||||
foreach (float num in stream)
|
|
||||||
{
|
|
||||||
if (ret > num) {
|
|
||||||
ret = num;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Cos"
|
|
||||||
// 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.CompilerServices;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static float Cos(float x)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
float refer = x / 360.0f;
|
|
||||||
refer -= (int)refer;
|
|
||||||
|
|
||||||
refer *= 40;
|
|
||||||
int a = (int)refer; //大分度,查表
|
|
||||||
refer -= a; //小分度,拟合
|
|
||||||
|
|
||||||
float refer2 = refer * refer;
|
|
||||||
|
|
||||||
|
|
||||||
return ((-sinData[a]) * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)))
|
|
||||||
+ (cosData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)));
|
|
||||||
*/
|
|
||||||
return MathF.Cos(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Ctor"
|
|
||||||
// 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.Mathematics
|
|
||||||
{
|
|
||||||
public unsafe delegate float ScalarCalcHandler(float* x);
|
|
||||||
|
|
||||||
public static unsafe partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
private const uint MEM_COMMIT = 0x1000;
|
|
||||||
private const uint MEM_RELEASE = 0x8000;
|
|
||||||
private const uint MEM_RESERVE = 0x2000;
|
|
||||||
private const uint PAGE_EXECUTE_READWRITE = 0x40;
|
|
||||||
|
|
||||||
static Scalar() { }
|
|
||||||
|
|
||||||
[DllImport("Kernel32.dll", EntryPoint = "VirtualAlloc")]
|
|
||||||
private static extern IntPtr VirtualAlloc(IntPtr address, int size, uint allocType, uint protect);
|
|
||||||
|
|
||||||
[DllImport("Kernel32.dll", EntryPoint = "VirtualFree")]
|
|
||||||
private static extern bool VirtualFree(IntPtr address, int size, uint freeType);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Exp"
|
|
||||||
// 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.CompilerServices;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static unsafe partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
public const float E = 2.718281828f;
|
|
||||||
public const double EDouble = System.Math.E;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static float Exp(float x)
|
|
||||||
{
|
|
||||||
return MathF.Exp(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static double Exp(double x)
|
|
||||||
{
|
|
||||||
return System.Math.Exp(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the value of E ^ x;
|
|
||||||
/// </summary>
|
|
||||||
/// <param _label="x">
|
|
||||||
///
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
///
|
|
||||||
/// </returns>
|
|
||||||
public static unsafe float ExpSlow(float x)
|
|
||||||
{
|
|
||||||
if (x == 1) {
|
|
||||||
return E;
|
|
||||||
}
|
|
||||||
if (x == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sign = false;
|
|
||||||
if (x < 0)
|
|
||||||
{
|
|
||||||
sign = true;
|
|
||||||
x = -x;
|
|
||||||
}
|
|
||||||
|
|
||||||
float z = x, t;
|
|
||||||
if (x < 0.5f)
|
|
||||||
{
|
|
||||||
t = 1.0f + (x * (1.0f + (x * (0.5f + (x * (0.1666666667f + (x * (0.0416666666667f + (x * 8.333333333e-3f)))))))));
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* define z = n * 2 ^ m
|
|
||||||
* n is between 0 and 0.5
|
|
||||||
*/
|
|
||||||
uint zBit = *(uint*)&z;
|
|
||||||
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
|
||||||
uint uintm = zBitAbs >> 23;
|
|
||||||
int m = (*(int*)&uintm) - 126;
|
|
||||||
|
|
||||||
|
|
||||||
uint nBit = (zBitAbs & 0b_0000_0000_0111_1111_1111_1111_1111_1111) + 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
|
||||||
float n = (*(float*)&nBit) - 1;
|
|
||||||
|
|
||||||
t = 2.718281828f + (n * (2.718281828f + (n * (1.359140914f + (n * (0.4530469714f + (n * (0.1132617429f + (n * 0.02265234857f)))))))));
|
|
||||||
|
|
||||||
for (int i = 0; i < m; i++) {
|
|
||||||
t = t * t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sign) {
|
|
||||||
t = 1 / t;
|
|
||||||
}
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Factorial"
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
private static readonly uint[] factorialResult = [
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
6,
|
|
||||||
24,
|
|
||||||
120,
|
|
||||||
720,
|
|
||||||
5040,
|
|
||||||
40320,
|
|
||||||
362880,
|
|
||||||
3628800,
|
|
||||||
39916800,
|
|
||||||
479001600];
|
|
||||||
|
|
||||||
public static unsafe ulong Factorial(int n)
|
|
||||||
{
|
|
||||||
ArgumentOutOfRangeException.ThrowIfLessThan(n, 0);
|
|
||||||
if (n < 13) {
|
|
||||||
return factorialResult[n];
|
|
||||||
}
|
|
||||||
if (n < 30) {
|
|
||||||
return NumericalModule.GlobalContext.factorial_simd(n);
|
|
||||||
}
|
|
||||||
double
|
|
||||||
dn = n,
|
|
||||||
stir = Sqrt(2 * PiDouble * dn) * Pow(dn / EDouble, dn),
|
|
||||||
correction = Exp(1 / (12 * dn));
|
|
||||||
return (ulong)(stir * correction);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Log"
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
private static readonly float[] logArray = {
|
|
||||||
0f, 0.00995033085316809f, 0.0198026272961797f, 0.0295588022415444f, 0.0392207131532813f, 0.048790164169432f, 0.0582689081239758f, 0.0676586484738149f, 0.0769610411361284f, 0.0861776962410524f, 0.0953101798043249f, 0.104360015324243f, 0.113328685307003f, 0.122217632724249f, 0.131028262406404f, 0.139761942375159f, 0.148420005118273f, 0.157003748809665f, 0.165514438477573f, 0.173953307123438f, 0.182321556793955f, 0.19062035960865f, 0.198850858745165f, 0.207014169384326f, 0.215111379616945f, 0.22314355131421f, 0.231111720963387f, 0.2390169004705f, 0.246860077931526f, 0.254642218373581f, 0.262364264467491f, 0.27002713721306f, 0.27763173659828f, 0.285178942233662f, 0.29266961396282f, 0.300104592450338f, 0.307484699747961f, 0.314810739840034f, 0.322083499169113f, 0.3293037471426f, 0.336472236621213f, 0.343589704390077f, 0.350656871613169f, 0.357674444271816f, 0.364643113587909f, 0.371563556432483f, 0.378436435720245f, 0.385262400790645f, 0.392042087776024f, 0.398776119957368f, 0.405465108108164f, 0.412109650826833f, 0.418710334858185f, 0.425267735404344f, 0.431782416425538f, 0.438254930931155f, 0.444685821261446f, 0.451075619360217f, 0.457424847038875f, 0.46373401623214f, 0.470003629245736f, 0.476234178996372f, 0.482426149244293f, 0.488580014818671f, 0.494696241836107f, 0.500775287912489f, 0.506817602368452f, 0.512823626428664f, 0.518793793415168f, 0.524728528934982f, 0.53062825106217f, 0.536493370514568f, 0.542324290825362f, 0.548121408509688f, 0.553885113226438f, 0.559615787935423f, 0.56531380905006f, 0.570979546585738f, 0.576613364303994f, 0.582215619852664f, 0.587786664902119f, 0.593326845277734f, 0.598836501088704f, 0.60431596685333f, 0.609765571620894f, 0.615185639090233f, 0.62057648772511f, 0.625938430866495f, 0.631271776841858f, 0.636576829071551f, 0.641853886172395f, 0.647103242058538f, 0.65232518603969f, 0.657520002916794f, 0.662687973075237f, 0.667829372575655f, 0.672944473242426f, 0.678033542749897f, 0.683096844706444f, 0.688134638736401f,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param _label="x">
|
|
||||||
///
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// Returns the value of ln(x).
|
|
||||||
/// </returns>
|
|
||||||
public static unsafe float Log(float x)
|
|
||||||
{
|
|
||||||
if (x < 0) {
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
|
||||||
uint input = *(uint*)&x;
|
|
||||||
|
|
||||||
int f = (int)input;
|
|
||||||
f >>= 23;
|
|
||||||
f -= 127;
|
|
||||||
input <<= 9;
|
|
||||||
input >>= 9;
|
|
||||||
input += 0b_0011_1111_1000_0000_0000_0000_0000_0000;
|
|
||||||
float result = *(float*)&input;
|
|
||||||
uint order = ((uint)(result * 100)) - 100;
|
|
||||||
|
|
||||||
float cache = (result / (1f + (0.01f * order))) - 1;
|
|
||||||
result = (cache * (-0.25f)) + 0.3333333333333f;
|
|
||||||
result = (result * cache) - 0.5f;
|
|
||||||
result = (result * cache) + 1.0f;
|
|
||||||
result *= cache;
|
|
||||||
|
|
||||||
return
|
|
||||||
(f * 0.6931471806f) + result + logArray[order];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float Log(float x, float y)
|
|
||||||
{
|
|
||||||
return Log(x) / Log(y);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Pow"
|
|
||||||
// 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.Mathematics
|
|
||||||
{
|
|
||||||
public static unsafe partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe float Pow(float x, float y)
|
|
||||||
{
|
|
||||||
return System.MathF.Pow(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe double Pow(double x, double y)
|
|
||||||
{
|
|
||||||
return System.Math.Pow(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// calculate the value of x^y
|
|
||||||
/// </summary>
|
|
||||||
/// <param _label="x">
|
|
||||||
///
|
|
||||||
/// </param>
|
|
||||||
/// <param _label="y">
|
|
||||||
///
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// Returns the value of x^y
|
|
||||||
/// </returns>
|
|
||||||
public static unsafe float PowSlow(float x, float y)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* x^y = E ^ ( log( x ) * y )
|
|
||||||
* Now define z = | log(x) * y | = m * n
|
|
||||||
* and m is an integer, and 0.5 < |n| < 1
|
|
||||||
* then E ^ z = ( E ^ n ) ^ m
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* As a float number can be expressed in (1+e)*(2^f)
|
|
||||||
* n = (1+e)/2
|
|
||||||
* m = 2 ^ (f + 1)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
float z, t;
|
|
||||||
if ((x == 1) || (y == 0)) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if ((x == 1) && (y == 0)) {
|
|
||||||
return float.PositiveInfinity;
|
|
||||||
}
|
|
||||||
if ((x == 0) && (y != 0)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
z = Scalar.Log(x) * y;
|
|
||||||
|
|
||||||
bool sign = false;
|
|
||||||
if (z < 0)
|
|
||||||
{
|
|
||||||
sign = true;
|
|
||||||
z = -z;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (z < 0.5f)
|
|
||||||
{
|
|
||||||
t = 1.0f + (z * (1.0f + (z * (0.5f + (z * (0.1666666667f + (z * (0.0416666666667f + (z * 8.333333333e-3f)))))))));
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
uint zBit = *(uint*)&z;
|
|
||||||
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
|
||||||
uint uintm = zBitAbs >> 23;
|
|
||||||
int m = (*(int*)&uintm) - 126;
|
|
||||||
|
|
||||||
|
|
||||||
uint nBit = (zBitAbs & 0b_0000_0000_0111_1111_1111_1111_1111_1111) + 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
|
||||||
float n = (*(float*)&nBit) - 1;
|
|
||||||
|
|
||||||
t = 2.718281828f + (n * (2.718281828f + (n * (1.359140914f + (n * (0.4530469714f + (n * (0.1132617429f + (n * 0.02265234857f)))))))));
|
|
||||||
|
|
||||||
for (int i = 0; i < m; i++) {
|
|
||||||
t = t * t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sign) {
|
|
||||||
t = 1 / t;
|
|
||||||
}
|
|
||||||
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Random"
|
|
||||||
// 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.Data;
|
|
||||||
using System.Numerics;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static unsafe partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
private static byte[] randomSeed;
|
|
||||||
|
|
||||||
internal static float currentSeed
|
|
||||||
#if DEBUG
|
|
||||||
= 0.5f;
|
|
||||||
|
|
||||||
#else
|
|
||||||
= Abs(System.DateTime.UtcNow.GetHashCode());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// returns a random float number between 0 and 1.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
///
|
|
||||||
/// </returns>
|
|
||||||
public static unsafe float LowProceisionRandom()
|
|
||||||
{
|
|
||||||
float seed = currentSeed;
|
|
||||||
|
|
||||||
float sample = Scalar.Pow(Scalar.SeedSqrt(seed), 2);
|
|
||||||
float sample2 = (sample - seed) / seed;
|
|
||||||
sample2 = Scalar.Abs(sample2);
|
|
||||||
|
|
||||||
if (sample == 1) {
|
|
||||||
sample = sample2;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentSeed = sample;
|
|
||||||
sample2 *= 1000000;
|
|
||||||
|
|
||||||
float result = sample2 - ((int)sample2);
|
|
||||||
if (result == 0)
|
|
||||||
{
|
|
||||||
currentSeed = sample2 + 0.1f;
|
|
||||||
result = Scalar.LowProceisionRandom();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
///
|
|
||||||
/// </returns>
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static T Random<T>() where T : unmanaged, IConvertible, INumber<T>
|
|
||||||
|
|
||||||
{
|
|
||||||
if (randomSeed == null)
|
|
||||||
{
|
|
||||||
randomSeed = new byte[64];
|
|
||||||
string originSeed =
|
|
||||||
($"{((Assembly.GetEntryAssembly() == null) ? (Assembly.GetAssembly(typeof(World))!) :
|
|
||||||
Assembly.GetEntryAssembly())}") + ($"{DateTime.UtcNow.ToString("o")}");
|
|
||||||
randomSeed = SHA256.HashData(Encoding.UTF8.GetBytes(originSeed));
|
|
||||||
}
|
|
||||||
randomSeed = SHA256.HashData(randomSeed);
|
|
||||||
fixed (byte* bptr = randomSeed) {
|
|
||||||
return *(T*)bptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generates a random seed in int value.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
///
|
|
||||||
/// </returns>
|
|
||||||
public static unsafe int RandomSeed()
|
|
||||||
{
|
|
||||||
float seedValue1 = LowProceisionRandom();
|
|
||||||
float seedValue2 = LowProceisionRandom();
|
|
||||||
uint seedValueBits = *(uint*)&seedValue1;
|
|
||||||
|
|
||||||
float seedValue = seedValueBits * seedValue2;
|
|
||||||
|
|
||||||
return *(int*)&seedValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="RandomGenerator.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.Mathematics.Internal;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Xml.Serialization;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric.Scalar
|
|
||||||
{
|
|
||||||
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,65 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="SignOf"
|
|
||||||
// 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 unsafe partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe int SignOf(float x)
|
|
||||||
{
|
|
||||||
if (x == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (x > 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe int SignOf(int x)
|
|
||||||
{
|
|
||||||
if (x == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (x > 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Sin"
|
|
||||||
// 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.Net.NetworkInformation;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
public const float Pi = 3.1415926f;
|
|
||||||
public const double PiDouble = System.Math.PI;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe float Sin(float x)
|
|
||||||
{
|
|
||||||
return MathF.Sin(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="Sqrt"
|
|
||||||
// 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.CompilerServices;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
public static partial class Scalar
|
|
||||||
{
|
|
||||||
|
|
||||||
public static unsafe float SeedSqrt(float x)
|
|
||||||
{
|
|
||||||
ArgumentOutOfRangeException.ThrowIfNegative(x);
|
|
||||||
if (x <= 1e-12) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint a = *(uint*)&x;
|
|
||||||
uint f = a;
|
|
||||||
f >>= 23;
|
|
||||||
f /= 2;
|
|
||||||
f += 64;
|
|
||||||
a -= 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
|
||||||
uint e = a << 8;
|
|
||||||
e >>= 8;
|
|
||||||
e *= 0b_1101_0001;
|
|
||||||
e >>= 24;
|
|
||||||
e += 0b_0000_0000_0001_0000_1010_1000_1110_0010;
|
|
||||||
f <<= 23;
|
|
||||||
e += f;
|
|
||||||
float result = *(float*)&e;
|
|
||||||
result = (result + (x / result)) / 2;
|
|
||||||
return (result + (x / result)) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static float Sqrt(float x)
|
|
||||||
{
|
|
||||||
return MathF.Sqrt(x);
|
|
||||||
/**/
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static double Sqrt(double x)
|
|
||||||
{
|
|
||||||
return System.Math.Sqrt(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -97,10 +97,10 @@ namespace StgSharp.RegularAnalysis.Abstraction
|
|||||||
Token<TLabel> right
|
Token<TLabel> right
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return left.Value.SequenceEqual(right.Value) &&
|
return !left.Value.SequenceEqual(right.Value) ||
|
||||||
left.Line == right.Line &&
|
left.Line != right.Line ||
|
||||||
left.Column == right.Column &&
|
left.Column != right.Column ||
|
||||||
left.Flag.Equals(right.Flag);
|
!left.Flag.Equals(right.Flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(
|
public static bool operator ==(
|
||||||
@@ -108,10 +108,10 @@ namespace StgSharp.RegularAnalysis.Abstraction
|
|||||||
Token<TLabel> right
|
Token<TLabel> right
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return left.Value.SequenceEqual(right.Value) ||
|
return left.Value.SequenceEqual(right.Value) &&
|
||||||
left.Line != right.Line ||
|
left.Line == right.Line &&
|
||||||
left.Column != right.Column ||
|
left.Column == right.Column &&
|
||||||
!(left.Flag.Equals(right.Flag));
|
left.Flag.Equals(right.Flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,18 +56,18 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
|||||||
public static RegexAstNode Empty { get; }
|
public static RegexAstNode Empty { get; }
|
||||||
= new EmptyRegexAstNode();
|
= new EmptyRegexAstNode();
|
||||||
|
|
||||||
public RegexAstNode Previous { get; set; }
|
public RegexAstNode Previous { get; set; }
|
||||||
|
|
||||||
public RegexAstNode Next { get; set; }
|
public RegexAstNode Next { get; set; }
|
||||||
|
|
||||||
public RegexAstNode Parent { get; set; }
|
public RegexAstNode Parent { get; set; }
|
||||||
|
|
||||||
public RegexAstNode Left
|
public RegexAstNode Left
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
field?.Parent = Empty;
|
_ = (field?.Parent = Empty);
|
||||||
field = value;
|
field = value;
|
||||||
if (!IsNullOrEmpty(value)) {
|
if (!IsNullOrEmpty(value)) {
|
||||||
value.Parent = this;
|
value.Parent = this;
|
||||||
@@ -80,7 +80,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
|||||||
get;
|
get;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
field?.Parent = Empty;
|
_ = (field?.Parent = Empty);
|
||||||
field = value;
|
field = value;
|
||||||
if (!IsNullOrEmpty(value)) {
|
if (!IsNullOrEmpty(value)) {
|
||||||
value.Parent = this;
|
value.Parent = this;
|
||||||
@@ -88,10 +88,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegexElementLabel EqualityTypeConvert
|
public RegexElementLabel EqualityTypeConvert => Source.Flag;
|
||||||
{
|
|
||||||
get => Source.Flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Value => Source.Value;
|
public string Value => Source.Value;
|
||||||
|
|
||||||
@@ -108,9 +105,9 @@ namespace StgSharp.RegularAnalysis.TextRegex
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static (bool Valid,int Value) ComparePrecedence(
|
public static (bool Valid, int Value) ComparePrecedence(
|
||||||
RegexElementLabel left,
|
RegexElementLabel left,
|
||||||
RegexElementLabel right
|
RegexElementLabel right
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
left &= RegexElementLabel.OPERATOR;
|
left &= RegexElementLabel.OPERATOR;
|
||||||
|
|||||||
+16
-10
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixTest"
|
// file="MatrixTest"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
||||||
using StgSharp.Mathematics.Memory;
|
using StgSharp.Mathematics.Memory;
|
||||||
using StgSharp.Mathematics.Numeric;
|
using StgSharp.Mathematics.Numeric;
|
||||||
using System;
|
using System;
|
||||||
@@ -55,12 +54,18 @@ namespace StgSharp
|
|||||||
unchecked {
|
unchecked {
|
||||||
hlsf = new((nuint)size, 32, size);
|
hlsf = new((nuint)size, 32, size);
|
||||||
}
|
}
|
||||||
Matrix<T> m = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle, hlsf);
|
Matrix<T> m = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle,
|
||||||
MatrixCompute.Fill(m, 1.0f);
|
hlsf);
|
||||||
Matrix<T> n = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle, hlsf);
|
|
||||||
MatrixCompute.Fill(n, 1.0f);
|
// MatrixCompute.Fill(m, 1.0f);
|
||||||
Matrix<T> p = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle, hlsf);
|
Matrix<T> n = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle,
|
||||||
MatrixCompute.Fill(p, 0.0f);
|
hlsf);
|
||||||
|
|
||||||
|
// MatrixCompute.Fill(n, 1.0f);
|
||||||
|
Matrix<T> p = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle,
|
||||||
|
hlsf);
|
||||||
|
|
||||||
|
// MatrixCompute.Fill(p, 0.0f);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (int j = 0; j < 20; j++)
|
for (int j = 0; j < 20; j++)
|
||||||
@@ -73,7 +78,8 @@ namespace StgSharp
|
|||||||
|
|
||||||
/**/
|
/**/
|
||||||
Console.WriteLine("===================================================");
|
Console.WriteLine("===================================================");
|
||||||
MatrixCompute.Mul(n, m, p);
|
|
||||||
|
// MatrixCompute.Mul(n, m, p);
|
||||||
/**/
|
/**/
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Controls;
|
|
||||||
using StgSharp.Geometries;
|
using StgSharp.Geometries;
|
||||||
using StgSharp.Graphics;
|
using StgSharp.Graphics;
|
||||||
using StgSharp.Graphics.OpenGL;
|
using StgSharp.Graphics.OpenGL;
|
||||||
@@ -192,6 +191,7 @@ namespace StgSharp
|
|||||||
GL.Assert(false);
|
GL.Assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public void RenderButton(
|
public void RenderButton(
|
||||||
ButtonStatus status,
|
ButtonStatus status,
|
||||||
float statusBegin,
|
float statusBegin,
|
||||||
@@ -200,7 +200,7 @@ namespace StgSharp
|
|||||||
{
|
{
|
||||||
provider.UpdateFromImage(i);
|
provider.UpdateFromImage(i);
|
||||||
}
|
}
|
||||||
|
/**/
|
||||||
internal static Vec3 DefaultRotation(
|
internal static Vec3 DefaultRotation(
|
||||||
TimeSpanProvider provider,
|
TimeSpanProvider provider,
|
||||||
out float rotation
|
out float rotation
|
||||||
@@ -208,7 +208,7 @@ namespace StgSharp
|
|||||||
{
|
{
|
||||||
rotation = 1.0f / 60;
|
rotation = 1.0f / 60;
|
||||||
float angle = (float)provider.CurrentSecond * 2;
|
float angle = (float)provider.CurrentSecond * 2;
|
||||||
return (new Vec3(Scalar.Cos(angle), Scalar.Sin(angle),
|
return (new Vec3(MathF.Cos(angle), MathF.Sin(angle),
|
||||||
0)) * rotation;
|
0)) * rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,16 +222,16 @@ namespace StgSharp
|
|||||||
buffer = new PlainInstancingBuffer<ParticleOnPlain>();
|
buffer = new PlainInstancingBuffer<ParticleOnPlain>();
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
float ai = Scalar.Abs(i - 5.0f);
|
float ai = MathF.Abs(i - 5.0f);
|
||||||
for (int t = 0; t < 10; t++)
|
for (int t = 0; t < 10; t++)
|
||||||
{
|
{
|
||||||
float at = Scalar.Abs(t - 5.0f);
|
float at = MathF.Abs(t - 5.0f);
|
||||||
|
|
||||||
ParticleOnPlain p = new ParticleOnPlain(buffer);
|
ParticleOnPlain p = new ParticleOnPlain(buffer);
|
||||||
((IInstancing)p).Coord = new Vec3(
|
((IInstancing)p).Coord = new Vec3(
|
||||||
(((-5) + i) * 0.2f) + 0.1f, (((-5) + t) * 0.2f) + 0.1f, 0);
|
(((-5) + i) * 0.2f) + 0.1f, (((-5) + t) * 0.2f) + 0.1f, 0);
|
||||||
((IInstancing)p).Scale =
|
((IInstancing)p).Scale =
|
||||||
Scalar.MinOf(i, t) * 0.15f;
|
float.Min(i, t) * 0.15f;
|
||||||
((IInstancing)p).Motion = new GeometryMotion(
|
((IInstancing)p).Motion = new GeometryMotion(
|
||||||
true, TimeProvider, DefaultRotation);
|
true, TimeProvider, DefaultRotation);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
#version 430 core
|
|
||||||
|
|
||||||
in vec3 texCoord;
|
|
||||||
|
|
||||||
out vec4 fragColor;
|
|
||||||
|
|
||||||
uniform sampler2D tex;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
fragColor = texture(tex, texCoord.xy);
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#version 430 core
|
|
||||||
|
|
||||||
layout(location = 0)in vec3 coord;
|
|
||||||
layout(location = 1)in vec3 tCoord;
|
|
||||||
|
|
||||||
out vec3 texCoord;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vec4(coord.xyz,1.0f);
|
|
||||||
texCoord = tCoord;
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 29 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 40 KiB |
@@ -1,13 +0,0 @@
|
|||||||
#version 430 core
|
|
||||||
|
|
||||||
in vec3 texCoord;
|
|
||||||
|
|
||||||
out vec4 fragColor;
|
|
||||||
|
|
||||||
uniform sampler2D tex;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
fragColor = texture(tex, texCoord.xy);
|
|
||||||
//fragColor = vec4(0.099f,0.226f,0.335f,0.0f);
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
|
|
||||||
layout(location = 0)in vec3 coord;
|
|
||||||
layout(location = 1)in vec3 tCoord;
|
|
||||||
|
|
||||||
out vec3 texCoord;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vec4(coord.xyz,1.0f);
|
|
||||||
texCoord = tCoord;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
|
|
||||||
in vec2 TexCoord;
|
|
||||||
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
uniform vec4 color;
|
|
||||||
uniform sampler2D ourTexture;
|
|
||||||
uniform sampler2D ourTexture2;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
vec4 tex1 = texture(ourTexture, TexCoord);
|
|
||||||
vec4 tex2 = texture(ourTexture2,TexCoord);
|
|
||||||
FragColor = mix(tex1 * vec4( color.xyz, 1.0), tex2, 0.2) /* *vec4( TexColor,1.0) /**/;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 aPos;
|
|
||||||
layout(location = 1) in vec3 aColor;
|
|
||||||
layout(location = 2) in vec2 aTextCoord;
|
|
||||||
|
|
||||||
out vec2 TexCoord;
|
|
||||||
|
|
||||||
uniform mat4x4 camera;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
|
|
||||||
TexCoord = aTextCoord;
|
|
||||||
vec4 temp = vec4(aPos.xyz,1.0);
|
|
||||||
gl_Position = /**/ camera * /**/ temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
//struct
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#version 460 core
|
|
||||||
|
|
||||||
uniform float time;
|
|
||||||
|
|
||||||
out vec3 fragColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
|
|
||||||
fragColor = vec3( 0.5f,0.336f,mod( (0.9961f + time),1.0f) );
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#version 460 core
|
|
||||||
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 singleCoord;
|
|
||||||
layout(location = 1) in vec3 locations;
|
|
||||||
layout(location = 2) in float rotation;
|
|
||||||
layout(location = 3) in float scale;
|
|
||||||
|
|
||||||
uniform mat4x4 Camera;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
/**/
|
|
||||||
mat4x4 scalingMat = mat4x4
|
|
||||||
(
|
|
||||||
scale,0,0,0,
|
|
||||||
0,scale,0,0,
|
|
||||||
0,0,scale,0,
|
|
||||||
0,0,0,1
|
|
||||||
);
|
|
||||||
/**/
|
|
||||||
/**/
|
|
||||||
|
|
||||||
mat4x4 rotationMat = mat4x4
|
|
||||||
(
|
|
||||||
cos(rotation),-sin(rotation),0,0,
|
|
||||||
sin(rotation),cos(rotation),0,0,
|
|
||||||
0,0,1,0,
|
|
||||||
0,0,0,1
|
|
||||||
);
|
|
||||||
|
|
||||||
/**/
|
|
||||||
|
|
||||||
gl_Position = Camera * ( rotationMat * scalingMat * vec4( singleCoord.xyz , 1) + vec4( locations.xyz , 0));
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -17,32 +17,5 @@
|
|||||||
<ProjectReference Include="..\StgSharp.RegularAnalysis\StgSharp.RegularAnalysis.csproj" />
|
<ProjectReference Include="..\StgSharp.RegularAnalysis\StgSharp.RegularAnalysis.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="Shader\awesomeface.png">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Shader\fbo.frag">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Shader\fbo.vert">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Shader\Image1.png">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Shader\main.frag">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Shader\main.vert">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Shader\particle.vert">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Shader\particle.frag">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="TestSwiss"
|
// file="TestSwiss"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -41,21 +41,23 @@ namespace StgSharp
|
|||||||
public static void TestSwiss()
|
public static void TestSwiss()
|
||||||
{
|
{
|
||||||
SwissTable swiss = SwissTable.Create();
|
SwissTable swiss = SwissTable.Create();
|
||||||
for (int i = 0; i < 10000; i++)
|
for (int i = 0; i < 5000; i++)
|
||||||
{
|
{
|
||||||
|
Console.Write($"Set {i}: ");
|
||||||
_ = swiss.TryAddOrSet(i, i * 2, out _);
|
_ = swiss.TryAddOrSet(i, i * 2, out _);
|
||||||
Console.WriteLine($"Set a kvp of ({i},{i * 2})");
|
Console.WriteLine($"Set a kvp of ({i},{i * 2})");
|
||||||
}
|
}
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
for (int i = 0; i < 10000; i++)
|
for (int i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
int key = rand.Next(0, 10000);
|
Console.Write($"Get {i}: ");
|
||||||
|
int key = rand.Next(4000, 5000);
|
||||||
if (swiss.TryGet(key, out nint value))
|
if (swiss.TryGet(key, out nint value))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Get a kvp of ({key},{value})");
|
Console.WriteLine($"Success in get a kvp of ({key},{value})");
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Failed to get a kvp of ({key},?)");
|
Console.WriteLine($"Failed to get a kvp of ({key},?)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// file="Control.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.Controlling.UsrActivity;
|
|
||||||
using StgSharp.MVVM;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp
|
|
||||||
{
|
|
||||||
public partial class ViewMain
|
|
||||||
{
|
|
||||||
|
|
||||||
protected class Control : ViewResponder<ViewMain>
|
|
||||||
{
|
|
||||||
|
|
||||||
public Control( ViewMain view ) : base( view ) { }
|
|
||||||
|
|
||||||
public override void CustomizedInitialize(
|
|
||||||
Func<IClickTrigger, string, Action> keyRegister ) { }
|
|
||||||
|
|
||||||
public override bool ValidateInitializing()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// file="Design.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.Controlling;
|
|
||||||
using StgSharp.Controlling.UsrActivity;
|
|
||||||
using StgSharp.Controls;
|
|
||||||
|
|
||||||
using StgSharp.Geometries;
|
|
||||||
using StgSharp.Graphics;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp
|
|
||||||
{
|
|
||||||
public partial class ViewMain
|
|
||||||
{
|
|
||||||
|
|
||||||
internal DemoButtonGroup Group { get; set; }
|
|
||||||
|
|
||||||
internal TriggerButton OnlyButton { get; set; }
|
|
||||||
|
|
||||||
internal class Design : ViewDesigner<ViewMain>
|
|
||||||
{
|
|
||||||
|
|
||||||
public Design( ViewMain view ) : base( view ) { }
|
|
||||||
|
|
||||||
public override sealed void CustomizedInitialize()
|
|
||||||
{
|
|
||||||
Binding.Group = CreateKeyboardButtonGroup<DemoButtonGroup>(
|
|
||||||
new KeyTrigger( KeyboardKey.Left, KeyStatus.PRESS ),
|
|
||||||
new KeyTrigger( KeyboardKey.Right, KeyStatus.PRESS ),
|
|
||||||
new KeyTrigger( KeyboardKey.Up, KeyStatus.PRESS ),
|
|
||||||
new KeyTrigger( KeyboardKey.Down, KeyStatus.PRESS ),
|
|
||||||
new KeyTrigger( KeyboardKey.Enter, KeyStatus.PRESS ) );
|
|
||||||
Binding.OnlyButton = CreateKeyboardButton(
|
|
||||||
Binding.Stream.ButtonBounding, Binding.Stream.ButtonTextureProvider, true );
|
|
||||||
Binding.OnlyButton.RenderButtonTexture += Binding.Stream.RenderButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool ValidateInitializing()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DemoButtonGroup : KeyboardButtonGroup
|
|
||||||
{
|
|
||||||
|
|
||||||
public override sealed void Confirm()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// file="ViewMain.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.Graphics;
|
|
||||||
using StgSharp.MVVM;
|
|
||||||
using StgSharp.MVVM.ViewModel;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp
|
|
||||||
{
|
|
||||||
public partial class ViewMain : ViewBase
|
|
||||||
{
|
|
||||||
|
|
||||||
private Dictionary<string, DataBindingEntry> _databindingIndexMap;
|
|
||||||
|
|
||||||
public ViewMain()
|
|
||||||
{
|
|
||||||
_databindingIndexMap = new Dictionary<string, DataBindingEntry>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void CustomizedInitialize( [NotNull]ViewModelBase viewModelBinding )
|
|
||||||
{
|
|
||||||
Designer = new Design( this );
|
|
||||||
Responder = new Control( this );
|
|
||||||
Render = new NewRender( this );
|
|
||||||
|
|
||||||
Render.Initialize();
|
|
||||||
Designer.Initialize();
|
|
||||||
Responder.Initialize( viewModelBinding.MethodLookup );
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool TryGetObjectReference( string name, out DataBindingEntry entry )
|
|
||||||
{
|
|
||||||
if( _databindingIndexMap.TryGetValue( name, out entry ) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
entry = name switch
|
|
||||||
{
|
|
||||||
_ => default( DataBindingEntry ),
|
|
||||||
};
|
|
||||||
return !entry.ExactEqual( default( DataBindingEntry ) );
|
|
||||||
}
|
|
||||||
catch( Exception )
|
|
||||||
{
|
|
||||||
entry = default( DataBindingEntry );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Show()
|
|
||||||
{
|
|
||||||
Stream.RenderStart();
|
|
||||||
|
|
||||||
//Stream.NothingMain();
|
|
||||||
|
|
||||||
Stream.Main();
|
|
||||||
Stream.ButtonMain( OnlyButton );
|
|
||||||
Stream.RenderEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// file="ViewModelMain.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.Graphics;
|
|
||||||
|
|
||||||
using StgSharp.MVVM;
|
|
||||||
using StgSharp.MVVM.ViewModel;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp
|
|
||||||
{
|
|
||||||
public class ViewModelMain : ViewModelBase
|
|
||||||
{
|
|
||||||
|
|
||||||
private Dictionary<string, DataBindingEntry> dataBindingEntryIndexMap;
|
|
||||||
|
|
||||||
public ViewModelMain( ViewPort vp )
|
|
||||||
: base( vp, 60 )
|
|
||||||
{
|
|
||||||
dataBindingEntryIndexMap = new Dictionary<string, DataBindingEntry>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void CustomizeInitialize() { }
|
|
||||||
|
|
||||||
public override bool TryGetObjectReference( string name, out DataBindingEntry entry )
|
|
||||||
{
|
|
||||||
if( dataBindingEntryIndexMap.TryGetValue( name, out entry ) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
entry = name switch
|
|
||||||
{
|
|
||||||
_ => DataBindingEntry.NullBinding,
|
|
||||||
};
|
|
||||||
|
|
||||||
if( entry.ExactEqual( DataBindingEntry.NullBinding ) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
dataBindingEntryIndexMap.Add( name, entry );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}//------------------------------------- End of Class ------------------------------------------
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"Name": "新建配置文件",
|
||||||
|
"Projects": []
|
||||||
|
}
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user