2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
how define callback function for 3DGS?
#466268
06/05/17 02:43
06/05/17 02:43
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
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: Ayumi]
#466270
06/05/17 12:05
06/05/17 12:05
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
OP
Member
Joined: Dec 2009
Posts: 128
China
|
I say about Lite C,not purl C.
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
Expert
|
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
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
have a look:
#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]
#466281
06/06/17 01:20
06/06/17 01:20
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
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]
#466283
06/06/17 02:15
06/06/17 02:15
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
OP
Member
Joined: Dec 2009
Posts: 128
China
|
i try it,but script is crash!
#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!
|
|
|
|