Example #1
0
static bool writeConsoleState(Path const &filePath)
{
    if(filePath.isEmpty()) return false;

    // Ensure the destination directory exists.
    String fileDir = filePath.toString().fileNamePath();
    if(!fileDir.isEmpty())
    {
        F_MakePath(fileDir.toUtf8().constData());
    }

    if(FILE *file = fopen(filePath.toUtf8().constData(), "wt"))
    {
        LOG_SCR_VERBOSE("Writing state to \"%s\"...")
                << NativePath(filePath).pretty();

        writeHeaderComment(file);
        fprintf(file, "#\n# CONSOLE VARIABLES\n#\n\n");
        writeVariablesToFile(file);

        fprintf(file, "\n#\n# ALIASES\n#\n\n");
        writeAliasesToFile(file);
        fclose(file);
        return true;
    }

    LOG_SCR_WARNING("Failed opening \"%s\" for writing")
            << NativePath(filePath).pretty();

    return false;
}
Example #2
0
static bool writeBindingsState(Path const &filePath)
{
    if(filePath.isEmpty()) return false;

    // Ensure the destination directory exists.
    String fileDir = filePath.toString().fileNamePath();
    if(!fileDir.isEmpty())
    {
        F_MakePath(fileDir.toUtf8().constData());
    }

    if(FILE *file = fopen(filePath.toUtf8().constData(), "wt"))
    {
        LOG_SCR_VERBOSE("Writing bindings to \"%s\"...")
                << NativePath(filePath).pretty();

        writeHeaderComment(file);
        B_WriteToFile(file);
        fclose(file);
        return true;
    }

    LOG_SCR_WARNING("Failed opening \"%s\" for writing")
            << NativePath(filePath).pretty();

    return false;
}
Example #3
0
void DS::Stream::writeSafeString(const String& value, DS::StringType format)
{
    if (format == e_StringUTF16) {
        StringBuffer<chr16_t> buffer = value.toUtf16();
        uint16_t length = value.length() & 0x0FFF;
        chr16_t* data = new chr16_t[length];
        memcpy(data, buffer.data(), length * sizeof(chr16_t));
        for (uint16_t i=0; i<length; ++i)
            data[i] = ~data[i];
        write<uint16_t>(length | 0xF000);
        writeBytes(data, length * sizeof(chr16_t));
        write<chr16_t>(0);
        delete[] data;
    } else {
        StringBuffer<chr8_t> buffer = (format == e_StringUTF8) ? value.toUtf8()
                                                               : value.toRaw();
        uint16_t length = value.length() & 0x0FFF;
        chr8_t* data = new chr8_t[length];
        memcpy(data, buffer.data(), length * sizeof(chr8_t));
        for (uint16_t i=0; i<length; ++i)
            data[i] = ~data[i];
        write<uint16_t>(length | 0xF000);
        writeBytes(data, length * sizeof(chr8_t));
        delete[] data;
    }
}
Example #4
0
        ConvertSavegameTask(String const &sourcePath, String const &gameId)
        {
            // Ensure the game is defined (sanity check).
            if (DoomsdayApp::games().contains(gameId))
            {
                // Ensure the output folder exists if it doesn't already.
                String const outputPath = String("/home/savegames") / gameId;
                FileSystem::get().makeFolder(outputPath);

                Str_Set(Str_InitStd(&parm.sourcePath),     sourcePath.toUtf8().constData());
                Str_Set(Str_InitStd(&parm.outputPath),     outputPath.toUtf8().constData());
                Str_Set(Str_InitStd(&parm.fallbackGameId), gameId.toUtf8().constData());
            }
            else
            {
                LOG_ERROR("Game \"%s\" does not exist") << gameId;
            }
        }
Example #5
0
void DxBuilder::buildPixelShader(const ASTEffect& effect, ASTTechnique& technique)
{
   const ASTFunction* pfunction = effect.findFunction(technique.mPixel.mEntry);

   String code = UTEXT("// generated pixel shader\n\n");

   String num;
   NumberConverter& conv = NumberConverter::getInstance();
   for ( std::size_t index = 0; index < effect.mTextures.size(); ++index )
   {
      ASTTexture* ptexture = effect.mTextures[index];
      code += UTEXT("Texture2D ") + ptexture->mName + UTEXT(" : register(t");

      int reg = ptexture->mRegister;
      if ( reg == -1 )
      {
         reg = (int) index;
      }
      
      code += conv.format(num, reg) + UTEXT(");\n");
      num = UTEXT("");
   }

   for ( std::size_t index = 0; index < effect.mSamplers.size(); ++index )
   {
      ASTSampler* psampler = effect.mSamplers[index];
      code += UTEXT("SamplerState ") + psampler->mName + UTEXT(" : register(s");
      
      int reg = psampler->mRegister;
      if ( reg == -1 )
      {
         reg = index;
      }
      
      code += conv.format(num, (int)reg) + UTEXT(");\n");
      num = UTEXT("");
   }

   code += buildStructs(effect, *pfunction);
   code += buildFunction(*pfunction);

   std::string data = code.toUtf8();
   std::string entry = technique.mPixel.mEntry.toUtf8();
   std::string target = technique.mPixel.mTarget.toUtf8();
   uint32_t flags = D3DCOMPILE_ENABLE_STRICTNESS;

   ID3DBlob *presult, *perror;
   HRESULT hr = D3DCompile(data.c_str(), data.length(), NULL, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, entry.c_str(), target.c_str(), flags, 0, &presult, &perror);
   if ( FAILED(hr) )
   {
      std::string d3derror = "Shader compile error: " + std::string((const char*)perror->GetBufferPointer());
      throw std::exception(d3derror.c_str());
   }
      
   technique.mPixel.mCompiledCode.writeBlob(presult->GetBufferPointer(), presult->GetBufferSize());
}
Example #6
0
void DS::Stream::writeString(const String& value, DS::StringType format)
{
    if (format == e_StringUTF16) {
        StringBuffer<chr16_t> buffer = value.toUtf16();
        writeBytes(buffer.data(), buffer.length());
    } else {
        StringBuffer<chr8_t> buffer = (format == e_StringUTF8) ? value.toUtf8()
                                                               : value.toRaw();
        writeBytes(buffer.data(), buffer.length());
    }
}
Example #7
0
AutoStr *P_NameForMapEntityDef(MapEntityDef const *def)
{
    String name;  // Not found.
    if (def)
    {
        ::entityDefs->forAll([&def, &name] (StringPool::Id id)
        {
            if (::entityDefs->userPointer(id) == def)
            {
                name = ::entityDefs->string(id);
                return LoopAbort;
            }
            return LoopContinue;
        });
    }
    return AutoStr_FromText(name.toUtf8().constData());
}
Example #8
0
void DxBuilder::buildVertexShader(const ASTEffect& effect, ASTTechnique& technique)
{
   const ASTFunction* pfunction = effect.findFunction(technique.mVertex.mEntry);
   if ( pfunction->mArguments.size() == 1 && pfunction->mArguments[0]->mpType->isStruct() )
   {
      const ASTStruct& input = pfunction->mArguments[0]->mpType->getStruct();
      technique.mpLayout = buildInputLayout(input);
   }

   String code = UTEXT("// generated vertex shader\n\n");
   
   String num;
   NumberConverter& conv = NumberConverter::getInstance();
   for ( std::size_t index = 0; index < effect.mBuffers.size(); ++index )
   {
      const ASTBuffer* pbuffer = effect.mBuffers[index];
      code += UTEXT("cbuffer ") + pbuffer->mName;

      int reg = pbuffer->mRegister;
      if ( reg == -1 )
         reg = (int) index;
      
      code += UTEXT(" : register(b") + conv.format(num, reg) + UTEXT(")\n{") + pbuffer->mBody + UTEXT("};\n\n");
   }

   code += buildStructs(effect, *pfunction);
   code += buildFunction(*pfunction);

   std::string data = code.toUtf8();
   std::string entry = technique.mVertex.mEntry.toUtf8();
   std::string target = technique.mVertex.mTarget.toUtf8();
   uint32_t flags = D3DCOMPILE_ENABLE_STRICTNESS;

   ID3DBlob *presult, *perror;
   HRESULT hr = D3DCompile(data.c_str(), data.length(), NULL, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, entry.c_str(), target.c_str(), flags, 0, &presult, &perror);
   if ( FAILED(hr) )
   {
      std::string d3derror = "Shader compile error: " + std::string((const char*)perror->GetBufferPointer());
      throw std::exception(d3derror.c_str());
   }

   technique.mVertex.mCompiledCode.writeBlob(presult->GetBufferPointer(), presult->GetBufferSize());
}
void SBE_DrawGui()
{
    float const opacity = .8f;

    if(!editActive || editHidden) return;

    if(!App_WorldSystem().hasMap()) return;

    Map &map = App_WorldSystem().map();
    Hand &hand = App_WorldSystem().hand();

    DENG_ASSERT_IN_MAIN_THREAD();

    // Go into screen projection mode.
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, DENG_GAMEVIEW_WIDTH, DENG_GAMEVIEW_HEIGHT, 0, -1, 1);

    glEnable(GL_TEXTURE_2D);

    // Overall stats: numSources / MAX (left)
    String text = String("%1 / %2 (%3 free)")
                    .arg(map.biasSourceCount())
                    .arg(Map::MAX_BIAS_SOURCES)
                    .arg(Map::MAX_BIAS_SOURCES - map.biasSourceCount());

    FR_SetFont(fontFixed);
    FR_LoadDefaultAttrib();
    FR_SetShadowOffset(UI_SHADOW_OFFSET, UI_SHADOW_OFFSET);
    FR_SetShadowStrength(UI_SHADOW_STRENGTH);

    Vector2i size(FR_TextWidth(text.toUtf8().constData()) + 16,
                  FR_SingleLineHeight(text.toUtf8().constData()) + 16);
    int top = DENG_GAMEVIEW_HEIGHT - 10 - size.y;

    Vector2i origin(10, top);
    drawBoxBackground(origin, size, 0);
    origin.x += 8;
    origin.y += size.y / 2;

    drawText(text, origin, UI_Color(UIC_TITLE), opacity);
    origin.y = top - size.y / 2;

    // The map ID.
    String label = (map.def()? map.def()->composeUniqueId(App_CurrentGame()) : "(unknown map)");
    drawText(label, origin, UI_Color(UIC_TITLE), opacity);

    glDisable(GL_TEXTURE_2D);

    if(map.biasSourceCount())
    {
        // Stats for nearest & grabbed:
        drawInfoBox(map.biasSourceNear(hand.origin()), 0, "Nearest", opacity);

        if(!hand.isEmpty())
        {
            FR_SetFont(fontFixed);
            int x = FR_TextWidth("0") * 30;
            drawInfoBox(&hand.grabbed().first()->as<BiasSource>(), x, "Grabbed", opacity);
        }

        drawLightGauge(Vector2i(20, DENG_GAMEVIEW_HEIGHT/2 - 255/2));
    }

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
}
static void drawText(String const &text, Vector2i const &origin_, ui_color_t *color, float alpha,
                     int align = ALIGN_LEFT, short flags = DTF_ONLY_SHADOW)
{
    Point2Raw origin(origin_.x, origin_.y);
    UI_TextOutEx2(text.toUtf8().constData(), &origin, color, alpha, align, flags);
}
static bool SBE_Save(char const *name = 0)
{
    DENG2_ASSERT(editActive);

    LOG_AS("Bias");

    Map &map = App_WorldSystem().map();

    ddstring_t fileName; Str_Init(&fileName);
    if(!name || !name[0])
    {
        Str_Set(&fileName, String(map.def()? map.def()->composeUri().path() : "unknownmap").toUtf8().constData());
    }
    else
    {
        Str_Set(&fileName, name);
        F_ExpandBasePath(&fileName, &fileName);
    }

    // Do we need to append an extension?
    if(String(Str_Text(&fileName)).fileNameExtension().isEmpty())
    {
        Str_Append(&fileName, ".ded");
    }

    F_ToNativeSlashes(&fileName, &fileName);
    FILE *file = fopen(Str_Text(&fileName), "wt");
    if(!file)
    {
        LOG_RES_WARNING("Failed to save light sources to \"%s\": could not open file")
                << NativePath(Str_Text(&fileName)).pretty();
        Str_Free(&fileName);
        return false;
    }

    LOG_RES_VERBOSE("Saving to \"%s\"...")
            << NativePath(Str_Text(&fileName)).pretty();

    String uid = (map.def()? map.def()->composeUniqueId(App_CurrentGame()) : "(unknown map)");
    fprintf(file, "# %i Bias Lights for %s", map.biasSourceCount(), uid.toUtf8().constData());

    // Since there can be quite a lot of these, make sure we'll skip
    // the ones that are definitely not suitable.
    fprintf(file, "\n\nSkipIf Not %s", App_CurrentGame().identityKey().toUtf8().constData());

    map.forAllBiasSources([&file, &uid] (BiasSource &bsrc)
    {
        float minLight, maxLight;
        bsrc.lightLevels(minLight, maxLight);

        fprintf(file, "\n\nLight {");
        fprintf(file, "\n  Map = \"%s\"", uid.toUtf8().constData());
        fprintf(file, "\n  Origin { %g %g %g }", bsrc.origin().x, bsrc.origin().y, bsrc.origin().z);
        fprintf(file, "\n  Color { %g %g %g }", bsrc.color().x, bsrc.color().y, bsrc.color().z);
        fprintf(file, "\n  Intensity = %g", bsrc.intensity());
        fprintf(file, "\n  Sector levels { %g %g }", minLight, maxLight);
        fprintf(file, "\n}");

        return LoopContinue;
    });

    fclose(file);
    Str_Free(&fileName);
    return true;
}