Entity, Renderer: Add (incomplete) pig, remake entity renderer

This commit is contained in:
Er2
2023-12-03 19:35:51 +03:00
parent 0afea4428c
commit d6bf825c11
26 changed files with 283 additions and 70 deletions

View File

@@ -91,6 +91,7 @@ add_library(reminecraftpe-core STATIC
client/model/PolygonQuad.cpp
client/model/Model.cpp
client/model/HumanoidModel.cpp
client/model/PigModel.cpp
client/model/Cube.cpp
client/player/input/ControllerTurnInput.cpp
client/player/input/Controller.cpp
@@ -148,6 +149,7 @@ add_library(reminecraftpe-core STATIC
world/entity/Entity.cpp
world/entity/FallingTile.cpp
world/entity/TripodCamera.cpp
world/entity/Pig.cpp
world/entity/ItemEntity.cpp
world/level/Dimension.cpp
world/level/Material.cpp

View File

@@ -469,8 +469,9 @@ void Minecraft::tickInput()
bool thirdPerson = getOptions()->m_bThirdPerson;
if (thirdPerson && !getOptions()->field_241)
getOptions()->field_241 = 1;
else {
getOptions()->m_bThirdPerson = !getOptions()->m_bThirdPerson;
else
{
getOptions()->m_bThirdPerson = !thirdPerson;
getOptions()->field_241 = 0;
}
}

View File

@@ -16,30 +16,29 @@ Cube::Cube(int a, int b)
m_posX = m_posY = m_posZ = 0.0f;
m_rotX = m_rotY = m_rotZ = 0.0f;
field_18 = false;
field_19 = true;
field_1A = false;
m_swapX = false;
m_bIgnore = false;
m_bCompiled = false;
field_2C0 = 0;
m_buffer = 0;
m_brightness = 1.0f;
field_2B4 = a;
field_2B8 = b;
m_texOffsetX = a;
m_texOffsetY = b;
}
void Cube::addBox(float x, float y, float z, int d, int e, int f, float g)
void Cube::addBox(float x, float y, float z, int displayX, int displayY, int displayZ, float scale)
{
int d = displayX, e = displayY, f = displayZ;
float x1 = x, y1 = y, z1 = z;
float x2 = x + float(d), y2 = y + float(e), z2 = z + float(f);
x1 -= g;
y1 -= g;
z1 -= g;
x2 += g;
y2 += g;
z2 += g;
x1 -= scale;
y1 -= scale;
z1 -= scale;
x2 += scale;
y2 += scale;
z2 += scale;
if (field_18)
if (m_swapX)
std::swap(x1, x2);
m_verts[0] = VertexPT(x1, y1, z1, 0.0f, 0.0f);
@@ -51,7 +50,7 @@ void Cube::addBox(float x, float y, float z, int d, int e, int f, float g)
m_verts[6] = VertexPT(x2, y2, z2, 8.0f, 8.0f);
m_verts[7] = VertexPT(x1, y2, z2, 8.0f, 0.0f);
int m = field_2B4, n = field_2B8;
int m = m_texOffsetX, n = m_texOffsetY;
m_faces[0] = PolygonQuad(&m_verts[5], &m_verts[1], &m_verts[2], &m_verts[6], m + f + d, n + f, m + f + d + f, n + f + e); // x2 face
m_faces[1] = PolygonQuad(&m_verts[0], &m_verts[4], &m_verts[7], &m_verts[3], m, n + f, m + f, n + f + e); // x1 face
@@ -68,7 +67,7 @@ void Cube::addBox(float x, float y, float z, int d, int e, int f, float g)
m_faces[3].setColor(0.5f, 0.5f, 0.5f);
#endif
if (field_18)
if (m_swapX)
{
for (int i = 0; i < 6; i++)
m_faces[i].mirror();
@@ -114,10 +113,7 @@ void Cube::drawSlow(float scale)
void Cube::render(float scale)
{
if (field_1A)
return;
if (!field_19)
if (m_bIgnore)
return;
if (!m_bCompiled)
@@ -159,10 +155,7 @@ void Cube::translateRotTo(float scale)
void Cube::translateTo(float scale)
{
if (field_1A)
return;
if (!field_19)
if (m_bIgnore)
return;
if (!hasDefaultRot())
@@ -197,6 +190,6 @@ void Cube::setPos(float x, float y, float z)
void Cube::setTexOffs(int a, int b)
{
field_2B4 = a;
field_2B8 = b;
m_texOffsetX = a;
m_texOffsetY = b;
}

View File

@@ -15,7 +15,7 @@ class Cube
public:
Cube(int, int);
void addBox(float a, float b, float c, int d, int e, int f, float g = 0);
void addBox(float x, float y, float z, int displayX, int displayY, int displayZ, float scale = 0);
// @TODO: void addTexBox(float a, float b, float c, int d, int e, int f, int g); -- No xrefs
void compile(float scale);
void draw();
@@ -39,15 +39,13 @@ public:
float m_rotX;
float m_rotY;
float m_rotZ;
bool field_18;
bool field_19;
bool field_1A;
bool m_swapX;
bool m_bIgnore;
VertexPT m_verts[8];
PolygonQuad m_faces[6];
int field_2B4;
int field_2B8;
int m_texOffsetX;
int m_texOffsetY;
bool m_bCompiled;
int field_2C0;
GLuint m_buffer;
float m_brightness;

View File

@@ -27,12 +27,12 @@ HumanoidModel::HumanoidModel(float a, float b):
m_body.setPos(0, b, 0);
m_armL.addBox(-3, -2, -2, 4, 12, 4, a);
m_armL.setPos(-5, b + 2, 0);
m_armR.field_18 = true;
m_armR.m_swapX = true;
m_armR.addBox(-1, -2, -2, 4, 12, 4, a);
m_armR.setPos(5, b + 2, 0);
m_legL.addBox(-2, 0, -2, 4, 12, 4, a);
m_legL.setPos(-2, b + 12, 0);
m_legR.field_18 = true;
m_legR.m_swapX = true;
m_legR.addBox(-2, 0, -2, 4, 12, 4, a);
m_legR.setPos(2, b + 12, 0);
}

View File

@@ -8,10 +8,11 @@
#include "Model.hpp"
Model::Model()
Model::Model(std::string texture)
{
field_4 = 0.0f;
field_8 = false;
m_texture = texture;
}
void Model::onGraphicsReset()

View File

@@ -15,7 +15,7 @@ class Mob;
class Model
{
public:
Model();
Model(std::string texture = "mob/char.png");
virtual void onGraphicsReset();
virtual void prepareMobModel(Mob*, float, float, float);
virtual void render(float, float, float, float, float, float);
@@ -25,4 +25,5 @@ public:
public:
float field_4;
bool field_8;
std::string m_texture;
};

View File

@@ -0,0 +1,107 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "PigModel.hpp"
#include "client/app/Minecraft.hpp"
PigModel::PigModel(float a, float b):
Model("mob/pig.png"),
m_head(0, 0),
m_body(28, 16),
m_armL(0, 16),
m_armR(0, 16),
m_legL(0, 16),
m_legR(0, 16),
m_snout(16, 16)
{
// @NOTE: Why 25 (19+6) is lowest Y coordinate? I have many questions to Mojang
m_head.addBox(-2, 9, -9, 8, 8, 8, a);
m_head.setPos(0, b, 0);
m_snout.addBox(0, 12, -10, 4, 3, 1);
m_snout.setPos(0, b, 0);
m_body.addBox(-3, 11, -3, 10, 8, 16, a);
m_body.setPos(0, b, 0);
m_armL.addBox(-3, 19, -2, 4, 6, 4, a);
m_armL.setPos(0, b, 0);
m_armR.addBox(3, 19, -2, 4, 6, 4, a);
m_armR.setPos(0, b, 0);
m_legL.addBox(-3, 19, 9, 4, 6, 4, a);
m_legL.setPos(0, b, 0);
m_legR.addBox(3, 19, 9, 4, 6, 4, a);
m_legR.setPos(0, b, 0);
}
void PigModel::_logGraphics()
{
Matrix m;
if (Minecraft::customDebugId == 1)
{
// @NOTE: I think most of this function was ifdef'd/commented out
m.fetchGL(GL_MODELVIEW_MATRIX);
}
}
void PigModel::onGraphicsReset()
{
m_head.m_bCompiled = false;
m_body.m_bCompiled = false;
m_armL.m_bCompiled = false;
m_armR.m_bCompiled = false;
m_legL.m_bCompiled = false;
m_legR.m_bCompiled = false;
m_snout.m_bCompiled = false;
}
void PigModel::render(float a, float b, float c, float d, float e, float f)
{
setupAnim(a, b, c, d, e, f);
m_head.render(f);
m_snout.render(f);
m_body.render(f);
m_armL.render(f);
m_armR.render(f);
m_legL.render(f);
m_legR.render(f);
_logGraphics();
}
void PigModel::setupAnim(float a2, float a3, float a4, float yaw, float pitch, float a7)
{
m_snout.m_rotY = m_head.m_rotY = std::clamp(yaw * 0.017453f, -0.5f, 0.5f);
m_snout.m_rotX = m_head.m_rotX = std::clamp(pitch * 0.017453f, -0.5f, 0.5f);
float v12 = (a2 * 0.6662f) + 3.1416f;
m_armL.m_rotX = m_legL.m_rotX = Mth::cos(a2 * 0.6662f) * 0.2f * a3;
m_armR.m_rotX = m_legR.m_rotX = Mth::cos(v12) * 0.2f * a3;
m_armL.m_rotY = m_legL.m_rotY = 0.0f;
m_armR.m_rotY = m_legR.m_rotY = 0.0f;
if (field_8)
{
float v16 = (3.1416f * -0.5f) * 0.8f;
m_armL.m_rotX = m_legL.m_rotX = v16;
m_armR.m_rotX = m_legR.m_rotX = v16;
m_armL.m_rotY = m_legL.m_rotY = (3.1416f * 0.5f) * 0.2f;
m_armR.m_rotY = m_legR.m_rotY = (3.1416f * -0.5f) * 0.2f;
}
}
void PigModel::setBrightness(float f)
{
m_head.setBrightness(f);
m_snout.setBrightness(f);
m_body.setBrightness(f);
m_armL.setBrightness(f);
m_armR.setBrightness(f);
m_legL.setBrightness(f);
m_legR.setBrightness(f);
}

View File

@@ -0,0 +1,31 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#pragma once
#include "Model.hpp"
class PigModel : public Model
{
public:
PigModel(float a, float b);
void _logGraphics();
// @TODO - No xrefs: void render(PigModel* a, float f);
void onGraphicsReset() override;
void render(float, float, float, float, float, float) override;
void setupAnim(float, float, float, float, float, float) override;
void setBrightness(float) override;
public:
Cube m_head, m_body, m_armL, m_armR, m_legL, m_legR, m_snout;
bool field_10BC;
bool field_10BD;
bool field_10BE;
};

View File

@@ -7,6 +7,7 @@
********************************************************************/
#include "ItemInHandRenderer.hpp"
#include "entity/HumanoidMobRenderer.hpp"
#include "client/app/Minecraft.hpp"
ItemInHandRenderer::ItemInHandRenderer(Minecraft* pMC) :
@@ -186,7 +187,8 @@ void ItemInHandRenderer::render(float f)
glRotatef(Mth::sin(float(M_PI) * Mth::sqrt(fAnim)) * 70.0f, 0.0f, 1.0f, 0.0f);
glRotatef(Mth::sin(float(M_PI) * fAnim * fAnim) * -20.0f, 0.0f, 0.0f, 1.0f);
m_pMinecraft->m_pTextures->loadAndBindTexture("mob/char.png");
HumanoidMobRenderer* pRenderer = (HumanoidMobRenderer*)EntityRenderDispatcher::getInstance()->getRenderer(m_pMinecraft->m_pLocalPlayer);
m_pMinecraft->m_pTextures->loadAndBindTexture(pRenderer->m_pModel->m_texture);
glTranslatef(-1.0f, 3.6f, 3.5f);
glRotatef(120.0f, 0.0f, 0.0f, 1.0f);
glRotatef(200.0f, 1.0f, 0.0f, 0.0f);
@@ -194,7 +196,6 @@ void ItemInHandRenderer::render(float f)
glScalef(1.0f, 1.0f, 1.0f);
glTranslatef(5.6f, 0.0f, 0.0f);
HumanoidMobRenderer* pRenderer = (HumanoidMobRenderer*)EntityRenderDispatcher::getInstance()->getRenderer(m_pMinecraft->m_pLocalPlayer);
glScalef(1.0f, 1.0f, 1.0f);
pRenderer->renderHand();

View File

@@ -14,7 +14,8 @@ EntityRenderDispatcher* EntityRenderDispatcher::instance;
float EntityRenderDispatcher::xOff, EntityRenderDispatcher::yOff, EntityRenderDispatcher::zOff;
EntityRenderDispatcher::EntityRenderDispatcher() :
m_HumanoidMobRenderer(new HumanoidModel(0.0f, 0.0f), 0.0f)
m_ModelRenderer(nullptr, 0),
m_HumanoidRenderer(new HumanoidModel(0.0f, 0.0f), 0.0f)
{
m_pItemInHandRenderer = nullptr;
m_pTextures = nullptr;
@@ -26,7 +27,8 @@ EntityRenderDispatcher::EntityRenderDispatcher() :
m_pOptions = nullptr;
m_pFont = nullptr;
m_HumanoidMobRenderer.init(this);
m_HumanoidRenderer.init(this);
m_ModelRenderer.init(this);
m_TntRenderer.init(this);
m_CameraRenderer.init(this);
@@ -74,7 +76,11 @@ EntityRenderer* EntityRenderDispatcher::getRenderer(Entity* pEnt)
case RENDER_CAMERA:
return &m_CameraRenderer;
case RENDER_HUMANOID:
return &m_HumanoidMobRenderer;
m_HumanoidRenderer.m_pModel = m_HumanoidRenderer.m_pHumanoidModel = (HumanoidModel *)pEnt->getModel();
return &m_HumanoidRenderer;
case RENDER_MODEL:
m_ModelRenderer.m_pModel = pEnt->getModel();
return &m_ModelRenderer;
#ifdef ENH_ALLOW_SAND_GRAVITY
case RENDER_FALLING_TILE:
return &m_FallingTileRenderer;
@@ -86,7 +92,8 @@ EntityRenderer* EntityRenderDispatcher::getRenderer(Entity* pEnt)
void EntityRenderDispatcher::onGraphicsReset()
{
m_HumanoidMobRenderer.onGraphicsReset();
m_HumanoidRenderer.onGraphicsReset();
m_ModelRenderer.onGraphicsReset();
}
void EntityRenderDispatcher::prepare(Level* level, Textures* textures, Font* font, Mob* mob, Options* options, float f)

View File

@@ -9,11 +9,12 @@
#pragma once
#include "EntityRenderer.hpp"
#include "HumanoidMobRenderer.hpp"
#include "TripodCameraRenderer.hpp"
#include "TntRenderer.hpp"
#include "ItemRenderer.hpp"
#include "FallingTileRenderer.hpp"
#include "MobRenderer.hpp"
#include "HumanoidMobRenderer.hpp"
class Minecraft;
class Font;
@@ -40,7 +41,8 @@ public:
public:
ItemInHandRenderer* m_pItemInHandRenderer;
HumanoidMobRenderer m_HumanoidMobRenderer;
MobRenderer m_ModelRenderer;
HumanoidMobRenderer m_HumanoidRenderer;
TntRenderer m_TntRenderer;
ItemRenderer m_ItemRenderer;
TripodCameraRenderer m_CameraRenderer;

View File

@@ -9,7 +9,7 @@
#include "EntityRenderer.hpp"
#include "EntityRenderDispatcher.hpp"
EntityRenderer::EntityRenderer() : m_model(0.0f, 0.0f)
EntityRenderer::EntityRenderer()
{
field_4 = 0.0f;
field_8 = 1.0f;

View File

@@ -9,7 +9,7 @@
#pragma once
#include "world/phys/AABB.hpp"
#include "client/model/HumanoidModel.hpp"
#include "client/model/Model.hpp"
#include "client/renderer/Font.hpp"
class EntityRenderDispatcher;
@@ -31,8 +31,4 @@ public:
float field_4;
float field_8;
EntityRenderDispatcher* m_pDispatcher;
// @HUH: Why is there a HumanoidModel here? There's another
// in HumanoidMobRenderer...
HumanoidModel m_model;
};

View File

@@ -9,6 +9,7 @@
#pragma once
#include "MobRenderer.hpp"
#include "client/model/HumanoidModel.hpp"
class HumanoidMobRenderer : public MobRenderer
{

View File

@@ -104,7 +104,7 @@ void MobRenderer::render(Entity* entity, float x, float y, float z, float unused
x1 = 1.0f;
float x2 = pMob->field_130 - pMob->field_12C * (1.0f - f);
bindTexture("mob/char.png");
bindTexture(m_pModel->m_texture);
glEnable(GL_ALPHA_TEST);
m_pModel->setBrightness(entity->getBrightness(1.0f));
@@ -165,7 +165,7 @@ void MobRenderer::renderName(Mob* mob, float x, float y, float z)
void MobRenderer::renderNameTag(Mob* mob, const std::string& str, float x, float y, float z, int a)
{
if (mob->distanceToSqr(m_pDispatcher->m_pMob) > float(a * a))
if (mob->distanceToSqr(m_pDispatcher->m_pMob) > float(a * a) || str.length() == 0)
return;
Font* font = getFont();

View File

@@ -10,6 +10,7 @@
#include "common/Utils.hpp"
#include "world/entity/TripodCamera.hpp"
#include "world/entity/Pig.hpp"
#include "world/entity/PrimedTnt.hpp"
// This lets you make the server shut up and not log events in the debug console.
@@ -122,9 +123,9 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LoginPacke
sgp.m_version = 2;
sgp.m_time = m_pLevel->getTime();
RakNet::BitStream *sgpbs;
sgp.write(sgpbs);
m_pRakNetPeer->Send(sgpbs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false);
RakNet::BitStream sgpbs;
sgp.write(&sgpbs);
m_pRakNetPeer->Send(&sgpbs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false);
// send the connecting player info about all other players in the world
for (int i = 0; i < int(m_pLevel->m_players.size()); i++)
@@ -571,6 +572,11 @@ void ServerSideNetworkHandler::commandSummon(OnlinePlayer* player, const std::ve
else tnt->m_fuseTimer = 0; // as in original
ent = tnt;
}
else if (entity == "pig")
{
Pig *pig = new Pig(m_pLevel, pos.x, pos.y, pos.z);
ent = pig;
}
if (!ent)
{

View File

@@ -1082,3 +1082,8 @@ bool Entity::isLocalPlayer()
{
return false;
}
Model *Entity::getModel()
{
return nullptr;
}

View File

@@ -8,6 +8,7 @@
#pragma once
#include "client/model/Model.hpp"
#include "world/phys/Vec3.hpp"
#include "world/phys/AABB.hpp"
#include "world/level/Material.hpp"
@@ -24,6 +25,7 @@ enum eEntityRenderType
RENDER_NONE,
RENDER_TNT,
RENDER_HUMANOID,
RENDER_MODEL,
RENDER_ITEM,
RENDER_CAMERA,
@@ -46,7 +48,7 @@ struct EntityPos
EntityPos(const Vec3& pos)
{
m_pos = pos;
m_yaw = 0; m_pitch = 0;
m_yaw = 0; m_pitch = 0;
m_bHasPos = true;
m_bHasRot = false;
}
@@ -142,6 +144,8 @@ public:
virtual bool isLocalPlayer();
virtual Model *getModel();
int hashCode();
bool operator==(const Entity& other) const;

View File

@@ -57,8 +57,8 @@ Mob::Mob(Level* pLevel) : Entity(pLevel)
field_B84 = 0;
m_pEntLookedAt = nullptr;
m_texture = "/mob/char.png";
m_class = "";
m_renderType = RENDER_MODEL;
field_34 = 1;
@@ -439,11 +439,6 @@ void Mob::spawnAnim()
}
std::string Mob::getTexture()
{
return m_texture;
}
void Mob::playAmbientSound()
{

View File

@@ -40,7 +40,6 @@ public:
virtual bool canSee(Entity* pEnt);
virtual bool onLadder();
virtual void spawnAnim();
virtual std::string getTexture();
virtual bool isWaterMob();
virtual void playAmbientSound();
virtual int getAmbientSoundInterval();
@@ -109,8 +108,8 @@ public:
char field_B0C;
float field_B10;
float field_B14;
std::string m_texture;
std::string m_class;
std::string m_name;
int field_B48;
float field_B4C;
float field_B50;

View File

@@ -0,0 +1,26 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "Pig.hpp"
#include "world/level/Level.hpp"
Pig::Pig(Level* level, float x, float y, float z) : Mob(level)
{
setSize(1.5f, 0.5f);
field_84 = field_8C;
setPos(x, y, z);
field_3C.x = x;
field_3C.y = y;
field_3C.z = z;
}
Model *Pig::getModel()
{
return &m_model;
}

View File

@@ -0,0 +1,27 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#pragma once
#include "Mob.hpp"
#include "client/model/PigModel.hpp"
class Level;
class Player;
class Pig : public Mob
{
public:
Pig(Level*, float, float, float);
Model *getModel();
private:
PigModel m_model = PigModel(0.0f, 0.0f);
};

View File

@@ -9,7 +9,8 @@
#include "Player.hpp"
#include "world/level/Level.hpp"
Player::Player(Level* pLevel) : Mob(pLevel)
Player::Player(Level* pLevel) : Mob(pLevel),
m_model(0.0f, 0.0f)
{
m_pInventory = nullptr;
field_B94 = 0;
@@ -35,7 +36,6 @@ Player::Player(Level* pLevel) : Mob(pLevel)
m_health = 20;
m_class = "humanoid";
m_texture = "mob/char.png";
field_C4 = 20;
field_B5C = 180.0f;
@@ -373,3 +373,8 @@ void Player::interact(Entity* pEnt)
{
pEnt->interact(this);
}
Model *Player::getModel()
{
return &m_model;
}

View File

@@ -8,6 +8,7 @@
#pragma once
#include "client/model/HumanoidModel.hpp"
#include "common/Utils.hpp"
#include "thirdparty/raknet/RakNetTypes.h"
#include "world/item/Inventory.hpp"
@@ -71,6 +72,8 @@ public:
void interact(Entity* pEnt);
#pragma GCC diagnostic pop
Model *getModel();
public:
//TODO
Inventory* m_pInventory;
@@ -80,7 +83,6 @@ public:
float field_BA0;
bool field_BA4;
int field_BA8;
std::string m_name;
int field_BC4;
RakNet::RakNetGUID m_guid;
//TODO
@@ -88,5 +90,7 @@ public:
//TODO
bool m_bHaveRespawnPos;
//TODO
HumanoidModel m_model;
};

View File

@@ -7,6 +7,7 @@
********************************************************************/
#include "CameraItem.hpp"
#include "world/entity/Pig.hpp"
#include "world/level/Level.hpp"
#include "world/entity/TripodCamera.hpp"
#include "world/entity/Player.hpp"