Skip to content
Merged
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
4 changes: 4 additions & 0 deletions 1k/platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ endif()

# compiler id

if(NOT WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(FULL_CLANG TRUE)
endif()

# generators that are capable of organizing into a hierarchy of folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Expand Down
70 changes: 35 additions & 35 deletions 3rdparty/yasio/yasio/bindings/lyasio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum
};

template <typename _Stream>
static void obstream_write_v(_Stream* obs, cxx17::string_view val, int length_field_bits)
static void obstream_write_v(_Stream* obs, std::string_view val, int length_field_bits)
{
// default: Use variant length of length field, just like .net BinaryWriter.Write(String),
// see:
Expand All @@ -58,7 +58,7 @@ static void obstream_write_v(_Stream* obs, cxx17::string_view val, int length_fi
}
};
template <typename _Stream>
static cxx17::string_view ibstream_read_v(_Stream* ibs, int length_field_bits)
static std::string_view ibstream_read_v(_Stream* ibs, int length_field_bits)
{
// default: Use variant length of length field, just like .net BinaryReader.ReadString,
// see:
Expand Down Expand Up @@ -113,21 +113,21 @@ static void register_obstream(sol::table& lib, const char* usertype)
"write_f16", &_Stream::template write<fp16_t>,
# endif
"write_f", &_Stream::template write<float>, "write_lf", &_Stream::template write<double>, "write_v",
[](_Stream* obs, cxx17::string_view sv, sol::variadic_args args) {
[](_Stream* obs, std::string_view sv, sol::variadic_args args) {
int lfl = -1;
if (args.size() > 0)
lfl = static_cast<int>(args[0]);
return obstream_write_v<_Stream>(obs, sv, lfl);
},
"write_bytes", static_cast<void (_Stream::*)(cxx17::string_view)>(&_Stream::write_bytes), "length", &_Stream::length, "to_string",
[](_Stream* obs) { return cxx17::string_view(obs->data(), obs->length()); }, "save", &_Stream::save);
"write_bytes", static_cast<void (_Stream::*)(std::string_view)>(&_Stream::write_bytes), "length", &_Stream::length, "to_string",
[](_Stream* obs) { return std::string_view(obs->data(), obs->length()); }, "save", &_Stream::save);
}

template <typename _Stream, typename _StreamView, typename _OStream>
static void register_ibstream(sol::table& lib, const char* usertype)
{
lib.new_usertype<_Stream>(
usertype, sol::constructors<_Stream(), _Stream(yasio::sbyte_buffer), _Stream(const _OStream*)>(), "load", &_Stream::load, "read_ix",
usertype, sol::constructors<_Stream(), _Stream(tlx::sbyte_buffer), _Stream(const _OStream*)>(), "load", &_Stream::load, "read_ix",
&_Stream::template read_ix<int64_t>, "read_bool", &_Stream::template read<bool>, "read_i8", &_Stream::template read<int8_t>, "read_i16",
&_Stream::template read<int16_t>, "read_i32", &_Stream::template read<int32_t>, "read_i64", &_Stream::template read<int64_t>, "read_u8",
&_Stream::template read<uint8_t>, "read_u16", &_Stream::template read<uint16_t>, "read_u32", &_Stream::template read<uint32_t>, "read_u64",
Expand All @@ -142,8 +142,8 @@ static void register_ibstream(sol::table& lib, const char* usertype)
lfl = static_cast<int>(args[0]);
return ibstream_read_v<_Stream>(ibs, lfl);
},
"read_bytes", static_cast<cxx17::string_view (_Stream::*)(int)>(&_Stream::read_bytes), "seek", &_StreamView::seek, "length", &_StreamView::length,
"to_string", [](_Stream* ibs) { return cxx17::string_view(ibs->data(), ibs->length()); });
"read_bytes", static_cast<std::string_view (_Stream::*)(int)>(&_Stream::read_bytes), "seek", &_StreamView::seek, "length", &_StreamView::length,
"to_string", [](_Stream* ibs) { return std::string_view(ibs->data(), ibs->length()); });
}
} // namespace lyasio

Expand All @@ -170,11 +170,11 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
switch (buffer_type)
{
case lyasio::BUFFER_RAW:
return sol::make_object(L, cxx17::string_view{packet_data(pkt), packet_len(pkt)});
return sol::make_object(L, std::string_view{packet_data(pkt), packet_len(pkt)});
case lyasio::BUFFER_FAST:
return sol::make_object(L, cxx14::make_unique<yasio::fast_ibstream>(forward_packet((packet_t &&) pkt)));
return sol::make_object(L, std::make_unique<yasio::fast_ibstream>(forward_packet((packet_t &&) pkt)));
default:
return sol::make_object(L, cxx14::make_unique<yasio::ibstream>(forward_packet((packet_t &&) pkt)));
return sol::make_object(L, std::make_unique<yasio::ibstream>(forward_packet((packet_t &&) pkt)));
}
},
"cindex", &io_event::cindex, "transport", &io_event::transport
Expand All @@ -192,13 +192,13 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
std::vector<io_hostent> hosts;
auto host = channel_eps["host"];
if (host.valid())
hosts.push_back(io_hostent(host.get<cxx17::string_view>(), channel_eps["port"]));
hosts.push_back(io_hostent(host.get<std::string_view>(), channel_eps["port"]));
else
{
for (auto item : channel_eps)
{
auto ep = item.second.as<sol::table>();
hosts.push_back(io_hostent(ep["host"].get<cxx17::string_view>(), ep["port"]));
hosts.push_back(io_hostent(ep["host"].get<std::string_view>(), ep["port"]));
}
}
return new (&uninitialized_memory)
Expand Down Expand Up @@ -258,16 +258,16 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
sol::overload(static_cast<void (io_service::*)(transport_handle_t)>(&io_service::close), static_cast<void (io_service::*)(int)>(&io_service::close)),
"write",
sol::overload(
[](io_service* service, transport_handle_t transport, cxx17::string_view s) {
return service->write(transport, yasio::sbyte_buffer{s.data(), s.data() + s.length()});
[](io_service* service, transport_handle_t transport, std::string_view s) {
return service->write(transport, tlx::sbyte_buffer{s.data(), s.data() + s.length()});
},
[](io_service* service, transport_handle_t transport, yasio::obstream* obs) { return service->write(transport, std::move(obs->buffer())); }),
"write_to",
sol::overload(
[](io_service* service, transport_handle_t transport, cxx17::string_view s, cxx17::string_view ip, u_short port) {
return service->write_to(transport, yasio::sbyte_buffer{s.data(), s.data() + s.length()}, ip::endpoint{ip.data(), port});
[](io_service* service, transport_handle_t transport, std::string_view s, std::string_view ip, u_short port) {
return service->write_to(transport, tlx::sbyte_buffer{s.data(), s.data() + s.length()}, ip::endpoint{ip.data(), port});
},
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, cxx17::string_view ip, u_short port) {
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, std::string_view ip, u_short port) {
return service->write_to(transport, std::move(obs->buffer()), ip::endpoint{ip.data(), port});
}),
"native_ptr", [](io_service* service) { return (void*)service; });
Expand All @@ -280,8 +280,8 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
lyasio::register_ibstream<ibstream, ibstream_view, obstream>(yasio_lib, "ibstream");
lyasio::register_ibstream<fast_ibstream, fast_ibstream_view, fast_obstream>(yasio_lib, "fast_ibstream");

yasio_lib["highp_clock"] = &highp_clock<yasio::steady_clock_t>;
yasio_lib["highp_time"] = &highp_clock<yasio::system_clock_t>;
yasio_lib["highp_clock"] = &tlx::highp_clock<tlx::steady_clock_t>;
yasio_lib["highp_time"] = &tlx::highp_clock<tlx::system_clock_t>;

yasio_lib["unwrap_ptr"] = [](lua_State* L) -> int {
auto& pkt = *(packet_t*)lua_touserdata(L, 1);
Expand Down Expand Up @@ -371,19 +371,19 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
/// customize the type conversion from/to lua
namespace kaguya
{
// cxx17::string_view
// std::string_view
template <>
struct lua_type_traits<cxx17::string_view> {
typedef cxx17::string_view get_type;
typedef cxx17::string_view push_type;
struct lua_type_traits<std::string_view> {
typedef std::string_view get_type;
typedef std::string_view push_type;

static bool strictCheckType(lua_State* l, int index) { return lua_type(l, index) == LUA_TSTRING; }
static bool checkType(lua_State* l, int index) { return lua_isstring(l, index) != 0; }
static get_type get(lua_State* l, int index)
{
size_t size = 0;
const char* buffer = lua_tolstring(l, index, &size);
return cxx17::string_view(buffer, size);
return std::string_view(buffer, size);
}
static int push(lua_State* l, push_type s)
{
Expand Down Expand Up @@ -527,15 +527,15 @@ static void register_obstream(kaguya::LuaTable& lib, const char* usertype, const
.addFunction("write_f", &_BaseStream::template write<float>)
.addFunction("write_lf", &_BaseStream::template write<double>)
.addStaticFunction("write_v",
[](_BaseStream* obs, cxx17::string_view sv, kaguya::VariadicArgType args) {
[](_BaseStream* obs, std::string_view sv, kaguya::VariadicArgType args) {
int lfl = -1;
if (args.size() > 0)
lfl = static_cast<int>(args[0]);
return lyasio::obstream_write_v(obs, sv, lfl);
})
.addFunction("write_bytes", static_cast<void (_BaseStream::*)(cxx17::string_view)>(&_BaseStream::write_bytes))
.addFunction("write_bytes", static_cast<void (_BaseStream::*)(std::string_view)>(&_BaseStream::write_bytes))
.addFunction("length", &_BaseStream::length)
.addStaticFunction("to_string", [](_BaseStream* obs) { return cxx17::string_view(obs->data(), obs->length()); }));
.addStaticFunction("to_string", [](_BaseStream* obs) { return std::string_view(obs->data(), obs->length()); }));
// ##-- obstream
lib[usertype].setClass(userclass);
}
Expand Down Expand Up @@ -565,10 +565,10 @@ static void register_ibstream(kaguya::LuaTable& lib, const char* usertype, const
length_field_bits = static_cast<int>(args[0]);
return lyasio::ibstream_read_v(ibs, length_field_bits);
})
.addFunction("read_bytes", static_cast<cxx17::string_view (_StreamView::*)(int)>(&_StreamView::read_bytes))
.addFunction("read_bytes", static_cast<std::string_view (_StreamView::*)(int)>(&_StreamView::read_bytes))
.addFunction("seek", &_StreamView::seek)
.addFunction("length", &_StreamView::length)
.addStaticFunction("to_string", [](_StreamView* ibs) { return cxx17::string_view(ibs->data(), ibs->length()); }));
.addStaticFunction("to_string", [](_StreamView* ibs) { return std::string_view(ibs->data(), ibs->length()); }));

// ##-- ibstream
lib[usertype].setClass(userclass);
Expand Down Expand Up @@ -602,8 +602,8 @@ YASIO_LUA_API int luaopen_yasio(lua_State* L)
[](io_event* ev) {
auto& pkt = ev->packet();
if (is_packet_empty(pkt))
return cxx17::string_view{""};
return cxx17::string_view{packet_data(pkt), packet_len(pkt)};
return std::string_view{""};
return std::string_view{packet_data(pkt), packet_len(pkt)};
})
.addStaticFunction("fast_packet",
[](io_event* ev) {
Expand Down Expand Up @@ -652,16 +652,16 @@ end
static_cast<void (io_service::*)(int)>(&io_service::close))
.addOverloadedFunctions(
"write",
[](io_service* service, transport_handle_t transport, cxx17::string_view s) {
[](io_service* service, transport_handle_t transport, std::string_view s) {
return service->write(transport, yasio::sbyte_buffer(s.data(), s.data() + s.length()));
},
[](io_service* service, transport_handle_t transport, yasio::obstream* obs) { return service->write(transport, std::move(obs->buffer())); })
.addOverloadedFunctions(
"write_to",
[](io_service* service, transport_handle_t transport, cxx17::string_view s, cxx17::string_view ip, u_short port) {
[](io_service* service, transport_handle_t transport, std::string_view s, std::string_view ip, u_short port) {
return service->write_to(transport, yasio::sbyte_buffer(s.data(), s.data() + s.length()), ip::endpoint{ip.data(), port});
},
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, cxx17::string_view ip, u_short port) {
[](io_service* service, transport_handle_t transport, yasio::obstream* obs, std::string_view ip, u_short port) {
return service->write_to(transport, std::move(obs->buffer()), ip::endpoint{ip.data(), port});
})
.addStaticFunction("set_option",
Expand Down
17 changes: 12 additions & 5 deletions 3rdparty/yasio/yasio/bindings/yasio_axlua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ SOFTWARE.
#include "yasio/bindings/yasio_axlua.hpp"
#include "yasio/bindings/lyasio.hpp"
#include "yasio/object_pool.hpp"
#include "yasio/ref_ptr.hpp"
#include "yasio/string_view.hpp"

// A workaround to fix compile issue caused by `CCPlatformMacros.h` doesn't handle `__has_attribute` it properly
# if !__has_attribute(format)
Expand All @@ -40,6 +38,7 @@ SOFTWARE.

#include "axmol/base/Director.h"
#include "axmol/base/Scheduler.h"
#include "axmol/tlx/memory.hpp"

using namespace ax;

Expand All @@ -63,15 +62,23 @@ struct TimerObject
static uintptr_t s_timerId;

DEFINE_FAST_OBJECT_POOL_ALLOCATION(TimerObject, 128)
YASIO__DEFINE_REFERENCE_CLASS

void retain() { ++_referenceCount; }
void release()
{
if (--_referenceCount == 0)
delete this;
}

uint32_t _referenceCount{1};
};
uintptr_t TimerObject::s_timerId = 0;

static TIMER_ID loop(unsigned int n, float interval, vcallback_t callback)
{
if (n > 0 && interval >= 0)
{
yasio::ref_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)));
tlx::retain_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)), tlx::adopt_object);

auto timerId = reinterpret_cast<TIMER_ID>(++TimerObject::s_timerId);

Expand All @@ -93,7 +100,7 @@ static TIMER_ID delay(float delay, vcallback_t callback)
{
if (delay > 0)
{
yasio::ref_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)));
tlx::retain_ptr<TimerObject> timerObj(new TimerObject(std::move(callback)), tlx::adopt_object);
auto timerId = reinterpret_cast<TIMER_ID>(++TimerObject::s_timerId);

std::string key = fmt::format("LSTMR#{}", fmt::ptr(timerId));
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/yasio/yasio/bindings/yasio_ni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ YASIO_NI_API void yasio_set_option(void* service_ptr, int opt, const char* pszAr
std::string strArgs = pszArgs;
std::array<cxx17::string_view, YASIO_MAX_OPTION_ARGC> args;
int argc = 0;
yasio::split_if(&strArgs.front(), ';', [&](char* s, char* e) {
tlx::split_if(&strArgs.front(), ';', [&](char* s, char* e) {
if (e) {
*e = '\0'; // to c style string
args[argc++] = cxx17::string_view(s, e - s);
Expand Down
14 changes: 7 additions & 7 deletions 3rdparty/yasio/yasio/bindings/yasio_sol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,33 @@ SOFTWARE.
# include "sol2/sol.hpp" // sol2-2.x
#endif

// use cxx17::string_view workaround with std::string_view
// use std::string_view workaround with std::string_view
#if !YASIO__HAS_CXX17
namespace sol
{
namespace stack
{
template <>
struct pusher<cxx17::string_view> {
static int push(lua_State* L, const cxx17::string_view& str)
struct pusher<std::string_view> {
static int push(lua_State* L, const std::string_view& str)
{
lua_pushlstring(L, !str.empty() ? str.c_str() : "", str.length());
return 1;
}
};
template <>
struct getter<cxx17::string_view> {
static cxx17::string_view get(lua_State* L, int index, record& tracking)
struct getter<std::string_view> {
static std::string_view get(lua_State* L, int index, record& tracking)
{
tracking.use(1); // THIS IS THE ONLY BIT THAT CHANGES
size_t len = 0;
const char* s = lua_tolstring(L, index, &len);
return cxx17::string_view(s, len);
return std::string_view(s, len);
}
};
} // namespace stack
template <>
struct lua_type_of<cxx17::string_view> : std::integral_constant<type, type::string> {};
struct lua_type_of<std::string_view> : std::integral_constant<type, type::string> {};
} // namespace sol
#endif

Expand Down
Loading