Browse files

Fixing for new SFML

  • Loading branch information...
1 parent d21af98 commit 1e16f42ae58196f9f47deee73b726b37d198eab4 @svenstaro committed Oct 14, 2011
View
13 GGJ2011/src/AnimatedSprite.cpp
@@ -2,7 +2,6 @@
#include <iostream>
#include <SFML/Graphics/Sprite.hpp>
-#include <SFML/Graphics/Image.hpp>
using namespace sf;
@@ -15,8 +14,8 @@ AnimatedSprite::AnimatedSprite() {
mTimeSinceLastFrame = 0;
}
-AnimatedSprite::AnimatedSprite(const Image& Img, const Vector2f& Position, const Vector2f& Scale, float Rotation, const Color& Col) {
- SetImage(Img);
+AnimatedSprite::AnimatedSprite(const Texture& Texture, const Vector2f& Position, const Vector2f& Scale, float Rotation, const Color& Col) {
+ SetTexture(Texture);
SetPosition(Position);
SetScale(Scale);
SetRotation(Rotation);
@@ -78,11 +77,11 @@ void AnimatedSprite::Render(RenderTarget&, Renderer& renderer) const
float width = mSubRectSize.x;
float height = mSubRectSize.y;
- // Check if the image is valid, and calculate the texture coordinates
+ // Check if the texture is valid, and calculate the texture coordinates
FloatRect coords;
IntRect subrect(mSubRectOffset.x + mSubRectSize.x * mFrameNumber, mSubRectOffset.y, mSubRectSize.x, mSubRectSize.y);
- if (GetImage())
- coords = GetImage()->GetTexCoords(subrect);
+ if (GetTexture())
+ coords = GetTexture()->GetTexCoords(subrect);
// Compute the texture coordinates
float left = coords.Left;
@@ -91,7 +90,7 @@ void AnimatedSprite::Render(RenderTarget&, Renderer& renderer) const
float bottom = coords.Top + coords.Height;
// Bind the texture
- renderer.SetTexture(GetImage());
+ renderer.SetTexture(GetTexture());
// Draw the sprite's geometry
renderer.Begin(Renderer::TriangleStrip);
View
2 GGJ2011/src/AnimatedSprite.hpp
@@ -11,7 +11,7 @@ using namespace sf;
class AnimatedSprite : public sf::Sprite {
public:
AnimatedSprite();
- explicit AnimatedSprite(const Image& Img,
+ explicit AnimatedSprite(const Texture& Texture,
const Vector2f& Position = Vector2f(0, 0),
const Vector2f& Scale = Vector2f(1, 1),
float Rotation = 0.f,
View
22 GGJ2011/src/Entity.cpp
@@ -14,8 +14,8 @@ void Entity::Initialize(World& world) {
SetUsePhysics(world, false);
}
-void Entity::Initialize(World& world, const std::string& imagefile, int layer, bool use_physics) {
- mImageFile = imagefile;
+void Entity::Initialize(World& world, const std::string& texturefile, int layer, bool use_physics) {
+ mTextureFile = texturefile;
mLayer = layer;
mUsePhysics = false;
SetUsePhysics(world, use_physics);
@@ -62,9 +62,9 @@ void Entity::InitializePhysics() {
if(mUID.substr(0,5) == "empty") {
mCollisionShape = boost::shared_ptr<btCollisionShape>(new btBoxShape(btVector3(15*mScale, 1*mScale, 1)));
- } else if(mImageFile == "evil1") {
+ } else if(mTextureFile == "evil1") {
mCollisionShape = boost::shared_ptr<btCollisionShape>(new btBoxShape(btVector3(0.5*mScale, 0.22*mScale, 1)));
- } else if(mImageFile == "evil2") {
+ } else if(mTextureFile == "evil2") {
mCollisionShape = boost::shared_ptr<btCollisionShape>(new btBoxShape(btVector3(0.5*mScale, 0.05*mScale, 1)));
} else {
mCollisionShape = boost::shared_ptr<btCollisionShape>(new btBoxShape(btVector3(1.2*mScale, 1.2*mScale, 1)));
@@ -127,8 +127,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(mTextureFile));
+ 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);
@@ -150,12 +150,12 @@ void Entity::DrawAllAttachments(sf::RenderTarget* target, sf::Shader& shader) {
}
}
-void Entity::SetImage(const std::string& filename) {
- mImageFile = filename;
+void Entity::SetTexture(const std::string& filename) {
+ mTextureFile = filename;
}
-const std::string& Entity::GetImage() const {
- return mImageFile;
+const std::string& Entity::GetTexture() const {
+ return mTextureFile;
}
void Entity::GenerateUID() {
@@ -264,7 +264,7 @@ bool Entity::SortHelper(const Entity& l, const Entity& r) {
void Entity::Save(boost::property_tree::ptree* pt) {
pt->add("entities."+mUID+".x", mPosition.x);
pt->add("entities."+mUID+".y", mPosition.y);
- pt->add("entities."+mUID+".img", mImageFile);
+ pt->add("entities."+mUID+".img", mTextureFile);
pt->add("entities."+mUID+".rot", mRotation);
pt->add("entities."+mUID+".a", mAlpha);
pt->add("entities."+mUID+".s", mScale);
View
8 GGJ2011/src/Entity.hpp
@@ -49,7 +49,7 @@ class Entity : public GameObject {
~Entity();
virtual void Initialize(World& world);
- virtual void Initialize(World& world, const std::string& imagefile, int layer=1, bool use_physics = false);
+ virtual void Initialize(World& world, const std::string& texturefile, int layer=1, bool use_physics = false);
virtual void Initialize(World& world, boost::property_tree::ptree* pt, std::string uid);
virtual void InitializePhysics();
@@ -61,8 +61,8 @@ class Entity : public GameObject {
virtual void Draw(sf::RenderTarget* target, sf::Shader& shader, bool editor_mode = false) const;
void DrawAllAttachments(sf::RenderTarget* target, sf::Shader& shader);
- void SetImage(const std::string& filename);
- const std::string& GetImage() const;
+ void SetTexture(const std::string& filename);
+ const std::string& GetTexture() const;
void GenerateUID();
void SetUID(const std::string& id);
@@ -120,7 +120,7 @@ class Entity : public GameObject {
protected:
std::string mUID;
- std::string mImageFile;
+ std::string mTextureFile;
int mLayer;
int mLocalLayer;
View
112 GGJ2011/src/GameApp.cpp
@@ -78,59 +78,59 @@ void GameApp::Init(char* argv[]) {
}
// load resources
- mResourceManager.AddImage(data / "gfx", "box.png", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "rail.png", 20*METERS_PER_PIXEL, 20*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "target.png", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "box.png", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "rail.png", 20*METERS_PER_PIXEL, 20*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "target.png", 200*METERS_PER_PIXEL, 200*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "magnet_pull.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "magnet_push.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "magnet_off.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "magnet_pull.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "magnet_push.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "magnet_off.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "static_pull.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "static_push.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "static_off.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "static_pull.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "static_push.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "static_off.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "spring_pull.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "spring_push.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "spring_off.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "spring_pull.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "spring_push.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "spring_off.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "evil1.png", 64*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "evil2.png", 64*METERS_PER_PIXEL, 16*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "evil1.png", 64*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "evil2.png", 64*METERS_PER_PIXEL, 16*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "cursor_pull.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "cursor_push.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "cursor_default.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "cursor_spring_pull.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "cursor_spring_push.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "cursor_pull.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "cursor_push.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "cursor_default.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "cursor_spring_pull.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "cursor_spring_push.png", 32*METERS_PER_PIXEL, 32*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "selector.png", 330*METERS_PER_PIXEL, 160*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "selector.png", 330*METERS_PER_PIXEL, 160*METERS_PER_PIXEL);
// -- add new images here
- mResourceManager.AddImage(data / "gfx" / "maps", "level01.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx" / "maps", "level02.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx" / "maps", "level03.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx" / "maps", "level04.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx" / "maps", "level05.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx" / "maps", "level06.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx" / "maps", "level07.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx" / "maps", "level08.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx" / "maps", "level09.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx" / "maps", "level10.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
-
- mResourceManager.AddImage(data / "gfx", "icon_build.png", 1.f,1.f);
- mResourceManager.AddImage(data / "gfx", "icon_go.png", 1.f,1.f);
- mResourceManager.AddImage(data / "gfx", "icon_retry.png", 1.f,1.f);
- mResourceManager.AddImage(data / "gfx", "gui_blob.png", 1.f, 1.f);
-
- mResourceManager.AddImage(data / "gfx", "clock_lower.png", 1.f, 1.f);
- mResourceManager.AddImage(data / "gfx", "clock_upper.png", 1.f, 1.f);
-
- mResourceManager.AddImage(data / "gfx", "titlescreen.png", 1024*METERS_PER_PIXEL, 600*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "teamlogo.png", mRenderWin->GetWidth()*METERS_PER_PIXEL, mRenderWin->GetHeight()*METERS_PER_PIXEL);
- mResourceManager.AddImage(data / "gfx", "empty.png", 150*METERS_PER_PIXEL, 10*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level01.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level02.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level03.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level04.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level05.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level06.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level07.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level08.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level09.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx" / "maps", "level10.png", 1056*METERS_PER_PIXEL, 624*METERS_PER_PIXEL);
+
+ mResourceManager.AddTexture(data / "gfx", "icon_build.png", 1.f,1.f);
+ mResourceManager.AddTexture(data / "gfx", "icon_go.png", 1.f,1.f);
+ mResourceManager.AddTexture(data / "gfx", "icon_retry.png", 1.f,1.f);
+ mResourceManager.AddTexture(data / "gfx", "gui_blob.png", 1.f, 1.f);
+
+ mResourceManager.AddTexture(data / "gfx", "clock_lower.png", 1.f, 1.f);
+ mResourceManager.AddTexture(data / "gfx", "clock_upper.png", 1.f, 1.f);
+
+ mResourceManager.AddTexture(data / "gfx", "titlescreen.png", 1024*METERS_PER_PIXEL, 600*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "teamlogo.png", mRenderWin->GetWidth()*METERS_PER_PIXEL, mRenderWin->GetHeight()*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "empty.png", 150*METERS_PER_PIXEL, 10*METERS_PER_PIXEL);
// animation test
- mResourceManager.AddImage(data / "gfx", "cursors.png", 256*METERS_PER_PIXEL, 256*METERS_PER_PIXEL);
+ mResourceManager.AddTexture(data / "gfx", "cursors.png", 256*METERS_PER_PIXEL, 256*METERS_PER_PIXEL);
mResourceManager.AddSoundBuffer(data / "snd", "collide.ogg", "collide");
mResourceManager.AddSoundBuffer(data / "snd", "push.ogg", "push");
@@ -158,7 +158,7 @@ void GameApp::Init(char* argv[]) {
// Animation test
- mBusy.SetImage(mResourceManager.GetImage("cursors"));
+ mBusy.SetTexture(mResourceManager.GetTexture("cursors"));
mBusy.SetSubRectSize(sf::Vector2f(16,16));
mBusy.SetSubRectOffset(sf::Vector2f(0,16));
mBusy.SetFPS(8);
@@ -286,8 +286,8 @@ void GameApp::Run() {
t.SetFont(mResourceManager.GetFont("custom"));
mRenderWin->Draw(t);*/
} else if(mWorld.GetCurrentLevel() != 0){
- sf::Sprite clock(mResourceManager.GetImage("clock_lower"));
- clock.SetPosition(mRenderWin->GetWidth() / 2 - clock.GetImage()->GetWidth() / 2, 0);
+ sf::Sprite clock(mResourceManager.GetTexture("clock_lower"));
+ clock.SetPosition(mRenderWin->GetWidth() / 2 - clock.GetTexture()->GetWidth() / 2, 0);
mRenderWin->Draw(clock);
boost::posix_time::time_duration td = boost::posix_time::seconds(mTotalTime);
@@ -308,7 +308,7 @@ void GameApp::Run() {
mRenderWin->Draw(t);
- clock.SetImage(mResourceManager.GetImage("clock_upper"));
+ clock.SetTexture(mResourceManager.GetTexture("clock_upper"));
mRenderWin->Draw(clock);
}
@@ -323,13 +323,13 @@ void GameApp::Run() {
mCursor.SetColor(sf::Color(255,255,255,255));
if(mAppMode != AM_PLAY)
- mCursor.SetImage(mResourceManager.GetImage("cursor_default"));
+ mCursor.SetTexture(mResourceManager.GetTexture("cursor_default"));
else {
if(mWorld.GetCurrentRail() != NULL && mWorld.GetCurrentRail()->GetMover().GetMoverType() == MT_SPRING && mWorld.GetBoxEntity() != NULL) {
if(sf::Mouse::IsButtonPressed(sf::Mouse::Left))
- mCursor.SetImage(mResourceManager.GetImage("cursor_spring_push"));
+ mCursor.SetTexture(mResourceManager.GetTexture("cursor_spring_push"));
else
- mCursor.SetImage(mResourceManager.GetImage("cursor_spring_pull"));
+ mCursor.SetTexture(mResourceManager.GetTexture("cursor_spring_pull"));
Vector2D mp = Coordinates::ScreenPixelToWorldFloat(GetMousePosition());
btVector3 dir(mp.x, mp.y, 0);
@@ -345,10 +345,10 @@ void GameApp::Run() {
mCursor.SetColor(sf::Color(255,255,255,a));
} else {
if(sf::Mouse::IsButtonPressed(sf::Mouse::Left)) {
- mCursor.SetImage(mResourceManager.GetImage("cursor_push"));
+ mCursor.SetTexture(mResourceManager.GetTexture("cursor_push"));
mResourceManager.PlaySound("push");
} else {
- mCursor.SetImage(mResourceManager.GetImage("cursor_pull"));
+ mCursor.SetTexture(mResourceManager.GetTexture("cursor_pull"));
} mCursor.SetRotation(mCursorRotation);
}
}
@@ -359,12 +359,12 @@ void GameApp::Run() {
Vector2D b1(mRenderWin->GetWidth() - 1 * 70 - 10,42);
Vector2D b2(mRenderWin->GetWidth() - 2 * 70 - 10,42);
- sf::Sprite s1(mResourceManager.GetImage("icon_retry"));
+ sf::Sprite s1(mResourceManager.GetTexture("icon_retry"));
sf::Sprite s2;
if(mAppMode == AM_PLAY)
- s2.SetImage(mResourceManager.GetImage("icon_build"));
+ s2.SetTexture(mResourceManager.GetTexture("icon_build"));
else
- s2.SetImage(mResourceManager.GetImage("icon_go"));
+ s2.SetTexture(mResourceManager.GetTexture("icon_go"));
s1.SetOrigin(32,32);
s2.SetOrigin(32,32);
@@ -386,7 +386,7 @@ void GameApp::Run() {
// Draw crdits
if(mCreditsActive) {
- sf::Sprite credits(mResourceManager.GetImage("teamlogo"));
+ sf::Sprite credits(mResourceManager.GetTexture("teamlogo"));
credits.Move(0, mTimeSinceCreditsActive * -100);
mRenderWin->Draw(credits);
View
4 GGJ2011/src/Mover.cpp
@@ -60,8 +60,8 @@ void Mover::Update(float time_delta) {
else
img += "pull";
- mSprite.SetImage(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImage(img));
- mSprite.SetOrigin(mSprite.GetImage()->GetWidth() / 2,mSprite.GetImage()->GetHeight() / 2);
+ mSprite.SetTexture(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTexture(img));
+ mSprite.SetOrigin(mSprite.GetTexture()->GetWidth() / 2,mSprite.GetTexture()->GetHeight() / 2);
}
void Mover::Draw(sf::RenderTarget* target, sf::Shader& shader, bool editor_mode) const {
View
2 GGJ2011/src/Rail.cpp
@@ -81,7 +81,7 @@ void Rail::InitializePhysics() {
}
void Rail::Update(float time_delta) {
- mTiledSprite.SetImage(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImage("rail"));
+ mTiledSprite.SetTexture(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTexture("rail"));
Vector2D diff = Coordinates::WorldFloatToWorldPixel(mPoint2 - mPoint1);
mTiledSprite.SetPosition(Coordinates::WorldFloatToWorldPixel(mPoint1).x,Coordinates::WorldFloatToWorldPixel(mPoint1).y);
mTiledSprite.SetScale(diff.Magnitude(), 20);
View
54 GGJ2011/src/ResourceManager.cpp
@@ -4,13 +4,13 @@
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) {
if(!boost::filesystem::is_regular_file(path/imgname)) {
- std::cerr << "Tried loading image path '" << (path/imgname).string() << "' but this image path doesn't exist!" << std::endl;
+ std::cerr << "Tried loading texture path '" << (path/imgname).string() << "' but this texture path doesn't exist!" << std::endl;
exit(1);
}
@@ -21,44 +21,44 @@ bool ResourceManager::AddImage(const boost::filesystem::path& path,
std::string originalFile = (path / imgname).string();
// if the optional param key is not given, use the basename as key
- std::string image_key = boost::filesystem::basename(originalFile);
+ std::string texture_key = boost::filesystem::basename(originalFile);
// Create Cache Paths
//boost::filesystem::path cacheDir = (path / "cached").string();
- //std::string cacheFile = (cacheDir / image_key ).string()+".png";
+ //std::string cacheFile = (cacheDir / texture_key ).string()+".png";
- // if an image with that key already exists in the dictionary, return
- if(mImages.count(image_key) != 0) {
+ // if an texture with that key already exists in the dictionary, return
+ if(mTextures.count(texture_key) != 0) {
return true;
}
- sf::Image sfimage;
- bool success = sfimage.LoadFromFile(originalFile);
+ sf::Texture sftexture;
+ bool success = sftexture.LoadFromFile(originalFile);
if(!success) {
- std::cerr << "Image " << originalFile << " does not exists. Exit. "<< std::endl;
+ std::cerr << "Texture " << originalFile << " does not exists. Exit. "<< std::endl;
exit(1);
}
/*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;
}
}
if(cache){
- std::cout << ":: Caching image " << originalFile << std::endl;
+ std::cout << ":: Caching texture " << originalFile << std::endl;
// Create cache directory
boost::filesystem::create_directory(cacheDir.string());
- // Load, convert and save image (originalFile > cacheFile)
+ // Load, convert and save texture (originalFile > cacheFile)
Magick::Image mimage;
mimage.backgroundColor(Magick::Color(0, 0, 0, 65535));
mimage.density(Magick::Geometry(144, 144));
@@ -70,33 +70,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;
+ //std::cout << " Added texture: "<< texture_key << std::endl;
+ // Save loaded texture in Dictionary
+ mTextures[texture_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;
+ std::cerr << "Tried getting texture '"<<img<<"' but this texture 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);
}
View
8 GGJ2011/src/ResourceManager.hpp
@@ -19,10 +19,10 @@ 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);
@@ -34,7 +34,7 @@ class ResourceManager {
void StopSound(std::string key);
void StopSounds();
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;
boost::ptr_map<std::string, sf::Sound> mSounds;
View
15 GGJ2011/src/TiledSprite.cpp
@@ -2,7 +2,6 @@
#include <iostream>
#include <SFML/Graphics/Sprite.hpp>
-#include <SFML/Graphics/Image.hpp>
using namespace sf;
@@ -11,8 +10,8 @@ TiledSprite::TiledSprite() {
SetSubRect(IntRect(0,0,1,1));
}
-TiledSprite::TiledSprite(const Image& Img, const Vector2f& Position, const Vector2f& Scale, const float Rotation, const Color& Col) {
- SetImage(Img);
+TiledSprite::TiledSprite(const Texture& Img, const Vector2f& Position, const Vector2f& Scale, const float Rotation, const Color& Col) {
+ SetTexture(Img);
SetPosition(Position);
SetScale(Scale);
SetRotation(Rotation);
@@ -21,7 +20,7 @@ TiledSprite::TiledSprite(const Image& Img, const Vector2f& Position, const Vecto
}
void TiledSprite::Render(RenderTarget&, Renderer& renderer) const {
- const Image* image = GetImage();
+ const Texture* texture = GetTexture();
const IntRect& sub_rect = GetSubRect();
@@ -36,16 +35,16 @@ void TiledSprite::Render(RenderTarget&, Renderer& renderer) const {
float sw = GetScale().x; // 200
float sh = GetScale().y; // 30
- // Check if the image is valid
- if(image) {
+ // Check if the texture is valid
+ if(texture) {
// Bind the texture
- renderer.SetTexture(image);
+ renderer.SetTexture(texture);
// 9 subrects
for(int x = 0; x < 3; x++) {
for(int y = 0; y < 3; y++) {
// Calculate the texture coordinates
- FloatRect tc = image->GetTexCoords(IntRect(x * subw, y * subh, subw, subh));
+ FloatRect tc = texture->GetTexCoords(IntRect(x * subw, y * subh, subw, subh));
float left = 0, top = 0, right = 0, bottom = 0;
float hp = subw/sw;
View
2 GGJ2011/src/TiledSprite.hpp
@@ -11,7 +11,7 @@ using namespace sf;
class TiledSprite : public sf::Sprite {
public:
TiledSprite();
- explicit TiledSprite(const Image& Img,
+ explicit TiledSprite(const Texture& Img,
const Vector2f& Position = Vector2f(0, 0),
const Vector2f& Scale = Vector2f(1, 1),
const float Rotation = 0.f,
View
22 GGJ2011/src/World.cpp
@@ -162,7 +162,7 @@ void World::Draw(sf::RenderTarget* target, sf::Shader& shader) {
GameApp::get_mutable_instance().SetGuiPaintingMode(false);
// draw background
if(mCurrentLevel > 0) {
- sf::Sprite back(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImage("level"+leadingZeros2(mCurrentLevel, 2)));
+ sf::Sprite back(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTexture("level"+leadingZeros2(mCurrentLevel, 2)));
target->Draw(back);
}
@@ -227,11 +227,11 @@ void World::Draw(sf::RenderTarget* target, sf::Shader& shader) {
Vector2D b2(target->GetWidth() / 2, 42);
Vector2D b3(target->GetWidth() / 2 + 50, 42);
- sf::Sprite s1(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImage("magnet_off"));
- sf::Sprite s2(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImage("spring_off"));
- sf::Sprite s3(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImage("static_off"));
+ sf::Sprite s1(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTexture("magnet_off"));
+ sf::Sprite s2(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTexture("spring_off"));
+ sf::Sprite s3(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTexture("static_off"));
- sf::Sprite sel(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImage("selector"));
+ sf::Sprite sel(GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTexture("selector"));
sel.SetOrigin(330 / 2, 0);
sel.SetScale(0.5,0.6);
sel.SetPosition(target->GetWidth() / 2, 10);
@@ -339,7 +339,7 @@ void World::HandleEvent(const sf::Event& event) {
GameApp::get_mutable_instance().Quit();
} else if(GameApp::get_mutable_instance().IsEditorMode()) {
// EDITOR
- std::vector<std::string> img_keys = GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImageKeys();
+ std::vector<std::string> img_keys = GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTextureKeys();
if (img_keys.size() == 0) {
std::cerr << "There are no images. The Editor cannot be used when there are no images loaded. Exiting." << std::endl;
exit(1);
@@ -382,7 +382,7 @@ void World::HandleEvent(const sf::Event& event) {
Entity* e = new Entity();
if (mEditorSelectedEntity != NULL) {
// copy properties
- e->Initialize(*this, mEditorSelectedEntity->GetImage(),mEditorLayer);
+ e->Initialize(*this, mEditorSelectedEntity->GetTexture(),mEditorLayer);
e->SetLocalLayer(mLocalLayerCount);
mLocalLayerCount++;
e->SetRotation(mEditorSelectedEntity->GetRotation());
@@ -403,11 +403,11 @@ void World::HandleEvent(const sf::Event& event) {
} else if(event.Key.Code == sf::Keyboard::E) {
//next image
if (mEditorSelectedEntity!=NULL)
- mEditorSelectedEntity->SetImage(GetImageKeyRelativeTo(mEditorSelectedEntity->GetImage(), +1));
+ mEditorSelectedEntity->SetTexture(GetTextureKeyRelativeTo(mEditorSelectedEntity->GetTexture(), +1));
} else if(event.Key.Code == sf::Keyboard::W) {
//prev entity
if (mEditorSelectedEntity!=NULL)
- mEditorSelectedEntity->SetImage(GetImageKeyRelativeTo(mEditorSelectedEntity->GetImage(), -1));
+ mEditorSelectedEntity->SetTexture(GetTextureKeyRelativeTo(mEditorSelectedEntity->GetTexture(), -1));
} else if(event.Key.Code == sf::Keyboard::F) {
// move up 1 layer
if(mEditorSelectedEntity!=NULL && mEditorSelectedEntity->GetLayer()<9) {
@@ -750,8 +750,8 @@ void World::ToggleSetMouseAction(EditorMouseAction action) {
}
-std::string World::GetImageKeyRelativeTo(const std::string& original, int offset) {
- const std::vector<std::string> img_keys = GameApp::get_mutable_instance().GetResourceManagerPtr()->GetImageKeys();
+std::string World::GetTextureKeyRelativeTo(const std::string& original, int offset) {
+ const std::vector<std::string> img_keys = GameApp::get_mutable_instance().GetResourceManagerPtr()->GetTextureKeys();
int i = 0;
int n = img_keys.size();
View
2 GGJ2011/src/World.hpp
@@ -63,7 +63,7 @@ class World {
void ToggleSetMouseAction(EditorMouseAction action);
- static std::string GetImageKeyRelativeTo(const std::string& original, int offset);
+ static std::string GetTextureKeyRelativeTo(const std::string& original, int offset);
int GetEditorLayer() const;
void SetEditorLayer(int layer);

0 comments on commit 1e16f42

Please sign in to comment.