📄 gameswf_movie.cpp
字号:
if ((fd = open(filespec.c_str(), O_RDONLY)) > 0) { unsigned char buf[5]; memset(buf, 0, 5); if (read(fd, buf, 4)) { close(fd); // we don't need this anymore // This is the magic number for any JPEG format file if ((buf[0] == 0xff) && (buf[1] == 0xd8) && (buf[2] == 0xff)) { //log_msg("File is a JPEG!\n"); } else { //log_error("File is not a JPEG!\n"); unlink(filespec.c_str()); fn.result->set(false); return; } } else { log_error("Can't read image header!\n"); unlink(filespec.c_str()); fn.result->set(false); return; } } else { log_error("Can't open image!\n"); unlink(filespec.c_str()); fn.result->set(false); return; } bitmap_info* bi = NULL; image::rgb* im = image::read_jpeg(filespec.c_str()); if (im != NULL) { bi = render::create_bitmap_info_rgb(im); delete im; } else { log_error("Can't read jpeg: %s\n", filespec.c_str()); } //bitmap_character* ch = new bitmap_character(bi); movie *mov = target->to_movie(); //movie_definition *def = mov->get_movie_definition(); //movie_definition_sub *m = (movie_definition_sub *)mov; //target->add_bitmap_info(bi); character* tar = (character*)mov; const char* name = tar->get_name(); Uint16 id = tar->get_id(); //log_msg("Target name is: %s, ID: %d\n", name, id); // FIXME: none of this works yet //movie_definition *md = create_library_movie(filespec.c_str()); // add image to movie, under character id. //m->add_bitmap_character(666, ch);// #if 1 tu_string swfm = filespec.utf8_substring(0, filespec.length() - 3); swfm += "swf"; movie_definition_sub *ms = create_movie_sub(swfm.c_str()); // The file may not exist. if (ms) { movie_interface* extern_movie = create_library_movie_inst_sub(ms); character * newchar = ms->create_character_instance(tar->get_parent(), id); } //save_extern_movie(extern_movie); //movie* new_movie = static_cast<movie*>(extern_movie)->get_root_movie(); // #else// movie_definition_sub *ms;// ms->add_bitmap_info(bi);// #endif //movie* m = mov->get_root_movie(); //set_current_root(extern_movie); //movie* m = static_cast<movie*>(extern_movie)->get_root_movie(); mov->on_event(event_id::LOAD); //add_display_object(); //Uint16 depth = tar->get_depth(); bool use_cxform = false; //cxform color_transform = tar->get_cxform(); bool use_matrix = false; matrix mat = tar->get_matrix(); //float ratio = tar->get_ratio(); //Uint16 clip_depth = tar->get_clip_depth(); array<swf_event*> dummy_event_handlers; movie* parent = tar->get_parent(); character *newch = new character(parent, id); #if 0 parent->clone_display_object(name, "album_image", depth); parent->add_display_object((Uint16)id, name, dummy_event_handlers, tar->get_depth(), true, tar->get_cxform(), tar->get_matrix(), tar->get_ratio(), tar->get_clip_depth());#endif parent->replace_display_object(newch, name, tar->get_depth(), use_cxform, tar->get_cxform(), use_matrix, tar->get_matrix(), tar->get_ratio(), tar->get_clip_depth()); } struct mcl *mcl_data = ptr->mov_obj.getProgress(target); // the callback since we're done loading the file // FIXME: these both probably shouldn't be set to the same value mcl_data->bytes_loaded = stats.st_size; mcl_data->bytes_total = stats.st_size; fn.env->set_member("target_mc", target); //env->push(as_value(target)); //moviecliploader_onload_complete(result, this_ptr, env, 0, 0); moviecliploader_onload_complete(fn); //env->pop(); fn.result->set(true); //unlink(filespec.c_str()); //xmlNanoHTTPCleanup();#endif // HAVE_LIBXML}voidmoviecliploader_unloadclip(const fn_call& fn){ const tu_string filespec = fn.arg(0).to_string(); log_msg("%s: FIXME: Load Movie Clip: %s\n", __FUNCTION__, filespec.c_str()); }voidmoviecliploader_new(const fn_call& fn){ log_msg("%s: args=%d\n", __FUNCTION__, fn.nargs); const tu_string filespec = fn.arg(0).to_string(); as_object* mov_obj = new moviecliploader_as_object; //log_msg("\tCreated New MovieClipLoader object at %p\n", mov_obj); mov_obj->set_member("loadClip", &moviecliploader_loadclip); mov_obj->set_member("unloadClip", &moviecliploader_unloadclip); mov_obj->set_member("getProgress", &moviecliploader_getprogress);#if 0 // Load the default event handlers. These should really never // be called directly, as to be useful they are redefined // within the SWF script. These get called if there is a problem // Setup the event handlers mov_obj->set_event_handler(event_id::LOAD_INIT, (as_c_function_ptr)&event_test); mov_obj->set_event_handler(event_id::LOAD_START, (as_c_function_ptr)&event_test); mov_obj->set_event_handler(event_id::LOAD_PROGRESS, (as_c_function_ptr)&event_test); mov_obj->set_event_handler(event_id::LOAD_ERROR, (as_c_function_ptr)&event_test);#endif fn.result->set_as_object_interface(mov_obj);}voidmoviecliploader_onload_init(const fn_call& fn){ log_msg("%s: FIXME: Default event handler, you shouldn't be here!\n", __FUNCTION__);}// Invoked when a call to MovieClipLoader.loadClip() has successfully// begun to download a file.voidmoviecliploader_onload_start(const fn_call& fn){ log_msg("%s: FIXME: Default event handler, you shouldn't be here!\n", __FUNCTION__);}// Invoked every time the loading content is written to disk during// the loading process.voidmoviecliploader_getprogress(const fn_call& fn){ //log_msg("%s: nargs = %d\n", __FUNCTION__, nargs); moviecliploader_as_object* ptr = (moviecliploader_as_object*) (as_object*) fn.this_ptr; assert(ptr); as_object *target = (as_object*) fn.arg(0).to_object(); struct mcl *mcl_data = ptr->mov_obj.getProgress(target); mcl_as_object *mcl_obj = (mcl_as_object *)new mcl_as_object; mcl_obj->set_member("bytesLoaded", mcl_data->bytes_loaded); mcl_obj->set_member("bytesTotal", mcl_data->bytes_total); fn.result->set_as_object_interface(mcl_obj);}// Invoked when a file loaded with MovieClipLoader.loadClip() has// completely downloaded.voidmoviecliploader_onload_complete(const fn_call& fn){ as_value val, method; //log_msg("%s: FIXME: nargs = %d\n", __FUNCTION__, nargs); //moviecliploader_as_object* ptr = (moviecliploader_as_object*) (as_object*) this_ptr; tu_string url = fn.arg(0).to_string(); //as_object *target = (as_object *)env->bottom(first_arg-1).to_object(); //log_msg("load clip: %s, target is: %p\n", url.c_str(), target); //log_msg("%s: FIXME: Default event handler, you shouldn't be here!\n", __FUNCTION__); if (fn.this_ptr->get_member("onLoadComplete", &method)) { //log_msg("FIXME: Found onLoadComplete!\n"); as_c_function_ptr func = method.to_c_function(); fn.env->set_variable("success", true, 0); if (func) { // It's a C function. Call it. //log_msg("Calling C function for onLoadComplete\n"); (*func)(fn_call(&val, fn.this_ptr, fn.env, 0, 0)); } else if (as_as_function* as_func = method.to_as_function()) { // It's an ActionScript function. Call it. //log_msg("Calling ActionScript function for onLoadComplete\n"); (*as_func)(fn_call(&val, fn.this_ptr, fn.env, 0, 0)); } else { log_error("error in call_method(): method is not a function\n"); } } else { log_error("Couldn't find onLoadComplete!\n"); }}// Invoked when a file loaded with MovieClipLoader.loadClip() has failed to load.voidmoviecliploader_onload_error(const fn_call& fn){ //log_msg("%s: FIXME: Default event handler, you shouldn't be here!\n", __FUNCTION__); as_value val, method; log_msg("%s: FIXME: nargs = %d\n", __FUNCTION__, fn.nargs); //moviecliploader_as_object* ptr = (moviecliploader_as_object*) (as_object*) this_ptr; tu_string url = fn.arg(0).to_string(); as_object *target = (as_object*) fn.arg(1).to_object(); log_msg("load clip: %s, target is: %p\n", url.c_str(), target); //log_msg("%s: FIXME: Default event handler, you shouldn't be here!\n", __FUNCTION__); if (fn.this_ptr->get_member("onLoadError", &method)) { //log_msg("FIXME: Found onLoadError!\n"); as_c_function_ptr func = method.to_c_function(); fn.env->set_variable("success", true, 0); if (func) { // It's a C function. Call it. log_msg("Calling C function for onLoadError\n"); (*func)(fn_call(&val, fn.this_ptr, fn.env, 0, 0)); } else if (as_as_function* as_func = method.to_as_function()) { // It's an ActionScript function. Call it. log_msg("Calling ActionScript function for onLoadError\n"); (*as_func)(fn_call(&val, fn.this_ptr, fn.env, 0, 0)); } else { log_error("error in call_method(): method is not a function\n"); } } else { log_error("Couldn't find onLoadError!\n"); }}// This is the default event handler. To wind up here is an error.voidmoviecliploader_default(const fn_call& fn){ log_msg("%s: FIXME: Default event handler, you shouldn't be here!\n", __FUNCTION__);}} // end of gameswf namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -