bool playMOD (int f, int a, int fromTrack) { if (soundOK) { stopMOD (a); setResourceForFatal (f); uint32_t length = openFileFromNum (f); if (length == 0) return NULL; char * memImage; memImage = loadEntireFileToMemory (bigDataFile, length); if (! memImage) return fatal (ERROR_MUSIC_MEMORY_LOW); mod[a] = BASS_MusicLoad (true, memImage, 0, length, BASS_MUSIC_LOOP|BASS_MUSIC_RAMP/*|BASS_MUSIC_PRESCAN needed too if we're going to set the position in bytes*/, 0); delete memImage; if (! mod[a]) { } else { setMusicVolume (a, defVol); if (! BASS_ChannelPlay (mod[a], true) ) debugOut("playMOD: Error %d!\n", BASS_ErrorGetCode()); BASS_ChannelSetPosition (mod[a], MAKELONG(fromTrack, 0), BASS_POS_MUSIC_ORDER); BASS_ChannelFlags(mod[a], BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP, BASS_SAMPLE_LOOP|BASS_MUSIC_RAMP); } setResourceForFatal (-1); } return true; }
void mixBackDrop (int fileNum, int x, int y) { setResourceForFatal (fileNum); if (! openFileFromNum (fileNum)) { fatal ("Can't load overlay image"); return; } if (! mixHSI (bigDataFile, x, y)) { fatal ("Can't paste overlay image outside screen dimensions"); } finishAccess (); setResourceForFatal (-1); }
int cacheSound (int f) { setResourceForFatal (f); if (! soundOK) return 0; int a = findInSoundCache (f); if (a != -1) return a; if (f == -2) return -1; a = findEmptySoundSlot (); freeSound (a); uint32_t length = openFileFromNum (f); if (! length) return -1; char * memImage; bool tryAgain = true; while (tryAgain) { memImage = loadEntireFileToMemory (bigDataFile, length); tryAgain = memImage == NULL; if (tryAgain) { if (! forceRemoveSound ()) { fatal (ERROR_SOUND_MEMORY_LOW); return -1; } } } for (;;) { // soundWarning (" Trying to load sound into slot", a); soundCache[a].sample = BASS_SampleLoad(true, memImage, 0, length, 65535, 0); if (soundCache[a].sample) { soundCache[a].fileLoaded = f; delete memImage; setResourceForFatal (-1); return a; } warning (ERROR_SOUND_ODDNESS); soundCache[a].sample = NULL; soundCache[a].fileLoaded = -1; soundCache[a].looping = false; return -1; } }
void loadBackDrop (int fileNum, int x, int y) { setResourceForFatal (fileNum); if (! openFileFromNum (fileNum)) { fatal ("Can't load overlay image"); return; } if (! loadHSI (bigDataFile, x, y, false)) { char mess[200]; sprintf (mess, "Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i", x, y, sceneWidth, sceneHeight); fatal (mess); } finishAccess (); setResourceForFatal (-1); }
bool playMOD (int f, int a, int fromTrack) { if (! soundOK) return true; stopMOD (a); setResourceForFatal (f); uint32_t length = openFileFromNum (f); if (length == 0) { finishAccess(); setResourceForFatal (-1); return false; } unsigned char * memImage; memImage = (unsigned char *) loadEntireFileToMemory (bigDataFile, length); if (! memImage) return fatal (ERROR_MUSIC_MEMORY_LOW); modCache[a].stream = alureCreateStreamFromMemory(memImage, length, 19200, 0, NULL); delete memImage; if (modCache[a].stream != NULL) { setMusicVolume (a, defVol); if (! alureSetStreamOrder (modCache[a].stream, fromTrack)) { debugOut( "Failed to set stream order: %s\n", alureGetErrorString()); } playStream (a, true, true); } else { debugOut("Failed to create stream from MOD: %s\n", alureGetErrorString()); warning (ERROR_MUSIC_ODDNESS); soundCache[a].stream = NULL; soundCache[a].playing = false; soundCache[a].playingOnSource = 0; } setResourceForFatal (-1); return true; }
bool setZBuffer (int y) { int x, n; uint32_t stillToGo = 0; int yPalette[16], sorted[16], sortback[16]; killZBuffer (); setResourceForFatal (y); zBuffer.originalNum = y; if (! openFileFromNum (y)) return false; if (fgetc (bigDataFile) != 'S') return fatal ("Not a Z-buffer file"); if (fgetc (bigDataFile) != 'z') return fatal ("Not a Z-buffer file"); if (fgetc (bigDataFile) != 'b') return fatal ("Not a Z-buffer file"); switch (fgetc (bigDataFile)) { case 0: zBuffer.width = 640; zBuffer.height = 480; break; case 1: zBuffer.width = get2bytes (bigDataFile); zBuffer.height = get2bytes (bigDataFile); break; default: return fatal ("Extended Z-buffer format not supported in this version of the SLUDGE engine"); } if (zBuffer.width != sceneWidth || zBuffer.height != sceneHeight) { char tmp[256]; sprintf (tmp, "Z-w: %d Z-h:%d w: %d, h:%d", zBuffer.width, zBuffer.height, sceneWidth, sceneHeight); return fatal ("Z-buffer width and height don't match scene width and height", tmp); } zBuffer.numPanels = fgetc (bigDataFile); for (y = 0; y < zBuffer.numPanels; y ++) { yPalette[y] = get2bytes (bigDataFile); } sortZPal (yPalette, sorted, zBuffer.numPanels); for (y = 0; y < zBuffer.numPanels; y ++) { zBuffer.panel[y] = yPalette[sorted[y]]; sortback[sorted[y]] = y; } int picWidth = sceneWidth; int picHeight = sceneHeight; if (! NPOT_textures) { picWidth = getNextPOT(picWidth); picHeight = getNextPOT(picHeight); } zBuffer.tex = new GLubyte [picHeight*picWidth]; if (! checkNew (zBuffer.tex)) return false; for (y = 0; y < sceneHeight; y ++) { for (x = 0; x < sceneWidth; x ++) { if (stillToGo == 0) { n = fgetc (bigDataFile); stillToGo = n >> 4; if (stillToGo == 15) stillToGo = get2bytes (bigDataFile) + 16l; else stillToGo ++; n &= 15; } zBuffer.tex[y*picWidth + x] = sortback[n]*16; stillToGo --; } }
bool loadParallax (unsigned short v, unsigned short fracX, unsigned short fracY) { setResourceForFatal (v); if (! openFileFromNum (v)) return fatal ("Can't open parallax image"); parallaxLayer * nP = new parallaxLayer; if (! checkNew (nP)) return false; nP -> next = parallaxStuff; parallaxStuff = nP; if (nP -> next) { nP -> next -> prev = nP; } nP -> prev = NULL; int picWidth; int picHeight; long file_pointer = ftell (bigDataFile); png_structp png_ptr; png_infop info_ptr, end_info; int fileIsPNG = true; // Is this a PNG file? char tmp[10]; size_t bytes_read = fread(tmp, 1, 8, bigDataFile); if (bytes_read != 8 && ferror (bigDataFile)) { debugOut("Reading error in loadParallax.\n"); } if (png_sig_cmp((png_byte *) tmp, 0, 8)) { // No, it's old-school HSI fileIsPNG = false; fseek(bigDataFile, file_pointer, SEEK_SET); picWidth = nP -> width = get2bytes (bigDataFile); picHeight = nP -> height = get2bytes (bigDataFile); } else { // Read the PNG header png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { return false; } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL); return false; } end_info = png_create_info_struct(png_ptr); if (!end_info) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); return false; } png_init_io(png_ptr, bigDataFile); // Tell libpng which file to read png_set_sig_bytes(png_ptr, 8); // 8 bytes already read png_read_info(png_ptr, info_ptr); png_uint_32 width, height; int bit_depth, color_type, interlace_type, compression_type, filter_method; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method); picWidth = nP -> width = width; picHeight = nP -> height = height; if (bit_depth < 8) png_set_packing(png_ptr); png_set_expand(png_ptr); if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr); if (bit_depth == 16) png_set_strip_16(png_ptr); png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER); png_read_update_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method); //int rowbytes = png_get_rowbytes(png_ptr, info_ptr); } if (! NPOT_textures) { picWidth = getNextPOT(picWidth); picHeight = getNextPOT(picHeight); } nP -> fileNum = v; nP -> fractionX = fracX; nP -> fractionY = fracY; if (fracX == 65535) { nP -> wrapS = false; if (nP -> width < winWidth) { fatal ("For AUTOFIT parallax backgrounds, the image must be at least as wide as the game window/screen."); return false; } } else { nP -> wrapS = true; } if (fracY == 65535) { nP -> wrapT = false; if (nP -> height < winHeight) { fatal ("For AUTOFIT parallax backgrounds, the image must be at least as tall as the game window/screen."); return false; } } else { nP -> wrapT = true; } nP -> texture = new GLubyte [picHeight * picWidth * 4]; if (! checkNew (nP -> texture)) return false; if (fileIsPNG) { unsigned char * row_pointers[nP -> height]; for (int i = 0; i < nP -> height; i++) row_pointers[i] = nP -> texture + 4*i*picWidth; png_read_image(png_ptr, (png_byte **) row_pointers); png_read_end(png_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); } else { int t1, t2, n; unsigned short c; GLubyte * target; for (t2 = 0; t2 < nP -> height; t2 ++) { t1 = 0; while (t1 < nP -> width) { c = (unsigned short) get2bytes (bigDataFile); if (c & 32) { n = fgetc (bigDataFile) + 1; c -= 32; } else { n = 1; } while (n--) { target = nP -> texture + 4*picWidth*t2 + t1*4; if (c == 63519 || c == 2015) { target[0] = (GLubyte) 0; target[1] = (GLubyte) 0; target[2] = (GLubyte) 0; target[3] = (GLubyte) 0; } else { target[0] = (GLubyte) redValue(c); target[1] = (GLubyte) greenValue(c); target[2] = (GLubyte) blueValue(c); target[3] = (GLubyte) 255; } t1 ++; } } } } glGenTextures (1, &nP->textureName); glBindTexture (GL_TEXTURE_2D, nP->textureName); if (nP -> wrapS) glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); else glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); if (nP -> wrapT) glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); else glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (gameSettings.antiAlias < 0) { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } texImage2D (GL_TEXTURE_2D, 0, GL_RGBA, picWidth, picHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nP->texture, nP->textureName); finishAccess (); setResourceForFatal (-1); return true; }
bool loadLightMap (int v) { int newPicWidth, newPicHeight; setResourceForFatal (v); if (! openFileFromNum (v)) return fatal ("Can't open light map."); long file_pointer = ftell (bigDataFile); png_structp png_ptr; png_infop info_ptr, end_info; int fileIsPNG = true; // Is this a PNG file? char tmp[10]; size_t bytes_read = fread(tmp, 1, 8, bigDataFile); if (bytes_read != 8 && ferror (bigDataFile)) { debugOut("Reading error in loadLightMap.\n"); } if (png_sig_cmp((png_byte *) tmp, 0, 8)) { // No, it's old-school HSI fileIsPNG = false; fseek(bigDataFile, file_pointer, SEEK_SET); newPicWidth = lightMap.w = get2bytes (bigDataFile); newPicHeight = lightMap.h = get2bytes (bigDataFile); } else { // Read the PNG header png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { return false; } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL); return false; } end_info = png_create_info_struct(png_ptr); if (!end_info) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); return false; } png_init_io(png_ptr, bigDataFile); // Tell libpng which file to read png_set_sig_bytes(png_ptr, 8); // 8 bytes already read png_read_info(png_ptr, info_ptr); png_uint_32 width, height; int bit_depth, color_type, interlace_type, compression_type, filter_method; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method); newPicWidth = lightMap.w = width; newPicHeight = lightMap.h = height; if (bit_depth < 8) png_set_packing(png_ptr); png_set_expand(png_ptr); if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr); if (bit_depth == 16) png_set_strip_16(png_ptr); png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER); png_read_update_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method); //int rowbytes = png_get_rowbytes(png_ptr, info_ptr); } if (lightMapMode == LIGHTMAPMODE_HOTSPOT) { if (lightMap.w != sceneWidth || lightMap.h != sceneHeight) { return fatal ("Light map width and height don't match scene width and height. That is required for lightmaps in HOTSPOT mode."); } } if (! NPOT_textures) { newPicWidth = getNextPOT(lightMap.w); newPicHeight = getNextPOT(lightMap.h); lightMap.texW = (double) lightMap.w / newPicWidth; lightMap.texH = (double) lightMap.h / newPicHeight; } else { lightMap.texW = 1.0; lightMap.texH = 1.0; } killLightMap (); lightMapNumber = v; glPixelStorei (GL_UNPACK_ALIGNMENT, 1); if (lightMap.data) delete [] lightMap.data; lightMap.data = new GLubyte [newPicWidth*newPicHeight*4]; if (! lightMap.data) { return fatal ("Out of memory loading light map."); } int t1, t2, n; unsigned short c; GLubyte * target; if (fileIsPNG) { unsigned char * row_pointers[lightMap.h]; for (int i = 0; i<lightMap.h; i++) row_pointers[i] = lightMap.data + 4*i*newPicWidth; png_read_image(png_ptr, (png_byte **) row_pointers); png_read_end(png_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); } else { for (t2 = 0; t2 < lightMap.h; t2 ++) { t1 = 0; while (t1 < lightMap.w) { c = (unsigned short) get2bytes (bigDataFile); if (c & 32) { n = fgetc (bigDataFile) + 1; c -= 32; } else { n = 1; } while (n --) { target = lightMap.data + 4*newPicWidth*t2 + t1*4; target[0] = (GLubyte) redValue(c); target[1] = (GLubyte) greenValue(c); target[2] = (GLubyte) blueValue(c); target[3] = (GLubyte) 255; t1++; } } } } if (! lightMap.name) glGenTextures (1, &lightMap.name); glBindTexture(GL_TEXTURE_2D, lightMap.name); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); texImage2D (GL_TEXTURE_2D, 0, GL_RGBA, newPicWidth, newPicHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, lightMap.data, lightMap.name); finishAccess (); setResourceForFatal (-1); return true; }
bool loadSpriteBank (int fileNum, spriteBank & loadhere, bool isFont) { int i, tex_num, total, picwidth, picheight, spriteBankVersion = 0, howmany=0, startIndex=0; int * totalwidth, * maxheight; int numTextures = 0; byte * data; setResourceForFatal (fileNum); if (! openFileFromNum (fileNum)) return fatal ("Can't open sprite bank / font"); loadhere.isFont = isFont; total = get2bytes (bigDataFile); if (! total) { spriteBankVersion = fgetc (bigDataFile); if (spriteBankVersion == 1) { total = 0; } else { total = get2bytes (bigDataFile); } } if (total <= 0) return fatal ("No sprites in bank or invalid sprite bank file"); if (spriteBankVersion > 3) return fatal ("Unsupported sprite bank file format"); loadhere.total = total; loadhere.sprites = new sprite [total]; if (! checkNew (loadhere.sprites)) return false; byte ** spriteData = new byte * [total]; if (! checkNew (spriteData)) return false; totalwidth = new int[total]; if (! checkNew (totalwidth)) return false; maxheight = new int[total]; if (! checkNew (maxheight)) return false; loadhere.myPalette.tex_names = new GLuint [total]; if (! checkNew (loadhere.myPalette.tex_names)) return false; if (isFont) { loadhere.myPalette.burnTex_names = new GLuint [total]; if (! checkNew (loadhere.myPalette.burnTex_names)) return false; } loadhere.myPalette.tex_w = new int [total]; if (! checkNew (loadhere.myPalette.tex_w)) return false; loadhere.myPalette.tex_h = new int [total]; if (! checkNew (loadhere.myPalette.tex_h)) return false; if (spriteBankVersion && spriteBankVersion < 3) { howmany = fgetc (bigDataFile); startIndex = 1; } totalwidth[0] = maxheight[0] = 1; for (i = 0; i < total; i ++) { switch (spriteBankVersion) { case 3: { loadhere.sprites[i].xhot = getSigned (bigDataFile); loadhere.sprites[i].yhot = getSigned (bigDataFile); png_structp png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { return fatal ("Can't open sprite bank / font."); } png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL); return fatal ("Can't open sprite bank / font."); } png_infop end_info = png_create_info_struct(png_ptr); if (!end_info) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); return fatal ("Can't open sprite bank / font."); } png_init_io(png_ptr, bigDataFile); // Tell libpng which file to read png_set_sig_bytes(png_ptr, 8); // No sig png_read_info(png_ptr, info_ptr); png_uint_32 width, height; int bit_depth, color_type, interlace_type, compression_type, filter_method; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, &compression_type, &filter_method); int rowbytes = png_get_rowbytes(png_ptr, info_ptr); unsigned char * row_pointers[height]; spriteData[i] = new unsigned char [rowbytes*height]; if (! checkNew (spriteData[i])) return false; for (unsigned int row = 0; row<height; row++) row_pointers[row] = spriteData[i] + row*rowbytes; png_read_image(png_ptr, (png_byte **) row_pointers); png_read_end(png_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); picwidth = loadhere.sprites[i].width = width; picheight = loadhere.sprites[i].height = height; break; } case 2: picwidth = get2bytes (bigDataFile); picheight = get2bytes (bigDataFile); loadhere.sprites[i].xhot = getSigned (bigDataFile); loadhere.sprites[i].yhot = getSigned (bigDataFile); break; default: picwidth = (byte) fgetc (bigDataFile); picheight = (byte) fgetc (bigDataFile); loadhere.sprites[i].xhot = fgetc (bigDataFile); loadhere.sprites[i].yhot = fgetc (bigDataFile); break; } if (totalwidth[numTextures] + picwidth < 2047) { loadhere.sprites[i].tex_x = totalwidth[numTextures]; totalwidth[numTextures] += (loadhere.sprites[i].width = picwidth) + 1; if ((loadhere.sprites[i].height = picheight)+2 > maxheight[numTextures]) maxheight[numTextures] = picheight+2; } else { numTextures++; if (numTextures > 255) return fatal ("Can't open sprite bank / font - it's too big."); loadhere.sprites[i].tex_x = 0; totalwidth[numTextures] = (loadhere.sprites[i].width = picwidth); maxheight[numTextures] = loadhere.sprites[i].height = picheight; } loadhere.sprites[i].texNum = numTextures; if (spriteBankVersion < 3) { data = (byte *) new byte [picwidth * (picheight + 1)]; if (! checkNew (data)) return false; int ooo = picwidth * picheight; for (int tt = 0; tt < picwidth; tt ++) { data[ooo ++] = 0; } spriteData[i] = data; switch (spriteBankVersion) { case 2: // RUN LENGTH COMPRESSED DATA { unsigned size = picwidth * picheight; unsigned pip = 0; while (pip < size) { byte col = fgetc (bigDataFile); int looper; if (col > howmany) { col -= howmany + 1; looper = fgetc (bigDataFile) + 1; } else looper = 1; while (looper --) { data[pip ++] = col; } } } break; default: // RAW DATA size_t bytes_read = fread (data, picwidth, picheight, bigDataFile); if (bytes_read != picwidth * picheight && ferror (bigDataFile)) { debugOut("Reading error in loadSpriteBank.\n"); } break; } } } numTextures++; if (! spriteBankVersion) { howmany = fgetc (bigDataFile); startIndex = fgetc (bigDataFile); } if (spriteBankVersion < 3) { if (! reserveSpritePal (loadhere.myPalette, howmany + startIndex)) return false; for (i = 0; i < howmany; i ++) { loadhere.myPalette.r[i + startIndex] = (byte) fgetc (bigDataFile); loadhere.myPalette.g[i + startIndex] = (byte) fgetc (bigDataFile); loadhere.myPalette.b[i + startIndex] = (byte) fgetc (bigDataFile); loadhere.myPalette.pal[i + startIndex] = makeColour (loadhere.myPalette.r[i + startIndex], loadhere.myPalette.g[i + startIndex], loadhere.myPalette.b[i + startIndex]); } } loadhere.myPalette.originalRed = loadhere.myPalette.originalGreen = loadhere.myPalette.originalBlue = 255; loadhere.myPalette.numTextures = numTextures; GLubyte * tmp[numTextures]; GLubyte * tmp2[numTextures]; for (tex_num = 0; tex_num < numTextures; tex_num++) { if (! NPOT_textures) { totalwidth[tex_num] = getNextPOT(totalwidth[tex_num]); maxheight[tex_num] = getNextPOT(maxheight[tex_num]); } tmp[tex_num] = new GLubyte [(maxheight[tex_num]+1)*totalwidth[tex_num]*4]; if (! checkNew (tmp[tex_num])) return false; memset (tmp[tex_num], 0, maxheight[tex_num]*totalwidth[tex_num]*4); if (isFont) { tmp2[tex_num] = new GLubyte [(maxheight[tex_num]+1)*totalwidth[tex_num]*4]; if (! checkNew (tmp2[tex_num])) return false; memset (tmp2[tex_num], 0, maxheight[tex_num]*totalwidth[tex_num]*4); } loadhere.myPalette.tex_w[tex_num] = totalwidth[tex_num]; loadhere.myPalette.tex_h[tex_num] = maxheight[tex_num]; } int fromhere; unsigned char s; for (i = 0; i < total; i ++) { fromhere = 0; int transColour = -1; if (spriteBankVersion < 3) { int size = loadhere.sprites[i].height * loadhere.sprites[i].width; while (fromhere < size) { s = spriteData[i][fromhere++]; if (s) { transColour = s; break; } } fromhere = 0; } for (int y = 1; y < 1 + loadhere.sprites[i].height; y ++) { for (int x = loadhere.sprites[i].tex_x; x < loadhere.sprites[i].tex_x+loadhere.sprites[i].width; x ++) { GLubyte * target = tmp[loadhere.sprites[i].texNum] + 4*totalwidth[loadhere.sprites[i].texNum]*y + x*4; if (spriteBankVersion < 3) { s = spriteData[i][fromhere++]; if (s) { target[0] = (GLubyte) loadhere.myPalette.r[s]; target[1] = (GLubyte) loadhere.myPalette.g[s]; target[2] = (GLubyte) loadhere.myPalette.b[s]; target[3] = (GLubyte) 255; transColour = s; } else if (transColour >=0) { target[0] = (GLubyte) loadhere.myPalette.r[transColour]; target[1] = (GLubyte) loadhere.myPalette.g[transColour]; target[2] = (GLubyte) loadhere.myPalette.b[transColour]; target[3] = (GLubyte) 0; } if (isFont) { target = tmp2[loadhere.sprites[i].texNum] + 4*totalwidth[loadhere.sprites[i].texNum]*y + x*4; target[0] = (GLubyte) 255; target[1] = (GLubyte) 255; target[2] = (GLubyte) 255; if (s) target[3] = (GLubyte) loadhere.myPalette.r[s]; /*else target[3] = (GLubyte) 0;*/ } } else { target[0] = (GLubyte) spriteData[i][fromhere++]; target[1] = (GLubyte) spriteData[i][fromhere++]; target[2] = (GLubyte) spriteData[i][fromhere++]; target[3] = (GLubyte) spriteData[i][fromhere++]; } } } delete spriteData[i]; } delete spriteData; spriteData = NULL; glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glGenTextures (numTextures, loadhere.myPalette.tex_names); if (isFont) glGenTextures (numTextures, loadhere.myPalette.burnTex_names); for (tex_num = 0; tex_num < numTextures; tex_num++) { glBindTexture (GL_TEXTURE_2D, loadhere.myPalette.tex_names[tex_num]); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (gameSettings.antiAlias < 0) { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } texImage2D (GL_TEXTURE_2D, 0, GL_RGBA, totalwidth[tex_num], maxheight[tex_num], 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp[tex_num], loadhere.myPalette.tex_names[tex_num]); delete tmp[tex_num]; tmp[tex_num] = NULL; if (isFont) { glBindTexture (GL_TEXTURE_2D, loadhere.myPalette.burnTex_names[tex_num]); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (gameSettings.antiAlias < 0) { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } texImage2D (GL_TEXTURE_2D, 0, GL_RGBA, totalwidth[tex_num], maxheight[tex_num], 0, GL_RGBA, GL_UNSIGNED_BYTE, tmp2[tex_num], loadhere.myPalette.burnTex_names[tex_num]); delete tmp2[tex_num]; tmp2[tex_num] = NULL; } } finishAccess (); setResourceForFatal (-1); return true; }
bool FloorManager::setFloor(int fileNum) { int i, j; setFloorNull(); setResourceForFatal(fileNum); if (!g_sludge->_resMan->openFileFromNum(fileNum)) return false; // Find out how many polygons there are and reserve memory _currentFloor->originalNum = fileNum; _currentFloor->numPolygons = g_sludge->_resMan->getData()->readByte(); _currentFloor->polygon = new FloorPolygon[_currentFloor->numPolygons]; if (!checkNew(_currentFloor->polygon)) return false; // Read in each polygon for (i = 0; i < _currentFloor->numPolygons; i++) { // Find out how many vertex IDs there are and reserve memory _currentFloor->polygon[i].numVertices = g_sludge->_resMan->getData()->readByte(); _currentFloor->polygon[i].vertexID = new int[_currentFloor->polygon[i].numVertices]; if (!checkNew(_currentFloor->polygon[i].vertexID)) return false; // Read in each vertex ID for (j = 0; j < _currentFloor->polygon[i].numVertices; j++) { _currentFloor->polygon[i].vertexID[j] = g_sludge->_resMan->getData()->readUint16BE(); } } // Find out how many vertices there are and reserve memory i = g_sludge->_resMan->getData()->readUint16BE(); _currentFloor->vertex = new Common::Point[i]; if (!checkNew(_currentFloor->vertex)) return false; for (j = 0; j < i; j++) { _currentFloor->vertex[j].x = g_sludge->_resMan->getData()->readUint16BE(); _currentFloor->vertex[j].y = g_sludge->_resMan->getData()->readUint16BE(); } g_sludge->_resMan->finishAccess(); // Now build the movement martix _currentFloor->matrix = new int *[_currentFloor->numPolygons]; int **distanceMatrix = new int *[_currentFloor->numPolygons]; if (!checkNew(_currentFloor->matrix)) return false; for (i = 0; i < _currentFloor->numPolygons; i++) { _currentFloor->matrix[i] = new int[_currentFloor->numPolygons]; distanceMatrix[i] = new int[_currentFloor->numPolygons]; if (!checkNew(_currentFloor->matrix[i])) return false; for (j = 0; j < _currentFloor->numPolygons; j++) { _currentFloor->matrix[i][j] = -1; distanceMatrix[i][j] = 10000; } } for (i = 0; i < _currentFloor->numPolygons; i++) { for (j = 0; j < _currentFloor->numPolygons; j++) { if (i != j) { if (polysShareSide(_currentFloor->polygon[i], _currentFloor->polygon[j])) { _currentFloor->matrix[i][j] = j; distanceMatrix[i][j] = 1; } } else { _currentFloor->matrix[i][j] = -2; distanceMatrix[i][j] = 0; } } } bool madeChange; int lookForDistance = 0; do { lookForDistance++; madeChange = false; for (i = 0; i < _currentFloor->numPolygons; i++) { for (j = 0; j < _currentFloor->numPolygons; j++) { if (_currentFloor->matrix[i][j] == -1) { // OK, so we don't know how to get from i to j... for (int d = 0; d < _currentFloor->numPolygons; d++) { if (d != i && d != j) { if (_currentFloor->matrix[i][d] == d && _currentFloor->matrix[d][j] >= 0 && distanceMatrix[d][j] <= lookForDistance) { _currentFloor->matrix[i][j] = d; distanceMatrix[i][j] = lookForDistance + 1; madeChange = true; } } } } } } } while (madeChange); for (i = 0; i < _currentFloor->numPolygons; i++) { delete[] distanceMatrix[i]; } delete []distanceMatrix; distanceMatrix = nullptr; setResourceForFatal(-1); return true; }
int cacheSound (int f) { if (! soundOK) return -1; unsigned int chunkLength; int retval; bool loopy; loopy = cacheLoopySound; cacheLoopySound = false; setResourceForFatal (f); if (! soundOK) return 0; int a = findInSoundCache (f); if (a != -1) { if (soundCache[a].playing) { if (! alureStopSource(soundCache[a].playingOnSource, AL_TRUE)) { debugOut( "Failed to stop source: %s\n", alureGetErrorString()); } } if (! alureRewindStream (soundCache[a].stream)) { debugOut( "Failed to rewind stream: %s\n", alureGetErrorString()); } return a; } if (f == -2) return -1; a = findEmptySoundSlot (); freeSound (a); uint32_t length = openFileFromNum (f); if (! length) return -1; unsigned char * memImage; bool tryAgain = true; while (tryAgain) { memImage = (unsigned char*)loadEntireFileToMemory (bigDataFile, length); tryAgain = memImage == NULL; if (tryAgain) { if (! forceRemoveSound ()) { fatal (ERROR_SOUND_MEMORY_LOW); return -1; } } } chunkLength = 19200; // Small looping sounds need small chunklengths. if (loopy) { if (length < NUM_BUFS * chunkLength) { chunkLength = length / NUM_BUFS; } } else if (length < chunkLength) { chunkLength = length; } soundCache[a].stream = alureCreateStreamFromMemory(memImage, length, chunkLength, 0, NULL); delete memImage; if (soundCache[a].stream != NULL) { soundCache[a].fileLoaded = f; setResourceForFatal (-1); retval = a; } else { debugOut("Failed to create stream from sound: %s\n", alureGetErrorString()); warning (ERROR_SOUND_ODDNESS); soundCache[a].stream = NULL; soundCache[a].playing = false; soundCache[a].playingOnSource = 0; soundCache[a].fileLoaded = -1; soundCache[a].looping = false; retval = -1; } return retval; }