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

Improve map debug options #3100

Merged
merged 6 commits into from
Nov 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ private void zoom(boolean zoomIn, float x, float y) {
*/
@UiThread
public boolean isDebugActive() {
return mNativeMapView.getDebug() || mNativeMapView.getCollisionDebug();
return mNativeMapView.getDebug();
}

/**
Expand All @@ -1319,20 +1319,19 @@ public boolean isDebugActive() {
@UiThread
public void setDebugActive(boolean debugActive) {
mNativeMapView.setDebug(debugActive);
mNativeMapView.setCollisionDebug(debugActive);
}

/**
* Toggles whether the map debug information is shown.
* Cycles through the map debug options.
* <p/>
* The value of {@link MapView#isDebugActive()} is toggled.
* The value of {@link MapView#isDebugActive()} reflects whether there are
* any map debug options enabled or disabled.
*
* @see MapView#isDebugActive()
*/
@UiThread
public void toggleDebug() {
mNativeMapView.toggleDebug();
mNativeMapView.toggleCollisionDebug();
public void cycleDebugOptions() {
mNativeMapView.cycleDebugOptions();
}

// True if map has finished loading the view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,26 +401,14 @@ public void setDebug(boolean debug) {
nativeSetDebug(mNativeMapViewPtr, debug);
}

public void toggleDebug() {
public void cycleDebugOptions() {
nativeToggleDebug(mNativeMapViewPtr);
}

public boolean getDebug() {
return nativeGetDebug(mNativeMapViewPtr);
}

public void setCollisionDebug(boolean debug) {
nativeSetCollisionDebug(mNativeMapViewPtr, debug);
}

public void toggleCollisionDebug() {
nativeToggleCollisionDebug(mNativeMapViewPtr);
}

public boolean getCollisionDebug() {
return nativeGetCollisionDebug(mNativeMapViewPtr);
}

public boolean isFullyLoaded() {
return nativeIsFullyLoaded(mNativeMapViewPtr);
}
Expand Down Expand Up @@ -614,12 +602,6 @@ private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, Lat

private native boolean nativeGetDebug(long nativeMapViewPtr);

private native void nativeSetCollisionDebug(long nativeMapViewPtr, boolean debug);

private native void nativeToggleCollisionDebug(long nativeMapViewPtr);

private native boolean nativeGetCollisionDebug(long nativeMapViewPtr);

private native boolean nativeIsFullyLoaded(long nativeMapViewPtr);

private native void nativeSetReachability(long nativeMapViewPtr, boolean status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {

case R.id.action_debug:
// Toggle debug mode
mMapView.toggleDebug();
// Cycle map debug options
mMapView.cycleDebugOptions();
toggleFpsCounter(mMapView.isDebugActive());
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<string name="action_gps">Toggle GPS location</string>
<string name="action_user_location_tracking">User location tracking</string>
<string name="action_compass">Toggle compass</string>
<string name="action_debug">Toggle debug mode</string>
<string name="action_debug">Cycle map debug options</string>
<string name="action_point_annotations">Toggle point annotations</string>
<string name="action_info_window_adapter">InfoWindow Adapter</string>
<string name="action_map_fragment">MapFragment</string>
Expand Down
2 changes: 1 addition & 1 deletion bin/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int main(int argc, char *argv[]) {
map.setBearing(bearing);

if (debug) {
map.setDebug(debug);
map.setDebug(debug ? mbgl::MapDebugOptions::TileBorders | mbgl::MapDebugOptions::ParseStatus : mbgl::MapDebugOptions::NoDebug);
}

uv_async_t *async = new uv_async_t;
Expand Down
2 changes: 1 addition & 1 deletion docs/DEVELOP_IOS_OSX.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ If you want to run the tests in Xcode instead, first `make ipackage` to create a
- Double-tap to zoom in one level
- Two-finger single-tap to zoom out one level
- Double-tap, long-pressing the second, then pan up and down to "quick zoom" (iPhone only, meant for one-handed use)
- Use the debug menu to add test annotations, reset position, and toggle debug info.
- Use the debug menu to add test annotations, reset position, and cycle through the debug options.
4 changes: 2 additions & 2 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ IB_DESIGNABLE
* The default value of this property is `NO`. */
@property (nonatomic, getter=isDebugActive) BOOL debugActive;

/** Toggle the current value of debugActive. */
- (void)toggleDebug;
/** Cycle map debug options. */
- (void)cycleDebugOptions;

/** Empties the in-memory tile cache. */
- (void)emptyMemoryCache;
Expand Down
10 changes: 4 additions & 6 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,10 @@ class Map : private util::noncopyable {
void onLowMemory();

// Debug
void setDebug(bool value);
void toggleDebug();
bool getDebug() const;
void setCollisionDebug(bool value);
void toggleCollisionDebug();
bool getCollisionDebug() const;
void setDebug(MapDebugOptions);
void cycleDebugOptions();
MapDebugOptions getDebug() const;

bool isFullyLoaded() const;
void dumpDebugLogs() const;

Expand Down
29 changes: 26 additions & 3 deletions include/mbgl/map/mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace mbgl {

enum class MapMode : uint8_t {
using EnumType = uint32_t;

enum class MapMode : EnumType {
Continuous, // continually updating map
Still, // a once-off still image
};
Expand All @@ -14,18 +16,39 @@ enum class MapMode : uint8_t {
// being shared. In a shared GL context case, we need to make sure that the
// correct GL configurations are in use - they might have changed between render
// calls.
enum class GLContextMode : uint8_t {
enum class GLContextMode : EnumType {
Unique,
Shared,
};

// We can choose to constrain the map both horizontally or vertically, or only
// vertically e.g. while panning.
enum class ConstrainMode : uint8_t {
enum class ConstrainMode : EnumType {
HeightOnly,
WidthAndHeight,
};

enum class MapDebugOptions : EnumType {
NoDebug = 0,
TileBorders = 1 << 1,
ParseStatus = 1 << 2,
Timestamps = 1 << 3,
Collision = 1 << 4,
};

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

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

inline bool operator& (const MapDebugOptions& lhs, const MapDebugOptions& rhs) {
return static_cast<EnumType>(lhs) & static_cast<EnumType>(rhs);
}

} // namespace mbgl

#endif // MBGL_MAP_MODE
2 changes: 1 addition & 1 deletion include/mbgl/platform/darwin/settings_nsuserdefaults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Settings_NSUserDefaults {
MGLUserTrackingMode userTrackingMode = MGLUserTrackingModeNone;
bool showsUserLocation = false;

bool debug = false;
uint32_t debug = 0;
};

}
Expand Down
4 changes: 3 additions & 1 deletion include/mbgl/platform/default/settings_json.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef MBGL_JSON_SETTINGS
#define MBGL_JSON_SETTINGS

#include <mbgl/map/mode.hpp>

namespace mbgl {

class Settings_JSON {
Expand All @@ -17,7 +19,7 @@ class Settings_JSON {
double bearing = 0;
double pitch = 0;

bool debug = false;
EnumType debug = 0;
};

}
Expand Down
6 changes: 4 additions & 2 deletions include/mbgl/storage/response.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef MBGL_STORAGE_RESPONSE
#define MBGL_STORAGE_RESPONSE

#include <mbgl/util/chrono.hpp>

#include <string>
#include <memory>

Expand All @@ -25,8 +27,8 @@ class Response {
// The actual data of the response. This is guaranteed to never be empty.
std::shared_ptr<const std::string> data;

int64_t modified = 0;
int64_t expires = 0;
Seconds modified = Seconds::zero();
Seconds expires = Seconds::zero();
std::string etag;
};

Expand Down
31 changes: 31 additions & 0 deletions include/mbgl/util/chrono.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,40 @@ namespace mbgl {
using Clock = std::chrono::steady_clock;
using SystemClock = std::chrono::system_clock;

using Seconds = std::chrono::seconds;
using Milliseconds = std::chrono::milliseconds;

using TimePoint = Clock::time_point;
using Duration = Clock::duration;

using SystemTimePoint = SystemClock::time_point;
using SystemDuration = SystemClock::duration;

template <class _Clock, class _Duration>
_Duration toDuration(std::chrono::time_point<_Clock, _Duration> time_point) {
return time_point.time_since_epoch();
}

template <class _Duration>
Seconds asSeconds(_Duration duration) {
return std::chrono::duration_cast<Seconds>(duration);
}

template <class _Clock, class _Duration>
Seconds toSeconds(std::chrono::time_point<_Clock, _Duration> time_point) {
return asSeconds(toDuration<_Clock, _Duration>(time_point));
}

template <class _Duration>
Milliseconds asMilliseconds(_Duration duration) {
return std::chrono::duration_cast<Milliseconds>(duration);
}

template <class _Clock, class _Duration>
Milliseconds toMilliseconds(std::chrono::time_point<_Clock, _Duration> time_point) {
return asMilliseconds(toDuration<_Clock, _Duration>(time_point));
}

}

#endif
5 changes: 5 additions & 0 deletions include/mbgl/util/time.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef MBGL_UTIL_TIME
#define MBGL_UTIL_TIME

#include <mbgl/util/chrono.hpp>

#include <string>
#include <cstdint>
#include <ctime>
Expand All @@ -12,6 +14,9 @@ namespace util {
// Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT"
std::string rfc1123(std::time_t time);

// YYYY-mm-dd HH:MM:SS e.g. "2015-11-26 16:11:23"
std::string iso8601(std::time_t time);

}

}
Expand Down
4 changes: 2 additions & 2 deletions ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ - (void)showSettings
destructiveButtonTitle:nil
otherButtonTitles:@"Reset North",
@"Reset Position",
@"Toggle Debug",
@"Cycle debug options",
@"Empty Memory",
@"Add 100 Points",
@"Add 1,000 Points",
Expand All @@ -156,7 +156,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 2)
{
[self.mapView toggleDebug];
[self.mapView cycleDebugOptions];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 3)
{
Expand Down
4 changes: 2 additions & 2 deletions linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) {
map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom);
map.setBearing(settings.bearing);
map.setPitch(settings.pitch);
map.setDebug(settings.debug);
map.setDebug(mbgl::MapDebugOptions(settings.debug));
}

view->setChangeStyleCallback([&map] () {
Expand Down Expand Up @@ -167,7 +167,7 @@ int main(int argc, char *argv[]) {
settings.zoom = map.getZoom();
settings.bearing = map.getBearing();
settings.pitch = map.getPitch();
settings.debug = map.getDebug();
settings.debug = mbgl::EnumType(map.getDebug());
if (!skipConfig) {
settings.save();
}
Expand Down
4 changes: 2 additions & 2 deletions macosx/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int main(int argc, char* argv[]) {
map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom);
map.setBearing(settings.bearing);
map.setPitch(settings.pitch);
map.setDebug(settings.debug);
map.setDebug(mbgl::MapDebugOptions(settings.debug));

view.setChangeStyleCallback([&map, &view] () {
static uint8_t currentStyleIndex;
Expand Down Expand Up @@ -205,7 +205,7 @@ int main(int argc, char* argv[]) {
settings.zoom = map.getZoom();
settings.bearing = map.getBearing();
settings.pitch = map.getPitch();
settings.debug = map.getDebug();
settings.debug = uint32_t(map.getDebug());
settings.save();

return 0;
Expand Down
8 changes: 4 additions & 4 deletions platform/android/http_request_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ HTTPAndroidRequest::HTTPAndroidRequest(HTTPAndroidContext* context_, const Resou
if (existingResponse) {
if (!existingResponse->etag.empty()) {
etagStr = existingResponse->etag;
} else if (existingResponse->modified) {
modifiedStr = util::rfc1123(existingResponse->modified);
} else if (existingResponse->modified != Seconds::zero()) {
modifiedStr = util::rfc1123(existingResponse->modified.count());
}
}

Expand Down Expand Up @@ -195,11 +195,11 @@ void HTTPAndroidRequest::onResponse(int code, std::string message, std::string e
response = std::make_unique<Response>();
using Error = Response::Error;

response->modified = parse_date(modified.c_str());
response->modified = Seconds(parse_date(modified.c_str()));
response->etag = etag;
response->expires = parseCacheControl(cacheControl.c_str());
if (!expires.empty()) {
response->expires = parse_date(expires.c_str());
response->expires = Seconds(parse_date(expires.c_str()));
}
response->data = std::make_shared<std::string>(body);

Expand Down
Loading