cheatsheet: Add sead::DynamicCast

This commit is contained in:
Léo Lam 2021-09-09 22:37:42 +02:00
parent 934ee7b096
commit d81186c208
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
1 changed files with 26 additions and 0 deletions

View File

@ -369,6 +369,32 @@ item = buffer[i];
---
#### RTTI (Runtime Type Info)
##### sead::DynamicCast
```cpp
some_ptr = ...;
x = __ldar(...); // usually a guard variable, but the variable is not always named
another_ptr = some_ptr;
if ( (x & 1) == 0 && _cxa_guard_acquire_0(...)) // the same guard variable
{
... = &...;
_cxa_guard_release_0(...); // the same guard variable
}
if ( another_ptr && another_ptr->checkDerivedRuntimeTypeInfo(another_ptr, ...) )
{
// code that uses another_ptr
}
```
⬇️
```cpp
if (auto* another_ptr = sead::DynamicCast<T>(some_ptr))
...
```
T is a derived type that should be related to the type of the original pointer.
### agl
agl is one of Nintendo's in-house graphics libraries.