Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Quad), 748 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
clear vector()'s #393484
02/03/12 22:23
02/03/12 22:23
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Hi,

Is there a way to clear all vectors made by vector() without wait(1)? I exceed 64 vector() calls easily when using draw_line3d for drawing something. Before throwing my complete code over to an alternative approach, I was hoping to just clear the vector()s so I can call them again.


Click and join the 3dgs irc community!
Room: #3dgs
Re: clear vector()'s [Re: Joozey] #393493
02/04/12 00:03
02/04/12 00:03
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
vector() does not create VECTORs, it simply uses one of 64 pre-allocated VECTORs. I assume it works approximately as follows:

VECTOR _vector[64];
var _vector_current = 0;

VECTOR* vector(var x, var y, var z)
{
_vector_current = (_vector_current+1)%64;
_vector[_vector_current].x = x;
_vector[_vector_current].y = y;
_vector[_vector_current].z = z;
return &_vector[_vector_current];
}


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: clear vector()'s [Re: Superku] #393505
02/04/12 11:11
02/04/12 11:11
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
If you use a function like this:

Code:
VECTOR* vec_setxyz (VECTOR* v, float x, float y, float z)
{
    if (v)
    {
        v->x = x;
        v->y = y;
        v->z = z;
        
        return(v);
    }
    else
        return(NULL);
}



You can simply do this and don't have to rely on vector(..):

Code:
int myLittleFunction ()
{
	...
	
	VECTOR v;
	vec_setxyz(&v, 1, 2, 3);
	
	draw_point3d(&v, COLOR_RED, 100, 23);
	
	...
}



Since this is an engine-dll function, I don't understand why there is no std::vector<VECTOR*> used or the like and if in one frame the number of vector(...) calls exceeds the current used VECTOR*'s, new VECTOR*'s are generated and thrown into the std::vector... just my oppinion.

Re: clear vector()'s [Re: HeelX] #393507
02/04/12 12:31
02/04/12 12:31
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Quote:
_vector_current = (_vector_current+1)%64;

That's what I assumed too, but after 64 draw calls (using vector()) the draw function receives odd values.

Quote:
VECTOR* vec_setxyz (VECTOR* v, float x, float y, float z)

Hm yeah splitting stuff to a separate function at least solves the problem, although now I'm not entirely sure why.

Code:
draw_line3d( vec_add( vec_rotate( vec_create( vecTemp,  -4, -4, 0 ), vec_create( vecTemp, angle, 0, 0) ), pos ), vec_create( vecTemp, 100,100,100), 100 );


After 64 draw_lin3d calls, the position is screwed up here.
But why?

Quote:
VECTOR* rotate_point( VECTOR* relativePosition, VECTOR* absolutePosition, VECTOR* angle )
{
vec_rotate( relativePosition, angle );
vec_add( relativePosition, absolutePosition );
return relativePosition;
}

draw_line3d( rotate_point( vector(-4, -4, 0 ), vPos, vAngle ), vector( 100,100,100), 100 );

Now it works also above 64 draw calls.
So why didn't the former approach work?


Click and join the 3dgs irc community!
Room: #3dgs
Re: clear vector()'s [Re: Joozey] #393684
02/06/12 11:17
02/06/12 11:17
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Yes, vector() works indeed similar as described by Superku. It is for passing vector pointers to functions, not for generating vectors. To generate vectors or any other structs in a C program, use either sys_malloc or a static array.

vector() does not "clear" its vectors because there is nothing to clear. Only vectors that you have dynamically generated must be cleared.



Moderated by  old_bill, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1