Ejemplo n.º 1
0
void SGSHero::attacked()
{
  SGMessage* message = new SGMessage(kWhatAttacked, this);
  message->post();
  addDelay(SGS_HERO_ATTACK_ACTION_DURATION);
  return;
}
Ejemplo n.º 2
0
NS_CC_BEGIN

void SGSHero::attackHero(SGSHero* defense_hero)
{
  SGMessage* message = new SGMessage(kWhatAttack, this);
  message->setPtr("defender", defense_hero);
  message->post();
  addDelay(SGS_HERO_ATTACK_ACTION_DURATION);
  return;
}
Ejemplo n.º 3
0
float SGSHero::moveTo(SGSPoint* target_pos)
{
  SGMessage* message = new SGMessage(kWhatMove, this);
  message->setInt("x", target_pos->x);
  message->setInt("y", target_pos->y);
  message->post();
  SGSPointList& path = __terrain->calcShortestPath(this, *target_pos);
  int steps = path.size();
  float delay = steps * SGS_HERO_MOVE_ONE_STEP_TIME;
  addDelay(delay);
  return delay;
}
Ejemplo n.º 4
0
struct timespec DeterministicTimer::getTicks(TimeCallType type=TIMETYPE_UNTRACKED)
{
    //std::lock_guard<std::mutex> lock(mutex);
    DEBUGLOGCALL(LCF_TIMEGET | LCF_FREQUENT);

    /* If we are in the native thread state, just return the real time */
    if (threadState.isNative()) {
        struct timespec realtime;
        orig::clock_gettime(CLOCK_REALTIME, &realtime);
        return realtime;
    }

    if(tasflags.framerate == 0) {
        return nonDetTimer.getTicks(); // 0 framerate means disable deterministic timer
    }

    bool isFrameThread = isMainThread();

    /* If it is our own code calling this, we don't need to track the call */
    if (threadState.isOwnCode())
        type = TIMETYPE_UNTRACKED;

    /* Only the main thread can modify the timer */
    if(!isFrameThread) {
        if(type != TIMETYPE_UNTRACKED) {

            /* Well, actually, if another thread get the time too many times,
             * we temporarily consider it as the main thread.
             * This can lead to desyncs, but it avoids freeze in games that
             * expect the time to advance in other threads.
             */
            if(getTimes >= MAX_NONFRAME_GETTIMES)
            {
                if(getTimes == MAX_NONFRAME_GETTIMES)
                    debuglog(LCF_TIMEGET | LCF_DESYNC, "Temporarily assuming main thread");
                isFrameThread = true;
            }
            getTimes++;
        }
    }

    if (isFrameThread)
    {
        /* Only do this in the main thread so as to not dirty the timer with nondeterministic values
         * (not to mention it would be extremely multithreading-unsafe without using sync primitives otherwise)
         */

        int ticksExtra = 0;

        if (type != TIMETYPE_UNTRACKED)
        {
            debuglog(LCF_TIMESET | LCF_FREQUENT, "subticks ", type, " increased");
            altGetTimes[type]++;

            if(altGetTimes[type] > altGetTimeLimits[type]) {
                /* 
                 * We reached the limit of the number of calls.
                 * We advance the deterministic timer by some value
                 */
                int tickDelta = 1;

                debuglog(LCF_TIMESET | LCF_FREQUENT, "WARNING! force-advancing time of type ", type);

                ticksExtra += tickDelta;

                /* Reseting the number of calls from all functions */
                for (int i = 0; i < TIMETYPE_NUMTRACKEDTYPES; i++)
                    altGetTimes[i] = 0;

            }
        }

        if(ticksExtra) {
            /* Delay by ticksExtra ms. Arbitrary */
            struct timespec delay = {0, ticksExtra * 1000000};
            addDelay(delay);
        }
    }

    TimeHolder fakeTicks = ticks + fakeExtraTicks;
    return fakeTicks;
}
Ejemplo n.º 5
0
Program::Program(bool isadmin, int userid,int _id, QWidget *parent)
    : QWidget(parent)
{

    QString tempTeacherName;
    QString tempStudentName;

    this->is_admin = isadmin;
    this->user_id = userid;
    this->ID = _id;
    //setting program options
    if (this->is_admin)
        this->setFixedSize(480, 275);
    else
        this->setFixedSize(240, 245);
    this->setWindowTitle("IUST School!");
    std::vector<QString> names;
    if (is_admin)
    {
        grpTeachers = new QGroupBox(this);
        grpTeachers->setGeometry(245, 3, 233,100);

        teachersCombo = new QComboBox();

        names = sql.getTeacherNames();
        int numTeachers = names.size();
        for (int i = 0; i < numTeachers; ++i)
        {
            teachersCombo->addItem(names[i],i);
        }
        teachersCombo->setParent(grpTeachers);
        teachersCombo->setGeometry(10,2,140,20);

        tempTeacherName = teachersCombo->itemText(teachersCombo->currentIndex());

        connect(teachersCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateTeacherData()));

        label1 = new QLabel("معلم");
        label1->setGeometry(158, 2, 60, 20);
        label1->setParent(grpTeachers);

        label2 = new QLabel("نام:");
        label2->setGeometry(158, 24, 60, 20);
        label2->setParent(grpTeachers);

        label3 = new QLabel();
        label3->setGeometry(10, 24, 140, 20);
        label3->setAlignment(Qt::AlignLeft | Qt::AlignCenter);
        label3->setText(tempTeacherName);
        label3->setParent(grpTeachers);

        label4 = new QLabel("کلاس فعلی:");
        label4->setGeometry(158, 48, 60, 20);
        label4->setParent(grpTeachers);

        label5 = new QLabel();
        label5->setGeometry(10, 48, 140, 20);
        label5->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
        label5->setText(getClassName(sql.getTeacherClass(tempTeacherName)));
        label5->setParent(grpTeachers);

        classCombo = new QComboBox();
        classCombo->addItem("1/1");
        classCombo->addItem("1/2");
        classCombo->addItem("2/1");
        classCombo->addItem("2/2");
        classCombo->addItem("3/1");
        classCombo->addItem("3/2");
        classCombo->addItem("4/1");
        classCombo->addItem("4/2");
        classCombo->addItem("5/1");
        classCombo->addItem("5/2");
        classCombo->addItem("6/1");
        classCombo->addItem("6/2");
        classCombo->setParent(grpTeachers);
        classCombo->setGeometry(10,72,140,20);

        btnAddTeacherToClass = new QPushButton("تخصیص");
        btnAddTeacherToClass->setGeometry(160, 71, 60, 22);
        btnAddTeacherToClass->setParent(grpTeachers);

        connect(btnAddTeacherToClass, SIGNAL(clicked()), this, SLOT(bindTeacher()));

        grpDelays = new QGroupBox(this);
        grpDelays->setGeometry(245, 107, 233,100);

        btnFileDelayForStudent = new QPushButton("ثبت تاخیر برای دانش آموز", grpDelays);
        btnFileDelayForStudent->setGeometry(10, 5, 220, 24);

        connect(btnFileDelayForStudent, SIGNAL(clicked()), this, SLOT(addDelay()));

        delaysList = new QListWidget(grpDelays);
        delaysList->setGeometry(10, 35, 220, 60);

        grpAdminPanel = new QGroupBox(this);
        grpAdminPanel->setGeometry(245, 210, 233,54);

        btnAdminChangePassword = new QPushButton("تغییر رمز", grpAdminPanel);
        btnAdminChangePassword->setGeometry(10,1,213,22);

        connect(btnAdminChangePassword, SIGNAL(clicked()), this, SLOT(adminChangePassword()));

        btnAddTeacher = new QPushButton("اضافه کردن معلم", grpAdminPanel);
        btnAddTeacher->setGeometry(10,27,213,22);

        connect(btnAddTeacher, SIGNAL(clicked()), this, SLOT(addTeacher()));
    }

    grpStudents = new QGroupBox(this);
    if (is_admin)
        grpStudents->setGeometry(5, 3, 233,260);
    else
        grpStudents->setGeometry(5, 3, 233,230);
    studentsCombo = new QComboBox();

    std::vector<int> ids = sql.getStudentIDs(this->user_id);
    names = sql.getStudentNames(this->user_id);
    int numStudents = names.size();
    for (int i = 0; i < numStudents; ++i)
    {
        studentsCombo->addItem(names[i],ids[i]);
    }
    studentsCombo->setParent(grpStudents);
    studentsCombo->setGeometry(10,2,140,20);

    tempStudentName = studentsCombo->itemText(studentsCombo->currentIndex());

    connect(studentsCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateStudentData()));

    label1s = new QLabel("دانش آموز");
    label1s->setGeometry(158, 2, 60, 20);
    label1s->setParent(grpStudents);

    label2s = new QLabel("نام:");
    label2s->setGeometry(188, 22, 30, 18);
    label2s->setParent(grpStudents);

    label3s = new QLabel();
    label3s->setGeometry(10, 22, 190, 18);
    label3s->setAlignment(Qt::AlignLeft | Qt::AlignCenter);
    label3s->setText(studentsCombo->itemText(studentsCombo->currentIndex()));
    label3s->setParent(grpStudents);

    label4s = new QLabel("کلاس فعلی:");
    label4s->setGeometry(158, 40, 60, 18);
    label4s->setParent(grpStudents);

    label5s = new QLabel();
    label5s->setGeometry(80, 40, 70, 18);
    label5s->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
    label5s->setText(getClassName(sql.getStudentClass(tempStudentName)));
    label5s->setParent(grpStudents);

    label6s = new QLabel("ریاضی:");
    label6s->setGeometry(180, 58, 40, 18);
    label6s->setParent(grpStudents);

    label7s = new QLabel();
    label7s->setGeometry(110, 58, 50, 18);
    label7s->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
    label7s->setParent(grpStudents);

    label8s = new QLabel("فیزیک:");
    label8s->setGeometry(70, 58, 40, 18);
    label8s->setParent(grpStudents);

    label9s = new QLabel();
    label9s->setGeometry(10, 58, 50, 18);
    label9s->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
    label9s->setParent(grpStudents);

    label10s = new QLabel("فارسی:");
    label10s->setGeometry(180, 76, 40, 18);
    label10s->setParent(grpStudents);

    label11s = new QLabel();
    label11s->setGeometry(110, 76, 50, 18);
    label11s->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
    label11s->setParent(grpStudents);

    label12s = new QLabel("دینی:");
    label12s->setGeometry(70, 76, 40, 18);
    label12s->setParent(grpStudents);

    label13s = new QLabel();
    label13s->setGeometry(10, 76, 50, 18);
    label13s->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
    label13s->setParent(grpStudents);

    label14s = new QLabel("جغرافی:");
    label14s->setGeometry(180, 94, 40, 18);
    label14s->setParent(grpStudents);

    label15s = new QLabel();
    label15s->setGeometry(110, 94, 50, 18);
    label15s->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
    label15s->setParent(grpStudents);

    label16s = new QLabel("شیمی:");
    label16s->setGeometry(70, 94, 40, 18);
    label16s->setParent(grpStudents);

    label17s = new QLabel();
    label17s->setGeometry(10, 94, 50, 18);
    label17s->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
    label17s->setParent(grpStudents);

    label18s = new QLabel("انظباط:");
    label18s->setGeometry(180, 112, 40, 18);
    label18s->setParent(grpStudents);

    label19s = new QLabel();
    label19s->setGeometry(110, 112, 50, 18);
    label19s->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
    label19s->setParent(grpStudents);

    label20s = new QLabel("معدل:");
    label20s->setGeometry(70, 112, 40, 18);
    label20s->setParent(grpStudents);

    label21s = new QLabel();
    label21s->setGeometry(10, 112, 50, 18);
    label21s->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
    label21s->setParent(grpStudents);

    update_student_scores();

    if (is_admin)
    {

        classSCombo = new QComboBox();
        classSCombo->addItem("1/1");
        classSCombo->addItem("1/2");
        classSCombo->addItem("2/1");
        classSCombo->addItem("2/2");
        classSCombo->addItem("3/1");
        classSCombo->addItem("3/2");
        classSCombo->addItem("4/1");
        classSCombo->addItem("4/2");
        classSCombo->addItem("5/1");
        classSCombo->addItem("5/2");
        classSCombo->addItem("6/1");
        classSCombo->addItem("6/2");
        classSCombo->setParent(grpStudents);
        classSCombo->setGeometry(10,140,140,24);

        btnAddStudentToClass = new QPushButton("تخصیص");
        btnAddStudentToClass->setGeometry(160, 140, 60, 24);
        btnAddStudentToClass->setParent(grpStudents);

        connect(btnAddStudentToClass, SIGNAL(clicked()), this, SLOT(bindStudent()));

        btnAddStudent = new QPushButton("اضافه کردن دانش آموز جدید");
        btnAddStudent->setGeometry(70, 170, 150, 24);
        btnAddStudent->setParent(grpStudents);

        connect(btnAddStudent, SIGNAL(clicked()), this, SLOT(addNewStudent()));

        btnRemoveStudent = new QPushButton("حذف کردن دانش آموز کنونی");
        btnRemoveStudent->setGeometry(70, 200, 150, 24);
        btnRemoveStudent->setParent(grpStudents);

        connect(btnRemoveStudent, SIGNAL(clicked()), this, SLOT(removeCurrentStudent()));

        btnScoring = new QPushButton("نمره دهی");
        btnScoring->setGeometry(140, 230, 80, 24);
        btnScoring->setParent(grpStudents);

        connect(btnScoring, SIGNAL(clicked()), this, SLOT(setStudentScore()));

        coursesCombo = new QComboBox();

        coursesCombo->addItem("انظباط", 6);

        coursesCombo->setParent(grpStudents);
        coursesCombo->setGeometry(10,230,120,24);

        update_delays();
    }
    else
    {

        btnRemoveStudent = new QPushButton("اخراج دانش آموز کنونی");
        btnRemoveStudent->setGeometry(70, 140, 150, 24);
        btnRemoveStudent->setParent(grpStudents);

        connect(btnRemoveStudent, SIGNAL(clicked()), this, SLOT(removeCurrentStudent()));

        btnScoring = new QPushButton("نمره دهی");
        btnScoring->setGeometry(140, 170, 80, 24);
        btnScoring->setParent(grpStudents);

        connect(btnScoring, SIGNAL(clicked()), this, SLOT(setStudentScore()));

        coursesCombo = new QComboBox();

        coursesCombo->addItem("ریاضی", 0);
        coursesCombo->addItem("فیزیک", 1);
        coursesCombo->addItem("فارسی", 2);
        coursesCombo->addItem("دینی", 3);
        coursesCombo->addItem("جغرافی", 4);
        coursesCombo->addItem("شیمی", 5);

        coursesCombo->setParent(grpStudents);
        coursesCombo->setGeometry(10,170,120,24);

        btnTeacherChangePassword = new QPushButton("تغییر رمز", grpStudents);
        btnTeacherChangePassword->setGeometry(70, 200, 150, 24);

        connect(btnTeacherChangePassword, SIGNAL(clicked()), this, SLOT(changeTeacherPassword()));
    }
}