Fixed all errors.
This commit is contained in:
@@ -7,14 +7,11 @@ namespace ehs
|
||||
FontAtlas::FontAtlas()
|
||||
: glyphScale(0)
|
||||
{
|
||||
AddType("FontAtlas");
|
||||
}
|
||||
|
||||
FontAtlas::FontAtlas(const Str_8& filePath)
|
||||
: glyphScale(0)
|
||||
{
|
||||
AddType("FontAtlas");
|
||||
|
||||
File fontFile(filePath, Mode::READ, Disposition::OPEN);
|
||||
|
||||
hashId = fontFile.GetName().Hash_64();
|
||||
@@ -44,7 +41,6 @@ namespace ehs
|
||||
height = fData.Read<UInt_64>();
|
||||
data = new Byte[width * height * (bitDepth / 8) * channels];
|
||||
fData.ReadArray(data, &size);
|
||||
aspect = IMG_ASPECT_COLOR;
|
||||
}
|
||||
|
||||
FontAtlas::FontAtlas(FontAtlas&& fa) noexcept
|
||||
@@ -229,11 +225,6 @@ namespace ehs
|
||||
pos.x += (float)glyph.GetAdvance().x;
|
||||
}
|
||||
|
||||
return {"Label", std::move(verts), std::move(indices)};
|
||||
}
|
||||
|
||||
FontAtlas* FontAtlas::Clone() const
|
||||
{
|
||||
return new FontAtlas(*this);
|
||||
return {id, std::move(verts), std::move(indices)};
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "io/Window_XCB.h"
|
||||
#include "UTF.h"
|
||||
#include "Vec2.h"
|
||||
#include "io/hid/Keyboard.h"
|
||||
#include "io/hid/Mouse.h"
|
||||
#include "io/Console.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <xcb/xfixes.h>
|
||||
#include <xcb/xcb_cursor.h>
|
||||
|
||||
@@ -51,64 +51,73 @@ namespace ehs
|
||||
}
|
||||
|
||||
Audio::Audio()
|
||||
: sampleRate(0), dataType(DataType::FLOAT), byteDepth(ToByteDepth(dataType)), channels(0), frames(0), length(0.0f),
|
||||
data(nullptr), peak(nullptr)
|
||||
: hashId(0), sampleRate(0), dataType(DataType::FLOAT), byteDepth(0), channels(0), frames(0),
|
||||
length(0.0f), data(nullptr), peak(nullptr)
|
||||
{
|
||||
AddType("Audio");
|
||||
}
|
||||
|
||||
Audio::Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const UInt_64 frames, const Byte* const data)
|
||||
: Resource(std::move(id)), dataType(dataType), byteDepth(ToByteDepth(dataType)), sampleRate(sampleRate),
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), dataType(dataType), byteDepth(ToByteDepth(dataType)), sampleRate(sampleRate),
|
||||
channels(channels), frames(frames), length((float)frames / (float)sampleRate),
|
||||
data(new Byte[GetSize()]), peak(new Byte[byteDepth])
|
||||
{
|
||||
AddType("Audio");
|
||||
|
||||
Util::Copy(this->data, data, GetSize());
|
||||
|
||||
AddType("Audio");
|
||||
}
|
||||
|
||||
Audio::Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Serializer<UInt_64>& data)
|
||||
: Resource(std::move(id)), sampleRate(sampleRate), dataType(dataType), byteDepth(ToByteDepth(dataType)),
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), sampleRate(sampleRate), dataType(dataType), byteDepth(ToByteDepth(dataType)),
|
||||
channels(channels), frames(data.Size() / channels / byteDepth), length((float)frames / (float)sampleRate),
|
||||
data(new Byte[data.Size()]), peak(new Byte[byteDepth])
|
||||
{
|
||||
AddType("Audio");
|
||||
|
||||
Util::Copy(this->data, data, data.Size());
|
||||
|
||||
AddType("Audio");
|
||||
}
|
||||
|
||||
Audio::Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Vector<Byte>& data)
|
||||
: Resource(std::move(id)), sampleRate(sampleRate), dataType(dataType), byteDepth(ToByteDepth(dataType)),
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), sampleRate(sampleRate), dataType(dataType), byteDepth(ToByteDepth(dataType)),
|
||||
channels(channels), frames(data.Size() / channels / byteDepth), length((float)frames / (float)sampleRate),
|
||||
data(new Byte[data.Size()]), peak(new Byte[byteDepth])
|
||||
{
|
||||
AddType("Audio");
|
||||
|
||||
Util::Copy(this->data, data, data.Size());
|
||||
|
||||
AddType("Audio");
|
||||
}
|
||||
|
||||
Audio::Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Array<Byte>& data)
|
||||
: Resource(std::move(id)), sampleRate(sampleRate), dataType(dataType), byteDepth(ToByteDepth(dataType)),
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), sampleRate(sampleRate), dataType(dataType), byteDepth(ToByteDepth(dataType)),
|
||||
channels(channels), frames(data.Size() / channels / byteDepth), length((float)frames / (float)sampleRate),
|
||||
data(new Byte[data.Size()]), peak(new Byte[byteDepth])
|
||||
{
|
||||
AddType("Audio");
|
||||
|
||||
Util::Copy(this->data, data, data.Size());
|
||||
|
||||
AddType("Audio");
|
||||
}
|
||||
|
||||
Audio::Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const UInt_64 frames)
|
||||
: Resource(std::move(id)), sampleRate(sampleRate), dataType(dataType), byteDepth(ToByteDepth(dataType)),
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), sampleRate(sampleRate), dataType(dataType), byteDepth(ToByteDepth(dataType)),
|
||||
channels(channels), frames(frames), length((float)frames / (float)sampleRate),
|
||||
data(new Byte[GetSize()]), peak(new Byte[byteDepth])
|
||||
{
|
||||
AddType("Audio");
|
||||
}
|
||||
|
||||
Audio::Audio(Str_8 id)
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), sampleRate(0), dataType(DataType::FLOAT), byteDepth(0), channels(0),
|
||||
frames(0), length(0.0f), data(nullptr), peak(nullptr)
|
||||
{
|
||||
AddType("Audio");
|
||||
}
|
||||
|
||||
Audio::Audio(Audio&& audio) noexcept
|
||||
: Resource(std::move(audio)), sampleRate(audio.sampleRate), dataType(audio.dataType), byteDepth(audio.byteDepth),
|
||||
channels(audio.channels), frames(audio.frames), length(audio.length), data(audio.data), peak(audio.peak)
|
||||
: BaseObj((BaseObj&&)audio), hashId(audio.hashId), id((Str_8&&)id), sampleRate(audio.sampleRate),
|
||||
dataType(audio.dataType), byteDepth(audio.byteDepth), channels(audio.channels), frames(audio.frames),
|
||||
length(audio.length), data(audio.data), peak(audio.peak)
|
||||
{
|
||||
audio.hashId = 0;
|
||||
audio.sampleRate = 0;
|
||||
audio.dataType = DataType::FLOAT;
|
||||
audio.byteDepth = ToByteDepth(audio.dataType);
|
||||
@@ -120,9 +129,9 @@ namespace ehs
|
||||
}
|
||||
|
||||
Audio::Audio(const Audio& audio)
|
||||
: Resource(audio), sampleRate(audio.sampleRate), dataType(audio.dataType), byteDepth(audio.byteDepth),
|
||||
channels(audio.channels), frames(audio.frames), length(audio.length), data(new Byte[GetSize()]),
|
||||
peak(new Byte[audio.byteDepth])
|
||||
: BaseObj(audio), hashId(audio.hashId), id(audio.id), sampleRate(audio.sampleRate), dataType(audio.dataType),
|
||||
byteDepth(audio.byteDepth), channels(audio.channels), frames(audio.frames), length(audio.length),
|
||||
data(new Byte[GetSize()]), peak(new Byte[audio.byteDepth])
|
||||
{
|
||||
Util::Copy(data, audio.data, GetSize());
|
||||
}
|
||||
@@ -132,15 +141,22 @@ namespace ehs
|
||||
if (this == &audio)
|
||||
return *this;
|
||||
|
||||
BaseObj::operator=((BaseObj&&)audio);
|
||||
|
||||
hashId = audio.hashId;
|
||||
id = (Str_8&&)audio.id;
|
||||
sampleRate = audio.sampleRate;
|
||||
dataType = audio.dataType;
|
||||
byteDepth = audio.byteDepth;
|
||||
channels = audio.channels;
|
||||
frames = audio.frames;
|
||||
length = audio.length;
|
||||
delete[] data;
|
||||
data = audio.data;
|
||||
delete[] peak;
|
||||
peak = audio.peak;
|
||||
|
||||
audio.hashId = 0;
|
||||
audio.sampleRate = 0;
|
||||
audio.dataType = DataType::FLOAT;
|
||||
audio.byteDepth = ToByteDepth(audio.dataType);
|
||||
@@ -150,8 +166,6 @@ namespace ehs
|
||||
audio.data = nullptr;
|
||||
audio.peak = nullptr;
|
||||
|
||||
Resource::operator=(std::move(audio));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -160,6 +174,10 @@ namespace ehs
|
||||
if (this == &audio)
|
||||
return *this;
|
||||
|
||||
BaseObj::operator=(audio);
|
||||
|
||||
hashId = audio.hashId;
|
||||
id = audio.id;
|
||||
sampleRate = audio.sampleRate;
|
||||
dataType = audio.dataType;
|
||||
byteDepth = audio.byteDepth;
|
||||
@@ -168,11 +186,12 @@ namespace ehs
|
||||
frames = audio.frames;
|
||||
|
||||
delete[] data;
|
||||
data = new Byte[audio.frames];
|
||||
data = new Byte[audio.GetSize()];
|
||||
Util::Copy(data, audio.data, audio.GetSize());
|
||||
|
||||
Util::Copy(data, audio.data, frames);
|
||||
|
||||
Resource::operator=(audio);
|
||||
delete[] peak;
|
||||
peak = new Byte[audio.byteDepth];
|
||||
Util::Copy(peak, audio.peak, audio.byteDepth);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -187,6 +206,36 @@ namespace ehs
|
||||
return data;
|
||||
}
|
||||
|
||||
void Audio::Release()
|
||||
{
|
||||
sampleRate = 0;
|
||||
dataType = DataType::FLOAT;
|
||||
byteDepth = 0;
|
||||
channels = 0;
|
||||
frames = 0;
|
||||
length = 0.0f;
|
||||
delete[] data;
|
||||
data = nullptr;
|
||||
delete[] peak;
|
||||
peak = nullptr;
|
||||
}
|
||||
|
||||
UInt_64 Audio::GetHashId() const
|
||||
{
|
||||
return hashId;
|
||||
}
|
||||
|
||||
void Audio::SetId(Str_8 newId)
|
||||
{
|
||||
hashId = newId.Hash_64();
|
||||
id = (Str_8&&)newId;
|
||||
}
|
||||
|
||||
Str_8 Audio::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
UInt_64 Audio::GetSampleRate() const
|
||||
{
|
||||
return sampleRate;
|
||||
@@ -657,7 +706,7 @@ namespace ehs
|
||||
if (!data || newChannels == channels)
|
||||
return;
|
||||
|
||||
Byte* result = nullptr;
|
||||
Byte* result;
|
||||
|
||||
if (newChannels == 1)
|
||||
{
|
||||
@@ -837,12 +886,12 @@ namespace ehs
|
||||
return false;
|
||||
}
|
||||
|
||||
Serializer<UInt_64> data;
|
||||
if (!codec->Encode(data, this))
|
||||
Serializer<UInt_64> result;
|
||||
if (!codec->Encode(result, this))
|
||||
return false;
|
||||
|
||||
File file(filePath, Mode::WRITE, Disposition::CREATE_PERSISTENT);
|
||||
file.WriteSerializer_64(data);
|
||||
file.WriteSerializer_64(result);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -852,7 +901,7 @@ namespace ehs
|
||||
File file(filePath, Mode::READ, Disposition::OPEN);
|
||||
Str_8 ext = file.GetExtension();
|
||||
|
||||
Audio result;
|
||||
Audio result(file.GetName());
|
||||
|
||||
const AudioCodec* codec = GetCodec(ext);
|
||||
if (!codec)
|
||||
@@ -861,8 +910,6 @@ namespace ehs
|
||||
return result;
|
||||
}
|
||||
|
||||
result.id = file.GetName();
|
||||
|
||||
Serializer<UInt_64> data = file.ReadSerializer_64(codec->GetEndianness(), file.Size());
|
||||
|
||||
file.Release();
|
||||
@@ -887,8 +934,7 @@ namespace ehs
|
||||
return result;
|
||||
}
|
||||
|
||||
result = new Audio();
|
||||
result->id = file.GetName();
|
||||
result = new Audio(file.GetName());
|
||||
|
||||
Serializer<UInt_64> data = file.ReadSerializer_64(codec->GetEndianness(), file.Size());
|
||||
|
||||
@@ -923,9 +969,9 @@ namespace ehs
|
||||
return result;
|
||||
}
|
||||
|
||||
Audio Audio::FromData(const Str_8& ext, const Str_8& id, Serializer<UInt_64>& data)
|
||||
Audio Audio::FromData(Str_8 id, const Str_8& ext, Serializer<UInt_64>& data)
|
||||
{
|
||||
Audio result;
|
||||
Audio result((Str_8&&)id);
|
||||
|
||||
const AudioCodec* codec = GetCodec(ext);
|
||||
if (!codec)
|
||||
@@ -934,8 +980,6 @@ namespace ehs
|
||||
return result;
|
||||
}
|
||||
|
||||
result.id = id;
|
||||
|
||||
if (!codec->Decode(data, &result))
|
||||
return {};
|
||||
|
||||
|
||||
@@ -48,26 +48,36 @@ namespace ehs
|
||||
}
|
||||
|
||||
Img::Img()
|
||||
: data(nullptr), bitDepth(0), channels(0), width(0), height(0), size(0)
|
||||
: hashId(0), data(nullptr), bitDepth(0), channels(0), width(0), height(0), size(0)
|
||||
{
|
||||
AddType("Img");
|
||||
}
|
||||
|
||||
Img::Img(const UInt_8 bitDepth, const UInt_8 channels, const UInt_64 width, const UInt_64 height, const Byte* const data)
|
||||
: bitDepth(bitDepth), channels(channels), width(width), height(height),
|
||||
Img::Img(Str_8 id, const UInt_8 bitDepth, const UInt_8 channels, const UInt_64 width, const UInt_64 height, const Byte* const data)
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), bitDepth(bitDepth), channels(channels), width(width), height(height),
|
||||
size(width * (bitDepth / 8) * channels * height), data(new Byte[size])
|
||||
{
|
||||
Util::Copy(this->data, data, size);
|
||||
|
||||
AddType("Img");
|
||||
}
|
||||
|
||||
Img::Img(const UInt_8 bitDepth, const UInt_8 channels, const UInt_64 width, const UInt_64 height)
|
||||
: bitDepth(bitDepth), channels(channels), width(width), height(height),
|
||||
Img::Img(Str_8 id, const UInt_8 bitDepth, const UInt_8 channels, const UInt_64 width, const UInt_64 height)
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), bitDepth(bitDepth), channels(channels), width(width), height(height),
|
||||
size(width * (bitDepth / 8) * channels * height), data(new Byte[size])
|
||||
{
|
||||
AddType("Img");
|
||||
}
|
||||
|
||||
Img::Img(Str_8 id)
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), bitDepth(0), channels(0), width(0), height(0), size(0), data(nullptr)
|
||||
{
|
||||
AddType("Img");
|
||||
}
|
||||
|
||||
Img::Img(Img&& img) noexcept
|
||||
: bitDepth(img.bitDepth), channels(img.channels), width(img.width), height(img.height), size(img.size),
|
||||
data(img.data)
|
||||
: BaseObj((BaseObj&&)img), hashId(img.hashId), id((Str_8&&)img.id), bitDepth(img.bitDepth),
|
||||
channels(img.channels), width(img.width), height(img.height), size(img.size), data(img.data)
|
||||
{
|
||||
img.bitDepth = 0;
|
||||
img.channels = 0;
|
||||
@@ -78,8 +88,8 @@ namespace ehs
|
||||
}
|
||||
|
||||
Img::Img(const Img& img)
|
||||
: bitDepth(img.bitDepth), channels(img.channels), width(img.width), height(img.height), size(img.size),
|
||||
data(new Byte[img.size])
|
||||
: BaseObj(img), hashId(img.hashId), id(img.id), bitDepth(img.bitDepth), channels(img.channels), width(img.width),
|
||||
height(img.height), size(img.size), data(new Byte[img.size])
|
||||
{
|
||||
Util::Copy(data, img.data, img.size);
|
||||
}
|
||||
@@ -89,13 +99,14 @@ namespace ehs
|
||||
if (this == &img)
|
||||
return *this;
|
||||
|
||||
Release();
|
||||
BaseObj::operator=((BaseObj&&)img);
|
||||
|
||||
bitDepth = img.bitDepth;
|
||||
channels = img.channels;
|
||||
width = img.width;
|
||||
height = img.height;
|
||||
size = img.size;
|
||||
delete[] data;
|
||||
data = img.data;
|
||||
|
||||
img.bitDepth = 0;
|
||||
@@ -113,7 +124,7 @@ namespace ehs
|
||||
if (this == &img)
|
||||
return *this;
|
||||
|
||||
Release();
|
||||
BaseObj::operator=(img);
|
||||
|
||||
bitDepth = img.bitDepth;
|
||||
channels = img.channels;
|
||||
@@ -139,10 +150,31 @@ namespace ehs
|
||||
|
||||
void Img::Release()
|
||||
{
|
||||
bitDepth = 0;
|
||||
channels = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
size = 0;
|
||||
delete[] data;
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
UInt_64 Img::GetHashId() const
|
||||
{
|
||||
return hashId;
|
||||
}
|
||||
|
||||
void Img::SetId(Str_8 newId)
|
||||
{
|
||||
hashId = newId.Hash_64();
|
||||
id = (Str_8&&)newId;
|
||||
}
|
||||
|
||||
Str_8 Img::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
UInt_8 Img::BitDepth() const
|
||||
{
|
||||
return bitDepth;
|
||||
@@ -276,19 +308,19 @@ namespace ehs
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
Img result(bitDepth, 4, width, height);
|
||||
Img result(id, bitDepth, 4, width, height);
|
||||
RGB_To_RGBA(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
Img result(bitDepth, 4, width, height);
|
||||
Img result(id, bitDepth, 4, width, height);
|
||||
MonoA_To_RGBA(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
Img result(bitDepth, 4, width, height);
|
||||
Img result(id, bitDepth, 4, width, height);
|
||||
Mono_To_RGBA(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -346,7 +378,7 @@ namespace ehs
|
||||
{
|
||||
case 4:
|
||||
{
|
||||
Img result(bitDepth, 3, width, height);
|
||||
Img result(id, bitDepth, 3, width, height);
|
||||
RGBA_To_RGB(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -356,13 +388,13 @@ namespace ehs
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
Img result(bitDepth, 3, width, height);
|
||||
Img result(id, bitDepth, 3, width, height);
|
||||
MonoA_To_RGB(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
Img result(bitDepth, 3, width, height);
|
||||
Img result(id, bitDepth, 3, width, height);
|
||||
Mono_To_RGB(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -420,13 +452,13 @@ namespace ehs
|
||||
{
|
||||
case 4:
|
||||
{
|
||||
Img result(bitDepth, 2, width, height);
|
||||
Img result(id, bitDepth, 2, width, height);
|
||||
RGBA_To_MonoA(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
Img result(bitDepth, 2, width, height);
|
||||
Img result(id, bitDepth, 2, width, height);
|
||||
RGB_To_MonoA(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -436,7 +468,7 @@ namespace ehs
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
Img result(bitDepth, 2, width, height);
|
||||
Img result(id, bitDepth, 2, width, height);
|
||||
Mono_To_MonoA(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -494,19 +526,19 @@ namespace ehs
|
||||
{
|
||||
case 4:
|
||||
{
|
||||
Img result(bitDepth, 1, width, height);
|
||||
Img result(id, bitDepth, 1, width, height);
|
||||
RGBA_To_Mono(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
Img result(bitDepth, 1, width, height);
|
||||
Img result(id, bitDepth, 1, width, height);
|
||||
RGB_To_Mono(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
Img result(bitDepth, 1, width, height);
|
||||
Img result(id, bitDepth, 1, width, height);
|
||||
MonoA_To_Mono(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -572,19 +604,19 @@ namespace ehs
|
||||
}
|
||||
case 24:
|
||||
{
|
||||
Img result(32, channels, width, height);
|
||||
Img result(id, 32, channels, width, height);
|
||||
BD24_to_BD32(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 16:
|
||||
{
|
||||
Img result(32, channels, width, height);
|
||||
Img result(id, 32, channels, width, height);
|
||||
BD16_to_BD32(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
Img result(32, channels, width, height);
|
||||
Img result(id, 32, channels, width, height);
|
||||
BD8_to_BD32(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -642,7 +674,7 @@ namespace ehs
|
||||
{
|
||||
case 32:
|
||||
{
|
||||
Img result(24, channels, width, height);
|
||||
Img result(id, 24, channels, width, height);
|
||||
BD32_to_BD24(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -652,13 +684,13 @@ namespace ehs
|
||||
}
|
||||
case 16:
|
||||
{
|
||||
Img result(24, channels, width, height);
|
||||
Img result(id, 24, channels, width, height);
|
||||
BD16_to_BD24(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
Img result(24, channels, width, height);
|
||||
Img result(id, 24, channels, width, height);
|
||||
BD8_to_BD24(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -716,13 +748,13 @@ namespace ehs
|
||||
{
|
||||
case 32:
|
||||
{
|
||||
Img result(16, channels, width, height);
|
||||
Img result(id, 16, channels, width, height);
|
||||
BD32_to_BD16(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 24:
|
||||
{
|
||||
Img result(16, channels, width, height);
|
||||
Img result(id, 16, channels, width, height);
|
||||
BD24_to_BD16(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -732,7 +764,7 @@ namespace ehs
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
Img result(16, channels, width, height);
|
||||
Img result(id, 16, channels, width, height);
|
||||
BD8_to_BD16(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -790,19 +822,19 @@ namespace ehs
|
||||
{
|
||||
case 32:
|
||||
{
|
||||
Img result(8, channels, width, height);
|
||||
Img result(id, 8, channels, width, height);
|
||||
BD32_to_BD8(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 24:
|
||||
{
|
||||
Img result(8, channels, width, height);
|
||||
Img result(id, 8, channels, width, height);
|
||||
BD24_to_BD8(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
case 16:
|
||||
{
|
||||
Img result(8, channels, width, height);
|
||||
Img result(id, 8, channels, width, height);
|
||||
BD16_to_BD8(result.Size(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -848,7 +880,7 @@ namespace ehs
|
||||
File file(filePath, Mode::READ, Disposition::OPEN);
|
||||
Str_8 ext = file.GetExtension();
|
||||
|
||||
Img result;
|
||||
Img result(file.GetName());
|
||||
|
||||
const ImgCodec* codec = GetCodec(ext);
|
||||
if (!codec)
|
||||
@@ -881,7 +913,7 @@ namespace ehs
|
||||
return result;
|
||||
}
|
||||
|
||||
result = new Img();
|
||||
result = new Img(file.GetName());
|
||||
|
||||
Serializer<UInt_64> data = file.ReadSerializer_64(codec->GetEndianness(), file.Size());
|
||||
|
||||
@@ -896,9 +928,9 @@ namespace ehs
|
||||
return result;
|
||||
}
|
||||
|
||||
Img Img::FromData(const Str_8& ext, Serializer<UInt_64>& data)
|
||||
Img Img::FromData(Str_8 id, const Str_8& ext, Serializer<UInt_64>& data)
|
||||
{
|
||||
Img result;
|
||||
Img result((Str_8&&)id);
|
||||
|
||||
const ImgCodec* codec = GetCodec(ext);
|
||||
if (!codec)
|
||||
@@ -917,7 +949,7 @@ namespace ehs
|
||||
{
|
||||
UInt_8 bytes = bitDepth / 8;
|
||||
|
||||
Img result(bitDepth, channels, newWidth, newHeight);
|
||||
Img result(id, bitDepth, channels, newWidth, newHeight);
|
||||
|
||||
double xRatio = (double)width / (double)newWidth;
|
||||
double yRatio = (double)height / (double)newWidth;
|
||||
|
||||
@@ -3,37 +3,33 @@
|
||||
namespace ehs
|
||||
{
|
||||
Mesh::Mesh()
|
||||
: hashId(0)
|
||||
{
|
||||
AddType("Mesh");
|
||||
}
|
||||
|
||||
Mesh::Mesh(Str_8 id, Array<Vertex_f> vertices, Array<UInt_32> indices)
|
||||
: Resource(std::move(id)), vertices(std::move(vertices)), indices(std::move(indices))
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), vertices((Array<Vertex_f>&&)vertices),
|
||||
indices((Array<UInt_32>&&)indices)
|
||||
{
|
||||
AddType("Mesh");
|
||||
}
|
||||
|
||||
Mesh::Mesh(Str_8 id, Array<Vertex_f> vertices)
|
||||
: Resource(std::move(id)), vertices(std::move(vertices))
|
||||
{
|
||||
AddType("Mesh");
|
||||
}
|
||||
|
||||
Mesh::Mesh(Str_8 id)
|
||||
: Resource(std::move(id))
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), vertices((Array<Vertex_f>&&)vertices)
|
||||
{
|
||||
AddType("Mesh");
|
||||
}
|
||||
|
||||
Mesh::Mesh(Mesh&& mesh) noexcept
|
||||
: Resource(std::move(mesh)), vertices(std::move(mesh.vertices)),
|
||||
indices(std::move(mesh.indices))
|
||||
: BaseObj((BaseObj&&)mesh), hashId(mesh.hashId), id((Str_8&&)mesh.id), vertices((Array<Vertex_f>&&)mesh.vertices),
|
||||
indices((Array<UInt_32>&&)mesh.indices)
|
||||
{
|
||||
mesh.hashId = 0;
|
||||
}
|
||||
|
||||
Mesh::Mesh(const Mesh& mesh)
|
||||
: Resource(mesh), vertices(mesh.vertices), indices(mesh.indices), srcVertBuffer(mesh.srcVertBuffer),
|
||||
dstVertBuffer(mesh.dstVertBuffer), srcIndBuffer(mesh.srcIndBuffer), dstIndBuffer(mesh.dstIndBuffer)
|
||||
: BaseObj((BaseObj&&)mesh), hashId(mesh.hashId), id(mesh.id), vertices(mesh.vertices), indices(mesh.indices)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -42,14 +38,14 @@ namespace ehs
|
||||
if (this == &mesh)
|
||||
return *this;
|
||||
|
||||
vertices = std::move(mesh.vertices);
|
||||
indices = std::move(mesh.indices);
|
||||
srcVertBuffer = std::move(mesh.srcVertBuffer);
|
||||
dstVertBuffer = std::move(mesh.dstVertBuffer);
|
||||
srcIndBuffer = std::move(mesh.srcIndBuffer);
|
||||
dstIndBuffer = std::move(mesh.dstIndBuffer);
|
||||
BaseObj::operator=((BaseObj&&)mesh);
|
||||
|
||||
Resource::operator=(std::move(mesh));
|
||||
hashId = mesh.hashId;
|
||||
id = (Str_8&&)mesh.id;
|
||||
vertices = (Array<Vertex_f>&&)mesh.vertices;
|
||||
indices = (Array<UInt_32>&&)mesh.indices;
|
||||
|
||||
mesh.hashId = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -59,237 +55,36 @@ namespace ehs
|
||||
if (this == &mesh)
|
||||
return *this;
|
||||
|
||||
BaseObj::operator=(mesh);
|
||||
|
||||
hashId = mesh.hashId;
|
||||
id = mesh.id;
|
||||
vertices = mesh.vertices;
|
||||
indices = mesh.indices;
|
||||
srcVertBuffer = mesh.srcVertBuffer;
|
||||
dstVertBuffer = mesh.dstVertBuffer;
|
||||
srcIndBuffer = mesh.srcIndBuffer;
|
||||
dstIndBuffer = mesh.dstIndBuffer;
|
||||
|
||||
Resource::operator=(mesh);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Mesh::UploadToGpu(GpuCmdBuffer* cmdBuffer)
|
||||
void Mesh::Release()
|
||||
{
|
||||
GameLoop* gl = (GameLoop*)GetParent("GameLoop");
|
||||
if (!gl)
|
||||
return false;
|
||||
|
||||
RenderWindow* win = gl->GetWindow();
|
||||
if (!win)
|
||||
return false;
|
||||
|
||||
GpuInterface* inf = win->GetInterface();
|
||||
|
||||
if (readOnly)
|
||||
{
|
||||
srcVertBuffer = {
|
||||
inf,
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
||||
sizeof(Vertex_f) * vertices.Size()
|
||||
};
|
||||
|
||||
Byte* data = (Byte*)srcVertBuffer.MapMemory();
|
||||
|
||||
for (UInt_64 i = 0; i < vertices.Size(); ++i)
|
||||
for (UInt_64 v = 0; v < sizeof(Vertex_f); ++v)
|
||||
data[sizeof(Vertex_f) * i + v] = ((Byte*) &vertices[i])[v];
|
||||
|
||||
srcVertBuffer.UnMapMemory();
|
||||
|
||||
dstVertBuffer = {
|
||||
inf,
|
||||
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||
srcVertBuffer.Size(),
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
||||
};
|
||||
|
||||
VK_MEMORY_PROPERTY_HOST
|
||||
|
||||
VkBufferMemoryBarrier barrier = {};
|
||||
barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
|
||||
barrier.pNext = nullptr;
|
||||
barrier.srcAccessMask = 0;
|
||||
barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.buffer = dstVertBuffer;
|
||||
barrier.offset = 0;
|
||||
barrier.size = VK_WHOLE_SIZE;
|
||||
|
||||
cmdBuffer->BufferBarrier(
|
||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0,
|
||||
1,
|
||||
&barrier
|
||||
);
|
||||
|
||||
GpuBuffer::Copy(cmdBuffer, &srcVertBuffer, &dstVertBuffer);
|
||||
|
||||
barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
|
||||
barrier.pNext = nullptr;
|
||||
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.buffer = dstVertBuffer;
|
||||
barrier.offset = 0;
|
||||
barrier.size = VK_WHOLE_SIZE;
|
||||
|
||||
cmdBuffer->BufferBarrier(
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
|
||||
0,
|
||||
1,
|
||||
&barrier
|
||||
);
|
||||
|
||||
if (indices.Size())
|
||||
{
|
||||
srcIndBuffer = {
|
||||
inf,
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
||||
sizeof(UInt_32) * indices.Size()
|
||||
};
|
||||
|
||||
UInt_32* indMem = (UInt_32*)srcIndBuffer.MapMemory();
|
||||
|
||||
for (UInt_64 i = 0; i < indices.Size(); ++i)
|
||||
indMem[i] = indices[i];
|
||||
|
||||
srcIndBuffer.UnMapMemory();
|
||||
|
||||
dstIndBuffer = {
|
||||
inf,
|
||||
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
|
||||
srcIndBuffer.Size(),
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
||||
};
|
||||
|
||||
barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
|
||||
barrier.pNext = nullptr;
|
||||
barrier.srcAccessMask = 0;
|
||||
barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.buffer = dstIndBuffer;
|
||||
barrier.offset = 0;
|
||||
barrier.size = VK_WHOLE_SIZE;
|
||||
|
||||
cmdBuffer->BufferBarrier(
|
||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0,
|
||||
1,
|
||||
&barrier
|
||||
);
|
||||
|
||||
GpuBuffer::Copy(cmdBuffer, &srcIndBuffer, &dstIndBuffer);
|
||||
|
||||
barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
|
||||
barrier.pNext = nullptr;
|
||||
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.buffer = dstIndBuffer;
|
||||
barrier.offset = 0;
|
||||
barrier.size = VK_WHOLE_SIZE;
|
||||
|
||||
cmdBuffer->BufferBarrier(
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
|
||||
0,
|
||||
1,
|
||||
&barrier
|
||||
);
|
||||
}
|
||||
|
||||
cmdBuffer->AddDependency(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
dstVertBuffer = {
|
||||
inf,
|
||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||
sizeof(Vertex_f) * vertices.Size()
|
||||
};
|
||||
|
||||
void* data = dstVertBuffer.MapMemory();
|
||||
Util::Copy(data, &vertices[0], dstVertBuffer.Size());
|
||||
dstVertBuffer.UnMapMemory();
|
||||
|
||||
if (indices.Size())
|
||||
{
|
||||
dstIndBuffer = {
|
||||
inf,
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
|
||||
sizeof(UInt_32) * indices.Size()
|
||||
};
|
||||
|
||||
data = dstIndBuffer.MapMemory();
|
||||
Util::Copy(data, &indices[0], dstIndBuffer.Size());
|
||||
dstIndBuffer.UnMapMemory();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
vertices.Clear();
|
||||
indices.Clear();
|
||||
}
|
||||
|
||||
bool Mesh::PostGpuUpload()
|
||||
UInt_64 Mesh::GetHashId() const
|
||||
{
|
||||
srcVertBuffer.Release();
|
||||
srcIndBuffer.Release();
|
||||
|
||||
return true;
|
||||
return hashId;
|
||||
}
|
||||
|
||||
bool Mesh::HasPostGpuUploaded() const
|
||||
void Mesh::SetId(Str_8 newId)
|
||||
{
|
||||
return !srcVertBuffer.IsValid() && !srcIndBuffer.IsValid();
|
||||
hashId = newId.Hash_64();
|
||||
id = (Str_8&&)newId;
|
||||
}
|
||||
|
||||
bool Mesh::ReleaseFromGpu()
|
||||
Str_8 Mesh::GetId() const
|
||||
{
|
||||
srcVertBuffer.Release();
|
||||
srcIndBuffer.Release();
|
||||
dstVertBuffer.Release();
|
||||
dstIndBuffer.Release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Mesh::IsUploaded() const
|
||||
{
|
||||
return dstVertBuffer.IsValid();
|
||||
}
|
||||
|
||||
void Mesh::Bind(GpuCmdBuffer* cmdBuffer)
|
||||
{
|
||||
cmdBuffer->AddDependency(this);
|
||||
|
||||
if (dstIndBuffer.IsValid())
|
||||
{
|
||||
cmdBuffer->AddDependency(&dstIndBuffer);
|
||||
vkCmdBindIndexBuffer(*cmdBuffer, dstIndBuffer.GetBuffer(), 0, VK_INDEX_TYPE_UINT32);
|
||||
}
|
||||
|
||||
cmdBuffer->AddDependency(&dstVertBuffer);
|
||||
|
||||
VkDeviceSize offset = 0;
|
||||
VkBuffer vertB = dstVertBuffer.GetBuffer();
|
||||
vkCmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertB, &offset);
|
||||
}
|
||||
|
||||
void Mesh::Draw(GpuCmdBuffer* cmdBuffer, const UInt_32 instances)
|
||||
{
|
||||
if (dstIndBuffer.IsValid())
|
||||
vkCmdDrawIndexed(*cmdBuffer, indices.Size(), instances, 0, 0, 0);
|
||||
else
|
||||
vkCmdDraw(*cmdBuffer, vertices.Size(), instances, 0, 0);
|
||||
return id;
|
||||
}
|
||||
|
||||
void Mesh::SetVertices(const Array<Vertex_f>& newVertices)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace ehs
|
||||
{
|
||||
Model::Model()
|
||||
: hashId(0)
|
||||
{
|
||||
AddType("Model");
|
||||
}
|
||||
@@ -23,27 +24,27 @@ namespace ehs
|
||||
}
|
||||
|
||||
Model::Model(Str_8 id, Array<Mesh> meshes, Bone skeleton, Array<Animation> animations)
|
||||
: Resource(std::move(id)), meshes(std::move(meshes)), skeleton(std::move(skeleton)),
|
||||
animations(std::move(animations))
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), meshes((Array<Mesh>&&)meshes), skeleton((Bone&&)skeleton),
|
||||
animations((Array<Animation>&&)animations)
|
||||
{
|
||||
AddType("Model");
|
||||
}
|
||||
|
||||
Model::Model(Str_8 id, Array<Mesh> meshes, Bone skeleton)
|
||||
: Resource(std::move(id)), meshes(std::move(meshes)), skeleton(std::move(skeleton))
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), meshes((Array<Mesh>&&)meshes), skeleton((Bone&&)skeleton)
|
||||
{
|
||||
AddType("Model");
|
||||
}
|
||||
|
||||
Model::Model(Str_8 id, Array<Mesh> meshes)
|
||||
: Resource(std::move(id)), meshes(std::move(meshes))
|
||||
: hashId(id.Hash_64()), id((Str_8&&)id), meshes((Array<Mesh>&&)meshes)
|
||||
{
|
||||
AddType("Model");
|
||||
}
|
||||
|
||||
Model::Model(Model&& model) noexcept
|
||||
: Resource(std::move(model)), meshes(std::move(model.meshes)),
|
||||
skeleton(std::move(model.skeleton)), animations(std::move(model.animations))
|
||||
: BaseObj((BaseObj&&)model), hashId(model.hashId), id((Str_8&&)model.id), meshes((Array<Mesh>&&)model.meshes),
|
||||
skeleton((Bone&&)model.skeleton), animations((Array<Animation>&&)model.animations)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -52,60 +53,40 @@ namespace ehs
|
||||
if (this == &model)
|
||||
return *this;
|
||||
|
||||
BaseObj::operator=((BaseObj&&)model);
|
||||
|
||||
hashId = model.hashId;
|
||||
id = std::move(model.id);
|
||||
meshes = std::move(model.meshes);
|
||||
skeleton = std::move(model.skeleton);
|
||||
animations = std::move(model.animations);
|
||||
id = (Str_8&&)model.id;
|
||||
meshes = (Array<Mesh>&&)model.meshes;
|
||||
skeleton = (Bone&&)model.skeleton;
|
||||
animations = (Array<Animation>&&)model.animations;
|
||||
|
||||
model.hashId = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Model::UploadToGpu(GpuCmdBuffer* cmdBuffer)
|
||||
void Model::Release()
|
||||
{
|
||||
for (UInt_64 i = 0; i < meshes.Size(); ++i)
|
||||
if (!meshes[i].UploadToGpu(cmdBuffer))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
meshes.Clear();
|
||||
skeleton = {};
|
||||
animations.Clear();
|
||||
}
|
||||
|
||||
bool Model::PostGpuUpload()
|
||||
UInt_64 Model::GetHashId() const
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
for (UInt_64 i = 0; i < meshes.Size(); ++i)
|
||||
if (!meshes[i].PostGpuUpload())
|
||||
result = false;
|
||||
|
||||
return result;
|
||||
return hashId;
|
||||
}
|
||||
|
||||
bool Model::ReleaseFromGpu()
|
||||
void Model::SetId(Str_8 newId)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
for (UInt_64 i = 0; i < meshes.Size(); ++i)
|
||||
if (!meshes[i].ReleaseFromGpu())
|
||||
result = false;
|
||||
|
||||
return result;
|
||||
hashId = newId.Hash_64();
|
||||
id = (Str_8&&)newId;
|
||||
}
|
||||
|
||||
bool Model::IsUploaded() const
|
||||
Str_8 Model::GetId() const
|
||||
{
|
||||
return meshes[0].IsUploaded();
|
||||
}
|
||||
|
||||
void Model::Draw(GpuCmdBuffer* cmdBuffer, const UInt_32 instances)
|
||||
{
|
||||
for (UInt_64 i = 0; i < meshes.Size(); ++i)
|
||||
{
|
||||
meshes[i].Bind(cmdBuffer);
|
||||
meshes[i].Draw(cmdBuffer, instances);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
Array<Mesh> Model::GetMeshes() const
|
||||
@@ -118,18 +99,18 @@ namespace ehs
|
||||
return meshes;
|
||||
}
|
||||
|
||||
Mesh* Model::GetMesh(const UInt_64 hashId)
|
||||
Mesh* Model::GetMesh(const UInt_64 inHashId)
|
||||
{
|
||||
for (UInt_64 i = 0; i < meshes.Size(); ++i)
|
||||
if (meshes[i].GetHashId() == hashId)
|
||||
if (meshes[i].GetHashId() == inHashId)
|
||||
return &meshes[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Mesh* Model::GetMesh(const Str_8& id)
|
||||
Mesh* Model::GetMesh(const Str_8& inId)
|
||||
{
|
||||
return GetMesh(id.Hash_64());
|
||||
return GetMesh(inId.Hash_64());
|
||||
}
|
||||
|
||||
Bone Model::GetSkeleton() const
|
||||
@@ -142,10 +123,10 @@ namespace ehs
|
||||
return skeleton;
|
||||
}
|
||||
|
||||
Animation* Model::GetAnimation(const UInt_64 hashId)
|
||||
Animation* Model::GetAnimation(const UInt_64 inHashId)
|
||||
{
|
||||
for (UInt_64 i = 0; i < animations.Size(); ++i)
|
||||
if (animations[i].GetHashId() == hashId)
|
||||
if (animations[i].GetHashId() == inHashId)
|
||||
return &animations[i];
|
||||
|
||||
return nullptr;
|
||||
@@ -224,7 +205,6 @@ namespace ehs
|
||||
for (UInt_64 i = 0; i < meshes.Size(); ++i)
|
||||
{
|
||||
meshes[i].SetId(data.ReadStr<Char_8, UInt_64>());
|
||||
meshes[i].SetParent(this);
|
||||
|
||||
Array<Vertex_f>& vertices = meshes[i].GetVertices();
|
||||
vertices.Resize(data.Read<UInt_64>());
|
||||
|
||||
@@ -226,8 +226,7 @@ namespace ehs
|
||||
payload.WriteVersion(ver);
|
||||
payload.WriteVersion(appVer);
|
||||
|
||||
Endpoint* end = new Endpoint(hdl, type, address, port);
|
||||
end->SetParent(this);
|
||||
Endpoint* end = new Endpoint(this, type, address, port);
|
||||
end->Send(false, true, false, "Internal", "Connect", payload);
|
||||
|
||||
endpoints.Push(end);
|
||||
@@ -316,9 +315,8 @@ namespace ehs
|
||||
Architecture rArch = payload.Read<Architecture>();
|
||||
Str_8 rId = payload.ReadStr<Char_8, UInt_64>();
|
||||
|
||||
Endpoint* end = new Endpoint(hdl, header.disposition, rArch, rId, type, rAddress, rPort);
|
||||
Endpoint* end = new Endpoint(this, header.disposition, rArch, rId, type, rAddress, rPort);
|
||||
end->SetStatus(Status::PENDING);
|
||||
end->SetParent(this);
|
||||
|
||||
Serializer sPayload(Endianness::LE);
|
||||
|
||||
@@ -415,10 +413,9 @@ namespace ehs
|
||||
Architecture arch = payload.Read<Architecture>();
|
||||
Str_8 id = payload.ReadStr<Char_8, UInt_64>();
|
||||
|
||||
*end = Endpoint(hdl, header.disposition, arch, id, type, rAddress, rPort);
|
||||
*end = Endpoint(this, header.disposition, arch, id, type, rAddress, rPort);
|
||||
end->SetStatus(payload.Read<Status>());
|
||||
end->SetQueueSlot(payload.Read<UInt_64>());
|
||||
end->SetParent(this);
|
||||
|
||||
if (connectedCb)
|
||||
connectedCb(this, end);
|
||||
|
||||
@@ -20,24 +20,24 @@
|
||||
namespace ehs
|
||||
{
|
||||
Endpoint::Endpoint()
|
||||
: hdl(EHS_INVALID_SOCKET), disposition(EndDisp::UNKNOWN), status(Status::PENDING), arch(Architecture::UNKNOWN),
|
||||
: owner(nullptr), disposition(EndDisp::UNKNOWN), status(Status::PENDING), arch(Architecture::UNKNOWN),
|
||||
hashId(0), nextSendId(0), nextRecvId(0), port(0), deltaDuration(0.0f), deltaRate(1.0f / 60.0f),
|
||||
timeout(0.0f), lastPing(0.0f), oldLatency(0.0f), latency(0.0f), queueSlot(0)
|
||||
{
|
||||
AddType("Endpoint");
|
||||
}
|
||||
|
||||
Endpoint::Endpoint(Socket hdl, const EndDisp disposition, const Architecture arch, const Str_8& id,
|
||||
Endpoint::Endpoint(Comms* owner, const EndDisp disposition, const Architecture arch, const Str_8& id,
|
||||
const AddrType& type, const Str_8& address, const UInt_16 port)
|
||||
: hdl(hdl), disposition(disposition), status(Status::ACTIVE), arch(arch), id(id), hashId(id.Hash_32()), nextSendId(0),
|
||||
: owner(owner), disposition(disposition), status(Status::ACTIVE), arch(arch), id(id), hashId(id.Hash_32()), nextSendId(0),
|
||||
nextRecvId(0), address(address), port(port), deltaDuration(0.0f), deltaRate(1.0f / 60.0f), timeout(0.0f),
|
||||
lastPing(0.0f), oldLatency(0.0f), latency(0.0f), queueSlot(0)
|
||||
{
|
||||
AddType("Endpoint");
|
||||
}
|
||||
|
||||
Endpoint::Endpoint(Socket hdl, const AddrType& type, const Str_8& address, const UInt_16 port)
|
||||
: hdl(hdl), disposition(EndDisp::UNKNOWN), status(Status::PENDING), arch(Architecture::UNKNOWN), hashId(0),
|
||||
Endpoint::Endpoint(Comms* owner, const AddrType& type, const Str_8& address, const UInt_16 port)
|
||||
: owner(owner), disposition(EndDisp::UNKNOWN), status(Status::PENDING), arch(Architecture::UNKNOWN), hashId(0),
|
||||
nextSendId(0), nextRecvId(0), address(address), port(port), deltaDuration(0.0f), deltaRate(1.0f / 60.0f),
|
||||
timeout(0.0f), lastPing(0.0f), oldLatency(0.0f), latency(0.0f), queueSlot(0)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace ehs
|
||||
}
|
||||
|
||||
Endpoint::Endpoint(const Endpoint& end)
|
||||
: BaseObj(end), hdl(EHS_INVALID_SOCKET), disposition(end.disposition), status(Status::PENDING), arch(end.arch),
|
||||
: BaseObj(end), owner(nullptr), disposition(end.disposition), status(Status::PENDING), arch(end.arch),
|
||||
id(end.id), hashId(end.hashId), nextSendId(0), nextRecvId(0), address(end.address), port(end.port),
|
||||
deltaDuration(0.0f), deltaRate(1.0f / 60.0f), timeout(0.0f), lastPing(0.0f),
|
||||
oldLatency(0.0f), latency(0.0f), queueSlot(0)
|
||||
@@ -82,7 +82,7 @@ namespace ehs
|
||||
}
|
||||
else
|
||||
{
|
||||
hdl = EHS_INVALID_SOCKET;
|
||||
owner = nullptr;
|
||||
disposition = end.disposition;
|
||||
status = Status::PENDING;
|
||||
arch = end.arch;
|
||||
@@ -108,13 +108,6 @@ namespace ehs
|
||||
|
||||
void Endpoint::Poll(const float delta)
|
||||
{
|
||||
Comms* comms = (Comms*)GetParent();
|
||||
if (!comms)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Endpoint must be a child of a Socket object.");
|
||||
return;
|
||||
}
|
||||
|
||||
SortReceived();
|
||||
|
||||
if (deltaDuration >= deltaRate)
|
||||
@@ -129,7 +122,7 @@ namespace ehs
|
||||
for (UInt_64 i = 0; i < sent.Size(); ++i)
|
||||
{
|
||||
sent[i].lastResend += delta;
|
||||
if (sent[i].lastResend >= comms->GetResendRate())
|
||||
if (sent[i].lastResend >= owner->GetResendRate())
|
||||
{
|
||||
Serializer result(Endianness::LE);
|
||||
result.Write(sent[i].header);
|
||||
@@ -138,17 +131,17 @@ namespace ehs
|
||||
if (sent[i].header.encrypted)
|
||||
Encryption::Encrypt_64(result.Size() - sizeof(bool), &result[sizeof(bool)]);
|
||||
|
||||
if (comms->GetAddressType() == AddrType::IPV6)
|
||||
if (owner->GetAddressType() == AddrType::IPV6)
|
||||
Send_v6(result);
|
||||
else if (comms->GetAddressType() == AddrType::IPV4)
|
||||
else if (owner->GetAddressType() == AddrType::IPV4)
|
||||
Send_v4(result);
|
||||
|
||||
sent[i].lastResend = Math::Mod(sent[i].lastResend, comms->GetResendRate());
|
||||
sent[i].lastResend = Math::Mod(sent[i].lastResend, owner->GetResendRate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (comms->GetDisposition() == EndDisp::SERVICE)
|
||||
if (owner->GetDisposition() == EndDisp::SERVICE)
|
||||
{
|
||||
lastPing += delta;
|
||||
if (lastPing >= 1.0f)
|
||||
@@ -194,13 +187,6 @@ namespace ehs
|
||||
void Endpoint::Send(const bool deltaLocked, const bool encrypted, const bool ensure, const UInt_64 sys,
|
||||
const UInt_64 op, const Serializer<>& payload)
|
||||
{
|
||||
Comms* comms = (Comms*)GetParent();
|
||||
if (!comms)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Endpoint must be a child of a Socket object.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (deltaLocked && deltaDuration < deltaRate)
|
||||
return;
|
||||
|
||||
@@ -210,13 +196,13 @@ namespace ehs
|
||||
1,
|
||||
0,
|
||||
ensure,
|
||||
comms->GetDisposition(),
|
||||
comms->GetHashId(),
|
||||
owner->GetDisposition(),
|
||||
owner->GetHashId(),
|
||||
sys,
|
||||
op
|
||||
};
|
||||
|
||||
if ((comms->GetAddressType() == AddrType::IPV6 && payload.Size() > COMMS_IPV6_PAYLOAD) || (comms->GetAddressType() == AddrType::IPV4 && payload.Size() > COMMS_IPV4_PAYLOAD))
|
||||
if ((owner->GetAddressType() == AddrType::IPV6 && payload.Size() > COMMS_IPV6_PAYLOAD) || (owner->GetAddressType() == AddrType::IPV4 && payload.Size() > COMMS_IPV4_PAYLOAD))
|
||||
{
|
||||
Fragments frags = FragmentData(header, payload);
|
||||
for (UInt_64 i = 0; i < frags.Size(); ++i)
|
||||
@@ -380,16 +366,9 @@ namespace ehs
|
||||
|
||||
Fragments Endpoint::FragmentData(const Header& header, const Serializer<>& data)
|
||||
{
|
||||
Comms* comms = (Comms*)GetParent();
|
||||
if (!comms)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Endpoint must be a child of a Socket object.");
|
||||
return {};
|
||||
}
|
||||
|
||||
Fragments result;
|
||||
|
||||
if (comms->GetAddressType() == AddrType::IPV6)
|
||||
if (owner->GetAddressType() == AddrType::IPV6)
|
||||
{
|
||||
UInt_64 frags = data.Size() / COMMS_IPV6_PAYLOAD;
|
||||
if (data.Size() % COMMS_IPV6_PAYLOAD)
|
||||
@@ -408,7 +387,7 @@ namespace ehs
|
||||
result[i] = {data.GetEndianness(), &data[i * COMMS_IPV6_PAYLOAD], size};
|
||||
}
|
||||
}
|
||||
else if (comms->GetAddressType() == AddrType::IPV4)
|
||||
else if (owner->GetAddressType() == AddrType::IPV4)
|
||||
{
|
||||
UInt_64 frags = data.Size() / COMMS_IPV4_PAYLOAD;
|
||||
if (data.Size() % COMMS_IPV4_PAYLOAD)
|
||||
@@ -433,13 +412,6 @@ namespace ehs
|
||||
|
||||
void Endpoint::Send(const Header& header, const Serializer<>& payload)
|
||||
{
|
||||
Comms* comms = (Comms*)GetParent();
|
||||
if (!comms)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Endpoint must be a child of a Socket object.");
|
||||
return;
|
||||
}
|
||||
|
||||
Serializer result(Endianness::LE);
|
||||
result.Write(header);
|
||||
result.WriteSer(payload);
|
||||
@@ -450,9 +422,9 @@ namespace ehs
|
||||
if (header.ensure)
|
||||
sent.Push({header, payload});
|
||||
|
||||
if (comms->GetAddressType() == AddrType::IPV6)
|
||||
if (owner->GetAddressType() == AddrType::IPV6)
|
||||
Send_v6(result);
|
||||
else if (comms->GetAddressType() == AddrType::IPV4)
|
||||
else if (owner->GetAddressType() == AddrType::IPV4)
|
||||
Send_v4(result);
|
||||
}
|
||||
|
||||
@@ -512,7 +484,7 @@ namespace ehs
|
||||
|
||||
UInt_16 Endpoint::Send_v6(const Serializer<>& payload)
|
||||
{
|
||||
if (hdl == EHS_INVALID_SOCKET)
|
||||
if (!owner)
|
||||
{
|
||||
EHS_LOG_INT("Info", 0, "Attempted to send while socket is not initialized.");
|
||||
return 0;
|
||||
@@ -549,7 +521,7 @@ namespace ehs
|
||||
return 0;
|
||||
}
|
||||
|
||||
Int_32 sent = sendto(hdl, (char*)&payload[0], (int)payload.Size(), 0, (sockaddr*)&result, sizeof(sockaddr_in6));
|
||||
Int_32 sent = sendto(owner->hdl, (char*)&payload[0], (int)payload.Size(), 0, (sockaddr*)&result, sizeof(sockaddr_in6));
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
if (sent == SOCKET_ERROR)
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
@@ -566,7 +538,7 @@ namespace ehs
|
||||
|
||||
EHS_LOG_INT("Error", 4, "Failed to send with error #" + Str_8::FromNum(dCode) + ".");
|
||||
|
||||
((Comms*)GetParent())->UnInitialize();
|
||||
owner->UnInitialize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -576,7 +548,7 @@ namespace ehs
|
||||
|
||||
UInt_16 Endpoint::Send_v4(const Serializer<>& payload)
|
||||
{
|
||||
if (hdl == EHS_INVALID_SOCKET)
|
||||
if (!owner)
|
||||
{
|
||||
EHS_LOG_INT("Info", 0, "Attempted to send while socket is not initialized.");
|
||||
return 0;
|
||||
@@ -613,7 +585,7 @@ namespace ehs
|
||||
return 0;
|
||||
}
|
||||
|
||||
SInt_64 sent = sendto(hdl, (char*)&payload[0], (int)payload.Size(), 0, (sockaddr*)&result, sizeof(sockaddr_in));
|
||||
SInt_64 sent = sendto(owner->hdl, (char*)&payload[0], (int)payload.Size(), 0, (sockaddr*)&result, sizeof(sockaddr_in));
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
if (sent == SOCKET_ERROR)
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
@@ -636,7 +608,7 @@ namespace ehs
|
||||
{
|
||||
EHS_LOG_INT("Error", 3, "Failed to send with error #" + Str_8::FromNum(dCode) + ".");
|
||||
|
||||
((Comms*)GetParent())->UnInitialize();
|
||||
owner->UnInitialize();
|
||||
}
|
||||
#else
|
||||
Int_32 dCode = 0;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace ehs
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
client = TCP(lwe::AddrType::IPV4);
|
||||
client = TCP(ehs::AddrType::IPV4);
|
||||
client.Connect(DNS::Resolve(AddrType::IPV4, "irc.chat.twitch.tv"), 6667);
|
||||
client.SetBlocking(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user