Update to latest LibMultiSpacc, support Web build, update Makefile, add 2 blocks

This commit is contained in:
2025-02-15 15:52:22 +01:00
parent 1ca44c833d
commit 19e97565f2
9 changed files with 205 additions and 186 deletions

4
.gitignore vendored
View File

@@ -1,4 +1,8 @@
*.exe *.exe
*.js
*.wasm
*.data
*.run
*.o *.o
Source/LibMultiSpacc Source/LibMultiSpacc
Source/LibMultiSpacc/* Source/LibMultiSpacc/*

22
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,22 @@
image: debian:latest
before_script: |
apt update
apt install -y git
git clone --depth 1 https://gitlab.com/octospacc/MultiSpaccSDK
bash ./MultiSpaccSDK/Tools/InstallBuildEnvironment.sh
mv ./MultiSpaccSDK/LibMultiSpacc/LibMultiSpacc ./Source/LibMultiSpacc
pages:
stage: deploy
script: |
make -j$(nproc --all) Target=Web
mkdir -p ./public
mv ./Emscripten.* ./public/
mv ./MultiSpaccSDK/LibMultiSpacc/Examples/Emscripten.html ./public/index.html
artifacts:
paths:
- public
publish: public
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -1,7 +1,7 @@
AppName = BloccSpacc AppName = BloccSpacc
ExeSuffix = .exe ExeSuffix = .run
Sources = $(wildcard Source/*.c) Sources = $(wildcard Source/*.c Source/LibMultiSpacc/*.c)
CFlags = -O2 CFlags = -O2
CC = gcc $(Defines) CC = gcc $(Defines)
@@ -13,6 +13,12 @@ ifdef Target
ifeq ($(Target), PC) ifeq ($(Target), PC)
Defines = -DTarget_PC Defines = -DTarget_PC
MultiSpacc_Target = SDL20 MultiSpacc_Target = SDL20
else ifeq ($(Target), Web)
Defines = -DTarget_PC -DTarget_Web
MultiSpacc_Target = Web
AppName = Emscripten
ExeSuffix = .js
CC = emcc $(Defines)
else ifeq ($(Target), PocketGo) else ifeq ($(Target), PocketGo)
ExeSuffix = .PocketGo.exe ExeSuffix = .PocketGo.exe
PathPrefix = /opt/miyoo/bin/arm-miyoo-linux-uclibcgnueabi PathPrefix = /opt/miyoo/bin/arm-miyoo-linux-uclibcgnueabi
@@ -25,20 +31,26 @@ endif
ifeq ($(MultiSpacc_Target), SDL12) ifeq ($(MultiSpacc_Target), SDL12)
Defines += -DMultiSpacc_Target_SDL12 Defines += -DMultiSpacc_Target_SDL12
LdFlags += -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf LdFlags += -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf
Sources += $(wildcard Source/LibMultiSpacc/*.c Source/LibMultiSpacc/SDL12/*.c) Sources += $(wildcard Source/LibMultiSpacc/SDLCom/*.c Source/LibMultiSpacc/SDL12/*.c)
else ifeq ($(MultiSpacc_Target), SDL20) else ifeq ($(MultiSpacc_Target), SDL20)
Defines += -DMultiSpacc_Target_SDL20 Defines += -DMultiSpacc_Target_SDL20
LdFlags += -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf LdFlags += -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
Sources += $(wildcard Source/LibMultiSpacc/*.c Source/LibMultiSpacc/SDL20/*.c) Sources += $(wildcard Source/LibMultiSpacc/SDLCom/*.c Source/LibMultiSpacc/SDL20/*.c)
else ifeq ($(MultiSpacc_Target), Web)
Defines += -DMultiSpacc_Target_Web -DMultiSpacc_Target_SDL20 -DMultiSpacc_Target_SDLWeb
LdFlags += -sWASM=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sSDL2_IMAGE_FORMATS='["png"]' -sUSE_SDL_TTF=2 -sUSE_SDL_MIXER=2 --preload-file Assets/Blocks.png --preload-file Assets/Cursorset.png --preload-file Assets/Icon.png --preload-file Assets/LiberationMono-Regular.ttf
endif endif
Objects = $(Sources:.c=.o) Objects = $(Sources:.c=.o)
all: $(AppName) all All: $(AppName)
$(AppName): $(Objects) $(AppName): $(Objects)
$(CC) $^ $(CFlags) $(LdFlags) -o $(AppName)$(ExeSuffix) $(CC) $^ $(CFlags) $(LdFlags) -o $(AppName)$(ExeSuffix)
clean: run Run: All
./$(AppName)$(ExeSuffix)
clean Clean clear Clear:
find -L . -name "*.o" -type f -delete find -L . -name "*.o" -type f -delete
rm -f $(AppName)$(ExeSuffix) $(AppName).*$(ExeSuffix) rm -f $(AppName)$(ExeSuffix) $(AppName).*$(ExeSuffix) *.js *.wasm *.data

View File

@@ -1,8 +1,7 @@
#pragma once #pragma once
#include "LibMultiSpacc/MultiSpacc.h" #include "LibMultiSpacc/MultiSpacc.h"
//#include "SDL/SDL.h"
#define BlocksetNum 6 #define BlocksetNum 8
#define BlockSize 32 #define BlockSize 32
#define ChunkSize 16 #define ChunkSize 16
@@ -22,4 +21,6 @@ struct Block Blocks[BlocksetNum] = {
{ 3, "Gray", {}, 0, false, false }, { 3, "Gray", {}, 0, false, false },
{ 4, "Green", {}, 0, false, false }, { 4, "Green", {}, 0, false, false },
{ 5, "Blue", {}, 0, false, false }, { 5, "Blue", {}, 0, false, false },
{ 6, "Purple", {}, 0, false, false },
{ 7, "Red", {}, 0, false, false },
}; };

View File

@@ -2,28 +2,27 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include "LibMultiSpacc/MultiSpacc.h" #include "LibMultiSpacc/MultiSpacc.h"
//#include "SDL/SDL.h"
//#include "SDL/SDL_image.h"
//#include "SDL/SDL_ttf.h"
#include "TargetsConfigs.h" #include "TargetsConfigs.h"
#include "Blocks.h" #include "Blocks.h"
#include "Keys.h" #include "Keys.h"
#include "Util.h" #include "Util.h"
#define swcase break; case
#define AppName "BloccSpacc" #define AppName "BloccSpacc"
MultiSpacc_Window *Window = NULL; MultiSpacc_Window *Window = NULL;
MultiSpacc_Surface *Screen = NULL; MultiSpacc_Surface *Screen = NULL;
SDL_Event Event; MultiSpacc_Event Event;
#define GameTick 30 #define GameTick 30
SDL_Surface * Cursorset = NULL; MultiSpacc_Surface *Cursorset = NULL;
#define CursorsNum 2 #define CursorsNum 2
SDL_Rect Cursors[CursorsNum]; SDL_Rect Cursors[CursorsNum];
SDL_Surface * BlocksImg = NULL; MultiSpacc_Surface *BlocksImg = NULL;
SDL_Surface * DebugMsg = NULL; MultiSpacc_Surface *DebugMsg = NULL;
TTF_Font *DebugFont = NULL; TTF_Font *DebugFont = NULL;
SDL_Color DebugTextColor = { 80, 80, 80 }; SDL_Color DebugTextColor = { 80, 80, 80 };
@@ -32,16 +31,16 @@ bool InGame, InTitleMenu, InInventory;
bool Quit, Recalc, DebugMode; bool Quit, Recalc, DebugMode;
// <https://www.libsdl.org/release/SDL-1.2.15/docs/html/guidetimeexamples.html> // <https://www.libsdl.org/release/SDL-1.2.15/docs/html/guidetimeexamples.html>
static Uint32 NextTickTime; Uint32 NextTickTime;
Uint32 CalcTimeLeft() { Uint32 CalcTimeLeft() {
Uint32 Now; Uint32 Now;
Now = SDL_GetTicks(); Now = MultiSpacc_GetTicks();
if ( NextTickTime <= Now ) { if ( NextTickTime <= Now ) {
return 0; return 0;
} else { } else {
return NextTickTime - Now; return NextTickTime - Now;
} };
} };
struct UsedKeys { struct UsedKeys {
bool Up, Down, Left, Right, Above, Below; bool Up, Down, Left, Right, Above, Below;
@@ -63,20 +62,21 @@ struct xyz GetBlocksOnScreenNum() {
} }
bool SysInit() { bool SysInit() {
if ( SDL_Init ( SDL_INIT_EVERYTHING ) != 0 ) { //if ( MultiSpacc_Init( SDL_INIT_EVERYTHING ) != 0 ) {
printf("[E] Error initializing SDL.\n"); // printf("[E] Error initializing Core.\n");
return false; // return false;
} //};
Window = MultiSpacc_SetWindow( ScreenWidth, ScreenHeight, ScreenBits, 0 ); MultiSpacc_SurfaceConfig windowConfig = {0};
Window = MultiSpacc_SetWindow( &windowConfig );
Screen = MultiSpacc_GetWindowSurface( Window ); Screen = MultiSpacc_GetWindowSurface( Window );
if ( Screen == NULL ) { if ( Screen == NULL ) {
printf("[E] Error initializing screen.\n"); printf("[E] Error initializing Video System.\n");
return false; return false;
} };
if( TTF_Init() != 0 ) { if( TTF_Init() != 0 ) {
printf("[E] Error initializing SDL_TTF.\n"); printf("[E] Error initializing Font System.\n");
return false; return false;
} };
MultiSpacc_SetAppTitle( Window, AppName ); MultiSpacc_SetAppTitle( Window, AppName );
MultiSpacc_SetAppIcon( Window, LoadImage( "Assets/Icon.png", Screen ) ); MultiSpacc_SetAppIcon( Window, LoadImage( "Assets/Icon.png", Screen ) );
return true; return true;
@@ -87,19 +87,19 @@ bool LoadAssets() {
Cursorset = LoadImage( "Assets/Cursorset.png", Screen ); Cursorset = LoadImage( "Assets/Cursorset.png", Screen );
if ( Cursorset == NULL ) { if ( Cursorset == NULL ) {
Error = true; Error = true;
} };
BlocksImg = LoadImage( "Assets/Blocks.png", Screen ); BlocksImg = LoadImage( "Assets/Blocks.png", Screen );
if ( BlocksImg == NULL ) { if ( BlocksImg == NULL ) {
Error = true; Error = true;
} };
DebugFont = TTF_OpenFont( "Assets/LiberationMono-Regular.ttf", 12 ); DebugFont = TTF_OpenFont( "Assets/LiberationMono-Regular.ttf", 12 );
if ( DebugFont == NULL ) { if ( DebugFont == NULL ) {
Error = true; Error = true;
} };
if ( Error ) { if ( Error ) {
printf("[E] Error loading assets.\n"); printf("[E] Error loading assets.\n");
return false; return false;
} };
return true; return true;
} }
@@ -247,37 +247,41 @@ void DrawCursor() {
} }
} }
void DrawDebug() { // There's a memory leak somewhere here void DrawString( char Str[], int x, int y, TTF_Font* Font, SDL_Color Color ) {
char Str[127]; MultiSpacc_Surface *MsgSurf = TTF_RenderText_Blended( Font, Str, Color );
DrawSurf( x, y, MsgSurf, NULL, Screen );
SDL_FreeSurface( MsgSurf );
}
void DrawDebug() {
char Str[128];
snprintf( Str, sizeof(Str), "CursorPos: x:%d y:%d z:%d", CursorPos.x, CursorPos.y, CursorPos.z ); snprintf( Str, sizeof(Str), "CursorPos: x:%d y:%d z:%d", CursorPos.x, CursorPos.y, CursorPos.z );
DebugMsg = TTF_RenderText_Blended( DebugFont, Str, DebugTextColor ); DrawString( Str, 8, 8, DebugFont, DebugTextColor );
DrawSurf( 8, 8, DebugMsg, NULL, Screen );
snprintf( Str, sizeof(Str), "Camera: x:%d y:%d z:%d", Camera.x, Camera.y, Camera.z ); snprintf( Str, sizeof(Str), "Camera: x:%d y:%d z:%d", Camera.x, Camera.y, Camera.z );
DebugMsg = TTF_RenderText_Blended( DebugFont, Str, DebugTextColor ); DrawString( Str, 8, 20, DebugFont, DebugTextColor );
DrawSurf( 8, 20, DebugMsg, NULL, Screen );
struct xyz CursorCoords = OrthoToIso( CursorPos.x, CursorPos.y, CursorPos.z, 1 ); struct xyz CursorCoords = OrthoToIso( CursorPos.x, CursorPos.y, CursorPos.z, 1 );
snprintf( Str, sizeof(Str), "CursorCoords: x:%d y:%d z:%d", CursorCoords.x, CursorCoords.y, CursorCoords.z ); snprintf( Str, sizeof(Str), "CursorCoords: x:%d y:%d z:%d", CursorCoords.x, CursorCoords.y, CursorCoords.z );
DebugMsg = TTF_RenderText_Blended( DebugFont, Str, DebugTextColor ); DrawString( Str, 8, 32, DebugFont, DebugTextColor );
DrawSurf( 8, 32, DebugMsg, NULL, Screen );
} }
void SetSuperflatMap(){ void SetSuperflatMap(){
for ( int z = 0; z < ChunksNum.z; z++ ) { for ( int z = 0; z < ChunksNum.z; z++ ) {
for ( int x = 0; x < ChunksNum.x; x++ ) { for ( int x = 0; x < ChunksNum.x; x++ ) {
Map[0][z][x] = 4; Map[0][z][x] = 4;
} };
} };
for ( int y = 1; y < ChunksNum.y; y++ ) { for ( int y = 1; y < ChunksNum.y; y++ ) {
for ( int z = 0; z < ChunksNum.z; z++ ) { for ( int z = 0; z < ChunksNum.z; z++ ) {
for ( int x = 0; x < ChunksNum.x; x++ ) { for ( int x = 0; x < ChunksNum.x; x++ ) {
Map[y][z][x] = 0; Map[y][z][x] = 0;
} };
} };
} };
} };
void SetRandomNoiseMap(){ void SetRandomNoiseMap(){
for ( int y = 0; y < ChunksNum.y; y++ ) { for ( int y = 0; y < ChunksNum.y; y++ ) {
for ( int z = 0; z < ChunksNum.z; z++ ) { for ( int z = 0; z < ChunksNum.z; z++ ) {
@@ -285,12 +289,12 @@ void SetRandomNoiseMap() {
int r = rand() % BlocksetNum; int r = rand() % BlocksetNum;
if ( r == 1 ) { // Avoid block 1 (all white, hard to see) for testing if ( r == 1 ) { // Avoid block 1 (all white, hard to see) for testing
r = 2; r = 2;
} };
Map[y][z][x] = r; Map[y][z][x] = r;
} };
} };
} };
} };
void GameInit() { void GameInit() {
for ( int i = 0; i < CursorsNum; i++ ) { for ( int i = 0; i < CursorsNum; i++ ) {
@@ -318,71 +322,33 @@ void GameInit() {
SelectedBlock = 2; SelectedBlock = 2;
Recalc = true; Recalc = true;
InGame = true; InGame = true;
} };
int main( int argc, char* args[] ) { bool GameLoop ( void *args ) {
printf("[I] Starting!\n"); NextTickTime = MultiSpacc_GetTicks() + GameTick;
srand( time( NULL ) ); while ( MultiSpacc_PollEvent( &Event ) ) {
if ( Event.Type == SDL_QUIT ) {
if ( !SysInit() ) {
printf("[E] Error initializing SDL.\n");
return 1;
}
if ( !LoadAssets() ) {
printf("[E] Error loading assets.\n");
return 1;
}
GameInit();
while ( !Quit ) {
NextTickTime = SDL_GetTicks() + GameTick;
while ( SDL_PollEvent( & Event ) ) {
if ( Event.type == SDL_QUIT ) {
Quit = true; Quit = true;
} } else
else if ( Event.type == SDL_KEYUP ) { if ( Event.Type == SDL_KEYUP ) {
Recalc = true; Recalc = true;
if ( Event.key.keysym.sym == KeyEsc ) { switch( Event.Key ){
UsedKeys.Esc = true; swcase KeyUp : UsedKeys.Up = true;
} swcase KeyRight : UsedKeys.Right = true;
else if ( Event.key.keysym.sym == KeyDebug ) { swcase KeyDown : UsedKeys.Down = true;
DebugMode = !DebugMode; swcase KeyLeft : UsedKeys.Left = true;
} swcase KeyAbove : UsedKeys.Above = true;
else if ( Event.key.keysym.sym == KeyInventory ) { swcase KeyBelow : UsedKeys.Below = true;
UsedKeys.Inventory = true; swcase KeyPlace : UsedKeys.Place = true;
} swcase KeyBreak : UsedKeys.Break = true;
else if ( Event.key.keysym.sym == KeyGenFlatMap ) { swcase KeyEsc : UsedKeys.Esc = true;
SetSuperflatMap(); swcase KeyInventory : UsedKeys.Inventory = true;
} swcase KeyDebug : DebugMode = !DebugMode;
else if ( Event.key.keysym.sym == KeyGenNoiseMap ) { swcase KeyGenFlatMap : SetSuperflatMap();
SetRandomNoiseMap(); swcase KeyGenNoiseMap : SetRandomNoiseMap();
} };
else if ( Event.key.keysym.sym == KeyUp ) { };
UsedKeys.Up = true; };
}
else if ( Event.key.keysym.sym == KeyRight ) {
UsedKeys.Right = true;
}
else if ( Event.key.keysym.sym == KeyDown ) {
UsedKeys.Down = true;
}
else if ( Event.key.keysym.sym == KeyLeft ) {
UsedKeys.Left = true;
}
else if ( Event.key.keysym.sym == KeyAbove ) {
UsedKeys.Above = true;
}
else if ( Event.key.keysym.sym == KeyBelow ) {
UsedKeys.Below = true;
}
else if ( Event.key.keysym.sym == KeyPlace ) {
UsedKeys.Place = true;
}
else if ( Event.key.keysym.sym == KeyBreak ) {
UsedKeys.Break = true;
}
}
}
EventHandle(); EventHandle();
if ( Recalc ) { if ( Recalc ) {
FillSurfRGB ( 0xFF, 0xFF, 0xFF, Screen ); FillSurfRGB ( 0xFF, 0xFF, 0xFF, Screen );
@@ -392,21 +358,37 @@ int main( int argc, char* args[] ) {
DrawCursor(); DrawCursor();
if ( DebugMode ) { if ( DebugMode ) {
DrawDebug(); DrawDebug();
} };
} };
if ( InInventory ) { if ( InInventory ) {
DrawInventory(); DrawInventory();
} };
if ( !FlipScreen( Window ) ) { if ( !FlipScreen( Window ) ) {
return 1; return 1;
} };
Recalc = false; Recalc = false;
} };
SDL_Delay( CalcTimeLeft() ); //MultiSpacc_Sleep( CalcTimeLeft() );
NextTickTime += GameTick; NextTickTime += GameTick;
return !Quit;
} }
int main( int argc, char *args[] ) {
printf("[I] Starting!\n");
srand( time( NULL ) );
if ( !SysInit() ) {
printf("[E] Error initializing System.\n");
return 1;
};
if ( !LoadAssets() ) {
printf("[E] Error loading assets.\n");
return 1;
};
GameInit();
MultiSpacc_SetMainLoop( GameLoop, NULL, NULL );
printf("[I] Exiting!\n"); printf("[I] Exiting!\n");
SDL_Quit(); //SDL_Quit();
return 0; return 0;
} };

View File

@@ -1,11 +1,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "LibMultiSpacc/MultiSpacc.h" #include "LibMultiSpacc/MultiSpacc.h"
//#include "SDL/SDL.h"
//#include "SDL/SDL_image.h"
SDL_Surface * LoadImage ( char *FilePath, MultiSpacc_Surface *Screen ) { MultiSpacc_Surface * LoadImage ( char *FilePath, MultiSpacc_Surface *Screen ) {
SDL_Surface *a = NULL; MultiSpacc_Surface *a = NULL;
SDL_Surface *b = NULL; MultiSpacc_Surface *b = NULL;
a = IMG_Load ( FilePath );///* a = IMG_Load ( FilePath );///*
if ( a == NULL ) { if ( a == NULL ) {
printf("[E] Error reading image %s.\n", FilePath); printf("[E] Error reading image %s.\n", FilePath);
@@ -22,18 +20,18 @@ SDL_Surface * LoadImage ( char *FilePath, MultiSpacc_Surface *Screen ) {
return b;//*/return a; return b;//*/return a;
} }
void DrawSurf ( int x, int y, SDL_Surface * Src, SDL_Rect * Clip, SDL_Surface * Dst ) { void DrawSurf ( int x, int y, MultiSpacc_Surface * Src, SDL_Rect * Clip, MultiSpacc_Surface * Dst ) {
SDL_Rect Offset; SDL_Rect Offset;
Offset.x = x; Offset.x = x;
Offset.y = y; Offset.y = y;
SDL_BlitSurface( Src, Clip, Dst, &Offset ); SDL_BlitSurface( Src, Clip, Dst, &Offset );
} }
void FillSurfRGB ( int R, int G, int B, SDL_Surface * Dst ) { void FillSurfRGB ( int R, int G, int B, MultiSpacc_Surface * Dst ) {
SDL_FillRect( Dst, &Dst->clip_rect, SDL_MapRGB( Dst->format, R, G, B ) ); SDL_FillRect( Dst, &Dst->clip_rect, SDL_MapRGB( Dst->format, R, G, B ) );
} }
void DrawOutlineRect ( int x, int y, int w, int h, int Size, int R, int G, int B, SDL_Surface * Dst ) { void DrawOutlineRect ( int x, int y, int w, int h, int Size, int R, int G, int B, MultiSpacc_Surface * Dst ) {
SDL_Rect Rect; SDL_Rect Rect;
Rect.x = x; Rect.x = x;
Rect.y = y; Rect.y = y;