From 2d1e2f42d096dcff29fe6c3bf2e887df2f5f2ec3 Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 27 Apr 2016 20:51:44 +0200 Subject: [PATCH] Small fixes --- src/main.c | 18 +++++---------- src/patcher/cpp_to_c_util.cpp | 42 +++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/main.c b/src/main.c index a39d0ae..32d3238 100644 --- a/src/main.c +++ b/src/main.c @@ -16,20 +16,11 @@ #include "game/memory_area_table.h" #include "start.h" #include "patcher/function_hooks.h" +#include "patcher/cpp_to_c_util.h" #include "kernel/kernel_functions.h" #include "system/exception_handler.h" -#include "fs/fs_utils.h" -#include "fs/sd_fat_devoptab.h" #include "controller_patcher/controller_patcher.h" -typedef union u_serv_ip -{ - uint8_t digit[4]; - uint32_t full; -} u_serv_ip; - -#define PRINT_TEXT2(x, y, ...) { snprintf(msg, 80, __VA_ARGS__); OSScreenPutFontEx(0, x, y, msg); OSScreenPutFontEx(1, x, y, msg); } - /* Entry point */ int Menu_Main(void) { @@ -42,6 +33,8 @@ int Menu_Main(void) InitGX2FunctionPointers(); InitSysFunctionPointers(); + draw_Cursor_destroy(); + log_init("192.168.0.181"); SetupKernelCallback(); @@ -59,11 +52,12 @@ int Menu_Main(void) } if(strlen(cosAppXmlInfoStruct.rpx_name) <= 0){ // First boot back to SysMenu - log_printf("Startssed %s\n", cosAppXmlInfoStruct.rpx_name); SYSLaunchMenu(); return EXIT_RELAUNCH_ON_LOAD; } - log_printf("Stafdsf %s\n", cosAppXmlInfoStruct.rpx_name); + + draw_Cursor_destroy(); + RestoreInstructions(); deinit_config_controller(); diff --git a/src/patcher/cpp_to_c_util.cpp b/src/patcher/cpp_to_c_util.cpp index af3d0e7..76de1ac 100644 --- a/src/patcher/cpp_to_c_util.cpp +++ b/src/patcher/cpp_to_c_util.cpp @@ -3,8 +3,26 @@ #include "common/common.h" #include "video/shaders/ColorShader.h" -// TODO: not creating these stuff at every frame +u8 gCursorInitDone __attribute__((section(".data"))) = 0; + +static u8 * cursor_colorVtxs = NULL; + +void init_cursor(){ + if(!gCursorInitDone){ + if(!cursor_colorVtxs){ + cursor_colorVtxs = (u8*)memalign(0x40, sizeof(u8) * 16); + if(cursor_colorVtxs == NULL) return; + } + memset(cursor_colorVtxs,0xFF,16*sizeof(u8)); + GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, cursor_colorVtxs, 16 * sizeof(u8)); + gCursorInitDone = 1; + } +} + void draw_Cursor_at(f32 x, f32 y) { + init_cursor(); + if(cursor_colorVtxs == NULL) return; + f32 widthScaleFactor = 1.0f / (f32)1280; f32 heightScaleFactor = 1.0f / (f32)720; @@ -15,31 +33,27 @@ void draw_Cursor_at(f32 x, f32 y) { positionOffsets[0] = (x-((1280)/2)+(width/2)) * widthScaleFactor * 2.0f; positionOffsets[1] = -(y-((720)/2)+(width/2)) * heightScaleFactor * 2.0f; - u8 colorVtxs[16]; - memset(colorVtxs,0xFF,16*sizeof(u8)); - - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, colorVtxs, 16 * sizeof(u8)); - - glm::vec4 colorIntensity = glm::vec4(1.0f); - colorIntensity[3] = 255; - glm::vec3 scale(width*widthScaleFactor,width*heightScaleFactor,1.0f); + + ColorShader::instance()->setShaders(); - ColorShader::instance()->setAttributeBuffer(colorVtxs, NULL, 4); + ColorShader::instance()->setAttributeBuffer(cursor_colorVtxs, NULL, 4); ColorShader::instance()->setAngle(0); ColorShader::instance()->setOffset(positionOffsets); ColorShader::instance()->setScale(scale); - ColorShader::instance()->setColorIntensity(colorIntensity); + ColorShader::instance()->setColorIntensity(glm::vec4(1.0f)); ColorShader::instance()->draw(GX2_PRIMITIVE_QUADS, 4); } - void draw_Cursor_destroy() { //! destroy shaders ColorShader::destroyInstance(); + if(cursor_colorVtxs){ + free(cursor_colorVtxs); + cursor_colorVtxs = NULL; + } + gCursorInitDone = 0; } - -