void ApplicationContextImpl::initialise(int argc, char* argv[])
{
	initArgs(argc, argv);
    
    // Get application data directory from environment
	std::string appData = getenv("APPDATA");
	if (appData.empty())
    {
		throw std::runtime_error(
            "Critical: cannot find APPDATA environment variable."
        );
	}

    // Construct DarkRadiant home directory
	_homePath = appData + "\\DarkRadiant";
	if (!os::makeDirectory(_homePath))
    {
        std::cerr << "ApplicationContextImpl: could not create home directory "
                  << "'" << _homePath << "'" << std::endl;
    }

	{
		// get path to the editor
		wchar_t filename[MAX_PATH+1];
		GetModuleFileName(0, filename, MAX_PATH);
		wchar_t* last_separator = wcsrchr(filename, '\\');
		if (last_separator != 0) {
			*(last_separator+1) = '\0';
		}
		else {
			filename[0] = '\0';
		}

		// convert to std::string
		std::wstring wide(filename); 
		std::string appPathNarrow(wide.begin(), wide.end());

		// Make sure we have forward slashes
		_appPath = os::standardPath(appPathNarrow);
	}
	// Initialise the relative paths
	initPaths();
}
Ejemplo n.º 2
0
int
PL_initialise(int argc, char **argv)
{ int n;
  bool compile = FALSE;
  const char *rcpath = "<none>";

  if ( GD->initialised )
    succeed;

  initAlloc();
  initPrologThreads();			/* initialise thread system */
  SinitStreams();

  GD->cmdline.os_argc = argc;
  GD->cmdline.os_argv = argv;

  initOs();				/* Initialise OS bindings */
  initDefaults();			/* Initialise global defaults */
  initPaths(argc, (const char**)argv);	/* fetch some useful paths */

  { GET_LD
#ifdef HAVE_SIGNAL
  setPrologFlagMask(PLFLAG_SIGNALS);	/* default: handle signals */
#endif

  if (    (GD->resourceDB = rc_open_archive(GD->paths.executable, RC_RDONLY))
#ifdef __WINDOWS__
       || (GD->resourceDB = rc_open_archive(GD->paths.module, RC_RDONLY))
#endif
     )
  { rcpath = ((RcArchive)GD->resourceDB)->path;
    initDefaultOptions();
  }

  if ( !GD->resourceDB ||
       !streq(GD->options.saveclass, "runtime") )
  { int done;
    argc--; argv++;

    if ( argc == 1 && giveVersionInfo(argv[0]) ) /* -help, -v, etc */
    { exit(0);
    }

    for(n=0; n<argc; n++)		/* need to check this first */
    { if ( streq(argv[n], "--" ) )	/* --: terminates argument list */
	break;
      if ( streq(argv[n], "-b" ) )	/* -b: boot compilation */
      { GD->bootsession = TRUE;
	break;
      }
    }

    DEBUG(1, if (GD->bootsession) Sdprintf("Boot session\n"););

    if ( !GD->resourceDB )
    { if ( !(GD->resourceDB = openResourceDB(argc, argv)) )
      { fatalError("Could not find system resources");
      }
      rcpath = ((RcArchive)GD->resourceDB)->path;

      initDefaultOptions();
    }

    if ( (done = parseCommandLineOptions(argc, argv, &compile)) < 0 )
    { usage();
      fail;
    }
    argc -= done;
    argv += done;
  }
Ejemplo n.º 3
0
//--------------------------------------------------------------
// MARK: UPDATE
//--------------------------------------------------------------
void testApp::update(){
    
    // --------------------------------------------
    // DATA UPDATE

    // XML update > data update
    if(xmlThread.isAvailable() && !bRandomizeParticles) {
        data.getResultsFromBuffer(xmlThread.getXML());
        
        // if it is starting, load the first batch
        if(!hasInitiated) {
            hasInitiated = true;
            bResetData = true;
        // else, if it already started, add new particles (if it is the case)
        } else {
            if(data.getNewStreetPositives() != 0 || data.getNewStreetNeutrals() != 0 || data.getNewStreetNegatives() != 0 ||
               data.getNewNeighborhoodPositives() != 0 || data.getNewNeighborhoodNeutrals() != 0 || data.getNewNeighborhoodNegatives() != 0 ||
               data.getNewCityPositives() != 0 || data.getNewCityNeutrals() != 0 || data.getNewCityNegatives() != 0) {
                
                bResetData = true;
            }
        }
    }
    
    // reset the particles arrays, if it's the case
    if(bResetData) {

        // check if the new data should be randomized
        if(bRandomizeParticles) {
            // generating random values
            int delta = iMaxRandomParticles * ((100.0-iDeltaRandomParticles)/100.0);
            data.generateRandomValues(delta, iMaxRandomParticles);
        }
        
        bResetData = false;
        initPaths();
        initParticles();
    }
    
    // --------------------------------------------
    // KINECT UPDATE
    
    kinect.updateThreshPar(iFarThreshold, iNearThreshold);
    kinect.updateBlobPar(iMinBlobSize, iMaxBlobSize, iMaxNumBlobs);
    
    if(!bLockKinTilt) {
        kinect.setKinTiltAngle(false, fKin1TiltAngle);
        kinect.setKinTiltAngle(true, fKin2TiltAngle);
    }
    
    kinect.update();
    
    // --------------------------------------------
    // ATTRACTORS FROM BLOBS

    // variables to calculate the average attractor
    float sumx[3]    = {0.0, 0.0, 0.0};
    float sumy[3]    = {0.0, 0.0, 0.0};
    int   counter[3] = {0, 0, 0};
    
    // destroy dead attractors    
    for(map<int, Attractor>::iterator it = attractors.begin(); it != attractors.end(); it++) {
        if( kinect.foundBlobsMap.find((*it).first) == kinect.foundBlobsMap.end() ) {
            // get attractor
            Attractor a  = (*it).second;            
            // and check if it's time to die            
            if ( time(0) - a.bornTime > a.lifeTime ) {
                attractors.erase(it);
            } else {
                // if attractor is located in the first panel - the street panel
                if(a.location.x < FBO_W / 3) {
                    sumx[0] += a.location.x;
                    sumy[0] += a.location.y;
                    counter[0]++;
                }
                // or if attractor is located in the second panel - the neighborhood panel
                else if(a.location.x < FBO_W / 3 * 2) {
                    sumx[1] += a.location.x;
                    sumy[1] += a.location.y;
                    counter[1]++;
                }
                // or if attractor is located in the third panel - the city panel
                else {
                    sumx[2] += a.location.x;
                    sumy[2] += a.location.y;
                    counter[2]++;
                }
            }
        }
    }
        
    // update and add attractors
    for(int i = 0; i < kinect.activeBlobsIds.size(); i++) {
        
        // search for the key on the map
        int theKey = kinect.activeBlobsIds[i];
        ofxBlob b = kinect.foundBlobsMap[theKey];
        map<int, Attractor>::iterator it = attractors.find(theKey);

        // if it's already on it, update attractor
        if( it != attractors.end() ) {
            // inverting blob x
            float x = ofMap(b.centroid.x, 1.0f, 0.0f, 0.0f, 1.0f);
            attractors[theKey].location.set(x * FBO_W, b.centroid.y * FBO_H);
        }        
        // else, add attractor to the map
        else {
            // inverting blob x
            float x = ofMap(b.centroid.x, 1.0f, 0.0f, 0.0f, 1.0f);
            // add attractor to the map
            Attractor attract(ofVec2f(x * FBO_W, b.centroid.y * FBO_H), fAttractorLife);
            attractors[theKey] = attract;
        }

        
        // if attractor is located in the first panel - the street panel
        if(attractors[theKey].location.x < FBO_W / 3) {
            sumx[0] += attractors[theKey].location.x;
            sumy[0] += attractors[theKey].location.y;
            counter[0]++;
        }
        // or if attractor is located in the second panel - the neighborhood panel
        else if(attractors[theKey].location.x < FBO_W / 3 * 2) {
            sumx[1] += attractors[theKey].location.x;
            sumy[1] += attractors[theKey].location.y;
            counter[1]++;
        }
        // or if attractor is located in the third panel - the city panel
        else {
            sumx[2] += attractors[theKey].location.x;
            sumy[2] += attractors[theKey].location.y;
            counter[2]++;
        }

    }
    
    // if there are attractors in the first panel - the street panel,
    // set the panel average attractor
    if(counter[0] > 0) {
        doStreetPanelAttraction = true;
        attractorStreetPanel.setLocation(ofVec2f(sumx[0]/(float)counter[0], sumy[0]/(float)counter[0]));
    } else {
        doStreetPanelAttraction = false;
    }

    // if there are attractors in the second panel - the neighborhood panel,
    // set the panel average attractor
    if(counter[1] > 0) {
        doNeighborhoodPanelAttraction = true;
        attractorNeighborhoodPanel.setLocation(ofVec2f(sumx[1]/(float)counter[1], sumy[1]/(float)counter[1]));
    } else {
        doNeighborhoodPanelAttraction = false;
    }
    
    // if there are attractors in the third panel - the city panel,
    // set the panel average attractor
    if(counter[2] > 0) {
        doCityPanelAttraction = true;
        attractorCityPanel.setLocation(ofVec2f(sumx[2]/(float)counter[2], sumy[2]/(float)counter[2]));
    } else {
        doCityPanelAttraction = false;
    }
    
}
Ejemplo n.º 4
0
//--------------------------------------------------------------
// MARK: SETUP
//--------------------------------------------------------------
void testApp::setup(){
    
    ofSetFrameRate(60);
    ofSetVerticalSync(true);
    ofBackground(30);

    // --------------------------------------------
    // MARK: CONTROL VARIABLES SETUP
    
    iMode           = 0;
    iNetDataSource  = 0;
    iLogLevel       = 0;
    
    bTwoKinects     = 1;
    iLeftKinectId   = 0;
    iRightKinectId  = 1;
    iKinectsOpeningTries = 5;
    bLockKinTilt   = true;
    fKin1TiltAngle = 0;
    fKin2TiltAngle = 0;
    
    iNearThreshold  = 0;
    iFarThreshold   = 255;
    iMinBlobSize    = 1000;
    iMaxBlobSize    = 300000;
    iMaxNumBlobs    = 10;

    iFboAlpha   = 60;
    fPathRadius = (FBO_W / 3.0) / 2.4;

    bResetData            = false;
    bRandomizeParticles   = false;
    iMaxRandomParticles   = 200;
    iDeltaRandomParticles = 60;
    iGhostParticles      = 3;
    iMaxParticlesPerPanel = 10;
    iParticlesMultiplier = 2;

    fProxFactor      = 20.0;
    fMinParticleSize = 1.4;
    fMaxParticleSize = 6.0;
    
    fAttractionVelocity = 2.0;
    fAttractorLife      = 0.5;
    fAttractorRadius    = 2;
    
    f4Green[0]     = 0.0/255.0;   f4Green[1]     = 182.0/255.0; f4Green[2]     = 83.0/255.0;  f4Green[3]     = 255.0/255.0;
    f4Yellow[0]    = 250.0/255.0; f4Yellow[1]    = 235.0/255.0; f4Yellow[2]    = 52.0/255.0;  f4Yellow[3]    = 255.0/255.0;
    f4Red[0]       = 237.0/255.0; f4Red[1]       = 40.0/255.0;  f4Red[2]       = 73.0/255.0;  f4Red[3]       = 255.0/255.0;
    f4Gray[0]      = 102.0/255.0; f4Gray[1]      = 102.0/255.0; f4Gray[2]      = 102.0/255.0; f4Gray[3]      = 255.0/255.0;
    f4Highlight[0] = 255.0/255.0; f4Highlight[1] = 255.0/255.0; f4Highlight[2] = 255.0/255.0; f4Highlight[3] = 255.0/255.0;    
    
    
    // --------------------------------------------
    // MARK: INTERFACE SETUP
    
    iDrawWidth  = 400;
    iDrawHeight = 300;
    
    iTopMargin  = 115;
    iLeftMargin = 250;
    
    bDrawDepthMap   = true;
    bDrawThreshold  = false;
    bDrawBlobs      = false;
    
    // SETTINGS PAGE 1: GENERAL / _settings.xml
    gui.addSlider("Display Modes", iMode, 0, 2);
	string dataSourceTitles[] = {"FINAL", "TEST"};
    gui.addComboBox("Net Data Source", iNetDataSource, 2, dataSourceTitles);
	string logLevelTitles[] = {"NOTICE", "VERBOSE"};
    gui.addComboBox("Log Level", iLogLevel, 2, logLevelTitles);
    
    // SETTINGS PAGE 2: KINECTS / Kinects_settings.xml
    gui.addPage("Kinects");
    gui.addToggle("Two Kinects", bTwoKinects);
    gui.addSlider("Left Kinect ID", iLeftKinectId, 0, 1);
    gui.addSlider("Right Kinect ID", iRightKinectId, 0, 1);
    gui.addSlider("Opening Tries", iKinectsOpeningTries, 1, 10);
    gui.addToggle("Lock Tilt Angle", bLockKinTilt);
    gui.addSlider("Kin 1 Tilt Angle", fKin1TiltAngle, -30, 30);
    gui.addSlider("Kin 2 Tilt Angle", fKin2TiltAngle, -30, 30);
    
    // SETTINGS PAGE 3: DETECTION / Detection_settings.xml
    gui.addPage("Detection");
    gui.addSlider("Near Threshold", iNearThreshold, 0, 255);
    gui.addSlider("Far Threshold", iFarThreshold, 0, 255);
    gui.addSlider("Min Blob Size", iMinBlobSize, 0, 40000);
    gui.addSlider("Max Blob Size", iMaxBlobSize, 1, 307200);
    gui.addSlider("Max Num Blobs", iMaxNumBlobs, 1, 30);
    
    // SETTINGS PAGE 4: PARTICLES / Particles_01_settings.xml
    gui.addPage("Particles_01");
    gui.addTitle("REALTIME");
    gui.addSlider("Prox Factor", fProxFactor, 1.0f, 20.0f);
    gui.addSlider("Attractor Vel", fAttractionVelocity, 0.1f, 2.0f);
    gui.addSlider("Attractor Life", fAttractorLife, 0.1f, 2.0f);
    gui.addSlider("Attractor Radius", fAttractorRadius, 1.0f, 3.0f);
    gui.addSlider("FBO Alpha", iFboAlpha, 0, 255);
    
    // SETTINGS PAGE 5: PARTICLES / Particles_02_settings.xml
    gui.addPage("Particles_02");
    gui.addTitle("RESET NEEDED");
    gui.addSlider("Ghosts x100", iGhostParticles, 0, 5);
    gui.addSlider("Max Part per Panel x100", iMaxParticlesPerPanel, 5, 20);
    gui.addSlider("Particles per Vote", iParticlesMultiplier, 1, 10);
    gui.addSlider("Min Particle Size", fMinParticleSize, 1.0f, 4.0f);
    gui.addSlider("Max Particle Size", fMaxParticleSize, 1.0f, 20.0f);
    gui.addSlider("Path Radius", fPathRadius, 2.0f, 80.0f);
    gui.addToggle("Randomize", bRandomizeParticles);
    gui.addSlider("Random Max", iMaxRandomParticles, 50, 500);
    gui.addSlider("Random Delta", iDeltaRandomParticles, 0, 100);
    gui.addButton("Reset particles", bResetData);
    
    // SETTINGS PAGE 5: COLORS
    gui.addPage("Colors");
    gui.addColorPicker("Positivo", f4Green); 
    gui.addColorPicker("Neutro", f4Yellow); 
    gui.addColorPicker("Negativo", f4Red); 
    gui.addColorPicker("Ghosts", f4Gray); 
    gui.addColorPicker("Highlight", f4Highlight);
    
    gui.loadFromXML();
    gui.show();
    
    isGUIActive = false;
    
    
    // --------------------------------------------
    // MARK: LOG LEVEL
    
    if(iLogLevel == 0) {
        ofSetLogLevel(OF_LOG_NOTICE);
    } else {
        ofSetLogLevel(OF_LOG_VERBOSE);
    }

    // --------------------------------------------
    // MARK: KINECT SETUP
    
    if(bTwoKinects) {
        kinect.setup(true, iLeftKinectId, iRightKinectId, iKinectsOpeningTries);
    } else {
        kinect.setup(false, iKinectsOpeningTries);
    }

    
    // --------------------------------------------
    // MARK: FBO SETUP
    
    fbo.allocate(FBO_W, FBO_H);
    
    
    // --------------------------------------------
    // MARK: DATA SETUP
    
    // LOAD XML URLs (final/production and test)
    // the file that holds this data is named "_URL.xml" and located in the data folder
    // the finalURL node contains the final (production) XML URL
    // the testURL node contains the test XML URL
    ofxXmlSettings urls;
    urls.loadFile("_URL.xml");
    urls.pushTag("urls");
    string finalURL = urls.getValue("finalURL", "http://ituita.com.br/site/sugestoes/total/YYYY/MM.xml");
    string testURL  = urls.getValue("testURL", "http://fronte.co/dev/ituita/resultados.php");
    urls.popTag();
    
    // COMPLETE the finalURL with the current month and year
    // ---
    // the finalURL format is: http://ituita.com.br/site/sugestoes/total/[YEAR]/[MONTH].xml
    // example: http://ituita.com.br/site/sugestoes/total/2013/09.xml
    // ---
    // get the markers positions
    int pYear  = finalURL.find("YYYY");
    int pMonth = finalURL.find("MM");
    // get the current year and month
    string currentYear  = ofToString(ofGetYear());
    string currentMonth = (ofGetMonth() < 10) ? "0"+ofToString(ofGetMonth()) : ofToString(ofGetMonth());
    // replace the markers in the finalURL Ð YYYY and MM Ð with the current year and month
    finalURL.replace(pYear, 4, currentYear);
    finalURL.replace(pMonth, 2, currentMonth);
    
    // SETUP the thread that will load the data from the internet
    xmlThread.setFinalURL(finalURL);
    xmlThread.setTestURL(testURL);
    xmlThread.setActiveURL(iNetDataSource);
    xmlThread.setLoadingInterval(3000);
    
    // START the loading thread
    xmlThread.startThread(true, false);
    hasInitiated = false;
    
    
    // --------------------------------------------
    // MARK: PARTICLES SETUP
    
    doStreetPanelAttraction       = false;
    doNeighborhoodPanelAttraction = false;
    doCityPanelAttraction         = false;
    isMousePressed                = false;
    
    initPaths();
    initParticles();
        
}
Ejemplo n.º 5
0
void CAP3Worker::init() {
    input = ports.value(IN_PORT_DESCR);

    initSettings();
    initPaths();
}
Ejemplo n.º 6
0
/**
 * Charge la partie précédemment enregistré
 */
void load() {
	FILE * fic1;
	int x = -1, y = -1;
	int name, success, cardinal, tmp;
	int effectLoad[NB_MAX_EFFECT];
	unit uLoad;
	vector coordUnit;


	fic1 = fopen("assets/save/fileSave", "r");
	if(fic1 != NULL){
		initLists();

		success = fscanf(fic1, "%i - %i - %i\n", &noPlayer, &hasMoved, &hasAttacked); // Informations état joueur
		if(success == 3){

			while(!feof(fic1)) {

				success = fscanf(fic1, "(%i - %i){%i, %i, %i, %f, %i, %f, %f, %f, %i, %i, %i, %i, ", &x, &y, &name, &uLoad.stat.HP, &uLoad.stat.POWER,
						 &uLoad.stat.ARMOR, &uLoad.stat.RECOVERY, &uLoad.stat.BLOCK[0],&uLoad.stat.BLOCK[1], &uLoad.stat.BLOCK[2], &uLoad.stat.MOVE_RANGE, 
						 &uLoad.noPlayer, &uLoad.unitColor, &cardinal); // Stats de l'unité

				uLoad.name = name;
				uLoad.direct = cardinal;

				for(int k = 0; k <NB_MAX_EFFECT; k++) { // Effets de status liés à l'unité actuelle
					if(k == NB_MAX_EFFECT - 1){
						success += fscanf(fic1, " %i}\n", &effectLoad[k]);
					}else{
						success += fscanf(fic1, " %i, ", &effectLoad[k]);
					}
					uLoad.effect[k] = effectLoad[k];
					uLoad.effect[k] = effectLoad[k];
				}

				decrypt(&uLoad); // Décrypte les informations liées à l'unité chargée

				if(success == 20 && x >= 0 && x < N && y >= 0 && y < N && checkDecrypt(&uLoad)){ // Vérifie que les données sont valides
					coordUnit.x = x;
					coordUnit.y = y;

					grid[x][y] = uLoad;
					tmp        = noPlayer;
					noPlayer   = uLoad.noPlayer;

					addUnit(coordUnit); // Ajoute l'unité à la liste du joueur
					noPlayer   = tmp;

				}else{
					fclose(fic1);
					dumpAllLists(); // Libère les listes de la mémoire

					color(red, "\nDonnées invalides, le chargement n'a pu être effectué\n");
					exit(1);
				}
			}
		}else{
			fclose(fic1);
			dumpAllLists(); // Libère les listes de la mémoire

			color(red, "\nDonnées invalides, le chargement n'a pu être effectué\n");
			exit(1);
		}
		fclose(fic1);
		
		makePawns(); // Recrée les pions pour le chargement
		initPaths();
		startGame(); // Débute la partie

	}else{
		color(red, "Fichier introuvable, la sauvegarde n'a pas pu être chargée\n");
	}
}
Ejemplo n.º 7
0
BaseFileManager::BaseFileManager(Common::Language lang) {
	_language = lang;
	initPaths();
	registerPackages();
}