Game Development Community

dev|Pro Game Development Curriculum

Plan for Justin "avon Lady" Dujardin

by Justin DuJardin · 04/03/2005 (11:04 am) · 7 comments

So what's the result of all this experimenting? Well, first I decided that I needed to indulge my uncontrollable need for having a tree view control that can contain any information, much like windows, so i sat down and took a look at the TreeViewCtrl that the GuiEditor uses to display GUI hierarchies. Unfortunately this control was aimed specifically at handling SimSet's and didn't leave any room for interpretation beyond that!

This is quite the pickle, or was as the case may be. So what did I do? Well, being the massochistic guy that I am, I decided that I would completely redesign the TreeViewCtrl and make it support any number of things! This was not so easy a task as I had initially hoped, but in the end I think it payed off rather well. Let's take a look at our new TreeViewCtrl in action!


www.team5150.com/~av0n/openfiletree.jpgHere we see that our Open File dialogs now sport a nifty windows Explorer-esque directory browsing tree on the left side instead of that pesky drop down that used to be there, hopefully making it easier on people that use editors when they need to open a file!

www.team5150.com/~av0n/savefiletree.jpgAnd because you can't have an open without a save, here's our save dialog in action, getting ready to save with the best of 'em!

Well hey, that's kinda cool, but what if I'm just a scripter and want to make use of this new control that you came up with? No problem! Because I too have been in such a situation (not having source access or not wanting to recompile a binary) I designed the TreeView control so that it can be used not only from in engine source, but you can use and fill a tree with anything you like from in script, which it so happens that both of those dialogs are done with. Let's take a look at the functionality of adding a new Node to our Tree in code and script, and see how they work!

First adding a node in source
// Let's create a new root node
  TreeNode *Node = new TreeNode();
  if ( Node != NULL )
  {
    Node->text = StringTable->insert("My TreeView Root");
    Node->imageIndex = 1;
    Node->selImageIndex = 1;
    insert( NULL, Node );
  }
  // How about a child?
  TreeNode *child = new TreeNode();
  if ( child != NULL )
  {
    child->text = StringTable->insert("Child of Hello World!");
    child->imageIndex = 2;
    child->selImageIndex = 1;
    insert ( Node, child );
  }

as you can see, in code it's fairly straight forward, you allocate a new TreeNode object set it's attributes then tell the tree to insert it, with the first parameter being the parent node to attach it to. Of note is that the Node's are new'd with no corresponding delete at the end of the function. The tree will handle freeing memory associated with it's nodes when they are removed.

Ok that's cool and all, but where's the part about scripters? Let's just have a look at that for a moment.

// let's create a root node, we'll use '/' because we want it to represent the 
    // root of our directory tree
    %root = new TreeNode();
    %root.text = "/";
    %root.ImageIndex = 2;
    %root.SelImageIndex = 1;
    %root.ExpandedImageIndex = 1;
    directoryList.InsertItem( 0, %root );

    // new let's go ahead and add the common folder manually for demonstrative purposes without actually verifying it exists
    %common = new TreeNode();
    %common.text = "common";
    %common.imageIndex = 2;
    %common.selimageindex = 1;
    %common.expandedImageIndex = 1;
    directoryList.InsertItem( %root, %common );

As you can see the scripting and code both function the same way more or less. Now you may be wondering what all this imageIndex, selImageIndex, and expandedImageIndex are. Well that's another good question! Once again, being the hardcore windows GUI fan that I am, I decided to make the functionality of this tree support node Images. I did not want to however hardcode any image information into the control so I wrote a helper class that attempts to emulate the function of windows ImageList control.

The ImageList is not really so much a control in here as it is a helper class for Gui controls and scripts alike that would like to hold an array of textures for quick reference to from in code and in script. Let's take a look at the construction of the image list for our file browsing dialogs

First we want to create the new ImageList object to hold the textures, which of note is that unlike the Win32 ImageList, GuiImageList can hold any number of textures of any sizes. After we've created our ImageList we'll go ahead and call Clear just to be safe.
%DirImageList = new GuiImageList();
  %DirImageList.Clear();

Well now we have an imagelist, but we want some graphics to reference from it, so let's go ahead and insert our folder graphics and get their indexes. As it happens, since we know that we are starting from an empty list, i've gone ahead and noted their indexes will be 1 and 2 in the order in which they were inserted. There are other ways of retrieving the image index such as lookup by texture path.
// our first insert will return index 1 but we know this so we just assume
  %DirImageList.insert("common/ui/folder");
  // next we insert our closed image
  %DirImageList.insert("common/ui/folder_closed");

  // Once we've create our image list and filled it with the images we want, it's as easy as assigning the image list to our tree view control!
  directoryList.ImageList = %DirImageList;

Now we've created a tree, added nodes, and associated an imagelist with it, looks like we're good to go!


Phew, that was a long rant, but there's still more! After having completed the TreeView control I decided it would be a good idea to get acquainted with the other technologies i'll be working with over the summer, so I went ahead and dove into T2D next.

What a fantastic engine, making game development short and simple, while making the visual appearance amazing through the use of high resolution sprites and amazing particle effects, by and far the best 2D engine I've seen to date.

All the fanboy ranting aside, this was quite an interesting day or two of exploring this new neat toy. But what to play with? Luckily for me I'm never out of things I'd 'like to do' unfortunately some end up not getting alotted enough time and just wither and die; Not the case with T2D! So I needed to get used to the engine and it's inner workings as well as learn to use it for development of games, call me a nut for knowledge so I decided that I would attempt to create a small game myself.

A day later and a headache's worth of taking physics equations and translating them into code I have now the basic physics necessary for my recreation of the ever so addictive Scorched Earth game! The projectile physics were a bit tricky because the engine had no real support for accelerations ( mostly worried about gravity ). So I hacked in some basic gravitational support into my sceneobjects which I applied ever so carefully to only the projectiles, and worked a bit with that to come up with this beauty of projectile motion with objects being acted on by gravity. Let's check it out below!
www.team5150.com/~av0n/projectilemotion.jpg
And that's where I am today, having wasted most of my weekend doing fun stuff instead of doing ym calculus and studying for my exams, i'm now faced with an entire days worth of homework and a desire to post a plan instead of doing it :)

Until next time

#1
04/03/2005 (11:46 am)
Excellent plan, strange how these things work out Zachary Zadell (a GG intern) posted a .plan (www.garagegames.com/blogs/37827/7482) recently and he is also working on a new TreeViewCtrl. Is improving treeview controls some type of initiation test for GG interns? :)

How did you approach rotating the rocket based on the effects of gravity?
#2
04/03/2005 (11:53 am)
Russell - It was just a complete coincidence that zach and I both were working on TreeView controls, his is very impressive I've seen it, mine was more of a foolin' around kind of thing to get back into the GUI coding mindset for when i Intern.

Rotating the rocket wasn't all that difficult. First I calculate the angle that the cannon was aimed by getting it's rotation and normalized the angle for my needs. Then I calculated how long the projectile would be in the air and took the angle i needed to rotate to be facing downward in that amount of time which gave me distance/time which i used for the angular velocity.
#3
04/03/2005 (11:56 am)
Nice to see you back in action, Justin!
#4
04/03/2005 (3:01 pm)
That looks super sexy, nice work
#5
04/03/2005 (9:57 pm)
Hey Justin, nice work on that file browser :). I am looking forward to this summer when you come over for your internship.
#6
04/25/2005 (3:22 pm)
Justin, you rock man. Can't wait till you get out here. :)
#7
06/22/2005 (9:57 pm)
@Justin
1. Is the GuiImageList a function you created or something in TGE 1.4? I don't see it in the 1.3 code.
2. I asume I can read a directory of images and load them in the list for later display in a scroll window. is this right?

Thx man. I really envy you can spend your summer at GG.