I am writing a SDL program in C and I am using raycastlib. I set a global variable in a header file. I change it in main() and then call another function. This function uses the old value of the variable.
I have tried giving the new variable as an argument to the function, but that function called another function and it broke again. I don't want to add this as an argument to literally all functions in the header (yes this function uses almost all functions).
void draw()
{
RCL_RayConstraints c;
c.maxHits = 32;
c.maxSteps = 32;
RCL_renderComplex(camera,floorHeightAt,ceilingHeightAt,textureA
t,c);
}
This is the function as it is. The code is based on the example from raycastlib. It just tries to procedurelly generate the world (levelFloor in the code).
If this is not possible I will need to set the variable from the start (that is okay, the map doesn't change) but I will need to find a way to pass an array from a generating function to a variable without the main function to start the function.
The header file:
#define MAZE_WIDTH 25
#define MAZE_HEIGHT 25
int levelFloor[MAZE_WIDTH * MAZE_HEIGHT]; /* THIS VARIABLE IS THE PROBLEM */
static void shuffle(int *array, size_t n)
{
/* stuff */
/* returns nothing (but changes levelFloor) */
}
The part of main loop that uses these:
/* stuff */
#define STARTX (MAZE_WIDTH - (MAZE_WIDTH % 4))/2
#define STARTY (MAZE_HEIGHT - (MAZE_HEIGHT % 4))/2
MAZE_Recurse(STARTX,STARTY,levelFloor);
#undef STARTX
#undef STARTY
/* checked if it is changed here. it is. */
and
draw(levelFloor) /* I also tried changing the function and passing levelFloor as an argument which worked but didn't effect the other called function */
the draw() function:
void draw(int levelFloor[]) /* originally I didn't pass levelFloor as an argument */
{
RCL_RayConstraints c;
c.maxHits = 32;
c.maxSteps = 32;
RCL_renderComplex(camera,floorHeightAt,ceilingHeightAt,textureA
t,c);
}
RCL_RenderComplex comes from raycastlib.
To abstract the code is like this:
/*main.c*/
#include "xar.h"
#include "bar.h"
void foo()
{
bar();
}
int main()
{
xar();
foo();
}
/*bar.h*/
void bar()
{
stuff();
}
/*xar.h*/
int var[];
void xar()
{
var = 1;
return;
}
Thanks.
EDIT: I think I am going to rewrite the program.