Remote resource access over HTTP

96 views
Skip to first unread message

iarwain

unread,
Jun 15, 2014, 4:28:34 AM6/15/14
to orx...@googlegroups.com
Hi all,

Here's a small source file that adds a custom resource type enabling resource retrieval from a web server. I've tested it on windows/linux/osx but haven't tried iOS nor Android yet.

The main use for it is during debug as it allows one to run a game on a remote device (like a phone or a table for example) while having the resource on a local computer. As hotloading is supported, one can easily modify resource locally (sound, config, textures, ...) and see the effect directly on the device in real time.

It can even be used over internet for cooperative work, though it won't be as responsive due to latency.

Lastly, it can also be used in production to retrieve remote resources like announcements, custom xmas skins or whatever you want. =)

The code adds the client side to your game, it's as easy to use as the custom ZIP archive support (https://groups.google.com/forum/#!topic/orx-dev/gp-wHv1OmVk).

In your "game.cpp" where your init function lies:

#include "orxRemote.c"

And then simply call it first thing from your game's init function so that the support for web/remote resource will be enabled before any resource is actually loaded (beside the main config file that gets loaded right at the beginning):

orxSTATUS orxFASTCALL GameInit()
{
  orxSTATUS eResult;

  eResult = orxRemote_Init();

  // Inits everything else below
}

In your main config file you can then add your server (you can actually have more than one) to the resource paths, so that they get searched first when a resource is requested. If not found, it'll then look into your dev folders for the original resources. If the host:port is omitted, localhost:8080 will be used.

Something like this:

[Resource]
Config = http://localhost:8080/config # data/config
Texture = texture # data/texture
Sound = http://127.0.0.1:8080/sound # data/sound

Now on the server side, use any web server you want. No need to setup an Apache or anything, one-line web servers from node.js, python or the like work just fine. See this SO thread for some examples: http://stackoverflow.com/questions/12905426/faster-alternative-to-pythons-simplehttpserver

In this example, go to your exe folder, and run one like this:

twistd -no web --path ./data

If you look at the web server log, you'll see all orx's requests going through: GET requests to retrieve actual content and HEAD requests to find if a file exist and to check for modification.

If you have any question/comments, just let me know! :)

Cheers,

Rom

PS: I might merge orxArchive.c with orxRemote.c in the future, for more convenience.
orxRemote.c

Philippe Simons

unread,
Jun 17, 2014, 3:16:29 AM6/17/14
to orx...@googlegroups.com
nice


--
You received this message because you are subscribed to the Google Groups "orx-dev" group.
To post to this group, send email to orx...@googlegroups.com.
Visit this group at http://groups.google.com/group/orx-dev.

Reply all
Reply to author
Forward
0 new messages