Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Oct 19, 2024
1 parent 7fd44ef commit 1c9a040
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 141 deletions.
62 changes: 52 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,34 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: None
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: All
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: true
AlignTrailingComments: false
AlwaysBreakAfterReturnType: All
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: MultiLine
BreakBeforeBraces: Custom
BinPackArguments: false
BinPackParameters: false
BracedInitializerIndentWidth: 2
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: true
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
Expand All @@ -36,39 +43,74 @@ BraceWrapping:
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 2
Cpp11BracedListStyle: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
IncludeBlocks: Regroup
IndentAccessModifiers: false
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 2
IndentWrappedFunctionNames: true
InsertBraces: true
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
LineEnding: LF
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Never
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: Never
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 1
PenaltyBreakString: 1
PenaltyBreakFirstLessLess: 0
PenaltyExcessCharacter: 1000000
PointerAlignment: Right
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: false
SeparateDefinitionBlocks: Always
SortIncludes: CaseInsensitive
SortUsingDeclarations: Lexicographic
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
Maximum: 3
Minimum: 1
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 2
Cpp11BracedListStyle: false
UseTab: Never
231 changes: 113 additions & 118 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,161 +10,156 @@

// nxdk includes
#include "src/nxdk/hal/debug.h"
#include "src/nxdk/hal/xbox.h"
#include "src/nxdk/hal/video.h"
#include "src/nxdk/hal/xbox.h"
#include "src/nxdk/windows.h"

// local includes
#include "src/os.h"

static void printSDLErrorAndReboot()
{
debugPrint("SDL_Error: %s\n", SDL_GetError());
debugPrint("Rebooting in 5 seconds.\n");
Sleep(5000);
XReboot();
static void printSDLErrorAndReboot() {
debugPrint("SDL_Error: %s\n", SDL_GetError());
debugPrint("Rebooting in 5 seconds.\n");
Sleep(5000);
XReboot();
}

static void printIMGErrorAndReboot()
{
debugPrint("SDL_Image Error: %s\n", IMG_GetError());
debugPrint("Rebooting in 5 seconds.\n");
Sleep(5000);
XReboot();
static void printIMGErrorAndReboot() {
debugPrint("SDL_Image Error: %s\n", IMG_GetError());
debugPrint("Rebooting in 5 seconds.\n");
Sleep(5000);
XReboot();
}

// Screen dimension globals
static int SCREEN_WIDTH;
static int SCREEN_HEIGHT;

void splash_screen()
{
int done = 0;
SDL_Window *window;
SDL_Event event;
SDL_Surface *screenSurface, *imageSurface;

// Enable standard application logging
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
void splash_screen() {
int done = 0;
SDL_Window *window;
SDL_Event event;
SDL_Surface *screenSurface, *imageSurface;

// Enable standard application logging
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

if (SDL_VideoInit(NULL) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video.\n");
printSDLErrorAndReboot();
}

window = SDL_CreateWindow("splash",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_SHOWN);
if(window == NULL) {
debugPrint( "Window could not be created!\n");
SDL_VideoQuit();
printSDLErrorAndReboot();
}

if (SDL_VideoInit(NULL) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video.\n");
printSDLErrorAndReboot();
}
if (!(IMG_Init(IMG_INIT_JPG) & IMG_INIT_JPG)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't intialize SDL_image.\n");
SDL_VideoQuit();
printIMGErrorAndReboot();
}

window = SDL_CreateWindow("splash",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_SHOWN);
if(window == NULL)
{
debugPrint( "Window could not be created!\n");
SDL_VideoQuit();
printSDLErrorAndReboot();
}
screenSurface = SDL_GetWindowSurface(window);
if (!screenSurface) {
SDL_VideoQuit();
printSDLErrorAndReboot();
}

if (!(IMG_Init(IMG_INIT_JPG) & IMG_INIT_JPG)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't intialize SDL_image.\n");
SDL_VideoQuit();
printIMGErrorAndReboot();
}
// set string variable for splash screen path
std::string _splashScreenPath = std::string(DATA_PATH) + "assets" + PATH_SEP + "moonlight-splash-" +
std::to_string(SCREEN_WIDTH) + "x" + std::to_string(SCREEN_HEIGHT) + ".jpg";
const char *splashScreenPath = _splashScreenPath.c_str();

screenSurface = SDL_GetWindowSurface(window);
if (!screenSurface) {
SDL_VideoQuit();
printSDLErrorAndReboot();
imageSurface = IMG_Load(splashScreenPath);
if (!imageSurface) {
SDL_VideoQuit();
printIMGErrorAndReboot();
}

while (!done) {
// Check for events
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}

// set string variable for splash screen path
std::string _splashScreenPath = std::string(DATA_PATH) + "assets" + PATH_SEP + "moonlight-splash-" +
std::to_string(SCREEN_WIDTH) + "x" + std::to_string(SCREEN_HEIGHT) + ".jpg";
const char *splashScreenPath = _splashScreenPath.c_str();
SDL_BlitSurface(imageSurface, NULL, screenSurface, NULL);
SDL_UpdateWindowSurface(window);

imageSurface = IMG_Load(splashScreenPath);
if (!imageSurface) {
SDL_VideoQuit();
printIMGErrorAndReboot();
}

while (!done) {
// Check for events
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}

SDL_BlitSurface(imageSurface, NULL, screenSurface, NULL);
SDL_UpdateWindowSurface(window);

Sleep(1000);
}
Sleep(1000);
}

SDL_VideoQuit();
SDL_VideoQuit();
}

int main()
{
// create an empty list for the available video modes
std::vector<VIDEO_MODE> availableVideoModes;

// save the best video mode here
VIDEO_MODE bestVideoMode = {0, 0, 0, 0};
int main() {
// create an empty list for the available video modes
std::vector<VIDEO_MODE> availableVideoModes;

VIDEO_MODE vm;
int bpp = 32; // Bits per pixel
void *p = NULL; // Initialize to NULL for the first call
// save the best video mode here
VIDEO_MODE bestVideoMode = {0, 0, 0, 0};

// get the available video modes
while (XVideoListModes(&vm, bpp, REFRESH_DEFAULT, &p)) {
availableVideoModes.push_back(vm);
VIDEO_MODE vm;
int bpp = 32; // Bits per pixel
void *p = NULL; // Initialize to NULL for the first call

// ensure height is equal to or better than the current best video mode
if (vm.height < bestVideoMode.height) {
continue;
}
// get the available video modes
while (XVideoListModes(&vm, bpp, REFRESH_DEFAULT, &p)) {
availableVideoModes.push_back(vm);

// ensure width is equal to or better than the current best video mode
if (vm.width < bestVideoMode.width) {
continue;
}
// ensure height is equal to or better than the current best video mode
if (vm.height < bestVideoMode.height) {
continue;
}

// ensure bpp is equal to or better than the current best video mode
if (vm.bpp < bestVideoMode.bpp) {
continue;
}
// ensure width is equal to or better than the current best video mode
if (vm.width < bestVideoMode.width) {
continue;
}

// ensure refresh is equal to or better than the current best video mode
if (vm.refresh < bestVideoMode.refresh) {
continue;
}
// ensure bpp is equal to or better than the current best video mode
if (vm.bpp < bestVideoMode.bpp) {
continue;
}

// save the best video mode
bestVideoMode = vm;
// ensure refresh is equal to or better than the current best video mode
if (vm.refresh < bestVideoMode.refresh) {
continue;
}

SCREEN_WIDTH = bestVideoMode.width;
SCREEN_HEIGHT = bestVideoMode.height;
// save the best video mode
bestVideoMode = vm;
}

XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
SCREEN_WIDTH = bestVideoMode.width;
SCREEN_HEIGHT = bestVideoMode.height;

debugPrint("Available video modes:\n");
for (VIDEO_MODE vm : availableVideoModes) {
debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", vm.width, vm.height, vm.bpp, vm.refresh);
}
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);

debugPrint("Available video modes:\n");
for (VIDEO_MODE vm : availableVideoModes) {
debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", vm.width, vm.height, vm.bpp, vm.refresh);
}

debugPrint("Best video mode:\n");
debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", bestVideoMode.width, bestVideoMode.height, bestVideoMode.bpp, bestVideoMode.refresh);
debugPrint("Best video mode:\n");
debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", bestVideoMode.width, bestVideoMode.height, bestVideoMode.bpp, bestVideoMode.refresh);

Sleep(2000);
Sleep(2000);

XVideoSetMode(SCREEN_WIDTH, SCREEN_HEIGHT, bestVideoMode.bpp, bestVideoMode.refresh);
XVideoSetMode(SCREEN_WIDTH, SCREEN_HEIGHT, bestVideoMode.bpp, bestVideoMode.refresh);

splash_screen();
return 0;
splash_screen();
return 0;
}
Loading

0 comments on commit 1c9a040

Please sign in to comment.