bool gl_load_shader(const char* shader_path, GLuint* shader_id, GLenum shader_type) { //Read in shader source FILE* file = fopen(shader_path, "r"); if(file == NULL) { return false; message_log("Error loading file-", shader_path); } fseek(file, 0, SEEK_END); int length = ftell(file); fseek(file, 0, SEEK_SET); GLchar* shader_source = (GLchar*)walloc(sizeof(GLchar)*length+1); fread(shader_source, sizeof(GLchar), length, file); shader_source[length] = (GLchar)0; fclose(file); //Compile shader *shader_id = glCreateShader(shader_type); glShaderSource(*shader_id, 1, (const GLchar**)&shader_source, NULL); glCompileShader(*shader_id); GLint compiled = GL_FALSE; glGetShaderiv(*shader_id, GL_COMPILE_STATUS, &compiled); if(compiled != GL_TRUE ) { message_log("Open GL-", "error compiling shader"); message_log("Source:", shader_source); GLchar buffer[2048]; glGetShaderInfoLog(*shader_id, 2048, NULL, buffer); message_log("Open GL-", buffer); return false; } wfree(shader_source); return true; }
static void log_callback(bool error, const char* message) // Error callback for handling gameswf messages. { if (error) { // Log, and also print to stderr. message_log(message); fputs(message, stderr); } else { message_log(message); } }
int decoding(char* in, int inlen, char** out, int* outlen) { int ret; char* aes; int aes_len; char* msg; int msg_len; aes_len = inlen; /* base64 decode-length always smaller than encode-length */ aes = get_pre_aes_buffer(aes_len); if (aes == NULL) { message_log(LOG_ERR, 0, "get aes buffer for Base64Decode failed"); return -1; } ret = Base64Decode(in, inlen, aes, &aes_len); if (ret < 0) { message_log(LOG_ERR, 0, "Base64Decode failed ret %d", ret); return -2; } msg_len = aes_len; msg = get_pre_msg_buffer(msg_len); if (msg == NULL) { message_log(LOG_ERR, 0, "get msg buffer for aesDecrypt failed"); return -3; } ret = aesDecrypt(aes, aes_len, msg, &msg_len); if (ret < 0) { message_log(LOG_ERR, 0, "aesDecrypt failed ret %d", ret); return -4; } *out = msg; *outlen = msg_len; return 0; }
void SWFMovie::load(const char *name) { gameswf::get_movie_info(name, &movie_version, &movie_width, &movie_height, &movie_fps, NULL, &s_total_tags); if (movie_version == 0) { error_log("error: %s についての情報が取得できません", name); return; } else if (movie_version > 6) { message_log("warning: %s は対応していないバージョン %d のファイルです", movie_version); } md = gameswf::create_movie(name); if (md != NULL) { m = md->create_instance(); // 開始する m->get_root_movie()->execute_frame_tags(0); } lastFrame = -1; }
static void _router_process_route(component_t comp, nad_t nad) { int atype, ato, afrom; unsigned int dest; struct jid_st sto, sfrom; jid_static_buf sto_buf, sfrom_buf; jid_t to = NULL, from = NULL; routes_t targets; component_t target; union xhashv xhv; /* init static jid */ jid_static(&sto,&sto_buf); jid_static(&sfrom,&sfrom_buf); if(nad_find_attr(nad, 0, -1, "error", NULL) >= 0) { log_debug(ZONE, "dropping error packet, trying to avoid loops"); nad_free(nad); return; } atype = nad_find_attr(nad, 0, -1, "type", NULL); ato = nad_find_attr(nad, 0, -1, "to", NULL); afrom = nad_find_attr(nad, 0, -1, "from", NULL); if(ato >= 0) to = jid_reset(&sto, NAD_AVAL(nad, ato), NAD_AVAL_L(nad, ato)); if(afrom >= 0) from = jid_reset(&sfrom, NAD_AVAL(nad, afrom), NAD_AVAL_L(nad, afrom)); /* unicast */ if(atype < 0) { if(to == NULL || from == NULL) { log_debug(ZONE, "unicast route with missing or invalid to or from, bouncing"); nad_set_attr(nad, 0, -1, "error", "400", 3); _router_comp_write(comp, nad); return; } log_debug(ZONE, "unicast route from %s to %s", from->domain, to->domain); /* check the from */ if(xhash_get(comp->routes, from->domain) == NULL) { log_write(comp->r->log, LOG_NOTICE, "[%s, port=%d] tried to send a packet from '%s', but that name is not bound to this component", comp->ip, comp->port, from->domain); nad_set_attr(nad, 0, -1, "error", "401", 3); _router_comp_write(comp, nad); return; } /* filter it */ if(comp->r->filter != NULL) { int ret = filter_packet(comp->r, nad); if(ret == stanza_err_REDIRECT) { ato = nad_find_attr(nad, 0, -1, "to", NULL); if(ato >= 0) to = jid_reset(&sto, NAD_AVAL(nad, ato), NAD_AVAL_L(nad, ato)); } else if(ret > 0) { log_debug(ZONE, "packet filtered out: %s (%s)", _stanza_errors[ret - stanza_err_BAD_REQUEST].name, _stanza_errors[ret - stanza_err_BAD_REQUEST].code); nad_set_attr(nad, 0, -1, "error", _stanza_errors[ret - stanza_err_BAD_REQUEST].code, 3); _router_comp_write(comp, nad); return; } } /* find a target */ targets = xhash_get(comp->r->routes, to->domain); if(targets == NULL) { if(comp->r->default_route != NULL && strcmp(from->domain, comp->r->default_route) == 0) { log_debug(ZONE, "%s is unbound, bouncing", from->domain); nad_set_attr(nad, 0, -1, "error", "404", 3); _router_comp_write(comp, nad); return; } targets = xhash_get(comp->r->routes, comp->r->default_route); } if(targets == NULL) { log_debug(ZONE, "%s is unbound, and no default route, bouncing", to->domain); nad_set_attr(nad, 0, -1, "error", "404", 3); _router_comp_write(comp, nad); return; } /* copy to any log sinks */ if(xhash_count(comp->r->log_sinks) > 0) xhash_walk(comp->r->log_sinks, _router_route_log_sink, (void *) nad); /* get route candidate */ if(targets->ncomp == 1) { dest = 0; } else { switch(targets->rtype) { case route_MULTI_TO: ato = nad_find_attr(nad, 1, -1, "to", NULL); if(ato >= 0) to = jid_reset(&sto, NAD_AVAL(nad, ato), NAD_AVAL_L(nad, ato)); else { ato = nad_find_attr(nad, 1, -1, "target", NULL); if(ato >= 0) to = jid_reset(&sto, NAD_AVAL(nad, ato), NAD_AVAL_L(nad, ato)); else { const char *out; int len; nad_print(nad, 0, &out, &len); log_write(comp->r->log, LOG_ERR, "Cannot get destination for multiple route: %.*s", len, out); } } break; case route_MULTI_FROM: ato = nad_find_attr(nad, 1, -1, "from", NULL); if(ato >= 0) to = jid_reset(&sto, NAD_AVAL(nad, ato), NAD_AVAL_L(nad, ato)); else { const char *out; int len; nad_print(nad, 0, &out, &len); log_write(comp->r->log, LOG_ERR, "Cannot get source for multiple route: %.*s", len, out); } break; default: log_write(comp->r->log, LOG_ERR, "Multiple components bound to single component route '%s'", targets->name); /* simulate no 'to' info in this case */ } if(to->node == NULL || strlen(to->node) == 0) { /* no node in destination JID - going random */ dest = rand(); log_debug(ZONE, "randomized to %u %% %d = %d", dest, targets->ncomp, dest % targets->ncomp); } else { /* use JID hash */ unsigned char hashval[20]; unsigned int *val; int i; shahash_raw(jid_user(to), hashval); val = (unsigned int *) hashval; dest = *val; for(i=1; i < 20 / (sizeof(unsigned int)/sizeof(unsigned char)); i++, val++) { dest ^= *val; } dest >>= 2; log_debug(ZONE, "JID %s hashed to %u %% %d = %d", jid_user(to), dest, targets->ncomp, dest % targets->ncomp); /* jid_user() calls jid_expand() which may allocate some memory in _user and _full */ if (to->_user != NULL ) free(to->_user); if (to->_full != NULL ) free(to->_full); } dest = dest % targets->ncomp; } target = targets->comp[dest]; /* push it out */ log_debug(ZONE, "writing route for '%s'*%u to %s, port %d", to->domain, dest+1, target->ip, target->port); /* if logging enabled, log messages that match our criteria */ if (comp->r->message_logging_enabled && comp->r->message_logging_file != NULL) { int attr_msg_to; int attr_msg_from; int attr_route_to; int attr_route_from; jid_t jid_msg_from = NULL; jid_t jid_msg_to = NULL; jid_t jid_route_from = NULL; jid_t jid_route_to = NULL; if ((NAD_ENAME_L(nad, 1) == 7 && strncmp("message", NAD_ENAME(nad, 1), 7) == 0) && // has a "message" element ((attr_route_from = nad_find_attr(nad, 0, -1, "from", NULL)) >= 0) && ((attr_route_to = nad_find_attr(nad, 0, -1, "to", NULL)) >= 0) && ((strncmp(NAD_AVAL(nad, attr_route_to), "c2s", 3)) != 0) && // ignore messages to "c2s" or we'd have dups ((jid_route_from = jid_new(NAD_AVAL(nad, attr_route_from), NAD_AVAL_L(nad, attr_route_from))) != NULL) && // has valid JID source in route ((jid_route_to = jid_new(NAD_AVAL(nad, attr_route_to), NAD_AVAL_L(nad, attr_route_to))) != NULL) && // has valid JID destination in route ((attr_msg_from = nad_find_attr(nad, 1, -1, "from", NULL)) >= 0) && ((attr_msg_to = nad_find_attr(nad, 1, -1, "to", NULL)) >= 0) && ((jid_msg_from = jid_new(NAD_AVAL(nad, attr_msg_from), NAD_AVAL_L(nad, attr_msg_from))) != NULL) && // has valid JID source in message ((jid_msg_to = jid_new(NAD_AVAL(nad, attr_msg_to), NAD_AVAL_L(nad, attr_msg_to))) != NULL)) // has valid JID dest in message { message_log(nad, comp->r, jid_full(jid_msg_from), jid_full(jid_msg_to)); } if (jid_msg_from != NULL) jid_free(jid_msg_from); if (jid_msg_to != NULL) jid_free(jid_msg_to); if (jid_route_from != NULL) jid_free(jid_route_from); if (jid_route_to != NULL) jid_free(jid_route_to); } _router_comp_write(target, nad); return; } /* broadcast */ if(NAD_AVAL_L(nad, atype) == 9 && strncmp("broadcast", NAD_AVAL(nad, atype), 9) == 0) { if(from == NULL) { log_debug(ZONE, "broadcast route with missing or invalid from, bouncing"); nad_set_attr(nad, 0, -1, "error", "400", 3); _router_comp_write(comp, nad); return; } log_debug(ZONE, "broadcast route from %s", from->domain); /* check the from */ if(xhash_get(comp->routes, from->domain) == NULL) { log_write(comp->r->log, LOG_NOTICE, "[%s, port=%d] tried to send a packet from '%s', but that name is not bound to this component", comp->ip, comp->port, from->domain); nad_set_attr(nad, 0, -1, "error", "401", 3); _router_comp_write(comp, nad); return; } /* loop the components and distribute */ if(xhash_iter_first(comp->r->components)) do { xhv.comp_val = ⌖ xhash_iter_get(comp->r->components, NULL, NULL, xhv.val); if(target != comp) { log_debug(ZONE, "writing broadcast to %s, port %d", target->ip, target->port); _router_comp_write(target, nad_copy(nad)); } } while(xhash_iter_next(comp->r->components)); nad_free(nad); return; } log_debug(ZONE, "unknown route type '%.*s', dropping", NAD_AVAL_L(nad, atype), NAD_AVAL(nad, atype)); nad_free(nad); }
int main(int argc, char *argv[]) { tu_memdebug::open(); { // for testing memory leaks assert(tu_types_validate()); const char* infile = NULL; float exit_timeout = 0; bool do_render = true; bool do_sound = true; bool do_loop = true; bool sdl_abort = true; bool sdl_cursor = true; float tex_lod_bias; bool force_realtime_framerate = false; #ifdef _WIN32 WSADATA wsaData; int iResult = WSAStartup( MAKEWORD(2,2), &wsaData ); if ( iResult != NO_ERROR ) printf("Error at WSAStartup()\n"); #endif // -1.0 tends to look good. tex_lod_bias = -1.2f; tu_string flash_vars; int width = 0; int height = 0; gameswf::gc_ptr<gameswf::player> player = new gameswf::player(); for (int arg = 1; arg < argc; arg++) { if (argv[arg][0] == '-') { // Looks like an option. if (argv[arg][1] == 'h') { // Help. print_usage(); exit(1); } if (argv[arg][1] == 'u') { arg++; if (arg < argc) { flash_vars = argv[arg]; } else { fprintf(stderr, "-u arg must be followed string like myvar=x&myvar2=y and so on\n"); print_usage(); exit(1); } } else if (argv[arg][1] == 'w') { arg++; if (arg < argc) { width = atoi(argv[arg]); const char* x = strstr(argv[arg], "x"); if (x) { height = atoi(x + 1); } } if (width <=0 || height <= 0) { fprintf(stderr, "-w arg must be followed by the window size\n"); print_usage(); exit(1); } } else if (argv[arg][1] == 'c') { sdl_abort = false; } else if (argv[arg][1] == 'f') { force_realtime_framerate = true; } else if (argv[arg][1] == 'k') { sdl_cursor = false; } else if (argv[arg][1] == 'a') { // Set antialiasing on or off. arg++; if (arg < argc) { s_aa_level = atoi(argv[arg]); s_antialiased = s_aa_level > 0 ? true : false; } else { fprintf(stderr, "-a arg must be followed by the antialiasing level\n"); print_usage(); exit(1); } } else if (argv[arg][1] == 'b') { // Set default bit depth. arg++; if (arg < argc) { s_bit_depth = atoi(argv[arg]); if (s_bit_depth != 16 && s_bit_depth != 24 && s_bit_depth != 32) { fprintf(stderr, "Command-line supplied bit depth %d, but it must be 16, 24 or 32", s_bit_depth); print_usage(); exit(1); } } else { fprintf(stderr, "-b arg must be followed by 16 or 32 to set bit depth\n"); print_usage(); exit(1); } } else if (argv[arg][1] == 'd') { // Set a delay arg++; if (arg < argc) { s_delay = atoi(argv[arg]); } else { fprintf(stderr, "-d arg must be followed by number of milli-seconds to del in the main loop\n"); print_usage(); exit(1); } } else if (argv[arg][1] == 'p') { // Enable frame-rate/performance logging. s_measure_performance = true; } else if (argv[arg][1] == '1') { // Play once; don't loop. do_loop = false; } else if (argv[arg][1] == 'r') { // Set rendering on/off. arg++; if (arg < argc) { const int render_arg = atoi(argv[arg]); switch (render_arg) { case 0: // Disable both do_render = false; do_sound = false; break; case 1: // Enable both do_render = true; do_sound = true; break; case 2: // Disable just sound do_render = true; do_sound = false; break; default: fprintf(stderr, "-r must be followed by 0, 1 or 2 (%d is invalid)\n", render_arg); print_usage(); exit(1); break; } } else { fprintf(stderr, "-r must be followed by 0 an argument to disable/enable rendering\n"); print_usage(); exit(1); } } else if (argv[arg][1] == 't') { // Set timeout. arg++; if (arg < argc) { exit_timeout = (float) atof(argv[arg]); } else { fprintf(stderr, "-t must be followed by an exit timeout, in seconds\n"); print_usage(); exit(1); } } else if (argv[arg][1] == 'v') { // Be verbose; i.e. print log messages to stdout. if (argv[arg][2] == 'a') { // Enable spew re: action. player->verbose_action(true); } else if (argv[arg][2] == 'p') { // Enable parse spew. player->verbose_parse(true); } // ... } else if (argv[arg][1] == 'm') { if (argv[arg][2] == 'l') { arg++; tex_lod_bias = (float) atof(argv[arg]); //printf("Texture LOD Bais is no %f\n", tex_lod_bias); } else { fprintf(stderr, "unknown variant of -m arg\n"); print_usage(); exit(1); } } else if (argv[arg][1] == 'n') { s_allow_http = true; } else if (argv[arg][1] == 'i') { player->set_separate_thread(false); player->set_log_bitmap_info(true); } } else { infile = argv[arg]; } } if (infile == NULL) { printf("no input file\n"); print_usage(); exit(1); } // if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); //Use OpenGL 2.1 SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 ); // Set the video mode. // if (SDL_SetVideoMode(width, height, s_bit_depth, SDL_OPENGL | SDL_RESIZABLE) == 0) //if (SDL_SetVideoMode(width, height, s_bit_depth, SDL_OPENGL) == 0) window = SDL_CreateWindow("TestSWF", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN); if(!window) { fprintf(stderr, "SDL_CreateWindow() failed. %s", SDL_GetError()); exit(1); } gContext = SDL_GL_CreateContext(window); if( gContext == NULL ) { fprintf(stderr, "OpenGL context could not be created! SDL Error: %s\n", SDL_GetError() ); exit(1); } //Use Vsync if( SDL_GL_SetSwapInterval( 1 ) < 0 ) { fprintf(stderr, "Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError() ); } SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); if(!renderer) { fprintf(stderr, "SDL_CreateRenderer() failed. %s", SDL_GetError()); exit(1); } //SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); //SDL_RenderClear(renderer); //SDL_RenderPresent(renderer); // player->set_force_realtime_framerate(force_realtime_framerate); // use this for multifile games // workdir is used when LoadMovie("myfile.swf", _root) is called { tu_string workdir; // Find last slash or backslash. const char* ptr = infile + strlen(infile); for (; ptr >= infile && *ptr != '/' && *ptr != '\\'; ptr--) {} // Use everything up to last slash as the "workdir". int len = ptr - infile + 1; if (len > 0) { tu_string workdir(infile, len); player->set_workdir(workdir.c_str()); } } gameswf::register_file_opener_callback(file_opener); gameswf::register_fscommand_callback(fs_callback); if (gameswf::get_verbose_parse()) { gameswf::register_log_callback(log_callback); } gameswf::sound_handler* sound = NULL; gameswf::render_handler* render = NULL; if (do_render) { if (do_sound) { #ifdef TU_USE_SDL sound = gameswf::create_sound_handler_sdl(); #endif #ifdef TU_USE_OPENAL sound = gameswf::create_sound_handler_openal(); #endif gameswf::set_sound_handler(sound); } #ifdef TU_USE_SDL render = gameswf::create_render_handler_ogl(); gameswf::set_render_handler(render); #endif #ifdef TU_USE_OGLES render = gameswf::create_render_handler_ogles(); gameswf::set_render_handler(render); #endif #if TU_CONFIG_LINK_TO_FREETYPE == 1 gameswf::set_glyph_provider(gameswf::create_glyph_provider_freetype()); #else gameswf::set_glyph_provider(gameswf::create_glyph_provider_tu()); #endif } // // set_proxy("192.168.1.201", 8080); // // gameswf::set_use_cache_files(true); player->set_flash_vars(flash_vars); { gameswf::gc_ptr<gameswf::root> m = player->load_file(infile); if (m == NULL) { exit(1); } if (width == 0 || height == 0) { width = m->get_movie_width(); height = m->get_movie_height(); } float scale_x = (float) width / m->get_movie_width(); float scale_y = (float) height / m->get_movie_height(); float movie_fps = m->get_movie_fps(); if (do_render) { // Initialize the SDL subsystems we're using. Linux // and Darwin use Pthreads for SDL threads, Win32 // doesn't. Otherwise the SDL event loop just polls. //if (sdl_abort) //{ // // Other flags are SDL_INIT_JOYSTICK | SDL_INIT_CDROM // //#ifdef _WIN32 // //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) // //#else // //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_EVENTTHREAD )) // if (SDL_Init(SDL_INIT_EVERYTHING)) // //#endif // { // fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); // exit(1); // } //} //else //{ // fprintf(stderr, "warning: SDL won't trap core dumps \n"); // //#ifdef _WIN32 // //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE | SDL_INIT_EVENTTHREAD)) // //#else // //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE)) // //#endif // if (SDL_Init(SDL_INIT_EVERYTHING)) // { // fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); // exit(1); // } //} //atexit(SDL_Quit); //SDL_EnableKeyRepeat(250, 33); //event.key.repeat SDL_ShowCursor(sdl_cursor ? SDL_ENABLE : SDL_DISABLE); switch (s_bit_depth) { case 16: // 16-bit color, surface creation is likely to succeed. SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 15); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 5); break; case 24: // 24-bit color // SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); // SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); // SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); // SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); // SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); break; case 32: // 32-bit color etc, for getting dest alpha, // for MULTIPASS_ANTIALIASING (see gameswf_render_handler_ogl.cpp). SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); break; default: assert(0); } // try to enable FSAA if (s_aa_level > 1) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, s_aa_level); } // Change the LOD BIAS values to tweak blurriness. if (tex_lod_bias != 0.0f) { #ifdef FIX_I810_LOD_BIAS // If 2D textures weren't previously enabled, enable // them now and force the driver to notice the update, // then disable them again. if (!glIsEnabled(GL_TEXTURE_2D)) { // Clearing a mask of zero *should* have no // side effects, but coupled with enbling // GL_TEXTURE_2D it works around a segmentation // fault in the driver for the Intel 810 chip. glEnable(GL_TEXTURE_2D); glClear(0); glDisable(GL_TEXTURE_2D); } #endif // FIX_I810_LOD_BIAS glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, tex_lod_bias); } render->open(); render->set_antialiased(s_antialiased); // Turn on alpha blending. glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Turn on line smoothing. Antialiased lines can be used to // smooth the outsides of shapes. glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // GL_NICEST, GL_FASTEST, GL_DONT_CARE glMatrixMode(GL_PROJECTION); glOrtho(-OVERSIZE, OVERSIZE, OVERSIZE, -OVERSIZE, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // We don't need lighting effects glDisable(GL_LIGHTING); // glColorPointer(4, GL_UNSIGNED_BYTE, 0, *); // glInterleavedArrays(GL_T2F_N3F_V3F, 0, *) glPushAttrib (GL_ALL_ATTRIB_BITS); } // Set Title //SDL_WM_SetCaption("TestSWF", NULL); // Mouse state. int mouse_x = 0; int mouse_y = 0; int mouse_buttons = 0; float speed_scale = 1.0f; Uint32 start_ticks = 0; if (do_render) { start_ticks = tu_timer::get_ticks(); } Uint32 last_ticks = start_ticks; int frame_counter = 0; int last_logged_fps = last_ticks; int fps = 0; //TODO // gameswf::player* p = gameswf::create_player(); // p.run(); for (;;) { Uint32 ticks; if (do_render) { ticks = tu_timer::get_ticks(); } else { // Simulate time. ticks = last_ticks + (Uint32) (1000.0f / movie_fps); } int delta_ticks = ticks - last_ticks; float delta_t = delta_ticks / 1000.f; last_ticks = ticks; // Check auto timeout counter. if (exit_timeout > 0 && ticks - start_ticks > (Uint32) (exit_timeout * 1000)) { // Auto exit now. break; } bool ret = true; if (do_render) { SDL_Event event; // Handle input. while (ret) { if (SDL_PollEvent(&event) == 0) { break; } //printf("EVENT Type is %d\n", event.type); switch (event.type) { //case SDL_VIDEORESIZE: // TODO // s_scale = (float) event.resize.w / (float) width; // width = event.resize.w; // height = event.resize.h; // if (SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_OPENGL | SDL_RESIZABLE) == 0) // { // fprintf(stderr, "SDL_SetVideoMode() failed."); // exit(1); // } // glOrtho(-OVERSIZE, OVERSIZE, OVERSIZE, -OVERSIZE, -1, 1); //break; case SDL_USEREVENT: //printf("SDL_USER_EVENT at %s, code %d%d\n", __FUNCTION__, __LINE__, event.user.code); ret = false; break; case SDL_KEYDOWN: { SDL_Keycode key = event.key.keysym.sym; bool ctrl = (event.key.keysym.mod & KMOD_CTRL) != 0; if (key == SDLK_ESCAPE || (ctrl && key == SDLK_q) || (ctrl && key == SDLK_w)) { goto done; } else if (ctrl && key == SDLK_p) { // Toggle paused state. if (m->get_play_state() == gameswf::character::STOP) { m->set_play_state(gameswf::character::PLAY); } else { m->set_play_state(gameswf::character::STOP); } } else if (ctrl && key == SDLK_i) { // Init library, for detection of memory leaks (for testing purposes) /* // Clean up gameswf as much as possible, so valgrind will help find actual leaks. gameswf::set_sound_handler(NULL); delete sound; gameswf::set_render_handler(NULL); delete render; if (do_render) { if (do_sound) { sound = gameswf::create_sound_handler_sdl(); gameswf::set_sound_handler(sound); } render = gameswf::create_render_handler_ogl(); gameswf::set_render_handler(render); } */ // Load the actual movie. m = player->load_file(infile); if (m == NULL) { exit(1); } } else if (ctrl && (key == SDLK_LEFTBRACKET || key == SDLK_KP_MINUS)) { m->goto_frame(m->get_current_frame()-1); } else if (ctrl && (key == SDLK_RIGHTBRACKET || key == SDLK_KP_PLUS)) { m->goto_frame(m->get_current_frame()+1); } else if (ctrl && key == SDLK_a) { // Toggle antialiasing. s_antialiased = !s_antialiased; if (render) { render->set_antialiased(s_antialiased); } } else if (ctrl && key == SDLK_t) { // test text replacement / variable setting: m->set_variable("test.text", "set_edit_text was here...\nanother line of text for you to see in the text box"); } else if (ctrl && key == SDLK_g) { // test get_variable. message_log("testing get_variable: '"); message_log(m->get_variable("test.text")); message_log("'\n"); } else if (ctrl && key == SDLK_m) { // Test call_method. const char* result = m->call_method( "test_call", "%d, %f, %s, %ls", 200, 1.0f, "Test string", L"Test long string"); if (result) { message_log("call_method: result = "); message_log(result); message_log("\n"); } else { message_log("call_method: null result\n"); } } else if (ctrl && key == SDLK_b) { // toggle background color. s_background = !s_background; } // else if (ctrl && key == SDLK_f) //xxxxxx // { // extern bool gameswf_debug_show_paths; // gameswf_debug_show_paths = !gameswf_debug_show_paths; // } else if (ctrl && key == SDLK_EQUALS) { float f = gameswf::get_curve_max_pixel_error(); f *= 1.1f; gameswf::set_curve_max_pixel_error(f); printf("curve error tolerance = %f\n", f); } else if (ctrl && key == SDLK_MINUS) { float f = gameswf::get_curve_max_pixel_error(); f *= 0.9f; gameswf::set_curve_max_pixel_error(f); printf("curve error tolerance = %f\n", f); } else if (ctrl && key == SDLK_F2) { // Toggle wireframe. static bool wireframe_mode = false; wireframe_mode = !wireframe_mode; if (wireframe_mode) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } // TODO: clean up this interafce and re-enable. // } else if (ctrl && key == SDLK_d) { // // Flip a special debug flag. // gameswf_tesselate_dump_shape = true; } gameswf::key::code c = translate_key(key); if (c != gameswf::key::INVALID) { player->notify_key_event(c, true); } break; } case SDL_KEYUP: { SDL_Keycode key = event.key.keysym.sym; gameswf::key::code c = translate_key(key); if (c != gameswf::key::INVALID) { player->notify_key_event(c, false); } break; } case SDL_MOUSEMOTION: mouse_x = (int) (event.motion.x / scale_x); mouse_y = (int) (event.motion.y / scale_y); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { int mask = 1 << (event.button.button - 1); if (event.button.state == SDL_PRESSED) { mouse_buttons |= mask; } else { mouse_buttons &= ~mask; } break; } case SDL_QUIT: goto done; break; default: break; } } } if (do_render) { glDisable(GL_DEPTH_TEST); // Disable depth testing. glDrawBuffer(GL_BACK); } renderTest(); //m = player->get_root(); //m->set_display_viewport(0, 0, width, height); //m->set_background_alpha(s_background ? 1.0f : 0.05f); // //m->notify_mouse_state(mouse_x, mouse_y, mouse_buttons); // //Uint32 t_advance = tu_timer::get_ticks(); //m->advance(delta_t * speed_scale); //t_advance = tu_timer::get_ticks() - t_advance; // //if (do_sound && sound) //{ // sound->advance(delta_t * speed_scale); //} // Uint32 t_display = tu_timer::get_ticks(); m->display(); t_display = tu_timer::get_ticks() - t_display; if (do_render) { Uint32 t_swap = tu_timer::get_ticks(); //SDL_GL_SwapBuffers(); SDL_GL_SwapWindow(window); t_swap = tu_timer::get_ticks() - t_swap; //glPopAttrib (); frame_counter++; // Log the frame rate every second or so. if (last_ticks - last_logged_fps > 1000) { float delta = (last_ticks - last_logged_fps) / 1000.f; fps = (int) ((float) frame_counter / delta); last_logged_fps = last_ticks; frame_counter = 0; } if (s_measure_performance == false) { // Don't hog the CPU. SDL_Delay(s_delay); } else { printf("fps = %d\n", fps); } // for perfomance testing // printf("advance time: %d, display time %d, swap buffers time = %d\n", // t_advance, t_display, t_swap); #ifdef HAVE_PERFOMANCE_INFO char buffer[8]; snprintf(buffer, 8, "%03d", t_advance); m->set_variable("t_Advance", buffer); snprintf(buffer, 8, "%03d", t_display); m->set_variable("t_Display", buffer); snprintf(buffer, 8, "%03d", t_swap); m->set_variable("t_SwapBuffers", buffer); snprintf(buffer, 8, "%d", fps); m->set_variable("FPS", buffer); #endif } // TODO: clean up this interface and re-enable. // gameswf_tesselate_dump_shape = false; ///xxxxx // See if we should exit. if (do_loop == false && m->get_current_frame() + 1 == m->get_frame_count()) { // We're reached the end of the movie; exit. break; } } done: gameswf::set_sound_handler(NULL); delete sound; gameswf::set_render_handler(NULL); delete render; SDL_Quit(); } } // for testing memory leaks tu_memdebug::close(); return 0; }