How the GUI and game program work in comparison with web programs

I have been developing web applications for a long time and have dipped my finger in developing a graphical interface and a game.

In a web application (php for me), a request is made to a file that contains all the necessary files for processing information in memory, and then a stream from Top to Bottom for each request. (Mostly)

I know that for the Games, the action takes place in Game Loop, but how all the elements of the game are distributed in one cycle (menu system, gui, asset loading and 3d world) with constant loading and unloading of certain things.

The same goes for graphics programs, I believe that there is a "loop of applications."

Are most elements that are called into memory and then accessible are elements that are linked and loaded into memory when necessary?

What helped me to develop web applications faster, when I understood the program flow, it does not need to be detailed, just a general idea or pseudo-code.

+6
user-interface
source share
3 answers

There is almost always a cycle in all of these cases - but that’s not what you would think during most of your development.

If you take a step back, your web applications are based on a loop - accept() web server loop:

 while(listening) { get a socket connection; handle it; } 

.. but as a web developer, you are protected from this and write an "event-driven code" - when someone requests this URL, do it. "

GUIs are also event driven, and events are also detected in some kind of loop:

 while(running) { get mouse/keyboard/whatever event handle it } 

But the GUI developer does not need to think much about the loop. They write "when the mouse click here, do it."

Games, again. Someone should write a loop:

 while(game is in progress) { invoke every game object 'move one frame' method; poll for an input event; } 

... while other code is written in an event-driven style: "when the bullet object matches this object, fire an explosion event."

+14
source share

For applications and, to a lesser extent, games, the software is event driven. The user does something with a keyboard or mouse, and this event is sent to the rest of the software.

In games, the game loop is important because it focuses on screen processing and game state. Many games need real time. Thanks to the modern 3D graphics API, most of the screen processing can be reset to the GPU. However, the state of the game is monitored by the main circuit. Most of the team’s efforts for the game are focused on making the cycle handling very smooth.

For an application, typically complex processing is generated per thread. This is a tricky question due to issues with two things trying to access the same data. There are whole books on this subject.

For applications, the sequence

  • the user does X, X, and related information (for example, X, Y coordinates) is sent to UI_Controller.
  • The user interface determines which command to execute.
  • The command is executed.
  • Model / data changed.
  • The command tells UI_Controller to update various areas of the user interface.
  • UI_Controller redraws the user interface.
  • The command returns.
  • The application is waiting for the next event.

There are several options for this. A model can allow listeners to wait for changes in data. When the data, the listener executes and redraws the user interface.

+1
source share

As for game programming, I was just an amateur, but this is what I usually did:

I had an object, which was a very general concept of "Scenes" in the game. All major sections of the game derived from this scene object. A scene can really be anything, depending on the type of game. In any case, each more specific scene obtained from the scene had a procedure for loading all the necessary elements for this scene.

When the game consisted of changing scenes, the pointer to the active scene was set to a new scene, which then loaded all the objects it needed.

The shared Scene object had virtual functions, such as Load, Draw, and Logic, which were called at a specific time in the game loop from the active scene pointer. Each particular scene had its own ways of implementing these methods.

I do not know how this should be done or not, but it was very easy for me to control the flow of things. The concept of the scene also simplified the storage of several scenes as collections. With several pointers to the scene stored in the stack once a time, the scenes can be stored in reserve and maintain their full state upon return, or even do something like a dull one, but continue to draw while the active scene has drawn them as an overlay of views.

One way or another, if you do it this way, it is not as accurate as a web page, but I think if you think about it correctly, it will be quite similar.

+1
source share

All Articles