///////////////////////////////////////////////////////////////
//
// CClientPerfStatLuaTimingImpl::UpdateLuaTiming
//
//
//
///////////////////////////////////////////////////////////////
void CClientPerfStatLuaTimingImpl::UpdateLuaTiming ( CLuaMain* pLuaMain, const char* szEventName, TIMEUS timeUs )
{
    CLuaMainTiming* pLuaMainTiming = MapFind ( AllLuaTiming.LuaMainTimingMap, pLuaMain );
    if ( !pLuaMainTiming )
    {
        MapSet ( AllLuaTiming.LuaMainTimingMap, pLuaMain, CLuaMainTiming() );
        pLuaMainTiming = MapFind ( AllLuaTiming.LuaMainTimingMap, pLuaMain );
    }

    {
        CTiming& acc = pLuaMainTiming->ResourceTiming.s5.acc;
        acc.total_us += timeUs;
    }

    CTimingBlock* pEventTiming = MapFind ( pLuaMainTiming->EventTimingMap, szEventName );
    if ( !pEventTiming )
    {
        MapSet (pLuaMainTiming->EventTimingMap, szEventName, CTimingBlock() );
        pEventTiming = MapFind ( pLuaMainTiming->EventTimingMap, szEventName );
    }

    {
        CTiming& acc = pEventTiming->s5.acc;
        acc.calls++;
        acc.total_us += timeUs;
        acc.max_us = std::max ( acc.max_us, timeUs );
    }
}
Exemple #2
0
void CEntitySA::SetCollidableWith( CEntity *entity, bool enabled )
{
    CEntitySA *intEnt = dynamic_cast <CEntitySA*> ( entity );

    if ( intEnt == this )
        return;

    // quit if no change
    if ( MapContains( m_disabledColl, intEnt->GetInterface() ) != enabled )
        return;

    if ( enabled )
    {
        MapRemove( m_disabledColl, intEnt->GetInterface() );

        if ( m_disabledColl.empty() )
            MapRemove( pGame->m_disabledColl, this );
    }
    else
    {
        MapSet( m_disabledColl, intEnt->GetInterface(), true );
        MapSet( pGame->m_disabledColl, this, true );
    }

    // Set in the other entity as well
    intEnt->SetCollidableWith( this, enabled );
}
///////////////////////////////////////////////////////////////
//
// CGameEntityXRefManagerImpl::AddEntityXRef
//
// Add a new reference between a game entity and a client entity
//
///////////////////////////////////////////////////////////////
void CGameEntityXRefManagerImpl::AddEntityXRef ( CClientEntity* pEntity, CEntity* pEntitySA )
{
    CEntitySAInterface* pEntitySAInterface = pEntitySA->GetInterface ();

    assert ( !MapContains ( m_ClientToGameMap, pEntity ) );
    assert ( !MapContains ( m_GameToClientMap, pEntitySA ) );
    assert ( !MapContains ( m_InterfaceToClientMap, pEntitySAInterface ) );

    MapSet ( m_ClientToGameMap, pEntity, pEntitySA );
    MapSet ( m_GameToClientMap, pEntitySA, pEntity );
    MapSet ( m_InterfaceToClientMap, pEntitySAInterface, pEntity );
}
////////////////////////////////////////////////////////////////
//
// CEffectClonerImpl::CreateD3DEffect
//
//
//
////////////////////////////////////////////////////////////////
ID3DXEffect* CEffectClonerImpl::CreateD3DEffect ( const SString& strFilename, const SString& strRootPath, SString& strOutStatus, bool bDebug )
{
    // Do we have a match with the initial path
    CEffectTemplate* pEffectTemplate = MapFindRef ( m_ValidMap, ConformPathForSorting ( strFilename ) );
    if ( pEffectTemplate )
    {
        // Have files changed since create?
        if ( pEffectTemplate->HaveFilesChanged () )
        {
            // EffectTemplate is no good for cloning now, so move it to the old list 
            MapRemove ( m_ValidMap, ConformPathForSorting ( strFilename ) );
            m_OldList.push_back ( pEffectTemplate );
            pEffectTemplate = NULL;
        }
    }

    // Need to create new EffectTemplate?
    if ( !pEffectTemplate )
    {
        pEffectTemplate = NewEffectTemplate ( m_pManager, strFilename, strRootPath, strOutStatus, bDebug );
        if ( !pEffectTemplate->IsValid () )
        {
            SAFE_RELEASE( pEffectTemplate );
            return NULL;
        }

        OutputDebugLine ( SString ( "[Shader] CEffectClonerImpl::CreateD3DEffect - New EffectTemplate for %s", *strFilename ) );
        // Add to active map
        MapSet ( m_ValidMap, ConformPathForSorting ( strFilename ), pEffectTemplate );
    }


    //
    // Now we have a valid EffectTemplate to clone the effect from
    //

    // Clone D3DXEffect
    ID3DXEffect* pNewD3DEffect = pEffectTemplate->CloneD3DEffect ( &strOutStatus );

    if( !pNewD3DEffect )
    {
        if ( strOutStatus.empty () )
            strOutStatus = "Error: Clone failed";
        return NULL;
    }

    // Cross ref clone with original
    MapSet ( m_CloneMap, pNewD3DEffect, pEffectTemplate );

    // Return result
    return pNewD3DEffect;
}
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::CDatabaseJobQueueImpl
//
// Init known database types and start the job service thread
//
///////////////////////////////////////////////////////////////
CDatabaseJobQueueImpl::CDatabaseJobQueueImpl ( void )
    : m_uiJobCountWarnThresh ( 200 )
    , m_uiConnectionCountWarnThresh ( 20 )
{
    // Add known database types
    CDatabaseType* pDatabaseTypeSqlite = NewDatabaseTypeSqlite ();
    MapSet ( m_DatabaseTypeMap, pDatabaseTypeSqlite->GetDataSourceTag (), pDatabaseTypeSqlite );

    // Add known database types
    CDatabaseType* pDatabaseTypeMySql = NewDatabaseTypeMySql ();
    MapSet ( m_DatabaseTypeMap, pDatabaseTypeMySql->GetDataSourceTag (), pDatabaseTypeMySql );

    // Start the job queue processing thread
    m_pServiceThreadHandle = new CThreadHandle ( CDatabaseJobQueueImpl::StaticThreadProc, this );
}
Exemple #6
0
void CanMemberInsert(CanMemberStruct *Data, CanMemberInfo *CanMember)
{  unsigned long Uid;
   CanMemberInfo *OldCanMember;

   Uid = CanMemberInfoGetUid(CanMember);
   OldCanMember = (CanMemberInfo *)MapGet(CanMemberGetCanMemberDb(Data),
                                          (MapKeyType)Uid);
   if (OldCanMember != (CanMemberInfo *)NULL)
   {
      CanMemberInfoSetIsInvalid(OldCanMember, FALSE);
      CanMemberInfoSetUid(OldCanMember, CanMemberInfoGetUid(CanMember));
      CanMemberInfoSetVersion(OldCanMember, CanMemberInfoGetVersion(CanMember));
      CanMemberInfoSetType(OldCanMember, CanMemberInfoGetType(CanMember));
   }
   else
   {
      OldCanMember = (CanMemberInfo *)malloc(sizeof(CanMemberInfo));
      if (OldCanMember != (CanMemberInfo *)NULL)
      {
         CanMemberInfoSetIsInvalid(OldCanMember,  FALSE);
         CanMemberInfoSetUid(OldCanMember, CanMemberInfoGetUid(CanMember));
         CanMemberInfoSetVersion(OldCanMember, CanMemberInfoGetVersion(CanMember));
         CanMemberInfoSetType(OldCanMember, CanMemberInfoGetType(CanMember));
         MapSet(CanMemberGetCanMemberDb(Data),
                (MapKeyType)Uid, (MapDataType)OldCanMember);
         CanMemberSetNumMembers(Data, CanMemberGetNumMembers(Data) + 1);
      }
   }
}
Exemple #7
0
//
// CHudSA::InitComponentList
//
void CHudSA::InitComponentList ( void )
{
    SHudComponent componentList[] = {
                { 1, HUD_AMMO, 1, FUNC_DrawAmmo, 1, 0xCC, 0xC3 },
                { 1, HUD_WEAPON, 1, FUNC_DrawWeaponIcon, 1, 0xCC, 0xC3 },
                { 1, HUD_HEALTH, 1, FUNC_PrintHealthForPlayer, 1, 0xCC, 0xC3 },
                { 1, HUD_BREATH, 1, FUNC_PrintBreathForPlayer, 1, 0xCC, 0xC3 },
                { 1, HUD_ARMOUR, 1, FUNC_PrintArmourForPlayer, 1, 0xCC, 0xC3 },
                { 1, HUD_MONEY, 1, CODE_ShowMoney, 2, 0xCCCC, 0xE990 },
                { 1, HUD_VEHICLE_NAME, 1, FUNC_DrawVehicleName, 1, 0xCC, 0xC3 },
                { 1, HUD_AREA_NAME, 1, FUNC_DrawAreaName, 1, 0xCC, 0xC3 },
                { 1, HUD_RADAR, 1, FUNC_DrawRadar, 1, 0xCC, 0xC3 },
                { 1, HUD_CLOCK, 0, VAR_DisableClock, 1, 1, 0 },
                { 1, HUD_RADIO, 1, FUNC_DrawRadioName, 1, 0xCC, 0xC3 },
                { 1, HUD_WANTED, 1, FUNC_DrawWantedLevel, 1, 0xCC, 0xC3 },
                { 1, HUD_CROSSHAIR, 1, FUNC_DrawCrosshair, 1, 0xCC, 0xC3 },
                { 1, HUD_VITAL_STATS, 1, FUNC_DrawVitalStats, 1, 0xCC, 0xC3 },
                { 0, HUD_HELP_TEXT, 1, FUNC_DrawHelpText, 1, 0xCC, 0xC3 },
            };

    for ( uint i = 0 ; i < NUMELMS( componentList ) ; i++ )
    {
        const SHudComponent& component = componentList[i]; 
        MapSet ( m_HudComponentMap, component.type, component );
    }
}
bool CAccessControlListManager::CanObjectUseRight ( const char* szObjectName,
                                                    CAccessControlListGroupObject::EObjectType eObjectType,
                                                    const char* szRightName,
                                                    CAccessControlListRight::ERightType eRightType,
                                                    bool bDefaultAccessRight )
{
    // Clear cache if required
    if ( m_bReadCacheDirty )
        ClearReadCache ();

    // If object is resource, try cache
    if ( eObjectType == CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE )
    {
        // Make unique key for this query
        SString strKey ( "%s %s %d %d", szObjectName, szRightName, eRightType, bDefaultAccessRight );
        // Check if this query has been done before
        bool* pResult = MapFind( m_ReadCacheMap, strKey );
        if ( !pResult )
        {
            // If not, do query now and add result to the cache
            bool bResult = InternalCanObjectUseRight ( szObjectName, eObjectType, szRightName, eRightType, bDefaultAccessRight );
            MapSet ( m_ReadCacheMap, strKey, bResult );
            pResult = MapFind( m_ReadCacheMap, strKey );
        }
        // Return cached result
        return *pResult;
    }
    return InternalCanObjectUseRight ( szObjectName, eObjectType, szRightName, eRightType, bDefaultAccessRight );
}
Exemple #9
0
void CPlayer::MovePlayerToFarList ( CPlayer* pOther )
{
    dassert ( MapContains ( m_NearPlayerList, pOther ) && !MapContains ( m_FarPlayerList, pOther ) );
    SNearInfo* pInfo = MapFind ( m_NearPlayerList, pOther );
    MapSet ( m_FarPlayerList, pOther, *pInfo );
    MapRemove ( m_NearPlayerList, pOther );
}
Exemple #10
0
void LokInsert(LokStruct *Data, LokInfo *Lok)
{  char *Name;
   LokInfo *OldLok;

   Name = LokInfoGetName(Lok);
   if (strlen(Name) > 0)
   {
      OldLok = (LokInfo *)MapGet(LokGetLokDb(Data), (MapKeyType)Name);
      if (OldLok != (LokInfo *)NULL)
      {
         if (!LokIsEqual(OldLok, Lok))
         {
            LokSetIsChanged(Data, TRUE);
            memcpy(OldLok, Lok, sizeof(LokInfo));
         }
         LokInfoSetIsDeleted(OldLok, FALSE);
      }
      else
      {
         OldLok = (LokInfo *)malloc(sizeof(LokInfo));
         if (OldLok != (LokInfo *)NULL)
         {
            LokSetIsChanged(Data, TRUE);
            memcpy(OldLok, Lok, sizeof(LokInfo));
            LokInfoSetIsDeleted(OldLok, FALSE);
            MapSet(LokGetLokDb(Data),
                   (MapKeyType)LokInfoGetName(OldLok),
                   (MapDataType)OldLok);
            LokSetNumLoks(Data, LokGetNumLoks(Data) + 1);
         }
      }
   }
}
//
// CFunctionUseLogger::OnFunctionUse
//
void CFunctionUseLogger::OnFunctionUse( lua_State* luaVM, const char* szFunctionName, const char* szArgs, uint uiArgsSize )
{
    if ( m_strLogFilename.empty() )
        return;

    CResource* pResource = g_pGame->GetResourceManager()->GetResourceFromLuaState( luaVM );
    SString strResourceName = pResource ? pResource->GetName() : "Unknown";

    SString strKey( "%s-%s", szFunctionName, *strResourceName );

    SFuncCallRecord* pItem = MapFind( m_FuncCallRecordMap, strKey );
    if ( !pItem )
    {
        // Create new entry for this resource/function combo
        MapSet( m_FuncCallRecordMap, strKey, SFuncCallRecord() );
        pItem = MapFind( m_FuncCallRecordMap, strKey );
        pItem->strFunctionName = szFunctionName;
        pItem->strResourceName = strResourceName;
        pItem->uiCallCount = 0;
        pItem->timeFirstUsed = CTickCount::Now();
    }
    pItem->uiCallCount++;

    if ( pItem->strExampleArgs.empty() )
        pItem->strExampleArgs = SStringX( szArgs ).Left( 40 );
}
/////////////////////////////////////////////////////////////
//
// CProxyDirect3DVertexDeclaration::CProxyDirect3DVertexDeclaration
//
//
//
/////////////////////////////////////////////////////////////
CProxyDirect3DVertexDeclaration::CProxyDirect3DVertexDeclaration ( IDirect3DDevice9* InD3DDevice9,IDirect3DVertexDeclaration9* pOriginal, CONST D3DVERTEXELEMENT9* pVertexElements )
{
	m_pOriginal = pOriginal;

    CProxyDirect3DDevice9::SD3DVertexDeclState info;

    // Calc and cache info
    for ( uint i = 0 ; i < MAXD3DDECLLENGTH ; i++ )
    {
        const D3DVERTEXELEMENT9& element = pVertexElements[ i ];
        if ( element.Stream == 0xFF )
            break;

        switch ( element.Stream)
        {
            case 0:        info.bUsesStreamAtIndex[0] = true;  break;
            case 1:        info.bUsesStreamAtIndex[1] = true;  break;
        }

        switch ( element.Usage + element.UsageIndex * 16 )
        {
            case D3DDECLUSAGE_POSITION:         info.Position = 1;   break;
            case D3DDECLUSAGE_POSITIONT:        info.PositionT = 1;  break;
            case D3DDECLUSAGE_NORMAL:           info.Normal = 1;     break;
            case D3DDECLUSAGE_COLOR:            info.Color0 = 1;     break;
            case D3DDECLUSAGE_COLOR + 16:       info.Color1 = 1;     break;
            case D3DDECLUSAGE_TEXCOORD:         info.TexCoord0 = 1;  break;
            case D3DDECLUSAGE_TEXCOORD + 16:    info.TexCoord1 = 1;  break;
        }
    }

    // Add to cached info map
    MapSet ( g_pProxyDevice->m_VertexDeclMap, this, info );
}
Exemple #13
0
// Return true if data was changed
bool CAccount::SetData(const std::string& strKey, const std::string& strValue, int iType)
{
    if (strValue == "false" && iType == LUA_TBOOLEAN)
    {
        if (HasData(strKey))
        {
            RemoveData(strKey);
            return true;
        }
    }
    else
    {
        CAccountData* pData = GetDataPointer(strKey);

        if (pData)
        {
            if (pData->GetType() != iType || pData->GetStrValue() != strValue)
            {
                pData->SetStrValue(strValue);
                pData->SetType(iType);
                return true;
            }
        }
        else
        {
            MapSet(m_Data, strKey, CAccountData(strKey, strValue, iType));
            return true;
        }
    }
    return false;
}
Exemple #14
0
void GleisbildInsert(GleisbildStruct *Data, GleisbildInfo *Gleisbild)
{  int Id;
   GleisbildInfo *OldGleisbild;

   Id = GleisbildInfoGetId(Gleisbild);
   OldGleisbild = (GleisbildInfo *)MapGet(GleisbildGetGleisbildDb(Data),
                                          (MapKeyType)Id);
   if (OldGleisbild != (GleisbildInfo *)NULL)
   {
      GleisbildInfoSetId(OldGleisbild, GleisbildInfoGetId(Gleisbild));
      GleisbildInfoSetName(OldGleisbild, GleisbildInfoGetName(Gleisbild));
      GleisbildInfoSetZustand(OldGleisbild, GleisbildInfoGetZustand(Gleisbild));
   }
   else
   {
      OldGleisbild = (GleisbildInfo *)malloc(sizeof(GleisbildInfo));
      if (OldGleisbild != (GleisbildInfo *)NULL)
      {
         GleisbildInfoSetId(OldGleisbild, GleisbildInfoGetId(Gleisbild));
         GleisbildInfoSetName(OldGleisbild, GleisbildInfoGetName(Gleisbild));
         GleisbildInfoSetZustand(OldGleisbild,
	                         GleisbildInfoGetZustand(Gleisbild));
         MapSet(GleisbildGetGleisbildDb(Data),
                (MapKeyType)Id, (MapDataType)OldGleisbild);
      }
   }
}
///////////////////////////////////////////////////////////////
//
// CServerIdManagerImpl::LoadServerIdMap
//
// Load server id data from xml file
//
///////////////////////////////////////////////////////////////
bool CServerIdManagerImpl::LoadServerIdMap ( void )
{
    // Load config XML file
    CXMLFile* pConfigFile = g_pCore->GetXML ()->CreateXML ( PathJoin ( g_pClientGame->GetFileCacheRoot(), MTA_SERVERID_LOOKUP_XML ) );
    if ( !pConfigFile )
        return false;
    pConfigFile->Parse ();

    CXMLNode* pRoot = pConfigFile->GetRootNode ();
    if ( !pRoot )
        pRoot = pConfigFile->CreateRootNode ( "root" );

    m_ServerIdMap.clear ();

    // Read each node
    for ( uint i = 0 ; i < pRoot->GetSubNodeCount () ; i++ )
    {
        CXMLNode* pSubNode = pRoot->GetSubNode ( i );

        CServerIdKey key;
        CServerIdInfo info;
        key.strId = pSubNode->GetTagContent ();
        if ( CXMLAttribute* pAttribute = pSubNode->GetAttributes().Find ( "dir" ) )
            info.strDir = pAttribute->GetValue ();

        if ( !info.strDir.empty () )
            MapSet ( m_ServerIdMap, key, info );
    }

    // Maybe one day remove unwanted directories

    delete pConfigFile;
    return true;
}
Exemple #16
0
// Custom Lua stack argument->reference function
CLuaFunctionRef luaM_toref ( lua_State *luaVM, int iArgument )
{
    CLuaMain* pLuaMain = g_pGame->GetLuaManager ()->GetVirtualMachine ( luaVM );
    assert ( pLuaMain );

    const void* pFuncPtr = lua_topointer ( luaVM, iArgument );

    if ( CRefInfo* pInfo = MapFind ( pLuaMain->m_CallbackTable, pFuncPtr ) )
    {
        // Re-use the lua ref we already have to this function
        pInfo->ulUseCount++;
        return CLuaFunctionRef ( luaVM, pInfo->iFunction, pFuncPtr );
    }
    else
    {
        // Get a lua ref to this function
        lua_settop ( luaVM, iArgument );
        int ref = lua_ref ( luaVM, 1 );

        // Save ref info
        CRefInfo info;
        info.ulUseCount = 1;
        info.iFunction = ref;
        MapSet ( pLuaMain->m_CallbackTable, pFuncPtr, info );

        return CLuaFunctionRef ( luaVM, ref, pFuncPtr );
    }
}
////////////////////////////////////////////////////////////////
//
// CRenderWareSA::CreateTexInfo
//
//
//
////////////////////////////////////////////////////////////////
STexInfo* CRenderWareSA::CreateTexInfo ( ushort usTxdId, const SString& strTextureName, CD3DDUMMY* pD3DData )
{
    // Create texinfo
    m_TexInfoList.push_back ( STexInfo ( usTxdId, strTextureName, pD3DData ) );
    STexInfo* pTexInfo = &m_TexInfoList.back ();

    // Add to lookup maps
    SString strUniqueKey ( "%d_%s", pTexInfo->usTxdId, *pTexInfo->strTextureName );
    if ( MapContains ( m_UniqueTexInfoMap, strUniqueKey ) )
        AddReportLog ( 5132, SString ( "CreateTexInfo duplicate %s", *strUniqueKey ) );
    MapSet ( m_UniqueTexInfoMap, strUniqueKey, pTexInfo );

	// This assert fails when using engine txd replace functions - TODO find out why
    //assert ( !MapContains ( m_D3DDataTexInfoMap, pTexInfo->pD3DData ) );
    MapSet ( m_D3DDataTexInfoMap, pTexInfo->pD3DData, pTexInfo );
    return pTexInfo;
}
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::GetNextJobHandle
//
// Return a new job data object
//
///////////////////////////////////////////////////////////////
CDbJobData* CDatabaseJobQueueImpl::GetNewJobData ( void )
{
    g_pStats->iDbJobDataCount++;
    CDbJobData* pJobData = new CDbJobData ();
    assert ( !MapContains ( m_ActiveJobHandles, pJobData->GetId () ) );
    MapSet ( m_ActiveJobHandles, pJobData->GetId (), pJobData );
    return pJobData;
}
Exemple #19
0
void CPlayer::MovePlayerToNearList ( CPlayer* pOther )
{
    OutputDebugLine ( SString ( "[Sync] ++ %s: Move %s to nearlist", GetNick (), pOther->GetNick () ) );

    dassert ( !MapContains ( m_NearPlayerList, pOther ) && MapContains ( m_FarPlayerList, pOther ) );
    SViewerInfo* pInfo = MapFind ( m_FarPlayerList, pOther );
    MapSet ( m_NearPlayerList, pOther, *pInfo );
    MapRemove ( m_FarPlayerList, pOther );
}
Exemple #20
0
///////////////////////////////////////////////////////////////
//
// CSpatialDatabaseImpl::FlushUpdateQueue
//
// Process all entities that have changed since the last call
//
///////////////////////////////////////////////////////////////
void CSpatialDatabaseImpl::FlushUpdateQueue ( void )
{
    int iTotalUpdated = 0;

    for ( std::map < CElement*, int >::iterator it = m_UpdateQueue.begin (); it != m_UpdateQueue.end (); ++it )
    {
        CElement* pEntity = it->first;

        // Get the new bounding box
        SEntityInfo newInfo;
        CSphere sphere = pEntity->GetWorldBoundingSphere ();
        newInfo.box = CBox ( sphere.vecPosition, fabsf ( sphere.fRadius ) );
        // Make everything 2D for now
        newInfo.box.vecMin.fZ = SPATIAL_2D_Z;
        newInfo.box.vecMax.fZ = SPATIAL_2D_Z;

        // Get previous info
        if ( SEntityInfo* pOldInfo = MapFind ( m_InfoMap, pEntity ) )
        {
            // Don't update if bounding box is the same
            if ( pOldInfo->box == newInfo.box )
                continue;

            // Remove old bounding box from tree
            m_Tree.Remove ( &pOldInfo->box.vecMin.fX, &pOldInfo->box.vecMax.fX, pEntity );
        }

        if ( !IsValidSphere ( sphere ) )
            continue;

        // Add new bounding box
        m_Tree.Insert( &newInfo.box.vecMin.fX, &newInfo.box.vecMax.fX, pEntity );

        // Update info map
        MapSet ( m_InfoMap, pEntity, newInfo );
        iTotalUpdated++;
#ifdef SPATIAL_DATABASE_DEBUG_OUTPUTA
        OutputDebugLine ( SString ( "SpatialDatabase::UpdateEntity %08x  %2.0f,%2.0f,%2.0f   %2.0f,%2.0f,%2.0f"
                                    ,pEntity
                                    ,info.box.vecMin.fX
                                    ,info.box.vecMin.fY
                                    ,info.box.vecMin.fZ
                                    ,info.box.vecMax.fX
                                    ,info.box.vecMax.fY
                                    ,info.box.vecMax.fZ
                                  ) );
#endif
    }
    m_UpdateQueue.clear ();

#ifdef SPATIAL_DATABASE_DEBUG_OUTPUTB
    int iTotalToUpdate = m_UpdateQueue.size ();
    if ( iTotalToUpdate )
        OutputDebugLine ( SString ( "SpatialDatabase::FlushUpdateQueue  TotalToUpdate: %d   TotalUpdated: %d  m_InfoMap: %d    tree: %d  ", iTotalToUpdate, iTotalUpdated, m_InfoMap.size (), m_Tree.Count () ) );
#endif
}
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::ProcessConnect
//
//
//
///////////////////////////////////////////////////////////////
void CDatabaseJobQueueImpl::ProcessConnect ( CDbJobData* pJobData )
{
    // Determine which type manager to use
    std::vector < SString > parts;
    pJobData->command.strData.Split ( "\1", parts );
    if ( parts.size () < 5 )
    {
        pJobData->result.status = EJobResult::FAIL;
        pJobData->result.strReason = "Internal Error (JobQueueServer:ProcessConnect #1)";
        return;
    }

    CDatabaseType* pTypeManager = MapFindRef ( m_DatabaseTypeMap, parts[0] );
    if ( !pTypeManager )
    {
        pJobData->result.status = EJobResult::FAIL;
        pJobData->result.strReason = "Not valid type";
        return;
    }

    // Get type manager to return a CDatabaseConnection*
    CDatabaseConnection* pConnection = pTypeManager->Connect ( parts[1], parts[2], parts[3], parts[4] );
    if ( !pConnection )
    {
        pJobData->result.status = EJobResult::FAIL;
        pJobData->result.strReason = "Could not connect";
        return;
    }

    if ( !pConnection->IsValid () )
    {
        pJobData->result.status = EJobResult::FAIL;
        pJobData->result.strReason = pConnection->GetLastErrorMessage ();
        pConnection->Release ();
        return;
    }

    // Extract some options
    GetOption < CDbOptionsMap > ( parts[4], "log", pConnection->m_bLoggingEnabled, 0 );
    GetOption < CDbOptionsMap > ( parts[4], "tag", pConnection->m_strLogTag );
    GetOption < CDbOptionsMap > ( parts[4], "suppress", ",", pConnection->m_SuppressedErrorCodes );

    // Only allow error codes to be suppress with mysql, as sqlite only has one error code
    if ( pTypeManager->GetDataSourceTag () != "mysql" )
        pConnection->m_SuppressedErrorCodes.clear ();

    // Associate handle with CDatabaseConnection*
    shared.m_Mutex.Lock();
    MapSet( shared.m_HandleConnectionMap, pJobData->command.connectionHandle, pConnection );
    shared.m_Mutex.Unlock();

    // Set result
    pJobData->result.status = EJobResult::SUCCESS;
}
///////////////////////////////////////////////////////////////
//
// CClientModelCacheManagerImpl::InsertIntoNeedCacheList
//
// Update model id closest distance
//
///////////////////////////////////////////////////////////////
void CClientModelCacheManagerImpl::InsertIntoNeedCacheList(std::map<ushort, float>& outNeedCacheList, ushort usModelId, float fDistSq)
{
    float* pfDistSqCurrent = MapFind(outNeedCacheList, usModelId);
    if (!pfDistSqCurrent)
    {
        MapSet(outNeedCacheList, usModelId, fDistSq);
        return;
    }
    if (fDistSq < *pfDistSqCurrent)
        *pfDistSqCurrent = fDistSq;
}
Exemple #23
0
void ConfigAddStrVal(ConfigStruct *Data, CfgStrValues ValueTyp, char *Value)
{  char *p;
   IniValue *ValuePtr;

   switch (ValueTyp)
   {
      case CfgIfaceVal:
         p = INI_STR_IFACE;
         break;
      case CfgAddrVal:
         p = INI_STR_ADDRESS;
         break;
      case CfgCanIfVal:
         p = INI_STR_CAN_IFACE;
         break;
      case CfgPathVal:
         p = INI_STR_CS2_PATH;
         break;
      case CfgUdpBcVal:
         p = INI_STR_UDP_BC;
         break;
      case CfgStartVal:
         p = INI_STR_START;
         break;
      case CfgWakeUpS88:
         p = INI_STR_WAKEUP_S88;
         break;
      case CfgGpioS88:
         p = INI_STR_GPIO_S88;
         break;
      case CfgHideMs2Val:
         p = INI_STR_HIDE_MS2;
         break;
      case CfgSerialLineVal:
         p = INI_STR_SERIAL_LINE;
         break;
   }
   ValuePtr = (IniValue *)MapGet(ConfigGetConfig(Data), (MapKeyType)p);
   if (ValuePtr == (IniValue *)NULL)
   {
      ValuePtr = malloc(sizeof(IniValue));
      ValuePtr->DataType = IniParsString;
      ValuePtr->IntValue = 0;
      strcpy(ValuePtr->StringValue, Value);
      MapSet(ConfigGetConfig(Data), (MapKeyType)strdup(p),
             (MapDataType)ValuePtr);
   }
   else
   {
      ValuePtr->DataType = IniParsString;
      ValuePtr->IntValue = 0;
      strcpy(ValuePtr->StringValue, Value);
   }
}
///////////////////////////////////////////////////////////////
//
// CResourceChecker::CheckVersionRequirements
//
// Update m_strReqClientVersion or m_strReqServerVersion with the version requirement for the
// supplied identifier
//
///////////////////////////////////////////////////////////////
void CResourceChecker::CheckVersionRequirements ( const string& strIdentifierName, bool bClientScript )
{
//    if ( MTASA_VERSION_TYPE < VERSION_TYPE_RELEASE )
//        return;

    static CHashMap < SString, SString > clientFunctionMap;
    static CHashMap < SString, SString > serverFunctionMap;

    // Check if lookup maps need initializing
    if ( clientFunctionMap.empty () )
    {
        for ( uint i = 0 ; i < NUMELMS( clientFunctionInitList ) ; i++ )
            MapSet ( clientFunctionMap, clientFunctionInitList[i].functionName, clientFunctionInitList[i].minMtaVersion );

        for ( uint i = 0 ; i < NUMELMS( serverFunctionInitList ) ; i++ )
            MapSet ( serverFunctionMap, serverFunctionInitList[i].functionName, serverFunctionInitList[i].minMtaVersion );
    }

    // Select client or server check
    const CHashMap < SString, SString >& functionMap = bClientScript ? clientFunctionMap : serverFunctionMap;
    SString& strReqMtaVersion                        = bClientScript ? m_strReqClientVersion : m_strReqServerVersion;
    SString& strReqMtaReason                         = bClientScript ? m_strReqClientReason : m_strReqServerReason;

    const SString* pResult = MapFind ( functionMap, strIdentifierName );
    if ( pResult )
    {
        // This identifier has a version requirement
        const SString& strResult = *pResult;

        // Is the new requirement relevant for this MTA generation
        if ( strResult > CStaticFunctionDefinitions::GetVersionSortable ().Left ( 3 ) )
        {
            // Is the new requirement higher than the current?
            if ( strResult > strReqMtaVersion )
            {
                strReqMtaVersion = strResult;
                strReqMtaReason = strIdentifierName;
            }
        }
    }
}
Exemple #25
0
const SBindableKey* CKeyBinds::GetBindableFromKey ( const char* szKey )
{
    // Map for faster lookup
    static std::map < SString, const SBindableKey* > bindableKeyMap;

    // Init map if required
    if ( bindableKeyMap.empty () )
        for ( int i = 0 ; *g_bkKeys [ i ].szKey != 0 ; i++ )
            MapSet ( bindableKeyMap, SStringX ( g_bkKeys [ i ].szKey ).ToLower (), &g_bkKeys [ i ] );

    return MapFindRef ( bindableKeyMap, SStringX ( szKey ).ToLower () );
}
///////////////////////////////////////////////////////////////
//
// CCrashDumpWriter::OnCrashAverted
//
// Static function. Called everytime a crash is averted
//
///////////////////////////////////////////////////////////////
void CCrashDumpWriter::OnCrashAverted ( uint uiId )
{
    SCrashAvertedInfo* pInfo = MapFind ( ms_CrashAvertedMap, uiId );
    if ( !pInfo )
    {
        MapSet ( ms_CrashAvertedMap, uiId, SCrashAvertedInfo () );
        pInfo = MapFind ( ms_CrashAvertedMap, uiId );
        pInfo->uiUsageCount = 0;
    }
    pInfo->uiTickCount = GetTickCount32 ();
    pInfo->uiUsageCount++;
}
Exemple #27
0
const SBindableGTAControl* CKeyBinds::GetBindableFromControl ( const char* szControl )
{
    // Map for faster lookup
    static std::map < SString, const SBindableGTAControl* > bindableControlMap;

    // Init map if required
    if ( bindableControlMap.empty () )
        for ( int i = 0 ; *g_bcControls [ i ].szControl != 0 ; i++ )
            MapSet ( bindableControlMap, SStringX ( g_bcControls [ i ].szControl ).ToLower (), &g_bcControls [ i ] );

    return MapFindRef ( bindableControlMap, SStringX ( szControl ).ToLower () );
}
///////////////////////////////////////////////////////////////
//
// CPerfStatLibMemoryImpl::UpdateLibMemory
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatLibMemoryImpl::UpdateLibMemory ( const SString& strLibName, int iMemUsed, int iMemUsedMax )
{
    CLibMemory* pLibMemory = MapFind ( AllLibMemory.LibMemoryMap, strLibName );
    if ( !pLibMemory )
    {
        MapSet ( AllLibMemory.LibMemoryMap, strLibName, CLibMemory() );
        pLibMemory = MapFind ( AllLibMemory.LibMemoryMap, strLibName );
    }

    pLibMemory->Delta += iMemUsed - pLibMemory->Current;
    pLibMemory->Current = iMemUsed;
    pLibMemory->Max = Max ( pLibMemory->Max, iMemUsedMax );
}
Exemple #29
0
///////////////////////////////////////////////////////////////
//
// CLuaMain::GetFunctionTag
//
// Turn iFunctionNumber into something human readable
//
///////////////////////////////////////////////////////////////
const SString& CLuaMain::GetFunctionTag ( int iLuaFunction )
{
    // Find existing
    SString* pTag = MapFind ( m_FunctionTagMap, iLuaFunction );
#ifndef CHECK_FUNCTION_TAG
    if ( !pTag )
#endif
    {
        // Create if required
        SString strText;

        lua_Debug debugInfo;
        lua_getref ( m_luaVM, iLuaFunction );
        if ( lua_getinfo( m_luaVM, ">nlS", &debugInfo ) )
        {
            // Make sure this function isn't defined in a string
            if ( debugInfo.source[0] == '@' )
            {
                //std::string strFilename2 = ConformResourcePath ( debugInfo.source );
                SString strFilename = debugInfo.source;

                int iPos = strFilename.find_last_of ( "/\\" );
                if ( iPos >= 0 )
                    strFilename = strFilename.substr ( iPos + 1 );

                strText = SString ( "@%s:%d", strFilename.c_str (), debugInfo.currentline != -1 ? debugInfo.currentline : debugInfo.linedefined, iLuaFunction );
            }
            else
            {
                strText = SString ( "@func_%d %s", iLuaFunction, debugInfo.short_src );
            }
        }
        else
        {
            strText = SString ( "@func_%d NULL", iLuaFunction );
        }

    #ifdef CHECK_FUNCTION_TAG
        if ( pTag )
        {
            // Check tag remains unchanged
            assert ( strText == *pTag );
            return *pTag;
        }
    #endif

        MapSet ( m_FunctionTagMap, iLuaFunction, strText );
        pTag = MapFind ( m_FunctionTagMap, iLuaFunction );
    }
    return *pTag;
}
///////////////////////////////////////////////////////////////
//
// CServerIdManagerImpl::GetServerIdInfo
//
//
//
///////////////////////////////////////////////////////////////
const CServerIdInfo& CServerIdManagerImpl::GetServerIdInfo ( const SString& strServerId )
{
    // Find
    CServerIdKey findKey;
    findKey.strId = strServerId;
    CServerIdInfo* pInfo = MapFind ( m_ServerIdMap, findKey );
    if ( !pInfo )
    {
        // Add if missing

        // Use part of serverid for directory name
        SString strDir = strServerId.Left ( 6 );

        // Ensure the item does not exist in the map
        bool bAgain = true;
        while ( bAgain )
        {
            bAgain = false;
            for ( std::map < CServerIdKey, CServerIdInfo >::iterator it = m_ServerIdMap.begin () ; it != m_ServerIdMap.end () ; ++it )
            {
                const CServerIdInfo& info = it->second;
                if ( strDir == info.strDir )
                {
                    strDir = IncrementCounter ( strDir );
                    bAgain = true;
                    break;
                }
            }
        }

        // Ensure the directory does not exist
        while ( DirectoryExists ( PathJoin ( m_strServerIdLookupBaseDir, strDir ) ) )
        {
            strDir = IncrementCounter ( strDir );
        }

        // Add new item
        {
            CServerIdInfo info;
            info.strDir = strDir;
            MapSet ( m_ServerIdMap, findKey, info );

            m_bListChanged = true;
            SaveServerIdMap ();
        }

        pInfo = MapFind ( m_ServerIdMap, findKey ); 
    }

    return *pInfo;
}