• 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.
Sign in to follow this  
Followers 0
Tolito

Which method is more effective?

13 posts in this topic

I am working on an animation system and have an animation format and everything made. I am storing the animation database in an array (unsigned char). There are two ways I just can't choose between.

 

Frame return_frame(unsigned int animation_number, unsigned char frame_number) {
        Frame out;
        // Array here (unsigned char) containing animation database.
        // Code here that applies rotations to the variable, "out," from the frame, "frame_number," of the animation, "animation_number."
        return(out); }

 

I would have to call the above function each time I wanted to draw a frame. There are no global variables being used here as the database is declared each time the function is called.

 

The other method was to have a variable type, "Animation," which has a Frame variable in it named "frame." All animations would be declared globally and part of the program would loop through the database and fill them.

 

Which is more effective? Should I go with using a function each time that returns a frame or should I have all animations and their frames already loaded in memory? Either way, I am going to be using a function that combines different parts of different frames and returns a frame, if that information is useful.

 

Also, should I have an animation table that points to the start of each animation relative to the start of the animation database so the return_frame function does not have to go through and look for the "End Animation" command however many times in order to get to the animation that it is looking for or what? Should the same be done for frames? Does it matter?

 

Thank you! :)

0

Share this post


Link to post
Share on other sites

Between the 2 methods you suggest, use the first method i.e. go with using a function each time that returns a frame.

IMHO, both of them are not the best ways to go about this problem.

1

Share this post


Link to post
Share on other sites

Thank you for your input! That method isn't slower or rougher on the processor, is it? That was actually the one I was leaning towards. Which way would you go about doing this? And should I have an animation and frame table or is it just fine to go through the animation database, counting as it goes until it reaches the animation and frame that it is looking for? Thanks again!

Edited by Tolito
0

Share this post


Link to post
Share on other sites

I'd recommend against returning a structure as it would cause a rather unnecessary copy to be made(This can get quite expensive if the structure is large)(Unless C compilers are allowed/able to optimize this (Someone correct me if i'm wrong)), it would probably be better to pass a "out" frame by reference to the function and modify it in place instead and only return a error code in case the function fails for some reason.

Edited by SimonForsman
2

Share this post


Link to post
Share on other sites

Thank you for that information! I actually planned to call the function to return a frame as an argument to the function that will draw it. Will that be a problem? Do the copies stack up over time?

0

Share this post


Link to post
Share on other sites

What he's talking about is the fact that when you return a complex type such as a struct the object has to be copied from its old context into the new one. It's not like a value which can just be set directly. They won't 'stack up' because the struct inside the function will be destroyed when the function exits. The reason you want to avoid it is for performance, but in C++ you'd also want to avoid it because copying objects can trigger complex and possibly destructive behaviors.

 

If you want to use a function to populate a struct then something like this is common in C:

 

typedef struct {
  int apeCount;
  int bananaIndex;
} Monkies;
 
void doSomething(Monkies* monks) {
  monks.apeCount = 8;
  monks.bananaIndex = 3;
}
 
int main() {
  Monkies my_monkies;
  doSomething(&my_monkies);
}
1

Share this post


Link to post
Share on other sites

Thank you for the example code! I should have been a little more specific. I was referring to them stacking up if not called inside a function, like so:

Frame frame=return_frame(0,0);
display(frame);

When called inside a function, it will terminate automatically indeed. What I like about your example code is that the function you declared does not need to return a variable in order to modify the variable. Does that mean it would be better to do this...

Frame frame;
return_frame(&frame,0,0);
display(frame);

Instead of this?

display(return_frame(0,0));

Very helpful advice! I need to go back and check for code that is returning structures!

0

Share this post


Link to post
Share on other sites
LOL, the thread is tagged "C Language" but you're using C++ there.

I find it useful to use return codes for indicating error states or information about what the function did. Handling objects by reference or pointer not only frees up the return value but allows you a consistent means for when you want to pass more than one object.

Another thing to consider in cases like this - and I'm not implying that you don't already have it right in this case - is whether this function should be a member of the class/struct or remain as an outside function. Edited by Khatharr
0

Share this post


Link to post
Share on other sites

LOL, the thread is tagged "C Language" but you're using C++ there.

That's puzzling, after reading over all the posts, I still can't find hints that this is c++ they are talking about.
0

Share this post


Link to post
Share on other sites

 

Frame frame;
return_frame(&frame,0,0);
display(frame);

 

 

I don't see the C++ there at all. I even made a C program to try it out and it compiled correctly.

Edited by nobodynews
0

Share this post


Link to post
Share on other sites
Never mind. For some reason I saw the & and thought reference instead of pointer-to. Possibly an advanced case of herp-derp. I've been spending so much time on schoolwork lately (eng and mat pre-reqs) that I haven't been doing any actual coding. -.-
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0