The lobby could stage a room but the launched mission never fed the members.
BTLocalConsole_InstallNetworkMission (btl4console.cpp) makes the host play the
arcade console in-process over the NetTransport seam (Winsock TCP or Steam SDR):
- connect to each member's console channel (ip[:port] from BT412HOSTPODS);
- feed each the chunked egg (NetworkManager::ReceiveEggFileMessage, \n->NUL
wire image like tools/btconsole.py), resending until it ACKs;
- poll member state (StateQueryMessage); when the whole mesh is staged at
WaitingForLaunch, dispatch RunMission to every member + locally at once;
- StopMission at expiry (members first, then self after a short grace);
- scores are BT's kills/deaths snapshotted from the *meshed* roster at the
stop -- no EndMission wire intake (that flow is a BT stub; the mesh already
put every pilot in the host's roster). The owner's own pod is fed locally
via L4NetworkManager::FeedLocalEgg.
Engine change (ported 1:1 from RP412): gConsoleMarshalsLaunch (APPMGR.h/.cpp) +
the `!gConsoleMarshalsLaunch &&` guard in APP.cpp's WaitingForLaunch self-launch.
The owner has no console connection to itself, so without this it would
self-launch before the mesh staged and never send the coordinated RunMission.
Default False = stock behavior; solo boot un-regressed.
WinMain host path (btl4main.cpp) now honors BT412HOSTPODS (+BT412HOSTPORT) for
the lobby host AND a classic-LAN host: SetNetworkCommonFlatAddress +
InstallNetworkMission, falling back to a solo marshal if no member is reachable.
Verified (loopback): two `btl4.exe -net` pods fed by tools/btconsole.py reach
"All connections completed!" and run after the engine change -- the exact
protocol + launch handshake the marshal uses. Both gates build+link; the
Release dist boots and the Steam transport comes up. The live multi-machine
Steam mission (FakeIP mesh + pilot-slot matching) is untestable here -- see the
new docs/STEAM-3-MACHINE-TEST.md. Dist README updated: multiplayer is now
"newly implemented, please test" rather than deferred.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
263 lines
6.9 KiB
C++
263 lines
6.9 KiB
C++
#include "munga.h"
|
|
#pragma hdrstop
|
|
|
|
#include "appmgr.h"
|
|
|
|
HWND ghWnd = 0;
|
|
|
|
// BT412: losing the console mid-mission ends it (lobby-member / marshaled
|
|
// races -- the in-process console owns the clock, so a dropped console
|
|
// would otherwise count up forever). Arcade -net pods leave it False and
|
|
// re-listen for their console to return, exactly as always. Set by the
|
|
// front end / lobby member path (Phase 5/6).
|
|
Logical gConsoleLossEndsMission = False;
|
|
|
|
// BT412: a per-frame observer called each frame in RunMissions while an
|
|
// application is live (the in-process LocalConsole marshal hangs off this to
|
|
// own the mission clock). NULL when unregistered.
|
|
void (*gPerFrameHook)() = NULL;
|
|
|
|
// BT412: the in-process console owns the launch of a hosted network mission --
|
|
// when True, a staged pod stays at WaitingForLaunch instead of self-launching,
|
|
// so the console can launch the whole mesh at once (APP.cpp). Default False.
|
|
Logical gConsoleMarshalsLaunch = False;
|
|
|
|
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++;
|
|
|
|
//------------------------------------------------------------------
|
|
// BT412: give the per-frame observer a slice while 'application' is
|
|
// live (the loop condition NULLs the global on exit). The
|
|
// single-player LocalConsole marshal hangs off this; NULL otherwise.
|
|
//------------------------------------------------------------------
|
|
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();
|
|
// BT perf probe (env BT_PERF): 1-Hz frame breakdown.
|
|
{
|
|
static int s_perf = -1;
|
|
if (s_perf < 0) { const char *e = getenv("BT_PERF"); s_perf = (e && *e != '0') ? 1 : 0; }
|
|
if (s_perf)
|
|
{
|
|
static Time s_lastP = Now();
|
|
if (Now() - s_lastP >= 1.0f)
|
|
{
|
|
s_lastP = Now();
|
|
DEBUG_STREAM << "[perf] frame=" << (float)(Now() - beginFrameTimestamp)
|
|
<< " fg=" << (float)(startBackground - beginFrameTimestamp)
|
|
<< " bg=" << (float)(endBackground - startBackground)
|
|
<< " bgTasks=" << backgroundTasksRun << "\n" << std::flush;
|
|
}
|
|
}
|
|
}
|
|
|
|
//char str[256];
|
|
//Scalar lastFrameLength = Now() - beginFrameTimestamp;
|
|
//sprintf(str, "RPL4 - %.2f FPS", 1.0f / lastFrameLength);
|
|
//SetWindowTextA(ghWnd, str);
|
|
|
|
goto Start_Of_Frame;
|
|
}
|