1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Merge pull request #19 from borgesdan/develop

Develop
This commit is contained in:
Danilo Borges 2024-09-07 22:18:58 -03:00 committed by GitHub
commit 111648bd35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
116 changed files with 1024 additions and 4808 deletions

View File

@ -13,7 +13,7 @@ endif()
# VCPKG source directory
set(PROJECT_VCPKG_DIRECTORY "C:/vcpkg")
# Includes directory
set(PROJECT_INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/inc")
set(PROJECT_INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/includes")
# CMAKE_TOOLCHAIN_FILE
include("${PROJECT_VCPKG_DIRECTORY}/scripts/buildsystems/vcpkg.cmake")
@ -21,8 +21,7 @@ project ("xna")
# Include sub-projects.
include_directories(${PROJECT_INCLUDES_DIR})
add_subdirectory ("framework")
add_subdirectory ("sources")
add_subdirectory ("samples")

View File

@ -1,57 +0,0 @@
# CMakeList.txt : CMake project for xna, include source and define
# project specific logic here.
#
# Add source to this project's executable.
add_library (Xn65 STATIC
"csharp/stream.cpp"
"csharp/binary.cpp"
"csharp/type.cpp"
"game/component.cpp"
"game/servicecontainer.cpp"
"content/manager.cpp"
"content/reader.cpp"
"content/lzx/decoder.cpp"
"content/typereadermanager.cpp"
"common/color.cpp"
"common/collision.cpp"
"common/gjk.cpp"
"common/numerics.cpp"
"common/packedvalue.cpp"
"platform-dx/window.cpp"
"platform-dx/device.cpp"
"platform-dx/adapter.cpp"
"platform-dx/swapchain.cpp"
"platform-dx/rendertarget.cpp"
"platform-dx/texture.cpp"
"platform-dx/blendstate.cpp"
"platform-dx/game.cpp"
"platform-dx/gdevicemanager.cpp"
"platform-dx/rasterizerstate.cpp"
"platform-dx/samplerstate.cpp"
"platform-dx/sprite.cpp"
"platform-dx/depthstencilstate.cpp"
"platform-dx/keyboard.cpp"
"platform-dx/mouse.cpp"
"platform-dx/gamepad.cpp"
"platform-dx/soundeffect.cpp"
"platform-dx/displaymode.cpp"
"platform-dx/init.cpp"
"platform-dx/audioengine.cpp"
"graphics/gresource.cpp"
"platform-dx/effect.cpp"
"exception.cpp" "platform-dx/screen.cpp" )
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET Xn65 PROPERTY CXX_STANDARD 20)
endif()
# TODO: Add tests and install targets if needed.
find_package(directxtk CONFIG REQUIRED)
target_link_libraries(
Xn65 D3d11.lib dxgi.lib dxguid.lib d3dcompiler.lib Microsoft::DirectXTK dxguid.lib
#"${PROJECT_INCLUDES_DIR}/libmspack/mspack.lib"
#"${PROJECT_INCLUDES_DIR}/effects11/Effects11.lib"
)

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,222 +0,0 @@
/* This file is part of libmspack.
* (C) 2003-2013 Stuart Caie.
*
* The LZX method was created by Jonathan Forbes and Tomi Poutanen, adapted
* by Microsoft Corporation.
*
* libmspack is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License (LGPL) version 2.1
*
* For further details, see the file COPYING.LIB distributed with libmspack
*/
#include <sys/types.h>
#ifndef MSPACK_LZX_H
#define MSPACK_LZX_H 1
#ifdef __cplusplus
extern "C" {
#endif
/* LZX compression / decompression definitions */
/* some constants defined by the LZX specification */
#define LZX_MIN_MATCH (2)
#define LZX_MAX_MATCH (257)
#define LZX_NUM_CHARS (256)
#define LZX_BLOCKTYPE_INVALID (0) /* also blocktypes 4-7 invalid */
#define LZX_BLOCKTYPE_VERBATIM (1)
#define LZX_BLOCKTYPE_ALIGNED (2)
#define LZX_BLOCKTYPE_UNCOMPRESSED (3)
#define LZX_PRETREE_NUM_ELEMENTS (20)
#define LZX_ALIGNED_NUM_ELEMENTS (8) /* aligned offset tree #elements */
#define LZX_NUM_PRIMARY_LENGTHS (7) /* this one missing from spec! */
#define LZX_NUM_SECONDARY_LENGTHS (249) /* length tree #elements */
/* LZX huffman defines: tweak tablebits as desired */
#define LZX_PRETREE_MAXSYMBOLS (LZX_PRETREE_NUM_ELEMENTS)
#define LZX_PRETREE_TABLEBITS (6)
#define LZX_MAINTREE_MAXSYMBOLS (LZX_NUM_CHARS + 290*8)
#define LZX_MAINTREE_TABLEBITS (12)
#define LZX_LENGTH_MAXSYMBOLS (LZX_NUM_SECONDARY_LENGTHS+1)
#define LZX_LENGTH_TABLEBITS (12)
#define LZX_ALIGNED_MAXSYMBOLS (LZX_ALIGNED_NUM_ELEMENTS)
#define LZX_ALIGNED_TABLEBITS (7)
#define LZX_LENTABLE_SAFETY (64) /* table decoding overruns are allowed */
#define LZX_FRAME_SIZE (32768) /* the size of a frame in LZX */
struct lzxd_stream {
struct mspack_system *sys; /* I/O routines */
struct mspack_file *input; /* input file handle */
struct mspack_file *output; /* output file handle */
off_t offset; /* number of bytes actually output */
off_t length; /* overall decompressed length of stream */
unsigned char *window; /* decoding window */
unsigned int window_size; /* window size */
unsigned int ref_data_size; /* LZX DELTA reference data size */
unsigned int num_offsets; /* number of match_offset entries in table */
unsigned int window_posn; /* decompression offset within window */
unsigned int frame_posn; /* current frame offset within in window */
unsigned int frame; /* the number of 32kb frames processed */
unsigned int reset_interval; /* which frame do we reset the compressor? */
unsigned int R0, R1, R2; /* for the LRU offset system */
unsigned int block_length; /* uncompressed length of this LZX block */
unsigned int block_remaining; /* uncompressed bytes still left to decode */
signed int intel_filesize; /* magic header value used for transform */
unsigned char intel_started; /* has intel E8 decoding started? */
unsigned char block_type; /* type of the current block */
unsigned char header_read; /* have we started decoding at all yet? */
unsigned char input_end; /* have we reached the end of input? */
unsigned char is_delta; /* does stream follow LZX DELTA spec? */
int error;
/* I/O buffering */
unsigned char *inbuf, *i_ptr, *i_end, *o_ptr, *o_end;
unsigned int bit_buffer, bits_left, inbuf_size;
/* huffman code lengths */
unsigned char PRETREE_len [LZX_PRETREE_MAXSYMBOLS + LZX_LENTABLE_SAFETY];
unsigned char MAINTREE_len [LZX_MAINTREE_MAXSYMBOLS + LZX_LENTABLE_SAFETY];
unsigned char LENGTH_len [LZX_LENGTH_MAXSYMBOLS + LZX_LENTABLE_SAFETY];
unsigned char ALIGNED_len [LZX_ALIGNED_MAXSYMBOLS + LZX_LENTABLE_SAFETY];
/* huffman decoding tables */
unsigned short PRETREE_table [(1 << LZX_PRETREE_TABLEBITS) +
(LZX_PRETREE_MAXSYMBOLS * 2)];
unsigned short MAINTREE_table[(1 << LZX_MAINTREE_TABLEBITS) +
(LZX_MAINTREE_MAXSYMBOLS * 2)];
unsigned short LENGTH_table [(1 << LZX_LENGTH_TABLEBITS) +
(LZX_LENGTH_MAXSYMBOLS * 2)];
unsigned short ALIGNED_table [(1 << LZX_ALIGNED_TABLEBITS) +
(LZX_ALIGNED_MAXSYMBOLS * 2)];
unsigned char LENGTH_empty;
/* this is used purely for doing the intel E8 transform */
unsigned char e8_buf[LZX_FRAME_SIZE];
};
/**
* Allocates and initialises LZX decompression state for decoding an LZX
* stream.
*
* This routine uses system->alloc() to allocate memory. If memory
* allocation fails, or the parameters to this function are invalid,
* NULL is returned.
*
* @param system an mspack_system structure used to read from
* the input stream and write to the output
* stream, also to allocate and free memory.
* @param input an input stream with the LZX data.
* @param output an output stream to write the decoded data to.
* @param window_bits the size of the decoding window, which must be
* between 15 and 21 inclusive for regular LZX
* data, or between 17 and 25 inclusive for
* LZX DELTA data.
* @param reset_interval the interval at which the LZX bitstream is
* reset, in multiples of LZX frames (32678
* bytes), e.g. a value of 2 indicates the input
* stream resets after every 65536 output bytes.
* A value of 0 indicates that the bitstream never
* resets, such as in CAB LZX streams.
* @param input_buffer_size the number of bytes to use as an input
* bitstream buffer.
* @param output_length the length in bytes of the entirely
* decompressed output stream, if known in
* advance. It is used to correctly perform the
* Intel E8 transformation, which must stop 6
* bytes before the very end of the
* decompressed stream. It is not otherwise used
* or adhered to. If the full decompressed
* length is known in advance, set it here.
* If it is NOT known, use the value 0, and call
* lzxd_set_output_length() once it is
* known. If never set, 4 of the final 6 bytes
* of the output stream may be incorrect.
* @param is_delta should be zero for all regular LZX data,
* non-zero for LZX DELTA encoded data.
* @return a pointer to an initialised lzxd_stream structure, or NULL if
* there was not enough memory or parameters to the function were wrong.
*/
extern struct lzxd_stream *lzxd_init(struct mspack_system *system,
struct mspack_file *input,
struct mspack_file *output,
int window_bits,
int reset_interval,
int input_buffer_size,
off_t output_length,
char is_delta);
/* see description of output_length in lzxd_init() */
extern void lzxd_set_output_length(struct lzxd_stream *lzx,
off_t output_length);
/**
* Reads LZX DELTA reference data into the window and allows
* lzxd_decompress() to reference it.
*
* Call this before the first call to lzxd_decompress().
* @param lzx the LZX stream to apply this reference data to
* @param system an mspack_system implementation to use with the
* input param. Only read() will be called.
* @param input an input file handle to read reference data using
* system->read().
* @param length the length of the reference data. Cannot be longer
* than the LZX window size.
* @return an error code, or MSPACK_ERR_OK if successful
*/
extern int lzxd_set_reference_data(struct lzxd_stream *lzx,
struct mspack_system *system,
struct mspack_file *input,
unsigned int length);
/**
* Decompresses entire or partial LZX streams.
*
* The number of bytes of data that should be decompressed is given as the
* out_bytes parameter. If more bytes are decoded than are needed, they
* will be kept over for a later invocation.
*
* The output bytes will be passed to the system->write() function given in
* lzxd_init(), using the output file handle given in lzxd_init(). More than
* one call may be made to system->write().
* Input bytes will be read in as necessary using the system->read()
* function given in lzxd_init(), using the input file handle given in
* lzxd_init(). This will continue until system->read() returns 0 bytes,
* or an error. Errors will be passed out of the function as
* MSPACK_ERR_READ errors. Input streams should convey an "end of input
* stream" by refusing to supply all the bytes that LZX asks for when they
* reach the end of the stream, rather than return an error code.
*
* If any error code other than MSPACK_ERR_OK is returned, the stream
* should be considered unusable and lzxd_decompress() should not be
* called again on this stream.
*
* @param lzx LZX decompression state, as allocated by lzxd_init().
* @param out_bytes the number of bytes of data to decompress.
* @return an error code, or MSPACK_ERR_OK if successful
*/
extern int lzxd_decompress(struct lzxd_stream *lzx, off_t out_bytes);
/**
* Frees all state associated with an LZX data stream. This will call
* system->free() using the system pointer given in lzxd_init().
*
* @param lzx LZX decompression state to free.
*/
void lzxd_free(struct lzxd_stream *lzx);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,885 +0,0 @@
#ifndef XNA_XNADX_HPP
#define XNA_XNADX_HPP
#define NOMINMAX
//---------------- DX INCLUDES ----------------//
//DirectX
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#define NO_D3D11_DEBUG_NAME
#endif
#include "dxgi.h"
#include "d3d11.h"
#include <d3d11_1.h>
#include <d3d11_2.h>
#include <d3d11_3.h>
#include <d3d11_4.h>
#include <d3d11shader.h>
#include <d3d11shadertracing.h>
#include <d3dcommon.h>
#include <d3dcsx.h>
//DirectXTK
#include <DirectXMath.h>
#include <Audio.h>
#include <BufferHelpers.h>
#include <CommonStates.h>
#include <DDSTextureLoader.h>
#include <DirectXHelpers.h>
#include <Effects.h>
#include <GamePad.h>
#include <GeometricPrimitive.h>
#include <GraphicsMemory.h>
#include <Keyboard.h>
#include <Model.h>
#include <Mouse.h>
#include <PostProcess.h>
#include <PrimitiveBatch.h>
#include <ScreenGrab.h>
#include <SimpleMath.h>
#include <SpriteBatch.h>
#include <SpriteFont.h>
#include <VertexTypes.h>
#include <WICTextureLoader.h>
//Windows
#include <Windows.h>
#include <windowsx.h>
#include <Windows.Foundation.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
//---------------- USINGS ----------------//
template <typename T>
using comptr = Microsoft::WRL::ComPtr<T>;
//---------------- INCLUDES ----------------//
#include "xna.hpp"
//---------------- CLASSES ----------------//
namespace xna {
//---------------- HELPERS ----------------//
struct DxHelpers {
static constexpr RECT RectangleToDx(Rectangle const& value) {
RECT rect{};
rect.top = value.Top();
rect.left = value.Left();
rect.right = value.Right();
rect.bottom = value.Bottom();
return rect;
}
static constexpr D3D11_VIEWPORT ViewportToDx(Viewport const& value) {
D3D11_VIEWPORT _view{};
_view.TopLeftX = value.X;
_view.TopLeftY = value.Y;
_view.Width = value.Width;
_view.Height = value.Height;
_view.MinDepth = value.MinDetph;
_view.MaxDepth = value.MaxDepth;
return _view;
}
static constexpr DirectX::XMVECTOR VectorToDx(Vector2 const& value) {
DirectX::XMVECTOR v{};
v.m128_f32[0] = value.X;
v.m128_f32[1] = value.Y;
return v;
}
static constexpr DirectX::XMVECTOR VectorToDx(Vector3 const& value) {
DirectX::XMVECTOR v{};
v.m128_f32[0] = value.X;
v.m128_f32[1] = value.Y;
v.m128_f32[2] = value.Z;
return v;
}
static constexpr DirectX::XMFLOAT3 Vector3ToDx(Vector3 const& value) {
DirectX::XMFLOAT3 v{};
v.x = value.X;
v.y = value.Y;
v.z = value.Z;
return v;
}
static constexpr DirectX::XMVECTOR VectorToDx(Vector4 const& value) {
DirectX::XMVECTOR v{};
v.m128_f32[0] = value.X;
v.m128_f32[1] = value.Y;
v.m128_f32[2] = value.Z;
v.m128_f32[3] = value.W;
return v;
}
static constexpr DirectX::XMMATRIX MatrixToDx(Matrix const& value) {
auto m = DirectX::XMMATRIX(
value.M11,
value.M12,
value.M13,
value.M14,
value.M21,
value.M22,
value.M23,
value.M24,
value.M31,
value.M32,
value.M33,
value.M34,
value.M41,
value.M42,
value.M43,
value.M44
);
return m;
}
static constexpr DirectX::SpriteSortMode SpriteSortToDx(SpriteSortMode value) {
return static_cast<DirectX::SpriteSortMode>(static_cast<int>(value));
}
static constexpr DXGI_FORMAT SurfaceFormatToDx(SurfaceFormat format)
{
switch (format)
{
case SurfaceFormat::Color://21
return DXGI_FORMAT_R8G8B8A8_UNORM;
case SurfaceFormat::Bgr565: //23
return DXGI_FORMAT_B5G6R5_UNORM;
case SurfaceFormat::Bgra5551://25
return DXGI_FORMAT_B5G5R5A1_UNORM;
case SurfaceFormat::Bgra4444://26
return DXGI_FORMAT_B4G4R4A4_UNORM;
case SurfaceFormat::Dxt1://827611204
return DXGI_FORMAT_BC1_UNORM;
case SurfaceFormat::Dxt3://861165636
return DXGI_FORMAT_BC2_UNORM;
case SurfaceFormat::Dxt5://894720068
return DXGI_FORMAT_BC3_UNORM;
case SurfaceFormat::NormalizedByte2://60
return DXGI_FORMAT_R8G8_SNORM;
case SurfaceFormat::NormalizedByte4://63
return DXGI_FORMAT_R8G8B8A8_SNORM;
case SurfaceFormat::Rgba1010102://31
return DXGI_FORMAT_R10G10B10A2_UNORM;
case SurfaceFormat::Rg32://34
return DXGI_FORMAT_R16G16_UNORM;
case SurfaceFormat::Rgba64://36
return DXGI_FORMAT_R16G16B16A16_UNORM;
case SurfaceFormat::Alpha8://28
return DXGI_FORMAT_A8_UNORM;
case SurfaceFormat::Single://114
return DXGI_FORMAT_R32_FLOAT;
case SurfaceFormat::Vector2://115
return DXGI_FORMAT_R32G32_FLOAT;
case SurfaceFormat::Vector4://116
return DXGI_FORMAT_R32G32B32A32_FLOAT;
case SurfaceFormat::HalfSingle://111
return DXGI_FORMAT_R16_FLOAT;
case SurfaceFormat::HalfVector2://112
return DXGI_FORMAT_R16G16_FLOAT;
case SurfaceFormat::HalfVector4://113
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case SurfaceFormat::HdrBlendable://113
return DXGI_FORMAT_R16G16B16A16_FLOAT;
default://0
return DXGI_FORMAT_UNKNOWN;
}
}
static constexpr SurfaceFormat SurfaceFormatToXna(DXGI_FORMAT format) {
switch (format)
{
case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_B8G8R8A8_UNORM:
return SurfaceFormat::Color;
case DXGI_FORMAT_B5G6R5_UNORM:
return SurfaceFormat::Bgr565;
case DXGI_FORMAT_B5G5R5A1_UNORM:
return SurfaceFormat::Bgra5551;
case DXGI_FORMAT_B4G4R4A4_UNORM:
return SurfaceFormat::Bgra4444;
case DXGI_FORMAT_BC2_UNORM:
return SurfaceFormat::Dxt3;
case DXGI_FORMAT_BC3_UNORM:
return SurfaceFormat::Dxt5;
case DXGI_FORMAT_R8G8_SNORM:
return SurfaceFormat::NormalizedByte2;
case DXGI_FORMAT_R8G8B8A8_SNORM:
return SurfaceFormat::NormalizedByte4;
case DXGI_FORMAT_R10G10B10A2_UNORM:
return SurfaceFormat::Rgba1010102;
case DXGI_FORMAT_R16G16_UNORM:
return SurfaceFormat::Rg32;
case DXGI_FORMAT_R16G16B16A16_UNORM:
return SurfaceFormat::Rgba64;
case DXGI_FORMAT_A8_UNORM:
return SurfaceFormat::Alpha8;
case DXGI_FORMAT_R32_FLOAT:
return SurfaceFormat::Single;
case DXGI_FORMAT_R32G32_FLOAT:
return SurfaceFormat::Vector2;
case DXGI_FORMAT_R32G32B32A32_FLOAT:
return SurfaceFormat::Vector4;
case DXGI_FORMAT_R16_FLOAT:
return SurfaceFormat::HalfSingle;
case DXGI_FORMAT_R16G16_FLOAT:
return SurfaceFormat::HalfVector2;
case DXGI_FORMAT_R16G16B16A16_FLOAT:
return SurfaceFormat::HalfVector4;
default:
return SurfaceFormat::Unknown;
}
}
static constexpr Blend BlendToXna(D3D11_BLEND blend) {
switch (blend) {
case D3D11_BLEND_ZERO:
return Blend::Zero;
case D3D11_BLEND_ONE:
return Blend::One;
case D3D11_BLEND_SRC_COLOR:
return Blend::SourceColor;
case D3D11_BLEND_INV_SRC_COLOR:
return Blend::InverseSourceColor;
case D3D11_BLEND_SRC_ALPHA:
return Blend::SourceAlpha;
case D3D11_BLEND_INV_SRC_ALPHA:
return Blend::InverseSourceAlpha;
case D3D11_BLEND_DEST_ALPHA:
return Blend::DestinationAlpha;
case D3D11_BLEND_INV_DEST_ALPHA:
return Blend::InverseDestinationAlpha;
case D3D11_BLEND_DEST_COLOR:
return Blend::DestinationColor;
case D3D11_BLEND_INV_DEST_COLOR:
return Blend::InverseDestinationColor;
case D3D11_BLEND_SRC_ALPHA_SAT:
return Blend::SourceAlphaSaturation;
case D3D11_BLEND_BLEND_FACTOR:
return Blend::BlendFactor;
case D3D11_BLEND_INV_BLEND_FACTOR:
return Blend::InverseBlendFactor;
case D3D11_BLEND_SRC1_COLOR:
return Blend::Source1Color;
case D3D11_BLEND_INV_SRC1_COLOR:
return Blend::InverseSource1Color;
case D3D11_BLEND_SRC1_ALPHA:
return Blend::Source1Alpha;
case D3D11_BLEND_INV_SRC1_ALPHA:
return Blend::InverseSource1Alpha;
default:
return Blend::Zero;
}
}
static constexpr D3D11_BLEND BlendToDx(Blend blend) {
switch (blend)
{
case xna::Blend::Zero:
return D3D11_BLEND_ZERO;
case xna::Blend::One:
return D3D11_BLEND_ONE;
case xna::Blend::SourceColor:
return D3D11_BLEND_SRC_COLOR;
case xna::Blend::InverseSourceColor:
return D3D11_BLEND_INV_SRC_COLOR;
case xna::Blend::SourceAlpha:
return D3D11_BLEND_SRC_ALPHA;
case xna::Blend::InverseSourceAlpha:
return D3D11_BLEND_INV_SRC_ALPHA;
case xna::Blend::DestinationAlpha:
return D3D11_BLEND_DEST_ALPHA;
case xna::Blend::InverseDestinationAlpha:
return D3D11_BLEND_INV_DEST_ALPHA;
case xna::Blend::DestinationColor:
return D3D11_BLEND_DEST_COLOR;
case xna::Blend::InverseDestinationColor:
return D3D11_BLEND_INV_DEST_COLOR;
case xna::Blend::SourceAlphaSaturation:
return D3D11_BLEND_SRC_ALPHA_SAT;
case xna::Blend::BlendFactor:
return D3D11_BLEND_BLEND_FACTOR;
case xna::Blend::InverseBlendFactor:
return D3D11_BLEND_INV_BLEND_FACTOR;
case xna::Blend::Source1Color:
return D3D11_BLEND_SRC1_COLOR;
case xna::Blend::InverseSource1Color:
return D3D11_BLEND_INV_SRC1_COLOR;
case xna::Blend::Source1Alpha:
return D3D11_BLEND_SRC1_ALPHA;
case xna::Blend::InverseSource1Alpha:
return D3D11_BLEND_INV_SRC1_ALPHA;
default:
return D3D11_BLEND_ZERO;
}
}
static constexpr D3D11_BLEND_OP BlendOperationToDx(BlendOperation op) {
return static_cast<D3D11_BLEND_OP>(static_cast<int>(op) + 1);
}
static constexpr BlendOperation BlendOperationToXna(D3D11_BLEND_OP op) {
return static_cast<BlendOperation>(static_cast<int>(op) - 1);
}
static constexpr D3D11_COLOR_WRITE_ENABLE ColorWriteChannelsToDx(ColorWriteChannels colorWrite) {
switch (colorWrite)
{
case xna::ColorWriteChannels::Red:
return D3D11_COLOR_WRITE_ENABLE_RED;
case xna::ColorWriteChannels::Green:
return D3D11_COLOR_WRITE_ENABLE_GREEN;
case xna::ColorWriteChannels::Blue:
return D3D11_COLOR_WRITE_ENABLE_BLUE;
case xna::ColorWriteChannels::Alpha:
return D3D11_COLOR_WRITE_ENABLE_ALPHA;
case xna::ColorWriteChannels::All:
return D3D11_COLOR_WRITE_ENABLE_ALL;
default:
return D3D11_COLOR_WRITE_ENABLE_ALL;
}
}
static constexpr D3D11_TEXTURE_ADDRESS_MODE TextureAddresModeToDx(TextureAddressMode value) {
return static_cast<D3D11_TEXTURE_ADDRESS_MODE>(static_cast<int>(value) + 1);
}
static constexpr TextureAddressMode TextureAddresModeToXna(D3D11_TEXTURE_ADDRESS_MODE value) {
return static_cast<TextureAddressMode>(value - 1);
}
};
struct PlatformInit {
static void Init() {
InitRegisteredTypes();
InitActivadors();
}
static void InitRegisteredTypes();
static void InitActivadors();
private:
template <typename T>
static void insertRegisteredReader(String const& readerName) {
const auto reader = typeof<T>();
//Type::NameOfRegisteredTypes.insert({ "xna::" + readerName, reader });
Type::NameOfRegisteredTypes.insert({ reader->FullName(), reader });
Type::NameOfRegisteredTypes.insert({ "Microsoft.Xna.Framework.Content." + readerName, reader });
}
template <typename T>
static void insertRegisteredReader(String const& readerName, String const& microsoftNameFullName) {
const auto reader = typeof<T>();
//Type::NameOfRegisteredTypes.insert({ "xna::" + readerName, reader });
Type::NameOfRegisteredTypes.insert({ reader->FullName(), reader });
Type::NameOfRegisteredTypes.insert({ microsoftNameFullName, reader });
}
template <typename T>
static void insertActivadorReader() {
ContentTypeReaderActivador::SetActivador(typeof<T>(), []() -> sptr<ContentTypeReader> {
auto obj = snew<T>();
return reinterpret_pointer_cast<ContentTypeReader>(obj);
});
}
};
// Helper class for animation and simulation timing.
class StepTimer
{
public:
StepTimer() noexcept(false) :
m_elapsedTicks(0),
m_totalTicks(0),
m_leftOverTicks(0),
m_frameCount(0),
m_framesPerSecond(0),
m_framesThisSecond(0),
m_qpcSecondCounter(0),
m_isFixedTimeStep(false),
m_targetElapsedTicks(TicksPerSecond / 60)
{
if (!QueryPerformanceFrequency(&m_qpcFrequency))
{
throw std::exception();
}
if (!QueryPerformanceCounter(&m_qpcLastTime))
{
throw std::exception();
}
// Initialize max delta to 1/10 of a second.
m_qpcMaxDelta = static_cast<uint64_t>(m_qpcFrequency.QuadPart / 10);
}
// Get elapsed time since the previous Update call.
uint64_t GetElapsedTicks() const noexcept { return m_elapsedTicks; }
double GetElapsedSeconds() const noexcept { return TicksToSeconds(m_elapsedTicks); }
// Get total time since the start of the program.
uint64_t GetTotalTicks() const noexcept { return m_totalTicks; }
double GetTotalSeconds() const noexcept { return TicksToSeconds(m_totalTicks); }
// Get total number of updates since start of the program.
uint32_t GetFrameCount() const noexcept { return m_frameCount; }
// Get the current framerate.
uint32_t GetFramesPerSecond() const noexcept { return m_framesPerSecond; }
// Set whether to use fixed or variable timestep mode.
void SetFixedTimeStep(bool isFixedTimestep) noexcept { m_isFixedTimeStep = isFixedTimestep; }
// Set how often to call Update when in fixed timestep mode.
void SetTargetElapsedTicks(uint64_t targetElapsed) noexcept { m_targetElapsedTicks = targetElapsed; }
void SetTargetElapsedSeconds(double targetElapsed) noexcept { m_targetElapsedTicks = SecondsToTicks(targetElapsed); }
// Integer format represents time using 10,000,000 ticks per second.
static constexpr uint64_t TicksPerSecond = 10000000;
static constexpr double TicksToSeconds(uint64_t ticks) noexcept { return static_cast<double>(ticks) / TicksPerSecond; }
static constexpr uint64_t SecondsToTicks(double seconds) noexcept { return static_cast<uint64_t>(seconds * TicksPerSecond); }
// After an intentional timing discontinuity (for instance a blocking IO operation)
// call this to avoid having the fixed timestep logic attempt a set of catch-up
// Update calls.
void ResetElapsedTime()
{
if (!QueryPerformanceCounter(&m_qpcLastTime))
{
throw std::exception();
}
m_leftOverTicks = 0;
m_framesPerSecond = 0;
m_framesThisSecond = 0;
m_qpcSecondCounter = 0;
}
// Update timer state, calling the specified Update function the appropriate number of times.
template<typename TUpdate>
void Tick(const TUpdate& update)
{
// Query the current time.
LARGE_INTEGER currentTime;
if (!QueryPerformanceCounter(&currentTime))
{
throw std::exception();
}
uint64_t timeDelta = static_cast<uint64_t>(currentTime.QuadPart - m_qpcLastTime.QuadPart);
m_qpcLastTime = currentTime;
m_qpcSecondCounter += timeDelta;
// Clamp excessively large time deltas (e.g. after paused in the debugger).
if (timeDelta > m_qpcMaxDelta)
{
timeDelta = m_qpcMaxDelta;
}
// Convert QPC units into a canonical tick format. This cannot overflow due to the previous clamp.
timeDelta *= TicksPerSecond;
timeDelta /= static_cast<uint64_t>(m_qpcFrequency.QuadPart);
const uint32_t lastFrameCount = m_frameCount;
if (m_isFixedTimeStep)
{
// Fixed timestep update logic
// If the app is running very close to the target elapsed time (within 1/4 of a millisecond) just clamp
// the clock to exactly match the target value. This prevents tiny and irrelevant errors
// from accumulating over time. Without this clamping, a game that requested a 60 fps
// fixed update, running with vsync enabled on a 59.94 NTSC display, would eventually
// accumulate enough tiny errors that it would drop a frame. It is better to just round
// small deviations down to zero to leave things running smoothly.
if (static_cast<uint64_t>(std::abs(static_cast<int64_t>(timeDelta - m_targetElapsedTicks))) < TicksPerSecond / 4000)
{
timeDelta = m_targetElapsedTicks;
}
m_leftOverTicks += timeDelta;
while (m_leftOverTicks >= m_targetElapsedTicks)
{
m_elapsedTicks = m_targetElapsedTicks;
m_totalTicks += m_targetElapsedTicks;
m_leftOverTicks -= m_targetElapsedTicks;
m_frameCount++;
update();
}
}
else
{
// Variable timestep update logic.
m_elapsedTicks = timeDelta;
m_totalTicks += timeDelta;
m_leftOverTicks = 0;
m_frameCount++;
update();
}
// Track the current framerate.
if (m_frameCount != lastFrameCount)
{
m_framesThisSecond++;
}
if (m_qpcSecondCounter >= static_cast<uint64_t>(m_qpcFrequency.QuadPart))
{
m_framesPerSecond = m_framesThisSecond;
m_framesThisSecond = 0;
m_qpcSecondCounter %= static_cast<uint64_t>(m_qpcFrequency.QuadPart);
}
}
private:
// Source timing data uses QPC units.
LARGE_INTEGER m_qpcFrequency;
LARGE_INTEGER m_qpcLastTime;
uint64_t m_qpcMaxDelta;
// Derived timing data uses a canonical tick format.
uint64_t m_elapsedTicks;
uint64_t m_totalTicks;
uint64_t m_leftOverTicks;
// Members for tracking the framerate.
uint32_t m_frameCount;
uint32_t m_framesPerSecond;
uint32_t m_framesThisSecond;
uint64_t m_qpcSecondCounter;
// Members for configuring fixed timestep mode.
bool m_isFixedTimeStep;
uint64_t m_targetElapsedTicks;
};
//---------------- IMPLEMENTATIONS ----------------//
struct SpriteFont::PlatformImplementation {
uptr<DirectX::SpriteFont> dxSpriteFont{ nullptr };
};
struct SpriteBatch::PlatformImplementation {
sptr<DirectX::SpriteBatch> dxSpriteBatch = nullptr;
comptr<ID3D11InputLayout> dxInputLayout = nullptr;
sptr<DirectX::DX11::IEffect> dxEffectBuffer = nullptr;
};
struct GraphicsAdapter::PlatformImplementation {
comptr<IDXGIAdapter1> dxAdapter = nullptr;
comptr<IDXGIFactory1> dxFactory = nullptr;
};
struct BlendRenderTarget {
bool Enabled{ true };
Blend Source{ Blend::SourceAlpha };
Blend Destination{ Blend::InverseSourceAlpha };
BlendOperation Operation{ BlendOperation::Add };
Blend SourceAlpha{ Blend::One };
Blend DestinationAlpha{ Blend::Zero };
BlendOperation OperationAlpha{ BlendOperation::Add };
ColorWriteChannels WriteMask{ ColorWriteChannels::All };
constexpr BlendRenderTarget() = default;
};
struct BlendState::PlatformImplementation {
comptr<ID3D11BlendState> dxBlendState = nullptr;
D3D11_BLEND_DESC dxDescription{};
float blendFactor[4]{ 1.0F, 1.0F, 1.0F, 1.0F };
UINT sampleMask{ 0xffffffff };
};
struct DepthStencilState::PlatformImplementation {
comptr<ID3D11DepthStencilState> dxDepthStencil = nullptr;
D3D11_DEPTH_STENCIL_DESC dxDescription{};
};
struct GamePad::PlatformImplementation {
uptr<DirectX::GamePad> _dxGamePad = unew<DirectX::GamePad>();
void Suspend() const {
if (_dxGamePad)
_dxGamePad->Suspend();
}
void Resume() const {
if (_dxGamePad)
_dxGamePad->Resume();
}
};
struct Keyboard::PlatformImplementation {
PlatformImplementation() {
_dxKeyboard = unew<DirectX::Keyboard>();
}
uptr<DirectX::Keyboard> _dxKeyboard = nullptr;
inline void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const {
if (_dxKeyboard)
_dxKeyboard->ProcessMessage(message, wParam, lParam);
}
};
struct Mouse::PlatformImplementation {
PlatformImplementation() {
_dxMouse = unew<DirectX::Mouse>();
}
inline void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const {
if (_dxMouse)
_dxMouse->ProcessMessage(message, wParam, lParam);
}
uptr<DirectX::Mouse> _dxMouse = nullptr;
};
struct RasterizerState::PlatformImplementation {
comptr<ID3D11RasterizerState> dxRasterizerState = nullptr;
D3D11_RASTERIZER_DESC dxDescription{};
};
struct SamplerState::PlatformImplementation {
comptr<ID3D11SamplerState> _samplerState = nullptr;
D3D11_SAMPLER_DESC _description{};
};
struct SwapChain::PlatformImplementation {
comptr<IDXGISwapChain1> dxSwapChain{ nullptr };
DXGI_SWAP_CHAIN_DESC1 dxDescription{};
DXGI_SWAP_CHAIN_FULLSCREEN_DESC dxFullScreenDescription{};
bool GetBackBuffer(comptr<ID3D11Texture2D>& texture2D) const {
if (!dxSwapChain)
return false;
const auto hr = dxSwapChain->GetBuffer(0, __uuidof(texture2D), (void**)texture2D.GetAddressOf());
return !FAILED(hr);
}
};
struct Texture2D::PlatformImplementation {
comptr<ID3D11Texture2D> dxTexture2D{ nullptr };
comptr<ID3D11ShaderResourceView> dxShaderResource{ nullptr };
D3D11_SUBRESOURCE_DATA dxSubResource{};
D3D11_TEXTURE2D_DESC dxDescription{};
D3D11_SHADER_RESOURCE_VIEW_DESC dxShaderDescription{};
};
struct RenderTarget2D::PlatformImplementation {
comptr<ID3D11RenderTargetView> _renderTargetView = nullptr;
D3D11_RENDER_TARGET_VIEW_DESC _renderTargetDesc{};
};
enum class GameWindowMode : UINT {
Fullscreen = WS_POPUP | WS_VISIBLE,
Windowed = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE,
Borderless = WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE,
};
struct GameWindow::PlatformImplementation {
public:
PlatformImplementation(GameWindow* gameWindow): gameWindow(gameWindow){}
constexpr void Mode(GameWindowMode mode) {
_windowStyle = static_cast<int>(mode);
}
constexpr GameWindowMode Mode() const {
return static_cast<GameWindowMode>(_windowStyle);
}
void Position(int width, int height, bool update = true);
void Size(int width, int height, bool update = true);
inline HINSTANCE HInstance() const {
return _hInstance;
}
inline HWND WindowHandle() const {
return _windowHandle;
}
constexpr int Width() const {
return _windowWidth;
}
constexpr int Height() const {
return _windowHeight;
}
inline void Icon(unsigned int icon) {
_windowIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(icon));
}
inline void Icon(HICON icon) {
_windowIcon = icon;
}
inline void Cursor(unsigned int cursor) {
_windowCursor = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(cursor));
}
inline void Cursor(HCURSOR cursor) {
_windowCursor = cursor;
}
constexpr float CenterX() const {
return _windowCenterX;
}
constexpr float CenterY() const {
return _windowCenterY;
}
inline void CursorVisibility(bool visible) const {
ShowCursor(visible);
}
inline void Close() const {
PostMessage(_windowHandle, WM_DESTROY, 0, 0);
}
constexpr COLORREF Color() const {
return _windowColor;
}
constexpr void Color(COLORREF color) {
_windowColor = color;
}
constexpr void Color(BYTE r, BYTE g, BYTE b) {
_windowColor = RGB(r, g, b);
}
bool Create();
bool Update();
static LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
private:
friend class GameWindow;
GameWindow* gameWindow = nullptr;
HINSTANCE _hInstance{ nullptr };
HWND _windowHandle{ nullptr };
int _windowWidth{ 800 };
int _windowHeight{ 480 };
HICON _windowIcon{ nullptr };
HCURSOR _windowCursor{ nullptr };
COLORREF _windowColor{ RGB(0,0,0) };
String _windowTitle{ "Xna++ Game Development" };
DWORD _windowStyle{ 0 };
int _windowPosX{ 0 };
int _windowPosY{ 0 };
float _windowCenterX{ 0 };
float _windowCenterY{ 0 };
inline void setPosition() {
_windowPosX = GetSystemMetrics(SM_CXSCREEN) / 2 - _windowWidth / 2;
_windowPosY = GetSystemMetrics(SM_CYSCREEN) / 2 - _windowHeight / 2;
}
inline void setCenter() {
_windowCenterX = _windowWidth / 2.0f;
_windowCenterY = _windowHeight / 2.0f;
}
};
struct AudioEngine::PlatformImplementation {
PlatformImplementation() {
_dxAudioEngine = unew<DirectX::AudioEngine>(
#ifdef _DEBUG
DirectX::AudioEngine_Debug
#endif
);
}
~PlatformImplementation() {
if (_dxAudioEngine) {
_dxAudioEngine->Suspend();
}
}
uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
};
struct GraphicsDevice::PlatformImplementation {
comptr<ID3D11Device> _device = nullptr;
comptr<ID3D11DeviceContext> _context = nullptr;
comptr<IDXGIFactory1> _factory = nullptr;
sptr<SwapChain> _swapChain = nullptr;
sptr<RenderTarget2D> _renderTarget2D = nullptr;
intptr_t windowHandle{ 0 };
D3D_FEATURE_LEVEL featureLevels[7] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1,
};
D3D_FEATURE_LEVEL currentFeatureLevel{ D3D_FEATURE_LEVEL_11_1 };
private:
friend class GraphicsDevice;
float _backgroundColor[4] = { 0, 0, 0, 0 };
UINT vSyncValue = 1;
};
struct Game::PlatformImplementation {
private:
friend class Game;
xna::StepTimer _stepTimer{};
};
struct SoundEffectInstance::PlatformImplementation {
uptr<DirectX::SoundEffectInstance> _dxInstance = nullptr;
};
struct SoundEffect::PlatformImplementation {
uptr<DirectX::SoundEffect> _dxSoundEffect = nullptr;
};
struct Effect::PlatformImplementation {
sptr<DirectX::IEffect> dxEffect = nullptr;
};
struct BasicEffect::PlatformImplementation {
sptr<DirectX::BasicEffect> dxBasicEffect = nullptr;
};
}
#endif

View File

@ -0,0 +1,4 @@
#include "steptimer.hpp"
#include "init.hpp"
#include "implementations.hpp"
#include "helpers.hpp"

View File

@ -0,0 +1,61 @@
#ifndef XNA_DX_HEADERS_HPP
#define XNA_DX_HEADERS_HPP
#define NOMINMAX
//---------------- DX INCLUDES ----------------//
//DirectX
#if defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d11_x.h>
#define NO_D3D11_DEBUG_NAME
#endif
#include "dxgi.h"
#include "d3d11.h"
#include <d3d11_1.h>
#include <d3d11_2.h>
#include <d3d11_3.h>
#include <d3d11_4.h>
#include <d3d11shader.h>
#include <d3d11shadertracing.h>
#include <d3dcommon.h>
#include <d3dcsx.h>
//DirectXTK
#include <DirectXMath.h>
#include <Audio.h>
#include <BufferHelpers.h>
#include <CommonStates.h>
#include <DDSTextureLoader.h>
#include <DirectXHelpers.h>
#include <Effects.h>
#include <GamePad.h>
#include <GeometricPrimitive.h>
#include <GraphicsMemory.h>
#include <Keyboard.h>
#include <Model.h>
#include <Mouse.h>
#include <PostProcess.h>
#include <PrimitiveBatch.h>
#include <ScreenGrab.h>
#include <SimpleMath.h>
#include <SpriteBatch.h>
#include <SpriteFont.h>
#include <VertexTypes.h>
#include <WICTextureLoader.h>
//Windows
#include <Windows.h>
#include <windowsx.h>
#include <Windows.Foundation.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
//Xna
#include "xna/framework.hpp"
//---------------- USINGS ----------------//
template <typename T>
using comptr = Microsoft::WRL::ComPtr<T>;
#endif

311
includes/xna-dx/helpers.hpp Normal file
View File

@ -0,0 +1,311 @@
#ifndef XNA_DX_HELPERS_HPP
#define XNA_DX_HELPERS_HPP
#include "headers.hpp"
namespace xna {
struct DxHelpers {
static constexpr RECT RectangleToDx(Rectangle const& value) {
RECT rect{};
rect.top = value.Top();
rect.left = value.Left();
rect.right = value.Right();
rect.bottom = value.Bottom();
return rect;
}
static constexpr D3D11_VIEWPORT ViewportToDx(Viewport const& value) {
D3D11_VIEWPORT _view{};
_view.TopLeftX = value.X;
_view.TopLeftY = value.Y;
_view.Width = value.Width;
_view.Height = value.Height;
_view.MinDepth = value.MinDetph;
_view.MaxDepth = value.MaxDepth;
return _view;
}
static constexpr DirectX::XMVECTOR VectorToDx(Vector2 const& value) {
DirectX::XMVECTOR v{};
v.m128_f32[0] = value.X;
v.m128_f32[1] = value.Y;
return v;
}
static constexpr DirectX::XMVECTOR VectorToDx(Vector3 const& value) {
DirectX::XMVECTOR v{};
v.m128_f32[0] = value.X;
v.m128_f32[1] = value.Y;
v.m128_f32[2] = value.Z;
return v;
}
static constexpr DirectX::XMFLOAT3 Vector3ToDx(Vector3 const& value) {
DirectX::XMFLOAT3 v{};
v.x = value.X;
v.y = value.Y;
v.z = value.Z;
return v;
}
static constexpr DirectX::XMVECTOR VectorToDx(Vector4 const& value) {
DirectX::XMVECTOR v{};
v.m128_f32[0] = value.X;
v.m128_f32[1] = value.Y;
v.m128_f32[2] = value.Z;
v.m128_f32[3] = value.W;
return v;
}
static constexpr DirectX::XMMATRIX MatrixToDx(Matrix const& value) {
auto m = DirectX::XMMATRIX(
value.M11,
value.M12,
value.M13,
value.M14,
value.M21,
value.M22,
value.M23,
value.M24,
value.M31,
value.M32,
value.M33,
value.M34,
value.M41,
value.M42,
value.M43,
value.M44
);
return m;
}
static constexpr DirectX::SpriteSortMode SpriteSortToDx(SpriteSortMode value) {
return static_cast<DirectX::SpriteSortMode>(static_cast<int>(value));
}
static constexpr DXGI_FORMAT SurfaceFormatToDx(SurfaceFormat format)
{
switch (format)
{
case SurfaceFormat::Color://21
return DXGI_FORMAT_R8G8B8A8_UNORM;
case SurfaceFormat::Bgr565: //23
return DXGI_FORMAT_B5G6R5_UNORM;
case SurfaceFormat::Bgra5551://25
return DXGI_FORMAT_B5G5R5A1_UNORM;
case SurfaceFormat::Bgra4444://26
return DXGI_FORMAT_B4G4R4A4_UNORM;
case SurfaceFormat::Dxt1://827611204
return DXGI_FORMAT_BC1_UNORM;
case SurfaceFormat::Dxt3://861165636
return DXGI_FORMAT_BC2_UNORM;
case SurfaceFormat::Dxt5://894720068
return DXGI_FORMAT_BC3_UNORM;
case SurfaceFormat::NormalizedByte2://60
return DXGI_FORMAT_R8G8_SNORM;
case SurfaceFormat::NormalizedByte4://63
return DXGI_FORMAT_R8G8B8A8_SNORM;
case SurfaceFormat::Rgba1010102://31
return DXGI_FORMAT_R10G10B10A2_UNORM;
case SurfaceFormat::Rg32://34
return DXGI_FORMAT_R16G16_UNORM;
case SurfaceFormat::Rgba64://36
return DXGI_FORMAT_R16G16B16A16_UNORM;
case SurfaceFormat::Alpha8://28
return DXGI_FORMAT_A8_UNORM;
case SurfaceFormat::Single://114
return DXGI_FORMAT_R32_FLOAT;
case SurfaceFormat::Vector2://115
return DXGI_FORMAT_R32G32_FLOAT;
case SurfaceFormat::Vector4://116
return DXGI_FORMAT_R32G32B32A32_FLOAT;
case SurfaceFormat::HalfSingle://111
return DXGI_FORMAT_R16_FLOAT;
case SurfaceFormat::HalfVector2://112
return DXGI_FORMAT_R16G16_FLOAT;
case SurfaceFormat::HalfVector4://113
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case SurfaceFormat::HdrBlendable://113
return DXGI_FORMAT_R16G16B16A16_FLOAT;
default://0
return DXGI_FORMAT_UNKNOWN;
}
}
static constexpr SurfaceFormat SurfaceFormatToXna(DXGI_FORMAT format) {
switch (format)
{
case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_B8G8R8A8_UNORM:
return SurfaceFormat::Color;
case DXGI_FORMAT_B5G6R5_UNORM:
return SurfaceFormat::Bgr565;
case DXGI_FORMAT_B5G5R5A1_UNORM:
return SurfaceFormat::Bgra5551;
case DXGI_FORMAT_B4G4R4A4_UNORM:
return SurfaceFormat::Bgra4444;
case DXGI_FORMAT_BC2_UNORM:
return SurfaceFormat::Dxt3;
case DXGI_FORMAT_BC3_UNORM:
return SurfaceFormat::Dxt5;
case DXGI_FORMAT_R8G8_SNORM:
return SurfaceFormat::NormalizedByte2;
case DXGI_FORMAT_R8G8B8A8_SNORM:
return SurfaceFormat::NormalizedByte4;
case DXGI_FORMAT_R10G10B10A2_UNORM:
return SurfaceFormat::Rgba1010102;
case DXGI_FORMAT_R16G16_UNORM:
return SurfaceFormat::Rg32;
case DXGI_FORMAT_R16G16B16A16_UNORM:
return SurfaceFormat::Rgba64;
case DXGI_FORMAT_A8_UNORM:
return SurfaceFormat::Alpha8;
case DXGI_FORMAT_R32_FLOAT:
return SurfaceFormat::Single;
case DXGI_FORMAT_R32G32_FLOAT:
return SurfaceFormat::Vector2;
case DXGI_FORMAT_R32G32B32A32_FLOAT:
return SurfaceFormat::Vector4;
case DXGI_FORMAT_R16_FLOAT:
return SurfaceFormat::HalfSingle;
case DXGI_FORMAT_R16G16_FLOAT:
return SurfaceFormat::HalfVector2;
case DXGI_FORMAT_R16G16B16A16_FLOAT:
return SurfaceFormat::HalfVector4;
default:
return SurfaceFormat::Unknown;
}
}
static constexpr Blend BlendToXna(D3D11_BLEND blend) {
switch (blend) {
case D3D11_BLEND_ZERO:
return Blend::Zero;
case D3D11_BLEND_ONE:
return Blend::One;
case D3D11_BLEND_SRC_COLOR:
return Blend::SourceColor;
case D3D11_BLEND_INV_SRC_COLOR:
return Blend::InverseSourceColor;
case D3D11_BLEND_SRC_ALPHA:
return Blend::SourceAlpha;
case D3D11_BLEND_INV_SRC_ALPHA:
return Blend::InverseSourceAlpha;
case D3D11_BLEND_DEST_ALPHA:
return Blend::DestinationAlpha;
case D3D11_BLEND_INV_DEST_ALPHA:
return Blend::InverseDestinationAlpha;
case D3D11_BLEND_DEST_COLOR:
return Blend::DestinationColor;
case D3D11_BLEND_INV_DEST_COLOR:
return Blend::InverseDestinationColor;
case D3D11_BLEND_SRC_ALPHA_SAT:
return Blend::SourceAlphaSaturation;
case D3D11_BLEND_BLEND_FACTOR:
return Blend::BlendFactor;
case D3D11_BLEND_INV_BLEND_FACTOR:
return Blend::InverseBlendFactor;
case D3D11_BLEND_SRC1_COLOR:
return Blend::Source1Color;
case D3D11_BLEND_INV_SRC1_COLOR:
return Blend::InverseSource1Color;
case D3D11_BLEND_SRC1_ALPHA:
return Blend::Source1Alpha;
case D3D11_BLEND_INV_SRC1_ALPHA:
return Blend::InverseSource1Alpha;
default:
return Blend::Zero;
}
}
static constexpr D3D11_BLEND BlendToDx(Blend blend) {
switch (blend)
{
case xna::Blend::Zero:
return D3D11_BLEND_ZERO;
case xna::Blend::One:
return D3D11_BLEND_ONE;
case xna::Blend::SourceColor:
return D3D11_BLEND_SRC_COLOR;
case xna::Blend::InverseSourceColor:
return D3D11_BLEND_INV_SRC_COLOR;
case xna::Blend::SourceAlpha:
return D3D11_BLEND_SRC_ALPHA;
case xna::Blend::InverseSourceAlpha:
return D3D11_BLEND_INV_SRC_ALPHA;
case xna::Blend::DestinationAlpha:
return D3D11_BLEND_DEST_ALPHA;
case xna::Blend::InverseDestinationAlpha:
return D3D11_BLEND_INV_DEST_ALPHA;
case xna::Blend::DestinationColor:
return D3D11_BLEND_DEST_COLOR;
case xna::Blend::InverseDestinationColor:
return D3D11_BLEND_INV_DEST_COLOR;
case xna::Blend::SourceAlphaSaturation:
return D3D11_BLEND_SRC_ALPHA_SAT;
case xna::Blend::BlendFactor:
return D3D11_BLEND_BLEND_FACTOR;
case xna::Blend::InverseBlendFactor:
return D3D11_BLEND_INV_BLEND_FACTOR;
case xna::Blend::Source1Color:
return D3D11_BLEND_SRC1_COLOR;
case xna::Blend::InverseSource1Color:
return D3D11_BLEND_INV_SRC1_COLOR;
case xna::Blend::Source1Alpha:
return D3D11_BLEND_SRC1_ALPHA;
case xna::Blend::InverseSource1Alpha:
return D3D11_BLEND_INV_SRC1_ALPHA;
default:
return D3D11_BLEND_ZERO;
}
}
static constexpr D3D11_BLEND_OP BlendOperationToDx(BlendOperation op) {
return static_cast<D3D11_BLEND_OP>(static_cast<int>(op) + 1);
}
static constexpr BlendOperation BlendOperationToXna(D3D11_BLEND_OP op) {
return static_cast<BlendOperation>(static_cast<int>(op) - 1);
}
static constexpr D3D11_COLOR_WRITE_ENABLE ColorWriteChannelsToDx(ColorWriteChannels colorWrite) {
switch (colorWrite)
{
case xna::ColorWriteChannels::Red:
return D3D11_COLOR_WRITE_ENABLE_RED;
case xna::ColorWriteChannels::Green:
return D3D11_COLOR_WRITE_ENABLE_GREEN;
case xna::ColorWriteChannels::Blue:
return D3D11_COLOR_WRITE_ENABLE_BLUE;
case xna::ColorWriteChannels::Alpha:
return D3D11_COLOR_WRITE_ENABLE_ALPHA;
case xna::ColorWriteChannels::All:
return D3D11_COLOR_WRITE_ENABLE_ALL;
default:
return D3D11_COLOR_WRITE_ENABLE_ALL;
}
}
static constexpr D3D11_TEXTURE_ADDRESS_MODE TextureAddresModeToDx(TextureAddressMode value) {
return static_cast<D3D11_TEXTURE_ADDRESS_MODE>(static_cast<int>(value) + 1);
}
static constexpr TextureAddressMode TextureAddresModeToXna(D3D11_TEXTURE_ADDRESS_MODE value) {
return static_cast<TextureAddressMode>(value - 1);
}
};
}
#endif

View File

@ -0,0 +1,310 @@
#ifndef XNA_DX_IMPLEMENTATIONS_HPP
#define XNA_DX_IMPLEMENTATIONS_HPP
#include "headers.hpp"
namespace xna {
struct SpriteFont::PlatformImplementation {
uptr<DirectX::SpriteFont> dxSpriteFont{ nullptr };
};
struct SpriteBatch::PlatformImplementation {
sptr<DirectX::SpriteBatch> dxSpriteBatch = nullptr;
comptr<ID3D11InputLayout> dxInputLayout = nullptr;
sptr<DirectX::DX11::IEffect> dxEffectBuffer = nullptr;
};
struct GraphicsAdapter::PlatformImplementation {
comptr<IDXGIAdapter1> dxAdapter = nullptr;
comptr<IDXGIFactory1> dxFactory = nullptr;
};
struct BlendRenderTarget {
bool Enabled{ true };
Blend Source{ Blend::SourceAlpha };
Blend Destination{ Blend::InverseSourceAlpha };
BlendOperation Operation{ BlendOperation::Add };
Blend SourceAlpha{ Blend::One };
Blend DestinationAlpha{ Blend::Zero };
BlendOperation OperationAlpha{ BlendOperation::Add };
ColorWriteChannels WriteMask{ ColorWriteChannels::All };
constexpr BlendRenderTarget() = default;
};
struct BlendState::PlatformImplementation {
comptr<ID3D11BlendState> dxBlendState = nullptr;
D3D11_BLEND_DESC dxDescription{};
float blendFactor[4]{ 1.0F, 1.0F, 1.0F, 1.0F };
UINT sampleMask{ 0xffffffff };
};
struct DepthStencilState::PlatformImplementation {
comptr<ID3D11DepthStencilState> dxDepthStencil = nullptr;
D3D11_DEPTH_STENCIL_DESC dxDescription{};
};
struct GamePad::PlatformImplementation {
uptr<DirectX::GamePad> _dxGamePad = unew<DirectX::GamePad>();
void Suspend() const {
if (_dxGamePad)
_dxGamePad->Suspend();
}
void Resume() const {
if (_dxGamePad)
_dxGamePad->Resume();
}
};
struct Keyboard::PlatformImplementation {
PlatformImplementation() {
_dxKeyboard = unew<DirectX::Keyboard>();
}
uptr<DirectX::Keyboard> _dxKeyboard = nullptr;
inline void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const {
if (_dxKeyboard)
_dxKeyboard->ProcessMessage(message, wParam, lParam);
}
};
struct Mouse::PlatformImplementation {
PlatformImplementation() {
_dxMouse = unew<DirectX::Mouse>();
}
inline void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const {
if (_dxMouse)
_dxMouse->ProcessMessage(message, wParam, lParam);
}
uptr<DirectX::Mouse> _dxMouse = nullptr;
};
struct RasterizerState::PlatformImplementation {
comptr<ID3D11RasterizerState> dxRasterizerState = nullptr;
D3D11_RASTERIZER_DESC dxDescription{};
};
struct SamplerState::PlatformImplementation {
comptr<ID3D11SamplerState> _samplerState = nullptr;
D3D11_SAMPLER_DESC _description{};
};
struct SwapChain::PlatformImplementation {
comptr<IDXGISwapChain1> dxSwapChain{ nullptr };
DXGI_SWAP_CHAIN_DESC1 dxDescription{};
DXGI_SWAP_CHAIN_FULLSCREEN_DESC dxFullScreenDescription{};
bool GetBackBuffer(comptr<ID3D11Texture2D>& texture2D) const {
if (!dxSwapChain)
return false;
const auto hr = dxSwapChain->GetBuffer(0, __uuidof(texture2D), (void**)texture2D.GetAddressOf());
return !FAILED(hr);
}
};
struct Texture2D::PlatformImplementation {
comptr<ID3D11Texture2D> dxTexture2D{ nullptr };
comptr<ID3D11ShaderResourceView> dxShaderResource{ nullptr };
D3D11_SUBRESOURCE_DATA dxSubResource{};
D3D11_TEXTURE2D_DESC dxDescription{};
D3D11_SHADER_RESOURCE_VIEW_DESC dxShaderDescription{};
};
struct RenderTarget2D::PlatformImplementation {
comptr<ID3D11RenderTargetView> _renderTargetView = nullptr;
D3D11_RENDER_TARGET_VIEW_DESC _renderTargetDesc{};
};
enum class GameWindowMode : UINT {
Fullscreen = WS_POPUP | WS_VISIBLE,
Windowed = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE,
Borderless = WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE,
};
struct GameWindow::PlatformImplementation {
public:
PlatformImplementation(GameWindow* gameWindow) : gameWindow(gameWindow) {}
constexpr void Mode(GameWindowMode mode) {
_windowStyle = static_cast<int>(mode);
}
constexpr GameWindowMode Mode() const {
return static_cast<GameWindowMode>(_windowStyle);
}
void Position(int width, int height, bool update = true);
void Size(int width, int height, bool update = true);
inline HINSTANCE HInstance() const {
return _hInstance;
}
inline HWND WindowHandle() const {
return _windowHandle;
}
constexpr int Width() const {
return _windowWidth;
}
constexpr int Height() const {
return _windowHeight;
}
inline void Icon(unsigned int icon) {
_windowIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(icon));
}
inline void Icon(HICON icon) {
_windowIcon = icon;
}
inline void Cursor(unsigned int cursor) {
_windowCursor = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(cursor));
}
inline void Cursor(HCURSOR cursor) {
_windowCursor = cursor;
}
constexpr float CenterX() const {
return _windowCenterX;
}
constexpr float CenterY() const {
return _windowCenterY;
}
inline void CursorVisibility(bool visible) const {
ShowCursor(visible);
}
inline void Close() const {
PostMessage(_windowHandle, WM_DESTROY, 0, 0);
}
constexpr COLORREF Color() const {
return _windowColor;
}
constexpr void Color(COLORREF color) {
_windowColor = color;
}
constexpr void Color(BYTE r, BYTE g, BYTE b) {
_windowColor = RGB(r, g, b);
}
bool Create();
bool Update();
static LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
private:
friend class GameWindow;
GameWindow* gameWindow = nullptr;
HINSTANCE _hInstance{ nullptr };
HWND _windowHandle{ nullptr };
int _windowWidth{ 800 };
int _windowHeight{ 480 };
HICON _windowIcon{ nullptr };
HCURSOR _windowCursor{ nullptr };
COLORREF _windowColor{ RGB(0,0,0) };
String _windowTitle{ "Xna++ Game Development" };
DWORD _windowStyle{ 0 };
int _windowPosX{ 0 };
int _windowPosY{ 0 };
float _windowCenterX{ 0 };
float _windowCenterY{ 0 };
inline void setPosition() {
_windowPosX = GetSystemMetrics(SM_CXSCREEN) / 2 - _windowWidth / 2;
_windowPosY = GetSystemMetrics(SM_CYSCREEN) / 2 - _windowHeight / 2;
}
inline void setCenter() {
_windowCenterX = _windowWidth / 2.0f;
_windowCenterY = _windowHeight / 2.0f;
}
};
struct AudioEngine::PlatformImplementation {
PlatformImplementation() {
_dxAudioEngine = unew<DirectX::AudioEngine>(
#ifdef _DEBUG
DirectX::AudioEngine_Debug
#endif
);
}
~PlatformImplementation() {
if (_dxAudioEngine) {
_dxAudioEngine->Suspend();
}
}
uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
};
struct GraphicsDevice::PlatformImplementation {
comptr<ID3D11Device> _device = nullptr;
comptr<ID3D11DeviceContext> _context = nullptr;
comptr<IDXGIFactory1> _factory = nullptr;
sptr<SwapChain> _swapChain = nullptr;
sptr<RenderTarget2D> _renderTarget2D = nullptr;
intptr_t windowHandle{ 0 };
D3D_FEATURE_LEVEL featureLevels[7] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1,
};
D3D_FEATURE_LEVEL currentFeatureLevel{ D3D_FEATURE_LEVEL_11_1 };
private:
friend class GraphicsDevice;
float _backgroundColor[4] = { 0, 0, 0, 0 };
UINT vSyncValue = 1;
};
struct Game::PlatformImplementation {
private:
friend class Game;
xna::StepTimer _stepTimer{};
};
struct SoundEffectInstance::PlatformImplementation {
uptr<DirectX::SoundEffectInstance> _dxInstance = nullptr;
};
struct SoundEffect::PlatformImplementation {
uptr<DirectX::SoundEffect> _dxSoundEffect = nullptr;
};
struct Effect::PlatformImplementation {
sptr<DirectX::IEffect> dxEffect = nullptr;
};
struct BasicEffect::PlatformImplementation {
sptr<DirectX::BasicEffect> dxBasicEffect = nullptr;
};
}
#endif

43
includes/xna-dx/init.hpp Normal file
View File

@ -0,0 +1,43 @@
#ifndef XNA_DX_INIT_HPP
#define XNA_DX_INIT_HPP
#include "headers.hpp"
namespace xna {
struct PlatformInit {
static void Init() {
InitRegisteredTypes();
InitActivadors();
}
static void InitRegisteredTypes();
static void InitActivadors();
private:
template <typename T>
static void insertRegisteredReader(String const& readerName) {
const auto reader = typeof<T>();
//Type::NameOfRegisteredTypes.insert({ "xna::" + readerName, reader });
Type::NameOfRegisteredTypes.insert({ reader->FullName(), reader });
Type::NameOfRegisteredTypes.insert({ "Microsoft.Xna.Framework.Content." + readerName, reader });
}
template <typename T>
static void insertRegisteredReader(String const& readerName, String const& microsoftNameFullName) {
const auto reader = typeof<T>();
//Type::NameOfRegisteredTypes.insert({ "xna::" + readerName, reader });
Type::NameOfRegisteredTypes.insert({ reader->FullName(), reader });
Type::NameOfRegisteredTypes.insert({ microsoftNameFullName, reader });
}
template <typename T>
static void insertActivadorReader() {
ContentTypeReaderActivador::SetActivador(typeof<T>(), []() -> sptr<ContentTypeReader> {
auto obj = snew<T>();
return reinterpret_pointer_cast<ContentTypeReader>(obj);
});
}
};
}
#endif

View File

@ -0,0 +1,185 @@
#ifndef XNA_DX_STEPTIMER_HPP
#define XNA_DX_STEPTIMER_HPP
#include "headers.hpp"
namespace xna {
// Helper class for animation and simulation timing.
class StepTimer
{
public:
StepTimer() noexcept(false) :
m_elapsedTicks(0),
m_totalTicks(0),
m_leftOverTicks(0),
m_frameCount(0),
m_framesPerSecond(0),
m_framesThisSecond(0),
m_qpcSecondCounter(0),
m_isFixedTimeStep(false),
m_targetElapsedTicks(TicksPerSecond / 60)
{
if (!QueryPerformanceFrequency(&m_qpcFrequency))
{
throw std::exception();
}
if (!QueryPerformanceCounter(&m_qpcLastTime))
{
throw std::exception();
}
// Initialize max delta to 1/10 of a second.
m_qpcMaxDelta = static_cast<uint64_t>(m_qpcFrequency.QuadPart / 10);
}
// Get elapsed time since the previous Update call.
uint64_t GetElapsedTicks() const noexcept { return m_elapsedTicks; }
double GetElapsedSeconds() const noexcept { return TicksToSeconds(m_elapsedTicks); }
// Get total time since the start of the program.
uint64_t GetTotalTicks() const noexcept { return m_totalTicks; }
double GetTotalSeconds() const noexcept { return TicksToSeconds(m_totalTicks); }
// Get total number of updates since start of the program.
uint32_t GetFrameCount() const noexcept { return m_frameCount; }
// Get the current framerate.
uint32_t GetFramesPerSecond() const noexcept { return m_framesPerSecond; }
// Set whether to use fixed or variable timestep mode.
void SetFixedTimeStep(bool isFixedTimestep) noexcept { m_isFixedTimeStep = isFixedTimestep; }
// Set how often to call Update when in fixed timestep mode.
void SetTargetElapsedTicks(uint64_t targetElapsed) noexcept { m_targetElapsedTicks = targetElapsed; }
void SetTargetElapsedSeconds(double targetElapsed) noexcept { m_targetElapsedTicks = SecondsToTicks(targetElapsed); }
// Integer format represents time using 10,000,000 ticks per second.
static constexpr uint64_t TicksPerSecond = 10000000;
static constexpr double TicksToSeconds(uint64_t ticks) noexcept { return static_cast<double>(ticks) / TicksPerSecond; }
static constexpr uint64_t SecondsToTicks(double seconds) noexcept { return static_cast<uint64_t>(seconds * TicksPerSecond); }
// After an intentional timing discontinuity (for instance a blocking IO operation)
// call this to avoid having the fixed timestep logic attempt a set of catch-up
// Update calls.
void ResetElapsedTime()
{
if (!QueryPerformanceCounter(&m_qpcLastTime))
{
throw std::exception();
}
m_leftOverTicks = 0;
m_framesPerSecond = 0;
m_framesThisSecond = 0;
m_qpcSecondCounter = 0;
}
// Update timer state, calling the specified Update function the appropriate number of times.
template<typename TUpdate>
void Tick(const TUpdate& update)
{
// Query the current time.
LARGE_INTEGER currentTime;
if (!QueryPerformanceCounter(&currentTime))
{
throw std::exception();
}
uint64_t timeDelta = static_cast<uint64_t>(currentTime.QuadPart - m_qpcLastTime.QuadPart);
m_qpcLastTime = currentTime;
m_qpcSecondCounter += timeDelta;
// Clamp excessively large time deltas (e.g. after paused in the debugger).
if (timeDelta > m_qpcMaxDelta)
{
timeDelta = m_qpcMaxDelta;
}
// Convert QPC units into a canonical tick format. This cannot overflow due to the previous clamp.
timeDelta *= TicksPerSecond;
timeDelta /= static_cast<uint64_t>(m_qpcFrequency.QuadPart);
const uint32_t lastFrameCount = m_frameCount;
if (m_isFixedTimeStep)
{
// Fixed timestep update logic
// If the app is running very close to the target elapsed time (within 1/4 of a millisecond) just clamp
// the clock to exactly match the target value. This prevents tiny and irrelevant errors
// from accumulating over time. Without this clamping, a game that requested a 60 fps
// fixed update, running with vsync enabled on a 59.94 NTSC display, would eventually
// accumulate enough tiny errors that it would drop a frame. It is better to just round
// small deviations down to zero to leave things running smoothly.
if (static_cast<uint64_t>(std::abs(static_cast<int64_t>(timeDelta - m_targetElapsedTicks))) < TicksPerSecond / 4000)
{
timeDelta = m_targetElapsedTicks;
}
m_leftOverTicks += timeDelta;
while (m_leftOverTicks >= m_targetElapsedTicks)
{
m_elapsedTicks = m_targetElapsedTicks;
m_totalTicks += m_targetElapsedTicks;
m_leftOverTicks -= m_targetElapsedTicks;
m_frameCount++;
update();
}
}
else
{
// Variable timestep update logic.
m_elapsedTicks = timeDelta;
m_totalTicks += timeDelta;
m_leftOverTicks = 0;
m_frameCount++;
update();
}
// Track the current framerate.
if (m_frameCount != lastFrameCount)
{
m_framesThisSecond++;
}
if (m_qpcSecondCounter >= static_cast<uint64_t>(m_qpcFrequency.QuadPart))
{
m_framesPerSecond = m_framesThisSecond;
m_framesThisSecond = 0;
m_qpcSecondCounter %= static_cast<uint64_t>(m_qpcFrequency.QuadPart);
}
}
private:
// Source timing data uses QPC units.
LARGE_INTEGER m_qpcFrequency;
LARGE_INTEGER m_qpcLastTime;
uint64_t m_qpcMaxDelta;
// Derived timing data uses a canonical tick format.
uint64_t m_elapsedTicks;
uint64_t m_totalTicks;
uint64_t m_leftOverTicks;
// Members for tracking the framerate.
uint32_t m_frameCount;
uint32_t m_framesPerSecond;
uint32_t m_framesThisSecond;
uint64_t m_qpcSecondCounter;
// Members for configuring fixed timestep mode.
bool m_isFixedTimeStep;
uint64_t m_targetElapsedTicks;
};
}
#endif

View File

@ -10,4 +10,4 @@ if (CMAKE_VERSION VERSION_GREATER 3.12)
endif()
# TODO: Add tests and install targets if needed.
target_link_libraries(BlankApp Xn65)
target_link_libraries(BlankApp Xn65DX)

View File

@ -1,8 +1,7 @@
// xna.cpp : Defines the entry point for the application.
//
#include "xna/xna.hpp"
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
using namespace std;
using namespace xna;

View File

@ -11,5 +11,5 @@ endif()
# TODO: Add tests and install targets if needed.
target_link_libraries(
PlatformApp Xn65
PlatformApp Xn65DX
)

View File

@ -1,7 +1,7 @@
#ifndef PLATFORMSTARTERKIT_EXTENSIONS_HPP
#define PLATFORMSTARTERKIT_EXTENSIONS_HPP
#include "xna/xna.hpp"
#include "headers.hpp"
namespace PlatformerStarterKit {
struct RectangleExtensions {

View File

@ -1 +1 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"

View File

@ -4,4 +4,4 @@
# Add source to this project's executable.
add_subdirectory ("01_blank")
add_subdirectory ("02_PlatfformerStarterKit")
#add_subdirectory ("02_PlatfformerStarterKit")

2
sources/CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
add_subdirectory ("framework")
add_subdirectory ("framework-dx")

View File

@ -0,0 +1,37 @@
# CMakeList.txt : CMake project for xna, include source and define
# project specific logic here.
#
# Add source to this project's executable.
add_library (Xn65DX STATIC
"window.cpp"
"device.cpp"
"adapter.cpp"
"swapchain.cpp"
"rendertarget.cpp"
"texture.cpp"
"blendstate.cpp"
"game.cpp"
"gdevicemanager.cpp"
"rasterizerstate.cpp"
"samplerstate.cpp"
"sprite.cpp"
"depthstencilstate.cpp"
"keyboard.cpp"
"mouse.cpp"
"gamepad.cpp"
"soundeffect.cpp"
"init.cpp"
"audioengine.cpp"
"effect.cpp"
"screen.cpp")
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET Xn65DX PROPERTY CXX_STANDARD 20)
endif()
find_package(directxtk CONFIG REQUIRED)
target_link_libraries(
Xn65DX Xn65 D3d11.lib dxgi.lib dxguid.lib d3dcompiler.lib Microsoft::DirectXTK dxguid.lib
)

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
static void setOutputVars(comptr<IDXGIAdapter1> const& adapter, String& deviceName, intptr_t& monitorHandle);

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
void AudioEngine::Initialize() {

View File

@ -1,6 +1,6 @@
#include "xna/graphics/blendstate.hpp"
#include "xna/graphics/gresource.hpp"
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
BlendState::BlendState() : BlendState(nullptr) {}

View File

@ -1,5 +1,5 @@
#include "xna/graphics/depthstencilstate.hpp"
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
static D3D11_DEPTH_STENCIL_DESC defaultDesc() {

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
static void reset(GraphicsDevice::PlatformImplementation& impl);

View File

@ -1,5 +1,5 @@
#include "xna/graphics/effect.hpp"
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
#include "xna/common/math.hpp"
using DxBasicEffect = DirectX::BasicEffect;

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
Game::Game() {

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
#include "xna/input/gamepad.hpp"
namespace xna {

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
static bool IsWindowOnAdapter(intptr_t windowHandle, GraphicsAdapter const& adapter);

View File

@ -3,7 +3,7 @@
#include "xna/content/readers/audio.hpp"
#include "xna/content/typereadermanager.hpp"
#include "xna/content/readers/default.hpp"
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
void Platform::Init() {

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
KeyboardState Keyboard::GetState() {

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
MouseState Mouse::GetState() {

View File

@ -1,5 +1,5 @@
#include "xna/graphics/rasterizerstate.hpp"
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
RenderTarget2D::RenderTarget2D() : Texture2D(nullptr) {

View File

@ -1,6 +1,6 @@
#include "xna/graphics/samplerstate.hpp"
#include "xna/graphics/samplerstate.hpp"
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
SamplerState::SamplerState() : SamplerState(nullptr){}

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
#include "xna/csharp/stream.hpp"
using DxSoundEffect = DirectX::SoundEffect;

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
#include <functional>
using DxSpriteBatch = DirectX::SpriteBatch;

View File

@ -1,6 +1,6 @@
#include "xna/graphics/adapter.hpp"
#include "xna/graphics/swapchain.hpp"
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
#include "xna/graphics/device.hpp"
namespace xna {

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
static void setDefaultTexture2DDesc(Texture2D::PlatformImplementation& impl);

View File

@ -1,4 +1,4 @@
#include "xna/xna-dx.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
GameWindow::GameWindow() {

View File

@ -0,0 +1,27 @@
# CMakeList.txt : CMake project for xna, include source and define
# project specific logic here.
#
# Add source to this project's executable.
add_library (Xn65 STATIC
"csharp/stream.cpp"
"csharp/binary.cpp"
"csharp/type.cpp"
"game/component.cpp"
"game/servicecontainer.cpp"
"content/manager.cpp"
"content/reader.cpp"
"content/lzx/decoder.cpp"
"content/typereadermanager.cpp"
"common/color.cpp"
"common/collision.cpp"
"common/gjk.cpp"
"common/numerics.cpp"
"common/packedvalue.cpp"
"graphics/gresource.cpp"
"graphics/displaymode"
"exception.cpp")
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET Xn65 PROPERTY CXX_STANDARD 20)
endif()

Some files were not shown because too many files have changed in this diff Show More