void b2Factory::CreateFxField(){ b2Body* body; b2BodyDef bodyDef; b2FixtureDef fixtureDef; b2EdgeShape edge; bodyDef.type=b2_staticBody; bodyDef.userData=NULL; bodyDef.position=b2Vec2(P2M(gapi->GetScreenHeight()),P2M(gapi->GetScreenHeight()/2)); edge.Set(b2Vec2(0,P2M(-gapi->GetScreenHeight())),b2Vec2(0,P2M(gapi->GetScreenHeight()))); fixtureDef.shape=&edge; body=fxworld->CreateBody(&bodyDef); body->CreateFixture(&fixtureDef); bodyDef.position=b2Vec2(P2M(gapi->GetScreenWidth()),P2M(gapi->GetScreenHeight()/2)); body=fxworld->CreateBody(&bodyDef); body->CreateFixture(&fixtureDef); bodyDef.type=b2_staticBody; bodyDef.userData=NULL; bodyDef.position=b2Vec2(P2M(700),P2M(260)); edge.Set( b2Vec2(P2M(-200),0) ,b2Vec2(P2M(200),0) ); fixtureDef.shape=&edge; body=fxworld->CreateBody(&bodyDef); body->CreateFixture(&fixtureDef); }
void b2Factory::ProcessCursor() { // update cursor position and cursor velocity for my input process POINT p=iapi->mouse->GetPoint(); b2Vec2 pv; pv=b2Vec2(P2M(max(20,min(580,p.x))),P2M(p.y)); pv=pv-cursor->GetPosition(); cursor->SetLinearVelocity(b2Vec2(pv.x*10,pv.y*10)); }
void b2Factory::UpdateStableFlag(){ // update sleep flag of elements in world // update flag isAllSleep // find dead body and update deadBodyList isAllSleep=true; b2Body* body; b2Vec2 v; Color4f c; body=world->GetBodyList(); magnetCount=0; while(body!=NULL){ if(body->GetUserData()!=NULL){ b2Object* obj=(b2Object*)(body->GetUserData()); if(obj!=NULL){ // kind is magnet , has velocity if(obj->isMagnet){ if(body->GetLinearVelocity().Length()>P2M(10)){ isAllSleep=false; } body->SetSleepingAllowed(true); } // count rest objects if(obj->isMagnet && obj->light){ magnetCount++; } } } body=body->GetNext(); } }
void b2Factory::CreateParticle(int num,b2Vec2 dp,Color4f col){ b2Body* body; b2Fixture* fixture; b2Object* obj; b2BodyDef bodyDef; // currentScore+=num; currentScore+=1; for(int i=0;i<num;i++){ obj = new b2Object(gapi); obj->InitAsParticle(img_cursor,col); bodyDef = obj->bodyDef; bodyDef.position=dp; body = fxworld->CreateBody(&(bodyDef)); body->ApplyForceToCenter(b2Vec2(P2M(rand()%1000-500),P2M(rand()%400-200))); fixture=body->CreateFixture(&(obj->fixtureDef)); body->ResetMassData(); body->SetUserData(obj); } }
void b2Factory::CreateRandomBody(){ b2Object* obj; b2Body* body; b2Fixture* fixture; switch(rand()%2){ case 0: obj=b2r->CreateBallObject(b2Vec2(0,0),b2Vec2(0,0)); break; case 1: obj=b2r->CreateSquareObject(b2Vec2(0,0),b2Vec2(0,0)); break; } if(rand()%2){ obj->bodyDef.position=b2Vec2(P2M(40),P2M(140)); obj->bodyDef.linearVelocity=b2Vec2(P2M(rand()%100),0); }else{ obj->bodyDef.position=b2Vec2(P2M(560),P2M(140)); obj->bodyDef.linearVelocity=b2Vec2(P2M(-rand()%100),0); } body=world->CreateBody(&(obj->bodyDef)); fixture=body->CreateFixture(&(obj->fixtureDef)); body->ResetMassData(); body->SetUserData(obj); b2c->MakeNode(body); magnetNum++; }
void b2Factory::CreateField(){ b2BodyDef bodyDef; b2FixtureDef fixtureDef; b2ChainShape chain; int cent; b2Vec2 v[4]; bodyDef.type=b2_staticBody; bodyDef.userData=NULL; cent= min(gapi->GetScreenHeight() , gapi->GetScreenWidth())/2; bodyDef.position=b2Vec2(P2M(cent),P2M(cent)); v[0].Set(P2M(-cent),P2M(-cent)); v[1].Set(P2M(-cent),P2M(cent)); v[2].Set(P2M(cent),P2M(cent)); v[3].Set(P2M(cent),P2M(-cent)); chain.CreateLoop(v,4); fixtureDef.shape=&chain; b2Body* body=world->CreateBody(&bodyDef); body->CreateFixture(&fixtureDef); }
void b2Factory::CreateBody(){ b2Object* obj; b2Body* body; b2Fixture* fixture; obj = b2r->Pop(); obj->bodyDef.position=b2Vec2(cursor->GetPosition().x,P2M(100)); obj->bodyDef.linearVelocity=b2Vec2(0,0); body=world->CreateBody(&(obj->bodyDef)); fixture=body->CreateFixture(&(obj->fixtureDef)); body->ResetMassData(); body->SetUserData(obj); b2c->MakeNode(body); // magnet[magnetNum]=body; magnetNum++; }
void b2Factory::UpdateDeadParticleList(){ // check fx world body // push back deadParticleList b2Body* body; body=fxworld->GetBodyList(); while(body!=NULL){ if(body->GetUserData()!=NULL){ b2Object* obj=(b2Object*)(body->GetUserData()); if(obj!=NULL){ if(body->GetPosition().y<P2M(0)){ deadParticleList.push_back(body); } } } body=body->GetNext(); } }
void fix_acpi_tables(void *map_base, u64 phys_base) { void *buf_base = map_base + 0x8000; void *p = buf_base; memset(buf_base, 0, 0x8000); printf("Fixing ACPI tables at 0x%llx (%p)\n", phys_base, map_base); struct RSDP *rsdp = COPYP(struct RSDP, phys_base); printf("RSDT at 0x%x\n", rsdp->rsdt_addr); printf("XSDT at 0x%llx\n", rsdp->xsdt_addr); struct RSDT *rsdt_src = P2M(rsdp->rsdt_addr); struct RSDT *rsdt = COPYTP(rsdp->rsdt_addr); rsdp->rsdt_addr = B2P(rsdt); PADB(0x30); // this gives us space for new tables struct XSDT *xsdt = COPYTP(rsdp->xsdt_addr); rsdp->xsdt_addr = B2P(xsdt); PADB(0x60); struct FADT *fadt = NULL; int cnt = (rsdt_src->hdr.length - sizeof(*rsdt)) / 4; int i; for (i = 0; i < cnt; i++) { struct SDTH *hdr = P2M(rsdt_src->table_addr[i]); printf("%c%c%c%c at 0x%x\n", PSIG32(hdr->sig), rsdt_src->table_addr[i]); switch (hdr->sig) { case SIG32('F', 'A', 'C', 'P'): { fadt = (void*)hdr; printf("FACS at 0x%x\n", fadt->facs); printf("DSDT at 0x%x\n", fadt->dsdt); // Sony puts the FACS before the FADT, unaligned, which is // noncompliant, but let's keep it there u8 *facs = COPYB(64, P2M(fadt->facs)); fadt = (void*)(hdr = COPYT(hdr)); fadt->facs = B2P(facs); PADB(0x38); break; } case SIG32('S', 'S', 'D', 'T'): { // Put the DSDT before the SSDT if (fadt) { PADB(0xf0); u8 *dsdt = COPYTP(fadt->dsdt); fadt->dsdt = B2P(dsdt); PADB(0x174); table_checksum(fadt); } else { printf("ERROR: no FADT yet?\n"); } hdr = COPYT(hdr); break; } default: hdr = COPYT(hdr); } table_checksum(hdr); xsdt->table_addr[i] = rsdt->table_addr[i] = B2P(hdr); } xsdt->table_addr[i] = rsdt->table_addr[i] = B2P(p); i++; p = build_ivrs(p); rsdt->hdr.length = sizeof(*rsdt) + 4 * i; xsdt->hdr.length = sizeof(*xsdt) + 8 * i; rsdp_checksum(rsdp); table_checksum(rsdt); table_checksum(xsdt); memcpy(map_base, buf_base, p - buf_base); }