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.
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();
#82
i was trying to use the resource but faced some problems while compiling it
while i added the file to my TGE and compiled it gave me certain errors which i could not getrid off
thus i request you peoples to please guide me through
here i am giving all the errors which occured
Torque Lib error PRJ0019: A tool returned an error code: "Performing Custom Build Step"
buildWad fatal error LNK1181: cannot open input file 'engine_DEBUG.lib'
map2dif plus fatal error LNK1181: cannot open input file 'engine_DEBUG.lib'
Torque Demo error PRJ0019: A tool returned an error code: "Performing Custom Build Step"
map2dif fatal error LNK1181: cannot open input file 'engine_DEBUG.lib'
if anyone of you could figure out how and why these errors are coming and could guide me in getting rid of them i would really appreciate that
thanking you
12/07/2006 (4:38 am)
hi everyonei was trying to use the resource but faced some problems while compiling it
while i added the file to my TGE and compiled it gave me certain errors which i could not getrid off
thus i request you peoples to please guide me through
here i am giving all the errors which occured
Torque Lib error PRJ0019: A tool returned an error code: "Performing Custom Build Step"
buildWad fatal error LNK1181: cannot open input file 'engine_DEBUG.lib'
map2dif plus fatal error LNK1181: cannot open input file 'engine_DEBUG.lib'
Torque Demo error PRJ0019: A tool returned an error code: "Performing Custom Build Step"
map2dif fatal error LNK1181: cannot open input file 'engine_DEBUG.lib'
if anyone of you could figure out how and why these errors are coming and could guide me in getting rid of them i would really appreciate that
thanking you
#83
But alas, here is where it dies:
c:\torque\sdk\engine\gui\controls\guicommandermap.cc(9) : fatal error C1083: Cannot open include file: 'atlas/atlasInstance.h': No such file or directory
and
BSCMAKE: error BK1506 : cannot open file '..\engine\out.vc8.debug\guicommandermap.sbr': No such file or directory
I'm using MS Visual Studio 2005 C++.
12/18/2006 (1:36 pm)
ACtually I too have not been able to compile this add-on at all.... everything is added correctly - I even got the converted version of Shannon's.But alas, here is where it dies:
c:\torque\sdk\engine\gui\controls\guicommandermap.cc(9) : fatal error C1083: Cannot open include file: 'atlas/atlasInstance.h': No such file or directory
and
BSCMAKE: error BK1506 : cannot open file '..\engine\out.vc8.debug\guicommandermap.sbr': No such file or directory
I'm using MS Visual Studio 2005 C++.
#84
12/18/2006 (2:22 pm)
Have you tried making sure that the requested header file exists? (If you have TGE, you don't have Atlas.)
#85
Since the New 1.5 includes the TSE version, maybe I should start there........
12/18/2006 (3:01 pm)
Oh - I C - let's see what that does.....Since the New 1.5 includes the TSE version, maybe I should start there........
#86
Here's the TGE 1.5 Code that needs to be changed.
#include "gui/core/guiTSControl.h"
#include "gui/core/guiCanvas.h"
#include "core/frameAllocator.h"
#include "gui/controls/guiMLTextCtrl.h"
//-----------------------------------------------------------------------------\\
The Original doesn't account for them being 1 more layer deep :)
12/18/2006 (3:30 pm)
Yes - there it is.... compiled and running....Here's the TGE 1.5 Code that needs to be changed.
#include "gui/core/guiTSControl.h"
#include "gui/core/guiCanvas.h"
#include "core/frameAllocator.h"
#include "gui/controls/guiMLTextCtrl.h"
//-----------------------------------------------------------------------------\\
The Original doesn't account for them being 1 more layer deep :)
#87
03/28/2007 (12:40 pm)
Does anyone have confirmed TGE 1.5-working code for displaying dots / bitmaps for players / objects in a radar-esque fashion? No matter what combination of GL commands I include after the comment in onRender(), I get nothing. No errors, no crashes, but no new pixels either. Any help would be greatly appreciated.
#88
04/14/2007 (4:39 pm)
@Jay - I've got code working for drawing dots for player positions, I'm new to Torque so the code is a little messy at the moment, just cleaning up & commenting the code and I'll paste it here for everyone to use after I'm done
#89
Edit: Jay, You could alternatively check out the guiRadarCtrl to draw dots (GL).
04/23/2007 (9:05 am)
Sweet works great even in TGEA v1.0 (after making Shanon's changes)Edit: Jay, You could alternatively check out the guiRadarCtrl to draw dots (GL).
#90
Do I have to add it to playGui.gui (maybe because it's using the GameTSCtrl)?
04/23/2007 (11:35 am)
Has anyone tried to add this to an other GuiControl than Playgui? I'm getting a black screen.Do I have to add it to playGui.gui (maybe because it's using the GameTSCtrl)?
#91
04/23/2007 (2:53 pm)
The only problem with this resource is that it doesn't work under TGEA 1.0 ATLAS. Although Shannon's code works a little bit, the screen freezes with a bunch of Atlas chunk errors in the console.
#92
04/23/2007 (11:25 pm)
I dont have a terrain, so maybe I spoke too soon, sorry.
#93
EDIT: Nevermind, I think my problem is the fact that there is no Terrain. It uses the Terrain Box to set the visibleDistance, FogDistance, where the camera is, to determine Farplane and near plane. Will try to use MissionArea for this.
04/25/2007 (12:09 am)
Sorry for all the questions, but has anyone gotten player icons/images drawn (using GFX->drawBitmap) in TGEA?EDIT: Nevermind, I think my problem is the fact that there is no Terrain. It uses the Terrain Box to set the visibleDistance, FogDistance, where the camera is, to determine Farplane and near plane. Will try to use MissionArea for this.
#94
In fact... Me drawing anything (Text, Bitmaps) manually in the middle of the screen just does not show up. I dunno anymore, I've wasted a whole weekend on this... pls help!
05/01/2007 (8:35 am)
Okay I've tried over and over... and failed. I'm starting to think that GFX->drawBitmap can't be used to get Icons (bitmaps) on the screen when using this control. They just dont get drawn for some reason. In fact... Me drawing anything (Text, Bitmaps) manually in the middle of the screen just does not show up. I dunno anymore, I've wasted a whole weekend on this... pls help!
#95
05/01/2007 (9:54 am)
Have you made sure your Zwrite and test is disabled and that you're drawing after the commander map does its stuff? Have you tried using GLIntercept (if you're using TGE) or PIX (if you're using TGEA) to see what each draw command is doing? GLIntercept in particular has a nice mode where you can have it capture a single frame, and take a snapshot after every draw command - easy to see if stuff is getting covered up or just never drawn at all.
#96
I'm using TGEA. So to I'm using GFX->setZEnabled(false); and GFX->setZWriteEnabled(false); Dunno what the command is for the TEST you're pointing out?
I'm definately drawing it after the Commander map, which means I'm doing all my drawing after Parent::onRender(offset, updateRect);
Never used the any DirectX tools... Quickly tested PIX and it looks cool. Will give it a bash and see if I can figure out how it works
05/01/2007 (1:09 pm)
Hey Ben.I'm using TGEA. So to I'm using GFX->setZEnabled(false); and GFX->setZWriteEnabled(false); Dunno what the command is for the TEST you're pointing out?
I'm definately drawing it after the Commander map, which means I'm doing all my drawing after Parent::onRender(offset, updateRect);
Never used the any DirectX tools... Quickly tested PIX and it looks cool. Will give it a bash and see if I can figure out how it works
#97
PIX is a good tool; read the tutorial and go to town!
05/01/2007 (3:00 pm)
setZEnable is the one I meant.PIX is a good tool; read the tutorial and go to town!
#98
Compilation was succesful and i add these line on PlayGui :
new GuiCommanderHud(commHud) {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "244 132";
Extent = "247 220";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
cameraZRot = "0";
forceFOV = "0";
panSpeed = "10 10";
zoomSpeed = "1";
};
I'm d'ont see the problem , is someone have an idea?
Thx for help in advance
oxi
05/01/2007 (3:01 pm)
I work with TSE 1.0.1 and have a black map... Compilation was succesful and i add these line on PlayGui :
new GuiCommanderHud(commHud) {
canSaveDynamicFields = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "244 132";
Extent = "247 220";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
cameraZRot = "0";
forceFOV = "0";
panSpeed = "10 10";
zoomSpeed = "1";
};
I'm d'ont see the problem , is someone have an idea?
Thx for help in advance
oxi
#99
However -- there are still MAJOR ISSUES with this code and when using Atlas. It works but it produces errors repeatedly in the console regarding invalid chunks or something. It's not Atlas-friendly at all.
And it's not just the errors, it's the constant refreshing it's doing to display Atlas on the map. Not sure what's causing it, but it reduces FPS down to 4 when viewing the Commander Hud. Causes your screen to be "choppy", etc.
05/01/2007 (5:34 pm)
Chris, I was getting that too because I was using Atlas. But I added the AtlasObject check in the code and it worked.However -- there are still MAJOR ISSUES with this code and when using Atlas. It works but it produces errors repeatedly in the console regarding invalid chunks or something. It's not Atlas-friendly at all.
And it's not just the errors, it's the constant refreshing it's doing to display Atlas on the map. Not sure what's causing it, but it reduces FPS down to 4 when viewing the Commander Hud. Causes your screen to be "choppy", etc.
#100
Do you know an other patch for a mini-map ? else can you give me the method to add AtlasObject check ? I'm a french noob so it is difficult lol :)
I think i will read all Altas's documentation and try to resolve issue. But effectively , i have seen some flicking outside of the gui.
Is there a big differrence between Atlas and old terrain support ?
05/02/2007 (1:03 am)
Thx for your help Andy,Do you know an other patch for a mini-map ? else can you give me the method to add AtlasObject check ? I'm a french noob so it is difficult lol :)
I think i will read all Altas's documentation and try to resolve issue. But effectively , i have seen some flicking outside of the gui.
Is there a big differrence between Atlas and old terrain support ?

Jyan Smithy
Pimp
Lol thanks a lot =) It explains why there is only one resource for this that you don't have to pay for on Torque, because this is all you need =)
Also, thanks Dreamer for the updates on this!