Skip to content

Commit

Permalink
More fixes & general improvements (#12)
Browse files Browse the repository at this point in the history
* Correct function names for Player

* Correct ProcessInput -> ReadInputDevice

* the changes :fear:

* rename more funcs/vars to match RSDKv2

* Correct more names

* Fix more names, and fix y offset camera bug

Specifically, rolling :)

* Fix crash on invalid mod selection, allow for left/right mod selection

* oh, whoops

* More renaming & Add ModAPI.cpp/hpp

* Format CMakeLists.txt

* Add CMake support for Windows, Fix Visual Studio project, and revert ClearScreen change

* the computer ate my changes

(actually i ate the changes they were tasty)

* Fix small palette oversight

* names, names and names - more of em

* they kidnapped me and forced me to become a penguin.

* whos gonna give me my pink name for this 😭

* Update readme

* Fix mod reordering

* actually this works fine lol

* Remove unused variables from ModAPI

* Small readme change

* Fix clang-format
  • Loading branch information
Jdsle authored Nov 14, 2024
1 parent a09d89b commit 5d7c98e
Show file tree
Hide file tree
Showing 46 changed files with 4,129 additions and 4,388 deletions.
3 changes: 1 addition & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AllowShortLoopsOnASingleLine: true
BinPackArguments: true
BinPackParameters: true
SpaceAfterCStyleCast: false
BreakBeforeBraces: Attach
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakBeforeBinaryOperators: NonAssignment
Cpp11BracedListStyle: false
Expand All @@ -23,7 +23,6 @@ AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
UseTab: Never
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.10)

project(RetroEngine)

Expand Down Expand Up @@ -27,6 +27,7 @@ set(RETRO_FILES
Nexus/fcaseopen.c
Nexus/main.cpp
Nexus/Math.cpp
Nexus/ModAPI.cpp
Nexus/Object.cpp
Nexus/Palette.cpp
Nexus/Player.cpp
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SOURCES = \
Nexus/Input.cpp \
Nexus/main.cpp \
Nexus/Math.cpp \
Nexus/ModAPI.cpp \
Nexus/Object.cpp \
Nexus/Palette.cpp \
Nexus/Player.cpp \
Expand Down
29 changes: 13 additions & 16 deletions Nexus/Animation.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "RetroEngine.hpp"

SpriteFrame scriptFrames[SPRITEFRAME_COUNT];
int scriptFrameCount = 0;
SpriteFrame ScriptFrames[SPRITEFRAME_COUNT];
int ScriptFramesNo = 0;

SpriteFrame animFrames[SPRITEFRAME_COUNT];
Hitbox hitboxList[HITBOX_COUNT];
Hitbox PlayerCBoxes[HITBOX_COUNT];

void LoadPlayerAnimation(const char *filePath, int playerID)
{
Expand All @@ -25,7 +25,7 @@ void LoadPlayerAnimation(const char *filePath, int playerID)
FileRead(&fileBuffer, 1);
FileRead(&fileBuffer, 1);

//Read & load each spritesheet
// Read & load each spritesheet
for (int s = 0; s < 4; ++s) {
FileRead(&fileBuffer, 1);
if (fileBuffer) {
Expand Down Expand Up @@ -54,10 +54,10 @@ void LoadPlayerAnimation(const char *filePath, int playerID)
byte animCount = 0;
FileRead(&animCount, 1);

//Read animations
// Read animations
int frameID = playerID << 10;
for (int a = 0; a < animCount; ++a) {
SpriteAnimation *anim = &playerScriptList[playerID].animations[a];
SpriteAnimation *anim = &PlayerScriptList[playerID].animations[a];
FileRead(&anim->frameCount, 1);
FileRead(&anim->speed, 1);
FileRead(&anim->loopPoint, 1);
Expand Down Expand Up @@ -85,30 +85,27 @@ void LoadPlayerAnimation(const char *filePath, int playerID)
}
}

//Read Hitboxes
// Read Hitboxes
FileRead(&fileBuffer, 1);
int hitboxID = playerID << 3;
for (int i = 0; i < fileBuffer; ++i) {
Hitbox *hitbox = &hitboxList[hitboxID++];
Hitbox *hitbox = &PlayerCBoxes[hitboxID++];
for (int d = 0; d < HITBOX_DIR_COUNT; ++d) {
FileRead(&hitbox->left[d], 1);
FileRead(&hitbox->top[d], 1);
FileRead(&hitbox->right[d], 1);
FileRead(&hitbox->bottom[d], 1);
}
}
playerScriptList[playerID].startWalkSpeed = playerScriptList[playerID].animations[ANI_WALKING].speed - 20;
playerScriptList[playerID].startRunSpeed = playerScriptList[playerID].animations[ANI_RUNNING].speed;
playerScriptList[playerID].startJumpSpeed = playerScriptList[playerID].animations[ANI_JUMPING].speed - 48;
PlayerScriptList[playerID].startWalkSpeed = PlayerScriptList[playerID].animations[ANI_WALKING].speed - 20;
PlayerScriptList[playerID].startRunSpeed = PlayerScriptList[playerID].animations[ANI_RUNNING].speed;
PlayerScriptList[playerID].startJumpSpeed = PlayerScriptList[playerID].animations[ANI_JUMPING].speed - 48;

CloseFile();
}
}
void ClearAnimationData()
{
for (int f = 0; f < SPRITEFRAME_COUNT; ++f) MEM_ZERO(scriptFrames[f]);
//for (int f = 0; f < SPRITEFRAME_COUNT; ++f) MEM_ZERO(animFrames[f]);
//for (int h = 0; h < HITBOX_COUNT; ++h) MEM_ZERO(hitboxList[h]);

scriptFrameCount = 0;
for (int f = 0; f < SPRITEFRAME_COUNT; ++f) MEM_ZERO(ScriptFrames[f]);
ScriptFramesNo = 0;
}
6 changes: 3 additions & 3 deletions Nexus/Animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ struct Hitbox {
sbyte bottom[HITBOX_DIR_COUNT];
};

extern SpriteFrame scriptFrames[SPRITEFRAME_COUNT];
extern int scriptFrameCount;
extern SpriteFrame ScriptFrames[SPRITEFRAME_COUNT];
extern int ScriptFramesNo;

extern SpriteFrame animFrames[SPRITEFRAME_COUNT];
extern Hitbox hitboxList[HITBOX_COUNT];
extern Hitbox PlayerCBoxes[HITBOX_COUNT];

void LoadPlayerAnimation(const char *filePath, int playerID);
void ClearAnimationData();
Expand Down
39 changes: 19 additions & 20 deletions Nexus/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include <cmath>
#include <iostream>

int globalSFXCount = 0;
int stageSFXCount = 0;
int NoGlobalSFX = 0;
int NoStageSFX = 0;

int masterVolume = MAX_VOLUME;
int trackID = -1;
int MusicVolume = MAX_VOLUME;
int CurrentMusicTrack = -1;
int sfxVolume = MAX_VOLUME;
int bgmVolume = MAX_VOLUME;
bool audioEnabled = false;
Expand Down Expand Up @@ -47,7 +47,7 @@ SDL_AudioDeviceID audioDevice;

#define MIX_BUFFER_SAMPLES (256)

int InitAudioPlayback()
int InitSoundDevice()
{
StopAllSfx(); //"init"
#if RETRO_USING_SDL1 || RETRO_USING_SDL2
Expand All @@ -58,13 +58,13 @@ int InitAudioPlayback()
want.channels = AUDIO_CHANNELS;
want.callback = ProcessAudioPlayback;

#if RETRO_USING_SDL2
#if RETRO_USING_SDL2
if ((audioDevice = SDL_OpenAudioDevice(nullptr, 0, &want, &audioDeviceFormat, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE)) > 0) {
audioEnabled = true;
SDL_PauseAudioDevice(audioDevice, 0);
}
else {
printLog("Unable to open audio device: %s", SDL_GetError());
PrintLog("Unable to open audio device: %s", SDL_GetError());
audioEnabled = false;
return true; // no audio but game wont crash now
}
Expand All @@ -75,7 +75,7 @@ int InitAudioPlayback()
SDL_PauseAudio(0);
}
else {
printLog("Unable to open audio device: %s", SDL_GetError());
PrintLog("Unable to open audio device: %s", SDL_GetError());
audioEnabled = false;
return true; // no audio but game wont crash now
}
Expand Down Expand Up @@ -133,8 +133,8 @@ void LoadGlobalSfx()

// Read SFX
FileRead(&fileBuffer, 1);
globalSFXCount = fileBuffer;
for (byte s = 0; s < globalSFXCount; ++s) {
NoGlobalSFX = fileBuffer;
for (byte s = 0; s < NoGlobalSFX; ++s) {
FileRead(&fileBuffer, 1);
FileRead(strBuffer, fileBuffer);
strBuffer[fileBuffer] = 0;
Expand All @@ -147,7 +147,6 @@ void LoadGlobalSfx()
CloseFile();
}

// sfxDataPosStage = sfxDataPos;
nextChannelPos = 0;
for (int i = 0; i < CHANNEL_COUNT; ++i) sfxChannels[i].sfxID = -1;
}
Expand Down Expand Up @@ -216,7 +215,7 @@ void ProcessMusicStream(Sint32 *stream, size_t bytes_wanted)
return;
}
if (bytes_done != 0)
ProcessAudioMixing(stream, musInfo.buffer, bytes_done / sizeof(Sint16), (bgmVolume * masterVolume) / MAX_VOLUME, 0);
ProcessAudioMixing(stream, musInfo.buffer, bytes_done / sizeof(Sint16), (bgmVolume * MusicVolume) / MAX_VOLUME, 0);
#endif

#if RETRO_USING_SDL1
Expand Down Expand Up @@ -247,7 +246,7 @@ void ProcessMusicStream(Sint32 *stream, size_t bytes_wanted)
bytes_gotten += bytes_read;
}
else {
printLog("Music read error: vorbis error: %d", bytes_read);
PrintLog("Music read error: vorbis error: %d", bytes_read);
}
}

Expand All @@ -266,7 +265,7 @@ void ProcessMusicStream(Sint32 *stream, size_t bytes_wanted)
}

if (cvtResult == 0)
ProcessAudioMixing(stream, (const Sint16 *)convert.buf, bytes_gotten / sizeof(Sint16), (bgmVolume * masterVolume) / MAX_VOLUME,
ProcessAudioMixing(stream, (const Sint16 *)convert.buf, bytes_gotten / sizeof(Sint16), (bgmVolume * MusicVolume) / MAX_VOLUME,
0);

if (convert.len > 0 && convert.buf)
Expand Down Expand Up @@ -446,7 +445,7 @@ void LoadMusic(void *userdata)
musInfo.stream = SDL_NewAudioStream(AUDIO_S16, musInfo.vorbisFile.vi->channels, musInfo.vorbisFile.vi->rate, audioDeviceFormat.format,
audioDeviceFormat.channels, audioDeviceFormat.freq);
if (!musInfo.stream) {
printLog("Failed to create stream: %s", SDL_GetError());
PrintLog("Failed to create stream: %s", SDL_GetError());
}
#endif

Expand All @@ -459,8 +458,8 @@ void LoadMusic(void *userdata)
musInfo.buffer = new Sint16[MIX_BUFFER_SAMPLES];

musicStatus = MUSIC_PLAYING;
masterVolume = MAX_VOLUME;
trackID = trackBuffer;
MusicVolume = MAX_VOLUME;
CurrentMusicTrack = trackBuffer;
trackBuffer = -1;
}
}
Expand Down Expand Up @@ -508,7 +507,7 @@ void LoadSfx(char *filePath, byte sfxID)
FileRead(sfx, info.fileSize);
CloseFile();

//Un-encrypt sfx
// unencrypt sfx
if (info.encrypted) {
for (int i = 0; i < info.fileSize; ++i) sfx[i] ^= 0xFF;
}
Expand All @@ -517,7 +516,7 @@ void LoadSfx(char *filePath, byte sfxID)
SDL_LockAudio();
SDL_RWops *src = SDL_RWFromMem(sfx, info.fileSize);
if (src == NULL) {
printLog("Unable to open sfx: %s", info.fileName);
PrintLog("Unable to open sfx: %s", info.fileName);
}
else {
SDL_AudioSpec wav_spec;
Expand All @@ -528,7 +527,7 @@ void LoadSfx(char *filePath, byte sfxID)
SDL_RWclose(src);
delete[] sfx;
if (wav == NULL) {
printLog("Unable to read sfx: %s", info.fileName);
PrintLog("Unable to read sfx: %s", info.fileName);
}
else {
SDL_AudioCVT convert;
Expand Down
22 changes: 11 additions & 11 deletions Nexus/Audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ enum MusicStatuses {
MUSIC_READY = 4,
};

extern int globalSFXCount;
extern int stageSFXCount;
extern int NoGlobalSFX;
extern int NoStageSFX;

extern int masterVolume;
extern int trackID;
extern int MusicVolume;
extern int CurrentMusicTrack;
extern int sfxVolume;
extern int bgmVolume;
extern bool audioEnabled;
Expand All @@ -82,7 +82,7 @@ extern MusicPlaybackInfo musInfo;
extern SDL_AudioSpec audioDeviceFormat;
#endif

int InitAudioPlayback();
int InitSoundDevice();
void LoadGlobalSfx();

#if RETRO_USING_SDL1 || RETRO_USING_SDL2
Expand Down Expand Up @@ -166,7 +166,7 @@ inline void SetMusicVolume(int volume)
volume = 0;
if (volume > MAX_VOLUME)
volume = MAX_VOLUME;
masterVolume = volume;
MusicVolume = volume;
}

inline void PauseSound()
Expand All @@ -189,30 +189,30 @@ inline void StopAllSfx()
inline void ReleaseGlobalSfx()
{
StopAllSfx();
for (int i = globalSFXCount - 1; i >= 0; --i) {
for (int i = NoGlobalSFX - 1; i >= 0; --i) {
if (sfxList[i].loaded) {
StrCopy(sfxList[i].name, "");
free(sfxList[i].buffer);
sfxList[i].length = 0;
sfxList[i].loaded = false;
}
}
globalSFXCount = 0;
NoGlobalSFX = 0;
}
inline void ReleaseStageSfx()
{
for (int i = stageSFXCount + globalSFXCount; i >= globalSFXCount; --i) {
for (int i = NoStageSFX + NoGlobalSFX; i >= NoGlobalSFX; --i) {
if (sfxList[i].loaded) {
StrCopy(sfxList[i].name, "");
free(sfxList[i].buffer);
sfxList[i].length = 0;
sfxList[i].loaded = false;
}
}
stageSFXCount = 0;
NoStageSFX = 0;
}

inline void ReleaseAudioDevice()
inline void ReleaseSoundDevice()
{
StopMusic();
StopAllSfx();
Expand Down
Loading

0 comments on commit 5d7c98e

Please sign in to comment.