|
| 1 | +#include once "inc/flatmap.bi" |
| 2 | + |
| 3 | +constructor FlatMap(map_w as integer, map_h as integer) |
| 4 | + this._w = map_w |
| 5 | + this._h = map_h |
| 6 | + dim i as integer |
| 7 | + for i = 0 to MAP_WIDTH*MAP_HEIGHT-1: this._callbacks(i) = 0: next i |
| 8 | + 'redim this._walls(map_w, map_h) |
| 9 | + 'redim this._heights(map_w, map_h) |
| 10 | + 'redim this._colors(map_w, map_h) |
| 11 | +end constructor |
| 12 | +function FlatMap.walls(x as integer, y as integer) as byte |
| 13 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 14 | + return this._walls(x+((this._h-1-y) shl 10)) |
| 15 | + else |
| 16 | + return 0 |
| 17 | + end if |
| 18 | +end function |
| 19 | +function FlatMap.heights(x as integer, y as integer) as short |
| 20 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 21 | + return this._heights(x+((this._h-1-y) shl 10)) |
| 22 | + else |
| 23 | + return 0 |
| 24 | + end if |
| 25 | +end function |
| 26 | +function FlatMap.colors(x as integer, y as integer) as integer |
| 27 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 28 | + return this._colors(x+((this._h-1-y) shl 10)) |
| 29 | + else |
| 30 | + return 0 |
| 31 | + end if |
| 32 | +end function |
| 33 | +function FlatMap.callbacks(x as integer, y as integer) as sub(byref x_dx as uinteger, byref x_dy as uinteger, byref y_dx as uinteger, byref y_dy as uinteger) |
| 34 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 35 | + return this._callbacks(x+((this._h-1-y) shl 10)) |
| 36 | + else |
| 37 | + return 0 |
| 38 | + end if |
| 39 | +end function |
| 40 | +function FlatMap.datas(x as integer, y as integer, z as integer=0) as integer |
| 41 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 42 | + return this._data(x+((this._h-1-y) shl 10)+(z shl 20)) |
| 43 | + else |
| 44 | + return 0 |
| 45 | + end if |
| 46 | +end function |
| 47 | +property Flatmap.w() as integer |
| 48 | + return this._w |
| 49 | +end property |
| 50 | +property Flatmap.w(new_w as integer) |
| 51 | + this._w = new_w |
| 52 | +end property |
| 53 | +property Flatmap.h() as integer |
| 54 | + return this._h |
| 55 | +end property |
| 56 | +property Flatmap.h(new_h as integer) |
| 57 | + this._h = new_h |
| 58 | +end property |
| 59 | +function Flatmap.setWall(x as integer, y as integer, new_w as integer) as FlatMap ptr |
| 60 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 61 | + this._walls(x+((this._h-1-y) shl 10)) = new_w |
| 62 | + end if |
| 63 | + return @this |
| 64 | +end function |
| 65 | +function Flatmap.setHeight(x as integer, y as integer, new_h as integer) as FlatMap ptr |
| 66 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 67 | + this._heights(x+((this._h-1-y) shl 10)) = new_h |
| 68 | + end if |
| 69 | + return @this |
| 70 | +end function |
| 71 | +function Flatmap.setColor(x as integer, y as integer, new_c as integer) as FlatMap ptr |
| 72 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 73 | + this._colors(x+((this._h-1-y) shl 10)) = new_c |
| 74 | + end if |
| 75 | + return @this |
| 76 | +end function |
| 77 | +function Flatmap.setCallback(x as integer, y as integer, s as sub(byref x_dx as uinteger, byref x_dy as uinteger, byref y_dx as uinteger, byref y_dy as uinteger)) as FlatMap ptr |
| 78 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 79 | + this._callbacks((this._h-1-y) shl 10) = s |
| 80 | + end if |
| 81 | + return @this |
| 82 | +end function |
| 83 | +function Flatmap.setData(x as integer, y as integer, z as integer, value as integer) as FlatMap ptr |
| 84 | + if x >= 0 and x < this._w and y >= 0 and y < this._h then |
| 85 | + this._data(x+((this._h-1-y) shl 10)+(z shl 20)) = value |
| 86 | + end if |
| 87 | + return @this |
| 88 | +end function |
| 89 | +function FlatMap.getWallAvg(x as integer, y as integer, size as integer) as integer |
| 90 | + dim mx as integer, my as integer |
| 91 | + dim sum as double |
| 92 | + dim max as double |
| 93 | + for my = y to y+size-1 |
| 94 | + for mx = x to x+size-1 |
| 95 | + sum += this.walls(mx, my) |
| 96 | + next mx |
| 97 | + next my |
| 98 | + size *= size |
| 99 | + return sum / size |
| 100 | +end function |
| 101 | +function FlatMap.getHeightAvg(x as integer, y as integer, size as integer) as integer |
| 102 | + dim mx as integer, my as integer |
| 103 | + 'dim sum as double |
| 104 | + dim max as double |
| 105 | + max = -99999 |
| 106 | + for my = y to y+size-1 |
| 107 | + for mx = x to x+size-1 |
| 108 | + 'sum += this.heights(mx, my) |
| 109 | + if this.heights(mx, my) > max then |
| 110 | + max = this.heights(mx, my) |
| 111 | + end if |
| 112 | + next mx |
| 113 | + next my |
| 114 | + 'size *= size |
| 115 | + 'return sum / size |
| 116 | + return max |
| 117 | +end function |
| 118 | +function FlatMap.getColorAvg(x as integer, y as integer, size as integer) as integer |
| 119 | + dim mx as integer, my as integer |
| 120 | + dim colr as integer |
| 121 | + dim max as double |
| 122 | + max = -99999 |
| 123 | + for my = y to y+size-1 |
| 124 | + for mx = x to x+size-1 |
| 125 | + if this.heights(mx, my) > max then |
| 126 | + max = this.heights(mx, my) |
| 127 | + colr = this.colors(mx, my) |
| 128 | + end if |
| 129 | + next mx |
| 130 | + next my |
| 131 | + return colr |
| 132 | + 'dim r as integer, g as integer, b as integer |
| 133 | + 'for my = y to y+size-1 |
| 134 | + ' for mx = x to x+size-1 |
| 135 | + ' r += ((this.colors(mx, my) shr 16) and &hff) |
| 136 | + ' g += ((this.colors(mx, my) shr 8) and &hff) |
| 137 | + ' b += (this.colors(mx, my) and &hff) |
| 138 | + ' next mx |
| 139 | + 'next my |
| 140 | + 'size *= size |
| 141 | + 'return rgb(r / size, g / size, b / size) |
| 142 | +end function |
| 143 | +function FlatMap.getCallbackAvg(x as integer, y as integer, size as integer) as sub(byref x_dx as uinteger, byref x_dy as uinteger, byref y_dx as uinteger, byref y_dy as uinteger) |
| 144 | + dim mx as integer, my as integer |
| 145 | + 'dim sum as double |
| 146 | + dim s as sub(byref x_dx as uinteger, byref x_dy as uinteger, byref y_dx as uinteger, byref y_dy as uinteger) |
| 147 | + dim max as double |
| 148 | + max = -99999 |
| 149 | + s = 0 |
| 150 | + for my = y to y+size-1 |
| 151 | + for mx = x to x+size-1 |
| 152 | + 'sum += this.heights(mx, my) |
| 153 | + if this.heights(mx, my) > max then |
| 154 | + max = this.heights(mx, my) |
| 155 | + s = this.callbacks(mx, my) |
| 156 | + end if |
| 157 | + next mx |
| 158 | + next my |
| 159 | + 'size *= size |
| 160 | + 'return sum / size |
| 161 | + return s |
| 162 | +end function |
| 163 | +function FlatMap.getDataAvg(x as integer, y as integer, z as integer, size as integer) as integer |
| 164 | + dim mx as integer, my as integer |
| 165 | + 'dim sum as double |
| 166 | + dim dat as integer |
| 167 | + dim max as double |
| 168 | + max = -99999 |
| 169 | + for my = y to y+size-1 |
| 170 | + for mx = x to x+size-1 |
| 171 | + 'sum += this.heights(mx, my) |
| 172 | + if this.heights(mx, my) > max then |
| 173 | + max = this.heights(mx, my) |
| 174 | + dat = this.datas(mx, my, z) |
| 175 | + end if |
| 176 | + next mx |
| 177 | + next my |
| 178 | + 'size *= size |
| 179 | + 'return sum / size |
| 180 | + return dat |
| 181 | +end function |
0 commit comments