Jump to content

A C# update


LukasPJ

Recommended Posts

Hello everyone,


Progress is slow, but I have made some updates to the C# stuff.


Where to try T3D.net

I have a spectatorGameplay implementation in C# at this repository: https://github.com/lukaspj/T3D.Net-BaseGame

The repository contains pre-compiled Torque3D as well as .sln and .csproj files which should work, but there might be some paths wrong etc.


The pre-compiled version of Torque3D uses the branch from this PR:

https://github.com/GarageGames/Torque3D/pull/2366



Quick intro

The repository has 3 folders:

  • BaseGame
  • GameCore
  • T3DNetFramework

 

The GameCore folder contains a typical Torque3D project, with scripts, assets, binaries.


The T3DNetFramework folder contains a library which is used for the interop layer between T3D and C#.


The BaseGame folder contains the C# game project, with a C# implementation of the SpectatorGameplay scripts.


The whole thing is unpolished, but I'm happy to answer any questions here or in Discord.


How can I help?

If anyone wants to help me on the project, please just download the C# project and muck about in it. Find bugs, or stuff you think has a weird syntax or functionalities that are missing.



What is the current feature set?

The C# implementation currently has:

  • The full ConsoleObject class-hierarchy generated as C# classes.
  • Full, statically typed interop on all function calls from C# to T3D
  • Full interoperability with TorqueScript
  • Stringly typed interop on all function calls from T3D to C#, with reflection-based conversion of parameters
  • Stringly typed property accessors
  • API documentation exported from the EngineAPI

 

Differences between TorqueScript and C#

The primary difference is type-safety, if the underlying T3D function requires a float, you have to pass a float. Not a string or int.


All Global ConsoleFunctions are prefixed with Global.


You have to "register" SimObjects (similar to how it's done on the C++ side). As an example see the VolumetricFog class:

https://github.com/lukaspj/T3D.Net-BaseGame/blob/master/BaseGame/Game/Spectator/Server/VolumetricFog.cs#L60


As an example this TorqueScript:

   if (isObject(LevelFilesList))
   {
      for ( %file = findFirstFile( "data/spectatorGameplay/levels/*.mis" );
            %file !$= "";
            %file = findNextFile( "data/spectatorGameplay/levels/*.mis" ))
      {
         LevelFilesList.add(%file);
      }
   }

 

Becomes this C#:

         if (Global.IsObject("LevelFilesList")) 
         {
            for (string file = Global.FindFirstFile("data/spectatorGameplay/levels/*.mis");
                        file != "";
                        file = Global.FindNextFile("data/spectatorGameplay/levels/*.mis")) 
            {
               Core.SimObjects.Collections.LevelFilesList.Add(file);
            }
         }

 

Global variables has to be accessed via a function instead of via the dollar-sign thingy:

 

Global.SetConsoleString("Game::DefaultCameraClass", "Camera");
Global.GetConsoleString("Game::DefaultCameraClass");

 

And dynamic fields has to be accessed via a method as well:

 

client.SetFieldValue("camera", camId.ToString());
client.GetFieldValue("camera");
Link to comment
Share on other sites

Thank you very much @noemen :)


I hope that the C# project at the very least can serve as a template for how people can integrate external runtimes / languages to the engine. The principle techniques are actually very simple, so it should be a nice step forward!

Link to comment
Share on other sites

More updates!


The generator has been updated with a new templating engine and more edge-case handling:

https://github.com/lukaspj/T3DSharp


Should be much easier to get up-and-running with now for anyone who wants to look into it at some point.(Albeit still far from "pretty")


Code documentation!

I have extended the Generator with the capability to convert Torque3D's internal doxygen-based comments to C#'s XML comment language.


https://github.com/lukaspj/T3D.Net-BaseGame/blob/master/T3DNetFramework/Generated/Classes/Sim/ActionMap.cs#L628-L647


So now you can get that API documentation directly in your IDE!

Link to comment
Share on other sites

More updates!


The generator has been updated with a new templating engine and more edge-case handling:

https://github.com/lukaspj/T3DSharp


Should be much easier to get up-and-running with now for anyone who wants to look into it at some point.(Albeit still far from "pretty")


Code documentation!

I have extended the Generator with the capability to convert Torque3D's internal doxygen-based comments to C#'s XML comment language.


https://github.com/lukaspj/T3D.Net-BaseGame/blob/master/T3DNetFramework/Generated/Classes/Sim/ActionMap.cs#L628-L647


So now you can get that API documentation directly in your IDE!

 

I'm studying the c#, in the future I will support you in this wonderful project.

In 2 months or more I will be ready.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...