So, I'm writing a generic class that takes a structure with information on
a source value and how it should change over time and modifies that value via
a pointer. I seem to have implemented it wrong, because whenever I pass it a
structure and run it, the value comes out vastly unexpected. My game engine
relies heavily on vectors (where lists may serve it better, but it's a work
in progress) and I think that it might be part of the problem, but I'm not
changing the vectors size during this execution. I'll throw up the code...
Honestly, this was supposed to solve problems, but it just broke my engine.
class gEvent{
protected:
union{
double *d;
long *l;
} m_ptr;
union{
double d;
long l;
} m_result;
union{
double d;
long l;
} m_init;
char m_format;
//long l
//double d
float m_duration;
float m_start;
long m_handle;
public:
gEvent();
gEvent(const gEvent &rhs);
gEvent(double *d, float time, double val);
gEvent(long *l, float time, long val);
void operator=(const gEvent& rhs);
void SetDuration(float time);
void SetValue(double d);
void SetValue(long l);
void Start(float now);
bool Step(float now); //Steps the value of the pointer
void SetPointer(long *l);
void SetPointer(double *d);
};
The functions are named for their functions, aptly enough.
Here's the code that runs through a deque of these structures.
bool CORE::Game::gEvent::Step(float now){
if(m_ptr.l == NULL || m_ptr.d == NULL)
return false; //Done, delete the instance
switch(m_format){
case 'l':
if((m_duration<(now-m_start))){
*m_ptr.l = m_result.l;
return false;
}
(*m_ptr.l) = (m_init.l)*(m_duration/(now-m_start));
return true;
break;
case 'd':
if((m_duration<(now-m_start))){
*m_ptr.d = m_result.d;
return false;
}
(*m_ptr.d) = (m_init.d)*(m_duration/(now-m_start));
return true;
break;
default:
return false;
break;
}
}
Is there a better way to generically time data changes? I've done some
googling, but can't seem to hit the right keywords or something.
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be