|
Last change
on this file since 8758eb was 8758eb, checked in by Frederik Heber <heber@…>, 16 years ago |
|
FIX: cell_size in World has not been set to a default size, i.e. has been uninitialized.
- cell_size is now set to {20,0,20,0,0,20}, the default value it was set to before.
Signed-off-by: Frederik Heber <heber@…>
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * world.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Mar 3, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "World.hpp"
|
|---|
| 9 |
|
|---|
| 10 | double *World::cell_size = 0;
|
|---|
| 11 |
|
|---|
| 12 | /** Constructor of World.
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 | World::World()
|
|---|
| 16 | {
|
|---|
| 17 | cell_size = new double[6];
|
|---|
| 18 | cell_size[0] = 20.;
|
|---|
| 19 | cell_size[1] = 0.;
|
|---|
| 20 | cell_size[2] = 20.;
|
|---|
| 21 | cell_size[3] = 0.;
|
|---|
| 22 | cell_size[4] = 0.;
|
|---|
| 23 | cell_size[5] = 20.;
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | /** Destructor of World.
|
|---|
| 27 | *
|
|---|
| 28 | */
|
|---|
| 29 | World::~World()
|
|---|
| 30 | {
|
|---|
| 31 | delete[](cell_size);
|
|---|
| 32 | };
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | // TODO: Hide boost-thread using Autotools stuff when no threads are used
|
|---|
| 36 | World* World::theWorld = 0;
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | World* World::get(){
|
|---|
| 40 | // boost supports RAII-Style locking, so we don't need to unlock
|
|---|
| 41 | if(!theWorld) {
|
|---|
| 42 | theWorld = new World();
|
|---|
| 43 | }
|
|---|
| 44 | return theWorld;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void World::destroy(){
|
|---|
| 48 | delete theWorld;
|
|---|
| 49 | theWorld = 0;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | World* World::reset(){
|
|---|
| 53 | World* oldWorld = 0;
|
|---|
| 54 | {
|
|---|
| 55 | oldWorld = theWorld;
|
|---|
| 56 | theWorld = new World();
|
|---|
| 57 | // oldworld does not need protection any more,
|
|---|
| 58 | // since we should have the only reference
|
|---|
| 59 |
|
|---|
| 60 | // worldLock handles access to the pointer,
|
|---|
| 61 | // not to the object
|
|---|
| 62 | } // scope-end releases the lock
|
|---|
| 63 |
|
|---|
| 64 | // we have to let all the observers know that the
|
|---|
| 65 | // oldWorld was destroyed. oldWorld calls subjectKilled
|
|---|
| 66 | // upon destruction. Every Observer getting that signal
|
|---|
| 67 | // should see that it gets the updated new world
|
|---|
| 68 | delete oldWorld;
|
|---|
| 69 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.