Skip to content

Commit

Permalink
Refactor headers to allow cleaner inlines
Browse files Browse the repository at this point in the history
  • Loading branch information
aglab2 committed Feb 22, 2023
1 parent ab5e8c4 commit a028d3d
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 202 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
Expand Down
24 changes: 23 additions & 1 deletion Hacktice/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ public class Config
public byte checkpointCoin;
public byte checkpointRed;

// since version 1.3.6
public byte name3 = (byte)'C';
public byte name2 = (byte)'A';
public byte name1 = (byte)'R';
public byte name0 = (byte)'P';

public byte name7 = (byte)'E';
public byte name6 = (byte)'C';
public byte name5 = (byte)'I';
public byte name4 = (byte)'T';

public byte showName;
public byte name10;
public byte name9;
public byte name8;

public void setName(string name)
{
name0 = name1 = name2 = name3 = name4 = name5 = name6 = name7 = name8 = name9 = name10 = 0;
}

// TODO: Do this better please
public bool Equals(Config o)
{
Expand Down Expand Up @@ -80,7 +101,8 @@ public bool Equals(Config o)
&& checkpointCoin == o.checkpointCoin
&& checkpointRed == o.checkpointRed
&& dpadUpAction == o.dpadUpAction
&& warpWheel == o.warpWheel;
&& warpWheel == o.warpWheel
&& showName == o.showName;
}
}
}
17 changes: 16 additions & 1 deletion Hacktice/Emulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,22 @@ public Config ReadConfig()
var config = (Config) Marshal.PtrToStructure(ptr, typeof(Config));
Marshal.FreeHGlobal(ptr);

// TODO: Trim config based on 'hackticeConfigSize'. Currently it is unnecessary
if (hackticeConfigSize <= (int) Marshal.OffsetOf<Config>("name3"))
{
config.name0 = (byte)'P';
config.name1 = (byte)'R';
config.name2 = (byte)'A';
config.name3 = (byte)'C';
config.name4 = (byte)'T';
config.name5 = (byte)'I';
config.name6 = (byte)'C';
config.name7 = (byte)'E';
config.name8 = 0;
config.name9 = 0;
config.name10 = 0;
config.showName = 0;
}

return config;
}

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ PAYLOAD_DATA = $(TOOL_DIR)/payload_data
CC = clang
AR = llvm-ar
LD = ld.lld
CFLAGS = -flto -Wall -Wdouble-promotion -Os -mfix4300 -march=mips2 --target=mips-img-elf -fomit-frame-pointer -G0 -I $(INCLUDE_PATH) -I $(INCLUDE_PATH)/libc -mno-check-zero-division -fno-exceptions -fno-builtin -fno-rtti -fno-common -mno-abicalls -DTARGET_N64 -mfpxx
CFLAGS = -flto -Wall -Wdouble-promotion -Oz -mfix4300 -march=mips2 --target=mips-img-elf -fomit-frame-pointer -G0 -I $(INCLUDE_PATH) -I $(INCLUDE_PATH)/libc -mno-check-zero-division -fno-exceptions -fno-builtin -fno-rtti -fno-common -mno-abicalls -DTARGET_N64 -mfpxx

all: $(OBJ_DIR) $(ROM) $(PAYLOAD_HEADER) $(PAYLOAD_DATA)

Expand Down
18 changes: 1 addition & 17 deletions src/action.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
#include "action.h"
#include "game/level_update.h"

static int sLastAction = 0;

void Action_onNormal()
{
sLastAction = gMarioStates->action;
}

int Action_last()
{
return sLastAction;
}

bool Action_changed()
{
return sLastAction != gMarioStates->action;
}
int Action_sLastAction = 0;
20 changes: 17 additions & 3 deletions src/action.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
#pragma once
#include "bool.h"
#include "game/level_update.h"

void Action_onNormal();
int Action_last();
bool Action_changed();
extern int Action_sLastAction;

static inline void Action_onNormal()
{
Action_sLastAction = gMarioStates->action;
}

static inline int Action_last()
{
return Action_sLastAction;
}

static inline bool Action_changed()
{
return Action_sLastAction != gMarioStates->action;
}
148 changes: 9 additions & 139 deletions src/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
#include "game/ingame_menu.h"
#include "engine/math_util.h"

static char sWarp;
static char sMusicNumber;
char Config_gWarp;
char Config_gMusicNumber;
char Config_gOnDeathAction;

Config sConfig = {
.magic = HACKTICE_CONFIG_CANARY,
.selfSize = sizeof(Config),
.timerShow = true,
.warpWheel = true,
.name = "PRACTICE",
};

typedef enum Pages
Expand Down Expand Up @@ -53,8 +55,6 @@ static const u8* const actionNames[] = { uOFF, uACT_SELECT, uLEVEL_RESET, uLE
static u8 lMusicNumber[] = { 0x00, 0x00, 0xff };
static const u8* const lMusicNumbers[] = { lMusicNumber, NULL };

static u8 sOnDeathAction = 0;

#define VALUE_NAMES(x) x, ARRAY_SIZE(x)
#define INT_NAMES(x, cnt) x, cnt

Expand Down Expand Up @@ -95,7 +95,7 @@ static const ConfigDescriptor sGeneralDescriptors[] =

{ &sConfig.deathAction, uDEATH_ACTION, VALUE_NAMES(deathActionNames) },

{ &sMusicNumber, uMUSIC_NUMBER, lMusicNumbers, 64 },
{ &Config_gMusicNumber, uMUSIC_NUMBER, lMusicNumbers, 64 },
{ &sConfig.stateSaveStyle, uSSAVESTYLE, VALUE_NAMES(stateSaveNames) },
{ &sConfig.speed, uSPEED, VALUE_NAMES(onOffValueNames) },
{ &sConfig.timerShow, uTIMER, VALUE_NAMES(onOffValueNames) },
Expand All @@ -109,7 +109,7 @@ static const ConfigDescriptor sGeneralDescriptors[] =

// Warp
static const ConfigDescriptor sWarpDescriptors[] = {
{ &sWarp, uSELECT_WARP_TARGET, NULL, 25 },
{ &Config_gWarp, uSELECT_WARP_TARGET, NULL, 25 },
};
#define sWarpMaxAllowedOption 0

Expand Down Expand Up @@ -288,19 +288,9 @@ void Config_onPause()
processInputs();
}

Config_StickStyle Config_showStick()
{
return (Config_StickStyle) sConfig.stickStyle;
}

bool Config_showButtons()
{
return sConfig.showButtons;
}

static inline LevelConv_PlainLevels Config_warpId()
{
return (LevelConv_PlainLevels) sWarp;
return (LevelConv_PlainLevels) Config_gWarp;
}

LevelConv_PlainLevels Config_warpIdAndReset()
Expand All @@ -323,9 +313,9 @@ LevelConv_PlainLevels Config_warpIdAndReset()

Config_ButtonAction Config_action()
{
if (sOnDeathAction)
if (Config_gOnDeathAction)
{
return (Config_ButtonAction) sOnDeathAction;
return (Config_ButtonAction) Config_gOnDeathAction;
}

if (sConfig.lRAction && BUTTONS_PRESSED(L_TRIG | R_TRIG))
Expand All @@ -351,123 +341,3 @@ Config_ButtonAction Config_action()

return Config_ButtonAction_OFF;
}

bool Config_showWallkickFrame()
{
return sConfig.wallkickFrame;
}

bool Config_showDistanceFromClosestRed()
{
return sConfig.distanceFromClosestRed;
}

bool Config_showDistanceFromClosestSecret()
{
return sConfig.distanceFromClosestSecret;
}

bool Config_showSpeed()
{
return sConfig.speed;
}

bool Config_timerShow()
{
return sConfig.timerShow;
}

Config_TimerStyle Config_timerStyle()
{
return (Config_TimerStyle) sConfig.timerStyle;
}

bool Config_timerStopOnCoinStar()
{
return sConfig.timerStopOnCoinStar;
}

Config_StateSaveStyle Config_saveStateStyle()
{
return (Config_StateSaveStyle) sConfig.stateSaveStyle;
}

bool Config_muteMusic()
{
return sConfig.muteMusic;
}

char Config_musicNumber()
{
return sMusicNumber;
}

Config_DeathAction Config_deathAction()
{
return (Config_DeathAction) sConfig.deathAction;
}

void Config_setOnDeathAction(Config_ButtonAction act)
{
sOnDeathAction = (u8) act;
}

bool Config_checkpointWallkick()
{
return sConfig.checkpointWallkick;
}

bool Config_checkpointDoor()
{
return sConfig.checkpointDoor;
}

bool Config_checkpointPole()
{
return sConfig.checkpointPole;
}

bool Config_checkpointLava()
{
return sConfig.checkpointLava;
}

bool Config_checkpointGroundpound()
{
return sConfig.checkpointGroundpound;
}

bool Config_checkpointBurning()
{
return sConfig.checkpointBurning;
}

bool Config_checkpointCannon()
{
return sConfig.checkpointCannon;
}

bool Config_checkpointWarp()
{
return sConfig.checkpointWarp;
}

bool Config_checkpointRed()
{
return sConfig.checkpointRed;
}

bool Config_checkpointCoin()
{
return sConfig.checkpointCoin;
}

bool Config_checkpointObject()
{
return sConfig.checkpointObject;
}

bool Config_checkpointPlatform()
{
return sConfig.checkpointPlatform;
}
Loading

0 comments on commit a028d3d

Please sign in to comment.