OSDN Git Service

[Refactor] #3230 sniper_data_type を構造体からクラスへ変更し、メソッドを追加した
[hengbandforosx/hengbandosx.git] / src / save / save-util.cpp
1 #include "save/save-util.h"
2
3 FILE *saving_savefile; /* Current save "file" */
4 byte save_xor_byte; /* Simple encryption */
5 uint32_t v_stamp = 0L; /* A simple "checksum" on the actual values */
6 uint32_t x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
7
8 /*!
9  * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
10  * @param v 書き込むバイト値
11  */
12 static void sf_put(byte v)
13 {
14     /* Encode the value, write a character */
15     save_xor_byte ^= v;
16     (void)putc((int)save_xor_byte, saving_savefile);
17
18     /* Maintain the checksum info */
19     v_stamp += v;
20     x_stamp += save_xor_byte;
21 }
22
23 /*!
24  * @brief bool値をファイルに書き込む(wr_byte()の糖衣)
25  * @param v 書き込むbool値
26  */
27 void wr_bool(bool v)
28 {
29     wr_byte(v ? 1 : 0);
30 }
31
32 /*!
33  * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
34  * @param v 書き込むバイト
35  */
36 void wr_byte(byte v)
37 {
38     sf_put(v);
39 }
40
41 /*!
42  * @brief 符号なし16ビットをファイルに書き込む
43  * @param v 書き込む符号なし16bit値
44  */
45 void wr_u16b(uint16_t v)
46 {
47     wr_byte((byte)(v & 0xFF));
48     wr_byte((byte)((v >> 8) & 0xFF));
49 }
50
51 /*!
52  * @brief 符号あり16ビットをファイルに書き込む
53  * @param v 書き込む符号あり16bit値
54  */
55 void wr_s16b(int16_t v)
56 {
57     wr_u16b((uint16_t)v);
58 }
59
60 /*!
61  * @brief 符号なし32ビットをファイルに書き込む
62  * @param v 書き込む符号なし32bit値
63  */
64 void wr_u32b(uint32_t v)
65 {
66     wr_byte((byte)(v & 0xFF));
67     wr_byte((byte)((v >> 8) & 0xFF));
68     wr_byte((byte)((v >> 16) & 0xFF));
69     wr_byte((byte)((v >> 24) & 0xFF));
70 }
71
72 /*!
73  * @brief 符号あり32ビットをファイルに書き込む
74  * @param v 書き込む符号あり32bit値
75  */
76 void wr_s32b(int32_t v)
77 {
78     wr_u32b((uint32_t)v);
79 }
80
81 /*!
82  * @brief 文字列をファイルに書き込む
83  * @param str 書き込む文字列
84  */
85 void wr_string(std::string_view sv)
86 {
87     for (auto c : sv) {
88         wr_byte(c);
89     }
90     wr_byte('\0');
91 }