ese 519 include files

Dependents:   PROJECT_3D_AUDIO COG4050_adxl355_tilt COG4050_adxl355_tilt COG4050_adxl355_tilt_4050

Committer:
niv17
Date:
Tue Apr 07 21:09:51 2015 +0000
Revision:
0:5347612e39a3
april_7 _ sonic start

Who changed what in which revision?

UserRevisionLine numberNew contents of line
niv17 0:5347612e39a3 1 #ifndef WORLD_H
niv17 0:5347612e39a3 2 #define WORLD_H
niv17 0:5347612e39a3 3
niv17 0:5347612e39a3 4 #include <stdexcept>
niv17 0:5347612e39a3 5 #include <vector>
niv17 0:5347612e39a3 6 #include "pthread.h"
niv17 0:5347612e39a3 7 #include <unistd.h>
niv17 0:5347612e39a3 8
niv17 0:5347612e39a3 9 #include "location.h"
niv17 0:5347612e39a3 10 #include "velocity.h"
niv17 0:5347612e39a3 11 #include "AudioObj.h"
niv17 0:5347612e39a3 12 #include "Player.h"
niv17 0:5347612e39a3 13
niv17 0:5347612e39a3 14 // TODO: Move AUDIO_OBJECT_LOAD_INTERVAL to Sonic.h
niv17 0:5347612e39a3 15 #define AUDIO_OBJECT_LOAD_INTERVAL 10000 // interval at which input is loaded into audio object buffers
niv17 0:5347612e39a3 16
niv17 0:5347612e39a3 17 using namespace std;
niv17 0:5347612e39a3 18
niv17 0:5347612e39a3 19 // TODO: finish documenting World class
niv17 0:5347612e39a3 20 class World {
niv17 0:5347612e39a3 21
niv17 0:5347612e39a3 22 Player player;
niv17 0:5347612e39a3 23 vector<AudioObj *> objList;
niv17 0:5347612e39a3 24 float threshold;
niv17 0:5347612e39a3 25 pthread_t writeThread;
niv17 0:5347612e39a3 26 bool isWriteThreadCreated;
niv17 0:5347612e39a3 27
niv17 0:5347612e39a3 28 static void *writeAudioObjects (void *);
niv17 0:5347612e39a3 29
niv17 0:5347612e39a3 30 public:
niv17 0:5347612e39a3 31 static const int MAX_OBJ = 20;
niv17 0:5347612e39a3 32
niv17 0:5347612e39a3 33 //Constructors
niv17 0:5347612e39a3 34
niv17 0:5347612e39a3 35 /**
niv17 0:5347612e39a3 36 Default constructor creates a player at the world's origin, {0,0,0}.
niv17 0:5347612e39a3 37 */
niv17 0:5347612e39a3 38 World() : threshold(0.05), isWriteThreadCreated(false) {}
niv17 0:5347612e39a3 39
niv17 0:5347612e39a3 40 /**
niv17 0:5347612e39a3 41 Creates a player at the
niv17 0:5347612e39a3 42 location specified by the first parameter,
niv17 0:5347612e39a3 43 and sets the player's bearing specified by
niv17 0:5347612e39a3 44 the second parameter.
niv17 0:5347612e39a3 45 */
niv17 0:5347612e39a3 46 World(const Location& loc, const Velocity& vel, float bear) : player(Player(loc,vel, bear)), threshold(0.05), isWriteThreadCreated(false) {}
niv17 0:5347612e39a3 47
niv17 0:5347612e39a3 48 ~World();
niv17 0:5347612e39a3 49
niv17 0:5347612e39a3 50 //Getters
niv17 0:5347612e39a3 51 float getPlayerBearing();
niv17 0:5347612e39a3 52
niv17 0:5347612e39a3 53 /**
niv17 0:5347612e39a3 54 Returns a reference to the player.
niv17 0:5347612e39a3 55 */
niv17 0:5347612e39a3 56 Player& getPlayer();
niv17 0:5347612e39a3 57
niv17 0:5347612e39a3 58 /**
niv17 0:5347612e39a3 59 Returns a reference to the audio object at the
niv17 0:5347612e39a3 60 specified index.
niv17 0:5347612e39a3 61 */
niv17 0:5347612e39a3 62 AudioObj* getAudioObj(size_t index) const;
niv17 0:5347612e39a3 63
niv17 0:5347612e39a3 64 /**
niv17 0:5347612e39a3 65 Returns the array of the player's location.
niv17 0:5347612e39a3 66 */
niv17 0:5347612e39a3 67 Location getPlayerLocation() const;
niv17 0:5347612e39a3 68 void getPlayerLocation(float &xOut, float &yOut, float &zOut);
niv17 0:5347612e39a3 69 void getPlayerGpsLocation(float &latitudeOut, float &longitudeOut, float &altitudeOut);
niv17 0:5347612e39a3 70 /**
niv17 0:5347612e39a3 71 Returns the number of audio objects in the world.
niv17 0:5347612e39a3 72 */
niv17 0:5347612e39a3 73 int getNumObj();
niv17 0:5347612e39a3 74
niv17 0:5347612e39a3 75 // Setters
niv17 0:5347612e39a3 76 void setPlayerLocation(float x, float y, float z);
niv17 0:5347612e39a3 77 void setPlayerGpsLocation(float latitude, float longitude, float altitude);
niv17 0:5347612e39a3 78 void setPlayerBearing(float bearing);
niv17 0:5347612e39a3 79
niv17 0:5347612e39a3 80 /**
niv17 0:5347612e39a3 81 Adds an audio object to the world. Returns the
niv17 0:5347612e39a3 82 index of the created object. Sets the location
niv17 0:5347612e39a3 83 of the created object at the world's origin, {0,0,0}.
niv17 0:5347612e39a3 84 */
niv17 0:5347612e39a3 85 AudioObj* addAudioObj(const std::string wavFileName, bool isBackgroundObject=false);
niv17 0:5347612e39a3 86
niv17 0:5347612e39a3 87
niv17 0:5347612e39a3 88 AudioObj* addAudioObj(const std::string wavFileName, const Location& loc, bool isGpsObject=false);
niv17 0:5347612e39a3 89
niv17 0:5347612e39a3 90 /**
niv17 0:5347612e39a3 91 Adds an audio object to the world. Returns the
niv17 0:5347612e39a3 92 index of the created object. Sets the location
niv17 0:5347612e39a3 93 of the created object at the location specified
niv17 0:5347612e39a3 94 by the parameter.
niv17 0:5347612e39a3 95 */
niv17 0:5347612e39a3 96 AudioObj* addAudioObj(const std::string wavFileName, const Location& loc, const Velocity& vel);
niv17 0:5347612e39a3 97
niv17 0:5347612e39a3 98 AudioObj* addBackgroundAudioObj(const std::string wavFileName);
niv17 0:5347612e39a3 99
niv17 0:5347612e39a3 100 void createWriteThread();
niv17 0:5347612e39a3 101
niv17 0:5347612e39a3 102
niv17 0:5347612e39a3 103 };
niv17 0:5347612e39a3 104
niv17 0:5347612e39a3 105 #endif