Skip to content

Commit

Permalink
replace intN to fixed width integer in C++11 (#688)
Browse files Browse the repository at this point in the history
* remove int8

* replace int16_t

* replace int32_t

* replace int64_t

* replace uint16_t

* replace uint32_t

* replace uint64_t

* replace uint8_t
  • Loading branch information
salix5 authored Dec 12, 2024
1 parent 6871274 commit a6ddb76
Show file tree
Hide file tree
Showing 25 changed files with 4,999 additions and 5,007 deletions.
890 changes: 445 additions & 445 deletions card.cpp

Large diffs are not rendered by default.

484 changes: 242 additions & 242 deletions card.h

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions card_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

constexpr int CARD_ARTWORK_VERSIONS_OFFSET = 20;
constexpr int SIZE_SETCODE = 16;
constexpr uint32 CARD_BLACK_LUSTER_SOLDIER2 = 5405695;
constexpr uint32_t CARD_BLACK_LUSTER_SOLDIER2 = 5405695;

//double name
constexpr uint32 CARD_MARINE_DOLPHIN = 78734254;
constexpr uint32 CARD_TWINKLE_MOSS = 13857930;
constexpr uint32 CARD_TIMAEUS = 1784686;
constexpr uint32 CARD_CRITIAS = 11082056;
constexpr uint32 CARD_HERMOS = 46232525;
constexpr uint32_t CARD_MARINE_DOLPHIN = 78734254;
constexpr uint32_t CARD_TWINKLE_MOSS = 13857930;
constexpr uint32_t CARD_TIMAEUS = 1784686;
constexpr uint32_t CARD_CRITIAS = 11082056;
constexpr uint32_t CARD_HERMOS = 46232525;

const std::unordered_map<uint32, uint32> second_code = {
const std::unordered_map<uint32_t, uint32_t> second_code = {
{CARD_MARINE_DOLPHIN, 17955766u},
{CARD_TWINKLE_MOSS, 17732278u},
{CARD_TIMAEUS, 10000050u},
Expand All @@ -24,18 +24,18 @@ const std::unordered_map<uint32, uint32> second_code = {
};

struct card_data {
uint32 code{};
uint32 alias{};
uint32_t code{};
uint32_t alias{};
uint16_t setcode[SIZE_SETCODE]{};
uint32 type{};
uint32 level{};
uint32 attribute{};
uint32 race{};
int32 attack{};
int32 defense{};
uint32 lscale{};
uint32 rscale{};
uint32 link_marker{};
uint32_t type{};
uint32_t level{};
uint32_t attribute{};
uint32_t race{};
int32_t attack{};
int32_t defense{};
uint32_t lscale{};
uint32_t rscale{};
uint32_t link_marker{};

void clear() {
code = 0;
Expand All @@ -53,7 +53,7 @@ struct card_data {
link_marker = 0;
}

bool is_setcode(uint32 value) const {
bool is_setcode(uint32_t value) const {
uint16_t settype = value & 0x0fff;
uint16_t setsubtype = value & 0xf000;
for (auto& x : setcode) {
Expand All @@ -71,7 +71,7 @@ struct card_data {
return alias && (alias < code + CARD_ARTWORK_VERSIONS_OFFSET) && (code < alias + CARD_ARTWORK_VERSIONS_OFFSET);
}

void set_setcode(uint64 value) {
void set_setcode(uint64_t value) {
int ctr = 0;
while (value) {
if (value & 0xffff) {
Expand All @@ -84,7 +84,7 @@ struct card_data {
setcode[i] = 0;
}

uint32 get_original_code() const {
uint32_t get_original_code() const {
return is_alternative() ? alias : code;
}
};
Expand Down
8 changes: 0 additions & 8 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@

#include <stdint.h>
#include <assert.h>
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
typedef unsigned char byte;
typedef long long int64;
typedef int int32;
typedef short int16;
typedef signed char int8;

#define MATCH_ALL(x,y) (((x)&(y))==(y))
#define MATCH_ANY(x,y) ((x)&(y))
Expand Down
16 changes: 8 additions & 8 deletions duel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void duel::clear() {
game_field = new field(this);
game_field->temp_card = new_card(0);
}
card* duel::new_card(uint32 code) {
card* duel::new_card(uint32_t code) {
card* pcard = new card(this);
cards.insert(pcard);
if (code != TEMP_CARD_ID)
Expand Down Expand Up @@ -97,11 +97,11 @@ void duel::delete_effect(effect* peffect) {
effects.erase(peffect);
delete peffect;
}
int32 duel::read_buffer(byte* buf) {
int32_t duel::read_buffer(byte* buf) {
auto size = buffer_size();
if (size)
std::memcpy(buf, message_buffer.data(), size);
return (int32)size;
return (int32_t)size;
}
void duel::release_script_group() {
for(auto& pgroup : sgroups) {
Expand All @@ -121,25 +121,25 @@ void duel::restore_assumes() {
void duel::write_buffer(const void* data, int size) {
vector_write_block(message_buffer, data, size);
}
void duel::write_buffer32(uint32 value) {
void duel::write_buffer32(uint32_t value) {
vector_write<uint32_t>(message_buffer, value);
}
void duel::write_buffer16(uint16 value) {
void duel::write_buffer16(uint16_t value) {
vector_write<uint16_t>(message_buffer, value);
}
void duel::write_buffer8(uint8 value) {
void duel::write_buffer8(uint8_t value) {
vector_write<unsigned char>(message_buffer, value);
}
void duel::clear_buffer() {
message_buffer.clear();
}
void duel::set_responsei(uint32 resp) {
void duel::set_responsei(uint32_t resp) {
game_field->returns.ivalue[0] = resp;
}
void duel::set_responseb(byte* resp) {
std::memcpy(game_field->returns.bvalue, resp, SIZE_RETURN_VALUE);
}
int32 duel::get_next_integer(int32 l, int32 h) {
int32_t duel::get_next_integer(int32_t l, int32_t h) {
if (game_field->core.duel_options & DUEL_OLD_REPLAY) {
return random.get_random_integer_old(l, h);
}
Expand Down
18 changes: 9 additions & 9 deletions duel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class duel {
~duel();
void clear();

uint32 buffer_size() const {
return (uint32)message_buffer.size() & PROCESSOR_BUFFER_LEN;
uint32_t buffer_size() const {
return (uint32_t)message_buffer.size() & PROCESSOR_BUFFER_LEN;
}
card* new_card(uint32 code);
card* new_card(uint32_t code);
group* new_group();
group* new_group(card* pcard);
group* new_group(const card_set& cset);
Expand All @@ -54,15 +54,15 @@ class duel {
void delete_effect(effect* peffect);
void release_script_group();
void restore_assumes();
int32 read_buffer(byte* buf);
int32_t read_buffer(byte* buf);
void write_buffer(const void* data, int size);
void write_buffer32(uint32 value);
void write_buffer16(uint16 value);
void write_buffer8(uint8 value);
void write_buffer32(uint32_t value);
void write_buffer16(uint16_t value);
void write_buffer8(uint8_t value);
void clear_buffer();
void set_responsei(uint32 resp);
void set_responsei(uint32_t resp);
void set_responseb(byte* resp);
int32 get_next_integer(int32 l, int32 h);
int32_t get_next_integer(int32_t l, int32_t h);
private:
group* register_group(group* pgroup);
};
Expand Down
Loading

0 comments on commit a6ddb76

Please sign in to comment.