A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
Stream.cc
1#include "Stream.hh"
2
3namespace EGG {
4
5Stream::Stream() : m_endian(std::endian::big), m_index(0) {}
6
7Stream::~Stream() = default;
8
9void Stream::skip(u32 count) {
10 m_index += count;
11 ASSERT(!bad());
12}
13
14void Stream::jump(u32 index) {
15 m_index = index;
16 ASSERT(!bad());
17}
18
19u8 Stream::read_u8() {
20 return read<u8>();
21}
22
23u16 Stream::read_u16() {
24 return read<u16>();
25}
26
27u32 Stream::read_u32() {
28 return read<u32>();
29}
30
31u64 Stream::read_u64() {
32 return read<u64>();
33}
34
35s8 Stream::read_s8() {
36 return read<s8>();
37}
38
39s16 Stream::read_s16() {
40 return read<s16>();
41}
42
43s32 Stream::read_s32() {
44 return read<s32>();
45}
46
47s64 Stream::read_s64() {
48 return read<s64>();
49}
50
51f32 Stream::read_f32() {
52 return read<f32>();
53}
54
55f64 Stream::read_f64() {
56 return read<f64>();
57}
58
59RamStream::RamStream() : m_buffer(nullptr), m_size(0) {}
60
61RamStream::RamStream(const void *buffer, u32 size) {
62 setBufferAndSize(const_cast<void *>(buffer), size);
63}
64
65void RamStream::read(void *output, u32 size) {
66 u8 *buffer = reinterpret_cast<u8 *>(output);
67 for (size_t i = 0; i < size; ++i) {
68 buffer[i] = m_buffer[m_index + i];
69 }
70}
71
72void RamStream::write(void *input, u32 size) {
73 u8 *buffer = reinterpret_cast<u8 *>(input);
74 for (size_t i = 0; i < size; ++i) {
75 m_buffer[m_index + i] = buffer[i];
76 }
77}
78
79// Expects a null-terminated char array, and moves the index past the null terminator
80std::string RamStream::read_string() {
81 std::string ret(reinterpret_cast<char *>(m_buffer + m_index));
82 m_index += ret.size() + 1;
83 ASSERT(!bad());
84 return ret;
85}
86
87void RamStream::setBufferAndSize(void *buffer, u32 size) {
88 m_buffer = reinterpret_cast<u8 *>(buffer);
89 m_size = size;
90}
91
96RamStream RamStream::split(u32 size) {
97 RamStream stream = RamStream(m_buffer + m_index, size);
98 m_index += size;
99 ASSERT(!bad());
100
101 return stream;
102}
103
104} // namespace EGG
A stream of data stored in memory.
Definition Stream.hh:64
EGG core library.
Definition Archive.cc:6