mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-01-22 11:28:56 +00:00
small bitmap code cleanup
This commit is contained in:
parent
1f94e623b2
commit
5d8affda0e
@ -394,11 +394,6 @@ int FindTextureBitmapName(const char *name) {
|
||||
if ((!stricmp(GameBitmaps[vc->frames[t]].name, name)))
|
||||
retval = i;
|
||||
|
||||
/*if (not_res)
|
||||
{
|
||||
FreeVClipResidency (GameTextures[i].bm_handle);
|
||||
}*/
|
||||
|
||||
if (retval != -1)
|
||||
return retval;
|
||||
} else {
|
||||
|
@ -236,20 +236,6 @@ void FreeVClip(int num) {
|
||||
ASSERT(Num_vclips >= 0);
|
||||
}
|
||||
|
||||
// Frees up the bitmaps used by a vclip
|
||||
void FreeVClipResidency(int num) {
|
||||
ASSERT(GameVClips[num].used > 0);
|
||||
|
||||
mprintf((0, "Freeing vclip residency!\n"));
|
||||
|
||||
if (!(GameVClips[num].flags & VCF_NOT_RESIDENT)) {
|
||||
for (int i = 0; i < GameVClips[num].num_frames; i++)
|
||||
bm_FreeBitmap(GameVClips[num].frames[i]);
|
||||
}
|
||||
|
||||
GameVClips[num].flags |= VCF_NOT_RESIDENT;
|
||||
}
|
||||
|
||||
// Saves a given video clip to a file
|
||||
// Returns 1 if everything ok, 0 otherwise
|
||||
// "num" is index into GameVClip array
|
||||
@ -643,55 +629,3 @@ int FindVClipName(const char *name) {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Returns frame "frame" of vclip "vclip". Will mod the frame so that there
|
||||
// is no overflow
|
||||
int GetVClipBitmap(int v, int frame) {
|
||||
ASSERT(GameVClips[v].used > 0);
|
||||
ASSERT(v >= 0 && v < MAX_VCLIPS);
|
||||
ASSERT(frame >= 0);
|
||||
|
||||
vclip *vc = &GameVClips[v];
|
||||
|
||||
int bm = vc->frames[frame % vc->num_frames];
|
||||
|
||||
return bm;
|
||||
}
|
||||
|
||||
// Loads an animation from an IFF ANIM file
|
||||
int AllocLoadIFFAnimClip(const char *filename, int texture) {
|
||||
/* char name[PAGENAME_LEN];
|
||||
int i;
|
||||
|
||||
ASSERT (filename!=NULL);
|
||||
|
||||
ChangeVClipName (filename,name);
|
||||
|
||||
if ((i=FindVClipName(name))!=-1)
|
||||
{
|
||||
GameVClips[i].used++;
|
||||
return i;
|
||||
}
|
||||
|
||||
mprintf ((0,"Loading IFF vclip %s\n",name));
|
||||
|
||||
int vcnum=AllocVClip ();
|
||||
|
||||
ASSERT (vcnum>=0);
|
||||
|
||||
vclip *vc=&GameVClips[vcnum];
|
||||
|
||||
vc->num_frames=bm_AllocLoadIFFAnim (filename,vc->frames,0);
|
||||
if (vc->num_frames==-1)
|
||||
{
|
||||
mprintf ((0,"Couldn't load vclip named %d!\n",name));
|
||||
FreeVClip (vcnum);
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy (vc->name,name);
|
||||
|
||||
return vcnum;*/
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -77,17 +77,7 @@ void ChangeVClipName(const char *src, char *dest);
|
||||
// or index of vclip with name
|
||||
int FindVClipName(const char *name);
|
||||
|
||||
// Returns frame "frame" of vclip "vclip". Will mod the frame so that there
|
||||
// is no overflow
|
||||
int GetVClipBitmap(int vclip, int frame);
|
||||
|
||||
// Loads an animation from an IFF ANIM file
|
||||
int AllocLoadIFFAnimClip(const char *filename, int texture);
|
||||
|
||||
// Pages in a vclip if it needs to be
|
||||
void PageInVClip(int vcnum);
|
||||
|
||||
// Frees up the bitmaps used by a vclip
|
||||
void FreeVClipResidency(int vcnum);
|
||||
|
||||
#endif
|
||||
|
@ -586,18 +586,6 @@ int bm_FindBitmapName(const char *name) {
|
||||
return fnode->data - GameBitmaps;
|
||||
} else
|
||||
return -1;
|
||||
/*
|
||||
for (i=0;i<MAX_BITMAPS && num_counted<Num_of_bitmaps;i++)
|
||||
{
|
||||
if (GameBitmaps[i].used)
|
||||
{
|
||||
num_counted++;
|
||||
if(!stricmp (GameBitmaps[i].name,name))
|
||||
return i;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return -1;
|
||||
}
|
||||
// Given a handle, frees the bitmap memory and flags this bitmap as unused
|
||||
void bm_FreeBitmap(int handle) {
|
||||
@ -876,97 +864,6 @@ int bm_AllocLoadFileBitmap(const char *fname, int mipped, int format) {
|
||||
// Allocs and loads a bitmap but doesn't actually load texel data!
|
||||
// Returns the handle of the loaded bitmap
|
||||
// Returns -1 if something is wrong
|
||||
/*
|
||||
int bm_AllocLoadFileNoMemBitmap (char *fname,int mipped)
|
||||
{
|
||||
CFILE *infile;
|
||||
if (!Bitmaps_initted)
|
||||
{
|
||||
Int3();
|
||||
mprintf ((0,"Bitmaps not initted!!!\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *filename,name[BITMAP_NAME_LEN];
|
||||
int n,src_bm;
|
||||
|
||||
filename = fname;
|
||||
|
||||
// due to a bug in some people's tablefile editors, we got to make sure there is
|
||||
// no path if there shouldn't be
|
||||
if(!cfexist(filename))
|
||||
{
|
||||
// generate a possible new filename
|
||||
char *end_ptr,*start_ptr;
|
||||
start_ptr = fname;
|
||||
end_ptr = start_ptr + strlen(start_ptr) - 1;
|
||||
while( (end_ptr >= start_ptr) && (*end_ptr!='\\') ) end_ptr--;
|
||||
if(end_ptr < start_ptr)
|
||||
{
|
||||
mprintf((0,"Unable to find bitmap %s\n",fname));
|
||||
return -1;
|
||||
}
|
||||
ASSERT(*end_ptr=='\\');
|
||||
end_ptr++;
|
||||
filename = end_ptr;
|
||||
mprintf((0,"Couldn't find %s, so gonna try %s\n",fname,filename));
|
||||
}
|
||||
|
||||
|
||||
// Check to see if this bitmap is already in memory, if so, just return that
|
||||
// bitmaps handle
|
||||
if ((n=bm_TestName(filename))!=-1)
|
||||
{
|
||||
GameBitmaps[n].used++;
|
||||
mprintf ((0,"Found duplicate bitmap %s.\n",GameBitmaps[n].name));
|
||||
return n;
|
||||
}
|
||||
|
||||
bm_ChangeEndName (filename,name);
|
||||
if (strlen(name)>33)
|
||||
{
|
||||
mprintf ((0,"ERROR!! This bitmaps name is too long, try shortening it and retry!\n"));
|
||||
return -1;
|
||||
}
|
||||
// Try to open the file. If we can't load it from the network if possible
|
||||
infile=(CFILE *)cfopen (filename,"rb");
|
||||
if( !infile)
|
||||
{
|
||||
mprintf ((0,"bm_AllocLoadFileBitmap: Can't open file named %s.\n",filename));
|
||||
|
||||
#ifdef _DEBUG
|
||||
return BAD_BITMAP_HANDLE; // return the bad texture
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
// Check to see if this is IFF. If so, call the IFF reader. If not,
|
||||
// rewind the file and read as a TGA
|
||||
|
||||
int filetype=bm_GetFileType (infile,filename);
|
||||
|
||||
switch (filetype)
|
||||
{
|
||||
case BM_FILETYPE_TGA:
|
||||
// reads a tga or an outrage graphics file (ogf)
|
||||
src_bm=bm_tga_load_short_file(infile,name);
|
||||
break;
|
||||
default:
|
||||
Int3(); // Can't read this type
|
||||
break;
|
||||
}
|
||||
cfclose (infile);
|
||||
if (src_bm<0)
|
||||
{
|
||||
mprintf ((0,"Couldn't load %s.",filename));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return src_bm; // We made it!
|
||||
}*/
|
||||
// Allocs and loads a bitmap but doesn't actually load texel data!
|
||||
// Returns the handle of the loaded bitmap
|
||||
// Returns -1 if something is wrong
|
||||
int bm_AllocLoadFileNoMemBitmap(const char *fname, int mipped, int format) {
|
||||
if (!Bitmaps_initted) {
|
||||
Int3();
|
||||
@ -1448,71 +1345,6 @@ void bm_ScaleBitmapToBitmap(int dest, int src) {
|
||||
}
|
||||
GameBitmaps[dest].flags |= BF_CHANGED;
|
||||
}
|
||||
// Returns whether or not this bitmap is in use
|
||||
int bm_used(int n) {
|
||||
ASSERT(n >= 0 && n < MAX_BITMAPS);
|
||||
return GameBitmaps[n].used;
|
||||
}
|
||||
// Loads a series of bitmaps from an IFF file
|
||||
int bm_AllocLoadIFFAnim(const char *filename, int *dest_index, int mipped) {
|
||||
char name[BITMAP_NAME_LEN];
|
||||
char str[BITMAP_NAME_LEN + 16];
|
||||
int num_bitmaps, i, src_bm, n;
|
||||
int bm_index[200];
|
||||
bm_ChangeEndName(filename, name);
|
||||
|
||||
num_bitmaps = bm_iff_read_animbrush(filename, bm_index);
|
||||
if (num_bitmaps < 0) {
|
||||
mprintf((0, "Couldn't load %s.", filename));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Allocate space for our bitmap. If its mipped it must mean its a texture,
|
||||
// so make it TEXTURE_WIDTH x TEXTURE_SIZE
|
||||
for (i = 0; i < num_bitmaps; i++) {
|
||||
src_bm = bm_index[i];
|
||||
ASSERT(GameBitmaps[src_bm].used);
|
||||
if (mipped) {
|
||||
if ((bm_mipped(src_bm)) == 0) // If we want a mipped but we don't have one
|
||||
{
|
||||
int w = bm_w(src_bm, 0);
|
||||
int h = bm_h(src_bm, 0);
|
||||
|
||||
n = bm_AllocBitmap(w, h, mipped * (((w * h * 2) / 3)));
|
||||
|
||||
ASSERT(n >= 0);
|
||||
bm_ScaleBitmapToBitmap(n, src_bm);
|
||||
bm_FreeBitmap(src_bm);
|
||||
|
||||
bm_GenerateMipMaps(n);
|
||||
} else
|
||||
n = src_bm;
|
||||
} else // If we don't want a mipped
|
||||
{
|
||||
if ((bm_mipped(src_bm)) == 0)
|
||||
n = src_bm;
|
||||
else // And this is already mipped
|
||||
{
|
||||
int w = bm_w(src_bm, 0);
|
||||
int h = bm_h(src_bm, 0);
|
||||
ushort *src_data, *dest_data;
|
||||
|
||||
n = bm_AllocBitmap(w, h, mipped * (((w * h * 2) / 3)));
|
||||
ASSERT(n >= 0);
|
||||
src_data = (ushort *)bm_data(src_bm, 0);
|
||||
dest_data = (ushort *)bm_data(n, 0);
|
||||
memcpy(dest_data, src_data, w * h * 2);
|
||||
|
||||
bm_FreeBitmap(src_bm);
|
||||
}
|
||||
}
|
||||
snprintf(str, sizeof(str), "%s%d", name, i);
|
||||
strcpy(GameBitmaps[n].name, str);
|
||||
dest_index[i] = n;
|
||||
bm_FreeBitmap(src_bm);
|
||||
}
|
||||
return num_bitmaps; // We made it!
|
||||
}
|
||||
// given a handle and a miplevel, returns the bytes per bitmap row
|
||||
int bm_rowsize(int handle, int miplevel) {
|
||||
int w;
|
||||
|
17
lib/bitmap.h
17
lib/bitmap.h
@ -18,13 +18,17 @@
|
||||
|
||||
#ifndef PSBITMAP_H
|
||||
#define PSBITMAP_H
|
||||
|
||||
#include "pstypes.h"
|
||||
#include "cfile.h"
|
||||
|
||||
#ifdef __LINUX__
|
||||
#include "linux/linux_fix.h" //needed for stricmp's throughout bitmap lib
|
||||
#endif
|
||||
|
||||
#define MAX_BITMAPS 5000
|
||||
#define NUM_MIP_LEVELS 5
|
||||
|
||||
// It really doesn't matter what these are, as long as its above 10
|
||||
#define OUTRAGE_4444_COMPRESSED_MIPPED 121
|
||||
#define OUTRAGE_1555_COMPRESSED_MIPPED 122
|
||||
@ -35,6 +39,7 @@
|
||||
#define OUTRAGE_COMPRESSED_OGF 127
|
||||
#define BITMAP_NAME_LEN 35
|
||||
#define BAD_BITMAP_HANDLE 0
|
||||
|
||||
// Bitmap flags
|
||||
#define BF_TRANSPARENT 1
|
||||
#define BF_CHANGED 2 // this bitmap has changed since last frame (useful for hardware cacheing)
|
||||
@ -44,10 +49,12 @@
|
||||
#define BF_WANTS_4444 32 // Read data as 4444 when this bitmap is paged in
|
||||
#define BF_BRAND_NEW 64 // This bitmap was just allocated and hasn't been to the video card
|
||||
#define BF_COMPRESSABLE 128 // This bitmap is compressable for 3dhardware that supports it
|
||||
|
||||
// Bitmap priorities
|
||||
#define BITMAP_FORMAT_STANDARD 0
|
||||
#define BITMAP_FORMAT_1555 0
|
||||
#define BITMAP_FORMAT_4444 1
|
||||
|
||||
typedef struct {
|
||||
ushort *data16; // 16bit data
|
||||
ushort width, height; // Width and height in pixels
|
||||
@ -60,6 +67,7 @@ typedef struct {
|
||||
ubyte format; // See bitmap format types above
|
||||
char name[BITMAP_NAME_LEN]; // Whats the name of this bitmap? (ie SteelWall)
|
||||
} bms_bitmap;
|
||||
|
||||
typedef struct chunked_bitmap {
|
||||
int pw, ph; // pixel width and height
|
||||
int w, h; // width and height in square bitmaps.
|
||||
@ -67,7 +75,7 @@ typedef struct chunked_bitmap {
|
||||
} chunked_bitmap;
|
||||
extern bms_bitmap GameBitmaps[MAX_BITMAPS];
|
||||
extern ulong Bitmap_memory_used;
|
||||
extern ubyte Memory_map[];
|
||||
|
||||
// Sets all the bitmaps to unused
|
||||
void bm_InitBitmaps();
|
||||
// Frees up all memory used by bitmaps
|
||||
@ -119,18 +127,12 @@ int bm_bpp(int handle);
|
||||
void bm_GenerateMipMaps(int handle);
|
||||
// Given two bitmaps, scales the data from src to the size of dest
|
||||
void bm_ScaleBitmapToBitmap(int dest, int src);
|
||||
// Returns whether or not this bitmap is in use
|
||||
int bm_used(int n);
|
||||
// Loads a series of bitmaps from an IFF file
|
||||
int bm_AllocLoadIFFAnim(const char *filename, int *dest_index, int mipped);
|
||||
// given a handle and a miplevel, returns the bytes per bitmap row
|
||||
int bm_rowsize(int handle, int miplevel);
|
||||
// Goes through the bitmap and sees if there is any transparency...if so, flag it!
|
||||
int bm_SetBitmapIfTransparent(int handle);
|
||||
// Saves the passed bitmap handle as a 24 bit uncompressed tga
|
||||
int bm_SaveBitmapTGA(const char *filename, int handle);
|
||||
// Sets the bitmap priority. This comes in handy for our 3d hardware
|
||||
void bm_set_priority(int handle, int priority);
|
||||
// Allocs and loads a bitmap but doesn't actually load texel data!
|
||||
// Returns the handle of the loaded bitmap
|
||||
// Returns -1 if something is wrong
|
||||
@ -152,4 +154,5 @@ void bm_FreeBitmapData(int handle);
|
||||
int bm_format(int handle);
|
||||
// Returns the number of mipmap levels
|
||||
int bm_miplevels(int handle);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user