• 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.

Diakon_Tristan

Quadtree to file

2 posts in this topic

As the topic says I would like to save a quadtree to a file. I have no idea how to do it. I hope you can help. Here is my Quadtree: typedef class QUADTREE { public: QUADTREE(void); //data QUADTREE *node1, *node2, *node3, *node4; }T_QUADTREE; typedef T_QUADTREE *QUADTREE_POINTER; If a node is a leaf of the tree it is marked. I would like to use fopen() etc.
0

Share this post


Link to post
Share on other sites
Just add methods called SaveTree() and LoadTree() to the node class, and have them each take a FILE* as a parameter.

  
SaveTree(FILE* f)
{
// print all items which arent child pointers to the file

node1->SaveTree(f);
node2->SaveTree(f);
node3->SaveTree(f);
node4->SaveTree(f);
}

LoadTree(FILE* f)
{
// load data from file here

if(!leaf)
{
node1 = new QUADTREE;
node1->LoadTree(f);
node2 = new QUADTREE;
node2->LoadTree(f);
node3 = new QUADTREE;
node3->LoadTree(f);
node4 = new QUADTREE;
node4->LoadTree(f);
}
}



I havent tested this, but I see no reason why it shouldnt work..
0

Share this post


Link to post
Share on other sites
Well, that example lacks base cases, so it won''t actually DO anything, but it''s the right idea.

Basically, when writing out a tree structure, a preorder listing is the way to go, as long as there is an unambiguous ordering between the children. Given that they are named node1 through node4, that pretty much gives you the ordering you''re looking for. So slightly more useful code would look kind of like this:

  
SaveTree(FILE* f)
{
if (isLeaf)
{
fprintf(f, "L");
fprintf(f, "Put the leaf data here, terminated with a newline");
}
else // is an internal node

{
fprintf(f, "I");
fprintf(f, "Put the internal node data (other than the children) here, terminated with a newline");
node1->SaveTree(f);
node2->SaveTree(f);
node3->SaveTree(f);
node4->SaveTree(f);
}
} // SaveTree(FILE *)



LoadTree(FILE *f)
{
char buff[1024];
fgets(buff, 1024, f);
if (*buff == ''L'')
{
// parse the Leaf data out of the remainder of the

// string stored in buff

}
else // internal node

{
// parse the internal node data out of the remainder

// of the string stored in buff, then:

node1->LoadTree(f);
node2->LoadTree(f);
node3->LoadTree(f);
node4->LoadTree(f);
}
}


Note that just using newlines to separate records is a bit fragile, and parsing out of string format can be a bit hard, although sscanf should do fine with it. Also, 1024 might not be enough characters for a line, which would really screw that function up. But it shows the basic idea of how to use a preorder recursive listing to save and load a tree structure.

The big advantage to using a preorder listing is that it is complete on its own. You don''t need to store any information about the number of nodes in the tree, because the recursive loading is always filling in subtrees from the top down, and when all of the subtrees are full, the load is done. A postorder listing, on the other hand, fills in the tree from the leaves up to the root, which means that it requires knowing how large the tree is, so that it knows when the tree it''s built is done.
0

Share this post


Link to post
Share on other sites