2015-05-28 23:05:24 +00:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2015 Google Inc. http://bulletphysics.org
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
#include "PhysicsServerExample.h"
|
2016-10-20 21:08:55 +00:00
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
#include "Bullet3Common/b3CommandLineArgs.h"
|
|
|
|
|
|
|
|
#include "../CommonInterfaces/CommonExampleInterface.h"
|
|
|
|
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
2015-05-29 22:04:05 +00:00
|
|
|
#include "SharedMemoryCommon.h"
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-08-06 19:07:08 +00:00
|
|
|
|
2015-08-06 18:59:31 +00:00
|
|
|
#include <stdlib.h>
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
int gSharedMemoryKey = -1;
|
2015-08-06 18:59:31 +00:00
|
|
|
|
|
|
|
static SharedMemoryCommon* example = NULL;
|
|
|
|
static bool interrupted = false;
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2015-08-06 19:07:08 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <err.h>
|
2015-08-06 18:59:31 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
static void cleanup(int signo)
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-08-06 18:59:31 +00:00
|
|
|
if (interrupted) { // this is the second time, we're hanging somewhere
|
|
|
|
// if (example) {
|
|
|
|
// example->abort();
|
|
|
|
// }
|
|
|
|
b3Printf("Aborting and deleting SharedMemoryCommon object");
|
|
|
|
sleep(1);
|
|
|
|
delete example;
|
|
|
|
errx(EXIT_FAILURE, "aborted example on signal %d", signo);
|
|
|
|
}
|
|
|
|
interrupted = true;
|
|
|
|
warnx("caught signal %d", signo);
|
|
|
|
}
|
|
|
|
#endif//_WIN32
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-08-06 18:59:31 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
|
|
|
struct sigaction action;
|
|
|
|
memset(&action, 0x0, sizeof(action));
|
|
|
|
action.sa_handler = cleanup;
|
|
|
|
static const int signos[] = { SIGHUP, SIGINT, SIGQUIT, SIGABRT, SIGSEGV, SIGPIPE, SIGTERM };
|
|
|
|
for (int ii(0); ii < sizeof(signos) / sizeof(*signos); ++ii) {
|
|
|
|
if (0 != sigaction(signos[ii], &action, NULL)) {
|
|
|
|
err(EXIT_FAILURE, "signal %d", signos[ii]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
b3CommandLineArgs args(argc, argv);
|
|
|
|
|
|
|
|
DummyGUIHelper noGfx;
|
|
|
|
|
|
|
|
CommonExampleOptions options(&noGfx);
|
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
args.GetCmdLineArgument("shared_memory_key", gSharedMemoryKey);
|
2016-12-29 05:51:54 +00:00
|
|
|
args.GetCmdLineArgument("sharedMemoryKey", gSharedMemoryKey);
|
2015-08-07 07:13:26 +00:00
|
|
|
|
2016-10-20 21:08:55 +00:00
|
|
|
// options.m_option |= PHYSICS_SERVER_ENABLE_COMMAND_LOGGING;
|
|
|
|
// options.m_option |= PHYSICS_SERVER_REPLAY_FROM_COMMAND_LOG;
|
2016-04-09 01:17:17 +00:00
|
|
|
|
2016-10-20 21:08:55 +00:00
|
|
|
example = (SharedMemoryCommon*)PhysicsServerCreateFunc(options);
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
example->initPhysics();
|
2017-01-16 19:17:32 +00:00
|
|
|
|
|
|
|
|
2015-08-06 18:59:31 +00:00
|
|
|
while (example->isConnected() && !(example->wantsTermination() || interrupted))
|
2015-05-29 22:04:05 +00:00
|
|
|
{
|
|
|
|
example->stepSimulation(1.f/60.f);
|
|
|
|
}
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
example->exitPhysics();
|
|
|
|
|
|
|
|
delete example;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|