• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

wiseGuy

Pointers -ARGH-

7 posts in this topic

Okay folks, here''s the dilemma. I have two cpp source files in my project so far. One is main game routines and one has pathfinding algorithms. My problem is that I want to pass a pointer to an array to the FindPath() function, so that the function fills it out with directions. I moved findPath back into the main file, and tried this prototype: int findPath(int x1, int y1, int x2, int y2, int *directions[100], int *numDirections) and this code: if (.....) { directions[current]=whatever; //note there isn''t a * then later, outside the findPath function findPath(6,6,5,5, my_directions[100], &numDirs); //note there is no & /////// This is fine when both functions are in the same file, but when I seperate the files, i get problems and the program keeps crashing. I have to add *''s and add &''s which weren''t needed when the pathfinding function was in the same file as the main program. Is there another solution, such as references? I also tried using player_directions[100] as a global, but when it was changed in one file, it wasn''t changed in the other (i think). Anyway, if anyone has had the time to read this longgg message and knows what I am doing wrong, the I would be very grateful for your advice! Thanks all, wiseGuy
0

Share this post


Link to post
Share on other sites
Which file a function's in shouldn't matter.

Forgive me if you know this already, but if a function is in a different file, you've gotta declare it. For example

<>
void func_a(void) { /* body of func a */ }

<>
// if file B wants to use something in file A, it must have
// a declaration:
void func_a(void);

Obviously, the declaration should have the same parameters (and in the same order) as the actual function.

Any good C book should have more info on how declarations work and why you need them.

BTW, you should really consider putting your functions in a class. A good C++ program has NO functions that aren't inside a class.

Mason McCuskey
Spin Studios - home of Quaternion, 2000 GDC Indie Games Fest Finalist!
www.spin-studios.com

Edited by - mason on 1/8/00 6:57:31 PM
0

Share this post


Link to post
Share on other sites
You also don''t really want to pass the size of the array or use a pointer to an array.

An array is just a prettied up pointer. So in this context you''re using a pointer to a pointer

array[100]

is the same as

*(array + 100)

and int *array[100] (like you have) is *(*(array))
pretty ugly.

when you pass an array in a function you should just use the pointer. If you do something like

void function(int array[])
{

// now this works
array[100];
}

and then call function

function(sendThisArray[]);

things should work out right. I''m not exactly sure of where to use those brackets, I try to avoid arrays when possible, but you get the jist.

If you''re worried about the size of the array changing over two files, use something like

#define MAX_ARRAY_SIZE 200

in a header and use this for limit checking.

Hope this helps.
0

Share this post


Link to post
Share on other sites
that should be:
int Get100(int* Array)
{
return Array[100];
}

void func()
{
int my_array[200];
int i = func(my_array);
}
0

Share this post


Link to post
Share on other sites
Note to Mason:

A good C++ program has 1 function not in a class, it might look familiar to you:

int main(int argc,char **argv);

-or-

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)

(note : my main() definition might be off by a bit, since it''s been a long time since I''ve done DOS stuff)

gameguru4@yahoo.com
0

Share this post


Link to post
Share on other sites
I would suggest something like the following prototype (c style..)


typedef struct {
int x;
int y;
} POINT, *PPOINT;

/*
FindPath fills the array pointed to by DirArray with directions to get from PointA to PointB. When called, the variable Size should point to an integer that contains the max size of DirArray. After FindPath returns, Size will be filled with the number of directions actually placed into the array.

If DirArray is not large enough to hold the complete list of instructions, CompletePath will be set to FALSE.

FindPath returns TRUE if it was able to compute a path (even if DirArray is not large enough to hold the complete path..) If it is unable to compute a path, FindPath returns FALSE.
*/

BOOL FindPath (POINT PointA, POINT PointB, int * DirArray, int * Size, BOOL * CompletePath);

So, you would call your function like this:
int size;
int ary[MAX_DIR_ARRAY];
BOOL fullpath;
POINT pointA, pointB;

/*
Fill in pointA i& pointB info with data..
*/

size = MAX_DIR_ARRAY;

if (FindPath (pointA, pointB, ary, &size, &fullPath)) {
//
// Do stuff with our computed path...
//

}




0

Share this post


Link to post
Share on other sites
Mason
A good C++ program doesn't need to have all their functions in one class. Like, for myself, I have one file with all the initialization, for my window and DirectX stuff. All the rest of it is done in classes. Since I only use the DirectDraw stuff, I do the rest by myself. And the program is still good, at least as good as the rest of my stuff done with all classes.

Dance with me......

http://members.xoom.com/CJdeVos/index.htm

Edited by - CJ on 1/9/00 3:57:42 AM

0

Share this post


Link to post
Share on other sites