Author Topic: Location And Map_rect Macros  (Read 2692 times)

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Location And Map_rect Macros
« on: January 20, 2011, 10:18:22 AM »
While reading some older posts, I found this topic again. I remembered seeing something like that mentioned by AmIMeYet somewhere, so i searched the SDK and was surprised to actually find it:

Code: [Select]
// OP2Helper.h

#define MkXY(x,y) (LOCATION(x+31,y-1))
#define MkRect(x1,y1,x2,y2) (MAP_RECT(LOCATION(x1+31,y1-1),LOCATION(x2+31,y2-1)))
#define XYPos(x,y) x+31,y-1
#define RectPos(x1,y1,x2,y2) x1+31,y1-1,x2+31,y2-1

Maybe someone put it in there and forgot about it? However, AmIMeYet's suggestion to make it compatible for world maps is worth a thought. It could easily be done by replacing it by

Code: [Select]
#ifdef WORLDMAP

#define MkXY(x,y) (LOCATION(x-1,y-1))
#define MkRect(x1,y1,x2,y2) (MAP_RECT(LOCATION(x1-1,y1-1),LOCATION(x2-1,y2-1)))
#define XYPos(x,y) x-1,y-1
#define RectPos(x1,y1,x2,y2) x1-1,y1-1,x2-1,y2-1

#else

#define MkXY(x,y) (LOCATION(x+31,y-1))
#define MkRect(x1,y1,x2,y2) (MAP_RECT(LOCATION(x1+31,y1-1),LOCATION(x2+31,y2-1)))
#define XYPos(x,y) x+31,y-1
#define RectPos(x1,y1,x2,y2) x1+31,y1-1,x2+31,y2-1

#endif

Whew! I can hear Hoomans blood running cold.
Praise the mighty light towers!!!

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Location And Map_rect Macros
« Reply #1 on: January 20, 2011, 11:05:48 AM »
Should rather do it that way:

Code: [Select]
#ifdef WORLDMAP
#define XOFFSET (-1)
#else
#define XOFFSET (31)
#endif

#define MkXY(x,y) (LOCATION(x+XOFFSET,y-1))
#define MkRect(x1,y1,x2,y2) (MAP_RECT(LOCATION(x1+XOFFSET,y1-1),LOCATION(x2+XOFFSET,y2-1)))
#define XYPos(x,y) x+XOFFSET,y-1
#define RectPos(x1,y1,x2,y2) x1+XOFFSET,y1-1,x2+XOFFSET,y2-1

One could also make XOFFSET a global variable that is automatically set when the map is loaded. But I'm not sure if the bigger generality justifies the additional overhead.

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Location And Map_rect Macros
« Reply #2 on: January 20, 2011, 11:09:31 AM »
Thats good, I just wasn't sure since those offsets are commented out:
Code: [Select]
OP2Helper.h

// X and Y offset consts
//const int X_ = 31;
//const int Y_ = -1;
Praise the mighty light towers!!!

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1269
Location And Map_rect Macros
« Reply #3 on: January 20, 2011, 04:37:33 PM »
I don't think anyone's ever really used those macros. In the partial CCF2 source code, I had something in there that was the product of me messing around with a derived class of LOCATION called MapLocation (well, it derives from LocationEx, which is just another LOCATION derivative I made) that automatically factors in the map buffer x/y offsets, using HFL to dynamically determine what the x offset should be, though the HFL dependency could be removed fairly easily. Doing this does technically add some overhead, but it's negligible.
« Last Edit: January 20, 2011, 04:39:55 PM by Arklon »

Offline AmIMeYet

  • Full Member
  • ***
  • Posts: 128
Location And Map_rect Macros
« Reply #4 on: January 21, 2011, 09:05:43 AM »
Nice find, Flashy.

But wouldn't you have to set WORLDMAP yourself? Or is this already done somewhere? (Not that it really matters.. )

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Location And Map_rect Macros
« Reply #5 on: January 21, 2011, 10:41:02 AM »
Yes, you would have to define it yourself, but since you know the size of the map you want to use, that wouldn't be so bad.
Praise the mighty light towers!!!