Sherbert Lemon
Sherbert Lemon
CC#
Created by Sherbert Lemon on 5/23/2023 in #help
❔ I have a basic structuring issue
this is unity but it doesn't really matter for the sake of this I have a character which can move around and look around, but sometimes the movement changes and the mouse movements might be menus so I have a main class and an array of possible active classes for controlling movement, and another array for controling viewing, along with a variable for the current one of each. Sometimes the movement class has to get information from the viewing class, how should i structure this i think that having a reference between the two will make it bad, I am not sure honestly, and I am not sure with the rest of the structure
4 replies
CC#
Created by Sherbert Lemon on 3/28/2023 in #help
❔ How do I refactor this?
I am working with a grid of tiles, each tile has an int, which is made up of 4 bytes which represent what value in an enum each side of the tile is in. This means I have a lot of things that need to run after a few calculations are done in a loop of adjacent tiles here is most of the repeated code
for (int i = 0; i < Adjacency.Length; i++)
{
Vector2Int curr = Adjacency[i];

Vector2Int position = curr + _tile;

if (position.x >= width || position.y >= height || position.x < 0 || position.y < 0)
continue;

byte adjacentTileType = (byte)(_tiledata & (byte.MaxValue << (i * 8)));

int oppositeSide = i + 2;
oppositeSide = oppositeSide > 3 ? oppositeSide - 4 : oppositeSide;

uint shiftedAdjacentTile = (uint)((int)adjacentTileType << (oppositeSide * 8));
uint shiftedMask = (uint)(byte.MaxValue << (oppositeSide * 8));

// one function would have stuff to update tiles based on these calculations, another to check if they are valid, some other ones will be added
}
for (int i = 0; i < Adjacency.Length; i++)
{
Vector2Int curr = Adjacency[i];

Vector2Int position = curr + _tile;

if (position.x >= width || position.y >= height || position.x < 0 || position.y < 0)
continue;

byte adjacentTileType = (byte)(_tiledata & (byte.MaxValue << (i * 8)));

int oppositeSide = i + 2;
oppositeSide = oppositeSide > 3 ? oppositeSide - 4 : oppositeSide;

uint shiftedAdjacentTile = (uint)((int)adjacentTileType << (oppositeSide * 8));
uint shiftedMask = (uint)(byte.MaxValue << (oppositeSide * 8));

// one function would have stuff to update tiles based on these calculations, another to check if they are valid, some other ones will be added
}
This seems like a problem that would be solved with a functional language, but how would I allow for a few functions reuse this portion of code, adding a new bit on the end without copying and pasting all the starting stuff
4 replies
CC#
Created by Sherbert Lemon on 3/22/2023 in #help
❔ How Would I extract a single byte from an int
In my project, I have information which is effectively a byte[4] stored in an int32, I want to grab a specific byte from this I currently have the code
byte adjacentTileType = _tiledata >> (i * 8);
byte adjacentTileType = _tiledata >> (i * 8);
this produces an error as it should, but how would I do this properly
29 replies
CC#
Created by Sherbert Lemon on 12/29/2022 in #help
Error CS353 When it doesn't make sense for this situation
A result of a stackalloc expression of type 'Span<int>' cannot be used in this context because it may be exposed outside of the containing method however it isn't exposed out of the method, I will post the code in another message as it is a lil long
37 replies
CC#
Created by Sherbert Lemon on 11/16/2022 in #help
System.AccessViolation when passing a fixed pointer to opentk [Answered]
https://discord.com/channels/143867839282020352/1042197174982811719/1042197174982811719 - continuing on from this post, I now get a access violation when I pass it and don't know why, can anyone shed any light on what could cause it?
7 replies
CC#
Created by Sherbert Lemon on 11/15/2022 in #help
❔ How do I get an IntPtr from a Span [Answered]
a library wants me to give a span<byte> as a pointer, and I am not sure as I haven't really done much with pointers in c# before
12 replies
CC#
Created by Sherbert Lemon on 11/14/2022 in #help
Where do I download the .net framework sdks [Answered]
I have a rather old program I am trying to run and I need the sdk for 4.5.2 but on the https://dotnet.microsoft.com/en-us/download/visual-studio-sdks site the framework developer pack's don't install in the same way as the current sdks, where do they install and how do I get it working?
7 replies
CC#
Created by Sherbert Lemon on 11/5/2022 in #help
Naming conventions [Answered]
I am arguing with my friend about what casing to use in variable names. To settle the argument whatever the first naming convention that someone says (within reason say the actual one that you use) we will use
19 replies