DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[Code] Blake Stone Animation Sequences
Page 1 of 2 Goto page 1, 2  Next
DieHard Wolfers Forum Index -> Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 17 Jun 2019

Topics: 46
Posts: 2329
Location: USA
usa.gif

PostPosted: Wed Sep 13, 2006 9:50 pm
   Subject: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

OK, I just noticed Blake Stone's ANIM files again a couple days ago and decided to take a look at them. The files are a series of chunks that are: GR (graphic), FI (Fade in), FO (Fade out), SD (Play sound), PA (Pause), and XX (End).

To begin using them, you'll want to grab the "Blake Stone Animation Studio" (BSAS for short) from my website.
http://winwolf3d.dugtrio17.com/

Now you can create your own animation. To do this, you need a bunch of 320x200 8 bit BMPs. Add your graphics to a new project and save it to a file. For this tutorial, I assume that the files are named ANIMxxt.ext where xx is the map number from GAMEMAPS, 't' is the type (B = beginning, E = ending), and ext is your data file extension. ex: ANIM00E.WL6 would play after you defeat E1M1 in Wolf3D and ANIM08B.WL6 would play before starting E1M9. Now to the code, which is actually somewhat simple. Copy/Paste will work wonders here.

NOTE: Ripper has converted the code to work with Wolf4SDL.

First, let's add the meat:
Open WL_INTER.C and add this code (I added it right before the Victory() procedure):
::: CODE :::
#define ANIMDELAY 10

boolean DoAnimation(boolean startinglevel) {
   char AnimName[13] = "ANIMxyE.";
   int file,mapon;
   char chunktype[] = "  ";
   long chunknum,chunksize;
   int chunkvalue;
   byte bgcolor,readbyte,p;
   unsigned hasstrand,pixelpos,datalength;
   memptr buffer;
   byte far *screen;
   byte far *bufferpos;
   unsigned x,y,temp;
   SDSMode PrevDigiMode = DigiMode;

#ifdef SPEAR
   mapon=gamestate.mapon;
#else
   mapon=gamestate.mapon+gamestate.episode*10;
#endif
   // Build the file name.
   AnimName[4]=(mapon / 10)+'0';
   AnimName[5]=(mapon % 10)+'0';
   if (startinglevel)
      // B = Beginning, E = Ending
      AnimName[6]='B';
   strcat(AnimName,extension);
   // try to open the file.
   file = open(AnimName, O_BINARY | O_RDONLY, S_IREAD);
   if (file == -1)
      // file does not exist... abort.
      return false;
   // force it to start as faded out
   VW_FadeOut();
   // Force the output to NOT be digital (bombs with "PML_GetPageBuffer: Purged main block").
   DigiMode = sds_Off;
   // prepare the draw buffer
   MM_GetPtr (&buffer,64000);
   MM_SetLock (&buffer,true);
   IN_ClearKeysDown();
   do {
      // read the chunk information.
      read(file,&chunktype,2);
      read(file,&chunknum,sizeof(chunknum));
      read(file,&chunksize,sizeof(chunksize));
      if (strcmp(chunktype,"XX") == 0)   // end
      {
         break;
      }
      if (strcmp(chunktype,"GR") == 0)   // graphic
      {
         if (chunknum==1)
         {
            // read the background color.
            read(file,&bgcolor,sizeof(bgcolor));
            // clear the screen for the first chunk
            VWB_Bar(0,0,320,200,bgcolor);
            // set our buffer to the bgcolor
            /*bufferpos = (byte far *)buffer+pixelpos;
            for (x=0;x<64000;x++)
               *bufferpos++ = bgcolor;*/

            _fmemset(buffer, bgcolor, 64000);
         }
         // Process the draw data
         do
         {
            read(file,&hasstrand,sizeof(hasstrand));
            read(file,&pixelpos,sizeof(pixelpos));
            read(file,&datalength,sizeof(datalength));
            if (!hasstrand)
               // no more draw strands, exit loop.
               break;
            /*bufferpos = (byte far *)buffer+pixelpos;
            // NOTE: This is slow because we are reading one byte at a time.
            //   TODO: Find out how to read a chunk from the file at once.
            for (x=0;x<datalength;x++) {
               read(file,&readbyte,sizeof(readbyte));
               *bufferpos++ = readbyte;
            }*/

            CA_FarRead(file, (byte far *) buffer + pixelpos, datalength);
         }
         while (true);
         // update the backbuffer.
         for (p=0; p<4; p++)
         {
            byte mask=1<<p;
            VGAMAPMASK(mask);
            for (x=p;x<320;x+=4)
            {
               screen = MK_FP(SCREENSEG,bufferofs+(x>>2));
               bufferpos=(byte far *)buffer+x;
               for (y=0;y<200;y++,screen+=80,bufferpos+=320)
               {
                  // write to the screen.
                  *screen=*bufferpos;
               }
            }
         }
         // Mark the entire screen for updating.
         VW_MarkUpdateBlock(0,0,319,199);
         VW_UpdateScreen();
         // wait a bit
         TimeCount = 0;
         while (TimeCount < ANIMDELAY)
         ;
      }
      else if (strcmp(chunktype,"FI") == 0)   // fade in
      {
         VW_FadeIn();
      }
      else if (strcmp(chunktype,"FO") == 0)   // fade out
      {
         VW_FadeOut();
      }
      else if (strcmp(chunktype,"SD") == 0)   // sound
      {
         read(file,&chunkvalue,sizeof(chunkvalue));
         SD_PlaySound(chunkvalue);
      }
      else if (strcmp(chunktype,"PA") == 0)   // pause
      {
         read(file,&chunkvalue,sizeof(chunkvalue));
         TimeCount = 0;
         while (TimeCount < chunkvalue)
         ;            
      }
      else
      {
         sprintf(str,"Unknown animation command: %s",chunktype);
         Quit (str);
      }
   }
   // allow the user to interrupt the animation sequence.
   while (!LastScan);

   // close up
   close(file);
   MM_FreePtr(&buffer);
   // Change back to the previous digi mode.
   DigiMode =PrevDigiMode;
   // return true to redraw the borders/statusbar
   return true;
}


Next open WL_DEF.H and add:
::: CODE :::
boolean DoAnimation(boolean startinglevel);

Again, I added this code right before the Victory() line.

Finally open WL_GAME.C and search for the GameLoop() procedure.
To allow an animation to play before starting a level find this code:
::: CODE :::
restartgame:
   ClearMemory ();
   SETFONTCOLOR(0,15);
   DrawPlayScreen ();
   died = false;
restart:
   do
   {

Add this code immediately following it:
::: CODE :::
      if (!loadedgame)
      {
         CA_LoadAllSounds();
            if (DoAnimation(true))
              // redraw the play borders after animation.
            DrawPlayScreen();
      }


To allow an animation to play after completing a normal level find this code:
::: CODE :::
      switch (playstate)
      {
      case ex_completed:
      case ex_secretlevel:
         gamestate.keys = 0;
         DrawKeys ();
         VW_FadeOut ();

         ClearMemory ();

Add this code immediately following it:
::: CODE :::
            if (DoAnimation())
              // redraw the play borders after animation.
            DrawPlayScreen();


To allow an animation to play after completing the "victory" level find this code:
::: CODE :::
      case ex_victorious:
#ifndef SPEAR
         VW_FadeOut ();
#else
         VL_FadeOut (0,255,0,17,17,300);
#endif
         ClearMemory ();

Add this code immediately following it:
::: CODE :::
            if (DoAnimation(false))
              // redraw the play borders after animation.
            DrawPlayScreen();

And your done.

Some notes:
- I apologize to everyone who is familiar with C. This code is rough and looks like it could be greatly improved by someone with more knowledge of the language than I.
- this code is probably slow on older systems. I'm sure someone who knows C better than I can speed things up.
- For some reason the program will bomb with "PML_GetPageBuffer: Purged main block" if it tried to play a VSWAP sound during the animation. So I temporarily turn off digital sounds during the animation, then put the setting back how it was when it's done.

Hope someone can make some use of this.

EDIT: I changed the code slightly to allow animations to play before a map is loaded and also when the player wins the mission.
EDIT2: Forgot to add the line that forces the animation to start as 'faded out'.
EDIT3: Added some code reductions based upon Rippers' Wolf4SDL code. The green lines should be replaced by the blue lines.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page


Last edited by Adam Biser on Thu Mar 27, 2008 12:13 pm; edited 1 time in total
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Thu Sep 14, 2006 3:17 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I got the same thing when trying to put digisounds on the menu. It had the same error and some others. I abandoned that idea because i couldn't maneuver the menu.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 18:18 ago.

Topics: 166
Posts: 8396
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Fri Sep 15, 2006 9:27 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Excellent, Adam! Thanks! Thumbs Up This is much more ideal than trying to do animation through the VGAGRAPH pics. It'll be perfect to do for the ending sequence I have planned for my own TC, assuming I can handle the code changes okay.
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 17 Jun 2019

Topics: 46
Posts: 2329
Location: USA
usa.gif

PostPosted: Fri Sep 15, 2006 9:55 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yeah, I think so, too. It was a lot of fun figuring these files out. I just wish I was a better artist because these can be a lot of fun.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
Haasboy
DieHard Officer
DieHard Officer


Joined: 23 Jul 2003
Last Visit: 17 Jun 2019

Topics: 58
Posts: 581
Location: South Africa, Johannesburg
southafrica.gif

PostPosted: Fri Sep 15, 2006 10:03 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I thank thee for creating something so great. Can this tutorial also be used for stuff like the title screen???




Before you created this code I had a vision of having an animated sequence before the game starts and thanks to you I be able to implement it..................

_________________
Haasboy Engine - Currently under construction (To be used with future mods - F.A.D.E.D. - Mansion X - Rising Evil Series)
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 17 Jun 2019

Topics: 46
Posts: 2329
Location: USA
usa.gif

PostPosted: Fri Sep 15, 2006 10:12 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Before the game starts as in starting a mission? Or before the menu screen? This first way is already handled if you name the file ANIM00B.ext. The second might work by adding
::: CODE :::
DoAnimation(true);

someplace, like where the PC-13 message normally appeared. You'd have to modify it a bit to handle it since it's not a before or after map animation.... however you want to do it.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
Codetech84
Code Master
Code Master


Joined: 12 Mar 2003
Last Visit: 27 Aug 2018

Topics: 22
Posts: 1283
Location: Rauma - Finland
finland.gif

PostPosted: Sat Sep 16, 2006 12:21 am
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

What if you chaged the file specification to support audio. I mean something like,

::: CODE :::
if (strcmp(chunktype,"SD") == 0)   // sound


I'm sure you get the idea.

_________________
Click here to visit KFH Games website!
*UPDATED* Spear of Destiny Reloaded
KFH Games on Facebook
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 17 Jun 2019

Topics: 46
Posts: 2329
Location: USA
usa.gif

PostPosted: Sat Sep 16, 2006 9:04 am
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

It already does support audio, though it only plays adlib or pc because the digital sounds make it bomb.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
WLHack
DieHard Wolfer
DieHard Wolfer


Joined: 10 Jul 2005
Last Visit: 18 Jan 2018

Topics: 66
Posts: 1237
Location: Loppi - Finland
finland.gif

PostPosted: Sat Sep 16, 2006 9:55 am
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Hmm... This is really interesting. I think I could improve
my games lot with this... Thanks Adam.

_________________
False Spear download
False Spear SDL download
Wolfenstein-blog
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Sat Sep 16, 2006 12:27 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I got it to work as the PG13 screen. I made a special little logo for Crack Software. I modified the code like this:

::: CODE :::
#define ANIMDELAY 5

boolean CSLOGOAnim(void)
{
   char AnimName[13] = "ANIMCS.";
   int file;
   char chunktype[] = "  ";
   long chunknum,chunksize;
   int chunkvalue;

[...rest of code...]


In the definitions I removed a few as they were unneeded. I changed the ANIMDELAY to make them go faster, so the animation is a little better.

Then in PG13 I put CSLOGOAnim(); and removed the VWB_DrawPic and other things.

I may have forgotten a few things in this modification of code but it works on DOOM: LOH

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 17 Jun 2019

Topics: 46
Posts: 2329
Location: USA
usa.gif

PostPosted: Sat Sep 16, 2006 3:51 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Cool. I didn't think it would take much to make it work when starting the program. ANIMDELAY was just kind of arbitrarily chosen. It might not be the actual value that Blake Stone has. Did you have any trouble with the BS Anim. Studio program? Just curious how others find it.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Sat Sep 16, 2006 4:08 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

No problems at all, I just find it hard to figure out what image is what, and maybe in the next release put this tutorial in it, it might help anyone else who might what to use it. I haven't found any bugs in the program so it seems very stable. I like it, my brother says i have to put your name in large font on my credits for all of the things you've done to make everything work.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 18:18 ago.

Topics: 166
Posts: 8396
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Sat Sep 16, 2006 7:24 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

insurrectionman wrote:
In the definitions I removed a few as they were unneeded.
If it's not too much trouble, could you post the complete code with your optimizations? It'd be much easier to Copy and Paste into Notepad this way, at least for less experienced programmers like Yours Truly. Embarassed
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Sat Sep 16, 2006 8:21 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

This is in WL_INTER.C

::: CODE :::
#define ANIMDELAY 5

boolean CSLOGOAnim(void)
{
   char AnimName[13] = "ANIMCS.";
   int file;
   char chunktype[] = "  ";
   long chunknum,chunksize;
   int chunkvalue;
   byte bgcolor,readbyte,p;
   unsigned hasstrand,pixelpos,datalength;
   memptr buffer,strand;
   byte far *screen;
   byte far *bufferpos;
   unsigned x,y,temp;
   SDSMode PrevDigiMode = DigiMode;

 
   strcat(AnimName,extension);
   // try to open the file.
   file = open(AnimName, O_BINARY | O_RDONLY, S_IREAD);
   // force it to start as faded out
   VW_FadeOut();
   // Force the output to NOT be digital (bombs with "PML_GetPageBuffer: Purged main block").
   DigiMode = sds_Off;
   // prepare the draw buffer
   MM_GetPtr (&buffer,64000);
   MM_SetLock (&buffer,true);
   IN_ClearKeysDown();
   do
   {
      // read the chunk information.
      read(file,&chunktype,2);
      read(file,&chunknum,sizeof(chunknum));
      read(file,&chunksize,sizeof(chunksize));
      if (strcmp(chunktype,"XX") == 0)   // end
      {
         break;
      }
      if (strcmp(chunktype,"GR") == 0)   // graphic
      {
         if (chunknum==1)
         {
            // read the background color.
            read(file,&bgcolor,sizeof(bgcolor));
            // clear the screen for the first chunk
            VWB_Bar(0,0,320,200,bgcolor);
            // set our buffer to the bgcolor
            bufferpos = (byte far *)buffer+pixelpos;
            for (x=0;x<64000;x++)
               *bufferpos++ = bgcolor;
         }
         // Process the draw data
         do
         {
            read(file,&hasstrand,sizeof(hasstrand));
            read(file,&pixelpos,sizeof(pixelpos));
            read(file,&datalength,sizeof(datalength));
            if (!hasstrand)
               // no more draw strands, exit loop.
               break;
            bufferpos = (byte far *)buffer+pixelpos;
            // NOTE: This is slow because we are reading one byte at a time.
            //   TODO: Find out how to read a chunk from the file at once.
            for (x=0;x<datalength;x++)
            {
               read(file,&readbyte,sizeof(readbyte));
               *bufferpos++ = readbyte;
            }
         }
         while (true);
         // update the backbuffer.
         for (p=0; p<4; p++)
         {
            byte mask=1<<p;
            VGAMAPMASK(mask);
            for (x=p;x<320;x+=4)
            {
               screen = MK_FP(SCREENSEG,bufferofs+(x>>2));
               bufferpos=(byte far *)buffer+x;
               for (y=0;y<200;y++,screen+=80,bufferpos+=320)
               {
                  // write to the screen.
                  *screen=*bufferpos;
               }
            }
         }
         // Mark the entire screen for updating.
         VW_MarkUpdateBlock(0,0,319,199);
         VW_UpdateScreen();
         // wait a bit
         TimeCount = 0;
         while (TimeCount < ANIMDELAY)
         ;
      }
      else if (strcmp(chunktype,"FI") == 0)   // fade in
      {
         VW_FadeIn();
      }
      else if (strcmp(chunktype,"FO") == 0)   // fade out
      {
         VW_FadeOut();
      }
      else if (strcmp(chunktype,"SD") == 0)   // sound
      {
         read(file,&chunkvalue,sizeof(chunkvalue));
         SD_PlaySound(chunkvalue);
      }
      else if (strcmp(chunktype,"PA") == 0)   // pause
      {
         read(file,&chunkvalue,sizeof(chunkvalue));
         TimeCount = 0;
         while (TimeCount < chunkvalue)
         ;           
      }
      else
      {
         sprintf(str,"Unknown animation command: %s",chunktype);
         Quit (str);
      }
   }
   // allow the user to interrupt the animation sequence.
   while (!LastScan);

   // close up
   close(file);
   MM_FreePtr(&buffer);
   // Change back to the previous digi mode.
   DigiMode =PrevDigiMode;
   // return true to redraw the borders/statusbar
   return true;
}


This is in WL_MAIN.C

::: CODE :::
if (!NoWait)
        //   PG13 ();
        CSLOGOAnim ();
        VW_FadeOut ();


The VW_FadeOut(); is for when you press a key to skip the intro.

In WL_DEF.H put void CSLOGOAnim(void); anywhere

It should work there, i don't think i missed anything.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 17 Jun 2019

Topics: 46
Posts: 2329
Location: USA
usa.gif

PostPosted: Sat Sep 16, 2006 8:26 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

You might want to keep the
::: CODE :::
if (file == -1)
      // file does not exist... abort.
      return false;

In there, just in case there's a problem opening the file.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Sun Sep 17, 2006 12:00 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Good point, I never thought of that. I should look into that.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 18:18 ago.

Topics: 166
Posts: 8396
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Mon Sep 18, 2006 9:02 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Insurrectionman, thanks for posting the updated code. Maybe I could do something to return the favor, such as possibly sending you my first level of my mapper's-contest submissions? Smile
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Tue Sep 19, 2006 3:50 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

no problem, i don't want to get off topic with the mapping contest submission thing so i'll send you a PM regarding it.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 18:18 ago.

Topics: 166
Posts: 8396
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Tue Sep 19, 2006 7:40 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Insurrectionman - Thanks. Smile

Adam - If it's not too much trouble, could you tell us anything about how the script of the ANIM* files work? The Help section of the program isn't telling me much, and I've never seen the format of ANIM files elaborated anywhere.
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 17 Jun 2019

Topics: 46
Posts: 2329
Location: USA
usa.gif

PostPosted: Tue Sep 19, 2006 7:45 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yeah, I'm eventually going to add pages to my site's wiki that outlines how the data in each file type is stored. I'll probably do that one first since it's fresh on my mind and is pretty easy. I didn't really have any time to make up a decent help file for BSAS, but I didn't figure the program really needed one that badly.

EDIT: http://winwolf3d.dugtrio17.com/wiki/Anim_File_Format

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Fri Apr 06, 2007 8:39 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Is it possible to get this working on WOLF4GW? I got it to pass in coding, but it crashes when in-game.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
ZuljinRaynor
DieHard Officer
DieHard Officer


Joined: 17 Jan 2004
Last Visit: 30 May 2018

Topics: 19
Posts: 559

usa.gif

PostPosted: Wed May 30, 2007 2:03 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Sorry for bumping this, but I got a question.
Since sound is limited to Adlib/Pc Speaker, how about Music?

This seems really, really, really, really cool and I plan on using it, but since there are no digi sounds, I don't have a problem there. Just how about music? Will IMFs play during a movie?
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 17 Jun 2019

Topics: 46
Posts: 2329
Location: USA
usa.gif

PostPosted: Wed May 30, 2007 4:12 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Hmm, I would think so. You'd have to try it out.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Wed Mar 26, 2008 3:13 pm
   Subject: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Hey, to all who can help,

I have been attempting to work on this tutorial to make it work properly in Wolf4SDL or Wolf4GW (at first), I have gotten the function to compile in Wolf4SDL but it doesn't work at all. It has something to do with "memptr buffer" in the function, if anyone knows how to help, or even give some advice, I'd appreciate it

here's my edited function:

::: CODE :::
#define ANIMDELAY 10

boolean DoAnimation(boolean startinglevel)
{
   char AnimName[13] = "ANIMxyE.";
   int file,mapon;
   char chunktype[] = "  ";
   long chunknum,chunksize;
   int chunkvalue;
   byte bgcolor,readbyte,p;
   unsigned hasstrand,pixelpos,datalength;
   memptr buffer=0; // needs to be =0 (probably isn't, to not give a warning, otherwise it is not defined and the game debugs out)
   byte *screen;
   byte *bufferpos;
   unsigned x,y;
   SDSMode PrevDigiMode = DigiMode;

#ifdef SPEAR
   mapon=gamestate.mapon;
#else
   mapon=gamestate.mapon+gamestate.episode*10;
#endif
   // Build the file name.
   AnimName[4]=(mapon / 10)+'0';
   AnimName[5]=(mapon % 10)+'0';
   if (startinglevel)
      // B = Beginning, E = Ending
      AnimName[6]='B';
   strcat(AnimName,extension);
   // try to open the file.
   file = open(AnimName, O_BINARY | O_RDONLY); // removed I_SREAD (isn't defined in SDL)
   if (file == -1)
      // file does not exist... abort.
      return false;
   // force it to start as faded out
   VW_FadeOut();
   // Force the output to NOT be digital (bombs with "PML_GetPageBuffer: Purged main block").
   DigiMode = sds_Off;
   // prepare the draw buffer
//   MM_GetPtr (&buffer,64000);
   //MM_SetLock (&buffer,true);
   IN_ClearKeysDown();
   do
   {
      // read the chunk information.
      read(file,&chunktype,2);
      read(file,&chunknum,sizeof(chunknum));
      read(file,&chunksize,sizeof(chunksize));
      if (strcmp(chunktype,"XX") == 0)   // end
      {
         break;
      }
      if (strcmp(chunktype,"GR") == 0)   // graphic
      {
         if (chunknum==1)
         {
            // read the background color.
            read(file,&bgcolor,sizeof(bgcolor));
            // clear the screen for the first chunk
            VWB_Bar(0,0,320,200,bgcolor);
            // set our buffer to the bgcolor
            bufferpos = (byte *)buffer+pixelpos;
            for (x=0;x<screenHeight*screenWidth;x++)
               *bufferpos++ = bgcolor;
         }
         // Process the draw data
         do
         {
            read(file,&hasstrand,sizeof(hasstrand));
            read(file,&pixelpos,sizeof(pixelpos));
            read(file,&datalength,sizeof(datalength));
            if (!hasstrand)
               // no more draw strands, exit loop.
               break;
            bufferpos = (byte *)buffer+pixelpos;
            // NOTE: This is slow because we are reading one byte at a time.
            //   TODO: Find out how to read a chunk from the file at once.
            for (x=0;x<datalength;x++)
            {
               read(file,&readbyte,sizeof(readbyte));
               *bufferpos++ = readbyte;
            }
         }
         while (true);
         // update the backbuffer.
         for (p=0; p<4; p++)
         {
            byte mask=1<<p;
            for (x=p;x<screenHeight;x+=4)
            {
               screen = vbuf+x;
               bufferpos=(byte *)buffer+x;
               for (y=0;y<screenWidth;y++,screen+=bufferPitch,bufferpos+=screenHeight)
               {
                  // write to the screen.
                  *screen=*bufferpos;
               }
            }
         }
         // Mark the entire screen for updating.
//         VW_MarkUpdateBlock(0,0,319,199);
         VW_UpdateScreen();
         // wait a bit
         gamestate.TimeCount = 0;
         while (gamestate.TimeCount < ANIMDELAY);
      }
      else if (strcmp(chunktype,"FI") == 0)   // fade in
      {
         VW_FadeIn();
      }
      else if (strcmp(chunktype,"FO") == 0)   // fade out
      {
         VW_FadeOut();
      }
      else if (strcmp(chunktype,"SD") == 0)   // sound
      {
         read(file,&chunkvalue,sizeof(chunkvalue));
         SD_PlaySound((soundnames)chunkvalue);
      }
      else if (strcmp(chunktype,"PA") == 0)   // pause
      {
         read(file,&chunkvalue,sizeof(chunkvalue));
         gamestate.TimeCount = 0;
         while (gamestate.TimeCount < chunkvalue)
         ;           
      }
      else
      {
         sprintf(str,"Unknown animation command: %s",chunktype);
         Quit (str);
      }
   }
   // allow the user to interrupt the animation sequence.
   while (!LastScan);

   // close up
   close(file);
   free(buffer); // this originally was MM_FreePtr (buffer);
   // Change back to the previous digi mode.
   DigiMode =PrevDigiMode;
   // return true to redraw the borders/statusbar
   return true;
}


EDIT: Sorry to bump this thread, but it is a fantastic feature open to animations and such.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Ripper
Code Master - Developer
Code Master - Developer


Joined: 15 Mar 2003
Last Visit: 30 Sep 2008

Topics: 21
Posts: 527
Location: Germany
blank.gif

PostPosted: Wed Mar 26, 2008 4:52 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

You forgot one change you made: you commented out the line "MM_GetPtr (&buffer,64000);". This was a vital line, which allocated a buffer of 64000 bytes, and wants to get a proper replacement, just like the "MM_FreePtr(buffer);" line, you already replaced correctly.
So the replacement for the MM_GetPtr line is: buffer = malloc(64000);

But there are more problems: The code was written for a 16-bit system. So the data types int and unsigned were only 16-bit, and not 32-bit as on a 32-bit system.
As you read data out of files, you have to make sure, the correct sizes are used.
If you search the code for "sizeof" you'll find several variables. Here's a list with their declared data types and the data types you should use instead:

chunknum: long -> int32_t
chunksize: long -> int32_t
bgcolor: byte (OK)
hasstrand: unsigned -> uint16_t
pixelpos: unsigned -> uint16_t
datalength: unsigned -> uint16_t
readbyte: byte (OK)
chunkvalue: int -> int16_t

Another problem:
::: CODE :::
         gamestate.TimeCount = 0;
         while (gamestate.TimeCount < ANIMDELAY);
and
::: CODE :::
gamestate.TimeCount = 0;
         while (gamestate.TimeCount < chunkvalue)
         ;

As there is no timer interrupt and such gamestate.TimeCount never gets changed, this is an endless loop.
Replace the code parts by the line "Delay(ANIMDELAY);" and "Delay(chunkvalue);" respectively.

To make it possible for the user to interrupt the animation, call "IN_WaitAndProcessEvents();" before the end of the "while(!LastScan)" loop. Otherwise LastScan will never be updated.

I didn't try it, so I don't know, if all problems are solved.
Hope that helps!

_________________
Life is an awful game, but the graphics resolution rocks ;D
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Wed Mar 26, 2008 5:36 pm
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Close, but no cigar, it is probably just better cleaned up now, but i've traced the crashing of the function to this line:

::: CODE :::
for (x=0;x<64000;x++)
               *bufferpos++ = bgcolor;


i suppose the buffer needs to be larger for large screen sizes, i'm not 100% sure, just a guess.

EDIT: Also another spot found

::: CODE :::
for (y=0;y<screenWidth;y++,screen+=bufferPitch,bufferpos+=screenHeight)
               {
                  // write to the screen.
                  *screen=*bufferpos;
               }


that might be different as i removed the lines from the first error (coded above), that may have caused this to change.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Ripper
Code Master - Developer
Code Master - Developer


Joined: 15 Mar 2003
Last Visit: 30 Sep 2008

Topics: 21
Posts: 527
Location: Germany
blank.gif

PostPosted: Thu Mar 27, 2008 4:45 am
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Oh yes, I forgot to say, that after those changes it will only work for a resolution of 320x200.

But
::: CODE :::
            bufferpos = (byte *)buffer+pixelpos;
            for (x=0;x<screenHeight*screenWidth;x++)
               *bufferpos++ = bgcolor;
should be
::: CODE :::
            memset(buffer, bgcolor, 64000);


By the way, you can replace
::: CODE :::
            bufferpos = (byte *)buffer+pixelpos;
            // NOTE: This is slow because we are reading one byte at a time.
            //   TODO: Find out how to read a chunk from the file at once.
            for (x=0;x<datalength;x++)
            {
               read(file,&readbyte,sizeof(readbyte));
               *bufferpos++ = readbyte;
            }
by
::: CODE :::
            read(file, (byte *) buffer + pixelpos, datalength);


The scaling should be done, when you "update the backbuffer" (which actually updates the screen buffer). You should be able to find very similar code in id_vh.cpp (VH_MemToScreen or something).
But
::: CODE :::
            for (x=p;x<screenHeight;x+=4)
            {
               screen = vbuf+x;
               bufferpos=(byte *)buffer+x;
               for (y=0;y<screenWidth;y++,screen+=bufferPitch,bufferpos+=screenHeight)
               {
                  // write to the screen.
                  *screen=*bufferpos;
               }
            }
should read
::: CODE :::
            for (x=p;x<320;x+=4)
            {
               screen = vbuf+x;
               bufferpos=(byte *)buffer+x;
               for (y=0;y<200;y++,screen+=bufferPitch,bufferpos+=320)
               {
                  // write to the screen.
                  *screen=*bufferpos;
               }
            }

But I think the outer loop is not necessary. It should just work, if you replace "x+=4" by "x++".

We're getting closer Wink

_________________
Life is an awful game, but the graphics resolution rocks ;D
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 17 Jun 2019

Topics: 46
Posts: 2329
Location: USA
usa.gif

PostPosted: Thu Mar 27, 2008 6:28 am
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks for pointing out the first two code reductions. For the original Wolf code they become:
::: CODE :::
_fmemset(buffer, bgcolor, 64000);

and
::: CODE :::
CA_FarRead(file, (byte far *) buffer + pixelpos, datalength);

Testing seems to show that they work. Missing such nice little calls like those shows how much C I know. Laughing

I think the animations are cool addition. Too bad I suck at drawing things. I'd love to be able to implement some original ones.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 16 May 2019

Topics: 87
Posts: 758
Location: Wisconsin
usa.gif

PostPosted: Thu Mar 27, 2008 7:59 am
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I guess it is helping but I am still having problems with the backbuffer, I've even set my resolution at 320x200, it doesn't seem to help. I thought I knew what I was doing but I guess I am as lost as ever. For some reason it doesn't want to write the images onto the screen.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Ripper
Code Master - Developer
Code Master - Developer


Joined: 15 Mar 2003
Last Visit: 30 Sep 2008

Topics: 21
Posts: 527
Location: Germany
blank.gif

PostPosted: Thu Mar 27, 2008 11:59 am
   Subject: Re: [Code] Blake Stone Animation Sequences
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

OK, I got it running and also included the scaling to full resolution and removed the backbuffer, as there is already buffering.
The problems were the wrong "IN_WaitAndProcessEvents()" function (correct is "IN_ProcessEvents()") (sorry Mr Green) and the non existance of the vbuf variable you were using. Where did you take this variable? There is a reason, that you cannot access that variable outside of wl_draw.cpp: It's only valid in there! To get access to the screenBuffer memory elsewhere you have to issue an "byte *vbuf = VL_LockSurface(screenBuffer);" and BEFORE you call any functions which use any blitting functions "VL_UnlockSurface(screenBuffer);".
If you forget to call the unlock function, you may get strange results on some but not all computers, leading to very annoying support problems Wink

Here's the full code of the Wolf4SDL version:
::: CODE :::
#define ANIMDELAY 2

boolean DoAnimation(char *filename)
{
    char chunktype[] = "  ";
    int32_t chunknum, chunksize;
    int16_t chunkvalue;
    byte bgcolor, readbyte;
    uint16_t hasstrand, pixelpos, datalength;
    SDSMode PrevDigiMode = DigiMode;

    // try to open the file.
    int file = open(filename, O_BINARY | O_RDONLY);
    if (file == -1)
        // file does not exist... abort.
        return false;

    byte *buf = (byte *) malloc(65536);

    // force it to start as faded out
    VW_FadeOut();

    // Force the output to NOT be digital (bombs with "PML_GetPageBuffer: Purged main block").
    DigiMode = sds_Off;

    IN_ClearKeysDown();
    do
    {
        // read the chunk information.
        read(file,&chunktype,2);
        read(file,&chunknum,sizeof(chunknum));
        read(file,&chunksize,sizeof(chunksize));
        if (strcmp(chunktype,"XX") == 0)   // end
            break;

        if (strcmp(chunktype,"GR") == 0)   // graphic
        {
            byte *vbuf = VL_LockSurface(screenBuffer);
            if (chunknum==1)
            {
                // read the background color.
                read(file,&bgcolor,sizeof(bgcolor));
                // clear the screen for the first chunk
                VWB_Bar(0,0,320,200,bgcolor);
            }
            // Process the draw data
            do
            {
                read(file,&hasstrand,sizeof(hasstrand));
                read(file,&pixelpos,sizeof(pixelpos));
                read(file,&datalength,sizeof(datalength));
                if (!hasstrand)
                    // no more draw strands, exit loop.
                    break;

                read(file, buf, datalength);    // datalength is always < 65536 (it's only 16-bit)

                int x = pixelpos % 320;
                int y = pixelpos / 320;
                byte *vbufptr = vbuf + y * scaleFactor * bufferPitch + x * scaleFactor;
                byte *bufptr = buf;
                for(int i = 0; i < datalength; vbufptr += scaleFactor * (bufferPitch - 320), x = 0)
                {
                    for(int j = x; i < datalength && j < 320; i++, j++, vbufptr += scaleFactor)
                    {
                        byte col = *bufptr++;
                        for(unsigned m = 0; m < scaleFactor; m++)
                            for(unsigned n = 0; n < scaleFactor; n++)
                                vbufptr[m * bufferPitch + n] = col;
                    }
                }
            }
            while (true);
            VL_UnlockSurface(screenBuffer);
            VW_UpdateScreen();
            Delay(ANIMDELAY);
        }
        else if (strcmp(chunktype,"FI") == 0)   // fade in
        {
            VW_FadeIn();
        }
        else if (strcmp(chunktype,"FO") == 0)   // fade out
        {
            VW_FadeOut();
        }
        else if (strcmp(chunktype,"SD") == 0)   // sound
        {
            read(file,&chunkvalue,sizeof(chunkvalue));
            SD_PlaySound((soundnames)chunkvalue);
        }
        else if (strcmp(chunktype,"PA") == 0)   // pause
        {
            read(file,&chunkvalue,sizeof(chunkvalue));
            Delay(chunkvalue);
        }
        else
        {
            sprintf(str,"Unknown animation command: %s",chunktype);
            close(file);
            free(buf);
            Quit (str);
        }
        IN_ProcessEvents();
    }
    // allow the user to interrupt the animation sequence.
    while (!LastScan);

    // close up
    close(file);
    free(buf);
    // Change back to the previous digi mode.
    DigiMode = PrevDigiMode;
    // return true to redraw the borders/statusbar
    return true;
}

As you can see I also changed the ANIMDELAY from 10 to 2. On my system it is far too slow otherwise. I don't know if there is a problem with the SDL_Delay function. It gets the delay in ms, so it should be system independent. But perhaps it doesn't work correctly, if the delay is too short... But 142 ms is a very long time (10 Wolf tics), so it should be no problem.
Please tell me, how you feel about the animation speed.

@Adam: Are you really sure that one animation tic is one 70th of a second just as in Wolf?

_________________
Life is an awful game, but the graphics resolution rocks ;D
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 2 Goto page 1, 2  Next
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Sticky: [Info] Help for newbie coders! C++ Tutorial
Author: Dugtrio17
20 11124 Sun Jan 10, 2010 12:26 pm
Fragstein3D View latest post
No new posts [Info] Black & White Effect - Tutorial
Author: Guest
10 299 Thu Mar 17, 2005 6:24 pm
Dugtrio17 View latest post
No new posts [Help] Setting RocketLauncher: Explosive Range...?
Author: KyleRTCW
17 7087 Thu Jun 03, 2004 3:21 am
Codetech84 View latest post
No new posts [Help] Berserk mode
Author: wolf3dbreaker
2 2451 Tue Feb 03, 2004 11:01 pm
Xarkon View latest post
No new posts [Info] Swap file decompiler
Author: DarkOne
3 4865 Wed Jul 09, 2003 10:34 pm
Guest View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group