I can give it a try, too.
I can give it a try, too.
my projects https://github.com/dpethes
Pm'ed Laggyluk, will PM imcold in a minute.
//edit: PM'ed imcold as well.
Last edited by Darkhog; 24-06-2013 at 04:08 PM. Reason: Because.
Can you send it to me also. I would also like to try help you out.
And besides since I'm closely folowing Factorio which also uses allegro game engine it would probably give me better idea of what it is posible to do with allegro and what not. This way I could probably give better suggestion to Factorio developers. And no Factorio is unfortunately not made with pascal.
You're getting errors due to changing the Chunk.Data in your keyboard handling code. The your keyboard handler is running in another context/thread (read the doc carefully: http://allegro-pas.sourceforge.net/d...install_int_ex). What does this mean? The data modified in the handler can change at any moment, independently of your main loop routine - if it changes when you're in your Draw routine, all hell's gonna break loose due to invalid pointers etc.
The solution is to just set a flag to signal that a world refresh is needed, and check it in the main loop (and there should be a lock around the flag, to do things 100% properly; but you can probably get away without it in this case).
main routine:Code:var update_chunks: boolean; procedure RegenerateChunk; begin update_chunks := false; Chunk.Data:=WorldGenerator.GenerateChunkData(chunkx,0,18); Inc(chunkx); al_clear_to_color(perlin,al_makecol(255,0,255)); for x:=0 to 100-1 do begin for y:=0 to 100-1 do begin al_putpixel(perlin,x,y,generate_pixel(x,y)); end; end; end; procedure update_keyboard(); begin Dec(lasted); dec(chunklasted); if (al_keyboard_needs_poll) then al_poll_keyboard; if ((al_key[AL_KEY_P]<>0) and (lasted<=0)) then begin pause:=not pause; lasted:=pausedelay; end; if not pause then begin if ((al_key[AL_KEY_SPACE]<>0) and (chunklasted<=0)) then begin update_chunks := true; chunklasted:=pausedelay; end; end; end;Code:repeat draw; if update_chunks then RegenerateChunk; until (al_key[AL_KEY_Q]<>0) or quit;
Last edited by imcold; 24-06-2013 at 07:40 PM.
my projects https://github.com/dpethes
imcold that fixed it, I think. Thank you!
Hi. I know I'm late but ...
Does it means that the code you send me by PM was fixed?
Anyway, the way you made the main loop and the keyboard handler aren't recommendable. You shouldn't manage the user input in an interruption (as documentation says it's called in "interruption time" not in "execution time"). I recommend you to read the timers tutorial and the sources of the Allegro.pas' demo game.
No signature provided yet.
Well, when I've tried it in mainloop it ran too fast. Plus I only need keyboard to be read 60 frames per second, all over this would be excessive.
Well, you can set the speed or your "logic loop", even use two counters. I don't see the problem.
No signature provided yet.
The rate of any spinning threads and/or polling you need to do should all be configurable. As a general rule of thumb you should avoid maxing a bunch of threads out as it leads to more unpredictable switches between threads by the OS Scheduler (IE what if you don't return to the audio thread quickly enough to keep the output buffer filled etc) You want things as fast as they'll go whilst retaining a consistent execution rate.
When the moon hits your eye like a big pizza pie - that's an extinction level impact event.
Bookmarks