Skip to content

Commit 79bfb2b

Browse files
committed
Check if decorator exists before trying to get them
1 parent bfc2ee0 commit 79bfb2b

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

script.cpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,39 +1077,38 @@ void updateCameraDriverSeat() {
10771077
}
10781078
else
10791079
{
1080-
CAM::STOP_CAM_POINTING(customCam);
1081-
1082-
Vector3f rot = toV3f(ENTITY::GET_ENTITY_ROTATION(veh, 2));
1083-
Quaternionf rotQuat = getEntityQuaternion(veh);
1084-
//smoothRotSeat = Vector3fLerpAngle(smoothRotSeat, rot, clamp01(30.f * SYSTEM::TIMESTEP()));
1085-
//smoothRotSeat = Vector3fInertialDampAngle(smoothRotSeat, rot, 0.06f);
1086-
smoothRotSeat = Vector3fLerpAngle(smoothRotSeat, rot, clamp01(30.f * getDeltaTime()));
1087-
smoothQuatSeat = slerp(smoothQuatSeat, rotQuat, clamp01(30.f * getDeltaTime()));
1088-
1089-
if (smoothIsMouseLooking > 0.001f && btnLookingFactor < 0.001f) {
1090-
Vector3f gameplayCamRot = toV3f(CAM::GET_GAMEPLAY_CAM_ROT(2));
1091-
Vector3f finalRotSeat = Vector3fLerpAngle(smoothRotSeat, gameplayCamRot, smoothIsMouseLooking);
1092-
CAM::SET_CAM_ROT(customCam, finalRotSeat.x(), finalRotSeat.y(), finalRotSeat.z(), 2);
1093-
}
1094-
else
1095-
{
1096-
float leftRightAngle = RelativeLookFactor < 0 ?
1097-
lerp(0.f, -LookLeftAngle1p, -RelativeLookFactor)
1098-
:
1099-
lerp(0.f, LookRightAngle1p, RelativeLookFactor)
1100-
;
1080+
CAM::STOP_CAM_POINTING(customCam);
11011081

1102-
float leftRightRad = leftRightAngle * DEG_TO_RAD;
1082+
Vector3f rot = toV3f(ENTITY::GET_ENTITY_ROTATION(veh, 2));
1083+
Quaternionf rotQuat = getEntityQuaternion(veh);
1084+
//smoothRotSeat = Vector3fLerpAngle(smoothRotSeat, rot, clamp01(30.f * SYSTEM::TIMESTEP()));
1085+
//smoothRotSeat = Vector3fInertialDampAngle(smoothRotSeat, rot, 0.06f);
1086+
smoothRotSeat = Vector3fLerpAngle(smoothRotSeat, rot, clamp01(30.f * getDeltaTime()));
1087+
smoothQuatSeat = slerp(smoothQuatSeat, rotQuat, clamp01(30.f * getDeltaTime()));
11031088

1104-
float roll = 0.f, pitch = 0.f, yaw = leftRightRad;
1105-
Quaternionf qLookLeftRight;
1106-
qLookLeftRight = AngleAxisf(roll, Vector3f::UnitX())
1107-
* AngleAxisf(pitch, Vector3f::UnitY())
1108-
* AngleAxisf(yaw, Vector3f::UnitZ());
1089+
if (smoothIsMouseLooking > 0.001f && btnLookingFactor < 0.001f) {
1090+
Vector3f gameplayCamRot = toV3f(CAM::GET_GAMEPLAY_CAM_ROT(2));
1091+
Vector3f finalRotSeat = Vector3fLerpAngle(smoothRotSeat, gameplayCamRot, smoothIsMouseLooking);
1092+
CAM::SET_CAM_ROT(customCam, finalRotSeat.x(), finalRotSeat.y(), finalRotSeat.z(), 2);
1093+
}
1094+
else
1095+
{
1096+
float leftRightAngle = RelativeLookFactor < 0 ?
1097+
lerp(0.f, -LookLeftAngle1p, -RelativeLookFactor)
1098+
:
1099+
lerp(0.f, LookRightAngle1p, RelativeLookFactor)
1100+
;
11091101

1110-
SET_CAM_QUATERNION(customCam, smoothQuatSeat * qLookLeftRight);
1111-
}
1112-
1102+
float leftRightRad = leftRightAngle * DEG_TO_RAD;
1103+
1104+
float roll = 0.f, pitch = 0.f, yaw = leftRightRad;
1105+
Quaternionf qLookLeftRight;
1106+
qLookLeftRight = AngleAxisf(roll, Vector3f::UnitX())
1107+
* AngleAxisf(pitch, Vector3f::UnitY())
1108+
* AngleAxisf(yaw, Vector3f::UnitZ());
1109+
1110+
SET_CAM_QUATERNION(customCam, smoothQuatSeat * qLookLeftRight);
1111+
}
11131112
}
11141113

11151114
CAM::RENDER_SCRIPT_CAMS(true, false, 3000, 1, 0);
@@ -1119,10 +1118,10 @@ void ProccessLookLeftRightOrBackInput()
11191118
{
11201119
const float rotSpeed = 9.f;
11211120

1122-
bool evalLeft = IsKeyDown(str2key(lookLeftKey)) || (readInputFromMt && DECORATOR::DECOR_GET_BOOL(veh, (char *)"mt_looking_left"));
1123-
bool evalRight = IsKeyDown(str2key(lookRightKey)) || (readInputFromMt && DECORATOR::DECOR_GET_BOOL(veh, (char *)"mt_looking_right"));
1121+
bool evalLeft = IsKeyDown(str2key(lookLeftKey)) || (readInputFromMt && GetDecoratorBool("mt_looking_left"));
1122+
bool evalRight = IsKeyDown(str2key(lookRightKey)) || (readInputFromMt && GetDecoratorBool("mt_looking_right"));
11241123

1125-
isLookingBack = CONTROLS::IS_CONTROL_PRESSED(0, eControl::ControlVehicleLookBehind) || (readInputFromMt && DECORATOR::DECOR_GET_BOOL(veh, (char *)"mt_looking_back")) || (evalLeft && evalRight);
1124+
isLookingBack = CONTROLS::IS_CONTROL_PRESSED(0, eControl::ControlVehicleLookBehind) || (readInputFromMt && GetDecoratorBool("mt_looking_back")) || (evalLeft && evalRight);
11261125

11271126
if (evalLeft && !evalRight) {
11281127
RelativeLookFactor += rotSpeed * getDeltaTime();
@@ -1141,6 +1140,11 @@ void ProccessLookLeftRightOrBackInput()
11411140
RelativeLookFactor = clamp(RelativeLookFactor, -1.f, 1.f);
11421141
}
11431142

1143+
BOOL GetDecoratorBool(char * decoratorKey)
1144+
{
1145+
return DECORATOR::DECOR_IS_REGISTERED_AS_TYPE(decoratorKey, eDecorType::DECOR_TYPE_BOOL) && DECORATOR::DECOR_EXIST_ON(veh, decoratorKey) && DECORATOR::DECOR_GET_BOOL(veh, (char *)decoratorKey);
1146+
}
1147+
11441148
void lookBehind1p()
11451149
{
11461150
Vector3f camPos;

script.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ void lookBehind1p();
4646

4747
void ProccessLookLeftRightOrBackInput();
4848

49+
BOOL GetDecoratorBool(char * decoratorKey);
50+
4951
Vector3f GetBonePos(Entity entity, char * boneName);
5052

5153
void updateVehicleProperties();
@@ -62,6 +64,14 @@ void setGameplayCameraDirection(Vector3f dir);
6264

6365
Vector3f getCameraForwardVector(Camera cam);
6466

67+
enum eDecorType {
68+
DECOR_TYPE_FLOAT = 1,
69+
DECOR_TYPE_BOOL,
70+
DECOR_TYPE_INT,
71+
DECOR_TYPE_UNK,
72+
DECOR_TYPE_TIME
73+
};
74+
6575
const char* const vehicleBones[] =
6676
{
6777
"chassis",

0 commit comments

Comments
 (0)