Merge branch 'main' of github.com:Persson-dev/Blitz

This commit is contained in:
2024-03-05 09:01:15 +01:00
10 changed files with 30 additions and 45 deletions

View File

@@ -0,0 +1,15 @@
#pragma once
namespace blitz {
class NonCopyable {
public:
NonCopyable(const NonCopyable&) = delete;
NonCopyable& operator=(const NonCopyable&) = delete;
protected:
NonCopyable() {}
~NonCopyable() {}
};
} // namespace blitz

View File

@@ -81,19 +81,19 @@ struct Vec4 {
using Vec2uc = Vec2<unsigned int>;
using Vec2uc = Vec2<unsigned char>;
using Vec2i = Vec2<int>;
using Vec2u = Vec2<unsigned int>;
using Vec2f = Vec2<float>;
using Vec2d = Vec2<double>;
using Vec3uc = Vec3<unsigned int>;
using Vec3uc = Vec3<unsigned char>;
using Vec3i = Vec3<int>;
using Vec3u = Vec3<unsigned int>;
using Vec3f = Vec3<float>;
using Vec3d = Vec3<double>;
using Vec4uc = Vec4<unsigned int>;
using Vec4uc = Vec4<unsigned char>;
using Vec4i = Vec4<int>;
using Vec4u = Vec4<unsigned int>;
using Vec4f = Vec4<float>;

View File

@@ -1,5 +0,0 @@
#pragma once
#define REMOVE_COPY(className) \
className(const className&) = delete; \
className& operator=(const className&) = delete

View File

@@ -16,7 +16,7 @@ namespace network {
* \class Connexion
* \brief Represents a network connexion
*/
class Connexion : public protocol::PacketHandler {
class Connexion : public protocol::PacketHandler, private NonCopyable {
protected:
protocol::PacketDispatcher m_Dispatcher;
@@ -72,11 +72,6 @@ class Connexion : public protocol::PacketHandler {
* \param packet The protocol::Packet to send
*/
void SendPacket(const protocol::Packet* packet);
/**
* \brief Disables Connexion copy
*/
REMOVE_COPY(Connexion);
};
} // namespace network

View File

@@ -21,7 +21,7 @@ namespace network {
* \note This class is meant to be created only once in your program. \n
* The easiest thing to do is to create an instance of this class at the top of your **main.cpp**.
*/
class NetworkInitializer {
class NetworkInitializer : private NonCopyable {
public:
/**
* \brief Creates the networking context
@@ -31,8 +31,6 @@ class NetworkInitializer {
* \brief Destroys the networking context
*/
~NetworkInitializer();
REMOVE_COPY(NetworkInitializer);
};
} // namespace network

View File

@@ -14,7 +14,7 @@ namespace network {
* \class TCPListener
* \brief Cross platform abstraction of a TCP socket server
*/
class TCPListener {
class TCPListener : private NonCopyable {
private:
SocketHandle m_Handle;
std::uint16_t m_Port;
@@ -79,11 +79,6 @@ class TCPListener {
int GetMaximumConnections() const {
return m_MaxConnections;
}
/**
* \brief Disables TCPListener copy
*/
REMOVE_COPY(TCPListener);
};
} // namespace network

View File

@@ -1,7 +1,7 @@
#pragma once
#include "blitz/common/DataBuffer.h"
#include "blitz/misc/ClassEntity.h"
#include "blitz/common/NonCopyable.h"
#ifdef _WIN32
#include <winsock2.h>
@@ -40,7 +40,7 @@ typedef int SocketHandle;
* \class TCPSocket
* \brief Cross platform abstraction of a TCP socket
*/
class TCPSocket {
class TCPSocket : private NonCopyable {
public:
/**
* \enum Status
@@ -153,11 +153,6 @@ class TCPSocket {
*/
std::size_t Receive(DataBuffer& buffer, std::size_t amount);
/**
* \brief Disable TCPSocket copy, as it disconnects when destroyed
*/
REMOVE_COPY(TCPSocket);
friend class TCPListener;
};

View File

@@ -1,6 +1,6 @@
#pragma once
#include "blitz/misc/ClassEntity.h"
#include "blitz/common/NonCopyable.h"
#include <vector>
@@ -13,7 +13,7 @@ struct VertexAttribPointer {
unsigned int m_Offset;
};
class ElementBuffer {
class ElementBuffer : private NonCopyable {
private:
unsigned int m_ID = 0;
std::size_t m_TriangleCount;
@@ -33,11 +33,9 @@ class ElementBuffer {
std::size_t GetTriangleCount() const {
return m_TriangleCount;
}
REMOVE_COPY(ElementBuffer);
};
class VertexBuffer {
class VertexBuffer : private NonCopyable {
private:
unsigned int m_ID = 0, m_DataStride;
std::vector<VertexAttribPointer> m_VertexAttribs;
@@ -56,11 +54,9 @@ class VertexBuffer {
void Unbind() const;
void AddVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset);
void BindVertexAttribs() const;
REMOVE_COPY(VertexBuffer);
};
class VertexArray {
class VertexArray : private NonCopyable {
private:
unsigned int m_ID = 0;
ElementBuffer m_ElementBuffer;
@@ -82,8 +78,6 @@ class VertexArray {
void Bind() const;
void Unbind() const;
REMOVE_COPY(VertexArray);
private:
void BindElementArrayBuffer();
};

View File

@@ -49,8 +49,6 @@ class ServerConnexion : public network::Connexion {
virtual bool UpdateSocket();
REMOVE_COPY(ServerConnexion);
private:
void RegisterHandlers();
void CheckKeepAlive();

View File

@@ -46,13 +46,13 @@ std::string ChatPacket::GetTextColor(Vec3uc color) {
ss << std::hex << "\\u";
if (color.r <= 0xF)
ss << 0;
ss << color.r;
ss << +color.r;
if (color.g <= 0xF)
ss << 0;
ss << color.g;
ss << +color.g;
if (color.b <= 0xF)
ss << 0;
ss << color.b;
ss << +color.b;
return ss.str();
}