LukasPJ Posted December 5, 2016 Share Posted December 5, 2016 Hey guys,So, I've implemented T3D into C# in order to provide a C# scripting interface for the engine. It's still very much a work in progress, so it's not nice or anything. It's more or less a proof of concept.So I'm looking for someone interested in downloading the attached binaries, opening it up and taking a stab at it just doing different things you are curious about and reporting any marshalling errors for me.I will provide more information about this whole Torque3D and C# thing in a blog, when the project is more mature.Be advised, that this is not polished in any way and you should know your way around TorqueScript, C# and Torque itself in order to figure out how to use it.The attached code file delivers the following:The Empty project with a compiled DLLA folder "c#" with the following:A C# project "Game" with a file program.cs which initializes the engine and TestScript.cs which is a translation of the main.cs fileA C# project "Torque3D" with all the interop-code and proxy classes in order to interact with Torque3D. You can download it at: http://lukasj.org/TorqueSharp-0.3.0.zipFeel free to ask any specific questions about how it works and report all bugs you find. Thanks a ton!Edit:In case anyone is curious, here is a comparison between main.cs in C# and TorqueScript and there's also a bit more information to be found in the now-inactive Torque6-C# wiki: https://github.com/lukaspj/Torque6-Embedded-CSharp/wiki Quote Link to comment Share on other sites More sharing options...
RasterRon Posted December 6, 2016 Share Posted December 6, 2016 This looks interesting Lukas, so basically you can still use both TorqueScript and C#? nice. :) Quote Link to comment Share on other sites More sharing options...
deathbravo Posted December 7, 2016 Share Posted December 7, 2016 when i first run it in cmd console, it gives :Unhandled Exception: System.NullReferenceException: Object reference not set toan instance of an object. at Torque3D.GuiCanvas.showWindow() in D:\GameDev\Torque3D-Hobby\Torque#-Alpha\c#\Torque3D\Torque3D\Engine\GuiCanvas.cs:line 940 at Game.TestScript.entry() in D:\GameDev\Torque3D-Hobby\Torque#-Alpha\c#\Torque3D\Game\TestScript.cs:line 142 at Torque3D.Torque3D.Initialize(String[] args, Libraries libraryNames) in D:\GameDev\Torque3D-Hobby\Torque#-Alpha\c#\Torque3D\Torque3D\Torque3D.cs:line 121 at Game.Program.Main(String[] args) in D:\GameDev\Torque3D-Hobby\Torque#-Alpha\c#\Torque3D\Game\Program.cs:line 17then I tried it in visual studio, it works. Then it can work in cmd console without the exception thrown. Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted December 7, 2016 Author Share Posted December 7, 2016 This looks interesting Lukas, so basically you can still use both TorqueScript and C#? nice. :)Yeah, TorqueScript works just like it has always done. C# is just an optional layer on top of that.. It doesn't even have to be merged into the official repo!@deathbravo Huh, that's really odd. Thanks for reporting the issue! :) I'll have a look at it, seems like it might just be some outdated binaries or something though. Quote Link to comment Share on other sites More sharing options...
RasterRon Posted December 7, 2016 Share Posted December 7, 2016 Yeah, TorqueScript works just like it has always done. C# is just an optional layer on top of that.. It doesn't even have to be merged into the official repo! Got it and that's awesome! I'm also getting the same error as [mention]deathbravo[/mention]. Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted December 7, 2016 Author Share Posted December 7, 2016 Yeah, TorqueScript works just like it has always done. C# is just an optional layer on top of that.. It doesn't even have to be merged into the official repo! Got it and that's awesome! I'm also getting the same error as [mention]deathbravo[/mention]. Just had a chance to look at it, and apparently the precompiled .exe file is outdated. So recompiling it through VS should fix it. I'm updating an updated .zip file soon :) Quote Link to comment Share on other sites More sharing options...
Monkeychops Posted December 9, 2016 Share Posted December 9, 2016 Seems to run for me, although not sure how to do much except start the blank scene.This is really cool - I have to say I've kinda given up on Torque because TS is too quirky and not a lot of open source libraries and such out there for it.. but C# would be a whole new story. Quote Link to comment Share on other sites More sharing options...
RasterRon Posted December 9, 2016 Share Posted December 9, 2016 Just had a chance to look at it, and apparently the precompiled .exe file is outdated. So recompiling it through VS should fix it. I'm updating an updated .zip file soon :) Ah ok thanks. Apparently I still have to do a VS2015 reinstall and my latest working here is 2010 but anyway, looking forward to it. :) Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted December 15, 2016 Author Share Posted December 15, 2016 Monkeychops said: Seems to run for me, although not sure how to do much except start the blank scene. This is really cool - I have to say I've kinda given up on Torque because TS is too quirky and not a lot of open source libraries and such out there for it.. but C# would be a whole new story. Honestly, I don't mind TorqueScript, but yeah the reason I'm doing this C# thing, is because of a Hackathon I want to hold at my University, and I don't feel like asking people to learn TS in a day On another note.. New release! This release features: Properties All SimObjects static fields can now be accessed like regular C# properties: StaticShape coin = Sim.FindObject(obj); ParticleEmitterNode emitterNode = new ParticleEmitterNode { DataBlock = Sim.FindObjectByName("CoinNode"), Emitter = Sim.FindObjectByName("CoinEmitter"), Position = coin.Position }; emitterNode.registerObject(); emitterNode.schedule(200, "delete"); They are all going through the console, so they are converted to and from string which of course is sub-optimal. But it's something! Furthermore, I added some more sample C#. scripts.. Namely first and second part of this tutorial: http://wiki.torque3d.org/scripter:coincollection I still haven't fixed creation of datablocks, so they are eval'ed atm but small steps all the time! Quote Link to comment Share on other sites More sharing options...
JeffR Posted December 15, 2016 Share Posted December 15, 2016 You sexy beast! ;)Very awesome. I need to give this a proper run-down.So outside of obvious, improvements like cutting back on how much string interpretation we use and whatnot, what do you think is still missing at least an initial implementation?It's sounding like it's pretty close to at least the 'everything runs' level. Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted December 16, 2016 Author Share Posted December 16, 2016 You sexy beast! ;)Very awesome. I need to give this a proper run-down.So outside of obvious, improvements like cutting back on how much string interpretation we use and whatnot, what do you think is still missing at least an initial implementation?It's sounding like it's pretty close to at least the 'everything runs' level. I really want to implement typed callbacks, right now they are stringly typed, and you don't override them from the parent class.Datablocks don't really work properly in C# yet, and there are a bunch of the structs (like Point3F) that don't work (Point3F does though), so they will have to be brought up to date.Furthermore, some things might not be marshalled properly (bools for instance) and I don't know if enums work.Also have to decide what I want to do with packages, but in the big picture this is all minor things. The one major issue, that I know of, is cleanup. C# allocates SimObjectPtr's in order to access C++ objects safely and being able to cast errors, but they are not delete properly on C# destructors, this makes the engine crash if you enter a mission twice, as some things are not cleaned up properly. Quote Link to comment Share on other sites More sharing options...
RasterRon Posted December 16, 2016 Share Posted December 16, 2016 Finally got 2015 reinstalled and it works great. Keep it up Lukas! :) Quote Link to comment Share on other sites More sharing options...
chriscalef Posted December 18, 2016 Share Posted December 18, 2016 Sounds great, @LukasPJ! Fill me in though, how does this relate to / contrast against the work you guys have been doing for years re: T3D and C#? I guess I kinda thought you had done this some time ago. But it's awesome! I too would love to be able to share T3D without forcing people to learn TS. For my purposes, I wouldn't even mind if the existing Torque Script for the editors, etc. stayed in place, as long as new scripts could be written in C#. It's been a low priority for me so far, but consider me on the list of interested parties! Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted December 18, 2016 Author Share Posted December 18, 2016 Sounds great, @LukasPJ! Fill me in though, how does this relate to / contrast against the work you guys have been doing for years re: T3D and C#? I guess I kinda thought you had done this some time ago. But it's awesome! I too would love to be able to share T3D without forcing people to learn TS. For my purposes, I wouldn't even mind if the existing Torque Script for the editors, etc. stayed in place, as long as new scripts could be written in C#. It's been a low priority for me so far, but consider me on the list of interested parties! Well first of all Vince's (from Winterleaf) version of C# for Torque3D is a whole other project. I'm not really affiliated with WLE anymore, in fact I don't think it even exists (?). They moved to UE4 some time ago.Second, I believe I'm going for a cleaner solution. At least, I'm trying to make it as light-weight as possible. Furthermore, the OMNI stuff was still stringly-typed. I'm going for a completely typed interaction with the engine, with no conversion to and from strings (where possible at least). OMNI also modified the engine quite a lot (example: https://github.com/Winterleaf/OmniEngine.Net/blob/3363364e8c4514d5ef18574ce2200368e5946df4/Engine/source/T3D/aiClient.cpp#L692 ) I don't want to step on anyones toes, so I'm keeping engine-modifications to a bare-minimum. The only modifications I've made is various bug-fixes and improvements, and a few changes to the macros for consistency reasons.In case you are curious, the OMNI repo is still up:https://github.com/Winterleaf/OmniEngine.Net Quote Link to comment Share on other sites More sharing options...
chriscalef Posted December 18, 2016 Share Posted December 18, 2016 Ah, I get it. Well, right on man, more power to you! Good luck!! Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted December 23, 2016 Author Share Posted December 23, 2016 New release! This release primarily focuses on various bug-fixes.The biggest new feature in this release is more script examples!This release does not have any TorqueScript code, only C# and C++, so there's more test-cases and a more complete insight into Torque3D with C#. It's based on the awesome T3Dbones repository, and you can see the C# code online if you don't want to download it here: https://github.com/lukaspj/t3d-bones-sharpCurrently known issues: A lot of the vararg methods are not working Some enums seem to be marshalled incorrectly C#-destructors doesn't seem to clean-up the SimObjectPtr properly Quote Link to comment Share on other sites More sharing options...
Timmy Posted December 23, 2016 Share Posted December 23, 2016 Awesome stuff lukas. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.