void javax_virtualsense_network_Packet_javax_virtualsense_network_Packet_createPacket_byte__(){ uint8_t i = 0; dj_object* ret = NULL; dj_int_array * byteArray = REF_TO_VOIDP(dj_exec_stackPopRef()); // create an object or allocate the chunk as is ? //heap_chunk * chk = (heap_chunk *)byteArray; PRINTF("array size is %d\n", byteArray->array.length); // resolve runtime class dj_global_id refClass = dj_vm_resolveRuntimeClass(dj_exec_getVM(), byteArray->data.bytes[4]); if(refClass.infusion != NULL){ ret = (dj_object*)dj_mem_alloc((byteArray->array.length - sizeof(heap_chunk)), byteArray->data.bytes[4]); heap_chunk * chk = getChunk(ret); PRINTF("BEFORE W Created object id %d s %d\n", chk->id, chk->size); memcpy((char*)ret, (char*)(byteArray->data.bytes+sizeof(heap_chunk)), byteArray->array.length- sizeof(heap_chunk)); chk = getChunk(ret); PRINTF("Created object id %d s %d\n", chk->id, chk->size); for(i = 0; i < byteArray->array.length; i++) PRINTF("%x-", byteArray->data.bytes[i]); PRINTF("\n"); }else { PRINTF("Packet not created\n"); } dj_exec_stackPushRef(VOIDP_TO_REF(ret)); // crete a new object from array }
//-------------------------------------------------------------------- // load edges from neighbors void ChunkWorld::updateEdges( ChunkObj* chunk) { if (chunk->m_blobs[0] == NULL) return; // empty cell ChunkObj* other; other = getChunk(chunk->m_originX - CHUNK_SIZE, chunk->m_originZ); if (other != NULL && other->m_blobs[0] != NULL) { for (int i = 0; i < CHUNK_COLUMN; i++) chunk->m_blobs[i]->updateXMinEdge(other->m_blobs[i]); } other = getChunk(chunk->m_originX + CHUNK_SIZE, chunk->m_originZ); if (other != NULL && other->m_blobs[0] != NULL) { for (int i = 0; i < CHUNK_COLUMN; i++) chunk->m_blobs[i]->updateXMaxEdge(other->m_blobs[i]); } other = getChunk(chunk->m_originX, chunk->m_originZ - CHUNK_SIZE); if (other != NULL && other->m_blobs[0] != NULL) { for (int i = 0; i < CHUNK_COLUMN; i++) chunk->m_blobs[i]->updateZMinEdge(other->m_blobs[i]); } other = getChunk(chunk->m_originX, chunk->m_originZ + CHUNK_SIZE); if (other != NULL && other->m_blobs[0] != NULL) { for (int i = 0; i < CHUNK_COLUMN; i++) chunk->m_blobs[i]->updateZMaxEdge(other->m_blobs[i]); } }
DsChunkPtr DsWorld::generateChunk(int x, int y) const { /*DsChunkPtr new_chunk = std::make_shared<DsChunk>(x, y, ROUGHNESS, getChunk(x - 1, y - 1), getChunk(x, y - 1), getChunk(x + 1, y), getChunk(x + 1, y + 1));*/ DsChunkPtr new_chunk = new DsChunk(x, y, ROUGHNESS, getChunk(x - 1, y), getChunk(x, y - 1), getChunk(x + 1, y), getChunk(x, y + 1)); chunk_dict->insert(std::pair <std::tuple<int, int>, DsChunkPtr>(std::tuple<int, int>(x, y), new_chunk)); return new_chunk; }
void fillWorld(World *world) { int cx, cy, cz, bx, by, bz; for (cx = 0; cx < world->size; cx++) { for (cy = 0; cy < world->size; cy++) { for (cz = 0; cz < world->size; cz++) { for (bx = 0; bx < CHUNK_SIZE; bx++) { for (by = 0; by < CHUNK_SIZE; by++) { for (bz = 0; bz < CHUNK_SIZE; bz++) { int r = (!bx|(bx==CHUNK_SIZE-1))&(!bz|(bz==CHUNK_SIZE-1)); int m = (bx + by + bz) % 2 ? -1 : (-1 << 6); if (r) { m = 0; r = 255; } if (by == 0 && cy == 0) { setBlock(getChunk(world, cx, cy, cz), bx, by, bz, (Block){1, {{255 & (r|m), 255 & m, 255 & m, 255}}}); } // } else if (((bx == 0 && cx == 0) || (bz == 0 && cz == 0)) && by == 1 && cy == 0) { // setBlock(getChunk(world, cx, cy, cz), bx, by, bz, // (Block){1, {{255 & m, 255 & m, 255 & m, 255}}}); // } } } } renderChunk(getChunk(world, cx, cy, cz)); } } } }
void MapImpl::set(int x, int y, int z, const MapCell & cell) { if (!myPruneThread.joinable()) myPruneThread.start_thread(); uint64_t hash = myBank->put(cell); std::shared_ptr<Chunk> chunk = getChunk(x, y, z); boost::unique_lock<boost::shared_mutex> guard(chunk->lock); if(!chunk->accessor) { loadChunk(chunk); } // boost::upgrade_to_unique_lock<boost::shared_mutex> lock(guard); if (hash == myBackgroundValue) chunk->accessor->setValueOff( ovdb::Coord(x % myChunkSize.x(), y % myChunkSize.y(), z % myChunkSize.z()), hash); else chunk->accessor->setValue( ovdb::Coord(x % myChunkSize.x(), y % myChunkSize.y(), z % myChunkSize.z()), hash); chunk->dirty = true; // if (!myChunks.empty() && (myAccessCounter++ % myAccessTolerance == 0)) // prune(false); }
int solidBlockInArea(World *world, int minx, int miny, int minz, int maxx, int maxy, int maxz) { int x, y, z; int bx, by, bz, cx, cy, cz; for (x = minx; x < maxx; x++) { for (y = miny; y < maxy; y++) { for (z = minz; z < maxz; z++) { bx = x & BLOCK_MASK; by = y & BLOCK_MASK; bz = z & BLOCK_MASK; cx = x >> LOG_CHUNK_SIZE; cy = y >> LOG_CHUNK_SIZE; cz = z >> LOG_CHUNK_SIZE; if (bx >= 0 && by >= 0 && bz >= 0 && bx < CHUNK_SIZE && by < CHUNK_SIZE && bz < CHUNK_SIZE && cx >= 0 && cy >= 0 && cz >= 0 && cx < world->size && cy < world->size && cz < world->size && getBlock(getChunk(world, cx, cy, cz), bx, by, bz)->active) return 1; } } } return 0; }
Block WorldCache::getBlock(const mc::BlockPos& pos, const mc::Chunk* chunk, int get) { // this can happen when we check for the bottom block shadow edges if (pos.y < 0) return Block(); mc::ChunkPos chunk_pos(pos); const mc::Chunk* mychunk = chunk; if (chunk == nullptr || chunk_pos != chunk->getPos()) mychunk = getChunk(chunk_pos); // chunk may be nullptr if (mychunk == nullptr) { return Block(); // otherwise get all required block data } else { mc::LocalBlockPos local(pos); Block block; if (get & GET_ID) block.id = mychunk->getBlockID(local); if (get & GET_DATA) block.data = mychunk->getBlockData(local); if (get & GET_BIOME) block.biome = mychunk->getBiomeAt(local); if (get & GET_BLOCK_LIGHT) block.block_light = mychunk->getBlockLight(local); if (get & GET_SKY_LIGHT) block.sky_light = mychunk->getSkyLight(local); return block; } }
static long PNGdecodeImage_getBytes(void *p, unsigned char *buffer, long count) { idatInflateData *d = (idatInflateData *)p; imageSrcPtr src = d->src; unsigned long chunkType = UNDF_CHUNK; /* while, because it's possible to have 0-length chunks! */ while (d->clen == 0) { /* unsigned long CRC = */ (void)getInt(src); getChunk(src, &chunkType, &(d->clen)); if (chunkType != IDAT_CHUNK) { return 0; } } if (d->clen <= (int)count) { count = d->clen; } count = (long)(src->getBytes(src, buffer, (int)count)); d->clen -= (int)count; return count; }
ChunkPool::~ChunkPool() { SPChunk* c; AtomicStatistics* stat = new AtomicStatistics(); while ((c = getChunk(stat)) != NULL) delete c; delete stat; delete chunkQueue; }
Selection selectBlock(World *world, vec3 position, vec3 direction, float radius) { Selection ret; ret.selected_active = ret.previous_active = 0; int x = floor(position[0]); int y = floor(position[1]); int z = floor(position[2]); float dx = direction[0]; float dy = direction[1]; float dz = direction[2]; int stepX = dx > 0 ? 1 : dx < 0 ? -1 : 0; int stepY = dy > 0 ? 1 : dy < 0 ? -1 : 0; int stepZ = dz > 0 ? 1 : dz < 0 ? -1 : 0; float tMaxX = intbound(position[0], dx); float tMaxY = intbound(position[1], dy); float tMaxZ = intbound(position[2], dz); float tDeltaX = stepX / dx; float tDeltaY = stepY / dy; float tDeltaZ = stepZ / dz; int px = -1, py = -1, pz = -1; if (dx == 0 && dy == 0 && dz == 0) return ret; while (1) { if (!(x < 0 || y < 0 || z < 0 || x >= CHUNK_SIZE * world->size || y >= CHUNK_SIZE * world->size || z >= CHUNK_SIZE * world->size)) { ret.selected_chunk_x = x >> LOG_CHUNK_SIZE; ret.selected_chunk_y = y >> LOG_CHUNK_SIZE; ret.selected_chunk_z = z >> LOG_CHUNK_SIZE; ret.selected_block_x = x & BLOCK_MASK; ret.selected_block_y = y & BLOCK_MASK; ret.selected_block_z = z & BLOCK_MASK; // now check if the block is solid if (getBlock(getChunk(world, ret.selected_chunk_x, ret.selected_chunk_y, ret.selected_chunk_z), ret.selected_block_x, ret.selected_block_y, ret.selected_block_z)->active) { ret.selected_active = 1; if (px >= 0 && py >= 0 && pz >= 0 && px < CHUNK_SIZE * world->size && py < CHUNK_SIZE * world->size && pz < CHUNK_SIZE * world->size) { ret.previous_chunk_x = px >> LOG_CHUNK_SIZE; ret.previous_chunk_y = py >> LOG_CHUNK_SIZE; ret.previous_chunk_z = pz >> LOG_CHUNK_SIZE; ret.previous_block_x = px & BLOCK_MASK; ret.previous_block_y = py & BLOCK_MASK; ret.previous_block_z = pz & BLOCK_MASK; ret.previous_active = 1; } break; }
void DsWorld::deleteChunk(int x, int y) const { auto ch = getChunk(x, y); if (ch != nullptr) { chunk_dict->erase(std::tuple<int, int>(x, y)); } delete ch; }
char* disk_cache_man::getChunk(const string& id,unsigned int& size) { boost::mutex::scoped_lock lock(cache_mut); fs::path chunkPath = getChunkPath(id); if(!fs::exists(chunkPath)) runtime_error("Specifed chunk does not exist in cache"); return getChunk(chunkPath,size); }
std::string World::serialize(const std::vector<Vector2i> &chunkIds, const std::vector<Vector2i> &positions, const std::vector<Vector2i> &sizes) { ProtocolMessage msg; WorldZone *worldZone = new WorldZone; ChunkZone *chunkZone; VectorInt *id; VectorUint *position; VectorUint *size; std::string serialized; Chunk *chunk; unsigned int x; unsigned int y; unsigned int chunkNb; unsigned int nbChunks = chunkIds.size(); for (chunkNb = 0; chunkNb < nbChunks; ++chunkNb) { if ((chunk = getChunk(chunkIds[chunkNb])) != nullptr) { chunkZone = worldZone->add_chunkzone(); if (chunkZone == nullptr) continue ; for (y = 0; y < Chunk::height; ++y) { for (x = 0; x < Chunk::width; ++x) { chunkZone->add_fgtiles(static_cast<unsigned int>(chunk->getTile(x, y))); } } } else continue ; id = new VectorInt; position = new VectorUint; size = new VectorUint; id->set_x(chunkIds[chunkNb].x); id->set_y(chunkIds[chunkNb].y); position->set_x(positions[chunkNb].x); position->set_y(positions[chunkNb].y); size->set_x(sizes[chunkNb].x); size->set_y(sizes[chunkNb].y); chunkZone->set_allocated_id(id); chunkZone->set_allocated_position(position); chunkZone->set_allocated_size(size); } msg.set_content(ProtocolMessage::CHUNKZONE); msg.set_allocated_worldzone(worldZone); msg.SerializeToString(&serialized); return serialized; }
char* disk_cache_man::getLabel(const string& id,const string& tracker,unsigned int& size) { //log_error(string("Attempting to get label ; id: ") + id + string(" tracker/peer: ") + tracker); boost::mutex::scoped_lock lock(cache_mut); string first2; fs::path labelpath = getLabelPath(id,tracker); if(!fs::exists(labelpath)) //throw runtime_error("Label doesn't exist!"); return NULL; return getChunk(labelpath,size); }
void blockInversion(bit block[block_length]){ int i; bit chunk[chunk_length]; for(i = 0; i < 4; i++) { getChunk(block , chunk , i); inverteArray(chunk , chunk_length); setChunk(block , chunk , i); } }
void IpcLogOutputter::sendBuffer() { if (m_buffer.empty() || !m_ipcServer.hasClients(m_clientType)) { return; } IpcLogLineMessage message(getChunk(kMaxSendLines)); m_sending = true; m_ipcServer.send(message, kIpcClientGui); m_sending = false; }
bool ChunkManager::setTileGID(int gid, const Vec2 & pos) { auto chunk = getChunk(pos); if (chunk) { chunk->setTileGID(3, pos - chunk->getPosition()); return true; } else { return false; } }
void onIncoming(const void* msg, size_t len) { lock_t l(_m); Head h(LOG, len); auto t = getChunk(sizeof(h) + h.len); memcpy(t->data + t->tail, &h, sizeof(h)); t->tail += sizeof(h); memcpy(t->data + t->tail, msg, len); t->tail += len; uint64_t value = 1; if (::write(_fd, &value, 8)) {} }
void onEvent(const char* msg) { auto len = strlen(msg); lock_t l(_m); Head h(EVENT, len); auto t = getChunk(sizeof(h) + h.len); memcpy(t->data + t->tail, &h, sizeof(h)); t->tail += sizeof(h); memcpy(t->data + t->tail, msg, len); t->tail += len; uint64_t value = 1; if (::write(_fd, &value, 8)) {} }
Chunk* GameWorld::getChunkFromCoords(int x, int y)const { Chunk * chosenchunk = nullptr; Vector2f position; position.x = x*ChunkSize*TileSize + 5; position.y = y*ChunkSize*TileSize + 5; chosenchunk = getChunk(position); return chosenchunk; }
/* * Duplicate a string value using the chunk allocator. * The returned string cannot be individually freed, but can only be freed * with other strings when freeChunks is called. Returns NULL on failure. */ char * chunkstrdup(const char * str) { int len; char * newStr; len = strlen(str) + 1; newStr = getChunk(len); if (newStr) memcpy(newStr, str, len); return newStr; }
void inverse_sboxLayer(bit block[block_length]){ int i; for(i = 0; i < 4; i++) { bit chunk[chunk_length]; getChunk(block , chunk , i); inverse_sbox(chunk , i); setChunk(block , chunk , i); } }
int ChunkListI::setChunk(const char *type, void *data, int size, ChunkInfos *infos) { Chunk *c; if(c=getChunk(type)) { m_chunklist.delItem(c); if(!infos) { // copy old infos into new one infos=new ChunkInfosI(c->getChunkInfos()); } delete(c); } m_chunklist.addItem(new ChunkI(type,data,size,infos)); return 1; }
gridfs_offset GridFile::write( ostream & out ) { _exists(); const int num = getNumChunks(); for ( int i=0; i<num; i++ ) { GridFSChunk c = getChunk( i ); int len; const char * data = c.data( len ); out.write( data , len ); } return getContentLength(); }
const MapCell & MapImpl::get(int x, int y, int z) const { std::shared_ptr<Chunk> chunk = getChunk(x, y, z); boost::upgrade_lock<boost::shared_mutex> guard(chunk->lock); if(!chunk->accessor) { boost::upgrade_to_unique_lock<boost::shared_mutex> lock(guard); loadChunk(chunk); } // if (myAccessCounter++ % myAccessTolerance == 0) // prune(false); const MapCell & value = myBank->get(chunk->accessor->getValue( ovdb::Coord(x % myChunkSize.x(), y % myChunkSize.y(), z % myChunkSize.z()))); return value; }
javax_virtualsense_network_Packet_byte___toByteArray(){ uint8_t i = 0; dj_object *obj = REF_TO_VOIDP(dj_exec_stackPopRef()); heap_chunk * chk = getChunk(obj); dj_int_array * ret; uint16_t length = chk->size; PRINTF("obj id is %d and array size is %d \n", chk->id, chk->size); ret = dj_int_array_create(T_BYTE, length); // data.bytes conatains | chunk struct | chk->size -sizeof(heap_chunk) bytes | memcpy(ret->data.bytes, (char*)chk, length); for(i = 0; i < ret->array.length; i++) PRINTF("%x-", ret->data.bytes[i]); PRINTF("\n"); dj_exec_stackPushRef(VOIDP_TO_REF(ret)); }
void mixingLayerMatrixMul(bit block[block_length] , bit result_chunk[chunk_length], unsigned int column){ int i; for(i = 0; i < chunk_length; i++) result_chunk[i] = 0; for(i = 0; i < 4; i++) { bit chunk[chunk_length]; getChunk(block , chunk , i); arrayMul(chunk , mixingMatrix[i][column] , primitivePoly , chunk , primitivePolyDegree); arraySum(result_chunk , chunk , result_chunk , chunk_length); } }
//------------------------------------------------------------------------------------------------------- VstIntPtr AudioEffect::dispatcher (VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt) { VstIntPtr v = 0; switch (opcode) { case effOpen: open (); break; case effClose: close (); break; case effSetProgram: if (value < numPrograms) setProgram ((VstInt32)value); break; case effGetProgram: v = getProgram (); break; case effSetProgramName: setProgramName ((char*)ptr); break; case effGetProgramName: getProgramName ((char*)ptr); break; case effGetParamLabel: getParameterLabel (index, (char*)ptr); break; case effGetParamDisplay: getParameterDisplay (index, (char*)ptr); break; case effGetParamName: getParameterName (index, (char*)ptr); break; case effSetSampleRate: setSampleRate (opt); break; case effSetBlockSize: setBlockSize ((VstInt32)value); break; case effMainsChanged: if (!value) suspend (); else resume (); break; #if !VST_FORCE_DEPRECATED case effGetVu: v = (VstIntPtr)(getVu () * 32767.); break; #endif //---Editor------------ case effEditGetRect: if (editor) v = editor->getRect ((ERect**)ptr) ? 1 : 0; break; case effEditOpen: if (editor) v = editor->open (ptr) ? 1 : 0; break; case effEditClose: if (editor) editor->close (); break; case effEditIdle: if (editor) editor->idle (); break; #if (TARGET_API_MAC_CARBON && !VST_FORCE_DEPRECATED) case effEditDraw: if (editor) editor->draw ((ERect*)ptr); break; case effEditMouse: if (editor) v = editor->mouse (index, value); break; case effEditKey: if (editor) v = editor->key (value); break; case effEditTop: if (editor) editor->top (); break; case effEditSleep: if (editor) editor->sleep (); break; #endif case DECLARE_VST_DEPRECATED (effIdentify): v = CCONST ('N', 'v', 'E', 'f'); break; //---Persistence------- case effGetChunk: v = getChunk ((void**)ptr, index ? true : false); break; case effSetChunk: v = setChunk (ptr, (VstInt32)value, index ? true : false); break; } return v; }
void ChunkManager::saveIndexFile() { File fptr; if (!fptr.open(index_file,"wb")) throw Error(i18n("Cannot open index file %1 : %2").arg(index_file).arg(fptr.errorString())); for (unsigned int i = 0;i < tor.getNumChunks();i++) { Chunk* c = getChunk(i); if (c->getStatus() != Chunk::NOT_DOWNLOADED) { NewChunkHeader hdr; hdr.index = i; fptr.write(&hdr,sizeof(NewChunkHeader)); } } savePriorityInfo(); }
//----------------------------------------------------------------------------- long AudioEffect::dispatcher(long opCode, long index, long value, void *ptr, float opt) { long v = 0; switch(opCode) { case effOpen: open(); break; case effClose: close(); break; case effSetProgram: if(value < numPrograms) setProgram(value); break; case effGetProgram: v = getProgram(); break; case effSetProgramName: setProgramName((char *)ptr); break; case effGetProgramName: getProgramName((char *)ptr); break; case effGetParamLabel: getParameterLabel(index, (char *)ptr); break; case effGetParamDisplay: getParameterDisplay(index, (char *)ptr); break; case effGetParamName: getParameterName(index, (char *)ptr); break; case effSetSampleRate: setSampleRate(opt); break; case effSetBlockSize: setBlockSize(value); break; case effMainsChanged: if(!value) suspend(); else resume(); break; case effGetVu: v = (long)(getVu() * 32767.); break; // editor case effEditGetRect: if(editor) v = editor->getRect((ERect **)ptr); break; case effEditOpen: if(editor) v = editor->open(ptr); break; case effEditClose: if(editor) editor->close(); break; case effEditIdle: if(editor) editor->idle(); break; #if MAC case effEditDraw: if(editor) editor->draw((ERect *)ptr); break; case effEditMouse: if(editor) v = editor->mouse(index, value); break; case effEditKey: if(editor) v = editor->key(value); break; case effEditTop: if(editor) editor->top(); break; case effEditSleep: if(editor) editor->sleep(); break; #endif // new case effIdentify: v = 'NvEf'; break; case effGetChunk: v = getChunk((void**)ptr, index ? true : false); break; case effSetChunk: v = setChunk(ptr, value, index ? true : false); break; } return v; }