diff --git a/.gitignore b/.gitignore index 06795a80..5de88ad9 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,15 @@ gf2d *.log makefile.dep + +# platform build folders +build_gamecube +build_switch +build_wii + +#vscode folder and executables +.vscode +*.dol +*.elf +*.nacp +*.nro \ No newline at end of file diff --git a/Makefile.ogc b/Makefile.ogc new file mode 100644 index 00000000..b9a86955 --- /dev/null +++ b/Makefile.ogc @@ -0,0 +1,151 @@ +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") +endif + +include $(DEVKITPPC)/gamecube_rules + +#--------------------------------------------------------------------------------- +# 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 := $(notdir $(CURDIR)) +BUILD := build_gamecube +SOURCES := gfc/simple_logger/src gfc/simple_json/src gfc/src src +DATA := platform/gamecube/data +INCLUDES := include gfc/include gfc/simple_logger/include gfc/simple_json/include + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- + +CFLAGS = `$(PREFIX)pkg-config --cflags sdl2 SDL2_mixer SDL2_image` -g -O2 -Wall $(MACHDEP) $(INCLUDE) -D__GAMECUBE__ -D__BIG_ENDIAN__ +CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions + +LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := -lSDL2_mixer -lSDL2_image -lSDL2main -lSDL2 \ + -lfat -lpng -ljpeg -lz -lopusfile -lopus -lmodplug -lvorbisidec -logg \ + -laesnd -logc -lm + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBOGC) + +#--------------------------------------------------------------------------------- +# 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 OUTPUT := $(CURDIR)/$(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 +#--------------------------------------------------------------------------------- +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)/*.*))) + +#--------------------------------------------------------------------------------- +# 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_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) + +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) \ + -I$(LIBOGC_INC) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.ogc + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf +$(OUTPUT).elf: $(OFILES) + +$(OFILES_SOURCES) : $(HFILES) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .jpg extension +#--------------------------------------------------------------------------------- +%.jpg.o %_jpg.h : %.jpg +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .png extension +#--------------------------------------------------------------------------------- +%.png.o %_png.h : %.png +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .json extension +#--------------------------------------------------------------------------------- +%.json.o %_json.h : %.json +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- \ No newline at end of file diff --git a/Makefile.switch b/Makefile.switch new file mode 100644 index 00000000..bdb5e564 --- /dev/null +++ b/Makefile.switch @@ -0,0 +1,217 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) +include $(DEVKITPRO)/libnx/switch_rules + +#--------------------------------------------------------------------------------- +# 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 +# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional) +# +# NO_ICON: if set to anything, do not use icon. +# NO_NACP: if set to anything, no .nacp file is generated. +# APP_TITLE is the name of the app stored in the .nacp file (Optional) +# APP_AUTHOR is the author of the app stored in the .nacp file (Optional) +# APP_VERSION is the version of the app stored in the .nacp file (Optional) +# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) +# ICON is the filename of the icon (.jpg), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .jpg +# - icon.jpg +# - /default_icon.jpg +# +# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .json +# - config.json +# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead +# of a homebrew executable (.nro). This is intended to be used for sysmodules. +# NACP building is skipped as well. +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build_switch +SOURCES := gfc/simple_logger/src gfc/simple_json/src gfc/src src +DATA := data +INCLUDES := include gfc/include gfc/simple_logger/include gfc/simple_json/include +ROMFS := platform/switch/romfs + +APP_TITLE := GF2D +APP_AUTHOR := DJ Kehoe + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE + +CFLAGS := `$(PREFIX)pkg-config --cflags sdl2 SDL2_mixer SDL2_image` -Wall -O2 -ffunction-sections \ + $(ARCH) $(DEFINES) -Iinclude + +CFLAGS += $(INCLUDE) -D__SWITCH__ + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +LIBS := `$(PREFIX)pkg-config --libs sdl2 SDL2_mixer SDL2_image SDL2_ttf` \ + -lnx + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBNX) + + +#--------------------------------------------------------------------------------- +# 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 OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +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++ and libEGL dependent projects +#--------------------------------------------------------------------------------- +export LD := $(CXX) + +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) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +ifeq ($(strip $(CONFIG_JSON)),) + jsons := $(wildcard *.json) + ifneq (,$(findstring $(TARGET).json,$(jsons))) + export APP_JSON := $(TOPDIR)/$(TARGET).json + else + ifneq (,$(findstring config.json,$(jsons))) + export APP_JSON := $(TOPDIR)/config.json + endif + endif +else + export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) +endif + +ifeq ($(strip $(ICON)),) + icons := $(wildcard *.jpg) + ifneq (,$(findstring $(TARGET).jpg,$(icons))) + export APP_ICON := $(TOPDIR)/$(TARGET).jpg + else + ifneq (,$(findstring icon.jpg,$(icons))) + export APP_ICON := $(TOPDIR)/icon.jpg + endif + endif +else + export APP_ICON := $(TOPDIR)/$(ICON) +endif + +ifeq ($(strip $(NO_ICON)),) + export NROFLAGS += --icon=$(APP_ICON) +endif + +ifeq ($(strip $(NO_NACP)),) + export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp +endif + +ifneq ($(APP_TITLEID),) + export NACPFLAGS += --titleid=$(APP_TITLEID) +endif + +ifneq ($(ROMFS),) + export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) +endif + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.switch + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... +ifeq ($(strip $(APP_JSON)),) + @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf +else + @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf +endif + + +#--------------------------------------------------------------------------------- +else +.PHONY: all + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +ifeq ($(strip $(APP_JSON)),) + +all : $(OUTPUT).nro + +ifeq ($(strip $(NO_NACP)),) +$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp +else +$(OUTPUT).nro : $(OUTPUT).elf +endif + +else + +all : $(OUTPUT).nsp + +$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm + +$(OUTPUT).nso : $(OUTPUT).elf + +endif + +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SRC) : $(HFILES_BIN) + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/Makefile.wii b/Makefile.wii new file mode 100644 index 00000000..19dddaed --- /dev/null +++ b/Makefile.wii @@ -0,0 +1,156 @@ +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") +endif + +include $(DEVKITPPC)/wii_rules + +#--------------------------------------------------------------------------------- +# 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 := $(notdir $(CURDIR)) +BUILD := build_wii +SOURCES := gfc/simple_logger/src gfc/simple_json/src gfc/src src +DATA := platform/gamecube/data +INCLUDES := include gfc/include gfc/simple_logger/include gfc/simple_json/include + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- + +CFLAGS = `$(PREFIX)pkg-config --cflags sdl2 SDL2_mixer SDL2_image` -g -O2 -Wall $(MACHDEP) $(INCLUDE) -D__WII__ -D__BIG_ENDIAN__ +CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions + +LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := -lSDL2_mixer -lSDL2_image -lSDL2main -lSDL2 \ + -lfat -lpng -ljpeg -lz -lopusfile -lopus -lmodplug -lvorbisidec -logg \ + -laesnd -logc -lm -lwiiuse -lwiikeyboard -lbte -logc -lm + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBOGC) + +#--------------------------------------------------------------------------------- +# 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 OUTPUT := $(CURDIR)/$(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 +#--------------------------------------------------------------------------------- +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)/*.*))) + +#--------------------------------------------------------------------------------- +# 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_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) + +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) \ + -I$(LIBOGC_INC) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.wii + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol + +#--------------------------------------------------------------------------------- +run: + wiiload $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf +$(OUTPUT).elf: $(OFILES) + +$(OFILES_SOURCES) : $(HFILES) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .jpg extension +#--------------------------------------------------------------------------------- +%.jpg.o %_jpg.h : %.jpg +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .png extension +#--------------------------------------------------------------------------------- +%.png.o %_png.h : %.png +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .json extension +#--------------------------------------------------------------------------------- +%.json.o %_json.h : %.json +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- \ No newline at end of file diff --git a/include/gf2d_sprite.h b/include/gf2d_sprite.h index f6c47b93..80e15b54 100644 --- a/include/gf2d_sprite.h +++ b/include/gf2d_sprite.h @@ -30,6 +30,8 @@ void gf2d_sprite_init(Uint32 max); */ Sprite *gf2d_sprite_load_image(const char *filename); +Sprite *gf2d_sprite_load_image_mem(const char *name, const uint8_t *data, size_t size); + /** * @brief draw a simple image to screen at the position provided * @param image the sprite image to draw @@ -53,6 +55,16 @@ Sprite *gf2d_sprite_load_all( Bool keepSurface ); +Sprite *gf2d_sprite_load_all_mem( + const char *name, + const uint8_t *data, + size_t size, + Sint32 frameWidth, + Sint32 frameHeigh, + Sint32 framesPerLine, + Bool keepSurface +); + /** * @brief draw a sprite to the screen with all options * @param sprite the sprite to draw diff --git a/include/platform.h b/include/platform.h new file mode 100644 index 00000000..8a405b53 --- /dev/null +++ b/include/platform.h @@ -0,0 +1,4 @@ +#ifdef __GAMECUBE__ +#define open_image() +#else +#endif \ No newline at end of file diff --git a/platform/gamecube/data/bg_flat.png b/platform/gamecube/data/bg_flat.png new file mode 100644 index 00000000..a790ef1d Binary files /dev/null and b/platform/gamecube/data/bg_flat.png differ diff --git a/platform/gamecube/data/ed210.png b/platform/gamecube/data/ed210.png new file mode 100644 index 00000000..2184fb21 Binary files /dev/null and b/platform/gamecube/data/ed210.png differ diff --git a/platform/gamecube/data/ed210_top.png b/platform/gamecube/data/ed210_top.png new file mode 100644 index 00000000..ef4a300b Binary files /dev/null and b/platform/gamecube/data/ed210_top.png differ diff --git a/platform/gamecube/data/perlin-grey.png b/platform/gamecube/data/perlin-grey.png new file mode 100644 index 00000000..dfda0c93 Binary files /dev/null and b/platform/gamecube/data/perlin-grey.png differ diff --git a/platform/gamecube/data/pointer.png b/platform/gamecube/data/pointer.png new file mode 100644 index 00000000..3f80ca24 Binary files /dev/null and b/platform/gamecube/data/pointer.png differ diff --git a/platform/gamecube/data/space_bug.png b/platform/gamecube/data/space_bug.png new file mode 100644 index 00000000..76df3a4b Binary files /dev/null and b/platform/gamecube/data/space_bug.png differ diff --git a/platform/gamecube/data/space_bug_top.png b/platform/gamecube/data/space_bug_top.png new file mode 100644 index 00000000..3ac58210 Binary files /dev/null and b/platform/gamecube/data/space_bug_top.png differ diff --git a/platform/switch/romfs/images/backgrounds/bg_flat.png b/platform/switch/romfs/images/backgrounds/bg_flat.png new file mode 100644 index 00000000..8a2c7716 Binary files /dev/null and b/platform/switch/romfs/images/backgrounds/bg_flat.png differ diff --git a/platform/switch/romfs/images/ed210.png b/platform/switch/romfs/images/ed210.png new file mode 100644 index 00000000..2184fb21 Binary files /dev/null and b/platform/switch/romfs/images/ed210.png differ diff --git a/platform/switch/romfs/images/ed210_top.png b/platform/switch/romfs/images/ed210_top.png new file mode 100644 index 00000000..ef4a300b Binary files /dev/null and b/platform/switch/romfs/images/ed210_top.png differ diff --git a/platform/switch/romfs/images/perlin-grey.png b/platform/switch/romfs/images/perlin-grey.png new file mode 100644 index 00000000..dfda0c93 Binary files /dev/null and b/platform/switch/romfs/images/perlin-grey.png differ diff --git a/platform/switch/romfs/images/pointer.png b/platform/switch/romfs/images/pointer.png new file mode 100644 index 00000000..3f80ca24 Binary files /dev/null and b/platform/switch/romfs/images/pointer.png differ diff --git a/platform/switch/romfs/images/space_bug.png b/platform/switch/romfs/images/space_bug.png new file mode 100644 index 00000000..76df3a4b Binary files /dev/null and b/platform/switch/romfs/images/space_bug.png differ diff --git a/platform/switch/romfs/images/space_bug_top.png b/platform/switch/romfs/images/space_bug_top.png new file mode 100644 index 00000000..3ac58210 Binary files /dev/null and b/platform/switch/romfs/images/space_bug_top.png differ diff --git a/src/game.c b/src/game.c index 8080a4e9..9ca842c6 100644 --- a/src/game.c +++ b/src/game.c @@ -1,46 +1,136 @@ -#include +#include #include "simple_logger.h" #include "gf2d_graphics.h" #include "gf2d_sprite.h" -int main(int argc, char * argv[]) +#ifdef __SWITCH__ +#include +#include +#endif + +#ifdef __GAMECUBE__ +#include +#include +#endif + +#if defined(__GAMECUBE__) || defined(__WII__) +#include "bg_flat_png.h" +#include "pointer_png.h" +#endif + + +int main(int argc, char **argv) { + +#ifdef __SWITCH__ + romfsInit(); + chdir("romfs:/"); +#endif + +#ifdef __GAMECUBE__ + PAD_Init(); +#endif + /*variable declarations*/ int done = 0; const Uint8 * keys; Sprite *sprite; - int mx,my; + int mx = 0, my = 0; float mf = 0; Sprite *mouse; Color mouseColor = gfc_color8(255,100,255,200); /*program initializtion*/ + +#ifdef __SWITCH__ + init_logger("sdmc:/gf2d.log",0); +#elif __GAMECUBE__ + SYS_STDIO_Report(true); + PAD_Init(); +#else init_logger("gf2d.log",0); +#endif + slog("---==== BEGIN ====---"); - gf2d_graphics_initialize( - "gf2d", - 1200, - 720, - 1200, - 720, - vector4d(0,0,0,255), - 0); +#ifdef __GAMECUBE__ + gf2d_graphics_initialize("gf2d", 640, 480, 640, 480, vector4d(0,0,0,255), 0); +#elif __WII__ + gf2d_graphics_initialize("gf2d", 1024, 720, 1024, 720, vector4d(0,0,0,255), 0); +#else + gf2d_graphics_initialize("gf2d", 1200, 720, 1200, 720, vector4d(0,0,0,255), 0); +#endif gf2d_graphics_set_frame_delay(16); gf2d_sprite_init(1024); SDL_ShowCursor(SDL_DISABLE); +#if defined(__SWITCH__) + SDL_JoystickEventState(SDL_ENABLE); + SDL_Joystick* joystick = SDL_JoystickOpen(0); +#endif + +#if defined(__GAMECUBE__) || defined(__WII__) + sprite = gf2d_sprite_load_image_mem("images/backgrounds/bg_flat.png", bg_flat_png, bg_flat_png_size); + mouse = gf2d_sprite_load_all_mem("images/pointer.png", pointer_png, pointer_png_size,32,32,16,0); +#else /*demo setup*/ sprite = gf2d_sprite_load_image("images/backgrounds/bg_flat.png"); mouse = gf2d_sprite_load_all("images/pointer.png",32,32,16,0); +#endif + + /*main game loop*/ +#ifdef __SWITCH__ + while(!done && appletMainLoop()) +#else while(!done) +#endif { SDL_PumpEvents(); // update SDL's internal event structures keys = SDL_GetKeyboardState(NULL); // get the keyboard state for this frame /*update things here*/ + +#if defined(__SWITCH__) + if(SDL_JoystickGetAxis(joystick, 0) > 0) + { + mx+=4; + } + else if(SDL_JoystickGetAxis(joystick, 0) < 0) + { + mx-=4; + } + + if(SDL_JoystickGetAxis(joystick, 1) > 0) + { + my+=4; + } + else if(SDL_JoystickGetAxis(joystick, 1) < 0) + { + my-=4; + } +#elif defined(__GAMECUBE__) + if(PAD_StickX(0) > 0) + { + mx+=4; + } + else if(PAD_StickX(0) < 0) + { + mx-=4; + } + + if(PAD_StickY(0) < 0) + { + my+=4; + } + else if(PAD_StickY(0) > 0) + { + my-=4; + } +#else SDL_GetMouseState(&mx,&my); +#endif + mf+=0.1; if (mf >= 16.0)mf = 0; @@ -66,6 +156,9 @@ int main(int argc, char * argv[]) //slog("Rendering at %f FPS",gf2d_graphics_get_frames_per_second()); } slog("---==== END ====---"); +#ifdef __SWITCH__ + romfsExit(); +#endif return 0; } /*eol@eof*/ diff --git a/src/gf2d_graphics.c b/src/gf2d_graphics.c index 073b6491..06c1b924 100644 --- a/src/gf2d_graphics.c +++ b/src/gf2d_graphics.c @@ -109,6 +109,7 @@ void gf2d_graphics_initialize( return; } + SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB8888, &gf2d_graphics.bitdepth, &gf2d_graphics.rmask, diff --git a/src/gf2d_sprite.c b/src/gf2d_sprite.c index 192276cf..770eb1d1 100644 --- a/src/gf2d_sprite.c +++ b/src/gf2d_sprite.c @@ -1,4 +1,5 @@ #include +#include #include #include "simple_logger.h" @@ -128,6 +129,11 @@ Sprite *gf2d_sprite_load_image(const char *filename) return gf2d_sprite_load_all(filename,-1,-1,1,false); } +Sprite *gf2d_sprite_load_image_mem(const char *name, const uint8_t *data, size_t size) +{ + return gf2d_sprite_load_all_mem(name, data, size,-1,-1,1,false); +} + Sprite *gf2d_sprite_load_all( const char *filename, Sint32 frameWidth, @@ -208,6 +214,92 @@ Sprite *gf2d_sprite_load_all( return sprite; } +Sprite *gf2d_sprite_load_all_mem( + const char *name, + const uint8_t *data, + size_t size, + Sint32 frameWidth, + Sint32 frameHeight, + Sint32 framesPerLine, + Bool keepSurface +) +{ + SDL_Surface *surface = NULL; + Sprite *sprite = NULL; + if (!name) + { + slog("cannot find blank filename"); + return NULL; + } + + sprite = gf2d_sprite_get_by_filename(name); + if (sprite != NULL) + { + // found a copy already in memory + sprite->ref_count++; + return sprite; + } + + SDL_RWops* imgMem = SDL_RWFromConstMem((const void*)data, (int)size); + + surface = IMG_Load_RW(imgMem, 1); + if (!surface) + { + slog("failed to load sprite image %s",name); + return NULL; + } + sprite = gf2d_sprite_new(); + if (!sprite) + { + SDL_FreeSurface(surface); + return NULL; + } + surface = gf2d_graphics_screen_convert(&surface); + if (!surface) + { + slog("failed to load sprite image %s",name); + gf2d_sprite_free(sprite); + return NULL; + } + + sprite->texture = SDL_CreateTextureFromSurface(gf2d_graphics_get_renderer(),surface); + if (!sprite->texture) + { + slog("failed to load sprite image %s",name); + gf2d_sprite_free(sprite); + SDL_FreeSurface(surface); + return NULL; + } + SDL_SetTextureBlendMode(sprite->texture,SDL_BLENDMODE_BLEND); + SDL_UpdateTexture(sprite->texture, + NULL, + surface->pixels, + surface->pitch); + if (frameHeight == -1) + { + sprite->frame_h = surface->h; + } + else sprite->frame_h = frameHeight; + if (frameWidth == -1) + { + sprite->frame_w = surface->w; + } + else sprite->frame_w = frameWidth; + sprite->frames_per_line = framesPerLine; + gfc_line_cpy(sprite->filepath,name); + + if(!keepSurface) + { + SDL_FreeSurface(surface); + } + else + { + sprite->surface = surface; + } + + return sprite; +} + void gf2d_sprite_draw_to_surface( Sprite *sprite, Vector2D position,