void AEQSTestingPawn::MakeOneStep()
{
	UEnvQueryManager* EQS = UEnvQueryManager::GetCurrent(GetWorld());
	if (EQS == NULL)
	{
		return;
	}

	if (QueryInstance.IsValid() == false && QueryTemplate != NULL)
	{
		FEnvQueryRequest QueryRequest(QueryTemplate, this);
		QueryRequest.SetNamedParams(QueryParams);
		QueryInstance = EQS->PrepareQueryInstance(QueryRequest, QueryingMode);
		if (QueryInstance.IsValid())
		{
			EQS->RegisterExternalQuery(QueryInstance);
		}
	}

	// possible still not valid 
	if (QueryInstance.IsValid() == true && QueryInstance->IsFinished() == false)
	{
		QueryInstance->ExecuteOneStep(double(TimeLimitPerStep));
		StepResults.Add(*(QueryInstance.Get()));

		if (QueryInstance->IsFinished())
		{
			StepToDebugDraw = StepResults.Num() - 1;
			UpdateDrawing();
		}
	}
}
void AEQSTestingPawn::PostEditChangeProperty( FPropertyChangedEvent& PropertyChangedEvent)
{
	static const FName NAME_QueryTemplate = GET_MEMBER_NAME_CHECKED(AEQSTestingPawn, QueryTemplate);
	static const FName NAME_StepToDebugDraw = GET_MEMBER_NAME_CHECKED(AEQSTestingPawn, StepToDebugDraw);
	static const FName NAME_QueryParams = GET_MEMBER_NAME_CHECKED(AEQSTestingPawn, QueryParams);
	static const FName NAME_ShouldBeVisibleInGame = GET_MEMBER_NAME_CHECKED(AEQSTestingPawn, bShouldBeVisibleInGame);
	static const FName NAME_QueryingMode = GET_MEMBER_NAME_CHECKED(AEQSTestingPawn, QueryingMode);

	if (PropertyChangedEvent.Property != NULL)
	{
		const FName PropName = PropertyChangedEvent.MemberProperty->GetFName();
		if (PropName == NAME_QueryTemplate || PropName == NAME_QueryParams)
		{
			if (QueryTemplate)
			{
				QueryTemplate->CollectQueryParams(QueryParams);
			}

			RunEQSQuery();
		}
		else if (PropName == NAME_StepToDebugDraw)
		{
			StepToDebugDraw  = FMath::Clamp(StepToDebugDraw, 0, StepResults.Num() - 1 );
			UpdateDrawing();
		}
		else if (PropName == GET_MEMBER_NAME_CHECKED(AEQSTestingPawn, bDrawFailedItems) ||
			PropName == GET_MEMBER_NAME_CHECKED(AEQSTestingPawn, HighlightMode))
		{
			UpdateDrawing();
		}
		else if (PropName == NAME_ShouldBeVisibleInGame)
		{
			UBillboardComponent* SpriteComponent = FindComponentByClass<UBillboardComponent>();
			if (SpriteComponent != NULL)
			{
				SpriteComponent->bHiddenInGame = !bShouldBeVisibleInGame;
			}
		}
		else if (PropName == NAME_QueryingMode)
		{
			RunEQSQuery();
		}
	}

	Super::PostEditChangeProperty(PropertyChangedEvent);
}
void infogb_vram_blit()
{
   gp_uploadTexture(&thegp, NES_TEX, 256, 0, 0, 0x02, &g_BitmapData, 160, 144);
   gp_setTex(&thegp, NES_TEX, 256, 8, GS256, 0x02, 0, 0, 0, g_Filter);

   if ( g_Stretch == 2 ) {
      gp_texrect(&thegp, 0, 16, 0, 0, 320, (256-16), 160, 144, 2,
         GS_SET_RGBA(0x00, 0x00, 0x00, 0x80));
   } else if ( g_Stretch == 1 ) {
      gp_texrect(&thegp, 40, 20, 0, 0, (240+40), (216+20), 160, 144, 2,
         GS_SET_RGBA(0x00, 0x00, 0x00, 0x80));
   } else {
      gp_texrect(&thegp, 80, 56, 0, 0, (160+80), (144+56), 160, 144, 2,
         GS_SET_RGBA(0x00, 0x00, 0x00, 0x80));
   }

   if ( g_ShowFPS ) {
      char strInfo[32];
      sprintf(strInfo, "FPS Rate: %i", PS2_FPSMeasure());
      TextOut(15, 30, strInfo, 3);
   }

   UpdateDrawing();
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
  ui(new Ui::MainWindow) {
  ui->setupUi(this);

  scene = new Scene(this);
  ui->glwidget->SetScene(scene);
  //ui->raycastwidget->s = scene;

  QObject::connect(ui->object_create_button, SIGNAL(clicked(bool)), scene, SLOT(CreateObject()));
  QObject::connect(ui->octree_create_button, SIGNAL(clicked(bool)), this, SLOT(CreateOctreePressed()));

  QObject::connect(ui->object_tree,
                   SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
                   this,
                   SLOT(SelectObject(QTreeWidgetItem *, QTreeWidgetItem *)));

  QObject::connect(scene, SIGNAL(UpdateObjList()), this, SLOT(UpdateObjList()));
  QObject::connect(scene, SIGNAL(UpdateDrawing()), this, SLOT(UpdateDrawing()));

  QObject::connect(ui->octree_spread_slider, SIGNAL(valueChanged(int)), scene, SLOT(ChangeOctreeSpread(int)));

  QObject::connect(ui->pos_x, SIGNAL(valueChanged(double)), this, SLOT(UpdateCurrentObjectTransform(double)));
  QObject::connect(ui->pos_y, SIGNAL(valueChanged(double)), this, SLOT(UpdateCurrentObjectTransform(double)));
  QObject::connect(ui->pos_z, SIGNAL(valueChanged(double)), this, SLOT(UpdateCurrentObjectTransform(double)));
  QObject::connect(ui->rot_x, SIGNAL(valueChanged(double)), this, SLOT(UpdateCurrentObjectTransform(double)));
  QObject::connect(ui->rot_y, SIGNAL(valueChanged(double)), this, SLOT(UpdateCurrentObjectTransform(double)));
  QObject::connect(ui->rot_z, SIGNAL(valueChanged(double)), this, SLOT(UpdateCurrentObjectTransform(double)));
  QObject::connect(ui->sca_x, SIGNAL(valueChanged(double)), this, SLOT(UpdateCurrentObjectTransform(double)));
  QObject::connect(ui->sca_y, SIGNAL(valueChanged(double)), this, SLOT(UpdateCurrentObjectTransform(double)));
  QObject::connect(ui->sca_z, SIGNAL(valueChanged(double)), this, SLOT(UpdateCurrentObjectTransform(double)));

  QObject::connect(ui->name_lineEdit, SIGNAL(textEdited(QString)), this, SLOT(UpdateCurrentObjectName(QString)));
  QObject::connect(ui->lines_checkBox, SIGNAL(toggled(bool)), this, SLOT(UpdateCurrentObjectCheck(bool)));
  QObject::connect(ui->hide_checkBox, SIGNAL(toggled(bool)), this, SLOT(UpdateCurrentObjectCheck(bool)));

  ui->obj_content->setEnabled(false);

  QObject::connect(ui->object_tree, SIGNAL(ChangeParent(QString, QString)), scene, SLOT(Reparent(QString, QString)));

  QObject::connect(ui->delete_object, SIGNAL(clicked(bool)), scene, SLOT(DeleteCurrentObject()));

  QObject::connect(ui->operate_octree_button, SIGNAL(clicked(bool)), this, SLOT(OperateOctreePressed()));

  QObject::connect(ui->save_pushButton,SIGNAL(clicked(bool)),this,SLOT(SaveScenePress()));
  QObject::connect(ui->load_pushButton,SIGNAL(clicked(bool)),this,SLOT(LoadScenePress()));

  QObject::connect(ui->duplicate_button,SIGNAL(clicked(bool)),this,SLOT(DuplicateObjectPressed()));

  QObject::connect(ui->faceColor,SIGNAL(clicked(bool)),this,SLOT(SetFaceColor()));
  QObject::connect(ui->lineColor,SIGNAL(clicked(bool)),this,SLOT(SetLineColor()));

  faceColor = QColor(0,0,0);
  ui->faceColor->setStyleSheet(colorButtonStyle.arg(faceColor.name()));

  lineColor = QColor(255,255,255);
  ui->lineColor->setStyleSheet(colorButtonStyle.arg(lineColor.name()));

  QObject::connect(ui->clear_pushButton,SIGNAL(clicked(bool)),this,SLOT(ClearScene()));

  QObject::connect(ui->create_csg_pushButton,SIGNAL(clicked(bool)),this,SLOT(CreateCSGPressed()));

  QObject::connect(ui->create_he_button,SIGNAL(clicked(bool)),this,SLOT(CreateHEPressed()));

  QObject::connect(ui->edge_spinBox,SIGNAL(valueChanged(int)),this,SLOT(UpdateCurrentObjectHE()));
  //QObject::connect(ui->face_spinBox,SIGNAL(valueChanged(int)),this,SLOT(UpdateCurrentObjectHE()));

//  QObject::connect(ui->face_pushButton,SIGNAL(clicked(bool)),this,SLOT(GetEdgeFace()));
  QObject::connect(ui->next_pushButton,SIGNAL(clicked(bool)),this,SLOT(GetNextEdge()));
  QObject::connect(ui->mate_pushButton,SIGNAL(clicked(bool)),this,SLOT(GetMateEdge()));

  QObject::connect(ui->mef,SIGNAL(clicked(bool)),this,SLOT(MEF()));
  QObject::connect(ui->mev,SIGNAL(clicked(bool)),this,SLOT(MEV()));
  QObject::connect(ui->translate,SIGNAL(clicked(bool)),this,SLOT(Translate()));
  QObject::connect(ui->extrude,SIGNAL(clicked(bool)),this,SLOT(Extrude()));

  QObject::connect(ui->create_bezier_button,SIGNAL(clicked(bool)),this,SLOT(CreateBezierPressed()));

  QObject::connect(ui->bezi,SIGNAL(valueChanged(int)),this,SLOT(SelectBezierControl()));
  QObject::connect(ui->bezj,SIGNAL(valueChanged(int)),this,SLOT(SelectBezierControl()));
  QObject::connect(ui->bezx,SIGNAL(valueChanged(double)),this,SLOT(SelectBezierPosition()));
  QObject::connect(ui->bezy,SIGNAL(valueChanged(double)),this,SLOT(SelectBezierPosition()));
  QObject::connect(ui->bezz,SIGNAL(valueChanged(double)),this,SLOT(SelectBezierPosition()));

  ui->specific_stackedWidget->setCurrentWidget(ui->default_page);
}