Jump to content

  • Log In with Google      Sign In   
  • Create Account

Felix Ungman

Member Since 19 Nov 2007
Offline Last Active Oct 20 2016 06:44 AM

#5307003 Friends living abroad have really laggy connection to me, why?(using raknet,...

Posted by on 21 August 2016 - 05:37 AM

In UDP, instead of waiting for a dropped packet to be resent again, you can just make 100 copies of the same packet and send them all in case some of them are dropped. You kind of flood the network a little bit, but it's faster than the TCP way of handling dropped packets, which is what is needed in FPS games.


That's a bad idea. First, you would increase the bandwidth by two orders of magnitudes, which is not just a little bit. Second, today the majority of packet drops are caused by congestion, meaning that not just one but many packets are dropped, so if you send many at the same time you still risk losing them all.


Back to the original question, your solution is to not only send position but also velocity (and possibly acceleration, depending on the game), as well as a timestamp. On the other end you will then be able to calculate the expected position at any time from the last known values of these parameters. You can improve this further by using various techniques for interpolation and clock synchronization.

#5280923 Mobile multiplayer game

Posted by on 12 March 2016 - 01:40 PM

There are two problems here. One is to synchronize wall clock time, either by using a centralized reference (say ntp), or to guessing from the round-trip time between the clients. The other is synchronizing simulation time, which is solved by using a lookahead. If player 1 presses a button at simulation time T, the change is scheduled to take place at time T+D where D is sufficiently large to be sure that this information has been transmitted to player 2.

#5252291 Linux c++ debugging

Posted by on 14 September 2015 - 11:28 PM

I'm using CLion from JetBrains (the ReSharper folks), works great on all platforms, including Linux. Highly recommended for modern C++ development.

#5251106 C++11 lambda, modifying copied value

Posted by on 07 September 2015 - 11:59 PM

Using std::function for lambdas is like using std::vector for arrays. I tend to use both heavily (except in cases where I don't).


The advice is to know what you are doing and to know what it will cost you (but that's true for everything in C++!!).

#5248912 C++ duck typing with optional members

Posted by on 26 August 2015 - 12:08 AM


Some ideas: Put the FindMember classes inside a namespace, e.g. FindMember::Foo instead of FindMember_Foo. Instead of macro TRY_GET_MEMBER, overload operator ->* on these FindMember classes. 
std::vector<DrawItem*>* zpass = view->*FindMember::zpass<std::vector<DrawItem*>();

#5225780 c++ shared_ptr usage

Posted by on 27 April 2015 - 01:49 AM

I think in order to understand shared_ptr, you should first understand unique_ptr. To fully understand the unique_ptr you need to also understand move semantics (and e.g. how/why unique_ptr is very useful for factory methods). Then you can move on to cases where you need to access the same unique_ptr from different places, and need to convert the unique_ptr into a shared_ptr. And finally there's weak_ptr, that's useful in cases where you have circular references or cached objects. The point is, in order to understand unique_ptr you need to understand all three.

#5211412 What do you use for handling sounds?

Posted by on 18 February 2015 - 06:20 AM

I've found http://www.libsdl.org/projects/SDL_mixer/ a small, cross platform and easy to use alternative to OpenAL.

#5210222 I this going to be ok as a Network message class

Posted by on 12 February 2015 - 02:46 AM

You should take a look at https://developers.google.com/protocol-buffers/


It uses a domain-specific language to define your messages, and then pre-compiles it to C++ (or other languages). You'll end up with the corresponding message classes above, but it's much more convenient and readable, with less typing and less error-prone.

#5179815 How do you manage object pools in your engine/game?

Posted by on 12 September 2014 - 03:00 AM

I like to keep things simple and use the new and delete operators most of the time and don't worry that much about allocation. I'm confident that the implementation of new/delete doesn't do anything terribly stupid and that I would have to work really hard to do something better performance-wise. If I need to track objects I put them into an std::vector or sometimes a std::map. There are some cases where I have groups of large numbers of very small objects, and for those I instead use the operator new[] and delete[].

#5178247 GOTO, why are you adverse to using it

Posted by on 05 September 2014 - 01:26 AM

Oh, I use goto on a regular basis. I've used it twice in the last 10 years, which means I write about one goto statement every fifth year. I'm not adverse, but imho goto is lame, real programmers use comefrom.

#5177822 How Does a Noob Start Creating a Simulator?

Posted by on 03 September 2014 - 04:18 AM

Install some IDE, there are many good free ones like http://www.jetbrains.com/pycharm/ and try to do something really simple, like http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

Implementing Game of Life will highlight some of the basic concepts of writing simulation systems, yet it's possible to implement in few hundreds line of code.

#5177365 Online Course: Understanding Video Games

Posted by on 01 September 2014 - 12:29 AM

There's a course over at Coursera starting this week that seems worth checking out: https://www.coursera.org/course/uvg


An 11-lesson course teaching a comprehensive overview of analytical theory pertaining to video game media. Topics covered: play and game, emergence versus progression, game mechanics, story, interpretive theory, the culture of games, violence, sex and race in games, and finally, serious games. Estimated workload: 3-5 hrs/wk for non-credit; 7-10 hrs/wk for credit.

About the Course
Video games are a globally entrenched entertainment medium that entertains, informs and challenges us. These games are defined by, and define our modern culture. In this course, students will learn how to study games and engage in informed discussions about them. Ultimately, this course is about understanding the literacy of video games.
Understanding Video Games was created with the help of world renowned video game developer, BioWare Corp, located in Edmonton, Alberta.
The three main parts of the course are: 
1) developing the terminology that enables us to talk about video games; 
2) exploring how these terms are used in theoretical frameworks to interpret games, and; 
3) turning these theories toward cultural aspects of games in order to understand how the medium has impacted society. One of the most important insights students will gain from the course will be an understanding of the interplay between video game designers, players and the games themselves.




#5170132 Can somebody explain this code to me, please

Posted by on 29 July 2014 - 12:06 PM

I don't know perl, but isn't it supposed to be a write-only language?

#5154331 Member variable as template paramter

Posted by on 17 May 2014 - 04:11 PM

Ok, the example maybe didn't illustrate what I meant, a better one might be:  

class ButtonWidget
    std::function<void()> _onClick;

    void SetOnClick(std::function<void()> action) { _onClick = action; }

    void TrackClick()
        // ...
        if (_onClick)
        // ...

Then you can fix the data you want to hold in the lambda:

for (int i = 0; i < n; ++i) {
    int buttonNumber = i;
    button[i]->SetOnClick([buttonNumber]() {

Code is simple but powerful. I don't know how it relates to your framework or how you would need to rewrite it (it seems you use signals both for events and for data bindings, right?), but I've found the technique very useful in my own gui code.

#5153492 Opinion needed: returning values without null checks everywhere

Posted by on 14 May 2014 - 12:32 AM

Objective-C has an interesting take on this problem. If you have a nil object reference, calling a method is a no-op, and calling a function returns a default value (i.e. zero, false, or nil). Good coding practice is *not* checking the object for nil, but instead just send the message and checking the return value instead. Unfortunately there's no simple equivalent construction in C++.