chunkter.h

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2001 The Exult Team
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifndef CHUNKTER_H
00026 #define CHUNKTER_H
00027 
00028 #include "shapeid.h"
00029 
00030 class Image_buffer8;
00031 class GL_texshape;
00032 
00033 /*
00034  *  The flat landscape, 16x16 tiles:
00035  */
00036 class Chunk_terrain : public Game_singletons
00037   {
00038   ShapeID shapes[256];    // Id's.  The flat (non-RLE's) are
00039           //   rendered here, the others are
00040           //   turned into Game_objects in the
00041           //   chunks that point to us.
00042   ShapeID *undo_shapes;   // Set to prev. values when editing.
00043   int num_clients;    // # of Chunk's that point to us.
00044   bool modified;      // Changed (by map-editor).
00045   Image_buffer8 *rendered_flats;  // Flats rendered for entire chunk.
00046   GL_texshape *glflats;   // OpenGL texture from rendered_flats.
00047           // Most-recently used circular queue
00048           //   for rendered_flats:
00049   static Chunk_terrain *render_queue;
00050   static int queue_size;
00051   Chunk_terrain *render_queue_next, *render_queue_prev;
00052           //   Kept only for nearby chunks.
00053   void insert_in_queue();   // Queue methods.
00054   void remove_from_queue();
00055           // Create rendered_flats.
00056   void paint_tile(int tilex, int tiley);
00057   Image_buffer8 *render_flats();
00058   void free_rendered_flats();
00059 public:
00060           // Create from 16x16x2 data:
00061   Chunk_terrain(unsigned char *data);
00062           // Copy-constructor:
00063   Chunk_terrain(const Chunk_terrain& c2);
00064   ~Chunk_terrain();
00065   inline void add_client()
00066     { num_clients++; }
00067   inline void remove_client()
00068     { num_clients--; }
00069   inline bool is_modified()
00070     { return modified; }
00071   inline void set_modified(bool tf = true)
00072     { modified = tf; }
00073 #if 0
00074           // Less-than c2 (for STL Map)?
00075   bool operator<(const Chunk_terrain& c2) const;
00076 #endif
00077           // Get tile's shape ID.
00078   inline ShapeID get_flat(int tilex, int tiley) const
00079     { return shapes[16*tiley + tilex]; }
00080 
00081   inline Shape_frame *get_shape(int tilex, int tiley)
00082     { return shapes[16*tiley + tilex].get_shape(); }
00083 
00084           // Set tile's shape.
00085   void set_flat(int tilex, int tiley, ShapeID id);
00086   bool commit_edits();    // Commit changes.  Rets. true if
00087           //   edited.
00088   void abort_edits();   // Undo changes.
00089   Image_buffer8 *get_rendered_flats()
00090     {
00091     if (render_queue != this)// Not already first in queue?
00092           // Move to front of queue.
00093       insert_in_queue();
00094     return rendered_flats
00095       ? rendered_flats : render_flats();
00096     }
00097   GL_texshape *get_glflats()
00098     { get_rendered_flats();  return glflats; }
00099   void render_all(int cx, int cy);// Render (in terrain-editing mode).
00100           // Write out to chunk.
00101   void write_flats(unsigned char *chunk_data);
00102   };
00103 
00104 
00105 
00106 #endif

Generated on Mon Jul 9 14:42:49 2007 for ExultEngine by  doxygen 1.5.1