mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações iniciais
This commit is contained in:
parent
fe6c1fd1b7
commit
61aa08ff61
framework
inc/xna
samples
@ -40,7 +40,7 @@ add_library (Xn65 STATIC
|
|||||||
"platform-dx/audioengine.cpp"
|
"platform-dx/audioengine.cpp"
|
||||||
"graphics/gresource.cpp"
|
"graphics/gresource.cpp"
|
||||||
"platform-dx/effect.cpp"
|
"platform-dx/effect.cpp"
|
||||||
"exception.cpp" "platform-dx/screen.cpp" )
|
"exception.cpp" "platform-dx/screen.cpp" "pipeline/writer.cpp")
|
||||||
|
|
||||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||||
set_property(TARGET Xn65 PROPERTY CXX_STANDARD 20)
|
set_property(TARGET Xn65 PROPERTY CXX_STANDARD 20)
|
||||||
|
133
framework/pipeline/writer.cpp
Normal file
133
framework/pipeline/writer.cpp
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
#include "xna/pipeline/writer.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
ContentWriter::ContentWriter(
|
||||||
|
P_ContentCompiler& compiler,
|
||||||
|
P_Stream const& output,
|
||||||
|
TargetPlatform targetPlatform,
|
||||||
|
GraphicsProfile targetProfile,
|
||||||
|
bool compressContent,
|
||||||
|
String const& rootDirectory,
|
||||||
|
String const& referenceRelocationPath
|
||||||
|
) : compiler(compiler),
|
||||||
|
targetPlatform(targetPlatform),
|
||||||
|
targetProfile(targetProfile),
|
||||||
|
compressContent(compressContent),
|
||||||
|
rootDirectory(rootDirectory),
|
||||||
|
referenceRelocationPath(referenceRelocationPath),
|
||||||
|
finalOutput(output)
|
||||||
|
{
|
||||||
|
headerData = snew<MemoryStream>();
|
||||||
|
contentData = snew<MemoryStream>();
|
||||||
|
OutStream = reinterpret_pointer_cast<Stream>(contentData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::WriteSharedResources() {
|
||||||
|
while (sharedResources.size() > 0) {
|
||||||
|
sharedResources.pop();
|
||||||
|
auto& res = sharedResources.front();
|
||||||
|
WriteObject<std::any>(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::WriteHeader() {
|
||||||
|
OutStream = reinterpret_pointer_cast<Stream>(headerData);
|
||||||
|
Write7BitEncodedInt(static_cast<Int>(typeWriters.size()));
|
||||||
|
|
||||||
|
for (size_t i = 0; i < typeWriters.size(); ++i) {
|
||||||
|
auto& typeWriter = typeWriters[i];
|
||||||
|
|
||||||
|
Write(typeWriter->GetRuntimeReader(targetPlatform));
|
||||||
|
Write(typeWriter->TypeVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
Write7BitEncodedInt(static_cast<Int>(sharedResourceNames.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::WriteFinalOutput() {
|
||||||
|
OutStream = finalOutput;
|
||||||
|
|
||||||
|
Write((Byte)88);
|
||||||
|
Write((Byte)78);
|
||||||
|
Write((Byte)66);
|
||||||
|
|
||||||
|
if (targetPlatform == TargetPlatform::Windows)
|
||||||
|
Write((Byte)119);
|
||||||
|
else
|
||||||
|
Exception::Throw(Exception::NOT_IMPLEMENTED);
|
||||||
|
|
||||||
|
if (compressContent)
|
||||||
|
WriteCompressedOutput();
|
||||||
|
else
|
||||||
|
WriteUncompressedOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::WriteUncompressedOutput() {
|
||||||
|
WriteVersionNumber((Ushort)5);
|
||||||
|
|
||||||
|
const auto length1 = static_cast<Int>(headerData->Length());
|
||||||
|
const auto length2 = static_cast<Int>(contentData->Length());
|
||||||
|
|
||||||
|
Write(10 + length1 + length2);
|
||||||
|
|
||||||
|
OutStream->Write(headerData->_buffer, 0, length1);
|
||||||
|
OutStream->Write(contentData->_buffer, 0, length2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::WriteCompressedOutput() {
|
||||||
|
Exception::Throw(Exception::NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::WriteVersionNumber(Ushort version) {
|
||||||
|
version |= static_cast<Ushort>(static_cast<Int>(targetProfile) << 8 & 32512);
|
||||||
|
Write(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::Write(Vector2 const& value) {
|
||||||
|
Write(value.X);
|
||||||
|
Write(value.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::Write(Vector3 const& value) {
|
||||||
|
Write(value.X);
|
||||||
|
Write(value.Y);
|
||||||
|
Write(value.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::Write(Vector4 const& value) {
|
||||||
|
Write(value.X);
|
||||||
|
Write(value.Y);
|
||||||
|
Write(value.Z);
|
||||||
|
Write(value.W);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::Write(Matrix const& value) {
|
||||||
|
Write(value.M11);
|
||||||
|
Write(value.M12);
|
||||||
|
Write(value.M13);
|
||||||
|
Write(value.M14);
|
||||||
|
Write(value.M21);
|
||||||
|
Write(value.M22);
|
||||||
|
Write(value.M23);
|
||||||
|
Write(value.M24);
|
||||||
|
Write(value.M31);
|
||||||
|
Write(value.M32);
|
||||||
|
Write(value.M33);
|
||||||
|
Write(value.M34);
|
||||||
|
Write(value.M41);
|
||||||
|
Write(value.M42);
|
||||||
|
Write(value.M43);
|
||||||
|
Write(value.M44);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::Write(Quaternion const& value) {
|
||||||
|
Write(value.X);
|
||||||
|
Write(value.Y);
|
||||||
|
Write(value.Z);
|
||||||
|
Write(value.W);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContentWriter::Write(Color const& value) {
|
||||||
|
Write(value.PackedValue());
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,8 @@ namespace xna {
|
|||||||
//A simplified port of the System.IO.MemoryStream.
|
//A simplified port of the System.IO.MemoryStream.
|
||||||
class MemoryStream : public Stream {
|
class MemoryStream : public Stream {
|
||||||
public:
|
public:
|
||||||
|
constexpr MemoryStream(){}
|
||||||
|
|
||||||
constexpr MemoryStream(std::vector<Byte> const& bytes):
|
constexpr MemoryStream(std::vector<Byte> const& bytes):
|
||||||
_buffer(bytes),
|
_buffer(bytes),
|
||||||
_length(static_cast<Int>(bytes.size())){}
|
_length(static_cast<Int>(bytes.size())){}
|
||||||
@ -83,6 +85,10 @@ namespace xna {
|
|||||||
virtual void Write(std::vector<Byte> const& buffer, Int offset, Int count) override;
|
virtual void Write(std::vector<Byte> const& buffer, Int offset, Int count) override;
|
||||||
virtual void WriteByte(Byte value) override;
|
virtual void WriteByte(Byte value) override;
|
||||||
|
|
||||||
|
virtual std::vector<Byte> GetBuffer() const {
|
||||||
|
return _buffer;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<Byte> _buffer;
|
std::vector<Byte> _buffer;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
#include "enumerations.hpp"
|
#include "enumerations.hpp"
|
||||||
#include "exception.hpp"
|
#include "exception.hpp"
|
||||||
@ -195,6 +196,17 @@ namespace xna {
|
|||||||
struct KeyboardState;
|
struct KeyboardState;
|
||||||
struct MouseState;
|
struct MouseState;
|
||||||
|
|
||||||
|
//Pipeline
|
||||||
|
class ContentWriter;
|
||||||
|
class ContentCompiler;
|
||||||
|
class ContentTypeWriter;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Forward Pointers
|
||||||
|
//
|
||||||
|
|
||||||
|
//Graphics
|
||||||
using P_BlendState = sptr<BlendState>;
|
using P_BlendState = sptr<BlendState>;
|
||||||
using P_DepthStencilState = sptr<DepthStencilState>;
|
using P_DepthStencilState = sptr<DepthStencilState>;
|
||||||
using P_GraphicsAdapter = sptr<GraphicsAdapter>;
|
using P_GraphicsAdapter = sptr<GraphicsAdapter>;
|
||||||
@ -202,12 +214,17 @@ namespace xna {
|
|||||||
using P_RasterizerState = sptr<RasterizerState>;
|
using P_RasterizerState = sptr<RasterizerState>;
|
||||||
using P_PresentationParameters = sptr<PresentationParameters>;
|
using P_PresentationParameters = sptr<PresentationParameters>;
|
||||||
using P_SamplerStateCollection = sptr<SamplerStateCollection>;
|
using P_SamplerStateCollection = sptr<SamplerStateCollection>;
|
||||||
using P_Stream = sptr<Stream>;
|
using P_RenderTarget2D = sptr<RenderTarget2D>;
|
||||||
using P_MemoryStream = sptr<MemoryStream>;
|
|
||||||
using P_FileStream = sptr<FileStream>;
|
|
||||||
using P_Texture = sptr<Texture>;
|
using P_Texture = sptr<Texture>;
|
||||||
using P_Texture2D = sptr<Texture2D>;
|
using P_Texture2D = sptr<Texture2D>;
|
||||||
using P_RenderTarget2D = sptr<RenderTarget2D>;
|
//CSharp
|
||||||
|
using P_Stream = sptr<Stream>;
|
||||||
|
using P_MemoryStream = sptr<MemoryStream>;
|
||||||
|
using P_FileStream = sptr<FileStream>;
|
||||||
|
//Pipeline
|
||||||
|
using P_ContentWriter = sptr<ContentWriter>;
|
||||||
|
using P_ContentCompiler = sptr<ContentCompiler>;
|
||||||
|
using P_ContentTypeWriter = sptr<ContentTypeWriter>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
12
inc/xna/pipeline/compiler.hpp
Normal file
12
inc/xna/pipeline/compiler.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef XNA_PIPELINE_COMPILER_HPP
|
||||||
|
#define XNA_PIPELINE_COMPILER_HPP
|
||||||
|
|
||||||
|
#include "../default.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
class ContentCompiler {
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
11
inc/xna/pipeline/pipeline-enums.hpp
Normal file
11
inc/xna/pipeline/pipeline-enums.hpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef XNA_PIPELINE_ENUMS_HPP
|
||||||
|
#define XNA_PIPELINE_ENUMS_HPP
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
enum class TargetPlatform
|
||||||
|
{
|
||||||
|
Windows,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
150
inc/xna/pipeline/writer.hpp
Normal file
150
inc/xna/pipeline/writer.hpp
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
#ifndef XNA_PIPELINE_WRITER_HPP
|
||||||
|
#define XNA_PIPELINE_WRITER_HPP
|
||||||
|
|
||||||
|
#include "../csharp/binary.hpp"
|
||||||
|
#include "../default.hpp"
|
||||||
|
#include "pipeline-enums.hpp"
|
||||||
|
#include "../common/numerics.hpp"
|
||||||
|
#include "../common/color.hpp"
|
||||||
|
|
||||||
|
namespace xna {
|
||||||
|
class ContentTypeWriter {
|
||||||
|
public:
|
||||||
|
virtual String GetRuntimeReader(TargetPlatform targetPlatform) = 0;
|
||||||
|
virtual Int TypeVersion() const { return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class ExternalReference {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//Provides an implementation for many of the ContentCompiler methods including compilation, state tracking for shared resources and creation of the header type manifest.
|
||||||
|
class ContentWriter : public BinaryWriter {
|
||||||
|
public:
|
||||||
|
ContentWriter(
|
||||||
|
P_ContentCompiler& compiler,
|
||||||
|
P_Stream const& output,
|
||||||
|
TargetPlatform targetPlatform,
|
||||||
|
GraphicsProfile targetProfile,
|
||||||
|
bool compressContent,
|
||||||
|
String const& rootDirectory,
|
||||||
|
String const& referenceRelocationPath
|
||||||
|
);
|
||||||
|
|
||||||
|
//Gets the content build target platform.
|
||||||
|
constexpr TargetPlatform Target() const { return targetPlatform; }
|
||||||
|
//Gets or sets the target graphics profile.
|
||||||
|
constexpr GraphicsProfile TargetProfile() const { return targetProfile; }
|
||||||
|
|
||||||
|
//Writes a single object preceded by a type identifier to the output binary.
|
||||||
|
template <class T> void WriteObject(T& value);
|
||||||
|
//Writes a single object to the output binary, using the specified type hint and writer worker.
|
||||||
|
template <class T> void WriteObject(T& value, ContentTypeWriter& writer);
|
||||||
|
//Writes a single object to the output binary as an instance of the specified type.
|
||||||
|
template <class T> void WriteRawObject(T& value);
|
||||||
|
//Writes a single object to the output binary using the specified writer worker.
|
||||||
|
template <class T> void WriteRawObject(T& value, ContentTypeWriter& typeWriter);
|
||||||
|
//Adds a shared reference to the output binary and records the object to be serialized later.
|
||||||
|
template <class T> void WriteSharedResource(T& value);
|
||||||
|
//Writes the name of an external file to the output binary.
|
||||||
|
template <class T> void WriteExternalReference(ExternalReference<T>& reference);
|
||||||
|
|
||||||
|
using BinaryWriter::Write;
|
||||||
|
|
||||||
|
//Writes a Vector2 value.
|
||||||
|
void Write(Vector2 const& value);
|
||||||
|
//Writes a Vector3 value.
|
||||||
|
void Write(Vector3 const& value);
|
||||||
|
//Writes a Vector4 value.
|
||||||
|
void Write(Vector4 const& value);
|
||||||
|
//Writes a Matrix value.
|
||||||
|
void Write(Matrix const& value);
|
||||||
|
//Writes a Quaternion value.
|
||||||
|
void Write(Quaternion const& value);
|
||||||
|
//Writes a Color value.
|
||||||
|
void Write(Color const& value);
|
||||||
|
|
||||||
|
inline void FlushOutput() {
|
||||||
|
WriteSharedResources();
|
||||||
|
WriteHeader();
|
||||||
|
WriteFinalOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template <class T> void InvokeWriter(T& value, ContentTypeWriter& writer);
|
||||||
|
sptr<ContentTypeWriter> GetTypeWriter(Type const& type, int& typeIndex) { return nullptr; }
|
||||||
|
void WriteSharedResources();
|
||||||
|
void WriteHeader();
|
||||||
|
void WriteFinalOutput();
|
||||||
|
void WriteUncompressedOutput();
|
||||||
|
void WriteCompressedOutput();
|
||||||
|
void WriteVersionNumber(Ushort version);
|
||||||
|
|
||||||
|
private:
|
||||||
|
P_ContentCompiler compiler{ nullptr };
|
||||||
|
TargetPlatform targetPlatform{ TargetPlatform::Windows };
|
||||||
|
GraphicsProfile targetProfile{ GraphicsProfile::HiDef };
|
||||||
|
bool compressContent{ false };
|
||||||
|
String rootDirectory;
|
||||||
|
String referenceRelocationPath;
|
||||||
|
P_Stream finalOutput{ nullptr };
|
||||||
|
P_MemoryStream headerData{ nullptr };
|
||||||
|
P_MemoryStream contentData{ nullptr };
|
||||||
|
std::vector<P_ContentTypeWriter> typeWriters;
|
||||||
|
std::map<std::any, Int> sharedResourceNames;
|
||||||
|
std::queue<std::any> sharedResources;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr Ushort XnbVersion = 5;
|
||||||
|
static constexpr Ushort XnbCompressedVersion = 32773;
|
||||||
|
static constexpr Ushort XnbVersionProfileMask = 32512;
|
||||||
|
static constexpr Int XnbVersionProfileShift = 8;
|
||||||
|
static constexpr Int XnbVersionOffset = 4;
|
||||||
|
static constexpr Int XnbFileSizeOffset = 6;
|
||||||
|
static constexpr Int XnbPrologueSize = 10;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generics implementations
|
||||||
|
//
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void ContentWriter::WriteObject(T& value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void ContentWriter::WriteObject(T& value, ContentTypeWriter& writer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void ContentWriter::WriteRawObject(T& value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void ContentWriter::WriteRawObject(T& value, ContentTypeWriter& typeWriter) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void ContentWriter::WriteSharedResource(T& value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void ContentWriter::WriteExternalReference(ExternalReference<T>& reference) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void ContentWriter::InvokeWriter(T& value, ContentTypeWriter& writer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -53,6 +53,8 @@
|
|||||||
#include "input/gamepad.hpp"
|
#include "input/gamepad.hpp"
|
||||||
#include "input/keyboard.hpp"
|
#include "input/keyboard.hpp"
|
||||||
#include "input/mouse.hpp"
|
#include "input/mouse.hpp"
|
||||||
|
#include "pipeline/writer.hpp"
|
||||||
|
#include "pipeline/compiler.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
//Exposes functions that must be implemented by the platform
|
//Exposes functions that must be implemented by the platform
|
||||||
|
@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
# Add source to this project's executable.
|
# Add source to this project's executable.
|
||||||
add_subdirectory ("01_blank")
|
add_subdirectory ("01_blank")
|
||||||
add_subdirectory ("02_PlatfformerStarterKit")
|
#add_subdirectory ("02_PlatfformerStarterKit")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user