home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / formats / ttddd / spec / t3d_src / writeim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-30  |  19.2 KB  |  808 lines

  1. /* writeim.c - write an Imagine 2.0 TDDD (3D Data Decription) file
  2.  *           - by traversing the TTDDDLIB database
  3.  *           - written by Glenn M. Lewis - 3/27/92
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include "t3dlib.h"
  9. #ifdef __STDC__
  10. #include <stdlib.h>
  11. #include <strings.h>
  12. #include "writeim_protos.h"
  13. #endif
  14. #include <sys/types.h>
  15. #include <sys/stat.h>
  16.  
  17. #ifdef AZTEC_C
  18. #include <fcntl.h>
  19. #include <exec/types.h>
  20. #endif
  21.  
  22. static void process_INFO();
  23. static void process_OBJ();
  24. static void process_EXTR();
  25. static void process_DESC();
  26. static void process_ISTG();        /* Imagine staging file */
  27.  
  28. /* Here are a few necessary utilities */
  29.  
  30. static void put_name(world, name, size)
  31. WORLD *world;
  32. register char  *name;
  33. register int size;
  34. {
  35.     while (*name && size) {
  36.         fputc(*name++, world->inp);
  37.         size--;
  38.     }
  39.     while (size--) fputc(0, world->inp);    /* Pad the rest of the string w/ 0 */
  40. }
  41.  
  42. static void put_UBYTE(world, u)
  43. WORLD *world;
  44. UBYTE u;
  45. {
  46.     fputc((char)u, world->inp);
  47. }
  48.  
  49. static void put_UWORD(world, w)
  50. WORLD *world;
  51. UWORD w;
  52. {
  53.     put_UBYTE(world, (UBYTE)(w>>8));
  54.     put_UBYTE(world, (UBYTE)(w&0xFF));
  55. }
  56.  
  57. static void put_ULONG(world, l)
  58. WORLD *world;
  59. ULONG l;
  60. {
  61.     put_UWORD(world, (UWORD)(l>>16));
  62.     put_UWORD(world, (UWORD)(l&0xFFFF));
  63. }
  64.  
  65. static void put_FRACT(world, f)
  66. WORLD *world;
  67. double f;
  68. {
  69.     put_ULONG(world, (ULONG)(f*65536.0));
  70. }
  71.  
  72. static void put_XYZ(world, st)            /* Write a common string */
  73. WORLD *world;
  74. XYZ_st *st;
  75. {
  76.     put_FRACT(world, st->x);
  77.     put_FRACT(world, st->y);
  78.     put_FRACT(world, st->z);
  79. }
  80.  
  81. static void put_RGB(world, st)            /* Write a common string */
  82. WORLD *world;
  83. RGB_st *st;
  84. {
  85.     put_UBYTE(world, 0);    /* PAD */
  86.     put_UBYTE(world, st->r);
  87.     put_UBYTE(world, st->g);
  88.     put_UBYTE(world, st->b);
  89. }
  90.  
  91. static void write_size(world, pos)
  92. WORLD *world;
  93. long pos;
  94. {
  95.     long size;
  96.     long cur = ftell(world->inp);
  97.     size = cur-pos;
  98.     if (size&1) { size++; put_UBYTE(world, (UBYTE)0); }
  99.     fseek(world->inp, pos-4L, 0);
  100.     put_ULONG(world, (ULONG)size);
  101.     fseek(world->inp, cur, 0);
  102. }
  103.  
  104. /********************/
  105. /* The MAIN section */
  106. /********************/
  107.  
  108. int write_TDDD(world, myfile)
  109. WORLD *world;
  110. FILE *myfile;
  111. {
  112.     long pos, pos2;
  113.     OBJECT *obj;
  114.     struct stat statbuf;
  115.     int x;
  116.  
  117.     if (!world || !myfile) return(0);
  118.     world->inp = myfile;
  119.  
  120.     if (world->info || world->object) {
  121.         /* Don't write TDDD if there is nothing to write */
  122.  
  123.         /* Start the IFF TDDD file */
  124.         put_name(world, "FORM", 4);
  125.         put_ULONG(world, 0L);        /* Fill this in later [seek(,4L,0)] */
  126.         pos = ftell(world->inp);    /* Save where this starting position is */
  127.         put_name(world, "TDDD", 4);
  128.  
  129.         if (world->info) process_INFO(world, world->info);
  130.         for (obj = world->object; obj; obj=obj->next) {
  131.             put_name(world, "OBJ ", 4);
  132.             put_ULONG(world, 0L);
  133.             pos2 = ftell(world->inp);    /* Save for later */
  134.             process_OBJ(world, obj);
  135.             write_size(world, pos2);
  136.         }
  137.         write_size(world, pos);
  138.  
  139.     /* All done.  Close up shop. */
  140.         fclose(world->inp);
  141.     }
  142.  
  143. /* Also write the staging file if we have staging information */
  144.     if (!world->istg) return(1);
  145.  
  146.     /* Check is the staging file already exists */
  147.     if (stat("staging", &statbuf)==0) {
  148.         fprintf(stderr, "WARNING: Moving existing 'staging' file to 'staging.bak'.\n");
  149. #ifdef AMIGA
  150.         /* We can only assume this will wait until process completes */
  151.         x = system("copy staging staging.bak");
  152.         if (x != 0) fprintf(stderr, "ERROR:  Staging file copy failed\n");
  153. #else
  154.         system("mv staging staging.bak");
  155.         wait(1);
  156. #endif
  157.     }
  158.  
  159.     if (!(world->inp = fopen("staging", "w"))) {
  160.         fprintf(stderr, "WARNING: Could not open 'staging' file for output.\n");
  161.         fprintf(stderr, "No staging information saved!\n");
  162.         world->inp = myfile;
  163.         return(1);
  164.     }
  165.  
  166.     /* Output the staging file... */
  167.     /* Start the IFF ISTG file */
  168.     put_name(world, "FORM", 4);
  169.     put_ULONG(world, 0L);            /* Fill this in later [seek(,4L,0)] */
  170.     pos = ftell(world->inp);        /* Save where this starting position is */
  171.     put_name(world, "ISTG", 4);
  172.     process_ISTG(world);
  173.     write_size(world, pos);
  174.  
  175.     /* Return the file pointer back to normal... */
  176.     fclose(world->inp);
  177.     world->inp = myfile;
  178.     return(1);
  179. }
  180.  
  181. static void process_INFO(world, info)
  182. WORLD *world;
  183. INFO *info;
  184. {
  185.     register ULONG i;
  186.     long pos;
  187.  
  188.     put_name(world, "INFO", 4);
  189.     put_ULONG(world, 0L);
  190.     pos = ftell(world->inp);    /* Save for later */
  191.  
  192.     for (i=0; i<8; i++)
  193.         if (info->brsh[i][0]) {
  194.             put_name(world, "BRSH", 4);
  195.             put_ULONG(world, 82L);
  196.             put_UWORD(world, (UWORD)i);
  197.             put_name(world, info->brsh[i], 80);
  198.         }
  199.  
  200.     for (i=0; i<8; i++)
  201.         if (info->stnc[i][0]) {
  202.             put_name(world, "STNC", 4);
  203.             put_ULONG(world, 82L);
  204.             put_UWORD(world, (UWORD)i);
  205.             put_name(world, info->stnc[i], 80);
  206.         }
  207.  
  208.     for (i=0; i<8; i++)
  209.         if (info->txtr[i][0]) {
  210.             put_name(world, "TXTR", 4);
  211.             put_ULONG(world, 82L);
  212.             put_UWORD(world, (UWORD)i);
  213.             put_name(world, info->txtr[i], 80);
  214.         }
  215.  
  216.     if (info->otrk[0]) {
  217.         put_name(world, "OTRK", 4);
  218.         put_ULONG(world, 18L);
  219.         put_name(world, info->otrk, 18);
  220.     }
  221.  
  222.     if (info->ambi) {
  223.         put_name(world, "AMBI", 4);
  224.         put_ULONG(world, 4L);
  225.         put_RGB(world, info->ambi);
  226.     }
  227.  
  228.     if (info->obsv) {
  229.         put_name(world, "OBSV", 4);
  230.         put_ULONG(world, 28L);
  231.         put_XYZ(world, &info->obsv->came);
  232.         put_XYZ(world, &info->obsv->rota);
  233.         put_FRACT(world, info->obsv->foca);
  234.     }
  235.  
  236.     if (info->ostr) {
  237.         put_name(world, "OSTR", 4);
  238.         put_ULONG(world, 56L);
  239.         put_name(world, info->ostr->path, 18);
  240.         put_XYZ(world, &info->ostr->tran);
  241.         put_XYZ(world, &info->ostr->rota);
  242.         put_XYZ(world, &info->ostr->scal);
  243.         put_UWORD(world, info->ostr->info);
  244.     }
  245.  
  246.     if (info->fade) {
  247.         put_name(world, "FADE", 4);
  248.         put_ULONG(world, 12L);
  249.         put_FRACT(world, info->fade->at);
  250.         put_FRACT(world, info->fade->by);
  251.         put_RGB(world, &info->fade->to);
  252.     }
  253.  
  254.     if (info->skyc) {
  255.         put_name(world, "SKYC", 4);
  256.         put_ULONG(world, 8L);
  257.         put_RGB(world, &info->skyc->hori);
  258.         put_RGB(world, &info->skyc->zeni);
  259.     }
  260.  
  261.     if (info->glb0) {
  262.         put_name(world, "GLB0", 4);
  263.         put_ULONG(world, 8L);
  264.         for (i=0; i<8; i++)
  265.             put_UBYTE(world, (UBYTE)info->glb0[i]);
  266.     }
  267.     write_size(world, pos);
  268. }
  269.  
  270. static void process_OBJ(world, obj)
  271. WORLD *world;
  272. OBJECT *obj;
  273. {
  274.     OBJECT *o;
  275.  
  276.     if (obj->extr) process_EXTR(world, obj);
  277.     else process_DESC(world, obj);
  278.  
  279.     for (o=obj->child; o; o=o->next)
  280.         process_OBJ(world, o);
  281.  
  282.     put_name(world, "TOBJ", 4);
  283.     put_ULONG(world, 0L);
  284. }
  285.  
  286. static void process_EXTR(world, obj)
  287. WORLD *world;
  288. OBJECT *obj;
  289. {
  290.     long pos;
  291.  
  292.     put_name(world, "EXTR", 4);
  293.     put_ULONG(world, 0L);
  294.     pos = ftell(world->inp);    /* Save for later */
  295.  
  296.     put_name(world, "LOAD", 4);
  297.     put_ULONG(world, 80L);
  298.     put_name(world, obj->extr->filename, 80);
  299.  
  300.     put_name(world, "MTRX", 4);
  301.     put_ULONG(world, 60L);
  302.     put_XYZ(world, &obj->extr->mtrx.tran);
  303.     put_XYZ(world, &obj->extr->mtrx.scal);
  304.     put_XYZ(world, &obj->extr->mtrx.rota1);
  305.     put_XYZ(world, &obj->extr->mtrx.rota2);
  306.     put_XYZ(world, &obj->extr->mtrx.rota3);
  307.  
  308.     write_size(world, pos);
  309. }
  310.  
  311. static void process_DESC(world, obj)
  312. WORLD *world;
  313. OBJECT *obj;
  314. {
  315.     register int i, j;
  316.     register DESC *desc;
  317.     FGRP *fgrp;
  318.     long pos;
  319.  
  320.     if (!obj) return;
  321.     desc = obj->desc;
  322.     if (!desc) return;
  323.  
  324.     put_name(world, "DESC", 4);
  325.     put_ULONG(world, 0L);
  326.     pos = ftell(world->inp);    /* Save for later */
  327.  
  328.     if (desc->name) {
  329.         put_name(world, "NAME", 4);
  330.         put_ULONG(world, 18L);
  331.         put_name(world, desc->name, 18);
  332.     }
  333.  
  334.     if (desc->posi) {
  335.         put_name(world, "POSI", 4);
  336.         put_ULONG(world, 12L);
  337.         put_XYZ(world, desc->posi);
  338.     }
  339.  
  340.     if (desc->size) {
  341.         put_name(world, "SIZE", 4);
  342.         put_ULONG(world, 12L);
  343.         put_XYZ(world, desc->size);
  344.     }
  345.  
  346.     if (desc->colr) {
  347.         put_name(world, "COLR", 4);
  348.         put_ULONG(world, 4L);
  349.         put_RGB(world, desc->colr);
  350.     }
  351.  
  352.     if (desc->refl) {
  353.         put_name(world, "REFL", 4);
  354.         put_ULONG(world, 4L);
  355.         put_RGB(world, desc->refl);
  356.     }
  357.  
  358.     if (desc->tran) {
  359.         put_name(world, "TRAN", 4);
  360.         put_ULONG(world, 4L);
  361.         put_RGB(world, desc->tran);
  362.     }
  363.  
  364.     if (desc->spc1) {
  365.         put_name(world, "SPC1", 4);
  366.         put_ULONG(world, 4L);
  367.         put_RGB(world, desc->spc1);
  368.     }
  369.  
  370.     if (desc->ints) {
  371.         put_name(world, "INTS", 4);
  372.         put_ULONG(world, 4L);
  373.         put_FRACT(world, (*desc->ints));
  374.     }
  375.  
  376.     /* Mandatory field... stuff it, regardless */
  377.     if (desc->shap) {
  378.         put_name(world, "SHAP", 4);
  379.         put_ULONG(world, 4L);
  380.         put_UWORD(world, (UWORD)desc->shap[0]);
  381.         put_UWORD(world, (UWORD)desc->shap[1]);
  382.     } else {
  383.         put_name(world, "SHAP", 4);
  384.         put_ULONG(world, 4L);
  385.         put_UWORD(world, (UWORD)2);
  386.         put_UWORD(world, (UWORD)1);
  387.     }
  388.  
  389.     if (desc->axis) {
  390.         put_name(world, "AXIS", 4);
  391.         put_ULONG(world, 36L);
  392.         put_XYZ(world, &desc->axis->xaxi);
  393.         put_XYZ(world, &desc->axis->yaxi);
  394.         put_XYZ(world, &desc->axis->zaxi);
  395.     }
  396.  
  397.     if (desc->tpar) {
  398.         put_name(world, "TPAR", 4);
  399.         put_ULONG(world, 64L);
  400.         for (i=0; i<16; i++) put_FRACT(world, desc->tpar[i]);
  401.     }
  402.  
  403.     if (desc->surf) {
  404.         put_name(world, "SURF", 4);
  405.         put_ULONG(world, 5L);
  406.         for (i=0; i<5; i++) put_UBYTE(world, desc->surf[i]);
  407.         put_UBYTE(world, (UBYTE)0);    /* To make this chunk even-sized */
  408.     }
  409.  
  410.     if (desc->mttr) {
  411.         put_name(world, "MTTR", 4);
  412.         put_ULONG(world, 2L);
  413.         put_UBYTE(world, desc->mttr->type);
  414.         put_UBYTE(world, (UBYTE)(((int)((desc->mttr->indx-1.0)*100.0))&0xFF));
  415.     }
  416.  
  417.     if (desc->spec) {
  418.         put_name(world, "SPEC", 4);
  419.         put_ULONG(world, 2L);
  420.         put_UBYTE(world, desc->spec[0]);
  421.         put_UBYTE(world, desc->spec[1]);
  422.     }
  423.  
  424.     if (desc->prp0) {
  425.         put_name(world, "PRP0", 4);
  426.         put_ULONG(world, 6L);
  427.         for (i=0; i<6; i++) put_UBYTE(world, desc->prp0[i]);
  428.     }
  429.  
  430.     if (desc->prp1) {
  431.         put_name(world, "PRP1", 4);
  432.         put_ULONG(world, 8L);
  433.         for (i=0; i<8; i++) put_UBYTE(world, desc->prp1[i]);
  434.     }
  435.  
  436.     if (desc->stry) {
  437.         put_name(world, "STRY", 4);
  438.         put_ULONG(world, 56L);
  439.         put_name(world, desc->stry->path, 18);
  440.         put_XYZ(world, &desc->stry->tran);
  441.         put_XYZ(world, &desc->stry->rota);
  442.         put_XYZ(world, &desc->stry->scal);
  443.         put_UWORD(world, desc->stry->info);
  444.     }
  445.  
  446.     if (desc->pcount) {
  447.         put_name(world, "PNTS", 4);
  448.         put_ULONG(world, (ULONG)desc->pcount*12L+2L);
  449.         put_UWORD(world, desc->pcount);
  450.         for (i=0; i<desc->pcount; i++)
  451.             put_XYZ(world, &desc->pnts[i]);
  452.     }
  453.  
  454.     if (desc->ecount) {
  455.         put_name(world, "EDGE", 4);
  456.         put_ULONG(world, (ULONG)desc->ecount*4L+2L);
  457.         put_UWORD(world, desc->ecount);
  458.         for (i=0; i<2*desc->ecount; i++)
  459.             put_UWORD(world, desc->edge[i]);
  460.     }
  461.  
  462.     if (desc->eflg) {
  463.         put_name(world, "EFLG", 4);
  464.         put_ULONG(world, (ULONG)desc->eflg->num+2L);
  465.         put_UWORD(world, desc->eflg->num);
  466.         for (i=0; i<desc->eflg->num; i++)
  467.             put_UBYTE(world, desc->eflg->eflg[i]);
  468.         if (desc->eflg->num&1) put_UBYTE(world, 0);    /* Pad on even boundary */
  469.     }
  470.  
  471.     if (desc->fcount) {
  472.         put_name(world, "FACE", 4);
  473.         put_ULONG(world, (ULONG)desc->fcount*6L+2L);
  474.         put_UWORD(world, desc->fcount);
  475.         for (i=0; i<3*desc->fcount; i++)
  476.             put_UWORD(world, desc->face[i]);
  477.  
  478.         if (desc->clst) {
  479.             put_name(world, "CLST", 4);
  480.             put_ULONG(world, (ULONG)desc->fcount*3L+2L);
  481.             put_UWORD(world, desc->fcount);
  482.             for (i=0; i<3*desc->fcount; i++)
  483.                 put_UBYTE(world, desc->clst[i]);
  484.             if (desc->fcount&1) put_UBYTE(world, 0);    /* Pad to even length */
  485.         }
  486.         if (desc->rlst) {
  487.             put_name(world, "RLST", 4);
  488.             put_ULONG(world, (ULONG)desc->fcount*3L+2L);
  489.             put_UWORD(world, desc->fcount);
  490.             for (i=0; i<3*desc->fcount; i++)
  491.                 put_UBYTE(world, desc->rlst[i]);
  492.             if (desc->fcount&1) put_UBYTE(world, 0);    /* Pad to even length */
  493.         }
  494.         if (desc->tlst) {
  495.             put_name(world, "TLST", 4);
  496.             put_ULONG(world, (ULONG)desc->fcount*3L+2L);
  497.             put_UWORD(world, desc->fcount);
  498.             for (i=0; i<3*desc->fcount; i++)
  499.                 put_UBYTE(world, desc->tlst[i]);
  500.             if (desc->fcount&1) put_UBYTE(world, 0);    /* Pad to even length */
  501.         }
  502.     }
  503.  
  504.     for (fgrp=desc->fgrp; fgrp; fgrp=fgrp->next) {
  505.         put_name(world, "FGRP", 4);
  506.         put_ULONG(world, (ULONG)fgrp->num*2L+2L+18L);
  507.         put_UWORD(world, fgrp->num);
  508.         put_name(world, fgrp->name, 18);
  509.         for (i=0; i<fgrp->num; i++)
  510.             put_UWORD(world, fgrp->face[i]);
  511.     }
  512.  
  513.     for (i=0; i<4; i++) {
  514.         if (!desc->txt2[i]) continue;
  515.         put_name(world, "TXT2", 4);
  516.         j = strlen(desc->txt2[i]->Name);
  517. /* CWC */    j = 144L+17L+j;  /* Oddly enough, an odd number is allowed here */
  518. /* CWC         put_ULONG(world, 94L+18L+j+(1-(j&1)));    original line */
  519. /* CWC */    put_ULONG(world, j);
  520.         put_UWORD(world, desc->txt2[i]->Flags);
  521.         put_XYZ(world, &desc->txt2[i]->TAxis.tran);
  522.         put_XYZ(world, &desc->txt2[i]->TAxis.rota1);
  523.         put_XYZ(world, &desc->txt2[i]->TAxis.rota2);
  524.         put_XYZ(world, &desc->txt2[i]->TAxis.rota3);
  525.         put_XYZ(world, &desc->txt2[i]->TAxis.scal);
  526.         for (j = 0; j < 16; j++) put_FRACT(world, desc->txt2[i]->Params[j]);
  527.         for (j = 0; j < 16; j++) put_UBYTE(world, desc->txt2[i]->PFlags[j]);
  528. /* CWC        put_name(world, desc->txt2[i]->SubName, 18); original line */
  529. /* CWC */    put_name(world, desc->txt2[i]->SubName, 17);  /* Yes, this 
  530.                                                                  is correct! */
  531.         j = strlen(desc->txt2[i]->Name);
  532.         put_UWORD(world, j);
  533.         put_name(world, desc->txt2[i]->Name, j);
  534. /* CWC */       j = j + 144L + 17L;
  535.         if (j&1) put_UBYTE(world, 0);    /* Pad the odd byte */
  536.     }
  537.  
  538.     write_size(world, pos);
  539. }
  540.  
  541. /************************************************************************/
  542. /* New code to write staging file - written by Glenn M. Lewis - 8/11/92 */
  543. /************************************************************************/
  544.  
  545. static void process_OSIZ();
  546. static void process_POSN();
  547. static void process_ALGN();
  548. static void process_PALN();
  549. static void process_TALN();
  550. static void process_PTH2();
  551. static void process_GLB2();
  552. static void process_AXIS();
  553. static void process_LITE();
  554. static void process_FILE();
  555.  
  556. static void process_ISTG(world)
  557. WORLD *world;
  558. {
  559.     register ISTG *istg = world->istg;
  560.     register SOBJ *sobj;
  561.     long pos2;
  562.  
  563.     if (!world->inp) return;    /* File not open */
  564.  
  565.     put_name(world, "MAXF", 4);
  566.     put_ULONG(world, 2L);
  567.     put_UWORD(world, istg->maxf);
  568.  
  569.     /* Sort the SOBJ's first? */
  570.  
  571. /* Here is the main loop: */
  572.     for (sobj=istg->head; sobj; sobj=sobj->next) {
  573.         put_name(world, "SOBJ", 4);
  574.         put_ULONG(world, 0L);
  575.  
  576.         pos2 = ftell(world->inp);    /* Save for later */
  577.  
  578.         put_name(world, "NAME", 4);
  579.         put_ULONG(world, 18L);
  580.         put_name(world, sobj->name, 18);
  581.         put_name(world, "STGF", 4);
  582.         put_ULONG(world, 2L);
  583.         put_UWORD(world, sobj->stgf);
  584.         if (sobj->glb2) process_GLB2(sobj, world);
  585.         if (sobj->file) process_FILE(sobj, world);
  586.         if (sobj->lite) process_LITE(sobj, world);
  587.         if (sobj->axis) process_AXIS(sobj, world);
  588.         if (sobj->posn) process_POSN(sobj, world);
  589.         if (sobj->algn) process_ALGN(sobj, world);
  590.         if (sobj->osiz) process_OSIZ(sobj, world);
  591.         if (sobj->paln) process_PALN(sobj, world);
  592.         if (sobj->taln) process_TALN(sobj, world);
  593.         if (sobj->pth2) process_PTH2(sobj, world);
  594.  
  595.         write_size(world, pos2);
  596.     }
  597.  
  598. /* All done. */
  599. }
  600.  
  601. static void process_OSIZ(sobj, world)
  602. SOBJ *sobj;
  603. WORLD *world;
  604. {
  605.     register OSIZ *osiz;
  606.  
  607.     for (osiz=sobj->osiz; osiz; osiz=osiz->next) {
  608.         put_name(world, "OSIZ", 4);
  609.         put_ULONG(world, 18L);
  610.         put_UWORD(world, osiz->flags);
  611.         put_UWORD(world, osiz->start);
  612.         put_UWORD(world, osiz->stop);
  613.         put_XYZ(world, &osiz->size);
  614.     }
  615. }
  616.  
  617. static void process_POSN(sobj, world)
  618. SOBJ *sobj;
  619. WORLD *world;
  620. {
  621.     register POSN *posn;
  622.  
  623.     for (posn=sobj->posn; posn; posn=posn->next) {
  624.         put_name(world, "POSN", 4);
  625.         put_ULONG(world, 18L);
  626.         put_UWORD(world, posn->flags);
  627.         put_UWORD(world, posn->start);
  628.         put_UWORD(world, posn->stop);
  629.         put_XYZ(world, &posn->posn);
  630.     }
  631. }
  632.  
  633. static void process_ALGN(sobj, world)
  634. SOBJ *sobj;
  635. WORLD *world;
  636. {
  637.     register ALGN *algn;
  638.  
  639.     for (algn=sobj->algn; algn; algn=algn->next) {
  640.         put_name(world, "ALGN", 4);
  641.         put_ULONG(world, 18L);
  642.         put_UWORD(world, algn->flags);
  643.         put_UWORD(world, algn->start);
  644.         put_UWORD(world, algn->stop);
  645.         put_XYZ(world, &algn->algn);
  646.     }
  647. }
  648.  
  649. static void process_PALN(sobj, world)
  650. SOBJ *sobj;
  651. WORLD *world;
  652. {
  653.     register PALN *paln;
  654.  
  655.     for (paln=sobj->paln; paln; paln=paln->next) {
  656.         put_name(world, "PALN", 4);
  657.         put_ULONG(world, 6L);
  658.         put_UWORD(world, paln->flags);
  659.         put_UWORD(world, paln->start);
  660.         put_UWORD(world, paln->stop);
  661.     }
  662. }
  663.  
  664. static void process_TALN(sobj, world)
  665. SOBJ *sobj;
  666. WORLD *world;
  667. {
  668.     register TALN *taln;
  669.     int len;
  670.  
  671.     for (taln=sobj->taln; taln; taln=taln->next) {
  672.         len = strlen(taln->trackobj);
  673.         put_name(world, "TALN", 4);
  674.         put_ULONG(world, (ULONG)16L+(long)len);
  675.         put_UWORD(world, taln->flags);
  676.         put_UWORD(world, taln->start);
  677.         put_UWORD(world, taln->stop);
  678.         put_FRACT(world, taln->initial_y);
  679.         put_FRACT(world, taln->final_y);
  680.         /* BCPL string... byte (length) followed by string, then zero */
  681.         put_UBYTE(world, (UBYTE)len);
  682.         put_name(world, taln->trackobj, len);
  683.         put_UBYTE(world, 0);
  684.         if (len&1) put_UBYTE(world, 0);        /* pad byte */
  685.     }
  686. }
  687.  
  688. static void process_PTH2(sobj, world)
  689. SOBJ *sobj;
  690. WORLD *world;
  691. {
  692.     register PTH2 *pth2;
  693.     int len;
  694.  
  695.     for (pth2=sobj->pth2; pth2; pth2=pth2->next) {
  696.         len = strlen(pth2->path);
  697.         put_name(world, "PTH2", 4);
  698.         put_ULONG(world, (ULONG)24L+len);
  699.         put_UWORD(world, pth2->flags);
  700.         put_UWORD(world, pth2->start);
  701.         put_UWORD(world, pth2->stop);
  702.         put_ULONG(world, pth2->acceleration_frames);
  703.         put_FRACT(world, pth2->start_speed);
  704.         put_ULONG(world, pth2->deacceleration_frames);
  705.         put_FRACT(world, pth2->end_speed);
  706.         /* BCPL string... byte (length) followed by string, then zero */
  707.         put_UBYTE(world, (UBYTE)len);
  708.         put_name(world, pth2->path, len);
  709.         put_UBYTE(world, 0);
  710.         if (len&1) put_UBYTE(world, 0);        /* pad byte */
  711.     }
  712. }
  713.  
  714. static void process_GLB2(sobj, world)
  715. SOBJ *sobj;
  716. WORLD *world;
  717. {
  718.     register GLB2 *glb2;
  719.     int len;
  720.  
  721.     for (glb2=sobj->glb2; glb2; glb2=glb2->next) {
  722.         len = strlen(glb2->globalbrush);
  723.         put_name(world, "GLB2", 4);
  724.         put_ULONG(world, (ULONG)356L+len);
  725.         put_UWORD(world, glb2->flags);
  726.         put_UWORD(world, glb2->start);
  727.         put_UWORD(world, glb2->stop);
  728.         put_ULONG(world, glb2->sky_blending);
  729.         put_FRACT(world, glb2->starfield);
  730.         put_ULONG(world, glb2->transition);
  731.         /* These colors are stored as FRACTs */
  732.         put_XYZ(world, &glb2->ambient);
  733.         put_XYZ(world, &glb2->horizon);
  734.         put_XYZ(world, &glb2->zenith1);
  735.         put_XYZ(world, &glb2->zenith2);
  736.         put_XYZ(world, &glb2->fog_color);
  737.         put_FRACT(world, glb2->fog_bottom);
  738.         put_FRACT(world, glb2->fog_top);
  739.         put_FRACT(world, glb2->fog_length);
  740.         put_ULONG(world, glb2->brush_seq);
  741.         put_ULONG(world, glb2->backdrop_seq);
  742.         put_name(world, glb2->backdrop, 256);        /* Fixed size */
  743.         /* BCPL string... byte (length) followed by string, then zero */
  744.         put_UBYTE(world, (UBYTE)len);
  745.         put_name(world, glb2->globalbrush, len);    /* Var. size */
  746.         put_UBYTE(world, 0);
  747.         if (len&1) put_UBYTE(world, 0);        /* pad byte */
  748.     }
  749. }
  750.  
  751. static void process_AXIS(sobj, world)
  752. SOBJ *sobj;
  753. WORLD *world;
  754. {
  755.     register SAXIS *axis;
  756.  
  757.     for (axis=sobj->axis; axis; axis=axis->next) {
  758.         put_name(world, "AXIS", 4);
  759.         put_ULONG(world, 6L);
  760.         put_UWORD(world, axis->flags);
  761.         put_UWORD(world, axis->start);
  762.         put_UWORD(world, axis->stop);
  763.     }
  764. }
  765.  
  766. static void process_LITE(sobj, world)
  767. SOBJ *sobj;
  768. WORLD *world;
  769. {
  770.     register LITE *lite;
  771.  
  772.     for (lite=sobj->lite; lite; lite=lite->next) {
  773.         put_name(world, "LITE", 4);
  774.         put_ULONG(world, 22L);
  775.         put_UWORD(world, lite->flags);
  776.         put_UWORD(world, lite->start);
  777.         put_UWORD(world, lite->stop);
  778.         /* This color is stored as a FRACT */
  779.         put_XYZ(world, &lite->color);
  780.         put_ULONG(world, lite->transition);
  781.     }
  782. }
  783.  
  784. static void process_FILE(sobj, world)
  785. SOBJ *sobj;
  786. WORLD *world;
  787. {
  788.     register SFILE *file;
  789.     int len;
  790.  
  791.     for (file=sobj->file; file; file=file->next) {
  792.         len = strlen(file->object_description);
  793.         put_name(world, "FILE", 4);
  794.         put_ULONG(world, (ULONG)20L+len-(len&1));
  795.         put_UWORD(world, file->flags);
  796.         put_UWORD(world, file->start);
  797.         put_UWORD(world, file->stop);
  798.         put_FRACT(world, file->cycles_to_perform);
  799.         put_FRACT(world, file->initial_cycle_phase);
  800.         put_ULONG(world, file->transition);
  801.         /* BCPL string... byte (length) followed by string */
  802.         put_UBYTE(world, (UBYTE)len);
  803.         put_name(world, file->object_description, len);
  804.         if (!(len&1)) put_UBYTE(world, 0);        /* pad byte */
  805.     }
  806. }
  807.  
  808.