[comp.sys.mac.programmer] Misc. Questions

c60a-3ec@e260-4g.berkeley.edu (Matthew Hills) (03/16/90)

Questions Regarding Sound:
  In using the Four-Tone Synthesizer, I want to produce 3-part music.
  Since any given Sound Rec only represents one set of notes, what is the
  best technique for sticking them together?  I understand that I should
  play asynchronously; but I'm curious what to do when I have a continuing
  note for 1 part, and need a new note for another.  Finally, the 3rd part
  will be a regular rhythm, and it will be playing the same note repeatedly;
  thus, I need a bit of a gap to distinguish between beats.

Questions Regarding Graphics:
  To get fast action, I will be saving everything as offscreen bitmaps (I'm
  not terribly worried about memory), and will by using CopyBits to bring
  them on screen.  Basically, I need to move the objects smoothly (and
  quickly) over the screen.  What is the best combination of erasing/
  shifting/redrawing?  I was thinking of using EraseRect to erase old
  picture, update the rectangle boundaries manually, then use copybits to
  bring the bitmap into the new rectangle.  Would this produce too much
  flicker?  Any comments on ways to make this more efficient?

General Questions:
  Is it generally faster to do stuff manually (ie: "if (x>3) v=0;"--have
  a lot of if's and cases) or to call procedures that will deal with a more
  general case?

Any advice on making a program fairly fast?  Basically, it will be a game
  program (no, no music while the game is playing).  I am planning on
  having movement of missles/bad_guys/good_guy spread out over a loop.
  (ie--1 loop consists of a bunch of "impulses", and fastest objects move
  every other impulse, slower objects move every 3rd, 4th, etc...).
  When is it best to check for player going "out of bounds"?  I was planning
  on checking on *every* impulse before he was moved.  Is there some ingenious
  way of avoiding checking every time, to eliminate unnecesary calculations?
  (I'm using Lightspeed, err Think, C).

Thanks Much,

==============================================================================
=--Matthew Hills-=--"You know, it just doesn't--=--Any viewpoints expressed--=
=----(KC6FGM)----=---get any better than this"--=--herein are my own.--------=
==============================================================================

jackiw@cs.swarthmore.edu (Nick Jackiw) (03/17/90)

c60a-3ec@e260-4g (Matthew Hills) writes:
> 
> Questions Regarding Sound:

Can't help you out.

> Questions Regarding Graphics:
>   To get fast action, I will be saving everything as offscreen bitmaps (I'm
>   not terribly worried about memory), and will by using CopyBits to bring
>   them on screen.  Basically, I need to move the objects smoothly (and
>   quickly) over the screen.  What is the best combination of erasing/
>   shifting/redrawing?  I was thinking of using EraseRect to erase old
>   picture, update the rectangle boundaries manually, then use copybits to
>   bring the bitmap into the new rectangle.  Would this produce too much
>   flicker?  Any comments on ways to make this more efficient?

Keep all images bit and depth aligned to the final destination.  I posted
an article a week ago describing this in some detail; check your archives.
Worst case CopyBits time is about 105% of average time, which means average
time is about as bad as it gets.  Best case time is 60-70% of average time.
If your game has any sort of static background, keep:

	A) An offscreen preserved copy of the background
	B) Offscreen image(s) of all the moving parts+their masks
	C) A "scratch buffer"

Initially, copy the background into the (C) and the screen.  Then, on each
wave of animation, compose your image in the appropriate layers by copying
images from (B) onto (C).  Keep track of the area in (C) which has been
modified. Copy only this to the screen.  Then copy only that area from (A)
back to C),  to set things up for the next phase.

Extend all of your CopyBits of areas so that horizontally, they copy full
longwords with no extra bits.
> 
> General Questions:
>   Is it generally faster to do stuff manually (ie: "if (x>3) v=0;"--have
>   a lot of if's and cases) or to call procedures that will deal with a more
>   general case?
> 

Manually.  C's procedures aren't *that* bad; Pascal's are wretched. Use
lots of global variables.

> Any advice on making a program fairly fast?  Basically, it will be a game
>   program (no, no music while the game is playing).  I am planning on
>   having movement of missles/bad_guys/good_guy spread out over a loop.
>   (ie--1 loop consists of a bunch of "impulses", and fastest objects move
>   every other impulse, slower objects move every 3rd, 4th, etc...).
>   When is it best to check for player going "out of bounds"?  I was planning
>   on checking on *every* impulse before he was moved.  Is there some ingenious
>   way of avoiding checking every time, to eliminate unnecesary calculations?
>   (I'm using Lightspeed, err Think, C).
> 

If it's a game, take whatever steps are reasonable to *guarantee* that you're
frontmost.  (For instance, track MultiFinder suspend and resume events, don't
allow desk accessories, etc.)  Also make sure that your window is always
fully visible--it's never dragged partially offscreen.  (You shouldn't let
them drag it at all, if you want to maintain bit-alignment.)  Now find
someone to write you a super-optimized CopyBits, which only transports
longwords from a source bitmap to a destination with three modes: WRITE,
AND, and OR.  Use this instead of copyBits, implement CopyMask as
myCopy(inversemaskBits,destRect,AND), myCopy(sourceImage,destRect,OR).
This will be at least twice as fast as CopyBits...Word does it: compare
scrolling a full screen window fully onscreen to the same window dragged
80% offscreen.  Though the content to copy is only 20% of the original,
they have to use CopyBits to get the clipping and the speed is twice as
slow.

> Thanks Much,
> 
> ==============================================================================
> =--Matthew Hills-=--"You know, it just doesn't--=--Any viewpoints expressed--=
> =----(KC6FGM)----=---get any better than this"--=--herein are my own.--------=
> ==============================================================================

If it's not commercial, post a copy to c.m.binaries.


--
     _  _|\____    Nick Jackiw | Visual Geometry Project | Math Department
   / /_/   O>  \   ------------+-------------------------+ Swarthmore College
   |       O>   |  215-328-8225| jackiw@cs.swarthmore.edu| Swarthmore PA 19081
    \_Guernica_/   ------------+-------------------------+                 USA