int change_modmap(ClientPtr client, DeviceIntPtr dev, KeyCode *modkeymap, int max_keys_per_mod) { int ret; CARD8 modmap[MAP_LENGTH]; DeviceIntPtr tmp; ret = build_modmap_from_modkeymap(modmap, modkeymap, max_keys_per_mod); if (ret != Success) return ret; /* If we can't perform the change on the requested device, bail out. */ ret = check_modmap_change(client, dev, modmap); if (ret != Success) return ret; do_modmap_change(client, dev, modmap); /* Change any attached masters/slaves. */ if (IsMaster(dev)) { for (tmp = inputInfo.devices; tmp; tmp = tmp->next) { if (!IsMaster(tmp) && tmp->u.master == dev) if (check_modmap_change_slave(client, dev, tmp, modmap)) do_modmap_change(client, tmp, modmap); } } else if (dev->u.master && dev->u.master->u.lastSlave == dev) { /* If this fails, expect the results to be weird. */ if (check_modmap_change(client, dev->u.master, modmap)) do_modmap_change(client, dev->u.master, modmap); } return Success; }
/** * Compares two grabs and returns TRUE if the first grab matches the second * grab. * * A match is when * - the devices set for the grab are equal (this is optional). * - the event types for both grabs are equal. * - XXX * * @param ignoreDevice TRUE if the device settings on the grabs are to be * ignored. * @return TRUE if the grabs match or FALSE otherwise. */ Bool GrabMatchesSecond(GrabPtr pFirstGrab, GrabPtr pSecondGrab, Bool ignoreDevice) { unsigned int any_modifier = (pFirstGrab->grabtype == GRABTYPE_XI2) ? (unsigned int)XIAnyModifier : (unsigned int)AnyModifier; if (pFirstGrab->grabtype != pSecondGrab->grabtype) return FALSE; if (pFirstGrab->grabtype == GRABTYPE_XI2) { if (pFirstGrab->device == inputInfo.all_devices || pSecondGrab->device == inputInfo.all_devices) { /* do nothing */ } else if (pFirstGrab->device == inputInfo.all_master_devices) { if (pSecondGrab->device != inputInfo.all_master_devices && !IsMaster(pSecondGrab->device)) return FALSE; } else if (pSecondGrab->device == inputInfo.all_master_devices) { if (pFirstGrab->device != inputInfo.all_master_devices && !IsMaster(pFirstGrab->device)) return FALSE; } else if (pSecondGrab->device != pFirstGrab->device) return FALSE; } else if (!ignoreDevice && ((pFirstGrab->device != pSecondGrab->device) || (pFirstGrab->modifierDevice != pSecondGrab->modifierDevice))) return FALSE; if (pFirstGrab->type != pSecondGrab->type) return FALSE; if (GrabSupersedesSecond(pFirstGrab, pSecondGrab) || GrabSupersedesSecond(pSecondGrab, pFirstGrab)) return TRUE; if (DetailSupersedesSecond(pSecondGrab->detail, pFirstGrab->detail, (unsigned int)AnyKey) && DetailSupersedesSecond(pFirstGrab->modifiersDetail, pSecondGrab->modifiersDetail, any_modifier)) return TRUE; if (DetailSupersedesSecond(pFirstGrab->detail, pSecondGrab->detail, (unsigned int)AnyKey) && DetailSupersedesSecond(pSecondGrab->modifiersDetail, pFirstGrab->modifiersDetail, any_modifier)) return TRUE; return FALSE; }
static int attach_slave(ClientPtr client, xXIAttachSlaveInfo *c, int flags[MAXDEVICES]) { DeviceIntPtr dev; DeviceIntPtr newmaster; int rc; rc = dixLookupDevice(&dev, c->deviceid, client, DixManageAccess); if (rc != Success) goto unwind; if (IsMaster(dev)) { client->errorValue = c->deviceid; rc = BadDevice; goto unwind; } /* Don't allow changes to XTest Devices, these are fixed */ if (IsXTestDevice(dev, NULL)) { client->errorValue = c->deviceid; rc = BadDevice; goto unwind; } rc = dixLookupDevice(&newmaster, c->new_master, client, DixAddAccess); if (rc != Success) goto unwind; if (!IsMaster(newmaster)) { client->errorValue = c->new_master; rc = BadDevice; goto unwind; } if (!((IsPointerDevice(newmaster) && IsPointerDevice(dev)) || (IsKeyboardDevice(newmaster) && IsKeyboardDevice(dev)))) { rc = BadDevice; goto unwind; } ReleaseButtonsAndKeys(dev); AttachDevice(client, dev, newmaster); flags[dev->id] |= XISlaveAttached; unwind: return rc; }
void XkbDDXFakeDeviceButton(DeviceIntPtr dev,Bool press,int button) { EventListPtr events; int nevents, i; DeviceIntPtr ptr; /* If dev is a slave device, and the SD is attached, do nothing. If we'd * post through the attached master pointer we'd get duplicate events. * * if dev is a master keyboard, post through the XTEST device * * if dev is a floating slave, post through the device itself. */ if (IsMaster(dev)) ptr = GetXTestDevice(GetMaster(dev, MASTER_POINTER)); else if (!dev->u.master) ptr = dev; else return; events = InitEventList(GetMaximumEventsNum()); OsBlockSignals(); nevents = GetPointerEvents(events, ptr, press ? ButtonPress : ButtonRelease, button, 0 /* flags */, 0 /* first */, 0 /* num_val */, NULL); OsReleaseSignals(); for (i = 0; i < nevents; i++) mieqProcessDeviceEvent(ptr, (InternalEvent*)events[i].event, NULL); FreeEventList(events, GetMaximumEventsNum()); }
static int detach_slave(ClientPtr client, xXIDetachSlaveInfo *c, int flags[MAXDEVICES]) { DeviceIntPtr dev; int rc; rc = dixLookupDevice(&dev, c->deviceid, client, DixManageAccess); if (rc != Success) goto unwind; if (IsMaster(dev)) { client->errorValue = c->deviceid; rc = BadDevice; goto unwind; } /* Don't allow changes to XTest Devices, these are fixed */ if (IsXTestDevice(dev, NULL)) { client->errorValue = c->deviceid; rc = BadDevice; goto unwind; } ReleaseButtonsAndKeys(dev); AttachDevice(client, dev, NULL); flags[dev->id] |= XISlaveDetached; unwind: return rc; }
/* Move the pointer on the current screen, and update the sprite. */ static void miPointerMoveNoEvent (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) { miPointerPtr pPointer; SetupScreen(pScreen); pPointer = MIPOINTER(pDev); /* Hack: We mustn't call into ->MoveCursor for anything but the * VCP, as this may cause a non-HW rendered cursor to be rendered during * SIGIO. This again leads to allocs during SIGIO which leads to SIGABRT. */ if ((pDev == inputInfo.pointer || (!IsMaster(pDev) && pDev->u.master == inputInfo.pointer)) && !pScreenPriv->waitForUpdate && pScreen == pPointer->pSpriteScreen) { pPointer->devx = x; pPointer->devy = y; if(pPointer->pCursor && !pPointer->pCursor->bits->emptyMask) (*pScreenPriv->spriteFuncs->MoveCursor) (pDev, pScreen, x, y); } pPointer->x = x; pPointer->y = y; pPointer->pScreen = pScreen; }
static Bool miPointerDisplayCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) { miPointerPtr pPointer; /* return for keyboards */ if ((IsMaster(pDev) && !DevHasCursor(pDev)) || (!IsMaster(pDev) && pDev->u.master && !DevHasCursor(pDev->u.master))) return FALSE; pPointer = MIPOINTER(pDev); pPointer->pCursor = pCursor; pPointer->pScreen = pScreen; miPointerUpdateSprite(pDev); return TRUE; }
int ProcXIAllowEvents(ClientPtr client) { TimeStamp time; DeviceIntPtr dev; int ret = Success; REQUEST(xXIAllowEventsReq); REQUEST_SIZE_MATCH(xXIAllowEventsReq); ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess); if (ret != Success) return ret; time = ClientTimeToServerTime(stuff->time); switch (stuff->mode) { case XIReplayDevice: AllowSome(client, time, dev, NOT_GRABBED); break; case XISyncDevice: AllowSome(client, time, dev, FREEZE_NEXT_EVENT); break; case XIAsyncDevice: AllowSome(client, time, dev, THAWED); break; case XIAsyncPairedDevice: if (IsMaster(dev)) AllowSome(client, time, dev, THAW_OTHERS); break; case XISyncPair: if (IsMaster(dev)) AllowSome(client, time, dev, FREEZE_BOTH_NEXT_EVENT); break; case XIAsyncPair: if (IsMaster(dev)) AllowSome(client, time, dev, THAWED_BOTH); break; default: client->errorValue = stuff->mode; ret = BadValue; } return ret; }
/** * @return Whether the device should be included in the returned list. */ static Bool ShouldSkipDevice(ClientPtr client, int deviceid, DeviceIntPtr dev) { /* if all devices are not being queried, only master devices are */ if (deviceid == XIAllDevices || IsMaster(dev)) { int rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixGetAttrAccess); if (rc == Success) return FALSE; } return TRUE; }
/* Clean up after device. This function will be called once before the device is freed in the DIX */ static void miPointerDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen) { SetupScreen(pScreen); if (!IsMaster(pDev) && pDev->u.master) return; (*pScreenPriv->spriteFuncs->DeviceCursorCleanup)(pDev, pScreen); free(dixLookupPrivate(&pDev->devPrivates, miPointerPrivKey)); dixSetPrivate(&pDev->devPrivates, miPointerPrivKey, NULL); }
int ProcXIGrabDevice(ClientPtr client) { DeviceIntPtr dev; xXIGrabDeviceReply rep; int ret = Success; uint8_t status; GrabMask mask; int mask_len; REQUEST(xXIGrabDeviceReq); REQUEST_AT_LEAST_SIZE(xXIGrabDeviceReq); ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess); if (ret != Success) return ret; if (!IsMaster(dev)) stuff->paired_device_mode = GrabModeAsync; if (XICheckInvalidMaskBits((unsigned char*)&stuff[1], stuff->mask_len * 4) != Success) return BadValue; mask_len = min(sizeof(mask.xi2mask[stuff->deviceid]), stuff->mask_len * 4); memset(mask.xi2mask, 0, sizeof(mask.xi2mask)); memcpy(mask.xi2mask, (char*)&stuff[1], mask_len); ret = GrabDevice(client, dev, stuff->grab_mode, stuff->paired_device_mode, stuff->grab_window, stuff->owner_events, stuff->time, &mask, GRABTYPE_XI2, stuff->cursor, None /* confineTo */, &status); if (ret != Success) return ret; rep.repType = X_Reply; rep.RepType = X_XIGrabDevice; rep.length = 0; rep.sequenceNumber = client->sequence; rep.status = status; WriteReplyToClient(client, sizeof(rep), &rep); return ret; }
void CGame::HandleKey( int a_iPlayer, int a_iKey, bool a_bDown ) { int iCurrentTick = g_oBackend.m_iGameTick + m_iEnqueueDelay; if ( IsNetworkGame() ) { a_iPlayer = IsMaster() ? 0 : 1; g_poNetwork->SendKeystroke( iCurrentTick, a_iKey, a_bDown ); } m_oKeyQueue.EnqueueKey( iCurrentTick, a_iPlayer, a_iKey, a_bDown ); }
void AMagnetTile::activate() { if ( activated || !canActivate ) return; Super::activate(); magnetParticle->Activate( true ); magnetParticle->ActivateSystem(); magnetParticle->EmitterInstances[0]->SetBeamTargetPoint( magnetParticle->GetComponentLocation() , 0 ); if ( IsMaster() ) { magnetSound->Play(); } }
/** * If master is NULL, return TRUE if the given device is an xtest device or * FALSE otherwise. * If master is not NULL, return TRUE if the given device is this master's * xtest device. */ BOOL IsXTestDevice(DeviceIntPtr dev, DeviceIntPtr master) { if (IsMaster(dev)) return FALSE; /* deviceid 0 is reserved for XIAllDevices, non-zero mid means XTest * device */ if (master) return dev->xtest_master_id == master->id; return dev->xtest_master_id != 0; }
BOOL CCampus::IsChangeBuffLevel( u_long idPlayer ) { if( IsMaster( idPlayer ) ) { int nLevel = GetBuffLevel( idPlayer ); if( m_nPreBuffLevel != nLevel ) { m_nPreBuffLevel = nLevel; return TRUE; } } return FALSE; }
void AMagnetTile::deactivate() { if (!activated ) return; Super::deactivate(); if ( magnetParticle->IsActive() ) { magnetParticle->DeactivateSystem(); magnetParticle->Deactivate(); } if ( IsMaster() ) { magnetSound->Stop(); } KillSubMagnet(); }
void AMagnetTile::BeginPlay() { Super::BeginPlay(); if ( IsMaster() ) { GetWorld()->GetFirstPlayerController()->InputComponent->BindAction( "ActivateCube" , IE_Released , this , &AMagnetTile::deactivate ); } magnetParticle->SetVisibility( true ); magnetParticle->DeactivateSystem(); magnetParticle->Deactivate(); auto forward = GetClampedForwardVector(); if ( forward.Z == -1.0f ) { isVertical = true; } }
void RunAction::EndOfRunAction(const G4Run* run) { G4int nofEvents = run -> GetNumberOfEvent(); if (nofEvents == 0) return; // Our run conditions const PrimaryGeneratorAction* generatorAction = static_cast<const PrimaryGeneratorAction*> (G4RunManager::GetRunManager() -> GetUserPrimaryGeneratorAction()); G4String partName; if (generatorAction) { G4ParticleDefinition* particle = generatorAction -> GetParticleGun() -> GetParticleDefinition(); partName = particle -> GetParticleName(); } // Get our results \ o / const Run* tRun = static_cast<const Run*>(run); G4double sumDose = tRun -> GetSumDose(); // And print the data if (IsMaster()) { G4cout << G4endl << "--------------- End of Global Run --------------" << G4endl << " The run was " << nofEvents << "events "; } else { G4cout << G4endl << "--------------- End of Local Run ---------------" << G4endl << " The run was " << nofEvents << " " << partName; } G4cout << G4endl << "Total dose to the plate : " << G4BestUnit(sumDose, "Dose") << G4endl << "--------------------------------------------------" << G4endl << G4endl; }
int GetDeviceUse(DeviceIntPtr dev, uint16_t *attachment) { DeviceIntPtr master = dev->u.master; int use; if (IsMaster(dev)) { DeviceIntPtr paired = GetPairedDevice(dev); use = IsPointerDevice(dev) ? XIMasterPointer : XIMasterKeyboard; *attachment = (paired ? paired->id : 0); } else if (master) { use = IsPointerDevice(master) ? XISlavePointer : XISlaveKeyboard; *attachment = master->id; } else use = XIFloatingSlave; return use; }
int ProcXIChangeCursor(ClientPtr client) { int rc; WindowPtr pWin = NULL; DeviceIntPtr pDev = NULL; CursorPtr pCursor = NULL; REQUEST(xXIChangeCursorReq); REQUEST_SIZE_MATCH(xXIChangeCursorReq); rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixSetAttrAccess); if (rc != Success) return rc; if (!IsMaster(pDev) || !IsPointerDevice(pDev)) return BadDevice; if (stuff->win != None) { rc = dixLookupWindow(&pWin, stuff->win, client, DixSetAttrAccess); if (rc != Success) return rc; } if (stuff->cursor == None) { if (pWin == pWin->drawable.pScreen->root) pCursor = rootCursor; else pCursor = (CursorPtr)None; } else { rc = dixLookupResourceByType((pointer *)&pCursor, stuff->cursor, RT_CURSOR, client, DixUseAccess); if (rc != Success) return rc; } ChangeWindowDeviceCursor(pWin, pDev, pCursor); return Success; }
int CCampus::GetBuffLevel( u_long idPlayer ) { int nLevel = 0; if( IsMaster( idPlayer ) ) { for( MAP_CM::iterator it = m_mapCM.begin(); it != m_mapCM.end(); ++it ) { CUser* pPupil = g_UserMng.GetUserByPlayerID( ( it->second )->GetPlayerId() ); if( IsValidObj( pPupil ) && ( it->second )->GetLevel() == CAMPUS_PUPIL ) ++nLevel; } } else { CUser* pMaster = g_UserMng.GetUserByPlayerID( GetMaster() ); if( IsValidObj( pMaster ) ) ++nLevel; } return nLevel; }
int ProcXOpenDevice(ClientPtr client) { xInputClassInfo evbase[numInputClasses]; int j = 0; int status = Success; xOpenDeviceReply rep; DeviceIntPtr dev; REQUEST(xOpenDeviceReq); REQUEST_SIZE_MATCH(xOpenDeviceReq); status = dixLookupDevice(&dev, stuff->deviceid, client, DixUseAccess); if (status == BadDevice) { /* not open */ for (dev = inputInfo.off_devices; dev; dev = dev->next) if (dev->id == stuff->deviceid) break; if (dev == NULL) return BadDevice; } else if (status != Success) return status; if (IsMaster(dev)) return BadDevice; OpenInputDevice(dev, client, &status); if (status != Success) return status; memset(&rep, 0, sizeof(xOpenDeviceReply)); rep.repType = X_Reply; rep.RepType = X_OpenDevice; rep.sequenceNumber = client->sequence; if (dev->key != NULL) { evbase[j].class = KeyClass; evbase[j++].event_type_base = event_base[KeyClass]; }
static Bool xf86RandRSetConfig (ScreenPtr pScreen, Rotation rotation, int rate, RRScreenSizePtr pSize) { ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); DisplayModePtr mode; int pos[MAXDEVICES][2]; Bool useVirtual = FALSE; Rotation oldRotation = randrp->rotation; DeviceIntPtr dev; Bool view_adjusted = FALSE; for (dev = inputInfo.devices; dev; dev = dev->next) { if (!IsMaster(dev) && !IsFloating(dev)) continue; miPointerGetPosition(dev, &pos[dev->id][0], &pos[dev->id][1]); } for (mode = scrp->modes; ; mode = mode->next) { if (mode->HDisplay == pSize->width && mode->VDisplay == pSize->height && (rate == 0 || xf86RandRModeRefresh (mode) == rate)) break; if (mode->next == scrp->modes) { if (pSize->width == randrp->virtualX && pSize->height == randrp->virtualY) { mode = scrp->modes; useVirtual = TRUE; break; } return FALSE; } } if (randrp->rotation != rotation) { /* Have the driver do its thing. */ if (scrp->DriverFunc) { xorgRRRotation RRRotation; RRRotation.RRConfig.rotation = rotation; RRRotation.RRConfig.rate = rate; RRRotation.RRConfig.width = pSize->width; RRRotation.RRConfig.height = pSize->height; /* * Currently we need to rely on HW support for rotation. */ if (!(*scrp->DriverFunc)(scrp, RR_SET_CONFIG, &RRRotation)) return FALSE; } else return FALSE; randrp->rotation = rotation; } if (!xf86RandRSetMode (pScreen, mode, useVirtual, pSize->mmWidth, pSize->mmHeight)) { if(randrp->rotation != oldRotation) { /* Have the driver undo its thing. */ if (scrp->DriverFunc) { xorgRRRotation RRRotation; RRRotation.RRConfig.rotation = oldRotation; RRRotation.RRConfig.rate = xf86RandRModeRefresh (scrp->currentMode); RRRotation.RRConfig.width = scrp->virtualX; RRRotation.RRConfig.height = scrp->virtualY; (*scrp->DriverFunc)(scrp, RR_SET_CONFIG, &RRRotation); } randrp->rotation = oldRotation; } return FALSE; } /* * Move the cursor back where it belongs; SwitchMode repositions it * FIXME: duplicated code, see modes/xf86RandR12.c */ for (dev = inputInfo.devices; dev; dev = dev->next) { if (!IsMaster(dev) && !IsFloating(dev)) continue; if (pScreen == miPointerGetScreen(dev)) { int px = pos[dev->id][0]; int py = pos[dev->id][1]; px = (px >= pScreen->width ? (pScreen->width - 1) : px); py = (py >= pScreen->height ? (pScreen->height - 1) : py); /* Setting the viewpoint makes only sense on one device */ if (!view_adjusted && IsMaster(dev)) { xf86SetViewport(pScreen, px, py); view_adjusted = TRUE; } (*pScreen->SetCursorPosition) (dev, pScreen, px, py, FALSE); } } return TRUE; }
static int remove_master(ClientPtr client, xXIRemoveMasterInfo *r, int flags[MAXDEVICES]) { DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd; int rc = Success; if (r->return_mode != XIAttachToMaster && r->return_mode != XIFloating) return BadValue; rc = dixLookupDevice(&ptr, r->deviceid, client, DixDestroyAccess); if (rc != Success) goto unwind; if (!IsMaster(ptr)) { client->errorValue = r->deviceid; rc = BadDevice; goto unwind; } /* XXX: For now, don't allow removal of VCP, VCK */ if (ptr == inputInfo.pointer || ptr == inputInfo.keyboard) { rc = BadDevice; goto unwind; } ptr = GetMaster(ptr, MASTER_POINTER); rc = dixLookupDevice(&ptr, ptr->id, client, DixDestroyAccess); if (rc != Success) goto unwind; keybd = GetMaster(ptr, MASTER_KEYBOARD); rc = dixLookupDevice(&keybd, keybd->id, client, DixDestroyAccess); if (rc != Success) goto unwind; XTestptr = GetXTestDevice(ptr); rc = dixLookupDevice(&XTestptr, XTestptr->id, client, DixDestroyAccess); if (rc != Success) goto unwind; XTestkeybd = GetXTestDevice(keybd); rc = dixLookupDevice(&XTestkeybd, XTestkeybd->id, client, DixDestroyAccess); if (rc != Success) goto unwind; disable_clientpointer(ptr); /* Disabling sends the devices floating, reattach them if * desired. */ if (r->return_mode == XIAttachToMaster) { DeviceIntPtr attached, newptr, newkeybd; rc = dixLookupDevice(&newptr, r->return_pointer, client, DixAddAccess); if (rc != Success) goto unwind; if (!IsMaster(newptr)) { client->errorValue = r->return_pointer; rc = BadDevice; goto unwind; } rc = dixLookupDevice(&newkeybd, r->return_keyboard, client, DixAddAccess); if (rc != Success) goto unwind; if (!IsMaster(newkeybd)) { client->errorValue = r->return_keyboard; rc = BadDevice; goto unwind; } for (attached = inputInfo.devices; attached; attached = attached->next) { if (!IsMaster(attached)) { if (GetMaster(attached, MASTER_ATTACHED) == ptr) { AttachDevice(client, attached, newptr); flags[attached->id] |= XISlaveAttached; } if (GetMaster(attached, MASTER_ATTACHED) == keybd) { AttachDevice(client, attached, newkeybd); flags[attached->id] |= XISlaveAttached; } } } } /* can't disable until we removed pairing */ keybd->spriteInfo->paired = NULL; ptr->spriteInfo->paired = NULL; XTestptr->spriteInfo->paired = NULL; XTestkeybd->spriteInfo->paired = NULL; /* disable the remove the devices, XTest devices must be done first else the sprites they rely on will be destroyed */ DisableDevice(XTestptr, FALSE); DisableDevice(XTestkeybd, FALSE); DisableDevice(keybd, FALSE); DisableDevice(ptr, FALSE); flags[XTestptr->id] |= XIDeviceDisabled | XISlaveDetached; flags[XTestkeybd->id] |= XIDeviceDisabled | XISlaveDetached; flags[keybd->id] |= XIDeviceDisabled; flags[ptr->id] |= XIDeviceDisabled; RemoveDevice(XTestptr, FALSE); RemoveDevice(XTestkeybd, FALSE); RemoveDevice(keybd, FALSE); RemoveDevice(ptr, FALSE); flags[XTestptr->id] |= XISlaveRemoved; flags[XTestkeybd->id] |= XISlaveRemoved; flags[keybd->id] |= XIMasterRemoved; flags[ptr->id] |= XIMasterRemoved; unwind: return rc; }
bool IsSlave(uchar ibPrt) { return( IsMaster(ibPrt) ? false : true ); }
const PcpPrimIndex & Usd_PrimData::GetPrimIndex() const { static const PcpPrimIndex dummyPrimIndex; return ARCH_UNLIKELY(IsMaster()) ? dummyPrimIndex : *_primIndex; }
/** This methods executes one round of gameplay. The game progresses through phases Ph_START, Ph_NORMAL, and Ph_KO. If a KO happened, it will invoke InstantReplay. At the end of the round m_aiRoundsWonByPlayer[x] will be incremented depending on the outcome. m_iNumberOfRounds will also increase by 1. */ void CGame::DoOneRound() { m_enGamePhase = Ph_START; m_poBackground->DeleteExtraLayers(); int iTeamSize = (SState::Team_ONE_VS_ONE==g_oState.m_enTeamMode) ? 1 : g_oPlayerSelect.GetPlayerInfo(0).m_aenTeam.size(); int aiTeamNumber[MAXPLAYERS]; for ( int i=0; i<g_oState.m_iNumPlayers; ++i ) { aiTeamNumber[i] = 0; } if ( IsTeamMode() ) { for ( int i=0; i<g_oState.m_iNumPlayers; ++i ) { g_oPlayerSelect.SetPlayer( i, g_oPlayerSelect.GetPlayerInfo(i).m_aenTeam[aiTeamNumber[i]] ); } } g_oBackend.PerlEvalF( "GameStart(%d,%d,%d,%d,%d);", IsMaster() ? g_oState.m_iHitPoints : g_poNetwork->GetGameParams().iHitPoints, g_oState.m_iNumPlayers, iTeamSize, m_bWide, m_bDebug ); g_oBackend.ReadFromPerl(); if ( IsNetworkGame() ) { g_poNetwork->SynchStartRound(); g_poNetwork->SendGameTick( g_oBackend.m_iGameTick-1 ); } int iKoFrame = -1; double dGameTime = 2 * 1000; // Only for the "greeting phase", the real gametime will be set after. int iThisTick, iLastTick, iGameSpeed; bool bHurryUp = false; bool bReplayAfter = true; iGameSpeed = IsMaster() ? g_oState.m_iGameSpeed : g_poNetwork->GetGameParams().iGameSpeed; iThisTick = SDL_GetTicks() / iGameSpeed; iLastTick = iThisTick - 1; m_oKeyQueue.Reset(); oFpsCounter.Reset(); // 1. DO THE NORMAL GAME ROUND (START, NORMAL, KO, TIMEUP) while ( dGameTime >= 0 ) { if ( m_enInitialGameMode != g_oState.m_enGameMode ) { return; } // 1. Wait for the next tick (on extremely fast machines..) while (iThisTick == iLastTick) { iThisTick = SDL_GetTicks() / iGameSpeed; if ( iThisTick==iLastTick ) SDL_Delay(1); } // 2. Advance as many ticks as necessary.. int iNumTicks = iThisTick - iLastTick; if ( iNumTicks > MAXFRAMESKIP ) iNumTicks = MAXFRAMESKIP; Advance( iNumTicks ); dGameTime -= iNumTicks * iGameSpeed; // 3. Check for state transitions and game time. // START -> NORMAL // NORMAL -> KO // NORMAL -> TIMEUP // bHurryUp flag can be set during NORMAL phase if ( Ph_START == m_enGamePhase ) // Check for the end of the START phase { if ( dGameTime <= 0 ) { m_enGamePhase = Ph_NORMAL; dGameTime = (IsMaster() ? g_oState.m_iRoundLength : g_poNetwork->GetGameParams().iRoundLength) * 1000; } } else if ( Ph_NORMAL == m_enGamePhase ) // Check for the end of the NORMAL phase { if ( dGameTime < 10 * 1000 && !bHurryUp ) { bHurryUp = true; g_poNetwork->SendHurryup( 1 ); HurryUp(); iGameSpeed = iGameSpeed * 3 / 4; } if ( g_oBackend.m_bKO ) { m_enGamePhase = Ph_KO; dGameTime = 10 * 1000; iKoFrame = m_aReplayOffsets.size(); } else if ( dGameTime <= 0 ) { m_enGamePhase = Ph_TIMEUP; g_poNetwork->SendHurryup( 2 ); TimeUp(); break; } } m_iGameTime = (int) ((dGameTime + 500.0) / 1000.0); iLastTick = iThisTick; // ProcessEvents will read keyboard/gamepad input // It will also transmit them to the remote side in a network game. if ( ProcessEvents() || g_oState.m_bQuitFlag ) { bReplayAfter = false; break; } oFpsCounter.Tick(); // 3. Draw the next game screen.. Draw(); // 4. Check 'end of round' condition. for ( int i=0; i<g_oState.m_iNumPlayers; ++i ) { if ( g_oBackend.m_aoPlayers[i].m_iRealHitPoints <= -10000 ) { // We have a dead player here. if ( aiTeamNumber[i] < iTeamSize-1 ) { ++aiTeamNumber[i]; AddBodyToBackground( i ); FighterEnum enFighter = g_oPlayerSelect.GetPlayerInfo(i).m_aenTeam[ aiTeamNumber[i] ]; g_oPlayerSelect.SetPlayer( i, enFighter ); g_oBackend.PerlEvalF( "NextTeamMember(%d,%d);", i, enFighter ); } } } if ( g_oBackend.m_iGameOver ) { break; } if ( !IsMaster() ) { if ( g_poNetwork->IsRoundOver() ) { break; } } } int p1h = g_oBackend.m_aoPlayers[0].m_iRealHitPoints; int p2h = g_oBackend.m_aoPlayers[1].m_iRealHitPoints; // 3. DO THE REPLAY (IF THERE WAS A KO) if ( iKoFrame>0 && bReplayAfter && !IsNetworkGame() ) { InstantReplay( iKoFrame ); } // 4. END OF ROUND debug( "Game over; p1h = %d; p2h = %d\n", p1h, p2h ); if ( IsMaster() ) { int iWhoWon = -1; if ( p1h > p2h ) { ++m_aiRoundsWonByPlayer[0]; iWhoWon = 0; } if ( p2h > p1h ) { ++m_aiRoundsWonByPlayer[1]; iWhoWon = 1; } if ( IsNetworkGame() ) { g_poNetwork->SendGameTick( g_oBackend.m_iGameTick + m_iEnqueueDelay * 100 ); g_poNetwork->SendRoundOver( iWhoWon, m_iNumberOfRounds > 0 ); } } else { int iWhoWon = g_poNetwork->GetWhoWon(); if ( iWhoWon>=0 ) { ++m_aiRoundsWonByPlayer[iWhoWon]; } } ++m_iNumberOfRounds; }
int ProcXIQueryPointer(ClientPtr client) { int rc; xXIQueryPointerReply rep; DeviceIntPtr pDev, kbd; WindowPtr pWin, t; SpritePtr pSprite; XkbStatePtr state; char *buttons = NULL; int buttons_size = 0; /* size of buttons array */ REQUEST(xXIQueryPointerReq); REQUEST_SIZE_MATCH(xXIQueryPointerReq); rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixReadAccess); if (rc != Success) { client->errorValue = stuff->deviceid; return rc; } if (pDev->valuator == NULL || IsKeyboardDevice(pDev) || (!IsMaster(pDev) && pDev->u.master)) /* no attached devices */ { client->errorValue = stuff->deviceid; return BadDevice; } rc = dixLookupWindow(&pWin, stuff->win, client, DixGetAttrAccess); if (rc != Success) { SendErrorToClient(client, IReqCode, X_XIQueryPointer, stuff->win, rc); return Success; } if (pDev->valuator->motionHintWindow) MaybeStopHint(pDev, client); if (IsMaster(pDev)) kbd = GetPairedDevice(pDev); else kbd = (pDev->key) ? pDev : NULL; pSprite = pDev->spriteInfo->sprite; memset(&rep, 0, sizeof(rep)); rep.repType = X_Reply; rep.RepType = X_XIQueryPointer; rep.length = 6; rep.sequenceNumber = client->sequence; rep.root = (GetCurrentRootWindow(pDev))->drawable.id; rep.root_x = FP1616(pSprite->hot.x, 0); rep.root_y = FP1616(pSprite->hot.y, 0); rep.child = None; if (kbd) { state = &kbd->key->xkbInfo->prev_state; rep.mods.base_mods = state->base_mods; rep.mods.latched_mods = state->latched_mods; rep.mods.locked_mods = state->locked_mods; rep.group.base_group = state->base_group; rep.group.latched_group = state->latched_group; rep.group.locked_group = state->locked_group; } if (pDev->button) { int i, down; rep.buttons_len = bytes_to_int32(bits_to_bytes(pDev->button->numButtons)); rep.length += rep.buttons_len; buttons_size = rep.buttons_len * 4; buttons = xcalloc(1, buttons_size); if (!buttons) return BadAlloc; down = pDev->button->buttonsDown; for (i = 0; i < pDev->button->numButtons && down; i++) { if (BitIsOn(pDev->button->down, i)) { SetBit(buttons, i); down--; } } } else rep.buttons_len = 0; if (pSprite->hot.pScreen == pWin->drawable.pScreen) { rep.same_screen = xTrue; rep.win_x = FP1616(pSprite->hot.x - pWin->drawable.x, 0); rep.win_y = FP1616(pSprite->hot.y - pWin->drawable.y, 0); for (t = pSprite->win; t; t = t->parent) if (t->parent == pWin) { rep.child = t->drawable.id; break; } } else { rep.same_screen = xFalse; rep.win_x = 0; rep.win_y = 0; } #ifdef PANORAMIX if(!noPanoramiXExtension) { rep.root_x += FP1616(panoramiXdataPtr[0].x, 0); rep.root_y += FP1616(panoramiXdataPtr[0].y, 0); if (stuff->win == rep.root) { rep.win_x += FP1616(panoramiXdataPtr[0].x, 0); rep.win_y += FP1616(panoramiXdataPtr[0].y, 0); } } #endif WriteReplyToClient(client, sizeof(xXIQueryPointerReply), &rep); if (buttons) WriteToClient(client, buttons_size, buttons); xfree(buttons); return Success; }
void CGame::Advance( int a_iNumFrames ) { if ( m_bIsReplay ) { // Replay mode... m_iFrame += a_iNumFrames; if ( m_iFrame >= ((int)m_aReplayOffsets.size())-1 ) m_iFrame = m_aReplayOffsets.size() - 2; if ( m_iFrame <= 0 ) m_iFrame = 0; std::string sFrameDesc = m_sReplayString.substr( m_aReplayOffsets[m_iFrame], m_aReplayOffsets[m_iFrame+1] - m_aReplayOffsets[m_iFrame] ); g_oBackend.ReadFromString( sFrameDesc ); return; } static std::string sFrameDesc; if ( IsNetworkGame() ) { g_poNetwork->SendGameTick( g_oBackend.m_iGameTick ); g_poNetwork->Update(); int i = 0; while ( g_poNetwork->GetGameTick() + m_iEnqueueDelay < g_oBackend.m_iGameTick + a_iNumFrames ) { ++i; if ( i > 300 ) { // Waited for too long.. g_poNetwork->Stop(); } // The remote side is lagging behind.. Wait for it. SDL_Delay( 10 ); g_poNetwork->Update(); if ( m_enInitialGameMode != g_oState.m_enGameMode ) { return; } } int iTime; int iKey; bool bPressed; while ( g_poNetwork->GetKeystroke( iTime, iKey, bPressed ) ) { debug( "Got GetKeystroke: %d, %d, %d at %d\n", iTime, iKey, bPressed, g_oBackend.m_iGameTick ); // g_oBackend.PerlEvalF( bPressed ? "KeyDown(%d,%d);" : "KeyUp(%d,%d);", 1, iKey ); m_oKeyQueue.EnqueueKey( iTime, IsMaster() ? 1 : 0, iKey, bPressed ); if ( iTime <= g_oBackend.m_iGameTick ) { debug( "KEY ARRIVED TOO LATE!!!\n" ); } } } while ( a_iNumFrames > 0 ) { -- a_iNumFrames; g_oBackend.AdvancePerl(); g_oBackend.ReadFromPerl(); g_oBackend.PlaySounds(); m_oKeyQueue.DequeueKeys( g_oBackend.m_iGameTick ); g_oBackend.WriteToString( sFrameDesc ); m_sReplayString += sFrameDesc; m_sReplayString += '\n'; m_aReplayOffsets.push_back( m_sReplayString.size() ); } }
int ProcXIGrabDevice(ClientPtr client) { DeviceIntPtr dev; xXIGrabDeviceReply rep; int ret = Success; uint8_t status; GrabMask mask = { 0 }; int mask_len; REQUEST(xXIGrabDeviceReq); REQUEST_AT_LEAST_SIZE(xXIGrabDeviceReq); ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess); if (ret != Success) return ret; if (!IsMaster(dev)) stuff->paired_device_mode = GrabModeAsync; if (XICheckInvalidMaskBits(client, (unsigned char *) &stuff[1], stuff->mask_len * 4) != Success) return BadValue; mask.xi2mask = xi2mask_new(); if (!mask.xi2mask) return BadAlloc; mask_len = min(xi2mask_mask_size(mask.xi2mask), stuff->mask_len * 4); /* FIXME: I think the old code was broken here */ xi2mask_set_one_mask(mask.xi2mask, dev->id, (unsigned char *) &stuff[1], mask_len); ret = GrabDevice(client, dev, stuff->grab_mode, stuff->paired_device_mode, stuff->grab_window, stuff->owner_events, stuff->time, &mask, XI2, stuff->cursor, None /* confineTo */ , &status); xi2mask_free(&mask.xi2mask); if (ret != Success) return ret; rep = (xXIGrabDeviceReply) { .repType = X_Reply, .RepType = X_XIGrabDevice, .sequenceNumber = client->sequence, .length = 0, .status = status }; WriteReplyToClient(client, sizeof(rep), &rep); return ret; } int SProcXIUngrabDevice(ClientPtr client) { REQUEST(xXIUngrabDeviceReq); swaps(&stuff->length); swaps(&stuff->deviceid); swapl(&stuff->time); return ProcXIUngrabDevice(client); }