tcod-haskell-0.1.0.0: Bindings to libtcod roguelike engine

Safe HaskellNone
LanguageHaskell2010

Game.TCOD.BSP

Description

This toolkit allows one to create and manipulate 2D Binary Space Partition trees. They can be used to split a rectangular region into non overlapping sub-regions.

Synopsis

Documentation

data BSP Source #

Data for BSP of map

Constructors

BSP 

Fields

Instances

Eq BSP Source # 

Methods

(==) :: BSP -> BSP -> Bool #

(/=) :: BSP -> BSP -> Bool #

Show BSP Source # 

Methods

showsPrec :: Int -> BSP -> ShowS #

show :: BSP -> String #

showList :: [BSP] -> ShowS #

Generic BSP Source # 

Associated Types

type Rep BSP :: * -> * #

Methods

from :: BSP -> Rep BSP x #

to :: Rep BSP x -> BSP #

Storable BSP Source # 

Methods

sizeOf :: BSP -> Int #

alignment :: BSP -> Int #

peekElemOff :: Ptr BSP -> Int -> IO BSP #

pokeElemOff :: Ptr BSP -> Int -> BSP -> IO () #

peekByteOff :: Ptr b -> Int -> IO BSP #

pokeByteOff :: Ptr b -> Int -> BSP -> IO () #

peek :: Ptr BSP -> IO BSP #

poke :: Ptr BSP -> BSP -> IO () #

type Rep BSP Source # 

type BSPCallback = BSP -> IO Bool Source #

Callback for BSP traversal

bspNew :: IO BSP Source #

Creating the root node

First, you have to create the root node of the tree. This node encompasses the whole rectangular region.

bspNewWithSize Source #

Arguments

:: Int

x Top left corner position and size of the rectangular region covered by the BSP tree.

-> Int

y

-> Int

w

-> Int

h

-> IO BSP 

Creating the root node

First, you have to create the root node of the tree. This node encompasses the whole rectangular region.

bspDelete :: BSP -> IO () Source #

Destroy BSP and all subtrees

bspLeft :: BSP -> IO (Maybe BSP) Source #

Get left subtree

bspRight :: BSP -> IO (Maybe BSP) Source #

Get right subtree

bspFather :: BSP -> IO (Maybe BSP) Source #

Get parent subtree

bspIsLeaf :: BSP -> IO Bool Source #

You can know if a node is a leaf (not split, no sons) with this function

bspTraversePreOrder Source #

Arguments

:: BSP

node

-> BSPCallback 
-> IO Bool 

Traversing the tree

You can scan all the nodes of the tree and have a custom function called back for each node. Each traversal function returns false if the traversal has been interrupted (a callback returned false).

Pre-order : the callback is called for the current node, then for the left son, then for the right son.

bspTraverseInOrder Source #

Arguments

:: BSP

node

-> BSPCallback 
-> IO Bool 

Traversing the tree

You can scan all the nodes of the tree and have a custom function called back for each node. Each traversal function returns false if the traversal has been interrupted (a callback returned false).

In-order : the callback is called for the left son, then for current node, then for the right son.

bspTraversePostOrder Source #

Arguments

:: BSP

node

-> BSPCallback 
-> IO Bool 

Traversing the tree

You can scan all the nodes of the tree and have a custom function called back for each node. Each traversal function returns false if the traversal has been interrupted (a callback returned false).

Post-order : the callback is called for the left son, then for the right son, then for the current node.

bspTraverseLevelOrder Source #

Arguments

:: BSP

node

-> BSPCallback 
-> IO Bool 

Traversing the tree

You can scan all the nodes of the tree and have a custom function called back for each node. Each traversal function returns false if the traversal has been interrupted (a callback returned false).

Level-order : the callback is called for the nodes level by level, from left to right.

bspTraverseInvertedLevelOrder Source #

Arguments

:: BSP

node

-> BSPCallback 
-> IO Bool 

Traversing the tree

You can scan all the nodes of the tree and have a custom function called back for each node. Each traversal function returns false if the traversal has been interrupted (a callback returned false).

Inverted level-order : the callback is called in the exact inverse order as Level-order.

bspContains Source #

Arguments

:: BSP 
-> Int

x

-> Int

y

-> IO Bool 

Check if a cell is inside a node

bspFindNode Source #

Arguments

:: BSP 
-> Int

x

-> Int

y

-> IO (Maybe BSP) 

Getting the node containing a cell

bspResize Source #

Arguments

:: BSP 
-> Int

x

-> Int

y

-> Int

w

-> Int

h

-> IO () 

This operation resets the size of the tree nodes without changing the splitting data (orientation/position). It should be called with the initial region size or a bigger size, else some splitting position may be out of the region.

You can use it if you changed the nodes size and position while using the BSP tree, which happens typically when you use the tree to build a dungeon. You create rooms inside the tree leafs, then shrink the leaf to fit the room size. Calling resize on the root node with the original region size allows you to reset all nodes to their original size.

bspSplitOnce Source #

Arguments

:: BSP 
-> Bool

horizontal?

-> Int

position

-> IO () 

Splitting a node once

Once you have the root node, you can split it into two smaller non-overlapping nodes.

bspSplitRecursive Source #

Arguments

:: BSP 
-> TCODRandom

randomize algorithm

-> Int

Number of recursion levels.

-> Int

min h size. Minimum values of w and h for a node. A node is split only if the resulting sub-nodes are bigger than minHSize x minVSize

-> Int

min v size

-> Float

max h ratio. Maximum values of wh and hw for a node. If a node does not conform, the splitting orientation is forced to reduce either the wh or the hw ratio. Use values near 1.0 to promote square nodes.

-> Float

max v ratio

-> IO () 

Recursively splitting a node

You can also recursively split the bsp. At each step, a random orientation (horizontal/vertical) and position are chosen

bspRemoveSons :: BSP -> IO () Source #

Deleting a part of the tree

You can delete a part of the tree, releasing resources for all sub nodes with