summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/engine')
-rw-r--r--public/assets/javascripts/rectangles/engine/map/draw.js14
-rw-r--r--public/assets/javascripts/rectangles/engine/shapes/regionlist.js59
2 files changed, 51 insertions, 22 deletions
diff --git a/public/assets/javascripts/rectangles/engine/map/draw.js b/public/assets/javascripts/rectangles/engine/map/draw.js
index f47f10c..c97603b 100644
--- a/public/assets/javascripts/rectangles/engine/map/draw.js
+++ b/public/assets/javascripts/rectangles/engine/map/draw.js
@@ -169,20 +169,6 @@ Map.Draw = function(map, opt){
}
draw.coords = function(){
- /*
- ctx.fillStyle = "#888";
- dot_at(0,0)
- ctx.fillStyle = "#bbb";
- dot_at(100,0)
- dot_at(0,100)
- ctx.fillStyle = "#ddd";
- dot_at(200,0)
- dot_at(0,200)
- ctx.fillStyle = "#eee";
- dot_at(300,0)
- dot_at(0,300)
- */
-
ctx.strokeStyle = "rgba(0,0,0,0.1)"
ctx.lineWidth = 1/map.zoom
diff --git a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js
index 93a0df7..fb2c8e5 100644
--- a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js
+++ b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js
@@ -27,7 +27,7 @@ var RegionList = (function(){
open_segments.splice(j--, 1)
x_segment = new vec2( open_segment.x.a, segment.x.b )
- y_segments = open_segment.y.split(segment.y, TOP, BOTTOM)
+ y_segments = open_segment.y.split(segment.y, 0, 0)
seen_segments = {}
@@ -35,9 +35,11 @@ var RegionList = (function(){
seen_segments[ seg[0]+"" ] = true
var room = new Rect( x_segment, seg[0] )
- if (seen_rooms[ room+"" ]) return;
-
+ if (seen_rooms[ room+"" ]) return
seen_rooms[ room+"" ] = true
+
+ room.sides = 0
+
rooms.push(room)
var new_seg = new Rect( segment.x, seg[0] )
open_segments.unshift(new_seg)
@@ -54,7 +56,6 @@ var RegionList = (function(){
}
}
if (overlapped) {
- // sort open segments?
open_segments = open_segments.sort(function(a,b){
if (a.y.a < b.y.a) { return -1 }
if (a.y.a == b.y.a) { return 0 }
@@ -69,7 +70,6 @@ var RegionList = (function(){
}
else if (open_segments[k-1].y.overlaps(open_segments[k].y)) {
open_segments[k].y = open_segments[k].y.clone()
- console.log(open_segments[k-1].y+"", open_segments[k].y+"")
open_segments[k].y.a = open_segments[k-1].y.b
}
}
@@ -79,14 +79,57 @@ var RegionList = (function(){
}
}
+ var splits, splitter
+
for (var i = 0; i < segments.length; i++) {
segment = segments[i]
- if (! segment.isHorizontal()) {
- continue
+ var horizontal = segment.isHorizontal(), vertical = segment.isVertical()
+ for (var r = 0; r < rooms.length; r++){
+ room = rooms[r]
+ if (vertical) {
+ if (segment.y.containsVec(room.y)) {
+ if (segment.x.a == room.x.a) {
+ room.sides |= LEFT
+ }
+ if (segment.x.a == room.x.b) {
+ room.sides |= RIGHT
+ }
+ }
+ }
+ if (horizontal) {
+ if (segment.x.containsVec(room.x)) {
+ if (segment.y.a == room.y.a) {
+ room.sides |= FRONT
+ }
+ if (segment.y.a == room.y.b) {
+ room.sides |= BACK
+ }
+ }
+/*
+ else if ((segment.y.a == room.y.a || segment.y.a == room.y.b) && room.x.containsVec(segment.x)) {
+ splits = room.x.split(segment.x, LEFT, RIGHT)
+ for (var k = 0; k < splits.length; k++) {
+ splitter = splits[k]
+ var new_room = new Rect( splitter[0], room.y )
+ new_room.sides |= splitter[1]
+ if (segment.x.containsVec(splitter[0])) {
+ if (segment.y.a == room.y.a) {
+ room.sides |= FRONT
+ }
+ if (segment.y.a == room.y.b) {
+ room.sides |= BACK
+ }
+ }
+ rooms.unshift(new_room)
+ r++
+ }
+ }
+*/
+ }
}
}
- return { rooms: rooms, open_segments: open_segments, segments: segments, closed_segments: closed_segments }
+ return { rooms: rooms }
}
RegionList.getSortedSegments = function(){