Example #1
0
void VUMeter::drawBar(QPainter *painter)
{
    painter->save();

    QLinearGradient linGrad(50, 0, 50, 500);
    linGrad.setColorAt(0, colorHigh);
    linGrad.setColorAt(1, colorLow);
    linGrad.setSpread(QGradient::PadSpread);
    painter->setBrush(linGrad);

    //绘制柱状条
    QRectF bar3(20, 50, 25, 450);
    painter->drawRect(bar3);
    QRectF bar4(55, 50, 25, 450);
    painter->drawRect(bar4);

    //绘制柱状背景
    painter->setBrush(QColor(40, 40, 40));

    double length = 450.0;
    double leftBar = abs(length * (minValue - leftValue) / (maxValue - minValue));
    double rightBar = abs(length * (minValue - rightValue) / (maxValue - minValue));
    QRectF bar1(20, 50, 25, 450 - leftBar);
    painter->drawRect(bar1);
    QRectF bar2(55, 50, 25, 450 - rightBar);
    painter->drawRect(bar2);

    painter->setPen(QPen(Qt::black, 2));
    for (int i = 0; i <= 60; i++) {
        painter->drawLine(21, 500 - 450 * i / 60, 44, 500 - 450 * i / 60);
        painter->drawLine(56, 500 - 450 * i / 60, 79, 500 - 450 * i / 60);
    }

    painter->restore();
}
Example #2
0
void
foo3 ()
{
  void bar3 (L);
  H a1 { 5 };		// { dg-error "invalid conversion from 'int' to 'A'" }
  I b1 { 7 };		// { dg-error "invalid conversion from 'int' to 'B'" "" { target c++14_down } }
  J c1 { s };
  K d1 { K(t) };	// { dg-error "invalid cast from type 'T' to type 'D'" }
  K d2 { t };		// { dg-error "cannot convert 'T' to 'D' in initialization" "" { target c++14_down } }
			// { dg-error "invalid cast from type 'T' to type 'D'" "" { target c++17 } .-1 }
  K d3 { 9 };		// { dg-error "cannot convert 'int' to 'D' in initialization" "" { target c++14_down } }
  K d4 { l };		// { dg-error "cannot convert 'long int' to 'D' in initialization" "" { target c++14_down } }
  K d5 { K(l) };
  K d6 { G };		// { dg-error "cannot convert 'A' to 'D' in initialization" "" { target c++14_down } }
  L e1 { 5 };		// { dg-error "cannot convert 'int' to 'E' in initialization" "" { target c++14_down } }
  L e2 { -1 };		// { dg-error "cannot convert 'int' to 'E' in initialization" "" { target c++14_down } }
			// { dg-error "narrowing conversion of '-1' from 'int' to 'unsigned char' inside" "" { target c++17 } .-1 }
  L e3 { 5.0 };		// { dg-error "cannot convert 'double' to 'E' in initialization" "" { target c++14_down } }
			// { dg-error "narrowing conversion of '5.0e.0' from 'double' to 'unsigned char' inside" "" { target c++17 } .-1 }
  L e4 { 5.2 };		// { dg-error "cannot convert 'double' to 'E' in initialization" "" { target c++14_down } }
			// { dg-error "narrowing conversion of '5.\[0-9]*e.0' from 'double' to 'unsigned char' inside" "" { target c++17 } .-1 }
  I b2 = { 7 };		// { dg-error "invalid conversion from 'int' to 'B'" }
  J c2 = { J { 8 } };	// { dg-error "cannot convert 'int' to 'C' in initialization" "" { target c++14_down } }
  K *d7 = new K { 9 };	// { dg-error "cannot convert \[^\n\r]* to 'D' in initialization" "" { target c++14_down } }
  L *e5 = new L { -4 };	// { dg-error "cannot convert \[^\n\r]* to 'E' in initialization" "" { target c++14_down } }
			// { dg-error "narrowing conversion of '-4' from 'int' to 'unsigned char' inside" "" { target c++17 } .-1 }
  bar3 ({ 10 });	// { dg-error "cannot convert \[^\n\r]* to 'E' for argument" }
  bar3 (E { 9 });	// { dg-error "cannot convert 'int' to 'E' in initialization" "" { target c++14_down } }
  M v1 = { { 11 } };	// { dg-error "braces around scalar initializer for type 'E'" }
  M v2 = { L { 12 } };	// { dg-error "cannot convert 'int' to 'E' in initialization" "" { target c++14_down } }
  M v3 = { L { 5.0 } };	// { dg-error "cannot convert 'double' to 'E' in initialization" "" { target c++14_down } }
			// { dg-error "narrowing conversion of '5.0e.0' from 'double' to 'unsigned char' inside" "" { target c++17 } .-1 }
  M v4 = { 13 };	// { dg-error "cannot convert 'int' to 'E' in initialization" }
  if (I b3 { 5 })	// { dg-error "invalid conversion from 'int' to 'B'" "" { target c++14_down } }
    ;
  if (I b4 { 4.0 })	// { dg-error "cannot convert 'double' to 'B' in initialization" "" { target c++14_down } }
    ;			// { dg-error "narrowing conversion of '4.0e.0' from 'double' to 'short int' inside" "" { target c++17 } .-1 }
  J c3 { 8L };		// { dg-error "cannot convert 'long int' to 'C' in initialization" "" { target c++14_down } }
  I b4 {short (c + 5)};	// { dg-error "invalid conversion from 'short int' to 'B'" "" { target c++14_down } }
  I b5 {c + 5};		// { dg-error "invalid conversion from 'int' to 'B'" "" { target c++14_down } }
			// { dg-error "narrowing conversion of \[^\n\r]* from 'int' to 'short int' inside" "" { target c++17 } .-1 }
  J c4 { ll };		// { dg-error "cannot convert 'long long int' to 'C' in initialization" "" { target c++14_down } }
			// { dg-error "narrowing conversion of 'll' from 'long long int' to 'int' inside" "" { target c++17 } .-1 }
  J c5 {short (c + 5)};	// { dg-error "cannot convert 'short int' to 'C' in initialization" "" { target c++14_down } }
  J c6 {c + 5};		// { dg-error "cannot convert 'int' to 'C' in initialization" "" { target c++14_down } }
}
Example #3
0
int main()
{
  Foo foo;
  fprintf(stderr, "Foo::add(2,4) = %d\n" ,bar1(2,4, &foo, &Foo::add));
  fprintf(stderr, "Foo::mult(3,5) = %d\n", bar2(3,5, &foo, &Foo::mult));
  fprintf(stderr, "Foo::negate(6) = %d\n" , bar3(6, &Foo::negate));
  return 0;
}
Example #4
0
int
main (void)
{
    struct S
        a = { 3 },
    b = { 6 },
    c = { 9 };

    return bar3 (b, a, c);
}
Example #5
0
int
main (void)
{
  struct S a = { 3, 4, 5 }, b = { 6, 7, 8 }, c = { 9, 10, 11 };

  bar2 (b, a);
  bar3 (b, a, c);
  baz3 (c, a, b);
  return 0;
}
Example #6
0
File: main.cpp Project: CCJY/coliru
int main () {

  int x = 1;

  //Bar bar0(Foo0(x), Foo1(x), Foo2(x)); // Does not work: conflicting declaration ‘Foo1 x’ previous declaration as ‘Foo0 x’; conflicting declaration ‘Foo2 x’ previous declaration as ‘Foo0 x’
  //Bar bar1(Foo0{x}, Foo1(x), Foo2(x)); // Works WTF
  //Bar bar2(Foo0(x), Foo1{x}, Foo2(x)); // Works WTF
  Bar bar3(Foo0(x), Foo1(x), Foo2{x}); // Does not work: conflicting declaration ‘Foo1 x’ previous declaration as ‘Foo0 x’
  //Bar bar4(Foo0{x}, Foo1{x}, Foo2{x}); // Works totally makes sens to me

  //x.doStuff(); //Dose not work. This makes sens to me. But in the context its curious though.
}
void
testTortureExecute (void)
{
#if 0
  struct S a = { 3, 4, 5 }, b = { 6, 7, 8 }, c = { 9, 10, 11 };

  bar2 (b, a);
  bar3 (b, a, c);
  baz3 (c, a, b);
  return;
#endif
}
Example #8
0
int main(){
	
	int n;
	
	/// Example 1 ///

	n = 100;
	ProgressBar *bar1 = new ProgressBar(n, "Example 1");
	
	for(int i=0;i<=n;++i){
		bar1->Progressed(i);
        std::this_thread::sleep_for (std::chrono::milliseconds(10));
    }

	/// Example 2 ///

	n = 1000;
	ProgressBar *bar2 = new ProgressBar(n, "Example 2");
	bar2->SetFrequencyUpdate(10);
	bar2->SetStyle("|","-");
	//bar2->SetStyle("\u2588", "-"); for linux
	
	std::cout << std::endl;
	for(int i=0;i<=n;++i){
		bar2->Progressed(i);
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
    }
	
	n = 5;
	ProgressBar bar3(n);
    bar3.Progressed(0);
    std::this_thread::sleep_for (std::chrono::milliseconds(200));
    bar3.Progressed(1);
    std::this_thread::sleep_for (std::chrono::milliseconds(200));
    bar3.Progressed(2);
    std::this_thread::sleep_for (std::chrono::milliseconds(200));
    bar3.Progressed(3);
    std::this_thread::sleep_for (std::chrono::milliseconds(200));
    bar3.Progressed(4);
    std::this_thread::sleep_for (std::chrono::milliseconds(200));
    bar3.Progressed(5);
    // following tests exception error
    std::this_thread::sleep_for (std::chrono::milliseconds(200));
    bar3.Progressed(6);
    std::this_thread::sleep_for (std::chrono::milliseconds(200));
    bar3.Progressed(7);

	return 0;
}
Example #9
0
static void foo3 ( void )
{
   static char static_local_def[10]    = {0,0,0,0,0, 0,0,0,0,0};
          char nonstatic_local_def[10] = {0,0,0,0,0, 0,0,0,0,0};
   static char static_local_undef[10];
          char nonstatic_local_undef[10];
   croak ( 1 + (char*)&static_global_def );
   croak ( 2 + (char*)&nonstatic_global_def );
   croak ( 3 + (char*)&static_global_undef );
   croak ( 4 + (char*)&nonstatic_global_undef );
   bar3( 5 + (char*)&static_local_def,
         6 + (char*)&nonstatic_local_def,
         7 + (char*)&static_local_undef,
         8 + (char*)&nonstatic_local_undef );
}
Example #10
0
File: vrp41.c Project: 0day-ci/gcc
void
foo (int a)
{
  if (a < 100)
    return;
  if (200 < a)
    return;

  switch (a)
    {
    case  99: bar0 (); return;
    case 100: bar1 (); return;
    case 101: bar2 (); return;
    case 102: bar3 (); return;
    }
}
Example #11
0
void QProg::paintBar()
{
    QPainter painter(this);
    painter.setWindow(0, 0, 470, 80);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QColor(70, 70, 70));
    //background color
    QRectF back(20, 10, 360, 60);
    painter.drawRoundRect(back, 3);
    // chech value
    if (actVal > maxVal)
    {
        return;
    }
    if (actVal < minVal)
    {
        return;
    }
    // waiting state if min = max
    if(minVal == maxVal)
    {
        painter.setBrush(colBar);
        QRectF bar(40, 10, 40, 60);
        QRectF bar1(130, 10, 40, 60);
        QRectF bar2(220, 10, 40, 60);
        QRectF bar3(310, 10, 40, 60);
        painter.drawRoundRect(bar, 3);
        painter.drawRoundRect(bar1, 3);
        painter.drawRoundRect(bar2, 3);
        painter.drawRoundRect(bar3, 3);
        return;
	}	
   	// check positive or negative scale
    if (maxVal >= 0 && minVal >= 0 || maxVal >= 0 && minVal <= 0)
    {
        lengthBar = 360-360 * (maxVal-actVal)/(maxVal-minVal);
    }
    if (maxVal <= 0 && minVal <= 0)
    {
        lengthBar = 360 * (minVal-actVal)/(minVal-maxVal);
    }
    // length and color bar
    painter.setBrush(colBar);
    QRectF bar(20, 10, lengthBar, 60);
    painter.drawRoundRect(bar, 3);
    emit valueChanged(actVal);
}
Example #12
0
void BelowsEnh::paintBar()
{
    QPainter painter(this);
    painter.setWindow(0, 0, 100, 540);
    painter.setRenderHint(QPainter::Antialiasing);

    QLinearGradient linGrad(50, 0, 50, 500);
    linGrad.setColorAt(0, colHigh);
    linGrad.setColorAt(1, colLow);
    linGrad.setSpread(QGradient::PadSpread);
    painter.setBrush(linGrad);

    // draw color bar
   
    // QRectF bar3(20, 50, 25, 450);
    QRectF bar3(20, 50, 60, 450);
    painter.drawRect(bar3);    
    //QRectF bar4(55, 50, 25, 450);
    //painter.drawRect(bar4);
    
    // draw background bar
    painter.setBrush(QColor(40, 40, 40));
    
    double length = 450.0;
    double leftBar = abs(length * (min-leftVal)/(max-min));
    double rightBar = abs(length * (min-rightVal)/(max-min));
    QRectF bar1(20, 50, 60, 450-leftBar);
    painter.drawRect(bar1);
    //QRectF bar2(55, 50, 25, 450-rightBar);
    //painter.drawRect(bar2);


    painter.setPen(QPen(Qt::black, 2));

    for (int i = 0; i <=60; i++)
    {
        //painter.drawLine(21, 500-450*i/60, 44, 500-450*i/60);
        painter.drawLine(21, 500-450*i/60, 79, 500-450*i/60);
        //painter.drawLine(56, 500-450*i/60, 79, 500-450*i/60);
    }

}
Example #13
0
int
foo(void)
{
  int      a,b,g;
  int      i,len;
  int      stop;
                                                                     
  len = 10;
  stop = 0;
  for (i=0; i<len; i++)
  {
    a = bar1() ? 0 : 1;
    b = bar2() ? 0 : 1;
    g = bar3() ? 0 : 1;
                                                                     
    if (stop = ((a+b) % 2 != g)) break;
  }
 
  return stop;
}
Example #14
0
void GameEvent::LoadFromDB()
{
    {
        QueryResult *result = WorldDatabase.Query("SELECT MAX(entry) FROM game_event");
        if( !result )
        {
            sLog.outString(">> Table game_event is empty.");
            sLog.outString();
            return;
        }

        Field *fields = result->Fetch();

        uint32 max_event_id = fields[0].GetUInt16();
        delete result;

        mGameEvent.resize(max_event_id+1);
    }

    QueryResult *result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,description FROM game_event");
    if( !result )
    {
        mGameEvent.clear();
        sLog.outString(">> Table game_event is empty:");
        sLog.outString();
        return;
    }

    uint32 count = 0;

    barGoLink bar( result->GetRowCount() );
    do
    {
        ++count;
        Field *fields = result->Fetch();

        bar.step();

        uint16 event_id = fields[0].GetUInt16();
        if(event_id==0)
        {
            sLog.outErrorDb("`game_event` game event id (%i) is reserved and can't be used.",event_id);
            continue;
        }

        GameEventData& pGameEvent = mGameEvent[event_id];
        uint64 starttime        = fields[1].GetUInt64();
        pGameEvent.start        = time_t(starttime);
        uint64 endtime          = fields[2].GetUInt64();
        pGameEvent.end          = time_t(endtime);
        pGameEvent.occurence    = fields[3].GetUInt32();
        pGameEvent.length       = fields[4].GetUInt32();

        if(pGameEvent.length==0)                            // length>0 is validity check
        {
            sLog.outErrorDb("`game_event` game event id (%i) have length 0 and can't be used.",event_id);
            continue;
        }

        pGameEvent.description  = fields[5].GetCppString();

    } while( result->NextRow() );

    sLog.outString();
    sLog.outString( ">> Loaded %u game events", count );
    delete result;

    mGameEventCreatureGuids.resize(mGameEvent.size()*2-1);
    //                                   1              2
    result = WorldDatabase.Query("SELECT creature.guid, game_event_creature.event "
        "FROM creature JOIN game_event_creature ON creature.guid = game_event_creature.guid");

    count = 0;
    if( !result )
    {
        barGoLink bar2(1);
        bar2.step();

        sLog.outString();
        sLog.outString(">> Loaded %u creatures in game events", count );
    }
    else
    {

        barGoLink bar2( result->GetRowCount() );
        do
        {
            Field *fields = result->Fetch();

            bar2.step();

            uint32 guid    = fields[0].GetUInt32();
            int16 event_id = fields[1].GetInt16();

            int32 internal_event_id = mGameEvent.size() + event_id - 1;

            if(internal_event_id < 0 || internal_event_id >= mGameEventCreatureGuids.size())
            {
                sLog.outErrorDb("`game_event_creature` game event id (%i) is out of range compared to max event id in `game_event`",event_id);
                continue;
            }

            ++count;
            GuidList& crelist = mGameEventCreatureGuids[internal_event_id];
            crelist.push_back(guid);

        } while( result->NextRow() );
        sLog.outString();
        sLog.outString( ">> Loaded %u creatures in game events", count );
        delete result;
    }

    mGameEventGameobjectGuids.resize(mGameEvent.size()*2-1);
    //                                   1                2
    result = WorldDatabase.Query("SELECT gameobject.guid, game_event_gameobject.event "
        "FROM gameobject JOIN game_event_gameobject ON gameobject.guid=game_event_gameobject.guid");

    count = 0;
    if( !result )
    {
        barGoLink bar3(1);
        bar3.step();

        sLog.outString();
        sLog.outString(">> Loaded %u gameobjects in game events", count );
    }
    else
    {

        barGoLink bar3( result->GetRowCount() );
        do
        {
            Field *fields = result->Fetch();

            bar3.step();

            uint32 guid    = fields[0].GetUInt32();
            int16 event_id = fields[1].GetInt16();

            int32 internal_event_id = mGameEvent.size() + event_id - 1;

            if(internal_event_id < 0 || internal_event_id >= mGameEventGameobjectGuids.size())
            {
                sLog.outErrorDb("`game_event_gameobject` game event id (%i) is out of range compared to max event id in `game_event`",event_id);
                continue;
            }

            ++count;
            GuidList& golist = mGameEventGameobjectGuids[internal_event_id];
            golist.push_back(guid);

        } while( result->NextRow() );
        sLog.outString();
        sLog.outString( ">> Loaded %u gameobjects in game events", count );

        delete result;
    }

    mGameEventModelEquip.resize(mGameEvent.size());
    //                                   0              1                             2
    result = WorldDatabase.Query("SELECT creature.guid, game_event_model_equip.event, game_event_model_equip.modelid,"
    //   3
        "game_event_model_equip.equipment_id "
        "FROM creature JOIN game_event_model_equip ON creature.guid=game_event_model_equip.guid");

    count = 0;
    if( !result )
    {
        barGoLink bar3(1);
        bar3.step();

        sLog.outString();
        sLog.outString(">> Loaded %u model/equipment changes in game events", count );
    }
    else
    {

        barGoLink bar3( result->GetRowCount() );
        do
        {
            Field *fields = result->Fetch();

            bar3.step();
            uint32 guid     = fields[0].GetUInt32();
            uint16 event_id = fields[1].GetUInt16();

            if(event_id >= mGameEventModelEquip.size())
            {
                sLog.outErrorDb("`game_event_model_equip` game event id (%u) is out of range compared to max event id in `game_event`",event_id);
                continue;
            }

            ++count;
            ModelEquipList& equiplist = mGameEventModelEquip[event_id];
            ModelEquip newModelEquipSet;
            newModelEquipSet.modelid = fields[2].GetUInt32();
            newModelEquipSet.equipment_id = fields[3].GetUInt32();
            newModelEquipSet.equipement_id_prev = 0;
            newModelEquipSet.modelid_prev = 0;

            if(newModelEquipSet.equipment_id > 0)
            {
                if(!objmgr.GetEquipmentInfo(newModelEquipSet.equipment_id))
                {
                    sLog.outErrorDb("Table `game_event_model_equip` have creature (Guid: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.", guid, newModelEquipSet.equipment_id);
                    continue;
                }
            }

            equiplist.push_back(std::pair<uint32, ModelEquip>(guid, newModelEquipSet));

        } while( result->NextRow() );
        sLog.outString();
        sLog.outString( ">> Loaded %u model/equipment changes in game events", count );

        delete result;
    }

    mGameEventQuests.resize(mGameEvent.size());
    //                                   0   1      2
    result = WorldDatabase.Query("SELECT id, quest, event FROM game_event_creature_quest");

    count = 0;
    if( !result )
    {
        barGoLink bar3(1);
        bar3.step();

        sLog.outString();
        sLog.outString(">> Loaded %u quests additions in game events", count );
    }
    else
    {

        barGoLink bar3( result->GetRowCount() );
        do
        {
            Field *fields = result->Fetch();

            bar3.step();
            uint32 id       = fields[0].GetUInt32();
            uint32 quest    = fields[1].GetUInt32();
            uint16 event_id = fields[2].GetUInt16();

            if(event_id >= mGameEventQuests.size())
            {
                sLog.outErrorDb("`game_event_creature_quest` game event id (%u) is out of range compared to max event id in `game_event`",event_id);
                continue;
            }

            ++count;
            QuestRelList& questlist = mGameEventQuests[event_id];
            questlist.push_back(QuestRelation(id, quest));

        } while( result->NextRow() );
        sLog.outString();
        sLog.outString( ">> Loaded %u quests additions in game events", count );

        delete result;
    }
}
Example #15
0
void ExclusivePoolMgr::LoadFromDB()
{
    QueryResult* result = WorldDatabase.Query("SELECT * FROM exclusive_pool");
    if (!result)
    {
        sLog.outString(">> Table exclusive_pool is empty.");
        sLog.outString();
        return;
    }
    
    BarGoLink bar(result->GetRowCount());
     
    do
    {
        Field* fields = result->Fetch();
        
        bar.step();
        
        uint32 poolID = fields[0].GetUInt32();
        time_t respawnTime = fields[1].GetUInt64();
        
        m_pools[poolID] = ExclusivePool(poolID, respawnTime);
        
    } while (result->NextRow());
     
    delete result;
     
    sLog.outBasic("Loaded %lu exclusive events...", m_pools.size());
     
    QueryResult* result1 = WorldDatabase.Query("SELECT * FROM exclusive_pool_creature");
    if (!result1)
    {
       sLog.outString(">> Table exclusive_pool_creature is empty.");
       sLog.outString();
    }
    else
    {
        BarGoLink bar1(result1->GetRowCount());
        
        uint32 counter = 0;
        do
        {
            Field* fields = result1->Fetch();
                
            ++counter;
            bar1.step();
            
            uint32 guid = fields[0].GetUInt32();
            uint32 poolID = fields[1].GetUInt32();
            uint32 groupID = fields[2].GetUInt32();
            
            
            const CreatureData* pData = sObjectMgr.GetCreatureData(guid);
            if (pData)
                m_pools[poolID].m_objects[groupID].push_back(pData->GetObjectGuid(guid));
            
        } while (result1->NextRow());
        
        delete result1;
        
        sLog.outBasic("Loaded %u exclusive_pool_creatures...", counter);
    }
    
    QueryResult* result2 = WorldDatabase.Query("SELECT * FROM exclusive_pool_spot");
    if (!result2)
    {
       sLog.outString(">> Table exclusive_pool_spot is empty.");
       sLog.outString();
    }
    else
    {   
        BarGoLink bar2(result2->GetRowCount());
        
        uint32 counter = 0;
        do
        {
            Field* fields = result2->Fetch();
            
            ++counter;
            bar2.step();
            
            uint32 poolID = fields[1].GetUInt32();
            uint32 mapID = fields[2].GetUInt32();
            float x = fields[3].GetFloat();
            float y = fields[4].GetFloat();
            float z = fields[5].GetFloat();
            float o = fields[6].GetFloat();
            
            ExclusivePoolSpot spot = { mapID, x, y, z, o };
            m_poolSpots[poolID].push_back(spot);
        } while (result2->NextRow());
       
        delete result2;
        
        sLog.outBasic("Loaded %u exclusive_pool_spots...", counter);
    }
    
    QueryResult* result3 = WorldDatabase.Query("SELECT * FROM exclusive_pool_respawn");
    if (!result3)
    {
       sLog.outString(">> Table exclusive_pool_spot is empty.");
       sLog.outString();
    }
    else
    {
        BarGoLink bar3(result3->GetRowCount());
        
        do
        {
            Field* fields = result3->Fetch();
            
            bar3.step();
            
            uint32 poolID = fields[0].GetUInt32();
            time_t currentRespawnTime = fields[1].GetUInt64();
            
            m_pools[poolID].currentRespawnTime = currentRespawnTime;
        } while (result3->NextRow());
        
        delete result3;
    }
    
}
Example #16
0
void GameEvent::LoadFromDB()
{
    QueryResult *result = WorldDatabase.Query("SELECT MAX(`entry`) FROM `game_event`");
    if( !result )
    {
        sLog.outString(">> Table game_event is empty.");
        sLog.outString();
        return;
    }
    else
    {
        Field *fields = result->Fetch();
        max_event_id = fields[0].GetUInt16();
        delete result;
    }

    mGameEvent.resize(max_event_id + 1);

    result = WorldDatabase.Query("SELECT `entry`,UNIX_TIMESTAMP(`start`),UNIX_TIMESTAMP(`end`),`occurence`,`length`,`description` FROM `game_event`");
    if( !result )
    {
        mGameEvent.clear();
        sLog.outString(">> Table game_event is empty:");
        sLog.outString();
        return;
    }

    uint32 count = 0;

    barGoLink bar( result->GetRowCount() );
    do
    {
        count++;
        Field *fields = result->Fetch();

        bar.step();

        uint16 event_id = fields[0].GetUInt16();

        GameEventData& pGameEvent = mGameEvent[event_id];
        uint64 starttime        = fields[1].GetUInt64();
        pGameEvent.start        = time_t(starttime);
        uint64 endtime          = fields[2].GetUInt64();
        pGameEvent.end          = time_t(endtime);
        pGameEvent.occurence    = fields[3].GetUInt32();
        pGameEvent.length       = fields[4].GetUInt32();
        pGameEvent.description  = fields[5].GetCppString();

    } while( result->NextRow() );

    sLog.outString();
    sLog.outString( ">> Loaded %u game events", count );
    delete result;

    mGameEventCreatureGuids.resize((max_event_id * 2) + 1);
    //                               1                 2
    result = WorldDatabase.Query("SELECT `creature`.`guid`,`game_event_creature`.`event` "
        "FROM `creature` JOIN `game_event_creature` ON `creature`.`guid` = `game_event_creature`.`guid`");

    count = 0;
    if( !result )
    {
        barGoLink bar2(1);
        bar2.step();

        sLog.outString();
        sLog.outString(">> Loaded %u creatures in game events", count );
    }
    else
    {

        barGoLink bar2( result->GetRowCount() );
        do
        {
            Field *fields = result->Fetch();

            bar2.step();

            uint32 guid    = fields[0].GetUInt32();
            int16 event_id = fields[1].GetInt16();

            if(max_event_id + event_id >= mGameEventCreatureGuids.size())
            {
                sLog.outErrorDb("`game_event_creature` game event id (%i) is out of range compared to max event id in `game_event`",event_id);
                continue;
            }

            count++;
            GuidList& crelist = mGameEventCreatureGuids[max_event_id + event_id];
            crelist.push_back(guid);

        } while( result->NextRow() );
        sLog.outString();
        sLog.outString( ">> Loaded %u creatures in game events", count );
        delete result;
    }

    mGameEventGameobjectGuids.resize((max_event_id * 2) + 1);
    //                               1                   2
    result = WorldDatabase.Query("SELECT `gameobject`.`guid`,`game_event_gameobject`.`event` "
        "FROM `gameobject` JOIN `game_event_gameobject` ON `gameobject`.`guid`=`game_event_gameobject`.`guid`");

    count = 0;
    if( !result )
    {
        barGoLink bar3(1);
        bar3.step();

        sLog.outString();
        sLog.outString(">> Loaded %u gameobjects in game events", count );
    }
    else
    {

        barGoLink bar3( result->GetRowCount() );
        do
        {
            Field *fields = result->Fetch();

            bar3.step();

            uint32 guid    = fields[0].GetUInt32();
            int16 event_id = fields[1].GetInt16();

            if(max_event_id + event_id >= mGameEventGameobjectGuids.size())
            {
                sLog.outErrorDb("`game_event_gameobject` game event id (%i) is out of range compared to max event id in `game_event`",event_id);
                continue;
            }

            count++;
            GuidList& golist = mGameEventGameobjectGuids[max_event_id + event_id];
            golist.push_back(guid);

        } while( result->NextRow() );
        sLog.outString();
        sLog.outString( ">> Loaded %u gameobjects in game events", count );

        delete result;
    }

    mGameEventModelEquip.resize(max_event_id + 1);
    //                               0                 1                                2
    result = WorldDatabase.Query("SELECT `creature`.`guid`,`game_event_model_equip`.`event`,`game_event_model_equip`.`modelid`,"
    //   3
        "`game_event_model_equip`.`equipment_id` "
        "FROM `creature` JOIN `game_event_model_equip` ON `creature`.`guid`=`game_event_model_equip`.`guid`");

    count = 0;
    if( !result )
    {
        barGoLink bar3(1);
        bar3.step();

        sLog.outString();
        sLog.outString(">> Loaded %u model/equipment changes in game events", count );
    }
    else
    {

        barGoLink bar3( result->GetRowCount() );
        do
        {
            Field *fields = result->Fetch();

            bar3.step();
            uint32 guid     = fields[0].GetUInt32();
            uint16 event_id = fields[1].GetUInt16();

            if(event_id >= mGameEventModelEquip.size())
            {
                sLog.outErrorDb("`game_event_model_equip` game event id (%u) is out of range compared to max event id in `game_event`",event_id);
                continue;
            }

            count++;
            ModelEquipList& equiplist = mGameEventModelEquip[event_id];
            ModelEquip newModelEquipSet;
            newModelEquipSet.modelid = fields[2].GetUInt32();
            newModelEquipSet.equipment_id = fields[3].GetUInt32();
            newModelEquipSet.equipement_id_prev = 0;
            newModelEquipSet.modelid_prev = 0;
            equiplist.push_back(std::pair<uint32, ModelEquip>(guid, newModelEquipSet));

        } while( result->NextRow() );
        sLog.outString();
        sLog.outString( ">> Loaded %u model/equipment changes in game events", count );

        delete result;
    }

    mGameEventQuests.resize(max_event_id + 1);
    //                               0    1       2
    result = WorldDatabase.Query("SELECT `id`,`quest`,`event` FROM `game_event_creature_quest`");

    count = 0;
    if( !result )
    {
        barGoLink bar3(1);
        bar3.step();

        sLog.outString();
        sLog.outString(">> Loaded %u quests additions in game events", count );
    }
    else
    {

        barGoLink bar3( result->GetRowCount() );
        do
        {
            Field *fields = result->Fetch();

            bar3.step();
            uint32 id       = fields[0].GetUInt32();
            uint32 quest    = fields[1].GetUInt32();
            uint16 event_id = fields[2].GetUInt16();

            if(event_id >= mGameEventQuests.size())
            {
                sLog.outErrorDb("`game_event_creature_quest` game event id (%u) is out of range compared to max event id in `game_event`",event_id);
                continue;
            }

            count++;
            QuestRelList& questlist = mGameEventQuests[event_id];
            questlist.push_back(QuestRelation(id, quest));

        } while( result->NextRow() );
        sLog.outString();
        sLog.outString( ">> Loaded %u quests additions in game events", count );

        delete result;
    }
}
Example #17
0
DEF_TEST(sk_sp, reporter) {
    reset_counters();

    Paint paint;
    REPORTER_ASSERT(reporter, paint.fEffect.get() == nullptr);
    REPORTER_ASSERT(reporter, !paint.get());
    check(reporter, 0, 0, 0, 0);

    paint.set(Create());
    check(reporter, 0, 0, 1, 0);
    REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 1);

    if (paint.get()) {
        REPORTER_ASSERT(reporter, true);
    } else {
        REPORTER_ASSERT(reporter, false);
    }
    if (!paint.get()) {
        REPORTER_ASSERT(reporter, false);
    } else {
        REPORTER_ASSERT(reporter, true);
    }

    paint.set(nullptr);
    check(reporter, 0, 1, 1, 1);

    if (paint.get()) {
        REPORTER_ASSERT(reporter, false);
    } else {
        REPORTER_ASSERT(reporter, true);
    }
    if (!paint.get()) {
        REPORTER_ASSERT(reporter, true);
    } else {
        REPORTER_ASSERT(reporter, false);
    }

    auto e = Create();
    REPORTER_ASSERT(reporter, sizeof(e) == sizeof(void*));

    check(reporter, 0, 1, 2, 1);
    paint.set(e);
    check(reporter, 1, 1, 2, 1);
    REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 2);

    Paint paint2;
    paint2.set(paint.get());
    check(reporter, 2, 1, 2, 1);
    REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 3);

    // Test sk_sp::operator->
    delete paint.get()->method();
    check(reporter, 2, 1, 2, 1);

    // Test sk_sp::operator*
    delete (*paint.get()).method();
    check(reporter, 2, 1, 2, 1);

    paint.set(nullptr);
    e = nullptr;
    paint2.set(nullptr);
    check(reporter, 2, 4, 2, 2);

    reset_counters();
    {
        // Test convertible sk_sp assignment.
        check(reporter, 0, 0, 0, 0);
        sk_sp<Effect> foo(nullptr);
        REPORTER_ASSERT(reporter, !foo);
        foo = make_effect();
        REPORTER_ASSERT(reporter, foo);
        check(reporter, 0, 0, 1, 0);
    }
    check(reporter, 0, 1, 1, 1);

    // Test passing convertible rvalue into funtion.
    reset_counters();
    paint.set(EffectImpl::Create());
    check(reporter, 0, 0, 1, 0);
    paint.set(nullptr);
    check(reporter, 0, 1, 1, 1);

    reset_counters();
    auto baz = EffectImpl::Create();
    check(reporter, 0, 0, 1, 0);
    paint.set(std::move(baz));
    check(reporter, 0, 0, 1, 0);
    REPORTER_ASSERT(reporter, !baz);
    paint.set(nullptr);
    check(reporter, 0, 1, 1, 1);

    reset_counters();
    {
        // test comparison operator with convertible type.
        sk_sp<EffectImpl> bar1 = EffectImpl::Create();
        sk_sp<Effect> bar2(bar1);  // convertible copy constructor
        check(reporter, 1, 0, 1, 0);
        REPORTER_ASSERT(reporter, bar1);
        REPORTER_ASSERT(reporter, bar2);
        REPORTER_ASSERT(reporter, bar1 == bar2);
        REPORTER_ASSERT(reporter, bar2 == bar1);
        REPORTER_ASSERT(reporter, !(bar1 != bar2));
        REPORTER_ASSERT(reporter, !(bar2 != bar1));
        sk_sp<Effect> bar3(nullptr);
        bar3 = bar1;  // convertible copy assignment
        check(reporter, 2, 0, 1, 0);

    }
    check(reporter, 2, 3, 1, 1);

    // test passing convertible copy into funtion.
    reset_counters();
    baz = EffectImpl::Create();
    check(reporter, 0, 0, 1, 0);
    paint.set(baz);
    check(reporter, 1, 0, 1, 0);
    baz = nullptr;
    check(reporter, 1, 1, 1, 0);
    paint.set(nullptr);
    check(reporter, 1, 2, 1, 1);

    {
        sk_sp<SkRefCnt> empty;
        sk_sp<SkRefCnt> notEmpty = sk_make_sp<SkRefCnt>();
        REPORTER_ASSERT(reporter, empty == sk_sp<SkRefCnt>());

        REPORTER_ASSERT(reporter, notEmpty != empty);
        REPORTER_ASSERT(reporter, empty != notEmpty);

        REPORTER_ASSERT(reporter, nullptr == empty);
        REPORTER_ASSERT(reporter, empty == nullptr);
        REPORTER_ASSERT(reporter, empty == empty);

        REPORTER_ASSERT(reporter, nullptr <= empty);
        REPORTER_ASSERT(reporter, empty <= nullptr);
        REPORTER_ASSERT(reporter, empty <= empty);

        REPORTER_ASSERT(reporter, nullptr >= empty);
        REPORTER_ASSERT(reporter, empty >= nullptr);
        REPORTER_ASSERT(reporter, empty >= empty);
    }

    {
        sk_sp<SkRefCnt> a = sk_make_sp<SkRefCnt>();
        sk_sp<SkRefCnt> b = sk_make_sp<SkRefCnt>();
        REPORTER_ASSERT(reporter, a != b);
        REPORTER_ASSERT(reporter, (a < b) != (b < a));
        REPORTER_ASSERT(reporter, (b > a) != (a > b));
        REPORTER_ASSERT(reporter, (a <= b) != (b <= a));
        REPORTER_ASSERT(reporter, (b >= a) != (a >= b));

        REPORTER_ASSERT(reporter, a == a);
        REPORTER_ASSERT(reporter, a <= a);
        REPORTER_ASSERT(reporter, a >= a);
    }

    // http://wg21.cmeerw.net/lwg/issue998
    {
        class foo : public SkRefCnt {
        public:
            foo() : bar(this) {}
            void reset() { bar.reset(); }
        private:
            sk_sp<foo> bar;
        };
        // The following should properly delete the object and not cause undefined behavior.
        // This is an ugly example, but the same issue can arise in more subtle ways.
        (new foo)->reset();
    }

    // https://crrev.com/0d4ef2583a6f19c3e61be04d36eb1a60b133832c
    {
        struct StructB;
        struct StructA : public SkRefCnt {
            sk_sp<StructB> b;
        };

        struct StructB : public SkRefCnt {
            sk_sp<StructA> a;
            ~StructB() override {} // Some clang versions don't emit this implicitly.
        };

        // Create a reference cycle.
        StructA* a = new StructA;
        a->b.reset(new StructB);
        a->b->a.reset(a);

        // Break the cycle by calling reset(). This will cause |a| (and hence, |a.b|)
        // to be deleted before the call to reset() returns. This tests that the
        // implementation of sk_sp::reset() doesn't access |this| after it
        // deletes the underlying pointer. This behaviour is consistent with the
        // definition of unique_ptr::reset in C++11.
        a->b.reset();
    }
}