Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
ode.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/* $Header: /G/wwmath/ode.h 9 9/21/99 5:54p Neal_k $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando *
25 * *
26 * $Archive:: /G/wwmath/ode.h $*
27 * *
28 * Author:: Greg_h *
29 * *
30 * $Modtime:: 9/21/99 5:54p $*
31 * *
32 * $Revision:: 9 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef ODE_H
44#define ODE_H
45
46#include "always.h"
47#include "vector.h"
48#include "wwdebug.h"
49
50
51/*
52** StateVectorClass
53** The state vector for a system of ordinary differential equations will be
54** stored in this form. It is a dynamically resizeable array so that we don't
55** have to hard-code a maximum size. If needed, in the final product, we could
56** do a slight optimization which makes this a normal fixed size array that
57** we've determined is "big enough".
58*/
60{
61public:
62 void Reset(void) { ActiveCount = 0; }
63 void Resize(int size) { if (size > VectorMax) { DynamicVectorClass<float>::Resize(size); } }
64};
65
66
67/*
68** ODESystemClass
69** If a system of Ordinary Differential Equations (ODE's) are put behind an interface
70** of this type, they can be integrated using the Integrators defined in this module.
71*/
73{
74
75public:
76
77 /*
78 ** Get_Current_State
79 ** This function should fill the given state vector with the
80 ** current state of this object. Each state variable should be
81 ** inserted into the vector using its 'Add' interface.
82 */
83 virtual void Get_State(StateVectorClass & set_state) = 0;
84
85 /*
86 ** Set_Current_State
87 ** This function should read its state from this state vector starting from the
88 ** given index. The return value should be the index that the next object should
89 ** read from (i.e. increment the index past your state)
90 */
91 virtual int Set_State(const StateVectorClass & new_state,int start_index = 0) = 0;
92
93 /*
94 ** Compute_Derivatives
95 ** The various ODE solvers will use this interface to ask the ODESystemClass to
96 ** compute the derivatives of their state. In some cases, the integrator will
97 ** pass in a new state vector (test_state) to be used when computing the derivatives.
98 ** NULL will be passed if they want the derivatives for the initial state.
99 ** This function works similarly to the Set_State function in that it passes you
100 ** the index to start reading from and you pass it back the index to continue from.
101 */
102 virtual int Compute_Derivatives(float t,StateVectorClass * test_state,StateVectorClass * dydt,int start_index = 0) = 0;
103
104};
105
106
107/*
108** IntegrationSystem
109**
110** The Euler_Solve is the simplest but most inaccurate. It requires only
111** a single computation of the derivatives per timestep.
112**
113** The Midpoint_Solve function will evaluate the derivatives at two points
114**
115** The Runge_Kutta_Solve requires four evaluations of the derivatives.
116** This is the fourth order Runge-Kutta method...
117**
118** Runge_Kutta5_Solve is an implementation of fifth order Runge-
119** Kutta. It requires six evaluations of the derivatives.
120*/
121
123{
124public:
125
126 static void Euler_Integrate(ODESystemClass * sys,float dt);
127 static void Midpoint_Integrate(ODESystemClass * sys,float dt);
128 static void Runge_Kutta_Integrate(ODESystemClass * sys,float dt);
129 static void Runge_Kutta5_Integrate(ODESystemClass * odesys,float dt);
130
131};
132
133#endif
134
virtual bool Resize(int newsize, T const *array=0)
Definition Vector.H:615
DynamicVectorClass(unsigned size=0, float const *array=0)
Definition Vector.H:587
static void Runge_Kutta5_Integrate(ODESystemClass *odesys, float dt)
Definition ode.cpp:260
static void Midpoint_Integrate(ODESystemClass *sys, float dt)
Definition ode.cpp:119
static void Euler_Integrate(ODESystemClass *sys, float dt)
Definition ode.cpp:72
static void Runge_Kutta_Integrate(ODESystemClass *sys, float dt)
Definition ode.cpp:183
virtual void Get_State(StateVectorClass &set_state)=0
virtual int Set_State(const StateVectorClass &new_state, int start_index=0)=0
virtual int Compute_Derivatives(float t, StateVectorClass *test_state, StateVectorClass *dydt, int start_index=0)=0
void Reset(void)
Definition ode.h:62
void Resize(int size)
Definition ode.h:63