Skip to content

Commit

Permalink
+ "Real" predictable random. Seed depends on usercode map.
Browse files Browse the repository at this point in the history
  • Loading branch information
domenukk committed May 13, 2014
1 parent 78a0efa commit 2807e83
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/lib/world/world.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = class World
@systems = []
@systemMap = {}
@scriptNotes = []
@rand = new Rand 0
# We want a seed thats not always 0 yet reproducable.
@rand = new Rand @hashString(JSON.stringify @userCodeMap)
@frames = [new WorldFrame(@, 0)]

getFrame: (frameIndex) ->
Expand Down Expand Up @@ -402,7 +403,7 @@ module.exports = class World
return
@finishDeserializing w, finishedWorldCallback, perf

@finishDeserializing: (w, finishedWorldCallback, perf) =>
@finishDeserializing: (w, finishedWorldCallback, perf) ->
perf.t4 = now()
w.ended = true
w.getFrame(w.totalFrames - 1).restoreState()
Expand Down Expand Up @@ -485,3 +486,7 @@ module.exports = class World
teamForPlayer: (n) ->
playableTeams = @playableTeams ? ['humans']
playableTeams[n % playableTeams.length]

#djb2 algorithm
hashString: (str) ->
(str.charCodeAt i for i in [0...str]).reduce(((hash, char) -> ((hash << 5) + hash) + char), 5381) # hash * 33 + c

0 comments on commit 2807e83

Please sign in to comment.