The Code Kingdom

viva la programmers!

Skip to content

File/Resource Load callbacks

What'd you like to see in Awesomium?

File/Resource Load callbacks

Postby CliffCawley » Wed Sep 23, 2009 10:28 am

Hi there!

I've been using your Awesomium library for about a day now and am loving it, great work!

To load my HTML pages I'm using the loadHTML function as I load the file from my Resource Manager. The reason for this, is that eventually I'm going to be packing all of my game data, which will mean that:

  • Awesomium won't be able to find any external assets that are referenced in the HTML data
OR
  • I'll have to leave the assets that Awesomium needs access to outside of the game data pack.

Ideally I'd like to be able to get Awesomium to load from my data pack as its much more optimal and cleaner. This way, any time Awesomium needs to load a resource/assets, i.e. a jpg or a .css, etc it will check to see if a callback has been registered and use that.

Perhaps something like:

In Awesomium:
Code: Select all
void SetIOHooks( FileOpen, FileRead, FileSize, FileClose );


Each of the arguments above would be function pointers that I could specify.

The function prototypes would look something like:

Code: Select all
// Here I would ask my resource manager to load the file with this filename.
// I would return to you an object of my liking, most likely a pointer to
// the resource I just loaded.
// Perhaps if I return NULL you can do the default, which is to
// load from disk (If I've turned another option on to allow that?)
void* FileOpen( const TCHAR* filename );


Code: Select all
// context would contain whatever I returned from FileOpen();
// I'd use it to return the file size of my resource.
int FileSize( void* context );


Code: Select all
// context would contain whatever I returned from FileOpen();
// buffer is a buffer you've constructed, using the size
// returned from FileSize();
// readSizeBytes would be the amount of bytes you want me
// to copy into buffer (usually FileSize results)
int FileRead( void* context, void* buffer, int readSizeBytes);


Code: Select all
// Essentially means you are finished with the File Resource
// and I can either close or leave around in my cache.
void FileClose( void* context );


Do you think this would be possible?

Cliff :-)

CliffCawley
 
Posts: 2
Joined: Wed Sep 23, 2009 10:06 am


Re: File/Resource Load callbacks

Postby Dotmister » Sat Oct 03, 2009 10:38 pm

Well you can include images in an HTML page using CSS.

http://jedisthlm.com/2008/12/03/urldataimagejpgbase64/

CSS I guess you've have to stick to <style type="text/css"></style>

same for JS.

Dotmister
 
Posts: 4
Joined: Sat May 16, 2009 9:18 pm

Re: File/Resource Load callbacks

Postby CliffCawley » Fri Jan 01, 2010 7:48 am

Dotmister wrote:Well you can include images in an HTML page using CSS.

http://jedisthlm.com/2008/12/03/urldataimagejpgbase64/

CSS I guess you've have to stick to <style type="text/css"></style>

same for JS.


That looks like it would work for a single image, however what if I use an instance of that image in several places within the CSS?

I.e. if I was using image regions/maps in my CSS so that I had a single image, but just used a different region, then I'd need to duplicate the image data wherever I referenced it within the CSS.

In order to support what you've suggested, I'll have to create a tool that packs all external files into the HTML at build time. I'll have to do some tests to see how well it performs.

I read up on the rfc ( http://tools.ietf.org/html/rfc2397 ) and its only recommended for small images. A note about large images states "The effect of using long "data" URLs in applications is currently unknown; some software packages may exhibit unreasonable behavior when confronted with data that exceeds its allocated buffer size.". I'll have to see how well this is handled and if there is an upper limit or not. Would be painful to start using this, only to find out later when the data is bigger that this becomes a problem and can't be used at all.

Cliff

CliffCawley
 
Posts: 2
Joined: Wed Sep 23, 2009 10:06 am


Return to Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron