ZoneAreaComponent.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 ZoneAreaComponent_hpp
00023 #define ZoneAreaComponent_hpp
00024 
00025 #include "comp/comp.hpp"
00026 #include "comp/node/RootChildComponent.hpp"
00027 #include "comp/list/ComponentList.hpp"
00028 #include "util/vecmath/util_vecmath.hpp"
00029 #include "sim/sim.hpp"
00030 #include "Exit.hpp"
00031 
00032 
00033 namespace se_core {
00034     class _SeCoreExport Page {
00035     public:
00036         int x_, y_, z_, w_;
00037 
00038         Page() {}
00039         Page(int x, int y, int z, int w) : x_(x), y_(y), z_(z), w_(w) {}
00040         Page(const Page& p1, const Page& p2) 
00041                 : x_(p1.x_ - p2.x_), y_(p1.y_ - p2.y_), z_(p1.z_ - p2.z_), w_(p1.w_ - p2.w_) {
00042         }
00043 
00044 
00045         void set(int x, int y, int z, int w) {
00046             x_ = x;
00047             y_ = y;
00048             z_ = z;
00049             w_ = w;
00050         }
00051 
00052 
00053         void sub(const Page& p1, const Page& p2) {
00054             x_ = p1.x_ - p2.x_;
00055             y_ = p1.y_ - p2.y_;
00056             z_ = p1.z_ - p2.z_;
00057             w_ = p1.w_ - p2.w_;
00058         }
00059 
00060 
00061         bool isNeighbourOffset() const {
00062             return (x_ >= -1 && x_ <= 1
00063                 && y_ >= -1 && y_ <= 1
00064                 && z_ >= -1 && z_ <= 1
00065                 && w_ == 0);
00066         }
00067 
00068 
00069         void clampToNeighbourOffset(const Page& rel) {
00070             x_ = rel.x_;
00071             y_ = rel.y_;
00072             z_ = rel.z_;
00073             w_ = rel.w_;
00074 
00075             if(x_ < -1) x_ = -1;
00076             if(x_ > 1) x_ = 1;
00077 
00078             if(y_ < -1) z_ = -1;
00079             if(y_ > 1) z_ = 1;
00080 
00081             if(z_ < -1) z_ = -1;
00082             if(z_ > 1) z_ = 1;
00083         }
00084     };
00085 
00086 
00087     class _SeCoreExport ZoneAreaComponent : public RootChildComponent {
00088     public:
00089         typedef ComponentPtr<ZoneAreaComponent, sct_ZONE> Ptr;
00090 
00091 
00092 
00095         ZoneAreaComponent(Composite* owner, const ComponentFactory* factory = 0);
00096         ~ZoneAreaComponent();
00097         void setActive(bool state);
00098 
00099         const char* name() const { return "ZoneArea"; }
00100 
00101         void offset(const ZoneAreaComponent& other, Page& dest) const;
00102         bool offset(const ZoneAreaComponent& other, const Vector3& size, Vector3& dest) const;
00103 
00104         Page& page() { return page_; }
00105         const Page& page() const { return page_; }
00106 
00107         bool addNeighbour(ZoneAreaComponent& other);
00108         int neighbourIndex(const Page& rel) const;
00109         ZoneAreaComponent* neighbour(int relX, int relY, int relZ);
00110         const ZoneAreaComponent* neighbour(int relX, int relY, int relZ) const;
00111 
00112         void addLink(ZoneAreaComponent& link);
00113         ComponentList& links() { return links_; }
00114         void setExits(Exit* exits, int count);
00115         Exit& exit(int id);
00116         const Exit& exit(int id) const;
00117         int exitCount() const { return exitCount_; }
00118 
00119     protected:
00120         friend class ZoneAreaComponentFactory;
00121 
00122         Page page_;
00123         ComponentList links_;
00124         static const int MAX_NEIGHBOURS = 3 * 3 * 3;
00125         ZoneAreaComponent* neighbours_[ MAX_NEIGHBOURS ];
00126         int exitCount_;
00127         Exit* exits_;
00128     };
00129 }
00130 
00131 #endif

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

SourceForge.net Logo