World class More...
#include <stage.hh>
Classes | |
class | Event |
struct | ltx |
struct | lty |
Public Member Functions | |
virtual void | AddModel (Model *mod) |
void | AddModelName (Model *mod, const std::string &name) |
void | AddPowerPack (PowerPack *pp) |
SuperRegion * | AddSuperRegion (const point_int_t &coord) |
void | AddUpdateCallback (world_callback_t cb, void *user) |
void | CancelQuit () |
void | CancelQuitAll () |
void | ClearRays () |
virtual std::string | ClockString (void) const |
void | ConsumeQueue (unsigned int queue_num) |
Model * | CreateModel (Model *parent, const std::string &typestr) |
SuperRegion * | CreateSuperRegion (point_int_t origin) |
void | DestroySuperRegion (SuperRegion *sr) |
void | DisableEnergy (Model *m) |
void | EnableEnergy (Model *m) |
void | Enqueue (unsigned int queue_num, usec_t delay, Model *mod, model_callback_t cb, void *arg) |
void | Extend (point3_t pt) |
const std::set< Model * > | GetAllModels () const |
unsigned int | GetEventQueue (Model *mod) const |
const bounds3d_t & | GetExtent () const |
Model * | GetGround () |
Model * | GetModel (const std::string &name) const |
SuperRegion * | GetSuperRegion (const point_int_t &org) |
SuperRegion * | GetSuperRegionCreate (const point_int_t &org) |
uint64_t | GetUpdateCount () const |
Worldfile * | GetWorldFile () |
virtual bool | IsGUI () const |
virtual void | Load (const std::string &worldfile_path) |
void | LoadBlock (Worldfile *wf, int entity) |
void | LoadBlockGroup (Worldfile *wf, int entity) |
void | LoadModel (Worldfile *wf, int entity) |
void | LoadSensor (Worldfile *wf, int entity) |
void | Log (Model *mod) |
void | MapPoly (const std::vector< point_int_t > &poly, Block *block, unsigned int layer) |
int32_t | MetersToPixels (meters_t x) const |
point_int_t | MetersToPixels (const point_t &pt) const |
void | NeedRedraw () |
bool | PastQuitTime () |
bool | Paused () const |
virtual void | PopColor () |
virtual void | PushColor (Color col) |
virtual void | PushColor (double r, double g, double b, double a) |
void | Quit () |
void | QuitAll () |
RaytraceResult | Raytrace (const Ray &ray) |
RaytraceResult | Raytrace (const Pose &pose, const meters_t range, const ray_test_func_t func, const Model *finder, const void *arg, const bool ztest) |
void | Raytrace (const Pose &pose, const meters_t range, const radians_t fov, const ray_test_func_t func, const Model *finder, const void *arg, RaytraceResult *samples, const uint32_t sample_count, const bool ztest) |
virtual Model * | RecentlySelectedModel () const |
void | RecordRay (double x1, double y1, double x2, double y2) |
virtual void | Redraw (void) |
void | RegisterOption (Option *opt) |
Register an Option for pickup by the GUI. | |
virtual void | Reload () |
virtual void | RemoveModel (Model *mod) |
void | RemovePowerPack (PowerPack *pp) |
int | RemoveUpdateCallback (world_callback_t cb, void *user) |
double | Resolution () const |
virtual bool | Save (const char *filename) |
void | ShowClock (bool enable) |
Control printing time to stdout. | |
usec_t | SimTimeNow (void) const |
virtual void | Start () |
virtual void | Stop () |
bool | TestQuit () const |
virtual void | TogglePause () |
void | TryCharge (PowerPack *pp, const Pose &pose) |
virtual void | UnLoad () |
virtual bool | Update (void) |
uint64_t | UpdateCount () |
World (const std::string &name="MyWorld", double ppm=DEFAULT_PPM) | |
virtual | ~World () |
Static Public Member Functions | |
static void | Run () |
static void * | update_thread_entry (std::pair< World *, int > *info) |
static bool | UpdateAll () |
Public Attributes | |
std::set< Model * > | active_energy |
std::set< ModelPosition * > | active_velocity |
std::vector < std::priority_queue< Event > > | event_queues |
Model * | ground |
bool | paused |
if true, the simulation is stopped | |
std::vector< std::queue< Model * > > | pending_update_callbacks |
std::vector< point_int_t > | rt_candidate_cells |
std::vector< point_int_t > | rt_cells |
usec_t | sim_interval |
int | update_cb_count |
Static Public Attributes | |
static std::vector< std::string > | args |
static std::string | ctrlargs |
static const int | DEFAULT_PPM = 50 |
Protected Member Functions | |
void | CallUpdateCallbacks () |
Call all calbacks in cb_list, removing any that return true;. | |
Protected Attributes | |
std::list< std::pair < world_callback_t, void * > > | cb_list |
List of callback functions and arguments. | |
bounds3d_t | extent |
Describes the 3D volume of the world. | |
bool | graphics |
true iff we have a GUI | |
std::set< Option * > | option_table |
GUI options (toggles) registered by models. | |
std::list< PowerPack * > | powerpack_list |
List of all the powerpacks attached to models in the world. | |
usec_t | quit_time |
std::list< float * > | ray_list |
List of rays traced for debug visualization. | |
usec_t | sim_time |
the current sim time in this world in microseconds | |
std::map< point_int_t, SuperRegion * > | superregions |
std::vector< std::vector < Model * > > | update_lists |
uint64_t | updates |
the number of simulated time steps executed so far | |
Worldfile * | wf |
If set, points to the worldfile used to create this world. | |
Private Member Functions | |
void | FiducialErase (Model *mod) |
void | FiducialInsert (Model *mod) |
Static Private Member Functions | |
static void | UpdateCb (World *world) |
Private Attributes | |
bool | destroy |
bool | dirty |
iff true, a gui redraw would be required | |
std::set< Model * > | models |
std::map< std::string, Model * > | models_by_name |
std::map< int, Model * > | models_by_wfentity |
std::vector< Model * > | models_with_fiducials |
std::set< Model *, ltx > | models_with_fiducials_byx |
std::set< Model *, lty > | models_with_fiducials_byy |
double | ppm |
the resolution of the world model in pixels per meter | |
bool | quit |
quit this world ASAP | |
bool | show_clock |
iff true, print the sim time on stdout | |
unsigned int | show_clock_interval |
updates between clock outputs | |
pthread_mutex_t | sync_mutex |
protect the worker thread management stuff | |
pthread_cond_t | threads_done_cond |
signalled by last worker thread to unblock main thread | |
pthread_cond_t | threads_start_cond |
signalled to unblock worker threads | |
unsigned int | threads_working |
the number of worker threads not yet finished | |
int | total_subs |
the total number of subscriptions to all models | |
unsigned int | worker_threads |
the number of worker threads to use | |
Static Private Attributes | |
static unsigned int | next_id |
initially zero, used to allocate unique sequential world ids | |
static bool | quit_all |
quit all worlds ASAP | |
static std::set< World * > | world_set |
all the worlds that exist | |
Friends | |
class | Block |
class | Canvas |
class | Model |
class | ModelFiducial |
class | WorkerThread |
World::World | ( | const std::string & | name = "MyWorld" , |
double | ppm = DEFAULT_PPM |
||
) |
World::~World | ( | void | ) | [virtual] |
void World::AddModel | ( | Model * | mod | ) | [virtual] |
Reimplemented in Stg::WorldGui.
void World::AddModelName | ( | Model * | mod, |
const std::string & | name | ||
) |
void World::AddPowerPack | ( | PowerPack * | pp | ) |
SuperRegion * World::AddSuperRegion | ( | const point_int_t & | coord | ) |
void World::AddUpdateCallback | ( | world_callback_t | cb, |
void * | user | ||
) |
void World::CallUpdateCallbacks | ( | ) | [protected] |
void Stg::World::CancelQuit | ( | ) | [inline] |
void Stg::World::CancelQuitAll | ( | ) | [inline] |
void World::ClearRays | ( | ) |
std::string World::ClockString | ( | void | ) | const [virtual] |
Get human readable string that describes the current simulation time.
Reimplemented in Stg::WorldGui.
void World::ConsumeQueue | ( | unsigned int | queue_num | ) |
Model * World::CreateModel | ( | Model * | parent, |
const std::string & | typestr | ||
) |
SuperRegion * World::CreateSuperRegion | ( | point_int_t | origin | ) |
void World::DestroySuperRegion | ( | SuperRegion * | sr | ) |
void Stg::World::DisableEnergy | ( | Model * | m | ) | [inline] |
void Stg::World::EnableEnergy | ( | Model * | m | ) | [inline] |
void Stg::World::Enqueue | ( | unsigned int | queue_num, |
usec_t | delay, | ||
Model * | mod, | ||
model_callback_t | cb, | ||
void * | arg | ||
) | [inline] |
Create a new simulation event to be handled in the future.
queue_num | Specify which queue the event should be on. The main thread is 0. |
delay | The time from now until the event occurs, in microseconds. |
mod | The model that should have its Update() method called at the specified time. |
void World::Extend | ( | point3_t | pt | ) | [inline] |
void Stg::World::FiducialErase | ( | Model * | mod | ) | [inline, private] |
void Stg::World::FiducialInsert | ( | Model * | mod | ) | [inline, private] |
const std::set<Model*> Stg::World::GetAllModels | ( | ) | const [inline] |
unsigned int World::GetEventQueue | ( | Model * | mod | ) | const |
const bounds3d_t& Stg::World::GetExtent | ( | ) | const [inline] |
Model* Stg::World::GetGround | ( | ) | [inline] |
Model * World::GetModel | ( | const std::string & | name | ) | const |
SuperRegion * World::GetSuperRegion | ( | const point_int_t & | org | ) | [inline] |
SuperRegion * World::GetSuperRegionCreate | ( | const point_int_t & | org | ) | [inline] |
uint64_t Stg::World::GetUpdateCount | ( | ) | const [inline] |
Worldfile* Stg::World::GetWorldFile | ( | ) | [inline] |
virtual bool Stg::World::IsGUI | ( | ) | const [inline, virtual] |
Returns true iff this World implements a GUI. The base World class returns false, but subclasses can override this behaviour.
Reimplemented in Stg::WorldGui.
void World::Load | ( | const std::string & | worldfile_path | ) | [virtual] |
Open the file at the specified location, create a Worldfile object, read the file and configure the world from the contents, creating models as necessary. The created object persists, and can be retrieved later with World::GetWorldFile().
Reimplemented in Stg::WorldGui.
void World::LoadBlock | ( | Worldfile * | wf, |
int | entity | ||
) |
void Stg::World::LoadBlockGroup | ( | Worldfile * | wf, |
int | entity | ||
) |
void World::LoadModel | ( | Worldfile * | wf, |
int | entity | ||
) |
void World::LoadSensor | ( | Worldfile * | wf, |
int | entity | ||
) |
void World::Log | ( | Model * | mod | ) |
void World::MapPoly | ( | const std::vector< point_int_t > & | poly, |
Block * | block, | ||
unsigned int | layer | ||
) |
int32_t Stg::World::MetersToPixels | ( | meters_t | x | ) | const [inline] |
point_int_t Stg::World::MetersToPixels | ( | const point_t & | pt | ) | const [inline] |
void Stg::World::NeedRedraw | ( | ) | [inline] |
bool World::PastQuitTime | ( | ) |
bool Stg::World::Paused | ( | ) | const [inline] |
virtual void Stg::World::PopColor | ( | ) | [inline, virtual] |
Reimplemented in Stg::WorldGui.
virtual void Stg::World::PushColor | ( | Color | col | ) | [inline, virtual] |
Reimplemented in Stg::WorldGui.
virtual void Stg::World::PushColor | ( | double | r, |
double | g, | ||
double | b, | ||
double | a | ||
) | [inline, virtual] |
Reimplemented in Stg::WorldGui.
void Stg::World::Quit | ( | ) | [inline] |
void Stg::World::QuitAll | ( | ) | [inline] |
RaytraceResult World::Raytrace | ( | const Ray & | ray | ) |
RaytraceResult World::Raytrace | ( | const Pose & | pose, |
const meters_t | range, | ||
const ray_test_func_t | func, | ||
const Model * | finder, | ||
const void * | arg, | ||
const bool | ztest | ||
) |
void World::Raytrace | ( | const Pose & | pose, |
const meters_t | range, | ||
const radians_t | fov, | ||
const ray_test_func_t | func, | ||
const Model * | finder, | ||
const void * | arg, | ||
RaytraceResult * | samples, | ||
const uint32_t | sample_count, | ||
const bool | ztest | ||
) |
virtual Model* Stg::World::RecentlySelectedModel | ( | ) | const [inline, virtual] |
Reimplemented in Stg::WorldGui.
void World::RecordRay | ( | double | x1, |
double | y1, | ||
double | x2, | ||
double | y2 | ||
) |
virtual void Stg::World::Redraw | ( | void | ) | [inline, virtual] |
Force the GUI to redraw the world, even if paused. This imlementation does nothing, but can be overridden by subclasses.
Reimplemented in Stg::WorldGui.
void World::RegisterOption | ( | Option * | opt | ) |
void World::Reload | ( | void | ) | [virtual] |
void World::RemoveModel | ( | Model * | mod | ) | [virtual] |
void World::RemovePowerPack | ( | PowerPack * | pp | ) |
int World::RemoveUpdateCallback | ( | world_callback_t | cb, |
void * | user | ||
) |
double Stg::World::Resolution | ( | ) | const [inline] |
void World::Run | ( | ) | [static] |
run all worlds. If only non-gui worlds were created, UpdateAll() is repeatedly called. To simulate a gui world only a single gui world may have been created. This world is then simulated.
bool World::Save | ( | const char * | filename | ) | [virtual] |
Save the current world state into a worldfile with the given filename.
Filename | to save as. |
Reimplemented in Stg::WorldGui.
void Stg::World::ShowClock | ( | bool | enable | ) | [inline] |
usec_t Stg::World::SimTimeNow | ( | void | ) | const [inline] |
virtual void Stg::World::Start | ( | ) | [inline, virtual] |
Reimplemented in Stg::WorldGui.
virtual void Stg::World::Stop | ( | ) | [inline, virtual] |
Reimplemented in Stg::WorldGui.
bool Stg::World::TestQuit | ( | ) | const [inline] |
virtual void Stg::World::TogglePause | ( | ) | [inline, virtual] |
void Stg::World::TryCharge | ( | PowerPack * | pp, |
const Pose & | pose | ||
) |
void World::UnLoad | ( | ) | [virtual] |
Reimplemented in Stg::WorldGui.
bool World::Update | ( | void | ) | [virtual] |
Run one simulation timestep. Advances the simulation clock, executes all simulation updates due at the current time, then queues up future events.
Reimplemented in Stg::WorldGui.
void * World::update_thread_entry | ( | std::pair< World *, int > * | info | ) | [static] |
bool World::UpdateAll | ( | ) | [static] |
static void Stg::World::UpdateCb | ( | World * | world | ) | [static, private] |
uint64_t Stg::World::UpdateCount | ( | ) | [inline] |
friend class Canvas [friend] |
Reimplemented from Stg::Ancestor.
Reimplemented in Stg::WorldGui.
friend class Model [friend] |
Reimplemented in Stg::WorldGui.
friend class ModelFiducial [friend] |
friend class WorkerThread [friend] |
std::set<Model*> Stg::World::active_energy |
Set of models that require energy calculations at each World::Update().
std::set<ModelPosition*> Stg::World::active_velocity |
Set of models that require their positions to be recalculated at each World::Update().
std::vector< std::string > World::args [static] |
contains the command line arguments passed to Stg::Init(), so that controllers can read them.
std::list<std::pair<world_callback_t,void*> > Stg::World::cb_list [protected] |
std::string World::ctrlargs [static] |
const int Stg::World::DEFAULT_PPM = 50 [static] |
bool Stg::World::destroy [private] |
bool Stg::World::dirty [private] |
std::vector<std::priority_queue<Event> > Stg::World::event_queues |
bounds3d_t Stg::World::extent [protected] |
bool Stg::World::graphics [protected] |
std::set<Model*> Stg::World::models [private] |
std::map<std::string, Model*> Stg::World::models_by_name [private] |
std::map<int,Model*> Stg::World::models_by_wfentity [private] |
std::vector<Model*> Stg::World::models_with_fiducials [private] |
std::set<Model*,ltx> Stg::World::models_with_fiducials_byx [private] |
std::set<Model*,lty> Stg::World::models_with_fiducials_byy [private] |
unsigned int World::next_id [static, private] |
std::set<Option*> Stg::World::option_table [protected] |
bool Stg::World::paused |
std::vector<std::queue<Model*> > Stg::World::pending_update_callbacks |
std::list<PowerPack*> Stg::World::powerpack_list [protected] |
double Stg::World::ppm [private] |
bool Stg::World::quit [private] |
bool World::quit_all [static, private] |
usec_t Stg::World::quit_time [protected] |
World::quit is set true when this simulation time is reached
std::list<float*> Stg::World::ray_list [protected] |
std::vector<point_int_t> Stg::World::rt_candidate_cells |
std::vector<point_int_t> Stg::World::rt_cells |
bool Stg::World::show_clock [private] |
unsigned int Stg::World::show_clock_interval [private] |
usec_t Stg::World::sim_time [protected] |
std::map<point_int_t,SuperRegion*> Stg::World::superregions [protected] |
pthread_mutex_t Stg::World::sync_mutex [private] |
pthread_cond_t Stg::World::threads_done_cond [private] |
pthread_cond_t Stg::World::threads_start_cond [private] |
unsigned int Stg::World::threads_working [private] |
int Stg::World::total_subs [private] |
std::vector< std::vector<Model*> > Stg::World::update_lists [protected] |
uint64_t Stg::World::updates [protected] |
Worldfile* Stg::World::wf [protected] |
unsigned int Stg::World::worker_threads [private] |
std::set< World * > World::world_set [static, private] |