]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/compilers/dmap/glfile.cpp
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / tools / compilers / dmap / glfile.cpp
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #include "../../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "dmap.h"
33
34 int             c_glfaces;
35
36 int PortalVisibleSides( uPortal_t *p )
37 {
38         int             fcon, bcon;
39
40         if (!p->onnode)
41                 return 0;               // outside
42
43         fcon = p->nodes[0]->opaque;
44         bcon = p->nodes[1]->opaque;
45
46         // same contents never create a face
47         if (fcon == bcon)
48                 return 0;
49
50         if (!fcon)
51                 return 1;
52         if (!bcon)
53                 return 2;
54         return 0;
55 }
56
57 void OutputWinding( idWinding *w, idFile *glview )
58 {
59         static  int     level = 128;
60         float           light;
61         int                     i;
62
63         glview->WriteFloatString( "%i\n", w->GetNumPoints() );
64         level += 28;
65         light = (level&255)/255.0;
66         for ( i = 0; i < w->GetNumPoints(); i++ ) {
67                 glview->WriteFloatString( "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
68                         (*w)[i][0],
69                         (*w)[i][1],
70                         (*w)[i][2],
71                         light,
72                         light,
73                         light );
74         }
75         glview->WriteFloatString( "\n" );
76 }
77
78 /*
79 =============
80 OutputPortal
81 =============
82 */
83 void OutputPortal( uPortal_t *p, idFile *glview ) {
84         idWinding       *w;
85         int             sides;
86
87         sides = PortalVisibleSides( p );
88         if ( !sides ) {
89                 return;
90         }
91
92         c_glfaces++;
93
94         w = p->winding;
95
96         if ( sides == 2 ) {             // back side
97                 w = w->Reverse();
98         }
99
100         OutputWinding( w, glview );
101
102         if ( sides == 2 ) {
103                 delete w;
104         }
105 }
106
107 /*
108 =============
109 WriteGLView_r
110 =============
111 */
112 void WriteGLView_r( node_t *node, idFile *glview )
113 {
114         uPortal_t       *p, *nextp;
115
116         if ( node->planenum != PLANENUM_LEAF )
117         {
118                 WriteGLView_r( node->children[0], glview );
119                 WriteGLView_r( node->children[1], glview );
120                 return;
121         }
122
123         // write all the portals
124         for ( p = node->portals; p; p = nextp )
125         {
126                 if ( p->nodes[0] == node )
127                 {
128                         OutputPortal( p, glview );
129                         nextp = p->next[0];
130                 }
131                 else {
132                         nextp = p->next[1];
133                 }
134         }
135 }
136
137 /*
138 =============
139 WriteGLView
140 =============
141 */
142 void WriteGLView( tree_t *tree, char *source )
143 {
144         idFile *glview;
145
146         c_glfaces = 0;
147         common->Printf( "Writing %s\n", source );
148
149         glview = fileSystem->OpenExplicitFileWrite( source );
150         if ( !glview ) {
151                 common->Error( "Couldn't open %s", source );
152         }
153         WriteGLView_r( tree->headnode, glview );
154         fileSystem->CloseFile( glview );
155
156         common->Printf( "%5i c_glfaces\n", c_glfaces );
157 }
158