Updated test

This commit is contained in:
2024-11-25 16:20:48 +03:00
parent 40183a44a7
commit c0248e1b11
11 changed files with 249 additions and 1203 deletions

View File

@@ -68,6 +68,100 @@ String &String::operator+=(const char *p_str) {
return *this;
}
bool String::operator==(const String &p_str) const {
if (length() != p_str.length()) {
return false;
}
if (empty()) {
return true;
}
int l = length();
const CharType *src = c_str();
const CharType *dst = p_str.c_str();
/* Compare char by char */
for (int i = 0; i < l; i++) {
if (src[i] != dst[i]) {
return false;
}
}
return true;
}
bool String::operator!=(const String &p_str) const {
return !(*this == p_str);
}
bool String::operator==(const char *p_str) const {
int len = 0;
const char *aux = p_str;
while (*(aux++) != 0) {
len++;
}
if (length() != len) {
return false;
}
if (empty()) {
return true;
}
int l = length();
const CharType *dst = c_str();
/* Compare char by char */
for (int i = 0; i < l; i++) {
if (p_str[i] != dst[i]) {
return false;
}
}
return true;
}
bool String::operator==(const CharType *p_str) const {
int len = 0;
const CharType *aux = p_str;
while (*(aux++) != 0) {
len++;
}
if (length() != len) {
return false;
}
if (empty()) {
return true;
}
int l = length();
const CharType *dst = c_str();
/* Compare char by char */
for (int i = 0; i < l; i++) {
if (p_str[i] != dst[i]) {
return false;
}
}
return true;
}
bool String::operator!=(const char *p_str) const {
return (!(*this == p_str));
}
bool String::operator!=(const CharType *p_str) const {
return (!(*this == p_str));
}
CharString String::ascii(bool p_allow_extended) const {
if (!length()) {
return CharString();
@@ -314,5 +408,56 @@ const CharType *String::c_str() const {
}
bool operator==(const char *p_chr, const String &p_str) {
return p_str == p_chr;
}
String operator+(const char *p_chr, const String &p_str) {
String tmp = p_chr;
tmp += p_str;
return tmp;
}
String itos(int64_t p_val) {
return String::num_int64(p_val);
}
String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
bool sign = p_num < 0;
int64_t n = p_num;
int chars = 0;
do {
n /= base;
chars++;
} while (n);
if (sign) {
chars++;
}
String s;
s.resize(chars + 1);
CharType *c = s.ptrw();
c[chars] = 0;
n = p_num;
do {
int mod = ABS(n % base);
if (mod >= 10) {
char a = (capitalize_hex ? 'A' : 'a');
c[--chars] = a + (mod - 10);
} else {
c[--chars] = '0' + mod;
}
n /= base;
} while (n);
if (sign) {
c[0] = '-';
}
return s;
}

View File

@@ -188,7 +188,7 @@ void Vector<T>::append_array(Vector<T> p_other) {
template <class T>
bool Vector<T>::push_back(T p_elem) {
Error err = resize(size() + 1);
assert(err != OK);
assert(err == OK);
set(size() - 1, p_elem);
return false;

View File

@@ -2,6 +2,34 @@
int main()
{
int i;
flecs::world ecs;
flecs::entity graph_base_e = ecs.entity("graph");
flecs::entity graph_e = ecs.entity("v1").child_of(graph_base_e);
flecs::entity grid_base_e = ecs.entity("grid");
flecs::entity grid_e = ecs.entity("v1").child_of(grid_base_e);
flecs::entity grid_floor_e = ecs.entity("floor_0").child_of(grid_e);
List<struct region> region_list;
struct region region;
region.region_et = graph_e.id();
region.rect = RegionRect2i(0, 0, 25, 25);
struct region_tree regions;
regions.region = region;
regions.dump(grid_floor_e);
flecs::entity zone1_e = ecs.entity("zone1").child_of(graph_e),
zone2_e = ecs.entity("zone2").child_of(graph_e),
zone3_e = ecs.entity("zone3").child_of(graph_e);
struct region region_data[] = {
{.region_et = zone1_e.id(), .rect = {0, 0, 1, 1}},
{.region_et = zone2_e.id(), .rect = {2, 2, 1, 1}},
{.region_et = zone3_e.id(), .rect = {4, 4, 1 ,1}}
};
for (i = 0; i < sizeof(region_data) / sizeof(region_data[0]); i++)
region_list.push_back(region_data[i]);
regions.split(region_list);
regions.dump(grid_floor_e);
regions.grow();
regions.dump(grid_floor_e);
return 0;
}