mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-17 18:41:29 +00:00
Optimize Map::LoadV2 a bit
Microbenchmarking showed ~33% increase in loading moors Real world testing showed ~48%
This commit is contained in:
parent
c41521c310
commit
f431e820ef
120
zone/map.cpp
120
zone/map.cpp
@ -360,13 +360,13 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> data;
|
std::vector<char> data;
|
||||||
data.resize(data_size);
|
data.reserve(data_size);
|
||||||
if (fread(&data[0], data_size, 1, f) != 1) {
|
if (fread(&data[0], data_size, 1, f) != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> buffer;
|
std::vector<char> buffer;
|
||||||
buffer.resize(buffer_size);
|
buffer.reserve(buffer_size);
|
||||||
uint32 v = InflateData(&data[0], data_size, &buffer[0], buffer_size);
|
uint32 v = InflateData(&data[0], data_size, &buffer[0], buffer_size);
|
||||||
|
|
||||||
char *buf = &buffer[0];
|
char *buf = &buffer[0];
|
||||||
@ -412,7 +412,9 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
buf += sizeof(float);
|
buf += sizeof(float);
|
||||||
|
|
||||||
std::vector<glm::vec3> verts;
|
std::vector<glm::vec3> verts;
|
||||||
|
verts.reserve(vert_count);
|
||||||
std::vector<uint32> indices;
|
std::vector<uint32> indices;
|
||||||
|
indices.reserve(ind_count);
|
||||||
|
|
||||||
for (uint32 i = 0; i < vert_count; ++i) {
|
for (uint32 i = 0; i < vert_count; ++i) {
|
||||||
float x;
|
float x;
|
||||||
@ -428,16 +430,12 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
z = *(float*)buf;
|
z = *(float*)buf;
|
||||||
buf += sizeof(float);
|
buf += sizeof(float);
|
||||||
|
|
||||||
glm::vec3 vert(x, y, z);
|
verts.emplace_back(x, y, z);
|
||||||
verts.push_back(vert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32 i = 0; i < ind_count; ++i) {
|
for (uint32 i = 0; i < ind_count; ++i) {
|
||||||
uint32 index;
|
indices.emplace_back(*(uint32 *)buf);
|
||||||
index = *(uint32*)buf;
|
|
||||||
buf += sizeof(uint32);
|
buf += sizeof(uint32);
|
||||||
|
|
||||||
indices.push_back(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32 i = 0; i < nc_vert_count; ++i) {
|
for (uint32 i = 0; i < nc_vert_count; ++i) {
|
||||||
@ -460,7 +458,7 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
uint32 poly_count = *(uint32*)buf;
|
uint32 poly_count = *(uint32*)buf;
|
||||||
buf += sizeof(uint32);
|
buf += sizeof(uint32);
|
||||||
|
|
||||||
me->verts.resize(vert_count);
|
me->verts.reserve(vert_count);
|
||||||
for (uint32 j = 0; j < vert_count; ++j) {
|
for (uint32 j = 0; j < vert_count; ++j) {
|
||||||
float x = *(float*)buf;
|
float x = *(float*)buf;
|
||||||
buf += sizeof(float);
|
buf += sizeof(float);
|
||||||
@ -469,10 +467,10 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
float z = *(float*)buf;
|
float z = *(float*)buf;
|
||||||
buf += sizeof(float);
|
buf += sizeof(float);
|
||||||
|
|
||||||
me->verts[j] = glm::vec3(x, y, z);
|
me->verts.emplace_back(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
me->polys.resize(poly_count);
|
me->polys.reserve(poly_count);
|
||||||
for (uint32 j = 0; j < poly_count; ++j) {
|
for (uint32 j = 0; j < poly_count; ++j) {
|
||||||
uint32 v1 = *(uint32*)buf;
|
uint32 v1 = *(uint32*)buf;
|
||||||
buf += sizeof(uint32);
|
buf += sizeof(uint32);
|
||||||
@ -527,6 +525,8 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
auto &mod_verts = model->verts;
|
auto &mod_verts = model->verts;
|
||||||
for (uint32 j = 0; j < mod_polys.size(); ++j) {
|
for (uint32 j = 0; j < mod_polys.size(); ++j) {
|
||||||
auto ¤t_poly = mod_polys[j];
|
auto ¤t_poly = mod_polys[j];
|
||||||
|
if (current_poly.vis == 0)
|
||||||
|
continue;
|
||||||
auto v1 = mod_verts[current_poly.v1];
|
auto v1 = mod_verts[current_poly.v1];
|
||||||
auto v2 = mod_verts[current_poly.v2];
|
auto v2 = mod_verts[current_poly.v2];
|
||||||
auto v3 = mod_verts[current_poly.v3];
|
auto v3 = mod_verts[current_poly.v3];
|
||||||
@ -543,27 +543,13 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
TranslateVertex(v2, x, y, z);
|
TranslateVertex(v2, x, y, z);
|
||||||
TranslateVertex(v3, x, y, z);
|
TranslateVertex(v3, x, y, z);
|
||||||
|
|
||||||
float t = v1.x;
|
verts.emplace_back(v1.y, v1.x, v1.z); // x/y swapped
|
||||||
v1.x = v1.y;
|
verts.emplace_back(v2.y, v2.x, v2.z);
|
||||||
v1.y = t;
|
verts.emplace_back(v3.y, v3.x, v3.z);
|
||||||
|
|
||||||
t = v2.x;
|
indices.emplace_back((uint32)verts.size() - 3);
|
||||||
v2.x = v2.y;
|
indices.emplace_back((uint32)verts.size() - 2);
|
||||||
v2.y = t;
|
indices.emplace_back((uint32)verts.size() - 1);
|
||||||
|
|
||||||
t = v3.x;
|
|
||||||
v3.x = v3.y;
|
|
||||||
v3.y = t;
|
|
||||||
|
|
||||||
if (current_poly.vis != 0) {
|
|
||||||
verts.push_back(v1);
|
|
||||||
verts.push_back(v2);
|
|
||||||
verts.push_back(v3);
|
|
||||||
|
|
||||||
indices.push_back((uint32)verts.size() - 3);
|
|
||||||
indices.push_back((uint32)verts.size() - 2);
|
|
||||||
indices.push_back((uint32)verts.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,6 +617,8 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
|
|
||||||
for (size_t k = 0; k < model->polys.size(); ++k) {
|
for (size_t k = 0; k < model->polys.size(); ++k) {
|
||||||
auto &poly = model->polys[k];
|
auto &poly = model->polys[k];
|
||||||
|
if (poly.vis == 0)
|
||||||
|
continue;
|
||||||
glm::vec3 v1, v2, v3;
|
glm::vec3 v1, v2, v3;
|
||||||
|
|
||||||
v1 = model->verts[poly.v1];
|
v1 = model->verts[poly.v1];
|
||||||
@ -693,27 +681,13 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
TranslateVertex(v2, x, y, z);
|
TranslateVertex(v2, x, y, z);
|
||||||
TranslateVertex(v3, x, y, z);
|
TranslateVertex(v3, x, y, z);
|
||||||
|
|
||||||
float t = v1.x;
|
verts.emplace_back(v1.y, v1.x, v1.z); // x/y swapped
|
||||||
v1.x = v1.y;
|
verts.emplace_back(v2.y, v2.x, v2.z);
|
||||||
v1.y = t;
|
verts.emplace_back(v3.y, v3.x, v3.z);
|
||||||
|
|
||||||
t = v2.x;
|
indices.emplace_back((uint32)verts.size() - 3);
|
||||||
v2.x = v2.y;
|
indices.emplace_back((uint32)verts.size() - 2);
|
||||||
v2.y = t;
|
indices.emplace_back((uint32)verts.size() - 1);
|
||||||
|
|
||||||
t = v3.x;
|
|
||||||
v3.x = v3.y;
|
|
||||||
v3.y = t;
|
|
||||||
|
|
||||||
if (poly.vis != 0) {
|
|
||||||
verts.push_back(v1);
|
|
||||||
verts.push_back(v2);
|
|
||||||
verts.push_back(v3);
|
|
||||||
|
|
||||||
indices.push_back((uint32)verts.size() - 3);
|
|
||||||
indices.push_back((uint32)verts.size() - 2);
|
|
||||||
indices.push_back((uint32)verts.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -722,8 +696,8 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
uint32 ter_vert_count = ((quads_per_tile + 1) * (quads_per_tile + 1));
|
uint32 ter_vert_count = ((quads_per_tile + 1) * (quads_per_tile + 1));
|
||||||
std::vector<uint8> flags;
|
std::vector<uint8> flags;
|
||||||
std::vector<float> floats;
|
std::vector<float> floats;
|
||||||
flags.resize(ter_quad_count);
|
flags.reserve(ter_quad_count);
|
||||||
floats.resize(ter_vert_count);
|
floats.reserve(ter_vert_count);
|
||||||
for (uint32 i = 0; i < tile_count; ++i) {
|
for (uint32 i = 0; i < tile_count; ++i) {
|
||||||
bool flat;
|
bool flat;
|
||||||
flat = *(bool*)buf;
|
flat = *(bool*)buf;
|
||||||
@ -759,18 +733,18 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
float QuadVertex4Z = QuadVertex1Z;
|
float QuadVertex4Z = QuadVertex1Z;
|
||||||
|
|
||||||
uint32 current_vert = (uint32)verts.size() + 3;
|
uint32 current_vert = (uint32)verts.size() + 3;
|
||||||
verts.push_back(glm::vec3(QuadVertex1X, QuadVertex1Y, QuadVertex1Z));
|
verts.emplace_back(QuadVertex1X, QuadVertex1Y, QuadVertex1Z);
|
||||||
verts.push_back(glm::vec3(QuadVertex2X, QuadVertex2Y, QuadVertex2Z));
|
verts.emplace_back(QuadVertex2X, QuadVertex2Y, QuadVertex2Z);
|
||||||
verts.push_back(glm::vec3(QuadVertex3X, QuadVertex3Y, QuadVertex3Z));
|
verts.emplace_back(QuadVertex3X, QuadVertex3Y, QuadVertex3Z);
|
||||||
verts.push_back(glm::vec3(QuadVertex4X, QuadVertex4Y, QuadVertex4Z));
|
verts.emplace_back(QuadVertex4X, QuadVertex4Y, QuadVertex4Z);
|
||||||
|
|
||||||
indices.push_back(current_vert);
|
indices.emplace_back(current_vert);
|
||||||
indices.push_back(current_vert - 2);
|
indices.emplace_back(current_vert - 2);
|
||||||
indices.push_back(current_vert - 1);
|
indices.emplace_back(current_vert - 1);
|
||||||
|
|
||||||
indices.push_back(current_vert);
|
indices.emplace_back(current_vert);
|
||||||
indices.push_back(current_vert - 3);
|
indices.emplace_back(current_vert - 3);
|
||||||
indices.push_back(current_vert - 2);
|
indices.emplace_back(current_vert - 2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//read flags
|
//read flags
|
||||||
@ -825,7 +799,7 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i1 = (uint32)verts.size();
|
i1 = (uint32)verts.size();
|
||||||
verts.push_back(glm::vec3(QuadVertex1X, QuadVertex1Y, QuadVertex1Z));
|
verts.emplace_back(QuadVertex1X, QuadVertex1Y, QuadVertex1Z);
|
||||||
cur_verts[std::make_tuple(QuadVertex1X, QuadVertex1Y, QuadVertex1Z)] = i1;
|
cur_verts[std::make_tuple(QuadVertex1X, QuadVertex1Y, QuadVertex1Z)] = i1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,7 +810,7 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i2 = (uint32)verts.size();
|
i2 = (uint32)verts.size();
|
||||||
verts.push_back(glm::vec3(QuadVertex2X, QuadVertex2Y, QuadVertex2Z));
|
verts.emplace_back(QuadVertex2X, QuadVertex2Y, QuadVertex2Z);
|
||||||
cur_verts[std::make_tuple(QuadVertex2X, QuadVertex2Y, QuadVertex2Z)] = i2;
|
cur_verts[std::make_tuple(QuadVertex2X, QuadVertex2Y, QuadVertex2Z)] = i2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -847,7 +821,7 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i3 = (uint32)verts.size();
|
i3 = (uint32)verts.size();
|
||||||
verts.push_back(glm::vec3(QuadVertex3X, QuadVertex3Y, QuadVertex3Z));
|
verts.emplace_back(QuadVertex3X, QuadVertex3Y, QuadVertex3Z);
|
||||||
cur_verts[std::make_tuple(QuadVertex3X, QuadVertex3Y, QuadVertex3Z)] = i3;
|
cur_verts[std::make_tuple(QuadVertex3X, QuadVertex3Y, QuadVertex3Z)] = i3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -858,17 +832,17 @@ bool Map::LoadV2(FILE *f) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i4 = (uint32)verts.size();
|
i4 = (uint32)verts.size();
|
||||||
verts.push_back(glm::vec3(QuadVertex4X, QuadVertex4Y, QuadVertex4Z));
|
verts.emplace_back(QuadVertex4X, QuadVertex4Y, QuadVertex4Z);
|
||||||
cur_verts[std::make_tuple(QuadVertex4X, QuadVertex4Y, QuadVertex4Z)] = i4;
|
cur_verts[std::make_tuple(QuadVertex4X, QuadVertex4Y, QuadVertex4Z)] = i4;
|
||||||
}
|
}
|
||||||
|
|
||||||
indices.push_back(i4);
|
indices.emplace_back(i4);
|
||||||
indices.push_back(i2);
|
indices.emplace_back(i2);
|
||||||
indices.push_back(i3);
|
indices.emplace_back(i3);
|
||||||
|
|
||||||
indices.push_back(i4);
|
indices.emplace_back(i4);
|
||||||
indices.push_back(i1);
|
indices.emplace_back(i1);
|
||||||
indices.push_back(i2);
|
indices.emplace_back(i2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user