Hi guys.
I've looking around the main-win.c and main-sdl.c to try and figure out where the program loop runs. Essentially, I want to update screen elements and swap buffers inside the main processing loop. So I have been navigating the main code and watched as it disappeared into play_game().
Here's my journey to find the angband game controller...
-----------------------------------------------------------------------
main.c
main() --aka WinMain
entry to game. Reads files, "modules", settings, ui specific initization, and launches into play_game()
50'
dungeon.c
play_game()
Contains the whole lifecycle of the angband game (initializing, checking the term window, load saved, character birth, randomization seed, cave generation, ui flushing)
main loop is processing an endless number of "caves", handling each cave with dungeon()
100'
dungeon.c
dungeon(cave)
Updates a bunch of statistics, redraws status, checks level, checks item stacks, check torch radius (?!), gives energy to start, then loops
secondary loop is processing actions of characters on the "cave" (player->monsters->world-> reenergizing)
150'
dungeon.c
process_player()
updates resting, sets energy, runs repeat commands, movement, and normal commands.
third loop is waiting for energy usage to fill up to 100 while getting user commands
200'
game_cmd.c
process_command(cmd_context, bool repeatLast)
takes the ui command and runs non-movement associated actions
250'
game_cmd.c
cmd_get(cmd_context, gamecommand, bool wait)
looks for a repeating command, otherwises checks the cmd_head/tail to see if cmd_get_hook is required
300'
game_cmd.h
*cmd_get_hook(cmd_context, wait)
externally defined *pointer* function to be implemented by the UI
350'
main.c
cmd_get_hook
assigned to default_get_cmd
400'
main.c
default_get_cmd(cmd_context, wait) --aka win_get_cmd
Links to get_init_cmd() on CMD_INIT otherwise textui_get_cmd()
|
| 450'
| SPLIT 1
| main.c
| get_init_cmd()
| always waits for terminal response. Handles commands for newgame and loadfile
| calls pause_line(Term)
v
450'
SPLIT 2
textui.h
textui_get_cmd()
externally defined function to be implemented by the UI
500'
xtra3.c
textui_get_cmd(cmd_context, wait)
checks for get birth commands at get_birth_command() or processing game commands textui_process_command()
|
| 550'
| SPLIT 1
| ui-birth.c
| get_birth_command(wait)
| state machine for handling birth. calls various commands
| get_quickstart_command
| menu_question
| point_based_command
| roller_command
| get_name_command
| get_confirm_command
v
550'
SPLIT 2
cmd0.c
textui_process_command(wait)
calls for textui command and handles resize/mouse keyboard processing. Ignores the "wait" boolean that we've been tracking for the past few functions
600'
cmd0.c
textui_get_command()
handles keymapping mode, enters loop to get comand at inkey_ex(), and promptly break the loop before repeating.
650'
util.c
inkey_ex()
grabs any existing inkey_next, otherwise starts a loop to retrive a real value for ke.type. Flushes screen
700'
util.c
inkey_aux(int inkey_scan)
Scans Term_inkey looking to update ke. cuts off loop if there is "excessive delay"
750'
z-term.c
Term_inkey(ui_event, wait, take)
if waiting, loops, otherwise simply checks if the key_head and key_tail match, Calls Term_xtra(TERM_EXTRA_EVENT, wait) while waiting. Extracts keyvalue from term to *ch and logs the key
800'
z-term.c
Term_xtra(n, v)
calls the function Term->xtra_hook with n,v parameters
850'
main-xxx.c
Term->xtra_hook
adds a hook to ->xtra_hook as Term_xtra_xxx
900'
main-xxx.c
Term_xtra_xxx(n,v)
on type "TERM_XTRA_EVENT", calls the Term_xtra_xxx_event"
950'
main-xxx.c
Term_xtra_xxx_event(int)
main process loop for retriving ui input. loops until message appears, adding system sleep. Runs system calls to handle event.
-----------------------------------------------------------------------
Finish!
This is an extraordinarily intertwined UI and game command processing. I would think the code would be much simpler if game engine was fed commands from the UI instead of waiting around expecting commands.
Anyways,
I guess the terminal flushes its display at the inkey_ex() level? I cannot find the definition of the "excessive delay" cutoff, and I so I don't know the approximate time interval. It seems that handling the Term_xtra() for FLUSH is the way to go?
I could also use a good grep-like tool for finding all the global variables. Would anyone have a recommendation for a Windows user?
I've looking around the main-win.c and main-sdl.c to try and figure out where the program loop runs. Essentially, I want to update screen elements and swap buffers inside the main processing loop. So I have been navigating the main code and watched as it disappeared into play_game().
Here's my journey to find the angband game controller...
-----------------------------------------------------------------------
main.c
main() --aka WinMain
entry to game. Reads files, "modules", settings, ui specific initization, and launches into play_game()
50'
dungeon.c
play_game()
Contains the whole lifecycle of the angband game (initializing, checking the term window, load saved, character birth, randomization seed, cave generation, ui flushing)
main loop is processing an endless number of "caves", handling each cave with dungeon()
100'
dungeon.c
dungeon(cave)
Updates a bunch of statistics, redraws status, checks level, checks item stacks, check torch radius (?!), gives energy to start, then loops
secondary loop is processing actions of characters on the "cave" (player->monsters->world-> reenergizing)
150'
dungeon.c
process_player()
updates resting, sets energy, runs repeat commands, movement, and normal commands.
third loop is waiting for energy usage to fill up to 100 while getting user commands
200'
game_cmd.c
process_command(cmd_context, bool repeatLast)
takes the ui command and runs non-movement associated actions
250'
game_cmd.c
cmd_get(cmd_context, gamecommand, bool wait)
looks for a repeating command, otherwises checks the cmd_head/tail to see if cmd_get_hook is required
300'
game_cmd.h
*cmd_get_hook(cmd_context, wait)
externally defined *pointer* function to be implemented by the UI
350'
main.c
cmd_get_hook
assigned to default_get_cmd
400'
main.c
default_get_cmd(cmd_context, wait) --aka win_get_cmd
Links to get_init_cmd() on CMD_INIT otherwise textui_get_cmd()
|
| 450'
| SPLIT 1
| main.c
| get_init_cmd()
| always waits for terminal response. Handles commands for newgame and loadfile
| calls pause_line(Term)
v
450'
SPLIT 2
textui.h
textui_get_cmd()
externally defined function to be implemented by the UI
500'
xtra3.c
textui_get_cmd(cmd_context, wait)
checks for get birth commands at get_birth_command() or processing game commands textui_process_command()
|
| 550'
| SPLIT 1
| ui-birth.c
| get_birth_command(wait)
| state machine for handling birth. calls various commands
| get_quickstart_command
| menu_question
| point_based_command
| roller_command
| get_name_command
| get_confirm_command
v
550'
SPLIT 2
cmd0.c
textui_process_command(wait)
calls for textui command and handles resize/mouse keyboard processing. Ignores the "wait" boolean that we've been tracking for the past few functions
600'
cmd0.c
textui_get_command()
handles keymapping mode, enters loop to get comand at inkey_ex(), and promptly break the loop before repeating.
650'
util.c
inkey_ex()
grabs any existing inkey_next, otherwise starts a loop to retrive a real value for ke.type. Flushes screen
700'
util.c
inkey_aux(int inkey_scan)
Scans Term_inkey looking to update ke. cuts off loop if there is "excessive delay"
750'
z-term.c
Term_inkey(ui_event, wait, take)
if waiting, loops, otherwise simply checks if the key_head and key_tail match, Calls Term_xtra(TERM_EXTRA_EVENT, wait) while waiting. Extracts keyvalue from term to *ch and logs the key
800'
z-term.c
Term_xtra(n, v)
calls the function Term->xtra_hook with n,v parameters
850'
main-xxx.c
Term->xtra_hook
adds a hook to ->xtra_hook as Term_xtra_xxx
900'
main-xxx.c
Term_xtra_xxx(n,v)
on type "TERM_XTRA_EVENT", calls the Term_xtra_xxx_event"
950'
main-xxx.c
Term_xtra_xxx_event(int)
main process loop for retriving ui input. loops until message appears, adding system sleep. Runs system calls to handle event.
-----------------------------------------------------------------------
Finish!
This is an extraordinarily intertwined UI and game command processing. I would think the code would be much simpler if game engine was fed commands from the UI instead of waiting around expecting commands.
Anyways,
I guess the terminal flushes its display at the inkey_ex() level? I cannot find the definition of the "excessive delay" cutoff, and I so I don't know the approximate time interval. It seems that handling the Term_xtra() for FLUSH is the way to go?
I could also use a good grep-like tool for finding all the global variables. Would anyone have a recommendation for a Windows user?