Improved Tracers

This commit is contained in:
Elias Fleckenstein 2020-10-04 22:59:43 +02:00
parent c36ff3edb1
commit ee88f4b94f
7 changed files with 28 additions and 17 deletions

View File

@ -42,6 +42,11 @@ public:
return (n != m_active_objects.end() ? n->second : nullptr);
}
std::unordered_map<u16, T *> getAllActiveObjects() const
{
return m_active_objects;
}
protected:
u16 getFreeId() const
{

View File

@ -1289,9 +1289,6 @@ void Client::sendReady()
void Client::sendPlayerPos(v3f pos)
{
if (g_settings->getBool("freecam"))
return;
LocalPlayer *player = m_env.getLocalPlayer();
if (!player)
return;
@ -1309,7 +1306,7 @@ void Client::sendPlayerPos(v3f pos)
if (
player->last_position == pos &&
player->last_speed == player->getSpeed() &&
player->last_speed == player->getLegitSpeed() &&
player->last_pitch == player->getPitch() &&
player->last_yaw == player->getYaw() &&
player->last_keyPressed == player->keyPressed &&
@ -1318,7 +1315,7 @@ void Client::sendPlayerPos(v3f pos)
return;
player->last_position = pos;
player->last_speed = player->getSpeed();
player->last_speed = player->getLegitSpeed();
player->last_pitch = player->getPitch();
player->last_yaw = player->getYaw();
player->last_keyPressed = player->keyPressed;
@ -1337,7 +1334,7 @@ void Client::sendPlayerPos()
LocalPlayer *player = m_env.getLocalPlayer();
if (!player)
return;
sendPlayerPos(player->getPosition());
sendPlayerPos(player->getLegitPosition());
}
void Client::removeNode(v3s16 p)
@ -1678,7 +1675,7 @@ void Client::updateAllMapBlocks()
MapBlockVect blocks;
sector->getBlocks(blocks);
for (MapBlock *block : blocks) {
addUpdateMeshTask(block->getPos(), false, true);
addUpdateMeshTask(block->getPos(), false, false);
}
}
}

View File

@ -93,6 +93,11 @@ public:
return m_ao_manager.getActiveObject(id);
}
std::unordered_map<u16, ClientActiveObject*> getAllActiveObjects()
{
return m_ao_manager.getAllActiveObjects();
}
/*
Adds an active object to the environment.
Environment handles deletion of object.

View File

@ -44,6 +44,7 @@ public:
virtual void updateLight(u32 day_night_ratio) {}
virtual bool isItem() const { return false; }
virtual bool getCollisionBox(aabb3f *toset) const { return false; }
virtual bool getSelectionBox(aabb3f *toset) const { return false; }
virtual bool collideWithObjects() const { return false; }

View File

@ -215,6 +215,8 @@ public:
m_is_visible = toset;
}
bool isItem() const { return m_prop.visual == "wielditem" || m_prop.visual == "item"; }
void setChildrenVisible(bool toset);
void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
void getAttachment(int *parent_id, std::string *bone, v3f *position,

View File

@ -26,16 +26,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
void Tracers::draw(video::IVideoDriver* driver, Client *client)
{
ClientEnvironment &env = client->getEnv();
LocalPlayer *player = env.getLocalPlayer();
Camera *camera = client->getCamera();
v3f player_pos = player->getPosition();
v3f head_pos = camera->getPosition() + camera->getDirection();
std::vector<DistanceSortedActiveObject> allObjects;
env.getActiveObjects(player_pos, 1000000, allObjects);
for (const auto &allObject : allObjects) {
ClientActiveObject *obj = allObject.obj;
if (obj->isLocalPlayer() || obj->getParent())
auto allObjects = env.getAllActiveObjects();
for (auto &it : allObjects) {
ClientActiveObject *obj = it.second;
if (obj->isLocalPlayer() || obj->getParent() || obj->isItem())
continue;
driver->draw3DLine(head_pos, obj->getPosition(), video::SColor(255, 255, 255, 255));
v3f pos = obj->getPosition();
aabb3f box;
if (obj->getSelectionBox(&box))
pos += box.getCenter();
driver->draw3DLine(head_pos, pos, video::SColor(255, 255, 255, 255));
}
}