Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -5,18 +5,18 @@
|
||||
#include "Bullet3Common/b3CommandLineArgs.h"
|
||||
|
||||
#ifdef NO_SHARED_MEMORY
|
||||
#include "PhysicsServerCommandProcessor.h"
|
||||
typedef PhysicsServerCommandProcessor MyCommandProcessor;
|
||||
#include "PhysicsServerCommandProcessor.h"
|
||||
typedef PhysicsServerCommandProcessor MyCommandProcessor;
|
||||
#else
|
||||
#include "SharedMemoryCommandProcessor.h"
|
||||
typedef SharedMemoryCommandProcessor MyCommandProcessor;
|
||||
#endif //NO_SHARED_MEMORY
|
||||
#include "SharedMemoryCommandProcessor.h"
|
||||
typedef SharedMemoryCommandProcessor MyCommandProcessor;
|
||||
#endif //NO_SHARED_MEMORY
|
||||
|
||||
#include "SharedMemoryCommands.h"
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "PhysicsServerCommandProcessor.h"
|
||||
#include "../Utils/b3Clock.h"
|
||||
|
||||
|
||||
bool gVerboseNetworkMessagesServer = false;
|
||||
|
||||
void MySerializeInt(unsigned int sz, unsigned char* output)
|
||||
@@ -31,11 +31,9 @@ void MySerializeInt(unsigned int sz, unsigned char* output)
|
||||
output[3] = tmp & 255;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
b3CommandLineArgs parseArgs(argc,argv);
|
||||
b3CommandLineArgs parseArgs(argc, argv);
|
||||
b3Clock clock;
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
@@ -44,7 +42,7 @@ int main(int argc, char *argv[])
|
||||
sm->setGuiHelper(&guiHelper);
|
||||
|
||||
int port = 1234;
|
||||
if (parseArgs.GetCmdLineArgument("port",port))
|
||||
if (parseArgs.GetCmdLineArgument("port", port))
|
||||
{
|
||||
printf("Using UDP port %d\n", port);
|
||||
}
|
||||
@@ -53,13 +51,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
#ifndef NO_SHARED_MEMORY
|
||||
int key = 0;
|
||||
if (parseArgs.GetCmdLineArgument("sharedMemoryKey",key))
|
||||
if (parseArgs.GetCmdLineArgument("sharedMemoryKey", key))
|
||||
{
|
||||
sm->setSharedMemoryKey(key);
|
||||
}
|
||||
#endif//NO_SHARED_MEMORY
|
||||
#endif //NO_SHARED_MEMORY
|
||||
|
||||
// PhysicsDirect* sm = new PhysicsDirect(sdk);
|
||||
// PhysicsDirect* sm = new PhysicsDirect(sdk);
|
||||
|
||||
//PhysicsClientSharedMemory* sm = new PhysicsClientSharedMemory();
|
||||
|
||||
@@ -67,9 +65,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (isPhysicsClientConnected)
|
||||
{
|
||||
|
||||
ENetAddress address;
|
||||
ENetHost *server;
|
||||
ENetHost* server;
|
||||
ENetEvent event;
|
||||
int serviceResult;
|
||||
|
||||
@@ -81,7 +78,6 @@ int main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
/* Bind the server to the default localhost. */
|
||||
/* A specific host address can be specified by */
|
||||
/* enet_address_set_host (& address, "x.x.x.x"); */
|
||||
@@ -90,10 +86,10 @@ int main(int argc, char *argv[])
|
||||
address.port = port;
|
||||
|
||||
server = enet_host_create(&address,
|
||||
32, /* number of clients */
|
||||
2, /* number of channels */
|
||||
0, /* Any incoming bandwith */
|
||||
0); /* Any outgoing bandwith */
|
||||
32, /* number of clients */
|
||||
2, /* number of channels */
|
||||
0, /* Any incoming bandwith */
|
||||
0); /* Any outgoing bandwith */
|
||||
|
||||
if (server == NULL)
|
||||
{
|
||||
@@ -101,7 +97,6 @@ int main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
while (true)
|
||||
{
|
||||
b3Clock::usleep(0);
|
||||
@@ -115,141 +110,139 @@ int main(int argc, char *argv[])
|
||||
serviceResult = enet_host_service(server, &event, 0);
|
||||
if (serviceResult > 0)
|
||||
{
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case ENET_EVENT_TYPE_CONNECT:
|
||||
{
|
||||
printf("A new client connected from %x:%u.\n",
|
||||
event.peer->address.host,
|
||||
event.peer->address.port);
|
||||
|
||||
/* Store any relevant client information here. */
|
||||
event.peer->data = (void*)"Client information";
|
||||
|
||||
break;
|
||||
}
|
||||
case ENET_EVENT_TYPE_RECEIVE:
|
||||
{
|
||||
if (gVerboseNetworkMessagesServer)
|
||||
case ENET_EVENT_TYPE_CONNECT:
|
||||
{
|
||||
int dataLen = (int)event.packet->dataLength;
|
||||
printf("A new client connected from %x:%u.\n",
|
||||
event.peer->address.host,
|
||||
event.peer->address.port);
|
||||
|
||||
printf("A packet of length %u containing '%s' was "
|
||||
"received from %s on channel %u.\n",
|
||||
dataLen,
|
||||
event.packet->data,
|
||||
event.peer->data,
|
||||
event.channelID);
|
||||
/* Store any relevant client information here. */
|
||||
event.peer->data = (void*)"Client information";
|
||||
|
||||
break;
|
||||
}
|
||||
SharedMemoryCommand cmd;
|
||||
|
||||
SharedMemoryCommand* cmdPtr = 0;
|
||||
|
||||
//performance test
|
||||
if (event.packet->dataLength == sizeof(int))
|
||||
case ENET_EVENT_TYPE_RECEIVE:
|
||||
{
|
||||
cmdPtr = &cmd;
|
||||
cmd.m_type = *(int*)event.packet->data;
|
||||
}
|
||||
|
||||
if (event.packet->dataLength == sizeof(SharedMemoryCommand))
|
||||
{
|
||||
cmdPtr = (SharedMemoryCommand*)event.packet->data;
|
||||
}
|
||||
if (cmdPtr)
|
||||
{
|
||||
SharedMemoryStatus serverStatus;
|
||||
b3AlignedObjectArray<char> buffer;
|
||||
buffer.resize(SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
|
||||
bool hasStatus = sm->processCommand(*cmdPtr,serverStatus, &buffer[0], buffer.size());
|
||||
|
||||
double startTimeSeconds = clock.getTimeInSeconds();
|
||||
double curTimeSeconds = clock.getTimeInSeconds();
|
||||
|
||||
while ((!hasStatus) && ((curTimeSeconds - startTimeSeconds) <timeOutInSeconds))
|
||||
{
|
||||
hasStatus = sm->receiveStatus(serverStatus, &buffer[0], buffer.size());
|
||||
curTimeSeconds = clock.getTimeInSeconds();
|
||||
}
|
||||
if (gVerboseNetworkMessagesServer)
|
||||
{
|
||||
printf("buffer.size = %d\n", buffer.size());
|
||||
printf("serverStatus.m_numDataStreamBytes = %d\n", serverStatus.m_numDataStreamBytes);
|
||||
int dataLen = (int)event.packet->dataLength;
|
||||
|
||||
printf(
|
||||
"A packet of length %u containing '%s' was "
|
||||
"received from %s on channel %u.\n",
|
||||
dataLen,
|
||||
event.packet->data,
|
||||
event.peer->data,
|
||||
event.channelID);
|
||||
}
|
||||
if (hasStatus)
|
||||
SharedMemoryCommand cmd;
|
||||
|
||||
SharedMemoryCommand* cmdPtr = 0;
|
||||
|
||||
//performance test
|
||||
if (event.packet->dataLength == sizeof(int))
|
||||
{
|
||||
b3AlignedObjectArray<unsigned char> packetData;
|
||||
unsigned char* statBytes = (unsigned char*)&serverStatus;
|
||||
cmdPtr = &cmd;
|
||||
cmd.m_type = *(int*)event.packet->data;
|
||||
}
|
||||
|
||||
if (cmdPtr->m_type == CMD_STEP_FORWARD_SIMULATION)
|
||||
if (event.packet->dataLength == sizeof(SharedMemoryCommand))
|
||||
{
|
||||
cmdPtr = (SharedMemoryCommand*)event.packet->data;
|
||||
}
|
||||
if (cmdPtr)
|
||||
{
|
||||
SharedMemoryStatus serverStatus;
|
||||
b3AlignedObjectArray<char> buffer;
|
||||
buffer.resize(SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
|
||||
bool hasStatus = sm->processCommand(*cmdPtr, serverStatus, &buffer[0], buffer.size());
|
||||
|
||||
double startTimeSeconds = clock.getTimeInSeconds();
|
||||
double curTimeSeconds = clock.getTimeInSeconds();
|
||||
|
||||
while ((!hasStatus) && ((curTimeSeconds - startTimeSeconds) < timeOutInSeconds))
|
||||
{
|
||||
packetData.resize(4 + sizeof(int));
|
||||
int sz = packetData.size();
|
||||
int curPos = 0;
|
||||
|
||||
MySerializeInt(sz, &packetData[curPos]);
|
||||
curPos += 4;
|
||||
for (int i = 0; i < sizeof(int); i++)
|
||||
{
|
||||
packetData[i + curPos] = statBytes[i];
|
||||
}
|
||||
curPos += sizeof(int);
|
||||
ENetPacket *packet = enet_packet_create(&packetData[0], packetData.size(), ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(event.peer, 0, packet);
|
||||
hasStatus = sm->receiveStatus(serverStatus, &buffer[0], buffer.size());
|
||||
curTimeSeconds = clock.getTimeInSeconds();
|
||||
}
|
||||
else
|
||||
if (gVerboseNetworkMessagesServer)
|
||||
{
|
||||
//create packetData with [int packetSizeInBytes, status, streamBytes)
|
||||
packetData.resize(4 + sizeof(SharedMemoryStatus) + serverStatus.m_numDataStreamBytes);
|
||||
int sz = packetData.size();
|
||||
int curPos = 0;
|
||||
printf("buffer.size = %d\n", buffer.size());
|
||||
printf("serverStatus.m_numDataStreamBytes = %d\n", serverStatus.m_numDataStreamBytes);
|
||||
}
|
||||
if (hasStatus)
|
||||
{
|
||||
b3AlignedObjectArray<unsigned char> packetData;
|
||||
unsigned char* statBytes = (unsigned char*)&serverStatus;
|
||||
|
||||
MySerializeInt(sz, &packetData[curPos]);
|
||||
curPos += 4;
|
||||
for (int i = 0; i < sizeof(SharedMemoryStatus); i++)
|
||||
if (cmdPtr->m_type == CMD_STEP_FORWARD_SIMULATION)
|
||||
{
|
||||
packetData[i + curPos] = statBytes[i];
|
||||
}
|
||||
curPos += sizeof(SharedMemoryStatus);
|
||||
packetData.resize(4 + sizeof(int));
|
||||
int sz = packetData.size();
|
||||
int curPos = 0;
|
||||
|
||||
for (int i = 0; i < serverStatus.m_numDataStreamBytes; i++)
|
||||
MySerializeInt(sz, &packetData[curPos]);
|
||||
curPos += 4;
|
||||
for (int i = 0; i < sizeof(int); i++)
|
||||
{
|
||||
packetData[i + curPos] = statBytes[i];
|
||||
}
|
||||
curPos += sizeof(int);
|
||||
ENetPacket* packet = enet_packet_create(&packetData[0], packetData.size(), ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(event.peer, 0, packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
packetData[i + curPos] = buffer[i];
|
||||
}
|
||||
//create packetData with [int packetSizeInBytes, status, streamBytes)
|
||||
packetData.resize(4 + sizeof(SharedMemoryStatus) + serverStatus.m_numDataStreamBytes);
|
||||
int sz = packetData.size();
|
||||
int curPos = 0;
|
||||
|
||||
ENetPacket *packet = enet_packet_create(&packetData[0], packetData.size(), ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(event.peer, 0, packet);
|
||||
//enet_host_broadcast(server, 0, packet);
|
||||
MySerializeInt(sz, &packetData[curPos]);
|
||||
curPos += 4;
|
||||
for (int i = 0; i < sizeof(SharedMemoryStatus); i++)
|
||||
{
|
||||
packetData[i + curPos] = statBytes[i];
|
||||
}
|
||||
curPos += sizeof(SharedMemoryStatus);
|
||||
|
||||
for (int i = 0; i < serverStatus.m_numDataStreamBytes; i++)
|
||||
{
|
||||
packetData[i + curPos] = buffer[i];
|
||||
}
|
||||
|
||||
ENetPacket* packet = enet_packet_create(&packetData[0], packetData.size(), ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(event.peer, 0, packet);
|
||||
//enet_host_broadcast(server, 0, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("received packet with unknown contents\n");
|
||||
}
|
||||
|
||||
/* Tell all clients about this message */
|
||||
//enet_host_broadcast(server, 0, event.packet);
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
case ENET_EVENT_TYPE_DISCONNECT:
|
||||
{
|
||||
printf("%s disconnected.\n", event.peer->data);
|
||||
|
||||
/* Reset the peer's client information. */
|
||||
|
||||
event.peer->data = NULL;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf("received packet with unknown contents\n");
|
||||
}
|
||||
|
||||
|
||||
/* Tell all clients about this message */
|
||||
//enet_host_broadcast(server, 0, event.packet);
|
||||
|
||||
break;
|
||||
}
|
||||
case ENET_EVENT_TYPE_DISCONNECT:
|
||||
{
|
||||
printf("%s disconnected.\n", event.peer->data);
|
||||
|
||||
/* Reset the peer's client information. */
|
||||
|
||||
event.peer->data = NULL;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (serviceResult > 0)
|
||||
@@ -258,7 +251,6 @@ int main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enet_host_destroy(server);
|
||||
@@ -267,5 +259,4 @@ int main(int argc, char *argv[])
|
||||
delete sm;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user