Pass a pointer to a 2d array to BMax

BlitzMax Forums/BlitzMax Programming/Pass a pointer to a 2d array to BMax

Blitzplotter(Posted 2007) [#1]
I've populated a 2 dimensional array in C, in essence it contains chars which relate to space invaders, bullets and the like.

I realise it's be easier just to do it in BMax, however I'm interested in passing a pointer to memory where my 2d array which is updated in 'c' to a BMax function.... This might be more complex than I'm giving it due, but if anyone has any pointers on a good jumping of point to populating and refreshing an array with 'c', then allowing BMax to periodically use the 2D array to plot my space invaders etc....

regards,

BP.


ImaginaryHuman(Posted 2007) [#2]
I guess you need a blitzmax function which calls a routine in the c program that returns the pointer as a return value - it can just be an int or whatever, then in blitzmax you can easily turn it into a pointer.


Czar Flavius(Posted 2007) [#3]
I made a grid based game using C(++) and BlitzMax, where there was a C 2d array for the game's grid. Rather than fiddle with pointers, I simply made a C function that took x and y as parameters, and returned that element of the array.

For example char getCell(int x, int y, char array) {return array[x][y];}

Not the fastest or most elegant solution, but I found it more convienent for my simple game (and didn't have any performance issues with it) than dealing with pointer headaches. Depends whether you want the speed/must use pointers, or looking for a quick-fix ;)


Blitzplotter(Posted 2007) [#4]
thanks, I'll investigate at the weekend.