Menu

#1 Remove Global Data

General API
open
nobody
7
2006-02-23
2006-02-23
No

Currently we're defining global data for "m_odeGlobals"
and "m_odeBodies". These should be defined as SubData
to allow for multiple ODESolvers to run in a hip sim.

Here's some advice from Mark Tucker:

I would suggest creating a SIM_Data subclass to hold
this information instead. Somthing like this:

class SIM_OdeWorldData : public SIM_Data
{
public:
odeGlobals &getOrCreateOdeGlobals()
{ return m_odeGlobals; }
std::map<int, odeBody> &getOdeBodies()
{ return m_odeBodies; }

protected:
explicit SIM_OdeWorldData(const SIM_DataFactory
*factory)
: BaseClass(factory),
m_odeBodies(0),
m_odeGlobals(0),
m_shareCount(0)
{ }
virtual ~SIM_OdeWorldData()
{ clear(); }

// This ensures that this data is always kept in
RAM, even when
// the cache runs out of space and writes out
the simulation
// step to disk. This is necessary because the
ODE data can't
// be written to disk.
virtual bool getCanBeSavedToDiskSubclass() const
{ return false; }

// Start fro scratch. We create a brand new world.
virtual void initiailizeSubclass()
{
clear();
m_odeBodies = new
std::map<int,

odeBody>();
m_odeGlobals = new
odeGlobals();
m_shareCount = new int(1);
}

// To make one world equal to another, copythe
data exactly.
// The share count lets several of these data
share the same
// ODE world and bodies without worrying that
the ODE data
// will get deleted as long as any
SIM_OdeWorldData is holding
// onto it.
virtual void makeEqualSubclass(const SIM_Data *src)
{
SIM_OdeWorldData *world;
world = SIM_DATA_CASTCONST(src,
SIM_OdeWorldData);
if( world )
{
clear();
m_shareCount =
world->m_shareCount;
m_odeBodies =
world->m_odeBodies;
m_odeGlobals =
world->m_odeGlobals;
(*m_shareCount)++;
}
}

private:
void clear()
{
if( m_shareCount )
{
(*m_shareCount)--;
if(*m_shareCount
== 0)
{

m_odeBodies.clear();
delete
m_odeGlobals;
delete
m_shareCount;
}
}
m_shareCount = 0;
m_odeGlobals = 0;
m_odeBodies = 0;
}

std::map<int, odeBody> *m_odeBodies;
odeGlobals *m_odeGlobals;
int *m_shareCount;
}

Discussion

  • Daniel Kramer

    Daniel Kramer - 2006-02-23
    • labels: 745058 -->
    • milestone: 500561 -->
    • summary: Remove Global Data --> Remove Global Data
     
  • Daniel Kramer

    Daniel Kramer - 2006-02-23
    • labels: --> DOP: SolverODE
    • milestone: --> General API
     
  • Daniel Kramer

    Daniel Kramer - 2006-02-23
    • priority: 5 --> 7
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.