<commit_before>-----------------------------------------------------------------------------
-- |
-- Copyright   : (C) 2014 <NAME>
-- License     : BSD3
--
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : portable
--
----------------------------------------------------------------------------

module Photon.Photon (
    -- *
  ) where

import Control.Lens
import Control.Monad.Trans.State ( StateT )
import Photon.Core.Effect
import Photon.Core.Light ( Light )
import Photon.Render.OpenGL.State
import Photon.Utils.FreeList ( FreeList )

newtype Photon m a = Photon { runPhoton :: StateT (FreeLists,OpenGLSt) m a }

data FreeLists = FreeLists {
    _flLights    :: FreeList
  , _flMaterials :: FreeList
  , _flMeshes    :: FreeList
  }

makeLenses ''FreeLists

class Manageable a where
  manage :: a -> Photon (Managed a)
  drop :: Managed a -> Photon ()

instance Manageable Light where
  manage a = do
    (h,fl) <- uses (_1.flLights) nextFree
    _1 . flLights .~ fl
    return (Managed (H h) a)
  drop (Managed (H h) _) = _1 . flLights %~ recycleFree h
<commit_msg>Material and Mesh are both Manageable in Photon.<commit_after>-----------------------------------------------------------------------------
-- |
-- Copyright   : (C) 2014 <NAME>
-- License     : BSD3
--
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : experimental
-- Portability : portable
--
----------------------------------------------------------------------------

module Photon.Photon (
    -- *
  ) where

import Control.Lens
import Control.Monad.Trans.State ( StateT )
import Photon.Core.Effect
import Photon.Core.Light ( Light )
import Photon.Render.OpenGL.State
import Photon.Utils.FreeList ( FreeList )

newtype Photon m a = Photon { runPhoton :: StateT (FreeLists,OpenGLSt) m a }

data FreeLists = FreeLists {
    _flLights    :: FreeList
  , _flMaterials :: FreeList
  , _flMeshes    :: FreeList
  }

makeLenses ''FreeLists

class Manageable a where
  manage :: a -> Photon (Managed a)
  drop :: Managed a -> Photon ()

instance Manageable Light where
  manage a = do
    (h,fl) <- uses (_1.flLights) nextFree
    _1 . flLights .~ fl
    return (Managed (H h) a)
  drop (Managed (H h) _) = _1 . flLights %~ recycleFree h

instance Manageable Material where
  manage a = do
    (h,fl) <- uses (_1.flMaterials) nextFree
    _1 . flMaterials .~ fl
    return (Managed (H h) a)
  drop (Managed (H h) _) = _1 . flMaterials %~ recycleFree h

instance Manageable Mesh where
  manage a = do
    (h,fl) <- uses (_1.flMeshes) nextFree
    _1 . flMeshes .~ fl
    return (Managed (H h) a)
  drop (Managed (H h) _) = _1 . flMeshes %~ recycleFree h

{'fraction_non_alphanumeric': 0.2217620481927711, 'fraction_numerical': 0.008283132530120483, 'mean_word_length': 1.922992299229923, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '312601', 'n_tokens_mistral': 864, 'n_tokens_neox': 836, 'n_words': 247}