diff options
| author | jussi | 2023-11-29 19:52:47 +0200 |
|---|---|---|
| committer | jussi | 2023-11-29 19:52:47 +0200 |
| commit | 8882d2ff2c4c77c08a5c5b0931a70ff906ecbdb5 (patch) | |
| tree | 1ec267213ed205af75fcc02c46f45c05e01fa7bb | |
| parent | 4ff1b1dcb9f52a2642feabda38c8c135aac6c599 (diff) | |
| download | reilua-enhanced-8882d2ff2c4c77c08a5c5b0931a70ff906ecbdb5.tar.gz reilua-enhanced-8882d2ff2c4c77c08a5c5b0931a70ff906ecbdb5.tar.bz2 reilua-enhanced-8882d2ff2c4c77c08a5c5b0931a70ff906ecbdb5.zip | |
Platform web.
| -rw-r--r-- | CMakeLists.txt | 9 | ||||
| -rw-r--r-- | changelog | 1 | ||||
| -rw-r--r-- | include/lua_core.h | 2 | ||||
| -rw-r--r-- | src/core.c | 2 | ||||
| -rw-r--r-- | src/gl.c | 2 | ||||
| -rw-r--r-- | src/lua_core.c | 24 | ||||
| -rw-r--r-- | src/platforms/core_desktop.c | 26 | ||||
| -rw-r--r-- | src/platforms/core_desktop_sdl.c | 26 | ||||
| -rw-r--r-- | src/platforms/core_web.c | 20 |
9 files changed, 79 insertions, 33 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 381c4a8..92a6026 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set( CMAKE_C_STANDARD 99 ) # Requires C99 standard option( SHARED "Build using dynamic libraries." off ) option( LUAJIT "Use LuaJIT." off ) -enum_option( PLATFORM "Desktop;Desktop_SDL" "Platform to build for." ) +enum_option( PLATFORM "Desktop;Desktop_SDL;Web" "Platform to build for." ) if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) @@ -29,16 +29,19 @@ if( PLATFORM STREQUAL "Desktop" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP" ) elseif( PLATFORM STREQUAL "Desktop_SDL" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP_SDL" ) +elseif( PLATFORM STREQUAL "Web" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WEB" ) endif() -if( EMSCRIPTEN ) # Web +if( PLATFORM STREQUAL "Web" ) target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/web/libraylib.a ) target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/web/liblua.a ) # Try "-s USE_PTHREADS" if not getting pixel perfect rendering. set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY" ) + # set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s FORCE_FILESYSTEM=1" ) set( CMAKE_EXECUTABLE_SUFFIX ".html" ) # This line is used to set your executable to build with the emscripten html template so that you can directly open it. - set( resources_dir "resources" ) + set( resources_dir "resources@/" ) # Sets resources as root for the virtual file system. set_target_properties( ${PROJECT_NAME} PROPERTIES LINK_FLAGS "--preload-file ${resources_dir}" ) else() # Desktop if( SHARED ) @@ -15,6 +15,7 @@ KEY CHANGES: - ADDED: SDL Events. - ADDED: Experimental GLFW Pen Touch events. Needs glfw PR https://github.com/glfw/glfw/pull/1445. - ADDED: Platform specific API documentation generation. + - ADDED: Platform web. DETAILED CHANGES: - REMOVED: DrawLineBezierQuad, DrawLineBezierCubic. diff --git a/include/lua_core.h b/include/lua_core.h index 6c81aaa..b1bc016 100644 --- a/include/lua_core.h +++ b/include/lua_core.h @@ -31,6 +31,8 @@ void luaCallProcess(); void luaCallDraw(); void luaCallExit(); void luaRegister(); +void platformDefineGlobals(); +void luaPlatformRegister(); /* Lua get types. */ bool uluaGetBoolean( lua_State *L, int index ); Color uluaGetColor( lua_State *L, int index ); @@ -14,8 +14,8 @@ static int getBufferElementSize( Buffer *buffer ) { case BUFFER_INT: return sizeof( int ); case BUFFER_FLOAT: return sizeof( float ); case BUFFER_DOUBLE: return sizeof( double ); - default: 1; } + return 1; } void unloadBuffer( Buffer *buffer ) { @@ -15,6 +15,7 @@ Copy a block of pixels from one framebuffer object to another. Use -1 RenderTexture for window framebuffer */ int lglBlitFramebuffer( lua_State *L ) { +#if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL ) if ( !( lua_isuserdata( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isuserdata( L, 2 ) || lua_isnil( L, 2 ) ) ) { TraceLog( state->logLevelInvalid, "%s", "Argument needs to be RenderTexture or nil" ); lua_pushnil( L ); @@ -52,4 +53,5 @@ int lglBlitFramebuffer( lua_State *L ) { glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); return 1; +#endif } diff --git a/src/lua_core.c b/src/lua_core.c index a777bc4..56162c1 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -18,6 +18,8 @@ #include "platforms/core_desktop.c" #elif PLATFORM_DESKTOP_SDL #include "platforms/core_desktop_sdl.c" +#elif PLATFORM_WEB + #include "platforms/core_web.c" #endif /* Define types. */ @@ -28,6 +30,7 @@ static int gcBuffer( lua_State *L ) { Buffer *buffer = luaL_checkudata( L, 1, "Buffer" ); unloadBuffer( buffer ); } + return 0; } static void defineBuffer() { @@ -46,6 +49,7 @@ static int gcImage( lua_State *L ) { Image *image = luaL_checkudata( L, 1, "Image" ); UnloadImage( *image ); } + return 0; } static void defineImage() { @@ -64,6 +68,7 @@ static int gcTexture( lua_State *L ) { Texture *texture = luaL_checkudata( L, 1, "Texture" ); UnloadTexture( *texture ); } + return 0; } static void defineTexture() { @@ -83,6 +88,7 @@ static int gcRenderTexture( lua_State *L ) { RenderTexture *renderTexture = luaL_checkudata( L, 1, "RenderTexture" ); UnloadRenderTexture( *renderTexture ); } + return 0; } static void defineRenderTexture() { @@ -119,6 +125,7 @@ static int gcShader( lua_State *L ) { Shader *shader = luaL_checkudata( L, 1, "Shader" ); UnloadShader( *shader ); } + return 0; } static void defineShader() { @@ -137,6 +144,7 @@ static int gcFont( lua_State *L ) { Font *font = luaL_checkudata( L, 1, "Font" ); UnloadFont( *font ); } + return 0; } static void defineFont() { @@ -155,6 +163,7 @@ static int gcWave( lua_State *L ) { Wave *wave = luaL_checkudata( L, 1, "Wave" ); UnloadWave( *wave ); } + return 0; } static void defineWave() { @@ -173,6 +182,7 @@ static int gcSound( lua_State *L ) { Sound *sound = luaL_checkudata( L, 1, "Sound" ); UnloadSound( *sound ); } + return 0; } static void defineSound() { @@ -191,6 +201,7 @@ static int gcMusic( lua_State *L ) { Music *music = luaL_checkudata( L, 1, "Music" ); UnloadMusicStream( *music ); } + return 0; } static void defineMusic() { @@ -219,6 +230,7 @@ static int gcMaterial( lua_State *L ) { /* Custom UnloadMaterial since we don't want to free Shaders or Textures. */ unloadMaterial( material ); } + return 0; } static void defineMaterial() { @@ -237,6 +249,7 @@ static int gcMesh( lua_State *L ) { Mesh *mesh = luaL_checkudata( L, 1, "Mesh" ); UnloadMesh( *mesh ); } + return 0; } static void defineMesh() { @@ -256,6 +269,7 @@ static int gcModel( lua_State *L ) { UnloadModel( *model ); // UnloadModelKeepMeshes( *model ); } + return 0; } static void defineModel() { @@ -274,6 +288,7 @@ static int gcModelAnimation( lua_State *L ) { ModelAnimation *modelAnimation = luaL_checkudata( L, 1, "ModelAnimation" ); UnloadModelAnimation( *modelAnimation ); } + return 0; } static void defineModelAnimation() { @@ -1030,11 +1045,11 @@ bool luaCallMain() { char path[ STRING_LEN ] = { '\0' }; /* If web, set path to resources folder. */ -#ifdef EMSCRIPTEN - snprintf( path, STRING_LEN, "resources/main.lua" ); +#ifdef PLATFORM_WEB + snprintf( path, STRING_LEN, "main.lua" ); /* Alternatively look for main. Could be precompiled binary file. */ if ( !FileExists( path ) ) { - snprintf( path, STRING_LEN, "resources/main" ); + snprintf( path, STRING_LEN, "main" ); } #else snprintf( path, STRING_LEN, "%smain.lua", state->exePath ); @@ -1055,8 +1070,6 @@ bool luaCallMain() { /* Apply custom callback here. */ SetTraceLogCallback( logCustom ); - platformRegisterEvents(); - lua_getglobal( L, "RL" ); lua_getfield( L, -1, "init" ); @@ -1077,6 +1090,7 @@ bool luaCallMain() { } void luaCallProcess() { + #ifdef PLATFORM_DESKTOP_SDL platformSendEvents(); #endif diff --git a/src/platforms/core_desktop.c b/src/platforms/core_desktop.c index 614062d..d2c595e 100644 --- a/src/platforms/core_desktop.c +++ b/src/platforms/core_desktop.c @@ -3,7 +3,7 @@ #include "core.h" #include "platforms/core_desktop.h" -static void platformDefineGlobals() { +void platformDefineGlobals() { lua_State *L = state->luaState; lua_getglobal( L, "RL" ); @@ -87,17 +87,6 @@ int lcoreGetKeyScancode( lua_State *L ) { return 1; } -static void luaPlatformRegister() { - lua_State *L = state->luaState; - lua_getglobal( L, "RL" ); - - /* Input-related functions: keyboard. */ - assingGlobalFunction( "GetKeyName", lcoreGetKeyName ); - assingGlobalFunction( "GetKeyScancode", lcoreGetKeyScancode ); - - lua_pop( L, -1 ); -} - /* Events. */ /* @@ -649,3 +638,16 @@ static void platformRegisterEvents() { // state->glfwtabletCursorCallback = glfwSetPenTabletCursorCallback( penTabletCursorEvent ); // state->glfwtabletProximityCallback = glfwSetPenTabletProximityCallback( penTabletProximityEvent ); } + +void luaPlatformRegister() { + lua_State *L = state->luaState; + lua_getglobal( L, "RL" ); + + /* Input-related functions: keyboard. */ + assingGlobalFunction( "GetKeyName", lcoreGetKeyName ); + assingGlobalFunction( "GetKeyScancode", lcoreGetKeyScancode ); + + lua_pop( L, -1 ); + + platformRegisterEvents(); +} diff --git a/src/platforms/core_desktop_sdl.c b/src/platforms/core_desktop_sdl.c index f1483e5..9ad1c58 100644 --- a/src/platforms/core_desktop_sdl.c +++ b/src/platforms/core_desktop_sdl.c @@ -3,7 +3,7 @@ #include "core.h" #include "platforms/core_desktop_sdl.h" -static void platformDefineGlobals() { +void platformDefineGlobals() { lua_State *L = state->luaState; lua_getglobal( L, "RL" ); @@ -111,17 +111,6 @@ int lcoreGetScancodeFromKey( lua_State *L ) { return 1; } -static void luaPlatformRegister() { - lua_State *L = state->luaState; - lua_getglobal( L, "RL" ); - - /* Input-related functions: keyboard. */ - assingGlobalFunction( "GetKeyName", lcoreGetKeyName ); - assingGlobalFunction( "GetScancodeFromKey", lcoreGetScancodeFromKey ); - - lua_pop( L, -1 ); -} - /* Events. */ /* @@ -555,3 +544,16 @@ Event occurs an event of type SDL_DOLLARGESTURE or SDL_DOLLARRECORD is reported. } state->SDL_eventQueueLen = 0; } + +void luaPlatformRegister() { + lua_State *L = state->luaState; + lua_getglobal( L, "RL" ); + + /* Input-related functions: keyboard. */ + assingGlobalFunction( "GetKeyName", lcoreGetKeyName ); + assingGlobalFunction( "GetScancodeFromKey", lcoreGetScancodeFromKey ); + + lua_pop( L, -1 ); + + platformRegisterEvents() +} diff --git a/src/platforms/core_web.c b/src/platforms/core_web.c new file mode 100644 index 0000000..24d3bf2 --- /dev/null +++ b/src/platforms/core_web.c @@ -0,0 +1,20 @@ +#include "main.h" +#include "lua_core.h" +#include "core.h" + +void platformDefineGlobals() { + lua_State *L = state->luaState; + + lua_getglobal( L, "RL" ); +/*DOC_DEFINES_START*/ +/*DOC_DEFINES_END*/ + lua_pop( L, -1 ); +} + +/* Functions. */ + +/* Events. */ + +void luaPlatformRegister() { + return; +} |
