int main(int argc, char **argv) { DARNIT_TILEMAP *tm; DARNIT_TILESHEET *ts; int i, j; d_init("isotest", "isotest", NULL); ts = d_render_tilesheet_isom_load("isosheet.png", 64, 64, DARNIT_PFORMAT_RGB5A1); tm = d_tilemap_isom_new(0, ts, 0xFF, 32, 16, 32); d_render_blend_enable(); d_tilemap_recalc(tm); for (i = 0;; i++) { j = i % 1200; if (j > 600) j = j + (2*(j - 600)) * -1; j *= -1; j += 300; d_tilemap_camera_move(tm, 0, 0); d_render_begin(); d_render_blend_enable(); d_tilemap_draw(tm); d_render_end(); d_loop(); } d_quit(); }
int main(int argc, char **argv) { DARNIT_TILESHEET *ts; DARNIT_TILEMAP *tm; int i, t; d_init("orthotest", "orthotest", NULL); ts = d_render_tilesheet_load("grid.png", 24, 24, DARNIT_PFORMAT_RGB5A1); tm = d_tilemap_new(0xFFF, ts, 0xFFF, 10, 18); for (i = 0; i < 180; i++) tm->data[i] = 1; d_tilemap_recalc(tm); d_tilemap_camera_move(tm, -1, 0); t = d_time_get(); for (i = 0;; i++) { fprintf(stderr, "Moving camera %i\n", -i / 30); d_tilemap_camera_move(tm, 0, -i / 30); d_render_begin(); d_tilemap_draw(tm); d_render_end(); d_loop(); } d_quit(); }
int main(int argc, char **argv) { d_init("pong", "Pong!", NULL); if (!init()) { fprintf(stderr, "libDarnit didn't init\n"); return -1; } d_render_clearcolor_set(0, 0, 192); for (;;) { player_loop(); ball_loop(); d_render_begin(); d_render_tile_blit(p.player_ts, 0, p.player.x, p.player.y / 1000); d_render_end(); d_loop(); } d_quit(); return 0; }
int main(int argc, char **argv) { DARNIT_SPRITE *sprite; if (argc <3) { fprintf(stdout, "Usage: %s <sprite> <direction>\n", argv[0]); return -1; } if (d_init("libDarnit spriteview", "spriteview", NULL) == NULL) { fprintf(stderr, "libDarnit failed to init\n"); return -1; } if ((sprite = d_sprite_load(argv[1], atoi(argv[2]), DARNIT_PFORMAT_RGB5A1)) == NULL) { fprintf(stderr, "Unable to open sprite %s\n", argv[1]); d_quit(); return -1; } d_sprite_move(sprite, 0, 0); d_sprite_animate_start(sprite); d_render_blend_enable(); for (;;) { d_render_begin(); d_sprite_draw(sprite); d_render_end(); d_loop(); } return 0; }
int main(int argc, char **argv) { DARNIT_IMAGE_DATA img; DARNIT_TILESHEET *ts; IMG_STRUCT **imgs, **tmp; DARNIT_KEYS keys; int images, image_disp, i; imgs = NULL; images = 0; image_disp = 0; if (argc < 2) { fprintf(stderr, "Usage: %s <image to analyze>\n", argv[0]); return -1; } d_init("algdata", "algdata", NULL); if (!((img = d_img_load_raw(argv[1])).data)) { fprintf(stderr, "Unable to load %s\n", argv[1]); d_quit(); } d_render_clearcolor_set(255, 255, 255); do { i = 0; ts = next_image(img, &i); if (ts) { if (!(tmp = realloc(imgs, sizeof(IMG_STRUCT **) * (images + 1)))) d_quit(); imgs = tmp; imgs[images] = new_image(ts, i); images++; } } while (ts); if (!imgs) d_quit(); sort_image(imgs, images); for (;;) { keys = d_keys_get(); if (keys.start) { image_disp = (image_disp + 1 >= images) ? 0 : image_disp + 1; d_keys_set(keys); } d_render_begin(); d_render_tile_blit(imgs[image_disp]->ts, 0, 0, 0); d_render_end(); d_loop(); } return 0; }
FUNCTION static CODE index_bld( struct SFILE *tsfile, /* in: SFILE for message text file */ struct FSBLOCK *tfsblock, /* in: FSBLOCK for text file */ struct SFILE *isfile, /* out: SFILE for index file */ COUNT ilun /* in: lun to use for index file */ ) { struct DIRBLK dirblk; /* directive block for text file */ struct INXREC inxrec; /* output record */ TEXT key[STRINGSIZ+1]; TEXT dirctv[STRINGSIZ+1]; CODE code; static TEXT *sys_char[1] = {""}; /* all values okay */ /* open index file with same name and library */ code = f_open(isfile, ilun, (*tfsblock).libr, (*tfsblock).name, INX_TYPE, F_WRITE); if (code != SUCCESS) { parm_err("Could not open index file in library '%s'.", "TAE-INXOPEN", (uintptr_t)(*tfsblock).libr,0,0); return(FAIL); } d_init(&dirblk, tsfile, (*tfsblock).libr, sys_char, 1); /* initialize for d_ calls */ do { code = d_dirctv(&dirblk, dirctv, key); /* read next directive record */ if (s_equal(dirctv, ".end") || code != SUCCESS ) break; /* end of file */ if (!s_equal(dirctv, ".key")) /* not key specification */ { parm_err("Invalid directive '%s' encountered .", "TAE-INVDIR", (uintptr_t)dirctv,0,0); return(FAIL); } bytmov((GENPTR) key, (GENPTR) inxrec.key, KEYSIZ+1); /* copy key */ MOVE_STRUCT((*tsfile).posctx, inxrec.posctx); /* copy position context */ code = f_bwrite(isfile, (GENPTR) &inxrec, sizeof(inxrec)); /* write to file */ } while (code == SUCCESS); if (code == D_EOF) /* end of message text file */ { code = SUCCESS; f_close(isfile, F_KEEP); /* close index file */ } f_close(tsfile, F_KEEP); /* close text file */ return(code); }
/*----------------------------------------------------------------------------- [Init] -----------------------------------------------------------------------------*/ BOOL AOUT_Init( Sint32 soundType, //Kitao追加 Uint32 bufSize, // in samples Uint32 sampleRate, void (*pCallBack)(int ch, Sint16* pBuf, Sint32 nSamples)) //Kitao更新。ch(チャンネルナンバー)を追加 { if (d_init(soundType, WINMAIN_GetHwnd(), 2, (WORD)sampleRate, 16, (DWORD)bufSize*2*2)) { _pCallBack = pCallBack; return TRUE; } return FALSE; }
int main (int argc, char *argv[]) { GtkWidget *window; gtk_init (&argc, &argv); t_init (); window = d_init ( ); gtk_widget_show_all (window); gtk_main (); return 0; }
int main(int argc, char **argv) { int i, j; struct GRAPH *g, *tree=NULL; struct VERTEX *v; struct POINT p; DARNIT_KEYS keys; srand(time(NULL)); d_init("Graphs", "uppg8", NULL); for(i=0; i<256; i++) { circle[i]=d_render_circle_new(32, 1); line[i]=d_render_line_new(1, 1); } for(j=0; j<4; j++) for(i=0; i<7; i++) { p.x=i*100+50;//(rand()%80)*10; p.y=j*100+50;//(rand()%48)*10; v=graph_add_vertex(&graph, p); for(g=graph; g; g=g->next) if(!(rand()%6)) graph_add_edge(v, g->vertex, rand()%100, DIRECTION_DOUBLE); } tree=graph_prim(graph); draw_graph(graph); for(g=graph;;) { keys=d_keys_get(); if(keys.start) { g=g==graph?tree:graph; draw_graph(g); } d_keys_set(keys); d_render_begin(); d_render_tint(0xFF, 0xFF, 0xFF, 0xFF); for(i=0; i<vertices; i++) d_render_circle_draw(circle[i]); for(i=0; i<edges; i++) { d_render_tint(length[i], 0x7F, 0x0, 0xFF); d_render_line_draw(line[i], 1); } d_render_end(); d_loop(); } d_quit(); return 0; }
///Main function! Kind of. int crawl(char *start_url, int download_workers, int parse_workers, int queue_size, char * (*_fetch_fn)(char *url), void (*_edge_fn)(char *from, char *to)) { //start code here: pthread_initialize(); //assign queue_size to global var dq_size = queue_size; _fetch_function = _fetch_fn; _edge_function = _edge_fn; p_init(); d_init(); dfill(start_url); check_visited(start_url); pthread_t pid[download_workers], cid[parse_workers]; int i; for(i = 0; i < download_workers; i++){ pthread_create(&pid[i], NULL, download_thread, NULL); } for(i = 0; i < parse_workers; i++){ pthread_create(&cid[i], NULL, parse_thread, NULL); } pthread_mutex_lock(&w_lock); while(work > 0){ pthread_cond_wait(&done, &w_lock); } pthread_mutex_unlock(&w_lock); return 0; }
static void init() { int i; DARNIT_INPUT_MAP map; d_init("pewpewtris", "pewpewtris", NULL); d_fs_mount_self(); d_fs_mount("music.ldi"); d_fs_mount("sounds.ldi"); config_init(); ppt.ui.offset_x = 288; ppt.ui.offset_y = 0; for (i = 0; i < 180; ppt.tile_lookup[i++] = -1); ppt.block = d_render_tilesheet_load("res/block.png", 24, 24, DARNIT_PFORMAT_RGB5A1); ppt.tile = d_render_tile_new(10 * 18, ppt.block); ppt.bbox = d_bbox_new(180); d_bbox_set_indexkey(ppt.bbox); ppt.tm = d_tilemap_new(0xFFF, ppt.block, 0xFFF, 10, 18); ppt.request_new = 0; ppt.font = d_font_load("res/font.ttf", 28, 256, 256); ui_init(); bullet_init(30); highscore_init(); state_init(); music_init(); ppt.ui.play_background = d_map_load("res/playfield_background.ldmz"); ppt.ui.menu_background = d_map_load("res/mainmenu_background.ldmz"); ppt.ui.highscore_background = d_map_load("res/highscore_background.ldmz"); /* Re-map B to space */ if (!(d_platform_get().platform & DARNIT_PLATFORM_PANDORA)) { map = d_keymapping_get(); map.b = TPW_KEY_SPACE; d_keymapping_set(map); } block_particle_init(); /* FIXME: Remove */ ppt.fps = d_text_surface_new(ppt.font, 6, 1000, 0, 0); }
int main(int argc, char *argv[]) { bool found_tag = false; bool do_print = false; dstr line = ""; dstr prefix = ""; d_init(argc, argv); while (d_getline(line)) { if (d_match(line, "/[*] (Function|Type|Enum): (.*)")) { found_tag = true; do_print = false; d_assign(prefix, d_submatch(2)); continue; } if (found_tag && d_match(line, "^ ?\\*/")) { found_tag = false; do_print = true; continue; } if (d_match(line, "^\\{|^$")) { do_print = false; continue; } /* Prototype ends on blank line. */ /* TODO: Should the above regexp match it? If so it doesn't here... */ if (line[0] == 0) { do_print = false; continue; } if (do_print) { printf("%s: %s\n", prefix, line); } if (d_match(line, "\\{ *$|; *$")) { do_print = false; } } return 0; }
int main(int argc, char *argv[]) { dstr line; Aatree * root = &aa_nil; d_init(argc, argv); d_printf("# Index\n"); while ((d_getline(line))) { if (d_match(line, "^\\[([^\\]]*)")) { const char *ref = d_submatch(1); char *s = xstrdup(ref); root = aa_insert(root, s, s); } } pre_order_traversal(root, print_link); aa_destroy(root); return 0; }
FUNCTION CODE hard_help ( struct SFILE *fctx, /* In: file context block for opened file */ TEXT curlib[], /* In: library name of opened file */ TEXT procname[], /* In: proc name for LHS of help display */ TEXT outname[], /* In: name of output file */ struct HELPBLK *helpblk /* out: help output control block */ ) { IMPORT struct VARIABLE *char_gbl; /* system characteristics */ struct DIRBLK dirblk; /* directive control block */ struct TXTSTOR title; /* context for dynamically stored title text */ struct SFILE f; struct POSCTX saved_pos; struct POSCTX level2_pos; BOOL has_level2; TEXT str[STRINGSIZ+1]; CODE code; TEXT field[STRINGSIZ+1]; /* text field after a directive */ TEXT name[STRINGSIZ+1]; TEXT key[KEYSIZ+1]; TEXT msg[STRINGSIZ+1]; /* If no output name was given, */ if (NULLSTR(outname)) /* use pdf or command name */ { f_name(procname, outname); s_append(".MEM", outname); /* procname.MEM for output */ } /* note -- SAVELUN is safe because |save| qual is not allowed for this command */ code = f_ophf(&f, SAVELUN, outname, F_WRITE); /* open output file */ if (code != SUCCESS) { sprintf(msg, "Error opening output, host code = %d", f.host_code); store_help_error(helpblk, msg, "TAE-OPNWRT"); return(FAIL); } d_init(&dirblk, fctx, curlib, (TEXT **)(*char_gbl).v_cvp, (*char_gbl).v_count); /* init directive block */ if ((*helpblk).compiled) /* if PDF is compiled */ { if ((code = prep_c_help(&dirblk, &title, msg, key)) != SUCCESS) /* prepare*/ goto put_error; str[0] = EOS; } else /* PDF is not compiled */ { code = d_dirctv(&dirblk, str, field); if (s_equal(str, ".TITLE")) { /* read the title into dynamic store */ if ((code = gettitle(&dirblk, &title, msg, key))!= SUCCESS) goto put_error; code = d_dirctv(&dirblk, str, field); } else /* no title */ { title.numline = 0; } } code = put_title(&f, &title, msg, key); /* start filling output file */ if (code != SUCCESS) goto put_error; if (title.tp != NULL) fretxt(&title); /* free the dyamically-stored title */ /* str should contain .HELP directive now. If not, find it */ if (! s_equal( str, ".HELP")) { code = d_search(&dirblk, ".HELP", field); if (code != SUCCESS) { store_help_error(helpblk, "No help available on '%s'.", "TAE-NOHELP"); return (FAIL); } } code = put_text_block(&f, &dirblk, msg, key); /* output general help */ if (code != SUCCESS) goto put_error; code = d_search(&dirblk, ".LEVEL1", field); if (code != SUCCESS) /* if there is no level1 help then */ goto return_success; /* assume we are done and exit */ f_movpos(CURRENT_POS, &saved_pos); /* save position in input */ code = d_search(&dirblk, ".LEVEL2", field); /* find detailed help */ has_level2 = (code == SUCCESS); if (has_level2) /* if detailed help exists, */ f_movpos(CURRENT_POS, &level2_pos); /* save the position in file */ f_setpos(dirblk.sfileptr, &saved_pos); /* reset position to curr pos */ code = d_dirctv(&dirblk, str, name); /* gives str=".TITLE" */ while (1) { code = d_dirctv(&dirblk, str, name); if (code != SUCCESS) /* if no more directives, we */ break; /* are done */ if (s_equal(str, ".END") || s_equal(str, ".LEVEL2")) /* done */ break; code = put_header(&f, &dirblk, str, name, msg, key); if (code != SUCCESS) goto put_error; if (has_level2) code = put_level2_text(&f, &dirblk, &level2_pos, str, name, msg, key); if (code != SUCCESS) goto put_error; } return_success: f_close(&f, F_KEEP); s_lower(outname); sprintf(msg, "Wrote file \"%s\".", outname); put_stdout(msg); return (SUCCESS); put_error: store_help_error(helpblk, msg, key); return (FAIL); }
FUNCTION static CODE tut_h_prep ( struct CONTXT *pctx, /* in: proc context */ struct SFILE *hf, /* in/out: help file */ struct TXTSTOR *title /* out: blodk of .TITLE text */ ) { IMPORT struct VARIABLE *char_gbl; /* system characteristics */ struct CONTXT *ctx; TEXT libe[FLIBRSIZ+1]; struct DIRBLK db; /* directive ctrl blk for d_ package */ struct CP_HEADER header; /* compiled PDF header record */ COUNT recsize; CODE code; TEXT field[STRINGSIZ+1]; TEXT dirtyp[STRINGSIZ+1]; TEXT ttlmsg[STRINGSIZ+1]; TEXT ttlkey[STRINGSIZ+1]; for (ctx = pctx; (s_equal((*ctx).pdf.libr,"/LOCAL/")); ctx = (*ctx).backlink); s_copy ((*ctx).pdf.libr, libe); d_init(&db, hf, libe, (TEXT **) (*char_gbl).v_cvp, (*char_gbl).v_count); /* init directive block */ if ((*pctx).compiled) /* if compiled PDF */ { f_rewind(hf); f_read(hf, field); /* dummy read -- space to header*/ code = f_bread(hf, (GENPTR)&header, sizeof(struct CP_HEADER), &recsize); if (code != SUCCESS) goto read_err; if (header.type != C_HEADER) goto hdr_type_err; if (header.title.possav) /* if .TITLE text exists */ { f_setpos(hf, &header.title); /* position to .TITLE */ code = f_read(hf, field); /* read the .TITLE record */ if (code != SUCCESS) goto read_err; code = gettitle(&db, title, ttlmsg, ttlkey); if (code != SUCCESS) goto title_err; } if (header.help.possav) /* if .HELP text exists */ { MOVE_STRUCT(header.help, tutctx.hlppos); /* save .HELP posit */ tutctx.hlpexist = TRUE; } if (header.level2.possav) /* if .LEVEL2 help text exists */ { f_setpos(hf, &header.level2); /* posit to .LEVEL2 */ f_read(hf, field); f_read(hf, field); /* dummy reads to pass .LEVEL2 */ f_movpos(&(*hf).posctx, &tutctx.lasth2pos); f_movpos(&(*hf).posctx, &tutctx.lev2start); tutctx.h2exist = TRUE; } if (header.level1.possav) /* if .LEVEL1 help text exists */ { f_setpos(hf, &header.level1); /* posit to .LEVEL1 */ f_read(hf, field); f_read(hf, field); /* dummy reads to pass .LEVEL1 */ f_movpos(&(*hf).posctx, &tutctx.lasth1pos); /* save as last level 1 help posit*/ f_movpos(&(*hf).posctx, &tutctx.lev1start); /* & permanently as start of .LEVEL section*/ tutctx.h1exist = TRUE; } tutctx.nohelpf= !tutctx.hlpexist && !tutctx.h1exist && !tutctx.h2exist; } else /* not in compiled PDF */ { while ((code = d_dirctv(&db, dirtyp, field)) == SUCCESS) { if (s_equal(dirtyp, ".TITLE")) /* if .TITLE text present */ { if (gettitle(&db, title, ttlmsg, ttlkey) != SUCCESS) goto title_err; } else if (s_equal(dirtyp, ".HELP")) { f_movpos(&(*hf).posctx, &tutctx.hlppos); /* save .HELP posit*/ tutctx.hlpexist = TRUE; } else if (s_equal(dirtyp, ".LEVEL1")) { f_read(hf, field); /* dummy read to get past .LEVEL1 */ f_movpos(&(*hf).posctx, &tutctx.lasth1pos); /* save as last level 1 help posit*/ f_movpos(&(*hf).posctx, &tutctx.lev1start); /* & permanently as start of .LEVEL section*/ tutctx.h1exist = TRUE; break; } else if (s_equal(dirtyp, ".LEVEL2")) { f_read(hf, field); /* dummy read to get past .LEVEL2 */ f_movpos(&(*hf).posctx, &tutctx.lasth2pos); f_movpos(&(*hf).posctx, &tutctx.lev2start); tutctx.h2exist = TRUE; } else if (s_equal(dirtyp, ".END")) { tutctx.nohelpf= !tutctx.hlpexist && !tutctx.h1exist && !tutctx.h2exist; break; } else goto struct_err; /* otherwise badly structured help file */ } if (code != SUCCESS) goto dir_err; } return(SUCCESS); title_err: tutmsg(ttlmsg, ttlkey, 0, 0, 0, 0, 0); /* help file title read error */ goto close_err; struct_err: tutmsg("Unrecognized directive '%s' in help file.", "TAE-BADHLPDIR", (uintptr_t) dirtyp, 0, 0, 0, 0); fretxt(title); goto close_err; dir_err: tutmsg(msg_hrde, key_hrde, (uintptr_t) (*pctx).pdf.name, 0, 0, 0, 0); /* help file read error */ fretxt(title); goto close_err; read_err: tutmsg(msg_hrde, key_hrde, (uintptr_t) (*pctx).pdf.name, 0, 0, 0, 0); /* help file read error */ goto close_err; hdr_type_err: tutmsg("Compiled PDF has bad header record.", "TAE-CPDFBHDR", 0, 0, 0, 0, 0); goto close_err; close_err: return(FAIL); }
FUNCTION CODE inlevel2 ( struct CONTXT *pctx, /* in/out: proc context w/ tab to update.*/ struct SFILE *hf, /* in/out: help file control block */ TEXT type[], /* in: subcmd/parm */ TEXT subcmd[] /* in: subcommand qualifier to search */ ) { IMPORT struct VARIABLE *char_gbl; /* system characteristics */ TEXT dirctv[STRINGSIZ+1]; TEXT field[STRINGSIZ+1]; TEXT scope[STRINGSIZ+1]; TEXT prmname[NAMESIZ+1]; TEXT proc[FSPECSIZ+1]; TEXT subname[SUBCMDSIZ+1]; struct SYNBLK sb; struct VARIABLE *v; struct SUBCMD *s; struct TUTEXT *t; TEXT str[STRINGSIZ+1]; CODE code; struct DIRBLK db; /* directive block for d_ pkg */ TEXT libe[FLIBRSIZ+1]; struct CONTXT *ctx; if (tutctx.nohelpf || tutctx.srch2cplt) /* if search complete, no help */ goto nhelp_err; for (ctx = pctx; (s_equal((*ctx).pdf.libr,"/LOCAL/")); ctx = (*ctx).backlink); s_copy ((*ctx).pdf.libr, libe); d_init(&db, hf, libe, (TEXT **) (*char_gbl).v_cvp, (*char_gbl).v_count); /* init directive block */ if (!tutctx.h2exist) /* if lev 2 help existence not yet known*/ { if (tutctx.h1exist) /* if level1 exists */ f_setpos(hf, &tutctx.lasth1pos); /* start looking from lev 1 help posit */ else f_setpos(hf, &(*hf).posctx); /* look from current position */ while ((code = d_dirctv(&db, dirctv, field)) == SUCCESS) { if (s_equal(dirctv, ".LEVEL2")) /* .level2 help found */ break; else if (s_equal(dirctv, ".HELP")) /* .HELP encountered */ { f_movpos(&(*hf).posctx, &tutctx.hlppos);/* save .help posctx */ tutctx.hlpexist = TRUE; /* mark as exists */ } else if (s_equal(dirctv, ".END")) /* End of file reached */ { tutctx.srch2cplt = TRUE; goto nhelp_err; } } if (code != SUCCESS) goto read_err; if (f_read(hf, str) != SUCCESS) goto read_err; tutctx.h2exist = TRUE; f_movpos(&(*hf).posctx, &tutctx.lasth2pos); f_movpos(&(*hf).posctx, &tutctx.lev2start); } f_setpos(hf, &tutctx.lasth2pos); /* restore last lev 2 help position */ while (FOREVER) { if (d_dirctv(&db, dirctv, field) != SUCCESS) goto read_err; /* input next directive line*/ f_movpos(&(*hf).posctx, &tutctx.lasth2pos); if (!s_lseq(".VAR", dirctv) && !s_equal(".SUBCMD", dirctv)) { tutctx.srch2cplt = TRUE; goto nhelp_err; } if (s_equal(type, "subcmd") && s_equal(".SUBCMD", dirctv)) break; if (s_equal(type, "parm") && s_lseq(".VAR", dirctv)) break; } initok(&sb, field); /* init sb for syntax pkg */ code = gettok(&sb, prmname); if (code != S_ALPHA && (!s_equal(type, "subcmd") || code != '-')) goto noparm_err; if (s_equal(type, "subcmd")) { if (code == '-') prmname[0] = EOS; else prmname[SUBCMDSIZ] = EOS; s = subex((*pctx).subptr, prmname); if (s == NULL) goto nparm_ret; t = &(*s).ext; } else { prmname[NAMESIZ] = EOS; proc[0] = EOS; subname[0] = EOS; s_copy(sb.curchr, scope); if (!NULLSTR(scope)) cmd_parse(&sb, scope, NULL, proc, subname); if (!NULLSTR(proc) && !s_equal((*pctx).pdf.name, proc)) goto nparm_ret; if (!s_equal(subcmd, subname)) goto nparm_ret; v = lookex(&(*pctx).parmst, prmname); if (v == NULL) goto nparm_ret; if ((*v).v_tp == NULL) if (((*v).v_tp = (struct TUTEXT *) tae_alloc(1, sizeof(struct TUTEXT))) == NULL) goto over_err; t = (*v).v_tp; } if ((*t).l2hexist) goto nparm_ret; (*t).l2hexist = TRUE; f_movpos(&(*hf).posctx, &(*t).l2hpos); /* save help posit for this var */ f_read(hf, str); /* pass this position */ f_movpos(&(*hf).posctx, &tutctx.lasth2pos); return(SUCCESS); nparm_ret: f_read(hf, str); f_movpos(&(*hf).posctx, &tutctx.lasth2pos); return(SUCCESS); nhelp_err: return(TUT_NOL2HELP); /* no leve2 help */ read_err: tutmsg(msg_hrde, key_hrde, (uintptr_t) (*pctx).pdf.name, 0, 0, 0, 0); /* tutor mode help file read error*/ return(FAIL); noparm_err: tutmsg("Level 2 .VARIABLE statement missing a parameter name.", "TAE-TNPNAM", 0, 0, 0, 0, 0); return(FAIL); over_err: tutmsg(msg_mmov, key_mmov, 0, 0, 0, 0, 0); /* dyn mem overflow */ return(FAIL); }
FUNCTION static CODE inlevel1 ( struct CONTXT *pctx, /* in/out: proc context w/ tab to update. */ struct SFILE *hf, /* in/out: help file control block */ TEXT subcmd[] /* in: subcommand qualifier to search */ ) { IMPORT struct VARIABLE *char_gbl; /* system characteristics */ TEXT dirctv[STRINGSIZ+1]; TEXT field[STRINGSIZ+1]; TEXT scope[STRINGSIZ+1]; TEXT prmname[SUBCMDSIZ+1]; TEXT proc[FSPECSIZ+1]; TEXT subname[SUBCMDSIZ+1]; struct SYNBLK sb; struct VARIABLE *v; struct SUBCMD *s; struct TUTEXT *t; TEXT str[STRINGSIZ+1]; CODE code, code1; struct DIRBLK db; /* directive block for d_ pkg */ TEXT libe[FLIBRSIZ+1]; struct CONTXT *ctx; if (!tutctx.h1exist || tutctx.h1done) return(TUT_H1DONE); f_setpos(hf, &tutctx.lasth1pos); /* restore last lev 1 help position */ for (ctx = pctx; (s_equal((*ctx).pdf.libr,"/LOCAL/")); ctx = (*ctx).backlink); s_copy ((*ctx).pdf.libr, libe); /* make sure we have a libe good for internal procs */ d_init(&db, hf, libe, (TEXT **) (*char_gbl).v_cvp, (*char_gbl).v_count); /* init directive block */ while (FOREVER) { if ((code = d_dirctv(&db, dirctv, field)) != SUCCESS) goto read_err; /* input next directive line*/ f_movpos(&(*hf).posctx, &tutctx.lasth1pos); if (!s_lseq(".VAR", dirctv) && !s_equal(".SUBCMD", dirctv)) { tutctx.h1done = TRUE; return(TUT_H1DONE); } if (tutctx.subtut && s_equal(".SUBCMD", dirctv)) break; if (!tutctx.subtut && s_lseq(".VAR", dirctv)) break; } initok(&sb, field); /* init sb for syntax pkg */ code = gettok(&sb, prmname); if (code != S_ALPHA && (!tutctx.subtut || code != '-')) goto name_err; if (tutctx.subtut) { if (code == '-') prmname[0] = EOS; else prmname[SUBCMDSIZ] = EOS; if ((s = subex((*pctx).subptr, prmname)) == NULL) goto nsubc_err; t = &(*s).ext; } else { prmname[NAMESIZ] = EOS; proc[0] = EOS; subname[0] = EOS; s_copy(sb.curchr, scope); if (!NULLSTR(scope)) cmd_parse(&sb, scope, NULL, proc, subname); if (!NULLSTR(proc) && !s_equal((*pctx).pdf.name, proc)) goto nparm_err; if (!s_equal(subcmd, subname)) goto nparm_err; if ((v = lookex(&(*pctx).parmst, prmname)) == NULL) goto nparm_err; if ((*v).v_tp == NULL) if (((*v).v_tp = (struct TUTEXT *) tae_alloc(1, sizeof(struct TUTEXT))) == NULL) goto over_err; t = (*v).v_tp; } if ((*t).l1hexist) goto name_err; (*t).l1hexist = TRUE; code1 = SUCCESS; /* in case we get out at once */ while ((code = txtread(&db, str, &tutctx.lasth1pos)) == SUCCESS) { if ((code1 = addtxt(&(*t).l1help, str)) != SUCCESS) break; } d_incclose(&db); /* close .include file, if any */ if (code != D_EOT) goto read_err; if (code1 != SUCCESS) goto over_err; if (tutctx.screen) if ((brktxt(&(*t).l1help, TUTHL1SIZ)) != SUCCESS) goto over_err; /* break text up for descr field width*/ return(SUCCESS); read_err: tutmsg(msg_hrde, key_hrde, (uintptr_t) (*pctx).pdf.name, 0, 0, 0, 0); /* tutor mode help file read error */ tutctx.h1done = TRUE; return(TUT_H1DONE); nsubc_err: nparm_err: name_err: f_read(hf, str); f_movpos(&(*hf).posctx, &tutctx.lasth1pos); return(SUCCESS); over_err: tutmsg(msg_mmov, key_mmov, 0, 0, 0, 0, 0); /* dyn mem overflow */ return(FAIL); }
int main(int argc, char **argv) { int i, j, js0_x, js0_y, js1_x, js1_y; void *font, *surface, *text, *mapsheet, *sprite, *textinput, *mtsprite, *fps_text, *tilebuf, *fancy_text; void *music; char test[256], fps[16]; char *test_text; DARNIT_MOUSE mouse; DARNIT_KEYS keys; DARNIT_MAP *map; DARNIT_SPRITE *mapsprite; if (!d_init("TESTAPP - libDarnit", "testapp", NULL)) return -1; compression_test(); /* Sound/music */ music = d_sound_tracked_load("latyl-greasy_duck_v1.mod", DARNIT_AUDIO_STREAM, DARNIT_AUDIO_STEREO); d_sound_play(music, 0, 127, 127, 0); /* Text rendering */ test_text = malloc(64); font = d_font_load("dejavu_sans.ttf", 28, 512, 512); text = d_text_surface_new(font, 80, 800, 0, 460); fancy_text = d_text_surface_color_new(font, 16, 800, 0, 420); colorTest(fancy_text); fps_text = d_text_surface_new(font, 16, 200, 0, 40); /* Menutk test */ surface = d_menu_vertical_new("Hello\nGoodbye\nOther\nNothing\nLess than nothing", 50, 100, font, 200, 10, 3); sprintf(test_text, "Héllo, world. Modify m€! Test of offsets"); textinput = d_menu_textinput_new(0, 0, font, test_text, 64, 200); /* Sprites */ sprite = d_sprite_load("test.spr", 0, DARNIT_PFORMAT_RGB5A1); mapsprite = d_sprite_load("baurn.spr", 0, DARNIT_PFORMAT_RGB5A1); d_sprite_move(sprite, 50, 50); d_sprite_move(mapsprite, 0, 0); d_sprite_animate_start(sprite); d_sprite_animate_start(mapsprite); mtsprite = d_mtsprite_load("testspr.mts"); d_mtsprite_animate_start(mtsprite); /* Maps */ mapsheet = d_render_tilesheet_load("mapsheet.png", 32, 32, DARNIT_PFORMAT_RGBA8); if ((map = d_map_load("testmap_iso.ldmz")) == NULL) fprintf(stderr, "Map load failed\n"); d_tilemap_sprite_add(map->layer[0].tilemap, mapsprite); /* Tile caches */ tilebuf = d_render_tile_new(1, mapsheet); d_render_tile_move(tilebuf, 0, 64, 64); d_render_tile_tilesheet_coord_set(tilebuf, 0, 16, 16, 32, 32); /* Misc */ fprintf(stderr, "String lenght: %i\n", d_font_string_w(font, "ASDFÅÄÖ,,")); for (i = j = 0;;) { d_sprite_move(mapsprite, 64, j * 4); keys = d_keys_get(); d_text_surface_reset(text); d_text_surface_reset(fps_text); mouse = d_mouse_get(); d_joystick_get(&js0_x, &js0_y, &js1_x, &js1_y); sprintf(test, "X: %i, Y: %i, W: %i;; TX: %i, TY: %i;; nub0 (%i,%i) ;; nub1(%i,%i)", mouse.x, mouse.y, mouse.wheel, i*4, j*4, js0_x, js0_y, js1_x, js1_y); sprintf(fps, "%i", d_last_frame_time()); d_text_surface_string_append(text, test); d_text_surface_string_append(fps_text, "ASDFÅÄÖ,,"); if (keys.lmb) d_render_fade_in(1000, 1.0f, 0.0f, 0.0f); if (keys.rmb) d_render_fade_out(1000); d_render_begin(); if (keys.left == 1) i--; if (keys.right == 1) i++; if (keys.up == 1) j--; if (keys.down == 1) j++; if (keys.select) fprintf(stderr, "Blololol\n"); if (keys.r == 1) d_tilemap_camera_move(map->layer->tilemap, i*4, j*4); d_render_blend_enable(); d_tilemap_draw(map->layer->tilemap); if (keys.l == 1) if (d_menu_loop(surface) != -1) return 0; d_menu_loop(textinput); d_sprite_draw(sprite); d_text_surface_draw(text); d_text_surface_draw(fancy_text); d_text_surface_draw(fps_text); d_render_offset(-200, -200); d_mtsprite_draw(mtsprite); d_render_offset(0, 0); d_render_blend_disable(); d_render_tile_draw(tilebuf, 1); d_render_end(); d_loop(); } return 0; }