Changeset 538

Show
Ignore:
Timestamp:
08/19/07 12:46:27 (1 year ago)
Author:
ajps
Message:

First stages of new game command interface thing. Seems to work OK on Windows and Linux, will have broken mac, ros, etc.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/Makefile.src

    r528 r538  
    3535        effects.o \ 
    3636        files.o \ 
     37        game-cmd.o \ 
    3738        generate.o \ 
    3839        init1.o \ 
  • trunk/src/dungeon.c

    r522 r538  
    17671767 * flag, which is a hack, but which optimizes loading of savefiles. 
    17681768 */ 
    1769 void play_game(bool new_game
     1769void play_game(void
    17701770{ 
     1771        /* Initialize */ 
     1772        bool new_game = init_angband(); 
     1773 
     1774 
     1775 
    17711776        /*** Do horrible, hacky things, to start the game off ***/ 
    17721777 
  • trunk/src/externs.h

    r532 r538  
    315315 
    316316/* dungeon.c */ 
    317 extern void play_game(bool new_game); 
     317extern void play_game(void); 
    318318extern int value_check_aux1(const object_type *o_ptr); 
    319319 
     
    344344extern void init_file_paths(const char *path); 
    345345extern void create_user_dirs(void); 
    346 extern void init_angband(void); 
     346extern bool init_angband(void); 
    347347extern void cleanup_angband(void); 
    348348 
  • trunk/src/init2.c

    r522 r538  
    1515#include "cmds.h" 
    1616#include "option.h" 
     17#include "ui-event.h" 
     18#include "game-cmd.h" 
    1719 
    1820/* 
     
    13511353 
    13521354 
    1353 /* 
    1354  * Hack -- take notes on line 23 
    1355  */ 
    1356 static void note(cptr str) 
    1357 { 
    1358         Term_erase(0, 23, 255); 
    1359         Term_putstr(20, 23, -1, TERM_WHITE, str); 
    1360         Term_fresh(); 
    1361 } 
    1362  
    1363  
    1364  
    1365 /* 
    1366  * Hack -- Explain a broken "lib" folder and quit (see below). 
    1367  */ 
    1368 static void init_angband_aux(cptr why) 
    1369 { 
    1370         quit_fmt("%s\n\n%s", why, 
    1371                  "The 'lib' directory is probably missing or broken.\n" 
    1372                  "Perhaps the archive was not extracted correctly.\n" 
    1373                  "See the 'readme.txt' file for more information."); 
    1374 } 
    1375  
    13761355 
    13771356/* 
     
    14221401 * if needed, in the first (?) pass through "TERM_XTRA_REACT". 
    14231402 */ 
    1424 void init_angband(void) 
    1425 
    1426         ang_file *fp; 
    1427  
    1428         char buf[1024]; 
    1429  
    1430         /* Set up the display handlers and things. */ 
    1431         init_display(); 
    1432  
    1433         /*** Verify the "news" file ***/ 
    1434  
    1435         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt"); 
    1436         if (!file_exists(buf)) 
    1437         { 
    1438                 char why[1024]; 
    1439  
    1440                 /* Crash and burn */ 
    1441                 strnfmt(why, sizeof(why), "Cannot access the '%s' file!", buf); 
    1442                 init_angband_aux(why); 
    1443         } 
    1444  
    1445  
    1446         /*** Display the "news" file ***/ 
    1447  
    1448         Term_clear(); 
    1449  
    1450         /* Open the News file */ 
    1451         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt"); 
    1452         fp = file_open(buf, MODE_READ, -1); 
    1453  
    1454         /* Dump */ 
    1455         if (fp) 
    1456         { 
    1457                 int i = 0; 
    1458  
    1459                 /* Dump the file to the screen */ 
    1460                 while (file_getl(fp, buf, sizeof(buf))) 
    1461                         Term_putstr(0, i++, -1, TERM_WHITE, buf); 
    1462  
    1463                 file_close(fp); 
    1464         } 
    1465  
    1466         /* Flush it */ 
    1467         Term_fresh(); 
    1468  
    1469  
     1403bool init_angband(void) 
     1404
     1405        ui_event_signal(ui_ENTER_INIT); 
    14701406 
    14711407        /* Initialize the menus */ 
     
    14751411        /*** Initialize some arrays ***/ 
    14761412 
    1477  
    14781413        /* Initialize size info */ 
    1479         note("[Initializing array sizes...]"); 
     1414        ui_event_signal_string(ui_INIT_STATUS, "Initializing array sizes..."); 
    14801415        if (init_z_info()) quit("Cannot initialize sizes"); 
    14811416 
    14821417        /* Initialize feature info */ 
    1483         note("[Initializing arrays... (features)]"); 
     1418        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (features)"); 
    14841419        if (init_f_info()) quit("Cannot initialize features"); 
    14851420 
    14861421        /* Initialize object info */ 
    1487         note("[Initializing arrays... (objects)]"); 
     1422        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (objects)"); 
    14881423        if (init_k_info()) quit("Cannot initialize objects"); 
    14891424 
    14901425        /* Initialize artifact info */ 
    1491         note("[Initializing arrays... (artifacts)]"); 
     1426        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (artifacts)"); 
    14921427        if (init_a_info()) quit("Cannot initialize artifacts"); 
    14931428 
    14941429        /* Initialize ego-item info */ 
    1495         note("[Initializing arrays... (ego-items)]"); 
     1430        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (ego-items"); 
    14961431        if (init_e_info()) quit("Cannot initialize ego-items"); 
    14971432 
    14981433        /* Initialize monster info */ 
    1499         note("[Initializing arrays... (monsters)]"); 
     1434        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (monsters)"); 
    15001435        if (init_r_info()) quit("Cannot initialize monsters"); 
    15011436 
    15021437        /* Initialize feature info */ 
    1503         note("[Initializing arrays... (vaults)]"); 
     1438        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (vaults)"); 
    15041439        if (init_v_info()) quit("Cannot initialize vaults"); 
    15051440 
    15061441        /* Initialize history info */ 
    1507         note("[Initializing arrays... (histories)]"); 
     1442        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (histories)"); 
    15081443        if (init_h_info()) quit("Cannot initialize histories"); 
    15091444 
    15101445        /* Initialize race info */ 
    1511         note("[Initializing arrays... (races)]"); 
     1446        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (races)"); 
    15121447        if (init_p_info()) quit("Cannot initialize races"); 
    15131448 
    15141449        /* Initialize class info */ 
    1515         note("[Initializing arrays... (classes)]"); 
     1450        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (classes)"); 
    15161451        if (init_c_info()) quit("Cannot initialize classes"); 
    15171452 
    15181453        /* Initialize owner info */ 
    1519         note("[Initializing arrays... (owners)]"); 
     1454        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (owners)"); 
    15201455        if (init_b_info()) quit("Cannot initialize owners"); 
    15211456 
    15221457        /* Initialize price info */ 
    1523         note("[Initializing arrays... (prices)]"); 
     1458        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (prices)"); 
    15241459        if (init_g_info()) quit("Cannot initialize prices"); 
    15251460 
    15261461        /* Initialize flavor info */ 
    1527         note("[Initializing arrays... (flavors)]"); 
     1462        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (flavors)"); 
    15281463        if (init_flavor_info()) quit("Cannot initialize flavors"); 
    15291464         
    15301465        /* Initialize spell info */ 
    1531         note("[Initializing arrays... (spells)]"); 
     1466        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (spells)"); 
    15321467        if (init_s_info()) quit("Cannot initialize spells"); 
    15331468 
    15341469        /* Initialize spellbook info */ 
    1535         note("[Initializing arrays... (spellbooks)]"); 
     1470        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (spellbooks)"); 
    15361471        init_books(); 
    15371472 
    15381473        /* Initialize some other arrays */ 
    1539         note("[Initializing arrays... (other)]"); 
     1474        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (other)"); 
    15401475        if (init_other()) quit("Cannot initialize other stuff"); 
    15411476 
    15421477        /* Initialize some other arrays */ 
    1543         note("[Initializing arrays... (alloc)]"); 
     1478        ui_event_signal_string(ui_INIT_STATUS, "Initializing arrays... (alloc)"); 
    15441479        if (init_alloc()) quit("Cannot initialize alloc stuff"); 
    15451480 
     
    15471482 
    15481483        /* Initialize feature info */ 
    1549         note("[Loading basic user pref file...]"); 
     1484        ui_event_signal_string(ui_INIT_STATUS, "Loading basic user pref file..."); 
    15501485 
    15511486        /* Process that file */ 
     
    15531488 
    15541489        /* Done */ 
    1555         note("[Initialization complete]"); 
     1490        ui_event_signal_string(ui_INIT_STATUS, "Initialization complete"); 
    15561491 
    15571492        /* Sneakily init command list */ 
    15581493        cmd_init(); 
     1494 
     1495        /* Ask for a "command" until we get one we like. */ 
     1496        while (1) 
     1497        { 
     1498                game_command command_req = get_game_command(); 
     1499 
     1500                if (command_req.command == CMD_QUIT) 
     1501                        quit(NULL); 
     1502 
     1503                else if (command_req.command == CMD_NEWGAME) 
     1504                        return TRUE; 
     1505 
     1506                else if (command_req.command == CMD_LOADFILE) 
     1507                        /* In future we might want to pass back or set the savefile 
     1508                           path here. */ 
     1509                        return FALSE; 
     1510        } 
    15591511} 
    15601512 
  • trunk/src/main-win.c

    r529 r538  
    661661}; 
    662662 
     663#include "game-cmd.h" 
     664 
     665static game_command cmd = { CMD_NULL, 0 }; 
     666 
    663667#if 0 
    664668/* 
     
    29462950        /* Next arg */ 
    29472951        p = strchr(s, ' '); 
    2948  
     2952         
    29492953        /* Tokenize */ 
    29502954        if (p) *p = '\0'; 
     
    29562960        validate_file(savefile); 
    29572961 
    2958         /* Game in progress */ 
    2959         game_in_progress = TRUE; 
    2960  
    2961         Term_fresh(); 
    2962  
    2963         /* Play game */ 
    2964         play_game(FALSE); 
    2965  
    2966         /* Quit */ 
    2967         quit(NULL); 
     2962        /* Set the command now so that we skip the "Open File" prompt. */ 
     2963        cmd.command = CMD_LOADFILE; 
    29682964} 
    29692965 
     
    31593155                        else 
    31603156                        { 
    3161                                 game_in_progress = TRUE; 
    3162                                 Term_flush(); 
    3163                                 play_game(TRUE); 
    3164                                 quit(NULL); 
     3157                                /* We'll return NEWGAME to the game. */ 
     3158                                cmd.command = CMD_NEWGAME; 
    31653159                        } 
    31663160                        break; 
     
    31943188                                        /* Load 'savefile' */ 
    31953189                                        validate_file(savefile); 
    3196                                         game_in_progress = TRUE; 
    3197                                         Term_flush(); 
    3198                                         play_game(FALSE); 
    3199                                         quit(NULL); 
     3190 
     3191                                        /* We'll return NEWGAME to the game. */ 
     3192                                        cmd.command = CMD_LOADFILE; 
    32003193                                } 
    32013194                        } 
     
    45544547 
    45554548        exit(0); 
     4549} 
     4550 
     4551 
     4552static game_command get_init_cmd() 
     4553{ 
     4554        MSG msg; 
     4555 
     4556        /* Prompt the user */ 
     4557        prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17); 
     4558        Term_fresh(); 
     4559 
     4560        /* Process messages forever */ 
     4561        while (cmd.command == CMD_NULL && GetMessage(&msg, NULL, 0, 0)) 
     4562        { 
     4563                TranslateMessage(&msg); 
     4564                DispatchMessage(&msg); 
     4565        } 
     4566 
     4567        /* Bit of a hack, we'll do this when we leave the INIT context in future. */ 
     4568        game_in_progress = TRUE; 
     4569 
     4570        return cmd; 
    45564571} 
    45574572 
     
    47094724        WNDCLASS wc; 
    47104725        HDC hdc; 
    4711         MSG msg; 
    47124726 
    47134727        /* Unused parameter */ 
     
    48434857        ANGBAND_SYS = "win"; 
    48444858 
    4845         /* Initialize */ 
    4846         init_angband(); 
    4847  
    4848         /* We are now initialized */ 
    4849         initialized = TRUE; 
    4850  
    48514859#ifdef USE_SAVER 
    48524860        if (screensaver) 
     
    48704878        check_for_save_file(lpCmdLine); 
    48714879 
    4872         /* Prompt the user */ 
    4873         prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17)
    4874         Term_fresh(); 
    4875  
    4876         /* Process messages forever */ 
    4877         while (GetMessage(&msg, NULL, 0, 0)) 
    4878         { 
    4879                 TranslateMessage(&msg); 
    4880                DispatchMessage(&msg); 
    4881         } 
     4880        /* Set command hook */ 
     4881        get_game_command = get_init_cmd
     4882 
     4883        /* Set up the display handlers and things. */ 
     4884        init_display(); 
     4885 
     4886        initialized = TRUE; 
     4887 
     4888        /* Play the game */ 
     4889        play_game(); 
    48824890 
    48834891        /* Paranoia */ 
  • trunk/src/main.c

    r529 r538  
    3030 
    3131#include "main.h" 
     32#include "game-cmd.h" 
    3233 
    3334 
     
    193194#endif /* SET_UID */ 
    194195 
     196static bool new_game; 
     197 
     198/* 
     199 * Pass the appropriate "Initialisation screen" command to the game, 
     200 * getting user input if needed. 
     201 */  
     202static game_command get_init_cmd() 
     203{ 
     204        game_command cmd; 
     205 
     206        /* Wait for response */ 
     207        pause_line(Term->hgt - 1); 
     208 
     209        if (new_game) 
     210                cmd.command = CMD_NEWGAME; 
     211        else 
     212                /* This might be modified to supply the filename in future. */ 
     213                cmd.command = CMD_LOADFILE; 
     214 
     215        return cmd; 
     216} 
     217 
    195218 
    196219/* 
     
    206229 
    207230        bool done = FALSE; 
    208         bool new_game = FALSE; 
    209231 
    210232        int show_score = 0; 
     
    435457        signals_init(); 
    436458 
    437         /* Initialize */ 
    438         init_angband(); 
    439  
    440         /* Hack -- If requested, display scores and quit */ 
    441         if (show_score > 0) display_scores(0, show_score); 
    442  
    443         /* Wait for response */ 
    444         pause_line(Term->hgt - 1); 
     459        /* Set up the command hooks */ 
     460        get_game_command = get_init_cmd; 
     461 
     462        /* Set up the display handlers and things. */ 
     463        init_display();       
    445464 
    446465        /* Play the game */ 
    447         play_game(new_game); 
     466        play_game(); 
    448467 
    449468        /* Free resources */ 
  • trunk/src/ui-event.c

    r536 r538  
    129129        ui_event_dispatch(type, &data); 
    130130} 
     131 
     132 
     133void ui_event_signal_string(ui_event_type type, const char *s) 
     134{ 
     135        ui_event_data data; 
     136        data.string = s; 
     137 
     138        ui_event_dispatch(type, &data); 
     139} 
  • trunk/src/ui-event.h

    r523 r538  
    3434        ui_MESSAGES_CHANGED, 
    3535 
    36         ui_event_REDRAW         /* It's the end of a "set" of events, so safe to update */ 
     36        ui_event_REDRAW,                /* It's the end of a "set" of events, so safe to update */ 
     37 
     38        ui_INIT_STATUS,         /* New status message for initialisation */ 
     39 
     40        /* Changing of the game state/context. */ 
     41        ui_ENTER_INIT, 
     42        ui_ENTER_BIRTH, 
     43        ui_ENTER_GAME, 
     44        ui_ENTER_STORE, 
     45        ui_ENTER_DEATH 
    3746} ui_event_type; 
    3847 
    39 #define  N_UI_EVENTS ui_event_REDRAW 
     48#define  N_UI_EVENTS ui_ENTER_DEATH 
    4049 
    4150typedef union 
     
    4655                int y; 
    4756        } point; 
     57 
     58        const char *string; 
    4859 
    4960} ui_event_data; 
     
    5768 
    5869void ui_event_signal_point(ui_event_type, int x, int y); 
     70void ui_event_signal_string(ui_event_type, const char *s); 
    5971void ui_event_signal(ui_event_type); 
    6072 
  • trunk/src/xtra3.c

    r534 r538  
    14601460 
    14611461/* ------------------------------------------------------------------------ 
     1462 * Showing and updating the splash screen. 
     1463 * ------------------------------------------------------------------------ */ 
     1464/* 
     1465 * Hack -- Explain a broken "lib" folder and quit (see below). 
     1466 */ 
     1467static void init_angband_aux(cptr why) 
     1468{ 
     1469        quit_fmt("%s\n\n%s", why, 
     1470                 "The 'lib' directory is probably missing or broken.\n" 
     1471                 "Perhaps the archive was not extracted correctly.\n" 
     1472                 "See the 'readme.txt' file for more information."); 
     1473} 
     1474 
     1475/* 
     1476 * Hack -- take notes on line 23 
     1477 */ 
     1478static void splashscreen_note(ui_event_type type, ui_event_data *data, void *user) 
     1479{ 
     1480        Term_erase(0, 23, 255); 
     1481        Term_putstr(20, 23, -1, TERM_WHITE, format("[%s]", data->string)); 
     1482        Term_fresh(); 
     1483} 
     1484 
     1485static void show_splashscreen(ui_event_type type, ui_event_data *data, void *user) 
     1486{ 
     1487        ang_file *fp; 
     1488 
     1489        char buf[1024]; 
     1490 
     1491        /*** Verify the "news" file ***/ 
     1492 
     1493        path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt"); 
     1494        if (!file_exists(buf)) 
     1495        { 
     1496                char why[1024]; 
     1497 
     1498                /* Crash and burn */ 
     1499                strnfmt(why, sizeof(why), "Cannot access the '%s' file!", buf); 
     1500                init_angband_aux(why); 
     1501        } 
     1502 
     1503 
     1504        /*** Display the "news" file ***/ 
     1505 
     1506        Term_clear(); 
     1507 
     1508        /* Open the News file */ 
     1509        path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt"); 
     1510        fp = file_open(buf, MODE_READ, -1); 
     1511 
     1512        /* Dump */ 
     1513        if (fp) 
     1514        { 
     1515                int i = 0; 
     1516 
     1517                /* Dump the file to the screen */ 
     1518                while (file_getl(fp, buf, sizeof(buf))) 
     1519                        Term_putstr(0, i++, -1, TERM_WHITE, buf); 
     1520 
     1521                file_close(fp); 
     1522        } 
     1523 
     1524        /* Flush it */ 
     1525        Term_fresh(); 
     1526} 
     1527 
     1528 
     1529/* ------------------------------------------------------------------------ 
    14621530 * Temporary (hopefully) hackish solutions. 
    14631531 * ------------------------------------------------------------------------ */ 
     
    14921560        /* Check if the panel should shift when the player's moved */ 
    14931561        ui_event_register(ui_PLAYER_MOVED, check_panel, NULL); 
    1494 
     1562 
     1563 
     1564        /* Set up our splashscreen handlers */ 
     1565        ui_event_register(ui_ENTER_INIT, show_splashscreen, NULL); 
     1566        ui_event_register(ui_INIT_STATUS, splashscreen_note, NULL); 
     1567