Commits

Devlon committed 68b8535

Optimizations. Cleaning code. Minor changes

Comments (0)

Files changed (13)

 PROJECT(cepheus CXX)
 
 SET (CMAKE_CXX_COMPILER                   "/usr/bin/clang++")
-SET (CMAKE_CXX_FLAGS_INIT                 "-Wall -pedantic -fPIC -shared -ggdb")
+SET (CMAKE_CXX_FLAGS_INIT                 "-Wall -pedantic -fPIC -ggdb")
 SET (CMAKE_LINK_FLAGS                     "-fPIC -shared")
 
 
                         src/Core/Input.cpp
                         src/Graphics/Screen.cpp
                         src/Graphics/GraphicManager.cpp
-                        src/Scene/Scene.cpp
                         src/Scene/SceneManager.cpp
                         src/Scene/Component.cpp
                         src/Scene/SceneManager.cpp
 ADD_LIBRARY (
         cepheus_shared          SHARED          ${SOURCES}    
 )
-ADD_LIBRARY (
-        cepheus_static          STATIC          ${SOURCES}
-)
 
 FIND_LIBRARY( 
             SDL_LIB 
         cepheus_shared          ${SDL_LIB}      ${SDLMAIN_LIB} 
 )
 
-
-TARGET_LINK_LIBRARIES( 
-        cepheus_static           ${SDL_LIB}     ${SDLMAIN_LIB}
-)
-
-
 SET_TARGET_PROPERTIES(
                      cepheus_shared 
-                     cepheus_static 
                      PROPERTIES OUTPUT_NAME          cepheus
                      LIBRARY_OUTPUT_DIRECTORY        "bin"
                      ARCHIVE_OUTPUT_DIRECTORY        "bin"
 ADD_EXECUTABLE(
         test4_shared                  src/tests/test4.cpp
 )
-ADD_EXECUTABLE(
-        test1_static                  src/tests/main1.cpp
-)
-ADD_EXECUTABLE(
-        test2_static                  src/tests/test2.cpp
-)
-ADD_EXECUTABLE(
-        test3_static                  src/tests/test3.cpp
-)
 
 ### Generate shared linked binaries
 TARGET_LINK_LIBRARIES(
 TARGET_LINK_LIBRARIES(
         test4_shared           cepheus_shared
 )
-
-### Generate static linked binaries
-TARGET_LINK_LIBRARIES(
-       test1_static           cepheus_static
-)
-TARGET_LINK_LIBRARIES(
-       test2_static           cepheus_static
-)
-TARGET_LINK_LIBRARIES(
-       test3_static           cepheus_static
-)
-# file(REMOVE ${CONF_FILE})
+# file(REMOVE ${CONF_FILE})

bin/assets/1.bmp

Added
New image

src/Core/Game.cpp

   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/
+
 #include "../headers/Core/Game.h"
 
 Cepheus :: Game :: Game(){
     init();
 }
-Cepheus :: Game :: ~Game(){
-    init();
-}
+Cepheus :: Game :: ~Game(){}
 void Cepheus :: Game :: render(Cepheus::GraphicManager *gm){}
 void Cepheus :: Game :: update(){}
 
 void Cepheus :: Game :: run(){    
     // Enter main loop.
     loop();
-    
-    // Clear Screen.
-    getGraphicManager()->getScreen()->clear();
 }
 void Cepheus :: Game :: tick(){
     _lastcicle += 1000 / _fps;
         }
         _cicle = SDL_GetTicks();
         while (_lastcicle < _cicle) {
+            // Get Input state.  
             _input->update();
+
+            // Update game logic.
             update();
+
+            // Render scene.
             render( getGraphicManager() );
+
+            // Clear Screen.
+            getGraphicManager()->getScreen()->clear();
+
+            // Update cicle limit.
             tick(); 
         }
     }
 bool Cepheus :: Game :: closed(){
     return SDL_QuitRequested();
 }
-

src/Core/Input.cpp

     }
     return true;
 }
-Cepheus::Mouse  Cepheus :: Input :: getMouseState(){
+struct Cepheus::Mouse Cepheus :: Input :: getMouseState(){
     return _mousestate;
 }
 

src/Scene/Component.cpp

 void Cepheus:: Component :: addComponent(Cepheus::Component * component){
     _components.push_back(component);
 }
+std::vector<Cepheus::Component *> * Cepheus :: 
+                                        Component :: getComponents(){
+    return &_components;
+}
+Cepheus::Component * Cepheus::Component :: getComponent(int id){
+    return _components[id];
+}

src/Scene/Scene.cpp

 
 #include "../headers/Scene/Scene.h"
 #include "../headers/Core/Input.h"
-
-Cepheus::Panel * Cepheus :: Scene :: _searchPanel(Mouse mouse){
-    for(int i = _panels.size(); i>0;i--){
-        if( _panels[i]->checkPanel(mouse) ){
-            return ( _panels[i] );
-        }
-    }
-    return NULL;
-}
-Cepheus :: Panel * Cepheus :: Scene :: getPanel(int id){ return NULL; }
-void Cepheus :: Scene :: leftClick(Mouse mouse){
-    _searchPanel(mouse)->leftClick(mouse);
-}
-void Cepheus :: Scene :: rightClick(Mouse mouse){
-    _searchPanel(mouse)->rightClick(mouse);
-}
-

src/Scene/SceneManager.cpp

 *******************************************************************************/
 
 #include "../headers/Scene/SceneManager.h"
-void Cepheus :: SceneManager :: delScene(int id){
-  delete _scenes[id];
-}
+
+// Cepheus :: SceneManager :: SceneManager(Cepheus::Input *in): _input(in){}
 void Cepheus :: SceneManager :: setCurrentScene(int id){
     _currentId = id;
 }
 
 // Getters for some types of Scenes.
-Cepheus::Scene * Cepheus :: SceneManager :: getScene(int id){
-    return _scenes[ id ];
-}
-std::vector<Cepheus::Scene *>* Cepheus :: SceneManager :: getScenes(){
-    return &_scenes;
-}
 Cepheus::Scene * Cepheus :: SceneManager :: getCurrentScene(){
-    return _scenes[ _currentId ];
-}
-void Cepheus :: SceneManager ::  addScene(Cepheus::Scene* scene){
-    _scenes.push_back(scene);
+    return static_cast<Scene *>( _components[ _currentId ] );
 }
 
+void Cepheus :: SceneManager :: leftClick( Mouse mouse, Cepheus::SceneManager *sm) {
+    getCurrentScene()->leftClick(mouse, sm);
+}
+void Cepheus :: SceneManager :: rightClick( Cepheus::Mouse mouse , Cepheus::SceneManager *sm) {
+    getCurrentScene()->rightClick(mouse, sm);
+}
+void Cepheus :: SceneManager :: keyPress( Cepheus::Key key , Cepheus::SceneManager *sm) {
+    getCurrentScene()->keyPress(key, sm);
+}
+

src/headers/Core/Input.h

     {
         typedef SDLKey Key;
         typedef Uint8   Button;
-        typedef struct{
-            int _x,_y,_xrel,_yrel;
-            int buttons[3] ;
-            int cursor;
-        }Mouse;
+        struct Mouse{
+                    int _x,_y,_xrel,_yrel;
+                    int buttons[3] ;
+                    int cursor;
+        };
         
         class Input {
             private:
-                Mouse _mousestate;
+                struct Mouse _mousestate;
                 Uint8 *_keystate;
                 SDL_Event *e;
                 
                 bool isPressed(Key k);
                 bool isClicked(Button button);
                 void update();
-                Mouse getMouseState();
+                struct Mouse getMouseState();
         };
     }        
 #endif

src/headers/Scene/Component.h

                 virtual ~Component();
 
                 Cepheus::Component* getComponent(int id);
+                std::vector<Cepheus::Component*>* getComponents();
                 void addComponent(Cepheus::Component * component);
             
-                // Override this methods.
-                virtual void leftClick(Mouse mouse) = 0;
-                virtual void rightClick(Mouse mouse) = 0;
-                virtual void keyPress(Cepheus::Key k) = 0;
-                virtual void update(Cepheus::Input *input, Cepheus::SceneManager * sm) = 0;                    
+                // Override this methods. Input Logic
+                virtual void leftClick(struct Cepheus::Mouse mouse, Cepheus::SceneManager * sm) = 0;
+                virtual void rightClick(struct Cepheus::Mouse mouse, Cepheus::SceneManager * sm) = 0;
+                virtual void keyPress(Cepheus::Key k, Cepheus::SceneManager * sm) = 0;
+                
+                virtual void update(Cepheus::Input *input, Cepheus::SceneManager * sm) = 0;
+                
+                // Override this. Render Logic
                 virtual void render(Cepheus::GraphicManager * gm) = 0;
+                
             };
     }
 #endif

src/headers/Scene/Scene.h

     #define _CEPHEUS_SCENE_H_
     #include "Panel.h"
     #include "../IA/IAManager.h"
+    #include "../Scene/Component.h"
     
     namespace Cepheus
     {
-        class Scene{
-            protected:
-                std::vector<Cepheus::Panel *> _panels;
-                
-                // Protected methods
-                Cepheus::Panel * _searchPanel(Mouse mouse);
-                Cepheus::SceneManager *_sm;
-
+        class Scene : public Component {
             public:
                 Scene(){}
                 virtual ~Scene(){}
                 
-                void addPanel(Cepheus::Panel * panel);
-                void delPanel(int id);
-
-                Cepheus::Panel * getPanel(int id);
-
-                // Events delegated in Panels, and Panels in Components
-
-                // Override this methods.
-                virtual void leftClick(Mouse mouse);
-                virtual void rightClick(Mouse mouse);
-                virtual void keyPress(SDL_keysym key) = 0;
-                virtual void update(Cepheus::Input *input, Cepheus::Manager *m) = 0;
-                virtual void render(Cepheus::GraphicManager * gm) = 0;
+                Cepheus::Component * checkComponent();
+                Cepheus::Component * currentComponent();
         };
     }
 #endif

src/headers/Scene/SceneManager.h

     #define _CEPHEUS_SCENEMANAGER_H_
     #include <vector>
     #include "Scene.h"
-    #include "../Core/Manager.h"
+    #include "../Scene/Component.h"
+    #include "../Core/Input.h"
 
     namespace Cepheus
     {
-        class SceneManager : public Manager{
+        class SceneManager : public Component{
             private:
                 int _currentId;
-                std::vector<Cepheus::Scene *> _scenes;
+                Cepheus::Input *_input;
 
             public:
                 SceneManager(){}
-                virtual ~SceneManager(){}
+                SceneManager(Cepheus::Input *in):_input(in){}
+                ~SceneManager(){}
 
                 // Scenes Management
                 void addScene(Cepheus::Scene* scene);
                 void setCurrentScene(int id);
                 
                 // Getters for some types of Scenes.
-                Cepheus::Scene * getScene(int id);
                 Cepheus::Scene * getCurrentScene();
-                std::vector<Cepheus::Scene *> * getScenes();
                 
-                virtual void addEvent(Cepheus::Event *e){};
-                virtual void delEvent(int id){};
-                virtual void handleEvents(){};
-
-                virtual void render(Cepheus::GraphicManager * gm){}
+                
+                void leftClick( Mouse mouse, Cepheus::SceneManager *sm);
+                void rightClick( Mouse mouse , Cepheus::SceneManager *sm);
+                void keyPress(Cepheus::Key k, Cepheus::SceneManager *sm);
+                void update (Cepheus::Input *in, Cepheus::SceneManager * sm){}
+                void render (Cepheus::GraphicManager *gm){}
         };
     }
 #endif

src/tests/test3.cpp

     public:
         Scene1(){}
         
-        ~Scene1(){}
-        void keyPress(SDL_keysym key){}
-
-        void update( Cepheus::Input *input, Cepheus::Manager *m){
+        virtual ~Scene1(){}
+ 
+        // Override some virtual methods.
+        void leftClick(Cepheus::Mouse mouse, Cepheus::SceneManager *sm) {}
+        void rightClick(Cepheus::Mouse mouse, Cepheus::SceneManager *sm){}
+        void keyPress(Cepheus::Key k, Cepheus::SceneManager *sm){}
+        
+        void update(Cepheus::Input *in, Cepheus::SceneManager *sm){
             std::cout << ">> Updating Scene" << std::endl;
         }
-
         void render(Cepheus::GraphicManager *gm){
             std::cout << "\t:: Rendering Scene" << std::endl;
-        }    
+        }
+        
 };
 class Scene2 : public Cepheus::Scene{
     public:
         Scene2(){}
         
-        ~Scene2(){}
-        void keyPress(SDL_keysym key){}
+        virtual ~Scene2(){}
 
-        void update( Cepheus::Input *input, Cepheus::Manager *m){
-            std::cout << ">> Updating Scene 2" << std::endl;
+        // Override some virtual methods.
+        void leftClick(Cepheus::Mouse mouse, Cepheus::SceneManager *sm) {}
+        void rightClick(Cepheus::Mouse mouse, Cepheus::SceneManager *sm){}
+        void keyPress(Cepheus::Key k, Cepheus::SceneManager *sm){}
+        
+        void update(Cepheus::Input *in, Cepheus::SceneManager *sm){
+             std::cout << ">> Updating Scene 2" << std::endl;
         }
-
         void render(Cepheus::GraphicManager *gm){
             std::cout << "\t:: Rendering Scene 2" << std::endl;
-        }    
+        }
 };
 class Test3 : public Cepheus::Game{
     private:
             }
 
             // Do all logic stuff here.
-            // getSceneManager()->getCurrentScene()->update( getInput(), getSceneManager() );
-            for(int i = 0 ; i < getSceneManager()->getScenes()->size(); i++ ){
+            for(int i = 0 ; i < getSceneManager()->getComponents()->size(); i++ ){
                 getSceneManager()
-                        ->getScene(i)
-                            ->update( getInput(), getSceneManager() );
+                        ->getComponent(i)->update( getInput(), getSceneManager() );
             }
         }
 
             gm->getScreen()->clear();
 
             // Do all rendering stuff here.
-            // getSceneManager()->getScenes->render(gm);
-            for(int i = 0 ; i < getSceneManager()->getScenes()->size(); i++ ){
-                getSceneManager()->getScene(i)->render(gm);
-            }
-
-            // Render back graphic buffer.
+            //  ........
+            
+            // Then render the scene.
             gm->getScreen()->render();
         }
 };
     game->getGraphicManager()->getScreen()->init();
     game->getGraphicManager()->getScreen()->setTitle("Test 3");
 
-    // Initialize starting Scene
-    game->getSceneManager()->addScene( new Scene1() );
-    game->getSceneManager()->addScene( new Scene2() );
+    // Initializing Scenes
+    game->getSceneManager()->addComponent( new Scene1() );
+    game->getSceneManager()->addComponent( new Scene2() );
+
     game->getSceneManager()->setCurrentScene(0);
     
     // Let's Go

src/tests/test4.cpp

                this->exit();
             }
             // Do all logic stuff here.
+//             getSceneManager()->getCurrentScene()->update( getSceneManager() );
+            std::cout<< ":: Doing stuff" << std::endl;
         }
 
         // Override render method.