void gr_init_canvas(grs_canvas &canv, unsigned char *const pixdata, const bm_mode pixtype, const uint16_t w, const uint16_t h) { canv.cv_fade_level = GR_FADE_OFF; canv.cv_font = NULL; canv.cv_font_fg_color = 0; canv.cv_font_bg_color = 0; auto wreal = w; gr_init_bitmap(canv.cv_bitmap, pixtype, 0, 0, w, h, wreal, pixdata); }
int properties_init() { int sbytes = 0; char temp_name_read[16]; char temp_name[16]; grs_bitmap temp_bitmap; digi_sound temp_sound; DiskBitmapHeader bmh; DiskSoundHeader sndh; int header_size, N_bitmaps, N_sounds; int i,size; int Pigdata_start; int pigsize; int retval; hashtable_init( &AllBitmapsNames, MAX_BITMAP_FILES ); hashtable_init( &AllDigiSndNames, MAX_SOUND_FILES ); for (i=0; i<MAX_SOUND_FILES; i++ ) { #ifdef ALLEGRO GameSounds[i].len = 0; #else GameSounds[i].length = 0; #endif GameSounds[i].data = NULL; SoundOffset[i] = 0; //added on 11/13/99 by Victor Rachels to ready for changing freq GameSounds[i].bits = 0; GameSounds[i].freq = 0; //end this section addition - VR } for (i=0; i<MAX_BITMAP_FILES; i++ ) { GameBitmapXlat[i] = i; GameBitmaps[i].bm_flags = BM_FLAG_PAGED_OUT; } if ( !bogus_bitmap_initialized ) { int i; ubyte c; bogus_bitmap_initialized = 1; c = gr_find_closest_color( 0, 0, 63 ); for (i=0; i<4096; i++ ) bogus_data[i] = c; c = gr_find_closest_color( 63, 0, 0 ); // Make a big red X ! for (i=0; i<64; i++ ) { bogus_data[i*64+i] = c; bogus_data[i*64+(63-i)] = c; } gr_init_bitmap (&bogus_bitmap, 0, 0, 0, 64, 64, 64, bogus_data); piggy_register_bitmap( &bogus_bitmap, "bogus", 1 ); #ifdef ALLEGRO bogus_sound.len = 64*64; #else bogus_sound.length = 64*64; #endif bogus_sound.data = bogus_data; //added on 11/13/99 by Victor Rachels to ready for changing freq bogus_sound.freq = 11025; bogus_sound.bits = 8; //end this section addition - VR GameBitmapOffset[0] = 0; } Piggy_fp = PHYSFSX_openReadBuffered(DEFAULT_PIGFILE_REGISTERED); if (Piggy_fp==NULL) { if (!PHYSFSX_exists("BITMAPS.TBL",1) && !PHYSFSX_exists("BITMAPS.BIN",1)) Error("Cannot find " DEFAULT_PIGFILE_REGISTERED " or BITMAPS.TBL"); return 1; // need to run gamedata_read_tbl } pigsize = PHYSFS_fileLength(Piggy_fp); switch (pigsize) { case D1_SHARE_BIG_PIGSIZE: case D1_SHARE_10_PIGSIZE: case D1_SHARE_PIGSIZE: PCSharePig = 1; Pigdata_start = 0; break; case D1_10_BIG_PIGSIZE: case D1_10_PIGSIZE: Pigdata_start = 0; break; default: Warning("Unknown size for " DEFAULT_PIGFILE_REGISTERED); Int3(); // fall through case D1_MAC_PIGSIZE: case D1_MAC_SHARE_PIGSIZE: MacPig = 1; case D1_PIGSIZE: case D1_OEM_PIGSIZE: Pigdata_start = PHYSFSX_readInt(Piggy_fp ); break; } HiresGFXAvailable = MacPig; // for now at least if (PCSharePig) retval = PIGGY_PC_SHAREWARE; // run gamedata_read_tbl in shareware mode else if (GameArg.EdiNoBm || (!PHYSFSX_exists("BITMAPS.TBL",1) && !PHYSFSX_exists("BITMAPS.BIN",1))) { properties_read_cmp( Piggy_fp ); // Note connection to above if!!! for (i = 0; i < MAX_BITMAP_FILES; i++) { GameBitmapXlat[i] = PHYSFSX_readShort(Piggy_fp); if (PHYSFS_eof(Piggy_fp)) break; } retval = 0; // don't run gamedata_read_tbl } else retval = 1; // run gamedata_read_tbl PHYSFSX_fseek( Piggy_fp, Pigdata_start, SEEK_SET ); size = PHYSFS_fileLength(Piggy_fp) - Pigdata_start; N_bitmaps = PHYSFSX_readInt(Piggy_fp); size -= sizeof(int); N_sounds = PHYSFSX_readInt(Piggy_fp); size -= sizeof(int); header_size = (N_bitmaps*sizeof(DiskBitmapHeader)) + (N_sounds*sizeof(DiskSoundHeader)); for (i=0; i<N_bitmaps; i++ ) { DiskBitmapHeader_read(&bmh, Piggy_fp); GameBitmapFlags[i+1] = 0; if ( bmh.flags & BM_FLAG_TRANSPARENT ) GameBitmapFlags[i+1] |= BM_FLAG_TRANSPARENT; if ( bmh.flags & BM_FLAG_SUPER_TRANSPARENT ) GameBitmapFlags[i+1] |= BM_FLAG_SUPER_TRANSPARENT; if ( bmh.flags & BM_FLAG_NO_LIGHTING ) GameBitmapFlags[i+1] |= BM_FLAG_NO_LIGHTING; if ( bmh.flags & BM_FLAG_RLE ) GameBitmapFlags[i+1] |= BM_FLAG_RLE; GameBitmapOffset[i+1] = bmh.offset + header_size + (sizeof(int)*2) + Pigdata_start; Assert( (i+1) == Num_bitmap_files ); //size -= sizeof(DiskBitmapHeader); memcpy( temp_name_read, bmh.name, 8 ); temp_name_read[8] = 0; if ( bmh.dflags & DBM_FLAG_ABM ) sprintf( temp_name, "%s#%d", temp_name_read, bmh.dflags & 63 ); else strcpy( temp_name, temp_name_read ); memset( &temp_bitmap, 0, sizeof(grs_bitmap) ); gr_init_bitmap( &temp_bitmap, 0, 0, 0, (bmh.dflags & DBM_FLAG_LARGE) ? bmh.width + 256 : bmh.width, bmh.height, (bmh.dflags & DBM_FLAG_LARGE) ? bmh.width + 256 : bmh.width, Piggy_bitmap_cache_data); temp_bitmap.bm_flags |= BM_FLAG_PAGED_OUT; temp_bitmap.avg_color = bmh.avg_color; if (MacPig) { // HACK HACK HACK!!!!! if (!strnicmp(bmh.name, "cockpit", 7) || !strnicmp(bmh.name, "status", 6) || !strnicmp(bmh.name, "rearview", 8)) { temp_bitmap.bm_w = temp_bitmap.bm_rowsize = 640; if (GameBitmapFlags[i+1] & BM_FLAG_RLE) GameBitmapFlags[i+1] |= BM_FLAG_RLE_BIG; } if (!strnicmp(bmh.name, "cockpit", 7) || !strnicmp(bmh.name, "rearview", 8)) temp_bitmap.bm_h = 480; } piggy_register_bitmap( &temp_bitmap, temp_name, 1 ); } for (i=0; !MacPig && i<N_sounds; i++ ) { DiskSoundHeader_read(&sndh, Piggy_fp); //size -= sizeof(DiskSoundHeader); #ifdef ALLEGRO temp_sound.len = sndh.length; #else temp_sound.length = sndh.length; #endif //added on 11/13/99 by Victor Rachels to ready for changing freq temp_sound.bits = 8; temp_sound.freq = 11025; //end this section addition - VR temp_sound.data = (ubyte *)(sndh.offset + header_size + (sizeof(int)*2)+Pigdata_start); SoundOffset[Num_sound_files] = sndh.offset + header_size + (sizeof(int)*2)+Pigdata_start; if (PCSharePig) SoundCompressed[Num_sound_files] = sndh.data_length; memcpy( temp_name_read, sndh.name, 8 ); temp_name_read[8] = 0; piggy_register_sound( &temp_sound, temp_name_read, 1 ); sbytes += sndh.length; } if (!MacPig) { SoundBits = d_malloc( sbytes + 16 ); if ( SoundBits == NULL ) Error( "Not enough memory to load DESCENT.PIG sounds\n"); } #if 1 //def EDITOR Piggy_bitmap_cache_size = size - header_size - sbytes + 16; Assert( Piggy_bitmap_cache_size > 0 ); #else Piggy_bitmap_cache_size = PIGGY_BUFFER_SIZE; if (GameArg.SysLowMem) Piggy_bitmap_cache_size = PIGGY_SMALL_BUFFER_SIZE; #endif BitmapBits = d_malloc( Piggy_bitmap_cache_size ); if ( BitmapBits == NULL ) Error( "Not enough memory to load DESCENT.PIG bitmaps\n" ); Piggy_bitmap_cache_data = BitmapBits; Piggy_bitmap_cache_next = 0; return retval; }
int dd_gfx_loadbitmap2D(unsigned short handle, void *buf, int rleflag) { HRESULT ddresult; DDSURFACEDESC ddsd; char *ptr; int pitch, i; grs_bitmap tbmp; Assert(handle != 0); if (!dd_gfx_initialized) return 0; handle--; // Convert to valid handle RedoLock: memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddresult = IDirectDrawSurface_Lock(gfxBitmap[handle].lpdds, NULL, &ddsd, DDLOCK_WAIT, NULL); if (ddresult != DD_OK) { if (ddresult == DDERR_SURFACELOST) { ddresult = IDirectDrawSurface_Restore(gfxBitmap[handle].lpdds); if (ddresult != DD_OK) { if (ddresult != DDERR_WRONGMODE) { logentry("DDGFX::Restore::Surface err: %x\n", ddresult); return 1; } else { LPDIRECTDRAWSURFACE lpdds; DDCOLORKEY ddck; IDirectDrawSurface_Release(lpdds); gfxBitmap[handle].lpdds = NULL; memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY; ddsd.dwWidth = gfxBitmap[handle].w; ddsd.dwHeight = gfxBitmap[handle].h; ddresult = IDirectDraw_CreateSurface(_lpDD, &ddsd, &lpdds, NULL); if (ddresult != DD_OK) { mprintf((0, "DDGFX: Failed to restore vidmem 2d bitmap.\n")); return 1; } ddck.dwColorSpaceLowValue = TRANSPARENCY_COLOR; ddck.dwColorSpaceHighValue = TRANSPARENCY_COLOR; IDirectDrawSurface_SetColorKey(lpdds, DDCKEY_SRCBLT, &ddck); gfxBitmap[handle].lpdds = lpdds; } } goto RedoLock; } else { mprintf((0, "DDGFX:Unable to lock surface!!\n")); return 1; } } // Locked! ptr = ddsd.lpSurface; pitch = ddsd.lPitch; gr_init_bitmap(&tbmp, BM_LINEAR, 0,0,gfxBitmap[handle].w, gfxBitmap[handle].h, gfxBitmap[handle].w, buf); if (rleflag) tbmp.bm_flags = BM_FLAG_RLE; for(i = 0; i < gfxBitmap[handle].h; i++) { extern ubyte scale_rle_data[]; if (rleflag) { decode_row(&tbmp,i); memcpy(ptr+(i*pitch), scale_rle_data, gfxBitmap[handle].w); } else memcpy(ptr+(i*pitch), (ubyte*)(buf)+(i*gfxBitmap[handle].w), gfxBitmap[handle].w); } IDirectDrawSurface_Unlock(gfxBitmap[handle].lpdds, ptr); // Unlocked... return 0; }