Offloading the entire VD pipeline to a seperate thread.

This commit is contained in:
jaynus 2015-05-10 11:00:31 -07:00
parent cc36f3dbb9
commit b1d509236e
12 changed files with 83 additions and 33 deletions

BIN
ace_dynload.dll Normal file

Binary file not shown.

BIN
ace_vd.dll Normal file

Binary file not shown.

View File

@ -2,11 +2,17 @@
ADDON = false;
// Core engine functions
// Extension engine functions
PREP(initializeExtension);
PREP(monitorResultsPFH);
PREP(parseResult);
PREP(callExtension);
GVAR(extensionLibrary) = "z\ace\ace_vd.dll";
GVAR(async) = true;
GVAR(ready) = false;
// Core functionality
PREP(registerVehicleDamageHandler);
PREP(registerVehicleWithExtension);
PREP(unregisterWithExtension);
@ -15,8 +21,6 @@ PREP(dispatchHitPart);
PREP(dispatchDamage);
PREP(doHit);
// Unique local vehicle ID
GVAR(extensionLibrary) = "z\ace\ace_vd.dll";
GVAR(vehicle_id) = 0;
FUNC(_textVector) = {

View File

@ -8,6 +8,11 @@ GVAR(ready) = false;
"ace_dynload" callExtension format["load:%1", GVAR(extensionLibrary)];
#endif
if(GVAR(async)) then {
"async:" call FUNC(callExtension);
};
diag_log text format["[ACE] - Vehicle damage extension caching..."];
"init:" call FUNC(callExtension);
#ifdef ACE_VEHICLEDAMAGE_RENDER_DEBUG
@ -18,8 +23,10 @@ GVAR(ready) = false;
private["_result"];
// Wait until the extension is ready
_result = "ready" call FUNC(callExtension);
if(_result == "0") then {
if(!isNil "_result" && {_result == "0" } ) then {
[(_this select 1)] call CBA_fnc_removePerFrameHandler;
diag_log text format["[ACE] - Vehicle damage extension initialized"];
GVAR(ready) = true;
};
}, 0, [] ] CBA_fnc_addPerFrameHandler;
}, 0, [] ] call CBA_fnc_addPerFrameHandler;

View File

@ -3,17 +3,19 @@
PARAMS_2(_args,_handle);
private["_result"];
_result = "fetch_result:1" call FUNC(callExtension);;
while { _result != "" && {_result != "-1"} } do {
TRACE_1("", _result);
if(GVAR(ready)) then {
_result = "fetch_result:1" call FUNC(callExtension);;
_resultArgs = [_result] call FUNC(parseResult);
if(!isNil "_resultArgs") then {
if((_resultArgs select 0) == "exec") then {
[] call (_resultArgs select 1);
} else {
[format["ace_vehicledamage_%1", (_result select 0)], (_result select 1)] call EFUNC(common,localEvent);
while { _result != "" && {_result != "-1"} } do {
TRACE_1("", _result);
_result = "fetch_result:1" call FUNC(callExtension);;
_resultArgs = [_result] call FUNC(parseResult);
if(!isNil "_resultArgs") then {
if((_resultArgs select 0) == "exec") then {
[] call (_resultArgs select 1);
} else {
[format["ace_vehicledamage_%1", (_result select 0)], (_result select 1)] call EFUNC(common,localEvent);
};
};
};
};

View File

@ -5,7 +5,7 @@ PARAMS_1(_resultString);
private["_values", "_result", "_strings", "_command", "_arguments"];
TRACE_1("", _resultString);
if(!(_resultString find ":") ) exitWith { nil };
if( (_resultString find ":") < 0 ) exitWith { nil };
_strings = [_resultString, ":"] call CBA_fnc_split;
TRACE_1("", _strings);

View File

@ -32,8 +32,8 @@ if(USE_BULLET)
add_definitions(-DUSE_BULLET)
include_directories(BEFORE "lib/bullet3/src")
link_directories("lib/bullet3/lib")
set(BULLET_LIBS_DEBUG "BulletCollision_vs2010_debug.lib;LinearMath_vs2010_debug.lib;BulletDynamics_vs2010_debug.lib")
set(BULLET_LIBS "BulletCollision_vs2010.lib;LinearMath_vs2010.lib;BulletDynamics_vs2010.lib")
set(BULLET_LIBS_DEBUG "BulletCollision_debug.lib;LinearMath_debug.lib;BulletDynamics_debug.lib")
set(BULLET_LIBS "BulletCollision.lib;LinearMath.lib;BulletDynamics.lib")
else()
set(BULLET_LIBS_DEBUG "")
set(BULLET_LIBS "")

View File

@ -61,6 +61,25 @@ namespace ace {
return _original;
}
std::string create(const std::string & command) const {
std::stringstream ss;
ss << command << ":";
for (auto & v : _args) {
ss << v << ",";
}
// Remove the trailing ,
std::string result = ss.str();
result.erase(result.length());
return result;
}
static std::string create(const std::string & command, const arguments & args) {
return args.create(command);
}
protected:
std::vector<std::string> _args;
const std::string &_original;

View File

@ -108,7 +108,14 @@ namespace ace {
result.id = _messages.front().id;
result.message.resize(4096);
LOG(TRACE) << "dispatch[threaded]:\t[" << _messages.front().command << "] { " << _messages.front().args.get() << " }";
#ifdef _DEBUG
if (_messages.front().command != "fetch_result") {
LOG(TRACE) << "dispatch[threaded]:\t[" << _messages.front().command << "]";
if (_messages.front().args.size() > 0) {
// LOG(TRACE) << "\t{ " << _messages.front().args.get() << " }";
}
}
#endif
dispatcher::call(_messages.front().command, _messages.front().args, result.message);
{
std::lock_guard<std::mutex> lock(_results_lock);
@ -119,6 +126,7 @@ namespace ace {
}
}
}
sleep(5);
}
}
std::queue<dispatch_result> _results;

View File

@ -23,6 +23,10 @@
#define EXTENSION_RETURN() return;
#endif
#ifdef _WINDOWS
#define sleep(x) Sleep(x)
#endif
namespace ace {
template< typename T >
struct array_deleter

View File

@ -9,6 +9,7 @@
#include "controller.hpp"
#include "arguments.hpp"
#include "ace_vd.hpp"
#include <atomic>
static char version[] = "1.0";
@ -24,6 +25,7 @@ std::string get_command(const std::string & input) {
return input.substr(0, cmd_end);
}
std::atomic_bool _threaded = false;
void __stdcall RVExtension(char *output, int outputSize, const char *function) {
ZERO_OUTPUT();
@ -46,31 +48,31 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) {
}
if (command == "version") {
result = version;
}
if (command == "echo") {
} else if (command == "echo") {
result = function;
}
if (command == "ready") {
} else if (command == "async") {
_threaded = true;
result = "0";
} else if (command == "ready") {
if (ace::model_collection::get().ready() && ace::model_collection::get().ready()) {
result = "0";
} else {
result = "-1";
}
}
/*************************/
// Real functionality goes here
if (command == "init") { // init:
if (!ace::model_collection::get().ready()) {
ace::model_collection::get().init();
}
} else if (command == "init") { // init:
ace::vehicledamage::controller::get();
ace::vehicledamage::controller::get().call("reset", _args, result, _threaded);
result = "0";
EXTENSION_RETURN();
} else {
ace::vehicledamage::controller::get().call(command, _args, result);
if (command == "fetch_result") {
ace::vehicledamage::controller::get().call(command, _args, result, false);
}
else {
ace::vehicledamage::controller::get().call(command, _args, result, _threaded);
}
}
if (result.length() > 0) {
sprintf_s(output, outputSize, "%s", result.c_str());
}

View File

@ -73,6 +73,10 @@ namespace ace {
bool controller::reset(const arguments &_args, std::string & result) {
vehicles.clear();
if (!ace::model_collection::get().ready()) {
ace::model_collection::get().init();
}
return true;
}