diff --git a/.gitignore b/.gitignore index 558529a..317fad8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ release/ debug/ -lib/ \ No newline at end of file +lib/ +*.xz \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8b0c549 --- /dev/null +++ b/Makefile @@ -0,0 +1,205 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") +endif + +include $(DEVKITARM)/3ds_rules + +export renderd7_MAJOR := 0 +export renderd7_MINOR := 8 +export renderd7_PATCH := 0 + +VERSION := $(renderd7_MAJOR).$(renderd7_MINOR).$(renderd7_PATCH) + +# If on a tagged commit, use the tag instead of the commit +ifneq ($(shell echo $(shell git tag -l --points-at HEAD) | head -c 1),) +GIT_VER := $(shell git tag -l --points-at HEAD) +else +GIT_VER := $(shell git rev-parse --short HEAD) +endif + +TIME_TIME := $(shell date --iso=seconds) + + +#--------------------------------------------------------------------------------- +# 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 +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +#--------------------------------------------------------------------------------- +TARGET := renderd7 +SOURCES := source external/source external/libnsbmp/source +DATA := data +INCLUDES := include + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft + +CFLAGS := -g -Wall -Werror -mword-relocations -save-temps\ + -DV_STRING=\"$(GIT_VER)\" \ + -DV_TIME=\"$(TIME_TIME)\" \ + -ffunction-sections -fdata-sections \ + $(ARCH) $(BUILD_CFLAGS) + +CFLAGS += $(INCLUDE) -D__3DS__ -D_GNU_SOURCE=1 + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++20 + +ASFLAGS := -g $(ARCH) $(DEFINES) + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(CTRULIB) + +#--------------------------------------------------------------------------------- +# 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 VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) +SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) +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_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \ + $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) + +export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) + +export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I. + +.PHONY: clean all doc + +#--------------------------------------------------------------------------------- +all: lib/librenderd7.a lib/librenderd7d.a + +doc: + @doxygen Doxyfile + +dist-bin: all + @tar --exclude=*~ -cjf $(TARGET)-$(VERSION).tar.bz2 include lib + +dist-src: + @tar --exclude=*~ -cjf $(TARGET)-src-$(VERSION).tar.bz2 include source Makefile + +dist: dist-src dist-bin + +install: dist-bin + mkdir -p $(DEPSDIR)$(DEVKITPRO)/libctru + bzip2 -cd $(TARGET)-$(VERSION).tar.bz2 | tar -xf - -C $(DEPSDIR)$(DEVKITPRO)/libctru + +lib: + @[ -d $@ ] || mkdir -p $@ + +release: + @[ -d $@ ] || mkdir -p $@ + +debug: + @[ -d $@ ] || mkdir -p $@ + + +lib/librenderd7.a : lib release $(SOURCES) $(INCLUDES) + @$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \ + BUILD_CFLAGS="-DNDEBUG=1 -O2 -fomit-frame-pointer" \ + DEPSDIR=$(CURDIR)/release \ + --no-print-directory -C release \ + -f $(CURDIR)/Makefile + +lib/librenderd7d.a : lib debug $(SOURCES) $(INCLUDES) + @$(MAKE) BUILD=debug OUTPUT=$(CURDIR)/$@ \ + BUILD_CFLAGS="-DDEBUG=1 -Og" \ + DEPSDIR=$(CURDIR)/debug \ + --no-print-directory -C debug \ + -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr release debug lib includes + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT) : $(OFILES) + +$(OFILES_SOURCES) : $(HFILES) + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +#--------------------------------------------------------------------------------- +# rules for assembling GPU shaders +#--------------------------------------------------------------------------------- +define shader-as + $(eval CURBIN := $*.shbin) + $(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d) + echo "$(CURBIN).o: $< $1" > $(DEPSFILE) + echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h + echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h + echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h + picasso -o $(CURBIN) $1 + bin2s $(CURBIN) | $(AS) -o $*.shbin.o +endef + +%.shbin.o %_shbin.h : %.v.pica %.g.pica + @echo $(notdir $^) + @$(call shader-as,$^) + +%.shbin.o %_shbin.h : %.v.pica + @echo $(notdir $<) + @$(call shader-as,$<) + +%.shbin.o %_shbin.h : %.shlist + @echo $(notdir $<) + @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file))) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/README.md b/README.md index e35767e..6cc7085 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ +# RenderD7 +RenderD7 is now LibRenderD7. +### Installation (Ubuntu) +first run this +`sudo su` +then this +``` +git clone https://github.com/NPI-D7/RenderD7.git +cd RenderD7 +export DEVKITARM=/opt/devkitpro/devkitARM/ +export DEVKITPRO=/opt/devkitpro/ +make install +``` +Make sure that `-lrenderd7` is before `-lcitro2d`, `-lcitro3d`, `-lctru`. + # RenderD7 (https://npi-d7.github.io/RenderD7/) Simple and Easey to use UI and Graphics helper. Create DOCS diff --git a/external/libnsbmp/libnsbmp.c b/external/libnsbmp/source/libnsbmp.c similarity index 99% rename from external/libnsbmp/libnsbmp.c rename to external/libnsbmp/source/libnsbmp.c index 378a20f..ab286c0 100644 --- a/external/libnsbmp/libnsbmp.c +++ b/external/libnsbmp/source/libnsbmp.c @@ -30,9 +30,9 @@ #include #include -#include +#include -#include "log.h" +#include /* squashes unused variable compiler warnings */ #define UNUSED(x) ((x)=(x)) diff --git a/external/fs.c b/external/source/fs.c similarity index 98% rename from external/fs.c rename to external/source/fs.c index f93b4bb..9f153df 100644 --- a/external/fs.c +++ b/external/source/fs.c @@ -1,4 +1,4 @@ -#include "external/fs.h" +#include #include #include @@ -185,7 +185,7 @@ u64 FS_GetTotalStorage(FS_SystemMediaType media_type) { } u64 FS_GetUsedStorage(FS_SystemMediaType media_type) { - return (FS_GetTotalStorage(media_type) - FS_GetUsedStorage(media_type)); + return 0;//(FS_GetTotalStorage(media_type) - FS_GetUsedStorage(media_type)); } Result FS_RemoveFile(FS_Archive archive, const char *path) { diff --git a/external/lodepng.cpp b/external/source/lodepng.cpp similarity index 99% rename from external/lodepng.cpp rename to external/source/lodepng.cpp index 51492b8..30bece2 100644 --- a/external/lodepng.cpp +++ b/external/source/lodepng.cpp @@ -28,7 +28,7 @@ The manual and changelog are in the header file "lodepng.h" Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for C. */ -#include "lodepng.h" +#include #ifdef LODEPNG_COMPILE_DISK #include /* LONG_MAX */ diff --git a/include/rd7.hpp b/include/rd7.hpp new file mode 100644 index 0000000..621d163 --- /dev/null +++ b/include/rd7.hpp @@ -0,0 +1,4 @@ +#pragma once + +#include +#include \ No newline at end of file diff --git a/internal/Clock.hpp b/include/renderd7/Clock.hpp similarity index 88% rename from internal/Clock.hpp rename to include/renderd7/Clock.hpp index 2deaa30..3811ddd 100644 --- a/internal/Clock.hpp +++ b/include/renderd7/Clock.hpp @@ -1,5 +1,5 @@ -#include - +#pragma once +#include namespace rnd7 { class Clock { diff --git a/internal/Time.hpp b/include/renderd7/Time.hpp similarity index 100% rename from internal/Time.hpp rename to include/renderd7/Time.hpp diff --git a/bmp.hpp b/include/renderd7/bmp.hpp similarity index 85% rename from bmp.hpp rename to include/renderd7/bmp.hpp index 82d8674..66dcde5 100644 --- a/bmp.hpp +++ b/include/renderd7/bmp.hpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include using namespace std; #pragma pack(push, 1) @@ -52,13 +54,13 @@ struct BMP { read(fname); } - void read(const char *fname) { + int read(const char *fname) { std::ifstream inp{ fname, std::ios_base::binary }; if (inp) { inp.read((char*)&file_header, sizeof(file_header)); if(file_header.file_type != 0x4D42) { - return;//throw std::runtime_error("Error! Unrecognized file format."); + return 50;//throw std::runtime_error("Error! Unrecognized file format."); } inp.read((char*)&bmp_info_header, sizeof(bmp_info_header)); @@ -71,7 +73,7 @@ struct BMP { check_color_header(bmp_color_header); } else { //std::cerr << "Error! The file \"" << fname << "\" does not seem to contain bit mask information\n"; - return;//throw std::runtime_error("Error! Unrecognized file format."); + return 51;//throw std::runtime_error("Error! Unrecognized file format."); } } @@ -90,7 +92,7 @@ struct BMP { file_header.file_size = file_header.offset_data; if (bmp_info_header.height < 0) { - return;//throw std::runtime_error("The program can treat only BMP images with the origin in the bottom left corner!"); + return 52;//throw std::runtime_error("The program can treat only BMP images with the origin in the bottom left corner!"); } data.resize(bmp_info_header.width * bmp_info_header.height * bmp_info_header.bit_count / 8); @@ -113,13 +115,82 @@ struct BMP { } } else { - return;//throw std::runtime_error("Unable to open the input image file "+std::string(fname)); + return 53;//throw std::runtime_error("Unable to open the input image file "+std::string(fname)); } + return 0; + } + + int read_mem(std::vector buffer) { + std::stringstream inp; + std::copy(buffer.begin(), buffer.end(),std::ostream_iterator(inp,"\n")); + if (inp) { + inp.read((char*)&file_header, sizeof(file_header)); + if(file_header.file_type != 0x4D42) { + + return 50;//throw std::runtime_error("Error! Unrecognized file format."); + } + inp.read((char*)&bmp_info_header, sizeof(bmp_info_header)); + + // The BMPColorHeader is used only for transparent images + if(bmp_info_header.bit_count == 32) { + // Check if the file has bit mask color information + if(bmp_info_header.size >= (sizeof(BMPInfoHeader) + sizeof(BMPColorHeader))) { + inp.read((char*)&bmp_color_header, sizeof(bmp_color_header)); + // Check if the pixel data is stored as BGRA and if the color space type is sRGB + check_color_header(bmp_color_header); + } else { + //std::cerr << "Error! The file \"" << fname << "\" does not seem to contain bit mask information\n"; + return 51;//throw std::runtime_error("Error! Unrecognized file format."); + } + } + + // Jump to the pixel data location + inp.seekg(file_header.offset_data, inp.beg); + + // Adjust the header fields for output. + // Some editors will put extra info in the image file, we only save the headers and the data. + if(bmp_info_header.bit_count == 32) { + bmp_info_header.size = sizeof(BMPInfoHeader) + sizeof(BMPColorHeader); + file_header.offset_data = sizeof(BMPFileHeader) + sizeof(BMPInfoHeader) + sizeof(BMPColorHeader); + } else { + bmp_info_header.size = sizeof(BMPInfoHeader); + file_header.offset_data = sizeof(BMPFileHeader) + sizeof(BMPInfoHeader); + } + file_header.file_size = file_header.offset_data; + + if (bmp_info_header.height < 0) { + return 52;//throw std::runtime_error("The program can treat only BMP images with the origin in the bottom left corner!"); + } + + data.resize(bmp_info_header.width * bmp_info_header.height * bmp_info_header.bit_count / 8); + + // Here we check if we need to take into account row padding + if (bmp_info_header.width % 4 == 0) { + inp.read((char*)data.data(), data.size()); + file_header.file_size += static_cast(data.size()); + } + else { + row_stride = bmp_info_header.width * bmp_info_header.bit_count / 8; + uint32_t new_stride = make_stride_aligned(4); + std::vector padding_row(new_stride - row_stride); + + for (int y = 0; y < bmp_info_header.height; ++y) { + inp.read((char*)(data.data() + row_stride * y), row_stride); + inp.read((char*)padding_row.data(), padding_row.size()); + } + file_header.file_size += static_cast(data.size()) + bmp_info_header.height * static_cast(padding_row.size()); + } + } + else { + return 53;//throw std::runtime_error("Unable to open the input image file "+std::string(fname)); + } + return 0; } BMP(int32_t width, int32_t height, bool has_alpha = true) { if (width <= 0 || height <= 0) { - return;//throw std::runtime_error("The image width and height must be positive numbers."); + width = 1; + height = 1; } bmp_info_header.width = width; @@ -148,7 +219,7 @@ struct BMP { } } - void write(const char *fname) { + unsigned write(const char *fname) { std::ofstream of{ fname, std::ios_base::binary }; if (of) { if (bmp_info_header.bit_count == 32) { @@ -171,12 +242,13 @@ struct BMP { } } else { - return;//throw std::runtime_error("The program can treat only 24 or 32 bits per pixel BMP files"); + return 54;//throw std::runtime_error("The program can treat only 24 or 32 bits per pixel BMP files"); } } else { - return;//throw std::runtime_error("Unable to open the output image file."); + return 55;//throw std::runtime_error("Unable to open the output image file."); } + return 0; } @@ -215,9 +287,9 @@ struct BMP { } - void fill_region(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint8_t B, uint8_t G, uint8_t R, uint8_t A) { + unsigned fill_region(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint8_t B, uint8_t G, uint8_t R, uint8_t A) { if (x0 + w > (uint32_t)bmp_info_header.width || y0 + h > (uint32_t)bmp_info_header.height) { - return;//throw std::runtime_error("The region does not fit in the image!"); + return 59; } uint32_t channels = bmp_info_header.bit_count / 8; @@ -231,6 +303,7 @@ struct BMP { } } } + return 0; } void fill_region_df(uint32_t x1, uint32_t y1, uint32_t w, uint32_t h, uint8_t B, uint8_t G, uint8_t R, uint8_t A) { @@ -536,9 +609,9 @@ struct BMP { return intensity; } - void set_pixel(uint32_t x0, uint32_t y0, uint8_t B, uint8_t G, uint8_t R, uint8_t A) { + unsigned set_pixel(uint32_t x0, uint32_t y0, uint8_t B, uint8_t G, uint8_t R, uint8_t A) { if (x0 >= (uint32_t)bmp_info_header.width || y0 >= (uint32_t)bmp_info_header.height || x0 < 0 || y0 < 0) { - return;//throw std::runtime_error("The point is outside the image boundaries!"); + return 59;//throw std::runtime_error("The point is outside the image boundaries!"); } uint32_t channels = bmp_info_header.bit_count / 8; data[channels * (y0 * bmp_info_header.width + x0) + 0] = B; @@ -547,6 +620,7 @@ struct BMP { if (channels == 4) { data[channels * (y0 * bmp_info_header.width + x0) + 3] = A; } + return 0; } void set_pixel_df(uint32_t x0, uint32_t y0, uint8_t B, uint8_t G, uint8_t R, uint8_t A) { @@ -564,16 +638,17 @@ struct BMP { } } - void draw_rectangle(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, + unsigned draw_rectangle(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint8_t B, uint8_t G, uint8_t R, uint8_t A, uint8_t line_w) { if (x0 + w > (uint32_t)bmp_info_header.width || y0 + h > (uint32_t)bmp_info_header.height) { - return;//throw std::runtime_error("The rectangle does not fit in the image!"); + return 59;//throw std::runtime_error("The rectangle does not fit in the image!"); } fill_region(x0, y0, w, line_w, B, G, R, A); // top line fill_region(x0, (y0 + h - line_w), w, line_w, B, G, R, A); // bottom line fill_region((x0 + w - line_w), (y0 + line_w), line_w, (h - (2 * line_w)), B, G, R, A); // right line fill_region(x0, (y0 + line_w), line_w, (h - (2 * line_w)), B, G, R, A); // left line + return 0; } void draw_rectangle_df(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, diff --git a/include/renderd7/bmpconverter.hpp b/include/renderd7/bmpconverter.hpp new file mode 100644 index 0000000..d549035 --- /dev/null +++ b/include/renderd7/bmpconverter.hpp @@ -0,0 +1,14 @@ +#pragma once +#include + +#include + +namespace BitmapConverter{ +//returns 0 if all went ok, non-0 if error +//output image is always given in RGBA (with alpha channel), even if it's a BMP without alpha channel +unsigned decodeBMP(std::vector& image, unsigned& w, unsigned& h, const std::vector& bmp); + +std::vector ConvertFile(std::string filename); + +std::vector ConvertData(std::vector data); +} \ No newline at end of file diff --git a/external/fs.h b/include/renderd7/external/fs.h similarity index 96% rename from external/fs.h rename to include/renderd7/external/fs.h index 1e1a574..517d43c 100644 --- a/external/fs.h +++ b/include/renderd7/external/fs.h @@ -1,5 +1,4 @@ -#ifndef _3D_SHELL_FS_H -#define _3D_SHELL_FS_H + #include <3ds.h> @@ -28,5 +27,3 @@ Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size) char *FS_GetFileTimestamp(const char *path); Result makeDirs(const char * path); Result openFile(Handle* fileHandle, const char * path, bool write); - -#endif \ No newline at end of file diff --git a/external/json.hpp b/include/renderd7/external/json.hpp similarity index 100% rename from external/json.hpp rename to include/renderd7/external/json.hpp diff --git a/external/libnsbmp/libnsbmp.h b/include/renderd7/external/libnsbmp/libnsbmp.h similarity index 100% rename from external/libnsbmp/libnsbmp.h rename to include/renderd7/external/libnsbmp/libnsbmp.h diff --git a/external/libnsbmp/log.h b/include/renderd7/external/libnsbmp/log.h similarity index 100% rename from external/libnsbmp/log.h rename to include/renderd7/external/libnsbmp/log.h diff --git a/external/lodepng.h b/include/renderd7/external/lodepng.h similarity index 100% rename from external/lodepng.h rename to include/renderd7/external/lodepng.h diff --git a/external/stb_image.h b/include/renderd7/external/stb_image.h similarity index 100% rename from external/stb_image.h rename to include/renderd7/external/stb_image.h diff --git a/external/stb_image_write.h b/include/renderd7/external/stb_image_write.h similarity index 100% rename from external/stb_image_write.h rename to include/renderd7/external/stb_image_write.h diff --git a/internal/ini.hpp b/include/renderd7/ini.hpp similarity index 100% rename from internal/ini.hpp rename to include/renderd7/ini.hpp diff --git a/internal/lang.hpp b/include/renderd7/lang.hpp similarity index 92% rename from internal/lang.hpp rename to include/renderd7/lang.hpp index 25363d5..9bca5cb 100644 --- a/internal/lang.hpp +++ b/include/renderd7/lang.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include "json.hpp" +#include /// RenderD7::Lang namespace RenderD7::Lang diff --git a/log.hpp b/include/renderd7/log.hpp similarity index 100% rename from log.hpp rename to include/renderd7/log.hpp diff --git a/internal/parameter.hpp b/include/renderd7/parameter.hpp similarity index 100% rename from internal/parameter.hpp rename to include/renderd7/parameter.hpp diff --git a/renderd7.hpp b/include/renderd7/renderd7.hpp similarity index 83% rename from renderd7.hpp rename to include/renderd7/renderd7.hpp index e3db6c9..83ba7b9 100644 --- a/renderd7.hpp +++ b/include/renderd7/renderd7.hpp @@ -18,25 +18,27 @@ #include #include #include -#include "external/lodepng.h" #include #include -#include "lang.hpp" -#include "parameter.hpp" -#include "thread.hpp" -#include "ini.hpp" -#include "stringtool.hpp" -#include "Clock.hpp" -#include "bmp.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include extern "C" { - #include "external/fs.h" + #include } -#define RENDERD7VSTRING "0.7.3" -#define CHANGELOG "0.7.3: Implement Over Render Overlay Framework\n0.7.2: Implement MT to csv file saving. Add RGB2HEX. \n0.7.1: Add the New Overlay Handler. Its Just in code and does nothing yet. \n0.7.0: Made Big Progress In the MT Ovl but it still crashes On a Scnd C3D_FrameEnd(). Implement 800px but doesn't work that good. \n0.6.2: Fix Crash when exiting trouth Home Menu. \n0.6.10: rewrite Threadsystem, Improve framerate\n0.6.02: Fix Code in lang.hpp\nadd Draw Text Left Function.\nadd changelog\n0.6.01: add Threading system." +#define RENDERD7VSTRING "0.8.0" +#define CHANGELOG "0.8.0: Implement BitmapPrinter\n0.7.3: Implement Over Render Overlay Framework\n0.7.2: Implement MT to csv file saving. Add RGB2HEX. \n0.7.1: Add the New Overlay Handler. Its Just in code and does nothing yet. \n0.7.0: Made Big Progress In the MT Ovl but it still crashes On a Scnd C3D_FrameEnd(). Implement 800px but doesn't work that good. \n0.6.2: Fix Crash when exiting trouth Home Menu. \n0.6.10: rewrite Threadsystem, Improve framerate\n0.6.02: Fix Code in lang.hpp\nadd Draw Text Left Function.\nadd changelog\n0.6.01: add Threading system." #define DEFAULT_CENTER 0.5f extern C3D_RenderTarget* Top; @@ -413,4 +415,34 @@ namespace RenderD7 void GetDirContentsExt(std::vector &dircontent, const std::vector &extensions); void GetDirContents(std::vector &dircontent); + class BitmapPrinter + { + public: + BitmapPrinter(int w, int h); + ~BitmapPrinter(); + bool DecodeFile(std::string file); + + bool DecodeMem(std::vector buffer); + void DrawPixel(int x, int y, u8 b, u8 g, u8 r, u8 a); + void DrawRect(int x, int y, int w, int h, u8 line_w, u8 b, u8 g, u8 r, u8 a); + void DrawRectFilled(int x, int y, int w, int h, u8 b, u8 g, u8 r, u8 a); + void UsePreMap(BMP map); + void UsePrePrintMap(BitmapPrinter printmap); + BMP GetBitmap(){ return bitmap; } + void SaveBmp(std::string name); + void SavePng(std::string name); + + void CreateScreen(C3D_RenderTarget *target); + void DrawScreen(int framerate); + void Clear(u8 b = 0, u8 g = 0, u8 r = 0, u8 a = 255); + void ClearBlank(); + RenderD7::Image GetImage(); + private: + int frame = 0; + RenderD7::Image renderframe; + bool isscreen = false; + C3D_RenderTarget* targetr; + BMP bitmap = NULL; + BMP blank = NULL; + }; } /// RenderD7 diff --git a/sound.hpp b/include/renderd7/sound.hpp similarity index 100% rename from sound.hpp rename to include/renderd7/sound.hpp diff --git a/internal/stringtool.hpp b/include/renderd7/stringtool.hpp similarity index 100% rename from internal/stringtool.hpp rename to include/renderd7/stringtool.hpp diff --git a/internal/thread.hpp b/include/renderd7/thread.hpp similarity index 99% rename from internal/thread.hpp rename to include/renderd7/thread.hpp index ccd5eba..195d262 100644 --- a/internal/thread.hpp +++ b/include/renderd7/thread.hpp @@ -3,7 +3,7 @@ #include #include #include -#include "parameter.hpp" +#include using CTRU_Thread = Thread; diff --git a/internal/tween.hpp b/include/renderd7/tween.hpp similarity index 92% rename from internal/tween.hpp rename to include/renderd7/tween.hpp index 688dc76..bdf6fdf 100644 --- a/internal/tween.hpp +++ b/include/renderd7/tween.hpp @@ -1,4 +1,4 @@ -#include "Clock.hpp" +#include namespace rnd7{ enum class TweenType : int {Position = 1, Color, Alpha}; diff --git a/internal/engine.hpp b/internal/engine.hpp deleted file mode 100644 index 842523c..0000000 --- a/internal/engine.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include <3ds.h> -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "lang.hpp" -#include "parameter.hpp" -#include "thread.hpp" -#include "ini.hpp" -#include "stringtool.hpp" - -enum EngineType -{ - _2D, - _3D -}; - -namespace Npi -class Game { - public: - Game(EngineType, std::string name); - ~Game(){} - private: - std::string g_name; - EngineType g_etype; -}; -} diff --git a/renderd7-0.8.0.tar.bz2 b/renderd7-0.8.0.tar.bz2 new file mode 100644 index 0000000..bbe11c2 Binary files /dev/null and b/renderd7-0.8.0.tar.bz2 differ diff --git a/internal/Clock.cpp b/source/Clock.cpp similarity index 93% rename from internal/Clock.cpp rename to source/Clock.cpp index 51fc961..7ad3604 100644 --- a/internal/Clock.cpp +++ b/source/Clock.cpp @@ -1,4 +1,4 @@ -#include "Clock.hpp" +#include namespace rnd7 { diff --git a/internal/Time.cpp b/source/Time.cpp similarity index 99% rename from internal/Time.cpp rename to source/Time.cpp index 551e479..b77b88e 100644 --- a/internal/Time.cpp +++ b/source/Time.cpp @@ -1,4 +1,4 @@ -#include "Time.hpp" +#include namespace rnd7 { diff --git a/bmpconverter.hpp b/source/bmpconverter.cpp similarity index 94% rename from bmpconverter.hpp rename to source/bmpconverter.cpp index d04a464..13e6d5f 100644 --- a/bmpconverter.hpp +++ b/source/bmpconverter.cpp @@ -1,7 +1,6 @@ -#pragma once -#include "lodepng.h" +#include -#include +namespace BitmapConverter{ //returns 0 if all went ok, non-0 if error //output image is always given in RGBA (with alpha channel), even if it's a BMP without alpha channel @@ -63,7 +62,7 @@ std::vector ConvertFile(std::string filename) { std::vector image; unsigned w, h; - unsigned error = decodeBMP(image, w, h, bmp); + unsigned error = BitmapConverter::decodeBMP(image, w, h, bmp); if(error) { std::cout << "BMP decoding error " << error << std::endl; @@ -86,7 +85,7 @@ std::vector ConvertData(std::vector data) { std::vector image; unsigned w, h; - unsigned error = decodeBMP(image, w, h, data); + unsigned error = BitmapConverter::decodeBMP(image, w, h, data); if(error) { std::cout << "BMP decoding error " << error << std::endl; @@ -104,3 +103,4 @@ std::vector ConvertData(std::vector data) { return png; } +} \ No newline at end of file diff --git a/internal/lang.cpp b/source/lang.cpp similarity index 98% rename from internal/lang.cpp rename to source/lang.cpp index 4d1ceaf..167ff65 100644 --- a/internal/lang.cpp +++ b/source/lang.cpp @@ -1,4 +1,4 @@ -#include "lang.hpp" +#include #include #include #include diff --git a/log.cpp b/source/log.cpp similarity index 93% rename from log.cpp rename to source/log.cpp index 7cf962a..9fbb0cc 100644 --- a/log.cpp +++ b/source/log.cpp @@ -1,4 +1,4 @@ -#include "log.hpp" +#include #include diff --git a/renderd7.cpp b/source/renderd7.cpp similarity index 89% rename from renderd7.cpp rename to source/renderd7.cpp index 9b1db34..8330dff 100644 --- a/renderd7.cpp +++ b/source/renderd7.cpp @@ -1,10 +1,10 @@ -#include "renderd7.hpp" -#include "log.hpp" +#include +#include #include #define RGBA8(r, g, b, a) ((((r) & 0xFF) << 0) | (((g) & 0xFF) << 8) | (((b) & 0xFF) << 16) | (((a) & 0xFF) << 24)) #define D7_NOTHING C2D_Color32(0, 0, 0, 0) -#define CFGVER "2" +#define CFGVER "3" Log renderd7log; float animtime; bool isndspinit = false; @@ -698,6 +698,7 @@ Result RenderD7::Init::Main(std::string app_name) cfgstruct["settings"]["forcetimeoutLB"] = "1"; cfgstruct["settings"]["forceFrameRate"] = "60"; cfgstruct["settings"]["super-reselution"] = "0"; + cfgstruct["settings"]["renderer"] = "c3d_c2d"; cfgstruct["metrik-settings"]["enableoverlay"] = "0"; cfgstruct["metrik-settings"]["Screen"] = "0"; cfgstruct["metrik-settings"]["txtColor"] = "#ffffff"; @@ -1284,6 +1285,8 @@ void RenderD7::RSettings::Draw(void) const std::string rd7ver = RENDERD7VSTRING; std::string rd7cfgver = CFGVER; std::string citras = is_citra ? "true" : "false"; + std::string buildtime = V_TIME; + std::string commit = V_STRING; RenderD7::OnScreen(Top); RenderD7::DrawRect(0, 0, 400, 21, RenderD7::Color::Hex("#111111")); RenderD7::DrawRect(0, 21, 400, 220, RenderD7::Color::Hex("#eeeeee")); @@ -1293,7 +1296,8 @@ void RenderD7::RSettings::Draw(void) const RenderD7::DrawText(0, 50, 0.7f, DSEVENBLACK, "RenderD7: " + rd7ver); RenderD7::DrawText(0, 70, 0.7f, DSEVENBLACK, "Config-Version: " + rd7cfgver); RenderD7::DrawText(0, 90, 0.7f, DSEVENBLACK, "Citra: " + citras); - RenderD7::DrawText(0, 110, 0.7f, DSEVENBLACK, "C2D_MAX_OBJ: " + std::to_string(maxobj__)); + RenderD7::DrawText(0, 110, 0.7f, DSEVENBLACK, "RenderD7-Build-Time: \n" + buildtime); + RenderD7::DrawText(0, 150, 0.7f, DSEVENBLACK, "RenderD7-Commit: " + commit); /*RenderD7::DrawText(0, 130, 0.7f, DSEVENBLACK, "Metrik Text RGB: " + mttxtcolstate); RenderD7::DrawText(0, 150, 0.7f, DSEVENBLACK, "Metrik Alpha: " + mtcola); RenderD7::DrawText(0, 170, 0.7f, DSEVENBLACK, "Metrik Text Alpha: " + mttxtcola);*/ @@ -1469,7 +1473,7 @@ std::string RenderD7::GetTimeStr(void) } extern "C" { - #include "libnsbmp.h" + #include } static const u32 BYTES_PER_PIXEL = 4; #define MAX_IMAGE_BYTES (48 * 1024 * 1024) @@ -1530,9 +1534,10 @@ unsigned Image_to_C3D(C2D_Image img, const std::vector& bmpc) { return 3; } } - C2D_Image* texture; + C2D_Image* texture = new C2D_Image(); bool ret = C3DTexToC2DImage(texture, static_cast(bmp.width), static_cast(bmp.height), static_cast(bmp.bitmap)); bmp_finalise(&bmp); + delete texture; if (!ret) { return 4; @@ -1575,4 +1580,151 @@ void RenderD7::Toast::Logic() msgposy++/*=(int)RenderD7::GetDeltaTime*/; if(msgposy > 400) this->Kill(); } +} + +RenderD7::BitmapPrinter::BitmapPrinter(int w, int h) +{ + bitmap = BMP(w, h, true); + renderframe.LoadPFromBuffer(BitmapConverter::ConvertData(bitmap.DATA())); + blank = BMP(w, h, true); +} + +RenderD7::BitmapPrinter::~BitmapPrinter() +{ + +} + +bool RenderD7::BitmapPrinter::DecodeFile(std::string file) +{ + unsigned error = bitmap.read(file.c_str()); + + if (error) + { + RenderD7::AddOvl(std::make_unique("BitmapPrinter", "Error Code: " + std::to_string(error))); + return false; + } + + return true; +} +bool RenderD7::BitmapPrinter::DecodeMem(std::vector buffer) +{ + unsigned error = bitmap.read_mem(buffer); + if (error) + { + RenderD7::AddOvl(std::make_unique("BitmapPrinter", "Error Code: " + std::to_string(error))); + return false; + } + return true; +} + +void RenderD7::BitmapPrinter::DrawPixel(int x, int y, u8 b, u8 g, u8 r, u8 a) +{ + unsigned error = bitmap.set_pixel(x, bitmap.bmp_info_header.height - y, b, g, r, a); + if (error) + { + RenderD7::AddOvl(std::make_unique("BitmapPrinter->Pixel", "Error Code: " + std::to_string(error))); + } +} +void RenderD7::BitmapPrinter::DrawRect(int x, int y, int w, int h, u8 line_w, u8 b, u8 g, u8 r, u8 a) +{ + unsigned error = bitmap.draw_rectangle(x, bitmap.bmp_info_header.height - w - y, w, h, b, g, r, a, line_w); + if (error) + { + RenderD7::AddOvl(std::make_unique("BitmapPrinter->Rect", "Error Code: " + std::to_string(error))); + } +} + +void RenderD7::BitmapPrinter::DrawRectFilled(int x, int y, int w, int h, u8 b, u8 g, u8 r, u8 a) +{ + unsigned error = bitmap.fill_region(x, bitmap.bmp_info_header.height - w - y, w, h, b, g, r, a); + if (error) + { + RenderD7::AddOvl(std::make_unique("BitmapPrinter->RectF", "Error Code: " + std::to_string(error))); + } +} + +void RenderD7::BitmapPrinter::SaveBmp(std::string name) +{ + if(!RenderD7::NameIsEndingWith(name, {"bmp"})) + { + name += ".bmp"; + } + bitmap.write(name.c_str()); +} +void RenderD7::BitmapPrinter::SavePng(std::string name) +{ + if(!RenderD7::NameIsEndingWith(name, {"png"})) + { + name += ".png"; + } + std::vector ImageBuffer; + ImageBuffer = BitmapConverter::ConvertData(bitmap.DATA()); + lodepng::save_file(ImageBuffer, name); +} + +void RenderD7::BitmapPrinter::CreateScreen(C3D_RenderTarget *target) +{ + isscreen = true; + targetr = target; + if (target == Top) + { + bitmap = BMP(400, 240, true); + blank = BMP(400, 240, true); + } + if (target == TopRight) + { + bitmap = BMP(400, 240, true); + blank = BMP(400, 240, true); + } + if (target == Bottom) + { + bitmap = BMP(320, 240, true); + blank = BMP(320, 240, true); + } + renderframe.LoadPFromBuffer(BitmapConverter::ConvertData(bitmap.DATA())); + +} +void RenderD7::BitmapPrinter::DrawScreen(int framerate) +{ + if (isscreen) + { + if(frame == (60/framerate)){ + RenderD7::OnScreen(targetr); + RenderD7::Image *img = new RenderD7::Image(); + img->Unload(); + //img->LoadFromBitmap(bitmap); + renderframe.Unload(); + renderframe.LoadFromBitmap(bitmap); + renderframe.img = img->Get(); + img->Unload(); + delete img; + } + + renderframe.Draw(0, 0); + frame++; + } +} +RenderD7::Image RenderD7::BitmapPrinter::GetImage() +{ + RenderD7::Image img; + img.LoadFromBitmap(bitmap); + return img; +} + +void RenderD7::BitmapPrinter::UsePreMap(BMP map) +{ + bitmap = map; +} +void RenderD7::BitmapPrinter::UsePrePrintMap(BitmapPrinter printmap) +{ + bitmap = printmap.GetBitmap(); +} + +void RenderD7::BitmapPrinter::Clear(u8 b, u8 g, u8 r, u8 a) +{ + bitmap.fill_region(0, 0, bitmap.bmp_info_header.width, bitmap.bmp_info_header.height, b, g, r, a); +} +void RenderD7::BitmapPrinter::ClearBlank() +{ + bitmap = blank; } \ No newline at end of file diff --git a/sound.cpp b/source/sound.cpp similarity index 95% rename from sound.cpp rename to source/sound.cpp index fef3d58..e471217 100644 --- a/sound.cpp +++ b/source/sound.cpp @@ -1,4 +1,4 @@ -#include "sound.hpp" +#include #include #include diff --git a/internal/thread.cpp b/source/thread.cpp similarity index 98% rename from internal/thread.cpp rename to source/thread.cpp index 95c500e..c6dbc56 100644 --- a/internal/thread.cpp +++ b/source/thread.cpp @@ -1,4 +1,4 @@ -#include "thread.hpp" +#include namespace RenderD7 { void Threads::Exit() {