Exemplo n.º 1
0
int ReplayManager::maxTouchingCount() {
    #if SAC_DESKTOP
    LOGF_IF(!replayMode, __FUNCTION__ << " used but replay is disabled");
    int result = sourceDfp.get(HASH("Misc", 0), "max_touching_count", &pointerCount);
    LOGF_IF(!result, "Unable to read max_touching_count from replay file");

    // update touching state
    char* tmp1 = (char*) alloca(50);
    char* tmp2 = (char*) alloca(50);
    sprintf(tmp2, "frame_%lu", frameCount);
    for (int i=0; i<pointerCount; i++) {
        glm::vec2 c;
        sprintf(tmp1, "Pointer_%d", i);
        if (sourceDfp.get(Murmur::RuntimeHash(tmp1), tmp2, &c.x, 2)) {
            touching[i].first = true;
            touching[i].second = c;
        } else {
            touching[i].first = false;
        }
    }

    frameCount++;
    return pointerCount;
    #else
    return 0;
    #endif
}
Exemplo n.º 2
0
unsigned int ReplayManager::getRandomSeed() const {
    LOGF_IF(!replayMode, __FUNCTION__ << " used but replay is disabled");
    unsigned int seed = 0;
    int result = sourceDfp.get(HASH("Misc", 0), "random_seed", &seed);
    LOGF_IF(!result, "Unable to read seed from replay file");
    return seed;
}
Exemplo n.º 3
0
void ReplayManager::enableReplayMode(const char* sourceFile, AssetAPI* assetAPI) {
    LOGF_IF(replayMode, "Multiple calls to " << __FUNCTION__);

    FileBuffer fb = assetAPI->loadFile(sourceFile);
    LOGF_IF (!fb.size, "Invalid replay source file: " << sourceFile);

    LOGV(1, "Init replay from '" << sourceFile << "'");
    sourceDfp.load(fb, sourceFile);
}
Exemplo n.º 4
0
int main(int argc, char** argv)
{
  double pi_d = 3.1415926535897932384626433832795;
  float pi_f = 3.1415926535897932384626433832795f;


  g2LogWorker logger(argv[0], path_to_log_file);
  g2::initializeLogging(&logger);
  std::cout << "*** This is an example of g2log " << std::endl;
  std::cout << "*** It WILL exit by a FATAL trigger in the end" << std::endl;
  std::cout << "*** Please see the generated log and compare to " << std::endl;
  std::cout << "***    the code at g2log/test_example/main.cpp" << std::endl;
  std::cout << "\n*** Log file: [" << logger.logFileName() << "]\n\n" << std::endl;

  LOGF(INFO, "Hi log %d", 123);
  LOG(INFO) << "Test SLOG INFO";
  LOG(DEBUG) << "Test SLOG DEBUG";
  LOG(INFO) << "one: " << 1;
  LOG(INFO) << "two: " << 2;
  LOG(INFO) << "one and two: " << 1 << " and " << 2;
  LOG(DEBUG) << "float 2.14: " << 1000/2.14f;
  LOG(DEBUG) << "pi double: " << pi_d;
  LOG(DEBUG) << "pi float: " << pi_f;
  LOG(DEBUG) << "pi float (width 10): " << std::setprecision(10) << pi_f;
  LOGF(INFO, "pi float printf:%f", pi_f);

  //
  // START: LOG Entris that were in the article
  //
  //LOG(UNKNOWN_LEVEL) << "This log attempt will cause a compiler error";
  LOG(INFO) << "Simple to use with streaming syntax, easy as abc or " << 123;
  LOGF(WARNING, "Printf-style syntax is also %s", "available");
  LOG_IF(INFO, (1 < 2)) << "If true this text will be logged";
  LOGF_IF(INFO, (1<2), "if %d<%d : then this text will be logged", 1,2);
  LOG_IF(FATAL, (2>3)) << "This message should NOT throw";
  LOGF(DEBUG, "This API is popular with some %s", "programmers");
  LOGF_IF(DEBUG, (1<2), "If true, then this %s will be logged", "message");
  {
    // OK --- on Ubunti this WILL get a compiler warning
    // On windows it'll probably crash  std::cout << "\n\n***** Be ready on Windows this example will 'abort' " << std::endl;
  std::cout << "\n\n***** Be ready this last example will 'abort' if on Windows" << std::endl;
  std::cout << "************************************************************\n\n" << std::endl;
  const std::string logging = "logging";
  LOGF(DEBUG, "ILLEGAL PRINTF_SYNTAX EXAMPLE. WILL GENERATE compiler warning.\n\nbadly formatted message:[Printf-type %s is the number 1 for many %s]", logging.c_str());
  }


  std::cout << "\n\n***** Be ready this last example will 'abort' " << std::endl;
  std::cout << "************************************************************\n\n" << std::endl;
  CHECK(1<2) << "SHOULD NOT SEE THIS MESSAGE";
  CHECK(1>2) << "Test to see if contract works: onetwothree: " << 123 << ". This should be at the end of the log, and will exit this example";
}
Exemplo n.º 5
0
void GameModeManager::generateLeaves(int* nb, int type) {
    for (unsigned int i=0;i<branchLeaves.size();i++)
        theEntityManager.DeleteEntity(branchLeaves[i].e);

    branchLeaves.clear();
    fillVec();

    LOGF_IF(posBranch.empty(), "posBranch isn't initialized before call to generateLeaves");

    for (int j=0;j<type;j++) {
        for (int i=0 ; i < (nb ? nb[j] : 6);i++) {
            // LOGI(j << ',' << i << " -> " << posBranch.size());
            int rnd = Random::Int(0, posBranch.size()-1);
            glm::vec2 pos = posBranch[rnd].v;
            pos.x -= PlacementHelper::GimpXToScreen(0) - -PlacementHelper::ScreenSize.x*0.5f;

            BranchLeaf bl;
            bl.e = createAndAddLeave(j, pos, posBranch[rnd].rot);
            bl.type = j;
            branchLeaves.push_back(bl);

            posBranch.erase(posBranch.begin()+rnd);
        }
    }
    //shuffle pour éviter que les mêmes couleurs soient à coté dans la liste :
    //ça sert en 100 tiles, pour que les feuilles supprimées soient d'abord ttes les
    //rouges, ensuites les jaunes etc..
    std::random_shuffle(branchLeaves.begin(), branchLeaves.end());
}
Exemplo n.º 6
0
bool ReplayManager::isTouching(int index, glm::vec2* windowCoords) {
    LOGF_IF(!replayMode, __FUNCTION__ << " used but replay is disabled");

    if (!touching)
        return false;

    *windowCoords = touching[index].second;
    return touching[index].first;
}
Exemplo n.º 7
0
bool EffectLibrary::doLoad(const char* assetName, Shader& out, const EffectRef& ref) {
    LOGF_IF(assetAPI == 0, "Unitialized assetAPI member");

    std::map<EffectRef, FileBuffer>::iterator it = dataSource.find(ref);
    if (it == dataSource.end()) {
        LOGV(1, "loadShader: '" << assetName << "' from file");
        out = buildShaderFromAsset(assetAPI, "default.vs", assetName);
    } else {
        const FileBuffer& fb = it->second;
        LOGV(1, "loadShader: '" << assetName << "' from InMemoryShader (" << fb.size << ')');
        out = buildShaderFromFileBuffer("default.vs", fb);
    }

    return true;
}
Exemplo n.º 8
0
void ScrollingSystem::DoUpdate(float dt) {
    FOR_EACH_ENTITY_COMPONENT(Scrolling, a, sc)
        EltIt iter = elements.find(a);
        if (iter == elements.end()) {
            if ( glm::abs(glm::length(sc->direction) - 1) <= 0.001) {
                initScrolling(a, sc);
                iter = elements.find(a);
            }
            continue;
        }
        if (!sc->show) {
            ScrollingElement& se = iter->second;
            for (int i=0; i<2; i++) {
                RENDERING(se.e[i])->show = false;
            }
            continue;
        }

        LOGF_IF(sc->speed < 0, "Scrolling component '" << sc << "' has a speed < 0");

        ScrollingElement& se = iter->second;
        for (int i=0; i<2; i++) {
            RENDERING(se.e[i])->show = true;

            AnchorComponent* tc = ANCHOR(se.e[i]);
            tc->position += sc->direction * (sc->speed * dt);

            bool isVisible = theRenderingSystem.isVisible(se.e[i]);
            if (!se.hasBeenVisible[i] && isVisible) {
                se.hasBeenVisible[i] = true;
            } else if (se.hasBeenVisible[i] && !isVisible) {
                se.imageIndex[i] = (se.imageIndex[i] + 2) % sc->images.size();
                RENDERING(se.e[i])->texture = sc->images[se.imageIndex[i]];
                const auto* ptc = TRANSFORM(a);
                tc->position =
                    ANCHOR(se.e[(i+1)%2])->position -
                    glm::vec2(sc->direction.x * ptc->size.x, sc->direction.y * ptc->size.y);
                se.hasBeenVisible[i] = false;
            }
        }
    END_FOR_EACH()
}
Exemplo n.º 9
0
void initStateEntities(AssetAPI* assetAPI, const char* stateName, std::map<hash_t, Entity>& entities) {
    LOGF_IF(!assetAPI, "Missing assetAPI");

    // Retrieve .entity in scene subfolder
    char* subfolder = (char*) alloca(sizeof("entities/") + strlen(stateName) + 100);
    strcpy(subfolder, "entities/");
    strcat(subfolder, stateName);
    auto files = assetAPI->listAssetContent(".entity", subfolder);

    std::list<Entity> entitiesBuilt;

    unsigned buildCount = entitiesBuilt.size();

    // build all entities (inefficient but only used ~10 times)
    while (!files.empty()) {
        bool earlyExit = false;

        for (auto f=files.begin(); f!=files.end(); ++f) {
            auto* fullname = buildFullName(stateName, (*f).c_str(), subfolder);

            const EntityTemplateRef tmpl = theEntityManager.entityTemplateLibrary.load(fullname);
            const EntityTemplate* t = theEntityManager.entityTemplateLibrary.get(tmpl, false);

            if (!t->autoCreate) {
                files.erase(f);
                earlyExit = true;
                break;
            }

            // Only build if all dependencies have been built
            bool dependenciesReady = true;
            std::for_each(t->dependencies.begin(), t->dependencies.end(), [&entitiesBuilt, &dependenciesReady] (hash_t h) -> void {
                Entity e = theEntityManager.getEntityByName(h);
                if (e == 0) {
                    if (std::find(entitiesBuilt.begin(), entitiesBuilt.end(), h) == entitiesBuilt.end()) {
                        LOGV(2, "Missing " << INV_HASH(h));
                        dependenciesReady = false;
                    }
                }
            });

            if (dependenciesReady) {
                hash_t h = Murmur::RuntimeHash(fullname);
                entities[h] =
                    theEntityManager.CreateEntityFromTemplate(fullname);
                entitiesBuilt.push_back(h);

                files.erase(f);
                break;
            }
        }

        if (!earlyExit) {
            unsigned newCount = entitiesBuilt.size();
            if (newCount <= buildCount) {
                #if SAC_ENABLE_LOG
                LOGE("Entities built:");
                for (auto e: entitiesBuilt) LOGE("\t* " << INV_HASH(e) << ".entity");
                LOGE("Entities not-built");
                for (auto e: files) {
                    auto* fullname = buildFullName(stateName, (e).c_str(), subfolder);
                    const EntityTemplateRef tmpl = theEntityManager.entityTemplateLibrary.load(fullname);
                    const EntityTemplate* t = theEntityManager.entityTemplateLibrary.get(tmpl, false);

                    std::stringstream d;
                    d << "dependencies=";
                    for (auto dep: t->dependencies) {
                        d << INV_HASH(dep) << "  ";
                    }
                    LOGE("\t* " << stateName << '/' << e << ".entity (" << d.str() << ')');
                }
                #endif
                LOGF("Entities defined for state " << stateName << " have circular dependencies (" << entitiesBuilt.size() << " built and " << files.size() << " not built)");
            }
            buildCount = newCount;
        }
    }
}