PhysicsComponent.hpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #ifndef engine_physics_PhysicsComponent_hpp
00023 #define engine_physics_PhysicsComponent_hpp
00024 
00025 #include "Physics.hpp"
00026 #include "Move.hpp"
00027 #include "comp/Component.hpp"
00028 #include "comp/node/NodeComponent.hpp"
00029 #include "../area/sim_area.hpp"
00030 #include "../custom/sim_custom.hpp"
00031 #include "../stat/sim_stat.hpp"
00032 #include "../thing/sim_thing.hpp"
00033 #include "../pos/PosComponent.hpp"
00034 #include "../react/ThingCollide.hpp"
00035 
00036 namespace se_core {
00037     class _SeCoreExport PhysicsComponent : public NodeComponent {
00038     public:
00039         typedef ComponentPtr<PhysicsComponent, sct_PHYSICS> Ptr;
00040 
00041         static PhysicsComponent* get(Composite& composite) {
00042             PhysicsComponent* c = static_cast<PhysicsComponent*>(composite.component(se_core::sct_PHYSICS));
00043             return c;
00044         }
00045 
00046         static const PhysicsComponent* get(const Composite& composite) {
00047             const PhysicsComponent* c = static_cast<const PhysicsComponent*>(composite.component(se_core::sct_PHYSICS));
00048             return c;
00049         }
00050 
00051         static PhysicsComponent* get(Component& component) {
00052             PhysicsComponent* c = static_cast<PhysicsComponent*>(component.owner()->component(se_core::sct_PHYSICS));
00053             return c;
00054         }
00055 
00056         static const PhysicsComponent* get(const Component& component) {
00057             const PhysicsComponent* c = static_cast<const PhysicsComponent*>(component.owner()->component(se_core::sct_PHYSICS));
00058             return c;
00059         }
00060 
00061 
00062 
00065         PhysicsComponent(Composite* owner, PosComponent* posComponent);
00066         PhysicsComponent(Composite* owner, const ComponentFactory* factory);
00067         ~PhysicsComponent();
00068 
00069         bool calcNextCoor();
00070 
00071         void affect() {
00072             if(!affect_)
00073                 return;
00074             affect_->affect(*this);
00075         }
00076 
00077         void pushPhysics(const char* name);
00078         void pushPhysics(const Physics *ph);
00079         void popPhysics();
00080         void clearPhysics();
00081 
00082         inline const Move& move() const {
00083             return move_;
00084         }
00085 
00086         inline Move& nextMove() {
00087             return nextMove_;
00088         }
00089 
00090         void setDefaultPhysics(const Physics* ph) {
00091             physics_[0] = ph;
00092         }
00093 
00094         bool isMover() const;
00095 
00096         void flip();
00097         bool didMove() const {
00098             return didMove_;
00099         }
00100 
00101         //inline bool hasPhysics() const {
00102         //  return (currentPhysics_ >= 0 && physics_[currentPhysics_] != 0);
00103         //}
00104 
00105     private:
00106         inline bool hasDefaultPhysics() const {
00107             return (physics_[0] != 0);
00108         }
00109 
00110         inline const Physics& physics() {
00111             return *physics_[currentPhysics_];
00112         }
00113         inline const Physics& physics() const {
00114             return *physics_[currentPhysics_];
00115         }
00116 
00117         short currentPhysics_;
00118         static const short MAX_PHYSICS_STACK_SIZE = 4;
00119         const Physics* physics_[ MAX_PHYSICS_STACK_SIZE ];
00120         const Physics* affect_;
00121         friend class PhysicsAreaComponent;
00122         PosComponent* posComponent_;
00123 
00124         Move move_, nextMove_;
00125 
00126         bool didMove_;
00127     };
00128 }
00129 
00130 #endif

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:11 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo