RumTery
RumTery
CC#
Created by RumTery on 10/26/2024 in #help
How to catch implicit conversion using SyntaxWalker and SemanticModel?
No description
6 replies
CC#
Created by RumTery on 5/5/2024 in #help
Hide private partial class/struct members
I am generating code based on a given class, this partial class contains a generated public interface and generated private members. Is it possible to hide the visibility of private members for the original non-generated class? Some code example
[System]
internal partial class IterativeSystem
{
[SystemCall]
public void Do(int a, ref int b)
{

}
}
[System]
internal partial class IterativeSystem
{
[SystemCall]
public void Do(int a, ref int b)
{

}
}
internal partial class IterativeSystem
{
private static Type[] _mutTypes = [typeof(int)];
private static Type[] _readTypes = [typeof(int)];
public ReadOnlySpan<Type> MutTypes => _mutTypes;
public ReadOnlySpan<Type> ReadTypes => _readTypes;

public void Update()
{
// __DoCall(IRuntimeContext.Current.World);
}

private readonly QueryDescription __DoQuery;
private void __DoCall(World world)
{
var query = world.Query(in __DoQuery);
foreach (ref var chunk in query)
{
var componentsFirst = chunk.GetFirst<int, int>();
foreach (var entityIndex in chunk)
{
ref var t0Component = ref Unsafe.Add(ref componentsFirst.t0, entityIndex);
ref var t1Component = ref Unsafe.Add(ref componentsFirst.t1, entityIndex);
Do(t0Component, ref t1Component);
}
}
}
}
internal partial class IterativeSystem
{
private static Type[] _mutTypes = [typeof(int)];
private static Type[] _readTypes = [typeof(int)];
public ReadOnlySpan<Type> MutTypes => _mutTypes;
public ReadOnlySpan<Type> ReadTypes => _readTypes;

public void Update()
{
// __DoCall(IRuntimeContext.Current.World);
}

private readonly QueryDescription __DoQuery;
private void __DoCall(World world)
{
var query = world.Query(in __DoQuery);
foreach (ref var chunk in query)
{
var componentsFirst = chunk.GetFirst<int, int>();
foreach (var entityIndex in chunk)
{
ref var t0Component = ref Unsafe.Add(ref componentsFirst.t0, entityIndex);
ref var t1Component = ref Unsafe.Add(ref componentsFirst.t1, entityIndex);
Do(t0Component, ref t1Component);
}
}
}
}
4 replies
CC#
Created by RumTery on 11/6/2023 in #help
Is there some standard KeyValue collection allowing adding by value and retrive by key, not dict?
Something like this
public interface IKeyd<TKey> where TKey: IEquatable<TKey>
{
public TKey Key { get; }
}
public class KeyValueCollection<TKey, TValue> where TValue: IKeyd<TKey> where TKey: IEquatable<TKey>
{
private Dictionary<TKey, TValue> _keyValues = new();
public void Add(TValue value)
{
_keyValues.Add(value.Key, value);
}
public bool TryGetValue(TKey key, out TValue value)
{
return _keyValues.TryGetValue(key, out value);
}
public bool Contains(TValue value)
{
return _keyValues.ContainsKey(value.Key);
}
public bool Contains(TKey key)
{
return _keyValues.ContainsKey(key);
}
public bool Remove(TKey key)
{
return _keyValues.Remove(key);
}
public bool Remove(TValue value)
{
return _keyValues.Remove(value.Key);
}
}
public interface IKeyd<TKey> where TKey: IEquatable<TKey>
{
public TKey Key { get; }
}
public class KeyValueCollection<TKey, TValue> where TValue: IKeyd<TKey> where TKey: IEquatable<TKey>
{
private Dictionary<TKey, TValue> _keyValues = new();
public void Add(TValue value)
{
_keyValues.Add(value.Key, value);
}
public bool TryGetValue(TKey key, out TValue value)
{
return _keyValues.TryGetValue(key, out value);
}
public bool Contains(TValue value)
{
return _keyValues.ContainsKey(value.Key);
}
public bool Contains(TKey key)
{
return _keyValues.ContainsKey(key);
}
public bool Remove(TKey key)
{
return _keyValues.Remove(key);
}
public bool Remove(TValue value)
{
return _keyValues.Remove(value.Key);
}
}
10 replies
CC#
Created by RumTery on 10/1/2023 in #help
Delegate caching. Is it safe to use or some dirty hack to avoid? (code below)
Here's some delegate caching into struct...
using System;

public class InstanceHandler<T> where T : InstanceHandler<T>
{
public static T _instance { get; private set; }
public InstanceHandler() => _instance = (T)this;

public readonly struct valuedelegate
{
private readonly Action _instAction;
public valuedelegate(Action<T> action)
{
T caller = _instance;
_instAction = () => action.Invoke(caller);
}
public void Invoke()=> _instAction();
public static implicit operator Action(valuedelegate d) => d._instAction;
}
public readonly struct valuedelegate<N>
{
private readonly Action<N> _instAction;
public valuedelegate(Action<T, N> action)
{
T caller = _instance;
_instAction = x => action.Invoke(caller, x);
}
public void Invoke(N val)=> _instAction(val);
public static implicit operator Action<N>(valuedelegate<N> v) => v._instAction;
}
}

abstract class example : InstanceHandler<example>
{
public void Do() { }
public void Do(int l) { }
methods m;
public class methods
{
public valuedelegate a = new valuedelegate((x) => x.Do());
public valuedelegate<int> b = new valuedelegate<int>((x, z) => x.Do(z));
}

public example():base()
{
m = new methods();
}

public void DoElse()
{
m.a.Invoke();
m.b.Invoke(30);
}

}
using System;

public class InstanceHandler<T> where T : InstanceHandler<T>
{
public static T _instance { get; private set; }
public InstanceHandler() => _instance = (T)this;

public readonly struct valuedelegate
{
private readonly Action _instAction;
public valuedelegate(Action<T> action)
{
T caller = _instance;
_instAction = () => action.Invoke(caller);
}
public void Invoke()=> _instAction();
public static implicit operator Action(valuedelegate d) => d._instAction;
}
public readonly struct valuedelegate<N>
{
private readonly Action<N> _instAction;
public valuedelegate(Action<T, N> action)
{
T caller = _instance;
_instAction = x => action.Invoke(caller, x);
}
public void Invoke(N val)=> _instAction(val);
public static implicit operator Action<N>(valuedelegate<N> v) => v._instAction;
}
}

abstract class example : InstanceHandler<example>
{
public void Do() { }
public void Do(int l) { }
methods m;
public class methods
{
public valuedelegate a = new valuedelegate((x) => x.Do());
public valuedelegate<int> b = new valuedelegate<int>((x, z) => x.Do(z));
}

public example():base()
{
m = new methods();
}

public void DoElse()
{
m.a.Invoke();
m.b.Invoke(30);
}

}
60 replies
CC#
Created by RumTery on 9/15/2023 in #help
Any GUI tool for editing class instance and save to JSON?
I'm creating game tutorial system and want easily edit it's states, conditions etc.. So I have some interfaces as ITutorial, IAction, ICondition, and some implementations as Tutorial, ActionFoo, ActionBar, IfFooBar etc. Is there any gui tool, where i can choose implementation of some interface, fill it's fields and save to json with appropriate class types?
7 replies
CC#
Created by RumTery on 5/6/2023 in #help
❔ Any reasons to use System.Memory<T> instead Array<T>
Just read docs about System.Memory<T>, tried it... I there any use cases where array can't do same work?
77 replies