Archival snapshot of the Virtual World Entertainment Tesla cockpit software, 1994-1996: MUNGA engine and L4 pod layer source (Borland C++ 5.0), BT/RP game code, and game content (models, audio, maps, gauges, Division renderer data). Includes third-party libraries: Division dVS/DPL graphics, HMI SOS audio, WATTCP networking. Files are preserved byte-for-byte (.gitattributes disables all line-ending conversion). README.md documents the layout, target hardware, and toolchain. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
419 lines
9.1 KiB
Plaintext
419 lines
9.1 KiB
Plaintext
|
|
#include "receiver.hpp"
|
|
#include "network.hpp"
|
|
#include "l4net.hpp"
|
|
#include "time.hpp"
|
|
#include "l4net.hpp"
|
|
extern "C"
|
|
{
|
|
getch();
|
|
}
|
|
//
|
|
//##############################################################################
|
|
//################# L4NetworkManager #######################
|
|
//##############################################################################
|
|
|
|
Logical
|
|
L4NetworkManager::TestClass()
|
|
{
|
|
#if 0
|
|
|
|
|
|
|
|
|
|
struct Track
|
|
{
|
|
long
|
|
departureTics;
|
|
HostID
|
|
sentBy;
|
|
long
|
|
serialNo;
|
|
char
|
|
name[120];
|
|
}test_mess;
|
|
|
|
|
|
struct Traffic
|
|
{
|
|
//HostID
|
|
// echoedBy;
|
|
long
|
|
//currSerialNo,
|
|
//currArrivalTicks,
|
|
prevSerialNo,
|
|
prevArrivalTicks,
|
|
travelTimeTicksMax,
|
|
travelTimeTicksMin;
|
|
short
|
|
maxBunchSize,
|
|
bunchAmount;
|
|
long
|
|
//packets_sent,
|
|
packets_received;
|
|
|
|
long
|
|
sequenceErrors;
|
|
};
|
|
|
|
Traffic traffic[10];//application->GetNetworkManager()->netPlayerCount];
|
|
// ???
|
|
|
|
HostManager::RemoteHostIterator
|
|
remote_hosts(application->GetHostManager());
|
|
Host
|
|
*this_host;
|
|
while ((this_host = remote_hosts.ReadAndNext()) != NULL)
|
|
{
|
|
Check(this_host);
|
|
HostID
|
|
this_hostID = this_host->GetHostID();
|
|
traffic[this_hostID].prevSerialNo = 0;
|
|
traffic[this_hostID].prevArrivalTicks = 0;
|
|
traffic[this_hostID].travelTimeTicksMax= -1;
|
|
traffic[this_hostID].travelTimeTicksMin= 0x0fffffff;
|
|
traffic[this_hostID].maxBunchSize = 0;
|
|
traffic[this_hostID].bunchAmount = 0;
|
|
traffic[this_hostID].packets_received = 0;
|
|
traffic[this_hostID].sequenceErrors = 0;
|
|
|
|
}
|
|
|
|
HostID
|
|
my_hostID = application->GetHostManager()->GetLocalHostID();
|
|
traffic[my_hostID].prevSerialNo = 0;
|
|
traffic[my_hostID].prevArrivalTicks = 0;
|
|
traffic[my_hostID].travelTimeTicksMax= -1;
|
|
traffic[my_hostID].travelTimeTicksMin= 0x0fffffff;
|
|
traffic[my_hostID].maxBunchSize = 0;
|
|
traffic[my_hostID].bunchAmount = 0;
|
|
traffic[my_hostID].packets_received = 0;
|
|
traffic[my_hostID].sequenceErrors = 0;
|
|
|
|
|
|
|
|
//
|
|
//-------------------------------------------
|
|
// Get environmental variables:
|
|
// packet_period, packets_amount, echo_packet, print_packet
|
|
//-------------------------------------------
|
|
//
|
|
Scalar
|
|
packet_period, //sent
|
|
receive_period; //receive
|
|
long
|
|
packets_amount;
|
|
Logical
|
|
echo_packet, //=True,
|
|
print_packet; //=False;
|
|
int
|
|
broadcast_packet; //1
|
|
char
|
|
*pp = getenv("PERIOD");
|
|
if (pp != NULL)
|
|
{
|
|
packet_period = atof(pp);
|
|
}
|
|
else
|
|
{
|
|
packet_period = 1.0f;
|
|
}
|
|
cout<<"PERIOD = "<<packet_period<<endl;
|
|
|
|
pp = getenv("RECEIVE");
|
|
if (pp != NULL)
|
|
{
|
|
receive_period = atof(pp);
|
|
}
|
|
else
|
|
{
|
|
receive_period = 1.0f;
|
|
}
|
|
cout<<"RECEIVE period = "<<receive_period<<endl;
|
|
|
|
|
|
|
|
pp = getenv("AMOUNT");
|
|
if (pp != NULL)
|
|
{
|
|
packets_amount = atol(pp);
|
|
}
|
|
else
|
|
{
|
|
packets_amount = 10;
|
|
}
|
|
cout<<"AMOUNT = "<<packets_amount<<endl;
|
|
|
|
pp = getenv("ECHO");
|
|
if (pp != NULL)
|
|
{
|
|
echo_packet = atoi(pp);
|
|
}
|
|
else
|
|
{
|
|
echo_packet = True;
|
|
}
|
|
cout<<"ECHO= "<<echo_packet<<endl;
|
|
|
|
pp = getenv("PRINT");
|
|
if (pp != NULL)
|
|
{
|
|
print_packet = atoi(pp);
|
|
}
|
|
else
|
|
{
|
|
print_packet = False;
|
|
}
|
|
cout<<"PRINT= "<<print_packet<<endl;
|
|
|
|
|
|
pp = getenv("BROADCAST");
|
|
if (pp != NULL)
|
|
{
|
|
broadcast_packet = atoi(pp);
|
|
}
|
|
else
|
|
{
|
|
broadcast_packet = 1;
|
|
}
|
|
cout<<"BROADCAST= "<<broadcast_packet<<endl;
|
|
|
|
|
|
//
|
|
//-------------------------------------------
|
|
// Start testing
|
|
//-------------------------------------------
|
|
//
|
|
short
|
|
packets=0;
|
|
Check(application);
|
|
Check(application->GetHostManager());
|
|
|
|
test_mess.serialNo = 0;
|
|
test_mess.sentBy = my_hostID;//application->GetHostManager()->GetLocalHostID();
|
|
|
|
memset(test_mess.name,'p',sizeof(test_mess.name));
|
|
// Str_Copy(test_mess.name,"sent packet",sizeof("sent packet"));
|
|
|
|
|
|
ReceiverDataMessageOf<Track>
|
|
what(Receiver::AnyMessageID,
|
|
sizeof(ReceiverDataMessageOf<Track>),
|
|
test_mess
|
|
);
|
|
|
|
Byte
|
|
message_buffer[NETWORKMANAGER_BUFFER_SIZE]; //512
|
|
#if sizeof(NetworkPacketHeader) + sizeof(ReceiverDataMessageOf<Track>) >= \
|
|
NETWORKMANAGER_BUFFER_SIZE
|
|
#error NETWORKMANAGER_BUFFER_SIZE too small!
|
|
#endif
|
|
|
|
|
|
NetworkPacket
|
|
*p = (NetworkPacket*)message_buffer;
|
|
|
|
cout << "Packet size = " <<
|
|
" sizeof(NetworkPacketHeader) + sizeof(ReceiverDataMessageOf<Track>) = " <<
|
|
(sizeof(NetworkPacketHeader) + sizeof(ReceiverDataMessageOf<Track>)) <<
|
|
endl;
|
|
|
|
|
|
Time
|
|
timer = Now();
|
|
timer += 2.0f;//packet_period; //at the beginning it listens for 2 secs
|
|
|
|
Time
|
|
receive_timer = Now();
|
|
while(1)
|
|
{
|
|
|
|
|
|
//-------------------------------------------------------------
|
|
// Send
|
|
//-------------------------------------------------------------
|
|
if (packets < packets_amount)
|
|
{
|
|
if (timer < Now())
|
|
{
|
|
packets++;
|
|
what.dataContents.serialNo++;
|
|
|
|
//--------------------------
|
|
//test testing sequence error
|
|
//--------------------------
|
|
//if (what.dataContents.serialNo==5)
|
|
//{
|
|
// what.dataContents.serialNo=6;
|
|
//}
|
|
|
|
Time
|
|
departureTime = Now();
|
|
what.dataContents.departureTics = departureTime.ticks;
|
|
|
|
Check(application);
|
|
Check(application->GetNetworkManager());
|
|
|
|
for (int b=0; b<broadcast_packet; b++)
|
|
{
|
|
application->
|
|
GetNetworkManager()->
|
|
ExclusiveBroadcast(
|
|
&what,
|
|
NetworkManagerClientID
|
|
);
|
|
}
|
|
|
|
timer = Now();
|
|
timer += packet_period;
|
|
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (packets == packets_amount)
|
|
{
|
|
packets++;
|
|
//-----------------
|
|
// set time to catch up left packets
|
|
//-----------------
|
|
timer = Now();
|
|
timer += 2.0f;
|
|
}
|
|
else
|
|
{
|
|
if (timer < Now())
|
|
{
|
|
//--------
|
|
// exit
|
|
//--------
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------
|
|
// Receive
|
|
//-------------------------------------------------------------
|
|
if (receive_timer < Now())
|
|
{
|
|
|
|
if (application->GetNetworkManager()->CheckBuffers(p))
|
|
{
|
|
if (p->clientID != NetworkManagerClientID)
|
|
{
|
|
cout<<"p->messageData.messageID= "<<p->messageData.messageID<<endl;
|
|
cout<<"p->messageData.messageLength= "<<p->messageData.messageLength<<endl;
|
|
|
|
}
|
|
|
|
if ( (p->clientID == NetworkManagerClientID)
|
|
//&& (p->messageData.messageID == Receiver::AnyMessageID)
|
|
//&& (p->messageData.messageLength == sizeof(ReceiverDataMessageOf<Track>))
|
|
)
|
|
{
|
|
Verify(p->messageData.messageID == Receiver::AnyMessageID);
|
|
Verify(p->messageData.messageLength == sizeof(ReceiverDataMessageOf<Track>));
|
|
ReceiverDataMessageOf<Track>*
|
|
what_ptr = (ReceiverDataMessageOf<Track>*)(&p->messageData);
|
|
if (print_packet)
|
|
{
|
|
cout<<what_ptr->dataContents.name<<endl;
|
|
}
|
|
|
|
|
|
if (echo_packet && (what_ptr->dataContents.sentBy != my_hostID))
|
|
{
|
|
//-----------------------------------------------------
|
|
// Got their packet - Send back
|
|
//-----------------------------------------------------
|
|
Str_Copy(what_ptr->dataContents.name,
|
|
"RETURNED PACKET",
|
|
sizeof(what_ptr->dataContents.name)
|
|
);
|
|
Check(application);
|
|
Check(application->GetNetworkManager());
|
|
application->
|
|
GetNetworkManager()->
|
|
Send(what_ptr,
|
|
NetworkManagerClientID,
|
|
p->fromHost
|
|
);
|
|
}
|
|
|
|
|
|
if (what_ptr->dataContents.sentBy == my_hostID)
|
|
{
|
|
//-----------------------------------------------------
|
|
// Got our own returned packet
|
|
//
|
|
// - Check serialNo; Get travel time; ...
|
|
//-----------------------------------------------------
|
|
traffic[p->fromHost].packets_received++;
|
|
//----------------
|
|
// Get travel time
|
|
//----------------
|
|
Time
|
|
travelTime = Now();
|
|
travelTime.ticks -= what_ptr->dataContents.departureTics;
|
|
traffic[p->fromHost].travelTimeTicksMax =
|
|
Max(travelTime.ticks, traffic[p->fromHost].travelTimeTicksMax);
|
|
traffic[p->fromHost].travelTimeTicksMin =
|
|
Min(travelTime.ticks, traffic[p->fromHost].travelTimeTicksMin);
|
|
|
|
//----------------
|
|
// Check serialNo
|
|
//----------------
|
|
if (what_ptr->dataContents.serialNo !=
|
|
traffic[p->fromHost].prevSerialNo + 1)
|
|
{
|
|
traffic[p->fromHost].sequenceErrors++;
|
|
}
|
|
traffic[p->fromHost].prevSerialNo = what_ptr->dataContents.serialNo;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
receive_timer = Now();
|
|
receive_timer += receive_period;
|
|
}
|
|
}//while
|
|
|
|
|
|
if (broadcast_packet)
|
|
{
|
|
remote_hosts.First();
|
|
while ((this_host = remote_hosts.ReadAndNext()) != NULL)
|
|
{
|
|
Check(this_host);
|
|
HostID
|
|
this_hostID = this_host->GetHostID();
|
|
cout
|
|
<<"From "
|
|
<<this_hostID
|
|
|
|
<<" received = "
|
|
<<traffic[this_hostID].packets_received
|
|
|
|
<<" seqErrors = "
|
|
<<traffic[this_hostID].sequenceErrors
|
|
|
|
<<" travelTimeMax = "
|
|
<<traffic[this_hostID].travelTimeTicksMax
|
|
|
|
<<" travelTimeMin = "
|
|
<<traffic[this_hostID].travelTimeTicksMin
|
|
|
|
<<endl;
|
|
}
|
|
}
|
|
cout<<"\nHit button\n";
|
|
getch();
|
|
#endif
|
|
return True;
|
|
}
|
|
|
|
|