Esempio n. 1
0
static kbool_t FuelVM_VisitIfNode(KonohaContext *kctx, KBuilder *builder, kNode *stmt, void *thunk)
{
	kNode *expr    = kNode_getFirstNode(kctx, stmt);
	Block *ThenBB  = CreateBlock(BLD(builder));
	Block *ElseBB  = CreateBlock(BLD(builder));
	Block *MergeBB = CreateBlock(BLD(builder));
	/* if */
	SUGAR VisitNode(kctx, builder, expr, thunk);
	CreateBranch(BLD(builder), FuelVM_getExpression(builder), ThenBB, ElseBB);
	{ /* then */
		IRBuilder_setBlock(BLD(builder), ThenBB);
		SUGAR VisitNode(kctx, builder, kNode_getFirstBlock(kctx, stmt), thunk);
		if(!Block_HasTerminatorInst(BLD(builder)->Current)) {
			IRBuilder_JumpTo(BLD(builder), MergeBB);
		}
	}
	{ /* else */
		IRBuilder_setBlock(BLD(builder), ElseBB);
		SUGAR VisitNode(kctx, builder, kNode_getElseBlock(kctx, stmt), thunk);
		if(!Block_HasTerminatorInst(BLD(builder)->Current)) {
			IRBuilder_JumpTo(BLD(builder), MergeBB);
		}
	}
	/* endif */
	IRBuilder_setBlock(BLD(builder), MergeBB);
	return true;
}
Esempio n. 2
0
void Building::CreateTower() {
    x_dim = 10;
    z_dim = 8;
    top_height = 0;

    transform_group tower = share<Transform>();
    transform_group a = CreatePyramid(10, randomMaterial(), CUBE);
    tower->addChild(a);

    transform_group b = CreatePillarsVertical(5, randomMaterial(), CUBE);
    tower->addChild(b);

    transform_group c = CreatePyramid(8, randomMaterial(), CYLINDER);
    tower->addChild(c);

    transform_group d = CreateBlock(7, randomMaterial(), CYLINDER);
    tower->addChild(d);
    
    transform_group d1 = CreatePillarsHorizontal(randomMaterial(), CUBE);
    tower->addChild(d1);
    transform_group d2 = CreatePillarsHorizontal(randomMaterial(), CYLINDER);
    tower->addChild(d2);
    transform_group d3 = CreateBlock(2, randomMaterial(), CYLINDER);
    tower->addChild(d3);

    transform_group e = CreatePillarsVertical(3, randomMaterial(), CYLINDER);
    tower->addChild(e);

    transform_group f = CreatePyramid(4, randomMaterial(), CUBE);
    tower->addChild(f);

    transform_group g = CreateBlock(3, randomMaterial(), CUBE);
    tower->addChild(g);
    transform_group g1 = CreatePillarsHorizontal(randomMaterial(), CYLINDER);
    tower->addChild(g1);
    transform_group g2 = CreatePillarsHorizontal(randomMaterial(), CYLINDER);
    tower->addChild(g2);

    transform_group h = CreatePyramid(15, randomMaterial(), CYLINDER);
    tower->addChild(h);

    transform_group i = CreateBlock(2, randomMaterial(), CYLINDER);
    tower->addChild(i);

    transform_group j = CreateDome(randomMaterial());
    tower->addChild(j);
//    tower->translateLocal(0, 0, -50);
    world->addChild(tower);
}
Esempio n. 3
0
/**
 * @brief Reads the given file and calls the appropriate functions in
 * the given creation interface for every entity found in the file.
 *
 * @param file Input
 *		Path and name of file to read
 * @param creationInterface
 *		Pointer to the class which takes care of the entities in the file.
 *
 * @retval true If \p file could be opened.
 * @retval false If \p file could not be opened.
 */
bool DL_Jww::in(const string& file, DL_CreationInterface* creationInterface) {
	//JWWファイル読み取り
	string ofile("");
	JWWDocument* jwdoc = new JWWDocument((std::string&)file, ofile);
	if(!jwdoc->Read())
		return false;
	//DXF変数設定
	creationInterface->setVariableString("$DWGCODEPAGE", "SJIS", 7);
	creationInterface->setVariableString("$TEXTSTYLE", "japanese", 7);
	//線分データ
	for( unsigned int i = 0; i < jwdoc->vSen.size(); i++ )
		CreateSen(creationInterface, jwdoc->vSen[i]);
	//円弧データ
	for( unsigned int i = 0; i < jwdoc->vEnko.size(); i++ )
		CreateEnko(creationInterface, jwdoc->vEnko[i]);
	//点データ
	for( unsigned int i = 0; i < jwdoc->vTen.size(); i++ )
		CreateTen(creationInterface, jwdoc->vTen[i]);
	//文字データ
	for( unsigned int i = 0; i < jwdoc->vMoji.size(); i++ )
		CreateMoji(creationInterface, jwdoc->vMoji[i]);
	//寸法
    for(unsigned int i=0 ; i < jwdoc->vSunpou.size(); i++ )
		CreateSunpou(creationInterface, jwdoc->vSunpou[i]);
	//ソリッド
    for(unsigned int i=0 ; i < jwdoc->vSolid.size(); i++ )
		CreateSolid(creationInterface, jwdoc->vSolid[i]);
	//部品
    for(unsigned int i=0 ; i < jwdoc->vBlock.size(); i++)
		CreateBlock(creationInterface, jwdoc->vBlock[i]);
	delete jwdoc;

	return true;
}
Esempio n. 4
0
void* GrMemoryPool::allocate(size_t size) {
    VALIDATE;
    size = GrSizeAlignUp(size, kAlignment);
    size += kPerAllocPad;
    if (fTail->fFreeSize < size) {
        int blockSize = size;
        blockSize = GrMax<size_t>(blockSize, fMinAllocSize);
        BlockHeader* block = CreateBlock(blockSize);

        block->fPrev = fTail;
        block->fNext = NULL;
        GrAssert(NULL == fTail->fNext);
        fTail->fNext = block;
        fTail = block;
    }
    GrAssert(fTail->fFreeSize >= size);
    intptr_t ptr = fTail->fCurrPtr;
    // We stash a pointer to the block header, just before the allocated space,
    // so that we can decrement the live count on delete in constant time.
    *reinterpret_cast<BlockHeader**>(ptr) = fTail;
    ptr += kPerAllocPad;
    fTail->fCurrPtr += size;
    fTail->fFreeSize -= size;
    fTail->fLiveCount += 1;
    GR_DEBUGCODE(++fAllocationCnt);
    VALIDATE;
    return reinterpret_cast<void*>(ptr);
}
Esempio n. 5
0
void OnSetBlock(Packet& packet) {
	auto chmgr = ChunkManager::Get();
	u8 orientation;
	u16 chunkID, blockType;
	ivec3 vxPos;

	// Assume vxPos is in bounds
	packet.Read(chunkID);
	packet.Read<ivec3>(vxPos);
	packet.Read(blockType);

	orientation = blockType & 3;
	blockType >>= 2;

	auto ch = chmgr->GetChunk(chunkID);
	if(!ch) {
		logger << "Missing chunkID " << chunkID;
		return;
	}

	if(blockType) {
		auto blk = ch->CreateBlock(vxPos, blockType);
		if(blk) blk->orientation = orientation;
		else logger << "Block create failed at " << vxPos;
	}else{
		ch->DestroyBlock(vxPos);
	}
}
Esempio n. 6
0
CM_Sys_MapGenerator::CM_Sys_MapGenerator(const int level, const int depth) : m_Map({level, 0})
{
	//深さ分だけ生成する
	for (int l_Depth = 0; l_Depth < depth; ++l_Depth)
	{
		//20回に1回の確率でアイテムを出現させる
		if (l_Depth % 20 == 0)
		{
			int randCreatePos = std::rand() % 9;
			unsigned int nextID = m_Map.m_Img_Block.nextID();
			CVector2D createPosition(200.0f + 80.0f * randCreatePos, 200.0f + 80.0f * l_Depth);

			m_Map.m_Img_Block.Add(new CM_Img_Block(++m_Map.m_Group, createPosition, std::rand() % 2));

			m_Map.m_AddList.push_back(CVector2D(randCreatePos, l_Depth));
		}

		//横幅分だけ生成する
		for (int l_Parallel = 0; l_Parallel < 9; ++l_Parallel)
		{
			//ブロックを生成する
			CreateBlock(CVector2D(static_cast<float>(l_Parallel), static_cast<float>(l_Depth)));
		}
	}
}
Esempio n. 7
0
void* GrMemoryPool::allocate(size_t size) {
    VALIDATE;
    size += kPerAllocPad;
    size = GrSizeAlignUp(size, kAlignment);
    if (fTail->fFreeSize < size) {
        size_t blockSize = size;
        blockSize = SkTMax<size_t>(blockSize, fMinAllocSize);
        BlockHeader* block = CreateBlock(blockSize);

        block->fPrev = fTail;
        block->fNext = nullptr;
        SkASSERT(nullptr == fTail->fNext);
        fTail->fNext = block;
        fTail = block;
        fSize += block->fSize;
        SkDEBUGCODE(++fAllocBlockCnt);
    }
    SkASSERT(kAssignedMarker == fTail->fBlockSentinal);
    SkASSERT(fTail->fFreeSize >= size);
    intptr_t ptr = fTail->fCurrPtr;
    // We stash a pointer to the block header, just before the allocated space,
    // so that we can decrement the live count on delete in constant time.
    AllocHeader* allocData = reinterpret_cast<AllocHeader*>(ptr);
    SkDEBUGCODE(allocData->fSentinal = kAssignedMarker);
    allocData->fHeader = fTail;
    ptr += kPerAllocPad;
    fTail->fPrevPtr = fTail->fCurrPtr;
    fTail->fCurrPtr += size;
    fTail->fFreeSize -= size;
    fTail->fLiveCount += 1;

    SkDEBUGCODE(++fAllocationCnt);
    VALIDATE;
    return reinterpret_cast<void*>(ptr);
}
Esempio n. 8
0
File: HDD.cpp Progetto: ss23/rpcs3
void vfsHDDManager::CreateHDD(const std::string& path, u64 size, u64 block_size)
{
	fs::file f(path, fom::rewrite);

	static const u64 cur_dir_block = 1;

	vfsHDD_Hdr hdr;
	CreateBlock(hdr);
	hdr.next_block = cur_dir_block;
	hdr.magic = g_hdd_magic;
	hdr.version = g_hdd_version;
	hdr.block_count = (size + block_size) / block_size;
	hdr.block_size = block_size;
	f.write(&hdr, sizeof(vfsHDD_Hdr));

	{
		vfsHDD_Entry entry;
		CreateEntry(entry);
		entry.type = vfsHDD_Entry_Dir;
		entry.data_block = hdr.next_block;
		entry.next_block = 0;

		f.seek(cur_dir_block * hdr.block_size);
		f.write(&entry, sizeof(vfsHDD_Entry));
		f.write(".", 1);
	}

	u8 null = 0;

	CHECK_ASSERTION(f.seek(hdr.block_count * hdr.block_size - sizeof(null)) != -1);
	
	f.write(&null, sizeof(null));
}
Esempio n. 9
0
static struct KVirtualCode *FuelVM_GenerateVirtualCode(KonohaContext *kctx, kMethod *mtd, kNode *block, int option)
{
	if(unlikely(AbstractMethodPtr == 0)) {
		AbstractMethodPtr = mtd->invokeKMethodFunc;
	}

	kNameSpace *ns = kNode_ns(block);
	KBuilder builderbuf = {}, *builder = &builderbuf;
	FuelIRBuilder Builder = {};
	INIT_GCSTACK();
	IRBuilder_Init(&Builder, kctx, ns);
	builder->builder = &Builder;
	builder->common.api = ns->builderApi;
	Block *EntryBlock = CreateBlock(BLD(builder));
	IRBuilder_setBlock(BLD(builder), EntryBlock);
	INode *Self = SetUpArguments(kctx, &Builder, mtd);

	SUGAR VisitNode(kctx, builder, block, NULL);

	if(!Block_HasTerminatorInst(BLD(builder)->Current)) {
		if(mtd->mn == MN_new) {
			INode *Ret = CreateReturn(BLD(builder), Self);
			INode_setType(Ret, ConvertToTypeId(kctx, mtd->typeId));
		} else {
			ktypeattr_t retTy = kMethod_GetReturnType(mtd)->typeId;
			if(retTy == KType_void) {
				CreateReturn(BLD(builder), 0);
			} else {
				enum TypeId Type = ConvertToTypeId(kctx, retTy);
				INode *Ret;
				if(KType_Is(UnboxType, retTy)) {
					SValue V; V.bits = 0;
					Ret = CreateConstant(BLD(builder), Type, V);
				} else {
					kObject *obj = KLIB Knull(kctx, KClass_(retTy));
					Ret = CreateObject(BLD(builder), Type, (void *)obj);
				}
				Ret = CreateReturn(BLD(builder), Ret);
				INode_setType(Ret, Type);
				CreateReturn(BLD(builder), 0);
			}
		}
	}
	RESET_GCSTACK();
	IMethod Mtd = {kctx, mtd, EntryBlock, ns};
	BLD(builder)->Method = &Mtd;
	bool JITCompiled = false;
	union ByteCode *code = IRBuilder_Compile(BLD(builder), &Mtd, option, &JITCompiled);
	if(mtd->invokeKMethodFunc == FuelVM_RunVirtualMachine) {
		mtd->virtualCodeApi_plus1[-1]->FreeVirtualCode(kctx, mtd->vcode_start);
	}
	KLIB kMethod_SetFunc(kctx, mtd, 0);
	if(JITCompiled) {
		KLIB kMethod_SetFunc(kctx, mtd, (KMethodFunc) code);
	}
	KFieldSet(mtd, ((kMethodVar *)mtd)->CompiledNode, block);
	IRBuilder_Exit(&Builder);
	return (struct KVirtualCode *) code;
}
Esempio n. 10
0
TerrainGenerator::TerrainGenerator()
{
	CreateBlock();

	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(glm::vec2),
		(GLvoid*)0);
}
CCBlock* CCBlockSet::AddBlock(void)
{
	CCBlock*	pcBlock;

	pcBlock = CreateBlock();
	mapcBlocks.Add(&pcBlock);
	return pcBlock;
}
Esempio n. 12
0
static void CreateCond(KonohaContext *kctx, KBuilder *builder, kNode *expr, enum ConditionalOp Op, void *thunk)
{
	kNode *LHS = kNode_At(expr, 1);
	kNode *RHS = kNode_At(expr, 2);

	Block *HeadBB  = CreateBlock(BLD(builder));
	Block *ThenBB  = CreateBlock(BLD(builder));
	Block *MergeBB = CreateBlock(BLD(builder));

	/* [CondExpr]
	 * LogicalAnd case
	 *       | goto Head
	 * Head  | let bval = LHS
	 *       | if(bval) { goto Then } else { goto Merge }
	 * Then  | bval = RHS
	 *       | goto Merge
	 * Merge | ...
	 */

	INode *Node;
	IRBuilder_JumpTo(BLD(builder), HeadBB);
	{ /* Head */
		IRBuilder_setBlock(BLD(builder), HeadBB);
		Node = CreateLocal(BLD(builder), TYPE_boolean);
		SUGAR VisitNode(kctx, builder, LHS, thunk);
		INode *Left = FuelVM_getExpression(builder);
		CreateUpdate(BLD(builder), Node, Left);

		if(Op == LogicalAnd) {
			CreateBranch(BLD(builder), Left, ThenBB, MergeBB);
		} else {
			CreateBranch(BLD(builder), Left, MergeBB, ThenBB);
		}
	}
	{ /* Then */
		IRBuilder_setBlock(BLD(builder), ThenBB);
		SUGAR VisitNode(kctx, builder, RHS, thunk);
		INode *Right = FuelVM_getExpression(builder);
		CreateUpdate(BLD(builder), Node, Right);
		IRBuilder_JumpTo(BLD(builder), MergeBB);
	}

	IRBuilder_setBlock(BLD(builder), MergeBB);
	builder->Value = Node;
}
Esempio n. 13
0
void Widget::StartGame()
{
    game_timer=startTimer(speed_ms); //开启游戏timer
    paint_timer=startTimer(refresh_ms); //开启界面刷新timer
    //产生初始下一个方块
    int block_id=rand()%7;
    CreateBlock(next_block,block_id);
    ResetBlock(); //产生方块
}
Esempio n. 14
0
File: HDD.cpp Progetto: ss23/rpcs3
void vfsHDDManager::CreateEntry(vfsHDD_Entry& entry)
{
	memset(&entry, 0, sizeof(vfsHDD_Entry));
	u64 ctime = time(nullptr);
	entry.atime = ctime;
	entry.ctime = ctime;
	entry.mtime = ctime;
	entry.access = 0666;
	CreateBlock(entry);
}
void CGameFrameWork::BuildObjects()
{
	m_pBoard = new CBoard();
	m_pBoard->Initialize();

	m_pBackBuffer = new CBitMap();
	m_pBackBuffer->LoadBmp(L"../Texture/backbuffer.bmp");

	CreateBlock();
}
Esempio n. 16
0
T* PoolAllocator<T>::New(SIZE_T N)
{
  if (N > m_pBlockChain->FreeCount)
    if (N <= m_BlockSize)
      m_pBlockChain = CreateBlock(m_BlockSize, m_pBlockChain);
    else
      m_pBlockChain = CreateBlock(N, m_pBlockChain);

  m_pBlockChain->FreeCount -= N;
  T* pObjects = m_pBlockChain->pFreePointer;
  m_pBlockChain->pFreePointer += N;

  if (Traits<T>::IsPrimitive)
    ZeroMemory(pObjects, sizeof(T)*N);
  else
    for (SIZE_T i=0; i<N; i++)
      pObjects[i] = T();

  return pObjects;
}
Esempio n. 17
0
char *SimpleHeap::Malloc(size_t aSize)
// Seems okay to return char* for convenience, since that's the type most often used.
// This could be made more memory efficient by searching old blocks for sufficient
// free space to handle <size> prior to creating a new block.  But the whole point
// of this class is that it's only called to allocate relatively small objects,
// such as the lines of text in a script file.  The length of such lines is typically
// around 80, and only rarely would exceed 1000.  Trying to find memory in old blocks
// seems like a bad trade-off compared to the performance impact of traversing a
// potentially large linked list or maintaining and traversing an array of
// "under-utilized" blocks.
{
	if (aSize < 1 || aSize > BLOCK_SIZE)
		return NULL;
	if (!sFirst) // We need at least one block to do anything, so create it.
		if (   !(sFirst = CreateBlock())   )
			return NULL;
	if (aSize > sLast->mSpaceAvailable)
		if (   !(sLast->mNextBlock = CreateBlock())   )
			return NULL;
	sMostRecentlyAllocated = sLast->mFreeMarker; // THIS IS NOW THE NEWLY ALLOCATED BLOCK FOR THE CALLER, which is 32-bit aligned because the previous call to this function (i.e. the logic below) set it up that way.
	// v1.0.40.04: Set up the NEXT chunk to be aligned on a 32-bit boundary (the first chunk in each block
	// should always be aligned since the block's address came from malloc()).  On average, this change
	// "wastes" only 1.5 bytes per chunk. In a 200 KB script of typical contents, this change requires less
	// than 8 KB of additional memory (as shown by temporarily making BLOCK_SIZE a smaller value such as 8 KB
	// for a more accurate measurement).  That cost seems well worth the following benefits:
	// 1) Solves failure of API functions like GetRawInputDeviceList() when passed a non-aligned address.
	// 2) May solve other obscure issues (past and future), which improves sanity due to not chasing bugs
	//    for hours on end that were caused solely by non-alignment.
	// 3) May slightly improve performance since aligned data is easier for the CPU to access and cache.
	size_t remainder = aSize % 4;
	size_t size_consumed = remainder ? aSize + (4 - remainder) : aSize;
	// v1.0.45: The following can't happen when BLOCK_SIZE is a multiple of 4, so it's commented out:
	//if (size_consumed > sLast->mSpaceAvailable) // For maintainability, don't allow mFreeMarker to go out of bounds or
	//	size_consumed = sLast->mSpaceAvailable; // mSpaceAvailable to go negative (which it can't due to be unsigned).
	sLast->mFreeMarker += size_consumed;
	sLast->mSpaceAvailable -= size_consumed;
	return sMostRecentlyAllocated;
}
Esempio n. 18
0
GrMemoryPool::GrMemoryPool(size_t preallocSize, size_t minAllocSize) {
    GR_DEBUGCODE(fAllocationCnt = 0);

    minAllocSize = GrMax<size_t>(minAllocSize, 1 << 10);
    fMinAllocSize = GrSizeAlignUp(minAllocSize + kPerAllocPad, kAlignment),
    fPreallocSize = GrSizeAlignUp(preallocSize + kPerAllocPad, kAlignment);
    fPreallocSize = GrMax(fPreallocSize, fMinAllocSize);

    fHead = CreateBlock(fPreallocSize);
    fTail = fHead;
    fHead->fNext = NULL;
    fHead->fPrev = NULL;
    VALIDATE;
};
Esempio n. 19
0
// 프레임워크 함수
void Init()
{
	// Stage 초기화
	Stage.level = 0;

	// Board 초기화
	Board.topY = 4;
	Board.bottomY = Board.topY + Board.Height;
	Board.leftX = 8;
	Board.rightX = Board.leftX + Board.Width;

	// Portal 초기화
	// 상
	Portal[0].X = 35;
	Portal[0].Y = 6;
	// 우
	Portal[1].X = 70;
	Portal[1].Y = 10;
	// 하
	Portal[2].X = 35;
	Portal[2].Y = 18;
	// 좌
	Portal[3].X = 10;
	Portal[3].Y = 10;

	for (int i = 0; i < 4; i++)
	{
		Portal[i].IsEnable = false; // 모든 Portal 비활성화
	}

	// Start, Goal 지점 초기화
	Goal.X = 70;
	Goal.Y = 18;
	SetStartGoal();

	// Map 초기화
	MapIndex = StartP.whereMap;
	CreateBlock(MapIndex);


	// Player 초기화
	Player.X = PlayerFirstX;
	Player.Y = PlayerFirstY;
	Player.Life = 15;
	Player.Direction = M_RIGHT;
	Player.OldTime = clock();
	Player.IsReady = 1;
	Player.MoveTime = 170;
}
Esempio n. 20
0
void MapLayer::onEnter()
{
	m_moveStartMousePos	= Point( 0.0f, 0.0f );
	m_moveStartLayerPos	= Point( 0.0f, 0.0f );

//	this->setColor( Color3B( 255, 0, 0 ));
	// 들어왔니?

	for ( int y=1;y<10;y++)
	{
		for ( int x=1;x<10;x++)
		{
			CreateBlock( Point( x * 50, y * 50 ));
		}	
	}
}
Esempio n. 21
0
T* PoolAllocator<T>::New()
{
  if (m_pBlockChain->FreeCount < 1)
    m_pBlockChain = CreateBlock(m_BlockSize, m_pBlockChain);

  m_pBlockChain->FreeCount--;
  T* pObject = m_pBlockChain->pFreePointer;
  m_pBlockChain->pFreePointer++;

  if (Traits<T>::IsPrimitive)
    ZeroMemory(pObject, sizeof(T));
  else
    *pObject = T();

  return pObject;
}
Esempio n. 22
0
GrMemoryPool::GrMemoryPool(size_t preallocSize, size_t minAllocSize) {
    SkDEBUGCODE(fAllocationCnt = 0);
    SkDEBUGCODE(fAllocBlockCnt = 0);

    minAllocSize = SkTMax<size_t>(minAllocSize, 1 << 10);
    fMinAllocSize = GrSizeAlignUp(minAllocSize + kPerAllocPad, kAlignment);
    fPreallocSize = GrSizeAlignUp(preallocSize + kPerAllocPad, kAlignment);
    fPreallocSize = SkTMax(fPreallocSize, fMinAllocSize);
    fSize = 0;

    fHead = CreateBlock(fPreallocSize);
    fTail = fHead;
    fHead->fNext = nullptr;
    fHead->fPrev = nullptr;
    VALIDATE;
};
void Stage_001::InitializeWorld()
{
    for (int i = 0; i < WIDTH; i++) {
        for (int j = 0; j < HEIGHT; j++) {
            int mapChip = map[j][i];
            switch (mapChip) {
                case 1:
                    CreateBlock(CPoint((float)i * SPRITE_SIZE, (float)j * SPRITE_SIZE));
                    break;
                    
                default:
                    break;
            }
        }
    }
}
Esempio n. 24
0
void Widget::ResetBlock()
{
    //产生当前方块
    block_cpy(cur_block,next_block);
    GetBorder(cur_block,cur_border);

    //产生下一个方块
    int block_id=rand()%7;
    CreateBlock(next_block,block_id);

    //设置初始方块坐标,以方块左上角为锚点
    block_point start_point;
    start_point.pos_x=AREA_COL/2-2;
    start_point.pos_y=0;
    block_pos=start_point;
}
Esempio n. 25
0
void OnChunkDownload(Packet& p) {
	u16 chunkID, offset;
	u8 size;

	p.Read(chunkID);
	p.Read(offset);
	p.Read(size);

	auto chmgr = ChunkManager::Get();
	auto ch = chmgr->GetChunk(chunkID);
	if(!ch) {
		logger << "Downloading chunk that doesn't exist";
		return;
	}

	u8 w = ch->width;
	u8 h = ch->height;
	u8 d = ch->depth;

	u8 x, y, z;
	z = offset % d;
	y = (offset / d) % h;
	x = (offset / d / h) % w;

	for(u8 i = 0; i < size; i++) {
		u16 blockType;
		p.Read(blockType);

		u8 orientation = blockType&3;
		blockType >>= 2;

		auto blk = ch->CreateBlock(ivec3{x,y,z}, blockType);
		if(blk) blk->orientation = orientation;

		if(++z >= d) {
			if(++y >= h) {
				++x; 
				y = 0;
			}
			z = 0;
		}
	}
}
Esempio n. 26
0
void Draw_Dxf::addBlock(const DL_BlockData& data)
{
    assert(_isBlockOpen == false && "블록이 열려있는데 또 addblock");

    RGBA color = RGBA(150,150,150);
    Block* p;

    _isBlockOpen = true;

    TCHAR* lpszBlockName = String2TCHAR(data.name);
    p = CreateBlock(_painter, lpszBlockName, data.flags, (FLOAT)data.bpx, (FLOAT)data.bpy);

    _block = p;

    INT32 clValue = attributes.getColor();
    if(clValue != 256) color = CL2RGBA(clValue);
    p->setLineColor(color);

}
Esempio n. 27
0
static kbool_t FuelVM_VisitBlockNode(KonohaContext *kctx, KBuilder *builder, kNode *block, void *thunk)
{
	unsigned size = ARRAY_size(BLD(builder)->Stack);
	Block *NewBlock = CreateBlock(BLD(builder));
	IRBuilder_JumpTo(BLD(builder), NewBlock);
	IRBuilder_setBlock(BLD(builder), NewBlock);
	size_t i;
	for(i = 0; i < kNode_GetNodeListSize(kctx, block); i++) {
		kNode *stmt = block->NodeList->NodeItems[i];
		builder->common.uline = kNode_uline(stmt);
		if(!SUGAR VisitNode(kctx, builder, stmt, thunk))
			break;
	}
	ARRAY_size(BLD(builder)->Stack) = size;
	if(builder->Value) {
		INode *Node = FuelVM_getExpression(builder);
		builder->Value = Node;
	}
	return true;
}
Esempio n. 28
0
int     TetrisPlay(int param)
{
    static int flag = 0;
    if(!flag){
        flag = 1;
        InitialMatrix();
        CreateBlock(&curBlock);

        // Create next block
        CreateBlock(&nextBlock);
        GetCurrentLine(curBlock.y);
        DisplayScoreLevel();
    }

    //while(1)
    {
        int key;
        TetrisAction action;
        DebugDump();

        // Check valid
        if(!CheckBlock(&curBlock,TA_None)){
            // Game over
            printf("Game over!\n");
        }

        key = GetKey();
        switch(key){
            case KEY_LEFT:
                action = TA_Left;
                score++;
                break;
            case KEY_RIGHT:
                action = TA_Right;
                score+=10;
                break;
            case KEY_UP:
                action = TA_Rotate;
                score+=100;
                break;
            case KEY_DOWN:
                action = TA_Down;
                score+=1000;
                break;
            case KEY_PAUSE:
                break;
            default:
                action = TA_Down;
                break;
        }
        if(CheckBlock(&curBlock,action)){
            MoveBlock(&curBlock,action);
        }else if(action == TA_Down){
            ScoreUp(DropBlock(&curBlock));
            CopyBlock(&curBlock,&nextBlock);
            CreateBlock(&nextBlock);
            GetCurrentLine(curBlock.y);
        }
    }
    return 0;
}
Esempio n. 29
0
void CM_Sys_MapGenerator::CreateBlock(CVector2D start, const int back)
{
	//座標がかぶっていればその場で終了
	if (PositionCollision(start) || start.x < 0.0f || 8.0f < start.x || start.y < 0.0f) return;

	//グループをずらす
	if (back == -1) m_Map.m_Group++;

	//ブロックの生成
	unsigned int nextID = m_Map.m_Img_Block.nextID();
	CVector2D createPosition(200.0f + 80.0f * start.x, 200.0f + 80.0f * start.y);
	m_Map.m_Img_Block.Add(new CM_Img_Block(m_Map.m_Group, createPosition));
	m_Map.m_AddList.push_back(start);

	//接続部を設定する
	switch (back)
	{
	case 0: //上
		m_Map.m_Img_Block(nextID).m_Down = 1;
		break;

	case 1: //下
		m_Map.m_Img_Block(nextID).m_Up = 1;
		break;

	case 2: //左
		m_Map.m_Img_Block(nextID).m_Right = 1;
		break;

	case 3: //右
		m_Map.m_Img_Block(nextID).m_Left = 1;
		break;
	}

	//20%の確率でブロックの周囲にブロックが生成される
	if (m_Map.m_Img_Block(nextID).m_Up == -1 && std::rand() % 5 == 0)
	{
		CreateBlock(start + CVector2D(0, -1), 0);
		m_Map.m_Img_Block(nextID).m_Up = 1;
	}
	else m_Map.m_Img_Block(nextID).m_Up = 0;

	if (m_Map.m_Img_Block(nextID).m_Down == -1 && std::rand() % 5 == 0)
	{
		CreateBlock(start + CVector2D(0, 1), 1);
		m_Map.m_Img_Block(nextID).m_Down = 1;
	}
	else m_Map.m_Img_Block(nextID).m_Down = 0;

	if (m_Map.m_Img_Block(nextID).m_Left == -1 && std::rand() % 5 == 0)
	{
		CreateBlock(start + CVector2D(-1, 0), 2);
		m_Map.m_Img_Block(nextID).m_Left = 1;
	}
	else m_Map.m_Img_Block(nextID).m_Left = 0;

	if (m_Map.m_Img_Block(nextID).m_Right == -1 && std::rand() % 5 == 0)
	{
		CreateBlock(start + CVector2D(1, 0), 3);
		m_Map.m_Img_Block(nextID).m_Right = 1;
	}
	else m_Map.m_Img_Block(nextID).m_Right = 0;
}
void CGameFrameWork::AnimateObjects()
{
	if (m_bMove && m_vecBlock.size() < 16)
	{
		MoveBlock();

		int cnt = 0;

		for (auto p = m_vecBlock.cbegin(); p != m_vecBlock.cend(); ++p)
			if (dynamic_cast<CBlock*>(*p)->GetBlockState() == BLOCK_MOVE)
				++cnt;

		if (0 == cnt)
		{
			m_bMove = false;

			///////////////////////////////////////////////////////
			if (!m_bReplay)
			{
				CreateBlock();

				if (m_bRecord)
					m_vecRecord.push_back(RecordData(elapsedTime.count(), m_eKeyDir, m_NewBlockPos));
			}

			else
				CreateBlock(m_vecRecord[m_nReplayCnt++].newBlockPos);
			///////////////////////////////////////////////////////


			for (auto p = m_vecBlock.begin(); p != m_vecBlock.end();)
			{
				if (dynamic_cast<CBlock*>(*p)->GetBlockInfo().addCheck == 1)
				{
					SAFE_DELETE(*p);
					p = m_vecBlock.erase(p);

					continue;
				}

				else if (dynamic_cast<CBlock*>(*p)->GetBlockInfo().addCheck == 2)
				{
					int val = dynamic_cast<CBlock*>(*p)->GetBlockInfo().value;

					dynamic_cast<CBlock*>(*p)->SetBlockValue(val * 2);
					dynamic_cast<CBlock*>(*p)->SetBlockBmp(val * 2);

					dynamic_cast<CBlock*>(*p)->SetBlockAddCheck(0);

					m_nScore += val * 2;
				}

				++p;
			}
		}
	}

	for (auto p = m_vecBlock.begin(); p != m_vecBlock.end(); ++p)
	{
		int idx = dynamic_cast<CBlock*>(*p)->GetBlockInfo().index;

		Point2D pt = dynamic_cast<CBoard*>(m_pBoard)->GetTile()[idx]->pos;

		if (pt.x != dynamic_cast<CBlock*>(*p)->GetBlockInfo().pos.x ||
			pt.y != dynamic_cast<CBlock*>(*p)->GetBlockInfo().pos.y)
		{
			dynamic_cast<CBlock*>(*p)->Move();
		}

		else
			dynamic_cast<CBlock*>(*p)->SetBlockState(BLOCK_STOP);
	}
}