Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, Nymphodora, Quad, TipmyPip, Imhotep), 852 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
how define callback function for 3DGS? #466268
06/05/17 02:43
06/05/17 02:43
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
how define callback function for 3DGS?
any one know?


development 3d game is interesting!
Re: how define callback function for 3DGS? [Re: frankjiang] #466269
06/05/17 09:37
06/05/17 09:37
Joined: Oct 2008
Posts: 679
Germany
Ayumi Offline
User
Ayumi  Offline
User

Joined: Oct 2008
Posts: 679
Germany

Re: how define callback function for 3DGS? [Re: Ayumi] #466270
06/05/17 12:05
06/05/17 12:05
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
I say about Lite C,not purl C.
Code:
void populate_array(int *array, size_t arraySize, int (*getNextValue)(void))
{
	    for (size_t i=0; i<arraySize; i++)
	        array[i] = getNextValue();
}

int getNextRandomValue(void)
{
	return 0;
}



this will be show syntax error!

Last edited by frankjiang; 06/05/17 12:14.

development 3d game is interesting!
Re: how define callback function for 3DGS? [Re: frankjiang] #466272
06/05/17 16:46
06/05/17 16:46
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
I remember having a similar issue but you can do things like this in lite-c. Give me a minute, I'll give it a try!


POTATO-MAN saves the day! - Random
Re: how define callback function for 3DGS? [Re: Kartoffel] #466273
06/05/17 16:56
06/05/17 16:56
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
have a look:
Code:
#include <acknex.h>

//

void populate_array(int * array, int arraySize, void * getNextValue)
{
	int i;
	for(i = 0; i < arraySize; i++)
	{
		int TempFunction(); // temporary function
		TempFunction = getNextValue; // set function pointer
		
		array[i] = TempFunction(); // execute function
	}
}

int getNextRandomValue(void)
{
	return (int)(random(1000));
}

void main()
{
	fps_max = 60;
	
	random_seed(0); // initialize random seed
	
	//
	
	int MyArray[8]; // create array
	
	populate_array(MyArray, 8, getNextRandomValue); // fill array with return values of function "getNextRandomValue()"
	
	printf("Array Content: (%d, %d, %d, %d, %d, %d, %d, %d)", 
		MyArray[0], MyArray[1], MyArray[2], MyArray[3],
		MyArray[4], MyArray[5], MyArray[6], MyArray[7]);
}

It's a strange work-around but it works. Note that this is a lite-c-only thing, I don't think this would work in C.


POTATO-MAN saves the day! - Random
Re: how define callback function for 3DGS? [Re: Kartoffel] #466275
06/05/17 17:24
06/05/17 17:24
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Its just a simple function pointer, you can pass anything which is 4 bytes in size and cast it to a function to call it...

Re: how define callback function for 3DGS? [Re: Ch40zzC0d3r] #466280
06/06/17 01:18
06/06/17 01:18
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
well,can you show any demo code with it? tongue


development 3d game is interesting!
Re: how define callback function for 3DGS? [Re: Kartoffel] #466281
06/06/17 01:20
06/06/17 01:20
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
thanks,your example code looks so nice!


development 3d game is interesting!
Re: how define callback function for 3DGS? [Re: Kartoffel] #466282
06/06/17 02:11
06/06/17 02:11
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
i want to give this function any parms,how to do it?
Code:
int getNextRandomValue(int a)
{
	return a * a;
}


laugh


development 3d game is interesting!
Re: how define callback function for 3DGS? [Re: Kartoffel] #466283
06/06/17 02:15
06/06/17 02:15
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
i try it,but script is crash!
Code:
#include <acknex.h>

//

void populate_array(int * array, int arraySize, void * getNextValue)
{
	int i;
	for(i = 0; i < arraySize; i++)
	{
		int TempFunction(); // temporary function
		TempFunction = getNextValue; // set function pointer
		
		array[i] = TempFunction(); // execute function
	}
}

int getNextRandomValue(int a)
{
	return a*a;
}

void main()
{
	fps_max = 60;
	
	random_seed(0); // initialize random seed
	
	//
	
	int MyArray[8]; // create array
	
	populate_array(MyArray, 2, getNextRandomValue); // fill array with return values of function "getNextRandomValue()"
	
	int TempFunction(int a);
	TempFunction = MyArray[0];
	int res = TempFunction(2);
	printf("%d",res);
}



development 3d game is interesting!
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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