Skip to content

Commit

Permalink
remove last vestiges of starting vertex cache
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Oct 19, 2015
1 parent f2d90c4 commit 2dc0ba5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 419 deletions.
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ gulp.task('build-min', () => {
'visibility',
],
use_types_for_optimization: null,
// variable_renaming_report: 'varreport.txt',

// Since DOM isn't touched, don't use default externs, leaving only the
// core language keywords unobfuscated.
Expand Down
128 changes: 4 additions & 124 deletions libtess.cat.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
* Copyright 2000, Silicon Graphics, Inc. All Rights Reserved.
* Copyright 2014, Google Inc. All Rights Reserved.
* Copyright 2015, Google Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -85,13 +85,6 @@ libtess.GLU_TESS_MAX_COORD = 1e150;
*/
libtess.TRUE_PROJECT = false;

/**
* We cache vertex data for single-contour polygons so that we can try a
* quick-and-dirty decomposition first.
* @const {number}
*/
libtess.TESS_MAX_CACHE = 100;

/**
* The default tolerance for merging features, 0, meaning vertices are only
* merged if they are exactly coincident
Expand Down Expand Up @@ -3263,31 +3256,6 @@ libtess.DictNode.prototype.getPredecessor = function() {



/* global libtess */

/**
* Cached vertex data for single-countour polygons for quick-and-dirty
* decomposition.
* @constructor
* @struct
*/
libtess.CachedVertex = function() {
/**
* [coords description]
* @type {Array.<number>}
*/
this.coords = [0, 0, 0];
// TODO(bckenny): better way to init?

/**
* [data description]
* @type {Object}
*/
this.data = null;
};



/* global libtess */

// TODO(bckenny): create more javascript-y API, e.g. make gluTessEndPolygon
Expand Down Expand Up @@ -3325,7 +3293,6 @@ libtess.GluTesselator = function() {
* @type {libtess.GluMesh}
*/
this.mesh = null;
// NOTE(bckenny): initialized in this.emptyCache_

/**
* Error callback.
Expand Down Expand Up @@ -3496,31 +3463,6 @@ libtess.GluTesselator = function() {
* @type {Object}
*/
this.polygonData_ = null;

/*** state needed to cache single-contour polygons for renderCache() ***/
/**
* empty cache on next vertex() call
* @type {boolean}
*/
this.emptyCache = false;
// TODO(bckenny): possibly rename to be clear it's a boolean

/**
* number of cached vertices
* @type {number}
*/
this.cacheCount = 0;

/**
* the vertex data
* @type {Array.<libtess.CachedVertex>}
*/
this.cache = new Array(libtess.TESS_MAX_CACHE);

// TODO(bckenny): fill now? or init on demand
for (var i = 0; i < libtess.TESS_MAX_CACHE; i++) {
this.cache[i] = new libtess.CachedVertex();
}
};

/**
Expand Down Expand Up @@ -3730,11 +3672,6 @@ libtess.GluTesselator.prototype.gluTessVertex = function(coords, data) {

this.requireState_(libtess.GluTesselator.tessState_.T_IN_CONTOUR);

if (this.emptyCache) {
this.emptyCache_();
this.lastEdge_ = null;
}

for (var i = 0; i < 3; ++i) {
var x = coords[i];
if (x < -libtess.GLU_TESS_MAX_COORD) {
Expand All @@ -3752,16 +3689,6 @@ libtess.GluTesselator.prototype.gluTessVertex = function(coords, data) {
this.callErrorOrErrorData(libtess.errorType.GLU_TESS_COORD_TOO_LARGE);
}

if (this.mesh === null) {
if (this.cacheCount < libtess.TESS_MAX_CACHE) {
this.cacheVertex_(clamped, data);
return;
}

// cache is full, create mesh and add cached verts to it
this.emptyCache_();
}

this.addVertex_(clamped, data);
};

Expand All @@ -3774,9 +3701,8 @@ libtess.GluTesselator.prototype.gluTessBeginPolygon = function(data) {
this.requireState_(libtess.GluTesselator.tessState_.T_DORMANT);

this.state = libtess.GluTesselator.tessState_.T_IN_POLYGON;
this.cacheCount = 0;
this.emptyCache = false;
this.mesh = null;

this.mesh = new libtess.GluMesh();

this.polygonData_ = data;
};
Expand All @@ -3790,13 +3716,6 @@ libtess.GluTesselator.prototype.gluTessBeginContour = function() {

this.state = libtess.GluTesselator.tessState_.T_IN_CONTOUR;
this.lastEdge_ = null;
if (this.cacheCount > 0) {
// Just set a flag so we don't get confused by empty contours
// -- these can be generated accidentally with the obsolete
// NextContour() interface.
// TODO(bckenny): we aren't implementing NextContour() interface.
this.emptyCache = true;
}
};


Expand All @@ -3816,11 +3735,6 @@ libtess.GluTesselator.prototype.gluTessEndPolygon = function() {
this.requireState_(libtess.GluTesselator.tessState_.T_IN_POLYGON);
this.state = libtess.GluTesselator.tessState_.T_DORMANT;

if (this.mesh === null) {
// TODO(bckenny): can we eliminate more cache functionality?
this.emptyCache_();
}

// Determine the polygon normal and project vertices onto the plane
// of the polygon.
libtess.normal.projectPolygon(this);
Expand Down Expand Up @@ -3888,6 +3802,7 @@ libtess.GluTesselator.prototype.gluTessEndPolygon = function() {
* @private
*/
libtess.GluTesselator.prototype.makeDormant_ = function() {
// TODO(bckenny): this could be eliminated by just auto-finishing the poly.
if (this.mesh) {
libtess.mesh.deleteMesh(this.mesh);
}
Expand Down Expand Up @@ -3990,41 +3905,6 @@ libtess.GluTesselator.prototype.addVertex_ = function(coords, data) {
};


/**
* [cacheVertex_ description]
* @private
* @param {Array.<number>} coords [description].
* @param {Object} data [description].
*/
libtess.GluTesselator.prototype.cacheVertex_ = function(coords, data) {
var v = this.cache[this.cacheCount];

v.data = data;
v.coords[0] = coords[0];
v.coords[1] = coords[1];
v.coords[2] = coords[2];
++this.cacheCount;
};


/**
* [emptyCache_ description]
* @private
*/
libtess.GluTesselator.prototype.emptyCache_ = function() {
// NOTE(bckenny): surprise!
this.mesh = new libtess.GluMesh();

for (var i = 0; i < this.cacheCount; i++) {
var v = this.cache[i];
this.addVertex_(v.coords, v.data);
}

this.cacheCount = 0;
this.emptyCache = false;
};


// TODO(bckenny): all following conditional callbacks could be simplified
// TODO(bckenny): using null for now, but may rework
// TODO(bckenny): should add documentation that references in callback are volatile (or make a copy)
Expand Down
Loading

0 comments on commit 2dc0ba5

Please sign in to comment.