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

Is it acceptable to call a destructor?

40 posts in this topic

[quote name='StoneMask' timestamp='1350667804' post='4991837']
Are you saying I put it a step further, lol?

I'm unfamiliar with the syntaxes some of you are giving me, or I don't really find them very clean/readable (no offense). So to me it looks like I'm doing [b]less [/b]work or I'm lacking in some area of efficiency or functionality. I kind of think that way whenever I run into an unfamiliar syntax or code that looks intimidating to read through.

Compared to the methods that have been discussed in the thread compared to my posted way of doing it, which is the best in terms of efficiency and cleanliness? In C++ or something similar, please. Or even pseudocode!
[/quote]
You can make a decision on basic points: how much objects you want to use, what features you want to have and so on It's another great lesson what you have to learn on programming. But I suggest you to do it as good as possible, to use it in the next time ;)

ADDED

After reading [url="http://www.gamedev.net/topic/632993-is-it-acceptable-to-call-a-destructor/page__view__findpost__p__4991883"]this post[/url] by Brother Bob, I wanna add that you extremely have to learn basics of working with memory. It will strongly help you in the future. As middle point I want you to get some examples of SmartPointers(WeakPtr, StrongPtr, AutoPtr and so on).

PS when you will get a point of code from Brother Bob and tell how to use it in real application, then they will call you advantaged programmer ;) Edited by AlexB.hpp
0

Share this post


Link to post
Share on other sites
I'm not just learning about how to use for loops, lol. If you want to explain lambda functions to me, then I would gladly accept it.I've been meaning to anyway.
The reason I'm asking about this topic is that I'm making a game, and I want to make it as streamlined and advanced as I can with the tools given to me.
Most of the time when I ask questions here it has to do with conventions. Like, is it accepted by the general programming community to do this or that, etc. and this is one such question. But thank you all for the information once more. Edited by StoneMask
0

Share this post


Link to post
Share on other sites
You could make your own Delete() method, and that would set a boolean flag in the object (IsNull, for example) to true and delete any memory you may have allocated. Then, you could have a get() function (Or integrate this into the class with the boolean flag) to make sure you never tried to access members of the class that weren't there anymore.
0

Share this post


Link to post
Share on other sites
[quote name='superman3275' timestamp='1350761889' post='4992239']
You could make your own Delete() method, and that would set a boolean flag in the object (IsNull, for example) to true and delete any memory you may have allocated. Then, you could have a get() function (Or integrate this into the class with the boolean flag) to make sure you never tried to access members of the class that weren't there anymore.
[/quote]
That is entirely the wrong approach. If you delete an object and access it later, then the object shouldn't have been deleted in the first place because it was still in use. You have a lifetime management issue in that case and the proper way to handle that is to ensure that objects that are in use are [i]never[/i] deleted, not to delete them arbitrarily and add a safety net just in case.
2

Share this post


Link to post
Share on other sites
The way I handle it is a boolean that determines whether or not the object "exists". If it doesn't exist, I make its position far from anything that it could interact with, I disable its actions, and erase it from the board. Then once your character is out of the environment that has the enemy objects, they stay in a state of nonexistence until the next time they need to be initialized. So I would delete them right before I make more of them, and if the program ends, I delete them regardless.
0

Share this post


Link to post
Share on other sites
Wait, you move them "very far away". That is some really bad resource management. What you should do is stop drawing it altogether and delete all of it's member variables. I know there's some way to dot his without using new and delete, however I can't put my finger on it.
0

Share this post


Link to post
Share on other sites
I do stop drawing them altogether. I make it so the program doesn't access them anymore. The objects still exist, but nothing about them is accessed.
0

Share this post


Link to post
Share on other sites
Yes, but it doesn't matter if you don't draw them or access them, you're still using the R.A.M. required for them. Resource Management, although in this case not vital (Because it's a small game) is very important. What's the point in having them there if you're not going to use them? There isn't one. You need to delete the memory to free up space for other programs / more variables / bigger programs.
0

Share this post


Link to post
Share on other sites
Depending on the game, it may actually be more efficient to set a kill flag and ignore dead objects than to frequently new/delete objects.
1

Share this post


Link to post
Share on other sites
[quote name='yckx' timestamp='1350855608' post='4992578']
Depending on the game, it may actually be more efficient to set a kill flag and ignore dead objects than to frequently new/delete objects.
[/quote]

true, but that should be an optimization that comes AFTER the new/delete has been proven as the application bottleneck. An application should use the right data structure for the problem that is trying to solve, and then, only if necessary, implement an optimized version hiding that optimization away from the rest of the application.

The possibility that a game will need frequent new/delete is very low.. it usually only applies to particles and bullets (which are usually designed with memory pools straight away for this very reason) .

99% of the time, this is a premature optimization that will only bite you back later in the dev process by making code more complex to reason about ( I always tell to the guys working with me, your code makes sense to you NOW, how much sense will it make in 2 months?) and, using dead flags, hide poor data handling until it's too late to fix it.
0

Share this post


Link to post
Share on other sites
[quote name='kunos' timestamp='1350885685' post='4992682']
...
99% of the time, this is a premature optimization that will only bite you back later in the dev process by making code more complex to reason about ( I always tell to the guys working with me, your code makes sense to you NOW, how much sense will it make in 2 months?) and, using dead flags, hide poor data handling until it's too late to fix it.
[/quote]

That's why every project should have documentation: generated from code manuals, design doc, defined code convention, architecture doc and few other. This is programming too.
0

Share this post


Link to post
Share on other sites
The enemies only have a coordinate position, an unsigned short timer variable, a facing direction, and a bunch of functions that can move it around using random number generation. There is no graphics handling to take care of with these objects. You can think of them as practically invisible.

So are you saying that deleting these objects would be better for every time they intersect with my projectile? Or should I check out my CPU Usage every time they're deleted, and compare that against just shoving them off to the side until later, or what?

What do you think of a similar way of handling the player's projectile object? My player object has a projectile object that merely pops out of existence at the end of its run, and the player always has exactly one. Edited by StoneMask
0

Share this post


Link to post
Share on other sites
[quote name='StoneMask' timestamp='1350890620' post='4992696']
So are you saying that deleting these objects would be better for every time they intersect with my projectile? Or should I check out my CPU Usage every time they're deleted, and compare that against just shoving them off to the side until later, or what?
[/quote]

i think you should do the thing that is mapping better to the world you are trying to simulate and that results in the cleanest and (possibly) shortest code.

This is simply a vector of Stuff* or, shared_ptr<Stuff> ... add and remove objects in a standard C++ way. Because when things die, they are not part of the "living things set" (your vector) and they are destroyed.. dead people are gone, they don't wear a hat saying "I'm dead" ;)
Get the game to a prototype stage and then evaluate what parts of the code need special attention.
And, honestly, since I don't think you're working on the new Crysis, it's VERY unlikely you'll find any bottleneck in the C++ standard library.
1

Share this post


Link to post
Share on other sites
Ah, I hadn't considered a vector. Now that I look through the thread again they were mentioned once or twice.

Also, it's a small game, but I want to learn more about structure and efficiency. Even if it's small, I want it to be freakishly efficient.
0

Share this post


Link to post
Share on other sites
[quote name='StoneMask' timestamp='1350967756' post='4992983']
Even if it's small, I want it to be freakishly efficient.
[/quote]

If you are obsessive about this kind of thing, I suggest you try to fight the impulse. If you can't, your psychiatrist might have some pills for you.
2

Share this post


Link to post
Share on other sites
Kunos's response to my post is correct: the dead flag is an approach that should not be taken without some evidence that it would be an improvement in a given context. I simply wanted to note that superman3275's post immediately above mine perhaps should not be quite so absolute :)

I was posting from my phone (as I am now) and so perhaps erred on the side of brevity for convenience's sake.
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