00001 /* 00002 Copyright (c) 2009, Dan Hagerstrand and contributors 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, 00009 this list of conditions and the following disclaimer. 00010 00011 * Redistributions in binary form must reproduce the above copyright notice, 00012 this list of conditions and the following disclaimer in the documentation 00013 and/or other materials provided with the distribution. 00014 00015 * Neither the name of Cirrus Creative nor the names of its 00016 contributors may be used to endorse or promote products derived from this 00017 software without specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00023 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00024 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00025 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 00032 #ifndef BENG_LAYER_H 00033 #define BENG_LAYER_H 00034 00035 #include <bitset> 00036 00037 #include <list> 00038 00039 #include "Array2d.h" 00040 #include "BengFixedPoint.h" 00041 #include "BengInterface.h" 00042 #include "BengIntern.h" 00043 #include "Object.h" 00044 #include "Resource.h" 00045 #include "System.h" 00046 #include "Scene.h" 00047 00048 class BengSystem; 00049 class BengScene; 00050 class BengObject; 00051 00052 class BengLayer : public BengArray2D<short int> { 00053 friend class BengObject; 00054 friend class BengScene; 00055 friend class BengIGfx; 00056 00057 private: 00058 00059 BengScene *scene_; 00060 00061 unsigned int tileSizeX_; 00062 unsigned int tileSizeY_; 00063 00064 BengVector offset_; 00065 BengVector scrollSpeed_; 00066 BengVector scrollSpeedAuto_; 00067 00068 std::list<BengObject*> objectList_; 00069 std::list<BengObject*>::iterator objectIterator_; 00070 00071 BengResource<BengISprite> *tileset_; 00072 00073 int objectsForDeletion_; 00074 char deleteAll_; 00075 00076 std::bitset<8> internFlags_; 00077 00078 void purgeObjects_(void); 00079 00080 public: 00081 00082 BengLayer(unsigned int xsize, unsigned int ysize) : BengArray2D<short int>(xsize, ysize) 00083 { 00084 this->offset_.x = this->offset_.y = this->scrollSpeed_.x = this->scrollSpeed_.y 00085 = this->scrollSpeedAuto_.x = this->scrollSpeedAuto_.y 00086 = this->objectsForDeletion_ = this->deleteAll_ = 0; 00087 00088 this->internFlags_.reset(); 00089 this->internFlags_[BENG_LAYER_INTERN_JUST_CREATED] 00090 = this->internFlags_[BENG_LAYER_INTERN_VISIBLE] = true; 00091 00092 this->tileset_ = NULL; 00093 } 00094 ~BengLayer(void); 00095 00096 BengScene *getScene(void); 00097 BengSystem *getSystem(void); 00098 00099 void setOffset(BengFixed xIn, BengFixed yIn); // TODO: Implement functionality in real-world 00100 void getOffset(BengVector &out); 00101 void setScrollSpeed(BengFixed xIn, BengFixed yIn); 00102 void getScrollSpeed(BengVector &out); 00103 void setScrollSpeedAuto(BengFixed xIn, BengFixed yIn); 00104 void getScrollSpeedAuto(BengVector &out); 00105 00106 void addObject(BengObject *object); 00107 void clearObjects(void); 00108 int getNumObjects(void); 00109 00110 void setVisibility(bool visibility); 00111 bool getVisibility(void); 00112 00113 void getTileSize(unsigned int &xOut, unsigned int &yOut); 00114 void setTileSize(unsigned int xIn, unsigned int yIn); 00115 00116 void setTileset(BengResource<BengISprite> *tileset) 00117 { 00118 this->tileset_ = tileset; 00119 } 00120 00121 BengResource<BengISprite> *getTileset(void); 00122 00123 void process(void); 00124 00125 void destroy(void); 00126 00127 }; 00128 00129 #endif
1.5.8