Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patches/* -text
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/build/
/build-*/
/build-SimpleGraphic
/.idea
/.idea
132 changes: 120 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ set(SIMPLEGRAPHIC_SOURCES

set (SIMPLEGRAPHIC_PLATFORM_SOURCES)
if (APPLE)
set (SIMPLEGRAPHIC_PLATFORM_SOURCES
list (APPEND SIMPLEGRAPHIC_PLATFORM_SOURCES
"engine/system/win/sys_macos.mm"
)
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 @@ -131,6 +131,12 @@ find_package(zstd REQUIRED)
find_package(ZLIB REQUIRED)
find_package(WebP)

if (TARGET zstd::libzstd_shared)
set(ZSTD_LIBRARY zstd::libzstd_shared)
else ()
set(ZSTD_LIBRARY zstd::libzstd_static)
endif ()

add_library(cmp_core STATIC
dep/compressonator/cmp_core/source/cmp_core.cpp
dep/compressonator/cmp_core/source/cmp_core.h
Expand Down Expand Up @@ -240,9 +246,17 @@ target_link_libraries(SimpleGraphic
Threads::Threads
WebP::webpdecoder
ZLIB::ZLIB
zstd::libzstd_shared
${ZSTD_LIBRARY}
)

if (APPLE)
set_target_properties(SimpleGraphic PROPERTIES
BUILD_WITH_INSTALL_NAME_DIR TRUE
INSTALL_NAME_DIR "@rpath"
MACOSX_RPATH TRUE
)
endif ()

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

Expand Down Expand Up @@ -276,10 +290,25 @@ if (WIN32)
)
endif ()

if (APPLE)
find_program(PATCH_EXECUTABLE patch REQUIRED)
set(LCURL_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/Lua-cURLv3)
file(REMOVE_RECURSE ${LCURL_SOURCE_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/libs/Lua-cURLv3/src
DESTINATION ${LCURL_SOURCE_DIR})
execute_process(
COMMAND ${PATCH_EXECUTABLE} -l -p1 -i
${CMAKE_CURRENT_SOURCE_DIR}/patches/Lua-cURLv3-skip-luaL_setfuncs-on-luajit.patch
WORKING_DIRECTORY ${LCURL_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
else ()
set(LCURL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/Lua-cURLv3)
endif ()


# lcurl module

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})

Expand All @@ -301,10 +330,14 @@ install(FILES $<TARGET_RUNTIME_DLLS:lcurl> DESTINATION ".")

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
)
elseif (APPLE)
target_compile_options(lua-utf8 PRIVATE -include limits.h)
endif ()

target_include_directories(lua-utf8
PRIVATE
Expand Down Expand Up @@ -333,9 +366,14 @@ add_library(luasocket SHARED
"libs/luasocket/src/tcp.c"
"libs/luasocket/src/timeout.c"
"libs/luasocket/src/udp.c"
"libs/luasocket/src/wsocket.c"
)

if (WIN32)
target_sources(luasocket PRIVATE "libs/luasocket/src/wsocket.c")
else ()
target_sources(luasocket PRIVATE "libs/luasocket/src/usocket.c")
endif ()

target_include_directories(luasocket
PRIVATE
${LSOCKET_SOURCE_DIR}/src
Expand All @@ -344,10 +382,12 @@ target_include_directories(luasocket
target_link_libraries(luasocket
PRIVATE
LuaJIT::LuaJIT
wsock32
ws2_32
)

if (WIN32)
target_link_libraries(luasocket PRIVATE wsock32 ws2_32)
endif ()

set_target_properties( luasocket PROPERTIES OUTPUT_NAME "socket" )
install(TARGETS luasocket RUNTIME DESTINATION ".")
install(FILES $<TARGET_RUNTIME_DLLS:luasocket> DESTINATION ".")
Expand All @@ -368,3 +408,71 @@ target_link_libraries(lzip

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

if (APPLE)
set_target_properties(lcurl lua-utf8 luasocket lzip PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "@loader_path/../Frameworks"
PREFIX ""
SUFFIX ".so"
)

set_source_files_properties(macos/smoke/Launch.lua PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
add_executable(SimpleGraphicSmoke MACOSX_BUNDLE
macos/launcher.c
macos/smoke/Launch.lua
)
target_link_libraries(SimpleGraphicSmoke PRIVATE SimpleGraphic)
add_dependencies(SimpleGraphicSmoke lcurl lua-utf8 luasocket lzip)
set_property(TARGET SimpleGraphicSmoke APPEND PROPERTY LINK_DEPENDS
"$<TARGET_FILE:lcurl>"
"$<TARGET_FILE:lua-utf8>"
"$<TARGET_FILE:luasocket>"
"$<TARGET_FILE:lzip>"
)
set_target_properties(SimpleGraphicSmoke PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "@executable_path/../Frameworks"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/macos/Info.plist.in"
MACOSX_BUNDLE_BUNDLE_NAME "SimpleGraphicSmoke"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.pathofbuilding.simplegraphic.smoke"
)

add_custom_command(TARGET SimpleGraphicSmoke POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Frameworks"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Resources/lcurl"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Resources/socket"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:SimpleGraphic>"
"$<TARGET_FILE:unofficial::angle::libEGL>"
"$<TARGET_FILE:unofficial::angle::libGLESv2>"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Frameworks"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:unofficial::angle::libEGL>"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Frameworks/libEGL.dylib"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:unofficial::angle::libGLESv2>"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Frameworks/libGLESv2.dylib"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:lcurl>"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Resources/lcurl.so"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:lcurl>"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Resources/lcurl/safe.so"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:lua-utf8>"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Resources/lua-utf8.so"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:luasocket>"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Resources/socket/core.so"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:lzip>"
"$<TARGET_FILE_DIR:SimpleGraphicSmoke>/../Resources/lzip.so"
COMMAND /usr/bin/codesign --force --deep --sign -
"$<TARGET_BUNDLE_DIR:SimpleGraphicSmoke>"
VERBATIM
)
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.0 luajit-2.1
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
4 changes: 2 additions & 2 deletions engine/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ char* NarrowUTF8String(const wchar_t* str)
return NarrowCodepageString(str, CP_UTF8);
}

#endif

IndexedUTF32String IndexUTF8ToUTF32(std::string_view input)
{
IndexedUTF32String ret{};
Expand Down Expand Up @@ -500,5 +502,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_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ r_font_c::FontHeightEntry r_font_c::FindFontHeight(int height) {
void r_font_c::DrawTextLine(scp_t pos, int align, int height, col4_t col, std::u32string_view str)
{
// Check if the line is visible
if (pos[Y] >= renderer->sys->video->vid.size[1] || pos[Y] <= -height) {
if (pos[Y] >= renderer->VirtualScreenHeight() || pos[Y] <= -height) {
// Just process the colour codes
while (!str.empty()) {
// Check for escape character
Expand Down
4 changes: 3 additions & 1 deletion engine/render/r_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <algorithm>
#include <array>
#include <chrono>
#include <thread>
#include <filesystem>
#include <fmt/chrono.h>
#include <future>
Expand Down Expand Up @@ -1640,7 +1642,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);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
width = hnd->sh->tex->fileWidth;
height = hnd->sh->tex->fileHeight;
Expand Down
5 changes: 3 additions & 2 deletions engine/render/r_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <mutex>
#include <vector>
#include <atomic>
#include <thread>
#include "r_local.h"

#include "cmp_core.h"
Expand Down Expand Up @@ -504,7 +505,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 +525,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
25 changes: 18 additions & 7 deletions engine/system/win/sys_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,13 @@ std::filesystem::path FindBasePath()
progPath = basePath;
#endif
progPath = weakly_canonical(progPath);
return progPath.parent_path();
auto dirPath = progPath.parent_path();
#if __APPLE__ && __MACH__
if (dirPath.filename() == "MacOS" && dirPath.parent_path().filename() == "Contents") {
dirPath = dirPath.parent_path() / "Resources";
}
#endif
return dirPath;
}

std::tuple<std::optional<std::filesystem::path>, std::optional<std::string>> FindUserPath()
Expand Down Expand Up @@ -609,11 +615,7 @@ std::tuple<std::optional<std::filesystem::path>, std::optional<std::string>> Fin
sys_main_c::sys_main_c()
: heldKeyState(KEY_SCROLL + 1, (uint8_t)0)
{
#ifdef _WIN64
x64 = true;
#else
x64 = false;
#endif
x64 = sizeof(void*) == 8;
#ifdef _DEBUG
debug = true;
#else
Expand Down Expand Up @@ -650,7 +652,12 @@ bool sys_main_c::Run(int argc, char** argv)
core = core_IMain::GetHandle(this);

// Print some handy information
con->Printf(CFG_VERSION" %s %s, built " __DATE__ "\n", x64? "x64":"x86", debug? "Debug":"Release");
#if defined(__aarch64__) || defined(_M_ARM64)
const char* architecture = "arm64";
#else
const char* architecture = x64 ? "x64" : "x86";
#endif
con->Printf(CFG_VERSION" %s %s, built " __DATE__ "\n", architecture, debug? "Debug":"Release");
if (debuggerRunning) {
con->Printf("Debugger is present.\n");
}
Expand Down Expand Up @@ -715,17 +722,21 @@ bool sys_main_c::Run(int argc, char** argv)
#endif

if (exitMsg) {
#ifdef _WIN32
exitFlag = false;
#endif
video->SetVisible(false);
conWin->SetVisible(true);
if (exitMsg) {
con->Printf("\n%s", exitMsg);
FreeString(exitMsg);
exitMsg = NULL;
}
#ifdef _WIN32
while (exitFlag == false) {
Sleep(50);
}
#endif
}

initialised = false;
Expand Down
Loading