void Mem_Clr (void *pmem, CPU_SIZE_T size) { Mem_Set((void *)pmem, (CPU_INT08U)0, /* See Note #2. */ (CPU_SIZE_T)size); }
/* ================ CL_TestEntities if cl_testentities is set, create 32 player models ================ */ void CL_TestEntities( void ) { int i, j; float f, r; edict_t ent, *pl; if( !cl_testentities->integer ) return; pl = CL_GetLocalPlayer(); Mem_Set( &ent, 0, sizeof( edict_t )); V_ClearScene(); for( i = 0; i < 32; i++ ) { r = 64 * ((i%4) - 1.5 ); f = 64 * (i/4) + 128; for( j = 0; j < 3; j++ ) ent.v.origin[j] = cl.refdef.vieworg[j]+cl.refdef.forward[j] * f + cl.refdef.right[j] * r; ent.v.scale = 1.0f; ent.serialnumber = pl->serialnumber; ent.v.controller[0] = ent.v.controller[1] = 90.0f; ent.v.controller[2] = ent.v.controller[3] = 180.0f; ent.v.modelindex = pl->v.modelindex; re->AddRefEntity( &ent, ED_NORMAL, -1 ); } }
int channel_open(char *const addr, int port) { int ret; struct sockaddr_in ServerAddr; // struct sockaddr_in ClientAddr; // int ServerID; int ClientID; Mem_Set(&ServerAddr, (CPU_CHAR)0, sizeof(ServerAddr) ); ServerAddr.sin_family = AF_INET; ServerAddr.sin_port = htons(port); ServerAddr.sin_addr.s_addr = inet_addr (addr); ClientID = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(-1 == ClientID) { return -1; } ret = connect(ClientID, (struct sockaddr*)&ServerAddr, sizeof(ServerAddr)); if(-1 == ret) { return -1; } else { return ClientID; } }
void SW_VES_new_year(void) { /* =================================================== */ /* we can use the debug memset because we allocated days, * that is, it wasn't allocated by the compiler. */ if (0==SW_VegEstab.count) return; Mem_Set(SW_VegEstab.yrsum.days, 0, SW_VegEstab.count); }
void S_StopBackgroundTrack( void ) { S_StopStreaming(); if( !s_bgTrack.stream ) return; FS_CloseStream( s_bgTrack.stream ); Mem_Set( &s_bgTrack, 0, sizeof( bg_track_t )); s_rawend = 0; }
/* ============= SV_BuildClientFrame Decides which entities are going to be visible to the client, and copies off the playerstat and areabits. ============= */ void SV_BuildClientFrame( sv_client_t *cl ) { edict_t *ent; edict_t *clent; edict_t *viewent; // may be NULL client_frame_t *frame; entity_state_t *state; sv_ents_t frame_ents; int i; clent = cl->edict; viewent = cl->pViewEntity; sv.net_framenum++; // this is the frame we are creating frame = &cl->frames[sv.framenum & SV_UPDATE_MASK]; frame->senttime = svs.realtime; // save it for ping calc later // clear everything in this snapshot frame_ents.num_entities = c_fullsend = 0; Mem_Set( frame->areabits, 0, sizeof( frame->areabits )); if( !clent->pvServerData->client ) return; // not in game yet // grab the current player index frame->index = NUM_FOR_EDICT( clent ); // add all the entities directly visible to the eye, which // may include portal entities that merge other viewpoints SV_AddEntitiesToPacket( viewent, clent, frame, &frame_ents, false ); // if there were portals visible, there may be out of order entities // in the list which will need to be resorted for the delta compression // to work correctly. This also catches the error condition // of an entity being included twice. qsort( frame_ents.entities, frame_ents.num_entities, sizeof( frame_ents.entities[0] ), SV_EntityNumbers ); // copy the entity states out frame->num_entities = 0; frame->first_entity = svs.next_client_entities; for( i = 0; i < frame_ents.num_entities; i++ ) { ent = EDICT_NUM( frame_ents.entities[i] ); // add it to the circular client_entities array state = &svs.client_entities[svs.next_client_entities % svs.num_client_entities]; *state = ent->pvServerData->s; svs.next_client_entities++; // this should never hit, map should always be restarted first in SV_Frame if( svs.next_client_entities >= 0x7FFFFFFE ) Host_Error( "svs.next_client_entities wrapped (sv.time limit is out)\n" ); frame->num_entities++; } }
/* ********************************************************************************************************* * 函 数 名: bsp_InitI2C * 功能说明: 配置I2C总线的GPIO,采用模拟IO的方式实现 * 形 参: 无 * 返 回 值: 无 ********************************************************************************************************* */ void bsp_InitI2C0(void) { GPIO_InitTypeDef GPIO_InitStructure; Mem_Set(&GPIO_InitStructure, 0x00, sizeof(GPIO_InitTypeDef)); RCC_AHB1PeriphClockCmd(RCC_I2C_PORT, ENABLE); /* 打开GPIO时钟 */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; /* 设为输出口 */ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; /* 设为开漏模式 */ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; /* 上下拉电阻不使能 */ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; /* IO口最大速度 */ GPIO_InitStructure.GPIO_Pin = I2C_SCL_PIN | I2C_SDA_PIN; GPIO_Init(GPIO_PORT_I2C, &GPIO_InitStructure); /* 给一个停止信号, 复位I2C总线上的所有设备到待机模式 */ i2c0_Stop(); }
void *Mem_Calloc( size_t nobjs, size_t size, const char *funcname) { /*------------------------------------------- Duplicates the behavior of calloc() similar to Mem_Malloc. cwb - 8/10/01 -------------------------------------------*/ void *p; p = Mem_Malloc( size * nobjs, funcname); #ifndef DEBUG_MEM /* if using mcguire's code, no need to memset after * malloc() as it is done there. */ Mem_Set(p, 0, size * nobjs); #endif return p; }
STATUS HSCSI_Check_Create(PHSCSI_INSTANCE_DATA Id) { VOID *p_memory; STATUS status = NU_SUCCESS; UNSIGNED check_data_size; HSCSI_TRACE_ENTRY(HSCSI_Check_Create); // Calculate the amount of space we will need for check data: // one per LUN per initiator check_data_size = sizeof(U8) * FCP_INITIATOR_MAX * FCP_LUNS_MAX; HSCSI_PRINT_HEX(TRACE_L8,"\n\rcheck_data_size = ", check_data_size); // Insure UNSIGNED alignment of check_data_size check_data_size = ((check_data_size + sizeof(UNSIGNED) - 1) / sizeof(UNSIGNED)) * sizeof(UNSIGNED); // get memory for the check_data array p_memory = HSCSI_Alloc((tSMALL|tUNCACHED), check_data_size); // Save pointer to check_data HSCSI_p_check_data = (HSCSI_P_CHECK_DATA)p_memory; HSCSI_PRINT_STRING(TRACE_L8, "\n\rHSCSI_p_check_data set"); // Initialize check data Mem_Set(p_memory, 0, check_data_size); // Update p_memory with size of check data p_memory = (char*)p_memory + check_data_size; return status; } // HSCSI_Check_Create
/* ================= ParseRawBrush parses the sides into buildBrush->sides[], nothing else. no validation, back plane removal, etc. ================= */ static void ParseRawBrush( bool onlyLights ) { side_t *side; float planePoints[3][3]; int planenum; char name[MAX_SHADERPATH]; char shader[MAX_SHADERPATH]; shaderInfo_t *si; token_t token; vects_t vects; int flags; buildBrush->numsides = 0; buildBrush->detail = false; if( g_bBrushPrimit == BRUSH_RADIANT ) Com_CheckToken( mapfile, "{" ); while( 1 ) { if( !Com_ReadToken( mapfile, SC_ALLOW_NEWLINES|SC_COMMENT_SEMICOLON, &token )) break; if( !com.stricmp( token.string, "}" )) break; if( g_bBrushPrimit == BRUSH_RADIANT ) { while( 1 ) { if( com.strcmp( token.string, "(" )) Com_ReadToken( mapfile, 0, &token ); else break; Com_ReadToken( mapfile, SC_ALLOW_NEWLINES, &token ); } } Com_SaveToken( mapfile, &token ); if( buildBrush->numsides >= MAX_BUILD_SIDES ) Sys_Break( "Entity %i, Brush %i MAX_BUILD_SIDES\n", buildBrush->entityNum, buildBrush->brushNum ); side = &buildBrush->sides[ buildBrush->numsides ]; Mem_Set( side, 0, sizeof( *side )); buildBrush->numsides++; // read the three point plane definition Com_Parse1DMatrix( mapfile, 3, planePoints[0] ); Com_Parse1DMatrix( mapfile, 3, planePoints[1] ); Com_Parse1DMatrix( mapfile, 3, planePoints[2] ); // read the texture matrix if( g_bBrushPrimit == BRUSH_RADIANT ) Com_Parse2DMatrix( mapfile, 2, 3, (float *)side->texMat ); // read the texturedef or shadername Com_ReadToken( mapfile, SC_ALLOW_PATHNAMES|SC_PARSE_GENERIC, &token ); com.strncpy( name, token.string, sizeof( name )); if( g_bBrushPrimit == BRUSH_WORLDCRAFT_22 || g_bBrushPrimit == BRUSH_GEARCRAFT_40 ) // Worldcraft 2.2+ { // texture U axis Com_ReadToken( mapfile, 0, &token ); if( com.strcmp( token.string, "[" )) Sys_Break( "missing '[' in texturedef (U)\n" ); Com_ReadFloat( mapfile, false, &vects.hammer.UAxis[0] ); Com_ReadFloat( mapfile, false, &vects.hammer.UAxis[1] ); Com_ReadFloat( mapfile, false, &vects.hammer.UAxis[2] ); Com_ReadFloat( mapfile, false, &vects.hammer.shift[0] ); Com_ReadToken( mapfile, 0, &token ); if( com.strcmp( token.string, "]" )) Sys_Break( "missing ']' in texturedef (U)\n" ); // texture V axis Com_ReadToken( mapfile, 0, &token ); if( com.strcmp( token.string, "[" )) Sys_Break( "missing '[' in texturedef (V)\n" ); Com_ReadFloat( mapfile, false, &vects.hammer.VAxis[0] ); Com_ReadFloat( mapfile, false, &vects.hammer.VAxis[1] ); Com_ReadFloat( mapfile, false, &vects.hammer.VAxis[2] ); Com_ReadFloat( mapfile, false, &vects.hammer.shift[1] ); Com_ReadToken( mapfile, 0, &token ); if( com.strcmp( token.string, "]" )) Sys_Break( "missing ']' in texturedef (V)\n"); // texture rotation is implicit in U/V axes. Com_ReadToken( mapfile, 0, &token ); vects.hammer.rotate = 0; // texure scale Com_ReadFloat( mapfile, false, &vects.hammer.scale[0] ); Com_ReadFloat( mapfile, false, &vects.hammer.scale[1] ); if( g_bBrushPrimit == BRUSH_GEARCRAFT_40 ) { Com_ReadLong( mapfile, false, &flags ); // read gearcraft flags Com_SkipRestOfLine( mapfile ); // gearcraft lightmap scale and rotate if( flags & GEARBOX_DETAIL ) side->compileFlags |= C_DETAIL; } } else if( g_bBrushPrimit == BRUSH_WORLDCRAFT_21 || g_bBrushPrimit == BRUSH_QUARK ) { // worldcraft 2.1-, old Radiant, QuArK Com_ReadFloat( mapfile, false, &vects.hammer.shift[0] ); Com_ReadFloat( mapfile, false, &vects.hammer.shift[1] ); Com_ReadFloat( mapfile, false, &vects.hammer.rotate ); Com_ReadFloat( mapfile, false, &vects.hammer.scale[0] ); Com_ReadFloat( mapfile, SC_COMMENT_SEMICOLON, &vects.hammer.scale[1] ); } // set default flags and values com.sprintf( shader, "textures/%s", name ); if( onlyLights ) si = &shaderInfo[0]; else si = ShaderInfoForShader( shader ); side->shaderInfo = si; side->surfaceFlags = si->surfaceFlags; side->contentFlags = si->contentFlags; side->compileFlags = si->compileFlags; side->value = si->value; // bias texture shift for non-radiant sides if( g_bBrushPrimit != BRUSH_RADIANT && si->globalTexture == false ) { vects.hammer.shift[0] -= (floor( vects.hammer.shift[0] / si->shaderWidth ) * si->shaderWidth); vects.hammer.shift[1] -= (floor( vects.hammer.shift[1] / si->shaderHeight ) * si->shaderHeight); } // historically, there are 3 integer values at the end of a brushside line in a .map file. // in quake 3, the only thing that mattered was the first of these three values, which // was previously the content flags. and only then did a single bit matter, the detail // bit. because every game has its own special flags for specifying detail, the // traditionally game-specified BASECONT_DETAIL flag was overridden for Q3Map 2.3.0 // by C_DETAIL, defined in q3map2.h. the value is exactly as it was before, but // is stored in compileFlags, as opposed to contentFlags, for multiple-game // portability. :sigh: if( g_bBrushPrimit != BRUSH_QUARK && Com_ReadToken( mapfile, SC_COMMENT_SEMICOLON, &token )) { // overwrite shader values directly from .map file Com_SaveToken( mapfile, &token ); Com_ReadLong( mapfile, false, &flags ); Com_ReadLong( mapfile, false, NULL ); Com_ReadLong( mapfile, false, NULL ); if( flags & C_DETAIL ) side->compileFlags |= C_DETAIL; } if( mapfile->TXcommand == '1' || mapfile->TXcommand == '2' ) { // we are QuArK mode and need to translate some numbers to align textures its way // from QuArK, the texture vectors are given directly from the three points vec3_t texMat[2]; float dot22, dot23, dot33, mdet, aa, bb, dd; int j, k; g_bBrushPrimit = BRUSH_QUARK; // we can detect it only here k = mapfile->TXcommand - '0'; for( j = 0; j < 3; j++ ) texMat[1][j] = (planePoints[k][j] - planePoints[0][j]) * (0.0078125f); // QuArK magic value k = 3 - k; for( j = 0; j < 3; j++ ) texMat[0][j] = (planePoints[k][j] - planePoints[0][j]) * (0.0078125f); // QuArK magic value dot22 = DotProduct( texMat[0], texMat[0] ); dot23 = DotProduct( texMat[0], texMat[1] ); dot33 = DotProduct( texMat[1], texMat[1] ); mdet = dot22 * dot33 - dot23 * dot23; if( mdet < 1E-6 && mdet > -1E-6 ) { aa = bb = dd = 0; MsgDev( D_WARN, "Entity %i, Brush %i: degenerate QuArK-style texture: \n", buildBrush->entityNum, buildBrush->brushNum ); } else { mdet = 1.0 / mdet; aa = dot33 * mdet; bb = -dot23 * mdet; dd = dot22 * mdet; } for( j = 0; j < 3; j++ ) { vects.quark.vecs[0][j] = aa * texMat[0][j] + bb * texMat[1][j]; vects.quark.vecs[1][j] = -(bb * texMat[0][j] + dd * texMat[1][j]); } vects.quark.vecs[0][3] = -DotProduct( vects.quark.vecs[0], planePoints[0] ); vects.quark.vecs[1][3] = -DotProduct( vects.quark.vecs[1], planePoints[0] ); } // find the plane number planenum = MapPlaneFromPoints( planePoints ); if( planenum == -1 ) { MsgDev( D_ERROR, "Entity %i, Brush %i: plane with no normal\n", buildBrush->entityNum, buildBrush->brushNum ); continue; } side->planenum = planenum; if( g_bBrushPrimit == BRUSH_QUARK ) { // QuArK format completely matched with internal // FIXME: don't calculate vecs, use QuArK texMat instead ? Mem_Copy( side->vecs, vects.quark.vecs, sizeof( side->vecs )); } else if( g_bBrushPrimit != BRUSH_RADIANT ) { vec3_t vecs[2]; float ang, sinv, cosv, ns, nt; int i, j, sv, tv; if( g_bBrushPrimit == BRUSH_WORLDCRAFT_21 ) TextureAxisFromPlane( &mapplanes[planenum], vecs[0], vecs[1] ); if( !vects.hammer.scale[0] ) vects.hammer.scale[0] = 1.0f; if( !vects.hammer.scale[1] ) vects.hammer.scale[1] = 1.0f; if( g_bBrushPrimit == BRUSH_WORLDCRAFT_21 ) { // rotate axis if( vects.hammer.rotate == 0 ) { sinv = 0; cosv = 1; } else if( vects.hammer.rotate == 90 ) { sinv = 1; cosv = 0; } else if( vects.hammer.rotate == 180 ) { sinv = 0; cosv = -1; } else if( vects.hammer.rotate == 270 ) { sinv = -1; cosv = 0; } else { ang = vects.hammer.rotate / 180 * M_PI; sinv = sin( ang ); cosv = cos( ang ); } if( vecs[0][0] ) sv = 0; else if( vecs[0][1] ) sv = 1; else sv = 2; if( vecs[1][0] ) tv = 0; else if( vecs[1][1] ) tv = 1; else tv = 2; for( i = 0; i < 2; i++ ) { ns = cosv * vecs[i][sv] - sinv * vecs[i][tv]; nt = sinv * vecs[i][sv] + cosv * vecs[i][tv]; vecs[i][sv] = ns; vecs[i][tv] = nt; } for( i = 0; i < 2; i++ ) for( j = 0; j < 3; j++ ) side->vecs[i][j] = vecs[i][j] / vects.hammer.scale[i]; } else if( g_bBrushPrimit == BRUSH_WORLDCRAFT_22 || g_bBrushPrimit == BRUSH_GEARCRAFT_40 ) { float scale; scale = 1.0f / vects.hammer.scale[0]; VectorScale( vects.hammer.UAxis, scale, side->vecs[0] ); scale = 1.0f / vects.hammer.scale[1]; VectorScale( vects.hammer.VAxis, scale, side->vecs[1] ); } // add shifts side->vecs[0][3] = vects.hammer.shift[0]; side->vecs[1][3] = vects.hammer.shift[1]; } } if( g_bBrushPrimit == BRUSH_RADIANT ) { Com_SaveToken( mapfile, &token ); Com_CheckToken( mapfile, "}" ); Com_CheckToken( mapfile, "}" ); } }
/* ================= AddBrushBevels adds any additional planes necessary to allow the brush being built to be expanded against axial bounding boxes 2003-01-20: added mr.Elusive fixes ================= */ void AddBrushBevels( void ) { int axis, dir; int i, j, k, l, order = 0; side_t sidetemp; side_t *s, *s2; winding_t *w, *w2; vec3_t normal; float dist; vec3_t vec, vec2; float d, minBack; // add the axial planes for( axis = 0; axis < 3; axis++ ) { for( dir = -1; dir <= 1; dir += 2, order++ ) { // see if the plane is allready present for( i = 0, s = buildBrush->sides; i < buildBrush->numsides; i++, s++ ) { if( mapplanes[s->planenum].normal[axis] == dir ) break; } if( i == buildBrush->numsides ) { // add a new side if( buildBrush->numsides == MAX_BUILD_SIDES ) Sys_Break( "Entity %i, Brush %i MAX_BUILD_SIDES\n", buildBrush->entityNum, buildBrush->brushNum ); Mem_Set( s, 0, sizeof( *s )); buildBrush->numsides++; VectorClear (normal); normal[axis] = dir; if( dir == 1 ) { // adding bevel plane snapping for fewer bsp planes if( bevelSnap > 0 ) dist = floor( buildBrush->maxs[axis] / bevelSnap ) * bevelSnap; else dist = buildBrush->maxs[axis]; } else { // adding bevel plane snapping for fewer bsp planes if( bevelSnap > 0 ) dist = -ceil( buildBrush->mins[axis] / bevelSnap ) * bevelSnap; else dist = -buildBrush->mins[axis]; } s->planenum = FindFloatPlane( normal, dist, 0, NULL ); s->contentFlags = buildBrush->sides[0].contentFlags; s->bevel = true; c_boxbevels++; } // if the plane is not in it canonical order, swap it if( i != order ) { sidetemp = buildBrush->sides[order]; buildBrush->sides[order] = buildBrush->sides[i]; buildBrush->sides[i] = sidetemp; } } } // add the edge bevels if( buildBrush->numsides == 6 ) return; // pure axial // test the non-axial plane edges for( i = 6; i < buildBrush->numsides; i++ ) { s = buildBrush->sides + i; w = s->winding; if( !w ) continue; for( j = 0; j < w->numpoints; j++ ) { k = (j+1)%w->numpoints; VectorSubtract( w->p[j], w->p[k], vec ); if( VectorNormalizeLength( vec ) < 0.5f ) continue; SnapNormal( vec ); for( k = 0; k < 3; k++ ) { if( vec[k] == -1.0f || vec[k] == 1.0f || (vec[k] == 0.0f && vec[(k+1)%3] == 0.0f)) break; // axial } if( k != 3 ) continue; // only test non-axial edges // try the six possible slanted axials from this edge for( axis = 0; axis < 3; axis++ ) { for( dir = -1; dir <= 1; dir += 2 ) { // construct a plane VectorClear( vec2 ); vec2[axis] = dir; CrossProduct( vec, vec2, normal ); if( VectorNormalizeLength( normal ) < 0.5f ) continue; dist = DotProduct( w->p[j], normal ); // if all the points on all the sides are // behind this plane, it is a proper edge bevel for( k = 0; k < buildBrush->numsides; k++ ) { // if this plane has allready been used, skip it if( PlaneEqual( &mapplanes[buildBrush->sides[k].planenum], normal, dist )) break; w2 = buildBrush->sides[k].winding; if( !w2 ) continue; minBack = 0.0f; for( l = 0; l < w2->numpoints; l++ ) { d = DotProduct( w2->p[l], normal ) - dist; if( d > 0.1f ) break; // point in front if( d < minBack ) minBack = d; } // if some point was at the front if( l != w2->numpoints ) break; // if no points at the back then the winding is on the bevel plane if( minBack > -0.1f ) break; } if( k != buildBrush->numsides ) continue; // wasn't part of the outer hull // add this plane if( buildBrush->numsides == MAX_BUILD_SIDES ) Sys_Break( "Entity %i, Brush %i MAX_BUILD_SIDES\n", buildBrush->entityNum, buildBrush->brushNum ); s2 = &buildBrush->sides[buildBrush->numsides]; buildBrush->numsides++; Mem_Set( s2, 0, sizeof( *s2 ) ); s2->planenum = FindFloatPlane( normal, dist, 1, &w->p[j] ); s2->contentFlags = buildBrush->sides[0].contentFlags; s2->bevel = true; c_edgebevels++; } } } } }
/* ================= UI_CreateGame_Init ================= */ static void UI_CreateGame_Init( void ) { Mem_Set( &uiCreateGame, 0, sizeof( uiCreateGame_t )); com.strncat( uiCreateGame.hintText, "Map", MAPNAME_LENGTH ); com.strncat( uiCreateGame.hintText, uiEmptyString, MAPNAME_LENGTH ); com.strncat( uiCreateGame.hintText, "Title", TITLE_LENGTH ); com.strncat( uiCreateGame.hintText, uiEmptyString, TITLE_LENGTH ); uiCreateGame.background.generic.id = ID_BACKGROUND; uiCreateGame.background.generic.type = QMTYPE_BITMAP; uiCreateGame.background.generic.flags = QMF_INACTIVE; uiCreateGame.background.generic.x = 0; uiCreateGame.background.generic.y = 0; uiCreateGame.background.generic.width = 1024; uiCreateGame.background.generic.height = 768; uiCreateGame.background.pic = ART_BACKGROUND; uiCreateGame.banner.generic.id = ID_BANNER; uiCreateGame.banner.generic.type = QMTYPE_BITMAP; uiCreateGame.banner.generic.flags = QMF_INACTIVE; uiCreateGame.banner.generic.x = UI_BANNER_POSX; uiCreateGame.banner.generic.y = UI_BANNER_POSY; uiCreateGame.banner.generic.width = UI_BANNER_WIDTH; uiCreateGame.banner.generic.height = UI_BANNER_HEIGHT; uiCreateGame.banner.pic = ART_BANNER; uiCreateGame.advOptions.generic.id = ID_ADVOPTIONS; uiCreateGame.advOptions.generic.type = QMTYPE_ACTION; uiCreateGame.advOptions.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW|QMF_GRAYED; uiCreateGame.advOptions.generic.x = 72; uiCreateGame.advOptions.generic.y = 230; uiCreateGame.advOptions.generic.name = "Adv. Options"; uiCreateGame.advOptions.generic.statusText = "Open the LAN game advanced options menu"; uiCreateGame.advOptions.generic.callback = UI_CreateGame_Callback; uiCreateGame.done.generic.id = ID_DONE; uiCreateGame.done.generic.type = QMTYPE_ACTION; uiCreateGame.done.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW; uiCreateGame.done.generic.x = 72; uiCreateGame.done.generic.y = 280; uiCreateGame.done.generic.name = "Ok"; uiCreateGame.done.generic.statusText = "Start the multiplayer game"; uiCreateGame.done.generic.callback = UI_CreateGame_Callback; uiCreateGame.cancel.generic.id = ID_CANCEL; uiCreateGame.cancel.generic.type = QMTYPE_ACTION; uiCreateGame.cancel.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW; uiCreateGame.cancel.generic.x = 72; uiCreateGame.cancel.generic.y = 330; uiCreateGame.cancel.generic.name = "Cancel"; uiCreateGame.cancel.generic.statusText = "Return to LAN game menu"; uiCreateGame.cancel.generic.callback = UI_CreateGame_Callback; uiCreateGame.dedicatedServer.generic.id = ID_DEDICATED; uiCreateGame.dedicatedServer.generic.type = QMTYPE_CHECKBOX; uiCreateGame.dedicatedServer.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_ACT_ONRELEASE|QMF_MOUSEONLY|QMF_DROPSHADOW; uiCreateGame.dedicatedServer.generic.name = "Dedicated server"; uiCreateGame.dedicatedServer.generic.x = 72; uiCreateGame.dedicatedServer.generic.y = 685; uiCreateGame.dedicatedServer.generic.callback = UI_CreateGame_Callback; uiCreateGame.dedicatedServer.generic.statusText = "faster, but you can't join the server from this machine"; uiCreateGame.hintMessage.generic.id = ID_TABLEHINT; uiCreateGame.hintMessage.generic.type = QMTYPE_ACTION; uiCreateGame.hintMessage.generic.flags = QMF_INACTIVE|QMF_SMALLFONT; uiCreateGame.hintMessage.generic.color = uiColorHelp; uiCreateGame.hintMessage.generic.name = uiCreateGame.hintText; uiCreateGame.hintMessage.generic.x = 590; uiCreateGame.hintMessage.generic.y = 215; uiCreateGame.mapsList.generic.id = ID_MAPLIST; uiCreateGame.mapsList.generic.type = QMTYPE_SCROLLLIST; uiCreateGame.mapsList.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_SMALLFONT; uiCreateGame.mapsList.generic.x = 590; uiCreateGame.mapsList.generic.y = 245; uiCreateGame.mapsList.generic.width = 410; uiCreateGame.mapsList.generic.height = 440; uiCreateGame.mapsList.generic.callback = UI_CreateGame_Callback; uiCreateGame.hostName.generic.id = ID_HOSTNAME; uiCreateGame.hostName.generic.type = QMTYPE_FIELD; uiCreateGame.hostName.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW; uiCreateGame.hostName.generic.name = "Server Name:"; uiCreateGame.hostName.generic.x = 350; uiCreateGame.hostName.generic.y = 260; uiCreateGame.hostName.generic.width = 205; uiCreateGame.hostName.generic.height = 32; uiCreateGame.hostName.generic.callback = UI_CreateGame_Callback; uiCreateGame.hostName.maxLength = 16; com.strncpy( uiCreateGame.hostName.buffer, Cvar_VariableString( "sv_hostname" ), sizeof( uiCreateGame.hostName.buffer )); uiCreateGame.maxClients.generic.id = ID_MAXCLIENTS; uiCreateGame.maxClients.generic.type = QMTYPE_FIELD; uiCreateGame.maxClients.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW|QMF_NUMBERSONLY; uiCreateGame.maxClients.generic.name = "Max Players:"; uiCreateGame.maxClients.generic.x = 350; uiCreateGame.maxClients.generic.y = 360; uiCreateGame.maxClients.generic.width = 205; uiCreateGame.maxClients.generic.height = 32; uiCreateGame.maxClients.maxLength = 3; if( Cvar_VariableInteger( "sv_maxclients" ) <= 1 ) com.snprintf( uiCreateGame.maxClients.buffer, sizeof( uiCreateGame.maxClients.buffer ), "8" ); else com.snprintf( uiCreateGame.maxClients.buffer, sizeof( uiCreateGame.maxClients.buffer ), "%i", Cvar_VariableInteger( "sv_maxclients" )); uiCreateGame.password.generic.id = ID_PASSWORD; uiCreateGame.password.generic.type = QMTYPE_FIELD; uiCreateGame.password.generic.flags = QMF_CENTER_JUSTIFY|QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW; uiCreateGame.password.generic.name = "Password:"******"Starting a new game will exit"; uiCreateGame.dlgMessage1.generic.x = 248; uiCreateGame.dlgMessage1.generic.y = 280; uiCreateGame.dlgMessage2.generic.id = ID_MSGTEXT; uiCreateGame.dlgMessage2.generic.type = QMTYPE_ACTION; uiCreateGame.dlgMessage2.generic.flags = QMF_INACTIVE|QMF_HIDDEN; uiCreateGame.dlgMessage2.generic.name = "any current game, OK to exit?"; uiCreateGame.dlgMessage2.generic.x = 248; uiCreateGame.dlgMessage2.generic.y = 310; uiCreateGame.yes.generic.id = ID_YES; uiCreateGame.yes.generic.type = QMTYPE_ACTION; uiCreateGame.yes.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_HIDDEN; uiCreateGame.yes.generic.name = "Ok"; uiCreateGame.yes.generic.x = 380; uiCreateGame.yes.generic.y = 460; uiCreateGame.yes.generic.callback = UI_CreateGame_Callback; uiCreateGame.no.generic.id = ID_NO; uiCreateGame.no.generic.type = QMTYPE_ACTION; uiCreateGame.no.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_HIDDEN; uiCreateGame.no.generic.name = "Cancel"; uiCreateGame.no.generic.x = 530; uiCreateGame.no.generic.y = 460; uiCreateGame.no.generic.callback = UI_CreateGame_Callback; UI_CreateGame_GetMapsList(); if( !Host_ServerState()) SV_LoadProgs( "server" ); // force to get user mp_variables UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.background ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.banner ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.advOptions ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.done ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.cancel ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.maxClients ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.hostName ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.password ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.dedicatedServer ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.hintMessage ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.mapsList ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.msgBox ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.dlgMessage1 ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.dlgMessage2 ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.no ); UI_AddItem( &uiCreateGame.menu, (void *)&uiCreateGame.yes ); }
/* ================== CM_SurfaceCollideFromTriangleSoup ================== */ static void CM_SurfaceCollideFromTriangleSoup( cTriangleSoup_t *triSoup, cSurfaceCollide_t *sc ) { float *p1, *p2, *p3; int i, i1, i2, i3; cfacet_t *facet; numPlanes = 0; numFacets = 0; #ifdef USE_HASHING // initialize hash table Mem_Set( planeHashTable, 0, sizeof( planeHashTable )); #endif // find the planes for each triangle of the grid for( i = 0; i < triSoup->numTriangles; i++ ) { p1 = triSoup->points[i][0]; p2 = triSoup->points[i][1]; p3 = triSoup->points[i][2]; triSoup->trianglePlanes[i] = CM_FindPlane( p1, p2, p3 ); } // create the borders for each triangle for( i = 0; i < triSoup->numTriangles; i++ ) { facet = &facets[numFacets]; Mem_Set( facet, 0, sizeof( *facet )); i1 = triSoup->indexes[i*3+0]; i2 = triSoup->indexes[i*3+1]; i3 = triSoup->indexes[i*3+2]; p1 = triSoup->points[i][0]; p2 = triSoup->points[i][1]; p3 = triSoup->points[i][2]; facet->surfacePlane = triSoup->trianglePlanes[i]; // try and make a quad out of two triangles #if 0 if( i != triSoup->numTriangles - 1 ) { int i4, i5, i6; float *p4; i4 = triSoup->indexes[i*3+3]; i5 = triSoup->indexes[i*3+4]; i6 = triSoup->indexes[i*3+5]; if( i4 == i3 && i5 == i2 ) { p4 = triSoup->points[i][5]; // vertex at i6 if(CM_GenerateFacetFor4Points( facet, p1, p2, p4, p3 )) { CM_SetBorderInward( facet, triSoup, i, 0 ); if( CM_ValidateFacet( facet )) { CM_AddFacetBevels( facet ); numFacets++; i++; // skip next tri continue; } } } } #endif if( CM_GenerateFacetFor3Points( facet, p1, p2, p3 )) { CM_SetBorderInward( facet, triSoup, i, 0 ); if( CM_ValidateFacet( facet )) { CM_AddFacetBevels( facet ); numFacets++; } } } // copy the results out sc->numPlanes = numPlanes; sc->planes = Mem_Alloc( cms.mempool, numPlanes * sizeof( *sc->planes )); Mem_Copy( sc->planes, planes, numPlanes * sizeof( *sc->planes )); sc->numFacets = numFacets; sc->facets = Mem_Alloc( cms.mempool, numFacets * sizeof( *sc->facets )); Mem_Copy( sc->facets, facets, numFacets * sizeof( *sc->facets )); }
/* ================= R_TraceLine ================= */ msurface_t *R_TransformedTraceLine( trace_t *tr, const vec3_t start, const vec3_t end, ref_entity_t *test, int umask ) { ref_model_t *model; r_fragmentframecount++; // for multi-check avoidance // fill in a default trace Mem_Set( tr, 0, sizeof( trace_t )); trace_surface = NULL; trace_umask = umask; trace_fraction = 1; VectorCopy( end, trace_impact ); Mem_Set( &trace_plane, 0, sizeof( trace_plane )); ClearBounds( trace_absmins, trace_absmaxs ); AddPointToBounds( start, trace_absmins, trace_absmaxs ); AddPointToBounds( end, trace_absmins, trace_absmaxs ); model = test->model; if( model ) { if( model->type == mod_world || model->type == mod_brush ) { mbrushmodel_t *bmodel = ( mbrushmodel_t * )model->extradata; vec3_t temp, start_l, end_l, axis[3]; bool rotated = !Matrix3x3_Compare( test->axis, matrix3x3_identity ); // transform VectorSubtract( start, test->origin, start_l ); VectorSubtract( end, test->origin, end_l ); if( rotated ) { VectorCopy( start_l, temp ); Matrix3x3_Transform( test->axis, temp, start_l ); VectorCopy( end_l, temp ); Matrix3x3_Transform( test->axis, temp, end_l ); } VectorCopy( start_l, trace_start ); VectorCopy( end_l, trace_end ); // world uses a recursive approach using BSP tree, submodels // just walk the list of surfaces linearly if( test->model->type == mod_world ) R_RecursiveHullCheck( bmodel->nodes, start_l, end_l ); else if( BoundsIntersect( model->mins, model->maxs, trace_absmins, trace_absmaxs ) ) R_TraceAgainstBmodel( bmodel ); // transform back if( rotated && trace_fraction != 1 ) { Matrix3x3_Transpose( axis, test->axis ); VectorCopy( tr->vecPlaneNormal, temp ); Matrix3x3_Transform( axis, temp, trace_plane.normal ); } } } // calculate the impact plane, if any if( trace_fraction < 1.0f ) { VectorNormalize( trace_plane.normal ); trace_plane.dist = DotProduct( trace_plane.normal, trace_impact ); CategorizePlane( &trace_plane ); tr->flPlaneDist = trace_plane.dist; VectorCopy( trace_plane.normal, tr->vecPlaneNormal ); tr->iContents = trace_surface->contents; tr->pHit = (edict_t *)test; } tr->flFraction = trace_fraction; VectorCopy( trace_impact, tr->vecEndPos ); return trace_surface; }
/* ********************************************************************************************************* * 函 数 名: RTC_Config * 功能说明: 用于配置时间戳功能 * 形 参:无 * 返 回 值: 无 ********************************************************************************************************* */ void RTC_Config(void) { int RtcTimeout; /* RTC超时计数 */ RTC_TimeTypeDef RTC_TimeStructure; RTC_InitTypeDef RTC_InitStructure; RTC_DateTypeDef RTC_DateStructure; Mem_Set(&RTC_TimeStructure, 0x00, sizeof(RTC_TimeTypeDef)); Mem_Set(&RTC_InitStructure, 0x00, sizeof(RTC_InitTypeDef)); Mem_Set(&RTC_DateStructure, 0x00, sizeof(RTC_DateTypeDef)); RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);/* 使能PWR时钟 */ PWR_BackupAccessCmd(ENABLE);/* 允许访问RTC */ try_again: if(OBCBootInfo.BootRTC_Source == 0) /* 选择LSE作为时钟源 */ { RCC_LSEConfig(RCC_LSE_ON); /* 使能LSE振荡器 */ RtcTimeout = 0; /* 等待就绪 */ while((RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && ((RtcTimeout++) < RTC_TIMEOUT_US))//20 { bsp_DelayUS(1); /* STM32延迟函数 */ } if(RtcTimeout > RTC_TIMEOUT_US) //18 /* 判断是否有超时 */ { DEBUG_LOG("Init RTC Wrong: Oscillator time out! \r\n"); RCC_LSEConfig(RCC_LSE_OFF); OBCBootInfo.BootLSE_Error = 1; OBCBootInfo.BootRTC_Source = 1; /* 自动配置RTC为内部时钟 */ } if(OBCBootInfo.BootRTC_Source == 0) { DEBUG_LOG("Enable RTC with LSE \r\n"); RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /* 选择RTC时钟源 */ uwSynchPrediv = 0xFF; uwAsynchPrediv = 0x7F; } } if(OBCBootInfo.BootRTC_Source == 1) /* 选择LSI作为时钟源 */ { RCC_LSICmd(ENABLE); /* 使能内部时钟 */ RtcTimeout = 0; /* 等待内部时钟稳定*/ while((RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) && ((RtcTimeout++) < RTC_TIMEOUT_US)) { bsp_DelayUS(1); /* STM32延迟函数 */ } if(RtcTimeout > RTC_TIMEOUT_US) { DEBUG_LOG("All Oscillator time out! \r\n"); //RCC_LSICmd(DISABLE); OBCBootInfo.BootLSI_Error = 1; OBCBootInfo.BootRTC_Source = 2; /* 自动配置RTC为内部时钟 */ } if(OBCBootInfo.BootRTC_Source == 1) { DEBUG_LOG("Enable RTC with LSI \r\n"); RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); /* 选择RTC时钟源 */ uwSynchPrediv = 0xFF; uwAsynchPrediv = 0x7F; } } if((OBCBootInfo.BootRTC_Source == 0)||(OBCBootInfo.BootRTC_Source == 1)) { RCC_RTCCLKCmd(ENABLE); /* 使能RTC时钟 */ RTC_WaitForSynchro(); /* 等待RTC APB寄存器同步 */ RTC_TimeStampCmd(RTC_TimeStampEdge_Falling, ENABLE); /* 使能时间戳 */ RTC_TimeStampPinSelection(RTC_TamperPin_PC13); RTC_InitStructure.RTC_AsynchPrediv = uwAsynchPrediv; /* 配置RTC数据寄存器和分频器 */ RTC_InitStructure.RTC_SynchPrediv = uwSynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; if (RTC_Init(&RTC_InitStructure) == ERROR) /* 检测RTC初始化 */ { DEBUG_LOG("RTC Init wrong \r\n"); if(OBCBootInfo.BootRTC_Source == 0) { OBCBootInfo.BootRTC_Source = 1; goto try_again; } } /* 设置年月日和星期 */ RTC_DateStructure.RTC_Year = 0x14; RTC_DateStructure.RTC_Month = RTC_Month_October; RTC_DateStructure.RTC_Date = 0x23; RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Thursday; RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure); /* 设置时分秒,以及显示格式 */ RTC_TimeStructure.RTC_H12 = RTC_H12_AM; RTC_TimeStructure.RTC_Hours = 0x00; RTC_TimeStructure.RTC_Minutes = 0x00; RTC_TimeStructure.RTC_Seconds = 0x00; RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure); } }
static int MakeDecalProjector( shaderInfo_t *si, vec4_t projection, float distance, int numVerts, bspDrawVert_t **dv ) { int i, j; decalProjector_t *dp; vec3_t xyz; /* dummy check */ if( numVerts != 3 && numVerts != 4 ) return -1; /* limit check */ if( numProjectors >= MAX_PROJECTORS ) { MsgDev( D_WARN, "MAX_PROJECTORS (%d) exceeded, no more decal projectors available.\n", MAX_PROJECTORS ); return -2; } /* create a new projector */ dp = &projectors[ numProjectors ]; Mem_Set( dp, 0, sizeof( *dp )); /* basic setup */ dp->si = si; dp->numPlanes = numVerts + 2; /* make texture matrix */ if( !MakeTextureMatrix( dp, projection, dv[ 0 ], dv[ 1 ], dv[ 2 ] ) ) return -1; /* bound the projector */ ClearBounds( dp->mins, dp->maxs ); for( i = 0; i < numVerts; i++ ) { AddPointToBounds( dv[ i ]->xyz, dp->mins, dp->maxs ); VectorMA( dv[ i ]->xyz, distance, projection, xyz ); AddPointToBounds( xyz, dp->mins, dp->maxs ); } /* make bouding sphere */ VectorAdd( dp->mins, dp->maxs, dp->center ); VectorScale( dp->center, 0.5f, dp->center ); VectorSubtract( dp->maxs, dp->center, xyz ); dp->radius = VectorLength( xyz ); dp->radius2 = dp->radius * dp->radius; /* make the front plane */ if( !PlaneFromPoints( dp->planes[ 0 ], dv[ 0 ]->xyz, dv[ 1 ]->xyz, dv[ 2 ]->xyz ) ) return -1; /* make the back plane */ VectorSubtract( vec3_origin, dp->planes[ 0 ], dp->planes[ 1 ] ); VectorMA( dv[ 0 ]->xyz, distance, projection, xyz ); dp->planes[ 1 ][ 3 ] = DotProduct( xyz, dp->planes[ 1 ] ); /* make the side planes */ for( i = 0; i < numVerts; i++ ) { j = (i + 1) % numVerts; VectorMA( dv[ i ]->xyz, distance, projection, xyz ); if( !PlaneFromPoints( dp->planes[ i + 2 ], dv[ j ]->xyz, dv[ i ]->xyz, xyz ) ) return -1; } /* return ok */ numProjectors++; return numProjectors - 1; }
static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds, winding_t *w ) { int i, j; float d, d2, alpha; winding_t *front, *back; mapDrawSurface_t *ds2; bspDrawVert_t *dv; vec4_t plane; /* dummy check */ if( w->numpoints < 3 ) { FreeWinding( w ); return; } /* offset by entity origin */ for( i = 0; i < w->numpoints; i++ ) VectorAdd( w->p[ i ], entityOrigin, w->p[ i ] ); /* make a plane from the winding */ if( !PlaneFromPoints( plane, w->p[ 0 ], w->p[ 1 ], w->p[ 2 ] ) ) { FreeWinding( w ); return; } /* backface check */ d = DotProduct( dp->planes[ 0 ], plane ); if( d < -0.0001f ) { FreeWinding( w ); return; } /* walk list of planes */ for( i = 0; i < dp->numPlanes; i++ ) { /* chop winding by the plane */ ClipWindingEpsilon( w, dp->planes[ i ], dp->planes[ i ][ 3 ], 0.0625f, &front, &back ); FreeWinding( w ); /* lose the front fragment */ if( front != NULL ) FreeWinding( front ); /* if nothing left in back, then bail */ if( back == NULL ) return; /* reset winding */ w = back; } /* nothing left? */ if( w == NULL || w->numpoints < 3 ) return; /* add to counts */ numDecalSurfaces++; /* make a new surface */ ds2 = AllocDrawSurface( SURFACE_DECAL ); /* set it up */ ds2->entityNum = ds->entityNum; ds2->castShadows = ds->castShadows; ds2->recvShadows = ds->recvShadows; ds2->shaderInfo = dp->si; ds2->fogNum = ds->fogNum; /* why was this -1? */ ds2->lightmapScale = ds->lightmapScale; ds2->numVerts = w->numpoints; ds2->verts = Malloc( ds2->numVerts * sizeof( *ds2->verts ) ); Mem_Set( ds2->verts, 0, ds2->numVerts * sizeof( *ds2->verts ) ); /* set vertexes */ for( i = 0; i < ds2->numVerts; i++ ) { /* get vertex */ dv = &ds2->verts[ i ]; /* set alpha */ d = DotProduct( w->p[ i ], dp->planes[ 0 ] ) - dp->planes[ 0 ][ 3 ]; d2 = DotProduct( w->p[ i ], dp->planes[ 1 ] ) - dp->planes[ 1 ][ 3 ]; alpha = 255.0f * d2 / (d + d2); if( alpha > 255 ) alpha = 255; else if( alpha < 0 ) alpha = 0; /* set misc */ VectorSubtract( w->p[ i ], entityOrigin, dv->xyz ); VectorCopy( plane, dv->normal ); dv->st[ 0 ] = DotProduct( dv->xyz, dp->texMat[ 0 ] ) + dp->texMat[ 0 ][ 3 ]; dv->st[ 1 ] = DotProduct( dv->xyz, dp->texMat[ 1 ] ) + dp->texMat[ 1 ][ 3 ]; /* set color */ for( j = 0; j < MAX_LIGHTMAPS; j++ ) { dv->color[ j ][ 0 ] = 255; dv->color[ j ][ 1 ] = 255; dv->color[ j ][ 2 ] = 255; dv->color[ j ][ 3 ] = alpha; } } }
/* ********************************************************************************************************* * 函 数 名: bsp_InitNorFlash * 功能说明: 配置连接外部NOR Flash的GPIO和FSMC * 形 参: 无 * 返 回 值: 无 ********************************************************************************************************* */ void bsp_InitNorFlash(void) { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; GPIO_InitTypeDef GPIO_InitStructure; uint32_t ChipID; Mem_Set(&GPIO_InitStructure, 0x00, sizeof(GPIO_InitTypeDef)); Mem_Set(&FSMC_NORSRAMInitStructure, 0x00, sizeof(FSMC_NORSRAMInitTypeDef)); Mem_Set(&p, 0x00, sizeof(FSMC_NORSRAMTimingInitTypeDef)); /* 使能GPIO时钟 */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG, ENABLE); /* 使能 FSMC 时钟 */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /* NOR Flash 的 GPIO : PD0/FSMC_D2 PD1/FSMC_D3 PD4/FSMC_NOE PD5/FSMC_NWE PD6/FSMC_NWAIT - 忙信号,配置为GPIO,输入模式,通过软件查询方式判忙 PD8/FSMC_D13 PD9/FSMC_D14 PD10/FSMC_D15 PD11/FSMC_CLE/FSMC_A16 PD12/FSMC_ALE/FSMC_A17 PD13/FSMC_A18 PD14/FSMC_D0 PD15/FSMC_D1 PE3/FSMC_A19 PE4/FSMC_A20 PE5/FSMC_A21 PE6/FSMC_A22 PE7/FSMC_D4 PE8/FSMC_D5 PE9/FSMC_D6 PE10/FSMC_D7 PE11/FSMC_D8 PE12/FSMC_D9 PE13/FSMC_D10 PE14/FSMC_D11 PE15/FSMC_D12 PF0/FSMC_A0 PF1/FSMC_A1 PF2/FSMC_A2 PF3/FSMC_A3 PF4/FSMC_A4 PF5/FSMC_A5 PF12/FSMC_A6 PF13/FSMC_A7 PF14/FSMC_A8 PF15/FSMC_A9 PG0/FSMC_A10 PG1/FSMC_A11 PG2/FSMC_A12 PG3/FSMC_A13 PG4/FSMC_A14 PG5/FSMC_A15 PG9/FSMC_NE2 - 片选信号 */ /* GPIOD configuration */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); /* GPIOE configuration */ GPIO_PinAFConfig(GPIOE, GPIO_PinSource3 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource4 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource5 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11| GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_Init(GPIOE, &GPIO_InitStructure); /* GPIOF configuration */ GPIO_PinAFConfig(GPIOF, GPIO_PinSource0 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource1 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource2 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource3 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource4 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource5 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource12 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource13 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource14 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource15 , GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_Init(GPIOF, &GPIO_InitStructure); /* GPIOG configuration */ GPIO_PinAFConfig(GPIOG, GPIO_PinSource0 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource1 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource2 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource3 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource4 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource5 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource9 , GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_9; GPIO_Init(GPIOG, &GPIO_InitStructure); /* PD6 作为忙信号, 配置为GPIO输入模式,软件查询 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; /* 输入模式 */ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); /*-- FSMC Configuration ------------------------------------------------------*/ p.FSMC_AddressSetupTime = 0x06; /* 0x05正常, 0x04 出错 */ p.FSMC_AddressHoldTime = 0x01; p.FSMC_DataSetupTime = 0x0C; /* 0x0B正常, 0x0A 出错 */ p.FSMC_BusTurnAroundDuration = 0x00; p.FSMC_CLKDivision = 0x00; p.FSMC_DataLatency = 0x00; p.FSMC_AccessMode = FSMC_AccessMode_B; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); /*!< Enable FSMC Bank1_SRAM2 Bank */ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); #if debug_enable ChipID = NOR_ReadID(); if(ChipID == 0x017E0A00) { printf("NorFlash ID = %x, Model = S29JL032H \r\n", ChipID); } #endif }
static void SV_AddEntitiesToPacket( edict_t *pViewEnt, edict_t *pClient, client_frame_t *frame, sv_ents_t *ents, bool portal ) { edict_t *ent; vec3_t origin; byte *pset; sv_client_t *cl; int leafnum, fullvis = false; int e, clientcluster, clientarea; bool force = false; // during an error shutdown message we may need to transmit // the shutdown message after the server has shutdown, so // specfically check for it if( !sv.state ) return; if( pClient && !portal ) { // portals can't change hostflags sv.hostflags &= ~SVF_SKIPLOCALHOST; cl = SV_ClientFromEdict( pClient, true ); Com_Assert( cl == NULL ); // setup hostflags if( com.atoi( Info_ValueForKey( cl->userinfo, "cl_lw" )) == 1 ) sv.hostflags |= SVF_SKIPLOCALHOST; } e = svgame.dllFuncs.pfnSetupVisibility( pViewEnt, pClient, portal, origin ); if( e == 0 ) return; // invalid viewent ? if( e == -1 ) fullvis = true; clientpvs = CM_FatPVS( origin, portal ); leafnum = CM_PointLeafnum( origin ); clientarea = CM_LeafArea( leafnum ); clientcluster = CM_LeafCluster( leafnum ); clientphs = CM_FatPHS( clientcluster, portal ); // calculate the visible areas if( fullvis ) { if( !portal ) Mem_Set( frame->areabits, 0xFF, sizeof( frame->areabits )); frame->areabits_size = sizeof( frame->areabits ); } else frame->areabits_size = CM_WriteAreaBits( frame->areabits, clientarea, portal ); for( e = 1; e < svgame.globals->numEntities; e++ ) { ent = EDICT_NUM( e ); if( ent->free ) continue; if( ent->serialnumber != e ) { // this should never happens MsgDev( D_NOTE, "fixing ent->serialnumber from %i to %i\n", ent->serialnumber, e ); ent->serialnumber = e; } // don't double add an entity through portals (already added) if( ent->pvServerData->framenum == sv.net_framenum ) continue; if( fullvis ) force = true; else force = false; // clear forceflag // NOTE: always add himslef to list if( !portal && ( ent == pClient )) force = true; if( ent->v.flags & FL_PHS_FILTER ) pset = clientphs; else pset = clientpvs; if( !force ) { // run custom user filter if( !svgame.dllFuncs.pfnAddToFullPack( pViewEnt, pClient, ent, sv.hostflags, clientarea, pset )) continue; } SV_AddEntToSnapshot( ent->pvServerData, ent, ents ); // add it if( fullvis ) continue; // portal ents will be added anywhere, ignore recursion // if its a portal entity, add everything visible from its camera position if( !portal && (ent->pvServerData->s.ed_type == ED_PORTAL || ent->pvServerData->s.ed_type == ED_SKYPORTAL)) SV_AddEntitiesToPacket( ent, pClient, frame, ents, true ); } }