Skip to content

Commit

Permalink
Merge branch 'master' into conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
yukani authored Nov 22, 2023
2 parents fde2405 + a8ea950 commit 853a613
Show file tree
Hide file tree
Showing 55 changed files with 1,361 additions and 440 deletions.
190 changes: 182 additions & 8 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,10 +1,184 @@
Language: Cpp
PointerAlignment: Left
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: Left
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignEscapedNewlines: Right
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
AlignOperands: DontAlign
BreakBeforeBinaryOperators: NonAssignment
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: false
SplitEmptyNamespace: true
BreakAfterAttributes: Never
BreakBeforeTernaryOperators: true
BreakAfterJavaFieldAnnotations: false
BreakArrays: true
BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakConstructorInitializers: AfterColon
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
IndentWrappedFunctionNames: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
IncludeBlocks: Preserve
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: false
IndentPPDirectives: BeforeHash
IndentRequiresClause: true
IndentWidth: 4
ColumnLimit: 180
SortIncludes: false
AccessModifierOffset: -4
AllowShortFunctionsOnASingleLine: Empty
#AlignConsecutiveDeclarations: true
IndentWrappedFunctionNames: false
InsertBraces: true
InsertNewlineAtEOF: true
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 4
Decimal: 3
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
Language: Cpp
LineEnding: DeriveLF
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PPIndentWidth: -1
PackConstructorInitializers: Never
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
QualifierAlignment: Left
ReferenceAlignment: Pointer
ReflowComments: false
RemoveBracesLLVM: false
RemoveSemicolon: true
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 1
SortIncludes: Never
SortUsingDeclarations: Never
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDeclarationName: false
AfterFunctionDefinitionName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 4
UseTab: Never
WhitespaceSensitiveMacros:
- RwRenderStateSet
- RwRenderStateGet
- RH_ScopedOverloadedInstall
- RH_ScopedInstall
- RH_ScopedVMTInstall
- RH_ScopedVirtualInstall
- RH_ScopedGlobalInstall

# VS's clang-format is not up-to-date enough for this yet
#AlignConsecutiveShortCaseStatements:
# Enabled: true
# AcrossEmptyLines: true
# AcrossComments: true
# AlignCaseColons: false
8 changes: 5 additions & 3 deletions source/InjectHooksMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
#include "TaskComplexCrossRoadLookAndAchieveHeading.h"
#include "TaskComplexGoToPointAndStandStill.h"
#include "TaskSimpleAchieveHeading.h"
#include "TaskSimpleCarGoToPointNearDoorUntilDoorNotInUse.h"
#include "TaskSimpleGiveCPR.h"
#include "TaskSimpleCarSetPedInAsPassenger.h"
#include "TaskComplexDriveFireTruck.h"
Expand All @@ -262,6 +263,7 @@
#include "TaskComplexPassObject.h"
#include "TaskComplexEnterCarAsPassenger.h"
#include "TaskComplexEnterCarAsDriver.h"
#include "TaskSimpleCarShuffle.h"
#include "TaskComplexReactToGunAimedAt.h"
#include "TaskSimpleNone.h"
#include "TaskComplexKillPedOnFoot.h"
Expand Down Expand Up @@ -948,13 +950,13 @@ void InjectHooksMain() {
// CTaskSimpleCarForcePedOut::InjectHooks();
CTaskSimpleCarGetOut::InjectHooks();
CTaskSimpleCarGetIn::InjectHooks();
// CTaskSimpleCarGoToPointNearDoorUntilDoorNotInUse::InjectHooks();
CTaskSimpleCarGoToPointNearDoorUntilDoorNotInUse::InjectHooks();
CTaskSimpleCarOpenDoorFromOutside::InjectHooks();
CTaskSimpleCarJumpOut::InjectHooks();
CTaskSimpleCarOpenLockedDoorFromOutside::InjectHooks();
// CTaskSimpleCarSetPedSlowDraggedOut::InjectHooks();
CTaskSimpleCarSetTempAction::InjectHooks();
// CTaskSimpleCarShuffle::InjectHooks();
CTaskSimpleCarShuffle::InjectHooks();
// CTaskSimpleCarSlowBeDraggedOut::InjectHooks();
CTaskSimpleCarWaitToSlowDown::InjectHooks();
CTaskSimpleCarWaitForDoorNotToBeInUse::InjectHooks();
Expand Down Expand Up @@ -1122,7 +1124,7 @@ void InjectHooksMain() {
CTaskSimpleIKPointArm::InjectHooks();
CTaskSimpleIKLookAt::InjectHooks();
CTaskComplexDie::InjectHooks();
// CTaskComplexEnterBoatAsDriver::InjectHooks();
CTaskComplexEnterBoatAsDriver::InjectHooks();
CTaskSimpleFight::InjectHooks();
CTaskComplexUseWaterCannon::InjectHooks();
// CTaskComplexDriveToPoint::InjectHooks();
Expand Down
6 changes: 4 additions & 2 deletions source/game_sa/Animation/AnimBlendAssociation.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ struct SClumpAnimAssoc {
int16 m_nAnimId;
uint16 m_nFlags; // TODO: use bitfield

float GetTimeProgress() const;
float GetBlendAmount(float weight) const { return IsPartial() ? m_fBlendAmount : m_fBlendAmount * weight; }
float GetTimeProgress() const;
float GetBlendAmount(float weight = 1.f) const { return IsPartial() ? m_fBlendAmount : m_fBlendAmount * weight; }

[[nodiscard]] bool IsRunning() const { return (m_nFlags & ANIMATION_STARTED) != 0; }
[[nodiscard]] bool IsRepeating() const { return (m_nFlags & ANIMATION_LOOPED) != 0; }
[[nodiscard]] bool IsPartial() const { return (m_nFlags & ANIMATION_PARTIAL) != 0; }
Expand Down Expand Up @@ -120,6 +121,7 @@ class NOTSA_EXPORT_VTABLE CAnimBlendAssociation : public SClumpAnimAssoc {
void Init(CAnimBlendStaticAssociation& source);

void ReferenceAnimBlock();
void SetBlendDelta(float value) { m_fBlendDelta = value; }
void SetBlend(float blendAmount, float blendDelta);
void SetBlendTo(float blendAmount, float blendDelta);
void SetCurrentTime(float currentTime);
Expand Down
8 changes: 6 additions & 2 deletions source/game_sa/Audio/AESound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ void CAESound::UpdatePlayTime(int16 soundLength, int16 loopStartTime, int16 play
return;
}

assert(soundLength > 0);
m_nCurrentPlayPosition = loopStartTime + (m_nCurrentPlayPosition % soundLength);
// Avoid division by 0
// This seems to have been fixed the same way in Android
// The cause is/can be missing audio files, but I'm lazy to fix it, so this is gonna be fine for now
m_nCurrentPlayPosition = !notsa::IsFixBugs() || soundLength > 0
? loopStartTime + (m_nCurrentPlayPosition % soundLength)
: loopStartTime;
}

// 0x4EF350
Expand Down
3 changes: 1 addition & 2 deletions source/game_sa/Audio/entities/AECollisionAudioEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ void CAECollisionAudioEntity::AddCollisionSoundToList(CEntity* entity1, CEntity*
});

if (newEntry == m_Entries.end()) {
// Game tries to access m_Entries[300] in this case.
NOTSA_UNREACHABLE();
return;
}

// ? check
Expand Down
12 changes: 6 additions & 6 deletions source/game_sa/Collision/CollisionData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ CLink<CCollisionData*>* CCollisionData::GetLinkPtr() {
}

auto CCollisionData::GetNumFaceGroups() const -> uint32 {
// See `CCollisionData` header for explanation :)
assert(!bHasFaceGroups || m_pTriangles);
return bHasFaceGroups
? *reinterpret_cast<uint32*>(reinterpret_cast<uint8*>(m_pTriangles) - sizeof(uint32))
: 0u;
if (bHasFaceGroups) {
assert(m_pTriangles);
return *reinterpret_cast<uint32*>(reinterpret_cast<byte*>(m_pTriangles) - sizeof(uint32)); // See `CCollisionData` header for explanation :)
}
return 0;
}

auto CCollisionData::GetFaceGroups() const -> std::span<ColHelpers::TFaceGroup> {
Expand All @@ -249,7 +249,7 @@ auto CCollisionData::GetFaceGroups() const -> std::span<ColHelpers::TFaceGroup>

auto CCollisionData::GetTriVertices(const CColTriangle& tri) const->std::array<CVector, 3> {
std::array<CVector, 3> verts;
for (const auto [i, j] : notsa::enumerate(tri.m_vertIndices)) {
for (auto&& [i, j] : notsa::enumerate(tri.m_vertIndices)) {
verts[i] = UncompressVector(m_pVertices[j]);
}
return verts;
Expand Down
5 changes: 5 additions & 0 deletions source/game_sa/Core/Pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ template <class A, class B = A, bool DontDebugCheckAlloc = false> class CPool {

// Deallocates object
void Delete(A* obj) {
#ifdef FIX_BUGS // C++ says that `delete nullptr` is well defined, and should do nothing.
if (!obj) {
return;
}
#endif
int32 index = GetIndex(obj);
m_byteMap[index].bEmpty = true;
if (index < m_nFirstFree)
Expand Down
4 changes: 2 additions & 2 deletions source/game_sa/Core/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ class CVector : public RwV3d {

//! Get a copy of `*this` vector projected onto `projectOnTo` (which is assumed to be unit length)
//! The result will have a magnitude of `sqrt(abs(this->Dot(projectOnTo)))`
CVector ProjectOnToNormal(const CVector& projectOnTo) const {
return projectOnTo * Dot(projectOnTo);
CVector ProjectOnToNormal(const CVector& projectOnTo, float offset = 0.f) const {
return projectOnTo * (Dot(projectOnTo) + offset);
}

//! Calculate the average position
Expand Down
2 changes: 2 additions & 0 deletions source/game_sa/Events/EventDamage.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class NOTSA_EXPORT_VTABLE CEventDamage : public CEventEditableResponse {
CPedDamageResponse m_damageResponse;

public:
static constexpr auto Type = eEventType::EVENT_DAMAGE;

CEventDamage(const CEventDamage& event);
CEventDamage(CEntity* source, uint32 startTime, eWeaponType weaponType, ePedPieceTypes pieceHit, uint8 direction, bool a7, bool bPedInVehicle);
~CEventDamage() override;
Expand Down
2 changes: 1 addition & 1 deletion source/game_sa/PathFind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void CPathFind::Init() {
m_nNumForbiddenAreas = 0;
m_loadAreaRequestPending = false;

for (auto i = 0u; i < NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS; ++i) {
for (auto i = 0u; i < NUM_TOTAL_PATH_NODE_AREAS; ++i) {
m_pPathNodes[i] = nullptr;
m_pNaviNodes[i] = nullptr;
m_pNodeLinks[i] = nullptr;
Expand Down
22 changes: 11 additions & 11 deletions source/game_sa/PathFind.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,21 @@ class CPathFind {
* The first part of the array has the vehicle nodes (count: `m_anNumVehicleNodes`)
* the remaining part has ped nodes (count: `m_anNumPedNodes`)
*/
CPathNode* m_pPathNodes[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS]; // 0x804
CPathNode* m_pPathNodes[NUM_TOTAL_PATH_NODE_AREAS]; // 0x804

// Use CPathFind::GetCarPathLink to access
CCarPathLink* m_pNaviNodes[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS]; // 0x924
CNodeAddress* m_pNodeLinks[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS]; // 0xA44
uint8* m_pLinkLengths[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS]; // 0xB64
CPathIntersectionInfo* m_pPathIntersections[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS]; // 0xC84
CCarPathLink* m_pNaviNodes[NUM_TOTAL_PATH_NODE_AREAS]; // 0x924
CNodeAddress* m_pNodeLinks[NUM_TOTAL_PATH_NODE_AREAS]; // 0xA44
uint8* m_pLinkLengths[NUM_TOTAL_PATH_NODE_AREAS]; // 0xB64
CPathIntersectionInfo* m_pPathIntersections[NUM_TOTAL_PATH_NODE_AREAS]; // 0xC84
CCarPathLinkAddress* m_pNaviLinks[NUM_PATH_MAP_AREAS]; // 0xDA4
void* m_aUnused[22]; // 0xEA4
uint32 m_aUnk[NUM_PATH_MAP_AREAS - 22]; // 0xEFC
uint32 m_anNumNodes[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS]; // 0xFA4
uint32 m_anNumVehicleNodes[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS]; // 0x10C4
uint32 m_anNumPedNodes[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS]; // 0x11E4
uint32 m_anNumCarPathLinks[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS];
uint32 m_anNumAddresses[NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS];
uint32 m_anNumNodes[NUM_TOTAL_PATH_NODE_AREAS]; // 0xFA4
uint32 m_anNumVehicleNodes[NUM_TOTAL_PATH_NODE_AREAS]; // 0x10C4
uint32 m_anNumPedNodes[NUM_TOTAL_PATH_NODE_AREAS]; // 0x11E4
uint32 m_anNumCarPathLinks[NUM_TOTAL_PATH_NODE_AREAS];
uint32 m_anNumAddresses[NUM_TOTAL_PATH_NODE_AREAS];
int32 m_aDynamicLinksBaseIds[NUM_PATH_MAP_AREAS][NUM_DYNAMIC_LINKS_PER_AREA];
int32 m_aDynamicLinksIds[NUM_PATH_MAP_AREAS][NUM_DYNAMIC_LINKS_PER_AREA];
uint32 m_totalNumNodesInPathFindHashTable; // Number of items in total in all buckets of `m_pathFindHashTable`
Expand Down Expand Up @@ -460,7 +460,7 @@ class CPathFind {
CPathNode* GetPathNode(CNodeAddress address);

inline CCarPathLink& GetCarPathLink(const CCarPathLinkAddress& address) {
assert(address.m_wAreaId < NUM_PATH_MAP_AREAS + NUM_PATH_INTERIOR_AREAS);
assert(address.m_wAreaId < NUM_TOTAL_PATH_NODE_AREAS);
return m_pNaviNodes[address.m_wAreaId][address.m_wCarPathLinkId];
}

Expand Down
4 changes: 4 additions & 0 deletions source/game_sa/Tasks/TaskTypes/TaskComplexAvoidEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "IKChainManager_c.h"
#include "TaskSimpleGoToPoint.h"

// !!!!!!!!!!!!!!!!
// UNUSED TASK
// !!!!!!!!!!!!!!!!

void CTaskComplexAvoidEntity::InjectHooks() {
RH_ScopedClass(CTaskComplexAvoidEntity);
RH_ScopedCategory("Tasks/TaskTypes");
Expand Down
Loading

0 comments on commit 853a613

Please sign in to comment.