Example #1
0
void *loom_asset_lock(const char *name, unsigned int type, int block)
{
    const char *namePtr = stringtable_insert(name);

    loom_mutex_lock(gAssetLock);

    // Look it up.
    loom_asset_t *asset = loom_asset_getAssetByName(namePtr, 1);
    lmAssert(asset != NULL, "Didn't get asset even though we should have!");

    // If not loaded, and we aren't ready to block, return NULL.
    if ((block == 0) && (asset->state != loom_asset_t::Loaded))
    {
        lmLogDebug(gAssetLogGroup, "Not blocking and not loaded yet; lock of '%s' failed.", namePtr);
        loom_mutex_unlock(gAssetLock);
        return NULL;
    }

    // Otherwise, let's force it to load now.
    if (asset->state != loom_asset_t::Loaded)
    {
        lmLogDebug(gAssetLogGroup, "Blocking so forcing load of '%s'.", namePtr);

        loom_asset_preload(namePtr);

        lmAssert(loom_asset_isOnTrackToLoad(asset), "Preloaded but wasn't on track to load!");

        while (loom_asset_checkLoadedPercentage(namePtr) != 1.f && loom_asset_isOnTrackToLoad(asset))
        {
            lmLogDebug(gAssetLogGroup, "Pumping load of '%s'...", namePtr);
            loom_asset_pump();
        }

        if (asset->state != loom_asset_t::Loaded)
        {
            lmLogError(gAssetLogGroup, "Unable to load asset '%s'!", name);
            loom_mutex_unlock(gAssetLock);
            return NULL;
        }
    }

    // Check type.
    if (asset->type != type)
    {
        lmLogError(gAssetLogGroup, "Tried to lock asset '%s' with wrong type, assetType=%x, requestedType=%x", name, asset->type, type);
        loom_mutex_unlock(gAssetLock);
        return NULL;
    }

    // Inc count.
    asset->blob->incRef();

    loom_mutex_unlock(gAssetLock);

    lmLogDebug(gAssetLogGroup, "Locked asset '%s'...", namePtr);

    // Return ptr.
    return asset->blob->bits;
}
Example #2
0
void loom_asset_waitForConnection(int msToWait)
{
    // be extra agressive before starting up
    gAssetServerConnectTryInterval = 10;

    int startTime = platform_getMilliseconds();
    while (!gAssetConnectionOpen && (platform_getMilliseconds() - startTime) < msToWait)
    {
        loom_asset_pump();
        loom_thread_sleep(10);
    }

    // Go back to pinging every 3 seconds
    gAssetServerConnectTryInterval = 3000;
}
Example #3
0
static int pumpTillLoaded(int timeoutMs)
{
    int startTime = platform_getMilliseconds();

    while (loom_asset_queryPendingLoads())
    {
        loom_asset_pump();

        if (platform_getMilliseconds() - startTime > timeoutMs)
        {
            return 0;
        }
    }

    return 1;
}
void loom_tick()
{
    // Mark the main thread for NativeDelegates. On some platforms this
    // may change so we remark every frame.
    NativeDelegate::markMainThread();
    NativeDelegate::executeDeferredCalls(LoomApplication::getRootVM()->VM());

    performance_tick();

    profilerBlock_t p = { "loom_tick", platform_getMilliseconds(), 8 };

    if (LoomApplication::getReloadQueued())
    {
        LoomApplication::reloadMainAssembly();
    }
    else
    {
        LSLuaState *vm = LoomApplication::getRootVM();
        if (vm)
        {
            // https://theengineco.atlassian.net/browse/LOOM-468
            // decouple debugger enabled from connection time
            // as the debugger matures this may change a bit
            if (LoomApplicationConfig::waitForDebugger() > 0)
            {
                vm->invokeStaticMethod("system.debugger.DebuggerClient", "update");
            }

            LoomApplication::ticks.invoke();
        }
    }

    loom_asset_pump();

    platform_HTTPUpdate();

    GFX::Texture::tick();

    lualoom_gc_update(LoomApplication::getRootVM()->VM());

    if(Loom2D::Stage::smMainStage)
        Loom2D::Stage::smMainStage->invokeRenderStage();

    finishProfilerBlock(&p);
}
Example #5
0
void loom_tick()
{
    if (atomic_load32(&gLoomTicking) < 1)
    {

        // Signal that the app has really stopped execution
        if (atomic_load32(&gLoomPaused) == 0)
        {
            atomic_store32(&gLoomPaused, 1);
        }

        // Sleep for longer while paused.
        // Since graphics aren't running in a paused state, there is no yielding
        // we would otherwise run in a busy loop without sleeping.
        loom_thread_sleep(30);

        return;
    }

    atomic_store32(&gLoomPaused, 0);

    Telemetry::beginTick();
    
    LOOM_PROFILE_START(loom_tick);

    LSLuaState *vm = NULL;

    vm = LoomApplication::getReloadQueued() ? NULL : LoomApplication::getRootVM();

    // Mark the main thread for NativeDelegates. On some platforms this
    // may change so we remark every frame.
    NativeDelegate::markMainThread();
    if (vm) NativeDelegate::executeDeferredCalls(vm->VM());

    performance_tick();

    profilerBlock_t p = { "loom_tick", platform_getMilliseconds(), 17 };
    
    if (LoomApplication::getReloadQueued())
    {
        LoomApplication::reloadMainAssembly();
    }
    else
    {
        if (vm)
        {
            // https://theengineco.atlassian.net/browse/LOOM-468
            // decouple debugger enabled from connection time
            // as the debugger matures this may change a bit
            if (LoomApplicationConfig::waitForDebugger() > 0)
            {
                vm->invokeStaticMethod("system.debugger.DebuggerClient", "update");
            }

            LoomApplication::ticks.invoke();
        }
    }
    
    loom_asset_pump();
    
    platform_HTTPUpdate();
    
    GFX::Texture::tick();
    
    if (Loom2D::Stage::smMainStage) Loom2D::Stage::smMainStage->invokeRenderStage();
    
    finishProfilerBlock(&p);
    
    LOOM_PROFILE_END(loom_tick);
    
    LOOM_PROFILE_ZERO_CHECK()
    
    Telemetry::endTick();

}