summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-16 20:18:50 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-16 20:18:50 +0000
commit7489419558c12ba19eb7d0f26bf5a29149330eb0 (patch)
tree769035b8e79b95a2767aa04daa5cb567492e1254 /src
parent4453a80a2f43c5ebf20dce881586a89c484d4830 (diff)
downloadmana-7489419558c12ba19eb7d0f26bf5a29149330eb0.tar.gz
mana-7489419558c12ba19eb7d0f26bf5a29149330eb0.tar.bz2
mana-7489419558c12ba19eb7d0f26bf5a29149330eb0.tar.xz
mana-7489419558c12ba19eb7d0f26bf5a29149330eb0.zip
Use the ResourceManager to get spritesets.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp13
-rw-r--r--src/engine.cpp44
-rw-r--r--src/engine.h4
-rw-r--r--src/game.cpp3
-rw-r--r--src/gui/equipmentwindow.cpp9
-rw-r--r--src/gui/itemcontainer.cpp6
-rw-r--r--src/main.cpp30
7 files changed, 35 insertions, 74 deletions
diff --git a/src/being.cpp b/src/being.cpp
index fdfc5c8c..42b2c2f5 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -39,7 +39,6 @@
#include "net/protocol.h"
#include "resources/resourcemanager.h"
-#include "resources/image.h"
extern Being* autoTarget;
extern std::map<int, Spriteset*> monsterset;
@@ -108,14 +107,12 @@ Being* createBeing(Uint32 id, Uint16 job, Map *map)
filename << "graphics/sprites/monster" << (being->job - 1002) << ".png";
logger->log("%s",filename.str().c_str());
- Image *monsterbitmap =
- ResourceManager::getInstance()->getImage(filename.str());
-
- if (!monsterbitmap) {
- logger->error("Unable to load monster.png");
+ Spriteset *tmp = ResourceManager::getInstance()->createSpriteset(
+ filename.str(), 60, 60);
+ if (!tmp) {
+ logger->error("Unable to load monster spriteset!");
} else {
- monsterset[being->job - 1002] = new Spriteset(monsterbitmap, 60, 60);
- monsterbitmap->decRef();
+ monsterset[being->job - 1002] = tmp;
}
}
diff --git a/src/engine.cpp b/src/engine.cpp
index 706435d4..9f5106bd 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -40,17 +40,11 @@
#include "gui/gui.h"
#include "gui/minimap.h"
-#include "resources/image.h"
-#include "resources/iteminfo.h"
#include "resources/itemmanager.h"
#include "resources/mapreader.h"
#include "resources/resourcemanager.h"
-extern Being *autoTarget;
-extern Graphics *graphics;
extern Minimap *minimap;
-extern std::list<FloorItem*> floorItems;
-extern int frame;
char itemCurrenyQ[10] = "0";
int camera_x, camera_y;
@@ -68,32 +62,20 @@ Spriteset *weaponset;
Engine::Engine():
mCurrentMap(NULL)
{
- // Initializes GUI
-
// Load the sprite sets
ResourceManager *resman = ResourceManager::getInstance();
- Image *npcbmp = resman->getImage("graphics/sprites/npcs.png");
- Image *emotionbmp = resman->getImage("graphics/sprites/emotions.png");
- Image *weaponbitmap = resman->getImage("graphics/sprites/weapons.png");
- Image *itembitmap = resman->getImage("graphics/sprites/items.png");
-
- if (!npcbmp) logger->error("Unable to load npcs.png");
- if (!emotionbmp) logger->error("Unable to load emotions.png");
- if (!weaponbitmap) logger->error("Unable to load weapons.png");
- if (!itembitmap) logger->error("Unable to load items.png");
-
- npcset = new Spriteset(npcbmp, 50, 80);
- emotionset = new Spriteset(emotionbmp, 30, 32);
- weaponset = new Spriteset(weaponbitmap, 160, 120);
- itemset = new Spriteset(itembitmap, 32, 32);
- npcbmp->decRef();
- emotionbmp->decRef();
- weaponbitmap->decRef();
- itembitmap->decRef();
+ npcset = resman->createSpriteset("graphics/sprites/npcs.png", 50, 80);
+ emotionset = resman->createSpriteset("graphics/sprites/emotions.png",
+ 30, 32);
+ weaponset = resman->createSpriteset("graphics/sprites/weapons.png",
+ 160, 120);
+ itemset = resman->createSpriteset("graphics/sprites/items.png", 32, 32);
- attackTarget = resman->getImage("graphics/gui/attack_target.png");
- if (!attackTarget) logger->error("Unable to load attack_target.png");
+ if (!npcset) logger->error("Unable to load NPC spriteset!");
+ if (!emotionset) logger->error("Unable to load emotions spriteset!");
+ if (!weaponset) logger->error("Unable to load weapon spriteset!");
+ if (!itemset) logger->error("Unable to load item spriteset!");
// Initialize item manager
itemDb = new ItemManager();
@@ -114,8 +96,6 @@ Engine::~Engine()
delete weaponset;
delete itemset;
- attackTarget->decRef();
-
delete itemDb;
}
@@ -199,7 +179,7 @@ void Engine::logic()
}
}
-void Engine::draw()
+void Engine::draw(Graphics *graphics)
{
int midTileX = graphics->getWidth() / 32 / 2;
int midTileY = graphics->getHeight() / 32 / 2;
@@ -225,8 +205,6 @@ void Engine::draw()
camera_x = map_x / 32;
camera_y = map_y / 32;
- frame++;
-
// Draw tiles and sprites
if (mCurrentMap != NULL)
{
diff --git a/src/engine.h b/src/engine.h
index 74f2ce9d..25367436 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -28,9 +28,9 @@
extern int camera_x, camera_y;
+class Graphics;
class Image;
class Map;
-class Spriteset;
/**
* Game engine that does the main drawing.
@@ -66,7 +66,7 @@ class Engine
/**
* Draws everything on the screen.
*/
- void draw();
+ void draw(Graphics *graphics);
private:
Map *mCurrentMap;
diff --git a/src/game.cpp b/src/game.cpp
index de2bb600..35196e4a 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -388,7 +388,8 @@ void game()
// Update the screen when application is active, delay otherwise
if (SDL_GetAppState() & SDL_APPACTIVE)
{
- engine->draw();
+ frame++;
+ engine->draw(graphics);
graphics->updateScreen();
}
else
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index d1d23ee1..d3b5fc6b 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -30,7 +30,6 @@
#include "../graphic/spriteset.h"
-#include "../resources/image.h"
#include "../resources/iteminfo.h"
#include "../resources/resourcemanager.h"
@@ -43,11 +42,9 @@ EquipmentWindow::EquipmentWindow():
setDefaultSize(5, 230, 200, 90);
loadWindowState();
- ResourceManager *resman = ResourceManager::getInstance();
- Image *itemImg = resman->getImage("graphics/sprites/items.png");
- if (!itemImg) logger->error("Unable to load items.png");
- itemset = new Spriteset(itemImg, 32, 32);
- itemImg->decRef();
+ itemset = ResourceManager::getInstance()->createSpriteset(
+ "graphics/sprites/items.png", 32, 32);
+ if (!itemset) logger->error("Unable to load items.png");
}
EquipmentWindow::~EquipmentWindow()
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 3f00f9eb..0cdb8864 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -42,10 +42,8 @@ ItemContainer::ItemContainer(Inventory *inventory):
mInventory(inventory)
{
ResourceManager *resman = ResourceManager::getInstance();
- Image *itemImg = resman->getImage("graphics/sprites/items.png");
- if (!itemImg) logger->error("Unable to load items.png");
- itemset = new Spriteset(itemImg, 32, 32);
- itemImg->decRef();
+ itemset = resman->createSpriteset("graphics/sprites/items.png", 32, 32);
+ if (!itemset) logger->error("Unable to load items.png");
selImg = resman->getImage("graphics/gui/selection.png");
if (!selImg) logger->error("Unable to load selection.png");
diff --git a/src/main.cpp b/src/main.cpp
index 90a0aac3..d4766bfe 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -45,7 +45,6 @@
#ifdef USE_OPENGL
#include "openglgraphics.h"
#endif
-#include "playerinfo.h"
#include "sound.h"
#include "graphic/spriteset.h"
@@ -58,9 +57,6 @@
#include "gui/login.h"
#include "gui/ok_dialog.h"
#include "gui/updatewindow.h"
-#include "gui/error.h"
-
-#include "net/protocol.h"
#include "resources/image.h"
#include "resources/resourcemanager.h"
@@ -266,19 +262,13 @@ void init_engine()
// Initialize for drawing
graphics->_beginDraw();
- Image *playerImg = resman->getImage(
- "graphics/sprites/player_male_base.png");
- Image *hairImg = resman->getImage(
- "graphics/sprites/player_male_hair.png");
-
- if (!playerImg) logger->error("Couldn't load player_male_base.png");
- if (!hairImg) logger->error("Couldn't load player_male_hair.png");
+ playerset = resman->createSpriteset(
+ "graphics/sprites/player_male_base.png", 64, 64);
+ hairset = resman->createSpriteset(
+ "graphics/sprites/player_male_hair.png", 40, 40);
- playerset = new Spriteset(playerImg, 64, 64);
- hairset = new Spriteset(hairImg, 40, 40);
-
- playerImg->decRef();
- hairImg->decRef();
+ if (!playerset) logger->error("Couldn't load player spriteset!");
+ if (!hairset) logger->error("Couldn't load hair spriteset!");
gui = new Gui(graphics);
state = UPDATE_STATE; /**< Initial game state */
@@ -427,7 +417,7 @@ int main(int argc, char *argv[])
void (*inputHandler)(SDL_KeyboardEvent*) = NULL;
Image *login_wallpaper = NULL;
-
+
sound.playMusic(TMW_DATADIR "data/music/Magick - Real.ogg");
while (state != EXIT_STATE)
@@ -448,9 +438,9 @@ int main(int argc, char *argv[])
guiInput->pushInput(event);
}
-
+
gui->logic();
-
+
if (!login_wallpaper)
{
login_wallpaper = ResourceManager::getInstance()->
@@ -525,7 +515,7 @@ int main(int argc, char *argv[])
}
}
}
-
+
if (nullFile)
{
fclose(nullFile);