Skip to content

Commit

Permalink
OnlineCTR organizing
Browse files Browse the repository at this point in the history
  • Loading branch information
Niko committed Feb 22, 2025
1 parent c912b75 commit 60d1c45
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 105 deletions.
107 changes: 2 additions & 105 deletions decompile/General/AltMods/Mods4.c
Original file line number Diff line number Diff line change
@@ -1,108 +1,5 @@
#ifdef USE_ONLINE
#include "OnlineCTR/names3d.c"

void UpdateCheckpointTracker(int driverID);
typedef void (*VehicleFuncPtr)(struct Thread* thread, struct Driver* driver);

void RunVehicleThread(VehicleFuncPtr func, struct Thread* thread, struct Driver* driver)
{
UpdateCheckpointTracker(driver->driverID);
if (func == nullptr) { return; }

bool restore = false;
if ((sdata->gGT->gameMode1 & END_OF_RACE) && (checkpointTracker[driver->driverID].raceFinished == 0))
{
sdata->gGT->gameMode1 &= ~(END_OF_RACE);
restore = true;
}
func(thread, driver);
if (restore) { sdata->gGT->gameMode1 |= END_OF_RACE; }
}

void RunVehicleSet13(struct Thread* dThread, struct Driver* dOnline)
{
if(dThread->funcThTick != 0)
return;

// This only works because we have NO collision
// and therefore NO bounce physics, update P1
// first, then update other drivers later

// We can still "eventually" have mask-weapon
// collision, but no "bounce" physics with this logic

for(int iVar11 = 0; iVar11 < 13; iVar11++)
{
VehicleFuncPtr pcVar5 = dOnline->funcPtrs[iVar11];

if(pcVar5 == NULL)
continue;

RunVehicleThread(pcVar5, dThread, dOnline);

#ifdef USE_60FPS
#ifndef REBUILD_PS1
// if this function just ran
if(pcVar5 == VehFrameProc_Driving)
{
// only if jumping animation,
// otherwise wheelie gets bugged
if(dOnline->instSelf->animIndex == 3)
{
dOnline->matrixIndex =
dOnline->matrixIndex >> 1;
}
}
#endif
#endif
}
}
#include "OnlineCTR/vehThread.c"
#include "OnlineCTR/hsvColor.c"
#endif

#ifdef USE_ONLINE
Color HsvToRgb(int h, int s, int v)
{
Color rgb;
h = h & 0xFF; // modulo 256
int region, remainder, p, q, t;

if (s == 0)
{
rgb.r = v;
rgb.g = v;
rgb.b = v;
return rgb;
}

region = h / 43;
remainder = (h - (region * 43)) * 6;

p = (v * (255 - s)) >> 8;
q = (v * (255 - ((s * remainder) >> 8))) >> 8;
t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;

switch (region)
{
case 0:
rgb.r = v; rgb.g = t; rgb.b = p;
break;
case 1:
rgb.r = q; rgb.g = v; rgb.b = p;
break;
case 2:
rgb.r = p; rgb.g = v; rgb.b = t;
break;
case 3:
rgb.r = p; rgb.g = q; rgb.b = v;
break;
case 4:
rgb.r = t; rgb.g = p; rgb.b = v;
break;
default:
rgb.r = v; rgb.g = p; rgb.b = q;
break;
}

return rgb;
}
#endif
46 changes: 46 additions & 0 deletions decompile/General/AltMods/OnlineCTR/hsvColor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

Color HsvToRgb(int h, int s, int v)
{
Color rgb;
h = h & 0xFF; // modulo 256
int region, remainder, p, q, t;

if (s == 0)
{
rgb.r = v;
rgb.g = v;
rgb.b = v;
return rgb;
}

region = h / 43;
remainder = (h - (region * 43)) * 6;

p = (v * (255 - s)) >> 8;
q = (v * (255 - ((s * remainder) >> 8))) >> 8;
t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;

switch (region)
{
case 0:
rgb.r = v; rgb.g = t; rgb.b = p;
break;
case 1:
rgb.r = q; rgb.g = v; rgb.b = p;
break;
case 2:
rgb.r = p; rgb.g = v; rgb.b = t;
break;
case 3:
rgb.r = p; rgb.g = q; rgb.b = v;
break;
case 4:
rgb.r = t; rgb.g = p; rgb.b = v;
break;
default:
rgb.r = v; rgb.g = p; rgb.b = q;
break;
}

return rgb;
}
62 changes: 62 additions & 0 deletions decompile/General/AltMods/OnlineCTR/vehThread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

void UpdateCheckpointTracker(int driverID);
typedef void (*VehicleFuncPtr)(struct Thread* thread, struct Driver* driver);

void RunVehicleThread(VehicleFuncPtr func, struct Thread* thread, struct Driver* driver)
{
UpdateCheckpointTracker(driver->driverID);
if (func == nullptr) { return; }

bool restore = false;
if ((sdata->gGT->gameMode1 & END_OF_RACE) && (checkpointTracker[driver->driverID].raceFinished == 0))
{
sdata->gGT->gameMode1 &= ~(END_OF_RACE);
restore = true;
}
func(thread, driver);
if (restore) { sdata->gGT->gameMode1 |= END_OF_RACE; }
}


// TODO: This isnt called anymore,
// need to decide if still needed
#if 0
void RunVehicleSet13(struct Thread* dThread, struct Driver* dOnline)
{
if(dThread->funcThTick != 0)
return;

// This only works because we have NO collision
// and therefore NO bounce physics, update P1
// first, then update other drivers later

// We can still "eventually" have mask-weapon
// collision, but no "bounce" physics with this logic

for(int iVar11 = 0; iVar11 < 13; iVar11++)
{
VehicleFuncPtr pcVar5 = dOnline->funcPtrs[iVar11];

if(pcVar5 == NULL)
continue;

RunVehicleThread(pcVar5, dThread, dOnline);

#ifdef USE_60FPS
#ifndef REBUILD_PS1
// if this function just ran
if(pcVar5 == VehFrameProc_Driving)
{
// only if jumping animation,
// otherwise wheelie gets bugged
if(dOnline->instSelf->animIndex == 3)
{
dOnline->matrixIndex =
dOnline->matrixIndex >> 1;
}
}
#endif
#endif
}
}
#endif

0 comments on commit 60d1c45

Please sign in to comment.