# Fixes
- Fix LinearAlloc bug not using *sizeof(T) - Add WaitForRead to net backend - Add a Get func to Tween - Skip \r in Text Rendering - Add Citro3D Max Texsize check
This commit is contained in:
parent
13c2869ba8
commit
f75f7067ff
@ -39,7 +39,8 @@ class LinearAlloc : public Allocator<T> {
|
|||||||
LinearAlloc() = default;
|
LinearAlloc() = default;
|
||||||
~LinearAlloc() = default;
|
~LinearAlloc() = default;
|
||||||
|
|
||||||
T* Allocate(size_t n) override { return (T*)linearAlloc(n); }
|
/** Never forget the sizeof(T) again (most painful bug i created) */
|
||||||
|
T* Allocate(size_t n) override { return (T*)linearAlloc(n * sizeof(T)); }
|
||||||
void Deallocate(T* ptr) { linearFree(ptr); }
|
void Deallocate(T* ptr) { linearFree(ptr); }
|
||||||
};
|
};
|
||||||
namespace LI {
|
namespace LI {
|
||||||
|
@ -66,6 +66,20 @@ class NetBackend3DS : public Net::Backend {
|
|||||||
bool Listen(int sock_id, int backlog = 5) {
|
bool Listen(int sock_id, int backlog = 5) {
|
||||||
return listen(sock_id, backlog) != -1;
|
return listen(sock_id, backlog) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WaitForRead(int sock_id, int timeout_ms) override {
|
||||||
|
fd_set set;
|
||||||
|
FD_ZERO(&set);
|
||||||
|
FD_SET(sock_id, &set);
|
||||||
|
|
||||||
|
timeval timeout{};
|
||||||
|
timeout.tv_sec = timeout_ms / 1000;
|
||||||
|
timeout.tv_usec = (timeout_ms % 1000) * 1000;
|
||||||
|
|
||||||
|
int result = select(sock_id + 1, &set, nullptr, nullptr, &timeout);
|
||||||
|
return (result > 0 && FD_ISSET(sock_id, &set));
|
||||||
|
}
|
||||||
|
|
||||||
bool Accept(int sock_id, Net::Socket::Ref client) {
|
bool Accept(int sock_id, Net::Socket::Ref client) {
|
||||||
int client_soc = accept(sock_id, nullptr, nullptr);
|
int client_soc = accept(sock_id, nullptr, nullptr);
|
||||||
if (client_soc == -1) {
|
if (client_soc == -1) {
|
||||||
|
@ -44,7 +44,6 @@ unsigned char li_shader[] = {
|
|||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
size_t li_shader_size = 0x124;
|
size_t li_shader_size = 0x124;
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace LI {
|
namespace LI {
|
||||||
GPU_TEXCOLOR GetTexFmt(Texture::Type type) {
|
GPU_TEXCOLOR GetTexFmt(Texture::Type type) {
|
||||||
@ -170,6 +169,9 @@ PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels,
|
|||||||
PD::LI::Texture::Type type,
|
PD::LI::Texture::Type type,
|
||||||
PD::LI::Texture::Filter filter) {
|
PD::LI::Texture::Filter filter) {
|
||||||
std::cout << "Loading Tex " << std::format("[{}, {}]", w, h) << std::endl;
|
std::cout << "Loading Tex " << std::format("[{}, {}]", w, h) << std::endl;
|
||||||
|
if (w > 1024 || h > 1024) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
// Don't check here as check done before
|
// Don't check here as check done before
|
||||||
PD::LI::Texture::Ref res = PD::LI::Texture::New();
|
PD::LI::Texture::Ref res = PD::LI::Texture::New();
|
||||||
int bpp = GetBPP(type);
|
int bpp = GetBPP(type);
|
||||||
@ -226,4 +228,4 @@ PD::LI::Texture::Ref Backend_C3D::LoadTexture(const std::vector<PD::u8>& pixels,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} // namespace LI
|
} // namespace LI
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
|
@ -33,6 +33,7 @@ SOFTWARE.
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <pd/net/backend.hpp>
|
#include <pd/net/backend.hpp>
|
||||||
@ -76,17 +77,31 @@ class NetBackendDesktop : public PD::Net::Backend {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bind(int sock_id, u16 port) {
|
bool Bind(int sock_id, u16 port) override {
|
||||||
sockaddr_in addr{};
|
sockaddr_in addr{};
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
addr.sin_port = htons(port);
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
||||||
}
|
}
|
||||||
bool Listen(int sock_id, int backlog = 5) {
|
bool Listen(int sock_id, int backlog = 5) override {
|
||||||
return listen(sock_id, backlog) != -1;
|
return listen(sock_id, backlog) != -1;
|
||||||
}
|
}
|
||||||
bool Accept(int sock_id, Net::Socket::Ref client) {
|
|
||||||
|
bool WaitForRead(int sock_id, int timeout_ms) override {
|
||||||
|
fd_set set;
|
||||||
|
FD_ZERO(&set);
|
||||||
|
FD_SET(sock_id, &set);
|
||||||
|
|
||||||
|
timeval timeout{};
|
||||||
|
timeout.tv_sec = timeout_ms / 1000;
|
||||||
|
timeout.tv_usec = (timeout_ms % 1000) * 1000;
|
||||||
|
|
||||||
|
int result = select(sock_id + 1, &set, nullptr, nullptr, &timeout);
|
||||||
|
return (result > 0 && FD_ISSET(sock_id, &set));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Accept(int sock_id, Net::Socket::Ref client) override {
|
||||||
int client_soc = accept(sock_id, nullptr, nullptr);
|
int client_soc = accept(sock_id, nullptr, nullptr);
|
||||||
if (client_soc == GetInvalidRef()) {
|
if (client_soc == GetInvalidRef()) {
|
||||||
return false;
|
return false;
|
||||||
@ -94,17 +109,17 @@ class NetBackendDesktop : public PD::Net::Backend {
|
|||||||
client->pSocket = client_soc;
|
client->pSocket = client_soc;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool Connect(int sock_id, const std::string& ip, u16 port) {
|
bool Connect(int sock_id, const std::string& ip, u16 port) override {
|
||||||
sockaddr_in addr{};
|
sockaddr_in addr{};
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
addr.sin_port = htons(port);
|
||||||
inet_pton(AF_INET, ip.c_str(), &addr.sin_addr);
|
inet_pton(AF_INET, ip.c_str(), &addr.sin_addr);
|
||||||
return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
||||||
}
|
}
|
||||||
int Send(int sock_id, const std::string& data) {
|
int Send(int sock_id, const std::string& data) override {
|
||||||
return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0);
|
return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0);
|
||||||
}
|
}
|
||||||
int Receive(int sock_id, std::string& data, int size = 1024) {
|
int Receive(int sock_id, std::string& data, int size = 1024) override {
|
||||||
char* tmp = new char[size];
|
char* tmp = new char[size];
|
||||||
int res = recv(sock_id, tmp, size, 0);
|
int res = recv(sock_id, tmp, size, 0);
|
||||||
if (res > 0) {
|
if (res > 0) {
|
||||||
|
@ -37,16 +37,28 @@ namespace PD {
|
|||||||
* @note Safetey checks are disabled for maximum performance
|
* @note Safetey checks are disabled for maximum performance
|
||||||
*/
|
*/
|
||||||
class PD_CORE_API Color {
|
class PD_CORE_API Color {
|
||||||
|
private:
|
||||||
|
/** Red Value */
|
||||||
|
u8 m_r;
|
||||||
|
/** Green Value */
|
||||||
|
u8 m_g;
|
||||||
|
/** Blue Value */
|
||||||
|
u8 m_b;
|
||||||
|
/** Alpha Value */
|
||||||
|
u8 m_a;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Default Constructor (all variables are set to 0)
|
* Default Constructor (all variables are set to 0)
|
||||||
*/
|
*/
|
||||||
Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
// Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
||||||
|
constexpr Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
||||||
|
constexpr ~Color() {}
|
||||||
/**
|
/**
|
||||||
* Constructor for 32Bit Color Input
|
* Constructor for 32Bit Color Input
|
||||||
* @param color 32Bit Color value
|
* @param color 32Bit Color value
|
||||||
*/
|
*/
|
||||||
Color(u32 color) {
|
constexpr Color(u32 color) {
|
||||||
m_a = (color >> 24) & 0xff;
|
m_a = (color >> 24) & 0xff;
|
||||||
m_b = (color >> 16) & 0xff;
|
m_b = (color >> 16) & 0xff;
|
||||||
m_g = (color >> 8) & 0xff;
|
m_g = (color >> 8) & 0xff;
|
||||||
@ -59,7 +71,7 @@ class PD_CORE_API Color {
|
|||||||
* @param b Blue Value
|
* @param b Blue Value
|
||||||
* @param a Optional Alpha Value (Defaults to 255)
|
* @param a Optional Alpha Value (Defaults to 255)
|
||||||
*/
|
*/
|
||||||
Color(u8 r, u8 g, u8 b, u8 a = 255) {
|
constexpr Color(int r, int g, int b, int a = 255) {
|
||||||
m_r = r;
|
m_r = r;
|
||||||
m_g = g;
|
m_g = g;
|
||||||
m_b = b;
|
m_b = b;
|
||||||
@ -73,7 +85,7 @@ class PD_CORE_API Color {
|
|||||||
* @param a Optional Alpha Value (Defaults to 1.0f)
|
* @param a Optional Alpha Value (Defaults to 1.0f)
|
||||||
* @note There is no Check if the number is between 0.0 and 1.0
|
* @note There is no Check if the number is between 0.0 and 1.0
|
||||||
*/
|
*/
|
||||||
Color(float r, float g, float b, float a = 1.f) {
|
constexpr Color(float r, float g, float b, float a = 1.f) {
|
||||||
m_r = static_cast<u8>(255.f * r);
|
m_r = static_cast<u8>(255.f * r);
|
||||||
m_g = static_cast<u8>(255.f * g);
|
m_g = static_cast<u8>(255.f * g);
|
||||||
m_b = static_cast<u8>(255.f * b);
|
m_b = static_cast<u8>(255.f * b);
|
||||||
@ -87,7 +99,7 @@ class PD_CORE_API Color {
|
|||||||
/**
|
/**
|
||||||
* Unused Deconstructor
|
* Unused Deconstructor
|
||||||
*/
|
*/
|
||||||
~Color() {}
|
// ~Color() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Color Object by Hex String
|
* Create Color Object by Hex String
|
||||||
@ -196,15 +208,24 @@ class PD_CORE_API Color {
|
|||||||
* @return 32Bit Color Value
|
* @return 32Bit Color Value
|
||||||
*/
|
*/
|
||||||
operator u32() const { return Get(); }
|
operator u32() const { return Get(); }
|
||||||
|
|
||||||
private:
|
|
||||||
/** Red Value */
|
|
||||||
u8 m_r;
|
|
||||||
/** Green Value */
|
|
||||||
u8 m_g;
|
|
||||||
/** Blue Value */
|
|
||||||
u8 m_b;
|
|
||||||
/** Alpha Value */
|
|
||||||
u8 m_a;
|
|
||||||
};
|
};
|
||||||
|
namespace Colors {
|
||||||
|
constexpr Color White = Color(1.f, 1.f, 1.f, 1.f);
|
||||||
|
constexpr Color Black = Color(0.f, 0.f, 0.f, 1.f);
|
||||||
|
constexpr Color Red = Color(1.f, 0.f, 0.f, 1.f);
|
||||||
|
constexpr Color Green = Color(0.f, 1.f, 0.f, 1.f);
|
||||||
|
constexpr Color Blue = Color(0.f, 0.f, 1.f, 1.f);
|
||||||
|
constexpr Color Yellow = Color(1.f, 1.f, 0.f, 1.f);
|
||||||
|
constexpr Color Cyan = Color(0.f, 1.f, 1.f, 1.f);
|
||||||
|
constexpr Color Magenta = Color(1.f, 0.f, 1.f, 1.f);
|
||||||
|
constexpr Color Gray = Color(0.5f, 0.5f, 0.5f, 1.f);
|
||||||
|
constexpr Color LightGray = Color(0.75f, 0.75f, 0.75f, 1.f);
|
||||||
|
constexpr Color DarkGray = Color(0.25f, 0.25f, 0.25f, 1.f);
|
||||||
|
constexpr Color Orange = Color(1.f, 0.65f, 0.f, 1.f);
|
||||||
|
constexpr Color Pink = Color(1.f, 0.75f, 0.8f, 1.f);
|
||||||
|
constexpr Color Brown = Color(0.6f, 0.4f, 0.2f, 1.f);
|
||||||
|
constexpr Color Purple = Color(0.5f, 0.f, 0.5f, 1.f);
|
||||||
|
constexpr Color Teal = Color(0.f, 0.5f, 0.5f, 1.f);
|
||||||
|
constexpr Color Transparent = Color(0.f, 0.f, 0.f, 0.f);
|
||||||
|
} // namespace Colors
|
||||||
} // namespace PD
|
} // namespace PD
|
@ -150,11 +150,7 @@ class Tween {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
T Get() const {
|
||||||
* Operator that returns the current value calculated
|
|
||||||
* by time and effect
|
|
||||||
*/
|
|
||||||
operator T() {
|
|
||||||
float t = 0.f;
|
float t = 0.f;
|
||||||
switch (effect) {
|
switch (effect) {
|
||||||
case EaseInQuad:
|
case EaseInQuad:
|
||||||
@ -203,6 +199,12 @@ class Tween {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operator that returns the current value calculated
|
||||||
|
* by time and effect
|
||||||
|
*/
|
||||||
|
operator T() const { return Get(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Animation Effect */
|
/** Animation Effect */
|
||||||
Effect effect;
|
Effect effect;
|
||||||
|
@ -40,6 +40,7 @@ class Backend {
|
|||||||
virtual int GetInvalidRef() const = 0;
|
virtual int GetInvalidRef() const = 0;
|
||||||
virtual bool Bind(int sock_id, u16 port) = 0;
|
virtual bool Bind(int sock_id, u16 port) = 0;
|
||||||
virtual bool Listen(int sock_id, int backlog = 5) = 0;
|
virtual bool Listen(int sock_id, int backlog = 5) = 0;
|
||||||
|
virtual bool WaitForRead(int sock_id, int timeout_ms) = 0;
|
||||||
virtual bool Accept(int sock_id, Socket::Ref client) = 0;
|
virtual bool Accept(int sock_id, Socket::Ref client) = 0;
|
||||||
virtual bool Connect(int sock_id, const std::string& ip, u16 port) = 0;
|
virtual bool Connect(int sock_id, const std::string& ip, u16 port) = 0;
|
||||||
virtual int Send(int sock_id, const std::string& data) = 0;
|
virtual int Send(int sock_id, const std::string& data) = 0;
|
||||||
|
@ -46,6 +46,7 @@ class PD_NET_API Socket {
|
|||||||
bool Create();
|
bool Create();
|
||||||
bool Bind(u16 port);
|
bool Bind(u16 port);
|
||||||
bool Listen(int backlog = 5);
|
bool Listen(int backlog = 5);
|
||||||
|
bool WaitForRead(int timeout_ms);
|
||||||
bool Accept(Socket::Ref client);
|
bool Accept(Socket::Ref client);
|
||||||
bool Connect(const std::string& ip, u16 port);
|
bool Connect(const std::string& ip, u16 port);
|
||||||
int Send(const std::string& data);
|
int Send(const std::string& data);
|
||||||
|
@ -239,7 +239,7 @@ PD_LITHIUM_API void Font::CmdTextEx(Vec<Command::Ref> &cmds, const fvec2 &pos,
|
|||||||
cmd->Tex = Tex;
|
cmd->Tex = Tex;
|
||||||
for (auto &jt : wline) {
|
for (auto &jt : wline) {
|
||||||
auto cp = GetCodepoint(jt);
|
auto cp = GetCodepoint(jt);
|
||||||
if (cp.pInvalid && jt != '\n' && jt != '\t') {
|
if ((cp.pInvalid && jt != '\n' && jt != '\t') && jt != '\r') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Tex != cp.Tex) {
|
if (Tex != cp.Tex) {
|
||||||
|
@ -38,6 +38,10 @@ PD_NET_API bool Socket::Listen(int backlog) {
|
|||||||
return backend->Listen(pSocket, backlog);
|
return backend->Listen(pSocket, backlog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PD_NET_API bool Socket::WaitForRead(int timeout_ms) {
|
||||||
|
return backend->WaitForRead(pSocket, timeout_ms);
|
||||||
|
}
|
||||||
|
|
||||||
PD_NET_API bool Socket::Accept(Socket::Ref client) {
|
PD_NET_API bool Socket::Accept(Socket::Ref client) {
|
||||||
return backend->Accept(pSocket, client);
|
return backend->Accept(pSocket, client);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user