예제 #1
0
TEST(BitMap, contains__unaligned) {
  BitMapMemory mx(aligned_size);
  BitMapMemory my(aligned_size);

  BitMapView x = mx.make_view(unaligned_size, even_bits);
  BitMapView y = my.make_view(unaligned_size, even_bits);

  // Check that a missing bit beyond the end of x doesn't count.
  {
    BitMapView aligned = BitMapView(mx.memory(), aligned_size);
    const idx_t index = aligned_size - 2;
    STATIC_ASSERT(unaligned_size <= index);

    WithBitClear wbc(aligned, index);
    EXPECT_TRUE(x.contains(y));
  }

  // Check that a missing bit in the final partial word does count.
  {
    idx_t index = unaligned_size - 2;
    ASSERT_LE(BitMap::word_align_down(unaligned_size), index);

    WithBitClear wbc(x, index);
    EXPECT_FALSE(x.contains(y));
  }
}
예제 #2
0
/*
 * Toolbar
 */
nsresult
nsWebShellWindow::Toolbar()
{
    nsCOMPtr<nsIXULWindow> kungFuDeathGrip(this);
    nsCOMPtr<nsIWebBrowserChrome> wbc(do_GetInterface(kungFuDeathGrip));
    if (!wbc)
      return NS_ERROR_UNEXPECTED;

    // rjc: don't use "nsIWebBrowserChrome::CHROME_EXTRA"
    //      due to components with multiple sidebar components
    //      (such as Mail/News, Addressbook, etc)... and frankly,
    //      Mac IE, OmniWeb, and other Mac OS X apps all work this way

    PRUint32    chromeMask = (nsIWebBrowserChrome::CHROME_TOOLBAR |
                              nsIWebBrowserChrome::CHROME_LOCATIONBAR |
                              nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR);

    PRUint32    chromeFlags, newChromeFlags = 0;
    wbc->GetChromeFlags(&chromeFlags);
    newChromeFlags = chromeFlags & chromeMask;
    if (!newChromeFlags)    chromeFlags |= chromeMask;
    else                    chromeFlags &= (~newChromeFlags);
    wbc->SetChromeFlags(chromeFlags);
    return NS_OK;
}
예제 #3
0
TEST(BitMap, contains__aligned) {
  BitMapMemory mx(aligned_size);
  BitMapMemory my(aligned_size);

  BitMapView x = mx.make_view(aligned_size, even_bits);
  BitMapView y = my.make_view(aligned_size, even_bits);
  EXPECT_TRUE(x.contains(y));

  WithBitClear wbc(x, aligned_size / 2);
  EXPECT_FALSE(x.contains(y));
}
예제 #4
0
void sim_frame(const narf::Input &input, narf::timediff dt)
{
	if (input.text() != "") {
		if (input.text()[0] == '/') { // commands begin with slash
			narf::cmd::exec(input.text().substr(1));
		} else {
			chat(input.text());
		}
	}

	// tell the console whether to draw the cursor
	clientConsole->setEditState(input.state() == narf::Input::InputStateText);

	if (input.state() == narf::Input::InputStateText) {
		SDL_SetRelativeMouseMode(SDL_FALSE);
	} else {
		SDL_SetRelativeMouseMode(SDL_TRUE);
	}

	narf::Vector3f vel_rel(0.0f, 0.0f, 0.0f);

	float movePitch = 0.0f;

	if (playerEID != narf::Entity::InvalidID) {
		narf::EntityRef player(world->entityManager, playerEID);

		if (player.ent && player->antigrav) {
			// if flying, move in the direction of camera including pitch
			movePitch = cam.orientation.pitch;
		}

		if (input.moveForward()) {
			vel_rel += narf::Orientationf(movePitch, cam.orientation.yaw);
		} else if (input.moveBackward()) {
			vel_rel -= narf::Orientationf(movePitch, cam.orientation.yaw);
		}

		if (input.strafeLeft()) {
			vel_rel += narf::Orientationf(0.0f, cam.orientation.yaw + (float)M_PI / 2);
		} else if (input.strafeRight()) {
			vel_rel -= narf::Orientationf(0.0f, cam.orientation.yaw + (float)M_PI / 2);
		}

		// normalize so that diagonal movement is not faster than cardinal directions
		vel_rel = vel_rel.normalize() * (input.run() ? runspeed : movespeed);

		if (connectState == ConnectState::Unconnected) {
			// TODO: do client-side prediction
			if (input.jump()) {
				if (player->onGround) {
					vel_rel += narf::Vector3f(0.0f, 0.0f, 8.0f);
				} else if (player->velocity.z > 0.0f) {
					// still going up - double jump triggers flying
					player->antigrav = true;
					narf::console->println("entered antigrav mode");
				}
			}

			// hax
			player->velocity.x = vel_rel.x;
			player->velocity.y = vel_rel.y;
			player->velocity.z += vel_rel.z;

			if (player->antigrav) {
				player->velocity.z = vel_rel.z;
			}
		}
	}

	world->update(dt);

	if (playerEID != narf::Entity::InvalidID) {
		narf::EntityRef player(world->entityManager, playerEID);
		if (player.ent) {
			if (player->onGround && player->antigrav) {
				player->antigrav = false;
				narf::console->println("left antigrav mode");
			}

			// lock camera to player
			cam.position = player->position;
			cam.position.z += 1.6f;
		}
	}

	// Let's see what we're looking at
	auto pos = narf::Point3f(cam.position.x, cam.position.y, cam.position.z);
	auto maxInteractDistance = 7.5f;
	selectedBlockFace = {};
	bool traceHitBlock = false;
	world->rayTrace(pos, cam.orientation,
		[&](const narf::Point3f& point, const narf::BlockCoord& blockCoord, const narf::BlockFace& face){
			if (point.distanceTo(pos) >= maxInteractDistance) {
				return true; // ran out of distance
			}

			// TODO: stop the trace if it runs off the edge of the world
			auto block = world->getBlock(blockCoord);
			if (block && block->id != 0) {
				// found a solid block
				selectedBlockFace = {block, blockCoord.x, blockCoord.y, blockCoord.z, face};
				traceHitBlock = true;
				return true; // stop the trace
			}
			return false; // keep going
		});

	if (traceHitBlock) {
		if (input.actionPrimaryBegin() || input.actionSecondaryBegin()) {
			narf::BlockCoord wbc(selectedBlockFace.x, selectedBlockFace.y, selectedBlockFace.z);
			if (input.actionPrimaryBegin()) {
				// remove block at cursor
				narf::PlayerCommand cmd(narf::PlayerCommand::Type::PrimaryAction);
				cmd.wbc = wbc;
				playerCommandQueue.push(cmd);
			} else {
				// add new block next to selected face
				// TODO: move this adjustment to PlayerCommand::exec()
				switch (selectedBlockFace.face) {
				case narf::BlockFace::XPos: wbc.x++; break;
				case narf::BlockFace::XNeg: wbc.x--; break;
				case narf::BlockFace::YPos: wbc.y++; break;
				case narf::BlockFace::YNeg: wbc.y--; break;
				case narf::BlockFace::ZPos: wbc.z++; break;
				case narf::BlockFace::ZNeg: wbc.z--; break;
				case narf::BlockFace::Invalid: assert(0); break;
				}
				narf::PlayerCommand cmd(narf::PlayerCommand::Type::SecondaryAction);
				cmd.wbc = wbc;
				playerCommandQueue.push(cmd);
			}
		}
	}

	if (input.actionTernary()) {
		narf::PlayerCommand cmd(narf::PlayerCommand::Type::TernaryAction);
		cmd.velocity = narf::Vector3f(0.0f, 0.0f, 0.0f);
		if (playerEID != narf::Entity::InvalidID) {
			narf::EntityRef player(world->entityManager, playerEID);
			if (player.ent) {
				cmd.velocity = player->velocity;
			}
		}
		cmd.position = cam.position;
		cmd.orientation = cam.orientation;
		playerCommandQueue.push(cmd);
	}

	if (input.toggleWireframe()) {
		renderer->wireframe = !renderer->wireframe;
	}

	if (input.toggleBackfaceCulling()) {
		renderer->backfaceCulling = !renderer->backfaceCulling;
	}

	if (input.toggleFog()) {
		renderer->fog = !renderer->fog;
	}

	if (input.toggleFullscreen()) {
		display->toggleFullscreen();
	}

	if (input.screenshot()) {
		screenshot = true;
	}

	processPlayerCommandQueue(playerCommandQueue);
}