DXGL r512 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r511‎ | r512 | r513 >
Date:20:35, 1 September 2014
Author:admin
Status:new
Tags:
Comment:
Combine refcounts of glDirect3DMaterial interface versions.
Modified paths:
  • /ddraw/glDirect3DMaterial.cpp (modified) (history)
  • /ddraw/glDirect3DMaterial.h (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DMaterial.cpp
@@ -37,8 +37,8 @@
3838 material.hTexture = 0;
3939 material.dwRampSize = 0;
4040 handle = 0;
41 - glD3DM2 = NULL;
42 - glD3DM1 = NULL;
 41+ glD3DM2 = new glDirect3DMaterial2(this);
 42+ glD3DM1 = new glDirect3DMaterial1(this);
4343 TRACE_EXIT(-1,0);
4444 }
4545
@@ -46,6 +46,8 @@
4747 {
4848 TRACE_ENTER(1,14,this);
4949 if(device) device->Release();
 50+ delete glD3DM2;
 51+ delete glD3DM1;
5052 TRACE_EXIT(-1,0);
5153 }
5254
@@ -71,45 +73,21 @@
7274 }
7375 if(riid == IID_IDirect3DMaterial2)
7476 {
75 - if(glD3DM2)
76 - {
77 - *ppvObj = glD3DM2;
78 - glD3DM2->AddRef();
79 - TRACE_VAR("*ppvObj",14,*ppvObj);
80 - TRACE_EXIT(23,D3D_OK);
81 - return D3D_OK;
82 - }
83 - else
84 - {
85 - this->AddRef();
86 - *ppvObj = new glDirect3DMaterial2(this);
87 - glD3DM2 = (glDirect3DMaterial2*)*ppvObj;
88 - TRACE_VAR("*ppvObj",14,*ppvObj);
89 - TRACE_EXIT(23,D3D_OK);
90 - return D3D_OK;
91 - }
 77+ this - AddRef();
 78+ *ppvObj = glD3DM2;
 79+ TRACE_VAR("*ppvObj",14,*ppvObj);
 80+ TRACE_EXIT(23,D3D_OK);
 81+ return D3D_OK;
9282 }
9383 if(riid == IID_IDirect3DMaterial)
9484 {
95 - if(glD3DM1)
96 - {
97 - *ppvObj = glD3DM1;
98 - glD3DM1->AddRef();
99 - TRACE_VAR("*ppvObj",14,*ppvObj);
100 - TRACE_EXIT(23,D3D_OK);
101 - return D3D_OK;
102 - }
103 - else
104 - {
105 - this->AddRef();
106 - *ppvObj = new glDirect3DMaterial1(this);
107 - glD3DM1 = (glDirect3DMaterial1*)*ppvObj;
108 - TRACE_VAR("*ppvObj",14,*ppvObj);
109 - TRACE_EXIT(23,D3D_OK);
110 - return D3D_OK;
111 - }
 85+ this - AddRef();
 86+ *ppvObj = glD3DM1;
 87+ TRACE_VAR("*ppvObj", 14, *ppvObj);
 88+ TRACE_EXIT(23, D3D_OK);
 89+ return D3D_OK;
11290 }
113 - TRACE_EXIT(23,E_NOINTERFACE);
 91+ TRACE_EXIT(23, E_NOINTERFACE);
11492 return E_NOINTERFACE;
11593 }
11694
@@ -215,26 +193,15 @@
216194 glDirect3DMaterial2::glDirect3DMaterial2(glDirect3DMaterial3 *glD3DM3)
217195 {
218196 TRACE_ENTER(2,14,this,14,glD3DM3);
219 - refcount = 1;
220197 this->glD3DM3 = glD3DM3;
221198 TRACE_EXIT(-1,0);
222199 }
223200
224 -glDirect3DMaterial2::~glDirect3DMaterial2()
225 -{
226 - TRACE_ENTER(1,14,this);
227 - glD3DM3->glD3DM2 = NULL;
228 - glD3DM3->Release();
229 - TRACE_EXIT(-1,0);
230 -}
231 -
232201 ULONG WINAPI glDirect3DMaterial2::AddRef()
233202 {
234203 TRACE_ENTER(1,14,this);
235204 if(!this) TRACE_RET(ULONG,8,0);
236 - refcount++;
237 - TRACE_EXIT(8,refcount);
238 - return refcount;
 205+ TRACE_RET(ULONG, 8, glD3DM3->AddRef());
239206 }
240207
241208 ULONG WINAPI glDirect3DMaterial2::Release()
@@ -241,12 +208,7 @@
242209 {
243210 TRACE_ENTER(1,14,this);
244211 if(!this) TRACE_RET(ULONG,8,0);
245 - ULONG ret;
246 - refcount--;
247 - ret = refcount;
248 - if(refcount == 0) delete this;
249 - TRACE_EXIT(8,ret);
250 - return ret;
 212+ TRACE_RET(ULONG, 8, glD3DM3->Release());
251213 }
252214
253215 HRESULT WINAPI glDirect3DMaterial2::QueryInterface(REFIID riid, void** ppvObj)
@@ -294,26 +256,15 @@
295257 glDirect3DMaterial1::glDirect3DMaterial1(glDirect3DMaterial3 *glD3DM3)
296258 {
297259 TRACE_ENTER(2,14,this,14,glD3DM3);
298 - refcount = 1;
299260 this->glD3DM3 = glD3DM3;
300261 TRACE_EXIT(-1,0);
301262 }
302263
303 -glDirect3DMaterial1::~glDirect3DMaterial1()
304 -{
305 - TRACE_ENTER(1,14,this);
306 - glD3DM3->glD3DM1 = NULL;
307 - glD3DM3->Release();
308 - TRACE_EXIT(-1,0);
309 -}
310 -
311264 ULONG WINAPI glDirect3DMaterial1::AddRef()
312265 {
313266 TRACE_ENTER(1,14,this);
314267 if(!this) TRACE_RET(ULONG,8,0);
315 - refcount++;
316 - TRACE_EXIT(8,refcount);
317 - return refcount;
 268+ TRACE_RET(ULONG, 8, glD3DM3->AddRef());
318269 }
319270
320271 ULONG WINAPI glDirect3DMaterial1::Release()
@@ -320,12 +271,7 @@
321272 {
322273 TRACE_ENTER(1,14,this);
323274 if(!this) TRACE_RET(ULONG,8,0);
324 - ULONG ret;
325 - refcount--;
326 - ret = refcount;
327 - if(refcount == 0) delete this;
328 - TRACE_EXIT(8,ret);
329 - return ret;
 275+ TRACE_RET(ULONG, 8, glD3DM3->Release());
330276 }
331277
332278 HRESULT WINAPI glDirect3DMaterial1::QueryInterface(REFIID riid, void** ppvObj)
Index: ddraw/glDirect3DMaterial.h
@@ -49,7 +49,6 @@
5050 {
5151 public:
5252 glDirect3DMaterial2(glDirect3DMaterial3 *glD3DM3);
53 - virtual ~glDirect3DMaterial2();
5453 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
5554 ULONG WINAPI AddRef();
5655 ULONG WINAPI Release();
@@ -57,7 +56,6 @@
5857 HRESULT WINAPI GetMaterial(LPD3DMATERIAL lpMat);
5958 HRESULT WINAPI SetMaterial(LPD3DMATERIAL lpMat);
6059 private:
61 - ULONG refcount;
6260 glDirect3DMaterial3 *glD3DM3;
6361 };
6462
@@ -65,7 +63,6 @@
6664 {
6765 public:
6866 glDirect3DMaterial1(glDirect3DMaterial3 *glD3DM3);
69 - virtual ~glDirect3DMaterial1();
7067 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
7168 ULONG WINAPI AddRef();
7269 ULONG WINAPI Release();
@@ -76,7 +73,6 @@
7774 HRESULT WINAPI SetMaterial(LPD3DMATERIAL lpMat);
7875 HRESULT WINAPI Unreserve();
7976 private:
80 - ULONG refcount;
8177 glDirect3DMaterial3 *glD3DM3;
8278 };
8379