mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 05:21:49 +00:00
Merge branch 'MihailRis:main' into main
This commit is contained in:
commit
e694ce2ac1
6 changed files with 48 additions and 13 deletions
|
|
@ -21,7 +21,7 @@ input.get_bindings() -> table<string>
|
||||||
input.get_binding_text(bindname: string) -> string
|
input.get_binding_text(bindname: string) -> string
|
||||||
|
|
||||||
-- Проверяет активность привязки.
|
-- Проверяет активность привязки.
|
||||||
input.is_active(bindname: string) -> string
|
input.is_active(bindname: string) -> boolean
|
||||||
|
|
||||||
-- Включает/выключает привязку до выхода из мира.
|
-- Включает/выключает привязку до выхода из мира.
|
||||||
input.set_enabled(bindname: string, flag: boolean)
|
input.set_enabled(bindname: string, flag: boolean)
|
||||||
|
|
@ -74,4 +74,4 @@ input.add_callback("key:escape", function ()
|
||||||
print("NO")
|
print("NO")
|
||||||
return true -- предотвращает вызов назначенных ранее функций
|
return true -- предотвращает вызов назначенных ранее функций
|
||||||
end, document.root)
|
end, document.root)
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,26 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double power(double base, int64_t power) {
|
inline double power(double base, int64_t power) {
|
||||||
|
if (power == 0) {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t exp;
|
||||||
|
if (power < 0) {
|
||||||
|
base = 1.0 / base;
|
||||||
|
exp = static_cast<uint64_t>(-(power + 1)) + 1;
|
||||||
|
} else {
|
||||||
|
exp = static_cast<uint64_t>(power);
|
||||||
|
}
|
||||||
|
|
||||||
double result = 1.0;
|
double result = 1.0;
|
||||||
for (int64_t i = 0; i < power; i++) {
|
|
||||||
result *= base;
|
while (exp > 0) {
|
||||||
|
if (exp & 1)
|
||||||
|
result *= base;
|
||||||
|
|
||||||
|
base *= base;
|
||||||
|
exp >>= 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,10 @@
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T read_int_le(const uint8_t* src, size_t offset=0) {
|
inline T read_int_le(const uint8_t* src) {
|
||||||
return dataio::le2h(*(reinterpret_cast<const T*>(src) + offset));
|
T tmp;
|
||||||
|
std::memcpy(&tmp, src, sizeof(T));
|
||||||
|
return dataio::le2h(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Simple heap implementation for memory-optimal sparse array of
|
/// @brief Simple heap implementation for memory-optimal sparse array of
|
||||||
|
|
@ -87,8 +89,7 @@ namespace util {
|
||||||
std::memset(found, 0, entrySize);
|
std::memset(found, 0, entrySize);
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
this->free(found);
|
free(found);
|
||||||
return allocate(index, size);
|
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < entriesCount; i++) {
|
for (size_t i = 0; i < entriesCount; i++) {
|
||||||
auto data = buffer.data() + offset;
|
auto data = buffer.data() + offset;
|
||||||
|
|
@ -110,9 +111,12 @@ namespace util {
|
||||||
entriesCount++;
|
entriesCount++;
|
||||||
|
|
||||||
auto data = buffer.data() + offset;
|
auto data = buffer.data() + offset;
|
||||||
*reinterpret_cast<Tindex*>(data) = dataio::h2le(index);
|
|
||||||
|
Tindex indexTmp = dataio::h2le(index);
|
||||||
|
Tsize sizeTmp = dataio::h2le(size);
|
||||||
|
std::memcpy(data, &indexTmp, sizeof(Tindex));
|
||||||
data += sizeof(Tindex);
|
data += sizeof(Tindex);
|
||||||
*reinterpret_cast<Tsize*>(data) = dataio::h2le(size);
|
std::memcpy(data, &sizeTmp, sizeof(Tsize));
|
||||||
return data + sizeof(Tsize);
|
return data + sizeof(Tsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +126,7 @@ namespace util {
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return read_int_le<Tsize>(ptr, -1);
|
return read_int_le<Tsize>(ptr - sizeof(Tsize));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return number of entries
|
/// @return number of entries
|
||||||
|
|
@ -147,7 +151,8 @@ namespace util {
|
||||||
ubyte* dst = out.data();
|
ubyte* dst = out.data();
|
||||||
const ubyte* src = buffer.data();
|
const ubyte* src = buffer.data();
|
||||||
|
|
||||||
*reinterpret_cast<Tindex*>(dst) = dataio::h2le(entriesCount);
|
Tindex countTmp = dataio::h2le(entriesCount);
|
||||||
|
std::memcpy(dst, &countTmp, sizeof(Tindex));
|
||||||
dst += sizeof(Tindex);
|
dst += sizeof(Tindex);
|
||||||
|
|
||||||
std::memcpy(dst, src, buffer.size());
|
std::memcpy(dst, src, buffer.size());
|
||||||
|
|
@ -172,7 +177,7 @@ namespace util {
|
||||||
) : buffer(buffer), index(index), offset(offset) {}
|
) : buffer(buffer), index(index), offset(offset) {}
|
||||||
|
|
||||||
Tsize size() const {
|
Tsize size() const {
|
||||||
return read_int_le<Tsize>(buffer.data() + offset, -1);
|
return read_int_le<Tsize>(buffer.data() + offset - sizeof(Tsize));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const const_iterator& o) const {
|
bool operator!=(const const_iterator& o) const {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ static void init_gl_extensions_list() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[maybe_unused]]
|
||||||
static bool is_gl_extension_supported(const char *extension) {
|
static bool is_gl_extension_supported(const char *extension) {
|
||||||
if (!extension || !*extension) {
|
if (!extension || !*extension) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -40,6 +41,7 @@ static bool is_gl_extension_supported(const char *extension) {
|
||||||
return supported_gl_extensions.find(extension) != supported_gl_extensions.end();
|
return supported_gl_extensions.find(extension) != supported_gl_extensions.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
static const char* gl_error_name(int error) {
|
static const char* gl_error_name(int error) {
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case GL_DEBUG_TYPE_ERROR: return "ERROR";
|
case GL_DEBUG_TYPE_ERROR: return "ERROR";
|
||||||
|
|
@ -80,6 +82,7 @@ static void GLAPIENTRY gl_message_callback(
|
||||||
logger.warning() << "GL:" << gl_error_name(type) << ":"
|
logger.warning() << "GL:" << gl_error_name(type) << ":"
|
||||||
<< gl_severity_name(severity) << ": " << message;
|
<< gl_severity_name(severity) << ": " << message;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool initialize_gl(int width, int height) {
|
static bool initialize_gl(int width, int height) {
|
||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ TEST(JSON, EncodeDecode) {
|
||||||
const int bytesSize = 20;
|
const int bytesSize = 20;
|
||||||
const int year = 2019;
|
const int year = 2019;
|
||||||
const float score = 3.141592;
|
const float score = 3.141592;
|
||||||
|
const double distance = 1.23e45;
|
||||||
|
const double epsilon = 1e-6;
|
||||||
const bool visible = true;
|
const bool visible = true;
|
||||||
dv::objects::Bytes srcBytes(bytesSize);
|
dv::objects::Bytes srcBytes(bytesSize);
|
||||||
for (int i = 0; i < bytesSize; i ++) {
|
for (int i = 0; i < bytesSize; i ++) {
|
||||||
|
|
@ -20,6 +22,8 @@ TEST(JSON, EncodeDecode) {
|
||||||
object["name"] = name;
|
object["name"] = name;
|
||||||
object["year"] = year;
|
object["year"] = year;
|
||||||
object["score"] = score;
|
object["score"] = score;
|
||||||
|
object["distance"] = distance;
|
||||||
|
object["epsilon"] = epsilon;
|
||||||
object["visible"] = visible;
|
object["visible"] = visible;
|
||||||
object["data"] = srcBytes;
|
object["data"] = srcBytes;
|
||||||
|
|
||||||
|
|
@ -30,6 +34,8 @@ TEST(JSON, EncodeDecode) {
|
||||||
EXPECT_EQ(object["name"].asString(), name);
|
EXPECT_EQ(object["name"].asString(), name);
|
||||||
EXPECT_EQ(object["year"].asInteger(), year);
|
EXPECT_EQ(object["year"].asInteger(), year);
|
||||||
EXPECT_FLOAT_EQ(object["score"].asNumber(), score);
|
EXPECT_FLOAT_EQ(object["score"].asNumber(), score);
|
||||||
|
EXPECT_DOUBLE_EQ(object["distance"].asNumber(), distance);
|
||||||
|
EXPECT_DOUBLE_EQ(object["epsilon"].asNumber(), epsilon);
|
||||||
EXPECT_EQ(object["visible"].asBoolean(), visible);
|
EXPECT_EQ(object["visible"].asBoolean(), visible);
|
||||||
auto b64string = object["data"].asString();
|
auto b64string = object["data"].asString();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,13 @@ TEST(SmallHeap, Allocation) {
|
||||||
auto index = 0;
|
auto index = 0;
|
||||||
auto size = 4;
|
auto size = 4;
|
||||||
|
|
||||||
|
std::cout << "step 1" << std::endl;
|
||||||
SmallHeap<uint16_t, uint8_t> map;
|
SmallHeap<uint16_t, uint8_t> map;
|
||||||
|
std::cout << "step 2" << std::endl;
|
||||||
auto ptr = map.allocate(index, size);
|
auto ptr = map.allocate(index, size);
|
||||||
|
std::cout << "ptr: " << (void*)ptr << " le2h(1): " << dataio::le2h(1) << " h2le(1): " << dataio::h2le(1) << std::endl;
|
||||||
EXPECT_EQ(map.sizeOf(ptr), size);
|
EXPECT_EQ(map.sizeOf(ptr), size);
|
||||||
|
std::cout << "step 4" << std::endl;
|
||||||
EXPECT_EQ(ptr, map.find(index));
|
EXPECT_EQ(ptr, map.find(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue