Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: bad animation ...

From: moliad::gmail::com at: 4-Jun-2007 16:55

also remember that VIEW is a cpu-based rendering engine. so graphics card have little effect on the general feel of REBOL (they have some effect, but at some point, the cpu is usually slower than the gfx card, so most recent graphics card just wait after the rendering.) I admit not having taken the time to look at the code, but here are some general guidelines on improving animation within rebol: -If your animation are simple and can be implemented using faces only, then do so (don't use draw if you don't have to). Faces are generally much faster. Things like scaling images, moving pictures around, and sliding guis, are usually faster when only using faces. -restrict your animations to smaller panes, when it makes sense to do so. large areas, really kill any pretence of speed in rebol (release 2.x). -do not mix face and draw animations within the same face. IIRC It seems to slow down the refresh a lot (possibly two blittings instead of one) -do not call show based on mouse events. use a timer and call show on that event only (using engage), even if you are reacting to mouse draging and stuff. -clear ALL detect and redraw feels of ALL faces which are animated. if some faces depend on this (buttons or other widgets) well, try to put them within another pane which will not have to be refreshed (show is not called on it). -SOME people have reported that the event handling when coupled with refreshing, seems to be unable to go above 20-30 frames per second, even if the refresh takes much less time to perform. (a loop able to refresh at 100 fps, if coupled to a scroller instead will generally only refresh 30 fps. it might feel smoother, but its a perception thing) AND THE BIGGEST SPEED IMPROVEMENT (keeping the best for last ;-): -use the changes facet within the face, I give an example at the end of my mail which shows the difference. This will give you almost real-time scrolling (even on larger faces) since they do not render, but really only blit damaged regions around! for scroll bars and dragging around faces, for example, the difference is staggering! (note that if you have Draw commands in the face being scrolled... there is a bug, it seems, where view will waste a little bit of time handling it anyways... but its still MUCH faster (it feels like its at least 10 times faster :-) -MAx rebol [ title: "FAST scrolling trick" license: 'MIT ] ; just open console print "" glbpane: none gblface: none steps: 50 ; a large-ish gui gui-size: 900x600 interrupt: false ;-------------------- ;- stop-anim() ;-------------------- stop-anim: func [ "" ][ iface/size: 0x0 show iface interrupt: true ] ;-------------------- ;- start-anim() ;-------------------- start-anim: func [ "" ][ iface/size: 125x30 show iface interrupt: false ] ;-------------------- ;- anim-fast() ;-------------------- anim-fast: func [ "" /local i ][ start-anim repeat i steps [ if interrupt [ break ] print i gblface/changes: 'offset gblface/offset: (i * 200 * 1x0 / steps) wait 0 show gblface ] ] ;-------------------- ;- anim-slow() ;-------------------- anim-slow: func [ "" /local i ][ start-anim repeat i steps [ if interrupt [ break ] print i gblface/offset: (i * 200 * 1x0 / steps) wait 0 show gblface ] ] view/new layout [ across gblpane: box gui-size return button "slow" [anim-slow] button "fast" [anim-fast] iface: button "STOP!" [stop-anim] 0x0 red ] gblface: make face [ size: 500x500 effect: [draw [ pen none fill-pen diamond 863x9 0 216 225 8 8 142.128.110.213 250.240.230.179 0.48.0.128 250.240.230.128 255.228.196.160 128.128.0.192 255.255.0.189 0.255.255.191 0.128.128.203 128.0.128.193 175.155.120.202 100.136.116.163 72.0.90.199 38.58.108.192 160.180.160.131 255.0.255.179 255.228.196.184 139.69.19.135 box 0x0 gui-size pen none fill-pen conic 127x863 0 300 116 9 7 192.192.192.160 255.0.255.171 240.240.240.157 40.100.130.137 255.164.200.133 255.255.255.154 0.128.128.163 0.0.128.166 255.228.196.145 255.0.255.168 box 0x0 gui-size pen none fill-pen cubic 375x810 0 89 72 1 8 222.184.135.137 160.82.45.166 38.58.108.157 255.205.40.131 255.150.10.129 240.240.240.139 0.48.0.171 179.179.126.150 0.255.0.131 72.0.90.159 box 0x0 gui-size pen none fill-pen radial -117x-266 0 65 158 3 2 255.255.255.143 72.0.90.181 40.100.130.146 100.120.100.130 178.34.34.185 128.0.128.169 72.0.90.160 139.69.19.190 100.120.100.165 178.34.34.148 222.184.135.164 0.0.255.141 160.82.45.143 box 0x0 gui-size pen none fill-pen cubic 826x989 0 171 233 2 2 160.82.45.134 192.192.192.167 38.58.108.191 100.136.116.158 175.155.120.187 245.222.129.140 80.108.142.189 255.150.10.158 40.100.130.197 164.200.255.187 179.179.126.169 255.150.10.168 164.200.255.197 220.20.60.170 255.0.0.147 76.26.0.175 box 0x0 gui-size ] ] ] gblpane/pane: gblface show gblpane do-events ;------------------------------------------------- here is an old example I gave on this list, for using faces instead of draw to resize images, might inspire you in a different direction than you where thinking, you can change the map-size to see how image size affects the rendering... can easily give you a good measure of the limits on which you can base your software: rebol [ title: "anim face resizing" license: 'MIT ] map-size: 200x200 steps: 50 sub-face-size-start: 50x50 sub-face-size-end: map-size * 5 ; create image map print "generating map buffer" map: make image! reduce [map-size white] fx: [ pen none fill-pen diamond 863x9 0 216 225 8 8 142.128.110.213 250.240.230.179 0.48.0.128 250.240.230.128 255.228.196.160 128.128.0.192 255.255.0.189 0.255.255.191 0.128.128.203 128.0.128.193 175.155.120.202 100.136.116.163 72.0.90.199 38.58.108.192 160.180.160.131 255.0.255.179 255.228.196.184 139.69.19.135 box 0x0 map-size pen none fill-pen conic 127x863 0 300 116 9 7 192.192.192.160 255.0.255.171 240.240.240.157 40.100.130.137 255.164.200.133 255.255.255.154 0.128.128.163 0.0.128.166 255.228.196.145 255.0.255.168 box 0x0 map-size pen none fill-pen cubic 375x810 0 89 72 1 8 222.184.135.137 160.82.45.166 38.58.108.157 255.205.40.131 255.150.10.129 240.240.240.139 0.48.0.171 179.179.126.150 0.255.0.131 72.0.90.159 box 0x0 map-size pen none fill-pen radial -117x-266 0 65 158 3 2 255.255.255.143 72.0.90.181 40.100.130.146 100.120.100.130 178.34.34.185 128.0.128.169 72.0.90.160 139.69.19.190 100.120.100.165 178.34.34.148 222.184.135.164 0.0.255.141 160.82.45.143 box 0x0 map-size pen none fill-pen cubic 826x989 0 171 233 2 2 160.82.45.134 192.192.192.167 38.58.108.191 100.136.116.158 175.155.120.187 245.222.129.140 80.108.142.189 255.150.10.158 40.100.130.197 164.200.255.187 179.179.126.169 255.150.10.168 164.200.255.197 220.20.60.170 255.0.0.147 76.26.0.175 box 0x0 map-size ] ; render a pretty pic print ["rendering pretty pic at " map-size] draw map fx do-size: func [ scale ][ sub/offset: (-200x-200 * scale) sub/size: ((sub-face-size-end - sub-face-size-start) * (scale)) + sub-face-size-start show sub ] ; anim simulation: do-anim: does [ s: now/precise repeat i steps [ do-size i / steps ;sub/offset: (-200x-200 * (i / steps)) ;sub/size: ((sub-face-size-end - sub-face-size-start) * (i / steps)) + sub-face-size-start ;show sub ;print i ] print ["map res: " map/size] print ["steps: " steps] print ["time: " difference now/precise s ] print ["frame rate: " steps / (to-decimal difference now/precise s) " f/sec"] ] ; open gui l: layout [ sub: box map 200x200 effect [fit] ] view layout [ canvas: box 500x500 button "animate" [do-anim] scroller 500x15 [do-size value] do [ canvas/pane: sub show canvas ] ]