2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "ivisdef.h"
|
2006-08-22 07:28:49 -07:00
|
|
|
#include "imd.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "tex.h"
|
|
|
|
#include "ivispatch.h"
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
#define MAX_SHAPE_RADIUS 160
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
#ifdef SAVEIMD
|
|
|
|
// new code the write out the connectors !
|
|
|
|
void _imd_save_connectors(FILE *fp, iIMDShape *s)
|
|
|
|
{
|
2007-03-16 09:20:16 -07:00
|
|
|
Vector3i *p;
|
2007-06-28 10:47:08 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (s->nconnectors != 0) {
|
|
|
|
fprintf(fp,"CONNECTORS %d\n",s->nconnectors);
|
|
|
|
p = s->connectors;
|
|
|
|
for (i=0; i<s->nconnectors; i++, p++) {
|
2006-08-22 07:28:49 -07:00
|
|
|
fprintf(fp,"\t%d %d %d\n", p->x,p->y,p->z);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
//*** save IMD file
|
|
|
|
//*
|
|
|
|
//* pre shape successfully loaded
|
|
|
|
//*
|
|
|
|
//* params filename = name of file to save to including .IMD extention
|
|
|
|
//* s = pointer to IMD shape
|
|
|
|
//*
|
|
|
|
//* returns TRUE -> ok, FLASE -> error
|
|
|
|
//*
|
|
|
|
//******
|
2007-03-15 15:49:54 -07:00
|
|
|
BOOL iV_IMDSave(char *filename, iIMDShape *s, BOOL PieIMD)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
iIMDShape *sp;
|
|
|
|
iIMDPoly *poly;
|
|
|
|
int nlevel, i, j, d;
|
|
|
|
|
|
|
|
if ((fp = fopen(filename,"w")) == NULL) {
|
|
|
|
return FALSE;
|
2007-04-28 04:12:14 -07:00
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
if (PieIMD==TRUE) {
|
|
|
|
fprintf(fp,"%s %d\n",PIE_NAME,PIE_VER);
|
|
|
|
} else {
|
|
|
|
fprintf(fp,"%s %d\n",IMD_NAME,IMD_VER);
|
|
|
|
}
|
|
|
|
fprintf(fp,"TYPE %x\n",s->flags);
|
|
|
|
|
|
|
|
// if textured write tex page file info
|
2007-07-25 13:58:57 -07:00
|
|
|
if (s->texpage != iV_TEX_INVALID)
|
2007-04-28 04:12:14 -07:00
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
fprintf(fp,"TEXTURE %d %s %d %d\n",iV_TEXTYPE(s->texpage),
|
|
|
|
iV_TEXNAME(s->texpage),iV_TEXWIDTH(s->texpage),
|
|
|
|
iV_TEXHEIGHT(s->texpage));
|
|
|
|
}
|
|
|
|
|
|
|
|
// find number of levels in shape
|
|
|
|
for (nlevel=0, sp = s; sp != NULL; sp = sp->next, nlevel++)
|
|
|
|
;
|
|
|
|
|
|
|
|
fprintf(fp,"LEVELS %d\n",nlevel);
|
|
|
|
|
|
|
|
for (sp = s, i=0; i<nlevel; sp = sp->next, i++) {
|
|
|
|
fprintf(fp,"LEVEL %d\n",(i+1));
|
|
|
|
fprintf(fp,"POINTS %d\n",sp->npoints);
|
|
|
|
|
|
|
|
// write shape points
|
|
|
|
for (j = 0; j < sp->npoints; j++) {
|
|
|
|
fprintf(fp,"\t%d %d %d\n",sp->points[j].x,sp->points[j].y,
|
|
|
|
sp->points[j].z);
|
|
|
|
}
|
|
|
|
|
|
|
|
// write shape polys
|
2006-08-22 07:28:49 -07:00
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
fprintf(fp,"POLYGONS %d\n",sp->npolys);
|
|
|
|
for (poly = sp->polys, j=0; j<sp->npolys; j++, poly++) {
|
|
|
|
fprintf(fp,"\t%8x %d",poly->flags,poly->npnts);
|
|
|
|
for (d=0; d<poly->npnts; d++) {
|
|
|
|
fprintf(fp," %d",poly->pindex[d]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (poly->flags & iV_IMD_TEXANIM) {
|
|
|
|
|
|
|
|
if (poly->pTexAnim == NULL) {
|
2006-08-23 08:27:20 -07:00
|
|
|
debug( LOG_3D, "No TexAnim pointer!\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
} else {
|
|
|
|
fprintf(fp," %d %d %d %d",
|
|
|
|
poly->pTexAnim->nFrames,
|
|
|
|
poly->pTexAnim->playbackRate,
|
|
|
|
poly->pTexAnim->textureWidth,
|
|
|
|
poly->pTexAnim->textureHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if textured write texture uv's
|
2007-06-18 08:46:12 -07:00
|
|
|
if (poly->flags & iV_IMD_TEX)
|
2007-04-28 04:12:14 -07:00
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
for (d=0; d<poly->npnts; d++) {
|
|
|
|
fprintf(fp," %d %d",poly->vrt[d].u,poly->vrt[d].v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(fp,"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_imd_save_connectors(fp,s); // Write out the connectors if they exist
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//*************************************************************************
|
|
|
|
//*** free IMD shape memory
|
|
|
|
//*
|
|
|
|
//* pre shape successfully allocated
|
|
|
|
//*
|
|
|
|
//* params shape = pointer to IMD shape
|
|
|
|
//*
|
|
|
|
//******
|
|
|
|
void iV_IMDRelease(iIMDShape *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
iIMDShape *d;
|
|
|
|
|
|
|
|
if (s) {
|
|
|
|
if (s->points) {
|
2007-04-15 03:43:05 -07:00
|
|
|
free(s->points);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
if (s->connectors) {
|
2007-04-15 03:43:05 -07:00
|
|
|
free(s->connectors);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
if (s->polys) {
|
|
|
|
for (i = 0; i < s->npolys; i++) {
|
|
|
|
if (s->polys[i].pindex) {
|
2007-04-15 03:43:05 -07:00
|
|
|
free(s->polys[i].pindex);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
if (s->polys[i].pTexAnim) {
|
2007-04-15 03:43:05 -07:00
|
|
|
free(s->polys[i].pTexAnim);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
if (s->polys[i].vrt) {
|
2007-04-15 03:43:05 -07:00
|
|
|
free(s->polys[i].vrt);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
2007-04-15 03:43:05 -07:00
|
|
|
free(s->polys);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
2007-03-24 15:53:18 -07:00
|
|
|
if (s->shadowEdgeList)
|
|
|
|
{
|
|
|
|
free(s->shadowEdgeList);
|
|
|
|
s->shadowEdgeList = NULL;
|
|
|
|
}
|
2007-06-18 08:46:12 -07:00
|
|
|
debug(LOG_3D, "imd[IMDRelease] = release successful\n");
|
2007-06-28 10:47:08 -07:00
|
|
|
d = s->next;
|
2007-04-15 03:43:05 -07:00
|
|
|
free(s);
|
2007-06-28 10:47:08 -07:00
|
|
|
iV_IMDRelease(d);
|
|
|
|
}
|
|
|
|
}
|