From 1fd737dfa3eec3b29452845f6aaf755bd6980489 Mon Sep 17 00:00:00 2001 From: Danilo Date: Sat, 13 Jul 2024 22:50:52 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=B5es=20e=20implementa=C3=A7?= =?UTF-8?q?=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/CMakeLists.txt | 2 +- framework/content/manager.cpp | 7 +- framework/csharp/binary.cpp | 59 ++-- framework/csharp/stream.cpp | 5 +- framework/exception.cpp | 37 ++ framework/platform-dx/game.cpp | 8 +- inc/xna/content/manager.hpp | 33 +- inc/xna/content/reader.hpp | 38 ++- inc/xna/csharp/binary.hpp | 90 +++-- inc/xna/csharp/stream.hpp | 39 +-- inc/xna/default.hpp | 204 ++++++++++- inc/xna/{enums.hpp => enumerations.hpp} | 316 +++++++++--------- inc/xna/exception.hpp | 33 +- inc/xna/forward.hpp | 96 ------ inc/xna/game/time.hpp | 3 +- inc/xna/graphics/sprite.hpp | 1 - inc/xna/helpers.hpp | 4 +- inc/xna/types.hpp | 94 ------ inc/xna/xna.hpp | 4 +- samples/01_blank/xna.cpp | 1 - .../02_PlatfformerStarterKit/animation.hpp | 2 +- samples/02_PlatfformerStarterKit/circle.hpp | 2 +- samples/02_PlatfformerStarterKit/enemy.hpp | 2 +- samples/02_PlatfformerStarterKit/game.cpp | 3 +- samples/02_PlatfformerStarterKit/gem.hpp | 2 +- samples/02_PlatfformerStarterKit/headers.hpp | 2 + samples/02_PlatfformerStarterKit/level.hpp | 2 +- samples/02_PlatfformerStarterKit/player.hpp | 2 +- samples/02_PlatfformerStarterKit/tile.hpp | 2 + 29 files changed, 573 insertions(+), 520 deletions(-) create mode 100644 framework/exception.cpp rename inc/xna/{enums.hpp => enumerations.hpp} (70%) delete mode 100644 inc/xna/forward.hpp delete mode 100644 inc/xna/types.hpp create mode 100644 samples/02_PlatfformerStarterKit/headers.hpp diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 4541fb7..9d2d114 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -40,7 +40,7 @@ add_library (Xn65 STATIC "platform-dx/audioengine.cpp" "graphics/gresource.cpp" "platform-dx/effect.cpp" -) + "exception.cpp") if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET Xn65 PROPERTY CXX_STANDARD 20) diff --git a/framework/content/manager.cpp b/framework/content/manager.cpp index c20cb6d..79bce6e 100644 --- a/framework/content/manager.cpp +++ b/framework/content/manager.cpp @@ -2,11 +2,8 @@ namespace xna { sptr ContentManager::OpenStream(String const& assetName) const { - const String filePath = _rootDirectory + "\\" + assetName + contentExtension; - const auto stream = snew(filePath, FileMode::Open); - - if (stream->IsClosed()) - return nullptr; + const String filePath = rootDirectory + "\\" + assetName + contentExtension; + const auto stream = snew(filePath, FileMode::Open); return reinterpret_pointer_cast(stream); } diff --git a/framework/csharp/binary.cpp b/framework/csharp/binary.cpp index c5639a7..dba28e0 100644 --- a/framework/csharp/binary.cpp +++ b/framework/csharp/binary.cpp @@ -2,6 +2,13 @@ #include "xna/csharp/buffer.hpp" namespace xna { + BinaryReader::BinaryReader(sptr const& input) { + Exception::ThrowIfNull(input, nameof(input)); + + stream = input; + buffer = std::vector(bufferLength); + } + Int BinaryReader::PeekChar() { const auto position = stream->Position(); @@ -256,7 +263,7 @@ namespace xna { void BinaryReader::FillBuffer(Int numBytes) { if (numBytes < 0 || numBytes > buffer.size()) { - throw std::out_of_range("numBytes"); + Exception::Throw(Exception::OUT_OF_BOUNDS); } Int bytesRead = 0; @@ -266,7 +273,7 @@ namespace xna { n = stream->ReadByte(); if (n == -1){ - throw std::runtime_error("End of file."); + Exception::Throw(Exception::END_OF_FILE); } buffer[0] = static_cast(n); @@ -277,7 +284,7 @@ namespace xna { n = stream->Read(buffer, bytesRead, numBytes - bytesRead); if (n == 0) { - throw std::runtime_error("End of file."); + Exception::Throw(Exception::END_OF_FILE); } bytesRead += n; @@ -432,50 +439,58 @@ namespace xna { //Binary Writer + BinaryWriter::BinaryWriter(sptr const& stream) { + Exception::ThrowIfNull(stream, nameof(stream)); + + OutStream = stream; + _buffer = std::vector(16); + } + Long BinaryWriter::Seek(Int offset, SeekOrigin origin) { - return _stream->Seek(offset, origin); + return OutStream->Seek(offset, origin); } void BinaryWriter::Write(bool value) { - _buffer[0] = value ? (Byte)1 : (Byte)0; - _stream->Write(_buffer, 0, 1); + _buffer[0] = value ? static_cast(1) : static_cast(0); + OutStream->Write(_buffer, 0, 1); } void BinaryWriter::Write(Byte value) { - _stream->WriteByte(value); + OutStream->WriteByte(value); } void BinaryWriter::Write(Sbyte value) { - _stream->WriteByte(static_cast(value)); + OutStream->WriteByte(static_cast(value)); } void BinaryWriter::Write(Byte const* buffer, Int bufferLength) { - _stream->Write(buffer, bufferLength, 0, bufferLength); + OutStream->Write(buffer, bufferLength, 0, bufferLength); } void BinaryWriter::Write(std::vector const& buffer) { - _stream->Write(buffer, 0, static_cast(buffer.size())); + OutStream->Write(buffer, 0, static_cast(buffer.size())); } + void BinaryWriter::Write(Byte const* buffer, Int bufferLength, Int index, Int count) { - _stream->Write(buffer, bufferLength, index, count); + OutStream->Write(buffer, bufferLength, index, count); } void BinaryWriter::Write(std::vector const& buffer, Int index, Int count) { - _stream->Write(buffer, index, count); + OutStream->Write(buffer, index, count); } void BinaryWriter::Write(Char ch) { _buffer[0] = static_cast(ch); - _stream->Write(_buffer, 0, 1); + OutStream->Write(_buffer, 0, 1); } void BinaryWriter::Write(double value) @@ -490,21 +505,21 @@ namespace xna { _buffer[6] = static_cast(num >> 48); _buffer[7] = static_cast(num >> 56); - _stream->Write(_buffer, 0, 8); + OutStream->Write(_buffer, 0, 8); } void BinaryWriter::Write(Short value) { _buffer[0] = static_cast(value); _buffer[1] = static_cast((Uint)value >> 8); - _stream->Write(_buffer, 0, 2); + OutStream->Write(_buffer, 0, 2); } void BinaryWriter::Write(Ushort value) { _buffer[0] = static_cast(value); _buffer[1] = static_cast((Uint)value >> 8); - _stream->Write(_buffer, 0, 2); + OutStream->Write(_buffer, 0, 2); } void BinaryWriter::Write(Int value) @@ -513,7 +528,7 @@ namespace xna { _buffer[1] = static_cast(value >> 8); _buffer[2] = static_cast(value >> 16); _buffer[3] = static_cast(value >> 24); - _stream->Write(_buffer, 0, 4); + OutStream->Write(_buffer, 0, 4); } void BinaryWriter::Write(Uint value) @@ -522,7 +537,7 @@ namespace xna { _buffer[1] = static_cast(value >> 8); _buffer[2] = static_cast(value >> 16); _buffer[3] = static_cast(value >> 24); - _stream->Write(_buffer, 0, 4); + OutStream->Write(_buffer, 0, 4); } void BinaryWriter::Write(Ulong value) @@ -535,7 +550,7 @@ namespace xna { _buffer[5] = static_cast(value >> 40); _buffer[6] = static_cast(value >> 48); _buffer[7] = static_cast(value >> 56); - _stream->Write(_buffer, 0, 8); + OutStream->Write(_buffer, 0, 8); } void BinaryWriter::Write(float value) @@ -545,7 +560,7 @@ namespace xna { _buffer[1] = static_cast(num >> 8); _buffer[2] = static_cast(num >> 16); _buffer[3] = static_cast(num >> 24); - _stream->Write(_buffer, 0, 4); + OutStream->Write(_buffer, 0, 4); } void BinaryWriter::Write(std::string const& value) @@ -557,7 +572,7 @@ namespace xna { { Write7BitEncodedInt(static_cast(stringLength)); const auto b = reinterpret_cast(_string); - _stream->Write(b, static_cast(stringLength), 0, static_cast(stringLength)); + OutStream->Write(b, static_cast(stringLength), 0, static_cast(stringLength)); } void BinaryWriter::Write7BitEncodedInt(Int value) @@ -579,6 +594,6 @@ namespace xna { _buffer[5] = static_cast(value >> 40); _buffer[6] = static_cast(value >> 48); _buffer[7] = static_cast(value >> 56); - _stream->Write(_buffer, 0, 8); + OutStream->Write(_buffer, 0, 8); } } \ No newline at end of file diff --git a/framework/csharp/stream.cpp b/framework/csharp/stream.cpp index 09aaeb9..09b2dd1 100644 --- a/framework/csharp/stream.cpp +++ b/framework/csharp/stream.cpp @@ -168,14 +168,13 @@ namespace xna { _fstream.open(path.c_str(), flags); if (!_fstream.good()) - _closed = true; + Exception::Throw("Failed to open file: " + path); } FileStream::FileStream(String const& path) { int flags = std::fstream::in | std::fstream::out | std::fstream::binary; - //| std::fstream::ate; const auto exists = std::filesystem::exists(path); @@ -185,7 +184,7 @@ namespace xna { _fstream.open(path.c_str(), flags); if (!_fstream.good()) - _closed = true; + Exception::Throw("Failed to open file: " + path); } Int FileStream::Length() { diff --git a/framework/exception.cpp b/framework/exception.cpp new file mode 100644 index 0000000..9fca374 --- /dev/null +++ b/framework/exception.cpp @@ -0,0 +1,37 @@ +#include "xna/exception.hpp" + +namespace xna { + void Exception::Throw(std::string const& message, std::source_location const& location) { + std::string error; + + error.append("Exception in: "); +#if _DEBUG + error.append(location.file_name()); + error.append("("); + error.append(std::to_string(location.line())); + error.append(":"); + error.append(std::to_string(location.column())); + error.append(") "); +#endif + error.append("': "); + error.append(location.function_name()); + error.append("': "); + error.append(message); + error.append("\n"); + + throw std::runtime_error(error); + } + + void Exception::ThrowIfNull(void const* argument, std::string const& argumentName, std::source_location const& location) { + if (argument) + return; + + std::string error; + + error.append("The value of "); + error.append(argumentName); + error.append(" is null."); + + Throw(error); + } +} \ No newline at end of file diff --git a/framework/platform-dx/game.cpp b/framework/platform-dx/game.cpp index 764002b..2c20d82 100644 --- a/framework/platform-dx/game.cpp +++ b/framework/platform-dx/game.cpp @@ -1,9 +1,3 @@ -#include "xna/content/manager.hpp" -#include "xna/csharp/type.hpp" -#include "xna/game/component.hpp" -#include "xna/game/gdevicemanager.hpp" -#include "xna/game/servicecontainer.hpp" -#include "xna/game/time.hpp" #include "xna/platform/dx.hpp" namespace xna { @@ -12,7 +6,7 @@ namespace xna { services = snew(); auto iservice = reinterpret_pointer_cast(services); _contentManager = snew(services, ""); - _contentManager->_gameServices = iservice; + _contentManager->mainGameService = iservice; _gameWindow = snew(); _gameWindow->impl->Color(146, 150, 154); diff --git a/inc/xna/content/manager.hpp b/inc/xna/content/manager.hpp index 810a12a..ec70e7d 100644 --- a/inc/xna/content/manager.hpp +++ b/inc/xna/content/manager.hpp @@ -5,35 +5,34 @@ #include "../csharp/stream.hpp" #include "../default.hpp" #include "reader.hpp" -#include namespace xna { //The run-time component which loads managed objects from the binary files produced by the design time content pipeline. class ContentManager : public std::enable_shared_from_this { public: ContentManager(sptr const& services) : - _rootDirectory("") { - _services = services; + rootDirectory("") { + serviceProvider = services; }; ContentManager(sptr const& services, String const& rootDirectory) : - _rootDirectory(rootDirectory){ - _services = services; + rootDirectory(rootDirectory){ + serviceProvider = services; }; //Gets the service provider associated with the ContentManager. sptr ServiceProvider() const { - return _services; + return serviceProvider; } //Gets or sets the root directory associated with this ContentManager. constexpr String RootDirectory() const { - return _rootDirectory; + return rootDirectory; } //Gets or sets the root directory associated with this ContentManager. void RootDirectory(String const& value) { - _rootDirectory = value; + rootDirectory = value; } //Loads an asset that has been processed by the Content Pipeline. @@ -45,8 +44,8 @@ namespace xna { if constexpr (XnaHelper::is_shared_ptr::value) { - if (_loadedAssets.contains(assetName)) { - auto& voidAsset = _loadedAssets[assetName]; + if (loadedAssets.contains(assetName)) { + auto& voidAsset = loadedAssets[assetName]; using TYPE = T::element_type; auto asset = reinterpret_pointer_cast(voidAsset); return asset; @@ -58,7 +57,7 @@ namespace xna { if constexpr (XnaHelper::is_shared_ptr::value) { if(obj2) - _loadedAssets.emplace( assetName, obj2 ); + loadedAssets.emplace( assetName, obj2 ); } return obj2; @@ -66,12 +65,12 @@ namespace xna { //Disposes all data that was loaded by this ContentManager. void Unload() { - _loadedAssets.clear(); + loadedAssets.clear(); } //Gets the service provider associated with the main Game. static sptr GameServiceProvider() { - return _gameServices; + return mainGameService; } protected: @@ -95,11 +94,11 @@ namespace xna { friend class ContentReader; friend class Game; - String _rootDirectory; - sptr _services = nullptr; - std::map> _loadedAssets; + String rootDirectory; + sptr serviceProvider = nullptr; + std::map> loadedAssets; - inline static sptr _gameServices = nullptr; + inline static sptr mainGameService = nullptr; inline const static String contentExtension = ".xnb"; }; } diff --git a/inc/xna/content/reader.hpp b/inc/xna/content/reader.hpp index 7dc926e..a96f6d1 100644 --- a/inc/xna/content/reader.hpp +++ b/inc/xna/content/reader.hpp @@ -21,7 +21,7 @@ namespace xna { // Reads a single object from the current stream. template - auto ReadObject(T existingInstance); + auto ReadObject(T& existingInstance); // Reads a single object from the current stream. template @@ -29,7 +29,7 @@ namespace xna { // Reads a single object from the current stream. template - auto ReadObject(ContentTypeReader& typeReader, T existingInstance); + auto ReadObject(ContentTypeReader& typeReader, T& existingInstance); //Reads a Vector2 value from the current stream. Vector2 ReadVector2(); @@ -44,9 +44,9 @@ namespace xna { //Reads a Color value from the currently open stream. Color ReadColor(); //Reads a float value from the currently open stream. - float ReadSingle(); + float ReadSingle() override; //Reads a double value from the currently open stream. - double ReadDouble(); + double ReadDouble() override; //Gets the name of the asset currently being read by this ContentReader. constexpr String AssetName() const { @@ -77,10 +77,10 @@ namespace xna { auto ReadObjectInternal(std::any& existingInstance); template - auto ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance); + auto ReadObjectInternal(ContentTypeReader& typeReader, Object& existingInstance); template - auto InvokeReader(ContentTypeReader& reader, std::any& existingInstance); + auto InvokeReader(ContentTypeReader& reader, Object& existingInstance); private: sptr _contentManager = nullptr; @@ -93,10 +93,13 @@ namespace xna { static constexpr Ushort XnbCompressedVersion = 32773; static constexpr Ushort XnbVersion = 5; static constexpr Int XnbVersionProfileShift = 8; + static constexpr Char PlatformLabel = 'w'; + static constexpr Int XnbPrologueSize = 10; + static constexpr Int XnbCompressedPrologueSize = 14; }; template - inline auto ContentReader::ReadObjectInternal(std::any& existingInstance) + inline auto ContentReader::ReadObjectInternal(Object& existingInstance) { const auto num = Read7BitEncodedInt(); @@ -107,16 +110,16 @@ namespace xna { const auto index = num - 1; if (index >= typeReaders.size()) { - throw std::runtime_error("ContentReader::ReadObjectInternal: Bad xbn."); + Exception::Throw(Exception::BAD_XNB); } - auto reader = typeReaders[index]; + auto& reader = typeReaders[index]; return InvokeReader(*reader, existingInstance); } template - inline auto ContentReader::InvokeReader(ContentTypeReader& reader, std::any& existingInstance) + inline auto ContentReader::InvokeReader(ContentTypeReader& reader, Object& existingInstance) { auto contentTypeReader = reinterpret_cast*>(&reader); T objB; @@ -149,9 +152,9 @@ namespace xna { } template - inline auto ContentReader::ReadObject(T existingInstance) + inline auto ContentReader::ReadObject(T& existingInstance) { - return ReadObjectInternal(std::any(existingInstance)); + return ReadObjectInternal(Object(existingInstance)); } template @@ -162,17 +165,18 @@ namespace xna { } template - inline auto ContentReader::ReadObject(ContentTypeReader& typeReader, T existingInstance) + inline auto ContentReader::ReadObject(ContentTypeReader& typeReader, T& existingInstance) { return ReadObjectInternal(typeReader, std::any(existingInstance)); } template - inline auto ContentReader::ReadObjectInternal(ContentTypeReader& typeReader, std::any& existingInstance) + inline auto ContentReader::ReadObjectInternal(ContentTypeReader& typeReader, Object& existingInstance) { - return typeReader.TargetIsValueType - ? InvokeReader(typeReader, existingInstance) - : ReadObjectInternal(existingInstance); + if (typeReader.TargetIsValueType) + return InvokeReader(typeReader, existingInstance); + + ReadObjectInternal(existingInstance); } } diff --git a/inc/xna/csharp/binary.hpp b/inc/xna/csharp/binary.hpp index a7778c2..c81b5cb 100644 --- a/inc/xna/csharp/binary.hpp +++ b/inc/xna/csharp/binary.hpp @@ -8,53 +8,47 @@ namespace xna { //A simplified port of the System.IO.BinaryReader class. class BinaryReader { public: - BinaryReader(sptr const& input) { - if (!input) - throw std::invalid_argument("input is null."); - - stream = input; - buffer = std::vector(bufferLength); - } + BinaryReader(sptr const& input); //Returns the next available character and does not advance the byte or character position. Int PeekChar(); //Reads bytes from the underlying stream and advances the current position of the stream. - Int Read(); + virtual Int Read(); //Reads a Boolean value from the current stream and advances the current position of the stream by one byte. - bool ReadBoolean(); + virtual bool ReadBoolean(); //Reads the next byte from the current stream and advances the current position of the stream by one byte. - Byte ReadByte(); + virtual Byte ReadByte(); //Reads a signed byte from this stream and advances the current position of the stream by one byte. - Sbyte ReadSByte(); + virtual Sbyte ReadSByte(); //Reads the next character from the current stream and advances the current position of the stream. - Char ReadChar(); + virtual Char ReadChar(); //Reads a 2-byte signed integer from the current stream and advances the current position of the stream by two bytes. - Short ReadInt16(); + virtual Short ReadInt16(); //Reads a 2-byte unsigned integer from the current stream and advances the position of the stream by two bytes. - Ushort ReadUInt16(); + virtual Ushort ReadUInt16(); //Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes. - Int ReadInt32(); + virtual Int ReadInt32(); //Reads a 4-byte unsigned integer from the current stream and advances the position of the stream by four bytes. - Uint ReadUInt32(); + virtual Uint ReadUInt32(); //Reads a 8-byte signed integer from the current stream and advances the current position of the stream by eight bytes. - Long ReadInt64(); + virtual Long ReadInt64(); //Reads a 8-byte unsigned integer from the current stream and advances the position of the stream by eight bytes. - Ulong ReadUInt64(); + virtual Ulong ReadUInt64(); //Reads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes. - float ReadSingle(); + virtual float ReadSingle(); //Reads an 8-byte floating point value from the current stream and advances the current position of the stream by eight bytes. - double ReadDouble(); + virtual double ReadDouble(); //Reads a string from the current stream. - std::string ReadString(); + virtual std::string ReadString(); //Reads chars from the underlying stream and advances the current position of the stream. - Int Read(std::vector& buffer, size_t index, size_t count); + virtual Int Read(std::vector& buffer, size_t index, size_t count); //Reads bytes from the underlying stream and advances the current position of the stream. - Int Read(std::vector& buffer, size_t index, size_t count); + virtual Int Read(std::vector& buffer, size_t index, size_t count); // Reads the specified number of bytes from the current stream into a byte array // and advances the current position by that number of bytes. - std::vector ReadBytes(size_t count); + virtual std::vector ReadBytes(size_t count); // Reads a 32-bit integer in compressed format. // This function may throw a std::format_error exception. @@ -64,6 +58,16 @@ namespace xna { // This function may throw a std::format_error exception. Long Read7BitEncodedInt64(); + //Exposes access to the underlying stream of the BinaryReader. + virtual inline sptr BaseStream() const { + return stream; + } + + //Closes the current reader and the underlying stream. + virtual inline void Close() { + stream = nullptr; + } + protected: Int InternalReadOneChar(); void FillBuffer(Int numBytes); @@ -79,20 +83,12 @@ namespace xna { std::vector charBuffer; //bool m2BytesPerChar{ false }; - }; + }; //A simplified port of the System.IO.BinaryWriter class. class BinaryWriter { public: - BinaryWriter(sptr const& stream) { - if (!stream) - throw std::invalid_argument("stream is null."); - - _stream = stream; - _buffer = std::vector(16); - } - - virtual ~BinaryWriter() = default; + BinaryWriter(sptr const& stream); protected: BinaryWriter() = default; @@ -104,32 +100,56 @@ namespace xna { // Writes a value to the current stream. // + //Writes a value to the current stream. virtual void Write(bool value); + //Writes a value to the current stream. virtual void Write(Byte value); + //Writes a value to the current stream. virtual void Write(Sbyte value); + //Writes a value to the current stream. virtual void Write(Byte const* buffer, Int bufferLength); + //Writes a value to the current stream. virtual void Write(std::vector const& buffer); + //Writes a value to the current stream. virtual void Write(Byte const* buffer, Int bufferLength, Int index, Int count); + //Writes a value to the current stream. virtual void Write(std::vector const& buffer, Int index, Int count); + //Writes a value to the current stream. virtual void Write(Char ch); + //Writes a value to the current stream. virtual void Write(double value); + //Writes a value to the current stream. virtual void Write(Short value); + //Writes a value to the current stream. virtual void Write(Ushort value); + //Writes a value to the current stream. virtual void Write(Int value); + //Writes a value to the current stream. virtual void Write(Uint value); + //Writes a value to the current stream. virtual void Write(Long value); + //Writes a value to the current stream. virtual void Write(Ulong value); + //Writes a value to the current stream. virtual void Write(float value); + //Writes a value to the current stream. virtual void Write(std::string const& value); + //Writes a value to the current stream. virtual void Write(const char* _string, size_t stringLength); + //Exposes access to the underlying stream of the BinaryWriter. + virtual inline sptr BaseStream() const { + return OutStream; + } + //Writes a 32-bit integer in a compressed format. void Write7BitEncodedInt(Int value); //void Write7BitEncodedInt64(Long value); + protected: + sptr OutStream = nullptr; private: - sptr _stream = nullptr; std::vector _buffer; }; } diff --git a/inc/xna/csharp/stream.hpp b/inc/xna/csharp/stream.hpp index 8e8d4b7..4e33bfe 100644 --- a/inc/xna/csharp/stream.hpp +++ b/inc/xna/csharp/stream.hpp @@ -1,12 +1,15 @@ #ifndef XNA_CSHARP_STREAM_HPP #define XNA_CSHARP_STREAM_HPP -#include "../types.hpp" -#include "../enums.hpp" -#include -#include +#include "../default.hpp" namespace xna { + enum class SeekOrigin { + Begin, + Current, + End, + }; + //A simplified port of the System.IO.Stream. //Provides a generic view of a sequence of bytes. This is an abstract class. class Stream { @@ -18,23 +21,20 @@ namespace xna { virtual Long Position() = 0; //Closes the current stream and releases any resources virtual void Close() = 0; - virtual bool IsClosed() = 0; //Sets the position within the current stream. virtual Long Seek(Long offset, SeekOrigin const& origin) = 0; - // //Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. - // virtual Int Read(Byte* buffer, Int bufferLength, Int offset, Int count) = 0; + //Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. virtual Int Read(std::vector& buffer, Int offset, Int count) = 0; //Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream. virtual Int ReadByte() = 0; - // - //When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. - // + //Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. virtual void Write(Byte const* buffer, Int bufferLength, Int offset, Int count) = 0; + //Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. virtual void Write(std::vector const& buffer, Int offset, Int count) = 0; //Writes a byte to the current position in the stream and advances the position within the stream by one byte. @@ -49,6 +49,10 @@ namespace xna { constexpr MemoryStream(std::vector const& bytes): _buffer(bytes), _length(bytes.size()){} + ~MemoryStream() override { + Close(); + } + constexpr MemoryStream(Int capacity) : _buffer(static_cast(capacity)), _length(capacity > 0 ? capacity : 0){} @@ -70,11 +74,7 @@ namespace xna { virtual constexpr void Close() override { _closed = true; _buffer = std::vector(); - } - - virtual constexpr bool IsClosed() override { - return _closed; - } + } virtual Long Seek(Long offset, SeekOrigin const& origin) override; virtual Int Read(Byte* buffer, Int bufferLength, Int offset, Int count) override; @@ -90,6 +90,7 @@ namespace xna { public: std::vector _buffer; + private: Int _position{ 0 }; Int _origin{ 0 }; @@ -103,7 +104,7 @@ namespace xna { FileStream(String const& path, FileMode fileMode); FileStream(String const& path); - ~FileStream() { + ~FileStream() override { Close(); } @@ -115,11 +116,7 @@ namespace xna { if(_fstream.is_open()) _fstream.close(); - } - - inline virtual constexpr bool IsClosed() override { - return _closed; - } + } virtual Long Seek(Long offset, SeekOrigin const& origin) override; virtual Int Read(Byte* buffer, Int bufferLength, Int offset, Int count) override; diff --git a/inc/xna/default.hpp b/inc/xna/default.hpp index 634624e..86f50a1 100644 --- a/inc/xna/default.hpp +++ b/inc/xna/default.hpp @@ -1,5 +1,201 @@ -#include "types.hpp" -#include "forward.hpp" -#include "enums.hpp" +#ifndef XNA_DEFAULT_HPP +#define XNA_DEFAULT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "enumerations.hpp" +#include "exception.hpp" #include "helpers.hpp" -#include "exception.hpp" \ No newline at end of file + +namespace xna { + + // + //C# nameof + // +#define nameof(name) std::string(#name) + + // + // C# standard types + // + + using Sbyte = int8_t; + using Byte = uint8_t; + using Short = int16_t; + using Ushort = uint16_t; + using Int = int32_t; + using Uint = uint32_t; + using Long = int64_t; + using Ulong = uint64_t; + using Char = char16_t; + + // + // C# Min and Max Value + // + + constexpr Sbyte SbyteMaxValue = (std::numeric_limits::max)(); + constexpr Sbyte SbyteMinValue = (std::numeric_limits::min)(); + constexpr Byte ByteMaxValue = (std::numeric_limits::max)(); + constexpr Byte ByteMinValue = (std::numeric_limits::min)(); + constexpr Short ShortMaxValue = (std::numeric_limits::max)(); + constexpr Short ShortMinValue = (std::numeric_limits::min)(); + constexpr Ushort UshortMaxValue = (std::numeric_limits::max)(); + constexpr Ushort UshortMinValue = (std::numeric_limits::min)(); + constexpr Int IntMaxValue = (std::numeric_limits::max)(); + constexpr Int IntMinValue = (std::numeric_limits::min)(); + constexpr Uint UintMaxValue = (std::numeric_limits::max)(); + constexpr Uint UintMinValue = (std::numeric_limits::min)(); + constexpr Long LongMaxValue = (std::numeric_limits::max)(); + constexpr Long LongMinValue = (std::numeric_limits::min)(); + constexpr Ulong UlongMaxValue = (std::numeric_limits::max)(); + constexpr Ulong UlongMinValue = (std::numeric_limits::min)(); + constexpr Char CharMaxValue = (std::numeric_limits::max)(); + constexpr Char CharMinValue = (std::numeric_limits::min)(); + constexpr float FloatMaxValue = (std::numeric_limits::max)(); + constexpr float FloatMinValue = (std::numeric_limits::min)(); + constexpr double DoubleMaxValue = (std::numeric_limits::max)(); + constexpr double DoubleMinValue = (std::numeric_limits::min)(); + + // + // C# Object + // + + //Same as std::any + using Object = std::any; + + // + // About strings: https://stackoverflow.com/questions/402283/stdwstring-vs-stdstring + // + + //Same as std::string + using String = std::string; + //Same as std::wstring + using WString = std::wstring; + + //Same as std::shared_ptr + template + using sptr = std::shared_ptr; + //Same as std::weak_ptr + template + using wptr = std::weak_ptr; + //Same as std::unique_ptr + template + using uptr = std::unique_ptr; + + //Same as std::make_shared + template + inline std::shared_ptr<_Ty> snew(_Types&&... _Args) { + return std::make_shared<_Ty>(std::forward<_Types>(_Args)...); + } + + //Same as std::make_unique + template + inline std::unique_ptr<_Ty> unew(_Types&&... _Args) { + return std::make_unique<_Ty>(std::forward<_Types>(_Args)...); + } + + // + // Forward + // + + //Audio + class SoundEffect; + struct SoundEffectInstance; + class AudioEngine; + struct WaveFormat; + + //CShap + struct TimeSpan; + class Stream; + class FileStream; + class MemoryStream; + class Type; + + //Content + class ContentManager; + class ContentReader; + class ContentTypeReader; + class ContentTypeReaderManager; + + //Common + struct BoundingBox; + struct BoundingFrustum; + struct BoundingSphere; + struct Color; + struct Curve; + struct CurveKey; + struct CurveKeyCollection; + struct Matrix; + struct Plane; + struct Point; + struct Quaternion; + struct Ray; + struct Rectangle; + struct Vector2; + struct Vector3; + struct Vector4; + + //Game + class Game; + class GameComponent; + class GameClock; + class GameTime; + class GameWindow; + class GraphicsDeviceInformation; + class GraphicsDeviceManager; + class IGameTime; + class IGameComponent; + class GameServiceContainer; + class GameComponentCollection; + + //Graphics + class BlendState; + class ConstantBuffer; + class DataBuffer; + class DepthStencilState; + class DisplayMode; + class DisplayModeCollection; + class Effect; + class GraphicsAdapter; + class GraphicsDevice; + class GraphicsDeviceInformation; + struct PresentationParameters; + class RenderTarget2D; + class SwapChain; + class Texture; + class Texture2D; + class Texture3D; + class TextureCube; + class RasterizerState; + class SamplerState; + class SamplerStateCollection; + class Shader; + class SpriteBatch; + class SpriteFont; + struct VertexPositionColor; + class VertexShader; + struct Viewport; + + //Input + struct GamePadTriggers; + struct GamePadThumbSticks; + struct GamePadDPad; + struct GamePadCapabilities; + struct GamePadButtons; + struct GamePadState; + struct KeyboardState; + struct MouseState; +} + + +#endif \ No newline at end of file diff --git a/inc/xna/enums.hpp b/inc/xna/enumerations.hpp similarity index 70% rename from inc/xna/enums.hpp rename to inc/xna/enumerations.hpp index 3bd7aaf..51bf886 100644 --- a/inc/xna/enums.hpp +++ b/inc/xna/enumerations.hpp @@ -1,5 +1,5 @@ -#ifndef XNA_ENUMS_HPP -#define XNA_ENUMS_HPP +#ifndef XNA_ENUMERATIONS_HPP +#define XNA_ENUMERATIONS_HPP namespace xna { enum class AudioChannels @@ -43,35 +43,35 @@ namespace xna { Max }; - enum class Blend { - Zero, - One, - SourceColor, - InverseSourceColor, - SourceAlpha, - InverseSourceAlpha, - DestinationAlpha, - InverseDestinationAlpha, - DestinationColor, - InverseDestinationColor, - SourceAlphaSaturation, - BlendFactor, - InverseBlendFactor, - Source1Color, - InverseSource1Color, - Source1Alpha, - InverseSource1Alpha - }; + enum class Blend { + Zero, + One, + SourceColor, + InverseSourceColor, + SourceAlpha, + InverseSourceAlpha, + DestinationAlpha, + InverseDestinationAlpha, + DestinationColor, + InverseDestinationColor, + SourceAlphaSaturation, + BlendFactor, + InverseBlendFactor, + Source1Color, + InverseSource1Color, + Source1Alpha, + InverseSource1Alpha + }; - enum class BlendFunction { - Add = 0, - Subtract = 1, - ReverseSubtract = 2, - Min = 3, - Max = 4, - }; + enum class BlendFunction { + Add = 0, + Subtract = 1, + ReverseSubtract = 2, + Min = 3, + Max = 4, + }; - using BlendOperation = BlendFunction; + using BlendOperation = BlendFunction; enum class BufferUsage { Default, @@ -120,14 +120,14 @@ namespace xna { Target, }; - enum class ColorWriteChannels { - Red, - Green, - Blue, - Alpha, - All, + enum class ColorWriteChannels { + Red, + Green, + Blue, + Alpha, + All, None - }; + }; enum class ContainmentType { Disjoint, @@ -135,19 +135,19 @@ namespace xna { Intersects, }; - enum class ComparisonFunction { - Never, - Less, - Equal, - LessEquals, - Greater, - NotEqual, - GreaterEqual, - Always - }; + enum class ComparisonFunction { + Never, + Less, + Equal, + LessEquals, + Greater, + NotEqual, + GreaterEqual, + Always + }; using CompareFunction = ComparisonFunction; - + enum class CurveContinuity { Smooth, Step, @@ -168,30 +168,30 @@ namespace xna { Linear, }; - enum class CullMode { - None, - CullClockwiseFace, - CullCounterClockwiseFace, - }; + enum class CullMode { + None, + CullClockwiseFace, + CullCounterClockwiseFace, + }; - enum class DepthFormat { - None, - Depth16, - Depth24, - Depth24Stencil8 - }; + enum class DepthFormat { + None, + Depth16, + Depth24, + Depth24Stencil8 + }; - enum class DepthWriteMask { - Zero, - All - }; + enum class DepthWriteMask { + Zero, + All + }; - enum class DisplayOrientation { - Default = 0, - LandscapeLeft = 1, - LandscapeRight = 2, - Portrait = 4, - }; + enum class DisplayOrientation { + Default = 0, + LandscapeLeft = 1, + LandscapeRight = 2, + Portrait = 4, + }; enum class DisplayModeScanlineOrder { Unspecified = 0, @@ -236,11 +236,11 @@ namespace xna { Truncate }; - enum class FillMode - { - WireFrame, + enum class FillMode + { + WireFrame, Solid, - }; + }; enum class GameComponentType { Updatable, @@ -268,12 +268,12 @@ namespace xna { None, }; - enum class GraphicsProfile { - Reach, - HiDef - }; + enum class GraphicsProfile { + Reach, + HiDef + }; - enum class Keys : unsigned char{ + enum class Keys : unsigned char { None = 0, Back = 0x8, @@ -473,12 +473,12 @@ namespace xna { Four, }; - enum class PresentInterval { - Default, - One, - Two, - Immediate - }; + enum class PresentInterval { + Default, + One, + Two, + Immediate + }; enum class PrimitiveType { @@ -488,69 +488,65 @@ namespace xna { LineStrip, }; - enum RenderTargetUsage { - DiscardContents, - PreserveContents, - PlatformContents - }; + enum RenderTargetUsage { + DiscardContents, + PreserveContents, + PlatformContents + }; - enum class SeekOrigin { - Begin, - Current, - End, - }; + - enum class SpriteEffects { - None = 0, - FlipHorizontally = 1, - FlipVertically = 2, - Both = FlipHorizontally | FlipVertically - }; + enum class SpriteEffects { + None = 0, + FlipHorizontally = 1, + FlipVertically = 2, + Both = FlipHorizontally | FlipVertically + }; - enum class SpriteSortMode - { - Deferred, - Immediate, - Texture, - BackToFront, - FrontToBack, - }; + enum class SpriteSortMode + { + Deferred, + Immediate, + Texture, + BackToFront, + FrontToBack, + }; - enum class StencilOperation - { - Keep, - Zero, - Replace, - IncrementSaturation, - DecrementSaturation, - Invert, - Increment, - Decrement, - }; + enum class StencilOperation + { + Keep, + Zero, + Replace, + IncrementSaturation, + DecrementSaturation, + Invert, + Increment, + Decrement, + }; - enum class SurfaceFormat { - Color = 0, - Bgr565 = 1, - Bgra5551 = 2, - Bgra4444 = 3, - Dxt1 = 4, - Dxt3 = 5, - Dxt5 = 6, - NormalizedByte2 = 7, - NormalizedByte4 = 8, - Rgba1010102 = 9, - Rg32 = 10, - Rgba64 = 11, - Alpha8 = 12, - Single = 13, - Vector2 = 14, - Vector4 = 15, - HalfSingle = 16, - HalfVector2 = 17, - HalfVector4 = 18, - HdrBlendable = 19, + enum class SurfaceFormat { + Color = 0, + Bgr565 = 1, + Bgra5551 = 2, + Bgra4444 = 3, + Dxt1 = 4, + Dxt3 = 5, + Dxt5 = 6, + NormalizedByte2 = 7, + NormalizedByte4 = 8, + Rgba1010102 = 9, + Rg32 = 10, + Rgba64 = 11, + Alpha8 = 12, + Single = 13, + Vector2 = 14, + Vector4 = 15, + HalfSingle = 16, + HalfVector2 = 17, + HalfVector4 = 18, + HdrBlendable = 19, Unknown, - }; + }; enum class SwapEffect { Discard, @@ -559,29 +555,27 @@ namespace xna { FlipDiscard }; - enum class TextureAddressMode { - Wrap, - Mirror, - Clamp, - Border, - MirrorOnce - }; + enum class TextureAddressMode { + Wrap, + Mirror, + Clamp, + Border, + MirrorOnce + }; - enum class TextureFilter { - Linear, - Point, - Anisotropic, - LinearMipPoint, - PointMipLinear, - MinLinearMagPointMipLinear, - MinLinearMagPointMipPoint, - MinPointMagLinearMipLinear, - MinPointMagLinearMipPoint, - }; + enum class TextureFilter { + Linear, + Point, + Anisotropic, + LinearMipPoint, + PointMipLinear, + MinLinearMagPointMipLinear, + MinLinearMagPointMipPoint, + MinPointMagLinearMipLinear, + MinPointMagLinearMipPoint, + }; - - - constexpr int SURFACE_FORMAT_COUNT = 19; + constexpr int SURFACE_FORMAT_COUNT = 19; } #endif \ No newline at end of file diff --git a/inc/xna/exception.hpp b/inc/xna/exception.hpp index 414e22f..4dffea3 100644 --- a/inc/xna/exception.hpp +++ b/inc/xna/exception.hpp @@ -4,32 +4,24 @@ #include #include #include +#include namespace xna { //Structure for throwing exceptions with a message and information from the source file struct Exception { //Raises an exception with a message. Source file information is automatically captured. - static void Throw(std::string const& message = "", const std::source_location location = std::source_location::current()) { - std::string error; + static void Throw(std::string const& message = "", std::source_location const& location = std::source_location::current()); - error.append("Exception in: "); -#if _DEBUG - error.append(location.file_name()); - error.append("("); - error.append(std::to_string(location.line())); - error.append(":"); - error.append(std::to_string(location.column())); - error.append(") "); -#endif - error.append("'"); - error.append(location.function_name()); - error.append("': "); - error.append(message); - error.append("\n"); - - throw std::runtime_error(error); + inline static void ThrowIfNull(std::shared_ptr const& argument, std::string const& argumentName, std::source_location const& location = std::source_location::current()) { + ThrowIfNull(&argument, argumentName, location); } + inline static void ThrowIfNull(std::unique_ptr const& argument, std::string const& argumentName, std::source_location const& location = std::source_location::current()) { + ThrowIfNull(&argument, argumentName, location); + } + + static void ThrowIfNull(void const* argument, std::string const& argumentName, std::source_location const& location = std::source_location::current()); + inline static const std::string FAILED_TO_CREATE = "Failed to create component."; inline static const std::string FAILED_TO_APPLY = "Failed to apply component."; inline static const std::string FAILED_TO_MAKE_WINDOW_ASSOCIATION = "Failed to create association with window."; @@ -38,7 +30,10 @@ namespace xna { inline static const std::string NOT_IMPLEMENTED = "Not Implemented."; inline static const std::string ARGUMENT_IS_NULL = "The argument is null or one of its values."; inline static const std::string INVALID_OPERATION = "An invalid operation occurred."; - }; + inline static const std::string BAD_XNB = "Bad xnb file"; + inline static const std::string OUT_OF_BOUNDS = "Out of bounds."; + inline static const std::string END_OF_FILE = "End of file."; + }; } #endif \ No newline at end of file diff --git a/inc/xna/forward.hpp b/inc/xna/forward.hpp deleted file mode 100644 index eb5afa6..0000000 --- a/inc/xna/forward.hpp +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef XNA_FORWARD_HPP -#define XNA_FORWARD_HPP - -#include "types.hpp" - -namespace xna { - //Audio - class SoundEffect; - struct SoundEffectInstance; - class AudioEngine; - struct WaveFormat; - - //CShap - struct TimeSpan; - class Stream; - class FileStream; - class MemoryStream; - class Type; - - //Content - class ContentManager; - class ContentReader; - class ContentTypeReader; - class ContentTypeReaderManager; - - //Common - struct BoundingBox; - struct BoundingFrustum; - struct BoundingSphere; - struct Color; - struct Curve; - struct CurveKey; - struct CurveKeyCollection; - struct Matrix; - struct Plane; - struct Point; - struct Quaternion; - struct Ray; - struct Rectangle; - struct Vector2; - struct Vector3; - struct Vector4; - - //Game - class Game; - class GameComponent; - class GameClock; - class GameTime; - class GameWindow; - class GraphicsDeviceInformation; - class GraphicsDeviceManager; - class IGameTime; - class IGameComponent; - class GameServiceContainer; - class GameComponentCollection; - - //Graphics - class BlendState; - class ConstantBuffer; - class DataBuffer; - class DepthStencilState; - class DisplayMode; - class DisplayModeCollection; - class Effect; - class GraphicsAdapter; - class GraphicsDevice; - class GraphicsDeviceInformation; - struct PresentationParameters; - class RenderTarget2D; - class SwapChain; - class Texture; - class Texture2D; - class Texture3D; - class TextureCube; - class RasterizerState; - class SamplerState; - class SamplerStateCollection; - class Shader; - class SpriteBatch; - class SpriteFont; - struct VertexPositionColor; - class VertexShader; - struct Viewport; - - //Input - struct GamePadTriggers; - struct GamePadThumbSticks; - struct GamePadDPad; - struct GamePadCapabilities; - struct GamePadButtons; - struct GamePadState; - struct KeyboardState; - struct MouseState; -} - -#endif \ No newline at end of file diff --git a/inc/xna/game/time.hpp b/inc/xna/game/time.hpp index 6488cac..474eb89 100644 --- a/inc/xna/game/time.hpp +++ b/inc/xna/game/time.hpp @@ -1,8 +1,7 @@ #ifndef XNA_GAME_TIME_HPP #define XNA_GAME_TIME_HPP -#include "../forward.hpp" -#include "../types.hpp" +#include "../default.hpp" #include "../csharp/timespan.hpp" namespace xna { diff --git a/inc/xna/graphics/sprite.hpp b/inc/xna/graphics/sprite.hpp index 3bfb2d0..f25cf66 100644 --- a/inc/xna/graphics/sprite.hpp +++ b/inc/xna/graphics/sprite.hpp @@ -5,7 +5,6 @@ #include "../common/numerics.hpp" #include "../default.hpp" #include "../graphics/gresource.hpp" -#include namespace xna { //Enables a group of sprites to be drawn using the same settings. diff --git a/inc/xna/helpers.hpp b/inc/xna/helpers.hpp index a11114d..46fe92e 100644 --- a/inc/xna/helpers.hpp +++ b/inc/xna/helpers.hpp @@ -1,9 +1,7 @@ #ifndef XNA_HELPERS_HPP #define XNA_HELPERS_HPP -#include -#include -#include "exception.hpp" +#include "default.hpp" namespace xna { //Class for helper functions diff --git a/inc/xna/types.hpp b/inc/xna/types.hpp deleted file mode 100644 index 9553407..0000000 --- a/inc/xna/types.hpp +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef XNA_TYPES_HPP -#define XNA_TYPES_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace xna { - - // - // C# standard types - // - - using Sbyte = int8_t; - using Byte = uint8_t; - using Short = int16_t; - using Ushort = uint16_t; - using Int = int32_t; - using Uint = uint32_t; - using Long = int64_t; - using Ulong = uint64_t; - using Char = char16_t; - - // - // C# Min and Max Value - // - - constexpr Sbyte SbyteMaxValue = (std::numeric_limits::max)(); - constexpr Sbyte SbyteMinValue = (std::numeric_limits::min)(); - constexpr Byte ByteMaxValue = (std::numeric_limits::max)(); - constexpr Byte ByteMinValue = (std::numeric_limits::min)(); - constexpr Short ShortMaxValue = (std::numeric_limits::max)(); - constexpr Short ShortMinValue = (std::numeric_limits::min)(); - constexpr Ushort UshortMaxValue = (std::numeric_limits::max)(); - constexpr Ushort UshortMinValue = (std::numeric_limits::min)(); - constexpr Int IntMaxValue = (std::numeric_limits::max)(); - constexpr Int IntMinValue = (std::numeric_limits::min)(); - constexpr Uint UintMaxValue = (std::numeric_limits::max)(); - constexpr Uint UintMinValue = (std::numeric_limits::min)(); - constexpr Long LongMaxValue = (std::numeric_limits::max)(); - constexpr Long LongMinValue = (std::numeric_limits::min)(); - constexpr Ulong UlongMaxValue = (std::numeric_limits::max)(); - constexpr Ulong UlongMinValue = (std::numeric_limits::min)(); - constexpr Char CharMaxValue = (std::numeric_limits::max)(); - constexpr Char CharMinValue = (std::numeric_limits::min)(); - constexpr float FloatMaxValue = (std::numeric_limits::max)(); - constexpr float FloatMinValue = (std::numeric_limits::min)(); - constexpr double DoubleMaxValue = (std::numeric_limits::max)(); - constexpr double DoubleMinValue = (std::numeric_limits::min)(); - - // - // C# Object - // - using Object = std::any; - - // - // About strings: https://stackoverflow.com/questions/402283/stdwstring-vs-stdstring - // - - //Same as std::string - using String = std::string; - //Same as std::wstring - using WString = std::wstring; - - //Same as std::shared_ptr - template - using sptr = std::shared_ptr; - //Same as std::weak_ptr - template - using wptr = std::weak_ptr; - //Same as std::unique_ptr - template - using uptr = std::unique_ptr; - - //Same as std::make_shared - template - inline std::shared_ptr<_Ty> snew(_Types&&... _Args) { - return std::make_shared<_Ty>(std::forward<_Types>(_Args)...); - } - - //Same as std::make_unique - template - inline std::unique_ptr<_Ty> unew(_Types&&... _Args) { - return std::make_unique<_Ty>(std::forward<_Types>(_Args)...); - } -} - -#endif \ No newline at end of file diff --git a/inc/xna/xna.hpp b/inc/xna/xna.hpp index 1bc4cbb..427eb79 100644 --- a/inc/xna/xna.hpp +++ b/inc/xna/xna.hpp @@ -23,7 +23,6 @@ #include "csharp/stream.hpp" #include "csharp/timespan.hpp" #include "csharp/type.hpp" -#include "enums.hpp" #include "exception.hpp" #include "game/component.hpp" #include "game/game.hpp" @@ -37,6 +36,7 @@ #include "graphics/depthstencilstate.hpp" #include "graphics/device.hpp" #include "graphics/displaymode.hpp" +#include "graphics/effect.hpp" #include "graphics/gresource.hpp" #include "graphics/presentparams.hpp" #include "graphics/rasterizerstate.hpp" @@ -47,12 +47,10 @@ #include "graphics/texture.hpp" #include "graphics/vertexposition.hpp" #include "graphics/viewport.hpp" -#include "graphics/effect.hpp" #include "helpers.hpp" #include "input/gamepad.hpp" #include "input/keyboard.hpp" #include "input/mouse.hpp" -#include "types.hpp" namespace xna { //Exposes functions that must be implemented by the platform diff --git a/samples/01_blank/xna.cpp b/samples/01_blank/xna.cpp index 2c8bd9a..9f8727a 100644 --- a/samples/01_blank/xna.cpp +++ b/samples/01_blank/xna.cpp @@ -27,7 +27,6 @@ namespace xna { void LoadContent() override { spriteBatch = snew(graphicsDevice); - auto texture = Content()->Load("Idle"); Game::LoadContent(); } diff --git a/samples/02_PlatfformerStarterKit/animation.hpp b/samples/02_PlatfformerStarterKit/animation.hpp index 6dc2209..28f80ad 100644 --- a/samples/02_PlatfformerStarterKit/animation.hpp +++ b/samples/02_PlatfformerStarterKit/animation.hpp @@ -1,7 +1,7 @@ #ifndef PLATFORMSTARTERKIT_ANIMATION_HPP #define PLATFORMSTARTERKIT_ANIMATION_HPP -#include "xna/xna.hpp" +#include "headers.hpp" namespace PlatformerStarterKit { /* diff --git a/samples/02_PlatfformerStarterKit/circle.hpp b/samples/02_PlatfformerStarterKit/circle.hpp index d3146fa..8fbc889 100644 --- a/samples/02_PlatfformerStarterKit/circle.hpp +++ b/samples/02_PlatfformerStarterKit/circle.hpp @@ -1,7 +1,7 @@ #ifndef PLATFORMSTARTERKIT_CIRCLE_HPP #define PLATFORMSTARTERKIT_CIRCLE_HPP -#include "xna/xna.hpp" +#include "headers.hpp" namespace PlatformerStarterKit { //Represents a 2D circle. diff --git a/samples/02_PlatfformerStarterKit/enemy.hpp b/samples/02_PlatfformerStarterKit/enemy.hpp index 9a1aef9..64c48f8 100644 --- a/samples/02_PlatfformerStarterKit/enemy.hpp +++ b/samples/02_PlatfformerStarterKit/enemy.hpp @@ -1,7 +1,7 @@ #ifndef PLATFORMSTARTERKIT_ENEMY_HPP #define PLATFORMSTARTERKIT_ENEMY_HPP -#include "xna/xna.hpp" +#include "headers.hpp" #include "animation.hpp" namespace PlatformerStarterKit { diff --git a/samples/02_PlatfformerStarterKit/game.cpp b/samples/02_PlatfformerStarterKit/game.cpp index 2f2c343..958688f 100644 --- a/samples/02_PlatfformerStarterKit/game.cpp +++ b/samples/02_PlatfformerStarterKit/game.cpp @@ -1,8 +1,7 @@ // xna.cpp : Defines the entry point for the application. // -#include "xna/xna.hpp" -#include "xna/platform/dx.hpp" +#include "headers.hpp" #include "player.hpp" #include "enemy.hpp" #include "level.hpp" diff --git a/samples/02_PlatfformerStarterKit/gem.hpp b/samples/02_PlatfformerStarterKit/gem.hpp index 949a31b..df98bdc 100644 --- a/samples/02_PlatfformerStarterKit/gem.hpp +++ b/samples/02_PlatfformerStarterKit/gem.hpp @@ -1,7 +1,7 @@ #ifndef PLATFORMSTARTERKIT_GEM_HPP #define PLATFORMSTARTERKIT_GEM_HPP -#include "xna/xna.hpp" +#include "headers.hpp" #include "circle.hpp" #include "tile.hpp" diff --git a/samples/02_PlatfformerStarterKit/headers.hpp b/samples/02_PlatfformerStarterKit/headers.hpp new file mode 100644 index 0000000..dac1e61 --- /dev/null +++ b/samples/02_PlatfformerStarterKit/headers.hpp @@ -0,0 +1,2 @@ +#include "xna/xna.hpp" +#include "xna/platform/dx.hpp" \ No newline at end of file diff --git a/samples/02_PlatfformerStarterKit/level.hpp b/samples/02_PlatfformerStarterKit/level.hpp index 4261614..7c84557 100644 --- a/samples/02_PlatfformerStarterKit/level.hpp +++ b/samples/02_PlatfformerStarterKit/level.hpp @@ -1,7 +1,7 @@ #ifndef PLATFORMSTARTERKIT_LEVEL_HPP #define PLATFORMSTARTERKIT_LEVEL_HPP -#include "xna/xna.hpp" +#include "headers.hpp" #include "tile.hpp" namespace PlatformerStarterKit { diff --git a/samples/02_PlatfformerStarterKit/player.hpp b/samples/02_PlatfformerStarterKit/player.hpp index 684efd6..8872554 100644 --- a/samples/02_PlatfformerStarterKit/player.hpp +++ b/samples/02_PlatfformerStarterKit/player.hpp @@ -1,7 +1,7 @@ #ifndef PLATFORMSTARTERKIT_PLAYER_HPP #define PLATFORMSTARTERKIT_PLAYER_HPP -#include "xna/xna.hpp" +#include "headers.hpp" #include "animation.hpp" namespace PlatformerStarterKit { diff --git a/samples/02_PlatfformerStarterKit/tile.hpp b/samples/02_PlatfformerStarterKit/tile.hpp index f2374a7..bf24a9c 100644 --- a/samples/02_PlatfformerStarterKit/tile.hpp +++ b/samples/02_PlatfformerStarterKit/tile.hpp @@ -1,6 +1,8 @@ #ifndef PLATFORMSTARTERKIT_TILE_HPP #define PLATFORMSTARTERKIT_TILE_HPP +#include "headers.hpp" + namespace PlatformerStarterKit { // Controls the collision detection and response behavior of a tile. enum class TileCollision {