mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em String e Texture
This commit is contained in:
parent
fcb6ed41bd
commit
4be6f4abcc
@ -11,7 +11,7 @@ namespace xna {
|
||||
std::vector<PContentTypeReader> newTypeReaders;
|
||||
|
||||
for (size_t index = 0; index < typeCount; ++index)
|
||||
{
|
||||
{
|
||||
const auto readerTypeName = contentReader->ReadString();
|
||||
const auto xnaType = readerTypeName.substr(0, readerTypeName.find(","));
|
||||
|
||||
@ -24,15 +24,15 @@ namespace xna {
|
||||
return std::vector<PContentTypeReader>();
|
||||
}
|
||||
|
||||
contentTypeReaderArray[index] = typeReader;
|
||||
contentTypeReaderArray[index] = typeReader;
|
||||
}
|
||||
|
||||
if (!newTypeReaders.empty()) {
|
||||
auto manager = std::shared_ptr<ContentTypeReaderManager>(new ContentTypeReaderManager(contentReader));
|
||||
if (!newTypeReaders.empty()) {
|
||||
auto manager = std::shared_ptr<ContentTypeReaderManager>(new ContentTypeReaderManager(contentReader));
|
||||
|
||||
for (size_t i = 0; i < newTypeReaders.size(); ++i) {
|
||||
auto& contentTypeReader = newTypeReaders[i];
|
||||
contentTypeReader->Initialize(manager);
|
||||
}
|
||||
for (size_t i = 0; i < newTypeReaders.size(); ++i) {
|
||||
auto& contentTypeReader = newTypeReaders[i];
|
||||
contentTypeReader->Initialize(manager);
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,14 +44,7 @@ namespace xna {
|
||||
if (!targetType) {
|
||||
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//sptr<ContentTypeReader> typeReader = nullptr;
|
||||
|
||||
/*if (!ContentTypeReaderManager::targetTypeToReader.contains(targetType)) {
|
||||
xna_error_apply(err, XnaErrorCode::ARGUMENT_OUT_OF_RANGE);
|
||||
return nullptr;
|
||||
} */
|
||||
}
|
||||
|
||||
for (auto const& item : ContentTypeReaderManager::targetTypeToReader) {
|
||||
auto firstHashCode = item.first->GetHashCode();
|
||||
@ -123,7 +116,6 @@ namespace xna {
|
||||
}
|
||||
|
||||
ContentTypeReaderManager::targetTypeToReader.insert({ targetType, reader });
|
||||
//ContentTypeReaderManager::readerTypeToReader.insert({ reader->GetType(), reader });
|
||||
ContentTypeReaderManager::readerTypeToReader.insert({ typeof(*reader), reader});
|
||||
ContentTypeReaderManager::nameToReader.insert({ readerTypeName, reader });
|
||||
}
|
||||
@ -146,9 +138,7 @@ namespace xna {
|
||||
if (targetTypeToReader.empty() && readerTypeToReader.empty()) {
|
||||
auto typeReader = New<ObjectReader>();
|
||||
auto contentTypeReader = reinterpret_pointer_cast<ContentTypeReader>(typeReader);
|
||||
|
||||
//targetTypeToReader.insert({ typeReader->TargetType(), contentTypeReader});
|
||||
//readerTypeToReader.insert({ typeReader->GetType(), contentTypeReader});
|
||||
|
||||
targetTypeToReader.insert({ typeof<Object>(), contentTypeReader});
|
||||
readerTypeToReader.insert({ typeof<ObjectReader>(), contentTypeReader});
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace xna {
|
||||
sptr<Texture2D> const& texture,
|
||||
std::vector<Rectangle> const& glyphs,
|
||||
std::vector<Rectangle> const& cropping,
|
||||
std::vector<char> const& charMap,
|
||||
std::vector<Char> const& charMap,
|
||||
Int lineSpacing,
|
||||
float spacing,
|
||||
std::vector<Vector3> const& kerning,
|
||||
@ -37,7 +37,7 @@ namespace xna {
|
||||
if (!texture)
|
||||
throw std::invalid_argument("SpriteFont: texture is null.");
|
||||
|
||||
std::vector<DxGlyph> dxGlyps(glyphs.size());
|
||||
std::vector<DxGlyph> dxGlyps(glyphs.size());
|
||||
|
||||
for (size_t i = 0; i < dxGlyps.size(); ++i) {
|
||||
DxGlyph g;
|
||||
@ -45,8 +45,13 @@ namespace xna {
|
||||
g.Subrect.right = glyphs[i].Right();
|
||||
g.Subrect.bottom = glyphs[i].Bottom();
|
||||
g.Subrect.top = glyphs[i].Top();
|
||||
}
|
||||
|
||||
g.Character = static_cast<Uint>(charMap[i]);
|
||||
g.XOffset = kerning[i].X;
|
||||
g.YOffset = kerning[i].Y;
|
||||
g.XAdvance = kerning[i].Z;
|
||||
dxGlyps[i] = g;
|
||||
}
|
||||
|
||||
impl = uNew<PlatformImplementation>();
|
||||
impl->_dxSpriteFont = unew<DxSpriteFont>(
|
||||
//ID3D11ShaderResourceView* texture
|
||||
@ -63,6 +68,9 @@ namespace xna {
|
||||
const auto defChar = static_cast<wchar_t>(defaultCharacter.value());
|
||||
impl->_dxSpriteFont->SetDefaultCharacter(defChar);
|
||||
}
|
||||
else {
|
||||
impl->_dxSpriteFont->SetDefaultCharacter(charMap[0]);
|
||||
}
|
||||
}
|
||||
|
||||
SpriteFont::~SpriteFont() {
|
||||
|
@ -271,6 +271,7 @@ namespace xna {
|
||||
impl->dxShaderResource = nullptr;
|
||||
}
|
||||
|
||||
impl->dxShaderDescription.Format = impl->dxDescription.Format;
|
||||
impl->dxShaderDescription.Texture2D.MipLevels = impl->dxDescription.MipLevels;
|
||||
hr = m_device->impl->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource);
|
||||
|
||||
|
@ -89,7 +89,7 @@ namespace xna {
|
||||
auto reader = typeReaders[index];
|
||||
|
||||
//Verificação necessária pois a depender da situação é encontrado um reader errado
|
||||
auto typeT = typeof<T>();
|
||||
/*auto typeT = typeof<T>();
|
||||
auto typeThash = typeT->GetHashCode();
|
||||
auto readerType = reader->TargetType();
|
||||
|
||||
@ -103,7 +103,7 @@ namespace xna {
|
||||
|
||||
if(reader->TargetType()->GetHashCode() != typeThash)
|
||||
throw std::runtime_error("ContentReader::ReadObjectInternal: wrong reader!");
|
||||
}
|
||||
} */
|
||||
|
||||
return InvokeReader<T>(*reader, existingInstance, err);
|
||||
}
|
||||
|
@ -10,7 +10,9 @@
|
||||
namespace xna {
|
||||
class SoundEffectReader : public ContentTypeReaderT<PSoundEffect> {
|
||||
public:
|
||||
SoundEffectReader() : ContentTypeReaderT(typeof<PSoundEffect>()) {}
|
||||
SoundEffectReader() : ContentTypeReaderT(typeof<PSoundEffect>()) {
|
||||
ContentTypeReader::TargetIsValueType = false;
|
||||
}
|
||||
|
||||
PSoundEffect Read(ContentReader& input, PSoundEffect& existingInstance) override {
|
||||
const auto count1 = input.ReadInt32();
|
||||
|
@ -235,7 +235,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
void Initialize(sptr<ContentTypeReaderManager> const& manager) override {
|
||||
elementReader = manager->GetTypeReader(typeof<std::vector<T>>());
|
||||
elementReader = manager->GetTypeReader(typeof<T>());
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -12,7 +12,9 @@
|
||||
namespace xna {
|
||||
class Texture2DReader : public ContentTypeReaderT<PTexture2D> {
|
||||
public:
|
||||
Texture2DReader() : ContentTypeReaderT(typeof<PTexture2D>()) {}
|
||||
Texture2DReader() : ContentTypeReaderT(typeof<PTexture2D>()) {
|
||||
ContentTypeReader::TargetIsValueType = false;
|
||||
}
|
||||
|
||||
PTexture2D Read(ContentReader& input, PTexture2D& existingInstance) override {
|
||||
const auto format = static_cast<SurfaceFormat>(input.ReadInt32());
|
||||
@ -41,13 +43,15 @@ namespace xna {
|
||||
|
||||
class SpriteFontReader : public ContentTypeReaderT<PSpriteFont> {
|
||||
public:
|
||||
SpriteFontReader() : ContentTypeReaderT(typeof<PSpriteFont>()) {}
|
||||
SpriteFontReader() : ContentTypeReaderT(typeof<PSpriteFont>()) {
|
||||
ContentTypeReader::TargetIsValueType = false;
|
||||
}
|
||||
|
||||
PSpriteFont Read(ContentReader& input, PSpriteFont& existingInstance) override {
|
||||
auto texture = input.ReadObject<PTexture2D>();
|
||||
auto glyphs = input.ReadObject<std::vector<Rectangle>>();
|
||||
auto cropping = input.ReadObject<std::vector<Rectangle>>();
|
||||
auto charMap = input.ReadObject<std::vector<char>>();
|
||||
auto charMap = input.ReadObject<std::vector<Char>>();
|
||||
auto lineSpacing = input.ReadInt32();
|
||||
auto spacing = input.ReadSingle();
|
||||
auto kerning = input.ReadObject<std::vector<Vector3>>();
|
||||
|
@ -22,10 +22,14 @@ namespace xna {
|
||||
|
||||
protected:
|
||||
ContentTypeReader(sptr<Type> const& targetType) : _targetType(targetType)
|
||||
{}
|
||||
{
|
||||
//TargetIsValueType = targetType->IsValueType();
|
||||
}
|
||||
|
||||
public:
|
||||
bool TargetIsValueType{ false };
|
||||
//Vamos admitir que primariamente o alvo é tipo valor
|
||||
//caso não seja deve ser setado manualmente para falso
|
||||
bool TargetIsValueType{ true };
|
||||
|
||||
private:
|
||||
sptr<Type> _targetType = nullptr;
|
||||
|
@ -15,6 +15,7 @@ namespace xna {
|
||||
constexpr bool IsEnum() const { return isEnum; }
|
||||
constexpr bool IsValueType() const { return isValueType; }
|
||||
constexpr bool IsPrimitive() const { return isPrimitive; }
|
||||
constexpr bool IsPointer() const { return isPointer; }
|
||||
|
||||
virtual size_t GetHashCode() const;
|
||||
|
||||
@ -24,6 +25,7 @@ namespace xna {
|
||||
&& isClass == other.isClass
|
||||
&& isEnum == other.isEnum
|
||||
&& isValueType == other.isValueType
|
||||
&& isPointer == other.isPointer
|
||||
&& isPrimitive == other.isPrimitive;
|
||||
}
|
||||
|
||||
@ -43,6 +45,7 @@ namespace xna {
|
||||
bool isEnum{ false };
|
||||
bool isValueType{ false };
|
||||
bool isPrimitive{ false };
|
||||
bool isPointer { false };
|
||||
};
|
||||
|
||||
template <class T>
|
||||
@ -63,6 +66,13 @@ namespace xna {
|
||||
return enumType;
|
||||
}
|
||||
|
||||
if (std::is_pointer<T>::value) {
|
||||
auto pointerType = New<Type>();
|
||||
pointerType->fullName = typeid(T).name();
|
||||
pointerType->isPointer = true;
|
||||
return pointerType;
|
||||
}
|
||||
|
||||
if (std::is_class<T>::value) {
|
||||
auto classType = New<Type>();
|
||||
classType->fullName = typeid(T).name();
|
||||
|
@ -87,7 +87,7 @@ namespace xna {
|
||||
sptr<Texture2D> const& texture,
|
||||
std::vector<Rectangle> const& glyphs,
|
||||
std::vector<Rectangle> const& cropping,
|
||||
std::vector<char> const& charMap,
|
||||
std::vector<Char> const& charMap,
|
||||
Int lineSpacing,
|
||||
float spacing,
|
||||
std::vector<Vector3> const& kerning,
|
||||
@ -100,7 +100,7 @@ namespace xna {
|
||||
sptr<Texture2D> textureValue = nullptr;
|
||||
std::vector<Rectangle> glyphData;
|
||||
std::vector<Rectangle> croppingData;
|
||||
std::vector<char> characterMap;
|
||||
std::vector<Char> characterMap;
|
||||
Int lineSpacing{0};
|
||||
float spacing{0};
|
||||
std::vector<Vector3> kerning;
|
||||
|
@ -59,8 +59,8 @@ namespace PlatformerStarterKit {
|
||||
spriteBatch->Begin();
|
||||
|
||||
level->Draw(gameTime, *spriteBatch);
|
||||
|
||||
//DrawHud();
|
||||
|
||||
DrawHud();
|
||||
|
||||
spriteBatch->End();
|
||||
|
||||
@ -126,8 +126,7 @@ namespace PlatformerStarterKit {
|
||||
auto center = Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f,
|
||||
titleSafeArea.Y + titleSafeArea.Height / 2.0f);
|
||||
|
||||
//string timeString = "TIME: " + to_string(level->TimeRemaining().Minutes()) + ":" + to_string(level->TimeRemaining().Seconds());
|
||||
string timeString = "TIME";
|
||||
string timeString = "TIME: " + to_string(level->TimeRemaining().Minutes()) + ":" + to_string(level->TimeRemaining().Seconds());
|
||||
Color timeColor;
|
||||
if (level->TimeRemaining() > WarningTime ||
|
||||
level->ReachedExit() ||
|
||||
|
Loading…
x
Reference in New Issue
Block a user