Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 17 Jul 2002
Offline Last Active Yesterday, 06:54 PM

#5302546 Compiling My Sdl C++ In Mac

Posted by ApochPiQ on 25 July 2016 - 05:03 PM


If your code was written carefully and designed to be platform-agnostic, it should port over fairly easily. If not... you might be in for as much as a complete rewrite of large chunks.

Without seeing your code it's impossible to say for sure.

#5302015 Generate Unique Ids

Posted by ApochPiQ on 22 July 2016 - 01:56 PM

Just allocate IDs one at a time starting at 0 (or 1). You have 4 billion+ IDs to play with in a 32-bit unsigned integer.

As for tracking sub-IDs, why not just keep a std::map<unsigned, std::set<unsigned>> that holds the sub-IDs allocated to each "parent" ID? Then you can traverse that set and nuke/free the IDs as needed.

#5301601 I'm Getting An Index Out Of Bounds When Trying To Add Buttons Pragmatically.

Posted by ApochPiQ on 20 July 2016 - 01:01 PM

Walk through your code with the debugger and watch the values of num in particular. I think you'll find it surprising and enlightening.

#5300212 The big face-off between inheritance/interfacing

Posted by ApochPiQ on 11 July 2016 - 11:09 AM

Favor composition instead. A popular set of approaches for this exists under the umbrella term entity/component system.

#5299656 What Language Is Best For Game Programming?

Posted by ApochPiQ on 07 July 2016 - 12:17 PM

Obligatory resource.

#5299353 Interpolating a direction that reverses.

Posted by ApochPiQ on 06 July 2016 - 11:55 AM

Your alpha value is missing some key information. You should track the start timestamp for interpolation and the end timestamp instead. Then you can compute alpha based on the current timestamp with minimal effort.

When you hit an obstacle or otherwise change directions, set the start time of interpolation to the time of impact, and the end time to the timestamp at which your end-position is valid. Problem solved :-)

#5298715 Hundreds of timers...

Posted by ApochPiQ on 01 July 2016 - 12:12 PM

I love how this thread ended up in premature optimization land.

Frankly IMO it kinda started off there ;-)

#5298662 what means these error?

Posted by ApochPiQ on 30 June 2016 - 02:36 PM

This is the equivalent of cutting your arm off because your fingers are itchy.

Sleep is not the solution, it's just masking your problem. You need to do your research and actually understand how to do cross-thread synchronization correctly.

#5298544 What are the basic types of code used in video game programming (not languages)

Posted by ApochPiQ on 29 June 2016 - 12:19 PM

There are probably hundreds of concepts worth knowing for a routine day of game programming. Maybe more.

Don't worry about knowing all of them up front. Just write code, and when you run into something that seems awkward, overly complex, or even impossible, that's the time to ask a specific question about how to solve your problem in code.

#5298457 what means these error?

Posted by ApochPiQ on 28 June 2016 - 03:59 PM

That's not how you do cross-thread communication. Because of caches, memory access models, and machine-code-level optimizations, you may not get the correct values for static variables when accessed across threads.

PLEASE do yourself a favor and research basic multithreading techniques. At a minimum you need to use an atomic variable, possibly even a locking model to protect shared data depending on how many variables you want to modify between threads.

#5298432 [MSVC] Why does SDL initialize member variables?

Posted by ApochPiQ on 28 June 2016 - 12:39 PM

To really appreciate the SDL checks you have to think like an attacker.

This post is a recent and excellent walkthrough of how exploits are crafted. Study it carefully.

Now that you're thinking like an attacker, riddle me this: would you like to have the ability to inject arbitrary data into an object using an uninitialized field, just by allocating that object on top of your own pre-crafted memory block?

If you're thinking carefully, the answer is a resounding YES. If I can pre-fill an uninitialized structure with anything I want, I can get some pretty powerful exploits, including but not limited to:

- Arbitrary code execution
- Privilege escalation
- Corrupting or malforming arbitrary data

So in the long run, 0-initialization is way better than allowing data injection attacks.

#5298307 Hundreds of timers...

Posted by ApochPiQ on 27 June 2016 - 05:17 PM

Overcomplicated and premature optimization.

The vast majority of Guild Wars 2 game timers run on a single priority queue. On any given map instance there are probably many tens of thousands of timers in the list, with resolutions down to 40ms (the game simulation runs at 25Hz). There is no relevant performance penalty to doing this.

The actual work associated with a given timer (doing damage, changing status effects on a character, causing movement, etc.) is almost always several orders of magnitude more expensive than even the most simple and naive implementation of a timer queue.

Profile and measure before you optimize. It will save you a lot of pain and over-engineering on stuff that doesn't actually matter.

#5298299 Space Simulation Game Design (Finding The Fun)

Posted by ApochPiQ on 27 June 2016 - 04:22 PM

From my personal experience working on space games for many years, I will warn you now that they are a niche genre at best. This doesn't mean you shouldn't make your game or try to make it as fun as possible - it just means that many people will not find it engaging, and many people will.

Your best bet IMHO is to focus on entertaining the kinds of players who are likely to want to play your game. That may sound ludicrously tautological, but it's important. Trying to appeal to a Call of Battlezone player is not going to be as successful as trying to appeal to the core who just love flying around in space and doing stuff.

We spent literal years and untold sums of money trying to appeal to people who never did really click with the games. In the end the best bet was to double down on doing things really well and accepting that being a space game means that some people may not want to play.

#5298260 Is using one the switch statement better then using multiple if statements?

Posted by ApochPiQ on 27 June 2016 - 10:57 AM

Performance is a question of your run-time branching, performed instruction saves, navigating, not at all a question of wheather it was an if or a switch. But frankly, I cannot spot when and how switch can have outperformed proper conditionals in any way on any platform- and by my logic I conclude it cannot.

The reason has already been covered in this very thread: switches are easy to convert to lookup tables in machine code. Conditional statements are less easy. So in a common case you will get better machine code generated for a switch than a if/else ladder. Some compilers are better at this than others.

Just because you can't imagine it doesn't mean it isn't true.

#5297751 Microsoft Checked C

Posted by ApochPiQ on 23 June 2016 - 04:18 PM

Very little of any software "has to be" written in C anymore.

Entire huge games have been shipped with no C in them, for example. Of the things you listed, the C implementation is usually for compatibility with non-C languages, not to espouse C directly!

I have an entire language and compiler toolchain written with 0 dependencies on raw C. It has support for speaking the C ABI, but that has nothing to do with the C language being a mandatory component of anything.

The pieces of software that are in C are usually some of the most hardened and well-tested portions, for several reasons - not least of which being the fact that they usually exist to interface with non-C languages.

The effort of rewriting C code into Checked C is nontrivial. The reward is marginal at best for already-bulletproofed code. I just don't see a compelling reason for adoption.

It's a nifty project from a languages standpoint, but I don't see it being revolutionary.