Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to create .NET csharp example illustrating the use case below? #1

Open
GeorgeS2019 opened this issue Apr 11, 2024 · 10 comments
Labels
enhancement New feature or request

Comments

@GeorgeS2019
Copy link

Start Godot from a .NET process to use standard .NET tooling

@kisg kisg added the enhancement New feature or request label Apr 11, 2024
@kisg
Copy link
Contributor

kisg commented Apr 11, 2024

Thanks for the feature request. This should be done probably with this: https://github.com/raulsntos/godot-dotnet

@GeorgeS2019
Copy link
Author

GeorgeS2019 commented Apr 11, 2024

@raulsntos
We respect your wishes that all discussions are channeled elsewhere.
We understand you wish to stay focus on developing, instead of answering questions not related to bugs and not feature request.

We understand that you wish that further discussions will only take place after this project is merged to the main.

Our question, what is the time line for the merge.

During this time, how can we coordinate as godot 4 .NET community to speed up the merge?

What are the TODOLIst for this repos so we can estimate how much more we need to coordinate

This is a feedback because we really care that the .NET extension part is not too far from other extensions.

https://github.com/raulsntos/godot-dotnet

@Repiteo
@ZerxZ
@Faolan-Rad
@scgm0

Latest Update

https://github.com/Delsin-Yu/CSharp-Wrapper-Generator-for-GDExtension

@GeorgeS2019
Copy link
Author

GeorgeS2019 commented Jul 12, 2024

@GeorgeS2019
Copy link
Author

Still on the TODO list:
godotengine/godot#90510 (comment)

  • Windows build
  • Fix CI builds
  • Create a .NET/C# example using the new GDExtension-based .NET implementation.

[WIP] Windows platform: libgodot.dll

The libgodot.dll comes from

  • library_type=shared_library

scons platform=windows target=template_debug arch=x86_64 verbose=yes msvc=yes library_type=shared_library dev_build=yes debug_symbols=yes

bin\ godot.windows.template_debug.dev.x86_64.dll

scons platform=windows arch=x86_64 verbose=yes msvc=yes dev_build=yes debug_symbols=yes

bin\ godot.windows.editor.dev.x86_64.exe --dump-extension-api

With this, provide the json and the dll to the godot-dotnet project.

  1. bin\ extension_api.json
  2. bin\ godot.windows.template_debug.dev.x86_64.dll

The output will be c# wrappers for the godot.windows.template_debug.dev.x86_64.dll

Users can then write c# applications to embed godot as a library in .NET applications

Very similar to: LibGodotSharp

@INeedAUniqueUsername
Copy link

Does this example enable web export? Is there a way to use WASM / Emscripten on NET 9.0 + LibGodot to make something that can run in Firefox?

@GeorgeS2019
Copy link
Author

JiepengTan/libgodot_llgo_demo#1 (comment)

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);
}

@GeorgeS2019
Copy link
Author

GeorgeS2019 commented Aug 17, 2024

Launcher with (Windows) libgodot.dll

https://github.com/JiepengTan/libgodot_llgo_demo/tree/main/samples/cs_sample/Launcher

image

"Launcher.exe" "../../Summator/Game"
Hello Libgodot-csharp !
Project path: ../../Summator/Game
Godot Engine v4.3.beta.custom_build - https://godotengine.org
WARNING: Unable to initialize Windows common controls. Native dialogs may not work properly.
     at: DisplayServerWindows::DisplayServerWindows (platform\windows\display_server_windows.cpp:5725)
OpenGL API 3.3.0 NVIDIA 538.18 - Compatibility - Using Device: NVIDIA

60 <=== right answer

WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: ObjectDB::cleanup (core\object\object.cpp:2284)

https://github.com/JiepengTan/libgodot_llgo_demo/tree/main/samples/project

"Launcher.exe"  "project"
Hello Libgodot-csharp !
Project path: ../../project
Godot Engine v4.3.beta.custom_build - https://godotengine.org
WARNING: Unable to initialize Windows common controls. Native dialogs may not work properly.
     at: DisplayServerWindows::DisplayServerWindows (platform\windows\display_server_windows.cpp:5725)

@GeorgeS2019
Copy link
Author

@kisg
Just want to share that we are progressing into Windows and .NET support for libgodot and how to integrate test driven approach for c# bindings of LibGodot

@daerogami
Copy link

daerogami commented Oct 23, 2024

Woah! I had no idea this much progress had been made towards running the godotlib in .NET; kudos to all involved! Are there plans to write hostbuilder extensions for configuring and running the Godot instance or is it much too early to be discussing that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants