How is GUI and Game Program Flow compared to Web programs

前端 未结 3 1549
粉色の甜心
粉色の甜心 2020-12-31 23:44

I\'ve been developing Web applications for a while now and have dipped my toe into GUI and Game application development.

In the web application (php for me), a reque

3条回答
  •  一向
    一向 (楼主)
    2021-01-01 00:05

    There's almost always a loop in all of these - but it's not something you would tend to think about during most of your development.

    If you take a step back, your web applications are based around a loop - the Web Server's accept() loop:

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

    .. but as a Web developer, you're shielded from that, and write 'event driven' code -- 'when someone requests this URL, do this'.

    GUIs are also event driven, and the events are also detected by a loop somewhere:

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

    But a GUI developer doesn't need to think about the loop much. They write 'when a mouse click occurs here, do this'.

    Games, again the same. Someone has to write a loop:

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

    ... while other code is written in a more event-driven style: 'when a bullet object coincides with this object, trigger an explosion event'.

提交回复
热议问题