Merge pull request #855 from erwincoumans/master
add proper 'App_PhysicsServerUDP' without shared memory usage, and re…
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include "../MultiThreading/b3ThreadSupportInterface.h"
|
#include "../MultiThreading/b3ThreadSupportInterface.h"
|
||||||
void UDPThreadFunc(void* userPtr, void* lsMemory);
|
void UDPThreadFunc(void* userPtr, void* lsMemory);
|
||||||
void* UDPlsMemoryFunc();
|
void* UDPlsMemoryFunc();
|
||||||
|
bool gVerboseNetworkMessagesClient = false;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include "../MultiThreading/b3PosixThreadSupport.h"
|
#include "../MultiThreading/b3PosixThreadSupport.h"
|
||||||
@@ -101,6 +102,7 @@ struct UdpNetworkedInternalData
|
|||||||
if (enet_initialize() != 0)
|
if (enet_initialize() != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error initialising enet");
|
fprintf(stderr, "Error initialising enet");
|
||||||
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -165,13 +167,16 @@ struct UdpNetworkedInternalData
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ENET_EVENT_TYPE_RECEIVE:
|
case ENET_EVENT_TYPE_RECEIVE:
|
||||||
printf("A packet of length %u containing '%s' was "
|
|
||||||
"received from %s on channel %u.\n",
|
if (gVerboseNetworkMessagesClient)
|
||||||
m_event.packet->dataLength,
|
{
|
||||||
m_event.packet->data,
|
printf("A packet of length %u containing '%s' was "
|
||||||
m_event.peer->data,
|
"received from %s on channel %u.\n",
|
||||||
m_event.channelID);
|
m_event.packet->dataLength,
|
||||||
|
m_event.packet->data,
|
||||||
|
m_event.peer->data,
|
||||||
|
m_event.channelID);
|
||||||
|
}
|
||||||
/* Clean up the packet now that we're done using it.
|
/* Clean up the packet now that we're done using it.
|
||||||
> */
|
> */
|
||||||
enet_packet_destroy(m_event.packet);
|
enet_packet_destroy(m_event.packet);
|
||||||
@@ -198,7 +203,7 @@ struct UdpNetworkedInternalData
|
|||||||
{
|
{
|
||||||
bool hasStatus = false;
|
bool hasStatus = false;
|
||||||
|
|
||||||
int serviceResult = enet_host_service(m_client, &m_event, 100);
|
int serviceResult = enet_host_service(m_client, &m_event, 0);
|
||||||
|
|
||||||
if (serviceResult > 0)
|
if (serviceResult > 0)
|
||||||
{
|
{
|
||||||
@@ -214,13 +219,15 @@ struct UdpNetworkedInternalData
|
|||||||
|
|
||||||
case ENET_EVENT_TYPE_RECEIVE:
|
case ENET_EVENT_TYPE_RECEIVE:
|
||||||
{
|
{
|
||||||
printf("A packet of length %u containing '%s' was "
|
if (gVerboseNetworkMessagesClient)
|
||||||
"received from %s on channel %u.\n",
|
{
|
||||||
m_event.packet->dataLength,
|
printf("A packet of length %u containing '%s' was "
|
||||||
m_event.packet->data,
|
"received from %s on channel %u.\n",
|
||||||
m_event.peer->data,
|
m_event.packet->dataLength,
|
||||||
m_event.channelID);
|
m_event.packet->data,
|
||||||
|
m_event.peer->data,
|
||||||
|
m_event.channelID);
|
||||||
|
}
|
||||||
|
|
||||||
int packetSizeInBytes = b3DeserializeInt(m_event.packet->data);
|
int packetSizeInBytes = b3DeserializeInt(m_event.packet->data);
|
||||||
|
|
||||||
|
|||||||
@@ -2313,6 +2313,18 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
|||||||
dofIndex += mb->getLink(i).m_dofCount;
|
dofIndex += mb->getLink(i).m_dofCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btAlignedObjectArray<btQuaternion> scratch_q;
|
||||||
|
btAlignedObjectArray<btVector3> scratch_m;
|
||||||
|
|
||||||
|
mb->forwardKinematics(scratch_q,scratch_m);
|
||||||
|
int nLinks = mb->getNumLinks();
|
||||||
|
scratch_q.resize(nLinks+1);
|
||||||
|
scratch_m.resize(nLinks+1);
|
||||||
|
|
||||||
|
mb->updateCollisionObjectWorldTransforms(scratch_q,scratch_m);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedMemoryStatus& serverCmd =serverStatusOut;
|
SharedMemoryStatus& serverCmd =serverStatusOut;
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
/* server.cpp */
|
/* server.cpp */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <enet/enet.h>
|
#include <enet/enet.h>
|
||||||
#include "SharedMemoryCommandProcessor.h"
|
#include "../../CommonInterfaces/CommonGUIHelperInterface.h"
|
||||||
|
#ifdef NO_SHARED_MEMORY
|
||||||
|
#include "PhysicsServerCommandProcessor.h"
|
||||||
|
typedef PhysicsServerCommandProcessor MyCommandProcessor;
|
||||||
|
#else
|
||||||
|
#include "SharedMemoryCommandProcessor.h"
|
||||||
|
typedef SharedMemoryCommandProcessor MyCommandProcessor ;
|
||||||
|
#endif //NO_SHARED_MEMORY
|
||||||
#include "SharedMemoryCommands.h"
|
#include "SharedMemoryCommands.h"
|
||||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||||
#include "PhysicsServerCommandProcessor.h"
|
#include "PhysicsServerCommandProcessor.h"
|
||||||
|
|
||||||
|
|
||||||
|
bool gVerboseNetworkMessagesServer = false;
|
||||||
|
|
||||||
void MySerializeInt(unsigned int sz, unsigned char* output)
|
void MySerializeInt(unsigned int sz, unsigned char* output)
|
||||||
{
|
{
|
||||||
@@ -22,10 +32,10 @@ void MySerializeInt(unsigned int sz, unsigned char* output)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned char buf[4];
|
|
||||||
|
|
||||||
|
DummyGUIHelper guiHelper;
|
||||||
SharedMemoryCommandProcessor* sm = new SharedMemoryCommandProcessor;
|
PhysicsCommandProcessorInterface* sm = new MyCommandProcessor;
|
||||||
|
sm->setGuiHelper(&guiHelper);
|
||||||
|
|
||||||
// PhysicsDirect* sm = new PhysicsDirect(sdk);
|
// PhysicsDirect* sm = new PhysicsDirect(sdk);
|
||||||
|
|
||||||
@@ -95,13 +105,15 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ENET_EVENT_TYPE_RECEIVE:
|
case ENET_EVENT_TYPE_RECEIVE:
|
||||||
printf("A packet of length %u containing '%s' was "
|
if (gVerboseNetworkMessagesServer)
|
||||||
"received from %s on channel %u.\n",
|
{
|
||||||
event.packet->dataLength,
|
printf("A packet of length %u containing '%s' was "
|
||||||
event.packet->data,
|
"received from %s on channel %u.\n",
|
||||||
event.peer->data,
|
event.packet->dataLength,
|
||||||
event.channelID);
|
event.packet->data,
|
||||||
|
event.peer->data,
|
||||||
|
event.channelID);
|
||||||
|
}
|
||||||
if (event.packet->dataLength == sizeof(SharedMemoryCommand))
|
if (event.packet->dataLength == sizeof(SharedMemoryCommand))
|
||||||
{
|
{
|
||||||
SharedMemoryCommand* cmdPtr = (SharedMemoryCommand*)event.packet->data;
|
SharedMemoryCommand* cmdPtr = (SharedMemoryCommand*)event.packet->data;
|
||||||
@@ -117,8 +129,11 @@ int main(int argc, char *argv[])
|
|||||||
hasStatus = sm->receiveStatus(serverStatus, &buffer[0], buffer.size());
|
hasStatus = sm->receiveStatus(serverStatus, &buffer[0], buffer.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
printf("buffer.size = %d\n", buffer.size());
|
if (gVerboseNetworkMessagesServer)
|
||||||
printf("serverStatus.m_numDataStreamBytes = %d\n", serverStatus.m_numDataStreamBytes);
|
{
|
||||||
|
printf("buffer.size = %d\n", buffer.size());
|
||||||
|
printf("serverStatus.m_numDataStreamBytes = %d\n", serverStatus.m_numDataStreamBytes);
|
||||||
|
}
|
||||||
if (hasStatus)
|
if (hasStatus)
|
||||||
{
|
{
|
||||||
//create packetData with [int packetSizeInBytes, status, streamBytes)
|
//create packetData with [int packetSizeInBytes, status, streamBytes)
|
||||||
@@ -138,13 +153,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
for (int i = 0; i < serverStatus.m_numDataStreamBytes; i++)
|
for (int i = 0; i < serverStatus.m_numDataStreamBytes; i++)
|
||||||
{
|
{
|
||||||
packetData[i + curPos] = serverStatus.m_dataStream[i];
|
packetData[i + curPos] = buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetPacket *packet = enet_packet_create(&packetData[0], packetData.size() , ENET_PACKET_FLAG_RELIABLE);
|
ENetPacket *packet = enet_packet_create(&packetData[0], packetData.size() , ENET_PACKET_FLAG_RELIABLE);
|
||||||
//enet_peer_send(peer, 0, packet);
|
enet_peer_send(event.peer, 0, packet);
|
||||||
|
//enet_host_broadcast(server, 0, packet);
|
||||||
enet_host_broadcast(server, 0, packet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
project ("App_PhysicsServerUDP")
|
project ("App_PhysicsServerSharedMemoryBridgeUDP")
|
||||||
|
|
||||||
language "C++"
|
language "C++"
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ project ("App_PhysicsServerUDP")
|
|||||||
|
|
||||||
if os.is("Windows") then
|
if os.is("Windows") then
|
||||||
defines { "WIN32" }
|
defines { "WIN32" }
|
||||||
|
|
||||||
|
|
||||||
links {"Ws2_32","Winmm"}
|
links {"Ws2_32","Winmm"}
|
||||||
end
|
end
|
||||||
@@ -44,3 +45,82 @@ project ("App_PhysicsServerUDP")
|
|||||||
"../../Utils/b3ResourcePath.h",
|
"../../Utils/b3ResourcePath.h",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
project "App_PhysicsServerUDP"
|
||||||
|
|
||||||
|
if _OPTIONS["ios"] then
|
||||||
|
kind "WindowedApp"
|
||||||
|
else
|
||||||
|
kind "ConsoleApp"
|
||||||
|
end
|
||||||
|
|
||||||
|
defines { "NO_SHARED_MEMORY" }
|
||||||
|
|
||||||
|
includedirs {"..","../../../src", "../../ThirdPartyLibs","../../ThirdPartyLibs/enet/include"}
|
||||||
|
|
||||||
|
links {
|
||||||
|
"enet","Bullet3Common","BulletInverseDynamicsUtils", "BulletInverseDynamics", "BulletDynamics","BulletCollision", "LinearMath", "BussIK"
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.is("Windows") then
|
||||||
|
defines { "WIN32" }
|
||||||
|
links {"Ws2_32","Winmm"}
|
||||||
|
end
|
||||||
|
|
||||||
|
language "C++"
|
||||||
|
|
||||||
|
myfiles =
|
||||||
|
{
|
||||||
|
"../IKTrajectoryHelper.cpp",
|
||||||
|
"../IKTrajectoryHelper.h",
|
||||||
|
"../SharedMemoryCommands.h",
|
||||||
|
"../SharedMemoryPublic.h",
|
||||||
|
"../PhysicsServerCommandProcessor.cpp",
|
||||||
|
"../PhysicsServerCommandProcessor.h",
|
||||||
|
"../TinyRendererVisualShapeConverter.cpp",
|
||||||
|
"../TinyRendererVisualShapeConverter.h",
|
||||||
|
"../../TinyRenderer/geometry.cpp",
|
||||||
|
"../../TinyRenderer/model.cpp",
|
||||||
|
"../../TinyRenderer/tgaimage.cpp",
|
||||||
|
"../../TinyRenderer/our_gl.cpp",
|
||||||
|
"../../TinyRenderer/TinyRenderer.cpp",
|
||||||
|
"../../OpenGLWindow/SimpleCamera.cpp",
|
||||||
|
"../../OpenGLWindow/SimpleCamera.h",
|
||||||
|
"../../Importers/ImportURDFDemo/ConvertRigidBodies2MultiBody.h",
|
||||||
|
"../../Importers/ImportURDFDemo/MultiBodyCreationInterface.h",
|
||||||
|
"../../Importers/ImportURDFDemo/MyMultiBodyCreator.cpp",
|
||||||
|
"../../Importers/ImportURDFDemo/MyMultiBodyCreator.h",
|
||||||
|
"../../Importers/ImportURDFDemo/BulletUrdfImporter.cpp",
|
||||||
|
"../../Importers/ImportURDFDemo/BulletUrdfImporter.h",
|
||||||
|
"../../Importers/ImportURDFDemo/UrdfParser.cpp",
|
||||||
|
"../../Importers/ImportURDFDemo/urdfStringSplit.cpp",
|
||||||
|
"../../Importers/ImportURDFDemo/UrdfParser.cpp",
|
||||||
|
"../../Importers/ImportURDFDemo/UrdfParser.h",
|
||||||
|
"../../Importers/ImportURDFDemo/URDF2Bullet.cpp",
|
||||||
|
"../../Importers/ImportURDFDemo/URDF2Bullet.h",
|
||||||
|
"../../Utils/b3ResourcePath.cpp",
|
||||||
|
"../../Utils/b3Clock.cpp",
|
||||||
|
"../../../Extras/Serialize/BulletWorldImporter/*",
|
||||||
|
"../../../Extras/Serialize/BulletFileLoader/*",
|
||||||
|
"../../Importers/ImportURDFDemo/URDFImporterInterface.h",
|
||||||
|
"../../Importers/ImportURDFDemo/URDFJointTypes.h",
|
||||||
|
"../../Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp",
|
||||||
|
"../../Importers/ImportObjDemo/LoadMeshFromObj.cpp",
|
||||||
|
"../../Importers/ImportSTLDemo/ImportSTLSetup.h",
|
||||||
|
"../../Importers/ImportSTLDemo/LoadMeshFromSTL.h",
|
||||||
|
"../../Importers/ImportColladaDemo/LoadMeshFromCollada.cpp",
|
||||||
|
"../../Importers/ImportColladaDemo/ColladaGraphicsInstance.h",
|
||||||
|
"../../ThirdPartyLibs/Wavefront/tiny_obj_loader.cpp",
|
||||||
|
"../../ThirdPartyLibs/tinyxml/tinystr.cpp",
|
||||||
|
"../../ThirdPartyLibs/tinyxml/tinyxml.cpp",
|
||||||
|
"../../ThirdPartyLibs/tinyxml/tinyxmlerror.cpp",
|
||||||
|
"../../ThirdPartyLibs/tinyxml/tinyxmlparser.cpp",
|
||||||
|
"../../Importers/ImportMeshUtility/b3ImportMeshUtility.cpp",
|
||||||
|
"../../ThirdPartyLibs/stb_image/stb_image.cpp",
|
||||||
|
}
|
||||||
|
|
||||||
|
files {
|
||||||
|
myfiles,
|
||||||
|
"main.cpp",
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,8 +119,11 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
|
|
||||||
printf("Say> ");
|
printf("Say> ");
|
||||||
|
#ifdef _WIN32
|
||||||
gets_s(message, 1024);
|
gets_s(message, 1024);
|
||||||
|
#else
|
||||||
|
gets(message);
|
||||||
|
#endif
|
||||||
if (strcmp(message, "exit") == 0 ||
|
if (strcmp(message, "exit") == 0 ||
|
||||||
strcmp(message, "quit") == 0) {
|
strcmp(message, "quit") == 0) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user