Layout Checker Algorythm [r-speeds]

OlljOllj our themepark-stalking nightmare Fade Join Date: 2002-12-12 Member: 10696Members
edited March 2003 in NS General Discussion
<div class="IPBDescription">Lots of text</div> What about the idea of making a "layout r-speeds checker".
All this tool does is reading a 2-color gif/bmp of a map overview (white = wall, black = path) to see if there would be places with bad r_speeds (if the map would be plain).
After reading a B&W map Layout that tool draws out 2 pictures:
1) This picture shows "r_speed performance" of every point shown by the color of this point (red = bad r_speed performance, green = average , blue = close to 0.
2) This picture shows the 10 "longest straigt lines of sight" (througth long corridors and "L shapes" that should be "U shapes").

1:
lets define "r_speed performance":
Its not the ingame r_speeds because I dont want to (and cant) transfer the way VIS works onto a 2D layout.
Its just the max amount of room that you can see from a point in a 180° field of view (VIS checks a 180° field of view).

The algorythm:
go through the whole bitmap and check each point if its black (room) or white (wall):
If its black send 8 "mayor scanning rays" from this point and continue trought black space till they hit a white wall (or the picture border wich gives an "leak error" <!--emo&:)--><img src='http://www.natural-selection.org/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo--> )
(see pic 1, I mean the blue lines only)
Store their length (trigonometry)
if length of diagonal ray > 0 ->> make 1 more ray in between of the blue ones (red lines)
if length = 0 ->> notice a "wall" (you dont expect a higher r_speed when you look to a wall, we just care for wider open fields of view)
Now lets group the rays between the walls because our field of view is 180°, not 360° and not a thin ray.
a group of 9 rays = 180° field of view.
A "wall" splits "groups of rays" into smaller groups.
if the group is <=9 sum up the length of the rays to a "group length" the "group length" is relative to the room that you see from this point (!!!) (in this case you will see 2 walls (90° left and 90° right side) when you stand there)
if the group is > 9 split the group in each possible group of 9 Rays . We just want to know the highest possible r-Speed performance.)
Example:
if there is no "wall" you have 16 Rays and 16 possible 180° fields of view. if the group is 15 rays big you have 7 possible full 180° views without seeing a wall. 14 -> 6 , 13 -> 5 ...
- Now compare all the "group length`s" of this point. we just care for the longest, and store it by the coordinate of this point.
(now we have the longest "group length" of each black point of the map)
- Now search the longest "group length" of all points and set that as 100%.
- Now set 100% = red , 50% =blue , 0% = green ...
A rainbow that shows the "max group lenghts" of all points relative to the longest "max group length"
Draw each "max group length" color on each black point.
Done.
-> red places show you places were you can exect high r_speeds.

2:
lets define "longest straigt lines of sight".
Its the longest straight line that can go from one wall to another.

This is simular to "1" but now we scan the whole map in "world rays" instread of scanning from one point.
A world ray is just one ray that goes straight thought the world without getting stopped.
Groups of "world rays" cover the whole map with the same angle (parallel)
Pic 2 shows 12 groups of world rays (a world way is red, green or blue) scanning in 12 different angles.
you can try more smooth angle-steps of course...
Now make 10 variables for a top 10 to remember length and the 2 wall points of the 10 "longest straigt lines of sight".
For each angle of world rays check each single world ray when it hits 2 wall points (white) with a room point (black) between it.
calculate the length of a world ray (trigonometric with its angle) and put it in the top 10 if its long enough.
When each single ray of all angles is checked your top 10 is finished.
Now draw the 10 lines reading start and end point and do rainbowcolor(relative length like in "1") from the top 10.
-> you directly see the 10 longest lines of sight and their lenght (red = longest)
The advantage of "2" is that its more absolute than "1".
Making more smoother angles makes it take longer, but gives way better results.

Comments

  • OlljOllj our themepark-stalking nightmare Fade Join Date: 2002-12-12 Member: 10696Members
  • LegionnairedLegionnaired Join Date: 2002-04-30 Member: 552Members, Constellation
    Alright, i'm a C++ noob, but I think it'd be pretty easy to do. I'm thinking a 2-bit bitmap. If black, value of pixel=1, otherwise, =0. Then you use a crapload of for loops to check for adjoining hallways... once you get past a certain point, it starts going exponentially. Then you just find a way to color-code the map. I could probably write the algorithm, given a 2D array, but I have no idea how to compile/Decompile a bitmap like that.

    However, a lot of R_Speeds are vertical detail anyway, but it'd still be better then nothing.
  • HOBHOB Join Date: 2002-11-02 Member: 3930Members
    looks like someone is trying to show off what they learned in computer science class.
    and why would you check the r_speeds for a 3d map with a 2d bitmap?
  • ZelZel Join Date: 2003-01-27 Member: 12861Members
    well i could tell you how to decode the bitmap, first of all it sounds like there is a program to take a top down picture of a map, then do some photo editing and it wouldnt be difficult to make it black and white, save it as a low quality bitmap, then look up bitmap file structure, its basically jsut a header, a pallate, then bytes of each palate value.

    i ahve no idea what r_speeds are or what the loops youre talking about mean, but bitmap file structure is no problem.
  • LegionnairedLegionnaired Join Date: 2002-04-30 Member: 552Members, Constellation
    <!--QuoteBegin--Zel+Mar 5 2003, 10:36 PM--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Zel @ Mar 5 2003, 10:36 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> well i could tell you how to decode the bitmap, first of all it sounds like there is a program to take a top down picture of a map, then do some photo editing and it wouldnt be difficult to make it black and white, save it as a low quality bitmap, then look up bitmap file structure, its basically jsut a header, a pallate, then bytes of each palate value.

    i ahve no idea what r_speeds are or what the loops youre talking about mean, but bitmap file structure is no problem. <!--QuoteEnd--> </td></tr></table><span class='postcolor'> <!--QuoteEEnd-->
    Sweet, can you PM me with reference links on how to do it? That'd be great, thanks. I'll work on it during class tomorrow, I've finished everything I need for the week anyway.
  • OlljOllj our themepark-stalking nightmare Fade Join Date: 2002-12-12 Member: 10696Members
    edited March 2003
    <!--QuoteBegin--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> </td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->i have no idea what r_speeds are or what the loops youre talking about mean, but bitmap file structure is no problem. <!--QuoteEnd--></td></tr></table><span class='postcolor'><!--QuoteEEnd-->
    For me its the other way around.

    <!--QuoteBegin--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> </td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->
    R_speed:
    Redraw or refresh speed.
    Commonly used for the wpoly count only, as in: "What are your r_speeds?"
    Although really it also includes many other factors such as: transparencies, epolys & sprites.
    R_speeds affects lag and fps.
    <!--QuoteEnd--></td></tr></table><span class='postcolor'><!--QuoteEEnd-->
    r_speeds are high when you see much of the map in HL -> This causes less fps and lag.

    This should be in the mapping forum, my fault.
  • ZelZel Join Date: 2003-01-27 Member: 12861Members
    edited March 2003
    if you can interpret the VB, here is a basic 8bit BMP format:
    <a href='http://rookscape.com/vbgaming/tutR.php' target='_blank'>http://rookscape.com/vbgaming/tutR.php</a>

    heres the same thing written from the java point of view:
    <a href='http://www.javaworld.com/javaworld/javatips/jw-javatip60.html' target='_blank'>http://www.javaworld.com/javaworld/javatip...-javatip60.html</a>

    heres microsoft's version, reading HEX:
    <a href='http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_4v1h.asp' target='_blank'>http://msdn.microsoft.com/library/default....itmaps_4v1h.asp</a>

    they look quite similar, so any information that one is missing you should be able to glean from the other two links.

    (sorry if i am insufficiently helpful, i havent done any programming in about two years, at which point i was writing VGA games on my 386)
  • OlljOllj our themepark-stalking nightmare Fade Join Date: 2002-12-12 Member: 10696Members
    Can someone make such a tool?
  • LegionnairedLegionnaired Join Date: 2002-04-30 Member: 552Members, Constellation
    I'll give it a whirl.. The algorithm should work fine, but I'm not sure about the functions and other ins and outs of C++. I'll see what I can do.
  • CageyCagey Ex-Unknown Worlds Programmer Join Date: 2002-11-15 Member: 8829Members, Retired Developer, NS1 Playtester, Constellation
    Leg, lemme know if you'd like a hand with a specific part of it... sounds like an interesting project <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo-->
  • JedediahJedediah Join Date: 2003-01-27 Member: 12847Members
    To test the visibility from a point, you have to cast rays in all directions, not just 8. VIS does this (I assume) by casting rays to the corners of portals and other polygons. Since you are using a downsampled bitmap image, this can't be done accurately. I think to make this work you would need your layout defined with line segments which have the exact relative lengths of your final map.
  • OlljOllj our themepark-stalking nightmare Fade Join Date: 2002-12-12 Member: 10696Members
    edited March 2003
    I choosed a SIMPLE max-vis-space aproximation and dont think a more accurate would make much sense.
    Feel free to use any more accurate Algorythm to approximate the max-visible-space in 180°.
    But dont take this way of "r_speed"-pre-testing (with just a small 2D bitmap) too serious.
  • LegionnairedLegionnaired Join Date: 2002-04-30 Member: 552Members, Constellation
    OK, i just searched around for something to get started on. I just realized I'm sub-n00b at this, so I'm going to cry in the corner now. Now, if someone wants to write up something that will turn a 24-bit .BMP into a 2-D array of RGB codes, I'll happily do the rest, but I'm pretty much clueless beyond that. Sorry I can't be of more help.
Sign In or Register to comment.