XMLObject v1.0 Beta Release

Posted in: C/C++, Game Development |

I have released the existing XMLObject code as a v1.0 Beta, and the details can be found in this GG .plan.

The current object supports the majority of the expat libraries standard callbacks, with the exception of it’s Schema/DTD callbacks, as well as the ability to parse both a full file and a string (obtained from network resources such as SOAP and XML-RPC requests).

Additional features, demos and examples of use for the XMLObject will be released in time, these examples include integrating my existing HighScores object as an XML document, as well as retrieving the HighScores object from a network resource.

For more details, and a download link, please drop by and read the GG .plan.

Want to Advertise on this Site?

XMLObject Updates

Posted in: C/C++, Game Development |

Ok, I’ve finished some more of the XMLObject code, and now have the following SAX methods implemented as TorqueScript callbacks:

  • onElementStart(%this, %name, %attributes)
  • onElementEnd(%this, %name)
  • onCharacterData(%this, %name, %data) // %name is a reference to the last element started
  • onProcessingInstruction(%this, %target, %data)
  • onComment(%this, %data)
  • onCdataSectionStart(%this)
  • onCdataSectionEnd(%this)
  • onDefault(%this, %data, %len)

Not all of the callbacks have been thoroughly tested, but the following callbacks have been tested and found to be in full working order so far;

OnElementStart, onElementEnd, onCharacterData and onComment.

It looks like I’m getting nearer and nearer to having my saveXml() and loadXml() methods fully functioning, and as seen in my previous post, I’ve already got the makings of a TorqueScript-based object/level loader.

Want to Advertise on this Site?

TorqueScript XML Object Loads

Posted in: C/C++, Game Development |

I've managed to get the XMLObject to a fairly useable point, so far, the following script, is useable:

JavaScript:
  1. function sceneObjectParser::onElementStart(%this, %name, %atts)
  2. {
  3.    switch$(%name)
  4.    {
  5.       case "objects": %this.objectBlock = true;
  6.       default:
  7.          if(%this.objectBlock)
  8.          {
  9.             %obj = new (%name)()
  10.             {
  11.                class = getAttribute(%atts, "class");
  12.                superClass = getAttribute(%atts, "superClass");
  13.             };
  14.             %obj.dump();
  15.          }
  16.    }
  17. }
  18.  
  19. function sceneObjectParser::onElementEnd(%this, %name)
  20. {
  21.     switch$(%name)
  22.     {
  23.        case "objects": %this.objectBlock = false;
  24.     }
  25. }
  26.  
  27. function sceneObjectParser::onCharacterData(%this, %name, %data, %len)
  28. {
  29.    echo("CDATA: ---" @ %name @ " - " @ %data @ "---");
  30. }
  31.  
  32. function getAttribute(%atts, %name)
  33. {
  34.    for(%x = 0; %x <%atts.getCount(); %x++)
  35.    {
  36.       if(%atts.getObject(%x).AttributeName $= %name) return %atts.getObject(%x).AttributeValue;
  37.    }
  38.    return "";
  39. }
  40.  
  41. $xml = new XMLObject() { class = "sceneObjectParser"; objectBlock = false; };
  42. $xml.parseDocument("XMLTestFile.xml");

This will actually create instances of the objects identified by the xml elements inside of an "objects" node, for example, the following XML document was parsed for testing;

XML:
  1. <level name="xmlLevel">
  2.     <objects>
  3.         <t2dsceneobject class="mySceneObject" superClass="mySuperClass" />
  4.         <t2dstaticsprite class="myStaticSprite" />
  5.         <scriptobject class="myScriptObject" superClass="mySuperClass2" />
  6.     </objects>

I've not yet thoroughly tested it, but once I find a useful and reusable XML format for Objects and Levels, I'll start working on the saveXml and loadXml functions respectively, and add them as either ConsoleFunctions which take in any SimObject, or add them as addon functions to the base SimObject within the XMLObject.cc itself (little to no engine code should need to be updated for this resource to work effectively)

Want to Advertise on this Site?

TorqueScript XMLObject

Posted in: C/C++, Game Development |

I have started working on an implementation of Expat (the Gnome XML Parser) library into TGB, and expect that a large portion of the code should work with TGE as well, as it's just a simple Console Object being added to the system.

So far, I've managed to create and expose the XMLObject class to TorqueScript, as well as added a 'parseDocument' method to the object, which is exposed to TorqueScript and takes in a Filename as it's only parameter. This then makes numerous calls to the startElement and endElement C++ methods (there's a static and non-static version of each, something to do with the function pointers that expat uses since its written in C). These C++ methods then call there TorqueScript equivalents, onStartElement and onEndElement, which allows a script developer to very simply use the SAX parser functionality of Expat within TorqueScript by doing the following:

JavaScript:
  1. function MySax::onStartElement(%this, %name, %atts)
  2. {
  3.   echo("ElementStart: " @ %name);
  4.   for(%x = 0; %x &lt;%atts.getCount(); %x++)
  5.   {
  6.     echo("  Name:  " @ %atts.getObject(%x).AttributeName);
  7.     echo("  Value: " @ %atts.getObject(%x).AttributeValue);
  8.   }
  9. }
  10.  
  11. function MySax::onElementEnd(%this, %name)
  12. {
  13.   echo("TS ElementEnd: " @ %name);
  14. }
  15.  
  16. %sax = new XMLObject()
  17. {
  18.   class = "MySax";
  19. };
  20.  
  21. %sax.parseDocument("XMLFile.xml");

I am intending to release the XMLObject code, along with any other TGB engine hacks I make that use the code, as a resource on GG's site. I'll post my progress here, and when I get a more completed version, I'll post a .plan on GG's site.

So far, all I've managed to cover is the Start and End element handlers, and the CDATA handler for the XML, my plans include to add the following:

  1. SimObject.saveXml() -- save SimObjects as XML Files rather then TorqueScript
  2. SimObject.loadXml() -- load SimObjects from XML Files, rather then exec()ing the TorqueScript
  3. Full list of SAX Methods, as made available through Expat
  4. Possibility of adding a DOM to the Code (Adding a DOM may require using yet another library, other then SAX, or a replacement to SAX that supports DOM -- but I'm going to take a look at implementing a very simple DOM using my own code, and my own XPath implementation -- just cause I wanna see how hard it'll be to do ;p)
Want to Advertise on this Site?

Multiplayer Split Screen Action

Posted in: Game Development |

I've just posted a .plan on the GG website,it makes reference to how you can easily create a 2-player splitscreen UI in a TGB game with almost no code and a simple GUI with two scene window's in it.

The .plan can be found, here

I've also posted a TGB Template Project, which can be downloaded, here

Want to Advertise on this Site?

TGB High Scores Object

Posted in: Game Development |

I was browsing the TGB TDN the other day, and noticed that there was a request for a High Scores Table article. I immediately went, "Hey, I need one of those in my game" and proceeded to code a quick HighScores object in TorqueScript. After writing the object, I decided to post a quick and dirty tutorial on how I created it, and attached the completed highScores.cs to the resource. This resource can be located here, Simple High Scores Object.

As this resource was posted under the TGB TDN, and the script object is not specific to TGB, I figured I'd post it here as well, sort of a "what I've been up to over the holiday", so here's the object:

Want to Advertise on this Site?