//--------------------------------------------------------------------- public void addLoadRequest(EntityLoader loader) { lock (mLockQueEntityLoadRequest) { mQueEntityLoadRequest.Enqueue(loader); } }
//--------------------------------------------------------------------- void _threadSerializer() { while (true) { // 处理Entity Load if (!mSignDestroy) { EntityLoader loader = null; lock (mLockQueEntityLoadRequest) { if (mQueEntityLoadRequest.Count > 0) { loader = mQueEntityLoadRequest.Dequeue(); } } if (loader != null) { loader.handleLoad(); lock (mLockQueEntityLoadResponse) { mQueEntityLoadResponse.Enqueue(loader); } } } // 处理Entity Save { EntitySaver saver = null; lock (mLockQueEntitySaveRequest) { if (mQueEntitySaveRequest.Count > 0) { saver = mQueEntitySaveRequest.Dequeue(); } } if (saver != null) { saver.handleSave(); } if (mSignDestroy) { lock (mLockQueEntitySaveRequest) { if (mQueEntitySaveRequest.Count == 0) { break; } } } } Thread.Sleep(10); } }
//--------------------------------------------------------------------- public void update(float elapsed_tm) { bool done = false; EntityLoader loader = null; int count = 0; while (!done) { count++; if (count > 20) { break; } // GetEntityData lock (mLockQueEntityLoadResponse) { if (mQueEntityLoadResponse.Count > 0) { loader = mQueEntityLoadResponse.Dequeue(); } else { done = true; } } // CreateEntity if (!done) { Entity entity = null; EntityData entity_data = loader.getEntityData(); if (entity_data != null) { entity = mEntityMgr._createEntityImpl(entity_data, loader.getEntityParent(), loader.isRecursive()); } loader.onLoadFinished(entity); } } }
//--------------------------------------------------------------------- public EntityAsyncStatus asyncLoadCreateEntity(EntityLoader loader) { mEntitySerializerMgr.addLoadRequest(loader); return(loader.getEntityAsyncStatus()); }