Skip to content

Commit

Permalink
#1264: network functions moved to system folder
Browse files Browse the repository at this point in the history
  • Loading branch information
nesbox committed Dec 7, 2020
1 parent cf2ce87 commit a90f143
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 164 deletions.
107 changes: 49 additions & 58 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,11 @@ message("BUILD_TOUCH_INPUT: ${BUILD_TOUCH_INPUT}")

if (N3DS)
set(BUILD_SDL off)
# disable CURL linking - use HTTPC instead
set(DISABLE_NETWORKING TRUE)
endif()

if (BAREMETALPI)
set(BUILD_SDL OFF)
set(BUILD_DEMO_CARTS OFF)
set(DISABLE_NETWORKING TRUE)
endif()

if (DISABLE_NETWORKING)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDISABLE_NETWORKING")
endif()

if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID AND NOT N3DS)
Expand Down Expand Up @@ -465,41 +458,6 @@ if(BUILD_LIBRETRO)
set_target_properties(tic80_libretro PROPERTIES PREFIX "")
endif()

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

if (NOT DISABLE_NETWORKING)

if (NOT N3DS AND NOT EMSCRIPTEN)

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

endif()

################################
# ZLIB
################################
Expand Down Expand Up @@ -623,7 +581,6 @@ set(TIC80STUDIO_SRC
${TIC80LIB_DIR}/ext/md5.c
${TIC80LIB_DIR}/ext/gif.c
${TIC80LIB_DIR}/ext/history.c
${TIC80LIB_DIR}/ext/net.c
)

set(TIC80_OUTPUT tic80)
Expand All @@ -643,14 +600,6 @@ if(N3DS)
target_link_directories(tic80studio PUBLIC ${DEVKITPRO}/portlibs/3ds/lib)
endif()

if(NOT DISABLE_NETWORKING)
if(N3DS)
target_link_libraries(tic80studio curl mbedtls mbedx509 mbedcrypto)
elseif(NOT EMSCRIPTEN)
target_link_libraries(tic80studio libcurl)
endif()
endif()

if(BUILD_PRO)
target_compile_definitions(tic80studio PRIVATE TIC80_PRO)
endif()
Expand Down Expand Up @@ -737,6 +686,50 @@ if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "-static")
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
################################

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

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

target_link_libraries(tic80 tic80studio)
target_link_libraries(tic80 tic80studio net)

if(BUILD_TOUCH_INPUT)
target_compile_definitions(tic80 PRIVATE TOUCH_INPUT_SUPPORT)
Expand Down Expand Up @@ -851,7 +844,7 @@ if(BUILD_SOKOL)
target_link_libraries(tic80-sokol mingw32)
endif()

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

endif()

Expand All @@ -867,19 +860,17 @@ if(N3DS)
${CMAKE_SOURCE_DIR}/src/system/n3ds/main.c
)

if (DISABLE_NETWORKING)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_HTTPC")
endif()

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
${CMAKE_SOURCE_DIR}/src)

target_link_directories(tic80_n3ds PRIVATE ${DEVKITPRO}/libctru/lib)
target_link_libraries(tic80_n3ds tic80studio png citro3d)
target_link_libraries(tic80_n3ds tic80studio png citro3d curl mbedtls mbedx509 mbedcrypto)

add_custom_command(TARGET tic80_n3ds
POST_BUILD
Expand Down
61 changes: 61 additions & 0 deletions src/studio/http.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// MIT License

// Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#include "tic80_types.h"

typedef struct
{
enum
{
HttpGetProgress,
HttpGetDone,
HttpGetError,
} type;

union
{
struct
{
s32 size;
s32 total;
} progress;

struct
{
s32 size;
u8* data;
} done;

struct
{
s32 code;
} error;
};

void* calldata;
const char* url;

} HttpGetData;

typedef void(*HttpGetCallback)(const HttpGetData*);
77 changes: 32 additions & 45 deletions src/studio/system.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
// MIT License

// Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#include "api.h"
#include "version.h"
#include "http.h"

#if defined(TIC80_PRO)
#define TIC_VERSION_POST " Pro"
Expand Down Expand Up @@ -30,42 +53,6 @@
#define KEYBOARD_HOLD 20
#define KEYBOARD_PERIOD 3

typedef struct
{
enum
{
HttpGetProgress,
HttpGetDone,
HttpGetError,
} type;

union
{
struct
{
s32 size;
s32 total;
} progress;

struct
{
s32 size;
u8* data;
} done;

struct
{
s32 code;
} error;
};

void* calldata;
const char* url;

} HttpGetData;

typedef void(*HttpGetCallback)(const HttpGetData*);

typedef struct
{
void (*setClipboardText)(const char* text);
Expand All @@ -76,18 +63,18 @@ typedef struct
u64 (*getPerformanceCounter)();
u64 (*getPerformanceFrequency)();

void* (*httpGetSync)(const char* url, s32* size);
void (*httpGet)(const char* url, HttpGetCallback callback, void* userdata);
void* (*httpGetSync)(const char* url, s32* size);
void (*httpGet)(const char* url, HttpGetCallback callback, void* userdata);

void (*goFullscreen)();
void (*showMessageBox)(const char* title, const char* message);
void (*setWindowTitle)(const char* title);
void (*goFullscreen)();
void (*showMessageBox)(const char* title, const char* message);
void (*setWindowTitle)(const char* title);

void (*openSystemPath)(const char* path);
void (*openSystemPath)(const char* path);

void (*preseed)();
void (*poll)();
char (*text)();
void (*preseed)();
void (*poll)();
char (*text)();

void (*updateConfig)();

Expand Down
Loading

0 comments on commit a90f143

Please sign in to comment.