Merge pull request #623 from MihailRis/fixes

Fixes
This commit is contained in:
MihailRis 2025-09-23 01:09:50 +03:00 committed by GitHub
commit 286e03f590
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 86 additions and 16 deletions

View File

@ -86,9 +86,9 @@ body:get_size() -> vec3
body:set_size(size: vec3)
-- Returns the gravity multiplier
body:get_gravity_scale() -> vec3
body:get_gravity_scale() -> number
-- Sets the gravity multiplier
body:set_gravity_scale(scale: vec3)
body:set_gravity_scale(scale: number)
-- Returns the linear velocity attenuation multiplier (used to simulate air resistance and friction)
body:get_linear_damping() -> number

View File

@ -86,9 +86,9 @@ body:get_size() -> vec3
body:set_size(size: vec3)
-- Возвращает множитель гравитации
body:get_gravity_scale() -> vec3
body:get_gravity_scale() -> number
-- Устанавливает множитель гравитации
body:set_gravity_scale(scale: vec3)
body:set_gravity_scale(scale: number)
-- Возвращает множитель затухания линейной скорости (используется для имитации сопротивления воздуха и трения)
body:get_linear_damping() -> number

View File

@ -159,7 +159,7 @@ local prev_angle = (vec2.angle({dir[3], dir[1]})) % 360
function on_physics_update(delta)
local grounded = body:is_grounded()
body:set_vdamping(flight)
body:set_gravity_scale({0, flight and 0.0 or props.gravity_scale, 0})
body:set_gravity_scale(flight and 0.0 or props.gravity_scale)
body:set_linear_damping(
(flight or not grounded) and props.air_damping or props.ground_damping
)

View File

@ -43,7 +43,7 @@ float calc_shadow(
// TODO: add array textures support
float calc_shadow(vec4 modelPos, vec3 realnormal, float distance) {
#ifdef ENABLE_SHADOWS
float s = pow(abs(cos(u_dayTime * PI2)), 0.25) * u_shadowsOpacity;
float s = u_shadowsOpacity;
vec3 normalOffset = realnormal * (distance > 64.0 ? 0.2 : 0.04);
// as slow as mix(...)

View File

@ -4,7 +4,7 @@
#include <constants>
vec3 pick_sky_color(samplerCube cubemap) {
vec3 skyLightColor = texture(cubemap, vec3(0.8f, 0.01f, 0.4f)).rgb;
vec3 skyLightColor = texture(cubemap, vec3(0.4f, 0.05f, 0.4f)).rgb;
skyLightColor *= SKY_LIGHT_TINT;
skyLightColor = min(vec3(1.0f), skyLightColor * SKY_LIGHT_MUL);
skyLightColor = max(MIN_SKY_LIGHT, skyLightColor);

View File

@ -268,7 +268,11 @@ void main() {
camera_vector, // the camera vector (ray direction of this pixel)
1e12f, // max dist, essentially the scene depth
vec3(0.0f), // scene color, the color of the current pixel being rendered
vec3(u_lightDir.x, pow(u_lightDir.y, 3.0), u_lightDir.z), // light direction
vec3(
u_lightDir.x,
u_lightDir.y,
u_lightDir.z
), // light direction
vec3(40.0*fog), // light intensity, 40 looks nice
PLANET_POS, // position of the planet
PLANET_RADIUS, // radius of the planet in meters

View File

@ -32,7 +32,7 @@ protected:
void goBack(size_t count = 1);
void reset();
int64_t parseSimpleInt(int base);
int64_t parseSimpleInt(int base, size_t maxLength = 0xFFFFFFFF);
dv::value parseNumber(int sign);
dv::value parseNumber();
StringT parseString(CharT chr, bool closeRequired = true);

View File

@ -349,7 +349,10 @@ std::basic_string<CharT> BasicParser<CharT>::parseXmlName() {
}
template <typename CharT>
int64_t BasicParser<CharT>::parseSimpleInt(int base) {
int64_t BasicParser<CharT>::parseSimpleInt(int base, size_t maxLength) {
if (maxLength == 0) return 0;
size_t start = pos;
CharT c = peek();
int index = hexchar2int(c);
if (index == -1 || index >= base) {
@ -357,7 +360,7 @@ int64_t BasicParser<CharT>::parseSimpleInt(int base) {
}
int64_t value = index;
pos++;
while (hasNext()) {
while (hasNext() && pos - start < maxLength) {
c = source[pos];
while (c == '_') {
c = source[++pos];
@ -476,7 +479,7 @@ std::basic_string<CharT> BasicParser<CharT>::parseString(
continue;
}
if (c == 'u' || c == 'x') {
int codepoint = parseSimpleInt(16);
int codepoint = parseSimpleInt(16, c == 'u' ? 4 : 2);
ubyte bytes[4];
int size = util::encode_utf8(codepoint, bytes);
CharT chars[4];

View File

@ -96,12 +96,16 @@ void Shadows::setup(Shader& shader, const Weather& weather) {
if (shadows) {
const auto& worldInfo = level.getWorld()->getInfo();
float cloudsIntensity = glm::max(worldInfo.fog, weather.clouds());
float shadowsOpacity = 1.0f - cloudsIntensity;
shadowsOpacity *= glm::sqrt(glm::abs(
glm::mod((worldInfo.daytime + 0.5f) * 2.0f, 1.0f) * 2.0f - 1.0f
));
shader.uniform1i("u_screen", 0);
shader.uniformMatrix("u_shadowsMatrix[0]", shadowCamera.getProjView());
shader.uniformMatrix("u_shadowsMatrix[1]", wideShadowCamera.getProjView());
shader.uniform3f("u_sunDir", shadowCamera.front);
shader.uniform1i("u_shadowsRes", shadowMap->getResolution());
shader.uniform1f("u_shadowsOpacity", 1.0f - cloudsIntensity); // TODO: make it configurable
shader.uniform1f("u_shadowsOpacity", shadowsOpacity); // TODO: make it configurable
shader.uniform1f("u_shadowsSoftness", 1.0f + cloudsIntensity * 4); // TODO: make it configurable
glActiveTexture(GL_TEXTURE0 + TARGET_SHADOWS0);

View File

@ -22,7 +22,7 @@ namespace markdown {
Result<wchar_t> process(std::wstring_view source, bool eraseMarkdown);
template <typename CharT>
inline std::basic_string<CharT> escape(std::string_view source) {
inline std::basic_string<CharT> escape(std::basic_string_view<CharT> source) {
std::basic_stringstream<CharT> ss;
int pos = 0;
while (pos < source.size()) {

View File

@ -54,7 +54,12 @@ static int l_get_gravity_scale(lua::State* L) {
static int l_set_gravity_scale(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
entity->getRigidbody().hitbox.gravityScale = lua::tovec3(L, 2).y;
auto& hitbox = entity->getRigidbody().hitbox;
if (lua::istable(L, 2)) {
hitbox.gravityScale = lua::tovec3(L, 2).y;
} else {
hitbox.gravityScale = lua::tonumber(L, 2);
}
}
return 0;
}

View File

@ -40,7 +40,7 @@ std::string util::escape(std::string_view s, bool escapeUnicode) {
uint cpsize;
int codepoint = decode_utf8(cpsize, s.data() + pos);
if (escapeUnicode) {
ss << "\\u" << std::hex << codepoint;
ss << "\\u" << std::setw(4) << std::setfill('0') << std::hex << codepoint;
} else {
ss << std::string(s.data() + pos, cpsize);
}

View File

@ -1,4 +1,5 @@
#include "util/stringutil.hpp"
#include "coders/BasicParser.hpp"
#include <gtest/gtest.h>
@ -16,6 +17,25 @@ TEST(stringutil, utf8) {
EXPECT_EQ(str, str2);
}
static std::wstring gen_random_unicode_wstring(int n) {
std::wstring str;
str.resize(n);
for (int i = 0; i < n; i++) {
// wstring is 16 bit in some systems
str[i] = rand() & 0xFFFF;
}
return str;
}
TEST(stringutil, utf8_random) {
srand(5436324);
auto str = gen_random_unicode_wstring(10'000);
auto utf8str = util::wstr2str_utf8(str);
auto back = util::str2wstr_utf8(utf8str);
EXPECT_EQ(str, back);
}
TEST(stringutil, base64) {
srand(2019);
for (size_t size = 0; size < 30; size++) {
@ -47,3 +67,37 @@ TEST(stringutil, base64_urlsafe) {
}
}
}
class StringParser : BasicParser<char> {
public:
StringParser(std::string_view source) : BasicParser("<string>", source) {}
std::string parse() {
++pos;
return parseString(source[0], true);
}
};
TEST(stringutil, escape_cases) {
auto escaped = util::escape("тест5", true);
auto expected = "\"\\u0442\\u0435\\u0441\\u04425\"";
ASSERT_EQ(expected, escaped);
srand(345873458);
for (int i = 0; i < 36; i++) {
rand();
}
auto str = gen_random_unicode_wstring(40);
auto utf8str = util::wstr2str_utf8(str);
escaped = util::escape(utf8str, true);
StringParser parser(escaped);
auto restored = parser.parse();
for (int i = 0; i < utf8str.length(); i++) {
if (utf8str[i] != restored[i]) {
std::cout << i << ": " << (int)utf8str[i] << " " << (int)restored[i] << std::endl;
}
}
EXPECT_EQ(utf8str, restored);
}