Maj terminée. Pour consulter la release notes associée voici le lien :

Commit e0014e95 authored by VAN TOLL Wouter's avatar VAN TOLL Wouter
Browse files

- Split the original project into "Engine" and "OCSR_ConsoleApplication".

- Added "OCSR_Library" which compiles to a DLL with a couple of API functions. This library can be used in Unity, for example.
parent d7bcbbbf
#define DLL_EXPORT
#include "APIFunctions.h"
#include <core/crowdSimulator.h>
#include <algorithm>
extern "C" {
CrowdSimulator* cs;
AgentData* agentData;
size_t agentDataSize;
API_FUNCTION void StartSimulation(const char* configFileName)
// initialize a new crowd simulation with the given config file
cs = new CrowdSimulator();
// prepare the agentData array
agentDataSize = std::max((size_t)4, cs->getWorld()->getAgents().size() * 2);
agentData = new AgentData[agentDataSize];
API_FUNCTION void DoSimulationSteps(int nrSteps)
if (cs != nullptr)
API_FUNCTION void GetAgentPositions(AgentData*& result_agentData, int& result_nrAgents)
if (cs == nullptr)
const auto& agents = cs->getWorld()->getAgents();
// check if the AgentData array is large enough; resize it if necessary
if (agents.size() > agentDataSize)
delete[] agentData;
agentDataSize *= 2;
agentData = new AgentData[agentDataSize];
else if (agents.size() * 4 < agentDataSize)
delete[] agentData;
agentDataSize /= 4;
agentData = new AgentData[agentDataSize];
// fill the AgentData array with the current agent data
int i = 0;
for (const auto& agent : agents)
agentData[i].id = agent->getID();
agentData[i].x = agent->getPosition().x();
agentData[i].y = agent->getPosition().y();
// store references to these results, for the client program to use
result_agentData = agentData;
result_nrAgents = (int)agents.size();
API_FUNCTION void CleanUp()
if (cs != nullptr)
delete cs;
delete[] agentData;
\ No newline at end of file
#define API_FUNCTION __declspec(dllexport)
#define API_FUNCTION __declspec(dllimport)
extern "C" {
struct AgentData
int id;
float x;
float y;
API_FUNCTION void StartSimulation(const char* configFileName);
API_FUNCTION void DoSimulationSteps(int nrSteps);
API_FUNCTION void GetAgentPositions(AgentData*& result_agentData, int& result_nrAgents);
API_FUNCTION void CleanUp();
\ No newline at end of file
......@@ -41,12 +41,18 @@ link_directories( ./lib/${CMAKE_BUILD_TYPE} )
file( GLOB_RECURSE source_files src/* include/*)
file( GLOB_RECURSE tinyxml_src 3rd-party/tinyxml/*)
add_executable(my_app main.cpp ${source_files} ${tinyxml_src})
add_library(Engine STATIC ${source_files} ${tinyxml_src})
add_executable(OCSR_ConsoleApplication main.cpp)
target_link_libraries(OCSR_ConsoleApplication Engine)
#add_executable(test_xmlparser ./test/test_xmlparser.cpp ${source_files} ${tinyxml_src})
#add_executable(test_socialforces ./test/SocialForcesExample.cpp ${source_files} ${tinyxml_src})
#add_executable(test_ttcaDca ./test/DcaTtcaExample.cpp ${source_files} ${tinyxml_src})
add_library(OCSR_Library SHARED "APIFunctions.h" "APIFunctions.cpp")
target_link_libraries(OCSR_Library Engine)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment