示例#1
0
	void PositionText(const string& message, int row)
	{
    coordinate_mode mode(coordinate_mode::mode_character);

		char coor[2];
		screen_size(coor);
		write_at (message.data(), message.length(), 1 + ((coor[1] - message.length()) / 2), row);
	}
示例#2
0
static void print_banner(FILE *stream, int color)
{
	int x;
	const char *use = NULL;
#include <cc.h>

	screen_size(&x, NULL);

	use = (x > 100) ? cc : cc_s;

#ifdef WIN32
	/* Print banner in yellow with blue background */
	if (color) {
		SetConsoleTextAttribute(hStdout, ESL_SEQ_FYELLOW | BACKGROUND_BLUE);
	}
	WriteFile(hStdout, banner, (DWORD) strlen(banner), NULL, NULL);
	WriteFile(hStdout, use, (DWORD) strlen(use), NULL, NULL);
	if (color) {
		SetConsoleTextAttribute(hStdout, wOldColorAttrs);
	}

	/* Print the rest info in default colors */
	fprintf(stream, "\n%s\n", inf);
#else

	if (color) {
		fprintf(stream, "%s%s%s", ESL_SEQ_DEFAULT_COLOR, ESL_SEQ_FYELLOW, ESL_SEQ_BBLUE);
	}

	fprintf(stream, "%s%s", banner, use);


	if (color) {
		fprintf(stream, "%s", ESL_SEQ_DEFAULT_COLOR);
	}

	fprintf(stream, "\n%s\n", inf);


	if (color) {
		fprintf(stream, "%s", output_text_color);
	}
#endif

	if (x < 160) {
		fprintf(stream, "\n[This app Best viewed at 160x60 or more..]\n");
	}
}
示例#3
0
void InitDataReport(int argc, LPWSTR* argv)
{
  ygdata_report::GetMachineIdTimeout(10 * 1000);
  ygdata_report::AddEidDescList(kEidDescList);
	bool debug_string = CmdLineFindFlag(argc, argv, L"--data-report-debug-string") >= 0;
	//增加窗口
	debug_string = debug_string || IsDebugStringValue();

	ygdata_report::Init(L"http://stat.game.yy.com/data.do", "pas", "yyexplorer", 5 * 60 * 1000, NULL, L"", 0, debug_string);
	ygdata_report::Run();

	SessionInfo info;
	std::string screen_size("0.0");
	std::string screen_color("0");

	DEVMODEW dm;
	dm.dmSize = sizeof(dm);

	BOOL result = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
	if (result)
	{
		char number[32];

		screen_size.clear();
		screen_size.append(_itoa(dm.dmPelsWidth, number, 10));
		screen_size.append(".");
		screen_size.append(_itoa(dm.dmPelsHeight, number, 10));

		screen_color.clear();
		screen_color.append(_itoa(dm.dmBitsPerPel, number, 10));
	}

	info.cha = "yeuninstall";
	info.rso = "from_yeuninstall";
	info.ive = STR_PRODUCT_VERSION"."STR_FILE_VERSION;
	info.uve = info.ive;
	info.os = ygdata_report::GetOsPlatformVersion();
	info.lla = "zh_cn";
	info.sre = screen_size;
	info.sco = screen_color;
	ygdata_report::PostSessionInfo(info);

	ygdata_report::SendEventWithSrc("yeuninstall", "StartUp");
}
示例#4
0
static void
Main()
{
  PixelSize screen_size(320, 240);
  if (portrait)
    std::swap(screen_size.cx, screen_size.cy);

  Layout::Initialize(screen_size.cx, screen_size.cy);
  SingleWindow main_window;
  main_window.Create(_T("RunDialog"), screen_size);
  main_window.Show();

  WndForm *form = LoadDialog(NULL, main_window, xmlfile.c_str());
  if (form == NULL) {
    fprintf(stderr, "Failed to load resource '%s'\n",
            (const char *)NarrowPathName(xmlfile.c_str()));
    return;
  }

  form->ShowModal();
  delete form;
}
示例#5
0
void save_slot_preview(BYTE slot) {
	uTCHAR *file;
	FILE *fp;

	if (!save_slot.preview_start) {
		memcpy(tl.snaps[TL_SNAP_FREE] + tl.preview, screen.data, screen_size());
		save_slot.preview_start = TRUE;
	}

	if (!save_slot.state[slot]) {
		memcpy(screen.data, tl.snaps[TL_SNAP_FREE] + tl.preview, screen_size());
		gfx_draw_screen(TRUE);
		return;
	}

	if ((file = name_slot_file(slot)) == NULL) {
		memcpy(screen.data, tl.snaps[TL_SNAP_FREE] + tl.preview, screen_size());
		gfx_draw_screen(TRUE);
		return;
	}

	if ((fp = ufopen(file, uL("rb"))) == NULL) {
		memcpy(screen.data, tl.snaps[TL_SNAP_FREE] + tl.preview, screen_size());
		gfx_draw_screen(TRUE);
		fprintf(stderr, "error on load preview\n");
		return;
	}

	fseek(fp, save_slot.preview[slot], SEEK_SET);

	{
		DBWORD bytes;

		bytes = fread(screen.data, screen_size(), 1, fp);

		if (bytes != 1) {
			memcpy(screen.data, tl.snaps[TL_SNAP_FREE] + tl.preview, screen_size());
		}
	}

	fclose(fp);
	gfx_draw_screen(TRUE);
}
示例#6
0
void cv::viz::InteractorStyle::OnKeyDown()
{
    CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_);
    FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]);

    // Save the initial windows width/height
    if (win_size_[0] == -1 || win_size_[1] == -1)
        win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize());

    bool alt = Interactor->GetAltKey() != 0;

    std::string key(Interactor->GetKeySym());
    if (key.find("XF86ZoomIn") != std::string::npos)
        zoomIn();
    else if (key.find("XF86ZoomOut") != std::string::npos)
        zoomOut();

    switch (Interactor->GetKeyCode())
    {
    case 'h': case 'H':
    {
        std::cout << "| Help:\n"
                     "-------\n"
                     "          p, P   : switch to a point-based representation\n"
                     "          w, W   : switch to a wireframe-based representation (where available)\n"
                     "          s, S   : switch to a surface-based representation (where available)\n"
                     "\n"
                     "          j, J   : take a .PNG snapshot of the current window view\n"
                     "          k, K   : export scene to Wavefront .obj format\n"
                     "    ALT + k, K   : export scene to VRML format\n"
                     "          c, C   : display current camera/window parameters\n"
                     "          f, F   : fly to point mode, hold the key and move mouse where to fly\n"
                     "\n"
                     "          e, E   : exit the interactor\n"
                     "          q, Q   : stop and call VTK's TerminateApp\n"
                     "\n"
                     "           +/-   : increment/decrement overall point size\n"
                     "     +/- [+ ALT] : zoom in/out \n"
                     "\n"
                     "    r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]\n"
                     "\n"
                     "    ALT + s, S   : turn stereo mode on/off\n"
                     "    ALT + f, F   : switch between maximized window mode and original size\n"
                     "\n"
                  << std::endl;
        break;
    }

        // Switch representation to points
    case 'p': case 'P':
    {
        vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
        vtkCollectionSimpleIterator ait;
        for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
            for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
            {
                vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp());
                apart->GetProperty()->SetRepresentationToPoints();
            }
        break;
    }

        // Save a PNG snapshot
    case 'j': case 'J':
        saveScreenshot(cv::format("screenshot-%d.png", (unsigned int)time(0))); break;

        // Export scene as in obj or vrml format
    case 'k': case 'K':
    {
        String format = alt ? "scene-%d.vrml" : "scene-%d";
        exportScene(cv::format(format.c_str(), (unsigned int)time(0)));
        break;
    }

        // display current camera settings/parameters
    case 'c': case 'C':
    {
        vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera();

        Vec2d clip(cam->GetClippingRange());
        Vec3d focal(cam->GetFocalPoint()), pos(cam->GetPosition()), view(cam->GetViewUp());
        Vec2i win_pos(Interactor->GetRenderWindow()->GetPosition());
        Vec2i win_size(Interactor->GetRenderWindow()->GetSize());
        double angle = cam->GetViewAngle () / 180.0 * CV_PI;

        String data = cv::format("clip(%f,%f) focal(%f,%f,%f) pos(%f,%f,%f) view(%f,%f,%f) angle(%f) winsz(%d,%d) winpos(%d,%d)",
                                 clip[0], clip[1], focal[0], focal[1], focal[2], pos[0], pos[1], pos[2], view[0], view[1], view[2],
                                 angle, win_size[0], win_size[1], win_pos[0], win_pos[1]);

        std::cout << data.c_str() << std::endl;

        break;
    }
    case '=':
    {
        zoomIn();
        break;
    }
    case 43:        // KEY_PLUS
    {
        if (alt)
            zoomIn();
        else
        {
            vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
            vtkCollectionSimpleIterator ait;
            for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
                for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
                {
                    vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp());
                    float psize = apart->GetProperty()->GetPointSize();
                    if (psize < 63.0f)
                        apart->GetProperty()->SetPointSize(psize + 1.0f);
                }
        }
        break;
    }
    case 45:        // KEY_MINUS
    {
        if (alt)
            zoomOut();
        else
        {
            vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
            vtkCollectionSimpleIterator ait;
            for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
                for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
                {
                    vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp());
                    float psize = apart->GetProperty()->GetPointSize();
                    if (psize > 1.0f)
                        apart->GetProperty()->SetPointSize(psize - 1.0f);
                }
        }
        break;
    }
        // Switch between maximize and original window size
    case 'f': case 'F':
    {
        if (alt)
        {
            Vec2i screen_size(Interactor->GetRenderWindow()->GetScreenSize());
            Vec2i win_size(Interactor->GetRenderWindow()->GetSize());

            // Is window size = max?
            if (win_size == max_win_size_)
            {
                Interactor->GetRenderWindow()->SetSize(win_size_.val);
                Interactor->GetRenderWindow()->SetPosition(win_pos_.val);
                Interactor->GetRenderWindow()->Render();
                Interactor->Render();
            }
            // Set to max
            else
            {
                win_pos_ = Vec2i(Interactor->GetRenderWindow()->GetPosition());
                win_size_ = win_size;

                Interactor->GetRenderWindow()->SetSize(screen_size.val);
                Interactor->GetRenderWindow()->Render();
                Interactor->Render();
                max_win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize());
            }
        }
        else
        {
            AnimState = VTKIS_ANIM_ON;
            Interactor->GetPicker()->Pick(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1], 0.0, CurrentRenderer);
            vtkSmartPointer<vtkAbstractPropPicker> picker = vtkAbstractPropPicker::SafeDownCast(Interactor->GetPicker());
            if (picker)
                if (picker->GetPath())
                    Interactor->FlyTo(CurrentRenderer, picker->GetPickPosition());
            AnimState = VTKIS_ANIM_OFF;
        }
        break;
    }
        // 's'/'S' w/out ALT
    case 's': case 'S':
    {
        if (alt)
        {
            vtkSmartPointer<vtkRenderWindow> window = Interactor->GetRenderWindow();
            if (!window->GetStereoRender())
            {
                static Vec2i red_blue(4, 3), magenta_green(2, 5);
                window->SetAnaglyphColorMask (stereo_anaglyph_mask_default_ ? red_blue.val : magenta_green.val);
                stereo_anaglyph_mask_default_ = !stereo_anaglyph_mask_default_;
            }
            window->SetStereoRender(!window->GetStereoRender());
            Interactor->Render();
        }
        else
            Superclass::OnKeyDown();
        break;
    }

    case 'o': case 'O':
    {
        vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera();
        cam->SetParallelProjection(!cam->GetParallelProjection());
        CurrentRenderer->Render();
        break;
    }

        // Overwrite the camera reset
    case 'r': case 'R':
    {
        if (!alt)
        {
            Superclass::OnKeyDown();
            break;
        }

        WidgetActorMap::iterator it = widget_actor_map_->begin();
        // it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault.
        for (; it != widget_actor_map_->end();  ++it)
        {
            vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
            if (actor && actor->GetUserMatrix())
                break;
        }

        vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera();

        // if a valid transformation was found, use it otherwise fall back to default view point.
        if (it != widget_actor_map_->end())
        {
            vtkMatrix4x4* m = vtkProp3D::SafeDownCast(it->second)->GetUserMatrix();

            cam->SetFocalPoint(m->GetElement(0, 3) - m->GetElement(0, 2),
                               m->GetElement(1, 3) - m->GetElement(1, 2),
                               m->GetElement(2, 3) - m->GetElement(2, 2));

            cam->SetViewUp  (m->GetElement(0, 1), m->GetElement(1, 1), m->GetElement(2, 1));
            cam->SetPosition(m->GetElement(0, 3), m->GetElement(1, 3), m->GetElement(2, 3));
        }
        else
        {
            cam->SetPosition(0, 0, 0);
            cam->SetFocalPoint(0, 0, 1);
            cam->SetViewUp(0, -1, 0);
        }

        // go to the next actor for the next key-press event.
        if (it != widget_actor_map_->end())
            ++it;
        else
            it = widget_actor_map_->begin();

        CurrentRenderer->SetActiveCamera(cam);
        CurrentRenderer->ResetCameraClippingRange();
        CurrentRenderer->Render();
        break;
    }

    case 'q': case 'Q':
    {
        Interactor->ExitCallback();
        return;
    }
    default:
    {
        Superclass::OnKeyDown();
        break;
    }
    }

    KeyboardEvent event(KeyboardEvent::KEY_DOWN, Interactor->GetKeySym(), Interactor->GetKeyCode(), getModifiers());
    if (keyboardCallback_)
        keyboardCallback_(event, keyboard_callback_cookie_);
    Interactor->Render();
}
int main(int argc, char** argv) {
  init(argc, argv);

  std::string image_format = argv[1];
  int n = boost::lexical_cast<int>(argv[2]);
  CHECK(n > 0) << "Need at least one frame, two would be great";
  cv::Size screen_size(FLAGS_width, FLAGS_height);
  double rho = FLAGS_rho;
  double lambda = FLAGS_lambda;

  // Pre-load images.
  LOG(INFO) << "Loading images...";
  std::vector<cv::Mat> color_images;
  loadImages(image_format, n, screen_size, color_images);

  // Convert to grayscale.
  LOG(INFO) << "Loaded " << color_images.size() << " images";
  std::vector<cv::Mat> gray_images;
  std::vector<cv::Mat>::const_iterator color_image;
  for (color_image = color_images.begin();
       color_image != color_images.end();
       ++color_image) {
    cv::Mat gray_image;
    cv::cvtColor(*color_image, gray_image, CV_BGR2GRAY);
    gray_images.push_back(gray_image);
  }

  TrackList<cv::Point2d> track;

  bool exit = false;
  State state;
  state.clicked = false;

  cv::namedWindow("video");
  cv::setMouseCallback("video", onMouse, &state);

  // Display the image and ask the user to click a point.
  cv::imshow("video", color_images[0]);

  while (!state.clicked) {
    cv::waitKey(10);
  }

  // Extract a patch for cross-correlation.
  cv::Mat original;
  {
    cv::Point offset(state.point.x - RADIUS, state.point.y - RADIUS);
    cv::Rect region(offset, cv::Size(DIAMETER, DIAMETER));
    original = gray_images.front()(region);
  }

  // Match the template to every image.
  std::vector<cv::Mat> responses;
  LOG(INFO) << "Performing cross-correlation...";
  std::vector<cv::Mat>::const_iterator image;
  for (image = gray_images.begin(); image != gray_images.end(); ++image) {
    // Evaluate response to template.
    cv::Mat response;
    cv::matchTemplate(*image, original, response, cv::TM_CCORR_NORMED);
    // Convert to 64-bit.
    response = cv::Mat_<double>(response);
    response = -1. * response;
    // Add to list.
    responses.push_back(response);
  }

  // Solve dynamic program.
  cv::Mat x_star = cv::Mat_<double>(n, 2, 0.);
  LOG(INFO) << "Solving dynamic program...";
  {
    std::vector<cv::Mat> scaled;
    std::vector<cv::Mat>::const_iterator response;
    for (response = responses.begin();
         response != responses.end();
         ++response) {
      scaled.push_back(cv::Mat(1. / lambda * (*response)));
    }

    std::vector<cv::Vec2i> x;
    solveViterbiQuadratic2D(scaled, x);

    std::vector<cv::Vec2i>::const_iterator x_t;
    int t = 0;
    for (x_t = x.begin(); x_t != x.end(); ++x_t) {
      x_star.at<double>(t, 0) = (*x_t)[1];
      x_star.at<double>(t, 1) = (*x_t)[0];
      t += 1;
    }
  }

  LOG(INFO) << "Solving ADMM...";

  // Guess Lagrange multipliers to all be zero.
  cv::Mat x = cv::Mat_<double>(n, 2, 0.);
  // Initialize track positions to origin.
  cv::Mat z = cv::Mat_<double>(n, 2, 0.);
  // Smoothest path will also be origin.
  cv::Mat u = cv::Mat_<double>(n, 2, 0.);

  while (!exit) {
    LOG(INFO) << "rho => " << rho;

    // Solve first sub-problem.
    for (int t = 0; t < n; t += 1) {
      cv::Point2d z_t(z.at<double>(t, 0), z.at<double>(t, 1));
      cv::Point2d u_t(u.at<double>(t, 0), u.at<double>(t, 1));

      cv::Point2d x_t;
      findBestResponse(z_t, u_t, responses[t], rho, x_t);

      x.at<double>(t, 0) = x_t.x;
      x.at<double>(t, 1) = x_t.y;
    }
    //LOG(INFO) << "x-update: norm(x - z) => " << cv::norm(x - z) / n;

    cv::Mat z_old = z.clone();

    // Solve second sub-problem.
    for (int d = 0; d < 2; d += 1) {
      cv::Mat dst = z.col(d);
      findSmoothestPath(x.col(d), u.col(d), rho, lambda, dst);
    }
    //LOG(INFO) << "z-update: norm(x - z) => " << cv::norm(x - z) / n;

    // Update multipliers.
    u += x - z;

    cv::Mat r = x - z;
    cv::Mat s = rho * (z - z_old);

    LOG(INFO) << "norm(r) => " << cv::norm(r);
    LOG(INFO) << "norm(s) => " << cv::norm(s);
    LOG(INFO) << "norm(x - x_star) / n => " << cv::norm(x - x_star) / n;

    // Play the video.
    for (int t = 0; t < n; t += 1) {
      cv::Mat display = color_images[t].clone();

      // Draw tracks on frame.
      cv::Point2d pt1;
      cv::Point2d pt2;

      pt1 = cv::Point2d(x_star.at<double>(t, 0), x_star.at<double>(t, 1));
      pt2 = pt1 + cv::Point2d(DIAMETER, DIAMETER);
      cv::rectangle(display, pt1, pt2, cv::Scalar(0, 0x99, 0), 2);

      pt1 = cv::Point2d(z.at<double>(t, 0), z.at<double>(t, 1));
      pt2 = pt1 + cv::Point2d(DIAMETER, DIAMETER);
      cv::rectangle(display, pt1, pt2, cv::Scalar(0xFF, 0, 0), 2);

      pt1 = cv::Point2d(x.at<double>(t, 0), x.at<double>(t, 1));
      pt2 = pt1 + cv::Point2d(DIAMETER, DIAMETER);
      cv::rectangle(display, pt1, pt2, cv::Scalar(0, 0, 0xFF), 2);

      cv::imshow("video", display);
      cv::waitKey(10);
    }

    if (rho < 1.) {
      cv::Mat y = rho * u;
      rho = rho * FLAGS_rho_step;
      u = 1. / rho * y;
    }
  }

  return 0;
}
示例#8
0
// Write out the config file for the whole application
int configAppSaveXml()
{
	if (bCmdOptUsed) {
		return 1;
	}

	char configName[MAX_PATH];
	createConfigName(configName);

	try {
		char tempStr[64] = "";

		// root
		ticpp::Document doc;
		ticpp::Declaration decl("1.0", "UTF-8", "");
		doc.LinkEndChild(&decl);

		ticpp::Element root("configuration");
		setAttr(root, "version", configVersion);
		ticpp::Comment comment("Don't edit this file manually unless you know what you're doing\n" \
					APP_TITLE " will restore default settings when this file is deleted");
		doc.LinkEndChild(&comment);
		doc.LinkEndChild(&root);

		// title
		sprintf(tempStr, "0x%06X", nBurnVer);
		addTextNode(root, "version", tempStr);

		// emulation
		ticpp::Element emulation("emulation");
		root.LinkEndChild(&emulation);
		setAttr(emulation, "asm-68k", bBurnUseASM68K);
		setAttr(emulation, "all-ram", bDrvSaveAll);

		// video
		ticpp::Element video("video");
		root.LinkEndChild(&video);

		ticpp::Element fullscreen("fullscreen");
		video.LinkEndChild(&fullscreen);
		setAttr(fullscreen, "width", nVidWidth);
		setAttr(fullscreen, "height", nVidHeight);
		setAttr(fullscreen, "depth", nVidDepth);
		setAttr(fullscreen, "refresh", nVidRefresh);

		ticpp::Element adjust("adjust");
		video.LinkEndChild(&adjust);
		setAttr(adjust, "rotate-vertical", nVidRotationAdjust);

		ticpp::Element screen_size("screen-size");
		video.LinkEndChild(&screen_size);
		setAttr(screen_size, "window", nWindowSize);

		ticpp::Element window_position("window-position");
		video.LinkEndChild(&window_position);
		setAttr(window_position, "x", nWindowPosX);
		setAttr(window_position, "y", nWindowPosY);

		ticpp::Element stretch("stretch");
		video.LinkEndChild(&stretch);
		setAttr(stretch, "full-stretch", bVidFullStretch);
		setAttr(stretch, "correct-aspect", bVidCorrectAspect);

		ticpp::Element color("color");
		video.LinkEndChild(&color);
		setAttr(color, "enable", bcolorAdjust);
		setAttr(color, "contrast", color_contrast);
		setAttr(color, "brightness", color_brightness);
		setAttr(color, "gamma", color_gamma);
		setAttr(color, "grayscale", color_grayscale);
		setAttr(color, "invert", color_invert);

		ticpp::Element vsync("vsync");
		video.LinkEndChild(&vsync);
		setAttr(vsync, "enable", bVidVSync);

		ticpp::Element triple_buffer("triple-buffer");
		video.LinkEndChild(&triple_buffer);
		setAttr(triple_buffer, "enable", bVidTripleBuffer);

		// video render
		ticpp::Element render("render");
		video.LinkEndChild(&render);

		ticpp::Element render_driver("render-driver");
		render.LinkEndChild(&render_driver);
		setAttr(render_driver, "driver", nVidSelect);
		setAttr(render_driver, "adapter", nVidAdapter);

		ticpp::Element filter("filter");
		render.LinkEndChild(&filter);
		setAttr(filter, "linear", vidFilterLinear);
		setAttr(filter, "use-pixelfilter", vidUseFilter);
		setAttr(filter, "pixel-filter", nVidFilter);

		ticpp::Element option("option");
		render.LinkEndChild(&option);
		setAttr(option, "force-16bit", bVidForce16bit);
		setAttr(option, "hardware-vertex", vidHardwareVertex);
		setAttr(option, "motion-blur", vidMotionBlur);
		setAttr(option, "projection", nVid3DProjection);
		setAttr(option, "angel", fVidScreenAngle);
		setAttr(option, "curvature", fVidScreenCurvature);
		setAttr(option, "dxmanager", nVidDXTextureManager);

		setAttr(option, "x-offset", nXOffset);
		setAttr(option, "y-offset", nYOffset);
		setAttr(option, "x-scale",  nXScale);
		setAttr(option, "y-scale",  nYScale);

		// video others
		ticpp::Element monitor("monitor");
		video.LinkEndChild(&monitor);
		setAttr(monitor, "auto-aspect", autoVidScrnAspect);
		setAttr(monitor, "aspect-x", nVidScrnAspectX);
		setAttr(monitor, "aspect-y", nVidScrnAspectY);

		ticpp::Element frame("frame");
		video.LinkEndChild(&frame);
		setAttr(frame, "auto-frameskip", autoFrameSkip);
		setAttr(frame, "force-60hz", bForce60Hz);

		// audio
		ticpp::Element audio("audio");
		root.LinkEndChild(&audio);
		addTextNode(audio, "sound", audSelect);

		ticpp::Element device("device");
		audio.LinkEndChild(&device);
		setAttr(device, "ds", dsDevice);
		setAttr(device, "xa2", xa2Device);
		setAttr(device, "oal", oalDevice);

		ticpp::Element audio_set("setting");
		audio.LinkEndChild(&audio_set);
		setAttr(audio_set, "rate", nAudSampleRate);
		setAttr(audio_set, "frame", nAudSegCount);
		setAttr(audio_set, "dsp", nAudDSPModule);
		setAttr(audio_set, "pcm-interp", nInterpolation);
		setAttr(audio_set, "fm-interp", nFMInterpolation);
		setAttr(audio_set, "stereo-upmix", audStereoUpmixing);

		// gui
		ticpp::Element gui("gui");
		root.LinkEndChild(&gui);
		addTextNode(gui, "language", szLanguage);
		//addTextNode(gui, "gamelist", szTransGamelistFile);

		ticpp::Element chat("chat-font");
		gui.LinkEndChild(&chat);
		setAttr(chat, "min-size", nMinChatFontSize);
		setAttr(chat, "max-size", nMaxChatFontSize);

		ticpp::Element menu("menu");
		gui.LinkEndChild(&menu);
		setAttr(menu, "modeless", bModelessMenu);
		setAttr(menu, "style", menuNewStyle);

		ticpp::Element gui_misc("gui-misc");
		gui.LinkEndChild(&gui_misc);
		setAttr(gui_misc, "on-top", bShowOnTop);
		setAttr(gui_misc, "auto-fullscreen", bFullscreenOnStart);
		setAttr(gui_misc, "lastRom", nLastRom);
		setAttr(gui_misc, "lastFilter", nLastFilter);

		setAttr(gui_misc, "hideChildren", HideChildren);
		setAttr(gui_misc, "showThreeFourPlayerOnly", ThreeOrFourPlayerOnly);
		setAttr(gui_misc, "arcadeJoyStickSettings", ArcadeJoystick);

		// gui load game dialog
		ticpp::Element gamelist("gamelist-dlg");
		gui.LinkEndChild(&gamelist);
		setAttr(gamelist, "options", nLoadMenuShowX);
		//setAttr(gamelist, "drivers", nLoadDriverShowX);
		//setAttr(gamelist, "sys-sel", nSystemSel);
		//setAttr(gamelist, "tab-sel", nTabSel);
		//addTextNode(gamelist, "user-filter", szUserFilterStr);

		// gui ips
		ticpp::Element ips("ips");
		gui.LinkEndChild(&ips);
		setAttr(ips, "language", nPatchLang);
		setAttr(ips, "dependancy", bEnforceDep);

		//ticpp::Element skin("skin");
		//gui.LinkEndChild(&skin);
		//setAttr(skin, "use-placeholder", bVidUsePlaceholder);
		//setAttr(skin, "random", nRandomSkin);
		//addTextNode(skin, NULL, szPlaceHolder);

		// preferences
		ticpp::Element preference("preferences");
		root.LinkEndChild(&preference);

		ticpp::Element settings("settings");
		preference.LinkEndChild(&settings);
		setAttr(settings, "always-processkey", bAlwaysProcessKey);
		setAttr(settings, "auto-pause", bAutoPause);
		//setAttr(settings, "avi-audio", nAviIntAudio);
		//setAttr(settings, "use-gdip", bUseGdip);
		ticpp::Element fastforward("fastforward");
		preference.LinkEndChild(&fastforward);
		setAttr(fastforward, "speed", nFastSpeed);
		ticpp::Element thread("thread");
		preference.LinkEndChild(&thread);
		setAttr(thread, "priority", nAppThreadPriority);
		ticpp::Element autofire("autofire");
		preference.LinkEndChild(&autofire);
		setAttr(autofire, "enable", nAutofireEnabled);
		setAttr(autofire, "default-delay", autofireDefaultDelay);
		ticpp::Element macro("macro");
		preference.LinkEndChild(&macro);
		setAttr(macro, "enable", nInputMacroEnabled);

		// pref misc
		ticpp::Element pref_misc("misc");
		preference.LinkEndChild(&pref_misc);
		setAttr(pref_misc, "effect", nShowEffect);

		ticpp::Element controls("controls");
		preference.LinkEndChild(&controls);
		for (int i = 0; i < 4; i++) {
			sprintf(tempStr, "default%d", i);
			addTextNode(controls, tempStr, szPlayerDefaultIni[i]);
		}

		// paths
		ticpp::Element paths("paths");
		root.LinkEndChild(&paths);

		ticpp::Element rom_path("rom");
		paths.LinkEndChild(&rom_path);
		for (int i = 0; i < DIRS_MAX; i++) {
			addTextNode(rom_path, "path", szAppRomPaths[i]);
		}

		ticpp::Element misc_path("misc");
		paths.LinkEndChild(&misc_path);
		for (int i = PATH_PREVIEW; i < PATH_SUM; i++) {
			sprintf(tempStr, "path%d", i);
			addTextNode(misc_path, tempStr, szMiscPaths[i]);
		}

		// hotkeys
		ticpp::Element hotkeys("hotkeys");
		root.LinkEndChild(&hotkeys);

		/*for (int i = 0; !lastCustomKey(customKeys[i]); i++) {
			CustomKey& customkey = customKeys[i];

			ticpp::Element key(customkey.config_code);
			hotkeys.LinkEndChild(&key);
			setAttr(key, "key", customkey.key);
			setAttr(key, "mod", customkey.keymod);
		}*/

		// save file
		doc.SaveFile(configName, TIXML_ENCODING_UTF8);
	}
	catch (ticpp::Exception& ex) {
		return 1;
	}

	return 0;
}
示例#9
0
文件: Screen.cpp 项目: njun-git/kvs
/*===========================================================================*/
Screen::Screen( kvs::tdw::Application* application ):
    kvs::ScreenBase()
{
    if ( application ) application->attach( this );

    // Create a camera for TDW instead of the default camera.
    if ( BaseClass::m_camera ) delete BaseClass::m_camera;
    BaseClass::m_camera = new kvs::tdw::Camera();

    m_paint_event_func = &Screen::default_paint_event;
    m_resize_event_func = &Screen::default_resize_event;

    if ( kvs::tdw::Application::IsRenderer() )
    {
        m_mouse_press_event_func = 0;
        m_mouse_move_event_func = 0;
        m_mouse_release_event_func = 0;
        m_wheel_event_func = 0;
        m_key_press_event_func = 0;

        m_idle_mouse_event_listener = 0;
        m_idle_mouse_timer = 0;

        kvs::Vector2i origin = kvs::tdw::Configuration::Renderer().origin();
        kvs::Vector2i size = kvs::tdw::Configuration::Renderer().size();
        kvs::Vector2i screen_size( glutGet( (GLenum)GLUT_SCREEN_WIDTH ), glutGet( (GLenum)GLUT_SCREEN_HEIGHT ) );
        if ( origin.x() + size.x() > screen_size.x() || screen_size.x() <= 0 ) origin.x() = 0;
        if ( origin.y() + size.y() > screen_size.y() || screen_size.y() <= 0 ) origin.y() = 0;
        this->set_position( origin.x(), origin.y() );
        this->set_size( size.x(), size.y() );

        RendererEvent = new kvs::tdw::RendererPaintEvent();
        DefalutKeyPressEvent* key_press = new DefalutKeyPressEvent( this );
        RendererEvent->attach( key_press );

        RendererEvent->setScreen( this );
        BaseClass::eventHandler()->attach( RendererEvent );
    }
    else
    {
        m_mouse_press_event_func = &Screen::default_mouse_press_event;
        m_mouse_move_event_func = &Screen::default_mouse_move_event;
        m_mouse_release_event_func = &Screen::default_mouse_release_event;
        m_wheel_event_func = &Screen::default_wheel_event;
        m_key_press_event_func = &Screen::default_key_press_event;

        m_idle_mouse_event_listener = new ::IdleMouseEvent( this );
        m_idle_mouse_timer = new kvs::tdw::Timer( m_idle_mouse_event_listener );

        kvs::Vector2i size = kvs::tdw::Configuration::Master().resolution();
        const float aspect = (float)size.x() / size.y();
        if ( aspect > 1.0 ) this->set_size( 512, 512 / aspect );
        else                this->set_size( 512 * aspect, 512 );

        MasterSender = new kvs::tdw::MasterMessageSender( this );
    }

    m_initialize_event_handler = new kvs::EventHandler();

    BaseClass::m_elapse_time_counter.start();
}
示例#10
0
文件: scene.cpp 项目: tuxerr/City
Scene::Scene(Display *disp) : 
    light_number(0), disp(disp), camera_changed(false), 
    octree(Vec3<float>(0,0,0),Vec3<float>(4096,4096,4096))
{
    // program initialisation
    disp->new_program("shaders/default.vert","shaders/default.frag",NULL,NULL,NULL);
    disp->new_program("shaders/fullscreen_draw.vert","shaders/phong.frag",NULL,NULL,NULL,"phong");
    disp->new_program("shaders/blur_vertical.vert","shaders/blur.frag",NULL,NULL,NULL,"vertical_blur");
    disp->new_program("shaders/blur_horizontal.vert","shaders/blur.frag",NULL,NULL,NULL,"horizontal_blur");
    disp->new_program("shaders/pointlight_draw.vert","shaders/phong_pointlight.frag",NULL,NULL,NULL,"phong_pointlight");
    disp->new_program("shaders/pointlight_draw.vert","shaders/depth_creation.frag",NULL,NULL,NULL,"phong_pointlight_stencil");
    disp->new_program("shaders/depth_creation.vert","shaders/depth_creation.frag",NULL,NULL,NULL,"depth_creation");
    disp->new_program("shaders/displaytexture.vert","shaders/displaytexture.frag",NULL,NULL,NULL,"display_texture");
    //disp->new_program("shaders/deferred_tess.vert","shaders/deferred_tess.frag","shaders/terrain_tc.tess","shaders/terrain_te.tess",NULL,"deferred_tess");
    disp->new_program("shaders/deferred.vert","shaders/deferred.frag",NULL,NULL,NULL,"deferred");

    int screen_width=disp->get_width();
    int screen_height=disp->get_height();

    globalvalues=disp->new_uniformblock("GlobalValues");
    disp->link_program_to_uniformblock("default",globalvalues);
    disp->link_program_to_uniformblock("phong",globalvalues);
    disp->link_program_to_uniformblock("phong_pointlight",globalvalues);
    disp->link_program_to_uniformblock("phong_pointlight_stencil",globalvalues);
    disp->link_program_to_uniformblock("depth_creation",globalvalues);
    disp->link_program_to_uniformblock("deferred",globalvalues);
    disp->link_program_to_uniformblock("display_texture",globalvalues);
    disp->link_program_to_uniformblock("vertical_blur",globalvalues);
    disp->link_program_to_uniformblock("horizontal_blur",globalvalues);

    
    Vec2<float> screen_size(screen_width,screen_height);
    globalvalues->set_value(screen_size, "screen_size");

    for(int i=0;i<MAX_LIGHTS;i++) {
        lights[i]=NULL;
    }
    
    if(disp->has_program("phong")) {
        uniform_cascaded_shading_zdelta=disp->new_uniform("cascaded_shading_zdelta",UNIFORM_FLOAT);
        disp->link_program_to_uniform("phong",uniform_cascaded_shading_zdelta);

        uniform_phong_normalmap=disp->new_uniform("normalmap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_phong_normalmap);

        uniform_phong_depthmap=disp->new_uniform("depthmap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_phong_depthmap);

        uniform_phong_colormap=disp->new_uniform("colormap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_phong_colormap);

        uniform_phong_texcoordmap=disp->new_uniform("texcoordmap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_phong_texcoordmap);

        uniform_light=disp->new_uniformblock("Light");
        disp->link_program_to_uniformblock("phong",uniform_light);
        
        uniform_light_sampler=disp->new_uniform("shadowmap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_light_sampler);

            //uniform_name.str("");
            //uniform_name<<"shadowcubemap["<<i<<"]";
            //uniform_light_samplercube[i]=disp->new_uniform(uniform_name.str(),UNIFORM_SAMPLER);
            //disp->link_program_to_uniform("phong",uniform_light_samplercube[i]);
        

    }
    if(disp->has_program("phong_pointlight")) {
        disp->link_program_to_uniform("phong_pointlight",uniform_phong_normalmap);
        disp->link_program_to_uniform("phong_pointlight",uniform_phong_depthmap);
        disp->link_program_to_uniform("phong_pointlight",uniform_phong_colormap);
        disp->link_program_to_uniformblock("phong_pointlight",uniform_light);
    }
    if(disp->has_program("vertical_blur")) {
        uniform_postprocess_colormap=disp->new_uniform("deferred_colormap",UNIFORM_SAMPLER);

        //disp->link_program_to_uniform("blur_vertical",uniform_phong_normalmap);
        //disp->link_program_to_uniform("blur_vertical",uniform_phong_depthmap);
        disp->link_program_to_uniform("vertical_blur",uniform_postprocess_colormap);
    }
    if(disp->has_program("horizontal_blur")) {
        //disp->link_program_to_uniform("blur_horizontal",uniform_phong_normalmap);
        //disp->link_program_to_uniform("blur_horizontal",uniform_phong_depthmap);
        disp->link_program_to_uniform("horizontal_blur",uniform_postprocess_colormap);
    }
    if(disp->has_program("depth_creation")) {
        uniform_light_projection=disp->new_uniformblock("Light_properties");
        disp->link_program_to_uniformblock("depth_creation",uniform_light_projection);
    }
    if(disp->has_program("display_texture")) {
        uniform_displaytex_tex = disp->new_uniform("tex",UNIFORM_SAMPLER);
        uniform_displaytex_arraytex = disp->new_uniform("arraytex",UNIFORM_SAMPLER);
        uniform_displaytex_choice = disp->new_uniform("choice",UNIFORM_INT);
        disp->link_program_to_uniform("display_texture",uniform_displaytex_tex);
        disp->link_program_to_uniform("display_texture",uniform_displaytex_arraytex);
        disp->link_program_to_uniform("display_texture",uniform_displaytex_choice);
    }

    generate_fullscreen_quad();
    generate_cube(); //cube centered at 0,0,0 and of size 2 (-1 to 1)
    
    // textures initialization
    null_colortex=new Texture(DEPTH_TEXTURE_SIZE,DEPTH_TEXTURE_SIZE,TEXTURE_RGBA);
    deferred_colormap=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    deferred_normalmap=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    deferred_texcoordmap=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    deferred_depthmap=new Texture(screen_width,screen_height,TEXTURE_DEPTH);
    deferred_result=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    postprocess_flip1=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    postprocess_flip2=new Texture(screen_width,screen_height,TEXTURE_RGBA);

    // uniform setting
    uniform_phong_normalmap->set_value(deferred_normalmap);
    uniform_phong_colormap->set_value(deferred_colormap);
    uniform_phong_texcoordmap->set_value(deferred_texcoordmap);
    uniform_phong_depthmap->set_value(deferred_depthmap);

    uniform_displaytex_tex->set_value(postprocess_flip2);
    uniform_displaytex_choice->set_value(-1);
    
    //rendering FBOs initialization
    fbo_shadows.attach_texture(null_colortex,FBO_COLOR0);
    
    fbo_deferred_phong.attach_texture(deferred_result,FBO_COLOR0);
    fbo_deferred_phong.attach_texture(deferred_depthmap,FBO_DEPTH);
    
    fbo_deferred.attach_texture(deferred_normalmap,FBO_COLOR0);
    fbo_deferred.attach_texture(deferred_colormap,FBO_COLOR1);
    fbo_deferred.attach_texture(deferred_texcoordmap,FBO_COLOR2);
    fbo_deferred.attach_texture(deferred_depthmap,FBO_DEPTH);
}
示例#11
0
int
PingusMain::run(int argc, char** argv)
{
  g_logger.set_log_level(Logger::kWarning);

  tinygettext::Log::set_log_info_callback(0);

  try
  {
    // FIXME force set language using System::get_language() to get it from env
    dictionary_manager.set_language(tinygettext::Language::from_env(System::get_language()));
    
    parse_args(argc, argv); // here language and po dir isn't set, no traslation in command line
    init_path_finder(); // here init language path
    read_rc_file(); // here set language if ~/.pingus/config exist and language value is set
    apply_args(); // here set language if arg -l is specified
    
    print_greeting_message();
    
    // init the display
    FramebufferType fbtype = SDL_FRAMEBUFFER; 
    if (cmd_options.framebuffer_type.is_set())
    {
      fbtype = cmd_options.framebuffer_type.get();
    }

    bool fullscreen = cmd_options.fullscreen.is_set() ? cmd_options.fullscreen.get() : false;
    bool resizable  = cmd_options.resizable.is_set()  ? cmd_options.resizable.get()  : true;

    Size screen_size(800, 600);
    if (fullscreen)
    {
      if (cmd_options.fullscreen_resolution.is_set())
      {
        screen_size = cmd_options.fullscreen_resolution.get();
      }
    }
    else
    {
      if (cmd_options.geometry.is_set())
      {
        screen_size = cmd_options.geometry.get();
      }
    }

    SDLSystem system;
    try
    {
      system.create_window(fbtype, screen_size, fullscreen, resizable);
    }
    catch(const std::exception& err)
    {
      if (fbtype == SDL_FRAMEBUFFER)
      {
        throw;
      }
      else
      {
        log_error("couldn't create window, falling back to SDL: " << err.what());
        system.create_window(SDL_FRAMEBUFFER, screen_size, fullscreen, resizable);
        config_manager.set_renderer(SDL_FRAMEBUFFER);
      }
    }

    // init other components
    SavegameManager savegame_manager("savegames/savegames.scm");
    StatManager stat_manager("savegames/variables.scm");

    // FIXME: turn these into RAII 
    Resource::init();
    Fonts::init();
    Sound::PingusSound::init();
    
    config_manager.apply(cmd_options);

    // start and run the actual game
    start_game();
  }
  catch (const std::bad_alloc&) 
  {
    std::cout << _("Pingus: Out of memory!") << std::endl;
  }
  catch (const std::exception& a) 
  {
    std::cout << _("Pingus: Standard exception caught!:\n") << a.what() << std::endl;
  }
  catch (...) 
  {
    std::cout << _("Pingus: Unknown throw caught!") << std::endl;
  }

  Sound::PingusSound::deinit();
  Fonts::deinit();
  WorldObjFactory::deinit();
  Resource::deinit();

  return 0;
}