sundeepblue

Computer Graphics, CAGD, Demoscene, intro [crack each line of code, cram each bit of byte, create each idea of mind]

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

如何在demo中合成场景?

from http://scene.org/showforum.php?forum=11&topic=108058
-----------------------------------------------------------------------
I'm skilled in c++/delphi/asm and graphics coding.
But one moment is still unclear: sync in demos.
I suppose that there should be a kind a script containing a timeline, like this

[time] [effect] [params]
....
....


Am I right or not?
How transition beetween scenes is made according to timeline?
And how all this is set up in main loop (we need main loop?)?

So, what is a basic structure of demo? Which parts it contain?

I'll be glad to any help

[Post edited by nofate on Saturday 15 July 2006 - 10:39]

-----------------------------------------------------------------------

Posted by _-_-__ Saturday 15 July 2006 - 10:12 
The main structure of a demo is:


initVideoAndAudioDevices();
buildEffects(); // pre-calculation, allocations
mainLoop();
// in demo making it is allowed to use the OS as a garbage collector ;)
releaseVideoAndAudioDevices()


Sometimes the main loop of a demo is as simple as:


boolean mustQuit = false;
while (!mustQuit) {
const double ms = getCurrentMilliseconds();
const double transition1Ms = 8000.;
const double transition2Ms = 12000.;

if (ms >= 0. && ms < transition1Ms) {
effect1 (ms);
} else if (ms >= transition1Ms && ms < transition2Ms) {
effect2 (ms);
} else if (ms >= transition2Ms && ms < endMs) {
effect3 (ms);
} else if (ms >= endMs) {
mustQuit = true;
}

if (pressedEscape ()) {
mustQuit = true;
}
}


Now the quality of the sync depends on the time source. It must not drift respective to the music's sync.

For more sophisticated purposes, for example if you want to have multiple effects running at the same time, or run transition effects for a period, either you stick with the manual if ... else sequence like such:


if (ms >= 0. && ms < transition1StartMs) {
effect1 (ms);
} else if (ms >= transition1StartMs && ms < transition1EndMs) {
transition1 (effect1(ms), effect2(ms));
} else if (ms >= transition1EndMs && ms < transition2Ms) {
effect2 (ms)
}


Or you design a timeline system: tracks of effects with ending and starting points. The problems is when you want to compose effects together. Then you need to have a certain order of operation between tracks.

It is also particularly interesting to either be able to restart the effect from the beginning ( effect (ms - clipBeginningMs) or keep it running. ( effect (ms) )

See for example mfx or kewlers demos for a good use of the two methods. Sometimes they will slice an effect with cuts of another effect, sometimes they will play the same effect for a while, but resetting the origin at given sync points. Making it appear to jump.

Historically, we also used the module player as a sync device, for effect control. Since one could add custom commands inside the module, that would be ignored by the sound player, but could be processed and detected by your effect code. This *could* be carried over today by embedding information inside the music stream (.ogg for example)

Another historical but still practical method to create your timeline, is spacebar-synching: run a special development version of your demo that record spacebar presses in time as transitions from one effect to another. You obtain a file with sync points that you can then include in your released demo.

[Post edited by _-_-__ on Saturday 15 July 2006 - 10:25]

posted on 2007-07-31 13:13  sundeepblue  阅读(222)  评论(0编辑  收藏  举报