This commit is contained in:
aozhiwei 2021-07-22 06:34:38 +00:00
parent 92fafb9bc7
commit 5d8b338aa3
4 changed files with 70 additions and 9 deletions

View File

@ -1,6 +1,10 @@
#include "precompile.h"
#include "mapblock.h"
#include "collider.h"
#include "cs_proto.pb.h"
#include "typeconvert.h"
#include "metamgr.h"
MapBlock::MapBlock()
{
@ -24,22 +28,67 @@ void MapBlock::RecalcSelfCollider()
void MapBlock::FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(ET_Obstacle);
cs::MFObstaclePart* p = part_data->mutable_union_obj_2();
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
p->set_scale(1.0f);
}
void MapBlock::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(ET_Obstacle);
if (IsClientCached(hum)) {
int object_flags = 0;
a8::SetBitFlag(object_flags, kOfReadCache);
full_data->set_obj_uniid(GetUniId());
full_data->set_object_flags(object_flags);
return;
}
cs::MFObstacleFull* p = full_data->mutable_union_obj_2();
if (CanClientCache(hum)) {
int object_flags = 0;
a8::SetBitFlag(object_flags, kOfWriteCache);
#if 0
full_data->set_obj_uniid(GetUniId());
#endif
full_data->set_object_flags(object_flags);
AddClientCache(hum);
}
p->set_obj_uniid(GetUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos());
p->set_scale(1.0f);
p->set_obstacle_id(meta->i->thing_id());
p->set_health(0);
p->set_dead(false);
p->set_dead_at_thisframe(false);
p->set_is_door(false);
{
cs::MFCollider* collider = full_data->mutable_union_obj_2()->mutable_collider();
collider->set_shape(shape);
if (shape == 1) {
collider->set_width(width);
collider->set_height(height);
} else {
collider->set_width(rad);
collider->set_height(rad);
}
}
}
void MapBlock::GetAabbBox(AabbCollider& aabb_box)
{
aabb_box.active = false;
aabb_box.owner = this;
}
void MapBlock::GetCircleBox(CircleCollider& circle_box)
{
circle_box.active = false;
circle_box.owner = this;
}
bool MapBlock::IsDead(Room* room)

View File

@ -45,8 +45,6 @@ protected:
MapBlock();
protected:
CircleCollider* self_collider_ = nullptr;
AabbCollider* self_collider2_ = nullptr;
friend class EntityFactory;
};

View File

@ -280,11 +280,25 @@ void MapInstance::CreateBlock()
for (auto& obj : *blocks) {
switch (obj.shape()) {
case 1:
{
}
break;
case 2:
{
if (!obj.bullet_penetrate()) {
MapBlock* block = EntityFactory::Instance()->MakeBlock(++current_map_block_uniid_);
block->meta = MetaMgr::Instance()->GetMapThing
(obj.bullet_penetrate() ? 40002 : 40001);
block->shape = obj.shape();
block->width = obj.width();
block->height = obj.height();
block->rad = obj.rad();
block->permanent_map_service = map_service_;
block->SetPos(a8::Vec2(obj.x(), obj.y()));
block->Initialize();
uniid_hash_[block->GetUniId()] = block;
grid_service_->AddPermanentEntity(block);
if (!block->meta) {
abort();
}
}
}
break;
default:

View File

@ -154,7 +154,7 @@ message MFPropertyChg
//
message MFCollider
{
optional int32 shape = 1; // 1 2width=eight
optional int32 shape = 1; // 1 2width=height
optional int32 width = 2; //
optional int32 height = 3; //
}