]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/points.cpp
Merge pull request #21 from merlin1991/Q3-gamepack-fix
[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         s_num_points = 0;
34 }
35
36 void CPointfile::PushPoint( vec3_t v ){
37         if ( s_num_points < MAX_POINTFILE ) {
38                 VectorCopy( v, s_pointvecs[s_num_points] );
39                 s_num_points++;
40         }
41 }
42
43 // create the display list at the end
44 void CPointfile::GenerateDisplayList(){
45         int i;
46
47         if ( !g_qeglobals.d_pointfile_display_list ) {
48                 g_qeglobals.d_pointfile_display_list = qglGenLists( 1 );
49         }
50
51         qglNewList( g_qeglobals.d_pointfile_display_list,  GL_COMPILE );
52
53         qglColor3f( 1, 0, 0 );
54         qglDisable( GL_TEXTURE_2D );
55         qglDisable( GL_TEXTURE_1D );
56         qglLineWidth( 4 );
57         qglBegin( GL_LINE_STRIP );
58         for ( i = 0; i < s_num_points; i++ )
59         {
60                 if ( s_num_points < MAX_POINTFILE ) {
61                         qglVertex3fv( s_pointvecs[i] );
62                 }
63         }
64         qglEnd();
65         qglLineWidth( 1 );
66
67         qglEndList();
68
69         s_check_point = 0;
70 }
71
72 // old (but still relevant) pointfile code -------------------------------------
73
74 void Pointfile_Delete( void ){
75         char name[1024];
76
77         strcpy( name, currentmap );
78         StripExtension( name );
79         strcat( name, ".lin" );
80
81         remove( name );
82 }
83
84 // advance camera to next point
85 void Pointfile_Next( void ){
86         vec3_t dir;
87
88         if ( s_check_point >= s_num_points - 2 ) {
89                 Sys_Status( "End of pointfile", 0 );
90                 return;
91         }
92         s_check_point++;
93         VectorCopy( s_pointvecs[s_check_point], g_pParentWnd->GetCamWnd()->Camera()->origin );
94         VectorCopy( s_pointvecs[s_check_point], g_pParentWnd->GetXYWnd()->GetOrigin() );
95         VectorSubtract( s_pointvecs[s_check_point + 1], g_pParentWnd->GetCamWnd()->Camera()->origin, dir );
96         VectorNormalize( dir, dir );
97         g_pParentWnd->GetCamWnd()->Camera()->angles[1] = atan2( dir[1], dir[0] ) * 180 / 3.14159;
98         g_pParentWnd->GetCamWnd()->Camera()->angles[0] = asin( dir[2] ) * 180 / 3.14159;
99
100         Sys_UpdateWindows( W_ALL );
101 }
102
103 // advance camera to previous point
104 void Pointfile_Prev( void ){
105         vec3_t dir;
106
107         if ( s_check_point == 0 ) {
108                 Sys_Status( "Start of pointfile", 0 );
109                 return;
110         }
111         s_check_point--;
112         VectorCopy( s_pointvecs[s_check_point], g_pParentWnd->GetCamWnd()->Camera()->origin );
113         VectorCopy( s_pointvecs[s_check_point], g_pParentWnd->GetXYWnd()->GetOrigin() );
114         VectorSubtract( s_pointvecs[s_check_point + 1], g_pParentWnd->GetCamWnd()->Camera()->origin, dir );
115         VectorNormalize( dir, dir );
116         g_pParentWnd->GetCamWnd()->Camera()->angles[1] = atan2( dir[1], dir[0] ) * 180 / 3.14159;
117         g_pParentWnd->GetCamWnd()->Camera()->angles[0] = asin( dir[2] ) * 180 / 3.14159;
118
119         Sys_UpdateWindows( W_ALL );
120 }
121
122 void WINAPI Pointfile_Check( void ){
123         char name[1024];
124         int size;
125         char    *data;
126         char  *text;
127         int line = 1;
128         vec3_t v;
129
130         strcpy( name, currentmap );
131         StripExtension( name );
132         strcat( name, ".lin" );
133
134         size = vfsLoadFullPathFile( name, (void**)&data );
135         if ( size <= 0 ) {
136                 Sys_FPrintf( SYS_ERR, "Pointfile %s not found\n", name );
137                 return;
138         }
139
140         // store a pointer
141         text = data;
142
143         Sys_Printf( "Reading pointfile %s\n", name );
144
145         g_pointfile.Init();
146
147         while ( *data )
148         {
149                 if ( sscanf( data,"%f %f %f", &v[0], &v[1], &v[2] ) != 3 ) {
150                         Sys_Printf( "Corrupt point file, line %d\n",line );
151                         break;
152                 }
153
154                 while ( *data && *data != '\n' )
155                 {
156                         if ( *( data - 1 ) == ' ' && *( data ) == '-' && *( data + 1 ) == ' ' ) {
157                                 break;
158                         }
159                         data++;
160                 }
161                 // deal with zhlt style point files.
162                 if ( *data == '-' ) {
163                         if ( sscanf( data,"- %f %f %f", &v[0], &v[1], &v[2] ) != 3 ) {
164                                 Sys_Printf( "Corrupt point file, line %d\n",line );
165                                 break;
166                         }
167
168                         while ( *data && *data != '\n' )
169                                 data++;
170
171                 }
172                 while ( *data == '\n' )
173                 {
174                         data++; // skip the \n
175                         line++;
176                 }
177                 g_pointfile.PushPoint( v );
178         }
179
180         g_free( text );
181
182         g_pointfile.GenerateDisplayList();
183
184         Sys_UpdateWindows( W_ALL );
185 }
186
187 void Pointfile_Draw( void ){
188         qglCallList( g_qeglobals.d_pointfile_display_list );
189 }
190
191 void Pointfile_Clear( void ){
192         if ( !g_qeglobals.d_pointfile_display_list ) {
193                 return;
194         }
195
196         qglDeleteLists( g_qeglobals.d_pointfile_display_list, 1 );
197         g_qeglobals.d_pointfile_display_list = 0;
198         Sys_UpdateWindows( W_ALL );
199 }
200
201 // CPointfile implementation for SAX speicific stuff -------------------------------
202 void CPointfile::saxStartElement( message_info_t *ctx, const xmlChar *name, const xmlChar **attrs ){
203         if ( strcmp( (char *)name, "polyline" ) == 0 ) {
204                 Init();
205                 // there's a prefs setting to avoid stopping on leak
206                 if ( !g_PrefsDlg.m_bLeakStop ) {
207                         ctx->stop_depth = 0;
208                 }
209         }
210 }
211
212 void CPointfile::saxEndElement( message_info_t *ctx, const xmlChar *name ){
213         if ( strcmp( (char *)name, "polyline" ) == 0 ) {
214                 // we are done
215                 GenerateDisplayList();
216                 ctx->bGeometry = false;
217         }
218 }
219
220 // only "point" is expected to have characters around here
221 void CPointfile::saxCharacters( message_info_t *ctx, const xmlChar *ch, int len ){
222         vec3_t v;
223
224         sscanf( (char *)ch, "%f %f %f\n", &v[0], &v[1], &v[2] );
225         PushPoint( v );
226 }
227
228 char * CPointfile::getName(){
229         return "Map is leaked";
230 }