0

I'm working on a small game project and by mere curiosity I commented the line that makes a refresh to the main WINDOW object.

while(game->state)
    {
      //Move into player
      params->mov = player_1;
      params->x = player_1->pos_x;
      params->y = player_1->pos_y;
      params->game = game;
      //curs_set(FALSE);
      player_1->key_move(params);

      //Move into player
      mvwprintw(p_info,y, x, "TERRAIN: [%c]", player_1->inplace);

      //wrefresh(main_scene);           /* THE LINE I DELETED */
      wrefresh(p_info);
      sleep(TICK);

    }

The game ran without problems and player updated its position graphically. player_1->key_move(params) eventually calls wgetch(), mvwaddch(), and mvinch(), nothing else (from ncurses). wrefresh(p_info) was commented after and, as expected, that WINDOW object never updated. I'm wondering if that function calls wrefresh() at some point. There's no direct indication of this in the manual.

If it does, are there alternatives to mvwaddch() that doesn't update the WINDOW object?

Kolt Penny
  • 164
  • 1
  • 13

1 Answers1

0

According to man wgetch, and I quote:

If the window is not a pad, and it has been moved or modified since the last call to wrefresh, wrefresh will be called before another character is read.

Because this is a game, inside the loop, and more concrete in the routine call to player_1->key_move(params) there are modifications to the WINDOW object. This is why the program is causing such behaviour.

I realised that game logic was depending on state from the WINDOW, so several reads/writes would potentially come in the future. All game logic is to be handled separately.

Kolt Penny
  • 164
  • 1
  • 13