Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reverted to using counter-clockwise winded tree.

Major code changes required to make the bsp tree code winding-agnostic.
Something to attempt at a later stage maybe.
  • Loading branch information...
commit 5cc47359b87e62321995ca95363e1236f18edbd2 1 parent 408788f
@nicokruger authored
View
29 src/main/javascript/game/level.js
@@ -22,20 +22,19 @@ doom.get_sectors = function(leveldata) {
_(doom_linedefs).each(function (linedef) {
if (linedef.right != -1) {
- sectors[sidedefs_sectors[linedef.right]].push($L(doom_vertices[linedef.vx_a], doom_vertices[linedef.vx_b]));
+ sectors[sidedefs_sectors[linedef.right]].push($L(doom_vertices[linedef.vx_b], doom_vertices[linedef.vx_a]));
}
if (linedef.left != -1) {
- sectors[sidedefs_sectors[linedef.left]].push($L(doom_vertices[linedef.vx_b], doom_vertices[linedef.vx_a]));
+ sectors[sidedefs_sectors[linedef.left]].push($L(doom_vertices[linedef.vx_a], doom_vertices[linedef.vx_b]));
}
});
return _(sectors).map(function (s) {
- return {
- tick: function (delta) {
- },
- poly: {
+ var bsp = renderlib.bsp.create(s);
+
+ var poly = {
edges: s,
- bsp: renderlib.bsp_cl.create(s),
+ bsp: bsp,
vertices: _(s).chain().map(function (x) { return x.origin }).uniq().value(),
extremes: {
x1: -768,
@@ -43,11 +42,19 @@ doom.get_sectors = function(leveldata) {
y1: 256,
y2: 768
},
- partition: function (line) {
- return renderlib.bsp_cl.partition(s, line)
- },
+ width: -256 - -768,
+ height: 768 - 256
+ }
+ poly["partition"] = function (line) {
+ return renderlib.bsp.partition(poly, line)
+ }
+ return {
+ tick: function (delta) {
},
- texture: "doomlogo2"
+ poly: poly,
+ texture: "doomlogo2",
+ width: -256 - -768,
+ height: 768 - 256
}
});
View
2  src/main/javascript/index.html
@@ -67,9 +67,9 @@
<option value="data/MAP30.json">MAP30</option>
</select>
Renderer: <select id="renderer" onchange="changerenderer()">
+ <option value="renderlib.screens.blit">blit</option>
<option value="renderlib.screens.fullCanvas">fullCanvas</option>
<option value="renderlib.screens.backingCanvas">backingCanvas</option>
- <option value="renderlib.screens.blit">blit</option>
<option value="renderlib.screens.gl">gl</option>
</select>
</span>
View
27 src/main/javascript/renderlib/btree.js
@@ -6,7 +6,10 @@ var CCL = {
INTERSECTS_BACKWARD: 1,
LEFT: -1,
RIGHT: 2,
- COINCIDENT: 3
+ COINCIDENT: 3,
+ patch: function (x,y) {
+ return $L(x, y);
+ }
}
var CL = {
@@ -14,7 +17,10 @@ var CL = {
INTERSECTS_BACKWARD: 0,
LEFT: 2,
RIGHT: -1,
- COINCIDENT: 3
+ COINCIDENT: 3,
+ patch: function (x,y) {
+ return $L(y,x);
+ }
}
var bsp = function(winding) {
@@ -64,11 +70,13 @@ var bsp = function(winding) {
}
if (!I.equals(edge.end)) {
- var second = $L(I, edge.end);
+ //var second = $L(I, edge.end);
+ var second = winding.patch(I, edge.end);
pos_partition(T.positive, second, partition_node);
}
if (!edge.origin.equals(I)) {
- var first = $L(edge.origin, I)
+ //var first = $L(edge.origin, I)
+ var first = winding.patch(edge.origin, I);
neg_partition(T.negative, first, partition_node);
}
@@ -81,11 +89,13 @@ var bsp = function(winding) {
}
if (!edge.origin.equals(I)) {
- var first = $L(edge.origin, I)
+ //var first = $L(edge.origin, I)
+ var first = winding.patch(edge.origin, I);
pos_partition(T.positive, first, partition_node);
}
if (!I.equals(edge.end)) {
- var second = $L(I, edge.end);
+ //var second = $L(I, edge.end);
+ var second = winding.patch(I, edge.end);
neg_partition(T.negative, second, partition_node);
}
@@ -95,6 +105,11 @@ var bsp = function(winding) {
neg_partition(T.negative, edge, partition_node);
} else if (classification == winding.COINCIDENT) {
T.coincident.forEach(function (EE) {
+
+ //
+ // THE BUG IS HERE
+ //
+
var I = EE.coincident_segment(edge)
// Check the direction of the line
View
16 src/main/javascript/renderlib/screens/blit.js
@@ -33,6 +33,22 @@ renderlib.screens.blit = function(game,width,height) {
renderlib.util.Timer.subend();
renderlib.util.Timer.end();
+
+ for (var i = 0; i < sectors.length; i++) {
+ for (var k = 0; k < sectors[i].poly.edges.length; k++) {
+ ctx.beginPath();
+ var one = sectors[i].poly.edges[k].origin;
+ var two = sectors[i].poly.edges[k].end;
+ var g = ctx.createLinearGradient(c2s.cartesian2screenx(one.x), c2s.cartesian2screeny(one.y),
+ c2s.cartesian2screenx(two.x), c2s.cartesian2screeny(two.y));
+ g.addColorStop(0.0, 'rgba(255, 0, 0, 1.0)');
+ g.addColorStop(1.0, 'rgba(0, 255, 0, 1.0)');
+ ctx.strokeStyle = g;
+ ctx.moveTo(c2s.cartesian2screenx(one.x), c2s.cartesian2screeny(one.y));
+ ctx.lineTo(c2s.cartesian2screenx(two.x), c2s.cartesian2screeny(two.y));
+ ctx.stroke();
+ }
+ }
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.