From 5411a40f2a8ce23dbf0cd6a8d64512b724c48ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 25 Sep 2020 09:33:42 +0200 Subject: [PATCH 1/7] TimeUtil.cpp cleanup --- Common/TimeUtil.cpp | 33 +++++---------------------------- Common/TimeUtil.h | 17 ----------------- 2 files changed, 5 insertions(+), 45 deletions(-) diff --git a/Common/TimeUtil.cpp b/Common/TimeUtil.cpp index 41986021c9..5b8a0c2611 100644 --- a/Common/TimeUtil.cpp +++ b/Common/TimeUtil.cpp @@ -20,9 +20,9 @@ static double curtime = 0; #ifdef _WIN32 -LARGE_INTEGER frequency; -double frequencyMult; -LARGE_INTEGER startTime; +static LARGE_INTEGER frequency; +static double frequencyMult; +static LARGE_INTEGER startTime; double time_now_d() { if (frequency.QuadPart == 0) { @@ -39,8 +39,8 @@ double time_now_d() { #else -uint64_t _frequency = 0; -uint64_t _starttime = 0; +static uint64_t _frequency = 0; +static uint64_t _starttime = 0; double time_now_d() { static time_t start; @@ -64,26 +64,3 @@ void sleep_ms(int ms) { usleep(ms * 1000); #endif } - -LoggingDeadline::LoggingDeadline(const char *name, int ms) : name_(name), endCalled_(false) { - totalTime_ = (double)ms * 0.001; - endTime_ = time_now_d() + totalTime_; -} - -LoggingDeadline::~LoggingDeadline() { - if (!endCalled_) - End(); -} - -bool LoggingDeadline::End() { - endCalled_ = true; - double now = time_now_d(); - if (now > endTime_) { - double late = (now - endTime_); - double totalTime = late + totalTime_; - ERROR_LOG(SYSTEM, "===== %0.2fms DEADLINE PASSED FOR %s at %0.2fms - %0.2fms late =====", totalTime_ * 1000.0, name_, 1000.0 * totalTime, 1000.0 * late); - return false; - } - return true; -} - diff --git a/Common/TimeUtil.h b/Common/TimeUtil.h index b6362cac4e..c19e98f5ad 100644 --- a/Common/TimeUtil.h +++ b/Common/TimeUtil.h @@ -1,24 +1,7 @@ #pragma once -// http://linux.die.net/man/3/clock_gettime - // Seconds. double time_now_d(); // Sleep. Does not necessarily have millisecond granularity, especially on Windows. void sleep_ms(int ms); - -// Can be sprinkled around the code to make sure that thing don't take -// unexpectedly long. What that means is up to you. -class LoggingDeadline { -public: - LoggingDeadline(const char *name, int deadline_in_ms); - ~LoggingDeadline(); - bool End(); - -private: - const char *name_; - bool endCalled_; - double totalTime_; - double endTime_; -}; From 204fbe463eb7b5da9239955e28de411c656f85af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 25 Sep 2020 09:33:56 +0200 Subject: [PATCH 2/7] Delete unused backtrace.cpp --- CMakeLists.txt | 2 -- UWP/NativeUWP/NativeUWP.vcxproj | 2 -- UWP/NativeUWP/NativeUWP.vcxproj.filters | 6 ------ ext/native/Android.mk | 1 - ext/native/base/CMakeLists.txt | 2 +- ext/native/base/backtrace.cpp | 22 ---------------------- ext/native/base/backtrace.h | 3 --- ext/native/native.vcxproj | 2 -- ext/native/native.vcxproj.filters | 8 +------- libretro/Makefile.common | 1 - 10 files changed, 2 insertions(+), 47 deletions(-) delete mode 100644 ext/native/base/backtrace.cpp delete mode 100644 ext/native/base/backtrace.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e83e590f44..006843ac21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -939,8 +939,6 @@ endif() add_library(native STATIC ${nativeExtra} - ext/native/base/backtrace.cpp - ext/native/base/backtrace.h ext/native/base/basictypes.h ext/native/base/buffer.cpp ext/native/base/buffer.h diff --git a/UWP/NativeUWP/NativeUWP.vcxproj b/UWP/NativeUWP/NativeUWP.vcxproj index 0fba453b04..9fe46fd1b6 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj +++ b/UWP/NativeUWP/NativeUWP.vcxproj @@ -379,7 +379,6 @@ - @@ -473,7 +472,6 @@ - diff --git a/UWP/NativeUWP/NativeUWP.vcxproj.filters b/UWP/NativeUWP/NativeUWP.vcxproj.filters index 8835c898dd..b955c76d5f 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj.filters +++ b/UWP/NativeUWP/NativeUWP.vcxproj.filters @@ -64,9 +64,6 @@ - - base - base @@ -475,9 +472,6 @@ - - base - base diff --git a/ext/native/Android.mk b/ext/native/Android.mk index d95685387d..75bf2b31be 100644 --- a/ext/native/Android.mk +++ b/ext/native/Android.mk @@ -7,7 +7,6 @@ include $(CLEAR_VARS) LOCAL_MODULE := libnative LOCAL_ARM_MODE := arm LOCAL_SRC_FILES :=\ - base/backtrace.cpp \ base/buffer.cpp \ base/display.cpp \ base/colorutil.cpp \ diff --git a/ext/native/base/CMakeLists.txt b/ext/native/base/CMakeLists.txt index 7044873bbe..1e4f0530dd 100644 --- a/ext/native/base/CMakeLists.txt +++ b/ext/native/base/CMakeLists.txt @@ -3,7 +3,7 @@ set(SRCS ../thread/threadutil.cpp display.cpp buffer.cpp - backtrace.cpp) +) add_library(base STATIC ${SRCS}) diff --git a/ext/native/base/backtrace.cpp b/ext/native/base/backtrace.cpp deleted file mode 100644 index 2b5cddb972..0000000000 --- a/ext/native/base/backtrace.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "base/backtrace.h" - -#if (defined(__GLIBC__) && !defined(__UCLIBC__)) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) -#include -#include - -static void *backtrace_buffer[128]; - -void PrintBacktraceToStderr() { - int num_addrs = backtrace(backtrace_buffer, 128); - backtrace_symbols_fd(backtrace_buffer, num_addrs, STDERR_FILENO); -} - -#else - -#include - -void PrintBacktraceToStderr() { - fprintf(stderr, "No backtrace available to print on this platform\n"); -} - -#endif diff --git a/ext/native/base/backtrace.h b/ext/native/base/backtrace.h deleted file mode 100644 index 4ff0917f30..0000000000 --- a/ext/native/base/backtrace.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void PrintBacktraceToStderr(); diff --git a/ext/native/native.vcxproj b/ext/native/native.vcxproj index 338f014265..ccd6b2d7f5 100644 --- a/ext/native/native.vcxproj +++ b/ext/native/native.vcxproj @@ -382,7 +382,6 @@ - @@ -490,7 +489,6 @@ - diff --git a/ext/native/native.vcxproj.filters b/ext/native/native.vcxproj.filters index 6f6f940372..9363be3e69 100644 --- a/ext/native/native.vcxproj.filters +++ b/ext/native/native.vcxproj.filters @@ -131,9 +131,6 @@ ui - - base - math @@ -439,9 +436,6 @@ ui - - base - math @@ -907,4 +901,4 @@ {5b740c6f-8dbc-4529-9114-6564b37b3548} - \ No newline at end of file + diff --git a/libretro/Makefile.common b/libretro/Makefile.common index f5c2ef547f..b53cce49a3 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -214,7 +214,6 @@ SOURCES_CXX += \ $(GPUDIR)/GLES/ShaderManagerGLES.cpp \ $(GPUDIR)/GLES/StateMappingGLES.cpp \ $(GPUDIR)/GLES/StencilBufferGLES.cpp \ - $(EXTDIR)/native/base/backtrace.cpp \ $(EXTDIR)/native/base/buffer.cpp \ $(EXTDIR)/native/base/colorutil.cpp \ $(EXTDIR)/native/base/display.cpp \ From 536d881626e39feab4ca252c8e12804abfebed4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 29 Sep 2020 00:35:38 +0200 Subject: [PATCH 3/7] Very minor optimization (divisions by constants are faster unsigned) --- GPU/GPUCommon.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 66bfc80fe9..da92f820c4 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -2337,9 +2337,9 @@ void GPUCommon::Execute_Unknown(u32 op, u32 diff) { } void GPUCommon::FastLoadBoneMatrix(u32 target) { - const int num = gstate.boneMatrixNumber & 0x7F; - const int mtxNum = num / 12; - uint32_t uniformsToDirty = DIRTY_BONEMATRIX0 << mtxNum; + const u32 num = gstate.boneMatrixNumber & 0x7F; + const u32 mtxNum = num / 12; + u32 uniformsToDirty = DIRTY_BONEMATRIX0 << mtxNum; if (num != 12 * mtxNum) { uniformsToDirty |= DIRTY_BONEMATRIX0 << ((mtxNum + 1) & 7); } From 30ecde5bc94c95950cc750133c59861a38497d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 29 Sep 2020 00:41:32 +0200 Subject: [PATCH 4/7] Delete some unused string functions --- ext/native/base/stringutil.cpp | 53 ---------------------------------- ext/native/base/stringutil.h | 19 ------------ ext/native/file/ini_file.h | 2 +- ext/native/ui/view.cpp | 3 +- ext/native/ui/viewgroup.cpp | 3 +- 5 files changed, 3 insertions(+), 77 deletions(-) diff --git a/ext/native/base/stringutil.cpp b/ext/native/base/stringutil.cpp index b3a992c711..965c458040 100644 --- a/ext/native/base/stringutil.cpp +++ b/ext/native/base/stringutil.cpp @@ -34,33 +34,12 @@ std::string LineNumberString(const std::string &str) { return output.str(); } -void StringTrimEndNonAlphaNum(char *str) { - ssize_t n = strlen(str); - while (!isalnum(str[n]) && n >= 0) { - str[n--] = '\0'; - } -} - void SkipSpace(const char **ptr) { while (**ptr && isspace(**ptr)) { (*ptr)++; } } -void StringUpper(char *str) { - while (*str) { - *str = toupper(*str); - str++; - } -} - -void StringUpper(char *str, int len) { - while (len--) { - *str = toupper(*str); - str++; - } -} - void DataToHexString(const uint8_t *data, size_t size, std::string *output) { Buffer buffer; for (size_t i = 0; i < size; i++) { @@ -140,11 +119,6 @@ std::string StringFromInt(int value) return temp; } -std::string StringFromBool(bool value) -{ - return value ? "True" : "False"; -} - // Turns " hej " into "hej". Also handles tabs. std::string StripSpaces(const std::string &str) { @@ -167,27 +141,6 @@ std::string StripQuotes(const std::string& s) return s; } -// For Debugging. Read out an u8 array. -std::string ArrayToString(const uint8_t *data, uint32_t size, int line_len, bool spaces) -{ - std::ostringstream oss; - oss << std::setfill('0') << std::hex; - - for (int line = 0; size; ++data, --size) - { - oss << std::setw(2) << (int)*data; - if (line_len == ++line) - { - oss << '\n'; - line = 0; - } - else if (spaces) - oss << ' '; - } - - return oss.str(); -} - void SplitString(const std::string& str, const char delim, std::vector& output) { size_t next = 0; @@ -243,9 +196,3 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st } return result; } - -int strcmpIgnore(std::string str1, std::string str2, std::string ignorestr1, std::string ignorestr2) { - str1 = ReplaceAll(str1, ignorestr1, ignorestr2); - str2 = ReplaceAll(str2, ignorestr1, ignorestr2); - return strcmp(str1.c_str(),str2.c_str()); -} diff --git a/ext/native/base/stringutil.h b/ext/native/base/stringutil.h index 6721930195..3a64058838 100644 --- a/ext/native/base/stringutil.h +++ b/ext/native/base/stringutil.h @@ -13,16 +13,6 @@ #include #endif -// Dumb wrapper around itoa, providing a buffer. Declare this on the stack. -class ITOA { -public: - char buffer[16]; - const char *p(int i) { - sprintf(buffer, "%i", i); - return &buffer[0]; - } -}; - // Useful for shaders with error messages.. std::string LineNumberString(const std::string &str); @@ -62,9 +52,6 @@ inline void StringToHexString(const std::string &data, std::string *output) { std::string StringFromFormat(const char* format, ...); std::string StringFromInt(int value); -std::string StringFromBool(bool value); - -std::string ArrayToString(const uint8_t *data, uint32_t size, int line_len = 20, bool spaces = true); std::string StripSpaces(const std::string &s); std::string StripQuotes(const std::string &s); @@ -75,10 +62,4 @@ void GetQuotedStrings(const std::string& str, std::vector& output); std::string ReplaceAll(std::string input, const std::string& src, const std::string& dest); -// Compare two strings, ignore the difference between the ignorestr1 and the ignorestr2 in str1 and str2. -int strcmpIgnore(std::string str1, std::string str2, std::string ignorestr1, std::string ignorestr2); - -void StringTrimEndNonAlphaNum(char *str); void SkipSpace(const char **ptr); -void StringUpper(char *str); -void StringUpper(char *str, int len); diff --git a/ext/native/file/ini_file.h b/ext/native/file/ini_file.h index 41d7bb711f..4c2b65ed4b 100644 --- a/ext/native/file/ini_file.h +++ b/ext/native/file/ini_file.h @@ -52,7 +52,7 @@ public: void Set(const char* key, bool newValue, bool defaultValue); void Set(const char* key, bool newValue) { - Set(key, StringFromBool(newValue).c_str()); + Set(key, newValue ? "True" : "False"); } void Set(const char* key, const std::vector& newValues); diff --git a/ext/native/ui/view.cpp b/ext/native/ui/view.cpp index 849ec8947a..b8e62a5cce 100644 --- a/ext/native/ui/view.cpp +++ b/ext/native/ui/view.cpp @@ -162,9 +162,8 @@ void View::PersistData(PersistStatus status, std::string anonId, PersistMap &sto break; } - ITOA stringify; for (int i = 0; i < (int)tweens_.size(); ++i) { - tweens_[i]->PersistData(status, tag + "/" + stringify.p((int)i), storage); + tweens_[i]->PersistData(status, tag + "/" + StringFromInt(i), storage); } } diff --git a/ext/native/ui/viewgroup.cpp b/ext/native/ui/viewgroup.cpp index 1a13ac27e9..cd3221f790 100644 --- a/ext/native/ui/viewgroup.cpp +++ b/ext/native/ui/viewgroup.cpp @@ -70,9 +70,8 @@ void ViewGroup::PersistData(PersistStatus status, std::string anonId, PersistMap tag = anonId; } - ITOA stringify; for (size_t i = 0; i < views_.size(); i++) { - views_[i]->PersistData(status, tag + "/" + stringify.p((int)i), storage); + views_[i]->PersistData(status, tag + "/" + StringFromInt((int)i), storage); } } From 1e6c13cb56865e5876c00d33e68e0c7aebe5a5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 29 Sep 2020 10:07:07 +0200 Subject: [PATCH 5/7] Delete more old detritus --- Core/HLE/sceNetAdhoc.cpp | 2 +- UWP/NativeUWP/NativeUWP.vcxproj | 1 - UWP/NativeUWP/NativeUWP.vcxproj.filters | 3 -- ext/native/data/compression.h | 23 +----------- ext/native/data/listable.h | 49 ------------------------- ext/native/file/chunk_file.cpp | 3 -- ext/native/file/chunk_file.h | 4 +- ext/native/native.vcxproj | 3 +- ext/native/native.vcxproj.filters | 11 +----- 9 files changed, 6 insertions(+), 93 deletions(-) delete mode 100644 ext/native/data/listable.h diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 470b53bb0a..0645f4c707 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -6415,7 +6415,7 @@ void actOnBirthPacket(SceNetAdhocMatchingContext * context, SceNetEtherAddr * se SceNetEtherAddr mac; memcpy(&mac, context->rxbuf + 1, sizeof(SceNetEtherAddr)); - // Allocate Memory (If this fails... we are fucked.) + // Allocate Memory SceNetAdhocMatchingMemberInternal * sibling = (SceNetAdhocMatchingMemberInternal *)malloc(sizeof(SceNetAdhocMatchingMemberInternal)); // Allocated Memory diff --git a/UWP/NativeUWP/NativeUWP.vcxproj b/UWP/NativeUWP/NativeUWP.vcxproj index 9fe46fd1b6..70bc7f2a6e 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj +++ b/UWP/NativeUWP/NativeUWP.vcxproj @@ -390,7 +390,6 @@ - diff --git a/UWP/NativeUWP/NativeUWP.vcxproj.filters b/UWP/NativeUWP/NativeUWP.vcxproj.filters index b955c76d5f..eed8497fbb 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj.filters +++ b/UWP/NativeUWP/NativeUWP.vcxproj.filters @@ -712,9 +712,6 @@ data - - data - diff --git a/ext/native/data/compression.h b/ext/native/data/compression.h index e37ff85794..5323b8f549 100644 --- a/ext/native/data/compression.h +++ b/ext/native/data/compression.h @@ -2,27 +2,6 @@ #include +// inflate/deflate convenience wrapper. Uses zlib. bool compress_string(const std::string& str, std::string *dest, int compressionlevel = 9); bool decompress_string(const std::string& str, std::string *dest); - - -// Delta encoding/decoding - many formats benefit from a pass of this before zlibbing. -// WARNING : Do not use these with floating point data, especially not float16... - -template -inline void delta(T *data, int length) { - T prev = data[0]; - for (int i = 1; i < length; i++) { - T temp = data[i] - prev; - prev = data[i]; - data[i] = temp; - } -} - -template -inline void dedelta(T *data, int length) { - for (int i = 1; i < length; i++) { - data[i] += data[i - 1]; - } -} - diff --git a/ext/native/data/listable.h b/ext/native/data/listable.h deleted file mode 100644 index 017cacf1b9..0000000000 --- a/ext/native/data/listable.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include -#include - -class Listable -{ -public: - virtual ~Listable() {} - virtual const char *getItem(size_t i) const = 0; - virtual size_t numItems() const = 0; - - // Returns -1 for not found. - // Child classes are meant to specialize this if they have a faster way - // than brute force search. - virtual int getIndex(const char *text) { - for (size_t i = 0; i < numItems(); i++) { - if (!strcmp(getItem(i), text)) - return i; - } - return -1; - } -}; - -class ArrayListable : public Listable -{ -public: - ArrayListable(const char * const*arr, size_t count) : arr_(arr), count_(count) {} - virtual ~ArrayListable() {} - - virtual const char *getItem(size_t i) const { return arr_[i]; } - virtual size_t numItems() const { return count_; } - -private: - const char *const*arr_; - size_t count_; -}; - -class VectorListable : public Listable -{ - VectorListable(const std::vector &vec) : vec_(vec) {} - virtual ~VectorListable() {} - - virtual const char *getItem(size_t i) const { return vec_[i].c_str(); } - virtual size_t numItems() const { return vec_.size(); } - -private: - const std::vector &vec_; -}; \ No newline at end of file diff --git a/ext/native/file/chunk_file.cpp b/ext/native/file/chunk_file.cpp index 20553a8657..2dab992913 100644 --- a/ext/native/file/chunk_file.cpp +++ b/ext/native/file/chunk_file.cpp @@ -29,7 +29,6 @@ int RIFFReader::ReadInt() { return 0; } -// let's get into the business bool RIFFReader::Descend(uint32_t intoId) { if (depth_ > 30) return false; @@ -83,7 +82,6 @@ bool RIFFReader::Descend(uint32_t intoId) { return true; } -// let's ascend out void RIFFReader::Ascend() { // ascend, and restore information depth_--; @@ -91,7 +89,6 @@ void RIFFReader::Ascend() { eof_ = stack[depth_].parentEOF; } -// read a block void RIFFReader::ReadData(void *what, int count) { memcpy(what, data_ + pos_, count); pos_ += count; diff --git a/ext/native/file/chunk_file.h b/ext/native/file/chunk_file.h index 18d8a80e8b..ebc2db99a4 100644 --- a/ext/native/file/chunk_file.h +++ b/ext/native/file/chunk_file.h @@ -1,7 +1,7 @@ #pragma once -// RIFF file format reader/writer. Very old code, basically a total mess but it still works. -// Has nothing to do with the ChunkFile.h used in Dolphin or PPSSPP. +// Simple RIFF file format reader/writer. +// Unrelated to the ChunkFile.h used in Dolphin and PPSSPP. // TO REMEMBER WHEN USING: diff --git a/ext/native/native.vcxproj b/ext/native/native.vcxproj index ccd6b2d7f5..7e5e759400 100644 --- a/ext/native/native.vcxproj +++ b/ext/native/native.vcxproj @@ -390,7 +390,6 @@ - @@ -1211,4 +1210,4 @@ - + \ No newline at end of file diff --git a/ext/native/native.vcxproj.filters b/ext/native/native.vcxproj.filters index 9363be3e69..a1f06f8607 100644 --- a/ext/native/native.vcxproj.filters +++ b/ext/native/native.vcxproj.filters @@ -110,12 +110,6 @@ ui - - data - - - base - net @@ -775,9 +769,6 @@ thin3d - - base - gfx @@ -901,4 +892,4 @@ {5b740c6f-8dbc-4529-9114-6564b37b3548} - + \ No newline at end of file From db9cc41a1a5c6817aa65415af554a6049368f7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 29 Sep 2020 10:07:20 +0200 Subject: [PATCH 6/7] Delete unused math code --- CMakeLists.txt | 5 - UWP/NativeUWP/NativeUWP.vcxproj | 4 - UWP/NativeUWP/NativeUWP.vcxproj.filters | 12 --- ext/native/Android.mk | 2 - ext/native/math/CMakeLists.txt | 5 +- ext/native/math/lin/matrix4x4.cpp | 1 - ext/native/math/lin/plane.cpp | 13 --- ext/native/math/lin/plane.h | 41 -------- ext/native/math/lin/quat.cpp | 129 ------------------------ ext/native/math/lin/quat.h | 96 ------------------ ext/native/math/lin/ray.h | 14 --- ext/native/native.vcxproj | 4 - ext/native/native.vcxproj.filters | 15 --- libretro/Makefile.common | 2 - 14 files changed, 2 insertions(+), 341 deletions(-) delete mode 100644 ext/native/math/lin/plane.cpp delete mode 100644 ext/native/math/lin/plane.h delete mode 100644 ext/native/math/lin/quat.cpp delete mode 100644 ext/native/math/lin/quat.h delete mode 100644 ext/native/math/lin/ray.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 006843ac21..b2804099bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1022,11 +1022,6 @@ add_library(native STATIC ext/native/math/expression_parser.h ext/native/math/lin/matrix4x4.cpp ext/native/math/lin/matrix4x4.h - ext/native/math/lin/plane.cpp - ext/native/math/lin/plane.h - ext/native/math/lin/quat.cpp - ext/native/math/lin/quat.h - ext/native/math/lin/ray.h ext/native/math/lin/vec3.cpp ext/native/math/lin/vec3.h ext/native/math/math_util.cpp diff --git a/UWP/NativeUWP/NativeUWP.vcxproj b/UWP/NativeUWP/NativeUWP.vcxproj index 70bc7f2a6e..0d4f747f02 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj +++ b/UWP/NativeUWP/NativeUWP.vcxproj @@ -434,8 +434,6 @@ - - @@ -1585,8 +1583,6 @@ - - diff --git a/UWP/NativeUWP/NativeUWP.vcxproj.filters b/UWP/NativeUWP/NativeUWP.vcxproj.filters index eed8497fbb..a424450ad6 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj.filters +++ b/UWP/NativeUWP/NativeUWP.vcxproj.filters @@ -166,12 +166,6 @@ math - - math - - - math - math @@ -601,12 +595,6 @@ math - - math - - - math - math diff --git a/ext/native/Android.mk b/ext/native/Android.mk index 75bf2b31be..a922490f88 100644 --- a/ext/native/Android.mk +++ b/ext/native/Android.mk @@ -52,8 +52,6 @@ LOCAL_SRC_FILES :=\ math/math_util.cpp \ math/curves.cpp \ math/expression_parser.cpp \ - math/lin/plane.cpp.arm \ - math/lin/quat.cpp.arm \ math/lin/vec3.cpp.arm \ math/lin/matrix4x4.cpp.arm \ net/http_client.cpp \ diff --git a/ext/native/math/CMakeLists.txt b/ext/native/math/CMakeLists.txt index 4093973f06..3d6e0daa52 100644 --- a/ext/native/math/CMakeLists.txt +++ b/ext/native/math/CMakeLists.txt @@ -1,9 +1,8 @@ set(SRCS lin/matrix4x4.cpp lin/vec3.cpp - lin/quat.cpp - curves.cpp - math_util.cpp + curves.cpp + math_util.cpp ) set(SRCS ${SRCS}) diff --git a/ext/native/math/lin/matrix4x4.cpp b/ext/native/math/lin/matrix4x4.cpp index 007b8a8d17..7b4179bfef 100644 --- a/ext/native/math/lin/matrix4x4.cpp +++ b/ext/native/math/lin/matrix4x4.cpp @@ -3,7 +3,6 @@ #include #include "math/lin/vec3.h" -#include "math/lin/quat.h" #include "math/fast/fast_matrix.h" #ifdef _WIN32 diff --git a/ext/native/math/lin/plane.cpp b/ext/native/math/lin/plane.cpp deleted file mode 100644 index d62277889d..0000000000 --- a/ext/native/math/lin/plane.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "math/lin/matrix4x4.h" -#include "math/lin/plane.h" - -namespace Lin { - -void Plane::TransformByIT(const Matrix4x4 &m, Plane *out) { - out->x = x * m.xx + y * m.yx + z * m.zx + d * m.wx; - out->y = x * m.xy + y * m.yy + z * m.zy + d * m.wy; - out->z = x * m.xz + y * m.yz + z * m.zz + d * m.wz; - out->d = x * m.xw + y * m.yw + z * m.zw + d * m.ww; -} - -} // namespace Lin diff --git a/ext/native/math/lin/plane.h b/ext/native/math/lin/plane.h deleted file mode 100644 index 295c3f250a..0000000000 --- a/ext/native/math/lin/plane.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _PLANE_H -#define _PLANE_H - -#include "math/lin/vec3.h" - -namespace Lin { - -class Matrix4x4; - -class Plane { -public: - float x, y, z, d; - Plane() {} - Plane(float x_, float y_, float z_, float d_) - : x(x_), y(y_), z(z_), d(d_) { } - ~Plane() {} - - float Distance(const Vec3 &v) const { - return x * v.x + y * v.y + z * v.z + d; - } - - float Distance(float px, float py, float pz) const { - return x * px + y * py + z * pz + d; - } - - void Normalize() { - float inv_length = sqrtf(x * x + y * y + z * z); - x *= inv_length; - y *= inv_length; - z *= inv_length; - d *= inv_length; - } - - // Matrix is the inverse transpose of the wanted transform. - // out cannot be equal to this. - void TransformByIT(const Matrix4x4 &matrix, Plane *out); -}; - -} // namespace Lin - -#endif diff --git a/ext/native/math/lin/quat.cpp b/ext/native/math/lin/quat.cpp deleted file mode 100644 index f5479a51f5..0000000000 --- a/ext/native/math/lin/quat.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "math/lin/quat.h" -#include "math/lin/matrix4x4.h" - -namespace Lin { - -void Quaternion::toMatrix(Matrix4x4 *out) const { - Matrix4x4 temp; - temp.setIdentity(); - float ww, xx, yy, zz, wx, wy, wz, xy, xz, yz; - ww = w*w; xx = x*x; yy = y*y; zz = z*z; - wx = w*x*2; wy = w*y*2; wz = w*z*2; - xy = x*y*2; xz = x*z*2; yz = y*z*2; - - temp.xx = ww + xx - yy - zz; - temp.xy = xy + wz; - temp.xz = xz - wy; - - temp.yx = xy - wz; - temp.yy = ww - xx + yy - zz; - temp.yz = yz + wx; - - temp.zx = xz + wy; - temp.zy = yz - wx; - temp.zz = ww - xx - yy + zz; - - *out = temp; -} - -Quaternion Quaternion::fromMatrix(Matrix4x4 &m) -{ - // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes - // article "Quaternion Calculus and Fast Animation". - Quaternion q(0,0,0,1); - /* - float fTrace = m[0][0] + m[1][1] + m[2][2]; - float fRoot; - - if( fTrace > 0.0 ) - { - fRoot = sqrtf( fTrace + 1.0f ); - - q.w = 0.5f * fRoot; - - fRoot = 0.5f / fRoot; - - q.x = ( m[2][1] - m[1][2] ) * fRoot; - q.y = ( m[0][2] - m[2][0] ) * fRoot; - q.z = ( m[1][0] - m[0][1] ) * fRoot; - } - else - { - int iNext[3] = { 1, 2, 0 }; - - int i = 0; - if( m[1][1] > m[0][0] ) - i = 1; - - if( m[2][2] > m[i][i] ) - i = 2; - - int j = iNext[i]; - int k = iNext[j]; - - fRoot = sqrtf( m[i][i] - m[j][j] - m[k][k] + 1.0f ); - - float *apfQuat = &q.x; - - apfQuat[i] = 0.5f * fRoot; - - fRoot = 0.5f / fRoot; - - q.w = ( m[k][j] - m[j][k] ) * fRoot; - - apfQuat[j] = ( m[j][i] + m[i][j] ) * fRoot; - apfQuat[k] = ( m[k][i] + m[i][k] ) * fRoot; - } - q.normalize(); */ - return q; -}; - -// TODO: Allegedly, lerp + normalize can achieve almost as good results. -Quaternion Quaternion::slerp(const Quaternion &to, const float a) const { - Quaternion to2; - float angle, cos_angle, scale_from, scale_to, sin_angle; - - cos_angle = (x * to.x) + (y * to.y) + (z * to.z) + (w * to.w); //4D dot product - - if (cos_angle < 0.0f) - { - cos_angle = -cos_angle; - to2.w = -to.w; to2.x = -to.x; to2.y = -to.y; to2.z = -to.z; - } - else - { - to2 = to; - } - - if ((1.0f - fabsf(cos_angle)) > 0.00001f) - { - /* spherical linear interpolation (SLERP) */ - angle = acosf(cos_angle); - sin_angle = sinf(angle); - scale_from = sinf((1.0f - a) * angle) / sin_angle; - scale_to = sinf(a * angle) / sin_angle; - } - else - { - /* to prevent divide-by-zero, resort to linear interpolation */ - // This is okay in 99% of cases anyway, maybe should be the default? - scale_from = 1.0f - a; - scale_to = a; - } - - return Quaternion( - scale_from*x + scale_to*to2.x, - scale_from*y + scale_to*to2.y, - scale_from*z + scale_to*to2.z, - scale_from*w + scale_to*to2.w - ); -} - -Quaternion Quaternion::multiply(const Quaternion &q) const { - return Quaternion((w * q.x) + (x * q.w) + (y * q.z) - (z * q.y), - (w * q.y) + (y * q.w) + (z * q.x) - (x * q.z), - (w * q.z) + (z * q.w) + (x * q.y) - (y * q.x), - (w * q.w) - (x * q.x) - (y * q.y) - (z * q.z)); -} - -} diff --git a/ext/native/math/lin/quat.h b/ext/native/math/lin/quat.h deleted file mode 100644 index 8be9a94f5c..0000000000 --- a/ext/native/math/lin/quat.h +++ /dev/null @@ -1,96 +0,0 @@ -#ifndef _MATH_LIN_QUAT_H -#define _MATH_LIN_QUAT_H - -#include "math/lin/vec3.h" - -namespace Lin { - -class Matrix4x4; - -class Quaternion -{ -public: - float x,y,z,w; - - Quaternion() { } - Quaternion(const float _x, const float _y, const float _z, const float _w) { - x=_x; y=_y; z=_z; w=_w; - } - void setIdentity() - { - x=y=z=0; w=1.0f; - } - void setXRotation(const float r) { w = cosf(r / 2); x = sinf(r / 2); y = z = 0; } - void setYRotation(const float r) { w = cosf(r / 2); y = sinf(r / 2); x = z = 0; } - void setZRotation(const float r) { w = cosf(r / 2); z = sinf(r / 2); x = y = 0; } - void toMatrix(Matrix4x4 *out) const; - static Quaternion fromMatrix(Matrix4x4 &m); - - Quaternion operator *(Quaternion &q) const - { - return Quaternion( - (w * q.w) - (x * q.x) - (y * q.y) - (z * q.z), - (w * q.x) + (x * q.w) + (y * q.z) - (z * q.y), - (w * q.y) + (y * q.w) + (z * q.x) - (x * q.z), - (w * q.z) + (z * q.w) + (x * q.y) - (y * q.x) - ); - } - Quaternion operator -() - { - return Quaternion(-x,-y,-z,-w); - } - void setRotation(Vec3 axis, float angle) - { - axis /= axis.length(); - angle *= .5f; - float sine = sinf(angle); - w = cosf(angle); - x = sine * axis.x; - y = sine * axis.y; - z = sine * axis.z; - } - void toAxisAngle(Vec3 &v, float &angle) - { - normalize(); - if (w==1.0f && x==0.0f && y==0.0f && z==0.0f) - { - v = Vec3(0,1,0); - angle = 0.0f; - return; - } - float cos_a = w; - angle = acosf(cos_a) * 2; - float sin_a = sqrtf( 1.0f - cos_a * cos_a ); - if (fabsf(sin_a) < 0.00005f) sin_a = 1; - float inv_sin_a=1.0f/sin_a; - v.x = x * inv_sin_a; - v.y = y * inv_sin_a; - v.z = z * inv_sin_a; - } - enum { - QUAT_SHORT, - QUAT_LONG, - QUAT_CW, - QUAT_CCW - }; - Quaternion slerp(const Quaternion &to, const float a) const; - Quaternion multiply(const Quaternion &q) const; - float &operator [] (int i) { - return *((&x) + i); - } - float operator [] (int i) const { - return *((&x) + i); - } - //not sure about this, maybe mag is supposed to sqrt - float magnitude() const { - return x*x + y*y + z*z + w*w; - } - void normalize() { - float f = 1.0f/sqrtf(magnitude()); - x*=f; y*=f; z*=f; w*=f; - } -}; - -} // namespace Lin - -#endif // _MATH_LIN_QUAT_H diff --git a/ext/native/math/lin/ray.h b/ext/native/math/lin/ray.h deleted file mode 100644 index 2287460fbb..0000000000 --- a/ext/native/math/lin/ray.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "vec3.h" - -/* __declspec(align(16)) */ struct Ray -{ - Vec3 origin; - int pad; - Vec3 dir; - int pad2; - Vec3 invdir; - int pad3; -}; - diff --git a/ext/native/native.vcxproj b/ext/native/native.vcxproj index 7e5e759400..b6653404d0 100644 --- a/ext/native/native.vcxproj +++ b/ext/native/native.vcxproj @@ -454,8 +454,6 @@ - - @@ -1169,8 +1167,6 @@ - - diff --git a/ext/native/native.vcxproj.filters b/ext/native/native.vcxproj.filters index a1f06f8607..d4ce209515 100644 --- a/ext/native/native.vcxproj.filters +++ b/ext/native/native.vcxproj.filters @@ -41,9 +41,6 @@ image - - math - math @@ -125,9 +122,6 @@ ui - - math - util @@ -361,9 +355,6 @@ math - - math - math @@ -430,9 +421,6 @@ ui - - math - math @@ -858,9 +846,6 @@ {d5fa3d62-88bf-4dc4-9814-28f3c0444e62} - - {1e85f968-7106-483c-ae7d-77d0ef58d787} - {6a548b3d-3a4c-4114-aa2f-0b42bf7bf2ce} diff --git a/libretro/Makefile.common b/libretro/Makefile.common index b53cce49a3..87fc689e03 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -301,8 +301,6 @@ SOURCES_CXX += $(NATIVEDIR)/math/dataconv.cpp \ $(NATIVEDIR)/math/curves.cpp \ $(NATIVEDIR)/math/expression_parser.cpp \ $(NATIVEDIR)/math/lin/matrix4x4.cpp \ - $(NATIVEDIR)/math/lin/plane.cpp \ - $(NATIVEDIR)/math/lin/quat.cpp \ $(NATIVEDIR)/math/lin/vec3.cpp \ $(NATIVEDIR)/net/http_client.cpp \ $(NATIVEDIR)/net/resolve.cpp \ From ec7458b6a939b8ec2c73f6a2126d5f57c3fa0ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 29 Sep 2020 10:13:27 +0200 Subject: [PATCH 7/7] Delete more useless math code --- ext/native/math/lin/matrix4x4.cpp | 158 ------------------------------ ext/native/math/lin/matrix4x4.h | 54 +--------- ext/native/math/lin/vec3.cpp | 12 --- ext/native/math/lin/vec3.h | 6 -- ext/native/math/math_util.h | 42 -------- 5 files changed, 2 insertions(+), 270 deletions(-) diff --git a/ext/native/math/lin/matrix4x4.cpp b/ext/native/math/lin/matrix4x4.cpp index 7b4179bfef..b514714573 100644 --- a/ext/native/math/lin/matrix4x4.cpp +++ b/ext/native/math/lin/matrix4x4.cpp @@ -15,32 +15,6 @@ namespace Lin { -Matrix4x4 Matrix4x4::simpleInverse() const { - Matrix4x4 out; - out.xx = xx; - out.xy = yx; - out.xz = zx; - - out.yx = xy; - out.yy = yy; - out.yz = zy; - - out.zx = xz; - out.zy = yz; - out.zz = zz; - - out.wx = -(xx * wx + xy * wy + xz * wz); - out.wy = -(yx * wx + yy * wy + yz * wz); - out.wz = -(zx * wx + zy * wy + zz * wz); - - out.xw = 0.0f; - out.yw = 0.0f; - out.zw = 0.0f; - out.ww = 1.0f; - - return out; -} - Matrix4x4 Matrix4x4::transpose() const { Matrix4x4 out; @@ -58,100 +32,6 @@ Matrix4x4 Matrix4x4::operator * (const Matrix4x4 &other) const return temp; } -Matrix4x4 Matrix4x4::inverse() const { - Matrix4x4 temp; - float dW = 1.0f / (xx*(yy*zz - yz*zy) - xy*(yx*zz - yz*zx) - xz*(yy*zx - yx*zy)); - - temp.xx = (yy*zz - yz*zy) * dW; - temp.xy = (xz*zy - xy*zz) * dW; - temp.xz = (xy*yz - xz*yy) * dW; - temp.xw = xw; - - temp.yx = (yz*zx - yx*zz) * dW; - temp.yy = (xx*zz - xz*zx) * dW; - temp.yz = (xz*yx - xx*zx) * dW; - temp.yw = yw; - - temp.zx = (yx*zy - yy*zx) * dW; - temp.zy = (xy*zx - xx*zy) * dW; - temp.zz = (xx*yy - xy*yx) * dW; - temp.zw = zw; - - temp.wx = (yy*(zx*wz - zz*wx) + yz*(zy*wx - zx*wy) - yx*(zy*wz - zz*wy)) * dW; - temp.wy = (xx*(zy*wz - zz*wy) + xy*(zz*wx - zx*wz) + xz*(zx*wy - zy*wx)) * dW; - temp.wz = (xy*(yx*wz - yz*wx) + xz*(yy*wx - yx*wy) - xx*(yy*wz - yz*wy)) * dW; - temp.ww = ww; - - return temp; -} - -void Matrix4x4::setViewLookAt(const Vec3 &vFrom, const Vec3 &vAt, const Vec3 &vWorldUp) { - Vec3 vView = vFrom - vAt; // OpenGL, sigh... - vView.normalize(); - float DotProduct = vWorldUp * vView; - Vec3 vUp = vWorldUp - vView * DotProduct; - float Length = vUp.length(); - - if (1e-6f > Length) { - // EMERGENCY - vUp = Vec3(0.0f, 1.0f, 0.0f) - vView * vView.y; - // If we still have near-zero length, resort to a different axis. - Length = vUp.length(); - if (1e-6f > Length) - { - vUp = Vec3(0.0f, 0.0f, 1.0f) - vView * vView.z; - Length = vUp.length(); - if (1e-6f > Length) - return; - } - } - vUp.normalize(); - Vec3 vRight = vUp % vView; - empty(); - - xx = vRight.x; xy = vUp.x; xz=vView.x; - yx = vRight.y; yy = vUp.y; yz=vView.y; - zx = vRight.z; zy = vUp.z; zz=vView.z; - - wx = -vFrom * vRight; - wy = -vFrom * vUp; - wz = -vFrom * vView; - ww = 1.0f; -} - -void Matrix4x4::setViewLookAtD3D(const Vec3 &vFrom, const Vec3 &vAt, const Vec3 &vWorldUp) { - Vec3 vView = vAt - vFrom; - vView.normalize(); - float DotProduct = vWorldUp * vView; - Vec3 vUp = vWorldUp - vView * DotProduct; - float Length = vUp.length(); - - if (1e-6f > Length) { - vUp = Vec3(0.0f, 1.0f, 0.0f) - vView * vView.y; - // If we still have near-zero length, resort to a different axis. - Length = vUp.length(); - if (1e-6f > Length) - { - vUp = Vec3(0.0f, 0.0f, 1.0f) - vView * vView.z; - Length = vUp.length(); - if (1e-6f > Length) - return; - } - } - vUp.normalize(); - Vec3 vRight = vUp % vView; - empty(); - - xx = vRight.x; xy = vUp.x; xz=vView.x; - yx = vRight.y; yy = vUp.y; yz=vView.y; - zx = vRight.z; zy = vUp.z; zz=vView.z; - - wx = -vFrom * vRight; - wy = -vFrom * vUp; - wz = -vFrom * vView; - ww = 1.0f; -} - void Matrix4x4::setViewFrame(const Vec3 &pos, const Vec3 &vRight, const Vec3 &vView, const Vec3 &vUp) { xx = vRight.x; xy = vUp.x; xz=vView.x; xw = 0.0f; yx = vRight.y; yy = vUp.y; yz=vView.y; yw = 0.0f; @@ -163,44 +43,6 @@ void Matrix4x4::setViewFrame(const Vec3 &pos, const Vec3 &vRight, const Vec3 &vV ww = 1.0f; } -//YXZ euler angles -void Matrix4x4::setRotation(float x,float y, float z) -{ - setRotationY(y); - Matrix4x4 temp; - temp.setRotationX(x); - *this *= temp; - temp.setRotationZ(z); - *this *= temp; -} - -void Matrix4x4::setProjection(float near, float far, float fov_horiz, float aspect) { - // Now OpenGL style. - empty(); - - float xFac = tanf(fov_horiz * 3.14f/360); - float yFac = xFac * aspect; - xx = 1.0f / xFac; - yy = 1.0f / yFac; - zz = -(far+near)/(far-near); - zw = -1.0f; - wz = -(2*far*near)/(far-near); -} - -void Matrix4x4::setProjectionD3D(float near_plane, float far_plane, float fov_horiz, float aspect) { - empty(); - float Q, f; - - f = fov_horiz*0.5f; - Q = far_plane / (far_plane - near_plane); - - xx = (float)(1.0f / tanf(f));; - yy = (float)(1.0f / tanf(f*aspect)); - zz = Q; - wz = -Q * near_plane; - zw = 1.0f; -} - void Matrix4x4::setOrtho(float left, float right, float bottom, float top, float near, float far) { empty(); xx = 2.0f / (right - left); diff --git a/ext/native/math/lin/matrix4x4.h b/ext/native/math/lin/matrix4x4.h index a9e312de70..70644a80f6 100644 --- a/ext/native/math/lin/matrix4x4.h +++ b/ext/native/math/lin/matrix4x4.h @@ -24,19 +24,6 @@ public: const Vec3 front() const {return Vec3(zx, zy, zz);} const Vec3 move() const {return Vec3(wx, wy, wz);} - void setRight(const Vec3 &v) { - xx = v.x; xy = v.y; xz = v.z; - } - void setUp(const Vec3 &v) { - yx = v.x; yy = v.y; yz = v.z; - } - void setFront(const Vec3 &v) { - zx = v.x; zy = v.y; zz = v.z; - } - void setMove(const Vec3 &v) { - wx = v.x; wy = v.y; wz = v.z; - } - const float &operator[](int i) const { return *(((const float *)this) + i); } @@ -53,17 +40,14 @@ public: void empty() { memset(this, 0, 16 * sizeof(float)); } - void setScaling(const float f) { - empty(); - xx=yy=zz=f; ww=1.0f; - } static Matrix4x4 identity() { Matrix4x4 id; id.setIdentity(); return id; } void setIdentity() { - setScaling(1.0f); + empty(); + xx = yy = zz = ww = 1.0f; } void setTranslation(const Vec3 &trans) { setIdentity(); @@ -72,37 +56,8 @@ public: wz = trans.z; } - Matrix4x4 inverse() const; - Matrix4x4 simpleInverse() const; Matrix4x4 transpose() const; - void setRotationX(const float a) { - empty(); - float c = cosf(a); - float s = sinf(a); - xx = 1.0f; - yy = c; yz = s; - zy = -s; zz = c; - ww = 1.0f; - } - void setRotationY(const float a) { - empty(); - float c = cosf(a); - float s = sinf(a); - xx = c; xz = -s; - yy = 1.0f; - zx = s; zz = c; - ww = 1.0f; - } - void setRotationZ(const float a) { - empty(); - float c = cosf(a); - float s = sinf(a); - xx = c; xy = s; - yx = -s; yy = c; - zz = 1.0f; - ww = 1.0f; - } // Exact angles to avoid any artifacts. void setRotationZ90() { empty(); @@ -132,15 +87,10 @@ public: ww = 1.0f; } - void setRotation(float x,float y, float z); - void setProjection(float near_plane, float far_plane, float fov_horiz, float aspect = 0.75f); - void setProjectionD3D(float near_plane, float far_plane, float fov_horiz, float aspect = 0.75f); void setOrtho(float left, float right, float bottom, float top, float near, float far); void setOrthoD3D(float left, float right, float bottom, float top, float near, float far); void setOrthoVulkan(float left, float right, float top, float bottom, float near, float far); - void setViewLookAt(const Vec3 &from, const Vec3 &at, const Vec3 &worldup); - void setViewLookAtD3D(const Vec3 &from, const Vec3 &at, const Vec3 &worldup); void setViewFrame(const Vec3 &pos, const Vec3 &right, const Vec3 &forward, const Vec3 &up); void toText(char *buffer, int len) const; void print() const; diff --git a/ext/native/math/lin/vec3.cpp b/ext/native/math/lin/vec3.cpp index 95c2469fc3..7c66339cda 100644 --- a/ext/native/math/lin/vec3.cpp +++ b/ext/native/math/lin/vec3.cpp @@ -10,18 +10,6 @@ Vec3 Vec3::operator *(const Matrix4x4 &m) const { x*m.xy + y*m.yy + z*m.zy + m.wy, x*m.xz + y*m.yz + z*m.zz + m.wz); } -Vec4 Vec3::multiply4D(const Matrix4x4 &m) const { - return Vec4(x*m.xx + y*m.yx + z*m.zx + m.wx, - x*m.xy + y*m.yy + z*m.zy + m.wy, - x*m.xz + y*m.yz + z*m.zz + m.wz, - x*m.xw + y*m.yw + z*m.zw + m.ww); -} -Vec4 Vec4::multiply4D(Matrix4x4 &m) const { - return Vec4(x*m.xx + y*m.yx + z*m.zx + w*m.wx, - x*m.xy + y*m.yy + z*m.zy + w*m.wy, - x*m.xz + y*m.yz + z*m.zz + w*m.wz, - x*m.xw + y*m.yw + z*m.zw + w*m.ww); -} Vec3 Vec3::rotatedBy(const Matrix4x4 &m) const { return Vec3(x*m.xx + y*m.yx + z*m.zx, diff --git a/ext/native/math/lin/vec3.h b/ext/native/math/lin/vec3.h index 10096153d7..988a2d08b5 100644 --- a/ext/native/math/lin/vec3.h +++ b/ext/native/math/lin/vec3.h @@ -14,7 +14,6 @@ public: float x,y,z,w; Vec4(){} Vec4(float a, float b, float c, float d) {x=a;y=b;z=c;w=d;} - Vec4 multiply4D(Matrix4x4 &m) const; }; class Vec3 { @@ -80,7 +79,6 @@ public: void operator *=(const Matrix4x4 &m) { *this = *this * m; } - Vec4 multiply4D(const Matrix4x4 &m) const; Vec3 rotatedBy(const Matrix4x4 &m) const; Vec3 operator %(const Vec3 &v) const { return Vec3(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); @@ -134,10 +132,6 @@ inline Vec3 cross(const Vec3 &a, const Vec3 &b) { return a % b; } -inline float sqr(const Vec3 &v) { - return dot(v, v); -} - class AABBox { public: Vec3 min; diff --git a/ext/native/math/math_util.h b/ext/native/math/math_util.h index 4d30d080c6..12147a6f64 100644 --- a/ext/native/math/math_util.h +++ b/ext/native/math/math_util.h @@ -8,9 +8,6 @@ #include "base/basictypes.h" -inline float sqr(float f) {return f*f;} -inline float sqr_signed(float f) {return f<0 ? -f*f : f*f;} - typedef unsigned short float16; // This ain't a 1.5.10 float16, it's a stupid hack format where we chop 16 bits off a float. @@ -56,33 +53,6 @@ inline uint32_t log2i(uint32_t val) { #define M_PI 3.141592653589793f #endif -// Calculate pseudo-random 32 bit number based on linear congruential method. -void SetSeed(unsigned int seed); -unsigned int GenerateRandomNumber(); -inline float GenerateRandomFloat01() { - return (float)((double)GenerateRandomNumber() / 0xFFFFFFFF); -} -inline float GenerateRandomSignedFloat() { - return (float)((double)GenerateRandomNumber() / 0x80000000) - 1.0f; -} - - -inline float GaussRand() -{ - float R1 = GenerateRandomFloat01(); - float R2 = GenerateRandomFloat01(); - - float X = sqrtf(-2.0f * logf(R1)) * cosf(2.0f * PI * R2); - if (X > 4.0f) X = 4.0f; - if (X < -4.0f) X = -4.0f; - return X; -} - -// Accuracy unknown -inline double atan_fast(double x) { - return (x / (1.0 + 0.28 * (x * x))); -} - template inline T clamp_value(T val, T floor, T cap) { if (val > cap) @@ -93,18 +63,6 @@ inline T clamp_value(T val, T floor, T cap) { return val; } -// linear -> dB conversion -inline float lin2dB(float lin) { - const float LOG_2_DB = 8.6858896380650365530225783783321f; // 20 / ln( 10 ) - return logf(lin) * LOG_2_DB; -} - -// dB -> linear conversion -inline float dB2lin(float dB) { - const float DB_2_LOG = 0.11512925464970228420089957273422f; // ln( 10 ) / 20 - return expf(dB * DB_2_LOG); -} - union FP32 { uint32_t u; float f;