当前位置: 首页>>代码示例>>C++>>正文


C++ MaterialInfo类代码示例

本文整理汇总了C++中MaterialInfo的典型用法代码示例。如果您正苦于以下问题:C++ MaterialInfo类的具体用法?C++ MaterialInfo怎么用?C++ MaterialInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MaterialInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dfhack_matinfo_matches

static int dfhack_matinfo_matches(lua_State *state)
{
    MaterialInfo info;
    if (!decode_matinfo(state, &info))
        luaL_argerror(state, 1, "material info object expected");

    luaL_checkany(state, 2);

    if (lua_isuserdata(state, 2))
    {
        if (auto mc = Lua::GetDFObject<df::job_material_category>(state, 2))
            lua_pushboolean(state, info.matches(*mc));
        else if (auto mc = Lua::GetDFObject<df::dfhack_material_category>(state, 2))
            lua_pushboolean(state, info.matches(*mc));
        else if (auto mc = Lua::GetDFObject<df::job_item>(state, 2))
            lua_pushboolean(state, info.matches(*mc));
        else
            luaL_argerror(state, 2, "material category object expected");
    }
    else if (lua_istable(state, 2))
    {
        df::dfhack_material_category tmp;
        Lua::CheckDFAssign(state, &tmp, 2, false);
        lua_pushboolean(state, info.matches(tmp));
    }
    else
        luaL_argerror(state, 2, "material category object expected");

    return 1;
}
开发者ID:Elvang,项目名称:dfhack,代码行数:30,代码来源:LuaApi.cpp

示例2: df_changevein

command_result df_changevein (color_ostream &out, vector <string> & parameters)
{
    if (parameters.size() != 1)
        return CR_WRONG_USAGE;

    CoreSuspender suspend;

    if (!Maps::IsValid())
    {
        out.printerr("Map is not available!\n");
        return CR_FAILURE;
    }
    if (!cursor || cursor->x == -30000)
    {
        out.printerr("No cursor detected - please place the cursor over a mineral vein.\n");
        return CR_FAILURE;
    }

    MaterialInfo mi;
    if (!mi.findInorganic(parameters[0]))
    {
        out.printerr("No such material!\n");
        return CR_FAILURE;
    }
    if (mi.inorganic->material.flags.is_set(material_flags::IS_METAL) ||
        mi.inorganic->material.flags.is_set(material_flags::NO_STONE_STOCKPILE) ||
        mi.inorganic->flags.is_set(inorganic_flags::SOIL_ANY))
    {
        out.printerr("Invalid material - you must select a type of stone or gem\n");
        return CR_FAILURE;
    }

    df::map_block *block = Maps::getBlockAbs(cursor->x, cursor->y, cursor->z);
    if (!block)
    {
        out.printerr("Invalid tile selected.\n");
        return CR_FAILURE;
    }
    df::block_square_event_mineralst *mineral = NULL;
    int tx = cursor->x % 16, ty = cursor->y % 16;
    for (size_t j = 0; j < block->block_events.size(); j++)
    {
        df::block_square_event *evt = block->block_events[j];
        if (evt->getType() != block_square_event_type::mineral)
            continue;
        mineral = (df::block_square_event_mineralst *)evt;
        if (mineral->getassignment(tx, ty))
            break;
        mineral = NULL;
    }
    if (!mineral)
    {
        out.printerr("Selected tile does not contain a mineral vein.\n");
        return CR_FAILURE;
    }
    mineral->inorganic_mat = mi.index;

    return CR_OK;
}
开发者ID:AnnanFay,项目名称:dfhack,代码行数:59,代码来源:changevein.cpp

示例3: dfhack_matinfo_getToken

static int dfhack_matinfo_getToken(lua_State *state)
{
    MaterialInfo info;
    decode_matinfo(state, &info, true);
    auto str = info.getToken();
    lua_pushstring(state, str.c_str());
    return 1;
}
开发者ID:Elvang,项目名称:dfhack,代码行数:8,代码来源:LuaApi.cpp

示例4: dfhack_matinfo_getCraftClass

static int dfhack_matinfo_getCraftClass(lua_State *state)
{
    MaterialInfo info;
    if (decode_matinfo(state, &info, true))
        lua_pushinteger(state, info.getCraftClass());
    else
        lua_pushnil(state);
    return 1;
}
开发者ID:Elvang,项目名称:dfhack,代码行数:9,代码来源:LuaApi.cpp

示例5: dfhack_matinfo_toString

static int dfhack_matinfo_toString(lua_State *state)
{
    MaterialInfo info;
    decode_matinfo(state, &info);

    lua_settop(state, 3);
    auto str = info.toString(luaL_optint(state, 2, 10015), lua_toboolean(state, 3));
    lua_pushstring(state, str.c_str());
    return 1;
}
开发者ID:Elvang,项目名称:dfhack,代码行数:10,代码来源:LuaApi.cpp

示例6: job_material_in_build

static command_result job_material_in_build(Core *c, MaterialInfo &new_mat)
{
    df::ui_build_selector *sel = ui_build_selector;
    df::ui_build_item_req *req = sel->requirements[ui_build_selector->req_index];

    // Loop through matching choices
    bool matches = build_choice_matches(req, sel->choices[sel->sel_index], new_mat, true);

    size_t size = sel->choices.size();
    int base = (matches ? sel->sel_index + 1 : 0);

    for (size_t i = 0; i < size; i++)
    {
        int idx = (base + i) % size;

        if (build_choice_matches(req, sel->choices[idx], new_mat, false))
        {
            sel->sel_index = idx;
            return CR_OK;
        }
    }

    c->con.printerr("Could not find material in list: %s\n", new_mat.toString().c_str());
    return CR_FAILURE;
}
开发者ID:lxnt,项目名称:dfhack,代码行数:25,代码来源:jobutils.cpp

示例7: dfhack_matinfo_find

static int dfhack_matinfo_find(lua_State *state)
{
    MaterialInfo info;
    int argc = lua_gettop(state);

    if (argc == 1)
        info.find(luaL_checkstring(state, 1));
    else
    {
        std::vector<std::string> tokens;

        for (int i = 1; i < argc; i++)
            tokens.push_back(luaL_checkstring(state, i));

        info.find(tokens);
    }

    push_matinfo(state, info);
    return 1;
}
开发者ID:Elvang,项目名称:dfhack,代码行数:20,代码来源:LuaApi.cpp

示例8: shortJobDescription

static std::string shortJobDescription(df::job *job)
{
    std::string rv = stl_sprintf("job %d: ", job->id);

    if (job->job_type != job_type::CustomReaction)
        rv += ENUM_KEY_STR(job_type, job->job_type);
    else
        rv += job->reaction_name;

    MaterialInfo mat;
    df::dfhack_material_category mat_mask;
    guess_job_material(job, mat, mat_mask);

    if (mat.isValid())
        rv += " [" + mat.toString() + "]";
    else if (mat_mask.whole)
        rv += " [" + bitfield_to_string(mat_mask) + "]";

    return rv;
}
开发者ID:Reag,项目名称:dfhack,代码行数:20,代码来源:workflow.cpp

示例9: BindShaderForTexturePrePass

/** Binds the texture for the given mesh-key.
	- Returns false if not cached in */
bool D3D11GraphicsEngineTest::BindShaderForKey(const MeshKey& key)
{
	zCTexture* tx = key.Texture;

	if(!tx)
		return false; // FIXME: Gregs hat has this! Returning here causes it to not render at all

	// Bind texture
	if(tx->CacheIn(0.6f) == zRES_CACHED_IN) // FIXME: Don't always use a texture in a z-pre-pass!
	{
		MyDirectDrawSurface7* surface = tx->GetSurface();
		ID3D11ShaderResourceView* srv[2];

		// Get diffuse and normalmap
		srv[0] = ((D3D11Texture *)surface->GetEngineTexture())->GetShaderResourceView();
		srv[1] = surface->GetNormalmap() ? ((D3D11Texture *)surface->GetNormalmap())->GetShaderResourceView() : NULL;

		// Bind both
		Context->PSSetShaderResources(0,2, srv);

		if(RenderingStage == DES_Z_PRE_PASS)
		{
			// Force alphatest on vobs for now
			BindShaderForTexturePrePass(tx, true);
		}else
		{
			BindShaderForTextureDiffusePass(tx);
		}

		// Get and update info if neccessary
		MaterialInfo* info = key.Info;
		if(!info->Constantbuffer)
			info->UpdateConstantbuffer();

		// Bind info to pixel shader
		info->Constantbuffer->BindToPixelShader(2);
	}
}
开发者ID:DennisGT,项目名称:GD3D11,代码行数:40,代码来源:D3D11GraphicsEngineTest.cpp

示例10: setMaterial

//Method for setting the current material
void OpenGLContainer::setMaterial(MaterialInfo m){
    float *diffuse = m.getDiffuse();
    glMaterialfv(GL_FRONT, GL_SPECULAR,  m.getSpecular());
    glMaterialf (GL_FRONT, GL_SHININESS, m.getShininess());
    glMaterialfv(GL_FRONT, GL_AMBIENT,   m.getAmbient());
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   m.getDiffuse());
    glMaterialfv(GL_FRONT, GL_EMISSION, m.getEmitted());
    glColor4f(diffuse[0],diffuse[1],diffuse[2],1.0);
}
开发者ID:Michael-Z,项目名称:FinalProject,代码行数:10,代码来源:OpenGLContainer.cpp

示例11: push_matinfo

static void push_matinfo(lua_State *state, MaterialInfo &info)
{
    if (!info.isValid())
    {
        lua_pushnil(state);
        return;
    }

    lua_newtable(state);
    lua_pushvalue(state, lua_upvalueindex(1));
    lua_setmetatable(state, -2);

    lua_pushinteger(state, info.type);
    lua_setfield(state, -2, "type");
    lua_pushinteger(state, info.index);
    lua_setfield(state, -2, "index");

#define SETOBJ(name) { \
    Lua::PushDFObject(state, info.name); \
    lua_setfield(state, -2, #name); \
}
    SETOBJ(material);
    if (info.plant) SETOBJ(plant);
    if (info.creature) SETOBJ(creature);
    if (info.inorganic) SETOBJ(inorganic);
    if (info.figure) SETOBJ(figure);
#undef SETOBJ

    if (info.mode != MaterialInfo::Builtin)
    {
        lua_pushinteger(state, info.subtype);
        lua_setfield(state, -2, "subtype");
    }

    const char *id = "builtin";
    switch (info.mode)
    {
        case MaterialInfo::Plant: id = "plant"; break;
        case MaterialInfo::Creature: id = "creature"; break;
        case MaterialInfo::Inorganic: id = "inorganic"; break;
        default: break;
    }

    lua_pushstring(state, id);
    lua_setfield(state, -2, "mode");
}
开发者ID:Elvang,项目名称:dfhack,代码行数:46,代码来源:LuaApi.cpp

示例12: assert

void DFHack::describeMaterial(BasicMaterialInfo *info, const MaterialInfo &mat,
                              const BasicMaterialInfoMask *mask)
{
    assert(mat.isValid());

    info->set_type(mat.type);
    info->set_index(mat.index);

    describeMaterial(info, mat.material, mask);

    switch (mat.mode) {
    case MaterialInfo::Inorganic:
        info->set_token(mat.inorganic->id);
        if (mask && mask->flags())
            flagarray_to_ints(info->mutable_inorganic_flags(), mat.inorganic->flags);
        break;

    case MaterialInfo::Creature:
        info->set_subtype(mat.subtype);
        if (mat.figure)
        {
            info->set_histfig_id(mat.index);
            info->set_creature_id(mat.figure->race);
        }
        else
            info->set_creature_id(mat.index);
        break;

    case MaterialInfo::Plant:
        info->set_plant_id(mat.index);
        break;

    default:
        break;
    }
}
开发者ID:Putnam3145,项目名称:dfhack,代码行数:36,代码来源:RemoteTools.cpp

示例13: guess_job_material

static void guess_job_material(df::job *job, MaterialInfo &mat, df::dfhack_material_category &mat_mask)
{
    using namespace df::enums::job_type;

    if (job->job_type == PrepareMeal)
        mat.decode(-1);
    else
        mat.decode(job);

    mat_mask.whole = job->material_category.whole;

    // Material from the job enum
    const char *job_material = ENUM_ATTR(job_type, material, job->job_type);
    if (job_material)
    {
        MaterialInfo info;
        if (info.findBuiltin(job_material))
            mat = info;
        else
            parseJobMaterialCategory(&mat_mask, job_material);
    }

    // Material from the job reagent
    if (!mat.isValid() && !job->job_items.empty() &&
        (job->job_items.size() == 1 ||
         job->job_items[0]->item_type == item_type::PLANT))
    {
        mat.decode(job->job_items[0]);

        switch (job->job_items[0]->item_type)
        {
        case item_type::WOOD:
            mat_mask.bits.wood = mat_mask.bits.wood2 = true;
            break;

        default:
            break;
        }
    }
}
开发者ID:Reag,项目名称:dfhack,代码行数:40,代码来源:workflow.cpp

示例14: if

MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) {
  Key key = pos.get_material_key();
  int index = key & (size - 1);
  MaterialInfo *mi = entries + index;

  // If mi->key matches the position's material hash key, it means that we 
  // have analysed this material configuration before, and we can simply
  // return the information we found the last time instead of recomputing it:
  if(mi->key == key)
    return mi;

  // Clear the MaterialInfo object, and set its key:
  mi->clear();
  mi->key = key;

  // A special case before looking for a specialized evaluation function:
  // KNN vs K is a draw:
  if(key == KNNKMaterialKey || key == KKNNMaterialKey) {
    mi->factor[WHITE] = mi->factor[BLACK] = 0;
    return mi;
  }

  // Let's look if we have a specialized evaluation function for this
  // particular material configuration:
  if(key == KPKMaterialKey) {
    mi->evaluationFunction = &EvaluateKPK;
    return mi;
  }
  else if(key == KKPMaterialKey) {
    mi->evaluationFunction = &EvaluateKKP;
    return mi;
  }
  else if(key == KBNKMaterialKey) {
    mi->evaluationFunction = &EvaluateKBNK;
    return mi;
  }
  else if(key == KKBNMaterialKey) {
    mi->evaluationFunction = &EvaluateKKBN;
    return mi;
  }
  else if(key == KRKPMaterialKey) {
    mi->evaluationFunction = &EvaluateKRKP;
    return mi;
  }
  else if(key == KPKRMaterialKey) {
    mi->evaluationFunction = &EvaluateKPKR;
    return mi;
  }
  else if(key == KRKBMaterialKey) {
    mi->evaluationFunction = &EvaluateKRKB;
    return mi;
  }
  else if(key == KBKRMaterialKey) {
    mi->evaluationFunction = &EvaluateKBKR;
    return mi;
  }
  else if(key == KRKNMaterialKey) {
    mi->evaluationFunction = &EvaluateKRKN;
    return mi;
  }
  else if(key == KNKRMaterialKey) {
    mi->evaluationFunction = &EvaluateKNKR;
    return mi;
  }
  else if(key == KQKRMaterialKey) {
    mi->evaluationFunction = &EvaluateKQKR;
    return mi;
  }
  else if(key == KRKQMaterialKey) {
    mi->evaluationFunction = &EvaluateKRKQ;
    return mi;
  }
  else if(key == KBBKNMaterialKey) {
    mi->evaluationFunction = &EvaluateKBBKN;
    return mi;
  }
  else if(key == KNKBBMaterialKey) {
    mi->evaluationFunction = &EvaluateKNKBB;
    return mi;
  }
  else if(pos.non_pawn_material(BLACK) == Value(0) &&
          pos.pawn_count(BLACK) == 0 &&
          pos.non_pawn_material(WHITE) >= RookValueEndgame) {
    mi->evaluationFunction = &EvaluateKXK;
    return mi;
  }
  else if(pos.non_pawn_material(WHITE) == Value(0) &&
          pos.pawn_count(WHITE) == 0 &&
          pos.non_pawn_material(BLACK) >= RookValueEndgame) {
    mi->evaluationFunction = &EvaluateKKX;
    return mi;
  }
  else if(pos.pawns() == EmptyBoardBB && pos.rooks() == EmptyBoardBB
          && pos.queens() == EmptyBoardBB) {
    // Minor piece endgame with at least one minor piece per side,
    // and no pawns.
    assert(pos.knights(WHITE) | pos.bishops(WHITE));
    assert(pos.knights(BLACK) | pos.bishops(BLACK));

    if(pos.bishop_count(WHITE) + pos.knight_count(WHITE) <= 2
//.........这里部分代码省略.........
开发者ID:GordCaswell,项目名称:lucaschessportable,代码行数:101,代码来源:material.cpp

示例15: job_material_in_job

static command_result job_material_in_job(Core *c, MaterialInfo &new_mat)
{
    df::job *job = getSelectedWorkshopJob(c);
    if (!job)
        return CR_FAILURE;

    if (!new_mat.isValid() || new_mat.type != 0)
    {
        c->con.printerr("New job material isn't inorganic: %s\n",
                        new_mat.toString().c_str());
        return CR_FAILURE;
    }

    MaterialInfo cur_mat(job);

    if (!cur_mat.isValid() || cur_mat.type != 0)
    {
        c->con.printerr("Current job material isn't inorganic: %s\n",
                        cur_mat.toString().c_str());
        return CR_FAILURE;
    }

    df::craft_material_class old_class = cur_mat.getCraftClass();
    if (old_class == craft_material_class::None)
    {
        c->con.printerr("Unexpected current material type: %s\n",
                        cur_mat.toString().c_str());
        return CR_FAILURE;
    }
    if (new_mat.getCraftClass() != old_class)
    {
        c->con.printerr("New material %s does not satisfy requirement: %s\n",
                        new_mat.toString().c_str(), ENUM_KEY_STR(craft_material_class, old_class));
        return CR_FAILURE;
    }

    for (size_t i = 0; i < job->job_items.size(); i++)
    {
        df::job_item *item = job->job_items[i];
        MaterialInfo item_mat(item);

        if (item_mat != cur_mat)
        {
            c->con.printerr("Job item %d has different material: %s\n",
                            i, item_mat.toString().c_str());
            return CR_FAILURE;
        }

        if (!new_mat.matches(*item))
        {
            c->con.printerr("Job item %d requirements not satisfied by %s.\n",
                            i, new_mat.toString().c_str());
            return CR_FAILURE;
        }
    }

    // Apply the substitution
    job->mat_type = new_mat.type;
    job->mat_index = new_mat.index;

    for (size_t i = 0; i < job->job_items.size(); i++)
    {
        df::job_item *item = job->job_items[i];
        item->mat_type = new_mat.type;
        item->mat_index = new_mat.index;
    }

    c->con << "Applied material '" << new_mat.toString()
           << "' to job " << ENUM_KEY_STR(job_type,job->job_type) << endl;
    return CR_OK;
}
开发者ID:lxnt,项目名称:dfhack,代码行数:71,代码来源:jobutils.cpp


注:本文中的MaterialInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。