Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced use of the vgl module. #918

Merged
merged 1 commit into from
Sep 11, 2018
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Changes
- Removed the dependency on the vgl module for the `object` and `timestamp` classes (#918)

## Version 0.18.1

### Bug Fixes
Expand Down
8 changes: 4 additions & 4 deletions examples/animation/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ $(function () {
function animation_frame() {
var datalen = animationState.order.length,
styles = animationState.styleArrays,
curTime = new Date().getTime(), genTime, updateTime,
curTime = Date.now(), genTime, updateTime,
position, i, idx, p;
timeRecords.frames.push(curTime);
animationState.raf = null;
Expand Down Expand Up @@ -284,9 +284,9 @@ $(function () {
updateStyles[key] = styles[key];
}
});
genTime = new Date().getTime();
genTime = Date.now();
pointFeature.updateStyleFromArray(updateStyles, null, true);
updateTime = new Date().getTime();
updateTime = Date.now();
timeRecords.generate.push(genTime - curTime);
timeRecords.update.push(updateTime - genTime);
show_framerate();
Expand Down Expand Up @@ -325,7 +325,7 @@ $(function () {
if (animationState.position === undefined || animationState.position === null) {
animationState.position = 0;
}
animationState.startTime = new Date().getTime() - animationState.duration * animationState.position;
animationState.startTime = Date.now() - animationState.duration * animationState.position;
if (!animationState.styleArrays || datalen !== animationState.order.length) {
animationState.order = new Array(datalen);
if (!animationState.orderedData) {
Expand Down
2 changes: 1 addition & 1 deletion src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ var annotationLayer = function (args) {
* @returns {this} The current layer.
*/
this._update = function () {
if (m_this.getMTime() > m_buildTime.getMTime()) {
if (m_this.timestamp() > m_buildTime.timestamp()) {
var labels = m_this.options('showLabels') ? [] : null,
editable = m_this.options('clickToEdit') || m_this.mode() === m_this.modes.edit;
/* Interally, we have a set of feature levels (to provide z-index
Expand Down
6 changes: 3 additions & 3 deletions src/canvas/heatmapFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ var canvas_heatmapFeature = function (arg) {
*/
this._renderOnCanvas = function (context2d, map) {

if (m_renderTime.getMTime() < m_this.buildTime().getMTime()) {
if (m_renderTime.timestamp() < m_this.buildTime().timestamp()) {
var data = m_this.data() || [],
radius = m_this.style('radius') + m_this.style('blurRadius'),
binned = m_this.binned(),
Expand Down Expand Up @@ -375,8 +375,8 @@ var canvas_heatmapFeature = function (arg) {
*/
this._update = function () {
s_update.call(m_this);
if (m_this.buildTime().getMTime() <= m_this.dataTime().getMTime() ||
m_this.updateTime().getMTime() < m_this.getMTime()) {
if (m_this.buildTime().timestamp() <= m_this.dataTime().timestamp() ||
m_this.updateTime().timestamp() < m_this.timestamp()) {
m_this._build();
}
m_this.updateTime().modified();
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/quadFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ var canvas_quadFeature = function (arg) {
*/
this._update = function () {
s_update.call(m_this);
if (m_this.buildTime().getMTime() <= m_this.dataTime().getMTime() ||
m_this.updateTime().getMTime() < m_this.getMTime()) {
if (m_this.buildTime().timestamp() <= m_this.dataTime().timestamp() ||
m_this.updateTime().timestamp() < m_this.timestamp()) {
m_this._build();
}

Expand Down
2 changes: 1 addition & 1 deletion src/d3/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var d3_lineFeature = function (arg) {
this._update = function () {
s_update.call(m_this);

if (m_this.getMTime() >= m_buildTime.getMTime()) {
if (m_this.timestamp() >= m_buildTime.timestamp()) {
m_this._build();
}

Expand Down
2 changes: 1 addition & 1 deletion src/d3/pathFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var d3_pathFeature = function (arg) {
this._update = function () {
s_update.call(m_this);

if (m_this.dataTime().getMTime() >= m_buildTime.getMTime()) {
if (m_this.dataTime().timestamp() >= m_buildTime.timestamp()) {
m_this._build();
}

Expand Down
2 changes: 1 addition & 1 deletion src/d3/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var d3_pointFeature = function (arg) {
this._update = function () {
s_update.call(m_this);

if (m_this.getMTime() >= m_buildTime.getMTime()) {
if (m_this.timestamp() >= m_buildTime.timestamp()) {
m_this._build();
}

Expand Down
4 changes: 2 additions & 2 deletions src/d3/quadFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ var d3_quadFeature = function (arg) {
*/
this._update = function () {
s_update.call(m_this);
if (m_this.buildTime().getMTime() <= m_this.dataTime().getMTime() ||
m_this.buildTime().getMTime() < m_this.getMTime()) {
if (m_this.buildTime().timestamp() <= m_this.dataTime().timestamp() ||
m_this.buildTime().timestamp() < m_this.timestamp()) {
m_this._build();
}
return m_this;
Expand Down
2 changes: 1 addition & 1 deletion src/d3/vectorFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ var d3_vectorFeature = function (arg) {
this._update = function () {
s_update.call(m_this);

if (m_this.getMTime() >= m_buildTime.getMTime()) {
if (m_this.timestamp() >= m_buildTime.timestamp()) {
m_this._build();
} else {
updateMarkers(
Expand Down
2 changes: 1 addition & 1 deletion src/featureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ var featureLayer = function (arg) {
// Call base class update
s_update.call(m_this, request);

if (m_this.dataTime().getMTime() > m_this.updateTime().getMTime()) {
if (m_this.dataTime().timestamp() > m_this.updateTime().timestamp()) {
for (i = 0; i < m_features.length; i += 1) {
m_features[i].renderer(m_this.renderer());
}
Expand Down
4 changes: 2 additions & 2 deletions src/gl/choroplethFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ var gl_choroplethFeature = function (arg) {
*/
this._update = function () {
s_update.call(m_this);
if (m_this.dataTime().getMTime() >= m_this.buildTime().getMTime() ||
m_this.updateTime().getMTime() <= m_this.getMTime()) {
if (m_this.dataTime().timestamp() >= m_this.buildTime().timestamp() ||
m_this.updateTime().timestamp() <= m_this.timestamp()) {
m_this._wipePolygons();
m_this._build();
}
Expand Down
4 changes: 2 additions & 2 deletions src/gl/contourFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ var gl_contourFeature = function (arg) {
this._update = function () {
s_update.call(m_this);

if (m_this.dataTime().getMTime() >= m_this.buildTime().getMTime() ||
m_this.updateTime().getMTime() <= m_this.getMTime()) {
if (m_this.dataTime().timestamp() >= m_this.buildTime().timestamp() ||
m_this.updateTime().timestamp() <= m_this.timestamp()) {
m_this._build();
}

Expand Down
6 changes: 3 additions & 3 deletions src/gl/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ var gl_lineFeature = function (arg) {
* @returns {this}
*/
this._build = function () {
createGLLines(m_this.dataTime().getMTime() < m_this.buildTime().getMTime() && m_geometry);
createGLLines(m_this.dataTime().timestamp() < m_this.buildTime().timestamp() && m_geometry);

if (!m_this.renderer().contextRenderer().hasActor(m_actor)) {
m_this.renderer().contextRenderer().addActor(m_actor);
Expand All @@ -771,8 +771,8 @@ var gl_lineFeature = function (arg) {
this._update = function () {
s_update.call(m_this);

if (m_this.dataTime().getMTime() >= m_this.buildTime().getMTime() ||
m_this.updateTime().getMTime() <= m_this.getMTime()) {
if (m_this.dataTime().timestamp() >= m_this.buildTime().timestamp() ||
m_this.updateTime().timestamp() <= m_this.timestamp()) {
m_this._build();
}

Expand Down
4 changes: 2 additions & 2 deletions src/gl/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,8 @@ var gl_pointFeature = function (arg) {

// For now build if the data or style changes. In the future we may
// we able to partially update the data using dynamic gl buffers.
if (m_this.dataTime().getMTime() >= m_this.buildTime().getMTime() ||
m_this.updateTime().getMTime() < m_this.getMTime()) {
if (m_this.dataTime().timestamp() >= m_this.buildTime().timestamp() ||
m_this.updateTime().timestamp() < m_this.timestamp()) {
m_this._build();
}

Expand Down
6 changes: 3 additions & 3 deletions src/gl/polygonFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ var gl_polygonFeature = function (arg) {
* @override
*/
this._build = function () {
createGLPolygons(m_this.dataTime().getMTime() < m_this.buildTime().getMTime() && m_geometry);
createGLPolygons(m_this.dataTime().timestamp() < m_this.buildTime().timestamp() && m_geometry);

if (!m_this.renderer().contextRenderer().hasActor(m_actor)) {
m_this.renderer().contextRenderer().addActor(m_actor);
Expand Down Expand Up @@ -352,8 +352,8 @@ var gl_polygonFeature = function (arg) {
}
s_update.call(m_this);

if (m_this.dataTime().getMTime() >= m_this.buildTime().getMTime() ||
m_this.updateTime().getMTime() <= m_this.getMTime()) {
if (m_this.dataTime().timestamp() >= m_this.buildTime().timestamp() ||
m_this.updateTime().timestamp() <= m_this.timestamp()) {
m_this._build();
}

Expand Down
49 changes: 34 additions & 15 deletions src/gl/quadFeature.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var inherit = require('../inherit');
var registerFeature = require('../registry').registerFeature;
var quadFeature = require('../quadFeature');
var timestamp = require('../timestamp');

/**
* Create a new instance of class quadFeature.
Expand Down Expand Up @@ -31,8 +32,8 @@ var gl_quadFeature = function (arg) {
m_modelViewUniform,
m_actor_image, m_actor_color, m_glBuffers = {}, m_imgposbuf,
m_clrposbuf, m_clrModelViewUniform,
m_glCompileTimestamp = vgl.timestamp(),
m_glColorCompileTimestamp = vgl.timestamp(),
m_glCompileTimestamp = timestamp(),
m_glColorCompileTimestamp = timestamp(),
m_quads;
var fragmentShaderImageSource = [
'varying highp vec2 iTextureCoord;',
Expand Down Expand Up @@ -144,6 +145,29 @@ var gl_quadFeature = function (arg) {
m_glColorCompileTimestamp.modified();
}

/**
* Get a vgl mapper, mark dynamicDraw, augment the timestamp and the render
* function.
*
* @private
* @param {function} renderFunc Our own render function.
* @returns {vgl.mapper} a vgl mapper object.
*/
function getVGLMapper(renderFunc) {
var mapper = new vgl.mapper({dynamicDraw: true});
mapper.s_modified = mapper.modified;
mapper.g_timestamp = timestamp();
mapper.timestamp = mapper.g_timestamp.timestamp;
mapper.modified = function () {
mapper.s_modified();
mapper.g_timestamp.modified();
return mapper;
};
mapper.s_render = mapper.render;
mapper.render = renderFunc;
return mapper;
}

/**
* Build this feature.
*/
Expand All @@ -157,7 +181,7 @@ var gl_quadFeature = function (arg) {
/* Create an actor to render image quads */
if (m_quads.imgQuads.length && !m_actor_image) {
m_this.visible(false);
mapper = new vgl.mapper({dynamicDraw: true});
mapper = getVGLMapper(m_this._renderImageQuads);
m_actor_image = new vgl.actor();
/* This is similar to vgl.utils.createTextureMaterial */
m_actor_image.setMapper(mapper);
Expand Down Expand Up @@ -193,16 +217,13 @@ var gl_quadFeature = function (arg) {

mapper.setGeometryData(geom);
m_actor_image.setMaterial(mat);

mapper.s_render = mapper.render;
mapper.render = m_this._renderImageQuads;
m_this.renderer().contextRenderer().addActor(m_actor_image);
m_this.visible(true);
}
/* Create an actor to render color quads */
if (m_quads.clrQuads.length && !m_actor_color) {
m_this.visible(false);
mapper = new vgl.mapper({dynamicDraw: true});
mapper = getVGLMapper(m_this._renderColorQuads);
m_actor_color = new vgl.actor();
/* This is similar to vgl.utils.createTextureMaterial */
m_actor_color.setMapper(mapper);
Expand Down Expand Up @@ -231,8 +252,6 @@ var gl_quadFeature = function (arg) {
mapper.setGeometryData(geom);
m_actor_color.setMaterial(mat);

mapper.s_render = mapper.render;
mapper.render = m_this._renderColorQuads;
m_this.renderer().contextRenderer().addActor(m_actor_color);
m_this.visible(true);
}
Expand Down Expand Up @@ -277,8 +296,8 @@ var gl_quadFeature = function (arg) {
return;
}
var mapper = this;
if (mapper.getMTime() > m_glColorCompileTimestamp.getMTime() ||
m_this.dataTime().getMTime() > m_glColorCompileTimestamp.getMTime() ||
if (mapper.timestamp() > m_glColorCompileTimestamp.timestamp() ||
m_this.dataTime().timestamp() > m_glColorCompileTimestamp.timestamp() ||
renderState.m_contextChanged || !m_clrposbuf ||
m_quads.clrQuads.length * 12 > m_clrposbuf.length) {
setupColorDrawObjects(renderState);
Expand Down Expand Up @@ -324,8 +343,8 @@ var gl_quadFeature = function (arg) {
return;
}
var mapper = this;
if (mapper.getMTime() > m_glCompileTimestamp.getMTime() ||
m_this.dataTime().getMTime() > m_glCompileTimestamp.getMTime() ||
if (mapper.timestamp() > m_glCompileTimestamp.timestamp() ||
m_this.dataTime().timestamp() > m_glCompileTimestamp.timestamp() ||
renderState.m_contextChanged || !m_imgposbuf ||
m_quads.imgQuads.length * 12 > m_imgposbuf.length) {
setupDrawObjects(renderState);
Expand Down Expand Up @@ -371,8 +390,8 @@ var gl_quadFeature = function (arg) {
*/
this._update = function () {
s_update.call(m_this);
if (m_this.buildTime().getMTime() <= m_this.dataTime().getMTime() ||
m_this.updateTime().getMTime() < m_this.getMTime()) {
if (m_this.buildTime().timestamp() <= m_this.dataTime().timestamp() ||
m_this.updateTime().timestamp() < m_this.timestamp()) {
m_this._build();
}
if (m_actor_color) {
Expand Down
6 changes: 3 additions & 3 deletions src/isolineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ var isolineFeature = function (arg) {
* @returns {this}
*/
this.labelPositions = function () {
if (m_this.dataTime().getMTime() >= m_this.buildTime().getMTime()) {
if (m_this.dataTime().timestamp() >= m_this.buildTime().timestamp()) {
m_this._build();
}
m_lastLabelPositions = null;
Expand Down Expand Up @@ -756,8 +756,8 @@ var isolineFeature = function (arg) {
this._update = function () {
s_update.call(m_this);

if (m_this.dataTime().getMTime() >= m_this.buildTime().getMTime() ||
m_this.updateTime().getMTime() <= m_this.getMTime()) {
if (m_this.dataTime().timestamp() >= m_this.buildTime().timestamp() ||
m_this.updateTime().timestamp() <= m_this.timestamp()) {
m_this._build();
}
m_this.updateTime().modified();
Expand Down
4 changes: 2 additions & 2 deletions src/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ var lineFeature = function (arg) {
* @returns {object} The point search information record.
*/
this._updatePointSearchInfo = function () {
if (m_pointSearchTime.getMTime() >= m_this.dataTime().getMTime() &&
m_pointSearchTime.getMTime() >= m_this.getMTime()) {
if (m_pointSearchTime.timestamp() >= m_this.dataTime().timestamp() &&
m_pointSearchTime.timestamp() >= m_this.timestamp()) {
return m_pointSearchInfo;
}
m_pointSearchTime.modified();
Expand Down
5 changes: 2 additions & 3 deletions src/map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var $ = require('jquery');
var vgl = require('vgl');
var inherit = require('./inherit');
var sceneObject = require('./sceneObject');

Expand Down Expand Up @@ -1097,10 +1096,10 @@ var map = function (arg) {

// Transform zoom level into z-coordinate and inverse.
function zoom2z(z) {
return vgl.zoomToHeight(z + 1, m_width, m_height) * units;
return Math.pow(2, -(z + 1)) * units * m_height;
}
function z2zoom(z) {
return vgl.heightToZoom(z / units, m_width, m_height) - 1;
return -Math.log2(z / units / m_height) - 1;
}

var defaultOpts = {
Expand Down
Loading