Skip to content

Commit

Permalink
fix two visual errors and add things
Browse files Browse the repository at this point in the history
  • Loading branch information
LittlePlanetCD committed May 28, 2024
1 parent 0b1a2a7 commit 75d80a0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Nexus/Drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ void DrawTintRectangle(int XPos, int YPos, int width, int height, byte tintID)
height += YPos;
YPos = 0;
}
if (width <= 0 || height <= 0)
if (width < 0 || height < 0)
return;

byte *tintTable = NULL;
Expand All @@ -1649,7 +1649,7 @@ void DrawTintRectangle(int XPos, int YPos, int width, int height, byte tintID)
int yOffset = SCREEN_XSIZE - width;
for (byte *pixelBufferPtr = &Engine.pixelBuffer[XPos + SCREEN_XSIZE * YPos];; pixelBufferPtr += yOffset) {
height--;
if (!height)
if (height < 0)
break;
int w = width;
while (w--) {
Expand Down
2 changes: 1 addition & 1 deletion Nexus/Palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void SetFade(byte r, byte g, byte b, ushort a, int start, int end)
a = 255;
if (end < 256)
++end;
for (int i = start; i < end; ++i) {
for (int i = start; i <= end; ++i) {
byte red = (ushort)(r * a + (0xFF - a) * palette8[i].r) >> 8;
byte green = (ushort)(g * a + (0xFF - a) * palette8[i].g) >> 8;
byte blue = (ushort)(b * a + (0xFF - a) * palette8[i].b) >> 8;
Expand Down
27 changes: 6 additions & 21 deletions Nexus/RetroEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,30 +269,15 @@ void RetroEngine::Init()

void RetroEngine::Run()
{
const Uint64 frequency = SDL_GetPerformanceFrequency();
Uint64 frameStart = SDL_GetPerformanceCounter(), frameEnd = SDL_GetPerformanceCounter();
Uint64 frameStartBlunt = SDL_GetTicks(), frameEndBlunt = SDL_GetTicks();
float frameDelta = 0.0f;
float frameDeltaBlunt = 0.0f;

unsigned long long targetFreq = SDL_GetPerformanceFrequency() / Engine.refreshRate;
unsigned long long curTicks = 0;

while (running) {
#if !RETRO_USE_ORIGINAL_CODE
if (!vsync) {
frameStartBlunt = SDL_GetTicks();
frameDeltaBlunt = frameStartBlunt - frameEndBlunt;
//++frameDeltaBlunt;
if (frameDeltaBlunt < 15.0f) {
SDL_Delay(15.0f - frameDeltaBlunt);
continue;
}

frameStart = SDL_GetPerformanceCounter();
frameDelta = frameStart - frameEnd;
if (frameDelta < frequency / 60.0f) {
continue;
}
frameEnd = SDL_GetPerformanceCounter();
frameEndBlunt = SDL_GetTicks();
if (SDL_GetPerformanceCounter() < curTicks + targetFreq)
continue;
curTicks = SDL_GetPerformanceCounter();
}
#endif
running = processEvents();
Expand Down
18 changes: 9 additions & 9 deletions Nexus/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int textMenuSurfaceNo = 0;
void SetupTextMenu(TextMenu *menu, int rowCount)
{
menu->textDataPos = 0;
menu->rowCount = rowCount;
menu->rowCount = rowCount;
}
void AddTextMenuEntry(TextMenu *menu, const char *text)
{
Expand Down Expand Up @@ -75,12 +75,12 @@ void LoadConfigListText(TextMenu *menu, int listNo)
// Variables
FileRead(&count, 1);
for (int v = 0; v < count; ++v) {
//Var Name
// Var Name
FileRead(&strLen, 1);
FileRead(&strBuf, strLen);
strBuf[strLen] = 0;

//Var Value
// Var Value
FileRead(&fileBuffer, 1);
FileRead(&fileBuffer, 1);
FileRead(&fileBuffer, 1);
Expand Down Expand Up @@ -111,7 +111,7 @@ void LoadConfigListText(TextMenu *menu, int listNo)
FileRead(&strBuf, strLen);
strBuf[strLen] = 0;

if (listNo == 0) //Player List
if (listNo == 0) // Player List
AddTextMenuEntry(menu, strBuf);
}

Expand All @@ -120,26 +120,26 @@ void LoadConfigListText(TextMenu *menu, int listNo)
byte stageCnt = 0;
FileRead(&stageCnt, 1);
for (int s = 0; s < stageCnt; ++s) {
//Stage Folder
// Stage Folder
FileRead(&strLen, 1);
FileRead(&strBuf, strLen);
strBuf[strLen] = 0;

//Stage ID
// Stage ID
FileRead(&strLen, 1);
FileRead(&strBuf, strLen);
strBuf[strLen] = 0;

//Stage Name
// Stage Name
FileRead(&strLen, 1);
FileRead(&strBuf, strLen);
strBuf[strLen] = '\0';

//IsHighlighted
// IsHighlighted
FileRead(&fileBuffer, 1);
if (listNo == c) {
menu->entryHighlight[s] = fileBuffer;
AddTextMenuEntry(menu, strBuf);
menu->entryHighlight[menu->rowCount - 1] = fileBuffer;
}
}
}
Expand Down
62 changes: 58 additions & 4 deletions Nexus/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,68 @@
#include "RetroEngine.hpp"

int main(int argc, char *argv[])
{
for (int i = 0; i < argc; ++i) {
if (StrComp(argv[i], "UsingCWD"))
#if !RETRO_USE_ORIGINAL_CODE

#if RETRO_PLATFORM == RETRO_WIN && _MSC_VER
#include "Windows.h"
#endif

void parseArguments(int argc, char *argv[]) {
for (int a = 0; a < argc; ++a) {
const char *find = "";

find = strstr(argv[a], "stage=");
if (find) {
int b = 0;
int c = 6;
while (find[c] && find[c] != ';') Engine.startSceneFolder[b++] = find[c++];
Engine.startSceneFolder[b] = 0;
}

find = strstr(argv[a], "scene=");
if (find) {
int b = 0;
int c = 6;
while (find[c] && find[c] != ';') Engine.startSceneID[b++] = find[c++];
Engine.startSceneID[b] = 0;
}

find = strstr(argv[a], "console=true");
if (find) {
engineDebugMode = true;
Engine.devMenu = true;
Engine.consoleEnabled = true;
#if RETRO_PLATFORM == RETRO_WIN && _MSC_VER
AllocConsole();
freopen_s((FILE **)stdin, "CONIN$", "w", stdin);
freopen_s((FILE **)stdout, "CONOUT$", "w", stdout);
freopen_s((FILE **)stderr, "CONOUT$", "w", stderr);
#endif
}

find = strstr(argv[a], "usingCWD=true");
if (find) {
usingCWD = true;
}
}
}
#endif

int main(int argc, char *argv[])
{
#if !RETRO_USE_ORIGINAL_CODE
parseArguments(argc, argv);
#endif

Engine.Init();
Engine.Run();

#if !RETRO_USE_ORIGINAL_CODE
if (Engine.consoleEnabled) {
#if RETRO_PLATFORM == RETRO_WIN && _MSC_VER
FreeConsole();
#endif
}
#endif

return 0;
}

0 comments on commit 75d80a0

Please sign in to comment.