* * Reads a byte from a file (do not call yourself, use ReadByte()) * */
| 57 | * |
| 58 | */ |
| 59 | static uint8_t ReadByteFromFile(LoadgameState &ls) |
| 60 | { |
| 61 | /* To avoid slow reads, we read BUFFER_SIZE of bytes per time |
| 62 | and just return a byte per time */ |
| 63 | if (ls.buffer_cur >= ls.buffer_count) { |
| 64 | |
| 65 | /* Read some new bytes from the file */ |
| 66 | int count = static_cast<int>(fread(ls.buffer.data(), 1, ls.buffer.size(), *ls.file)); |
| 67 | |
| 68 | /* We tried to read, but there is nothing in the file anymore.. */ |
| 69 | if (count == 0) { |
| 70 | Debug(oldloader, 0, "Read past end of file, loading failed"); |
| 71 | throw std::exception(); |
| 72 | } |
| 73 | |
| 74 | ls.buffer_count = count; |
| 75 | ls.buffer_cur = 0; |
| 76 | } |
| 77 | |
| 78 | return ls.buffer[ls.buffer_cur++]; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * |