[Xmltools-development] xmltools2/xmltools/tests track.c
Status: Beta
Brought to you by:
nik_89
|
From: um, r. <sm...@us...> - 2004-11-14 12:00:38
|
Update of /cvsroot/xmltools/xmltools2/xmltools/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv531 Modified Files: track.c Log Message: exported xml stuff to another file Index: track.c =================================================================== RCS file: /cvsroot/xmltools/xmltools2/xmltools/tests/track.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** track.c 11 Nov 2004 22:26:56 -0000 1.7 --- track.c 14 Nov 2004 12:00:26 -0000 1.8 *************** *** 11,20 **** /* change back to track.h later. really this module only needs to know about * itself and won't be making any calls to other modules */ ! #include "racing.h" ! - #include "xmltools/xmltools.h" - static unsigned char mytrack[TRACK_WIDTH][TRACK_HEIGHT]; --- 11,17 ---- /* change back to track.h later. really this module only needs to know about * itself and won't be making any calls to other modules */ ! #include "track.h" static unsigned char mytrack[TRACK_WIDTH][TRACK_HEIGHT]; *************** *** 119,167 **** } /* constructors/destructors */ int Track_Init() { - memset(mytrack, 0, sizeof(unsigned char) * TRACK_WIDTH * TRACK_HEIGHT); Track_SetTile(3, 4, TT_HORIZONTAL); /* track start */ - - #if load_track - /* load the map from the save file */ - int a = 0; - if (a = open("save_racetrack.xml", 0644) == -1) - { - return 0; - } - close(a); - - Xmltool_GetXmlDesc("save_racetrack.xml"); - NODE_MAP *template = Nmap_GetData(); - - char num[5]; - a = 0; - NODE_MAP *n_map = NULL; - char *x, *y, *type; - while (a < 30) - { - memset(num, '\0', 5); - sprintf(num, "%d", a); - n_map = (NODE_MAP*)Xmltool_MReadXml("save_racetrack.xml", template->parent_name, "num", num); - x = (char*)Nmap_GetContent("x"); - y = (char*)Nmap_GetContent("y"); - type = (char*)Nmap_GetContent("type"); - - Track_SetTile(atoi(x), atoi(y), type[0] - 'A'); - a++; - } - int fd = 0; - if (fd = open("save_racetrack.xml", 0644) != -1) - unlink("save_racetrack.xml"); - close(fd); ! /* end of map loading */ #endif ! ! #if sample_debug_track /* debug sample track */ Track_SetTile(4, 4, TT_BOTTOMRIGHT_CORNER); --- 116,133 ---- } + /* constructors/destructors */ int Track_Init() { memset(mytrack, 0, sizeof(unsigned char) * TRACK_WIDTH * TRACK_HEIGHT); Track_SetTile(3, 4, TT_HORIZONTAL); /* track start */ ! #ifdef CFG_PERSISTENT_TRACK ! Persist_LoadTrack(); #endif ! ! //#if rigorous_debug_track ! #if 1 /* debug sample track */ Track_SetTile(4, 4, TT_BOTTOMRIGHT_CORNER); *************** *** 206,232 **** #endif - #if old_track_size - Track_SetTile(6, 4, TT_HORIZONTAL); - Track_SetTile(7, 4, TT_BOTTOMRIGHT_CORNER); - Track_SetTile(7, 3, TT_TOPRIGHT_CORNER); - Track_SetTile(6, 3, TT_BOTTOMLEFT_CORNER); - Track_SetTile(6, 2, TT_TOPLEFT_CORNER); - Track_SetTile(7, 2, TT_HORIZONTAL); - Track_SetTile(8, 2, TT_TOPRIGHT_CORNER); - Track_SetTile(8, 3, TT_VERTICAL); - Track_SetTile(8, 4, TT_VERTICAL); - Track_SetTile(8, 5, TT_BOTTOMRIGHT_CORNER); - Track_SetTile(7, 5, TT_TOPLEFT_CORNER); - Track_SetTile(7, 6, TT_BOTTOMRIGHT_CORNER); - Track_SetTile(6, 6, TT_HORIZONTAL); - Track_SetTile(5, 6, TT_HORIZONTAL); - Track_SetTile(4, 6, TT_BOTTOMLEFT_CORNER); - Track_SetTile(4, 5, TT_VERTICAL); - Track_SetTile(4, 4, TT_VERTICAL); - Track_SetTile(4, 3, TT_TOPLEFT_CORNER); - Track_SetTile(5, 3, TT_TOPRIGHT_CORNER); - Track_SetTile(5, 4, TT_BOTTOMLEFT_CORNER); - #endif - return 0; } --- 172,175 ---- *************** *** 234,278 **** int Track_Cleanup() { ! #if save_track /* save the track configuration if it is valid */ if (Track_IsValid()) ! { ! char *savefile = "save_racetrack.xml"; ! int x = 0; ! int y = 0, a = 0; ! char strx[20], stry[20], type[5], num[5]; ! Nmap_Clear(); ! while (y < 5) ! { ! printf("here\n"); ! memset(strx, '\0', 20); ! memset(stry, '\0', 20); ! memset(type, '\0', 5); ! memset(num, '\0', 5); ! ! sprintf(strx, "%d", x); ! sprintf(stry, "%d", y); ! sprintf(num, "%d", a); ! type[0] = mytrack[x][y] + 'A'; ! ! /* printf("num %s type %s\n x-y(%s-%s)\n", num, type, strx, stry); */ ! ! Nmap_Add("track", "num", num); ! Nmap_Add("track", "type", type); ! Nmap_Add("track", "x", strx); ! Nmap_Add("track", "y", stry); ! Xmltool_MAddXml(savefile); ! ! x++; ! if (x >= 6) ! { ! y++; ! x = 0; ! } ! a++; ! } ! printf("saved racetrack successfully\n"); ! } #endif return 0; } --- 177,186 ---- int Track_Cleanup() { ! #ifdef CFG_PERSISTENT_TRACK /* save the track configuration if it is valid */ if (Track_IsValid()) ! Persist_SaveTrack(); #endif + return 0; } |