if (data ==NULL) return NULL;
// read resource completely Iseek (file, directory [index].offset, SEEK_SET ); read (file, data, directory [index].size );
Pic * pic = new Pic; if (pic == NULL ) {
free (data ); return NULL;
}
pic -> width = picHdr -> width; pic -> height = picHdr -> height; pic -> leftOffset = picHdr -> leftOffset; pic -> topOffset = picHdr -> topOffset; pic -> colOffsets = picHdr -> colPtr; pic -> data = data;
return pic;
}
Texture * WadFile :: loadTexture ( const char * texName ) {
if (texturel == NULL ) // will use only TEXTURE 1
JoadTexturel ();
if (texturel -= NULL ) return NULL;
if ( pnames == NULL ) loadPNames ();
if ( pnames == NULL ) return NULL;
for (int i = 0; i < texturel [0]; i++ ) {
TextureEntry * entry = (TextureEntry *)( texturel [i+1] + (char *) texturel )?
13. Элементы виртуальной реальност
if (Istrnicmp ( entry -> textureName, texName, 8 )) {
Texture * tex = new Texture; // mit Texture
if (tex == NULL ) return NULL;
strncpy (tex -> name,. texName, 8 );
tex -> width = entry -> width; tex -> height = entry -> height;
tex -> data = (char *) malloc ( entry -> width * entry -> height);
if (tex -> data == NULL ) {
delete tex; return NULL;
}
memset (tex -> data, 0, entry -> width * entry -> height);
// apply patches for (int j = 0; j < entry -> numPatches; j++ ) . applyPatch (tex, entry -> patch 0]);
return tex;
}
}
return NULL; // texture not found
}
void WadFiie :: applyPatch ( Texture * tex, TexturePatch& patch ) {
Pic * pic = loadPic ( pnames + 2 + patch.pnamesNo * 8 );
if ( pic == NULL ) return;
if (tex -> data == NULL ) return;
for (int col = 0; col < pic -> width; col++ ) {
if ( col + patch.xOffset < 0 ) continue;
char * colData = pic -> data + pic -> colOffsets [col]; char * texData; int curRow;
if (*colData == '\xFF') continue;
do {
int row = *colData++;
int nonTransparentPixels = *colData++; int count = nonTransparentPixels;