00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "BaseWorldUtility.h"
00022 #include "FindModule.h"
00023 #include "BaseConnectionManager.h"
00024
00025 Define_Module(BaseWorldUtility);
00026
00027
00028 const double BaseWorldUtility::speedOfLight = 299792458.0;
00029
00030 BaseWorldUtility::BaseWorldUtility():
00031 isInitialized(false)
00032 {}
00033
00034 void BaseWorldUtility::initialize(int stage) {
00035 Blackboard::initialize(stage);
00036
00037 if (stage == 0) {
00038 initializeIfNecessary();
00039 }
00040 else if(stage == 1) {
00041
00042
00043 if(!FindModule<BaseConnectionManager*>::findGlobalModule()) {
00044 opp_warning("Could not find a connection manager module in the network!");
00045 }
00046 }
00047 }
00048
00049 void BaseWorldUtility::initializeIfNecessary()
00050 {
00051 if(isInitialized)
00052 return;
00053
00054 use2DFlag = par("use2D");
00055
00056 if (use2DFlag) {
00057 playgroundSize = Coord(par("playgroundSizeX"),
00058 par("playgroundSizeY"));
00059 } else {
00060 playgroundSize = Coord(par("playgroundSizeX"),
00061 par("playgroundSizeY"),
00062 par("playgroundSizeZ"));
00063 }
00064
00065 if(playgroundSize.getX() <= 0) {
00066 opp_error("Playground size in X direction is invalid: "\
00067 "(%f). Should be greater zero.", playgroundSize.getX());
00068 }
00069 if(playgroundSize.getY() <= 0) {
00070 opp_error("Playground size in Y direction is invalid: "\
00071 "(%f). Should be greater zero.", playgroundSize.getY());
00072 }
00073 if(!use2DFlag && playgroundSize.getZ() <= 0) {
00074 opp_error("Playground size in Z direction is invalid: "\
00075 "(%f). Should be greater zero (or use 2D mode).", playgroundSize.getZ());
00076 }
00077
00078 useTorusFlag = par("useTorus");
00079
00080 airFrameId = 0;
00081
00082 isInitialized = true;
00083 }
00084
00085 Coord BaseWorldUtility::getRandomPosition()
00086 {
00087 initializeIfNecessary();
00088
00089 if (use2DFlag) {
00090 return Coord(uniform(0, playgroundSize.getX()),
00091 uniform(0, playgroundSize.getY()));
00092 } else {
00093 return Coord(uniform(0, playgroundSize.getX()),
00094 uniform(0, playgroundSize.getY()),
00095 uniform(0, playgroundSize.getZ()));
00096 }
00097 }
00098