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

Integrate clang-format #176

Merged
merged 4 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
98 changes: 98 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
BasedOnStyle: WebKit
Language: Cpp
LineEnding: LF
ColumnLimit: 0

AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: Consecutive
AlignTrailingComments: false

AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false

BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both

InsertBraces: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterStruct: false
AfterUnion: false
BeforeElse: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: false

AlwaysBreakAfterReturnType: None
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
BreakStringLiterals: true

DerivePointerAlignment: false
PointerAlignment: Right
ReferenceAlignment: Right

ContinuationIndentWidth: 4
IndentCaseBlocks: false
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 4

SortIncludes: CaseSensitive
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '((<.+>)|("nitro/.*\.h"))'
Priority: 1
- Regex: '"(consts|constants)/.*\.h"'
Priority: 2
- Regex: '"(struct_(decls|defs))/.*\.h"'
Priority: 3
- Regex: '"(constdata|res)/.*\.(h|naix)"'
Priority: 6
- Regex: '"[[:alnum:]_]+/.*\.(h|naix)"'
Priority: 4
- Regex: '"[[:alnum:]_]+\.(h|naix)"'
Priority: 5
- Regex: '.*'
Priority: 7

InsertTrailingCommas: Wrapped
InsertNewlineAtEOF: true
KeepEmptyLinesAtEOF: false
MaxEmptyLinesToKeep: 1
RemoveParentheses: ReturnStatement
RemoveSemicolon: true

# QualifierAlignment: Custom
# QualifierOrder: [static, inline, const, volatile, type]

SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
23 changes: 23 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# These files still contain inline-ASM functions; ignore them for formatting for now
src/overlay117/ov117_02260668.c
src/overlay112/ov112_0225C700.c
src/overlay110/ov110_021D0D80.c
src/overlay020/ov20_021D4728.c
src/unk_0208A3F4.c
src/unk_02089604.c
src/overlay073/ov73_021D3250.c
src/overlay107/ov107_02245EB0.c
src/overlay107/ov107_02241AE0.c
src/overlay007/ov7_02249960.c
src/overlay071/ov71_0223C69C.c
src/overlay019/ov19_021D0D80.c
src/overlay022/ov22_02259C58.c
src/overlay023/ov23_02253598.c
src/overlay065/ov65_0222DCE0.c
src/overlay064/ov64_0222DCE0.c
src/overlay098/ov98_022471C8.c
src/overlay062/ov62_02241204.c
src/overlay062/ov62_0223DFA8.c
src/overlay062/ov62_0223CAEC.c
src/overlay062/ov62_02231690.c
src/overlay062/ov62_02237D24.c
3 changes: 3 additions & 0 deletions .clang-format-include
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include/**/*
src/**/*

9 changes: 9 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# Redirect output to stderr.
exec 1>&2

# Run clang-format on staged files; abort the commit if any files are changed
if ! git clang-format ; then
echo "linting made changes to source files; aborting commit"
exit 1
fi
32 changes: 32 additions & 0 deletions .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: pr-lint
on:
pull_request:
branches: [main]
paths: ['**.c', '**.h']

jobs:
pr-lint:
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: read

steps:
- uses: actions/checkout@v4

- uses: cpp-linter/cpp-linter-action@v2
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: 'file' # Use repository .clang-format file
tidy-checks: '-*' # Disable clang-tidy checks
version: '18'
files-changed-only: false # Github returns error code 406 if more than 300 files are changed in a PR
ignore: '.github|lib|subprojects|tools'
file-annotations: false

- name: fail fast
if: steps.linter.outputs.clang-format-checks-failed > 0
run: exit 1
39 changes: 32 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Contributing to pret/pokeplatinum

<!--toc:start-->
- [Editor Enhancements](#editor-enhancements)
- [Code Formatting](#code-formatting)
<!--toc:end-->

This document provides a synopsis and loose guidelines for how to contribute to this project. It is a work in progress. Maintainers should expand this document.

## Contents
- [Editor enhancements](#editor-enhancements)
## Editor Enhancements

<a href="editor-enhancements"></a>
## Editor enhancements

This repository includes a script to generate a `compile_commands.json` that is compatible with C language servers such as `clangd`.

### Requirements

- python3.8 or newer
- gcc-arm-none-eabi
- clangd
- `python3.8` or newer
- `gcc-arm-none-eabi`
- `clangd`

### Usage

Expand All @@ -23,3 +25,26 @@ This repository includes a script to generate a `compile_commands.json` that is
```

This will create a file named `compile_commands.json` in the project root, overwriting the previous copy.

## Code Formatting

This repository includes an opinionated `clang-format` specification to ensure that we maintain a common code style. For convenience, a pre-commit hook is also provided in `.githooks` which will run `clang-format` against any staged changes prior to executing a commit.

### Requirements

- `clang-format@17` or newer

### Usage

To set up the pre-commit hook:

```sh
git config --local core.hooksPath .githooks/
```

To run the formatter on the full source tree:

```bash
./format.sh
```

4 changes: 4 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

"${NINJA:-ninja}" -C build clang-format
5 changes: 3 additions & 2 deletions include/ascii_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define POKEPLATINUM_ASCII_UTIL_H

#include <nnsys.h>

#include "charcode.h"

#define MAX_STRING_COPY_LEN 256
#define MAX_STRING_COPY_LEN 256

int Ascii_Length(char *str);
char* Ascii_CopyToTerminator(char *src, char *dst, char terminator);
char *Ascii_CopyToTerminator(char *src, char *dst, char terminator);
int Ascii_ConvertToInt(char *str);
void Ascii_SetResourceName(NNSG3dResName *resource, const char *src);
BOOL IsFullWidthChar(charcode_t character);
Expand Down
29 changes: 15 additions & 14 deletions include/bag.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef POKEPLATINUM_BAG_H
#define POKEPLATINUM_BAG_H

#include "savedata.h"
#include "constants/heap.h"

#include "savedata.h"

#define ITEM_POCKET_SIZE 165
#define KEY_ITEM_POCKET_SIZE 50
#define TMHM_POCKET_SIZE 100
Expand Down Expand Up @@ -69,18 +70,18 @@ void Pocket_Sort(BagItem *pocket, const u32 size); // Same as Pocket_SortEmpty,
void *sub_0207D824(Bag *bag, const u8 *pockets, enum HeapId heapID);
BagItem *Bag_GetItemSlot(Bag *bag, u16 pocketID, u16 slot);
Bag *SaveData_GetBag(SaveData *saveData);
UnkStruct_0207D99C * sub_0207D99C(u32 param0);
void sub_0207D9B4(UnkStruct_0207D99C * param0, u32 param1, u8 * param2, u8 * param3);
u16 sub_0207D9C4(UnkStruct_0207D99C * param0);
void sub_0207D9C8(UnkStruct_0207D99C * param0, u32 param1, u8 param2, u8 param3);
void sub_0207D9D4(UnkStruct_0207D99C * param0, u16 param1);
void sub_0207D9D8(UnkStruct_0207D99C * param0, u32 param1, u8 * param2, u8 * param3);
u16 sub_0207D9E4(UnkStruct_0207D99C * param0);
u16 sub_0207D9E8(UnkStruct_0207D99C * param0);
u16 sub_0207D9EC(UnkStruct_0207D99C * param0);
void sub_0207D9F0(UnkStruct_0207D99C * param0, u32 param1, u8 param2, u8 param3);
void sub_0207D9F8(UnkStruct_0207D99C * param0);
void Bag_SetLastItemUsed(UnkStruct_0207D99C * param0, u16 param1, u16 param2);
void sub_0207DA24(UnkStruct_0207D99C * param0, u16 param1);
UnkStruct_0207D99C *sub_0207D99C(u32 param0);
void sub_0207D9B4(UnkStruct_0207D99C *param0, u32 param1, u8 *param2, u8 *param3);
u16 sub_0207D9C4(UnkStruct_0207D99C *param0);
void sub_0207D9C8(UnkStruct_0207D99C *param0, u32 param1, u8 param2, u8 param3);
void sub_0207D9D4(UnkStruct_0207D99C *param0, u16 param1);
void sub_0207D9D8(UnkStruct_0207D99C *param0, u32 param1, u8 *param2, u8 *param3);
u16 sub_0207D9E4(UnkStruct_0207D99C *param0);
u16 sub_0207D9E8(UnkStruct_0207D99C *param0);
u16 sub_0207D9EC(UnkStruct_0207D99C *param0);
void sub_0207D9F0(UnkStruct_0207D99C *param0, u32 param1, u8 param2, u8 param3);
void sub_0207D9F8(UnkStruct_0207D99C *param0);
void Bag_SetLastItemUsed(UnkStruct_0207D99C *param0, u16 param1, u16 param2);
void sub_0207DA24(UnkStruct_0207D99C *param0, u16 param1);

#endif // POKEPLATINUM_BAG_H
2 changes: 1 addition & 1 deletion include/battle/ai_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef struct AIContext {
int padding0014; // this does not match with a u32, weird

u8 moveDamageRolls[LEARNED_MOVES_MAX];

u16 battlerMoves[MAX_BATTLERS][LEARNED_MOVES_MAX];
u8 battlerAbilities[MAX_BATTLERS];
u16 battlerHeldItems[MAX_BATTLERS];
Expand Down
24 changes: 12 additions & 12 deletions include/battle/battle_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include "constants/battle.h"
#include "constants/pokemon.h"

#include "battle/ai_context.h"
#include "battle/battle_message.h"
#include "battle/battle_mon.h"

#include "struct_decls/battle_system.h"
#include "struct_decls/cell_actor_data.h"
#include "struct_decls/font_oam.h"
#include "struct_defs/sprite_manager_allocation.h"
#include "struct_decls/battle_system.h"

#include "battle/ai_context.h"
#include "battle/battle_message.h"
#include "battle/battle_mon.h"
#include "overlay012/struct_ball_rotation_decl.h"

typedef struct BattleContext BattleContext;
Expand Down Expand Up @@ -161,7 +161,7 @@ struct BattleContext {
int sideEffectFlags;
int sideEffectMon;
int lastBattlerId;

int gainedExp;
int sharedExp;
u32 sideGetExpMask[2];
Expand Down Expand Up @@ -197,13 +197,13 @@ struct BattleContext {

BattleScriptTaskData *taskData;
void *tmpData;

u32 fieldConditionsMask;
FieldConditions fieldConditions;

u32 sideConditionsMask[NUM_BATTLE_SIDES];
SideConditions sideConditions[NUM_BATTLE_SIDES];

TurnFlags turnFlags[MAX_BATTLERS];
SelfTurnFlags selfTurnFlags[MAX_BATTLERS];
MoveFailFlags moveFailFlags[MAX_BATTLERS];
Expand All @@ -214,7 +214,7 @@ struct BattleContext {

u32 battleStatusMask;
u32 battleStatusMask2;

int damage;
int hitDamage;
int criticalBoosts;
Expand Down Expand Up @@ -243,12 +243,12 @@ struct BattleContext {
u8 selectedPartySlot[MAX_BATTLERS];
u8 switchedPartySlot[MAX_BATTLERS];
u8 aiSwitchedPartySlot[MAX_BATTLERS];

u32 battlerActions[MAX_BATTLERS][MAX_BATTLE_ACTIONS];
u8 battlerActionOrder[MAX_BATTLERS];
u8 monSpeedOrder[MAX_BATTLERS];
u32 monSpeedValues[MAX_BATTLERS];

u8 ioQueue[MAX_LINK_BATTLERS][MAX_BATTLERS][BATTLE_IO_QUEUE_SIZE];
u8 ioBuffer[MAX_BATTLERS][BATTLE_IO_BUFFER_SIZE];
int battleScript[BATTLE_SCRIPT_SIZE_MAX];
Expand Down Expand Up @@ -282,7 +282,7 @@ struct BattleContext {
u16 padding310A;

u16 speedRand[MAX_BATTLERS];

int flingTemp;
int flingScript;

Expand Down
Loading
Loading