Revert "* Improve the entity ID system, and add priority system. We should no longer have clashes."

This reverts commit 1b97875dd6.
This commit is contained in:
iProgramInCpp
2023-08-08 10:22:13 +03:00
parent 57c2b339ea
commit 1fdd94a43e
9 changed files with 6 additions and 78 deletions

View File

@@ -30,7 +30,6 @@ void HumanoidMobRenderer::additionalRendering(Mob* mob, float f)
ItemInstance inst(itemID, 1, 0);
glPushMatrix();
m_pHumanoidModel->m_armL.translateTo(0.0625f);
glTranslatef(-0.0625f, 0.4375f, 0.0625f);
if (itemID <= C_MAX_TILES && TileRenderer::canRender(Tile::tiles[itemID]->getRenderShape()))
@@ -65,14 +64,6 @@ void HumanoidMobRenderer::onGraphicsReset()
m_pHumanoidModel->onGraphicsReset();
}
void HumanoidMobRenderer::renderName(Mob* mob, float x, float y, float z)
{
if (!mob->isPlayer()) return;
Player* player = (Player*)mob;
renderNameTag(player, player->m_name, x, y, z, player->isSneaking() ? 32 : 64);
}
void HumanoidMobRenderer::renderHand()
{
m_pHumanoidModel->field_4 = 0;

View File

@@ -16,7 +16,6 @@ public:
HumanoidMobRenderer(HumanoidModel*, float);
virtual void additionalRendering(Mob*, float) override;
virtual void onGraphicsReset() override;
virtual void renderName(Mob*, float, float, float) override;
void renderHand();

View File

@@ -156,7 +156,7 @@ void MobRenderer::renderNameTag(Mob* mob, const std::string& str, float x, float
glNormal3f(0.0f, 1.0f, 0.0f);
// billboard the name towards the camera
glRotatef(-m_pDispatcher->m_yaw, 0.0f, 1.0f, 0.0f);
glRotatef(m_pDispatcher->m_pitch, 1.0f, 0.0f, 0.0f);
glRotatef(-m_pDispatcher->m_pitch, 1.0f, 0.0f, 0.0f);
glScalef(-0.026667f, -0.026667f, 0.026667f);
glDepthMask(false);
glDisable(GL_DEPTH_TEST);

View File

@@ -10,7 +10,7 @@
#include "Player.hpp"
#include "world/level/Level.hpp"
EntityIDSet Entity::s_EntityIDs;
int Entity::entityCounter;
Random Entity::sharedRandom;
void Entity::_init()
@@ -56,7 +56,6 @@ void Entity::_init()
field_D5 = false;
field_D6 = true;
field_D8 = 1;
m_EntityID = 0;
}
Entity::Entity(Level* pLevel)
@@ -64,7 +63,7 @@ Entity::Entity(Level* pLevel)
_init();
m_pLevel = pLevel;
m_EntityID = allocateEntityId();
m_EntityID = ++entityCounter;
setPos(0, 0, 0);
}
@@ -1065,31 +1064,3 @@ bool Entity::operator==(const Entity& other) const
{
return m_EntityID == other.m_EntityID;
}
bool Entity::isUnimportant()
{
return false;
}
int Entity::allocateEntityId()
{
int id = 1;
// TODO: could be improved? While a static monotonically increasing integer
// is okay, as long as entities with non-standard entity IDs start to get
// added you run into issues with clashing IDs, because Level::addEntity
// will actually remove the old entity with the same ID.
while (s_EntityIDs.find(id) != s_EntityIDs.end())
id++;
return id;
}
void Entity::releaseEntityId(int id)
{
EntityIDSet::iterator it = s_EntityIDs.find(id);
if (it == s_EntityIDs.end())
return;
s_EntityIDs.erase(it);
}

View File

@@ -8,7 +8,6 @@
#pragma once
#include <unordered_set>
#include "client/common/AABB.hpp"
#include "client/common/Vec3.hpp"
#include "world/level/Material.hpp"
@@ -40,22 +39,19 @@ struct EntityPos
EntityPos()
{
m_yaw = 0, m_pitch = 0;
m_bHasRot = false, m_bHasPos = false;
m_bHasRot, m_bHasPos;
};
EntityPos(const Vec3& pos)
{
m_pos = pos;
m_yaw = m_pitch = 0;
m_bHasPos = true;
m_bHasRot = false;
}
EntityPos(float yaw, float pitch)
{
m_yaw = yaw;
m_pitch = pitch;
m_bHasPos = false;
m_bHasRot = true;
}
@@ -69,8 +65,6 @@ struct EntityPos
}
};
typedef std::unordered_set<int> EntityIDSet;
class Entity
{
private:
@@ -140,7 +134,6 @@ public:
virtual void markHurt();
virtual void burn(int);
virtual void lavaHurt();
virtual bool isUnimportant();
int hashCode();
@@ -154,12 +147,8 @@ public:
(m_pos.z - z) * (m_pos.z - z);
}
private:
int allocateEntityId();
void releaseEntityId(int);
static EntityIDSet s_EntityIDs;
//static int entityCounter;
public:
static int entityCounter;
static Random sharedRandom;
Vec3 m_pos;

View File

@@ -279,14 +279,6 @@ Material* Level::getMaterial(int x, int y, int z)
Entity* Level::getEntity(int id)
{
// always prioritize players!!
for (auto it = m_entities.begin(); it != m_entities.end(); it++)
{
Entity* pEnt = *it;
if (pEnt->isPlayer() && pEnt->m_EntityID == id)
return pEnt;
}
for (auto it = m_entities.begin(); it != m_entities.end(); it++)
{
Entity* pEnt = *it;
@@ -1070,12 +1062,7 @@ bool Level::addEntity(Entity* pEnt)
{
Entity* pOldEnt = getEntity(pEnt->hashCode());
if (pOldEnt)
{
if (pOldEnt->isUnimportant())
removeEntity(pOldEnt);
else
LogMsg("Clash of entity IDs! (%d) This could go bad", pEnt->hashCode());
}
removeEntity(pOldEnt);
//@NOTE: useless Mth::floor() calls
Mth::floor(pEnt->m_pos.x / 16);

View File

@@ -52,11 +52,6 @@ int Particle::getParticleTexture()
return PT_PARTICLES;
}
bool Particle::isUnimportant()
{
return true;
}
Particle* Particle::scale(float f)
{
setSize(0.2f * f, 0.2f * f);

View File

@@ -36,7 +36,6 @@ public:
virtual void render(Tesselator&, float, float, float, float, float, float);
virtual int getParticleTexture();
virtual bool isUnimportant();
//TODO: addAdditonalSaveData
//TODO: readAdditionalSaveData
//TODO: defineSynchedData

View File

@@ -81,9 +81,6 @@ bool SandTile::isFree(Level* level, int x, int y, int z)
void SandTile::tick(Level* level, int x, int y, int z, Random* random)
{
if (level->field_11)
return;
checkSlide(level, x, y, z);
}