Advertisement

Game engine in C and open source, The Box, structural programming

Started by December 22, 2019 10:49 AM
129 comments, last by alex4 4 years, 8 months ago
Advertisement

Some asked in another topic how to automate models it was something i was thinking in to implement models by code.


Attempting to doing something like that, create models with code, so we don't need complex functionality. The code will do that for us.

It will probably something easy to do.

Was thinking in a example: let's say we create adjust points, so a base of the foot have 2 curves, 2 lines, adjusting them we create different types. based on this we can apply to the rest parts of the body. Adding adjusting points.

Then it's probably a thing of create a average set of points, for a lady style it have x proportions, for a male z proportions, etc…

the lady have hips + 20% then male, male + 20% musculus, click and it's done.

For a car, let's say wheels, 2 circles, +1 inside for rims. In this probably the adjusting point is where it bends. Adjust click auto generate wheels.

Once we store the proportions then we can automate stuff. We know that top curve have x proportions. All human foots will be more or less like that…

It have a higher bend in one way… probably a percentage or some kind of math for that.

Once we do this for the rest of the body, we can adjust all parts. Then we need a some kind of proportion variable. So it adjusts more or less width the stuff we are doing.

the proportion is a min and a max, lets say that the top line can't be more then 30%, so it keeps the correct bend for that line.

Don't know if we can lather generate a full algorithm, for types, not a big expert in math. That was the original concept with a couple of variables, configure the model and generate.

Was thinking a bit on the planning and added the concept of layers objects (layer.h).

Since many things use layers, it could reuse a large amount of things. If we put layers in a separated part or object.

like :

Colors : color and the alpha channel, they could stack

Textures on 3D models

3D models in 3D models.

Many things use layers, but we still don't “decopulate” in to it's own object.

Our steps are :

window - it does not inherit layers
layers
control - it inherit layers
color - it inherit layers
interface - it inherit layers, and color
3D/2D - it inherit layers, and color

Advertisement

The Box Version 0.0.2

Still it does not have that much work that i wanted but is the possible work. The file have like 30 pages. It should have every thing you need to understand and develop. It explain: interfaces, code, objects, objectives, tools, tutorials, planning, etc…

2 PDF, and the box folder :

You should have access to the public folder

https://drive.google.com/drive/u/1/folders/1LqXNvuu5p5t7cQ4yH-7YEqugL7glslMk

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.

Tutorial on code design and how the code is looking like :

Code refactor on Lips of Luna

The refactor of code does not seem that hard once we have the planning, was able to refactor high amount of code. Doing like this: first remove all dependency and leave only procedural code, “leave notes in case we want to know what is going on lather” do not remove libraries because on 2º stage we are going to need to get that extra code from the dependency's.

Object planning

Object planning this is already on the internet i din't invent it, the theory : “if a object is doing to much is bad and is if bad doing to little. So a object should deal with a set of functions in a proper way". For example Lips 3D model load first file is ok in therms of planning but the 2º part i called in this example : ”open model" and “load of model”, in this case is load of model, there are several files scattered with 50 lines which, in this case is doing to little.

I will convert them in to the “load model”, to deal with materials, particles, etc…

Code

Is more advanced then my PHP engine, it was only one layer, or two layers. In here we have several layers, and inheritance.

I usely put all variables on top to be more readable, but in here since we may reuse variables, putting them above the include, for now putting the settings in if and else, if need some kind of setting from file is just a matter of setting to true. “files_list = 1; // true”

to refactor functions, it transform them in a if with a true state, to use e need to set it to true.

But still have to see what will be the better design.

Dynamic functions

For now setting all to file object non dynamic, lather when it evolves if procedural can't handle it i will create a “system object” to pass things to procedural or handle the parts procedural can't.

A bit like PHP : it uses procedural based on a Object, or a set of objects.

How the code looks:

#include variables.h
#mouse.h
#keys.h

language = "PT";
#include language.c

operating_system = "windows";
#include settings.c

mouse_arrow = "costume arrow";
#include mouse.c

keyboard_esq = "jump";
#include keys.c

//Concatenate

#include path.c //Open directorys

folders = {"", "c:/the_box/projects/models", "c:/the_box/projects/images"};
folders_index = {"models", "images"};
files_list = 1; // true
directory_list = 1; // true

#include open_folders.c // open folder

images = {"image1.jpg", "image2.jpg"};
images_index = {"menu_button", "menu_effect"};
#include jpg.c

models = {"model1.3D", "model2.3D"};
models_index = {"character", "character2"};
#include open_models.c // models open

3D_low_poly;

#include load_models.c

window_height = 400;
window_width = 400;

#include window.c

control_height = 400;
control_width = 400;

#include control.c

text_style = "liberation serif";
text_color = "black";

property_background = "white";
property_menu;

property_buttons = {"button1", "button2", "button3"};

property_button;

#include interface.c

draw_menu;
draw_map;
draw_models;

#include draw.c

@trsh What do you use github for?

@hermetix

@domarius

Ya Godot is nice, i'm aware of all of those engines.

The engine is not just the engine if you read the version 0.0.2 PDF have much more to it. Automate many tasks, create free market and open social tools.

Creating all this tools and not having a costume code to do it sound a bit strange…

And all that code open source, is good so that we can refactor code, starting from zero and not having all that code, that will be a very hard task. But if i can study their code think is a bit easy.

This topic is closed to new replies.

Advertisement