MAK RTIspy API Documentation for HLA 1516
ballController.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2010 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: .h,v $ $Revision: 1.2 $ $State: Exp $
00007 *******************************************************************************/
00008 
00009 #ifndef BallController_H_
00010 #define BallController_H_
00011 
00012 #include "ballData.h"
00013 #include "regionData.h"
00014 #include "textData.h"
00015 
00016 #include <string>
00017 #include <list>
00018 
00019 // Generic class that updates owned balls and processes updates on
00020 // other balls
00021 class BallController
00022 {
00023 public:
00024 
00025    BallController(BallMap* data, DdmRegionMap* regionData);
00026    virtual ~BallController();
00027 
00028    // Creates (if not already created) and joins the given federation.
00029    // Returns success indicator.
00030    virtual bool createAndJoinFederation(const std::wstring& federation,
00031       const std::wstring& federateType,
00032       const std::wstring& federateName = std::wstring(),
00033       bool includeInterExt = false) = 0;
00034 
00035    // Resigns from and attempts to destroy the current federation.
00036    // Returns success indicator.
00037    virtual bool resignAndDestroyFederation() = 0;
00038 
00039    // Subscribes to the ball class and all its attributes. Must already have
00040    // created and joined the federation. Returns success indicator.
00041    virtual bool subscribe() = 0;
00042 
00043    // Unsubscribes to the ball class and all its attributes. Must already have
00044    // created and joined the federation. Returns success indicator.
00045    virtual bool unsubscribe() = 0;
00046 
00047    // Move owned balls and receive updates on others
00048    virtual void update();
00049 
00050    // Adds a new ball that is owned by this federate at the
00051    // given location
00052    virtual void addBall(int x, int y);
00053 
00054    // Deletes the owned ball with the given ID
00055    virtual void deleteBall(const std::wstring id) = 0;
00056 
00057    // Attempts to acquire the ball with the given ID
00058    virtual void acquireBall(const std::wstring id) = 0;
00059 
00060    // Attempts to divest the owned ball with the given ID
00061    virtual void divestBall(const std::wstring id) = 0;
00062 
00063    // Adds a new DDM subscription region
00064    virtual bool subscribeWithRegion(int xLowerBound, int yLowerBound,
00065       int xUpperBound, int yUpperBound) = 0;
00066 
00067    // Unsubscribes from the current DDM regions. If resubscribeWithoutRegion is
00068    // set, automatically resubscribes without regions.
00069    virtual bool unsubscribeWithRegions(bool resubscribeWithoutRegion) = 0;
00070 
00071    // Sets the field dimensions
00072    virtual void setDimensions(int minX, int minY, int maxX, int maxY);
00073 
00074    // Sets the current ball color for this federate
00075    virtual void setBallColor(BallColor);
00076 
00077    // Returns the federate ID (based on the federate handle)
00078    virtual const std::wstring& federateId() const = 0;
00079 
00080    // Returns the federate type
00081    virtual const std::wstring& federateType() const = 0;
00082 
00083    // Returns the federate name
00084    virtual const std::wstring& federateName() const = 0;
00085 
00086    // Returns the federation name
00087    virtual const std::wstring& federationName() const = 0;
00088 
00089    // Returns true if the federate name field is supported
00090    virtual bool isFederateNameSupported() const = 0;
00091 
00092    // Returns true if the optional interaction module extension is supported
00093    virtual bool isInteractionExtensionSupported() const = 0;
00094 
00095    // Returns true if DDM is enabled
00096    virtual bool isDdmEnabled() const;
00097 
00098    // Returns true if ownership transfer is enabled
00099    virtual bool isOwnershipTransferEnabled() const;
00100 
00101    // Returns true if the federate is currently connected
00102    virtual bool isConnected() const;
00103 
00104    // Returns true if the federate is currently joined to the federation
00105    virtual bool isJoined() const;
00106 
00107    // Returns true if the federate is currently subscribed
00108    virtual bool isSubscribed() const;
00109 
00110    // Returns a list of pending text events
00111    virtual void getPendingTextEvents(std::list<TextEvent>& textEvents);
00112 
00113    // Access the notification log
00114    virtual const std::wstring& getLog() const;
00115    virtual void clearLog();
00116 
00117 protected:
00118 
00119    // Calculates the new locations for all owned balls 
00120    virtual void moveBalls();
00121 
00122    // Calculates the new location for the ball
00123    virtual void calculateNewLoc(double x, double y, double distance,
00124       double direction, double& newX, double& newY) const;
00125 
00126    // Calculate if a collision occurred with a vertical wall, and, if so,
00127    // determine new location and direction of the ball
00128    virtual bool calculateVertWallCollision(double x, double y,
00129       double distance, double direction, double newX, double newY,
00130       double radius, double& finalDirection, double& distAfterColl,
00131       double& collX, double& collY, double& finalX, double& finalY) const;
00132 
00133    // Calculate if a collision occurred with a horizontal wall, and, if so,
00134    // determine new location and direction of the ball
00135    virtual bool calculateHorizWallCollision(double x, double y,
00136       double distance, double direction, double newX, double newY,
00137       double radius, double& finalDirection, double& distAfterColl,
00138       double& collX, double& collY, double& finalX, double& finalY) const;
00139 
00140    // Sends updates on all owned balls to other federates in the federation
00141    virtual void sendUpdates() = 0;
00142 
00143    // Receives updates on balls from other federates in the federation
00144    virtual void receiveUpdates() = 0;
00145 
00146    // Request the RTI to create the a new ball
00147    virtual void requestNewBall(Ball* ball, const std::wstring name) = 0;
00148 
00149 private:
00150 
00151    // No default constructor
00152    BallController();
00153 
00154 protected:
00155 
00156    BallMap* myBallData;
00157    DdmRegionMap* myRegionData;
00158 
00159    std::list<TextEvent> myPendingTextEvents;
00160 
00161    bool myIsConnected;
00162    bool myDdmEnabled;
00163    bool myOwnershipTransferEnabled;
00164    bool myIsJoined;
00165    bool myIsSubscribed;
00166 
00167    int myMinX;
00168    int myMinY;
00169    int myMaxX;
00170    int myMaxY;
00171 
00172    unsigned int myNextBallNumber;
00173    BallColor myBallColor;
00174 
00175    std::wstring myLog;
00176 
00177    // Math constants
00178    static const double pi;
00179    static const double maxRadians;
00180    static const double maxDegrees;
00181    static const double degreesToRadians;
00182 };
00183 
00184 #endif

Document ID: Generated on Thu Jun 14 14:15:04 EDT 2012 from SVN revision 116116
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)