Skip to content

Commit

Permalink
add duel::buffer_size() (#653)
Browse files Browse the repository at this point in the history
* add duel::buffer_size()

* fix warning C4267 about size
  • Loading branch information
salix5 authored Nov 9, 2024
1 parent 3d92ce9 commit 8568c8f
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 100 deletions.
7 changes: 4 additions & 3 deletions duel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ void duel::delete_effect(effect* peffect) {
delete peffect;
}
int32 duel::read_buffer(byte* buf) {
if(message_buffer.size())
std::memcpy(buf, message_buffer.data(), message_buffer.size());
return (int32)message_buffer.size();
auto size = buffer_size();
if (size)
std::memcpy(buf, message_buffer.data(), size);
return (int32)size;
}
void duel::release_script_group() {
for(auto& pgroup : sgroups) {
Expand Down
4 changes: 4 additions & 0 deletions duel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mtrandom.h"
#include <set>
#include <unordered_set>
#include <vector>

class card;
class group;
Expand Down Expand Up @@ -40,6 +41,9 @@ class duel {
~duel();
void clear();

uint32 buffer_size() const {
return (uint32)message_buffer.size() & PROCESSOR_BUFFER_LEN;
}
card* new_card(uint32 code);
group* new_group();
group* new_group(card* pcard);
Expand Down
2 changes: 1 addition & 1 deletion field.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ class field {
int32 toss_dice(uint16 step, effect* reason_effect, uint8 reason_player, uint8 playerid, uint8 count1, uint8 count2);
int32 rock_paper_scissors(uint16 step, uint8 repeat);

bool check_response(int32 vector_size, int32 min_len, int32 max_len) const;
bool check_response(size_t vector_size, int32 min_len, int32 max_len) const;
int32 select_battle_command(uint16 step, uint8 playerid);
int32 select_idle_command(uint16 step, uint8 playerid);
int32 select_effect_yes_no(uint16 step, uint8 playerid, uint32 description, card* pcard);
Expand Down
4 changes: 2 additions & 2 deletions operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4367,7 +4367,7 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3
raise_single_event(pcard, 0, EVENT_DESTROYED, pcard->current.reason_effect, pcard->current.reason, pcard->current.reason_player, 0, 0);
}
if(pcard->xyz_materials.size()) {
pcard->xyz_materials_previous_count_onfield = pcard->xyz_materials.size();
pcard->xyz_materials_previous_count_onfield = (int32)pcard->xyz_materials.size();
for(auto& mcard : pcard->xyz_materials)
overlays.insert(mcard);
} else {
Expand Down Expand Up @@ -4711,7 +4711,7 @@ int32 field::move_to_field(uint16 step, card* target, uint32 enable, uint32 ret,
}
}
if(target->xyz_materials.size()) {
target->xyz_materials_previous_count_onfield = target->xyz_materials.size();
target->xyz_materials_previous_count_onfield = (int32)target->xyz_materials.size();
card_set overlays;
overlays.insert(target->xyz_materials.begin(), target->xyz_materials.end());
send_to(&overlays, 0, REASON_LOST_OVERLAY + REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
Expand Down
4 changes: 2 additions & 2 deletions playerop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#include <algorithm>
#include <stack>

bool field::check_response(int32 vector_size, int32 min_len, int32 max_len) const {
bool field::check_response(size_t vector_size, int32 min_len, int32 max_len) const {
const int32 len = returns.bvalue[0];
if (len < min_len || len > max_len)
return false;
std::set<uint8> index_set;
for (int32 i = 0; i < len; ++i) {
uint8 index = returns.bvalue[1 + i];
if (index >=vector_size || index_set.count(index)) {
if (index >= (int32)vector_size || index_set.count(index)) {
return false;
}
index_set.insert(index);
Expand Down
Loading

0 comments on commit 8568c8f

Please sign in to comment.