The cockpit displays were updating every two to three seconds while the 3D view held a perfectly smooth 55 fps. This is why, and it is one line. Every device was created D3DCREATE_SOFTWARE_VERTEXPROCESSING - every vertex on the track transformed and lit on the CPU, on the one core this game uses for everything. That was not a choice when the engine was written; there was no hardware to hand it to. The error message beneath the call still says "Couldn't create HARDWARE_VERTEXPROCESSING device", so the flag was changed at some point and the message left behind. Measured on the biggest track, 1920x1080: software foreground 17.2 ms background 1.2 ms 2.4 gauge passes/s hardware foreground 0.2 ms background 17.9 ms 50.0 gauge passes/s The frame loop runs the foreground and then spends whatever is LEFT on the background gauge work. A foreground costing 17.2 ms of an 18 ms frame leaves nothing, so the gauge loop got the single pass it is guaranteed and no more. A pass needs about twenty steps - eighteen gauges and three display copies - so the cockpit ran at two passes a second, and since the renderer walks a sixteen-step rate wheel, a gauge on one step redrew once per SIXTEEN of those. Three seconds. The map, the clock, the boost gauge and the sim still running after the fade to black were all that one number. Hardware T&L is now the default and sw is the way back. Fixed-function lighting and fog are not bit-identical between the old software path and a driver, so the escape hatch stays - but the picture was checked against both and the difference is not the one worth defending. A cockpit whose instruments update twice a second is. It falls back to software by itself if the adapter has no hardware T&L. The instruments that found it stay in, because nothing about this was visible from outside: - FrameSplit, under RP412GAUGEDIAG, reports foreground against background against whole frame. APPMGR has computed those four timestamps every frame since forever and never reported one of them; it would have pointed here on the first day. - FrameDiag reports frames per second on the same window, so the gauge sweep rate can be read against the frame rate rather than guessed at. - ProfileReport, which already existed and was only reachable through F11 on the RIO controls mapper - not the mapper a desktop player runs, so in practice unreachable - now runs on a timer under RP412GAUGEPROFILE. Its per-gauge line gains the rate mask and tier, which is what names a display as one-in-sixteen rather than merely slow. - The winners' circle logs what its exterior and name-plate rebuilds cost, since nothing else runs while they do. RP412VSYNC is here too, and it is honest about itself: presenting IMMEDIATE was measured and made no difference to the frame budget, because the frame was full of work rather than waiting. It stays as a latency-against-tearing preference, not a fix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
312 lines
7.7 KiB
C++
312 lines
7.7 KiB
C++
#include "munga.h"
|
|
#pragma hdrstop
|
|
|
|
#include "appmgr.h"
|
|
|
|
HWND ghWnd = 0;
|
|
|
|
// per-frame observer slot (see RunMissions); the game layer registers
|
|
// the single-player local-console marshal here
|
|
void (*gPerFrameHook)() = NULL;
|
|
|
|
// an in-process console owns the launch (hosted network races)
|
|
Logical gConsoleMarshalsLaunch = False;
|
|
|
|
// losing the console mid-mission ends it (lobby-member races)
|
|
Logical gConsoleLossEndsMission = False;
|
|
|
|
// the console's countdown, when a console is marshalling (see APPMGR.h)
|
|
Logical (*gMissionClockHook)(Scalar *seconds_remaining) = NULL;
|
|
|
|
ApplicationManager* ApplicationManager::CurrentAppManager = NULL;
|
|
|
|
ApplicationManager::ApplicationManager(HINSTANCE hInstance, HWND hWnd, Scalar frame_rate) : Node(ApplicationManagerClassID), runningApplications(this)
|
|
{
|
|
frameRate = frame_rate;
|
|
frameDuration = 1.0f/frameRate;
|
|
mHInstance = hInstance;
|
|
ghWnd = hWnd;
|
|
ApplicationManager::CurrentAppManager = this;
|
|
Check_Fpu();
|
|
}
|
|
|
|
ApplicationManager::~ApplicationManager()
|
|
{
|
|
}
|
|
|
|
void ApplicationManager::StartApplication(Application *new_app)
|
|
{
|
|
Check(this);
|
|
Check(new_app);
|
|
|
|
runningApplications.Add(new_app);
|
|
application = new_app;
|
|
new_app->Initialize();
|
|
}
|
|
|
|
//
|
|
//#############################################################################
|
|
// RunMissions
|
|
//#############################################################################
|
|
//
|
|
void ApplicationManager::RunMissions()
|
|
{
|
|
Check(this);
|
|
int backgroundTasksRun = 0;
|
|
int foregroundTasksRun = 0;
|
|
Time beginFrameTimestamp, lastFrameTimestamp;
|
|
|
|
MSG msg;
|
|
SChainIteratorOf<Application*> current_application(runningApplications);
|
|
SChainOf<Application*> endedApplications(NULL);
|
|
SChainIteratorOf<Application*> endingApplication(endedApplications);
|
|
|
|
Start_Of_Frame:
|
|
backgroundTasksRun = 0;
|
|
foregroundTasksRun = 0;
|
|
beginFrameTimestamp = Now();
|
|
|
|
current_application.First();
|
|
|
|
lastFrameTimestamp = Now();
|
|
|
|
Time end_of_frame = Now();
|
|
end_of_frame += frameDuration;
|
|
#if defined(LAB_ONLY)
|
|
int bad_count = 0;
|
|
#endif
|
|
|
|
//
|
|
//----------------------------------
|
|
// Run all relevant foreground loops
|
|
//----------------------------------
|
|
//
|
|
|
|
Time startForeground = Now();
|
|
while ((application = current_application.ReadAndNext()) != NULL)
|
|
{
|
|
Check(application);
|
|
foregroundTasksRun++;
|
|
|
|
//------------------------------------------------------------------
|
|
// Give the per-frame observer a slice while 'application' is live
|
|
// (the loop condition NULLs the global on exit). The single-player
|
|
// local-console marshal hangs off this; NULL when unregistered.
|
|
//------------------------------------------------------------------
|
|
if (gPerFrameHook != NULL)
|
|
{
|
|
(*gPerFrameHook)();
|
|
}
|
|
|
|
if (!application->ExecuteForeground(end_of_frame, frameDuration))
|
|
{
|
|
if (!application->Shutdown(current_application.GetSize()))
|
|
{
|
|
endedApplications.Add(application);
|
|
|
|
if (current_application.GetCurrent() == NULL)
|
|
{
|
|
current_application.Last();
|
|
} else
|
|
{
|
|
current_application.Previous();
|
|
}
|
|
current_application.Remove();
|
|
}
|
|
}
|
|
}
|
|
Time endForeground = Now();
|
|
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// Check the Windows message queue for messages to be processed
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
//InvalidateRect(ghWnd, NULL, false);
|
|
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
{
|
|
if (msg.message == WM_QUIT)
|
|
{
|
|
endingApplication.First();
|
|
|
|
while (application = endingApplication.ReadAndNext())
|
|
{
|
|
application->Terminate();
|
|
delete application;
|
|
}
|
|
|
|
return;
|
|
}
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// Run all relevant background loops until it is time for the next frame.
|
|
// If no applications remain, exit the whole loop
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
current_application.First();
|
|
application = current_application.GetCurrent();
|
|
if (!application)
|
|
{
|
|
endingApplication.First();
|
|
|
|
while (application = endingApplication.ReadAndNext())
|
|
{
|
|
application->Terminate();
|
|
delete application;
|
|
}
|
|
return;
|
|
}
|
|
|
|
do
|
|
{
|
|
while (application->GetNetworkManager()->RoutePacket())
|
|
;
|
|
|
|
current_application.Next();
|
|
application = current_application.GetCurrent();
|
|
} while (application);
|
|
|
|
current_application.First();
|
|
application = current_application.GetCurrent();
|
|
if (!application)
|
|
{
|
|
endingApplication.First();
|
|
|
|
while (application = endingApplication.ReadAndNext())
|
|
{
|
|
application->Terminate();
|
|
delete application;
|
|
}
|
|
return;
|
|
}
|
|
|
|
//
|
|
//------------------------------------------------------------------
|
|
// Give each application a chance to do at least one background task
|
|
//------------------------------------------------------------------
|
|
//
|
|
Time startBackground = Now();
|
|
Background_Loop:
|
|
do
|
|
{
|
|
Check(application);
|
|
application->ExecuteBackgroundTask();
|
|
backgroundTasksRun++;
|
|
|
|
//
|
|
// Move to the next application
|
|
//
|
|
current_application.Next();
|
|
application = current_application.GetCurrent();
|
|
} while (application);
|
|
|
|
//
|
|
//---------------------------------------------------------------------
|
|
// If time remains before the next frame is due, do another pass on the
|
|
// background tasks
|
|
//---------------------------------------------------------------------
|
|
//
|
|
Time t2 = Now();
|
|
Time lateTime = Now();
|
|
lateTime += 15L;
|
|
|
|
current_application.First();
|
|
application = current_application.GetCurrent();
|
|
|
|
if (t2 < end_of_frame)
|
|
{
|
|
|
|
#if defined(LAB_ONLY)
|
|
if (end_of_frame - t2 > 0.1f)
|
|
{
|
|
DEBUG_STREAM << t2 << ',' << end_of_frame << endl << std::flush;
|
|
if (++bad_count == 1000)
|
|
{
|
|
Fail("End-of-frame cannot be correctly calculated!");
|
|
}
|
|
}
|
|
#endif
|
|
goto Background_Loop;
|
|
}
|
|
Time endBackground = Now();
|
|
|
|
//
|
|
//---------------------------------------------------------------------
|
|
// RP412GAUGEDIAG=1: where the frame actually goes.
|
|
//
|
|
// These four timestamps have been computed every frame since forever
|
|
// and never reported. The whole cockpit problem is a question about
|
|
// this split - the background loop only gets what the foreground
|
|
// leaves - and it has been measurable all along.
|
|
//---------------------------------------------------------------------
|
|
//
|
|
{
|
|
static int
|
|
frameSplitDiag = -1;
|
|
|
|
if (frameSplitDiag < 0)
|
|
{
|
|
const char
|
|
*setting = getenv("RP412GAUGEDIAG");
|
|
|
|
frameSplitDiag = (setting != NULL && atoi(setting) != 0) ? 1 : 0;
|
|
}
|
|
if (frameSplitDiag)
|
|
{
|
|
static Scalar
|
|
foregroundSum = (Scalar) 0,
|
|
backgroundSum = (Scalar) 0,
|
|
frameSum = (Scalar) 0;
|
|
static int
|
|
splitFrames = 0;
|
|
static Logical
|
|
splitStarted = False;
|
|
static Time
|
|
splitWindowStart;
|
|
|
|
Time
|
|
splitNow = Now();
|
|
|
|
foregroundSum += (Scalar)(endForeground - startForeground);
|
|
backgroundSum += (Scalar)(endBackground - startBackground);
|
|
frameSum += (Scalar)(splitNow - beginFrameTimestamp);
|
|
++splitFrames;
|
|
|
|
if (!splitStarted)
|
|
{
|
|
splitStarted = True;
|
|
splitWindowStart = splitNow;
|
|
}
|
|
else if ((Scalar)(splitNow - splitWindowStart) >= (Scalar) 2)
|
|
{
|
|
char
|
|
buffer[200];
|
|
|
|
sprintf(buffer,
|
|
"FrameSplit: %d frames | foreground %.2f ms | "
|
|
"background %.2f ms | whole frame %.2f ms\n",
|
|
splitFrames,
|
|
(double)(foregroundSum * 1000.0f / splitFrames),
|
|
(double)(backgroundSum * 1000.0f / splitFrames),
|
|
(double)(frameSum * 1000.0f / splitFrames));
|
|
DEBUG_STREAM << buffer << std::flush;
|
|
|
|
foregroundSum = backgroundSum = frameSum = (Scalar) 0;
|
|
splitFrames = 0;
|
|
splitWindowStart = splitNow;
|
|
}
|
|
}
|
|
}
|
|
|
|
//char str[256];
|
|
//Scalar lastFrameLength = Now() - beginFrameTimestamp;
|
|
//sprintf(str, "RPL4 - %.2f FPS", 1.0f / lastFrameLength);
|
|
//SetWindowTextA(ghWnd, str);
|
|
|
|
goto Start_Of_Frame;
|
|
}
|