Example #1
0
File: main.c Project: peko/tttm2
int main(int argc, char** argv) {

    GLFWwindow* window;

    glfwSetErrorCallback(on_error);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

    window = glfwCreateWindow(800, 600, "show mesh", NULL, NULL);
    if (!window) {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwSetKeyCallback(window, on_key);
    glfwSetCursorPosCallback(window, on_mouse);
    glfwSetMouseButtonCallback(window, on_click);
    glfwSetScrollCallback(window, on_scroll);

    glfwMakeContextCurrent(window);
    gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
    glfwSwapInterval(1);

    app_init(argc, argv);
    gui_init(window);

    while (!glfwWindowShouldClose(window)) {
        float ratio;
        int width, height;

        glfwGetFramebufferSize(window, &width, &height);
        ratio = width / (float) height;

        glViewport(0, 0, width, height);
        glClear(GL_COLOR_BUFFER_BIT);

        glfwPollEvents();

        app_draw(ratio);

        gui_logic();
        gui_draw();

        glfwSwapBuffers(window);
    }

    glfwDestroyWindow(window);

    glfwTerminate();

    app_cleanup();
    gui_cleanup();

    exit(EXIT_SUCCESS);
}
Example #2
0
File: rui.c Project: Maxsl/r-source
void readconsolecfg()
{
    char  fn[128];
    int   sty = Plain;
    char  optf[PATH_MAX+1];

    struct structGUI gui;

    getDefaults(&gui);

    if (R_LoadRconsole) {
	snprintf(optf, PATH_MAX+1, "%s/Rconsole", getenv("R_USER"));
	if (!loadRconsole(&gui, optf)) {
	    snprintf(optf, PATH_MAX+1, "%s/etc/Rconsole", getenv("R_HOME"));
	    if (!loadRconsole(&gui, optf)) {
		app_cleanup();
		RConsole = NULL;
		exit(10);
	    }
	}
    }
    if (gui.tt_font) {
	strcpy(fn, "TT ");
	strcpy(fn+3, gui.font);
    } else strcpy(fn, gui.font);

    MDIsize = gui.MDIsize;

    if (gui.MDI)  RguiMDI |= RW_MDI;
    else          RguiMDI &= ~RW_MDI;

    if (MDIset == 1)  RguiMDI |= RW_MDI;
    if (MDIset == -1) RguiMDI &= ~RW_MDI;

    if (gui.toolbar) RguiMDI |= RW_TOOLBAR;
    else	     RguiMDI &= ~RW_TOOLBAR;
    if (gui.statusbar) RguiMDI |= RW_STATUSBAR;
    else	       RguiMDI &= ~RW_STATUSBAR;

    if (!strcmp(gui.style, "normal")) sty = Plain;
    if (!strcmp(gui.style, "bold")) sty = Bold;
    if (!strcmp(gui.style, "italic")) sty = Italic;

    Rwin_graphicsx = gui.grx;
    Rwin_graphicsy = gui.gry;

    if(strlen(gui.language)) {
	char *buf = malloc(50);
	snprintf(buf, 50, "LANGUAGE=%s", gui.language);
	putenv(buf);
    }
    setconsoleoptions(fn, sty, gui.pointsize, gui.crows, gui.ccols,
		      gui.cx, gui.cy,
		      gui.guiColors,
		      gui.prows, gui.pcols, gui.pagerMultiple, gui.setWidthOnResize,
		      gui.cbb, gui.cbl, gui.buffered, gui.cursor_blink);
}
Example #3
0
void R_CleanUp(SA_TYPE saveact, int status, int runLast)
{
    if(saveact == SA_DEFAULT) /* The normal case apart from R_Suicide */
	saveact = SaveAction;

    if(saveact == SA_SAVEASK) {
	if(R_Interactive) {
	    switch (R_YesNoCancel(G_("Save workspace image?"))) {
	    case YES:
		saveact = SA_SAVE;
		break;
	    case NO:
		saveact = SA_NOSAVE;
		break;
	    case CANCEL:
		jump_to_toplevel();
		break;

	    }
	} else saveact = SaveAction;
    }

    switch (saveact) {
    case SA_SAVE:
	if(runLast) R_dot_Last();
	if(R_DirtyImage) R_SaveGlobalEnv();
	if (CharacterMode == RGui ||
	    (R_Interactive && CharacterMode == RTerm)) {
	    R_setupHistory(); /* re-read the history size and filename */
	    gl_savehistory(R_HistoryFile, R_HistorySize);
	}
	break;
    case SA_NOSAVE:
	if(runLast) R_dot_Last();
	break;
    case SA_SUICIDE:
    default:
	break;
    }
    R_RunExitFinalizers();
    editorcleanall();
    CleanEd();
    CleanTempDir();
    closeAllHlpFiles();
    KillAllDevices();
    AllDevicesKilled = TRUE;
    if (R_Interactive && CharacterMode == RTerm)
	SetConsoleTitle(oldtitle);
    UnLoad_Rbitmap_Dll();
    if (R_CollectWarnings && saveact != SA_SUICIDE
	&& CharacterMode == RTerm)
	PrintWarnings();
    app_cleanup();
    RConsole = NULL;
    exit(status);
}
Example #4
0
/* use fatal !=0 for emergency bail out */
void Rf_endEmbeddedR(int fatal)
{
    R_RunExitFinalizers();
    CleanEd();
    R_CleanTempDir();
    if(!fatal){
	Rf_KillAllDevices();
	AllDevicesKilled = TRUE;
    }
    if(!fatal && R_CollectWarnings)
	PrintWarnings();	/* from device close and .Last */
    app_cleanup();
}
Example #5
0
void R_CleanUp(SA_TYPE saveact, int status, int runLast)
{
    if(saveact == SA_DEFAULT) /* The normal case apart from R_Suicide */
	saveact = SaveAction;

    if(saveact == SA_SAVEASK) {
	if(R_Interactive) {
	    switch (R_YesNoCancel(G_("Save workspace image?"))) {
	    case YES:
		saveact = SA_SAVE;
		break;
	    case NO:
		saveact = SA_NOSAVE;
		break;
	    case CANCEL:
		// There might be residual events with destroyed handles
		R_ProcessEvents();
		jump_to_toplevel();
		break;

	    }
	} else saveact = SaveAction;
    }

    switch (saveact) {
    case SA_SAVE:
	if(runLast) R_dot_Last();
	if(R_DirtyImage) R_SaveGlobalEnv();
	if (CharacterMode == RGui) {
	    R_setupHistory(); /* re-read the history size and filename */
	    wgl_savehistory(R_HistoryFile, R_HistorySize);
	} else if(R_Interactive && CharacterMode == RTerm) {
	    R_setupHistory(); /* re-read the history size and filename */
	    gl_savehistory(R_HistoryFile, R_HistorySize);
	}
	break;
    case SA_NOSAVE:
	if(runLast) R_dot_Last();
	break;
    case SA_SUICIDE:
    default:
	break;
    }
    R_RunExitFinalizers();
    editorcleanall();
    CleanEd();
    KillAllDevices(); /* Unix does not do this under SA_SUICIDE */
    AllDevicesKilled = TRUE; /* used in devWindows.c to inhibit callbacks */
    R_CleanTempDir(); /* changes directory */
    if (R_Interactive && CharacterMode == RTerm)
	SetConsoleTitle(oldtitle);
    if (R_CollectWarnings && saveact != SA_SUICIDE
	&& CharacterMode == RTerm)   /* no point in doing this for Rgui
					as the console is about to close */
	PrintWarnings();        /* from device close and (if run) .Last */
    app_cleanup();
    RConsole = NULL;
    if(ifp) fclose(ifp);        /* input file from -f or --file= */
    if(ifile[0]) unlink(ifile); /* input file from -e */
    exit(status);
}
Example #6
0
int main(int argc, char **argv)
{
	unsigned long prev_msec = 0, frame_time;
	unsigned int sdl_flags = SDL_HWPALETTE | SDL_HWSURFACE;

	char *env = getenv("FULLSCREEN");
	if(env && atoi(env)) {
		sdl_flags |= SDL_FULLSCREEN;
	}

	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
		fprintf(stderr, "failed to initialize SDL\n");
		return 1;
	}
	if(!(fbsurf = SDL_SetVideoMode(640, 480, 8, sdl_flags))) {
		fprintf(stderr, "failed to set video mode\n");
		SDL_Quit();
		return 1;
	}
	SDL_WM_SetCaption("colcycle/SDL", 0);

	SDL_LockSurface(fbsurf);
	fbwidth = fbsurf->w;
	fbheight = fbsurf->h;
	fbpixels = fbsurf->pixels;

	if(app_init(argc, argv) == -1) {
		SDL_Quit();
		return 1;
	}
	SDL_UnlockSurface(fbsurf);
	SDL_UpdateRect(fbsurf, 0, 0, 0, 0);

	if(sdl_flags & SDL_FULLSCREEN) {
		SDL_ShowCursor(0);
	}

	start_msec = SDL_GetTicks();

	while(!quit) {
		SDL_Event ev;
		while(SDL_PollEvent(&ev)) {
			switch(ev.type) {
			case SDL_QUIT:
				quit = 1;
				break;
			case SDL_KEYDOWN:
				app_keyboard(ev.key.keysym.sym, 1);
				break;
			case SDL_KEYUP:
				app_keyboard(ev.key.keysym.sym, 0);
				break;

			default:
				break;
			}
			if(quit) goto break_evloop;
		}

		if(SDL_MUSTLOCK(fbsurf)) {
			SDL_LockSurface(fbsurf);
		}
		fbpixels = fbsurf->pixels;

		time_msec = get_msec();
		app_draw();
		if(SDL_MUSTLOCK(fbsurf)) {
			SDL_UnlockSurface(fbsurf);
		}

		time_msec = get_msec();
		frame_time = time_msec - prev_msec;
		prev_msec = time_msec;
		if(frame_time < 16) {
			SDL_Delay(16 - frame_time);
		}
	}

break_evloop:
	app_cleanup();
	SDL_ShowCursor(1);
	SDL_Quit();
	return 0;
}
Example #7
0
int
main(int argc, char *argv[])
{
  GError *err = NULL;
  GOptionContext *opt_ctxt;
  GMainLoop *loop;
  PlcIoComm *io_comm;
  GIOStream *ser_io;
  
#ifdef MEMPROFILE
  g_mem_set_vtable (glib_mem_profiler_table);
#endif
  app_init(&app_ctxt);
/*g_type_init();*/
  opt_ctxt = g_option_context_new (" - Scratch helper for PLCS2 extension");
  g_option_context_add_main_entries(opt_ctxt, app_options, NULL);
  if (!g_option_context_parse(opt_ctxt, &argc, &argv, &err)) {
    g_printerr("Failed to parse options: %s\n", err->message);
    app_cleanup(&app_ctxt);
    return EXIT_FAILURE;
  }
  g_option_context_free(opt_ctxt);
  if (!app_ctxt.config_filename) {
    g_printerr("No configuration file\n");
    app_cleanup(&app_ctxt);
    return EXIT_FAILURE;
  }
  if (!read_config_file(&app_ctxt, &err)) {
    g_printerr("Failed to read config file: %s\n", err->message);
    g_clear_error(&err);
    app_cleanup(&app_ctxt);
    return EXIT_FAILURE;
  }


  if (app_ctxt.daemon) {
    if (!go_daemon(&app_ctxt, &err)) {
      g_printerr("Failed to start as daemon: %s\n", err->message);
      g_clear_error(&err);
      app_cleanup(&app_ctxt);
      return EXIT_FAILURE;
    }
  }

  ser_io = serial_device_open(app_ctxt.serial_device, 38400, 8, ParityNone, &err);
  if (!ser_io) {
    g_critical("Failed to open serial device: %s\n", err->message);
    app_cleanup(&app_ctxt);
    g_clear_error(&err);
    return EXIT_FAILURE;
  }
  
  io_comm = plc_io_comm_new(ser_io, &err);
  g_object_unref(ser_io);
  if (!io_comm) {
    g_critical("Failed to setup communication with PLC: %s\n", err->message);
    app_cleanup(&app_ctxt);
    g_clear_error(&err);
    return EXIT_FAILURE;
  }
  app_ctxt.websocket_server = (WebsocketServer*)plc_io_server_new(io_comm);
  g_object_unref(io_comm);
  
  
  configure_websocket_server(&app_ctxt);
  if (!websocket_server_start(app_ctxt.websocket_server, &err)) {
    g_critical("Failed to setup server: %s\n", err->message);
    app_cleanup(&app_ctxt);
    g_clear_error(&err);
    return EXIT_FAILURE;
  }
  
  loop = g_main_loop_new(NULL, FALSE);
  g_unix_signal_add(SIGINT, sigint_handler, loop);
  g_unix_signal_add(SIGTERM, sigint_handler, loop);
  g_debug("Starting");
  g_main_loop_run(loop);
  g_main_loop_unref(loop);
  g_message("Exiting");
  app_cleanup(&app_ctxt);
#ifdef MEMPROFILE
  g_mem_profile ();
#endif
  return EXIT_SUCCESS;
}