From b934d22cbdd5fb44b14825b369ee6a89c6e6e760 Mon Sep 17 00:00:00 2001 From: Jayant Jain Date: Mon, 14 Jul 2014 01:28:21 +0530 Subject: [PATCH] Batches insertion of thangs to treema to speed up terrain generation --- app/views/editor/level/thangs_tab_view.coffee | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/views/editor/level/thangs_tab_view.coffee b/app/views/editor/level/thangs_tab_view.coffee index e594b00be..304cdab34 100644 --- a/app/views/editor/level/thangs_tab_view.coffee +++ b/app/views/editor/level/thangs_tab_view.coffee @@ -225,9 +225,11 @@ module.exports = class ThangsTabView extends View @editThang thangID: e.thang.id onRandomiseTerrain: (e) -> + @thangsBatch = [] for thang in e.thangs @selectAddThangType thang.id - @addThang @addThangType, thang.pos + @addThang @addThangType, thang.pos, true + @batchInsert() @selectAddThangType null # TODO: figure out a good way to have all Surface clicks and Treema clicks just proxy in one direction, so we can maintain only one way of handling selection and deletion @@ -397,7 +399,11 @@ module.exports = class ThangsTabView extends View id = treema?.data?.id @editThang thangID: id if id - addThang: (thangType, pos) -> + batchInsert: -> + @thangsTreema.set '', @thangsBatch + @thangsBatch = [] + + addThang: (thangType, pos, batchInsert = false) -> thangID = Thang.nextID(thangType.get('name'), @world) until thangID and not @thangsTreema.get "id=#{thangID}" if @cloneSourceThang components = _.cloneDeep @thangsTreema.get "id=#{@cloneSourceThang.id}/components" @@ -408,7 +414,10 @@ module.exports = class ThangsTabView extends View physical = _.find components, (c) -> c.config?.pos? physical.config.pos = x: pos.x, y: pos.y, z: physical.config.pos.z if physical thang = thangType: thangType.get('original'), id: thangID, components: components - @thangsTreema.insert '', thang + if batchInsert + @thangsBatch.push thang + else + @thangsTreema.insert '', thang editThang: (e) -> if e.target # click event