Commit MetaInfo

修订版373a3b6398dcc10e88cb034131dd41c945d612ac (tree)
时间2011-06-21 07:00:00
作者Jarmonik
CommiterJarmonik

Log Message

D3D9Client: auto-check for 4xAA capability + 2D Panel performance improvements

更改概述

差异

diff -r 71022f40c2a4 -r 373a3b6398dc Modules/D3D9Client/D3D9Client.fx
--- a/Modules/D3D9Client/D3D9Client.fx Mon Oct 24 14:51:17 2011 +0200
+++ b/Modules/D3D9Client/D3D9Client.fx Tue Jun 21 00:00:00 2011 +0200
@@ -200,8 +200,8 @@
200200 MagFilter = LINEAR;
201201 MipFilter = NONE;
202202 MaxAnisotropy = 2;
203- AddressU = MIRROR;
204- AddressV = MIRROR;
203+ AddressU = CLAMP;
204+ AddressV = CLAMP;
205205 };
206206
207207 sampler RingS = sampler_state // Planetary rings sampler
@@ -293,12 +293,12 @@
293293 void LegacySunColor(out half4 diff, out float ambi, out float nigh, in float3 normalW)
294294 {
295295 float h = dot(-gSun.direction, normalW);
296- float3 r0 = 1.0 - float3(0.40f, 0.65f, 1.0f) * gDispersion;
296+ float3 r0 = 1.0 - float3(0.40, 0.65, 1.0) * gDispersion;
297297
298298 if (gDispersion!=0) { // case 1: planet has atmosphere
299299 float3 di = (r0 + (1.0-r0) * saturate(h*5.780)) * saturate((h+gSunAppRad)/(2.0*gSunAppRad));
300300 float ni = (h+0.242)*2.924;
301- float am = saturate(gAmbient0*saturate(ni)-0.05 + gGlobalAmb);
301+ float am = saturate(max(gAmbient0*saturate(ni)-0.05, gGlobalAmb));
302302
303303 diff = float4(di*(1.0-am*0.5),1);
304304 ambi = am;
@@ -306,7 +306,7 @@
306306 }
307307 else { // case 2: planet has no atmosphere
308308 diff = float4(r0*saturate((h+gSunAppRad)/(2.0f*gSunAppRad)), 1);
309- ambi = 0;
309+ ambi = gGlobalAmb;
310310 nigh = 0;
311311 }
312312 }
diff -r 71022f40c2a4 -r 373a3b6398dc Modules/D3D9Client/Mesh.fx
--- a/Modules/D3D9Client/Mesh.fx Mon Oct 24 14:51:17 2011 +0200
+++ b/Modules/D3D9Client/Mesh.fx Tue Jun 21 00:00:00 2011 +0200
@@ -309,7 +309,7 @@
309309
310310 float3 r = reflect(gSun.direction, normalW);
311311 float s = pow(max(dot(r, normalize(frg.toCamW)), 0.0f), 20.0f) * (1.0f-dayTex.a);
312- float d = dot(-gSun.direction, normalW);
312+ float d = saturate(dot(-gSun.direction, normalW)*1.5);
313313 //float n = 1.0f;
314314
315315 if (d<0) {
diff -r 71022f40c2a4 -r 373a3b6398dc Modules/D3D9Client/Planet.fx
--- a/Modules/D3D9Client/Planet.fx Mon Oct 24 14:51:17 2011 +0200
+++ b/Modules/D3D9Client/Planet.fx Tue Jun 21 00:00:00 2011 +0200
@@ -32,7 +32,7 @@
3232 float3 tocam = normalize(-posW);
3333 float3 sundir = gSun.direction;
3434
35- float diff = max(dot(-sundir, nrmW), 0.0f);
35+ float diff = saturate(dot(-sundir, nrmW)*1.5);
3636 float dotr = max(dot(reflect(sundir, nrmW), tocam), 0.0f);
3737 float spec = pow(diff,0.25f) * pow(dotr, gWater.specPower);
3838 float nigh = 0.0f;
@@ -87,7 +87,7 @@
8787 float4 color = tex2D(Planet0S, frg.tex0);
8888
8989 if (dot(frg.normalW, frg.toCamW)<0) { // Render cloud layer from below
90- float4 diff = (min(1,frg.aux.g+0.5) * frg.diffuse) * gMat.diffuse + data;
90+ float4 diff = (min(1,frg.aux.g+0.7) * frg.diffuse) * gMat.diffuse + data;
9191 return float4((color.rgb*diff.rgb), color.a*mic);
9292 }
9393
@@ -191,27 +191,4 @@
191191 ZEnable = false;
192192 ZWriteEnable = false;
193193 }
194-}
195-
196-
197-
198-/*
199-float4 PlanetTechPS(TileVS frg) : COLOR
200-{
201- float diff = max(0.0f, dot(-normalize(gSun.direction), normalize(frg.normalW)));
202- float4 vDif = diff * (gSun.diffuse) + (gMat.ambient*gSun.ambient) + (gMat.emissive);
203- float micro = 1.0f;
204-
205- if (gMix>0.0f) micro -= tex2D(Planet3S, frg.tex1).a;
206-
207- float dotr = max(0.0f, dot(reflect(normalize(gSun.direction), normalize(frg.normalW)), normalize(frg.toCamW)));
208-
209- float4 vSpe = (pow(diff,0.5f)*pow(dotr, gWater.specPower)) * (gWater.specular*gSun.specular) * micro;
210-
211- if (gSpecMode==2) vSpe *= 1.0f - tex2D(Planet1S, frg.tex0).a;
212- if (gSpecMode==0) vSpe = 0;
213-
214- float4 color = vDif * tex2D(Planet0S, frg.tex0) + frg.aux.a*tex2D(Planet1S, frg.tex0) + vSpe;
215-
216- return float4(color.rgb+gColor.rgb, 1.0f);
217-}*/
\ No newline at end of file
194+}
\ No newline at end of file
diff -r 71022f40c2a4 -r 373a3b6398dc Modules/Plugin/D3D9Client.dll
Binary file Modules/Plugin/D3D9Client.dll has changed
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/D3D9Client.cpp
--- a/Orbitersdk/D3D9Client/D3D9Client.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/D3D9Client.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -37,7 +37,6 @@
3737 D3D9Client *g_client = 0;
3838 D3D9Catalog *MeshCatalog = 0;
3939
40-
4140 // ==============================================================
4241 // API interface
4342 // ==============================================================
@@ -90,6 +89,7 @@
9089
9190 D3D9Client::D3D9Client (HINSTANCE hInstance) : ogciClass(hInstance)
9291 {
92+ hSplashScreen = NULL;
9393 pFramework = NULL;
9494 pd3dDevice = NULL;
9595 vtab = NULL;
@@ -155,14 +155,19 @@
155155 {
156156 _TRACER;
157157
158+ hSplashScreen = NULL;
158159 hRenderWnd = NULL;
159160 pDefaultTex = NULL;
160161 bControlPanel = false;
162+ bVisualsCreated = false;
161163 bFullscreen = false;
162164 bFailed = false;
165+ bRunning = false;
163166 bSkpGDI = true;
167+ bSafeStartup = true;
164168 viewW = viewH = 0;
165169 viewBPP = 0;
170+ uFrameCounter = 0;
166171 scene = NULL;
167172 meshmgr = NULL;
168173 texmgr = NULL;
@@ -208,9 +213,11 @@
208213 D3D9PadPen::D3D9TechInit(pd3dDevice);
209214 D3D9PadBrush::D3D9TechInit(pd3dDevice);
210215 D3D9Pad::D3D9TechInit(pd3dDevice);
216+
217+ deffont = (oapi::Font*) new D3D9PadFont(18, true, "fixed");
218+ defpen = (oapi::Pen*) new D3D9PadPen(1, 1, 0x00FF00);
211219
212- //ShowDefaultSplash(); // Warning D3D9ClientSurface is not yet fully initialized here
213- SplashScreen();
220+ SplashScreen(); // Warning D3D9ClientSurface is not yet fully initialized here
214221
215222 D3D9ClientSurface::D3D9TechInit(pd3dDevice);
216223 D3D9Effect::D3D9TechInit(pd3dDevice);
@@ -247,7 +254,11 @@
247254 {
248255 _TRACER;
249256 LogAlw("================ clbkPostCreation ===============");
250- if (scene) scene->Initialise();
257+
258+ bStartPaused = oapiGetPause();
259+
260+ if (scene) scene->Initialise(); // This doesn't do much
261+
251262 WriteLog("[Scene Initialized]");
252263 }
253264
@@ -263,7 +274,6 @@
263274 GraphicsClient::clbkCloseSession(fastclose);
264275 SAFE_DELETE(scene);
265276
266- LogAlw("Clearing Garbage Collection");
267277 WriteLog("[Session Closed. Scene deleted.]");
268278 }
269279
@@ -281,16 +291,27 @@
281291 vStar::GlobalExit();
282292 vVessel::GlobalExit();
283293 vObject::GlobalExit();
294+
295+ delete defpen;
296+ delete deffont;
297+
284298 D3D9Pad::GlobalExit();
285299
286300 SAFE_DELETE(meshmgr);
287301 SAFE_DELETE(texmgr);
288-
302+ SAFE_DELETE(hSplashScreen);
303+
289304 pFramework->Reset();
290305
291- pd3dDevice = NULL;
292- viewW = viewH = viewBPP = 0;
293- hRenderWnd = NULL;
306+ pd3dDevice = NULL;
307+ hRenderWnd = NULL;
308+ bVisualsCreated = false;
309+ bFailed = false;
310+ bRunning = false;
311+ bSafeStartup = true;
312+ viewW = viewH = 0;
313+ viewBPP = 0;
314+ uFrameCounter = 0;
294315 }
295316
296317 // ==============================================================
@@ -298,9 +319,12 @@
298319 void D3D9Client::clbkUpdate(bool running)
299320 {
300321 _TRACER;
301- if (bFailed==false) {
302- scene->Update();
303- }
322+ if (bFailed==false) scene->Update();
323+}
324+
325+void D3D9Client::VisualsCreated()
326+{
327+ bVisualsCreated = true;
304328 }
305329
306330 // ==============================================================
@@ -317,8 +341,30 @@
317341 return;
318342 }
319343
344+ if (bSafeStartup && !bRunning && !bStartPaused) {
345+ if (oapiGetSimTime()>1.2) oapiSetPause(true);
346+ if (oapiGetSimTime()>1.2) uFrameCounter++;
347+ if (uFrameCounter>10) {
348+ uFrameCounter = 0;
349+ bSafeStartup = false;
350+ }
351+ clbkBlt(NULL, 0, 0, hSplashScreen);
352+ return;
353+ }
354+
320355 LogOk("== Begin Scene ===========================================================================================================");
321356
357+ scene->UpdateCamVis();
358+
359+ if (bVisualsCreated && !bRunning) {
360+ uFrameCounter++;
361+ if (uFrameCounter>5) {
362+ oapiSetPause(bStartPaused);
363+ bVisualsCreated = false;
364+ bRunning = true;
365+ }
366+ }
367+
322368 bScene = true;
323369 scene->Render();
324370 bScene = false;
@@ -330,19 +376,20 @@
330376
331377 RECT rect = {0, viewH-20, viewW, viewH};
332378 pFramework->GetSmallFont()->DrawTextA(0, oapiDebugString(), -1, &rect, DT_LEFT | DT_TOP, D3DCOLOR_XRGB(255, 255, 255));
333-
379+
334380 if (oapiGetPause()) {
381+ char text[32]; int len;
382+ if (bRunning==true) strcpy_s(text,32,"PAUSED"), len = 6;
383+ else strcpy_s(text,32,"D3D9CLIENT IS STARTING UP"), len = 25;
335384 RECT rect2 = {0,viewH-60,viewW,viewH-20};
336- pFramework->GetLargeFont()->DrawTextA(0, "PAUSED", 6, &rect2, DT_CENTER | DT_TOP, D3DCOLOR_XRGB(0, 0, 0));
385+ pFramework->GetLargeFont()->DrawTextA(0, text, len, &rect2, DT_CENTER | DT_TOP, D3DCOLOR_XRGB(0, 0, 0));
337386 rect2.left-=4; rect2.top-=4;
338- pFramework->GetLargeFont()->DrawTextA(0, "PAUSED", 6, &rect2, DT_CENTER | DT_TOP, D3DCOLOR_XRGB(255, 255, 255));
387+ pFramework->GetLargeFont()->DrawTextA(0, text, len, &rect2, DT_CENTER | DT_TOP, D3DCOLOR_XRGB(255, 255, 255));
339388 }
340389
341390 bScene = false;
342391 HR(pd3dDevice->EndScene());
343392
344- uFrameCounter++;
345-
346393 if (bControlPanel) RenderControlPanel();
347394
348395 LogOk("== End Scene ==");
@@ -360,9 +407,8 @@
360407
361408 bool D3D9Client::clbkDisplayFrame()
362409 {
363- _TRACER;
364- if (!RenderWithPopupWindows()) pFramework->ShowFrame();
365- LogMsg("...return");
410+ if (!RenderWithPopupWindows()) pFramework->ShowFrame();
411+ //else pFramework->ShowFrame();
366412 return true;
367413 }
368414
@@ -605,7 +651,7 @@
605651 if (!bFullscreen) return false; // no special treatment required in windowed mode
606652
607653 if (count) GetDevice()->SetDialogBoxMode(true);
608- else GetDevice()->SetDialogBoxMode(false);
654+ else GetDevice()->SetDialogBoxMode(false);
609655
610656 return false;
611657 }
@@ -765,8 +811,6 @@
765811
766812 if (ngrp==0) return;
767813
768- D3D9Mesh pMesh(this);
769-
770814 float sx = 1.0f/(float)(T->m11), dx = (float)(T->m13);
771815 float sy = 1.0f/(float)(T->m22), dy = (float)(T->m23);
772816 float vw = (float)viewW;
@@ -798,7 +842,7 @@
798842
799843 for (unsigned int k=0;k<gr->nVtx;k++) gr->Vtx[k].z = 0.0f;
800844
801- pMesh.Render2DPanel(gr, SURFACE(surf), &ident, alpha, scale);
845+ D3D9Mesh::Render2DPanel(pd3dDevice, gr, SURFACE(surf), &ident, alpha, scale);
802846 }
803847 }
804848
@@ -1100,7 +1144,8 @@
11001144 DWORD Width = pFramework->GetRenderWidth();
11011145 DWORD Height = pFramework->GetRenderHeight();
11021146 HINSTANCE hInst = oapiGetOrbiterInstance();
1103- SURFHANDLE hScaled = oapiCreateSurface(Width, Height);
1147+
1148+ hSplashScreen = SURFACE(oapiCreateSurface(Width, Height));
11041149
11051150 HBITMAP hBM = LoadBitmap(hInst, MAKEINTRESOURCE(273));
11061151 BITMAP bm;
@@ -1108,7 +1153,7 @@
11081153 GetObject(hBM, sizeof(BITMAP), &bm);
11091154
11101155 HDC hSrc = CreateCompatibleDC(NULL);
1111- HDC hDC = SURFACE(hScaled)->GetDCHard();
1156+ HDC hDC = SURFACE(hSplashScreen)->GetDCHard();
11121157
11131158 HGDIOBJ hOld = SelectObject(hSrc, hBM);
11141159
@@ -1144,24 +1189,32 @@
11441189 if (m>12) m=0;
11451190
11461191 char dataA[128];
1147- sprintf_s(dataA,128,"D3D9Client RC25 Build [%s]",__DATE__);
1192+ sprintf_s(dataA,128,"D3D9Client RC26 Build [%s]",__DATE__);
11481193 char dataB[128];
11491194 sprintf_s(dataB,128,"Build %s %u 20%u [%u]", months[m], d, y, oapiGetOrbiterVersion());
11501195
1196+ char dataC[]={"Warning: Running in GDI compatibility mode. Expect a low framerate."};
11511197 int xc = Width*814/bm.bmWidth;
11521198 int yc = Height*544/bm.bmHeight;
11531199
11541200 TextOut(hDC, xc, yc + 0*20, "ORBITER Space Flight Simulator",30);
11551201 TextOut(hDC, xc, yc + 1*20, dataB, strlen(dataB));
11561202 TextOut(hDC, xc, yc + 2*20, dataA, strlen(dataA));
1203+
1204+ if (bGDIBB) {
1205+ SetTextAlign(hDC, TA_CENTER);
1206+ TextOut(hDC, Width/2, Height-30, dataC, strlen(dataC));
1207+ }
1208+
11571209
11581210 SelectObject(hDC, hO);
11591211 DeleteObject(hF);
11601212
1161- SURFACE(hScaled)->ReleaseDC(hDC);
1213+ SURFACE(hSplashScreen)->ReleaseDC(hDC);
11621214
1163- clbkBlt(NULL, 0, 0, hScaled);
1164- clbkDisplayFrame();
1215+ clbkBlt(NULL, 0, 0, hSplashScreen);
1216+
1217+ pFramework->ShowFrame();
11651218 }
11661219
11671220 #pragma region Drawing_(Sketchpad)_Interface
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/D3D9Client.h
--- a/Orbitersdk/D3D9Client/D3D9Client.h Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/D3D9Client.h Tue Jun 21 00:00:00 2011 +0200
@@ -455,6 +455,7 @@
455455 void DebugString(const char *format, ...) const;
456456 void WriteLog2(const char *format, ...) const;
457457 void SplashScreen();
458+ void VisualsCreated();
458459
459460 const LPD3DXMATRIX GetIdentity() const { return (const LPD3DXMATRIX)&ident; }
460461
@@ -561,6 +562,7 @@
561562 LPDIRECT3DDEVICE9 pd3dDevice;
562563 LPD3D9CLIENTSURFACE pDefaultTex;
563564 LPD3D9CLIENTSURFACE pScatterTest;
565+ LPD3D9CLIENTSURFACE hSplashScreen;
564566
565567 SURFHANDLE hTest;
566568
@@ -572,13 +574,17 @@
572574 bool bScatterUpdate;
573575 bool bSkpGDI;
574576 bool bFullscreen; // fullscreen render mode flag
575- bool bGDIBB; // use stencil buffers
577+ bool bGDIBB;
576578 bool bFailed;
577579 bool bScene;
580+ bool bStartPaused;
581+ bool bVisualsCreated;
582+ bool bSafeStartup;
583+ bool bRunning;
578584
579585 DWORD viewW, viewH; // dimensions of the render viewport
580586 DWORD viewBPP; // bit depth of render viewport
581-
587+
582588 // device enumeration callback function
583589
584590 VideoTab *vtab; // video selection user interface
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/D3D9ControlPanel.cpp
--- a/Orbitersdk/D3D9Client/D3D9ControlPanel.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/D3D9ControlPanel.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -62,9 +62,10 @@
6262 pItemsSkp = oapiGetSketchpad(GetBackBufferHandle());
6363
6464 oapi::Pen * pen = oapiCreatePen(1, 10, 0xFFFF00);
65+ oapi::Pen * nullp = oapiCreatePen(0, 1, 0xFFFFFF);
6566 oapi::Brush *brush = oapiCreateBrush(0xA0000000);
6667
67- pItemsSkp->SetPen(NULL);
68+ pItemsSkp->SetPen(nullp);
6869 pItemsSkp->SetBrush(brush);
6970
7071 pItemsSkp->Rectangle(0, 0, viewW, viewH);
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/D3D9Frame.cpp
--- a/Orbitersdk/D3D9Client/D3D9Frame.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/D3D9Frame.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -16,10 +16,8 @@
1616
1717 using namespace oapi;
1818
19-IDirect3DVertexDeclaration9 *pPatchVertexDecl = NULL;
2019 IDirect3DVertexDeclaration9 *pHazeVertexDecl = NULL;
2120 IDirect3DVertexDeclaration9 *pNTVertexDecl = NULL;
22-IDirect3DVertexDeclaration9 *pAdVertexDecl = NULL;
2321 IDirect3DVertexDeclaration9 *pPosColorDecl = NULL;
2422 IDirect3DVertexDeclaration9 *pPositionDecl = NULL;
2523 IDirect3DVertexDeclaration9 *pVector4Decl = NULL;
@@ -97,10 +95,8 @@
9795 SAFE_RELEASE(pLargeFont);
9896 SAFE_RELEASE(pSmallFont);
9997
100- SAFE_RELEASE(pPatchVertexDecl);
10198 SAFE_RELEASE(pHazeVertexDecl);
10299 SAFE_RELEASE(pNTVertexDecl);
103- SAFE_RELEASE(pAdVertexDecl);
104100 SAFE_RELEASE(pPosColorDecl);
105101 SAFE_RELEASE(pPositionDecl);
106102 SAFE_RELEASE(pPosTexDecl);
@@ -171,7 +167,12 @@
171167
172168 // Hardware CAPS Checks --------------------------------------------------
173169 //
174- HR(pD3D->GetDeviceCaps(Adapter, D3DDEVTYPE_HAL, &caps));
170+ HRESULT hr = pD3D->GetDeviceCaps(Adapter, D3DDEVTYPE_HAL, &caps);
171+
172+ if (hr!=S_OK) {
173+ LogErr("pD3D->GetDeviceCaps(Adapter, D3DDEVTYPE_HAL, &caps)");
174+ return hr;
175+ }
175176
176177 LogAlw("MaxTextureBlendStages..: %u",caps.MaxTextureBlendStages);
177178 LogAlw("MaxTextureWidth........: %u",caps.MaxTextureWidth);
@@ -244,8 +245,6 @@
244245 return -1;
245246 }
246247
247- HRESULT hr = NULL;
248-
249248 if (bIsFullscreen) hr = CreateFullscreenMode();
250249 else hr = CreateWindowedMode();
251250
@@ -266,12 +265,10 @@
266265 }
267266
268267 HR(pd3dDevice->CreateVertexDeclaration(NTVertexDecl, &pNTVertexDecl));
269- HR(pd3dDevice->CreateVertexDeclaration(AdVertexDecl, &pAdVertexDecl));
270268 HR(pd3dDevice->CreateVertexDeclaration(PosColorDecl, &pPosColorDecl));
271269 HR(pd3dDevice->CreateVertexDeclaration(PositionDecl, &pPositionDecl));
272270 HR(pd3dDevice->CreateVertexDeclaration(Vector4Decl, &pVector4Decl));
273271 HR(pd3dDevice->CreateVertexDeclaration(PosTexDecl, &pPosTexDecl));
274- HR(pd3dDevice->CreateVertexDeclaration(PatchVertexDecl, &pPatchVertexDecl));
275272 HR(pd3dDevice->CreateVertexDeclaration(HazeVertexDecl, &pHazeVertexDecl));
276273
277274 // Setup some default fomts
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/D3D9Pad.cpp
--- a/Orbitersdk/D3D9Client/D3D9Pad.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/D3D9Pad.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -19,8 +19,14 @@
1919 HFONT hFont;
2020 } fcache[128];
2121
22+
2223 int nfcache = 0;
24+int pens_allocated = 0;
25+int brushes_allocated = 0;
26+int fonts_allocated = 0;
2327
28+oapi::Font * deffont = 0;
29+oapi::Pen * defpen = 0;
2430
2531 // ======================================================================
2632 // class GDIPad
@@ -64,6 +70,7 @@
6470 }
6571
6672 cfont = deffont;
73+ cpen = defpen;
6774 }
6875
6976
@@ -72,13 +79,16 @@
7279 _TRACE;
7380 if (pTgt) if (pTgt->IsBackBuffer()==false) pTgt->ReleaseGPU();
7481 pTgt = NULL;
82+
83+ //if (cfont!=deffont && cfont!=NULL) LogWrn("Custom font still attached in sketchpad 0x%X",this);
84+ //if (cpen!=defpen && cpen!=NULL) LogWrn("Custom pen still attached in sketchpad 0x%X",this);
85+ //if (cbrush!=NULL) LogWrn("Custom brush still attached in sketchpad 0x%X",this);
86+
7587 LogOk("...D3D9 SketchPad Released");
7688 }
7789
78-
7990 Font *D3D9Pad::SetFont(Font *font) const
8091 {
81- _TRACE;
8292 Font *pfont = cfont;
8393 if (font) cfont = font;
8494 else cfont = deffont;
@@ -88,9 +98,9 @@
8898 Pen *D3D9Pad::SetPen (Pen *pen) const
8999 {
90100 Pen *ppen = cpen;
91- cpen = pen;
92- if (pen) pencolor = ((D3D9PadPen *)pen)->fcolor;
93- else pencolor = D3DXCOLOR(DWORD(0));
101+ if (pen) cpen = pen;
102+ else cpen = NULL;
103+ if (cpen) pencolor = ((D3D9PadPen *)cpen)->fcolor;
94104 return ppen;
95105 }
96106
@@ -165,6 +175,25 @@
165175 origy = y;
166176 }
167177
178+bool D3D9Pad::HasPen()
179+{
180+ if (cpen==NULL) return false;
181+ if (((D3D9PadPen*)cpen)->style==PS_NULL) return false;
182+ return true;
183+}
184+
185+bool D3D9Pad::HasWidePen()
186+{
187+ if (cpen==NULL) return false;
188+ if (((D3D9PadPen*)cpen)->width>1) return true;
189+ return false;
190+}
191+
192+bool D3D9Pad::HasBrush()
193+{
194+ return (cbrush != NULL);
195+}
196+
168197 bool D3D9Pad::Text (int x, int y, const char *str, int len)
169198 {
170199 D3D9Text *pText = ((D3D9PadFont *)cfont)->pFont;
@@ -201,7 +230,7 @@
201230
202231 void D3D9Pad::LineTo (int x, int y)
203232 {
204- if (cpen==NULL) return;
233+ if (!HasPen()) return;
205234 D3DXVECTOR3 pts[2];
206235 pts[0] = D3DXVECTOR3(float(cx), float(cy), 0.0f);
207236 pts[1] = D3DXVECTOR3(float(origx+x), float(origy+y), 0.0f);
@@ -211,7 +240,7 @@
211240
212241 void D3D9Pad::Line (int x0, int y0, int x1, int y1)
213242 {
214- if (cpen==NULL) return;
243+ if (!HasPen()) return;
215244 x0+=origx; y0+=origy;
216245 x1+=origx; y1+=origy;
217246 D3DXVECTOR3 pts[2];
@@ -225,14 +254,9 @@
225254 {
226255 l+=origx; t+=origy;
227256 r+=origx; b+=origy;
228-
229257 D3D9PadPen * pen = (D3D9PadPen*)cpen;
230-
231- if (pen==NULL) Rectangle2(float(l+r)*0.5f, float(t+b)*0.5f, float(r-l), float(b-t));
232- else {
233- if (pen->width==1) Rectangle2(float(l+r)*0.5f, float(t+b)*0.5f, float(r-l), float(b-t));
234- else Rectangle3(float(l+r)*0.5f, float(t+b)*0.5f, float(r-l), float(b-t), pen->width);
235- }
258+ if (HasWidePen()) Rectangle3(float(l+r)*0.5f, float(t+b)*0.5f, float(r-l), float(b-t), pen->width);
259+ else Rectangle2(float(l+r)*0.5f, float(t+b)*0.5f, float(r-l), float(b-t));
236260 }
237261
238262 void D3D9Pad::Ellipse (int l, int t, int r, int b)
@@ -251,13 +275,6 @@
251275 {
252276 if (cpen==NULL) return;
253277 LogErr("D3D9SketchPad: Polyline not implemented");
254- /*
255- D3DXVECTOR3 *pVert = new D3DXVECTOR3[(npt-1)*2];
256-
257- for (int i=0;i<npt;i++) {
258- pVert[i].x = pt[i].x, pVert[i].y = pt[i].y, pVert[i].z = 0.5f;
259- }
260- */
261278 }
262279
263280 // -----------------------------------------------------------------------------------------------
@@ -283,7 +300,7 @@
283300 D3DXVECTOR4 data(x, y, w*0.5f, h*0.5f);
284301 HR(pDev->SetVertexDeclaration(pPositionDecl));
285302
286- if (w<24 && h<24) pDev->SetStreamSource(0, pCircleLow, 0, sizeof(D3DXVECTOR3));
303+ if (w<32 && h<32) pDev->SetStreamSource(0, pCircleLow, 0, sizeof(D3DXVECTOR3));
287304 else pDev->SetStreamSource(0, pCircleHigh, 0, sizeof(D3DXVECTOR3));
288305
289306 FX->SetTechnique(eDraw);
@@ -292,14 +309,14 @@
292309 FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE);
293310 FX->BeginPass(0);
294311
295- if (cbrush) {
296- if (w<24 && h<24) pDev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 15);
312+ if (HasBrush()) {
313+ if (w<32 && h<32) pDev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 15);
297314 else pDev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 63);
298315 }
299- if (cpen) {
316+ if (HasPen()) {
300317 FX->SetValue(eColor, &pencolor, sizeof(D3DXCOLOR));
301318 FX->CommitChanges();
302- if (w<24 && h<24) pDev->DrawPrimitive(D3DPT_LINESTRIP, 1, 15);
319+ if (w<32 && h<32) pDev->DrawPrimitive(D3DPT_LINESTRIP, 1, 15);
303320 else pDev->DrawPrimitive(D3DPT_LINESTRIP, 1, 63);
304321 }
305322 FX->EndPass();
@@ -329,10 +346,10 @@
329346
330347 FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE);
331348 FX->BeginPass(0);
332- if (cbrush) {
349+ if (HasBrush()) {
333350 pDev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &indices, D3DFMT_INDEX16, &verts, sizeof(D3DXVECTOR3));
334351 }
335- if (cpen) {
352+ if (HasPen()) {
336353 FX->SetValue(eColor, &pencolor, sizeof(D3DXCOLOR));
337354 FX->CommitChanges();
338355 pDev->DrawPrimitiveUP(D3DPT_LINESTRIP, 4, &verts, sizeof(D3DXVECTOR3));
@@ -373,10 +390,10 @@
373390 FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE);
374391 FX->BeginPass(0);
375392
376- if (cbrush) {
393+ if (HasBrush()) {
377394 pDev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 8, 2, &f_indices, D3DFMT_INDEX16, &verts, sizeof(D3DXVECTOR3));
378395 }
379- if (cpen) {
396+ if (HasPen()) {
380397 FX->SetValue(eColor, &pencolor, sizeof(D3DXCOLOR));
381398 FX->CommitChanges();
382399 pDev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 8, 8, &o_indices, D3DFMT_INDEX16, &verts, sizeof(D3DXVECTOR3));
@@ -390,13 +407,18 @@
390407 //
391408 void D3D9Pad::GlobalExit()
392409 {
393- if (deffont) delete deffont;
394- deffont = NULL;
410+
411+ if (pens_allocated!=0) LogErr("SketchPad Pens still in use %d",pens_allocated);
412+ if (brushes_allocated!=0) LogErr("SketchPad Brushes still in use %d",brushes_allocated);
413+ if (fonts_allocated!=0) LogErr("SketchPad Fonts still in use %d",fonts_allocated);
414+
415+ if (pens_allocated==0 && brushes_allocated==0 && fonts_allocated==0) LogAlw("Sketchap Exiting... All resources released");
395416
396417 for (int i=0;i<nfcache;i++) {
397418 if (fcache[i].pFont) delete fcache[i].pFont;
398419 if (fcache[i].hFont) DeleteObject(fcache[i].hFont);
399420 }
421+
400422 memset(fcache, 0, 128*sizeof(FontCache));
401423 }
402424
@@ -405,13 +427,10 @@
405427 //
406428 void D3D9Pad::D3D9TechInit(LPDIRECT3DDEVICE9 pDevice)
407429 {
408-
409430 memset(fcache, 0, 128*sizeof(FontCache));
410431
411432 pDev = pDevice;
412433
413- deffont = (oapi::Font*) new D3D9PadFont(18, true, "fixed");
414-
415434 // Initialize Ellipses -------------------------------------------------------------------------
416435 //
417436 HR(pDev->CreateVertexBuffer(17*sizeof(D3DXVECTOR3), 0, 0, D3DPOOL_DEFAULT, &pCircleLow, NULL));
@@ -492,8 +511,6 @@
492511 LPDIRECT3DVERTEXBUFFER9 D3D9Pad::pCircleLow = 0;
493512 LPDIRECT3DVERTEXBUFFER9 D3D9Pad::pCircleHigh = 0;
494513 LPDIRECT3DVERTEXBUFFER9 D3D9Pad::pRect = 0;
495-oapi::Font * D3D9Pad::deffont = 0;
496-
497514 LPDIRECT3DDEVICE9 D3D9PadFont::pDev = 0;
498515 LPDIRECT3DDEVICE9 D3D9PadPen::pDev = 0;
499516 LPDIRECT3DDEVICE9 D3D9PadBrush::pDev = 0;
@@ -509,6 +526,8 @@
509526
510527 D3D9PadFont::D3D9PadFont(int height, bool prop, const char *face, Style style, int orientation) : oapi::Font (height, prop, face, style, orientation)
511528 {
529+ fonts_allocated++;
530+
512531 char *def_fixedface = "Courier New";
513532 char *def_sansface = "Arial";
514533 char *def_serifface = "Times New Roman";
@@ -596,8 +615,8 @@
596615
597616 D3D9PadFont::~D3D9PadFont ()
598617 {
599- //if (bDelete) DeleteObject(hFont); // Delete only rotated GDI fonts
600- if (hFont && bDelete) DeleteObject(hFont);
618+ fonts_allocated--;
619+ if (hFont && bDelete) DeleteObject(hFont); // Delete rotated (non-cached) fonts
601620 }
602621
603622 void D3D9PadFont::D3D9TechInit(LPDIRECT3DDEVICE9 pDevice)
@@ -612,6 +631,8 @@
612631
613632 D3D9PadPen::D3D9PadPen (int s, int w, DWORD col): oapi::Pen (style, width, col)
614633 {
634+ pens_allocated++;
635+
615636 switch (s) {
616637 case 0: style = PS_NULL; break;
617638 case 2: style = PS_DOT; break;
@@ -627,6 +648,7 @@
627648
628649 D3D9PadPen::~D3D9PadPen ()
629650 {
651+ pens_allocated--;
630652 DeleteObject(hPen);
631653 }
632654
@@ -635,12 +657,14 @@
635657 pDev = pDevice;
636658 }
637659
660+
638661 // ======================================================================
639662 // class GDIBrush
640663 // ======================================================================
641664
642665 D3D9PadBrush::D3D9PadBrush (DWORD col): oapi::Brush (col)
643666 {
667+ brushes_allocated++;
644668 if ((col&0xFF000000)==0) col|=0xFF000000;
645669 fcolor = D3DXCOLOR(col);
646670 D3DXCOLORSWAP(&fcolor);
@@ -649,6 +673,7 @@
649673
650674 D3D9PadBrush::~D3D9PadBrush ()
651675 {
676+ brushes_allocated--;
652677 DeleteObject(hBrush);
653678 }
654679
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/D3D9Pad.h
--- a/Orbitersdk/D3D9Client/D3D9Pad.h Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/D3D9Pad.h Tue Jun 21 00:00:00 2011 +0200
@@ -15,6 +15,8 @@
1515 * DirectX calls.
1616 */
1717
18+extern oapi::Font *deffont;
19+extern oapi::Pen *defpen;
1820
1921 class D3D9Pad: public oapi::Sketchpad {
2022
@@ -56,6 +58,10 @@
5658
5759 private:
5860
61+ bool HasPen();
62+ bool HasBrush();
63+ bool HasWidePen();
64+
5965 void Ellipse2( float x, float y, float w, float h);
6066 void Rectangle2(float x, float y, float w, float h);
6167 void Rectangle3(float x, float y, float w, float h, int width);
@@ -78,7 +84,6 @@
7884
7985 D3D9ClientSurface *pTgt;
8086
81- static oapi::Font *deffont;
8287 static LPDIRECT3DDEVICE9 pDev;
8388 static LPDIRECT3DVERTEXBUFFER9 pCircleLow;
8489 static LPDIRECT3DVERTEXBUFFER9 pCircleHigh;
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/D3D9Surface.cpp
--- a/Orbitersdk/D3D9Client/D3D9Surface.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/D3D9Surface.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -1173,6 +1173,7 @@
11731173 //
11741174 void D3D9ClientSurface::SetColorKey(DWORD ck)
11751175 {
1176+ /*
11761177 if (ck=='BEGN') {
11771178 LogErr("Begin Blit Group");
11781179 if (Type!=D3D9S_RTGTTEX) ConvertToRenderTargetTexture();
@@ -1197,9 +1198,9 @@
11971198 ReleaseGPU();
11981199 bBlitGroup = false;
11991200 return;
1200- }
1201+ }*/
12011202
1202- if (ck==0) ck=0xFF000000;
1203+ //if (ck==0) ck=0xFF000000;
12031204 ColorKey = ck;
12041205 ClrKey = D3DXCOLOR(ColorKey);
12051206 }
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/D3D9Util.cpp
--- a/Orbitersdk/D3D9Client/D3D9Util.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/D3D9Util.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -47,11 +47,11 @@
4747 if (atm) { // case 1: planet has atmosphere
4848 lcol = (r0 + (_one-r0) * saturate(h/d)) * saturate((h+rs)/(2.0f*rs));
4949 amb = saturate((h+ae)/aq);
50- amb = saturate(amb0*amb-0.05f+ao);
50+ amb = saturate(max(amb0*amb-0.05f,ao));
5151 lcol *= 1.0f-amb*0.5f; // reduce direct light component to avoid overexposure
5252 }
5353 else { // case 2: planet has no atmosphere
54- lcol = r0 * saturate((h-rs)/(2.0f*rs));
54+ lcol = r0 * saturate((h+rs)/(2.0f*rs));
5555 amb = ao;
5656 lcol *= 1.0f-amb*0.5f; // reduce direct light component to avoid overexposure
5757 }
@@ -79,64 +79,63 @@
7979
8080 VECTOR3 S = GS-GO; // sun's position from base
8181 VECTOR3 P = GO-GP;
82-
82+
83+ double r = length(P);
84+ double s = length(S);
8385 double pres = 1.0;
8486 double size = oapiGetSize(hP);
8587 double grav = oapiGetMass(hP) * 6.67259e-11 / (size*size);
8688
87- double aalt = 1.0;
88- double amb0 = 0.0;
89- double disp = 0.0;
90- double amb = 0.0;
91- double aq = 0.342;
92- double ae = 0.242;
93- double al = 0.0;
89+ float aalt = 1.0f;
90+ float amb0 = 0.0f;
91+ float disp = 0.0f;
92+ float amb = 0.0f;
93+ float aq = 0.342f;
94+ float ae = 0.242f;
95+ float al = 0.0f;
96+ float k = float(sqrt(r*r-size*size)); // HOrizon distance
97+ float alt = float(r-size);
98+ float rs = float(oapiGetSize(hS) / s);
99+ float ac = float(-dotp(S,P)/(r*s)); // sun elevation
94100
95- double r = length(P);
96- double s = length(S); // sun's distance
97- double k = sqrt(r*r-size*size); // HOrizon distance
98- double alt = r-size;
99- double rs = oapiGetSize(hS) / s;
100- double ac = -dotp(S,P)/(r*s); // sun elevation
101+ if (ac>1.0f) ac=1.0f; if (ac<-1.0f) ac=-1.0f;
101102
102- if (ac>1.0) ac=1.0; if (ac<-1.0) ac=-1.0;
103-
104- ac = acos(ac) - asin(size/r);
103+ ac = acos(ac) - asin(float(size/r));
105104
106- if (ac>1.39) ac = 1.39;
107- if (ac<-1.39) ac = -1.39;
105+ if (ac>1.39f) ac = 1.39f;
106+ if (ac<-1.39f) ac = -1.39f;
108107
109- double h = tan(ac);
108+ float h = tan(ac);
110109
111110 const ATMCONST *atm = (oapiGetObjectType(hP)==OBJTP_PLANET ? oapiGetPlanetAtmConstants (hP) : NULL);
112111
113112 if (atm) {
114- aalt = atm->p0 * log(atm->p0/pres) / (atm->rho0*grav);
115- amb0 = min (0.7f, log(float(atm->rho0)+1.0f)*0.4f);
116- disp = max (0.02f, min(0.9f, log(float(atm->rho0)+1.0f)));
113+ aalt = float(atm->p0 * log(atm->p0/pres) / (atm->rho0*grav));
114+ amb0 = float(min (0.7, log(atm->rho0+1.0f)*0.4));
115+ disp = float(max (0.02, min(0.9, log(atm->rho0+1.0))));
117116 }
118117
119- if (alt>10e3) al = aalt / k;
120- else al = 0.173;
118+ if (alt>10e3f) al = aalt / k;
119+ else al = 0.173f;
121120
122121 D3DXVECTOR3 lcol(1,1,1);
123- D3DXVECTOR3 r0 = _one - D3DXVECTOR3(0.45f, 0.75f, 1.0f) * (float)disp;
122+ D3DXVECTOR3 r0 = _one - D3DXVECTOR3(0.45f, 0.75f, 1.0f) * disp;
124123
125124 if (atm) {
126- lcol = (r0 + (_one-r0) * saturate((float)(h/al))) * saturate(float((h+rs)/(2.0f*rs)));
127- amb = amb0 / (alt*0.5e-4 + 1.0);
128- amb = saturate((float)amb*saturate((float)((h+ae)/aq)-0.05f+ao));
129- lcol *= 1.0f-(float)amb*0.5f; // reduce direct light component to avoid overexposure
125+ lcol = (r0 + (_one-r0) * saturate((h/al))) * saturate((h+rs)/(2.0f*rs));
126+ amb = amb0 / (alt*0.5e-4f + 1.0f);
127+ amb = saturate(max(amb*saturate(((h+ae)/aq)-0.05f), ao));
128+ lcol *= 1.0f-amb*0.5f; // reduce direct light component to avoid overexposure
130129 }
131130 else {
132- lcol = (r0 * saturate((float)((h+rs)/(2.0f*rs))));
131+ lcol = r0 * saturate((h+rs)/(2.0f*rs));
133132 amb = ao;
134- lcol *= 1.0f-(float)amb*0.5f; // reduce direct light component to avoid overexposure
133+ lcol *= 1.0f-amb*0.5f; // reduce direct light component to avoid overexposure
135134 }
136135
137136 light->Diffuse = light->Specular = D3DXCOLOR(lcol.x, lcol.y, lcol.z, 1.0f);
138- light->Ambient = D3DXCOLOR((float)amb, (float)amb, (float)amb, 1.0f);
139- light->Direction = D3DXVECTOR3(float(S.x), float(S.y), float(S.z)) * (-1.0f/(float)s);
137+ light->Ambient = D3DXCOLOR(amb, amb, amb, 1.0f);
138+ light->Direction = D3DXVECTOR3(float(S.x), float(S.y), float(S.z)) * (-1.0f/float(s));
140139 }
141140
142141
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/D3D9Util.h
--- a/Orbitersdk/D3D9Client/D3D9Util.h Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/D3D9Util.h Tue Jun 21 00:00:00 2011 +0200
@@ -64,14 +64,6 @@
6464 D3DDECL_END()
6565 };
6666
67-const D3DVERTEXELEMENT9 AdVertexDecl[] = {
68- {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
69- {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
70- {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
71- {0, 32, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0},
72- D3DDECL_END()
73-};
74-
7567 const D3DVERTEXELEMENT9 PatchVertexDecl[] = {
7668 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
7769 {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
@@ -113,18 +105,6 @@
113105 float x; ///< vertex x position
114106 float y; ///< vertex y position
115107 float z; ///< vertex z position
116- float nx; ///< vertex x normal
117- float ny; ///< vertex y normal
118- float nz; ///< vertex z normal
119- float tu; ///< vertex u texture coordinate
120- float tv; ///< vertex v texture coordinate
121- int idx; ///< blend index
122-} ADVERTEX;
123-
124-typedef struct {
125- float x; ///< vertex x position
126- float y; ///< vertex y position
127- float z; ///< vertex z position
128108 float tu; ///< vertex u texture coordinate
129109 float tv; ///< vertex v texture coordinate
130110 } SMVERTEX;
@@ -146,10 +126,8 @@
146126 #define D3D9LTheta 2
147127 #define D3D9LPhi 3
148128
149-extern IDirect3DVertexDeclaration9 *pPatchVertexDecl;
150129 extern IDirect3DVertexDeclaration9 *pHazeVertexDecl;
151130 extern IDirect3DVertexDeclaration9 *pNTVertexDecl;
152-extern IDirect3DVertexDeclaration9 *pAdVertexDecl;
153131 extern IDirect3DVertexDeclaration9 *pPosColorDecl;
154132 extern IDirect3DVertexDeclaration9 *pPositionDecl;
155133 extern IDirect3DVertexDeclaration9 *pPosTexDecl;
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/GDIPad.cpp
--- a/Orbitersdk/D3D9Client/GDIPad.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/GDIPad.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -17,10 +17,9 @@
1717 {
1818 LogOk("Creating GDI SketchPad...");
1919
20- hDC = hdc;
21- hFont0 = NULL;
22- cfont = NULL;
23- cpen = NULL;
20+ hDC = hdc;
21+ cfont = deffont;
22+ cpen = NULL; //defpen;
2423 cbrush = NULL;
2524
2625 //LogAlw("Creating a GDI Sketchpad for surface 0x%X",s);
@@ -28,57 +27,47 @@
2827 // Default initial drawing settings
2928 SetBkMode (hDC, TRANSPARENT); // transparent text background
3029
31- if (cfont) hFont0 = (HFONT)SelectObject(hDC, ((D3D9PadFont*)cfont)->hFont);
30+ if (cfont) SelectObject(hDC, ((D3D9PadFont*)cfont)->hFont);
31+
32+ if (cpen) SelectObject(hDC, ((D3D9PadPen*)cpen)->hPen);
33+ else SelectObject(hDC, GetStockObject (NULL_PEN));
34+
3235 SelectObject (hDC, GetStockObject (NULL_BRUSH)); // no fill
33- SelectObject (hDC, GetStockObject (NULL_PEN)); // no outline
3436 }
3537
3638 GDIPad::~GDIPad ()
3739 {
38- //LogAlw("[CLOSED] GDI Sketchpad");
3940 // make sure to deselect custom resources before destroying the DC
40- if (hFont0) SelectObject (hDC, hFont0);
41- if (cpen) SelectObject (hDC, GetStockObject (NULL_PEN));
42- if (cbrush) SelectObject (hDC, GetStockObject (NULL_BRUSH));
43-
41+ SelectObject (hDC, GetStockObject (NULL_PEN));
42+ SelectObject (hDC, GetStockObject (NULL_BRUSH));
4443 LogOk("...GDI SketchPad Released");
4544 }
4645
4746 Font *GDIPad::SetFont (Font *font) const
4847 {
4948 Font *pfont = cfont;
50- if (font) {
51- HFONT hFont = (HFONT)SelectObject (hDC, ((D3D9PadFont*)font)->hFont);
52- if (!cfont) hFont0 = hFont;
53- } else if (hFont0) { // restore original font
54- SelectObject (hDC, hFont0);
55- hFont0 = 0;
56- }
57- cfont = font;
49+ if (font) cfont = font;
50+ else cfont = deffont;
51+ SelectObject(hDC, ((D3D9PadFont*)cfont)->hFont);
5852 return pfont;
5953 }
6054
6155 Pen *GDIPad::SetPen (Pen *pen) const
6256 {
6357 Pen *ppen = cpen;
64- if (pen) {
65- SelectObject (hDC, ((D3D9PadPen*)pen)->hPen);
66- } else { // disable outlines
67- SelectObject (hDC, GetStockObject (NULL_PEN));
68- }
69- cpen = pen;
58+ if (pen) cpen = pen;
59+ else cpen = NULL;
60+ if (cpen) SelectObject (hDC, ((D3D9PadPen*)cpen)->hPen);
61+ else SelectObject (hDC, GetStockObject (NULL_BRUSH));
7062 return ppen;
7163 }
7264
7365 Brush *GDIPad::SetBrush (Brush *brush) const
7466 {
7567 Brush *pbrush = cbrush;
76- if (brush) {
77- SelectObject (hDC, ((D3D9PadBrush*)brush)->hBrush);
78- } else { // disable filled brush
79- SelectObject (hDC, GetStockObject (NULL_BRUSH));
80- }
8168 cbrush = brush;
69+ if (brush) SelectObject (hDC, ((D3D9PadBrush*)cbrush)->hBrush);
70+ else SelectObject (hDC, GetStockObject (NULL_BRUSH));
8271 return pbrush;
8372 }
8473
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/Log.cpp
--- a/Orbitersdk/D3D9Client/Log.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/Log.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -8,9 +8,11 @@
88
99 FILE *d3d9client_log = NULL;
1010
11+#define LOG_MAX_LINES 250000
1112 #define ERRBUF 8096
1213 #define OPRBUF 512
1314 #define TIMEBUF 63
15+
1416 char ErrBuf[ERRBUF+1];
1517 char OprBuf[OPRBUF+1];
1618 char TimeBuf[TIMEBUF+1];
@@ -62,20 +64,11 @@
6264
6365 char *my_ctime(const time_t *t)
6466 {
65- //if (ctime_s(TimeBuf, TIMEBUF, t)) strcpy_s(TimeBuf, TIMEBUF, "Error");
6667 __int64 qpcCurrent;
6768 QueryPerformanceCounter((LARGE_INTEGER*)&qpcCurrent);
6869 double time = double(qpcCurrent-qpcRef) * 1e6 / double(qpcFrq);
6970 double timet = double(qpcCurrent-qpcStart) / double(qpcFrq);
7071 sprintf_s(OprBuf,OPRBUF,"%d: %.2fs %.0fus",iLine, timet, time); iLine++;
71-
72- /*
73- for (int i=0;i<=OPRBUF;i++) {
74- char c = OprBuf[i];
75- if (c==13 || c==10 || c==0) { OprBuf[i]=0; return OprBuf; }
76- }
77- LogErr("Logging Failed");
78- */
7972 return OprBuf;
8073 }
8174
@@ -84,6 +77,7 @@
8477 void LogMsg(const char *format, ...)
8578 {
8679 if (d3d9client_log==NULL) return;
80+ if (iLine>LOG_MAX_LINES) return;
8781 if (uEnableLog>3) {
8882 DWORD th = GetCurrentThreadId();
8983 time(&ltime);
@@ -93,8 +87,7 @@
9387 va_start(args, format);
9488
9589 _vsnprintf_s(ErrBuf, ERRBUF, ERRBUF, format, args);
96- //va_end(args);
97-
90+
9891 fputs(ErrBuf,d3d9client_log);
9992 fputs("<br>\n",d3d9client_log);
10093 fflush(d3d9client_log);
@@ -106,6 +99,7 @@
10699 void LogAlw(const char *format, ...)
107100 {
108101 if (d3d9client_log==NULL) return;
102+ if (iLine>LOG_MAX_LINES) return;
109103 if (uEnableLog>0) {
110104 DWORD th = GetCurrentThreadId();
111105 time(&ltime);
@@ -115,8 +109,7 @@
115109 va_start(args, format);
116110
117111 _vsnprintf_s(ErrBuf, ERRBUF, ERRBUF, format, args);
118- //va_end(args);
119-
112+
120113 fputs(ErrBuf,d3d9client_log);
121114 fputs("</font><br>\n",d3d9client_log);
122115 fflush(d3d9client_log);
@@ -129,6 +122,7 @@
129122 void LogErr(const char *format, ...)
130123 {
131124 if (d3d9client_log==NULL) return;
125+ if (iLine>LOG_MAX_LINES) return;
132126 if (uEnableLog>0) {
133127 DWORD th = GetCurrentThreadId();
134128 time(&ltime);
@@ -138,8 +132,7 @@
138132 va_start(args, format);
139133
140134 _vsnprintf_s(ErrBuf, ERRBUF, ERRBUF, format, args);
141- //va_end(args);
142-
135+
143136 fputs(ErrBuf,d3d9client_log);
144137 fputs("</font><br>\n",d3d9client_log);
145138 fflush(d3d9client_log);
@@ -151,6 +144,7 @@
151144 void LogBlu(const char *format, ...)
152145 {
153146 if (d3d9client_log==NULL) return;
147+ if (iLine>LOG_MAX_LINES) return;
154148 if (uEnableLog>1) {
155149 DWORD th = GetCurrentThreadId();
156150 time(&ltime);
@@ -160,8 +154,7 @@
160154 va_start(args, format);
161155
162156 _vsnprintf_s(ErrBuf, ERRBUF, ERRBUF, format, args);
163- //va_end(args);
164-
157+
165158 fputs(ErrBuf,d3d9client_log);
166159 fputs("</font><br>\n",d3d9client_log);
167160 fflush(d3d9client_log);
@@ -173,6 +166,7 @@
173166 void LogWrn(const char *format, ...)
174167 {
175168 if (d3d9client_log==NULL) return;
169+ if (iLine>LOG_MAX_LINES) return;
176170 if (uEnableLog>1) {
177171 DWORD th = GetCurrentThreadId();
178172 time(&ltime);
@@ -182,7 +176,6 @@
182176 va_start(args, format);
183177
184178 _vsnprintf_s(ErrBuf, ERRBUF, ERRBUF, format, args);
185- //va_end(args);
186179
187180 fputs(ErrBuf,d3d9client_log);
188181 fputs("</font><br>\n",d3d9client_log);
@@ -195,6 +188,7 @@
195188 void LogOk(const char *format, ...)
196189 {
197190 if (d3d9client_log==NULL) return;
191+ if (iLine>LOG_MAX_LINES) return;
198192 if (uEnableLog>2) {
199193 DWORD th = GetCurrentThreadId();
200194 time(&ltime);
@@ -204,8 +198,7 @@
204198 va_start(args, format);
205199
206200 _vsnprintf_s(ErrBuf, ERRBUF, ERRBUF, format, args);
207- //va_end(args);
208-
201+
209202 fputs(ErrBuf,d3d9client_log);
210203 fputs("</font><br>\n",d3d9client_log);
211204 fflush(d3d9client_log);
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/Mesh.cpp
--- a/Orbitersdk/D3D9Client/Mesh.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/Mesh.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -369,8 +369,8 @@
369369 void D3D9Mesh::ProcessInherit()
370370 {
371371 if (!pVB) return;
372- if (Grp[0]->MtrlIdx == SPEC_INHERIT) { LogWrn("Material SPEC_INHERIT in MesgGroup[0], Mesh=0x%X",this); Grp[0]->MtrlIdx = SPEC_DEFAULT; }
373- if (Grp[0]->TexIdx == SPEC_INHERIT) { LogWrn("Texture SPEC_INHERIT in MeshGroup[0], Mesh=0x%X",this); Grp[0]->TexIdx = SPEC_DEFAULT; }
372+ if (Grp[0]->MtrlIdx == SPEC_INHERIT) Grp[0]->MtrlIdx = SPEC_DEFAULT;
373+ if (Grp[0]->TexIdx == SPEC_INHERIT) Grp[0]->TexIdx = SPEC_DEFAULT;
374374
375375 for (DWORD i=0;i<nGrp;i++) {
376376
@@ -1268,7 +1268,7 @@
12681268
12691269 // ===========================================================================================
12701270 //
1271-void D3D9Mesh::Render2DPanel(const MESHGROUP *mg, const LPD3D9CLIENTSURFACE pTex, const LPD3DXMATRIX pW, float alpha, float scale)
1271+void D3D9Mesh::Render2DPanel(LPDIRECT3DDEVICE9 dev, const MESHGROUP *mg, const LPD3D9CLIENTSURFACE pTex, const LPD3DXMATRIX pW, float alpha, float scale)
12721272 {
12731273 UINT numPasses = 0;
12741274
@@ -1287,11 +1287,11 @@
12871287 HR(FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE));
12881288 HR(FX->BeginPass(0));
12891289
1290- if (alpha<0.5f) gc->GetDevice()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
1291- else gc->GetDevice()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1290+ if (alpha<0.5f) dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
1291+ else dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
12921292
1293- gc->GetDevice()->SetVertexDeclaration(pNTVertexDecl);
1294- gc->GetDevice()->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, mg->nVtx, mg->nIdx/3, mg->Idx, D3DFMT_INDEX16, mg->Vtx, sizeof(NTVERTEX));
1293+ dev->SetVertexDeclaration(pNTVertexDecl);
1294+ dev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, mg->nVtx, mg->nIdx/3, mg->Idx, D3DFMT_INDEX16, mg->Vtx, sizeof(NTVERTEX));
12951295
12961296 HR(FX->EndPass());
12971297 HR(FX->End());
@@ -1301,19 +1301,8 @@
13011301
13021302 void D3D9Mesh::RenderReEntry(LPDIRECT3DDEVICE9 dev, const LPD3D9CLIENTSURFACE pTex, const LPD3DXVECTOR3 vPosA, const LPD3DXVECTOR3 vPosB, const LPD3DXVECTOR3 vDir, float alpha_a, float alpha_b, float size)
13031303 {
1304- /*
1305- static float period = 35.0f;
1306- static double check = 0.0f;
1307-
1308- if (oapiGetSimTime()>check) {
1309- double rnd = oapiRand()*0.25 + 0.75;
1310- check = oapiGetSimTime() + rnd;
1311- period = (8.0f*6.283185f) / float(rnd);
1312- }*/
1313-
1314- static WORD ReentryIdxA[6] = {0,1,2, 3,2,1};
1315- static WORD ReentryIdxB[6] = {0,1,2, 3,2,1};
1316-
1304+ static WORD ReentryIdx[6] = {0,1,2, 3,2,1};
1305+
13171306 static NTVERTEX ReentryVtxB[4] = {
13181307 {0,-1,-1, 0,0,0, 0.51f, 0.01f},
13191308 {0,-1, 1, 0,0,0, 0.99f, 0.01f},
@@ -1321,12 +1310,12 @@
13211310 {0, 1, 1, 0,0,0, 0.99f, 0.49f}
13221311 };
13231312
1324- float x = (5.5f+sin(fmod(float(oapiGetSimTime())*60.0f, 6.283185f))) * 0.7f;
1313+ float x = 4.5f + sin(fmod(float(oapiGetSimTime())*60.0f, 6.283185f)) * 0.5f;
13251314
13261315 NTVERTEX ReentryVtxA[4] = {
1327- {0, 1, 1, 0,0,0, 0.49f, 0.01f},
1316+ {0, 1, 1, 0,0,0, 0.49f, 0.01f},
13281317 {0, 1,-x, 0,0,0, 0.49f, 0.99f},
1329- {0,-1, 1, 0,0,0, 0.01f, 0.01f},
1318+ {0,-1, 1, 0,0,0, 0.01f, 0.01f},
13301319 {0,-1,-x, 0,0,0, 0.01f, 0.99f},
13311320 };
13321321
@@ -1334,7 +1323,7 @@
13341323 D3DXMATRIX WA, WB;
13351324 D3DXVECTOR3 vCam;
13361325 D3DXVec3Normalize(&vCam, vPosA);
1337- D3DMAT_CreateX_Billboard(&vCam, vPosB, size*(1.0f+x*0.1), &WB);
1326+ D3DMAT_CreateX_Billboard(&vCam, vPosB, size*(0.8f+x*0.02f), &WB);
13381327 D3DMAT_CreateX_Billboard(&vCam, vPosA, vDir, size, size, &WA);
13391328
13401329 dev->SetVertexDeclaration(pNTVertexDecl);
@@ -1346,11 +1335,11 @@
13461335 FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE);
13471336 FX->BeginPass(0);
13481337
1349- dev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &ReentryIdxB, D3DFMT_INDEX16, &ReentryVtxB, sizeof(NTVERTEX));
1338+ dev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &ReentryIdx, D3DFMT_INDEX16, &ReentryVtxB, sizeof(NTVERTEX));
13501339 FX->SetFloat(eMix, alpha_a);
13511340 FX->SetMatrix(eW, &WA);
13521341 FX->CommitChanges();
1353- dev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &ReentryIdxA, D3DFMT_INDEX16, &ReentryVtxA, sizeof(NTVERTEX));
1342+ dev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &ReentryIdx, D3DFMT_INDEX16, &ReentryVtxA, sizeof(NTVERTEX));
13541343
13551344 FX->EndPass();
13561345 FX->End();
@@ -1399,6 +1388,7 @@
13991388 void D3D9Mesh::TransformGroup(DWORD n, const D3DXMATRIX *m)
14001389 {
14011390 if (!pVB) return;
1391+
14021392 bBSRecompute = true;
14031393 Grp[n]->bTransform = true;
14041394 Grp[n]->Transform = Grp[n]->Transform * (*m);
@@ -1410,6 +1400,7 @@
14101400 void D3D9Mesh::Transform(const D3DXMATRIX *m)
14111401 {
14121402 if (!pVB) return;
1403+
14131404 bBSRecompute = true;
14141405 bGlobalTF = true;
14151406 mTransform = mTransform * (*m);
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/Mesh.h
--- a/Orbitersdk/D3D9Client/Mesh.h Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/Mesh.h Tue Jun 21 00:00:00 2011 +0200
@@ -130,7 +130,8 @@
130130 void RenderExhaust(LPDIRECT3DDEVICE9 dev, float alpha, const LPD3DXMATRIX pW, LPD3D9CLIENTSURFACE pTex);
131131 void RenderBaseTile(LPDIRECT3DDEVICE9 dev, const LPD3DXMATRIX pW, LPD3D9CLIENTSURFACE pTex);
132132 void RenderSpot(LPDIRECT3DDEVICE9 dev, float intens, const LPD3DXCOLOR color, const LPD3DXMATRIX pW, LPD3D9CLIENTSURFACE pTex);
133- void Render2DPanel(const MESHGROUP *mg, const LPD3D9CLIENTSURFACE pTex, const LPD3DXMATRIX pW, float alpha, float scale);
133+
134+ static void Render2DPanel(LPDIRECT3DDEVICE9 dev, const MESHGROUP *mg, const LPD3D9CLIENTSURFACE pTex, const LPD3DXMATRIX pW, float alpha, float scale);
134135 static void RenderReEntry(LPDIRECT3DDEVICE9 dev, const LPD3D9CLIENTSURFACE pTex, const LPD3DXVECTOR3 vPosA, const LPD3DXVECTOR3 vPosB, const LPD3DXVECTOR3 vDir, float alpha_a, float alpha_b, float size);
135136
136137 void Render(LPDIRECT3DDEVICE9 dev, const LPD3DXMATRIX pW, int iTech=0);
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/Scene.cpp
--- a/Orbitersdk/D3D9Client/Scene.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/Scene.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -108,6 +108,8 @@
108108 delete []pstream;
109109 }
110110
111+ DeleteAllVisuals();
112+
111113 ExitGDIResources();
112114 }
113115
@@ -180,7 +182,6 @@
180182 void Scene::DelVisualRec (VOBJREC *pv)
181183 {
182184 _TRACE;
183- LogAlw("DelVisualRec");
184185 // unlink the entry
185186 if (pv->prev) pv->prev->next = pv->next;
186187 else vobjFirst = pv->next;
@@ -194,6 +195,23 @@
194195 delete pv;
195196 }
196197
198+
199+void Scene::DeleteAllVisuals()
200+{
201+ _TRACE;
202+ VOBJREC *pv = vobjFirst;
203+ while (pv) {
204+ VOBJREC *pvn = pv->next;
205+ gc->UnregisterVisObject(pv->vobj->GetObject());
206+ LogAlw("Deleting Visual 0x%X",pv->vobj);
207+ delete pv->vobj;
208+ delete pv;
209+ pv = pvn;
210+ }
211+ vobjFirst = vobjLast = NULL;
212+}
213+
214+
197215 Scene::VOBJREC *Scene::AddVisualRec(OBJHANDLE hObj)
198216 {
199217 _TRACER;
@@ -218,8 +236,7 @@
218236
219237 LogAlw("RegisteringVisual (%s) hVessel=0x%X, hObj=0x%X, Vis=0x%X, Rec=0x%X, Type=%d", buf, hVes, hObj, pv->vobj, pv, pv->type);
220238 gc->RegisterVisObject(hObj, (VISHANDLE)pv->vobj);
221- LogMsg("Visual Registered succesfully");
222-
239+
223240 return pv;
224241 }
225242
@@ -261,7 +278,10 @@
261278 // check object visibility (one object per frame in the interest
262279 // of scalability)
263280 DWORD nobj = oapiGetObjectCount();
264- if (iVCheck >= nobj) iVCheck = 0;
281+ if (iVCheck >= nobj) {
282+ iVCheck = 0;
283+ gc->VisualsCreated();
284+ }
265285 OBJHANDLE hObj = oapiGetObjectByIndex(iVCheck++);
266286
267287 CheckVisual(hObj);
@@ -377,8 +397,6 @@
377397 {
378398 _TRACE;
379399
380- UpdateCamVis();
381-
382400 D3DXCOLOR yellow(1.0f, 1.0f, 0.0f, 1.0f);
383401
384402 VOBJREC *pv = NULL;
@@ -808,6 +826,8 @@
808826 }
809827 }
810828
829+ pSketch->SetFont(NULL);
830+ pSketch->SetPen(NULL);
811831
812832 oapiReleaseSketchpad(pSketch);
813833
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/Scene.h
--- a/Orbitersdk/D3D9Client/Scene.h Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/Scene.h Tue Jun 21 00:00:00 2011 +0200
@@ -66,6 +66,7 @@
6666 inline const DWORD ViewH() const { return viewH; }
6767 // return viewport dimensions
6868
69+ void UpdateCamVis();
6970 void CheckVisual (OBJHANDLE hObj);
7071 // checks if hObj is within visual range, and creates or
7172 // deletes the associated vObject as required.
@@ -166,6 +167,7 @@
166167 // NULL if not found
167168
168169 void DelVisualRec (VOBJREC *pv);
170+ void DeleteAllVisuals();
169171 // Delete entry pv from the list of visuals
170172
171173 VOBJREC *AddVisualRec (OBJHANDLE hObj);
@@ -177,7 +179,7 @@
177179 void InitGDIResources();
178180 void ExitGDIResources();
179181
180- void UpdateCamVis();
182+
181183
182184
183185 // Scene variables ================================================================
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/TileMgr.cpp
--- a/Orbitersdk/D3D9Client/TileMgr.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/TileMgr.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -58,6 +58,9 @@
5858 maxlvl = maxbaselvl = 0;
5959 microtex = 0;
6060 microlvl = 0.0;
61+ tiledesc = NULL;
62+ texbuf = NULL;
63+ specbuf = NULL;
6164 cAmbient = 0;
6265 bPreloadTile = cfg->PlanetPreloadMode;
6366 if (bPreloadTile) LogAlw("PreLoad Highres textures");
@@ -69,20 +72,20 @@
6972 {
7073 DWORD i, maxidx = patchidx[maxbaselvl];
7174
72- if (ntex) {
75+ if (ntex && texbuf) {
7376 for (i = 0; i < ntex; i++)
7477 texbuf[i]->Release();
7578 delete []texbuf;
7679 }
77- if (nmask) {
80+ if (nmask && specbuf) {
7881 for (i = 0; i < nmask; i++)
7982 specbuf[i]->Release();
8083 delete []specbuf;
8184 }
8285
83- delete tilebuf;
84- delete []tiledesc;
85- delete []objname;
86+ //delete tilebuf; // This is static resource created in GlobalInit
87+ if (tiledesc) delete []tiledesc;
88+ if (objname) delete []objname;
8689 }
8790
8891 // =======================================================================
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/VObject.cpp
--- a/Orbitersdk/D3D9Client/VObject.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/VObject.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -200,7 +200,7 @@
200200 D3DXMATRIX W;
201201 D3DXVECTOR3 vCam;
202202 D3DXVECTOR3 vPos(float(cpos.x), float(cpos.y), float(cpos.z));
203- vPos*=ds;
203+ vPos*=float(ds);
204204
205205 D3DXVec3Normalize(&vCam, &vPos);
206206 D3DMAT_CreateX_Billboard(&vCam, &vPos, size, &W);
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/VPlanet.cpp
--- a/Orbitersdk/D3D9Client/VPlanet.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/VPlanet.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -100,7 +100,7 @@
100100 for (DWORD i=0;i<nbase;i++) vbase[i] = NULL;
101101
102102
103- if (gc->Cfg()->PreLBaseVis) {
103+ if (gc->Cfg()->PreLBaseVis && _hObj==oapiGetFocusInterface()->GetSurfaceRef()) {
104104 LogAlw("PreLoading Base Visuals");
105105 for (DWORD i=0;i<nbase;i++) {
106106 OBJHANDLE hBase = oapiGetBaseByIndex (_hObj, i);
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/VVessel.cpp
--- a/Orbitersdk/D3D9Client/VVessel.cpp Mon Oct 24 14:51:17 2011 +0200
+++ b/Orbitersdk/D3D9Client/VVessel.cpp Tue Jun 21 00:00:00 2011 +0200
@@ -112,7 +112,7 @@
112112 case EVENT_VESSEL_MESHVISMODE:
113113 {
114114 //LogBlu("EVENT_VESSEL_MESHVISMODE");
115- LogAlw("VisMode set to 0x%hX",vessel->GetMeshVisibilityMode(context));
115+ //LogAlw("VisMode set to 0x%hX",vessel->GetMeshVisibilityMode(context));
116116 if (context < nmesh) meshlist[context].vismode = vessel->GetMeshVisibilityMode(context);
117117 } break;
118118
@@ -381,6 +381,9 @@
381381 void vVessel::UpdateAnimations (UINT mshidx)
382382 {
383383 double newstate;
384+
385+ nanim = vessel->GetAnimPtr(&anim);
386+
384387 for (UINT i = 0; i < nanim; i++) {
385388 if (!anim[i].ncomp) continue;
386389 if (animstate[i] != (newstate = anim[i].state)) {
@@ -845,7 +848,7 @@
845848 void vVessel::AnimateComponent (ANIMATIONCOMP *comp, const D3DXMATRIX &T)
846849 {
847850 UINT i;
848-
851+
849852 bBSRecompute = true;
850853
851854 MGROUP_TRANSFORM *trans = comp->trans;
@@ -962,13 +965,13 @@
962965 vessel->GlobalRot(d, d);
963966 normalise(d);
964967
965- float x = dotp(d, unit(cpos));
968+ float x = float(dotp(d, unit(cpos)));
966969 if (x<0) x=-x; x=pow(x,0.3f);
967970
968- float alpha_B = (x*0.45f + 0.40f) * ints;
969- float alpha_A = (1.0f - x*0.50) * ints * 1.2f;
971+ float alpha_B = (x*0.40f + 0.60f) * ints;
972+ float alpha_A = (1.0f - x*0.50f) * ints * 1.2f;
970973
971- float size = vessel->GetSize()*1.7f;
974+ float size = float(vessel->GetSize()) * 1.7f;
972975
973976 D3DXVECTOR3 vPosA(float(cpos.x), float(cpos.y), float(cpos.z));
974977 D3DXVECTOR3 vDir(float(d.x), float(d.y), float(d.z));
diff -r 71022f40c2a4 -r 373a3b6398dc Orbitersdk/D3D9Client/VideoTab.rc
--- a/Orbitersdk/D3D9Client/VideoTab.rc Mon Oct 24 14:51:17 2011 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,113 +0,0 @@
1-//Microsoft Developer Studio generated resource script.
2-//
3-#include "VideoTabRS.h"
4-
5-#define APSTUDIO_READONLY_SYMBOLS
6-/////////////////////////////////////////////////////////////////////////////
7-//
8-// Generated from the TEXTINCLUDE 2 resource.
9-//
10-#include "afxres.h"
11-
12-/////////////////////////////////////////////////////////////////////////////
13-#undef APSTUDIO_READONLY_SYMBOLS
14-
15-/////////////////////////////////////////////////////////////////////////////
16-// Finnish resources
17-
18-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FIN)
19-#ifdef _WIN32
20-LANGUAGE LANG_FINNISH, SUBLANG_DEFAULT
21-#pragma code_page(1252)
22-#endif //_WIN32
23-
24-/////////////////////////////////////////////////////////////////////////////
25-//
26-// Dialog
27-//
28-
29-IDD_VIDEOTAB DIALOG DISCARDABLE 0, 0, 345, 210
30-STYLE WS_CHILD | WS_BORDER
31-FONT 8, "MS Sans Serif"
32-BEGIN
33- GROUPBOX "3D Adapter",IDC_ADAPTERFRAME,15,7,310,36
34- GROUPBOX "",IDC_FRAME1,15,50,149,152
35- GROUPBOX "",IDC_FRAME2,177,50,149,152
36- PUSHBUTTON "Fullscreen",IDC_FULLSCREEN,29,63,115,14
37- PUSHBUTTON "Windowed",IDC_WINDOWED,193,63,115,14
38- EDITTEXT IDC_WIDTH,195,97,48,12,ES_AUTOHSCROLL
39- EDITTEXT IDC_HEIGHT,255,97,50,12,ES_AUTOHSCROLL
40- LTEXT "Width",IDC_STATIC2X,195,85,48,10
41- LTEXT "Height",IDC_STATIC3X,255,85,48,10
42- COMBOBOX IDC_ASPECT,195,130,110,15,CBS_DROPDOWN | CBS_SORT |
43- WS_VSCROLL | WS_TABSTOP
44- LTEXT "Aspect ration",IDC_STATIC1X,195,118,42,10
45- COMBOBOX IDC_RESOLUTION,30,97,115,12,CBS_DROPDOWN | CBS_SORT |
46- WS_VSCROLL | WS_TABSTOP
47- LTEXT "Video Resolution",IDC_STATIC4X,30,85,55,10
48- CONTROL "V.Sync On",IDC_VSYNC,"Button",BS_AUTOCHECKBOX |
49- WS_TABSTOP,30,120,105,10
50- COMBOBOX IDC_ADAPTER,27,21,284,14,CBS_DROPDOWN | CBS_SORT |
51- WS_VSCROLL | WS_TABSTOP
52-END
53-
54-
55-/////////////////////////////////////////////////////////////////////////////
56-//
57-// DESIGNINFO
58-//
59-
60-#ifdef APSTUDIO_INVOKED
61-GUIDELINES DESIGNINFO DISCARDABLE
62-BEGIN
63- IDD_VIDEOTAB, DIALOG
64- BEGIN
65- LEFTMARGIN, 7
66- RIGHTMARGIN, 338
67- TOPMARGIN, 7
68- BOTTOMMARGIN, 203
69- END
70-END
71-#endif // APSTUDIO_INVOKED
72-
73-
74-#ifdef APSTUDIO_INVOKED
75-/////////////////////////////////////////////////////////////////////////////
76-//
77-// TEXTINCLUDE
78-//
79-
80-1 TEXTINCLUDE DISCARDABLE
81-BEGIN
82- "resource.h\0"
83-END
84-
85-2 TEXTINCLUDE DISCARDABLE
86-BEGIN
87- "#include ""afxres.h""\r\n"
88- "\0"
89-END
90-
91-3 TEXTINCLUDE DISCARDABLE
92-BEGIN
93- "\r\n"
94- "\0"
95-END
96-
97-#endif // APSTUDIO_INVOKED
98-
99-#endif // Finnish resources
100-/////////////////////////////////////////////////////////////////////////////
101-
102-
103-
104-#ifndef APSTUDIO_INVOKED
105-/////////////////////////////////////////////////////////////////////////////
106-//
107-// Generated from the TEXTINCLUDE 3 resource.
108-//
109-
110-
111-/////////////////////////////////////////////////////////////////////////////
112-#endif // not APSTUDIO_INVOKED
113-
Show on old repository browser