Need Help with Musubi Demo

new topic     » topic index » view thread      » older message » newer message

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() 
new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu