Exemple #1
0
/*!	This works only after console_init() was called.
*/
extern "C" void
panic(const char* format, ...)
{
	const char hint[] = "*** PANIC ***";
	char buffer[512];
	va_list list;
	int length;

	platform_switch_to_text_mode();

	serial_puts(hint, sizeof(hint));
	serial_puts("\n", 1);
	//fprintf(stderr, "%s", hint);
	puts(hint);

	va_start(list, format);
	length = vsnprintf(buffer, sizeof(buffer), format, list);
	va_end(list);

	if (length >= (int)sizeof(buffer))
		length = sizeof(buffer) - 1;

	serial_puts(buffer, length);
	//fprintf(stderr, "%s", buffer);
	puts(buffer);

	puts("\nPress key to reboot.");

	clear_key_buffer();
	wait_for_key();
	platform_exit();
}
Exemple #2
0
void target_shutdown(void)
{
	enter_critical_section();
	
	if(fbcon_display())
		htcleo_display_shutdown();
	platform_exit();
	msm_proc_comm(PCOM_POWER_DOWN, 0, 0);
	for (;;) ;
}
Exemple #3
0
void target_reboot(unsigned reboot_reason)
{
	enter_critical_section();
	
	if(fbcon_display())
		htcleo_display_shutdown();
	platform_exit();
	writel(reboot_reason, LK_BOOTREASON_ADDR);
	writel(reboot_reason^MARK_LK_TAG, LK_BOOTREASON_ADDR + 4);
	reboot(reboot_reason);
}
Exemple #4
0
void GameManager::run()
{
    init();

#ifdef CHOWDREN_IS_EMSCRIPTEN
    emscripten_set_main_loop(_emscripten_run, 0, 1);
#else
    while (true) {
        if (!update())
            break;
    }
    frame->data->on_app_end();
    frame->data->on_end();
    media.stop();
    platform_exit();
#endif
}
Exemple #5
0
/*!	This works only after console_init() was called.
*/
extern "C" void
panic(const char* format, ...)
{
	va_list list;

	platform_switch_to_text_mode();

	puts("*** PANIC ***");

	va_start(list, format);
	vprintf(format, list);
	va_end(list);

	puts("\nPress key to reboot.");

	clear_key_buffer();
	wait_for_key();
	platform_exit();
}
Exemple #6
0
void
platform_handle_events(Input *in)
{
	Window active;
	int revert_to;
	XGetInputFocus(g_pctx.display, &active, &revert_to);
	// TODO: Stop updating the camera if the mouse pointer isn't inside our window?
	if (active == g_pctx.window)
		platform_update_mouse_pos(&in->mouse);

	// TODO: Set up an auto-pause when we lose focus?
	XEvent xev;
	while (XPending(g_pctx.display)) {
		XNextEvent(g_pctx.display, &xev);
		switch(xev.type) {
		case KeyPress: {
			input_key_down(&in->keyboard, xev.xkey.keycode);
		} break;
		case KeyRelease: {
			input_key_up(&in->keyboard, xev.xkey.keycode);
		} break;
		case ButtonPress: {
			input_mbutton_down((Mouse_Button)xev.xbutton.button, &in->mouse);
		} break;
		case ButtonRelease: {
			input_mbutton_up((Mouse_Button)xev.xbutton.button, &in->mouse);
		} break;
		case FocusOut: {
			in->mouse.motion = {0,0}; // Clear residual mouse motion so we don't keep using it in cam calculations.
		} break;
		case FocusIn: {
			platform_update_mouse_pos(&in->mouse); // Reset mouse position so the view doesn't "jump" when we regain focus.
		} break;
		case ClientMessage:
			if ((Atom)xev.xclient.data.l[0] == g_pctx.wm_delete_window)
				platform_exit();
		}
	}
}
Exemple #7
0
extern "C" void
panic(const char* format, ...)
{
	const char hint[] = "\n*** PANIC ***\n";
	char buffer[512];
	va_list list;
	int length;

	serial_puts(hint, sizeof(hint));
	va_start(list, format);
	length = vsnprintf(buffer, sizeof(buffer), format, list);
	va_end(list);

	if (length >= (int)sizeof(buffer))
		length = sizeof(buffer) - 1;

	serial_puts(buffer, length);
	//fprintf(stderr, "%s", buffer);

	serial_puts("\nPress key to reboot.", 21);

	platform_exit();
}
Exemple #8
0
static bool
user_menu_reboot(Menu *menu, MenuItem *item)
{
    platform_exit();
    return true;
}
Exemple #9
0
int
main()
{
	GLXFBConfig fbconfig;
	Vec2u screen_dim { 1200, 900 };

	// create window
	{
		int buffer_attribs[] = {
			GLX_X_RENDERABLE    , True,
			GLX_DRAWABLE_TYPE   , GLX_WINDOW_BIT,
			GLX_RENDER_TYPE     , GLX_RGBA_BIT,
			GLX_X_VISUAL_TYPE   , GLX_TRUE_COLOR,
			GLX_RED_SIZE        , 8,
			GLX_GREEN_SIZE      , 8,
			GLX_BLUE_SIZE       , 8,
			GLX_ALPHA_SIZE      , 8,
			GLX_DEPTH_SIZE      , 24,
			GLX_STENCIL_SIZE    , 8,
			GLX_DOUBLEBUFFER    , True,
			//GLX_SAMPLE_BUFFERS  , 1,
			//GLX_SAMPLES         , 4,
			None
		};

		g_pctx.display = XOpenDisplay(NULL);
		if (!g_pctx.display)
			zabort("failed to create display");
		int xscreen = XDefaultScreen(g_pctx.display), num_fbconfigs;
		GLXFBConfig *fbconfigs = glXChooseFBConfig(g_pctx.display, xscreen, buffer_attribs, &num_fbconfigs);
		if (!fbconfigs)
			zabort("Failed to retrieve frame buffer configs");
		int best_fbc = -1, best_num_samp = -1;
		for (int i = 0; i < num_fbconfigs; ++i) {
			XVisualInfo *visual = glXGetVisualFromFBConfig(g_pctx.display, fbconfigs[i]);
			if (visual) {
				int samp_buf, samples;
				glXGetFBConfigAttrib(g_pctx.display, fbconfigs[i], GLX_SAMPLE_BUFFERS, &samp_buf);
				glXGetFBConfigAttrib(g_pctx.display, fbconfigs[i], GLX_SAMPLES, &samples);

				if (best_fbc < 0 || (samp_buf && samples > best_num_samp))
					best_fbc = i, best_num_samp = samples;
				//if (worst_fbc < 0 || !samp_buf || samples < worst_num_samp)
					//worst_fbc = i, worst_num_samp = samples;
			}
			XFree(visual);
		}
		if (best_fbc < 0)
			zabort("failed to get a frame buffer");
		fbconfig = fbconfigs[0];
		XFree(fbconfigs);

		XVisualInfo *visual = glXGetVisualFromFBConfig(g_pctx.display, fbconfig);
		Window root = DefaultRootWindow(g_pctx.display);
		XSetWindowAttributes win_attribs;
		win_attribs.colormap = XCreateColormap(g_pctx.display, root, visual->visual, AllocNone);
		win_attribs.background_pixmap = None;
		win_attribs.border_pixmap = None;
		win_attribs.border_pixel = 0;
		win_attribs.event_mask =
			StructureNotifyMask |
			FocusChangeMask |
			EnterWindowMask |
			LeaveWindowMask |
			ExposureMask |
			ButtonPressMask |
			ButtonReleaseMask |
			OwnerGrabButtonMask |
			KeyPressMask |
			KeyReleaseMask;

		int win_attribs_mask = 
			CWBackPixmap|
			CWColormap|
			CWBorderPixel|
			CWEventMask;

		assert(visual->c_class == TrueColor);
		g_pctx.window = XCreateWindow(g_pctx.display, root, 0, 0, screen_dim.x, screen_dim.y, 0, visual->depth, InputOutput, visual->visual, win_attribs_mask, &win_attribs);
		if (!g_pctx.window)
			zabort("Failed to create a window.\n");
		XFree(visual);
		XStoreName(g_pctx.display, g_pctx.window, "cge");
		XMapWindow(g_pctx.display, g_pctx.window);
		if ((g_pctx.wm_delete_window = XInternAtom(g_pctx.display, "WM_DELETE_WINDOW", 1)))
			XSetWMProtocols(g_pctx.display, g_pctx.window, &g_pctx.wm_delete_window, 1);
		else
			zerror("Unable to register WM_DELETE_WINDOW atom");
	}

	// Create OpenGL context.
	{
		int major_ver, minor_ver;
		if (!glXQueryVersion(g_pctx.display, &major_ver, &minor_ver))
			zabort("Unable to query GLX version");
		if ((major_ver == 1 && minor_ver < 3) || major_ver < 1)
			zabort("GLX version is too old");

		// Install a new error handler so that the program doesn't just exit if we fail to get a 3.1 context.
		// Note this error handler is global.  All display connections in all threads of a process use the same error handler.
		ctx_error_occured = false;
		int (*old_handler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctx_error_handler);

		const char *gl_exts = glXQueryExtensionsString(g_pctx.display, XDefaultScreen(g_pctx.display));
		if (!is_ext_supported(gl_exts, "GLX_ARB_create_context"))
			zabort("OpenGL does not support glXCreateContextAttribsARB extension");

		int context_attribs[] = {
			GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
			GLX_CONTEXT_MINOR_VERSION_ARB, 1,
			//GLX_CONTEXT_FLAGS_ARB        , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
			None
		};
		typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
		glXCreateContextAttribsARBProc glXCreateContextAttribsARB = NULL;
		glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB");
		if (!glXCreateContextAttribsARB)
			zabort("Could not load glXCreateContextAttribsARB");
		g_pctx.gl_context = NULL;
		g_pctx.gl_context = glXCreateContextAttribsARB(g_pctx.display, fbconfig, 0, True, context_attribs);
		XSync(g_pctx.display, False);
		if (ctx_error_occured || !g_pctx.gl_context)
			zabort("Failed to create OpenGL context");
		XSetErrorHandler(old_handler);
		glXMakeCurrent(g_pctx.display, g_pctx.window, g_pctx.gl_context);
	}

	// Load OpenGL functions.
	#define LOADPROC
	#include "glprocs.h"
	#undef LOADPROC

	main_loop(screen_dim);
	platform_exit();
	return 0;
}
Exemple #10
0
void solo5_abort(void)
{
    log(INFO, "Solo5: solo5_abort() called\n");
    platform_exit(SOLO5_EXIT_ABORT, NULL);
}
Exemple #11
0
void solo5_exit(int status)
{
    log(INFO, "Solo5: solo5_exit(%d) called\n", status);
    platform_exit(status, NULL);
}