Doc::Doc(char *l) { parser(l); enableBehavior(PERSISTENT); enableBehavior(TAKABLE); setRenderPrior(RENDER_NORMAL); initializeMobileObject(0); createPermanentNetObject(PROPS, ++oid); }
void Thunder::behavior() { enableBehavior(NO_ELEMENTARY_MOVE); enableBehavior(NO_BBABLE); enableBehavior(UNSELECTABLE); enableBehavior(SPECIFIC_RENDER); setRenderPrior(RENDER_LOW); #if 0 initializeEphemeralObject(0); #else initializeMobileObject(0); #endif enablePermanentMovement(); }
void Particle::behavior() { enableBehavior(PARTICLE); enableBehavior(NO_ELEMENTARY_MOVE); enableBehavior(NO_BBABLE); enableBehavior(UNSELECTABLE); enableBehavior(SPECIFIC_RENDER); setRenderPrior(RENDER_LOW); initializeMobileObject(0); switch (system) { case FIREWORK: break; default: enablePermanentMovement(); break; } }
Wall::Wall(WObject *user, char *geom) { setOwner(); parse()->parseSolids(geom, SEP, this); enableBehavior(DYNAMIC); initializeMobileObject(0); pos.x = user->pos.x + 0.7; pos.y = user->pos.y; pos.z = user->pos.z; updatePosition(); }
Guide::Guide(char *l) { parser(l); guide = this; enableBehavior(SPECIFIC_RENDER); setRenderPrior(RENDER_HIGH); initializeMobileObject(0); createPermanentNetObject(PROPS, ++oid); if (perpetual) enablePermanentMovement(); pos.az = atan((path[pt+1][1]-path[pt][1]) / (path[pt+1][0]-path[pt][0])); initial[0] = pos.x; initial[1] = pos.y; initial[2] = pos.z; initial[3] = pos.az; draw(color); // draw path }
void ProtoMotivator::motivate() { #if __PROTOMOTIVATOR_H__DEBUG Serial.println("Motivating!"); #endif /////////////////////////////////////////////////////////////////////////// // Enable always active behaviors enableBehavior(B_READCOMPASS); //select goal, see if goal should be called based on current goal. //lower number goals have priotity and can override higher level goals. /////////////////////////////////////////////////////////////////////////// // GOAL_AVOID_CRITICAL if (GOAL_AVOID_CRITICAL <= goal) { bool shouldBeActive = data.DirectFrontObstructionRange() <= G_AVOIDCRITICALRANGE; bool isActive = goal == GOAL_AVOID_CRITICAL; //if goal should be active if (shouldBeActive && !isActive) { Serial.println("New goal: GOAL_AVOID_CRITICAL"); goal = GOAL_AVOID_CRITICAL; goalStartTime = simpleTimer.getTime(); } if (shouldBeActive && isActive) { //carry out the behaviors //scan logic if (data.DirectFrontStale(200)) { enableBehavior(B_SCANDIRECTFORWARD); enableBehavior(B_STOP); } else { enableBehavior(B_SCANDIRECTFORWARD); //Move enableBehavior(B_BACKWARD); } } //if goal should not be active, and is if (!shouldBeActive && isActive) { goal = GOAL_DEFAULT; } } /////////////////////////////////////////////////////////////////////////// // GOAL_AVOID_OBSTRUCTION if (GOAL_AVOID_OBSTRUCTION <= goal) { bool shouldBeActive = data.FrontObstruction(); bool isActive = goal == GOAL_AVOID_OBSTRUCTION; //if goal should be active if (shouldBeActive && !isActive) { Serial.println("New goal: GOAL_AVOID_OBSTRUCTION"); goal = GOAL_AVOID_OBSTRUCTION; goalStartTime = simpleTimer.getTime(); heading = data.CompassHeading; avoidChosen = false; } if (shouldBeActive && isActive) { //carry out the behaviors #if __PROTOMOTIVATOR_H__DEBUG Serial.println("GOAL_AVOID_OBSTRUCTION"); #endif if (simpleTimer.getTime() > (goalStartTime + G_AVOIDSCANTIME)) { // if (!avoidChosen) { //choose avoid direction if (data.RightObstruction() && data.RightObstructionRange() < data.LeftObstructionRange()) { avoidRight = false; } else if (data.LeftObstruction() && data.RightObstructionRange() > data.LeftObstructionRange()) { avoidRight = true; } else if (data.FrontObstruction()) { if (data.RightObstructionRange() > data.LeftObstructionRange()) avoidRight = false; else avoidRight = true; } if (avoidRight) heading = data.CompassHeading + G_AVOIDTURNDEGREES; else heading = data.CompassHeading - G_AVOIDTURNDEGREES; avoidChosen = true; } //avoid ------------------------------------------------------- // scan forward while avoiding enableBehavior(B_SCANFORWARD); //enable avoid behavior if (!compass.headingMatches(data.CompassHeading, heading, G_AVOIDTURNSLOP)) { if (avoidRight) { enableBehavior(B_RIGHT); } else { enableBehavior(B_LEFT); } } else { goal = GOAL_DEFAULT; } } else { //enable full scan for scan time enableBehavior(B_SCANFULL); enableBehavior(B_STOP); } } //if goal should not be active, and is if (!shouldBeActive && isActive) { goal = GOAL_DEFAULT; } } /////////////////////////////////////////////////////////////////////////// // GOAL_FORWARD if (GOAL_FORWARD <= goal) { bool shouldBeActive = true; bool isActive = goal == GOAL_FORWARD; //if goal should be active if (shouldBeActive && !isActive) { Serial.println("New goal: GOAL_FORWARD"); goal = GOAL_FORWARD; goalStartTime = simpleTimer.getTime(); } if (shouldBeActive && isActive) { //carry out the behaviors //scan logic if (data.FrontStale(200)) { enableBehavior(B_SCANFORWARD); } else if (data.FrontStale()) { enableBehavior(B_SCANFORWARD); } else { enableBehavior(B_SCANFULL); } //Move enableBehavior(B_FORWARD); } //if goal should not be active, and is if (!shouldBeActive && isActive) { goal = GOAL_DEFAULT; } } /////////////////////////////////////////////////////////////////////////// //make it happen! executeBehaviors(); }
/* called by GUI */ Icon::Icon(User *user, void *d) { char *infos = (char *) d; ifile = NULL; ofile = NULL; char *action = NULL; vref = NULL; char icon[URL_LEN]; *icon = 0; /* parameters transmission */ for (char *pt = strtok(infos, "&"); pt ; pt = strtok(NULL, "&")) { if (! stringcmp(pt, "<url=")) { pt = getParam(pt); strcpy(names.url, pt); taken = true; } else if (! stringcmp(pt, "<file=")) { pt = getParam(pt); ifile = strdup(pt); } else if (! stringcmp(pt, "<ofile=")) { pt = getParam(pt); strcpy(names.url, pt); } else if (! stringcmp(pt, "<name=")) { pt = getParam(pt); strcpy(names.named, pt); } else if (! stringcmp(pt, "<icon=")) { pt = getParam(pt); strcpy(icon, pt); } else if (! stringcmp(pt, "<action=")) { pt = getParam(pt); action = strdup(pt); } else if (! stringcmp(pt, "<vref=")) { pt = strchr(pt, '='); pt++; char *p2; if ((p2 = strchr(pt, '>'))) *p2 = 0; vref = strdup(pt); } } if (vref) { // local saved document exists parser(vref); // get the last loaded texture int texid = Texture::getIdByUrl(names.url); Texture *tclast = Texture::getEntryById(texid); if (! tclast) { tex = new char[sizeof(ICO_DEF) + 1]; strcpy(tex, ICO_DEF); // default texture } else { tex = new char[strlen(tclast->url) + 1]; strcpy(tex, tclast->url); } taken = false; } else { // new document named interactively by hand /* position */ float off = 0.4; pos.x = user->pos.x + off * Cos(user->pos.az); pos.y = user->pos.y + off * Sin(user->pos.az); pos.z = user->pos.z + 0.6; // visible by eyes pos.az = user->pos.az + M_PI_2; /* texture */ if (*icon) { tex = new char[strlen(icon) + 1]; strcpy(tex, icon); } else { // default binding icon to document char ext[8] = ""; memset(ext, 0, sizeof(ext)); if (Format::getExt(names.url, ext)) { tex = new char[URL_LEN]; Format::getImgByExt(ext, tex); } else { tex = new char[sizeof(ICO_DEF) + 1]; strcpy(tex, ICO_DEF); } } if (ifile) { // private local document if (*names.url) { // public url given by user Cache::download(ifile, ofile, "inout"); } else { // build local ofile in ~/public_html/vreng/ ofile = new char[URL_LEN]; sprintf(ofile, "%s/public_html", getenv("HOME")); if (access(ofile, R_OK|W_OK|X_OK) == 0) { strcat(ofile, "/vreng/"); if (access(ofile, R_OK|W_OK|X_OK) == -1) mkdir(ofile, 0755); strcat(ofile, ifile); FILE *fin, *fout; if ((fin = File::openFile(ifile, "r")) && (fout = File::openFile(ofile, "w"))) { char buf[2]; while (fread(buf, 1, 1, fin)) fwrite(buf, 1, 1, fout); File::closeFile(fin); File::closeFile(fout); chmod(ofile, 0644); //FIXME: define local http_server sprintf(names.url, "http://%s/~%s/vreng/%s", DEF_HTTP_SERVER, getenv("USER"), ifile); } else { error("can't open %s or %s: %s (%d)", ifile, ofile, strerror(errno), errno); free(ifile); ifile = NULL; delete[] ofile; } } else { error("can't access %s", ofile); free(ifile); ifile = NULL; delete[] ofile; } } } makeSolid(); } // local creation defaults(); enableBehavior(REMOVABLE); enableBehavior(NO_ELEMENTARY_MOVE); setRenderPrior(RENDER_HIGH); initializeMobileObject(1); ttl = (taken) ? MAXFLOAT : 0; initImposedMovement(ttl); disablePermanentMovement(); // network creation createVolatileNetObject(PROPS); // document's owner setOwner(); trace(DBG_WO, "Icon: url=%s icon=%s name=%s owner=%s", urlName(), tex, getInstance(), ownerName()); if (action) { if (! stringcmp(action, "pin")) pin(this, NULL, 0L, 0L); else if (! stringcmp(action, "push")) push(this, NULL, 0L, 0L); else if (! stringcmp(action, "carry")) carry(this, NULL, 0L, 0L); } }