summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-08-14 17:45:08 -0400
committerJules Laplace <jules@okfoc.us>2014-08-14 17:45:08 -0400
commit8ed5bf2ceba8e85be9c911f8b33483242e979ab7 (patch)
treefc03b904a1bdd8bd4bffaf097cb8000374041750 /public/assets/javascripts/rectangles/engine
parent31907c69cc192a23bb409adf5c438ed708db0842 (diff)
fix last wrinkle in grouper
Diffstat (limited to 'public/assets/javascripts/rectangles/engine')
-rw-r--r--public/assets/javascripts/rectangles/engine/rooms/grouper.js73
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/_scenery.js4
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/_object.js4
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/image.js8
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/video.js8
5 files changed, 62 insertions, 35 deletions
diff --git a/public/assets/javascripts/rectangles/engine/rooms/grouper.js b/public/assets/javascripts/rectangles/engine/rooms/grouper.js
index 4ad3bd8..cde9fbb 100644
--- a/public/assets/javascripts/rectangles/engine/rooms/grouper.js
+++ b/public/assets/javascripts/rectangles/engine/rooms/grouper.js
@@ -1,6 +1,6 @@
(function(){
- var vec2, Rect, Rooms, UidGenerator, Wall, Surface, sort
+ var vec2, Rect, Rooms, UidGenerator, Wall, Surface, sort, _
if ('window' in this) {
vec2 = window.vec2
Rect = window.Rect
@@ -9,6 +9,7 @@
UidGenerator = window.UidGenerator
Wall = window.Wall
sort = window.sort
+ _ = window._
}
else {
Rooms = require('./_rooms')
@@ -18,6 +19,7 @@
Wall = require('../../models/wall')
Surface = require('../../models/surface')
sort = require('../../util/sort')
+ _ = require('lodash')
FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8, FLOOR = 0x10, CEILING = 0x20
PI = Math.PI
HALF_PI = PI/2
@@ -82,6 +84,7 @@
collection.sort( useX ? sort.compare_zx : sort.compare_xz )
collection.forEach(function(mx){
if (last_mx && last_mx.rect.eq(mx.rect)) {
+ // culls half-walls
if (last_mx.rect.id == mx.rect.id) {
last_mx.height += mx.height/2
last_mx.y += mx.height/4
@@ -103,41 +106,53 @@
}
base.group = function(walls, collections, side){
var collection = collections[side]
- var wall
var useX = side & FRONT_BACK
- var useA = side & (FRONT | RIGHT)
+ var useA = side & (FRONT | LEFT)
// collection.sort( useX ? sort.compare_zx : sort.compare_xz )
+ var planes = {}
+
collection.forEach(function(mx){
if (mx.culled) return
- var coplanar = wall && wall.edge == mx.rect[useX ? 'y': 'x'][useA ? 'a': 'b']
-
- if (wall && coplanar) {
- if (useX && wall.vec.b == mx.rect.x.a) {
- wall.vec.b = mx.rect.x.b
- wall.mx.push(mx)
- wall.surface.add(mx.face)
- return
- }
- else if (! useX && wall.vec.b == mx.rect.y.a) {
- wall.vec.b = mx.rect.y.b
- wall.mx.push(mx)
- wall.surface.add(mx.face)
- return
- }
- }
- wall = new Wall ({
- id: base.uid(),
- side: side,
- mx: [ mx ],
- surface: new Surface( mx.face ),
- vec: mx.rect[ useX ? 'x' : 'y' ].clone(),
- edge: mx.rect[ useX ? 'y' : 'x' ][ useA ? 'a' : 'b' ],
- })
- walls.push(wall)
+ var edge = mx.rect[useX ? 'y': 'x'][ useA ? 'a': 'b']
+ planes[edge] = planes[edge] || []
+ planes[edge].push(mx)
})
-
+
+ var edges = _.keys(planes)
+ edges.forEach(function(edge){
+
+ var wall
+
+ planes[edge].forEach(function(mx){
+
+ if (wall) {
+ if (useX && wall.vec.b == mx.rect.x.a) {
+ wall.vec.b = mx.rect.x.b
+ wall.mx.push(mx)
+ wall.surface.add(mx.face)
+ return
+ }
+ else if (! useX && wall.vec.b == mx.rect.y.a) {
+ wall.vec.b = mx.rect.y.b
+ wall.mx.push(mx)
+ wall.surface.add(mx.face)
+ return
+ }
+ }
+ wall = new Wall ({
+ id: base.uid(),
+ side: side,
+ mx: [ mx ],
+ surface: new Surface( mx.face ),
+ vec: mx.rect[ useX ? 'x' : 'y' ].clone(),
+ edge: mx.rect[ useX ? 'y' : 'x' ][ useA ? 'a' : 'b' ],
+ })
+ walls.push(wall)
+ })
+ })
+
return walls
}
diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
index c43ef14..b4a38f8 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
@@ -14,7 +14,7 @@ var Scenery = new function(){
base.add = function(opt){
var scene_media
- switch (media.type) {
+ switch (opt.media.type) {
case 'image':
scene_media = new Scenery.types.image (opt)
break
@@ -74,11 +74,11 @@ var Scenery = new function(){
scenery_data.forEach(function(data){
var wall = Rooms.walls[data.wall_id]
var scene_media = base.add({
+ data: data,
wall: wall,
media: data.media,
id: data.id
})
- scene_media.deserialize(data)
})
}
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
index 46bc0e7..3a2dcc2 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
@@ -62,8 +62,8 @@ Scenery.types.base = Fiber.extend(function(base){
set_wall: function(wall, mx){
this.wall = wall || this.wall
- this.bounds = this.wall.bounds_for(this.media, this.scale)
- this.center = this.wall.center()
+ // this.bounds = this.wall.bounds_for(this.media, this.scale)
+ // this.center = this.wall.center()
},
set_scale: function(scale){
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js
index 99c1810..576242e 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js
@@ -10,7 +10,13 @@ Scenery.types.image = Scenery.types.base.extend(function(base){
this.build()
this.bind()
this.set_wall()
- this.recenter()
+
+ if (opt.data) {
+ this.deserialize(opt.data)
+ }
+ else {
+ this.recenter()
+ }
},
build: function(){
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/video.js b/public/assets/javascripts/rectangles/engine/scenery/types/video.js
index a8df875..0bd5c06 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/video.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/video.js
@@ -10,7 +10,13 @@ Scenery.types.video = Scenery.types.base.extend(function(base){
this.build()
this.bind()
this.set_wall()
- this.recenter()
+
+ if (opt.data) {
+ this.deserialize(opt.data)
+ }
+ else {
+ this.recenter()
+ }
},
build: function(){