Skip to content

Commit

Permalink
pass structures by pointer for core APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
DyXel committed Jan 7, 2024
1 parent a7d8ab6 commit 4ea1d85
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/Hornet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void MainLoop()
opts.logHandler = &LogHandler;
opts.cardReaderDone = &DataReaderDone;
OCG_Duel duel = nullptr;
int r = OCG_CreateDuel(&duel, opts);
int r = OCG_CreateDuel(&duel, &opts);
auto* wptr = hss->bytes.data();
Write<int>(wptr, r);
Write<OCG_Duel>(wptr, duel);
Expand All @@ -166,7 +166,8 @@ void MainLoop()
{
const auto* rptr = hss->bytes.data();
const auto duel = Read<OCG_Duel>(rptr);
OCG_DuelNewCard(duel, Read<OCG_NewCardInfo>(rptr));
const auto card = Read<OCG_NewCardInfo>(rptr);
OCG_DuelNewCard(duel, &card);
break;
}
case Action::OCG_START_DUEL:
Expand Down Expand Up @@ -233,7 +234,7 @@ void MainLoop()
const auto duel = Read<OCG_Duel>(rptr);
const auto info = Read<OCG_QueryInfo>(rptr);
uint32_t qLength = 0U;
auto* qPtr = OCG_DuelQuery(duel, &qLength, info);
auto* qPtr = OCG_DuelQuery(duel, &qLength, &info);
auto* wptr = hss->bytes.data();
Write<uint32_t>(wptr, qLength);
std::memcpy(wptr, qPtr, static_cast<std::size_t>(qLength));
Expand All @@ -245,7 +246,7 @@ void MainLoop()
const auto duel = Read<OCG_Duel>(rptr);
const auto info = Read<OCG_QueryInfo>(rptr);
uint32_t qLength = 0U;
auto* qPtr = OCG_DuelQueryLocation(duel, &qLength, info);
auto* qPtr = OCG_DuelQueryLocation(duel, &qLength, &info);
auto* wptr = hss->bytes.data();
Write<uint32_t>(wptr, qLength);
std::memcpy(wptr, qPtr, static_cast<std::size_t>(qLength));
Expand Down
10 changes: 5 additions & 5 deletions src/Multirole/Core/DLWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ IWrapper::Duel DLWrapper::CreateDuel(const DuelOptions& opts)
OCG_Duel duel{nullptr};
std::scoped_lock lock(ssdMutex);
auto ssdIter = ssdList.insert(ssdList.end(), {opts.scriptSupplier, OCG_LoadScript});
OCG_DuelOptions options =
const OCG_DuelOptions options =
{
{opts.seed[0U], opts.seed[1U], opts.seed[2U], opts.seed[3U]},
opts.flags,
Expand All @@ -97,7 +97,7 @@ IWrapper::Duel DLWrapper::CreateDuel(const DuelOptions& opts)
&opts.dataSupplier,
0
};
if(OCG_CreateDuel(&duel, options) != OCG_DUEL_CREATION_SUCCESS)
if(OCG_CreateDuel(&duel, &options) != OCG_DUEL_CREATION_SUCCESS)
{
ssdList.erase(ssdIter);
throw Core::Exception(I18N::DLWRAPPER_EXCEPT_CREATE_DUEL);
Expand All @@ -117,7 +117,7 @@ void DLWrapper::DestroyDuel(Duel duel)

void DLWrapper::AddCard(Duel duel, const OCG_NewCardInfo& info)
{
OCG_DuelNewCard(duel, info);
OCG_DuelNewCard(duel, &info);
}

void DLWrapper::Start(Duel duel)
Expand Down Expand Up @@ -157,7 +157,7 @@ std::size_t DLWrapper::QueryCount(Duel duel, uint8_t team, uint32_t loc)
IWrapper::Buffer DLWrapper::Query(Duel duel, const QueryInfo& info)
{
uint32_t length = 0U;
auto* pointer = OCG_DuelQuery(duel, &length, info);
auto* pointer = OCG_DuelQuery(duel, &length, &info);
Buffer buffer(static_cast<Buffer::size_type>(length));
std::memcpy(buffer.data(), pointer, static_cast<std::size_t>(length));
return buffer;
Expand All @@ -166,7 +166,7 @@ IWrapper::Buffer DLWrapper::Query(Duel duel, const QueryInfo& info)
IWrapper::Buffer DLWrapper::QueryLocation(Duel duel, const QueryInfo& info)
{
uint32_t length = 0U;
auto* pointer = OCG_DuelQueryLocation(duel, &length, info);
auto* pointer = OCG_DuelQueryLocation(duel, &length, &info);
Buffer buffer(static_cast<Buffer::size_type>(length));
std::memcpy(buffer.data(), pointer, static_cast<std::size_t>(length));
return buffer;
Expand Down
8 changes: 4 additions & 4 deletions src/ocgapi_funcs.inl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
OCGFUNC(void, OCG_GetVersion, (int* major, int* minor))

OCGFUNC(int, OCG_CreateDuel, (OCG_Duel* duel, OCG_DuelOptions options))
OCGFUNC(int, OCG_CreateDuel, (OCG_Duel* duel, const OCG_DuelOptions* options))
OCGFUNC(void, OCG_DestroyDuel, (OCG_Duel duel))
OCGFUNC(void, OCG_DuelNewCard, (OCG_Duel duel, OCG_NewCardInfo info))
OCGFUNC(void, OCG_DuelNewCard, (OCG_Duel duel, const OCG_NewCardInfo* info))
OCGFUNC(int, OCG_StartDuel, (OCG_Duel duel))

OCGFUNC(int, OCG_DuelProcess, (OCG_Duel duel))
Expand All @@ -11,6 +11,6 @@ OCGFUNC(void, OCG_DuelSetResponse, (OCG_Duel duel, const void* buffer, uint32_t
OCGFUNC(int, OCG_LoadScript, (OCG_Duel duel, const char* buffer, uint32_t length, const char* name))

OCGFUNC(uint32_t, OCG_DuelQueryCount, (OCG_Duel duel, uint8_t team, uint32_t loc))
OCGFUNC(void*, OCG_DuelQuery, (OCG_Duel duel, uint32_t* length, OCG_QueryInfo info))
OCGFUNC(void*, OCG_DuelQueryLocation, (OCG_Duel duel, uint32_t* length, OCG_QueryInfo info))
OCGFUNC(void*, OCG_DuelQuery, (OCG_Duel duel, uint32_t* length, const OCG_QueryInfo* info))
OCGFUNC(void*, OCG_DuelQueryLocation, (OCG_Duel duel, uint32_t* length, const OCG_QueryInfo* info))
OCGFUNC(void*, OCG_DuelQueryField, (OCG_Duel duel, uint32_t* length))

0 comments on commit 4ea1d85

Please sign in to comment.