From 015ce283b47d5cd15b349bde600cb5b97e7247b7 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Thu, 21 Dec 2023 10:52:51 -0500 Subject: [PATCH] Match over 20 new funcs in sf 77e40 (#55) * Match func_8007B9DC and func_8007BB14 * Remove macro and add debug notices * Fix merge diff * Match func_8007BC7C * Match func_8007BCE8 * Match func_8007BDE0 * Match func_8007BE54 and an audio func func_8001A500 * Match func_8007BEE8 * Match func_8007BF64 * Match func_8007BFFC * Match func_8007C088 * Match func_8007C120 * Match func_8007C1AC * Match func_8007C250 * Fix merge from master * Match func_8007C3B4 * Match func_8007C484 and func_8007C50C * Match func_8007C608 and func_8007C688 * Match func_8007C6FC and func_8007C85C * Match func_8007C8C4 * Add a progress script WIP --- Makefile | 1 + include/functions.h | 18 ++- include/hud.h | 2 +- src/main/sf_77E40.c | 323 ++++++++++++++++++++++++++++++++++--- src/main/sys_audio_17650.c | 14 +- tools/progress.py | 114 +++++++++++++ 6 files changed, 441 insertions(+), 31 deletions(-) create mode 100644 tools/progress.py diff --git a/Makefile b/Makefile index e1ed8cbf..43e90157 100644 --- a/Makefile +++ b/Makefile @@ -230,6 +230,7 @@ $(shell mkdir -p $(BUILD_DIR)/linker_scripts/$(VERSION) $(BUILD_DIR)/linker_scri # directory flags # per-file flags +build/src/main/sys_audio_17650.o: OPTFLAGS := -O2 -g0 build/src/main/sys_audio_1EB50.o: OPTFLAGS := -O1 -g0 build/src/main/sys_sprintf.o: OPTFLAGS := -O2 -g0 build/src/main/sys_math64.o: OPTFLAGS := -O2 -g0 diff --git a/include/functions.h b/include/functions.h index 6c2dec96..5924e14b 100644 --- a/include/functions.h +++ b/include/functions.h @@ -23,7 +23,9 @@ u8* func_8001C3EC(void); void func_80016A50(void); void func_800182F4(s32); void func_80019218(u32, Vec3f*, u8, f32*, f32*, s8*); -void func_8001A500(Vec3f*); +void func_80019290(s32, Vec3f**); +void func_8001A38C(u8, Vec3f*); +void func_8001A500(Vec3f* sfxPos); void func_8001A55C(Vec3f*, u32); void func_8001A838(u32); void func_8001ACDC(s32); @@ -196,7 +198,7 @@ void func_80060968(void); void func_80060F30(Vec3f* , u32 , s32 ); void Object_Kill(Object*, Vec3f*); s32 func_80060FE4(Vec3f*, f32); -void Object_SetInfo(ObjectInfo*, u32); +void Object_SetInfo(ObjectInfo* info, u32 objId); void Object_80_Initialize(Object_80*); void Object_4C_Initialize(Object_4C*); void Object_2F4_Initialize(Object_2F4*); @@ -348,19 +350,20 @@ void func_8007B67C(Object_8C*); void func_8007B758(Object_8C*); void func_8007B8F8(f32 posX, f32 posY, f32 posZ, f32 ); void func_8007B960(Object_8C*); -void func_8007BC7C(f32, f32, f32, f32); +void func_8007BC7C(f32 posX, f32 posY, f32 posZ, f32); void func_8007BCE8(Object_8C*); void func_8007B9DC(Object_8C*); void func_8007BDE0(Object_8C*); void func_8007BE54(Object_8C*); void func_8007BEE8(Object_8C*); -void func_8007BFFC(f32, f32, f32, f32, f32, f32, f32, s32); -void func_8007C120(f32, f32, f32, f32, f32, f32, f32, s32); +void func_8007BFFC(f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg6, s32 arg7); +void func_8007C120(f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg6, s32 arg7); void func_8007C250(Object_8C*); -void func_8007C484(f32, f32, f32, f32, f32, f32, f32, s32); +void func_8007C484(f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg6, s32 arg7); void func_8007C50C(Object_8C*); -void func_8007C688(f32 , f32 , f32 , f32 , s32 ); +void func_8007C688(f32 posX, f32 posY, f32 posZ, f32 arg3, s32 arg4); void func_8007C8C4(Object_8C*); +void func_8007C85C(f32 posX, f32 posY, f32 posZ, f32 arg3); void func_8007C9E0(Object_8C*); void func_8007CAF0(Object_8C*); void func_8007D074(f32, f32, f32, f32); @@ -483,6 +486,7 @@ s32 Play_GetMaxShields(void); void func_800A5844(void); void func_800A5D6C(void); void func_800A5FA0(Vec3f* , u32 , s32 ); +void func_800A6070(Vec3f* arg0, u32 arg1); void func_800A6148(void); void func_800A69F8(s32 , f32 , f32 , f32 ); void func_800A6CD0(Player *, s32, s32); diff --git a/include/hud.h b/include/hud.h index 9960b993..77d658d5 100644 --- a/include/hud.h +++ b/include/hud.h @@ -55,7 +55,7 @@ extern s32 D_1011E60[]; extern s32 D_1013580[]; extern s32 D_1013700[]; extern s32 D_20031B0[]; -extern s32 D_2010A30[]; +extern Gfx D_2010A30[]; extern u16 D_3000B20[]; extern u16 D_30013E0[]; diff --git a/src/main/sf_77E40.c b/src/main/sf_77E40.c index 6dc82837..97322506 100644 --- a/src/main/sf_77E40.c +++ b/src/main/sf_77E40.c @@ -1,4 +1,5 @@ #include "global.h" +#include "hud.h" void func_80077240(f32 posX, f32 posY, f32 posZ, s32 hits) { s32 i; @@ -1254,47 +1255,327 @@ void func_8007B960(Object_8C* obj8C) { obj8C->unk_54.y += 0.2f; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007B9DC.s") +void func_8007B9DC(Object_8C* arg0) { + //! DEBUG + if (gControllerHold[3].button & Z_TRIG) { + RCP_SetupDL(&gMasterDisp, 4); + } + func_8005980C(arg0->unk_70); + if (gCurrentLevel != LEVEL_MACBETH) { + gDPSetPrimColor(gMasterDisp++, 0, 0, 140, 99, 58, arg0->unk_4A); + } else { + gDPSetPrimColor(gMasterDisp++, 0, 0, (gFrameCount & 3) + 5, (gFrameCount & 3) + 3, (gFrameCount & 3) + 3, 220); + } + //! DEBUG + if (!(gControllerHold[3].button & A_BUTTON)) { + gSPDisplayList(gMasterDisp++, D_2010A30); + } + //! DEBUG + if (gControllerHold[3].button & Z_TRIG) { + RCP_SetupDL(&gMasterDisp, 0x40); + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007BB14.s") +void func_8007BB14(Object_8C* arg0, f32 posX, f32 posY, f32 posZ, f32 arg4) { + Object_8C_Initialize(arg0); + arg0->obj.status = 1; + arg0->obj.id = OBJ_8C_362; + arg0->obj.pos.x = posX; + arg0->obj.pos.y = posY; + arg0->obj.pos.z = posZ; + arg0->unk_54.x = (Rand_ZeroOne() - 0.5f) * 5.0f; + arg0->unk_54.y = (Rand_ZeroOne() - 0.5f) * 3.0f; + arg0->unk_48 = 3; + if (Rand_ZeroOne() < 0.5f) { + arg0->unk_48 = -arg0->unk_48; + } + arg0->unk_4A = 0xB4; + arg0->unk_46 = 8; + if (arg4 > 15.0f) { + arg0->unk_46 = 5; + arg0->unk_4A = 0x50; + } + arg0->unk_70 = arg4 * 0.25f; + arg0->obj.rot.z = Rand_ZeroOne() * 360.0f; + if (arg4 == 6.0f) { + arg0->unk_54.z = gPlayer->unk_0C0.z * 0.6f; + } + Object_SetInfo(&arg0->info, arg0->obj.id); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007BC7C.s") +void func_8007BC7C(f32 posX, f32 posY, f32 posZ, f32 arg3) { + s32 i; -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007BCE8.s") + for (i = ARRAY_COUNT(gObjects8C) - 20; i >= 0; i--) { + if (gObjects8C[i].obj.status == 0) { + func_8007BB14(&gObjects8C[i], posX, posY, posZ, arg3); + break; + } + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007BDE0.s") +void func_8007BCE8(Object_8C* arg0) { + if (gPlayer->unk_1C8 == 7) { + arg0->obj.rot.x = (gPlayer->unk_05C * 180.0f) / M_PI; + arg0->obj.rot.y = (-gPlayer->unk_058 * 180.0f) / M_PI; + } + if (gPlayer->unk_1C8 == 6) { + arg0->unk_46 = 2; + arg0->unk_54.y -= 0.13f; + } + arg0->unk_70 += 0.07f; + arg0->unk_4A -= arg0->unk_46; + if (arg0->unk_4A < 0) { + Object_Kill(&arg0->obj, &arg0->sfxPos); + } + arg0->obj.rot.z += arg0->unk_48; + arg0->unk_54.y += 0.2f; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007BE54.s") +void func_8007BDE0(Object_8C* arg0) { + arg0->unk_70 += 0.04f; + arg0->unk_4A -= 2; + if (arg0->unk_4A < 0) { + Object_Kill(&arg0->obj, &arg0->sfxPos); + } + arg0->obj.rot.z += arg0->unk_48; + arg0->unk_54.y += arg0->unk_6C; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007BEE8.s") +void func_8007BE54(Object_8C* arg0) { + arg0->unk_70 += 0.02f; + arg0->unk_4A -= 3; + if (arg0->unk_4A < 0) { + Object_Kill(&arg0->obj, &arg0->sfxPos); + } + arg0->unk_54.z = gPlayer->unk_0C0.z + 7.0f; + arg0->obj.rot.z += arg0->unk_48; + arg0->unk_54.y += 0.1f; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007BF64.s") +void func_8007BEE8(Object_8C* arg0) { + func_8005980C(arg0->unk_70); + gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 255, arg0->unk_4A); + gSPDisplayList(gMasterDisp++, D_2010A30); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007BFFC.s") +void func_8007BF64(Object_8C* arg0, f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg7, s32 arg8) { + Object_8C_Initialize(arg0); + arg0->obj.status = 1; + arg0->obj.id = OBJ_8C_386; + arg0->obj.pos.x = posX; + arg0->obj.pos.y = posY; + arg0->obj.pos.z = posZ; + arg0->unk_54.x = x; + arg0->unk_54.y = y; + arg0->unk_54.z = z; + arg0->unk_70 = arg7; + arg0->unk_50 = arg8; + Object_SetInfo(&arg0->info, arg0->obj.id); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C088.s") +void func_8007BFFC(f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg6, s32 arg7) { + s32 i; -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C120.s") + for (i = ARRAY_COUNT(gObjects8C) - 1; i >= 0; i--) { + if (gObjects8C[i].obj.status == 0) { + func_8007BF64(&gObjects8C[i], posX, posY, posZ, x, y, z, arg6, arg7); + break; + } + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C1AC.s") +void func_8007C088(Object_8C* arg0, f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg7, s32 arg8) { + Object_8C_Initialize(arg0); + arg0->obj.status = 1; + arg0->obj.id = OBJ_8C_390; + arg0->obj.pos.x = posX; + arg0->obj.pos.y = posY; + arg0->obj.pos.z = posZ; + arg0->unk_54.x = x; + arg0->unk_54.y = y; + arg0->unk_54.z = z; + arg0->unk_70 = arg7; + arg0->unk_50 = arg8; + Object_SetInfo(&arg0->info, arg0->obj.id); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C250.s") +void func_8007C120(f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg6, s32 arg7) { + s32 i; -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C3B4.s") + for (i = ARRAY_COUNT(gObjects8C) - 1; i >= 0; i--) { + if (gObjects8C[i].obj.status == 0) { + func_8007C088(&gObjects8C[i], posX, posY, posZ, x, y, z, arg6, arg7); + break; + } + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C484.s") +void func_8007C1AC(f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg6, s32 arg7) { + s32 i; -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C50C.s") + for (i = ARRAY_COUNT(gObjects8C) - 1; i >= 0; i--) { + if (gObjects8C[i].obj.status == 0) { + func_8007BF64(&gObjects8C[i], posX, posY, posZ, x, y, z, arg6, arg7); + func_800A6070(&gObjects8C[i].sfxPos, 0x29000000); + break; + } + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C608.s") +void func_8007C250(Object_8C* arg0) { + f32 randX; + f32 randY; + f32 randOther; + s32 var_v0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C688.s") + Math_SmoothStepToF(&arg0->unk_54.x, 0.0f, 0.2f, 10.0f, 0.1f); + Math_SmoothStepToF(&arg0->unk_54.y, 0.0f, 0.2f, 10.0f, 0.1f); + Math_SmoothStepToF(&arg0->unk_54.z, 0.0f, 0.2f, 10.0f, 0.1f); + var_v0 = 3; + if (gAllRangeMode == 1) { + var_v0 = 1; + } + if (!(arg0->unk_50 & var_v0)) { + randX = (Rand_ZeroOne() - 0.5f) * 40.0f; + randY = (Rand_ZeroOne() - 0.5f) * 40.0f; + randOther = ((Rand_ZeroOne() * 0.5f) + 1.0f); + func_8007D0E0(arg0->obj.pos.x + randX, arg0->obj.pos.y + randY, arg0->obj.pos.z, arg0->unk_70 * randOther); + if (arg0->unk_50 == 0) { + Object_Kill(&arg0->obj, &arg0->sfxPos); + } + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C6FC.s") +void func_8007C3B4(Object_8C* arg0, f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg7, s32 arg8) { + Object_8C_Initialize(arg0); + arg0->obj.status = 1; + arg0->obj.id = OBJ_8C_389; + arg0->obj.pos.x = posX; + arg0->obj.pos.y = posY; + arg0->obj.pos.z = posZ; + arg0->unk_54.x = x; + arg0->unk_54.y = y; + arg0->unk_54.z = z; + arg0->unk_70 = arg7; + arg0->unk_4A = arg8; + arg0->unk_4C = (s32) (Rand_ZeroOne() * 12.0f); + arg0->obj.rot.z = Rand_ZeroOne() * 360.0f; + Object_SetInfo(&arg0->info, arg0->obj.id); + arg0->unk_44 = 0xFF; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C85C.s") +void func_8007C484(f32 posX, f32 posY, f32 posZ, f32 x, f32 y, f32 z, f32 arg6, s32 arg7) { + s32 i; -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C8C4.s") + for (i = ARRAY_COUNT(gObjects8C) - 1; i > 32; i--) { + if (gObjects8C[i].obj.status == 0) { + func_8007C3B4(&gObjects8C[i], posX, posY, posZ, x, y, z, arg6, arg7); + break; + } + } +} + +void func_8007C50C(Object_8C* arg0) { + f32 randX; + f32 randY; + f32 randOther; + + if (!(arg0->unk_50 & 7)) { + randX = (Rand_ZeroOne() - 0.5f) * 40.0f * arg0->unk_70; + randY = (Rand_ZeroOne() - 0.5f) * 40.0f * arg0->unk_70; + randOther = (Rand_ZeroOne() + 1.0f); + func_8007C484(arg0->obj.pos.x + randX, arg0->obj.pos.y + randY, arg0->obj.pos.z, arg0->unk_54.x, arg0->unk_54.y, + arg0->unk_54.z, arg0->unk_70 * randOther, 0); + if (arg0->unk_50 == 0) { + Object_Kill(&arg0->obj, &arg0->sfxPos); + } + } +} + +void func_8007C608(Object_8C* arg0, f32 posX, f32 posY, f32 posZ, f32 arg4, s32 arg5) { + Object_8C_Initialize(arg0); + arg0->obj.status = 1; + arg0->obj.id = OBJ_8C_387; + arg0->obj.pos.x = posX; + arg0->obj.pos.y = posY; + arg0->obj.pos.z = posZ; + arg0->unk_70 = arg4; + arg0->unk_50 = arg5; + Object_SetInfo(&arg0->info, arg0->obj.id); +} + +void func_8007C688(f32 posX, f32 posY, f32 posZ, f32 arg3, s32 arg4) { + s32 i; + + for (i = ARRAY_COUNT(gObjects8C) - 1; i >= 0; i--) { + if (gObjects8C[i].obj.status == 0) { + func_8007C608(&gObjects8C[i], posX, posY, posZ, arg3, arg4); + break; + } + } +} + +void func_8007C6FC(Object_8C* arg0, f32 posX, f32 posY, f32 posZ, f32 arg4) { + Object_8C_Initialize(arg0); + arg0->obj.status = 1; + arg0->obj.id = OBJ_8C_343; + arg0->obj.pos.x = posX; + arg0->obj.pos.y = posY; + arg0->obj.pos.z = posZ; + arg0->unk_48 = 3; + arg0->unk_54.y = 5.0f; + if (Rand_ZeroOne() < 0.5f) { + arg0->unk_48 = -arg0->unk_48; + } + if ((gCurrentLevel == LEVEL_FORTUNA) && (gPlayer->unk_1C8 != 6)) { + arg0->unk_4A = 180; + } else { + arg0->unk_4A = 255; + } + arg0->unk_70 = arg4 * 0.25f; + arg0->obj.rot.z = Rand_ZeroOne() * 360.0f; + arg0->unk_44 = 0; + if (Rand_ZeroOne() < 0.3f) { + arg0->unk_44 = 1; + arg0->unk_4A = 255; + arg0->unk_70 = arg4 * 0.3f; + } + arg0->unk_6C = Rand_ZeroOne() * 0.2f; + Object_SetInfo(&arg0->info, arg0->obj.id); +} + +void func_8007C85C(f32 posX, f32 posY, f32 posZ, f32 arg3) { + s32 i; + + for (i = 0; i < ARRAY_COUNT(gObjects8C) - 20; i++) { + if (gObjects8C[i].obj.status == 0) { + func_8007C6FC(&gObjects8C[i], posX, posY, posZ, arg3); + break; + } + } +} + +void func_8007C8C4(Object_8C* arg0) { + f32 randX; + f32 randY; + f32 randOther; + s32 var_v0; + + var_v0 = 0; + if ((gCurrentLevel == LEVEL_FORTUNA) && (gPlayer->unk_1C8 != 6)) { + var_v0 = 3; + } + if (!(arg0->unk_50 & var_v0) && (gLevelType == LEVELTYPE_GROUND)) { + randX = (Rand_ZeroOne() - 0.5f) * 10.0f; + randY = (Rand_ZeroOne() - 0.5f) * 10.0f; + randOther = ((Rand_ZeroOne() * 0.5f) + 1.0f); + func_8007C85C(arg0->obj.pos.x + randX, arg0->obj.pos.y + randY, arg0->obj.pos.z, arg0->unk_70 * randOther); + if (arg0->unk_50 == 0) { + Object_Kill(&arg0->obj, &arg0->sfxPos); + } + } +} #pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_77E40/func_8007C9E0.s") diff --git a/src/main/sys_audio_17650.c b/src/main/sys_audio_17650.c index b3c54a28..5fa1a00f 100644 --- a/src/main/sys_audio_17650.c +++ b/src/main/sys_audio_17650.c @@ -1,4 +1,4 @@ -#include "common.h" +#include "global.h" void func_80016A50(void) { } @@ -77,7 +77,17 @@ void func_80016A50(void) { #pragma GLOBAL_ASM("asm/us/nonmatchings/main/sys_audio_17650/func_8001A4B8.s") -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sys_audio_17650/func_8001A500.s") +void func_8001A500(Vec3f* sfxPos) { + Vec3f pad[4]; + Vec3f* sp24; + u8 i; + + for (i = 0; i < 5; i++) { + func_8001A38C(i, sfxPos); + } + sp24 = sfxPos; + func_80019290(2, &sp24); +} #pragma GLOBAL_ASM("asm/us/nonmatchings/main/sys_audio_17650/func_8001A55C.s") diff --git a/tools/progress.py b/tools/progress.py new file mode 100644 index 00000000..d840954c --- /dev/null +++ b/tools/progress.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 + +import argparse +import git +import os +import subprocess +import sys +from colour import Color + +script_dir = os.path.dirname(os.path.realpath(__file__)) +root_dir = os.path.join(script_dir, "..") +asm_dir = os.path.join(root_dir, "asm", "us", "nonmatchings") +build_dir = os.path.join(root_dir, "build") +elf_path = os.path.join(build_dir, "starfox64.us.elf") + +def get_func_sizes(): + try: + result = subprocess.run(['objdump', '-x', elf_path], stdout=subprocess.PIPE) + nm_lines = result.stdout.decode().split("\n") + except: + print(f"Error: Could not run objdump on {elf_path} - make sure that the project is built") + sys.exit(1) + + sizes = {} + total = 0 + + for line in nm_lines: + if " F " in line: + components = line.split() + size = int(components[4], 16) + name = components[5] + total += size + sizes[name] = size + + return sizes, total + +def get_nonmatching_funcs(): + funcs = set() + for root, dirs, files in os.walk(asm_dir): + for f in files: + if f.endswith(".s"): + funcs.add(f[:-2]) + + return funcs + +def get_funcs_sizes(sizes, matchings, nonmatchings): + msize = 0 + nmsize = 0 + + for func in matchings: + msize += sizes[func] + + for func in nonmatchings: + if func not in sizes: + pass + # print(func) + else: + nmsize += sizes[func] + #print("% s,%i" % (func, sizes[func])) + + return msize, nmsize + +def lerp(a, b, alpha): + return a + (b - a) * alpha + +def main(args): + func_sizes, total_size = get_func_sizes() + all_funcs = set(func_sizes.keys()) + + nonmatching_funcs = get_nonmatching_funcs() + matching_funcs = all_funcs - nonmatching_funcs + + matching_size, nonmatching_size = get_funcs_sizes(func_sizes, matching_funcs, nonmatching_funcs) + + if len(all_funcs) == 0: + funcs_matching_ratio = 0.0 + matching_ratio = 0.0 + else: + funcs_matching_ratio = (len(matching_funcs) / len(all_funcs)) * 100 + matching_ratio = (matching_size / total_size) * 100 + + if args.csv: + version = 1 + git_object = git.Repo().head.object + timestamp = str(git_object.committed_date) + git_hash = git_object.hexsha + csv_list = [str(version), timestamp, git_hash, str(len(all_funcs)), str(len(nonmatching_funcs)), + str(len(matching_funcs)), str(total_size), str(nonmatching_size), str(matching_size)] + print(",".join(csv_list)) + elif args.shield_json: + import json + + # https://shields.io/endpoint + color = Color("#50ca22", hue=lerp(0, 105/255, matching_ratio / 100)) + print(json.dumps({ + "schemaVersion": 1, + "label": f"progress", + "message": f"{matching_ratio:.2f}%", + "color": color.hex, + })) + else: + if matching_size + nonmatching_size != total_size: + print("Warning: category/total size mismatch!\n") + print(f"{len(matching_funcs)} matched functions / {len(all_funcs)} total ({funcs_matching_ratio:.2f}%)") + print(f"{matching_size} matching bytes / {total_size} total ({matching_ratio:.2f}%)") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Reports progress for the project") + parser.add_argument("--csv", action="store_true") + parser.add_argument("--shield-json", action="store_true") + args = parser.parse_args() + + main(args)