2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #include "../idlib/precompiled.h"
35 idDeclTable::TableLookup
38 float idDeclTable::TableLookup( float index ) const {
42 int domain = values.Num() - 1;
50 if ( index >= domain - 1 ) {
51 return values[domain - 1];
52 } else if ( index <= 0 ) {
55 iIndex = idMath::Ftoi( index );
56 iFrac = index - iIndex;
61 index += domain * idMath::Ceil( -index / domain );
64 iIndex = idMath::FtoiFast( idMath::Floor( index ) );
65 iFrac = index - iIndex;
66 iIndex = iIndex % domain;
70 // we duplicated the 0 index at the end at creation time, so we
71 // don't need to worry about wrapping the filter
72 return values[iIndex] * ( 1.0f - iFrac ) + values[iIndex + 1] * iFrac;
75 return values[iIndex];
83 size_t idDeclTable::Size( void ) const {
84 return sizeof( idDeclTable ) + values.Allocated();
92 void idDeclTable::FreeData( void ) {
100 idDeclTable::DefaultDefinition
103 const char *idDeclTable::DefaultDefinition( void ) const {
112 bool idDeclTable::Parse( const char *text, const int textLength ) {
117 src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
118 src.SetFlags( DECL_LEXER_FLAGS );
119 src.SkipUntilString( "{" );
126 if ( !src.ReadToken( &token ) ) {
130 if ( token == "}" ) {
134 if ( token.Icmp( "snap" ) == 0 ) {
136 } else if ( token.Icmp( "clamp" ) == 0 ) {
138 } else if ( token.Icmp( "{" ) == 0 ) {
143 v = src.ParseFloat( &errorFlag );
145 // we got something non-numeric
152 src.ReadToken( &token );
153 if ( token == "}" ) {
156 if ( token == "," ) {
159 src.Warning( "expected comma or brace" );
165 src.Warning( "unknown token '%s'", token.c_str() );
171 // copy the 0 element to the end, so lerping doesn't
172 // need to worry about the wrap case
173 float val = values[0]; // template bug requires this to not be in the Append()?
174 values.Append( val );