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

Add more assert cases in the codebase #1115

Merged
merged 11 commits into from Apr 27, 2024

Conversation

Idain
Copy link
Contributor

@Idain Idain commented Mar 16, 2024

No description provided.

@Rangi42
Copy link
Member

Rangi42 commented Mar 16, 2024

Neat, want to do a couple dozen more? git grep -E '(inc|dec) [abcdehl] ; [A-Z0-9_]+$' :)

Also, similar asserts have gone before the relevant line, which here is the inc a. Examples:

	assert PokemonPicPointers == UnownPicPointers
	ld hl, PokemonPicPointers
	assert BUG_CONTEST_PLAYER == 1
	dec a
	assert LOW(SERIAL_LINK_BYTE_TIMEOUT) == 0
	xor a ; LOW(SERIAL_LINK_BYTE_TIMEOUT)

@Idain
Copy link
Contributor Author

Idain commented Mar 16, 2024

Yeah, I can do it. Give me a few minutes.

@Rangi42
Copy link
Member

Rangi42 commented Mar 16, 2024

Thanks a lot!

@Idain
Copy link
Contributor Author

Idain commented Mar 16, 2024

I found some cases triggered by a ; TRUE comment. I don't think we need assert TRUE == 1, do we...?

@Idain
Copy link
Contributor Author

Idain commented Mar 16, 2024

Also, there are a lot of cases for wBattleMode where it decreases, making the assumption WILD_BATTLE == 1 and TRAINER_BATTLE == 2 (around ~65 cases). Do I also have to add asserts for those as well?

@Idain Idain changed the title Add assert for FACING_GRASS_1 and FACING_GRASS_2 Add more assert cases in the codebase Mar 16, 2024
@Idain
Copy link
Contributor Author

Idain commented Mar 16, 2024

Have fun, @Rangi42. :)

@mid-kid
Copy link
Member

mid-kid commented Mar 18, 2024

My biggest fear is excessive asserts cluttering the codebase.

One source of excessive asserts as exemplified by this PR is 0 and 1-index checks (and sets, i.e. xor a).

Do we really want this? Personally, I'd argue no. Most instances of this are trivial enums that won't be reordered (e.g. WILD_/TRAINER_BATTLE), or instances where the 0 value has a special meaning (e.g. LINK_NULL).

I'd really restrict enum-related asserts to enums that are more than a handful of values, likely to warrant reordering, and skip asserts for 0 where 0 is the "nothing" value. For anything else, comments would suffice.

@mid-kid
Copy link
Member

mid-kid commented Mar 18, 2024

Years ago we considered macros like lda x to pick between ld a, x and xor a depending on the value of x. IMO this is mildly more acceptable than the assert approach, but a hard sell in terms of readability.

@Rangi42
Copy link
Member

Rangi42 commented Mar 18, 2024

I'd be very against a lda macro, where it's not clear how many bytes or cycles it would take or what the effect on flags would be. In which case I'd rather just leave out some of the more trivial asserts.

In particular, this is a lot of assert LINK_NULL == 0 and assert WILD_BATTLE == 1, which aren't even likely to change.

@mid-kid
Copy link
Member

mid-kid commented Mar 19, 2024

lda would ideally only be used in places where cycle count doesn't matter, but I digress. Not a relevant topic here.

In particular, this is a lot of assert LINK_NULL == 0 and assert WILD_BATTLE == 1, which aren't even likely to change.

Exactly, I think the asserts are cluttery due to this.

@Idain
Copy link
Contributor Author

Idain commented Mar 20, 2024

I can delete those asserts without problem.

@Idain
Copy link
Contributor Author

Idain commented Mar 20, 2024

Feel free to check again. @Rangi42 @mid-kid

Copy link
Collaborator

@vulcandth vulcandth left a comment

Choose a reason for hiding this comment

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

I am all for asserts, but not for every little thing. I think most of these that are left are fine. Basically we want to leave it to instances where people are likely to change, and likely to miss something when doing so.

engine/battle/core.asm Outdated Show resolved Hide resolved
@Idain
Copy link
Contributor Author

Idain commented Apr 22, 2024

So, what's your verdict? @Rangi42 @vulcandth

Copy link
Collaborator

@vulcandth vulcandth left a comment

Choose a reason for hiding this comment

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

I looked it over.. Looks fine to me. I'll give a chance for other's to add final comments and then i'll merge if nobody objects.

Copy link
Member

@Rangi42 Rangi42 left a comment

Choose a reason for hiding this comment

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

Thank you!

@vulcandth vulcandth merged commit 4432df0 into pret:master Apr 27, 2024
1 check passed
vulcandth pushed a commit to pret/pokegold that referenced this pull request Apr 27, 2024
* Add assert for FACING_GRASS_1 and FACING_GRASS_2

* Add more assert cases

* Add assert for HP bar colors

* Assert LINK_NULL == 0

* Fix assert syntax

* Add asserts for WILD_BATTLE == 1

* Add additional WILD assert

- I need to sleep more...

* Revert asserts for WILD_BATTLE and LINK_NULL

* Commit suggested changes

* Add more assert cases

* Fix syntax error
@Idain Idain deleted the add_assert_grass_shake branch April 30, 2024 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants