ksys/phys: Add CharacterControllerParam shape creation

This commit is contained in:
Léo Lam 2022-02-13 19:26:28 +01:00
parent dfcfbbe4a4
commit a6268d3815
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
4 changed files with 147 additions and 13 deletions

View File

@ -94786,9 +94786,9 @@ Address,Quality,Size,Name
0x0000007101281318,O,000420,_ZN4ksys4phys24CharacterControllerParam4Form5parseEN3agl3utl16ResParameterListEPN4sead4HeapE
0x00000071012814bc,U,000112,phys::CharacterControllerParam::createController
0x000000710128152c,U,000732,phys::CharacterControllerParam::createControllerState
0x0000007101281808,O,000116,_ZN4ksys4phys24CharacterControllerParam10createFormEiPN4sead4HeapE
0x000000710128187c,U,002128,phys::CharacterControllerParam::Form::createForm
0x00000071012820cc,O,000120,_ZThn72_N4ksys4phys24CharacterControllerParam10createFormEiPN4sead4HeapE
0x0000007101281808,O,000116,_ZN4ksys4phys24CharacterControllerParam11createShapeEiPN4sead4HeapE
0x000000710128187c,O,002128,_ZNK4ksys4phys24CharacterControllerParam4Form11createShapeEPN4sead4HeapE
0x00000071012820cc,O,000120,_ZThn72_N4ksys4phys24CharacterControllerParam11createShapeEiPN4sead4HeapE
0x0000007101282144,O,000544,_ZN4ksys4phys24CharacterControllerParam4FormC1Ev
0x0000007101282364,O,000168,_ZN4ksys4phys24CharacterControllerParam4FormD1Ev
0x000000710128240c,O,000112,_ZN4ksys4phys24CharacterControllerParam4FormD0Ev

Can't render this file because it is too large.

View File

@ -8,9 +8,9 @@ namespace ksys::phys {
class PolytopeShape;
struct CharacterPrismShapeParam {
float radius;
sead::Vector3f translate_0;
sead::Vector3f translate_1;
float radius = 0.35;
sead::Vector3f translate_0 = {0.5, 1.5, 1.8};
sead::Vector3f translate_1 = sead::Vector3f::zero;
CommonShapeParam common;
};

View File

@ -1,5 +1,15 @@
#include "KingSystem/Physics/System/physCharacterControllerParam.h"
#include <basis/seadRawPrint.h>
#include "KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.h"
#include "KingSystem/Physics/RigidBody/Shape/Capsule/physCapsuleShape.h"
#include "KingSystem/Physics/RigidBody/Shape/CharacterPrism/physCharacterPrismShape.h"
#include "KingSystem/Physics/RigidBody/Shape/Cylinder/physCylinderShape.h"
#include "KingSystem/Physics/RigidBody/Shape/List/physListShape.h"
#include "KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeShape.h"
#include "KingSystem/Physics/RigidBody/Shape/Sphere/physSphereShape.h"
#include "KingSystem/Physics/RigidBody/Shape/physShape.h"
#include "KingSystem/Physics/RigidBody/Shape/physShapeParamObj.h"
#include "KingSystem/Utils/SafeDelete.h"
namespace ksys::phys {
@ -66,10 +76,10 @@ bool CharacterControllerParam::parse(agl::utl::ResParameterList res_list, sead::
return true;
}
void* CharacterControllerParam::createForm(int form_idx, sead::Heap* heap) {
Shape* CharacterControllerParam::createShape(int form_idx, sead::Heap* heap) {
if (form_idx >= getNumForms() || form_idx < 0)
return nullptr;
return forms[form_idx].createForm(heap);
return forms[form_idx].createShape(heap);
}
CharacterControllerParam::Form::Form()
@ -102,6 +112,131 @@ bool CharacterControllerParam::Form::parse(agl::utl::ResParameterList res_list,
return true;
}
Shape* CharacterControllerParam::Form::createShape(sead::Heap* heap) const {
if (*shape_num == 1) {
switch (shape_params[0].getShapeType()) {
case ShapeType::Sphere: {
SphereShapeParam param;
shape_params[0].getSphere(&param);
return SphereShape::make(param, heap);
}
case ShapeType::Capsule: {
CapsuleShapeParam param;
shape_params[0].getCapsule(&param);
return CapsuleShape::make(param, heap);
}
case ShapeType::Box: {
BoxShapeParam param;
shape_params[0].getBox(&param);
return BoxShape::make(param, heap);
}
case ShapeType::Cylinder: {
CylinderShapeParam param;
shape_params[0].getCylinder(&param);
return CylinderShape::make(param, heap);
}
case ShapeType::Polytope: {
PolytopeShapeParam param;
shape_params[0].getPolytope(&param);
auto* shape = PolytopeShape::make(param, heap);
for (int i = 0, n = *shape_params[0].vertex_num; i < n; ++i) {
shape->setVertex(i, *shape_params[0].vertices[i]);
}
shape->updateHavokShape();
return shape;
}
case ShapeType::CharacterPrism: {
CharacterPrismShapeParam param;
shape_params[0].getCharacterPrism(&param);
return CharacterPrismShape::make(param, heap);
}
case ShapeType::List:
case ShapeType::BoxWater:
case ShapeType::CylinderWater:
case ShapeType::Unknown:
break;
}
SEAD_ASSERT_MSG(false, "unsupported shape type for CharacterController with one shape");
return nullptr;
}
ListShapeParam list_param;
list_param.num_shapes = static_cast<decltype(list_param.num_shapes)>(*shape_num);
auto* list_shape = ListShape::make(list_param, heap);
for (int i = 0; i < int(list_param.num_shapes); ++i) {
switch (shape_params[i].getShapeType()) {
case ShapeType::Sphere: {
SphereShapeParam param;
shape_params[i].getSphere(&param);
list_shape->replaceWithNewSphere(i, param, heap);
continue;
}
case ShapeType::Capsule: {
CapsuleShapeParam param;
shape_params[i].getCapsule(&param);
list_shape->replaceWithNewCapsule(i, param, heap);
continue;
}
case ShapeType::Box: {
BoxShapeParam param;
shape_params[i].getBox(&param);
list_shape->replaceWithNewBox(i, param, heap);
continue;
}
case ShapeType::Cylinder: {
CylinderShapeParam param;
shape_params[i].getCylinder(&param);
list_shape->replaceWithNewCylinder(i, param, heap);
continue;
}
case ShapeType::Polytope: {
PolytopeShapeParam param;
shape_params[i].getPolytope(&param);
auto* shape =
static_cast<PolytopeShape*>(list_shape->replaceWithNewPolytope(i, param, heap));
for (int vertex = 0, n = *shape_params[i].vertex_num; vertex < n; ++vertex) {
shape->setVertex(vertex, *shape_params[i].vertices[vertex]);
}
shape->updateHavokShape();
continue;
}
case ShapeType::CharacterPrism: {
CharacterPrismShapeParam param;
shape_params[i].getCharacterPrism(&param);
list_shape->replaceWithNewCharacterPrism(i, param, heap);
continue;
}
case ShapeType::List:
case ShapeType::BoxWater:
case ShapeType::CylinderWater:
case ShapeType::Unknown:
break;
}
SEAD_ASSERT_MSG(false, "unsupported child shape type for CharacterController");
util::safeDelete(list_shape);
return nullptr;
}
list_shape->updateHavokShape();
return list_shape;
}
int CharacterControllerParam::findFormIdx(const sead::SafeString& form_type) const {
for (int i = 0, n = forms.size(); i < n; ++i) {
if (form_type == *forms[i].form_type)

View File

@ -8,6 +8,7 @@
namespace ksys::phys {
class Shape;
struct ShapeParamObj;
SEAD_ENUM(NavMeshCharacterType,
@ -37,8 +38,7 @@ bool navMeshCharacterTypeFromText(NavMeshCharacterType& value, const sead::SafeS
struct ICharacterControllerParam {
virtual int getNumForms() = 0;
// TODO: return type
virtual void* createForm(int form_idx, sead::Heap* heap) = 0;
virtual Shape* createShape(int form_idx, sead::Heap* heap) = 0;
};
struct CharacterControllerParam : agl::utl::ParameterList, ICharacterControllerParam {
@ -50,8 +50,7 @@ struct CharacterControllerParam : agl::utl::ParameterList, ICharacterControllerP
bool parse(agl::utl::ResParameterList res_list, sead::Heap* heap);
// TODO: return type
void* createForm(sead::Heap* heap);
Shape* createShape(sead::Heap* heap) const;
agl::utl::ParameterObj form_header_obj;
agl::utl::Parameter<int> shape_num;
@ -65,7 +64,7 @@ struct CharacterControllerParam : agl::utl::ParameterList, ICharacterControllerP
auto operator=(const CharacterControllerParam&) = delete;
int getNumForms() override { return forms.size(); }
void* createForm(int form_idx, sead::Heap* heap) override;
Shape* createShape(int form_idx, sead::Heap* heap) override;
// TODO: return type
void* createController(sead::Heap* heap);