Holy cow... (cSharp enhanced Torque)
by Vince Gee · 01/23/2012 (8:32 am) · 22 comments
Happy Monday everyone!
Well, what an incredible journey I've been on! Last year sometime I started working on an MMO project for Torque. Well, I wouldn't call it a MMO, since I never imagine getting the millions of subscribers MMO's get, but hey we will call it a MMO anyway!
So, my responsibility in this project is to provide the business and data layer to torque, other people handle the gui, artwork etc.
Server OS: Windows 2008
Database: MS SQL Server 2008
Ok, so last year I built a somewhat complex method for calling C# from torque using the Com Interface via an Out-Of-Process Com Exe. It worked great initially for loading information about players and parameters. Then I added AI's.
Soon I found that the Com Interface couldn't handle the rapid calls from Torque, slowly but surely the Com Interface would completely crap out and crash the server very very bad.
So this weekend, I was pretty much depressed, if I couldn't figure out a way to make this work, months worth of work writing the csharp Dll that the game uses for the Business Layer and Data Layer would be thrown away. It wasn't looking good for my project
In my depression I started reviewing how the pyTorque solution worked, going over the code changes to Torque and trying to get a grasp on the solution as a whole.
Now, for those who don't know me, my Day Job is a business programmer for a Brick and Mortar. I rarely have to do any coding at the nuts and bolts level of anything. Usually, it's a very mundane job and thus the reason I work on this project.
After doing some reading and finding some interesting articles on the internet, I got a prototype working for something I affectionately call 'csTorque', basically a way to start Torque under the CLR runtime using PinInvokes and provide a series of callbacks to the c#.
My goal, is simple, to provide the same level of functionality (or more) that pyTorque offers for Dot Net.
Imagine, if you will, being able to do 90 percent of your game code in a language like vbscript or csharp (the later being my favorite)
Vince
Well, what an incredible journey I've been on! Last year sometime I started working on an MMO project for Torque. Well, I wouldn't call it a MMO, since I never imagine getting the millions of subscribers MMO's get, but hey we will call it a MMO anyway!
So, my responsibility in this project is to provide the business and data layer to torque, other people handle the gui, artwork etc.
Server OS: Windows 2008
Database: MS SQL Server 2008
Ok, so last year I built a somewhat complex method for calling C# from torque using the Com Interface via an Out-Of-Process Com Exe. It worked great initially for loading information about players and parameters. Then I added AI's.
Soon I found that the Com Interface couldn't handle the rapid calls from Torque, slowly but surely the Com Interface would completely crap out and crash the server very very bad.
So this weekend, I was pretty much depressed, if I couldn't figure out a way to make this work, months worth of work writing the csharp Dll that the game uses for the Business Layer and Data Layer would be thrown away. It wasn't looking good for my project
In my depression I started reviewing how the pyTorque solution worked, going over the code changes to Torque and trying to get a grasp on the solution as a whole.
Now, for those who don't know me, my Day Job is a business programmer for a Brick and Mortar. I rarely have to do any coding at the nuts and bolts level of anything. Usually, it's a very mundane job and thus the reason I work on this project.
After doing some reading and finding some interesting articles on the internet, I got a prototype working for something I affectionately call 'csTorque', basically a way to start Torque under the CLR runtime using PinInvokes and provide a series of callbacks to the c#.
My goal, is simple, to provide the same level of functionality (or more) that pyTorque offers for Dot Net.
Imagine, if you will, being able to do 90 percent of your game code in a language like vbscript or csharp (the later being my favorite)
Vince
About the author
www.winterleafentertainment.com
#22
I realize this was a corner case for handling an obscure way for calling a function, but it took care of the issue when a SimObject was not available. So I first look for a SimObject, if one is not available I use the supplied namespace. This makes the functions operate exactly like a TS function would. So make sure you cannot do this: "namespace::function" type calls or it may not call the right function for the object.
Check out www.garagegames.com/community/blogs/view/21420 I go into more detail as to why.
01/27/2012 (10:08 am)
Because you can call a function in a way that will cause the resulting function called to be ambiguous:// 2 different objects
new SimObject(Test1){};
new ScriptObject(Test2){};
// 2 different functions
function SimObject::echo(%this){
}
function ScriptObject::echo(%this){
}
// I just called the wrong function on the wrong object
SimObject::echo(Test2);
// no simobject
// The next issue is this
SimObject::echo(ScriptObject);
// I only get a string for the first arg which is a namspace.
// No object validation, no simbojectI realize this was a corner case for handling an obscure way for calling a function, but it took care of the issue when a SimObject was not available. So I first look for a SimObject, if one is not available I use the supplied namespace. This makes the functions operate exactly like a TS function would. So make sure you cannot do this: "namespace::function" type calls or it may not call the right function for the object.
Check out www.garagegames.com/community/blogs/view/21420 I go into more detail as to why.

Torque Owner Vince Gee
WinterLeaf Entertainment
I found the same issue with the namespace, but if you look at the callback from c++ it does pass a pointer to the simobject. (When the function is called off of a in game object) If you use memory parsing, you can extract a whole bunch of goodies from that pointer.
Or, you can take the route I did and make one call back to the dll, pass the pointer it gave you to the simobject to it, cast it to a simobject, copy the important properties to a holding structure, and then, return that holding structure back to the outside language. Thus, you can extract what you need in the foreign language.
Total modifications to the C++ for my solution was like 20 lines of code :)