+ Created function for generating a reproducable seed out of user code but it fails inside the web-worker

This commit is contained in:
Dominik Maier 2014-05-13 04:18:56 +02:00
parent 2807e83672
commit efa39ffcd9

View file

@ -31,9 +31,17 @@ module.exports = class World
@systemMap = {}
@scriptNotes = []
# We want a seed thats not always 0 yet reproducable.
@rand = new Rand @hashString(JSON.stringify @userCodeMap)
console.log "Seed: ", @getSeed()
@rand = new Rand @getSeed()
@frames = [new WorldFrame(@, 0)]
getSeed: ->
return 0 unless @userCodeMap #TODO: When does this happen?
#Packs all methods in all thangs in one big array, then sorts and joins them. Then returns a hash value of the result.
@hashString((methods for thangID, methods of @userCodeMap).reduce(((ret, methods) ->
(method for methodID, method of methods).reduce(((ret, method) -> ret.push(method)), ret)
), []).sort().join())
getFrame: (frameIndex) ->
# Optimize it a bit--assume we have all if @ended and are at the previous frame otherwise
frames = @frames