SpaceOrg.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 5 -*- */
00002 
00003 /*
00004  * Combination of a first person action and a real time strategy battle game.
00005  */
00006 
00007 /*
00008  * SpaceOrg.h
00009  * MetalWarriors
00010  * $Revision: 1.7 $
00011  *
00012  * Created by Daniel Aarno on Sun Oct 12 2003.
00013  * Copyright (c) 2003 Daniel Aarno and Erik Ytterberg - All rights reserved.
00014  *
00015  *     This program is free software; you can redistribute it and/or modify
00016  *     it under the terms of the GNU General Public License as published by
00017  *     the Free Software Foundation; either version 2 of the License, or
00018  *     (at your option) any later version.
00019  *
00020  *     This program is distributed in the hope that it will be useful,
00021  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *     GNU General Public License for more details.
00024  *
00025  *     You should have received a copy of the GNU General Public License
00026  *     along with this program; if not, write to the Free Software
00027  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00028  */
00029 
00030 #ifndef SPACEORG_H
00031 #define SPACEORG_H
00032 
00033 #include <list>
00034 #include "Sprite.h"
00035 
00036 #define SPACEORG_SOLID_BIT 0x40000000u
00037 
00038 typedef struct{
00039   std::list<Sprite*> solid;
00040   std::list<Sprite*> transparent;
00041 }space_segment_t;
00042 
00043 class SpaceOrg
00044 {
00045 protected:
00046      space_segment_t **space;
00047      float size_x, size_y;
00048      float resolution;
00049      int cull_segments;
00050      unsigned int squares_x;
00051      unsigned int squares_y;
00052      
00053 public:
00054      SpaceOrg(float x_size, float y_size, float res, int no_segments_cull);
00055      ~SpaceOrg(void);
00056      void putSprite(Sprite *sprite, unsigned int index);
00057      int delSprite(Sprite *sprite, unsigned int index);
00058      int putTransparent(Sprite *sprite, unsigned int &index);
00059      void updateSpritePos(Sprite *sprite, unsigned int &index);
00060      /*Note that the index given determines if the returned sprite list
00061        will contain transparent or solid sprites */
00062      std::list<Sprite*> *getSprites(unsigned int &index, int xoffset, int yoffset);
00063      /*Will currently return only transparent sprites*/
00064      std::list<Sprite*> *getSprites(float x_pos, float y_pos);
00065      void getIndexForPos(float x_pos, float y_pos, unsigned int &index);
00066      void draw(void);
00067      
00068      /*dont use this method, very slow*/
00069      int getIndexForSprite(Sprite *sprite, int *index_x, int *index_y);
00070      
00071 protected:
00072      inline unsigned int coord2Index(float x, float y);
00073      inline int indexGetX(unsigned int index);
00074      inline int indexGetY(unsigned int index);
00075      inline bool indexIsSolid(unsigned int index);
00076      void setCullArea(int *check_start_x, int *check_start_y,
00077                       int *check_stop_x, int *check_stop_y);
00078      
00079 };
00080 
00081 #endif /*SPACEORG_H*/

Generated on Sun Mar 11 15:33:23 2007 for MetalWarriors by  doxygen 1.4.7