Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 18 Oct 2005
Offline Last Active Yesterday, 05:25 PM

#5313294 peekmessage while vs if (main/game loop)

Posted by on 29 September 2016 - 03:07 PM

Imagine you render scene with vsync turned on.
If you go with 'if' implementation, you will process single input event per rendered frame.
But there will be lots of events, especially when mouse moves. If you will process only one event, render frame, wait for 16ms (vsync on), then with simple mouse movement you will create some work for many seconds upfront. Scene update will lag to the point where app will become totally unresponsive.
So you must go with 'while' loop, processing all inputs before you start rendering.

With 'while' it sounds like waiting till a message occurs.

You don't wait for events with PeekMessage(), you would wait with GetMessage().

The if version won't run any update or rendering logic unless peekmessage returns false so it should work properly.
All game and rendering code is inside the else block, it should even be a tiny bit faster since it only has to do the check for VM_QUIT (and not the extra assignment and checks for run like the while version does)
It also has the advantage of exiting almost immediately on a VM_QUIT, the while version will run through one update before exiting.

#5304918 How Much Lua Should I Learn To Use Unitale.

Posted by on 09 August 2016 - 11:06 AM

Roughly 542 litres but it is highly dependent on your project so it is impossible to give an exact figure.


If you know how to program (in any language) you can just dive in and learn whatever it is you need for your project as you go along, Lua is not that different from other mainstream programming languages.

#5303665 Only 12 Enemies, And My Fps Drops To 30, Why Is That?

Posted by on 02 August 2016 - 09:56 AM

Guys, very big thanks to all for all the helpful answers, this morning I couldn't load 12 enemies, now I'm loading 70, I'm very happy.


Lactose, I haven't thought about that, and you are right, basically the bigger the fps is, the smaller the difference in milliseconds is. 


I was just wondering why my fps would jump from 100 to 111 every time, now when I think about it, 1000ms/100 = 10ms and 1000ms/111 = 9.09ms, and only the rounding error miscalculates the fps with 11!


EDIT: Alberth, I just installed some free profiler called VerySleepy, and it told me that printf takes 99% from the thread, and I checked all my code, I didn't have any printf functions at all.


But what I did have is "snprintf" and I guess verySleepy counts snprintf() at least as heavy as printf(). Luckily, I need this function to be executed only in the beginning of my game, not every frame, so I moved it out of the loop and fps jumped from 100 to 166! This snprintf is a very heavy function....

void MMORPG::getBoneLocation(Shader& shader)
    for (unsigned int i = 0 ; i < 100 ; i++)
        char Name[128];
        memset(Name, 0, sizeof(Name));
        snprintf(Name, sizeof(Name), "gBones[%d]", i);
        boneLocation[i] = glGetUniformLocation( shader.programID, Name );

EDIT: Guys, VerySleepy continues to show that printf takes 90-100% of some thread. I checked all parts of my source code, I even tried commenting everything, fps went crazy and the profiler still says that printf works in background somehow, although I checked multiple times that I don't have anything that says 'print' in my whole project.


First I thought that the reason is that my project is set up as a console application in codeblocks, but I changed it to a GUI application and it still cries about printf, I profiled the printf, and the only thing it shows is where the function is declared in stdio.h. Any ideas?


it could be any function that outputs data to stdout (the console / terminal / IDE), a lot of such functions could be implemented as wrappers around printf), normally stdout will be line buffered when it is tied to a terminal (each newline will cause the buffer to be flushed which is a fairly slow operation), if you need to push large amount of text to the console you should flush manually when appropriate (once per frame, between levels, when the app closes, once the buffer is full, or whatever suits your application)

if you use c++ you can call std::ios_base::sync_with_stdio(false); and then avoid using std::endl (just throw in \n for linebreaks and flush manuall using std::flush once per frame or something) and for C you can use setvbuf to change the buffer mode on stdout, just make sure you have a big enough buffer for your needs.


If you are using debug builds quite a few third party libraries will push data through stdout or stderr to your IDE, make sure you are using release builds when you are profiling.

#5294538 Building a game like "Game of War"

Posted by on 01 June 2016 - 03:32 PM

Ok. I have your attention. You guys are the experienced developers. You say it takes a lot of people and experience to make a game. I believe you. But when I look at the game it looks easy to me to make. If honestly it does take a lot of people and a lot of time I'll drop it. But I'll explain again.
I use a wallpaper for the kingdom. Designate spots for you to build buildings. I need visual art work for each building. 20 buildings. All the game mechanics are done. All it needs is coding. World map is a plain flat surface with resources to gather, kingdoms of other players and monsters to hunt. Can it really be that hard and time consuming? If I were to draw on paper and use things on papaer I can make the game on paper in 40 hours or less. Why does it make it so much harder to do on the programming side? You all make it sound like I'm building a hard game. Its not like star craft, wow, lol, charter. Those are hard games. No story. No videos. The game mechanics are finished. Can it really be that hard? :( combat system like chess with 7 units. That's all. U ether move or attack or skip turn. No spells. Turn based. It really can't be that difficult. I could careless for 3d high quality graphics right now. 2d pixel art is fine. 2d in general art is fine. It doesn't need to high quality graphics. Look at mine craft. Candy crush. Simple stupid graphics. Even angry birds. I don't need 3d amazing animation.

So I use unity and gimp. Any other programs I need?


You probably want something to record and mix sound and music as well. (Audacity is free and probably good enough to start with).


And yes, it can really be quite hard, the biggest challenge for you will most likely be to prevent rampant cheating while still keeping the server side scalable and fast. Doing one of those things is reasonably easy if you know what you are doing, doing both at the same time is extremely difficult, The client side programming of those games is fairly straight forward but you still want some high quality artwork (which is both time consuming and difficult to produce)

#5291896 Best gaming platform in the future with marketing perspective.

Posted by on 16 May 2016 - 11:36 AM

You'd be like the guys coding Cobol. They thought they'd have a job forever. However technology moves on, new languages appear, Cobol was discarded, and they're out of a job.

Cobol isn't quite dead yet, There are 17 open cobol positions in my city right now, (all at banks and government agencies), devs who are well past retirement age are being paid insane salaries to stick around and employers are prepared to spend months training junior devs in the language.

Technology may move quickly but big corporations and governments do not, Zombie technology may not be all that flashy and interesting but once big business critical systems have been built on any platform it becomes very difficult to kill it completely and you can build a great career supporting that crap.

#5289277 Does server's location affect players' ping?

Posted by on 29 April 2016 - 11:47 AM

How big is that tiny bit of latency? Currently it is > 100 for some(e.g. that korean had ~200), so some of them cannot play. I want it at least < 60.

the speed of light is roughly 300.000 km/s , the distance between germany and south korea is 8570km which means light would need ~56ms to travel back and forth between client and server if it could do so in a straight line without interruptions (i.e, if the earth was flat and you used lasers instead of cables)

#5286887 Multi-keypress movement in SDL2

Posted by on 14 April 2016 - 11:11 AM

don't move things when you process the events, flag the keys as pressed on key down, unflag on key up.
    key_pressed[...keysym.sym] = 1;
    key_pressed[...keysym.sym] = 0;


gameloop ...
    dt = Time::GetDeltaTime();
    dx = dt * (key_pressed[SDLK_RIGHT] - key_pressed[SDLK_LEFT])
    dy = dt * (key_pressed[SDLK_DOWN] - key_pressed[SDLK_UP])
    sprite->Move(dx, dy);

#5258234 Is there any space left for games about zombies?

Posted by on 20 October 2015 - 09:32 PM

I think there's more room for funny zombie games, especially if they make use of zombie animals rather than just humans.

I think there's room for both extremes really, animalistic zombies, and zombies that are basically people shuffling around. It's the middle ground that people seem to be getting sick of, where you have some special zombies, and most just shuffle around.
Specifically, games that have well thought out stories (or at least "deep" survival stories) seem to be doing well with zombies right now.

Personally i think the zombies are irrelevant.

What makes the game fun ? L4D for example is not fun because of the zombies, its fun because of how its mechanics push people to cooperate, You could take that game and move it to a sci-fi setting with aliens and it would still work.

#5256147 How can I improve my network performance?

Posted by on 07 October 2015 - 11:55 PM

Today I gathered my group together in which we had 6 of us trying out the networked game play. It didn't go too well. When there is only 2 of us everything works as expected and it's enjoyable. However, some strange discrepancies started occurring when there were 6 of us; 3 or more really. Individuals started to time-out mainly, some were even crashing for some unknown reasons. Mainly tho, the time-outs is what I'm concerned about. That isn't supposed to happen unless they don't receive a reply from the server after 30 seconds or so, or if they disconnect manually.
One of the strange things I noticed during the test on the Server log was multiple requests for the particular individual to exit the game, which was very strange because they weren't requesting to do so.
My network system is currently just TCP, which I think may be the root of my problem. I've been thinking that all of my packets should be guaranteed to be delivered timely since we are only working across LAN, I'm starting to become doubtful. However, another concern I suppose is maybe I am sending update messages to frequently.
Right now every .125 seconds and if the player's transform changed I send a message that looks like this:

// send our transform information to the other players
  transMsg << NetworkManager::GetInstance().GetServerCmdFromMessageType(MESSAGE_TYPE::Game)
           << "!SPECIFICOBJECTMESSAGE " << netCompRef.GenerateMessageID("UPDATEOBJTRANSFORM")
           << gameObj->m_Pos.GetX()   << NLDS << gameObj->m_Pos.GetY()   << NLDS << gameObj->m_Pos.GetZ()   << NLDS
           << playerCam->m_Rot.GetX() << NLDS << playerCam->m_Rot.GetY() << NLDS << playerCam->m_Rot.GetZ() << NLDS
           << gameObj->m_Scale << NLDS << "\r\n";
I'm also doing something not good for when we are shooting. Every bullet that is generate will send to the server the creation of the bullet, which since we have rapid fire now is definitely sending a ton of messages to the server, then back to the other connected clients. Also, another thing I was thinking is maybe my router's firewall is detecting the influx of packets and is thinking it's a DDOS or something, which then terminates the connection on that end. However, I don't think that's the case, but it might be possible.
Thanks for any insight in helping me improve my networking, I'm willing to hear any suggestions.

are you sending a long string for each message ? if so you should switch to a binary format, a 32 bit float uses 4 bytes, a 32 bit float encoded as a string tends to use 7+ bytes, things like "!SPECIFICOBJECTMESSAGE " is 23 bytes (could probably be replaced by a 1 or 2 byte number), you also get a nice chunk of CPU overhead from the encoding/decoding (converting numeric values to strings and concatenating them is not cheap)

Your timeout / disconnect problems are probably caused by something else though, (on a LAN you should be able to send tons of data without any problems)

#5255053 Virtual / abstract class variables / functions that are shared across all ins...

Posted by on 01 October 2015 - 03:31 PM


I consider myself to be very fluent with java syntax and I somewhat understand some parts of C# and C++. In java I have stumbled across a problem in my game programming that I cannot resolve, I have searched for a workaround or solution for the problem on different forums and websites, I also asked this in a few forums myself, however nothing nor' no one gave me any solution, adequate in my view, nor' convinced me that it's better to disallow a basic unimplemented solution that I myself and many other people have had as their first thought to this problem.

From my understanding, neither java nor' C++ allow the virtual / abstract modifier with the static modifier and I believe I understand why, considering what the static modifier does. However in java, you cannot force inherited classes to provide an implementation for an identifier (field or method) within a class that is shared across all instances of the class and can be accessed without the need to instantiate the class. I think this would be an extremely useful feature, but before replying, please do consider that, in computer science theory, I consider myself to be somewhat naive.

Kind Regards,

Why would you want to re-implement a static method in a child class ? since the static method won't use the instance anyway you can always access it using Baseclass.staticmethod() (from anywhere if it is public and from the child classes if it is protected)

#5254612 What exactly is API-First?

Posted by on 29 September 2015 - 09:53 AM

I can't help but keep returning to the fact that the OP's article is a terrible, strong-arm sales pitch aimed at non-technical managers of tech teams, trying to trick them into being hyped over a nonsense manufactured trend, which the author intends to profit from

Well, that sounds like every trend in the last 20 years. Anyone had their team agile-buzzword'ed lately?

Unfortunately no, our team got agile-made-up-word'ed instead since the company is innovative and unique. (I like the innovation but the made up words are confusing, with the usual buzzwords you can at least sort-of understand what the suits are referring to)

#5252526 SDL Key Delay

Posted by on 16 September 2015 - 09:51 AM

while (SDL_PollEvent(&ev) !=0)
		{ //inicio do eventHandle
			if (ev.type == SDL_QUIT || ev.key.keysym.sym == SDLK_ESCAPE)
				isRunning = false;
			if(ev.type == SDL_KEYDOWN)
					case SDLK_RIGHT:
						flipTheDog = frontDog;
						quadradoOrigem.x +=35;
						if (quadradoOrigem.x > 70)
							quadradoOrigem.x = 0;
Hello Again Guys!
Programming my first game in SDL, the Kakorro's Quest it was that I found a doubt..
I was programed the basic walk animation. Until here, it's all ok.
But, when i pressed a Key, and keep it pressed, the game takes a delay to recognize the next keypressed...
this causes a stop motion in the animation, like the dog walking animation, then stops for a little delay, then do the animation normally.
How i can fix that?
My code:

show more code.

you can simplify the inner loops but show the full structure (if you for example update game state and render inside the event polling while loop you will get significant delays on all events, not just keyboard events)

#5252209 Linux c++ debugging

Posted by on 14 September 2015 - 10:56 AM

I had no linux experience coming into my latest job. Some of our code is on linux and I'm so used to visual studio. I've used GDB as a debugger but it's a pain coming from Visual Studio. Are there any suggestions on programming tools on Linux?

Try QtCreator, it should provide a pretty decent graphical interface on top of gdb
other IDEs like code::blocks and eclipse should do the same

#5251371 System requirements

Posted by on 09 September 2015 - 10:44 AM

1.3 GHz is less than my phone. Quad-core will help with multiple file compilation but your linking time is going to be awfully long, since it needs single core power.
Not sure about graphics, but compare it other games: can you run Skyrim? Do you plan to make something better than Skyrim?

I want that when using tools like Unreal engine, VS, etc, not to get stuck, and  not to get messages like "... has stopped working" . I plan to develop 3D games, but not better than Skyrim, with not heavy graphics.

I wouldn't buy any laptop for any purpose these days unless it has SSD or atleast a hybrid drive, faster disk access makes even light office work smoother.

#5251194 Standard ML book?

Posted by on 08 September 2015 - 02:13 PM

Hi, any advise on a decent book about Standard ML book?
I need mostly exercises, level beginner to intermediate, not a reference manual.
Thank you.


That one is pretty good imho, each chapter ends with a series of exercises making it a pretty solid introduction to both SML and for functional programming in general.