home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- * sprshow.c
- *
- * A simple program for viewing sprites. Creates two animated sprites
- * from the given sprite map file and bounces them around for 1000
- * steps. Displays the size of the memory allocated for the sprite
- * shape data and the time to animate the two sprites 1000 times.
- * Usage:
- * show [-res] fil.ext
- * -res can be either -1, -2, -4 or -8 and it means the horizontal
- * resolution of animation (-8 means one pixel resolution).
- **********************************************************************
- This file is part of
-
- STK -- The sprite toolkit -- version 1.0
-
- Copyright (C) Jari Karjala 1990
-
- The sprite toolkit (STK) is a FreeWare toolkit for creating high
- resolution sprite graphics with PCompatible hardware. This toolkit
- is provided as is without any warranty or such thing. See the file
- COPYING for further information.
-
- **********************************************************************/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <graphics.h>
- #include <conio.h>
- #include <dos.h>
- #include <time.h>
- #include <alloc.h>
-
- #include "stk.h"
-
-
- void main(int argc, char **argv)
- {
- ANIM_SPRITE as1, as2;
- int res,i,j;
- clock_t tt;
- long mf2, mf3;
-
- if (argc<2) {
- puts("Usage: show [-res] sprite.smp");
- exit(1);
- }
-
- if (argv[1][0]=='-') {
- res = atoi(&argv[1][1]);
- argv++;
- argc--;
- }
- else
- res = 4;
-
- detectgraph(&i, &j);
- if (i==EGA || i==VGA) {
- i = EGAMONO;
- j = EGAMONOHI;
- }
- else if (i!=HERCMONO) {
- puts("Unsupported graphics mode, sorry!");
- exit(100);
- }
-
- gr_start(&i, &j);
- spr_initialize(i);
-
- mf2 = farcoreleft();
-
- as1 = spr_anim_create(1, spr_fio_read_smp(argv[1], res, 1));
- if (as1==NULL) {
- gr_puts("Load error (invalid filename, out of heap?) \nPress enter");
- getch();
- exit(2);
- }
- spr_anim_set_time(as1, 0, 6,5000);
- spr_anim_set_location(as1, 20,15);
- spr_anim_set_vector(as1, 2,2);
- spr_anim_set_limits(as1, 20, 10, 620, 330);
- spr_anim_start(as1);
-
-
- as2 = spr_anim_create(1, spr_fio_read_smp(argv[1], res, 1));
- if (as2==NULL) {
- gr_dual_xy_printf(0,0,"Load error (out of heap?) \nPress enter");
- getch();
- gr_dual_xy_printf(0,0," \n ");
- }
- else {
- spr_anim_set_time(as2, 0,6,5000);
- spr_anim_set_location(as2, 300,150);
- spr_anim_set_vector(as2, -2,2);
- spr_anim_set_limits(as2, 20, 10, 620, 330);
- spr_anim_start(as2);
- }
-
- mf3 = farcoreleft();
-
- /** some background pictures **/
- gr_dual_xy_printf(0,0,
- "The shape data took %ld bytes (%ld free). ", mf2-mf3,mf3);
- setactivepage(1);
- rectangle(20, 10, 620, 330);
- bar(100,100,300,160);
- bar(300,160,500,220);
- setactivepage(0);
- rectangle(20, 10, 620, 330);
- bar(100,100,300,160);
- bar(300,160,500,220);
-
-
- tt = clock();
- j = 0;
- while (j++ < 1000) {
- setactivepage(spr_anim_next_pass());
- }
- gr_dual_xy_printf(0,8,
- "Unregulated animation time: %ld sec (1000 iterations)",
- (clock() - tt) * 10L / 182L);
- getch();
-
- }
-