Skip to content

Commit

Permalink
Merge pull request #657 Update to CPR 1.10.5
Browse files Browse the repository at this point in the history
from SkyLeite/develop
  • Loading branch information
Drewol authored Jan 6, 2024
2 parents 2358d3a + 096ef35 commit 76c359f
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[submodule "third_party/cpr"]
path = third_party/cpr
url = https://github.com/whoshuu/cpr.git
branch = 1.10.x
[submodule "third_party/miniaudio"]
path = third_party/miniaudio
url = https://github.com/dr-soft/miniaudio.git
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Root CMake file
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "v")
set(CMAKE_CXX_STANDARD_REQUIRED True)
#set(VCPKG_CRT_LINKAGE static)
#set(VCPKG_LIBRARY_LINKAGE static)
#set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "Vcpkg target triplet (ex. x86-windows)")
Expand All @@ -14,6 +16,7 @@ endif()

option(BUILD_SHARED_LIBS "Build libraries as shared libraries" OFF)
option(USC_GNU_WERROR "Set Werror for gcc." OFF)
option(USE_SYSTEM_CPR "Use system CPR" OFF)

project(USC VERSION 0.5.0)
if(WIN32 AND ${CMAKE_VERSION} VERSION_GREATER "3.12")
Expand Down
5 changes: 5 additions & 0 deletions Main/include/LuaRequests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ struct AsyncRequest
struct lua_State* L;
cpr::AsyncResponse r;
int callback;

AsyncRequest(struct lua_State* luaState, cpr::AsyncResponse asyncResponse, int callback)
: L(luaState), r(std::move(asyncResponse)), callback(callback)
{
}
};

struct CompleteRequest
Expand Down
10 changes: 5 additions & 5 deletions Main/src/ScoreScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ScoreScreen_Impl : public ScoreScreen
//promote this to higher scope so i can use it in tick
String m_replayPath;

cpr::AsyncResponse m_irResponse;
std::unique_ptr<cpr::AsyncResponse> m_irResponse;
nlohmann::json m_irResponseJson;

HitWindow m_hitWindow = HitWindow::NORMAL;
Expand Down Expand Up @@ -349,7 +349,7 @@ class ScoreScreen_Impl : public ScoreScreen
if (g_gameConfig.GetString(GameConfigKeys::IRBaseURL) != "")
{
m_irState = IR::ResponseState::Pending;
m_irResponse = IR::PostScore(*newScore, m_beatmapSettings);
m_irResponse = std::make_unique<cpr::AsyncResponse>(std::move(IR::PostScore(*newScore, m_beatmapSettings)));
}

const bool cleared = Scoring::CalculateBadge(*newScore) >= ClearMark::NormalClear;
Expand Down Expand Up @@ -560,7 +560,7 @@ class ScoreScreen_Impl : public ScoreScreen
}

ScoreScreen_Impl(class Game* game, MultiplayerScreen* multiplayer,
String uid, Vector<nlohmann::json> const* multistats, ChallengeManager* manager)
String uid, Vector<nlohmann::json> const* multistats, ChallengeManager* manager) : m_irResponse(nullptr)
{
m_challengeManager = manager;
m_displayIndex = 0;
Expand Down Expand Up @@ -1174,9 +1174,9 @@ class ScoreScreen_Impl : public ScoreScreen
try {


if(m_irResponse.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
if(m_irResponse->wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
cpr::Response response = m_irResponse.get();
cpr::Response response = m_irResponse->get();

if(response.status_code != 200)
{
Expand Down
10 changes: 2 additions & 8 deletions Main/src/SkinHttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ int SkinHttp::lGetAsync(lua_State * L)
String url = luaL_checkstring(L, 2);
cpr::Header header = HeaderFromLuaTable(L, 3);
int callback = luaL_ref(L, LUA_REGISTRYINDEX);
AsyncRequest* r = new AsyncRequest();
r->r = cpr::GetAsync(cpr::Url{ url }, header);
r->callback = callback;
r->L = L;
AsyncRequest* r = new AsyncRequest(L, cpr::GetAsync(cpr::Url{ url }, header), callback);
m_mutex.lock();
m_requests.push(r);
m_mutex.unlock();
Expand All @@ -135,10 +132,7 @@ int SkinHttp::lPostAsync(lua_State * L)
String payload = luaL_checkstring(L, 3);
cpr::Header header = HeaderFromLuaTable(L, 4);
int callback = luaL_ref(L, LUA_REGISTRYINDEX);
AsyncRequest* r = new AsyncRequest();
r->r = cpr::PostAsync(cpr::Url{ url }, cpr::Body{ *payload }, header);
r->callback = callback;
r->L = L;
AsyncRequest* r = new AsyncRequest(L, cpr::PostAsync(cpr::Url{ url }, cpr::Body{ *payload }, header), callback);
m_mutex.lock();
m_requests.push(r);
m_mutex.unlock();
Expand Down
20 changes: 4 additions & 16 deletions Main/src/SkinIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ SkinIR::~SkinIR()
int SkinIR::lHeartbeat(struct lua_State* L)
{
int callback = luaL_ref(L, LUA_REGISTRYINDEX);
AsyncRequest* r = new AsyncRequest();
r->r = IR::Heartbeat();
r->callback = callback;
r->L = L;
AsyncRequest* r = new AsyncRequest(L, IR::Heartbeat(), callback);
m_mutex.lock();
m_requests.push(r);
m_mutex.unlock();
Expand All @@ -155,10 +152,7 @@ int SkinIR::lChartTracked(struct lua_State* L)
{
String hash = luaL_checkstring(L, 2);
int callback = luaL_ref(L, LUA_REGISTRYINDEX);
AsyncRequest* r = new AsyncRequest();
r->r = IR::ChartTracked(hash);
r->callback = callback;
r->L = L;
AsyncRequest* r = new AsyncRequest(L, IR::ChartTracked(hash), callback);
m_mutex.lock();
m_requests.push(r);
m_mutex.unlock();
Expand All @@ -169,10 +163,7 @@ int SkinIR::lRecord(struct lua_State* L)
{
String hash = luaL_checkstring(L, 2);
int callback = luaL_ref(L, LUA_REGISTRYINDEX);
AsyncRequest* r = new AsyncRequest();
r->r = IR::Record(hash);
r->callback = callback;
r->L = L;
AsyncRequest* r = new AsyncRequest(L, IR::Record(hash), callback);
m_mutex.lock();
m_requests.push(r);
m_mutex.unlock();
Expand All @@ -185,10 +176,7 @@ int SkinIR::lLeaderboard(struct lua_State* L)
String mode = luaL_checkstring(L, 3);
int n = luaL_checkinteger(L, 4);
int callback = luaL_ref(L, LUA_REGISTRYINDEX);
AsyncRequest* r = new AsyncRequest();
r->r = IR::Leaderboard(hash, mode, n);
r->callback = callback;
r->L = L;
AsyncRequest* r = new AsyncRequest(L, IR::Leaderboard(hash, mode, n), callback);
m_mutex.lock();
m_requests.push(r);
m_mutex.unlock();
Expand Down
2 changes: 1 addition & 1 deletion Main/stdafx.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Main and precompiled header file for Main project*/
#pragma once

#include "cpr/cpr.h"
// OpenGL headers
#include <Graphics/GL.hpp>

Expand Down Expand Up @@ -57,7 +58,6 @@ using namespace Graphics;

#include "archive.h"
#include "archive_entry.h"
#include "cpr/cpr.h"
#include "discord_rpc.h"
#include "json.hpp"
#include "lua.hpp"
Expand Down
26 changes: 26 additions & 0 deletions cmake/Modules/FindCPR.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# - C++ Requests, Curl for People
# This module is a libcurl wrapper written in modern C++.
# It provides an easy, intuitive, and efficient interface to
# a host of networking methods.
#
# Finding this module will define the following variables:
# CPR_FOUND - True if the core library has been found
# CPR_LIBRARIES - Path to the core library archive
# CPR_INCLUDE_DIRS - Path to the include directories. Gives access
# to cpr.h, which must be included in every
# file that uses this interface

find_path(CPR_INCLUDE_DIR
NAMES cpr.h)

find_library(CPR_LIBRARY
NAMES cpr
HINTS ${CPR_LIBRARY_ROOT})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CPR REQUIRED_VARS CPR_LIBRARY CPR_INCLUDE_DIR)

if(CPR_FOUND)
set(CPR_LIBRARIES ${CPR_LIBRARY})
set(CPR_INCLUDE_DIRS ${CPR_INCLUDE_DIR})
endif()
8 changes: 6 additions & 2 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ set(CPR_ENABLE_SSL ON)
#if(MSVC)
# set(CPR_FORCE_USE_SYSTEM_CURL ON) #curl should be available through vcpkg
#endif(MSVC)
add_subdirectory(cpr)
target_include_directories(cpr PUBLIC ${CPR_INCLUDE_DIRS})
if(USE_SYSTEM_CPR)
find_package(cpr REQUIRED)
else()
add_subdirectory(cpr)
target_include_directories(cpr PUBLIC ${CPR_INCLUDE_DIRS})
endif(USE_SYSTEM_CPR)

#discord example program
option(BUILD_EXAMPLES "Build example apps" OFF)
Expand Down

0 comments on commit 76c359f

Please sign in to comment.