[module] Unsure how to properly use ChangeDirectory()
differenceclouds opened this issue · comments
So, I'm using Raylib-CS on macos, so that might be pertinent. Right now, for loading assets I am using a solution I picked up from using Monogame. It goes something like this:
Check "copy to output directory" on all assets (images etc). Then I use this function whenever I'm loading a file:
static string getFullPath(string relativePath)
{
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
return System.IO.Path.Combine(baseDirectory, relativePath);
}
Font ALAGARD = LoadFont(getFullPath("Assets/fonts/alagard.png"));
Image cursorImage = LoadImage(getFullPath("Assets/cursor.png"));
This works for me, but I've been made aware that another solution would be to call ChangeDirectory(GetApplicationDirectory());
The issue is, I don't know how to use this function properly with C#. I get the following errors:
Again, what I was already doing works, but I'm curious how to use these functions properly. It doesn't seem like using "unsafe" should be required. I feel that I am missing something obvious here, any help would be appreciated!
Have a look at Utf8StringUtils
it allows you to convert pointers to strings and back.
As for the current directory, try and prefer the built-in C# methods, e.g. System.Numerics
over RayMath, AppDomain.CurrentDomain.BaseDirectory
or Assembly.GetExecutingAssembly().Location
over raylib.GetApplicationDirectory
, etc.
I think we should make these methods internal and provide a safe method for every one to not confuse the users.
Maybe it's worth taking a look at all the methods that take pointers. I've gotten the image manipulation functions to work with the "ref" keyword but this wasn't obvious.
@differenceclouds
Oh, the ref
keyword is common in C#:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref
When you use void ImageRotateCW(ref Image image)
for example, the with and height of the image change and in order to update the fields, you have to provide a reference.
That's because Image is a struct and not a class.
@JupiterRider I agree providing more wrapper utilities is a good idea. I also want to improve documentation about built in C# alternatives to raylib methods to make the options clearer.