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!


Member Since 18 Oct 2007
Offline Last Active Mar 31 2015 07:44 PM

#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):
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.

#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.


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
    Shape(double width, double length) : m_width(width), m_length(length)
    ~Shape() = default;
    double Area() const
        return width * length;
    double m_width;
    double m_length;

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

    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.

#5216402 Compilation errors from Visual Studio 2010 visual C++ compiler

Posted by Satharis on 14 March 2015 - 01:12 AM


From what I can tell, you are trying to create a console application from a Win32 project.  The compiler is looking for "INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, INT )," but can't find it.  Thus, it is telling you that it can't find the Win32 entry point.  As "Nypyren" said, create a console application or go into properties and change the system to console.

This. I came up on this problem myself while learning Windows programming. Windows does not like "int main(...)" at all in Win32 projects! That only works with console applications.


Windows actually calls different startup functions depending on your linker settings. mainCRTStartup basically initializes the C runtime library and some other little things like calls global constructors before it calls the correct "main" function. So in terms of code its basically trying to call one particular function that does not exist, hence undefined symbol.

#5216398 Why learn game programming?

Posted by Satharis on 14 March 2015 - 12:50 AM

A variety of reasons:

  • You're interested in an AAA career and want to learn the kind of fundamentals that can get you a more low level coding job, not just the guy that can use Unity and what knowledge of C# you learned from it, knowledge that is likely missing very large and fundamental powerful tools of the language.
  • You want to create your own games from scratch as a fun learning exercise and don't require the power or complexity that a massive engine comes with.
  • You are an experienced programmer and for reasons such as licensing or the engine not fitting your needs, you'd rather roll your own code.

This topic has been explained in probably hundreds of threads before this one. The point is not "why do other people do it?" but "what are your particular needs." If you just want to make a game as a hobby there isn't anyone stopping you from using something like game maker or a user friendly engine like Unity.


Although to be honest if you're talking about making some fancy 3d shooter and whipping out a large build environment like Unreal or even to a lesser extent Unity, I'd be surprised if you get very far as a one person operation. Those engines are designed for people to make games as a product, they're industrial strength.

#5216373 Aiming to create an ARPG. Any tips?

Posted by Satharis on 13 March 2015 - 08:49 PM

To be honest coding for games is a lot of code and very little game. Yes you'll get to have the game come together, yes you'll be able to manipulate it and make it what you want, that is rewarding of course, especially getting to play it. But its like building a house, if you just like the idea of living in a house you're not necessarily going to want to learn the billion skills required to build one. Unless you find some joy in the process involved you're likely going to hate coding.

Don't get me wrong, I'm not trying to be a downer or mr. negative but if even learning the basics is boring to you, you're going to have a lot of trouble. You also need an extreme amount of patience, you might get stuck for hours on something really simplistic that just isn't working right and the answer may take forever to figure out.

#5215892 Where do I begin?

Posted by Satharis on 11 March 2015 - 01:39 PM

I would also recommend a dedicated programming environment such as Linux (CentOS is my flavor of choice) using only the command-line GNU compiler.

Of course someone always has to bring up Linux. Totally disagree, Windows is just as fine to learn on.

This will do many things to benefit you in the long run, from keeping it simple to helping you learn a non-Windows environment, if you don't already.

I fail to see how switching to a possibly completely foreign OS just to begin learning something brand new is "simple." When I first used Linux(mint) I found it completely confusing.

From there, don't even THINK about game development; not even Ro Sham Bo. That's the goal, but not the focus. You'll start with your obligatory "Hello World" and progress through to implementing your own data structures; linked lists, stacks, queues, and binary trees. Then you'll have a real solid understanding for the fundamental concepts that many budding programmers miss these days.

Also disagree here, you can make simple console games like hangman or pick a number or rock-paper-scissors without needing to know anything about linked lists, stacks, queues or binary trees. Frankly the first you shouldn't even have to implement any of those things if you even need them(because hurr, STL) if anything learning to make them is just an increase in knowledge and experience, but certainly not required early on or even making some pretty complex games.

There is some merit to the idea of learning to just use a text editor and a compiler on the command line to learn the process, but you could do that easily on windows with something like mingw and notepad++ just as simply as on linux. You don't need a fancy shell to run a compiler on a file or two, in fact it would give the opportunity to be creative, you could make a rudimentary build system similar to make by using a batch script, for example. If he wants to learn Linux that is up to the OP but I certainly wouldn't push it as being some magic tool.

#5215623 Resource Management

Posted by Satharis on 10 March 2015 - 04:10 AM

I really want to start coding but I'm stuck too much time on the design. This is really depressing =[

If there is one lesson that I've learned with coding it is that taking this inbuilt sense of "I have to do everything perfectly" that I have and throwing it out the window is the path to greatness.

Coding is one of those things where you more or less cannot design a useful system without having firsthand experience with it. That applies to any coding topic really. Sometimes the best thing to do is just jump in the deep end and fix problems when you run into them.


If anyone here started coding a game and were say, asked to code an input handling system and they just threw together some masterpiece of technology I would love to meet them, I would hazard a guess most of us made really pathetic attempts at new specializations of coding even if they had a ton of prior experience in the language, some stuff just takes revision to make pretty.


Looking at code and thinking that will teach you and you can just mimic their style also doesn't work, coding isn't like watching someone cut wood with a saw, it has thousands of levels of depth that only time and attempts and coding the thing yourself will really cement into your mind.