Closed GeorgeS2019 closed 2 months ago
@JiepengTan I am unsure how challenging to have a c# demo.
I wonder if it is due to lack of readiness of the c# project : https://github.com/raulsntos/godot-dotnet
https://github.com/godotengine/godot/pull/90510#issuecomment-2285924926
@JiepengTan I am unsure how challenging to have a c# demo.
I wonder if it is due to lack of readiness of the c# project : https://github.com/raulsntos/godot-dotnet
sorry. I've been busy with other things for the last few weeks, I have tried building the godot-dotnet repository on Windows, Ubuntu, and Mac (following the instructions in the README), but I failed to build it
@JiepengTan I am unsure how challenging to have a c# demo. I wonder if it is due to lack of readiness of the c# project : https://github.com/raulsntos/godot-dotnet godotengine/godot#90510 (comment)
sorry. I've been busy with other things for the last few weeks, I have tried building the godot-dotnet repository on Windows, Ubuntu, and Mac (following the instructions in the README), but I failed to build it
The author mentioned the solution to this problem in the issues. I will add a C# example tomorrow.
Thank you for your effort.
[ ] Is it possible now to have the c# version to create the SAME sample .net program as that of the cpp demo?
[x] Is it possible now to have a c# demo similar to the cpp demo? https://github.com/JiepengTan/libgodot_llgo_demo/blob/07b9287bd65e6a1cd1dc0fa100987eb9adcfeaf7/samples/cpp_sample/src/main.cpp#L152
int main(int argc, char **argv) {
LibGodot libgodot;
std::string program;
std::string project_path = "../../project/";
if (argc > 0) {
program = std::string(argv[0]);
}
if (argc > 1) {
project_path = std::string(argv[1]);
}
std::vector<std::string> args = { program, "--path", project_path, "--rendering-method", "gl_compatibility", "--rendering-driver", "opengl3" };
std::vector<char *> argvs;
for (const auto &arg : args) {
argvs.push_back((char *)arg.data());
}
argvs.push_back(nullptr);
GDExtensionObjectPtr instance = libgodot.create(argvs.size(), argvs.data());
if (instance == nullptr) {
fprintf(stderr, "Error creating Godot instance\n");
return EXIT_FAILURE;
}
bool succ = libgodot.start(instance);
while (!libgodot.iteration(instance)) {
}
libgodot.destroy(instance);
return EXIT_SUCCESS;
}
@JiepengTan Thank you, exactly what I hope for. Thank you again.
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello Libgodot-csharp ! ");
string program = "";
string projectPath = "../../Summator/Game";
if (args.Length > 0)
{
projectPath = args[0];
Console.WriteLine("Project path: " + projectPath);
}
List<string> arguments = new List<string> { program, "--path", projectPath, "--rendering-method", "gl_compatibility", "--rendering-driver", "opengl3" };
IntPtr instance = LibGodot.libgodot_create_godot_instance(arguments.Count, arguments.ToArray(), IntPtr.Zero);
if (instance == IntPtr.Zero)
{
Console.Error.WriteLine("Error creating Godot instance");
Environment.Exit(1);
}
bool success = LibGodot.libgodot_start_godot_instance(instance);
while (LibGodot.libgodot_iteration_godot_instance(instance))
{
}
LibGodot.libgodot_destroy_godot_instance(instance);
Environment.Exit(0);
}
}
The essential c# interopt with Windows: libgodot.dll
using System;
using System.Runtime.InteropServices;
public enum GDExtensionInitializationLevel
{
GDEXTENSION_INITIALIZATION_CORE,
GDEXTENSION_INITIALIZATION_SERVERS,
GDEXTENSION_INITIALIZATION_SCENE,
GDEXTENSION_INITIALIZATION_EDITOR,
GDEXTENSION_MAX_INITIALIZATION_LEVEL
}
[StructLayout(LayoutKind.Sequential)]
public struct GDExtensionInitialization
{
public GDExtensionInitializationLevel minimum_initialization_level;
public IntPtr userdata;
public Action<IntPtr, GDExtensionInitializationLevel> initialize;
public Action<IntPtr, GDExtensionInitializationLevel> deinitialize;
}
public class LibGodot
{
const string LIBGODOT_LIBRARY_NAME = "libgodot.dll";
[DllImport(LIBGODOT_LIBRARY_NAME)]
public static extern IntPtr libgodot_create_godot_instance(int argc, string[] argv, IntPtr handle);
[DllImport(LIBGODOT_LIBRARY_NAME)]
public static extern void libgodot_destroy_godot_instance(IntPtr instance);
[DllImport(LIBGODOT_LIBRARY_NAME)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool libgodot_start_godot_instance(IntPtr instance);
[DllImport(LIBGODOT_LIBRARY_NAME)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool libgodot_iteration_godot_instance(IntPtr instance);
}
ok, i will try it later