RadarHandler::RadarMap

RadarHandler::RadarMap

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
Kelson
Posts: 76
Joined: 29 Oct 2005, 08:32

RadarHandler::RadarMap

Post by Kelson »

I was trying to test the radar coverage of areas and, I'm guessing, I'm accessing the contents out of order, but I keep receiving impossible results.

Conversion: World <x,y,z> <==> Radar <x/8,y/8>
Indexing: World <x,y,z> ==> Radar[(y*width + x)/8]

(Note: The radar is 1/8 the resolution of the world map)

What I tried doing was spitting the radar to a text file, coordinate by coordinate, to see if it the coordinates were different than I expected. The result was somewhat stunning - on comet catcher and with only 2 comms in the game, I found 6 islands of non-zero (large, contiguous chunks) and various streaks of non-zero data values for a single player. When moving the radar source (commander), there was clearly a change in several of these islands in a similar direction, but not all of them. Below is essentially the radarmap transcribing code:

Code: Select all

int height = cb->GetMapHeight();
int width  = cb->GetMapWidth ();
int cells  = (height*width)/8;

const unsigned short *radar = cb->GetRadarMap();

ofstream output("radar.txt");
output << "Height = " << height << endl
       << "Width  = " << width  << endl
       << "Cells  = " << cells  << endl;

for(int a=0;a<cells;a++)
{
  output << radar[a];
  if(!(a%(width/8)) output << endl;
}
Could someone tell me what I'm doing wrong here? Why am I seeing multiple non-zero values? I checked the radarHandler.cpp code and, with only one commander, I should only see 0s and 1s, not the 11+ values I'm seeing. Perhaps this is the correct result - if so, why are there several islands of non-zero in the data when I only have a single radar operating (the one in my commander)?

Edit: Figured it out. I was over-running the bounds of the array in a hardcore way. cells should be (height * width) / 64, not /8. I wonder what other array I was reading....
Last edited by Kelson on 21 Jan 2006, 10:06, edited 1 time in total.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

"Radar[(y*width + x)/8]" should be "radar[(y*width/8 + x)/8]"?
Kelson
Posts: 76
Joined: 29 Oct 2005, 08:32

Post by Kelson »

Problem Solved.

(Expect a math minor to fail miserably and say x/A * y/A = x*y/A...yay!)
greenail
Spring Developer
Posts: 80
Joined: 13 Dec 2005, 20:16

Post by greenail »

I'm trying to document how simple things are accomplished at http://taspring.clan-sy.com/wiki/Greena ... ove_a_unit, perhaps you can add some content, or perhaps we should make the HowTo a seperate page.
Post Reply

Return to “Engine”