Пример #1
0
    void MapLevel::dump() const
    {
        LOG_CALL("MapLevel::dump");
        LOG_INFO("========= Box2D dump ========");
        for (b2Body* body = mBoxWorld.GetBodyList(); body != nullptr; body = body->GetNext()) {
            b2Vec2 b2Pos = body->GetPosition();
            b2Vec2 b2Vel = body->GetLinearVelocity();
            b2BodyType type = body->GetType();

            bool skip = false;
            b2utils::Category::ID c = b2utils::Category::WORLD;
            for (b2Fixture* f = body->GetFixtureList(); f; f = f->GetNext()) {
                if (f->GetFilterData().categoryBits & b2utils::Category::WORLD) {
                    skip = true;
                    break;
                }
                c = static_cast<b2utils::Category::ID>(f->GetFilterData().categoryBits);
            }
            if (skip) {
                continue;
            }


            sf::Vector2f pos = sf::Vector2f(b2utils::metersToPixels(b2Pos.x), b2utils::metersToPixels(b2Pos.y));
            sf::Vector2f vel = sf::Vector2f(b2utils::metersToPixels(b2Vel.x), b2utils::metersToPixels(b2Vel.y));
            LOG_DEBUG("Box2D: %s: pos: (%d, %d), velocity: (%d, %d)", catToString(c), pos.x, pos.y, vel.x, vel.y);
        }
    }
Пример #2
0
 fmi2Status fmi2SerializeFMUstate(fmi2Component c, fmi2FMUstate FMUstate,
                                  fmi2Byte serializedState[], size_t size)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2SerializeFMUstate not implemented");
   return fmi2Error;
 }
Пример #3
0
    void MapLevel::loadLevel(std::size_t level, sf::Image& levelData)
    {
        LOG_CALL("MapLevel::loadLevel");
        int imageX0 = level * LevelWidth;
        int imageY0 = 0;

        sf::Vector2u dataSize = levelData.getSize();
        LOG_DEBUG("LevelData size: %d, %d", dataSize.x, dataSize.y);

        mVertices.setPrimitiveType(sf::Quads);
        mVertices.resize(LevelWidth * LevelHeight * 4);


        for (std::size_t j = 0; j < LevelHeight; ++j) {
            for (std::size_t i = 0; i < LevelWidth; ++i) {
                int imageX = imageX0 + i;
                int imageY = imageY0 + j;

                Tile tile = getTileFromColor(levelData.getPixel(imageX, imageY));
                mWorld[i][j] = tile;

                if (tile == Tile::Wall) {
                    sf::Vector2i texCoords = getTexCoords(tile);
                    sf::Vertex* quad = &mVertices[(i + j * LevelWidth) * 4];
                    int tu = texCoords.x;
                    int tv = texCoords.y;

                    int left = WorldOffsetX + i * TileWidth;
                    int top = WorldOffsetY + j * TileHeight;
                    int right = WorldOffsetX + (i + 1) * TileWidth;
                    int bottom = WorldOffsetY + (j + 1) * TileHeight;

                    // Define 4 corners of vertice
                    quad[0].position = sf::Vector2f(left, top);
                    quad[1].position = sf::Vector2f(right, top);
                    quad[2].position = sf::Vector2f(right, bottom);
                    quad[3].position = sf::Vector2f(left, bottom);

                    quad[0].texCoords = sf::Vector2f(tu * TileWidth, tv * TileHeight);
                    quad[1].texCoords = sf::Vector2f((tu + 1) * TileWidth, tv * TileHeight);
                    quad[2].texCoords = sf::Vector2f((tu + 1) * TileWidth, (tv + 1) * TileHeight);
                    quad[3].texCoords = sf::Vector2f(tu * TileWidth, (tv + 1) * TileHeight);

                    // Register wall in Box2D
                    b2utils::createGround(mBoxWorld, (left + right) / 2, (top + bottom) / 2, TileWidth, TileHeight);

                } else if (tile == Tile::PlayerSpawn) {
                    mPlayerSpawnPos.x = i;
                    mPlayerSpawnPos.y = j;

                } else if (tile == Tile::DestinationSpawn) {
                    mDestinationList.push_back(Position(i, j));

                } else if (tile == Tile::SourceSpawn) {
                    mSourceList.push_back(Position(i, j));
                }
            }
        }
    }
Пример #4
0
 fmi2Status fmi2Reset(fmi2Component c)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2Reset");
   try {
     return w->reset();
   }
   CATCH_EXCEPTION(w);
 }
Пример #5
0
 fmi2Status fmi2NewDiscreteStates(fmi2Component c, fmi2EventInfo *eventInfo)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2NewDiscreteStates");
   try {
     return w->newDiscreteStates(eventInfo);
   }
   CATCH_EXCEPTION(w);
 }
Пример #6
0
 fmi2Status fmi2SetTime(fmi2Component c, fmi2Real time)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2SetTime(%g)", time);
   try {
     return w->setTime(time);
   }
   CATCH_EXCEPTION(w);
 }
Пример #7
0
 fmi2Status fmi2ExitInitializationMode(fmi2Component c)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2ExitInitializationMode");
   try {
     return w->exitInitializationMode();
   }
   CATCH_EXCEPTION(w);
 }
Пример #8
0
 fmi2Status fmi2Terminate(fmi2Component c)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2Terminate");
   try {
     return w->terminate();
   }
   CATCH_EXCEPTION(w);
 }
Пример #9
0
 fmi2Status fmi2GetEventIndicators(fmi2Component c,
                                   fmi2Real eventIndicators[], size_t ni)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2GetEventIndicators(ni = %d)", ni);
   try {
     return w->getEventIndicators(eventIndicators, ni);
   }
   CATCH_EXCEPTION(w);
 }
Пример #10
0
 fmi2Status fmi2SetContinuousStates(fmi2Component c,
                                    const fmi2Real x[], size_t nx)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2SetContinuousStates(nx = %d)", nx);
   try {
     return w->setContinuousStates(x, nx);
   }
   CATCH_EXCEPTION(w);
 }
Пример #11
0
 fmi2Status fmi2GetDerivatives(fmi2Component c,
                               fmi2Real derivatives[], size_t nx)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2GetDerivatives(nx = %d)", nx);
   try {
     return w->getDerivatives(derivatives, nx);
   }
   CATCH_EXCEPTION(w);
 }
Пример #12
0
 fmi2Status fmi2GetNominalsOfContinuousStates(fmi2Component c,
                                              fmi2Real x_nominal[], size_t nx)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2GetNominalsOfContinuousStates(nx = %d)", nx);
   try {
     return w->getNominalsOfContinuousStates(x_nominal, nx);
   }
   CATCH_EXCEPTION(w);
 }
Пример #13
0
 fmi2Status fmi2SetString(fmi2Component c,
                          const fmi2ValueReference vr[], size_t nvr,
                          const fmi2String value[])
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2SetString(nvr = %d)", nvr);
   try {
     return w->setString(vr, nvr, value);
   }
   CATCH_EXCEPTION(w);
 }
Пример #14
0
 fmi2Status fmi2GetDirectionalDerivative(fmi2Component c,
                                         const fmi2ValueReference vUnknown_ref[],
                                         size_t nUnknown,
                                         const fmi2ValueReference vKnown_ref[],
                                         size_t nKnown,
                                         const fmi2Real dvKnown[],
                                         fmi2Real dvUnknown[])
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2GetDirectionalDerivative not implemented");
   return fmi2Error;
 }
Пример #15
0
    void Context::loadSound(Sounds::ID id, const std::string& filename)
    {
        LOG_CALL("Context::loadSound");

        SoundPtr sound(new sf::SoundBuffer());
        if (!sound->loadFromFile(filename)) {
            throw std::runtime_error("loadSound: Failed to load file: " + filename);
        }

        auto inserted = mSoundMap.insert(std::make_pair(id, std::move(sound)));
        assert(inserted.second);
    }
Пример #16
0
    void Context::loadFont(Fonts::ID id, const std::string& filename)
    {
        LOG_CALL("Context::loadFont");

        FontPtr font(new sf::Font());
        if (!font->loadFromFile(filename)) {
            throw std::runtime_error("loadFont: Failed to load file: " + filename);
        }

        auto inserted = mFontMap.insert(std::make_pair(id, std::move(font)));
        assert(inserted.second);
    }
Пример #17
0
 fmi2Status fmi2CompletedIntegratorStep(fmi2Component c,
                                        fmi2Boolean noSetFMUStatePriorToCurrentPoint,
                                        fmi2Boolean* enterEventMode,
                                        fmi2Boolean* terminateSimulation)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2CompletedIntegratorStep");
   try {
     return w->completedIntegratorStep(noSetFMUStatePriorToCurrentPoint,
                                       enterEventMode, terminateSimulation);
   }
   CATCH_EXCEPTION(w);
 }
Пример #18
0
    void Context::loadTexture(Textures::ID id, const std::string& filename)
    {
        LOG_CALL("Context::loadTexture");

        TexturePtr texture(new sf::Texture());
        if (!texture->loadFromFile(filename)) {
            LOG_ERROR("Failed to load file %s", filename);
            throw std::runtime_error("loadTexture: Failed to load file: " + filename);
        }

        auto inserted = mTextureMap.insert(std::make_pair(id, std::move(texture)));
        assert(inserted.second);
    }
Пример #19
0
 fmi2Status fmi2SetDebugLogging(fmi2Component c,
                                fmi2Boolean loggingOn,
                                size_t nCategories,
                                const fmi2String categories[])
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2SetDebugLogging(%s, nCategories = %d)",
            loggingOn? "true": "false", nCategories);
   try {
     return w->setDebugLogging(loggingOn, nCategories, categories);
   }
   CATCH_EXCEPTION(w);
 }
/**
 * games_card_textures_cache_get_card_texture_by_id:
 * @cache:
 * @card_id:
 *
 * Returns: a cached #CoglHandle for @card_id.
 */
CoglHandle
games_card_textures_cache_get_card_texture_by_id (GamesCardTexturesCache *cache,
                                                  guint card_id)
{
  GamesCardTexturesCachePrivate *priv = cache->priv;
  CoglHandle handle;

  g_return_val_if_fail (card_id < GAMES_CARDS_TOTAL , NULL);

  LOG_CALL (cache);

  handle = priv->cards[card_id];
  if (IS_FAILED_HANDLE (handle)) {
    LOG_CACHE_HIT (cache);
    return COGL_INVALID_HANDLE;
  }

  if (handle == COGL_INVALID_HANDLE) {
    GdkPixbuf *pixbuf;

    LOG_CACHE_MISS (cache);

    pixbuf = games_card_theme_get_card_pixbuf (priv->theme, card_id);
    if (!pixbuf) {
      priv->cards[card_id] = FAILED_HANDLE;
      return COGL_INVALID_HANDLE;
    }

    handle = cogl_texture_new_from_data (gdk_pixbuf_get_width (pixbuf),
                                         gdk_pixbuf_get_height (pixbuf),
                                         64, FALSE,
                                         gdk_pixbuf_get_has_alpha (pixbuf)
                                         ? COGL_PIXEL_FORMAT_RGBA_8888
                                         : COGL_PIXEL_FORMAT_RGB_888,
                                         COGL_PIXEL_FORMAT_ANY,
                                         gdk_pixbuf_get_rowstride (pixbuf),
                                         gdk_pixbuf_get_pixels (pixbuf));
    g_object_unref (pixbuf);

    if (handle == COGL_INVALID_HANDLE) {
      priv->cards[card_id] = FAILED_HANDLE;
      return COGL_INVALID_HANDLE;
    }

    priv->cards[card_id] = handle;
  } else {
    LOG_CACHE_HIT (cache);
  }

  return handle;
}
Пример #21
0
/**
 * ar_card_surface_cache_get_card_surface_by_id:
 * @cache:
 * @card_id:
 *
 * Returns: a cached #cairo_surface_t for @card_id.
 */
cairo_surface_t *
ar_card_surface_cache_get_card_surface_by_id (ArCardSurfaceCache *cache,
                                              guint card_id)
{
  ArCardSurfaceCachePrivate *priv = cache->priv;
  cairo_surface_t *surface;

  g_return_val_if_fail (card_id < AR_CARDS_TOTAL , NULL);

  LOG_CALL (cache);

  surface = priv->cards[card_id];
  if (IS_FAILED_SURFACE (surface)) {
    LOG_CACHE_HIT (cache);
    return NULL;
  }

  if (surface == NULL) {
    CardSize card_size;
    cairo_t *cr;

    LOG_CACHE_MISS (cache);

    ar_card_theme_get_size (priv->theme, &card_size);

    if (priv->drawable != NULL) {
      surface = gdk_window_create_similar_surface (priv->drawable, CAIRO_CONTENT_COLOR_ALPHA,
                                                   card_size.width, card_size.height);
    } else {
      surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                            card_size.width, card_size.height);
    }

    cr = cairo_create (surface);
    ar_card_theme_paint_card (priv->theme, cr, card_id);
    cairo_destroy (cr);

    if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
      cairo_surface_destroy (surface);
      priv->cards[card_id] = FAILED_SURFACE;
      return NULL;
    }

    priv->cards[card_id] = surface; /* adopts */
  } else {
    LOG_CACHE_HIT (cache);
  }

  return surface;
}
Пример #22
0
 fmi2Status fmi2SetupExperiment(fmi2Component c,
                                fmi2Boolean toleranceDefined,
                                fmi2Real tolerance,
                                fmi2Real startTime,
                                fmi2Boolean stopTimeDefined,
                                fmi2Real stopTime)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2SetupExperiment(startTime = %g)", startTime);
   try {
     return w->setupExperiment(toleranceDefined, tolerance, startTime,
                               stopTimeDefined, stopTime);
   }
   CATCH_EXCEPTION(w);
 }
Пример #23
0
    void MapLevel::initSprites()
    {
        LOG_CALL("MapLevel::initSprites");
        for (auto& pos : mDestinationList) {
            sf::Sprite sprite(mTexture);
            sf::Vector2f worldPos(WorldOffsetX + pos.x * TileWidth, WorldOffsetY + pos.y * TileHeight);
            Entity::Ptr entity(new Flag(sprite, mBoxWorld, worldPos));
            Flag* flag = dynamic_cast<Flag*>(entity.get());
            mEntities.push_back(std::move(entity));
        }

        for (auto& pos : mSourceList) {
            sf::Sprite sprite(mTexture);
            Entity::Ptr entity(new PackageEntity(sprite, mBoxWorld));
            PackageEntity* package = dynamic_cast<PackageEntity*>(entity.get());
            package->setPosition(sf::Vector2f(WorldOffsetX + pos.x * TileWidth, WorldOffsetY + pos.y * TileHeight));
            mEntities.push_back(std::move(entity));
        }
    }
Пример #24
0
    void Spawner::update(sf::Time dt)
    {
        LOG_CALL("Spawner::update");
        mUpdateTime += dt;

        if (!mSpawnQueue.empty()) {
            sf::Time& nextSpawnTime = mSpawnQueue.front();
            if (mUpdateTime >= nextSpawnTime) {
                LOG_DEBUG("Calling spawner callback");
                mOnSpawnCallback();
                mSpawnQueue.pop_front();

                if (mSpawnQueue.empty()) {
                    LOG_DEBUG("Calling finish callback");
                    mOnFinishCallback();
                }
            }
        }
    }
Пример #25
0
bool SessionData::VerifyCheckedObjects (vector<hIO>* etalon)
{
	LOG_CALL("Verifying checked objects ...\n");

	size_t min_count = std::min (etalon->size(), m_testManager->gotten_objects.size());
	bool bResult = true;
	for (int i = 0; i < min_count; ++i)
	{
		char buf[32];
		LOG_CALL3("Verifying object ",itoa(i+1, buf, 10),"\n");
		if (!aux::isIoEquals (etalon->at(i), m_testManager->gotten_objects.at(i))) bResult = false;
	}

	if (etalon->size() != m_testManager->gotten_objects.size())
	{
		char buf[32], buf2[32];
		LOG_CALL5("\tIncorrect number of objects...",itoa(etalon->size(), buf, 10),"-",itoa(m_testManager->gotten_objects.size(), buf, 10),"\n");
		return false;
	}

	return bResult;
}
Пример #26
0
    void MapLevel::onSpawnRequest()
    {
        LOG_CALL("MapLevel::onSpawnRequest");
        bool playSound = false;

        for (auto const& entity : mEntities) {
            if (entity->isSource()) {
                PackageEntity& package = dynamic_cast<PackageEntity&>(*entity);
                if (!package.isSpawned()) {
                    LOG_DEBUG("Spawning new package!");
                    package.activate(TempColor);
                    playSound = true;

                    break;
                } else {
                    LOG_DEBUG("Package is already spawned.");
                }
            }
        }

        for (auto const& entity : mEntities) {
            if (entity->isDestination()) {
                Flag& flag = dynamic_cast<Flag&>(*entity);
                if (!flag.isBound()) {
                    LOG_DEBUG("Activating new flag!");
                    flag.bind(TempColor);
                    playSound = true;

                    break;
                }
            }
        }

        mContext.playSound(Sounds::Spawn);


        TempColor = (TempColor + 1) % NumColors;
    }
Пример #27
0
 fmi2Component fmi2Instantiate(fmi2String instanceName,
                               fmi2Type fmuType,
                               fmi2String GUID,
                               fmi2String fmuResourceLocation,
                               const fmi2CallbackFunctions *functions,
                               fmi2Boolean visible,
                               fmi2Boolean loggingOn)
 {
   FMU2Wrapper *w;
   try {
     w = new FMU2Wrapper(instanceName, GUID, functions, loggingOn);
   }
   catch (std::exception &e) {
     if (functions && functions->logger)
       functions->logger(functions->componentEnvironment,
                         instanceName, fmi2Error,
                         FMU2Wrapper::logCategoryName(logStatusError),
                         e.what());
     return NULL;
   }
   LOG_CALL(w, "fmi2Instantiate");
   return reinterpret_cast<fmi2Component>(w);
 }
Пример #28
0
    MapLevel::MapLevel(Context& context, std::size_t level, sf::Image& levelData, b2World& world)
        : mContext(context)
        , mWorld(LevelWidth, std::vector<Tile>(LevelHeight))
        , mBoxWorld(world)
        , mTexture(context.getTexture(Textures::GameAtlas))
        , mDestinationList()
        , mSourceList()
        , mEntities()
    {
        LOG_CALL("MapLevel::MapLevel");

        // Reset Box2D world
        LOG_DEBUG("Clearing Box2D world from entities: %d to remove.", mBoxWorld.GetBodyCount());
        b2Body* body = world.GetBodyList();
        while (nullptr != body) {

            b2Body* nextBody = body->GetNext();
            world.DestroyBody(body);
            body = nextBody;
        }

        // Create Box2D world boundaries
        b2utils::createGround(mBoxWorld, 20.f, 300.f, 40.f, 600.f);
        b2utils::createGround(mBoxWorld, 780.f, 300.f, 40.f, 600.f);

        b2utils::createGround(mBoxWorld, 400.f, 18.f, 800.f, 36.f);
        b2utils::createGround(mBoxWorld, 400.f, 582.f, 800.f, 36.f);

        loadLevel(level, levelData);
        initSprites();

        //mDebugPlayerSpawn.setFillColor(sf::Color::Yellow);
        //LOG_DEBUG("Player spawn position: (%d, %d)", mPlayerSpawnPos.x, mPlayerSpawnPos.y);
        //mDebugPlayerSpawn.setPosition(WorldOffsetX + TileWidth * mPlayerSpawnPos.x, WorldOffsetY + TileHeight * mPlayerSpawnPos.y);
        //mDebugPlayerSpawn.setSize(sf::Vector2f(24.f, 24.f));
    }
Пример #29
0
 fmi2Status fmi2EnterContinuousTimeMode(fmi2Component c)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2EnterContinuousTimeMode");
   return fmi2OK;
 }
Пример #30
0
 void fmi2FreeInstance(fmi2Component c)
 {
   FMU2Wrapper *w = reinterpret_cast<FMU2Wrapper*>(c);
   LOG_CALL(w, "fmi2FreeInstance");
   delete w;
 }