87 lines
2.2 KiB
C++
87 lines
2.2 KiB
C++
#include "map.hpp"
|
|
#include "cache.hpp"
|
|
#include "utils/files.hpp"
|
|
#include "cmdfile.hpp"
|
|
|
|
std::shared_ptr<const assets::Map> assets::Map::LoadFromFile(const std::string& filename)
|
|
{
|
|
auto map = std::make_shared<Map>();
|
|
|
|
LoadCMDFile(filename, [&](const std::string& command, std::istringstream& iss) {
|
|
if (command == "basemodel")
|
|
{
|
|
std::string model_name;
|
|
iss >> model_name;
|
|
|
|
map->basemodel_ = CacheManager::GetModel("data/" + model_name + ".mdl");
|
|
}
|
|
else if (command == "static")
|
|
{
|
|
MapStaticObject obj;
|
|
|
|
std::string model_name;
|
|
iss >> model_name;
|
|
|
|
obj.model = assets::CacheManager::GetModel("data/" + model_name + ".mdl");
|
|
|
|
glm::vec3 angles;
|
|
|
|
auto trans = &obj.node.local;
|
|
|
|
iss >> trans->position.x >> trans->position.y >> trans->position.z;
|
|
iss >> angles.x >> angles.y >> angles.z;
|
|
trans->SetAngles(angles);
|
|
iss >> trans->scale;
|
|
|
|
obj.node.UpdateMatrix();
|
|
|
|
std::string flag;
|
|
while (iss >> flag)
|
|
{
|
|
if (flag == "+color")
|
|
{
|
|
iss >> obj.color.r >> obj.color.g >> obj.color.b;
|
|
}
|
|
}
|
|
|
|
|
|
map->static_objects_.push_back(std::move(obj));
|
|
}
|
|
});
|
|
|
|
return map;
|
|
}
|
|
|
|
#ifdef CLIENT
|
|
void assets::Map::Draw(gfx::DrawList& dlist) const
|
|
{
|
|
if (!basemodel_ || !basemodel_->GetMesh())
|
|
return;
|
|
|
|
const auto& surfaces = basemodel_->GetMesh()->surfaces;
|
|
|
|
for (const auto& surface : surfaces)
|
|
{
|
|
gfx::DrawSurfaceCmd cmd;
|
|
cmd.surface = &surface;
|
|
dlist.AddSurface(cmd);
|
|
}
|
|
|
|
for (const auto& obj : static_objects_)
|
|
{
|
|
if (!obj.model || !obj.model->GetMesh())
|
|
continue;
|
|
|
|
const auto& surfaces = obj.model->GetMesh()->surfaces;
|
|
|
|
for (const auto& surface : surfaces)
|
|
{
|
|
gfx::DrawSurfaceCmd cmd;
|
|
cmd.surface = &surface;
|
|
cmd.matrices = &obj.node.matrix;
|
|
// cmd.color_mod = glm::vec4(obj.color, 1.0f);
|
|
dlist.AddSurface(cmd);
|
|
}
|
|
}
|
|
}
|
|
#endif // CLIENT
|