Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating an update function for my game

Creating an update function for my game

Scheduled Pinned Locked Moved C / C++ / MFC
game-devgraphicshelptutorialquestion
7 Posts 3 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Calin Negru
    wrote on last edited by
    #1

    I was told that if I want to call invalidate rectangle the space between begin paint and end paint is not a good place to set the dimensions of rectangles, hence I`m trying to create an update function for my game, a place where I can set the position and dimension of rectangles and also compute all sorts of other things required in the game. I borrowed this code from a DirectX tutorial

    while (WM_QUIT != msg.message)
    {
    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);

    }
    else
    {
    	UpdateGame();
    }
    

    }

    but the execution never reaches UpdateGame(). Could you please help me out find a place for UpdateGame()?

    L C 2 Replies Last reply
    0
    • C Calin Negru

      I was told that if I want to call invalidate rectangle the space between begin paint and end paint is not a good place to set the dimensions of rectangles, hence I`m trying to create an update function for my game, a place where I can set the position and dimension of rectangles and also compute all sorts of other things required in the game. I borrowed this code from a DirectX tutorial

      while (WM_QUIT != msg.message)
      {
      if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
      TranslateMessage(&msg);
      DispatchMessage(&msg);

      }
      else
      {
      	UpdateGame();
      }
      

      }

      but the execution never reaches UpdateGame(). Could you please help me out find a place for UpdateGame()?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to provide more details about what you are trying to do here. Calling UpdateGame in the message loop as you show, will only work if there are no messages in the queue. And given the way Windows operates, this is not very likely. The only thing you should do in your WM_PAINT handler, is to update the screen. All calculations and measurements should be performed elsewhere.

      C 1 Reply Last reply
      0
      • C Calin Negru

        I was told that if I want to call invalidate rectangle the space between begin paint and end paint is not a good place to set the dimensions of rectangles, hence I`m trying to create an update function for my game, a place where I can set the position and dimension of rectangles and also compute all sorts of other things required in the game. I borrowed this code from a DirectX tutorial

        while (WM_QUIT != msg.message)
        {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
        TranslateMessage(&msg);
        DispatchMessage(&msg);

        }
        else
        {
        	UpdateGame();
        }
        

        }

        but the execution never reaches UpdateGame(). Could you please help me out find a place for UpdateGame()?

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        Quote:

        but the execution never reaches UpdateGame()

        Are you sure? Even here: The basic game loop · microsoft/DirectXTK12 Wiki · GitHub[^] such a loop is suggested (look at the bottom of the page).

        "In testa che avete, Signor di Ceprano?" -- Rigoletto

        1 Reply Last reply
        0
        • L Lost User

          You need to provide more details about what you are trying to do here. Calling UpdateGame in the message loop as you show, will only work if there are no messages in the queue. And given the way Windows operates, this is not very likely. The only thing you should do in your WM_PAINT handler, is to update the screen. All calculations and measurements should be performed elsewhere.

          C Offline
          C Offline
          Calin Negru
          wrote on last edited by
          #4

          Original post edited, I hope it makes sense now

          L 1 Reply Last reply
          0
          • C Calin Negru

            Original post edited, I hope it makes sense now

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            I just ran a quick test and the call to UpdateGame does indeed get called many times in a simple Window. You need to do some more debugging to find out why that does not happen in your code.

            C 1 Reply Last reply
            0
            • L Lost User

              I just ran a quick test and the call to UpdateGame does indeed get called many times in a simple Window. You need to do some more debugging to find out why that does not happen in your code.

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              Wow, you're a game developer, now! :thumbsup: :-D

              "In testa che avete, Signor di Ceprano?" -- Rigoletto

              L 1 Reply Last reply
              0
              • C CPallini

                Wow, you're a game developer, now! :thumbsup: :-D

                "In testa che avete, Signor di Ceprano?" -- Rigoletto

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                void UpdateGame()
                {
                MessageBox(hWnd, "Doing the update", "Game", MB_OK);
                }

                :laugh: :laugh:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups