]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/points.cpp
added file copy tree for the game packs - lists supported games
[xonotic/netradiant.git] / radiant / points.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #include "stdafx.h"
23
24 #define MAX_POINTFILE   8192
25 static vec3_t   s_pointvecs[MAX_POINTFILE];
26 static int              s_num_points, s_check_point;
27
28 CPointfile g_pointfile;
29
30 // CPointfile routine used by the standard code ---------------------------------
31
32 void CPointfile::Init()
33 {
34   s_num_points = 0;
35 }
36
37 void CPointfile::PushPoint (vec3_t v)
38 {
39         if (s_num_points < MAX_POINTFILE)
40         {
41                 VectorCopy (v, s_pointvecs[s_num_points]);
42                 s_num_points++;
43         }
44 }
45
46 // create the display list at the end
47 void CPointfile::GenerateDisplayList()
48 {
49   int i;
50
51         if (!g_qeglobals.d_pointfile_display_list)
52                 g_qeglobals.d_pointfile_display_list = qglGenLists(1);
53
54   qglNewList (g_qeglobals.d_pointfile_display_list,  GL_COMPILE);
55   
56         qglColor3f (1, 0, 0);
57         qglDisable(GL_TEXTURE_2D);
58         qglDisable(GL_TEXTURE_1D);
59         qglLineWidth (4);
60         qglBegin(GL_LINE_STRIP);
61         for (i=0;i<s_num_points;i++)
62         {
63           if (s_num_points < MAX_POINTFILE)
64           {
65             qglVertex3fv (s_pointvecs[i]);
66           }
67         }
68         qglEnd();
69         qglLineWidth (1);
70         
71         qglEndList ();
72         
73         s_check_point = 0;
74 }
75
76 // old (but still relevant) pointfile code -------------------------------------
77
78 void Pointfile_Delete (void)
79 {
80         char    name[1024];
81
82         strcpy (name, currentmap);
83         StripExtension (name);
84         strcat (name, ".lin");
85
86         remove(name);
87 }
88
89 // advance camera to next point
90 void Pointfile_Next (void)
91 {
92         vec3_t  dir;
93
94         if (s_check_point >= s_num_points-2)
95         {
96                 Sys_Status ("End of pointfile", 0);
97                 return;
98         }
99         s_check_point++;
100         VectorCopy (s_pointvecs[s_check_point], g_pParentWnd->GetCamWnd()->Camera()->origin);
101         VectorCopy (s_pointvecs[s_check_point], g_pParentWnd->GetXYWnd()->GetOrigin());
102         VectorSubtract (s_pointvecs[s_check_point+1], g_pParentWnd->GetCamWnd()->Camera()->origin, dir);
103         VectorNormalize (dir, dir);
104         g_pParentWnd->GetCamWnd()->Camera()->angles[1] = atan2 (dir[1], dir[0])*180/3.14159;
105         g_pParentWnd->GetCamWnd()->Camera()->angles[0] = asin (dir[2])*180/3.14159;
106
107         Sys_UpdateWindows (W_ALL);
108 }
109
110 // advance camera to previous point
111 void Pointfile_Prev (void)
112 {
113         vec3_t  dir;
114
115         if ( s_check_point == 0)
116         {
117                 Sys_Status ("Start of pointfile", 0);
118                 return;
119         }
120         s_check_point--;
121         VectorCopy (s_pointvecs[s_check_point], g_pParentWnd->GetCamWnd()->Camera()->origin);
122         VectorCopy (s_pointvecs[s_check_point], g_pParentWnd->GetXYWnd()->GetOrigin());
123         VectorSubtract (s_pointvecs[s_check_point+1], g_pParentWnd->GetCamWnd()->Camera()->origin, dir);
124         VectorNormalize (dir, dir);
125         g_pParentWnd->GetCamWnd()->Camera()->angles[1] = atan2 (dir[1], dir[0])*180/3.14159;
126         g_pParentWnd->GetCamWnd()->Camera()->angles[0] = asin (dir[2])*180/3.14159;
127
128         Sys_UpdateWindows (W_ALL);
129 }
130
131 void WINAPI Pointfile_Check (void)
132 {
133         char    name[1024];
134         int             size;
135         char    *data;
136   char  *text;
137   int   line = 1;
138         vec3_t v;
139
140         strcpy (name, currentmap);
141         StripExtension (name);
142         strcat (name, ".lin");
143
144         size = vfsLoadFullPathFile (name, (void**)&data);
145   if (size <= 0)
146   {
147     Sys_FPrintf (SYS_ERR, "Pointfile %s not found\n", name);
148                 return;
149   }
150
151   // store a pointer
152   text = data;
153
154         Sys_Printf ("Reading pointfile %s\n", name);
155
156   g_pointfile.Init();
157
158         while (*data)
159         {
160     if (sscanf(data,"%f %f %f", &v[0], &v[1], &v[2]) != 3)
161     {
162       Sys_Printf("Corrupt point file, line %d\n",line);
163                         break;
164     }
165
166         while (*data && *data != '\n')
167     {
168       if (*(data-1) == ' ' && *(data) == '-' && *(data+1) == ' ')
169         break;
170                   data++;
171     }
172     // deal with zhlt style point files.
173     if (*data == '-')
174     {
175       if (sscanf(data,"- %f %f %f", &v[0], &v[1], &v[2]) != 3)
176       {
177         Sys_Printf("Corrupt point file, line %d\n",line);
178         break;
179       }
180
181       while (*data && *data != '\n')
182                     data++;
183
184     }
185     while (*data == '\n')
186     {
187       data++; // skip the \n
188       line++;
189     }
190                 g_pointfile.PushPoint (v);
191         }
192
193   g_free(text);
194         
195         g_pointfile.GenerateDisplayList();
196
197   Sys_UpdateWindows (W_ALL);
198 }
199
200 void Pointfile_Draw( void )
201 {
202   qglCallList (g_qeglobals.d_pointfile_display_list);
203 }
204
205 void Pointfile_Clear (void)
206 {
207         if (!g_qeglobals.d_pointfile_display_list)
208                 return;
209
210         qglDeleteLists (g_qeglobals.d_pointfile_display_list, 1);
211         g_qeglobals.d_pointfile_display_list = 0;
212         Sys_UpdateWindows (W_ALL);
213 }
214
215 // CPointfile implementation for SAX speicific stuff -------------------------------
216 void CPointfile::saxStartElement (message_info_t *ctx, const xmlChar *name, const xmlChar **attrs)
217 {
218   if (strcmp ((char *)name, "polyline")==0)
219   {
220     Init();
221     // there's a prefs setting to avoid stopping on leak
222     if (!g_PrefsDlg.m_bLeakStop)
223       ctx->stop_depth = 0;
224   }
225 }
226
227 void CPointfile::saxEndElement (message_info_t *ctx, const xmlChar *name)
228 {
229   if (strcmp ((char *)name, "polyline")==0)
230   {
231     // we are done
232     GenerateDisplayList();
233     ctx->bGeometry = false;
234   }
235 }
236
237 // only "point" is expected to have characters around here
238 void CPointfile::saxCharacters (message_info_t *ctx, const xmlChar *ch, int len)
239 {
240   vec3_t v;
241   
242   sscanf ((char *)ch, "%f %f %f\n", &v[0], &v[1], &v[2]);
243   PushPoint (v);
244 }
245
246 char * CPointfile::getName()
247 {
248   return "Map is leaked";
249 }