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