void World::start() { // The maze model also has a locator in it for where to start the ball // To access it we use the find command LPoint3f startPos = m_mazeNp.find("**/start").get_pos(); // Set the ball in the starting position m_ballRootNp.set_pos(startPos); // Initial velocity is 0 m_ballV = LVector3f(0,0,0); // Initial acceleration is 0 m_accelV = LVector3f(0,0,0); // For a traverser to actually do collisions, you need to call // traverser.traverse() on a part of the scene. Fortunately, base has a // task that does this for the entire scene once a frame. This sets up our // traverser as the one to be called automatically // Note: have to do it manually in C++ PT(GenericAsyncTask) traverserTaskPtr = new GenericAsyncTask("traverser", call_traverse, this); if(traverserTaskPtr != NULL) { AsyncTaskManager::get_global_ptr()->add(traverserTaskPtr); } // Create the movement task, but first make sure it is not already running PT(GenericAsyncTask) rollTaskPtr = DCAST(GenericAsyncTask, AsyncTaskManager::get_global_ptr()->find_task("rollTask")); if(rollTaskPtr == NULL) { rollTaskPtr = new GenericAsyncTask("rollTask", call_roll, this); if(rollTaskPtr != NULL) { AsyncTaskManager::get_global_ptr()->add(rollTaskPtr); } } m_last = 0; }
cmd_type commBase::read() { //Required - insures we can read the packets startListening(); cmd_type ret = PKT_EMPTY; byte packet[PACKET_SIZE]; //packet buffer if (com.available()) { delay(5); com.read(packet, PACKET_SIZE); } else return ret; for (int i = 0; i < PACKET_SIZE; i++) PT(packet[i]); PTL(); byte cmd = packet[0]; //first packet gives the type of packet if (cmd == PKT_UPDATE_TEMPERATURE) { PT("Updating Temp "); float * value = (float*)&packet[1]; temperature_sensor = *value; ret = PKT_UPDATE_TEMPERATURE; PTL(*value); } // stopListening(); return ret; }
void FB_TOF::executeEvent(int pa_nEIID){ if(scm_nEventREQID == pa_nEIID){ if(IN() == true){ Q() = true; ET() = 0; fallingEdge = false; notFirstRisingEdge = true; start = 0; } else{ if(true == notFirstRisingEdge){ if(fallingEdge == false){ fallingEdge = true; start = TIME(); } else{ count = TIME() - start; if(PT() <= count){ Q() = false; ET() = PT(); }else{ ET() = count; } } } } sendOutputEvent(scm_nEventCNFID); } }
void FB_TON::executeEvent(int pa_nEIID){ if(scm_nEventREQID == pa_nEIID){ if(IN() == false){ Q() = false; ET() = 0; risingEdge = false; start = 0; } else{ if(risingEdge == false){ risingEdge = true; start = TIME(); }else{ count = TIME() - start; if(PT() <= count){ Q() = true; ET() = PT(); }else{ ET() = count; } } } sendOutputEvent(scm_nEventCNFID); } }
static int _entrance_session_userid_set(struct passwd *pwd) { if (!pwd) { PT("no passwd !\n"); return 1; } if (initgroups(pwd->pw_name, pwd->pw_gid) != 0) { PT("can't init group\n"); return 1; } if (setgid(pwd->pw_gid) != 0) { PT("can't set gid\n"); return 1; } if (setuid(pwd->pw_uid) != 0) { PT("can't set uid\n"); return 1; } /* PT("name -> %s, gid -> %d, uid -> %d\n", pwd->pw_name, pwd->pw_gid, pwd->pw_uid); */ return 0; }
int make_move(const GameState* state, int i, int d) { assert(d > 0); int player = ai_current_player(); MoveResult move = is_valid_move(state, player, i, d); DEBUG("make_move(): P%d moves %d -> %d (result %d)\n", player, i, i-d, move); int src = PT(player,i); int dest = PT(player,i-d); switch (move) { case MOVE_INVALID: return 0; case MOVE_BEAROFF: assert(src >= 0 && src < 24); SET(state->points[src], MAKEPOINT(player, state->points[src].count-1)); DEC(state->total[player]); ai_set_player_score(player, 15 - state->total[player]); DEBUG("make_move(): P%d beared off @ %d; %d left\n", player, i, state->total[player]); return 1; case MOVE_UNOCCUPIED: case MOVE_MERGE: assert(src >= 0 && src < 24); assert(dest >= 0 && dest < 24); SET(state->points[src], MAKEPOINT(player, state->points[src].count-1)); SET(state->points[dest], MAKEPOINT(player, state->points[dest].count+1)); return 1; case MOVE_HITBLOT: assert(src >= 0 && src < 24); assert(dest >= 0 && dest < 24); SET(state->points[src], MAKEPOINT(player, state->points[src].count-1)); SET(state->points[dest], MAKEPOINT(player, 1)); INC(state->bar[player^1]); return 1; } }
PT convert_script_value_f_point<PT>::operator()( QScriptEngine *, const QScriptValue & args ) const { typedef typename point_valtype<PT>::value_type value_type; value_type x = 0; value_type y = 0; QScriptValue obj; bool smellArray = (args.isArray() || ! args.property("length").isUndefined()); if( smellArray ) { if(0) qDebug() << "Looks like arguments array."; obj = args.property(0); } else if( args.isObject() ) { if(0) qDebug() << "Looks like an object."; obj = args; } if( smellArray && !obj.isObject() ) { if(0) qDebug() << "Trying arguments array."; x = value_type(args.property(0).toNumber()); y = value_type(args.property(1).toNumber()); } else { if(0) qDebug() << "Trying object x/y:" << obj.toString() << ":" << toSource( obj ); if(0) qDebug() << "obj.property(x).toNumber():"<<obj.property("x").toNumber(); x = value_type(obj.property("x").toNumber()); y = value_type(obj.property("y").toNumber()); } if(0) qDebug() << "PT:"<<PT(x,y); return PT(x,y); }
t_pt ft_farthest(t_pt pos, t_pt p1, t_pt p2) { const t_pt t1 = PT(p1.x - pos.x, p1.y - pos.y); const t_pt t2 = PT(p2.x - pos.x, p2.y - pos.y); if (((t1.x * t1.x) + (t1.y * t1.y)) > ((t2.x * t2.x) + (t2.y * t2.y))) return (p1); return (p2); }
uint64 NetworkBlockFile::getFreeBlock() { uint64 blocknum ; PT("Entering NetworkingBlockFile::getFreeBlock()") ; blocknum = sp->getFreeBlock() ; PT("Leaving NetworkingBlockFile::getFreeBlock()") ; return blocknum ; }
int main() { PT val[] = {PT(0, 0), PT(1, 1), PT(2, 2), PT(-1, 0)}; vector<PT> puntuak; for (int i = 0; i < 4; i++) puntuak.push_back(val[i]); ConvexHull(puntuak); for (int i = 0; i < puntuak.size(); i++) cout << puntuak[i].x << " " << puntuak[i].y << endl; return 0; }
// This is the task that deals with making everything interactive AsyncTask::DoneStatus World::roll(GenericAsyncTask* taskPtr) { // Standard technique for finding the amount of time since the last frame double dt = taskPtr->get_elapsed_time() - m_last; m_last = taskPtr->get_elapsed_time(); // If dt is large, then there has been a # hiccup that could cause the ball // to leave the field if this functions runs, so ignore the frame if(dt > 0.2) { return AsyncTask::DS_cont; } // The collision handler collects the collisions. We dispatch which function // to handle the collision based on the name of what was collided into for(int i = 0; i < m_cHandlerPtr->get_num_entries(); ++i) { PT(CollisionEntry) entryPtr = m_cHandlerPtr->get_entry(i); const string& name = entryPtr->get_into_node()->get_name(); if(name == "wall_collide") { wall_collide_handler(*entryPtr); } else if(name == "ground_collide") { ground_collide_handler(*entryPtr); } else if(name == "loseTrigger") { lose_game(*entryPtr); } } // Read the mouse position and tilt the maze accordingly PT(MouseWatcher) mouseWatcherPtr = DCAST(MouseWatcher, m_windowFrameworkPtr->get_mouse().node()); if(mouseWatcherPtr->has_mouse()) { // get the mouse position const LPoint2f& mpos = mouseWatcherPtr->get_mouse(); m_mazeNp.set_p(mpos.get_y() * -10); m_mazeNp.set_r(mpos.get_x() * 10); } // Finally, we move the ball // Update the velocity based on acceleration m_ballV += m_accelV * dt * ACCEL; // Clamp the velocity to the maximum speed if(m_ballV.length_squared() > MAX_SPEED_SQ) { m_ballV.normalize(); m_ballV *= MAX_SPEED; } // Update the position based on the velocity m_ballRootNp.set_pos(m_ballRootNp.get_pos() + (m_ballV * dt)); // This block of code rotates the ball. It uses something called a quaternion // to rotate the ball around an arbitrary axis. That axis perpendicular to // the balls rotation, and the amount has to do with the size of the ball // This is multiplied on the previous rotation to incrementally turn it. LRotationf prevRot(m_ballNp.get_quat()); LVector3f axis = UP.cross(m_ballV); LRotationf newRot(axis, 45.5 * dt * m_ballV.length()); m_ballNp.set_quat(prevRot * newRot); // Continue the task indefinitely return AsyncTask::DS_cont; }
/* * pico_give - free resources and give up picotext struct */ void pico_give(void *w) { register LINE *lp; register LINE *fp; fp = lforw(PT(w)->linep); while((lp = fp) != PT(w)->linep){ fp = lforw(lp); free(lp); } free(PT(w)->linep); free((PICOTEXT *)w); }
void FB_TP::executeEvent(int pa_nEIID){ if(pa_nEIID == scm_nEventREQID){ if (edgeFlag) { if(ET() >= PT()){ Q() = false; edgeFlag = false; DEVLOG_DEBUG("top\n"); }else{ ET() = TIME() - start; DEVLOG_DEBUG("rising\n"); } } else { if(IN() == true && ET() == 0){ Q() = true; edgeFlag = true; start = TIME(); DEVLOG_DEBUG("start\n"); } else if((false == IN()) && (ET()>0)) { ET() = 0; DEVLOG_DEBUG("reset\n"); } } sendOutputEvent(scm_nEventCNFID); } }
// Our custom load function to load the textures needed for a movie into a // list. It assumes the the files are named // "path/name<serial number>.extention" // It takes the following arguments // Frames: The number of frames to load // name: The "path/name" part of the filename path // suffix: The "extention" part of the path // padding: The number of digit the serial number contains: // e.g. if the serial number is 0001 then padding is 4 void World::load_texture_movie(int frames, const string& name, const string& suffix, int padding, vector<PT(Texture)>* texs) { // The following line is very complicated but does a lot in one line // Here's the explanation from the inside out: // first, a string representing the filename is built an example is: // "path/name%04d.extention" // The % after the string is an operator that works like C's sprintf function // It tells python to put the next argument (i) in place of the %04d // For more string formatting information look in the python manual // That string is then passed to the loader.loadTexture function // The loader.loadTexture command gets done in a loop once for each frame, // And the result is returned as a list. // For more information on "list comprehensions" see the python manual for(int frameItr = 0; frameItr < frames; ++frameItr) { ostringstream filename; filename << name << setfill('0') << setw(padding) << frameItr << "." << suffix; PT(Texture) tex = TexturePool::load_texture(filename.str()); (*texs).push_back(tex); } }
static void PathStart( PLOT *plot, int style, int axis, double unit ) { double res ; if( PathState != 0 ) IOerror( OpticBomb, "PathStart", "state mismatch" ) ; PathFile = PlotKludge( plot ) ; PathStyle = PlotKludge2( plot ) ; PathAxis = axis ; PathUnit = unit ; switch( PathStyle ) { case PLOT_PS: PT( "newpath\n" ) ; res = 1.0 / 25400.0 ; /* 1.0 microns */ break ; case PLOT_MG: res = 1.0 / 25400.0 ; /* 1.0 microns */ break ; case PLOT_AC: PathAxis = 0 ; res = 0.1 / 25.4 ; /* 0.1 mm */ break ; default: res = 0.0 ; } PathRes = (int) ( 0.99 - log10( PathUnit * res ) ) ; if( PathRes < 0 ) PathRes = 0 ; PathState = 1 ; }
int main(int argc, char *argv[]) { // setup Panda3d PandaFramework pandaFramework; pandaFramework.open_framework(argc, argv); PT(WindowFramework) windowFrameworkPtr = pandaFramework.open_window(); if(windowFrameworkPtr == NULL) { nout << "ERROR: could not open the WindowFramework." << endl; return 1; // error } // Tell Panda3D to use OpenAL, not FMOD load_prc_file_data("", "audio-library-name p3openal_audio"); // Create an instance of our class World world(windowFrameworkPtr); // Run the simulation pandaFramework.main_loop(); // quit Panda3d pandaFramework.close_framework(); return 0; // success }
SLPSet::equal_to(const SLPSet& other) const { if (other.roots.size() != this->roots.size()) { return false; } if (other.terminals_count != this->terminals_count) { return false; } for (auto this_root = this->roots.begin(), auto other_root = other.roots.end(); this_root != this->roots.end(); //Don't have to check other, because other.roots.size() == this->roots.size() ++this_root, ++other_root) { if (this->vertices[*this_root].length != other.vertices[*other_root].length) { return false; } } ProgressionTable PT(*this, other); for (auto this_root = this->roots.begin(), auto other_root = other.roots.end(); this_root != this->roots.end(); //Don't have to check other, because other.roots.size() == this->roots.size() ++this_root, ++other_root) { ProgressionTable::MatchResultSequence match = PT.get_matches(SignedVertex(*this_root, false), SignedVertex(*other_root, false)); if (match.start != 0 || match.count != 1) { return false; } } return true; }
int reenter_from_bar(const GameState* state, int player, int d) { if (d) { assert(d>=1&&d<=6); if (state->bar[player]) { MoveResult move = can_move_to(state, player, 24-d); if (move) { DEBUG("P%d entering from bar @ %d\n", player, 24-d); DEC(state->bar[player]); int dest = PT(player,24-d); switch (move) { case MOVE_UNOCCUPIED: case MOVE_MERGE: SET(state->points[dest], MAKEPOINT(player, state->points[dest].count+1)); return 1; case MOVE_HITBLOT: SET(state->points[dest], MAKEPOINT(player, 1)); INC(state->bar[player^1]); return 1; default: assert(0); } return 1; } } } return 0; }
__forceinline void SetPT(__in PAGE_TABLE_ENTRY& pte) { PAGE_TABLE_ENTRY* _pte = PT(); if (_pte) *_pte = pte; }
static void _signal_log(int sig __UNUSED__) { PT("reopen the log file\n"); entrance_close_log(); _open_log(); }
static void _entrance_wait() { execl(PACKAGE_BIN_DIR"/entrance_wait", "/usr/sbin/entrance", NULL); PT("HUM HUM HUM can't wait ...\n\n\n"); _exit(1); }
static Eina_Bool _entrance_session_begin(struct passwd *pwd, const char *cookie) { PT("Session Init\n"); if (pwd->pw_shell[0] == '\0') { setusershell(); strcpy(pwd->pw_shell, getusershell()); endusershell(); } #ifdef HAVE_PAM char *term = getenv("TERM"); if (term) entrance_pam_env_set("TERM", term); entrance_pam_env_set("HOME", pwd->pw_dir); entrance_pam_env_set("SHELL", pwd->pw_shell); entrance_pam_env_set("USER", pwd->pw_name); entrance_pam_env_set("LOGNAME", pwd->pw_name); entrance_pam_env_set("PATH", entrance_config->session_path); entrance_pam_env_set("DISPLAY", ":0.0"); entrance_pam_env_set("MAIL", ""); entrance_pam_env_set("XAUTHORITY", cookie); entrance_pam_env_set("XDG_SESSION_CLASS", "greeter"); #endif return EINA_TRUE; }
void entrance_session_init(const char *file) { uint16_t word; uint8_t hi, lo; int i; char buf[PATH_MAX]; PT("Session init\n"); _mcookie = calloc(33, sizeof(char)); _mcookie[0] = 'a'; srand(entrance_session_seed_get()); for (i=0; i<32; i+=4) { word = rand() & 0xffff; lo = word & 0xff; hi = word >> 8; _mcookie[i] = dig[lo & 0x0f]; _mcookie[i+1] = dig[lo >> 4]; _mcookie[i+2] = dig[hi & 0x0f]; _mcookie[i+3] = dig[hi >> 4]; } // remove(file); snprintf(buf, sizeof(buf), "XAUTHORITY=%s", file); putenv(strdup(buf)); //PT("cookie %s \n", _mcookie); _entrance_session_cookie_add(_mcookie, ":0", entrance_config->command.xauth_path, file); _entrance_session_desktops_init(); }
int main(int argc, char *argv[]) { // setup Panda3d PandaFramework pandaFramework; pandaFramework.open_framework(argc, argv); PT(WindowFramework) windowFramework = pandaFramework.open_window(); if(windowFramework == NULL) { nout << "ERROR: could not open the WindowFramework." << endl; return 1; // error } // Note: optional, reduce CPU use when the window is minimized. SleepWhenMinimized sleepWhenMinimized(windowFramework); // Make an instance of our class World world(windowFramework); // and run the world pandaFramework.main_loop(); // quit Panda3d pandaFramework.close_framework(); return 0; // success }
LRESULT OnPaint( HWND hWnd ) { CWnd* pWnd = CWnd::FromHandle(hWnd); CPaintDC dc(pWnd); CString Text; CRect RC; CFont Font; CFont *pOldFont; CBrush Brush; CBrush *pOldBrush; CPoint PT(2,2); dc.SetBkMode( TRANSPARENT ); Font.CreateFont( 12, 0, 0, 0, FW_HEAVY, 0, 0, 0, ANSI_CHARSET, \ OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, \ VARIABLE_PITCH | FF_SWISS, "MS Sans Serif" ); pOldFont = dc.SelectObject( &Font ); if( m_State == bsNormal) { if (m_Style==2) { CBitmap bmp; bmp.LoadBitmap(IDB_BKBUTTON); Brush.CreatePatternBrush(&bmp); } else Brush.CreateSolidBrush( RGB( 200, 200, 200 ) ); dc.SetTextColor( RGB( 80, 80, 80) ); } else if( m_State == bsDown ) { Brush.CreateSolidBrush( RGB( 160, 160, 160 ) ); dc.SetTextColor( RGB( 50, 50, 250 ) ); } else if( m_State == bsHot ) { Brush.CreateSolidBrush( RGB( 100, 100, 180 ) ); dc.SetTextColor( RGB( 250, 250, 0 ) ); } pOldBrush = dc.SelectObject( &Brush ); pWnd->GetClientRect( &RC ); dc.RoundRect( &RC, PT ); HRGN hRgn = CreateRectRgn( RC.left, RC.top, RC.right, RC.bottom ); pWnd->SetWindowRgn( hRgn, TRUE ); DeleteObject( hRgn ); pWnd->GetWindowText(Text ); dc.DrawText( Text, &RC, DT_CENTER | DT_VCENTER | DT_SINGLELINE ); dc.SelectObject( pOldFont ); dc.SelectObject( pOldBrush ); return TRUE; }
host_image2d<V>::host_image2d(V* data, unsigned nrows, unsigned ncols, unsigned pitch) : domain_(nrows, ncols), pitch_(pitch), border_(0) { data_ = PT(data, dummy_free<V>); begin_ = data_.get(); }
void switchPage(page_type _page) { PTS("Switching from "); PT(page); PTS(", to "); PTL(_page); page = _page; lcd.clear(); //Without this the page will stay empty for a while // forceLCDupdate = true; }
/* * This is what we've all been waiting for! */ int acpi_enter_sleepstate(s3a_t *s3ap) { ACPI_PHYSICAL_ADDRESS wakephys = s3ap->s3a_wakephys; caddr_t wakevirt = rm_platter_va; /*LINTED*/ wakecode_t *wp = (wakecode_t *)wakevirt; uint_t Sx = s3ap->s3a_state; PT(PT_SWV); /* Set waking vector */ if (AcpiSetFirmwareWakingVector(wakephys) != AE_OK) { PT(PT_SWV_FAIL); PMD(PMD_SX, ("Can't SetFirmwareWakingVector(%lx)\n", (long)wakephys)) goto insomnia; }
//Sets up some default lighting void World::setup_lights() const { PT(AmbientLight) ambientLightPtr = new AmbientLight("ambientLight"); PT(DirectionalLight) directionalLightPtr = new DirectionalLight("directionalLight"); if(ambientLightPtr == NULL || directionalLightPtr == NULL) { nout << "ERROR: out of memory." << endl; return; } ambientLightPtr->set_color(Colorf(.4,.4,.35,1)); directionalLightPtr->set_direction(LVector3f(0,8,-2.5)); directionalLightPtr->set_color(Colorf(0.9,0.8,0.9,1)); NodePath renderNp = m_windowFrameworkPtr->get_render(); renderNp.set_light(renderNp.attach_new_node(directionalLightPtr)); renderNp.set_light(renderNp.attach_new_node(ambientLightPtr)); }
AsyncTask::DoneStatus GenericFunctionInterval::wrapper(GenericAsyncTask* taskPtr, void* dataPtr) { if(dataPtr != NULL) { PT(GenericFunctionInterval) ptr = static_cast<GenericFunctionInterval*>(dataPtr); (*ptr->m_functionPtr)(ptr->m_dataPtr); } return AsyncTask::DS_done; }