1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
//-----------------------------------------------------------------------------
// BSPLIB MODULE: AodInput.cpp
//
// Copyright (c) 1996-1997 by Markus Hadwiger
// All Rights Reserved.
//-----------------------------------------------------------------------------
// bsplib header files
#include "AodInput.h"
#include "BspObject.h"
#include "BspTool.h"
BSPLIB_NAMESPACE_BEGIN
// file is read and parsed immediately after construction of an object --------
//
AodInput::AodInput( BspObjectList objectlist, const char *filename ) :
SingleInput( objectlist, filename )
{
ParseObjectData();
}
// destructor destroys only class members and the base classes ----------------
//
AodInput::~AodInput()
{
}
// assignment copies only the AodFormat part of the object --------------------
//
AodInput& AodInput::operator =( const AodInput& copyobj )
{
*(AodFormat *)this = copyobj;
return *this;
}
// print error message if error in object data-file ---------------------------
//
void AodInput::ParseError( int section )
{
//NOTE:
// GetSectionName() is overloaded and not virtual, therefore
// SingleInput's ParseError() cannot be used!
sprintf( line, "%sin section %s (line %d)", parser_err_str,
GetSectionName( section ), m_parser_lineno );
ErrorMessage( line );
HandleCriticalError();
}
// parse object data-file -----------------------------------------------------
//
int AodInput::ParseObjectData()
{
int faceprop_itemsread = 0;
int facenorm_itemsread = 0;
InfoMessage( "Processing input data file (format='AOD V1.1') ..." );
// parse sections and read data -------------------------------
m_section = _nil;
while ( m_input.ReadLine( line, TEXTLINE_MAX ) != NULL ) {
if ( ( m_parser_lineno++ & PARSER_DOT_SIZE ) == 0 )
printf( "." ), fflush( stdout );
if ( ( m_scanptr = strtok( line, "/, \t\n\r" ) ) == NULL )
continue;
else if ( *m_scanptr == ';' )
continue;
else if ( strnicmp( m_scanptr, "<end", 4 ) == 0 )
break;
else if ( *m_scanptr == '#' ) {
if ( strncmp( m_scanptr, _aodsig_str, strlen( _aodsig_str ) ) == 0 ) {
m_section = _comment;
} else if ( ( m_section = GetSectionId( m_scanptr ) ) == _nil ) {
{
StrScratch error;
sprintf( error, "%s[Undefined section-name]: %s (line %d)",
parser_err_str, m_scanptr, m_parser_lineno );
ErrorMessage( error );
}
HandleCriticalError();
}
} else {
switch ( m_section ) {
// list of vertices ------------------------------------
case _vertices :
ReadVertex();
break;
// vertexnums of faces ---------------------------------
case _faces :
ReadFace( TRUE );
break;
// normals for face's planes ---------------------------
case _facenormals :
//NOTE:
// face normals are currently ignored in the aod
// file, since they are too inaccurate for later
// BSP compilation purposes. if no normals are read
// in, they will be calculated later on anyway.
//ReadFaceNormal( facenorm_itemsread );
break;
// properties of faces ---------------------------------
case _faceproperties :
ReadFaceProperties( faceprop_itemsread );
break;
// texture->face correspondences ----------------------
case _correspondences :
ReadCorrespondences();
break;
// texturing data -----------------------------------
case _textures :
ReadTextures();
break;
// location of the object ---------------------------
case _worldlocation :
ReadWorldLocation();
break;
// location of camera -------------------------------
case _camera :
ReadCameraLocation();
break;
// filename of palette file -------------------------
case _palette :
ReadPaletteFilename();
break;
// scalefactors for object --------------------------
case _scalefactors :
ReadScaleFactors();
break;
// exchange command for axes ------------------------
case _xchange :
ReadXChangeCommand();
break;
// set new object origin ----------------------------
case _setorigin :
ReadOrigin();
break;
}
}
}
// do post processing after parsing
ApplyOriginTranslation();
FilterAxesDirSwitch();
FilterScaleFactors();
FilterAxesExchange();
EnforceMaximumExtents();
m_baseobject->CheckParsedData();
InfoMessage( "\nObject data ok.\n" );
// do colorindex to rgb conversion
ConvertColIndxs();
return ( m_inputok = TRUE );
}
BSPLIB_NAMESPACE_END
//-----------------------------------------------------------------------------
|