temp
This commit is contained in:
+286
-286
@@ -1,286 +1,286 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="HlsfStressTest"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static class HlsfStressTest
|
||||
{
|
||||
|
||||
private const uint MaxAllocSize = 32 * 1024 * 1024; // 32MB documented cap
|
||||
|
||||
// Allow overriding arena size via env HLSF_ARENA_MB (must be >=64MB)
|
||||
private static readonly ulong ArenaBytes = Environment.GetEnvironmentVariable("HLSF_ARENA_MB") is string mbStr &&
|
||||
int.TryParse(mbStr, out int mb) &&
|
||||
mb >= 64 ?
|
||||
(ulong)mb * 1024UL * 1024UL :
|
||||
3UL * 1024UL * 1024UL * 1024UL; // lower default to 512MB
|
||||
|
||||
private static readonly uint[] SizeSweep = {
|
||||
64, 128, 192, 256, 512, 768, 1024, 2048, 3072, 4096, 8192, 12288, 16384, 32768, 49152, 65536, 131072, 196608, 262144, 524288, 786432, 1_048_576, 2_097_152, 3_145_728, 4_194_304, 8_388_608, 12_582_912, 16_777_216, 25_165_824, 33_554_432
|
||||
};
|
||||
|
||||
public static unsafe void Run()
|
||||
{
|
||||
Console.WriteLine("=== HLSF Allocator Single-Thread Performance Benchmark ===");
|
||||
Console.WriteLine($"Arena size: {ArenaBytes / (1024 * 1024)} MiB (env override: HLSF_ARENA_MB)");
|
||||
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("[1] Allocation throughput (no touch)");
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
foreach (uint sz in SizeSweep)
|
||||
{
|
||||
uint size = sz > MaxAllocSize ? MaxAllocSize : sz;
|
||||
BenchAllocThroughput(allocator, size, touch:false);
|
||||
allocator.Collect();
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("[2] Allocation throughput (touch first byte)");
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
foreach (uint sz in SizeSweep)
|
||||
{
|
||||
uint size = sz > MaxAllocSize ? MaxAllocSize : sz;
|
||||
BenchAllocThroughput(allocator, size, touch:true);
|
||||
allocator.Collect();
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
Console.WriteLine("[3] Free throughput after pre-allocation (256k blocks of 1KB)");
|
||||
BenchFreeThroughput(allocator, 256 * 1024, 1024);
|
||||
allocator.Collect();
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("[4] Alloc+Immediate Free pairs (5,000,000 x 256B)");
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
BenchAllocFreePairs(allocator, 5_000_000, 256);
|
||||
allocator.Collect();
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("[5] Fragmentation cycle (allocate ~1024MB random, free half, reallocate)");
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
BenchFragmentationCycle(allocator, 512); // target within 500MB arena
|
||||
allocator.Collect();
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("=== Benchmark Complete ===");
|
||||
}
|
||||
|
||||
private static void BenchAllocFreePairs(
|
||||
HybridLayerSegregatedFitAllocator allocator,
|
||||
int pairs,
|
||||
uint blockSize)
|
||||
{
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
for (int i = 0; i < pairs; i++)
|
||||
{
|
||||
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(blockSize);
|
||||
allocator.Free(h);
|
||||
}
|
||||
sw.Stop();
|
||||
double opsPerSec = pairs / sw.Elapsed.TotalSeconds;
|
||||
|
||||
// Left align and widen columns
|
||||
Console.WriteLine($" size={Fmt(blockSize),-12} pairs={pairs,-12} alloc+free/s={opsPerSec,-16:0.0}");
|
||||
}
|
||||
|
||||
private static void BenchAllocThroughput(
|
||||
HybridLayerSegregatedFitAllocator allocator,
|
||||
uint blockSize,
|
||||
bool touch)
|
||||
{
|
||||
ulong budget = ArenaBytes / 2; // use half arena for test
|
||||
if (blockSize == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
long ops = (long)(budget / blockSize);
|
||||
ops = Math.Min(ops, blockSize >= (4 * 1024 * 1024) ? 2048 : 2_000_000);
|
||||
if (ops <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<HybridLayerSegregatedFitAllocationHandle> list = new List<HybridLayerSegregatedFitAllocationHandle>((int)ops);
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
for (long i = 0; i < ops; i++)
|
||||
{
|
||||
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(blockSize);
|
||||
if (touch)
|
||||
{
|
||||
Span<byte> span = h.BufferHandle;
|
||||
if (!span.IsEmpty) {
|
||||
span[0] = (byte)(i & 0xFF);
|
||||
}
|
||||
}
|
||||
list.Add(h);
|
||||
|
||||
// Console.WriteLine(i);
|
||||
}
|
||||
sw.Stop();
|
||||
double allocOpsPerSec = ops / sw.Elapsed.TotalSeconds;
|
||||
foreach (HybridLayerSegregatedFitAllocationHandle h in list) {
|
||||
allocator.Free(h);
|
||||
}
|
||||
|
||||
// Left align and widen columns
|
||||
Console.WriteLine($" size={Fmt(blockSize),-12} ops={ops,-12} alloc/s={allocOpsPerSec,-16:0.0} touch={touch,-5}");
|
||||
}
|
||||
|
||||
private static void BenchFragmentationCycle(
|
||||
HybridLayerSegregatedFitAllocator allocator,
|
||||
int targetMiB)
|
||||
{
|
||||
int targetBytes = targetMiB * 1024 * 1024;
|
||||
Random rng = new Random(123);
|
||||
List<HybridLayerSegregatedFitAllocationHandle> live = new List<HybridLayerSegregatedFitAllocationHandle>(128 * 1024);
|
||||
long allocated = 0;
|
||||
Stopwatch swA = Stopwatch.StartNew();
|
||||
while (allocated < targetBytes)
|
||||
{
|
||||
uint sz = PickSize(rng);
|
||||
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(sz);
|
||||
live.Add(h);
|
||||
allocated += sz;
|
||||
}
|
||||
swA.Stop();
|
||||
Console.WriteLine($" phaseA alloc {targetMiB}MB in {swA.Elapsed.TotalSeconds:0.00}s blocks={live.Count}");
|
||||
|
||||
Stopwatch swB = Stopwatch.StartNew();
|
||||
int freed = 0;
|
||||
for (int i = live.Count - 1; i >= 0; i -= 2)
|
||||
{
|
||||
allocator.Free(live[i]);
|
||||
live.RemoveAt(i);
|
||||
freed++;
|
||||
}
|
||||
swB.Stop();
|
||||
Console.WriteLine($" phaseB freed {freed} in {swB.Elapsed.TotalSeconds:0.00}s remain={live.Count}");
|
||||
|
||||
allocated = 0;
|
||||
int reCount = 0;
|
||||
Stopwatch swC = Stopwatch.StartNew();
|
||||
while (allocated < targetBytes / 2)
|
||||
{
|
||||
uint sz = PickSize(rng);
|
||||
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(sz);
|
||||
live.Add(h);
|
||||
allocated += sz;
|
||||
reCount++;
|
||||
}
|
||||
swC.Stop();
|
||||
Console.WriteLine($" phaseC re-alloc {reCount} in {swC.Elapsed.TotalSeconds:0.00}s ~{allocated / (1024.0 * 1024.0):0}MB");
|
||||
|
||||
Stopwatch swD = Stopwatch.StartNew();
|
||||
foreach (HybridLayerSegregatedFitAllocationHandle h in live) {
|
||||
allocator.Free(h);
|
||||
}
|
||||
|
||||
swD.Stop();
|
||||
Console.WriteLine($" cleanup freed {live.Count} in {swD.Elapsed.TotalSeconds:0.00}s");
|
||||
}
|
||||
|
||||
private static void BenchFreeThroughput(
|
||||
HybridLayerSegregatedFitAllocator allocator,
|
||||
int count,
|
||||
uint blockSize)
|
||||
{
|
||||
List<HybridLayerSegregatedFitAllocationHandle> list = new List<HybridLayerSegregatedFitAllocationHandle>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
list.Add(allocator.Alloc(blockSize));
|
||||
}
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
for (int i = 0; i < count; i++) {
|
||||
allocator.Free(list[i]);
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
double freesPerSec = count / sw.Elapsed.TotalSeconds;
|
||||
|
||||
// Left align and widen columns
|
||||
Console.WriteLine($" size={Fmt(blockSize),-12} count={count,-12} free/s={freesPerSec,-16:0.0}");
|
||||
}
|
||||
|
||||
private static string Fmt(uint bytes)
|
||||
{
|
||||
if (bytes >= 1024 * 1024) {
|
||||
return $"{bytes / (1024 * 1024)}MB";
|
||||
}
|
||||
|
||||
if (bytes >= 1024) {
|
||||
return $"{bytes / 1024}KB";
|
||||
}
|
||||
|
||||
return $"{bytes}B";
|
||||
}
|
||||
|
||||
private static uint PickSize(Random rng)
|
||||
{
|
||||
uint raw = SizeSweep[rng.Next(SizeSweep.Length)];
|
||||
return raw > MaxAllocSize ? MaxAllocSize : raw;
|
||||
}
|
||||
|
||||
private static void Warmup(HybridLayerSegregatedFitAllocator allocator)
|
||||
{
|
||||
List<HybridLayerSegregatedFitAllocationHandle> tmp = new List<HybridLayerSegregatedFitAllocationHandle>(4096);
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
tmp.Add(allocator.Alloc(256));
|
||||
}
|
||||
|
||||
foreach (HybridLayerSegregatedFitAllocationHandle h in tmp) {
|
||||
allocator.Free(h);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="HlsfStressTest"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static class HlsfStressTest
|
||||
{
|
||||
|
||||
private const uint MaxAllocSize = 32 * 1024 * 1024; // 32MB documented cap
|
||||
|
||||
// Allow overriding arena size via env HLSF_ARENA_MB (must be >=64MB)
|
||||
private static readonly ulong ArenaBytes = Environment.GetEnvironmentVariable("HLSF_ARENA_MB") is string mbStr &&
|
||||
int.TryParse(mbStr, out int mb) &&
|
||||
mb >= 64 ?
|
||||
(ulong)mb * 1024UL * 1024UL :
|
||||
3UL * 1024UL * 1024UL * 1024UL; // lower default to 512MB
|
||||
|
||||
private static readonly uint[] SizeSweep = {
|
||||
64, 128, 192, 256, 512, 768, 1024, 2048, 3072, 4096, 8192, 12288, 16384, 32768, 49152, 65536, 131072, 196608, 262144, 524288, 786432, 1_048_576, 2_097_152, 3_145_728, 4_194_304, 8_388_608, 12_582_912, 16_777_216, 25_165_824, 33_554_432
|
||||
};
|
||||
|
||||
public static unsafe void Run()
|
||||
{
|
||||
Console.WriteLine("=== HLSF Allocator Single-Thread Performance Benchmark ===");
|
||||
Console.WriteLine($"Arena size: {ArenaBytes / (1024 * 1024)} MiB (env override: HLSF_ARENA_MB)");
|
||||
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("[1] Allocation throughput (no touch)");
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
foreach (uint sz in SizeSweep)
|
||||
{
|
||||
uint size = sz > MaxAllocSize ? MaxAllocSize : sz;
|
||||
BenchAllocThroughput(allocator, size, touch:false);
|
||||
allocator.Collect();
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("[2] Allocation throughput (touch first byte)");
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
foreach (uint sz in SizeSweep)
|
||||
{
|
||||
uint size = sz > MaxAllocSize ? MaxAllocSize : sz;
|
||||
BenchAllocThroughput(allocator, size, touch:true);
|
||||
allocator.Collect();
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
Console.WriteLine("[3] Free throughput after pre-allocation (256k blocks of 1KB)");
|
||||
BenchFreeThroughput(allocator, 256 * 1024, 1024);
|
||||
allocator.Collect();
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("[4] Alloc+Immediate Free pairs (5,000,000 x 256B)");
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
BenchAllocFreePairs(allocator, 5_000_000, 256);
|
||||
allocator.Collect();
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("[5] Fragmentation cycle (allocate ~1024MB random, free half, reallocate)");
|
||||
using (HybridLayerSegregatedFitAllocator allocator = new HybridLayerSegregatedFitAllocator((nuint)ArenaBytes))
|
||||
{
|
||||
Warmup(allocator);
|
||||
|
||||
BenchFragmentationCycle(allocator, 512); // target within 500MB arena
|
||||
allocator.Collect();
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("=== Benchmark Complete ===");
|
||||
}
|
||||
|
||||
private static void BenchAllocFreePairs(
|
||||
HybridLayerSegregatedFitAllocator allocator,
|
||||
int pairs,
|
||||
uint blockSize)
|
||||
{
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
for (int i = 0; i < pairs; i++)
|
||||
{
|
||||
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(blockSize);
|
||||
allocator.Free(h);
|
||||
}
|
||||
sw.Stop();
|
||||
double opsPerSec = pairs / sw.Elapsed.TotalSeconds;
|
||||
|
||||
// Left align and widen columns
|
||||
Console.WriteLine($" size={Fmt(blockSize),-12} pairs={pairs,-12} alloc+free/s={opsPerSec,-16:0.0}");
|
||||
}
|
||||
|
||||
private static void BenchAllocThroughput(
|
||||
HybridLayerSegregatedFitAllocator allocator,
|
||||
uint blockSize,
|
||||
bool touch)
|
||||
{
|
||||
ulong budget = ArenaBytes / 2; // use half arena for test
|
||||
if (blockSize == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
long ops = (long)(budget / blockSize);
|
||||
ops = Math.Min(ops, blockSize >= (4 * 1024 * 1024) ? 2048 : 2_000_000);
|
||||
if (ops <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<HybridLayerSegregatedFitAllocationHandle> list = new List<HybridLayerSegregatedFitAllocationHandle>((int)ops);
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
for (long i = 0; i < ops; i++)
|
||||
{
|
||||
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(blockSize);
|
||||
if (touch)
|
||||
{
|
||||
Span<byte> span = h.BufferHandle;
|
||||
if (!span.IsEmpty) {
|
||||
span[0] = (byte)(i & 0xFF);
|
||||
}
|
||||
}
|
||||
list.Add(h);
|
||||
|
||||
// Console.WriteLine(i);
|
||||
}
|
||||
sw.Stop();
|
||||
double allocOpsPerSec = ops / sw.Elapsed.TotalSeconds;
|
||||
foreach (HybridLayerSegregatedFitAllocationHandle h in list) {
|
||||
allocator.Free(h);
|
||||
}
|
||||
|
||||
// Left align and widen columns
|
||||
Console.WriteLine($" size={Fmt(blockSize),-12} ops={ops,-12} alloc/s={allocOpsPerSec,-16:0.0} touch={touch,-5}");
|
||||
}
|
||||
|
||||
private static void BenchFragmentationCycle(
|
||||
HybridLayerSegregatedFitAllocator allocator,
|
||||
int targetMiB)
|
||||
{
|
||||
int targetBytes = targetMiB * 1024 * 1024;
|
||||
Random rng = new Random(123);
|
||||
List<HybridLayerSegregatedFitAllocationHandle> live = new List<HybridLayerSegregatedFitAllocationHandle>(128 * 1024);
|
||||
long allocated = 0;
|
||||
Stopwatch swA = Stopwatch.StartNew();
|
||||
while (allocated < targetBytes)
|
||||
{
|
||||
uint sz = PickSize(rng);
|
||||
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(sz);
|
||||
live.Add(h);
|
||||
allocated += sz;
|
||||
}
|
||||
swA.Stop();
|
||||
Console.WriteLine($" phaseA alloc {targetMiB}MB in {swA.Elapsed.TotalSeconds:0.00}s blocks={live.Count}");
|
||||
|
||||
Stopwatch swB = Stopwatch.StartNew();
|
||||
int freed = 0;
|
||||
for (int i = live.Count - 1; i >= 0; i -= 2)
|
||||
{
|
||||
allocator.Free(live[i]);
|
||||
live.RemoveAt(i);
|
||||
freed++;
|
||||
}
|
||||
swB.Stop();
|
||||
Console.WriteLine($" phaseB freed {freed} in {swB.Elapsed.TotalSeconds:0.00}s remain={live.Count}");
|
||||
|
||||
allocated = 0;
|
||||
int reCount = 0;
|
||||
Stopwatch swC = Stopwatch.StartNew();
|
||||
while (allocated < targetBytes / 2)
|
||||
{
|
||||
uint sz = PickSize(rng);
|
||||
HybridLayerSegregatedFitAllocationHandle h = allocator.Alloc(sz);
|
||||
live.Add(h);
|
||||
allocated += sz;
|
||||
reCount++;
|
||||
}
|
||||
swC.Stop();
|
||||
Console.WriteLine($" phaseC re-alloc {reCount} in {swC.Elapsed.TotalSeconds:0.00}s ~{allocated / (1024.0 * 1024.0):0}MB");
|
||||
|
||||
Stopwatch swD = Stopwatch.StartNew();
|
||||
foreach (HybridLayerSegregatedFitAllocationHandle h in live) {
|
||||
allocator.Free(h);
|
||||
}
|
||||
|
||||
swD.Stop();
|
||||
Console.WriteLine($" cleanup freed {live.Count} in {swD.Elapsed.TotalSeconds:0.00}s");
|
||||
}
|
||||
|
||||
private static void BenchFreeThroughput(
|
||||
HybridLayerSegregatedFitAllocator allocator,
|
||||
int count,
|
||||
uint blockSize)
|
||||
{
|
||||
List<HybridLayerSegregatedFitAllocationHandle> list = new List<HybridLayerSegregatedFitAllocationHandle>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
list.Add(allocator.Alloc(blockSize));
|
||||
}
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
for (int i = 0; i < count; i++) {
|
||||
allocator.Free(list[i]);
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
double freesPerSec = count / sw.Elapsed.TotalSeconds;
|
||||
|
||||
// Left align and widen columns
|
||||
Console.WriteLine($" size={Fmt(blockSize),-12} count={count,-12} free/s={freesPerSec,-16:0.0}");
|
||||
}
|
||||
|
||||
private static string Fmt(uint bytes)
|
||||
{
|
||||
if (bytes >= 1024 * 1024) {
|
||||
return $"{bytes / (1024 * 1024)}MB";
|
||||
}
|
||||
|
||||
if (bytes >= 1024) {
|
||||
return $"{bytes / 1024}KB";
|
||||
}
|
||||
|
||||
return $"{bytes}B";
|
||||
}
|
||||
|
||||
private static uint PickSize(Random rng)
|
||||
{
|
||||
uint raw = SizeSweep[rng.Next(SizeSweep.Length)];
|
||||
return raw > MaxAllocSize ? MaxAllocSize : raw;
|
||||
}
|
||||
|
||||
private static void Warmup(HybridLayerSegregatedFitAllocator allocator)
|
||||
{
|
||||
List<HybridLayerSegregatedFitAllocationHandle> tmp = new List<HybridLayerSegregatedFitAllocationHandle>(4096);
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
tmp.Add(allocator.Alloc(256));
|
||||
}
|
||||
|
||||
foreach (HybridLayerSegregatedFitAllocationHandle h in tmp) {
|
||||
allocator.Free(h);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+101
-102
@@ -1,103 +1,102 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixTest"
|
||||
// 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 Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using T = float;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
private static int sideLength = 20;
|
||||
|
||||
internal static unsafe void TestMatrix(
|
||||
)
|
||||
{
|
||||
// TestRender();
|
||||
/**/
|
||||
HybridLayerSegregatedFitAllocator hlsf;
|
||||
unchecked {
|
||||
hlsf = new((nuint)(4 * (ulong)1024 * 1024 * 1024), 32, 1024U * 1024U * 256U);
|
||||
}
|
||||
Matrix<T> m = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle,
|
||||
hlsf);
|
||||
MatrixCompute.Fill(m, 1.0f);
|
||||
Matrix<T> n = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle,
|
||||
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 k = 0; k < 10; k++) {
|
||||
Console.Write($"{m[j, k]:0.0E+00}\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/**/
|
||||
Console.WriteLine("===================================================");
|
||||
MatrixCompute.Mul(n, m, p);
|
||||
/**/
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
if (i % 4 == 0) {
|
||||
Console.WriteLine();
|
||||
}
|
||||
for (int j = 0; j < 20; j++)
|
||||
{
|
||||
string extra = j % 4 == 3 ? " " : ",";
|
||||
T value = p[j, i];
|
||||
|
||||
// value = T.Abs(value) < 1e-6 ? 0 : value;
|
||||
|
||||
Console.Write($"{p.GetElementOffset(j,i)}{extra}");
|
||||
|
||||
// Console.Write($"{value:000}{extra}");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine("===================================================");
|
||||
|
||||
/**/
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="MatrixTest"
|
||||
// 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 Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using T = float;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
private const long size = 1024L * 1024L * 1024L * 4L;
|
||||
|
||||
private static int sideLength = 1000;
|
||||
|
||||
internal static unsafe void TestMatrix(
|
||||
)
|
||||
{
|
||||
// TestRender();
|
||||
/**/
|
||||
HybridLayerSegregatedFitAllocator hlsf;
|
||||
unchecked {
|
||||
hlsf = new((nuint)size, 32, size);
|
||||
}
|
||||
Matrix<T> m = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle, hlsf);
|
||||
MatrixCompute.Fill(m, 1.0f);
|
||||
Matrix<T> n = Matrix<T>.Create(sideLength, sideLength, MatrixLayout.DenseRectangle, 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 k = 0; k < 10; k++) {
|
||||
Console.Write($"{m[j, k]:0.0E+00}\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
/**/
|
||||
Console.WriteLine("===================================================");
|
||||
MatrixCompute.Mul(n, m, p);
|
||||
/**/
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
if (i % 4 == 0) {
|
||||
Console.WriteLine();
|
||||
}
|
||||
for (int j = 0; j < 20; j++)
|
||||
{
|
||||
string extra = j % 4 == 3 ? " " : ",";
|
||||
T value = p[j, i];
|
||||
|
||||
// value = T.Abs(value) < 1e-6 ? 0 : value;
|
||||
|
||||
// Console.Write($"{p.GetElementOffset(j,i)}{extra}");
|
||||
|
||||
Console.Write($"{value:000}{extra}");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine("===================================================");
|
||||
|
||||
/**/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+77
-81
@@ -1,81 +1,77 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Program"
|
||||
// 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.Common.Timing;
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using StgSharp.Internal;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
using StgSharp.Timing;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
private static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
|
||||
|
||||
internal static unsafe void Main(
|
||||
string[] args
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
World.Initialize()
|
||||
.UseModule<NumericalModule>()
|
||||
.UseModule<GraphicModule>()
|
||||
.InitializeModule();
|
||||
|
||||
TestRegexAnalyse.Run();
|
||||
|
||||
// HlsfStressTest.Run();
|
||||
|
||||
// TestMatrix();
|
||||
|
||||
|
||||
// --- Logarithmic time sequence test: print seconds at each emitted span ---
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
Console.ReadLine();
|
||||
/*
|
||||
World.WriteLog($"{ex}", LogType.Error);
|
||||
Dialogue.PostError(ex);
|
||||
/**/
|
||||
World.Terminate(-1);
|
||||
/**/
|
||||
}
|
||||
finally
|
||||
{
|
||||
World.Terminate(0);
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Program"
|
||||
// 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.Common.Timing;
|
||||
using StgSharp.HighPerformance;
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using StgSharp.Internal;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
using StgSharp.Timing;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
private static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
|
||||
|
||||
internal static unsafe void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
World.Initialize().UseModule<NumericalModule>().UseModule<GraphicModule>().InitializeModule();
|
||||
|
||||
// TestRegexAnalyse.Run();
|
||||
|
||||
// HlsfStressTest.Run();
|
||||
|
||||
TestMatrix();
|
||||
|
||||
|
||||
/*
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
Console.ReadLine();
|
||||
/*
|
||||
World.WriteLog($"{ex}", LogType.Error);
|
||||
Dialogue.PostError(ex);
|
||||
/**/
|
||||
|
||||
// World.Terminate(-1);
|
||||
/**/
|
||||
}
|
||||
finally
|
||||
{
|
||||
World.Terminate(0);
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"profiles": {
|
||||
"StgSharpDebug": {
|
||||
"commandName": "Project",
|
||||
"nativeDebugging": true,
|
||||
"hotReloadEnabled": false
|
||||
}
|
||||
}
|
||||
{
|
||||
"profiles": {
|
||||
"StgSharpDebug": {
|
||||
"commandName": "Project",
|
||||
"nativeDebugging": true,
|
||||
"hotReloadEnabled": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,411 +1,411 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Partical"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class ParticleRenderStream : glRender
|
||||
{
|
||||
|
||||
private AutoTextureGL autoT;
|
||||
|
||||
private ElementBuffer ebo;
|
||||
private ElementBuffer f_ebo;
|
||||
private FrameBuffer fbo;
|
||||
private Image i;
|
||||
|
||||
private int temp = 0;
|
||||
private PlainInstancingBuffer<ParticleOnPlain> buffer;
|
||||
private RenderBuffer rbo;
|
||||
private ShaderProgram frameMainShader;
|
||||
private ShaderProgram s;
|
||||
private TextureGL f_t;
|
||||
private TextureGL t;
|
||||
private Uniform<int> texUniform;
|
||||
private Uniform<float> time;
|
||||
private VertexArray f_vao;
|
||||
private VertexArray vao;
|
||||
|
||||
private VertexBuffer f_vbo;
|
||||
private VertexBuffer vbo;
|
||||
|
||||
public ParticleRenderStream() { }
|
||||
|
||||
public override bool IsContextSharable => true;
|
||||
|
||||
public Rectangle ButtonBounding { get; private set; }
|
||||
|
||||
public TextureProvider ButtonTextureProvider { get; private set; }
|
||||
|
||||
// render a controlling item
|
||||
public void ButtonMain(
|
||||
IEnumerable<PlainGeometryMesh> items
|
||||
)
|
||||
{
|
||||
// Console.WriteLine("Render Button Itself");
|
||||
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero); /*GL.Assert(true);/**/
|
||||
GL.ClearColor(0.4f, TimePassed % 1.0f, 0f, 1.0f); /*GL.Assert(true);/**/
|
||||
GL.Clear(MaskBufferBit.COLOR /**/ | MaskBufferBit.DEPTH/**/); /*GL.Assert(true);/**/
|
||||
|
||||
f_vao.Bind(0); //GL.Assert(true);
|
||||
|
||||
foreach (PlainGeometryMesh mesh in items)
|
||||
{
|
||||
// autoT.SelectTextureAndBind(mesh.TextureImage);
|
||||
f_t.LoadTexture(0, mesh.TextureImage);
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
frameMainShader.Use(); //GL.Assert(true);
|
||||
|
||||
GL.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
}
|
||||
|
||||
// GL.ClearError();
|
||||
// GL.Assert(true);
|
||||
}
|
||||
|
||||
public void Main()
|
||||
{
|
||||
temp++;
|
||||
|
||||
// GL.ClearError();
|
||||
GL.Viewport(0, 0, Width, Height);
|
||||
|
||||
// Console.Clear();
|
||||
buffer.UpdateAllParticles();
|
||||
|
||||
// Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
|
||||
fbo.Bind(0); //GL.Assert(true);
|
||||
vao.Bind(0); //GL.Assert(true);
|
||||
t.Bind2D(0); //GL.Assert(false);
|
||||
|
||||
GL.Viewport(0, 0, Width, Height);
|
||||
|
||||
/**/
|
||||
|
||||
GL.TextureImage2d<byte>(Texture2DTarget.Texture2D, 0, ImageChannel.WithAlphaChannel,
|
||||
Width, Height, ImageChannel.WithAlphaChannel,
|
||||
PixelChannelLayout.Byte, null);
|
||||
/**/
|
||||
|
||||
// GL.Assert(false);
|
||||
// Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
|
||||
GL.ClearColor((0.6f + TimePassed) % 1.0f, 0.1f, 0.3f, 1);
|
||||
|
||||
// GL.Assert( false );
|
||||
|
||||
// Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
GL.Clear(MaskBufferBit.COLOR /**/ | MaskBufferBit.DEPTH/**/);
|
||||
|
||||
|
||||
// GL.Assert(false);
|
||||
|
||||
vbo.Bind(1);
|
||||
vbo.WriteVectorData<Vec4>(1, buffer.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
|
||||
|
||||
s.Use();
|
||||
NativeCamera.SetAllUniforms();
|
||||
GL.SetUniformValue(time, TimePassed);
|
||||
|
||||
GL.DrawElementsInstanced(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero, 100);
|
||||
|
||||
// Console.WriteLine(TimePassed);
|
||||
// GL.Assert(true);
|
||||
|
||||
GL.WaitAccomplishment();
|
||||
GL.BindVertexArray(GlHandle.Zero);
|
||||
/**/
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
ImageHelper.Resize(i, Width, Height, ImageMovement.Discard);
|
||||
|
||||
// GL.ClearError();
|
||||
// Console.Write($"Size set to {Height},{Width}");
|
||||
// Console.WriteLine($"Image resized to {i.Height} {i.Width}");
|
||||
GL.GetTextureImage(Texture2DTarget.Texture2D, 0, ImageChannel.WithAlphaChannel,
|
||||
PixelChannelLayout.Byte, i.PixelBuffer);
|
||||
/*
|
||||
for (int num = 0; num < i.PixelBuffer.Length; num+=10000)
|
||||
{
|
||||
Console.Write($"{i.PixelBuffer[num]}\t");
|
||||
}
|
||||
/**/
|
||||
|
||||
// GL.Assert(true);
|
||||
// Array.Fill<byte>(i.PixelBuffer, 24);
|
||||
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
|
||||
|
||||
// GL.Assert(true);
|
||||
/**/
|
||||
}
|
||||
|
||||
public void NothingMain()
|
||||
{
|
||||
GL.ClearError();
|
||||
|
||||
// GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
|
||||
GL.ClearColor(0.5f, 0.2f, 0.3f, 1.0f);
|
||||
GL.Assert(false);
|
||||
}
|
||||
|
||||
public void RenderButton(
|
||||
ButtonStatus status,
|
||||
float statusBegin,
|
||||
in TextureProvider provider
|
||||
)
|
||||
{
|
||||
provider.UpdateFromImage(i);
|
||||
}
|
||||
|
||||
internal static Vec3 DefaultRotation(
|
||||
TimeSpanProvider provider,
|
||||
out float rotation
|
||||
)
|
||||
{
|
||||
rotation = 1.0f / 60;
|
||||
float angle = (float)provider.CurrentSecond * 2;
|
||||
return (new Vec3(Scalar.Cos(angle), Scalar.Sin(angle),
|
||||
0)) * rotation;
|
||||
}
|
||||
|
||||
protected override void CustomizeDeinit() { }
|
||||
|
||||
protected override void CustomizeInit()
|
||||
{
|
||||
// GL.ClearError();
|
||||
// GL.Assert(true);
|
||||
|
||||
buffer = new PlainInstancingBuffer<ParticleOnPlain>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
float ai = Scalar.Abs(i - 5.0f);
|
||||
for (int t = 0; t < 10; t++)
|
||||
{
|
||||
float at = Scalar.Abs(t - 5.0f);
|
||||
|
||||
ParticleOnPlain p = new ParticleOnPlain(buffer);
|
||||
((IInstancing)p).Coord = new Vec3(
|
||||
(((-5) + i) * 0.2f) + 0.1f, (((-5) + t) * 0.2f) + 0.1f, 0);
|
||||
((IInstancing)p).Scale =
|
||||
Scalar.MinOf(i, t) * 0.15f;
|
||||
((IInstancing)p).Motion = new GeometryMotion(
|
||||
true, TimeProvider, DefaultRotation);
|
||||
}
|
||||
}
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
// SetSizeLimit(800, 800, 800, 800);
|
||||
|
||||
s = CreateShaderProgram();
|
||||
frameMainShader = CreateShaderProgram();
|
||||
Shader pvs = CreateShaderSegment(ShaderType.Vertex, 2);
|
||||
Shader pfs = CreateShaderSegment(ShaderType.Fragment, 2);
|
||||
|
||||
// GL.Assert(true);
|
||||
pvs.Compile(0, Shader.FromCodeFile("Shader\\particle.vert"));
|
||||
|
||||
// GL.Assert(true);
|
||||
pvs.AttachTo(0, s);
|
||||
|
||||
// GL.Assert(true);
|
||||
pfs.Compile(0, Shader.FromCodeFile("Shader\\particle.frag"));
|
||||
pfs.AttachTo(0, s);
|
||||
s.Link();
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
pvs.Compile(1, Shader.FromCodeFile("Shader\\fbo.vert"));
|
||||
pvs.AttachTo(1, frameMainShader);
|
||||
pfs.Compile(1, Shader.FromCodeFile("Shader\\fbo.frag"));
|
||||
pfs.AttachTo(1, frameMainShader);
|
||||
frameMainShader.Link();
|
||||
|
||||
// GL.Assert(true);
|
||||
vbo = CreateVertexBuffer(3);
|
||||
vao = CreateVertexArray(1);
|
||||
ebo = CreateElementBuffer(1);
|
||||
vbo.Bind(0);
|
||||
|
||||
Rectangle rec = new Rectangle(0.05f, 0.05f, 0.05f, -0.05f, -0.05f, -0.05f, -0.05f,
|
||||
0.05f);
|
||||
|
||||
// GL.Assert(true);
|
||||
vao.Bind(0);
|
||||
vbo.WriteVectorData(0, rec.VertexStream, BufferUsage.StaticDraw);
|
||||
ebo.SetValue(0, rec.VertexIndices, BufferUsage.StaticDraw);
|
||||
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
vbo.WriteVectorData<Vec4>(1, buffer.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
vao.SetVertexAttribute(2, 1, TypeCode.Single, false, 4 * sizeof(float),
|
||||
3 * sizeof(float));
|
||||
|
||||
GL.VertexAttributeDivisor(1, 1);
|
||||
GL.VertexAttributeDivisor(2, 1);
|
||||
|
||||
vbo.WriteScalerData<float>(2, buffer.ScalingSpan, BufferUsage.StaticDraw);
|
||||
vao.SetVertexAttribute(3, 1, TypeCode.Single, false, sizeof(float), 0);
|
||||
|
||||
GL.VertexAttributeDivisor(3, 1);
|
||||
|
||||
vbo.Unbind();
|
||||
GL.BindVertexArray(GlHandle.Zero);
|
||||
|
||||
NativeCameraViewTarget([
|
||||
0f,
|
||||
0f,
|
||||
-100f
|
||||
], [
|
||||
0f,
|
||||
0f,
|
||||
0f
|
||||
], [
|
||||
0f,
|
||||
1f,
|
||||
0f
|
||||
]);
|
||||
NativeCameraViewRange(new Degree(1.5f), Vec2.Zero, (50, 50));
|
||||
NativeCameraUniform(s, "Camera");
|
||||
|
||||
s.Use();
|
||||
|
||||
fbo = CreateFrameBuffer(1);
|
||||
rbo = CreateRenderBuffer(1);
|
||||
fbo.Bind(0);
|
||||
rbo.Bind(0);
|
||||
|
||||
// GL.Assert(true);
|
||||
t = CreateTexture(1);
|
||||
t.Bind2D(0);
|
||||
GL.TextureImage2d<byte>(Texture2DTarget.Texture2D, 0, ImageChannel.WithAlphaChannel,
|
||||
Width, Height, ImageChannel.WithAlphaChannel,
|
||||
PixelChannelLayout.Byte, null!);
|
||||
t.Set2dWrapProperty(0, TextureWrap.Repeat, TextureWrap.Repeat);
|
||||
t.Set2dFilterProperty(0, TextureFilter.Linear, TextureFilter.Linear);
|
||||
|
||||
// GL.Assert(true);
|
||||
GL.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
|
||||
Texture2DTarget.Texture2D, t[0], 0);
|
||||
|
||||
GL.SetRenderBufferStorage(RenderBufferInternalFormat.Depth24_Stencil8, this.Size);
|
||||
GL.CombineFrameBufferRenderBuffer(FrameBufferAttachment.DepthAndStencil, rbo[0]);
|
||||
|
||||
Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
|
||||
FrameBuffer.BindNull();
|
||||
|
||||
// GL.Assert(true);
|
||||
int streamLength = this.Width * this.Height * 4;
|
||||
byte[] imageStream = new byte[streamLength];
|
||||
i = Image.FromMemory(this.Size, ImageChannel.WithAlphaChannel, imageStream);
|
||||
|
||||
|
||||
time = s.GetUniform<float>("time");
|
||||
|
||||
Vec2[] buttonTextureCoordArray = {
|
||||
(0f, 1f),
|
||||
(1f, 1f),
|
||||
(1f, 0f),
|
||||
(0f, 0f)
|
||||
};
|
||||
ButtonBounding = new Rectangle(-0.9f, 0.9f, 0.9f, 0.9f, 0.9f, -0.9f, -0.9f, -0.9f);
|
||||
|
||||
// GL.Assert(true);
|
||||
ButtonTextureProvider = new TextureProvider(i, buttonTextureCoordArray);
|
||||
|
||||
f_vao = CreateVertexArray(1);
|
||||
f_vbo = CreateVertexBuffer(2);
|
||||
f_ebo = CreateElementBuffer(1);
|
||||
|
||||
// GL.Assert(true);
|
||||
f_vao.Bind(0);
|
||||
|
||||
f_ebo.Bind(0);
|
||||
f_ebo.SetValue(0, ButtonBounding.VertexIndices, BufferUsage.StaticDraw);
|
||||
|
||||
// GL.Assert(true);
|
||||
f_vbo.Bind(0);
|
||||
f_vbo.WriteVectorData(0, ButtonBounding.VertexStream, BufferUsage.StaticDraw);
|
||||
f_vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
// GL.Assert(true);
|
||||
f_vbo.Bind(1);
|
||||
f_vbo.WriteVectorData(1, buttonTextureCoordArray, BufferUsage.StaticDraw);
|
||||
f_vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
autoT = CreateAutoTexture(4);
|
||||
autoT.DefaultTextureProperty = new TextureProperty(TextureFilter.Nearest,
|
||||
TextureFilter.Nearest,
|
||||
TextureWrap.Repeat,
|
||||
TextureWrap.Repeat);
|
||||
|
||||
f_t = CreateTexture(1);
|
||||
f_t.Bind2D(0);
|
||||
f_t.Set2dWrapProperty(0, TextureWrap.Repeat, TextureWrap.Repeat);
|
||||
f_t.Set2dFilterProperty(0, TextureFilter.Nearest, TextureFilter.Nearest);
|
||||
|
||||
// GL.Assert(true);
|
||||
f_t.ActivateAs(TextureUnit.Unit1);
|
||||
|
||||
// GL.Assert(true);
|
||||
frameMainShader.Use();
|
||||
texUniform = frameMainShader.GetUniform<int>("tex");
|
||||
|
||||
// GL.Assert(true);
|
||||
GL.SetUniformValue(texUniform, 1);
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
GL.ClearError();
|
||||
GL.Assert(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Partical"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public class ParticleRenderStream : glRender
|
||||
{
|
||||
|
||||
private AutoTextureGL autoT;
|
||||
|
||||
private ElementBuffer ebo;
|
||||
private ElementBuffer f_ebo;
|
||||
private FrameBuffer fbo;
|
||||
private Image i;
|
||||
|
||||
private int temp = 0;
|
||||
private PlainInstancingBuffer<ParticleOnPlain> buffer;
|
||||
private RenderBuffer rbo;
|
||||
private ShaderProgram frameMainShader;
|
||||
private ShaderProgram s;
|
||||
private TextureGL f_t;
|
||||
private TextureGL t;
|
||||
private Uniform<int> texUniform;
|
||||
private Uniform<float> time;
|
||||
private VertexArray f_vao;
|
||||
private VertexArray vao;
|
||||
|
||||
private VertexBuffer f_vbo;
|
||||
private VertexBuffer vbo;
|
||||
|
||||
public ParticleRenderStream() { }
|
||||
|
||||
public override bool IsContextSharable => true;
|
||||
|
||||
public Rectangle ButtonBounding { get; private set; }
|
||||
|
||||
public TextureProvider ButtonTextureProvider { get; private set; }
|
||||
|
||||
// render a controlling item
|
||||
public void ButtonMain(
|
||||
IEnumerable<PlainGeometryMesh> items
|
||||
)
|
||||
{
|
||||
// Console.WriteLine("Render Button Itself");
|
||||
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero); /*GL.Assert(true);/**/
|
||||
GL.ClearColor(0.4f, TimePassed % 1.0f, 0f, 1.0f); /*GL.Assert(true);/**/
|
||||
GL.Clear(MaskBufferBit.COLOR /**/ | MaskBufferBit.DEPTH/**/); /*GL.Assert(true);/**/
|
||||
|
||||
f_vao.Bind(0); //GL.Assert(true);
|
||||
|
||||
foreach (PlainGeometryMesh mesh in items)
|
||||
{
|
||||
// autoT.SelectTextureAndBind(mesh.TextureImage);
|
||||
f_t.LoadTexture(0, mesh.TextureImage);
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
frameMainShader.Use(); //GL.Assert(true);
|
||||
|
||||
GL.DrawElements(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero);
|
||||
}
|
||||
|
||||
// GL.ClearError();
|
||||
// GL.Assert(true);
|
||||
}
|
||||
|
||||
public void Main()
|
||||
{
|
||||
temp++;
|
||||
|
||||
// GL.ClearError();
|
||||
GL.Viewport(0, 0, Width, Height);
|
||||
|
||||
// Console.Clear();
|
||||
buffer.UpdateAllParticles();
|
||||
|
||||
// Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
|
||||
fbo.Bind(0); //GL.Assert(true);
|
||||
vao.Bind(0); //GL.Assert(true);
|
||||
t.Bind2D(0); //GL.Assert(false);
|
||||
|
||||
GL.Viewport(0, 0, Width, Height);
|
||||
|
||||
/**/
|
||||
|
||||
GL.TextureImage2d<byte>(Texture2DTarget.Texture2D, 0, ImageChannel.WithAlphaChannel,
|
||||
Width, Height, ImageChannel.WithAlphaChannel,
|
||||
PixelChannelLayout.Byte, null);
|
||||
/**/
|
||||
|
||||
// GL.Assert(false);
|
||||
// Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
|
||||
GL.ClearColor((0.6f + TimePassed) % 1.0f, 0.1f, 0.3f, 1);
|
||||
|
||||
// GL.Assert( false );
|
||||
|
||||
// Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
GL.Clear(MaskBufferBit.COLOR /**/ | MaskBufferBit.DEPTH/**/);
|
||||
|
||||
|
||||
// GL.Assert(false);
|
||||
|
||||
vbo.Bind(1);
|
||||
vbo.WriteVectorData<Vec4>(1, buffer.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
|
||||
|
||||
s.Use();
|
||||
NativeCamera.SetAllUniforms();
|
||||
GL.SetUniformValue(time, TimePassed);
|
||||
|
||||
GL.DrawElementsInstanced(GeometryType.TRIANGLES, 6, TypeCode.UInt32, IntPtr.Zero, 100);
|
||||
|
||||
// Console.WriteLine(TimePassed);
|
||||
// GL.Assert(true);
|
||||
|
||||
GL.WaitAccomplishment();
|
||||
GL.BindVertexArray(GlHandle.Zero);
|
||||
/**/
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
ImageHelper.Resize(i, Width, Height, ImageMovement.Discard);
|
||||
|
||||
// GL.ClearError();
|
||||
// Console.Write($"Size set to {Height},{Width}");
|
||||
// Console.WriteLine($"Image resized to {i.Height} {i.Width}");
|
||||
GL.GetTextureImage(Texture2DTarget.Texture2D, 0, ImageChannel.WithAlphaChannel,
|
||||
PixelChannelLayout.Byte, i.PixelBuffer);
|
||||
/*
|
||||
for (int num = 0; num < i.PixelBuffer.Length; num+=10000)
|
||||
{
|
||||
Console.Write($"{i.PixelBuffer[num]}\t");
|
||||
}
|
||||
/**/
|
||||
|
||||
// GL.Assert(true);
|
||||
// Array.Fill<byte>(i.PixelBuffer, 24);
|
||||
|
||||
GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
|
||||
|
||||
// GL.Assert(true);
|
||||
/**/
|
||||
}
|
||||
|
||||
public void NothingMain()
|
||||
{
|
||||
GL.ClearError();
|
||||
|
||||
// GL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
|
||||
GL.ClearColor(0.5f, 0.2f, 0.3f, 1.0f);
|
||||
GL.Assert(false);
|
||||
}
|
||||
|
||||
public void RenderButton(
|
||||
ButtonStatus status,
|
||||
float statusBegin,
|
||||
in TextureProvider provider
|
||||
)
|
||||
{
|
||||
provider.UpdateFromImage(i);
|
||||
}
|
||||
|
||||
internal static Vec3 DefaultRotation(
|
||||
TimeSpanProvider provider,
|
||||
out float rotation
|
||||
)
|
||||
{
|
||||
rotation = 1.0f / 60;
|
||||
float angle = (float)provider.CurrentSecond * 2;
|
||||
return (new Vec3(Scalar.Cos(angle), Scalar.Sin(angle),
|
||||
0)) * rotation;
|
||||
}
|
||||
|
||||
protected override void CustomizeDeinit() { }
|
||||
|
||||
protected override void CustomizeInit()
|
||||
{
|
||||
// GL.ClearError();
|
||||
// GL.Assert(true);
|
||||
|
||||
buffer = new PlainInstancingBuffer<ParticleOnPlain>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
float ai = Scalar.Abs(i - 5.0f);
|
||||
for (int t = 0; t < 10; t++)
|
||||
{
|
||||
float at = Scalar.Abs(t - 5.0f);
|
||||
|
||||
ParticleOnPlain p = new ParticleOnPlain(buffer);
|
||||
((IInstancing)p).Coord = new Vec3(
|
||||
(((-5) + i) * 0.2f) + 0.1f, (((-5) + t) * 0.2f) + 0.1f, 0);
|
||||
((IInstancing)p).Scale =
|
||||
Scalar.MinOf(i, t) * 0.15f;
|
||||
((IInstancing)p).Motion = new GeometryMotion(
|
||||
true, TimeProvider, DefaultRotation);
|
||||
}
|
||||
}
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
// SetSizeLimit(800, 800, 800, 800);
|
||||
|
||||
s = CreateShaderProgram();
|
||||
frameMainShader = CreateShaderProgram();
|
||||
Shader pvs = CreateShaderSegment(ShaderType.Vertex, 2);
|
||||
Shader pfs = CreateShaderSegment(ShaderType.Fragment, 2);
|
||||
|
||||
// GL.Assert(true);
|
||||
pvs.Compile(0, Shader.FromCodeFile("Shader\\particle.vert"));
|
||||
|
||||
// GL.Assert(true);
|
||||
pvs.AttachTo(0, s);
|
||||
|
||||
// GL.Assert(true);
|
||||
pfs.Compile(0, Shader.FromCodeFile("Shader\\particle.frag"));
|
||||
pfs.AttachTo(0, s);
|
||||
s.Link();
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
pvs.Compile(1, Shader.FromCodeFile("Shader\\fbo.vert"));
|
||||
pvs.AttachTo(1, frameMainShader);
|
||||
pfs.Compile(1, Shader.FromCodeFile("Shader\\fbo.frag"));
|
||||
pfs.AttachTo(1, frameMainShader);
|
||||
frameMainShader.Link();
|
||||
|
||||
// GL.Assert(true);
|
||||
vbo = CreateVertexBuffer(3);
|
||||
vao = CreateVertexArray(1);
|
||||
ebo = CreateElementBuffer(1);
|
||||
vbo.Bind(0);
|
||||
|
||||
Rectangle rec = new Rectangle(0.05f, 0.05f, 0.05f, -0.05f, -0.05f, -0.05f, -0.05f,
|
||||
0.05f);
|
||||
|
||||
// GL.Assert(true);
|
||||
vao.Bind(0);
|
||||
vbo.WriteVectorData(0, rec.VertexStream, BufferUsage.StaticDraw);
|
||||
ebo.SetValue(0, rec.VertexIndices, BufferUsage.StaticDraw);
|
||||
vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
vbo.WriteVectorData<Vec4>(1, buffer.CoordAndRotationSpan, BufferUsage.StreamDraw);
|
||||
vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
vao.SetVertexAttribute(2, 1, TypeCode.Single, false, 4 * sizeof(float),
|
||||
3 * sizeof(float));
|
||||
|
||||
GL.VertexAttributeDivisor(1, 1);
|
||||
GL.VertexAttributeDivisor(2, 1);
|
||||
|
||||
vbo.WriteScalerData<float>(2, buffer.ScalingSpan, BufferUsage.StaticDraw);
|
||||
vao.SetVertexAttribute(3, 1, TypeCode.Single, false, sizeof(float), 0);
|
||||
|
||||
GL.VertexAttributeDivisor(3, 1);
|
||||
|
||||
vbo.Unbind();
|
||||
GL.BindVertexArray(GlHandle.Zero);
|
||||
|
||||
NativeCameraViewTarget([
|
||||
0f,
|
||||
0f,
|
||||
-100f
|
||||
], [
|
||||
0f,
|
||||
0f,
|
||||
0f
|
||||
], [
|
||||
0f,
|
||||
1f,
|
||||
0f
|
||||
]);
|
||||
NativeCameraViewRange(new Degree(1.5f), Vec2.Zero, (50, 50));
|
||||
NativeCameraUniform(s, "Camera");
|
||||
|
||||
s.Use();
|
||||
|
||||
fbo = CreateFrameBuffer(1);
|
||||
rbo = CreateRenderBuffer(1);
|
||||
fbo.Bind(0);
|
||||
rbo.Bind(0);
|
||||
|
||||
// GL.Assert(true);
|
||||
t = CreateTexture(1);
|
||||
t.Bind2D(0);
|
||||
GL.TextureImage2d<byte>(Texture2DTarget.Texture2D, 0, ImageChannel.WithAlphaChannel,
|
||||
Width, Height, ImageChannel.WithAlphaChannel,
|
||||
PixelChannelLayout.Byte, null!);
|
||||
t.Set2dWrapProperty(0, TextureWrap.Repeat, TextureWrap.Repeat);
|
||||
t.Set2dFilterProperty(0, TextureFilter.Linear, TextureFilter.Linear);
|
||||
|
||||
// GL.Assert(true);
|
||||
GL.FrameBufferTexture2d(FrameBufferTarget.All, glAttachment.Color(0),
|
||||
Texture2DTarget.Texture2D, t[0], 0);
|
||||
|
||||
GL.SetRenderBufferStorage(RenderBufferInternalFormat.Depth24_Stencil8, this.Size);
|
||||
GL.CombineFrameBufferRenderBuffer(FrameBufferAttachment.DepthAndStencil, rbo[0]);
|
||||
|
||||
Console.WriteLine(GL.CheckFrameBufferStatus(FrameBufferTarget.All));
|
||||
|
||||
FrameBuffer.BindNull();
|
||||
|
||||
// GL.Assert(true);
|
||||
int streamLength = this.Width * this.Height * 4;
|
||||
byte[] imageStream = new byte[streamLength];
|
||||
i = Image.FromMemory(this.Size, ImageChannel.WithAlphaChannel, imageStream);
|
||||
|
||||
|
||||
time = s.GetUniform<float>("time");
|
||||
|
||||
Vec2[] buttonTextureCoordArray = {
|
||||
(0f, 1f),
|
||||
(1f, 1f),
|
||||
(1f, 0f),
|
||||
(0f, 0f)
|
||||
};
|
||||
ButtonBounding = new Rectangle(-0.9f, 0.9f, 0.9f, 0.9f, 0.9f, -0.9f, -0.9f, -0.9f);
|
||||
|
||||
// GL.Assert(true);
|
||||
ButtonTextureProvider = new TextureProvider(i, buttonTextureCoordArray);
|
||||
|
||||
f_vao = CreateVertexArray(1);
|
||||
f_vbo = CreateVertexBuffer(2);
|
||||
f_ebo = CreateElementBuffer(1);
|
||||
|
||||
// GL.Assert(true);
|
||||
f_vao.Bind(0);
|
||||
|
||||
f_ebo.Bind(0);
|
||||
f_ebo.SetValue(0, ButtonBounding.VertexIndices, BufferUsage.StaticDraw);
|
||||
|
||||
// GL.Assert(true);
|
||||
f_vbo.Bind(0);
|
||||
f_vbo.WriteVectorData(0, ButtonBounding.VertexStream, BufferUsage.StaticDraw);
|
||||
f_vao.SetVertexAttribute(0, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
// GL.Assert(true);
|
||||
f_vbo.Bind(1);
|
||||
f_vbo.WriteVectorData(1, buttonTextureCoordArray, BufferUsage.StaticDraw);
|
||||
f_vao.SetVertexAttribute(1, 3, TypeCode.Single, false, 4 * sizeof(float), 0);
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
autoT = CreateAutoTexture(4);
|
||||
autoT.DefaultTextureProperty = new TextureProperty(TextureFilter.Nearest,
|
||||
TextureFilter.Nearest,
|
||||
TextureWrap.Repeat,
|
||||
TextureWrap.Repeat);
|
||||
|
||||
f_t = CreateTexture(1);
|
||||
f_t.Bind2D(0);
|
||||
f_t.Set2dWrapProperty(0, TextureWrap.Repeat, TextureWrap.Repeat);
|
||||
f_t.Set2dFilterProperty(0, TextureFilter.Nearest, TextureFilter.Nearest);
|
||||
|
||||
// GL.Assert(true);
|
||||
f_t.ActivateAs(TextureUnit.Unit1);
|
||||
|
||||
// GL.Assert(true);
|
||||
frameMainShader.Use();
|
||||
texUniform = frameMainShader.GetUniform<int>("tex");
|
||||
|
||||
// GL.Assert(true);
|
||||
GL.SetUniformValue(texUniform, 1);
|
||||
|
||||
// GL.Assert(true);
|
||||
|
||||
GL.ClearError();
|
||||
GL.Assert(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#version 430 core
|
||||
|
||||
in vec3 texCoord;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = texture(tex, texCoord.xy);
|
||||
#version 430 core
|
||||
|
||||
in vec3 texCoord;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = texture(tex, texCoord.xy);
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
#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;
|
||||
#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;
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
#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);
|
||||
#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 +1,13 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
#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 +1,17 @@
|
||||
#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) /**/;
|
||||
}
|
||||
|
||||
#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 +1,22 @@
|
||||
#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
|
||||
|
||||
|
||||
|
||||
#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 +1,12 @@
|
||||
#version 460 core
|
||||
|
||||
uniform float time;
|
||||
|
||||
out vec3 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
fragColor = vec3( 0.5f,0.336f,mod( (0.9961f + time),1.0f) );
|
||||
|
||||
#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 +1,36 @@
|
||||
#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));
|
||||
|
||||
}
|
||||
#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));
|
||||
|
||||
}
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SlabStressTest"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static class SlabStressTest
|
||||
{
|
||||
|
||||
// Exercise the Nonconcurrent Chunked SLAB used by HLSF (allocation/free only)
|
||||
public static unsafe void Run()
|
||||
{
|
||||
Console.WriteLine("=== SLAB Allocator (Chunked) Single-Thread Stress Test ===");
|
||||
|
||||
// Use SLAB with element size of pointer (nuint) to simulate Entry handles
|
||||
SlabAllocator<BunchOfBytes> slab = SlabAllocator<BunchOfBytes>.Create(64, SlabBufferLayout.Chunked, false);
|
||||
|
||||
int cycles = 10;
|
||||
int allocsPerCycle = 200_000; // large enough to force internal growth
|
||||
|
||||
Stopwatch sw = new Stopwatch();
|
||||
|
||||
for (int c = 0; c < cycles; c++)
|
||||
{
|
||||
Console.WriteLine($"--- Cycle {c+1} ---");
|
||||
nuint[] ptrs = new nuint[allocsPerCycle];
|
||||
|
||||
sw.Restart();
|
||||
for (int i = 0; i < allocsPerCycle; i++) {
|
||||
ptrs[i] = slab.Allocate();
|
||||
}
|
||||
sw.Stop();
|
||||
Console.WriteLine($"Allocate: {allocsPerCycle} in {sw.Elapsed.TotalSeconds:0.00}s");
|
||||
|
||||
sw.Restart();
|
||||
for (int i = 0; i < allocsPerCycle; i++) {
|
||||
slab.Free(ptrs[i]);
|
||||
}
|
||||
sw.Stop();
|
||||
Console.WriteLine($"Free: {allocsPerCycle} in {sw.Elapsed.TotalSeconds:0.00}s");
|
||||
}
|
||||
|
||||
slab.Dispose();
|
||||
Console.WriteLine("=== SLAB Stress Complete ===");
|
||||
}
|
||||
|
||||
internal unsafe struct BunchOfBytes
|
||||
{
|
||||
|
||||
public fixed byte Data[128];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="SlabStressTest"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static class SlabStressTest
|
||||
{
|
||||
|
||||
// Exercise the Nonconcurrent Chunked SLAB used by HLSF (allocation/free only)
|
||||
public static unsafe void Run()
|
||||
{
|
||||
Console.WriteLine("=== SLAB Allocator (Chunked) Single-Thread Stress Test ===");
|
||||
|
||||
// Use SLAB with element size of pointer (nuint) to simulate Entry handles
|
||||
SlabAllocator<BunchOfBytes> slab = SlabAllocator<BunchOfBytes>.Create(64, SlabBufferLayout.Chunked, false);
|
||||
|
||||
int cycles = 10;
|
||||
int allocsPerCycle = 200_000; // large enough to force internal growth
|
||||
|
||||
Stopwatch sw = new Stopwatch();
|
||||
|
||||
for (int c = 0; c < cycles; c++)
|
||||
{
|
||||
Console.WriteLine($"--- Cycle {c+1} ---");
|
||||
nuint[] ptrs = new nuint[allocsPerCycle];
|
||||
|
||||
sw.Restart();
|
||||
for (int i = 0; i < allocsPerCycle; i++) {
|
||||
ptrs[i] = slab.Allocate();
|
||||
}
|
||||
sw.Stop();
|
||||
Console.WriteLine($"Allocate: {allocsPerCycle} in {sw.Elapsed.TotalSeconds:0.00}s");
|
||||
|
||||
sw.Restart();
|
||||
for (int i = 0; i < allocsPerCycle; i++) {
|
||||
slab.Free(ptrs[i]);
|
||||
}
|
||||
sw.Stop();
|
||||
Console.WriteLine($"Free: {allocsPerCycle} in {sw.Elapsed.TotalSeconds:0.00}s");
|
||||
}
|
||||
|
||||
slab.Dispose();
|
||||
Console.WriteLine("=== SLAB Stress Complete ===");
|
||||
}
|
||||
|
||||
internal unsafe struct BunchOfBytes
|
||||
{
|
||||
|
||||
public fixed byte Data[128];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+116
-116
@@ -1,116 +1,116 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>Preview</LangVersion>
|
||||
<Nullable>warnings</Nullable>
|
||||
<StartupObject>StgSharp.Program</StartupObject>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<ErrorReport>none</ErrorReport>
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||
<PackageLicenseExpression> MIT</PackageLicenseExpression>
|
||||
<IncludeSymbols>False</IncludeSymbols>
|
||||
<Platforms>x64;ARM64</Platforms>
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
<Configurations>Debug;Release;PerformanceDebug</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='PerformanceDebug|x64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='PerformanceDebug|ARM64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
|
||||
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
|
||||
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
|
||||
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(IsWindows)'=='true'">
|
||||
<DefineConstants>Windows</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsOSX)'=='true'">
|
||||
<DefineConstants>OSX</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsLinux)'=='true'">
|
||||
<DefineConstants>Linux</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="SSG_errorlog.log" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\StgSharp.Common\StgSharp.Common.csproj" />
|
||||
<ProjectReference Include="..\StgSharp.Mathematics\StgSharp.Mathematics.csproj" />
|
||||
<ProjectReference Include="..\StgSharp.Model\StgSharp.Model.csproj" />
|
||||
<ProjectReference Include="..\StgSharp.RegularAnalysis\StgSharp.RegularAnalysis.csproj" />
|
||||
<ProjectReference Include="..\StgSharp.Script\StgSharp.Script.csproj" />
|
||||
</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>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="xcopy /E /I /Y $(SolutionDir)build $(OutDir)" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>Preview</LangVersion>
|
||||
<Nullable>warnings</Nullable>
|
||||
<StartupObject>StgSharp.Program</StartupObject>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<ErrorReport>none</ErrorReport>
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||
<PackageLicenseExpression> MIT</PackageLicenseExpression>
|
||||
<IncludeSymbols>False</IncludeSymbols>
|
||||
<Platforms>x64;ARM64</Platforms>
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
<Configurations>Debug;Release;PerformanceDebug</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='PerformanceDebug|x64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='PerformanceDebug|ARM64'">
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
|
||||
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
|
||||
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
|
||||
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(IsWindows)'=='true'">
|
||||
<DefineConstants>Windows</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsOSX)'=='true'">
|
||||
<DefineConstants>OSX</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsLinux)'=='true'">
|
||||
<DefineConstants>Linux</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="SSG_errorlog.log" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\StgSharp.Common\StgSharp.Common.csproj" />
|
||||
<ProjectReference Include="..\StgSharp.Mathematics\StgSharp.Mathematics.csproj" />
|
||||
<ProjectReference Include="..\StgSharp.Model\StgSharp.Model.csproj" />
|
||||
<ProjectReference Include="..\StgSharp.RegularAnalysis\StgSharp.RegularAnalysis.csproj" />
|
||||
<ProjectReference Include="..\StgSharp.Script\StgSharp.Script.csproj" />
|
||||
</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>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="xcopy /E /I /Y $(SolutionDir)build $(OutDir)" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TestRegexAnalyse"
|
||||
// Project: StgSharp
|
||||
|
||||
+64
-64
@@ -1,64 +1,64 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="TestRender.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.Collections;
|
||||
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
|
||||
{
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
public static void TestRender()
|
||||
{
|
||||
World.InitGL( 4, 6 );
|
||||
World.GlobalSetting.VSyncActivated = false;
|
||||
|
||||
ViewPort vp = new ViewPort( 800, 600, "Hello StgSharp!", IntPtr.Zero );
|
||||
|
||||
//throw new NotImplementedException();
|
||||
|
||||
ViewModelBase mainModel = new ViewModelMain( vp );
|
||||
mainModel.CreateAndBindView<ViewMain>( "MainView", (1, 1, 1) );
|
||||
|
||||
mainModel.UseViewModel( "MainView" );
|
||||
|
||||
World.Terminate( 0 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="TestRender.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.Collections;
|
||||
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
|
||||
{
|
||||
internal static partial class Program
|
||||
{
|
||||
|
||||
public static void TestRender()
|
||||
{
|
||||
World.InitGL( 4, 6 );
|
||||
World.GlobalSetting.VSyncActivated = false;
|
||||
|
||||
ViewPort vp = new ViewPort( 800, 600, "Hello StgSharp!", IntPtr.Zero );
|
||||
|
||||
//throw new NotImplementedException();
|
||||
|
||||
ViewModelBase mainModel = new ViewModelMain( vp );
|
||||
mainModel.CreateAndBindView<ViewMain>( "MainView", (1, 1, 1) );
|
||||
|
||||
mainModel.UseViewModel( "MainView" );
|
||||
|
||||
World.Terminate( 0 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 +1,91 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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,68 +1,68 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="NewRender.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.HighPerformance;
|
||||
|
||||
using StgSharp.Internal;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public partial class ViewMain
|
||||
{
|
||||
|
||||
public ParticleRenderStream Stream { get; set; }
|
||||
|
||||
private class NewRender : ViewRender<ViewMain>
|
||||
{
|
||||
|
||||
public NewRender( ViewMain view ) : base( view ) { }
|
||||
|
||||
public override void CustomizedInitialize()
|
||||
{
|
||||
Binding.Stream = CreateRenderStream<ParticleRenderStream>();
|
||||
Render[ "only".AsLabel() ] = Binding.Stream;
|
||||
}
|
||||
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
return Binding.Stream != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="NewRender.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.HighPerformance;
|
||||
|
||||
using StgSharp.Internal;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public partial class ViewMain
|
||||
{
|
||||
|
||||
public ParticleRenderStream Stream { get; set; }
|
||||
|
||||
private class NewRender : ViewRender<ViewMain>
|
||||
{
|
||||
|
||||
public NewRender( ViewMain view ) : base( view ) { }
|
||||
|
||||
public override void CustomizedInitialize()
|
||||
{
|
||||
Binding.Stream = CreateRenderStream<ParticleRenderStream>();
|
||||
Render[ "only".AsLabel() ] = Binding.Stream;
|
||||
}
|
||||
|
||||
public override bool ValidateInitializing()
|
||||
{
|
||||
return Binding.Stream != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,98 +1,98 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 +1,75 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 ------------------------------------------
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 ------------------------------------------
|
||||
}
|
||||
|
||||
+81
-81
@@ -1,81 +1,81 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="hlsf-test"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal partial class Program
|
||||
{
|
||||
|
||||
public static void TestHlsf()
|
||||
{
|
||||
// HLSF test arena
|
||||
Console.WriteLine(
|
||||
"=== HLSF (Hybrid Layer Segregated Fit Allocator) Single-threaded Stress Test ===\n");
|
||||
HybridLayerSegregatedFitAllocator hlsfAllocator = new HybridLayerSegregatedFitAllocator(1024 * 1024 * 1024);
|
||||
|
||||
// === 简洁交替测试:100次alloc与100次free交替进行,直到触发异常或达到最大循环 ===
|
||||
Console.WriteLine("\n=== 简洁交替测试:100次alloc + 100次free 交替 ===");
|
||||
|
||||
int maxRounds = 10000; // 可调整
|
||||
uint[] sizes = {
|
||||
64u, 128u, 256u, 512u, 1024u
|
||||
};
|
||||
Random rnd = new Random(42);
|
||||
for (int round = 1; round <= maxRounds; round++)
|
||||
{
|
||||
// 100 次分配
|
||||
List<HybridLayerSegregatedFitAllocationHandle> batch = new List<HybridLayerSegregatedFitAllocationHandle>(100);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
uint sz = sizes[rnd.Next(sizes.Length)];
|
||||
batch.Add(hlsfAllocator.Alloc(sz));
|
||||
Console.WriteLine($"alloced:{i}");
|
||||
}
|
||||
|
||||
// 100 次释放(逆序)
|
||||
for (int i = batch.Count - 1; i >= 0; i--)
|
||||
{
|
||||
hlsfAllocator.Free(batch[i]);
|
||||
Console.WriteLine($"freed:{i}");
|
||||
}
|
||||
if (round % 100 == 0) {
|
||||
Console.WriteLine($"[交替测试] 已完成 {round} 轮 100alloc+100free");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("[交替测试] 正常结束,无异常触发");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="hlsf-test"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance.Memory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal partial class Program
|
||||
{
|
||||
|
||||
public static void TestHlsf()
|
||||
{
|
||||
// HLSF test arena
|
||||
Console.WriteLine(
|
||||
"=== HLSF (Hybrid Layer Segregated Fit Allocator) Single-threaded Stress Test ===\n");
|
||||
HybridLayerSegregatedFitAllocator hlsfAllocator = new HybridLayerSegregatedFitAllocator(1024 * 1024 * 1024);
|
||||
|
||||
// === 简洁交替测试:100次alloc与100次free交替进行,直到触发异常或达到最大循环 ===
|
||||
Console.WriteLine("\n=== 简洁交替测试:100次alloc + 100次free 交替 ===");
|
||||
|
||||
int maxRounds = 10000; // 可调整
|
||||
uint[] sizes = {
|
||||
64u, 128u, 256u, 512u, 1024u
|
||||
};
|
||||
Random rnd = new Random(42);
|
||||
for (int round = 1; round <= maxRounds; round++)
|
||||
{
|
||||
// 100 次分配
|
||||
List<HybridLayerSegregatedFitAllocationHandle> batch = new List<HybridLayerSegregatedFitAllocationHandle>(100);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
uint sz = sizes[rnd.Next(sizes.Length)];
|
||||
batch.Add(hlsfAllocator.Alloc(sz));
|
||||
Console.WriteLine($"alloced:{i}");
|
||||
}
|
||||
|
||||
// 100 次释放(逆序)
|
||||
for (int i = batch.Count - 1; i >= 0; i--)
|
||||
{
|
||||
hlsfAllocator.Free(batch[i]);
|
||||
Console.WriteLine($"freed:{i}");
|
||||
}
|
||||
if (round % 100 == 0) {
|
||||
Console.WriteLine($"[交替测试] 已完成 {round} 轮 100alloc+100free");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("[交替测试] 正常结束,无异常触发");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user