From fafc66d35ca172f242200925ebb9f30a3d455ee7 Mon Sep 17 00:00:00 2001 From: h4570 Date: Wed, 26 May 2021 19:36:59 +0200 Subject: [PATCH] replaced PRINT_LOG and PRINT_ERR Signed-off-by: h4570 --- src/engine/engine.cpp | 16 ++--- src/engine/include/models/texture.hpp | 6 +- .../include/modules/texture_repository.hpp | 6 +- src/engine/include/utils/debug.hpp | 6 +- src/engine/loaders/bmp_loader.cpp | 12 +--- src/engine/loaders/dff_loader.cpp | 7 +-- src/engine/loaders/md2_loader.cpp | 17 ++---- src/engine/loaders/obj_loader.cpp | 24 +++----- src/engine/loaders/png_loader.cpp | 23 ++------ src/engine/models/mesh.cpp | 51 ++++++---------- src/engine/models/mesh_frame.cpp | 28 ++------- src/engine/models/mesh_material.cpp | 16 ++--- src/engine/models/texture.cpp | 15 +---- src/engine/modules/audio.cpp | 58 ++++++++----------- src/engine/modules/camera_base.cpp | 4 +- src/engine/modules/file_service.cpp | 19 +++--- src/engine/modules/gif_sender.cpp | 4 +- src/engine/modules/pad.cpp | 48 +++++---------- src/engine/modules/renderer.cpp | 40 +++++-------- src/engine/modules/texture_repository.cpp | 4 +- src/engine/modules/vif_sender.cpp | 4 +- 21 files changed, 136 insertions(+), 272 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 65a111e..2148dfb 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -52,16 +52,12 @@ void Engine::setDefaultScreen() void Engine::init(Game *t_game, u32 t_gifPacketSize) { - if (isInitialized) - PRINT_ERR("Already initialized!"); - else - { - game = t_game; - renderer = new Renderer(t_gifPacketSize, &screen); - isInitialized = true; - game->onInit(); - gameLoop(); - } + assertMsg(!isInitialized, "Engine was already initialized!"); + game = t_game; + renderer = new Renderer(t_gifPacketSize, &screen); + isInitialized = true; + game->onInit(); + gameLoop(); } /** Do not call this method. This is used in gameLoop() to maintain multithreading */ diff --git a/src/engine/include/models/texture.hpp b/src/engine/include/models/texture.hpp index 470c0b1..90fff21 100644 --- a/src/engine/include/models/texture.hpp +++ b/src/engine/include/models/texture.hpp @@ -167,10 +167,8 @@ public: void removeLinkById(const u32 &t_id) { s32 index = getIndexOfLink(t_id); - if (index != -1) - removeLinkByIndex(index); - else - PRINT_ERR("Cant remove link, because it was not found!"); + assertMsg(index != -1, "Cant remove link, because it was not found!"); + removeLinkByIndex(index); } private: diff --git a/src/engine/include/modules/texture_repository.hpp b/src/engine/include/modules/texture_repository.hpp index 67cd672..4d7dc15 100644 --- a/src/engine/include/modules/texture_repository.hpp +++ b/src/engine/include/modules/texture_repository.hpp @@ -119,10 +119,8 @@ public: const void removeById(const u32 &t_texId) { s32 index = getIndexOf(t_texId); - if (index != -1) - removeByIndex(index); - else - PRINT_ERR("Cant remove texture, because it was not found!"); + assertMsg(index != -1, "Cant remove texture, because it was not found!"); + removeByIndex(index); } private: diff --git a/src/engine/include/utils/debug.hpp b/src/engine/include/utils/debug.hpp index 81e2da5..03428a1 100644 --- a/src/engine/include/utils/debug.hpp +++ b/src/engine/include/utils/debug.hpp @@ -14,8 +14,6 @@ #ifdef NDEBUG #define consoleLog(message) ((void)0) #define assertMsg(condition, message) ((void)0) -#define PRINT_LOG(TEXT) ((void)0) // DELETE ME -#define PRINT_ERR(TEXT) ((void)0) // DELETE ME #else // IF Debug #include @@ -37,8 +35,6 @@ public: #define assertMsg(condition, message) \ if (!(condition)) \ Debug::trap(message, __FILE__) -#define PRINT_LOG(TEXT) printf("LOG: " TEXT " (" __FILE__ ")\n") // DELETE ME -#define PRINT_ERR(TEXT) Debug::trap(TEXT, __FILE__) // DELETE ME -#endif // NDEBUG +#endif // NDEBUG #endif // _TYRA_DEBUG_ diff --git a/src/engine/loaders/bmp_loader.cpp b/src/engine/loaders/bmp_loader.cpp index c6d60d7..8652901 100644 --- a/src/engine/loaders/bmp_loader.cpp +++ b/src/engine/loaders/bmp_loader.cpp @@ -38,12 +38,7 @@ void BmpLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char * delete[] path_part1; delete[] path_part2; FILE *file = fopen(path, "rb"); - - if (file == NULL) - { - PRINT_ERR("Failed to load .bmp file!"); - return; - } + assertMsg(file != NULL, "Failed to load .bmp file!"); unsigned char header[54]; fread(header, sizeof(unsigned char), 54, file); @@ -53,10 +48,7 @@ void BmpLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char * u32 bits = (u32)header[28]; u32 dataOffset = (u32)header[10]; - if (bits != 24) - { - PRINT_ERR("Invalid bits per pixel in .bmp file - expected 24!"); - } + assertMsg(bits == 24, "Invalid bits per pixel in .bmp file - expected 24!"); o_texture.setSize(width, height, TEX_TYPE_RGB); printf("BMPLoader - width: %d | height: %d | bits: %d\n", width, height, bits); diff --git a/src/engine/loaders/dff_loader.cpp b/src/engine/loaders/dff_loader.cpp index 23f73d7..66eb7d8 100644 --- a/src/engine/loaders/dff_loader.cpp +++ b/src/engine/loaders/dff_loader.cpp @@ -36,11 +36,10 @@ DffLoader::~DffLoader() {} void DffLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT) { - PRINT_LOG("Loading dff file"); + consoleLog("Loading dff file"); char *path = String::createConcatenated("host:", t_filename); FILE *file = fopen(path, "rb"); - if (file == NULL) - PRINT_ERR("Failed to load .dff file!"); + assertMsg(file != NULL, "Failed to load .dff file!"); fseek(file, 0L, SEEK_END); long fileSize = ftell(file); u8 data[fileSize]; @@ -50,7 +49,7 @@ void DffLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ serialize(o_result, t_invertT, data, t_scale); o_result->calculateBoundingBoxes(); delete[] path; - PRINT_LOG("Dff file loaded!"); + consoleLog("Dff file loaded!"); } // void DffLoader::im_not_used_anywhere(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_invertT) diff --git a/src/engine/loaders/md2_loader.cpp b/src/engine/loaders/md2_loader.cpp index d459c00..24f2698 100644 --- a/src/engine/loaders/md2_loader.cpp +++ b/src/engine/loaders/md2_loader.cpp @@ -44,7 +44,7 @@ int MEM_fread(char *buf, size_t size, size_t n, const FILE *f) */ MeshFrame *MD2Loader::load(u32 &o_framesCount, char *t_subpath, char *t_nameWithoutExtension, float t_scale, u8 t_invertT) { - PRINT_LOG("Loading new MD2 file"); + consoleLog("Loading new MD2 file"); char *part1 = String::createConcatenated(t_subpath, t_nameWithoutExtension); char *part2 = String::createConcatenated("host:", part1); char *finalPath = String::createConcatenated(part2, ".md2"); // "folder/object.md2" @@ -53,20 +53,11 @@ MeshFrame *MD2Loader::load(u32 &o_framesCount, char *t_subpath, char *t_nameWith md2_t header; FILE *file = fopen(finalPath, "rb"); - - if (file == NULL) - { - PRINT_ERR("Failed to load .md2 file!"); - return NULL; - } + assertMsg(file != NULL, "Failed to load .md2 file!"); fread((char *)&header, sizeof(md2_t), 1, file); - if ((header.ident != MD2_IDENT) && (header.version != MD2_VERSION)) - { - PRINT_ERR("This MD2 file was not in correct format!"); - return NULL; - } + assertMsg((header.ident == MD2_IDENT) && (header.version == MD2_VERSION), "This MD2 file was not in correct format!"); u32 framesCount = header.num_frames; u32 vertexCount = header.num_xyz; @@ -147,7 +138,7 @@ MeshFrame *MD2Loader::load(u32 &o_framesCount, char *t_subpath, char *t_nameWith } } - PRINT_LOG("MD2 file loaded!"); + consoleLog("MD2 file loaded!"); delete[] finalPath; o_framesCount = framesCount; for (u32 i = 0; i < framesCount; i++) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 5c065e1..4d7a38b 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -30,8 +30,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ { char *path = String::createConcatenated("host:", t_filename); FILE *file = fopen(path, "rb"); - if (file == NULL) - PRINT_ERR("Failed to load .obj file!"); + assertMsg(file != NULL, "Failed to load .obj file!"); allocateObjMemory(file, o_result); fseek(file, 0, SEEK_SET); u32 verticesI = 0, cordsI = 0, normalsI = 0, faceI = 0, vertexIndex[3], coordIndex[3], normalIndex[3]; @@ -112,26 +111,19 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ /** Failed, checking configuration V//VN */ newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", x, x, x, x, x, x); fsetpos(file, &start); - if (newerMatches == 6) - { - /** Configuration confirmed. */ - newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", - &vertexIndex[0], &normalIndex[0], - &vertexIndex[1], &normalIndex[1], - &vertexIndex[2], &normalIndex[2]); - } - else - { - /**Unknown configuration.*/ - PRINT_ERR("Unknown .obj face for .obj file!"); - } + assertMsg(newerMatches == 6, "Unknown .obj face for .obj file!"); + /** Configuration confirmed. */ + newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", + &vertexIndex[0], &normalIndex[0], + &vertexIndex[1], &normalIndex[1], + &vertexIndex[2], &normalIndex[2]); } break; } break; default: { - PRINT_ERR("Unknown faces format in .obj file!"); + assertMsg(true == false, "Unknown faces format in .obj file!"); break; } } diff --git a/src/engine/loaders/png_loader.cpp b/src/engine/loaders/png_loader.cpp index 402800c..76bef66 100644 --- a/src/engine/loaders/png_loader.cpp +++ b/src/engine/loaders/png_loader.cpp @@ -40,9 +40,7 @@ void PngLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char * delete[] path_part2; FILE *file = fopen(path, "rb"); - - if (file == NULL) - PRINT_ERR("Failed to open .png file!"); + assertMsg(file != NULL, "Failed to open .png file!"); png_structp png_ptr; png_infop info_ptr; @@ -52,26 +50,15 @@ void PngLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char * int bit_depth, color_type, interlace_type; png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL); - - if (!png_ptr) - PRINT_ERR("PNG struct info init failed(1)!"); - + assertMsg(png_ptr, "PNG struct info init failed(1)!"); info_ptr = png_create_info_struct(png_ptr); - - if (!info_ptr) - PRINT_ERR("PNG struct info init failed(2)!"); - - if (setjmp(png_jmpbuf(png_ptr))) - PRINT_ERR("PNG reader fatal error!"); + assertMsg(info_ptr, "PNG struct info init failed(2)!"); + assertMsg(!setjmp(png_jmpbuf(png_ptr)), "PNG reader fatal error!"); png_init_io(png_ptr, file); - png_set_sig_bytes(png_ptr, sig_read); - png_read_info(png_ptr, info_ptr); - png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL); - png_set_strip_16(png_ptr); if (color_type == PNG_COLOR_TYPE_PALETTE) @@ -98,7 +85,7 @@ void PngLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char * type = TEX_TYPE_RGB; break; default: - PRINT_ERR("This png format is not supported! RGB/RGBA only."); + assertMsg(true == false, "This png format is not supported! RGB/RGBA only."); } o_texture.setSize(width, height, type); diff --git a/src/engine/models/mesh.cpp b/src/engine/models/mesh.cpp index e4dd355..54537b6 100644 --- a/src/engine/models/mesh.cpp +++ b/src/engine/models/mesh.cpp @@ -70,9 +70,8 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, const float &t_scale, con void Mesh::loadObj(char *t_subfolder, char *t_objFile, const float &t_scale, const u32 &t_framesCount, const u8 &t_invertT) { - if (t_framesCount == 0) - PRINT_ERR("Frames count cannot be 0!"); - else if (t_framesCount == 1) + assertMsg(t_framesCount != 0, "Frames count cannot be 0!"); + if (t_framesCount == 1) loadObj(t_subfolder, t_objFile, t_scale, t_invertT); else { @@ -132,39 +131,27 @@ void Mesh::loadFrom(const Mesh &t_mesh) void Mesh::playAnimation(const u32 &t_startFrame, const u32 &t_endFrame) { - if (framesCount > 1) - { - if (t_endFrame >= framesCount) - PRINT_ERR("End frame value is too high. Valid range: (0, getFramesCount()-1)"); - animState.startFrame = t_startFrame; - animState.endFrame = t_endFrame; - if (animState.currentFrame == t_startFrame) - animState.nextFrame = t_endFrame; - else - animState.nextFrame = t_startFrame; - } - else if (framesCount == 0) - PRINT_ERR("Cant play animation, because no mesh data was loaded!"); - else if (framesCount == 1) - PRINT_ERR("Cant play animation, because this mesh have only one frame."); + assertMsg(framesCount > 0, "Cant play animation, because no mesh data was loaded!"); + assertMsg(framesCount != 1, "Cant play animation, because this mesh have only one frame."); + assertMsg(t_endFrame < framesCount, "End frame value is too high. Valid range: (0, getFramesCount()-1)"); + animState.startFrame = t_startFrame; + animState.endFrame = t_endFrame; + if (animState.currentFrame == t_startFrame) + animState.nextFrame = t_endFrame; + else + animState.nextFrame = t_startFrame; } void Mesh::playAnimation(const u32 &t_startFrame, const u32 &t_endFrame, const u32 &t_stayFrame) { - if (framesCount > 1) - { - if (t_endFrame >= framesCount) - PRINT_ERR("End frame value is too high. Valid range: (0, getFramesCount()-1)"); - animState.startFrame = t_startFrame; - animState.endFrame = t_endFrame; - animState.isStayFrameSet = true; - animState.stayFrame = t_stayFrame; - animState.nextFrame = t_startFrame; - } - else if (framesCount == 0) - PRINT_ERR("Cant play animation, because no mesh data was loaded!"); - else if (framesCount == 1) - PRINT_ERR("Cant play animation, because this mesh have only one frame."); + assertMsg(framesCount > 0, "Cant play animation, because no mesh data was loaded!"); + assertMsg(framesCount != 1, "Cant play animation, because this mesh have only one frame."); + assertMsg(t_endFrame < framesCount, "End frame value is too high. Valid range: (0, getFramesCount()-1)"); + animState.startFrame = t_startFrame; + animState.endFrame = t_endFrame; + animState.isStayFrameSet = true; + animState.stayFrame = t_stayFrame; + animState.nextFrame = t_startFrame; } void Mesh::animate() diff --git a/src/engine/models/mesh_frame.cpp b/src/engine/models/mesh_frame.cpp index 4fc959f..699c39c 100644 --- a/src/engine/models/mesh_frame.cpp +++ b/src/engine/models/mesh_frame.cpp @@ -52,11 +52,7 @@ MeshFrame::~MeshFrame() void MeshFrame::allocateSTs(const u32 &t_val) { - if (_areSTsAllocated) - { - PRINT_ERR("Can't allocate STs, because were already set!"); - return; - } + assertMsg(!_areSTsAllocated, "Can't allocate STs, because were already set!"); stsCount = t_val; sts = new Point[t_val]; _areSTsAllocated = true; @@ -64,11 +60,7 @@ void MeshFrame::allocateSTs(const u32 &t_val) void MeshFrame::allocateVertices(const u32 &t_val) { - if (_areVerticesAllocated) - { - PRINT_ERR("Can't allocate vertices, because were already set!"); - return; - } + assertMsg(!_areVerticesAllocated, "Can't allocate vertices, because were already set!"); vertexCount = t_val; vertices = new Vector3[t_val]; _areVerticesAllocated = true; @@ -76,11 +68,7 @@ void MeshFrame::allocateVertices(const u32 &t_val) void MeshFrame::allocateNormals(const u32 &t_val) { - if (_areNormalsAllocated) - { - PRINT_ERR("Can't allocate normals, because were already set!"); - return; - } + assertMsg(!_areNormalsAllocated, "Can't allocate normals, because were already set!"); normalsCount = t_val; normals = new Vector3[t_val]; _areNormalsAllocated = true; @@ -88,11 +76,7 @@ void MeshFrame::allocateNormals(const u32 &t_val) void MeshFrame::allocateMaterials(const u32 &t_val) { - if (_areMaterialsAllocated) - { - PRINT_ERR("Can't allocate materials, because were already set!"); - return; - } + assertMsg(!_areMaterialsAllocated, "Can't allocate materials, because were already set!"); materialsCount = t_val; materials = new MeshMaterial[t_val]; _areMaterialsAllocated = true; @@ -100,9 +84,7 @@ void MeshFrame::allocateMaterials(const u32 &t_val) void MeshFrame::calculateBoundingBoxes() { - if (!_areVerticesAllocated) - PRINT_ERR("Can't calculate bounding box, because vertices were not allocated!"); - + assertMsg(_areVerticesAllocated, "Can't calculate bounding box, because vertices were not allocated!"); for (u32 i = 0; i < materialsCount; i++) materials->calculateBoundingBox(vertices, vertexCount); diff --git a/src/engine/models/mesh_material.cpp b/src/engine/models/mesh_material.cpp index b758840..0fb947b 100644 --- a/src/engine/models/mesh_material.cpp +++ b/src/engine/models/mesh_material.cpp @@ -52,11 +52,7 @@ MeshMaterial::~MeshMaterial() void MeshMaterial::allocateFaces(const u32 &t_val) { - if (_areFacesAllocated) - { - PRINT_ERR("Can't allocate faces, because were already set!"); - return; - } + assertMsg(!_areFacesAllocated, "Can't allocate faces, because were already set!"); facesCount = t_val; stFaces = new u32[t_val]; normalFaces = new u32[t_val]; @@ -66,11 +62,7 @@ void MeshMaterial::allocateFaces(const u32 &t_val) void MeshMaterial::setName(char *t_val) { - if (_isNameSet) - { - PRINT_ERR("Can't set name, because was already set!"); - return; - } + assertMsg(!_isNameSet, "Can't set name, because was already set!"); name = String::createCopy(t_val); _isNameSet = true; } @@ -143,8 +135,8 @@ void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount) boundingBox[7].set(hiX, hiY, hiZ); _isBoundingBoxCalculated = true; - //BoundingBox is declared on the heap to prevent any ill-formed default - //constructor instantiated BoundingBox objects. + // BoundingBox is declared on the heap to prevent any ill-formed default + // constructor instantiated BoundingBox objects. boundingBoxObj = new BoundingBox(boundingBox); } diff --git a/src/engine/models/texture.cpp b/src/engine/models/texture.cpp index 1c247b3..107c353 100644 --- a/src/engine/models/texture.cpp +++ b/src/engine/models/texture.cpp @@ -41,13 +41,8 @@ Texture::~Texture() void Texture::setSize(const u8 &t_width, const u8 &t_height, const TextureType &t_type) { - if (_isSizeSet) - { - PRINT_ERR("Can't set size, because was already set!"); - return; - } - if (t_width > 256 || t_height > 256) - PRINT_ERR("Given texture can be too big for PS2. Please strict to 256x256 max. Prefer 128x128."); + assertMsg(!_isSizeSet, "Can't set size, because was already set!"); + assertMsg(t_width <= 256 && t_height <= 256, "Given texture can be too big for PS2. Please strict to 256x256 max. Prefer 128x128."); width = t_width; height = t_height; _type = t_type; @@ -57,11 +52,7 @@ void Texture::setSize(const u8 &t_width, const u8 &t_height, const TextureType & void Texture::setName(char *t_val) { - if (_isNameSet) - { - PRINT_ERR("Can't set name, because was already set!"); - return; - } + assertMsg(!_isNameSet, "Can't set name, because was already set!"); name = String::createCopy(t_val); _isNameSet = true; } diff --git a/src/engine/modules/audio.cpp b/src/engine/modules/audio.cpp index f7b51c0..d8a6165 100644 --- a/src/engine/modules/audio.cpp +++ b/src/engine/modules/audio.cpp @@ -52,20 +52,15 @@ void Audio::loadSong(char *t_path) char *fullFilename = String::createConcatenated("host:", t_path); wav = fopen(fullFilename, "rb"); delete[] fullFilename; - if (wav == NULL) - PRINT_ERR("Failed to open wav file!"); - else - { - rewindSongToStart(); - songLoaded = true; - PRINT_LOG("Song loaded!"); - } + assertMsg(wav != NULL, "Failed to open wav file!"); + rewindSongToStart(); + songLoaded = true; + consoleLog("Song loaded!"); } void Audio::playSong() { - if (!songLoaded) - PRINT_ERR("Cant play song because was not loaded!"); + assertMsg(songLoaded, "Cant play song because was not loaded!"); if (songFinished) rewindSongToStart(); volume = realVolume; @@ -105,8 +100,7 @@ void Audio::removeSongListener(const u32 &t_id) index = i; break; } - if (index == -1) - PRINT_ERR("Cant remove listener because given id was not found!"); + assertMsg(index != -1, "Cant remove listener because given id was not found!"); delete songListeners[index]; songListeners.erase(songListeners.begin() + index); } @@ -132,7 +126,7 @@ audsrv_adpcm_t *Audio::loadADPCM(char *t_path) if (audsrv_load_adpcm(result, data, adpcmFileSize)) { printf("AUDSRV returned error string: %s", audsrv_get_error_string()); - PRINT_ERR("audsrv_load_adpcm() failed!"); + assertMsg(true == false, "audsrv_load_adpcm() failed!"); } fclose(file); return result; @@ -143,7 +137,7 @@ void Audio::playADPCM(audsrv_adpcm_t *t_adpcm) if (audsrv_play_adpcm(t_adpcm)) { printf("AUDSRV returned error string: %s", audsrv_get_error_string()); - PRINT_ERR("audsrv_play_adpcm() failed!"); + assertMsg(true == false, "audsrv_play_adpcm() failed!"); } } @@ -152,7 +146,7 @@ void Audio::playADPCM(audsrv_adpcm_t *t_adpcm, const s8 &t_ch) if (audsrv_ch_play_adpcm(t_ch, t_adpcm)) { printf("AUDSRV returned error string: %s", audsrv_get_error_string()); - PRINT_ERR("audsrv_play_adpcm() failed!"); + assertMsg(true == false, "audsrv_ch_play_adpcm() failed!"); } } @@ -160,7 +154,7 @@ void Audio::playADPCM(audsrv_adpcm_t *t_adpcm, const s8 &t_ch) void Audio::startThread(FileService *t_fileService) { - PRINT_LOG("Creating audio thread"); + consoleLog("Creating audio thread"); // fileService = t_fileService; extern void *_gp; thread.func = (void *)Audio::mainThread; @@ -168,11 +162,11 @@ void Audio::startThread(FileService *t_fileService) thread.stack_size = getThreadStackSize(); thread.gp_reg = (void *)&_gp; thread.initial_priority = 0x17; - if ((threadId = CreateThread(&thread)) < 0) - PRINT_ERR("Create audio thread failed!"); - PRINT_LOG("Audio thread created"); + threadId = CreateThread(&thread); + assertMsg(threadId >= 0, "Create audio thread failed!"); + consoleLog("Audio thread created"); StartThread(threadId, NULL); - PRINT_LOG("Audio thread started"); + consoleLog("Audio thread started"); } /** Main thread loop */ @@ -256,25 +250,23 @@ void Audio::rewindSongToStart() /** Initialize semaphore which will wait until chunk of the song is not finished. */ void Audio::initSema() { - PRINT_LOG("Creating audio semaphore"); + consoleLog("Creating audio semaphore"); sema.init_count = 0; sema.max_count = 1; sema.option = 0; fillbufferSema = CreateSema(&sema); - PRINT_LOG("Audio semaphore created"); + consoleLog("Audio semaphore created"); } /** Load LIBSD and AUDSRV modules */ void Audio::loadModules() { - PRINT_LOG("Modules loading started (LIBSD, AUDSRV)"); + consoleLog("Modules loading started (LIBSD, AUDSRV)"); int ret = SifLoadModule("rom0:LIBSD", 0, NULL); - if (ret == -203) - PRINT_ERR("LIBSD loading failed!"); + assertMsg(ret != -203, "LIBSD loading failed!"); ret = SifLoadModule("host:AUDSRV.IRX", 0, NULL); - if (ret == -203) - PRINT_ERR("AUDSRV.IRX loading failed!"); - PRINT_LOG("Audio modules loaded"); + assertMsg(ret != -203, "AUDSRV.IRX loading failed!"); + consoleLog("Audio modules loaded"); } /** @@ -283,26 +275,26 @@ void Audio::loadModules() */ void Audio::initAUDSRV() { - PRINT_LOG("Initializing AUDSRV"); + consoleLog("Initializing AUDSRV"); int ret = audsrv_init(); if (ret != 0) { printf("AUDSRV returned error string: %s", audsrv_get_error_string()); - PRINT_ERR("Failed to initialize AUDSRV!"); + assertMsg(true == false, "Failed to initialize AUDSRV!"); } ret = audsrv_adpcm_init(); if (ret != 0) { printf("AUDSRV returned error string: %s", audsrv_get_error_string()); - PRINT_ERR("Failed to initialize AUDSRV ADPCM!"); + assertMsg(true == false, "Failed to initialize AUDSRV ADPCM!"); } ret = audsrv_on_fillbuf(getSongBufferSize(), (audsrv_callback_t)iSignalSema, (void *)fillbufferSema); if (ret != 0) { printf("AUDSRV returned error string: %s", audsrv_get_error_string()); - PRINT_ERR("Failed to initialize AUDSRV fillbuffer!"); + assertMsg(true == false, "Failed to initialize AUDSRV fillbuffer!"); } - PRINT_LOG("AUDSRV initialized!"); + consoleLog("AUDSRV initialized!"); } /** diff --git a/src/engine/modules/camera_base.cpp b/src/engine/modules/camera_base.cpp index 8453012..f6df653 100644 --- a/src/engine/modules/camera_base.cpp +++ b/src/engine/modules/camera_base.cpp @@ -21,7 +21,7 @@ CameraBase::CameraBase(ScreenSettings *t_screen, Vector3 *t_position) : screen(t_screen) { - PRINT_LOG("Initializing frustum"); + consoleLog("Initializing frustum"); farPlaneDist = screen->farPlaneDist; nearPlaneDist = screen->nearPlaneDist; float tang = tanf(screen->fov * Math::HALF_ANG2RAD); @@ -31,7 +31,7 @@ CameraBase::CameraBase(ScreenSettings *t_screen, Vector3 *t_position) farWidth = farHeight * screen->aspectRatio; p_position = t_position; up.set(0.0F, 1.0F, 0.0F); - PRINT_LOG("CameraBase initialized!"); + consoleLog("CameraBase initialized!"); } // ---- diff --git a/src/engine/modules/file_service.cpp b/src/engine/modules/file_service.cpp index daec879..1cf1c8a 100644 --- a/src/engine/modules/file_service.cpp +++ b/src/engine/modules/file_service.cpp @@ -43,8 +43,7 @@ u32 FileService::addReadChunk(FILE *t_file, void *t_destination, const u32 &t_si s32 FileService::isTaskDone(const u32 &t_taskId) { s32 taskIndex = getIndexOf(t_taskId); - if (taskIndex == -1) - PRINT_ERR("Task was not found!"); + assertMsg(taskIndex != -1, "Task was not found!"); s32 result = tasks[taskIndex].readStatus; if (result != -2137) removeByIndex(taskIndex); @@ -54,10 +53,8 @@ s32 FileService::isTaskDone(const u32 &t_taskId) const void FileService::removeById(const u32 &t_taskId) { s32 index = getIndexOf(t_taskId); - if (index != -1) - removeByIndex(index); - else - PRINT_ERR("Cant remove task, because it was not found!"); + assertMsg(index != -1, "Cant remove task, because it was not found!"); + removeByIndex(index); } const s32 FileService::getIndexOf(const u32 &t_taskId) @@ -72,18 +69,18 @@ const s32 FileService::getIndexOf(const u32 &t_taskId) void FileService::startThread() { - PRINT_LOG("Creating file service thread"); + consoleLog("Creating file service thread"); extern void *_gp; thread.func = (void *)FileService::mainThread; thread.stack = threadStack; thread.stack_size = getThreadStackSize(); thread.gp_reg = (void *)&_gp; thread.initial_priority = 0x12; - if ((threadId = CreateThread(&thread)) < 0) - PRINT_ERR("Create audio thread failed!"); - PRINT_LOG("File service created"); + threadId = CreateThread(&thread); + assertMsg(threadId >= 0, "Create audio thread failed!"); + consoleLog("File service created"); StartThread(threadId, NULL); - PRINT_LOG("File service started"); + consoleLog("File service started"); } /** Main thread loop */ diff --git a/src/engine/modules/gif_sender.cpp b/src/engine/modules/gif_sender.cpp index cf0eac5..2250215 100644 --- a/src/engine/modules/gif_sender.cpp +++ b/src/engine/modules/gif_sender.cpp @@ -30,12 +30,12 @@ */ GifSender::GifSender(u32 t_packetSize, ScreenSettings *t_screen, Light *t_light) : screen(t_screen) { - PRINT_LOG("Initializing GifSender"); + consoleLog("Initializing GifSender"); light = t_light; packetSize = t_packetSize; packets[0] = packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, false); packets[1] = packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, false); - PRINT_LOG("GifSender initialized!"); + consoleLog("GifSender initialized!"); } /** Releases packets memory */ diff --git a/src/engine/modules/pad.cpp b/src/engine/modules/pad.cpp index 4348d8c..edd340e 100644 --- a/src/engine/modules/pad.cpp +++ b/src/engine/modules/pad.cpp @@ -30,15 +30,10 @@ Pad::Pad() this->slot = 0; // Always zero if not using multitap if ((this->ret = padPortOpen(this->port, this->slot, padBuf)) == 0) { - PRINT_ERR("padPortOpen failed!"); printf("padPortOpen returned: %d\n", this->ret); - SleepThread(); - } - if (!this->initPad()) - { - PRINT_ERR("initPad failed!"); - SleepThread(); + assertMsg(true == false, "padPortOpen failed!"); } + assertMsg(this->initPad(), "initPad failed!"); } Pad::~Pad() {} @@ -50,22 +45,20 @@ Pad::~Pad() {} /** Load SIO2MAN and PADMAN modules */ void Pad::loadModules() { - PRINT_LOG("Loading pad modules"); + consoleLog("Loading pad modules"); this->ret = SifLoadModule("rom0:SIO2MAN", 0, NULL); if (this->ret < 0) { - PRINT_ERR("SifLoadModule (SIO2MAN) failed!"); printf("SifLoadModule returned: %d\n", this->ret); - SleepThread(); + assertMsg(true == false, "SifLoadModule (SIO2MAN) failed!"); } this->ret = SifLoadModule("rom0:PADMAN", 0, NULL); if (this->ret < 0) { - PRINT_ERR("SifLoadModule (PADMAN) failed!"); printf("SifLoadModule returned: %d\n", this->ret); - SleepThread(); + assertMsg(true == false, "SifLoadModule (PADMAN) failed!"); } - PRINT_LOG("Pad modules loaded!"); + consoleLog("Pad modules loaded!"); } /** Wait when pad will be ready (stable and ready) */ @@ -81,7 +74,7 @@ int Pad::waitPadReady() if (state != lastState) { padStateInt2String(state, stateString); - PRINT_LOG("Pad state changed"); + consoleLog("Pad state changed"); printf("Curent pad(%d,%d) status: %s\n", this->port, this->slot, stateString); } lastState = state; @@ -89,23 +82,20 @@ int Pad::waitPadReady() } // Were the pad ever 'out of sync'? if (lastState != -1) - PRINT_LOG("Pad is ready!"); + consoleLog("Pad is ready!"); return 0; } /** Initializes and checks type of pad */ int Pad::initPad() { - PRINT_LOG("Initializing pad"); + consoleLog("Initializing pad"); this->waitPadReady(); // How many different modes can this device operate in? // i.e. get # entrys in the modetable int modes = padInfoMode(this->port, this->slot, PAD_MODETABLE, -1); - if (modes == 0) - { - PRINT_ERR("Connected device is not a dual shock controller!"); // (it has no actuator engines) - return 1; - } + assertMsg(modes, "Connected device is not a dual shock controller!"); // (it has no actuator engines) + // Verify that the controller has a DUAL SHOCK mode int i = 0; do @@ -115,22 +105,14 @@ int Pad::initPad() i++; } while (i < modes); - if (i >= modes) - { - PRINT_ERR("Connected device is not a dual shock controller!"); - return 1; - } + assertMsg(i < modes, "Connected device is not a dual shock controller!"); // If ExId != 0x0 => This controller has actuator engines // This check should always pass if the Dual Shock test above passed this->ret = padInfoMode(this->port, this->slot, PAD_MODECUREXID, 0); - if (this->ret == 0) - { - PRINT_ERR("Connected device is not a dual shock controller!"); - return 1; - } + assertMsg(this->ret, "Connected device is not a dual shock controller!"); - PRINT_LOG("Enabling dual shock functions."); + consoleLog("Enabling dual shock functions."); // When using MMODE_LOCK, user cant change mode with Select button padSetMainMode(this->port, this->slot, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK); @@ -156,7 +138,7 @@ int Pad::initPad() else printf("Did not find any actuators.\n"); this->waitPadReady(); - PRINT_LOG("Pad initialized!"); + consoleLog("Pad initialized!"); return 1; } diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index f554b82..92f82d0 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -33,7 +33,7 @@ static const float SCREEN_CENTER = GS_CENTER / 2.0F; */ Renderer::Renderer(u32 t_packetSize, ScreenSettings *t_screen) { - PRINT_LOG("Initializing renderer"); + consoleLog("Initializing renderer"); dma_channel_initialize(DMA_CHANNEL_GIF, NULL, 0); // Initialize DMA to enable data transfer dma_channel_fast_waits(DMA_CHANNEL_GIF); screen = t_screen; @@ -53,7 +53,7 @@ Renderer::Renderer(u32 t_packetSize, ScreenSettings *t_screen) vifSender = new VifSender(&light); perspective.setPerspective(*t_screen); renderData.projection = &perspective; - PRINT_LOG("Renderer initialized!"); + consoleLog("Renderer initialized!"); } Renderer::~Renderer() {} @@ -69,8 +69,7 @@ void Renderer::allocateTextureBuffer(Texture *t_texture) textureBuffer.psm = t_texture->getType(); textureBuffer.info.components = textureBuffer.psm == TEX_TYPE_RGBA ? TEXTURE_COMPONENTS_RGBA : TEXTURE_COMPONENTS_RGB; textureBuffer.address = graph_vram_allocate(t_texture->getWidth(), t_texture->getHeight(), textureBuffer.psm, GRAPH_ALIGN_BLOCK); - if (textureBuffer.address <= 1) - PRINT_ERR("Texture buffer allocation error. No memory!"); + assertMsg(textureBuffer.address > 1, "Texture buffer allocation error. No memory!"); textureBuffer.info.width = draw_log2(t_texture->getWidth()); textureBuffer.info.height = draw_log2(t_texture->getHeight()); textureBuffer.info.function = TEXTURE_FUNCTION_MODULATE; @@ -89,18 +88,14 @@ void Renderer::deallocateTextureBuffer() void Renderer::changeTexture(Texture *t_tex) { - if (t_tex != NULL) + assertMsg(t_tex != NULL, "Texture was not found in texture repository!"); + if (t_tex->getId() != lastTextureId) { - if (t_tex->getId() != lastTextureId) - { - lastTextureId = t_tex->getId(); - deallocateTextureBuffer(); - allocateTextureBuffer(t_tex); - GifSender::sendTexture(*t_tex, &textureBuffer); - } + lastTextureId = t_tex->getId(); + deallocateTextureBuffer(); + allocateTextureBuffer(t_tex); + GifSender::sendTexture(*t_tex, &textureBuffer); } - else - PRINT_ERR("Texture was not found in texture repository!"); } void Renderer::draw(Sprite &t_sprite) @@ -164,7 +159,7 @@ void Renderer::draw(Sprite &t_sprite) /** Initializes drawing environment (1st app packet) */ void Renderer::initDrawingEnv() { - PRINT_LOG("Initializing drawing environment"); + consoleLog("Initializing drawing environment"); packet2_t *packet2 = packet2_create(20, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0); packet2_update(packet2, draw_setup_environment(packet2->base, 0, frameBuffers, &(zBuffer))); packet2_update(packet2, draw_primitive_xyoffset(packet2->next, 0, @@ -174,7 +169,7 @@ void Renderer::initDrawingEnv() dma_channel_send_packet2(packet2, DMA_CHANNEL_GIF, true); dma_channel_wait(DMA_CHANNEL_GIF, 0); packet2_free(packet2); - PRINT_LOG("Drawing environment initialized!"); + consoleLog("Drawing environment initialized!"); } /** Sets drawing prim for all 3D objects */ @@ -189,7 +184,7 @@ void Renderer::setPrim() prim.mapping_type = PRIM_MAP_ST; prim.colorfix = PRIM_UNFIXED; renderData.prim = &prim; - PRINT_LOG("Prim set!"); + consoleLog("Prim set!"); } void Renderer::setWorldColor(const color_t &t_rgb) @@ -219,7 +214,7 @@ void Renderer::allocateBuffers(int t_screenW, int t_screenH) zBuffer.method = ZTEST_METHOD_GREATER_EQUAL; zBuffer.zsm = GS_ZBUF_24; zBuffer.address = graph_vram_allocate(t_screenW, t_screenH, zBuffer.zsm, GRAPH_ALIGN_PAGE); - PRINT_LOG("Framebuffers, zBuffer set and allocated!"); + consoleLog("Framebuffers, zBuffer set and allocated!"); // Initialize the screen and tie the first framebuffer to the read circuits. graph_initialize(frameBuffers[0].address, frameBuffers[0].width, frameBuffers[0].height, frameBuffers[0].psm, 0, 0); @@ -274,9 +269,8 @@ void Renderer::allocateBuffers(int t_screenW, int t_screenH) void Renderer::draw(Mesh **t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount) { beginFrameIfNeeded(); - if (!t_meshes[0]->isDataLoaded()) - PRINT_ERR("Can't draw, because no mesh data was loaded!"); - else if ( + assertMsg(t_meshes[0]->isDataLoaded(), "Can't draw, because no mesh data was loaded!"); + if ( t_amount >= 3 && !t_meshes[0]->shouldBeBackfaceCulled && t_meshes[0]->getFramesCount() == 1 && @@ -309,9 +303,7 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) { beginFrameIfNeeded(); vifSender->calcMatrix(renderData, t_mesh.position, t_mesh.rotation); - if (!t_mesh.isDataLoaded()) - PRINT_ERR("Can't draw, because no mesh data was loaded!"); - + assertMsg(t_mesh.isDataLoaded(), "Can't draw, because no mesh data was loaded!"); camRotation.identity(); camRotation.rotate(-t_mesh.rotation); Vector3 rotatedCamera = Vector3(camRotation * *renderData.cameraPosition); diff --git a/src/engine/modules/texture_repository.cpp b/src/engine/modules/texture_repository.cpp index 2b4f816..ef35950 100644 --- a/src/engine/modules/texture_repository.cpp +++ b/src/engine/modules/texture_repository.cpp @@ -17,8 +17,8 @@ TextureRepository::TextureRepository() { - PRINT_LOG("Initializing texture repository"); - PRINT_LOG("Texture repository initialized!"); + consoleLog("Initializing texture repository"); + consoleLog("Texture repository initialized!"); } TextureRepository::~TextureRepository() diff --git a/src/engine/modules/vif_sender.cpp b/src/engine/modules/vif_sender.cpp index b078fd9..544edbc 100644 --- a/src/engine/modules/vif_sender.cpp +++ b/src/engine/modules/vif_sender.cpp @@ -33,7 +33,7 @@ extern u32 VU1Draw3D_CodeEnd __attribute__((section(".vudata"))); VifSender::VifSender(Light *t_light) { - PRINT_LOG("Initializing VifSender"); + consoleLog("Initializing VifSender"); light = t_light; lastVertCount = 0; isDrawWaitEnabled = true; @@ -44,7 +44,7 @@ VifSender::VifSender(Light *t_light) packets[1] = packet2_create(VU1_PACKET_SIZE, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); context = 0; setDoubleBufferAddStaticData(); - PRINT_LOG("VifSender initialized!"); + consoleLog("VifSender initialized!"); } VifSender::~VifSender()