Permalink
Browse files

RGJ05 fixed

  • Loading branch information...
1 parent c14aefb commit d824992ef734a171a34e7f81aea0f39d7f990f2d @svenstaro committed Oct 20, 2011
View
@@ -12,7 +12,7 @@ find_package(Bullet REQUIRED)
find_package(Boost COMPONENTS system filesystem REQUIRED)
find_package(ImageMagick COMPONENTS Magick++ REQUIRED)
-add_definitions(-Wall -Wextra -g -pedantic -fPIC -std=c++0x -DBOOST_FILESYSTEM_VERSION=3)
+add_definitions(-Wall -Wextra -Werror -Wno-unused-parameter -g -pedantic -fPIC -std=c++0x -DBOOST_FILESYSTEM_VERSION=3)
set(CMAKE_BUILD_TYPE "Debug")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
@@ -63,7 +63,7 @@ const Vector2D Coordinates::WorldFloatToViewPixel(const Vector2D coords) {
return tmp.GetViewPixel();
}
-const float Coordinates::WorldFloatToWorldPixel(const float length) {
+float Coordinates::WorldFloatToWorldPixel(const float length) {
Coordinates tmp;
tmp.SetWorldFloat(Vector2D(length, 0.f));
return tmp.GetWorldPixel().x;
@@ -24,7 +24,7 @@ class Coordinates {
static const Vector2D ScreenPixelToWorldFloat(const Vector2D coords);
static const Vector2D WorldFloatToViewPixel(const Vector2D coords);
- static const float WorldFloatToWorldPixel(const float length);
+ static float WorldFloatToWorldPixel(const float length);
static const Vector2D GetParallaxDisplacement(const Vector2D position, float displacement_factor);
View
@@ -125,8 +125,8 @@ void Entity::Draw(sf::RenderTarget* target, sf::Shader& shader, bool editor_mode
Vector2D p = Coordinates::WorldFloatToWorldPixel(mPosition);
// TODO: Actually draw
sf::Sprite s;
- s.SetImage(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImage(mImageFile));
- s.SetOrigin(s.GetImage()->GetWidth()/2, s.GetImage()->GetHeight()/2);
+ s.SetTexture(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTexture(mImageFile));
+ s.SetOrigin(s.GetTexture()->GetWidth()/2, s.GetTexture()->GetHeight()/2);
s.SetPosition(p.x, p.y);
s.SetRotation(Vector2D::rad2Deg(mRotation));
s.SetScale(mScale, mScale);
View
@@ -24,34 +24,34 @@ void GameApp::Init() {
// load resources
boost::filesystem::path gfx("../gfx/");
- mResourceManager.AddImage(gfx, "loverobot.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "heart.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "box.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "crystal1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "crystal2.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "crystal3.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "crystal4.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "grass2.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "grass1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "tree1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "flare.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "lightray1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "lightray2.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "lightray3.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "lightray4.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "lightray5.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "lightray6.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "platform.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "rock1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "rock2.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "rock3.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "rock4.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "rock5.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "rock6.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "rock7.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "rock8.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "rock9.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(gfx, "spaceship.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "loverobot.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "heart.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "box.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "crystal1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "crystal2.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "crystal3.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "crystal4.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "grass2.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "grass1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "tree1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "flare.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "lightray1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "lightray2.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "lightray3.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "lightray4.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "lightray5.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "lightray6.svg", 100*METERS_PER_PIXEL, 50*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "platform.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "rock1.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "rock2.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "rock3.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "rock4.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "rock5.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "rock6.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "rock7.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "rock8.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "rock9.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(gfx, "spaceship.svg", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
// -- add new images here
mViewBorder.LoadFromFile("../gfx/view_border.png");
@@ -73,10 +73,10 @@ void GameApp::Run() {
while(mRenderWin->IsOpened()) {
sf::Event event;
- while(mRenderWin->GetEvent(event)) {
+ while(mRenderWin->PollEvent(event)) {
if(event.Type == sf::Event::Closed)
Quit();
- if(event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Key::Quote) {
+ if(event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Keyboard::Quote) {
mDebugGrid = !mDebugGrid;
}
mWorld.HandleEvent(event);
@@ -86,7 +86,6 @@ void GameApp::Run() {
mClock.Reset();
// SFML access class for real-time input
- const sf::Input& input = mRenderWin->GetInput();
float frameTime = mRenderWin->GetFrameTime();
time_budget += time_delta;
@@ -213,12 +212,9 @@ void GameApp::SetGuiPaintingMode(bool guipaint) {
mRenderWin->SetView(*mView);
}
-const sf::Input& GameApp::GetInput() const {
- return mRenderWin.get()->GetInput();
-}
-
Vector2D GameApp::GetMousePosition() const {
- return Vector2D(GetInput().GetMouseX(), GetInput().GetMouseY());
+ return Vector2D(sf::Mouse::GetPosition().x,
+ sf::Mouse::GetPosition().y);
}
const Vector2D GameApp::GetWindowSize() const {
@@ -241,11 +237,11 @@ sf::Color GameApp::GetSpriteColor(const float alpha) const {
return sf::Color(v,v,v, alpha * 255);
}
-World* const GameApp::GetWorldPtr() {
+World* GameApp::GetWorldPtr() {
return &mWorld;
}
-ResourceManager* const GameApp::GetResourceManagerPtr() {
+ResourceManager* GameApp::GetResourceManagerPtr() {
return &mResourceManager;
}
View
@@ -31,7 +31,6 @@ class GameApp : public boost::serialization::singleton<GameApp> {
const Vector2D GetWindowSize() const;
sf::View& GetView();
void SetGuiPaintingMode(bool guipaint);
- const sf::Input& GetInput() const;
Vector2D GetMousePosition() const;
int GetNextId();
@@ -43,8 +42,8 @@ class GameApp : public boost::serialization::singleton<GameApp> {
void SetWorldHearts(int h);
int GetWorldHearts() const;
- World* const GetWorldPtr();
- ResourceManager* const GetResourceManagerPtr();
+ World* GetWorldPtr();
+ ResourceManager* GetResourceManagerPtr();
boost::shared_ptr<sf::RenderWindow> GetRenderWindowPtr();
private:
boost::shared_ptr<sf::RenderWindow> mRenderWin;
@@ -65,7 +64,7 @@ class GameApp : public boost::serialization::singleton<GameApp> {
int mWorldHearts;
bool mDebugGrid;
- sf::Image mViewBorder;
+ sf::Texture mViewBorder;
sf::Music mMusic;
};
@@ -4,7 +4,7 @@
ResourceManager::ResourceManager() {}
ResourceManager::~ResourceManager() {}
-bool ResourceManager::AddImage(const boost::filesystem::path& path,
+bool ResourceManager::AddTexture(const boost::filesystem::path& path,
const std::string& imgname,
const float width,
const float height) {
@@ -28,22 +28,22 @@ bool ResourceManager::AddImage(const boost::filesystem::path& path,
std::string cacheFile = (cacheDir / image_key ).string()+".png";
// if an image with that key already exists in the dictionary, return
- if(mImages.count(image_key) != 0) {
+ if(mTextures.count(image_key) != 0) {
return true;
}
- sf::Image sfimage;
+ sf::Texture sftexture;
bool cache = true;
if(boost::filesystem::is_regular_file(cacheFile)) {
// Load cached file
- bool success = sfimage.LoadFromFile(cacheFile);
- if (success && (int)sfimage.GetHeight() == (int)size.x && (int)sfimage.GetWidth() == (int)size.y) {
+ bool success = sftexture.LoadFromFile(cacheFile);
+ if (success && (int)sftexture.GetHeight() == (int)size.x && (int)sftexture.GetWidth() == (int)size.y) {
cache = false;
- std::cout << "Image " << originalFile << " already exists. Not caching. "<< std::endl;
+ std::cout << "Texture " << originalFile << " already exists. Not caching. "<< std::endl;
} else if (success) {
- std::cout << "Image " << originalFile << " does not exist in the resolution "
- << size.x << "x" << size.y << " but in " << sfimage.GetHeight() << "x" << sfimage.GetWidth() << "." << std::endl;
+ std::cout << "Texture " << originalFile << " does not exist in the resolution "
+ << size.x << "x" << size.y << " but in " << sftexture.GetHeight() << "x" << sftexture.GetWidth() << "." << std::endl;
}
}
@@ -65,33 +65,33 @@ bool ResourceManager::AddImage(const boost::filesystem::path& path,
mimage.write(cacheFile);
// Load cached file
- sfimage.LoadFromFile(cacheFile);
+ sftexture.LoadFromFile(cacheFile);
}
- sfimage.SetSmooth(true);
+ sftexture.SetSmooth(true);
//std::cout << " Added image: "<<image_key << std::endl;
- // Save loaded Image in Dictionary
- mImages[image_key] = sfimage;
+ // Save loaded Texture in Dictionary
+ mTextures[image_key] = sftexture;
return true;
}
-const sf::Image& ResourceManager::GetImage(const std::string& img) {
- if(mImages.count(img) >= 1) {
- return mImages[img];
+const sf::Texture& ResourceManager::GetTexture(const std::string& img) {
+ if(mTextures.count(img) >= 1) {
+ return mTextures[img];
} else {
std::cerr << "Tried getting image '"<<img<<"' but this image doesn't exist!"<<std::endl;
exit(1);
}
}
-const std::vector<std::string> ResourceManager::GetImageKeys() {
+const std::vector<std::string> ResourceManager::GetTextureKeys() {
std::vector<std::string> keys;
- for(auto iter = mImages.begin(); iter != mImages.end(); iter++) {
+ for(auto iter = mTextures.begin(); iter != mTextures.end(); iter++) {
if (iter->first != "view_border") {
keys.push_back(iter->first);
}
@@ -19,18 +19,18 @@ class ResourceManager {
~ResourceManager();
- bool AddImage(const boost::filesystem::path& path, const std::string& imgname,
+ bool AddTexture(const boost::filesystem::path& path, const std::string& imgname,
const float width, const float height);
- const sf::Image& GetImage(const std::string& filename);
- const std::vector<std::string> GetImageKeys();
+ const sf::Texture& GetTexture(const std::string& filename);
+ const std::vector<std::string> GetTextureKeys();
bool AddSoundBuffer(const boost::filesystem::path& path, const std::string& sound, const std::string& key="");
const sf::SoundBuffer& GetSoundBuffer(const std::string& sound);
void AddFont(sf::Font& font, std::string key);
const sf::Font& GetFont(const std::string& key);
private:
- boost::ptr_map<std::string, sf::Image> mImages;
+ boost::ptr_map<std::string, sf::Texture> mTextures;
boost::ptr_map<std::string, sf::Font> mFonts;
boost::ptr_map<std::string, sf::SoundBuffer> mSoundBuffers;
};
Oops, something went wrong.

0 comments on commit d824992

Please sign in to comment.