Skip to content

Commit

Permalink
Most of InteriorManager_c (gta-reversed#589)
Browse files Browse the repository at this point in the history
* Remove dead code

* Fix `CPopCycle::PickPedMIToStreamInForCurrentZone` + Add some comments in Streaming

* dllmain: Use VERIFY

* Add `FurnitureEntity_c`

* Install furniture stuff hooks

* TList Iterator + Support for range-loop on TList

* Rename some Interior_c members

* `InteriorGroup_c`: Add `GetInteriors`

* `GetBoundingBox`

* `ActivatePeds`

* `SetEntryExitPtr`

* `GetPedsInteriorGroup`

* Fix TList iterator constness

* Fix List_c iterator not being std compatible

* Most of `InteriorManager_c`

* Fix build

---------

Co-authored-by: yukani <yukani@zohomail.eu>
  • Loading branch information
Pirulax and yukani authored Aug 1, 2023
1 parent 9eb18e0 commit 50579ee
Show file tree
Hide file tree
Showing 17 changed files with 381 additions and 180 deletions.
1 change: 1 addition & 0 deletions source/InjectHooksMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,7 @@ void InjectHooksMain() {
Events();
Fx();
Vehicle();
Interior();
Scripts();
}

Expand Down
42 changes: 28 additions & 14 deletions source/game_sa/Core/List_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,37 @@ class ListItem_c;

template <typename T>
class TList_c {
class Iterator {
using ListT = TList_c<T>;
template<typename Y>
class BaseIterator {
public:
using iterator_category = std::forward_iterator_tag; // Actually it's bidirectional, but there are quirks, so let's pretend like its not
using difference_type = std::ptrdiff_t;
using value_type = T;
using pointer = T*;
using reference = T&;
using value_type = Y;
using pointer = Y*;
using reference = Y&;

Iterator(pointer ptr) : m_ptr{ ptr } {}
BaseIterator() = default;
BaseIterator(pointer ptr) : m_ptr{ ptr } {}

reference operator*() const { return *m_ptr; }
pointer operator->() { return m_ptr; }
pointer operator->() { return m_ptr; }

Iterator& operator++() { assert(m_ptr); m_ptr = m_ptr->m_pNext; return *this; }
Iterator operator++(int) { Iterator tmp = *this; ++(*this); return tmp; }
auto& operator++() { assert(m_ptr); m_ptr = m_ptr->m_pNext; return *this; }
auto operator++(int) { const auto tmp{ *this }; ++(*this); return tmp; }

// NOTE: Won't work properly in case `list.end() == *this` [Because `m_ptr` will be null]
Iterator& operator--() { assert(m_ptr); m_ptr = m_ptr->m_pPrev; return *this; }
Iterator operator--(int) { Iterator tmp = *this; --(*this); return tmp; }
auto& operator--() { assert(m_ptr); m_ptr = m_ptr->m_pPrev; return *this; }
auto operator--(int) { const auto tmp{ *this }; --(*this); return tmp; }

friend bool operator<=>(const Iterator&, const Iterator&) = default;
friend bool operator==(const BaseIterator<Y>& lhs, const BaseIterator<Y>& rhs) { return lhs.m_ptr == rhs.m_ptr; }
friend bool operator!=(const BaseIterator<Y>& lhs, const BaseIterator<Y>& rhs) { return !(lhs == rhs); }
private:
pointer m_ptr;
};
public:
using iterator = BaseIterator<T>;
using const_iterator = BaseIterator<const T>;

public:
void AddItem(T* item) {
assert(item);
Expand Down Expand Up @@ -197,8 +203,16 @@ class TList_c {

auto GetNumItems() const { return m_cnt; }

auto begin() const { return Iterator{ GetHead() }; }
auto end() const { return Iterator{ nullptr }; }
auto cbegin() const { return const_iterator{ GetHead() }; }
auto begin() const { return cbegin(); }
auto begin() { return iterator{ GetHead() }; }

// Past the end is always `nullptr` - Not really std comforting, but oh well
auto cend() const { return const_iterator{ nullptr }; }
auto end() const { return cend(); }
auto end() { return iterator{ nullptr }; }

auto IsEmpty() const { return m_head == nullptr; }

private:
T* m_head{};
Expand Down
3 changes: 3 additions & 0 deletions source/game_sa/Core/Rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class CRect {
* @brief Check if this rectangle is inside another one
*/
bool Contains(const CRect& o) const;

bool operator==(const CRect&) const = default;
bool operator!=(const CRect&) const = default;
};

VALIDATE_SIZE(CRect, 0x10);
2 changes: 1 addition & 1 deletion source/game_sa/FileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ void CFileLoader::Load2dEffect(const char* line) {
break;
case EFFECT_ATTRACTOR:
break;
case EFFECT_FURNITURE:
case EFFECT_INTERIOR:
break;
case EFFECT_ENEX:
break;
Expand Down
11 changes: 11 additions & 0 deletions source/game_sa/Interior/FurnitureEntity_c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <Base.h>
#include <ListItem_c.h>

class CEntity;

struct FurnitureEntity_c : ListItem_c<FurnitureEntity_c> {
CEntity* m_entity;
uint16 m_tileX, m_tileY;
};
3 changes: 3 additions & 0 deletions source/game_sa/Interior/FurnitureManager_c.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "StdInc.h"
#include "FurnitureManager_c.h"

auto& g_currSubGroupId = StaticRef<uint32, 0xBAB37C>();
auto& g_currFurnitureId = StaticRef<uint32, 0xBAB378>();

void FurnitureManager_c::InjectHooks() {
RH_ScopedClass(FurnitureManager_c);
RH_ScopedCategory("Interior");
Expand Down
2 changes: 2 additions & 0 deletions source/game_sa/Interior/FurnitureManager_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ class FurnitureManager_c {
static int32 GetSubGroupId(const char* name);
};
VALIDATE_SIZE(FurnitureManager_c, 0x2078);

static inline auto& g_furnitureMan = StaticRef<FurnitureManager_c, 0xBAB380>();
17 changes: 8 additions & 9 deletions source/game_sa/Interior/InteriorEffectInfo_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

#include "Vector.h"

class C2dEffect;
class CEntity;
struct C2dEffectInterior;
class CEntity;

struct InteriorEffectInfo_t {
CEntity* m_pEntity;
int32 m_nEffectCount;
C2dEffect* m_pEffects[8];
int32 m_nEffectIndicesInModelInfo[8];
int32 m_field_48;
bool m_field_4C;
int8 m_field_4D[3];
CEntity* entity;
size_t numFx;
C2dEffectInterior* fxs[8];
int32 fxIds[8];
float distSq;
bool8 culled;
};
VALIDATE_SIZE(InteriorEffectInfo_t, 0x50);
4 changes: 2 additions & 2 deletions source/game_sa/Interior/InteriorGroup_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void InteriorGroup_c::InjectHooks() {
}

// 0x5947E0
void InteriorGroup_c::Init(CEntity* entity, int32 a3) {
plugin::CallMethod<0x5947E0, InteriorGroup_c*, CEntity*, int32>(this, entity, a3);
void InteriorGroup_c::Init(CEntity* entity, int32 id) {
plugin::CallMethod<0x5947E0, InteriorGroup_c*, CEntity*, int32>(this, entity, id);
}

// 0x5968E0
Expand Down
29 changes: 17 additions & 12 deletions source/game_sa/Interior/InteriorGroup_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,33 @@ class Interior_c;
struct InteriorInfo_t;

class InteriorGroup_c : public ListItem_c<InteriorGroup_c> {
public:
CEntity* m_pEntity; // 0x8
uint8 m_nId; // 0xC
uint8 m_furnitureId; // 0xD
uint8 m_animType; // 0xE
uint8 m_interiorCount; // 0xF
uint8 m_id; // 0xC
uint8 m_groupId; // 0xD
uint8 m_groupType; // 0xE
uint8 m_numInteriors; // 0xF
Interior_c* m_interiors[8]; // 0x10
int32 field_30; // 0x30
int8 m_isVisible; // 0x34
int8 m_removePeds; // 0x35
int8 m_pedCount; // 0x36
int8 field_37; // 0x37
CEntryExit* m_enex; // 0x30
bool m_isVisible; // 0x34
bool m_lastIsVisible; // 0x35
int8 m_numPeds; // 0x36
CPed* m_peds[16]; // 0x38
int32 field_78[16]; // 0x78
CPed* m_pedsToRemove[16]; // 0x78
int8 m_pathSetupComplete; // 0xB8
int8 m_updatePeds; // 0xB9
int8 m_animBlockReferenced; // 0xBA
int8 field_BB; // 0xBB

public:
static void InjectHooks();

InteriorGroup_c() = default; // 0x597FE0
~InteriorGroup_c() = default; // 0x597FF0

void Init(CEntity* entity, int32 a3);
auto GetInteriors() { return m_interiors | rng::views::take(m_numInteriors); }
auto GetPeds() { return m_peds | rng::views::take(m_numPeds); }

void Init(CEntity* entity, int32 id);
void Update();
int32 AddInterior(Interior_c* interior);
void SetupPeds();
Expand All @@ -58,5 +60,8 @@ class InteriorGroup_c : public ListItem_c<InteriorGroup_c> {
bool FindInteriorInfo(int32 a2, InteriorInfo_t** a3, Interior_c** a4);
int32 GetNumInteriorInfos(int32 a2);
int32 GetRandomInterior();
auto GetId() const { return m_id; }

auto GetInteriors() const { return m_interiors | std::views::take(m_numInteriors); }
};
VALIDATE_SIZE(InteriorGroup_c, 0xBC);
Loading

0 comments on commit 50579ee

Please sign in to comment.