1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
|
TEXTURES
--------
BASIC TEXTURES, THAT MUST EXIST WITH GIVEN NAMES (INCLUDING DIRECTORIES)
------------------------------------------------------------------------
Following the description as in Code:
Routine "load_basic_textures"
Textures for the particle system:
txTexture[0]: "basicdat/particle.bmp"
Textures for walls and bottom:
txTexture[1]: "[module]/gamedat/tile0.bmp"
txTexture[2]: "[module]/gamedat/tile1.bmp"
txTexture[3]: "[module]/gamedat/tile2.bmp"
txTexture[4]: "[module]/gamedat/tile3.bmp"
Water textures:
txTexture[5]: "[module]/gamedat/watertop.bmp"
txTexture[6]: "[module]/gamedat/waterlow.bmp
Phong map:
txTexture[7]: "[module]/gamedat/phong.bmp"
THE MESH
--------
The mesh is a description of the whole maze. The maximum size is 64 by 64 tiles.
A tile in EGOBOO is called a "FAN".
The type of the file is controlled by the first four bytes.
Must be MAPID 0x4470614d // The string... "MapD"
Limits:
MAXMESHFAN (512*512) // terrain mesh size
MAXMESHSIZEY 1024 // Max fans in y direction
BYTESFOREACHVERTEX 14 // 14 bytes each
MAXMESHVERTICES 16 // Fansquare vertices
MAXMESHTYPE 64 // Number of fansquare command types
MAXMESHCOMMAND 4 // Draw up to 4 fans
MAXMESHCOMMANDENTRIES 32 // Fansquare command list size
MAXMESHCOMMANDSIZE 32 // Max trigs in each command
MAXTILETYPE 256 // Max number of tile images
MAXMESHRENDER 1024 // Max number of tiles to draw
FANOFF 0xffff // Don't draw the fansquare if tile = this
OFFEDGE 0 // Character not on a fan ( maybe )
The mesh is loaded from file "[module]/gamedat/level.mpd" with
the Routine "load_mesh(char *modname)"
Variables used:
unsigned int numfanblock = 0; // Number of collision areas
unsigned short meshbumplistchr[MAXMESHFAN/16]; // For character collisions
unsigned short meshbumplistchrnum[MAXMESHFAN/16]; // Number on the block
unsigned short meshbumplistprt[MAXMESHFAN/16]; // For particle collisions
unsigned short meshbumplistprtnum[MAXMESHFAN/16]; // Number on the block
unsigned char meshexploremode = FALSE; // Explore mode?
int maxtotalmeshvertices = (256*256*6);// Max number of vertices
int meshsizex; // Size in fansquares
int meshsizey; //
float meshedgex; // Limits of mesh !!!BAD!!!
float meshedgey; //
unsigned short meshlasttexture; // Last texture used
unsigned char meshtype[MAXMESHFAN]; // Command type
unsigned char meshfx[MAXMESHFAN]; // Special effects flags
unsigned char meshtwist[MAXMESHFAN]; //
unsigned char meshinrenderlist[MAXMESHFAN]; // Display fan? yes/no
unsigned short meshtile[MAXMESHFAN]; // Get texture from this
unsigned int meshvrtstart[MAXMESHFAN]; // Which vertex to start at
unsigned int meshblockstart[(MAXMESHSIZEY/4)+1];
unsigned int meshfanstart[MAXMESHSIZEY]; // Which fan to start a row with
Format of Mapfile:
Bytes 0 .. 3: Must be MAPID 0x4470614d // The string... "MapD"
Bytes 4 .. 7: numvert: INT Number of Vertices
Bytes 8 .. 11: meshsizex: Mesh size in x-direction
Bytes 12 .. 15: meshsizey: Mesh size in y-direction
// int numfan = meshsizex*meshsizey
First Step:
Numfan times:
Load meshtype data
Read INT into itmp
Split this into this values:
meshtype[fan] = itmp >> 24;
meshfx[fan] = itmp >> 16;
meshtile[fan] = itmp & 0xFFFF;
Second Step:
Load fan data
Numfan times:
Read UNSIGNED CHAR into ctmp
meshtwist[fan] = ctmp
Third Step:
Load vertex x data
Numvert times:
read FLOAT into ftmp
meshvrtx[cnt] = ftmp
Fourth Step:
Load vertex y data
Numvert times:
read FLOAT into ftmp
meshvrty[cnt] = ftmp
Fifth step:
Load vertex z data
Numvert times:
read FLOAT into ftmp
meshvrtz[cnt] = ftmp / 16.0; // Cartman uses 4 bit fixed point for Z
Sixth Step:
Get vertex lighting data.
Numvert times:
If fullbright:
Just set the maximum value
meshvrta[cnt] = 255;
meshvrtl[cnt] = 255;
Otherwise:
Read UNSIGNED CHAR into ctmp
meshvrta[cnt] = ctmp;
meshvrtl[cnt] = 0;
Seventh Step:
After the map is read, there is some more work to do:
make_fanstart();
Build a look up table to ease calculating the
fan number given an x,y pair
For cnt = 0 .. meshsizey:
meshfanstart[cnt] = meshsizex * cnt
For cnt = 0 .. (meshsizey >> 2):
meshblockstart[cnt] = (meshsizex >> 2) * cnt
Calculate the display vertices for the mesh:
for meshsizey
for meshsizex
fan = meshfanstart[y]+x;
meshvrtstart[fan] = vert;
vert+=meshcommandnumvertices[meshtype[fan]];
Additional needed data:
meshedgex = meshsizex*128;
meshedgey = meshsizey*128;
numfanblock = ((meshsizex>>2))*((meshsizey>>2)); // MESHSIZEX MUST BE MULTIPLE OF 4
watershift = 3;
if(meshsizex > 16) watershift = 4;
if(meshsizex > 32) watershift = 5;
if(meshsizex > 64) watershift = 6;
if(meshsizex > 128) watershift = 7;
if(meshsizex > 256) watershift = 8;
RENDERING A FAN
---------------
Fan means a tile in the maze.
Used Data:
DATA FOR MESH FANS
Additional:
meshlasttexture
Vertex is a value from 0-15, for the meshcommandref/u/v variables
Badvertex is a value that references the actual vertex number
RENDER A WATER FAN
------------------
Rendered with "render_water_fan"
Used Data:
waterlayeru[layer];
waterlayerv[layer];
waterlayerframe[layer];
waterlayerzadd[layer];
waterlayerz[layer];
waterlayercolor[layer]
waterlayeralpha[layer]
Setting up the textureoffset for moving textures:
Stored in
textureoffset[cnt];
DATA FOR MESH FANS
------------------
Loaded by "load__mesh_fans"
DATA in "FANS.TXT"
USED VARIABLES
unsigned char meshcommands[MAXMESHTYPE]; // Number of commands
unsigned char meshcommandsize[MAXMESHTYPE][MAXMESHCOMMAND]; // Entries in each command
unsigned short meshcommandvrt[MAXMESHTYPE][MAXMESHCOMMANDENTRIES]; // Fansquare vertex list
unsigned char meshcommandnumvertices[MAXMESHTYPE]; // Number of vertices
float meshcommandu[MAXMESHTYPE][MAXMESHVERTICES]; // Vertex texture position
float meshcommandv[MAXMESHTYPE][MAXMESHVERTICES]; //
float meshtileoffu[MAXTILETYPE]; // Tile texture offset
float meshtileoffv[MAXTILETYPE];
start of bigfantype at (MAXMESHTYPE/2)
As Struct:
struct {
unsigned char count; // Number of commands
unsigned char size[MAXMESHCOMMAND]; // Entries in each command
unsigned short vrt[MAXMESHCOMMANDENTRIES]; // Fansquare vertex list
unsigned char numvertices; // Number of vertices
float u[MAXMESHVERTICES]; // SMALL FANTYPE, BIG FANTYPE
float v[MAXMESHVERTICES]; // Vertex texture position
} meshcommand[MAXMESHTYPE];
struct {
float offu; // Tile texture offset
float offv;
} meshtile[MAXTILETYPE];
// Number of Fan Types: 26
numfantype: 26
Init:
fantype = 0;
bigfantype = MAXMESHTYPE/2
FANTYPE 0 // Two Faced Ground...
// Vertices: 4
numvertices: 4 // numvertices[fantype] / numvertices[bigfantype]
// Ref: 0 U: 0.00 V: 0.00
meshcommandu: 0.00, 1.00, 1.00, 0.00 // meshcommandu[fantype][cnt] = ftmp;
// meshcommandu[bigfantype][cnt] = ftmp
meshcommandv: 0.00, 0.00, 1.00, 1.00 // meshcommandv[fantype][cnt] = ftmp;
// meshcommandv[bigfantype][cnt] = ftmp
// Commands 1:
count: 1
// Command Size: 4
size: 4
vtrt: 1, 2, 3, 0 // meshcommandsize[fantype][command] = commandsize;
// meshcommandsize[bigfantype][command] = commandsize; // Dupe
FANTYPE 1 // Two Faced Ground...
numvertices: 4
meshcommandu: 0.00, 1.00, 1.00, 0.00
meshcommandv: 0.00, 0.00, 1.00, 1.00
count: 1
size: 4
vrt: 0, 1, 2, 3
FANTYPE 2 // Four Faced Ground...
numvertices: 5
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.50
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.50
count: 1
size: 6
vrt: 4, 3, 0, 1, 2, 3
FANTYPE 3 // Eight Faced Ground...
numvertices: 9
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.50, 1.00, 0.50, 0.00, 0.50
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.00, 0.50, 1.00, 0.50, 0.50
count: 1
size: 10
vrt: 8, 3, 7, 0, 4, 1, 5, 2, 6, 3
FANTYPE 4 // Ten Face Pillar...
numvertices: 8
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.33, 0.66, 0.66, 0.33
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.33, 0.33, 0.66, 0.66
count: 2
size: 8
vrt: 7, 3, 0, 4, 5, 6, 2, 3
size: 6
vrt: 5, 4, 0, 1, 2, 6
FANTYPE 5 // Eighteen Faced Pillar...
numvertices: 16
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.33, 0.66, 1.00, 1.00,
0.66, 0.33, 0.00, 0.00, 0.33, 0.66, 0.66, 0.33
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 0.33, 0.66,
1.00, 1.00, 0.66, 0.33, 0.33, 0.33, 0.66, 0.66
count: 4
size: 10
vrt: 15, 3, 10, 11, 12, 13, 14, 8, 9, 3
size: 8
vrt: 13, 12, 4, 5, 1, 6, 7, 14
size: 4
vrt: 12, 11, 0, 4
size: 4
vrt: 14, 7, 2, 8
FANTYPE 6 // Blank...
numvertices: 0
count: 0
FANTYPE 7 // Blank...
numvertices: 0
count: 0
FANTYPE 8 // Six Faced Wall (WE)...
numvertices: 8
meshcommandu: 0.00, 1.00, 1.00, 0.00, 1.00, 1.00, 0.00, 0.00
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.33, 0.66, 0.66, 0.33
count: 2
size: 6
vrt: 5, 2, 3, 6, 7, 4
size: 4
vrt: 4, 7, 0, 1
FANTYPE 9 // Six Faced Wall (NS)...
numvertices: 8
meshcommandu: 0.00, 1.00, 1.00, 0.00, 1.00, 1.00, 0.00, 0.00
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.33, 0.66, 0.66, 0.33
count: 2
size: 6
vrt: 7, 3, 0, 4, 5, 6
size: 4
vrt: 6, 5, 1, 2
FANTYPE 10 // Blank...
numvertices: 0
count: 0
FANTYPE 11 // Blank...
numvertices: 0
count: 0
FANTYPE 12 // Eight Faced Wall (W)...
numvertices: 8
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.00, 0.00, 0.66, 0.66
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.66, 0.33, 0.33, 0.66
count: 2
size: 8
vrt: 7, 3, 4, 5, 6, 1, 2, 3
size: 4
vrt: 1, 6, 5, 0
FANTYPE 13 // Eight Faced Wall (N)...
numvertices: 8
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.33, 0.66, 0.66, 0.33
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 0.66, 0.66
count: 2
size: 8
vrt: 7, 3, 0, 4, 5, 6, 2, 3
size: 4
vrt: 2, 6, 5, 1
FANTYPE 14 // Eight Faced Wall (E)...
numvertices: 8
meshcommandu: 0.00, 1.00, 1.00, 0.00, 1.00, 1.00, 0.33, 0.33
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.33, 0.66, 0.33, 0.66
count: 2
size: 8
vrt: 6, 3, 0, 1, 4, 5, 7, 3
size: 4
vrt: 3, 7, 5, 2
FANTYPE 15 // Eight Faced Wall (S)...
numvertices: 8
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.66, 0.33, 0.33, 0.66
meshcommandv: 0.00, 0.00, 1.00, 1.00, 1.00, 1.00, 0.33, 0.33
count: 2
size: 8
vrt: 7, 5, 6, 0, 1, 2, 4, 5
size: 4
vrt: 0, 6, 5, 3
FANTYPE 16 // Ten Faced Wall (WS)...
numvertices: 10
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.66, 0.33, 0.00, 0.00, 0.66, 0.33
meshcommandv: 0.00, 0.00, 1.00, 1.00, 1.00, 1.00, 0.66, 0.33, 0.33, 0.66
count: 2
size: 8
vrt: 9, 3, 6, 7, 8, 4, 5, 3
size: 6
vrt: 8, 7, 0, 1, 2, 4
FANTYPE 17 // Ten Faced Wall (NW)...
numvertices: 10
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.33, 0.66, 0.00, 0.00, 0.33, 0.66
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 0.66, 0.33, 0.33, 0.66
count: 2
size: 8
vrt: 8, 6, 7, 0, 4, 5, 9, 6
size: 6
vrt: 9, 5, 1, 2, 3, 6
FANTYPE 18 // Ten Faced Wall (NE)...
numvertices: 10
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.33, 0.66, 1.00, 1.00, 0.66, 0.33
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 0.33, 0.66, 0.33, 0.66
count: 2
size: 8
vrt: 8, 9, 4, 5, 1, 6, 7, 9
size: 6
vrt: 9, 7, 2, 3, 0, 4
FANTYPE 19 // Ten Faced Wall (ES)...
numvertices: 10
meshcommandu: 0.00, 1.00, 1.00, 0.00, 1.00, 1.00, 0.66, 0.33, 0.33, 0.66
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.33, 0.66, 1.00, 1.00, 0.33, 0.66
count: 2
size: 8
vrt: 9, 7, 8, 4, 5, 2, 6, 7
size: 6
vrt: 8, 7, 3, 0, 1, 4
FANTYPE 20 // Twelve Faced Wall (WSE)...
numvertices: 12
meshcommandu: 0.00, 1.00, 1.00, 0.00, 1.00, 1.00, 0.66, 0.33,
0.00, 0.00, 0.66, 0.33
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.33, 0.66, 1.00, 1.00,
0.66, 0.33, 0.66, 0.66
count: 3
size: 9
vrt: 11, 3, 8, 9, 4, 10, 6, 7, 3
size: 5
vrt: 10, 4, 5, 2, 6
size: 4
vrt: 4, 9, 0, 1
FANTYPE 21 // Twelve Faced Wall (NWS)...
numvertices: 12
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.33, 0.66, 0.66, 0.33,
0.00, 0.00, 0.33, 0.33
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00,
0.66, 0.33, 0.33, 0.66
count: 3
size: 9
vrt: 10, 8, 9, 0, 4, 5, 6, 11, 8
size: 5
vrt: 11, 6, 7, 3, 8
size: 4
vrt: 6, 5, 1, 2
FANTYPE 22 // Twelve Faced Wall (ENW)...
numvertices: 12
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.33, 0.66, 1.00, 1.00,
0.00, 0.00, 0.33, 0.66
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 0.33, 0.66,
0.66, 0.33, 0.33, 0.33
count: 3
size: 9
vrt: 11, 8, 10, 4, 5, 1, 6, 7, 8
size: 5
vrt: 10, 8, 9, 0, 4
size: 4
vrt: 8, 7, 2, 3
FANTYPE 23 // Twelve Faced Wall (SEN)...
numvertices: 12
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.33, 0.66, 1.00, 1.00, 0.66, 0.33, 0.66, 0.66
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 0.33, 0.66, 1.00, 1.00, 0.33, 0.66
count: 3
size: 9
vrt: 11, 9, 4, 10, 6, 7, 2, 8, 9
size: 5
vrt: 10, 4, 5, 1, 6
size: 4
vrt: 4, 9, 3, 0
FANTYPE 24 // Twelve Faced Stair (WE)...
numvertices: 14
meshcommandu: 0.00, 1.00, 1.00, 0.00, 0.16, 0.33, 0.50, 0.66,
0.83, 0.83, 0.66, 0.50, 0.33, 0.16
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.00, 0.00, 0.00, 0.00,
0.00, 1.00, 1.00, 1.00, 1.00, 1.00
count: 3
size: 6
vrt: 13, 3, 0, 4, 5, 12
size: 6
vrt: 11, 12, 5, 6, 7, 10
size: 6
vrt: 9, 10, 7, 8, 1, 2
FANTYPE 25 // Twelve Faced Stair (NS)...
numvertices: 14
meshcommandu: 0.00, 1.00, 1.00, 0.00, 1.00, 1.00, 1.00, 1.00,
1.00, 0.00, 0.00, 0.00, 0.00, 0.00
meshcommandv: 0.00, 0.00, 1.00, 1.00, 0.16, 0.33, 0.50, 0.66,
0.83, 0.83, 0.66, 0.50, 0.33, 0.16
count: 3
size: 6
vrt: 13, 0, 1, 4, 5, 12
size: 6
vrt: 11, 12, 5, 6, 7, 10
size: 6
vrt: 9, 10, 7, 8, 2, 3
The texture positions will be corrected after loading for seamless tiling.
With the following code:
entry = 0;
while(entry < MAXMESHTYPE/2)
{
cnt = 0;
while(cnt < meshcommandnumvertices[entry])
{
meshcommandu[entry][cnt] = ((.6/32)+(meshcommandu[entry][cnt]*30.8/32))/8;
meshcommandv[entry][cnt] = ((.6/32)+(meshcommandv[entry][cnt]*30.8/32))/8;
cnt++;
}
entry++;
}
// Do for big tiles too
while(entry < MAXMESHTYPE)
{
cnt = 0;
while(cnt < meshcommandnumvertices[entry])
{
meshcommandu[entry][cnt] = ((.6/64)+(meshcommandu[entry][cnt]*62.8/64))/4;
meshcommandv[entry][cnt] = ((.6/64)+(meshcommandv[entry][cnt]*62.8/64))/4;
cnt++;
}
entry++;
}
And as last step, the tile texture offsets are generated:
entry = 0;
while(entry < MAXTILETYPE) {
offx = (entry & 7) / 8.0;
offy = (entry >> 3) / 8.0;
meshtileoffu[entry] = offx;
meshtileoffv[entry] = offy;
entry++;
}
|