### Author Topic: Problem with the maximum number of 3D objects.  (Read 1860 times)

#### SnooPI

• Dr. Type
• Posts: 365
##### Problem with the maximum number of 3D objects.
« on: 2019-Feb-18 »
Normally, GENX_OBJ() only returns -1 if there is not enough memory but that is not the case.
It seems that GLBASIC don't allow more than 4096 3d object.

------
EDIT
------
In fact, the GENX_OBJ()  function gives 4095 at the beginning and decreases with each call, it has nothing to do with the memory, this function is probably just in relation to a memory array of 4096.
It is very restrictive that the maximum number of objects is not related to the available memory (as the help says), but only with a precalculated memory array, because a 3D world can often contain more than 4096 objects
« Last Edit: 2019-Feb-19 by Snoopy »

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1640
• Particle Hawk
##### Re: Problem with the maximum number of 3D objects.
« Reply #1 on: 2019-Feb-19 »
actually its 4224=4096+128 objects, but whos counting anyways? lol

i realize this defeats the purpose of having no extra files to load, yet...
u can reuse object ID numbers, and can save infinite amounts of objects to drive.

Code: (glbasic) [Select]
`INC num, 1 ////etc etc etcCreateCube(num, sz)// ------------------------------------------------------------- //// -=#  CREATECUBE_NO_TEXTURE: Fast but without texture  #=-// ------------------------------------------------------------- //FUNCTION CreateCube_no_texture:  num, sz // Diese Variablen sind als LOCAL definiert: // num, sz, // 2-4-3-1 // | | | | // 6-8-7-5 //   | | //   6-5 //   | | //   2-1 //   | | //   4-3 Strip: 4 3 8 7 5 3 1 4 2 8 6 5 2 1 // Normals + culling is wrong!!LOCAL s[], n, m, x,y,z DIM s[14] s[0]=4; s[1]=3; s[2]=8; s[3]=7; s[4]=5 s[5]=3; s[6]=1; s[7]=4; s[8]=2; s[9]=8 s[10]=6;s[11]=5;s[12]=2;s[13]=1 X_OBJSTART 0 FOR m=0 TO 13 n=s[m]-1 x = MOD(n, 2) y = 1-INTEGER(n/4) z = 1-MOD(INTEGER(n/2), 2) X_OBJADDVERTEX  x-.5, y-.5, z-.5, 0, 0, RGB(255,255,255) NEXT X_OBJEND X_SAVEOBJ "Filename" + num + ".png", 0ENDFUNCTION`
« Last Edit: 2019-Feb-19 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

#### SnooPI

• Dr. Type
• Posts: 365
##### Re: Problem with the maximum number of 3D objects.
« Reply #2 on: 2019-Feb-19 »
Hmm, I think you didn't understand the problem, but perhaps I'm poorly explained.
While you were answering me I wrote a modification in my first message, maybe it's clearer no?

If you exceed the number of 4096 objects in your program, your program crashes completely.
« Last Edit: 2019-Feb-19 by Snoopy »

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1640
• Particle Hawk
##### Re: Problem with the maximum number of 3D objects.
« Reply #3 on: 2019-Feb-19 »
ye, sounds like an array crash
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

#### SnooPI

• Dr. Type
• Posts: 365
##### Re: Problem with the maximum number of 3D objects.
« Reply #4 on: 2019-Feb-19 »
Yes

By cons, you are right in my test program it's not 4096 but 4224 the max

I'm going to bed, this bug gives me a headache

Thank You Hemlos.

« Last Edit: 2019-Feb-19 by Snoopy »

#### spacefractal

• Community Developer
• Prof. Inline
• Posts: 3926
##### Re: Problem with the maximum number of 3D objects.
« Reply #5 on: 2019-Feb-19 »
confirmed.

howover if you have access to the source code and download it. Not sure why Gernot limit it, since its could been higher. its currectly limited to 4096. If you ask me, this should been possible to change to whatever limit, so its a array issue.

But if you have download the source code, you can change this line in the file rainbows3d.h to a higher value:

#define GLR_MAX_OBJECTS      0x1000

0x1000 is set to extractly 4096 and not sure its possible to REDIM it.

Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

#### SnooPI

• Dr. Type
• Posts: 365
##### Re: Problem with the maximum number of 3D objects.
« Reply #6 on: 2019-Feb-19 »
Indeed, recompiling the source code could be a good idea, but my code will not be portable from one version to another
Moreover, it's unfortunate that memory allocations are static and not dynamic (no difference between a cube or a complex object) and I guess it's the same for all other resources: sprites, sounds, ...

For now I think I will dynamically allocate / deallocate objects in real time in my program (trying not to have too much slowdown).

Thanks for the confirmation Spacefractal.

#### spacefractal

• Community Developer
• Prof. Inline
• Posts: 3926
##### Re: Problem with the maximum number of 3D objects.
« Reply #7 on: 2019-Feb-19 »
There is a _build.bat for every platform, which will compile the whole platform. Then done then you can build as normal. There is a limit of 4096 objects in this case, but would been nice if you can set it  to any number by your self. but for now, this is the way for go.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10746
• here on my island the sea says 'hello'
##### Re: Problem with the maximum number of 3D objects.
« Reply #8 on: 2019-Feb-28 »
You need more than 4000 different 3D objects? Really?

#### SnooPI

• Dr. Type
• Posts: 365
##### Re: Problem with the maximum number of 3D objects.
« Reply #9 on: 2019-Mar-01 »
Yes, it's not so strange

Here are some reasons:
1 / We can only assign one texture per object (it's also a problem for the lightmapping).
2 / You have implemented a frustrum optimization by object (thanks, needless to do it), so it's interesting for speed.
3 / For example, games like Minecraft require a lot of objects.
4 / Moreover, what is important for the speed (and the memory) in Opengl is not the number of objects but the complexity of each object.

But rest assured, on the maps where I need more, I will assign them on the fly (I hope without much slowdown).

Thank you for your interest and long life to GLB on Steam

--- EDIT ---

Hmm ... after Gernot's intervention, I thought about it and maybe I was wrong.
I'm looking for too much speed, I'll see my algorithm again tomorrow.

Thank you Gernot you helped me without even answering me
« Last Edit: 2019-Mar-01 by Snoopy »

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10746
• here on my island the sea says 'hello'
##### Re: Problem with the maximum number of 3D objects.
« Reply #10 on: 2019-Mar-09 »
You don't need a separate object if you want to switch the texture.

#### SnooPI

• Dr. Type
• Posts: 365
##### Re: Problem with the maximum number of 3D objects.
« Reply #11 on: 2019-Mar-12 »
Yes, of course, but not the coordinates of the texture, as I have said, it's a problem for the lightmapping.
- different objects.
- similar objects but with different texture coordinates.
- but also similar objects with the same texture coordinates ... it's stupid  (especially for the low speed gained during the display).

I take this topic to ask you if one day the problem to make a lightmapping will be solved?
In summary, the possibility to assign multiple textures with different coordinates on the same object.
I think the lightmapping is important in a 3D game for a good rendering without asking the GPU too much (especially on mobile).

#### spacefractal

• Community Developer
• Prof. Inline
• Posts: 3926
##### Re: Problem with the maximum number of 3D objects.
« Reply #12 on: 2019-Mar-12 »
Snoopy, can you use the source code. its a easy fix with the total number objects really. Its can been happens more than 4096 is required throught if speed is not a issue.

Just change the define and rebuild it with the platforms _build.bat and then you can have more than 4096 objects.