Files
Cubed/include/glm/gtx/fast_exponential.inl
zhenyan121 def311c7dd feature: hud (#37)
* build: replace FetchContent with direct includes for glm

* build(deps): replace SOIL2 with stb for image and vorbis decoding

* build: replace FetchContent with direct includes for toml++

* refactor(texture): bump block texture size to 512 and disable items tab

* feat: add hotbar system with ItemStack and RowLayout

* fix(ui): restrict Ctrl key handling to typing mode

* feat(ui): add widget border support and highlight selected hotbar slot

* fix(ui): update borders on scale change and correct Image width

- Added update_border() calls in set_scale() for Button, ChatBox, Image, Label, and TextField.
- Fixed Image::width() to multiply by width instead of height.
- Added early return in Widget::update_border() if border is not supported.

* feat(ui): add border visual feedback on slider drag

* feat(ui): add ItemSlot widget and refactor hotbar to use it

* feat(world_scene): add inventory UI and pause type enum

* feat(ui): add item slot tooltip and make window size static

* fix(ui label): account for background offset in width/height

* refactor(ui): centralize item info label in inventory and add update

* feat(ui): add hotbar interaction in inventory UI

* fix(inventory-ui): correct row creation logic for first item

The loop starting at index 0 created a new row on the first iteration
(i % 10 == 0). Shift the loop to start at 1 and adjust modulus condition
to create rows correctly every 10 items.

* feat(block): add name_key for localized block names

Add `name_key` field to all block TOML definitions, enabling per-block localization. Update `BlockData` struct and `BlockManager` with `local_name()` method that returns a localized string via the translation system. Add corresponding entries to `en_US.json` and `zh_CN.json`. Modify inventory UI to use the localized name when displaying block info, and fix a bug where emptying a hotbar slot did not clear the item locally.

* fix(ui): change inventory item slot color from white to gray

* fix(ui): add missing include for std::array
2026-07-23 14:07:11 +08:00

137 lines
4.3 KiB
C++

/// @ref gtx_fast_exponential
namespace glm
{
// fastPow:
template<typename genType>
GLM_FUNC_QUALIFIER genType fastPow(genType x, genType y)
{
return exp(y * log(x));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastPow(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
{
return exp(y * log(x));
}
template<typename T>
GLM_FUNC_QUALIFIER T fastPow(T x, int y)
{
T f = static_cast<T>(1);
for(int i = 0; i < y; ++i)
f *= x;
return f;
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastPow(vec<L, T, Q> const& x, vec<L, int, Q> const& y)
{
vec<L, T, Q> Result;
for(length_t i = 0, n = x.length(); i < n; ++i)
Result[i] = fastPow(x[i], y[i]);
return Result;
}
// fastExp
// Note: This function provides accurate results only for value between -1 and 1, else avoid it.
template<typename T>
GLM_FUNC_QUALIFIER T fastExp(T x)
{
// This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower.
// return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f))));
T x2 = x * x;
T x3 = x2 * x;
T x4 = x3 * x;
T x5 = x4 * x;
return T(1) + x + (x2 * T(0.5)) + (x3 * T(0.1666666667)) + (x4 * T(0.041666667)) + (x5 * T(0.008333333333));
}
/* // Try to handle all values of float... but often shower than std::exp, glm::floor and the loop kill the performance
GLM_FUNC_QUALIFIER float fastExp(float x)
{
const float e = 2.718281828f;
const float IntegerPart = floor(x);
const float FloatPart = x - IntegerPart;
float z = 1.f;
for(int i = 0; i < int(IntegerPart); ++i)
z *= e;
const float x2 = FloatPart * FloatPart;
const float x3 = x2 * FloatPart;
const float x4 = x3 * FloatPart;
const float x5 = x4 * FloatPart;
return z * (1.0f + FloatPart + (x2 * 0.5f) + (x3 * 0.1666666667f) + (x4 * 0.041666667f) + (x5 * 0.008333333333f));
}
// Increase accuracy on number bigger that 1 and smaller than -1 but it's not enough for high and negative numbers
GLM_FUNC_QUALIFIER float fastExp(float x)
{
// This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower.
// return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f))));
float x2 = x * x;
float x3 = x2 * x;
float x4 = x3 * x;
float x5 = x4 * x;
float x6 = x5 * x;
float x7 = x6 * x;
float x8 = x7 * x;
return 1.0f + x + (x2 * 0.5f) + (x3 * 0.1666666667f) + (x4 * 0.041666667f) + (x5 * 0.008333333333f)+ (x6 * 0.00138888888888f) + (x7 * 0.000198412698f) + (x8 * 0.0000248015873f);;
}
*/
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastExp(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastExp, x);
}
// fastLog
template<typename genType>
GLM_FUNC_QUALIFIER genType fastLog(genType x)
{
return std::log(x);
}
/* Slower than the VC7.1 function...
GLM_FUNC_QUALIFIER float fastLog(float x)
{
float y1 = (x - 1.0f) / (x + 1.0f);
float y2 = y1 * y1;
return 2.0f * y1 * (1.0f + y2 * (0.3333333333f + y2 * (0.2f + y2 * 0.1428571429f)));
}
*/
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastLog(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastLog, x);
}
//fastExp2, ln2 = 0.69314718055994530941723212145818f
template<typename genType>
GLM_FUNC_QUALIFIER genType fastExp2(genType x)
{
return fastExp(static_cast<genType>(0.69314718055994530941723212145818) * x);
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastExp2(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastExp2, x);
}
// fastLog2, ln2 = 0.69314718055994530941723212145818f
template<typename genType>
GLM_FUNC_QUALIFIER genType fastLog2(genType x)
{
return fastLog(x) / static_cast<genType>(0.69314718055994530941723212145818);
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fastLog2(vec<L, T, Q> const& x)
{
return detail::functor1<vec, L, T, T, Q>::call(fastLog2, x);
}
}//namespace glm