修订版 | 4a2dc01d09ecfcde1572267eeb033a8d75c563de (tree) |
---|---|
时间 | 2019-02-06 02:00:02 |
作者 | <jarmonik@c0f5...> |
- Sketchpad Fixes, Safety checks.
@@ -394,6 +394,7 @@ | ||
394 | 394 | pBltGrpTgt = NULL; // Let's set this NULL here, constructor is called only once. Not when exiting and restarting a simulation. |
395 | 395 | pNoiseTex = NULL; |
396 | 396 | surfBltTgt = NULL; // This variable is not used, set it to NULL anyway |
397 | + hMainThread = GetCurrentThread(); | |
397 | 398 | |
398 | 399 | memset2(&D3D9Stats, 0, sizeof(D3D9Stats)); |
399 | 400 |
@@ -2541,6 +2542,11 @@ | ||
2541 | 2542 | _TRACE; |
2542 | 2543 | oapi::Sketchpad *pSkp = NULL; |
2543 | 2544 | |
2545 | + if (GetCurrentThread() != hMainThread) { | |
2546 | + _wassert(L"Sketchpad called from a worker thread !", _CRT_WIDE(__FILE__), __LINE__); | |
2547 | + return NULL; | |
2548 | + } | |
2549 | + | |
2544 | 2550 | sketching_time = D3D9GetTime(); |
2545 | 2551 | |
2546 | 2552 | if (surf == NULL) surf = GetBackBufferHandle(); |
@@ -2557,6 +2563,7 @@ | ||
2557 | 2563 | if (pCur) { |
2558 | 2564 | if (pCur == pPad) _wassert(L"Sketchpad already exists for this surface", _CRT_WIDE(__FILE__), __LINE__); |
2559 | 2565 | pCur->EndDrawing(); // Put the current one in hold |
2566 | + //LogErr("Double Sketching"); | |
2560 | 2567 | } |
2561 | 2568 | |
2562 | 2569 | // Push a new Sketchpad onto a stack |
@@ -2596,7 +2603,10 @@ | ||
2596 | 2603 | |
2597 | 2604 | // Do we have an old interface ? |
2598 | 2605 | D3D9Pad *pOld = GetTopInterface(); |
2599 | - if (pOld) pOld->BeginDrawing(); // Continue with the old one | |
2606 | + if (pOld) { | |
2607 | + pOld->BeginDrawing(); // Continue with the old one | |
2608 | + //LogErr("Continue Old"); | |
2609 | + } | |
2600 | 2610 | } |
2601 | 2611 | else { |
2602 | 2612 | GDIPad *pGDI = (GDIPad *)sp; |
@@ -1256,6 +1256,7 @@ | ||
1256 | 1256 | D3DCAPS9 caps; |
1257 | 1257 | FileParser * parser; |
1258 | 1258 | std::string scenarioName; |
1259 | + HANDLE hMainThread; | |
1259 | 1260 | |
1260 | 1261 | HWND hRenderWnd; // render window handle |
1261 | 1262 |
@@ -1,6 +1,6 @@ | ||
1 | 1 | Microsoft Visual Studio Solution File, Format Version 12.00 |
2 | 2 | # Visual Studio 14 |
3 | -VisualStudioVersion = 14.0.25123.0 | |
3 | +VisualStudioVersion = 14.0.25420.1 | |
4 | 4 | MinimumVisualStudioVersion = 10.0.40219.1 |
5 | 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D3D9Client", "D3D9ClientVS2015.vcxproj", "{5B2C5D1A-7B8E-4343-BC33-836ABD122D3A}" |
6 | 6 | EndProject |
@@ -153,6 +153,21 @@ | ||
153 | 153 | } |
154 | 154 | |
155 | 155 | |
156 | + | |
157 | +void D3D9Pad::Reset() | |
158 | +{ | |
159 | + bBeginDraw = false; | |
160 | + vI = 0; | |
161 | + iI = 0; | |
162 | + D3DXMatrixIdentity(&mO); | |
163 | + vTarget = D3DXVECTOR4(1,1,1,1); | |
164 | + pTgt = NULL; | |
165 | + pDep = NULL; | |
166 | + zfar = 1.0f; | |
167 | +} | |
168 | + | |
169 | + | |
170 | + | |
156 | 171 | // =============================================================================================== |
157 | 172 | // Restore Default Settings: Fonts, Pens, Colors, etc... |
158 | 173 | // |
@@ -222,11 +237,7 @@ | ||
222 | 237 | if (_name) strcpy_s(name, 32, _name); |
223 | 238 | else strcpy_s(name, 32, "NoName"); |
224 | 239 | |
225 | - // Don't put these in LoadDefaults() | |
226 | - bBeginDraw = false; | |
227 | - vI = 0; | |
228 | - iI = 0; | |
229 | - | |
240 | + Reset(); | |
230 | 241 | LoadDefaults(); |
231 | 242 | } |
232 | 243 |
@@ -244,11 +255,7 @@ | ||
244 | 255 | if (_name) strcpy_s(name, 32, _name); |
245 | 256 | else strcpy_s(name, 32, "NoName"); |
246 | 257 | |
247 | - // Don't put these in Reset() | |
248 | - bBeginDraw = false; | |
249 | - vI = 0; | |
250 | - iI = 0; | |
251 | - | |
258 | + Reset(); | |
252 | 259 | LoadDefaults(); |
253 | 260 | } |
254 | 261 |
@@ -291,14 +298,11 @@ | ||
291 | 298 | } |
292 | 299 | else bMustEndScene = false; |
293 | 300 | |
294 | - | |
295 | - if (pTgt != pRenderTgt) { | |
296 | - pRenderTgt->GetDesc(&tgt_desc); | |
297 | - zfar = float(max(tgt_desc.Width, tgt_desc.Height)); | |
298 | - D3DXMatrixOrthoOffCenterLH(&mO, 0.0f, (float)tgt_desc.Width, (float)tgt_desc.Height, 0.0f, 0.0f, zfar); | |
299 | - vTarget = D3DXVECTOR4(2.0f / (float)tgt_desc.Width, 2.0f / (float)tgt_desc.Height, (float)tgt_desc.Width, (float)tgt_desc.Height); | |
300 | - } | |
301 | - | |
301 | + pRenderTgt->GetDesc(&tgt_desc); | |
302 | + zfar = float(max(tgt_desc.Width, tgt_desc.Height)); | |
303 | + D3DXMatrixOrthoOffCenterLH(&mO, 0.0f, (float)tgt_desc.Width, (float)tgt_desc.Height, 0.0f, 0.0f, zfar); | |
304 | + vTarget = D3DXVECTOR4(2.0f / (float)tgt_desc.Width, 2.0f / (float)tgt_desc.Height, (float)tgt_desc.Width, (float)tgt_desc.Height); | |
305 | + | |
302 | 306 | pTgt = pRenderTgt; |
303 | 307 | pDep = pDepthStensil; |
304 | 308 |
@@ -321,6 +325,8 @@ | ||
321 | 325 | gc->EndScene(); |
322 | 326 | bMustEndScene = false; |
323 | 327 | } |
328 | + | |
329 | + Reset(); | |
324 | 330 | } |
325 | 331 | |
326 | 332 |
@@ -574,6 +574,7 @@ | ||
574 | 574 | |
575 | 575 | float GetPenWidth() const; |
576 | 576 | |
577 | + void Reset(); | |
577 | 578 | bool Flush(HPOLY hPoly = NULL); |
578 | 579 | void AddRectIdx(WORD aV); |
579 | 580 | void FillRect(int l, int t, int r, int b, SkpColor &c); |
@@ -449,7 +449,6 @@ | ||
449 | 449 | // |
450 | 450 | bool D3D9Pad::TexChangeNative(LPDIRECT3DTEXTURE9 hNew) |
451 | 451 | { |
452 | - if (hNew == hTexture) return false; | |
453 | 452 | Change |= SKPCHG_TEXTURE; |
454 | 453 | hTexture = hNew; |
455 | 454 | return true; |
@@ -470,16 +469,15 @@ | ||
470 | 469 | return; |
471 | 470 | } |
472 | 471 | |
473 | - if (TexChangeNative(SURFACE(hNew)->GetTexture())) { | |
474 | - | |
475 | - if (SURFACE(hNew)->IsColorKeyEnabled()) { | |
476 | - bColorKey = true; | |
477 | - cColorKey = SURFACE(hNew)->ClrKey; | |
478 | - } | |
479 | - else { | |
480 | - bColorKey = false; | |
481 | - cColorKey = D3DXCOLOR(DWORD(0)); | |
482 | - } | |
472 | + TexChangeNative(SURFACE(hNew)->GetTexture()); | |
473 | + | |
474 | + if (SURFACE(hNew)->IsColorKeyEnabled()) { | |
475 | + bColorKey = true; | |
476 | + cColorKey = SURFACE(hNew)->ClrKey; | |
477 | + } | |
478 | + else { | |
479 | + bColorKey = false; | |
480 | + cColorKey = D3DXCOLOR(DWORD(0)); | |
483 | 481 | } |
484 | 482 | } |
485 | 483 |