Pass a pointer to a 2d array to BMax
BlitzMax Forums/BlitzMax Programming/Pass a pointer to a 2d array to BMax
| ||
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. |
| ||
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. |
| ||
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 ;) |
| ||
thanks, I'll investigate at the weekend. |