Vanilla run_game_loop question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tom
    Apprentice
    • Dec 2020
    • 53

    Vanilla run_game_loop question

    Hey folks,

    I'm trying to get my head around the run_game_loop function in V 4.2.4. It contains 3 instances of this code:

    Code:
    	/* Keep processing the player until they use some energy or
    	 * another command is needed */
    	while (player->upkeep->playing) {
    		process_player();
    		if (player->upkeep->energy_use)
    			break;
    		else
    			return;
    	}
    Two of these instances happen before player energy is incremented by
    Code:
    			player->energy += turn_energy(player->state.speed);
    I don't understand what cases these are covering, and how the player would still have energy.
  • Nick
    Vanilla maintainer
    • Apr 2007
    • 9634

    #2
    It's because there are a lot of commands (looking at the inventory, inscribing, looking around, etc) that don't use energy - they're essentially UI commands rather than game commands. So the bigger loop is the ui-loop in ui-game.c:
    Code:
    		while (!player->is_dead && player->upkeep->playing) {
    			pre_turn_refresh();
    			cmd_get_hook(CTX_GAME);
    			run_game_loop();
    		}
    If the command this gets doesn't use energy, it is still the player's turn, so they get to do stuff until a command does use energy.
    One for the Dark Lord on his dark throne
    In the Land of Mordor where the Shadows lie.

    Comment

    • tom
      Apprentice
      • Dec 2020
      • 53

      #3
      Hmmmmmm. Thanks Nick. I'm experimenting with a sil-q style 'delving' power (to replace ranger/druid mapping), that uses distance from player (sound) to do the mapping. But that has necessitated propagating the sound a bit more often than the V game loop does. I guess the right thing to do is recalculate sound if the player has actually used some energy... but that might be multiple places

      Comment

      • backwardsEric
        Knight
        • Aug 2019
        • 527

        #4
        Originally posted by tom
        I guess the right thing to do is recalculate sound if the player has actually used some energy... but that might be multiple places
        Then you might check for that in game-world.c's process_player_cleanup() which is run after handling each player command.

        Comment

        • Nick
          Vanilla maintainer
          • Apr 2007
          • 9634

          #5
          Note too that Sil has game turns (turn) and player turns (player_turn) and its way of handling when things happen is a bit different. It also uses the old style game loop from before Angband 4.0.
          One for the Dark Lord on his dark throne
          In the Land of Mordor where the Shadows lie.

          Comment

          Working...
          😀
          😂
          🥰
          😘
          🤢
          😎
          😞
          😡
          👍
          👎