2017-01-20 08:36:52 -05:00
|
|
|
#pragma once
|
|
|
|
|
2016-12-20 16:22:20 -05:00
|
|
|
namespace Assets
|
|
|
|
{
|
|
|
|
class IclipMap_t : public Components::AssetHandler::IAsset
|
|
|
|
{
|
|
|
|
public:
|
2018-05-09 06:04:20 -04:00
|
|
|
virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_CLIPMAP_MP; };
|
2016-12-20 16:22:20 -05:00
|
|
|
|
|
|
|
virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
|
|
|
|
virtual void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
|
2018-12-17 08:29:18 -05:00
|
|
|
virtual void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override;
|
2017-03-19 23:38:53 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
class SModelQuadtree
|
|
|
|
{
|
|
|
|
public:
|
2017-03-26 09:48:21 -04:00
|
|
|
SModelQuadtree()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-09 08:33:52 -04:00
|
|
|
SModelQuadtree(Game::cStaticModel_s* modelList, int numModels)
|
2017-03-19 23:38:53 -04:00
|
|
|
{
|
|
|
|
numValues = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < numModels; ++i)
|
|
|
|
{
|
2017-03-26 09:48:21 -04:00
|
|
|
insert(&modelList[i]);
|
2017-03-19 23:38:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 08:33:52 -04:00
|
|
|
void insert(Game::cStaticModel_s* item)
|
2017-03-19 23:38:53 -04:00
|
|
|
{
|
|
|
|
if (numValues < 4) // add here
|
|
|
|
{
|
|
|
|
values[numValues++] = item;
|
|
|
|
}
|
|
|
|
else // add to child
|
|
|
|
{
|
|
|
|
if (numValues == 4) // split
|
|
|
|
{
|
2017-03-26 09:48:21 -04:00
|
|
|
// create children objects
|
2017-03-19 23:38:53 -04:00
|
|
|
for (int i = 0; i < 4; ++i)
|
2017-03-26 09:48:21 -04:00
|
|
|
{
|
|
|
|
children[i] = new SModelQuadtree();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < numValues; ++i)
|
2017-03-19 23:38:53 -04:00
|
|
|
{
|
|
|
|
if (item->origin[0] > x && values[i]->origin[1] > y)
|
|
|
|
children[0]->insert(values[i]);
|
|
|
|
if (item->origin[0] < x && values[i]->origin[1] > y)
|
|
|
|
children[1]->insert(values[i]);
|
|
|
|
if (item->origin[0] < x && values[i]->origin[1] < y)
|
|
|
|
children[2]->insert(values[i]);
|
|
|
|
if (item->origin[0] > x && values[i]->origin[1] < y)
|
|
|
|
children[3]->insert(values[i]);
|
|
|
|
|
|
|
|
values[i] = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
children[i]->halfX = halfX / 2;
|
|
|
|
children[i]->halfY = halfY / 2;
|
2017-03-26 09:48:21 -04:00
|
|
|
children[i]->halfZ = halfZ;
|
2017-03-19 23:38:53 -04:00
|
|
|
}
|
2017-03-26 09:48:21 -04:00
|
|
|
|
|
|
|
// update origins here
|
|
|
|
|
|
|
|
numValues++;
|
2017-03-19 23:38:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item->origin[0] > x && item->origin[1] > y)
|
|
|
|
children[0]->insert(item);
|
|
|
|
if (item->origin[0] < x && item->origin[1] > y)
|
|
|
|
children[1]->insert(item);
|
|
|
|
if (item->origin[0] < x && item->origin[1] < y)
|
|
|
|
children[2]->insert(item);
|
|
|
|
if (item->origin[0] > x && item->origin[1] < y)
|
|
|
|
children[3]->insert(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SModelQuadtree* children[4];
|
2018-05-09 08:33:52 -04:00
|
|
|
Game::cStaticModel_s* values[4];
|
2017-03-19 23:38:53 -04:00
|
|
|
int numValues;
|
|
|
|
float x, y, z;
|
|
|
|
float halfX, halfY, halfZ;
|
|
|
|
};
|
2016-12-20 16:22:20 -05:00
|
|
|
};
|
|
|
|
}
|