Update
Missed a small thing, how to convert code to procedural to use with the global objects.
Think the theory of structural programming could also be called stack programming, or have a stack part in it, because we do things by stacks.
In this example we are going to see a stack.
In this function from Lips of Luna, nodes for 3D models. How to covert it to procedural code:
LIMdlModel* limdl_model_new_copy (
const LIMdlModel* model,int shape_keys)
{
int i;
LIMdlModel* self;
self = lisys_calloc (1, sizeof (LIMdlModel));
if (self == NULL)
return NULL;
self->flags = model->flags;
self->bounds = model->bounds;
if (model->hairs.count)
{
self->hairs.array = lisys_calloc (model->hairs.count, sizeof (LIMdlHairs));
self->hairs.count = model->hairs.count;
for (i = 0 ; i < model->hairs.count ; i++)
limdl_hairs_init_copy (self->hairs.array + i, model->hairs.array + i);
}
if (model->lod.count)
{
self->lod.array = lisys_calloc (model->lod.count, sizeof (LIMdlLod));
self->lod.count = model->lod.count;
for (i = 0 ; i < model->lod.count ; i++)
limdl_lod_init_copy (self->lod.array + i, model->lod.array + i);
}
if (model->materials.count)
{
self->materials.array = lisys_calloc (model->materials.count, sizeof (LIMdlMaterial));
self->materials.count = model->materials.count;
for (i = 0 ; i < model->materials.count ; i++)
limdl_material_init_copy (self->materials.array + i, model->materials.array + i);
}
if (model->nodes.count)
{
self->nodes.array = lisys_calloc (model->nodes.count, sizeof (LIMdlNode*));
self->nodes.count = model->nodes.count;
for (i = 0 ; i < model->nodes.count ; i++)
self->nodes.array[i] = limdl_node_copy (model->nodes.array[i], 1);
}
The node.c file which will be kind of a stack if it works in C, didn't test it. This how i do it in PHP.
#include model.h / global variables on models
#include draw.h
models = “model1, model2, model3” // models to load
#include node.c
----------Start node.c----------------
while (models != not empty)
{
for (i = 0 ; i < model->materials.count ; i++)
{
limdl_material_init_copy (self->materials.array + i, model->materials.array + i);
}
for (i = 0 ; i < model->nodes.count ; i++)
self->nodes.array[i] = limdl_node_copy (model->nodes.array[i], 1);
}
}
---------end file----------
models_array // loaded models
#include draw.c // draw the models
the global variable should have the models loaded after the include of the file. The file is only procedural code. and is very fast. and very easy to read.