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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kplib.h"
|
|
|
|
|
|
|
|
#define HICEFFECTMASK (1|2)
|
2006-09-29 21:36:12 +00:00
|
|
|
palette_t hictinting[MAXPALOOKUPS];
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2006-08-30 23:32:39 +00:00
|
|
|
//moved into polymost.h
|
|
|
|
/*struct hicskybox_t {
|
2006-04-24 19:04:22 +00:00
|
|
|
long ignore;
|
|
|
|
char *face[6];
|
2006-04-23 06:44:19 +00:00
|
|
|
};
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2006-04-23 06:44:19 +00:00
|
|
|
typedef struct hicreplc_t {
|
2006-04-24 19:04:22 +00:00
|
|
|
struct hicreplc_t *next;
|
|
|
|
char palnum, ignore, flags, filler;
|
|
|
|
char *filename;
|
|
|
|
float alphacut;
|
|
|
|
struct hicskybox_t *skybox;
|
2006-08-30 23:32:39 +00:00
|
|
|
} hicreplctyp;*/
|
2006-04-23 06:44:19 +00:00
|
|
|
static hicreplctyp *hicreplc[MAXTILES];
|
|
|
|
static char hicfirstinit = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// find the index into hicreplc[] which contains the replacement tile particulars
|
|
|
|
//
|
|
|
|
static hicreplctyp * hicfindsubst(long picnum, long palnum, long skybox)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hicreplctyp *hr;
|
|
|
|
|
|
|
|
if (!hicfirstinit) return NULL;
|
|
|
|
if ((unsigned long)picnum >= (unsigned long)MAXTILES) return NULL;
|
|
|
|
|
|
|
|
do {
|
|
|
|
for (hr = hicreplc[picnum]; hr; hr = hr->next) {
|
|
|
|
if (hr->palnum == palnum) {
|
|
|
|
if (skybox) {
|
|
|
|
if (hr->skybox && !hr->skybox->ignore) return hr;
|
|
|
|
} else {
|
|
|
|
if (!hr->ignore) return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-15 22:26:50 +00:00
|
|
|
if (!palnum || palnum >= (MAXPALOOKUPS - RESERVEDPALS)) break;
|
2006-04-24 19:04:22 +00:00
|
|
|
palnum = 0;
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
return NULL; // no replacement found
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// hicinit()
|
|
|
|
// Initialise the high-colour stuff to default.
|
|
|
|
//
|
|
|
|
void hicinit(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
long i,j;
|
|
|
|
hicreplctyp *hr, *next;
|
|
|
|
|
|
|
|
for (i=0;i<MAXPALOOKUPS;i++) { // all tints should be 100%
|
|
|
|
hictinting[i].r = hictinting[i].g = hictinting[i].b = 0xff;
|
|
|
|
hictinting[i].f = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hicfirstinit)
|
|
|
|
for (i=MAXTILES-1;i>=0;i--) {
|
|
|
|
for (hr=hicreplc[i]; hr; ) {
|
|
|
|
next = hr->next;
|
|
|
|
|
|
|
|
if (hr->skybox) {
|
|
|
|
for (j=5;j>=0;j--) {
|
|
|
|
if (hr->skybox->face[j]) {
|
|
|
|
free(hr->skybox->face[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(hr->skybox);
|
|
|
|
}
|
|
|
|
if (hr->filename) free(hr->filename);
|
|
|
|
free(hr);
|
|
|
|
|
|
|
|
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
|
|
|
|
//
|
|
|
|
void hicsetpalettetint(long palnum, unsigned char r, unsigned char g, unsigned char b, unsigned char effect)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return;
|
|
|
|
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.
|
|
|
|
//
|
2007-02-17 02:23:50 +00:00
|
|
|
int hicsetsubsttex(long picnum, long palnum, char *filen, float alphacut, float xscale, float yscale, char flags)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hicreplctyp *hr, *hrn;
|
|
|
|
|
|
|
|
if ((unsigned long)picnum >= (unsigned long)MAXTILES) return -1;
|
|
|
|
if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return -1;
|
|
|
|
if (!hicfirstinit) hicinit();
|
|
|
|
|
|
|
|
for (hr = hicreplc[picnum]; hr; hr = hr->next) {
|
|
|
|
if (hr->palnum == palnum)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hr) {
|
|
|
|
// no replacement yet defined
|
|
|
|
hrn = (hicreplctyp *)calloc(1,sizeof(hicreplctyp));
|
|
|
|
if (!hrn) return -1;
|
|
|
|
hrn->palnum = palnum;
|
|
|
|
} else hrn = hr;
|
|
|
|
|
|
|
|
// store into hicreplc the details for this replacement
|
|
|
|
if (hrn->filename) free(hrn->filename);
|
|
|
|
|
|
|
|
hrn->filename = strdup(filen);
|
|
|
|
if (!hrn->filename) {
|
|
|
|
if (hrn->skybox) return -1; // don't free the base structure if there's a skybox defined
|
|
|
|
if (hr == NULL) free(hrn); // not yet a link in the chain
|
|
|
|
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;
|
2006-04-24 19:04:22 +00:00
|
|
|
hrn->flags = flags;
|
|
|
|
if (hr == NULL) {
|
|
|
|
hrn->next = hicreplc[picnum];
|
|
|
|
hicreplc[picnum] = hrn;
|
|
|
|
}
|
|
|
|
|
|
|
|
//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.
|
|
|
|
//
|
|
|
|
int hicsetskybox(long picnum, long palnum, char *faces[6])
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hicreplctyp *hr, *hrn;
|
|
|
|
long j;
|
|
|
|
|
|
|
|
if ((unsigned long)picnum >= (unsigned long)MAXTILES) return -1;
|
|
|
|
if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return -1;
|
|
|
|
for (j=5;j>=0;j--) if (!faces[j]) return -1;
|
|
|
|
if (!hicfirstinit) hicinit();
|
|
|
|
|
|
|
|
for (hr = hicreplc[picnum]; hr; hr = hr->next) {
|
|
|
|
if (hr->palnum == palnum)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hr) {
|
|
|
|
// no replacement yet defined
|
|
|
|
hrn = (hicreplctyp *)calloc(1,sizeof(hicreplctyp));
|
|
|
|
if (!hrn) return -1;
|
|
|
|
|
|
|
|
hrn->palnum = palnum;
|
|
|
|
} else hrn = hr;
|
|
|
|
|
|
|
|
if (!hrn->skybox) {
|
|
|
|
hrn->skybox = (struct hicskybox_t *)calloc(1,sizeof(struct hicskybox_t));
|
|
|
|
if (!hrn->skybox) {
|
|
|
|
if (hr == NULL) free(hrn); // not yet a link in the chain
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (j=5;j>=0;j--) {
|
|
|
|
if (hrn->skybox->face[j])
|
|
|
|
free(hrn->skybox->face[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// store each face's filename
|
|
|
|
for (j=0;j<6;j++) {
|
|
|
|
hrn->skybox->face[j] = strdup(faces[j]);
|
|
|
|
if (!hrn->skybox->face[j]) {
|
|
|
|
for (--j; j>=0; --j) // free any previous faces
|
|
|
|
free(hrn->skybox->face[j]);
|
|
|
|
free(hrn->skybox);
|
|
|
|
hrn->skybox = NULL;
|
|
|
|
if (hr == NULL) free(hrn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hrn->skybox->ignore = 0;
|
|
|
|
if (hr == NULL) {
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
int hicclearsubst(long picnum, long palnum)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
hicreplctyp *hr, *hrn = NULL;
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if ((unsigned long)picnum >= (unsigned long)MAXTILES) return -1;
|
|
|
|
if ((unsigned long)palnum >= (unsigned long)MAXPALOOKUPS) return -1;
|
|
|
|
if (!hicfirstinit) return 0;
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
for (hr = hicreplc[picnum]; hr; hrn = hr, hr = hr->next) {
|
|
|
|
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
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (hr->filename) free(hr->filename);
|
|
|
|
if (hr->skybox) {
|
|
|
|
int i;
|
|
|
|
for (i=5;i>=0;i--)
|
|
|
|
if (hr->skybox->face[i])
|
|
|
|
free(hr->skybox->face[i]);
|
|
|
|
free(hr->skybox);
|
|
|
|
}
|
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;
|
|
|
|
free(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
|
|
|
}
|