Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: Remove map_adjust_[xy] invocations from server (PR#10
Home

[Freeciv-Dev] Re: Remove map_adjust_[xy] invocations from server (PR#10

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Remove map_adjust_[xy] invocations from server (PR#1003)
From: Jason Dorje Short <vze2zq63@xxxxxxxxxxx>
Date: Fri, 12 Oct 2001 07:08:30 -0400
Reply-to: jdorje@xxxxxxxxxxxx

Raimar Falke wrote:
> 
> On Fri, Oct 12, 2001 at 05:40:13AM -0400, Jason Dorje Short wrote:

<snip...>

> > Upon further reflection, I really like the following change that unifies
> > check_coords with CHECK_MAP_POS.
> >
> > Though we may want to rename the function check_map_pos().  It could
> > also be made a macro, if desired.

<snip...>

> Rewrite it and change the name. However note that I'm still not sure
> if this is the way to go. check_map_pos has a function call overhead
> we don't want. So the first step in all cases is the introduction of
> CHECK_MAP_POS. We can then argue how CHECK_MAP_POS should be
> implemented and if it should segv or not.

Unfortunately, the following macro

#define CHECK_MAP_POS(x, y)         \
do {                                \
  if (!is_normal_map_pos(*x, *y)) { \
    assert(0);                      \
    if (!normalize_map_pos(x, y)) { \
      abort();                      \
    }                               \
  }                                 \
} while(0)

Does not seem like it will work inside map_inx:

#define map_inx(x,y) \
  (CHECK_MAP_POS(&x, &y), (x)+(y)*map.xsize)

There is surely some cleverness that could be done to work around this. 
Perhaps, though, the solution is to finally use an inline function?  I
believe it can be placed in map.h and function just like the macro:

static inline void check_map_pos(int *x, int *y)
{
  if (!is_normal_map_pos(*x, *y)) {
    assert(0);
    if (!normalize_map_pos(x, y)) {
      abort();
    }
  }
}

jason


[Prev in Thread] Current Thread [Next in Thread]