Skip to content

Commit

Permalink
git subrepo pull --force --branch=master spm-headers
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "spm-headers"
  merged:   "fd4c37f"
upstream:
  origin:   "https://github.com/SeekyCt/spm-headers.git"
  branch:   "master"
  commit:   "fd4c37f"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
  • Loading branch information
SeekyCt committed Jan 5, 2025
1 parent d443cf0 commit cc08cd8
Show file tree
Hide file tree
Showing 49 changed files with 479 additions and 218 deletions.
2 changes: 1 addition & 1 deletion spm-headers/.github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
region: [eu0, eu1, us0, us1, us2, jp0, jp1, kr0]
test: [mod_ctx, old_mod_ctx, decomp_ctx, mod_ctx_shuffle, test_mod_individual]
test: [mod_ctx, decomp_ctx, mod_ctx_shuffle, test_mod_individual]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions spm-headers/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
build
build.ninja
*.bat
.vscode
.cache
compile_commands.json
6 changes: 3 additions & 3 deletions spm-headers/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
;
[subrepo]
remote = https://github.com/SeekyCt/spm-headers.git
branch = decomp
commit = 4095228f03909bff88f65c58d092406050ec5ed6
parent = a5c9015f88d01bf95c26b4bbd9a755e5dd698e2f
branch = master
commit = fd4c37f1f6d9d3c4d06c031738ead2e8d7106704
parent = d443cf036b530e77ae8c249647c227a0656970f8
method = merge
cmdver = 0.4.9
13 changes: 12 additions & 1 deletion spm-headers/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## C++ notes
- Most headers are designed to be compileable in C and C++
- The CPP_WRAPPER macro allows for the file's namespace to be dropped when compiling in C and for `extern "C"` to
be inserted when compiling in C++
- The headers in the spm folder where the game used C++ features should still have C support
- These are rare, so it's less effort than supporting C++ in nw4r would be, and more useful
- Use `#ifdef __cplusplus` and padding where neccessary to achieve this
- The headers in the nw4r folder don't have C support since they were written in C++ originally
- They therefore don't use the CPP_WRAPPER macro
- They're named .hpp instead of .h to indicate this

## Naming

- Use official names when possible (from TTYD symbol map, asserts, etc.), and try to follow the style otherwise
Expand Down Expand Up @@ -30,7 +41,7 @@
- Wrap files in CPP_WRAPPER from where includes finish to the end of the file
- The name passed in should be `folder::filename` (for example, `spm::evtmgr`)
- `common.h` and the variants of `evt_cmd.h` are exceptions to this
- This won't apply to nw4r headers' code they're done properly
- This doesn't apply to nw4r headers' as they're done with real C++
- Wrap file-local and function-local symbols in DECOMP_STATIC in headers (for example, `DECOMP_STATIC(evtmgr_work)`)
- Add offset comments on the left of every struct member
- Add value comments on the left of every enum member
Expand Down
8 changes: 3 additions & 5 deletions spm-headers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ For use in decomp, the `include`, `include_cpp` and `decomp` folders should be a

## Mods

For use in mods, the `include`, `include_cpp` and `mod` folder should be added to the include path and an lst from `linker` should be used. If including your compiler's C++ standard library, the preprocessor define `USE_STL` should be used.
For use in mods, the `include` and `mod` folders should be added to the include path and an lst from `linker` should be used. Mods should include their compiler's standard library headers (do not use `-nostdinc`), though linking it is not required (so `-nostdlib` is fine).

## C

For the cases where C is required (such as m2c or maybe some niche modding cases), omitting the `include_cpp` folder should be all that's neccessary.
**Warning**: NW4R headers are probably unsafe to use with GCC currently

# Licensing

All code originally written for this project (everything under the `include`, `include_cpp`, `decomp` and `linker` directories) is available under the MIT license.
All code originally written for this project (everything under the `include`, `decomp` and `linker` directories) is available under the MIT license.

Everything under the `mod` folder is available under the GPLv3 license as it's derived from other GPL code.

Expand Down
16 changes: 5 additions & 11 deletions spm-headers/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

parser = ArgumentParser()
parser.add_argument("tests", type=str, nargs="*", help="Tests to run" \
"(mod_ctx, old_mod_ctx, decomp_ctx, mod_ctx_shuffle, test_mod_individual)")
"(mod_ctx, decomp_ctx, mod_ctx_shuffle, test_mod_individual)")
parser.add_argument("--regions", type=str, nargs="+", help="Regions to test")
parser.add_argument("--seed", type=int, default=1, help="Shuffling seed")
parser.add_argument("--shuffle", type=int, default=50, help="Number of randomised orders to test")
Expand Down Expand Up @@ -231,14 +231,9 @@ def find_headers(dirname: str, base=None) -> List[str]:

return ret

# Test the headers in the spm-utils modding setup
# Test the headers in the modding setup
def test_mod_ctx(regions: List[str]):
compile_regions(os.path.join("$builddir", "{region}", "mod.o"), "$mod_source", regions,
MOD_INCLUDES, ["USE_STL"])

# Test the headers in the old modding setup
def test_old_mod_ctx(regions: List[str]):
compile_regions(os.path.join("$builddir", "{region}", "old_mod.o"), "$mod_source", regions,
MOD_INCLUDES, [])

# Test the headers in the decomp setup
Expand All @@ -254,7 +249,7 @@ def test_mod_ctx_shuffle(regions: List[str]):
source = os.path.join("$builddir", f"shuffle_{args.seed}", f"{i}.cpp")
incgen(source, MOD_INCLUDES, i)
compile_regions(os.path.join("$builddir", "{region}", f"shuffle_mod_{args.seed}_{i}.o"),
source, regions, MOD_INCLUDES, ["USE_STL"])
source, regions, MOD_INCLUDES, [])

# Test individual headers
def test_mod_individual(regions: List[str]):
Expand All @@ -263,18 +258,17 @@ def test_mod_individual(regions: List[str]):
source = os.path.join("$builddir", "individual", f"{name}.c")
incgen_single(source, header)
compile_regions(os.path.join("$builddir", "{region}", "individual", f"{name}.o"), source,
regions, MOD_INCLUDES, ["USE_STL", "SPM_EU0"])
regions, MOD_INCLUDES, ["SPM_EU0"])

test_fns = {
"mod_ctx" : test_mod_ctx,
"old_mod_ctx" : test_old_mod_ctx,
"decomp_ctx" : test_decomp_ctx,
"mod_ctx_shuffle" : test_mod_ctx_shuffle,
"test_mod_individual" : test_mod_individual,
}

incgen("$mod_source", MOD_INCLUDES)
default_tests = ["mod_ctx", "old_mod_ctx"]
default_tests = ["mod_ctx"]

if args.codewarrior:
incgen("$decomp_source", DECOMP_INCLUDES)
Expand Down
12 changes: 12 additions & 0 deletions spm-headers/decomp/stdbool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <common.h>

#ifndef __cplusplus

#define bool _Bool
#define true 1
#define false 0

#endif

14 changes: 14 additions & 0 deletions spm-headers/decomp/stddef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <common.h>

#define NULL 0

typedef s32 ptrdiff_t;
typedef __typeof__(sizeof(0)) size_t;

#define offsetof(type, member) ((size_t)&((type *)0)->member)

#ifndef __cplusplus
typedef u16 wchar_t;
#endif
119 changes: 51 additions & 68 deletions spm-headers/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,71 +20,11 @@
#define HAS_ATTRIBUTE(x) 0
#endif

// Basic types

// Decomp needs long for matching, int is slightly more convenient for casting in mods
#ifdef DECOMP
#define INT_TYPE long
#else
#define INT_TYPE int
#endif

typedef unsigned long long u64;
typedef unsigned INT_TYPE u32;
typedef unsigned short u16;
typedef unsigned char u8;

typedef signed long long s64;
typedef signed INT_TYPE s32;
typedef signed short s16;
typedef signed char s8;

#undef INT_TYPE

typedef float f32;
typedef double f64;

#ifdef USE_STL
#include <cstddef>
static_assert(sizeof(size_t) == 4, "Expected 32-bit size_t");
#else
typedef u32 size_t;
#define NULL 0
#if HAS_BUILTIN(__builtin_offsetof)
#define offsetof __builtin_offsetof
#else
#define offsetof(type, member) ((u32)&((type *)0)->member)
#endif
#endif

typedef s32 BOOL;

#ifndef __cplusplus
#define bool char

#define true 1
#define false 0
#endif

#ifndef __cplusplus
#define wchar_t s16
#endif

#ifdef DECOMP
typedef wchar_t wchar16_t;
#else
typedef s16 wchar16_t;
#endif

// Unknown type
typedef u32 Unk;
typedef u32 Unk32;
typedef u16 Unk16;
typedef u8 unk8;

// Use CW special static assert
// Use required static_assert keyword
#ifdef __MWERKS__
#define static_assert(cond, msg) __static_assert(cond, msg)
#define static_assert __static_assert
#elif !(defined __cplusplus)
#define static_assert _Static_assert
#endif

// Macro for quick size static assert
Expand Down Expand Up @@ -152,7 +92,7 @@ typedef u8 unk8;
#define ATTRIBUTE(x)
#endif

#if HAS_ATTRIBUTE(noreturn)
#if HAS_ATTRIBUTE(noreturn) && (defined __cplusplus) // TODO: the usage sites are probabably what should be fixed here
#define NORETURN ATTRIBUTE(noreturn)
#else
#define NORETURN
Expand All @@ -166,6 +106,49 @@ typedef u8 unk8;
#define ATTRIBUTE_FORMAT(...)
#endif

#define SQUARE(x) ((x) * (x))
#define CUBE(x) ((x) * (x) * (x))
#define QUART(x) ((x) * (x) * (x) * (x))
// Basic types

// Decomp needs long for matching, int is slightly more convenient for casting in mods
#ifdef DECOMP
#define INT_TYPE long
#else
#define INT_TYPE int
#endif

typedef unsigned long long u64;
typedef unsigned INT_TYPE u32;
typedef unsigned short u16;
typedef unsigned char u8;

typedef signed long long s64;
typedef signed INT_TYPE s32;
typedef signed short s16;
typedef signed char s8;

#undef INT_TYPE

typedef float f32;
typedef double f64;

typedef int BOOL;

#ifdef M2C
#define wchar_t u16
#define bool char
#endif

#include <stddef.h>
#include <stdbool.h>

// wchar_t is 32-bit in GCC but 16-bit in CW
#ifdef DECOMP
typedef wchar_t wchar16_t;
#else
typedef u16 wchar16_t;
#endif

// Unknown type
typedef u32 Unk;
typedef u32 Unk32;
typedef u16 Unk16;
typedef u8 unk8;
9 changes: 9 additions & 0 deletions spm-headers/include/msl/errno.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <common.h>

CPP_WRAPPER(msl::errno)

s32 errno;

CPP_WRAPPER_END()
File renamed without changes.
6 changes: 6 additions & 0 deletions spm-headers/include/msl/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

CPP_WRAPPER(msl::math)

typedef float float_t;
typedef double double_t;

#define PI 3.141592653589793f
#define PIx2 (PI * 2.0f)

Expand All @@ -23,4 +26,7 @@ double sqrt(double x);
#define fabsf(x) __fabsf(x)
#define abs(x) __abs(x)

double ceil(double x);
#define ceilf(x) ((f32)ceil(x))

CPP_WRAPPER_END()
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// TODO: does this actually need to be hidden for modding?
#ifdef DECOMP

#include <msl/exception.h>
#include <msl/exception>

namespace std {

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <common.h>
#include <nw4r/lyt/resourceAccessor.h>
#include <nw4r/ut/linkList.h>
#include <nw4r/lyt/resourceAccessor.hpp>
#include <nw4r/ut/linkList.hpp>

namespace nw4r {
namespace lyt {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <common.h>
#include <nw4r/math/types.h>
#include <nw4r/ut/rect.h>
#include <nw4r/math/types.hpp>
#include <nw4r/ut/rect.hpp>

namespace nw4r {
namespace lyt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

#include <common.h>
#include <wii/mem.h>
#include <msl/new.h>
#include <nw4r/lyt/animation.h>
#include <nw4r/lyt/pane.h>
#include <nw4r/lyt/resourceAccessor.h>
#include <nw4r/ut/rect.h>
#include <msl/new>
#include <nw4r/lyt/animation.hpp>
#include <nw4r/lyt/drawInfo.hpp>
#include <nw4r/lyt/pane.hpp>
#include <nw4r/lyt/resourceAccessor.hpp>
#include <nw4r/ut/rect.hpp>

namespace nw4r {
namespace lyt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <common.h>
#include <wii/gx.h>
#include <nw4r/ut/linkList.h>
#include <nw4r/ut/linkList.hpp>

namespace nw4r {
namespace lyt {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include <common.h>
#include <msl/new.h>
#include <nw4r/lyt/animation.h>
#include <nw4r/lyt/material.h>
#include <nw4r/lyt/resourceAccessor.h>
#include <msl/new>
#include <nw4r/lyt/animation.hpp>
#include <nw4r/lyt/material.hpp>
#include <nw4r/lyt/resourceAccessor.hpp>

namespace nw4r {
namespace lyt {
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit cc08cd8

Please sign in to comment.