SharedPtr<Technique> Technique::CloneWithDefines(const String& vsDefines, const String& psDefines) { // Return self if no actual defines if (vsDefines.Empty() && psDefines.Empty()) return SharedPtr<Technique>(this); Pair<StringHash, StringHash> key = MakePair(StringHash(vsDefines), StringHash(psDefines)); // Return existing if possible HashMap<Pair<StringHash, StringHash>, SharedPtr<Technique> >::Iterator i = cloneTechniques_.Find(key); if (i != cloneTechniques_.End()) return i->second_; // Set same name as the original for the clones to ensure proper serialization of the material. This should not be a problem // since the clones are never stored to the resource cache i = cloneTechniques_.Insert(MakePair(key, Clone(GetName()))); for (Vector<SharedPtr<Pass> >::ConstIterator j = i->second_->passes_.Begin(); j != i->second_->passes_.End(); ++j) { Pass* pass = (*j); if (!pass) continue; if (!vsDefines.Empty()) pass->SetVertexShaderDefines(pass->GetVertexShaderDefines() + " " + vsDefines); if (!psDefines.Empty()) pass->SetPixelShaderDefines(pass->GetPixelShaderDefines() + " " + psDefines); } return i->second_; }
static size_t onWrite(char *ptr, size_t size, size_t nmemb, void *userdata) { WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(userdata)); is_->state = HTTP_OPEN; if (is_->isAborted) { is_->state = HTTP_CLOSED; // This should probably be CURL_WRITEFUNC_ABORT, but that doesn't // exist. It probably would be the same numeric value, if it did. // The docs say that it just has to be a number of bytes that is // not "size * nmemb" to abort. return CURL_READFUNC_ABORT; } // Find the size in bytes. size_t real_size(size * nmemb); // Write the date into the download buffer queue. Serializer* download(dynamic_cast<Serializer*>(is_->download.Get())); download->Write(ptr, (unsigned int)real_size); // Emit a "download_chunk" event. VariantMap eventData; eventData.Insert(MakePair(StringHash("download"), Variant(is_->download))); eventData.Insert(MakePair(StringHash("size"), Variant((unsigned int)real_size))); is_->es.SendEvent("download_chunk", eventData); return real_size; }
ea::shared_ptr<Technique> Technique::CloneWithDefines(const ea::string& vsDefines, const ea::string& psDefines) { // Return self if no actual defines if (vsDefines.empty() && psDefines.empty()) return ea::shared_ptr<Technique>(this); ea::pair<StringHash, StringHash> key = ea::make_pair(StringHash(vsDefines), StringHash(psDefines)); // Return existing if possible auto i = cloneTechniques_.find(key); if (i != cloneTechniques_.end()) return i->second; // Set same name as the original for the clones to ensure proper serialization of the material. This should not be a problem // since the clones are never stored to the resource cache i = cloneTechniques_.insert(ea::make_pair(key, Clone(GetName()))).first; for (auto j = i->second->passes_.begin(); j != i->second->passes_.end(); ++j) { Pass* pass = (*j); if (!pass) continue; if (!vsDefines.empty()) pass->SetVertexShaderDefines(pass->GetVertexShaderDefines() + " " + vsDefines); if (!psDefines.empty()) pass->SetPixelShaderDefines(pass->GetPixelShaderDefines() + " " + psDefines); } return i->second; }
void update_scene() { main_context::access(m_server, [&](main_context::Interface *imc) { Scene *scene = imc->check_scene(m_main_scene); Context *context = scene->GetContext(); ResourceCache *cache = context->GetSubsystem<ResourceCache>(); { Node *n = scene->GetChild("Base"); n->SetScale(Vector3(1.0f, 1.0f, 1.0f)); //n->SetPosition(Vector3(0.0f, 0.5f, 0.0f)); n->SetPosition(Vector3(0.0f, 0.5f, 0.0f)); //n->SetRotation(Quaternion(0, 90, 0)); int w = 10, h = 3, d = 10; ss_ data = "222222222211211111211111111111" "222222222211111111111111111111" "222222222211111111111111111111" "222222222211111111111111111111" "222222222211122111111112111111" "222233222211123111111112111111" "222233222211111111111111111111" "222222222211111111111111111111" "222222222211111111111111111111" "222222222211111111111111111111" ; // Convert data to the actually usable voxel type id namespace // starting from VOXELTYPEID_UNDEFINED=0 for(size_t i = 0; i < data.size(); i++){ data[i] = data[i] - '0'; } // Crude way of dynamically defining a voxel model n->SetVar(StringHash("simple_voxel_data"), Variant( PODVector<uint8_t>((const uint8_t*)data.c_str(), data.size()))); n->SetVar(StringHash("simple_voxel_w"), Variant(w)); n->SetVar(StringHash("simple_voxel_h"), Variant(h)); n->SetVar(StringHash("simple_voxel_d"), Variant(d)); // Load the same model in here and give it to the physics // subsystem so that it can be collided to SharedPtr<Model> model(interface::mesh:: create_8bit_voxel_physics_model(context, w, h, d, data, m_voxel_reg.get())); RigidBody *body = n->CreateComponent<RigidBody>(LOCAL); body->SetFriction(0.75f); CollisionShape *shape = n->CreateComponent<CollisionShape>( LOCAL); shape->SetTriangleMesh(model, 0, Vector3::ONE); } }); }
static size_t onRead(char *buffer, size_t size, size_t nitems, void *instream) { WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(instream)); is_->state = HTTP_OPEN; if (is_->isAborted) { is_->state = HTTP_CLOSED; return CURL_READFUNC_ABORT; } // Find the size in bytes. size_t real_size(size * nitems); // Read as much as we can from the upload buffer queue. Deserializer* upload(dynamic_cast<Deserializer*>(is_->upload.Get())); size_t size_queued(upload->GetSize()); size_t size_left(real_size); if ((size_left > 0) && (size_queued > 0)) { size_t read_size(std::min(size_queued, size_left)); upload->Read(buffer, (unsigned int)read_size); size_left -= read_size; } // If we still have bytes to fill, then emit a "upload_chunk" event. if (size_left > 0) { VariantMap eventData; eventData.Insert(MakePair(StringHash("upload"), Variant(is_->upload))); eventData.Insert(MakePair(StringHash("size"), Variant((unsigned int)size_left))); is_->es.SendEvent("upload_chunk", eventData); } // Read as much as we can from the upload buffer queue (again). size_queued = upload->GetSize(); size_left = real_size; if ((size_left > 0) && (size_queued > 0)) { size_t read_size(std::min(size_queued, size_left)); upload->Read(buffer, (unsigned int)read_size); size_left -= read_size; } // If we still have bytes to fill, then something went wrong, so we should abort. if (size_left > 0) { is_->isAborted = true; return CURL_READFUNC_ABORT; } return real_size; }
void LFO::CreateProperty(UnsignedType aPropertyID, Property *aProperty) { /* Shared Property Instantiation */ if (aPropertyID == StringHash("Wave Type", true)) { m_Type = NumberProperty<UnsignedType>::New(aProperty); return; } if (aPropertyID == StringHash("Frequency", true)) { m_Freq = NumberProperty<FloatType>::New(aProperty); return; } }
void WindowButton::onMenuUp() { m_Flags &= ~DEPRESSED; // post message to listeners postMessage( WB_MENUUP, StringHash( name() ), 0 ); }
void Node::SetName(const String& name) { name_ = name; nameHash_ = StringHash(name); MarkNetworkUpdate(); }
static bool SelectClass(EvalContext *ctx, const Rlist *list, const Promise *pp) { int count = 0; for (const Rlist *rp = list; rp != NULL; rp = rp->next) { count++; } if (count == 0) { Log(LOG_LEVEL_ERR, "No classes to select on RHS"); PromiseRef(LOG_LEVEL_ERR, pp); return false; } assert(list); char splay[CF_MAXVARSIZE]; snprintf(splay, CF_MAXVARSIZE, "%s+%s+%ju", VFQNAME, VIPADDRESS, (uintmax_t)getuid()); double hash = (double) StringHash(splay, 0, CF_HASHTABLESIZE); assert(hash < CF_HASHTABLESIZE); int n = (int) (count * hash / (double) CF_HASHTABLESIZE); assert(n < count); while (n > 0 && list->next != NULL) { n--; list = list->next; } EvalContextClassPutSoft(ctx, RlistScalarValue(list), CONTEXT_SCOPE_NAMESPACE, "source=promise"); return true; }
void onEnd(int code) { VariantMap eventData; if (code != CURLE_OK) { state = HTTP_ERROR; eventData.Insert(MakePair(StringHash("error"), Variant(String(error, (unsigned int)strnlen(error, sizeof(error)))))); } else { state = HTTP_CLOSED; eventData.Insert(MakePair(StringHash("download"), Variant(download))); eventData.Insert(MakePair(StringHash("upload"), Variant(upload))); } es.SendEvent("complete", eventData); }
bool ValueAnimation::LoadJSON(const JSONValue& source) { valueType_ = VAR_NONE; eventFrames_.Clear(); String interpMethodString = source.Get("interpolationmethod").GetString(); InterpMethod method = (InterpMethod)GetStringListIndex(interpMethodString.CString(), interpMethodNames, IM_LINEAR); SetInterpolationMethod(method); if (interpolationMethod_ == IM_SPLINE) splineTension_ = source.Get("splinetension").GetFloat(); // Load keyframes JSONArray keyFramesArray = source.Get("keyframes").GetArray(); for (unsigned i = 0; i < keyFramesArray.Size(); i++) { const JSONValue& val = keyFramesArray[i]; float time = val.Get("time").GetFloat(); Variant value = val.Get("value").GetVariant(); SetKeyFrame(time, value); } // Load event frames JSONArray eventFramesArray = source.Get("eventframes").GetArray(); for (unsigned i = 0; i < eventFramesArray.Size(); i++) { const JSONValue& eventFrameVal = eventFramesArray[i]; float time = eventFrameVal.Get("time").GetFloat(); unsigned eventType = eventFrameVal.Get("eventtype").GetUInt(); VariantMap eventData = eventFrameVal.Get("eventdata").GetVariantMap(); SetEventFrame(time, StringHash(eventType), eventData); } return true; }
bool ValueAnimation::LoadXML(const XMLElement& source) { valueType_ = VAR_NONE; eventFrames_.Clear(); String interpMethodString = source.GetAttribute("interpolationmethod"); InterpMethod method = (InterpMethod)GetStringListIndex(interpMethodString.CString(), interpMethodNames, IM_LINEAR); SetInterpolationMethod(method); if (interpolationMethod_ == IM_SPLINE) splineTension_ = source.GetFloat("splinetension"); XMLElement keyFrameElem = source.GetChild("keyframe"); while (keyFrameElem) { float time = keyFrameElem.GetFloat("time"); Variant value = keyFrameElem.GetVariant(); SetKeyFrame(time, value); keyFrameElem = keyFrameElem.GetNext("keyframe"); } XMLElement eventFrameElem = source.GetChild("eventframe"); while (eventFrameElem) { float time = eventFrameElem.GetFloat("time"); unsigned eventType = eventFrameElem.GetUInt("eventtype"); VariantMap eventData = eventFrameElem.GetChild("eventdata").GetVariantMap(); SetEventFrame(time, StringHash(eventType), eventData); eventFrameElem = eventFrameElem.GetNext("eventframe"); } return true; }
QString Localization::Get(const QString& id) { if (id.isEmpty()) return s_dummy; if (GetNumLanguages() == 0) { URHO3D_LOGWARNING("Localization::Get(id): no loaded languages"); return id; } QString result = strings_[StringHash(GetLanguage())][StringHash(id)]; if (result.isEmpty()) { URHO3D_LOGWARNING("Localization::Get(\"" + id + "\") not found translation, language=\"" + GetLanguage() + "\""); return id; } return result; }
void WindowButton::onButtonDown() { m_ButtonDown = true; m_Flags |= DEPRESSED; // send message to listeners postMessage( WB_BUTTONDOWN, StringHash( name() ), 0 ); }
String Localization::Get(const String& id) { if (id.Empty()) return String::EMPTY; if (GetNumLanguages() == 0) { LOGWARNING("Localization::Get(id): no loaded languages"); return id; } String result = strings_[StringHash(GetLanguage())][StringHash(id)]; if (result.Empty()) { LOGWARNING("Localization::Get(\"" + id + "\") not found translation, language=\"" + GetLanguage() + "\""); return id; } return result; }
int LockEnabled() { int retval = 1; HookCallbacks::RunCallback(StringHash("mouseLock"), &retval); return retval; }
Resource* ResourceCache::GetResource(ShortStringHash type, const String& nameIn) { String name = SanitateResourceName(nameIn); // Add the name to the hash map, so if this is an unknown resource, the error will not be unintelligible StoreNameHash(name); return GetResource(type, StringHash(name)); }
VariantMap XMLElement::GetVariantMap() const { VariantMap ret; XMLElement variantElem = GetChild("variant"); while (variantElem) { // If this is a manually edited map, user can not be expected to calculate hashes manually. Also accept "name" attribute if (variantElem.HasAttribute("name")) ret[StringHash(variantElem.GetAttribute("name"))] = variantElem.GetVariant(); else if (variantElem.HasAttribute("hash")) ret[StringHash(variantElem.GetUInt("hash"))] = variantElem.GetVariant(); variantElem = variantElem.GetNext("variant"); } return ret; }
static int onProgress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(clientp)); if (is_->isAborted) { // This should probably be CURL_XFERINFO_ABORT, but that doesn't // exist. It probably would be the same numeric value, if it did. // The docs say that it just has to be a nonzero to abort. return CURL_READFUNC_ABORT; } VariantMap eventData; eventData.Insert(MakePair(StringHash("down_total"), Variant((double)dltotal))); eventData.Insert(MakePair(StringHash("down_loaded"), Variant((double)dlnow))); eventData.Insert(MakePair(StringHash("up_total"), Variant((double)ultotal))); eventData.Insert(MakePair(StringHash("up_loaded"), Variant((double)ulnow))); is_->es.SendEvent("progress", eventData); return 0; }
void SoundSource::SetSoundType(const QString& type) { if (type == SOUND_MASTER) return; soundType_ = type; soundTypeHash_ = StringHash(type); UpdateMasterGain(); MarkNetworkUpdate(); }
bool Animation::RemoveTrack(const String& name) { HashMap<StringHash, AnimationTrack>::Iterator i = tracks_.Find(StringHash(name)); if (i != tracks_.End()) { tracks_.Erase(i); return true; } else return false; }
StringHash StringHash::RegisterSignificantString(const char* str) { StringHash hash(str); if (gSignificantLookup.Contains(hash)) return StringHash(hash); gSignificantLookup[hash] = String(str); return hash; }
/* ----------------------------------------------------- */ keeploc_t * getkeep(const char *s, int def_topline, int def_cursline) { /* 為省記憶體, 且避免 malloc/free 不成對, getkeep 最好不要 malloc, * 只記 s 的 hash 值, * fvn1a-32bit collision 機率約小於十萬分之一 */ /* 原本使用 link list, 可是一方面會造成 malloc/free 不成對, * 一方面 size 小, malloc space overhead 就高, 因此改成 link block, * 以 KEEPSLOT 為一個 block 的 link list. * 只有第一個 block 可能沒滿. */ /* TODO LRU recycle? 麻煩在於別處可能把 keeploc_t pointer 記著... */ #define KEEPSLOT 10 struct keepsome { unsigned char used; keeploc_t arr[KEEPSLOT]; struct keepsome *next; }; static struct keepsome preserv_keepblock; static struct keepsome *keeplist = &preserv_keepblock; struct keeploc_t *p; unsigned key=StringHash(s); int i; if (def_cursline >= 0) { struct keepsome *kl=keeplist; while(kl) { for(i=0; i<kl->used; i++) if(key == kl->arr[i].hashkey) { p = &kl->arr[i]; if (p->crs_ln < 1) p->crs_ln = 1; return p; } kl=kl->next; } } else def_cursline = -def_cursline; if(keeplist->used==KEEPSLOT) { struct keepsome *kl; kl = (struct keepsome*)malloc(sizeof(struct keepsome)); memset(kl, 0, sizeof(struct keepsome)); kl->next = keeplist; keeplist = kl; } p = &keeplist->arr[keeplist->used]; keeplist->used++; p->hashkey = key; p->top_ln = def_topline; p->crs_ln = def_cursline; return p; }
void Localization::LoadJSON(const JSONValue& source) { for (JSONObject::const_iterator i = source.GetObject().begin(); i != source.GetObject().end(); ++i) { QString id = MAP_KEY(i); if (id.isEmpty()) { URHO3D_LOGWARNING("Localization::LoadJSON(source): string ID is empty"); continue; } const JSONObject& langs = MAP_VALUE(i).GetObject(); for (JSONObject::const_iterator j = langs.begin(); j != langs.end(); ++j) { const QString& lang = MAP_KEY(j); if (lang.isEmpty()) { URHO3D_LOGWARNING("Localization::LoadJSON(source): language name is empty, string ID=\"" + id + "\""); continue; } const QString stringRef = MAP_VALUE(j).GetString(); if (stringRef.isEmpty()) { URHO3D_LOGWARNING( "Localization::LoadJSON(source): translation is empty, string ID=\"" + id + "\", language=\"" + lang + "\""); continue; } if (strings_[StringHash(lang)][StringHash(id)] != s_dummy) { URHO3D_LOGWARNING( "Localization::LoadJSON(source): override translation, string ID=\"" + id + "\", language=\"" + lang + "\""); } strings_[StringHash(lang)][StringHash(id)] = stringRef; if (!languages_.contains(lang)) languages_.push_back(lang); if (languageIndex_ == -1) languageIndex_ = 0; } } }
void Localization::LoadJSON(const JSONValue& source) { for (JSONObject::ConstIterator i = source.Begin(); i != source.End(); ++i) { String id = i->first_; if (id.Empty()) { LOGWARNING("Localization::LoadJSON(source): string ID is empty"); continue; } const JSONValue& langs = i->second_; for (JSONObject::ConstIterator j = langs.Begin(); j != langs.End(); ++j) { const String& lang = j->first_; if (lang.Empty()) { LOGWARNING("Localization::LoadJSON(source): language name is empty, string ID=\"" + id + "\""); continue; } const String& string = j->second_.GetString(); if (string.Empty()) { LOGWARNING( "Localization::LoadJSON(source): translation is empty, string ID=\"" + id + "\", language=\"" + lang + "\""); continue; } if (strings_[StringHash(lang)][StringHash(id)] != String::EMPTY) { LOGWARNING( "Localization::LoadJSON(source): override translation, string ID=\"" + id + "\", language=\"" + lang + "\""); } strings_[StringHash(lang)][StringHash(id)] = string; if (!languages_.Contains(lang)) languages_.Push(lang); if (languageIndex_ == -1) languageIndex_ = 0; } } }
namespace three { uint32_t Scene::Type = StringHash("Scene").hash; Scene::Scene() : Object(), matrixAutoUpdate(false) { } void Scene::__addObject(Object * object) { if (dynamic_cast<Light *>(object)) { lights.push_back(object); } else if (!dynamic_cast<Camera *>(object)) { objects.push_back(object); objectsAdded.push_back(object); objectsRemoved.erase(std::remove(objectsRemoved.begin(), objectsRemoved.end(), object), objectsRemoved.end()); } for (std::vector<Object *>::iterator it = object->children.begin(), end = object->children.end(); it != end; ++it) __addObject(*it); } void Scene::__removeObject(Object * object) { if (dynamic_cast<Light *>(object)) { lights.erase(std::remove(lights.begin(), lights.end(), object), lights.end()); } else if (!dynamic_cast<Camera *>(object)) { std::vector<Object *>::iterator result = std::find(objectsRemoved.begin(), objectsRemoved.end(), object); if (result != objectsRemoved.end()) { objects.erase(result); objectsRemoved.push_back(object); objectsAdded.erase(std::remove(objectsAdded.begin(), objectsAdded.end(), object), objectsAdded.end()); } } for (std::vector<Object *>::iterator it = object->children.begin(), end = object->children.end(); it != end; ++it) __removeObject(*it); } }
//******************************************************************************* void World_RequestState(PACKET_STREAM* Stream) { PLAYER* Player = PlayerList; DIRECTION_ACK_PACKET_HANDLER::DATA Data; while(Player != null) { Data.x = Player->Pos.x; Data.y = Player->Pos.y; Data.z = Player->Pos.z; Data.UserId = Player->Id; Stream->AddPacket(StringHash("DIRECTION_ACK"), sizeof(Data), &Data); Player = Player->Next; } }
Actor* addMainActor(Scene *scene) { Actor* actor = new Actor; TransformComponent* trans = new TransformComponent(); actor->addComponent(trans); CameraComponent* cam = new CameraComponent(); actor->addComponent(cam); actor->addComponent(new MyCharacterDynamicPhysicsComponent()); PlayerAnimationManagerComponent *anim = new PlayerAnimationManagerComponent(); actor->addComponent(anim); trans->setLocalPos(ComponentId::Render, vec3(0, -0.4, 0)); trans->setPos(vec3(0, 5, 0.5)); trans->setLocalPos(ComponentId::Light, vec3(0, 3, 0)); trans->setLocalScale(ComponentId::Render, vec3(0.017)); SkeletalMeshGraphicComponent * mesh = new SkeletalMeshGraphicComponent(AssetManager::getBasePath() + "Data/Model/mixamoWalkBlender.dae"); mesh->velocity = 1.4; Material *mat = new Material(); mat->setDiffuse(AssetManager::getBasePath() + "Data/Texture/default.png"); mat->setShininess(200); mesh->addMaterial(mat); actor->addComponent(mesh); scene->systemManager->getSystem(StringHash("GenericSystem").getHash())->addComponent(cam); scene->systemManager->getSystem(StringHash("GenericSystem").getHash())->addComponent(mesh); scene->addActor(actor); return actor; }
unsigned RvalHash(Rval rval, unsigned seed, unsigned max) { switch (rval.type) { case RVAL_TYPE_SCALAR: return StringHash(RvalScalarValue(rval), seed, max); case RVAL_TYPE_FNCALL: return FnCallHash(RvalFnCallValue(rval), seed, max); case RVAL_TYPE_LIST: return RlistHash(RvalRlistValue(rval), seed, max); case RVAL_TYPE_NOPROMISEE: return (seed + 1) % max; default: ProgrammingError("Unhandled case in switch: %d", rval.type); } }
void setuserhashedfile(char *buf, const char *filename) { #ifdef USERHASHSTORE_ROOTPATH // hash designed by kcwu unsigned hash = StringHash(cuser.userid) & 0xffff; assert(is_validuserid(cuser.userid)); snprintf(buf, PATHLEN, USERHASHSTORE_ROOTPATH "/%02x/%02x/%s.%s.%x", (hash >> 8) & 0xff, hash & 0xff, filename, cuser.userid, cuser.firstlogin); #else (void)buf; (void)filename; assert(!"you must define and initialize USERHASHSTORE_ROOTPATH"); #endif }