static void camera_frustum_from_matrix(GF_Camera *cam, GF_Matrix *mx) { u32 i; cam->planes[FRUS_LEFT_PLANE].normal.x = mx->m[3] + mx->m[0]; cam->planes[FRUS_LEFT_PLANE].normal.y = mx->m[7] + mx->m[4]; cam->planes[FRUS_LEFT_PLANE].normal.z = mx->m[11] + mx->m[8]; cam->planes[FRUS_LEFT_PLANE].d = mx->m[15] + mx->m[12]; cam->planes[FRUS_RIGHT_PLANE].normal.x = mx->m[3] - mx->m[0]; cam->planes[FRUS_RIGHT_PLANE].normal.y = mx->m[7] - mx->m[4]; cam->planes[FRUS_RIGHT_PLANE].normal.z = mx->m[11] - mx->m[8]; cam->planes[FRUS_RIGHT_PLANE].d = mx->m[15] - mx->m[12]; cam->planes[FRUS_BOTTOM_PLANE].normal.x = mx->m[3] + mx->m[1]; cam->planes[FRUS_BOTTOM_PLANE].normal.y = mx->m[7] + mx->m[5]; cam->planes[FRUS_BOTTOM_PLANE].normal.z = mx->m[11] + mx->m[9]; cam->planes[FRUS_BOTTOM_PLANE].d = mx->m[15] + mx->m[13]; cam->planes[FRUS_TOP_PLANE].normal.x = mx->m[3] - mx->m[1]; cam->planes[FRUS_TOP_PLANE].normal.y = mx->m[7] - mx->m[5]; cam->planes[FRUS_TOP_PLANE].normal.z = mx->m[11] - mx->m[9]; cam->planes[FRUS_TOP_PLANE].d = mx->m[15] - mx->m[13]; cam->planes[FRUS_FAR_PLANE].normal.x = mx->m[3] - mx->m[2]; cam->planes[FRUS_FAR_PLANE].normal.y = mx->m[7] - mx->m[6]; cam->planes[FRUS_FAR_PLANE].normal.z = mx->m[11] - mx->m[10]; cam->planes[FRUS_FAR_PLANE].d = mx->m[15] - mx->m[14]; cam->planes[FRUS_NEAR_PLANE].normal.x = mx->m[3] + mx->m[2]; cam->planes[FRUS_NEAR_PLANE].normal.y = mx->m[7] + mx->m[6]; cam->planes[FRUS_NEAR_PLANE].normal.z = mx->m[11] + mx->m[10]; cam->planes[FRUS_NEAR_PLANE].d = mx->m[15] + mx->m[14]; for (i=0; i<6; ++i) { #ifdef GPAC_FIXED_POINT /*after some testing, it's just safer to move back to float here, the smallest drift will result in completely wrong culling...*/ Float vx, vy, vz, nor; vx = FIX2FLT(cam->planes[i].normal.x); vy = FIX2FLT(cam->planes[i].normal.y); vz = FIX2FLT(cam->planes[i].normal.z); nor = (Float) sqrt(vx*vx + vy*vy + vz*vz); vx /= nor; vy /= nor; vz /= nor; cam->planes[i].d = FLT2FIX (FIX2FLT(cam->planes[i].d) / nor); cam->planes[i].normal.x = FLT2FIX(vx); cam->planes[i].normal.y = FLT2FIX(vy); cam->planes[i].normal.z = FLT2FIX(vz); #else Float len = (Float)(1.0f / gf_vec_len(cam->planes[i].normal)); cam->planes[i].normal = gf_vec_scale(cam->planes[i].normal, len); cam->planes[i].d *= len; #endif /*compute p-vertex idx*/ cam->p_idx[i] = gf_plane_get_p_vertex_idx(&cam->planes[i]); } }
static GF_Err gdip_get_text_size(GF_FontReader *dr, const unsigned short *string, Fixed *width, Fixed *height) { GpPath *path_tmp; GpStringFormat *fmt; FontPriv *ctx = (FontPriv *)dr->udta; *width = *height = 0; if (!ctx->font) return GF_BAD_PARAM; GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &fmt); GdipCreatePath(FillModeAlternate, &path_tmp); RectF rc; rc.X = rc.Y = 0; rc.Width = rc.Height = 0; GdipAddPathString(path_tmp, (const WCHAR *)string, -1, ctx->font, ctx->font_style, ctx->em_size, &rc, fmt); GdipGetPathWorldBounds(path_tmp, &rc, NULL, NULL); adjust_white_space(string, &rc.Width, ctx->whitespace_width); *width = FLT2FIX(rc.Width); *height = FLT2FIX(rc.Height); GdipDeleteStringFormat(fmt); GdipDeletePath(path_tmp); return GF_OK; }
/*generic N-bezier*/ static void NBezier(GF_Point2D *pts, s32 n, Double mu, GF_Point2D *pt_out) { s32 k,kn,nn,nkn; Double blend, muk, munk; pt_out->x = pt_out->y = 0; muk = 1; munk = pow(1-mu,(Double)n); for (k=0;k<=n;k++) { nn = n; kn = k; nkn = n - k; blend = muk * munk; muk *= mu; munk /= (1-mu); while (nn >= 1) { blend *= nn; nn--; if (kn > 1) { blend /= (double)kn; kn--; } if (nkn > 1) { blend /= (double)nkn; nkn--; } } pt_out->x += gf_mulfix(pts[k].x, FLT2FIX(blend)); pt_out->y += gf_mulfix(pts[k].y, FLT2FIX(blend)); } }
static Fixed convert_svg_length_to_user(GF_Renderer *sr, SVG_Length *length) { // Assuming the environment is 90dpi switch (length->type) { case SVG_NUMBER_PERCENTAGE: break; case SVG_NUMBER_EMS: break; case SVG_NUMBER_EXS: break; case SVG_NUMBER_VALUE: break; case SVG_NUMBER_PX: return length->value; case SVG_NUMBER_CM: return gf_mulfix(length->value, FLT2FIX(35.43307f)); break; case SVG_NUMBER_MM: return gf_mulfix(length->value, FLT2FIX(3.543307f)); case SVG_NUMBER_IN: return length->value * 90; case SVG_NUMBER_PT: return 5 * length->value / 4; case SVG_NUMBER_PC: return length->value * 15; case SVG_NUMBER_INHERIT: break; } return length->value; }
/** * Translation matrix * */ void translate ( float x, float y, float z ) { identity( ); m_matrix[0][3] = FLT2FIX( x ); m_matrix[1][3] = FLT2FIX( y ); m_matrix[2][3] = FLT2FIX( z ); }
/** * Constructs a rotation (about x-axis) matrix * */ void rotateZ ( float32 rad ) { fix32 sinf = FLT2FIX( sin( rad ) ); fix32 cosf = FLT2FIX( cos( rad ) ); identity( ); m_matrix[0][0] = cosf; m_matrix[0][1] = -sinf; m_matrix[1][0] = sinf; m_matrix[1][1] = cosf; }
Fixed BD_ReadSFFloat(GF_BifsDecoder * codec, GF_BitStream *bs) { if (codec->ActiveQP && codec->ActiveQP->useEfficientCoding) return gf_bifs_dec_mantissa_float(codec, bs); return FLT2FIX(gf_bs_read_float(bs)); }
static void Valuator_SetInSFTime(GF_Node *n, GF_Route *route) { SFVec4f val; M_Valuator *_this = (M_Valuator *) n; val.x = val.y = val.z = val.q = FLT2FIX(_this->inSFTime); SetValuatorOutput(_this, &val, NULL, GF_SG_VRML_SFTIME); }
static void get_point_size(GF_Matrix2D *mat, Fixed *w, Fixed *h) { GF_Point2D pt; pt.x = mat->m[0] + mat->m[1]; pt.y = mat->m[3] + mat->m[4]; *w = *h = gf_divfix(FLT2FIX(1.41421356f) , gf_v2d_len(&pt)); }
//parses efficient float Fixed gf_bifs_dec_mantissa_float(GF_BifsDecoder *codec, GF_BitStream *bs) { u32 mantLength, expLength, mantSign, mantissa, expSign, exponent; unsigned char exp; union { Float f; long l; } ft_value; mantLength = gf_bs_read_int(bs, 4); if (!mantLength) return 0; expLength = gf_bs_read_int(bs, 3); mantSign = gf_bs_read_int(bs, 1); mantissa = gf_bs_read_int(bs, mantLength - 1); expSign = exponent = 0; exp = 0; exp = 127; if (expLength) { expSign = gf_bs_read_int(bs, 1); exponent = gf_bs_read_int(bs, expLength-1); exp += (1-2*expSign)*( (1 << (expLength-1) ) + exponent); } ft_value.l = mantSign << 31; ft_value.l |= (exp & 0xff) << 23; ft_value.l |= mantissa << 9; return FLT2FIX(ft_value.f); }
Fixed gf_smil_timing_get_normalized_simple_time(SMIL_Timing_RTI *rti, Double scene_time) { Double activeTime; Double simpleTime; Fixed normalizedSimpleTime; if (!rti->current_interval) return 0; activeTime = scene_time - rti->current_interval->begin; if (rti->current_interval->active_duration != -1 && activeTime > rti->current_interval->active_duration) return FIX_ONE; if (rti->current_interval->simple_duration>0) { rti->current_interval->nb_iterations = (u32)floor(activeTime / rti->current_interval->simple_duration); } else { rti->current_interval->nb_iterations = 0; } simpleTime = activeTime - rti->current_interval->simple_duration * rti->current_interval->nb_iterations; /* to be sure clamp simpleTime */ simpleTime = MAX(0, simpleTime); simpleTime = MIN(rti->current_interval->simple_duration, simpleTime); normalizedSimpleTime = FLT2FIX(simpleTime / rti->current_interval->simple_duration); return normalizedSimpleTime; }
/** * Writes a view angle and coords packet. Doesn't send the packet outside. */ void Demo_WriteLocalCamera(int plrNum) { player_t* plr = &ddPlayers[plrNum]; ddplayer_t* ddpl = &plr->shared; mobj_t* mo = ddpl->mo; fixed_t x, y, z; byte flags; boolean incfov = (writeInfo[plrNum].fov != fieldOfView); const viewdata_t* viewData = R_ViewData(plrNum); if(!mo) return; Msg_Begin(clients[plrNum].recordPaused ? PKT_DEMOCAM_RESUME : PKT_DEMOCAM); // Flags. flags = (mo->origin[VZ] <= mo->floorZ ? LCAMF_ONGROUND : 0) // On ground? | (incfov ? LCAMF_FOV : 0); if(ddpl->flags & DDPF_CAMERA) { flags &= ~LCAMF_ONGROUND; flags |= LCAMF_CAMERA; } Writer_WriteByte(msgWriter, flags); // Coordinates. x = FLT2FIX(mo->origin[VX]); y = FLT2FIX(mo->origin[VY]); Writer_WriteInt16(msgWriter, x >> 16); Writer_WriteByte(msgWriter, x >> 8); Writer_WriteInt16(msgWriter, y >> 16); Writer_WriteByte(msgWriter, y >> 8); z = FLT2FIX(mo->origin[VZ] + viewData->current.origin[VZ]); Writer_WriteInt16(msgWriter, z >> 16); Writer_WriteByte(msgWriter, z >> 8); Writer_WriteInt16(msgWriter, mo->angle /*ddpl->clAngle*/ >> 16); /* $unifiedangles */ Writer_WriteInt16(msgWriter, ddpl->lookDir / 110 * DDMAXSHORT /* $unifiedangles */); // Field of view is optional. if(incfov) { Writer_WriteInt16(msgWriter, fieldOfView / 180 * DDMAXSHORT); writeInfo[plrNum].fov = fieldOfView; } Msg_End(); Net_SendBuffer(plrNum, SPF_DONT_SEND); }
/** * Constructor * * @param w Screen width * @param h Screen height */ TransformPipe ( sint32 w, sint32 h ) : m_transform( true ) { m_swdth = w/2; m_shght = h/2; m_aspect = FLT2FIX( (float32)w/h ); m_dist = 150; }
void pillar_s::write(MapStateWriter *msw) const { Writer1 *writer = msw->writer(); Writer_WriteByte(writer, 1); // Write a version byte. // Note we don't bother to save a byte to tell if the function // is present as we ALWAYS add one when loading. Writer_WriteInt32(writer, P_ToIndex(sector)); Writer_WriteInt32(writer, FLT2FIX(ceilingSpeed)); Writer_WriteInt32(writer, FLT2FIX(floorSpeed)); Writer_WriteInt32(writer, FLT2FIX(floorDest)); Writer_WriteInt32(writer, FLT2FIX(ceilingDest)); Writer_WriteInt32(writer, direction); Writer_WriteInt32(writer, crush); }
dd_bool EV_ThingSpawn(byte *args, dd_bool fog) { int tid, searcher; angle_t angle; mobj_t *mobj, *newMobj, *fogMobj; mobjtype_t moType; dd_bool success; //coord_t z; success = false; searcher = -1; tid = args[0]; moType = TranslateThingType[args[1]]; if(G_Ruleset_NoMonsters() && (MOBJINFO[moType].flags & MF_COUNTKILL)) { // Don't spawn monsters if -nomonsters return false; } angle = (int) args[2] << 24; while((mobj = P_FindMobjFromTID(tid, &searcher)) != NULL) { //z = mobj->origin[VZ]; if((newMobj = P_SpawnMobj(moType, mobj->origin, angle, 0))) { if(P_TestMobjLocation(newMobj) == false) { // Didn't fit P_MobjRemove(newMobj, true); } else { if(fog) { if((fogMobj = P_SpawnMobjXYZ(MT_TFOG, mobj->origin[VX], mobj->origin[VY], mobj->origin[VZ] + TELEFOGHEIGHT, angle + ANG180, 0))) S_StartSound(SFX_TELEPORT, fogMobj); } newMobj->flags2 |= MF2_DROPPED; // Don't respawn if(newMobj->flags2 & MF2_FLOATBOB) { newMobj->special1 = FLT2FIX(newMobj->origin[VZ] - newMobj->floorZ); } success = true; } } } return success; }
void camera_set_2d(GF_Camera *cam) { cam->is_3D = 0; #ifdef FORCE_CAMERA_3D cam->position.x = cam->position.y = 0; cam->position.z = INT2FIX(NEAR_PLANE_2D); cam->up.x = cam->up.z = 0; cam->up.y = FIX_ONE; cam->target.x = cam->target.y = cam->target.z = 0; cam->vp_position = cam->position; cam->vp_orientation.x = cam->vp_orientation.y = 0; cam->vp_orientation.q = 0; cam->vp_orientation.y = FIX_ONE; cam->vp_fov = cam->fieldOfView = FLT2FIX(0.785398); cam->vp_dist = INT2FIX(NEAR_PLANE_2D); cam->end_zoom = FIX_ONE; #endif }
/* valuator spec (9.4.2.116.2) Convert if the content of the string represents an int, float or double value. ‘Boolean’ string values 'true' and 'false' are converted to 1.0 and 0.0 respectively. Any other string is converted to 0.0 */ static void Valuator_SetInSFString(GF_Node *n, GF_Route *route) { SFVec4f val; M_Valuator *_this = (M_Valuator *) n; val.x = val.y = val.z = val.q = 0; if (! _this->inSFString.buffer) return; if (!stricmp(_this->inSFString.buffer, "true")) { val.x = val.y = val.z = val.q = FIX_ONE; } else if (!strstr(_this->inSFString.buffer, ".")) { val.x = INT2FIX( atoi(_this->inSFString.buffer) ); val.y = val.z = val.q = val.x; } else { val.x = FLT2FIX( atof(_this->inSFString.buffer) ); val.y = val.z = val.q = val.x; } SetValuatorOutput(_this, &val, NULL, GF_SG_VRML_SFSTRING); }
GF_Err swf_to_svg_init(SWFReader *read, u32 swf_flags, Float swf_flatten_angle) { if (!read->user) return GF_BAD_PARAM; /*init callbacks*/ read->show_frame = swf_svg_show_frame; read->allocate_depth = swf_svg_allocate_depth; read->place_obj = swf_svg_place_obj; read->remove_obj = swf_svg_remove_obj; read->define_shape = swf_svg_define_shape; read->define_sprite = swf_svg_define_sprite; read->set_backcol = swf_svg_set_backcol; read->define_button = swf_svg_define_button; read->define_text = swf_svg_define_text; read->define_edit_text = swf_svg_define_edit_text; read->setup_sound = swf_svg_setup_sound; read->start_sound = swf_svg_start_sound; read->setup_image = swf_svg_setup_image; read->action = swf_svg_action; read->finalize = swf_svg_finalize; read->flags = swf_flags; read->flat_limit = FLT2FIX(swf_flatten_angle); read->print_stream_header = GF_TRUE; swf_svg_print(read, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); swf_svg_print(read, "<svg xmlns=\"http://www.w3.org/2000/svg\" "); swf_svg_print(read, "xmlns:xlink=\"http://www.w3.org/1999/xlink\" "); swf_svg_print(read, "width=\"100%%\" "); swf_svg_print(read, "height=\"100%%\" "); swf_svg_print(read, "viewBox=\"0 0 %d %d\" ", FIX2INT(read->width), FIX2INT(read->height)); swf_svg_print(read, "viewport-fill=\"rgb(255,255,255)\" "); swf_svg_print(read, ">\n"); read->print_stream_header = GF_FALSE; /* update sample description */ read->add_header(read->user, read->svg_data, read->svg_data_size, GF_TRUE); gf_free(read->svg_data); read->svg_data = NULL; read->svg_data_size = 0; return GF_OK; }
void uir_load_event(GF_UIRecord *uir) { memset(&uir->next_event, 0, sizeof(GF_Event)); uir->evt_loaded = 0; if (!gf_bs_available(uir->bs)) return; uir->next_time = gf_bs_read_u32(uir->bs); uir->next_event.type = gf_bs_read_u8(uir->bs); switch (uir->next_event.type) { case GF_EVENT_CLICK: case GF_EVENT_MOUSEUP: case GF_EVENT_MOUSEDOWN: case GF_EVENT_MOUSEOVER: case GF_EVENT_MOUSEOUT: /*!! ALL MOUSE EVENTS SHALL BE DECLARED BEFORE MOUSEMOVE !! */ case GF_EVENT_MOUSEMOVE: /*mouse wheel event*/ case GF_EVENT_MOUSEWHEEL: uir->next_event.mouse.button = gf_bs_read_u8(uir->bs); uir->next_event.mouse.x = gf_bs_read_u32(uir->bs); uir->next_event.mouse.y = gf_bs_read_u32(uir->bs); uir->next_event.mouse.wheel_pos = FLT2FIX( gf_bs_read_float(uir->bs) ); uir->next_event.mouse.key_states = gf_bs_read_u8(uir->bs); break; /*Key Events*/ case GF_EVENT_KEYUP: case GF_EVENT_KEYDOWN: case GF_EVENT_LONGKEYPRESS: uir->next_event.key.key_code = gf_bs_read_u32(uir->bs); uir->next_event.key.hw_code = gf_bs_read_u32(uir->bs); uir->next_event.key.flags = gf_bs_read_u32(uir->bs); break; /*character input*/ case GF_EVENT_TEXTINPUT: uir->next_event.character.unicode_char = gf_bs_read_u32(uir->bs); break; } uir->evt_loaded = 1; }
dd_bool EV_StartFloorWaggle(int tag, int height, int speed, int offset, int timer) { iterlist_t *list = P_GetSectorIterListForTag(tag, false); if(!list) return false; dd_bool retCode = false; IterList_SetIteratorDirection(list, ITERLIST_FORWARD); IterList_RewindIterator(list); Sector *sec; while((sec = (Sector *)IterList_MoveIterator(list))) { if(P_ToXSector(sec)->specialData) continue; // Already moving, so keep going... retCode = true; waggle_t *waggle = (waggle_t *)Z_Calloc(sizeof(*waggle), PU_MAP, 0); waggle->thinker.function = (thinkfunc_t) T_FloorWaggle; Thinker_Add(&waggle->thinker); P_ToXSector(sec)->specialData = waggle; waggle->sector = sec; waggle->originalHeight = P_GetDoublep(sec, DMU_FLOOR_HEIGHT); waggle->accumulator = offset; waggle->accDelta = FIX2FLT(speed << 10); waggle->scale = 0; waggle->targetScale = FIX2FLT(height << 10); waggle->scaleDelta = FIX2FLT(FLT2FIX(waggle->targetScale) / (TICSPERSEC + ((3 * TICSPERSEC) * height) / 255)); waggle->ticker = timer ? timer * 35 : -1; waggle->state = WS_EXPAND; } return retCode; }
void plat_t::write(MapStateWriter *msw) const { Writer *writer = msw->writer(); Writer_WriteByte(writer, 1); // Write a version byte. Writer_WriteByte(writer, (byte) type); Writer_WriteInt32(writer, P_ToIndex(sector)); Writer_WriteInt32(writer, FLT2FIX(speed)); Writer_WriteInt16(writer, (int)low); Writer_WriteInt16(writer, (int)high); Writer_WriteInt32(writer, wait); Writer_WriteInt32(writer, count); Writer_WriteByte(writer, (byte) state); Writer_WriteByte(writer, (byte) oldState); Writer_WriteByte(writer, (byte) crush); Writer_WriteInt32(writer, tag); }
void waggle_s::write(MapStateWriter *msw) const { Writer1 *writer = msw->writer(); Writer_WriteByte(writer, 1); // Write a version byte. // Note we don't bother to save a byte to tell if the function // is present as we ALWAYS add one when loading. Writer_WriteInt32(writer, P_ToIndex(sector)); Writer_WriteInt32(writer, FLT2FIX(originalHeight)); Writer_WriteInt32(writer, FLT2FIX(accumulator)); Writer_WriteInt32(writer, FLT2FIX(accDelta)); Writer_WriteInt32(writer, FLT2FIX(targetScale)); Writer_WriteInt32(writer, FLT2FIX(scale)); Writer_WriteInt32(writer, FLT2FIX(scaleDelta)); Writer_WriteInt32(writer, ticker); Writer_WriteInt32(writer, state); }
static void storage_parse_sf(void *ptr, u32 fieldType, char *opt) { Float v1, v2, v3; switch (fieldType) { case GF_SG_VRML_SFBOOL: sscanf(opt, "%d", ((SFBool *)ptr)); break; case GF_SG_VRML_SFINT32: sscanf(opt, "%d", ((SFInt32 *)ptr) ); break; case GF_SG_VRML_SFTIME: sscanf(opt, "%lf", ((SFTime *)ptr) ); break; case GF_SG_VRML_SFFLOAT: sscanf(opt, "%g", &v1); * (SFFloat *)ptr = FLT2FIX(v1); break; case GF_SG_VRML_SFVEC2F: sscanf(opt, "%g %g", &v1, &v2); ((SFVec2f*)ptr)->x = FLT2FIX(v1); ((SFVec2f*)ptr)->y = FLT2FIX(v2); break; case GF_SG_VRML_SFVEC3F: sscanf(opt, "%g %g %g", &v1, &v2, &v3); ((SFVec3f*)ptr)->x = FLT2FIX(v1); ((SFVec3f*)ptr)->y = FLT2FIX(v2); ((SFVec3f*)ptr)->z = FLT2FIX(v3); break; case GF_SG_VRML_SFSTRING: if ( ((SFString *)ptr)->buffer) gf_free(((SFString *)ptr)->buffer); ((SFString *)ptr)->buffer = gf_strdup(opt); break; default: break; } }
int RenderMain ( void ) { int tmrLast = 0; int currFps = 0, lastFps = 0; int frameIndex = 0; float frameInterp = 0; float rotRadY = 0.0f, rotRadX = 0.0f; char textBuffer[128]; bool keyTable[4] = { false }; bool focus = true; Matrix4fi transMatrix( false ); MAExtent size = maGetScrSize( ); MDLFixed model( RES_MODEL_OGRE ); TransformPipe pipe( EXTENT_X( size ), EXTENT_Y( size ) ); // Center model model.centerModel( ); tmrLast = maGetMilliSecondCount( ); // // Rendering loop // while ( true ) { // // Handle input // MAEvent e; while ( maGetEvent( &e ) ) { if ( e.type == EVENT_TYPE_CLOSE || e.type == EVENT_TYPE_KEY_PRESSED || e.type == EVENT_TYPE_POINTER_PRESSED ) maExit(0); else if(e.type == EVENT_TYPE_FOCUS_LOST) focus = false; else if(e.type == EVENT_TYPE_FOCUS_GAINED) focus = true; else if ( e.type == EVENT_TYPE_KEY_PRESSED ) { if ( e.key == MAK_LEFT ) keyTable[MAK_LEFT-MAK_UP] = true; else if ( e.key == MAK_RIGHT ) keyTable[MAK_RIGHT-MAK_UP] = true; else if ( e.key == MAK_UP ) keyTable[MAK_UP-MAK_UP] = true; else if ( e.key == MAK_DOWN ) keyTable[MAK_DOWN-MAK_UP] = true; } else if ( e.type == EVENT_TYPE_KEY_RELEASED ) { if ( e.key == MAK_LEFT ) keyTable[MAK_LEFT-MAK_UP] = false; else if ( e.key == MAK_RIGHT ) keyTable[MAK_RIGHT-MAK_UP] = false; else if ( e.key == MAK_UP ) keyTable[MAK_UP-MAK_UP] = false; else if ( e.key == MAK_DOWN ) keyTable[MAK_DOWN-MAK_UP] = false; } } if(focus) { if ( keyTable[MAK_LEFT-MAK_UP] ) rotRadY -= (float)M_PI / 60; else if ( keyTable[MAK_RIGHT-MAK_UP] ) rotRadY += (float)M_PI / 60; else if ( keyTable[MAK_UP-MAK_UP] ) rotRadX -= (float)M_PI / 60; else if ( keyTable[MAK_DOWN-MAK_UP] ) rotRadX += (float)M_PI / 60; rotRadX = (rotRadX >= 2*(float)M_PI) ? rotRadX-2*(float)M_PI : rotRadX; rotRadY = (rotRadY >= 2*(float)M_PI) ? rotRadY-2*(float)M_PI : rotRadY; // // Construct transformation pipe // pipe.resetPipe( ); transMatrix.rotateX( (float)-M_PI/2 ); pipe.addTransform( transMatrix ); transMatrix.rotateY( (float)M_PI/4 ); pipe.addTransform( transMatrix ); transMatrix.rotateX( rotRadX ); pipe.addTransform( transMatrix ); transMatrix.rotateY( rotRadY ); pipe.addTransform( transMatrix ); transMatrix.translate( 0, 0, 130 ); pipe.addTransform( transMatrix ); // Clear screen maSetColor( 0 ); maFillRect( 0, 0, EXTENT_X( size ), EXTENT_Y( size ) ); // // Animate and render model // maSetColor( 0xffffff ); model.drawFrameLerp( frameIndex, FLT2FIX( frameInterp ), pipe ); frameInterp += 0.25f; if ( frameInterp >= 1.0f ) { frameIndex = (frameIndex+1) % model.getFrameCount( ); frameInterp = 0.0f; } // Draw fps to screen sprintf( textBuffer, "fps: %d", lastFps ); maDrawText( 0, 0, textBuffer ); // Update screen and keep backlight on maUpdateScreen( ); maResetBacklight( ); // FPS counter currFps++; if ( tmrLast+1000 <= maGetMilliSecondCount( ) ) { lastFps = currFps; currFps = 0; tmrLast = maGetMilliSecondCount( ); lprintfln( "fps: %d", lastFps ); } } else { // no focus maWait(0); } } }
static Bool compositor_handle_navigation_3d(GF_Compositor *compositor, GF_Event *ev) { Fixed x, y, trans_scale; Fixed dx, dy, key_trans, key_pan, key_exam; s32 key_inv; u32 keys; #ifdef SCALE_NAV Bool is_pixel_metrics; #endif GF_Camera *cam; Fixed zoom = compositor->zoom; cam = NULL; #ifndef GPAC_DISABLE_VRML if (compositor->active_layer) { cam = compositor_layer3d_get_camera(compositor->active_layer); #ifdef SCALE_NAV is_pixel_metrics = gf_sg_use_pixel_metrics(gf_node_get_graph(compositor->active_layer)); #endif } #endif if (!cam) { cam = &compositor->visual->camera; assert(compositor); assert(compositor->scene); #ifdef SCALE_NAV is_pixel_metrics = compositor->traverse_state->pixel_metrics; #endif } if (!cam || (cam->navigate_mode==GF_NAVIGATE_NONE)) return 0; keys = compositor->key_states; if (!cam->navigate_mode && !(keys & GF_KEY_MOD_ALT) ) return 0; x = y = 0; /*renorm between -1, 1*/ if (ev->type<=GF_EVENT_MOUSEWHEEL) { x = gf_divfix( INT2FIX(ev->mouse.x - (s32) compositor->visual->width/2), INT2FIX(compositor->visual->width)); y = gf_divfix( INT2FIX(ev->mouse.y - (s32) compositor->visual->height/2), INT2FIX(compositor->visual->height)); } dx = (x - compositor->grab_x); dy = (compositor->grab_y - y); #ifdef SCALE_NAV trans_scale = is_pixel_metrics ? cam->width/2 : INT2FIX(10); key_trans = is_pixel_metrics ? INT2FIX(10) : cam->avatar_size.x; #else trans_scale = cam->width/20; key_trans = cam->avatar_size.x/2; //if default VP is quite far from center use larger dz/dy moves if (cam->vp_dist>100) trans_scale *= 10; #endif if (cam->world_bbox.is_set && (key_trans*5 > cam->world_bbox.radius)) { key_trans = cam->world_bbox.radius / 100; } key_pan = FIX_ONE/25; key_exam = FIX_ONE/20; key_inv = 1; if (keys & GF_KEY_MOD_SHIFT) { dx *= 4; dy *= 4; key_pan *= 4; key_exam *= 4; key_trans*=4; } switch (ev->type) { case GF_EVENT_MOUSEDOWN: /*left*/ if (ev->mouse.button==GF_MOUSE_LEFT) { compositor->grab_x = x; compositor->grab_y = y; compositor->navigation_state = 1; /*change vp and examine center to current location*/ if ((keys & GF_KEY_MOD_CTRL) && compositor->hit_square_dist) { cam->vp_position = cam->position; cam->vp_orientation = camera_get_orientation(cam->position, cam->target, cam->up); cam->vp_fov = cam->fieldOfView; cam->examine_center = compositor->hit_world_point; camera_changed(compositor, cam); return 1; } } /*right*/ else if (ev->mouse.button==GF_MOUSE_RIGHT) { if (compositor->navigation_state && (cam->navigate_mode==GF_NAVIGATE_WALK)) { camera_jump(cam); gf_sc_invalidate(compositor, NULL); return 1; } else if (keys & GF_KEY_MOD_CTRL) gf_sc_fit_world_to_screen(compositor); } break; /* note: shortcuts are mostly the same as blaxxun contact, I don't feel like remembering 2 sets...*/ case GF_EVENT_MOUSEMOVE: if (!compositor->navigation_state) { if (cam->navigate_mode==GF_NAVIGATE_GAME) { /*init mode*/ compositor->grab_x = x; compositor->grab_y = y; compositor->navigation_state = 1; } return 0; } compositor->navigation_state++; switch (cam->navigate_mode) { /*FIXME- we'll likely need a "step" value for walk at some point*/ case GF_NAVIGATE_WALK: case GF_NAVIGATE_FLY: view_pan_x(compositor, cam, -dx); if (keys & GF_KEY_MOD_CTRL) view_pan_y(compositor, cam, dy); else view_translate_z(compositor, cam, gf_mulfix(dy, trans_scale)); break; case GF_NAVIGATE_VR: view_pan_x(compositor, cam, -dx); if (keys & GF_KEY_MOD_CTRL) view_zoom(compositor, cam, dy); else view_pan_y(compositor, cam, dy); break; case GF_NAVIGATE_PAN: view_pan_x(compositor, cam, -dx); if (keys & GF_KEY_MOD_CTRL) view_translate_z(compositor, cam, gf_mulfix(dy, trans_scale)); else view_pan_y(compositor, cam, dy); break; case GF_NAVIGATE_SLIDE: view_translate_x(compositor, cam, gf_mulfix(dx, trans_scale)); if (keys & GF_KEY_MOD_CTRL) view_translate_z(compositor, cam, gf_mulfix(dy, trans_scale)); else view_translate_y(compositor, cam, gf_mulfix(dy, trans_scale)); break; case GF_NAVIGATE_EXAMINE: if (keys & GF_KEY_MOD_CTRL) { view_translate_z(compositor, cam, gf_mulfix(dy, trans_scale)); view_roll(compositor, cam, gf_mulfix(dx, trans_scale)); } else { if (ABS(dx) > ABS(dy)) { view_exam_x(compositor, cam, -gf_mulfix(GF_PI, dx)); } else { view_exam_y(compositor, cam, gf_mulfix(GF_PI, dy)); } } break; case GF_NAVIGATE_ORBIT: if (keys & GF_KEY_MOD_CTRL) { view_translate_z(compositor, cam, gf_mulfix(dy, trans_scale)); } else { view_orbit_x(compositor, cam, -gf_mulfix(GF_PI, dx)); view_orbit_y(compositor, cam, gf_mulfix(GF_PI, dy)); } break; case GF_NAVIGATE_GAME: view_pan_x(compositor, cam, -dx); view_pan_y(compositor, cam, dy); break; } compositor->grab_x = x; compositor->grab_y = y; return 1; case GF_EVENT_MOUSEWHEEL: switch (cam->navigate_mode) { /*FIXME- we'll likely need a "step" value for walk at some point*/ case GF_NAVIGATE_WALK: case GF_NAVIGATE_FLY: view_pan_y(compositor, cam, gf_mulfix(key_pan, ev->mouse.wheel_pos)); break; case GF_NAVIGATE_VR: view_zoom(compositor, cam, gf_mulfix(key_pan, ev->mouse.wheel_pos)); break; case GF_NAVIGATE_SLIDE: case GF_NAVIGATE_EXAMINE: case GF_NAVIGATE_ORBIT: case GF_NAVIGATE_PAN: if (cam->is_3D) { view_translate_z(compositor, cam, gf_mulfix(trans_scale, ev->mouse.wheel_pos) * ((keys & GF_KEY_MOD_SHIFT) ? 4 : 1)); } else { nav_set_zoom_trans_2d(compositor->visual, zoom + INT2FIX(ev->mouse.wheel_pos)/10, 0, 0); } } return 1; case GF_EVENT_MOUSEUP: if (ev->mouse.button==GF_MOUSE_LEFT) compositor->navigation_state = 0; break; case GF_EVENT_KEYDOWN: switch (ev->key.key_code) { case GF_KEY_BACKSPACE: gf_sc_reset_graphics(compositor); return 1; case GF_KEY_C: compositor->collide_mode = compositor->collide_mode ? GF_COLLISION_NONE : GF_COLLISION_DISPLACEMENT; return 1; case GF_KEY_J: if (cam->navigate_mode==GF_NAVIGATE_WALK) { camera_jump(cam); gf_sc_invalidate(compositor, NULL); return 1; } break; case GF_KEY_HOME: if (!compositor->navigation_state) { compositor->visual->camera.start_zoom = compositor->zoom; compositor->zoom = FIX_ONE; compositor->interoccular_offset = 0; compositor->focus_distance = 0; compositor->interoccular_offset = 0; compositor->focus_distance = 0; compositor_3d_reset_camera(compositor); } break; case GF_KEY_END: if (cam->navigate_mode==GF_NAVIGATE_GAME) { cam->navigate_mode = GF_NAVIGATE_WALK; compositor->navigation_state = 0; return 1; } break; case GF_KEY_LEFT: key_inv = -1; case GF_KEY_RIGHT: if (keys & GF_KEY_MOD_ALT) { if ( (keys & GF_KEY_MOD_SHIFT) && (compositor->visual->nb_views > 1) ) { /*+ or - 10 cm*/ compositor->focus_distance += INT2FIX(key_inv); cam->flags |= CAM_IS_DIRTY; fprintf(stderr, "AutoStereo view distance %f - focus %f\n", FIX2FLT(compositor->video_out->view_distance)/100, FIX2FLT(compositor->focus_distance)/100); gf_sc_invalidate(compositor, NULL); return 1; } return 0; } switch (cam->navigate_mode) { case GF_NAVIGATE_SLIDE: if (keys & GF_KEY_MOD_CTRL) view_pan_x(compositor, cam, key_inv * key_pan); else view_translate_x(compositor, cam, key_inv * key_trans); break; case GF_NAVIGATE_EXAMINE: if (keys & GF_KEY_MOD_CTRL) view_roll(compositor, cam, gf_mulfix(dx, trans_scale)); else view_exam_x(compositor, cam, -key_inv * key_exam); break; case GF_NAVIGATE_ORBIT: if (keys & GF_KEY_MOD_CTRL) view_translate_x(compositor, cam, key_inv * key_trans); else view_orbit_x(compositor, cam, -key_inv * key_exam); break; case GF_NAVIGATE_GAME: view_translate_x(compositor, cam, key_inv * key_trans); break; case GF_NAVIGATE_VR: view_pan_x(compositor, cam, -key_inv * key_pan); break; /*walk/fly/pan*/ default: if (keys & GF_KEY_MOD_CTRL) view_translate_x(compositor, cam, key_inv * key_trans); else view_pan_x(compositor, cam, -key_inv * key_pan); break; } return 1; case GF_KEY_DOWN: key_inv = -1; case GF_KEY_UP: if (keys & GF_KEY_MOD_ALT) { if ( (keys & GF_KEY_MOD_SHIFT) && (compositor->visual->nb_views > 1) ) { compositor->interoccular_offset += FLT2FIX(0.5) * key_inv; fprintf(stderr, "AutoStereo interoccular distance %f\n", FIX2FLT(compositor->interoccular_distance + compositor->interoccular_offset)); cam->flags |= CAM_IS_DIRTY; gf_sc_invalidate(compositor, NULL); return 1; } return 0; } switch (cam->navigate_mode) { case GF_NAVIGATE_SLIDE: if (keys & GF_KEY_MOD_CTRL) view_translate_z(compositor, cam, key_inv * key_trans); else view_translate_y(compositor, cam, key_inv * key_trans); break; case GF_NAVIGATE_EXAMINE: if (keys & GF_KEY_MOD_CTRL) view_translate_z(compositor, cam, key_inv * key_trans); else view_exam_y(compositor, cam, -key_inv * key_exam); break; case GF_NAVIGATE_ORBIT: if (keys & GF_KEY_MOD_CTRL) view_translate_y(compositor, cam, key_inv * key_trans); else view_orbit_y(compositor, cam, -key_inv * key_exam); break; case GF_NAVIGATE_PAN: if (keys & GF_KEY_MOD_CTRL) view_translate_y(compositor, cam, key_inv * key_trans); else view_pan_y(compositor, cam, key_inv * key_pan); break; case GF_NAVIGATE_GAME: view_translate_z(compositor, cam, key_inv * key_trans); break; case GF_NAVIGATE_VR: if (keys & GF_KEY_MOD_CTRL) view_zoom(compositor, cam, key_inv * key_pan); else view_pan_y(compositor, cam, key_inv * key_pan); break; /*walk/fly*/ default: if (keys & GF_KEY_MOD_CTRL) view_pan_y(compositor, cam, key_inv * key_pan); else view_translate_z(compositor, cam, key_inv * key_trans); break; } return 1; case GF_KEY_PAGEDOWN: if (keys & GF_KEY_MOD_CTRL) { view_zoom(compositor, cam, FIX_ONE/10); return 1; } break; case GF_KEY_PAGEUP: if (keys & GF_KEY_MOD_CTRL) { view_zoom(compositor, cam, -FIX_ONE/10); return 1; } break; } break; } return 0; }
static Bool validator_load_event(GF_Validator *validator) { GF_XMLNode *event_node; GF_XMLAttribute *att; u32 att_index; memset(&validator->next_event, 0, sizeof(GF_Event)); validator->evt_loaded = 0; validator->next_event_snapshot = 0; if (!validator->xvs_node) return 0; while (1) { event_node = gf_list_get(validator->xvs_node->content, validator->xvs_event_index); if (!event_node) { return 0; } else if (event_node->type == GF_XML_NODE_TYPE) { validator->xvs_event_index++; break; } else { validator->xvs_event_index++; } } if (!strcmp(event_node->name, "snapshot")) { validator->next_event_snapshot = 1; } else { validator->next_event.type = gf_dom_event_type_by_name(event_node->name); if (validator->next_event.type == GF_EVENT_UNKNOWN) { return 1; } } att_index = 0; while (1) { att = gf_list_get(event_node->attributes, att_index); if (!att) break; if (!strcmp(att->name, "time")) { validator->next_time = atoi(att->value); } else if (!strcmp(att->name, "button")) { if (!strcmp(att->value, "Left")) { validator->next_event.mouse.button = 0; } else if (!strcmp(att->value, "Middle")) { validator->next_event.mouse.button = 1; } else if (!strcmp(att->value, "Right")) { validator->next_event.mouse.button = 2; } } else if (!strcmp(att->name, "x")) { validator->next_event.mouse.x = atoi(att->value); } else if (!strcmp(att->name, "y")) { validator->next_event.mouse.y = atoi(att->value); } else if (!strcmp(att->name, "wheel_pos")) { validator->next_event.mouse.wheel_pos = FLT2FIX(atof(att->value)); } else if (!strcmp(att->name, "shift") && !strcmp(att->value, "true")) { validator->next_event.mouse.key_states |= GF_KEY_MOD_SHIFT; } else if (!strcmp(att->name, "alt") && !strcmp(att->value, "true")) { validator->next_event.mouse.key_states |= GF_KEY_MOD_ALT; } else if (!strcmp(att->name, "ctrl") && !strcmp(att->value, "true")) { validator->next_event.mouse.key_states |= GF_KEY_MOD_CTRL; } else if (!strcmp(att->name, "key_identifier")) { validator->next_event.key.key_code = gf_dom_get_key_type(att->value); } else if (!strcmp(att->name, "unicode-char")) { validator->next_event.character.unicode_char = atoi(att->value); } att_index++; } validator->evt_loaded = 1; return 1; }
/* WARNING: According to SMIL (http://www.w3.org/TR/2005/REC-SMIL2-20051213/animation.html#animationNS-Fill, see "Illustration of animation combining a partial repeat and fill="freeze"") When a element is frozen, its normalized simple time is not necessarily 1, an animation can be frozen in the middle of a repeatition */ Fixed gf_smil_timing_get_normalized_simple_time(SMIL_Timing_RTI *rti, Double scene_time, Bool *force_end) { Double activeTime; Double simpleTime; Fixed normalizedSimpleTime; if (rti->current_interval->begin == -1) return 0; /* we define the active time as the elapsed time from the current activation of the element */ activeTime = scene_time - rti->current_interval->begin; /* Is the animation reaching the end of its active duration ? */ if (rti->current_interval->active_duration != -1 && activeTime >= rti->current_interval->active_duration) { /* we clamp the active time to its maximum value */ activeTime = rti->current_interval->active_duration; /* if the simple duration is defined, then we can take iterations into account */ if (rti->current_interval->simple_duration>0) { if (activeTime == rti->current_interval->simple_duration*(rti->current_interval->nb_iterations+1)) { return FIX_ONE; } else { goto end; } } else { /* If the element does not define its simple duration, but it has an active duration, and we are past this active duration, we assume it's blocked in final state We should take into account fill behavior*/ rti->current_interval->nb_iterations = 0; if (rti->timingp->fill && *(rti->timingp->fill) == SMIL_FILL_FREEZE) { if (rti->current_interval->repeat_duration == rti->current_interval->simple_duration) { return FIX_ONE; } else { return rti->normalized_simple_time; } } else { return 0; } } } end: /* if the simple duration is defined, then we can take iterations into account */ if (rti->current_interval->simple_duration>0) { /* if we are active but frozen or done (animate-elem-65-t, animate-elem-222-t) (see The rule to apply to compute the active duration of an element with min or max specified) */ if ((activeTime >= rti->current_interval->repeat_duration) && rti->current_interval->min_active) { /* freeze the normalized simple time */ if (force_end) *force_end = 1; if (rti->timingp->fill && *(rti->timingp->fill) == SMIL_FILL_FREEZE) { if (rti->current_interval->repeat_duration == rti->current_interval->simple_duration) { return FIX_ONE; } else { return rti->normalized_simple_time; } } } /* we update the number of iterations */ rti->current_interval->nb_iterations = (u32)floor(activeTime / rti->current_interval->simple_duration); } else { /* If the element does not define its simple duration, we assume it's blocked in final state Is this correct ? */ rti->current_interval->nb_iterations = 0; //GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Error Computing Normalized Simple Time while simple duration is indefinite\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); return FIX_ONE; } /* We compute the simple time by removing time taken by previous iterations */ simpleTime = activeTime - rti->current_interval->simple_duration * rti->current_interval->nb_iterations; /* Then we clamp the simple time to be sure it is between 0 and simple duration */ simpleTime = MAX(0, simpleTime); simpleTime = MIN(rti->current_interval->simple_duration, simpleTime); /* Then we normalize to have a value between 0 and 1 */ normalizedSimpleTime = FLT2FIX(simpleTime / rti->current_interval->simple_duration); return normalizedSimpleTime; }
/* Notifies the scene time to a timed element, potentially changing its status and triggering its evaluation Returns: 0 if no rendering traversal is required, 1 if a rendering traversal is required, -1 if the time node is a discard which has been deleted during this notification, -2 means that the timed element is waiting to begin, -3 means that the timed element is active but does not need further notifications (set without dur) but still requires a rendering traversal */ s32 gf_smil_timing_notify_time(SMIL_Timing_RTI *rti, Double in_scene_time) { s32 ret = 0; GF_DOM_Event evt; SMILTimingAttributesPointers *timingp = rti->timingp; Bool force_end = 0; if (!timingp) return 0; /* if the scene time is the same as it was during the previous notification, it means that the animations are paused and we don't need to evaluate it again unless the force_reevaluation flag is set */ if ((rti->scene_time == in_scene_time) && (rti->force_reevaluation == 0)) return 0; if (!rti->paused) rti->scene_time = in_scene_time; rti->force_reevaluation = 0; /* for fraction events, in all cases we indicate that the scene needs redraw */ if (rti->evaluate_status == SMIL_TIMING_EVAL_FRACTION) return 1; if (rti->evaluate_status == SMIL_TIMING_EVAL_DISCARD) { /* TODO: FIX ME discarding should send a begin event ? */ /* Since the discard can only be evaluated once, it unregisters itself from the list of timed elements to be notified, so for this special case we return -1 when the discard has actually been executed */ if (gf_smil_discard(rti, FLT2FIX(rti->scene_time))) return -1; else return 0; } gf_node_register(rti->timed_elt, NULL); waiting_to_begin: if (rti->status == SMIL_STATUS_WAITING_TO_BEGIN) { if (rti->current_interval->begin != -1 && rti->scene_time >= rti->current_interval->begin) { /* if there is a computed interval with a definite begin value and if that value is lesser than the scene time, then the animation becomes active */ GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Activating\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); rti->status = SMIL_STATUS_ACTIVE; if (rti->timed_elt->sgprivate->tag==TAG_LSR_conditional) { SVG_Element *e = (SVG_Element *)rti->timed_elt; /*activate conditional*/ if (e->children) gf_node_traverse(e->children->node, NULL); rti->status = SMIL_STATUS_DONE; } else { gf_smil_reorder_anim(rti); } memset(&evt, 0, sizeof(evt)); evt.type = GF_EVENT_BEGIN_EVENT; evt.smil_event_time = rti->current_interval->begin; gf_dom_event_fire((GF_Node *)rti->timed_elt, &evt); } else { GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Evaluating (Not starting)\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); ret = -2; goto exit; } } if (rti->status == SMIL_STATUS_ACTIVE) { u32 cur_id; if (rti->current_interval->active_duration >= 0 && rti->scene_time >= (rti->current_interval->begin + rti->current_interval->active_duration)) { force_end: GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Stopping \n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); rti->normalized_simple_time = gf_smil_timing_get_normalized_simple_time(rti, rti->scene_time, NULL); ret = rti->postpone; if (timingp->fill && *timingp->fill == SMIL_FILL_FREEZE) { rti->status = SMIL_STATUS_FROZEN; rti->evaluate_status = SMIL_TIMING_EVAL_FREEZE; GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Preparing to freeze\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); if (!rti->postpone) { rti->evaluate(rti, rti->normalized_simple_time, rti->evaluate_status); } } else { rti->status = SMIL_STATUS_DONE; rti->evaluate_status = SMIL_TIMING_EVAL_REMOVE; GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Preparing to remove\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); if (!rti->postpone) { rti->evaluate(rti, rti->normalized_simple_time, rti->evaluate_status); } } memset(&evt, 0, sizeof(evt)); evt.type = GF_EVENT_END_EVENT; /* WARNING: begin + active_duration may be greater than 'now' because of force_end cases */ evt.smil_event_time = rti->current_interval->begin + rti->current_interval->active_duration; gf_dom_event_fire((GF_Node *)rti->timed_elt, &evt); } else { /* the animation is still active */ if (!timingp->restart || *timingp->restart == SMIL_RESTART_ALWAYS) { GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Checking for restart (always)\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); if (rti->next_interval->begin != -1 && rti->next_interval->begin < rti->scene_time) { *rti->current_interval = *rti->next_interval; gf_smil_timing_get_next_interval(rti, 0, rti->next_interval, rti->scene_time); /* mark that this element has been modified and need to be reinserted at its proper place in the list of timed elements in the scenegraph */ gf_smil_mark_modified(rti, 0); /* if this is animation, reinserting the animation in the list of animations that targets this attribute, so that it is the last one */ gf_smil_reorder_anim(rti); memset(&evt, 0, sizeof(evt)); evt.type = GF_EVENT_BEGIN_EVENT; evt.smil_event_time = rti->current_interval->begin; gf_dom_event_fire((GF_Node *)rti->timed_elt, &evt); } } ret = rti->postpone; cur_id = rti->current_interval->nb_iterations; rti->normalized_simple_time = gf_smil_timing_get_normalized_simple_time(rti, rti->scene_time, &force_end); if (force_end) { GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Forcing end (fill or remove)\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); goto force_end; } if (cur_id < rti->current_interval->nb_iterations) { GF_LOG(GF_LOG_DEBUG, GF_LOG_INTERACT, ("[SMIL Timing ] Time %f - Timed element %s - Preparing to repeat\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); memset(&evt, 0, sizeof(evt)); evt.type = GF_EVENT_REPEAT_EVENT; evt.smil_event_time = rti->current_interval->begin + rti->current_interval->nb_iterations*rti->current_interval->simple_duration; evt.detail = rti->current_interval->nb_iterations; gf_dom_event_fire((GF_Node *)rti->timed_elt, &evt); rti->evaluate_status = SMIL_TIMING_EVAL_REPEAT; } else { GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Preparing to update\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); rti->evaluate_status = SMIL_TIMING_EVAL_UPDATE; } if (!rti->postpone) { rti->evaluate(rti, rti->normalized_simple_time, rti->evaluate_status); } /* special case for animations with unspecified simpleDur (not with media timed elements) we need to indicate that this anim does not need to be notified anymore and that it does not require tree traversal */ if (gf_svg_is_animation_tag(rti->timed_elt->sgprivate->tag) && (rti->current_interval->simple_duration==-1) && (rti->current_interval->active_duration==-1) ) { /*GF_SceneGraph * sg = rti->timed_elt->sgprivate->scenegraph; while (sg->parent_scene) sg = sg->parent_scene; gf_list_del_item(sg->smil_timed_elements, rti); ret = -3;*/ ret = 1; } } } if ((rti->status == SMIL_STATUS_DONE) || (rti->status == SMIL_STATUS_FROZEN)) { if (!timingp->restart || *timingp->restart != SMIL_RESTART_NEVER) { /* Check changes in begin or end attributes */ GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Checking for restart when not active\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); if (rti->next_interval->begin != -1) { Bool restart_timing = 0; /*next interval is right now*/ if (rti->next_interval->begin == rti->current_interval->begin+rti->current_interval->active_duration) restart_timing = 1; /*switch intervals*/ if (rti->next_interval->begin >= rti->current_interval->begin+rti->current_interval->active_duration) { *rti->current_interval = *rti->next_interval; gf_smil_timing_print_interval(rti, 1, rti->current_interval); gf_smil_timing_get_next_interval(rti, 0, rti->next_interval, rti->scene_time); /* mark that this element has been modified and need to be reinserted at its proper place in the list of timed elements in the scenegraph */ gf_smil_mark_modified(rti, 0); } else { rti->next_interval->begin = -1; } /*if chaining to new interval, go to wait_for begin right now*/ if (restart_timing) { rti->status = SMIL_STATUS_WAITING_TO_BEGIN; rti->evaluate_status = SMIL_TIMING_EVAL_NONE; GF_LOG(GF_LOG_DEBUG, GF_LOG_SMIL, ("[SMIL Timing ] Time %f - Timed element %s - Returning to eval none status\n", gf_node_get_scene_time((GF_Node *)rti->timed_elt), gf_node_get_log_name((GF_Node *)rti->timed_elt))); ret = 0; goto waiting_to_begin; } /*otherwise move state to waiting for begin for next smil_timing evaluation, but don't change evaluate status for next anim evaluation*/ else { rti->status = SMIL_STATUS_WAITING_TO_BEGIN; } } else { /*??? what is this ???*/ //ret = 0; } } else if ((rti->status == SMIL_STATUS_DONE) && timingp->restart && (*timingp->restart == SMIL_RESTART_NEVER)) { /* the timed element is done and cannot restart, we don't need to evaluate it anymore */ GF_SceneGraph * sg = rti->timed_elt->sgprivate->scenegraph; while (sg->parent_scene) sg = sg->parent_scene; gf_list_del_item(sg->smil_timed_elements, rti); ret = -1; } } exit: gf_node_unregister(rti->timed_elt, NULL); return ret; }
static GF_Err IS_ProcessData(GF_SceneDecoder *plug, const char *inBuffer, u32 inBufferLength, u16 ES_ID, u32 AU_time, u32 mmlevel) { u32 i, j, count; Double scene_time; GF_BitStream *bs; GF_FieldInfo *field; ISStack *st; ISPriv *priv = (ISPriv *)plug->privateStack; GF_Err e = GF_OK; /*decode data frame except if local stringSensor*/ bs = gf_bs_new(inBuffer, inBufferLength, GF_BITSTREAM_READ); i=0; while ((field = (GF_FieldInfo *)gf_list_enum(priv->ddf, &i))) { /*store present flag in eventIn for command skip - this is an ugly hack but it works since DDF don't have event types*/ field->eventType = gf_bs_read_int(bs, 1); /*parse val ourselves (we don't want to depend on bifs codec)*/ if (field->eventType) { switch (field->fieldType) { case GF_SG_VRML_SFBOOL: * ((SFBool *) field->far_ptr) = (SFBool) gf_bs_read_int(bs, 1); break; case GF_SG_VRML_SFFLOAT: *((SFFloat *)field->far_ptr) = FLT2FIX( gf_bs_read_float(bs) ); break; case GF_SG_VRML_SFINT32: *((SFInt32 *)field->far_ptr) = (s32) gf_bs_read_int(bs, 32); break; case GF_SG_VRML_SFTIME: *((SFTime *)field->far_ptr) = gf_bs_read_double(bs); break; case GF_SG_VRML_SFVEC2F: ((SFVec2f *)field->far_ptr)->x = FLT2FIX( gf_bs_read_float(bs) ); ((SFVec2f *)field->far_ptr)->y = FLT2FIX( gf_bs_read_float(bs) ); break; case GF_SG_VRML_SFVEC3F: ((SFVec3f *)field->far_ptr)->x = FLT2FIX( gf_bs_read_float(bs) ); ((SFVec3f *)field->far_ptr)->y = FLT2FIX( gf_bs_read_float(bs) ); ((SFVec3f *)field->far_ptr)->z = FLT2FIX( gf_bs_read_float(bs) ); break; case GF_SG_VRML_SFCOLOR: ((SFColor *)field->far_ptr)->red = FLT2FIX( gf_bs_read_float(bs) ); ((SFColor *)field->far_ptr)->green = FLT2FIX( gf_bs_read_float(bs) ); ((SFColor *)field->far_ptr)->blue = FLT2FIX( gf_bs_read_float(bs) ); break; case GF_SG_VRML_SFVEC4F: case GF_SG_VRML_SFROTATION: ((SFRotation *)field->far_ptr)->x = FLT2FIX( gf_bs_read_float(bs) ); ((SFRotation *)field->far_ptr)->y = FLT2FIX( gf_bs_read_float(bs) ); ((SFRotation *)field->far_ptr)->z = FLT2FIX( gf_bs_read_float(bs) ); ((SFRotation *)field->far_ptr)->q = FLT2FIX( gf_bs_read_float(bs) ); break; case GF_SG_VRML_SFSTRING: { u32 size, length; size = gf_bs_read_int(bs, 5); length = gf_bs_read_int(bs, size); if (gf_bs_available(bs) < length) return GF_NON_COMPLIANT_BITSTREAM; if ( ((SFString *)field->far_ptr)->buffer ) gf_free( ((SFString *)field->far_ptr)->buffer); ((SFString *)field->far_ptr)->buffer = (char*)gf_malloc(sizeof(char)*(length+1)); memset(((SFString *)field->far_ptr)->buffer , 0, length+1); for (j=0; j<length; j++) { ((SFString *)field->far_ptr)->buffer[j] = gf_bs_read_int(bs, 8); } } break; } } } gf_bs_del(bs); /*special case for StringSensor in local mode: lookup for special chars*/ if ((priv->type == IS_StringSensor) && priv->is_local) { char tmp_utf8[5000]; const unsigned short *ptr; u32 len; GF_FieldInfo *field1 = (GF_FieldInfo *)gf_list_get(priv->ddf, 0); GF_FieldInfo *field2 = (GF_FieldInfo *)gf_list_get(priv->ddf, 1); SFString *inText = (SFString *) field1->far_ptr; SFString *outText = (SFString *) field2->far_ptr; field1->eventType = field2->eventType = 0; priv->enteredText[priv->text_len] = (short) '\0'; len = gf_utf8_wcslen(priv->enteredText); if (len && (priv->enteredText[len-1] == priv->termChar)) { ptr = priv->enteredText; len = gf_utf8_wcstombs(tmp_utf8, 5000, &ptr); if (outText->buffer) gf_free(outText->buffer); outText->buffer = (char*)gf_malloc(sizeof(char) * (len)); memcpy(outText->buffer, tmp_utf8, sizeof(char) * len-1); outText->buffer[len-1] = 0; if (inText->buffer) gf_free(inText->buffer); inText->buffer = NULL; priv->text_len = 0; field1->eventType = field2->eventType = 1; } else { if (priv->delChar) { /*remove chars*/ if ((len>1) && (priv->enteredText[len-1] == priv->delChar)) { priv->enteredText[len-1] = (short) '\0'; len--; if (len) { priv->enteredText[len-1] = (short) '\0'; len--; } } } priv->text_len = len; ptr = priv->enteredText; len = gf_utf8_wcstombs(tmp_utf8, 5000, &ptr); if (inText->buffer) gf_free(inText->buffer); inText->buffer = (char*)gf_malloc(sizeof(char) * (len+1)); memcpy(inText->buffer, tmp_utf8, sizeof(char) * len); inText->buffer[len] = 0; field1->eventType = 1; } } gf_term_lock_compositor(priv->scene->root_od->term, 1); /*apply it*/ i=0; while ((st = (ISStack*)gf_list_enum(priv->is_nodes, &i))) { assert(st->is); assert(st->mo); if (!st->is->enabled) continue; count = gf_list_count(st->is->buffer.commandList); scene_time = gf_scene_get_time(priv->scene); for (j=0; j<count; j++) { GF_Command *com = (GF_Command *)gf_list_get(st->is->buffer.commandList, j); GF_FieldInfo *field = (GF_FieldInfo *)gf_list_get(priv->ddf, j); GF_CommandField *info = (GF_CommandField *)gf_list_get(com->command_fields, 0); if (info && field && field->eventType) { gf_sg_vrml_field_copy(info->field_ptr, field->far_ptr, field->fieldType); gf_sg_command_apply(priv->scene->graph, com, scene_time); } } } gf_term_lock_compositor(priv->scene->root_od->term, 0); return e; }
void SV_SaveGameClient(uint /*sessionId*/) { throw de::Error("SV_SaveGameClient", "Not currently implemented"); #if 0 #if !__JHEXEN__ // unsupported in libhexen player_t *pl = &players[CONSOLEPLAYER]; mobj_t *mo = pl->plr->mo; if(!IS_CLIENT || !mo) return; // Prepare new saved game session session. de::game::GameStateFolder *session = new de::game::GameStateFolder(saveNameForClientSessionId(sessionId)); de::game::GameStateMetadata *metadata = G_CurrentSessionMetadata(); metadata->set("sessionId", sessionId); session->replaceMetadata(metadata); de::Path path = de::String("/savegame") / "client" / session->path(); if(!SV_OpenFileForWrite(path)) { App_Log(DE2_RES_WARNING, "SV_SaveGameClient: Failed opening \"%s\" for writing", path.toString().toLatin1().constData()); // Discard the useless session. delete session; return; } Writer1 *writer = SV_NewWriter(); SV_WriteSessionMetadata(*metadata, writer); // Some important information. // Our position and look angles. Writer_WriteInt32(writer, FLT2FIX(mo->origin[VX])); Writer_WriteInt32(writer, FLT2FIX(mo->origin[VY])); Writer_WriteInt32(writer, FLT2FIX(mo->origin[VZ])); Writer_WriteInt32(writer, FLT2FIX(mo->floorZ)); Writer_WriteInt32(writer, FLT2FIX(mo->ceilingZ)); Writer_WriteInt32(writer, mo->angle); /* $unifiedangles */ Writer_WriteFloat(writer, pl->plr->lookDir); /* $unifiedangles */ SV_BeginSegment(ASEG_PLAYER_HEADER); playerheader_t plrHdr; plrHdr.write(writer); players[CONSOLEPLAYER].write(writer, plrHdr); ThingArchive thingArchive; MapStateWriter(thingArchive).write(writer); /// @todo No consistency bytes in client saves? SV_CloseFile(); Writer_Delete(writer); delete session; #else DENG2_UNUSED(sessionId); #endif #endif }