Exemplo n.º 1
0
Game::Game(Item* parent)
    : DisplayItemFrame(parent),
      m_viewWorld(this),
      m_lightSystem(this, view()->world()),
      m_particleSystem(m_lightSystem.lightTexture()->sourceItem()) {
  view()->initialize();
  lightSystem()->initialize();

  particleSystem()->setLightSystem(lightSystem());

  load(":/json/map00.json");
}
Exemplo n.º 2
0
void StaticLight::initialize(QWorld *w) {
  auto fixture = std::make_unique<Box2DBox>();
  fixture->setPosition(QPointF(-radius(), -radius()));
  fixture->setSize(QSizeF(2 * radius(), 2 * radius()));
  fixture->setSensor(true);
  fixture->setVisible(false);
  fixture->setShadowCaster(false);
  addFixture(std::move(fixture));

  assert(lightSystem());
  lightSystem()->addLight(this);

  QBody::initialize(w);
}
Exemplo n.º 3
0
void Game::sizeChanged() {
  DisplayItemFrame::sizeChanged();

#ifdef Q_OS_ANDROID
  const QSize maxres(800, 600);
#else
  const QSize maxres(1920, 1080);
#endif

  QSize resolution(std::min(int(size().width()), maxres.width()),
                   std::min(int(size().height()), maxres.height()));

  lightSystem()->setResolution(resolution);
  lightSystem()->setSize(size());
}
Exemplo n.º 4
0
void World::step() {
  QWorld::step();

  particleSystem()->step();
  lightSystem()->step();
  mainAction()->step();

  emit m_worldObject.fpsChanged();
  emit m_worldObject.playerScoreChanged();
}
Exemplo n.º 5
0
bool Game::write(QJsonObject& obj) const {
  QJsonObject viewWorld;
  view()->write(viewWorld);
  obj["viewWorld"] = viewWorld;

  QJsonObject lights;
  lightSystem()->write(lights);
  obj["lightSystem"] = lights;

  return true;
}
Exemplo n.º 6
0
std::unique_ptr<SceneGraph::Node> ParticleSystem::synchronize(
    std::unique_ptr<SceneGraph::Node> root) {
  Node* node = static_cast<Node*>(root.get());
  if (!root) {
    root = std::make_unique<Node>();
    node = static_cast<Node*>(root.get());

    QColor color;
    color.setRgbF(1.0, 0.5, 0.5, 1.0);
    node->material()->setColor(color);
    node->material()->setLightPosition(QVector3D(0.5, 0.5, 0.1));
  }

  assert(lightSystem());
  assert(lightSystem()->normalMap());

  node->update(m_particle);
  node->material()->setTime(time());
  node->material()->setNormalMap(lightSystem()->normalMap()->shaderNode());

  return root;
}
Exemplo n.º 7
0
std::unique_ptr<SceneGraph::Node> EnlightedItems::synchronize(
    std::unique_ptr<SceneGraph::Node> root) {
  if (!root) root = std::make_unique<Node>();

  Node* node = static_cast<Node*>(root.get());
  while (node->firstChild()) node->removeChild(node->firstChild());

  if (m_state & Reset) {
    m_state &= ~Reset;
    node->clear();
  }

  while (!m_destroyedFixture.empty()) {
    node->destroyedFixture(m_destroyedFixture.back());
    m_destroyedFixture.pop_back();
  }

  uint it = 0;
  QRectF visibleArea = world()->visibleRect();
  for (StaticLight* light : lightSystem()->visibleLights()) {
    if (!light->dynamicLight()) continue;

    QRectF lightRect = light->matrix().mapRect(light->boundingRect());
    QRectF rect = visibleArea.intersected(lightRect);
    for (QFixture* f : world()->fixtures(rect)) {
      if (f->shadowCaster()) {
        EnlightedNode* enlightedNode = node->getNode(f, light, it++);
        node->appendChild(enlightedNode);
      }
    }
  }

  update();

  return root;
}
Exemplo n.º 8
0
void World::onFixtureDestroyed(QFixture *f) {
  lightSystem()->onFixtureDestroyed(f);
}
Exemplo n.º 9
0
void World::onBodyAdded(QBody *body) {
  QWorld::onBodyAdded(body);

  assert(lightSystem());
  lightSystem()->addBody(body);
}
Exemplo n.º 10
0
QWorld* EnlightedItems::world() const { return lightSystem()->world(); }
Exemplo n.º 11
0
void StaticLight::visibleChanged() {
  if (lightSystem()) {
    lightSystem()->lightVisibilityChanged(this);
  }
}
Exemplo n.º 12
0
void StaticLight::destroyBody() {
  if (lightSystem()) lightSystem()->removeLight(this);

  Light::destroyBody();
}
Exemplo n.º 13
0
void Game::clear() {
  lightSystem()->clear();
  view()->world()->clear();
}
Exemplo n.º 14
0
bool Game::read(const QJsonObject& obj) {
  view()->read(obj["viewWorld"].toObject());
  lightSystem()->read(obj["lightSystem"].toObject());

  return true;
}