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

View File

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

View File

@ -3,17 +3,19 @@
PARAMS_2(_args,_handle); PARAMS_2(_args,_handle);
private["_result"]; private["_result"];
_result = "fetch_result:1" call FUNC(callExtension);; if(GVAR(ready)) then {
while { _result != "" && {_result != "-1"} } do {
TRACE_1("", _result);
_result = "fetch_result:1" call FUNC(callExtension);; _result = "fetch_result:1" call FUNC(callExtension);;
while { _result != "" && {_result != "-1"} } do {
_resultArgs = [_result] call FUNC(parseResult); TRACE_1("", _result);
if(!isNil "_resultArgs") then { _result = "fetch_result:1" call FUNC(callExtension);;
if((_resultArgs select 0) == "exec") then {
[] call (_resultArgs select 1); _resultArgs = [_result] call FUNC(parseResult);
} else { if(!isNil "_resultArgs") then {
[format["ace_vehicledamage_%1", (_result select 0)], (_result select 1)] call EFUNC(common,localEvent); 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"]; private["_values", "_result", "_strings", "_command", "_arguments"];
TRACE_1("", _resultString); TRACE_1("", _resultString);
if(!(_resultString find ":") ) exitWith { nil }; if( (_resultString find ":") < 0 ) exitWith { nil };
_strings = [_resultString, ":"] call CBA_fnc_split; _strings = [_resultString, ":"] call CBA_fnc_split;
TRACE_1("", _strings); TRACE_1("", _strings);

View File

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

View File

@ -61,6 +61,25 @@ namespace ace {
return _original; 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: protected:
std::vector<std::string> _args; std::vector<std::string> _args;
const std::string &_original; const std::string &_original;

View File

@ -108,7 +108,14 @@ namespace ace {
result.id = _messages.front().id; result.id = _messages.front().id;
result.message.resize(4096); 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); dispatcher::call(_messages.front().command, _messages.front().args, result.message);
{ {
std::lock_guard<std::mutex> lock(_results_lock); std::lock_guard<std::mutex> lock(_results_lock);
@ -119,6 +126,7 @@ namespace ace {
} }
} }
} }
sleep(5);
} }
} }
std::queue<dispatch_result> _results; std::queue<dispatch_result> _results;

View File

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

View File

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