+ "Real" predictable random. Seed depends on usercode map.
This commit is contained in:
parent
78a0efac78
commit
2807e83672
1 changed files with 7 additions and 2 deletions
|
@ -30,7 +30,8 @@ module.exports = class World
|
||||||
@systems = []
|
@systems = []
|
||||||
@systemMap = {}
|
@systemMap = {}
|
||||||
@scriptNotes = []
|
@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)]
|
@frames = [new WorldFrame(@, 0)]
|
||||||
|
|
||||||
getFrame: (frameIndex) ->
|
getFrame: (frameIndex) ->
|
||||||
|
@ -402,7 +403,7 @@ module.exports = class World
|
||||||
return
|
return
|
||||||
@finishDeserializing w, finishedWorldCallback, perf
|
@finishDeserializing w, finishedWorldCallback, perf
|
||||||
|
|
||||||
@finishDeserializing: (w, finishedWorldCallback, perf) =>
|
@finishDeserializing: (w, finishedWorldCallback, perf) ->
|
||||||
perf.t4 = now()
|
perf.t4 = now()
|
||||||
w.ended = true
|
w.ended = true
|
||||||
w.getFrame(w.totalFrames - 1).restoreState()
|
w.getFrame(w.totalFrames - 1).restoreState()
|
||||||
|
@ -485,3 +486,7 @@ module.exports = class World
|
||||||
teamForPlayer: (n) ->
|
teamForPlayer: (n) ->
|
||||||
playableTeams = @playableTeams ? ['humans']
|
playableTeams = @playableTeams ? ['humans']
|
||||||
playableTeams[n % playableTeams.length]
|
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
|
||||||
|
|
Reference in a new issue