Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Descent3/mission_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ bool msn_DownloadWithStatus(const char *url, const std::filesystem::path &filena
}

httplib::Result (D3::HttpClient::*hcg)(const std::string &, const httplib::ContentReceiver &,
const httplib::Progress &) = &D3::HttpClient::Get;
const D3::HttpClient::Progress &) = &D3::HttpClient::Get;
std::fstream in(qualfile, std::ios::binary | std::ios::trunc | std::ios::out);
auto async_task = std::async(
std::launch::async, hcg, &http_client, download_uri,
Expand Down
125 changes: 71 additions & 54 deletions lib/vecmat_external.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,47 +49,39 @@
#include <limits>
#include <numeric>

static constexpr inline bool VM_ISPOW2(uintmax_t x) { return (x && (!(x & (x-1)))); }

template<typename T>
static constexpr inline int VM_BIT_SCAN_REVERSE_CONST(const T n) noexcept {
if (n == 0) return -1;
if (VM_ISPOW2(n)) return n;
T a = n, b = 0, j = std::numeric_limits<T>::digits, k = 0;
do {
j >>= 1;
k = (T)1 << j;
if (a >= k) {
a >>= j;
b += j;
}
} while (j > 0);
return int(b);
}

template<typename T>
static constexpr inline T VM_BIT_CEIL(T x) noexcept { return T(1) << (VM_BIT_SCAN_REVERSE_CONST((T)x-1) + 1); };

template<typename T>
static constexpr inline T VM_BIT_FLOOR(T x) noexcept { return x == 0 || VM_ISPOW2(x) ? x : ((VM_BIT_FLOOR(x >> 1)) << 1); }

#ifdef _MSVC_LANG
#define VM_ALIGN(n) __declspec(align(n))
#else
#define VM_ALIGN(n) __attribute__((aligned(n)))
#endif
#define BITOP_RUP01__(x) ( (x) | ( (x) >> 1))
#define BITOP_RUP02__(x) (BITOP_RUP01__(x) | (BITOP_RUP01__(x) >> 2))
#define BITOP_RUP04__(x) (BITOP_RUP02__(x) | (BITOP_RUP02__(x) >> 4))
#define BITOP_RUP08__(x) (BITOP_RUP04__(x) | (BITOP_RUP04__(x) >> 8))
#define BITOP_RUP16__(x) (BITOP_RUP08__(x) | (BITOP_RUP08__(x) >> 16))
#define BITOP_RUP32__(x) (BITOP_RUP16__(x) | (BITOP_RUP16__(x) >> 32))
#define BITOP_RUP64__(x) (BITOP_RUP32__(x) | (BITOP_RUP32__(x) >> 64))

constexpr static inline uintmax_t VM_BIT_CEIL (uintmax_t x) {
switch(std::numeric_limits<uintmax_t>::digits)
{
case 8: return (BITOP_RUP04__(uint8_t (x) - 1) + 1);
case 16: return (BITOP_RUP08__(uint16_t(x) - 1) + 1);
default:
case 32: return (BITOP_RUP16__(uint32_t(x) - 1) + 1);
case 64: return (BITOP_RUP32__(uint64_t(x) - 1) + 1);
}
}

constexpr static inline bool VM_ISPOW2 (uintmax_t x) { return x && (!(x & (x-1))); }
constexpr static inline uintmax_t VM_BIT_FLOOR(uintmax_t x) { return ((x == 0) || VM_ISPOW2(x) ? x : ((VM_BIT_FLOOR(x >> 1)) << 1)); }

enum class align
{
none = 0 << 0,
scalar = 1 << 1,
vector = 2 << 1,
matrix = 3 << 1,
adaptive = 4 << 1,
scalar = 1 << 0,
linear = 1 << 1,
matrix = 1 << 2,
adaptive = 1 << 3,
};

template<typename T, size_t N, enum align A = align::adaptive, size_t N_POW2 = VM_BIT_CEIL(N)>
struct alignas(N==N_POW2 && A != align::scalar || A == align::vector ? alignof(T) * N_POW2 : alignof(T)) vec : std::array<T,N> {
template<typename T, size_t N, enum align A = align::adaptive, size_t N_POW2 = VM_BIT_CEIL(N), size_t T_S = std::max<size_t>(alignof(T), sizeof(T))>
struct alignas((((N == N_POW2) && (A != align::scalar)) || ((A == align::linear) || (A == align::matrix))) ? N_POW2 * T_S : T_S) vec : std::array<T,N> {

template<size_t N_DST = N, enum align A_DST = align::adaptive>
operator vec<T,N_DST,A_DST>() { return *reinterpret_cast<vec<T,N_DST,A_DST>*>(this); }
Expand Down Expand Up @@ -287,8 +279,8 @@ constexpr static inline scalar dot(const vec<T,N_A,A_A> &a, const vec<T,N_B,A_B>
template<size_t N_A = 3, size_t N_B = 3, enum align A_A = align::adaptive, enum align A_B = align::adaptive>
constexpr static inline vec<T,3> cross3(const vec<T,N_A,A_A> &a, const vec<T,N_B,A_B> &b)
{
return vec<T,3,align::vector>{a.y()*b.z(), a.z()*b.x(), a.x()*b.y()}
- vec<T,3,align::vector>{b.y()*a.z(), b.z()*a.x(), b.x()*a.y()};
return vec<T,3,align::linear>{a.y()*b.z(), a.z()*b.x(), a.x()*b.y()}
- vec<T,3,align::linear>{b.y()*a.z(), b.z()*a.x(), b.x()*a.y()};
}
constexpr inline scalar mag() const { return (scalar)sqrt(dot((*this),(*this))); }

Expand All @@ -300,17 +292,17 @@ static constexpr inline scalar distance(const vec<T,N_A,A_A> &a, const vec<T,N_B

using vector = vec<scalar,3>;
using vector_array = vector;
using aligned_vector = vec<scalar,3,align::vector>;
using aligned_vector = vec<scalar,3,align::linear>;
using aligned_vector_array = aligned_vector;

using vector4 = vec<scalar,4>;
using vector4_array = vector4;
using aligned_vector4 = vec<scalar,4,align::vector>;
using aligned_vector4 = vec<scalar,4,align::linear>;
using aligned_vector4_array = aligned_vector4;

using angvec = vec<angle,3>;
using angvec_array = angvec;
using aligned_angvec = vec<angle,3,align::vector>;
using aligned_angvec = vec<angle,3,align::linear>;
using aligned_angvec_array = aligned_angvec;

// Set an angvec to {0,0,0}
Expand Down Expand Up @@ -339,9 +331,31 @@ constexpr static inline const matrix ne()
{
return matrix{ vector{}, vector{}, vector{} };
}
constexpr inline void set_col(size_t i, const vector v)
{
a2d[0][i % 3] = v[0];
a2d[1][i % 3] = v[1];
a2d[2][i % 3] = v[2];
}
constexpr inline vector col(size_t i) const
{
return vector{ a2d[0][i % 3], a2d[1][i % 3], a2d[2][i % 3] };
}
constexpr inline matrix transposed() const
{
return matrix{ col(0), col(1), col(2) };
}
constexpr inline scalar det() const
{
scalar dst = scalar(0);
for(size_t i = 0; i < 3; i++)
dst += a2d[0][i] * (a2d[1][(i+1) % 3] * a2d[2][(i+2) % 3]
- a2d[1][(i+2) % 3] * a2d[2][(i+1) % 3]);
return dst;
}
};

constexpr matrix IDENTITY_MATRIX = matrix::id();
constexpr matrix IDENTITY_MATRIX = { vector::id(0), vector::id(1), vector::id(2) };

struct alignas(alignof(vector4) * 4) matrix4 {
constexpr static const size_t RIGHT_HAND = 0;
Expand All @@ -366,6 +380,21 @@ constexpr static inline const matrix4 ne()
{
return matrix4{ vector4{}, vector4{}, vector4{}, vector4{} };
}
constexpr inline void set_col(size_t i, const vector4 v)
{
a2d[0][i % 4] = v[0];
a2d[1][i % 4] = v[1];
a2d[2][i % 4] = v[2];
a2d[3][i % 4] = v[3];
}
constexpr inline vector4 col(size_t i) const
{
return vector4{ a2d[0][i % 4], a2d[1][i % 4], a2d[2][i % 4], a2d[2][i % 4] };
}
constexpr inline matrix4 transposed() const
{
return matrix4{ col(0), col(1), col(2), col(3) };
}
};

// Adds 2 matrices
Expand Down Expand Up @@ -436,19 +465,7 @@ static inline matrix operator/=(matrix &src, float n) { return (src = src / n);

// Matrix transpose
static inline matrix operator~(matrix m) {
float t;

t = m.uvec.x();
m.uvec.x() = m.rvec.y();
m.rvec.y() = t;
t = m.fvec.x();
m.fvec.x() = m.rvec.z();
m.rvec.z() = t;
t = m.fvec.y();
m.fvec.y() = m.uvec.z();
m.uvec.z() = t;

return m;
return m.transposed();
}

// Apply a matrix to a vector
Expand Down
4 changes: 2 additions & 2 deletions netcon/inetfile/httpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ httplib::Result HttpClient::Get(const std::string &URIPath) {
return m_client->Get(URIPath);
}

httplib::Result HttpClient::Get(const std::string &URIPath, const httplib::Progress &progress) {
httplib::Result HttpClient::Get(const std::string &URIPath, const HttpClient::Progress &progress) {
return m_client->Get(URIPath, progress);
}

Expand All @@ -39,7 +39,7 @@ httplib::Result HttpClient::Get(const std::string &URIPath, const httplib::Conte
}

httplib::Result HttpClient::Get(const std::string &URIPath, const httplib::ContentReceiver &content_receiver,
const httplib::Progress &progress) {
const HttpClient::Progress &progress) {
return m_client->Get(URIPath, content_receiver, progress);
}

Expand Down
5 changes: 3 additions & 2 deletions netcon/inetfile/httpclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace D3 {

class HttpClient {
public:
using Progress = std::function<bool(size_t current, size_t total)>;
/**
* Constructor for HttpClient
* @param URL request URL, should be in form of http://example.com. Don't add "/" on the end as it's part of URIPath.
Expand All @@ -46,12 +47,12 @@ class HttpClient {
* @param URIPath requested path (for example, "/some_dir/my_file.txt")
* @return standard HTTP code. 200 means is OK.
*/
httplib::Result Get(const std::string &URIPath, const httplib::Progress &progress);
httplib::Result Get(const std::string &URIPath, const HttpClient::Progress &progress);

httplib::Result Get(const std::string &URIPath, const httplib::ContentReceiver &content_receiver);

httplib::Result Get(const std::string &URIPath, const httplib::ContentReceiver &content_receiver,
const httplib::Progress &progress);
const HttpClient::Progress &progress);

void SetProxy(const std::string &proxy_host, uint16_t port);

Expand Down
22 changes: 5 additions & 17 deletions vecmat/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,9 @@ void vm_MatrixMulTMatrix(matrix *dest, const matrix *src0, const matrix *src1) {

ASSERT((dest != src0) && (dest != src1));

dest->rvec.x() = src0->rvec.x() * src1->rvec.x() + src0->uvec.x() * src1->uvec.x() + src0->fvec.x() * src1->fvec.x();
dest->uvec.x() = src0->rvec.x() * src1->rvec.y() + src0->uvec.x() * src1->uvec.y() + src0->fvec.x() * src1->fvec.y();
dest->fvec.x() = src0->rvec.x() * src1->rvec.z() + src0->uvec.x() * src1->uvec.z() + src0->fvec.x() * src1->fvec.z();

dest->rvec.y() = src0->rvec.y() * src1->rvec.x() + src0->uvec.y() * src1->uvec.x() + src0->fvec.y() * src1->fvec.x();
dest->uvec.y() = src0->rvec.y() * src1->rvec.y() + src0->uvec.y() * src1->uvec.y() + src0->fvec.y() * src1->fvec.y();
dest->fvec.y() = src0->rvec.y() * src1->rvec.z() + src0->uvec.y() * src1->uvec.z() + src0->fvec.y() * src1->fvec.z();

dest->rvec.z() = src0->rvec.z() * src1->rvec.x() + src0->uvec.z() * src1->uvec.x() + src0->fvec.z() * src1->fvec.x();
dest->uvec.z() = src0->rvec.z() * src1->rvec.y() + src0->uvec.z() * src1->uvec.y() + src0->fvec.z() * src1->fvec.y();
dest->fvec.z() = src0->rvec.z() * src1->rvec.z() + src0->uvec.z() * src1->uvec.z() + src0->fvec.z() * src1->fvec.z();
dest->set_col(0, src0->rvec.x() * src1->rvec + src0->uvec.x() * src1->uvec + src0->fvec.x() * src1->fvec);
dest->set_col(1, src0->rvec.y() * src1->rvec + src0->uvec.y() * src1->uvec + src0->fvec.y() * src1->fvec);
dest->set_col(2, src0->rvec.z() * src1->rvec + src0->uvec.z() * src1->uvec + src0->fvec.z() * src1->fvec);
}

matrix operator*(const matrix &src0, const matrix &src1) {
Expand Down Expand Up @@ -612,9 +604,7 @@ angvec *vm_ExtractAnglesFromMatrix(angvec *a, const matrix *m) {

// returns the value of a determinant
scalar calc_det_value(const matrix *det) {
return det->rvec.x() * det->uvec.y() * det->fvec.z() - det->rvec.x() * det->uvec.z() * det->fvec.y() -
det->rvec.y() * det->uvec.x() * det->fvec.z() + det->rvec.y() * det->uvec.z() * det->fvec.x() +
det->rvec.z() * det->uvec.x() * det->fvec.y() - det->rvec.z() * det->uvec.y() * det->fvec.x();
return det->det();
}

// computes the delta angle between two vectors.
Expand Down Expand Up @@ -762,9 +752,7 @@ scalar vm_GetCentroidFast(vector *centroid, const vector *src, int nv) {

// creates a completely random, non-normalized vector with a range of values from -1023 to +1024 values)
void vm_MakeRandomVector(vector *vec) {
vec->x() = ps_rand() - D3_RAND_MAX / 2;
vec->y() = ps_rand() - D3_RAND_MAX / 2;
vec->z() = ps_rand() - D3_RAND_MAX / 2;
vec->fill(ps_rand() - D3_RAND_MAX / 2);
}

// Given a set of points, computes the minimum bounding sphere of those points
Expand Down
Loading