OSDN Git Service

#xxxxx DTXViewerのプロジェクトを追加。
[dtxmania/dtxmania.git] / DTXViewerプロジェクト / @FDK10プロジェクト / CSurfaceManager.cpp
1 #include "stdafx.h"
2 #include "Debug.h"
3 #include "CSurfaceManager.h"
4
5 namespace FDK {
6         namespace Graphics {
7
8 CSurfaceManager::CSurfaceManager()
9 {
10         this->pSurfaceList = this->pSurfaceListLast = NULL;
11 }
12
13 void      CSurfaceManager::ResetCache()
14 {
15         for( SurfaceList* sc = this->pSurfaceList; sc != NULL; sc = sc->next )
16                 sc->bUse = false;
17 }
18
19 CSurface* CSurfaceManager::GetCachedSurface( LPCTSTR name, LPCTSTR filename, DWORD width, DWORD height, LOADPLACE place )
20 {
21         SurfaceList* cell;
22
23         // \83t\83@\83C\83\8b\82Ì\8dÅ\8fI\8dX\90V\8e\9e\8d\8f\82Ì\8eæ\93¾\81G
24         // \81@fileInfo \81© \8ew\92è\82³\82ê\82½\83t\83@\83C\83\8b\82Ì\8dÅ\8fI\8dX\90V\8e\9e\8d\8f
25         WIN32_FILE_ATTRIBUTE_DATA fileInfo;
26         if( ! ::GetFileAttributesEx( filename, GetFileExInfoStandard, &fileInfo) )
27                 return NULL;    // \8e¸\94s
28
29         // \83L\83\83\83b\83V\83\85\83\8a\83X\83g\82Ì\92\86\82É\93¯\88ê\82Ì\82à\82Ì\82ª\82 \82é\82©\92²\82×\82é
30         for( cell = this->pSurfaceList; cell != NULL; cell = cell->next )
31         {
32                 if( lstrcmp( name, cell->strSurfaceName ) == 0 && lstrcmp( filename, cell->strFileName ) == 0 
33                         && ( fileInfo.ftLastWriteTime.dwLowDateTime  == cell->ftLastWriteTime.dwLowDateTime )
34                         && ( fileInfo.ftLastWriteTime.dwHighDateTime == cell->ftLastWriteTime.dwHighDateTime )
35                         && ( cell->width == width && cell->height == height && cell->place == place ) )
36                 {
37                         cell->bUse = true;                      // \82 \82Á\82½\82Ì\82Å\82»\82ê\82ð\8eg\82¤
38                         return &cell->surface;
39                 }
40         }
41
42         // \8c´\94Å\82Ì\90V\8bK\8dì\90¬
43         cell = new SurfaceList();
44         cell->surface.InitDeviceObjectsFromFile( name, filename, width, height, place );
45         if( FAILED( cell->surface.RestoreDeviceObjects() ) )
46         {
47                 cell->surface.DeleteDeviceObjects();
48                 SAFE_DELETE( cell );
49                 return NULL;            // \8d\\92z\82É\8e¸\94s
50         }
51         cell->bUse = true;
52         lstrcpyn( cell->strFileName, filename, _MAX_PATH );
53         lstrcpyn( cell->strSurfaceName, name, _MAX_PATH );
54         cell->width = width;
55         cell->height = height;
56         cell->place = place;
57         cell->ftLastWriteTime = fileInfo.ftLastWriteTime;
58         cell->prev = cell->next = NULL;
59         APPENDLIST( this->pSurfaceList, this->pSurfaceListLast, cell );
60         return &cell->surface;
61 }
62
63 void      CSurfaceManager::RemoveUnusedSurfaces()
64 {
65         SurfaceList* sc = this->pSurfaceList;
66         while( sc != NULL )
67         {
68                 SurfaceList* next = sc->next;
69                 if( ! sc->bUse )
70                 {
71                         REMOVELIST( this->pSurfaceList, this->pSurfaceListLast, sc );
72                         sc->surface.DeleteDeviceObjects();
73                         SAFE_DELETE( sc );
74                 }
75                 sc = next;
76         }
77 }
78
79 HRESULT   CSurfaceManager::OneTimeSceneInit()
80 {
81         SurfaceList *s = this->pSurfaceList;
82         while( s != NULL )
83         {
84                 SurfaceList *next = s->next;
85                 s->surface.DeleteDeviceObjects();
86                 SAFE_DELETE( s );
87                 s = next;
88         }
89         this->pSurfaceList = this->pSurfaceListLast = NULL;
90         return S_OK;
91 }
92
93 HRESULT   CSurfaceManager::FinalCleanup()
94 {
95         SurfaceList *s = this->pSurfaceList;
96         while( s != NULL )
97         {
98                 SurfaceList *next = s->next;
99                 s->surface.DeleteDeviceObjects();
100                 SAFE_DELETE( s );
101                 s = next;
102         }
103         this->pSurfaceList = this->pSurfaceListLast = NULL;
104         return S_OK;
105 }
106
107 HRESULT   CSurfaceManager::InitDeviceObjects()
108 {
109         for( SurfaceList* s = this->pSurfaceList; s != NULL; s = s->next )
110                 s->surface.InitDeviceObjectsFromFile( s->strSurfaceName, s->strFileName, s->width, s->height, s->place );
111         return S_OK;
112 }
113
114 HRESULT   CSurfaceManager::RestoreDeviceObjects()
115 {
116         for( SurfaceList* s = this->pSurfaceList; s != NULL; s = s->next )
117                 s->surface.RestoreDeviceObjects();
118         return S_OK;
119 }
120
121 HRESULT   CSurfaceManager::InvalidateDeviceObjects()
122 {
123         for( SurfaceList* s = this->pSurfaceList; s != NULL; s = s->next )
124                 s->surface.InvalidateDeviceObjects();
125         return S_OK;
126 }
127
128 HRESULT   CSurfaceManager::DeleteDeviceObjects()
129 {
130         for( SurfaceList* s = this->pSurfaceList; s != NULL; s = s->next )
131                 s->surface.DeleteDeviceObjects();
132
133         return S_OK;
134 }
135
136         }//Graphics
137 }//FDK