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

Remove helpers.hpp e efetua correções

This commit is contained in:
Danilo Borges Santos 2024-12-02 14:42:09 -03:00
parent 1ec3a7ec60
commit e7e0781da5
13 changed files with 43 additions and 103 deletions

View File

@ -39,10 +39,10 @@ namespace xna {
template <typename T>
auto Load(String const& assetName) {
if (assetName.empty()) {
return XnaHelper::ReturnDefaultOrNull<T>();
return misc::ReturnDefaultOrNull<T>();
}
if constexpr (XnaHelper::is_shared_ptr<T>::value) {
if constexpr (misc::is_shared_ptr<T>::value) {
if (loadedAssets.contains(assetName)) {
auto& voidAsset = loadedAssets[assetName];
@ -54,7 +54,7 @@ namespace xna {
const auto obj2 = ReadAsset<T>(assetName);
if constexpr (XnaHelper::is_shared_ptr<T>::value) {
if constexpr (misc::is_shared_ptr<T>::value) {
if(obj2)
loadedAssets.emplace( assetName, obj2 );
@ -79,7 +79,7 @@ namespace xna {
auto input = OpenStream(assetName);
if (!input)
return XnaHelper::ReturnDefaultOrNull<T>();
return misc::ReturnDefaultOrNull<T>();
const auto _this = shared_from_this();
auto contentReader = ContentReader::Create(_this, input, assetName);

View File

@ -104,7 +104,7 @@ namespace xna {
const auto num = Read7BitEncodedInt();
if (num == 0) {
XnaHelper::ReturnDefaultOrNull<T>();
misc::ReturnDefaultOrNull<T>();
}
const auto index = num - 1;
@ -133,7 +133,7 @@ namespace xna {
Exception::Throw(Exception::NOT_IMPLEMENTED);
}
return XnaHelper::ReturnDefaultOrNull<T>();
return misc::ReturnDefaultOrNull<T>();
}
template<typename T>

View File

@ -56,7 +56,7 @@ namespace xna {
if (existingInstance.has_value() && !(existingInstance.type() == typeid(T)))
throw std::runtime_error("ContentTypeReader<T>::Read: bad xbn, wrong type.");
auto existingInstance1 = XnaHelper::ReturnDefaultOrNull<T>();
auto existingInstance1 = misc::ReturnDefaultOrNull<T>();
auto obj = Read(input, existingInstance1);
return obj;
}

View File

@ -1,7 +1,7 @@
#ifndef XNA_CSHARP_TYPE_HPP
#define XNA_CSHARP_TYPE_HPP
#include "../helpers.hpp"
#include "misc.hpp"
#include "../exception.hpp"
#include <map>
#include <memory>
@ -21,11 +21,11 @@ namespace xna {
constexpr size_t GetHashCode() const {
size_t seed = 0;
XnaHelper::HashCombine(seed, fullName);
XnaHelper::HashCombine(seed, isClass);
XnaHelper::HashCombine(seed, isEnum);
XnaHelper::HashCombine(seed, isValueType);
XnaHelper::HashCombine(seed, isPrimitive);
misc::HashCombine(seed, fullName);
misc::HashCombine(seed, isClass);
misc::HashCombine(seed, isEnum);
misc::HashCombine(seed, isValueType);
misc::HashCombine(seed, isPrimitive);
return seed;
}

View File

@ -16,7 +16,7 @@
#include "enumerations.hpp"
#include "exception.hpp"
#include "helpers.hpp"
#include "misc.hpp"
namespace xna {

View File

@ -123,14 +123,7 @@ namespace xna {
DiscardContents,
PreserveContents,
PlatformContents
};
enum class SpriteEffects {
None = 0,
FlipHorizontally = 1,
FlipVertically = 2,
Both = FlipHorizontally | FlipVertically
};
};
constexpr int SURFACE_FORMAT_COUNT = 19;
}

View File

@ -49,7 +49,6 @@
#include "graphics/texture.hpp"
#include "graphics/vertexposition.hpp"
#include "graphics/viewport.hpp"
#include "helpers.hpp"
#include "input/gamepad.hpp"
#include "input/keyboard.hpp"
#include "input/mouse.hpp"

View File

@ -7,6 +7,7 @@
#include <memory>
#include <optional>
#include <string>
#include <cstdint>
namespace xna {
//Defines sprite sort-rendering options.
@ -31,6 +32,21 @@ namespace xna {
FrontToBack,
};
enum class SpriteEffects {
None = 0,
FlipHorizontally = 1,
FlipVertically = 2,
Both = FlipHorizontally | FlipVertically
};
class BlendState;
class SamplerState;
class DepthStencilState;
class RasterizerState;
class Effect;
class Texture2D;
class SpriteFont;
struct SpriteBatchImplementation;
//Enables a group of sprites to be drawn using the same settings.
@ -159,11 +175,11 @@ namespace xna {
std::shared_ptr<Texture2D> const& texture,
std::vector<Rectangle> const& glyphs,
std::vector<Rectangle> const& cropping,
std::vector<Char> const& charMap,
std::vector<char16_t> const& charMap,
int32_t lineSpacing,
float spacing,
std::vector<Vector3> const& kerning,
std::optional<Char> const& defaultCharacter);
std::optional<char16_t> const& defaultCharacter);
// Returns the width and height of a string.
Vector2 MeasureString(std::string const& text, bool ignoreWhiteSpace = true);
@ -171,9 +187,9 @@ namespace xna {
Vector2 MeasureString(std::wstring const& text, bool ignoreWhiteSpace = true);
//Gets or sets the default character for the font.
Char DefaultCharacter() const;
char16_t DefaultCharacter() const;
//Gets or sets the default character for the font.
void DefaultCharacter(Char value);
void DefaultCharacter(char16_t value);
//Gets or sets the vertical distance (in pixels) between the base lines of two consecutive lines of text
int32_t LineSpacing() const;
//Gets or sets the vertical distance (in pixels) between the base lines of two consecutive lines of text

View File

@ -51,11 +51,11 @@ namespace xna {
void SetData(int32_t level, Rectangle* rect, std::vector<uint8_t> const& data, size_t startIndex, size_t elementCount);
//Loads texture data from a stream.
static P_Texture2D FromStream(GraphicsDevice& device, std::shared_ptr<Stream> const& stream);
static std::shared_ptr<Texture2D> FromStream(GraphicsDevice& device, std::shared_ptr<Stream> const& stream);
//Loads texture data from a file.
static P_Texture2D FromStream(GraphicsDevice& device, std::string const& fileName);
static std::shared_ptr<Texture2D> FromStream(GraphicsDevice& device, std::string const& fileName);
//Loads texture data from a data.
static P_Texture2D FromStream(GraphicsDevice& device, std::vector<uint8_t> const& data);
static std::shared_ptr<Texture2D> FromStream(GraphicsDevice& device, std::vector<uint8_t> const& data);
void Initialize();

View File

@ -1,68 +0,0 @@
#ifndef XNA_HELPERS_HPP
#define XNA_HELPERS_HPP
#include "default.hpp"
namespace xna {
//Class for helper functions
struct XnaHelper {
//
// Smart Pointer Comparator
//
template<typename T> struct is_shared_ptr : std::false_type {};
template<typename T> struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
template<typename T> struct is_weak_ptr : std::false_type {};
template<typename T> struct is_weak_ptr<std::weak_ptr<T>> : std::true_type {};
template<typename T> struct is_unique_ptr : std::false_type {};
template<typename T> struct is_unique_ptr<std::unique_ptr<T>> : std::true_type {};
//Returns true if the type is a smart pointer
template <typename T>
static constexpr bool IsSmartPoint() {
return is_shared_ptr<T>::value || is_unique_ptr<T>::value || is_weak_ptr<T>::value;
}
//Convert a string to wstring
static inline std::wstring ToWString(const std::string& str)
{
std::wstring wstr;
size_t size;
wstr.resize(str.length());
mbstowcs_s(&size, &wstr[0], wstr.size() + 1, str.c_str(), str.size());
return wstr;
}
//Convert a wstring to string
static inline std::string ToString(const std::wstring& wstr)
{
std::string str;
size_t size;
str.resize(wstr.length());
wcstombs_s(&size, &str[0], str.size() + 1, wstr.c_str(), wstr.size());
return str;
}
//Returns a hash reporting input values
template <class T>
static constexpr void HashCombine(std::size_t& seed, const T& v) {
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
//Returns null if the type is a smart pointer or default value if the type has a default constructor.
//Throws an exception if the object cannot be created
template<typename T>
static inline auto ReturnDefaultOrNull(const std::source_location location = std::source_location::current()) {
if constexpr (IsSmartPoint<T>())
return (T)nullptr;
else if constexpr (std::is_default_constructible<T>::value)
return T();
else
Exception::Throw(Exception::UNABLE_TO_BUILD_OBJECT, location);
}
};
}
#endif

View File

@ -28,7 +28,7 @@ namespace xna {
DXGI_ADAPTER_DESC1 desc{};
pAdapter->GetDesc1(&desc);
adp->description = XnaHelper::ToString(desc.Description);
adp->description = misc::ToString(desc.Description);
adp->deviceId = static_cast<Uint>(desc.DeviceId);
adp->isDefault = true;
adp->revision = static_cast<Uint>(desc.Revision);
@ -68,7 +68,7 @@ namespace xna {
DXGI_ADAPTER_DESC1 desc{};
pAdapter->GetDesc1(&desc);
adp->description = XnaHelper::ToString(desc.Description);
adp->description = misc::ToString(desc.Description);
adp->deviceId = static_cast<Uint>(desc.DeviceId);
adp->isDefault = count == 0;
adp->revision = static_cast<Uint>(desc.Revision);
@ -253,7 +253,7 @@ namespace xna {
DXGI_OUTPUT_DESC outputDesc;
pOutput->GetDesc(&outputDesc);
deviceName = XnaHelper::ToString(outputDesc.DeviceName);
deviceName = misc::ToString(outputDesc.DeviceName);
monitorHandle = reinterpret_cast<intptr_t>(outputDesc.Monitor);
}
}

View File

@ -16,7 +16,7 @@ namespace xna {
if (!AudioEngine::impl || !AudioEngine::impl->_dxAudioEngine)
return;
const auto file = XnaHelper::ToWString(fileName);
const auto file = misc::ToWString(fileName);
impl->_dxSoundEffect = unew<DxSoundEffect>(AudioEngine::impl->_dxAudioEngine.get(), file.c_str());
}

View File

@ -231,7 +231,7 @@ namespace xna {
auto _this = device.shared_from_this();
auto texture2d = snew<Texture2D>(_this);
comptr<ID3D11Resource> resource = nullptr;
auto wstr = XnaHelper::ToWString(fileName);
auto wstr = misc::ToWString(fileName);
HRESULT result = DirectX::CreateWICTextureFromFile(
device.Implementation->Device.Get(),