Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ani_texture.h
Go to the documentation of this file.
1 #ifndef __ANI_TEXTURE_H__
2 #define __ANI_TEXTURE_H__
3 
4 #include "aux_texture.h"
5 #include "vsfilesystem.h"
6 #include "vid_file.h"
7 
8 #include <stdio.h>
9 #include "../SharedPool.h"
10 
11 #include "audio/Types.h"
12 #include "audio/Source.h"
13 
14 class AnimatedTexture : public Texture
15 {
16  Texture **Decal;
17  unsigned int activebound; //For video mode
18  double physicsactive;
19  bool loadSuccess;
20  void AniInit();
21 
22  //For video mode
23  bool vidMode;
24  bool detailTex;
25  enum FILTER ismipmapped;
26  int texstage;
27  SharedPtr<Audio::Source> timeSource;
28 
29  vector< StringPool::Reference >frames; //Filenames for each frame
30  vector< Vector >frames_maxtc; //Maximum tcoords for each frame
31  vector< Vector >frames_mintc; //Minimum tcoords for each frame
32 
33  VidFile *vidSource;
34 
35  StringPool::Reference wrapper_file_path;
36  VSFileSystem::VSFileType wrapper_file_type;
37 
38  //Options
39  enum optionenum
40  {
41  optInterpolateFrames=0x01,
42  optInterpolateTCoord=0x02,
43  optLoopInterp =0x04,
44  optLoop=0x08,
45  optSoundTiming=0x10
46  };
47  unsigned char options;
48 
49  //Implementation
50  GFXColor multipass_interp_basecolor;
51  enum ADDRESSMODE defaultAddressMode; //default texture address mode, read from .ani
52 
53 protected:
54  unsigned int numframes;
55  float timeperframe;
56  unsigned int active;
57  unsigned int nextactive; //It is computable, but it's much more convenient this way
58  float active_fraction; //For interpolated animations
59  double curtime;
60 
61  // for video de-jittering
62  double lastcurtime;
63  double lastrealtime;
64 
66  bool done;
67 
68 public:
69  virtual void setTime( double tim );
70 
71  virtual double curTime() const
72  {
73  return curtime;
74  }
75 
76  virtual unsigned int numFrames() const
77  {
78  return numframes;
79  }
80 
81  virtual float framesPerSecond() const
82  {
83  return 1/timeperframe;
84  }
85 
86  virtual unsigned int numLayers() const;
87 
88  virtual unsigned int numPasses() const;
89 
90  virtual bool canMultiPass() const
91  {
92  return true;
93  }
94 
95  virtual bool constFrameRate() const
96  {
97  return constframerate;
98  }
99 
100  AnimatedTexture();
101  AnimatedTexture( int stage, enum FILTER imm, bool detailtexture = false );
102  AnimatedTexture( const char *file, int stage, enum FILTER imm, bool detailtexture = false );
103  AnimatedTexture( VSFileSystem::VSFile &openedfile, int stage, enum FILTER imm, bool detailtexture = false );
104 
105  void Load( VSFileSystem::VSFile &f, int stage, enum FILTER ismipmapped, bool detailtex = false );
106  void LoadAni( VSFileSystem::VSFile &f, int stage, enum FILTER ismipmapped, bool detailtex = false );
108 
109  virtual void LoadFrame( int num ); //For video mode
110 
111  void Destroy();
112 
113  virtual const Texture * Original() const;
114  virtual Texture * Original();
116  virtual Texture * Clone();
117 
118  virtual void MakeActive()
119  {
120  MakeActive( texstage, 0 );
121  } //MSVC bug seems to hide MakeActive() if we define MakeActive(int,int) - the suckers!
122 
123  virtual void MakeActive( int stage )
124  {
125  MakeActive( stage, 0 );
126  } //MSVC bug seems to hide MakeActive(int) if we define MakeActive(int,int) - the suckers!
127 
128  virtual void MakeActive( int stage, int pass );
129 
130  bool SetupPass( int pass, int stage, const enum BLENDFUNC src, const enum BLENDFUNC dst );
131 
132  bool SetupPass( int pass, const enum BLENDFUNC src, const enum BLENDFUNC dst )
133  {
134  return SetupPass( pass, texstage, src, dst );
135  }
136 
137  void SetInterpolateFrames( bool set )
138  {
139  options = (options&~optInterpolateFrames)|(set ? optInterpolateFrames : 0);
140  }
141 
142  void SetInterpolateTCoord( bool set )
143  {
144  options = (options&~optInterpolateTCoord)|(set ? optInterpolateTCoord : 0);
145  }
146 
147  void SetLoopInterp( bool set )
148  {
149  options = (options&~optLoopInterp)|(set ? optLoopInterp : 0);
150  }
151 
152  void SetLoop( bool set )
153  {
154  options = (options&~optLoop)|(set ? optLoop : 0);
155  }
156 
157  bool GetInterpolateFrames() const
158  {
159  return (options&optInterpolateFrames) != 0;
160  }
161 
162  bool GetInterpolateTCoord() const
163  {
164  return (options&optInterpolateTCoord) != 0;
165  }
166 
167  bool GetLoopInterp() const
168  {
169  return (options&optLoopInterp) != 0;
170  }
171 
172  bool GetLoop() const
173  {
174  return (options&optLoop) != 0;
175  }
176 
177  SharedPtr<Audio::Source> GetTimeSource() const
178  {
179  return (options&optSoundTiming) ? timeSource : SharedPtr<Audio::Source>();
180  }
181 
182  void SetTimeSource( SharedPtr<Audio::Source> source );
183 
184  void ClearTimeSource();
185 
186  static void UpdateAllPhysics();
187  static void UpdateAllFrame();
188 
189  //resets the animation to beginning
190  void Reset();
191  bool Done() const;
192 
193  virtual bool LoadSuccess();
194 
195  //Some useful factory methods -- also defined in ani_texture.cpp
196  static AnimatedTexture * CreateVideoTexture( const std::string &fname,
197  int stage = 0,
198  enum FILTER ismipmapped = BILINEAR,
199  bool detailtex = false );
200 };
201 
202 #endif
203