From d251df8704bfd59b3ab7892970027e88e6569756 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 20 Aug 2022 16:38:44 +0200 Subject: [PATCH] irx, nullptr, threading patch --- Makefile.base | 7 +- ROADMAP.txt | 3 +- demo/Makefile | 2 +- demo/inc/game_settings.hpp | 17 +++ demo/src/main.cpp | 11 +- demo/src/states/game/enemy/enemy.cpp | 6 +- demo/src/states/game/enemy/enemy_manager.cpp | 3 +- demo/src/states/game/game_state.cpp | 3 + .../intro/states/intro_press_key_state.cpp | 1 + .../intro/states/intro_ps2dev_state.cpp | 2 + .../states/intro/states/intro_tyra_state.cpp | 3 +- engine/inc/debug/debug.hpp | 73 +++++++--- engine/inc/engine.hpp | 15 +- engine/inc/file/file_utils.hpp | 6 +- engine/inc/info/info.hpp | 2 + engine/inc/irx/irx_loader.hpp | 16 ++- engine/inc/renderer/models/color.hpp | 2 + engine/src/audio/audio_song.cpp | 4 +- engine/src/debug/debug.cpp | 25 ++++ engine/src/engine.cpp | 21 ++- engine/src/file/file_utils.cpp | 6 +- engine/src/info/info.cpp | 22 +-- engine/src/irx/audsrv.irx-em | 2 + engine/src/irx/irx_loader.cpp | 132 ++++++++++++------ engine/src/irx/libsd.irx-em | 2 + engine/src/irx/padman.irx-em | 2 + engine/src/irx/sio2man.irx-em | 2 + .../src/loaders/3d/md2_loader/md2_loader.cpp | 2 +- .../pipeline/dynamic/core/dynpip_renderer.cpp | 2 +- .../programs/mcpip_programs_manager.cpp | 2 +- .../3d/pipeline/static/core/stapip_core.cpp | 2 +- .../static/core/stapip_qbuffer_renderer.cpp | 4 +- .../src/renderer/core/gs/renderer_core_gs.cpp | 2 +- .../src/renderer/core/paths/path3/path3.cpp | 2 +- engine/src/renderer/models/color.cpp | 15 ++ 35 files changed, 306 insertions(+), 115 deletions(-) create mode 100644 demo/inc/game_settings.hpp create mode 100644 engine/src/debug/debug.cpp create mode 100644 engine/src/irx/audsrv.irx-em create mode 100644 engine/src/irx/libsd.irx-em create mode 100644 engine/src/irx/padman.irx-em create mode 100644 engine/src/irx/sio2man.irx-em diff --git a/Makefile.base b/Makefile.base index f03fcc0..e31c0b7 100644 --- a/Makefile.base +++ b/Makefile.base @@ -38,7 +38,8 @@ VCL_SOURCES := $(shell find $(SRCDIR) -type f -name *.$(VCLPPEXT)) VCL_OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(VCL_SOURCES:.$(VCLPPEXT)=.$(OBJEXT))) #Default Make -all: resources irxcopy $(TARGET) +all: resources $(TARGET) +#all: resources irxcopy $(TARGET) release: $(MAKE) CFLAGS="-DNDEBUG $(CFLAGS)" @@ -64,8 +65,8 @@ cleaner: clean @$(RM) -rf $(TARGETDIR) @$(RM) -rf $(BUILDDIR) -irxcopy: - @cp $(PS2SDK)/iop/irx/audsrv.irx $(TARGETDIR)/audsrv.irx +#irxcopy: +# @cp $(PS2SDK)/iop/irx/audsrv.irx $(TARGETDIR)/audsrv.irx #Pull in dependency info for *existing* .o files -include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT)) diff --git a/ROADMAP.txt b/ROADMAP.txt index 2e246bb..e927708 100644 --- a/ROADMAP.txt +++ b/ROADMAP.txt @@ -1,6 +1,5 @@ ------------ Tyra's v2.0 roadmap to publish on GitHub ------------ -- [General] USB test - [General] CI in Github via docker image - [Tutorials] 1. Hello world! - explain init(), loop() and what should be inside them (every tutorial should be well commented!) @@ -39,6 +38,6 @@ because Mesh rendering uses only core.render() - [obj] Add multicolor support to obj - [Obj] Improve obj importing for multiple usemtl with same names - [tyrdat] Custom 3D data file with precalculated bboxes with support of async loading -- [Renderer] Interlacing +- [Renderer] Interlacing, a potem resolution 640x448 - [General] Add cpp lint checker in GitHub - [General] Control generated id to avoid duplication. Maybe Just increment from 0? Add interface IIdentificable? diff --git a/demo/Makefile b/demo/Makefile index 1ac4111..cd99cc7 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -15,7 +15,7 @@ DEPEXT := d OBJEXT := o #Flags, Libraries and Includes -CFLAGS := +CFLAGS := LIB := -ltyra LIBDIRS := -L$(ENGINEDIR)/bin INC := -I$(INCDIR) -I$(ENGINEDIR)/inc diff --git a/demo/inc/game_settings.hpp b/demo/inc/game_settings.hpp new file mode 100644 index 0000000..48f8ac0 --- /dev/null +++ b/demo/inc/game_settings.hpp @@ -0,0 +1,17 @@ +/* +# _____ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licensed under Apache License 2.0 +# Sandro Sobczyński +*/ + +#pragma once + +namespace Demo { + +const bool IS_REAL_PS2 = false; + +} // namespace Demo diff --git a/demo/src/main.cpp b/demo/src/main.cpp index e6b02aa..08cc626 100644 --- a/demo/src/main.cpp +++ b/demo/src/main.cpp @@ -10,9 +10,18 @@ #include #include "demo_game.hpp" +#include "game_settings.hpp" int main() { - Tyra::Engine engine; + Tyra::EngineOptions options; + + if (Demo::IS_REAL_PS2) { + options.writeLogsToFile = true; + options.loadUsbDriver = true; + } + + Tyra::Engine engine(options); + Demo::DemoGame game(&engine); engine.run(&game); SleepThread(); diff --git a/demo/src/states/game/enemy/enemy.cpp b/demo/src/states/game/enemy/enemy.cpp index 6381111..86070af 100644 --- a/demo/src/states/game/enemy/enemy.cpp +++ b/demo/src/states/game/enemy/enemy.cpp @@ -30,9 +30,9 @@ Enemy::Enemy(Engine* engine, const EnemyInfo& t_info) { info.bodyTexture->addLink(bodyMaterial->id); info.clothTexture->addLink(clothMaterial->id); - float r = Math::randomf(64.0F, 128.0F); - float g = Math::randomf(64.0F, 128.0F); - float b = Math::randomf(64.0F, 128.0F); + float r = Math::randomf(75.0F, 128.0F); + float g = Math::randomf(75.0F, 128.0F); + float b = Math::randomf(75.0F, 128.0F); bodyMaterial->ambient.set(r, g, b); clothMaterial->ambient.set(r, g, b); diff --git a/demo/src/states/game/enemy/enemy_manager.cpp b/demo/src/states/game/enemy/enemy_manager.cpp index 9a839d1..c463dd6 100644 --- a/demo/src/states/game/enemy/enemy_manager.cpp +++ b/demo/src/states/game/enemy/enemy_manager.cpp @@ -10,6 +10,7 @@ #include "states/game/enemy/enemy_manager.hpp" #include +#include "game_settings.hpp" using Tyra::FileUtils; using Tyra::Math; @@ -46,7 +47,7 @@ EnemyManager::EnemyManager(Engine* engine, const Heightmap& heightmap) { auto* death = engine->audio.adpcm.load( FileUtils::fromCwd("game/models/zombie/death.adpcm")); - const int enemyCount = 10; + const int enemyCount = IS_REAL_PS2 ? 8 : 12; for (int i = 0; i < enemyCount; i++) { EnemyInfo info; info.adpcmChannel = 9 + i; diff --git a/demo/src/states/game/game_state.cpp b/demo/src/states/game/game_state.cpp index 686886e..75121e5 100644 --- a/demo/src/states/game/game_state.cpp +++ b/demo/src/states/game/game_state.cpp @@ -9,6 +9,7 @@ */ #include "states/game/game_state.hpp" +#include "game_settings.hpp" using std::make_unique; using Tyra::FileUtils; @@ -44,6 +45,8 @@ void GameState::onStart() { engine->audio.song.setVolume(85); + if (IS_REAL_PS2) engine->renderer.setFrameLimit(false); + initialized = true; } diff --git a/demo/src/states/intro/states/intro_press_key_state.cpp b/demo/src/states/intro/states/intro_press_key_state.cpp index 9d5277b..8e7b691 100644 --- a/demo/src/states/intro/states/intro_press_key_state.cpp +++ b/demo/src/states/intro/states/intro_press_key_state.cpp @@ -155,6 +155,7 @@ void IntroPressKeyState::update() { } updateMap(); + Threading::switchThread(); for (u8 i = 0; i < mapRows; i++) diff --git a/demo/src/states/intro/states/intro_ps2dev_state.cpp b/demo/src/states/intro/states/intro_ps2dev_state.cpp index 3c10e07..e5cad85 100644 --- a/demo/src/states/intro/states/intro_ps2dev_state.cpp +++ b/demo/src/states/intro/states/intro_ps2dev_state.cpp @@ -41,6 +41,8 @@ void IntroPs2DevState::onStart() { settings.getHeight() / 2 - sprite->size.y / 2); sprite->color.a = 0; + Threading::switchThread(); + texture = engine->renderer.core.texture.repository.add( FileUtils::fromCwd("intro/ps2dev.png")); texture->addLink(sprite->id); diff --git a/demo/src/states/intro/states/intro_tyra_state.cpp b/demo/src/states/intro/states/intro_tyra_state.cpp index 96e730a..5cbdde8 100644 --- a/demo/src/states/intro/states/intro_tyra_state.cpp +++ b/demo/src/states/intro/states/intro_tyra_state.cpp @@ -64,6 +64,8 @@ void IntroTyraState::onStart() { FileUtils::fromCwd("intro/tyra_bg.png")); bgTexture->addLink(bgSprite->id); + Threading::switchThread(); + bg2Texture = engine->renderer.core.texture.repository.add( FileUtils::fromCwd("intro/tyra_bg2.png")); bg2Texture->addLink(bg2Sprite->id); @@ -146,7 +148,6 @@ void IntroTyraState::update() { engine->renderer.renderer2D.render(bg2Sprite); engine->renderer.renderer2D.render(tyraSprite); - Threading::switchThread(); renderFillers(); engine->renderer.endFrame(); diff --git a/engine/inc/debug/debug.hpp b/engine/inc/debug/debug.hpp index 74a787a..d919b0e 100644 --- a/engine/inc/debug/debug.hpp +++ b/engine/inc/debug/debug.hpp @@ -22,17 +22,22 @@ #include #include #include +#include #include +#include -#define TYRA_LOG(...) Debug::writeLines("LOG: ", ##__VA_ARGS__, "\n") -#define TYRA_WARN(...) Debug::writeLines("==WARN: ", ##__VA_ARGS__, "\n") -#define TYRA_ERROR(...) Debug::writeLines("====ERR: ", ##__VA_ARGS__, "\n") -#define TYRA_TRAP(...) Debug::trap(__FILE__, __LINE__, ##__VA_ARGS__) -#define TYRA_BREAKPOINT() Debug::trap(__FILE__, __LINE__, "Breakpoint") +#include "file/file_utils.hpp" +#include "info/info.hpp" + +#define TYRA_LOG(...) TyraDebug::writeLines("LOG: ", ##__VA_ARGS__, "\n") +#define TYRA_WARN(...) TyraDebug::writeLines("==WARN: ", ##__VA_ARGS__, "\n") +#define TYRA_ERROR(...) TyraDebug::writeLines("====ERR: ", ##__VA_ARGS__, "\n") +#define TYRA_TRAP(...) TyraDebug::trap(__FILE__, __LINE__, ##__VA_ARGS__) +#define TYRA_BREAKPOINT() TyraDebug::trap(__FILE__, __LINE__, "Breakpoint") #define TYRA_ASSERT(condition, ...) \ - if (!(condition)) Debug::trap(__FILE__, __LINE__, ##__VA_ARGS__) + if (!(condition)) TyraDebug::trap(__FILE__, __LINE__, ##__VA_ARGS__) -class Debug { +class TyraDebug { public: template static void writeLines(Arg&& arg, Args&&... args) { @@ -42,24 +47,54 @@ class Debug { using expander = int[]; (void)expander{0, (void(ss << std::forward(args)), 0)...}; - printf("%s", ss.str().c_str()); + if (Tyra::Info::writeLogsToFile) { + auto* logFile = getLogFile(); + *logFile << ss.str(); + logFile->flush(); + } else { + printf("%s", ss.str().c_str()); + } } template static void trap(const char* file, int line, Args... args) { - printf("\n"); - printf("============== TYRA ==============\n"); - printf("| Assertion failed!\n"); - printf("|\n"); + std::stringstream ss1; + ss1 << "\n"; + ss1 << "============== TYRA ==============\n"; + ss1 << "| Assertion failed!\n"; + ss1 << "|\n"; + + if (Tyra::Info::writeLogsToFile) { + auto* logFile = getLogFile(); + *logFile << ss1.str(); + logFile->flush(); + } else { + printf("%s", ss1.str().c_str()); + } + writeAssertLines(args...); - printf("|\n"); - printf("| File : %s:%d\n", file, line); - printf("====================================\n\n"); + + std::stringstream ss2; + ss2 << "|\n"; + ss2 << "| File : " << file << ":" << line << "\n"; + ss2 << "====================================\n\n"; + + if (Tyra::Info::writeLogsToFile) { + auto* logFile = getLogFile(); + *logFile << ss2.str(); + logFile->flush(); + } else { + printf("%s", ss2.str().c_str()); + } + for (;;) { } } private: + static std::unique_ptr logFile; + static std::ofstream* getLogFile(); + template static void writeAssertLines(Arg&& arg, Args&&... args) { std::stringstream ss; @@ -69,7 +104,13 @@ class Debug { (void)expander{ 0, (void(ss << "| " << std::forward(args) << "\n"), 0)...}; - printf("%s", ss.str().c_str()); + if (Tyra::Info::writeLogsToFile) { + auto* logfile = getLogFile(); + *logfile << ss.str(); + logFile->flush(); + } else { + printf("%s", ss.str().c_str()); + } } }; diff --git a/engine/inc/engine.hpp b/engine/inc/engine.hpp index 421090a..0344edc 100644 --- a/engine/inc/engine.hpp +++ b/engine/inc/engine.hpp @@ -20,24 +20,37 @@ namespace Tyra { +struct EngineOptions { + /** + * True -> logs will be written to file. + * False -> logs will be displayed in console + */ + bool writeLogsToFile = false; + + bool loadUsbDriver = false; +}; + class Engine { public: Engine(); + Engine(const EngineOptions& options); ~Engine(); Renderer renderer; Pad pad; Audio audio; - IrxLoader irx; Info info; void run(Game* t_game); private: + IrxLoader irx; + Game* game; Banner banner; void realLoop(); + void initAll(const bool& loadUsbDriver); }; } // namespace Tyra diff --git a/engine/inc/file/file_utils.hpp b/engine/inc/file/file_utils.hpp index d2eaee2..793e85b 100644 --- a/engine/inc/file/file_utils.hpp +++ b/engine/inc/file/file_utils.hpp @@ -28,9 +28,9 @@ class FileUtils { private: // Argv name+path & just path - char cwd[NAME_MAX]; - char elfName[NAME_MAX]; - char elfPath[NAME_MAX - 14]; + char cwd[255]; + char elfName[255]; + char elfPath[255 - 14]; void setPathInfo(const char* path); }; diff --git a/engine/inc/info/info.hpp b/engine/inc/info/info.hpp index d6f8635..d0c75ef 100644 --- a/engine/inc/info/info.hpp +++ b/engine/inc/info/info.hpp @@ -24,6 +24,8 @@ class Info { Version version; + static bool writeLogsToFile; + /** Called by engine */ void update(); diff --git a/engine/inc/irx/irx_loader.hpp b/engine/inc/irx/irx_loader.hpp index 07a0ce4..a9aa19f 100644 --- a/engine/inc/irx/irx_loader.hpp +++ b/engine/inc/irx/irx_loader.hpp @@ -19,16 +19,18 @@ class IrxLoader { IrxLoader(); ~IrxLoader(); - /** Load's audio and pad driver */ - void loadDefaultDrivers(); - - void loadUSBDriver(); + void loadAll(const bool& withUsb, const bool& isLoggingToFile); private: + static bool isLoaded; + + void loadSio2man(const bool& verbose); + void loadPadman(const bool& verbose); + void loadLibsd(const bool& verbose); + void loadUsbModules(const bool& verbose); + void loadAudsrv(const bool& verbose); + int applyRpcPatches(); - int loadAudio(); - int loadPad(); - int loadUsb(); void waitUntilUsbDeviceIsReady(); void delay(int count); }; diff --git a/engine/inc/renderer/models/color.hpp b/engine/inc/renderer/models/color.hpp index 238a29a..0799c8e 100644 --- a/engine/inc/renderer/models/color.hpp +++ b/engine/inc/renderer/models/color.hpp @@ -49,6 +49,8 @@ class Color { explicit Color(const float* v) { copy(this, v); } void operator=(const Color& v); + void operator+=(const float& v); + void operator-=(const float& v); void operator*=(const float& v); void operator/=(const float& v); diff --git a/engine/src/audio/audio_song.cpp b/engine/src/audio/audio_song.cpp index b0948ee..7844c8d 100644 --- a/engine/src/audio/audio_song.cpp +++ b/engine/src/audio/audio_song.cpp @@ -48,7 +48,7 @@ void AudioSong::init() { void AudioSong::load(const char* t_path) { if (songLoaded) unloadSong(); wav = fopen(t_path, "rb"); - TYRA_ASSERT(wav != NULL, "Failed to open wav file!"); + TYRA_ASSERT(wav != nullptr, "Failed to open wav file!"); rewindSongToStart(); songLoaded = true; } @@ -109,7 +109,7 @@ void AudioSong::unloadSong() { /** Fseek on wav. */ void AudioSong::rewindSongToStart() { - if (wav != NULL) fseek(wav, 0x30, SEEK_SET); + if (wav != nullptr) fseek(wav, 0x30, SEEK_SET); chunkReadStatus = 0; songFinished = false; } diff --git a/engine/src/debug/debug.cpp b/engine/src/debug/debug.cpp new file mode 100644 index 0000000..292a10a --- /dev/null +++ b/engine/src/debug/debug.cpp @@ -0,0 +1,25 @@ +/* +# _____ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2022, tyra - https://github.com/h4570/tyra +# Licensed under Apache License 2.0 +# Wellington Carvalho +*/ + +#include "debug/debug.hpp" + +std::unique_ptr TyraDebug::logFile; + +std::ofstream* TyraDebug::getLogFile() { + if (logFile) { + return logFile.get(); + } else { + logFile = std::make_unique(); + logFile->open(Tyra::FileUtils::fromCwd("log.txt"), + std::ofstream::out | std::ofstream::app); + return logFile.get(); + } + +} // namespace Tyra diff --git a/engine/src/engine.cpp b/engine/src/engine.cpp index 7285216..92ada7e 100644 --- a/engine/src/engine.cpp +++ b/engine/src/engine.cpp @@ -12,13 +12,11 @@ namespace Tyra { -Engine::Engine() { - srand(time(nullptr)); - renderer.init(); - banner.show(&renderer); - irx.loadDefaultDrivers(); - audio.init(); - pad.init(); +Engine::Engine() { initAll(false); } + +Engine::Engine(const EngineOptions& options) { + info.writeLogsToFile = options.writeLogsToFile; + initAll(options.loadUsbDriver); } Engine::~Engine() {} @@ -37,4 +35,13 @@ void Engine::realLoop() { info.update(); } +void Engine::initAll(const bool& loadUsbDriver) { + srand(time(nullptr)); + irx.loadAll(loadUsbDriver, info.writeLogsToFile); + renderer.init(); + banner.show(&renderer); + audio.init(); + pad.init(); +} + } // namespace Tyra diff --git a/engine/src/file/file_utils.cpp b/engine/src/file/file_utils.cpp index cbe8849..e4e30a8 100644 --- a/engine/src/file/file_utils.cpp +++ b/engine/src/file/file_utils.cpp @@ -34,11 +34,11 @@ void FileUtils::setPathInfo(const char* path) { strcpy(this->elfPath, path); ptr = strrchr(this->elfPath, '/'); - if (ptr == NULL) { + if (ptr == nullptr) { ptr = strrchr(this->elfPath, '\\'); - if (ptr == NULL) { + if (ptr == nullptr) { ptr = strrchr(this->elfPath, ':'); - if (ptr == NULL) { + if (ptr == nullptr) { TYRA_TRAP("Did not find path! PATH: ", path); } } diff --git a/engine/src/info/info.cpp b/engine/src/info/info.cpp index 25cee84..c51c748 100644 --- a/engine/src/info/info.cpp +++ b/engine/src/info/info.cpp @@ -14,6 +14,8 @@ namespace Tyra { +bool Info::writeLogsToFile = false; + Info::Info() { fps = 0; fpsDelayer = 0; @@ -48,21 +50,21 @@ void* Info::allocateLargestFreeRAMBlock(size_t* Size) { s0 = ~(size_t)0 ^ (~(size_t)0 >> 1); - while (s0 && (p = malloc(s0)) == NULL) s0 >>= 1; + while (s0 && (p = malloc(s0)) == nullptr) s0 >>= 1; if (p) free(p); s1 = s0 >> 1; while (s1) { - if ((p = malloc(s0 + s1)) != NULL) { + if ((p = malloc(s0 + s1)) != nullptr) { s0 += s1; free(p); } s1 >>= 1; } - while (s0 && (p = malloc(s0)) == NULL) s0 ^= s0 & -s0; + while (s0 && (p = malloc(s0)) == nullptr) s0 ^= s0 & -s0; *Size = s0; return p; @@ -70,30 +72,30 @@ void* Info::allocateLargestFreeRAMBlock(size_t* Size) { size_t Info::getFreeRAMSize() { size_t total = 0; - void* pFirst = NULL; - void* pLast = NULL; + void* pFirst = nullptr; + void* pLast = nullptr; for (;;) { size_t largest; void* p = allocateLargestFreeRAMBlock(&largest); if (largest < sizeof(void*)) { - if (p != NULL) free(p); + if (p != nullptr) free(p); break; } - *(void**)p = NULL; + *(void**)p = nullptr; total += largest; - if (pFirst == NULL) pFirst = p; + if (pFirst == nullptr) pFirst = p; - if (pLast != NULL) *(void**)pLast = p; + if (pLast != nullptr) *(void**)pLast = p; pLast = p; } - while (pFirst != NULL) { + while (pFirst != nullptr) { void* p = *(void**)pFirst; free(pFirst); pFirst = p; diff --git a/engine/src/irx/audsrv.irx-em b/engine/src/irx/audsrv.irx-em new file mode 100644 index 0000000..04b6d1b --- /dev/null +++ b/engine/src/irx/audsrv.irx-em @@ -0,0 +1,2 @@ +$PS2SDK/iop/irx/audsrv.irx +audsrv_irx diff --git a/engine/src/irx/irx_loader.cpp b/engine/src/irx/irx_loader.cpp index ac5d437..c36f9b8 100644 --- a/engine/src/irx/irx_loader.cpp +++ b/engine/src/irx/irx_loader.cpp @@ -16,8 +16,23 @@ #include #include #include +#include +#include "file/file_utils.hpp" // external IRX modules + +extern u8 sio2man_irx[]; +extern int size_sio2man_irx; + +extern u8 padman_irx[]; +extern int size_padman_irx; + +extern u8 audsrv_irx[]; +extern int size_audsrv_irx; + +extern u8 libsd_irx[]; +extern int size_libsd_irx; + extern u8 bdm_irx[]; extern int size_bdm_irx; @@ -32,19 +47,41 @@ extern int size_usbmass_bd_irx; namespace Tyra { +bool IrxLoader::isLoaded = false; + IrxLoader::IrxLoader() { SifInitRpc(0); + + while (!SifIopReset("", 0)) { + }; + while (!SifIopSync()) { + }; + + SifInitRpc(0); + this->applyRpcPatches(); } IrxLoader::~IrxLoader() {} -void IrxLoader::loadDefaultDrivers() { - this->loadAudio(); - this->loadPad(); -} +void IrxLoader::loadAll(const bool& withUsb, const bool& isLoggingToFile) { + if (isLoaded) { + TYRA_LOG("IRX modules already loaded!"); + return; + } -void IrxLoader::loadUSBDriver() { this->loadUsb(); } + loadSio2man(!isLoggingToFile); + loadPadman(!isLoggingToFile); + loadLibsd(!isLoggingToFile); + + if (withUsb) { + loadUsbModules(!isLoggingToFile); + } + + loadAudsrv(true); + + isLoaded = true; +} /** * @brief Apply the SBV LMB patch to allow modules to be loaded from a buffer in @@ -53,7 +90,6 @@ void IrxLoader::loadUSBDriver() { this->loadUsb(); } */ int IrxLoader::applyRpcPatches() { int ret; - TYRA_LOG("Applying SBV Patches"); ret = sbv_patch_enable_lmb(); TYRA_ASSERT(ret >= 0, @@ -67,65 +103,69 @@ int IrxLoader::applyRpcPatches() { ret = sbv_patch_fileio(); TYRA_ASSERT(ret >= 0, "Failed to load Applying SBV Patches sbv_patch_fileio"); - TYRA_LOG("SBV Patches applyed "); return ret; } -int IrxLoader::loadUsb() { +void IrxLoader::loadLibsd(const bool& verbose) { + if (verbose) TYRA_LOG("IRX: Loading libsd..."); + int ret; - TYRA_LOG("Loading USB modules"); + SifExecModuleBuffer(&libsd_irx, size_libsd_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret >= 0, "Failed to load module: libsd_irx"); - // Load Block Device Manager (BDM) - SifExecModuleBuffer(&bdm_irx, size_bdm_irx, 0, NULL, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: usbhdfsd"); - - // Load FATFS (mass:) driver - SifExecModuleBuffer(&bdmfs_fatfs_irx, size_bdmfs_fatfs_irx, 0, NULL, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: usbd"); - - // Load USB Block Device drivers - SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: usbd"); - - SifExecModuleBuffer(&usbmass_bd_irx, size_usbmass_bd_irx, 0, NULL, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: usbhdfsd"); - - this->waitUntilUsbDeviceIsReady(); - - TYRA_LOG("USB/MASS modules loaded!"); - - return ret; + if (verbose) TYRA_LOG("IRX: Libsd loaded!"); } -int IrxLoader::loadAudio() { +void IrxLoader::loadUsbModules(const bool& verbose) { + if (verbose) TYRA_LOG("IRX: Loading usb modules..."); + int ret; - TYRA_LOG("Modules loading started (LIBSD, AUDSRV)"); - ret = SifLoadModule("rom0:LIBSD", 0, NULL); - TYRA_ASSERT(ret != -203, "LIBSD loading failed!"); + SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret >= 0, "Failed to load module: usbd_irx"); - ret = SifLoadModule("host:audsrv.irx", 0, NULL); - TYRA_ASSERT(ret != -203, "audsrv.irx loading failed!"); - TYRA_LOG("Audio modules loaded"); + SifExecModuleBuffer(&bdm_irx, size_bdm_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret >= 0, "Failed to load module: bdm_irx"); - return ret; + SifExecModuleBuffer(&bdmfs_fatfs_irx, size_bdmfs_fatfs_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret >= 0, "Failed to load module: bdmfs_fatfs"); + + SifExecModuleBuffer(&usbmass_bd_irx, size_usbmass_bd_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret >= 0, "Failed to load module: usbmass"); + + waitUntilUsbDeviceIsReady(); + + if (verbose) TYRA_LOG("IRX: Usb modules loaded!"); } -int IrxLoader::loadPad() { +void IrxLoader::loadAudsrv(const bool& verbose) { + if (verbose) TYRA_LOG("IRX: Loading audsrv..."); + int ret; + SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret >= 0, "Failed to load module: audsrv_irx"); - TYRA_LOG("PAD Modules loading started (SIO2MAN, PADMAN)"); + if (verbose) TYRA_LOG("IRX: Audsrv loaded!"); +} - ret = SifLoadModule("rom0:SIO2MAN", 0, NULL); - TYRA_ASSERT(ret >= 0, - "SifLoadModule (SIO2MAN) failed! Returned value: ", ret); +void IrxLoader::loadSio2man(const bool& verbose) { + if (verbose) TYRA_LOG("IRX: Loading sio2man..."); - ret = SifLoadModule("rom0:PADMAN", 0, NULL); - TYRA_ASSERT(ret >= 0, "SifLoadModule (PADMAN) failed! Returned value: ", ret); + int ret; + SifExecModuleBuffer(&sio2man_irx, size_sio2man_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret >= 0, "Failed to load module: sio2man_irx"); - TYRA_LOG("Pad modules loaded!"); + if (verbose) TYRA_LOG("IRX: Sio2man loaded!"); +} - return ret; +void IrxLoader::loadPadman(const bool& verbose) { + if (verbose) TYRA_LOG("IRX: Loading padman..."); + + int ret; + SifExecModuleBuffer(&padman_irx, size_padman_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret >= 0, "Failed to load module: padman_irx"); + + if (verbose) TYRA_LOG("IRX: Padman loaded!"); } void IrxLoader::delay(int count) { diff --git a/engine/src/irx/libsd.irx-em b/engine/src/irx/libsd.irx-em new file mode 100644 index 0000000..346ebc7 --- /dev/null +++ b/engine/src/irx/libsd.irx-em @@ -0,0 +1,2 @@ +$PS2SDK/iop/irx/libsd.irx +libsd_irx diff --git a/engine/src/irx/padman.irx-em b/engine/src/irx/padman.irx-em new file mode 100644 index 0000000..82b2fd7 --- /dev/null +++ b/engine/src/irx/padman.irx-em @@ -0,0 +1,2 @@ +$PS2SDK/iop/irx/padman.irx +padman_irx diff --git a/engine/src/irx/sio2man.irx-em b/engine/src/irx/sio2man.irx-em new file mode 100644 index 0000000..52eb9ea --- /dev/null +++ b/engine/src/irx/sio2man.irx-em @@ -0,0 +1,2 @@ +$PS2SDK/iop/irx/sio2man.irx +sio2man_irx diff --git a/engine/src/loaders/3d/md2_loader/md2_loader.cpp b/engine/src/loaders/3d/md2_loader/md2_loader.cpp index 475bf76..0a96936 100644 --- a/engine/src/loaders/3d/md2_loader/md2_loader.cpp +++ b/engine/src/loaders/3d/md2_loader/md2_loader.cpp @@ -95,7 +95,7 @@ MeshBuilderData* MD2Loader::load(const char* fullpath, auto filename = getFilenameFromPath(path); FILE* file = fopen(fullpath, "rb"); - TYRA_ASSERT(file != NULL, "Failed to load: ", filename); + TYRA_ASSERT(file != nullptr, "Failed to load: ", filename); md2_t header; fread(reinterpret_cast(&header), sizeof(md2_t), 1, file); diff --git a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp index c174740..05e7f4b 100644 --- a/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp +++ b/engine/src/renderer/3d/pipeline/dynamic/core/dynpip_renderer.cpp @@ -55,7 +55,7 @@ void DynPipRenderer::init(RendererCore* t_core, rendererCore = t_core; programsRepo = t_programRepo; - dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); + dma_channel_initialize(DMA_CHANNEL_VIF1, nullptr, 0); setProgramsCache(); diff --git a/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp b/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp index 08b6853..248a7a6 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/programs/mcpip_programs_manager.cpp @@ -17,7 +17,7 @@ BlockizerProgramsManager::BlockizerProgramsManager() { context = 0; vu1BlockData = BlockNotUploaded; - dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); + dma_channel_initialize(DMA_CHANNEL_VIF1, nullptr, 0); setProgramsCache(); } diff --git a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp index 2115d48..753160e 100644 --- a/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_core.cpp @@ -15,7 +15,7 @@ // #define TYRA_RENDERER_VERBOSE_LOG 1 #ifdef TYRA_RENDERER_VERBOSE_LOG -#define Verbose(...) Debug::writeLines("VRB: ", ##__VA_ARGS__, "\n") +#define Verbose(...) TyraDebug::writeLines("VRB: ", ##__VA_ARGS__, "\n") #else #define Verbose(...) ((void)0) #endif diff --git a/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp b/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp index 266555b..4877369 100644 --- a/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp +++ b/engine/src/renderer/3d/pipeline/static/core/stapip_qbuffer_renderer.cpp @@ -14,7 +14,7 @@ // #define TYRA_QBUFF_RENDERER_VERBOSE_LOG 1 #ifdef TYRA_QBUFF_RENDERER_VERBOSE_LOG -#define Verbose(...) Debug::writeLines("VRB: ", ##__VA_ARGS__, "\n") +#define Verbose(...) TyraDebug::writeLines("VRB: ", ##__VA_ARGS__, "\n") #else #define Verbose(...) ((void)0) #endif @@ -98,7 +98,7 @@ void StaPipQBufferRenderer::init(RendererCore* t_core, prim_t* t_prim, prim = t_prim; lod = t_lod; - dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); + dma_channel_initialize(DMA_CHANNEL_VIF1, nullptr, 0); setProgramsCache(); diff --git a/engine/src/renderer/core/gs/renderer_core_gs.cpp b/engine/src/renderer/core/gs/renderer_core_gs.cpp index 5f02405..583df96 100644 --- a/engine/src/renderer/core/gs/renderer_core_gs.cpp +++ b/engine/src/renderer/core/gs/renderer_core_gs.cpp @@ -47,7 +47,7 @@ void RendererCoreGS::init(RendererSettings* t_settings) { } void RendererCoreGS::initChannels() { - dma_channel_initialize(DMA_CHANNEL_GIF, NULL, 0); + dma_channel_initialize(DMA_CHANNEL_GIF, nullptr, 0); } void RendererCoreGS::allocateBuffers() { diff --git a/engine/src/renderer/core/paths/path3/path3.cpp b/engine/src/renderer/core/paths/path3/path3.cpp index accb615..6e2e471 100644 --- a/engine/src/renderer/core/paths/path3/path3.cpp +++ b/engine/src/renderer/core/paths/path3/path3.cpp @@ -31,7 +31,7 @@ Path3::~Path3() { void Path3::init(RendererSettings* t_settings) { settings = t_settings; - dma_channel_initialize(DMA_CHANNEL_GIF, NULL, 0); + dma_channel_initialize(DMA_CHANNEL_GIF, nullptr, 0); TYRA_LOG("Path3 initialized"); } diff --git a/engine/src/renderer/models/color.cpp b/engine/src/renderer/models/color.cpp index a20bc58..a86203e 100644 --- a/engine/src/renderer/models/color.cpp +++ b/engine/src/renderer/models/color.cpp @@ -19,12 +19,27 @@ void Color::copy(Color* out, const float* in) { } void Color::operator=(const Color& v) { copy(this, v); } + +void Color::operator+=(const float& v) { + r += v; + g += v; + b += v; + a += v; +} +void Color::operator-=(const float& v) { + r -= v; + g -= v; + b -= v; + a -= v; +} + void Color::operator*=(const float& v) { r *= v; g *= v; b *= v; a *= v; } + void Color::operator/=(const float& v) { r /= v; g /= v;