As a follow-up to the C/SDL issue,
while( !quit )
{
//Handle events on queue
while( SDL_PollEvent( &e ) != 0 )
{
//printf("%d,%d\n",e,&e);
//User requests quit
if( e.type == SDL_QUIT )
{
quit = true;
}
}
t1=SDL_GetTicks();
dt=t1-t0; t0=t1;
total+=dt;
if(total>timer) {
printf("update;%d,%d\n",timer,total);
total=0;
if(!(PL_cons_functor(goal, PL_new_functor(PL_new_atom("update"), 2), a1,a2)&&PL_call(goal,m))) {
printf("error: 'update' predicate not found\n");
PL_raise_exception(exception);
PL_fail;
}
a1=a2;
a2=PL_new_term_ref();
}
SDL_Delay(1);
}
The full code is on a repository: GitHub - cosmos-lang/sdl_pl: SDL bindings for Prolog.
update([Y,I],[Y,I2]) :- ...
setRGBA(255,255,255,255),clear,
I2 is I+1,setRGBA(0,0,0,255),drawImage(Y,I,120),
rect(I,1,50,50),refresh.
The idea is that an update/2 predicate continually passes the state around. That would be the SDL main loop. This actually works well and moves a rectangle. However, drawImage sometimes does and sometimes doesn’t display the image. Is it possible to make something like this?