MAK RTIspy API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ballController.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2010 MaK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: .h,v $ $Revision: 1.2 $ $State: Exp $
7 *******************************************************************************/
8 
9 #ifndef BallController_H_
10 #define BallController_H_
11 
12 #include "ballData.h"
13 #include "regionData.h"
14 #include "textData.h"
15 
16 #include <string>
17 #include <list>
18 
19 // Generic class that updates owned balls and processes updates on
20 // other balls
22 {
23 public:
24 
25  BallController(BallMap* data, DdmRegionMap* regionData);
26  virtual ~BallController();
27 
28  // Creates (if not already created) and joins the given federation.
29  // Returns success indicator.
30  virtual bool createAndJoinFederation(const std::wstring& federation,
31  const std::wstring& federateType,
32  const std::wstring& federateName = std::wstring(),
33  bool includeInterExt = false) = 0;
34 
35  // Resigns from and attempts to destroy the current federation.
36  // Returns success indicator.
37  virtual bool resignAndDestroyFederation() = 0;
38 
39  // Subscribes to the ball class and all its attributes. Must already have
40  // created and joined the federation. Returns success indicator.
41  virtual bool subscribe() = 0;
42 
43  // Unsubscribes to the ball class and all its attributes. Must already have
44  // created and joined the federation. Returns success indicator.
45  virtual bool unsubscribe() = 0;
46 
47  // Move owned balls and receive updates on others
48  virtual void update();
49 
50  // Adds a new ball that is owned by this federate at the
51  // given location
52  virtual void addBall(int x, int y);
53 
54  // Deletes the owned ball with the given ID
55  virtual void deleteBall(const std::wstring id) = 0;
56 
57  // Attempts to acquire the ball with the given ID
58  virtual void acquireBall(const std::wstring id) = 0;
59 
60  // Attempts to divest the owned ball with the given ID
61  virtual void divestBall(const std::wstring id) = 0;
62 
63  // Adds a new DDM subscription region
64  virtual bool subscribeWithRegion(int xLowerBound, int yLowerBound,
65  int xUpperBound, int yUpperBound) = 0;
66 
67  // Unsubscribes from the current DDM regions. If resubscribeWithoutRegion is
68  // set, automatically resubscribes without regions.
69  virtual bool unsubscribeWithRegions(bool resubscribeWithoutRegion) = 0;
70 
71  // Sets the field dimensions
72  virtual void setDimensions(int minX, int minY, int maxX, int maxY);
73 
74  // Sets the current ball color for this federate
75  virtual void setBallColor(BallColor);
76 
77  // Returns the federate ID (based on the federate handle)
78  virtual const std::wstring& federateId() const = 0;
79 
80  // Returns the federate type
81  virtual const std::wstring& federateType() const = 0;
82 
83  // Returns the federate name
84  virtual const std::wstring& federateName() const = 0;
85 
86  // Returns the federation name
87  virtual const std::wstring& federationName() const = 0;
88 
89  // Returns true if the federate name field is supported
90  virtual bool isFederateNameSupported() const = 0;
91 
92  // Returns true if the optional interaction module extension is supported
93  virtual bool isInteractionExtensionSupported() const = 0;
94 
95  // Returns true if DDM is enabled
96  virtual bool isDdmEnabled() const;
97 
98  // Returns true if ownership transfer is enabled
99  virtual bool isOwnershipTransferEnabled() const;
100 
101  // Returns true if the federate is currently connected
102  virtual bool isConnected() const;
103 
104  // Returns true if the federate is currently joined to the federation
105  virtual bool isJoined() const;
106 
107  // Returns true if the federate is currently subscribed
108  virtual bool isSubscribed() const;
109 
110  // Returns a list of pending text events
111  virtual void getPendingTextEvents(std::list<TextEvent>& textEvents);
112 
113  // Access the notification log
114  virtual const std::wstring& getLog() const;
115  virtual void clearLog();
116 
117 protected:
118 
119  // Calculates the new locations for all owned balls
120  virtual void moveBalls();
121 
122  // Calculates the new location for the ball
123  virtual void calculateNewLoc(double x, double y, double distance,
124  double direction, double& newX, double& newY) const;
125 
126  // Calculate if a collision occurred with a vertical wall, and, if so,
127  // determine new location and direction of the ball
128  virtual bool calculateVertWallCollision(double x, double y,
129  double distance, double direction, double newX, double newY,
130  double radius, double& finalDirection, double& distAfterColl,
131  double& collX, double& collY, double& finalX, double& finalY) const;
132 
133  // Calculate if a collision occurred with a horizontal wall, and, if so,
134  // determine new location and direction of the ball
135  virtual bool calculateHorizWallCollision(double x, double y,
136  double distance, double direction, double newX, double newY,
137  double radius, double& finalDirection, double& distAfterColl,
138  double& collX, double& collY, double& finalX, double& finalY) const;
139 
140  // Sends updates on all owned balls to other federates in the federation
141  virtual void sendUpdates() = 0;
142 
143  // Receives updates on balls from other federates in the federation
144  virtual void receiveUpdates() = 0;
145 
146  // Request the RTI to create the a new ball
147  virtual void requestNewBall(Ball* ball, const std::wstring name) = 0;
148 
149 private:
150 
151  // No default constructor
152  BallController();
153 
154 protected:
155 
158 
159  std::list<TextEvent> myPendingTextEvents;
160 
166 
167  int myMinX;
168  int myMinY;
169  int myMaxX;
170  int myMaxY;
171 
172  unsigned int myNextBallNumber;
174 
175  std::wstring myLog;
176 
177  // Math constants
178  static const double pi;
179  static const double maxRadians;
180  static const double maxDegrees;
181  static const double degreesToRadians;
182 };
183 
184 #endif

Document ID: Generated on Wed Mar 11 20:26:49 EDT 2015 from SVN revision 150939
Copyright © 2005-2015 VT MÄK Inc. All Rights Reserved (www.mak.com)