Openkore.com

OpenKore Forums
It is currently 19 Oct 2019, 10:27

All times are UTC - 5 hours [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: r6655 | bug in generation of .dist | XS / C++ expert needed
PostPosted: 26 Jan 2009, 11:56 
Offline
Super Moderators
Super Moderators
User avatar

Joined: 06 May 2008, 12:47
Posts: 801
Diagnostics
Utils::old_makeDistMap generates a usable .dist from the fld2 (edge fix included) so its not fld2 specific. (for the non believers)

To confirm the actual bug i have made a fld2 file with walkable blocks and non walkable blocks swapped as if it were a fld1 file (edge fix not applied).
(walkable block [fld1:0], [fld2:1])
The outcome was exactly the same .dist file as fld1 -> dist, wich is normal.
Tho, when you do a normal fld2 -> dist (with the needed changes in the makeDistMap cases for walkable),
the outcome is different, wich is not normal.
Walkable / non-walkable blocks stay the same. So the dist isn't supposed to change.


Practically
data[i] == 3
(walkable water [fld1:3]) is somehow never true when the rawMap has a 3 on index i.
(this goes for every number but 0)

data[i] == 0
This , unlike the previous, is true when the rawMap has a 0 (walkable block [fld1:0]) on index i.

Cause
Why is only 0 recognized? (and not 1, 2, 3, ...)
Is this because of a mismatch between datatypes?
Could anyone with knowledge of .xs take a look at this?
Because that is the only thing thats stopping us from using the new fld2 format.

The best would be doing a bitwise AND operation on data[i] with 1,
wich will return 0 when the block is not walkable and 1 when it is walkable.

snippet with relevant code (src\auto\XSTools\misc\fastutils.xs):
Code:
SV *
makeDistMap(rawMap, width, height)
   SV *rawMap
   int width
   int height
INIT:
   STRLEN len;
   int i, x, y;
   int dist, val;
   unsigned char *c_rawMap, *data;
   bool done;
CODE:
   if (!SvOK (rawMap))
      XSRETURN_UNDEF;

   c_rawMap = (unsigned char *) SvPV (rawMap, len);
   if ((int) len != width * height)
      XSRETURN_UNDEF;

   /* Simplify the raw map data. Each byte in the raw map data
      represents a block on the field, but only some bytes are
      interesting to pathfinding. */
   New (0, data, len, unsigned char);
   Copy (c_rawMap, data, len, unsigned char);
   for (i = 0; i < (int) len; i++) {
      // 0 is open, 3 is walkable water
      switch (data[i]) {
      case 0:
      case 3:
         data[i] = 255;
         break;
      default:
         data[i] = 0;
         break;
      }
   }

_________________
One ST0 to rule them all? One PE viewer to find them!
One ST_kRO to bring them all and in the darkness bind them...

Mount Doom awaits us, fellowship of OpenKore!


Last edited by Technology on 29 Jan 2009, 07:28, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: r6655 | bug in generation of .dist
PostPosted: 27 Jan 2009, 01:28 
Offline
OpenKore Monk
OpenKore Monk

Joined: 04 Apr 2008, 10:10
Posts: 474
Our .xs is just C++ (or was it C) that have perl bindings. You can treat it just like any other C/C++ code.

I'll look into that a bit later.

_________________
Got your topic trashed by a mod?

Trashing topics is one click, and moving a topic to its proper forum is a lot harder. You expend the least effort in deciding where to post, mods expend the least effort by trashing.

Have a nice day.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group