Skip to content

Commit

Permalink
Use generic deriving for MinMax!
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-romes committed Oct 18, 2023
1 parent a4d49b8 commit 32bcf0d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
8 changes: 5 additions & 3 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ packages:
-- ~/Developer/vector/vector
-- ~/Developer/vector/vector-stream/
-- ~/Developer/linear-base-fork/
~/Developer/fir/

package dear-imgui
flags: +glfw +vulkan -sdl -opengl3
Expand All @@ -34,9 +35,9 @@ allow-newer:
linear-apecs:*,
typelits-witnesses:*

source-repository-package
type: git
location: https://gitlab.com/sheaf/fir.git
-- source-repository-package
-- type: git
-- location: https://gitlab.com/sheaf/fir.git

source-repository-package
type: git
Expand Down Expand Up @@ -84,3 +85,4 @@ source-repository-package
location: https://github.com/sheaf/packages
subdir: haskus-utils-variant
tag: 8a69e7bc8873c04d5b671271c2dbdf759f405a56

3 changes: 2 additions & 1 deletion games/ghengin-games.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ executable planets-core
ghengin-vulkan,
ghengin-core-indep,
mtl, vector, hsnoise, containers, random, linear-base,
derive-storable, geomancy, vulkan, time, ghengin-geometry
derive-storable, geomancy, vulkan, time, ghengin-geometry,
fir

ghc-options: -dcmm-lint -dstg-lint -dasm-lint -g2 -rtsopts -debug -Wno-partial-type-signatures
cpp-options: -DDEBUG
Expand Down
22 changes: 15 additions & 7 deletions games/planets-core/Planet.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE UndecidableInstances #-}
module Planet where

import qualified Prelude as P
Expand All @@ -19,13 +20,16 @@ import qualified Data.List.NonEmpty as NE

import Ghengin.Core
import Ghengin.Core.Mesh
import Ghengin.Core.Shader () -- instance Syntactic Float
import Geomancy.Vec3

import Game.Geometry.Sphere
import Foreign.Storable.Generic

import qualified FIR
import FIR.AST (FromGenericProduct(..))
import qualified Math.Linear as FIR
import qualified Generics.SOP as SOP

--------------------------------------------------------------------------------
-- * Planet
Expand All @@ -42,14 +46,18 @@ data PlanetSettings = PlanetSettings { resolution :: !Int

data DisplayFace = All | FaceUp | FaceRight deriving Show



data MinMax = MinMax !Float !Float
deriving (P.Eq, Generic, Show, GStorable)
instance FIR.Syntactic MinMax where
type Internal MinMax = FIR.Val (FIR.Struct '[ "min" 'FIR.:-> FIR.Float, "max" 'FIR.:-> FIR.Float ])
toAST (MinMax x y) = FIR.Struct (FIR.Lit x FIR.:& FIR.Lit y FIR.:& FIR.End)
fromAST struct = case (FIR.view @(FIR.Name "min") struct, FIR.view @(FIR.Name "max") struct) of
(FIR.Lit x, FIR.Lit y) -> MinMax x y
_ -> error "impossible"
deriving (P.Eq, Generic, SOP.Generic, Show, GStorable)
deriving FIR.Syntactic via (FromGenericProduct MinMax ["min", "max"])

-- instance FIR.Syntactic MinMax where
-- type Internal MinMax = FIR.Val (FIR.Struct '[ "min" 'FIR.:-> FIR.Float, "max" 'FIR.:-> FIR.Float ])
-- toAST (MinMax x y) = FIR.Struct (FIR.Lit x FIR.:& FIR.Lit y FIR.:& FIR.End)
-- fromAST struct = case (FIR.view @(FIR.Name "min") struct, FIR.view @(FIR.Name "max") struct) of
-- (FIR.Lit x, FIR.Lit y) -> MinMax x y
-- _ -> error "impossible"

newPlanetMesh :: CompatibleVertex '[Vec3, Vec3, Vec3] π
=> RenderPipeline π bs
Expand Down
5 changes: 4 additions & 1 deletion ghengin-core/ghengin-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ library

-- FIR re-exports, so people can import FIR without depending on fir (it's
-- already a transitive dependency, we simply make it easier to access)
reexported-modules: FIR, Math.Linear, Math.Quaternion
reexported-modules: FIR, Math.Linear, Math.Quaternion,
-- generics-sop, for deriving generically
Generics.SOP

hs-source-dirs: ghengin-core

Expand All @@ -127,6 +129,7 @@ library
containers,
mtl,
vector,
generics-sop,

gl-block,

Expand Down

0 comments on commit 32bcf0d

Please sign in to comment.