Asynchronous (non-blocking) downloading using TCastleDownload class, and other HTTP communication features

Posted on

asynchronous_download screenshot

The new class TCastleDownload allows to download data over http and https asynchronously, without blocking the main thread of the application. This means that you can trivially continue rendering and game logic, while some resource are being downloaded over the network.

I made a demo in examples/network/asynchronous_download/. It demonstrates multiple simultaneous downloads, and underneath a glTF animation is playing with smooth 60 FPS without any breaks.

The class supports all CGE URLs, like file, http, https, castle-data and more.

Manual chapter about networking was updated to reflect all new possibilities.

Features:

  • The download can be observed (looking at Status, DownloadedBytes, TotalBytes).
  • When it’s finished, look at Contents (if success) or ErrorMessage (if error, that is Status = dsError).

  • We can read MIME type from server (can be used throughout our engine to designate file type).

  • It’s actually a full-featured HTTP(S) web request. You can specify HttpMethod, like GET, POST, PUT etc. For POST, you can provide form data as PostData. Arbitrary HTTP headers can be specified using AddHeader.

More examples:

This feature was done thanks to your support on Patreon. It was requested by Peardox. Many thanks! If you like what I’m doing, please support our engine.

Start the discussion at Castle Game Engine Forum