|
| 1 | +#include "Pch.hpp" |
| 2 | +#include "FS.hpp" |
| 3 | +#include "xrCore/xrCore.h" |
| 4 | +#pragma warning(push) |
| 5 | +#pragma warning(disable:4995) // ignore deprecation warnings |
| 6 | +#include <msclr/marshal.h> |
| 7 | +#pragma warning(pop) |
| 8 | + |
| 9 | +using namespace msclr::interop; |
| 10 | +using namespace System::Diagnostics; |
| 11 | + |
| 12 | +namespace XRay |
| 13 | +{ |
| 14 | +namespace ManagedApi |
| 15 | +{ |
| 16 | +namespace Core |
| 17 | +{ |
| 18 | + |
| 19 | +WriterBase::~WriterBase() |
| 20 | +{ |
| 21 | + delete impl; |
| 22 | + impl = nullptr; |
| 23 | +} |
| 24 | +String^ WriterBase::FileName::get() |
| 25 | +{ |
| 26 | + if (!fileName) |
| 27 | + fileName = gcnew String(impl->fName.c_str()); |
| 28 | + return fileName; |
| 29 | +} |
| 30 | +void WriterBase::WriteUInt64(UInt64 value) { impl->w_u64(value); } |
| 31 | +void WriterBase::WriteUInt32(UInt32 value) { impl->w_u32(value); } |
| 32 | +void WriterBase::WriteUInt16(UInt16 value) { impl->w_u16(value); } |
| 33 | +void WriterBase::WriteByte(Byte value) { impl->w_u8(value); } |
| 34 | +void WriterBase::WriteInt64(Int64 value) { impl->w_s64(value); } |
| 35 | +void WriterBase::WriteInt32(Int32 value) { impl->w_s32(value); } |
| 36 | +void WriterBase::WriteInt16(Int16 value) { impl->w_s16(value); } |
| 37 | +void WriterBase::WriteSByte(SByte value) { impl->w_s8(value); } |
| 38 | +void WriterBase::WriteFloat(float value) { impl->w_float(value); } |
| 39 | +void WriterBase::WriteString(const char* buffer) { impl->w_string(buffer); } |
| 40 | +void WriterBase::WriteStringZ(const char* buffer) { impl->w_stringZ(buffer); } |
| 41 | +void WriterBase::WriteString(String^ value) |
| 42 | +{ |
| 43 | + auto context = gcnew marshal_context(); |
| 44 | + auto tmpStr = context->marshal_as<const char*>(value); |
| 45 | + impl->w_string(tmpStr); |
| 46 | + delete context; |
| 47 | +} |
| 48 | +void WriterBase::WriteStringZ(String^ value) |
| 49 | +{ |
| 50 | + auto context = gcnew marshal_context(); |
| 51 | + auto tmpStr = context->marshal_as<const char*>(value); |
| 52 | + impl->w_stringZ(tmpStr); |
| 53 | + delete context; |
| 54 | +} |
| 55 | +void WriterBase::WriteColorF(ColorF value) { impl->w_fcolor((const Fcolor&)value); } |
| 56 | +void WriterBase::WriteVector4F(Vector4F value) { impl->w_fvector4((const Fvector4&)value); } |
| 57 | +void WriterBase::WriteVector3F(Vector3F value) { impl->w_fvector3((const Fvector3&)value); } |
| 58 | +void WriterBase::WriteVector2F(Vector2F value) { impl->w_fvector2((const Fvector2&)value); } |
| 59 | +void WriterBase::WriteVector4I(Vector4I value) { impl->w_ivector4((const Ivector4&)value); } |
| 60 | +void WriterBase::WriteVector3I(Vector3I value) { impl->w_ivector3((const Ivector3&)value); } |
| 61 | +void WriterBase::WriteVector2I(Vector2I value) { impl->w_ivector2((const Ivector2&)value); } |
| 62 | +void WriterBase::WriteFloat16(float value, float min, float max) { impl->w_float_q16(value, min, max); } |
| 63 | +void WriterBase::WriteFloat8(float value, float min, float max) { impl->w_float_q8(value, min, max); } |
| 64 | +void WriterBase::WriteAngle16(float value) { impl->w_angle16(value); } |
| 65 | +void WriterBase::WriteAngle8(float value) { impl->w_angle8(value); } |
| 66 | +void WriterBase::WriteDirection(Vector3F value) { impl->w_dir((const Fvector3&)value); } |
| 67 | +void WriterBase::WriteScaledDirection(Vector3F value) { impl->w_sdir((const Fvector3&)value); } |
| 68 | +void WriterBase::WriteString(String^ format, ... array<Object^>^ args) |
| 69 | +{ |
| 70 | + auto str = String::Format(format, args); |
| 71 | + auto context = gcnew marshal_context(); |
| 72 | + auto tmpStr = context->marshal_as<const char*>(str); |
| 73 | + impl->w(tmpStr, xr_strlen(tmpStr)); |
| 74 | + delete context; |
| 75 | +} |
| 76 | +void WriterBase::OpenChunk(UInt32 type) { impl->open_chunk(type); } |
| 77 | +void WriterBase::CloseChunk() { impl->close_chunk(); } |
| 78 | +UInt32 WriterBase::ChunkSize::get() { return impl->chunk_size(); } |
| 79 | +void WriterBase::WriteCompressed(void* buffer, UInt32 bufferSize) { impl->w_compressed(buffer, bufferSize); } |
| 80 | +void WriterBase::WriteChunk(UInt32 type, void* buffer, UInt32 bufferSize) { impl->w_chunk(type, buffer, bufferSize); } |
| 81 | +bool WriterBase::CanWrite::get() { return impl->valid(); } |
| 82 | + |
| 83 | +ReaderBase::~ReaderBase() |
| 84 | +{ |
| 85 | + delete impl; |
| 86 | + impl = nullptr; |
| 87 | +} |
| 88 | +ReaderBase::ReaderBase(::IReader* impl) { this->impl = impl; } |
| 89 | +bool ReaderBase::EndOfStream::get() { return !!impl->eof(); } |
| 90 | +void ReaderBase::Read(void* buffer, int byteCount) { impl->r(buffer, byteCount); } |
| 91 | +Vector3F ReaderBase::ReadVector3F() { return *(Vector3F*)&impl->r_vec3(); } |
| 92 | +Vector4F ReaderBase::ReadVector4F() { return *(Vector4F*)&impl->r_vec4(); } |
| 93 | +UInt64 ReaderBase::ReadUInt64() { return impl->r_u64(); } |
| 94 | +UInt32 ReaderBase::ReadUInt32() { return impl->r_u32(); } |
| 95 | +UInt16 ReaderBase::ReadUInt16() { return impl->r_u16(); } |
| 96 | +Byte ReaderBase::ReadByte() { return impl->r_u8(); } |
| 97 | +Int64 ReaderBase::ReadInt64() { return impl->r_s64(); } |
| 98 | +Int32 ReaderBase::ReadInt32() { return impl->r_s32(); } |
| 99 | +Int16 ReaderBase::ReadInt16() { return impl->r_s16(); } |
| 100 | +SByte ReaderBase::ReadSByte() { return impl->r_s8(); } |
| 101 | +float ReaderBase::ReadFloat() { return impl->r_float(); } |
| 102 | +void ReaderBase::ReadVector4F([Out] Vector4F% v) |
| 103 | +{ |
| 104 | + Fvector4 tmp; |
| 105 | + impl->r_fvector4(tmp); |
| 106 | + v = reinterpret_cast<Vector4F&>(tmp); |
| 107 | +} |
| 108 | +void ReaderBase::ReadVector3F([Out] Vector3F% v) |
| 109 | +{ |
| 110 | + Fvector3 tmp; |
| 111 | + impl->r_fvector3(tmp); |
| 112 | + v = reinterpret_cast<Vector3F&>(tmp); |
| 113 | +} |
| 114 | +void ReaderBase::ReadVector2F([Out] Vector2F% v) |
| 115 | +{ |
| 116 | + Fvector2 tmp; |
| 117 | + impl->r_fvector2(tmp); |
| 118 | + v = reinterpret_cast<Vector2F&>(tmp); |
| 119 | +} |
| 120 | +void ReaderBase::ReadVector4I([Out] Vector4I% v) |
| 121 | +{ |
| 122 | + Ivector4 tmp; |
| 123 | + impl->r_ivector4(tmp); |
| 124 | + v = reinterpret_cast<Vector4I&>(tmp); |
| 125 | +} |
| 126 | +void ReaderBase::ReadVector3I([Out] Vector3I% v) |
| 127 | +{ |
| 128 | + Ivector3 tmp; |
| 129 | + impl->r_ivector4(tmp); |
| 130 | + v = reinterpret_cast<Vector3I&>(tmp); |
| 131 | +} |
| 132 | +void ReaderBase::ReadVector2I([Out] Vector2I% v) |
| 133 | +{ |
| 134 | + Ivector2 tmp; |
| 135 | + impl->r_ivector4(tmp); |
| 136 | + v = reinterpret_cast<Vector2I&>(tmp); |
| 137 | +} |
| 138 | +void ReaderBase::ReadColorF([Out] ColorF% v) |
| 139 | +{ |
| 140 | + Fcolor tmp; |
| 141 | + impl->r_fcolor(tmp); |
| 142 | + v = reinterpret_cast<ColorF&>(tmp); |
| 143 | +} |
| 144 | +float ReaderBase::ReadFloat16(float min, float max) { return impl->r_float_q16(min, max); } |
| 145 | +float ReaderBase::ReadFloat8(float min, float max) { return impl->r_float_q8(min, max); } |
| 146 | +float ReaderBase::ReadAngle16() { return impl->r_angle16(); } |
| 147 | +float ReaderBase::ReadAngle8() { return impl->r_angle8(); } |
| 148 | +void ReaderBase::ReadDirection([Out] Vector3F% A) |
| 149 | +{ |
| 150 | + Fvector3 tmp; |
| 151 | + impl->r_dir(tmp); |
| 152 | + A = reinterpret_cast<Vector3F&>(tmp); |
| 153 | +} |
| 154 | +void ReaderBase::ReadScaledDirection([Out] Vector3F% A) |
| 155 | +{ |
| 156 | + Fvector3 tmp; |
| 157 | + impl->r_sdir(tmp); |
| 158 | + A = reinterpret_cast<Vector3F&>(tmp); |
| 159 | +} |
| 160 | +void ReaderBase::Rewind() { impl->rewind(); } |
| 161 | +UInt32 ReaderBase::FindChunk(UInt32 id, int* isCompressed) { return impl->find_chunk(id, isCompressed); } |
| 162 | +bool ReaderBase::ReadChunk(UInt32 id, void* buffer) { return !!impl->r_chunk(id, buffer); } |
| 163 | +bool ReaderBase::ReadChunkSafe(UInt32 id, void* buffer, UInt32 bufferSize) |
| 164 | +{ |
| 165 | + return !!impl->r_chunk_safe(id, buffer, bufferSize); |
| 166 | +} |
| 167 | +int ReaderBase::Remain::get() { return impl->elapsed(); } |
| 168 | +int ReaderBase::Position::get() { return impl->tell(); } |
| 169 | +void ReaderBase::Seek(int position) { impl->seek(position); } |
| 170 | +int ReaderBase::Length::get() { return impl->length(); } |
| 171 | +void* ReaderBase::Pointer::get() { return impl->pointer(); } |
| 172 | +void ReaderBase::Skip(int byteCount) { impl->advance(byteCount); } |
| 173 | +void ReaderBase::ReadString(char* buffer, UInt32 bufferSize) { impl->r_string(buffer, bufferSize); } |
| 174 | +void ReaderBase::ReadString([Out] String^% str) |
| 175 | +{ |
| 176 | + xr_string tmp; |
| 177 | + impl->r_string(tmp); |
| 178 | + str = gcnew String(tmp.c_str()); |
| 179 | +} |
| 180 | +void ReaderBase::SkipStringZ() { impl->skip_stringZ(); } |
| 181 | +void ReaderBase::ReadStringZ(char* buffer, UInt32 bufferSize) { impl->r_stringZ(buffer, bufferSize); } |
| 182 | +void ReaderBase::ReadStringZ([Out] String^% str) |
| 183 | +{ |
| 184 | + xr_string tmp; |
| 185 | + impl->r_stringZ(tmp); |
| 186 | + str = gcnew String(tmp.c_str()); |
| 187 | +} |
| 188 | +void ReaderBase::Close() |
| 189 | +{ |
| 190 | + impl->close(); // close deletes impl |
| 191 | + impl = nullptr; |
| 192 | +} |
| 193 | +ReaderBase^ ReaderBase::OpenChunk(UInt32 id) |
| 194 | +{ |
| 195 | + auto rawReader = impl->open_chunk(id); |
| 196 | + return gcnew InternalReaderBase(rawReader); |
| 197 | +} |
| 198 | +ReaderBase^ ReaderBase::OpenChunkIterator([Out] UInt32% id, ReaderBase^ prevReader) |
| 199 | +{ |
| 200 | + UInt32 tmpId; |
| 201 | + auto rawReader = impl->open_chunk_iterator(tmpId, prevReader ? prevReader->impl : nullptr); |
| 202 | + id = tmpId; |
| 203 | + if (prevReader) |
| 204 | + prevReader->impl = nullptr; // open_chunk_iterator deletes impl |
| 205 | + return gcnew InternalReaderBase(rawReader); |
| 206 | +} |
| 207 | + |
| 208 | +} |
| 209 | +} |
| 210 | +} |
0 commit comments