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
AnimatedTexture Class Reference

#include <ani_texture.h>

Inheritance diagram for AnimatedTexture:
Texture Animation

Public Member Functions

virtual void setTime (double tim)
 
virtual double curTime () const
 
virtual unsigned int numFrames () const
 
virtual float framesPerSecond () const
 
virtual unsigned int numLayers () const
 
virtual unsigned int numPasses () const
 
virtual bool canMultiPass () const
 
virtual bool constFrameRate () const
 
 AnimatedTexture ()
 
 AnimatedTexture (int stage, enum FILTER imm, bool detailtexture=false)
 
 AnimatedTexture (const char *file, int stage, enum FILTER imm, bool detailtexture=false)
 
 AnimatedTexture (VSFileSystem::VSFile &openedfile, int stage, enum FILTER imm, bool detailtexture=false)
 
void Load (VSFileSystem::VSFile &f, int stage, enum FILTER ismipmapped, bool detailtex=false)
 
void LoadAni (VSFileSystem::VSFile &f, int stage, enum FILTER ismipmapped, bool detailtex=false)
 
void LoadVideoSource (VSFileSystem::VSFile &f)
 
virtual void LoadFrame (int num)
 
void Destroy ()
 
virtual const TextureOriginal () const
 
virtual TextureOriginal ()
 
 ~AnimatedTexture ()
 
virtual TextureClone ()
 
virtual void MakeActive ()
 Binds the texture in the GFX library. More...
 
virtual void MakeActive (int stage)
 
virtual void MakeActive (int stage, int pass)
 
bool SetupPass (int pass, int stage, const enum BLENDFUNC src, const enum BLENDFUNC dst)
 
bool SetupPass (int pass, const enum BLENDFUNC src, const enum BLENDFUNC dst)
 
void SetInterpolateFrames (bool set)
 
void SetInterpolateTCoord (bool set)
 
void SetLoopInterp (bool set)
 
void SetLoop (bool set)
 
bool GetInterpolateFrames () const
 
bool GetInterpolateTCoord () const
 
bool GetLoopInterp () const
 
bool GetLoop () const
 
SharedPtr< Audio::SourceGetTimeSource () const
 
void SetTimeSource (SharedPtr< Audio::Source > source)
 
void ClearTimeSource ()
 
void Reset ()
 
bool Done () const
 
virtual bool LoadSuccess ()
 If the texture has loaded properly returns true. More...
 
- Public Member Functions inherited from Texture
void FileNotFound (const std::string &)
 
GFXBOOL checkold (const std::string &s, bool shared, std::string &hashname)
 Returns if this texture is actually already loaded. More...
 
void modold (const std::string &s, bool shared, std::string &hashname)
 
void setold ()
 Loads the old texture. More...
 
bool checkbad (const string &s)
 
void setbad (const string &s)
 
void InitTexture ()
 Inits the class with default values. More...
 
int Bind (Texture *other, int maxdimension=65536, GFXBOOL detailtexture=GFXFALSE)
 Binds this texture to the same name as the given texture - for multipart textures. More...
 
 Texture (int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE)
 Creates an unbounded texture. Set data and dimensions before binding. Or explicitly load a file. More...
 
 Texture (const char *, const char *, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, float alpha=1, int zeroval=0, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 Creates a texture with a single bitmap as color data and another grayscale .bmp as alpha data. More...
 
 Texture (const char *FileName, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 Creates a texture with only color data as a single bitmap. More...
 
 Texture (VSFileSystem::VSFile *f, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 
void Load (const char *, const char *, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, float alpha=1, int zeroval=0, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 
void Load (const char *FileName, int stage=0, enum FILTER mipmap=MIPMAP, enum TEXTURE_TARGET target=TEXTURE2D, enum TEXTURE_IMAGE_TARGET imagetarget=TEXTURE_2D, GFXBOOL force=GFXFALSE, int max_dimension_size=65536, GFXBOOL detail_texture=GFXFALSE, GFXBOOL nocache=false, enum ADDRESSMODE address_mode=DEFAULT_ADDRESS_MODE, Texture *main=0)
 
virtual ~Texture ()
 Texture copy constructor that increases appropriate refcounts. More...
 
int getStage () const
 
int getFilter () const
 
int getTarget () const
 
int getImageTarget () const
 
bool operator< (const Texture &b) const
 A way to sort the texture by the original address (to make sure like textures stick togehter. More...
 
bool operator== (const Texture &b) const
 A way to test if the texture is equal to another based on original values. More...
 
void setReference (Texture *other)
 Make this instance a reference of "other". More...
 
virtual void Prioritize (float)
 Changes priority of texture. More...
 

Static Public Member Functions

static void UpdateAllPhysics ()
 
static void UpdateAllFrame ()
 
static AnimatedTextureCreateVideoTexture (const std::string &fname, int stage=0, enum FILTER ismipmapped=BILINEAR, bool detailtex=false)
 
- Static Public Member Functions inherited from Texture
static TextureExists (std::string s)
 Whether or not the string exists as a texture. More...
 
static TextureExists (std::string s, std::string a)
 Whether or not the color and alpha data already exist. More...
 

Protected Attributes

unsigned int numframes
 
float timeperframe
 
unsigned int active
 
unsigned int nextactive
 
float active_fraction
 
double curtime
 
double lastcurtime
 
double lastrealtime
 
bool constframerate
 
bool done
 

Additional Inherited Members

- Public Attributes inherited from Texture
StringPool::Reference texfilename
 The file name used to load this texture. More...
 
enum FILTER ismipmapped
 the filter mode of this texture More...
 
unsigned char * data
 The data of this texture (used in between functions, deleted) More...
 
int name
 The GFXname of this texture. More...
 
int stage
 The multitexture stage of this texture. More...
 
Vector mintcoord
 The minimum/maximum texturing coordinates for this texture (have in mind that it is not always enforce, ie. for meshes) (i=s, j=t, k=u) More...
 
Vector maxtcoord
 
Textureoriginal
 The original data that would represent this texture. More...
 
bool bound
 For re-biding. More...
 
uint boundSizeX
 
uint boundSizeY
 
VSImageMode boundMode
 
int refcount
 The number of references on the original data. More...
 
enum TEXTURE_TARGET texture_target
 The target this will go to (cubemap or otherwise) More...
 
enum TEXTURE_IMAGE_TARGET image_target
 
enum ADDRESSMODE address_mode
 The address mode being used with this texture. More...
 
- Protected Member Functions inherited from Texture
int Bind (int maxdimension, GFXBOOL detailtexture)
 Binds this texture to GFX library. More...
 
void UnBind ()
 UnBinds from GFX library. More...
 
void Transfer (int maxdimension, GFXBOOL detailtexture)
 Transfers this texture to GFX library. More...
 

Detailed Description

Definition at line 14 of file ani_texture.h.

Constructor & Destructor Documentation

AnimatedTexture::AnimatedTexture ( )

Definition at line 377 of file ani_texture.cpp.

Referenced by Clone(), and CreateVideoTexture().

378 {
379  AniInit();
380 }
AnimatedTexture::AnimatedTexture ( int  stage,
enum FILTER  imm,
bool  detailtexture = false 
)

Definition at line 328 of file ani_texture.cpp.

328  :
329  Texture( stage, imm )
330 {
331  AniInit();
332 }
AnimatedTexture::AnimatedTexture ( const char *  file,
int  stage,
enum FILTER  imm,
bool  detailtexture = false 
)

Definition at line 265 of file ani_texture.cpp.

References VSFileSystem::AnimFile, VSFileSystem::VSFile::Close(), f, VSFileSystem::VSFile::Fscanf(), height, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), and width.

266 {
267  AniInit();
268  VSFile f;
269  VSError err = f.OpenReadOnly( file, AnimFile );
270  //bool setdir=false;
271  if (err <= Ok) {
272  float width, height;
273  f.Fscanf( "%f %f", &width, &height ); //it's actually an animation in global animation shares
274  //setdir=true;
275  }
276  if (err <= Ok) {
277  Load( f, stage, imm, detailtex );
278  f.Close();
279  } else {
280  loadSuccess = false;
281  /*
282  * if (setdir) {
283  * VSFileSystem::vs_resetdir();
284  * }
285  */
286  }
287 }
AnimatedTexture::AnimatedTexture ( VSFileSystem::VSFile openedfile,
int  stage,
enum FILTER  imm,
bool  detailtexture = false 
)

Definition at line 322 of file ani_texture.cpp.

323 {
324  AniInit();
325  Load( fp, stage, imm, detailtex );
326 }
AnimatedTexture::~AnimatedTexture ( )

Definition at line 369 of file ani_texture.cpp.

References active, Texture::data, and Destroy().

370 {
371  Destroy();
372  data = NULL;
373  active = 0;
374  palette = NULL;
375 }

Member Function Documentation

virtual bool AnimatedTexture::canMultiPass ( ) const
inlinevirtual

Reimplemented from Texture.

Definition at line 90 of file ani_texture.h.

91  {
92  return true;
93  }
void AnimatedTexture::ClearTimeSource ( )

Definition at line 747 of file ani_texture.cpp.

748 {
749  timeSource.reset();
750  options &= ~optSoundTiming;
751 }
Texture * AnimatedTexture::Clone ( )
virtual

Reimplemented from Texture.

Definition at line 344 of file ani_texture.cpp.

References AnimatedTexture(), anis, Texture::bound, Texture::Clone(), f, i, LoadVideoSource(), Texture::name, numframes, and VSFileSystem::VSFile::OpenReadOnly().

345 {
346  AnimatedTexture *retval = new AnimatedTexture();
347  if (Decal) {
348  *retval = *this;
349  int nf = vidMode ? 1 : numframes;
350  retval->Decal = new Texture*[nf];
351  for (int i = 0; i < nf; i++)
352  retval->Decal[i] = Decal[i]->Clone();
353  } else if (vidSource) {
354  *retval = *this;
355  }
356  if (vidSource) {
357  retval->name = -1;
358  retval->bound = false;
360  f.OpenReadOnly( wrapper_file_path, wrapper_file_type );
361  retval->LoadVideoSource( f );
362  } else if (Decal) {
363  //LoadVideoSource adds to anis, otherwise we'll have to add ourselves
364  anis.insert( retval );
365  }
366  return retval;
367 }
virtual bool AnimatedTexture::constFrameRate ( ) const
inlinevirtual

Reimplemented from Texture.

Definition at line 95 of file ani_texture.h.

References constframerate.

96  {
97  return constframerate;
98  }
AnimatedTexture * AnimatedTexture::CreateVideoTexture ( const std::string &  fname,
int  stage = 0,
enum FILTER  ismipmapped = BILINEAR,
bool  detailtex = false 
)
static

Definition at line 487 of file ani_texture.cpp.

References AnimatedTexture(), f, fprintf, LoadVideoSource(), VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), SetLoop(), and VSFileSystem::VideoFile.

Referenced by BaseInterface::Room::BaseVSMovie::SetMovie().

491 {
492  AnimatedTexture *rv = new AnimatedTexture( stage, ismipmapped, detailtex );
494  VSError err = f.OpenReadOnly( fname, VSFileSystem::VideoFile );
495  if (err <= Ok)
496  rv->LoadVideoSource( f );
497  else
498  fprintf( stderr, "CreateVideoTexture could not find %s\n", fname.c_str() );
499 
500  // Videos usually don't want to be looped, so set non-looping as default
501  rv->SetLoop(false);
502 
503  return rv;
504 }
virtual double AnimatedTexture::curTime ( ) const
inlinevirtual

Reimplemented from Texture.

Definition at line 71 of file ani_texture.h.

References curtime.

Referenced by UpdateAllFrame().

72  {
73  return curtime;
74  }
void AnimatedTexture::Destroy ( )

Definition at line 382 of file ani_texture.cpp.

References anis, i, and numframes.

Referenced by ~AnimatedTexture().

383 {
384  anis.erase( this );
385  if (vidSource) {
386  delete vidSource;
387  vidSource = 0;
388  }
389  if (Decal) {
390  int i, nf;
391  nf = vidMode ? 1 : numframes;
392  for (i = 0; i < nf; i++)
393  delete Decal[i];
394  delete[] Decal;
395  Decal = NULL;
396  }
397 }
bool AnimatedTexture::Done ( ) const

Definition at line 248 of file ani_texture.cpp.

References curtime, done, numframes, and timeperframe.

Referenced by VDU::CheckCommAnimation(), VDU::Draw(), Animation::DrawNoTransform(), Animation::DrawNow(), and VDU::GetCommunicating().

249 {
250  //return physicsactive<0;
251  //Explosions aren't working right, and this would fix them.
252  //I don't see the reason for using physics frames as reference, all AnimatedTextures
253  //I've seen are gaphic-only entities (bolts use their own time-keeping system, for instance)
254  //If I'm wrong, and the above line is crucial, well... feel free to fix it.
255  return vidSource ? done : curtime >= numframes*timeperframe;
256 }
virtual float AnimatedTexture::framesPerSecond ( ) const
inlinevirtual

Reimplemented from Texture.

Definition at line 81 of file ani_texture.h.

References timeperframe.

Referenced by SpriteStarVlist::SpriteStarVlist().

82  {
83  return 1/timeperframe;
84  }
bool AnimatedTexture::GetInterpolateFrames ( ) const
inline

Definition at line 157 of file ani_texture.h.

Referenced by MakeActive(), numLayers(), numPasses(), and SetupPass().

158  {
159  return (options&optInterpolateFrames) != 0;
160  }
bool AnimatedTexture::GetInterpolateTCoord ( ) const
inline

Definition at line 162 of file ani_texture.h.

Referenced by MakeActive().

163  {
164  return (options&optInterpolateTCoord) != 0;
165  }
bool AnimatedTexture::GetLoop ( ) const
inline

Definition at line 172 of file ani_texture.h.

Referenced by MakeActive().

173  {
174  return (options&optLoop) != 0;
175  }
bool AnimatedTexture::GetLoopInterp ( ) const
inline

Definition at line 167 of file ani_texture.h.

Referenced by MakeActive().

168  {
169  return (options&optLoopInterp) != 0;
170  }
SharedPtr<Audio::Source> AnimatedTexture::GetTimeSource ( ) const
inline

Definition at line 177 of file ani_texture.h.

Referenced by UpdateAllFrame().

178  {
179  return (options&optSoundTiming) ? timeSource : SharedPtr<Audio::Source>();
180  }
void AnimatedTexture::Load ( VSFileSystem::VSFile f,
int  stage,
enum FILTER  ismipmapped,
bool  detailtex = false 
)

Definition at line 424 of file ani_texture.cpp.

References curtime, VSFileSystem::VSFile::GetType(), LoadAni(), LoadVideoSource(), and VSFileSystem::VideoFile.

Referenced by Animation::Animation().

425 {
426  curtime = 0;
427  frames.clear();
428  frames_maxtc.clear();
429  frames_mintc.clear();
430  if (f.GetType() == VSFileSystem::VideoFile)
431  LoadVideoSource( f );
432  else
433  LoadAni( f, stage, ismipmapped, detailtex );
434 }
void AnimatedTexture::LoadAni ( VSFileSystem::VSFile f,
int  stage,
enum FILTER  ismipmapped,
bool  detailtex = false 
)

Definition at line 506 of file ani_texture.cpp.

References active, alltrim(), anis, curtime, DEFAULT_ADDRESS_MODE, VSFileSystem::VSFile::Eof(), accountXML::file, VSFileSystem::VSFile::Fscanf(), g_game, VSRandom::genrand_int32(), VSFileSystem::VSFile::GetFilename(), VSFileSystem::VSFile::GetType(), GFXFALSE, GFXTRUE, i, j, Texture::maxtcoord, Texture::mintcoord, numframes, VSFileSystem::Ok, Texture::original, XMLSupport::parse_float(), XMLSupport::parse_option_ispresent(), XMLSupport::parse_option_value(), parseAddressMode(), VSFileSystem::VSFile::ReadLine(), Reset(), SetInterpolateFrames(), SetInterpolateTCoord(), SetLoop(), SetLoopInterp(), setTime(), Texture::stage, Texture::Texture(), TEXTURE2D, TEXTURE_2D, timeperframe, game_data_t::use_animations, game_data_t::use_textures, game_data_t::use_videos, Vector, and vsrandom.

Referenced by Load().

507 {
508  char options[1024];
509  f.Fscanf( "%d %f", &numframes, &timeperframe );
510  f.ReadLine( options, sizeof (options)-sizeof (*options) );
511  options[sizeof (options)/sizeof (*options)-1] = 0;
512  alltrim( options );
513 
514  Reset();
515 
516  vidMode = XMLSupport::parse_option_ispresent( options, "video" );
517  SetInterpolateFrames( XMLSupport::parse_option_ispresent( options, "interpolateFrames" ) );
518  SetInterpolateTCoord( XMLSupport::parse_option_ispresent( options, "interpolateTCoord" ) );
519  if ( XMLSupport::parse_option_ispresent( options, "forceLoopInterp" ) )
520  SetLoopInterp( true );
521 
522  else if ( XMLSupport::parse_option_ispresent( options, "forceNoLoopInterp" ) )
523  SetLoopInterp( false );
524  if ( XMLSupport::parse_option_ispresent( options, "forceLoop" ) )
525  SetLoop( true );
526 
527  else if ( XMLSupport::parse_option_ispresent( options, "forceNoLoop" ) )
528  SetLoop( false );
529  if ( XMLSupport::parse_option_ispresent( options, "startRandom" ) ) {
530  int curf = vsrandom.genrand_int32()%numframes;
531  setTime( (0.00001+curf)*timeperframe );
532  }
533  string addrmodestr = XMLSupport::parse_option_value( options, "addressMode", "" );
534  defaultAddressMode = parseAddressMode( addrmodestr, DEFAULT_ADDRESS_MODE );
535 
536  string defms = XMLSupport::parse_option_value( options, "mins", "0" );
537  string defmt = XMLSupport::parse_option_value( options, "mint", "0" );
538  string defmr = XMLSupport::parse_option_value( options, "minr", "0" );
539  string defMs = XMLSupport::parse_option_value( options, "maxs", "1" );
540  string defMt = XMLSupport::parse_option_value( options, "maxt", "1" );
541  string defMr = XMLSupport::parse_option_value( options, "maxr", "1" );
542 
543  int midframe; //FIXME midframe not initialized by all paths below
544  midframe = 0; //FIXME this line temporarily added by chuck_starchaser
545  bool loadall;
546  if (!vidMode)
547  loadall = !( g_game.use_animations == 0 || (g_game.use_animations != 0 && g_game.use_textures == 0) );
548 
549  else
550  loadall = !( g_game.use_videos == 0 || (g_game.use_videos != 0 && g_game.use_textures == 0) );
551  if (!loadall) {
553  midframe = numframes/2;
554  numframes = 1;
555  } //Added by Klauss
556 
557  active = 0;
558  int nf = (vidMode ? 1 : numframes);
559  Decal = new Texture*[nf];
560  if (vidMode) Decal[0] = new Texture;
561  char temp[512] = "white.bmp";
562  char file[512] = "white.bmp";
563  char alp[512] = "white.bmp";
564  char opt[512] = "";
565  int i = 0, j = 0;
566  for (; i < static_cast<int>(numframes); i++)
567  if ( loadall || (i == midframe) ) { //FIXME midframe used without guaranteed initialization
568  //if() added by Klauss
569  int numgets = 0;
570  while ( numgets <= 0 && !f.Eof() ) {
571  if (f.ReadLine( temp, 511 ) == Ok) {
572  temp[511] = '\0';
573  file[0] = 'z';
574  file[1] = '\0';
575  alp[0] = 'z';
576  alp[1] = '\0'; //windows crashes on null
577  opt[0] = 'z';
578  opt[1] = '\0';
579 
580  numgets = sscanf( temp, "%s %s %[^\r\n]", file, alp, opt );
581  if ( (numgets < 2) || (strcmp( alp, "-" ) == 0) ) alp[0] = '\0';
582  alltrim( opt );
583  } else {break; }}
584  if (vidMode) {
585  frames.push_back( StringPool::Reference( string( temp ) ) );
586  frames_mintc.push_back( Vector(
589  XMLSupport::parse_float( XMLSupport::parse_option_value( opt, "minr", defmr ) ) ) );
590  frames_maxtc.push_back( Vector(
593  XMLSupport::parse_float( XMLSupport::parse_option_value( opt, "maxr", defMr ) ) ) );
594  } else {
596  "addressMode",
597  "" ), defaultAddressMode );
598  if (alp[0] != '\0') {
599  Decal[j++] =
600  new Texture( file,
601  alp,
602  stage,
603  ismipmapped,
604  TEXTURE2D,
605  TEXTURE_2D,
606  1,
607  0,
609  65536,
610  (detailtex ? GFXTRUE : GFXFALSE),
611  GFXFALSE,
612  addrmode );
613  } else {
614  Decal[j++] = new Texture( file,
615  stage,
616  ismipmapped,
617  TEXTURE2D,
618  TEXTURE_2D,
620  65536,
621  (detailtex ? GFXTRUE : GFXFALSE),
622  GFXFALSE,
623  addrmode );
624  }
625  if (Decal[j-1]) {
626  Decal[j-1]->mintcoord = Vector(
629  XMLSupport::parse_float( XMLSupport::parse_option_value( opt, "minr", defmr ) ) );
630  Decal[j-1]->maxtcoord = Vector(
633  XMLSupport::parse_float( XMLSupport::parse_option_value( opt, "maxr", defMr ) ) );
634  }
635  }
636  }
637  this->texstage = stage;
638  this->detailTex = detailtex;
639  this->ismipmapped = ismipmapped;
640  if (vidMode) {
641  wrapper_file_path = f.GetFilename();
642  wrapper_file_type = f.GetType();
643  }
644  original = NULL;
645  loadSuccess = true;
646 
647  anis.insert( this );
648 
649  //Needed - must do housekeeping, tcoord stuff and the like.
650  setTime( curtime );
651 }
void AnimatedTexture::LoadFrame ( int  num)
virtual

Definition at line 653 of file ani_texture.cpp.

References BILINEAR, VSFileSystem::VSFile::Close(), gl_options_t::compression, f, accountXML::file, g_game, GFXFALSE, GFXTRUE, gl_options, MIPMAP, NEAREST, numframes, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), Texture::original, XMLSupport::parse_option_value(), parseAddressMode(), TEXTURE2D, TEXTURE_2D, TRILINEAR, and game_data_t::use_videos.

Referenced by MakeActive().

654 {
655  if ( !vidMode || (Decal == NULL) || (*Decal == NULL) ) return;
656  if ( (frame < 0) || (frame >= static_cast<int>(numframes)) ) return;
657  if ( (activebound >= 0) && (activebound < numframes) && (frames[frame] == frames[activebound]) ) return;
658  const char *temp = frames[frame].get().c_str();
659  char file[512] = "white.bmp";
660  char alp[512] = "white.bmp";
661  char opt[512] = "";
662  int numgets = 0;
663  numgets = sscanf( temp, "%s %s %[^\r\n]", file, alp, opt );
664  if ( (numgets < 2) || (strcmp( alp, "-" ) == 0) ) alp[0] = '\0';
665  string addrmodestr = XMLSupport::parse_option_value( opt, "addressMode", "" );
666  enum ADDRESSMODE addrmode = parseAddressMode( addrmodestr, defaultAddressMode );
667 
668  //Override compression options temporarily
669  //NOTE: This is ugly, but otherwise we would have to hack Texture way too much,
670  //or double the code. Let's use this then.
671  int ocompression = gl_options.compression;
673 
674  //Without this, VSFileSystem won't find the file -- ugly, but it's how it is.
675  VSFile f;
676  VSError err = f.OpenReadOnly( wrapper_file_path, wrapper_file_type );
677 
678  //Override mipmaping for video mode - too much overhead in generating the mipmamps.
679  enum FILTER ismip2 =
680  ( (ismipmapped == BILINEAR) || (ismipmapped == TRILINEAR) || (ismipmapped == MIPMAP) ) ? BILINEAR : NEAREST;
681  loadSuccess = true;
682  if (alp[0] != '\0') {
683  (*Decal)->Load( file,
684  alp,
685  texstage,
686  ismip2,
687  TEXTURE2D,
688  TEXTURE_2D,
689  1,
690  0,
692  65536,
693  (detailTex ? GFXTRUE : GFXFALSE),
694  GFXTRUE,
695  addrmode );
696  } else if (numgets == 1) {
697  (*Decal)->Load( file, texstage, ismip2, TEXTURE2D, TEXTURE_2D, (g_game.use_videos) ? GFXTRUE : GFXFALSE, 65536,
698  (detailTex ? GFXTRUE : GFXFALSE), GFXTRUE, addrmode );
699  } else {
700  loadSuccess = false;
701  }
702  if (err <= Ok) f.Close();
703  gl_options.compression = ocompression;
704 
705  original = NULL;
706  loadSuccess = loadSuccess && (*Decal)->LoadSuccess();
707  if (loadSuccess) activebound = frame;
708 }
bool AnimatedTexture::LoadSuccess ( )
virtual

If the texture has loaded properly returns true.

Reimplemented from Texture.

Definition at line 710 of file ani_texture.cpp.

711 {
712  return loadSuccess != false;
713 }
void AnimatedTexture::LoadVideoSource ( VSFileSystem::VSFile f)

Definition at line 436 of file ani_texture.cpp.

References anis, BILINEAR, Texture::Bind(), VSFileSystem::VSFile::Close(), Texture::data, e, VidFile::getDuration(), VSFileSystem::VSFile::GetFilename(), VidFile::getFrameBuffer(), VidFile::getFrameRate(), VidFile::getHeight(), VSFileSystem::VSFile::GetType(), VidFile::getWidth(), GFXFALSE, gl_options, Texture::image_target, int, gl_options_t::max_movie_dimension, Texture::maxtcoord, Texture::mintcoord, NEAREST, numframes, VidFile::open(), gl_options_t::pot_video_textures, gl_options_t::rect_textures, Reset(), TEXTURE_RECTANGLE, Texture::texture_target, TEXTURERECT, and timeperframe.

Referenced by Clone(), CreateVideoTexture(), and Load().

437 {
438  wrapper_file_path = f.GetFilename();
439  wrapper_file_type = f.GetType();
440  f.Close();
441 
442  Reset();
443 
444  vidMode = true;
445 
446  try {
447  vidSource = new::VidFile();
448  vidSource->open( wrapper_file_path, gl_options.max_movie_dimension, gl_options.pot_video_textures );
449 
450  physicsactive = vidSource->getDuration();
451  timeperframe = 1.0/vidSource->getFrameRate();
452  numframes = (unsigned int) (physicsactive*timeperframe);
453 
454  loadSuccess = true;
455  }
456  catch (::VidFile::Exception e) {
457  loadSuccess = false;
458  }
459  if (loadSuccess) {
460  sizeX = vidSource->getWidth();
461  sizeY = vidSource->getHeight();
462  mode = _24BIT;
463  data = (unsigned char*) vidSource->getFrameBuffer();
464  if ((ismipmapped == BILINEAR || ismipmapped == NEAREST) && gl_options.rect_textures) {
467  }
468 
469  Bind( 65535, GFXFALSE );
470 
471  maxtcoord.x = sizeX-0.5f;
472  maxtcoord.y = sizeY-0.5f;
473  mintcoord.x = 0.5f;
474  mintcoord.y = 0.5f;
475 
477  maxtcoord.x /= sizeX;
478  maxtcoord.y /= sizeY;
479  mintcoord.x /= sizeX;
480  mintcoord.y /= sizeY;
481  }
482 
483  anis.insert( this );
484  }
485 }
virtual void AnimatedTexture::MakeActive ( )
inlinevirtual

Binds the texture in the GFX library.

Reimplemented from Texture.

Definition at line 118 of file ani_texture.h.

Referenced by Animation::DrawAsVSSprite(), DrawDamageFlash(), Animation::DrawNoTransform(), Animation::DrawNow(), and MakeActive().

119  {
120  MakeActive( texstage, 0 );
121  } //MSVC bug seems to hide MakeActive() if we define MakeActive(int,int) - the suckers!
virtual void AnimatedTexture::MakeActive ( int  stage)
inlinevirtual

Reimplemented from Texture.

Definition at line 123 of file ani_texture.h.

References MakeActive().

124  {
125  MakeActive( stage, 0 );
126  } //MSVC bug seems to hide MakeActive(int) if we define MakeActive(int,int) - the suckers!
void AnimatedTexture::MakeActive ( int  stage,
int  pass 
)
virtual

Reimplemented from Texture.

Definition at line 54 of file ani_texture.cpp.

References ActivateWhite(), active, active_fraction, GFXColor::b, gl_options_t::compression, curtime, done, e, GFXColor::g, GetInterpolateFrames(), GetInterpolateTCoord(), GetLoop(), GetLoopInterp(), GFXColorf(), GFXFALSE, GFXINTERPOLATETEXTURE, GFXTextureEnv(), gl_options, int, intmax(), intmin(), LoadFrame(), MakeActive(), Texture::MakeActive(), Texture::maxtcoord, Texture::mintcoord, gl_options_t::Multitexture, nextactive, numframes, numFrames(), GFXColor::r, VidFile::seek(), setTime(), timeperframe, Texture::Transfer(), VSFileSystem::vs_dprintf(), and VidFile::Exception::what().

55 {
56  // Set active frame and texture coordinates
57  if (timeperframe && !vidSource) {
58  unsigned int numframes = numFrames();
59  unsigned int active = ( (unsigned int) (curtime/timeperframe) );
60  if ( GetLoop() )
61  active %= numframes;
62 
63  else
64  active = intmin( active, numframes-1 );
65  unsigned int nextactive = ( GetLoopInterp() ? ( (active+1)%numframes ) : intmin( active+1, numframes-1 ) );
66  float fraction = (curtime/timeperframe)-(unsigned int) (curtime/timeperframe);
67  if (fraction < 0) fraction += 1.0f;
68  this->active = active;
69  this->nextactive = nextactive;
70  this->active_fraction = fraction;
71  if (!vidMode) {
72  if ( GetInterpolateTCoord() && (active != nextactive) ) {
73  if (Decal && Decal[active] && Decal[nextactive]) {
74  this->maxtcoord = (1-fraction)*Decal[active]->maxtcoord+fraction*Decal[nextactive]->maxtcoord;
75  this->mintcoord = (1-fraction)*Decal[active]->mintcoord+fraction*Decal[nextactive]->mintcoord;
76  }
77  } else if (Decal && Decal[active]) {
78  this->maxtcoord = Decal[active]->maxtcoord;
79  this->mintcoord = Decal[active]->mintcoord;
80  }
81  } else {
82  if ( GetInterpolateTCoord() && (active != nextactive) ) {
83  if ( frames_maxtc.size() < intmax( active, nextactive ) ) {
84  this->maxtcoord = (1-fraction)*frames_maxtc[active]+fraction*frames_maxtc[nextactive];
85  this->mintcoord = (1-fraction)*frames_mintc[active]+fraction*frames_mintc[nextactive];
86  }
87  } else if ( active < frames_maxtc.size() ) {
88  this->maxtcoord = frames_maxtc[active];
89  this->mintcoord = frames_mintc[active];
90  }
91  }
92  active = ( (unsigned int) (curtime/timeperframe) )%numframes;
93  }
94 
95  // Effectively activate texture units
96  switch (pass)
97  {
98  case 0:
99  if (!vidMode) {
100  if ( GetInterpolateFrames() && (active != nextactive) ) {
101  if ( gl_options.Multitexture && ( (stage+1) < static_cast<int>(gl_options.Multitexture) ) ) {
102  if (Decal && Decal[nextactive%numframes])
103  Decal[nextactive%numframes]->MakeActive( stage+1 );
104 
105  else
106  ActivateWhite( stage+1 );
108  if (Decal && Decal[active%numframes])
109  Decal[active%numframes]->MakeActive( stage );
110 
111  else
112  ActivateWhite( stage );
113  //GFXTextureEnv(stage,GFXMODULATETEXTURE);
114  } else {
115  if (Decal && Decal[active%numframes])
116  Decal[active%numframes]->MakeActive( stage );
117 
118  else
119  ActivateWhite( stage );
120  multipass_interp_basecolor = GFXColorf();
121  GFXColor color = multipass_interp_basecolor;
122  color.r *= (1.0-active_fraction);
123  color.g *= (1.0-active_fraction);
124  color.b *= (1.0-active_fraction);
125  GFXColorf( color );
126  //GFXTextureEnv(stage,GFXMODULATETEXTURE);
127  }
128  } else {
129  if (Decal && Decal[active%numframes])
130  Decal[active%numframes]->MakeActive( stage );
131 
132  else
133  ActivateWhite( stage );
134  }
135  } else if (!vidSource) {
136  //No frame interpolation anything supported
137  if (Decal && *Decal) {
138  if (active != activebound)
139  LoadFrame( active%numframes );
140  (*Decal)->MakeActive( stage );
141  }
142  } else {
143  try {
144  //vidSource leaves frame data in its framebuffer, and our image data is initialized
145  //to point to that framebuffer, so all we need to do is transfer it to the GL.
146  if ( vidSource->seek( curtime ) ) {
147  //Override compression options temporarily
148  //NOTE: This is ugly, but otherwise we would have to hack Texture way too much,
149  //or double the code. Let's use this then.
150  int ocompression = gl_options.compression;
152 
153  VSFileSystem::vs_dprintf( 1, "Transferring video frame\n" );
154  Transfer( 65535, GFXFALSE );
155 
156  gl_options.compression = ocompression;
157  }
158  }
159  catch (::VidFile::EndOfStreamException e) {
160  if (GetLoop() && curtime > 0) {
161  setTime( 0 );
162  MakeActive( stage, pass );
163  return;
164  } else {
165  done = true;
166  }
167  }
168  catch (::VidFile::Exception e) {
169  VSFileSystem::vs_dprintf( 1, "\nVidFile exception: %s\n", e.what() );
170  }
171  Texture::MakeActive( stage, pass );
172  }
173  break;
174  case 1:
175  if ( !vidMode && GetInterpolateFrames() && (active != nextactive)
176  && !( gl_options.Multitexture && ( (stage+1) < static_cast<int>(gl_options.Multitexture) ) ) ) {
177  if (Decal && Decal[nextactive%numframes])
178  Decal[nextactive%numframes]->MakeActive( stage );
179 
180  else
181  ActivateWhite( stage );
182  GFXColor color = multipass_interp_basecolor;
183  color.r *= active_fraction;
184  color.g *= active_fraction;
185  color.b *= active_fraction;
186  GFXColorf( color );
187  //GFXTextureEnv(stage,GFXMODULATETEXTURE);
188  } else {ActivateWhite( stage ); } break;
189  }
190 }
virtual unsigned int AnimatedTexture::numFrames ( ) const
inlinevirtual

Reimplemented from Texture.

Definition at line 76 of file ani_texture.h.

References numframes.

Referenced by MakeActive(), and SpriteStarVlist::SpriteStarVlist().

77  {
78  return numframes;
79  }
unsigned int AnimatedTexture::numLayers ( ) const
virtual

Reimplemented from Texture.

Definition at line 715 of file ani_texture.cpp.

References active, GetInterpolateFrames(), gl_options, gl_options_t::Multitexture, and nextactive.

Referenced by Animation::DrawAsVSSprite(), Animation::DrawNoTransform(), and Animation::DrawNow().

716 {
718  && ( (texstage+1) < static_cast<int>(gl_options.Multitexture) ) )
719  return 2;
720 
721  else
722  return 1;
723 }
unsigned int AnimatedTexture::numPasses ( ) const
virtual

Reimplemented from Texture.

Definition at line 725 of file ani_texture.cpp.

References active, GetInterpolateFrames(), gl_options, gl_options_t::Multitexture, and nextactive.

Referenced by Animation::DrawAsVSSprite(), Animation::DrawNoTransform(), and Animation::DrawNow().

726 {
727  if ( GetInterpolateFrames() && (active != nextactive) ) {
728  if ( gl_options.Multitexture && ( (texstage+1) < static_cast<int>(gl_options.Multitexture) ) )
729  return 1;
730  else
731  return 2;
732  } else {
733  return 1;
734  }
735 }
const Texture * AnimatedTexture::Original ( ) const
virtual

Reimplemented from Texture.

Definition at line 339 of file ani_texture.cpp.

References active, and Texture::Original().

340 {
341  return Decal ? Decal[active]->Original() : this;
342 }
Texture * AnimatedTexture::Original ( )
virtual

Reimplemented from Texture.

Definition at line 334 of file ani_texture.cpp.

References active, and Texture::Original().

335 {
336  return Decal ? Decal[active]->Original() : this;
337 }
void AnimatedTexture::Reset ( )

Definition at line 399 of file ani_texture.cpp.

References active, curtime, done, numframes, and timeperframe.

Referenced by LoadAni(), LoadVideoSource(), and VDU::SetCommAnimation().

400 {
401  curtime = 0;
402  active = 0;
403  activebound = -1;
404  img_sides = SIDE_SINGLE;
405  physicsactive = numframes*timeperframe;
406  done = false;
407 }
void AnimatedTexture::SetInterpolateFrames ( bool  set)
inline

Definition at line 137 of file ani_texture.h.

Referenced by LoadAni().

138  {
139  options = (options&~optInterpolateFrames)|(set ? optInterpolateFrames : 0);
140  }
void AnimatedTexture::SetInterpolateTCoord ( bool  set)
inline

Definition at line 142 of file ani_texture.h.

Referenced by LoadAni().

143  {
144  options = (options&~optInterpolateTCoord)|(set ? optInterpolateTCoord : 0);
145  }
void AnimatedTexture::SetLoop ( bool  set)
inline

Definition at line 152 of file ani_texture.h.

Referenced by Animation::Animation(), CreateVideoTexture(), and LoadAni().

153  {
154  options = (options&~optLoop)|(set ? optLoop : 0);
155  }
void AnimatedTexture::SetLoopInterp ( bool  set)
inline

Definition at line 147 of file ani_texture.h.

Referenced by Animation::Animation(), and LoadAni().

148  {
149  options = (options&~optLoopInterp)|(set ? optLoopInterp : 0);
150  }
void AnimatedTexture::setTime ( double  tim)
virtual

Reimplemented from Texture.

Definition at line 258 of file ani_texture.cpp.

References curtime.

Referenced by LoadAni(), MakeActive(), SpriteStarVlist::SpriteStarVlist(), and UpdateAllFrame().

259 {
260  curtime = tim;
261 }
void AnimatedTexture::SetTimeSource ( SharedPtr< Audio::Source source)

Definition at line 737 of file ani_texture.cpp.

738 {
739  timeSource = source;
740  if (source)
741  options |= optSoundTiming;
742 
743  else
744  options &= ~optSoundTiming;
745 }
bool AnimatedTexture::SetupPass ( int  pass,
int  stage,
const enum BLENDFUNC  src,
const enum BLENDFUNC  dst 
)
virtual

Reimplemented from Texture.

Definition at line 192 of file ani_texture.cpp.

References GetInterpolateFrames(), GFXADDTEXTURE, GFXColorf(), GFXTextureEnv(), gl_options, and gl_options_t::Multitexture.

Referenced by Animation::DrawAsVSSprite(), Animation::DrawNoTransform(), Animation::DrawNow(), and SetupPass().

193 {
194  switch (pass)
195  {
196  case -1:
197  if ( !vidMode && GetInterpolateFrames() ) {
198  if ( !( gl_options.Multitexture && ( (stage+1) < static_cast<int>(gl_options.Multitexture) ) ) )
199  GFXColorf( multipass_interp_basecolor ); //Restore old color
200  else
201  //GFXTextureEnv(texstage,GFXMODULATETEXTURE); //Most expect this
202  GFXTextureEnv( stage+1, GFXADDTEXTURE ); //Most expect this
203  }
204  return true;
205 
206  default:
207  //Hey! Nothing to do! Yippie!
208  return true;
209  }
210 }
bool AnimatedTexture::SetupPass ( int  pass,
const enum BLENDFUNC  src,
const enum BLENDFUNC  dst 
)
inlinevirtual

Reimplemented from Texture.

Definition at line 132 of file ani_texture.h.

References SetupPass().

133  {
134  return SetupPass( pass, texstage, src, dst );
135  }
void AnimatedTexture::UpdateAllFrame ( )
static

Definition at line 218 of file ani_texture.cpp.

References anis, curTime(), GetElapsedTime(), GetTimeSource(), lastcurtime, lastrealtime, realTime(), and setTime().

Referenced by bootstrap_draw(), GameStarSystem::Draw(), BaseInterface::Draw(), and Briefing::Render().

219 {
220  double elapsed = GetElapsedTime();
221  double realtime = realTime();
222  for (set< AnimatedTexture* >::iterator iter = anis.begin(); iter != anis.end(); iter++) {
223  AnimatedTexture *ani = *iter;
224  if (ani->options & optSoundTiming) {
225  // lazy init
226  if (ani->lastrealtime == 0)
227  ani->lastrealtime = realtime;
228 
229  // de-jitter, playtime reporting tends to have some jitter
230  double newcurtime = ani->GetTimeSource()->getPlayingTime();
231  double delta = realtime - ani->lastrealtime;
232  double drift = newcurtime - ani->lastcurtime - delta;
233  if (fabs(drift) > 1.0) {
234  ani->lastcurtime = newcurtime - delta;
235  ani->lastrealtime = realtime;
236  } else if (fabs(drift) > 0.2) {
237  double catchup = drift * ((delta > 0.5) ? 0.5 : delta);
238  ani->lastcurtime += catchup;
239  ani->lastrealtime = realtime;
240  }
241  ani->setTime(ani->lastcurtime + delta);
242  } else {
243  ani->setTime( ani->curTime()+elapsed );
244  }
245  }
246 }
void AnimatedTexture::UpdateAllPhysics ( )
static

Definition at line 212 of file ani_texture.cpp.

References anis, and SIMULATION_ATOM.

Referenced by UpdateAnimatedTexture().

213 {
214  for (set< AnimatedTexture* >::iterator iter = anis.begin(); iter != anis.end(); iter++)
215  (*iter)->physicsactive -= SIMULATION_ATOM;
216 }

Member Data Documentation

unsigned int AnimatedTexture::active
protected

Definition at line 56 of file ani_texture.h.

Referenced by LoadAni(), MakeActive(), numLayers(), numPasses(), Original(), Reset(), and ~AnimatedTexture().

float AnimatedTexture::active_fraction
protected

Definition at line 58 of file ani_texture.h.

Referenced by MakeActive().

bool AnimatedTexture::constframerate
protected

Definition at line 65 of file ani_texture.h.

Referenced by constFrameRate().

double AnimatedTexture::curtime
protected

Definition at line 59 of file ani_texture.h.

Referenced by curTime(), Done(), Load(), LoadAni(), MakeActive(), Reset(), and setTime().

bool AnimatedTexture::done
protected

Definition at line 66 of file ani_texture.h.

Referenced by Done(), MakeActive(), and Reset().

double AnimatedTexture::lastcurtime
protected

Definition at line 62 of file ani_texture.h.

Referenced by UpdateAllFrame().

double AnimatedTexture::lastrealtime
protected

Definition at line 63 of file ani_texture.h.

Referenced by UpdateAllFrame().

unsigned int AnimatedTexture::nextactive
protected

Definition at line 57 of file ani_texture.h.

Referenced by MakeActive(), numLayers(), and numPasses().

unsigned int AnimatedTexture::numframes
protected
float AnimatedTexture::timeperframe
protected

Definition at line 55 of file ani_texture.h.

Referenced by Done(), framesPerSecond(), LoadAni(), LoadVideoSource(), MakeActive(), and Reset().


The documentation for this class was generated from the following files: