#21 Members - Reputation: 2766
Posted 19 October 2012 - 12:32 PM
Laerning how to use the standard library (std::remove_if(), std::vertex()) and the language features (lambdas, auto type deduction) is the boss fight that will unlock the next level.
Professional Free Software Developer
#22 Members - Reputation: 1551
Posted 19 October 2012 - 01:00 PM
I would argue Brother Bob's way is most efficient and clean, and has the most elegant and clean syntax. Then again, I'm used to reading C++.
Laerning how to use the standard library (std::remove_if(), std::vertex()) and the language features (lambdas, auto type deduction) is the boss fight that will unlock the next level.
The problem is this is a beginner's forum, and when you start putting lambda functions, using std::bind, functors, or any other somewhat advanced techniques, it's easy to get discouraged. As you said, you're used to looking at C++ (and, probably used to looking at C++11).
Do you really expect a beginner, who is just learning what a for loop does, to understand a lambda function?
So, IMO, this forum should stick to fundamentals and being obvious about how to conquer problems, and this would exclude any C++11.
The boss fight is for the experienced players, not someone who just picked up the joystick for the first time.
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
#23 Members - Reputation: 1085
Posted 19 October 2012 - 01:12 PM
Normally people do not call the destructors. Since C++ is clearly pretty new to you, take the advice and do what everyone else does and don't call the destructors directly. Because if you do, you'll be back here in a week asking people to debug the weird crashes in your program and that road is going to be really hard work because suddenly you're in a place where very few people will be able to help you because everyone else doesn't call the destructors because they don't want to be in that place.
There is a reason people learning to juggle start with bean bags and not running chainsaws. It's less exciting, that's for sure. But it's also less exciting.
#24 Moderators - Reputation: 4635
Posted 19 October 2012 - 01:33 PM
Fundamental does not equate simple. Everything in every language, literally, is just syntactic sugar on top of machine code that adds a levels of abstraction. The more of this sugar you exclude, the more of other things you have to learn instead. I don't think manually erasing elements is any more obvious than using functions that the standard library already provides.
I would argue Brother Bob's way is most efficient and clean, and has the most elegant and clean syntax. Then again, I'm used to reading C++.
Laerning how to use the standard library (std::remove_if(), std::vertex()) and the language features (lambdas, auto type deduction) is the boss fight that will unlock the next level.
The problem is this is a beginner's forum, and when you start putting lambda functions, using std::bind, functors, or any other somewhat advanced techniques, it's easy to get discouraged. As you said, you're used to looking at C++ (and, probably used to looking at C++11).
Do you really expect a beginner, who is just learning what a for loop does, to understand a lambda function?
So, IMO, this forum should stick to fundamentals and being obvious about how to conquer problems, and this would exclude any C++11.
The boss fight is for the experienced players, not someone who just picked up the joystick for the first time.
I have already responded to an earlier poster that I agree that my solution as a whole may be too much for a beginner (and frankly, I only posted it because alvaro asked for it). But I also argued that, once you have accepted the solution in general, the C++11 features I included actually improves the simplicity of it.
Ignoring the C++11 features because they add complexity is wrong in my opinion. You can ignore my solution as a whole, but it would be outright stupid to remove the C++11 from it because that's going to turn it into a mess (or an even greater mess, if you like).
#25 Members - Reputation: 3329
Posted 19 October 2012 - 01:36 PM
So, IMO, this forum should stick to fundamentals and being obvious about how to conquer problems, and this would exclude any C++11.
I love the irony.
This sort of thing isn't even a problem in the languages we regularly recommend to beginners. Maybe we should focus on excluding C++ altogether?
If we're going to include C++, then include it properly.
Edited by Telastyn, 19 October 2012 - 01:37 PM.
#26 Members - Reputation: 200
Posted 19 October 2012 - 02:47 PM
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 ;)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 less 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!
ADDED
After reading this post 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, 19 October 2012 - 03:15 PM.
#27 Members - Reputation: 204
Posted 20 October 2012 - 12:11 PM
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, 20 October 2012 - 12:14 PM.
#28 Crossbones+ - Reputation: 1373
Posted 20 October 2012 - 01:38 PM
Here's Breakout:
Breakout!
If you need some photo editing done, contact me:
superman3275@gmail.com
if you want some programming help, or are recruiting for a game development team, either PM me on here or email me up there
#29 Moderators - Reputation: 4635
Posted 20 October 2012 - 01:54 PM
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 never deleted, not to delete them arbitrarily and add a safety net just in case.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.
#30 Members - Reputation: 204
Posted 20 October 2012 - 02:20 PM
Baby, make your move, step across the line,
touch me one more time, come on, dare me! I wanna take you on, I know I can't lose,
#31 Crossbones+ - Reputation: 1373
Posted 20 October 2012 - 02:45 PM
Here's Breakout:
Breakout!
If you need some photo editing done, contact me:
superman3275@gmail.com
if you want some programming help, or are recruiting for a game development team, either PM me on here or email me up there
#32 Members - Reputation: 204
Posted 20 October 2012 - 02:57 PM
Baby, make your move, step across the line,
touch me one more time, come on, dare me! I wanna take you on, I know I can't lose,
#33 Crossbones+ - Reputation: 1373
Posted 20 October 2012 - 03:18 PM
Here's Breakout:
Breakout!
If you need some photo editing done, contact me:
superman3275@gmail.com
if you want some programming help, or are recruiting for a game development team, either PM me on here or email me up there
#35 Members - Reputation: 1302
Posted 22 October 2012 - 12:01 AM
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.
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.
#36 Members - Reputation: 200
Posted 22 October 2012 - 12:50 AM
...
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.
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.
#37 Members - Reputation: 204
Posted 22 October 2012 - 01:23 AM
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, 22 October 2012 - 01:45 AM.
#38 Members - Reputation: 1302
Posted 22 October 2012 - 01:48 AM
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?
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.
#39 Members - Reputation: 204
Posted 22 October 2012 - 10:49 PM
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.
Baby, make your move, step across the line,
touch me one more time, come on, dare me! I wanna take you on, I know I can't lose,







