1. Need Help with Musubi Demo
- Posted by euphoric (admin) Oct 19, 2010
- 1305 views
I have created a demo for wxEuphoria that provides a benchmark for graphics primitives. I'm wanting to port it to a demo for SDL/Musubi (from Mark Akita), but it's having memory issues. I'm posting the program below in case anybody can help.
In the original demo, buttons were used to toggle drawing on/off. With this Musubi demo, I'm just using keystrokes.
Of course, you'll need Mark Akita's Musubi package (don't know if that is cross-platform).
I appreciate any help I can get on this.
-- Musubi demo that can be used to benchmark the drawing of graphical primitives include std/search.e include std/sequence.e without warning include musubi/musubi.ew integer counter, maxX, maxY, gmode, stopped = 1 atom TIMER, timer integer timing, drawDots, drawLines, drawShapes, drawFilled timing = (1=2) drawDots = (1=2) drawLines = (1=2) drawShapes = (1=2) drawFilled = (1=2) procedure init() M_init() -- initialize Musubi M_set_screen_mode(windowed) -- windowed M_set_window_caption("Drawing Primitives Benchmark") -- * 640x480 graphics, mimic the euphoria mode 256 gmode=graphics_mode(256) -- * Manual updating is faster M_set_update_mode(manual) end procedure procedure fini() M_cleanup() end procedure procedure onTimer() atom dc, oTime sequence point, points integer numPoints maxX = 640 maxY = 480 while timing do counter += 1 if drawDots then points = {rand(maxX),rand(maxY)} pixel(10,points) end if if drawLines then points = {rand(maxX),rand(maxY),rand(maxX),rand(maxY)} draw_line(11, points ) end if if drawShapes then points = {} numPoints = 3 for t=1 to numPoints do points &= rand(maxX) & rand(maxY) end for polygon(12, 0, points ) end if if drawFilled then points = {} numPoints = 3 for t=1 to numPoints do points &= rand(maxX) & rand(maxY) end for polygon(11, 1, points ) end if if M_ticks() >= TIMER then -- M_render_text(1,sprintf("Draws per second: %d",{counter}),{30,20},224) TIMER = M_ticks() + 1000 counter = 0 end if M_update() end while end procedure sequence pressed = {} procedure ToggleDrawing(sequence keys) integer already_timing already_timing = timing if find_any("dD",keys) > 0 then -- start/stop the dots if find_any("dD",pressed) = 0 then drawDots = not drawDots pressed &= 'd' end if else pressed = remove_all( "d", pressed ) end if if find_any("lL",keys) > 0 then -- start/stop the dots if find_any("lL",pressed) = 0 then drawLines = not drawLines pressed &= 'l' -- letter el end if else pressed = remove_all( "l", pressed ) end if if find_any("eE",keys) > 0 then -- start/stop the dots if find_any("eE",pressed) = 0 then drawShapes = not drawShapes pressed &= 'e' end if else pressed = remove_all( "l", pressed ) end if if find_any("fF",keys) > 0 then -- start/stop the dots if find_any("fF",pressed) = 0 then drawFilled = not drawFilled pressed &= 'f' end if else pressed = remove_all( "f", pressed ) end if timing = drawDots or drawLines or drawShapes or drawFilled if not timing then if not stopped then -- M_render_text(1,"No timing",{30,20},224) puts(1,"\nSTOPPING") SDL_RemoveTimer( timer ) stopped = 1 end if elsif not already_timing then puts(1,"\nSTARTING") timer = SDL_AddTimer(1000, routine_id("onTimer"), 50) counter = 0 TIMER = M_ticks() stopped = 0 end if end procedure procedure do_test() sequence keys while find(SDLK_ESCAPE,keys) = 0 with entry do entry keys = M_read_keys() ToggleDrawing(keys) end while end procedure procedure main() init() do_test() fini() end procedure main()
2. Re: Need Help with Musubi Demo
- Posted by euphoric (admin) Oct 22, 2010
- 1253 views
Updated program now times drawing primitives for Musubi. HOWEVER, there must be something wrong because I get very low numbers compared to my wxEuphoria drawing primitives demo. It's a significant difference, and I would have thought SDL would be drawing faster since that's what it's meant to do...
I suspect it's the same problem I had when I originally developed the wxEuphoria drawing test... I was bottle-necking it somewhere. I originally tried using a Musubi/SDL timer, but couldn't get that to work. That's probably the problem. :(
Here's the wxEuphoria version for comparison.
-- Musubi demo that can be used to benchmark the drawing of graphical primitives include std/search.e include std/sequence.e without warning include musubi/musubi.ew as mus integer counter, maxX, maxY, gmode, stopped = 1 atom TIMER, timer integer timing, drawDots, drawLines, drawShapes, drawFilled, last_count timing = (1=2) drawDots = (1=2) drawLines = (1=2) drawShapes = (1=2) drawFilled = (1=2) last_count = 0 procedure init() M_init() -- initialize Musubi M_set_screen_mode(windowed) -- windowed M_set_window_caption("Drawing Primitives Benchmark") -- * 640x480 graphics, mimic the euphoria mode 256 gmode=graphics_mode(256) maxX = 640 maxY = 480 -- * Manual updating is faster M_set_update_mode(manual) TIMER = M_ticks() + 1000 end procedure procedure fini() M_cleanup() end procedure procedure do_draw() sequence points integer numPoints counter += 1 M_string(BLACK,{268,8},sprintf("Draws per second: %d",{last_count})) if drawDots then points = {rand(maxX),rand(maxY)} mus:pixel(10,points) end if if drawLines then points = {{rand(maxX),rand(maxY)},{rand(maxX),rand(maxY)}} draw_line(BLUE, points ) end if if drawShapes then points = {} numPoints = 3 for t=1 to numPoints do points &= {rand(maxX) & rand(maxY)} end for polygon(12, 0, points ) end if if drawFilled then points = {} numPoints = 3 for t=1 to numPoints do points &= {rand(maxX) & rand(maxY)} end for polygon(11, 1, points ) end if if M_ticks() >= TIMER then TIMER = M_ticks() + 1000 last_count = counter counter = 0 end if M_string(BRIGHT_WHITE,{268,8},sprintf("Draws per second: %d",{last_count})) M_update() end procedure sequence pressed = {} procedure ToggleDrawing(sequence keys) integer already_timing already_timing = timing if find('d',keys) > 0 then -- start/stop the dots drawDots = not drawDots if find('d',pressed) = 0 then pressed &= 'd' end if else pressed = remove_all( 'd', pressed ) end if if find_any("lL",keys) > 0 then -- start/stop the lines if find_any("lL",pressed) = 0 then drawLines = not drawLines pressed &= 'l' -- letter el end if else pressed = remove_all( 'l', pressed ) end if if find_any("eE",keys) > 0 then -- start/stop the empty triangles if find_any("eE",pressed) = 0 then drawShapes = not drawShapes pressed &= 'e' end if else pressed = remove_all( 'e', pressed ) end if if find_any("fF",keys) > 0 then -- start/stop the filled triangles if find_any("fF",pressed) = 0 then drawFilled = not drawFilled pressed &= 'f' end if else pressed = remove_all( 'f', pressed ) end if timing = drawDots or drawLines or drawShapes or drawFilled if timing then do_draw() else counter = 0 last_count = 0 TIMER = M_ticks() + 1000 end if end procedure procedure do_test() sequence keys while find(SDLK_ESCAPE,keys) = 0 with entry do entry keys = M_read_keys() ToggleDrawing(keys) end while end procedure procedure main() init() do_test() fini() end procedure main()