2006-04-23 06:44:19 +00:00
|
|
|
/*
|
|
|
|
* High-colour textures support for Polymost
|
|
|
|
* by Jonathon Fowler
|
|
|
|
* See the included license file "BUILDLIC.TXT" for license info.
|
|
|
|
*/
|
|
|
|
|
2008-12-02 10:44:39 +00:00
|
|
|
#ifdef POLYMOST
|
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
#include "compat.h"
|
2009-02-19 16:47:54 +00:00
|
|
|
#include "kplib.h"
|
2008-12-02 10:44:39 +00:00
|
|
|
#include "hightile.h"
|
|
|
|
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
palette_t hictinting[MAXPALOOKUPS];
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2008-12-02 10:44:39 +00:00
|
|
|
hicreplctyp *hicreplc[MAXTILES];
|
|
|
|
char hicfirstinit = 0;
|
2006-04-23 06:44:19 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// find the index into hicreplc[] which contains the replacement tile particulars
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
hicreplctyp * hicfindsubst(int32_t picnum, int32_t palnum, int32_t skybox)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
if (!hicfirstinit || (uint32_t)picnum >= (uint32_t)MAXTILES) return NULL;
|
2007-12-12 17:42:14 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
if (skybox)
|
|
|
|
{
|
|
|
|
hicreplctyp *hr = hicreplc[picnum];
|
|
|
|
for (; hr; hr = hr->next)
|
|
|
|
if (hr->palnum == palnum && hr->skybox && !hr->skybox->ignore)
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
else
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
hicreplctyp *hr = hicreplc[picnum];
|
|
|
|
for (; hr; hr = hr->next)
|
|
|
|
if (hr->palnum == palnum && !hr->ignore)
|
|
|
|
return hr;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2007-02-15 22:26:50 +00:00
|
|
|
if (!palnum || palnum >= (MAXPALOOKUPS - RESERVEDPALS)) break;
|
2006-04-24 19:04:22 +00:00
|
|
|
palnum = 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
while (1);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
return NULL; // no replacement found
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// hicinit()
|
2008-02-24 00:46:57 +00:00
|
|
|
// Initialize the high-colour stuff to default.
|
2006-04-23 06:44:19 +00:00
|
|
|
//
|
|
|
|
void hicinit(void)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i,j;
|
2006-04-24 19:04:22 +00:00
|
|
|
hicreplctyp *hr, *next;
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<MAXPALOOKUPS; i++) // all tints should be 100%
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hictinting[i].r = hictinting[i].g = hictinting[i].b = 0xff;
|
|
|
|
hictinting[i].f = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hicfirstinit)
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=MAXTILES-1; i>=0; i--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
for (hr=hicreplc[i]; hr;)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
next = hr->next;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hr->skybox)
|
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=5; j>=0; j--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
if (hr->skybox->face[j])
|
|
|
|
{
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(hr->skybox->face[j]);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(hr->skybox);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2009-10-07 06:47:35 +00:00
|
|
|
if (hr->filename) Bfree(hr->filename);
|
|
|
|
Bfree(hr);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
hr = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memset(hicreplc,0,sizeof(hicreplc));
|
|
|
|
|
|
|
|
hicfirstinit = 1;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// hicsetpalettetint(pal,r,g,b,effect)
|
|
|
|
// The tinting values represent a mechanism for emulating the effect of global sector
|
|
|
|
// palette shifts on true-colour textures and only true-colour textures.
|
|
|
|
// effect bitset: 1 = greyscale, 2 = invert
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
void hicsetpalettetint(int32_t palnum, char r, char g, char b, char effect)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return;
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!hicfirstinit) hicinit();
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
hictinting[palnum].r = r;
|
|
|
|
hictinting[palnum].g = g;
|
|
|
|
hictinting[palnum].b = b;
|
|
|
|
hictinting[palnum].f = effect & HICEFFECTMASK;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// hicsetsubsttex(picnum,pal,filen,alphacut)
|
|
|
|
// Specifies a replacement graphic file for an ART tile.
|
|
|
|
//
|
2011-01-16 00:23:39 +00:00
|
|
|
int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float alphacut, float xscale, float yscale, float specpower, float specfactor, char flags)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hicreplctyp *hr, *hrn;
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1;
|
|
|
|
if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1;
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!hicfirstinit) hicinit();
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (hr = hicreplc[picnum]; hr; hr = hr->next)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hr->palnum == palnum)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hr)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// no replacement yet defined
|
2009-10-07 06:47:35 +00:00
|
|
|
hrn = (hicreplctyp *)Bcalloc(1,sizeof(hicreplctyp));
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!hrn) return -1;
|
|
|
|
hrn->palnum = palnum;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else hrn = hr;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
// store into hicreplc the details for this replacement
|
2009-10-07 06:47:35 +00:00
|
|
|
if (hrn->filename) Bfree(hrn->filename);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2009-10-07 06:47:35 +00:00
|
|
|
hrn->filename = Bstrdup(filen);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hrn->filename)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hrn->skybox) return -1; // don't free the base structure if there's a skybox defined
|
2009-10-07 06:47:35 +00:00
|
|
|
if (hr == NULL) Bfree(hrn); // not yet a link in the chain
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
hrn->ignore = 0;
|
2007-02-17 02:23:50 +00:00
|
|
|
hrn->alphacut = min(alphacut,1.0);
|
|
|
|
hrn->xscale = xscale;
|
|
|
|
hrn->yscale = yscale;
|
2009-03-28 12:14:37 +00:00
|
|
|
hrn->specpower = specpower;
|
|
|
|
hrn->specfactor = specfactor;
|
2006-04-24 19:04:22 +00:00
|
|
|
hrn->flags = flags;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hr == NULL)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hrn->next = hicreplc[picnum];
|
|
|
|
hicreplc[picnum] = hrn;
|
|
|
|
}
|
|
|
|
|
2010-06-27 10:08:58 +00:00
|
|
|
if (tilesizx[picnum]<=0 || tilesizy[picnum]<=0)
|
|
|
|
{
|
|
|
|
static int32_t first=1;
|
|
|
|
OSD_Printf("warning: defined hightile replacement for empty tile %d.", picnum);
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
OSD_Printf(" Maybe some tiles???.art are not loaded?");
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
OSD_Printf("\n");
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//printf("Replacement [%d,%d]: %s\n", picnum, palnum, hicreplc[i]->filename);
|
|
|
|
|
|
|
|
return 0;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// hicsetskybox(picnum,pal,faces[6])
|
|
|
|
// Specifies a graphic files making up a skybox.
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6])
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hicreplctyp *hr, *hrn;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t j;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1;
|
|
|
|
if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=5; j>=0; j--) if (!faces[j]) return -1;
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!hicfirstinit) hicinit();
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (hr = hicreplc[picnum]; hr; hr = hr->next)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hr->palnum == palnum)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hr)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// no replacement yet defined
|
2009-10-07 06:47:35 +00:00
|
|
|
hrn = (hicreplctyp *)Bcalloc(1,sizeof(hicreplctyp));
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!hrn) return -1;
|
|
|
|
|
|
|
|
hrn->palnum = palnum;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else hrn = hr;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hrn->skybox)
|
|
|
|
{
|
2009-10-07 06:47:35 +00:00
|
|
|
hrn->skybox = (struct hicskybox_t *)Bcalloc(1,sizeof(struct hicskybox_t));
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hrn->skybox)
|
|
|
|
{
|
2009-10-07 06:47:35 +00:00
|
|
|
if (hr == NULL) Bfree(hrn); // not yet a link in the chain
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=5; j>=0; j--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hrn->skybox->face[j])
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(hrn->skybox->face[j]);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// store each face's filename
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=0; j<6; j++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-10-07 06:47:35 +00:00
|
|
|
hrn->skybox->face[j] = Bstrdup(faces[j]);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!hrn->skybox->face[j])
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
for (--j; j>=0; --j) // free any previous faces
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(hrn->skybox->face[j]);
|
|
|
|
Bfree(hrn->skybox);
|
2006-04-24 19:04:22 +00:00
|
|
|
hrn->skybox = NULL;
|
2009-10-07 06:47:35 +00:00
|
|
|
if (hr == NULL) Bfree(hrn);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hrn->skybox->ignore = 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hr == NULL)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hrn->next = hicreplc[picnum];
|
|
|
|
hicreplc[picnum] = hrn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// hicclearsubst(picnum,pal)
|
|
|
|
// Clears a replacement for an ART tile, including skybox faces.
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t hicclearsubst(int32_t picnum, int32_t palnum)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hicreplctyp *hr, *hrn = NULL;
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1;
|
|
|
|
if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1;
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!hicfirstinit) return 0;
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (hr = hicreplc[picnum]; hr; hrn = hr, hr = hr->next)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hr->palnum == palnum)
|
|
|
|
break;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!hr) return 0;
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2009-10-07 06:47:35 +00:00
|
|
|
if (hr->filename) Bfree(hr->filename);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (hr->skybox)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=5; i>=0; i--)
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hr->skybox->face[i])
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(hr->skybox->face[i]);
|
|
|
|
Bfree(hr->skybox);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hrn) hrn->next = hr->next;
|
|
|
|
else hicreplc[picnum] = hr->next;
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(hr);
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
2008-12-02 10:44:39 +00:00
|
|
|
|
|
|
|
#else /* POLYMOST */
|
|
|
|
|
2009-02-28 07:44:54 +00:00
|
|
|
#include "inttypes.h"
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
void hicsetpalettetint(int32_t palnum, char r, char g, char b, char effect) { }
|
2011-01-16 00:23:39 +00:00
|
|
|
int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float alphacut) { return 0; }
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6]) { return 0; }
|
|
|
|
int32_t hicclearsubst(int32_t picnum, int32_t palnum) { return 0; }
|
2008-12-02 10:44:39 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|