diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2020-07-25 18:49:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-25 18:49:18 +0200 |
commit | 0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837 (patch) | |
tree | 3c760d4d981aad30fa151343c224d3ea366c99d9 /src/World.cpp | |
parent | Merge pull request #36 from LaG1924/fix-windows-vs2019 (diff) | |
parent | Completely removed hardcoded list of blockstates (diff) | |
download | AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.gz AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.bz2 AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.lz AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.xz AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.tar.zst AltCraft-0a2ba2cdb8e01bbd7e9e8ef1d0582ef6a892f837.zip |
Diffstat (limited to '')
-rw-r--r-- | src/World.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/World.cpp b/src/World.cpp index da0a33b..00a1a19 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2,6 +2,7 @@ #include <bitset> #include <glm/glm.hpp> +#include <optick.h> #include "Event.hpp" #include "DebugInfo.hpp" @@ -97,7 +98,7 @@ bool World::isPlayerCollides(double X, double Y, double Z) const { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { BlockId block = section.GetBlockId(Vector(x, y, z)); - if (block.id == 0 || block.id == 31 || block.id == 37 || block.id == 38 || block.id == 175) + if (!GetBlockInfo(block).collides) continue; AABB blockColl{ (x + it.x * 16.0), (y + it.y * 16.0), @@ -131,6 +132,7 @@ const Section &World::GetSection(Vector sectionPos) const { // TODO: skip liquid blocks RaycastResult World::Raycast(glm::vec3 position, glm::vec3 direction) const { + OPTICK_EVENT(); const float maxLen = 5.0; const float step = 0.01; glm::vec3 pos = glm::vec3(0.0); @@ -150,6 +152,7 @@ RaycastResult World::Raycast(glm::vec3 position, glm::vec3 direction) const { } void World::UpdatePhysics(float delta) { + OPTICK_EVENT(); struct CollisionResult { bool isCollide; //Vector block; @@ -158,6 +161,7 @@ void World::UpdatePhysics(float delta) { }; auto testCollision = [this](double width, double height, VectorF pos)->CollisionResult { + OPTICK_EVENT("testCollision"); int blockXBegin = pos.x - width - 1.0; int blockXEnd = pos.x + width + 0.5; int blockYBegin = pos.y - 0.5; @@ -177,9 +181,10 @@ void World::UpdatePhysics(float delta) { for (int y = blockYBegin; y <= blockYEnd; y++) { for (int z = blockZBegin; z <= blockZEnd; z++) { for (int x = blockXBegin; x <= blockXEnd; x++) { + OPTICK_EVENT("testCollision"); BlockId block = this->GetBlockId(Vector(x, y, z)); - if (block.id == 0 || block.id == 31 || block.id == 37 || block.id == 38 || block.id == 175 || block.id == 78) - continue; + if (block.id == 0 || !GetBlockInfo(block).collides) + continue; AABB blockColl{ x,y,z,1.0,1.0,1.0 }; if (TestCollision(entityCollBox, blockColl)) { return { true }; @@ -191,6 +196,7 @@ void World::UpdatePhysics(float delta) { }; for (auto& it : entities) { + OPTICK_EVENT("Foreach entities"); if (it.isFlying) { VectorF newPos = it.pos + VectorF(it.vel.x, it.vel.y, it.vel.z) * delta; auto coll = testCollision(it.width, it.height, newPos); |