Skip to content

Commit

Permalink
fix world DSL hash primitive to depend on seed
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Jun 25, 2024
1 parent 3ad94a4 commit b84b4f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/swarm-scenario/Swarm/Game/World/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ compileConst seed = \case
CMask -> compileMask
CSeed -> CConst (fromIntegral seed)
CCoord ax -> CFun $ \(CConst (coordsToLoc -> Location x y)) -> CConst (fromIntegral (case ax of X -> x; Y -> y))
CHash -> compileHash
CHash -> compileHash seed
CPerlin -> compilePerlin
CReflect ax -> compileReflect ax
CRot rot -> compileRot rot
Expand All @@ -94,10 +94,10 @@ compileMask = CFun $ \p -> CFun $ \a -> CFun $ \ix ->
case p $$ ix of
CConst b -> if b then a $$ ix else CConst empty

compileHash :: CTerm (Coords -> Integer)
compileHash = CFun $ \(CConst (Coords ix)) -> CConst (fromIntegral (h ix))
compileHash :: Seed -> CTerm (Coords -> Integer)
compileHash seed = CFun $ \(CConst (Coords ix)) -> CConst (fromIntegral (h ix))
where
h = murmur3 0 . unTagged . from @String @(Encoding.UTF_8 ByteString) . show
h = murmur3 (fromIntegral seed) . unTagged . from @String @(Encoding.UTF_8 ByteString) . show

compilePerlin :: CTerm (Integer -> Integer -> Double -> Double -> World Double)
compilePerlin =
Expand Down
2 changes: 1 addition & 1 deletion src/swarm-scenario/Swarm/Game/World/Interpret.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interpConst seed = \case
CMask -> \b x c -> if b c then x c else empty
CSeed -> fromIntegral seed
CCoord ax -> \(coordsToLoc -> Location x y) -> fromIntegral (case ax of X -> x; Y -> y)
CHash -> \(Coords ix) -> fromIntegral . murmur3 0 . unTagged . from @String @(Encoding.UTF_8 ByteString) . show $ ix
CHash -> \(Coords ix) -> fromIntegral . murmur3 (fromIntegral seed) . unTagged . from @String @(Encoding.UTF_8 ByteString) . show $ ix
CPerlin -> \s o k p ->
let noise = perlin (fromIntegral s) (fromIntegral o) k p
sample (i, j) = noiseValue noise (fromIntegral i / 2, fromIntegral j / 2, 0)
Expand Down

0 comments on commit b84b4f9

Please sign in to comment.