Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
lookuptable.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WWPhys *
24 * *
25 * $Archive:: /Commando/Code/wwmath/lookuptable.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Greg_h $*
30 * *
31 * $Modtime:: 4/18/00 1:20p $*
32 * *
33 * $Revision:: 6 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39
40#ifndef LOOKUPTABLE_H
41#define LOOKUPTABLE_H
42
43#include "always.h"
44#include "simplevec.h"
45#include "wwstring.h"
46#include "refcount.h"
47#include "multilist.h"
48#include "wwmath.h"
49
50
51class Vector2;
52class Curve1DClass;
53class ChunkSaveClass;
54class ChunkLoadClass;
55
56
62{
63public:
64
65 LookupTableClass(int sample_count = 256);
66 virtual ~LookupTableClass(void);
67
68 void Init(const char * name,Curve1DClass * curve);
69 float Get_Value(float input);
70 float Get_Value_Quick(float input);
71 const char * Get_Name(void) { return Name; }
72protected:
73
74 StringClass Name; // name of this table, if it came from a file, this is also the filename
79
80};
81
82inline float LookupTableClass::Get_Value(float input)
83{
84 if (input <= MinInputValue) {
85 return OutputSamples[0];
86 }
87 if (input >= MaxInputValue) {
88 return OutputSamples[OutputSamples.Length()-1];
89 }
90
91 float normalized_input = (float)(OutputSamples.Length()-1) * (input - MinInputValue) * OOMaxMinusMin;
92 float input0 = WWMath::Floor(normalized_input);
93
94 int index0 = WWMath::Float_To_Long(input0);
95 int index1 = index0+1;
96 float lerp = normalized_input - input0;
97
98 return OutputSamples[index0] + lerp * (OutputSamples[index1] - OutputSamples[index0]);
99}
100
101inline float LookupTableClass::Get_Value_Quick(float input)
102{
103 if (input <= MinInputValue) {
104 return OutputSamples[0];
105 }
106 if (input >= MaxInputValue) {
107 return OutputSamples[OutputSamples.Length()-1];
108 }
109
110 int index = (OutputSamples.Length()-1) * WWMath::Float_To_Long((input - MinInputValue) * OOMaxMinusMin);
111 return OutputSamples[index];
112}
113
114
129{
130public:
133
134 // init and shutdown are automatically called from WWMath::Init, WWMath::Shutdown...
135 static void Init(void);
136 static void Shutdown(void);
137
138 static bool Add_Table(LookupTableClass * table);
139 static bool Remove_Table(LookupTableClass * table);
140 static LookupTableClass * Get_Table(const char * name,bool try_to_load = true);
141
142 static void Save_Table_Desc( ChunkSaveClass & csave,
143 Curve1DClass * curve,
144 const Vector2 & min,
145 const Vector2 & max );
146
147 static void Load_Table_Desc( ChunkLoadClass & cload,
148 Curve1DClass ** curve_ptr,
149 Vector2 * set_min = NULL,
150 Vector2 * set_max = NULL );
151
152 static void Reset(void);
153
154protected:
155
157
158};
159
160
161#endif // LOOKUPTABLE_H
#define NULL
Definition BaseType.h:92
#define min(x, y)
Definition BaseType.h:101
#define max(x, y)
Definition BaseType.h:105
StringClass Name
Definition lookuptable.h:74
void Init(const char *name, Curve1DClass *curve)
SimpleVecClass< float > OutputSamples
Definition lookuptable.h:78
virtual ~LookupTableClass(void)
float Get_Value(float input)
Definition lookuptable.h:82
const char * Get_Name(void)
Definition lookuptable.h:71
LookupTableClass(int sample_count=256)
float Get_Value_Quick(float input)
static void Init(void)
static void Save_Table_Desc(ChunkSaveClass &csave, Curve1DClass *curve, const Vector2 &min, const Vector2 &max)
static void Load_Table_Desc(ChunkLoadClass &cload, Curve1DClass **curve_ptr, Vector2 *set_min=NULL, Vector2 *set_max=NULL)
static RefMultiListClass< LookupTableClass > Tables
static bool Add_Table(LookupTableClass *table)
static bool Remove_Table(LookupTableClass *table)
static void Reset(void)
static void Shutdown(void)
static LookupTableClass * Get_Table(const char *name, bool try_to_load=true)
RefCountClass(void)
Definition refcount.h:108
static float Floor(float val)
Definition wwmath.h:153
static long Float_To_Long(float f)
Definition wwmath.h:322