From 12c2dfee6d8201d873cbaf22378caec2d521ae63 Mon Sep 17 00:00:00 2001 From: OctoSpacc Date: Mon, 30 Oct 2023 12:27:41 +0100 Subject: [PATCH] Restructure code in preparation for function-based hierarchy --- LibMultiSpacc/Examples/Common.mk | 17 +-- LibMultiSpacc/Examples/NDS.mk | 38 +++--- LibMultiSpacc/LibMultiSpacc/MultiSpacc.c | 154 +++++++++++++++++++++++ LibMultiSpacc/LibMultiSpacc/MultiSpacc.h | 42 ++++++- LibMultiSpacc/LibMultiSpacc/NDS/NDS.c | 40 ------ LibMultiSpacc/LibMultiSpacc/NDS/NDS.h | 20 --- LibMultiSpacc/LibMultiSpacc/SDL12/SDL.c | 27 ---- LibMultiSpacc/LibMultiSpacc/SDL12/SDL.h | 19 --- LibMultiSpacc/LibMultiSpacc/SDL20/SDL.c | 27 ---- LibMultiSpacc/LibMultiSpacc/SDL20/SDL.h | 19 --- LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c | 59 --------- LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.h | 9 -- 12 files changed, 220 insertions(+), 251 deletions(-) create mode 100644 LibMultiSpacc/LibMultiSpacc/MultiSpacc.c delete mode 100644 LibMultiSpacc/LibMultiSpacc/NDS/NDS.c delete mode 100644 LibMultiSpacc/LibMultiSpacc/NDS/NDS.h delete mode 100644 LibMultiSpacc/LibMultiSpacc/SDL12/SDL.c delete mode 100644 LibMultiSpacc/LibMultiSpacc/SDL12/SDL.h delete mode 100644 LibMultiSpacc/LibMultiSpacc/SDL20/SDL.c delete mode 100644 LibMultiSpacc/LibMultiSpacc/SDL20/SDL.h delete mode 100644 LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c delete mode 100644 LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.h diff --git a/LibMultiSpacc/Examples/Common.mk b/LibMultiSpacc/Examples/Common.mk index cc6f6ed..6f2bf43 100644 --- a/LibMultiSpacc/Examples/Common.mk +++ b/LibMultiSpacc/Examples/Common.mk @@ -2,6 +2,7 @@ AppName = $(notdir ${CURDIR}) Sources = $(wildcard *.c ../../LibMultiSpacc/*.c) CFlags = -O2 -Wpedantic -Werror +# Default build is always for the host system ifndef Target ifeq ($(shell uname --operating-system), Msys) Target = WindowsPC @@ -26,16 +27,16 @@ ifdef Target endif ifeq ($(MultiSpacc_Target), SDL12) - Defines += -DMultiSpacc_Target_SDL12 + Defines += -DMultiSpacc_Target_SDL12 -DMultiSpacc_Target_SDLCom CFlags += $(shell sdl-config --cflags) LdFlags += $(shell sdl-config --libs) -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf - Sources += $(wildcard ../../LibMultiSpacc/SDLCom/*.c ../../LibMultiSpacc/SDL12/*.c) + #Sources += $(wildcard ../../LibMultiSpacc/SDLCom/*.c ../../LibMultiSpacc/SDL12/*.c) BuildProcess = Normal else ifeq ($(MultiSpacc_Target), SDL20) - Defines += -DMultiSpacc_Target_SDL20 + Defines += -DMultiSpacc_Target_SDL20 -DMultiSpacc_Target_SDLCom CFlags += $(shell sdl2-config --cflags) LdFlags += $(shell sdl2-config --libs) -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf - Sources += $(wildcard ../../LibMultiSpacc/SDLCom/*.c ../../LibMultiSpacc/SDL20/*.c) + #Sources += $(wildcard ../../LibMultiSpacc/SDLCom/*.c ../../LibMultiSpacc/SDL20/*.c) BuildProcess = Normal else ifeq ($(MultiSpacc_Target), NDS) Defines += -DMultiSpacc_Target_NDS @@ -56,12 +57,14 @@ NDS: cp ../NDS.mk $(VirtualBuildDir)/Makefile cp $(Sources) $(VirtualBuildDir)/source/ cp $(wildcard ../../LibMultiSpacc/*.*) $(VirtualBuildDir)/source/.tmp/ - cd $(VirtualBuildDir)/source/.tmp; for i in *; do mv $$i ../LibMultiSpacc_$$i; done - cp $(wildcard ../../LibMultiSpacc/NDS/*.*) $(VirtualBuildDir)/source/.tmp/ - cd $(VirtualBuildDir)/source/.tmp; for i in *; do mv $$i ../LibMultiSpacc_NDS_$$i; done + # rm of the last file is temporary fix for a strange file duplication bug + cd $(VirtualBuildDir)/source/.tmp; for i in *; do mv $$i ../LibMultiSpacc_$$i; done; rm ../MultiSpacc.c # + #cp $(wildcard ../../LibMultiSpacc/NDS/*.*) $(VirtualBuildDir)/source/.tmp/ + #cd $(VirtualBuildDir)/source/.tmp; for i in *; do mv $$i ../LibMultiSpacc_NDS_$$i; done for i in $(VirtualBuildDir)/source/*; do sed -i 's|#include[ \t]"../../LibMultiSpacc/|#include "LibMultiSpacc_|g' $$i; done for i in $(VirtualBuildDir)/source/*; do sed -i 's|#include[ \t]"../MultiSpacc|#include "LibMultiSpacc_MultiSpacc|g' $$i; done for i in $(VirtualBuildDir)/source/*; do sed -i 's|#include[ \t]"NDS/|#include "LibMultiSpacc_NDS_|g' $$i; done + for i in $(VirtualBuildDir)/source/*; do sed -i 's|#include[ \t]"./|#include "./LibMultiSpacc_|g' $$i; done cd $(VirtualBuildDir); make Run run: All diff --git a/LibMultiSpacc/Examples/NDS.mk b/LibMultiSpacc/Examples/NDS.mk index f654894..dfd1ce7 100644 --- a/LibMultiSpacc/Examples/NDS.mk +++ b/LibMultiSpacc/Examples/NDS.mk @@ -1,3 +1,6 @@ +# This Makefile is borrowed from devkitPro's nds-examples +# + #--------------------------------------------------------------------------------- .SUFFIXES: #--------------------------------------------------------------------------------- @@ -39,23 +42,22 @@ LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- LIBS := -lnds9 - - + #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- LIBDIRS := $(LIBNDS) - + #--------------------------------------------------------------------------------- # 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)) export DEPSDIR := $(CURDIR)/$(BUILD) @@ -63,7 +65,7 @@ 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,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin))) - + #--------------------------------------------------------------------------------- # use CXX for linking C++ projects, CC for standard C #--------------------------------------------------------------------------------- @@ -80,46 +82,44 @@ endif export OFILES := $(BINFILES:.bin=.o) \ $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - + 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) - + .PHONY: $(BUILD) clean - + #--------------------------------------------------------------------------------- $(BUILD): @[ -d $@ ] || mkdir -p $@ @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - + #--------------------------------------------------------------------------------- clean: @echo clean ... @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).ds.gba - - + #--------------------------------------------------------------------------------- else - + DEPENDS := $(OFILES:.o=.d) - + #--------------------------------------------------------------------------------- # main targets #--------------------------------------------------------------------------------- $(OUTPUT).nds : $(OUTPUT).elf $(OUTPUT).elf : $(OFILES) - + #--------------------------------------------------------------------------------- %.o : %.bin #--------------------------------------------------------------------------------- @echo $(notdir $<) $(bin2o) - - + -include $(DEPENDS) - + #--------------------------------------------------------------------------------------- endif #--------------------------------------------------------------------------------------- diff --git a/LibMultiSpacc/LibMultiSpacc/MultiSpacc.c b/LibMultiSpacc/LibMultiSpacc/MultiSpacc.c new file mode 100644 index 0000000..f06b9b9 --- /dev/null +++ b/LibMultiSpacc/LibMultiSpacc/MultiSpacc.c @@ -0,0 +1,154 @@ +#include "./MultiSpacc.h" + +#ifdef MultiSpacc_Target_SDL12 + MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ) { + return SDL_SetVideoMode( WindowConfig.Width, WindowConfig.Height, WindowConfig.Bits, WindowConfig.Flags ); + } + MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) { + return Window; + } + + void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char *Title ) { + SDL_WM_SetCaption( Title, NULL ); + } + void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon ) { + SDL_WM_SetIcon( Icon, NULL ); + } + + int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) { + if( Flag ) + return SDL_SetColorKey( Surface, SDL_SRCCOLORKEY, Key ); + else + return SDL_SetColorKey( Surface, 0, Key ); + } +#endif + +#ifdef MultiSpacc_Target_SDL20 + MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ) { + return SDL_CreateWindow( NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WindowConfig.Width, WindowConfig.Height, WindowConfig.Flags ); + } + MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) { + return SDL_GetWindowSurface( Window ); + } + + void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char Title[] ) { + SDL_SetWindowTitle( Window, Title ); + } + void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon ) { + SDL_SetWindowIcon( Window, Icon ); + } + + int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) { + if ( Flag ) { + return SDL_SetColorKey( Surface, SDL_TRUE, Key ); + } else { + return SDL_SetColorKey( Surface, SDL_FALSE, Key ); + } + } +#endif + +#ifdef MultiSpacc_Target_SDLCom + int MultiSpacc_PollEvent( MultiSpacc_Event *Event ) + { + SDL_Event FromEvent; + int Result = SDL_PollEvent( &FromEvent ); + *Event = (MultiSpacc_Event) { + .Type = FromEvent.type, + .Key = FromEvent.key.keysym.sym, + }; + return Result; + } + + MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *Screen, Uint32 *ColorKey ) + { + MultiSpacc_Surface *Final = NULL; + MultiSpacc_Surface *Raw = IMG_Load( FilePath ); + if( Raw == NULL ) { + printf("[E] Error reading image %s.\n", FilePath); + } else { + Final = SDL_ConvertSurface( Raw, Screen->format, 0 ); + SDL_FreeSurface( Raw ); + if( Final == NULL ) { + printf("[E] Error adapting image %s.\n", FilePath); + } else { + Uint32 FinalColorKey = SDL_MapRGB( Final->format, 0xFF, 0x00, 0xFF ); // Magenta + if( ColorKey != NULL ) + FinalColorKey = *ColorKey; + MultiSpacc_SetColorKey( Final, true, FinalColorKey ); + }; + }; + return Final; + } + + void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, MultiSpacc_SurfaceConfig WindowConfig, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ) + { + for( int i = 0; i < strlen( Text ); i++ ) + { + MultiSpacc_Rect Offset = { + .x = (x * 8) + (8 * i), + .y = (y * 8), + }; + MultiSpacc_Rect Clip = { + .x = 8 * (Text[i] % 16), + .y = 8 * (Text[i] / 16), + .w = 8, + .h = 8, + }; + SDL_BlitSurface( Tiles, &Clip, Surface, &Offset ); + }; + } + + void MultiSpacc_PrintDebug( const char *format, ... ) + { + va_list args; + va_start(args, format); + fprintf(stderr, format, args); + va_end(args); + } +#endif + +#ifdef MultiSpacc_Target_NDS + MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ) + { + PrintConsole *bottomScreen = NULL; + + videoSetModeSub(MODE_0_2D); + vramSetBankC(VRAM_C_SUB_BG); + + bottomScreen = consoleInit(bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true); + consoleSelect(bottomScreen); + return bottomScreen; + } + + MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) + { + return Window; + } + + void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char Title[] ){} + void MultiSpacc_PrintDebug( const char *format, ... ){} + + int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window ) + { + return 0; + } + + void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, MultiSpacc_SurfaceConfig WindowConfig, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ) + { + iprintf(Text); + } + + void MultiSpacc_Sleep( int milliseconds ) + { + int frames = (60 * milliseconds / 1000); + for (int i=0; i #ifdef MultiSpacc_Target_SDL12 - #include "SDL12/SDL.h" - #include "SDLCom/SDL.h" + #include + #include + #include + #include + #define MultiSpacc_Window SDL_Surface + #define MultiSpacc_UpdateWindowSurface SDL_Flip + typedef struct MultiSpacc_Event { + Uint32 Type; + SDLKey Key; + } MultiSpacc_Event; #endif #ifdef MultiSpacc_Target_SDL20 - #include "SDL20/SDL.h" - #include "SDLCom/SDL.h" + #include + #include + #include + #include + #define MultiSpacc_Window SDL_Window + #define MultiSpacc_UpdateWindowSurface SDL_UpdateWindowSurface + typedef struct MultiSpacc_Event { + Uint32 Type; + SDL_Keycode Key; + } MultiSpacc_Event; +#endif + +#ifdef MultiSpacc_Target_SDLCom + #define MultiSpacc_Init SDL_Init + #define MultiSpacc_Surface SDL_Surface + #define MultiSpacc_GetTicks SDL_GetTicks + #define MultiSpacc_Sleep SDL_Delay + #define MultiSpacc_Rect SDL_Rect #endif #ifdef MultiSpacc_Target_NDS - #include "NDS/NDS.h" + #include + #define Uint32 int32 + #define MultiSpacc_Surface PrintConsole + #define MultiSpacc_Window PrintConsole + typedef struct MultiSpacc_Event { + int Keys; + } MultiSpacc_Event; + int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window ); + void MultiSpacc_Sleep( int milliseconds ); #endif typedef struct MultiSpacc_SurfaceConfig { diff --git a/LibMultiSpacc/LibMultiSpacc/NDS/NDS.c b/LibMultiSpacc/LibMultiSpacc/NDS/NDS.c deleted file mode 100644 index 81826ca..0000000 --- a/LibMultiSpacc/LibMultiSpacc/NDS/NDS.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "../MultiSpacc.h" - -MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ) -{ - PrintConsole *bottomScreen = NULL; - - videoSetModeSub(MODE_0_2D); - vramSetBankC(VRAM_C_SUB_BG); - - bottomScreen = consoleInit(bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true); - consoleSelect(bottomScreen); - return bottomScreen; -} - -MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) -{ - return Window; -} - -void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char Title[] ){} -void MultiSpacc_PrintDebug( const char *format, ... ){} - -int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window ) -{ - return 0; -} - -void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, MultiSpacc_SurfaceConfig WindowConfig, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ) -{ - iprintf(Text); -} - -void MultiSpacc_Sleep( int milliseconds ) -{ - int frames = (60 * milliseconds / 1000); - for (int i=0; i - -#define Uint32 int32 -#define MultiSpacc_Surface PrintConsole -#define MultiSpacc_Window PrintConsole - -typedef struct MultiSpacc_Event { - int Keys; -} MultiSpacc_Event; - -int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window ); - -void MultiSpacc_Sleep( int milliseconds ); \ No newline at end of file diff --git a/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.c b/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.c deleted file mode 100644 index 0a36500..0000000 --- a/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "../MultiSpacc.h" -#include "SDL/SDL.h" -#include "SDL/SDL_image.h" -#include "SDL/SDL_mixer.h" -#include "SDL/SDL_ttf.h" -#include "../SDLCom/SDL.h" - -MultiSpacc_Window MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ) { - return *SDL_SetVideoMode( WindowConfig.Width, WindowConfig.Height, WindowConfig.Bits, WindowConfig.Flags ); -} -MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) { - return Window; -} - -void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char *Title ) { - SDL_WM_SetCaption( Title, NULL ); -} -void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon ) { - SDL_WM_SetIcon( Icon, NULL ); -} - -int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) { - if( Flag ) - return SDL_SetColorKey( Surface, SDL_SRCCOLORKEY, Key ); - else - return SDL_SetColorKey( Surface, 0, Key ); -} diff --git a/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.h b/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.h deleted file mode 100644 index 0fe8865..0000000 --- a/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#ifndef MultiSpacc_Target_SDL12 - #define MultiSpacc_Target_SDL12 -#endif - -#include "../MultiSpacc.h" -#include -#include -#include -#include - -#define MultiSpacc_Window SDL_Surface -#define MultiSpacc_UpdateWindowSurface SDL_Flip - -typedef struct MultiSpacc_Event { - Uint32 Type; - SDLKey Key; -} MultiSpacc_Event; diff --git a/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.c b/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.c deleted file mode 100644 index 294b7a8..0000000 --- a/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "../MultiSpacc.h" -#include "SDL2/SDL.h" -#include "SDL2/SDL_image.h" -#include "SDL2/SDL_mixer.h" -#include "SDL2/SDL_ttf.h" -#include "../SDLCom/SDL.h" - -MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ) { - return SDL_CreateWindow( NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WindowConfig.Width, WindowConfig.Height, WindowConfig.Flags ); -} -MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) { - return SDL_GetWindowSurface( Window ); -} - -void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char Title[] ) { - SDL_SetWindowTitle( Window, Title ); -} -void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon ) { - SDL_SetWindowIcon( Window, Icon ); -} - -int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) { - if ( Flag ) - return SDL_SetColorKey( Surface, SDL_TRUE, Key ); - else - return SDL_SetColorKey( Surface, SDL_FALSE, Key ); -} diff --git a/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.h b/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.h deleted file mode 100644 index 898b52b..0000000 --- a/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#ifndef MultiSpacc_Target_SDL20 - #define MultiSpacc_Target_SDL20 -#endif - -#include "../MultiSpacc.h" -#include -#include -#include -#include - -#define MultiSpacc_Window SDL_Window -#define MultiSpacc_UpdateWindowSurface SDL_UpdateWindowSurface - -typedef struct MultiSpacc_Event { - Uint32 Type; - SDL_Keycode Key; -} MultiSpacc_Event; diff --git a/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c b/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c deleted file mode 100644 index bfc7a32..0000000 --- a/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "../MultiSpacc.h" - -int MultiSpacc_PollEvent( MultiSpacc_Event *Event ) -{ - SDL_Event FromEvent; - int Result = SDL_PollEvent( &FromEvent ); - *Event = (MultiSpacc_Event) { - .Type = FromEvent.type, - .Key = FromEvent.key.keysym.sym, - }; - return Result; -} - -MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *Screen, Uint32 *ColorKey ) -{ - MultiSpacc_Surface *Final = NULL; - MultiSpacc_Surface *Raw = IMG_Load( FilePath ); - if( Raw == NULL ) { - printf("[E] Error reading image %s.\n", FilePath); - } else { - Final = SDL_ConvertSurface( Raw, Screen->format, 0 ); - SDL_FreeSurface( Raw ); - if( Final == NULL ) { - printf("[E] Error adapting image %s.\n", FilePath); - } else { - Uint32 FinalColorKey = SDL_MapRGB( Final->format, 0xFF, 0x00, 0xFF ); // Magenta - if( ColorKey != NULL ) - FinalColorKey = *ColorKey; - MultiSpacc_SetColorKey( Final, true, FinalColorKey ); - }; - }; - return Final; -} - -void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, MultiSpacc_SurfaceConfig WindowConfig, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ) -{ - for( int i = 0; i < strlen( Text ); i++ ) - { - MultiSpacc_Rect Offset = { - .x = (x * 8) + (8 * i), - .y = (y * 8), - }; - MultiSpacc_Rect Clip = { - .x = 8 * (Text[i] % 16), - .y = 8 * (Text[i] / 16), - .w = 8, - .h = 8, - }; - SDL_BlitSurface( Tiles, &Clip, Surface, &Offset ); - }; -} - -void MultiSpacc_PrintDebug( const char *format, ... ) -{ - va_list args; - va_start(args, format); - fprintf(stderr, format, args); - va_end(args); -} \ No newline at end of file diff --git a/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.h b/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.h deleted file mode 100644 index e244df5..0000000 --- a/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "../MultiSpacc.h" - -#define MultiSpacc_Init SDL_Init -#define MultiSpacc_Surface SDL_Surface -#define MultiSpacc_GetTicks SDL_GetTicks -#define MultiSpacc_Sleep SDL_Delay -#define MultiSpacc_Rect SDL_Rect