diff --git a/.gitignore b/.gitignore index 065103d..fdfb2d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,6 @@ -build/* -*.cbp +build/ +*.rpx *.elf -*.cscope_file_list -*.layout -screenshots/* -release/* -*.mod -*.id* -*.nam -*.til -*.layout \ No newline at end of file +*.exe +src/resources/filelist.h +*.cbp diff --git a/.gitmodules b/.gitmodules index 3667759..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "src/mocha"] - path = src/mocha - url = https://github.com/Maschell/mocha - branch = sd_access diff --git a/Makefile b/Makefile index e026497..e214d13 100644 --- a/Makefile +++ b/Makefile @@ -1,270 +1,164 @@ -DO_LOGGING := 1 - -#--------------------------------------------------------------------------------- -# Clear the implicit built in rules -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- .SUFFIXES: -#--------------------------------------------------------------------------------- -ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") -endif +#------------------------------------------------------------------------------- + ifeq ($(strip $(DEVKITPRO)),) -$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=devkitPRO") +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") endif -export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH):$(DEVKITPRO)/tools/bin -export PORTLIBS := $(DEVKITPRO)/portlibs/ppc +TOPDIR ?= $(CURDIR) -PREFIX := powerpc-eabi- +include $(DEVKITPRO)/wut/share/wut_rules -export AS := $(PREFIX)as -export CC := $(PREFIX)gcc -export CXX := $(PREFIX)g++ -export AR := $(PREFIX)ar -export OBJCOPY := $(PREFIX)objcopy - -print-% : ; @echo $* = $($*) - -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- # TARGET is the name of the output # BUILD is the directory where object files & intermediate files will be placed # SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -#--------------------------------------------------------------------------------- -TARGET := wiiupluginloader -BUILD := build -BUILD_DBG := $(TARGET)_dbg -SOURCES := src/common \ - src/custom/gui \ - src/libelf \ - src/menu/content \ - src/menu \ - src/mymemory \ - src/mykernel \ - src/myutils \ - src/patcher \ - src/plugin \ - src/resources \ - src/settings \ - src/ +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +#------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCES := src \ + src/custom/gui \ + src/fs \ + src/game \ + src/plugin \ + src/language \ + src/menu \ + src/menu/content \ + src/resources \ + src/settings \ + src/system \ + src/utils +DATA := data \ + data/images \ + data/sounds \ + data/fonts +INCLUDES := src -DATA := data/images \ - data/sounds \ - data/fonts \ - -INCLUDES := src/libelf \ - src/ - -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- # options for code generation -#--------------------------------------------------------------------------------- -CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ - -O0 -D__wiiu__ -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing -D_GNU_SOURCE $(INCLUDE) -CXXFLAGS := -std=gnu++11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ - -O0 -D__wiiu__ -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing -D_GNU_SOURCE $(INCLUDE) +#------------------------------------------------------------------------------- +CFLAGS := -g -Wall -O2 -ffunction-sections \ + $(MACHDEP) -ifeq ($(DO_LOGGING), 1) - CFLAGS += -D__LOGGING__ - CXXFLAGS += -D__LOGGING__ -endif +CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -ASFLAGS := -mregnames -LDFLAGS := -nostartfiles -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,--gc-sections +CXXFLAGS := $(CFLAGS) -#--------------------------------------------------------------------------------- -Q := @ -MAKEFLAGS += --no-print-directory -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project -#--------------------------------------------------------------------------------- -LIBS := -lgui -lm -lgcc -lfat -liosuhax -lutils -ldynamiclibs -lfreetype -lgd -lpng -ljpeg -lz -lmad -lvorbisidec -logg -lbz2 +ASFLAGS := -g $(ARCH) +LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CURDIR) \ - $(DEVKITPPC)/lib \ - $(DEVKITPRO)/wups +LIBS := -lgui -lfreetype -lgd -lpng -ljpeg -lz -lmad -lvorbisidec -logg -lbz2 -lwut -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level +# containing include and lib +#------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(WUT_ROOT) + +#------------------------------------------------------------------------------- # no real need to edit anything past this point unless you need to add additional # rules for different file extensions -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- -export PROJECTDIR := $(CURDIR) -export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) -export DEPSDIR := $(CURDIR)/$(BUILD) - -#--------------------------------------------------------------------------------- -# automatically build a list of object files for our project -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- FILELIST := $(shell bash ./filelist.sh) -LANGUAGES := $(shell bash ./updatelang.sh) -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) -TTFFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ttf))) -PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) - export LD := $(CC) -else - export LD := $(CXX) -endif - -export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ - $(sFILES:.s=.o) $(SFILES:.S=.o) \ - $(PNGFILES:.png=.png.o) $(addsuffix .o,$(BINFILES)) - -#--------------------------------------------------------------------------------- -# build a list of include paths -#--------------------------------------------------------------------------------- -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(PORTLIBS)/include -I$(CURDIR)/$(BUILD) \ - -I$(PORTLIBS)/include/libutils \ - -I$(PORTLIBS)/include/freetype2 -I$(PORTLIBS)/include/libgui - - -#--------------------------------------------------------------------------------- -# build a list of library paths -#--------------------------------------------------------------------------------- -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ - -L$(PORTLIBS)/lib export OUTPUT := $(CURDIR)/$(TARGET) -.PHONY: $(BUILD) clean install +export TOPDIR := $(CURDIR) -#--------------------------------------------------------------------------------- -$(BUILD): $(CURDIR)/src/mocha/ios_kernel/ios_kernel.bin.h +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#------------------------------------------------------------------------------- + export LD := $(CC) +#------------------------------------------------------------------------------- +else +#------------------------------------------------------------------------------- + export LD := $(CXX) +#------------------------------------------------------------------------------- +endif +#------------------------------------------------------------------------------- + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) +export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) -I$(PORTLIBS_PATH)/ppc/include/freetype2 + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean all + +#------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): @[ -d $@ ] || mkdir -p $@ @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile -$(CURDIR)/src/mocha/ios_kernel/ios_kernel.bin.h: $(CURDIR)/src/mocha/ios_usb/ios_usb.bin.h $(CURDIR)/src/mocha/ios_mcp/ios_mcp.bin.h $(CURDIR)/src/mocha/ios_fs/ios_fs.bin.h $(CURDIR)/src/mocha/ios_bsp/ios_bsp.bin.h $(CURDIR)/src/mocha/ios_acp/ios_acp.bin.h - @$(MAKE) -j1 --no-print-directory -C $(CURDIR)/src/mocha/ios_kernel -f $(CURDIR)/src/mocha/ios_kernel/Makefile - -$(CURDIR)/src/mocha/ios_usb/ios_usb.bin.h: - @$(MAKE) -j1 --no-print-directory -C $(CURDIR)/src/mocha/ios_usb -f $(CURDIR)/src/mocha/ios_usb/Makefile - -$(CURDIR)/src/mocha/ios_fs/ios_fs.bin.h: - @$(MAKE) -j1 --no-print-directory -C $(CURDIR)/src/mocha/ios_fs -f $(CURDIR)/src/mocha/ios_fs/Makefile - -$(CURDIR)/src/mocha/ios_bsp/ios_bsp.bin.h: - @$(MAKE) -j1 --no-print-directory -C $(CURDIR)/src/mocha/ios_bsp -f $(CURDIR)/src/mocha/ios_bsp/Makefile - -$(CURDIR)/src/mocha/ios_mcp/ios_mcp.bin.h: - @$(MAKE) -j1 --no-print-directory -C $(CURDIR)/src/mocha/ios_mcp -f $(CURDIR)/src/mocha/ios_mcp/Makefile - -$(CURDIR)/src/mocha/ios_acp/ios_acp.bin.h: - @$(MAKE) -j1 --no-print-directory -C $(CURDIR)/src/mocha/ios_acp -f $(CURDIR)/src/mocha/ios_acp/Makefile - -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- clean: @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf - @$(MAKE) --no-print-directory -C $(CURDIR)/src/mocha/ios_kernel -f $(CURDIR)/src/mocha/ios_kernel/Makefile clean - @$(MAKE) --no-print-directory -C $(CURDIR)/src/mocha/ios_usb -f $(CURDIR)/src/mocha/ios_usb/Makefile clean - @$(MAKE) --no-print-directory -C $(CURDIR)/src/mocha/ios_fs -f $(CURDIR)/src/mocha/ios_fs/Makefile clean - @$(MAKE) --no-print-directory -C $(CURDIR)/src/mocha/ios_bsp -f $(CURDIR)/src/mocha/ios_bsp/Makefile clean - @$(MAKE) --no-print-directory -C $(CURDIR)/src/mocha/ios_mcp -f $(CURDIR)/src/mocha/ios_mcp/Makefile clean - @$(MAKE) --no-print-directory -C $(CURDIR)/src/mocha/ios_acp -f $(CURDIR)/src/mocha/ios_acp/Makefile clean + @rm -fr $(BUILD) $(TARGET).rpx $(TARGET).elf -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- else +.PHONY: all DEPENDS := $(OFILES:.o=.d) -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- # main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).elf: $(OFILES) +#------------------------------------------------------------------------------- +all : $(OUTPUT).rpx -#--------------------------------------------------------------------------------- -# This rule links in binary data with the .jpg extension -#--------------------------------------------------------------------------------- -%.elf: link.ld $(OFILES) - @echo "linking ... $(TARGET).elf" - $(Q)$(LD) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf $(LIBPATHS) $(LIBS) - $(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@ +$(OUTPUT).rpx : $(OUTPUT).elf +$(OUTPUT).elf : $(OFILES) -#--------------------------------------------------------------------------------- -%.a: -#--------------------------------------------------------------------------------- - @echo $(notdir $@) - @rm -f $@ - @$(AR) -rc $@ $^ +$(OFILES_SRC) : $(HFILES_BIN) -#--------------------------------------------------------------------------------- -%.o: %.cpp +#------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin @echo $(notdir $<) - @$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER) + @$(bin2o) -#--------------------------------------------------------------------------------- -%.o: %.c +%.png.o %_png.h : %.png @echo $(notdir $<) - @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER) - -#--------------------------------------------------------------------------------- -%.o: %.S - @echo $(notdir $<) - @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER) + @$(bin2o) -#--------------------------------------------------------------------------------- -%.o: %.s +%.ogg.o %_ogg.h : %.ogg @echo $(notdir $<) - @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER) - -#--------------------------------------------------------------------------------- -%.png.o : %.png + @$(bin2o) + +%.mp3.o %_mp3.h : %.mp3 @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -#--------------------------------------------------------------------------------- -%.jpg.o : %.jpg + @$(bin2o) + +%.ttf.o %_ttf.h : %.ttf @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -#--------------------------------------------------------------------------------- -%.ttf.o : %.ttf - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -#--------------------------------------------------------------------------------- -%.wav.o : %.wav - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -#--------------------------------------------------------------------------------- -%.mp3.o : %.mp3 - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -#--------------------------------------------------------------------------------- -%.ogg.o : %.ogg - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -#--------------------------------------------------------------------------------- -%.tga.o : %.tga - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) + @$(bin2o) -include $(DEPENDS) -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- endif -#--------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- diff --git a/filelist.sh b/filelist.sh index 9d3867d..15addd3 100644 --- a/filelist.sh +++ b/filelist.sh @@ -3,7 +3,7 @@ # Automatic resource file list generation # Created by Dimok -outFile="./src/resources/filelist.cpp" +outFile="./src/resources/filelist.h" count_old=$(cat $outFile 2>/dev/null | tr -d '\n\n' | sed 's/[^0-9]*\([0-9]*\).*/\1/') count=0 @@ -29,18 +29,27 @@ fi if [ "$count_old" != "$count" ] || [ ! -f $outFile ] then -echo "Generating filelist.c for $count files." >&2 +echo "Generating filelist.h for $count files." >&2 cat < $outFile /**************************************************************************** - * Resource files. + * Loadiine resource files. * This file is generated automatically. * Includes $count files. * * NOTE: * Any manual modification of this file will be overwriten by the generation. - *****************************************************************************/ -#include -#include + ****************************************************************************/ +#ifndef _FILELIST_H_ +#define _FILELIST_H_ + +typedef struct _RecourceFile +{ + const char *filename; + const unsigned char *DefaultFile; + const unsigned int &DefaultFileSize; + unsigned char *CustomFile; + unsigned int CustomFileSize; +} RecourceFile; EOF @@ -48,12 +57,12 @@ for i in ${files[@]} do filename=${i%.*} extension=${i##*.} - echo 'extern const uint8_t '$filename'_'$extension'[];' >> $outFile - echo 'extern const uint32_t '$filename'_'$extension'_size;' >> $outFile + echo 'extern const unsigned char '$filename'_'$extension'[];' >> $outFile + echo 'extern const unsigned int '$filename'_'$extension'_size;' >> $outFile echo '' >> $outFile done -echo 'static ResourceFile ResourceList[] =' >> $outFile +echo 'static RecourceFile RecourceList[] =' >> $outFile echo '{' >> $outFile for i in ${files[@]} @@ -65,7 +74,8 @@ done echo -e '\t{NULL, NULL, 0, NULL, 0}' >> $outFile echo '};' >> $outFile + echo '' >> $outFile -echo 'ResourceFile * getResourceList(){ return ResourceList; }' >> $outFile -echo '' >> $outFile +echo '#endif' >> $outFile + fi diff --git a/installupdateportlibs.sh b/installupdateportlibs.sh deleted file mode 100644 index 6f6d891..0000000 --- a/installupdateportlibs.sh +++ /dev/null @@ -1,19 +0,0 @@ -#! /bin/bash -# -7z x -y ./libs/portlibs.zip -o${DEVKITPRO} -mkdir portlib_repos -cd portlib_repos -((git clone https://github.com/Maschell/dynamic_libs.git -b lib && (7z x -y ./dynamic_libs/libs/portlibs.zip -o${DEVKITPRO})) || (cd dynamic_libs && git pull)) -(git clone https://github.com/dimok789/libiosuhax.git || (cd libiosuhax && git pull)) -(git clone https://github.com/Maschell/libfat.git || (cd libfat && git pull)) -(git clone https://github.com/Maschell/libutils.git || (cd libutils && git pull)) -((git clone https://github.com/Maschell/libgui.git && (7z x -y ./libgui/libs/portlibs.zip -o${DEVKITPRO})) || (cd libgui && git pull)) -(git clone https://github.com/Maschell/fs_wrapper.git || (cd fs_wrapper && git pull)) -(git clone https://github.com/Maschell/controller_patcher.git || (cd controller_patcher && git pull)) -(cd dynamic_libs && ((make -j8 | grep -c "built ... ") && make install && echo "installed" ) || (echo "no need for make install" && make)) -(cd libiosuhax && make -j8 && make install) -(cd libfat && make wiiu-release && make wiiu-install) -(cd libutils && ((make -j8 | grep -c "built ... ") && make install && echo "installed" ) || (echo "no need for make install" && make)) -(cd libgui && ((make -j8 | grep -c "built ... ") && make install) || echo "no need for make install") -(cd fs_wrapper && ((make -j8 | grep -c "built ... ") && make install && echo "installed" ) || (echo "no need for make install" && make)) -(cd controller_patcher && ((make -j8 | grep -c "built ... ") && make install && echo "installed" ) || (echo "no need for make install" && make)) diff --git a/libs/portlibs.zip b/libs/portlibs.zip deleted file mode 100644 index d2a9905..0000000 Binary files a/libs/portlibs.zip and /dev/null differ diff --git a/src/Application.cpp b/src/Application.cpp index da15b99..96a989d 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -17,41 +17,46 @@ ****************************************************************************/ #include "Application.h" #include "common/common.h" -#include +#include +#include +#include +#include #include #include #include +#include "system/memory.h" #include "resources/Resources.h" -#include +#include #include #include "settings/CSettings.h" -#include "myutils/TcpReceiver.h" -#include "mymemory/memory_mapping.h" +#include "utils/TcpReceiver.h" Application *Application::applicationInstance = NULL; bool Application::exitApplication = false; +bool Application::quitRequest = false; Application::Application() : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000) , bgMusic(NULL) , video(NULL) , mainWindow(NULL) - , exitCode(EXIT_RELAUNCH_ON_LOAD) { + , fontSystem(NULL) + , exitCode(0) { controller[0] = new VPadController(GuiTrigger::CHANNEL_1); controller[1] = new WPadController(GuiTrigger::CHANNEL_2); controller[2] = new WPadController(GuiTrigger::CHANNEL_3); controller[3] = new WPadController(GuiTrigger::CHANNEL_4); controller[4] = new WPadController(GuiTrigger::CHANNEL_5); - CSettings::instance()->Load(); - //! create bgMusic bgMusic = new GuiSound(Resources::GetFile("bgMusic.mp3"), Resources::GetFileSize("bgMusic.mp3")); - - //! load language - loadLanguageFromConfig(); + bgMusic->SetLoop(true); + bgMusic->Play(); + bgMusic->SetVolume(50); exitApplication = false; + + ProcUIInit(OSSavesDone_ReadyToRelease); } Application::~Application() { @@ -70,7 +75,7 @@ Application::~Application() { AsyncDeleter::triggerDeleteProcess(); while(!AsyncDeleter::realListEmpty()) { DEBUG_FUNCTION_LINE("Waiting...\n"); - os_usleep(1000); + OSSleepTicks(OSMicrosecondsToTicks(1000)); } } while(!AsyncDeleter::deleteListEmpty()); AsyncDeleter::destroyInstance(); @@ -80,6 +85,8 @@ Application::~Application() { DEBUG_FUNCTION_LINE("Stop sound handler\n"); SoundHandler::DestroyInstance(); + + ProcUIShutdown(); } int32_t Application::exec() { @@ -91,15 +98,12 @@ int32_t Application::exec() { return exitCode; } -void Application::reloadUI() { - reloadUIflag = true; -} void Application::fadeOut() { GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color) { 0, 0, 0, 255 }); - for(int32_t i = 0; i < 255; i += 10) { + for(int i = 0; i < 255; i += 10) { if(i > 255) i = 255; @@ -109,9 +113,9 @@ void Application::fadeOut() { video->prepareDrcRendering(); mainWindow->drawDrc(video); - GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_ALWAYS); + GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS); fadeOut.draw(video); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); video->drcDrawDone(); @@ -120,9 +124,9 @@ void Application::fadeOut() { mainWindow->drawTv(video); - GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_ALWAYS); + GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS); fadeOut.draw(video); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); video->tvDrawDone(); @@ -142,109 +146,151 @@ void Application::fadeOut() { video->drcEnable(false); } -void Application::executeThread(void) { - DEBUG_FUNCTION_LINE("Initialize video\n"); - video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_SINGLE); +bool Application::procUI(void) { + bool executeProcess = false; - DEBUG_FUNCTION_LINE("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); - - //! setup default Font - DEBUG_FUNCTION_LINE("Initialize main font system\n"); - FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); - GuiText::setPresetFont(fontSystem); - - reloadUIflag = true; - if(bgMusic != NULL) { - bgMusic->SetLoop(true); - bgMusic->SetVolume(50); - bgMusic->Stop(); //CHANG MEEEEEEEEEEEEEEEEEEE + switch(ProcUIProcessMessages(true)) { + case PROCUI_STATUS_EXITING: { + DEBUG_FUNCTION_LINE("PROCUI_STATUS_EXITING\n"); + exitCode = EXIT_SUCCESS; + exitApplication = true; + break; } + case PROCUI_STATUS_RELEASE_FOREGROUND: { + DEBUG_FUNCTION_LINE("PROCUI_STATUS_RELEASE_FOREGROUND\n"); + if(video != NULL) { + // we can turn of the screen but we don't need to and it will display the last image + video->tvEnable(true); + video->drcEnable(true); + DEBUG_FUNCTION_LINE("delete fontSystem\n"); + delete fontSystem; + fontSystem = NULL; - while(reloadUIflag) { - reloadUIflag = false; - exitCode = EXIT_RELAUNCH_ON_LOAD; - DEBUG_FUNCTION_LINE("Initialize the language\n"); - loadLanguageFromConfig(); - DEBUG_FUNCTION_LINE("Initialize main window\n"); - mainWindow = MainWindow::getInstance(video->getTvWidth(), video->getTvHeight()); + DEBUG_FUNCTION_LINE("delete video\n"); + delete video; + video = NULL; - exitApplication = false; - //! main GX2 loop (60 Hz cycle with max priority on core 1) - - DEBUG_FUNCTION_LINE("Starting TcpReceiver\n"); - TcpReceiver pluginReceiver(4299); - DEBUG_FUNCTION_LINE("Entering main loop\n"); - while(!exitApplication && !reloadUIflag) { - //! Read out inputs - for(int32_t i = 0; i < 5; i++) { - if(controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false) - continue; - - if(controller[i]->data.buttons_d & VPAD_BUTTON_PLUS) { - exitCode = APPLICATION_CLOSE_APPLY; - if(linkPluginsCallback != NULL) { - bool result = linkPluginsCallback(); - if(!result) { - // On linking errors return to the HBL. -#warning TODO: proper error handling when linking fails. - exitCode = APPLICATION_CLOSE_MIIMAKER; - } - } - exitApplication = true; - } - - if(controller[i]->data.buttons_d & VPAD_BUTTON_MINUS) { - exitCode = APPLICATION_CLOSE_APPLY_MEMORY; - exitApplication = true; - } - - if(controller[i]->data.buttons_d & VPAD_BUTTON_HOME) { - exitCode = APPLICATION_CLOSE_MIIMAKER; - exitApplication = true; - } - - //! update controller states - mainWindow->update(controller[i]); - } - mainWindow->process(); - - //! start rendering DRC - video->prepareDrcRendering(); - mainWindow->drawDrc(video); - video->drcDrawDone(); - - //! start rendering TV - video->prepareTvRendering(); - mainWindow->drawTv(video); - video->tvDrawDone(); - - //! enable screen after first frame render - if(video->getFrameCount() == 0) { - video->tvEnable(true); - video->drcEnable(true); - } - - - //! as last point update the effects as it can drop elements - mainWindow->updateEffects(); - - video->waitForVSync(); - - //! transfer elements to real delete list here after all processes are finished - //! the elements are transfered to another list to delete the elements in a separate thread - //! and avoid blocking the GUI thread - AsyncDeleter::triggerDeleteProcess(); + DEBUG_FUNCTION_LINE("deinitialze memory\n"); + memoryRelease(); + ProcUIDrawDoneRelease(); + } else { + ProcUIDrawDoneRelease(); } - DEBUG_FUNCTION_LINE("Fading out\n"); - fadeOut(); - DEBUG_FUNCTION_LINE("Destroying the MainWindow\n"); - MainWindow::destroyInstance(); + break; } - DEBUG_FUNCTION_LINE("Delete fontSystem\n"); + case PROCUI_STATUS_IN_FOREGROUND: { + if(!quitRequest) { + if(video == NULL) { + DEBUG_FUNCTION_LINE("PROCUI_STATUS_IN_FOREGROUND\n"); + DEBUG_FUNCTION_LINE("initialze memory\n"); + memoryInitialize(); + + DEBUG_FUNCTION_LINE("Initialize video\n"); + video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE); + DEBUG_FUNCTION_LINE("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); + + //! setup default Font + DEBUG_FUNCTION_LINE("Initialize main font system\n"); + FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); + GuiText::setPresetFont(fontSystem); + + if(mainWindow == NULL) { + DEBUG_FUNCTION_LINE("Initialize main window\n"); + Application::loadLanguageFromConfig(); + mainWindow = MainWindow::getInstance(video->getTvWidth(), video->getTvHeight()); + } + + } + executeProcess = true; + } + break; + } + case PROCUI_STATUS_IN_BACKGROUND: + default: + break; + } + + return executeProcess; +} + +void Application::executeThread(void) { + DEBUG_FUNCTION_LINE("Entering main loop\n"); + + //! main GX2 loop (60 Hz cycle with max priority on core 1) + while(!exitApplication) { + if(procUI() == false) + continue; + + //! Read out inputs + for(int i = 0; i < 5; i++) { + if(controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false) + continue; + + if(controller[i]->data.buttons_d & VPAD_BUTTON_PLUS) { + if(linkPluginsCallback != NULL) { + bool result = linkPluginsCallback(); + if(!result) { + // On linking errors return to the HBL. +#warning TODO: proper error handling when linking fails. + } + } + SYSLaunchMenu(); + //quit(0); + } + + //! update controller states + mainWindow->update(controller[i]); + } + + mainWindow->process(); + + //! start rendering DRC + video->prepareDrcRendering(); + mainWindow->drawDrc(video); + video->drcDrawDone(); + + //! start rendering TV + video->prepareTvRendering(); + mainWindow->drawTv(video); + video->tvDrawDone(); + + //! enable screen after first frame render + if(video->getFrameCount() == 0) { + video->tvEnable(true); + video->drcEnable(true); + } + + //! as last point update the effects as it can drop elements + mainWindow->updateEffects(); + + video->waitForVSync(); + + //! transfer elements to real delete list here after all processes are finished + //! the elements are transfered to another list to delete the elements in a separate thread + //! and avoid blocking the GUI thread + AsyncDeleter::triggerDeleteProcess(); + } + + //! in case we exit to a homebrew let's smoothly fade out + if(video) { + fadeOut(); + } + + DEBUG_FUNCTION_LINE("delete mainWindow\n"); + MainWindow::destroyInstance(); + mainWindow = NULL; + + DEBUG_FUNCTION_LINE("delete fontSystem\n"); delete fontSystem; - DEBUG_FUNCTION_LINE("Delete video\n"); + fontSystem = NULL; + + DEBUG_FUNCTION_LINE("delete video\n"); delete video; + video = NULL; + + DEBUG_FUNCTION_LINE("deinitialze memory\n"); + memoryRelease(); } void Application::loadLanguageFromConfig() { diff --git a/src/Application.h b/src/Application.h index 0d5f33d..0a731d7 100644 --- a/src/Application.h +++ b/src/Application.h @@ -20,8 +20,9 @@ #include "menu/MainWindow.h" #include -#include