Castle Game Engine: CastleVideos: Class TVideosCache

# Class TVideosCache
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleVideos ## Declaration `type TVideosCache = class(TObject)` ## Description A cache of loaded videos. The idea is that instead of creating TVideo instance and calling TVideo.LoadFromFile, you instead call `Video := Cache.Video_IncReference(...)`. Later, instead of freeing this video, call `Video_DecReference(Video)`. From your point of view, things will work the same. But if you expect to load many videos from the same URL, then you will get a great speed and memory saving, because video will only be actually loaded once. This may happen e.g. if you have a VRML / X3D file with lots of MovieTexture nodes with the same urls. Notes: All passed here URLs must be absolute. Note that in case of problems with loading, Video_IncReference may raise an exception, just like normal TVideo.LoadFromFile. In this case it's guaranteed that no reference will be incremented, of course. If Video_IncReference returns in a normal way, then it will return something non-`Nil` for sure. Video_DecReference alwas sets Video to `Nil`, like FreeAndNil. All videos handled here are always loaded. So Video_IncReference always returns TVideo with TVideo.Loaded = `True`. And you are forbidden from closing this video by TVideo.Close yourself. Note that before destroying this object you must free all videos, i.e. call Video_DecReference for all videos allocated by Video_IncReference. This class is not a lousy way of avoiding memory leaks — it would be a bad idea, because it would cause sloppy programming, where memory is unnecessarily allocated for a long time. In fact, this class asserts in destructor that no videos are in cache anymore, so if you compiled with assertions enabled, this class does the job of memory-leak detector. ## Hierarchy TObject TVideosCache ## Overview ### Methods
| `constructor Create;`
| `destructor Destroy; override;`
| `function Video_IncReference(const URL: string; out AlphaChannel: TAlphaChannel): TVideo;`
| `procedure Video_DecReference(var Video: TVideo);`
| `function Empty: boolean; virtual;`
### Properties
| `property OnEmpty: TProcedure read FOnEmpty write FOnEmpty;`
## Description ### Methods
| `constructor Create;`
| `destructor Destroy; override;`
| `function Video_IncReference(const URL: string; out AlphaChannel: TAlphaChannel): TVideo;`
| `procedure Video_DecReference(var Video: TVideo);`
| `function Empty: boolean; virtual;`
### Properties
| `property OnEmpty: TProcedure read FOnEmpty write FOnEmpty;`
Called when cache becomes empty. This is only for internal usage by X3DNodes unit for now.
Generated by PasDoc 0.13.0 on 2013-08-17 21:27:14