[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-07-03 16:50:46
Message-ID: 1246639846.960905.18354.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 990989 by rivol:

- Add GLView class which is essentially a view or a layer that can be rendered into a \
GLWidget.  I'm hoping to use different layers for the actual scene and the GUI which \
should keep the code more  organized.
- Shooting works again (key is space now (but can be reconfigured)).

 M  +1 -0      CMakeLists.txt  
 M  +23 -8     displaywidget.cpp  
 M  +5 -3      displaywidget.h  
 M  +5 -13     gameview.cpp  
 M  +3 -7      gameview.h  
 A             glview.cpp   [License: GPL (v3+)]
 A             glview.h   [License: GPL (v3+)]
 M  +14 -1     mainwindow.cpp  
 M  +2 -0      mainwindow.h  


--- trunk/playground/games/astrododge/src/CMakeLists.txt #990988:990989
@@ -7,6 +7,7 @@
         gameobject.cpp
         gameview.cpp
         gameworld.cpp
+        glview.cpp
         levelloader.cpp
         main.cpp
         mainwindow.cpp
--- trunk/playground/games/astrododge/src/displaywidget.cpp #990988:990989
@@ -38,7 +38,6 @@
     mProxy = 0;
     mActiveWidget = 0;
 
-    mView = 0;
     mMainMenu = 0;
 }
 
@@ -65,12 +64,20 @@
     return mProxy;
 }
 
-void DisplayWidget::setGameView(GameView* view)
+void DisplayWidget::appendView(GLView* view)
 {
-    mView = view;
-    mView->init();
+    mViews.append(view);
+
+    if (glInitialized()) {
+        view->init();
+    }
 }
 
+void DisplayWidget::removeView(GLView* view)
+{
+    mViews.removeAll(view);
+}
+
 void DisplayWidget::mouseMoveEvent(QMouseEvent* e)
 {
     if (e->buttons() & Qt::LeftButton) {
@@ -99,6 +106,10 @@
 
     camera()->setFoV(90);
     camera()->setDepthRange(1, 15000);
+
+    foreach (GLView* v, mViews) {
+        v->init();
+    }
 }
 
 void DisplayWidget::resizeGL(int width, int height)
@@ -118,15 +129,19 @@
     textRenderer()->draw(rect(), "Welcome to AstroDodge", Qt::AlignTop | \
Qt::AlignHCenter, QFont("Arial", 20));  textRenderer()->end();
 
-    if (mView) {
-        QTimer::singleShot(0, this, SLOT(update()));
+    foreach (GLView* v, mViews) {
+        if (v->viewType() == GLView::View_GUI) {
+            v->render();
+        }
     }
 }
 
 void DisplayWidget::renderScene()
 {
-    if (mView) {
-        mView->render();
+    foreach (GLView* v, mViews) {
+        if (v->viewType() != GLView::View_GUI) {
+            v->render();
+        }
     }
 }
 
--- trunk/playground/games/astrododge/src/displaywidget.h #990988:990989
@@ -21,7 +21,7 @@
 #include <kgllib/hdrglwidget.h>
 
 class GameWorld;
-class GameView;
+class GLView;
 
 namespace KGLLib
 {
@@ -43,7 +43,8 @@
 
         KGLLib::WidgetProxy* proxy();
 
-        void setGameView(GameView* view);
+        void appendView(GLView* view);
+        void removeView(GLView* view);
 
         void showMainMenu();
         void hideMenus();
@@ -65,8 +66,9 @@
         QGraphicsProxyWidget* mActiveWidget;
 
         QWidget* mMainMenu;
-        GameView* mView;
         QPoint mMousePos;
+
+        QList<GLView*> mViews;
 };
 
 #endif // DISPLAYWIDGET_H
--- trunk/playground/games/astrododge/src/gameview.cpp #990988:990989
@@ -21,6 +21,7 @@
 #include "ship.h"
 #include "asteroid.h"
 #include "model.h"
+#include "bullet.h"
 
 #include <kgllib/camera.h>
 #include <kgllib/widgetproxy.h>
@@ -29,14 +30,13 @@
 
 #include <KDebug>
 #include <KStandardDirs>
-#include "bullet.h"
+#include <QTimer>
 
 using namespace KGLLib;
 
 
-GameView::GameView(DisplayWidget* parent, GameWorld* world) : QObject(parent)
+GameView::GameView(KGLLib::GLWidget* parent, GameWorld* world) : GLView(parent)
 {
-    mDisplay = parent;
     mWorld = world;
 
     mDetailLevel = 1.0f;
@@ -46,16 +46,6 @@
 {
 }
 
-Camera* GameView::camera()
-{
-    return mDisplay->camera();
-}
-
-FPSCounter* GameView::fpsCounter()
-{
-    return mDisplay->fpsCounter();
-}
-
 void GameView::init()
 {
     kDebug();
@@ -155,6 +145,8 @@
     glPopMatrix();
     glMatrixMode(GL_MODELVIEW);
     checkGLError("after renderScene()");
+
+    QTimer::singleShot(0, this, SLOT(update()));
 }
 
 void GameView::renderAsteroids()
--- trunk/playground/games/astrododge/src/gameview.h #990988:990989
@@ -18,17 +18,17 @@
 #ifndef GAMEVIEW_H
 #define GAMEVIEW_H
 
-#include "displaywidget.h"
+#include "glview.h"
 
 class GameWorld;
 class Asteroid;
 
 
-class GameView : public QObject
+class GameView : public GLView
 {
     Q_OBJECT
     public:
-        GameView(DisplayWidget* parent, GameWorld* world);
+        GameView(KGLLib::GLWidget* parent, GameWorld* world);
         ~GameView();
 
         virtual void init();
@@ -38,16 +38,12 @@
         void dataLoadingProgress(int done, int total, const QString& text);
 
     protected:
-        KGLLib::Camera* camera();
-        KGLLib::FPSCounter* fpsCounter();
-
         void setupWorldView();
 
         void renderAsteroids();
         void renderAsteroid(const Asteroid* a);
 
     private:
-        DisplayWidget* mDisplay;
         GameWorld* mWorld;
         float mDetailLevel;
 };
--- trunk/playground/games/astrododge/src/mainwindow.cpp #990988:990989
@@ -89,6 +89,11 @@
     actionCollection()->addAction("dodge_down", dodgeDownAction);
     connect(dodgeDownAction, SIGNAL(triggered(bool)), this, SLOT(dodgeDown()));
 
+    KAction* fireAction = new KAction("Fire cannon", this);
+    fireAction->setShortcut(Qt::Key_Space);
+    actionCollection()->addAction("fire_cannon", fireAction);
+    connect(fireAction, SIGNAL(triggered(bool)), this, SLOT(fireCannon(bool)));
+
     // Game state actions
     KStandardGameAction::gameNew(this, SLOT(startNewGame()), actionCollection());
     KStandardGameAction::quit(this, SLOT(close()), actionCollection());
@@ -101,7 +106,7 @@
 
     mWorld = new GameWorld(this);
     mView = new GameView(mDisplay, mWorld);
-    mDisplay->setGameView(mView);
+    mDisplay->appendView(mView);
 
     connect(mDisplay, SIGNAL(signalRotateShip(int,int)), mWorld, \
SLOT(slotRotateShip(int,int)));  
@@ -130,3 +135,11 @@
         mWorld->ship()->dodge(x, y);
     }
 }
+
+void MainWindow::fireCannon(bool fire)
+{
+    kDebug() << fire;
+    if (mGameRunning) {
+        mWorld->slotShootBullet();
+    }
+}
--- trunk/playground/games/astrododge/src/mainwindow.h #990988:990989
@@ -63,6 +63,8 @@
         void dodgeDown()   { dodge( 0, -1); }
         void dodge(int x, int y);
 
+        void fireCannon(bool fire);
+
     protected:
         virtual void wheelEvent(QWheelEvent*);
 


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

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