diff --git a/ace_clipboard.dll b/ace_clipboard.dll index 4f77d63f1f..9431e30f54 100644 Binary files a/ace_clipboard.dll and b/ace_clipboard.dll differ diff --git a/ace_dynload.dll b/ace_dynload.dll index 77d7f0a035..35f42b39e4 100644 Binary files a/ace_dynload.dll and b/ace_dynload.dll differ diff --git a/ace_vd.dll b/ace_vd.dll deleted file mode 100644 index 8b64685b58..0000000000 Binary files a/ace_vd.dll and /dev/null differ diff --git a/addons/vehicledamage/XEH_postInit.sqf b/addons/vehicledamage/XEH_postInit.sqf index b51b76f82a..59fe7b5589 100644 --- a/addons/vehicledamage/XEH_postInit.sqf +++ b/addons/vehicledamage/XEH_postInit.sqf @@ -3,4 +3,8 @@ // Handle damage to local vehicles [QGVAR(hp), FUNC(dispatchHitPart)] call EFUNC(common,addEventHandler); -[FUNC(monitorResultsPFH), 0, []] call CBA_fnc_addPerFrameHandler; \ No newline at end of file +// Extension dispatch commands +[QGVAR(setAnimationNames), FUNC(setAnimationNames)] call EFUNC(common,addEventHandler); +// Trigger and start fetching results +[FUNC(monitorResultsPFH), 0, []] call CBA_fnc_addPerFrameHandler; + diff --git a/addons/vehicledamage/XEH_preInit.sqf b/addons/vehicledamage/XEH_preInit.sqf index 2cb81fcfc5..d89dd6ea46 100644 --- a/addons/vehicledamage/XEH_preInit.sqf +++ b/addons/vehicledamage/XEH_preInit.sqf @@ -8,11 +8,24 @@ PREP(monitorResultsPFH); PREP(parseResult); PREP(callExtension); -// This value is used for debug loading of the extension with dynload -GVAR(extensionLibrary) = "z\ace\extensions\build\vd\Debug\ace_vd.dll"; + GVAR(async) = true; GVAR(ready) = false; +#ifdef DEBUG_LOG_EXTENSION +GVAR(debug_log) = []; +#endif +#ifdef DEBUG_EXTENSION_DYNLOAD +// This value is used for debug loading of the extension with dynload +GVAR(extensionLibrary) = "z\ace\extensions\build\vd\Debug\ace_vd.dll"; +#endif + +// Extension dispatch events +PREP(setAnimationNames); + +// To extension send events +PREP(getAnimationStates); + // Core functionality PREP(registerVehicleDamageHandler); PREP(registerVehicleWithExtension); @@ -23,6 +36,7 @@ PREP(dispatchDamage); PREP(doHit); GVAR(vehicle_id) = 0; +GVAR(vehicles) = HASH_CREATE; FUNC(_textVector) = { private["_str"]; @@ -30,6 +44,37 @@ FUNC(_textVector) = { _str }; +#ifdef DEBUG_LOG_EXTENSION +FUNC(clipboardExport) = { + private["_chunks"]; + _chunks = []; + + _chunks = [_this select 0, ";"] call CBA_fnc_split; + + { + private["_chunk"]; + _chunk = _x + ";"; + "ace_clipboard" callExtension format["%1", _chunk]; + } forEach _chunks; + + "ace_clipboard" callExtension "--COMPLETE--"; +}; +FUNC(exportLog) = { + private["_chunks"]; + _chunks = [str(_this select 0), ","] call CBA_fnc_split; + + { + private["_chunk"]; + _chunk = _x + ";"; + "ace_clipboard" callExtension format["%1", _chunk]; + } forEach _chunks; + + "ace_clipboard" callExtension "--COMPLETE--"; +}; +#endif + + + [] call FUNC(initializeExtension); ADDON = true; diff --git a/addons/vehicledamage/functions/fnc_callExtension.sqf b/addons/vehicledamage/functions/fnc_callExtension.sqf index ce8adc6b33..97ddf31dc0 100644 --- a/addons/vehicledamage/functions/fnc_callExtension.sqf +++ b/addons/vehicledamage/functions/fnc_callExtension.sqf @@ -1,7 +1,20 @@ #include "script_component.hpp" +private["_extResult"]; #ifdef DEBUG_EXTENSION_DYNLOAD - "ace_dynload" callExtension format["call:%1,%2", GVAR(extensionLibrary), _this]; + _extResult = "ace_dynload" callExtension format["call:%1,%2", GVAR(extensionLibrary), _this]; #else - "ace_vd" callExtension _this; -#endif \ No newline at end of file + _extResult = "ace_vd" callExtension _this; +#endif + +#ifdef DEBUG_LOG_EXTENSION +if((_this find "fetch_result") < 0) then { + GVAR(debug_log) pushBack [_this, _extResult]; +}; +#endif + +if(!isNil "_extResult") then { + _extResult +} else { + nil +}; \ No newline at end of file diff --git a/addons/vehicledamage/functions/fnc_doHit.sqf b/addons/vehicledamage/functions/fnc_doHit.sqf index 49341ecc78..646f67394c 100644 --- a/addons/vehicledamage/functions/fnc_doHit.sqf +++ b/addons/vehicledamage/functions/fnc_doHit.sqf @@ -33,9 +33,10 @@ if(_projectileLength == 0) then { _vehicleId = _vehicle getVariable[QGVAR(id), -1]; -_command = format["hit:%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13,%14,%15,%16", +_command = format["hit:%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13,%14,%15,%16,%17,%18", _vehicleId, // vehicle id registered - _model, _selection, +// _model, _selection, + _model, "BALLS", VECTOR_TEXT(vectorDir _vehicle), VECTOR_TEXT(vectorUp _vehicle), _projectileType, //projectile type id diff --git a/addons/vehicledamage/functions/fnc_getAnimationStates.sqf b/addons/vehicledamage/functions/fnc_getAnimationStates.sqf new file mode 100644 index 0000000000..15f22510b1 --- /dev/null +++ b/addons/vehicledamage/functions/fnc_getAnimationStates.sqf @@ -0,0 +1,45 @@ +//#define DEBUG_MODE_FULL +#include "script_component.hpp" +private["_vehicleData", "_animationNames", "_animationResults", "_sendToExtension"]; +PARAMS_1(_vehicle); + +_sendToExtension = false; +if( (count _this) > 1) then { + _sendToExtension = true; +}; + +if((typeName _vehicle) != "OBJECT") then { + _vehicleData = HASH_GET(GVAR(vehicles),_vehicle); + TRACE_1("", _vehicleData); + if(isNil "_vehicleData") exitWith { nil }; + _vehicle = _vehicleData select 0; +}; + +if(isNull _vehicle) exitWith { + diag_log text format["[ACE] - ERROR! Vehicle was null!!!"]; +}; + +_animationNames = _vehicle getVariable[QGVAR(animationNames), nil]; +if(isNil "_animationNames") exitWith { + diag_log text format["[ACE] - ERROR: Animations not loaded for vehicle [%1]", _vehicle]; +}; + +_animationResults = []; +{ + _animationResults pushBack [_x, (_vehicle animationPhase _x) ]; +} forEach _animationNames; +TRACE_1("Returning", _animationResults); + +if(_sendToExtension) then { + private["_cmd"]; + + _cmd = format["set_animation_state:%1,", (_vehicle getVariable[QGVAR(id), -1])]; + { + _cmd = _cmd + format["%1,%2,", (_x select 0), ([(_x select 1)] call CBA_fnc_formatNumber)]; + } forEach _animationResults; + + _cmd call FUNC(callExtension); +}; + + +_animationResults \ No newline at end of file diff --git a/addons/vehicledamage/functions/fnc_initializeExtension.sqf b/addons/vehicledamage/functions/fnc_initializeExtension.sqf index a393f1db92..0cd4998b0f 100644 --- a/addons/vehicledamage/functions/fnc_initializeExtension.sqf +++ b/addons/vehicledamage/functions/fnc_initializeExtension.sqf @@ -6,7 +6,9 @@ GVAR(ready) = false; #ifdef DEBUG_EXTENSION_DYNLOAD +#ifdef DEBUG_EXTENSION_DYNLOAD_RELOAD "ace_dynload" callExtension format["unload:%1", GVAR(extensionLibrary)]; +#endif "ace_dynload" callExtension format["load:%1", GVAR(extensionLibrary)]; diag_log text format["[ACE] - DEBUG - Dynamic extension loaded for Vehicle Damage"]; #endif @@ -18,7 +20,7 @@ if(GVAR(async)) then { diag_log text format["[ACE] - Vehicle damage extension caching..."]; "init:" call FUNC(callExtension); -#ifdef ACE_VEHICLEDAMAGE_RENDER_DEBUG +#ifdef DEBUG_VEHICLEDAMAGE_RENDER "debug_render:" call FUNC(callExtension); diag_log text format["[ACE] - DEBUG - DirectX11 Debug Rendering initialized"]; #endif diff --git a/addons/vehicledamage/functions/fnc_monitorResultsPFH.sqf b/addons/vehicledamage/functions/fnc_monitorResultsPFH.sqf index 44af397d2b..486f071d6d 100644 --- a/addons/vehicledamage/functions/fnc_monitorResultsPFH.sqf +++ b/addons/vehicledamage/functions/fnc_monitorResultsPFH.sqf @@ -1,21 +1,27 @@ //#define DEBUG_MODE_FULL #include "script_component.hpp" -PARAMS_2(_args,_handle); +// params not used here to prevent debug spam +_args = _this select 0; +_handle = _this select 1; private["_result"]; if(GVAR(ready)) then { _result = "fetch_result:1" call FUNC(callExtension);; 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 { + TRACE_1("", "Dispatching exec"); [] call (_resultArgs select 1); } else { - [format["ace_vehicledamage_%1", (_result select 0)], (_result select 1)] call EFUNC(common,localEvent); + _event = format["ace_vehicledamage_%1", (_resultArgs select 0)]; + TRACE_3("Dispatch command", _event, (_resultArgs select 0), (_resultArgs select 1)); + [_event, (_resultArgs select 1)] call EFUNC(common,localEvent); }; }; + // Pull next result + _result = "fetch_result:1" call FUNC(callExtension); }; }; \ No newline at end of file diff --git a/addons/vehicledamage/functions/fnc_registerVehicleWithExtension.sqf b/addons/vehicledamage/functions/fnc_registerVehicleWithExtension.sqf index 3106f629e7..4749cd252b 100644 --- a/addons/vehicledamage/functions/fnc_registerVehicleWithExtension.sqf +++ b/addons/vehicledamage/functions/fnc_registerVehicleWithExtension.sqf @@ -2,7 +2,7 @@ #include "script_component.hpp" PARAMS_1(_vehicle); -private["_id", "_model"]; +private["_id", "_model","_vehicleData"]; if(GVAR(Enabled) < 1) exitWith {}; @@ -15,6 +15,8 @@ if(_model != "") then { TRACE_1("", _value); _result = _value call FUNC(callExtension); _vehicle setVariable[QGVAR(id), _id, false]; + _vehicleData = [_vehicle]; + HASH_SET(GVAR(vehicles),_id,_vehicleData); }; diag_log text format["[ACE] - Vehicle queued for extension loading %1 - %2=[%2]", _id, _vehicle, _model]; \ No newline at end of file diff --git a/addons/vehicledamage/functions/fnc_setAnimationNames.sqf b/addons/vehicledamage/functions/fnc_setAnimationNames.sqf new file mode 100644 index 0000000000..4bedc6e869 --- /dev/null +++ b/addons/vehicledamage/functions/fnc_setAnimationNames.sqf @@ -0,0 +1,16 @@ +#define DEBUG_MODE_FULL +#include "script_component.hpp" +private["_id", "_vehicle", "_vehicleData"]; +_id = parseNumber (_this select 0); + +// The rest of the arguments in the array are just a stream of animation names +// remove the id +_this deleteAt 0; + +_vehicleData = HASH_GET(GVAR(vehicles),_id); +TRACE_1("", _vehicleData); +if(!isNil "_vehicleData") then { + _vehicle = _vehicleData select 0; + + _vehicle setVariable[QGVAR(animationNames), _this, false]; +}; \ No newline at end of file diff --git a/addons/vehicledamage/script_component.hpp b/addons/vehicledamage/script_component.hpp index 93b1714dbb..1f81f8bd09 100644 --- a/addons/vehicledamage/script_component.hpp +++ b/addons/vehicledamage/script_component.hpp @@ -15,4 +15,7 @@ #define VECTOR_TEXT(x) ([(x)] call FUNC(_textVector)) #define RELATIVE_VECTOR_TEXT(o,x) ([(o worldToModelVisual ((x) call EFUNC(common,ASLToPosition)))] call FUNC(_textVector)) -#define DEBUG_EXTENSION_DYNLOAD \ No newline at end of file +#define DEBUG_EXTENSION_DYNLOAD +#define DEBUG_LOG_EXTENSION +//#define DEBUG_EXTENSION_DYNLOAD_RELOAD +//#define DEBUG_VEHICLEDAMAGE_RENDER \ No newline at end of file diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index 2575d79d4c..457cfe771d 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -3,6 +3,10 @@ project (ACE) set_property(GLOBAL PROPERTY USE_FOLDERS ON) +if(WIN32) +add_definitions(/DWINVER=0x0600 /D_WIN32_WINNT=0x0600) +endif() + if (NOT CMAKE_BUILD_TYPE AND CMAKE_COMPILER_IS_GNUCXX) message(STATUS "No build type selected, default to Debug") set(CMAKE_BUILD_TYPE "Debug") @@ -29,14 +33,44 @@ endif() include_directories("common") if(USE_BULLET) - add_definitions(-DUSE_BULLET) + # Dependencies + # + set(BACKUP_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) + set(BACKUP_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + set(BACKUP_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + + add_definitions(-DUSE_DIRECTX) + add_subdirectory(lib/bullet3) + + set_target_properties(App_BasicExample PROPERTIES FOLDER Bullet3) + set_target_properties(App_HelloWorld PROPERTIES FOLDER Bullet3) + set_target_properties(App_ExampleBrowser PROPERTIES FOLDER Bullet3) + set_target_properties(Bullet2FileLoader PROPERTIES FOLDER Bullet3) + set_target_properties(Bullet3Collision PROPERTIES FOLDER Bullet3) + set_target_properties(Bullet3Dynamics PROPERTIES FOLDER Bullet3) + set_target_properties(Bullet3Geometry PROPERTIES FOLDER Bullet3) + set_target_properties(Bullet3Common PROPERTIES FOLDER Bullet3) + set_target_properties(Bullet3OpenCL_clew PROPERTIES FOLDER Bullet3) + set_target_properties(BulletCollision PROPERTIES FOLDER Bullet3) + set_target_properties(BulletDynamics PROPERTIES FOLDER Bullet3) + set_target_properties(BulletFileLoader PROPERTIES FOLDER Bullet3) + set_target_properties(BulletSoftBody PROPERTIES FOLDER Bullet3) + + set_target_properties(BulletWorldImporter PROPERTIES FOLDER Bullet3) + set_target_properties(BulletXmlWorldImporter PROPERTIES FOLDER Bullet3) + set_target_properties(ConvexDecomposition PROPERTIES FOLDER Bullet3) + set_target_properties(GIMPACTUtils PROPERTIES FOLDER Bullet3) + set_target_properties(gtest PROPERTIES FOLDER Bullet3) + set_target_properties(gwen PROPERTIES FOLDER Bullet3) + set_target_properties(HACD PROPERTIES FOLDER Bullet3) + set_target_properties(OpenGLWindow PROPERTIES FOLDER Bullet3) + set_target_properties(LinearMath PROPERTIES FOLDER Bullet3) + + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BACKUP_ARCHIVE_OUTPUT_DIRECTORY}) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BACKUP_LIBRARY_OUTPUT_DIRECTORY}) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BACKUP_RUNTIME_OUTPUT_DIRECTORY}) + include_directories(BEFORE "lib/bullet3/src") - link_directories("lib/bullet3/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 "") endif() if(USE_DIRECTX) add_definitions(-DUSE_DIRECTX) @@ -78,6 +112,7 @@ endif() include_directories(${CMAKE_CURRENT_BINARY_DIR}/common) set(GLOBAL_SOURCES ${GLOBAL_RC}) + # Add extensions to build here add_subdirectory(common) diff --git a/extensions/common/arguments.hpp b/extensions/common/arguments.hpp index df51d6148c..70e942a241 100644 --- a/extensions/common/arguments.hpp +++ b/extensions/common/arguments.hpp @@ -40,6 +40,9 @@ namespace ace { public: arguments(const std::string & str) : _original(str) { _args = ace::split(str, ','); + for (int i = 0; i < _args.size(); i++) { + _args[i] = trim(_args[i]); + } } size_t size() const { return _args.size(); } @@ -82,6 +85,6 @@ namespace ace { protected: std::vector _args; - const std::string &_original; + const std::string _original; }; } \ No newline at end of file diff --git a/extensions/common/directx/d3d_display.cpp b/extensions/common/directx/d3d_display.cpp index ffb9d39877..bfc7a0e013 100644 --- a/extensions/common/directx/d3d_display.cpp +++ b/extensions/common/directx/d3d_display.cpp @@ -3,12 +3,36 @@ #include "shared.hpp" #include "d3d_display.hpp" +#include + #include using namespace DirectX; namespace ace { namespace debug { + + DWORD GetMainThreadId() { + const std::shared_ptr hThreadSnapshot( + CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0), CloseHandle); + if (hThreadSnapshot.get() == INVALID_HANDLE_VALUE) { + throw std::runtime_error("GetMainThreadId failed"); + } + THREADENTRY32 tEntry; + tEntry.dwSize = sizeof(THREADENTRY32); + DWORD result = 0; + DWORD currentPID = GetCurrentProcessId(); + for (BOOL success = Thread32First(hThreadSnapshot.get(), &tEntry); + !result && success && GetLastError() != ERROR_NO_MORE_FILES; + success = Thread32Next(hThreadSnapshot.get(), &tEntry)) + { + if (tEntry.th32OwnerProcessID == currentPID) { + result = tEntry.th32ThreadID; + } + } + return result; + } + d3d_display::d3d_display() : _fullscreen(false) {} d3d_display::~d3d_display() {} @@ -210,6 +234,9 @@ namespace ace { return false; } + // Attach our input to the master input + //AttachThreadInput(GetCurrentThreadId(), GetMainThraedId()); + SetWindowLongPtr(_hWnd, GWLP_USERDATA, (LONG)this); ShowWindow(_hWnd, 5); @@ -307,11 +334,13 @@ namespace ace { LRESULT CALLBACK d3d_display::_wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; - + switch (message) { case WM_INPUT: { UINT dwSize; - + if (GetActiveWindow() != _hWnd) { + return DefWindowProc(hWnd, message, wParam, lParam); + } GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)); LPBYTE lpb = new BYTE[dwSize]; diff --git a/extensions/common/dispatch.hpp b/extensions/common/dispatch.hpp index 76e8a5202e..0a37824b83 100644 --- a/extensions/common/dispatch.hpp +++ b/extensions/common/dispatch.hpp @@ -55,7 +55,7 @@ namespace ace { class threaded_dispatcher : public dispatcher { public: - threaded_dispatcher() : _worker(&ace::threaded_dispatcher::monitor, this) { + threaded_dispatcher() : _stop(false), _worker(&ace::threaded_dispatcher::monitor, this) { } ~threaded_dispatcher() {} @@ -99,11 +99,14 @@ namespace ace { void push_result(const std::string & result) { push_result(dispatch_result(result, -1)); } - + void stop() { + std::lock_guard lock(_messages_lock); + _stop = true; + } protected: void monitor() { _ready = false; - while (true) { + while (!_stop) { { std::lock_guard lock(_messages_lock); while (!_messages.empty()) { @@ -135,15 +138,16 @@ namespace ace { sleep(5); } } - std::queue _results; - std::mutex _results_lock; + std::atomic_bool _stop; + std::queue _results; + std::mutex _results_lock; - std::queue _messages; - std::mutex _messages_lock; + std::queue _messages; + std::mutex _messages_lock; - std::thread _worker; + std::thread _worker; - uint64_t _message_id; + uint64_t _message_id; }; class threaded_dispatch : public threaded_dispatcher, public singleton { }; }; \ No newline at end of file diff --git a/extensions/common/p3d/animation.cpp b/extensions/common/p3d/animation.cpp index 9d135053e1..1c97399a1e 100644 --- a/extensions/common/p3d/animation.cpp +++ b/extensions/common/p3d/animation.cpp @@ -20,17 +20,11 @@ namespace ace { stream_.read((char *)&min_phase, sizeof(float)); stream_.read((char *)&max_phase, sizeof(float)); - //stream_.read((char *)&junk, sizeof(uint32_t)); - //stream_.read((char *)&junk2, sizeof(uint32_t)); + stream_.read((char *)&junk, sizeof(uint32_t)); + stream_.read((char *)&junk2, sizeof(uint32_t)); stream_.read((char *)&source_address, sizeof(uint32_t)); - float buffer[4]; - stream_.read((char *)buffer, sizeof(float) * 4); - return; - - // THIS IS ALL WRONG - // ARMA3 HAS FIXED 4-FLOAT TRANSFORMS - + // This always adds up to 2*4 more bytes unless its direct apparently switch (type) { // rotations case 0: @@ -61,9 +55,11 @@ namespace ace { case 9: // fucking hides... stream_.read((char *)&hide_value, sizeof(float)); stream_.read((char *)&offset1, sizeof(float)); // this is junk throw it in offset1 for hides + break; default: stream_.read((char *)&offset0, sizeof(float)); stream_.read((char *)&offset1, sizeof(float)); + break; } diff --git a/extensions/common/p3d/lod_info.cpp b/extensions/common/p3d/lod_info.cpp index b7d3cfe094..4b95c853b4 100644 --- a/extensions/common/p3d/lod_info.cpp +++ b/extensions/common/p3d/lod_info.cpp @@ -43,7 +43,7 @@ namespace ace { stream_.read((char *)&u_float_1, sizeof(float)); // Derp, this was only TOH apparently!? - //point_flags = compressed(stream_, true, true); + //point_flags = compressed(stream_, true, true, version); stream_.read((char *)&u_float_2, sizeof(float)); stream_.read((char *)&u_float_3, sizeof(float)); @@ -70,8 +70,8 @@ namespace ace { materials.push_back(std::make_shared(stream_, version)); } - edges.mlod = compressed(stream_, true, false).data; - edges.vertex = compressed(stream_, true, false).data; + edges.mlod = compressed(stream_, true, false, version).data; + edges.vertex = compressed(stream_, true, false, version).data; // @TODO: THIS IS OFF WTF?! // The first face is coming up null, so we missed something @@ -128,14 +128,14 @@ namespace ace { uv::uv() {} uv::uv(std::istream &stream_, uint32_t version = 68) { stream_.read((char *)&uv_scale, sizeof(float) * 4); - data = compressed(stream_, true, true); + data = compressed(stream_, true, true, version); } c_vertex_table::c_vertex_table() {} c_vertex_table::c_vertex_table(std::istream &stream_, uint32_t size_, uint32_t version = 68) : size(size_) { uint32_t temp_count; - point_flags = compressed(stream_, true, true); + point_flags = compressed(stream_, true, true, version); uvsets.push_back(std::make_shared(stream_, version)); @@ -145,7 +145,7 @@ namespace ace { uvsets.push_back(std::make_shared(stream_, version)); } - points = compressed>(stream_, true, false, false); + points = compressed>(stream_, true, false, false, version); size = points.size; } @@ -157,15 +157,15 @@ namespace ace { READ_STRING(name); - faces = compressed(stream_, true, false); + faces = compressed(stream_, true, false, version); - //face_weights = compressed(stream_, true, false); // Face weights - face_weights = compressed(stream_, true, false); + //face_weights = compressed(stream_, true, false, version); // Face weights + face_weights = compressed(stream_, true, false, version); READ_BOOL(is_sectional); - sections = compressed(stream_, true, false); - vertex_table = compressed(stream_, true, false); - texture_weights = compressed(stream_, true, false); + sections = compressed(stream_, true, false, version); + vertex_table = compressed(stream_, true, false, version); + texture_weights = compressed(stream_, true, false, version); //stream_.read((char *)&junk, 4); } diff --git a/extensions/common/p3d/model_info.cpp b/extensions/common/p3d/model_info.cpp index 09b85f6e93..c373907a9a 100644 --- a/extensions/common/p3d/model_info.cpp +++ b/extensions/common/p3d/model_info.cpp @@ -8,7 +8,7 @@ namespace ace { raw_resolutions(nullptr), u_floats_1(nullptr), default_indicators(nullptr) { } - model_info::model_info(std::istream & stream_, const uint32_t lod_count) + model_info::model_info(std::istream & stream_, const uint32_t lod_count, uint32_t version) : raw_resolutions(nullptr), u_floats_1(nullptr), default_indicators(nullptr) { raw_resolutions = new float[lod_count]; @@ -57,7 +57,7 @@ namespace ace { stream_.read((char *)&u_byte_1, sizeof(uint8_t)); - compressed u_floats_1(stream_, true, false); + compressed u_floats_1(stream_, true, false, version); stream_.read((char *)&mass, sizeof(float)); stream_.read((char *)&mass_reciprocal, sizeof(float)); diff --git a/extensions/common/p3d/model_info.hpp b/extensions/common/p3d/model_info.hpp index e6baa9b240..195e925a5a 100644 --- a/extensions/common/p3d/model_info.hpp +++ b/extensions/common/p3d/model_info.hpp @@ -11,7 +11,7 @@ namespace ace { class model_info { public: model_info(); - model_info(std::istream &, const uint32_t lod_count); + model_info(std::istream &, const uint32_t lod_count, uint32_t version = 68); ~model_info(); diff --git a/extensions/common/pbo/search.cpp b/extensions/common/pbo/search.cpp index 019e9dc1f0..f383bf5dc5 100644 --- a/extensions/common/pbo/search.cpp +++ b/extensions/common/pbo/search.cpp @@ -135,6 +135,8 @@ namespace ace { pbo_stream.close(); } + LOG(INFO) << "PBO Index complete"; + return true; } @@ -266,6 +268,8 @@ namespace ace { /* Cast our buffer into an UNICODE_STRING. */ objectName = *(PUNICODE_STRING)objectNameInfo; + + /* Print the information! */ if (objectName.Length) @@ -276,20 +280,11 @@ namespace ace { std::string object_type(tmp_type.begin(), tmp_type.end()); std::string object_name(tmp_name.begin(), tmp_name.end()); if (object_type == "File" && object_name.find(".pbo") != object_name.npos) { - char volume_letter[MAX_PATH]; - BOOL res = GetVolumePathName(object_name.c_str(), volume_letter, sizeof(volume_letter)); - if (res) { - volume_letter[2] = 0x00; - std::vector tokens = ace::split(object_name, '\\'); + char buffer[MAX_PATH]; + GetFinalPathNameByHandle(dupHandle, buffer, sizeof(buffer), VOLUME_NAME_DOS); - std::stringstream s; - s << volume_letter; - for (int x = 3; x < tokens.size(); x++) { - s << "\\" << tokens[x]; - } - LOG(DEBUG) << "Pbo: " << s.str(); - _active_pbo_list.push_back(s.str()); - } + LOG(DEBUG) << "Pbo: " << buffer; + _active_pbo_list.push_back(std::string(buffer)); } } diff --git a/extensions/common/shared.cpp b/extensions/common/shared.cpp index bfbcfd2ae7..ca0c65f409 100644 --- a/extensions/common/shared.cpp +++ b/extensions/common/shared.cpp @@ -1,5 +1,10 @@ #include "shared.hpp" +#include +#include +#include +#include + int test(int var) { return var; } diff --git a/extensions/common/shared.hpp b/extensions/common/shared.hpp index 0c1b42d3cf..c84624132a 100644 --- a/extensions/common/shared.hpp +++ b/extensions/common/shared.hpp @@ -40,6 +40,23 @@ namespace ace { std::vector &split(const std::string &s, char delim, std::vector &elems); std::vector split(const std::string &s, char delim); + // trim from start + static inline std::string <rim(std::string &s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); + return s; + } + + // trim from end + static inline std::string &rtrim(std::string &s) { + s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); + return s; + } + + // trim from both ends + static inline std::string &trim(std::string &s) { + return ltrim(rtrim(s)); + } + inline void runtime_assert(bool result); struct exception { diff --git a/extensions/common/simulation/object.cpp b/extensions/common/simulation/object.cpp index bdb737c599..0831111711 100644 --- a/extensions/common/simulation/object.cpp +++ b/extensions/common/simulation/object.cpp @@ -6,8 +6,8 @@ ace::simulation::vertex::vertex(vertex_table & _table, ace::vector3 _vertex, uint32_t _id) : table(_table), vertex_id(_id) { - this->original_vertex = _vertex; - this->animated_vertex = _vertex; + this->original_vertex = _vertex; + this->animated_vertex = _vertex; } ace::simulation::vertex::~vertex() @@ -16,50 +16,50 @@ ace::simulation::vertex::~vertex() ace::simulation::face::face( - const ace::p3d::face_p p3d_face, - const ace::p3d::lod_p p3d_lod, - const ace::p3d::model_p p3d, - ace::simulation::lod *object_lod) + const ace::p3d::face_p p3d_face, + const ace::p3d::lod_p p3d_lod, + const ace::p3d::model_p p3d, + ace::simulation::lod *object_lod) { - this->type = p3d_face->type; - for (uint16_t vertex_id : p3d_face->vertex_table) { - this->vertices.push_back(object_lod->vertices[vertex_id]); - object_lod->vertices[vertex_id]->faces.push_back(this); - } + this->type = p3d_face->type; + for (uint16_t vertex_id : p3d_face->vertex_table) { + this->vertices.push_back(object_lod->vertices[vertex_id]); + object_lod->vertices[vertex_id]->faces.push_back(this); + } } ace::simulation::face::~face() { } -void ace::simulation::vertex::animate(const glm::mat4 &matrix, ace::vector3 rotation_offset, bool offset) +void ace::simulation::vertex::animate(const glm::mat4 &matrix, ace::vector3 rotation_offset, bool offset) { - ace::vector3 temp_vector = this->original_vertex; - if (offset) { - temp_vector = temp_vector - rotation_offset; - } - glm::vec4 temp_gl_vector = glm::vec4(temp_vector.x(), temp_vector.y(), temp_vector.z(), 1.0f); - temp_gl_vector = matrix*temp_gl_vector; - this->animated_vertex = ace::vector3(temp_gl_vector.x, temp_gl_vector.y, temp_gl_vector.z); - if (offset) { - this->animated_vertex = this->animated_vertex + rotation_offset; - } + ace::vector3 temp_vector = this->original_vertex; + if (offset) { + temp_vector = temp_vector - rotation_offset; + } + glm::vec4 temp_gl_vector = glm::vec4(temp_vector.x(), temp_vector.y(), temp_vector.z(), 1.0f); + temp_gl_vector = matrix*temp_gl_vector; + this->animated_vertex = ace::vector3(temp_gl_vector.x, temp_gl_vector.y, temp_gl_vector.z); + if (offset) { + // this->animated_vertex = this->animated_vertex + rotation_offset; + } } ace::simulation::named_selection::named_selection( - const ace::p3d::named_selection_p p3d_selection, - const ace::p3d::lod_p p3d_lod, - const ace::p3d::model_p p3d, - ace::simulation::lod *object_lod) + const ace::p3d::named_selection_p p3d_selection, + const ace::p3d::lod_p p3d_lod, + const ace::p3d::model_p p3d, + ace::simulation::lod *object_lod) { - this->name = p3d_selection->name; - for (uint16_t vertex_id : p3d_selection->vertex_table.data) { - this->vertices.push_back(object_lod->vertices[vertex_id]); - object_lod->vertices[vertex_id]->selections.push_back(this); - } - for (uint16_t face_id : p3d_selection->faces.data) { - this->faces.push_back(object_lod->faces[face_id]); - } + this->name = p3d_selection->name; + for (uint16_t vertex_id : p3d_selection->vertex_table.data) { + this->vertices.push_back(object_lod->vertices[vertex_id]); + object_lod->vertices[vertex_id]->selections.push_back(this); + } + for (uint16_t face_id : p3d_selection->faces.data) { + this->faces.push_back(object_lod->faces[face_id]); + } } ace::simulation::named_selection::~named_selection() @@ -68,10 +68,10 @@ ace::simulation::named_selection::~named_selection() void ace::simulation::named_selection::animate(const glm::mat4 &matrix, ace::vector3 rotation_offset) { - bool offset = rotation_offset.zero_distance(); - for (auto selection_vertex : this->vertices) { - selection_vertex->animate(matrix, rotation_offset, offset); - } + bool offset = !rotation_offset.zero_distance(); + for (auto selection_vertex : this->vertices) { + selection_vertex->animate(matrix, rotation_offset, offset); + } } @@ -79,21 +79,21 @@ void ace::simulation::named_selection::animate(const glm::mat4 &matrix, ace::vec ace::simulation::vertex_table::vertex_table(const ace::p3d::vertex_table_p p3d_vertex_table, const ace::p3d::lod_p p3d_lod, const ace::p3d::model_p p3d) : animated(false) { - this->vertices.resize(p3d_vertex_table->points.size); - for (uint32_t i = 0; i <= p3d_vertex_table->points.size - 1; ++i) { - if(p3d->info->autocenter) { - ace::vector3 new_vertex = ace::vector3( - p3d_vertex_table->points[i].x() + (p3d_lod->autocenter_pos.x()*-1), - p3d_vertex_table->points[i].y() + (p3d_lod->autocenter_pos.y()*-1), - p3d_vertex_table->points[i].z() + (p3d_lod->autocenter_pos.z()*-1) - ); - this->vertices[i] = std::make_shared(*this, new_vertex, i); - - } - else { - this->vertices[i] = std::make_shared(*this, p3d_vertex_table->points[i], i); - } - } + this->vertices.resize(p3d_vertex_table->points.size); + for (uint32_t i = 0; i <= p3d_vertex_table->points.size - 1; ++i) { + if (p3d->info->autocenter) { + ace::vector3 new_vertex = ace::vector3( + p3d_vertex_table->points[i].x() + (p3d_lod->autocenter_pos.x()*-1), + p3d_vertex_table->points[i].y() + (p3d_lod->autocenter_pos.y()*-1), + p3d_vertex_table->points[i].z() + (p3d_lod->autocenter_pos.z()*-1) + ); + this->vertices[i] = std::make_shared(*this, new_vertex, i); + + } + else { + this->vertices[i] = std::make_shared(*this, p3d_vertex_table->points[i], i); + } + } } ace::simulation::vertex_table::~vertex_table() @@ -102,17 +102,17 @@ ace::simulation::vertex_table::~vertex_table() ace::simulation::lod::lod(const ace::p3d::lod_p p3d_lod, const ace::p3d::model_p p3d) { - this->id = p3d_lod->id; - this->vertices = vertex_table(p3d_lod->vertices, p3d_lod, p3d); - this->autocenter_pos = p3d_lod->autocenter_pos; + this->id = p3d_lod->id; + this->vertices = vertex_table(p3d_lod->vertices, p3d_lod, p3d); + this->autocenter_pos = p3d_lod->autocenter_pos; - for (ace::p3d::face_p p3d_face : p3d_lod->faces) { - this->faces.push_back(std::make_shared(p3d_face, p3d_lod, p3d, this)); - } + for (ace::p3d::face_p p3d_face : p3d_lod->faces) { + this->faces.push_back(std::make_shared(p3d_face, p3d_lod, p3d, this)); + } - for (ace::p3d::named_selection_p p3d_selection : p3d_lod->selections) { - this->selections[p3d_selection->name] = std::make_shared(p3d_selection, p3d_lod, p3d, this); - } + for (ace::p3d::named_selection_p p3d_selection : p3d_lod->selections) { + this->selections[p3d_selection->name] = std::make_shared(p3d_selection, p3d_lod, p3d, this); + } } @@ -121,21 +121,21 @@ ace::simulation::lod::~lod() } ace::simulation::lod_animation_info::lod_animation_info( - animation *_animation, - lod_p _lod, - const ace::p3d::animate_bone_p p3d_animate_bone, - const ace::p3d::animation_p p3d_animation, - const ace::p3d::model_p p3d) : animation_definition(_animation), lod(_lod) + animation *_animation, + lod_p _lod, + const ace::p3d::animate_bone_p p3d_animate_bone, + const ace::p3d::animation_p p3d_animation, + const ace::p3d::model_p p3d) : animation_definition(_animation), lod(_lod) { - this->index = p3d_animate_bone->index; - if (p3d->info->autocenter) { - this->axis_position = p3d_animate_bone->axis_position + (lod->autocenter_pos*-1); - this->axis_direction = p3d_animate_bone->axis_direction.normalize(); - } - else { - this->axis_position = p3d_animate_bone->axis_position; - this->axis_direction = p3d_animate_bone->axis_direction.normalize(); - } + this->index = p3d_animate_bone->index; + if (p3d->info->autocenter) { + this->axis_position = p3d_animate_bone->axis_position + (lod->autocenter_pos*-1); + this->axis_direction = p3d_animate_bone->axis_direction.normalize(); + } + else { + this->axis_position = p3d_animate_bone->axis_position; + this->axis_direction = p3d_animate_bone->axis_direction.normalize(); + } } ace::simulation::lod_animation_info::~lod_animation_info() @@ -144,54 +144,54 @@ ace::simulation::lod_animation_info::~lod_animation_info() ace::simulation::animation::animation(object *parent_object, const ace::p3d::animation_p p3d_animation, const ace::p3d::model_p p3d) { - this->type = p3d_animation->type; - this->name = p3d_animation->name; - this->source = p3d_animation->source; + this->type = p3d_animation->type; + this->name = p3d_animation->name; + this->source = p3d_animation->source; - this->source_address = p3d_animation->source_address; + this->source_address = p3d_animation->source_address; - this->min_value = p3d_animation->min_value; - this->max_value = p3d_animation->max_value; + this->min_value = p3d_animation->min_value; + this->max_value = p3d_animation->max_value; - this->min_phase = p3d_animation->min_phase; - this->max_phase = p3d_animation->max_phase; + this->min_phase = p3d_animation->min_phase; + this->max_phase = p3d_animation->max_phase; - switch (type) { - // rotations - case 0: - case 1: - case 2: - case 3: - angle0 = p3d_animation->angle0; - angle1 = p3d_animation->angle1; - break; - // translations - case 4: - case 5: - case 6: - case 7: - offset0 = p3d_animation->offset0; - offset1 = p3d_animation->offset1; - break; - case 8: - direct_axis_pos = p3d_animation->direct_axis_pos; - direct_axis_dir = p3d_animation->direct_axis_dir; - direct_angle = p3d_animation->direct_angle; - direct_axis_offset = p3d_animation->direct_axis_offset; - break; - case 9: - hide_value = p3d_animation->hide_value; - default: - offset0 = 0.0f; - offset1 = 0.0f; - } + switch (type) { + // rotations + case 0: + case 1: + case 2: + case 3: + angle0 = p3d_animation->angle0; + angle1 = p3d_animation->angle1; + break; + // translations + case 4: + case 5: + case 6: + case 7: + offset0 = p3d_animation->offset0; + offset1 = p3d_animation->offset1; + break; + case 8: + direct_axis_pos = p3d_animation->direct_axis_pos; + direct_axis_dir = p3d_animation->direct_axis_dir; + direct_angle = p3d_animation->direct_angle; + direct_axis_offset = p3d_animation->direct_axis_offset; + break; + case 9: + hide_value = p3d_animation->hide_value; + default: + offset0 = 0.0f; + offset1 = 0.0f; + } - for (ace::p3d::animate_bone_p animation_bone : p3d_animation->bones) { - this->lod_info[animation_bone->lod] = std::make_shared(this, parent_object->lods[animation_bone->lod], animation_bone, p3d_animation, p3d); - } + for (ace::p3d::animate_bone_p animation_bone : p3d_animation->bones) { + this->lod_info[animation_bone->lod] = std::make_shared(this, parent_object->lods[animation_bone->lod], animation_bone, p3d_animation, p3d); + } } @@ -200,10 +200,10 @@ ace::simulation::animation::~animation() } typedef union { - float f; - struct { - uint32_t sh1 : 32; - } parts; + float f; + struct { + uint32_t sh1 : 32; + } parts; } double_cast; #define RAD2DEG(rad) (rad * 180.0f / 3.1415926f); @@ -211,171 +211,208 @@ typedef union { typedef std::map>> animation_transform; animation_transform ace::simulation::animation::animate(const float phase, const std::vector &lods, animation_transform base_transforms) { - animation_transform return_matrices; - for (auto lod_id : lods) { - glm::mat4 base_matrix = base_transforms[lod_id].first; - ace::vector3 base_rotation_offset = base_transforms[lod_id].second; - glm::mat4 animation_matrix; - ace::vector3 rotation_offset = ace::vector3(0, 0, 0); + animation_transform return_matrices; + for (auto lod_id : lods) { + glm::mat4 base_matrix = base_transforms[lod_id].first; + ace::vector3 base_rotation_offset = base_transforms[lod_id].second; + glm::mat4 animation_matrix, direction_matrix; + ace::vector3 rotation_offset = ace::vector3(0, 0, 0); - float scale = get_scale(phase); + float scale = get_scale(phase); - switch (this->type) { - //rotation - case 0: { - scale = (scale / (max_value - min_value)) * (angle1 - angle0); - glm::vec3 rotation_axis = glm::vec3(this->lod_info[lod_id]->axis_direction.x(), this->lod_info[lod_id]->axis_direction.y(), this->lod_info[lod_id]->axis_direction.z()); - animation_matrix = glm::rotate(animation_matrix, -scale, rotation_axis); - rotation_offset = this->lod_info[lod_id]->axis_position; - break; - } - //rotationX - case 1: { - scale = (scale / (max_value - min_value)) * (angle1 - angle0); - glm::vec3 rotation_axis = glm::vec3(1.0f, 0.0f, 0.0f); - animation_matrix = glm::rotate(animation_matrix, -scale, rotation_axis); - rotation_offset = this->lod_info[lod_id]->axis_position; - break; - } - //rotationY - case 2: { - scale = (scale / (max_value - min_value)) * (angle1 - angle0); - glm::vec3 rotation_axis = glm::vec3(0.0f, 1.0f, 0.0f); - animation_matrix = glm::rotate(animation_matrix, -scale, rotation_axis); - rotation_offset = this->lod_info[lod_id]->axis_position; - break; - } - //rotationZ - case 3: { - scale = (scale / (max_value - min_value)) * (angle1 - angle0); - glm::vec3 rotation_axis = glm::vec3(0.0f, 0.0f, 1.0f); - animation_matrix = glm::rotate(animation_matrix, -scale, rotation_axis); - rotation_offset = this->lod_info[lod_id]->axis_position; - break; - } - //translation - case 4: { - scale = (scale / (max_value - min_value)) * (offset1 - offset0); - animation_matrix = glm::translate(animation_matrix, glm::vec3( - this->lod_info[lod_id]->axis_direction.x()*scale, - this->lod_info[lod_id]->axis_direction.y()*scale, - this->lod_info[lod_id]->axis_direction.z()*scale - )); - - break; - } - //translationX - case 5: { - animation_matrix = glm::translate(animation_matrix, glm::vec3( - scale, - 0.0f, - 0.0f - )); - break; - } - //translationY - case 6: { - animation_matrix = glm::translate(animation_matrix, glm::vec3( - 0.0f, - scale, - 0.0f - )); - break; - } - //translationZ - case 7: { - animation_matrix = glm::translate(animation_matrix, glm::vec3( - 0.0f, - 0.0f, - scale - )); - break; - } - case 8: { - // fuck direct for now - } - //hide - case 9: { - if(phase >= hide_value) - animation_matrix = glm::mat4x4(0.0f); - break; - } - default: {} - } - return_matrices[lod_id].first = animation_matrix * base_matrix; - return_matrices[lod_id].second = base_rotation_offset + rotation_offset; - } - return return_matrices; + glm::vec3 axis_position = glm::vec3(this->lod_info[lod_id]->axis_position.x(), this->lod_info[lod_id]->axis_position.y(), this->lod_info[lod_id]->axis_position.z()); + glm::vec3 axis_direction = glm::vec3(this->lod_info[lod_id]->axis_direction.x(), this->lod_info[lod_id]->axis_direction.y(), this->lod_info[lod_id]->axis_direction.z()); + + if (this->type < 4) { + switch (this->type) { + //rotation + case 0: { + scale = (scale / (max_value - min_value)) * (angle1 - angle0); + + animation_matrix = glm::rotate(glm::mat4(1.0f), scale, axis_direction); + direction_matrix = glm::translate(glm::mat4(1.0f), axis_position); + + animation_matrix = animation_matrix * direction_matrix; + + rotation_offset = this->lod_info[lod_id]->axis_position; + break; + } + //rotationX + case 1: { + scale = (scale / (max_value - min_value)) * (angle1 - angle0); + glm::vec3 rotation_axis = glm::vec3(1.0f, 0.0f, 0.0f); + + animation_matrix = glm::rotate(glm::mat4(1.0f), -scale, rotation_axis); + direction_matrix = glm::translate(glm::mat4(1.0f), axis_position); + + animation_matrix = animation_matrix * direction_matrix; + + rotation_offset = this->lod_info[lod_id]->axis_position; + break; + } + //rotationY + case 2: { + scale = (scale / (max_value - min_value)) * (angle1 - angle0); + glm::vec3 rotation_axis = glm::vec3(0.0f, 1.0f, 0.0f); + + animation_matrix = glm::rotate(glm::mat4(1.0f), scale, rotation_axis); + direction_matrix = glm::translate(glm::mat4(1.0f), axis_position); + + animation_matrix = animation_matrix * direction_matrix; + + rotation_offset = this->lod_info[lod_id]->axis_position; + break; + } + //rotationZ + case 3: { + scale = (scale / (max_value - min_value)) * (angle1 - angle0); + glm::vec3 rotation_axis = glm::vec3(0.0f, 0.0f, 1.0f); + + direction_matrix = glm::translate(glm::mat4(1.0f), axis_position); + animation_matrix = glm::rotate(direction_matrix, -scale, rotation_axis); + + + animation_matrix = animation_matrix * direction_matrix; + + rotation_offset = this->lod_info[lod_id]->axis_position; + break; + } + //translation + case 4: { + scale = (scale / (max_value - min_value)) * (offset1 - offset0); + glm::vec3 direction( + this->lod_info[lod_id]->axis_direction.x(), + this->lod_info[lod_id]->axis_direction.y(), + this->lod_info[lod_id]->axis_direction.z() + ); + direction = direction * scale; + direction_matrix = glm::translate(glm::mat4(1.0f), axis_position); + animation_matrix = glm::translate(glm::mat4(1.0f), direction); + animation_matrix = animation_matrix * direction_matrix; + + break; + } + //translationX + case 5: { + scale = (scale / (max_value - min_value)) * (offset1 - offset0); + animation_matrix = glm::translate(animation_matrix, glm::vec3( + scale, + 0.0f, + 0.0f + )); + break; + } + //translationY + case 6: { + scale = (scale / (max_value - min_value)) * (offset1 - offset0); + animation_matrix = glm::translate(animation_matrix, glm::vec3( + 0.0f, + scale, + 0.0f + )); + break; + } + //translationZ + case 7: { + scale = (scale / (max_value - min_value)) * (offset1 - offset0); + animation_matrix = glm::translate(animation_matrix, glm::vec3( + 0.0f, + 0.0f, + scale + )); + break; + } + case 8: { + // fuck direct for now + break; + } + //hide + case 9: { + if (phase >= hide_value) + animation_matrix = glm::mat4x4(0.0f); + break; + } + default: {} + } + return_matrices[lod_id].first = animation_matrix * base_matrix; + return_matrices[lod_id].second = base_rotation_offset + rotation_offset; + } + } + return return_matrices; } float ace::simulation::animation::get_scale(float phase) { - float scale = 0; + float scale = 0; - switch (source_address) - { - case 1: - scale = fmod(phase - min_value, max_value - min_value) + min_value; - scale = std::min(std::max(scale, min_phase), max_phase); - break; - case 2: - scale = fmod(phase - min_value, (max_value - min_value) * 2) + min_value; - if (scale > max_value) scale = max_value - (scale - max_value); - scale = std::min(std::max(scale, min_phase), max_phase); - break; - default: - scale = std::min(std::max(phase, min_phase), max_phase); - } + switch (source_address) + { + case 1: + scale = fmod(phase - min_value, (max_value - min_value) * 2) + min_value; + // when over limit, mirror + if (phase > max_value) phase = max_value - (phase - max_value); - return scale; + scale = std::min(std::max(scale, min_phase), max_phase); + + break; + case 2: + scale = fmod(phase - min_value, (max_value - min_value)) + min_value; + if (scale > max_value) scale = max_value - (scale - max_value); + scale = std::min(std::max(scale, min_phase), max_phase); + break; + default: + scale = std::min(std::max(phase, min_phase), max_phase); + } + + return scale; } ace::simulation::bone::bone( - const std::string _name, - const std::vector &children, - const std::map &p3d_bones, - bone *_parent, - const ace::p3d::model_p p3d, - object * sim_object - ) : parent(_parent), name(_name), base_object(sim_object) + const std::string _name, + const std::vector &children, + const std::map &p3d_bones, + bone *_parent, + const ace::p3d::model_p p3d, + object * sim_object + ) : parent(_parent), name(_name), base_object(sim_object) { - for (auto const child_bone : children) { - if (sim_object->all_bones.find(child_bone) == sim_object->all_bones.end()) { - ace::p3d::bone_p p3d_bone = p3d_bones.find(child_bone)->second; - sim_object->all_bones[child_bone] = std::make_shared(p3d_bone->name, p3d_bone->children, p3d_bones, this, p3d, sim_object); - } - this->children.push_back(sim_object->all_bones[child_bone]); - } - if (parent) { - for (auto p3d_animation : p3d_bones.find(name)->second->animations) { - this->animations.push_back(sim_object->animations[p3d_animation]); - } - } + for (auto const child_bone : children) { + if (sim_object->all_bones.find(child_bone) == sim_object->all_bones.end()) { + ace::p3d::bone_p p3d_bone = p3d_bones.find(child_bone)->second; + sim_object->all_bones[child_bone] = std::make_shared(p3d_bone->name, p3d_bone->children, p3d_bones, this, p3d, sim_object); + } + this->children.push_back(sim_object->all_bones[child_bone]); + } + if (parent) { + for (auto p3d_animation : p3d_bones.find(name)->second->animations) { + this->animations.push_back(sim_object->animations[p3d_animation]); + } + } } void ace::simulation::bone::animate(const std::map &animation_state, const std::vector &lods, animation_transform base_transforms) { - if (animations.size() > 0) { - for (auto bone_animation : animations) { - if(animation_state.find(bone_animation->name) != animation_state.end()) { - base_transforms = bone_animation->animate(animation_state.find(bone_animation->name)->second, lods, base_transforms); - } - } - } - for (auto child_bone : children) { - child_bone->animate(animation_state, lods, base_transforms); - } - if(animations.size() > 0) { - for (auto bone_animation : animations) { - for (auto lod_id : lods) { - auto selection = this->base_object->lods[lod_id]->selections.find(this->name); - if(selection != this->base_object->lods[lod_id]->selections.end()) { - selection->second->animate(base_transforms[lod_id].first, base_transforms[lod_id].second); - } - } - } - } + if (animations.size() > 0) { + for (auto bone_animation : animations) { + if (animation_state.find(bone_animation->name) != animation_state.end()) { + base_transforms = bone_animation->animate(animation_state.find(bone_animation->name)->second, lods, base_transforms); + } + } + } + for (auto child_bone : children) { + child_bone->animate(animation_state, lods, base_transforms); + } + if (animations.size() > 0) { + for (auto bone_animation : animations) { + for (auto lod_id : lods) { + auto selection = this->base_object->lods[lod_id]->selections.find(this->name); + if (selection != this->base_object->lods[lod_id]->selections.end()) { + selection->second->animate(base_transforms[lod_id].first, base_transforms[lod_id].second); + } + } + } + } } ace::simulation::object::object() @@ -384,27 +421,27 @@ ace::simulation::object::object() ace::simulation::object::object(const ace::p3d::model_p model) { - for (ace::p3d::lod_p p3d_lod : model->lods) { - lod_p new_lod = std::make_shared(p3d_lod, model); - this->lods.push_back(new_lod); + for (ace::p3d::lod_p p3d_lod : model->lods) { + lod_p new_lod = std::make_shared(p3d_lod, model); + this->lods.push_back(new_lod); this->lods[p3d_lod->id]->type = model->info->resolutions[p3d_lod->id]; - } + } - for (ace::p3d::animation_p p3d_animation : model->animations) { - this->animations.push_back(std::make_shared(this, p3d_animation, model)); - } + for (ace::p3d::animation_p p3d_animation : model->animations) { + this->animations.push_back(std::make_shared(this, p3d_animation, model)); + } - std::map p3d_bones; - for (auto const skeleton_bone : model->skeleton->all_bones) { - p3d_bones[skeleton_bone->name] = skeleton_bone; - } + std::map p3d_bones; + for (auto const skeleton_bone : model->skeleton->all_bones) { + p3d_bones[skeleton_bone->name] = skeleton_bone; + } - std::vector root_bones; - for (auto const root_bone : model->skeleton->root_bones) { - root_bones.push_back(root_bone.first); - } + std::vector root_bones; + for (auto const root_bone : model->skeleton->root_bones) { + root_bones.push_back(root_bone.first); + } - this->root_bone = std::make_shared("", root_bones, p3d_bones, nullptr, model, this); + this->root_bone = std::make_shared("", root_bones, p3d_bones, nullptr, model, this); } @@ -414,14 +451,14 @@ ace::simulation::object::~object() } -void ace::simulation::object::animate(const std::map &animation_state, const std::vector &selected_lods) +void ace::simulation::object::animate(const std::map &animation_state, const std::vector &selected_lods) { - std::vector lods; - lods.push_back(1); - animation_transform identity_transform; - identity_transform[1].first = glm::mat4(); - identity_transform[1].second = ace::vector3(0, 0, 0); - this->root_bone->animate(animation_state, lods, identity_transform); + animation_transform identity_transform; + for (uint32_t lod_id : selected_lods) { + identity_transform[lod_id].first = glm::mat4(); + identity_transform[lod_id].second = ace::vector3(0, 0, 0); + } + this->root_bone->animate(animation_state, selected_lods, identity_transform); } diff --git a/extensions/common/simulation/object.hpp b/extensions/common/simulation/object.hpp index b9dbb6e661..a77da9d5cf 100644 --- a/extensions/common/simulation/object.hpp +++ b/extensions/common/simulation/object.hpp @@ -209,7 +209,7 @@ namespace ace { std::vector animations; - void animate(const std::map &, const std::vector &); + void animate(const std::map &, const std::vector &); std::map all_bones; diff --git a/extensions/common/vector.hpp b/extensions/common/vector.hpp index 5a32e9c5fe..ac5b38bd1f 100644 --- a/extensions/common/vector.hpp +++ b/extensions/common/vector.hpp @@ -65,7 +65,7 @@ namespace ace { T distance(const vector3 &v) const { vector3 dist = (*this - v); dist = dist * dist; return sqrt(dist.x() + dist.y() + dist.z()); } vector3 cross(const vector3 &v) const { return vector3(_y * v.z() - _z * v.y(), _z * v.x() - _x * v.z(), _x * v.y() - _y * v.x()); } vector3 normalize(void) const { return (*this / abs(magnitude())); }; - bool zero_distance() { if (_x == 0.0f && _y == 0.0f && _z == 0.0f) return true; return false; } + bool zero_distance() { return ((_x == 0.0f && _y == 0.0f && _z == 0.0f) ? true : false ); } static float clamp(T x, T a, T b) { return x < a ? a : (x > b ? b : x); } diff --git a/extensions/dynload/dynloader.hpp b/extensions/dynload/dynloader.hpp index 43d0dcdac9..8916e9af92 100644 --- a/extensions/dynload/dynloader.hpp +++ b/extensions/dynload/dynloader.hpp @@ -11,11 +11,11 @@ namespace ace { class module { public: module() : handle(nullptr), function(nullptr), name("") {} - module(const std::string & name_, HANDLE handle_, RVExtension function_, const std::string & file_) : handle(nullptr), function(function_), name(name_), temp_filename(file_) {} + module(const std::string & name_, HMODULE handle_, RVExtension function_, const std::string & file_) : handle(handle_), function(function_), name(name_), temp_filename(file_) {} std::string name; std::string temp_filename; - HINSTANCE handle; + HMODULE handle; RVExtension function; }; @@ -32,7 +32,7 @@ namespace ace { #ifdef _WINDOWS bool load(const arguments & args_, std::string & result) { - HINSTANCE dllHandle; + HMODULE dllHandle; RVExtension function; LOG(INFO) << "Load requested [" << args_.as_string(0) << "]"; @@ -55,9 +55,9 @@ namespace ace { return false; } std::string temp_filename = buffer; - if (!CopyFileA(args_.as_string(0).c_str(), temp_filename.c_str(), TRUE)) { + if (!CopyFileA(args_.as_string(0).c_str(), temp_filename.c_str(), FALSE)) { DeleteFile(temp_filename.c_str()); - if (!CopyFileA(args_.as_string(0).c_str(), temp_filename.c_str(), TRUE)) { + if (!CopyFileA(args_.as_string(0).c_str(), temp_filename.c_str(), FALSE)) { LOG(ERROR) << "CopyFile() , e=" << GetLastError(); return false; } @@ -89,17 +89,25 @@ namespace ace { LOG(INFO) << "Unload requested [" << args_.as_string(0) << "]"; - if (_modules.find(args_.as_string(0)) != _modules.end()) { + if (_modules.find(args_.as_string(0)) == _modules.end()) { LOG(INFO) << "Unload failed, module not loaded [" << args_.as_string(0) << "]"; return true; } - FreeLibrary(_modules[args_.as_string(0)].handle); + if (!FreeLibrary(_modules[args_.as_string(0)].handle)) { + LOG(INFO) << "FreeLibrary() failed during unload, e=" << GetLastError(); + return false; + } + //if (!DeleteFileA(_modules[args_.as_string(0)].temp_filename.c_str())) { + // LOG(INFO) << "DeleteFile() failed during unload, e=" << GetLastError(); + // return false; + //} + _modules.erase(args_.as_string(0)); LOG(INFO) << "Unload complete [" << args_.as_string(0) << "]"; - return false; + return true; } #endif @@ -116,10 +124,12 @@ namespace ace { std::string function_str; std::vector temp = ace::split(args_.get(), ','); - function_str = temp[1] + ":"; - for (int x = 2; x < temp.size(); x++) - function_str = function_str + temp[x] + ","; - + if (temp.size() < 3) { + function_str = temp[1]; + } else { + for (int x = 1; x < temp.size(); x++) + function_str = function_str + temp[x] + ","; + } _modules[args_.as_string(0)].function((char *)result.c_str(), 4096, (const char *)function_str.c_str()); #ifdef _DEBUG //if (args_.as_string(0) != "fetch_result" && args_.as_string(0) != "ready") { diff --git a/extensions/tests/AT_01.txt b/extensions/tests/AT_01.txt new file mode 100644 index 0000000000..9145fb9fdf --- /dev/null +++ b/extensions/tests/AT_01.txt @@ -0,0 +1,6 @@ +#c:\arma\arma3\addons\static_f_gamma.pbo C:\dev\ace3\extensions\tests\AT_01.txt +init: +debug_render: +register_vehicle:\A3\Static_F_gamma\AT_01\AT_01.p3d,0,4050.18;3802.55;5.075 +#set_animation_state:0, MainTurret, 0, MainGun, 0, MainTurret_destructX, 0, MainTurret_destructY, 0, MainTurret_destructZ, 0, MainGun_destructX, 0, MainGun_destructY, 0, MainGun_destructZ, 0, magazine_destruct, 0, ammo_belt_destruct, 0, bolt_destruct, 0, charging_handle_destruct, 0, damagehideVez_destruct, 0, damagehideHlaven_destruct, 0, damagehideRecoil_destruct, 0, Turret_shake, 0, Turret_shake_aside, 0, Magazine_hide, 0, Ammo_belt_hide, 0, muzzleFlash, 0, AddAutonomous_unhide, 0, bullet001_reload_hide, 0, bullet002_reload_hide, 0, bullet003_reload_hide, 0, bullet004_reload_hide, 0, bullet005_reload_hide, 0, bullet006_reload_hide, 0, bullet007_reload_hide, 0, bullet008_reload_hide, 0 +set_animation_state:0, MainTurret, -0, MainGun, 1, MainTurret_destructX, 0, MainTurret_destructY, 0, MainTurret_destructZ, 0, MainGun_destructX, 0, MainGun_destructY, 0, MainGun_destructZ, 0, magazine_destruct, 0, ammo_belt_destruct, 0, bolt_destruct, 0, charging_handle_destruct, 0, damagehideVez_destruct, 0, damagehideHlaven_destruct, 0, damagehideRecoil_destruct, 0, Turret_shake, 0, Turret_shake_aside, 0, Magazine_hide, 0, Ammo_belt_hide, 0, muzzleFlash, 0, AddAutonomous_unhide, 0, bullet001_reload_hide, 0, bullet002_reload_hide, 0, bullet003_reload_hide, 0, bullet004_reload_hide, 0, bullet005_reload_hide, 0, bullet006_reload_hide, 0, bullet007_reload_hide, 0, bullet008_reload_hide, 0 \ No newline at end of file diff --git a/extensions/tests/CMakeLists.txt b/extensions/tests/CMakeLists.txt index 106e989b51..fcaf5bd29e 100644 --- a/extensions/tests/CMakeLists.txt +++ b/extensions/tests/CMakeLists.txt @@ -15,15 +15,10 @@ if(USE_DIRECTX) add_dependencies(ace_vd_ext_test ace_common ace_vd_static) target_link_libraries(ace_vd_ext_test ace_common directxtk ace_vd_static - ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} - ${BULLET_LIBS_DEBUG} - ) + ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} BulletDynamics BulletCollision LinearMath) else() add_dependencies(ace_vd_ext_test ace_common ace_vd_static) - target_link_libraries(ace_vd_ext_test ace_common - ${BULLET_LIBS_DEBUG} - ace_vd_static - ) + target_link_libraries(ace_vd_ext_test ace_common BulletDynamics BulletCollision LinearMath ace_vd_static) endif() set_target_properties(ace_vd_ext_test PROPERTIES PREFIX "") set_target_properties(ace_vd_ext_test PROPERTIES FOLDER Tests) @@ -38,14 +33,10 @@ if(USE_DIRECTX) add_dependencies(ace_longrod_dxtk_test ace_common ace_vd_static) target_link_libraries(ace_longrod_dxtk_test ace_common directxtk ace_vd_static - ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} - ${BULLET_LIBS_DEBUG} - ) + ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} BulletDynamics BulletCollision LinearMath) else() add_dependencies(ace_longrod_dxtk_test ace_common ace_vd_static) - target_link_libraries(ace_longrod_dxtk_test ace_common - ${BULLET_LIBS_DEBUG} - ace_vd_static + target_link_libraries(ace_longrod_dxtk_test ace_common BulletDynamics BulletCollision LinearMath ace_vd_static ) endif() set_target_properties(ace_longrod_dxtk_test PROPERTIES PREFIX "") @@ -58,18 +49,14 @@ set_target_properties(ace_longrod_dxtk_test PROPERTIES FOLDER Tests) if(USE_DIRECTX) add_executable( ace_test_render test_render.cpp test_render.hpp) target_link_libraries(ace_test_render ace_common - ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} - ${BULLET_LIBS_DEBUG} - ) + ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} BulletDynamics BulletCollision LinearMath ) add_dependencies(ace_test_render ace_common) SET_TARGET_PROPERTIES(ace_test_render PROPERTIES PREFIX "") set_target_properties(ace_test_render PROPERTIES FOLDER Tests) add_executable( ace_dxtk_test dxtk_test.cpp) target_link_libraries(ace_dxtk_test ace_common directxtk - ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} - ${BULLET_LIBS_DEBUG} - ) + ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} BulletDynamics BulletCollision LinearMath) add_dependencies(ace_dxtk_test ace_common directxtk) SET_TARGET_PROPERTIES(ace_dxtk_test PROPERTIES PREFIX "") diff --git a/extensions/tests/longrod_dxtk_test.cpp b/extensions/tests/longrod_dxtk_test.cpp index d7dc7736c8..201b276938 100644 --- a/extensions/tests/longrod_dxtk_test.cpp +++ b/extensions/tests/longrod_dxtk_test.cpp @@ -69,5 +69,11 @@ int main(int argc, char **argv) { } } - getchar(); + while (true) { + scanf_s("%s", buffer, sizeof(buffer) - 1); + memset(output, 0x00, sizeof(output)); + LOG(INFO) << "Executing: '" << buffer << "'"; + RVExtension(output, sizeof(output), buffer); + LOG(INFO) << "Result: '" << output << "'"; + } } \ No newline at end of file diff --git a/extensions/tests/longrod_dxtk_test.txt b/extensions/tests/longrod_dxtk_test.txt index 92f95a7d4a..ee93010471 100644 --- a/extensions/tests/longrod_dxtk_test.txt +++ b/extensions/tests/longrod_dxtk_test.txt @@ -1,6 +1,5 @@ +#c:\arma\arma3\addons\armor_f_epb.pbo C:\dev\ace3\extensions\tests\longrod_dxtk_test.txt init: debug_render: -register_vehicle:\A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d,2,4050.18;3802.55;5.075 -#hit:2,\A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d,[],2,Sh_120mm_APFSDS,650,27,19100,50,10,708.602;235.609;-85.6468,-2.1748;0.139648;-1.35955,0.942743;0.31346;-0.113925,-1;6.1914e-007;0.000794772,-2.17383;0.139404;-1.32366,708.602;235.609;-85.6468 -#register_vehicle:\a3\structures_f\mil\BagFence\BagFence_Long_F.p3d,0,4050.18;3802.55;5.075 -#hit:0,A3\Structures_F\Mil\BagFence\BagFence_Long_F.p3d,[],0,B_65x39_Caseless,1295,264,11300,0,0,-16.5091;729.003;-177.406,0.2854;-0.239258;0.0619297,-0.0219989;0.971421;-0.236342,0.00232643;-0.999479;0.0321913 \ No newline at end of file +register_vehicle:\A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, 1, 4046.21;3902.56;5.075 +#set_animation_state:1,damageHide, 0, Wheel_kolL1, 0, Wheel_koloL1, 0, Wheel_podkoloL1, 1, Wheel_kolP1, 0, Wheel_koloP1, 0, Wheel_podkoloP1, 1, Wheel_kolL2, 0, Wheel_kolP2, 0, Wheel_koloL2, 0, Wheel_koloL3, 0, Wheel_koloL4, 0, Wheel_koloL5, 0, Wheel_koloL6, 0, Wheel_koloL7, 0, Wheel_koloP2, 0, Wheel_koloP3, 0, Wheel_koloP4, 0, Wheel_koloP5, 0, Wheel_koloP6, 0, Wheel_koloP7, 0, Wheel_podkoloL2, 1, Wheel_podkoloL3, 1, Wheel_podkoloL4, 1, Wheel_podkoloL5, 0, Wheel_podkoloL6, 0, Wheel_podkoloP2, 1, Wheel_podkoloP3, 1, Wheel_podkoloP4, 1, Wheel_podkoloP5, 0, Wheel_podkoloP6, 1, podkoloL1_hide_damage, 0, podkoloL2_hide_damage, 0, podkoloL3_hide_damage, 0, podkoloL4_hide_damage, 0, podkoloL5_hide_damage, 0, podkoloL6_hide_damage, 0, podkoloL7_hide_damage, 0, podkoloL8_hide_damage, 0, podkoloP1_hide_damage, 0, podkoloP2_hide_damage, 0, podkoloP3_hide_damage, 0, podkoloP4_hide_damage, 0, podkoloP5_hide_damage, 0, podkoloP6_hide_damage, 0, podkoloP7_hide_damage, 0, podkoloP8_hide_damage, 0, damageVez, 0, MainTurret, -3, MainGun, 0, Recoil, 0, ObsTurret, -0, ObsGun, 0, MainGunOptics, 0, Wheel_podkoloP7, 0, Wheel_podkoloL7, 0, HatchDriver, 0, HatchCommander, 0, HatchGunner, 0, damageVezVelitele, 0, poklop_commander_damage, 0, poklop_gunner_damage, 0, poklop_driver_damage, 0, zaslehROT_HMG, 101, zaslehROT_coax, 16, cannon_muzzle_flash, 0, zaslehROT_cannon, 956, HideHull, 1, HideTurret, 1, LockMuzzle, 0 \ No newline at end of file diff --git a/extensions/tests/longrod_dxtk_test.txt.backup b/extensions/tests/longrod_dxtk_test.txt.backup new file mode 100644 index 0000000000..f924e48327 --- /dev/null +++ b/extensions/tests/longrod_dxtk_test.txt.backup @@ -0,0 +1,6 @@ +#c:\arma\arma3\addons\structures_f_ind.pbo C:\dev\ace3\extensions\tests\longrod_dxtk_test.txt.backup +init: +debug_render: +register_vehicle:\A3\Structures_F\Ind\Cargo\Cargo40_blue_F.p3d,0,4050.18;3802.55;5.075 +set_animation_state:0,Door_1_rot,1,Door_Locked_1_rot,0,Door_2_rot,0,Door_Locked_2_rot,0, +fetch_result:1 \ No newline at end of file diff --git a/extensions/tests/p3d_parser.cpp b/extensions/tests/p3d_parser.cpp index d0da6acfa0..5b6072a690 100644 --- a/extensions/tests/p3d_parser.cpp +++ b/extensions/tests/p3d_parser.cpp @@ -21,6 +21,7 @@ int main(int argc, char **argv) { printf("Usage: %s [file.p3d]", argv[0]); return -1; } + ace::p3d::model_p _model = _parser.load(argv[1]); ace::simulation::object _object(_model); @@ -30,7 +31,7 @@ int main(int argc, char **argv) { test_phases["box1"] = 1.0f; std::vector test_lods; test_lods.push_back("GEO"); - _object.animate(test_phases, test_lods); + //_object.animate(test_phases, test_lods); /*printf("lod 0 face 0: %f %f %f\n\n", _object.lods[0]->faces[0]->vertices[0]->x(), _object.lods[0]->faces[0]->vertices[1]->y(), _object.lods[0]->selections[0]->faces[0]->vertices[0]->z());*/ diff --git a/extensions/tests/test.pbo.txt b/extensions/tests/test.pbo.txt new file mode 100644 index 0000000000..bcf512e9e6 --- /dev/null +++ b/extensions/tests/test.pbo.txt @@ -0,0 +1,5 @@ +# C:\dev\ace3\extensions\tests\test.pbo C:\dev\ace3\extensions\tests\test.pbo.txt +init: +debug_render: +register_vehicle:\test\test.p3d,0,4050.18;3802.55;5.075 +set_animation_state:0,box3_rotate,0.5,box3_translate,0, \ No newline at end of file diff --git a/extensions/vd/CMakeLists.txt b/extensions/vd/CMakeLists.txt index 77bd243bb3..f453550779 100644 --- a/extensions/vd/CMakeLists.txt +++ b/extensions/vd/CMakeLists.txt @@ -17,16 +17,14 @@ add_library( ${ACE_EXTENSION_NAME} SHARED ${DEBUG_SOURCES} ${SOURCES} ${DAMAGE_S add_library( ${ACE_EXTENSION_NAME}_static STATIC ${DEBUG_SOURCES} ${SOURCES} ${DAMAGE_SOURCES} ${PENETRATION_SOURCES} ${GLOBAL_SOURCES}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -if(USE_BULLET) - set(BULLET_LIBS ${BULLET_LIBS_DEBUG}) -else() +if(NOT USE_BULLET) message(FATAL_ERROR "Bullet is required for vehicle damage!\nYou need to build out the bullet3 folder and define -DUSE_BULLET=On") endif() if(DEVEL AND USE_DIRECTX) - set(LINK_LIBS directxtk ${BULLET_LIBS_DEBUG} ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY}) + set(LINK_LIBS directxtk BulletDynamics BulletCollision LinearMath ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY}) else() - set(LINK_LIBS ${BULLET_LIBS_DEBUG}) + set(LINK_LIBS BulletDynamics BulletCollision LinearMath) endif() target_link_libraries(${ACE_EXTENSION_NAME} ace_common ${LINK_LIBS}) diff --git a/extensions/vd/ace_vd_dllmain.cpp b/extensions/vd/ace_vd_dllmain.cpp index 4084982341..415ca0372a 100644 --- a/extensions/vd/ace_vd_dllmain.cpp +++ b/extensions/vd/ace_vd_dllmain.cpp @@ -1,6 +1,6 @@ #include "shared.hpp" #include "logging.hpp" - +#include "controller.hpp" INITIALIZE_EASYLOGGINGPP BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle, @@ -25,6 +25,10 @@ BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle, break; case DLL_PROCESS_DETACH: + if (Reserved == NULL) { + ace::vehicledamage::controller::get().stop(); + LOG(INFO) << "Vehicle Damage unloaded and halted"; + } break; } diff --git a/extensions/vd/base_vehicle.cpp b/extensions/vd/base_vehicle.cpp index cfb0ec0d01..2e660804ca 100644 --- a/extensions/vd/base_vehicle.cpp +++ b/extensions/vd/base_vehicle.cpp @@ -8,7 +8,7 @@ using namespace ace::simulation; namespace ace { namespace vehicledamage { - base_vehicle::base_vehicle(uint32_t id, ace::simulation::object_p object_, ace::vector3 position_) : object(object_) { + base_vehicle::base_vehicle(uint32_t id, ace::simulation::object_p object_, ace::vector3 position_) : id(id), object(object_) { bt_mesh = std::make_shared(); fire_lod = -1; @@ -21,16 +21,17 @@ namespace ace { } if (fire_lod == -1) // @TODO: fallback on geo LOD fire_lod = 0; + fire_lod = 0; assert(fire_lod != -1); - + // Build the mesh from object faces // TODO: LOD!? // P3d store in x,z,y format for (auto & face : object_->lods[fire_lod]->faces) { bt_mesh->addTriangle( - btVector3(face->vertices[0]->x(), face->vertices[0]->z(), face->vertices[0]->y()), - btVector3(face->vertices[1]->x(), face->vertices[1]->z(), face->vertices[1]->y()), - btVector3(face->vertices[2]->x(), face->vertices[2]->z(), face->vertices[2]->y()) + btVector3(face->vertices[0]->x(), face->vertices[0]->y(), face->vertices[0]->z()), + btVector3(face->vertices[1]->x(), face->vertices[1]->y(), face->vertices[1]->z()), + btVector3(face->vertices[2]->x(), face->vertices[2]->y(), face->vertices[2]->z()) ); } @@ -54,6 +55,15 @@ namespace ace { controller::get().bt_world->removeCollisionObject(bt_object.get()); } + bool base_vehicle::simulate() { + std::vector lods; + lods.push_back(fire_lod); + + object->animate(animation_state, lods); + + return true; + } + void base_vehicle::transform() { btTransform transform = bt_object->getWorldTransform(); diff --git a/extensions/vd/base_vehicle.hpp b/extensions/vd/base_vehicle.hpp index 7a207433fc..d85224dcf1 100644 --- a/extensions/vd/base_vehicle.hpp +++ b/extensions/vd/base_vehicle.hpp @@ -23,17 +23,18 @@ namespace ace { base_vehicle(uint32_t, ace::simulation::object_p, ace::vector3); ~base_vehicle(); + bool simulate(); + void transform(void); + float surface_raycast(const ace::vector3 &, const ace::vector3 &, std::vector> &); float thickness(const ace::vector3 &, const ace::vector3 &); - std::vector> selection_position(const uint32_t, const std::string &, const SELECTION_SEARCH_TYPE); std::vector> selection_by_name_vertices(const uint32_t, const std::string &); ace::simulation::named_selection_p selection_by_name(const uint32_t, const std::string &); - void transform(void); - // Bullet physx objects + uint32_t id; int fire_lod; ace::vector3 direction; @@ -44,6 +45,8 @@ namespace ace { std::shared_ptr bt_object; std::shared_ptr bt_body; + std::map animation_state; + ace::simulation::object_p object; protected: diff --git a/extensions/vd/controller.cpp b/extensions/vd/controller.cpp index 549ca44f14..479dac3fc7 100644 --- a/extensions/vd/controller.cpp +++ b/extensions/vd/controller.cpp @@ -36,6 +36,7 @@ namespace ace { add("delete_vehicle", std::bind(&ace::vehicledamage::controller::delete_vehicle, this, std::placeholders::_1, std::placeholders::_2)); add("set_vehicle_state", std::bind(&ace::vehicledamage::controller::set_vehicle_state, this, std::placeholders::_1, std::placeholders::_2)); + add("set_animation_state", std::bind(&ace::vehicledamage::controller::set_animation_state, this, std::placeholders::_1, std::placeholders::_2)); add("hit", std::bind(&ace::vehicledamage::controller::handle_hit, this, std::placeholders::_1, std::placeholders::_2)); @@ -111,8 +112,17 @@ namespace ace { vehicle_p _vehicle = std::make_shared(static_cast(_args[1]), _object, _args[2]); vehicles[static_cast(_args[1])] = _vehicle; - LOG(INFO) << "vehicle registered: [id=" << _args[1].as_uint32() << ", type=" << _args[0].as_string() << "]"; + // For results on a valid vehicle registration, we return its animation names for that given vehicle + std::stringstream _animationNames; + _animationNames << _vehicle->id; + for (auto & anim : _vehicle->object->animations) { + _animationNames << "," << anim->name; + _vehicle->animation_state[anim->name] = 0.0f; + } + + this->push_result("setAnimationNames:"+_animationNames.str()); + LOG(INFO) << "vehicle registered: [id=" << _args[1].as_uint32() << ", type=" << _args[0].as_string() << "]"; DEBUG_DISPATCH("register_vehicle", _args[1].as_string()); return true; @@ -133,6 +143,42 @@ namespace ace { return true; } + bool controller::set_animation_state(const arguments &_args, std::string & results) { + if (_args.size() < 3) + return false; + + uint32_t id = _args[0]; + + // First value is id, following values are name,value,name,value,name,value + if (vehicles.find(id) == vehicles.end()) + return false; + + for (int x = 1, y = 1; x < vehicles[id]->animation_state.size() && x < _args.size() / 2; x++, y +=2) { + std::string animation_name = _args[y]; + float state = _args[y + 1]; + vehicles[id]->animation_state[animation_name] = state; + } + + return false; + } + bool controller::get_animations(const arguments &_args, std::string & results) { + uint32_t id = static_cast(_args[1]); + + if (vehicles.find(id) == vehicles.end()) + return false; + + // For results on a valid vehicle registration, we return its animation names for that given vehicle + std::stringstream _animationNames; + _animationNames << vehicles[id]->id; + for (auto & anim : vehicles[id]->object->animations) { + _animationNames << "," << anim->name; + vehicles[id]->animation_state[anim->name] = 0.0f; + } + + this->push_result("get_animations:" + _animationNames.str()); + + return false; + } bool controller::set_vehicle_state(const arguments &_args, std::string & result) { if (_args.size() < 3) return false; @@ -142,7 +188,7 @@ namespace ace { vehicles[_args[0]]->direction = _args[1]; vehicles[_args[0]]->up = _args[2]; - vehicles[_args[0]]->transform(); + //vehicles[_args[0]]->transform(); return true; } diff --git a/extensions/vd/controller.hpp b/extensions/vd/controller.hpp index a14dd3c717..780f784819 100644 --- a/extensions/vd/controller.hpp +++ b/extensions/vd/controller.hpp @@ -29,9 +29,11 @@ namespace ace { bool register_vehicle(const arguments &, std::string &); bool delete_vehicle(const arguments &, std::string &); + bool set_animation_state(const arguments &, std::string &); bool set_vehicle_state(const arguments &, std::string &); bool handle_hit(const arguments & args, std::string &); + bool get_animations(const arguments &, std::string &); bool get_thickness(const arguments &, std::string &); bool selection_position(const arguments &, std::string &); #ifdef _DEBUG diff --git a/extensions/vd/debug/penetration_display.cpp b/extensions/vd/debug/penetration_display.cpp index ee990ccbde..3f57e209fb 100644 --- a/extensions/vd/debug/penetration_display.cpp +++ b/extensions/vd/debug/penetration_display.cpp @@ -44,13 +44,13 @@ namespace ace { _BatchEffect.reset(new BasicEffect(_pd3dDevice)); _BatchEffect->SetVertexColorEnabled(true); - + { void const* shaderByteCode; size_t byteCodeLength; _BatchEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength); - + hr = _pd3dDevice->CreateInputLayout(VertexPositionColor::InputElements, VertexPositionColor::InputElementCount, shaderByteCode, byteCodeLength, @@ -129,23 +129,15 @@ namespace ace { ace::vector3 hit_from, hit_to; hit_from = hit->impactposition; - hit_to = hit_from + (hit->impactvelocity * 0.005f); + hit_to = hit_from + (hit->impactvelocity * 0.01f); XMVECTORF32 from = { hit_from.x(), hit_from.y(), hit_from.z() }; XMVECTORF32 to = { hit_to.x(), hit_to.y(), hit_to.z() }; - XMVECTORF32 to_a1 = { hit_to.x() + 0.5, hit_to.y() + 0.5, hit_to.z() }; - XMVECTORF32 to_a2 = { hit_to.x() - 0.5, hit_to.y() - 0.5, hit_to.z() }; VertexPositionColor v1(from, color); VertexPositionColor v2(to, color); - VertexPositionColor a1(to_a2, color); - VertexPositionColor a2(to_a1, color); - batch.DrawLine(v1, v2); - - batch.DrawLine(a1, v2); - batch.DrawLine(a2, v2); } @@ -156,13 +148,39 @@ namespace ace { batch.Begin(); + // Debug animation the shit + _active_vehicle->simulate(); + + /*for (auto & selection : obj.lods[lod]->selections) { + for (auto & face : selection.second->faces) { + ace::vector3 vertices[3]; + vertices[0] = { face->vertices[0]->x(), face->vertices[0]->y(), face->vertices[0]->z() }; + vertices[1] = { face->vertices[1]->x(), face->vertices[1]->y(), face->vertices[1]->z() }; + vertices[2] = { face->vertices[2]->x(), face->vertices[2]->y(), face->vertices[2]->z() }; + + XMVECTORF32 v[3] = { + { vertices[0].x(), vertices[0].y(), vertices[0].z() }, + { vertices[1].x(), vertices[1].y(), vertices[1].z() }, + { vertices[2].x(), vertices[2].y(), vertices[2].z() } + }; + + VertexPositionColor v1(v[0], color); + VertexPositionColor v2(v[1], color); + VertexPositionColor v3(v[2], color); + + batch.DrawLine(v1, v2); + batch.DrawLine(v2, v3); + batch.DrawLine(v3, v1); + } + }*/ + + for (auto & face : obj.lods[lod]->faces) { ace::vector3 vertices[3]; vertices[0] = { face->vertices[0]->x(), face->vertices[0]->y(), face->vertices[0]->z() }; vertices[1] = { face->vertices[1]->x(), face->vertices[1]->y(), face->vertices[1]->z() }; vertices[2] = { face->vertices[2]->x(), face->vertices[2]->y(), face->vertices[2]->z() }; - XMVECTORF32 v[3] = { { vertices[0].x(), vertices[0].y(), vertices[0].z() }, { vertices[1].x(), vertices[1].y(), vertices[1].z() },