1000 entities VS 1000 materials

Posted By: Lion_Ts

1000 entities VS 1000 materials - 10/01/05 11:29

Hi!
This is small contrib about pointers.
If you didn't work with C or C++ you can mess one powerfull (but not fully implemented in C-script, where is C-lite ?!) thing - pointers.
In C-script you can use predefined pointer types (refer to 3dgs manual).
One example from Ulillillia (he says it's working, but he want to hard test it ):
You have many objects, you have materials for each, material properties assigned from object's skills... But number of objects is 1000
Simple solution to save your fingers is:
Code:

material* mymtl; //define material pointer
...
action myobj{
mymtl=mtl_create(); //create temp material
//copy standard model material to temp material
vec_set(mymtl.ambient_blue, mat_model.ambient_blue);
vec_set(mymtl.emissive_blue, mat_model.emissive_blue);
vec_set(mymtl.diffuse_blue, mat_model.diffuse_blue);
vec_set(mymtl.specular_blue, mat_model.specular_blue);
mymtl.power=mat_model.power;
mymtl.alpha=mat_model.alpha;
mymtl.albedo=mat_model.albedo;
//change needed values from skills or random generator or whatever else
mymtl.ambient_red=random(255);
mymtl.specular_blue=my.skill5;
//assign temp material to object
my.material=mymtl;
...
}


With this small snippet you have not to define 1000 materials in code
Posted By: nkl

Re: 1000 entities VS 1000 materials - 10/01/05 13:40

Hi.
Your code is very useful.
After I create 1000 materials.
How do I remove an unused materials pointer?
Thanks for your advance.
Thanks already.
Posted By: Helghast

Re: 1000 entities VS 1000 materials - 10/01/05 14:38

using ptr_for_handle...
Posted By: Lion_Ts

Re: 1000 entities VS 1000 materials - 10/01/05 19:55

Quote:

using ptr_for_handle...



Tell about it more, please.
I don't know how to release materials, bmaps, panels and so on. It's not described in the manual. And as described in the manual:
Quote:


handle (object);
Returns a handle of an object. A handle is a unique number that can be assigned to any variable, and identifies that object. The object can be an entity, an action, a string, a bmap, a panel, or a pointer to them.
Parameters:
object - Entity, Action, String, Bitmap, Panel or Pointer of an object




Material's pointers in the manual described very short...
Can you tell your idea ?
Posted By: ulillillia

Re: 1000 entities VS 1000 materials - 10/01/05 23:19

Actually, the version I have is shorter - useful for multi-colored things:

Code:

material* platform_colors;

// unrelated defines go here
define base_red, skill16;
define base_green, skill17;
define base_blue, skill18;
define base_alpha, skill19;

//uses: base_red, base_green, base_blue, base_alpha
action platforms
{
platform_colors = mtl_create();
platform_colors.ambient_red = my.skill16;
platform_colors.ambient_green = my.skill17;
platform_colors.ambient_blue = my.skill18;

if (my.skill19 != 0)
{
my.transparent = on;
my.alpha = my.skill19*100/255;
}
}



For best use, have a white texture with any decals on it. Then, set the color through the skills. Alpha is based on 0 to 255, as it's supposed to be. 8-bit means from 0-255, not 0-100 (I hate the 0-100 method - it means lots of guessing).

To set the color to a bright orange, set skill16 to 255, skill17 to 160, and skill18 to 64. For an alpha of 160, set skill19 to 160 to get 5/8 visible. This is a good technique for lights (models) without using any dynamic lights.
Posted By: Anonymous

Re: 1000 entities VS 1000 materials - 10/02/05 01:24

I heard you can get unlimited skills (local variables) for each object with C++, do you know how to do that too?
Posted By: nkl

Re: 1000 entities VS 1000 materials - 10/02/05 04:41

Hi
It is because A6 manual describe Material's pointers very shortly.
I don't know how to release materials, bmaps, panels and so on. It's not described in the manual. And as described in the manual:
Would you tell me more about using ptr_for_handle for release a mtl_create() materials, please?
Thanks for any advance!
Posted By: Lion_Ts

Re: 1000 entities VS 1000 materials - 10/02/05 21:20

Sorry for "panels, bmaps and so on...". But about materials it's truth.
Posted By: Lion_Ts

Re: 1000 entities VS 1000 materials - 10/02/05 23:38

For noobs like me:
no command like 'mtl_remove' in the manual. If you create material with mtl_create and forget assign it to entity, you'll have engine crash after level reload (engine don't deallocate your material). Materials, assigned to entities, deallocates automatically by engine (with level_load() or exit() ). I tested it with 200000 materials, all ok. One footprint: with big number of materials (even unassigned to entities or assigned to invisible static entities) you have bad FPS (big time for entity updates)
© 2023 lite-C Forums