Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 104 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ endif ()

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

if (APPLE)
set(VCPKG_OVERLAY_TRIPLETS "${PROJECT_SOURCE_DIR}/triplets")
endif ()

include(${PROJECT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)

set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".")
Expand Down Expand Up @@ -84,12 +88,12 @@ if (APPLE)
endif()

if (WIN32)
set (SIMPLEGRAPHIC_PLATFORM_SOURCES
list(APPEND SIMPLEGRAPHIC_PLATFORM_SOURCES
"engine/system/win/sys_console.cpp"
"SimpleGraphic.rc"
)
else()
set (SIMPLEGRAPHIC_PLATFORM_SOURCES
list(APPEND SIMPLEGRAPHIC_PLATFORM_SOURCES
"engine/system/win/sys_console_unix.cpp"
)
endif()
Expand Down Expand Up @@ -222,6 +226,41 @@ if (APPLE)
${CORE_FOUNDATION_LIBRARY}
${APPLICATION_SERVICES_LIBRARY}
)
set_target_properties(SimpleGraphic PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "@loader_path"
)
file(GLOB ANGLE_DYLIBS
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/*EGL*.dylib"
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/*GLESv2*.dylib")
set(ANGLE_EGL_NAME "")
set(ANGLE_GLES_NAME "")
foreach (angle_dylib IN LISTS ANGLE_DYLIBS)
get_filename_component(angle_dylib_name "${angle_dylib}" NAME)
if (angle_dylib_name MATCHES "EGL")
set(ANGLE_EGL_NAME "${angle_dylib_name}")
elseif (angle_dylib_name MATCHES "GLESv2")
set(ANGLE_GLES_NAME "${angle_dylib_name}")
endif ()
endforeach ()
if (NOT ANGLE_EGL_NAME OR NOT ANGLE_GLES_NAME)
message(FATAL_ERROR "Shared ANGLE dylibs not found in ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib (got: '${ANGLE_DYLIBS}'); expected dynamic ANGLE via triplets/arm64-osx.cmake")
endif ()
install(FILES ${ANGLE_DYLIBS} DESTINATION ".")
# GLFW loads EGL at runtime by these canonical names (egl_context.c), so
# alias the ANGLE dylibs, whose install names stay @rpath-based.
install(CODE "
file(REMOVE \"\${CMAKE_INSTALL_PREFIX}/libEGL.dylib\" \"\${CMAKE_INSTALL_PREFIX}/libGLESv2.dylib\")
file(CREATE_LINK ${ANGLE_EGL_NAME} \"\${CMAKE_INSTALL_PREFIX}/libEGL.dylib\" SYMBOLIC)
file(CREATE_LINK ${ANGLE_GLES_NAME} \"\${CMAKE_INSTALL_PREFIX}/libGLESv2.dylib\" SYMBOLIC)
")
endif ()

# Static triplets (e.g. arm64-osx) only provide the static zstd target
if (TARGET zstd::libzstd_shared)
set(ZSTD_TARGET zstd::libzstd_shared)
else ()
set(ZSTD_TARGET zstd::libzstd)
endif ()

target_link_libraries(SimpleGraphic
Expand All @@ -240,11 +279,11 @@ target_link_libraries(SimpleGraphic
Threads::Threads
WebP::webpdecoder
ZLIB::ZLIB
zstd::libzstd_shared
${ZSTD_TARGET}
)

install(FILES $<TARGET_RUNTIME_DLLS:SimpleGraphic> DESTINATION ".")
install(TARGETS SimpleGraphic RUNTIME DESTINATION ".")
install(TARGETS SimpleGraphic RUNTIME DESTINATION "." LIBRARY DESTINATION ".")

if (WIN32)
set(DEPS_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}")
Expand Down Expand Up @@ -283,6 +322,18 @@ set(LCURL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/Lua-cURLv3)
file(GLOB LCURL_SOURCES ${LCURL_SOURCE_DIR}/src/**.c)
add_library(lcurl SHARED ${LCURL_SOURCES})

if (NOT WIN32)
# When linking LuaJIT statically, Lua-cURLv3's local Lua 5.2-compat
# luaL_setfuncs shim collides with the one LuaJIT itself exports.
# Rename the local shim (and its internal callers) instead of patching
# the submodule; drop once https://github.com/Lua-cURL/Lua-cURLv3/pull/197
# is merged and the submodule is bumped.
target_compile_definitions(lcurl
PRIVATE
"luaL_setfuncs=lcurl_compat_setfuncs"
)
endif ()

target_include_directories(lcurl
PRIVATE
${LCURL_SOURCE_DIR}/src
Expand All @@ -294,17 +345,28 @@ target_link_libraries(lcurl
LuaJIT::LuaJIT
)

install(TARGETS lcurl RUNTIME DESTINATION ".")
install(TARGETS lcurl RUNTIME DESTINATION "." LIBRARY DESTINATION ".")
install(FILES $<TARGET_RUNTIME_DLLS:lcurl> DESTINATION ".")

# luautf8 module

add_library(lua-utf8 SHARED libs/luautf8/lutf8lib.c)

target_compile_definitions(lua-utf8
PRIVATE
LUA_BUILD_AS_DLL
)
if (WIN32)
target_compile_definitions(lua-utf8
PRIVATE
LUA_BUILD_AS_DLL
)
else ()
# lutf8lib.c uses INT_MAX without including <limits.h>; force-include it
# instead of patching the submodule; drop once
# https://github.com/starwing/luautf8/pull/62 is merged and the submodule
# is bumped.
target_compile_options(lua-utf8
PRIVATE
-include limits.h
)
endif ()

target_include_directories(lua-utf8
PRIVATE
Expand All @@ -315,11 +377,17 @@ target_link_libraries(lua-utf8
LuaJIT::LuaJIT
)

install(TARGETS lua-utf8 RUNTIME DESTINATION ".")
install(TARGETS lua-utf8 RUNTIME DESTINATION "." LIBRARY DESTINATION ".")
install(FILES $<TARGET_RUNTIME_DLLS:lua-utf8> DESTINATION ".")

# luasocket module

if (WIN32)
set(LUASOCKET_PLATFORM_SOURCES "libs/luasocket/src/wsocket.c")
else ()
set(LUASOCKET_PLATFORM_SOURCES "libs/luasocket/src/usocket.c")
endif ()

add_library(luasocket SHARED
"libs/luasocket/src/auxiliar.c"
"libs/luasocket/src/buffer.c"
Expand All @@ -333,7 +401,7 @@ add_library(luasocket SHARED
"libs/luasocket/src/tcp.c"
"libs/luasocket/src/timeout.c"
"libs/luasocket/src/udp.c"
"libs/luasocket/src/wsocket.c"
${LUASOCKET_PLATFORM_SOURCES}
)

target_include_directories(luasocket
Expand All @@ -344,12 +412,14 @@ target_include_directories(luasocket
target_link_libraries(luasocket
PRIVATE
LuaJIT::LuaJIT
wsock32
ws2_32
)

set_target_properties( luasocket PROPERTIES OUTPUT_NAME "socket" )
install(TARGETS luasocket RUNTIME DESTINATION ".")
if (WIN32)
target_link_libraries(luasocket PRIVATE wsock32 ws2_32)
endif ()

set_target_properties( luasocket PROPERTIES OUTPUT_NAME "socket" )
install(TARGETS luasocket RUNTIME DESTINATION "." LIBRARY DESTINATION ".")
install(FILES $<TARGET_RUNTIME_DLLS:luasocket> DESTINATION ".")

# lzip module
Expand All @@ -366,5 +436,23 @@ target_link_libraries(lzip
ZLIB::ZLIB
)

install(TARGETS lzip RUNTIME DESTINATION ".")
install(TARGETS lzip RUNTIME DESTINATION "." LIBRARY DESTINATION ".")
install(FILES $<TARGET_RUNTIME_DLLS:lzip> DESTINATION ".")

if (NOT WIN32)
set_target_properties(lcurl lua-utf8 luasocket lzip PROPERTIES PREFIX "" SUFFIX ".so")
endif ()

# macOS launcher (counterpart of the Windows frontend executable)
if (APPLE)
add_executable(pob macos/main.mm)
target_link_libraries(pob PRIVATE SimpleGraphic "-framework Foundation" "-framework CoreServices")
if (DEFINED POB_DEFAULT_SCRIPT)
target_compile_definitions(pob PRIVATE "POB_DEFAULT_SCRIPT=\"${POB_DEFAULT_SCRIPT}\"")
endif ()
set_target_properties(pob PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "@executable_path"
)
install(TARGETS pob RUNTIME DESTINATION ".")
endif ()
6 changes: 3 additions & 3 deletions cmake/FindLuaJIT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ if (DEFINED VCPKG_INSTALLED_DIR AND DEFINED VCPKG_TARGET_TRIPLET)

find_path(LuaJIT_INCLUDE_DIR luajit.h
PATHS ${LuaJIT_SEARCH_ROOT}/include
PATH_SUFFIXES luajit
PATH_SUFFIXES luajit luajit-2.1 luajit-2.0
NO_DEFAULT_PATH)

find_library(LuaJIT_LIBRARY_RELEASE NAMES lua51
find_library(LuaJIT_LIBRARY_RELEASE NAMES lua51 luajit-5.1
PATHS ${LuaJIT_SEARCH_ROOT}
PATH_SUFFIXES lib
NO_DEFAULT_PATH)

find_library(LuaJIT_LIBRARY_DEBUG NAMES lua51
find_library(LuaJIT_LIBRARY_DEBUG NAMES lua51 luajit-5.1
PATHS ${LuaJIT_SEARCH_ROOT}
PATH_SUFFIXES debug/lib
NO_DEFAULT_PATH)
Expand Down
1 change: 1 addition & 0 deletions engine/common/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "base64.h"

#include <stdlib.h>
#include <string.h>

/* ---- Base64 Encoding/Decoding Table --- */
/* Padding character string starts at offset 64. */
Expand Down
1 change: 1 addition & 0 deletions engine/common/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// Modified for standalone inclusion in SimpleGraphic.

#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
Expand Down
10 changes: 8 additions & 2 deletions engine/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "common.h"

#include <cstdint>

// ===================
// Argument List Class
// ===================
Expand Down Expand Up @@ -437,6 +439,12 @@ char* NarrowUTF8String(const wchar_t* str)
return NarrowCodepageString(str, CP_UTF8);
}

#endif

// IndexUTF8ToUTF32 has no platform-specific dependencies (pure UTF-8 decoding);
// it was previously nested inside the #ifdef _WIN32 block above, which left it
// undefined (and unlinkable) on non-Windows platforms despite being called from
// cross-platform code (r_main.cpp, r_font.cpp, sys_console.cpp).
IndexedUTF32String IndexUTF8ToUTF32(std::string_view input)
{
IndexedUTF32String ret{};
Expand Down Expand Up @@ -500,5 +508,3 @@ IndexedUTF32String IndexUTF8ToUTF32(std::string_view input)
ret.text = std::u32string(codepoints.begin(), codepoints.end());
return ret;
}

#endif
2 changes: 1 addition & 1 deletion engine/render/r_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ void r_renderer_c::GetShaderImageSize(r_shaderHnd_c* hnd, int& width, int& heigh
if (hnd)
{
while (hnd->sh->tex->status < r_tex_c::SIZE_KNOWN) {
Sleep(1);
sys->Sleep(1);
}
width = hnd->sh->tex->fileWidth;
height = hnd->sh->tex->fileHeight;
Expand Down
6 changes: 4 additions & 2 deletions engine/render/r_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
// Module: Render Texture
//

#include <algorithm>
#include <mutex>
#include <vector>
#include <atomic>
#include <thread>
#include "r_local.h"

#include "cmp_core.h"
Expand Down Expand Up @@ -504,7 +506,7 @@ static gli::texture2d_array TranscodeTexture(gli::texture2d_array src, gli::form

for (size_t blockRow = 0; blockRow < srcBlocksPerRow; ++blockRow) {
const size_t rowBase = blockRow * srcBlockSize.y;
const size_t rowsLeft = (std::min)(4ull, dstExtent.y - rowBase);
const size_t rowsLeft = (std::min)(size_t(4), dstExtent.y - rowBase);

for (size_t blockCol = 0; blockCol < srcBlocksPerColumn; ++blockCol) {
// Read source 4x4 texel block, no branching needed.
Expand All @@ -524,7 +526,7 @@ static gli::texture2d_array TranscodeTexture(gli::texture2d_array src, gli::form

// Here we work off that dstData points at the top left pixel of the block row in the destination.
const size_t colBase = blockCol * srcBlockSize.x;
const size_t colsLeft = (std::min)(4ull, dstExtent.x - colBase);
const size_t colsLeft = (std::min)(size_t(4), dstExtent.x - colBase);
const size_t colBytesLeft = colsLeft * 4;
for (size_t innerRow = 0; innerRow < rowsLeft; ++innerRow) {
auto* dstPtr = dstData + dstRowStride * innerRow + colBase * 4;
Expand Down
16 changes: 12 additions & 4 deletions engine/system/win/sys_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ sys_video_c::sys_video_c(sys_IMain* sysHnd)
platformType = GLFW_ANGLE_PLATFORM_TYPE_D3D11;
else // Native Windows
platformType = GLFW_ANGLE_PLATFORM_TYPE_D3D11;
#elif defined(__APPLE__)
platformType = GLFW_ANGLE_PLATFORM_TYPE_METAL;
#endif
glfwInitHint(GLFW_ANGLE_PLATFORM_TYPE, platformType);
glfwInit();
Expand Down Expand Up @@ -489,7 +491,9 @@ int sys_video_c::Apply(sys_vidSet_s* set)
return;
}
auto video = (sys_video_c*)sys->video;
video->lastCursorPos = CursorPos{ (int)x, (int)y };
double sx = video->vid.size[0] > 0 ? (double)video->vid.fbSize[0] / video->vid.size[0] : 1.0;
double sy = video->vid.size[1] > 0 ? (double)video->vid.fbSize[1] / video->vid.size[1] : 1.0;
video->lastCursorPos = CursorPos{ (int)(x * sx), (int)(y * sy) };
});
glfwSetWindowCloseCallback(wnd, [](GLFWwindow* wnd) {
auto sys = (sys_main_c*)glfwGetWindowUserPointer(wnd);
Expand Down Expand Up @@ -737,14 +741,18 @@ void sys_video_c::GetRelativeCursor(int& x, int& y)
if (!initialised) return;
double xpos, ypos;
glfwGetCursorPos(wnd, &xpos, &ypos);
x = (int)floor(xpos);
y = (int)floor(ypos);
double sx = vid.size[0] > 0 ? (double)vid.fbSize[0] / vid.size[0] : 1.0;
double sy = vid.size[1] > 0 ? (double)vid.fbSize[1] / vid.size[1] : 1.0;
x = (int)floor(xpos * sx);
y = (int)floor(ypos * sy);
}

void sys_video_c::SetRelativeCursor(int x, int y)
{
if (!initialised) return;
glfwSetCursorPos(wnd, (double)x, (double)y);
double sx = vid.fbSize[0] > 0 ? (double)vid.size[0] / vid.fbSize[0] : 1.0;
double sy = vid.fbSize[1] > 0 ? (double)vid.size[1] / vid.fbSize[1] : 1.0;
glfwSetCursorPos(wnd, x * sx, y * sy);
}

bool sys_video_c::IsCursorOverWindow()
Expand Down
Loading