Reworked with test p3d.

Animations accessible. Pass map of animation names and phases and pass a vector of the lods you want to animate.

Dynamic loading humbuggery.

Added: A3->Extension animation state sync framework done. Test cases for animations created.

Apply animation phases from game to test case render.

Continuing finalization. rotation_offset was reversed for zero_distance, thats fixed but still off. Rendering test hard-coded for container LOD temporarily.

Rotation translation corrected.

Removed: Scale flipping, these should work now but they dont.

Debug logging, debug model.

Correct parameters to extension.

Stability fixes.

Animations nearly aligning correctly.

scale, rotation and translation work; still not working. Back compat for v60 p3d's fully implemented.

Add vehicle ID to animation state send.

cmake bullet integration from submodule.

WINVER forced for all builds.

More bullet + windows + cmake fun.

Remove LinaerMath.

Testing for nou.

typo

Fixed: Pathing bug.

Vehicle damage working set for Nou.
This commit is contained in:
jaynus 2015-05-10 19:44:31 -07:00
parent 62e441fb1d
commit e22080db3a
42 changed files with 787 additions and 428 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,4 +3,8 @@
// Handle damage to local vehicles // Handle damage to local vehicles
[QGVAR(hp), FUNC(dispatchHitPart)] call EFUNC(common,addEventHandler); [QGVAR(hp), FUNC(dispatchHitPart)] call EFUNC(common,addEventHandler);
[FUNC(monitorResultsPFH), 0, []] call CBA_fnc_addPerFrameHandler; // Extension dispatch commands
[QGVAR(setAnimationNames), FUNC(setAnimationNames)] call EFUNC(common,addEventHandler);
// Trigger and start fetching results
[FUNC(monitorResultsPFH), 0, []] call CBA_fnc_addPerFrameHandler;

View File

@ -8,11 +8,24 @@ PREP(monitorResultsPFH);
PREP(parseResult); PREP(parseResult);
PREP(callExtension); 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(async) = true;
GVAR(ready) = false; 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 // Core functionality
PREP(registerVehicleDamageHandler); PREP(registerVehicleDamageHandler);
PREP(registerVehicleWithExtension); PREP(registerVehicleWithExtension);
@ -23,6 +36,7 @@ PREP(dispatchDamage);
PREP(doHit); PREP(doHit);
GVAR(vehicle_id) = 0; GVAR(vehicle_id) = 0;
GVAR(vehicles) = HASH_CREATE;
FUNC(_textVector) = { FUNC(_textVector) = {
private["_str"]; private["_str"];
@ -30,6 +44,37 @@ FUNC(_textVector) = {
_str _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); [] call FUNC(initializeExtension);
ADDON = true; ADDON = true;

View File

@ -1,7 +1,20 @@
#include "script_component.hpp" #include "script_component.hpp"
private["_extResult"];
#ifdef DEBUG_EXTENSION_DYNLOAD #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 #else
"ace_vd" callExtension _this; _extResult = "ace_vd" callExtension _this;
#endif #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
};

View File

@ -33,9 +33,10 @@ if(_projectileLength == 0) then {
_vehicleId = _vehicle getVariable[QGVAR(id), -1]; _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 _vehicleId, // vehicle id registered
_model, _selection, // _model, _selection,
_model, "BALLS",
VECTOR_TEXT(vectorDir _vehicle), VECTOR_TEXT(vectorDir _vehicle),
VECTOR_TEXT(vectorUp _vehicle), VECTOR_TEXT(vectorUp _vehicle),
_projectileType, //projectile type id _projectileType, //projectile type id

View File

@ -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

View File

@ -6,7 +6,9 @@
GVAR(ready) = false; GVAR(ready) = false;
#ifdef DEBUG_EXTENSION_DYNLOAD #ifdef DEBUG_EXTENSION_DYNLOAD
#ifdef DEBUG_EXTENSION_DYNLOAD_RELOAD
"ace_dynload" callExtension format["unload:%1", GVAR(extensionLibrary)]; "ace_dynload" callExtension format["unload:%1", GVAR(extensionLibrary)];
#endif
"ace_dynload" callExtension format["load:%1", GVAR(extensionLibrary)]; "ace_dynload" callExtension format["load:%1", GVAR(extensionLibrary)];
diag_log text format["[ACE] - DEBUG - Dynamic extension loaded for Vehicle Damage"]; diag_log text format["[ACE] - DEBUG - Dynamic extension loaded for Vehicle Damage"];
#endif #endif
@ -18,7 +20,7 @@ if(GVAR(async)) then {
diag_log text format["[ACE] - Vehicle damage extension caching..."]; diag_log text format["[ACE] - Vehicle damage extension caching..."];
"init:" call FUNC(callExtension); "init:" call FUNC(callExtension);
#ifdef ACE_VEHICLEDAMAGE_RENDER_DEBUG #ifdef DEBUG_VEHICLEDAMAGE_RENDER
"debug_render:" call FUNC(callExtension); "debug_render:" call FUNC(callExtension);
diag_log text format["[ACE] - DEBUG - DirectX11 Debug Rendering initialized"]; diag_log text format["[ACE] - DEBUG - DirectX11 Debug Rendering initialized"];
#endif #endif

View File

@ -1,21 +1,27 @@
//#define DEBUG_MODE_FULL //#define DEBUG_MODE_FULL
#include "script_component.hpp" #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"]; private["_result"];
if(GVAR(ready)) then { if(GVAR(ready)) then {
_result = "fetch_result:1" call FUNC(callExtension);; _result = "fetch_result:1" call FUNC(callExtension);;
while { _result != "" && {_result != "-1"} } do { while { _result != "" && {_result != "-1"} } do {
TRACE_1("", _result); TRACE_1("", _result);
_result = "fetch_result:1" call FUNC(callExtension);;
_resultArgs = [_result] call FUNC(parseResult); _resultArgs = [_result] call FUNC(parseResult);
if(!isNil "_resultArgs") then { if(!isNil "_resultArgs") then {
if((_resultArgs select 0) == "exec") then { if((_resultArgs select 0) == "exec") then {
TRACE_1("", "Dispatching exec");
[] call (_resultArgs select 1); [] call (_resultArgs select 1);
} else { } 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);
}; };
}; };

View File

@ -2,7 +2,7 @@
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_vehicle); PARAMS_1(_vehicle);
private["_id", "_model"]; private["_id", "_model","_vehicleData"];
if(GVAR(Enabled) < 1) exitWith {}; if(GVAR(Enabled) < 1) exitWith {};
@ -15,6 +15,8 @@ if(_model != "") then {
TRACE_1("", _value); TRACE_1("", _value);
_result = _value call FUNC(callExtension); _result = _value call FUNC(callExtension);
_vehicle setVariable[QGVAR(id), _id, false]; _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]; diag_log text format["[ACE] - Vehicle queued for extension loading %1 - %2=[%2]", _id, _vehicle, _model];

View File

@ -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];
};

View File

@ -15,4 +15,7 @@
#define VECTOR_TEXT(x) ([(x)] call FUNC(_textVector)) #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 RELATIVE_VECTOR_TEXT(o,x) ([(o worldToModelVisual ((x) call EFUNC(common,ASLToPosition)))] call FUNC(_textVector))
#define DEBUG_EXTENSION_DYNLOAD #define DEBUG_EXTENSION_DYNLOAD
#define DEBUG_LOG_EXTENSION
//#define DEBUG_EXTENSION_DYNLOAD_RELOAD
//#define DEBUG_VEHICLEDAMAGE_RENDER

View File

@ -3,6 +3,10 @@ project (ACE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON) 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) if (NOT CMAKE_BUILD_TYPE AND CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "No build type selected, default to Debug") message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug") set(CMAKE_BUILD_TYPE "Debug")
@ -29,14 +33,44 @@ endif()
include_directories("common") include_directories("common")
if(USE_BULLET) 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") 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() endif()
if(USE_DIRECTX) if(USE_DIRECTX)
add_definitions(-DUSE_DIRECTX) add_definitions(-DUSE_DIRECTX)
@ -78,6 +112,7 @@ endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR}/common) include_directories(${CMAKE_CURRENT_BINARY_DIR}/common)
set(GLOBAL_SOURCES ${GLOBAL_RC}) set(GLOBAL_SOURCES ${GLOBAL_RC})
# Add extensions to build here # Add extensions to build here
add_subdirectory(common) add_subdirectory(common)

View File

@ -40,6 +40,9 @@ namespace ace {
public: public:
arguments(const std::string & str) : _original(str) { arguments(const std::string & str) : _original(str) {
_args = ace::split(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(); } size_t size() const { return _args.size(); }
@ -82,6 +85,6 @@ namespace ace {
protected: protected:
std::vector<std::string> _args; std::vector<std::string> _args;
const std::string &_original; const std::string _original;
}; };
} }

View File

@ -3,12 +3,36 @@
#include "shared.hpp" #include "shared.hpp"
#include "d3d_display.hpp" #include "d3d_display.hpp"
#include <TlHelp32.h>
#include <thread> #include <thread>
using namespace DirectX; using namespace DirectX;
namespace ace { namespace ace {
namespace debug { namespace debug {
DWORD GetMainThreadId() {
const std::shared_ptr<void> 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() : _fullscreen(false) {}
d3d_display::~d3d_display() {} d3d_display::~d3d_display() {}
@ -210,6 +234,9 @@ namespace ace {
return false; return false;
} }
// Attach our input to the master input
//AttachThreadInput(GetCurrentThreadId(), GetMainThraedId());
SetWindowLongPtr(_hWnd, GWLP_USERDATA, (LONG)this); SetWindowLongPtr(_hWnd, GWLP_USERDATA, (LONG)this);
ShowWindow(_hWnd, 5); ShowWindow(_hWnd, 5);
@ -307,11 +334,13 @@ namespace ace {
LRESULT CALLBACK d3d_display::_wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT CALLBACK d3d_display::_wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps; PAINTSTRUCT ps;
HDC hdc; HDC hdc;
switch (message) { switch (message) {
case WM_INPUT: { case WM_INPUT: {
UINT dwSize; UINT dwSize;
if (GetActiveWindow() != _hWnd) {
return DefWindowProc(hWnd, message, wParam, lParam);
}
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize,
sizeof(RAWINPUTHEADER)); sizeof(RAWINPUTHEADER));
LPBYTE lpb = new BYTE[dwSize]; LPBYTE lpb = new BYTE[dwSize];

View File

@ -55,7 +55,7 @@ namespace ace {
class threaded_dispatcher : public dispatcher { class threaded_dispatcher : public dispatcher {
public: public:
threaded_dispatcher() : _worker(&ace::threaded_dispatcher::monitor, this) { threaded_dispatcher() : _stop(false), _worker(&ace::threaded_dispatcher::monitor, this) {
} }
~threaded_dispatcher() {} ~threaded_dispatcher() {}
@ -99,11 +99,14 @@ namespace ace {
void push_result(const std::string & result) { void push_result(const std::string & result) {
push_result(dispatch_result(result, -1)); push_result(dispatch_result(result, -1));
} }
void stop() {
std::lock_guard<std::mutex> lock(_messages_lock);
_stop = true;
}
protected: protected:
void monitor() { void monitor() {
_ready = false; _ready = false;
while (true) { while (!_stop) {
{ {
std::lock_guard<std::mutex> lock(_messages_lock); std::lock_guard<std::mutex> lock(_messages_lock);
while (!_messages.empty()) { while (!_messages.empty()) {
@ -135,15 +138,16 @@ namespace ace {
sleep(5); sleep(5);
} }
} }
std::queue<dispatch_result> _results; std::atomic_bool _stop;
std::mutex _results_lock; std::queue<dispatch_result> _results;
std::mutex _results_lock;
std::queue<dispatch_message> _messages; std::queue<dispatch_message> _messages;
std::mutex _messages_lock; 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<dispatch> { }; class threaded_dispatch : public threaded_dispatcher, public singleton<dispatch> { };
}; };

View File

@ -20,17 +20,11 @@ namespace ace {
stream_.read((char *)&min_phase, sizeof(float)); stream_.read((char *)&min_phase, sizeof(float));
stream_.read((char *)&max_phase, sizeof(float)); stream_.read((char *)&max_phase, sizeof(float));
//stream_.read((char *)&junk, sizeof(uint32_t)); stream_.read((char *)&junk, sizeof(uint32_t));
//stream_.read((char *)&junk2, sizeof(uint32_t)); stream_.read((char *)&junk2, sizeof(uint32_t));
stream_.read((char *)&source_address, sizeof(uint32_t)); stream_.read((char *)&source_address, sizeof(uint32_t));
float buffer[4]; // This always adds up to 2*4 more bytes unless its direct apparently
stream_.read((char *)buffer, sizeof(float) * 4);
return;
// THIS IS ALL WRONG
// ARMA3 HAS FIXED 4-FLOAT TRANSFORMS
switch (type) { switch (type) {
// rotations // rotations
case 0: case 0:
@ -61,9 +55,11 @@ namespace ace {
case 9: // fucking hides... case 9: // fucking hides...
stream_.read((char *)&hide_value, sizeof(float)); stream_.read((char *)&hide_value, sizeof(float));
stream_.read((char *)&offset1, sizeof(float)); // this is junk throw it in offset1 for hides stream_.read((char *)&offset1, sizeof(float)); // this is junk throw it in offset1 for hides
break;
default: default:
stream_.read((char *)&offset0, sizeof(float)); stream_.read((char *)&offset0, sizeof(float));
stream_.read((char *)&offset1, sizeof(float)); stream_.read((char *)&offset1, sizeof(float));
break;
} }

View File

@ -43,7 +43,7 @@ namespace ace {
stream_.read((char *)&u_float_1, sizeof(float)); stream_.read((char *)&u_float_1, sizeof(float));
// Derp, this was only TOH apparently!? // Derp, this was only TOH apparently!?
//point_flags = compressed<uint32_t>(stream_, true, true); //point_flags = compressed<uint32_t>(stream_, true, true, version);
stream_.read((char *)&u_float_2, sizeof(float)); stream_.read((char *)&u_float_2, sizeof(float));
stream_.read((char *)&u_float_3, sizeof(float)); stream_.read((char *)&u_float_3, sizeof(float));
@ -70,8 +70,8 @@ namespace ace {
materials.push_back(std::make_shared<material>(stream_, version)); materials.push_back(std::make_shared<material>(stream_, version));
} }
edges.mlod = compressed<uint16_t>(stream_, true, false).data; edges.mlod = compressed<uint16_t>(stream_, true, false, version).data;
edges.vertex = compressed<uint16_t>(stream_, true, false).data; edges.vertex = compressed<uint16_t>(stream_, true, false, version).data;
// @TODO: THIS IS OFF WTF?! // @TODO: THIS IS OFF WTF?!
// The first face is coming up null, so we missed something // The first face is coming up null, so we missed something
@ -128,14 +128,14 @@ namespace ace {
uv::uv() {} uv::uv() {}
uv::uv(std::istream &stream_, uint32_t version = 68) { uv::uv(std::istream &stream_, uint32_t version = 68) {
stream_.read((char *)&uv_scale, sizeof(float) * 4); stream_.read((char *)&uv_scale, sizeof(float) * 4);
data = compressed<float>(stream_, true, true); data = compressed<float>(stream_, true, true, version);
} }
c_vertex_table::c_vertex_table() {} c_vertex_table::c_vertex_table() {}
c_vertex_table::c_vertex_table(std::istream &stream_, uint32_t size_, uint32_t version = 68) : size(size_) { c_vertex_table::c_vertex_table(std::istream &stream_, uint32_t size_, uint32_t version = 68) : size(size_) {
uint32_t temp_count; uint32_t temp_count;
point_flags = compressed<uint32_t>(stream_, true, true); point_flags = compressed<uint32_t>(stream_, true, true, version);
uvsets.push_back(std::make_shared<uv>(stream_, version)); uvsets.push_back(std::make_shared<uv>(stream_, version));
@ -145,7 +145,7 @@ namespace ace {
uvsets.push_back(std::make_shared<uv>(stream_, version)); uvsets.push_back(std::make_shared<uv>(stream_, version));
} }
points = compressed<ace::vector3<float>>(stream_, true, false, false); points = compressed<ace::vector3<float>>(stream_, true, false, false, version);
size = points.size; size = points.size;
} }
@ -157,15 +157,15 @@ namespace ace {
READ_STRING(name); READ_STRING(name);
faces = compressed<uint16_t>(stream_, true, false); faces = compressed<uint16_t>(stream_, true, false, version);
//face_weights = compressed<uint32_t>(stream_, true, false); // Face weights //face_weights = compressed<uint32_t>(stream_, true, false, version); // Face weights
face_weights = compressed<uint32_t>(stream_, true, false); face_weights = compressed<uint32_t>(stream_, true, false, version);
READ_BOOL(is_sectional); READ_BOOL(is_sectional);
sections = compressed<uint32_t>(stream_, true, false); sections = compressed<uint32_t>(stream_, true, false, version);
vertex_table = compressed<uint16_t>(stream_, true, false); vertex_table = compressed<uint16_t>(stream_, true, false, version);
texture_weights = compressed<uint8_t>(stream_, true, false); texture_weights = compressed<uint8_t>(stream_, true, false, version);
//stream_.read((char *)&junk, 4); //stream_.read((char *)&junk, 4);
} }

View File

@ -8,7 +8,7 @@ namespace ace {
raw_resolutions(nullptr), u_floats_1(nullptr), default_indicators(nullptr) 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(nullptr), u_floats_1(nullptr), default_indicators(nullptr) {
raw_resolutions = new float[lod_count]; raw_resolutions = new float[lod_count];
@ -57,7 +57,7 @@ namespace ace {
stream_.read((char *)&u_byte_1, sizeof(uint8_t)); stream_.read((char *)&u_byte_1, sizeof(uint8_t));
compressed<float> u_floats_1(stream_, true, false); compressed<float> u_floats_1(stream_, true, false, version);
stream_.read((char *)&mass, sizeof(float)); stream_.read((char *)&mass, sizeof(float));
stream_.read((char *)&mass_reciprocal, sizeof(float)); stream_.read((char *)&mass_reciprocal, sizeof(float));

View File

@ -11,7 +11,7 @@ namespace ace {
class model_info { class model_info {
public: public:
model_info(); 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(); ~model_info();

View File

@ -135,6 +135,8 @@ namespace ace {
pbo_stream.close(); pbo_stream.close();
} }
LOG(INFO) << "PBO Index complete";
return true; return true;
} }
@ -266,6 +268,8 @@ namespace ace {
/* Cast our buffer into an UNICODE_STRING. */ /* Cast our buffer into an UNICODE_STRING. */
objectName = *(PUNICODE_STRING)objectNameInfo; objectName = *(PUNICODE_STRING)objectNameInfo;
/* Print the information! */ /* Print the information! */
if (objectName.Length) if (objectName.Length)
@ -276,20 +280,11 @@ namespace ace {
std::string object_type(tmp_type.begin(), tmp_type.end()); std::string object_type(tmp_type.begin(), tmp_type.end());
std::string object_name(tmp_name.begin(), tmp_name.end()); std::string object_name(tmp_name.begin(), tmp_name.end());
if (object_type == "File" && object_name.find(".pbo") != object_name.npos) { if (object_type == "File" && object_name.find(".pbo") != object_name.npos) {
char volume_letter[MAX_PATH]; char buffer[MAX_PATH];
BOOL res = GetVolumePathName(object_name.c_str(), volume_letter, sizeof(volume_letter)); GetFinalPathNameByHandle(dupHandle, buffer, sizeof(buffer), VOLUME_NAME_DOS);
if (res) {
volume_letter[2] = 0x00;
std::vector<std::string> tokens = ace::split(object_name, '\\');
std::stringstream s; LOG(DEBUG) << "Pbo: " << buffer;
s << volume_letter; _active_pbo_list.push_back(std::string(buffer));
for (int x = 3; x < tokens.size(); x++) {
s << "\\" << tokens[x];
}
LOG(DEBUG) << "Pbo: " << s.str();
_active_pbo_list.push_back(s.str());
}
} }
} }

View File

@ -1,5 +1,10 @@
#include "shared.hpp" #include "shared.hpp"
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
int test(int var) { int test(int var) {
return var; return var;
} }

View File

@ -40,6 +40,23 @@ namespace ace {
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems); std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);
std::vector<std::string> split(const std::string &s, char delim); std::vector<std::string> split(const std::string &s, char delim);
// trim from start
static inline std::string &ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(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<int, int>(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); inline void runtime_assert(bool result);
struct exception { struct exception {

View File

@ -6,8 +6,8 @@
ace::simulation::vertex::vertex(vertex_table & _table, ace::vector3<float> _vertex, uint32_t _id) : table(_table), vertex_id(_id) ace::simulation::vertex::vertex(vertex_table & _table, ace::vector3<float> _vertex, uint32_t _id) : table(_table), vertex_id(_id)
{ {
this->original_vertex = _vertex; this->original_vertex = _vertex;
this->animated_vertex = _vertex; this->animated_vertex = _vertex;
} }
ace::simulation::vertex::~vertex() ace::simulation::vertex::~vertex()
@ -16,50 +16,50 @@ ace::simulation::vertex::~vertex()
ace::simulation::face::face( ace::simulation::face::face(
const ace::p3d::face_p p3d_face, const ace::p3d::face_p p3d_face,
const ace::p3d::lod_p p3d_lod, const ace::p3d::lod_p p3d_lod,
const ace::p3d::model_p p3d, const ace::p3d::model_p p3d,
ace::simulation::lod *object_lod) ace::simulation::lod *object_lod)
{ {
this->type = p3d_face->type; this->type = p3d_face->type;
for (uint16_t vertex_id : p3d_face->vertex_table) { for (uint16_t vertex_id : p3d_face->vertex_table) {
this->vertices.push_back(object_lod->vertices[vertex_id]); this->vertices.push_back(object_lod->vertices[vertex_id]);
object_lod->vertices[vertex_id]->faces.push_back(this); object_lod->vertices[vertex_id]->faces.push_back(this);
} }
} }
ace::simulation::face::~face() ace::simulation::face::~face()
{ {
} }
void ace::simulation::vertex::animate(const glm::mat4 &matrix, ace::vector3<float> rotation_offset, bool offset) void ace::simulation::vertex::animate(const glm::mat4 &matrix, ace::vector3<float> rotation_offset, bool offset)
{ {
ace::vector3<float> temp_vector = this->original_vertex; ace::vector3<float> temp_vector = this->original_vertex;
if (offset) { if (offset) {
temp_vector = temp_vector - rotation_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); 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; temp_gl_vector = matrix*temp_gl_vector;
this->animated_vertex = ace::vector3<float>(temp_gl_vector.x, temp_gl_vector.y, temp_gl_vector.z); this->animated_vertex = ace::vector3<float>(temp_gl_vector.x, temp_gl_vector.y, temp_gl_vector.z);
if (offset) { if (offset) {
this->animated_vertex = this->animated_vertex + rotation_offset; // this->animated_vertex = this->animated_vertex + rotation_offset;
} }
} }
ace::simulation::named_selection::named_selection( ace::simulation::named_selection::named_selection(
const ace::p3d::named_selection_p p3d_selection, const ace::p3d::named_selection_p p3d_selection,
const ace::p3d::lod_p p3d_lod, const ace::p3d::lod_p p3d_lod,
const ace::p3d::model_p p3d, const ace::p3d::model_p p3d,
ace::simulation::lod *object_lod) ace::simulation::lod *object_lod)
{ {
this->name = p3d_selection->name; this->name = p3d_selection->name;
for (uint16_t vertex_id : p3d_selection->vertex_table.data) { for (uint16_t vertex_id : p3d_selection->vertex_table.data) {
this->vertices.push_back(object_lod->vertices[vertex_id]); this->vertices.push_back(object_lod->vertices[vertex_id]);
object_lod->vertices[vertex_id]->selections.push_back(this); object_lod->vertices[vertex_id]->selections.push_back(this);
} }
for (uint16_t face_id : p3d_selection->faces.data) { for (uint16_t face_id : p3d_selection->faces.data) {
this->faces.push_back(object_lod->faces[face_id]); this->faces.push_back(object_lod->faces[face_id]);
} }
} }
ace::simulation::named_selection::~named_selection() 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<float> rotation_offset) void ace::simulation::named_selection::animate(const glm::mat4 &matrix, ace::vector3<float> rotation_offset)
{ {
bool offset = rotation_offset.zero_distance(); bool offset = !rotation_offset.zero_distance();
for (auto selection_vertex : this->vertices) { for (auto selection_vertex : this->vertices) {
selection_vertex->animate(matrix, rotation_offset, offset); 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) 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); this->vertices.resize(p3d_vertex_table->points.size);
for (uint32_t i = 0; i <= p3d_vertex_table->points.size - 1; ++i) { for (uint32_t i = 0; i <= p3d_vertex_table->points.size - 1; ++i) {
if(p3d->info->autocenter) { if (p3d->info->autocenter) {
ace::vector3<float> new_vertex = ace::vector3<float>( ace::vector3<float> new_vertex = ace::vector3<float>(
p3d_vertex_table->points[i].x() + (p3d_lod->autocenter_pos.x()*-1), 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].y() + (p3d_lod->autocenter_pos.y()*-1),
p3d_vertex_table->points[i].z() + (p3d_lod->autocenter_pos.z()*-1) p3d_vertex_table->points[i].z() + (p3d_lod->autocenter_pos.z()*-1)
); );
this->vertices[i] = std::make_shared<vertex>(*this, new_vertex, i); this->vertices[i] = std::make_shared<vertex>(*this, new_vertex, i);
} }
else { else {
this->vertices[i] = std::make_shared<vertex>(*this, p3d_vertex_table->points[i], i); this->vertices[i] = std::make_shared<vertex>(*this, p3d_vertex_table->points[i], i);
} }
} }
} }
ace::simulation::vertex_table::~vertex_table() 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) ace::simulation::lod::lod(const ace::p3d::lod_p p3d_lod, const ace::p3d::model_p p3d)
{ {
this->id = p3d_lod->id; this->id = p3d_lod->id;
this->vertices = vertex_table(p3d_lod->vertices, p3d_lod, p3d); this->vertices = vertex_table(p3d_lod->vertices, p3d_lod, p3d);
this->autocenter_pos = p3d_lod->autocenter_pos; this->autocenter_pos = p3d_lod->autocenter_pos;
for (ace::p3d::face_p p3d_face : p3d_lod->faces) { for (ace::p3d::face_p p3d_face : p3d_lod->faces) {
this->faces.push_back(std::make_shared<face>(p3d_face, p3d_lod, p3d, this)); this->faces.push_back(std::make_shared<face>(p3d_face, p3d_lod, p3d, this));
} }
for (ace::p3d::named_selection_p p3d_selection : p3d_lod->selections) { for (ace::p3d::named_selection_p p3d_selection : p3d_lod->selections) {
this->selections[p3d_selection->name] = std::make_shared<named_selection>(p3d_selection, p3d_lod, p3d, this); this->selections[p3d_selection->name] = std::make_shared<named_selection>(p3d_selection, p3d_lod, p3d, this);
} }
} }
@ -121,21 +121,21 @@ ace::simulation::lod::~lod()
} }
ace::simulation::lod_animation_info::lod_animation_info( ace::simulation::lod_animation_info::lod_animation_info(
animation *_animation, animation *_animation,
lod_p _lod, lod_p _lod,
const ace::p3d::animate_bone_p p3d_animate_bone, const ace::p3d::animate_bone_p p3d_animate_bone,
const ace::p3d::animation_p p3d_animation, const ace::p3d::animation_p p3d_animation,
const ace::p3d::model_p p3d) : animation_definition(_animation), lod(_lod) const ace::p3d::model_p p3d) : animation_definition(_animation), lod(_lod)
{ {
this->index = p3d_animate_bone->index; this->index = p3d_animate_bone->index;
if (p3d->info->autocenter) { if (p3d->info->autocenter) {
this->axis_position = p3d_animate_bone->axis_position + (lod->autocenter_pos*-1); this->axis_position = p3d_animate_bone->axis_position + (lod->autocenter_pos*-1);
this->axis_direction = p3d_animate_bone->axis_direction.normalize(); this->axis_direction = p3d_animate_bone->axis_direction.normalize();
} }
else { else {
this->axis_position = p3d_animate_bone->axis_position; this->axis_position = p3d_animate_bone->axis_position;
this->axis_direction = p3d_animate_bone->axis_direction.normalize(); this->axis_direction = p3d_animate_bone->axis_direction.normalize();
} }
} }
ace::simulation::lod_animation_info::~lod_animation_info() 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) 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->type = p3d_animation->type;
this->name = p3d_animation->name; this->name = p3d_animation->name;
this->source = p3d_animation->source; 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->min_value = p3d_animation->min_value;
this->max_value = p3d_animation->max_value; this->max_value = p3d_animation->max_value;
this->min_phase = p3d_animation->min_phase; this->min_phase = p3d_animation->min_phase;
this->max_phase = p3d_animation->max_phase; this->max_phase = p3d_animation->max_phase;
switch (type) { switch (type) {
// rotations // rotations
case 0: case 0:
case 1: case 1:
case 2: case 2:
case 3: case 3:
angle0 = p3d_animation->angle0; angle0 = p3d_animation->angle0;
angle1 = p3d_animation->angle1; angle1 = p3d_animation->angle1;
break; break;
// translations // translations
case 4: case 4:
case 5: case 5:
case 6: case 6:
case 7: case 7:
offset0 = p3d_animation->offset0; offset0 = p3d_animation->offset0;
offset1 = p3d_animation->offset1; offset1 = p3d_animation->offset1;
break; break;
case 8: case 8:
direct_axis_pos = p3d_animation->direct_axis_pos; direct_axis_pos = p3d_animation->direct_axis_pos;
direct_axis_dir = p3d_animation->direct_axis_dir; direct_axis_dir = p3d_animation->direct_axis_dir;
direct_angle = p3d_animation->direct_angle; direct_angle = p3d_animation->direct_angle;
direct_axis_offset = p3d_animation->direct_axis_offset; direct_axis_offset = p3d_animation->direct_axis_offset;
break; break;
case 9: case 9:
hide_value = p3d_animation->hide_value; hide_value = p3d_animation->hide_value;
default: default:
offset0 = 0.0f; offset0 = 0.0f;
offset1 = 0.0f; offset1 = 0.0f;
} }
for (ace::p3d::animate_bone_p animation_bone : p3d_animation->bones) { for (ace::p3d::animate_bone_p animation_bone : p3d_animation->bones) {
this->lod_info[animation_bone->lod] = std::make_shared<lod_animation_info>(this, parent_object->lods[animation_bone->lod], animation_bone, p3d_animation, p3d); this->lod_info[animation_bone->lod] = std::make_shared<lod_animation_info>(this, parent_object->lods[animation_bone->lod], animation_bone, p3d_animation, p3d);
} }
} }
@ -200,10 +200,10 @@ ace::simulation::animation::~animation()
} }
typedef union { typedef union {
float f; float f;
struct { struct {
uint32_t sh1 : 32; uint32_t sh1 : 32;
} parts; } parts;
} double_cast; } double_cast;
#define RAD2DEG(rad) (rad * 180.0f / 3.1415926f); #define RAD2DEG(rad) (rad * 180.0f / 3.1415926f);
@ -211,171 +211,208 @@ typedef union {
typedef std::map<uint32_t, std::pair<glm::mat4, ace::vector3<float>>> animation_transform; typedef std::map<uint32_t, std::pair<glm::mat4, ace::vector3<float>>> animation_transform;
animation_transform ace::simulation::animation::animate(const float phase, const std::vector<uint32_t> &lods, animation_transform base_transforms) animation_transform ace::simulation::animation::animate(const float phase, const std::vector<uint32_t> &lods, animation_transform base_transforms)
{ {
animation_transform return_matrices; animation_transform return_matrices;
for (auto lod_id : lods) { for (auto lod_id : lods) {
glm::mat4 base_matrix = base_transforms[lod_id].first; glm::mat4 base_matrix = base_transforms[lod_id].first;
ace::vector3<float> base_rotation_offset = base_transforms[lod_id].second; ace::vector3<float> base_rotation_offset = base_transforms[lod_id].second;
glm::mat4 animation_matrix; glm::mat4 animation_matrix, direction_matrix;
ace::vector3<float> rotation_offset = ace::vector3<float>(0, 0, 0); ace::vector3<float> rotation_offset = ace::vector3<float>(0, 0, 0);
float scale = get_scale(phase); float scale = get_scale(phase);
switch (this->type) { 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());
//rotation 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());
case 0: {
scale = (scale / (max_value - min_value)) * (angle1 - angle0); if (this->type < 4) {
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()); switch (this->type) {
animation_matrix = glm::rotate(animation_matrix, -scale, rotation_axis); //rotation
rotation_offset = this->lod_info[lod_id]->axis_position; case 0: {
break; scale = (scale / (max_value - min_value)) * (angle1 - angle0);
}
//rotationX animation_matrix = glm::rotate(glm::mat4(1.0f), scale, axis_direction);
case 1: { direction_matrix = glm::translate(glm::mat4(1.0f), axis_position);
scale = (scale / (max_value - min_value)) * (angle1 - angle0);
glm::vec3 rotation_axis = glm::vec3(1.0f, 0.0f, 0.0f); animation_matrix = animation_matrix * direction_matrix;
animation_matrix = glm::rotate(animation_matrix, -scale, rotation_axis);
rotation_offset = this->lod_info[lod_id]->axis_position; rotation_offset = this->lod_info[lod_id]->axis_position;
break; break;
} }
//rotationY //rotationX
case 2: { case 1: {
scale = (scale / (max_value - min_value)) * (angle1 - angle0); scale = (scale / (max_value - min_value)) * (angle1 - angle0);
glm::vec3 rotation_axis = glm::vec3(0.0f, 1.0f, 0.0f); 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; animation_matrix = glm::rotate(glm::mat4(1.0f), -scale, rotation_axis);
break; direction_matrix = glm::translate(glm::mat4(1.0f), axis_position);
}
//rotationZ animation_matrix = animation_matrix * direction_matrix;
case 3: {
scale = (scale / (max_value - min_value)) * (angle1 - angle0); rotation_offset = this->lod_info[lod_id]->axis_position;
glm::vec3 rotation_axis = glm::vec3(0.0f, 0.0f, 1.0f); break;
animation_matrix = glm::rotate(animation_matrix, -scale, rotation_axis); }
rotation_offset = this->lod_info[lod_id]->axis_position; //rotationY
break; case 2: {
} scale = (scale / (max_value - min_value)) * (angle1 - angle0);
//translation glm::vec3 rotation_axis = glm::vec3(0.0f, 1.0f, 0.0f);
case 4: {
scale = (scale / (max_value - min_value)) * (offset1 - offset0); animation_matrix = glm::rotate(glm::mat4(1.0f), scale, rotation_axis);
animation_matrix = glm::translate(animation_matrix, glm::vec3( direction_matrix = glm::translate(glm::mat4(1.0f), axis_position);
this->lod_info[lod_id]->axis_direction.x()*scale,
this->lod_info[lod_id]->axis_direction.y()*scale, animation_matrix = animation_matrix * direction_matrix;
this->lod_info[lod_id]->axis_direction.z()*scale
)); rotation_offset = this->lod_info[lod_id]->axis_position;
break;
break; }
} //rotationZ
//translationX case 3: {
case 5: { scale = (scale / (max_value - min_value)) * (angle1 - angle0);
animation_matrix = glm::translate(animation_matrix, glm::vec3( glm::vec3 rotation_axis = glm::vec3(0.0f, 0.0f, 1.0f);
scale,
0.0f, direction_matrix = glm::translate(glm::mat4(1.0f), axis_position);
0.0f animation_matrix = glm::rotate(direction_matrix, -scale, rotation_axis);
));
break;
} animation_matrix = animation_matrix * direction_matrix;
//translationY
case 6: { rotation_offset = this->lod_info[lod_id]->axis_position;
animation_matrix = glm::translate(animation_matrix, glm::vec3( break;
0.0f, }
scale, //translation
0.0f case 4: {
)); scale = (scale / (max_value - min_value)) * (offset1 - offset0);
break; glm::vec3 direction(
} this->lod_info[lod_id]->axis_direction.x(),
//translationZ this->lod_info[lod_id]->axis_direction.y(),
case 7: { this->lod_info[lod_id]->axis_direction.z()
animation_matrix = glm::translate(animation_matrix, glm::vec3( );
0.0f, direction = direction * scale;
0.0f, direction_matrix = glm::translate(glm::mat4(1.0f), axis_position);
scale animation_matrix = glm::translate(glm::mat4(1.0f), direction);
)); animation_matrix = animation_matrix * direction_matrix;
break;
} break;
case 8: { }
// fuck direct for now //translationX
} case 5: {
//hide scale = (scale / (max_value - min_value)) * (offset1 - offset0);
case 9: { animation_matrix = glm::translate(animation_matrix, glm::vec3(
if(phase >= hide_value) scale,
animation_matrix = glm::mat4x4(0.0f); 0.0f,
break; 0.0f
} ));
default: {} break;
} }
return_matrices[lod_id].first = animation_matrix * base_matrix; //translationY
return_matrices[lod_id].second = base_rotation_offset + rotation_offset; case 6: {
} scale = (scale / (max_value - min_value)) * (offset1 - offset0);
return return_matrices; 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 ace::simulation::animation::get_scale(float phase)
{ {
float scale = 0; float scale = 0;
switch (source_address) switch (source_address)
{ {
case 1: case 1:
scale = fmod(phase - min_value, max_value - min_value) + min_value; scale = fmod(phase - min_value, (max_value - min_value) * 2) + min_value;
scale = std::min(std::max(scale, min_phase), max_phase); // when over limit, mirror
break; if (phase > max_value) phase = max_value - (phase - max_value);
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);
}
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( ace::simulation::bone::bone(
const std::string _name, const std::string _name,
const std::vector<std::string> &children, const std::vector<std::string> &children,
const std::map<std::string, ace::p3d::bone_p> &p3d_bones, const std::map<std::string, ace::p3d::bone_p> &p3d_bones,
bone *_parent, bone *_parent,
const ace::p3d::model_p p3d, const ace::p3d::model_p p3d,
object * sim_object object * sim_object
) : parent(_parent), name(_name), base_object(sim_object) ) : parent(_parent), name(_name), base_object(sim_object)
{ {
for (auto const child_bone : children) { for (auto const child_bone : children) {
if (sim_object->all_bones.find(child_bone) == sim_object->all_bones.end()) { 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; ace::p3d::bone_p p3d_bone = p3d_bones.find(child_bone)->second;
sim_object->all_bones[child_bone] = std::make_shared<bone>(p3d_bone->name, p3d_bone->children, p3d_bones, this, p3d, sim_object); sim_object->all_bones[child_bone] = std::make_shared<bone>(p3d_bone->name, p3d_bone->children, p3d_bones, this, p3d, sim_object);
} }
this->children.push_back(sim_object->all_bones[child_bone]); this->children.push_back(sim_object->all_bones[child_bone]);
} }
if (parent) { if (parent) {
for (auto p3d_animation : p3d_bones.find(name)->second->animations) { for (auto p3d_animation : p3d_bones.find(name)->second->animations) {
this->animations.push_back(sim_object->animations[p3d_animation]); this->animations.push_back(sim_object->animations[p3d_animation]);
} }
} }
} }
void ace::simulation::bone::animate(const std::map<std::string, float> &animation_state, const std::vector<uint32_t> &lods, animation_transform base_transforms) void ace::simulation::bone::animate(const std::map<std::string, float> &animation_state, const std::vector<uint32_t> &lods, animation_transform base_transforms)
{ {
if (animations.size() > 0) { if (animations.size() > 0) {
for (auto bone_animation : animations) { for (auto bone_animation : animations) {
if(animation_state.find(bone_animation->name) != animation_state.end()) { 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); base_transforms = bone_animation->animate(animation_state.find(bone_animation->name)->second, lods, base_transforms);
} }
} }
} }
for (auto child_bone : children) { for (auto child_bone : children) {
child_bone->animate(animation_state, lods, base_transforms); child_bone->animate(animation_state, lods, base_transforms);
} }
if(animations.size() > 0) { if (animations.size() > 0) {
for (auto bone_animation : animations) { for (auto bone_animation : animations) {
for (auto lod_id : lods) { for (auto lod_id : lods) {
auto selection = this->base_object->lods[lod_id]->selections.find(this->name); auto selection = this->base_object->lods[lod_id]->selections.find(this->name);
if(selection != this->base_object->lods[lod_id]->selections.end()) { if (selection != this->base_object->lods[lod_id]->selections.end()) {
selection->second->animate(base_transforms[lod_id].first, base_transforms[lod_id].second); selection->second->animate(base_transforms[lod_id].first, base_transforms[lod_id].second);
} }
} }
} }
} }
} }
ace::simulation::object::object() ace::simulation::object::object()
@ -384,27 +421,27 @@ ace::simulation::object::object()
ace::simulation::object::object(const ace::p3d::model_p model) ace::simulation::object::object(const ace::p3d::model_p model)
{ {
for (ace::p3d::lod_p p3d_lod : model->lods) { for (ace::p3d::lod_p p3d_lod : model->lods) {
lod_p new_lod = std::make_shared<lod>(p3d_lod, model); lod_p new_lod = std::make_shared<lod>(p3d_lod, model);
this->lods.push_back(new_lod); this->lods.push_back(new_lod);
this->lods[p3d_lod->id]->type = model->info->resolutions[p3d_lod->id]; this->lods[p3d_lod->id]->type = model->info->resolutions[p3d_lod->id];
} }
for (ace::p3d::animation_p p3d_animation : model->animations) { for (ace::p3d::animation_p p3d_animation : model->animations) {
this->animations.push_back(std::make_shared<animation>(this, p3d_animation, model)); this->animations.push_back(std::make_shared<animation>(this, p3d_animation, model));
} }
std::map<std::string, ace::p3d::bone_p> p3d_bones; std::map<std::string, ace::p3d::bone_p> p3d_bones;
for (auto const skeleton_bone : model->skeleton->all_bones) { for (auto const skeleton_bone : model->skeleton->all_bones) {
p3d_bones[skeleton_bone->name] = skeleton_bone; p3d_bones[skeleton_bone->name] = skeleton_bone;
} }
std::vector<std::string> root_bones; std::vector<std::string> root_bones;
for (auto const root_bone : model->skeleton->root_bones) { for (auto const root_bone : model->skeleton->root_bones) {
root_bones.push_back(root_bone.first); root_bones.push_back(root_bone.first);
} }
this->root_bone = std::make_shared<bone>("", root_bones, p3d_bones, nullptr, model, this); this->root_bone = std::make_shared<bone>("", root_bones, p3d_bones, nullptr, model, this);
} }
@ -414,14 +451,14 @@ ace::simulation::object::~object()
} }
void ace::simulation::object::animate(const std::map<std::string, float> &animation_state, const std::vector<std::string> &selected_lods) void ace::simulation::object::animate(const std::map<std::string, float> &animation_state, const std::vector<uint32_t> &selected_lods)
{ {
std::vector<uint32_t> lods; animation_transform identity_transform;
lods.push_back(1); for (uint32_t lod_id : selected_lods) {
animation_transform identity_transform; identity_transform[lod_id].first = glm::mat4();
identity_transform[1].first = glm::mat4(); identity_transform[lod_id].second = ace::vector3<float>(0, 0, 0);
identity_transform[1].second = ace::vector3<float>(0, 0, 0); }
this->root_bone->animate(animation_state, lods, identity_transform); this->root_bone->animate(animation_state, selected_lods, identity_transform);
} }

View File

@ -209,7 +209,7 @@ namespace ace {
std::vector<animation_p> animations; std::vector<animation_p> animations;
void animate(const std::map<std::string, float> &, const std::vector<std::string> &); void animate(const std::map<std::string, float> &, const std::vector<std::uint32_t> &);
std::map<std::string, bone_p> all_bones; std::map<std::string, bone_p> all_bones;

View File

@ -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()); } 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 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())); }; 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); } static float clamp(T x, T a, T b) { return x < a ? a : (x > b ? b : x); }

View File

@ -11,11 +11,11 @@ namespace ace {
class module { class module {
public: public:
module() : handle(nullptr), function(nullptr), name("") {} 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 name;
std::string temp_filename; std::string temp_filename;
HINSTANCE handle; HMODULE handle;
RVExtension function; RVExtension function;
}; };
@ -32,7 +32,7 @@ namespace ace {
#ifdef _WINDOWS #ifdef _WINDOWS
bool load(const arguments & args_, std::string & result) { bool load(const arguments & args_, std::string & result) {
HINSTANCE dllHandle; HMODULE dllHandle;
RVExtension function; RVExtension function;
LOG(INFO) << "Load requested [" << args_.as_string(0) << "]"; LOG(INFO) << "Load requested [" << args_.as_string(0) << "]";
@ -55,9 +55,9 @@ namespace ace {
return false; return false;
} }
std::string temp_filename = buffer; 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()); 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(); LOG(ERROR) << "CopyFile() , e=" << GetLastError();
return false; return false;
} }
@ -89,17 +89,25 @@ namespace ace {
LOG(INFO) << "Unload requested [" << args_.as_string(0) << "]"; 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) << "]"; LOG(INFO) << "Unload failed, module not loaded [" << args_.as_string(0) << "]";
return true; 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)); _modules.erase(args_.as_string(0));
LOG(INFO) << "Unload complete [" << args_.as_string(0) << "]"; LOG(INFO) << "Unload complete [" << args_.as_string(0) << "]";
return false; return true;
} }
#endif #endif
@ -116,10 +124,12 @@ namespace ace {
std::string function_str; std::string function_str;
std::vector<std::string> temp = ace::split(args_.get(), ','); std::vector<std::string> temp = ace::split(args_.get(), ',');
function_str = temp[1] + ":"; if (temp.size() < 3) {
for (int x = 2; x < temp.size(); x++) function_str = temp[1];
function_str = function_str + temp[x] + ","; } 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()); _modules[args_.as_string(0)].function((char *)result.c_str(), 4096, (const char *)function_str.c_str());
#ifdef _DEBUG #ifdef _DEBUG
//if (args_.as_string(0) != "fetch_result" && args_.as_string(0) != "ready") { //if (args_.as_string(0) != "fetch_result" && args_.as_string(0) != "ready") {

View File

@ -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

View File

@ -15,15 +15,10 @@ if(USE_DIRECTX)
add_dependencies(ace_vd_ext_test ace_common ace_vd_static) add_dependencies(ace_vd_ext_test ace_common ace_vd_static)
target_link_libraries(ace_vd_ext_test ace_common directxtk target_link_libraries(ace_vd_ext_test ace_common directxtk
ace_vd_static ace_vd_static
${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} BulletDynamics BulletCollision LinearMath)
${BULLET_LIBS_DEBUG}
)
else() else()
add_dependencies(ace_vd_ext_test ace_common ace_vd_static) add_dependencies(ace_vd_ext_test ace_common ace_vd_static)
target_link_libraries(ace_vd_ext_test ace_common target_link_libraries(ace_vd_ext_test ace_common BulletDynamics BulletCollision LinearMath ace_vd_static)
${BULLET_LIBS_DEBUG}
ace_vd_static
)
endif() endif()
set_target_properties(ace_vd_ext_test PROPERTIES PREFIX "") set_target_properties(ace_vd_ext_test PROPERTIES PREFIX "")
set_target_properties(ace_vd_ext_test PROPERTIES FOLDER Tests) 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) add_dependencies(ace_longrod_dxtk_test ace_common ace_vd_static)
target_link_libraries(ace_longrod_dxtk_test ace_common directxtk target_link_libraries(ace_longrod_dxtk_test ace_common directxtk
ace_vd_static ace_vd_static
${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} BulletDynamics BulletCollision LinearMath)
${BULLET_LIBS_DEBUG}
)
else() else()
add_dependencies(ace_longrod_dxtk_test ace_common ace_vd_static) add_dependencies(ace_longrod_dxtk_test ace_common ace_vd_static)
target_link_libraries(ace_longrod_dxtk_test ace_common target_link_libraries(ace_longrod_dxtk_test ace_common BulletDynamics BulletCollision LinearMath ace_vd_static
${BULLET_LIBS_DEBUG}
ace_vd_static
) )
endif() endif()
set_target_properties(ace_longrod_dxtk_test PROPERTIES PREFIX "") 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) if(USE_DIRECTX)
add_executable( ace_test_render test_render.cpp test_render.hpp) add_executable( ace_test_render test_render.cpp test_render.hpp)
target_link_libraries(ace_test_render ace_common target_link_libraries(ace_test_render ace_common
${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} BulletDynamics BulletCollision LinearMath )
${BULLET_LIBS_DEBUG}
)
add_dependencies(ace_test_render ace_common) add_dependencies(ace_test_render ace_common)
SET_TARGET_PROPERTIES(ace_test_render PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(ace_test_render PROPERTIES PREFIX "")
set_target_properties(ace_test_render PROPERTIES FOLDER Tests) set_target_properties(ace_test_render PROPERTIES FOLDER Tests)
add_executable( ace_dxtk_test dxtk_test.cpp) add_executable( ace_dxtk_test dxtk_test.cpp)
target_link_libraries(ace_dxtk_test ace_common directxtk target_link_libraries(ace_dxtk_test ace_common directxtk
${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} ${DirectX_D3DX11_LIBRARY} ${DirectX_D3D11_LIBRARY} ${DirectX_D3D11_1_LIBRARY} ${DirectX_D3D11_2_LIBRARY} BulletDynamics BulletCollision LinearMath)
${BULLET_LIBS_DEBUG}
)
add_dependencies(ace_dxtk_test ace_common directxtk) add_dependencies(ace_dxtk_test ace_common directxtk)
SET_TARGET_PROPERTIES(ace_dxtk_test PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(ace_dxtk_test PROPERTIES PREFIX "")

View File

@ -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 << "'";
}
} }

View File

@ -1,6 +1,5 @@
#c:\arma\arma3\addons\armor_f_epb.pbo C:\dev\ace3\extensions\tests\longrod_dxtk_test.txt
init: init:
debug_render: debug_render:
register_vehicle:\A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d,2,4050.18;3802.55;5.075 register_vehicle:\A3\Armor_F_EPB\MBT_03\MBT_03_cannon_F.p3d, 1, 4046.21;3902.56;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 #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
#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

View File

@ -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

View File

@ -21,6 +21,7 @@ int main(int argc, char **argv) {
printf("Usage: %s [file.p3d]", argv[0]); printf("Usage: %s [file.p3d]", argv[0]);
return -1; return -1;
} }
ace::p3d::model_p _model = _parser.load(argv[1]); ace::p3d::model_p _model = _parser.load(argv[1]);
ace::simulation::object _object(_model); ace::simulation::object _object(_model);
@ -30,7 +31,7 @@ int main(int argc, char **argv) {
test_phases["box1"] = 1.0f; test_phases["box1"] = 1.0f;
std::vector<std::string> test_lods; std::vector<std::string> test_lods;
test_lods.push_back("GEO"); 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(), /*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]->faces[0]->vertices[1]->y(),
_object.lods[0]->selections[0]->faces[0]->vertices[0]->z());*/ _object.lods[0]->selections[0]->faces[0]->vertices[0]->z());*/

View File

@ -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,

View File

@ -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}) add_library( ${ACE_EXTENSION_NAME}_static STATIC ${DEBUG_SOURCES} ${SOURCES} ${DAMAGE_SOURCES} ${PENETRATION_SOURCES} ${GLOBAL_SOURCES})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if(USE_BULLET) if(NOT USE_BULLET)
set(BULLET_LIBS ${BULLET_LIBS_DEBUG})
else()
message(FATAL_ERROR "Bullet is required for vehicle damage!\nYou need to build out the bullet3 folder and define -DUSE_BULLET=On") message(FATAL_ERROR "Bullet is required for vehicle damage!\nYou need to build out the bullet3 folder and define -DUSE_BULLET=On")
endif() endif()
if(DEVEL AND USE_DIRECTX) 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() else()
set(LINK_LIBS ${BULLET_LIBS_DEBUG}) set(LINK_LIBS BulletDynamics BulletCollision LinearMath)
endif() endif()
target_link_libraries(${ACE_EXTENSION_NAME} ace_common ${LINK_LIBS}) target_link_libraries(${ACE_EXTENSION_NAME} ace_common ${LINK_LIBS})

View File

@ -1,6 +1,6 @@
#include "shared.hpp" #include "shared.hpp"
#include "logging.hpp" #include "logging.hpp"
#include "controller.hpp"
INITIALIZE_EASYLOGGINGPP INITIALIZE_EASYLOGGINGPP
BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle, BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle,
@ -25,6 +25,10 @@ BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle,
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
if (Reserved == NULL) {
ace::vehicledamage::controller::get().stop();
LOG(INFO) << "Vehicle Damage unloaded and halted";
}
break; break;
} }

View File

@ -8,7 +8,7 @@ using namespace ace::simulation;
namespace ace { namespace ace {
namespace vehicledamage { namespace vehicledamage {
base_vehicle::base_vehicle(uint32_t id, ace::simulation::object_p object_, ace::vector3<float> position_) : object(object_) { base_vehicle::base_vehicle(uint32_t id, ace::simulation::object_p object_, ace::vector3<float> position_) : id(id), object(object_) {
bt_mesh = std::make_shared<btTriangleMesh>(); bt_mesh = std::make_shared<btTriangleMesh>();
fire_lod = -1; fire_lod = -1;
@ -21,16 +21,17 @@ namespace ace {
} }
if (fire_lod == -1) // @TODO: fallback on geo LOD if (fire_lod == -1) // @TODO: fallback on geo LOD
fire_lod = 0; fire_lod = 0;
fire_lod = 0;
assert(fire_lod != -1); assert(fire_lod != -1);
// Build the mesh from object faces // Build the mesh from object faces
// TODO: LOD!? // TODO: LOD!?
// P3d store in x,z,y format // P3d store in x,z,y format
for (auto & face : object_->lods[fire_lod]->faces) { for (auto & face : object_->lods[fire_lod]->faces) {
bt_mesh->addTriangle( bt_mesh->addTriangle(
btVector3(face->vertices[0]->x(), face->vertices[0]->z(), face->vertices[0]->y()), btVector3(face->vertices[0]->x(), face->vertices[0]->y(), face->vertices[0]->z()),
btVector3(face->vertices[1]->x(), face->vertices[1]->z(), face->vertices[1]->y()), btVector3(face->vertices[1]->x(), face->vertices[1]->y(), face->vertices[1]->z()),
btVector3(face->vertices[2]->x(), face->vertices[2]->z(), face->vertices[2]->y()) 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()); controller::get().bt_world->removeCollisionObject(bt_object.get());
} }
bool base_vehicle::simulate() {
std::vector<uint32_t> lods;
lods.push_back(fire_lod);
object->animate(animation_state, lods);
return true;
}
void base_vehicle::transform() { void base_vehicle::transform() {
btTransform transform = bt_object->getWorldTransform(); btTransform transform = bt_object->getWorldTransform();

View File

@ -23,17 +23,18 @@ namespace ace {
base_vehicle(uint32_t, ace::simulation::object_p, ace::vector3<float>); base_vehicle(uint32_t, ace::simulation::object_p, ace::vector3<float>);
~base_vehicle(); ~base_vehicle();
bool simulate();
void transform(void);
float surface_raycast(const ace::vector3<float> &, const ace::vector3<float> &, std::vector<ace::vector3<float>> &); float surface_raycast(const ace::vector3<float> &, const ace::vector3<float> &, std::vector<ace::vector3<float>> &);
float thickness(const ace::vector3<float> &, const ace::vector3<float> &); float thickness(const ace::vector3<float> &, const ace::vector3<float> &);
std::vector<ace::vector3<float>> selection_position(const uint32_t, const std::string &, const SELECTION_SEARCH_TYPE); std::vector<ace::vector3<float>> selection_position(const uint32_t, const std::string &, const SELECTION_SEARCH_TYPE);
std::vector<ace::vector3<float>> selection_by_name_vertices(const uint32_t, const std::string &); std::vector<ace::vector3<float>> selection_by_name_vertices(const uint32_t, const std::string &);
ace::simulation::named_selection_p selection_by_name(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 // Bullet physx objects
uint32_t id;
int fire_lod; int fire_lod;
ace::vector3<float> direction; ace::vector3<float> direction;
@ -44,6 +45,8 @@ namespace ace {
std::shared_ptr<btCollisionObject> bt_object; std::shared_ptr<btCollisionObject> bt_object;
std::shared_ptr<btRigidBody> bt_body; std::shared_ptr<btRigidBody> bt_body;
std::map<std::string, float> animation_state;
ace::simulation::object_p object; ace::simulation::object_p object;
protected: protected:

View File

@ -36,6 +36,7 @@ namespace ace {
add("delete_vehicle", std::bind(&ace::vehicledamage::controller::delete_vehicle, this, std::placeholders::_1, std::placeholders::_2)); 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_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)); 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<vehicle>(static_cast<uint32_t>(_args[1]), _object, _args[2]); vehicle_p _vehicle = std::make_shared<vehicle>(static_cast<uint32_t>(_args[1]), _object, _args[2]);
vehicles[static_cast<uint32_t>(_args[1])] = _vehicle; vehicles[static_cast<uint32_t>(_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()); DEBUG_DISPATCH("register_vehicle", _args[1].as_string());
return true; return true;
@ -133,6 +143,42 @@ namespace ace {
return true; 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<uint32_t>(_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) { bool controller::set_vehicle_state(const arguments &_args, std::string & result) {
if (_args.size() < 3) return false; if (_args.size() < 3) return false;
@ -142,7 +188,7 @@ namespace ace {
vehicles[_args[0]]->direction = _args[1]; vehicles[_args[0]]->direction = _args[1];
vehicles[_args[0]]->up = _args[2]; vehicles[_args[0]]->up = _args[2];
vehicles[_args[0]]->transform(); //vehicles[_args[0]]->transform();
return true; return true;
} }

View File

@ -29,9 +29,11 @@ namespace ace {
bool register_vehicle(const arguments &, std::string &); bool register_vehicle(const arguments &, std::string &);
bool delete_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 set_vehicle_state(const arguments &, std::string &);
bool handle_hit(const arguments & args, 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 get_thickness(const arguments &, std::string &);
bool selection_position(const arguments &, std::string &); bool selection_position(const arguments &, std::string &);
#ifdef _DEBUG #ifdef _DEBUG

View File

@ -44,13 +44,13 @@ namespace ace {
_BatchEffect.reset(new BasicEffect(_pd3dDevice)); _BatchEffect.reset(new BasicEffect(_pd3dDevice));
_BatchEffect->SetVertexColorEnabled(true); _BatchEffect->SetVertexColorEnabled(true);
{ {
void const* shaderByteCode; void const* shaderByteCode;
size_t byteCodeLength; size_t byteCodeLength;
_BatchEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength); _BatchEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength);
hr = _pd3dDevice->CreateInputLayout(VertexPositionColor::InputElements, hr = _pd3dDevice->CreateInputLayout(VertexPositionColor::InputElements,
VertexPositionColor::InputElementCount, VertexPositionColor::InputElementCount,
shaderByteCode, byteCodeLength, shaderByteCode, byteCodeLength,
@ -129,23 +129,15 @@ namespace ace {
ace::vector3<float> hit_from, hit_to; ace::vector3<float> hit_from, hit_to;
hit_from = hit->impactposition; 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 from = { hit_from.x(), hit_from.y(), hit_from.z() };
XMVECTORF32 to = { hit_to.x(), hit_to.y(), hit_to.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 v1(from, color);
VertexPositionColor v2(to, color); VertexPositionColor v2(to, color);
VertexPositionColor a1(to_a2, color);
VertexPositionColor a2(to_a1, color);
batch.DrawLine(v1, v2); batch.DrawLine(v1, v2);
batch.DrawLine(a1, v2);
batch.DrawLine(a2, v2);
} }
@ -156,13 +148,39 @@ namespace ace {
batch.Begin(); batch.Begin();
// Debug animation the shit
_active_vehicle->simulate();
/*for (auto & selection : obj.lods[lod]->selections) {
for (auto & face : selection.second->faces) {
ace::vector3<float> 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) { for (auto & face : obj.lods[lod]->faces) {
ace::vector3<float> vertices[3]; ace::vector3<float> vertices[3];
vertices[0] = { face->vertices[0]->x(), face->vertices[0]->y(), face->vertices[0]->z() }; 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[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() }; vertices[2] = { face->vertices[2]->x(), face->vertices[2]->y(), face->vertices[2]->z() };
XMVECTORF32 v[3] = { XMVECTORF32 v[3] = {
{ vertices[0].x(), vertices[0].y(), vertices[0].z() }, { vertices[0].x(), vertices[0].y(), vertices[0].z() },
{ vertices[1].x(), vertices[1].y(), vertices[1].z() }, { vertices[1].x(), vertices[1].y(), vertices[1].z() },