|
@@ -22,6 +22,28 @@ Chunk::~Chunk()
|
|
|
World::INSTANCE->zClient()->chunkAPIRequest(location, &msg, 1);
|
|
|
}
|
|
|
|
|
|
+void Chunk::appendAnimation(
|
|
|
+ Block* zB, int boneId, double time, Vec3<float> pos, Vec3<float> rot)
|
|
|
+{
|
|
|
+ if (!zB->zSkeleton() || !zB->zSkeleton()->zBone(boneId)) return;
|
|
|
+ acs.lock();
|
|
|
+ for (BlockAnimation* animation : animations)
|
|
|
+ {
|
|
|
+ if (animation->zBlock() == zB)
|
|
|
+ {
|
|
|
+ animation->appendAnimation(boneId, time, pos, rot);
|
|
|
+ acs.unlock();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SkeletonAnimation* sa = new SkeletonAnimation();
|
|
|
+ Bone* bone = zB->zSkeleton()->zBone(boneId);
|
|
|
+ sa->addAnimation(boneId, bone->getPosition(), bone->getRotation());
|
|
|
+ sa->addKeyFrame(boneId, time, pos, rot);
|
|
|
+ animations.add(new BlockAnimation(dynamic_cast<Block*>(zB->getThis()), sa));
|
|
|
+ acs.unlock();
|
|
|
+}
|
|
|
+
|
|
|
void Chunk::api(char* message)
|
|
|
{
|
|
|
switch (message[0])
|
|
@@ -47,6 +69,28 @@ void Chunk::api(char* message)
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
+ case 1: // animate block
|
|
|
+ {
|
|
|
+ int index = *(int*)(message + 1);
|
|
|
+ int boneId = *(int*)(message + 5);
|
|
|
+ double time = *(double*)(message + 9);
|
|
|
+ Framework::Vec3<float> pos;
|
|
|
+ pos.x = *(float*)(message + 17);
|
|
|
+ pos.y = *(float*)(message + 21);
|
|
|
+ pos.z = *(float*)(message + 25);
|
|
|
+ Framework::Vec3<float> rot;
|
|
|
+ rot.x = *(float*)(message + 29);
|
|
|
+ rot.y = *(float*)(message + 33);
|
|
|
+ rot.z = *(float*)(message + 37);
|
|
|
+ Framework::Vec3<int> location((index / WORLD_HEIGHT) / CHUNK_SIZE,
|
|
|
+ (index / WORLD_HEIGHT) % CHUNK_SIZE,
|
|
|
+ index % WORLD_HEIGHT);
|
|
|
+ location.x += this->location.x - CHUNK_SIZE / 2;
|
|
|
+ location.y += this->location.y - CHUNK_SIZE / 2;
|
|
|
+ Block* zB = zBlockAt(location);
|
|
|
+ if (zB) appendAnimation(zB, boneId, time, pos, rot);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -161,7 +205,8 @@ void Chunk::load(Framework::StreamReader* zReader)
|
|
|
pos.y + location.y - CHUNK_SIZE / 2,
|
|
|
pos.z});
|
|
|
blocks.add(b);
|
|
|
- blockCache.set((char*)&index, 4, dynamic_cast<Block*>(b->getThis()));
|
|
|
+ blockCache.set(
|
|
|
+ (char*)&index, 4, dynamic_cast<Block*>(b->getThis()));
|
|
|
cs.unlock();
|
|
|
vcs.lock();
|
|
|
if (b->isVisible())
|
|
@@ -190,8 +235,7 @@ void Chunk::load(Framework::StreamReader* zReader)
|
|
|
zReader->lese(lightData, 6);
|
|
|
if (x == -1)
|
|
|
{
|
|
|
- int cacheIndex
|
|
|
- = y * WORLD_HEIGHT + z;
|
|
|
+ int cacheIndex = y * WORLD_HEIGHT + z;
|
|
|
Block* zB = blockCache.z((char*)&cacheIndex, 4);
|
|
|
if (zB)
|
|
|
{
|
|
@@ -209,7 +253,8 @@ void Chunk::load(Framework::StreamReader* zReader)
|
|
|
}
|
|
|
else if (x == CHUNK_SIZE)
|
|
|
{
|
|
|
- int cacheIndex = ((CHUNK_SIZE - 1) * CHUNK_SIZE + y) * WORLD_HEIGHT + z;
|
|
|
+ int cacheIndex
|
|
|
+ = ((CHUNK_SIZE - 1) * CHUNK_SIZE + y) * WORLD_HEIGHT + z;
|
|
|
Block* zB = blockCache.z((char*)&cacheIndex, 4);
|
|
|
if (zB)
|
|
|
{
|
|
@@ -340,4 +385,29 @@ void Chunk::forAll(std::function<void(Model3D*)> f)
|
|
|
vcs.unlock();
|
|
|
}
|
|
|
|
|
|
-void Chunk::tick(std::function<void(Model3D*)> f) {}
|
|
|
+bool Chunk::tick(std::function<void(Model3D*)> f, double time)
|
|
|
+{
|
|
|
+ bool res = 0;
|
|
|
+ acs.lock();
|
|
|
+ auto iterator = animations.begin();
|
|
|
+ while (iterator)
|
|
|
+ {
|
|
|
+ if (iterator->tick(time))
|
|
|
+ {
|
|
|
+ res |= iterator->zBlock()->tick(time);
|
|
|
+ if (iterator->isFinished())
|
|
|
+ {
|
|
|
+ iterator.remove();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ iterator.remove();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ++iterator;
|
|
|
+ }
|
|
|
+ acs.unlock();
|
|
|
+ return res;
|
|
|
+}
|