00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdio.h>
00042 #include <string.h>
00043 #include <math.h>
00044 #ifndef __UNIX_
00045 #ifndef _Windows
00046 #include <bios.h>
00047 #endif
00048 #include <stdlib.h>
00049 #ifndef _Windows
00050 #include <graphics.h>
00051 #else
00052 #include <windows.h>
00053 #endif
00054 #include <time.h>
00055 #include <malloc.h>
00056 #else
00057 #endif
00058 #include "mensagem.h"
00059 #include "memvirtu.h"
00060 #include "lowparam.h"
00061 #include "lowmacro.h"
00062 #include "lowsolid.h"
00063 #include "vectorop.h"
00064 #include "disdispl.h"
00065 #include "animatio.h"
00066 #include "mancommd.h"
00067 #include "gphgraph.h"
00068
00069 #ifdef __UNIX_
00070 extern GC XViewGraphContext;
00071 extern Display *XDisplay;
00072 extern Window ViewWndw;
00073 #endif
00074
00075 int NumVec[100];
00076 INTVECTOR *ListFrames[100];
00077
00078 void cinema(void)
00079 {
00080 int ip, frini, frfim, frpasso;
00081 char AnimeName[13];
00082
00083 for (ip = 0; ip == 0;)
00084 {
00085 switch (optin())
00086 {
00087 case 'l':
00088 if ((sscanf(restbuf, "%s %d %d %d", AnimeName, &frini, &frfim,
00089 &frpasso)) == 4)
00090 {
00091 MSD_loadAnimation(AnimeName, frini, frfim, frpasso);
00092 ip = 1;
00093 }
00094 break;
00095
00096 case 'f':
00097 MSD_freeCinemaStructure();
00098 ip = 1;
00099 break;
00100
00101 case 'd':
00102 if ((sscanf(restbuf, "%d", &frpasso)) == 1)
00103 {
00104 MSD_displayLoadedAnimation(frpasso);
00105 ip = 1;
00106 }
00107 break;
00108 }
00109 if (ip == 0)
00110 {
00111 printf("-l AnimacaoNome FrameInicial FrameFinal Passo\n");
00112 printf("-f (libera memoria)\n");
00113 printf("-d Passo (exibe animacao)\n");
00114 if (!lineins("? "))
00115 {
00116 return;
00117 }
00118 }
00119 }
00120 }
00121
00122 void MSD_loadAnimation(char *AnimeName, int frini, int frfim, int frpasso)
00123 {
00124 int frnum, FrameNum, NumVectors, frct;
00125 char FrameIndex[13], FrameFileName[13];
00126 FILE *FrameIndexFile;
00127
00128 if (NumeroFrames != 0)
00129 {
00130 fprintf(stderr, "Ja esta carregada uma animacao!\n");
00131 return;
00132 }
00133
00134 frnum = (int)(floor((real)(frfim - frini) / (real)frpasso) + 1);
00135
00136 if (frnum > MAXNUMFRAMES)
00137 {
00138 printf("ExibeCinema: no memory left!\n");
00139 return;
00140 }
00141 strcpy(FrameIndex, AnimeName);
00142 strcat(FrameIndex, "000.dsp");
00143 if ((FrameIndexFile = fopen(FrameIndex, "r")) == (FILE *)NIL)
00144 {
00145 fprintf(stderr, "ExibeCinema: erro ao abrir arquivo %s\n",
00146 FrameIndex);
00147 return;
00148 }
00149
00150 FrameNum = 0;
00151 while (fscanf(FrameIndexFile, "%s %d", FrameFileName, &NumVectors) == 2)
00152 {
00153 frct = FindFrameNum(FrameFileName);
00154 if ((frct >= frini) && ((frct - frini) % frpasso == 0) && (frct <= frfim))
00155 {
00156 LoadFrame(FrameNum, NumVectors, FrameFileName);
00157 FrameNum++;
00158 }
00159 }
00160 fclose(FrameIndexFile);
00161 NumeroFrames = FrameNum;
00162 }
00163
00164 void DrawLine(INTVECTOR *auxpt)
00165 {
00166 int sv[2], ev[2];
00167
00168 if ((auxpt->cor < 0) || (auxpt->cor > 15))
00169 {
00170 return;
00171 }
00172 g_pcolor(auxpt->cor);
00173 sv[0] = auxpt->px1;
00174 sv[1] = auxpt->py1;
00175 ev[0] = auxpt->px2;
00176 ev[1] = auxpt->py2;
00177 g_iline(auxpt->tlinha == 0 ? SOLID_LINE : DASHED_LINE, sv, ev);
00178 }
00179
00180 void ExibeFrame(int p)
00181 {
00182 time_t now;
00183
00184 int x_ap = NumVec[p] - 4;
00185 INTVECTOR *auxptr_ap = ListFrames[p] + 4;
00186
00187 while (x_ap-- != 0)
00188 {
00189 DrawLine(auxptr_ap++);
00190 }
00191 time(&now);
00192 while (difftime(time(0), now) < 1)
00193 {
00194 ;
00195 }
00196 g_clear();
00197 }
00198
00199 void MSD_displayLoadedAnimation(int num)
00200 {
00201 if (NumeroFrames == 0)
00202 {
00203 fprintf(stderr, "Nao esta carregada nenhuma animacao!\n");
00204 return;
00205 }
00206
00207 g_clear();
00208
00209 int x = 0;
00210 INTVECTOR *ptr = ListFrames[0];
00211 while (x < NumVec[0])
00212 {
00213 DrawLine(&ptr[x]);
00214 x++;
00215 }
00216
00217 for (int i = 0; i < num; i++)
00218 {
00219 for (int p = 0; p < NumeroFrames; p++)
00220 {
00221 ExibeFrame(p);
00222 }
00223 for (p = NumeroFrames - 1; p > -1; p--)
00224 {
00225 ExibeFrame(p);
00226 }
00227 }
00228 }
00229
00230 void LoadFrame(int FrameNum, int NumVectors, char *FrameFileName)
00231 {
00232 FILE *FrameFile;
00233 INTVECTOR *vpptr, *listp;
00234 float x1, y1, x2, y2;
00235 vect2 ev, sv;
00236 int NewNumVectors, auxcor, auxtipo, gdcsv[2], gdcev[2], flag, k;
00237
00238 if ((FrameFile = fopen(FrameFileName, "r")) == (FILE *)NIL)
00239 {
00240 fprintf(stderr, "LoadCinema: erro ao abrir arquivo %s\n", FrameFileName);
00241 return;
00242 }
00243
00244 if ((ListFrames[FrameNum] = (INTVECTOR *)malloc(NumVectors
00245 * sizeof(INTVECTOR))) == (INTVECTOR *)NIL)
00246 {
00247 fprintf(stderr, "LoadCinema: no memory left!\n");
00248 fclose(FrameFile);
00249 return;
00250 }
00251
00252 listp = ListFrames[FrameNum];
00253 flag = NewNumVectors = 0;
00254 while (fscanf(FrameFile, "%d %d %f %f %f %f", &auxcor, &auxtipo,
00255 &x1, &y1, &x2, &y2) == 6)
00256 {
00257 sv[0] = x1;
00258 sv[1] = y1;
00259 ev[0] = x2;
00260 ev[1] = y2;
00261 gdcpos(sv, gdcsv);
00262 gdcpos(ev, gdcev);
00263 flag = 1;
00264 for (vpptr = listp, flag = k = 0; k < NewNumVectors; k++, vpptr++)
00265 {
00266 if (vpptr->px1 == gdcsv[0])
00267 {
00268 if (vpptr->py1 == gdcsv[1])
00269 {
00270 if (vpptr->px2 == gdcev[0])
00271 {
00272 if (vpptr->py2 == gdcev[1])
00273 {
00274 flag = 0;
00275 break;
00276 }
00277 }
00278 }
00279 }
00280 if (vpptr->px2 == gdcsv[0])
00281 {
00282 if (vpptr->py2 == gdcsv[1])
00283 {
00284 if (vpptr->px1 == gdcev[0])
00285 {
00286 if (vpptr->py1 == gdcev[1])
00287 {
00288 flag = 0;
00289 break;
00290 }
00291 }
00292 }
00293 }
00294 }
00295 if (flag == 0)
00296 {
00297 listp[NewNumVectors].cor = auxcor;
00298 listp[NewNumVectors].tlinha = auxtipo;
00299 listp[NewNumVectors].px1 = gdcsv[0];
00300 listp[NewNumVectors].py1 = gdcsv[1];
00301 listp[NewNumVectors].px2 = gdcev[0];
00302 listp[NewNumVectors].py2 = gdcev[1];
00303 NewNumVectors++;
00304 }
00305 }
00306 fclose(FrameFile);
00307 fprintf(stderr, "Frame %s %4d ---> %4d\n", FrameFileName, NumVectors,
00308 NewNumVectors);
00309 NumVec[FrameNum] = NewNumVectors;
00310 }
00311
00312 int FindFrameNum(char *nome)
00313 {
00314 return(atoi(strchr(nome, (char)NIL) - 7));
00315 }
00316
00317 void MSD_freeCinemaStructure(void)
00318 {
00319 if (NumeroFrames == 0)
00320 {
00321 fprintf(stderr, "Nao esta carregada nenhuma animacao!\n");
00322 return;
00323 }
00324
00325 for (int t = 0; t == NumeroFrames; t++)
00326 {
00327 free((char *)ListFrames[t]);
00328 }
00329 NumeroFrames = 0;
00330 }