MechWarrior99
MechWarrior99
CC#
Created by MechWarrior99 on 1/18/2025 in #help
Would a Declarative Reactive UI be too expensive?
Not 100% sure "reactive" is the right term. But frameworks like Flutter, where they rebuild sections of the UI with light weight objects when there is a state change. Would something like that work well in C#? Thinking of for like UI heavy games? It feels like it would generate a lot of garbage so not really make sense to do. But I also see there is like MAUI Reactor. Which seems to do it. But seems like it wouldn't scale well. And doesn't seem like they are doing any pooling or anything. It is one of those things that are a bit hard to setup a realistic MVP to profile myself.
39 replies
CC#
Created by MechWarrior99 on 1/5/2025 in #help
What's the right UI framework pattern?
I'm making a UI system (mostly for fun and to learn), and I'm trying to figure out the right pattern for it. I want to use it for games and editors. So I was thinking some type of immediate mode GUI since in game UIs, it doesn't make sense to have events when states change, and it is pretty high performance, especially when moving position of elements a lot. And simple. Immediate mode pattern has a few issues though, there isn't really a good way to have an editor for building the UI visually. And if there was some type of editor, doing bindings would require boxing for each value (at least I can't think of another way without boxing). It is difficult for extensions to modify the UI. For retained mode patterns, if you do something like MVVM it is heavily event driven, which isn't great for game UIs and has lots of boilerplate, also rather complex to make. But is quite easy to do a visual UI editor/builder for. Retained mode GUI also generally are less performant when moving elements and such. I looked at like a MVU pattern from Uno, but that seems to have a lot of the same issues as MVVM had, with performance and events. I feel like there are other patterns, one that would fit well with what I want. But I'm having trouble even finding different patterns to look in to. To summarize what I am looking for: - High performance updates. - Mostly not event driven. - Easily modifiable from third-party. - Buildable from an editor. Any suggestions?
59 replies
CC#
Created by MechWarrior99 on 12/26/2024 in #help
✅ How to make the compile treat a specific struct as a vector?
As I understand it, the compile has special handling for vector types, which allows them to have better performance than regular structs. Is there a way to get the compile to recognize a struct as a vector to get the same performance benefits? Or have I misunderstood what it is doing and it doesn't have special handling?
12 replies
CC#
Created by MechWarrior99 on 12/24/2024 in #help
High performances way to access members?
Hello, I'm developing a API for visiting members of a object and reading their values, for using in serialization, data validation, etc. I am trying to make it high performant (as reasonably possible), so I want to avoid boxing from reflection. So I've been using generics with MakeGenericMethod/Type with PropertyInfo and delegates to avoid it mostly. The issue is that it isn't well supported with Native AOT. So an alterative I thought of was to mark every class/record/struct with an attribute, and use source generation to make a 'handler' for it. But that feels like it would really bloat the class count along with compile times. Any recommendations, insights or alternatives?
14 replies
CC#
Created by MechWarrior99 on 8/14/2024 in #help
Arrange points in circle with a Sweep parameter
No description
8 replies
CC#
Created by MechWarrior99 on 7/23/2024 in #help
✅ Faster & thread safe random number generator?
Is there a good library for getting pseudo random numbers, faster than System.Random? I've done some looking but had a hard time coming up with much.
52 replies
CC#
Created by MechWarrior99 on 1/21/2024 in #help
How to safely access parameters from Task (Porting from Unity IJob)
I am making a program for generating a 3D mesh from parameters. The generation is done in some Tasks run with Task.Run. I'm struggling to grasp how to properly and safely access the parameters when generating. I am porting the system over from Unity's IJob system, which I think is sort of 'boxing' my thinking in making it hard to get my head around what I need to do. Do I make a class/struct that has all the parameters in it that I populate beforehand and use those values during generation? Sort of like Unity's Job system. Thanks 🙂
36 replies
CC#
Created by MechWarrior99 on 10/24/2023 in #help
❔ Cancel task on nested exception
I have a series of nested async methods, when a exception is thrown I want to cancel the task. The main issue is that I need to do a try cache in a for loop in a nested method, so that we can get more detailed telemetry about it. That means that the methods just keep going. I could pass the CTS to the tasks instead, or access it through other means, but that also feels a little messy. Hope this makes sense.
private CancellationTokenSource _tokenSource;
public async Task RunBigTask()
{
_tokenSource = new CancellationTokenSource();
// Some logic here...
await OtherClass.RunSmallerTasks(_tokenSource.Token);
// Some other logic here...
}

// In another class...
public async Task RunSmallerTasks(CancellationToken ct)
{
for(int i = 0; i < k; i++)
{
ct.ThrowIfCancellationRequested();
try
{
await RunSmallTask();
}
catch(Exception e)
{
// Sending telemetry here about the exception.
}
}
}
private CancellationTokenSource _tokenSource;
public async Task RunBigTask()
{
_tokenSource = new CancellationTokenSource();
// Some logic here...
await OtherClass.RunSmallerTasks(_tokenSource.Token);
// Some other logic here...
}

// In another class...
public async Task RunSmallerTasks(CancellationToken ct)
{
for(int i = 0; i < k; i++)
{
ct.ThrowIfCancellationRequested();
try
{
await RunSmallTask();
}
catch(Exception e)
{
// Sending telemetry here about the exception.
}
}
}
3 replies
CC#
Created by MechWarrior99 on 6/14/2023 in #help
❔ Cross-platform 3D rendering library?
Hello, I am working on an application/tool to generate 3D models. I was wondering if there was a good library for 3D rendering, and showing that in a UI. I know there is Silk.Net. But that seems a bit too low level for me (not a graphics/rendering guy at all). And on the other end, I also know that Avalonia has trouble showing 3D renders. Any suggestions to solve these issues? Would I be best to use a game engine like Godot, even if I would have to roll my own UI binding system, and don't need any of the other features a game engine has? Thanks!
7 replies
CC#
Created by MechWarrior99 on 8/18/2022 in #help
How does assigning default values when creating an instance work? [Answered]
I'm not sure how to ask this question. I also can't for the life of me remember what this style of instance creating is called, otherwise I would just look it up.
public interface IData
{
int Value { get; set; }
}
public class Data : IData
{
public int Value { get; set; }
}

public class Container
{
public IData DataSlot { get; set; }
}

// In some method...

var container = new Container()
{
// How does this work? DataSlot is a interface.
DataSlot = { Value = 5 }
}
public interface IData
{
int Value { get; set; }
}
public class Data : IData
{
public int Value { get; set; }
}

public class Container
{
public IData DataSlot { get; set; }
}

// In some method...

var container = new Container()
{
// How does this work? DataSlot is a interface.
DataSlot = { Value = 5 }
}
11 replies