Пример #1
0
void _identifySuccessors(struct grid *gd, struct node *activeNode, struct open_list *current, struct node *endNode)
{
	int endX = endNode->x;
	int endY = endNode->y;
	int *jumpPoint;
	struct neighbor_xy_list *neighbors_head = _findNeighbors(gd, activeNode);
	struct neighbor_xy_list *neighbors_current = neighbors_head;
	while (neighbors_head != (neighbors_current = neighbors_current->right)) {
		if (DEBUG) {
			if (isWalkableAt(gd, neighbors_current->x, neighbors_current->y))
				printf("Neighbor x:%d/y:%d is walkable!\n", neighbors_current->x, neighbors_current->y);
			else
				printf("Neighbor x:%d/y:%d is NOT walkable!\n", neighbors_current->x, neighbors_current->y);
		}

		jumpPoint = _jump(gd, neighbors_current->x, neighbors_current->y, activeNode->x, activeNode->y, endNode);
		if (DEBUG)
			printf("Jump point not set!\n\n");
		if (jumpPoint != NULL) {
			int jx, jy, d, ng;
			struct node *jumpNode;
			if (DEBUG)
				printf("Jump point set!\n\n");
			jx = jumpPoint[0];
			jy = jumpPoint[1];

			free(jumpPoint);
			malloc_count--; /* [ Malloc Count ] */

			jumpNode = getNodeAt(gd, jx, jy);
			if (jumpNode->closed) {
				continue;
			}

			d = euclidean(abs(jx - activeNode->x), abs(jy - activeNode->y));
			ng = activeNode->g + d;
			if (!jumpNode->opened || ng < jumpNode->g) {
				jumpNode->g = ng;
				if (!jumpNode->h)
					jumpNode->h = manhattan(abs(jx - endX), abs(jy - endY));
				/* jumpNode->h = jumpNode->h || manhattan(abs(jx - endX), abs(jy - endY)); // ASK FIDELIS !! */
				jumpNode->f = jumpNode->g + jumpNode->h;
				if (DEBUG)
					printf("Node g:%d h:%d f:%d\n", jumpNode->g, jumpNode->h, jumpNode->f);
				jumpNode->parent = activeNode;

				if (!jumpNode->opened) {
					current = ol_insert_right(current, jumpNode);
					jumpNode->opened = true;
				} else {
					ol_listsort(current->right);
				}
			}
		}
	}
	neighbor_xy_clean(neighbors_head);
}
  /**
   * Performs the branch instruction.
   *
   * The actual condition check is delegated polymorphically.
   *
   * \param memoryAccess The memory access object.
   *
   * \return The resulting program counter.
   */
  MemoryValue getValue(MemoryAccess& memoryAccess) const override {
    assert::that(validate(memoryAccess).isSuccess());
    auto destination = _children[0]->getIdentifier();
    auto programCounter = riscv::loadRegister<UnsignedWord>(memoryAccess, "pc");

    // Perform the jump. The return value of _jump() is the new program
    // counter. This has to be done before the return address is written
    // into the destination register, to allow jumps that use the same
    // register as base/destination register like jalr x1,x1,0
    auto result = _jump(programCounter, memoryAccess);

    // Store the return address (pc + 4) in the destination register
    riscv::storeRegister<UnsignedWord>(
        memoryAccess, destination, programCounter + 4);

    return riscv::convert<UnsignedWord>(result);
  }
Пример #3
0
    bool OnEvent(const SEvent& event)
    {
        if (event.EventType == irr::EET_KEY_INPUT_EVENT)
        {
            printf("Key: %d, down: %d\n", event.KeyInput.Key, event.KeyInput.PressedDown);
            switch(event.KeyInput.Key)
            {
            case KEY_SPACE:
                {
                    if(event.KeyInput.PressedDown)
                        _jump();
                }
                return true;
            case KEY_F1:
                {
                    if(event.KeyInput.PressedDown)
                    {
                        m_helpPanel->setVisible(!m_helpPanel->isVisible());
                    }
                    return true;
                }
            // adjust movement speed
#ifdef USE_IRR
            case KEY_LSHIFT:
            case KEY_SHIFT:
                {   
                    if(!m_fpsAnimator)
                        break;

                    if(event.KeyInput.PressedDown)
                    {
                        m_fpsAnimator->setMoveSpeed(m_moveSpeed * 3.f);
                    }
                    else
                    {
                        m_fpsAnimator->setMoveSpeed(m_moveSpeed);
                    }
                    return true;
                }
                break;
#endif

            // cycle render mode (normal/wireframe/pointcloud)
            case KEY_F3:
                {
                    if(event.KeyInput.PressedDown)
                    {
                        ++m_renderMode;
                        if(m_renderMode > 2)
                            m_renderMode = 0;
                        updateRenderMode(m_sceneManager->getRootSceneNode());
                        return true;
                    }                
                }
                break;

            // toggle physics debug
            case KEY_F4:
                if(!event.KeyInput.PressedDown)
                {
                    m_displayPhysicsDebug = m_displayPhysicsDebug ? false : true;
                    _enablePhysicsDebug(m_displayPhysicsDebug);
                    m_debugNode->setVisible(m_displayPhysicsDebug);
                    m_debugPanel->setVisible(m_displayPhysicsDebug);
                    return true;
                }
                break;

            case KEY_F5:
                if(event.KeyInput.PressedDown)
                {
                    _warp(m_startPos);
                    return true;
                }
                break;

            // screen shot
            case KEY_SNAPSHOT:
                {
                    if(!event.KeyInput.PressedDown) // key up
                    {
                        IImage* image = m_videoDriver->createScreenShot();
                        char buf[32];

                        sprintf(buf,"cap%.2d.png",m_capNumber++);

                        m_videoDriver->writeImageToFile(image,buf);

                        image->drop();
                    }
                    break;
                }

            // quit the app
            case KEY_ESCAPE:
                if(!event.KeyInput.PressedDown) // key up
                    m_running = false;
                return true;
            default:
                break;
            }
        }

        return _handleEvent(event);
    }
Пример #4
0
int *_jump(struct grid *gd, int x, int y, int px, int py, struct node *endNode)
{
	int dx = x - px;
	int dy = y - py;
	int *jx, *jy;
	if (DEBUG)
		printf("	_jump attempt: x:%d/y:%d px:%d/py:%d dx:%d/dy:%d\n", x, y, px, py, dx, dy);
	if (!isWalkableAt(gd, x, y)) {
		if (DEBUG)
			printf("	x:%d/y:%d is not walkable. Exiting _jump\n", x, y);
		return NULL;
	} else if (getNodeAt(gd, x, y) == endNode) {
		int *i = (int *) malloc(2 * sizeof(int));
		if (DEBUG)
			printf("	_jump(1) return value: x:%d/y:%d\n", x, y);
		malloc_count++; /* [ Malloc Count ] */
		i[0] = x;
		i[1] = y;
		return i;
	}

	if (dx != 0 && dy != 0) {
		if ((isWalkableAt(gd, (x - dx), (y + dy)) && !isWalkableAt(gd, (x - dx), y)) ||
		    (isWalkableAt(gd, (x + dx), (y - dy)) && !isWalkableAt(gd, x, (y - dy)))) {
			int *i = (int *) malloc(2 * sizeof(int));
			if (DEBUG)
				printf("	_jump(2) return value: x:%d/y:%d\n", x, y);
			malloc_count++;         /* [ Malloc Count ] */
			i[0] = x;
			i[1] = y;
			return i;
		}
	} else {
		if (dx != 0) {
			if ((isWalkableAt(gd, (x + dx), (y + 1)) && !isWalkableAt(gd, x, (y + 1))) ||
			    (isWalkableAt(gd, (x + dx), (y - 1)) && !isWalkableAt(gd, x, (y - 1)))) {
				int *i = (int *) malloc(2 * sizeof(int));
				if (DEBUG)
					printf("	_jump(3) return value: x:%d/y:%d\n", x, y);
				malloc_count++;         /* [ Malloc Count ] */
				i[0] = x;
				i[1] = y;
				return i;
			}
		} else {
			if ((isWalkableAt(gd, (x + 1), (y + dy)) && !isWalkableAt(gd, (x + 1), y)) ||
			    (isWalkableAt(gd, (x - 1), (y + dy)) && !isWalkableAt(gd, (x - 1), y))) {
				int *i = (int *) malloc(2 * sizeof(int));
				if (DEBUG)
					printf("	_jump(4) return value: x:%d/y:%d\n", x, y);
				malloc_count++;         /* [ Malloc Count ] */
				i[0] = x;
				i[1] = y;
				return i;
			}
		}
	}

	if (dx != 0 && dy != 0) {
		if (DEBUG)
			printf("	Recursive _jumping(1) with ( x:%d/y:%d px:%d/py:%d )\n", (x + dx), y, x, y);
		jx = _jump(gd, (x + dx), y, x, y, endNode);

		if (DEBUG)
			printf("	Recursive _jumping(2) with ( x:%d/y:%d px:%d/py:%d )\n", x, (y + dy), x, y);
		jy = _jump(gd, x, (y + dy), x, y, endNode);

		if (jx || jy) {
			int *i;

			if (DEBUG)
				printf("	_jump(5) return value: x:%d/y:%d\n", x, y);

			if (jx) {
				free(jx);
				malloc_count--; /* [ Malloc Count ] */
			}
			if (jy) {
				free(jy);
				malloc_count--; /* [ Malloc Count ] */
			}

			i = (int *) malloc(2 * sizeof(int));
			malloc_count++; /* [ Malloc Count ] */
			i[0] = x;
			i[1] = y;
			return i;
		}
	}

	if (isWalkableAt(gd, (x + dx), y) || isWalkableAt(gd, x, (y + dy))) {
		if (DEBUG)
			printf("	Recursive _jumping(3) with ( x:%d/y:%d px:%d/py:%d )\n", (x + dx), (y + dy), x, y);
		return _jump(gd, (x + dx), (y + dy), x, y, endNode);
	} else {
		if (DEBUG)
			printf("	Returning NULL\n");
		return NULL;
	}
}