Game Development Community

Plastic Gem #7: Marker Shape

by Paul Dana · 06/17/2008 (6:49 am) · 2 comments

Download Code File


i936.photobucket.com/albums/ad202/vincismurf/banner.jpg

Plastic Gem # 7 : Marker Shape

Difficulty: Easy

For a list of gems see the Gem A Day page.

www.plasticgames.com/dev/blog_images/gems/zombieGrid_hospital.jpgThe Zombie Grid

Gem number seven from Plastic Games introduces a very useful shape and some very useful script classes. Together they give you the ability to create flexible, scripted "marker" objects. This seems boring (and maybe it is) but we have used it for some very exciting things, such as implementing debug rendering for the Zombie Grid we use in our zombie game prototype, as depicted above. The zombie grid is a set of marker shapes placed in a mission that our script code connects into a mesh used for spawning and navigation. Each node shows how many zombies to spawn. The rings show the free spawn area around that nodes and the lines connect the nodes to show the mesh. This gem explains how we did the marker shape with the number, the rings and lines will be covered in a future gem.

You must follow the instructions in Gem #2 and Gem #5 before you can use this resource, and if you are doing that you really should likely follow Gem #3 as well..

1) Unzipping the files

After following the instructions in Gem #2 and Gem #5 (and optionally Gem #3), unzip the pg07_markerShape.zip file provided with this resource. Merge the files in the plastic folder from the .zip file with the plastic folder you created in Gem #5. There is a data folder in the plastic folder in the .zip file provided that you can just copy in as-is. There is also a server folder with a file you need to copy to the server folder you created as part of Gem #5.

2) Executing the scripts

We need to execute the digitBillboard.cs file that you copied over. Edit the plastic/server/init.cs script that you copied over in Gem #5. In the section that looks like this:

echo("--------- Initializing: Server Side Plastic Gems ---------");
//for future resources
echo("--------- Server Side Plastic Gems - Initialized ---------");

replace the line //for future resources, with this:

exec("./digitBillboard.cs");

3) Placing a Marker Shape

Place a DigitBillboardShape in the mission editor using the same steps described in Gem #1: Placeable Shapes.

www.plasticgames.com/dev/blog_images/gems/markerShape_placed.jpg4) Naming the marker
www.plasticgames.com/dev/blog_images/gems/markerShape_renamed.jpg
Let's give this marker shape a name so we can test out our utility method. Ensure that you are still in the Mission Editor and that the marker shape you just placed is still selected. Choose "World Editor Inspector" from the Window menu and you should see the fields of the marker shape displayed in the inspector window. Enter the name Marker into the name field at the top and hit the apply button. Capitilization does not matter in Torque object names.

OK great, so now we have placed a shape and given it the name "Marker". By default a marker shows no symbol at all so this is what we see:

www.plasticgames.com/dev/blog_images/gems/markerShape_0.jpg
5) Changing the Color and Symbol

Now hit the tilde key (~) to drop the Torque console and type in this command:

Marker.setDigitBillboardColorAndSymbol("blue","circle");
www.plasticgames.com/dev/blog_images/gems/markerShape_blueCircle.jpg
You should see the marker symbol change to a "circle" that is blue.

6) A digression on the practical side of development

At this point you will be saing "Hey! That ain't much of a circle; it's more like an oval...what gives?" The simple answer is we changed the shape to add another digit to the number, and this was the side effect. Jason Sharp asked me how much time he could have to update the marker shape and I said "do it as quickly as possible". He said "even if the shape is distorted and the number runs over it?". And I said "sure that's fine...we are on a deadline and we just need functional not pretty". He did the work and we have never gone back and changed it.

This illustrates another basic fact of our gems and how we develop software. Our solutions are almost never ideal. But they are good enough because we didn't stop putting effort in until the soluion was an actual solution to the problem. However at that point we often had to stop. There wasn't any time or resources to make the solution any better than this basic "good enough" cut off. You will notice this theme again and again in our gems. This is not to apologize for it - in fact we belive it is the right way to develop software: iteratively in small steps always evaluating if what you are building actaully solves the problem while actively avoiding over design.

7) Changing theNumber

Now type in this command:

Marker.setDigitBillboardNumber(17);
www.plasticgames.com/dev/blog_images/gems/markerShape_17.jpg
You should see the number change from zero to 17.

The Next Gem

That's all we have for this gem. We did not go over the code for this class in detail because the previous gem, Gem #6: Data Inheritance, and the gems you had to follow before following this one cover all the topics you need to know to understand how that code works. The marker shape blendable threads involve IFL animations instead of clock hands but the principle is exactly the same as what is shown in Gem #2.

The next gem extends this one by showing how to create an auto-naming marker shape that will use a default symbol and color of your choice. For example, let's say you create a marker datablock indicating you want a prefix of "TurretSpawn" and and a red circle as the symbol and color. This defines a placeable shape that will default to a red circle and will automatically create a name for this object of "TurretSpawn_1", unless that name is already used, in which case it uses "TurretSpawn_2". In any event the marker will show up as a red circle with the number reflecting the name of the object. This makes it super easy to look in the mission editor and see red circle with a 7 in it. You know you can refer to that as TurretSpawn_7 in your scripts.

#1
08/17/2008 (10:18 am)
I had to change the line in digitBillboard.cs
from
shapeFile = $plasticRef@"data/shapes/markers/marker_digits_v2.dts";
to
shapeFile = $plasticRef@"data/shapes/marker_digits_v2.dts";
because there is no markers path in the zip file. Other than that it worked great. Thanks for this and all the resources. I plan to implement each and every one in my prototype. Thanks again, you guys rock! :)
#2
01/07/2009 (7:33 am)
Thanks for the update joseph.