Skip to content

Commit

Permalink
fixed a bunch of straggler bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubberduckycooly committed May 12, 2021
1 parent a58fe79 commit dc84135
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Nexus/Collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ void ProcessTracedCollision(Player *player)
player->YPos = (sensors[4].YPos - collisionBottom) << 16;
player->angle = sensors[4].angle;
}
else if (sensors[5].collided ) {
else if (sensors[5].collided) {
player->YPos = (sensors[5].YPos - collisionBottom) << 16;
player->angle = sensors[5].angle;
}
Expand Down
4 changes: 2 additions & 2 deletions Nexus/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void InitSystemMenu()
ReleaseStageSfx();
fadeMode = 0;

if (Engine.usingBinFile && !Engine.devMenu) {
if (Engine.usingBinFile) {
ClearGraphicsData();
for (int i = 0; i < PLAYER_COUNT; ++i) playerScriptList[i].scriptPath[0] = 0;
LoadPalette("Data/Palettes/MasterPalette.act", 0, 256);
Expand Down Expand Up @@ -114,7 +114,7 @@ void ProcessSystemMenu()
else if (keyPress.B) {
ClearGraphicsData();
ClearAnimationData();
LoadPalette("MasterPalette.act", 0, 256);
LoadPalette("Data/Palettes/MasterPalette.act", 0, 256);
activeStageList = 0;
stageMode = STAGEMODE_LOAD;
Engine.gameMode = ENGINE_MAINGAME;
Expand Down
70 changes: 0 additions & 70 deletions Nexus/Math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,14 @@
#define M_PI 3.14159265358979323846264338327950288
#endif

int sinM[512];
int cosM[512];

int sinVal512[512];
int cosVal512[512];

int sinVal256[256];
int cosVal256[256];

byte atanVal256[0x100 * 0x100];

void CalculateTrigAngles()
{
for (int i = 0; i < 0x200; ++i) {
float Val = sin(((float)i / 256.0) * M_PI);
sinM[i] = (Val * 4096.0);
Val = cos(((float)i / 256.0) * M_PI);
cosM[i] = (Val * 4096.0);
}

cosM[0] = 4096;
cosM[128] = 0;
cosM[256] = -4096;
cosM[384] = 0;
sinM[0] = 0;
sinM[128] = 4096;
sinM[256] = 0;
sinM[384] = -4096;

for (int i = 0; i < 0x200; ++i) {
float Val = sinf(((float)i / 256) * M_PI);
Expand All @@ -54,54 +34,4 @@ void CalculateTrigAngles()
sinVal256[i] = (sinVal512[i * 2] >> 1);
cosVal256[i] = (cosVal512[i * 2] >> 1);
}

for (int Y = 0; Y < 0x100; ++Y) {
byte *ATan = (byte *)&atanVal256[Y];
for (int X = 0; X < 0x100; ++X) {
float angle = atan2f(Y, X);
*ATan = (signed int)(angle * 40.743664f);
ATan += 0x100;
}
}
}

byte ArcTanLookup(int X, int Y)
{
int XVal;
byte result = 0;
int YVal;

if (X >= 0)
XVal = X;
else
XVal = -X;

if (Y >= 0)
YVal = Y;
else
YVal = -Y;

if (XVal <= YVal) {
while (YVal > 0xFF) {
XVal >>= 4;
YVal >>= 4;
}
}
else {
while (XVal > 0xFF) {
XVal >>= 4;
YVal >>= 4;
}
}
if (X <= 0) {
if (Y <= 0)
result = atanVal256[0x100 * XVal + YVal] + -0x80;
else
result = -0x80 - atanVal256[0x100 * XVal + YVal];
}
else if (Y <= 0)
result = -atanVal256[0x100 * XVal + YVal];
else
result = atanVal256[0x100 * XVal + YVal];
return result;
}
8 changes: 0 additions & 8 deletions Nexus/Math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@
#define MEM_ZERO(x) memset(&(x), 0, sizeof((x)))
#define MEM_ZEROP(x) memset((x), 0, sizeof(*(x)))

extern int sinM[0x200];
extern int cosM[0x200];

extern int sinVal512[0x200];
extern int cosVal512[0x200];

extern int sinVal256[0x100];
extern int cosVal256[0x100];

extern byte atanVal256[0x100 * 0x100];

// Setup Angles
void CalculateTrigAngles();

Expand Down Expand Up @@ -51,7 +46,4 @@ inline int cos256(int angle)
return cosVal256[angle];
}

// Get Arc Tan value
byte ArcTanLookup(int X, int Y);

#endif // !MATH_H
2 changes: 1 addition & 1 deletion Nexus/Palette.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern int fadeMode;

#define RGB888_TO_RGB565(r, g, b) ((b) >> 3) | (((g) >> 2) << 5) | (((r) >> 3) << 11)

#define PACK_RGB888(r, g, b) (((b) << 16) | ((g) << 8) | ((b) << 0))
#define PACK_RGB888(r, g, b) ((0xFF << 24) | ((r) << 16) | ((g) << 8) | ((b) << 0))

void LoadPalette(const char *filePath, int startIndex, int endIndex);

Expand Down
31 changes: 16 additions & 15 deletions Nexus/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,28 +186,28 @@ void SetMovementStats(PlayerMovementStats *stats)

void DefaultAirMovement(Player *player)
{
if (player->YVelocity > -0x40000 && player->YVelocity < 0)
player->speed -= player->speed >> 5;

if (player->speed <= -player->stats.topSpeed) {
if (player->left)
if (player->left) {
player->direction = FLIP_X;
}
}
else if (player->left) {
player->speed -= player->stats.airAcceleration;
player->direction = FLIP_X;
else {
if (player->left) {
player->speed -= player->stats.airAcceleration;
player->direction = FLIP_X;
}
}

if (player->speed >= player->stats.topSpeed) {
if (player->right)
player->direction = FLIP_NONE;
}
else if (player->right) {
player->speed += player->stats.airAcceleration;
player->direction = FLIP_NONE;
}

if (player->YVelocity > -0x4000) {
if (player->YVelocity < 0) {
player->speed -= player->speed >> 5;
}
player->speed += player->stats.airAcceleration;
}
}

Expand Down Expand Up @@ -248,7 +248,7 @@ void DefaultGravityTrue(Player *player)

void DefaultGroundMovement(Player *player)
{
if ((sbyte)player->frictionLoss <= 0) {
if ((signed int)player->frictionLoss <= 0) {
if (player->left && player->speed > -player->stats.topSpeed) {
if (player->speed <= 0) {
player->speed -= player->stats.acceleration;
Expand Down Expand Up @@ -370,7 +370,7 @@ void DefaultGroundMovement(Player *player)
void DefaultJumpAction(Player *player)
{
player->frictionLoss = 0;
player->gravity = 1;
player->gravity = true;
player->XVelocity = (player->speed * cosVal256[player->angle] + player->stats.jumpStrength * sinVal256[player->angle]) >> 8;
player->YVelocity = (player->speed * sinVal256[player->angle] + -player->stats.jumpStrength * cosVal256[player->angle]) >> 8;
player->speed = player->XVelocity;
Expand All @@ -388,6 +388,7 @@ void DefaultRollingMovement(Player *player)
player->speed += player->stats.rollingDeceleration;
if (player->left && player->speed > 0)
player->speed -= player->stats.rollingDeceleration;

if (player->speed < 0) {
player->speed += player->stats.airDeceleration;
if (player->speed > 0)
Expand All @@ -403,14 +404,14 @@ void DefaultRollingMovement(Player *player)

if (player->speed <= 0) {
if (sinVal256[player->angle] >= 0) {
player->speed = (player->stats.rollingDeceleration * sinVal256[player->angle] >> 8) + player->speed;
player->speed += (player->stats.rollingDeceleration * sinVal256[player->angle] >> 8);
}
else {
player->speed += 0x5000 * sinVal256[player->angle] >> 8;
}
}
else if (sinVal256[player->angle] <= 0) {
player->speed = (player->stats.rollingDeceleration * sinVal256[player->angle] >> 8) + player->speed;
player->speed += (player->stats.rollingDeceleration * sinVal256[player->angle] >> 8);
}
else {
player->speed += 0x5000 * sinVal256[player->angle] >> 8;
Expand Down
4 changes: 4 additions & 0 deletions Nexus/RetroEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ bool processEvents()
case SDLK_ESCAPE:
if (Engine.devMenu)
Engine.gameMode = ENGINE_INITSYSMENU;
else {
Engine.gameMode = ENGINE_EXITGAME;
return false;
}
break;
case SDLK_F4:
Engine.isFullScreen ^= 1;
Expand Down
2 changes: 1 addition & 1 deletion Nexus/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void LoadStageFiles(void)
if (!CheckCurrentStageFolder(stageListPosition)) {
printLog("Loading Scene %s - %s", stageListNames[activeStageList], stageList[activeStageList][stageListPosition].name);
ReleaseStageSfx();
LoadPalette("MasterPalette.act", 0, 256);
LoadPalette("Data/Palettes/MasterPalette.act", 0, 256);
ClearScriptData();
for (int i = SPRITESHEETS_MAX; i > 0; i--) RemoveGraphicsFile((char *)"", i - 1);

Expand Down
16 changes: 14 additions & 2 deletions Nexus/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ int jumpTableDataPos = 0;
int jumpTableDataOffset = 0;

#define ALIAS_COUNT (0x80)
#if !RETRO_USE_ORIGINAL_CODE
#define COMMONALIAS_COUNT (25)
#else
#define COMMONALIAS_COUNT (14)
#endif
int aliasCount = 0;
int lineID = 0;

Expand Down Expand Up @@ -301,7 +305,14 @@ AliasInfo aliases[0x80] = { AliasInfo("true", "1"),
AliasInfo("MENU_2", "1"),
AliasInfo("C_TOUCH", "0"),
AliasInfo("C_BOX", "1"),
AliasInfo("C_PLATFORM", "2") };
AliasInfo("C_PLATFORM", "2"),
#if !RETRO_USE_ORIGINAL_CODE
AliasInfo("INK_NONE", "0"), AliasInfo("INK_BLEND", "1"), AliasInfo("INK_TINT", "2"),
AliasInfo("FX_SCALE", "0"), AliasInfo("FX_ROTATE", "1"), AliasInfo("FX_INK", "2"),
AliasInfo("FX_TINT", "3"), AliasInfo("FLIP_NONE", "0"), AliasInfo("FLIP_X", "1"),
AliasInfo("FLIP_Y", "2"), AliasInfo("FLIP_XY", "3"),
#endif
};


const char scriptEvaluationTokens[][0x4] = {
Expand Down Expand Up @@ -2007,7 +2018,8 @@ void ProcessScript(int scriptCodePtr, int jumpTablePtr, byte scriptSub)
break;
}
case FUNC_ATAN2: {
scriptEng.operands[0] = ArcTanLookup(scriptEng.operands[1], scriptEng.operands[2]);
opcodeSize = 0;
//doesn't exist
break;
}
case FUNC_INTERPOLATE:
Expand Down
7 changes: 7 additions & 0 deletions Nexus/Userdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void InitUserdata()
ini.SetInteger("Window", "WindowScale", Engine.windowScale = 2);
ini.SetInteger("Window", "ScreenWidth", SCREEN_XSIZE = DEFAULT_SCREEN_XSIZE);
ini.SetInteger("Window", "RefreshRate", Engine.refreshRate = 60);
ini.SetInteger("Window", "ColourMode", Engine.colourMode = 0);

ini.SetFloat("Audio", "BGMVolume", bgmVolume / (float)MAX_VOLUME);
ini.SetFloat("Audio", "SFXVolume", sfxVolume / (float)MAX_VOLUME);
Expand Down Expand Up @@ -133,6 +134,10 @@ void InitUserdata()
SCREEN_XSIZE = DEFAULT_SCREEN_XSIZE;
if (!ini.GetInteger("Window", "RefreshRate", &Engine.refreshRate))
Engine.refreshRate = 60;
int cm = Engine.colourMode;
if (!ini.GetInteger("Window", "ColourMode", &cm))
cm = 1;
Engine.colourMode = cm;

float bv = 0, sv = 0;
if (!ini.GetFloat("Audio", "BGMVolume", &bv))
Expand Down Expand Up @@ -283,6 +288,8 @@ void writeSettings() {
ini.SetInteger("Window", "ScreenWidth", SCREEN_XSIZE);
ini.SetComment("Window", "RRComment", "Determines the target FPS");
ini.SetInteger("Window", "RefreshRate", Engine.refreshRate);
ini.SetComment("Window", "CMComment", "Determines the output colour mode (0 = 8-bit, 1 = 16-bit, 2 = 32-bit)");
ini.SetInteger("Window", "ColourMode", Engine.colourMode);

ini.SetFloat("Audio", "BGMVolume", bgmVolume / (float)MAX_VOLUME);
ini.SetFloat("Audio", "SFXVolume", sfxVolume / (float)MAX_VOLUME);
Expand Down

0 comments on commit dc84135

Please sign in to comment.