Skip to content

Commit

Permalink
Enable clangd integration & revamp VS Code config
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed Oct 12, 2024
1 parent 5eb6264 commit 8768673
Show file tree
Hide file tree
Showing 21 changed files with 382 additions and 167 deletions.
46 changes: 28 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
__pycache__/
*.dol
*.dump
*.exe
*.map
build/
ctx.c
tools/elf2dol
tools/elf2rel
tools/metroidbuildinfo
tools/mwcc_compiler
*.bat
# IDE folders
.idea/
versions/
build.ninja
.ninja_deps
.ninja_lock
.ninja_log
objdiff.json
.vs/
.vscode/

# Caches
__pycache__
.mypy_cache
.cache/

# Original files
orig/*/*
!orig/*/.gitkeep

# Build files
build/
.ninja_*
build.ninja

# decompctx output
ctx.*
*.ctx

# Generated configs
objdiff.json
compile_commands.json

# Miscellaneous
/*.txt
*.exe
*.dol
26 changes: 0 additions & 26 deletions .vscode/c_cpp_properties.json

This file was deleted.

10 changes: 8 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"recommendations": [
"ms-vscode.cpptools",
"akiramiyakoda.cppincludeguard",
"ms-python.black-formatter"
"llvm-vs-code-extensions.vscode-clangd",
"ms-python.black-formatter",
"ms-python.flake8",
],
"unwantedRecommendations": [
"ms-vscode.cmake-tools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cpptools",
]
}
18 changes: 7 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
{
"[c]": {
"files.encoding": "utf8",
"editor.defaultFormatter": "ms-vscode.cpptools"
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
},
"[cpp]": {
"files.encoding": "utf8",
"editor.defaultFormatter": "ms-vscode.cpptools"
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"clangd.arguments": ["--header-insertion=never"],
"clangd.fallbackFlags": [
"-I${workspaceFolder}/include",
"-I${workspaceFolder}/libc",
"-I${workspaceFolder}/extern/musyx/include",
"-D__MWERKS__",
],
"editor.tabSize": 2,
"files.associations": {
"source_location": "cpp",
"*.h": "c",
"*.inc": "c"
"*.inc": "c",
".clangd": "yaml",
},
"files.autoSave": "onFocusChange",
"files.insertFinalNewline": true,
Expand Down Expand Up @@ -50,5 +44,7 @@
"C/C++ Include Guard.Auto Update Path Blocklist": [
"include/zlib"
],
"cmake.configureOnOpen": false
"cmake.configureOnOpen": false,
// Disable C++ intellisense engine, use clangd instead
"C_Cpp.intelliSenseEngine": "disabled"
}
32 changes: 2 additions & 30 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
// Use Ctrl+Shift+B to run build tasks.
// Or "Run Build Task" in the Command Palette.
"version": "2.0.0",
"tasks": [
{
"label": "ninja",
"type": "shell",
"command": "ninja",
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "all_source",
"type": "shell",
"command": "ninja all_source",
"group": "build",
"problemMatcher": []
},
{
"label": "all_source_host",
"type": "shell",
"command": "ninja all_source_host",
"problemMatcher": {
"base": "$gcc"
},
"group": "build"
},
{
"label": "current file (host)",
"type": "shell",
"command": "ninja host/${relativeFile}",
"problemMatcher": {
"base": "$gcc"
},
"group": {
"kind": "build",
"isDefault": true
Expand Down
4 changes: 2 additions & 2 deletions include/Kyoto/Alloc/CMemory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CMemory {
static void* Alloc(size_t len, IAllocator::EHint hint = IAllocator::kHI_None,
IAllocator::EScope scope = IAllocator::kSC_Unk1,
IAllocator::EType type = IAllocator::kTP_Heap,
const CCallStack& callstack = CCallStack(-1, "??(??)"));
const CCallStack& callstack = CCallStack(-1, "\?\?(\?\?)"));
static void Free(const void* ptr);
static void SetOutOfMemoryCallback(IAllocator::FOutOfMemoryCb callback, const void* context);
static void OffsetFakeStatics(int);
Expand All @@ -32,7 +32,7 @@ void* operator new(size_t sz, const char*, const char*);
void* operator new[](size_t sz, const char*, const char*);
inline void operator delete(void* ptr) { CMemory::Free(ptr); }
inline void operator delete[](void* ptr) { CMemory::Free(ptr); }
#define rs_new new ("??(??)", nullptr)
#define rs_new new ("\?\?(\?\?)", nullptr)
#else
void operator delete(void* ptr);
void operator delete[](void* ptr);
Expand Down
2 changes: 1 addition & 1 deletion include/Kyoto/Particles/IElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IElement {

// -> CFrameDelayedKiller
void* operator new(size_t sz, const char*, const char*);
void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); }
void* operator new(size_t sz) { return operator new(sz, "\?\?(\?\?)", nullptr); }
void operator delete(void* ptr, size_t sz);
};

Expand Down
2 changes: 1 addition & 1 deletion include/Kyoto/TOneStatic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ template < typename T >
class TOneStatic {
public:
void* operator new(size_t sz, const char*, const char*);
void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); }
void* operator new(size_t sz) { return operator new(sz, "\?\?(\?\?)", nullptr); }
void operator delete(void* ptr);

private:
Expand Down
15 changes: 11 additions & 4 deletions include/dolphin/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,25 @@ typedef int BOOL;
#define NULL 0
#endif
#endif

#if !defined(__cplusplus) || __cplusplus < 201103L
// Define nullptr as NULL
#ifndef nullptr
#define nullptr NULL
#endif
#endif // !defined(__cplusplus) || __cplusplus < 201103L

#if defined(__MWERKS__)
#if defined(__cplusplus) && __cplusplus < 201103L
#if defined(__clang__)
// Allow override in < C++11 mode with clangd
#pragma clang diagnostic ignored "-Wc++11-extensions"
#else
// Define override as nothing
#ifndef override
#define override
#endif
#endif

#endif
#endif // defined(__clang__)
#endif // defined(__cplusplus) && __cplusplus < 201103L

#ifndef ATTRIBUTE_ALIGN
#if defined(__MWERKS__) || defined(__GNUC__)
Expand Down
10 changes: 5 additions & 5 deletions include/rstl/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ class list {
return *this;
}
iterator operator--(int) { return iterator(this->curent->x0_prev); }
T* get_pointer() const { return current->get_value(); }
T& operator*() const { return *current->get_value(); }
T* operator->() const { return current->get_value(); }
bool operator==(const iterator& other) const { return current == other.current; }
bool operator!=(const iterator& other) const { return current != other.current; }
T* get_pointer() const { return this->current->get_value(); }
T& operator*() const { return *this->current->get_value(); }
T* operator->() const { return this->current->get_value(); }
bool operator==(const iterator& other) const { return this->current == other.current; }
bool operator!=(const iterator& other) const { return this->current != other.current; }
};

private:
Expand Down
4 changes: 2 additions & 2 deletions include/rstl/pointer_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ class pointer_iterator : public const_pointer_iterator< T, Vec, Alloc > {
return *this;
}
pointer_iterator operator+(int v) const {
return pointer_iterator(current + v);
return pointer_iterator(this->current + v);
}
pointer_iterator operator-(int v) const {
return pointer_iterator(current - v);
return pointer_iterator(this->current - v);
}
// HACK: non-const operator- is required to match vector::insert
difference_type operator-(const pointer_iterator& other) { return this->current - other.current; }
Expand Down
2 changes: 1 addition & 1 deletion include/rstl/single_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ single_ptr< T >& single_ptr< T >::Set(T* ptr) {
return *this = ptr;
}

typedef single_ptr< void > unk_singleptr;
typedef single_ptr< int > unk_singleptr;
CHECK_SIZEOF(unk_singleptr, 0x4);
} // namespace rstl

Expand Down
2 changes: 1 addition & 1 deletion include/rstl/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ typename vector< T, Alloc >::iterator vector< T, Alloc >::erase(iterator first,
return first;
}

typedef vector< void > unk_vector;
typedef vector< int > unk_vector;
CHECK_SIZEOF(unk_vector, 0x10)
} // namespace rstl

Expand Down
7 changes: 6 additions & 1 deletion include/static_assert.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// C++98 static assert

#ifdef __MWERKS__
struct false_type {
static const int value = 0;
};
Expand All @@ -17,7 +18,6 @@ struct _n_is_equal< A, A > : true_type {};
template < class T, int N >
struct check_sizeof : _n_is_equal< sizeof(T), N > {};

#ifdef __MWERKS__
#ifndef offsetof
typedef unsigned long size_t;
#define offsetof(type, member) ((size_t) & (((type*)0)->member))
Expand All @@ -26,6 +26,11 @@ typedef unsigned long size_t;
#define NESTED_CHECK_SIZEOF(parent, cls, size) extern int cls##_check[check_sizeof< parent::cls, size >::value];
#define CHECK_OFFSETOF(cls, member, offset) \
extern int cls##_check_offset##[_n_is_equal< offsetof(cls, member), offset >::value];
#elif defined(__clang__) && defined(__powerpc__) // Enable for clangd
#pragma clang diagnostic ignored "-Wc++17-extensions" // Allow _Static_assert without message
#define CHECK_SIZEOF(cls, size) _Static_assert(sizeof(cls) == size);
#define NESTED_CHECK_SIZEOF(parent, cls, size) _Static_assert(sizeof(parent::cls) == size);
#define CHECK_OFFSETOF(cls, member, offset) _Static_assert(offsetof(cls, member) == offset);
#else
#define CHECK_SIZEOF(cls, size)
#define NESTED_CHECK_SIZEOF(parent, cls, size)
Expand Down
5 changes: 5 additions & 0 deletions libc/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ static inline int __fpclassifyd(double x) {
#define isinf(x) (fpclassify(x) == FP_INFINITE)
#define isfinite(x) ((fpclassify(x) > FP_INFINITE))

#ifdef __MWERKS__
extern inline float sqrtf(float x) {
static const double _half = .5;
static const double _three = 3.0;
Expand Down Expand Up @@ -198,6 +199,10 @@ _MATH_INLINE double sqrt(double x) {
}
return INFINITY;
}
#else
float sqrtf(float x);
double sqrt(double x);
#endif

static inline float ldexpf(float x, int exp) { return (float)ldexp((double)x, exp); }
static inline double scalbn(double x, int n) { return ldexp(x, n); }
Expand Down
2 changes: 1 addition & 1 deletion src/Kyoto/CARAMManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool CARAMManager::Initialize(uint chunkSize) {
mpARAMStart = ARAlloc(chunkSize * numChunks);
mpBookKeepingMemory = (uint*)CMemory::Alloc(numChunks * 4, IAllocator::kHI_None,
IAllocator::kSC_Unk1, IAllocator::kTP_Heap,
CCallStack(-1, "??(??)"));
CCallStack(-1, "\?\?(\?\?)"));
CMemory::OffsetFakeStatics(mNumChunks * 4);

for (uint i = 0; i < numChunks; ++i) {
Expand Down
6 changes: 3 additions & 3 deletions src/MetroidPrime/Decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ CArchitectureMessage MakeMsg::CreateControllerStatus(EArchMsgTarget target, cons
}

CArchitectureMessage MakeMsg::CreateQuitGameplay(EArchMsgTarget target) {
return CArchitectureMessage(target, kAM_QuitGameplay, new("??(??)", nullptr) CArchMsgParmNull());
return CArchitectureMessage(target, kAM_QuitGameplay, rs_new CArchMsgParmNull());
}

CArchitectureMessage MakeMsg::CreateFrameBegin(EArchMsgTarget target, const int& a) {
return CArchitectureMessage(target, kAM_FrameBegin, new("??(??)", nullptr) CArchMsgParmInt32(a));
return CArchitectureMessage(target, kAM_FrameBegin, rs_new CArchMsgParmInt32(a));
}

const CArchMsgParmInt32& MakeMsg::GetParmFrameBegin(const CArchitectureMessage& msg) {
return *static_cast< const CArchMsgParmInt32* >(msg.GetParm());
}

CArchitectureMessage MakeMsg::CreateFrameEnd(EArchMsgTarget target, const int& a) {
return CArchitectureMessage(target, kAM_FrameEnd, new("??(??)", nullptr) CArchMsgParmInt32(a));
return CArchitectureMessage(target, kAM_FrameEnd, rs_new CArchMsgParmInt32(a));
}
6 changes: 4 additions & 2 deletions src/MetroidPrime/Player/CPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,11 @@ void CPlayer::Update(float dt, CStateManager& mgr) {
switch (x2f8_morphBallState) {
case kMS_Unmorphed:
case kMS_Morphing:
case kMS_Unmorphing:
case kMS_Unmorphing: {
CTransform4f gunXf = GetModelData()->GetScaledLocatorTransform(rstl::string_l(kGunLocator));
x7f4_gunWorldXf = GetTransform() * gunXf;
break;
}
case kMS_Morphed:
break;
}
Expand Down Expand Up @@ -2005,7 +2006,8 @@ void CPlayer::UpdateFreeLook(float dt) {
}

angleVelP = x3e8_horizFreeLookAngleVel - x3e4_freeLookYawAngle;
dx = lookDeltaAngle * CMath::Clamp(0.f, fabsf(angleVelP / gpTweakPlayer->GetHorizontalFreeLookAngleVel()), 1.f);
dx = lookDeltaAngle *
CMath::Clamp(0.f, fabsf(angleVelP / gpTweakPlayer->GetHorizontalFreeLookAngleVel()), 1.f);
if (0.f <= angleVelP) {
x3e4_freeLookYawAngle += dx;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/MetroidPrime/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const char* s1 = "MiscSamus_AGSC";
const char* s2 = "UI_AGSC";
const char* s3 = "Weapons_AGSC";
const char* s4 = "ZZZ_AGSC";
const char* s5 = "??(??)";
const char* s5 = "\?\?(\?\?)";
const char* s6 = "";
const char* s7 = "%d";
const char* st8 = ".pak";
Expand Down
Loading

0 comments on commit 8768673

Please sign in to comment.