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!


Satharis

Member Since 18 Oct 2007
Offline Last Active Jun 30 2015 01:39 AM

#5234014 Engine design, global interfaces

Posted by Satharis on 10 June 2015 - 02:31 AM

What the singleton debate really comes down to is not singletons, it is global state. I would say most code theorists or people that want to figure out better practices seem to come to the conclusion that global state causes more trouble than it solves and keeping code compartmentalized has many benefits, including simpler code reuse.

If I had one big complaint about these forums that might make sense to point out in a thread like this, its that a lot of people tend to get way too passionate about the designs they have run into over the years, they get through many failures and find what are probably good design patterns, but then they stop searching. They don't keep looking for even better ones they just come here and preach thme as "this is THE WAY it must be done."

If there was a "this is the way it must be done" we'd probably all be sitting outside on rock chairs looking at a sundial to tell the time of day.


#5233995 Special question about learning (STL and STD, etc.)

Posted by Satharis on 10 June 2015 - 12:09 AM

If you are learning I would try to do a 'real' project of some kind.

Yes.
 

Even something simple like a console program to calculate pi to a million places or something.

Er.. maybe. The entire point of making things to learn is to progressively set yourself bigger and bigger challenges. I could use a racing game as an example.

You might start racing on a simple circular track, you've never driven the car before and the controls, weight of the car and movement are foreign to you, you start in this simple track to learn these things, but after awhile you aren't going to get much better at handling your car just by driving that simple track. Moving on to more complex things a step at a time is the best way to get better at anything, coding included.

Using another racing analogy, books can help, you can learn about how the car works and read up on techniques to improve your driving, even watch other people play the game and such. But as anyone who has played a game after watching it will know, there is always a big difference between experience and study. You can watch ten different people drive one particular car on one particular track until you can recite every inch of it in your sleep, but you still won't learn the minute details of experience and feeling that come with doing it yourself.

A bit of a rant but I feel this part in particular requires a lot of emphasis, you can read an advanced graphics coding book front to back and unless you actually go and make things none of it is going to stick.
 

I don't think there is much point to learn STL. It's crap for game programming,

I don't know where you got that idea, I use standard library classes all the time, they're much more performant than what you or anyone you know is likely to write in any reasonable amount of time.
 

and if you get a job working for a company doing C++ they will probably have their own data structures.

They might, most of the time if thats the case it is because the environment(engine or whatever) came with that stuff already implemented to be a more performance intensive version for games.
The main weakness for stl classes in games is that they are very generic whereas games benefit much more from more specialized containers and algorithms.
 

It's also fairly complex and using it won't really teach you much as far as what's going on.

So you should avoid using helpful code because you don't understand how it works? I would postulate the opposite, that you should take advantage of useful and convenient code whenever you can and learn more about it when it strikes your fancy or when the knowledge will be useful to you. Using stl classes made me look up and learn a bit about a lot of things I had never used before.
 

You need to learn at a low level before you worry about high level APIs too much, basically.

You talk about jobs and such but at any job, especially as the new guy, you're not going to be making that low level stuff. They're just going to toss you into some corner of the code, lay out your clay cutting tools before you and say "make stars explode from this carrot" using more or less existing code. Yes knowing that low level stuff is helpful, in fact it makes you a much better programmer in the long run. But you shouldn't act like someone has to stop and learn how everything in the programming world works before they start writing any code. Oh and i'm not trying to downplay jobs, but in reality when you're new people don't know what they can trust you with, so they treat you like they would their potentially dumbest employee.

As a footnote, if you start writing a game and think about including that nice vector class and go "I bet I can write that better" you're already failing at game programming, quite honestly. What seperates good programmers from mediocre ones are being able to accept the fact that their skill will be required -when it is required- and you should try to avoid having to use it if possible. Don't rewrite a class just to rewrite a class, your mantra should be not to rewrite an stl class unless you have great need and benefit from doing so.


#5233262 Why don't game engines run in kernel mode?

Posted by Satharis on 06 June 2015 - 08:10 PM

This is kinda like saying cars are too slow, so rather than further develop the cars to reduce waste and improve their performance we just strap rockets to them.

Except in this case even if that didn't already sound like a bad idea, the rockets would barely carry the car's weight and have a high chance of exploding on ignition.


#5224084 Insurmountable limits on a touchscreen interface?

Posted by Satharis on 17 April 2015 - 04:16 PM

Only real way to know is to test it, make prototypes.

I've seen quite a few in development games(early access) that try to do new styles of gameplay using traditional mouse and keyboard, and it ends up extremely awkward simply because their idea of a control scheme doesn't match up with what the game wants you to be doing.

It isn't necessarily a point of "is this control type good enough for games of this style" it is more "can I pick a game design and control scheme that will feel good and workable on these platforms." I've tried shooters with touch screen and although it worked it does not in any way "feel good" in my opinion, things like that.

Take into consideration the limitations said above and think of how you can make it work.


#5220456 8 bit sprite animation

Posted by Satharis on 31 March 2015 - 04:43 AM

Interesting comments, the kind of 8 bit style I wanna make is like Pitfall, or a bit of more resolution (just a bit):
 
02m.png
 
Should I do all the draw manually? Or may I use a 3d software to generate sprites?

Using 3d software to make sprites like that is kind of like taking a priceless greek statue and then whacking it with a hammer until it is a roughly statue shaped block of stone.

I shouldn't really need to say that art like that should just be a bitmap.


#5220455 How best to represent data required for static and animated sprites?

Posted by Satharis on 31 March 2015 - 04:34 AM

Thanks for the advice chaps.
 

Separate the concepts of sprites and animations.

 
I've coded up a prototype in this vein and it definitely looks like the way to go. My sprites are now completely dumb, whilst all animations are managed by a dedicated animation system. This will allow me to do more complex things like chain animations together, cancel running animations etc, so cheers for that!


Probably one of the most effective things to learn for game development is to think of the different aspects of a game as being independant. In theory your game should be able to "play" without ever displaying anything, without ever playing sound, any of that. The moment you start making game logic rely on visuals is when things start getting taped together into a spider web. It also makes it much more difficult to change things.

In a way you can kind of think as visuals as a sort of peripheral, like you should be able to "unhook" them and even swap them out for some other pieces easily. You can technically think of it like model-view-controller but in reality it is more a design facet that the seperate systems of the game don't have much reason to be physically glued together, if anything they should just process relevant information.


#5218328 How to initialize a class member variable when using compositon?

Posted by Satharis on 22 March 2015 - 03:36 PM

I disagree,  the important part is to clearly document your constructors with doxygen or similar style comments, so that a programmer using the class can clearly see what it will do when constructed.

I personally don't care for implicit heavy lifting for that reason exactly, when I make a game class and fill it with objects I want to populate them and set them up when I run the actual game code, not simply the second I declare an instance of it in the main function.

I also find it particularly annoying that you have to look at the documentation for and read about every constructor just to know that it isn't doing a bunch of heavy lifting, and if it is then it forces that responsibility on any class that contains an instance of it. A window is a good example, if my game class has a window I shouldn't have to make it a pointer and call new just to be able to control when the window is actually created and shown, it shouldn't automagically do it just by being a member. I find that a very unflexible interface.
 

Also, I have no aversion to using exceptions if clearly documented. Exceptions are perfect for throwing errors from a constructor.

I've written code that throws from constructors, but the more chances you have to throw the bigger chance you'll end up in a spiral of death with one constructor throwing into another constructor. Frankly I just don't see a point to doing so unless there is an explicit need to do it in the constructor.


#5218316 How to initialize a class member variable when using compositon?

Posted by Satharis on 22 March 2015 - 02:52 PM

When in doubt, follow the example of the language's standard library. It is well designed and there is much to learn.

First, they initialize everything in their constructor. The fill in all the value that are necessary to initialize it.


What do they initialize it to? Generally they are initialized to an EMPTY state.

Create a string and you get an empty string. Create a vector, a map, a list, and you get an empty container. Create an fstream and you get an empty object not pointing to any file but still ready for use. You may provide additional constructors that do work, but those are not the default.

A common problem, especially here in For Beginners, is the thought that to "initialize" an object means reading from disk, parsing data, allocating resources, and doing other expensive operations. While you can provide alternate functions and constructors for that, you should have your default constructor initialize your objects to a clean, empty, usable state.

Finally, for the beginners, the concept of initializing with a constructor is an improvement from what was common back in the 1970s and earlier. First you would allocate the memory, and it would be 'random' data. The first instruction after a successful allocation was almost universally one or more lines of initialization. Usually that was a memset to zero, other times it was a memset to zero followed by setting a few individual actions away from zero. The constructor provides a nice way to do this without the two-step dance of allocate and initialize to zero.

This.

Actually if there is one rule when it comes to constructors(okay, programming in general) it is that everything is situational.

The only real job of a constructor is to initialize the object to sensible values that represent at least an EMPTY state, how much work you want to do in the constructor is completely situational and depends on a lot of factors.

Personally I prefer to do as little work as I can in the constructor unless it is cheap and simple and has little chance of needing to throw. Some people prefer the opposite. I just always found it a little offputting to think that if someone creates an instance of an object of mine then it would do a lot of heavy lifting and computation as a literal side effect of being constructed, rather than it happening when you explicitly ask for it(initialize functions.)

 

The important part is not to try and force some amazing consistancy between all your objects, the important part is to give them all a simple to understand interface.




#5218223 How to initialize a class member variable when using compositon?

Posted by Satharis on 22 March 2015 - 05:20 AM

What braindigitalis said is what I believe you want. But honestly your code is really convoluted.

This would do the same thing essentially:
 
#include <iostream>
using namespace std;

class Shape
{
public:
    Shape(double width, double length) : m_width(width), m_length(length)
    {
    
    }
    ~Shape() = default;
	
    double Area() const
    {
        return width * length;
    }
private:
    double m_width;
    double m_length;
};

int main()
{
    Shape rectShape(5.0, 5.0);
	
    // Do stuff with rectShape...
    double area = rectShape.Area();

    getchar();
    return 0;
}



#5217502 C++ do while error

Posted by Satharis on 18 March 2015 - 06:53 PM

I have to also question why your variable names are so utterly cryptic.

 

What would be the result of comparing a ca to a cc, do you know? I sure don't.




#5217170 Move Triangle in DirectX 11.1

Posted by Satharis on 17 March 2015 - 03:52 PM

This is stuff you should be looking up so I'm not going to detail extensively, however.

 

Usually to move things in a 3d world you modify the world transform for each object. You should have learned the basic idea already that the vertex shader(among other things) is essentially responsible for determining the final position of each vertex. It does that by multiplying the vertex position by the world-view-projection matrix, which is a matrix created by multiplying the world transform(essentially the position, rotation, scaling of the object in the world relative to the world origin) by the view and projection matrices(you can look that up.)

 

Hence to move the triangle you would change the world matrix, moving it in either direction based on which of your keys are hit. Usually you don't want to physically modify the vertices for each object. For a triangle that might seem strange but think of if your triangle was a model with 10k vertices. Moving each one by hand would be quite a nightmare.

 

Usually your most simplistic shader will take inputs for either the WVP matrix or the seperate matrices and combine them inside the shader, the difference lying in where you want to do the computation, on the cpu or on the gpu.




#5217164 is it possible to prevent a proggram(specialy a game) to get decompiled

Posted by Satharis on 17 March 2015 - 03:40 PM

Doing things client side in a mmo is only "fundamentally wrong" if cheating is your only concern.

More realistically it depends on many factors, including your business model. Having dumb servers and letting clients do most of the work can be pretty justified for a non subscription based game - especially if the gameplay is computationally demanding, for instance because it involves a detailed physic model.

Making the game hard enough to hack can suffice. It's an engineering compromise like everything else.

I can't really think of a time that is ever justified other than when you are working for a company or yourself and your concern of making money takes all precedence over making the game be fair. There is not "hard enough to hack" you're generally wasting time trying to make a game hard to hack because there is a very shallow line between "timmy with a text editor can modify this" vs the guy that will break through any encryption and indirection you have in place just because it will be a challenge to him.

 

I would say it is a case of morals in terms of going through with making a game you know you have not the interest or the design to safeguard from cheaters, if it is a competitive game. Of course for every competitive game out there out of a thousand people only 100 might actually stop playing if the game became one giant cheat fest, but the moral there is that the developers let it happen because they were more concerned with the product.

 

Personally I can't think of many MMO like designs where you have any excuse to have any important things be on the client only and have a dumb server. I don't agree with your justifying that. If my boss made me do it then sure I would do it, but I wouldn't enjoy doing it.




#5216950 is it possible to prevent a proggram(specialy a game) to get decompiled

Posted by Satharis on 16 March 2015 - 04:37 PM

 

I read the thread title and thought this would be a single player cheating thing.

In an mmo this really shouldn't even be a big issue to you, the client essentially cannot do anything without the authorization of the server, so the issue isn't trying to pretend the client is safe but to validate what the client says if the information is really important. You should never trust the client if you can help it, the only time MMO servers actually trust the client is when the effect is minimalistic and the alternative is a large performance loss, i.e. they don't necessarily do complex physics simulation to make sure the client is behaving precisely to spec, but they'll make sure they can't run super fast or go through walls.

 

The OP says he is working on an MMO and "handled many parts in clients". Many small-time games are designed by people without much of a clue or concern for security against cheats, and I'm sure there is some MMO out there that trusts the client on something it really shouldn't trust. An MMO is capable of being secured, but the developers have to actually do it. It could be a big issue if you have designed your game from the ground up to trust the client and then you have to move everything into the server.

 

I didn't really take his wording as meaning that but if he did indeed mean that then I couldn't really say much more than: "You're screwed, start moving stuff to the server." In a situation like that, there isn't really a way to protect the client from those of mal intent, as was mentioned above you don't even actually need a game client to start sending nonsense to a server, a server that trusts a client is just as likely to have a command line program send "I just killed joebob over there" as the client itself actually is.

 

Also yes there are plenty of MMO's out there that clientside things, and usually the developers make the decision to instead of moving the security to the server, they spend all their time trying to patch client holes that  people used, pouring more and more code on it to try and solve a fundamentally wrong design.




#5216667 is it possible to prevent a proggram(specialy a game) to get decompiled

Posted by Satharis on 15 March 2015 - 11:55 AM

I read the thread title and thought this would be a single player cheating thing.

In an mmo this really shouldn't even be a big issue to you, the client essentially cannot do anything without the authorization of the server, so the issue isn't trying to pretend the client is safe but to validate what the client says if the information is really important. You should never trust the client if you can help it, the only time MMO servers actually trust the client is when the effect is minimalistic and the alternative is a large performance loss, i.e. they don't necessarily do complex physics simulation to make sure the client is behaving precisely to spec, but they'll make sure they can't run super fast or go through walls.




#5216552 How to Acess a singleton from everywhere?

Posted by Satharis on 14 March 2015 - 10:03 PM

2) This is the problem with singletons and why you're being guided away from them. The order of initialization is not absolute.

This is actually wrong, singletons(at least by the design of the pattern) will always be constructed with the first call to whatever Get function you are using.

 

Static is a bit of a confusing keyword in C++ since it means different things in different places. The construction order issue is relegated to any kind of global object since global instances are not contained in a function there is no logical way to construct them from scoped code. In terms of global object the word static simply affects the linkage of the object.

 

A lot of people have issues with singletons for two seperate but related reasons. The first is that singletons are essentially masquerading globals, their construction is hidden in a function call but due to the Get call having to be static they are essentially globals, there will only be one created during the program lifetime and it is accessible from anywhere. The second issue and more prevalent one is that good engineering practice tends to say that globals are signals of bad code, they ironically create tight coupling by being accessible from anywhere because a complex weave of object interrelations begins to form between game and engine objects and the often large global "subsystems" that people make, i.e. a renderer, a state manager.

 

I can briefly go over the difference between a global and the different static constructs.

 

Global variables are technically any variable declared at global(program) scope. By itself a global isn't very useful, if you declare an int value in a header file and include it more than once it will cause linking errors(possibly compilation) since you will get multiply defined symbols. By declaring a global as extern and defining it ONCE(in a cpp file) all code can reference that one variable.

 

Which brings us to our uses of static:

  • Static on a global variable gives it internal linkage, this means the variable can be included by multiple files but each that includes it will get its own copy of the variable, they won't be shared and modifying one will not affect the others. Linkage basically refers to whether the variable will be visible and possibly accessible to other compilation units.
  • Static on a member variable is a bit different, it essentially means that the variable belongs to the class itself and only one will exist between all instances of the class.
  • Static on a member function has more or less the same effect as above, the function can be accessed through the class name itself and thus the function can't interact with any member variables of the class since it isn't actually part of any particular instance(there may not even be any.)
  • Static on a variable declared inside a function means the variable will be initialized only when the function is first called and will retain that state between function calls.

 

Using the above, a singleton must be created by at the very least having a static variable representing itself or in reference to itself. You could do that with a static function containing a static object declaration, that would create the object on first function call.

 

Either way the point is that a singleton is just a trick essentially in order to control the order of instantiation with a global, the same could be attained by only constructing globals with basic functionality and doing actual startup through an Init function. The book the OP referred to actually describes this quite a bit in detail, and he also later describes the singleton pattern as being semi-commonly used in game development but not necessarily ideal.






PARTNERS