Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


ChaosEngine

Member Since 09 Jun 2000
Offline Last Active Yesterday, 09:08 PM

#5211813 Curious about Save Protection Methods

Posted by ChaosEngine on 19 February 2015 - 09:34 PM

Generally the opinion round here is that you have two options:

  1. Store the save file on a server you control and make the game online only
  2. Don't bother (or at least, don't bother with anything more complex than a binary file format and a checksum)

Anything stored locally is subject to reverse engineering by a skilled cracker. If a binary file format or a really simple encryption puts it into the "not worth the effort" basket for 95% of your users, then that's good enough. 4.9% will then download an editor written by the 0.1% who saw your encryption as a challenge.

 

But honestly, I doubt I'd even worry about that. If a user wants to cheat and change their save somehow (adding items, health, etc) as long as it's a single player game, they're not really harming anyone.

 

If it's a multiplayer online game... then the save should be on the server.




#5210374 How to correctly inject and share an object to multiple other objects

Posted by ChaosEngine on 12 February 2015 - 05:02 PM

So B and C just need a reference (possibly const, depending on whether they will modify the A)

 
Aren't storing references a bad idea? http://stackoverflow.com/questions/892133/should-i-prefer-pointers-or-references-in-member-data . Again I'm only going by what I'm reading online.

 
Let's examine the objections in the accepted answer:

you are forced to initialise the reference in each constructor's initialiser list: there's no way to factor out this initialisation into another function (until C++0x, anyway)

First, the initialiser list is the correct place to initialise member variables. Second, it's 2015 and almost every major compiler has support for delegating constructors.
Besides, even if you can't use delegating constructors, it's not a massive maintenance burden to initialise your reference.
 

the reference cannot be rebound or be null. This can be an advantage, but if the code ever needs changing to allow rebinding or for the member to be null, all uses of the member need to change

If the object you are referring to cannot be null, then this is a good thing. If it can be null, then you shouldn't use a reference. In your case, your B class expects an A object to exist for the lifetime of the class.
 

unlike pointer members, references can't easily be replaced by smart pointers or iterators as refactoring might require

Again, you are expressing your intent through the language features. A reference implicitly tells you that the B class expects an A object to exist for the lifetime of the B object. If you change that intent, you should change the code to reflect that. Changing from a reference to a pointer will cause your code to fail to compile. That is A Good Thingtm. The compiler is now helping you see where your reference/pointer is used and forcing you to examine the usage of it in each context.
 
 
Horses for courses. 
If the injected object can be NULL: use a pointer.
If the injected object can be swapped out for a different object: use a pointer
If the injected object is not clearly owned by anyone: use a shared_ptr to create it and a weak_ptr to reference it.

But...
if in the case like this where the injected object cannot be null and must exist for the lifetime of the client object: use a reference.

 

Note that it's perfectly legitimate to store a raw pointer here to represent the concept of "NO ownership."

 
I like this approach, even though raw pointers are usually not good. I think if someone was to read my code and saw it, it would clearly convey there is no Ownership of this b2World object. If I take this approach, it would mean that I don't need to delete my a object in the destructor of both B and C. It would need to be handled separately?  Something like this then:
main(){
A aObject;
B bObject(&aObject);
C cObject(&aObject);
}
Then A would be deleted when it goes out of scope along with B and C automatically.

Note that that approach will work equally well with references.


#5209878 Operator Overloading C++

Posted by ChaosEngine on 10 February 2015 - 03:56 PM


You could argue that there is use in defining it const to prevent you from changing the value in the function.

 

True. Whether that's useful or not depends on the function itself, but in general I'd agree it's good programming practice.

 


Plus putting const on everything you can is just a good habit to get into.

 

Agreed. In fact, I'd go further. In some ways, I think variables should be const by default and marked as mutable otherwise, but I understand the historical reasons why C++ couldn't do that.

 


(And not being able to do it in C# drives me up the wall sometimes...)

Amen brother. Lack of const objects/methods is one of my pet hates in c#.

 


Though if I'm doing that I usually leave the const off of the function header in the .h file, adding it to the .cpp file only since the caller doesn't really care one way or the other since it's by-value.

 

Never knew you could do that. Wouldn't it change the function signature and mess up the linker?




#5209672 Clean OOP programming question

Posted by ChaosEngine on 09 February 2015 - 03:04 PM

OP, aside from the code formatting issues, what you're looking for is an event listener system. You could create your own (ala alnites suggestion) or you could use a "signals and slots" library such as Boost.Signals .

 

The idea behind these is to decouple your event handler from the event source.




#5207509 Modifying a cell value in Excel through an external app

Posted by ChaosEngine on 29 January 2015 - 02:04 PM

Another option is LinqToExcel

 

Presents a nice interface for query excel sheets. Really easy to use.




#5207326 Some programmers actually hate OOP languages? WHAT?!

Posted by ChaosEngine on 28 January 2015 - 07:20 PM


In Java (and in C#) you see people creating new classes whose only purpose is to be a bucket for static methods. How silly is it that one has to pay penance to the type system to achieve such a simple request as a free-standing function?

 

Yeah, I do that all the time in C#. 

 

I do wish they would add support for free functions, but in practice* it's no different from adding a free function to a namespace in C++, and namespaces are a Good Thing IMO.

 

* as long as you don't do anything stupid like depend on static state, but again you can do the exact same thing with functions and global state in C++.




#5204330 what kind of questions should I expect in a web developer Interview

Posted by ChaosEngine on 14 January 2015 - 04:34 PM

Most interviews are broken into non-technical and technical sections (typically in that order).

 

The non-technical section is there to learn about you as a person; how you work, will you fit in with the team, attitude... that kinda thing: see cozzie, NiteLordz and especially frobs replies for that.

 

The technical section varies. Some companies will assume you're good enough from looking at your experience. Others will do anything from a few simple questions to giving you a machine and asking you to implement something. No matter what happens here: don't be afraid to ask questions. Show your thought process. If you're asked about specific technologies (js frameworks, etc), be honest if you're not familiar with them, but try to compare them to something similar you do know. 

 

If you're given a code sample.... read it several times before answering.




#5202361 Run game only through a launcher

Posted by ChaosEngine on 06 January 2015 - 02:52 PM

There is a third option which has yet to be mentioned: don't use two different .EXEs. If the game and the launcher are the same program, you don't have to worry about them being run separately.


Don't most people do this to allow the game to be updated? Most OSs won't allow a running program to be overwritten on disk.

Personally, I'd go with SeanMiddleditchs approach and ignore it. Most of the time, a game will ship with an installer that creates some kind of shortcut to start the game. Ideally the user won't ever bother going into the games folder to click on the exe.

<slightly-unrelated-rant>
One final thing to bear in mind is that if you wanted to put your game on Steam (or any other kind of auto updating digital distribution) then it's incredibly annoying when the user launches the game and it only updates then. Planetside 2 does this and it drives me insane ("wayhey, time for some shooty fun....bollocks... 3 gigs of updates to download.... grrr")
</slightly-unrelated-rant>


#5195103 Multiple Inheritance or lots of pointers?

Posted by ChaosEngine on 27 November 2014 - 10:24 PM

Ask yourself a simple question when deciding to use inheritance: is a dog an animal, or does a dog have a tail?

 

So in your case, an entity is not a mesh, it's not physics data, etc. But it does have those things.

 

In general, this is what's know as "favouring composition over inheritance".

 

edit: damnit, ninja'd




#5194352 Building A Game Engine + Game

Posted by ChaosEngine on 23 November 2014 - 09:19 PM

Now, if you're talking about using C++ effectively/efficiently, then I'd partially agree.  For me, learning C++ wasn't so hard, but learning to use it properly was a bigger challenge, one that I'm still learning as the language evolves.

Well, I wasn't talking about writing "hello, world".

Learning to use it == learning to use it properly.
The very fact that you feel you have to differentiate between the two is symptomatic of the issues with c++.

Maybe you were some kind of c++ savant, but I've seen hundreds of beginner and junior programmers make mistakes in C++ that just don't happen in other languages. It is demonstrably difficult to learn for most people. If it wasn't, we wouldn't see those kinda of threads.


#5193162 Building A Game Engine + Game

Posted by ChaosEngine on 16 November 2014 - 06:53 PM

 

 


Its undefined because you haven't assigned a value to it. In reality it will be some value that was left in the stack from a previous local variable in some other function call.

While the question is simple, the correct answer is quite a lot more complicated than that (although more information would be required to accurately answer a specific "version" of the question).

The short answer is "It depends on where the line of code is written", followed by a number of different scenarioes with different rules & logic for the corresponding value.

 

 

However, if you are going by the language specification then you are to assume that gibberish is stored there.

We are writing C++ code, not coding a compiler.

 

 

 

I'm not trying to be mean, but this is textbook dunning kruger. You don't even realise what you don't know. Don't feel bad, C++ is a difficult language and most people don't understand all the corner cases.

 

I suggest you watch this video. If you still think C++ isn't hard to learn, you're either a genius or you haven't got experience to realise you're wrong.




#5193137 Building A Game Engine + Game

Posted by ChaosEngine on 16 November 2014 - 03:15 PM

C++ isn't hard to learn. Thats just a lie people use to sell new programming languages.

 
In that case, please answer the following simple question:
 
given the following code

int x;

what is value of x?

 

Maybe a few in this world are, like 2%-3% of the population.


eh? There are probably 20-30 million people (about 0.004% of the population) who actually write code in the whole world! 

Of those, there are probably around 2-3 million C++ programmers and of those, maybe 2-3% of them are experts, if that.

 

I would actually guess that the number of expert c++ programmers in the world is > 10000.




#5192348 Building A Game Engine + Game

Posted by ChaosEngine on 11 November 2014 - 08:25 PM

Before you even contemplate writing a game or an engine, you need to learn to program.

 

There are plenty of languages that are good for beginners; personally I'd recommend python or C#.

 


Call me old fashioned, but only wimps have to rely on an engine (and tbh, I believe that many devs in this day and age with such easy access to middleware engines lack the talent/skill to do it themselves, nor are they interested in learning to do so)

 

Yes, everyone should reinvent the wheel.... rolleyes.gif

 

Honestly, when was the last time you saw someone telling a chef they should build their own kitchen?




#5189575 function that returns class template

Posted by ChaosEngine on 27 October 2014 - 08:06 PM

Don't use underscores as a suffix prefix. note to self: don't post without coffee.

  • Reserved in any scope, including for use as implementation macros:
    • identifiers beginning with an underscore and an uppercase letter
    • identifiers containing adjacent underscores (or "double underscore")
  • Reserved in the global namespaces:
    • identifiers beginning with an underscore



#5188729 C++ header inclusion question

Posted by ChaosEngine on 23 October 2014 - 06:18 AM


Care to elaborate how this is a bad thing? I never ever had an error directly related to forward declaration, and having depencies spread is really a good thing - now if I have to include "X.h" into "Y.h" I can be asured that Y only has the barely minimum depencies that X relies on in its declaration, mostly due to templates/typedefs. Instead of having Y.h now suddenly contain every single include that might be there in the include-chain, which gives you nothing but increased compile times. Even with #pragma once, having all header-files included in other header-files will still lead to recompilation of half your project if you make a change to the header of certain classes.

 

Essentially DRY.

 

If you have a class (or more likely templated typedef) that you commonly forward declare, it's a good idea to put the forward declaration in a separate header file (AwesomeClass_fwd.h) and include that. 

 

As far as SeraphLances advice is concerned, I would say that including headers in headers is common enough to not be considered a deviation.

 

It's like saying "when driving, it's safest to stay below 20mph". It's certainly true, but not really practical. You're going to break that rule as soon as you want to do anything non-trivial. 






PARTNERS