本文整理汇总了C++中HashString类的典型用法代码示例。如果您正苦于以下问题:C++ HashString类的具体用法?C++ HashString怎么用?C++ HashString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HashString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadImage
/**
* @brief Load an image by file name.
* @param aName Name of the file.
*/
void PCShaderSurface::LoadImage(HashString const &aName)
{
/* If the file was already loaded,
let's avoid assigning a new id. */
TextureData const& textureData = GetManager()->GetTextureData(aName);
if(textureData.mTextureID != (unsigned)-1)
{
mTextureID = textureData.mTextureID;
SetTextureSize(Vector3(textureData.mWidth, textureData.mHeight, 0));
}
// else we load the image from file
else if((mSurface = IMG_Load(Common::RelativePath("Art", aName).c_str())))
{
if ((mSurface->w & (mSurface->w - 1)) != 0 )
{
DebugLogPrint("warning: width of image: %s is not a power of 2\n", aName.ToCharArray());
}
if ((mSurface->h & (mSurface->h - 1)) != 0 )
{
DebugLogPrint("warning: height of image: %s is not a power of 2\n", aName.ToCharArray());
}
SetTextureSize(Vector3(mSurface->w, mSurface->h, 0));
mNumberOfColors = mSurface->format->BytesPerPixel;
if (mNumberOfColors == 4)
{
if (mSurface->format->Rmask == 0x000000ff)
mTextureFormat = GL_RGBA;
else
#ifndef _WIN32
mTextureFormat = GL_BGRA;
#else
mTextureFormat = GL_RGBA;
#endif
}
else if (mNumberOfColors == 3)
{
if (mSurface->format->Rmask == 0x000000ff)
mTextureFormat = GL_RGB;
else
#ifndef _WIN32
mTextureFormat = GL_BGR;
#else
mTextureFormat = GL_RGB;
#endif
}
else
{
DebugLogPrint("warning: image %s is not truecolor... this will probably break\n", aName.ToCharArray());
DebugLogPrint("warning: bytes per pixel for image %s: %d\n", aName.ToCharArray(), mNumberOfColors);
}
AddTexturePairing(aName);
}
else
{
DebugLogPrint("warning: file: %s not found or incompatible format, check this out\n", aName.ToCharArray());
}
}
示例2:
// SetTo
status_t
ExtendedServerInfo::SetTo(ServerInfo* serverInfo)
{
if (!serverInfo)
return B_BAD_VALUE;
// set name and connection method
const char* name = serverInfo->GetServerName();
HashString addressString;
if (!name || strlen(name) == 0) {
status_t error = fAddress.GetString(&addressString, false);
if (error != B_OK)
return error;
name = addressString.GetString();
}
if (!fServerName.SetTo(name)
|| !fConnectionMethod.SetTo(serverInfo->GetConnectionMethod())) {
return B_NO_MEMORY;
}
// add the shares
int32 shareCount = serverInfo->CountShares();
for (int32 i = 0; i < shareCount; i++) {
const ShareInfo& shareInfo = serverInfo->ShareInfoAt(i);
status_t error = _AddShare(&shareInfo);
if (error != B_OK)
return error;
}
return B_OK;
}
示例3: Permissions
// GetNodePermissions
Permissions
SecurityContext::GetNodePermissions(const node_ref& ref, User* user)
{
if (!user)
return Permissions();
ContextLocker _(this);
HashString path;
status_t error = _AddNodePath(ref, &path);
if (error != B_OK)
return Permissions();
return fPermissions->Get(UserPath(path.GetString(), user));
}
示例4: Execute
virtual void Execute(const DataObject &object)
{
// The current player is now in a blocking action.
RULE.Execute(shRuleBeginBlockingAction, DataObject(current()));
wxASSERT(1 <= object.numItems());
//retrieve the text to put in the MessageUI
DataObject input(0), output;
const HashString& state = gameData<HashString>(shState);
if(false == DecideHash(state, input, output))
{
wxLogError(
wxString::Format(wxT("Programmer Error: No State %s in ")
wxT("RuleRequestInitialRoadSeafarers"), state.cwx_str()));
return;
}
wxASSERT(3 == output.numItems());
wxString text1 = output.read<wxString>();
wxString text2 = output.read<wxString>(1);
HashString logic = HashString::Format(shLogicStringFormat.c_str(),
output.read<HashString>(2).c_str());
HashString rule = HashString::Format(shRuleStringFormat.c_str(),
output.read<HashString>(2).c_str());
//if this involves ships, do some crazy mojo
if(TRUE == gameData<wxInt32>(shInitialShip))
{
text1 = stPlaceAShip;
text2 = stWaitingPlaceAShip;
wxInt32 index = logic.find(shRoad);
wxASSERT(-1 != index);
logic.replace(index, 4, shShip);
logic = HashString(logic.c_str());
}
RULE.Execute(shRuleUpdateMessageUI,
DataObject(text1, text2));
RULE.Execute(shRuleLocateInitialRoad, DataObject(
object.read<wxInt32>(), logic, rule));
}
示例5: l_setArgHashString
static int l_setArgHashString( lua_State * lua )
{
// Grab userdata from stack
rho::Event * p_event = static_cast< rho::Event * >( checklightuserdata( lua, 1 ) );
HashString arg_name = chechHashString( lua, 2 );
HashString val = chechHashString( lua, 3 );
// Perform set arg on event
p_event->setArgHashedStringID( arg_name, val.getHashValue() );
// Pop the args we were given
lua::pop_all(lua);
return 0;
}
示例6: _
// ClearNodePermissions
void
SecurityContext::ClearNodePermissions(const node_ref& ref, User* user)
{
ContextLocker _(this);
HashString path;
status_t error = _AddNodePath(ref, &path);
if (error != B_OK)
return;
if (user) {
fPermissions->Remove(UserPath(path.GetString(), user));
} else {
for (UserMap::Iterator it = fUsers->GetIterator(); it.HasNext();)
fPermissions->Remove(UserPath(path.GetString(), it.Next().value));
}
}
示例7: LoadText
/**
* @brief Loads a text surface in font.
* @param aFont Font to use.
* @param aText Text to render.
* @param aForegroundColor Color of the text.
* @param aBackgroundColor Color of the background.
* @param aSize Size of font.
* @param aMaxWidth Max width of a single line (in pixels).
* @return
*/
Vector3 PCShaderSurface::LoadText(HashString const &aFont, HashString const &aText, Vector4 const &aForegroundColor, Vector4 const &aBackgroundColor, int aSize, int aMaxWidth)
{
// Endianness is important here
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
HashString const textureDataHash = aFont + aText + Common::IntToString(aSize);
TextureData const& data = GetManager()->GetTextureData(textureDataHash);
if(data.mTextureID != (unsigned)-1)
{
Vector3 size = Vector3(data.mWidth, data.mHeight, 0);
mTextureID = data.mTextureID;
SetTextureSize(size);
return size;
}
else
{
if(!TTF_WasInit())
TTF_Init();
mFont = TTF_OpenFont(Common::RelativePath("Fonts", aFont).c_str(), aSize);
if(!mFont)
{
mFont = NULL;
DebugLogPrint("warning: file not found or incompatible format, check this out\n");
DebugLogPrint("%s", TTF_GetError());
return Vector3(0, 0, 0);
}
// Create text texture
SDL_Color fgColor = {(Uint8)aForegroundColor.x, (Uint8)aForegroundColor.y, (Uint8)aForegroundColor.z, (Uint8)aForegroundColor.w};
//SDL_Color bgColor = {(Uint8)aBackgroundColor.x, (Uint8)aBackgroundColor.y, (Uint8)aBackgroundColor.z, (Uint8)aBackgroundColor.w};
SDL_Surface *msg = TTF_RenderText_Blended_Wrapped(mFont, aText.ToCharArray(), fgColor, aMaxWidth);
if(!msg)
{
DebugLogPrint("TTF_RenderText failed: %s", TTF_GetError());
assert(msg);
}
mTextureFormat = GL_RGBA;
mSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, msg->w, msg->h, 32, rmask, gmask, bmask, amask);
SetTextureSize(Vector3(mSurface->w, mSurface->h, 0));
SDL_BlitSurface(msg, NULL, mSurface, NULL);
AddTexturePairing(textureDataHash);
return Vector3(mSurface->w, mSurface->h, 0);
}
}
示例8: mFileName
GameObject::GameObject(ObjectManager *aManager, HashString const &aFileName) :
mFileName(aFileName), mName(""), mComponents(), mManager(aManager)
{
for(int i = aFileName.Length() - 1; i >= 0 && aFileName[i] != '/'; --i)
{
mName.Push(aFileName[i]);
}
mName.Reverse();
mName = mName.SubString(0, mName.Size() - 4);
}
示例9: DestroyAllUnits
void Map::LoadFromJSON( const rapidjson::Value& object )
{
// Destroy all Units.
// TODO: Don't do this.
DestroyAllUnits();
// Get the Units tag.
const rapidjson::Value& unitsArray = object[ "units" ];
assertion( unitsArray.IsArray(), "Could not load game state from JSON because no \"units\" list was found!" );
Scenario* scenario = GetScenario();
for( auto it = unitsArray.Begin(); it != unitsArray.End(); ++it )
{
const rapidjson::Value& object = ( *it );
assertion( object.IsObject(), "Could not load Unit from JSON because the JSON provided was not an object!" );
// Get all properties.
HashString unitTypeName = GetJSONStringValue( object, "unitType", "" );
int ownerIndex = GetJSONIntValue( object, "owner", -1 );
int tileX = GetJSONIntValue( object, "x", -1 );
int tileY = GetJSONIntValue( object, "y", -1 );
assertion( GetTile( tileX, tileY ).IsValid(), "Loaded invalid tile position (%d,%d) from JSON!", tileX, tileY );
// Get references.
UnitType* unitType = scenario->UnitTypes.FindByName( unitTypeName );
assertion( unitType, "Could not load invalid UnitType (\"%s\") from JSON!", unitTypeName.GetCString() );
Faction* faction = GetFactionByIndex( ownerIndex );
assertion( faction, "Could not load Unit with invalid Faction index (%d) from JSON!", ownerIndex );
// Spawn the Unit.
Unit* unit = CreateUnit( unitType, faction, tileX, tileY );
// Load each Unit from the array.
unit->LoadFromJSON( *it );
}
}
示例10: assertion
//---------------------------------------
void Widget::AddChild( Widget* child )
{
assertion( child, "Cannot add null child to Widget \"%s\"!", GetName().GetCString() );
assertion( child->GetManager() == mManager, "Cannot add child \"%s\" to Widget \"%s\" because it was created by a different WidgetManager!", child->mName.GetCString(), mName.GetCString() );
HashString parentName = ( child->mParent ? child->mParent->mName : "" );
assertion( child->mParent == nullptr, "Cannot add child \"%s\" to Widget \"%s\" because it is already a child of Widget \"%s\"!", child->mName.GetCString(), mName.GetCString(), parentName.GetCString() );
assertion( !HasChildWithName( child->mName ), "Could not add child \"%s\" to Widget \"%s\" because a child of the same name already exists!", child->mName.GetCString(), mName.GetCString() );
//DebugPrintf( "Adding child \"%s\" to Widget \"%s\"...", child->GetName().GetCString(), GetName().GetCString() );
// If a child with the specified name does not already exist, add the new child.
mChildren[ child->mName ] = child;
child->mParent = this;
// Resort all children by their draw order.
InvalidateDrawOrder();
}
示例11: getTexture
pTexture TextureManager::getTexture( HashString const & texture_name )
{
TextureMap::iterator texture_pos = m_textureMap.find( texture_name );
pTexture p_texture;
if ( texture_pos != m_textureMap.end() ) // If we did find it
{
p_texture = texture_pos->second;
}
else
{
p_texture = pTexture( new sf::Texture );
if ( ! p_texture->loadFromFile( texture_name.getString() ) ) // If load fails, then use default texture
{
// Right now, fuck shit up
return pTexture();
}
m_textureMap[ texture_name ] = p_texture; // Add to map
}
return p_texture;
}
示例12: mAnimationSet
//---------------------------------------
// Sprite
//---------------------------------------
Sprite::Sprite( SpriteAnimationSet& animation, const HashString& initialAnimName )
: mAnimationSet( animation )
, DrawColor( Color::WHITE)
, RelativeToCamera( true )
, FixedSize( false )
, Scale( Vec2f::ONE )
{
HashMap< SpriteAnimation >::const_iterator anim = animation.Animations.find( initialAnimName );
if ( anim != animation.Animations.end() )
{
mSprAnimInfo.CurrentAnimationName = anim->first;
}
else
{
WarnInfo( "Sprite() initial animation not found: %s\n", initialAnimName.GetString().c_str() );
if ( !mAnimationSet.Animations.empty() )
{
mSprAnimInfo.CurrentAnimationName = mAnimationSet.Animations.begin()->first;
}
}
mSprAnimInfo.CurrentAnimationFrame = 0;
mSprAnimInfo.CurrentAnimationFrameTime = 0.0f;
}
示例13: GetHorizontalAlignmentByName
//---------------------------------------
Widget::HorizontalAlignment Widget::GetHorizontalAlignmentByName( const HashString& name )
{
HorizontalAlignment result = HORIZONTAL_ALIGN_LEFT;
if( name == HORIZONTAL_ALIGN_LEFT_NAME )
{
result = HORIZONTAL_ALIGN_LEFT;
}
else if( name == HORIZONTAL_ALIGN_CENTER_NAME )
{
result = HORIZONTAL_ALIGN_CENTER;
}
else if( name == HORIZONTAL_ALIGN_RIGHT_NAME )
{
result = HORIZONTAL_ALIGN_RIGHT;
}
else
{
WarnFail( "HorizontalAlignment setting \"%s\" is invalid!", name.GetCString() );
}
return result;
}
示例14: GetVerticalAlignmentByName
//---------------------------------------
Widget::VerticalAlignment Widget::GetVerticalAlignmentByName( const HashString& name )
{
VerticalAlignment result = VERTICAL_ALIGN_TOP;
if( name == VERTICAL_ALIGN_TOP_NAME )
{
result = VERTICAL_ALIGN_TOP;
}
else if( name == VERTICAL_ALIGN_CENTER_NAME )
{
result = VERTICAL_ALIGN_CENTER;
}
else if( name == VERTICAL_ALIGN_BOTTOM_NAME )
{
result = VERTICAL_ALIGN_BOTTOM;
}
else
{
WarnFail( "VerticalAlignment setting \"%s\" is invalid!", name.GetCString() );
}
return result;
}
示例15: RETURN_ERROR
// Init
status_t
ServerConnection::Init(vnode_id connectionBrokenTarget)
{
if (!fServerInfo)
RETURN_ERROR(B_BAD_VALUE);
// create a connection broken event
fConnectionBrokenEvent
= new(std::nothrow) ConnectionBrokenEvent(connectionBrokenTarget);
if (!fConnectionBrokenEvent)
return B_NO_MEMORY;
// get the server address
const char* connectionMethod = fServerInfo->GetConnectionMethod();
HashString server;
status_t error = fServerInfo->GetAddress().GetString(&server, false);
if (error != B_OK)
RETURN_ERROR(error);
// create the volume map
fVolumes = new(std::nothrow) VolumeMap;
if (!fVolumes)
RETURN_ERROR(B_NO_MEMORY);
error = fVolumes->InitCheck();
if (error != B_OK)
RETURN_ERROR(error);
// establish the connection
Connection* connection;
ConnectionFactory factory;
error = factory.CreateConnection(connectionMethod, server.GetString(),
&connection);
if (error != B_OK)
RETURN_ERROR(error);
// create a request connection
fConnection = new(std::nothrow) RequestConnection(connection, this);
if (!fConnection) {
delete connection;
RETURN_ERROR(B_NO_MEMORY);
}
error = fConnection->Init();
if (error != B_OK)
return error;
// send an `init connection request'
// prepare the request
InitConnectionRequest request;
request.bigEndian = B_HOST_IS_BENDIAN;
// send the request
Request* _reply;
error = fConnection->SendRequest(&request, &_reply);
if (error != B_OK)
return error;
ObjectDeleter<Request> replyDeleter(_reply);
// everything OK?
InitConnectionReply* reply = dynamic_cast<InitConnectionReply*>(_reply);
if (!reply)
return B_BAD_DATA;
if (reply->error != B_OK)
return reply->error;
fConnected = true;
return B_OK;
}