]> git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/gtkgensurf/heretic.cpp
reformat code! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / contrib / gtkgensurf / heretic.cpp
1 /*
2    GenSurf plugin for GtkRadiant
3    Copyright (C) 2001 David Hyde, Loki software and qeradiant.com
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <stdlib.h>
21 #include <math.h>
22 #include <stdio.h>
23 #include "gensurf.h"
24
25 // Heretic 2 - specific routines
26
27 typedef struct palette_s {
28     guint8 r, g, b;
29 } palette_t;
30
31 #define MIP_VERSION     2
32 #define PAL_SIZE        256
33 #define MIPLEVELS       16
34
35 typedef struct miptex_s {
36     int version;
37     char name[32];
38     unsigned width[MIPLEVELS], height[MIPLEVELS];
39     unsigned offsets[MIPLEVELS];        // four mip maps stored
40     char animname[32];                  // next frame in animation chain
41     palette_t palette[PAL_SIZE];
42     int flags;
43     int contents;
44     int value;
45 } miptex_t;
46
47 //=============================================================
48 int GetDefSurfaceProps(char *Tex)
49 {
50     return 0; // leo: only used for Heretic 2, fix later
51     /*
52        char             path[NAME_MAX];
53        char        *p;
54        int         flags;
55        miptex_t *mt;
56        FILE         *f;
57        int         length;
58        int         pos;
59
60        if(Game != HERETIC2) return 0;
61        if(!strlen(Tex)) return 0;
62
63        mt = NULL;
64        flags = 0;
65        if(UsePak[Game])
66        {
67           FILE         *fpak;
68           pak_header_t pakheader;
69           pak_item_t   pakitem;
70           int          i;
71           int          num;
72           int          numitems;
73
74           if (NULL != (fpak = fopen(pakfile[Game], "rb")))
75           {
76               sprintf(path,"textures/%s.m8",Tex);
77               g_strdown(path);
78               num=fread(&pakheader,1,sizeof(pak_header_t),fpak);
79               if((size_t)num < sizeof(pak_header_t))
80               {
81                   fclose(fpak);
82                   return 0;
83               }
84               if(strncmp(pakheader.id,"PACK",4))
85               {
86                   fclose(fpak);
87                   return 0;
88               }
89               numitems = pakheader.dsize/sizeof(pak_item_t);
90               fseek(fpak,pakheader.dstart,SEEK_SET);
91               for(i=0; i<numitems; i++)
92               {
93                   fread(&pakitem,1,sizeof(pak_item_t),fpak);
94                   if(strstr(pakitem.name,path))
95                   {
96                       fseek(fpak,pakitem.start,SEEK_SET);
97                       if((mt = (miptex_t*)malloc(sizeof(miptex_t)))==NULL)
98                       {
99                           fclose(fpak);
100                           return 0;
101                       }
102                       else
103                       {
104                           fread(mt, 1, sizeof(miptex_t), fpak);
105                           flags = mt->flags;
106                           free(mt);
107                       }
108                   }
109               }
110               fclose(fpak);
111           }
112        }
113        else
114        {
115           // Assume .map will be output to gamedir/maps, then back up
116           // to the gamedir and append /textures. Ugly but it should work
117           strcpy(path,gszMapFile);
118           g_strdown(path);
119           p = strstr(path,"maps");
120           if(!p) return 0;
121           p[0] = '\0';
122           strcat(path,"textures/");
123           strcat(path,Tex);
124           strcat(path,".m8");
125           f = fopen (path, "rb");
126           if (!f)
127               flags = 0;
128           else
129           {
130               pos = ftell (f);
131               fseek (f, 0, SEEK_END);
132               length = ftell (f);
133               fseek (f, pos, SEEK_SET);
134               if((mt = (miptex_t*)malloc(length+1))==NULL)
135                   flags = 0;
136               else
137               {
138                   ((char *)mt)[length] = 0;
139                   fread(mt, 1, length, f);
140                   fclose (f);
141                   flags = mt->flags;
142                   free(mt);
143               }
144           }
145        }
146        return flags;
147      */
148 }