Archive for January, 2010

Qt Creator saves the day

January 31st, 2010

First starting with Qt, I urgently wanted to run it with the Visual Studio 2008 addin. I soon regretted this decision, as I wanted to compile a little (official) addon component. I ended up in digging through forums, since I’m not fit with console-based compilation (nmake, qmake, etc.), but in the end, I somehow managed to get it to compile.
And now, as I wanted to test it on some other computers (with no Visual Studio 2008 installed), I couldn’t manage to get the app up and running by half a day. Not even dependency-walker helped me out here…looks like VS links all kinds of not needed crap into the app (woo-hoo, what a rhyme! :D ).
So I took a short break, and remembered, that back then, in one of my University OGRE-based projects, we had the same problem – remaining unsolved (installing VS2008 redistributables didn’t help either). And then it came to me: “You want it cross platform anyway, so why not try out the Qt Creator?!“. And what should I say: installed it, compiled the addons in no time and now I can run my app on every PC…that’s sweet!

Get class and super class

January 27th, 2010

For Level Master 2000, I needed two functions:

  1. getClass, which I stuff in any kind of object, and it returns me its class.
  2. getSuperClass, which I stuff in it’s class name as string, and it returns me the class name of its parent as string.

Note that first returns the class itself, and the second one works with strings. If you need to e.g. let the second one work with classes also, just adapt it like in the first function.

All in all, you need to import these functions:

import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
import flash.utils.getQualifiedSuperclassName;

And here are the two functions:

public static function getClass(obj:Object):Class
{
	return Class(getDefinitionByName(getQualifiedClassName(obj)));
}
static public function getSuperClass(className:String):String
{
	return getQualifiedSuperclassName(getDefinitionByName(className));
}

Note that getSuperClass only returns its direct parent. If you need to go further up the inheritance tree, you need to call it recursively. Highest it can get is “Object”.

PBE Series: using SchemaGenerator

January 22nd, 2010

Previously, in PBE Series: dynamically get list of public members, properties and methods of object or class, I noted that

SchemaGenerator.instance.generateSchema();

“dumps all classes and public info to a xml file”.
We’ll, I’ve used it now, and I must admit that was a lie ;)
So here’s how you use it, and what it results in!

First, you need to establish a local connection, and then call generateSchema:

conn = new LocalConnection();
conn.client = this;
conn.allowDomain('*');
try {
	conn.connect("_SchemaConnection");
} catch (error:ArgumentError) {
	trace("Can't connect to _SchemaConnection");
}
 
SchemaGenerator.instance.generateSchema();

SchemaGenerator.instance.generateSchema will then call OnSchemaReceived in your class, so you need to add that. It takes two string arguments: type and data. Type is either “START”, “END”, “ERROR” or “TYPE”. Data is an XML description of the current processed class (internally it uses flash.utils.describeType), which you then can further interact with.
Here’s an example of how OnSchemaReceived could look like:

public function OnSchemaReceived(type:String, data:String):void
{
	switch( type )
	{
		case "START":
		break;
 
		case "END":
		break;
 
		case "ERROR":
		break;
 
		case "TYPE":
		{
			var myXML:XML = new XML(data);
			myXML.ignoreWhite = true;
 
			var xmlList:XMLList = myXML.child("factory");
 
			//Check accessors:
			for each (var acc:XML in xmlList.accessor)
			{
				//DO SOMETHING.
			}
 
			//Check public variables:
			for each (var pVar:XML in xmlList.variable)
			{
				//DO SOMETHING.
			}
		}
		break;
	}
}

That should help you getting started!

Naughty, naughty Qt Designer!

January 14th, 2010

As briefly stated in Level Master 2000 goes Qt, Level Master 2000 uses Qt now for it’s main GUI. In able to display the Flash content, it runs a QWebView. Now, I must admit I’m fairly new to Qt, and I wanted to do most of the UI with Qt Designer, as you can see right away how it will look like.
Unfortunately, if you create your WebView with Qt Designer, look up the instance in code and want to add an object to JavaScript with

webView->page()->mainFrame()->addToJavaScriptWindowObject(...)

it doesn’t seem to work!
After playing around a bit, I figured out, that if I create the instance of QWebView myself in code, it works…now I don’t yet know what I’ve done wrong exactly or what Qt Designer messes up, but problems like this cost a lot of time and more important: nerves. But on the other hand, it’s a big relief, as soon as you figured out how to work around ;)

Level Master 2000 goes Qt

January 9th, 2010

New year, new news – and this time everything is different! I’ve been through some interesting discussions with Ben Garney (one of the big guys behind PushButton Engine) regarding how to tackle a general purpose editor beast for PushButton Engine. We came to the conclusion, that we’d rather try a non flash/flex way for the UI (mainly due to possible performance problems).
One solution would have been .NET/Mono, but that didn’t convince us at a first glance. Our second approach is using Qt!
Since Flash can’t comminicate directly with Cpp/Qt, we need to do the following:

  • In Flash, we use ExternalInterface to communicate with the outside world (meaning Javascript)
  • In Qt, we run a Webview, which loads the SWF and catches the ExternalInterface calls.
  • These caught calls are then passed on to Qt

So in short, it’s like: Flash >> Javascript >> Qt and the otherway.
We’ll see how this decision turns out in the end, but it’s an interesting approach indeed (and in case of emergency, there are ways to improve performance)!

For now, I can say, that I got the basic communication working:
Level Master 2000: first Qt screen shot

It features:

  • Entity selection
  • Display the as “editable” marked properties of the selected entity, grouped by components
  • (W.I.P.)Modify the properties: numbers and strings working, custom data types (like a point) on the way

Next upcoming features:

  • Entity Browser: visualisation
  • Entity Browser: interaction (selecting entities, adding + deleting components)

Stay tuned!