Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Mar 2005
Offline Last Active Yesterday, 06:25 PM

#5263780 loop: for(....) {... continue loop; ....} doesn't work

Posted by rip-off on 27 November 2015 - 02:54 AM

Note that using == on Strings may appear to work sometimes, this is very likely due to how Java handles String *literals*, which are often de-duplicated to reduce memory usage. Strings loaded from an external source do not get this behaviour.

#5263478 execute constructor of derived class

Posted by rip-off on 24 November 2015 - 04:34 PM

The typical rule of thumb is that a C++ class with any virtual member functions should also have a virtual destructor. Note that this also means specifying an empty virtual destructor even where you don't actually need custom destruction logic. This is based on the reasoning that writing code like frob demonstrated is typically only useful if the class in question has virtual member functions worth calling.

#5263149 Random errors in Release builds

Posted by rip-off on 22 November 2015 - 10:49 AM

As mentioned, please don't mark threads as "Solved" here, thanks.

#5260385 Singletons and Game Dev

Posted by rip-off on 03 November 2015 - 03:53 PM

How would my code look if I had to pass all that state around through function arguments and the like? Wouldn't that make it needlessly verbose?

This is a common argument for global state. The answer can be: "cleaner". Being forced to pass around state incentives programming styles that minimise dependencies and designs that are less coupled.


In short, you have constructed a false dichotomy between how your code currently looks and how it would look if you explicitly passed around the state, you are not considering the case where the code looks quite different from how it currently does.




When I was an intermediate programmer I was so proud of my little games with these "sub-systems" that were exposed via singletons. I thought I had a design. Looking back, these were horribly coupled. There were all sorts of dependencies between these so-called "sub-systems" because I didn't learn how to design code that wasn't coupled. If I needed to play a sound, or display something, I could and would reach from anywhere in the code into the relevent singleton and tell it what to do. From experience, I can clearly see that there was no overarching design.


That said, I'm not afraid of globals. I probably would still use them, for example as a placeholder while I experiment with an approach, before I know how I want or need the overall design to change. Particularly for smaller programs, a global for something simple and known like a logger or a resource cache is far from the end of the world.


I'd never bother with a singleton again. The "once and only once" rule doesn't seem relevant, I've never had an issue creating unexpected instances of something to justify the additional code that a full singleton requires - and the trade off against difficulty writing unit tests would be too big a burden to bear anyway.

#5260033 Collision Detection AS3

Posted by rip-off on 01 November 2015 - 03:27 PM

Unfortunately, as Lactose indicates, we don't allow people to get direct answers for their homework here. General questions about collision detection are allowed.

#5259135 Trying to get an idea of what a move object stream looks like in UDP?

Posted by rip-off on 26 October 2015 - 09:19 AM

Have you browsed the Networking and Multiplayer FAQ? Question 12 seems particularly relevant.


Also, to go one step further with the byte example above, am I going the right direction if I create a packet like protocol, so messages are smaller? In other words would I want to do that for efficiency (common sense? or no?)

Efficiency is relative. Even a fast paced user won't generate too many input commands per unit time, so there probably won't be a huge difference in overall performance in how you encode, transmit and decode such messages. As a counter example, if your game could end up having a lot of active entities on the server, then keeping all the clients up to date with all the entities may warrant much more extra care to avoid performance issues.


I'd recommend starting simple. Probably the best advice is to consider versioning your protocol or packets from the start. Including some kind of version identifier offers you the chance to change how your message work and ensure that new clients or new servers can either reject or interoperate with older versions.


So there might be an action packet like _ac:m:udlrlrudl and that would mean -> action move up down left right left ... etc. and I implement the parser to handle it locally?

You could do that. Remember if you are writing an action game you'll probably want to transmit the input command as soon as possible, so you are unlikely to be in a position to buffer so many commands at once. If your game is less action oriented, then there will be less consequence to the efficiency of the message.


It may be important to sent some kind of time identifier with input messages, so the server can attempt to replay the events from multiple clients and resolve unexpected sequences (if player A and B both attempt to move into the same tile at some point). Remember there is no guarantee the clocks on the server and client will match, so some kind of relative timing identifier must be used.


lol - which comes to my next question. After this I can start trying to implement it. How can I keep the server in sync with all clients when moving a monster.

I'd refer you back to the Forum FAQ, which has articles from real games as to how they've handled this. Unfortunately, all those games sounds significantly more complex than the one you're talking about so far, so perhaps there is an element of overkill in some of these approaches.


Ultimately, the big lesson of network game programming is that guaranteeing synchronisation (e.g. lock step) is a very expensive way to solve network games, any latency or connection issues will immediately impact on all users' experience of the game. Thus, most games choose to lose this guarantee and try to do their best to hide latency in various ways. Some games can use design and animation to hide most latency (e.g. Age of Empires, where a "Yes, Sir" sound would complete before the unit would respond to the command). Others accept that the clients and the users will sometimes disagree with the server's interpretation of events, and attempt to reduce the impact of such disagreements (such as the Source Engine "rewinding" the server when a player input packet arrives to resolve the event).


Ultimately, the network is a leaky abstraction, you cannot make it go away, you can just try to choose a trade off that impacts your game's style least.

#5258821 please help me teach yourself game programming in 21 days

Posted by rip-off on 24 October 2015 - 08:03 AM

As the others have mentioned already, what you are asking for is not allowed under copyright law.


Topic locked.

#5258409 Problem with save mechanisms

Posted by rip-off on 21 October 2015 - 02:03 PM

The stream read operation uses whitespace as a delimiter. You'll need to write something like a newline character between fields to read them back one by one. This will also allow you to use std::getline() for strings, thus allowing you to save strings with embedded space characters.

#5256673 Optimization in Javascript

Posted by rip-off on 11 October 2015 - 07:31 AM

I know that the next big thing would be to look again at my code logic and try to find new design ideas to speed things up but since I'm out of idea there...

That is the first thing you should be looking at - this is where the biggest gains are typically found. Micro-optimisation rarely results in orders of magnitude of a difference.

#5254157 Exiting running threads in a DLL when calling executable exits

Posted by rip-off on 26 September 2015 - 12:06 PM

Note that the behaviour you described does exist, it is just non standard. So in a way you are correct, once you qualify that it is compiler dependent. Now that the standard has thread support, there is little reason to rely on the older behaviour.

For example, Microsoft's C++ compiler documentation:

ISO Compliant
If you are familiar with the C# volatile keyword, or familiar with the behavior of volatile in earlier versions of Visual C++, be aware that the C++11 ISO Standard volatile keyword is different and is supported in Visual Studio when the /volatile:iso compiler option is specified. (For ARM, it's specified by default). The volatile keyword in C++11 ISO Standard code is to be used only for hardware access; do not use it for inter-thread communication. For inter-thread communication, use mechanisms such as std::atomic<T> from the C++ Standard Template Library.
End of ISO Compliant

Microsoft Specific
When the /volatile:ms compiler option is used—by default when architectures other than ARM are targeted—the compiler generates extra code to maintain ordering among references to volatile objects in addition to maintaining ordering to references to other global objects. In particular:

  • A write to a volatile object (also known as volatile write) has Release semantics; that is, a reference to a global or static object that occurs before a write to a volatile object in the instruction sequence will occur before that volatile write in the compiled binary.
  • A read of a volatile object (also known as volatile read) has Acquire semantics; that is, a reference to a global or static object that occurs after a read of volatile memory in the instruction sequence will occur after that volatile read in the compiled binary.
    This enables volatile objects to be used for memory locks and releases in multithreaded applications.

#5254149 Exiting running threads in a DLL when calling executable exits

Posted by rip-off on 26 September 2015 - 10:51 AM

A plain boolean is enough. No need to make it atomic as the thread doesn't change it. It may get an inconsistent state or miss a check, but it will be picked up the next time.

Unfortunately not. Without some kind of thread-safe modifier, the compiler is allowed to assume single-threaded behaviour, if it cannot see the variable being modified in a given area of code, it can assume the valaue never changes - as such, changes in thread A may *never* appear to thread B.

Locking and unlocking also take time.

True in general, but note that atomic operations don't actually lock or unlock, though you could build such behaviour on top of them.

Edit: You should make the boolean volatile, to avoid the compiler optimizing the access away.

Volatile is quite different from thread safety. It says to the compiler "make no assumptions about the current state of this variable, it could be changed at any time (e.g. by a hardware peripheral)".

While it is true that some compiler vendors have extended the meaning of "volatile" to be used for inter-thread communication, that was due to the absence of a standard alternative. Adding the thread-safe primitives to the standard was supposed to replace such non-standard extensions.

If you're worried about the cost of atomics, volatile should be much worse as it requires the current value to be fetched from real memory, bypassing all CPU cache levels in between. Atomic operations can work within the caches, though there is a cost to whatever inter-core cache consistency messaging protocols are used by the processor.

I can't remember the exact details now, so please double check this, but I believe there is an additional issue using "volatile", which is that the compiler and processor are still allowed interleave other instructions relative to the volatile memory access which can result in thread-safety issues. However, thread safe atomic operations have very strict ordering rules which the compiler must respect, and it needs to emit whatever memory barrier instructions which may be necessary to ensure the processor doesn't re-order incorrectly either. I believe this is the kind of non-standard guarantee that certain compiler vendors would make about "volatile".

#5250340 Should fanfic games be legal?

Posted by rip-off on 02 September 2015 - 05:00 PM

Star Wars, Jurassic Park and Back to the Future are all over 20 years old and still worth a great deal of money even in their original forms without the newer sequals.

My original reply was mostly aimed at derived works, though I admit I never called that out specifically. I think copyright on the original, unaltered version of anything could and probably should have a very long duration - but should come with a "use it or lose it" provision.

Of course lets not forget Disney I think Bambi, Micky Mouse and Cinderella have all been continually raking in the cash non stop without a break for over 60 years.

Many Disney "properties" are actually adaptations of earlier works - Cinderella is a folk tale and Bambi appears to have been the subject of an unusual copyright dispute.

I think this is great! (the adaptions, not the copyright dispute)

However, to enable such cultural re-use, eventually other works need to return to the public domain too, so the next Disney can bring their take on such stories. Unfortunately the trend of copyright duration expansion is locking more and more of our contemporary culture until far in the distant future.

People spend a lot of time and money creating unique IP and it becomes an asset. Weather they are currently doing anything with it or not is irrelevant as it is an asset that has monetary value.

Under the current system. Perhaps if copyright didn't last as long, there would be less emphasis on building a huge franchises that are "worth" so much money.

If you want to use it you need to get permission and pay for it

The day after you create something, certainly. A few years down the line, ok. Twenty years later, it should probably be fair game - if you're in any way creative you'll have made something new in the mean time.

Speaking specifically about games. How many long dormant titles suddenly got reboots when smartphones became popular?

That doesn't have to stop! I think having the original creator bring out a next canonical version will always draw a response. In fact, even now we can see that there is a lot of demand for some "spiritual successors" made by the original creator / team but without the rights, rather than the generic sequel made by whoever the current rights-holder has recently paid to churn something out.

Consider that had George Lucas actually *invented* a lightsabre in 1977, instead of it featuring in a film, by 1997 it would be out of Patent protection and we'd all have thought it was right and proper that the artificial monopoly was broken - and each year we'd be only delighted by the next wave of iteration by our favourite competing arms manufacturers!

#5249988 Should fanfic games be legal?

Posted by rip-off on 31 August 2015 - 02:23 PM

I think the current copyright laws are too restrictive and draconian. I think the duration needs to be seriously reduced. I think fair use should be expanded. I think there needs to be a "use it or lose it" rule, where copyright restrictions are not enforceable unless the owner is actively making the work available (in particular available in the region).

I believe every creative work borrows from what has gone before, and therefore there needs to be a balance between the right for an author to have control over their work versus enabling the next generation of works that will be based on it. For example, some extremely light Googling for "Terranigma" indicates that the central character is one "Ark", and that in the context of the game the character is clearly trying to draw on the "Noah's Ark" in Hebrew / Jewish mythology. I'm sure someone with more familiarity could find many more examples of ways this game was influenced by more recent culture.

So for me, I guess the question is "when", how long should a work remain the exclusive right of owner? That is a hard question. I think 20 years is plenty of time to reap the exclusive rewards from a work? I think most creative people don't milk just a single work forever, they are always creating new things.

#5249977 Parameter-Based Argument Sending

Posted by rip-off on 31 August 2015 - 01:10 PM

It isn't clear what problem you're trying to solve. You mention "worrying about how I deal with memory management", maybe if you explain this worry in more detail your proposal will be clearer?

#5249707 lame question how to delete something from vector

Posted by rip-off on 30 August 2015 - 09:20 AM

What have you tried searching for?