// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma // de Barcelona (UAB). // // This work is licensed under the terms of the MIT license. // For a copy, see . #pragma once #include #include #include #include #include "carla/Memory.h" #include "carla/NonCopyable.h" #include "carla/client/detail/Episode.h" #include "carla/client/Light.h" #include "carla/client/LightState.h" #include "carla/rpc/LightState.h" namespace carla { namespace client { class LightManager : public EnableSharedFromThis { using LightGroup = rpc::LightState::LightGroup; public: LightManager() {} ~LightManager(); LightManager(const LightManager& other) : EnableSharedFromThis() { _lights_state = other._lights_state; _lights_changes = other._lights_changes; _lights = other._lights; _episode = other._episode; _on_tick_register_id = other._on_tick_register_id; _on_light_update_register_id = other._on_light_update_register_id; _dirty = other._dirty; } void SetEpisode(detail::WeakEpisodeProxy episode); std::vector GetAllLights(LightGroup type = LightGroup::None) const; // TODO: std::vector GetAllLightsInRoad(RoadId id, LightGroup type = LightGroup::None); // TODO: std::vector GetAllLightsInDistance(Vec3 origin, float distance, LightGroup type = Light::LightType::None); void TurnOn(std::vector& lights); void TurnOff(std::vector& lights); void SetActive(std::vector& lights, std::vector& active); std::vector IsActive(std::vector& lights) const; std::vector GetTurnedOnLights(LightGroup type = LightGroup::None) const; std::vector GetTurnedOffLights(LightGroup type = LightGroup::None) const; void SetColor(std::vector& lights, Color color); void SetColor(std::vector& lights, std::vector& colors); std::vector GetColor(std::vector& lights) const; void SetIntensity(std::vector& lights, float intensity); void SetIntensity(std::vector& lights, std::vector& intensities); std::vector GetIntensity(std::vector& lights) const; void SetLightGroup(std::vector& lights, LightGroup group); void SetLightGroup(std::vector& lights, std::vector& groups); std::vector GetLightGroup(std::vector& lights) const; void SetLightState(std::vector& lights, LightState state); void SetLightState(std::vector& lights, std::vector& states); std::vector GetLightState(std::vector& lights) const; Color GetColor(LightId id) const; float GetIntensity(LightId id) const; LightState GetLightState(LightId id) const; LightGroup GetLightGroup(LightId id) const; bool IsActive(LightId id) const; void SetActive(LightId id, bool active); void SetColor(LightId id, Color color); void SetIntensity(LightId id, float intensity); void SetLightState(LightId id, const LightState& new_state); void SetLightStateNoLock(LightId id, const LightState& new_state); void SetLightGroup(LightId id, LightGroup group); void SetDayNightCycle(const bool active); private: const LightState& RetrieveLightState(LightId id) const; void QueryLightsStateToServer(); void UpdateServerLightsState(bool discard_client = false); void ApplyChanges(); std::unordered_map _lights_state; std::unordered_map _lights_changes; std::unordered_map _lights; detail::WeakEpisodeProxy _episode; std::mutex _mutex; LightState _state; size_t _on_tick_register_id = 0; size_t _on_light_update_register_id = 0; bool _dirty = false; }; } // namespace client } // namespace carla