Main Page   Class Hierarchy   Compound List   File List   Compound Members  

proctex.h

00001 /*
00002     Copyright (C) 2000-2001 by Jorrit Tyberghein
00003     Copyright (C) 2000 by Samuel Humphreys
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __PROCTEX_H__
00021 #define __PROCTEX_H__
00022 
00023 #include <stdarg.h>
00024 #include "csutil/csobject.h"
00025 
00026 struct iTextureWrapper;
00027 struct iMaterialWrapper;
00028 struct iEngine;
00029 
00030 struct iObjectRegistry;
00031 struct iGraphics2D;
00032 struct iGraphics3D;
00033 struct iTextureManager;
00034 struct iTextureWrapper;
00035 
00036 class csProcTexture : public csObject
00037 {
00038   friend struct ProcCallback;
00039 
00040 protected:
00041   // Will be set to true as soon as pt is initialized.
00042   bool ptReady;
00043 
00044   // Flags uses for the texture.
00045   int texFlags;
00046 
00047   // Texture wrapper.
00048   iTextureWrapper* tex;
00049   // Dimensions of texture.
00050   int mat_w, mat_h; 
00051   // Procedural G3D and G2D.
00052   iGraphics3D* ptG3D;
00053   iGraphics2D* ptG2D;
00054   iTextureManager* ptTxtMgr;
00055   iObjectRegistry* object_reg;
00056   bool anim_prepared;
00057 
00058   bool key_color;
00059   int key_red, key_green, key_blue;
00060 
00061   // If true (default) then proc texture will register a callback
00062   // so that the texture is automatically updated (Animate is called)
00063   // whenever it is used.
00064   bool use_cb;
00065   // The current time the previous time the callback was called.
00066   // This is used to detect if the callback is called multiple times
00067   // in one frame.
00068   csTicks last_cur_time;
00069 
00070 private:
00071   static void ProcCallback (iTextureWrapper* txt, void* data);
00072 
00073 public:
00074   csProcTexture ();
00075   virtual ~csProcTexture ();
00076 
00084   void DisableAutoUpdate () { use_cb = false; }
00085 
00100   virtual bool Initialize (iObjectRegistry* object_reg);
00101 
00111   iMaterialWrapper* Initialize (iObjectRegistry* object_reg, iEngine* engine,
00112         iTextureManager* txtmgr, const char* name);
00113 
00118   virtual bool PrepareAnim ();
00119 
00121   void SetKeyColor (int red, int green, int blue)
00122   {
00123     key_color = true;
00124     key_red = red;
00125     key_green = green;
00126     key_blue = blue;
00127   }
00128   
00133   virtual void Animate (csTicks current_time) = 0;
00134 
00136   iTextureWrapper* GetTextureWrapper () { return tex; }
00137 
00139   virtual void GetDimension (int &w, int &h)
00140   { w = w; h = mat_h; }
00141 
00142   static int GetRandom (int max)
00143   {
00144     return (int)(float(max)*rand()/(RAND_MAX+1.0));
00145   }
00146 };
00147 
00148 
00149 #endif // __PROCTEX_H__
00150 

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000