Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed timestep and parse the initial spawn point from the entities lump
- Loading branch information
Showing
11 changed files
with
328 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{-# language FlexibleContexts #-} | ||
{-# language OverloadedStrings #-} | ||
|
||
module Quake3.BSP.Entities | ||
( EntityProperties | ||
, getInt | ||
, getIntV3 | ||
, getText | ||
, parseEntityDefinitions | ||
) where | ||
|
||
-- base | ||
import Control.Applicative ( liftA2, many ) | ||
import Data.Void ( Void ) | ||
import Text.Read ( readMaybe ) | ||
|
||
-- containers | ||
import qualified Data.Map.Strict as Map | ||
|
||
-- linear | ||
import Linear ( V3(..) ) | ||
|
||
-- megaparsec | ||
import qualified Text.Megaparsec as Megaparsec | ||
import qualified Text.Megaparsec.Char as Megaparsec | ||
import qualified Text.Megaparsec.Char.Lexer as Megaparsec hiding ( space ) | ||
|
||
-- text | ||
import qualified Data.Text as StrictText | ||
|
||
|
||
newtype EntityProperties = | ||
EntityProperties ( Map.Map StrictText.Text StrictText.Text ) | ||
deriving ( Show ) | ||
|
||
|
||
getInt :: StrictText.Text -> EntityProperties -> Maybe Int | ||
getInt key ( EntityProperties m ) = | ||
fmap StrictText.unpack ( Map.lookup key m ) | ||
>>= readMaybe | ||
|
||
|
||
getIntV3 :: StrictText.Text -> EntityProperties -> Maybe ( V3 Int ) | ||
getIntV3 key ( EntityProperties m ) = do | ||
[ x, z, y ] <- | ||
fmap ( words . StrictText.unpack ) ( Map.lookup key m ) | ||
|
||
traverse readMaybe ( V3 x y z ) | ||
|
||
|
||
getText :: StrictText.Text -> EntityProperties -> Maybe StrictText.Text | ||
getText key ( EntityProperties m ) = | ||
Map.lookup key m | ||
|
||
|
||
parseEntityDefinitions | ||
:: StrictText.Text | ||
-> Either ( Megaparsec.ParseError Char Void ) [ EntityProperties ] | ||
parseEntityDefinitions = | ||
Megaparsec.parse parser "(entities)" | ||
|
||
|
||
parser | ||
:: Megaparsec.MonadParsec e StrictText.Text m | ||
=> m [ EntityProperties ] | ||
parser = | ||
many entityDefinition <* Megaparsec.eof | ||
|
||
|
||
entityDefinition | ||
:: Megaparsec.MonadParsec e StrictText.Text m | ||
=> m EntityProperties | ||
entityDefinition = | ||
EntityProperties | ||
<$> | ||
Megaparsec.between | ||
( symbol "{" ) | ||
( symbol "}" ) | ||
( fmap | ||
Map.fromList | ||
( Megaparsec.many ( liftA2 (,) quotedString quotedString ) ) | ||
) | ||
|
||
|
||
quotedString | ||
:: Megaparsec.MonadParsec e StrictText.Text m | ||
=> m StrictText.Text | ||
quotedString = | ||
symbol "\"" | ||
*> fmap StrictText.pack ( many ( Megaparsec.satisfy ( /= '"' ) ) ) | ||
<* symbol "\"" | ||
|
||
|
||
space | ||
:: Megaparsec.MonadParsec e StrictText.Text m | ||
=> m () | ||
space = | ||
Megaparsec.space | ||
|
||
|
||
symbol | ||
:: Megaparsec.MonadParsec e StrictText.Text m | ||
=> StrictText.Text -> m StrictText.Text | ||
symbol = | ||
Megaparsec.symbol space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{-# language DeriveGeneric #-} | ||
|
||
module Quake3.Entity ( Entity(..), parseEntity ) where | ||
|
||
-- base | ||
import GHC.Generics ( Generic ) | ||
|
||
-- zero-to-quake3 | ||
import qualified Quake3.BSP.Entities | ||
import qualified Quake3.Entity.InfoPlayerDeathmatch | ||
|
||
data Entity | ||
= InfoPlayerDeathmatch Quake3.Entity.InfoPlayerDeathmatch.InfoPlayerDeathmatch | ||
| Other | ||
deriving ( Generic, Show ) | ||
|
||
|
||
parseEntity | ||
:: Quake3.BSP.Entities.EntityProperties | ||
-> Maybe Entity | ||
parseEntity props = | ||
InfoPlayerDeathmatch <$> Quake3.Entity.InfoPlayerDeathmatch.parse props |
Oops, something went wrong.