mirror of
https://github.com/libretro/libretro-tyrquake.git
synced 2024-11-23 08:00:17 +00:00
draw: separate on-disk dpic_t type from in-memory qpic_t
Mainly because taking the address of the data pointer and casting to byte * is something easily confused. Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
parent
864a032c3b
commit
e21f7269bc
@ -71,13 +71,14 @@ static int menu_numcachepics;
|
||||
const qpic_t *
|
||||
Draw_PicFromWad(const char *name)
|
||||
{
|
||||
qpic_t *pic, *picdata;
|
||||
qpic_t *pic;
|
||||
dpic_t *dpic;
|
||||
|
||||
picdata = W_GetLumpName(&host_gfx, name);
|
||||
dpic = W_GetLumpName(&host_gfx, name);
|
||||
pic = Hunk_AllocName(sizeof(*pic), "qpic_t");
|
||||
pic->width = picdata->width;
|
||||
pic->height = picdata->height;
|
||||
pic->data = (byte *)&picdata->data;
|
||||
pic->width = dpic->width;
|
||||
pic->height = dpic->height;
|
||||
pic->data = dpic->data;
|
||||
|
||||
return pic;
|
||||
}
|
||||
@ -91,7 +92,7 @@ qpic_t *
|
||||
Draw_CachePic(const char *path)
|
||||
{
|
||||
cachepic_t *cachepic;
|
||||
qpic_t *pic;
|
||||
dpic_t *dpic;
|
||||
int i;
|
||||
|
||||
cachepic = menu_cachepics;
|
||||
@ -106,23 +107,23 @@ Draw_CachePic(const char *path)
|
||||
snprintf(cachepic->name, sizeof(cachepic->name), "%s", path);
|
||||
}
|
||||
|
||||
pic = Cache_Check(&cachepic->cache);
|
||||
if (pic) {
|
||||
dpic = Cache_Check(&cachepic->cache);
|
||||
if (dpic) {
|
||||
/* Cache data may have been moved */
|
||||
cachepic->pic.data = (byte *)&pic->data;
|
||||
cachepic->pic.data = dpic->data;
|
||||
return &cachepic->pic;
|
||||
}
|
||||
|
||||
/* load the pic from disk */
|
||||
COM_LoadCacheFile(path, &cachepic->cache);
|
||||
pic = cachepic->cache.data;
|
||||
if (!pic)
|
||||
dpic = cachepic->cache.data;
|
||||
if (!dpic)
|
||||
Sys_Error("%s: failed to load %s", __func__, path);
|
||||
|
||||
SwapPic(pic);
|
||||
cachepic->pic.width = pic->width;
|
||||
cachepic->pic.height = pic->height;
|
||||
cachepic->pic.data = (byte *)&pic->data;
|
||||
SwapPic(dpic);
|
||||
cachepic->pic.width = dpic->width;
|
||||
cachepic->pic.height = dpic->height;
|
||||
cachepic->pic.data = dpic->data;
|
||||
|
||||
return &cachepic->pic;
|
||||
}
|
||||
@ -137,20 +138,20 @@ Draw_Init(void)
|
||||
{
|
||||
static qpic_t draw_disc_pic;
|
||||
static qpic_t draw_backtile_pic;
|
||||
qpic_t *pic;
|
||||
dpic_t *dpic;
|
||||
|
||||
draw_chars = W_GetLumpName(&host_gfx, "conchars");
|
||||
|
||||
pic = W_GetLumpName(&host_gfx, "disc");
|
||||
draw_disc_pic.width = pic->width;
|
||||
draw_disc_pic.height = pic->height;
|
||||
draw_disc_pic.data = (byte *)&pic->data;
|
||||
dpic = W_GetLumpName(&host_gfx, "disc");
|
||||
draw_disc_pic.width = dpic->width;
|
||||
draw_disc_pic.height = dpic->height;
|
||||
draw_disc_pic.data = dpic->data;
|
||||
draw_disc = &draw_disc_pic;
|
||||
|
||||
pic = W_GetLumpName(&host_gfx, "backtile");
|
||||
draw_backtile_pic.width = pic->width;
|
||||
draw_backtile_pic.height = pic->height;
|
||||
draw_backtile_pic.data = (byte *)&pic->data;
|
||||
dpic = W_GetLumpName(&host_gfx, "backtile");
|
||||
draw_backtile_pic.width = dpic->width;
|
||||
draw_backtile_pic.height = dpic->height;
|
||||
draw_backtile_pic.data = dpic->data;
|
||||
draw_backtile = &draw_backtile_pic;
|
||||
|
||||
r_rectdesc.width = draw_backtile->width;
|
||||
@ -160,7 +161,6 @@ Draw_Init(void)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
Draw_Character
|
||||
|
@ -245,17 +245,18 @@ const qpic_t *
|
||||
Draw_PicFromWad(const char *name)
|
||||
{
|
||||
qpic_t *pic;
|
||||
dpic_t *dpic;
|
||||
glpic_t *glpic;
|
||||
scrap_t *scrap;
|
||||
|
||||
glpic = Hunk_AllocName(sizeof(*glpic), "qpic_t");
|
||||
pic = W_GetLumpName(&host_gfx, name);
|
||||
dpic = W_GetLumpName(&host_gfx, name);
|
||||
|
||||
/* Set up the embedded pic */
|
||||
glpic->pic.width = pic->width;
|
||||
glpic->pic.height = pic->height;
|
||||
glpic->pic.data = (byte *)&pic->data;
|
||||
pic = &glpic->pic;
|
||||
pic->width = dpic->width;
|
||||
pic->height = dpic->height;
|
||||
pic->data = dpic->data;
|
||||
|
||||
/* load little ones into the scrap */
|
||||
if (pic->width < 64 && pic->height < 64) {
|
||||
@ -295,6 +296,7 @@ const qpic_t *
|
||||
Draw_CachePic(const char *path)
|
||||
{
|
||||
cachepic_t *cachepic;
|
||||
dpic_t *dpic;
|
||||
qpic_t *pic;
|
||||
int i;
|
||||
|
||||
@ -309,13 +311,13 @@ Draw_CachePic(const char *path)
|
||||
|
||||
/* load the pic from disk */
|
||||
snprintf(cachepic->name, sizeof(cachepic->name), "%s", path);
|
||||
pic = COM_LoadHunkFile(path);
|
||||
if (!pic)
|
||||
dpic = COM_LoadHunkFile(path);
|
||||
if (!dpic)
|
||||
Sys_Error("%s: failed to load %s", __func__, path);
|
||||
SwapPic(pic);
|
||||
cachepic->glpic.pic.width = pic->width;
|
||||
cachepic->glpic.pic.height = pic->height;
|
||||
cachepic->glpic.pic.data = (byte *)&pic->data;
|
||||
SwapPic(dpic);
|
||||
cachepic->glpic.pic.width = dpic->width;
|
||||
cachepic->glpic.pic.height = dpic->height;
|
||||
cachepic->glpic.pic.data = dpic->data;
|
||||
pic = &cachepic->glpic.pic;
|
||||
|
||||
// HACK HACK HACK --- we need to keep the bytes for
|
||||
@ -475,6 +477,7 @@ void
|
||||
Draw_Init(void)
|
||||
{
|
||||
int i;
|
||||
dpic_t *dpic;
|
||||
qpic_t *pic;
|
||||
char version[5];
|
||||
|
||||
@ -509,13 +512,13 @@ Draw_Init(void)
|
||||
cs_texture = GL_LoadTexture("crosshair", 8, 8, cs_data, false, true);
|
||||
|
||||
conback = Hunk_AllocName(sizeof(*conback), "qpic_t");
|
||||
pic = COM_LoadHunkFile("gfx/conback.lmp");
|
||||
if (!pic)
|
||||
dpic = COM_LoadHunkFile("gfx/conback.lmp");
|
||||
if (!dpic)
|
||||
Sys_Error("Couldn't load gfx/conback.lmp");
|
||||
SwapPic(pic);
|
||||
conback->pic.width = pic->width;
|
||||
conback->pic.height = pic->height;
|
||||
conback->pic.data = (byte *)&pic->data;
|
||||
SwapPic(dpic);
|
||||
conback->pic.width = dpic->width;
|
||||
conback->pic.height = dpic->height;
|
||||
conback->pic.data = dpic->data;
|
||||
pic = &conback->pic;
|
||||
|
||||
/* hack the version number directly into the pic */
|
||||
|
@ -90,7 +90,7 @@ W_LoadWadFile(wad_t *wad, const char *filename)
|
||||
lump->size = LittleLong(lump->size);
|
||||
W_CleanupName(lump->name, lump->name);
|
||||
if (lump->type == TYP_QPIC)
|
||||
SwapPic((qpic_t *)(wad->base + lump->filepos));
|
||||
SwapPic((dpic_t *)(wad->base + lump->filepos));
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,8 +149,8 @@ automatic byte swapping
|
||||
*/
|
||||
|
||||
void
|
||||
SwapPic(qpic_t *pic)
|
||||
SwapPic(dpic_t *dpic)
|
||||
{
|
||||
pic->width = LittleLong(pic->width);
|
||||
pic->height = LittleLong(pic->height);
|
||||
dpic->width = LittleLong(dpic->width);
|
||||
dpic->height = LittleLong(dpic->height);
|
||||
}
|
||||
|
@ -40,6 +40,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#define TYP_SOUND 67
|
||||
#define TYP_MIPTEX 68
|
||||
|
||||
typedef struct {
|
||||
int width, height;
|
||||
byte data[];
|
||||
} dpic_t;
|
||||
|
||||
typedef struct {
|
||||
int width, height;
|
||||
byte *data;
|
||||
@ -74,6 +79,6 @@ lumpinfo_t *W_GetLumpinfo(wad_t *wad, const char *name);
|
||||
void *W_GetLumpName(wad_t *wad, const char *name);
|
||||
void *W_GetLumpNum(wad_t *wad, int num);
|
||||
|
||||
void SwapPic(qpic_t *pic);
|
||||
void SwapPic(dpic_t *dpic);
|
||||
|
||||
#endif /* WAD_H */
|
||||
|
Loading…
Reference in New Issue
Block a user