Skip to content

Commit 7c23bfc

Browse files
committed
Expose more parameters for vehicles
1 parent 51df43d commit 7c23bfc

File tree

13 files changed

+497
-369
lines changed

13 files changed

+497
-369
lines changed

data/Prefabs/Cars/Compact.prefab

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<Property type="String" name="m_name" value="New PhysicsBodyComponent"/>
3131
<Property type="Uint32" name="m_uid" value="2416209307"/>
3232
<Property type="Uint32" name="m_originalUID" value="0"/>
33-
<Property type="EnumFlagsU16" name="m_objectFlags" value="Opened"/>
33+
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
3434
<Property type="EnumFlagsU32" name="m_flags" value="Enabled"/>
3535
<Property type="EnumU8" name="m_category" value="Default"/>
3636
<Property type="Bool" name="m_useCollisionMask" value="false"/>
@@ -133,7 +133,7 @@
133133
<Property type="String" name="m_name" value="New SoundComponent"/>
134134
<Property type="Uint32" name="m_uid" value="729544579"/>
135135
<Property type="Uint32" name="m_originalUID" value="0"/>
136-
<Property type="EnumFlagsU16" name="m_objectFlags" value="Opened"/>
136+
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
137137
<Property type="EnumFlagsU32" name="m_flags" value="Enabled"/>
138138
<Property type="Object" name="m_sounds">
139139
<Object class="SoundResourceList">
@@ -180,7 +180,7 @@
180180
<Property type="String" name="m_name" value="New VehicleComponent"/>
181181
<Property type="Uint32" name="m_uid" value="2480422006"/>
182182
<Property type="Uint32" name="m_originalUID" value="0"/>
183-
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
183+
<Property type="EnumFlagsU16" name="m_objectFlags" value="Opened"/>
184184
<Property type="EnumFlagsU32" name="m_flags" value="Enabled"/>
185185
<Property type="Object" name="m_slots">
186186
<Object class="VehicleSlotList">
@@ -220,66 +220,37 @@
220220
</Property>
221221
</Object>
222222
</Property>
223+
<Property type="EnumU8" name="m_vehicleType" value="FourWheels"/>
223224
<Property type="ObjectPtr" name="m_vehicleConstraintDesc">
224-
<Object class="VehicleConstraintDesc">
225-
<Property type="String" name="m_name" value="VehicleConstraintDesc #0"/>
226-
<Property type="Uint32" name="m_uid" value="2933566650"/>
225+
<Object class="FourWheelsVehicleConstraintDesc">
226+
<Property type="String" name="m_name" value="FourWheelsVehicleConstraintDesc #4"/>
227+
<Property type="Uint32" name="m_uid" value="1656513048"/>
227228
<Property type="Uint32" name="m_originalUID" value="0"/>
228229
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
229230
<Property type="Bool" name="m_fourWheelDrive" value="false"/>
230-
<Property type="Float" name="m_maxPitchRollAngleInDegrees" value="3.1415927"/>
231-
<Property type="Object" name="m_wheelDescList">
232-
<Object class="VehicleWheelDescList">
231+
<Property type="Float" name="m_maxPitchRollAngleInDegrees" value="180"/>
232+
<Property type="Object" name="m_front">
233+
<Object class="VehicleAxleDesc">
233234
<Property type="String" name="m_name" value=""/>
234-
<Property type="Uint32" name="m_uid" value="1079280484"/>
235+
<Property type="Uint32" name="m_uid" value="2853335957"/>
235236
<Property type="Uint32" name="m_originalUID" value="0"/>
236237
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
237-
<Property type="ObjectVector" name="m_objects">
238-
<Object class="VehicleWheelDesc">
239-
<Property type="String" name="m_name" value="FrontLeft"/>
240-
<Property type="Uint32" name="m_uid" value="1382757690"/>
241-
<Property type="Uint32" name="m_originalUID" value="0"/>
242-
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
243-
<Property type="ObjectHandle" name="m_object" value="81703785"/>
244-
<Property type="EnumU8" name="m_axle" value="Front"/>
245-
<Property type="EnumU8" name="m_side" value="Left"/>
246-
<Property type="Float" name="m_radius" value="0.34999999"/>
247-
<Property type="Float" name="m_width" value="0.2"/>
248-
</Object>
249-
<Object class="VehicleWheelDesc">
250-
<Property type="String" name="m_name" value="FrontRight"/>
251-
<Property type="Uint32" name="m_uid" value="2582773578"/>
252-
<Property type="Uint32" name="m_originalUID" value="0"/>
253-
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
254-
<Property type="ObjectHandle" name="m_object" value="335609367"/>
255-
<Property type="EnumU8" name="m_axle" value="Front"/>
256-
<Property type="EnumU8" name="m_side" value="Right"/>
257-
<Property type="Float" name="m_radius" value="0.34999999"/>
258-
<Property type="Float" name="m_width" value="0.2"/>
259-
</Object>
260-
<Object class="VehicleWheelDesc">
261-
<Property type="String" name="m_name" value="RearLeft"/>
262-
<Property type="Uint32" name="m_uid" value="359660446"/>
263-
<Property type="Uint32" name="m_originalUID" value="0"/>
264-
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
265-
<Property type="ObjectHandle" name="m_object" value="1290695824"/>
266-
<Property type="EnumU8" name="m_axle" value="Rear"/>
267-
<Property type="EnumU8" name="m_side" value="Left"/>
268-
<Property type="Float" name="m_radius" value="0.34999999"/>
269-
<Property type="Float" name="m_width" value="0.2"/>
270-
</Object>
271-
<Object class="VehicleWheelDesc">
272-
<Property type="String" name="m_name" value="RearRight"/>
273-
<Property type="Uint32" name="m_uid" value="1025073595"/>
274-
<Property type="Uint32" name="m_originalUID" value="0"/>
275-
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
276-
<Property type="ObjectHandle" name="m_object" value="1534622751"/>
277-
<Property type="EnumU8" name="m_axle" value="Rear"/>
278-
<Property type="EnumU8" name="m_side" value="Right"/>
279-
<Property type="Float" name="m_radius" value="0.34999999"/>
280-
<Property type="Float" name="m_width" value="0.2"/>
281-
</Object>
282-
</Property>
238+
<Property type="Float" name="m_radius" value="0.34999999"/>
239+
<Property type="Float" name="m_width" value="0.2"/>
240+
<Property type="ObjectHandle" name="m_leftWheel" value="81703785"/>
241+
<Property type="ObjectHandle" name="m_rightWheel" value="335609367"/>
242+
</Object>
243+
</Property>
244+
<Property type="Object" name="m_rear">
245+
<Object class="VehicleAxleDesc">
246+
<Property type="String" name="m_name" value=""/>
247+
<Property type="Uint32" name="m_uid" value="892460903"/>
248+
<Property type="Uint32" name="m_originalUID" value="0"/>
249+
<Property type="EnumFlagsU16" name="m_objectFlags" value=""/>
250+
<Property type="Float" name="m_radius" value="0.34999999"/>
251+
<Property type="Float" name="m_width" value="0.2"/>
252+
<Property type="ObjectHandle" name="m_leftWheel" value="1290695824"/>
253+
<Property type="ObjectHandle" name="m_rightWheel" value="1534622751"/>
283254
</Object>
284255
</Property>
285256
</Object>

src/core/IClassDesc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace vg::core
2626
SceneNode = 0x0000000000000080,
2727
Plugin = 0x0000000000000100,
2828
UID = 0x0000000000000200,
29+
Abstract = 0x0000000000000400,
2930
Hidden = 0x0000000000004000
3031
};
3132

src/core/Object/AutoRegisterClass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
return false; \
1818
}
1919

20-
#define VG_REGISTER_ABSTRACT_CLASS(className, displayName) VG_REGISTER_ABSTRACT_CLASS_EX(className, displayName, vg::core::ClassDescFlags::None)
20+
#define VG_REGISTER_ABSTRACT_CLASS(className, displayName) VG_REGISTER_ABSTRACT_CLASS_EX(className, displayName, vg::core::ClassDescFlags::Abstract)
2121

2222
#define VG_REGISTER_OBJECT_CLASS_EX(className, displayName, flags) vg::core::AutoRegisterObjectClassHelper<className> autoRegister##className(#className, className::registerClass); \
2323
bool className::registerClass(vg::core::IFactory & _factory) \

src/core/Object/Factory.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@ namespace vg::core
220220

221221
if (desc)
222222
{
223-
VG_ASSERT(!asBool(ClassDescFlags::Singleton & desc->GetFlags()));
223+
VG_ASSERT(!asBool(ClassDescFlags::Singleton & desc->GetFlags()), "[Factory] Cannot instanciate singleton class \"%s\"", _className);
224+
VG_ASSERT(!asBool(ClassDescFlags::Abstract & desc->GetFlags()), "[Factory] Cannot instanciate abstract class \"%s\"", _className);
225+
226+
if (asBool((ClassDescFlags::Singleton | ClassDescFlags::Abstract) & desc->GetFlags()))
227+
return nullptr;
228+
224229
IObject * obj = desc->GetCreateFunc()(_name, _parent);
225230

226231
const auto index = desc->GetNextIndex();

src/engine/Component/Physics/Constraint/Vehicle/VehicleComponent.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ namespace vg::engine
6969
private:
7070
physics::DriveState m_driveState;
7171
core::float3 m_localVelocity = (core::float3)0.0f;
72+
float m_speedInKmPerHour = 0.0f;
73+
float m_engineRPM = 0.0f;
74+
int m_currentGear = 0;
75+
7276
physics::IVehicleConstraintDesc * m_vehicleConstraintDesc = nullptr;
77+
physics::VehicleType m_vehicleType = physics::VehicleType::FourWheels;
7378
physics::IVehicleConstraint * m_vehicleConstraint = nullptr;
7479
VehicleSlotList m_slots;
7580
core::float4x4 m_startPos = core::float4x4::identity();

src/engine/Component/Physics/Constraint/Vehicle/VehicleComponent.hpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,21 @@ namespace vg::engine
7070
setPropertyDescription(VehicleComponent, m_driveState.m_handBrake, "Value between 0 and 1 indicating how strong the hand brake is pulled");
7171
setPropertyRange(VehicleComponent, m_driveState.m_handBrake, float2(0, +1));
7272

73-
registerPropertyEx(VehicleComponent, m_localVelocity, "Local velocity", PropertyFlags::Transient | PropertyFlags::ReadOnly);
73+
registerPropertyEx(VehicleComponent, m_speedInKmPerHour, "Velocity", PropertyFlags::Transient | PropertyFlags::ReadOnly);
74+
setPropertyDescription(VehicleComponent, m_speedInKmPerHour, "Current speed in km/h");
75+
76+
registerPropertyEx(VehicleComponent, m_localVelocity, "Local Velocity", PropertyFlags::Transient | PropertyFlags::ReadOnly);
77+
78+
registerPropertyEx(VehicleComponent, m_engineRPM, "RPM", PropertyFlags::Transient | PropertyFlags::ReadOnly);
79+
setPropertyDescription(VehicleComponent, m_engineRPM, "Current engine Rotation Per Minute");
80+
81+
registerPropertyEx(VehicleComponent, m_currentGear, "Gear", PropertyFlags::Transient | PropertyFlags::ReadOnly);
7482

7583
registerPropertyObject(VehicleComponent, m_slots, "Slots");
7684

7785
registerPropertyGroupBegin(VehicleComponent, "Contraints");
7886
{
87+
registerPropertyEnum(VehicleComponent, physics::VehicleType, m_vehicleType, "Type");
7988
registerPropertyObjectPtrEx(VehicleComponent, m_vehicleConstraintDesc, "Constraints", PropertyFlags::Flatten);
8089
}
8190
registerPropertyGroupEnd(VehicleComponent);
@@ -136,7 +145,16 @@ namespace vg::engine
136145
{
137146
IFactory * factory = Kernel::getFactory();
138147

139-
m_vehicleConstraintDesc = (physics::IVehicleConstraintDesc *)factory->CreateObject("VehicleConstraintDesc", "", this);
148+
switch (m_vehicleType)
149+
{
150+
default:
151+
VG_ASSERT_ENUM_NOT_IMPLEMENTED(m_vehicleType);
152+
break;
153+
154+
case physics::VehicleType::FourWheels:
155+
m_vehicleConstraintDesc = (physics::IVehicleConstraintDesc *)factory->CreateObject("FourWheelsVehicleConstraintDesc", "", this);
156+
break;
157+
}
140158

141159
if (m_vehicleConstraintDesc)
142160
{
@@ -230,18 +248,26 @@ namespace vg::engine
230248
if (m_vehicleConstraint)
231249
{
232250
m_vehicleConstraint->Update(m_driveState);
251+
IGameObject * go = GetGameObject();
233252

234253
// Update local velocity
235-
if (IPhysicsBodyComponent * bodyComp = GetGameObject()->GetComponentT<IPhysicsBodyComponent>())
254+
if (IPhysicsBodyComponent * bodyComp = go->GetComponentT<IPhysicsBodyComponent>())
236255
{
237256
const float3 velocity = bodyComp->GetLinearVelocity();
238257

239-
m_localVelocity.x = dot(velocity, GetGameObject()->GetGlobalMatrix()[0].xyz);
240-
m_localVelocity.y = dot(velocity, GetGameObject()->GetGlobalMatrix()[1].xyz);
241-
m_localVelocity.z = dot(velocity, GetGameObject()->GetGlobalMatrix()[2].xyz);
258+
const float4x4 mat = go->GetGlobalMatrix();
259+
260+
m_localVelocity.x = dot(velocity, mat[0].xyz);
261+
m_localVelocity.y = dot(velocity, mat[1].xyz);
262+
m_localVelocity.z = dot(velocity, mat[2].xyz);
263+
264+
m_speedInKmPerHour = length(velocity) * 60.0f * 60.0f / 1000.0f; // m/s to km/h
265+
266+
m_engineRPM = m_vehicleConstraint->GetEngineRPM();
267+
m_currentGear = m_vehicleConstraint->GetCurrentGear();
242268
}
243269

244-
if (ISoundComponent * sound = GetGameObject()->GetComponentT<ISoundComponent>())
270+
if (ISoundComponent * sound = go->GetComponentT<ISoundComponent>())
245271
{
246272
// Engine
247273
{

0 commit comments

Comments
 (0)