First commit.
This commit is contained in:
199
include/IO/Audio/Audio.h
Normal file
199
include/IO/Audio/Audio.h
Normal file
@@ -0,0 +1,199 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../DataType.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Array.h"
|
||||
#include "AudioCodec.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Audio : public Resource
|
||||
{
|
||||
private:
|
||||
static Array<AudioCodec> codecs;
|
||||
UInt_64 sampleRate;
|
||||
DataType dataType;
|
||||
UInt_8 byteDepth;
|
||||
UInt_8 channels;
|
||||
UInt_64 frames;
|
||||
float length;
|
||||
Byte* data;
|
||||
Byte* peak;
|
||||
|
||||
public:
|
||||
static bool HasCodec(const UInt_64 hashExt);
|
||||
|
||||
static bool HasCodec(const Str_8& ext);
|
||||
|
||||
static bool AddCodec(AudioCodec codec);
|
||||
|
||||
static const AudioCodec* GetCodec(const UInt_64 hashExt);
|
||||
|
||||
static const AudioCodec* GetCodec(const Str_8& ext);
|
||||
|
||||
~Audio() override;
|
||||
|
||||
Audio();
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const UInt_64 frames, const Byte* const data);
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Serializer<UInt_64>& data);
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Vector<Byte>& data);
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Array<Byte>& data);
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const UInt_64 frames);
|
||||
|
||||
Audio(Audio&& audio) noexcept;
|
||||
|
||||
Audio(const Audio& audio);
|
||||
|
||||
Audio& operator=(Audio&& audio) noexcept;
|
||||
|
||||
Audio& operator=(const Audio& audio);
|
||||
|
||||
operator const Byte*() const;
|
||||
|
||||
operator Byte*();
|
||||
|
||||
UInt_64 GetSampleRate() const;
|
||||
|
||||
DataType GetDataType() const;
|
||||
|
||||
UInt_8 GetByteDepth() const;
|
||||
|
||||
UInt_8 GetBitDepth() const;
|
||||
|
||||
UInt_8 GetChannels() const;
|
||||
|
||||
UInt_64 GetFrameCount() const;
|
||||
|
||||
UInt_64 GetSampleCount() const;
|
||||
|
||||
UInt_64 GetSize() const;
|
||||
|
||||
float GetLength() const;
|
||||
|
||||
Array<Byte> FrameAsMono(const UInt_64 frameIndex) const;
|
||||
|
||||
Array<Byte> FrameAsStereo(const UInt_64 frameIndex) const;
|
||||
|
||||
Array<Byte> FrameAsFive_One(const UInt_64 frameIndex) const;
|
||||
|
||||
Array<Byte> FrameAsSeven_One(const UInt_64 frameIndex) const;
|
||||
|
||||
SInt_8 SampleAsSInt_8(const UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_16 SampleAsSInt_16(const UInt_64 sampleIndex) const;
|
||||
|
||||
float SampleAsFloat(const UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_32 SampleAsSInt_32(const UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_64 SampleAsSInt_64(const UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_8 PeakAsSInt_8() const;
|
||||
|
||||
SInt_16 PeakAsSInt_16() const;
|
||||
|
||||
float PeakAsFloat() const;
|
||||
|
||||
SInt_32 PeakAsSInt_32() const;
|
||||
|
||||
SInt_64 PeakAsSInt_64() const;
|
||||
|
||||
void SetPeak(const UInt_64 size, const Byte* newPeak);
|
||||
|
||||
const Byte* GetPeak() const;
|
||||
|
||||
void ToDataType(const DataType newDataType);
|
||||
|
||||
Audio GetAsDataType(const DataType newDataType) const;
|
||||
|
||||
void ToChannels(const UInt_8 newChannels);
|
||||
|
||||
Audio GetAsChannels(const UInt_8 newChannels) const;
|
||||
|
||||
bool ToFile(const Str_8& filePath) const;
|
||||
|
||||
static Audio FromFile(const Str_8& filePath);
|
||||
|
||||
static Audio* FromFile_Heap(const Str_8& filePath);
|
||||
|
||||
static Audio FromFile(const Str_8& filePath, const DataType required);
|
||||
|
||||
static Audio* FromFile_Heap(const Str_8& filePath, const DataType required);
|
||||
|
||||
static Audio FromData(const Str_8& ext, const Str_8& id, Serializer<UInt_64>& data);
|
||||
|
||||
private:
|
||||
void ToMono(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Mono_to_Stereo(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Five_One_to_Stereo(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Seven_One_to_Stereo(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Mono_to_Five_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Stereo_to_Five_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Seven_One_to_Five_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Mono_to_Seven_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Stereo_to_Seven_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Five_One_to_Seven_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
// To SInt_8
|
||||
void SInt_16_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void Float_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_32_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_64_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
// To SInt_16
|
||||
void SInt_8_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void Float_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_32_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_64_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
// To Float
|
||||
void SInt_8_to_Float(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_16_to_Float(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_32_to_Float(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_64_to_Float(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
// To SInt_32
|
||||
void SInt_8_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_16_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void Float_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_64_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
// To SInt_64
|
||||
void SInt_8_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_16_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void Float_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_32_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||||
};
|
||||
}
|
48
include/IO/Audio/AudioCodec.h
Normal file
48
include/IO/Audio/AudioCodec.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../File.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Audio;
|
||||
|
||||
class AudioCodec
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashExt;
|
||||
Str_8 ext;
|
||||
Endianness endianness;
|
||||
bool (*encodeCb)(const AudioCodec* const, Serializer<UInt_64>&, const Audio*);
|
||||
bool (*decodeCb)(const AudioCodec* const, Serializer<UInt_64>&, Audio*);
|
||||
|
||||
public:
|
||||
AudioCodec();
|
||||
|
||||
AudioCodec(Str_8 id, Str_8 ext, const Endianness end,
|
||||
bool (*encodeCb)(const AudioCodec* const, Serializer<UInt_64>&, const Audio*),
|
||||
bool (*decodeCb)(const AudioCodec* const, Serializer<UInt_64>&, Audio*));
|
||||
|
||||
AudioCodec(AudioCodec&& codec) noexcept;
|
||||
|
||||
AudioCodec(const AudioCodec& codec);
|
||||
|
||||
AudioCodec& operator=(AudioCodec&& codec) noexcept;
|
||||
|
||||
AudioCodec& operator=(const AudioCodec& codec);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashExt() const;
|
||||
|
||||
Str_8 GetExt() const;
|
||||
|
||||
Endianness GetEndianness() const;
|
||||
|
||||
bool Encode(Serializer<UInt_64>& out, const Audio* in) const;
|
||||
|
||||
bool Decode(Serializer<UInt_64>& in, Audio* out) const;
|
||||
};
|
||||
}
|
9
include/IO/Audio/AudioDevice.h
Normal file
9
include/IO/Audio/AudioDevice.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
#include "AudioDevice_W32.h"
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
#include "AudioDevice_ALSA.h"
|
||||
#endif
|
46
include/IO/Audio/AudioDevice_ALSA.h
Normal file
46
include/IO/Audio/AudioDevice_ALSA.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "BaseAudioDevice.h"
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class AudioDevice : public BaseAudioDevice
|
||||
{
|
||||
private:
|
||||
snd_pcm_t* hdl;
|
||||
|
||||
public:
|
||||
~AudioDevice() override;
|
||||
|
||||
AudioDevice();
|
||||
|
||||
AudioDevice(AudioDevice&& device) noexcept;
|
||||
|
||||
AudioDevice(const AudioDevice& device);
|
||||
|
||||
AudioDevice& operator=(AudioDevice&& device) noexcept;
|
||||
|
||||
AudioDevice& operator=(const AudioDevice& device);
|
||||
|
||||
void Release() override;
|
||||
|
||||
void OpenStream() override;
|
||||
|
||||
void CloseStream() override;
|
||||
|
||||
UInt_64 GetAvailFrames() const override;
|
||||
|
||||
Byte* Map(UInt_64* offset, UInt_64* frames) override;
|
||||
|
||||
void UnMap(const UInt_64 offset, const UInt_64 frames) override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
static AudioDevice GetDefault(const AudioDeviceType type);
|
||||
|
||||
static Array<AudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
|
||||
};
|
||||
}
|
66
include/IO/Audio/AudioDevice_W32.h
Normal file
66
include/IO/Audio/AudioDevice_W32.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "BaseAudioDevice.h"
|
||||
|
||||
#include <initguid.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <functiondiscoverykeys_devpkey.h>
|
||||
#include <Audioclient.h>
|
||||
|
||||
struct IMMDevice;
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class AudioDevice : public BaseAudioDevice
|
||||
{
|
||||
private:
|
||||
IMMDevice* hdl;
|
||||
IAudioClient* client;
|
||||
IAudioRenderClient* playbackClient;
|
||||
IAudioCaptureClient* captureClient;
|
||||
|
||||
public:
|
||||
~AudioDevice() override;
|
||||
|
||||
AudioDevice();
|
||||
|
||||
AudioDevice(AudioDevice&& device) noexcept;
|
||||
|
||||
AudioDevice(const AudioDevice& device);
|
||||
|
||||
AudioDevice& operator=(AudioDevice&& device) noexcept;
|
||||
|
||||
AudioDevice& operator=(const AudioDevice& device);
|
||||
|
||||
void Release() override;
|
||||
|
||||
void OpenStream() override;
|
||||
|
||||
void CloseStream() override;
|
||||
|
||||
UInt_64 GetAvailFrames() const override;
|
||||
|
||||
Byte* Map(UInt_64* offset, UInt_64* frames) override;
|
||||
|
||||
void UnMap(const UInt_64 offset, const UInt_64 frames) override;
|
||||
|
||||
Str_32 GetInterfaceName_32() const;
|
||||
|
||||
Str_16 GetInterfaceName_16() const;
|
||||
|
||||
Str_8 GetInterfaceName_8() const;
|
||||
|
||||
Str_32 GetName_32() const;
|
||||
|
||||
Str_16 GetName_16() const;
|
||||
|
||||
Str_8 GetName_8() const;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
static AudioDevice GetDefault(const AudioDeviceType type);
|
||||
|
||||
static Array<AudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
|
||||
};
|
||||
}
|
105
include/IO/Audio/BaseAudioDevice.h
Normal file
105
include/IO/Audio/BaseAudioDevice.h
Normal file
@@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Array.h"
|
||||
#include "../../DataType.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class AudioDeviceType
|
||||
{
|
||||
OUTPUT = 0x0,
|
||||
INPUT = 0x1,
|
||||
ALL = 0x2
|
||||
};
|
||||
|
||||
enum class AudioDeviceState
|
||||
{
|
||||
ACTIVE = 0x1,
|
||||
DISABLED = 0x2,
|
||||
NOT_PRESENT = 0x4,
|
||||
UNPLUGGED = 0x8
|
||||
};
|
||||
|
||||
class BaseAudioDevice
|
||||
{
|
||||
protected:
|
||||
AudioDeviceType type;
|
||||
DataType dataType;
|
||||
UInt_16 bitDepth;
|
||||
UInt_32 sampleRate;
|
||||
UInt_32 channels;
|
||||
UInt_32 period;
|
||||
UInt_32 latency;
|
||||
UInt_64 maxFrames;
|
||||
bool streaming;
|
||||
|
||||
public:
|
||||
virtual ~BaseAudioDevice() = default;
|
||||
|
||||
BaseAudioDevice();
|
||||
|
||||
BaseAudioDevice(const BaseAudioDevice& device);
|
||||
|
||||
BaseAudioDevice& operator=(const BaseAudioDevice& device);
|
||||
|
||||
virtual void Release();
|
||||
|
||||
virtual void OpenStream();
|
||||
|
||||
virtual void CloseStream();
|
||||
|
||||
virtual UInt_64 GetAvailFrames() const;
|
||||
|
||||
virtual Byte* Map(UInt_64* offset, UInt_64* frames);
|
||||
|
||||
virtual void UnMap(const UInt_64 offset, const UInt_64 frames);
|
||||
|
||||
AudioDeviceType GetType() const;
|
||||
|
||||
void SetDataType(const DataType newDataType);
|
||||
|
||||
DataType GetDataType() const;
|
||||
|
||||
UInt_8 GetByteDepth() const;
|
||||
|
||||
UInt_16 GetBitDepth() const;
|
||||
|
||||
void SetSampleRate(const UInt_32 newSampleRate);
|
||||
|
||||
UInt_32 GetSampleRate() const;
|
||||
|
||||
void SetChannels(const UInt_32 newChannels);
|
||||
|
||||
UInt_16 GetChannels() const;
|
||||
|
||||
UInt_32 GetFrameSize() const;
|
||||
|
||||
void SetPeriod(const UInt_32 newPeriod);
|
||||
|
||||
UInt_32 GetPeriod() const;
|
||||
|
||||
void SetLatency(const UInt_32 newLatency);
|
||||
|
||||
UInt_32 GetLatency() const;
|
||||
|
||||
UInt_64 GetMaxFrames() const;
|
||||
|
||||
bool IsStreaming() const;
|
||||
|
||||
virtual bool IsValid() const;
|
||||
|
||||
/// Retrieves the default audio input/output device.
|
||||
/// @param [in] type The audio device type to retrieve.
|
||||
/// @param [out] device The default audio device.
|
||||
static BaseAudioDevice GetDefault(const AudioDeviceType type);
|
||||
|
||||
/// Retrieves a list of audio input/output devices.
|
||||
/// @param [in] type The audio device type to retrieve.
|
||||
/// @param [in] state The audio device state to retrieve.
|
||||
/// @param [out] devices The list of audio devices.
|
||||
static Array<BaseAudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
|
||||
};
|
||||
}
|
260
include/IO/BaseFile.h
Normal file
260
include/IO/BaseFile.h
Normal file
@@ -0,0 +1,260 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../Vector.h"
|
||||
#include "../Array.h"
|
||||
#include "../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class Mode
|
||||
{
|
||||
READ,
|
||||
WRITE,
|
||||
READ_WRITE
|
||||
};
|
||||
|
||||
enum class Disposition
|
||||
{
|
||||
CREATE_PERSISTENT,
|
||||
CREATE,
|
||||
OPEN_PERSISTENT,
|
||||
OPEN,
|
||||
TRUNCATE
|
||||
};
|
||||
|
||||
/// A cross-platform wrapper class that handles native file input/output.
|
||||
class BaseFile
|
||||
{
|
||||
protected:
|
||||
Str_8 path;
|
||||
Str_8 fullName;
|
||||
Str_8 name;
|
||||
Str_8 extension;
|
||||
Mode mode;
|
||||
Disposition disposition;
|
||||
|
||||
public:
|
||||
/// Frees all native handles.
|
||||
virtual ~BaseFile() = default;
|
||||
|
||||
/// Default members initialization.
|
||||
BaseFile();
|
||||
|
||||
/// Initializes members with the given data.
|
||||
/// @param [in] filePath The file path to read or write to.
|
||||
/// @param [in] mode The mode when accessing the file.
|
||||
/// @param [in] disposition How to handle the file.
|
||||
BaseFile(const Str_8& filePath, const Mode mode, const Disposition disposition);
|
||||
|
||||
BaseFile(BaseFile&& file) noexcept;
|
||||
|
||||
/// Copy constructor.
|
||||
/// @param [in] file The file object to copy from.
|
||||
BaseFile(const BaseFile& file) = default;
|
||||
|
||||
BaseFile& operator=(BaseFile&& file) noexcept;
|
||||
|
||||
/// Copy operator.
|
||||
/// @param [in] file The file object to copy from.
|
||||
BaseFile& operator=(const BaseFile& file) = default;
|
||||
|
||||
virtual operator const Byte*() const = 0;
|
||||
|
||||
virtual operator Byte*() = 0;
|
||||
|
||||
/// Uninitializes the native handle.
|
||||
/// @param [in] raiseLog Whether or not to raise a log if already uninitialized. Mostly for deconstructor.
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual bool IsMapped() const = 0;
|
||||
|
||||
virtual UInt_64 MapSize() const = 0;
|
||||
|
||||
virtual void Map(const UInt_64 offset, const UInt_64 size) = 0;
|
||||
|
||||
virtual void Unmap() = 0;
|
||||
|
||||
virtual void FlushMap() = 0;
|
||||
|
||||
/// Writes a C-style byte array to the file.
|
||||
/// @param [in] data The C-style byte array to write to the file.
|
||||
/// @param [in] size The size of the given C-style byte array.
|
||||
virtual UInt_64 Write(const Byte* const data, const UInt_64 size) = 0;
|
||||
|
||||
/// Writes a C-style string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [in] str The C-style string to write to the file.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
void WriteStr_32(const Char_32* const str, const UInt_64 size);
|
||||
|
||||
/// Writes a string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] str The string to write to the file.
|
||||
void WriteStr_32(const Str_32& str);
|
||||
|
||||
/// Writes a C-style string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [in] str The C-style string to write to the file.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
void WriteStr_16(const Char_16* const str, const UInt_64 size);
|
||||
|
||||
/// Writes a string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] str The string to write to the file.
|
||||
void WriteStr_16(const Str_16& str);
|
||||
|
||||
/// Writes a C-style string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [in] str The C-style string to write to the file.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
void WriteStr_8(const Char_8* const str, const UInt_64 size);
|
||||
|
||||
/// Writes a string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] str The string to write to the file.
|
||||
void WriteStr_8(const Str_8& str);
|
||||
|
||||
/// Writes a vector to the file.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] vec The vector to write to the file.
|
||||
void WriteVector(const Vector<Byte, UInt_64>& vec);
|
||||
|
||||
/// Writes an array to the file.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] arr The array to write to the file.
|
||||
void WriteArray(const Array<Byte, UInt_64>& arr);
|
||||
|
||||
/// Writes a serializer to the file.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] ser The serializer to write to the file.
|
||||
void WriteSerializer_64(const Serializer<UInt_64>& ser);
|
||||
|
||||
/// Writes a serializer to the file.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] ser The serializer to write to the file.
|
||||
void WriteSerializer_32(const Serializer<UInt_32>& ser);
|
||||
|
||||
/// Reads data from the file as a C-style byte array.
|
||||
/// @param [out] buffer The buffer to store the data read from the file.
|
||||
/// @param [in] size The size of the given buffer and how much data to read.
|
||||
virtual UInt_64 Read(Byte* const buffer, const UInt_64 size) = 0;
|
||||
|
||||
/// Reads data from the file as a C-style string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [out] buffer The buffer to store the data read from the file.
|
||||
/// @param [in] size The size of the given buffer and how much data to read.
|
||||
void ReadStr_32(Char_32* const buffer, UInt_64& size);
|
||||
|
||||
/// Reads data from the file as a string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting string.
|
||||
Str_32 ReadStr_32(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a C-style string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [out] buffer The buffer to store the data read from the file.
|
||||
/// @param [in] size The size of the given buffer and how much data to read.
|
||||
void ReadStr_16(Char_16* const buffer, UInt_64& size);
|
||||
|
||||
/// Reads data from the file as a string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting string.
|
||||
Str_16 ReadStr_16(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a C-style string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [out] buffer The buffer to store the data read from the file.
|
||||
/// @param [in] size The size of the given buffer and how much data to read.
|
||||
void ReadStr_8(Char_8* const buffer, UInt_64& size);
|
||||
|
||||
/// Reads data from the file as a string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting string.
|
||||
Str_8 ReadStr_8(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a vector.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting vector.
|
||||
Vector<Byte, UInt_64> ReadVector(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as an array.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting array.
|
||||
Array<Byte, UInt_64> ReadArray(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a serializer.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param[in] end The Endianness of the data in the file.
|
||||
/// @param[in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting serializer.
|
||||
Serializer<UInt_64> ReadSerializer_64(const Endianness end, const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a serializer.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param[in] end The Endianness of the data in the file.
|
||||
/// @param[in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting serializer.
|
||||
Serializer<UInt_32> ReadSerializer_32(const Endianness end, const UInt_32 size);
|
||||
|
||||
virtual void Seek(UInt_64 index) = 0;
|
||||
|
||||
virtual void SeekBeginning() = 0;
|
||||
|
||||
virtual void SeekEnd() = 0;
|
||||
|
||||
virtual void Truncate(const UInt_64 size) = 0;
|
||||
|
||||
/// Retrieves the size of the file.
|
||||
/// @returns The result.
|
||||
virtual UInt_64 Size() const = 0;
|
||||
|
||||
Str_8 GetPath() const;
|
||||
|
||||
Str_8 GetFullName() const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
Str_8 GetExtension() const;
|
||||
|
||||
/// Retrieves whether or not this object is valid.
|
||||
/// @returns The result.
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
static void Rename_32(const Str_32& filePath, const Str_32& newName);
|
||||
|
||||
static void Rename_16(const Str_16& filePath, const Str_16& newName);
|
||||
|
||||
static void Rename_8(const Str_8& filePath, const Str_8& newName);
|
||||
|
||||
static Str_32 ProcessFullName_32(const Str_32& filePath);
|
||||
|
||||
static Str_16 ProcessFullName_16(const Str_16& filePath);
|
||||
|
||||
static Str_8 ProcessFullName_8(const Str_8& filePath);
|
||||
|
||||
static Str_32 ProcessName_32(const Str_32& filePath);
|
||||
|
||||
static Str_16 ProcessName_16(const Str_16& filePath);
|
||||
|
||||
static Str_8 ProcessName_8(const Str_8& filePath);
|
||||
|
||||
static Str_32 ProcessExt_32(const Str_32& filePath);
|
||||
|
||||
static Str_16 ProcessExt_16(const Str_16& filePath);
|
||||
|
||||
static Str_8 ProcessExt_8(const Str_8& filePath);
|
||||
};
|
||||
}
|
46
include/IO/BaseFileMonitor.h
Normal file
46
include/IO/BaseFileMonitor.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
|
||||
#define LWE_FE_NONE 0x00
|
||||
#define LWE_FE_MODIFIED 0x01
|
||||
#define LWE_FE_DELETED 0x02
|
||||
#define LWE_FE_MOVED 0x04
|
||||
#define LWE_FE_OPENED 0x08
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class BaseFileMonitor
|
||||
{
|
||||
protected:
|
||||
Str_8 filePath;
|
||||
|
||||
public:
|
||||
virtual ~BaseFileMonitor() = default;
|
||||
|
||||
BaseFileMonitor() = default;
|
||||
|
||||
BaseFileMonitor(Str_8 filePath);
|
||||
|
||||
BaseFileMonitor(BaseFileMonitor&& fm) noexcept;
|
||||
|
||||
BaseFileMonitor(const BaseFileMonitor& fm);
|
||||
|
||||
BaseFileMonitor& operator=(BaseFileMonitor&& fm) noexcept;
|
||||
|
||||
BaseFileMonitor& operator=(const BaseFileMonitor& fm);
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual UInt_8 Poll() = 0;
|
||||
|
||||
Str_8 GetFilePath() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
virtual bool IsInitialized() const = 0;
|
||||
};
|
||||
}
|
114
include/IO/BaseWindow.h
Normal file
114
include/IO/BaseWindow.h
Normal file
@@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../Vec2.h"
|
||||
#include "../Rect.h"
|
||||
#include "HID/Input.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class WindowState : UInt_8
|
||||
{
|
||||
NONE,
|
||||
FULLSCREEN
|
||||
};
|
||||
|
||||
enum class CursorImg : UInt_8
|
||||
{
|
||||
DEFAULT,
|
||||
I_BEAM
|
||||
};
|
||||
|
||||
class BaseWindow
|
||||
{
|
||||
protected:
|
||||
bool created;
|
||||
bool focused;
|
||||
Vec2_s32 cursorPos;
|
||||
bool cursorVisible;
|
||||
bool cursorConstrained;
|
||||
WindowState state;
|
||||
InputHandler ih;
|
||||
|
||||
public:
|
||||
virtual ~BaseWindow() = default;
|
||||
|
||||
BaseWindow();
|
||||
|
||||
BaseWindow(const BaseWindow& win);
|
||||
|
||||
BaseWindow& operator=(const BaseWindow& win);
|
||||
|
||||
virtual void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) = 0;
|
||||
|
||||
virtual void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) = 0;
|
||||
|
||||
virtual void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) = 0;
|
||||
|
||||
virtual void OnCreated() = 0;
|
||||
|
||||
virtual void Close() = 0;
|
||||
|
||||
virtual void Show() = 0;
|
||||
|
||||
virtual void Hide() = 0;
|
||||
|
||||
bool IsCreated() const;
|
||||
|
||||
virtual bool Poll();
|
||||
|
||||
bool HasFocus() const;
|
||||
|
||||
void EnableResizing(const bool enable);
|
||||
|
||||
bool IsResizable() const;
|
||||
|
||||
/// Gets the cursors position on the desktop in pixels.
|
||||
/// @param [in] relative Whether the position should be relative to the windows client.
|
||||
/// @returns The current value.
|
||||
Vec2_s32 GetCursorPos() const;
|
||||
|
||||
/// Shows the cursor on the window.
|
||||
/// @param [in] toggle The new status.
|
||||
virtual void ShowCursor(bool toggle) = 0;
|
||||
|
||||
/// Checks whether the cursor is shown.
|
||||
/// @returns The current status.
|
||||
bool IsCursorVisible() const;
|
||||
|
||||
virtual void ConstrainCursor(const bool constrain) = 0;
|
||||
|
||||
bool IsCursorConstrained() const;
|
||||
|
||||
WindowState GetState() const;
|
||||
|
||||
const InputHandler* GetInputHandler() const;
|
||||
|
||||
virtual void SetTitle_32(const Str_32& newTitle) = 0;
|
||||
|
||||
virtual Str_32 GetTitle_32() const = 0;
|
||||
|
||||
virtual void SetTitle_16(const Str_16& newTitle) = 0;
|
||||
|
||||
virtual Str_16 GetTitle_16() const = 0;
|
||||
|
||||
virtual void SetTitle_8(const Str_8& newTitle) = 0;
|
||||
|
||||
virtual Str_8 GetTitle_8() const = 0;
|
||||
|
||||
virtual void SetPos(const Vec2_s32& newPos) = 0;
|
||||
|
||||
virtual Vec2_s32 GetPos() const = 0;
|
||||
|
||||
virtual void SetScale(const Vec2_u32& newScale) = 0;
|
||||
|
||||
virtual Vec2_u32 GetScale() const = 0;
|
||||
|
||||
virtual Serializer<UInt_64> GetClipboard() = 0;
|
||||
|
||||
virtual void SetClipboard(Serializer<UInt_64> data) = 0;
|
||||
|
||||
virtual void SetCursorImg(const CursorImg img) = 0;
|
||||
};
|
||||
}
|
55
include/IO/COM.h
Normal file
55
include/IO/COM.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class Parity : UInt_8
|
||||
{
|
||||
NONE,
|
||||
ODD,
|
||||
EVEN,
|
||||
MARK,
|
||||
SPACE
|
||||
};
|
||||
|
||||
enum class StopBits : UInt_8
|
||||
{
|
||||
ONE,
|
||||
ONE_POINT_FIVE,
|
||||
TWO
|
||||
};
|
||||
|
||||
class COM
|
||||
{
|
||||
private:
|
||||
UInt_8 port;
|
||||
UInt_32 baudRate;
|
||||
UInt_8 byteSize;
|
||||
Parity parity;
|
||||
StopBits stopBits;
|
||||
void* hdl;
|
||||
bool initialized;
|
||||
|
||||
public:
|
||||
COM();
|
||||
|
||||
COM(const UInt_8 port, const UInt_32 baudRate, const UInt_8 byteSize, const Parity parity, const StopBits stopBits);
|
||||
|
||||
COM(const COM& com) = default;
|
||||
|
||||
void Initialize();
|
||||
|
||||
void UnInitialize();
|
||||
|
||||
UInt_32 Wait();
|
||||
|
||||
void Transmit(const Char_8 data);
|
||||
|
||||
UInt_32 Send(const Char_8* data, const UInt_32 size);
|
||||
|
||||
UInt_32 Receive(const Char_8* data, const UInt_32 size);
|
||||
|
||||
void Flush();
|
||||
};
|
||||
}
|
115
include/IO/Console.h
Normal file
115
include/IO/Console.h
Normal file
@@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Str.h"
|
||||
#include "../UTF.h"
|
||||
#include "../Array.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
typedef void* ConsoleHdl;
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
typedef int ConsoleHdl;
|
||||
#endif
|
||||
|
||||
class Console
|
||||
{
|
||||
private:
|
||||
static ConsoleHdl hdlOut;
|
||||
static ConsoleHdl hdlIn;
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
static bool isConsole;
|
||||
#endif
|
||||
|
||||
public:
|
||||
static void Attach();
|
||||
|
||||
/// Creates a console using standard input and output.
|
||||
/// @param [in] inputRequired Whether or not input is required from the console.
|
||||
static bool Create();
|
||||
|
||||
/// Frees the current console being used.
|
||||
static void Free();
|
||||
|
||||
static bool CanRead();
|
||||
|
||||
static bool CanWrite();
|
||||
|
||||
/// Writes to console using UTF32.
|
||||
/// @param [in] str The text to write to the console.
|
||||
/// @param [in] newLine To make a new line after the given text.
|
||||
/// @warning Has to convert from UTF32 to UTF16 for the Windows API.
|
||||
static void Write_32(const Str_32& str, const bool newLine = true);
|
||||
|
||||
/// Writes to console using UTF16.
|
||||
/// @param [in] str The text to write to the console.
|
||||
/// @param [in] newLine To make a new line after the given text.
|
||||
static void Write_16(const Str_16& str, const bool newLine = true);
|
||||
|
||||
/// Writes to console using UTF8.
|
||||
/// @param [in] str The text to write to the console.
|
||||
/// @param [in] newLine To make a new line after the given text.
|
||||
/// @warning Has to convert from UTF8 to UTF16 for the Windows API.
|
||||
static void Write_8(const Str_8& str, const bool newLine = true);
|
||||
|
||||
/// Reads from the console using UTF32.
|
||||
/// @returns The text the user wrote to the console.
|
||||
/// @warning Has to convert from UTF16 to UTF32 for the Windows API.
|
||||
static Str_32 Read_32(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Reads from the console using UTF16.
|
||||
/// @returns The text the user wrote to the console.
|
||||
static Str_16 Read_16(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Reads from the console using UTF8.
|
||||
/// @returns The text the user wrote to the console.
|
||||
/// @warning Has to convert from UTF8 to UTF16 for the Windows API.
|
||||
static Str_8 Read_8(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Clears the console.
|
||||
static void Clear();
|
||||
|
||||
/// Changes the console's title.
|
||||
/// @param [in] title The text to change the title to.
|
||||
/// @warning Has to convert from UTF32 to UTF16 for the Windows API.
|
||||
static void SetTitle_32(const Str_32& title);
|
||||
|
||||
/// Changes the console's title.
|
||||
/// @param [in] title The text to change the title to.
|
||||
static void SetTitle_16(const Str_16& title);
|
||||
|
||||
/// Changes the console's title.
|
||||
/// @param [in] title The text to change the title to.
|
||||
/// @warning Has to convert from UTF8 to UTF16 for the Windows API.
|
||||
static void SetTitle_8(const Str_8& title);
|
||||
|
||||
/// Retrieves the console's title in UTF32.
|
||||
/// @returns The console's title.
|
||||
/// @warning Has to convert from UTF16 to UTF32 for the Windows API.
|
||||
static Str_32 GetTitle_32();
|
||||
|
||||
/// Retrieves the console's title in UTF16.
|
||||
/// @returns The console's title.
|
||||
static Str_16 GetTitle_16();
|
||||
|
||||
/// Retrieves the console's title in UTF8.
|
||||
/// @returns The console's title.
|
||||
/// @warning Has to convert from UTF16 to UTF8 for the Windows API.
|
||||
static Str_8 GetTitle_8();
|
||||
|
||||
/// Retrieves the string used when executing the end application through a command line interface in UTF32.
|
||||
/// @returns The result.
|
||||
static Vector<Str_32> GetArgs_32(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Retrieves the string used when executing the end application through a command line interface in UTF16.
|
||||
/// @returns The result.
|
||||
static Vector<Str_16> GetArgs_16(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Retrieves the string used when executing the end application through a command line interface in UTF8.
|
||||
/// @returns The result.
|
||||
static Vector<Str_8> GetArgs_8(const UInt_64 bufferSize = 1024);
|
||||
|
||||
//static void* GetHandle();
|
||||
};
|
||||
}
|
9
include/IO/File.h
Normal file
9
include/IO/File.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
#include "File_W32.h"
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
#include "File_UNX.h"
|
||||
#endif
|
7
include/IO/FileMonitor.h
Normal file
7
include/IO/FileMonitor.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
#include "FileMonitor_W32.h"
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
#include "FileMonitor_UNX.h"
|
||||
#endif
|
37
include/IO/FileMonitor_UNX.h
Normal file
37
include/IO/FileMonitor_UNX.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "BaseFileMonitor.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class FileMonitor : public BaseFileMonitor
|
||||
{
|
||||
private:
|
||||
int hdl;
|
||||
int wd;
|
||||
|
||||
public:
|
||||
~FileMonitor();
|
||||
|
||||
FileMonitor();
|
||||
|
||||
FileMonitor(Str_8 filePath);
|
||||
|
||||
FileMonitor(FileMonitor&& fm) noexcept;
|
||||
|
||||
FileMonitor(const FileMonitor& fm);
|
||||
|
||||
FileMonitor& operator=(FileMonitor&& fm) noexcept;
|
||||
|
||||
FileMonitor& operator=(const FileMonitor& fm);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
UInt_8 Poll() override;
|
||||
|
||||
bool IsInitialized() const override;
|
||||
};
|
||||
}
|
37
include/IO/FileMonitor_W32.h
Normal file
37
include/IO/FileMonitor_W32.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "BaseFileMonitor.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class FileMonitor final : public BaseFileMonitor
|
||||
{
|
||||
private:
|
||||
Handle hdl;
|
||||
FILETIME time;
|
||||
|
||||
public:
|
||||
~FileMonitor() override;
|
||||
|
||||
FileMonitor();
|
||||
|
||||
FileMonitor(Str_8 filePath);
|
||||
|
||||
FileMonitor(FileMonitor&& fm) noexcept;
|
||||
|
||||
FileMonitor(const FileMonitor& fm);
|
||||
|
||||
FileMonitor& operator=(FileMonitor&& fm) noexcept;
|
||||
|
||||
FileMonitor& operator=(const FileMonitor& fm);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
UInt_8 Poll() override;
|
||||
|
||||
bool IsInitialized() const override;
|
||||
};
|
||||
}
|
73
include/IO/File_UNX.h
Normal file
73
include/IO/File_UNX.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../UTF.h"
|
||||
#include "../Vector.h"
|
||||
#include "../Array.h"
|
||||
#include "../Serializer.h"
|
||||
#include "BaseFile.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class File : public BaseFile
|
||||
{
|
||||
private:
|
||||
int hdl;
|
||||
void* map;
|
||||
UInt_64 mapSize;
|
||||
|
||||
public:
|
||||
~File() override;
|
||||
|
||||
File();
|
||||
|
||||
File(const Str_8& filePath, const Mode mode, const Disposition disposition);
|
||||
|
||||
File(File&& file) noexcept;
|
||||
|
||||
File(const File& file);
|
||||
|
||||
File& operator=(File&& file) noexcept;
|
||||
|
||||
File& operator=(const File& file);
|
||||
|
||||
operator const Byte*() const override;
|
||||
|
||||
operator Byte*() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
bool IsMapped() const override;
|
||||
|
||||
UInt_64 MapSize() const override;
|
||||
|
||||
void Map(const UInt_64 offset, const UInt_64 size) override;
|
||||
|
||||
void Unmap() override;
|
||||
|
||||
void FlushMap() override;
|
||||
|
||||
UInt_64 Write(const Byte* const data, const UInt_64 size) override;
|
||||
|
||||
UInt_64 Read(Byte* const buffer, const UInt_64 size) override;
|
||||
|
||||
void Seek(UInt_64 index) override;
|
||||
|
||||
void SeekBeginning() override;
|
||||
|
||||
void SeekEnd() override;
|
||||
|
||||
void Truncate(const UInt_64 size) override;
|
||||
|
||||
UInt_64 Size() const override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
static void Rename_32(const Str_32& filePath, const Str_32& newName);
|
||||
|
||||
static void Rename_16(const Str_16& filePath, const Str_16& newName);
|
||||
|
||||
static void Rename_8(const Str_8& filePath, const Str_8& newName);
|
||||
};
|
||||
}
|
74
include/IO/File_W32.h
Normal file
74
include/IO/File_W32.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../UTF.h"
|
||||
#include "../Vector.h"
|
||||
#include "../Array.h"
|
||||
#include "../Serializer.h"
|
||||
#include "BaseFile.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class File : public BaseFile
|
||||
{
|
||||
private:
|
||||
HANDLE hdl;
|
||||
HANDLE map;
|
||||
Byte* view;
|
||||
UInt_64 viewSize;
|
||||
|
||||
public:
|
||||
~File() override;
|
||||
|
||||
File();
|
||||
|
||||
File(const Str_8& filePath, const Mode mode, const Disposition disposition);
|
||||
|
||||
File(File&& file) noexcept;
|
||||
|
||||
File(const File& file);
|
||||
|
||||
File& operator=(File&& file) noexcept;
|
||||
|
||||
File& operator=(const File& file);
|
||||
|
||||
operator const Byte*() const override;
|
||||
|
||||
operator Byte*() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
bool IsMapped() const override;
|
||||
|
||||
UInt_64 MapSize() const override;
|
||||
|
||||
void Map(const UInt_64 offset, const UInt_64 size) override;
|
||||
|
||||
void Unmap() override;
|
||||
|
||||
void FlushMap() override;
|
||||
|
||||
UInt_64 Write(const Byte* const data, const UInt_64 size) override;
|
||||
|
||||
UInt_64 Read(Byte* const buffer, const UInt_64 size) override;
|
||||
|
||||
void Seek(UInt_64 index) override;
|
||||
|
||||
void SeekBeginning() override;
|
||||
|
||||
void SeekEnd() override;
|
||||
|
||||
void Truncate(const UInt_64 size) override;
|
||||
|
||||
UInt_64 Size() const override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
static void Rename_32(const Str_32& filePath, const Str_32& newName);
|
||||
|
||||
static void Rename_16(const Str_16& filePath, const Str_16& newName);
|
||||
|
||||
static void Rename_8(const Str_8& filePath, const Str_8& newName);
|
||||
};
|
||||
}
|
48
include/IO/FontAtlas.h
Normal file
48
include/IO/FontAtlas.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Array.h"
|
||||
|
||||
#include "Glyph.h"
|
||||
#include "../Anchor.h"
|
||||
#include "Img/Img.h"
|
||||
#include "Model/Mesh.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class FontAtlas : public Img
|
||||
{
|
||||
private:
|
||||
UInt_64 glyphScale;
|
||||
Array<Glyph> glyphs;
|
||||
|
||||
public:
|
||||
FontAtlas();
|
||||
|
||||
FontAtlas(const Str_8& filePath);
|
||||
|
||||
FontAtlas(FontAtlas&& fa) noexcept;
|
||||
|
||||
FontAtlas(const FontAtlas& fa);
|
||||
|
||||
FontAtlas& operator=(FontAtlas&& fa) noexcept;
|
||||
|
||||
FontAtlas& operator=(const FontAtlas& fa);
|
||||
|
||||
UInt_64 GetGlyphScale() const;
|
||||
|
||||
Glyph GetGlyph(const Char_32 code) const;
|
||||
|
||||
Vec2_f CalculateSize(const Str_8& text) const;
|
||||
|
||||
float CalculateWidth(const Str_8& text) const;
|
||||
|
||||
float CalculateHeight(const Str_8& text) const;
|
||||
|
||||
UInt_64 CalculateIndexAtPoint(const Str_8& text, const Vec2_f& point) const;
|
||||
|
||||
Mesh Generate(const Anchor anchor, const Str_8& text) const;
|
||||
|
||||
FontAtlas* Clone() const override;
|
||||
};
|
||||
}
|
59
include/IO/Glyph.h
Normal file
59
include/IO/Glyph.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Vec2.h"
|
||||
#include "../Rect.h"
|
||||
#include "../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Glyph
|
||||
{
|
||||
private:
|
||||
Char_32 code;
|
||||
Vec2_u64 pos;
|
||||
Vec2_u64 scale;
|
||||
Rect_f uv;
|
||||
Vec2_64 bearing;
|
||||
Vec2_64 advance;
|
||||
|
||||
public:
|
||||
Glyph();
|
||||
|
||||
Glyph(Serializer<>& ser);
|
||||
|
||||
Glyph(const Char_32 code);
|
||||
|
||||
Glyph(const Glyph& glyph);
|
||||
|
||||
Glyph& operator=(const Glyph& glyph);
|
||||
|
||||
bool operator==(const Glyph& glyph) const;
|
||||
|
||||
bool operator!=(const Glyph& glyph) const;
|
||||
|
||||
Char_32 GetCode() const;
|
||||
|
||||
void SetPos(const Vec2_u64& newPos);
|
||||
|
||||
Vec2_u64 GetPos() const;
|
||||
|
||||
void SetScale(const Vec2_u64& newScale);
|
||||
|
||||
Vec2_u64 GetScale() const;
|
||||
|
||||
void SetUV(const Rect_f& newUV);
|
||||
|
||||
Rect_f GetUV() const;
|
||||
|
||||
void SetBearing(const Vec2_64& newBearing);
|
||||
|
||||
Vec2_32 GetBearing() const;
|
||||
|
||||
void SetAdvance(const Vec2_64& newAdvance);
|
||||
|
||||
Vec2_32 GetAdvance() const;
|
||||
|
||||
void Serialize(Serializer<>& ser) const;
|
||||
};
|
||||
}
|
31
include/IO/HID/Button.h
Normal file
31
include/IO/HID/Button.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Button
|
||||
{
|
||||
private:
|
||||
Str_8 name;
|
||||
UInt_32 hash;
|
||||
|
||||
public:
|
||||
Button();
|
||||
|
||||
Button(const Str_8& name);
|
||||
|
||||
Button(const Button& key);
|
||||
|
||||
Button& operator=(const Button& key);
|
||||
|
||||
bool operator==(const Button& key) const;
|
||||
|
||||
bool operator!=(const Button& key) const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
UInt_32 GetHash() const;
|
||||
};
|
||||
}
|
55
include/IO/HID/ButtonState.h
Normal file
55
include/IO/HID/ButtonState.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "Button.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class State
|
||||
{
|
||||
JUST_RELEASED,
|
||||
RELEASED,
|
||||
PRESSED,
|
||||
TOUCHED
|
||||
};
|
||||
|
||||
class ButtonState
|
||||
{
|
||||
private:
|
||||
Button button;
|
||||
State state;
|
||||
bool pressed;
|
||||
float threshold;
|
||||
|
||||
public:
|
||||
ButtonState();
|
||||
|
||||
ButtonState(const Button& button, const State state);
|
||||
|
||||
ButtonState(const ButtonState& bs);
|
||||
|
||||
ButtonState& operator=(const ButtonState& bs);
|
||||
|
||||
bool operator==(const Button& other) const;
|
||||
|
||||
bool operator!=(const Button& other) const;
|
||||
|
||||
bool operator==(const State otherState) const;
|
||||
|
||||
bool operator!=(const State otherState) const;
|
||||
|
||||
Button GetButton() const;
|
||||
|
||||
void SetState(State newState);
|
||||
|
||||
State GetState() const;
|
||||
|
||||
void SetPressed(bool value);
|
||||
|
||||
bool IsPressed() const;
|
||||
|
||||
void SetThreshold(const float newThreshold);
|
||||
|
||||
float GetThreshold() const;
|
||||
};
|
||||
}
|
91
include/IO/HID/HID.h
Normal file
91
include/IO/HID/HID.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Array.h"
|
||||
#include "ButtonState.h"
|
||||
|
||||
#define LWE_HID_UNKNOWN 0
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class HID
|
||||
{
|
||||
protected:
|
||||
UInt_8 type;
|
||||
UInt_64 hashName;
|
||||
Str_8 name;
|
||||
UInt_64 id;
|
||||
Array<ButtonState> states;
|
||||
|
||||
public:
|
||||
HID();
|
||||
|
||||
HID(const UInt_8 type, Str_8 name, const UInt_64 id);
|
||||
|
||||
HID(HID&& hid) noexcept;
|
||||
|
||||
HID(const HID& hid);
|
||||
|
||||
HID& operator=(HID&& hid) noexcept;
|
||||
|
||||
HID& operator=(const HID& hid);
|
||||
|
||||
bool operator==(const HID& other) const;
|
||||
|
||||
bool operator!=(const HID& other) const;
|
||||
|
||||
bool operator==(const UInt_64 otherId) const;
|
||||
|
||||
bool operator!=(const UInt_64 otherId) const;
|
||||
|
||||
virtual void Poll();
|
||||
|
||||
UInt_8 GetType() const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
UInt_64 GetId() const;
|
||||
|
||||
void ReleaseAll();
|
||||
|
||||
Vector<const ButtonState*> GetAllTouched() const;
|
||||
|
||||
const ButtonState* IsTouched(const Button& button) const;
|
||||
|
||||
const ButtonState* IsTouched() const;
|
||||
|
||||
Vector<const ButtonState*> GetAllDown() const;
|
||||
|
||||
const ButtonState* IsDown(const Button& button) const;
|
||||
|
||||
const ButtonState* IsDown() const;
|
||||
|
||||
Vector<const ButtonState*> GetAllJustReleased() const;
|
||||
|
||||
const ButtonState* IsJustReleased(const Button& button) const;
|
||||
|
||||
const ButtonState* IsJustReleased() const;
|
||||
|
||||
Vector<const ButtonState*> GetAllUp() const;
|
||||
|
||||
const ButtonState* IsUp(const Button& button) const;
|
||||
|
||||
const ButtonState* IsUp() const;
|
||||
|
||||
void ButtonDown(const Button& button);
|
||||
|
||||
void ButtonUp(const Button& button);
|
||||
|
||||
const ButtonState* GetState(const Button& button) const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
virtual HID* Clone() const;
|
||||
|
||||
private:
|
||||
bool HasState(const Button& button) const;
|
||||
|
||||
bool AddState(const ButtonState& state);
|
||||
|
||||
ButtonState* GetState(const Button& button);
|
||||
};
|
||||
}
|
46
include/IO/HID/Input.h
Normal file
46
include/IO/HID/Input.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Array.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "InputHandler.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Input
|
||||
{
|
||||
private:
|
||||
Array<InputHandler*> handlers;
|
||||
bool initalized;
|
||||
|
||||
public:
|
||||
~Input();
|
||||
|
||||
Input();
|
||||
|
||||
Input(Input&& input) noexcept;
|
||||
|
||||
Input(const Input& input);
|
||||
|
||||
Input& operator=(Input&& input) noexcept;
|
||||
|
||||
Input& operator=(const Input& input);
|
||||
|
||||
void Initialize();
|
||||
|
||||
void Release();
|
||||
|
||||
void Poll();
|
||||
|
||||
bool HasHandler(const UInt_64 hashId) const;
|
||||
|
||||
bool HasHandler(const Str_8& id) const;
|
||||
|
||||
bool AddHandler(InputHandler* handler);
|
||||
|
||||
const InputHandler* GetHandler(const UInt_64 hashId) const;
|
||||
|
||||
const InputHandler* GetHandler(const Str_8& id) const;
|
||||
|
||||
bool IsInitialized() const;
|
||||
};
|
||||
}
|
58
include/IO/HID/InputHandler.h
Normal file
58
include/IO/HID/InputHandler.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Array.h"
|
||||
#include "HID.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class InputHandler
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
|
||||
protected:
|
||||
Array<HID*> devices;
|
||||
|
||||
public:
|
||||
virtual ~InputHandler();
|
||||
|
||||
InputHandler();
|
||||
|
||||
InputHandler(Str_8 id);
|
||||
|
||||
InputHandler(InputHandler&& ih) noexcept;
|
||||
|
||||
InputHandler(const InputHandler& ih);
|
||||
|
||||
InputHandler& operator=(InputHandler&& ih) noexcept;
|
||||
|
||||
InputHandler& operator=(const InputHandler& ih);
|
||||
|
||||
bool operator==(const UInt_64 otherHashId);
|
||||
|
||||
bool operator!=(const UInt_64 otherHashId);
|
||||
|
||||
virtual bool Initialize();
|
||||
|
||||
virtual bool Release();
|
||||
|
||||
virtual void Poll();
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
void ResetAllStates();
|
||||
|
||||
bool HasDevice(const UInt_64 id) const;
|
||||
|
||||
bool AddDevice(HID* device);
|
||||
|
||||
HID* GetDevice(const UInt_64 id) const;
|
||||
|
||||
HID* GetDeviceByType(const UInt_8 type) const;
|
||||
|
||||
virtual bool IsInitialized() const;
|
||||
};
|
||||
}
|
121
include/IO/HID/Keyboard.h
Normal file
121
include/IO/HID/Keyboard.h
Normal file
@@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Types.h"
|
||||
#include "Button.h"
|
||||
#include "HID.h"
|
||||
|
||||
#define LWE_HID_KEYBOARD 0x02
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Keyboard : public HID
|
||||
{
|
||||
public:
|
||||
Keyboard();
|
||||
|
||||
Keyboard(Str_8 name, const UInt_64 id);
|
||||
|
||||
Keyboard(Keyboard&& hid) noexcept = default;
|
||||
|
||||
Keyboard(const Keyboard& hid);
|
||||
|
||||
Keyboard& operator=(Keyboard&& hid) noexcept = default;
|
||||
|
||||
Keyboard& operator=(const Keyboard& hid);
|
||||
|
||||
void Poll() override;
|
||||
|
||||
Keyboard* Clone() const override;
|
||||
|
||||
static const Button Unknown;
|
||||
static const Button Escape;
|
||||
static const Button Backspace;
|
||||
static const Button Enter;
|
||||
static const Button LShift;
|
||||
static const Button RShift;
|
||||
static const Button LAlt;
|
||||
static const Button RAlt;
|
||||
static const Button LCtrl;
|
||||
static const Button RCtrl;
|
||||
static const Button Space;
|
||||
static const Button A;
|
||||
static const Button B;
|
||||
static const Button C;
|
||||
static const Button D;
|
||||
static const Button E;
|
||||
static const Button F;
|
||||
static const Button G;
|
||||
static const Button H;
|
||||
static const Button I;
|
||||
static const Button J;
|
||||
static const Button K;
|
||||
static const Button L;
|
||||
static const Button M;
|
||||
static const Button N;
|
||||
static const Button O;
|
||||
static const Button P;
|
||||
static const Button Q;
|
||||
static const Button R;
|
||||
static const Button S;
|
||||
static const Button T;
|
||||
static const Button U;
|
||||
static const Button V;
|
||||
static const Button W;
|
||||
static const Button X;
|
||||
static const Button Y;
|
||||
static const Button Z;
|
||||
static const Button One;
|
||||
static const Button Two;
|
||||
static const Button Three;
|
||||
static const Button Four;
|
||||
static const Button Five;
|
||||
static const Button Six;
|
||||
static const Button Seven;
|
||||
static const Button Eight;
|
||||
static const Button Nine;
|
||||
static const Button Zero;
|
||||
static const Button Minus;
|
||||
static const Button Equals;
|
||||
static const Button Tilde;
|
||||
static const Button BackSlash;
|
||||
static const Button LeftSquareBracket;
|
||||
static const Button RightSquareBracket;
|
||||
static const Button SemiColon;
|
||||
static const Button Apostrophe;
|
||||
static const Button Comma;
|
||||
static const Button Period;
|
||||
static const Button ForwardSlash;
|
||||
static const Button F1;
|
||||
static const Button F2;
|
||||
static const Button F3;
|
||||
static const Button F4;
|
||||
static const Button F5;
|
||||
static const Button F6;
|
||||
static const Button F7;
|
||||
static const Button F8;
|
||||
static const Button F9;
|
||||
static const Button F10;
|
||||
static const Button F11;
|
||||
static const Button F12;
|
||||
static const Button F13;
|
||||
static const Button F14;
|
||||
static const Button F15;
|
||||
static const Button F16;
|
||||
static const Button F17;
|
||||
static const Button F18;
|
||||
static const Button F19;
|
||||
static const Button F20;
|
||||
static const Button F21;
|
||||
static const Button F22;
|
||||
static const Button F23;
|
||||
static const Button F24;
|
||||
static const Button Left;
|
||||
static const Button Right;
|
||||
static const Button Up;
|
||||
static const Button Down;
|
||||
|
||||
static Button TranslateScanCode(const UInt_32 code);
|
||||
|
||||
static Char_8 TranslateToEnglish_8(const bool shifted, const Button& button);
|
||||
};
|
||||
}
|
55
include/IO/HID/Mouse.h
Normal file
55
include/IO/HID/Mouse.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Types.h"
|
||||
#include "../../Vec2.h"
|
||||
#include "Button.h"
|
||||
#include "HID.h"
|
||||
|
||||
#define LWE_HID_MOUSE 0x01
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Mouse : public HID
|
||||
{
|
||||
private:
|
||||
friend class Input;
|
||||
|
||||
Vec2_s32 delta;
|
||||
|
||||
public:
|
||||
Mouse();
|
||||
|
||||
Mouse(Str_8 name, const UInt_64 id);
|
||||
|
||||
Mouse(Mouse&& hid) noexcept = default;
|
||||
|
||||
Mouse(const Mouse& hid);
|
||||
|
||||
Mouse& operator=(Mouse&& hid) noexcept = default;
|
||||
|
||||
Mouse& operator=(const Mouse& hid);
|
||||
|
||||
void Poll() override;
|
||||
|
||||
void SetDelta(const Vec2_s32& newDelta);
|
||||
|
||||
Vec2_s32 GetDelta() const;
|
||||
|
||||
Mouse* Clone() const override;
|
||||
|
||||
static const Button Unknown;
|
||||
static const Button LMB;
|
||||
static const Button MMB;
|
||||
static const Button RMB;
|
||||
static const Button Four;
|
||||
static const Button Five;
|
||||
static const Button ScrollUp;
|
||||
static const Button ScrollDown;
|
||||
static const Button ScrollLeft;
|
||||
static const Button ScrollRight;
|
||||
static const Button Back;
|
||||
static const Button Forward;
|
||||
|
||||
static Button TranslateXCB(const UInt_32 code);
|
||||
};
|
||||
}
|
178
include/IO/Img/Img.h
Normal file
178
include/IO/Img/Img.h
Normal file
@@ -0,0 +1,178 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "ImgCodec.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class Resampling : UInt_8
|
||||
{
|
||||
NONE,
|
||||
NEAREST_NEIGHBOR
|
||||
};
|
||||
|
||||
class Img
|
||||
{
|
||||
private:
|
||||
static Array<ImgCodec> codecs;
|
||||
|
||||
protected:
|
||||
UInt_8 bitDepth;
|
||||
UInt_8 channels;
|
||||
UInt_64 width;
|
||||
UInt_64 height;
|
||||
UInt_64 size;
|
||||
Byte* data;
|
||||
|
||||
public:
|
||||
static bool HasCodec(UInt_64 hashExt);
|
||||
|
||||
static bool HasCodec(const Str_8& ext);
|
||||
|
||||
static bool AddCodec(ImgCodec codec);
|
||||
|
||||
static const ImgCodec* GetCodec(UInt_64 hashExt);
|
||||
|
||||
static const ImgCodec* GetCodec(const Str_8& ext);
|
||||
|
||||
~Img();
|
||||
|
||||
Img();
|
||||
|
||||
Img(UInt_8 bitDepth, UInt_8 channels, UInt_64 width, UInt_64 height, const Byte* data);
|
||||
|
||||
Img(UInt_8 bitDepth, UInt_8 channels, UInt_64 width, UInt_64 height);
|
||||
|
||||
Img(Img&& img) noexcept;
|
||||
|
||||
Img(const Img& img);
|
||||
|
||||
Img& operator=(Img&& img) noexcept;
|
||||
|
||||
Img& operator=(const Img& img);
|
||||
|
||||
operator const Byte* () const;
|
||||
|
||||
operator Byte* ();
|
||||
|
||||
void Release();
|
||||
|
||||
UInt_8 BitDepth() const;
|
||||
|
||||
UInt_8 Channels() const;
|
||||
|
||||
UInt_64 Width() const;
|
||||
|
||||
UInt_64 Height() const;
|
||||
|
||||
UInt_64 Size() const;
|
||||
|
||||
void SetPixel(UInt_64 index, const Byte* pixel);
|
||||
|
||||
void GetPixel(UInt_64 index, Byte* pixel) const;
|
||||
|
||||
void SetPixel(UInt_64 x, UInt_64 y, const Byte* pixel);
|
||||
|
||||
void GetPixel(UInt_64 x, UInt_64 y, Byte* pixel) const;
|
||||
|
||||
void Resize(Resampling method, UInt_64 newWidth, UInt_64 newHeight);
|
||||
|
||||
Img GetResized(Resampling method, UInt_64 newWidth, UInt_64 newHeight) const;
|
||||
|
||||
void ToRGBA();
|
||||
|
||||
Img GetAsRGBA() const;
|
||||
|
||||
void ToRGB();
|
||||
|
||||
Img GetAsRGB() const;
|
||||
|
||||
void ToMonoA();
|
||||
|
||||
Img GetAsMonoA() const;
|
||||
|
||||
void ToMono();
|
||||
|
||||
Img GetAsMono() const;
|
||||
|
||||
void To32();
|
||||
|
||||
Img GetAs32() const;
|
||||
|
||||
void To24();
|
||||
|
||||
Img GetAs24() const;
|
||||
|
||||
void To16();
|
||||
|
||||
Img GetAs16() const;
|
||||
|
||||
void To8();
|
||||
|
||||
Img GetAs8() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool ToFile(const Str_8& filePath) const;
|
||||
|
||||
static Img FromFile(const Str_8& filePath);
|
||||
|
||||
static Img* FromFile_Heap(const Str_8& filePath);
|
||||
|
||||
static Img FromData(const Str_8& ext, Serializer<UInt_64>& data);
|
||||
|
||||
private:
|
||||
Img GetNearestNeighbor(UInt_64 newWidth, UInt_64 newHeight) const;
|
||||
|
||||
void NearestNeighbor(UInt_64 newWidth, UInt_64 newHeight);
|
||||
|
||||
void RGB_To_RGBA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void MonoA_To_RGBA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void Mono_To_RGBA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGBA_To_RGB(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void MonoA_To_RGB(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void Mono_To_RGB(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGBA_To_MonoA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGB_To_MonoA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void Mono_To_MonoA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGBA_To_Mono(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGB_To_Mono(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void MonoA_To_Mono(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD24_to_BD32(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD16_to_BD32(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD8_to_BD32(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD32_to_BD24(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD16_to_BD24(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD8_to_BD24(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD32_to_BD16(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD24_to_BD16(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD8_to_BD16(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD32_to_BD8(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD24_to_BD8(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD16_to_BD8(UInt_64 newSize, Byte* buffer) const;
|
||||
};
|
||||
}
|
48
include/IO/Img/ImgCodec.h
Normal file
48
include/IO/Img/ImgCodec.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../File.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Img;
|
||||
|
||||
class ImgCodec
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashExt;
|
||||
Str_8 ext;
|
||||
Endianness endianness;
|
||||
bool (*encodeCb)(const ImgCodec* const, Serializer<UInt_64>&, const Img*);
|
||||
bool (*decodeCb)(const ImgCodec* const, Serializer<UInt_64>&, Img*);
|
||||
|
||||
public:
|
||||
ImgCodec();
|
||||
|
||||
ImgCodec(Str_8 id, Str_8 ext, const Endianness end,
|
||||
bool (*encodeCb)(const ImgCodec* const, Serializer<UInt_64>&, const Img*),
|
||||
bool (*decodeCb)(const ImgCodec* const, Serializer<UInt_64>&, Img*));
|
||||
|
||||
ImgCodec(ImgCodec&& codec) noexcept;
|
||||
|
||||
ImgCodec(const ImgCodec& codec);
|
||||
|
||||
ImgCodec& operator=(ImgCodec&& codec) noexcept;
|
||||
|
||||
ImgCodec& operator=(const ImgCodec& codec);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashExt() const;
|
||||
|
||||
Str_8 GetExt() const;
|
||||
|
||||
Endianness GetEndianness() const;
|
||||
|
||||
bool Encode(Serializer<UInt_64>& out, const Img* in) const;
|
||||
|
||||
bool Decode(Serializer<UInt_64>& in, Img* out) const;
|
||||
};
|
||||
}
|
51
include/IO/Img/PNG.h
Normal file
51
include/IO/Img/PNG.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "PNG_Chunk.h"
|
||||
#include "Img.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class PNG
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
Array<PNG_Chunk> chunks;
|
||||
|
||||
public:
|
||||
PNG();
|
||||
|
||||
PNG(const Str_8& filePath);
|
||||
|
||||
PNG(const Str_8& id, Serializer<UInt_64>& data);
|
||||
|
||||
PNG(const PNG& png);
|
||||
|
||||
PNG& operator=(const PNG& png);
|
||||
|
||||
bool HasChunk(const UInt_64 hashId) const;
|
||||
|
||||
bool HasChunk(const Str_8& id) const;
|
||||
|
||||
PNG_Chunk* GetChunk(const UInt_64 hashId);
|
||||
|
||||
PNG_Chunk* GetChunk(const Str_8& id);
|
||||
|
||||
static bool IsPNG(Serializer<UInt_32>& data);
|
||||
|
||||
static void FilterNone(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
static void FilterSub(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
static void FilterUp(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
static void FilterAverage(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
static void FilterPaeth(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
private:
|
||||
static Byte PaethPredictor(const Byte a, const Byte b, const Byte c);
|
||||
};
|
||||
}
|
34
include/IO/Img/PNG_Chunk.h
Normal file
34
include/IO/Img/PNG_Chunk.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class PNG_Chunk
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
Serializer<UInt_64> data;
|
||||
Byte crc[4];
|
||||
|
||||
public:
|
||||
PNG_Chunk();
|
||||
|
||||
PNG_Chunk(const Str_8& id, const Serializer<UInt_64>& data, const Byte crc[4]);
|
||||
|
||||
PNG_Chunk(const PNG_Chunk& chunk);
|
||||
|
||||
PNG_Chunk& operator=(const PNG_Chunk& chunk);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Serializer<UInt_64>* GetData();
|
||||
|
||||
const unsigned char* GetCRC() const;
|
||||
};
|
||||
}
|
40
include/IO/Model/AnimBone.h
Normal file
40
include/IO/Model/AnimBone.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "KeyFrame.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class AnimBone
|
||||
{
|
||||
private:
|
||||
UInt_8 boneId;
|
||||
Array<KeyFrame> keyFrames;
|
||||
|
||||
public:
|
||||
AnimBone();
|
||||
|
||||
AnimBone(const UInt_8 boneId);
|
||||
|
||||
AnimBone(const UInt_8 boneId, const UInt_64 size);
|
||||
|
||||
AnimBone(const UInt_8 boneId, Array<KeyFrame> keyFrames);
|
||||
|
||||
AnimBone(AnimBone&& anim) noexcept;
|
||||
|
||||
AnimBone(const AnimBone& anim);
|
||||
|
||||
AnimBone& operator=(AnimBone&& anim) noexcept;
|
||||
|
||||
AnimBone& operator=(const AnimBone& anim);
|
||||
|
||||
UInt_8 GetBoneId() const;
|
||||
|
||||
Array<KeyFrame> GetKeyFrames() const;
|
||||
|
||||
Array<KeyFrame>& GetKeyFrames();
|
||||
|
||||
float GetPrevAndNext(KeyFrame& prev, KeyFrame& next, const float elapsed) const;
|
||||
};
|
||||
}
|
49
include/IO/Model/Animation.h
Normal file
49
include/IO/Model/Animation.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Array.h"
|
||||
#include "AnimBone.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Animation
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
float duration;
|
||||
Array<AnimBone> animated;
|
||||
|
||||
public:
|
||||
Animation();
|
||||
|
||||
Animation(Str_8 id, const float duration);
|
||||
|
||||
Animation(Str_8 id, const float duration, UInt_64 size);
|
||||
|
||||
Animation(Str_8 id, const float duration, Array<AnimBone> animated);
|
||||
|
||||
Animation(Animation&& anim) noexcept;
|
||||
|
||||
Animation(const Animation& anim);
|
||||
|
||||
Animation& operator=(Animation&& anim) noexcept;
|
||||
|
||||
Animation& operator=(const Animation& anim);
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
float GetDuration() const;
|
||||
|
||||
Array<AnimBone> GetAnimated() const;
|
||||
|
||||
Array<AnimBone>& GetAnimated();
|
||||
|
||||
Array<Mat4_f> Interpolate(const UInt_64 boneCount, const float elapsed) const;
|
||||
};
|
||||
}
|
73
include/IO/Model/Bone.h
Normal file
73
include/IO/Model/Bone.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Quat.h"
|
||||
#include "../../Mat4.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Bone
|
||||
{
|
||||
private:
|
||||
UInt_64 hashName;
|
||||
Str_8 name;
|
||||
UInt_8 id;
|
||||
Mat4_f animTrans;
|
||||
Mat4_f localBindTrans;
|
||||
Mat4_f invBindTrans;
|
||||
Array<Bone> children;
|
||||
|
||||
public:
|
||||
Bone();
|
||||
|
||||
Bone(Str_8 name, const UInt_8 id, const Mat4_f& localBindTrans, const Mat4_f& invBindTrans);
|
||||
|
||||
Bone(Bone&& bone) noexcept;
|
||||
|
||||
Bone(const Bone& bone);
|
||||
|
||||
Bone& operator=(Bone&& bone) noexcept;
|
||||
|
||||
Bone& operator=(const Bone& bone);
|
||||
|
||||
UInt_64 GetHashName() const;
|
||||
|
||||
void SetName(Str_8 newId);
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
UInt_8 GetId() const;
|
||||
|
||||
void SetAnimTrans(const Mat4_f& newTrans);
|
||||
|
||||
Mat4_f GetAnimTrans() const;
|
||||
|
||||
void GetAnimTransRec(Array<Mat4_f>& output) const;
|
||||
|
||||
Mat4_f GetLocalBindTrans() const;
|
||||
|
||||
Mat4_f GetInvBindTrans() const;
|
||||
|
||||
UInt_8 GetBoneCount() const;
|
||||
|
||||
bool HasBone(const UInt_64 hashName, const UInt_8 id) const;
|
||||
|
||||
bool HasBone(const UInt_64 hashName) const;
|
||||
|
||||
bool HasBone(const UInt_8 id) const;
|
||||
|
||||
bool AddBone(Bone child);
|
||||
|
||||
const Bone* GetBone(const UInt_64 hashName) const;
|
||||
|
||||
Bone* GetBone(const UInt_64 hashName);
|
||||
|
||||
const Bone* GetBone(const UInt_8 id) const;
|
||||
|
||||
Bone* GetBone(const UInt_8 id);
|
||||
|
||||
const Array<Bone>& GetChildren() const;
|
||||
|
||||
Array<Bone>& GetChildren();
|
||||
};
|
||||
}
|
55
include/IO/Model/KeyFrame.h
Normal file
55
include/IO/Model/KeyFrame.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "../../Vec3.h"
|
||||
#include "../../Quat.h"
|
||||
#include "../../Mat4.h"
|
||||
#include "PropertyChange.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class KeyFrame
|
||||
{
|
||||
private:
|
||||
float num;
|
||||
float timeStamp;
|
||||
Vec3_f pos;
|
||||
Quat_f rot;
|
||||
Vec3_f scale;
|
||||
Mat4_f trans;
|
||||
|
||||
public:
|
||||
KeyFrame();
|
||||
|
||||
KeyFrame(const float num, const float timeStamp, const Vec3_f& pos, const Quat_f& rot, const Vec3_f& scale);
|
||||
|
||||
KeyFrame(const float num, const float timeStamp);
|
||||
|
||||
KeyFrame(const KeyFrame& kf);
|
||||
|
||||
KeyFrame& operator=(const KeyFrame& kf);
|
||||
|
||||
float GetNum() const;
|
||||
|
||||
float GetTimeStamp() const;
|
||||
|
||||
void SetPos(const Vec3_f& newPos);
|
||||
|
||||
Vec3_f GetPos() const;
|
||||
|
||||
void SetRot(const Quat_f& newRot);
|
||||
|
||||
Quat_f GetRot() const;
|
||||
|
||||
void SetScale(const Vec3_f& newScale);
|
||||
|
||||
Vec3_f GetScale() const;
|
||||
|
||||
void CalculateTransform();
|
||||
|
||||
Mat4_f GetTrans() const;
|
||||
|
||||
static Mat4_f Interpolate(const KeyFrame& prev, const KeyFrame& next, const float percentage);
|
||||
};
|
||||
}
|
101
include/IO/Model/Mesh.h
Normal file
101
include/IO/Model/Mesh.h
Normal file
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "Vertex.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
const Array<Vertex_f> portraitGuiVerts({
|
||||
{{0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}},
|
||||
{{0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}},
|
||||
{{1.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}},
|
||||
{{1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}}
|
||||
});
|
||||
|
||||
const Array<UInt_32> portraitGuiIndices({
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
1
|
||||
});
|
||||
|
||||
const Array<Vertex_f> portraitVerts({
|
||||
{{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}},
|
||||
{{-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}},
|
||||
{{0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}},
|
||||
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}}
|
||||
});
|
||||
|
||||
const Array<UInt_32> portraitIndices({
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
1
|
||||
});
|
||||
|
||||
class Mesh : public Resource
|
||||
{
|
||||
protected:
|
||||
Array<Vertex_f> vertices;
|
||||
Array<UInt_32> indices;
|
||||
GpuBuffer srcVertBuffer;
|
||||
GpuBuffer dstVertBuffer;
|
||||
GpuBuffer srcIndBuffer;
|
||||
GpuBuffer dstIndBuffer;
|
||||
|
||||
public:
|
||||
Mesh();
|
||||
|
||||
Mesh(Str_8 id, Array<Vertex_f> vertices, Array<UInt_32> indices);
|
||||
|
||||
Mesh(Str_8 id, Array<Vertex_f> vertices);
|
||||
|
||||
Mesh(Str_8 id);
|
||||
|
||||
Mesh(Mesh&& mesh) noexcept;
|
||||
|
||||
Mesh(const Mesh& mesh);
|
||||
|
||||
Mesh& operator=(Mesh&& mesh) noexcept;
|
||||
|
||||
Mesh& operator=(const Mesh& mesh);
|
||||
|
||||
bool UploadToGpu(GpuCmdBuffer* cmdBuffer) override;
|
||||
|
||||
bool PostGpuUpload() override;
|
||||
|
||||
bool HasPostGpuUploaded() const override;
|
||||
|
||||
bool ReleaseFromGpu() override;
|
||||
|
||||
bool IsUploaded() const override;
|
||||
|
||||
void Bind(GpuCmdBuffer* cmdBuffer);
|
||||
|
||||
void Draw(GpuCmdBuffer* cmdBuffer, const UInt_32 instances = 1);
|
||||
|
||||
void SetVertices(const Array<Vertex_f>& newVertices);
|
||||
|
||||
Array<Vertex_f> GetVertices() const;
|
||||
|
||||
Array<Vertex_f>& GetVertices();
|
||||
|
||||
void SetIndices(const Array<UInt_32>& newIndices);
|
||||
|
||||
bool HasIndices() const;
|
||||
|
||||
Array<UInt_32> GetIndices() const;
|
||||
|
||||
Array<UInt_32>& GetIndices();
|
||||
|
||||
void Calculate();
|
||||
|
||||
private:
|
||||
static void Calculate(Vertex_f& vert1, Vertex_f& vert2, Vertex_f& vert3);
|
||||
};
|
||||
}
|
80
include/IO/Model/Model.h
Normal file
80
include/IO/Model/Model.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "../File.h"
|
||||
#include "Mesh.h"
|
||||
#include "Bone.h"
|
||||
#include "Animation.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class ModelEncoding : UInt_8
|
||||
{
|
||||
EHM
|
||||
};
|
||||
|
||||
class Model : public Resource
|
||||
{
|
||||
protected:
|
||||
Array<Mesh> meshes;
|
||||
Bone skeleton;
|
||||
Array<Animation> animations;
|
||||
|
||||
public:
|
||||
Model();
|
||||
|
||||
Model(const Str_8& filePath);
|
||||
|
||||
Model(Str_8 id, Array<Mesh> meshes, Bone skeleton, Array<Animation> animations);
|
||||
|
||||
Model(Str_8 id, Array<Mesh> meshes, Bone skeleton);
|
||||
|
||||
Model(Str_8 id, Array<Mesh> meshes);
|
||||
|
||||
Model(Model&& model) noexcept;
|
||||
|
||||
Model(const Model& model) = default;
|
||||
|
||||
Model& operator=(Model&& model) noexcept;
|
||||
|
||||
Model& operator=(const Model& model) = default;
|
||||
|
||||
bool UploadToGpu(GpuCmdBuffer* cmdBuffer) override;
|
||||
|
||||
bool PostGpuUpload() override;
|
||||
|
||||
bool ReleaseFromGpu() override;
|
||||
|
||||
bool IsUploaded() const override;
|
||||
|
||||
void Draw(GpuCmdBuffer* cmdBuffer, const UInt_32 instances = 1);
|
||||
|
||||
Array<Mesh> GetMeshes() const;
|
||||
|
||||
Array<Mesh>& GetMeshes();
|
||||
|
||||
Mesh* GetMesh(const UInt_64 hashId);
|
||||
|
||||
Mesh* GetMesh(const Str_8& id);
|
||||
|
||||
Bone GetSkeleton() const;
|
||||
|
||||
Bone& GetSkeleton();
|
||||
|
||||
Animation* GetAnimation(const UInt_64 hashId);
|
||||
|
||||
Array<Animation> GetAnimations() const;
|
||||
|
||||
Array<Animation>& GetAnimations();
|
||||
|
||||
void Calculate();
|
||||
|
||||
void Export(const Str_8& filePath, const ModelEncoding encoding);
|
||||
|
||||
private:
|
||||
void ToEHM(File& file);
|
||||
|
||||
void FromEHM(File& file);
|
||||
};
|
||||
}
|
32
include/IO/Model/PropertyChange.h
Normal file
32
include/IO/Model/PropertyChange.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class ChangeType : UInt_8
|
||||
{
|
||||
X_AXIS_POS,
|
||||
Y_AXIS_POS,
|
||||
Z_AXIS_POS,
|
||||
X_AXIS_SCALE,
|
||||
Y_AXIS_SCALE,
|
||||
Z_AXIS_SCALE,
|
||||
X_AXIS_ROT,
|
||||
Y_AXIS_ROT,
|
||||
Z_AXIS_ROT,
|
||||
W_AXIS_ROT,
|
||||
INVALID
|
||||
};
|
||||
|
||||
class PropertyChange
|
||||
{
|
||||
public:
|
||||
ChangeType type;
|
||||
float value;
|
||||
|
||||
PropertyChange();
|
||||
|
||||
PropertyChange(const ChangeType type, const float value);
|
||||
};
|
||||
}
|
49
include/IO/Model/Vertex.h
Normal file
49
include/IO/Model/Vertex.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Vec3.h"
|
||||
#include "../../Vec2.h"
|
||||
#include "../../Color4.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
template<typename T = float>
|
||||
class Vertex
|
||||
{
|
||||
public:
|
||||
Vec3<T> pos;
|
||||
Vec3<T> normal;
|
||||
Vec2<T> uv;
|
||||
Vec3<T> tan;
|
||||
Vec3<T> bTan;
|
||||
Vec4<UInt_8> bones;
|
||||
Vec4<float> weights;
|
||||
|
||||
Vertex() = default;
|
||||
|
||||
Vertex(const Vec3<T>& pos)
|
||||
: pos(pos), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
|
||||
{
|
||||
}
|
||||
|
||||
Vertex(const Vec3<T>& pos, const Vec3<T>& normal)
|
||||
: pos(pos), normal(normal), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
|
||||
{
|
||||
}
|
||||
|
||||
Vertex(const Vec3<T>& pos, const Vec3<T>& normal, const Vec2<T>& uv)
|
||||
: pos(pos), normal(normal), uv(uv), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
|
||||
{
|
||||
}
|
||||
|
||||
Vertex(const Vertex& vert)
|
||||
: pos(vert.pos), normal(vert.normal), uv(vert.uv), bones(vert.bones), weights(vert.weights)
|
||||
{
|
||||
}
|
||||
|
||||
Vertex& operator=(const Vertex& vert) = default;
|
||||
};
|
||||
|
||||
typedef Vertex<double> Vertex_d;
|
||||
typedef Vertex<float> Vertex_f;
|
||||
}
|
38
include/IO/RIFF.h
Normal file
38
include/IO/RIFF.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../Vector.h"
|
||||
#include "../Serializer.h"
|
||||
#include "RIFF_Chunk.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class RIFF
|
||||
{
|
||||
private:
|
||||
Str_8 type;
|
||||
Vector<RIFF_Chunk> chunks;
|
||||
|
||||
public:
|
||||
RIFF() = default;
|
||||
|
||||
RIFF(const Str_8& filePath);
|
||||
|
||||
RIFF(Serializer<>& data);
|
||||
|
||||
RIFF(const RIFF& riff) = default;
|
||||
|
||||
operator const RIFF_Chunk*() const;
|
||||
|
||||
Str_8 GetType() const;
|
||||
|
||||
bool HasChunk(const UInt_64 hashId) const;
|
||||
|
||||
bool HasChunk(const Str_8& id) const;
|
||||
|
||||
RIFF_Chunk GetChunk(const UInt_64 hashId) const;
|
||||
|
||||
RIFF_Chunk GetChunk(const Str_8& id) const;
|
||||
};
|
||||
}
|
33
include/IO/RIFF_Chunk.h
Normal file
33
include/IO/RIFF_Chunk.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class RIFF_Chunk
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
Serializer<> data;
|
||||
|
||||
public:
|
||||
RIFF_Chunk();
|
||||
|
||||
RIFF_Chunk(const Str_8& id, const Serializer<>& data);
|
||||
|
||||
RIFF_Chunk(const RIFF_Chunk& chunk);
|
||||
|
||||
RIFF_Chunk& operator=(const RIFF_Chunk& chunk);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Serializer<> GetData() const;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
}
|
112
include/IO/Socket/BaseTCP.h
Normal file
112
include/IO/Socket/BaseTCP.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "Request.h"
|
||||
#include "Response.h"
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class BaseTCP
|
||||
{
|
||||
protected:
|
||||
AddrType addrType;
|
||||
Str_8 localAddr;
|
||||
unsigned short localPort;
|
||||
Str_8 remoteHostName;
|
||||
Str_8 remoteAddr;
|
||||
unsigned short remotePort;
|
||||
bool connection;
|
||||
bool bound;
|
||||
bool listening;
|
||||
bool connected;
|
||||
|
||||
public:
|
||||
static const UInt_16 HTTPS_Port = 443;
|
||||
static const UInt_16 HTTP_Port = 80;
|
||||
static const UInt_16 MaxHeaderSize = 8192;
|
||||
|
||||
virtual ~BaseTCP() = default;
|
||||
|
||||
BaseTCP();
|
||||
|
||||
BaseTCP(const AddrType addrType);
|
||||
|
||||
BaseTCP(BaseTCP&& tcp) noexcept;
|
||||
|
||||
BaseTCP(const BaseTCP& tcp);
|
||||
|
||||
BaseTCP& operator=(BaseTCP&& tcp) noexcept;
|
||||
|
||||
BaseTCP& operator=(const BaseTCP& tcp);
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual void Bind(const Str_8& address, unsigned short port) = 0;
|
||||
|
||||
virtual void Listen() = 0;
|
||||
|
||||
virtual BaseTCP* Accept() = 0;
|
||||
|
||||
virtual void Connect(const Str_8& address, const unsigned short port) = 0;
|
||||
|
||||
virtual UInt_64 Send(const Byte* const buffer, const UInt_32 size) = 0;
|
||||
|
||||
virtual UInt_64 Receive(Byte* const buffer, const UInt_32 size) = 0;
|
||||
|
||||
void SendStr(const Str_8& str);
|
||||
|
||||
/// Sends a HTTP response to the connected endpoint.
|
||||
/// @param [in] res The response to send.
|
||||
void SendRes(const Response& res);
|
||||
|
||||
/// Sends a HTTP request to the connected endpoint.
|
||||
/// @param [in] req The request to send.
|
||||
void SendReq(Request& req);
|
||||
|
||||
/// Receives a HTTP response from the connected endpoint.
|
||||
/// @returns The response received.
|
||||
Response RecvRes();
|
||||
|
||||
/// Receives a HTTP request from the connected endpoint.
|
||||
/// @returns The request received.
|
||||
Request RecvReq();
|
||||
|
||||
AddrType GetAddressType() const;
|
||||
|
||||
Str_8 GetLocalAddress() const;
|
||||
|
||||
unsigned short GetLocalPort() const;
|
||||
|
||||
Str_8 GetRemoteAddress() const;
|
||||
|
||||
unsigned short GetRemotePort() const;
|
||||
|
||||
bool IsConnection() const;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
bool IsListening() const;
|
||||
|
||||
bool IsConnected() const;
|
||||
|
||||
virtual void SetBlocking(const bool blocking) = 0;
|
||||
|
||||
virtual bool IsBlocking() const = 0;
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
private:
|
||||
Str_8 RecvHeader();
|
||||
|
||||
Str_8 RecvBody(const UInt_64 contentLength);
|
||||
|
||||
UInt_64 RecvChunkSize();
|
||||
|
||||
Str_8 RecvChunk(const UInt_64 chunkSize);
|
||||
};
|
||||
}
|
54
include/IO/Socket/BaseUDP.h
Normal file
54
include/IO/Socket/BaseUDP.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class BaseUDP
|
||||
{
|
||||
protected:
|
||||
AddrType addrType;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
bool bound;
|
||||
|
||||
public:
|
||||
virtual ~BaseUDP() = default;
|
||||
|
||||
BaseUDP();
|
||||
|
||||
BaseUDP(const AddrType addrType);
|
||||
|
||||
BaseUDP(BaseUDP&& udp) noexcept;
|
||||
|
||||
BaseUDP(const BaseUDP& udp);
|
||||
|
||||
BaseUDP& operator=(BaseUDP&& udp) noexcept;
|
||||
|
||||
BaseUDP& operator=(const BaseUDP& udp);
|
||||
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual void Bind(const Str_8& address, const UInt_16 port) = 0;
|
||||
|
||||
virtual UInt_64 Send(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size) = 0;
|
||||
|
||||
virtual UInt_64 Receive(Str_8* const addr, UInt_16* const port, Byte* const data, const UInt_64 size) = 0;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
virtual void SetBlocking(const bool blocking) = 0;
|
||||
|
||||
virtual bool IsBlocking() const = 0;
|
||||
|
||||
AddrType GetAddressType() const;
|
||||
|
||||
Str_8 GetLocalAddress() const;
|
||||
|
||||
UInt_16 GetLocalPort() const;
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
};
|
||||
}
|
194
include/IO/Socket/Comms.h
Normal file
194
include/IO/Socket/Comms.h
Normal file
@@ -0,0 +1,194 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Log.h"
|
||||
#include "../../BaseObj.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Array.h"
|
||||
#include "Socket.h"
|
||||
#include "UDP.h"
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class CommsSystem;
|
||||
class Endpoint;
|
||||
|
||||
class Comms : public BaseObj
|
||||
{
|
||||
private:
|
||||
static const Version ver;
|
||||
static const UInt_64 internalSys;
|
||||
static const UInt_64 connectOp;
|
||||
static const UInt_64 connectedOp;
|
||||
static const UInt_64 rejectedOp;
|
||||
static const UInt_64 disconnectOp;
|
||||
static const UInt_64 disconnectedOp;
|
||||
static const UInt_64 statusUpdateOp;
|
||||
static const UInt_64 pingOp;
|
||||
static const UInt_64 pongOp;
|
||||
static const UInt_64 latencyOp;
|
||||
static const UInt_64 receivedOp;
|
||||
|
||||
Socket hdl;
|
||||
AddrType type;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
bool bound;
|
||||
Version appVer;
|
||||
EndDisp disposition;
|
||||
bool dropPackets;
|
||||
Str_8 id;
|
||||
UInt_32 hashId;
|
||||
Byte* buffer;
|
||||
UInt_32 bufferSize;
|
||||
Array<CommsSystem*> systems;
|
||||
Vector<Endpoint*> endpoints;
|
||||
UInt_32 maxEndpoints;
|
||||
UInt_64 lastTSC;
|
||||
float delta;
|
||||
float maxTimeout;
|
||||
float resendRate;
|
||||
bool (*connectedCb)(Comms*, Endpoint*);
|
||||
void (*activeCb)(Comms*, Endpoint*);
|
||||
void (*disconnectedCb)(Comms*, Endpoint*);
|
||||
|
||||
public:
|
||||
~Comms() override;
|
||||
|
||||
Comms();
|
||||
|
||||
Comms(const Version& ver, const EndDisp disposition, const Str_8& id, const UInt_64 maxEndpoints);
|
||||
|
||||
Comms(const Comms& sock);
|
||||
|
||||
Comms& operator=(const Comms& sock);
|
||||
|
||||
void Initialize();
|
||||
|
||||
void UnInitialize();
|
||||
|
||||
void Bind(const Str_8& newAddress, const UInt_16 newPort);
|
||||
|
||||
void Connect(const Str_8& address, const UInt_16 port);
|
||||
|
||||
bool Disconnect(const EndDisp disposition, const UInt_64 hashId, const Str_8& msg);
|
||||
|
||||
bool Disconnect(const EndDisp disposition, const Str_8& id, const Str_8& msg);
|
||||
|
||||
void Broadcast(const EndDisp disposition, const Status status, const bool deltaLocked, const bool encrypted,
|
||||
const bool ensure, const UInt_64 sysHashId, const UInt_64 opHashId,
|
||||
const Serializer<>& payload);
|
||||
|
||||
void Broadcast(const EndDisp disposition, const Status status, const bool deltaLocked, const bool encrypted,
|
||||
const bool ensure, const Str_8& sysId, const Str_8& opId,
|
||||
const Serializer<>& payload);
|
||||
|
||||
void Poll();
|
||||
|
||||
bool IsInitialized() const;
|
||||
|
||||
void SetAddressType(const AddrType newType);
|
||||
|
||||
AddrType GetAddressType() const;
|
||||
|
||||
Str_8 GetAddress() const;
|
||||
|
||||
UInt_16 GetPort() const;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
Version GetVersion() const;
|
||||
|
||||
Version GetAppVersion() const;
|
||||
|
||||
EndDisp GetDisposition() const;
|
||||
|
||||
void EnableDropPackets(const bool enable);
|
||||
|
||||
bool IsDropPacketsEnabled() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
bool HasSystem(const UInt_64 hashId) const;
|
||||
|
||||
bool HasSystem(const Str_8& id) const;
|
||||
|
||||
bool AddSystem(CommsSystem* sys);
|
||||
|
||||
CommsSystem* GetSystem(const UInt_64 hashId);
|
||||
|
||||
CommsSystem* GetSystem(const Str_8& id);
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const Status status, const UInt_64 hashId) const;
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const Status status, const Str_8& id) const;
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const UInt_64 hashId) const;
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const Str_8& id) const;
|
||||
|
||||
bool HasEndpoint(const Str_8& address, const UInt_16 port) const;
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const Status status, const UInt_64 hashId);
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const Status status, const Str_8& id);
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const UInt_64 hashId);
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const Str_8& id);
|
||||
|
||||
Endpoint* GetEndpoint(const Str_8& address, const UInt_16 port);
|
||||
|
||||
Array<Endpoint*> GetEndpoints(const EndDisp disposition, const Status status);
|
||||
|
||||
Array<Endpoint*> GetEndpoints(const EndDisp disposition);
|
||||
|
||||
UInt_64 GetEndpointsCount(const EndDisp disposition, const Status status);
|
||||
|
||||
UInt_64 GetEndpointsCount(const EndDisp disposition);
|
||||
|
||||
UInt_64 GetMaxEndpoints() const;
|
||||
|
||||
void SetBlocking(const bool blocking);
|
||||
|
||||
bool IsBlocking() const;
|
||||
|
||||
void SetMaxTimeout(const float seconds);
|
||||
|
||||
float GetMaxTimeout() const;
|
||||
|
||||
void SetResendRate(const float seconds);
|
||||
|
||||
float GetResendRate() const;
|
||||
|
||||
void SetConnectedCb(bool (*newCb)(Comms*, Endpoint*));
|
||||
|
||||
void SetActiveCb(void (*newCb)(Comms*, Endpoint*));
|
||||
|
||||
void SetDisconnectedCb(void (*newCb)(Comms*, Endpoint*));
|
||||
|
||||
private:
|
||||
void UpdateQueue(UInt_64 active);
|
||||
|
||||
void UpdateQueue();
|
||||
|
||||
bool RemoveEndpoint(const EndDisp disposition, const UInt_64 hashId);
|
||||
|
||||
bool RemoveEndpoint(const Str_8& address, const UInt_16 port);
|
||||
|
||||
bool RemoveEndpoint(const Endpoint* const end);
|
||||
|
||||
void PollEndpoints(Vector<Endpoint*>& endpoints);
|
||||
|
||||
void Bind_v6(const Str_8& address, const UInt_16 port);
|
||||
|
||||
void Bind_v4(const Str_8& address, const UInt_16 port);
|
||||
|
||||
UInt_16 Receive(Str_8* address, UInt_16* port, Byte* const data, const UInt_16 size);
|
||||
};
|
||||
}
|
42
include/IO/Socket/CommsSystem.h
Normal file
42
include/IO/Socket/CommsSystem.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Array.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Endpoint;
|
||||
class Operation;
|
||||
class Comms;
|
||||
|
||||
class CommsSystem
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
Array<Operation*> ops;
|
||||
|
||||
public:
|
||||
~CommsSystem();
|
||||
|
||||
CommsSystem();
|
||||
|
||||
CommsSystem(const Str_8& id);
|
||||
|
||||
CommsSystem(const CommsSystem& sys);
|
||||
|
||||
CommsSystem& operator=(const CommsSystem& sys);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
bool HasOperation(const UInt_64 hashId);
|
||||
|
||||
bool AddOperation(Operation* op);
|
||||
|
||||
void Execute(Comms* comms, Endpoint* endpoint, const UInt_64 hashId, Serializer<>& payload);
|
||||
};
|
||||
}
|
14
include/IO/Socket/DNS.h
Normal file
14
include/IO/Socket/DNS.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class DNS
|
||||
{
|
||||
public:
|
||||
static Str_8 Resolve(const AddrType addrType, const Str_8& hostName);
|
||||
};
|
||||
}
|
137
include/IO/Socket/Endpoint.h
Normal file
137
include/IO/Socket/Endpoint.h
Normal file
@@ -0,0 +1,137 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../BaseObj.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "../../IO/Socket/Socket.h"
|
||||
|
||||
#include "Utils.h"
|
||||
#include "Fragments.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Comms;
|
||||
|
||||
class Endpoint : public BaseObj
|
||||
{
|
||||
private:
|
||||
Socket hdl;
|
||||
EndDisp disposition;
|
||||
Status status;
|
||||
Architecture arch;
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
UInt_64 nextSendId;
|
||||
Vector<Insurance> sent;
|
||||
UInt_64 nextRecvId;
|
||||
Vector<Fragments> received;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
float deltaDuration;
|
||||
float deltaRate;
|
||||
float timeout;
|
||||
float lastPing;
|
||||
float oldLatency;
|
||||
float latency;
|
||||
UInt_64 queueSlot;
|
||||
|
||||
public:
|
||||
Endpoint();
|
||||
|
||||
Endpoint(const Socket hdl, const EndDisp disposition, const Architecture arch, const Str_8& id,
|
||||
const AddrType& type, const Str_8& address, const UInt_16 port);
|
||||
|
||||
Endpoint(const Socket hdl, const AddrType& type, const Str_8& address, const UInt_16 port);
|
||||
|
||||
Endpoint(const Endpoint& end);
|
||||
|
||||
Endpoint& operator=(const Endpoint& end);
|
||||
|
||||
void Poll(const float delta);
|
||||
|
||||
EndDisp GetDisposition() const;
|
||||
|
||||
void SetStatus(const Status newStatus);
|
||||
|
||||
Status GetStatus() const;
|
||||
|
||||
Architecture GetArchitecture() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
UInt_64 GetNextSendId() const;
|
||||
|
||||
/// Sends data to the remote endpoint.
|
||||
/// @param [in] deltaLocked Whether or not to match the remote endpoint's delta time to prevent overloading the client. This will drop data if delta time does not match.
|
||||
/// @param [in] encrypted Whether or not to encrypt this data before sending to the remote endpoint.
|
||||
/// @param [in] ensure Whether or not to ensure the data was received by the remote endpoint.
|
||||
/// @param [in] sys The system hash id to execute an operation from.
|
||||
/// @param [in] op The operation hash id in the system to execute.
|
||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||
void Send(const bool deltaLocked, const bool encrypted, const bool ensure, const UInt_64 sys,
|
||||
const UInt_64 op, const Serializer<>& payload);
|
||||
|
||||
/// Sends data to the remote endpoint.
|
||||
/// @param [in] deltaLocked Whether or not to match the remote endpoint's delta time to prevent overloading the client. This will drop data if delta time does not match.
|
||||
/// @param [in] encrypted Whether or not to encrypt this data before sending to the remote endpoint.
|
||||
/// @param [in] ensure Whether or not to ensure the data was received by the remote endpoint.
|
||||
/// @param [in] sys The system string id to execute an operation from.
|
||||
/// @param [in] op The operation string id in the system to execute.
|
||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||
void Send(const bool deltaLocked, const bool encrypted, const bool ensure, const Str_8& sys,
|
||||
const Str_8& op, const Serializer<>& payload);
|
||||
|
||||
void RemoveInsurance(const UInt_64 msgId, const UInt_64 fragment);
|
||||
|
||||
UInt_64 GetNextRecvId() const;
|
||||
|
||||
void AddReceived(const Header& header, const Serializer<>& payload);
|
||||
|
||||
Vector<Fragments> GetReceived() const;
|
||||
|
||||
Vector<Fragments>* GetReceived();
|
||||
|
||||
Str_8 GetAddress() const;
|
||||
|
||||
UInt_16 GetPort() const;
|
||||
|
||||
void SetDeltaRate(const float newDeltaRate);
|
||||
|
||||
float GetDeltaRate() const;
|
||||
|
||||
float GetTimeout() const;
|
||||
|
||||
float GetLastPing() const;
|
||||
|
||||
void Ping(const float delta);
|
||||
|
||||
void Pong(const float delta);
|
||||
|
||||
void SendLatency();
|
||||
|
||||
void SetLatency(const float newLatency);
|
||||
|
||||
float GetLatency() const;
|
||||
|
||||
void SetQueueSlot(const UInt_64 slot);
|
||||
|
||||
UInt_64 GetQueueSlot() const;
|
||||
|
||||
private:
|
||||
Fragments FragmentData(const Header& header, const Serializer<>& data);
|
||||
|
||||
void Send(const Header& header, const Serializer<>& payload);
|
||||
|
||||
bool SortingNeeded() const;
|
||||
|
||||
void SortReceived();
|
||||
|
||||
UInt_16 Send_v6(const Serializer<>& payload);
|
||||
|
||||
UInt_16 Send_v4(const Serializer<>& payload);
|
||||
};
|
||||
}
|
42
include/IO/Socket/Fragments.h
Normal file
42
include/IO/Socket/Fragments.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Fragments
|
||||
{
|
||||
private:
|
||||
Header header;
|
||||
Serializer<>* data;
|
||||
UInt_64 size;
|
||||
|
||||
public:
|
||||
~Fragments();
|
||||
|
||||
Fragments();
|
||||
|
||||
Fragments(const Header& header, const Serializer<>& payload);
|
||||
|
||||
Fragments(const Header& header, const UInt_64 size);
|
||||
|
||||
Fragments(const Fragments& frags);
|
||||
|
||||
Fragments& operator=(const Fragments& frags);
|
||||
|
||||
operator const Serializer<>* () const;
|
||||
|
||||
operator Serializer<>* ();
|
||||
|
||||
Header GetHeader() const;
|
||||
|
||||
UInt_64 Size() const;
|
||||
|
||||
bool IsComplete() const;
|
||||
|
||||
Packet Combine() const;
|
||||
};
|
||||
}
|
36
include/IO/Socket/Operation.h
Normal file
36
include/IO/Socket/Operation.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class CommsSystem;
|
||||
class Comms;
|
||||
class Endpoint;
|
||||
|
||||
class Operation
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
|
||||
public:
|
||||
virtual ~Operation() = default;
|
||||
|
||||
Operation();
|
||||
|
||||
Operation(const Str_8& id);
|
||||
|
||||
Operation(const Operation& cmd);
|
||||
|
||||
Operation& operator=(const Operation& cmd);
|
||||
|
||||
virtual void Process(Comms* comms, Endpoint* endpoint, CommsSystem* sys, Serializer<>& payload);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
};
|
||||
}
|
164
include/IO/Socket/Request.h
Normal file
164
include/IO/Socket/Request.h
Normal file
@@ -0,0 +1,164 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Json/Json.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class Verb
|
||||
{
|
||||
POST,
|
||||
GET,
|
||||
PUT,
|
||||
DEL
|
||||
};
|
||||
|
||||
class Request
|
||||
{
|
||||
private:
|
||||
Verb verb;
|
||||
Str_8 rsrc;
|
||||
Vector<Str_8> queries;
|
||||
Vector<Str_8> header;
|
||||
ContentType cType;
|
||||
Str_8 body;
|
||||
|
||||
public:
|
||||
/// Default member initialization.
|
||||
Request();
|
||||
|
||||
/// Initializes this request with a given verb and URI resource.
|
||||
/// @param [in] verb The type of request to make.
|
||||
/// @param [in] rsrc The URI endpoint to make the request at.
|
||||
Request(const Verb verb, const Str_8& rsrc);
|
||||
|
||||
/// Initializes this request with the raw request data.
|
||||
/// @param [in] data The C-style string of the request.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
Request(const char* data, const UInt_64 size);
|
||||
|
||||
/// Initializes this request with the raw request data.
|
||||
/// @param [in] data The string of the request.
|
||||
Request(const Str_8& data);
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] req The object to copy from.
|
||||
Request(const Request& req) = default;
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] req The object to copy from.
|
||||
/// @returns The request that has been assigned to.
|
||||
Request& operator=(const Request& req);
|
||||
|
||||
/// Retrieves the verb for the request.
|
||||
/// @returns The result.
|
||||
Verb GetVerb() const;
|
||||
|
||||
/// Sets the content type for the body.
|
||||
/// @param [in] cType The content type to use.
|
||||
void SetContentType(const ContentType cType);
|
||||
|
||||
/// Retrieves the content type for the body.
|
||||
/// @returns The result.
|
||||
ContentType GetContentType() const;
|
||||
|
||||
/// Sets the URI resource.
|
||||
/// @param [in] rsrc The resource.
|
||||
void SetResource(const Str_8& rsrc);
|
||||
|
||||
/// Retrieves the URI resource.
|
||||
/// @returns The result.
|
||||
Str_8 GetResource() const;
|
||||
|
||||
/// Adds a query variable to the URI.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddQuery(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Retrieves a query variable from the URI.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the query variable. Empty if it was not found.
|
||||
Str_8 GetQuery(const Str_8& var);
|
||||
|
||||
/// Retrieves all the query variables from the URI in a vector object.
|
||||
/// @returns The result.
|
||||
Vector<Str_8> GetQueries() const;
|
||||
|
||||
/// A helper method to automatically add the required header variables for basic authentication.
|
||||
/// @param [in] id The username or id.
|
||||
/// @param [in] secret The secret given by an API.
|
||||
void BasicAuth(const Str_8& id, const Str_8& secret);
|
||||
|
||||
/// A helper method to automatically add the required header variables for bearer authentication.
|
||||
/// @param [in] token The token given by an API.
|
||||
void BearerAuth(const Str_8& token);
|
||||
|
||||
/// A helper method to automatically add the required header variables for bearer authentication.
|
||||
/// @param [in] token The token given by an API.
|
||||
/// @param [in] clientId The client id given by an API.
|
||||
void BearerAuth(const Str_8& token, const Str_8& clientId);
|
||||
|
||||
/// A helper method to automatically add the required header variables for bot authentication.
|
||||
/// @param [in] token The token given by an API.
|
||||
void BotAuth(const Str_8& token);
|
||||
|
||||
/// Adds a header variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToHeader(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Retrieves a header variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the header variable. Empty if it was not found.
|
||||
Str_8 GetHeader(const Str_8& var) const;
|
||||
|
||||
/// Retrieves all the header variables in a vector object.
|
||||
/// @returns The result.
|
||||
Vector<Str_8> GetHeader() const;
|
||||
|
||||
/// Adds a body variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToBody(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Adds a value to the body.
|
||||
/// @param [in] data The value to add.
|
||||
void AddToBody(const Str_8& data);
|
||||
|
||||
/// Sets the entire body.
|
||||
/// @param [in] body The body to use.
|
||||
void SetBody(const Str_8& body);
|
||||
|
||||
/// Retrieves a body variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the body variable. Empty if it was not found.
|
||||
Str_8 GetVar(const Str_8& var) const;
|
||||
|
||||
/// Retrieves the entire body.
|
||||
/// @returns The result.
|
||||
Str_8 GetBody() const;
|
||||
|
||||
/// Retrieves the entire body as a Json.
|
||||
/// @returns The result.
|
||||
Json GetJson() const;
|
||||
|
||||
/// Forms the raw result of the request to be sent.
|
||||
/// @returns The result.
|
||||
Str_8 FormResult() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
static Str_8 VerbToStr(const Verb verb);
|
||||
|
||||
static Str_8 ContentTypeToStr(const ContentType cType);
|
||||
|
||||
static ContentType StrToContentType(const Str_8& value);
|
||||
|
||||
void ReadData(const Str_8& data);
|
||||
|
||||
};
|
||||
}
|
127
include/IO/Socket/Response.h
Normal file
127
include/IO/Socket/Response.h
Normal file
@@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Json/Json.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Response
|
||||
{
|
||||
private:
|
||||
UInt_32 code;
|
||||
Str_8 server;
|
||||
ContentType cType;
|
||||
Vector<Str_8> header;
|
||||
Str_8 body;
|
||||
|
||||
public:
|
||||
/// Default member initialization.
|
||||
Response();
|
||||
|
||||
/// Initializes this response with a given code and server identifier.
|
||||
/// @param [in] code The code to give.
|
||||
/// @param [in] server The server identifier.
|
||||
Response(const UInt_32 code, const Str_8& server);
|
||||
|
||||
/// Initializes this response with the raw response data.
|
||||
/// @param [in] data The C-style string of the response.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
Response(const char* data, const UInt_64 size);
|
||||
|
||||
/// Initializes this response with the raw response data.
|
||||
/// @param [in] data The string of the response.
|
||||
Response(const Str_8& data);
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] res The object to copy from.
|
||||
Response(const Response& res) = default;
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] res The object to copy from.
|
||||
/// @returns The response that has been assigned to.
|
||||
Response& operator=(const Response& res);
|
||||
|
||||
/// Sets the response code to send to the endpoint.
|
||||
/// @param [in] code The code for success, error or info.
|
||||
void SetCode(const UInt_32 code);
|
||||
|
||||
/// Retrieves the response code.
|
||||
/// @returns The result.
|
||||
UInt_32 GetCode() const;
|
||||
|
||||
/// Sets the server identifier.
|
||||
/// @param [in] server The server identifier to use.
|
||||
void SetServer(const Str_8& server);
|
||||
|
||||
/// Retrieves the server identifier.
|
||||
/// @returns The result.
|
||||
Str_8 GetServer() const;
|
||||
|
||||
/// Sets the content type for the body.
|
||||
/// @param [in] cType The content type to use.
|
||||
void SetContentType(const ContentType cType);
|
||||
|
||||
/// Retrieves the content type for the body.
|
||||
/// @returns The result.
|
||||
ContentType GetContentType() const;
|
||||
|
||||
/// Adds a header variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToHeader(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Retrieves a header variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the header variable. Empty if it was not found.
|
||||
Str_8 GetHeader(const Str_8& var) const;
|
||||
|
||||
/// Retrieves all the header variables in a vector object.
|
||||
/// @returns The result.
|
||||
Vector<Str_8> GetHeader() const;
|
||||
|
||||
/// Adds a body variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToBody(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Adds a value to the body.
|
||||
/// @param [in] data The value to add.
|
||||
void AddToBody(const Str_8& data);
|
||||
|
||||
/// Sets the entire body.
|
||||
/// @param [in] body The body to use.
|
||||
void SetBody(const Str_8& body);
|
||||
|
||||
/// Retrieves a body variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the body variable. Empty if it was not found.
|
||||
Str_8 GetVar(const Str_8& var) const;
|
||||
|
||||
/// Retrieves the entire body.
|
||||
/// @returns The result.
|
||||
Str_8 GetBody() const;
|
||||
|
||||
/// Retrieves the entire body as a Json.
|
||||
/// @returns The result.
|
||||
Json GetJson() const;
|
||||
|
||||
/// Forms the raw result of the response to be sent.
|
||||
/// @returns The result.
|
||||
Str_8 FormResult() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
static Str_8 CodeToStr(const UInt_32 code);
|
||||
|
||||
static Str_8 ContentTypeToStr(const ContentType cType);
|
||||
|
||||
static ContentType StrToContentType(const Str_8& value);
|
||||
|
||||
void ReadData(const Str_8& data);
|
||||
|
||||
};
|
||||
}
|
113
include/IO/Socket/RestAPIs/Spotify.h
Normal file
113
include/IO/Socket/RestAPIs/Spotify.h
Normal file
@@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../EHS.h"
|
||||
#include "../../../Str.h"
|
||||
#include "../../../Array.h"
|
||||
#include "../SSL.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class SpotifyState
|
||||
{
|
||||
TRACK,
|
||||
CONTEXT,
|
||||
OFF
|
||||
};
|
||||
|
||||
struct Track
|
||||
{
|
||||
Array<Str_8> artists;
|
||||
Str_8 name;
|
||||
Str_8 id;
|
||||
};
|
||||
|
||||
class Spotify
|
||||
{
|
||||
private:
|
||||
SSL client;
|
||||
Str_8 clientId;
|
||||
Str_8 secret;
|
||||
Str_8 redURI;
|
||||
Array<Str_8> scopes;
|
||||
bool forceVerify;
|
||||
Str_8 token;
|
||||
Str_8 rToken;
|
||||
|
||||
public:
|
||||
static const Str_8 trackUriPrefix;
|
||||
|
||||
virtual ~Spotify();
|
||||
|
||||
Spotify();
|
||||
|
||||
Spotify(const Str_8& clientId, const Str_8& secret, const Str_8& redURI, const Array<Str_8>& scopes, const bool forceVerify);
|
||||
|
||||
bool Authorize();
|
||||
|
||||
/// Sets the volume for a device.
|
||||
/// @param [in] level The percentage to set the volume to.
|
||||
/// @returns The response code.
|
||||
UInt_32 SetVolume(const UInt_8 level);
|
||||
|
||||
/// Resume playback for a device.
|
||||
/// @returns The response code.
|
||||
UInt_32 Play();
|
||||
|
||||
/// Pauses playback for a device.
|
||||
/// @returns The response code.
|
||||
UInt_32 Pause();
|
||||
|
||||
/// Repeats playback for a device.
|
||||
/// @param [in] status The status to set it to.
|
||||
/// @returns The response code.
|
||||
UInt_32 SetRepeat(const SpotifyState state);
|
||||
|
||||
/// Shuffles playback for a device.
|
||||
/// @param [in] state The state to set shuffle to.
|
||||
/// @returns The response code.
|
||||
UInt_32 SetShuffle(const bool state);
|
||||
|
||||
UInt_32 SearchTrack(Vector<Str_8>& artists, Str_8& id, Str_8& name);
|
||||
|
||||
UInt_32 GetPlayingTrack(Vector<Str_8>& artists, Str_8& id, Str_8& name);
|
||||
|
||||
UInt_32 GetQueue(Array<Track>& tracks);
|
||||
|
||||
/// Adds a track to the queue for a device.
|
||||
/// @param [in] uri The track id to add.
|
||||
/// @returns The response code.
|
||||
UInt_32 QueueTrack(const Str_8& id);
|
||||
|
||||
UInt_32 AddTracks(const Str_8& playlistId, const Array<Str_8>& trackIds, const UInt_32 pos = 0);
|
||||
|
||||
UInt_32 AddTrack(const Str_8& playlistId, const Str_8& trackId, const UInt_32 pos = 0);
|
||||
|
||||
/// Skips to the next track.
|
||||
/// @returns The response code.
|
||||
UInt_32 Skip();
|
||||
|
||||
/// Skips to the previous track.
|
||||
/// @returns The response code.
|
||||
UInt_32 Previous();
|
||||
|
||||
/// Seeks to a position of the currently playing track in milliseconds.
|
||||
/// @param [in] pos The position in milliseconds to seek to.
|
||||
/// @returns The response code.
|
||||
UInt_32 Seek(const UInt_32 pos);
|
||||
|
||||
Str_8 GetClientId() const;
|
||||
|
||||
Str_8 GetSecret() const;
|
||||
|
||||
Str_8 GetRedURI() const;
|
||||
|
||||
bool IsVerificationForced() const;
|
||||
|
||||
bool IsActive() const;
|
||||
|
||||
private:
|
||||
void StartConnection();
|
||||
|
||||
bool ReAuthorize();
|
||||
};
|
||||
}
|
39
include/IO/Socket/RestAPIs/Twitch.h
Normal file
39
include/IO/Socket/RestAPIs/Twitch.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../EHS.h"
|
||||
#include "../../../Str.h"
|
||||
#include "../SSL.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Twitch
|
||||
{
|
||||
private:
|
||||
SSL client;
|
||||
Str_8 clientId;
|
||||
Str_8 secret;
|
||||
Str_8 redURI;
|
||||
Array<Str_8> scopes;
|
||||
bool forceVerify;
|
||||
Str_8 token;
|
||||
|
||||
public:
|
||||
virtual ~Twitch();
|
||||
|
||||
Twitch();
|
||||
|
||||
Twitch(const Str_8& clientId, const Str_8& secret, const Str_8& redURI, const Array<Str_8>& scopes, const bool forceVerify);
|
||||
|
||||
bool Authorize();
|
||||
|
||||
Str_8 GetClientId() const;
|
||||
|
||||
Str_8 GetSecret() const;
|
||||
|
||||
Str_8 GetRedURI() const;
|
||||
|
||||
bool IsVerificationForced() const;
|
||||
|
||||
Str_8 GetToken() const;
|
||||
};
|
||||
}
|
53
include/IO/Socket/RestAPIs/TwitchChat.h
Normal file
53
include/IO/Socket/RestAPIs/TwitchChat.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../EHS.h"
|
||||
#include "../../../Str.h"
|
||||
#include "../TCP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class TwitchChat
|
||||
{
|
||||
private:
|
||||
TCP client;
|
||||
Str_8 username;
|
||||
Str_8 token;
|
||||
Str_8 channel;
|
||||
bool initialized;
|
||||
|
||||
public:
|
||||
~TwitchChat();
|
||||
|
||||
TwitchChat();
|
||||
|
||||
TwitchChat(const Str_8& username);
|
||||
|
||||
TwitchChat(const Str_8& username, const Str_8& token);
|
||||
|
||||
TwitchChat(const TwitchChat& chat);
|
||||
|
||||
TwitchChat& operator=(const TwitchChat& chat);
|
||||
|
||||
void SetToken(const Str_8& newToken);
|
||||
|
||||
void Initialize();
|
||||
|
||||
void UnInitialize();
|
||||
|
||||
void JoinChannel(const Str_8& newChannel);
|
||||
|
||||
void LeaveChannel();
|
||||
|
||||
void SendPong();
|
||||
|
||||
void SendMsg(const Str_8& msg);
|
||||
|
||||
void WhisperMsg(const Str_8& user, const Str_8& msg);
|
||||
|
||||
Str_8 RecvMsg();
|
||||
|
||||
Str_8 GetUsername() const;
|
||||
|
||||
Str_8 GetChannel() const;
|
||||
};
|
||||
}
|
56
include/IO/Socket/SSL.h
Normal file
56
include/IO/Socket/SSL.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "TCP.h"
|
||||
#include "Request.h"
|
||||
#include "Response.h"
|
||||
|
||||
typedef struct ssl_ctx_st SSL_CTX;
|
||||
typedef struct ssl_st SSL;
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// A class for handling the HTTP(S) TCP socket layer.
|
||||
class SSL : public TCP
|
||||
{
|
||||
private:
|
||||
SSL_CTX* ctx;
|
||||
::SSL* sslHdl;
|
||||
|
||||
public:
|
||||
~SSL() override;
|
||||
|
||||
SSL();
|
||||
|
||||
SSL(const AddrType type);
|
||||
|
||||
SSL(TCP&& tcp) noexcept;
|
||||
|
||||
SSL(const TCP& tcp);
|
||||
|
||||
SSL(const SSL& ssl);
|
||||
|
||||
SSL& operator=(const SSL& ssl);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
void Bind(const Str_8& address, unsigned short port) override;
|
||||
|
||||
SSL* Accept() override;
|
||||
|
||||
void Connect(const Str_8& address, const UInt_16 port) override;
|
||||
|
||||
UInt_64 Send(const Byte* const buffer, const UInt_32 size) override;
|
||||
|
||||
UInt_64 Receive(Byte* const buffer, const UInt_32 size) override;
|
||||
|
||||
void UseCertificate(const Byte* data, const UInt_64 size);
|
||||
|
||||
void UsePrivateKey(const Byte* data, const UInt_64 size);
|
||||
|
||||
bool IsValid();
|
||||
};
|
||||
}
|
51
include/IO/Socket/Socket.h
Normal file
51
include/IO/Socket/Socket.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef LWE_IPV4_HEADER
|
||||
#define LWE_IPV4_HEADER 60
|
||||
#endif
|
||||
|
||||
#ifndef LWE_IPV6_HEADER
|
||||
#define LWE_IPV6_HEADER 40
|
||||
#endif
|
||||
|
||||
#ifndef LWE_UDP_HEADER
|
||||
#define LWE_UDP_HEADER 8
|
||||
#endif
|
||||
|
||||
#ifndef LWE_IPV4_UDP_PAYLOAD
|
||||
#define LWE_IPV4_UDP_PAYLOAD (LWE_UINT_16_MAX - LWE_IPV4_HEADER - LWE_UDP_HEADER)
|
||||
#endif
|
||||
|
||||
#ifndef LWE_IPV6_UDP_PAYLOAD
|
||||
#define LWE_IPV6_UDP_PAYLOAD (LWE_UINT_16_MAX - LWE_IPV6_HEADER - LWE_UDP_HEADER)
|
||||
#endif
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class AddrType
|
||||
{
|
||||
IPV6,
|
||||
IPV4
|
||||
};
|
||||
|
||||
enum class ContentType
|
||||
{
|
||||
APP_MULTIPART_FORMDATA,
|
||||
APP_FORMURLENCODED,
|
||||
APP_JAVASCRIPT,
|
||||
APP_JSON,
|
||||
APP_XML,
|
||||
TEXT_PLAIN,
|
||||
TEXT_HTML,
|
||||
TEXT_XML,
|
||||
NONE
|
||||
};
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
typedef UInt_64 Socket;
|
||||
#define LWE_INVALID_SOCKET LWE_UINT_64_MAX
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
typedef SInt_32 Socket;
|
||||
#define LWE_INVALID_SOCKET (SInt_32)0xffffffff
|
||||
#endif
|
||||
}
|
7
include/IO/Socket/TCP.h
Normal file
7
include/IO/Socket/TCP.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef LWE_OS_WINDOWS
|
||||
#include "TCP_W32.h"
|
||||
#else
|
||||
#include "TCP_BSD.h"
|
||||
#endif
|
94
include/IO/Socket/TCP_BSD.h
Normal file
94
include/IO/Socket/TCP_BSD.h
Normal file
@@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Log.h"
|
||||
|
||||
#include "Socket.h"
|
||||
#include "BaseTCP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// A wrapper class for the transmission control protocol socket.
|
||||
class TCP : public BaseTCP
|
||||
{
|
||||
protected:
|
||||
Socket hdl;
|
||||
|
||||
public:
|
||||
/// Frees any native handles.
|
||||
~TCP() override;
|
||||
|
||||
/// Default members initialization.
|
||||
TCP();
|
||||
|
||||
TCP(const AddrType addrType);
|
||||
|
||||
TCP(TCP&& tcp) noexcept;
|
||||
|
||||
/// Copies some members from the given TCP object.
|
||||
/// @param [in] tcp The TCP object to copy from.
|
||||
TCP(const TCP& tcp);
|
||||
|
||||
TCP& operator=(TCP&& tcp) noexcept;
|
||||
|
||||
/// Copies some members from the given TCP object.
|
||||
/// @param [in] tcp The TCP object to copy from.
|
||||
/// @returns The TCP object that has been assigned to.
|
||||
TCP& operator=(const TCP& tcp);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
/// Frees native handles and uninitializes them.
|
||||
void Release() override;
|
||||
|
||||
/// Binds the UDP socket to a local address and port.
|
||||
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param [in] port The port to bind to.
|
||||
/// @note Requires the port given to be forwarded if this is called.
|
||||
void Bind(const Str_8& address, unsigned short port) override;
|
||||
|
||||
/// Listens for incoming connections. Used for servers or PtP.
|
||||
void Listen() override;
|
||||
|
||||
/// Accepts an incoming connection. Used for servers or PtP.
|
||||
/// @returns The accepted client object.
|
||||
TCP* Accept() override;
|
||||
|
||||
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP.
|
||||
/// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param port The port of the listening TCP socket.
|
||||
void Connect(const Str_8& address, const unsigned short port) override;
|
||||
|
||||
/// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
|
||||
/// @param [in] buffer The C-style array to send.
|
||||
/// @param [in] size The size of the given C-style array.
|
||||
/// @returns The size of the data actually sent in bytes.
|
||||
UInt_64 Send(const Byte* const buffer, const UInt_32 size) override;
|
||||
|
||||
/// Receives data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
|
||||
/// @param [out] buffer The C-style array to receive with.
|
||||
/// @param [in] size The size of the given C-style array.
|
||||
/// @returns The size of the data actually received in bytes.
|
||||
UInt_64 Receive(Byte* const buffer, const UInt_32 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
void SetBlocking(const bool blocking) override;
|
||||
|
||||
/// Retrieves whether or not this socket will block when receiving data.
|
||||
/// @returns The result.
|
||||
bool IsBlocking() const override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
private:
|
||||
void Bind_v6(const Str_8& address, unsigned short port);
|
||||
|
||||
void Bind_v4(const Str_8& address, unsigned short port);
|
||||
|
||||
void Connect_v6(const Str_8& address, unsigned short port);
|
||||
|
||||
void Connect_v4(const Str_8& address, unsigned short port);
|
||||
};
|
||||
}
|
94
include/IO/Socket/TCP_W32.h
Normal file
94
include/IO/Socket/TCP_W32.h
Normal file
@@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Log.h"
|
||||
|
||||
#include "Socket.h"
|
||||
#include "BaseTCP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// A wrapper class for the transmission control protocol socket.
|
||||
class TCP : public BaseTCP
|
||||
{
|
||||
protected:
|
||||
Socket hdl;
|
||||
|
||||
public:
|
||||
/// Frees any native handles.
|
||||
~TCP() override;
|
||||
|
||||
/// Default members initialization.
|
||||
TCP();
|
||||
|
||||
TCP(const AddrType addrType);
|
||||
|
||||
TCP(TCP&& tcp) noexcept;
|
||||
|
||||
/// Copies some members from the given TCP object.
|
||||
/// @param [in] tcp The TCP object to copy from.
|
||||
TCP(const TCP& tcp);
|
||||
|
||||
TCP& operator=(TCP&& tcp) noexcept;
|
||||
|
||||
/// Copies some members from the given TCP object.
|
||||
/// @param [in] tcp The TCP object to copy from.
|
||||
/// @returns The TCP object that has been assigned to.
|
||||
TCP& operator=(const TCP& tcp);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
/// Frees native handles and uninitializes them.
|
||||
void Release() override;
|
||||
|
||||
/// Binds the UDP socket to a local address and port.
|
||||
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param [in] port The port to bind to.
|
||||
/// @note Requires the port given to be forwarded if this is called.
|
||||
void Bind(const Str_8& address, unsigned short port) override;
|
||||
|
||||
/// Listens for incoming connections. Used for servers or PtP.
|
||||
void Listen() override;
|
||||
|
||||
/// Accepts an incoming connection. Used for servers or PtP.
|
||||
/// @returns The accepted client object.
|
||||
TCP* Accept() override;
|
||||
|
||||
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP.
|
||||
/// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param port The port of the listening TCP socket.
|
||||
void Connect(const Str_8& address, const unsigned short port) override;
|
||||
|
||||
/// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
|
||||
/// @param [in] buffer The C-style array to send.
|
||||
/// @param [in] size The size of the given C-style array.
|
||||
/// @returns The size of the data actually sent in bytes.
|
||||
UInt_64 Send(const Byte* const buffer, const UInt_32 size) override;
|
||||
|
||||
/// Receives data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
|
||||
/// @param [out] buffer The C-style array to receive with.
|
||||
/// @param [in] size The size of the given C-style array.
|
||||
/// @returns The size of the data actually received in bytes.
|
||||
UInt_64 Receive(Byte* const buffer, const UInt_32 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
void SetBlocking(const bool blocking) override;
|
||||
|
||||
/// Retrieves whether or not this socket will block when receiving data.
|
||||
/// @returns The result.
|
||||
bool IsBlocking() const override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
private:
|
||||
void Bind_v6(const Str_8& address, unsigned short port);
|
||||
|
||||
void Bind_v4(const Str_8& address, unsigned short port);
|
||||
|
||||
void Connect_v6(const Str_8& address, unsigned short port);
|
||||
|
||||
void Connect_v4(const Str_8& address, unsigned short port);
|
||||
};
|
||||
}
|
7
include/IO/Socket/UDP.h
Normal file
7
include/IO/Socket/UDP.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef LWE_OS_WINDOWS
|
||||
#include "UDP_W32.h"
|
||||
#else
|
||||
#include "UDP_BSD.h"
|
||||
#endif
|
82
include/IO/Socket/UDP_BSD.h
Normal file
82
include/IO/Socket/UDP_BSD.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "BaseUDP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// A wrapper class for the user datagram protocol socket.
|
||||
class UDP : public BaseUDP
|
||||
{
|
||||
private:
|
||||
Socket hdl;
|
||||
|
||||
public:
|
||||
/// Frees any native handles.
|
||||
~UDP() override;
|
||||
|
||||
UDP();
|
||||
|
||||
/// Default members initialization.
|
||||
UDP(const AddrType addrType);
|
||||
|
||||
UDP(UDP&& udp) noexcept;
|
||||
|
||||
/// Copies some members from the given UDP object.
|
||||
/// @param [in] udp The UDP object to copy from.
|
||||
UDP(const UDP& udp);
|
||||
|
||||
UDP& operator=(UDP&& udp) noexcept;
|
||||
|
||||
/// Copies some members from the given UDP object.
|
||||
/// @param [in] udp The UDP object to copy from.
|
||||
/// @returns The UDP object that has been assigned to.
|
||||
UDP& operator=(const UDP& udp);
|
||||
|
||||
/// Frees native handles and uninitializes them.
|
||||
void Release() override;
|
||||
|
||||
/// Binds the UDP socket to a local address and port.
|
||||
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param [in] port The port to bind to.
|
||||
/// @note Requires the port given to be forwarded if this is called.
|
||||
void Bind(const Str_8& address, const UInt_16 port) override;
|
||||
|
||||
/// Sends data using a C-style byte array.
|
||||
/// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param [in] port The remote port to send to.
|
||||
/// @param [in] data The C-style byte array to send.
|
||||
/// @param [in] size The size of the C-style byte array.
|
||||
/// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6".
|
||||
UInt_64 Send(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size) override;
|
||||
|
||||
/// Receives data using the packet helper class.
|
||||
/// @param [out] addr The Ipv4 or Ipv6 address of the sender.
|
||||
/// @param [out] port The port of the sender.
|
||||
/// @param [out] data The C-style byte array received.
|
||||
/// @param [in] size The size of the pre-allocated C-style byte array.
|
||||
/// @returns The size of the data received.
|
||||
/// @warning The provided C-style byte array must be freed when finished using.
|
||||
UInt_64 Receive(Str_8* const addr, UInt_16* const port, Byte* const data, const UInt_64 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
void SetBlocking(const bool blocking) override;
|
||||
|
||||
/// Retrieves whether or not this socket will block when receiving data.
|
||||
/// @returns The result.
|
||||
bool IsBlocking() const override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
private:
|
||||
void Bind_v6(const Str_8& address, const UInt_16 port);
|
||||
|
||||
void Bind_v4(const Str_8& address, const UInt_16 port);
|
||||
|
||||
UInt_64 Send_v6(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
|
||||
UInt_64 Send_v4(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
};
|
||||
}
|
82
include/IO/Socket/UDP_W32.h
Normal file
82
include/IO/Socket/UDP_W32.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "BaseUDP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// A wrapper class for the user datagram protocol socket.
|
||||
class UDP : public BaseUDP
|
||||
{
|
||||
private:
|
||||
Socket hdl;
|
||||
|
||||
public:
|
||||
/// Frees any native handles.
|
||||
~UDP() override;
|
||||
|
||||
UDP();
|
||||
|
||||
/// Default members initialization.
|
||||
UDP(const AddrType addrType);
|
||||
|
||||
UDP(UDP&& udp) noexcept;
|
||||
|
||||
/// Copies some members from the given UDP object.
|
||||
/// @param [in] udp The UDP object to copy from.
|
||||
UDP(const UDP& udp);
|
||||
|
||||
UDP& operator=(UDP&& udp) noexcept;
|
||||
|
||||
/// Copies some members from the given UDP object.
|
||||
/// @param [in] udp The UDP object to copy from.
|
||||
/// @returns The UDP object that has been assigned to.
|
||||
UDP& operator=(const UDP& udp);
|
||||
|
||||
/// Frees native handles and uninitializes them.
|
||||
void Release() override;
|
||||
|
||||
/// Binds the UDP socket to a local address and port.
|
||||
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param [in] port The port to bind to.
|
||||
/// @note Requires the port given to be forwarded if this is called.
|
||||
void Bind(const Str_8& address, const UInt_16 port) override;
|
||||
|
||||
/// Sends data using a C-style byte array.
|
||||
/// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param [in] port The remote port to send to.
|
||||
/// @param [in] data The C-style byte array to send.
|
||||
/// @param [in] size The size of the C-style byte array.
|
||||
/// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6".
|
||||
UInt_64 Send(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size) override;
|
||||
|
||||
/// Receives data using the packet helper class.
|
||||
/// @param [out] addr The Ipv4 or Ipv6 address of the sender.
|
||||
/// @param [out] port The port of the sender.
|
||||
/// @param [out] data The C-style byte array received.
|
||||
/// @param [in] size The size of the pre-allocated C-style byte array.
|
||||
/// @returns The size of the data received.
|
||||
/// @warning The provided C-style byte array must be freed when finished using.
|
||||
UInt_64 Receive(Str_8* const addr, UInt_16* const port, Byte* const data, const UInt_64 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
void SetBlocking(const bool blocking) override;
|
||||
|
||||
/// Retrieves whether or not this socket will block when receiving data.
|
||||
/// @returns The result.
|
||||
bool IsBlocking() const override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
private:
|
||||
void Bind_v6(const Str_8& address, const UInt_16 port);
|
||||
|
||||
void Bind_v4(const Str_8& address, const UInt_16 port);
|
||||
|
||||
UInt_64 Send_v6(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
|
||||
UInt_64 Send_v4(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
};
|
||||
}
|
56
include/IO/Socket/Utils.h
Normal file
56
include/IO/Socket/Utils.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class EndDisp : UInt_8
|
||||
{
|
||||
UNKNOWN,
|
||||
SERVICE,
|
||||
ENDPOINT
|
||||
};
|
||||
|
||||
enum class Status : UInt_8
|
||||
{
|
||||
ACTIVE,
|
||||
PENDING,
|
||||
IN_LOCAL_QUEUE,
|
||||
IN_REMOTE_QUEUE,
|
||||
};
|
||||
|
||||
struct Header
|
||||
{
|
||||
bool encrypted = true;
|
||||
UInt_64 id = 0;
|
||||
UInt_64 fragments = 0;
|
||||
UInt_64 fragment = 0;
|
||||
bool ensure = false;
|
||||
EndDisp disposition = EndDisp::UNKNOWN;
|
||||
UInt_64 endpointId = 0;
|
||||
UInt_64 system = 0;
|
||||
UInt_64 op = 0;
|
||||
};
|
||||
|
||||
struct Packet
|
||||
{
|
||||
Header header;
|
||||
Serializer<> payload;
|
||||
};
|
||||
|
||||
struct Insurance
|
||||
{
|
||||
Header header;
|
||||
Serializer<> payload;
|
||||
float lastResend;
|
||||
};
|
||||
}
|
||||
|
||||
#ifndef COMMS_IPV4_PAYLOAD
|
||||
#define COMMS_IPV4_PAYLOAD (LWE_IPV4_UDP_PAYLOAD - (UInt_16)sizeof(Header))
|
||||
#endif
|
||||
|
||||
#ifndef COMMS_IPV6_PAYLOAD
|
||||
#define COMMS_IPV6_PAYLOAD (LWE_IPV6_UDP_PAYLOAD - (UInt_16)sizeof(Header))
|
||||
#endif
|
13
include/IO/Window.h
Normal file
13
include/IO/Window.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
#include "Window_W32.h"
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
#if defined(LWE_WS_XCB)
|
||||
#include "Window_XCB.h"
|
||||
#elif defined(LWE_WS_WAYLAND)
|
||||
#include "Window_Way.h"
|
||||
#endif
|
||||
#endif
|
127
include/IO/Window_W32.h
Normal file
127
include/IO/Window_W32.h
Normal file
@@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Array.h"
|
||||
#include "../Str.h"
|
||||
#include "../Vec4.h"
|
||||
#include "BaseWindow.h"
|
||||
#include "HID/InputHandler_RI.h"
|
||||
|
||||
#define WM_HIDE (WM_APP + 1)
|
||||
#define WM_SHOW (WM_APP + 2)
|
||||
#define WM_HIDE_CURSOR (WM_APP + 3)
|
||||
#define WM_SHOW_CURSOR (WM_APP + 4)
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Window : public BaseWindow
|
||||
{
|
||||
private:
|
||||
UInt_32 owner;
|
||||
HINSTANCE instance;
|
||||
HWND hdl;
|
||||
|
||||
static Array<Window*> windows;
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
public:
|
||||
virtual ~Window() override;
|
||||
|
||||
Window();
|
||||
|
||||
Window(const Window &win);
|
||||
|
||||
Window& operator=(const Window &win);
|
||||
|
||||
virtual bool Poll() override;
|
||||
|
||||
///Creates the native window.
|
||||
void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
///Creates the native window.
|
||||
void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
///Creates the native window.
|
||||
void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
///Uses an already existing window to render an overlay.
|
||||
void Use(HWND windowHdl);
|
||||
|
||||
///Closes the window.
|
||||
virtual void Close() override;
|
||||
|
||||
///Shows the window.
|
||||
void Show() override;
|
||||
|
||||
///Hides the window.
|
||||
void Hide() override;
|
||||
|
||||
void SetTitle_32(const Str_32& title) override;
|
||||
|
||||
Str_32 GetTitle_32();
|
||||
|
||||
void SetTitle_16(const Str_16& title) override;
|
||||
|
||||
Str_16 GetTitle_16();
|
||||
|
||||
void SetTitle_8(const Str_8& title) override;
|
||||
|
||||
Str_8 GetTitle_8();
|
||||
|
||||
void SetIcon(const Str_8& filePath);
|
||||
|
||||
/// Sets the windows client scale.
|
||||
/// @param [in] w The width in pixels.
|
||||
/// @param [in] h The height in pixels.
|
||||
void SetClientSize(const Vec2<UInt_32>& size);
|
||||
|
||||
Vec2<UInt_32> GetClientSize();
|
||||
|
||||
/// Gets the windows native handle for the operating system or other native tasks.
|
||||
/// @returns The window's native handle.
|
||||
HWND GetHdl() const;
|
||||
|
||||
/// Retrieves the first window handle that has been created using this library.
|
||||
/// @returns The window's native handle.
|
||||
static HWND GetAvailableHdl();
|
||||
|
||||
HINSTANCE GetInst() const;
|
||||
|
||||
/// Toggles whether the window updates and renders.
|
||||
/// @param [in] toggle The new status.
|
||||
void ToggleEnabled(bool toggle);
|
||||
|
||||
/// Checks whether the window updates and renders.
|
||||
/// @returns The current status.
|
||||
bool IsEnabled();
|
||||
|
||||
/// Sets the windows position on the desktop.
|
||||
/// @param [in] x The x axis in pixels.
|
||||
/// @param [in] y The y axis in pixels.
|
||||
void SetPos(int x, int y);
|
||||
|
||||
/// Gets the windows current position on the desktop.
|
||||
/// @returns The current value.
|
||||
Vec2<Int_32> GetPos();
|
||||
|
||||
virtual void OnResized(const Vec2<UInt_32>& newSize);
|
||||
|
||||
/// Sets the windows scale which includes the border.
|
||||
/// @param [in] w The width in pixels.
|
||||
/// @param [in] h The height in pixels.
|
||||
void SetSize(int w, int h);
|
||||
|
||||
/// Gets the windows current scale.
|
||||
/// @returns The current value.
|
||||
Vec2<Int_32> GetSize();
|
||||
|
||||
void ShowCursor(bool toggle) override;
|
||||
|
||||
void ConstrainCursor(const bool toggle) override;
|
||||
|
||||
protected:
|
||||
void SendMsg(const UINT msg, const WPARAM wParam, const LPARAM lParam);
|
||||
|
||||
};
|
||||
}
|
80
include/IO/Window_Way.h
Normal file
80
include/IO/Window_Way.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseWindow.h"
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include "xdg-shell-client-protocol.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Window : public BaseWindow
|
||||
{
|
||||
private:
|
||||
wl_display* display;
|
||||
wl_registry *registry;
|
||||
wl_compositor* compositor;
|
||||
wl_surface* surface;
|
||||
xdg_wm_base *xdgShell;
|
||||
xdg_surface *xdgSurface;
|
||||
xdg_toplevel *xdgToplevel;
|
||||
|
||||
static void SurfaceConfigure(void *data, xdg_surface *xdg_surface, UInt_32 serial);
|
||||
|
||||
static void ShellPing(void *data, xdg_wm_base *shell, UInt_32 serial);
|
||||
|
||||
static void RegistryHandler(void *data, wl_registry *registry, UInt_32 id, const char *interface, UInt_32 version);
|
||||
|
||||
static void RegistryRemoved(void *data, wl_registry *registry, UInt_32 id);
|
||||
|
||||
public:
|
||||
~Window() override;
|
||||
|
||||
Window();
|
||||
|
||||
void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
void OnCreated() override;
|
||||
|
||||
void Close() override;
|
||||
|
||||
void Show() override;
|
||||
|
||||
void Hide() override;
|
||||
|
||||
bool Poll() override;
|
||||
|
||||
void ShowCursor(bool toggle) override;
|
||||
|
||||
void ConstrainCursor(const bool constrain) override;
|
||||
|
||||
void SetTitle_32(const Str_32& newTitle) override;
|
||||
|
||||
Str_32 GetTitle_32() const override;
|
||||
|
||||
void SetTitle_16(const Str_16& newTitle) override;
|
||||
|
||||
Str_16 GetTitle_16() const override;
|
||||
|
||||
void SetTitle_8(const Str_8& newTitle) override;
|
||||
|
||||
Str_8 GetTitle_8() const override;
|
||||
|
||||
void SetPos(const Vec2_s32& newPos) override;
|
||||
|
||||
Vec2_s32 GetPos() const override;
|
||||
|
||||
void SetScale(const Vec2_u32& newScale) override;
|
||||
|
||||
Vec2_u32 GetScale() const override;
|
||||
|
||||
Serializer<UInt_64> GetClipboard() override;
|
||||
|
||||
void SetClipboard(Serializer<UInt_64> data) override;
|
||||
|
||||
void SetCursorImg(const CursorImg img) override;
|
||||
};
|
||||
}
|
84
include/IO/Window_XCB.h
Normal file
84
include/IO/Window_XCB.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseWindow.h"
|
||||
#include "File.h"
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xinput.h>
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Window : public BaseWindow
|
||||
{
|
||||
protected:
|
||||
friend class Input;
|
||||
|
||||
xcb_connection_t* server;
|
||||
xcb_screen_t* screen;
|
||||
xcb_window_t hdl;
|
||||
xcb_atom_t masks[2];
|
||||
UInt_8 extOpCode;
|
||||
Vector<xcb_generic_event_t*> events;
|
||||
Serializer<UInt_64> clipboard;
|
||||
|
||||
public:
|
||||
Window();
|
||||
|
||||
void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
void Close() override;
|
||||
|
||||
void Show() override;
|
||||
|
||||
void Hide() override;
|
||||
|
||||
bool Poll() override;
|
||||
|
||||
void ShowCursor(bool toggle) override;
|
||||
|
||||
void ConstrainCursor(const bool constrain) override;
|
||||
|
||||
void SetTitle_32(const Str_32& newTitle) override;
|
||||
|
||||
Str_32 GetTitle_32() const override;
|
||||
|
||||
void SetTitle_16(const Str_16& newTitle) override;
|
||||
|
||||
Str_16 GetTitle_16() const override;
|
||||
|
||||
void SetTitle_8(const Str_8& newTitle) override;
|
||||
|
||||
Str_8 GetTitle_8() const override;
|
||||
|
||||
void SetPos(const Vec2_s32& newPos) override;
|
||||
|
||||
Vec2_s32 GetPos() const override;
|
||||
|
||||
void SetScale(const Vec2_u32& newScale) override;
|
||||
|
||||
Vec2_u32 GetScale() const override;
|
||||
|
||||
Serializer<UInt_64> GetClipboard() override;
|
||||
|
||||
void SetClipboard(Serializer<UInt_64> data) override;
|
||||
|
||||
void SetCursorImg(const CursorImg img) override;
|
||||
|
||||
xcb_connection_t* GetServer();
|
||||
|
||||
private:
|
||||
xcb_generic_event_t* RetrieveEvent();
|
||||
|
||||
xcb_atom_t RetrieveAtom(const bool create, const Str_8& name) const;
|
||||
|
||||
xcb_get_property_reply_t* RetrieveProp(const xcb_atom_t prop, const xcb_atom_t type) const;
|
||||
|
||||
void QueryPrimaryDevices();
|
||||
|
||||
Str_8 QueryDeviceName(const UInt_16 id);
|
||||
};
|
||||
}
|
2307
include/IO/xdg-shell-client-protocol.h
Normal file
2307
include/IO/xdg-shell-client-protocol.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user