Skip to content

Commit

Permalink
Issues #121 #122
Browse files Browse the repository at this point in the history
  • Loading branch information
theballaam96 committed Nov 1, 2021
1 parent b056a39 commit 879e0f2
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ extern void writeFlagsToLog(void);
extern void destroyViewerOnTransition(void);
extern void controlFairyViewer(void);
extern void toggleSelectedActor(void);
extern void loadMapVars_0(void);
//extern void correctTagCode(void);

extern void toggleArcadeMenu(void);
Expand Down
1 change: 1 addition & 0 deletions src/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void cFuncLoop(void) {
if (TransitionSpeed < 0) {
savestateLoadMapLoadVars(); // LoadVarsOnMapLoad
fileStateMapLoadVars();
loadMapVars_0();
}
if (ShowSavePrompts) {
displaySavePrompt(); // ShowSavePrompts
Expand Down
29 changes: 22 additions & 7 deletions src/src/mapWarpExtra.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "../include/common.h"

static char warp_loadmapvars = 0;

void handleMapWarping(int map, int levelIndex) {
// Fixes some minor bugs with the following map categories
// Bosses
Expand All @@ -9,12 +11,25 @@ void handleMapWarping(int map, int levelIndex) {
// Jetpac
// Shops
// T&S
switch(map) {
case 2:
//setFlag(0x63,1,2);
break;
case 9:
//setFlag(0x61,1,2);
break;
// switch(map) {
// case 2:
// //setFlag(0x63,1,2);
// break;
// case 9:
// //setFlag(0x61,1,2);
// break;
// }
warp_loadmapvars = 1;
}

void loadMapVars_0(void) {
if ((ObjectModel2Timer == 20) && (TransitionSpeed < 0) && (warp_loadmapvars)) {
if (IsAutowalking) {
if ((AutowalkPointer) && isRDRAM(AutowalkPointer)) {
AutowalkPointer->xPos = (short)Player->xPos;
AutowalkPointer->zPos = (short)Player->zPos;
}
}
warp_loadmapvars = 0;
}
}
93 changes: 85 additions & 8 deletions src/src/watch/watchContainer.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ static const char* watch_assist_array[] = {
change_fairy,
};

static char float_str[22] = {};
static float test_floats[2] = {};

void openWatchMenu(void) {
changeMenu(12);
};
Expand Down Expand Up @@ -594,6 +597,70 @@ void stringConcat(char* dest,char* str1,char* str2) {
dest[offset++] = 0;
}

void reverse(char* str, int len) {
int i = 0, j = len - 1, temp;
while (i < j) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}
}

int intToStr(int x, char str[], int digits) {
int i = 0;
while (x) {
str[i++] = (x % 10) + 0x30;
x /= 10;
}
// If num digits is more, add 0s at beginning
while (i < digits) {
str[i++] = 0x30;
}
reverse(str,i);
str[i] = 0;
return i;
}

void floatToString(float flt, char* res, int precision) {
// Extract integer part
int ipart = (int)(flt + 0);

// Extract floating part
float fpart = (flt + 0) - (float)ipart;
// test_floats[0] = flt;
// test_floats[1] = fpart;
// TestVariable = (int)&test_floats;

// convert int to string
int i = intToStr(ipart, res, 1);
int pow = 1;

if (precision != 0) {
for (int k = 0; k < precision; k++) {
pow *= 10;
}
res[i] = 0x2E;
fpart *= pow;
intToStr((int)fpart, res + i + 1, precision);
}
}

typedef enum format_mode {
FLOAT_TYPE,
INT_TYPE,
} format_mode;

void headerFormatter(char* header, float _fval, int _ival, format_mode mode, int watch_index) {
if (mode == 0) {
floatToString(_fval,float_str,Precision);
} else {
intToStr(_ival,float_str,0);
}
stringConcat((char*)WatchTextSpace[watch_index],header,float_str);
}

void handleWatch(void) {
float _KRoolTimerX = 125;
char watch_present = 0;
Expand All @@ -609,7 +676,8 @@ void handleWatch(void) {
{
// Lag
if ((watch_cache_array[j][1] != StoredLag) || (watch_cache_array[j][0] != 1)) {
dk_strFormat((char *)WatchTextSpace[j],"LAG: %d",StoredLag);
headerFormatter("LAG: ",0,StoredLag,INT_TYPE,j);
//dk_strFormat((char *)WatchTextSpace[j],"LAG: %d",StoredLag);
}
watch_cache_array[j][0] = 1;
watch_cache_array[j][1] = StoredLag;
Expand All @@ -624,7 +692,10 @@ void handleWatch(void) {
}
AverageLag = (float)(_lagsum) / 16;
if ((watch_cache_array[j][1] != _lagsum) || (watch_cache_array[j][0] != 2)) {
dk_strFormat((char *)WatchTextSpace[j],"AVERAGE LAG: %f",AverageLag);
headerFormatter("AVERAGE LAG: ",AverageLag,0,FLOAT_TYPE,j);
// floatToString(AverageLag,float_str,Precision);
// stringConcat((char *)WatchTextSpace[j],"AVERAGE LAG: ",float_str);
//dk_strFormat((char *)WatchTextSpace[j],"AVERAGE LAG: %f",AverageLag);
}
watch_cache_array[j][0] = 2;
watch_cache_array[j][1] = _lagsum;
Expand All @@ -644,7 +715,7 @@ void handleWatch(void) {
}
}
if ((watch_cache_slotf[j] != _speed) || (watch_cache_array[j][0] != 3)) {
dk_strFormat((char *)WatchTextSpace[j],"SPEED: %f",_speed);
headerFormatter("SPEED: ",_speed,0,FLOAT_TYPE,j);
}
watch_cache_array[j][0] = 3;
watch_cache_slotf[j] = _speed;
Expand Down Expand Up @@ -682,7 +753,7 @@ void handleWatch(void) {
}
}
if ((watch_cache_array[j][1] != GiantKoshaTimerValue) || (watch_cache_array[j][0] != 5)) {
dk_strFormat((char *)WatchTextSpace[j],"KOSHA TIMER: %d",GiantKoshaTimerValue);
headerFormatter("KOSHA TIMER: ",0,GiantKoshaTimerValue,INT_TYPE,j);
}
watch_cache_array[j][0] = 5;
watch_cache_array[j][1] = GiantKoshaTimerValue;
Expand Down Expand Up @@ -739,7 +810,7 @@ void handleWatch(void) {
_angle = Player->facing_angle % 4096;
_angle = (_angle / 4096) * 360;
if ((watch_cache_array[j][1] != Player->facing_angle) || (watch_cache_array[j][0] != 7)) {
dk_strFormat((char *)WatchTextSpace[j],"ANGLE: %f",_angle);
headerFormatter("ANGLE: ",_angle,0,FLOAT_TYPE,j);
}
watch_cache_array[j][0] = 7;
watch_cache_array[j][1] = Player->facing_angle;
Expand All @@ -763,7 +834,7 @@ void handleWatch(void) {
colorWatch(0xFF,0x45,0x00,j);
}
if ((watch_cache_array[j][1] != held_actor_index) || (watch_cache_array[j][0] != 9)) {
dk_strFormat((char *)WatchTextSpace[j],"HELD ACTOR: %d",held_actor_index);
headerFormatter("HELD ACTOR: ",0,held_actor_index,INT_TYPE,j);
}
watch_cache_array[j][0] = 9;
watch_cache_array[j][1] = held_actor_index;
Expand Down Expand Up @@ -834,6 +905,12 @@ void handleWatch(void) {
_z = Player->zPos;
}
if (((watch_cache_array[j][1] != _x) || (watch_cache_array[j][2] != _y) || (watch_cache_array[j][3] != _z)) || (watch_cache_array[j][0] != 11)) {
// intToStr(_x,float_str,0);
// stringConcat((char*)WatchTextSpace[j],"POSITION",float_str);
// intToStr(_y,float_str,0);
// stringConcat((char*)WatchTextSpace[j],(char*)WatchTextSpace[j],float_str);
// intToStr(_z,float_str,0);
// stringConcat((char*)WatchTextSpace[j],(char*)WatchTextSpace[j],float_str);
dk_strFormat((char *)WatchTextSpace[j], "POSITION: %d, %d, %d",_x,_y,_z);
}
watch_cache_array[j][0] = 11;
Expand Down Expand Up @@ -895,7 +972,7 @@ void handleWatch(void) {
_floor = Player->floor;
}
if ((watch_cache_slotf[j] != _floor) || (watch_cache_array[j][0] != 14)) {
dk_strFormat((char *)WatchTextSpace[j], "FLOOR: %f",_floor);
headerFormatter("FLOOR: ",_floor,0,FLOAT_TYPE,j);
}
watch_cache_array[j][0] = 14;
watch_cache_slotf[j] = _floor;
Expand Down Expand Up @@ -979,7 +1056,7 @@ void handleWatch(void) {
}
_avgspd = (float)(_spdsum) / 64;
if ((watch_cache_array[j][1] != _spdsum) || (watch_cache_array[j][0] != 17)) {
dk_strFormat((char *)WatchTextSpace[j],"AVERAGE SPEED: %f",_avgspd);
headerFormatter("AVERAGE SPEED: ",_avgspd,0,FLOAT_TYPE,j);
}
watch_cache_array[j][0] = 17;
watch_cache_array[j][1] = _spdsum;
Expand Down

0 comments on commit 879e0f2

Please sign in to comment.