Map locations, marker_tuning and destructibles not destroying each other
This commit is contained in:
parent
b7411d4611
commit
08029fdd2e
@ -41,6 +41,15 @@ const assets::MapGraph* assets::Map::GetGraph(const std::string& name) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::span<const assets::MapLocation> assets::Map::GetLocations(const std::string& name) const
|
||||
{
|
||||
auto it = locations_.find(name);
|
||||
if (it == locations_.end())
|
||||
return std::span<const MapLocation>();
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// MapLoader
|
||||
|
||||
assets::MapLoader::MapLoader(const std::string& filename)
|
||||
@ -281,6 +290,13 @@ void assets::MapLoader::LoadStructs()
|
||||
|
||||
graph_edges.emplace_back(from_idx, to_idx);
|
||||
}
|
||||
else if (command == "loc")
|
||||
{
|
||||
std::string loc_name;
|
||||
iss >> loc_name;
|
||||
Transform& trans = map_->locations_[loc_name].emplace_back().transform;
|
||||
ParseTransform(iss, trans);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -51,6 +51,11 @@ struct MapGraph
|
||||
std::vector<size_t> nbs;
|
||||
};
|
||||
|
||||
struct MapLocation
|
||||
{
|
||||
Transform transform;
|
||||
};
|
||||
|
||||
class Map
|
||||
{
|
||||
public:
|
||||
@ -61,12 +66,14 @@ public:
|
||||
const std::vector<Chunk>& GetChunks() const { return chunks_; }
|
||||
const std::vector<MapStaticObject>& GetStaticObjects() const { return objs_; }
|
||||
const MapGraph* GetGraph(const std::string& name) const;
|
||||
std::span<const MapLocation> GetLocations(const std::string& name) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const Model> basemodel_;
|
||||
std::vector<Chunk> chunks_;
|
||||
std::vector<MapStaticObject> objs_;
|
||||
std::map<std::string, MapGraph> graphs_;
|
||||
std::map<std::string, std::vector<MapLocation>> locations_;
|
||||
|
||||
friend class MapLoader;
|
||||
};
|
||||
|
||||
@ -17,9 +17,10 @@ using ObjectFlags = int;
|
||||
|
||||
enum ObjectFlag : ObjectFlags
|
||||
{
|
||||
OF_DESTRUCTIBLE = 0x01,
|
||||
OF_NOTIFY_CONTACT = 0x02,
|
||||
OF_USABLE = 0x04,
|
||||
OF_DESTRUCTIBLE = 1,
|
||||
OF_NOTIFY_CONTACT = 2,
|
||||
OF_USABLE = 4,
|
||||
OF_DESTRUCTING = 8,
|
||||
};
|
||||
|
||||
struct ContactInfo
|
||||
|
||||
@ -8,6 +8,15 @@ game::DrivableVehicle::DrivableVehicle(World& world, const VehicleTuning& tuning
|
||||
OnPhysicsChanged();
|
||||
}
|
||||
|
||||
void game::DrivableVehicle::Update()
|
||||
{
|
||||
float daytime = world_.GetDayTime();
|
||||
SetLightsOn(seats_[0].occupant && (daytime < 6.0f || daytime > 18.0f));
|
||||
|
||||
Super::Update();
|
||||
|
||||
}
|
||||
|
||||
void game::DrivableVehicle::SetTuning(const VehicleTuning& tuning)
|
||||
{
|
||||
Super::SetTuning(tuning);
|
||||
@ -63,14 +72,8 @@ bool game::DrivableVehicle::SetPassenger(uint32_t seat_idx, ControllableCharacte
|
||||
|
||||
if (seat_idx == 0)
|
||||
{
|
||||
if (character)
|
||||
if (!character)
|
||||
{
|
||||
SetLightsOn(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetLightsOn(false);
|
||||
|
||||
// clear inputs
|
||||
SetInputs(0);
|
||||
SetSteering(false, 0.0f);
|
||||
|
||||
@ -20,6 +20,8 @@ public:
|
||||
|
||||
DrivableVehicle(World& world, const VehicleTuning& tuning);
|
||||
|
||||
virtual void Update() override;
|
||||
|
||||
virtual void SetTuning(const VehicleTuning& tuning) override;
|
||||
|
||||
virtual void OnPhysicsChanged() override;
|
||||
|
||||
@ -51,7 +51,7 @@ void game::Marker::SetUseTarget(const std::string& name, MarkerQueryCallback que
|
||||
{
|
||||
query_obj_ = std::make_unique<btCollisionObject>();
|
||||
|
||||
static btSphereShape query_sphere(1.0f);
|
||||
static btSphereShape query_sphere(0.01f);
|
||||
query_obj_->setCollisionShape(&query_sphere);
|
||||
query_obj_->setWorldTransform(root_.local.ToBtTransform());
|
||||
query_obj_->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
|
||||
|
||||
@ -82,7 +82,10 @@ game::OpenWorld::OpenWorld(Game& game) : EnterableWorld("openworld"), game_(game
|
||||
|
||||
daytime_offset_ = static_cast<float>(rand() % 24);
|
||||
|
||||
CreateTuningGarage(glm::vec3(0.0f, 0.0f, 0.0f), 0.0f);
|
||||
for (auto locs = GetMap().GetLocations("tuning"); const auto& loc : locs)
|
||||
{
|
||||
CreateTuningGarage(loc.transform.position, glm::eulerAngles(loc.transform.rotation).x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -633,7 +633,7 @@ game::VehiclePhysics::VehiclePhysics(collision::DynamicsWorld& world, Transform&
|
||||
body_ = std::make_unique<btRigidBody>(rb_info);
|
||||
// body_->setActivationState(DISABLE_DEACTIVATION);
|
||||
|
||||
collision::SetObjectInfo(body_.get(), collision::OT_ENTITY, collision::OF_NOTIFY_CONTACT, &obj_cb);
|
||||
collision::SetObjectInfo(body_.get(), collision::OT_ENTITY, collision::OF_NOTIFY_CONTACT | collision::OF_DESTRUCTING, &obj_cb);
|
||||
|
||||
// setup vehicle
|
||||
btRaycastVehicle::btVehicleTuning bt_tuning;
|
||||
|
||||
@ -198,6 +198,14 @@ void game::World::HandleContacts()
|
||||
|
||||
if (type == collision::OT_MAP_OBJECT && (flags & collision::OF_DESTRUCTIBLE))
|
||||
{
|
||||
collision::ObjectType other_type;
|
||||
collision::ObjectFlags other_flags;
|
||||
collision::ObjectCallback* other_cb;
|
||||
collision::GetObjectInfo(other_body, other_type, other_flags, other_cb);
|
||||
|
||||
if ((other_flags & collision::OF_DESTRUCTING) == 0)
|
||||
return;
|
||||
|
||||
auto col = dynamic_cast<MapObjectCollision*>(cb);
|
||||
if (!col)
|
||||
return;
|
||||
|
||||
@ -51,7 +51,7 @@ bool game::view::MarkerView::Init(net::InMessage& msg)
|
||||
|
||||
if (marker_type_ == MARKER_FOOT || marker_type_ == MARKER_VEHICLE)
|
||||
{
|
||||
model_ = assets::CacheManager::GetModel("data/marker.mdl");
|
||||
model_ = assets::CacheManager::GetModel("data/marker_tuning.mdl");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user