Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, SBGuy, Petra), 801 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 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: 681
Germany
Ayumi Offline
User
Ayumi  Offline
User

Joined: Oct 2008
Posts: 681
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