BaseWorldUtility.h

00001 /* -*- mode:c++ -*- ********************************************************
00002  * file:        BaseWorldUtility.h
00003  *
00004  * author:      Tom Parker
00005  *
00006  * copyright:   (C) 2007 Parallel and Distributed Systems Group (PDS) at
00007  *              Technische Universiteit Delft, The Netherlands.
00008  *
00009  *              This program is free software; you can redistribute it
00010  *              and/or modify it under the terms of the GNU General Public
00011  *              License as published by the Free Software Foundation; either
00012  *              version 2 of the License, or (at your option) any later
00013  *              version.
00014  *              For further information see file COPYING
00015  *              in the top level directory
00016  ***************************************************************************
00017  * description: basic world utility class
00018  *              provides world-required values
00019  **************************************************************************/
00020 
00021 #ifndef BASE_WORLD_UTIL_H
00022 #define BASE_WORLD_UTIL_H
00023 
00024 #include "Blackboard.h"
00025 #include "Coord.h"
00026 
00034 class BaseWorldUtility : public Blackboard
00035 {
00036 protected:
00044     Coord playgroundSize;
00045 
00047     bool useTorusFlag;
00048 
00050     bool use2DFlag;
00051 
00053     long airFrameId;
00054 
00056     bool isInitialized;
00057 
00058 public:
00060   static const double speedOfLight;
00061 
00062 protected:
00069     virtual void initializeIfNecessary();
00070 
00071 public:
00072   BaseWorldUtility();
00073 
00074   virtual void initialize(int stage);
00075 
00083     const Coord* getPgs(){
00084       initializeIfNecessary();
00085         return &playgroundSize;
00086     };
00087 
00089     bool useTorus(){
00090       initializeIfNecessary();
00091       return useTorusFlag;
00092     };
00093 
00095   virtual Coord getRandomPosition();
00096 
00098     bool use2D()
00099     {
00100       initializeIfNecessary();
00101       return use2DFlag;
00102     }
00103 
00105     long getUniqueAirFrameId()
00106     {
00107       initializeIfNecessary();
00108 
00109       // if counter has done one complete cycle and will be set to a value it already had
00110       if (airFrameId == -1){
00111         // print a warning
00112         ev << "WARNING: AirFrameId-Counter has done one complete cycle."
00113         << " AirFrameIds are repeating now and may not be unique anymore." << endl;
00114       }
00115 
00116       return airFrameId++;
00117     }
00118  };
00119 
00120 #endif