Game Development Community

dev|Pro Game Development Curriculum

Commander Map

by Kyle Carter · 03/01/2004 (10:52 am) · 155 comments

Download Code File

To use this resource:

1. Copy guiCommanderHud.cc to your engine/gui subfolder.
2. Open your IDE of choice (or a text editor if that's what you like).
3. Add the source file to your project so it will be compiled into Torque.
4. Do a clean rebuild.
5. Go to the GUI of your choice and add a GuiCommanderHud to it. Poof, instant GUI!

Security and Scoping Issues:

The HUD is designed to prevent people from abusing it in-game. It does not change how anything is scoped, so people will only see what the net code would have previously allowed them to see. If you want to have a special "commander map" behavior that shows all active objects you will need to add it either via server side scripting or in GameConnection::doneScopingScene(). Remember, the best way to prevent cheating and improve net performance on your game is to only scope what people need to see.

If you're particularly paranoid, you may want to remove the ConsoleMethods at the end of the file and control the commander map with events; this is probably unnecessary in most cases, as the commander map reveals no more information than the player could get by opening a map in single player mode or a dedicated server and flying/walking around.

Panning and Zooming:

There are three useful actions you can do via scripting with the GuiCommanderHud. First, you can zoom. This basically consists of changing the FOV of the overhead camera that the view is being rendered from (see GuiCommanderHud::processCameraQuery()), so you want to stick to values between 0 and one half pi. Larger values can give "interesting" results though no value should crash the engine. The available script methods for this are zoom() to instantly set the zoom level and zoomTo() to smoothly interpolate to the requested zoom level.

pan() and panTo() let you set the x,y co-ordinates of the overhead camera - essentially setting where the center of the map is. If you wish to pan onto an object, get the first two words of its position and pass them to pan() or panTo().

There are also two exposed fields, panSpeed and zoomSpeed, which let you tweak how quickly panning and zooming occurs. Negative values for these will give catastrophic results!

Performance:

On a 1.8Ghz P4 with 512mb of RAM and a GeForce 4 440 Go (equivalent to a fast GeForce 2), I get 70fps in the test FPS level without the map on screen, and 40fps with it on the screen (in addition to the normal FPS view). Suggested usage is to run the GuiCommanderHud in its own GUI, so that you don't have the overhead of the PlayGUI and its view of the world.

The GuiCommanderHud only renders interior, terrain, water, and environmental objects. You can easily change the mask it uses for rendering the scene by editing GuiCommanderHud::renderWorld() - there is a comment to guide you. Re-enabling all DTS shapes will bring a significant performance hit, since you'll be rendering potentially all the objects in the game world!

Extensions:

There are three major areas in which the GuiCommanderHud could be extended for your game.

First, you may want to render an overlay or icons indicating where objectives/players are. There is a comment located where you would want to render these objects, in GuiCommanderHud::onRender(). Using standard DGL calls will give good results.

Second, you may want to have the control handle mouse input. Looking at EditTSCtrl (located in engine/editor/editTSCtrl.*) will be an excellent guide for this process. You could either inherit from EditTSCtrl, or copy its mouse handling code to the GuiCommanderHud. The project() and unproject() functions that GuiCommmanderHud inherits from GuiTSCtrl may also be useful here.

Finally, you may wish to optimize rendering speed by caching output to a texture, rendering only the texture, and updating the texture as needed when the map needs to change its view. (You could even render to a large texture and simply pan it around, though this would kill the neat parallaxing and depth buffering effects that you could gain from actually rendering the world into the GuiCommanderHud.) This would be a bit tricky, but GuiCommanderHud::onRender would be your starting point. Look at TSShapeInstance::snapshot() for guidance on how to implement this sort of functionality in OpenGL - beware that the DirectX layer may not place nice with this.

Usage Restrictions:

None. Knock yourself out! :) I would ask that you put my name in your credits somewhere and send me a free copy of your game if this resource is a major piece of functionality for your project, but you are by no means required to do so. I'd also appreciate it if, if you found bugs or made enhancements for the code, if you'd send me your change(s) so I can merge them back into this resource. Many eyes find more bugs. ;)

Addendums:

Neat bit of code to try from the console(replace 1494 with the SimObject you want to track). Notice my commander hud is named commHud.

commHud.zoomTo(0.02);
function panPlayer() { commHud.panTo(getWord(1494.getPosition(), 0), getWord(1494.getPosition(), 1)); schedule(100, 0, panPlayer); }
panPlayer();
Page «Previous 1 2 3 4 5 6 7 Last »
#1
03/01/2004 (11:01 am)
Love it Ben working on rending icon currently
#2
03/01/2004 (5:15 pm)
Works good, although if you have "fog" on it doesn't show much :)

What I really like about this is how it shows to add nice functionality without patching 1/2 the engine. Lock and load :)

Its great!
#3
03/01/2004 (5:30 pm)
It should be tweaking the fog pretty extensively so that you see... everything you'd see from a high view. I think it sets the fog distance to something like 2000 by default. Set it to 10k if you want. ;)

Volume fog can mess stuff up, though.
#4
03/01/2004 (5:38 pm)
Fog volume is what I have on and what I am seeing... or rather not seeing. I might look into fixing that, although its not real high on my "things to do" list. The fog volume was on for some testing.
#5
03/01/2004 (5:46 pm)
Great stuff!
#6
03/02/2004 (11:13 am)
Great Ben!! This is excellent for the World Map View. We need. I wonder could this be added to the teleporter code to give players self-teleportation. This is some good stuff!!

John H.
#7
03/03/2004 (5:11 pm)
Wow! Thank you so much.
Probably very much needed by all.
#8
03/04/2004 (4:13 pm)
Oops, Opera posted too many times..
#9
03/04/2004 (4:14 pm)
Oops, Opera posted too many times....
#10
03/04/2004 (4:14 pm)
You are the best! thank you soo much!
#11
03/07/2004 (11:05 pm)
Sorry to be such a noob at this, but I am a bit of a loss as to what file I add the guicommanderhud.cc to, and what the syntax for it. Thanks
Apart from that I think this is a really good addition to the engine.
#12
03/08/2004 (7:57 pm)
If you're using visual studio or XCode, add it to the project using the GUI. If you're using make, you'll need to add it to the makefile. Details on how to do these things can be found in the manuals for your tools.
#13
03/13/2004 (1:03 am)
Thanks Ben. The transition from VB to VC++ is slow :)
#14
04/06/2004 (5:13 am)
I have tried your map hud but i only see a map like the one in the terrain editor, it seems like a fractal bitmap....
Someone could solve my troubles?
#15
04/21/2004 (12:50 pm)
Here is something interesting. If you find you cannot get particular classes to show up unless they are in a certain range this is due to the limited scope (camera's scope). Luckily traces from T2 is left in to allow you to add additonal scoping to the gameconnection.

By default this function is empty fill it with something like this to scope everything
void GameConnection::doneScopingScene()
{
   // Could add special post-scene scoping here, such as scoping
   // objects not visible to the camera, but visible to sensors.
		   gServerContainer.findObjects(0xFFFFFFFF,scopeCallback,this);
}

note you'll need the additional scopeCallback function which was a support function found in shapeBase.cc
static void scopeCallback(SceneObject* obj, void *conPtr)
{
   NetConnection * ptr = reinterpret_cast<NetConnection*>(conPtr);
   if (obj->isScopeable())
      ptr->objectInScope(obj);
}

Enjoy
#16
06/15/2004 (8:46 am)
For some reason when I add the commhud when shooting an arrow, the arror shoots but no imaes of it shooting shows up. Any ideas?
#17
07/14/2004 (9:50 pm)
Thanks Ben,
With some wrenching I got this in.
Works with the latest HEAD (at least my hacked up version).
Awsome!
Hurts the FPS really bad though.
Kinda a toggle thing (else you get killed for lagging).
I'll wrench on this some more and see what I can do.
Nice work.
#18
07/26/2004 (3:38 pm)
I am downloading as we speak.... :) seems very usefull.. will checkit out!..

Anyway.. Nice work.! Love ppl putting resources.. my team will put ours... in a short while!.
#19
10/10/2004 (12:02 pm)
Great resource! I got it working easy and have it pan with the player.

I got a question though. How can I make the map a little transparent?

Thanks,
Nick
#20
10/13/2004 (10:54 am)
A little problem with Torque version 1.3.0:

Downloaded 1.3, built it, ran debug - no problems, no errors.

Added guicommanderhud.cc, built the debug, ran debug - when I add guicommanderhud I get a gray box. When I quit, I get the following debug error:

Fatal: (c:\torque\engine\sim\sceneobject.cc @ 825) Error, a GameBase (729b580) i
sn't properly out of the bins!

Fatal: (c:\torque\engine\sim\sceneobject.cc @ 825) Error, a GameBase (55b0f90) i
sn't properly out of the bins!

Does it work with 1.3.0?

Thanks, Joe
Page «Previous 1 2 3 4 5 6 7 Last »