7 Commits

Author SHA1 Message Date
d754515c78 Merge branch 'optimise-summary' into 'main'
chore: optimise the summary screen

See merge request tbld/game!5
2022-05-24 14:29:46 +00:00
7e1b759681 Merge branch 'reflections' into 'main'
feat: better reflection code

See merge request tbld/game!6
2022-05-24 14:25:21 +00:00
d29b0f18df chore: optimise the summary screen
It needed a bit of cleanup, why not?
2022-05-24 14:06:08 +00:00
d152a71e58 feat: better reflection code 2022-05-24 13:52:18 +00:00
5408877964 Update CONTRIBUTING.md 2022-05-24 13:25:38 +00:00
a5cb4fd35f stupid gitpod yml... 2022-05-23 14:02:16 +00:00
7a1befb261 Update INSTALL.md 2022-05-20 17:19:38 +00:00
7 changed files with 165 additions and 180 deletions

8
.gitpod.yml Normal file
View File

@ -0,0 +1,8 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
# and commit this file to your remote git repository to share the goodness with others.
tasks:
- init: echo "See INSTALL.md for compilation instructions."

View File

@ -1,8 +1,10 @@
# DO's and DON'T's for contributors to `tumbledemerald`:
If you are looking for code style guidelines, see the [style guide](STYLE.md)
DO:
- Keep `tumbledemerald` up-to-date with `@pret`'s decomp. (pret/pokeemerald)
- Keep `tumbledemerald` up-to-date with `@pret`'s decomp. (pret/pokeemerald on GitHub.com)
- Send pull requests
- Send feature requests
- Hang out with us on **[matrix]**

View File

@ -2,27 +2,14 @@
These instructions explain how to set up the tools required to build **tumbledemerald**, which assembles the source files into a ROM.
If you're just ready to compile a ROM, and you have a machine running a Debian/Ubuntu-based distro or Arch Linux:
```fish
git clone https://github.com/tumbledemerald-org/te-utils.git
cd te-utils
cd scripts
cd linux
cd game
sh pacman # if you use Debian or Ubuntu, enter "sh apt" here instead.
```
For other systems, follow the manual install instructions below:
These instructions come with notes which can be expanded by clicking the "<i>Note...</i>" text.
In general, you should not need to open these unless if you get an error or if you need additional clarification.
If you run into trouble, ask for help on Matrix (see [README.md](README.md)).
If you run into trouble, ask for help on Matrix.
## Windows
Windows has instructions for building with three possible terminals, providing 3 different options in case the user stumbles upon unexpected errors.
- [Windows 10 (WSL1)](#windows-10-wsl1) (**Fastest, highly recommended**, Windows 10 only)
- [Windows 10 (WSL1)](#windows-10-wsl1) (**Fastest, highly recommended**, Windows 10 and later only)
- [Windows (msys2)](#windows-msys2) (Second fastest)
- [Windows (Cygwin)](#windows-cygwin) (Slowest)
@ -35,7 +22,7 @@ Unscientific benchmarks suggest **msys2 is 2x slower** than WSL1, and **Cygwin i
> may <a href="https://bugreports.qt.io/browse/QTBUG-86277">have problems with parsing the <code>\\wsl$</code> network drive path</a>.
</details>
All of the Windows instructions assume that the default drive is C:\\. If this differs to your actual drive letter, then replace C with the correct drive letter when reading the instructions.
All of the Windows instructions assume that the default drive is "C". If this differs to your actual drive letter, then replace C with the correct drive letter when reading the instructions.
**A note of caution**: As Windows 7 is officially unsupported by Microsoft and Windows 8 has very little usage, some maintainers are unwilling to maintain the Windows 7/8 instructions. Thus, these instructions may break in the future with fixes taking longer than fixes to the Windows 10 instructions.
@ -58,7 +45,7 @@ WSL1 is the preferred terminal to build **tumbledemerald**. The following instru
<details>
<summary><i>Note for advanced users...</i></summary>
> You can pick a preferred Linux distribution, but setup instructions may differ. Debian should work with the given instructions, but has not been tested.
> You can pick a preferred Linux distribution, but setup instructions may differ. Debian should work with the given instructions.
</details>
4. Open the [Microsoft Store Linux Selection](https://aka.ms/wslstore), click Ubuntu, then click Get, which will install the Ubuntu distribution.
@ -90,7 +77,7 @@ Some tips before proceeding:
sudo apt update && sudo apt upgrade
```
> Note: If the repository you plan to build has an **[older revision of the INSTALL.md](https://github.com/pret/pokeemerald/blob/571c598/INSTALL.md)**,which **tumbledemerald does ***not***, then follow the [legacy WSL1 instructions](docs/legacy_WSL1_INSTALL.md) from here.
> Note: If the repository you plan to build has an **[older revision of the INSTALL.md](https://github.com/pret/tumbledemerald/blob/571c598/INSTALL.md)**, which tumbledemerald does _not_, then follow the [legacy WSL1 instructions](docs/legacy_WSL1_INSTALL.md) from here.
4. Certain packages are required to build tumbledemerald. Install these packages by running the following command:
@ -122,7 +109,7 @@ cd /mnt/c/Users/<user>/Desktop/decomps
If this works, then proceed to [Installation](#installation).
Otherwise, ask for help on Matrix (see [README.md](README.md)), or continue reading below for [Windows instructions using msys2](#windows-msys2).
Otherwise, ask for help on Matrix, or continue reading below for [Windows instructions using msys2](#windows-msys2).
## Windows (msys2)
@ -138,12 +125,12 @@ Otherwise, ask for help on Matrix (see [README.md](README.md)), or continue read
Note that in msys2, Copy is Ctrl+Insert and Paste is Shift+Insert.
1. Open msys2 at C:\devkitPro\msys2\msys2_shell.bat.
1. Open msys2 at C:\devkitPro\msys2\mingw64.exe or run `C:\devkitPro\msys2\msys2_shell.bat -mingw64`.
2. Certain packages are required to build tumbledemerald. Install these by running the following command:
```bash
pacman -S make gcc zlib-devel git
pacman -S make zlib-devel git mingw-w64-x86_64-gcc mingw-w64-x86_64-libpng
```
<details>
<summary><i>Note...</i></summary>
@ -151,39 +138,6 @@ Note that in msys2, Copy is Ctrl+Insert and Paste is Shift+Insert.
> This command will ask for confirmation, just enter the yes action when prompted.
</details>
3. Download [libpng](https://sourceforge.net/projects/libpng/files/libpng16/1.6.37/libpng-1.6.37.tar.xz/download).
4. Change directory to where libpng was downloaded. By default, msys2 will start in the current user's profile folder, located at **C:\Users\\&#8288;_\<user>_**, where *\<user>* is your Windows username. In most cases, libpng should be saved within a subfolder of the profile folder. For example, if libpng was saved to **C:\Users\\_\<user>_\Downloads** (the Downloads location for most users), enter this command:
```bash
cd Downloads
```
<details>
<summary><i>Notes...</i></summary>
> Note 1: While not shown, msys uses forward slashes `/` instead of backwards slashes `\` as the directory separator.
> Note 2: If the path has spaces, then the path must be wrapped with quotations, e.g. `cd "Downloads/My Downloads"`.
> Note 3: Windows path names are case-insensitive so adhering to capitalization isnt needed.
> Note 4: If libpng was saved elsewhere, you will need to specify the full path to where libpng was downloaded, e.g. `cd c:/devkitpro/msys2` if it was saved there.
</details>
5. Run the following commands to uncompress and install libpng.
```bash
tar xf libpng-1.6.37.tar.xz
cd libpng-1.6.37
./configure --prefix=/usr
make check
make install
```
6. Then finally, run the following command to change back to the user profile folder.
```bash
cd
```
### Choosing where to store tumbledemerald (msys2)
At this point, you can choose a folder to store tumbledemerald into. If you're okay with storing tumbledemerald in the user profile folder, then proceed to [Installation](#installation). Otherwise, you'll need to account for where tumbledemerald is stored when changing directory to the tumbledemerald folder.
@ -195,7 +149,7 @@ cd Desktop/decomps
If this works, then proceed to [Installation](#installation).
Otherwise, ask for help on Matrix (see [README.md](README.md)), or continue reading below for [Windows instructions using Cygwin](#windows-cygwin).
Otherwise, ask for help on Matrix, or continue reading below for [Windows instructions using Cygwin](#windows-cygwin).
## Windows (Cygwin)
1. If devkitARM is **not installed**, then follow the instructions used to [install devkitARM](#installing-devkitarm) for the msys2 setup before continuing. *Remember to not continue following the msys2 instructions by mistake!*
@ -263,7 +217,7 @@ Note that the directory **must exist** in Windows. If you want to store tumblede
> Note 2: Windows path names are case-insensitive so adhering to capitalization isn't needed
</details>
If this works, then proceed to [Installation](#installation). Otherwise, ask for help on Matrix (see [README.md](README.md)).
If this works, then proceed to [Installation](#installation). Otherwise, ask for help on Matrix.
## macOS
1. If the Xcode Command Line Tools are not installed, download the tools [here](https://developer.apple.com/xcode/resources/), open your Terminal, and run the following command:
@ -333,39 +287,40 @@ Note that the directory **must exist** in the folder system. If you want to stor
> Note: If the path has spaces, then the path must be wrapped with quotations, e.g. `cd "Desktop/decomp folder"`
</details>
If this works, then proceed to [Installation](#installation). Otherwise, ask for help on Matrix (see [README.md](README.md)).
If this works, then proceed to [Installation](#installation). Otherwise, ask for help on Matrix.
## Linux
Open Terminal and enter the following commands, depending on which distro you're using.
### Debian/Ubuntu-based distributions
Run the following commands to install the necessary packages:
Run the following command to install the necessary packages:
```bash
sudo apt update && sudo apt upgrade -y
sudo apt install build-essential binutils-arm-none-eabi git libpng-dev
```
Then proceed to [Choosing where to store tumbledemerald (Linux)](#choosing-where-to-store-tumbledemerald-linux).
<details>
<summary><i>Note for legacy repos...</i></summary>
> If the repository you plan to build has an **[older revision of the INSTALL.md](https://github.com/pret/pokeemerald/blob/571c598/INSTALL.md)**, which **tumbledemerald** does ***not***,
> If the repository you plan to build has an **[older revision of the INSTALL.md](https://github.com/pret/tumbledemerald/blob/571c598/INSTALL.md)**, which tumbledemerald does _not_,
> then you will have to install devkitARM. Install all the above packages except binutils-arm-none-eabi, and follow the instructions to
> [install devkitARM on Debian/Ubuntu-based distributions](#installing-devkitarm-on-debianubuntu-based-distributions).
</details>
### Arch Linux based systems (Arch, Manjaro, Garuda, etc.)
Run the following commands to install the necessary packages:
```fish
sudo pacman -Syu
sudo pacman -S gcc g++ make arm-none-eabi-binutils git libpng
### Arch Linux, Manjaro, and other Arch-based distributions
Run this command as root to install the necessary packages:
```bash
pacman -S base-devel arm-none-eabi-binutils git libpng
```
A `pacman -Syu` is also recommended but not strictly required.
Then proceed to [Choosing where to store tumbledemerald (Linux)](#choosing-where-to-store-tumbledemerald-linux).
<details>
<summary><i>Note for legacy repos...</i></summary>
> If the repository you plan to build has an **[older revision of the INSTALL.md](https://github.com/pret/pokeemerald/blob/571c598/INSTALL.md)**, which **tumbledemerald** does ***not***,
> then you will have to install devkitARM. Install all the above packages except binutils-arm-none-eabi, and follow the instructions to
> [install devkitARM on Debian/Ubuntu-based distributions](#installing-devkitarm-on-debianubuntu-based-distributions).
> If the repository you plan to build has an **[older revision of the INSTALL.md](https://github.com/pret/tumbledemerald/blob/571c598/INSTALL.md)**, which tumbledemerald does _not_,
> then you will have to install devkitARM. Install all the above packages except arm-none-eabi-binutils, and follow the instructions to
> [install devkitARM on Arch Linux](#installing-devkitarm-on-arch-linux).
</details>
### Other distributions
@ -376,14 +331,12 @@ _(Specific instructions for other distributions would be greatly appreciated!)_
- `g++`
- `make`
- `git`
- `libpng-dev`
- `arm-none-eabi binutils`
- `libpng-dev` (sometimes called `libpng-devel` or just `libpng`)
2. Follow the instructions [here](https://devkitpro.org/wiki/devkitPro_pacman) to install devkitPro pacman. (unless you decided to use arm binutils) As a reminder, the goal is to configure an existing pacman installation to recognize devkitPro's repositories.
2. Follow the instructions [here](https://devkitpro.org/wiki/devkitPro_pacman) to install devkitPro pacman. As a reminder, the goal is to configure an existing pacman installation to recognize devkitPro's repositories.
3. Once devkitPro pacman is configured, run the following commands:
```bash
sudo pacman -Syu
sudo pacman -Sy
sudo pacman -S gba-dev
```
@ -393,7 +346,7 @@ _(Specific instructions for other distributions would be greatly appreciated!)_
### Choosing where to store tumbledemerald (Linux)
At this point, you can choose a folder to store tumbledemerald (and agbcc) into. If so, you'll have to account for the modified folder path when changing directory to the tumbledemerald folder.
If this works, then proceed to [Installation](#installation). Otherwise, ask for help on Matrix (see [README.md](README.md)).
If this works, then proceed to [Installation](#installation). Otherwise, ask for help on Matrix.
## Installation
@ -408,7 +361,7 @@ If this works, then proceed to [Installation](#installation). Otherwise, ask for
1. If tumbledemerald is not already downloaded (some users may prefer to download tumbledemerald via a git client like GitHub Desktop), run:
```bash
git clone https://github.com/Rebirth-Devs/tumbledemerald
git clone https://gitlab.com/tbld/game.git
```
<details>
@ -424,15 +377,37 @@ If this works, then proceed to [Installation](#installation). Otherwise, ask for
> Where *\<folder where tumbledemerald is to be stored>* is the path of the folder [where you chose to store tumbledemerald](#Choosing-where-to-store-tumbledemerald-WSL1). Then run the `git clone` command again.
</details>
2. Since agbcc is a submodule, here:
2. Install agbcc into tumbledemerald. The commands to run depend on certain conditions. **You should only follow one of the listed instructions**:
- If agbcc has **not been built before** in the folder where you chose to store tumbledemerald, run the following commands to build and install it into tumbledemerald:
In the game repo:
```bash
git clone https://github.com/pret/agbcc
cd agbcc
./build.sh
./install.sh ../
./install.sh ../tumbledemerald
```
- **Otherwise**, if agbcc has been built before (e.g. if the git clone above fails), but was **last built on a different terminal** than the one currently used (only relevant to Windows, e.g. switching from msys2 to WSL1), then run the following commands to build and install it into tumbledemerald:
```bash
cd agbcc
git clean -fX
./build.sh
./install.sh ../tumbledemerald
```
- **Otherwise**, if agbcc has been built before on the same terminal, run the following commands to install agbcc into tumbledemerald:
```bash
cd agbcc
./install.sh ../tumbledemerald
```
<details>
<summary><i>Note...</i></summary>
> If building agbcc or tumbledemerald results in an error, try deleting the agbcc folder and re-installing agbcc as if it has not been built before.
</details>
3. Once agbcc is installed, change directory back to the base directory where tumbledemerald and agbcc are stored:
@ -446,11 +421,15 @@ If you aren't in the tumbledemerald directory already, then **change directory**
```bash
cd tumbledemerald
```
To build **tumbledemerald.gba** for the first time and confirm it matches the official ROM image (Note: to speed up builds, see [Parallel builds](#parallel-builds)):
To build **tumbledemerald.gba** (Note: to speed up builds, see [Parallel builds](#parallel-builds)):
```bash
make compare
```
If an OK is returned, then the installation went smoothly.
If you see something like:
```bash
-m01 POKEMON EMER -cBPEE --silent
```
then the build was successful.
<details>
<summary>Note for Windows...</summary>
> If you switched terminals since the last build (e.g. from msys2 to WSL1), you must run `make clean-tools` once before any subsequent `make` commands.
@ -471,6 +450,8 @@ To speed up building, first get the value of `nproc` by running the following co
```bash
nproc
```
For example, I use Gitpod to compile the builds in releases, and the output of `nproc` there is `16`. So I would run `make -j16`.
Builds can then be sped up by running the following command:
```bash
make -j<output of nproc>
@ -479,13 +460,6 @@ Replace `<output of nproc>` with the number that the `nproc` command returned.
`nproc` is not available on macOS. The alternative is `sysctl -n hw.ncpu` ([relevant Stack Overflow thread](https://stackoverflow.com/questions/1715580)).
## Debug info
To build **tumbledemerald.elf** with enhanced debug info:
```bash
make DINFO=1
```
## devkitARM's C compiler
This project supports the `arm-none-eabi-gcc` compiler included with devkitARM. If devkitARM (a.k.a. gba-dev) has already been installed as part of the platform-specific instructions, simply run:
@ -562,7 +536,25 @@ devkitARM is now installed.
devkitARM is now installed.
## Other toolchains
### Installing devkitARM on Arch Linux
1. Follow [devkitPro's instructions](https://devkitpro.org/wiki/devkitPro_pacman#Customising_Existing_Pacman_Install) to configure `pacman` to download devkitPro packages.
2. Install `gba-dev`: run the following command as root.
```console
pacman -S gba-dev
```
This will ask for the selection of packages to install. Just press Enter to install all of them, followed by entering Y to proceed with the installation.
3. Run the following command to set devkitPro related environment variables (alternatively, close and re-open the Terminal):
```bash
source /etc/profile.d/devkit-env.sh
```
devkitARM is now installed.
### Other toolchains
To build using a toolchain other than devkitARM, override the `TOOLCHAIN` environment variable with the path to your toolchain, which must contain the subdirectory `bin`.
```bash
@ -574,8 +566,17 @@ make TOOLCHAIN="/usr/local/arm-none-eabi"
```
To compile the `modern` target with this toolchain, the subdirectories `lib`, `include`, and `arm-none-eabi` must also be present.
### Building with debug info under a modern toolchain
To build **tumbledemerald.elf** with debug symbols under a modern toolchain:
```bash
make modern DINFO=1
```
Note that this is not necessary for a non-modern build since those are built with debug symbols by default.
# Useful additional tools
* [porymap](https://github.com/huderlem/porymap) for viewing and editing maps
* [poryscript](https://github.com/huderlem/poryscript) for scripting ([VS Code extension](https://marketplace.visualstudio.com/items?itemName=karathan.poryscript))
* [poryscript](https://github.com/huderlem/poryscript) for scripting ([VS Code/VSCodium extension](https://marketplace.visualstudio.com/items?itemName=karathan.poryscript))
* [Tilemap Studio](https://github.com/Rangi42/tilemap-studio) for viewing and editing tilemaps
* [VSCodium](https://vscodium.com)

View File

@ -133,12 +133,9 @@ struct Pokemon
struct MonSpritesGfxManager
{
u32 numSprites:4;
u32 numSprites2:4; // Never read
u32 numFrames:8;
u32 active:8;
u32 dataSize:4;
u32 mode:4; // MON_SPR_GFX_MODE_*
u8 numSprites;
u8 numFrames;
bool16 active;
void *spriteBuffer;
u8 **spritePointers;
struct SpriteTemplate *templates;
@ -436,8 +433,8 @@ void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality);
const u8 *GetTrainerClassNameFromId(u16 trainerId);
const u8 *GetTrainerNameFromId(u16 trainerId);
bool8 HasTwoFramesAnimation(u16 species);
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode);
void DestroyMonSpritesGfxManager(u8 managerId);
u8 *MonSpritesGfxManager_GetSpritePtr(u8 managerId, u8 spriteNum);
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(void);
void DestroyMonSpritesGfxManager(void);
u8 *MonSpritesGfxManager_GetSpritePtr(u8 spriteNum);
#endif // GUARD_POKEMON_H

View File

@ -318,6 +318,21 @@ static u8 ObjectEventCB2_NoMovement2(void)
return 0;
}
static void TryHidePlayerReflection(void)
{
if (gObjectEvents[gPlayerAvatar.objectEventId].hasReflection) {
s16 x, y;
struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId];
x = playerObjEvent->currentCoords.x;
y = playerObjEvent->currentCoords.y;
MoveCoords(DIR_SOUTH, &x, &y);
if (!MetatileBehavior_IsReflective(MapGridGetMetatileBehaviorAt(x, y)))
playerObjEvent->hideReflection = TRUE;
else
playerObjEvent->hideReflection = FALSE;
}
}
void PlayerStep(u8 direction, u16 newKeys, u16 heldKeys)
{
struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId];
@ -325,6 +340,7 @@ void PlayerStep(u8 direction, u16 newKeys, u16 heldKeys)
HideShowWarpArrow(playerObjEvent);
if (gPlayerAvatar.preventStep == FALSE)
{
TryHidePlayerReflection();
Bike_TryAcroBikeHistoryUpdate(newKeys, heldKeys);
if (TryInterruptObjectEventSpecialAnim(playerObjEvent, direction) == 0)
{
@ -335,6 +351,8 @@ void PlayerStep(u8 direction, u16 newKeys, u16 heldKeys)
MovePlayerAvatarUsingKeypadInput(direction, newKeys, heldKeys);
PlayerAllowForcedMovementIfMovingSameDirection();
}
TryHidePlayerReflection();
}
}
}

View File

@ -69,7 +69,7 @@ EWRAM_DATA u8 gEnemyPartyCount = 0;
EWRAM_DATA struct Pokemon gPlayerParty[PARTY_SIZE] = {0};
EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0};
EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0};
EWRAM_DATA static struct MonSpritesGfxManager *sMonSpritesGfxManagers[MON_SPR_GFX_MANAGERS_COUNT] = {NULL};
EWRAM_DATA static struct MonSpritesGfxManager *sMonSpritesGfxManager = NULL;
#include "data/battle_moves.h"
@ -3468,12 +3468,8 @@ void SetMultiuseSpriteTemplateToPokemon(u16 speciesTag, u8 battlerPosition)
{
if (gMonSpritesGfxPtr != NULL)
gMultiuseSpriteTemplate = gMonSpritesGfxPtr->templates[battlerPosition];
else if (sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_A])
gMultiuseSpriteTemplate = sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_A]->templates[battlerPosition];
else if (sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_B])
gMultiuseSpriteTemplate = sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_B]->templates[battlerPosition];
else
gMultiuseSpriteTemplate = gBattlerSpriteTemplates[battlerPosition];
else if (sMonSpritesGfxManager)
gMultiuseSpriteTemplate = sMonSpritesGfxManager->templates[battlerPosition];
gMultiuseSpriteTemplate.paletteTag = speciesTag;
if (battlerPosition == B_POSITION_PLAYER_LEFT || battlerPosition == B_POSITION_PLAYER_RIGHT)
@ -6882,11 +6878,11 @@ static bool8 ShouldSkipFriendshipChange(void)
#define ALLOC_FAIL_STRUCT (1 << 1)
#define GFX_MANAGER_ACTIVE 0xA3 // Arbitrary value
#define GFX_MANAGER_SPR_SIZE (MON_PIC_SIZE * 4) // Only Castform uses more than MON_PIC_SIZE, despite not displaying its forms.
#define GFX_MANAGER_NUM_FRAMES 4 // Only 2 frames are needed
#define GFX_MANAGER_NUM_FRAMES 2 // Only 2 frames are needed, so only 2 frames are used in tumbledemerald
static void InitMonSpritesGfx_Battle(struct MonSpritesGfxManager* gfx)
{
u16 i, j;
u32 i, j;
for (i = 0; i < gfx->numSprites; i++)
{
gfx->templates[i] = gBattlerSpriteTemplates[i];
@ -6912,41 +6908,21 @@ static void InitMonSpritesGfx_FullParty(struct MonSpritesGfxManager* gfx)
}
}
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(void)
{
u8 i;
u32 i;
u8 failureFlags;
struct MonSpritesGfxManager *gfx;
failureFlags = 0;
managerId %= MON_SPR_GFX_MANAGERS_COUNT;
gfx = AllocZeroed(sizeof(*gfx));
if (gfx == NULL)
return NULL;
switch (mode)
{
case MON_SPR_GFX_MODE_FULL_PARTY:
gfx->numSprites = PARTY_SIZE + 1;
gfx->numSprites2 = PARTY_SIZE + 1;
gfx->numFrames = GFX_MANAGER_NUM_FRAMES;
gfx->dataSize = 1;
gfx->mode = MON_SPR_GFX_MODE_FULL_PARTY;
break;
// case MON_SPR_GFX_MODE_BATTLE:
case MON_SPR_GFX_MODE_NORMAL:
default:
gfx->numSprites = MAX_BATTLERS_COUNT;
gfx->numSprites2 = MAX_BATTLERS_COUNT;
gfx->numFrames = GFX_MANAGER_NUM_FRAMES;
gfx->dataSize = 1;
gfx->mode = MON_SPR_GFX_MODE_NORMAL;
break;
}
// Set up sprite / sprite pointer buffers
gfx->spriteBuffer = AllocZeroed(gfx->dataSize * GFX_MANAGER_SPR_SIZE * gfx->numSprites);
gfx->spritePointers = AllocZeroed(gfx->numSprites * 32); // ? Only * 4 is necessary, perhaps they were thinking bits.
gfx->numSprites = MAX_BATTLERS_COUNT;
gfx->numFrames = GFX_MANAGER_NUM_FRAMES;
gfx->spriteBuffer = AllocZeroed(GFX_MANAGER_SPR_SIZE * gfx->numSprites);
gfx->spritePointers = AllocZeroed(gfx->numSprites * 4);
if (gfx->spriteBuffer == NULL || gfx->spritePointers == NULL)
{
failureFlags |= ALLOC_FAIL_BUFFER;
@ -6954,7 +6930,7 @@ struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
else
{
for (i = 0; i < gfx->numSprites; i++)
gfx->spritePointers[i] = gfx->spriteBuffer + (gfx->dataSize * GFX_MANAGER_SPR_SIZE * i);
gfx->spritePointers[i] = gfx->spriteBuffer + (GFX_MANAGER_SPR_SIZE * i);
}
// Set up sprite structs
@ -6968,18 +6944,7 @@ struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
{
for (i = 0; i < gfx->numFrames * gfx->numSprites; i++)
gfx->frameImages[i].size = MON_PIC_SIZE;
switch (gfx->mode)
{
case MON_SPR_GFX_MODE_FULL_PARTY:
InitMonSpritesGfx_FullParty(gfx);
break;
case MON_SPR_GFX_MODE_NORMAL:
case MON_SPR_GFX_MODE_BATTLE:
default:
InitMonSpritesGfx_Battle(gfx);
break;
}
InitMonSpritesGfx_Battle(gfx);
}
// If either of the allocations failed free their respective members
@ -7002,27 +6967,21 @@ struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
}
else
{
gfx->active = GFX_MANAGER_ACTIVE;
sMonSpritesGfxManagers[managerId] = gfx;
gfx->active = TRUE;
sMonSpritesGfxManager = gfx;
}
return sMonSpritesGfxManagers[managerId];
return sMonSpritesGfxManager;
}
void DestroyMonSpritesGfxManager(u8 managerId)
void DestroyMonSpritesGfxManager(void)
{
struct MonSpritesGfxManager *gfx;
struct MonSpritesGfxManager *gfx = sMonSpritesGfxManager;
managerId %= MON_SPR_GFX_MANAGERS_COUNT;
gfx = sMonSpritesGfxManagers[managerId];
if (gfx == NULL)
return;
if (gfx->active != GFX_MANAGER_ACTIVE)
{
memset(gfx, 0, sizeof(*gfx));
}
else
if (gfx->active)
{
TRY_FREE_AND_SET_NULL(gfx->frameImages);
TRY_FREE_AND_SET_NULL(gfx->templates);
@ -7031,20 +6990,20 @@ void DestroyMonSpritesGfxManager(u8 managerId)
memset(gfx, 0, sizeof(*gfx));
Free(gfx);
}
else
memset(gfx, 0, sizeof(*gfx));
}
u8 *MonSpritesGfxManager_GetSpritePtr(u8 managerId, u8 spriteNum)
u8 *MonSpritesGfxManager_GetSpritePtr(u8 spriteNum)
{
struct MonSpritesGfxManager *gfx = sMonSpritesGfxManagers[managerId % MON_SPR_GFX_MANAGERS_COUNT];
if (gfx->active != GFX_MANAGER_ACTIVE)
{
return NULL;
}
else
struct MonSpritesGfxManager *gfx = sMonSpritesGfxManager;
if (gfx->active)
{
if (spriteNum >= gfx->numSprites)
spriteNum = 0;
return gfx->spritePointers[spriteNum];
}
return NULL;
}

View File

@ -1111,7 +1111,7 @@ void ShowPokemonSummaryScreen(u8 mode, void *mons, u8 monIndex, u8 maxMonIndex,
SummaryScreen_SetAnimDelayTaskId(TASK_NONE);
if (gMonSpritesGfxPtr == NULL)
CreateMonSpritesGfxManager(MON_SPR_GFX_MANAGER_A, MON_SPR_GFX_MODE_NORMAL);
CreateMonSpritesGfxManager();
SetMainCallback2(CB2_InitSummaryScreen);
}
@ -1500,7 +1500,7 @@ static void CloseSummaryScreen(u8 taskId)
StopCryAndClearCrySongs();
m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 0x100);
if (gMonSpritesGfxPtr == NULL)
DestroyMonSpritesGfxManager(MON_SPR_GFX_MANAGER_A);
DestroyMonSpritesGfxManager();
FreeSummaryScreen();
DestroyTask(taskId);
}
@ -3902,12 +3902,12 @@ static u8 LoadMonGfxAndSprite(struct Pokemon *mon, s16 *state)
{
if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == SUMMARY_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE)
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2],
MonSpritesGfxManager_GetSpritePtr(MON_SPR_GFX_MANAGER_A, B_POSITION_OPPONENT_LEFT),
MonSpritesGfxManager_GetSpritePtr(B_POSITION_OPPONENT_LEFT),
summary->species2,
summary->pid);
else
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2],
MonSpritesGfxManager_GetSpritePtr(MON_SPR_GFX_MANAGER_A, B_POSITION_OPPONENT_LEFT),
MonSpritesGfxManager_GetSpritePtr(B_POSITION_OPPONENT_LEFT),
summary->species2,
summary->pid);
}