[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/games/astrododge/src
From:       Rivo Laks <rivolaks () hot ! ee>
Date:       2009-08-08 18:06:35
Message-ID: 1249754795.777756.24151.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1008939 by rivol:

DataStore is now singleton

 M  +14 -0     datastore.cpp  
 M  +8 -2      datastore.h  
 M  +3 -3      gameworld.cpp  
 M  +1 -1      gameworld.h  
 M  +6 -6      mainwindow.cpp  
 M  +0 -2      mainwindow.h  


--- trunk/playground/games/astrododge/src/datastore.cpp #1008938:1008939
@@ -30,6 +30,20 @@
 #include <kgllib/geometrybuffer.h>
 
 
+DataStore* DataStore::mInstance = 0;
+
+
+void DataStore::initInstance(const QString& datadir)
+{
+    if (mInstance) {
+        kFatal() << "Instance already exists!";
+        return;
+    }
+
+    mInstance = new DataStore(datadir);
+}
+
+
 DataStore::DataStore(const QString& datadir)
 {
     mDataDir = datadir;
--- trunk/playground/games/astrododge/src/datastore.h #1008938:1008939
@@ -38,8 +38,8 @@
 {
     Q_OBJECT
     public:
-        DataStore(const QString& datadir);
-        ~DataStore();
+        static void initInstance(const QString& datadir);
+        static DataStore* instance()  { return mInstance; }
 
         QString dataDir() const  { return mDataDir; }
 
@@ -58,7 +58,13 @@
     signals:
         void loadingAsteroid(const QString& name, int i, int total);
 
+    protected:
+        DataStore(const QString& datadir);
+        ~DataStore();
+
     private:
+        static DataStore* mInstance;
+
         QString mDataDir;
 
         QHash<QString, Model*> mModels;
--- trunk/playground/games/astrododge/src/gameworld.cpp #1008938:1008939
@@ -69,7 +69,7 @@
 
 GameWorld* GameWorld::mInstance = 0;
 
-GameWorld::GameWorld(QObject *parent, DataStore* data)
+GameWorld::GameWorld(QObject *parent)
     : QObject(parent)
 {
     if (mInstance) {
@@ -78,8 +78,8 @@
     }
     mInstance = this;
 
-    mData = data;
-    mDataDir = data->dataDir();
+    mData = DataStore::instance();
+    mDataDir = mData->dataDir();
 
     mShip = 0;
 
--- trunk/playground/games/astrododge/src/gameworld.h #1008938:1008939
@@ -40,7 +40,7 @@
 {
 Q_OBJECT
 public:
-    GameWorld(QObject *parent, DataStore* data);
+    GameWorld(QObject *parent);
     ~GameWorld();
 
     static GameWorld* instance()  { return mInstance; }
--- trunk/playground/games/astrododge/src/mainwindow.cpp #1008938:1008939
@@ -50,10 +50,6 @@
     mWorld = 0;
     mView = 0;
 
-    mDisplay = new DisplayWidget(this);
-
-    setCentralWidget(mDisplay->proxy());
-
     // Find where our data is
     QString datadir = KGlobal::dirs()->findResourceDir("appdata", "shaders/render-light.frag");
     if (datadir.isEmpty()) {
@@ -61,8 +57,12 @@
                            "Data not found");
         qApp->quit();
     }
-    mData = new DataStore(datadir);
+    DataStore::initInstance(datadir);
 
+    mDisplay = new DisplayWidget(this);
+
+    setCentralWidget(mDisplay->proxy());
+
     setMinimumSize(640, 480);
 
     setupActions();
@@ -146,7 +146,7 @@
     kDebug();
     mMenuView->hide();
 
-    mWorld = new GameWorld(this, mData);
+    mWorld = new GameWorld(this);
     mShipLightAction->setChecked(false);
     connect(mShipLightAction, SIGNAL(triggered(bool)), mWorld, SLOT(setShipLight(bool)));
 
--- trunk/playground/games/astrododge/src/mainwindow.h #1008938:1008939
@@ -24,7 +24,6 @@
 class GameView;
 class DisplayWidget;
 class LoadingView;
-class DataStore;
 class MenuView;
 
 class KToggleAction;
@@ -64,7 +63,6 @@
     private:
         DisplayWidget* mDisplay;
         GameWorld* mWorld;
-        DataStore* mData;
 
         GameView* mView;
         LoadingView* mLoadingView;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic