Game Development Community

T3D and Pytorque

by Demolishun · in Torque 3D Professional · 10/30/2011 (3:53 pm) · 18 replies

Well, I bit the bullet and took a look at integrating Pytorque with T3D. I used the information here as a base.

What I found is this:

  1. The platform/gameInterface.h library is missing and app/mainLoop.h has taken its place.
  2. The changes to codeblock.h and codeblock.cpp are virtually identical except line numbers are different.
  3. The cinterface.cpp code outlines how to tap into the major calls to the engine as T3D is divided up into separate calls in a DLL. It is already designed to be used the way PyTorque expects. So with some minor changes to pytorque.cc I was up and running.
  4. I tweaked the DLL project to produce pytorque.pyd. I also tweaked the normal exe of the project to look for pytorque.pyd instead.

So, now that I have it working in very short order I have an issue that I am not sure how to resolve. When I launch the program using the normal code that talks to the game DLL it will load up the main.cs without problems. When I launch under the control of Python it pops up a dialog with "Locate Game Entry Script". If I select the main.cs that is in the project/game directory it loads up fine and runs. The one issues is it does not seem to find the textures when running a mission. So there is definitely a pathing issue between the two.

If someone is experienced with pytorque for TGE 1.5 then please step forward. Yes, I will turn this into a resource once I figure this out. I now develop Python for a living and could not bear programming Torque without it. It is too feature rich to ignore.

Thanks

About the author

I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67


#1
10/30/2011 (7:18 pm)
Frank, my suggestion would be to grab a copy T3D MMOKit if you can find it. It will give you tons of examples of usage and also has all the files you need to build it.
#2
10/30/2011 (7:53 pm)
The problem is that when you run a python script the execution path is where the python.exe is located. To correct in mainloop.cpp find:

Platform::setCurrentDirectory( Platform::getMainDotCsDir() );

and replace with:

Platform::setCurrentDirectory( Platform::getCurrentDirectory() );

Good luck.
#3
10/30/2011 (10:36 pm)
Awesome! I was hoping it would be simple like that.

Are you sure about the MMO kit. The link I put on here did was not updated for T3D. Has the MMO kit been updated for T3D or is it still against TGE 1.5?

Also, I thought there was a licensing issue with using that kit? I really wanted to avoid limiting who I can share the code with at GG. I understood if you use the kit you cannot provide the kit from a different source like if I decide to host the files. The part I linked to just showed how to put Python in and that is what I wanted. It also is not working for T3D so I wanted to document the changes for T3D.
#4
10/30/2011 (10:39 pm)
As long as you obtain the MMOKit through the proper channel there is no license issue. There are versions of the MMOKit TGE, TGEA and T3D. I have the files available and have corrected a large portion of the issues with the T3D version.
#5
10/30/2011 (10:54 pm)
This is what I do not want to get into the middle of:
www.mmoworkshop.com/trac/mom/phpbb?page=viewtopic.php&t=3506
#6
10/30/2011 (10:56 pm)
Then why hasn't someone created a Python only resource? I don't want the MMO portion.
#7
10/30/2011 (11:52 pm)
Hey Corbett,
I tried what you said and it is still not finding the main.cs file. Do I need to mess with some of the other path info stuff?

When I check this path:
Con::printf(Torque::FS::GetCwd().getPath());
Torque::FS::SetCwd( "game:/" );
Con::printf(Torque::FS::GetCwd().getPath());
The first prints out the script path minus the 'C:' and the second just shows '/'.

Edit:
I did this and it is the same result:
Platform::setMainDotCsDir(Platform::getCurrentDirectory());
Platform::setCurrentDirectory( Platform::getCurrentDirectory() );
Con::printf(Platform::getMainDotCsDir());
Con::printf(Platform::getCurrentDirectory());

The other code you mentioned does show the correct path all the way to game dir, but it is not working still. I am not sure what the issue is. Does it need to point to the .py location as root? It is confusing why there are two path setting statements in mainloop.
#8
10/31/2011 (12:53 am)
I am seeing this in the console.log:
Executing scripts/client/config.cs.
findFirstFile() invalid initial search directory: 'game:/'
findFirstFile() search directory not found: '*/materials.cs.dso'
findFirstFile() invalid initial search directory: 'game:/'
findFirstFile() search directory not found: '*/materials.cs'
Binding server port to default IP

I don't get these errors running it from the exe.

Apparently not executing in the proper directory has big issues. I wonder if I can get windows to fix this by using a shortcut.
#9
10/31/2011 (2:04 am)
Okay, figured out how to fix it. The dialog that pops up gave me a clue. it looks like it makes assumptions as to the directory when it first checks the file. Deep down inside it sets it according to the exe directory. So I did this (which is what the dialog does):
Torque::FS::SetCwd("game:/");
Torque::FS::Unmount( "game" );
Torque::FS::Mount( "game", Platform::FS::createNativeFS( ( const char* ) Platform::getCurrentDirectory() ) );
// Set our working directory.
//Platform::setCurrentDirectory( Platform::getMainDotCsDir() );

Platform::setMainDotCsDir(Platform::getCurrentDirectory());
Platform::setCurrentDirectory( Platform::getCurrentDirectory() );

So, I had to force it to fix the "mount" whatever that is. This actually solves the textures missing issues and gets rid of all the errors I saw on startup.

#10
10/31/2011 (9:19 am)
Hey Sean, is it possible to get a copy of the MMO kit files?
#11
10/31/2011 (11:44 pm)
Sean,
Is the license such that I could pull out the Python only portion and post a resource at GG?

Thanks for your help.
#12
11/01/2011 (9:28 am)
I would not recommend redistributing any part of the MMO Kit in any fashion.
#13
11/01/2011 (10:19 am)
@DMB - thanks, I was wondering about that, I was unsure because of the way the new license is written and how the license for the MMOKit was written. It seemed that things were no longer the same as when the post above was written.
#14
11/01/2011 (5:32 pm)
@Dave,
Thanks for the help on clarifying that.

@Sean,
Thanks for helping out.

I will push forward and create my own resource then. I have been meaning to learn how to turn an application into a full blown Python library. This is my chance to learn how to do that. I will also get a chance to get updated on the differences between TGE and T3D.

One question for @David.
I downloaded the files that show how to convert TGE to work as a Python library from PG. Should I be concerned about using that as a starting point? It has absolutely no copyright notice with those files. The files that do have copyright from there are attributed to GG. If I have to start over from scratch I will, I just have a partially working piece of code already.
#15
11/02/2011 (1:11 am)
I am not finding anything wrong with this code. I can run Python functions, create sim objects, and echo to the console. It just works.
#16
11/02/2011 (7:44 pm)
I just talked with PG. I got a clarification on that status of the code in this link. It is considered part of their MMOKit IP and must only be hosted at PG. As long as we respect their IP and their license (which is basically identical in nature as GG's license) there are no issues with using it with Torque.

My next step will be to pursue a resource outlining the changes from their code base to adapt to work with the changes in the existing code base. In any resource I create I will 'only' document changes from their code base where applicable. I will not be using anything other code than the code located at this link.

Any person interested in using the technology from PG should strongly consider trying out their MOM game. It not only shows what can be done by a small group, but is a very good implementation. AND it is fun! Also, by purchasing the product it ensures PG can keep their technology available for future game programmers.
#17
11/03/2011 (5:52 am)
There was also a large amount of code that was developed for the MoM MMO Kit that was NOT developed by the PG crew. if you are looking at re-creating that kit, it may be worth trying to locate the add-in code that Xerves, Leathal and the rest of the crew developed.
#18
11/03/2011 (12:33 pm)
No, I have no desire to recreate the kit. If someone else wants to go down that route that will be up to them.