refactor: remove calls to Vec3::newTemp when not returned

This commit is contained in:
orng 2026-03-26 04:19:04 -05:00
parent 9405f38f80
commit bee10e55a8
37 changed files with 6791 additions and 6831 deletions

View file

@ -6332,7 +6332,7 @@ int CMinecraftApp::WarningTrialTexturePackReturned(
DLCPack *pDLCPack=pDLCTexPack->getDLCInfoParentPack();//tPack->getDLCPack();
const char *pchPackName=wstringtofilename(pDLCPack->getName());
app.DebugPrintf("Texture Pack - %s\n",pchPackName);
SONYDLC *pSONYDLCInfo=app.GetSONYDLCInfo((char *)pchPackName);
SONYDLC *pSONYDLCInfo=app.GetSONYDLCInfo((char *)pchPackName);
if(pSONYDLCInfo!=NULL)
{
@ -6353,14 +6353,14 @@ int CMinecraftApp::WarningTrialTexturePackReturned(
#if defined __ORBIS__ || defined __PSVITA__ || defined __PS3__
if(app.CheckForEmptyStore(iPad)==false)
#endif
{
{
if(app.DLCAlreadyPurchased(chSkuID))
{
app.DownloadAlreadyPurchased(chSkuID);
}
else
{
app.Checkout(chSkuID);
app.Checkout(chSkuID);
}
}
}
@ -10355,4 +10355,4 @@ std::wstring CMinecraftApp::getRootPath(std::uint32_t packId,
void CMinecraftApp::SetReachedMainMenu() { m_hasReachedMainMenu = true; }
bool CMinecraftApp::HasReachedMainMenu() { return m_hasReachedMainMenu; }
#endif
#endif

View file

@ -251,4 +251,4 @@ void ApplySchematicRuleDefinition::reset() {
m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0;
m_completed = false;
}
}

View file

@ -463,8 +463,8 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
schematicCoordToChunkCoord(destinationBox, te->x, te->z, rot, targetX,
targetZ);
Vec3* pos = Vec3::newTemp(targetX, targetY, targetZ);
if (chunkBox->containsIncludingLowerBound(pos)) {
Vec3 pos(targetX, targetY, targetZ);
if (chunkBox->containsIncludingLowerBound(&pos)) {
std::shared_ptr<TileEntity> teCopy = chunk->getTileEntity(
(int)targetX & 15, (int)targetY & 15, (int)targetZ & 15);
@ -510,9 +510,8 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
// Add 0.01 as the AABB::contains function returns false if a value is
// <= the lower bound
Vec3* pos =
Vec3::newTemp(targetX + 0.01, targetY + 0.01, targetZ + 0.01);
if (!chunkBox->containsIncludingLowerBound(pos)) {
Vec3 pos(targetX + 0.01, targetY + 0.01, targetZ + 0.01);
if (!chunkBox->containsIncludingLowerBound(&pos)) {
++it;
continue;
}
@ -800,8 +799,8 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
// if (xs * ys * zs == LevelChunk::BLOCKS_LENGTH)
//{
// byteArray blockData = byteArray(data->data + blocksP,
//Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData); blocksP +=
//blockData.length;
// Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData);
// blocksP += blockData.length;
// byteArray dataData = byteArray(data->data + dataP, 16384);
// chunk->getBlockLightData(dataData);

View file

@ -37,15 +37,15 @@ bool AreaConstraint::canMoveToPosition(double xo, double yo, double zo,
double xt, double yt, double zt) {
if (!m_restrictsMovement) return true;
Vec3* targetPos = Vec3::newTemp(xt, yt, zt);
Vec3 targetPos(xt, yt, zt);
Minecraft* minecraft = Minecraft::GetInstance();
if (movementArea->contains(targetPos) == contains) {
if (movementArea->contains(&targetPos) == contains) {
return true;
}
Vec3* origPos = Vec3::newTemp(xo, yo, zo);
Vec3 origPos(xo, yo, zo);
double currDist = origPos->distanceTo(movementArea);
double targetDist = targetPos->distanceTo(movementArea);
double currDist = origPos.distanceTo(movementArea);
double targetDist = targetPos.distanceTo(movementArea);
return targetDist < currDist;
}

View file

@ -246,4 +246,4 @@ HRESULT CScene_Death::OnCustomMessage_Splitscreenplayer(bool bJoining,
bHandled = true;
return app.AdjustSplitscreenScene_PlayerChanged(m_hObj, &m_OriginalPosition,
m_iPad, bJoining);
}
}

View file

@ -1326,4 +1326,4 @@ void UIScene_PauseMenu::_ExitWorld(LPVOID lpParameter) {
void UIScene_PauseMenu::SetIgnoreInput(bool ignoreInput) {
m_bIgnoreInput = ignoreInput;
}
}

View file

@ -121,4 +121,4 @@ int Camera::getBlockAt(Level* level, std::shared_ptr<LivingEntity> player,
}
}
return t;
}
}

View file

@ -58,22 +58,22 @@ void FishingHookRenderer::render(std::shared_ptr<Entity> _hook, double x,
float swing = hook->owner->getAttackAnim(a);
float swing2 = (float)Mth::sin(sqrt(swing) * PI);
Vec3* vv = Vec3::newTemp(-0.5, 0.03, 0.8);
vv->xRot(-(hook->owner->xRotO +
Vec3 vv(-0.5, 0.03, 0.8);
vv.xRot(-(hook->owner->xRotO +
(hook->owner->xRot - hook->owner->xRotO) * a) *
PI / 180);
vv->yRot(-(hook->owner->yRotO +
vv.yRot(-(hook->owner->yRotO +
(hook->owner->yRot - hook->owner->yRotO) * a) *
PI / 180);
vv->yRot(swing2 * 0.5f);
vv->xRot(-swing2 * 0.7f);
vv.yRot(swing2 * 0.5f);
vv.xRot(-swing2 * 0.7f);
double xp =
hook->owner->xo + (hook->owner->x - hook->owner->xo) * a + vv->x;
hook->owner->xo + (hook->owner->x - hook->owner->xo) * a + vv.x;
double yp =
hook->owner->yo + (hook->owner->y - hook->owner->yo) * a + vv->y;
hook->owner->yo + (hook->owner->y - hook->owner->yo) * a + vv.y;
double zp =
hook->owner->zo + (hook->owner->z - hook->owner->zo) * a + vv->z;
hook->owner->zo + (hook->owner->z - hook->owner->zo) * a + vv.z;
double yOffset = hook->owner == std::dynamic_pointer_cast<Player>(
Minecraft::GetInstance()->player)
? 0

View file

@ -54,13 +54,13 @@ void MinecartRenderer::render(std::shared_ptr<Entity> _cart, double x, double y,
y += (p0->y + p1->y) / 2 - yy;
z += p->z - zz;
Vec3* dir = Vec3::newTemp(-p0->x, -p0->y, -p0->z);
*dir = dir->add(p1->x, p1->y, p1->z);
if (dir->length() == 0) {
Vec3 dir(-p0->x, -p0->y, -p0->z);
dir = dir.add(p1->x, p1->y, p1->z);
if (dir.length() == 0) {
} else {
*dir = dir->normalize();
rot = (float)(atan2(dir->z, dir->x) * 180 / PI);
xRot = (float)(atan(dir->y) * 73);
dir = dir.normalize();
rot = (float)(atan2(dir.z, dir.x) * 180 / PI);
xRot = (float)(atan(dir.y) * 73);
}
}
glTranslatef((float)x, (float)y, (float)z);

View file

@ -1045,9 +1045,8 @@ bool TileRenderer::tesselateAnvilInWorld(AnvilTile* tt, int x, int y, int z,
float TileRenderer::tesselateAnvilPiece(AnvilTile* tt, int x, int y, int z,
int part, float bottom, float width,
float height, float length,
bool rotate, bool render,
int data) {
float height, float length, bool rotate,
bool render, int data) {
if (rotate) {
float swap = width;
width = length;
@ -4068,9 +4067,11 @@ bool TileRenderer::tesselateCrossInWorld(Tile* tt, int x, int y, int z) {
float zt = (float)z;
if (tt == Tile::tallgrass) {
// 4jcraft add a bunch of casts to prevent overflow (i pray to god)
int64_t seed = ((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) + ((uint64_t)seed * 11ULL));
// 4jcraft add a bunch of casts to prevent overflow (i pray to god)
int64_t seed =
((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) +
((uint64_t)seed * 11ULL));
xt += ((((seed >> 16) & 0xf) / 15.0f) - 0.5f) * 0.5f;
yt += ((((seed >> 20) & 0xf) / 15.0f) - 1.0f) * 0.2f;
@ -4326,8 +4327,10 @@ bool TileRenderer::tesselateLilypadInWorld(Tile* tt, int x, int y, int z) {
float v1 = tex->getV1(true);
// 4jcraft add a bunch of casts to prevent overflow (i pray to god)
int64_t seed = ((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) + ((uint64_t)seed * 11ULL));
int64_t seed =
((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) +
((uint64_t)seed * 11ULL));
int dir = (int)((seed >> 16) & 0x3);

View file

@ -305,8 +305,8 @@ void GameRenderer::pick(float a) {
}
Vec3* b = mc->cameraTargetPlayer->getViewVector(a);
Vec3* to = Vec3::newTemp(b->x * range, b->y * range, b->z * range);
*to = to->add(from->x, from->y, from->z);
Vec3 to(b->x * range, b->y * range, b->z * range);
to = to.add(from->x, from->y, from->z);
hovered = nullptr;
float overlap = 1;
std::vector<std::shared_ptr<Entity> >* objects = mc->level->getEntities(
@ -323,7 +323,7 @@ void GameRenderer::pick(float a) {
float rr = e->getPickRadius();
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
HitResult* p = bb->clip(from, &to);
if (bb->contains(from)) {
if (0 < nearest || nearest == 0) {
hovered = e;
@ -524,11 +524,12 @@ void GameRenderer::moveCameraToPlayer(float a) {
// 4J - corrected bug here where zo was also added to x
// component
HitResult* hr = mc->level->clip(
Vec3::newTemp(x + xo, y + yo, z + zo),
Vec3::newTemp(x - xd + xo, y - yd + yo, z - zd + zo));
Vec3 a(x + xo, y + yo, z + zo);
Vec3 b(x - xd + xo, y - yd + yo, z - zd + zo);
HitResult* hr = mc->level->clip(&a, &b);
if (hr != NULL) {
double dist = hr->pos.distanceTo(*Vec3::newTemp(x, y, z));
Vec3 p(x, y, z);
double dist = hr->pos.distanceTo(p);
if (dist < cameraDist) cameraDist = dist;
delete hr;
}
@ -1865,10 +1866,10 @@ void GameRenderer::setupClearColor(float a) {
fb = (float)fogColor->z;
if (mc->options->viewDistance < 2) {
Vec3* sunAngle = Mth::sin(level->getSunAngle(a)) > 0
? Vec3::newTemp(-1, 0, 0)
: Vec3::newTemp(1, 0, 0);
float d = (float)player->getViewVector(a)->dot(*sunAngle);
Vec3 sunAngle = Mth::sin(level->getSunAngle(a)) > 0
? Vec3(-1, 0, 0)
: Vec3(1, 0, 0);
float d = (float)player->getViewVector(a)->dot(sunAngle);
if (d < 0) d = 0;
if (d > 0) {
float* c =

View file

@ -22,16 +22,16 @@ void Lighting::turnOn() {
float d = 0.6f;
float s = 0.0f;
Vec3* l = Vec3::newTemp(0.2f, 1.0f, -0.7f);
*l = l->normalize();
glLight(GL_LIGHT0, GL_POSITION, getBuffer(l->x, l->y, l->z, 0));
Vec3 l(0.2f, 1.0f, -0.7f);
l = l.normalize();
glLight(GL_LIGHT0, GL_POSITION, getBuffer(l.x, l.y, l.z, 0));
glLight(GL_LIGHT0, GL_DIFFUSE, getBuffer(d, d, d, 1));
glLight(GL_LIGHT0, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
glLight(GL_LIGHT0, GL_SPECULAR, getBuffer(s, s, s, 1.0f));
l = Vec3::newTemp(-0.2f, 1.0f, 0.7f);
*l = l->normalize();
glLight(GL_LIGHT1, GL_POSITION, getBuffer(l->x, l->y, l->z, 0));
l = Vec3(-0.2f, 1.0f, 0.7f);
l = l.normalize();
glLight(GL_LIGHT1, GL_POSITION, getBuffer(l.x, l.y, l.z, 0));
glLight(GL_LIGHT1, GL_DIFFUSE, getBuffer(d, d, d, 1));
glLight(GL_LIGHT1, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
glLight(GL_LIGHT1, GL_SPECULAR, getBuffer(s, s, s, 1.0f));

View file

@ -19,4 +19,4 @@ Vertex::Vertex(Vec3* pos, float u, float v) {
this->pos = pos;
this->u = u;
this->v = v;
}
}

View file

@ -64,10 +64,10 @@ bool AvoidPlayerGoal::canUse() {
delete entities;
}
Vec3 avoid_pos(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z);
Vec3* pos = RandomPos::getPosAvoid(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7,
Vec3::newTemp(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z));
7, &avoid_pos);
if (pos == NULL) return false;
if (toAvoid.lock()->distanceToSqr(pos->x, pos->y, pos->z) <
toAvoid.lock()->distanceToSqr(mob->shared_from_this()))

View file

@ -44,12 +44,11 @@ void MoveIndoorsGoal::start() {
}
if (mob->distanceToSqr(_doorInfo->getIndoorX(), _doorInfo->y,
_doorInfo->getIndoorZ()) > 16 * 16) {
Vec3 towards(_doorInfo->getIndoorX() + 0.5, _doorInfo->getIndoorY(),
_doorInfo->getIndoorZ() + 0.5);
Vec3* pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()),
14, 3,
Vec3::newTemp(_doorInfo->getIndoorX() + 0.5,
_doorInfo->getIndoorY(),
_doorInfo->getIndoorZ() + 0.5));
14, 3, &towards);
if (pos != NULL)
mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, 1.0f);
} else

View file

@ -47,9 +47,10 @@ bool MoveThroughVillageGoal::canUse() {
mob->getNavigation()->setCanOpenDoors(oldCanOpenDoors);
if (path != NULL) return true;
Vec3 towards(_doorInfo->x, _doorInfo->y, _doorInfo->z);
Vec3* pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10,
7, Vec3::newTemp(_doorInfo->x, _doorInfo->y, _doorInfo->z));
7, &towards);
if (pos == NULL) return false;
mob->getNavigation()->setCanOpenDoors(false);
delete path;

View file

@ -17,10 +17,11 @@ MoveTowardsRestrictionGoal::MoveTowardsRestrictionGoal(PathfinderMob* mob,
bool MoveTowardsRestrictionGoal::canUse() {
if (mob->isWithinRestriction()) return false;
Pos* towards = mob->getRestrictCenter();
Pos* toward = mob->getRestrictCenter();
Vec3 towards(toward->x, toward->y, toward->z);
Vec3* pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, Vec3::newTemp(towards->x, towards->y, towards->z));
7, &towards);
if (pos == NULL) return false;
wantedX = pos->x;
wantedY = pos->y;
@ -34,4 +35,4 @@ bool MoveTowardsRestrictionGoal::canContinueToUse() {
void MoveTowardsRestrictionGoal::start() {
mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier);
}
}

View file

@ -20,9 +20,10 @@ bool MoveTowardsTargetGoal::canUse() {
if (target.lock() == NULL) return false;
if (target.lock()->distanceToSqr(mob->shared_from_this()) > within * within)
return false;
Vec3 towards(target.lock()->x, target.lock()->y, target.lock()->z);
Vec3* pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, Vec3::newTemp(target.lock()->x, target.lock()->y, target.lock()->z));
7, &towards);
if (pos == NULL) return false;
wantedX = pos->x;
wantedY = pos->y;

View file

@ -792,18 +792,18 @@ void LivingEntity::breakItem(std::shared_ptr<ItemInstance> itemInstance) {
0.8f + level->random->nextFloat() * 0.4f);
for (int i = 0; i < 5; i++) {
Vec3* d = Vec3::newTemp((random->nextFloat() - 0.5) * 0.1,
Vec3 d = Vec3((random->nextFloat() - 0.5) * 0.1,
Math::random() * 0.1 + 0.1, 0);
d->xRot(-xRot * PI / 180);
d->yRot(-yRot * PI / 180);
d.xRot(-xRot * PI / 180);
d.yRot(-yRot * PI / 180);
Vec3* p = Vec3::newTemp((random->nextFloat() - 0.5) * 0.3,
Vec3 p = Vec3((random->nextFloat() - 0.5) * 0.3,
-random->nextFloat() * 0.6 - 0.3, 0.6);
p->xRot(-xRot * PI / 180);
p->yRot(-yRot * PI / 180);
*p = p->add(x, y + getHeadHeight(), z);
p.xRot(-xRot * PI / 180);
p.yRot(-yRot * PI / 180);
p = p.add(x, y + getHeadHeight(), z);
level->addParticle(PARTICLE_ICONCRACK(itemInstance->getItem()->id, 0),
p->x, p->y, p->z, d->x, d->y + 0.05, d->z);
p.x, p.y, p.z, d.x, d.y + 0.05, d.z);
}
}
@ -1641,10 +1641,10 @@ void LivingEntity::take(std::shared_ptr<Entity> e, int orgCount) {
}
bool LivingEntity::canSee(std::shared_ptr<Entity> target) {
HitResult* hres = level->clip(
Vec3::newTemp(x, y + getHeadHeight(), z),
Vec3::newTemp(target->x, target->y + target->getHeadHeight(),
target->z));
Vec3 a{x, y + getHeadHeight(), z};
Vec3 b{target->x, target->y + target->getHeadHeight(), target->z};
HitResult* hres = level->clip(&a, &b);
bool retVal = (hres == NULL);
delete hres;
return retVal;
@ -1690,11 +1690,11 @@ Vec3* LivingEntity::getPos(float a) {
}
HitResult* LivingEntity::pick(double range, float a) {
Vec3* from = getPos(a);
Vec3* b = getViewVector(a);
Vec3* to = Vec3::newTemp(b->x * range, b->y * range, b->z * range);
*to = to->add(from->x, from->y, from->z);
return level->clip(from, to);
Vec3 from = *getPos(a);
Vec3 b = *getViewVector(a);
Vec3 to{b.x * range, b.y * range, b.z * range};
to = to.add(from.x, from.y, from.z);
return level->clip(&from, &to);
}
bool LivingEntity::isEffectiveAi() { return !level->isClientSide; }

View file

@ -184,7 +184,8 @@ void Arrow::tick() {
if (t > 0) {
Tile::tiles[t]->updateShape(level, xTile, yTile, zTile);
AABB* aabb = Tile::tiles[t]->getAABB(level, xTile, yTile, zTile);
if (aabb != NULL && aabb->contains(Vec3::newTemp(x, y, z))) {
Vec3 pos{x, y, z};
if (aabb != NULL && aabb->contains(&pos)) {
inGround = true;
}
}
@ -217,15 +218,17 @@ void Arrow::tick() {
flightTime++;
}
Vec3* from = Vec3::newTemp(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to, false, true);
Vec3 from{x, y, z};
Vec3 to{x + xd, y + yd, z + zd};
HitResult* res = level->clip(&from, &to, false, true);
from = Vec3{x, y, z};
to = Vec3{x + xd, y + yd, z + zd};
from = Vec3::newTemp(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd);
if (res != NULL) {
to = Vec3::newTemp(res->pos.x, res->pos.y, res->pos.z);
to = Vec3{res->pos.x, res->pos.y, res->pos.z};
}
std::shared_ptr<Entity> hitEntity = nullptr;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
shared_from_this(), this->bb->expand(xd, yd, zd)->grow(1, 1, 1));
@ -237,9 +240,9 @@ void Arrow::tick() {
float rr = 0.3f;
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
HitResult* p = bb->clip(&from, &to);
if (p != NULL) {
double dd = from->distanceTo(p->pos);
double dd = from.distanceTo(p->pos);
if (dd < nearest || nearest == 0) {
hitEntity = e;
nearest = dd;

View file

@ -314,9 +314,9 @@ void EnderDragon::aiStep() {
// v->y, v->z, lSteps); unsigned int d = 0; for(unsigned int d = 1;
// d < 3; ++d)
{
Vec3* vN = Vec3::newTemp(v->x, v->y, v->z);
*vN = v->normalize();
vN->yRot(-PI / 4);
Vec3 vN = Vec3{v->x, v->y, v->z}.normalize();
vN.yRot(-PI / 4);
for (unsigned int i = 0; i < 8; ++i) {
if (getSynchedAction() == e_EnderdragonAction_Landing) {
// for(unsigned int j = 0; j < 6; ++j)
@ -335,9 +335,9 @@ void EnderDragon::aiStep() {
zP += (level->random->nextBoolean() ? 1 : -1) *
level->random->nextFloat() / 2;
level->addParticle(eParticleType_dragonbreath, xP,
yP, zP, (-vN->x * 0.08) + xd,
(-vN->y * 0.3) + yd,
(-vN->z * 0.08) + zd);
yP, zP, (-vN.x * 0.08) + xd,
(-vN.y * 0.3) + yd,
(-vN.z * 0.08) + zd);
}
} else {
double yVelocity = 0.6;
@ -357,12 +357,12 @@ void EnderDragon::aiStep() {
zP += (level->random->nextBoolean() ? 1 : -1) *
level->random->nextFloat() / 2;
level->addParticle(eParticleType_dragonbreath, xP,
yP, zP, -vN->x * xzVelocity * j,
-vN->y * yVelocity,
-vN->z * xzVelocity * j);
yP, zP, -vN.x * xzVelocity * j,
-vN.y * yVelocity,
-vN.z * xzVelocity * j);
}
}
vN->yRot(PI / (2 * 8));
vN.yRot(PI / (2 * 8));
}
}
} else if (getSynchedAction() ==
@ -478,15 +478,13 @@ void EnderDragon::aiStep() {
// No movement
} else if (getSynchedAction() == e_EnderdragonAction_Sitting_Scanning) {
if (attackTarget != NULL) {
Vec3* aim = Vec3::newTemp((attackTarget->x - x), 0,
(attackTarget->z - z));
*aim = aim->normalize();
Vec3 aim = Vec3((attackTarget->x - x), 0, (attackTarget->z - z))
.normalize();
Vec3* dir = Vec3::newTemp(sin(yRot * PI / 180), 0,
-cos(yRot * PI / 180));
Vec3 dir = Vec3(sin(yRot * PI / 180), 0, -cos(yRot * PI / 180))
.normalize();
*dir = dir->normalize();
float dot = (float)dir->dot(*aim);
float dot = (float)dir.dot(aim);
float angleDegs = acos(dot) * 180 / PI;
angleDegs = angleDegs + 0.5f;
@ -564,14 +562,12 @@ void EnderDragon::aiStep() {
if (yRotD > 50) yRotD = 50;
if (yRotD < -50) yRotD = -50;
Vec3* aim =
Vec3::newTemp((xTarget - x), (yTarget - y), (zTarget - z));
*aim = aim->normalize();
Vec3 aim =
Vec3((xTarget - x), (yTarget - y), (zTarget - z)).normalize();
Vec3* dir =
Vec3::newTemp(sin(yRot * PI / 180), yd, -cos(yRot * PI / 180));
*dir = dir->normalize();
float dot = (float)(dir->dot(*aim) + 0.5f) / 1.5f;
Vec3 dir = Vec3(sin(yRot * PI / 180), yd, -cos(yRot * PI / 180))
.normalize();
float dot = (float)(dir.dot(aim) + 0.5f) / 1.5f;
if (dot < 0) dot = 0;
yRotA *= 0.80f;
@ -595,9 +591,8 @@ void EnderDragon::aiStep() {
move(xd, yd, zd);
}
Vec3* actual = Vec3::newTemp(xd, yd, zd);
*actual = actual->normalize();
float slide = (float)(actual->dot(*dir) + 1) / 2.0f;
Vec3 actual = Vec3(xd, yd, zd).normalize();
float slide = (float)(actual.dot(dir) + 1) / 2.0f;
slide = 0.8f + 0.15f * slide;
xd *= slide;
@ -738,15 +733,13 @@ void EnderDragon::aiStep() {
maxDist * maxDist) {
if (this->canSee(attackTarget)) {
m_fireballCharge++;
Vec3* aim = Vec3::newTemp((attackTarget->x - x), 0,
(attackTarget->z - z));
*aim = aim->normalize();
Vec3 aim = Vec3((attackTarget->x - x), 0, (attackTarget->z - z))
.normalize();
Vec3* dir = Vec3::newTemp(sin(yRot * PI / 180), 0,
-cos(yRot * PI / 180));
*dir = dir->normalize();
Vec3 dir = Vec3(sin(yRot * PI / 180), 0, -cos(yRot * PI / 180))
.normalize();
float dot = (float)dir->dot(*aim);
float dot = (float)dir.dot(aim);
float angleDegs = acos(dot) * 180 / PI;
angleDegs = angleDegs + 0.5f;
@ -985,13 +978,13 @@ void EnderDragon::findNewTarget() {
int targetNodeIndex = 0;
if (playerNearestToEgg != NULL) {
Vec3* aim = Vec3::newTemp(playerNearestToEgg->x, 0,
playerNearestToEgg->z);
*aim = aim->normalize();
Vec3 aim = Vec3(playerNearestToEgg->x, 0, playerNearestToEgg->z)
.normalize();
// app.DebugPrintf("Final marker node near (%f,%d,%f)\n",
// -aim->x*40,105,-aim->z*40 );
targetNodeIndex =
findClosestNode(-aim->x * 40, 105.0, -aim->z * 40);
findClosestNode(-aim.x * 40, 105.0, -aim.z * 40);
} else {
targetNodeIndex = findClosestNode(40.0, eggHeight, 0.0);
}

View file

@ -117,13 +117,13 @@ bool EnderMan::isLookingAtMe(std::shared_ptr<Player> player) {
Vec3* look = player->getViewVector(1);
*look = look->normalize();
Vec3* dir = Vec3::newTemp(
x - player->x,
(bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()),
z - player->z);
double dist = dir->length();
*dir = dir->normalize();
double dot = look->dot(*dir);
Vec3 dir{x - player->x,
(bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()),
z - player->z};
double dist = dir.length();
dir = dir.normalize();
double dot = look->dot(dir);
if (dot > 1 - 0.025 / dist) {
return player->canSee(shared_from_this());
}
@ -251,13 +251,13 @@ bool EnderMan::teleport() {
}
bool EnderMan::teleportTowards(std::shared_ptr<Entity> e) {
Vec3* dir = Vec3::newTemp(
x - e->x, bb->y0 + bbHeight / 2 - e->y + e->getHeadHeight(), z - e->z);
*dir = dir->normalize();
Vec3 dir{x - e->x, bb->y0 + bbHeight / 2 - e->y + e->getHeadHeight(),
z - e->z};
dir = dir.normalize();
double d = 16;
double xx = x + (random->nextDouble() - 0.5) * 8 - dir->x * d;
double yy = y + (random->nextInt(16) - 8) - dir->y * d;
double zz = z + (random->nextDouble() - 0.5) * 8 - dir->z * d;
double xx = x + (random->nextDouble() - 0.5) * 8 - dir.x * d;
double yy = y + (random->nextInt(16) - 8) - dir.y * d;
double zz = z + (random->nextDouble() - 0.5) * 8 - dir.z * d;
return teleport(xx, yy, zz);
}

View file

@ -166,14 +166,14 @@ void Fireball::tick() {
}
MemSect(41);
Vec3* from = Vec3::newTemp(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to);
Vec3 from(x, y, z);
Vec3 to(x + xd, y + yd, z + zd);
HitResult* res = level->clip(&from, &to);
from = Vec3::newTemp(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd);
from = Vec3(x, y, z);
to = Vec3(x + xd, y + yd, z + zd);
if (res != NULL) {
*to = Vec3{res->pos.x, res->pos.y, res->pos.z};
to = Vec3{res->pos.x, res->pos.y, res->pos.z};
}
std::shared_ptr<Entity> hitEntity = nullptr;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
@ -188,9 +188,9 @@ void Fireball::tick() {
float rr = 0.3f;
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
HitResult* p = bb->clip(&from, &to);
if (p != NULL) {
double dd = from->distanceTo(p->pos);
double dd = from.distanceTo(p->pos);
if (dd < nearest || nearest == 0) {
hitEntity = e;
nearest = dd;

View file

@ -203,14 +203,14 @@ void FishingHook::tick() {
flightTime++;
}
Vec3* from = Vec3::newTemp(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to);
Vec3 from(x, y, z);
Vec3 to(x + xd, y + yd, z + zd);
HitResult* res = level->clip(&from, &to);
from = Vec3::newTemp(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd);
from = Vec3(x, y, z);
to = Vec3(x + xd, y + yd, z + zd);
if (res != NULL) {
to = Vec3::newTemp(res->pos.x, res->pos.y, res->pos.z);
to = Vec3(res->pos.x, res->pos.y, res->pos.z);
}
std::shared_ptr<Entity> hitEntity = nullptr;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
@ -223,9 +223,9 @@ void FishingHook::tick() {
float rr = 0.3f;
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
HitResult* p = bb->clip(&from, &to);
if (p != NULL) {
double dd = from->distanceTo(p->pos);
double dd = from.distanceTo(p->pos);
if (dd < nearest || nearest == 0) {
hitEntity = e;
nearest = dd;

View file

@ -724,13 +724,13 @@ void Minecart::push(std::shared_ptr<Entity> e) {
// other
// Fix for #38882 - TU5: Gameplay: Minecart with furnace is not
// able to move another minecart on the rail.
Vec3* dir = Vec3::newTemp(xo, 0, zo);
*dir = dir->normalize();
Vec3* facing =
Vec3::newTemp(cos(yRot * PI / 180), 0, sin(yRot * PI / 180));
*facing = facing->normalize();
Vec3 dir(xo, 0, zo);
dir = dir.normalize();
double dot = abs(dir->dot(*facing));
Vec3 facing(cos(yRot * PI / 180), 0, sin(yRot * PI / 180));
facing = facing.normalize();
double dot = abs(dir.dot(facing));
if (dot < 0.8f) {
return;

View file

@ -135,14 +135,14 @@ void Throwable::tick() {
flightTime++;
}
Vec3* from = Vec3::newTemp(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to);
Vec3 from(x, y, z);
Vec3 to(x + xd, y + yd, z + zd);
HitResult* res = level->clip(&from, &to);
from = Vec3::newTemp(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd);
from = Vec3(x, y, z);
to = Vec3(x + xd, y + yd, z + zd);
if (res != NULL) {
to = Vec3::newTemp(res->pos.x, res->pos.y, res->pos.z);
to = Vec3(res->pos.x, res->pos.y, res->pos.z);
}
if (!level->isClientSide) {
@ -157,9 +157,9 @@ void Throwable::tick() {
float rr = 0.3f;
AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, to);
HitResult* p = bb->clip(&from, &to);
if (p != NULL) {
double dd = from->distanceTo(p->pos);
double dd = from.distanceTo(p->pos);
delete p;
if (dd < nearest || nearest == 0) {
hitEntity = e;

View file

@ -62,7 +62,7 @@ std::shared_ptr<ItemInstance> BoatItem::use(
player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset;
double z = player->zo + (player->z - player->zo) * a;
Vec3* from = Vec3::newTemp(x, y, z);
Vec3 from(x, y, z);
float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI);
float ySin = Mth::sin(-yRot * Mth::RAD_TO_GRAD - PI);
@ -74,9 +74,9 @@ std::shared_ptr<ItemInstance> BoatItem::use(
float za = yCos * xCos;
double range = 5;
Vec3* to = Vec3::newTemp(xa * range, ya * range, za * range);
*to = to->add(from->x, from->y, from->z);
HitResult* hr = level->clip(from, to, true);
Vec3 to(xa * range, ya * range, za * range);
to = to.add(from.x, from.y, from.z);
HitResult* hr = level->clip(&from, &to, true);
if (hr == NULL) return itemInstance;
// check entity collision
@ -94,7 +94,7 @@ std::shared_ptr<ItemInstance> BoatItem::use(
float rr = e->getPickRadius();
AABB* bb = e->bb->grow(rr, rr, rr);
if (bb->contains(from)) {
if (bb->contains(&from)) {
hitEntity = true;
}
}

View file

@ -1603,7 +1603,7 @@ HitResult* Item::getPlayerPOVHitResult(Level* level,
player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset;
double z = player->zo + (player->z - player->zo) * a;
Vec3* from = Vec3::newTemp(x, y, z);
Vec3 from(x, y, z);
float yCos = (float)cos(-yRot * Mth::RAD_TO_GRAD - PI);
float ySin = (float)sin(-yRot * Mth::RAD_TO_GRAD - PI);
@ -1615,9 +1615,9 @@ HitResult* Item::getPlayerPOVHitResult(Level* level,
float za = yCos * xCos;
double range = 5;
Vec3* to = Vec3::newTemp(xa * range, ya * range, za * range);
*to = to->add(from->x, from->y, from->z);
return level->clip(from, to, alsoPickLiquid, !alsoPickLiquid);
Vec3 to(xa * range, ya * range, za * range);
to = to.add(from.x, from.y, from.z);
return level->clip(&from, &to, alsoPickLiquid, !alsoPickLiquid);
}
int Item::getEnchantmentValue() { return 0; }

View file

@ -60,4 +60,4 @@ Pos* TheEndDimension::getSpawnPos() { return new Pos(100, 50, 0); }
bool TheEndDimension::isFoggyAt(int x, int z) { return true; }
int TheEndDimension::getSpawnYPosition() { return 50; }
int TheEndDimension::getSpawnYPosition() { return 50; }

View file

@ -157,4 +157,4 @@ Vec3* VillageSiege::findRandomSpawnPos(int x, int y, int z) {
return Vec3::newTemp(xx, yy, zz);
}
return NULL;
}
}

View file

@ -108,7 +108,7 @@ void Explosion::explode() {
level->getEntities(source, AABB::newTemp(x0, y0, z0, x1, y1, z1));
std::vector<std::shared_ptr<Entity> > entities(levelEntities->begin(),
levelEntities->end());
Vec3* center = Vec3::newTemp(x, y, z);
Vec3 center(x, y, z);
AUTO_VAR(itEnd, entities.end());
for (AUTO_VAR(it, entities.begin()); it != itEnd; it++) {
@ -146,7 +146,7 @@ void Explosion::explode() {
za /= da;
}
double sp = level->getSeenPercent(center, e->bb);
double sp = level->getSeenPercent(&center, e->bb);
double pow = (1 - dist) * sp;
if (canDamage)
e->hurt(DamageSource::explosion(this),
@ -298,4 +298,4 @@ std::shared_ptr<LivingEntity> Explosion::getSourceMob() {
if (source->instanceof(eTYPE_LIVINGENTITY))
return std::dynamic_pointer_cast<LivingEntity>(source);
return nullptr;
}
}

View file

@ -1478,21 +1478,21 @@ HitResult* Level::clip(Vec3* a, Vec3* b, bool liquid, bool solidOnly) {
a->z = zClip;
}
Vec3* tPos = Vec3::newTemp(a->x, a->y, a->z);
xTile0 = (int)(tPos->x = floor(a->x));
Vec3 tPos(a->x, a->y, a->z);
xTile0 = (int)(tPos.x = floor(a->x));
if (face == 5) {
xTile0--;
tPos->x++;
tPos.x++;
}
yTile0 = (int)(tPos->y = floor(a->y));
yTile0 = (int)(tPos.y = floor(a->y));
if (face == 1) {
yTile0--;
tPos->y++;
tPos.y++;
}
zTile0 = (int)(tPos->z = floor(a->z));
zTile0 = (int)(tPos.z = floor(a->z));
if (face == 3) {
zTile0--;
tPos->z++;
tPos.z++;
}
int t = getTile(xTile0, yTile0, zTile0);
@ -2473,7 +2473,7 @@ bool Level::checkAndHandleWater(AABB* box, Material* material,
}
bool ok = false;
Vec3* current = Vec3::newTemp(0, 0, 0);
Vec3 current(0, 0, 0);
for (int x = x0; x < x1; x++) {
for (int y = y0; y < y1; y++) {
for (int z = z0; z < z1; z++) {
@ -2483,18 +2483,18 @@ bool Level::checkAndHandleWater(AABB* box, Material* material,
y + 1 - LiquidTile::getHeight(getData(x, y, z));
if (y1 >= yt0) {
ok = true;
tile->handleEntityInside(this, x, y, z, e, current);
tile->handleEntityInside(this, x, y, z, e, &current);
}
}
}
}
}
if (current->length() > 0 && e->isPushedByWater()) {
*current = current->normalize();
if (current.length() > 0 && e->isPushedByWater()) {
current = current.normalize();
double pow = 0.014;
e->xd += current->x * pow;
e->yd += current->y * pow;
e->zd += current->z * pow;
e->xd += current.x * pow;
e->yd += current.y * pow;
e->zd += current.z * pow;
}
return ok;
}
@ -2580,7 +2580,8 @@ float Level::getSeenPercent(Vec3* center, AABB* bb) {
double x = bb->x0 + (bb->x1 - bb->x0) * xx;
double y = bb->y0 + (bb->y1 - bb->y0) * yy;
double z = bb->z0 + (bb->z1 - bb->z0) * zz;
HitResult* res = clip(Vec3::newTemp(x, y, z), center);
Vec3 a(x, y, z);
HitResult* res = clip(&a, center);
if (res == NULL) hits++;
delete res;
count++;

View file

@ -109,32 +109,34 @@ int RandomLevelSource::getMinDistanceToEdge(int xxx, int zzz, int worldSize,
// // only check if either x or z values are within the falloff
// if(xxx > (min - falloffStart)
Vec3* topLeft = Vec3::newTemp(min, 0, min);
Vec3* topRight = Vec3::newTemp(max, 0, min);
Vec3* bottomLeft = Vec3::newTemp(min, 0, max);
Vec3* bottomRight = Vec3::newTemp(max, 0, max);
Vec3 topLeft(min, 0, min);
Vec3 topRight(max, 0, min);
Vec3 bottomLeft(min, 0, max);
Vec3 bottomRight(max, 0, max);
float closest = falloffStart;
float dist;
// make sure we're in range of the edges before we do a full distance check
if ((xxx > (min - falloffStart) && xxx < (min + falloffStart)) ||
(xxx > (max - falloffStart) && xxx < (max + falloffStart))) {
Vec3* point = Vec3::newTemp(xxx, 0, zzz);
Vec3 point(xxx, 0, zzz);
if (xxx > 0)
dist = point->distanceFromLine(*topRight, *bottomRight);
dist = point.distanceFromLine(topRight, bottomRight);
else
dist = point->distanceFromLine(*topLeft, *bottomLeft);
dist = point.distanceFromLine(topLeft, bottomLeft);
closest = dist;
}
// make sure we're in range of the edges before we do a full distance check
if ((zzz > (min - falloffStart) && zzz < (min + falloffStart)) ||
(zzz > (max - falloffStart) && zzz < (max + falloffStart))) {
Vec3* point = Vec3::newTemp(xxx, 0, zzz);
Vec3 point(xxx, 0, zzz);
if (zzz > 0)
dist = point->distanceFromLine(*bottomLeft, *bottomRight);
dist = point.distanceFromLine(bottomLeft, bottomRight);
else
dist = point->distanceFromLine(*topLeft, *topRight);
dist = point.distanceFromLine(topLeft, topRight);
if (dist < closest) closest = dist;
}

View file

@ -527,20 +527,20 @@ void Player::spawnEatParticles(std::shared_ptr<ItemInstance> useItem,
}
if (useItem->getUseAnimation() == UseAnim_eat) {
for (int i = 0; i < count; i++) {
Vec3* d = Vec3::newTemp((random->nextFloat() - 0.5) * 0.1,
Math::random() * 0.1 + 0.1, 0);
Vec3 d{(random->nextFloat() - 0.5) * 0.1,
Math::random() * 0.1 + 0.1, 0};
d->xRot(-xRot * PI / 180);
d->yRot(-yRot * PI / 180);
d.xRot(-xRot * PI / 180);
d.yRot(-yRot * PI / 180);
Vec3* p = Vec3::newTemp((random->nextFloat() - 0.5) * 0.3,
-random->nextFloat() * 0.6 - 0.3, 0.6);
p->xRot(-xRot * PI / 180);
p->yRot(-yRot * PI / 180);
*p = p->add(x, y + getHeadHeight(), z);
Vec3 p{(random->nextFloat() - 0.5) * 0.3,
-random->nextFloat() * 0.6 - 0.3, 0.6};
p.xRot(-xRot * PI / 180);
p.yRot(-yRot * PI / 180);
p = p.add(x, y + getHeadHeight(), z);
level->addParticle(PARTICLE_ICONCRACK(useItem->getItem()->id, 0),
p->x, p->y, p->z, d->x, d->y + 0.05, d->z);
p.x, p.y, p.z, d.x, d.y + 0.05, d.z);
}
// 4J Stu - Was L"mob.eat" which doesnt exist

View file

@ -1,7 +1,8 @@
#include "../Platform/stdafx.h"
#include "Vec3.h"
#include <format>
#include <optional>
#include "AABB.h"
unsigned int Vec3::tlsIdx = 0;

View file

@ -1,6 +1,8 @@
#pragma once
#include <optional>
#include <string>
class AABB;
class Vec3 {