Skip to content

Commit

Permalink
#1264: net.c moved back to studio
Browse files Browse the repository at this point in the history
  • Loading branch information
nesbox committed Jan 18, 2021
1 parent e9b9b40 commit cfd26b0
Show file tree
Hide file tree
Showing 19 changed files with 380 additions and 525 deletions.
92 changes: 41 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,37 @@ target_include_directories(wave_writer INTERFACE ${THIRDPARTY_DIR}/blip-buf)
add_library(argparse STATIC ${THIRDPARTY_DIR}/argparse/argparse.c)
target_include_directories(argparse INTERFACE ${THIRDPARTY_DIR}/argparse)

################################
# CURL
################################

if (NOT N3DS AND NOT EMSCRIPTEN AND NOT BAREMETALPI)

set(BUILD_SHARED_LIBS OFF CACHE BOOL "")

if(WIN32)
set(CURL_STATIC_CRT ON CACHE BOOL "")
endif()

set(CMAKE_USE_OPENSSL OFF CACHE BOOL "" )
set(CMAKE_USE_LIBSSH2 OFF CACHE BOOL "")
set(HTTP_ONLY ON CACHE BOOL "")
set(BUILD_CURL_EXE OFF CACHE BOOL "")
set(CURL_CA_BUNDLE "none" CACHE STRING "")
set(CURL_CA_PATH "none" CACHE STRING "")

if(RPI)
set(CURL_ZLIB OFF CACHE BOOL "" )
endif()

add_subdirectory(${THIRDPARTY_DIR}/curl)

if(RPI)
target_compile_definitions(libcurl PRIVATE NOT_USE_FILE_OFFSET64)
endif()

endif()

################################
# TIC-80 studio
################################
Expand All @@ -581,6 +612,7 @@ set(TIC80STUDIO_SRC
${TIC80LIB_DIR}/studio/config.c
${TIC80LIB_DIR}/studio/project.c
${TIC80LIB_DIR}/studio/fs.c
${TIC80LIB_DIR}/studio/net.c
${TIC80LIB_DIR}/ext/md5.c
${TIC80LIB_DIR}/ext/gif.c
${TIC80LIB_DIR}/ext/history.c
Expand All @@ -598,6 +630,13 @@ target_include_directories(tic80studio PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(tic80studio tic80core zip wave_writer argparse)

if(EMSCRIPTEN)
elseif(N3DS)
target_compile_definitions(tic80studio PRIVATE ENABLE_HTTPC)
else()
target_link_libraries(tic80studio libcurl)
endif()

if(BUILD_PRO)
target_compile_definitions(tic80studio PRIVATE TIC80_PRO)
endif()
Expand Down Expand Up @@ -680,52 +719,6 @@ endif()

endif()

################################
# CURL
################################

if (NOT N3DS AND NOT EMSCRIPTEN AND NOT BAREMETALPI)

set(BUILD_SHARED_LIBS OFF CACHE BOOL "")

if(WIN32)
set(CURL_STATIC_CRT ON CACHE BOOL "")
endif()

set(CMAKE_USE_OPENSSL OFF CACHE BOOL "" )
set(CMAKE_USE_LIBSSH2 OFF CACHE BOOL "")
set(HTTP_ONLY ON CACHE BOOL "")
set(BUILD_CURL_EXE OFF CACHE BOOL "")
set(CURL_CA_BUNDLE "none" CACHE STRING "")
set(CURL_CA_PATH "none" CACHE STRING "")

if(RPI)
set(CURL_ZLIB OFF CACHE BOOL "" )
endif()

add_subdirectory(${THIRDPARTY_DIR}/curl)

if(RPI)
target_compile_definitions(libcurl PRIVATE NOT_USE_FILE_OFFSET64)
endif()

endif()

################################
# Network library
################################

if (NOT N3DS)
add_library(net STATIC ${CMAKE_SOURCE_DIR}/src/system/net/net.c)
target_include_directories(net
PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/include
INTERFACE ${CMAKE_SOURCE_DIR}/src/system)

if(NOT EMSCRIPTEN)
target_link_libraries(net libcurl)
endif()
endif()

################################
# TIC-80 app
################################
Expand Down Expand Up @@ -770,7 +763,7 @@ if(BUILD_SDL)
target_link_libraries(tic80 SDL2main)
endif()

target_link_libraries(tic80 tic80studio net)
target_link_libraries(tic80 tic80studio)

if(BUILD_TOUCH_INPUT)
target_compile_definitions(tic80 PRIVATE TOUCH_INPUT_SUPPORT)
Expand Down Expand Up @@ -836,7 +829,7 @@ if(BUILD_SOKOL)
target_link_options(tic80-sokol PRIVATE -static -mconsole)
endif()

target_link_libraries(tic80-sokol tic80studio sokol net)
target_link_libraries(tic80-sokol tic80studio sokol)

endif()

Expand All @@ -848,14 +841,11 @@ if(N3DS)
set(TIC80_SRC ${TIC80_SRC}
${CMAKE_SOURCE_DIR}/src/system/n3ds/utils.c
${CMAKE_SOURCE_DIR}/src/system/n3ds/keyboard.c
${CMAKE_SOURCE_DIR}/src/system/n3ds/net_httpc.c
${CMAKE_SOURCE_DIR}/src/system/n3ds/main.c
)

add_executable(tic80_n3ds ${TIC80_SRC})

target_compile_definitions(tic80_n3ds PRIVATE ENABLE_HTTPC)

target_include_directories(tic80_n3ds PRIVATE
${DEVKITPRO}/portlibs/3ds/include
${CMAKE_SOURCE_DIR}/include
Expand Down
3 changes: 2 additions & 1 deletion src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define CLAMP(v,a,b) (MIN(MAX(v,a),b))
#define SWAP(a, b, type) do { type temp = a; a = b; b = temp; } while (0)
#define ZEROMEM(p) memset(&p, 0, sizeof p)
#define ZEROMEM(p) memset(&p, 0, sizeof p)
#define OBJCOPY(...) memcpy(malloc(sizeof __VA_ARGS__), &__VA_ARGS__, sizeof __VA_ARGS__)
14 changes: 9 additions & 5 deletions src/studio/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "studio.h"
#include "fs.h"
#include "net.h"

#if defined(BAREMETALPI) || defined(_3DS)
#ifdef EN_DEBUG
Expand Down Expand Up @@ -66,6 +67,7 @@ struct FileSystem
{
char dir[TICNAME_MAX];
char work[TICNAME_MAX];
Net* net;
};

#if defined(__EMSCRIPTEN__)
Expand Down Expand Up @@ -316,13 +318,13 @@ static void onDirResponse(u8* buffer, s32 size, void* data)
}
}

static void netDirRequest(const char* path, ListCallback callback, void* data)
static void netDirRequest(Net* net, const char* path, ListCallback callback, void* data)
{
char request[TICNAME_MAX] = {'\0'};
sprintf(request, "/api?fn=dir&path=%s", path);

s32 size = 0;
void* buffer = getSystem()->httpGetSync(request, &size);
void* buffer = netGetSync(net, request, &size);

NetDirData netDirData = {callback, data};
onDirResponse(buffer, size, &netDirData);
Expand Down Expand Up @@ -414,7 +416,7 @@ void fsEnumFiles(FileSystem* fs, ListCallback callback, void* data)

if(isPublic(fs))
{
netDirRequest(fs->work + sizeof(TIC_HOST), callback, data);
netDirRequest(fs->net, fs->work + sizeof(TIC_HOST), callback, data);
return;
}

Expand Down Expand Up @@ -892,7 +894,7 @@ void* fsLoadFileByHash(FileSystem* fs, const char* hash, s32* size)

char path[TICNAME_MAX] = {0};
sprintf(path, "/cart/%s/cart.tic", hash);
void* data = getSystem()->httpGetSync(path, size);
void* data = netGetSync(fs->net, path, size);

if(data)
fsSaveRootFile(fs, cachePath, data, *size, false);
Expand Down Expand Up @@ -1018,7 +1020,7 @@ void fsOpenWorkingFolder(FileSystem* fs)
getSystem()->openSystemPath(path);
}

FileSystem* createFileSystem(const char* path)
FileSystem* createFileSystem(const char* path, Net* net)
{
FileSystem* fs = (FileSystem*)calloc(1, sizeof(FileSystem));

Expand All @@ -1027,5 +1029,7 @@ FileSystem* createFileSystem(const char* path)
if(path[strlen(path) - 1] != SEP[0])
strcat(fs->dir, SEP);

fs->net = net;

return fs;
}
3 changes: 2 additions & 1 deletion src/studio/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
typedef bool(*ListCallback)(const char* name, const char* info, s32 id, void* data, bool dir);

typedef struct FileSystem FileSystem;
struct Net;

FileSystem* createFileSystem(const char* path);
FileSystem* createFileSystem(const char* path, struct Net* net);

void fsEnumFiles(FileSystem* fs, ListCallback callback, void* data);
bool fsDeleteFile(FileSystem* fs, const char* name);
Expand Down
Loading

0 comments on commit cfd26b0

Please sign in to comment.