My Project
FlashTextureManager.h
1 #pragma once
2 #include <vector>
3 #include <string>
4 #include "FileManager.h"
5 
6 #include "util/mutex.h"
7 #include <boost/thread.hpp>
8 #include <boost/shared_ptr.hpp>
9 
10 namespace ParaEngine
11 {
12  using namespace std;
16  struct SWFRect
17  {
18  int m_bitSize;
19  int m_minX;
20  int m_minY;
21  int m_maxX;
22  int m_maxY;
23  public:
24  int getMinX();
25  int getMinY();
26  int getMaxX();
27  int getMaxY();
28 
29  void setMinX( int minX );
30  void setMinY( int minY );
31  void setMaxX( int maxX );
32  void setMaxY( int maxY );
33 
34 
35  SWFRect( int minX, int minY, int maxX, int maxY );
36  SWFRect();
37 
39  void Init( CParaFile& in, bool bUnsigned=false);
40  };
52  struct SWFHeader
53  {
54  byte Signature[3]; // 'F', 'W', 'S' or 'C', 'W', 'S'(compressed)
55  byte Version;
56  DWORD fileLength;
57 
58  // rect
59  SWFRect frameSize;
60  short frameRate;
61  short frameCount;
62 
63  public:
64  SWFHeader();
65  SWFHeader(CParaFile& in);
66  };
67 
70  {
71  public:
72  CFlashPlayer(int nFlashPlayerIndex);
73  ~CFlashPlayer();
74 
76 
77  public:
79  bool IsFree(){return m_bFree;}
80 
82  void LoadMovie(const char* filename);
83 
87  void PutFlashVars(const char* args);
88 
113  const char* CallFlashFunction(const char* sFunc);
114 
118  void SetFlashReturnValue(const char* sResult);
119 
121  const char* GetFlashReturnValue();
122 
124  void UnloadMovie();
125 
127  void InvalidateDeviceObjects();
128 
132  void RenderFrameMove(float fCurTime);
133 
140  bool GetTextureInfo(int* width, int* height);
141 
146  LRESULT SendMessage( UINT Msg,WPARAM wParam,LPARAM lParam);
151  LRESULT PostMessage( UINT Msg,WPARAM wParam,LPARAM lParam);
152 
154  const char* GetFileName();
155 
157  int GetIndex() {return m_nFlashPlayerIndex;}
158 
159 
161  bool IsWindowMode() { return m_bWindowMode;};
162 
164  void SetWindowMode(bool bIsWindowMode);
165 
167  void MoveWindow(int x, int y, int width, int height, bool bRepaint=true);
168 
169 
172  void OnSizeChange();
173 
175  void SetWindowVisible(bool bVisible);
176 
180  void Repaint();
181 
183  void SetFocus();
184 
186  HWND GetWindowHandle();
187 
191  void UpdatePixelsBuffer();
192  private:
196  HRESULT CreateTexture(LPDIRECT3DTEXTURE9 *ppTexture);
197 
200  HRESULT UpdateTexture(LPDIRECT3DTEXTURE9 pTexture);
201 
202  public:
206  HRESULT StartWindowThread();
207  void DefaultWinThreadProc();
208 
210  bool MsgProcCustom(UINT message,WPARAM wParam,LPARAM lParam);
211 
213  bool PostWinThreadMessage(UINT message,WPARAM wParam,LPARAM lParam);
214 
217  bool SetParentWindow(HWND hWnd);
218 
220  bool HasFocus();
221  public:
223  LPDIRECT3DTEXTURE9 GetTexture();
224 
226  string m_filename;
228  float m_fTimeOut;
233 
235  LPDIRECT3DTEXTURE9 m_pTexture;
236  D3DFORMAT m_TextureFormat;
237  bool m_bUseDynamicTextures;
238 
243  bool m_bFree;
250 
251  int m_nX;
252  int m_nY;
253  int m_nWidth;
254  int m_nHeight;
255  int m_nBufWidth;// thread unsafe
256  int m_nBufHeight;// thread unsafe
257  int m_nTextureWidth;
258  int m_nTextureHeight;
259  int m_nWindowX;
260  int m_nWindowY;
261  int m_nWindowWidth;
262  int m_nWindowHeight;
263 
264  DWORD* m_lpPixels; // thread unsafe
265  LinearColor m_backgroundColor;
266 
269  bool m_bFlipVertical;
270 
273 
274  // the most recent flash return value.
275  string m_sFlashReturnValue;
276 
277  // the default window thread ptr.
278  Boost_Thread_ptr_type m_win_thread;
279  ParaEngine::mutex m_win_thread_mutex;
280  bool m_bWindowCreated;
281  bool m_bWinThreadMovieLoaded;
282  // the window thread id
283  DWORD m_dwWinThreadID;
284 
285  string m_sCurrentFlashFunc;
286  string m_sCurrentFlashFuncResponse;
287  bool m_bInFlashFunc;
288 
289  bool m_bHasFocus;
290  };
291 
296  {
297  public:
298  CFlashTextureManager(void);
299  virtual ~CFlashTextureManager(void);
300 
301  public:
302  HRESULT InitDeviceObjects();// device independent
303  HRESULT RestoreDeviceObjects(); // device dependent
304  HRESULT InvalidateDeviceObjects();
305  HRESULT DeleteDeviceObjects();
307  void Cleanup();
309  void LoadAsset();
311  void UnloadAsset();
314  void GarbageCollectAll();
315 
318  void OnSizeChange();
319 
323  void SetMaxFlashPlayerNum(int nNum);
327  int GetMaxFlashPlayerNum();
328 
333  CFlashPlayer* GetFlashPlayer(const char* sFileName);
334 
338  CFlashPlayer* GetFlashPlayer(int nIndex);
339 
344  int GetFlashPlayerIndex(const char* sFileName);
345 
350  LPDIRECT3DTEXTURE9 GetTexture(const char* sFileName);
352  bool GetTextureInfo(const char* sFileName, int* width, int* height);
353 
358  bool UnloadTexture(const char* sFileName);
359 
364  void RenderFrameMove(float fElapsedTime);
365 
369  string FindFile(const string& filename, bool bFindInSearchPaths);
370 
373  void RepaintAll();
374 
379  void RenderFlashWindows(SceneState& sceneState);
380 
383  bool SetParentWindow(HWND hWnd);
384 
386  static bool HasFocus();
387  public:
388  vector <CFlashPlayer*> m_FlashPlayers;
389 
390  static bool m_bHasFocus;
391  };
392 }
HWND m_hwndFlashPlayerControl
flash control handle
Definition: FlashTextureManager.h:249
It&#39;s used as parameter to Draw method of each scene object.
Definition: SceneState.h:284
float m_fTimeOut
if a flash player is never used for this number of time, it will be deleted.
Definition: FlashTextureManager.h:228
bool m_bTextureUpdatedThisFrame
whether the texture has been update in this rendering frame.
Definition: FlashTextureManager.h:241
different physics engine has different winding order.
Definition: EventBinding.h:32
string m_filename
file name that the current texture is associated with.
Definition: FlashTextureManager.h:226
bool m_bWindowMode
if true, we use a real win32 window.
Definition: FlashTextureManager.h:272
bool IsFree()
whether the current player is free to load a new movie.
Definition: FlashTextureManager.h:79
an instance of flash player.
Definition: FlashTextureManager.h:69
flash SWF header Signature UI8 Signature byte always ¡®F¡¯ Signature UI8 Signature byte always ¡®W¡¯ ...
Definition: FlashTextureManager.h:52
bool IsWindowMode()
whether this player is using a real win32 window for display.
Definition: FlashTextureManager.h:161
bool m_bNeedFlashUpdate
this flag is set to true every frame move. and set to false when the flash image is saved to temp buf...
Definition: FlashTextureManager.h:268
LPDIRECT3DTEXTURE9 m_pTexture
dynamic d3d texture
Definition: FlashTextureManager.h:235
search path manager interface and implementation.
Definition: FilePath.h:106
bool m_bTransparent
There are two modes of rendering are supported:
Definition: FlashTextureManager.h:247
for SWF rect
Definition: FlashTextureManager.h:16
it presents a real or virtual file in ParaEngine.
Definition: ParaFile.h:31
bool m_bFree
whether the current player is free.
Definition: FlashTextureManager.h:243
int m_nFlashPlayerIndex
index of this flash player
Definition: FlashTextureManager.h:232
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
cross platform mutex
Definition: mutex.h:95
managing flash textures.
Definition: FlashTextureManager.h:295
int GetIndex()
get unique index of this flash player .
Definition: FlashTextureManager.h:157
float m_fLastUsedTime
last time the GetTexture() is called.
Definition: FlashTextureManager.h:230