#ifndef Var1_SolarSystem_H
#define Var1_SolarSystem_H
#include <Glasses/ZNode.h>
#include <Glasses/ZVector.h>
#include <Glasses/ODECrawler.h>
#include <Stones/TimeMakerClient.h>
#include <Stones/ZColor.h>
#include <Gled/GCondition.h>
#include <TRandom.h>
class CosmicBall;
class SolarSystem : public ZNode,
public ODECrawlerMaster,
public TimeMakerClient
{
MAC_RNR_FRIENDS(SolarSystem);
private:
Bool_t hWarnTimeOutOfRange;
Double_t hStepIntegratorDt;
void _init();
public:
enum CrawlMode_e { CM_ChunkedStorage, CM_DirectStep };
protected:
ZLink<ZVector> mBalls;
ZLink<ODECrawler> mODECrawler;
CrawlMode_e mCrawlMode;
Double_t mTime;
Double_t mTimeFac;
Int_t mBallHistorySize;
ZColor mColor;
Double_t mStarMass;
Double_t mBallKappa;
TRandom mPlanetRnd;
Double_t mPlanetMinR;
Double_t mPlanetMaxR;
Double_t mOrbitMinR;
Double_t mOrbitMaxR;
Double_t mMaxTheta;
Double_t mMaxEcc;
ZColor mPlanetColor;
class Storage : public ODEStorageD
{
Int_t mId;
public:
Storage(Int_t order, Int_t capacity=128) :
ODEStorageD(order, capacity), mId(0)
{}
Storage(const Storage& s) : ODEStorageD(s.Order(), 12*s.Size()/10)
{ mId = s.mId + 1; }
Int_t GetId() const { return mId; }
};
typedef map<Double_t, Storage*> mTime2pStorage_t;
typedef map<Double_t, Storage*>::iterator mTime2pStorage_i;
mTime2pStorage_t mStorageMap;
mTime2pStorage_i mCurrentStorage;
Double_t mTimePerChunk;
Double_t mKeepPast;
Double_t mCalcFuture;
ODEStorageD* get_storage() { return (ODEStorageD*) mODECrawler->GetStorage(); }
Storage* find_storage_from_time(Double_t t);
Double_t set_time(Double_t t, Bool_t from_timetick);
GMutex mBallSwitchMutex;
list<CosmicBall*> mBallsToAdd;
list<CosmicBall*> mBallsToRemove;
GThread *mIntegratorThread;
GCondition mStorageCond;
static void* tl_IntegratorThread(SolarSystem* ss);
void ChunkIntegratorThread();
void StepIntegratorThread();
Bool_t bDesiredRHack;
Double_t mDesiredRHackT0;
void hack_desired_r(Double_t dt);
public:
SolarSystem(const Text_t* n="SolarSystem", const Text_t* t=0);
virtual ~SolarSystem();
virtual void AdEnlightenment();
virtual UInt_t ODEOrder();
virtual void ODEDerivatives(const Double_t x, const TVectorD& y, TVectorD& d);
virtual void ODEStart(TVectorD& v, Double_t& x1, Double_t& x2);
virtual void TimeTick(Double_t t, Double_t dt);
void StartChunkIntegratorThread();
void StartStepIntegratorThread();
void StopIntegratorThread();
void SetTime(Double_t t);
void SetBallHistorySize(Int_t history_size);
virtual CosmicBall* RandomPlanetoid(const TString& name);
virtual void MakeStar();
virtual void MakePlanetoid();
virtual void AddPlanetoid(CosmicBall* cb);
virtual void RemovePlanetoid(CosmicBall* cb);
#include "SolarSystem.h7"
ClassDef(SolarSystem, 1);
};
#endif