LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_landscape.c File Reference

Functions

LG_QTNode lg_qtnode (int id, const char *name, Rec2Df *bounds, void *data)
 
void lg_qtnode_add_child (LG_QTNode *node, LG_QTNode *child, int quadrant)
 
LG_QTNodelg_qtnode_get_root (LG_QTNode *node)
 
void lg_add_scenenode_from_qtnode (LG_SceneNode *top_scene_node, LG_QTNode *qt_node)
 
void lg_traverse_landscape (LG_QTNode *node, int(*func)(LG_QTNode *))
 
void lg_traverse_printout_landscape (LG_QTNode *node, zboolean extra_info)
 
void lg_qtnode_info (LG_QTNode *node)
 
int lg_qtnode_info2 (LG_QTNode *node)
 

Detailed Description

=== It's all about tiling, terrains, quadtrees, LOD stuff, bla bla ===

LG_QTNode = LG QuadTree Node

QuadTree quadrants: LG_NW (0), LG_NE (1), LG_SW (2), LG_SE (3)

struct LG_QTNode {
int id; // User-defined
char name[QUADTREE_NAME_MAX_LEN + 1];
LG_QTNode *parent;
LG_QTNode *child[4]; // NW, NE, SW, SE
Rec2Df bounds; // Or bounding_r - actually bounding square, ie w = h
zboolean is_leaf;
void *data; // Terrain, tile, mesh, object, ...
};

Function Documentation

◆ lg_qtnode()

LG_QTNode lg_qtnode ( int  id,
const char *  name,
Rec2Df bounds,
void *  data 
)

Create a new landscape node (LG_QTNode)

If no bounding rectangle is provided (bounds == NULL), default one is {-1.0, -1.0, 2.0, 2.0}

No need to free anything when done (no dynamically allocated memory)

Parameters
idNode's id
nameNode's name
boundsA pointer to a bounding rectangle (actually must be a square) , may be NULL
dataA pointer to data (terrain tile, mesh, whatever ...)
Returns
A LG_QTNode

◆ lg_qtnode_add_child()

void lg_qtnode_add_child ( LG_QTNode node,
LG_QTNode child,
int  quadrant 
)

Add child node to landscape node

WARNING: node == child, or adding twice the same node, will lead to undefined behaviour

Parameters
nodeA pointer to a LG_QTNode
childA pointer to a LG_QTNode
quadrantOne of LG_NW, LG_NE, LG_SW, LG_SE (lg_quadrant)

◆ lg_qtnode_get_root()

LG_QTNode* lg_qtnode_get_root ( LG_QTNode node)

Get the root node

Parameters
nodeA pointer to a LG_QTNode
Returns
The root LG_QTNode if OK, NULL on error

◆ lg_add_scenenode_from_qtnode()

void lg_add_scenenode_from_qtnode ( LG_SceneNode top_scene_node,
LG_QTNode qt_node 
)

Parse a quad tree and create/add a scene node for each leaf (to the top scene node)

Scene node id = QT node id + QUADTREE_TO_SCENENODE_ID_SHIFT

Parameters
top_scene_nodeA pointer to a LG_SceneNode
qt_nodeA pointer to a LG_QTNode

◆ lg_traverse_landscape()

void lg_traverse_landscape ( LG_QTNode node,
int(*)(LG_QTNode *)  func 
)

Go from top to bottom, starting at node (may be different from the top node)

Call (*func)(node) for each leaf

Parameters
nodeA pointer to a LG_QTNode
funcA func pointer

◆ lg_traverse_printout_landscape()

void lg_traverse_printout_landscape ( LG_QTNode node,
zboolean  extra_info 
)

Go from top to bottom

Print out quad tree structure (quite nicely) -> node->name (node->id)

Parameters
nodeA pointer to a LG_QTNode
extra_infoIf TRUE, print out extra info (node->id so far)

◆ lg_qtnode_info()

void lg_qtnode_info ( LG_QTNode node)

Print out LG_QTNode info

Parameters
nodeA pointer to a LG_QTNode

◆ lg_qtnode_info2()

int lg_qtnode_info2 ( LG_QTNode node)

Print out LG_QTNode info

Same as above func but returns (int)0, so suitable to use with lg_traverse_landscape()

Parameters
nodeA pointer to a LG_QTNode
Rec2Df
Definition: lg_gr_func.h:54
LG_QTNode
Definition: lg_landscape.h:29