KoduWorld.cc
Go to the documentation of this file.00001
00002
00003 #include "Kodu/KoduWorld.h"
00004 #include "Kodu/General/GeneralFncs.h"
00005
00006
00007 #include "DualCoding/Point.h"
00008 #include "DualCoding/ShapeFuns.h"
00009 #include "DualCoding/VRmixin.h"
00010 using namespace DualCoding;
00011
00012 namespace Kodu {
00013
00014 ScoreKeeper KoduWorld::globalScoreKeeper;
00015
00016 KoduWorld::KoduWorld()
00017 : thisAgent(),
00018 shapeToTagMap(),
00019 starConstellation(),
00020 worldBoundsPolygon(),
00021 worldSideLength(2000.0f)
00022 { }
00023
00024
00025 KoduWorld::~KoduWorld() {
00026
00027 globalScoreKeeper.initialize();
00028 }
00029
00030 void KoduWorld::applyGlobalScoreChanges(std::queue<ScoreChange>& queue) {
00031 while (!queue.empty()) {
00032 const ScoreChange& change = queue.front();
00033
00034 switch(change.operationType) {
00035
00036 case KoduActionScore::ST_SCORE:
00037 globalScoreKeeper.addScore(change.designator, change.value);
00038 break;
00039
00040
00041 case KoduActionScore::ST_SET_SCORE:
00042 globalScoreKeeper.setScore(change.designator, change.value);
00043 break;
00044
00045
00046 case KoduActionScore::ST_SUBTRACT:
00047 globalScoreKeeper.subtractScore(change.designator, change.value);
00048 break;
00049 }
00050
00051 queue.pop();
00052 }
00053 }
00054
00055 int KoduWorld::getScoreValue(const std::string& kDesignator) {
00056 return globalScoreKeeper.checkScoreValue(kDesignator);
00057 }
00058
00059 int KoduWorld::getTagIdForShape(int worldShapeId) {
00060 if (shapeTagPairExists(worldShapeId))
00061 return shapeToTagMap[worldShapeId];
00062 else
00063 return (-1);
00064 }
00065
00066 void KoduWorld::pairShapeWithTag(int worldShapeId, int aprilTagId) {
00067 if (!shapeTagPairExists(worldShapeId)) {
00068 shapeToTagMap.insert(std::pair<int, int>(worldShapeId, aprilTagId));
00069 }
00070 }
00071
00072 bool KoduWorld::shapeTagPairExists(int worldShapeId) const {
00073 return static_cast<bool>(shapeToTagMap.count(worldShapeId));
00074 }
00075
00076 const std::map<int, Point>& KoduWorld::getStarConstellation() const {
00077 return starConstellation;
00078 }
00079
00080 const Shape<PolygonData>& KoduWorld::getWorldBoundsPolygon() const {
00081 return worldBoundsPolygon;
00082 }
00083
00084 void KoduWorld::setStarConstellation(const std::vector<ShapeRoot>& kConstellation) {
00085 for (std::size_t i = 0; i < kConstellation.size(); i++) {
00086 const Shape<AprilTagData>& kTag = ShapeRootTypeConst(kConstellation[i], AprilTagData);
00087 starConstellation.insert(std::pair<int, Point>(kTag->getTagID(), kTag->getCentroid()));
00088 std::cout << "inserted pair: {" << kTag->getTagID() << ", "
00089 << kTag->getCentroid() << "}\n";
00090 }
00091 }
00092
00093 void KoduWorld::generateWorldBoundsPolygon() {
00094
00095 std::vector<Point> worldBounds;
00096 const float kSideLength = 2000.0f;
00097 const float kHalfSideLength = kSideLength / 2.0f;
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 const float maxX = 1500.0f;
00109 const float minX = maxX - kSideLength;
00110 const float maxY = kHalfSideLength;
00111 const float minY = -1.0f * kHalfSideLength;
00112
00113
00114 worldBounds.push_back(Point(minX, maxY, 0, allocentric));
00115 worldBounds.push_back(Point(maxX, maxY, 0, allocentric));
00116 worldBounds.push_back(Point(maxX, minY, 0, allocentric));
00117 worldBounds.push_back(Point(minX, minY, 0, allocentric));
00118 worldBounds.push_back(worldBounds[0]);
00119
00120
00121 NEW_SHAPE(wBoundPolygon, PolygonData, new PolygonData(VRmixin::worldShS, worldBounds, true));
00122 worldBoundsPolygon = wBoundPolygon;
00123 worldBoundsPolygon->setName("worldBoundsPolygon");
00124 worldBoundsPolygon->setObstacle(true);
00125 }
00126
00127 }