Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup map_object.c #306

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

cleanup map_object.c #306

wants to merge 19 commits into from

Conversation

red031000
Copy link
Member

No description provided.

@red031000
Copy link
Member Author

marking as ready cause this PR is getting too big and overwhelming, expect a part 2 sometime in the future

@red031000 red031000 marked this pull request as ready for review May 10, 2024 17:21
@@ -28,7 +28,7 @@
.public GF3dGfxRawResObj_GetTex4x4Key
.public GF3dGfxRawResObj_GetPlttKey
.public sub_02026E18
.public MapObject_GetFieldSysPtr
.public MapObject_GetFieldSystemPtr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can drop Ptr

@@ -34,7 +34,7 @@ u16* GetVarPointer(FieldSystem* fieldSystem, u16 varId);
u16 FieldSystem_VarGet(FieldSystem* fieldSystem, u16 varId);
BOOL FieldSystem_VarSet(FieldSystem* fieldSystem, u16 varId, u16 value);
u16 FieldSystem_VarGetObjectEventGraphicsId(FieldSystem* fieldSystem, u16 objId);
BOOL FieldSystem_FlagGet(FieldSystem *fieldSystem, u16 flagId);
BOOL FieldSystem_FlagCheck(FieldSystem *fieldSystem, u16 flagId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verb should come before? I remember having a discussion about this but that might've just been for the battle commands

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of scope (will fix it when I get to fieldmap)

u32 unk0;
u32 unk4;
u32 flags;
u32 flags2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any ay to distinguish between flags and flags2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly I forgot I even renamed these in this ptr, I'll check when I have more time lmao

GF_ASSERT(obj != NULL);

MapObject_SetID(obj, obj_apricorn);
MapObject_SetType(obj, 0);
MapObject_SetFlagID(obj, 0);
MapObject_SetXRange(obj, -1);
MapObject_SetYRange(obj, -1);
MapObject_SetFlagsBits(obj, MAPOBJECTFLAG_UNK13 | MAPOBJECTFLAG_UNK10);
MapObject_ClearFlagsBits(obj, MAPOBJECTFLAG_UNK8 | MAPOBJECTFLAG_UNK7);
MapObject_SetFlagsBits(obj, (MapObjectFlagBits)(MAPOBJECTFLAG_UNK13 | MAPOBJECTFLAG_UNK10));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really worth having the enum if you have to keep casting it? #define could work just as well

void MapObject_Delete(LocalMapObject *object) {
u32 flagId = MapObject_GetFlagID(object);
FieldSystem *fieldSystem = MapObject_GetFieldSystemPtr(object);
FieldSystem_FlagSet(fieldSystem, (u16)flagId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this match if you change the function signature to (FieldSystem *, u16) or change flagId to a u16?


static void sub_0205E934(LocalMapObject *object) {
MapObject_SetFlagsBits(object, (MapObjectFlagBits)(MAPOBJECTFLAG_UNK2 | MAPOBJECTFLAG_ACTIVE));
MapObject_ClearFlagsBits(object, (MapObjectFlagBits)(MAPOBJECTFLAG_IGNORE_HEIGHTS | MAPOBJECTFLAG_UNK22 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how much I like the stacking compared to before

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be an enum type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does kinda make sense to be an enum type, it's just flags enums are annoying, I wonder if there's a way to get the compiler to work properly with this, would be good

src/map_object.c Show resolved Hide resolved
src/unk_02055418.c Show resolved Hide resolved
@@ -37,7 +37,7 @@
#include "unk_020552A4.h"
#include "unk_02034354.h"
#include "unk_02066EDC.h"
#include "field_map_object.h"
#include "map_object.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is included twice

@@ -117,6 +115,7 @@ typedef struct UnkLMOCallbackStruct2 {
} UnkLMOCallbackStruct2;

typedef enum MapObjectFlagBits {
MAPOBJECTFLAG_INACTIVE = 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MAPOBJECTFLAG_INACTIVE = 0,
MAPOBJECTFLAG_NONE = 0,

Comment on lines -809 to -810
u32 object_gfx_id = MapObject_GetGfxID(object);
if (object_gfx_id != gfx_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oop

UnkLMOCallbackStruct2* unk = (gfx_id == 0x2000) ? (UnkLMOCallbackStruct2*)&ov01_0220724C : sub_0205FB38(gfx_id);
static void sub_0205ED18(LocalMapObject *object) {
u32 spriteId = MapObject_GetSpriteID(object);
UnkLMOCallbackStruct2 *unk = (spriteId == SPRITE_CAMERA_FOCUS) ? (UnkLMOCallbackStruct2 *)&ov01_0220724C : sub_0205FB38(spriteId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a const pointer

@@ -1,7 +1,7 @@
#ifndef POKEHEARTGOLD_FOLLOW_MON_H
#define POKEHEARTGOLD_FOLLOW_MON_H

#include "field_map_object.h"
#include "map_object.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original filename is adapted from gen 3, and imo equivalent routines should have equivalent (or close enough) names to facilitate transition from gen 3 to gen 4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field does have a special meaning in gen 4 (the field overlay) which ofc is not present in gen 3, I believe this is sufficient to differentiate it

plus I genuinely don't look at gen 3 when decomping/cleaning up, the structures, consoles, and general differences are enough to make gen 3 at best misleading, at worst completely breaking for the process

void sub_0205E104(MapObjectManager* manager, u32 a1, u32 a2, u32 num_object_events, ObjectEvent* object_events) {
u32 count = MapObjectManager_GetCount(manager);
LocalMapObject* objects = MapObjectManager_GetObjects(manager);
extern void ov01_021F9FB0(MapObjectManager *manager, void *);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in a header


static void sub_0205E934(LocalMapObject *object) {
MapObject_SetFlagsBits(object, (MapObjectFlagBits)(MAPOBJECTFLAG_UNK2 | MAPOBJECTFLAG_ACTIVE));
MapObject_ClearFlagsBits(object, (MapObjectFlagBits)(MAPOBJECTFLAG_IGNORE_HEIGHTS | MAPOBJECTFLAG_UNK22 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be an enum type.

void sub_0205EF6C(LocalMapObject* object) {
// No-op
static void MapObject_NoOp(LocalMapObject *object) {
// NoOp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency, noop is NoOp elsewhere in code, and the comment should be the same as the name of the func
basically there's little to no purpose to it other than the look nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants