| 145 | #define NOTHING_THERE 0 |
| 146 | |
| 147 | int CreateHotSpotMap(const char *map, int width, int height, hotspotmap_t *hsmap) { |
| 148 | // make sure we have a clean struct to work with |
| 149 | if (hsmap->hs) { |
| 150 | FreeHotSpotMapInternals(hsmap); |
| 151 | } |
| 152 | |
| 153 | int curr_sl, x, y, count, num_hs = 0; |
| 154 | uint8_t alpha; |
| 155 | char whats_there[256]; |
| 156 | int window_count; |
| 157 | |
| 158 | for (count = 0; count < 256; count++) |
| 159 | whats_there[count] = NOTHING_THERE; |
| 160 | |
| 161 | // Get total number of hotspots (based on highest hotspot value) |
| 162 | for (y = 0; y < height; y++) { |
| 163 | for (x = 0; x < width; x++) { |
| 164 | alpha = (unsigned)map[y * width + x]; |
| 165 | if ((alpha != NO_ALPHA) && (alpha != WRITEABLE_ALPHA) && (whats_there[alpha] == NOTHING_THERE)) { |
| 166 | if (alpha < MAX_HOTSPOTS) { |
| 167 | whats_there[alpha] = HOTSPOT_THERE; |
| 168 | if (alpha >= num_hs) |
| 169 | num_hs = alpha + 1; |
| 170 | } else { |
| 171 | whats_there[alpha] = WINDOW_THERE; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | hsmap->num_of_hotspots = num_hs; |
| 178 | if (!num_hs) |
| 179 | return -1; |
| 180 | |
| 181 | hsmap->hs = (hotspot *)mem_malloc(sizeof(hotspot) * num_hs); |
| 182 | ASSERT(hsmap->hs); |
| 183 | for (count = 0; count < num_hs; count++) { |
| 184 | if (whats_there[count] == HOTSPOT_THERE) { |
| 185 | hsmap->hs[count].starting_y = MAX_MAP_HEIGHT; |
| 186 | hsmap->hs[count].scanlines = 0; |
| 187 | } else { |
| 188 | hsmap->hs[count].starting_y = 0; |
| 189 | hsmap->hs[count].scanlines = 0; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | scanline sl_x[MAX_MAP_HEIGHT]; |
| 194 | int sl_count, last_y = -1; |
| 195 | |
| 196 | // this is to set the values of start and end initially |
| 197 | for (count = 0; count < MAX_MAP_HEIGHT; count++) { |
| 198 | sl_x[count].start = MAX_MAP_WIDTH; |
| 199 | sl_x[count].end = 0; |
| 200 | } |
| 201 | |
| 202 | // fill in hotspot info |
| 203 | // this is really nasty...MUST MAKE BETTER |
| 204 | for (count = 0; count < num_hs; count++) { |
no test coverage detected