diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 2de2f6d..d127244 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -3,7 +3,7 @@ # # Add source to this project's executable. -add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp" "platform/rasterizerstate-dx.cpp" "platform/vertexbuffer-dx.cpp" "platform/indexbuffer-dx.cpp" "common/matrix.cpp" "platform/constbuffer-dx.cpp" "platform/databuffer-dx.cpp" "platform/samplerstate-dx.cpp" "platform/spritebatch-dx.cpp" "platform/spritefont-dx.cpp" "platform/depthstencilstate-dx.cpp" "platform/keyboard-dx.cpp" "platform/mouse-dx.cpp" "platform/gamepad-dx.cpp" "common/vectors.cpp" "platform/soundeffect-dx.cpp" "platform/displaymode-dx.cpp" "platform/presentparameters-dx.cpp" "game/component.cpp") +add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" "platform/vertexinput-dx.cpp" "platform/shader-dx.cpp" "platform/rasterizerstate-dx.cpp" "platform/vertexbuffer-dx.cpp" "platform/indexbuffer-dx.cpp" "common/matrix.cpp" "platform/constbuffer-dx.cpp" "platform/databuffer-dx.cpp" "platform/samplerstate-dx.cpp" "platform/spritebatch-dx.cpp" "platform/spritefont-dx.cpp" "platform/depthstencilstate-dx.cpp" "platform/keyboard-dx.cpp" "platform/mouse-dx.cpp" "platform/gamepad-dx.cpp" "common/vectors.cpp" "platform/soundeffect-dx.cpp" "platform/displaymode-dx.cpp" "platform/presentparameters-dx.cpp" "game/component.cpp" "content/manager.cpp" "content/reader.cpp" "csharp/binary.cpp") if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET xna PROPERTY CXX_STANDARD 20) diff --git a/framework/content/manager.cpp b/framework/content/manager.cpp new file mode 100644 index 0000000..c421f25 --- /dev/null +++ b/framework/content/manager.cpp @@ -0,0 +1 @@ +#include "manager.hpp" \ No newline at end of file diff --git a/framework/content/manager.hpp b/framework/content/manager.hpp new file mode 100644 index 0000000..7dfe009 --- /dev/null +++ b/framework/content/manager.hpp @@ -0,0 +1,72 @@ +#ifndef XNA_CONTENT_MANAGER_HPP +#define XNA_CONTENT_MANAGER_HPP + +#include "../default.hpp" +#include +#include +#include +#include "../csharp/stream.hpp" + +namespace xna { + class ContentManager { + public: + ContentManager(String const& rootDirectory) : + _rootDirectory(rootDirectory), + _path(rootDirectory){}; + + virtual ~ContentManager(){ + Unload(); + } + + constexpr String RootDirectory() const { + return _rootDirectory; + } + + void RootDirectory(String const& value) { + _rootDirectory = value; + _path = value; + } + + virtual void Unload() { + if (_loadedAssets.empty()) + return; + + _loadedAssets.clear(); + } + + template + sptr Load(String const& assetName) { + if (assetName.empty()) return nullptr; + + if (_loadedAssets.contains(assetName)) { + const auto& ptr = _loadedAssets[assetName]; + const auto obj1 = reinterpret_pointer_cast(ptr); + + return obj1; + } + + const auto obj2 = ReadAsset(assetName); + return obj2; + } + + public: + template + sptr ReadAsset(String const& assetName) { + auto input = OpenStream(assetName); + } + + sptr OpenStream(String const& assetName) { + String filePath = _rootDirectory + "\\" + assetName + contentExtension; + const auto stream = New(filePath); + return reinterpret_pointer_cast(stream); + } + + private: + String _rootDirectory; + std::filesystem::path _path; + std::map> _loadedAssets; + inline const static String contentExtension = ".xnb"; + }; +} + +#endif \ No newline at end of file diff --git a/framework/content/reader.cpp b/framework/content/reader.cpp new file mode 100644 index 0000000..c229138 --- /dev/null +++ b/framework/content/reader.cpp @@ -0,0 +1,9 @@ +#include "reader.hpp" +#include "manager.hpp" + +namespace xna { + sptr ContentReader::Create(ContentManager* contentManager, Stream& input, String const& assetName) + { + return sptr(); + } +} diff --git a/framework/content/reader.hpp b/framework/content/reader.hpp new file mode 100644 index 0000000..7d00001 --- /dev/null +++ b/framework/content/reader.hpp @@ -0,0 +1,16 @@ +#ifndef XNA_CONTENT_READER_HPP +#define XNA_CONTENT_READER_HPP + +#include "../default.hpp" + +namespace xna { + class ContentReader { + public: + static sptr Create(ContentManager* contentManager, Stream& input, String const& assetName); + + private: + //ContentReader(ContentManager* contentManager, Stream& inut) + }; +} + +#endif \ No newline at end of file diff --git a/framework/csharp/binary.cpp b/framework/csharp/binary.cpp new file mode 100644 index 0000000..20adc25 --- /dev/null +++ b/framework/csharp/binary.cpp @@ -0,0 +1,651 @@ +#include "binary.hpp" + +namespace xna { + Int BinaryReader::PeekChar(xna_error_ptr_arg) + { + if (!stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return -1; + } + + const auto position = stream->Position(); + const auto num = Read(err); + + if (xna_error_haserros(err)) + return -1; + + stream->Seek(position, SeekOrigin::Begin, err); + + if (xna_error_haserros(err)) + return -1; + + return num; + } + + Int BinaryReader::Read(xna_error_ptr_arg) + { + if (!stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return -1; + } + + const auto result = InternalReadOneChar(err); + + return xna_error_haserros(err) ? -1 : result; + } + + bool BinaryReader::ReadBoolean(xna_error_ptr_arg) + { + FillBuffer(1, err); + return xna_error_haserros(err) ? false : buffer[0] > 0; + } + + Byte BinaryReader::ReadByte(xna_error_ptr_arg) + { + if (!stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return -1; + } + + const auto num = stream->ReadByte(); + + if (num == -1) + { + xna_error_apply(err, XnaErrorCode::END_OF_FILE); + return 0; + } + + return static_cast(num); + } + + Sbyte BinaryReader::ReadSByte(xna_error_ptr_arg) + { + FillBuffer(1, err); + return xna_error_haserros(err) ? -1 : static_cast(buffer[0]); + } + + Char BinaryReader::ReadChar(xna_error_ptr_arg) + { + auto num = Read(err); + + if (xna_error_haserros(err) || num == -1) + return '\0'; + + return static_cast(num); + } + + Short BinaryReader::ReadInt16(xna_error_ptr_arg) + { + FillBuffer(2, err); + + if (xna_error_haserros(err)) + return -1; + + return static_cast( + static_cast(buffer[0]) + | static_cast(buffer[1]) << 8); + } + + Ushort BinaryReader::ReadUInt16(xna_error_ptr_arg) + { + FillBuffer(2, err); + + if (xna_error_haserros(err)) + return 0; + + return static_cast( + static_cast(buffer[0]) + | static_cast(buffer[1]) << 8); + } + + Int BinaryReader::ReadInt32(xna_error_ptr_arg) + { + FillBuffer(4, err); + + if (xna_error_haserros(err)) + return -1; + + return static_cast(buffer[0]) + | static_cast(buffer[1]) << 8 + | static_cast(buffer[2]) << 16 + | static_cast(buffer[3]) << 24; + } + + Uint BinaryReader::ReadUInt32(xna_error_ptr_arg) + { + FillBuffer(4, err); + + if (xna_error_haserros(err)) + return -1; + + return static_cast( + static_cast(buffer[0]) + | static_cast(buffer[1]) << 8 + | static_cast(buffer[2]) << 16 + | static_cast(buffer[3]) << 24); + } + + Long BinaryReader::ReadInt64(xna_error_ptr_arg) + { + FillBuffer(8, err); + + if (xna_error_haserros(err)) + return -1; + + const auto num1 = static_cast( + static_cast(buffer[4]) + | static_cast(buffer[5]) << 8 + | static_cast(buffer[6]) << 16 + | static_cast(buffer[7]) << 24); + + const auto num2 = static_cast( + static_cast(buffer[0]) + | static_cast(buffer[1]) << 8 + | static_cast(buffer[2]) << 16 + | static_cast(buffer[3]) << 24); + + return static_cast(num1) << 32 | static_cast(num2); + } + + Ulong BinaryReader::ReadUInt64(xna_error_ptr_arg) + { + FillBuffer(8, err); + + if (xna_error_haserros(err)) + return 0; + + const auto num1 = static_cast( + static_cast(buffer[4]) + | static_cast(buffer[5]) << 8 + | static_cast(buffer[6]) << 16 + | static_cast(buffer[7]) << 24); + + const auto num2 = static_cast( + static_cast(buffer[0]) + | static_cast(buffer[1]) << 8 + | static_cast(buffer[2]) << 16 + | static_cast(buffer[3]) << 24); + + return static_cast(num1) << 32 | static_cast(num2); + } + + float BinaryReader::ReadSingle(xna_error_ptr_arg) + { + FillBuffer(4, err); + + if (xna_error_haserros(err)) + return std::numeric_limits::quiet_NaN(); + + const auto num = static_cast( + static_cast(buffer[0]) + | static_cast(buffer[1]) << 8 + | static_cast(buffer[2]) << 16 + | static_cast(buffer[3]) << 24); + + return *(float*)# + } + + double BinaryReader::ReadDouble(xna_error_ptr_arg) + { + FillBuffer(8, err); + + if (xna_error_haserros(err)) + return std::numeric_limits::quiet_NaN(); + + const auto num1 = static_cast( + static_cast(buffer[4]) + | static_cast(buffer[5]) << 8 + | static_cast(buffer[6]) << 16 + | static_cast(buffer[7]) << 24); + + const auto num2 = static_cast( + static_cast(buffer[0]) + | static_cast(buffer[1]) << 8 + | static_cast(buffer[2]) << 6 + | static_cast(buffer[3]) << 24); + + const auto num3 = static_cast(num1) << 32 | static_cast(num2); + + return *(double*)&num3; + } + + std::string BinaryReader::ReadString(xna_error_ptr_arg) + { + static const auto empty = std::string(); + + if (!stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return std::string(); + } + + Int num = 0; + auto val1 = Read7BitEncodedInt(err); + + if (xna_error_haserros(err)) + return empty; + + if (val1 < 0) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return empty; + } + + if (val1 == 0) + return empty; + + if (charBytes.empty()) + charBytes.resize(maxCharBytesSize); + + if (charBuffer.empty()) + charBuffer.resize(maxCharBytesSize); + + std::string sb; + + do { + const auto byteCount = stream->Read(charBytes, 0, val1 - num > 128 ? 128 : val1 - num); + + if (byteCount == 0) { + xna_error_apply(err, XnaErrorCode::END_OF_FILE); + return empty; + } + + auto data = reinterpret_cast(charBytes.data()); + const auto result = std::string(data); + + if (num == 0 && byteCount == val1) { + return result; + } + + sb.append(result); + num += byteCount; + + } while (num < val1); + + return empty; + } + + Int BinaryReader::InternalReadOneChar(xna_error_ptr_arg) + { + Int num1 = 0; + Long num2 = 0; + Long num3 = stream->Position(); + + if (charBytes.empty()) + charBytes.resize(128); + + if (singleChar.empty()) + singleChar.resize(1); + + while (num1 == 0) + { + auto byteCount = m2BytesPerChar ? 2 : 1; + const auto num4 = stream->ReadByte(); + + charBytes[0] = static_cast(num4); + + if (num4 == -1) + byteCount = 0; + + if (byteCount == 2) { + auto num5 = stream->ReadByte(); + charBytes[1] = static_cast(num5); + + if (num5 == -1) + byteCount = 1; + } + + if (byteCount == 0) { + return -1; + } + + auto data = reinterpret_cast(charBytes.data()); + const auto result = std::string(data, data + byteCount); + + if (!result.empty()) + { + num1 = static_cast(result.size()); + singleChar[0] = result[0]; + } + } + + return num1 == 0 ? -1 : static_cast(singleChar[0]); + } + + void BinaryReader::FillBuffer(Int numBytes, xna_error_ptr_arg) + { + if (!stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + if (!buffer.empty() && (numBytes < 0 || numBytes > buffer.size())) { + xna_error_apply(err, XnaErrorCode::ARGUMENT_OUT_OF_RANGE); + return; + } + + int offset = 0; + + if (numBytes == 1) + { + + const auto num = stream->ReadByte(); + if (num == -1) { + xna_error_apply(err, XnaErrorCode::END_OF_FILE); + return; + } + + buffer[0] = static_cast(num); + } + else + { + do + { + const auto num = stream->Read(buffer, offset, numBytes - offset); + + if (num == 0) + { + xna_error_apply(err, XnaErrorCode::END_OF_FILE); + return; + } + + offset += num; + } while (offset < numBytes); + } + } + + Int BinaryReader::InternalReadChars(char* buffer, size_t bufferSize, Int index, Int count, xna_error_ptr_arg) + { + auto charCount = count; + + if (charBytes.empty()) + charBytes.resize(128); + + while (charCount > 0) { + auto count1 = charCount; + + if (count1 > 1) + --count1; + + if (m2BytesPerChar) + count1 <<= 1; + + if (count1 > 128) + count1 = 128; + + Int num = 0; + Int byteCount; + + std::vector numArray; + + byteCount = stream->Read(charBytes, 0, count1); + numArray = charBytes; + + if (byteCount == 0) + return count - charCount; + + if (num < 0 || byteCount < 0 || (num + byteCount) > numArray.size()) { + xna_error_apply(err, XnaErrorCode::ARGUMENT_OUT_OF_RANGE); + return -1; + } + + if (index < 0 || charCount < 0 || (index + charCount) > bufferSize) { + xna_error_apply(err, XnaErrorCode::ARGUMENT_OUT_OF_RANGE); + return -1; + } + + auto data = reinterpret_cast(charBytes.data()); + const auto result = std::string((data + num), (data + num) + byteCount); + + const auto chars = result.size(); + + charCount -= static_cast(chars); + index += static_cast(chars); + } + + return count - charCount; + } + + Long BinaryWriter::Seek(Int offset, SeekOrigin origin, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return - 1; + } + + return _stream->Seek(offset, origin); + } + + void BinaryWriter::Write(bool value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _buffer[0] = value ? (Byte)1 : (Byte)0; + _stream->Write(_buffer, 0, 1); + } + + void BinaryWriter::Write(Byte value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _stream->WriteByte(value); + } + + void BinaryWriter::Write(Sbyte value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _stream->WriteByte(static_cast(value)); + } + + void BinaryWriter::Write(Byte const* buffer, Int bufferLength, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _stream->Write(buffer, bufferLength, 0, bufferLength); + } + + void BinaryWriter::Write(std::vector const& buffer, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _stream->Write(buffer, 0, static_cast(buffer.size())); + } + void BinaryWriter::Write(Byte const* buffer, Int bufferLength, Int index, Int count, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _stream->Write(buffer, bufferLength, index, count); + } + + void BinaryWriter::Write(std::vector const& buffer, Int index, Int count, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _stream->Write(buffer, index, count); + } + + void BinaryWriter::Write(Char ch, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _buffer[0] = static_cast(ch); + _stream->Write(_buffer, 0, 1); + } + + void BinaryWriter::Write(double value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + Ulong num = (Ulong) * (Long*)&value; + _buffer[0] = static_cast(num); + _buffer[1] = static_cast(num >> 8); + _buffer[2] = static_cast(num >> 16); + _buffer[3] = static_cast(num >> 24); + _buffer[4] = static_cast(num >> 32); + _buffer[5] = static_cast(num >> 40); + _buffer[6] = static_cast(num >> 48); + _buffer[7] = static_cast(num >> 56); + + _stream->Write(_buffer, 0, 8); + } + + void BinaryWriter::Write(Short value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _buffer[0] = static_cast(value); + _buffer[1] = static_cast((Uint)value >> 8); + _stream->Write(_buffer, 0, 2); + } + + void BinaryWriter::Write(Ushort value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _buffer[0] = static_cast(value); + _buffer[1] = static_cast((Uint)value >> 8); + _stream->Write(_buffer, 0, 2); + } + + void BinaryWriter::Write(Int value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _buffer[0] = static_cast(value); + _buffer[1] = static_cast(value >> 8); + _buffer[2] = static_cast(value >> 16); + _buffer[3] = static_cast(value >> 24); + _stream->Write(_buffer, 0, 4); + } + + void BinaryWriter::Write(Uint value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _buffer[0] = static_cast(value); + _buffer[1] = static_cast(value >> 8); + _buffer[2] = static_cast(value >> 16); + _buffer[3] = static_cast(value >> 24); + _stream->Write(_buffer, 0, 4); + } + + void BinaryWriter::Write(Ulong value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _buffer[0] = static_cast(value); + _buffer[1] = static_cast(value >> 8); + _buffer[2] = static_cast(value >> 16); + _buffer[3] = static_cast(value >> 24); + _buffer[4] = static_cast(value >> 32); + _buffer[5] = static_cast(value >> 40); + _buffer[6] = static_cast(value >> 48); + _buffer[7] = static_cast(value >> 56); + _stream->Write(_buffer, 0, 8); + } + + void BinaryWriter::Write(float value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + Uint num = *(Uint*)&value; + _buffer[0] = static_cast(num); + _buffer[1] = static_cast(num >> 8); + _buffer[2] = static_cast(num >> 16); + _buffer[3] = static_cast(num >> 24); + _stream->Write(_buffer, 0, 4); + } + + void BinaryWriter::Write(std::string const& value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + Write(value.c_str(), value.size()); + } + + void BinaryWriter::Write(const char* _string, size_t stringLength, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + Write7BitEncodedInt(static_cast(stringLength)); + const auto b = reinterpret_cast(_string); + _stream->Write(b, static_cast(stringLength), 0, static_cast(stringLength)); + } + + void BinaryWriter::Write7BitEncodedInt(Int value) + { + Uint num; + for (num = (Uint)value; num >= (Uint)128U; num >>= 7) + Write((Byte)(num | (Uint)128U)); + + Write((Byte)num); + } + + void BinaryWriter::Write(Long value, xna_error_ptr_arg) + { + if (!_stream) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + _buffer[0] = static_cast(value); + _buffer[1] = static_cast(value >> 8); + _buffer[2] = static_cast(value >> 16); + _buffer[3] = static_cast(value >> 24); + _buffer[4] = static_cast(value >> 32); + _buffer[5] = static_cast(value >> 40); + _buffer[6] = static_cast(value >> 48); + _buffer[7] = static_cast(value >> 56); + _stream->Write(_buffer, 0, 8); + } +} \ No newline at end of file diff --git a/framework/csharp/binary.hpp b/framework/csharp/binary.hpp new file mode 100644 index 0000000..a8ad428 --- /dev/null +++ b/framework/csharp/binary.hpp @@ -0,0 +1,114 @@ +#ifndef XNA_CSHARP_BINARY_HPP +#define XNA_CSHARP_BINARY_HPP + +#include "stream.hpp" +#include "../default.hpp" + +namespace xna { + class BinaryReader { + public: + BinaryReader(Stream* const& input) { + stream = input; + buffer = std::vector(bufferLength); + } + + Int PeekChar(xna_error_nullarg); + Int Read(xna_error_nullarg); + bool ReadBoolean(xna_error_nullarg); + Byte ReadByte(xna_error_nullarg); + Sbyte ReadSByte(xna_error_nullarg); + Char ReadChar(xna_error_nullarg); + Short ReadInt16(xna_error_nullarg); + Ushort ReadUInt16(xna_error_nullarg); + Int ReadInt32(xna_error_nullarg); + Uint ReadUInt32(xna_error_nullarg); + Long ReadInt64(xna_error_nullarg); + Ulong ReadUInt64(xna_error_nullarg); + float ReadSingle(xna_error_nullarg); + double ReadDouble(xna_error_nullarg); + std::string ReadString(xna_error_nullarg); + + Int Read(std::vector& buffer, size_t index, size_t count, xna_error_nullarg) { + return -1; + } + + std::vector ReadBytes(size_t count, xna_error_nullarg) { + return std::vector(); + } + + private: + static constexpr int maxCharBytesSize = 128; + static constexpr int bufferLength = 16; + Stream* stream = nullptr; + std::vector charBytes; + std::vector singleChar; + std::vector buffer; + std::vector charBuffer; + + bool m2BytesPerChar{ false }; + + Int InternalReadOneChar(xna_error_nullarg); + + void FillBuffer(Int numBytes, xna_error_nullarg); + + Int Read7BitEncodedInt(xna_error_nullarg) + { + Int num1 = 0; + Int num2 = 0; + + while (num2 != 35) { + auto num3 = ReadByte(err); + + if (xna_error_haserros(err)) + return -1; + + num1 |= (static_cast(num3) & static_cast(SbyteMaxValue)) << num2; + num2 += 7; + + if ((static_cast(num3) & 128) == 0) + return num1; + } + + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return -1; + } + + Int InternalReadChars(char* buffer, size_t bufferSize, Int index, Int count, xna_error_nullarg); + }; + + class BinaryWriter { + public: + BinaryWriter(Stream* stream) : _stream(stream), _buffer(16) { + } + + Long Seek(Int offset, SeekOrigin origin, xna_error_nullarg); + + void Write(bool value, xna_error_nullarg); + void Write(Byte value, xna_error_nullarg); + void Write(Sbyte value, xna_error_nullarg); + void Write(Byte const* buffer, Int bufferLength, xna_error_nullarg); + void Write(std::vector const& buffer, xna_error_nullarg); + void Write(Byte const* buffer, Int bufferLength, Int index, Int count, xna_error_nullarg); + void Write(std::vector const& buffer, Int index, Int count, xna_error_nullarg); + void Write(Char ch, xna_error_nullarg); + void Write(double value, xna_error_nullarg); + void Write(Short value, xna_error_nullarg); + void Write(Ushort value, xna_error_nullarg); + void Write(Int value, xna_error_nullarg); + void Write(Uint value, xna_error_nullarg); + void Write(Long value, xna_error_nullarg); + void Write(Ulong value, xna_error_nullarg); + void Write(float value, xna_error_nullarg); + void Write(std::string const& value, xna_error_nullarg); + void Write(const char* _string, size_t stringLength, xna_error_nullarg); + + public: + Stream* _stream; + + private: + std::vector _buffer; + void Write7BitEncodedInt(Int value); + }; +} + +#endif \ No newline at end of file diff --git a/framework/forward.hpp b/framework/forward.hpp index 58adc53..4df05f8 100644 --- a/framework/forward.hpp +++ b/framework/forward.hpp @@ -16,6 +16,10 @@ namespace xna { class FileStream; class MemoryStream; + //Content + class ContentManager; + class ContentReader; + //Framework class BoundingBox; class BoundingFrustum; diff --git a/framework/platform/game-dx.hpp b/framework/platform/game-dx.hpp index 769cea5..b1b42c0 100644 --- a/framework/platform/game-dx.hpp +++ b/framework/platform/game-dx.hpp @@ -58,7 +58,7 @@ namespace xna { void step(); sptr _gameComponents = nullptr; std::vector> _drawableGameComponents; - Uint _drawableGameComponentsCount{ 0 }; + size_t _drawableGameComponentsCount{ 0 }; bool _enabledGameComponents{ false }; }; } diff --git a/framework/xna.cpp b/framework/xna.cpp index 2be7edb..615e12d 100644 --- a/framework/xna.cpp +++ b/framework/xna.cpp @@ -13,7 +13,12 @@ namespace xna { auto _game = reinterpret_cast(this); graphics = New(_game); graphics->PreferredBackBufferWidth(1280); - graphics->PreferredBackBufferHeight(720); + graphics->PreferredBackBufferHeight(720); + + contentManager = New("Content"); + //const auto s = contentManager->_path.string(); + // const auto current = std::filesystem::current_path(); + auto s = contentManager->OpenStream("file"); } void Initialize() override { @@ -57,6 +62,7 @@ namespace xna { MouseState oldState{}; float vel = 1; int var = 0; + sptr contentManager; }; } diff --git a/framework/xna.h b/framework/xna.h index 7a0a6eb..e81e780 100644 --- a/framework/xna.h +++ b/framework/xna.h @@ -23,5 +23,6 @@ #include "game/component.hpp" #include "Windows.h" #include +#include "content/manager.hpp" // TODO: Reference additional headers your program requires here. diff --git a/framework/xnaerror.hpp b/framework/xnaerror.hpp index 8c32ec7..bd0a11b 100644 --- a/framework/xnaerror.hpp +++ b/framework/xnaerror.hpp @@ -12,7 +12,8 @@ namespace xna { NULL_CAST, BAD_CAST, STREAM_ERROR, - UNINTIALIZED_RESOURCE + UNINTIALIZED_RESOURCE, + END_OF_FILE }; inline void xna_error_apply(XnaErrorCode* source, XnaErrorCode const& value) {