9 #include <ppapi/cpp/instance.h>
10 #include <ppapi/cpp/module.h>
11 #include <ppapi/cpp/rect.h>
12 #include <ppapi/cpp/size.h>
13 #include <ppapi/cpp/file_system.h>
15 #include <SDL_video.h>
20 #include <nacl-mounts/base/KernelProxy.h>
21 #include <nacl-mounts/base/MainThreadRunner.h>
22 #include <nacl-mounts/http2/HTTP2Mount.h>
23 #include <nacl-mounts/pepper/PepperMount.h>
54 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
55 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
57 proxy_ = KernelProxy::KPInstance();
58 runner_ =
new MainThreadRunner(
this);
60 fprintf(stderr,
"Requesting an HTML5 local persistent filesystem.\n");
62 fs_ =
new pp::FileSystem(
this, PP_FILESYSTEMTYPE_LOCALPERSISTENT);
71 virtual void DidChangeView(
const pp::Rect& position,
const pp::Rect& clip) {
72 fprintf(stderr,
"did change view, new %dx%d, old %dx%d\n",
73 position.size().width(), position.size().height(),
77 width_ = position.size().width();
78 height_ = position.size().height();
86 int lval = SDL_Init(SDL_INIT_AUDIO);
95 SDL_NACL_PushEvent(event);
104 bool Init(
int argc,
const char* argn[],
const char* argv[]) {
122 fprintf(stderr,
"Initializing nacl-mounts.\n");
126 PepperMount* pepper_mount =
new PepperMount(runner_, fs_, 20 * 1024 * 1024);
128 pepper_mount->SetPathPrefix(
"/wesnoth-userdata");
130 proxy_->mkdir(
"/wesnoth-userdata", 0777);
131 int res = proxy_->mount(
"/wesnoth-userdata", pepper_mount);
134 proxy_->mkdir(
"/wesnoth-userdata/saves", 0777);
137 HTTP2Mount* http2_mount =
new HTTP2Mount(runner_,
"./usr/local/share/wesnoth");
138 http2_mount->SetLocalCache(fs_, 350*1024*1024,
"/wesnoth0",
true);
141 fprintf(stderr,
"Registering known files.\n");
146 http2_mount->AddDir(path);
153 http2_mount->AddFile(path, size);
161 http2_mount->SetInPack(path, pack_path, offset);
165 http2_mount->SetInMemory(
"/fonts/Andagii.ttf",
true);
166 http2_mount->SetInMemory(
"/fonts/DejaVuSans.ttf",
true);
167 http2_mount->SetInMemory(
"/fonts/wqy-zenhei.ttc",
true);
169 fprintf(stderr,
"Mounting the filesystem.\n");
171 proxy_->mkdir(
"/usr", 0777);
172 proxy_->mkdir(
"/usr/local", 0777);
173 proxy_->mkdir(
"/usr/local/share", 0777);
174 res = proxy_->mount(
"/usr/local/share/wesnoth", http2_mount);
176 fprintf(stderr,
"FS initialization success.\n");
178 fprintf(stderr,
"FS initialization failure.\n");
184 snprintf(res_s,
sizeof(res_s),
"%dx%d", width_, height_);
185 static char const * argv[] = {
"wesnoth",
"-r", res_s,
nullptr};
186 printf(
"starting game thread: %s\n", res_s);
187 wesnoth_main(
sizeof(argv) /
sizeof(*argv) - 1, (
char**)argv);
199 snprintf(buf,
sizeof(buf),
"%llu,%llu", (
unsigned long long)bytes,
200 (
unsigned long long)size);
202 instance_->PostMessage(message);
211 pp::CompletionCallback
cc_;
220 instance_->PostMessage(message);
224 fprintf(stderr,
"response: %s\n", response.c_str());
225 std::string::const_iterator ind = response.begin();
226 std::string::const_iterator
next = response.begin();
227 while (ind != response.end() && next != response.end()) {
228 if (*next ==
'\n' && ind != next) {
242 entries_->insert(last);
PluginInstance(PP_Instance instance)
int ReadDirectory(const std::string &path, std::set< std::string > *entries, const pp::CompletionCallback &cc)
void HandleProgress(std::string &path, int64_t bytes, int64_t size)
pp::CompletionCallback cc_
JSDirectoryReader directory_reader_
struct http_pack_info http_packs[]
JSDirectoryReader(pp::Instance *instance)
GLsizei const char ** path
static void * sdl_thread_static(void *param)
GLenum GLuint GLsizei const char * buf
void HandleResponse(const std::string &response)
int wesnoth_main(int argc, char **argv)
virtual void DidChangeView(const pp::Rect &position, const pp::Rect &clip)
ProgressHandler(pp::Instance *instance)
struct http_file_info http_files[]
pthread_t sdl_main_thread_
ProgressHandler progress_handler_
std::set< std::string > * entries_
GLsizei GLenum GLuint GLuint GLsizei char * message
MainThreadRunner * runner_
bool HandleInputEvent(const pp::InputEvent &event)
GLsizei const GLcharARB ** string
bool Init(int argc, const char *argn[], const char *argv[])
void HandleMessage(const pp::Var &message)
virtual pp::Instance * CreateInstance(PP_Instance instance)