Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Added operator implementations for mbgl::Update enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Aug 13, 2015
1 parent 5abb18a commit ac9d588
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
19 changes: 15 additions & 4 deletions include/mbgl/map/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

namespace mbgl {

using UpdateType = uint32_t;

enum class Update : UpdateType {
enum class Update : uint32_t {
Nothing = 0,
Dimensions = 1 << 1,
DefaultTransition = 1 << 2,
Expand All @@ -17,6 +15,19 @@ enum class Update : UpdateType {
Repaint = 1 << 6,
};

inline Update operator| (const Update& lhs, const Update& rhs) {
return Update(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
}

inline Update& operator|=(Update& lhs, const Update& rhs) {
lhs = lhs | rhs;
return lhs;
}

#endif
inline bool operator& (const Update& lhs, const Update& rhs) {
return static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs);
}

} // namespace mbgl

#endif // MBGL_MAP_UPDATE
13 changes: 6 additions & 7 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,18 @@ void Map::renderSync() {
}

void Map::nudgeTransitions() {
UpdateType update_ = transform->updateTransitions(Clock::now());
Update flags = transform->updateTransitions(Clock::now());
if (data->getNeedsRepaint()) {
update_ |= static_cast<UpdateType>(Update::Repaint);
flags |= Update::Repaint;
}
update(Update(update_));
update(flags);
}

void Map::update(Update update_) {
if (update_ == Update::Dimensions) {
void Map::update(Update flags) {
if (flags & Update::Dimensions) {
transform->resize(view.getSize());
}

context->invoke(&MapContext::triggerUpdate, transform->getState(), update_);
context->invoke(&MapContext::triggerUpdate, transform->getState(), flags);
}

#pragma mark - Style
Expand Down
26 changes: 11 additions & 15 deletions src/mbgl/map/map_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace mbgl {
MapContext::MapContext(View& view_, FileSource& fileSource, MapData& data_)
: view(view_),
data(data_),
updated(static_cast<UpdateType>(Update::Nothing)),
asyncUpdate(std::make_unique<uv::async>(util::RunLoop::getLoop(), [this] { update(); })),
texturePool(std::make_unique<TexturePool>()),
viewInvalidated(false) {
Expand Down Expand Up @@ -84,9 +83,9 @@ void MapContext::pause() {
view.activate();
}

void MapContext::triggerUpdate(const TransformState& state, const Update u) {
void MapContext::triggerUpdate(const TransformState& state, const Update flags) {
transformState = state;
updated |= static_cast<UpdateType>(u);
updateFlags |= flags;

asyncUpdate->send();
}
Expand Down Expand Up @@ -138,9 +137,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
// force style cascade, causing all pending transitions to complete.
style->cascade();

updated |= static_cast<UpdateType>(Update::DefaultTransition);
updated |= static_cast<UpdateType>(Update::Classes);
updated |= static_cast<UpdateType>(Update::Zoom);
updateFlags |= Update::DefaultTransition | Update::Classes | Update::Zoom;
asyncUpdate->send();

auto staleTiles = data.getAnnotationManager()->resetStaleTiles();
Expand Down Expand Up @@ -245,7 +242,7 @@ void MapContext::updateAnnotationTiles(const std::unordered_set<TileID, TileID::
}
}

updated |= static_cast<UpdateType>(Update::Classes);
updateFlags |= Update::Classes;
asyncUpdate->send();

annotationManager->resetStaleTiles();
Expand All @@ -255,21 +252,20 @@ void MapContext::update() {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));

if (!style) {
updated = static_cast<UpdateType>(Update::Nothing);
updateFlags = Update::Nothing;
}

if (updated == static_cast<UpdateType>(Update::Nothing)) {
if (updateFlags == Update::Nothing) {
return;
}

data.setAnimationTime(Clock::now());

if (updated & static_cast<UpdateType>(Update::Classes)) {
if (updateFlags & Update::Classes) {
style->cascade();
}

if (updated & static_cast<UpdateType>(Update::Classes) ||
updated & static_cast<UpdateType>(Update::Zoom)) {
if (updateFlags & Update::Classes || updateFlags & Update::Zoom) {
style->recalculate(transformState.getNormalizedZoom());
}

Expand All @@ -281,7 +277,7 @@ void MapContext::update() {
renderSync(transformState, frameData);
}

updated = static_cast<UpdateType>(Update::Nothing);
updateFlags = Update::Nothing;
}

void MapContext::renderStill(const TransformState& state, const FrameData& frame, Map::StillImageCallback fn) {
Expand Down Expand Up @@ -314,7 +310,7 @@ void MapContext::renderStill(const TransformState& state, const FrameData& frame
transformState = state;
frameData = frame;

updated |= static_cast<UpdateType>(Update::RenderStill);
updateFlags |= Update::RenderStill;
asyncUpdate->send();
}

Expand Down Expand Up @@ -400,7 +396,7 @@ void MapContext::setSprite(const std::string& name, std::shared_ptr<const Sprite
void MapContext::onTileDataChanged() {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));

updated |= static_cast<UpdateType>(Update::Repaint);
updateFlags |= Update::Repaint;
asyncUpdate->send();
}

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/map/map_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MapContext : public Style::Observer {

util::GLObjectStore glObjectStore;

UpdateType updated { static_cast<UpdateType>(Update::Nothing) };
Update updateFlags = Update::Nothing;
std::unique_ptr<uv::async> asyncUpdate;

std::unique_ptr<TexturePool> texturePool;
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ void Transform::startTransition(std::function<Update(double)> frame,
transitionFinishFn = finish;
}

UpdateType Transform::updateTransitions(const TimePoint& now) {
return static_cast<UpdateType>(transitionFrameFn ? transitionFrameFn(now) : Update::Nothing);
Update Transform::updateTransitions(const TimePoint& now) {
return transitionFrameFn ? transitionFrameFn(now) : Update::Nothing;
}

void Transform::cancelTransitions() {
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/map/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Transform : private util::noncopyable {
double getAngle() const;

// Transitions
UpdateType updateTransitions(const TimePoint& now);
Update updateTransitions(const TimePoint& now);
void cancelTransitions();

// Gesture
Expand Down

0 comments on commit ac9d588

Please sign in to comment.