Example #1
0
int
main(int argc, char **argv)
{
	int op, i, j;

	printf("[%c-%c, 1-4, *, ?=menu, !=quit]\n", LOWEST, HIGHEST);

	if (argc > 1) {
		for (i=1; i<argc; i++) {
			for (j=0; argv[i][j]; j++) {
				printf("Choose: %c\n",
				       argv[i][j]);
				runit(argv[i][j]);
			}
		}
	}
	else {
		menu();
		while (1) {
			printf("Choose: ");
			op = getchar();
			if (op==EOF) {
				break;
			}
			printf("%c\n", op);
			runit(op);
		}
	}

	return 0;
}
Example #2
0
int
main(int argc, char *argv[])
{
	unsigned numthinkers = 2;
	unsigned numgrinders = 0;
	unsigned numponggroups = 1;
	unsigned ponggroupsize = 6;

	int i;

	for (i=1; i<argc; i++) {
		if (!strcmp(argv[i], "-t")) {
			numthinkers = atoi(argv[++i]);
		}
		else if (!strcmp(argv[i], "-g")) {
			numgrinders = atoi(argv[++i]);
		}
		else if (!strcmp(argv[i], "-p")) {
			numponggroups = atoi(argv[++i]);
		}
		else if (!strcmp(argv[i], "-s")) {
			ponggroupsize = atoi(argv[++i]);
		}
		else {
			usage(argv[0]);
		}
	}

	runit(numthinkers, numgrinders, numponggroups, ponggroupsize);
	return 0;
}
Example #3
0
int main(int argc, char *argv[])
{
	become_root();
	for (int k = 0; k < arraysize(cmds); ++k)
		runit(cmds[k], 120000);

	return 0;
}
Example #4
0
STFResult ExclusivePhysicalUnit::UnlockAndLock(IVirtualUnit * vunit, uint32 flags, const STFHiPrec64BitTime & time, const STFHiPrec32BitDuration & duration, const STFHiPrec64BitTime & systemTime)
	{
	STFResult	err = STFRES_OK;

	if (vunit == currentUnit)
		{
		if (flags & VDRUALF_PREEMPT_UNLOCK)
			{
			if (lockCount > 0)
				{
				lockCount--;
				if (lockCount == 0 && numRegisteredUnits)
					{
					RegisteredVirtualUnit	runit(vunit, flags | VDRUALF_PREEMPT_REGISTERED, ageCount++, time, duration);

					if (registeredUnits[0] < runit)
						{
						lockCount = 0;
						SignalTopRegistration();
						
						if (flags & VDRUALF_PREEMPT_REGISTER)
							{
							//
							// Now register for preemption
							//
							AddRegistration(runit);
							//
							// Return with the info, that the activation has been deferred
							//
							err = STFRES_OPERATION_PENDING;
							}
						else
							err = STFRES_OBJECT_IN_USE;		
						}
					}
				}
			else
				err = STFRES_INVALID_PARAMETERS;
			}

		if (err == STFRES_OK && (flags & VDRUALF_PREEMPT_LOCK))
			{
			lockCount++;
			}
		}
	else
		err = STFRES_INVALID_PARAMETERS;

	STFRES_RAISE(err);
	}
PyObject *run(PyObject *self, PyObject *args)
{
    struct Runobj runobj = {0};
    struct Result rst = {0};
    rst.re_call = -1;
    
    if(initRun(&runobj, args)){
        if(runobj.args)
            free((void*)runobj.args);
        return NULL;
    }
    
    if(runit(&runobj, &rst) == -1)
        return NULL;
    if(runobj.args)
        free((void*)runobj.args);
    
    return genResult(&rst);
}
Example #6
0
STDMETHODIMP CJServer::Do(BSTR input, long *pr)
{
	*pr = runit(input, !displayflag);
    return NOERROR;
}
Example #7
0
int main(int argc, char **argv)
{
	int opt, numcolon;
	int totsec, seconds, minutes, hours;
	fdata sfd;
	time_t now;
	char *user, *start, *end, *prog2run, *mov2show, *timespec;
	char userbuf[FILENAME_MAX];
	char *fmt = "/home/%s/.config/alarm/alarm.txt";
	int cookingmode;
	int ampm = 0;
	// defaults
	cookingmode = 1;
	while((opt = getopt(argc, argv, ":ha")) != -1) {
		switch(opt) {
		case 'h':
			dohelp(0);
		break;
		case 'a':
			// absolute time of day ie alarm clock mode;
			cookingmode = 0;
		break;
		case ':':
			fprintf(stderr, "Option %c requires an argument\n",optopt);
			dohelp(1);
		break;
		case '?':
			fprintf(stderr, "Unknown option: %c\n",optopt);
			dohelp(1);
		break;
		} //switch()
	}//while()
	// now process the non-option arguments

	now = time(NULL);

	// 1.Check that argv[???] exists.
	if (!(argv[optind])) {
		fprintf(stderr, "No time specifier provided.\n");
		dohelp(1);
	}
	timespec = argv[optind];
	optind++;
	// go look for am or pm
	if (argv[optind]) {
		char *cp = argv[optind];
		if (*cp == 'P' || *cp == 'p') ampm = 1;
		// and it just doesn't matter if there is a following M|m or not
	}
	// Read my config file
	user = getenv("USER");
	sprintf(userbuf,  fmt, user);
	sfd = readfile(userbuf, 0, 0);
	if(sfd.from) {
		start = sfd.from;
		end = sfd.to;
	} else {
		firstrun("alarm", "alarm.txt");
		user = getenv("HOME");
		char advice[NAME_MAX];
		sprintf(advice, "Installed alarm.txt at %s.config/alarm/\n",
				user);
		fputs(advice, stderr);
		fputs("Please edit that file to suit your needs.\n", stderr);
		exit(EXIT_SUCCESS);
	}

	prog2run = getactdata(start, end, "program");
	mov2show = getactdata(start, end, "data");

	// now deal with the users timespec
	numcolon = countchars(timespec, ':');
	hours = minutes = seconds = 0;
	char *wstr = strdup(timespec);
	char *tofree = wstr;	// wstr gets altered.
	switch(numcolon) {
		char *cp;
		case 0:
		// the number is minutes;
		if (strlen(wstr)) minutes = strtol(wstr, NULL, 10);
		break;
		case 1:
		// have mm:ss or :ss or mm:
		cp = strchr(wstr, ':');
		*cp = '\0';
		if (strlen(wstr)) minutes = strtol(wstr, NULL, 10);
		cp++; // look at the second half
		wstr = cp;
		if (strlen(wstr)) seconds = strtol(wstr, NULL, 10);
		break;
		case 2:
		// have hh:mm:ss or hh:mm:
		cp = strchr(wstr, ':');
		*cp = '\0';
		if (strlen(wstr)) hours = strtol(wstr, NULL, 10);
		cp++; // next part
		wstr = cp;
		cp = strchr(wstr, ':');
		*cp = '\0';
		if (strlen(wstr)) minutes = strtol(wstr, NULL, 10);
		cp++;
		wstr = cp;
		if (strlen(wstr)) seconds = strtol(wstr, NULL, 10);
		break;
		default:
		fprintf(stderr,
				"Badly formed time specification: %s\n", timespec);
		exit(EXIT_FAILURE);
		break;
	}
	free(tofree);
	// total seconds to elapse before alarm
	if (ampm) {
		if (!(cookingmode)) {
			if (hours < 12) hours += 12;
		}
	}
	if(!(cookingmode)) { // used as an alarm clock, not cooking timer
		totsec = addclocktime(now, hours, minutes, seconds);
	} else {
		totsec = seconds + 60 * minutes + 3600 * hours;
	}
	printf("Total seconds: %d\n", totsec);
	// report every 60 seconds
	int aminute = 60;	// seconds
	while (aminute < totsec) {
		sleep(aminute);
		totsec -= aminute;
		if (cookingmode) {
			fprintf(stdout, "Remaining: %d seconds.\n", totsec);
		}
	}
	sleep(totsec);
	runit(prog2run, mov2show);
	return 0;
}//main()
Example #8
0
File: tglup.c Project: ombt/ombt
// test driver
main(int , char **)
{
	// start testing
	cout << "START OF LUP TEST CASES ..." << endl;

	// print out epsilon
	eps = calcEpsilon(double(0));
	cout.precision(6);
	cout.setf(ios::showpoint);
	cout << "EPSILON IS ... " << eps << endl;

	// run test cases
	runit(test1, data1);
	runit(test2, data2);
	runit(test3, data3);
	runit(test4, data4);
	runit(test5, data5);
	runit(test6, data6);
	runit(test7, data7);
	runit(test8, data8);
	runit(test9, data9);
	runit(test10, data10);
	runit(test11, data11);
	runit(test12, data12);
	runit(test13, data13);
	runit(test14, data14);
	runit(test15, data15);
	runit(test16, data16);
	runit(test17, data17);

	// all done
	cout << "END OF LUP TEST CASES ..." << endl << endl;
	return(0);
}
Example #9
0
STFResult ExclusivePhysicalUnit::ActivateAndLock(IVirtualUnit * vunit, uint32 flags, const STFHiPrec64BitTime & time, const STFHiPrec32BitDuration & duration, const STFHiPrec64BitTime & systemTime)
	{
	STFResult					err = STFRES_OK;
	RegisteredVirtualUnit	crunit;
	uint32						age;

	//
	// Separate recover flags from preemption flags.  
	// If recorvery and preemption are specified, we are only to recover if
	// the preemption fails.
	//
	uint32	rflags = flags & VDRUALF_PREEMPT_RECOVER;
	if (flags & VDRUALF_PREEMPT_DIRECT) flags &= ~VDRUALF_PREEMPT_RECOVER;

	//
	// If this is an already registered unit, remove it from the registration queue
	//
	if (CancelRegistration(vunit, crunit) == STFRES_TRUE)
		age = crunit.age;
	else
		age = ageCount++;

	if (flags & VDRUALF_PREEMPT_CHECK)
		{
		RegisteredVirtualUnit	runit(vunit, flags | VDRUALF_PREEMPT_REGISTERED, age, time, duration);

		//
		// Check if a different virtual unit locks this physical or the next in line
		// has a higher priority than what we have
		//
		if (lockCount > 0 && currentUnit != vunit || numRegisteredUnits > 0 && registeredUnits[0] < runit)
			{
			//
			// If so, we can not preempt
			//
			if (flags & VDRUALF_PREEMPT_REGISTER)
				{
				//
				// Now register for preemption
				//
				AddRegistration(runit);
				//
				// Return with the info, that the activation has been deferred
				//
				STFRES_RAISE(STFRES_OPERATION_PENDING);
				}
			else
				STFRES_RAISE(STFRES_OBJECT_IN_USE);
			}
		}

	//
	// First phase of preemption, stop previously active unit
	//
	if (!STFRES_IS_ERROR(err) && (flags & VDRUALF_PREEMPT_STOP_PREVIOUS))
		{
		//
		// Check for current phase
		//
		DPPREEMPT( vunit, "ActivateAndLock -  VDRUALF_PREEMPT_STOP_PREVIOUS\n");

		if (preemptionPhase == VDRUALF_PREEMPT_NONE)
			{
			//
			// Stop previous unit, if there is one and it is not the same as the current
			//
			if (currentUnit && currentUnit != vunit)
				err = currentUnit->PreemptUnit(VDRUALF_PREEMPT_STOP_PREVIOUS);

			//
			// Advance phase if we succeeded
			//
			if (!STFRES_IS_ERROR(err)) preemptionPhase = VDRUALF_PREEMPT_STOP_PREVIOUS;
			}
		else
			err = STFRES_INVALID_PARAMETERS;
		}

	//
	// Second phase of preemption, change parameters to new unit
	//
	if (!STFRES_IS_ERROR(err) && (flags & VDRUALF_PREEMPT_CHANGE))
		{
		DPPREEMPT(vunit, "ActivateAndLock - VDRUALF_PREEMPT_CHANGE\n");

		if (preemptionPhase == VDRUALF_PREEMPT_STOP_PREVIOUS)
			{
			//
			// Change the parameters if the new unit is not already the current one
			//
			if (currentUnit != vunit)
				{	  
				DPPREEMPT(vunit, "Calling vunit->PreemptUnit(VDRUALF_PREEMPT_CHANGE)\n");						

				err = vunit->PreemptUnit(VDRUALF_PREEMPT_CHANGE);				
				}
			else 
				DPPREEMPT(vunit, "Already current. not calling vunit->PreemptUnit(VDRUALF_PREEMPT_CHANGE)\n");
			
			if (!STFRES_IS_ERROR(err)) preemptionPhase = VDRUALF_PREEMPT_CHANGE;
			}
		else
			err = STFRES_INVALID_PARAMETERS;
		}

	//
	// Third phase of preemption, start the new unit
	//
	if (!STFRES_IS_ERROR(err) && (flags & VDRUALF_PREEMPT_START_NEW))
		{
		DPPREEMPT(vunit, "ActivateAndLock - VDRUALF_PREEMPT_START_NEW\n");				

		if (preemptionPhase == VDRUALF_PREEMPT_CHANGE)
			{
			//
			// Start the new unit, if it is not already the current one
			//
			if (currentUnit != vunit)
				{	 
				DPPREEMPT(vunit, "Calling vunit->PreemptUnit(VDRUALF_PREEMPT_START_NEW)\n");						

				err = vunit->PreemptUnit(VDRUALF_PREEMPT_START_NEW);
				}
			else
				DPPREEMPT(vunit, "Already current. Not calling vunit->PreemptUnit(VDRUALF_PREEMPT_START_NEW)\n");					

			if (!STFRES_IS_ERROR(err)) preemptionPhase = VDRUALF_PREEMPT_START_NEW;
			}
		else
			err = STFRES_INVALID_PARAMETERS;
		}

	//
	// Final phase of preemption, signal success
	//
	if (!STFRES_IS_ERROR(err) && (flags & VDRUALF_PREEMPT_COMPLETE))
		{
		DPPREEMPT(vunit, "ActivateAndLock(%s) VDRUALF_PREEMPT_COMPLETE\n");				

		if (preemptionPhase == VDRUALF_PREEMPT_START_NEW)
			{
			if (currentUnit != vunit)
				{
				DPPREEMPT(vunit, "Calling vunit->PreemptUnit(VDRUALF_PREEMPT_COMPLETE)\n");						

				err = vunit->PreemptUnit(VDRUALF_PREEMPT_COMPLETE);
				}
			else 
				DPPREEMPT(vunit, "Already current. Not calling vunit->PreemptUnit(VDRUALF_PREEMPT_COMPLETE)\n");

			//
			// If we succeeded, mark this unit as the new current one
			// or just increment the lockCount
			//
			if (!STFRES_IS_ERROR(err)) 
				{
				preemptionPhase = VDRUALF_PREEMPT_NONE;
				currentUnit = vunit;
				lockCount++;
				}
			}
		else
			err = STFRES_INVALID_PARAMETERS;
		}

	//
	// If this activation failed, and we are to recover or if this is
	// a pure recovery operation, do it
	//
	if (STFRES_IS_ERROR(err) || (flags & VDRUALF_PREEMPT_RECOVER))
		{
		//
		// Now we need to recover from a previous activation failure.  We only
		// recover the phases that succeeded before.
		//
		// First phase of recover is to stop the new unit, this might be
		// necessary if we are in a multi unit activation, and some other unit fails.
		// In a single unit scenario, this would not happen.
		//
		DPPREEMPT(vunit, "ActivateAndLock - VDRUALF_PREEMPT_RECOVER\n");				

		if (preemptionPhase == VDRUALF_PREEMPT_START_NEW && (rflags & VDRUALF_PREEMPT_STOP_NEW))
			{
			if (vunit != currentUnit)				
				{
				DPPREEMPT(vunit, "Calling vunit->PreemptUnit(VDRUALF_PREEMPT_STOP_NEW)\n");						

				vunit->PreemptUnit(VDRUALF_PREEMPT_STOP_NEW);
				}
			else 
				DPPREEMPT(vunit, " Already current - not calling vunit->PreemptUnit(VDRUALF_PREEMPT_STOP_NEW)\n");					

			preemptionPhase = VDRUALF_PREEMPT_CHANGE;
			}

		//
		//	Second phase of recovery, restore the parameters of the previously active
		// unit.
		//
		if (preemptionPhase == VDRUALF_PREEMPT_CHANGE && (rflags & VDRUALF_PREEMPT_RESTORE))
			{
			if (currentUnit && vunit != currentUnit)
				{
				DPPREEMPT(currentUnit," Calling currentUnit->PreemptUnit(VDRUALF_PREEMPT_RESTORE)\n");						
				currentUnit->PreemptUnit(VDRUALF_PREEMPT_RESTORE);
				}
			else 
				DPPREEMPT(currentUnit, "Already current - not calling currentUnit->PreemptUnit(VDRUALF_PREEMPT_RESTORE)\n");					

			preemptionPhase = VDRUALF_PREEMPT_STOP_PREVIOUS;
			}

		//
		// Final phase of recovery, restart the previous unit
		//
		if (preemptionPhase == VDRUALF_PREEMPT_STOP_PREVIOUS && (rflags & VDRUALF_PREEMPT_RESTART_PREVIOUS))
			{
			if (currentUnit && vunit != currentUnit)
				{
				DPPREEMPT(currentUnit, "Calling currentUnit->PreemptUnit(VDRUALF_PREEMPT_RESTART_PREVIOUS)\n");						

				currentUnit->PreemptUnit(VDRUALF_PREEMPT_RESTART_PREVIOUS);
				}
			else 
				DPPREEMPT(currentUnit, "Already current - not calling currentUnit->PreemptUnit(VDRUALF_PREEMPT_RESTART_PREVIOUS)\n");					

			preemptionPhase = VDRUALF_PREEMPT_NONE;
			}
		}

	STFRES_RAISE(err);
	}
Example #10
0
int main(int argc, char** argv)
{
    enum e_os ge_os;
    e_endian g_endian = check_endian(); // coped from util/qcn_util.cpp -- g_endian is global to all procs, i.e. the sac file I/O utils can now use it
    const char strMain[] = {"qcn"};
    memset(strReply, 0x00, iLenReply * sizeof(char));

    char strPath[_MAX_PATH];
    memset(strCWD, 0x00, _MAX_PATH * sizeof(char));
    
    ///Users/carlc/qcn/client/test/qcndemo
    char* strEnd = strrchr(argv[0], 'q');  // the first q found at the end should be our program
    if (strEnd) {
       strncpy(strCWD, argv[0], strEnd - argv[0]);
#ifdef _WIN32
       chdir(strCWD);
#else
       _chdir(strCWD);
#endif
	}
    fprintf(stdout, "Current directory is [%s]\n", strCWD);

#ifdef __APPLE_CC__
    if (g_endian == ENDIAN_BIG) { // powerpc
        ge_os = OS_MAC_PPC;
        sprintf(strSuffix, "_%s_powerpc-apple-darwin9.7.0", QCN_VERSION_STRING);
    }
    else {
        ge_os = OS_MAC_INTEL;
        sprintf(strSuffix, "_%s_i686-apple-darwin9.7.0", QCN_VERSION_STRING);
    }    
#else
#ifdef _WIN32
        ge_os = OS_WINDOWS;
#ifdef _DEBUG
        sprintf(strSuffix, "d.exe");
#else
        sprintf(strSuffix, "_%s_%s.exe", QCN_VERSION_STRING, BOINC_WIN_SUFFIX);
#endif
#else // Linux
        ge_os = OS_LINUX;
        sprintf(strSuffix, "_%s_i686-pc-linux-gnu", QCN_VERSION_STRING);
#endif
#endif
   

    int bStatus;
    fprintf(stdout, "Getting latest earthquake list...");
    fflush(stdout);
#ifdef _WIN32
	bStatus = runit("projects\\qcn.edu_qcn\\curl.exe -s http://qcn.stanford.edu/qcnalpha/download/qcn-quake.xml > slots/0/qcn-quake.xml");
#else
	bStatus = runit("curl -s http://qcn.stanford.edu/qcnalpha/download/qcn-quake.xml > slots/0/qcn-quake.xml");
#endif
    if (!bStatus)  {
#ifdef _WIN32
       bStatus = runit("type slots\\0\\init.1 slots\\0\\qcn-quake.xml slots\\0\\init.2 > slots\\0\\init_data.xml");
#else
       bStatus = runit( "cat slots/0/init.1 slots/0/qcn-quake.xml slots/0/init.2 > slots/0/init_data.xml");
#endif
    }
    else  {
       fprintf(stdout, "Error:\n%s\n", strReply);
       fflush(stdout);
    }

    // do any OS specific stuff, i.e. copy over ntpdate
    switch (ge_os) {
       case OS_WINDOWS:
            runit( "copy slots\\0\\ntpdate.win32 slots\\0\\ntpdate");
            break;
       case OS_MAC_PPC:
            runit( "cp slots/0/ntpdate.mac-ppc slots/0/ntpdate");
            break;
       case OS_MAC_INTEL:
            runit( "cp slots/0/ntpdate.mac-intel slots/0/ntpdate");
            break;
       default:
            break;
    }

#ifdef _WIN32
       runit("del /q /s /f projects\\qcn.edu_qcn\\triggers");
       runit("del /q /s /f slots\\0\\qcnprefs.xml slots\\0\\stderr.txt slots\\0\\boinc_quake_0 slots\\0\\trick*.xml");
#ifdef _WIN32
       chdir("slots\\0");
#else
       _chdir("slots\\0");
#endif
	   sprintf(strPath, "%s%s%s", "..\\..\\projects\\qcn.edu_qcn\\", strMain, strSuffix);
#else
       runit("rm -rf projects/qcn.edu_qcn/triggers");
       runit("rm -f slots/0/qcnprefs.xml slots/0/stderr.txt slots/0/boinc_quake_0 slots/0/trick*.xml");
       _chdir("slots/0");
       sprintf(strPath, "%s%s%s", "../../projects/qcn.edu_qcn/", strMain, strSuffix);
#endif

       LaunchGraphicsThread();

       fprintf(stdout, "Launching %s...\n", strPath);
       fprintf(stdout, "SAC file output in sac/\n");
       fprintf(stdout, "QCN Sensor output in qcndemo.txt\n");
       fprintf(stdout, "Press Ctrl+C to Quit\n");
       fflush(stdout);

       char strExec[_MAX_PATH];
#ifdef _WIN32
       sprintf(strExec, "%s --demo>..\\..\\qcndemo.txt", strPath);
#else
       sprintf(strExec, "%s --demo>../../qcndemo.txt", strPath);
#endif
       runit(strExec);

}
Example #11
0
    void start() {



        float x1 = -10;
        float y1 = -10;




//      glBindTexture(GL_TEXTURE_2D, texName);
//         float roty = -45;
        int light_x = 0;
        int light_xd = 1;

        vec3i light_pos( 0, 40, 0 );

        //int steps = 1;

        //light_scene ls( planes_, solid_ );


        auto t_old = CL_System::get_microseconds();
        bool light_on = true;
        bool light_button_down = false;
        double delta_t = 0.01;
        player p1;

        //rad_core_ = make_unique<rad_core_threaded>( scene_static_, light_static_ );
        
//         rad_core_ = make_rad_core_threaded(scene_static_, light_static_);
        
        
//         auto rad_core2 = make_unique<rad_core_opencl>( cl_context_, cl_cqueue_, scene_static_, light_static_ );
//         rad_core2->load_kernel( cl_context_, cl_used_devices_ );
        
        
//      float min_ff = 5e-5;

        
//         vab.render(planes_.begin(), planes_.end() );
        
//         vbo_builder vbob(scene_static_.planes().size());
//         vbob.update_index_buffer(scene_static_.planes().size());
//         vbob.update_vertices( scene_static_.planes().begin(), scene_static_.planes().end());
        
     //    std::ifstream is( "cryistal-castle-hidden-ramp.txt" );
        std::ifstream is( "house1.txt" );
        render_unit runit(is, vec3f( -40.0, -20.0, -40.0 ));
        
//         std::ifstream is2( "cryistal-castle-tree-wave.txt" );
//         std::ifstream is2( "cryistal-castle-hidden-ramp.txt" );
//         std::ifstream is2( "house1.txt" );
//         render_unit runit2(is2, vec3f( 60.0, -20.0, 0.0 ));
        
#if 0
        cl::BufferGL buf;
        //cl::Buffer buf;
        try {
            
            //cl_int cl_err;
            //buf = cl::Buffer( clCreateFromGLBuffer( cl_context_(), CL_MEM_WRITE_ONLY, vbob.buffers_[1], &cl_err ));
            //assert( cl_err == CL_SUCCESS );
            buf = cl::BufferGL( cl_context_, CL_MEM_WRITE_ONLY, vbob.buffers_[1] );
        
        
        
            cl_fcolor_ = cl::Buffer( cl_context_, CL_MEM_READ_ONLY, scene_static_.planes().size() * 3 * sizeof(float) );
            
            cl_kernel_.setArg(0, buf() );
            //cl_kernel_.setArg(1, cl_fcolor_ );
            cl_kernel_.setArg(1, rad_core2->f_rad() );
            cl_uint cl_color_size = scene_static_.planes().size();
            cl_kernel_.setArg(2, cl_color_size );
            
            
            
        } catch( cl::Error x ) {
            std::cerr << "cl error during gl buffer setup\ncall: " << x.what() << "\nerror code: " << cl_str_error( x.err() ) << "\n";            
            throw;
        }
#endif
        bool light_changed = true;
        
        //rad_core_ = make_unique<rad_core_lockfree>( scene_static_, light_static_ );
        
        bool do_quit = false;
        
        while ( !do_quit ) {

            //cube c(x1, 0, y1);

            CL_GraphicContext gc = wnd_.get_gc();
            CL_InputDevice &keyboard = wnd_.get_ic().get_keyboard();
            CL_InputDevice &mouse = wnd_.get_ic().get_mouse();

//          if( keyboard.get_keycode(CL_KEY_I) ) {
//          //  roty += 1;
//
//              min_ff += 5e-6;
//          }
//          if(  keyboard.get_keycode(CL_KEY_K) ) {
//              //roty -= 1;
//              min_ff -= 5e-6;
//          }
//
//          std::cout << "min ff: " << min_ff << "\n";

            p1.input(keyboard, mouse);
            p1.frame(t_old * 1.0e-3, delta_t);

            int light_speed = 1;
            
            do_quit = keyboard.get_keycode(CL_KEY_Q);
            
            if ( keyboard.get_keycode(CL_KEY_LEFT) ) {
                light_pos.x += light_speed;
                light_changed = true;
            }
            if (  keyboard.get_keycode(CL_KEY_RIGHT) ) {
                light_pos.x -= light_speed;
                light_changed = true;
            }
            if ( keyboard.get_keycode(CL_KEY_UP) ) {
                light_pos.z += light_speed;
                light_changed = true;
            }
            if (  keyboard.get_keycode(CL_KEY_DOWN) ) {
                light_pos.z -= light_speed;
                light_changed = true;
            }
            if ( keyboard.get_keycode(CL_KEY_L )) {
                if ( !light_button_down ) {
                    light_on = !light_on;
                    light_changed = true;
                }
                light_button_down = true;
            } else {
                light_button_down = false;
            }



            glEnable(GL_CULL_FACE);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


//          glTranslatef(0,0,-100);
//          glRotatef(45,1,0,0);
//          glRotatef(roty,0,1,0);


            if ( light_x > 60 || light_x < -60 ) {
                light_xd = -light_xd;
//              light_x = -20;
            }

            //          light_planes(vec3i(light_x, 10, 10 ));
            
            if( light_changed ) {
                //ls.reset_emit();
//                 light_dynamic_.clear_emit();
                runit.clear_emit();
//                 runit2.clear_emit();
                //ls.render_light(vec3f( 40, 50.0, light_x ), vec3f(1.0, 1.0, 1.0 ));
                if ( light_on ) {
                    //ls.render_light(light_pos, vec3f(1.0, 0.8, 0.6 ));
                    
                    //vec3f light_pos( p1.pos)
                    
                    //              vec3f light_pos = (p1.pos()* pump_factor_) - base_pos_;
                    vec3f light_weird = (light_pos * pump_factor_) - base_pos_;
//                     light_utils::render_light( light_dynamic_.emit(), scene_static_, light_weird, vec3f(1.0, 0.8, 0.6 ));
                    runit.render_light(light_weird, vec3f(1.0, 0.8, 0.6 ));
//                     runit2.render_light(light_weird, vec3f(1.0, 0.8, 0.6 ));
                }
                //ls.post();
                light_changed = false;
            }
            runit.update();
//             runit2.update();
//             rad_core2->set_emit( *light_dynamic_.emit() );
//             rad_core_->set_emit( *light_dynamic_.emit() );
            //ls.render_emit_patches();

            //steps = 1;
            //ls.do_radiosity( steps );

            //rad_core2->run();
//             rad_core_->copy( light_dynamic_.rad() );
             // stupid: transfer rgb energy fomr light scene to planes
//             for ( size_t i = 0; i < scene_static_.planes().size(); ++i ) {
//                 plane &p = const_cast<plane &>(scene_static_.planes()[i]); // FIXME: HACK!!! is the energy_rgp stored in the planes actually used? remove it!
//                 p.energy_rgb((*light_dynamic_.rad())[i]);
//             }
//             
            light_x += light_xd;


//          glPushMatrix();
            
            //CL_Mat4f proj = CL_Mat4f::look_at( 20, 20, 20, 0, 0, 0, 0.0, 1.0, 0.0 );

            //vab.update_color( planes_.begin(), planes_.end() );
//             vab.update_color( ls.rad_rgb().begin(), ls.rad_rgb().end() );
            
//             vab.setup_gl_pointers();
//             vbob.update_color(light_dynamic_.rad()->begin(), light_dynamic_.rad()->end());
#if 0
            try
            {
                cl_int err;
//                 glFinish();
                const auto &rad_colors = *light_dynamic_.rad();
//                 
                cl_cqueue_.enqueueWriteBuffer( cl_fcolor_, false, 0, rad_colors.size() * sizeof(vec3f), rad_colors.data() );
//                 
                

                err = clEnqueueAcquireGLObjects( cl_cqueue_(), 1, &(buf()), 0, 0, 0 );
                assert( err == CL_SUCCESS );


                
                //cl_kernel_.setArg(1, rad_core2->f_rad() );
                cl_kernel_.setArg(1, cl_fcolor_ );
                cl_cqueue_.enqueueNDRangeKernel( cl_kernel_, 0, cl::NDRange(scene_static_.planes().size()) );
                
                               

                // unmap buffer object
                err = clEnqueueReleaseGLObjects( cl_cqueue_(), 1, &(buf()), 0,0,0);
                assert( err == CL_SUCCESS );
                
                cl_cqueue_.finish();
                
                
                
            } catch( cl::Error x ) {
                std::cerr << "cl error during kernel execution\ncall: " << x.what() << "\nerror code: " << cl_str_error( x.err() ) << "\n";               
                throw;
            }
#endif       
            
            //setup_perspective( p1 );
            setup_ortho();

            int ortho_width = 320;
            int ortho_heigth = 200;
            glViewport( gc.get_width() - ortho_width, gc.get_height() - ortho_heigth, ortho_width, ortho_heigth );
       //     vab.draw_arrays();
            //  render_quads();
//          glPopMatrix();
            setup_perspective(p1);
            glViewport( 0, 0, gc.get_width(), gc.get_height());
//             render_quads();
//            vab.setup_gl_pointers();
//             vab.draw_arrays();
//             vbob.draw_arrays();
            runit.draw();
//             runit2.draw();
            wnd_.flip(1);



            auto t = CL_System::get_microseconds();

//             std::cout << "fps: " << 1e6 / (t - t_old) << "\n";
            delta_t = (t - t_old) * 1.0e-6;
            t_old = t;



//           std::cout << "delta: " << delta_t << "\n";

//             CL_System::sleep( 1000 / 60. );
//          getchar();
            CL_KeepAlive::process();


            x1 += 1;
            if ( x1 > 10 ) {
                x1 = -10;
                y1 += 1;
            }
            if ( y1 > 10 ) {
                y1 = -10;
            }

        }

    }