mys-venture-commits Mailing List for Mys-venture
Status: Inactive
Brought to you by:
kimmovii
You can subscribe to this list here.
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
(69) |
Aug
(5) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: <kim...@us...> - 2010-08-07 08:40:23
|
Revision: 88 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=88&view=rev Author: kimmovii Date: 2010-08-07 08:40:17 +0000 (Sat, 07 Aug 2010) Log Message: ----------- Oops. I had forgotten absolute paths in there. Changed to Qt resource paths. Modified Paths: -------------- trunk/mysventure/source/sub_level/levelfactory.cpp Modified: trunk/mysventure/source/sub_level/levelfactory.cpp =================================================================== --- trunk/mysventure/source/sub_level/levelfactory.cpp 2010-08-07 06:18:22 UTC (rev 87) +++ trunk/mysventure/source/sub_level/levelfactory.cpp 2010-08-07 08:40:17 UTC (rev 88) @@ -99,8 +99,8 @@ QString entityType("BaseGameEntity"); // Default image and passability to ground. - //QString entityImage(":/ground.png"); - QString entityImage("D:/kimmo/ohjelmointi/Ohjelmat/C++/QT/myssvn/trunk/mysventure/resource/tiles/ground.png"); + QString entityImage(":/ground.png"); + unsigned int isPassable = 1; // If the entity is a wall as per the above @@ -112,7 +112,7 @@ if (column == 0 || column == 1 || column == 38 || column == 39 || row == 0 || row == 29) { - entityImage = "D:/kimmo/ohjelmointi/Ohjelmat/C++/QT/myssvn/trunk/mysventure/resource/tiles/wall.png"; + entityImage = ":/wall.png"; isPassable = 0; } @@ -229,7 +229,7 @@ // If a wall was determined, change image and passability if (isWall) { - entityImage = "D:/kimmo/ohjelmointi/Ohjelmat/C++/QT/myssvn/trunk/mysventure/resource/tiles/wall.png"; + entityImage = ":/wall.png"; isPassable = 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-08-07 06:18:28
|
Revision: 87 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=87&view=rev Author: kimmovii Date: 2010-08-07 06:18:22 +0000 (Sat, 07 Aug 2010) Log Message: ----------- Map drawing now works. Modified Paths: -------------- trunk/mysventure/source/main.cpp trunk/mysventure/source/sub_entity/basegameentitymaker.cpp Modified: trunk/mysventure/source/main.cpp =================================================================== --- trunk/mysventure/source/main.cpp 2010-08-06 19:44:55 UTC (rev 86) +++ trunk/mysventure/source/main.cpp 2010-08-07 06:18:22 UTC (rev 87) @@ -29,7 +29,7 @@ GameApplication gameApp; gameApp.loadTestLevel(); gameApp.run(); - gameApp.drawMap(QPoint(0, 0)); + gameApp.drawMap(QPoint(64 * 3, 64 * 2)); return a.exec(); } Modified: trunk/mysventure/source/sub_entity/basegameentitymaker.cpp =================================================================== --- trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-08-06 19:44:55 UTC (rev 86) +++ trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-08-07 06:18:22 UTC (rev 87) @@ -32,8 +32,9 @@ using Sub_GameEntities::BaseGameEntity; using Sub_GameUtility::Position; +// Initialize static maker instance. +BaseGameEntityMaker BaseGameEntityMaker::m_maker; - /*! Registers the created maker instance with the maker registry. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-08-06 19:45:03
|
Revision: 86 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=86&view=rev Author: kimmovii Date: 2010-08-06 19:44:55 +0000 (Fri, 06 Aug 2010) Log Message: ----------- Implemented drawing the map on screen. It just doesn't work yet :) Needs some debugging. Modified Paths: -------------- trunk/design/game/technical_design.odt trunk/mysventure/include/sub_entity/basegameentity.h trunk/mysventure/include/sub_entity/basegameentitymaker.h trunk/mysventure/include/sub_level/gamemap.h trunk/mysventure/include/sub_level/sub_gamelevels.h trunk/mysventure/include/sub_view/mainwindow.h trunk/mysventure/include/sub_view/mapdrawer.h trunk/mysventure/include/sub_view/mapview.h trunk/mysventure/mys-venture.pro trunk/mysventure/source/main.cpp trunk/mysventure/source/sub_entity/basegameentity.cpp trunk/mysventure/source/sub_entity/basegameentitymaker.cpp trunk/mysventure/source/sub_level/gamemap.cpp trunk/mysventure/source/sub_view/mainwindow.cpp trunk/mysventure/source/sub_view/mapdrawer.cpp trunk/mysventure/source/sub_view/mapview.cpp Added Paths: ----------- trunk/mysventure/include/sub_level/gamelevel.h trunk/mysventure/include/sub_level/levelfactory.h trunk/mysventure/include/sub_main/gameapplication.h trunk/mysventure/include/sub_main/sub_main.h trunk/mysventure/resource/ trunk/mysventure/resource/tiles/ trunk/mysventure/resource/tiles/ground.png trunk/mysventure/resource/tiles/tiles.qrc trunk/mysventure/resource/tiles/wall.png trunk/mysventure/source/sub_level/gamelevel.cpp trunk/mysventure/source/sub_level/levelfactory.cpp trunk/mysventure/source/sub_main/gameapplication.cpp Modified: trunk/design/game/technical_design.odt =================================================================== (Binary files differ) Modified: trunk/mysventure/include/sub_entity/basegameentity.h =================================================================== --- trunk/mysventure/include/sub_entity/basegameentity.h 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/include/sub_entity/basegameentity.h 2010-08-06 19:44:55 UTC (rev 86) @@ -53,7 +53,8 @@ */ BaseGameEntity(const Sub_GameUtility::Identification& id, const Sub_GameUtility::Position& pos = Sub_GameUtility::Position(0, 0, 0), - const QPixmap& image = QPixmap()); + const QPixmap& image = QPixmap(), + bool isPassable = false); public slots: @@ -100,6 +101,11 @@ */ QPixmap getImage() const { return m_entityImage; } + /*! \brief + Returns true if the entity can be traversed. + */ + bool isPassable() const { return m_isPassable; } + private: /*! @@ -119,6 +125,11 @@ */ QPixmap m_entityImage; + /*! + True if the entity can be traversed. + */ + bool m_isPassable; + }; } // namespace Sub_GameEntities Modified: trunk/mysventure/include/sub_entity/basegameentitymaker.h =================================================================== --- trunk/mysventure/include/sub_entity/basegameentitymaker.h 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/include/sub_entity/basegameentitymaker.h 2010-08-06 19:44:55 UTC (rev 86) @@ -33,10 +33,12 @@ Part of the "entity factory pattern." Entity parameter keys used by the maker are: - - xposition: the x position of the entity on map. - - yposition: the y position of the entity on map. - - layer: the layer of the entity on map. - - image: the image of the entity. + - xposition: the x position of the entity on map. Unsigned int + - yposition: the y position of the entity on map. Unsigned int + - layer: the layer of the entity on map. Unsigned int + - image: the image of the entity. QString + - passable: can the entity be traversed? Unsigned int. A value + of 0 means false, other values mean true. */ class BaseGameEntityMaker : public AbstractEntityMaker { Added: trunk/mysventure/include/sub_level/gamelevel.h =================================================================== --- trunk/mysventure/include/sub_level/gamelevel.h (rev 0) +++ trunk/mysventure/include/sub_level/gamelevel.h 2010-08-06 19:44:55 UTC (rev 86) @@ -0,0 +1,74 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Declaration for class GameLevel. +*/ + +#ifndef GAMELEVEL_H +#define GAMELEVEL_H + +#include <QHash> +#include <QString> + +#include "sub_level/gamemap.h" + +namespace Sub_GameLevel +{ + + /*! \brief + GameLevel represents a level in the game. + */ + /*! + A level in the game is a collection of different maps. A level + has a specified starting point and a specified end point. + + At the moment, the GameLevel class is only a stump with + just the basic functionality to add a map etc. + */ + class GameLevel + { + /*! \todo + Finish GameLevel class. + */ + public: + + /*! \brief + Adds a map to the level. + */ + void addMap(const QString& mapName, const Sub_GameLevel::GameMap& map); + + /*! \brief + Retrieves the map with name mapName. + */ + Sub_GameLevel::GameMap getMap(const QString& mapName) const; + + private: + + /*! + The maps of the level. We store + the maps by value for simplicity. If this proves + too costly (which I doubt), we'll change it. + */ + QHash<QString, GameMap> m_level; + + }; + +} // namespace Sub_GameLevel + +#endif // GAMELEVEL_H Modified: trunk/mysventure/include/sub_level/gamemap.h =================================================================== --- trunk/mysventure/include/sub_level/gamemap.h 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/include/sub_level/gamemap.h 2010-08-06 19:44:55 UTC (rev 86) @@ -59,6 +59,16 @@ QVector<Sub_GameLevel::MapLayer>()); /*! \brief + Sets the map name. + */ + void setName(const QString& mapName) { m_mapName = mapName; } + + /*! \brief + Returns the map name. + */ + QString getName() const { return m_mapName; } + + /*! \brief Returns the map start message. */ QString getStartMessage() const; @@ -164,6 +174,11 @@ private: + /*! \brief + Holds the name of the map. This is used to identify the map. + */ + QString m_mapName; + /*! The message meant to be shown to the player when entering the map. Added: trunk/mysventure/include/sub_level/levelfactory.h =================================================================== --- trunk/mysventure/include/sub_level/levelfactory.h (rev 0) +++ trunk/mysventure/include/sub_level/levelfactory.h 2010-08-06 19:44:55 UTC (rev 86) @@ -0,0 +1,66 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Declaration for class LevelFactory. +*/ + +#ifndef LEVELFACTORY_H +#define LEVELFACTORY_H + +#include <QSharedPointer> + +#include "sub_level/gamelevel.h" +#include "sub_entity/entitymanager.h" + + +namespace Sub_GameLevel +{ + + /*! \brief + LevelFactory creates the game levels. + */ + /*! + LevelFactory reads the game level data from a text + source such as a QString or a QTextStream and constructs + a complete map from this data. + + LevelFactory returns smart pointers to dynamically + allocated objects. LevelFactory is not responsible + for the destruction of the created objects. + + The class is only a stump at the moment to allow us to create + one simple test map. + */ + class LevelFactory + { + public: + + /*! \brief + Creates a simple test level. + */ + QSharedPointer<Sub_GameLevel::GameLevel> + createTestLevel1(Sub_GameEntities::EntityManager& manager); + + private: + + }; // class LevelFactory + +} // namespace Sub_GameLevel + +#endif // LEVELFACTORY_H Modified: trunk/mysventure/include/sub_level/sub_gamelevels.h =================================================================== --- trunk/mysventure/include/sub_level/sub_gamelevels.h 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/include/sub_level/sub_gamelevels.h 2010-08-06 19:44:55 UTC (rev 86) @@ -26,6 +26,8 @@ #include "sub_level/mapcolumn.h" #include "sub_level/maplayer.h" #include "sub_level/gamemap.h" +#include "sub_level/gamelevel.h" +#include "sub_level/levelfactory.h" /*! \brief Contains all identifiers in the levels subsystem. Added: trunk/mysventure/include/sub_main/gameapplication.h =================================================================== --- trunk/mysventure/include/sub_main/gameapplication.h (rev 0) +++ trunk/mysventure/include/sub_main/gameapplication.h 2010-08-06 19:44:55 UTC (rev 86) @@ -0,0 +1,113 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Declaration for class GameApplication. +*/ + +#ifndef GAMEAPPLICATION_H +#define GAMEAPPLICATION_H + +#include <QObject> +#include <QSharedPointer> + +#include "sub_level/levelfactory.h" +#include "sub_entity/entitymanager.h" + +#include "sub_view/sub_gameview.h" + +namespace Sub_Main +{ + + class GameApplication : public QObject + { + Q_OBJECT + + public: + + /*! \brief + Default constructor. + */ + GameApplication(QObject* parent = 0); + + /*! \brief + Starts the game. In effect, shows the GUI. + */ + void run(); + + public slots: + + /*! \brief + A temporary slot to load the test level. + */ + void loadTestLevel(); + + + + /*! \brief + Test function. Draws test map. + */ + void drawMap(const QPoint& origin); + + private: + + /*! + The current, active level. + */ + QSharedPointer<Sub_GameLevel::GameLevel> m_currentLevel; + + /*! + Game GUI. + */ + Sub_GameView::MainWindow* m_gui; + + /*! + Used internally to draw the map. + */ + Sub_GameView::MapDrawer m_mapDrawer; + + /*! + Entity manager used by the game. + */ + Sub_GameEntities::EntityManager m_entityManager; + + /*! + Level factory used. + */ + Sub_GameLevel::LevelFactory m_levelFactory; + + + + /*! \brief + Initializes the game. Called from the constructor. + */ + bool init(); + + /*! \brief + Creates an image map from a map. This is for testing + only and operator on the test map. + */ + QMap<unsigned int, QList<QPair<QPoint, QPixmap> > > + entityMapToImageMap() const; + + + }; // class GameApplication + +} // namespace Sub_Main + +#endif // GAMEAPPLICATION_H Added: trunk/mysventure/include/sub_main/sub_main.h =================================================================== --- trunk/mysventure/include/sub_main/sub_main.h (rev 0) +++ trunk/mysventure/include/sub_main/sub_main.h 2010-08-06 19:44:55 UTC (rev 86) @@ -0,0 +1,36 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Subsystem-wide include for the Main subsystem. +*/ + +#ifndef SUB_MAIN_H +#define SUB_MAIN_H + +#include "sub_main/gameapplication.h" + +/*! +Contains all the classes of the Main subsystem. +*/ +namespace Sub_Main +{ + +} + +#endif // SUB_MAIN_H Modified: trunk/mysventure/include/sub_view/mainwindow.h =================================================================== --- trunk/mysventure/include/sub_view/mainwindow.h 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/include/sub_view/mainwindow.h 2010-08-06 19:44:55 UTC (rev 86) @@ -21,7 +21,10 @@ #include "ui_mainwindow.h" -class MainWindow : public QMainWindow, private Ui::MainWindow { +namespace Sub_GameView +{ + +class MainWindow : public QMainWindow, public Ui::MainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); @@ -30,4 +33,6 @@ void changeEvent(QEvent *e); }; +} + #endif // MAINWINDOW_H Modified: trunk/mysventure/include/sub_view/mapdrawer.h =================================================================== --- trunk/mysventure/include/sub_view/mapdrawer.h 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/include/sub_view/mapdrawer.h 2010-08-06 19:44:55 UTC (rev 86) @@ -97,7 +97,7 @@ This signal is emitted when drawMap() has finished drawing the map. */ - void mapDrawn(const QPixmap& mapImage); + void mapDrawn(QPixmap* mapImage); private: Modified: trunk/mysventure/include/sub_view/mapview.h =================================================================== --- trunk/mysventure/include/sub_view/mapview.h 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/include/sub_view/mapview.h 2010-08-06 19:44:55 UTC (rev 86) @@ -28,7 +28,7 @@ #include "ui_mapview.h" class QPaintEvent; -class QImage; +class QPixmap; namespace Sub_GameView @@ -62,7 +62,7 @@ /*! \brief Sets the map image to be painted. */ - void setMapImage(QImage* image); + void setMapImage(QPixmap* image); private: @@ -70,7 +70,7 @@ Holds the map to be painted on screen. If value is 0, no drawing is done. */ - QImage* m_mapImage; + QPixmap* m_mapImage; }; // class MapView Modified: trunk/mysventure/mys-venture.pro =================================================================== --- trunk/mysventure/mys-venture.pro 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/mys-venture.pro 2010-08-06 19:44:55 UTC (rev 86) @@ -26,7 +26,10 @@ source/sub_entity/entitymanager.cpp \ source/sub_level/mapcolumn.cpp \ source/sub_level/maplayer.cpp \ - source/sub_level/gamemap.cpp + source/sub_level/gamemap.cpp \ + source/sub_level/gamelevel.cpp \ + source/sub_level/levelfactory.cpp \ + source/sub_main/gameapplication.cpp HEADERS += include/sub_view/mainwindow.h \ include/util/Position.h \ include/util/identification.h \ @@ -55,7 +58,11 @@ include/sub_entity/entitymanager.h \ include/sub_level/mapcolumn.h \ include/sub_level/maplayer.h \ - include/sub_level/gamemap.h + include/sub_level/gamemap.h \ + include/sub_level/levelfactory.h \ + include/sub_level/gamelevel.h \ + include/sub_main/gameapplication.h \ + include/sub_main/sub_main.h FORMS += source/sub_view/mainwindow.ui \ source/sub_view/mapview.ui LIBS += -Llib \ @@ -67,4 +74,5 @@ include/sub_settings INCLUDEPATH += /lib/source/lua DESTDIR = bin -RESOURCES += +RESOURCES += \ + resource/tiles/tiles.qrc Added: trunk/mysventure/resource/tiles/ground.png =================================================================== (Binary files differ) Property changes on: trunk/mysventure/resource/tiles/ground.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/mysventure/resource/tiles/tiles.qrc =================================================================== --- trunk/mysventure/resource/tiles/tiles.qrc (rev 0) +++ trunk/mysventure/resource/tiles/tiles.qrc 2010-08-06 19:44:55 UTC (rev 86) @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file alias="wall.png">wall.png</file> + <file alias="ground.png">ground.png</file> + </qresource> +</RCC> Added: trunk/mysventure/resource/tiles/wall.png =================================================================== (Binary files differ) Property changes on: trunk/mysventure/resource/tiles/wall.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/mysventure/source/main.cpp =================================================================== --- trunk/mysventure/source/main.cpp 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/source/main.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -17,16 +17,19 @@ */ #include <QtGui/QApplication> -#include "include/sub_view/mainwindow.h" +#include "sub_main/gameapplication.h" +using namespace Sub_Main; int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow mainWindow; - mainWindow.show(); + GameApplication gameApp; + gameApp.loadTestLevel(); + gameApp.run(); + gameApp.drawMap(QPoint(0, 0)); return a.exec(); } Modified: trunk/mysventure/source/sub_entity/basegameentity.cpp =================================================================== --- trunk/mysventure/source/sub_entity/basegameentity.cpp 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/source/sub_entity/basegameentity.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -32,8 +32,10 @@ Sub_GameEntities:: BaseGameEntity::BaseGameEntity(const Sub_GameUtility::Identification &id, const Sub_GameUtility::Position &pos, - const QPixmap &image) -: QObject(), m_entityId(id), m_entityPosition(pos), m_entityImage(image) + const QPixmap &image, + bool isPassable) +: QObject(), m_entityId(id), m_entityPosition(pos), m_entityImage(image), + m_isPassable(isPassable) { } Modified: trunk/mysventure/source/sub_entity/basegameentitymaker.cpp =================================================================== --- trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -69,11 +69,15 @@ // Retrieve image path. QString imagePath = entityParams.value("image"); + // Retrieve passability + QString passability = entityParams.value("passable"); + // If some of these parameters is missing, return 0. if (xPosString.isEmpty() || yPosString.isEmpty() || layerString.isEmpty() - || imagePath.isEmpty()) + || imagePath.isEmpty() + || passability.isEmpty()) return 0; unsigned int xPos = @@ -82,6 +86,8 @@ yPosString.toUInt(&success, 10); unsigned int layer = layerString.toUInt(&success, 10); + unsigned int isPassable = + passability.toUInt(&success, 10); // If there was error during conversions, return 0. if (!success) @@ -92,7 +98,8 @@ BaseGameEntity* entity = new BaseGameEntity(entityId, entityPos, - imagePath); + imagePath, + isPassable); return entity; } Added: trunk/mysventure/source/sub_level/gamelevel.cpp =================================================================== --- trunk/mysventure/source/sub_level/gamelevel.cpp (rev 0) +++ trunk/mysventure/source/sub_level/gamelevel.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -0,0 +1,46 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Implementation for class GameLevel. +*/ + +#include "sub_level/gamelevel.h" + +using namespace Sub_GameLevel; + + + +void +Sub_GameLevel +::GameLevel::addMap(const QString &mapName, const Sub_GameLevel::GameMap &map) +{ + if (m_level.contains(mapName)) + return; + + m_level.insert(mapName, map); +} + + + +GameMap +Sub_GameLevel +::GameLevel::getMap(const QString &mapName) const +{ + return m_level.value(mapName); +} Modified: trunk/mysventure/source/sub_level/gamemap.cpp =================================================================== --- trunk/mysventure/source/sub_level/gamemap.cpp 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/source/sub_level/gamemap.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -330,10 +330,14 @@ Sub_GameLevel ::GameMap::getHighestLayer() const { + // If map has no layers. if (m_layers.isEmpty()) return 0; + // Get the layer numbers. QList<unsigned int> layers = m_layers.keys(); + + // Find and return the maximum of the layer numbers. unsigned int maxLayer = *(std::max_element(layers.begin(), layers.end())); return maxLayer; } Added: trunk/mysventure/source/sub_level/levelfactory.cpp =================================================================== --- trunk/mysventure/source/sub_level/levelfactory.cpp (rev 0) +++ trunk/mysventure/source/sub_level/levelfactory.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -0,0 +1,273 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \brief +Implementation for class LevelFactory. +*/ + +#include <QVector> + +#include "sub_level/levelfactory.h" +#include "sub_level/gamelevel.h" +#include "sub_level/sub_gamelevels.h" + +#include "sub_entity/basegameentity.h" +#include "sub_entity/entitymanager.h" + +using namespace Sub_GameLevel; +using namespace Sub_GameEntities; +using namespace Sub_GameUtility; + + +/*! +This method creates a map of size 40 columns, +30 rows. The map is composed of passable and +non-passable tiles. + +The generated map contains only one layer and +looks like this (# is non-passable, . is passable): + + +######################################## +########....##........................## +######....####..####............####..## +####......##....####............##....## +####......##....##..............##....## +##....#########.########........##..#### +##....#####.....#########..........##### +####...######..#################.....### +#####...######.##################.....## +######..#####...#####....###...####...## +###.###.######....######............#### +###.#.#.####....################..###### +###...#.#######.###############..####### +###.###.######....###########...######## +###...#.#####...####....####........#### +##..###.#####..######..#########...##### +###.##..###...######..................## +###.##.######.#######################.## +###.#.................................## +##...................................### +##................................###### +##...............................####### +##..........................############ +##.........................############# +##.....................################# +##..................#################### +##..#################################### +##........................####........## +##........##############.............### +######################################## +*/ +QSharedPointer<GameLevel> +Sub_GameLevel +::LevelFactory::createTestLevel1(EntityManager& manager) +{ + // This level contains only BaseGameEntity types. + // The keys used for the BaseGameEntity parameters + // are: xposition, yposition, layer, image. + // Layer will be 1 for all entities, image will + // be tiles/wall for the wall tiles and + // tiles/ground for the ground tiles. + // x and y positions will be hard-coded as if-statements. + + QSharedPointer<GameLevel> newLevel(new GameLevel); + QVector<MapColumn> layerData; + + for (int column = 0; column < 40; ++column) + { + QVector<Identification> columnData; + for (int row = 0; row < 30; ++row) + { + // Create new entity + Position entityPosition(column, row, 1); + QString entityType("BaseGameEntity"); + + // Default image and passability to ground. + //QString entityImage(":/ground.png"); + QString entityImage("D:/kimmo/ohjelmointi/Ohjelmat/C++/QT/myssvn/trunk/mysventure/resource/tiles/ground.png"); + unsigned int isPassable = 1; + + // If the entity is a wall as per the above + // map representation, set image to wall + // and passability to false. + + // If column is 0, 1, 38 or 39, entity is wall. + // If row is 0 or 29, entity is wall. + if (column == 0 || column == 1 || column == 38 || column == 39 || + row == 0 || row == 29) + { + entityImage = "D:/kimmo/ohjelmointi/Ohjelmat/C++/QT/myssvn/trunk/mysventure/resource/tiles/wall.png"; + isPassable = 0; + } + + // To save typing. + bool isWall = false; + + // Determine other cases column-by-column. + switch (column) + { + case 2: + if (row == 0 || row == 1 || row == 2 || row == 3 || row == 4 + || row == 7 || row == 8 || row == 9 || row == 10 + || row == 11 || row == 12 || row == 13 || row == 14 + || row == 16 || row == 17 || row == 18 || row == 29) + isWall = true; + break; + case 3: + if (row == 0 || row == 1|| row == 2 || row == 3 || row == 4 + || row == 7 || row == 8 || row == 9 + || row == 29) + isWall = true; + break; + case 4: + if (row == 0 || row == 1 || row == 2 + || row == 8 || row == 9 || row == 10 || row == 11 + || row == 13 + || row == 15 || row == 16 || row == 17 || row == 18 + || row == 26 || row == 29) + isWall = true; + break; + case 5: + if (row == 0 || row == 1 || row == 2 + || row == 9 || row == 10 + || row == 13 || row == 15 || row == 16 || row == 17 + || row == 26 || row == 29) + isWall = true; + break; + case 6: + if (row == 0 || row == 1 || row == 5 || row == 6 + || row == 10 || row == 11 || row == 12 || row == 13 + || row == 14 || row == 15 + || row == 26 || row == 29) + isWall = true; + break; + case 7: + if (row == 0 || row == 1 || row == 5 || row == 6 || row == 7 + || row == 17 || row == 26 || row == 29) + isWall = true; + break; + case 8: + if (row == 0 || row == 5 || row == 6 || row == 7 || row == 8 + || row == 9 || row == 10 || row == 11 || row == 12 || row == 13 + || row == 14 || row == 15 || row == 16 || row == 17 + || row ==26 || row == 29) + isWall = true; + break; + case 9: + if (row == 0 || row == 5 || row == 6 || row == 7 || row == 8 + || row == 9 || row == 10 || row == 11 || row == 12 || row == 13 + || row == 14 || row == 15 || row == 16 || row == 17 + || row == 26 || row == 29) + isWall = true; + break; + case 10: + if (row == 0 || row == 2 || row == 3 || row == 4 || row == 5 + || row == 6 || row == 7 || row == 8 || row == 9 || row == 10 + || row == 11 || row == 12 || row == 13 || row == 14 + || row == 15 || row == 16 || row == 17 + || row == 16 || row == 28 || row == 29) + isWall = true; + break; + case 11: + if (row == 0 || row == 2 || row == 3 || row == 4 || row == 5 + || row == 7 || row == 8 || row == 9 || row == 10 + || row == 11 || row == 12 || row == 13 || row == 14 || row == 15 + || row == 17 + || row == 26 || row == 28 || row == 29) + isWall = true; + break; + case 12: + if (row == 0 || row == 1 || row == 2 || row == 5 + || row == 7 || row == 8 || row == 9 || row == 10 + || row == 12 || row == 13 || row == 14 || row == 15 + || row == 17 || row == 26 || row == 28 || row == 29) + isWall = true; + break; + case 13: + if (row == 0 || row == 1 || row == 2 || row == 5 || row == 8 + || row == 10 || row == 12 || row == 13 || row == 26 || row == 28 || row == 29) + isWall = true; + break; + case 14: + if (row == 0 || row == 5 || row == 13 || row == 16 || row == 17 + || row == 26 || row == 28 || row == 29) + isWall = true; + break; + case 15: + if (row == 0 || row == 7 || row == 8 || row == 15 || row == 16 + || row == 17 || row == 26 || row == 28 || row == 29) + isWall = true; + break; + case 16: + if (row == 0 || row == 2 || row == 3 || row == 4 || row == 5 + || row == 6 || row == 7 || row == 8 || row == 9 + || row == 11 || row == 12 || row == 14 || row == 15 + || row == 16 || row == 17 || row == 26 || row == 28 || row == 29) + isWall = true; + break; + /*! \todo + Finish the switch to include the whole test map. + */ + } + + // If a wall was determined, change image and passability + if (isWall) + { + entityImage = "D:/kimmo/ohjelmointi/Ohjelmat/C++/QT/myssvn/trunk/mysventure/resource/tiles/wall.png"; + isPassable = 0; + } + + // Now we have the required parameters. Insert them into hash. + QHash<QString, QString> entityParams; + entityParams.insert("xposition", QString::number(entityPosition.getXPosition())); + entityParams.insert("yposition", QString::number(entityPosition.getYPosition())); + entityParams.insert("layer", QString::number(entityPosition.getLayer())); + entityParams.insert("image", entityImage); + entityParams.insert("passable", QString::number(isPassable)); + + // Create the entity + Identification newEntity = + manager.create(entityParams, "BaseGameEntity"); + + // If creation succeeded. + if (newEntity != Identification::invalidId()) + // Add to column + columnData.append(newEntity); + } + // Now we have a complete column. + // Add the column to layer data. + layerData.append(MapColumn(30, columnData)); + } + + // Now we have a complete layer. + // Create a layer from data. + MapLayer layer(40, 30, 1, layerData); + + // Create map data. + QVector<MapLayer> mapData; + mapData.append(layer); + + // Create a map from map data. + GameMap map(30, 40, mapData); + + // Add map to level. + newLevel->addMap("test", map); + + return newLevel; +} Added: trunk/mysventure/source/sub_main/gameapplication.cpp =================================================================== --- trunk/mysventure/source/sub_main/gameapplication.cpp (rev 0) +++ trunk/mysventure/source/sub_main/gameapplication.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -0,0 +1,162 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Implementation for class GameApplication. +*/ + +#include "sub_main/gameapplication.h" +#include "util/position.h" + +using namespace Sub_Main; +using namespace Sub_GameLevel; +using namespace Sub_GameView; +using namespace Sub_GameEntities; +using namespace Sub_GameUtility; + + +/*! +Default constructor initializes the game. +*/ +Sub_Main +::GameApplication::GameApplication(QObject *parent) +: QObject(parent) +{ + // Initialize game. + if (!init()) + exit(1); +} + + + +/*! +Init() is used to initialize the game. It is called +from the constructor. +*/ +bool +Sub_Main +::GameApplication::init() +{ + // Create the GUI, no parent. + m_gui = new MainWindow; + + // Init the map drawer. The map image is the same size + // as the map view. + m_mapDrawer.setDimensions(m_gui->mapView->width(), + m_gui->mapView->height()); + + // Connect map draw completed signal from MapDrawer to + // MapView's set map signal. + connect(&m_mapDrawer, SIGNAL(mapDrawn(QPixmap*)), + m_gui->mapView, SLOT(setMapImage(QPixmap*))); + + // That's all for now. + return true; +} + + + +void +Sub_Main +::GameApplication::run() +{ + m_gui->show(); +} + + +/*! +Creates the test level with MapFactory::createTestLevel1. +*/ +void +Sub_Main +::GameApplication::loadTestLevel() +{ + m_currentLevel = m_levelFactory.createTestLevel1(m_entityManager); + +} + + + +void +Sub_Main +::GameApplication::drawMap(const QPoint& origin) +{ + QMap<unsigned int, QList<QPair<QPoint, QPixmap> > > temp = + entityMapToImageMap(); + m_mapDrawer.drawMap(temp, origin); +} + + + + + + +QMap<unsigned int, QList<QPair<QPoint, QPixmap> > > +Sub_Main +::GameApplication::entityMapToImageMap() const +{ + // Get the test map. + GameMap testMap = m_currentLevel->getMap("test"); + + // Get highest layer. + unsigned int highestLayer = testMap.getHighestLayer(); + + QMap<unsigned int, QList<QPair<QPoint, QPixmap> > > imageMap; + + + + // Loop layers. + for (int i = 1; i <= highestLayer; ++i) + { + // If such a layer does not exist, continue + if (!testMap.hasLayer(i)) + continue; + + QList<QPair<QPoint, QPixmap> > imageMapLayer; + // Loop columns + for (int column = 0; column < testMap.getNumberOfColumns(); ++column) + { + // Loop rows + for (int row = 0; row < testMap.getNumberOfRows(); ++row) + { + // Get ID of entity. + Identification entityId = testMap.getEntity(Position(column, row, i)); + + // Get pointer to current entity. + BaseGameEntity* entity = + this->m_entityManager.getEntity(entityId); + + // just to be sure, get position of the entity + Position entityPos = entity->getPosition(); + + // Make entity pixel position. Assume tile side is 64 pixels. + QPoint entityPoint(entityPos.getXPosition() * 64, entityPos.getYPosition() * 64); + + // Get image of entity. + QPixmap entityImage = entity->getImage(); + + // Insert into layer list. + imageMapLayer.append(qMakePair(entityPoint, entityImage)); + } + } + // After processing layer, add to imageMap. + imageMap.insert(i, imageMapLayer); + } + // Return map. + return imageMap; +} Modified: trunk/mysventure/source/sub_view/mainwindow.cpp =================================================================== --- trunk/mysventure/source/sub_view/mainwindow.cpp 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/source/sub_view/mainwindow.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -18,12 +18,15 @@ #include "sub_view/mainwindow.h" -MainWindow::MainWindow(QWidget *parent) : +Sub_GameView +::MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ setupUi(this); } -void MainWindow::changeEvent(QEvent *e) +void +Sub_GameView +::MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) { Modified: trunk/mysventure/source/sub_view/mapdrawer.cpp =================================================================== --- trunk/mysventure/source/sub_view/mapdrawer.cpp 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/source/sub_view/mapdrawer.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -144,7 +144,7 @@ } // After drawing is done, send message. - emit this->mapDrawn(*m_mapImage); + emit this->mapDrawn(m_mapImage); } Modified: trunk/mysventure/source/sub_view/mapview.cpp =================================================================== --- trunk/mysventure/source/sub_view/mapview.cpp 2010-08-04 16:42:50 UTC (rev 85) +++ trunk/mysventure/source/sub_view/mapview.cpp 2010-08-06 19:44:55 UTC (rev 86) @@ -54,7 +54,7 @@ painter.setRenderHint(QPainter::Antialiasing); // Paint the map image. - painter.drawImage(QPoint(0, 0), *m_mapImage); + painter.drawPixmap(QPoint(0, 0), *m_mapImage); } @@ -66,7 +66,7 @@ */ void Sub_GameView:: -MapView::setMapImage(QImage *image) +MapView::setMapImage(QPixmap *image) { m_mapImage = image; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-08-04 16:42:56
|
Revision: 85 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=85&view=rev Author: kimmovii Date: 2010-08-04 16:42:50 +0000 (Wed, 04 Aug 2010) Log Message: ----------- Implemented MapDrawer. Untested, but not sure how to test it other than in practise. Modified Paths: -------------- trunk/design/game/technical_design.odt trunk/mysventure/include/sub_level/gamemap.h trunk/mysventure/include/sub_view/mapdrawer.h trunk/mysventure/source/sub_level/gamemap.cpp trunk/mysventure/source/sub_view/mapdrawer.cpp Modified: trunk/design/game/technical_design.odt =================================================================== (Binary files differ) Modified: trunk/mysventure/include/sub_level/gamemap.h =================================================================== --- trunk/mysventure/include/sub_level/gamemap.h 2010-08-02 10:22:23 UTC (rev 84) +++ trunk/mysventure/include/sub_level/gamemap.h 2010-08-04 16:42:50 UTC (rev 85) @@ -157,6 +157,11 @@ */ bool isInMap(unsigned int row, unsigned int column) const; + /*! \brief + Return the number of the highest layer. + */ + unsigned int getHighestLayer() const; + private: /*! Modified: trunk/mysventure/include/sub_view/mapdrawer.h =================================================================== --- trunk/mysventure/include/sub_view/mapdrawer.h 2010-08-02 10:22:23 UTC (rev 84) +++ trunk/mysventure/include/sub_view/mapdrawer.h 2010-08-04 16:42:50 UTC (rev 85) @@ -23,12 +23,16 @@ #ifndef MAPDRAWER_H #define MAPDRAWER_H -#include <QImage> +#include <QPixmap> +#include <QMap> +#include <QList> +#include <Qpair> +#include "sub_level/gamemap.h" -class GameMap; + namespace Sub_GameView { @@ -36,8 +40,14 @@ MapDrawer draws the game map. */ /*! - MapDrawer draws the game map on a QImage. MapDrawer is - inherited from QObject to allow Qt signal-slot communication. + MapDrawer draws the game map on a QPixmap. + + The dimensions of the map + can be provided in the constructor or changed with the slot + setDimensions(). It is important that correct dimensions are + set; if the dimensions are greater than the area drawn, then part + of the resulting map are blank. On the other hand, if the dimensions + are smaller, then part of the map will not be shown. */ class MapDrawer : public QObject { @@ -48,28 +58,54 @@ /*! \brief Default constructor. */ - MapDrawer(QObject* parent = 0); + MapDrawer(QObject* parent = 0, int mapWidth = 0, int mapHeight = 0); ~MapDrawer() { delete m_mapImage; } /*! \brief Returns a pointer to the map representation managed by the object. */ - QImage* getMap() const; + QPixmap* getMap() const; + /*! \brief + Returns the map image width in pixels. + */ + unsigned int getWidth() const; + + /*! \brief + Returns the map image height in pixels. + */ + unsigned int getHeight() const; + public slots: /*! \brief Draws the map map on the internal image. */ - void drawMap(const GameMap& map, int startX, int startY, - int endX, int endY); + void drawMap(QMap<unsigned int, + QList<QPair<QPoint, QPixmap> > >& map, + const QPoint& desiredOrigin = QPoint(0, 0)); + /*! \brief + Changes the image dimensions to (width, height). + */ + void setDimensions(int width, int height); + + signals: + + /*! \brief + This signal is emitted when drawMap() has finished + drawing the map. + */ + void mapDrawn(const QPixmap& mapImage); + private: /*! + The MapDrawer's image instance on which + the drawing operations are done. */ - QImage* m_mapImage; + QPixmap* m_mapImage; }; // class MapDrawer Modified: trunk/mysventure/source/sub_level/gamemap.cpp =================================================================== --- trunk/mysventure/source/sub_level/gamemap.cpp 2010-08-02 10:22:23 UTC (rev 84) +++ trunk/mysventure/source/sub_level/gamemap.cpp 2010-08-04 16:42:50 UTC (rev 85) @@ -20,6 +20,8 @@ Implementation for class GameMap. */ +#include <algorithm> + #include "sub_level/gamemap.h" using namespace Sub_GameLevel; @@ -40,8 +42,7 @@ // Copy the layers from mapData to m_layers. for (int i = 0; i < mapData.size(); ++i) { - m_layers.insert(mapData.at(i).getLayerNumber(), - mapData.at(i)); + addLayer(mapData.at(i)); } resize(m_columnSize, m_rowSize); @@ -116,8 +117,6 @@ Sub_GameLevel ::GameMap::addLayer(const MapLayer &layer) { - invariant(); - unsigned int layerNumber = layer.getLayerNumber(); // If a layer already exists, return @@ -325,6 +324,23 @@ /*! +If the map contains no layers, 0 is returned. +*/ +unsigned int +Sub_GameLevel +::GameMap::getHighestLayer() const +{ + if (m_layers.isEmpty()) + return 0; + + QList<unsigned int> layers = m_layers.keys(); + unsigned int maxLayer = *(std::max_element(layers.begin(), layers.end())); + return maxLayer; +} + + + +/*! The invariant is each layer's row and column size must be equal to the map's row and column size. */ Modified: trunk/mysventure/source/sub_view/mapdrawer.cpp =================================================================== --- trunk/mysventure/source/sub_view/mapdrawer.cpp 2010-08-02 10:22:23 UTC (rev 84) +++ trunk/mysventure/source/sub_view/mapdrawer.cpp 2010-08-04 16:42:50 UTC (rev 85) @@ -21,24 +21,25 @@ */ #include <QList> +#include <QPainter> - #include "sub_view/mapdrawer.h" +using namespace Sub_GameView; +using namespace Sub_GameUtility; - /*! Basic Qt-based constructor that takes a pointer to the parent object as an argument. + +The constructor also takes the width and the height of the game map. +NOTE: The width and height must be provided in pixels. */ Sub_GameView:: -MapDrawer::MapDrawer(QObject *parent) +MapDrawer::MapDrawer(QObject *parent, int mapWidth, int mapHeight) : QObject(parent), m_mapImage(0) { - // Create an 32-bit image with alpha channel... Not sure - // if the image resizes automatically when drawn onto or - // does this have to be taken care of too. - this->m_mapImage = new QImage(1, 1, QImage::Format_ARGB32); + this->m_mapImage = new QPixmap(mapWidth, mapHeight); } @@ -46,7 +47,7 @@ /*! The return value is always an address of a valid map. */ -QImage* +QPixmap* Sub_GameView:: MapDrawer::getMap() const { @@ -55,26 +56,114 @@ +unsigned int +Sub_GameView +::MapDrawer::getWidth() const +{ + return m_mapImage->width(); +} + +unsigned int +Sub_GameView +::MapDrawer::getHeight() const +{ + return m_mapImage->height(); +} + + + /*! -The drawing starts from the map position (startX, startY) -and ends at the map position (endX, endY). The drawing proceeds up to, -but not including (endX, endY). +The arguments to the function are interpreted as follows: +- The first argument is the list of images to draw. The drawing +starts from the list with the lowest key in the provided QMap. +All the images from the list are drawn in their corresponding +positions. When the list is exhausted, the drawing proceeds to +the next item in the QMap and so on. +- The origin argument specifies what point is to be considered +the top left corner of the map. Normally this point is (0, 0), +but the caller can change this behaviour by specifying a different +point. If the caller specifies for example origin (32, 64), then +an image at position (32, 64) would be drawn to the top left corner. +Any image with either a smaller x or a smaller y coordinate would not +be drawn at all. -Preconditions: -(startX, startY) must be a valid tile position in the map. -(endX, endY) must be a valid tile position in the map. -endX >= startX -endY >= endY -map must be a valid GameMap. +NOTE: It is the caller's responsibility to ensure the internal map image +is large enough to hold the desired images. */ void -Sub_GameView:: -MapDrawer::drawMap(const GameMap &map, int startX, int startY, - int endX, int endY) +Sub_GameView +::MapDrawer::drawMap(QMap< + unsigned int, QList< + QPair<QPoint, QPixmap> > > &map, + const QPoint &desiredOrigin) { - /*! \todo - Finish drawMap and the whole class after GameMap is done. - */ - Q_ASSERT(endX >= startX); - Q_ASSERT(endY >= startY); + QPainter painter(this->m_mapImage); + + // Remove pen; don't draw lines around images. + painter.setPen(Qt::NoPen); + + // First handle the translation. + // This must be done every time, as the origin + // is probably different almost every time + // (Unless the caller takes care of this). + + // When translating, the offsets from origin + // are added to the coordinate system. + // This means that to translate so that origin + // is in the top left corner, we must mirror + // the x and y coordinates in origin. + QPoint newOrigin; + newOrigin.rx() = -1 * desiredOrigin.x(); + newOrigin.ry() = -1 * desiredOrigin.y(); + + Q_ASSERT(desiredOrigin.x() + newOrigin.x() == 0); + Q_ASSERT(desiredOrigin.y() + newOrigin.y() == 0); + + // After mirroring the coordinates, perform translation + painter.translate(newOrigin); + + // Loop through the layers of the map. + QMap<unsigned int, QList<QPair<QPoint, QPixmap> > >::const_iterator it; + for (it = map.constBegin(); it != map.constEnd(); ++it) + { + // Get the current layer's image list. + const QList<QPair<QPoint, QPixmap> >& imageList = (*it); + + // For each layer, iterate over the list and draw each pixmap. + for (int i = 0; i < (*it).size(); ++i) + { + // Get position + const QPoint& position = imageList[i].first; + + // Get image + const QPixmap& image = imageList[i].second; + + // Draw image at position + painter.drawPixmap(position, image); + } + } + + // After drawing is done, send message. + emit this->mapDrawn(*m_mapImage); } + + +/*! +A new image is created when changing dimensions, so be sure +to draw the map after calling this function. +*/ +void +Sub_GameView +::MapDrawer::setDimensions(int width, int height) +{ + // Delete old image. + delete m_mapImage; + m_mapImage = 0; + + // Create new image of the specified size. + m_mapImage = new QPixmap(width, height); + + // Fill the image with a defaul color. + m_mapImage->fill(Qt::black); +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-08-02 10:22:29
|
Revision: 84 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=84&view=rev Author: kimmovii Date: 2010-08-02 10:22:23 +0000 (Mon, 02 Aug 2010) Log Message: ----------- Added test for for retrieving the highest layer from GameMap. Modified Paths: -------------- trunk/mysventure/test/sub_level/testgamemap/test.cpp Modified: trunk/mysventure/test/sub_level/testgamemap/test.cpp =================================================================== --- trunk/mysventure/test/sub_level/testgamemap/test.cpp 2010-07-31 16:33:22 UTC (rev 83) +++ trunk/mysventure/test/sub_level/testgamemap/test.cpp 2010-08-02 10:22:23 UTC (rev 84) @@ -65,6 +65,11 @@ */ void testIsInMap(); + /*! \brief + Tests getHighestLayer(). + */ + void testGetHighestLayer(); + private: GameMap* m_map; @@ -262,7 +267,26 @@ } +void Testgamemap::testGetHighestLayer() +{ + // Initially highest layer should be 3 + QVERIFY(m_map->getHighestLayer() == 3); + // Remove layer 3 and layer 1 + m_map->removeLayer(3); + m_map->removeLayer(1); + + // Highest layer should be 2 + QVERIFY(m_map->getHighestLayer() == 2); + + // Remove last layer. + m_map->removeLayer(2); + + // highest layer should be 0 + QVERIFY(m_map->getHighestLayer() == 0); +} + + QTEST_APPLESS_MAIN(Testgamemap); #include "test.moc" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-31 16:33:32
|
Revision: 83 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=83&view=rev Author: kimmovii Date: 2010-07-31 16:33:22 +0000 (Sat, 31 Jul 2010) Log Message: ----------- Implemented test for GameMap. Modified Paths: -------------- trunk/mysventure/source/sub_level/maplayer.cpp Added Paths: ----------- trunk/mysventure/test/sub_level/testgamemap/ trunk/mysventure/test/sub_level/testgamemap/test.cpp trunk/mysventure/test/sub_level/testgamemap/testgamemap.pro Modified: trunk/mysventure/source/sub_level/maplayer.cpp =================================================================== --- trunk/mysventure/source/sub_level/maplayer.cpp 2010-07-31 10:43:24 UTC (rev 82) +++ trunk/mysventure/source/sub_level/maplayer.cpp 2010-07-31 16:33:22 UTC (rev 83) @@ -63,7 +63,7 @@ Sub_GameLevel ::MapLayer::getRowSize() const { - m_layer.size(); + return m_layer.size(); } Added: trunk/mysventure/test/sub_level/testgamemap/test.cpp =================================================================== --- trunk/mysventure/test/sub_level/testgamemap/test.cpp (rev 0) +++ trunk/mysventure/test/sub_level/testgamemap/test.cpp 2010-07-31 16:33:22 UTC (rev 83) @@ -0,0 +1,268 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <QtCore/QString> +#include <QtTest/QtTest> + +#include "sub_level/gamemap.h" +#include "util/position.h" + +using namespace Sub_GameLevel; +using namespace Sub_GameUtility; + + + +class Testgamemap : public QObject +{ + Q_OBJECT + +public: + Testgamemap(); + +private Q_SLOTS: + + void init(); + void cleanup(); + + /*! \brief + Tests GameMap constructor. + */ + void testConstructor(); + + /*! \brief + Tests GameMap::addLayer() and GameMap::removeLayer(). + */ + void testAddRemoveLayer(); + + /*! \brief + Tests GameMap::resize(). + */ + void testResize(); + + /*! \brief + Tests GameMap::getEntity(), GameMap::setEntity() and + GameMap::getEntities(). + */ + void testSetGetEntity(); + + /*! \brief + Tests GameMap::isInMap(). + */ + void testIsInMap(); + +private: + + GameMap* m_map; + MapLayer* m_layer1; + MapLayer* m_layer2; + MapLayer* m_layer3; + + QVector<MapLayer> m_mapData; + + unsigned int m_numberOfRows; + unsigned int m_numberOfColumns; + +}; + +Testgamemap::Testgamemap() +{ + m_numberOfRows = 20; + m_numberOfColumns = 33; +} + +void Testgamemap::init() +{ + // Fill layer1-layer3 with entities. + QVector<MapColumn> layer1; + QVector<MapColumn> layer2; + QVector<MapColumn> layer3; + + for (int column = 0; column < m_numberOfColumns; ++column) + { + QVector<Identification> newColumn1; + QVector<Identification> newColumn2; + QVector<Identification> newColumn3; + for (int row = 0; row < m_numberOfRows; ++row) + { + newColumn1.push_back(Identification()); + newColumn2.push_back(Identification()); + newColumn3.push_back(Identification()); + } + layer1.push_back(MapColumn(m_numberOfRows, newColumn1)); + layer2.push_back(MapColumn(m_numberOfRows, newColumn2)); + layer3.push_back(MapColumn(m_numberOfRows, newColumn3)); + } + + m_layer1 = new MapLayer(m_numberOfColumns, m_numberOfRows, 1, + layer1); + m_layer2 = new MapLayer(m_numberOfColumns, m_numberOfRows, 2, + layer2); + m_layer3 = new MapLayer(m_numberOfColumns, m_numberOfRows, 3, + layer3); + + m_mapData << *m_layer1 << *m_layer2 << *m_layer3; + m_map = new GameMap(m_numberOfRows, m_numberOfColumns, + m_mapData); +} + +void Testgamemap::cleanup() +{ + delete m_layer1; + delete m_layer2; + delete m_layer3; + delete m_map; + m_mapData.clear(); +} + +/*! +Test plan: +- Verify that all entities are correct +- Verify that map dimensions are correct +*/ +void Testgamemap::testConstructor() +{ + // Verify map dimensions in map created in init(). + QVERIFY(m_map->getNumberOfColumns() == this->m_numberOfColumns); + QVERIFY(m_map->getNumberOfRows() == this->m_numberOfRows); + QVERIFY(m_map->getColumnSize() == this->m_numberOfRows); + QVERIFY(m_map->getRowSize() == this->m_numberOfColumns); + + // Verify contents + // Loop layers + for (int layer = 1; layer < 4; ++layer) + { + // Loop columns + for (int column = 0; column < m_numberOfColumns; ++column) + { + // Loop entities + for (int row = 0; row < m_numberOfRows; ++row) + { + QVERIFY(m_map->getEntity(Position(column, row, layer)) == + m_mapData.at(layer - 1 ).getEntity(row, column)); + } + } + } +} + +/*! +Test plan: +- Remove layers from map. +- Verify that removed layers are not on map. +- Add a layer +- Verify that added layer is on map. +- Verify that entities from removed layer are not found. +- Verify that entities from added layers are found. +*/ +void Testgamemap::testAddRemoveLayer() +{ + // Remove layer1 and layer2 from m_map. + m_map->removeLayer(1); + m_map->removeLayer(2); + QVERIFY(!m_map->hasLayer(1)); + QVERIFY(!m_map->hasLayer(2)); + QVERIFY(m_map->hasLayer(3)); + + // Add layer2 + m_map->addLayer(*m_layer2); + + QVERIFY(m_map->hasLayer(2)); + + // Verify that entities from removed layer are not found. + QVERIFY(m_map->getEntity(Position(m_numberOfColumns - 5, m_numberOfRows - 7, 1)) == + Identification::invalidId()); + + // Verify that entities from added layer are found. + QVERIFY(m_map->getEntity(Position(m_numberOfColumns - 1, m_numberOfRows - 1, 2)) + == m_layer2->getEntity(m_numberOfRows - 1, m_numberOfColumns - 1)); +} + +/*! +Test plan: +- Resize map to a different size +- Verify map dimensions were changed. +*/ +void Testgamemap::testResize() +{ + // Resize m_map to a different size + m_map->resize(m_numberOfRows + 5, m_numberOfColumns - 10); + QVERIFY(m_map->getNumberOfColumns() == m_numberOfColumns - 10); + QVERIFY(m_map->getNumberOfRows() == m_numberOfRows + 5); + QVERIFY(m_map->getColumnSize() == m_numberOfRows + 5); + QVERIFY(m_map->getRowSize() == m_numberOfColumns - 10); + + QVERIFY(m_map->getEntity(Position(m_numberOfRows + 3, 4)) == + Identification::invalidId()); +} + +/*! +Test plan: +- Verify entities. +- Verify getEntity() returns correct entities for valid positions. +- Verify getEntity() returns invalid entities for invalid positions. +- Verify getEntities() returns valid entities. +*/ +void Testgamemap::testSetGetEntity() +{ + // Test that returned entities are correct + for (int layer = 1; layer < 4; ++layer) + { + // Loop columns + for (int column = 0; column < m_numberOfColumns; ++column) + { + // Loop entities + for (int row = 0; row < m_numberOfRows; ++row) + { + QVERIFY(m_map->getEntity(Position(column, row, layer)) == + m_mapData.at(layer - 1 ).getEntity(row, column)); + } + } + } + + // Get all entities at position (0, 0) + QVector<Identification> entities = + m_map->getEntities(0, 0); + QVERIFY(entities.at(0) == m_layer1->getEntity(0, 0)); + QVERIFY(entities.at(1) == m_layer2->getEntity(0, 0)); + QVERIFY(entities.at(2) == m_layer3->getEntity(0, 0)); + + // Test that position outside m_map boundaries return invalid. + QVERIFY(m_map->getEntity(Position(5, 3, 5)) == Identification::invalidId()); + QVERIFY(m_map->getEntity(Position(m_numberOfColumns, m_numberOfRows, 2)) == + Identification::invalidId()); +} + +/*! +Test plan: +- Verify positions inside map are reported as such. +- Verify positions outside map are reported as such.*/ +void Testgamemap::testIsInMap() +{ + // Test positions inside map + QVERIFY(m_map->isInMap(Position(0, 0, 1))); + QVERIFY(m_map->isInMap(10, 12)); + + // Test positions outside map + QVERIFY(!(m_map->isInMap(m_numberOfRows, m_numberOfColumns))); + QVERIFY(!(m_map->isInMap(Position(5, 5, 4)))); +} + + + +QTEST_APPLESS_MAIN(Testgamemap); + +#include "test.moc" Added: trunk/mysventure/test/sub_level/testgamemap/testgamemap.pro =================================================================== --- trunk/mysventure/test/sub_level/testgamemap/testgamemap.pro (rev 0) +++ trunk/mysventure/test/sub_level/testgamemap/testgamemap.pro 2010-07-31 16:33:22 UTC (rev 83) @@ -0,0 +1,28 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-07-31T13:48:10 +# +#------------------------------------------------- + +QT += testlib + +QT -= gui + +TARGET = test +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + + +SOURCES += test.cpp \ + ../../../source/sub_level/gamemap.cpp \ + ../../../source/util/identification.cpp \ + ../../../source/sub_level/mapcolumn.cpp \ + ../../../source/sub_level/maplayer.cpp \ + ../../../source/util/Position.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" +INCLUDEPATH += ../../../include + +HEADERS += \ + ../../../include/sub_level/gamemap.h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-31 10:43:32
|
Revision: 82 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=82&view=rev Author: kimmovii Date: 2010-07-31 10:43:24 +0000 (Sat, 31 Jul 2010) Log Message: ----------- Implemented test for MapLayer. Fixed bugs in MapLayer. Modified Paths: -------------- trunk/README.txt trunk/mysventure/include/sub_level/maplayer.h trunk/mysventure/source/sub_level/mapcolumn.cpp trunk/mysventure/source/sub_level/maplayer.cpp trunk/mysventure/test/sub_level/testmapcolumn/test.cpp Added Paths: ----------- trunk/mysventure/test/sub_level/testmaplayer/ trunk/mysventure/test/sub_level/testmaplayer/test.cpp trunk/mysventure/test/sub_level/testmaplayer/testmaplayer.pro Modified: trunk/README.txt =================================================================== --- trunk/README.txt 2010-07-30 10:59:27 UTC (rev 81) +++ trunk/README.txt 2010-07-31 10:43:24 UTC (rev 82) @@ -4,6 +4,10 @@ For art, music etc. see LICENSE in the appropriate subdirectories. +mysventure subdirectory contains the project. + +design subdirectory contains the design related to project. + See INSTALL for instructions on how to build and run the project. Kimmo Viitanen <kvi...@gm...> Modified: trunk/mysventure/include/sub_level/maplayer.h =================================================================== --- trunk/mysventure/include/sub_level/maplayer.h 2010-07-30 10:59:27 UTC (rev 81) +++ trunk/mysventure/include/sub_level/maplayer.h 2010-07-31 10:43:24 UTC (rev 82) @@ -117,11 +117,6 @@ QVector<Sub_GameLevel::MapColumn> m_layer; /*! - Size of a row in layer. - */ - unsigned int m_rowSize; - - /*! Size of a column in layer. */ unsigned int m_columnSize; Modified: trunk/mysventure/source/sub_level/mapcolumn.cpp =================================================================== --- trunk/mysventure/source/sub_level/mapcolumn.cpp 2010-07-30 10:59:27 UTC (rev 81) +++ trunk/mysventure/source/sub_level/mapcolumn.cpp 2010-07-31 10:43:24 UTC (rev 82) @@ -172,5 +172,5 @@ Sub_GameLevel ::MapColumn::invariant() const { - Q_ASSERT(m_column.size() == m_column.size()); + } Modified: trunk/mysventure/source/sub_level/maplayer.cpp =================================================================== --- trunk/mysventure/source/sub_level/maplayer.cpp 2010-07-30 10:59:27 UTC (rev 81) +++ trunk/mysventure/source/sub_level/maplayer.cpp 2010-07-31 10:43:24 UTC (rev 82) @@ -31,7 +31,7 @@ unsigned int columnSize, unsigned int layerNumber, const QVector<Sub_GameLevel::MapColumn> &layerData) -: m_layer(layerData), m_rowSize(rowSize), m_columnSize(columnSize), +: m_layer(layerData), m_columnSize(columnSize), m_layerNumber(layerNumber) { resize(columnSize, rowSize); @@ -63,7 +63,7 @@ Sub_GameLevel ::MapLayer::getRowSize() const { - return m_rowSize; + m_layer.size(); } @@ -71,7 +71,7 @@ Sub_GameLevel ::MapLayer::getNumberOfColumns() const { - return m_rowSize; + return m_layer.size(); } @@ -90,7 +90,7 @@ ::MapLayer::setColumn(unsigned int pos, const MapColumn &column) { invariant(); - Q_ASSERT(pos < m_rowSize); + Q_ASSERT(pos < m_layer.size()); // Replace column. m_layer[pos] = column; @@ -109,7 +109,9 @@ const QVector<Sub_GameUtility::Identification> &column) { MapColumn newColumn(m_columnSize, column); - setColumn(pos, column); + + // Perform the real work using setColumn(unsigned int, MapColumn). + setColumn(pos, newColumn); } @@ -120,7 +122,7 @@ { invariant(); Q_ASSERT(row < m_columnSize); - Q_ASSERT(column < m_rowSize); + Q_ASSERT(column < m_layer.size()); return m_layer.at(column).getEntity(row); } @@ -135,7 +137,7 @@ { invariant(); Q_ASSERT(row < m_columnSize); - Q_ASSERT(column < m_rowSize); + Q_ASSERT(column < m_layer.size()); m_layer[column].setEntity(row, entity); } @@ -147,7 +149,7 @@ ::MapLayer::getColumn(unsigned int pos) const { invariant(); - Q_ASSERT(pos < m_rowSize); + Q_ASSERT(pos < m_layer.size()); return m_layer.at(pos); } @@ -164,13 +166,9 @@ Sub_GameLevel ::MapLayer::resize(unsigned int rows, unsigned int columns) { - invariant(); - Q_ASSERT(rows < m_columnSize); - Q_ASSERT(columns < m_rowSize); - - if (columns > m_rowSize) + if (columns > m_layer.size()) fitToGreater(rows, columns); - else if (columns < m_rowSize) + else if (columns < m_layer.size()) fitToSmaller(rows, columns); invariant(); @@ -186,26 +184,28 @@ Sub_GameLevel ::MapLayer::fitToGreater(unsigned int rows, unsigned int columns) { - // Create default column data. + // Create default column data with rows elements. QVector<Sub_GameUtility::Identification> columnData( - m_columnSize, Sub_GameUtility::Identification::invalidId()); + rows, Sub_GameUtility::Identification::invalidId()); - // Create default new column. - MapColumn newColumn(m_columnSize, columnData); + // Create default new column with size rows. + MapColumn newColumn(rows, columnData); // Loop from current max rows to the new max rows // and append a default column each time. - for (int i = m_rowSize; i < columns; ++i) + for (int i = m_layer.size(); i < columns; ++i) { m_layer.push_back(newColumn); + } - // After appending a default column, resize the column. - m_layer[i].resize(rows); + // After appending columns, resize all columns + for (int column = 0; column < columns; ++column) + { + m_layer[column].resize(rows); } // Then set sizes. m_columnSize = rows; - m_rowSize = columns; invariant(); } @@ -230,7 +230,6 @@ } m_columnSize = rows; - m_rowSize = columns; invariant(); } @@ -241,5 +240,5 @@ Sub_GameLevel ::MapLayer::invariant() const { - Q_ASSERT(m_layer.size() == m_rowSize); + } Modified: trunk/mysventure/test/sub_level/testmapcolumn/test.cpp =================================================================== --- trunk/mysventure/test/sub_level/testmapcolumn/test.cpp 2010-07-30 10:59:27 UTC (rev 81) +++ trunk/mysventure/test/sub_level/testmapcolumn/test.cpp 2010-07-31 10:43:24 UTC (rev 82) @@ -16,6 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/*! \file +Test for class MapColumn. +*/ + #include <QtCore/QString> #include <QtTest/QtTest> Added: trunk/mysventure/test/sub_level/testmaplayer/test.cpp =================================================================== --- trunk/mysventure/test/sub_level/testmaplayer/test.cpp (rev 0) +++ trunk/mysventure/test/sub_level/testmaplayer/test.cpp 2010-07-31 10:43:24 UTC (rev 82) @@ -0,0 +1,279 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Test for class MapLayer. +*/ + +#include <QtCore/QString> +#include <QtTest/QtTest> + +#include "sub_level/maplayer.h" + +using namespace Sub_GameLevel; +using namespace Sub_GameUtility; + + + +class Testmaplayer : public QObject +{ + Q_OBJECT + +public: + Testmaplayer(); + +private Q_SLOTS: + + void init(); + void cleanup(); + + /*! \brief + Test the constructor. + */ + void testConstructor(); + + /*! \brief + Test resize(). + */ + void testResize(); + + /*! \brief + Test setColumn() and getColumn(). + */ + void testSetGetColumn(); + + /*! \brief + Test setEntity() and getEntity(). + */ + void testSetGetEntity(); + +private: + + MapLayer* m_layer; + + QVector<MapColumn> m_columns; + + unsigned int layerWidth; + unsigned int layerHeight; + + QVector<Identification> idVector; + + + + void verifyLayer(const MapLayer& layer, + const QVector<MapColumn>& expected, + unsigned int rowSize, + unsigned int columnSize); + +}; + +Testmaplayer::Testmaplayer() +: layerWidth(24), layerHeight(30) +{ +} + +void Testmaplayer::init() +{ + // Populate idVector with IDs. + for (int i = 0; i < layerHeight; ++i) + { + idVector.push_back(Identification()); + } + + // Populate column vector with columns. + // All columns are equal, but it doesn't matter. + for (int i = 0; i < layerWidth; ++i) + { + m_columns.push_back(MapColumn(layerHeight, idVector)); + } +} + + +void Testmaplayer::cleanup() +{ + m_columns.clear(); + idVector.clear(); +} + + +/*! +Test plan: +- Create an empty layer. Verify layer is empty. +- Create a layer with number of columns greater than the passed data. +- Create a layer with number of columns smaller than the passed data. +*/ +void Testmaplayer::testConstructor() +{ + MapLayer layer1(layerWidth, layerHeight, 1, + m_columns); + + QVERIFY(layer1.getColumnSize() == layerHeight); + QVERIFY(layer1.getRowSize() == layerWidth); + QVERIFY(layer1.getLayerNumber() == 1); + + QVERIFY(layer1.getColumn(3).getColumnSize() == layerHeight); + + MapLayer layer2(layerWidth - 5, layerHeight + 10, 4, + m_columns); + + QVERIFY(layer2.getColumnSize() == layerHeight + 10); + QVERIFY(layer2.getRowSize() == layerWidth - 5); + + QVERIFY(layer2.getColumn(layerWidth - 6).getColumnSize() == layerHeight + 10); +} + +/*! +Test plan: +- Create a new layer. +- Resize the layer to a greater size. +- Resize the layer to a smaller size. +- Resize the layer to 0 size. +- Resize the layer to greater size from 0. +*/ +void Testmaplayer::testResize() +{ + MapLayer layer(layerWidth, layerHeight, 1, + m_columns); + + // Verify contents + verifyLayer(layer, m_columns, layerWidth, layerHeight); + + // Resize to greater size + layer.resize(layerHeight + 10, layerWidth + 10); + + // Append 10 columns to layer + for (int column = 0; column < 10; ++column) + { + m_columns.push_back(MapColumn(layerHeight, + QVector<Identification>(layerHeight, Identification::invalidId()))); + } + + // After appending 10 columns, append 10 items to each column + for (int column = 0; column < layerWidth + 10; ++column) + { + m_columns[column].resize(layerHeight + 10); + } + + // Verify contents + verifyLayer(layer, m_columns, layerWidth + 10, layerHeight + 10); + + // Resize to a smaller size. + layer.resize(layerHeight + 10 - 15, layerWidth + 10 - 20); + + // Verify contents + verifyLayer(layer, m_columns, layerWidth + 10 - 20, layerHeight + 10 - 15); + + // Resize to 0 + layer.resize(0, 0); + + // Verify + verifyLayer(layer, m_columns, 0, 0); + + // Resize from 0 + layer.resize(10, 5); + + // Clear expected contents and append 5 columns with invalid IDs. + m_columns.clear(); + for (int column = 0; column < 5; ++column) + { + m_columns.push_back(MapColumn(10)); + } + + // Verify + verifyLayer(layer, m_columns, 5, 10); +} + +/*! +Test plan: +- Create a layer. +- Set a column of the layer to different data. +- Retrieve the set column and verify the contents. +*/ +void Testmaplayer::testSetGetColumn() +{ + MapLayer layer(layerWidth, layerHeight, 2, + m_columns); + + QVector<Identification> newColumn; + for (int row = 0; row < layerHeight; ++row) + { + newColumn.push_back(Identification()); + } + + layer.setColumn(5, newColumn); + + MapColumn setColumn = layer.getColumn(5); + + for (int row = 0; row < layerHeight; ++row) + { + QVERIFY(setColumn.getEntity(row) == newColumn.at(row)); + } +} + +/*! +Test plan: +- Create a layer. +- Set entities on the layer to different ones. +- Also try to set entities that are not on the layer +- Verify the entities on the layer were changed correctly + and the entities outside the layer were not. +*/ +void Testmaplayer::testSetGetEntity() +{ + MapLayer layer(layerWidth, layerHeight, 1, + m_columns); + + QVector<Identification> ids; + for (int i = 0; i < 6; ++i) + { + ids.push_back(Identification()); + } + + for (int i = 0; i < 6; ++i) + { + layer.setEntity(i, i + 2, ids[i]); + } + + // Verify + for (int i = 0; i < 6; ++i) + { + QVERIFY(layer.getEntity(i, i + 2) == ids.at(i)); + } +} + + +void Testmaplayer::verifyLayer(const MapLayer& layer, + const QVector<MapColumn>& expected, + unsigned int rowSize, + unsigned int columnSize) +{ + for (int column = 0; column < rowSize; ++column) + { + MapColumn currentColumn = + layer.getColumn(column); + + for (int row = 0; row < columnSize; ++row) + { + QVERIFY(currentColumn.getEntity(row) == expected[column][row]); + } + } +} + +QTEST_APPLESS_MAIN(Testmaplayer); + +#include "test.moc" Added: trunk/mysventure/test/sub_level/testmaplayer/testmaplayer.pro =================================================================== --- trunk/mysventure/test/sub_level/testmaplayer/testmaplayer.pro (rev 0) +++ trunk/mysventure/test/sub_level/testmaplayer/testmaplayer.pro 2010-07-31 10:43:24 UTC (rev 82) @@ -0,0 +1,26 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-07-30T14:56:45 +# +#------------------------------------------------- + +QT += testlib + +QT -= gui + +TARGET = test +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + + +SOURCES += test.cpp \ + ../../../source/sub_level/maplayer.cpp \ + ../../../source/sub_level/mapcolumn.cpp \ + ../../../source/util/identification.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" +INCLUDEPATH += ../../../include + +HEADERS += \ + ../../../include/sub_level/maplayer.h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-30 10:59:33
|
Revision: 81 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=81&view=rev Author: kimmovii Date: 2010-07-30 10:59:27 +0000 (Fri, 30 Jul 2010) Log Message: ----------- Empty file removed. Replacing with a HTML format file which is probably more suitable and easier to work with. Removed Paths: ------------- trunk/design/game/map_file_format.odt Deleted: trunk/design/game/map_file_format.odt =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-30 09:33:38
|
Revision: 80 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=80&view=rev Author: kimmovii Date: 2010-07-30 09:33:31 +0000 (Fri, 30 Jul 2010) Log Message: ----------- Implemented test for MapColumn. Modified Paths: -------------- trunk/mysventure/include/sub_level/mapcolumn.h trunk/mysventure/include/sub_level/sub_gamelevels.h trunk/mysventure/source/sub_level/mapcolumn.cpp Added Paths: ----------- trunk/mysventure/test/sub_level/ trunk/mysventure/test/sub_level/testmapcolumn/ trunk/mysventure/test/sub_level/testmapcolumn/test.cpp trunk/mysventure/test/sub_level/testmapcolumn/testmapcolumn.pro Modified: trunk/mysventure/include/sub_level/mapcolumn.h =================================================================== --- trunk/mysventure/include/sub_level/mapcolumn.h 2010-07-29 09:36:14 UTC (rev 79) +++ trunk/mysventure/include/sub_level/mapcolumn.h 2010-07-30 09:33:31 UTC (rev 80) @@ -102,10 +102,6 @@ */ QVector<Sub_GameUtility::Identification> m_column; - /*! - The size of the column in tiles. - */ - unsigned int m_columnSize; /*! \brief Modified: trunk/mysventure/include/sub_level/sub_gamelevels.h =================================================================== --- trunk/mysventure/include/sub_level/sub_gamelevels.h 2010-07-29 09:36:14 UTC (rev 79) +++ trunk/mysventure/include/sub_level/sub_gamelevels.h 2010-07-30 09:33:31 UTC (rev 80) @@ -25,6 +25,7 @@ #include "sub_level/mapcolumn.h" #include "sub_level/maplayer.h" +#include "sub_level/gamemap.h" /*! \brief Contains all identifiers in the levels subsystem. Modified: trunk/mysventure/source/sub_level/mapcolumn.cpp =================================================================== --- trunk/mysventure/source/sub_level/mapcolumn.cpp 2010-07-29 09:36:14 UTC (rev 79) +++ trunk/mysventure/source/sub_level/mapcolumn.cpp 2010-07-30 09:33:31 UTC (rev 80) @@ -33,10 +33,12 @@ Sub_GameLevel ::MapColumn::MapColumn(unsigned int columnSize, const QVector<Identification> &columnData) -: m_column(columnData), m_columnSize(columnSize) +: m_column(columnData) { - if (columnData.size() != m_columnSize) - this->resize(m_columnSize); + // If size of passed data is dfferent from the size specified, + // resize to the specified size. + if (columnData.size() != columnSize) + this->resize(columnSize); invariant(); } @@ -54,16 +56,15 @@ Sub_GameLevel ::MapColumn::resize(unsigned int newSize) { - invariant(); - // If newSize is the same as existing size, do nothing. - if (newSize == m_columnSize) - return; - - if (newSize > m_columnSize) + // if new size is greater than column size, grow. + if (newSize > m_column.size()) fitToGreater(newSize); - else if (newSize < m_columnSize) + // If new size is smaller than column size, shrink. + else if (newSize < m_column.size()) fitToSmaller(newSize); + // If new size is equal to column size, nothing is done. + invariant(); } @@ -75,7 +76,7 @@ { invariant(); - return m_columnSize; + return m_column.size(); } @@ -85,7 +86,7 @@ { invariant(); - return m_columnSize; + return m_column.size(); } @@ -95,7 +96,7 @@ ::MapColumn::getEntity(unsigned int columnPos) const { invariant(); - Q_ASSERT(columnPos < m_columnSize); + Q_ASSERT(columnPos < m_column.size()); return m_column.at(columnPos); } @@ -107,7 +108,7 @@ ::MapColumn::setEntity(unsigned int columnPos, const Identification &entity) { invariant(); - Q_ASSERT(columnPos < m_columnSize); + Q_ASSERT(columnPos < m_column.size()); m_column[columnPos] = entity; } @@ -119,7 +120,7 @@ ::MapColumn::operator[](unsigned int columnPos) { invariant(); - Q_ASSERT(columnPos < m_columnSize); + Q_ASSERT(columnPos < m_column.size()); return m_column[columnPos]; } @@ -130,7 +131,7 @@ ::MapColumn::operator [](unsigned int columnPos) const { invariant(); - Q_ASSERT(columnPos < m_columnSize); + Q_ASSERT(columnPos < m_column.size()); return m_column[columnPos]; } @@ -141,9 +142,10 @@ Sub_GameLevel ::MapColumn::fitToGreater(unsigned int newSize) { - Q_ASSERT(newSize > m_columnSize); + Q_ASSERT(newSize > m_column.size()); - for (int i = m_columnSize; i < newSize; ++i) + // Start filling column from after the last valid index. + for (int i = m_column.size(); i < newSize; ++i) { m_column.push_back(Identification::invalidId()); } @@ -157,7 +159,7 @@ Sub_GameLevel ::MapColumn::fitToSmaller(unsigned int newSize) { - Q_ASSERT(newSize < m_columnSize); + Q_ASSERT(newSize < m_column.size()); m_column.resize(newSize); @@ -170,5 +172,5 @@ Sub_GameLevel ::MapColumn::invariant() const { - Q_ASSERT(m_columnSize == m_column.size()); + Q_ASSERT(m_column.size() == m_column.size()); } Added: trunk/mysventure/test/sub_level/testmapcolumn/test.cpp =================================================================== --- trunk/mysventure/test/sub_level/testmapcolumn/test.cpp (rev 0) +++ trunk/mysventure/test/sub_level/testmapcolumn/test.cpp 2010-07-30 09:33:31 UTC (rev 80) @@ -0,0 +1,363 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <QtCore/QString> +#include <QtTest/QtTest> + +#include "sub_level/mapcolumn.h" + +using namespace Sub_GameLevel; +using namespace Sub_GameUtility; + +class Testmapcolumn : public QObject +{ + Q_OBJECT + +public: + Testmapcolumn(); + +private Q_SLOTS: + + void init(); + void cleanup(); + + /*! \brief + Test the MapColumn constructor. Verify that contents are + initialized correctly. + */ + void testConstructor(); + + /*! \brief + Test resize() method. Verify that column is resized correctly. + */ + void testResize(); + + /*! \brief + Test getEntity(). Verify that entities are returned correctly. + */ + void testGetEntity(); + + /*! \brief + Test setEntity(). Verify that changing entities works as expected. + */ + void testSetEntity(); + + /*! \brief + Test operator[](). Verify that elements are correctly returned + and modified. + */ + void testIndexOperator(); + +private: + + MapColumn* m_testColumn; +}; + +Testmapcolumn::Testmapcolumn() +{ +} + +void Testmapcolumn::init() +{ + m_testColumn = new MapColumn; + m_testColumn = 0; +} + + +void Testmapcolumn::cleanup() +{ + delete m_testColumn; +} + + + +/* +void Testmapcolumn::testConstructor_data() +{ + QTest::addColumn<unsigned int>("size"); + QTest::addColumn<QVector<Identification> >("data"); + + Identification id1; + Identification id2; + Identification id3; + Identification id4; + Identification id5; + Identification id6; + + QVector<Identification> data; + data << id1 << id2 << id3 << id4 << id5 << id6; + + QTest::newRow("size smaller than data") << data.size() - 2 << data; + QTest::newRow("size greater than data") << data.size() + 4 << data; + QTest::newRow("size equal to data") << data.size() << data; + QTest::newRow("empty data, size > 0") << 12 << QVector<Identification>(); +} + + +Test is performed by creating three columns: +- one with a smaller size argument than the content size. +- one with a greater size argument than the content size. +- one with size argument equal to content size. +- as last case test passing empty data and size greater than 0 +void Testmapcolumn::testConstructor() +{ + QFETCH(unsigned int, size); + QFETCH(QVector<Identification>, data); + + MapColumn column(size, data); + + QVERIFY(column.getColumnSize() == size); + + for (int i = 0; i < column.getColumnSize(); ++i) + { + // When the index gets greater than size of data, + // verify that elements were set to invalid IDs. + if (i >= data.size()) + QVERIFY(column.getEntity(i) == Identification::invalidId()); + else + QVERIFY(column.getEntity(i) == data.at(i)); + } +} +*/ + + + +/*! +Test is performed by creating three columns: +- one with a smaller size argument than the content size. +- one with a greater size argument than the content size. +- one with size argument equal to content size. +- as last case test passing empty data and size greater than 0 +*/ +void Testmapcolumn::testConstructor() +{ + const unsigned int columnSize = 6; + + unsigned int size1 = 5; + unsigned int size2 = 8; + unsigned int size3 = 6; + unsigned int size4 = 10; + + Identification id1; + Identification id2; + Identification id3; + Identification id4; + Identification id5; + Identification id6; + + QVector<Identification> data; + data << id1 << id2 << id3 << id4 << id5 << id6; + + MapColumn column1(size1, data); + + QVERIFY(column1.getColumnSize() == size1); + + for (int i = 0; i < column1.getColumnSize(); ++i) + { + QVERIFY(column1.getEntity(i) == data.at(i)); + } + + MapColumn column2(size2, data); + + QVERIFY(column2.getColumnSize() == size2); + + for (int i = 0; i < column2.getColumnSize(); ++i) + { + // When the index gets greater than size of data, + // verify that elements were set to invalid IDs. + if (i >= data.size()) + QVERIFY(column2.getEntity(i) == Identification::invalidId()); + else + QVERIFY(column2.getEntity(i) == data.at(i)); + } + + MapColumn column3(size3, data); + + QVERIFY(column3.getColumnSize() == size3); + + for (int i = 0; i < column3.getColumnSize(); ++i) + { + QVERIFY(column3.getEntity(i) == data.at(i)); + } + + // Pass empty data and verify all elements are invalid. + MapColumn column4(size4, QVector<Identification>()); + + QVERIFY(column4.getColumnSize() == size4); + + for (int i = 0; i < size4; ++i) + { + QVERIFY(column4.getEntity(i) == Identification::invalidId()); + } +} + +/*! +Test is performed by creating a column +and resizing it to different sizes. +- Resize to a smaller size +- Resize to a greater size +- Resize to 0 +- Resize from 0 to greater size +- Resize to the same size +*/ +void Testmapcolumn::testResize() +{ + Identification id1; + Identification id2; + Identification id3; + Identification id4; + Identification id5; + Identification id6; + + QVector<Identification> data; + data << id1 << id2 << id3 << id4 << id5 << id6; + + MapColumn column1(data.size(), data); + QVERIFY(column1.getColumnSize() == data.size()); + + // Resize to a smaller size + column1.resize(3); + QVERIFY(column1.getColumnSize() == 3); + for (int i = 0; i < column1.getColumnSize(); ++i) + { + QVERIFY(column1.getEntity(i) == data.at(i)); + } + + // Resize to a greater size + column1.resize(10); + QVERIFY(column1.getColumnSize() == 10); + for (int i = 0; i< column1.getColumnSize(); ++i) + { + // All elements after index 2 should be invalid + if (i >= 3) + QVERIFY(column1.getEntity(i) == Identification::invalidId()); + else + QVERIFY(column1.getEntity(i) == data.at(i)); + } + + // Resize to 0 + column1.resize(0); + QVERIFY(column1.getColumnSize() == 0); + + // Resize from 0 + column1.resize(34); + QVERIFY(column1.getColumnSize() == 34); + for (int i = 0; i < column1.getColumnSize(); ++i) + { + QVERIFY(column1.getEntity(i) == Identification::invalidId()); + } + + // Resize to same size + MapColumn column2(data.size(), data); + column2.resize(data.size()); + + for (int i = 0; i < column2.getColumnSize(); ++i) + { + QVERIFY(column2.getEntity(i) == data.at(i)); + } +} + + +/*! +getEntity() is already tested in other functions, +but here it is anyway. +*/ +void Testmapcolumn::testGetEntity() +{ + Identification id1; + Identification id2; + Identification id3; + Identification id4; + Identification id5; + Identification id6; + + QVector<Identification> data; + data << id1 << id2 << id3 << id4 << id5 << id6; + + MapColumn column(data.size(), data); + QVERIFY(column.getEntity(4) == data.at(4)); + QVERIFY(column.getEntity(0) == data.at(0)); +} + +/*! +Test is performed by creating a column +and changing some entities. +*/ +void Testmapcolumn::testSetEntity() +{ + Identification id1; + Identification id2; + Identification id3; + Identification id4; + Identification id5; + Identification id6; + + QVector<Identification> data; + data << id1 << id2 << id3 << id4 << id5 << id6; + + MapColumn column(data.size(), data); + + Identification newId1; + Identification newId2; + Identification newId3; + + column.setEntity(0, newId1); + column.setEntity(4, newId2); + column.setEntity(data.size() - 1, newId3); + + QVERIFY(column.getEntity(0) == newId1); + QVERIFY(column.getEntity(4) == newId2); + QVERIFY((column.getEntity(data.size() - 1) == newId3)); +} + +/*! +- Retrieve an entity using operator[](). +- Change an entity through operator[]() +*/ +void Testmapcolumn::testIndexOperator() +{ + Identification id1; + Identification id2; + Identification id3; + Identification id4; + Identification id5; + Identification id6; + + QVector<Identification> data; + data << id1 << id2 << id3 << id4 << id5 << id6; + + MapColumn column(data.size(), data); + + for (int i = 0; i < column.getColumnSize(); ++i) + { + QVERIFY(column[i] == data.at(i)); + } + + Identification newId1; + Identification newId2; + + column[0] = newId1; + column[4] = newId2; + + QVERIFY(column.getEntity(0) == newId1); + QVERIFY(column[4] == newId2); +} + +QTEST_APPLESS_MAIN(Testmapcolumn); + +#include "test.moc" Added: trunk/mysventure/test/sub_level/testmapcolumn/testmapcolumn.pro =================================================================== --- trunk/mysventure/test/sub_level/testmapcolumn/testmapcolumn.pro (rev 0) +++ trunk/mysventure/test/sub_level/testmapcolumn/testmapcolumn.pro 2010-07-30 09:33:31 UTC (rev 80) @@ -0,0 +1,25 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-07-29T15:57:24 +# +#------------------------------------------------- + +QT += testlib + +QT -= gui + +TARGET = test +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + + +SOURCES += test.cpp \ + ../../../source/sub_level/mapcolumn.cpp \ + ../../../source/util/identification.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" +INCLUDEPATH += ../../../include + +HEADERS += \ + ../../../include/sub_level/mapcolumn.h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-29 09:36:21
|
Revision: 79 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=79&view=rev Author: kimmovii Date: 2010-07-29 09:36:14 +0000 (Thu, 29 Jul 2010) Log Message: ----------- Implemented GameMap. Untested. Modified Paths: -------------- trunk/design/game/technical_design.odt trunk/mysventure/include/util/position.h trunk/mysventure/mys-venture.pro trunk/mysventure/source/sub_level/maplayer.cpp Added Paths: ----------- trunk/mysventure/include/sub_level/gamemap.h trunk/mysventure/source/sub_level/gamemap.cpp Modified: trunk/design/game/technical_design.odt =================================================================== (Binary files differ) Added: trunk/mysventure/include/sub_level/gamemap.h =================================================================== --- trunk/mysventure/include/sub_level/gamemap.h (rev 0) +++ trunk/mysventure/include/sub_level/gamemap.h 2010-07-29 09:36:14 UTC (rev 79) @@ -0,0 +1,208 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Declaration for class GameMap. +*/ + +/*! \todo +The trigger-messages as "specified" by the design +are not implemented yet. +*/ + +#ifndef GAMEMAP_H +#define GAMEMAP_H + +#include <QMap> +#include <QString> + +#include "sub_level/maplayer.h" +#include "util/identification.h" +#include "util/Position.h" + +namespace Sub_GameLevel +{ + + /*! \brief + GameMap represents a single map in the game. + */ + /*! + GameMaps are composed of MapLayers. A map can be initialized on + construction by providing the number of rows, columns and + initial map data. Alternatively, an empty map can be constructed + and modified using resize() and addLayer(). + */ + class GameMap + { + public: + + /*! \brief + Default constructor can be used to initialize the map. + */ + GameMap(unsigned int rows = 0, unsigned int columns = 0, + const QVector<Sub_GameLevel::MapLayer>& mapData = + QVector<Sub_GameLevel::MapLayer>()); + + /*! \brief + Returns the map start message. + */ + QString getStartMessage() const; + + /*! \brief + Sets the map start message. + */ + void setStartMessage(const QString& message); + + /*! \brief + Returns the map end message. + */ + QString getEndMessage() const; + + /*! \brief + Sets the map end message. + */ + void setEndMessage(const QString& message); + + /*! \brief + Returns the map objective message. + */ + QString getObjectiveMessage() const; + + /*! \brief + Sets the map objective message. + */ + void setObjectiveMessage(const QString& message); + + /*! \brief + Adds a layer to the map. + */ + void addLayer(const MapLayer& layer); + + /*! \brief + Removes the layer with layer number layerNumber. + */ + void removeLayer(unsigned int layerNumber); + + /*! \brief + Returns true if the map has a layer with layer number layerNumber. + */ + bool hasLayer(unsigned int layerNumber) const; + + /*! \brief + Returns the size of a column on the map. + */ + unsigned int getColumnSize() const; + + /*! \brief + Returns number of rows on map. Same as column size. + */ + unsigned int getNumberOfRows() const; + + /*! \brief + Returns the size of a row on map. + */ + unsigned int getRowSize() const; + + /*! \brief + Returns the number of columns on map. Same as row size. + */ + unsigned int getNumberOfColumns() const; + + /*! \brief + Resizes the map to rows x columns size. + */ + void resize(unsigned int rows, unsigned int columns); + + /*! \brief + Returns the entity at the given position. + */ + Sub_GameUtility::Identification + getEntity(const Sub_GameUtility::Position& position) const; + + /*! \brief + Returns the entities at position (row, column) from all layers + as a QVector. + */ + QVector<Sub_GameUtility::Identification> + getEntities(unsigned int row, unsigned int column) const; + + /*! + Changes the entity at position to entity. + */ + void setEntity(const Sub_GameUtility::Position& position, + const Sub_GameUtility::Identification& entity); + + /*! \brief + Returns true if position is inside the map boundaries. + */ + bool isInMap(const Sub_GameUtility::Position& position) const; + + /*! \brief + Returns true if the given position is inside the map. + */ + bool isInMap(unsigned int row, unsigned int column) const; + + private: + + /*! + The message meant to be shown to the player when entering + the map. + */ + QString m_startMessage; + + /*! + The message meant to be shown to the player when exiting + the map. + */ + QString m_endMessage; + + /*! + The objective of the map. Basically, why is the player on this + map to begin with. + + This is shown in a place where the player can access it at anytime. + */ + QString m_mapObjective; + + /*! + The layers that make up the map. + */ + QMap<unsigned int, MapLayer> m_layers; + + /*! + The size of a map column. + */ + unsigned int m_columnSize; + + /*! + The size of a map row. + */ + unsigned int m_rowSize; + + + + /*! \brief + Holds the class invariant. + */ + void invariant() const; + + }; + +} // namespace Sub_GameLevel + +#endif // GAMEMAP_H Modified: trunk/mysventure/include/util/position.h =================================================================== --- trunk/mysventure/include/util/position.h 2010-07-28 13:17:23 UTC (rev 78) +++ trunk/mysventure/include/util/position.h 2010-07-29 09:36:14 UTC (rev 79) @@ -58,6 +58,11 @@ unsigned int getLayer() const { return m_layer; } + unsigned int getRowPosition() const { return m_y; } + + unsigned int getColumnPosition() const { return m_x; } + + private: Modified: trunk/mysventure/mys-venture.pro =================================================================== --- trunk/mysventure/mys-venture.pro 2010-07-28 13:17:23 UTC (rev 78) +++ trunk/mysventure/mys-venture.pro 2010-07-29 09:36:14 UTC (rev 79) @@ -25,7 +25,8 @@ source/sub_entity/basegameentitymaker.cpp \ source/sub_entity/entitymanager.cpp \ source/sub_level/mapcolumn.cpp \ - source/sub_level/maplayer.cpp + source/sub_level/maplayer.cpp \ + source/sub_level/gamemap.cpp HEADERS += include/sub_view/mainwindow.h \ include/util/Position.h \ include/util/identification.h \ @@ -53,7 +54,8 @@ include/util/util_functions.h \ include/sub_entity/entitymanager.h \ include/sub_level/mapcolumn.h \ - include/sub_level/maplayer.h + include/sub_level/maplayer.h \ + include/sub_level/gamemap.h FORMS += source/sub_view/mainwindow.ui \ source/sub_view/mapview.ui LIBS += -Llib \ Added: trunk/mysventure/source/sub_level/gamemap.cpp =================================================================== --- trunk/mysventure/source/sub_level/gamemap.cpp (rev 0) +++ trunk/mysventure/source/sub_level/gamemap.cpp 2010-07-29 09:36:14 UTC (rev 79) @@ -0,0 +1,341 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Implementation for class GameMap. +*/ + +#include "sub_level/gamemap.h" + +using namespace Sub_GameLevel; +using namespace Sub_GameUtility; + + + +/*! +The constructor copies the map data from mapData +and resizes the map to the size passed as arguments. +*/ +Sub_GameLevel +::GameMap::GameMap(unsigned int rows, + unsigned int columns, + const QVector<Sub_GameLevel::MapLayer> &mapData) +: m_columnSize(rows), m_rowSize(columns) +{ + // Copy the layers from mapData to m_layers. + for (int i = 0; i < mapData.size(); ++i) + { + m_layers.insert(mapData.at(i).getLayerNumber(), + mapData.at(i)); + } + + resize(m_columnSize, m_rowSize); + invariant(); +} + + + +QString +Sub_GameLevel +::GameMap::getStartMessage() const +{ + return m_startMessage; +} + + + +void +Sub_GameLevel +::GameMap::setStartMessage(const QString &message) +{ + m_startMessage = message; +} + + + +QString +Sub_GameLevel +::GameMap::getEndMessage() const +{ + return m_endMessage; +} + + + +void +Sub_GameLevel +::GameMap::setEndMessage(const QString &message) +{ + m_endMessage = message; +} + + + +QString +Sub_GameLevel +::GameMap::getObjectiveMessage() const +{ + return m_mapObjective; +} + + + +void +Sub_GameLevel +::GameMap::setObjectiveMessage(const QString &message) +{ + m_mapObjective = message; +} + + + +/*! +If the map already contains a layer with the same layer number +as the new layer, nothing is done. You must explicitly remove the +existing layer in this case. + +If no layer exists with the same layer number, then the new layer +is copied to map. +*/ +void +Sub_GameLevel +::GameMap::addLayer(const MapLayer &layer) +{ + invariant(); + + unsigned int layerNumber = layer.getLayerNumber(); + + // If a layer already exists, return + if (m_layers.contains(layerNumber)) + return; + + // Insert the layer + m_layers.insert(layerNumber, layer); + + Q_ASSERT(m_layers.contains(layerNumber)); + + // Resize the new layer to map size. + m_layers[layerNumber].resize(m_columnSize, m_rowSize); + + invariant(); +} + + + +/*! +Removes the layer with number layerNumber. +*/ +void +Sub_GameLevel +::GameMap::removeLayer(unsigned int layerNumber) +{ + m_layers.remove(layerNumber); + + Q_ASSERT(!(m_layers.contains(layerNumber))); + + invariant(); +} + + + +bool +Sub_GameLevel +::GameMap::hasLayer(unsigned int layerNumber) const +{ + return m_layers.contains(layerNumber); +} + + + +unsigned int +Sub_GameLevel +::GameMap::getColumnSize() const +{ + return m_columnSize; +} + + +unsigned int +Sub_GameLevel +::GameMap::getNumberOfRows() const +{ + return getColumnSize(); +} + + + +unsigned int +Sub_GameLevel +::GameMap::getRowSize() const +{ + return m_rowSize; +} + + + +unsigned int +Sub_GameLevel +::GameMap::getNumberOfColumns() const +{ + return getRowSize(); +} + + + +/*! +*/ +void +Sub_GameLevel +::GameMap::resize(unsigned int rows, unsigned int columns) +{ + // Resizing is performed by calling resize() for each layer. + // MapLayer and MapColumn have a resize() method that takes + // care of the actual resizing. + QMap<unsigned int, MapLayer>::iterator it; + for (it = m_layers.begin(); it != m_layers.end(); ++it) + { + (*it).resize(rows, columns); + + Q_ASSERT((*it).getColumnSize() == rows); + Q_ASSERT((*it).getRowSize() == columns); + } + + // Set new sizes + m_columnSize = rows; + m_rowSize = columns; + + invariant(); +} + + +/*! +If the position provided is not inside the map, an invalid ID +is returned. +*/ +Sub_GameUtility::Identification +Sub_GameLevel +::GameMap::getEntity(const Sub_GameUtility::Position &position) const +{ + // If the layer does not exist, return invalid. + if (!(m_layers.contains(position.getLayer()))) + return Sub_GameUtility::Identification::invalidId(); + + // If the position is not inside the map, return invalid. + if (!(isInMap(position))) + return Sub_GameUtility::Identification::invalidId(); + + return m_layers.value(position.getLayer()).getEntity(position.getYPosition(), + position.getXPosition()); +} + + + +/*! +If the position provided is not inside the map, +an empty vector is returned. +*/ +QVector<Sub_GameUtility::Identification> +Sub_GameLevel +::GameMap::getEntities(unsigned int row, unsigned int column) const +{ + QVector<Sub_GameUtility::Identification> result; + + // If not inside map, return empty vector. + if (!(isInMap(row, column))) + return result; + + QMap<unsigned int, MapLayer>::const_iterator it; + for (it = m_layers.constBegin(); it != m_layers.constEnd(); ++it) + { + result.push_back((*it).getEntity(row, column)); + } + + return result; +} + + + +void +Sub_GameLevel +::GameMap::setEntity(const Sub_GameUtility::Position &position, + const Sub_GameUtility::Identification &entity) +{ + // If position is not inside map, do nothing. + if (!isInMap(position)) + return; + + m_layers[position.getLayer()].setEntity(position.getRowPosition(), + position.getColumnPosition(), + entity); + + invariant(); +} + + +/*! +NOTE: This method also considers the layer information when +determining if the position is in the map. In other words, if the +map doesn't have the layer specified in position, false is returned. +*/ +bool +Sub_GameLevel +::GameMap::isInMap(const Position &position) const +{ + // If no such layer exists, position is outside map. + if (!(m_layers.contains(position.getLayer()))) + return false; + + // If layer exists, then only check if (row, column) + // is inside map. + return isInMap(position.getRowPosition(), + position.getColumnPosition()); +} + + + +/*! +NOTE: This method only considers the row and column dimensions +when determining if the position is on the map. +*/ +bool +Sub_GameLevel +::GameMap::isInMap(unsigned int row, unsigned int column) const +{ + if (row >= m_columnSize || + column >= m_rowSize) + return false; + + return true; +} + + +/*! +The invariant is each layer's row and column size must be +equal to the map's row and column size. +*/ +void +Sub_GameLevel +::GameMap::invariant() const +{ + QMap<unsigned int, MapLayer>::const_iterator it; + for (it = m_layers.constBegin(); it != m_layers.constEnd(); ++it) + { + Q_ASSERT(it.value().getColumnSize() == m_columnSize); + Q_ASSERT(it.value().getRowSize() == m_rowSize); + } +} Modified: trunk/mysventure/source/sub_level/maplayer.cpp =================================================================== --- trunk/mysventure/source/sub_level/maplayer.cpp 2010-07-28 13:17:23 UTC (rev 78) +++ trunk/mysventure/source/sub_level/maplayer.cpp 2010-07-29 09:36:14 UTC (rev 79) @@ -153,7 +153,13 @@ } +/*! +If the new size if greater than the current size, +default-constructed values (invalid IDs) are assigned to the emty space. +If the new size is smaller than the current size, +entities are simply cut from the end. +*/ void Sub_GameLevel ::MapLayer::resize(unsigned int rows, unsigned int columns) @@ -214,8 +220,10 @@ Sub_GameLevel ::MapLayer::fitToSmaller(unsigned int rows, unsigned int columns) { + // Resize the number of columns. m_layer.resize(columns); + // Resize each column. for (int i = 0; i < m_layer.size(); ++i) { m_layer[i].resize(rows); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-28 13:18:32
|
Revision: 78 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=78&view=rev Author: kimmovii Date: 2010-07-28 13:17:23 +0000 (Wed, 28 Jul 2010) Log Message: ----------- Implemented MapColumn and MapLayer. Untested. Modified Paths: -------------- trunk/design/game/technical_design.odt trunk/mysventure/include/sub_level/sub_gamelevels.h trunk/mysventure/mys-venture.pro Added Paths: ----------- trunk/mysventure/include/sub_level/mapcolumn.h trunk/mysventure/include/sub_level/maplayer.h trunk/mysventure/source/sub_level/mapcolumn.cpp trunk/mysventure/source/sub_level/maplayer.cpp Modified: trunk/design/game/technical_design.odt =================================================================== (Binary files differ) Added: trunk/mysventure/include/sub_level/mapcolumn.h =================================================================== --- trunk/mysventure/include/sub_level/mapcolumn.h (rev 0) +++ trunk/mysventure/include/sub_level/mapcolumn.h 2010-07-28 13:17:23 UTC (rev 78) @@ -0,0 +1,136 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Declaration for class MapColumn. +*/ + +#ifndef MAPCOLUMN_H +#define MAPCOLUMN_H + +#include <QVector> + +#include "util/identification.h" + + +namespace Sub_GameLevel +{ + + /*! \brief + MapColumn represents a column of a map layer. + */ + /*! + MapColumn is a container for Identification objects and + represents a single column on map layer. + + The column can be initialized during construction by passing + the size of the column and the column data as a QVector to + the constructor. + + The size of the column can be retrieved with either + getColumnSize() or getNumberOfRows(). The ID of the entity at a + position in the column can be retrieved with getEntity() and + a new entity can be set with setEntity(). + */ + class MapColumn + { + public: + + /*! \brief + The default constructor. + */ + MapColumn(unsigned int columnSize = 0, + const QVector<Sub_GameUtility::Identification>& columnData = + QVector<Sub_GameUtility::Identification>()); + + /*! \brief + Resizes the column to newSize elements. + */ + void resize(unsigned int newSize); + + /*! \brief + Returns the size of the column (the number of rows). + */ + unsigned int getColumnSize() const; + + /*! \brief + Returns the number of rows in column (the column size). + */ + unsigned int getNumberOfRows() const; + + /*! \brief + Returns the ID at position columnPos. + */ + Sub_GameUtility::Identification + getEntity(unsigned int columnPos) const; + + /*! \brief + Sets the ID at columnPos to entity. + */ + void setEntity(unsigned int columnPos, + const Sub_GameUtility::Identification& entity); + + /*! \brief + Returns a reference to the ID at position columnPos. + */ + Sub_GameUtility::Identification& operator[](unsigned int columnPos); + + /*! \brief + Returns a reference to the ID at position columnPos. const version. + */ + const Sub_GameUtility::Identification& operator[](unsigned int columnPos) const; + + private: + + /*! + The internal column. + */ + QVector<Sub_GameUtility::Identification> m_column; + + /*! + The size of the column in tiles. + */ + unsigned int m_columnSize; + + + /*! \brief + Fits the column to a size greater than the current size. + + Internal. + */ + void fitToGreater(unsigned int newSize); + + /*! \brief + Fist the column to a size smaller than the current size. + + Internal. + */ + void fitToSmaller(unsigned int newSize); + + /*! \brief + Checks the class invariant. + */ + void invariant() const; + + }; // class MapColumn + +} // namespace Sub_GameLevel + + + +#endif // MAPCOLUMN_H Added: trunk/mysventure/include/sub_level/maplayer.h =================================================================== --- trunk/mysventure/include/sub_level/maplayer.h (rev 0) +++ trunk/mysventure/include/sub_level/maplayer.h 2010-07-28 13:17:23 UTC (rev 78) @@ -0,0 +1,149 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef MAPLAYER_H +#define MAPLAYER_H + +#include <QVector> + +#include "sub_level/mapcolumn.h" + +namespace Sub_GameLevel +{ + + /*! \brief + MapLayer represents a layer on a game map. + */ + /*! + MapLayer can be initialized on construction by passing number of rows and + columns, layer number and the layer data to the default constructor. + + Layer size can be queried with getColumnSize() and getRowSize(). + + Contents of a whole column can be changed with setColumn(). + Contents of a single position can be changed with setEntity(). + */ + class MapLayer + { + public: + + /*! \brief + The default constructor. + */ + MapLayer(unsigned int rowSize = 0, + unsigned int columnSize = 0, + unsigned int layerNumber = 0, + const QVector<Sub_GameLevel::MapColumn>& layerData = + QVector<Sub_GameLevel::MapColumn>()); + + /*! \brief + Returns the size of a column in layer. + */ + unsigned int getColumnSize() const; + + /*! \brief + Returns the number of rows in a layer. + */ + unsigned int getNumberOfRows() const; + + /*! \brief + Returns the size of a row in layer. + */ + unsigned int getRowSize() const; + + /*! \brief + Returns the number of columns in the layer. + */ + unsigned int getNumberOfColumns() const; + + /*! \brief + Returns the layer number of the layer. + */ + unsigned int getLayerNumber() const; + + /*! \brief + Sets the contents of column pos to column. + */ + void setColumn(unsigned int pos, + const MapColumn& column); + + /*! \brief + Sets the contents of column pos to column. + */ + void setColumn(unsigned int pos, + const QVector<Sub_GameUtility::Identification>& column); + /*! \brief + Returns the ID of the entity at position (column, row). + */ + Sub_GameUtility::Identification + getEntity(unsigned int row, unsigned int column) const; + + /*! \brief + Sets the value of entity at (column, row) to entity. + */ + void setEntity(unsigned int row, unsigned int column, + const Sub_GameUtility::Identification& entity); + /*! \brief + Returns the contents of the column pos as a MapColumn. + */ + MapColumn getColumn(unsigned int pos) const; + + /*! \brief + Changes the size of the layer to rows rows and columns columns. + */ + void resize(unsigned int rows, + unsigned int columns); + + private: + + /*! + Internal layer. + */ + QVector<Sub_GameLevel::MapColumn> m_layer; + + /*! + Size of a row in layer. + */ + unsigned int m_rowSize; + + /*! + Size of a column in layer. + */ + unsigned int m_columnSize; + + /*! + Layer number of the layer. + */ + unsigned int m_layerNumber; + + + + void fitToGreater(unsigned int rows, unsigned int columns); + + void fitToSmaller(unsigned int rows, unsigned int columns); + + /*! \brief + Check class invariant. + */ + void invariant() const; + + }; + +} + +#endif // MAPLAYER_H Modified: trunk/mysventure/include/sub_level/sub_gamelevels.h =================================================================== --- trunk/mysventure/include/sub_level/sub_gamelevels.h 2010-07-26 15:34:19 UTC (rev 77) +++ trunk/mysventure/include/sub_level/sub_gamelevels.h 2010-07-28 13:17:23 UTC (rev 78) @@ -23,6 +23,9 @@ #ifndef SUB_GAMELEVELS_H #define SUB_GAMELEVELS_H +#include "sub_level/mapcolumn.h" +#include "sub_level/maplayer.h" + /*! \brief Contains all identifiers in the levels subsystem. */ Modified: trunk/mysventure/mys-venture.pro =================================================================== --- trunk/mysventure/mys-venture.pro 2010-07-26 15:34:19 UTC (rev 77) +++ trunk/mysventure/mys-venture.pro 2010-07-28 13:17:23 UTC (rev 78) @@ -23,7 +23,9 @@ source/sub_entity/entitystorage.cpp \ source/sub_entity/abstractentitymaker.cpp \ source/sub_entity/basegameentitymaker.cpp \ - source/sub_entity/entitymanager.cpp + source/sub_entity/entitymanager.cpp \ + source/sub_level/mapcolumn.cpp \ + source/sub_level/maplayer.cpp HEADERS += include/sub_view/mainwindow.h \ include/util/Position.h \ include/util/identification.h \ @@ -49,7 +51,9 @@ include/sub_entity/abstractentitymaker.h \ include/sub_entity/basegameentitymaker.h \ include/util/util_functions.h \ - include/sub_entity/entitymanager.h + include/sub_entity/entitymanager.h \ + include/sub_level/mapcolumn.h \ + include/sub_level/maplayer.h FORMS += source/sub_view/mainwindow.ui \ source/sub_view/mapview.ui LIBS += -Llib \ Added: trunk/mysventure/source/sub_level/mapcolumn.cpp =================================================================== --- trunk/mysventure/source/sub_level/mapcolumn.cpp (rev 0) +++ trunk/mysventure/source/sub_level/mapcolumn.cpp 2010-07-28 13:17:23 UTC (rev 78) @@ -0,0 +1,174 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Implementation for class MapColumn. +*/ + +#include "sub_level/mapcolumn.h" + +using Sub_GameUtility::Identification; + +/*! +The size of the column and the column data can be +passed to the default constructor. If the column size and +the size of the passed data are not equal, the column will be +resized to fit columnSize. +*/ +Sub_GameLevel +::MapColumn::MapColumn(unsigned int columnSize, + const QVector<Identification> &columnData) +: m_column(columnData), m_columnSize(columnSize) +{ + if (columnData.size() != m_columnSize) + this->resize(m_columnSize); + + invariant(); +} + + + +/*! +If newSize is smaller than the current column size, +the extra elements are cut off from the end. +If newSize is greater than the current column size, +the end of the column is filled with default values +(invalid IDs). +*/ +void +Sub_GameLevel +::MapColumn::resize(unsigned int newSize) +{ + invariant(); + // If newSize is the same as existing size, do nothing. + if (newSize == m_columnSize) + return; + + if (newSize > m_columnSize) + fitToGreater(newSize); + else if (newSize < m_columnSize) + fitToSmaller(newSize); + + invariant(); +} + + + +unsigned int +Sub_GameLevel +::MapColumn::getColumnSize() const +{ + invariant(); + + return m_columnSize; +} + + +unsigned int +Sub_GameLevel +::MapColumn::getNumberOfRows() const +{ + invariant(); + + return m_columnSize; +} + + + +Sub_GameUtility::Identification +Sub_GameLevel +::MapColumn::getEntity(unsigned int columnPos) const +{ + invariant(); + Q_ASSERT(columnPos < m_columnSize); + + return m_column.at(columnPos); +} + + + +void +Sub_GameLevel +::MapColumn::setEntity(unsigned int columnPos, const Identification &entity) +{ + invariant(); + Q_ASSERT(columnPos < m_columnSize); + + m_column[columnPos] = entity; +} + + + +Sub_GameUtility::Identification& +Sub_GameLevel +::MapColumn::operator[](unsigned int columnPos) +{ + invariant(); + Q_ASSERT(columnPos < m_columnSize); + + return m_column[columnPos]; +} + + +const Sub_GameUtility::Identification& +Sub_GameLevel +::MapColumn::operator [](unsigned int columnPos) const +{ + invariant(); + Q_ASSERT(columnPos < m_columnSize); + + return m_column[columnPos]; +} + + + +void +Sub_GameLevel +::MapColumn::fitToGreater(unsigned int newSize) +{ + Q_ASSERT(newSize > m_columnSize); + + for (int i = m_columnSize; i < newSize; ++i) + { + m_column.push_back(Identification::invalidId()); + } + + Q_ASSERT(newSize == m_column.size()); +} + + + +void +Sub_GameLevel +::MapColumn::fitToSmaller(unsigned int newSize) +{ + Q_ASSERT(newSize < m_columnSize); + + m_column.resize(newSize); + + Q_ASSERT(m_column.size() == newSize); +} + + + +void +Sub_GameLevel +::MapColumn::invariant() const +{ + Q_ASSERT(m_columnSize == m_column.size()); +} Added: trunk/mysventure/source/sub_level/maplayer.cpp =================================================================== --- trunk/mysventure/source/sub_level/maplayer.cpp (rev 0) +++ trunk/mysventure/source/sub_level/maplayer.cpp 2010-07-28 13:17:23 UTC (rev 78) @@ -0,0 +1,237 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Implementation for class MapLayer. +*/ + +#include "sub_level/maplayer.h" + +using namespace Sub_GameLevel; + + + +Sub_GameLevel +::MapLayer::MapLayer(unsigned int rowSize, + unsigned int columnSize, + unsigned int layerNumber, + const QVector<Sub_GameLevel::MapColumn> &layerData) +: m_layer(layerData), m_rowSize(rowSize), m_columnSize(columnSize), + m_layerNumber(layerNumber) +{ + resize(columnSize, rowSize); + + invariant(); +} + + + +unsigned int +Sub_GameLevel +::MapLayer::getColumnSize() const +{ + return m_columnSize; +} + + + +unsigned int +Sub_GameLevel +::MapLayer::getNumberOfRows() const +{ + return m_columnSize; +} + + + +unsigned int +Sub_GameLevel +::MapLayer::getRowSize() const +{ + return m_rowSize; +} + + +unsigned int +Sub_GameLevel +::MapLayer::getNumberOfColumns() const +{ + return m_rowSize; +} + + + +unsigned int +Sub_GameLevel +::MapLayer::getLayerNumber() const +{ + return m_layerNumber; +} + + + +void +Sub_GameLevel +::MapLayer::setColumn(unsigned int pos, const MapColumn &column) +{ + invariant(); + Q_ASSERT(pos < m_rowSize); + + // Replace column. + m_layer[pos] = column; + + // Make sure column is of correct size. + m_layer[pos].resize(m_columnSize); + + invariant(); +} + + + +void +Sub_GameLevel +::MapLayer::setColumn(unsigned int pos, + const QVector<Sub_GameUtility::Identification> &column) +{ + MapColumn newColumn(m_columnSize, column); + setColumn(pos, column); +} + + + +Sub_GameUtility::Identification +Sub_GameLevel +::MapLayer::getEntity(unsigned int row, unsigned int column) const +{ + invariant(); + Q_ASSERT(row < m_columnSize); + Q_ASSERT(column < m_rowSize); + + return m_layer.at(column).getEntity(row); +} + + + +void +Sub_GameLevel +::MapLayer::setEntity(unsigned int row, + unsigned int column, + const Sub_GameUtility::Identification &entity) +{ + invariant(); + Q_ASSERT(row < m_columnSize); + Q_ASSERT(column < m_rowSize); + + m_layer[column].setEntity(row, entity); +} + + + +Sub_GameLevel::MapColumn +Sub_GameLevel +::MapLayer::getColumn(unsigned int pos) const +{ + invariant(); + Q_ASSERT(pos < m_rowSize); + + return m_layer.at(pos); +} + + + +void +Sub_GameLevel +::MapLayer::resize(unsigned int rows, unsigned int columns) +{ + invariant(); + Q_ASSERT(rows < m_columnSize); + Q_ASSERT(columns < m_rowSize); + + if (columns > m_rowSize) + fitToGreater(rows, columns); + else if (columns < m_rowSize) + fitToSmaller(rows, columns); + + invariant(); +} + + +/*! +Fits the layer to a greater number of columns. +This is performed by adding default-constructed columns to +the end of the layer. +*/ +void +Sub_GameLevel +::MapLayer::fitToGreater(unsigned int rows, unsigned int columns) +{ + // Create default column data. + QVector<Sub_GameUtility::Identification> columnData( + m_columnSize, Sub_GameUtility::Identification::invalidId()); + + // Create default new column. + MapColumn newColumn(m_columnSize, columnData); + + // Loop from current max rows to the new max rows + // and append a default column each time. + for (int i = m_rowSize; i < columns; ++i) + { + m_layer.push_back(newColumn); + + // After appending a default column, resize the column. + m_layer[i].resize(rows); + } + + // Then set sizes. + m_columnSize = rows; + m_rowSize = columns; + + invariant(); +} + + +/*! +Fits the layer to a smaller number of columns. +This is performed by cutting the surplus columns off the +end of the layer. +*/ +void +Sub_GameLevel +::MapLayer::fitToSmaller(unsigned int rows, unsigned int columns) +{ + m_layer.resize(columns); + + for (int i = 0; i < m_layer.size(); ++i) + { + m_layer[i].resize(rows); + } + + m_columnSize = rows; + m_rowSize = columns; + + invariant(); +} + + + +void +Sub_GameLevel +::MapLayer::invariant() const +{ + Q_ASSERT(m_layer.size() == m_rowSize); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-26 15:34:26
|
Revision: 77 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=77&view=rev Author: kimmovii Date: 2010-07-26 15:34:19 +0000 (Mon, 26 Jul 2010) Log Message: ----------- Implemented test for AbstractEntityMaker to test maker registry. Added Paths: ----------- trunk/mysventure/test/sub_entity/testabstractentitymaker/ trunk/mysventure/test/sub_entity/testabstractentitymaker/test.cpp trunk/mysventure/test/sub_entity/testabstractentitymaker/testabstractentitymaker.pro trunk/mysventure/test/sub_entity/testbasegameentity/testbasegameentity.pro Added: trunk/mysventure/test/sub_entity/testabstractentitymaker/test.cpp =================================================================== --- trunk/mysventure/test/sub_entity/testabstractentitymaker/test.cpp (rev 0) +++ trunk/mysventure/test/sub_entity/testabstractentitymaker/test.cpp 2010-07-26 15:34:19 UTC (rev 77) @@ -0,0 +1,148 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <QtCore/QString> +#include <QtTest/QtTest> + +#include "sub_entity/abstractentitymaker.h" + +using namespace Sub_GameEntities; + +class Testabstractentitymaker : public QObject +{ + Q_OBJECT + +public: + Testabstractentitymaker(); + +private Q_SLOTS: + + void initTestCase(); + void cleanupTestCase(); + + /*! \brief + Tests maker registry of AbstractEntityMaker. + */ + void testMakerRegistry(); +}; + + + +/*! \brief +A dummy maker used for testing. +*/ +class DummyMaker : public AbstractEntityMaker +{ +public: + + DummyMaker() + { + registerMaker("Dummy", &m_maker); + } + + /*! \brief + A dummy implementation. + */ + virtual BaseGameEntity* create(const QHash<QString, QString> &entityParams, + const Sub_GameUtility::Identification &entityId) + { return 0; } + +private: + + static DummyMaker m_maker; +}; + +DummyMaker DummyMaker::m_maker; + +/*! \brief +A dummy maker used for testing. +*/ +class AnotherDummyMaker : public AbstractEntityMaker +{ +public: + + AnotherDummyMaker() + { + registerMaker("AnotherDummy", &m_maker); + } + + /*! \brief + A dummy implementation. + */ + virtual BaseGameEntity* create(const QHash<QString, QString> &entityParams, + const Sub_GameUtility::Identification &entityId) + { return 0; } + +private: + + static AnotherDummyMaker m_maker; +}; + +AnotherDummyMaker AnotherDummyMaker::m_maker; + + +Testabstractentitymaker::Testabstractentitymaker() +{ +} + +void Testabstractentitymaker::initTestCase() +{ +} + +void Testabstractentitymaker::cleanupTestCase() +{ +} + +/*! +The test plan is as follows. + +- At startup DummyMaker and AnotherDummyMaker will +register themselves with AbstractEntityMaker. Ensure +the registration was succesful by calling getMaker() for +both. +- Create some dummy instances of DummyMaker and +AnotherDummyMaker. Delete these instances and ensure the +registry still contains the valid static instances. +*/ +void Testabstractentitymaker::testMakerRegistry() +{ + // Make sure DummyMaker is registered. + QVERIFY(AbstractEntityMaker::getMaker("Dummy") != 0); + + // Maker sure AnotherDummyMaker is registered. + QVERIFY(AbstractEntityMaker::getMaker("AnotherDummy") != 0); + + // Get pointers to makers. + AbstractEntityMaker* dummy = AbstractEntityMaker::getMaker("Dummy"); + AbstractEntityMaker* anotherDummy = AbstractEntityMaker::getMaker("AnotherDummy"); + + // Create some new maker instances dynamically. + AbstractEntityMaker* new1 = new DummyMaker; + AbstractEntityMaker* new2 = new DummyMaker; + AbstractEntityMaker* new3 = new AnotherDummyMaker; + AbstractEntityMaker* new4 = new AnotherDummyMaker; + + delete new1; delete new2; delete new3; delete new4; + + QVERIFY(AbstractEntityMaker::getMaker("Dummy") == dummy); + QVERIFY(AbstractEntityMaker::getMaker("AnotherDummy") == anotherDummy); +} + +QTEST_MAIN(Testabstractentitymaker); + +#include "test.moc" Added: trunk/mysventure/test/sub_entity/testabstractentitymaker/testabstractentitymaker.pro =================================================================== --- trunk/mysventure/test/sub_entity/testabstractentitymaker/testabstractentitymaker.pro (rev 0) +++ trunk/mysventure/test/sub_entity/testabstractentitymaker/testabstractentitymaker.pro 2010-07-26 15:34:19 UTC (rev 77) @@ -0,0 +1,21 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-07-26T17:41:08 +# +#------------------------------------------------- + +QT += testlib + +QT -= gui + +TARGET = test +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + + +SOURCES += test.cpp \ + ../../../source/sub_entity/abstractentitymaker.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" +INCLUDEPATH += ../../../include Added: trunk/mysventure/test/sub_entity/testbasegameentity/testbasegameentity.pro =================================================================== --- trunk/mysventure/test/sub_entity/testbasegameentity/testbasegameentity.pro (rev 0) +++ trunk/mysventure/test/sub_entity/testbasegameentity/testbasegameentity.pro 2010-07-26 15:34:19 UTC (rev 77) @@ -0,0 +1,7 @@ +CONFIG += qtestlib +INCLUDEPATH += ../../../include +SOURCES += test.cpp \ + ../../../source/sub_entity/basegameentity.cpp \ + ../../../source/util/identification.cpp \ + ../../../source/util/Position.cpp +HEADERS += ../../../include/sub_entity/basegameentity.h This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-26 13:05:38
|
Revision: 76 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=76&view=rev Author: kimmovii Date: 2010-07-26 13:05:32 +0000 (Mon, 26 Jul 2010) Log Message: ----------- Modified Paths: -------------- trunk/design/game/technical_design.odt trunk/mysventure/source/sub_entity/basegameentitymaker.cpp Modified: trunk/design/game/technical_design.odt =================================================================== (Binary files differ) Modified: trunk/mysventure/source/sub_entity/basegameentitymaker.cpp =================================================================== --- trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-07-26 13:04:42 UTC (rev 75) +++ trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-07-26 13:05:32 UTC (rev 76) @@ -49,28 +49,50 @@ /*! Creates a new BaseGameEntity with the ID entityId and the data values extracted from entityParams. + +The parameters passed to create() must contain all the parameters +needed to construct the entity. If parameters are missing, 0 +is returned. */ BaseGameEntity* Sub_GameEntities ::BaseGameEntityMaker::create(const QHash<QString, QString> &entityParams, const Identification& entityId) { - bool success = false; + bool success = true; // Retrieve the entity position information. + QString xPosString = entityParams.value("xposition"); + QString yPosString = entityParams.value("yposition"); + QString layerString = entityParams.value("layer"); + + // Retrieve image path. + QString imagePath = entityParams.value("image"); + + // If some of these parameters is missing, return 0. + if (xPosString.isEmpty() + || yPosString.isEmpty() + || layerString.isEmpty() + || imagePath.isEmpty()) + return 0; + unsigned int xPos = - convert<unsigned int>(entityParams.value("xposition").toStdString(), success); + xPosString.toUInt(&success, 10); unsigned int yPos = - convert<unsigned int>(entityParams.value("yposition").toStdString(), success); + yPosString.toUInt(&success, 10); unsigned int layer = - convert<unsigned int>(entityParams.value("layer").toStdString(), success); + layerString.toUInt(&success, 10); + // If there was error during conversions, return 0. + if (!success) + return 0; + Position entityPos(xPos, yPos, layer); BaseGameEntity* entity = new BaseGameEntity(entityId, entityPos, - entityParams.value("image")); + imagePath); return entity; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-26 13:04:50
|
Revision: 75 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=75&view=rev Author: kimmovii Date: 2010-07-26 13:04:42 +0000 (Mon, 26 Jul 2010) Log Message: ----------- Extended test for BaseGameEntityMaker. Modified Paths: -------------- trunk/mysventure/test/sub_entity/testbasegameentitymaker/test.cpp Modified: trunk/mysventure/test/sub_entity/testbasegameentitymaker/test.cpp =================================================================== --- trunk/mysventure/test/sub_entity/testbasegameentitymaker/test.cpp 2010-07-25 19:41:48 UTC (rev 74) +++ trunk/mysventure/test/sub_entity/testbasegameentitymaker/test.cpp 2010-07-26 13:04:42 UTC (rev 75) @@ -37,9 +37,15 @@ private Q_SLOTS: + /*! \brief + Tests basic usage. + */ void testCreate(); -// void testCreateIncomplete(); + /*! \brief + Attemps to create an entity using incomplete parameter list. + */ + void testCreateIncomplete(); }; Testbasegameentitymaker::Testbasegameentitymaker() @@ -85,7 +91,28 @@ } +void Testbasegameentitymaker::testCreateIncomplete() +{ + QHash<QString, QString> entityParams; + // Insert position information + entityParams.insert("xposition", "100"); + entityParams.insert("yposition", "43"); + entityParams.insert("layer", "2"); + + // Leave image info out of parameters. + + Identification id; + + BaseGameEntityMaker maker; + + BaseGameEntity* newEntity = + maker.create(entityParams, id); + + // Entity should be 0. + QVERIFY(newEntity == 0); +} + QTEST_MAIN(Testbasegameentitymaker); #include "test.moc" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-25 19:41:55
|
Revision: 74 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=74&view=rev Author: kimmovii Date: 2010-07-25 19:41:48 +0000 (Sun, 25 Jul 2010) Log Message: ----------- Implemented incomplete test for BaseGameEntityMaker. The test passed. Modified Paths: -------------- trunk/design/game/technical_design.odt trunk/mysventure/include/sub_entity/basegameentity.h trunk/mysventure/include/sub_entity/basegameentitymaker.h trunk/mysventure/source/sub_entity/basegameentitymaker.cpp Added Paths: ----------- trunk/mysventure/test/sub_entity/testbasegameentitymaker/ trunk/mysventure/test/sub_entity/testbasegameentitymaker/test.cpp trunk/mysventure/test/sub_entity/testbasegameentitymaker/testbasegameentitymaker.pro Modified: trunk/design/game/technical_design.odt =================================================================== (Binary files differ) Modified: trunk/mysventure/include/sub_entity/basegameentity.h =================================================================== --- trunk/mysventure/include/sub_entity/basegameentity.h 2010-07-25 11:30:44 UTC (rev 73) +++ trunk/mysventure/include/sub_entity/basegameentity.h 2010-07-25 19:41:48 UTC (rev 74) @@ -56,6 +56,8 @@ const QPixmap& image = QPixmap()); + public slots: + /*! \brief Moves the entity by the amount specified in parameters. */ @@ -81,8 +83,8 @@ */ void moveDown(unsigned int amount = 1); + public: - /*! \brief Returns the entity's ID. */ Modified: trunk/mysventure/include/sub_entity/basegameentitymaker.h =================================================================== --- trunk/mysventure/include/sub_entity/basegameentitymaker.h 2010-07-25 11:30:44 UTC (rev 73) +++ trunk/mysventure/include/sub_entity/basegameentitymaker.h 2010-07-25 19:41:48 UTC (rev 74) @@ -51,7 +51,7 @@ /*! \brief Returns a pointer to a new BaseGameEntity instance. */ - virtual BaseGameEntity* + virtual Sub_GameEntities::BaseGameEntity* create(const QHash<QString, QString>& entityParams, const Sub_GameUtility::Identification& entityId); Modified: trunk/mysventure/source/sub_entity/basegameentitymaker.cpp =================================================================== --- trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-07-25 11:30:44 UTC (rev 73) +++ trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-07-25 19:41:48 UTC (rev 74) @@ -52,10 +52,11 @@ */ BaseGameEntity* Sub_GameEntities -::BaseGameEntityMaker::create(QHash<QString, QString> &entityParams, +::BaseGameEntityMaker::create(const QHash<QString, QString> &entityParams, const Identification& entityId) { bool success = false; + // Retrieve the entity position information. unsigned int xPos = convert<unsigned int>(entityParams.value("xposition").toStdString(), success); Added: trunk/mysventure/test/sub_entity/testbasegameentitymaker/test.cpp =================================================================== --- trunk/mysventure/test/sub_entity/testbasegameentitymaker/test.cpp (rev 0) +++ trunk/mysventure/test/sub_entity/testbasegameentitymaker/test.cpp 2010-07-25 19:41:48 UTC (rev 74) @@ -0,0 +1,91 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <QtCore/QString> +#include <QtTest/QtTest> +#include <QHash> +#include <QPixmap> + +#include "sub_entity/basegameentity.h" +#include "sub_entity/basegameentitymaker.h" +#include "util/identification.h" + +using namespace Sub_GameEntities; +using namespace Sub_GameUtility; + +class Testbasegameentitymaker : public QObject +{ + Q_OBJECT + +public: + Testbasegameentitymaker(); + +private Q_SLOTS: + + void testCreate(); + +// void testCreateIncomplete(); +}; + +Testbasegameentitymaker::Testbasegameentitymaker() +{ +} + + + +void Testbasegameentitymaker::testCreate() +{ + // Create entity parameters + QHash<QString, QString> entityParams; + + // Insert position information + entityParams.insert("xposition", "10"); + entityParams.insert("yposition", "20"); + entityParams.insert("layer", "1"); + + // Insert image info. The value for image is just a dummy value. + entityParams.insert("image", "d:/image.png"); + + // Create ID for entity. + Identification id; + + BaseGameEntityMaker maker; + // Create a new entity. + BaseGameEntity* newEntity = + maker.create(entityParams, id); + + // Assert the created entity has the specified parameters. + QCOMPARE(newEntity->getId(), id); + + /*! \todo + How to compare images? + */ + + QCOMPARE(newEntity->getPosition().getXPosition(), static_cast<unsigned int>(10)); + QCOMPARE(newEntity->getPosition().getYPosition(), static_cast<unsigned int>(20)); + QCOMPARE(newEntity->getPosition().getLayer(), static_cast<unsigned int>(1)); + + // delete entity + delete newEntity; +} + + + +QTEST_MAIN(Testbasegameentitymaker); + +#include "test.moc" Added: trunk/mysventure/test/sub_entity/testbasegameentitymaker/testbasegameentitymaker.pro =================================================================== --- trunk/mysventure/test/sub_entity/testbasegameentitymaker/testbasegameentitymaker.pro (rev 0) +++ trunk/mysventure/test/sub_entity/testbasegameentitymaker/testbasegameentitymaker.pro 2010-07-25 19:41:48 UTC (rev 74) @@ -0,0 +1,30 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-07-25T20:57:24 +# +#------------------------------------------------- + +QT += testlib + +#QT -= gui + +TARGET = test +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + + +SOURCES += test.cpp \ + ../../../source/sub_entity/basegameentitymaker.cpp \ + ../../../source/sub_entity/basegameentity.cpp \ + ../../../source/util/identification.cpp \ + ../../../source/sub_entity/abstractentitymaker.cpp \ + ../../../source/util/Position.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" + +HEADERS += \ + ../../../include/sub_entity/basegameentitymaker.h \ + ../../../include/sub_entity/basegameentity.h + +INCLUDEPATH += ../../../include This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-25 11:30:50
|
Revision: 73 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=73&view=rev Author: kimmovii Date: 2010-07-25 11:30:44 +0000 (Sun, 25 Jul 2010) Log Message: ----------- Implemented EntityManager. Untested. Modified Paths: -------------- trunk/mysventure/include/sub_entity/abstractentitymaker.h trunk/mysventure/include/sub_entity/basegameentitymaker.h trunk/mysventure/include/sub_entity/sub_gameentities.h trunk/mysventure/mys-venture.pro trunk/mysventure/source/sub_entity/basegameentitymaker.cpp Added Paths: ----------- trunk/mysventure/include/sub_entity/entitymanager.h trunk/mysventure/source/sub_entity/entitymanager.cpp Modified: trunk/mysventure/include/sub_entity/abstractentitymaker.h =================================================================== --- trunk/mysventure/include/sub_entity/abstractentitymaker.h 2010-07-24 19:58:49 UTC (rev 72) +++ trunk/mysventure/include/sub_entity/abstractentitymaker.h 2010-07-25 11:30:44 UTC (rev 73) @@ -69,7 +69,7 @@ /*! This method must be implemented by subclasses. */ - virtual BaseGameEntity* create(QHash<QString, QString>& entityParams, + virtual BaseGameEntity* create(const QHash<QString, QString>& entityParams, const Sub_GameUtility::Identification& entityId) = 0; /*! \brief Modified: trunk/mysventure/include/sub_entity/basegameentitymaker.h =================================================================== --- trunk/mysventure/include/sub_entity/basegameentitymaker.h 2010-07-24 19:58:49 UTC (rev 72) +++ trunk/mysventure/include/sub_entity/basegameentitymaker.h 2010-07-25 11:30:44 UTC (rev 73) @@ -42,6 +42,9 @@ { public: + /*! \brief + Default constructor. + */ BaseGameEntityMaker(); virtual ~BaseGameEntityMaker() {} @@ -49,7 +52,7 @@ Returns a pointer to a new BaseGameEntity instance. */ virtual BaseGameEntity* - create(QHash<QString, QString>& entityParams, + create(const QHash<QString, QString>& entityParams, const Sub_GameUtility::Identification& entityId); private: Added: trunk/mysventure/include/sub_entity/entitymanager.h =================================================================== --- trunk/mysventure/include/sub_entity/entitymanager.h (rev 0) +++ trunk/mysventure/include/sub_entity/entitymanager.h 2010-07-25 11:30:44 UTC (rev 73) @@ -0,0 +1,102 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Declaration for class EntityManager. +*/ + +#ifndef ENTITYMANAGER_H +#define ENTITYMANAGER_H + +#include <QHash> +#include <QString> +#include <QSharedPointer> + +#include "util/identification.h" +#include "util/identificationgenerator.h" +#include "sub_entity/entitystorage.h" +#include "sub_entity/basegameentity.h" +#include "sub_entity/basegameentitymaker.h" + + + +namespace Sub_GameEntities +{ + + /*! \brief + EntityManager creates, destroys and stores game entities. + */ + /*! + An entity can be created using the create() method. An entity can + be destroyed using the destroy() method. + + A (smart) pointer to the created entity can be retrieved using + getEntity(). If needed, it is possible to check for the existence + of an entity based on an ID. + */ + class EntityManager + { + public: + /*! + Typedef for the type of the entity ID. + */ + typedef Sub_GameUtility::Identification EntityIdType; + public: + + /*! \brief + Creates an entity of type entityType with parameters + entityParams. + */ + EntityIdType + create(const QHash<QString, QString>& entityParams, + const QString& entityType); + + /*! \brief + Destroys the entity with ID entityId. + */ + bool destroy(const EntityIdType& entityId); + + /*! \brief + Returns a pointer to the entity with the ID entityId. + */ + BaseGameEntity* + getEntity(const EntityIdType& entityId) const; + + /*! \brief + Returns true if an entity with ID entityId exists + in the manager's storage. + */ + bool contains(const EntityIdType& entityId) const; + + private: + + /*! + Stores the created entities. + */ + Sub_GameEntities::EntityStorage m_entityStorage; + + /*! + The ID generator instance used by the manager. + */ + Sub_GameUtility::IdentificationGenerator m_idCreator; + + }; // class EntityManager + +} // namespace Sub_GameEntities + +#endif // ENTITYMANAGER_H Modified: trunk/mysventure/include/sub_entity/sub_gameentities.h =================================================================== --- trunk/mysventure/include/sub_entity/sub_gameentities.h 2010-07-24 19:58:49 UTC (rev 72) +++ trunk/mysventure/include/sub_entity/sub_gameentities.h 2010-07-25 11:30:44 UTC (rev 73) @@ -28,6 +28,7 @@ #include "sub_entity/basegameentity.h" #include "sub_entity/entitystorage.h" #include "sub_entity/abstractentitymaker.h" +#include "sub_entity/entitymanager.h" /*! \brief Contains all identifiers of the entity subsystem. Modified: trunk/mysventure/mys-venture.pro =================================================================== --- trunk/mysventure/mys-venture.pro 2010-07-24 19:58:49 UTC (rev 72) +++ trunk/mysventure/mys-venture.pro 2010-07-25 11:30:44 UTC (rev 73) @@ -22,7 +22,8 @@ source/sub_entity/basegameentity.cpp \ source/sub_entity/entitystorage.cpp \ source/sub_entity/abstractentitymaker.cpp \ - source/sub_entity/basegameentitymaker.cpp + source/sub_entity/basegameentitymaker.cpp \ + source/sub_entity/entitymanager.cpp HEADERS += include/sub_view/mainwindow.h \ include/util/Position.h \ include/util/identification.h \ @@ -47,7 +48,8 @@ include/sub_entity/entitystorage.h \ include/sub_entity/abstractentitymaker.h \ include/sub_entity/basegameentitymaker.h \ - include/util/util_functions.h + include/util/util_functions.h \ + include/sub_entity/entitymanager.h FORMS += source/sub_view/mainwindow.ui \ source/sub_view/mapview.ui LIBS += -Llib \ Modified: trunk/mysventure/source/sub_entity/basegameentitymaker.cpp =================================================================== --- trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-07-24 19:58:49 UTC (rev 72) +++ trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-07-25 11:30:44 UTC (rev 73) @@ -34,6 +34,10 @@ +/*! +Registers the created maker instance with the +maker registry. +*/ Sub_GameEntities ::BaseGameEntityMaker::BaseGameEntityMaker() { @@ -41,6 +45,11 @@ } + +/*! +Creates a new BaseGameEntity with the ID entityId +and the data values extracted from entityParams. +*/ BaseGameEntity* Sub_GameEntities ::BaseGameEntityMaker::create(QHash<QString, QString> &entityParams, Added: trunk/mysventure/source/sub_entity/entitymanager.cpp =================================================================== --- trunk/mysventure/source/sub_entity/entitymanager.cpp (rev 0) +++ trunk/mysventure/source/sub_entity/entitymanager.cpp 2010-07-25 11:30:44 UTC (rev 73) @@ -0,0 +1,111 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Implementation for class EntityManager. +*/ + +#include "sub_entity/entitymanager.h" + +using namespace Sub_GameEntities; +using namespace Sub_GameUtility; + + + +/*! +If no maker for the given entity type is found, an invalid ID +is returned. +*/ +EntityManager::EntityIdType +Sub_GameEntities +::EntityManager::create(const QHash<QString, QString> &entityParams, + const QString &entityType) +{ + // Get maker for entityType. + AbstractEntityMaker* + entityMaker = AbstractEntityMaker::getMaker(entityType); + + // If such a maker was not found, return an invalid ID. + if (entityMaker == 0) + return Identification::invalidId(); + + // Generate an ID for the new entity. + const EntityIdType entityId = m_idCreator.create(); + + // Create the new entity from entityParams and the new ID. + BaseGameEntity* newEntity = + entityMaker->create(entityParams, entityId); + + // Assert that the entity ID is the same as the generated. + Q_ASSERT(entityId == newEntity->getId()); + + // Give ownership of new entity to a shared pointer to automate + // memory management. + QSharedPointer<BaseGameEntity> entityPointer(newEntity); + + // Insert entity into storage. + this->m_entityStorage.add(entityId, entityPointer); + + // Return the ID of the new entity. + return entityId; +} + + + +/*! +Returns true if the entity was succesfully removed, +false otherwise. +*/ +bool +Sub_GameEntities +::EntityManager::destroy(const EntityIdType &entityId) +{ + // Remove the entity from storage. + bool removed = m_entityStorage.remove(entityId); + + Q_ASSERT(!(m_entityStorage.contains(entityId))); + + return removed; +} + + + +/*! +If the entity is not found in storage, 0 is returned. +*/ +BaseGameEntity* +Sub_GameEntities +::EntityManager::getEntity(const EntityIdType &entityId) const +{ + BaseGameEntity* ret = + m_entityStorage.getEntity(entityId).data(); + + if (!ret) + Q_ASSERT(!(m_entityStorage.contains(entityId))); + + return ret; +} + + + +bool +Sub_GameEntities +::EntityManager::contains(const EntityIdType &entityId) const +{ + return m_entityStorage.contains(entityId); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-24 19:58:55
|
Revision: 72 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=72&view=rev Author: kimmovii Date: 2010-07-24 19:58:49 +0000 (Sat, 24 Jul 2010) Log Message: ----------- Changed design. Implemented a template type conversion function Sub_GameUtility::convert, the reason being the boost::lexical_cast is so hard to distribute. Implemented AbstractEntityMaker and BaseGameEntityMaker. Not tested yet. Modified Paths: -------------- trunk/design/game/technical_design.odt trunk/mysventure/include/sub_entity/sub_gameentities.h trunk/mysventure/mys-venture.pro Added Paths: ----------- trunk/mysventure/include/sub_entity/abstractentitymaker.h trunk/mysventure/include/sub_entity/basegameentitymaker.h trunk/mysventure/include/util/util_functions.h trunk/mysventure/source/sub_entity/abstractentitymaker.cpp trunk/mysventure/source/sub_entity/basegameentitymaker.cpp Modified: trunk/design/game/technical_design.odt =================================================================== (Binary files differ) Added: trunk/mysventure/include/sub_entity/abstractentitymaker.h =================================================================== --- trunk/mysventure/include/sub_entity/abstractentitymaker.h (rev 0) +++ trunk/mysventure/include/sub_entity/abstractentitymaker.h 2010-07-24 19:58:49 UTC (rev 72) @@ -0,0 +1,98 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Declaration for class AbstractEntityMaker. +*/ + +#ifndef ABSTRACTENTITYMAKER_H +#define ABSTRACTENTITYMAKER_H + +#include <QHash> +#include "util/identification.h" + +class QString; + + + +namespace Sub_GameEntities +{ + class BaseGameEntity; + + /*! \brief + AbstractEntityMaker is the base class for all entity makers. + */ + /*! + AbstractEntityMaker is an abstract base class. It defines a common + interface for all concrete entity makers for creating entities. + + To work in the same hiearchy with AbstractEntityMaker, the derived + makers must follow these steps: + + 1. Implement the pure virtual create(QHash<QString, QString>& entityParams) + method. + 2. Have a static instance of the class itself. + 3. Register the static instance in the class constructor with + registerMaker(const QString& entityType, AbstractEntityMaker* maker). + + A maker can be queried using the static method getMaker(), which + takes as argument the name of the class for which a maker is + desired. + */ + class AbstractEntityMaker + { + public: + + /*! \brief + Virtual destructor. + */ + virtual ~AbstractEntityMaker() {} + + /*! \brief + Creates a new entity and returns a pointer to it. Pure virtual. + */ + /*! + This method must be implemented by subclasses. + */ + virtual BaseGameEntity* create(QHash<QString, QString>& entityParams, + const Sub_GameUtility::Identification& entityId) = 0; + + /*! \brief + Returns a pointer to the maker capable of creating EntityType objects. + */ + static AbstractEntityMaker* getMaker(const QString& entityType); + + protected: + + /*! \brief + Registers a maker for type entityType in the registry. + */ + static bool registerMaker(const QString& entityType, + AbstractEntityMaker* maker); + + private: + + /*! + Returns a pointer to the static maker registry. + */ + static QHash<QString, AbstractEntityMaker*>* + getRegistry(); + }; + +} // namespace Sub_Entities +#endif // ABSTRACTENTITYMAKER_H Added: trunk/mysventure/include/sub_entity/basegameentitymaker.h =================================================================== --- trunk/mysventure/include/sub_entity/basegameentitymaker.h (rev 0) +++ trunk/mysventure/include/sub_entity/basegameentitymaker.h 2010-07-24 19:58:49 UTC (rev 72) @@ -0,0 +1,66 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef BASEGAMEENTITYMAKER_H +#define BASEGAMEENTITYMAKER_H + +#include "sub_entity/abstractentitymaker.h" +#include "util/identification.h" + + +namespace Sub_GameEntities +{ + + /*! \brief + Creates BaseGameEntity instances. + */ + /*! + Part of the "entity factory pattern." + + Entity parameter keys used by the maker are: + - xposition: the x position of the entity on map. + - yposition: the y position of the entity on map. + - layer: the layer of the entity on map. + - image: the image of the entity. + */ + class BaseGameEntityMaker : public AbstractEntityMaker + { + public: + + BaseGameEntityMaker(); + virtual ~BaseGameEntityMaker() {} + + /*! \brief + Returns a pointer to a new BaseGameEntity instance. + */ + virtual BaseGameEntity* + create(QHash<QString, QString>& entityParams, + const Sub_GameUtility::Identification& entityId); + + private: + + /*! + Static maker instance as required by AbstractEntityMaker. + */ + static BaseGameEntityMaker m_maker; + }; + +} // namespace Sub_GameEntities + +#endif // BASEGAMEENTITYMAKER_H + Modified: trunk/mysventure/include/sub_entity/sub_gameentities.h =================================================================== --- trunk/mysventure/include/sub_entity/sub_gameentities.h 2010-07-23 19:28:30 UTC (rev 71) +++ trunk/mysventure/include/sub_entity/sub_gameentities.h 2010-07-24 19:58:49 UTC (rev 72) @@ -27,6 +27,7 @@ #include "sub_entity/basegameentity.h" #include "sub_entity/entitystorage.h" +#include "sub_entity/abstractentitymaker.h" /*! \brief Contains all identifiers of the entity subsystem. Added: trunk/mysventure/include/util/util_functions.h =================================================================== --- trunk/mysventure/include/util/util_functions.h (rev 0) +++ trunk/mysventure/include/util/util_functions.h 2010-07-24 19:58:49 UTC (rev 72) @@ -0,0 +1,50 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Defines utility functions used by the application. +*/ + +#include <sstream> + +namespace Sub_GameUtility +{ + + /*! \brief + Convert an object of from_type to an object of to_type. + */ + /*! + The types being converted must support operator<<() and + operator>>(). + */ + template <typename to_type, typename from_type> + to_type convert(const from_type& source, bool& success) + { + success = false; + std::stringstream temp; + to_type ret; + temp << source; + temp >> ret; + + // The function can fail, but we don't care about that now. + success = true; + return ret; + } + + +} Modified: trunk/mysventure/mys-venture.pro =================================================================== --- trunk/mysventure/mys-venture.pro 2010-07-23 19:28:30 UTC (rev 71) +++ trunk/mysventure/mys-venture.pro 2010-07-24 19:58:49 UTC (rev 72) @@ -20,7 +20,9 @@ source/sub_view/mapview.cpp \ source/sub_view/mapdrawer.cpp \ source/sub_entity/basegameentity.cpp \ - source/sub_entity/entitystorage.cpp + source/sub_entity/entitystorage.cpp \ + source/sub_entity/abstractentitymaker.cpp \ + source/sub_entity/basegameentitymaker.cpp HEADERS += include/sub_view/mainwindow.h \ include/util/Position.h \ include/util/identification.h \ @@ -42,7 +44,10 @@ include/sub_level/sub_gamelevels.h \ include/util/sub_gameutility.h \ include/sub_entity/basegameentity.h \ - include/sub_entity/entitystorage.h + include/sub_entity/entitystorage.h \ + include/sub_entity/abstractentitymaker.h \ + include/sub_entity/basegameentitymaker.h \ + include/util/util_functions.h FORMS += source/sub_view/mainwindow.ui \ source/sub_view/mapview.ui LIBS += -Llib \ Added: trunk/mysventure/source/sub_entity/abstractentitymaker.cpp =================================================================== --- trunk/mysventure/source/sub_entity/abstractentitymaker.cpp (rev 0) +++ trunk/mysventure/source/sub_entity/abstractentitymaker.cpp 2010-07-24 19:58:49 UTC (rev 72) @@ -0,0 +1,77 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Implementation for class AbstractEntityMaker. +*/ + +#include <QString> + +#include "sub_entity/abstractentitymaker.h" + +using Sub_GameEntities::AbstractEntityMaker; +using Sub_GameEntities::BaseGameEntity; + + + +/*! +If no maker for the given class is found, 0 returned. +Otherwise a pointer to a correct maker is returned. +*/ +AbstractEntityMaker* +Sub_GameEntities:: +AbstractEntityMaker::getMaker(const QString &entityType) +{ + // If no maker is found, return 0 by default. + return getRegistry()->value(entityType, 0); +} + + +/*! +If a maker for the given type already is in the registry, +the previous value is not overridden. This way the registry +only contains pointers to the static maker instances which +guarantees they are always valid. +*/ +bool +Sub_GameEntities:: +AbstractEntityMaker::registerMaker(const QString &entityType, + AbstractEntityMaker *maker) +{ + if (getRegistry()->contains(entityType)) + return false; + + getRegistry()->insert(entityType, maker); + + return true; +} + + + +QHash<QString, AbstractEntityMaker*>* +Sub_GameEntities +::AbstractEntityMaker::getRegistry() +{ + // Create a static instance. This instance is preserved + // between calls and is initialized this function + // is run the first time. + static QHash<QString, AbstractEntityMaker*> registry; + + // Return a pointer to the static instance. + return ®istry; +} Added: trunk/mysventure/source/sub_entity/basegameentitymaker.cpp =================================================================== --- trunk/mysventure/source/sub_entity/basegameentitymaker.cpp (rev 0) +++ trunk/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-07-24 19:58:49 UTC (rev 72) @@ -0,0 +1,66 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*! \file +Implementation for class BaseGameEntityMaker. +*/ + +#include "sub_entity/basegameentitymaker.h" +#include "util/util_functions.h" +#include "util/identification.h" +#include "util/Position.h" +#include "sub_entity/basegameentity.h" + +using Sub_GameUtility::convert; +using Sub_GameEntities::BaseGameEntityMaker; +using Sub_GameUtility::Identification; +using Sub_GameEntities::BaseGameEntity; +using Sub_GameUtility::Position; + + + +Sub_GameEntities +::BaseGameEntityMaker::BaseGameEntityMaker() +{ + this->registerMaker("BaseGameEntity", this); +} + + +BaseGameEntity* +Sub_GameEntities +::BaseGameEntityMaker::create(QHash<QString, QString> &entityParams, + const Identification& entityId) +{ + bool success = false; + // Retrieve the entity position information. + unsigned int xPos = + convert<unsigned int>(entityParams.value("xposition").toStdString(), success); + unsigned int yPos = + convert<unsigned int>(entityParams.value("yposition").toStdString(), success); + unsigned int layer = + convert<unsigned int>(entityParams.value("layer").toStdString(), success); + + Position entityPos(xPos, yPos, layer); + + BaseGameEntity* entity = + new BaseGameEntity(entityId, + entityPos, + entityParams.value("image")); + + return entity; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-23 19:28:36
|
Revision: 71 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=71&view=rev Author: kimmovii Date: 2010-07-23 19:28:30 +0000 (Fri, 23 Jul 2010) Log Message: ----------- Updated design regarding entity creation. Modified Paths: -------------- trunk/design/game/technical_design.odt Modified: trunk/design/game/technical_design.odt =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-23 07:58:14
|
Revision: 70 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=70&view=rev Author: kimmovii Date: 2010-07-23 07:58:08 +0000 (Fri, 23 Jul 2010) Log Message: ----------- Implemented a (at least seemingly) working factory pattern for entity creation. Unfortunately it relies on a singleton but I think that won't be a problem. Modified Paths: -------------- branch/entitycreation/mysventure/include/sub_entity/abstractentitymaker.h branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.cpp branch/entitycreation/mysventure/lib/liblua514.a branch/entitycreation/mysventure/source/main.cpp branch/entitycreation/mysventure/source/sub_entity/abstractentitymaker.cpp Modified: branch/entitycreation/mysventure/include/sub_entity/abstractentitymaker.h =================================================================== --- branch/entitycreation/mysventure/include/sub_entity/abstractentitymaker.h 2010-07-22 19:36:59 UTC (rev 69) +++ branch/entitycreation/mysventure/include/sub_entity/abstractentitymaker.h 2010-07-23 07:58:08 UTC (rev 70) @@ -38,7 +38,7 @@ static AbstractEntityMaker* getMaker(const QString& entityType) { - return m_makerRegistry.value(entityType, 0); + return getRegistry()->value(entityType, 0); } protected: @@ -46,17 +46,24 @@ void registerMaker(const QString& entityType, AbstractEntityMaker* maker) { - if (m_makerRegistry.contains(entityType)) + if (getRegistry()->contains(entityType)) return; - m_makerRegistry.insert(entityType, + getRegistry()->insert(entityType, maker); } private: - static QHash<QString, AbstractEntityMaker*> m_makerRegistry; + static QHash<QString, AbstractEntityMaker*>* + getRegistry() + { + static QHash<QString, AbstractEntityMaker*> registry; + return ®istry; + } +// static QHash<QString, AbstractEntityMaker*> m_makerRegistry; + }; #endif // ABSTRACTENTITYMAKER_H Modified: branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.cpp =================================================================== --- branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.cpp 2010-07-22 19:36:59 UTC (rev 69) +++ branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.cpp 2010-07-23 07:58:08 UTC (rev 70) @@ -42,9 +42,12 @@ QPixmap entityImage(entityParams.value("entityimage")); + QString entityName = entityParams.value("name"); + InteractiveEntity* entity = new InteractiveEntity(Identification(), entityPos, - entityImage); + entityImage, + entityName); return entity; } Modified: branch/entitycreation/mysventure/lib/liblua514.a =================================================================== (Binary files differ) Modified: branch/entitycreation/mysventure/source/main.cpp =================================================================== --- branch/entitycreation/mysventure/source/main.cpp 2010-07-22 19:36:59 UTC (rev 69) +++ branch/entitycreation/mysventure/source/main.cpp 2010-07-23 07:58:08 UTC (rev 70) @@ -60,13 +60,22 @@ QString entityImage( "D:/kimmo/ohjelmointi/Ohjelmat/C++/QT/myssvn/branch/entitycreation/mysventure/resource/" - + QString::number(i) + ".png"); + + QString::number(i + 1) + ".png"); entityParams.insert("entityimage", entityImage); - Identification id = - manager.create(entityParams, "BaseGameEntity"); + Identification id(Identification::invalidId()); + if (i % 2) + { + entityParams.insert("name", QString("Entity#" + QString::number(i + 1))); + id = manager.create(entityParams, "InteractiveEntity"); + } + else + { + id = manager.create(entityParams, "BaseGameEntity"); + } + m_labels[i]->setPixmap(manager.getEntity(id)->getImage()); m_ids[i]->setText(manager.getEntity(id)->getId().toString()); Modified: branch/entitycreation/mysventure/source/sub_entity/abstractentitymaker.cpp =================================================================== --- branch/entitycreation/mysventure/source/sub_entity/abstractentitymaker.cpp 2010-07-22 19:36:59 UTC (rev 69) +++ branch/entitycreation/mysventure/source/sub_entity/abstractentitymaker.cpp 2010-07-23 07:58:08 UTC (rev 70) @@ -18,5 +18,5 @@ #include "sub_entity/abstractentitymaker.h" -QHash<QString, AbstractEntityMaker*> -AbstractEntityMaker::m_makerRegistry; +//QHash<QString, AbstractEntityMaker*> +//AbstractEntityMaker::m_makerRegistry; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-22 19:37:05
|
Revision: 69 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=69&view=rev Author: kimmovii Date: 2010-07-22 19:36:59 +0000 (Thu, 22 Jul 2010) Log Message: ----------- Implemented the pattern, only it does not: I was bitten by non-deterministic static initialization. The solution is to have a separate maker registry (which can be static) to which (non-static) maker instances are then added. Modified Paths: -------------- branch/entitycreation/mysventure/include/sub_entity/basegameentity.h branch/entitycreation/mysventure/mys-venture.pro branch/entitycreation/mysventure/source/main.cpp Added Paths: ----------- branch/entitycreation/mysventure/include/sub_entity/abstractentitymaker.h branch/entitycreation/mysventure/include/sub_entity/basegameentitymaker.h branch/entitycreation/mysventure/include/sub_entity/entitymanager.h branch/entitycreation/mysventure/include/sub_entity/interactiveentity.h branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.cpp branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.h branch/entitycreation/mysventure/source/sub_entity/abstractentitymaker.cpp branch/entitycreation/mysventure/source/sub_entity/basegameentitymaker.cpp branch/entitycreation/mysventure/source/sub_entity/entitymanager.cpp Added: branch/entitycreation/mysventure/include/sub_entity/abstractentitymaker.h =================================================================== --- branch/entitycreation/mysventure/include/sub_entity/abstractentitymaker.h (rev 0) +++ branch/entitycreation/mysventure/include/sub_entity/abstractentitymaker.h 2010-07-22 19:36:59 UTC (rev 69) @@ -0,0 +1,62 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef ABSTRACTENTITYMAKER_H +#define ABSTRACTENTITYMAKER_H + +#include <QHash> +#include <QString> + +class QString; + + +#include "sub_entity/basegameentity.h" + +class AbstractEntityMaker +{ +public: + + // Pure virtual method to be implemented by subclasses. + virtual Sub_GameEntities::BaseGameEntity* create(const QHash<QString, QString>& entityParams) = 0; + + virtual ~AbstractEntityMaker() {} + + static AbstractEntityMaker* getMaker(const QString& entityType) + { + return m_makerRegistry.value(entityType, 0); + } + +protected: + + void registerMaker(const QString& entityType, + AbstractEntityMaker* maker) + { + if (m_makerRegistry.contains(entityType)) + return; + + m_makerRegistry.insert(entityType, + maker); + } + +private: + + static QHash<QString, AbstractEntityMaker*> m_makerRegistry; + +}; + +#endif // ABSTRACTENTITYMAKER_H Modified: branch/entitycreation/mysventure/include/sub_entity/basegameentity.h =================================================================== --- branch/entitycreation/mysventure/include/sub_entity/basegameentity.h 2010-07-22 11:25:18 UTC (rev 68) +++ branch/entitycreation/mysventure/include/sub_entity/basegameentity.h 2010-07-22 19:36:59 UTC (rev 69) @@ -55,7 +55,9 @@ const Sub_GameUtility::Position& pos = Sub_GameUtility::Position(0, 0, 0), const QPixmap& image = QPixmap()); + virtual ~BaseGameEntity() {} + /*! \brief Moves the entity by the amount specified in parameters. */ Added: branch/entitycreation/mysventure/include/sub_entity/basegameentitymaker.h =================================================================== --- branch/entitycreation/mysventure/include/sub_entity/basegameentitymaker.h (rev 0) +++ branch/entitycreation/mysventure/include/sub_entity/basegameentitymaker.h 2010-07-22 19:36:59 UTC (rev 69) @@ -0,0 +1,46 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef BASEGAMEENTITYMAKER_H +#define BASEGAMEENTITYMAKER_H + +#include <QHash> + +#include "sub_entity/abstractentitymaker.h" +#include "sub_entity/basegameentity.h" + +class BaseGameEntityMaker : public AbstractEntityMaker +{ +public: + + BaseGameEntityMaker() + { + this->registerMaker("BaseGameEntity", this); + } + + Sub_GameEntities::BaseGameEntity* create(const QHash<QString, QString>& entityParams); + + virtual ~BaseGameEntityMaker() {} + +private: + + static BaseGameEntityMaker m_maker; + +}; + +#endif // BASEGAMEENTITYMAKER_H Added: branch/entitycreation/mysventure/include/sub_entity/entitymanager.h =================================================================== --- branch/entitycreation/mysventure/include/sub_entity/entitymanager.h (rev 0) +++ branch/entitycreation/mysventure/include/sub_entity/entitymanager.h 2010-07-22 19:36:59 UTC (rev 69) @@ -0,0 +1,51 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef ENTITYMANAGER_H +#define ENTITYMANAGER_H + +#include <QSharedPointer> + +#include "sub_entity/abstractentitymaker.h" +#include "sub_entity/basegameentity.h" +#include "sub_entity/entitystorage.h" +#include "util/identificationgenerator.h" + +class EntityManager +{ +public: + + Sub_GameUtility::Identification + create(const QHash<QString, QString>& entityParams, + const QString& entityType); + + bool destroy(const Sub_GameUtility::Identification& id); + + QSharedPointer<Sub_GameEntities::BaseGameEntity> getEntity(const Sub_GameUtility::Identification& id) + { + return m_entityStorage.getEntity(id); + } + +private: + + Sub_GameEntities::EntityStorage m_entityStorage; + + Sub_GameUtility::IdentificationGenerator m_entityIdGenerator; +}; + +#endif // ENTITYMANAGER_H Added: branch/entitycreation/mysventure/include/sub_entity/interactiveentity.h =================================================================== --- branch/entitycreation/mysventure/include/sub_entity/interactiveentity.h (rev 0) +++ branch/entitycreation/mysventure/include/sub_entity/interactiveentity.h 2010-07-22 19:36:59 UTC (rev 69) @@ -0,0 +1,53 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef INTERACTIVEENTITY_H +#define INTERACTIVEENTITY_H + +#include <QPixmap> +#include <QString> + +#include "sub_entity/basegameentity.h" +#include "util/identification.h" +#include "util/position.h" + + + +class InteractiveEntity : public Sub_GameEntities::BaseGameEntity +{ +public: + + InteractiveEntity(const Sub_GameUtility::Identification& id, + const Sub_GameUtility::Position& pos = Sub_GameUtility::Position(0, 0, 0), + const QPixmap& image = QPixmap(), + const QString& name = "") + : BaseGameEntity(id, pos, image), m_name(name) + { + + } + + virtual ~InteractiveEntity() {} + + QString getName() const { return m_name; } + +private: + + QString m_name; +}; + +#endif // INTERACTIVEENTITY_H Added: branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.cpp =================================================================== --- branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.cpp (rev 0) +++ branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.cpp 2010-07-22 19:36:59 UTC (rev 69) @@ -0,0 +1,50 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <QHash> +#include <QString> + +#include "sub_entity/interactiveentitymaker.h" +#include "sub_entity/interactiveentity.h" +#include "util/identification.h" +#include "util/position.h" + +#include <boost/lexical_cast.hpp> + +using namespace Sub_GameEntities; +using namespace Sub_GameUtility; + +InteractiveEntityMaker InteractiveEntityMaker::m_maker; + +InteractiveEntity* +InteractiveEntityMaker::create(const QHash<QString, QString> &entityParams) +{ + unsigned int xPos = boost::lexical_cast<unsigned int>(entityParams.value("xposition").toStdString()); + unsigned int yPos = boost::lexical_cast<unsigned int>(entityParams.value("yposition").toStdString()); + unsigned int layer = boost::lexical_cast<unsigned int>(entityParams.value("layer").toStdString()); + + Position entityPos(xPos, yPos, layer); + + QPixmap entityImage(entityParams.value("entityimage")); + + InteractiveEntity* entity = new InteractiveEntity(Identification(), + entityPos, + entityImage); + + return entity; +} Added: branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.h =================================================================== --- branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.h (rev 0) +++ branch/entitycreation/mysventure/include/sub_entity/interactiveentitymaker.h 2010-07-22 19:36:59 UTC (rev 69) @@ -0,0 +1,43 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef INTERACTIVEENTITYMAKER_H +#define INTERACTIVEENTITYMAKER_H + +#include "sub_entity/abstractentitymaker.h" +#include "sub_entity/interactiveentity.h" + + + +class InteractiveEntityMaker : public AbstractEntityMaker +{ +public: + + InteractiveEntityMaker() + { + this->registerMaker("InteractiveEntity", this); + } + + InteractiveEntity* create(const QHash<QString, QString>& entityParams); + +private: + + static InteractiveEntityMaker m_maker; +}; + +#endif // INTERACTIVEENTITYMAKER_H Modified: branch/entitycreation/mysventure/mys-venture.pro =================================================================== --- branch/entitycreation/mysventure/mys-venture.pro 2010-07-22 11:25:18 UTC (rev 68) +++ branch/entitycreation/mysventure/mys-venture.pro 2010-07-22 19:36:59 UTC (rev 69) @@ -20,7 +20,11 @@ source/sub_view/mapview.cpp \ source/sub_view/mapdrawer.cpp \ source/sub_entity/basegameentity.cpp \ - source/sub_entity/entitystorage.cpp + source/sub_entity/entitystorage.cpp \ + source/sub_entity/abstractentitymaker.cpp \ + source/sub_entity/basegameentitymaker.cpp \ + include/sub_entity/interactiveentitymaker.cpp \ + source/sub_entity/entitymanager.cpp HEADERS += include/sub_view/mainwindow.h \ include/util/Position.h \ include/util/identification.h \ @@ -42,11 +46,18 @@ include/sub_level/sub_gamelevels.h \ include/util/sub_gameutility.h \ include/sub_entity/basegameentity.h \ - include/sub_entity/entitystorage.h + include/sub_entity/entitystorage.h \ + include/sub_entity/abstractentitymaker.h \ + include/sub_entity/interactiveentity.h \ + include/sub_entity/basegameentitymaker.h \ + include/sub_entity/interactiveentitymaker.h \ + include/sub_entity/entitymanager.h FORMS += source/sub_view/mainwindow.ui \ source/sub_view/mapview.ui LIBS += -Llib \ +-L../mysventure/lib \ -llua514 + INCLUDEPATH += include \ include/util \ include/sub_view \ Modified: branch/entitycreation/mysventure/source/main.cpp =================================================================== --- branch/entitycreation/mysventure/source/main.cpp 2010-07-22 11:25:18 UTC (rev 68) +++ branch/entitycreation/mysventure/source/main.cpp 2010-07-22 19:36:59 UTC (rev 69) @@ -17,10 +17,18 @@ */ #include <QtGui/QApplication> +#include <QtGui> +#include <QVector> #include "include/sub_view/mainwindow.h" +#include "sub_entity/entitymanager.h" +#include "util/identification.h" +using namespace Sub_GameEntities; +using namespace Sub_GameUtility; + + int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -28,5 +36,44 @@ MainWindow mainWindow; mainWindow.show(); + QWidget entityWidget; + QVector<QLabel*> m_labels; + QVector<QLabel*> m_ids; + + for (int i = 0; i < 5; ++i) + { + m_labels.append(new QLabel(&entityWidget)); + m_labels[i]->move(0, i * 40); + + m_ids.append(new QLabel(&entityWidget)); + m_ids[i]->move(50, i * 40); + } + + EntityManager manager; + + for (int i = 0; i < 5; ++i) + { + QHash<QString, QString> entityParams; + entityParams.insert("xposition", QString::number(i)); + entityParams.insert("yposition", QString::number(i * 2)); + entityParams.insert("layer", QString::number(1)); + + QString entityImage( + "D:/kimmo/ohjelmointi/Ohjelmat/C++/QT/myssvn/branch/entitycreation/mysventure/resource/" + + QString::number(i) + ".png"); + + entityParams.insert("entityimage", entityImage); + + Identification id = + manager.create(entityParams, "BaseGameEntity"); + + m_labels[i]->setPixmap(manager.getEntity(id)->getImage()); + m_ids[i]->setText(manager.getEntity(id)->getId().toString()); + + } + + entityWidget.show(); + + return a.exec(); } Added: branch/entitycreation/mysventure/source/sub_entity/abstractentitymaker.cpp =================================================================== --- branch/entitycreation/mysventure/source/sub_entity/abstractentitymaker.cpp (rev 0) +++ branch/entitycreation/mysventure/source/sub_entity/abstractentitymaker.cpp 2010-07-22 19:36:59 UTC (rev 69) @@ -0,0 +1,22 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "sub_entity/abstractentitymaker.h" + +QHash<QString, AbstractEntityMaker*> +AbstractEntityMaker::m_makerRegistry; Added: branch/entitycreation/mysventure/source/sub_entity/basegameentitymaker.cpp =================================================================== --- branch/entitycreation/mysventure/source/sub_entity/basegameentitymaker.cpp (rev 0) +++ branch/entitycreation/mysventure/source/sub_entity/basegameentitymaker.cpp 2010-07-22 19:36:59 UTC (rev 69) @@ -0,0 +1,49 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "sub_entity/basegameentitymaker.h" +#include "sub_entity/basegameentity.h" +#include "util/identification.h" + +using namespace Sub_GameEntities; +using namespace Sub_GameUtility; + +#include <QHash> +#include <QPixmap> +#include <QString> +#include <boost/lexical_cast.hpp> + +BaseGameEntityMaker BaseGameEntityMaker::m_maker; + +BaseGameEntity* +BaseGameEntityMaker::create(const QHash<QString, QString> &entityParams) +{ + unsigned int xPos = boost::lexical_cast<unsigned int>(entityParams.value("xposition").toStdString()); + unsigned int yPos = boost::lexical_cast<unsigned int>(entityParams.value("yposition").toStdString()); + unsigned int layer = boost::lexical_cast<unsigned int>(entityParams.value("layer").toStdString()); + + Position entityPos(xPos, yPos, layer); + + QPixmap entityImage(entityParams.value("entityimage")); + + BaseGameEntity* entity = new BaseGameEntity(Identification(), + entityPos, + entityImage); + + return entity; +} Added: branch/entitycreation/mysventure/source/sub_entity/entitymanager.cpp =================================================================== --- branch/entitycreation/mysventure/source/sub_entity/entitymanager.cpp (rev 0) +++ branch/entitycreation/mysventure/source/sub_entity/entitymanager.cpp 2010-07-22 19:36:59 UTC (rev 69) @@ -0,0 +1,50 @@ +/* + Mys-venture is a 2D tile-based puzzle game. + Copyright (C) 2010 Kimmo Viitanen + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <QHash> +#include <QString> + +#include "sub_entity/entitymanager.h" +#include "sub_entity/abstractentitymaker.h" + +using namespace Sub_GameEntities; +using namespace Sub_GameUtility; + + + +Identification +EntityManager::create(const QHash<QString, QString> &entityParams, + const QString &entityType) +{ + QSharedPointer<BaseGameEntity> newEntity( + AbstractEntityMaker::getMaker(entityType)->create(entityParams)); + + m_entityStorage.add(newEntity->getId(), newEntity); + + return newEntity->getId(); +} + +bool +EntityManager::destroy(const Sub_GameUtility::Identification &id) +{ + if (!(m_entityStorage.contains(id))) + return false; + + m_entityStorage.remove(id); + return true; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-22 11:25:24
|
Revision: 68 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=68&view=rev Author: kimmovii Date: 2010-07-22 11:25:18 +0000 (Thu, 22 Jul 2010) Log Message: ----------- Updated project file to accommodate the default shadow build mode of QtCreator 2. The project should now build as-is with both QtCreator 2 and 1.3. Modified Paths: -------------- trunk/mysventure/mys-venture.pro Modified: trunk/mysventure/mys-venture.pro =================================================================== --- trunk/mysventure/mys-venture.pro 2010-07-21 15:16:46 UTC (rev 67) +++ trunk/mysventure/mys-venture.pro 2010-07-22 11:25:18 UTC (rev 68) @@ -46,6 +46,7 @@ FORMS += source/sub_view/mainwindow.ui \ source/sub_view/mapview.ui LIBS += -Llib \ + -L../mysventure/lib \ -llua514 INCLUDEPATH += include \ include/util \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-21 15:16:53
|
Revision: 67 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=67&view=rev Author: kimmovii Date: 2010-07-21 15:16:46 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Created branch for trying out entity creation using factories. Added Paths: ----------- branch/entitycreation/ Property changes on: branch/entitycreation ___________________________________________________________________ Added: svn:mergeinfo + /branch/settingsreader:20-49 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-21 15:15:22
|
Revision: 66 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=66&view=rev Author: kimmovii Date: 2010-07-21 15:15:17 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Cannot branch into existing directory... Always forget that. Removed Paths: ------------- branch/entitycreation/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-21 15:12:02
|
Revision: 65 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=65&view=rev Author: kimmovii Date: 2010-07-21 15:11:56 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Directory for the trying out the factory method of entity creation. Added Paths: ----------- branch/entitycreation/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kim...@us...> - 2010-07-21 15:07:47
|
Revision: 64 http://mys-venture.svn.sourceforge.net/mys-venture/?rev=64&view=rev Author: kimmovii Date: 2010-07-21 15:07:41 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Modified Paths: -------------- trunk/mysventure/source/sub_entity/entitystorage.cpp Modified: trunk/mysventure/source/sub_entity/entitystorage.cpp =================================================================== --- trunk/mysventure/source/sub_entity/entitystorage.cpp 2010-07-21 11:01:13 UTC (rev 63) +++ trunk/mysventure/source/sub_entity/entitystorage.cpp 2010-07-21 15:07:41 UTC (rev 64) @@ -107,7 +107,7 @@ } -/* +/*! */ int Sub_GameEntities:: @@ -118,6 +118,8 @@ +/*! +*/ bool Sub_GameEntities:: EntityStorage::isEmpty() const This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |