Skip to content

Commit

Permalink
More minor c++17 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
edo9300 committed Jan 5, 2024
1 parent 9790b55 commit 44b0f30
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace bit {

template<typename T>
inline uint8_t popcnt(T val) {
constexpr inline uint8_t popcnt(T val) {
uint8_t ans = 0;
while(val) {
val &= val - 1;
Expand All @@ -21,7 +21,7 @@ inline uint8_t popcnt(T val) {
}

template<typename T, typename T2>
inline bool has_invalid_bits(T value, T2 allowed) {
constexpr inline bool has_invalid_bits(T value, T2 allowed) {
return (value & (~allowed)) != 0;
}

Expand Down
2 changes: 0 additions & 2 deletions field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "group.h"
#include "interpreter.h"

int32_t field::field_used_count[32] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5};

bool chain::chain_operation_sort(const chain& c1, const chain& c2) {
return c1.triggering_effect->id < c2.triggering_effect->id;
}
Expand Down
9 changes: 8 additions & 1 deletion field.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <unordered_set>
#include <utility> //std::forward
#include <vector>
#include "bit.h"
#include "card.h"
#include "common.h"
#include "containers_fwd.h"
Expand Down Expand Up @@ -417,7 +418,13 @@ class field {
return_card_code return_card_codes;
tevent nil_event;

static int32_t field_used_count[32];
static constexpr auto field_used_count = ([]() constexpr {
std::array<int32_t, 32> ret{};
for(size_t i = 0; i < ret.size(); ++i) {
ret[i] = bit::popcnt(i);
}
return ret;
})();
explicit field(duel* pduel, const OCG_DuelOptions& options);
~field() = default;
void reload_field_info();
Expand Down
18 changes: 9 additions & 9 deletions interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interpreter::interpreter(duel* pd, const OCG_DuelOptions& options): coroutines(2
pduel = pd;
no_action = 0;
call_depth = 0;
memcpy(lua_getextraspace(lua_state), &pd, sizeof(duel*));
std::memcpy(lua_getextraspace(lua_state), &pd, sizeof(duel*));
// Open basic and used functionality
auto open_lib = [L=lua_state](const char* libname, lua_CFunction openf) {
luaL_requiref(L, libname, openf, 1);
Expand Down Expand Up @@ -229,27 +229,27 @@ bool interpreter::load_card_script(uint32_t code) {
void interpreter::push_param(lua_State* L, bool is_coroutine) {
int32_t pushed = 0;
luaL_checkstack(L, static_cast<uint32_t>(params.size()), nullptr);
for (const auto& it : params) {
switch(it.second) {
for(const auto& [param, type] : params) {
switch(type) {
case LuaParam::INT:
lua_pushinteger(L, it.first.integer);
lua_pushinteger(L, param.integer);
break;
case LuaParam::STRING:
lua_pushstring(L, static_cast<const char*>(it.first.ptr));
lua_pushstring(L, static_cast<const char*>(param.ptr));
break;
case LuaParam::BOOLEAN:
lua_pushboolean(L, static_cast<bool>(it.first.integer));
lua_pushboolean(L, static_cast<bool>(param.integer));
break;
case LuaParam::CARD:
case LuaParam::EFFECT:
case LuaParam::GROUP:
pushobject(L, static_cast<lua_obj*>(it.first.ptr));
pushobject(L, static_cast<lua_obj*>(param.ptr));
break;
case LuaParam::FUNCTION:
pushobject(L, static_cast<int32_t>(it.first.integer));
pushobject(L, static_cast<int32_t>(param.integer));
break;
case LuaParam::INDEX: {
auto index = static_cast<int32_t>(it.first.integer);
auto index = static_cast<int32_t>(param.integer);
if(index > 0)
lua_pushvalue(L, index);
else if(is_coroutine) {
Expand Down

0 comments on commit 44b0f30

Please sign in to comment.