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
5 registered members (AndrewAMD, TipmyPip, VoroneTZ, Quad, 1 invisible), 688 guests, and 11 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!
Re: how define callback function for 3DGS? [Re: frankjiang] #466288
06/06/17 09:20
06/06/17 09:20
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
your argument list must match when calling!

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



Visit my site: www.masterq32.de
Re: how define callback function for 3DGS? [Re: MasterQ32] #466293
06/06/17 12:38
06/06/17 12:38
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
thank you for your answer!
but i want to use this code likes:
Code:
void PrintfText(int value) 
{
    printf("Hello World %d!/n",value);
}

void CallPrintfText(void (*callfuct)(int),int value)
{
    callfuct(value);
}

int main()
{
    CallPrintfText(PrintfText);
    return 0;
}


Last edited by frankjiang; 06/06/17 12:39.

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

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
as you've seen in my example, you have to use that little workaround.
Code:
void PrintfText(int value) 
{
    printf("Hello World %d!/n",value);
}

void CallPrintfText(void * callfuct,int value)
{
    void func(int);
    func = callfunct;
    func(value);
}

int main()
{
    CallPrintfText(PrintfText);
    return 0;
}


I don't think there's another way using lite-c.


POTATO-MAN saves the day! - Random
Re: how define callback function for 3DGS? [Re: Kartoffel] #466300
06/07/17 02:09
06/07/17 02:09
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
Code:
#include <acknex.h>
#include <default.c>
void PrintfText(int value) 
{
    printf("Hello World n%d!",value);
}

void CallPrintfText(void * callfuct,int value)
{
    void func(int);
    func = callfunct;
    func(value);
}

int main()
{
    CallPrintfText(PrintfText);
    return 0;
}


this code will be show"callfuct undeclared idenitifier"


development 3d game is interesting!
Re: how define callback function for 3DGS? [Re: frankjiang] #466301
06/07/17 05:40
06/07/17 05:40
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Because there's a typo in the first parameter ("callfuct" instead of "callfunct").


"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: how define callback function for 3DGS? [Re: Superku] #466306
06/07/17 12:04
06/07/17 12:04
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
so do you know how do it?


development 3d game is interesting!
Re: how define callback function for 3DGS? [Re: frankjiang] #466312
06/08/17 00:51
06/08/17 00:51
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
Superku mean this :



void CallPrintfText(void * callfuct,int value)
{
void func(int);
func = callfunct;
func(value);
}

its not the same name just correct it like this :


Code:
#include <acknex.h>
#include <default.c>
void PrintfText(int value) 
{
    printf("Hello World n%d!",value);
}

void CallPrintfText(void * callfunct,int value)
{
    void func(int);
    func = callfunct;
    func(value);
}

int main()
{
    CallPrintfText(PrintfText,50);
    return 0;
}


Re: how define callback function for 3DGS? [Re: Dico] #466314
06/08/17 05:29
06/08/17 05:29
Joined: Dec 2009
Posts: 128
China
frankjiang Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
Thank you very much.


development 3d game is interesting!
Re: how define callback function for 3DGS? [Re: frankjiang] #466325
06/08/17 16:08
06/08/17 16:08
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
You're welcome laugh

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