Beispiel #1
0
static void print_vdi_list(uint32_t vid, char *name, char *tag, uint32_t snapid,
			   uint32_t flags, struct sheepdog_inode *i, void *data)
{
	int idx, is_clone = 0;
	uint64_t my_objs, cow_objs;
	char vdi_size_str[16], my_objs_str[16], cow_objs_str[16];
	time_t ti;
	struct tm tm;
	char dbuf[128];
	struct get_vdi_info *info = data;

	if (info && strcmp(name, info->name) != 0)
		return;

	ti = i->create_time >> 32;
	if (raw_output) {
		snprintf(dbuf, sizeof(dbuf), "%" PRIu64, (uint64_t) ti);
	} else {
		localtime_r(&ti, &tm);
		strftime(dbuf, sizeof(dbuf),
			 "%Y-%m-%d %H:%M", &tm);
	}

	my_objs = 0;
	cow_objs = 0;
	for (idx = 0; idx < MAX_DATA_OBJS; idx++) {
		if (!i->data_vdi_id[idx])
			continue;
		if (is_data_obj_writeable(i, idx))
			my_objs++;
		else
			cow_objs++;
	}

	size_to_str(i->vdi_size, vdi_size_str, sizeof(vdi_size_str));
	size_to_str(my_objs * SD_DATA_OBJ_SIZE, my_objs_str, sizeof(my_objs_str));
	size_to_str(cow_objs * SD_DATA_OBJ_SIZE, cow_objs_str, sizeof(cow_objs_str));

	if (i->snap_id == 1 && i->parent_vdi_id != 0)
		is_clone = 1;

	if (raw_output) {
		printf("%c ", is_current(i) ? (is_clone ? 'c' : '=') : 's');
		while (*name) {
			if (isspace(*name) || *name == '\\')
				putchar('\\');
			putchar(*name++);
		}
		printf(" %d %s %s %s %s %" PRIx32 " %d %s\n", snapid,
				vdi_size_str, my_objs_str, cow_objs_str, dbuf, vid,
				i->nr_copies, i->tag);
	} else {
		printf("%c %-8s %5d %7s %7s %7s %s  %7" PRIx32 " %5d %13s\n",
				is_current(i) ? (is_clone ? 'c' : ' ') : 's',
				name, snapid, vdi_size_str, my_objs_str, cow_objs_str,
				dbuf, vid, i->nr_copies, i->tag);
	}
}
/*
 * wield:
 *	Pull out a certain weapon
 */
void
wield(void)
{
	register struct linked_list *item ;
	register struct object *obj, *oweapon ;

	oweapon = cur_weapon ;
	if (!dropcheck(cur_weapon)) {
		cur_weapon = oweapon ;
		return ;
	}
	cur_weapon = oweapon ;
	if ((item = get_item("wield", WEAPON)) == NULL) {
		after = FALSE ;
		return ;
	}
	obj = (struct object *) ldata(item) ;
	if (obj->o_type != WEAPON) {
	    msg ("You can't wield that!");
	    return;
	}
	if (is_current(obj)) {
		after = FALSE ;
		return ;
	}
	if (terse) {
		addmsg("W") ;
	} else {
		addmsg("You are now w") ;
	}
	msg("ielding %s.", inv_name(obj, TRUE)) ;
	cur_weapon = obj ;
}
Beispiel #3
0
void CPUThread::awake()
{
	// must be called after the balanced sleep() call

	if (m_state.atomic_op([](u64& state) -> bool
	{
		if (state < CPU_STATE_MAX)
		{
			throw EXCEPTION("sleep()/awake() inconsistency");
		}

		if ((state -= CPU_STATE_MAX) < CPU_STATE_MAX)
		{
			state &= ~CPU_STATE_SLEEP;

			// notify the condition variable as well
			return true;
		}

		return false;
	}))
	{
		if (is_current()) return;

		// lock for reliable notification; the condition being checked is probably externally set
		std::lock_guard<std::mutex> lock(mutex);

		cv.notify_one();
	}
}
Beispiel #4
0
void Listener::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_ENTER_WORLD: {
			bool first_listener = get_viewport()->_listener_add(this);
			if (!get_tree()->is_node_being_edited(this) && (current || first_listener))
				make_current();
		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {
			_request_listener_update();
		} break;
		case NOTIFICATION_EXIT_WORLD: {

			if (!get_tree()->is_node_being_edited(this)) {
				if (is_current()) {
					clear_current();
					current = true; //keep it true

				} else {
					current = false;
				}
			}

			get_viewport()->_listener_remove(this);

		} break;
	}
}
Beispiel #5
0
//XXX:carefull, the dentry type is not supported by all fs
static void dir_parse(i parent_fd)
{
  ++depth;
  u8 dirents[DIRENTS_BUF_SZ];
  while(1){
    l r=getdents64(parent_fd,dirents,DIRENTS_BUF_SZ);
    if(ISERR(r)){
      PERR("ERROR(%ld):getdents error\n",r);
      exit(-1);
    }
    if(!r) break;
    l j=0;
    while(j<r){
      struct dirent64 *d=(struct dirent64*)(dirents+j);

      dout(d);

      if(d->type==DT_DIR&&!is_current(d->name)&&!is_parent(d->name)){
        i dir_fd;
        do
          dir_fd=(i)openat(parent_fd,d->name,RDONLY|NONBLOCK);
        while(dir_fd==-EINTR);
        if(ISERR(dir_fd))
          PERR("ERROR(%d):unable to open subdir:%s\n",dir_fd,d->name);
        else{
          dir_parse(dir_fd);
          l r1;
          do r1=close(dir_fd); while(r1==-EINTR);
        }
      }
      j+=d->rec_len;
    }
  }
  depth--;
}
Beispiel #6
0
bool Camera::_get(const StringName& p_name,Variant &r_ret) const {

	if (p_name=="projection") {
		r_ret= mode;
	} else if (p_name=="fov")
		r_ret= fov;
	else if (p_name=="size")
		r_ret= size;
	else if (p_name=="near")
		r_ret= near;
	else if (p_name=="far")
		r_ret= far;
	else if (p_name=="vaspect")
		r_ret= vaspect;
	else if (p_name=="current") {

		if (is_inside_scene() && get_scene()->is_editor_hint()) {
			r_ret=current;
		} else {
			r_ret=is_current();
		}
	} else if (p_name=="visible_layers") {
		r_ret=get_visible_layers();
	} else if (p_name=="environment") {
		r_ret=get_environment();
	} else
		return false;

	return true;
}
void
wield(void)
{
    THING *obj, *oweapon;
    char *sp;

    oweapon = cur_weapon;
    if (!dropcheck(cur_weapon))
    {
	cur_weapon = oweapon;
	return;
    }
    cur_weapon = oweapon;
    if ((obj = get_item("wield", WEAPON)) == NULL)
    {
bad:
	after = FALSE;
	return;
    }

    if (obj->o_type == ARMOR)
    {
	msg("you can't wield armor");
	goto bad;
    }
    if (is_current(obj))
        goto bad;

    sp = inv_name(obj, TRUE);
    cur_weapon = obj;
    if (!terse)
	addmsg("you are now ");
    msg("wielding %s (%c)", sp, obj->o_packch);
}
Beispiel #8
0
static void print_vdi_graph(uint32_t vid, char *name, char * tag, uint32_t snapid,
			    uint32_t flags, struct sheepdog_inode *i, void *data)
{
	time_t ti;
	struct tm tm;
	char dbuf[128], tbuf[128], size_str[128];

	ti = i->ctime >> 32;
	localtime_r(&ti, &tm);

	strftime(dbuf, sizeof(dbuf), "%Y-%m-%d", &tm);
	strftime(tbuf, sizeof(tbuf), "%H:%M:%S", &tm);
	size_to_str(i->vdi_size, size_str, sizeof(size_str));

	printf("  \"%x\" -> \"%x\";\n", i->parent_vdi_id, vid);
	printf("  \"%x\" [\n"
	       "    group = \"%s\",\n"
	       "    label = \"",
	       vid, name);
	printf("name: %10s\\n"
	       "tag : %10x\\n"
	       "size: %10s\\n"
	       "date: %10s\\n"
	       "time: %10s",
	       name, snapid, size_str, dbuf, tbuf);

	if (is_current(i))
		printf("\",\n    color=\"red\"\n  ];\n\n");
	else
		printf("\"\n  ];\n\n");

}
Beispiel #9
0
void SPUThread::fast_call(u32 ls_addr)
{
	if (!is_current())
	{
		throw EXCEPTION("Called from the wrong thread");
	}

	// LS:0x0: this is originally the entry point of the interrupt handler, but interrupts are not implemented
	write32(0x0, 2);

	auto old_pc = pc;
	auto old_lr = gpr[0]._u32[3];
	auto old_stack = gpr[1]._u32[3]; // only saved and restored (may be wrong)
	auto old_task = std::move(custom_task);

	pc = ls_addr;
	gpr[0]._u32[3] = 0x0;
	custom_task = nullptr;

	try
	{
		task();
	}
	catch (CPUThreadReturn)
	{
	}

	m_state &= ~CPU_STATE_RETURN;

	pc = old_pc;
	gpr[0]._u32[3] = old_lr;
	gpr[1]._u32[3] = old_stack;
	custom_task = std::move(old_task);
}
Beispiel #10
0
bool Camera::_get(const StringName& p_name,Variant &r_ret) const {

	if (p_name=="projection") {
		r_ret= mode;
	} else if (p_name=="fov" || p_name=="fovy" || p_name=="fovx")
		r_ret= fov;
	else if (p_name=="size" || p_name=="sizex" || p_name=="sizey")
		r_ret= size;
	else if (p_name=="near")
		r_ret= near;
	else if (p_name=="far")
		r_ret= far;
	else if (p_name=="keep_aspect")
		r_ret= int(keep_aspect);
	else if (p_name=="current") {

		if (is_inside_tree() && get_tree()->is_node_being_edited(this)) {
			r_ret=current;
		} else {
			r_ret=is_current();
		}
	} else if (p_name=="visible_layers") {
		r_ret=get_visible_layers();
	} else if (p_name=="h_offset") {
		r_ret=get_h_offset();
	} else if (p_name=="v_offset") {
		r_ret=get_v_offset();
	} else if (p_name=="environment") {
		r_ret=get_environment();
	} else
		return false;

	return true;
}
Beispiel #11
0
static void cal_total_vdi_size(uint32_t vid, const char *name, const char *tag,
			       uint32_t snapid, uint32_t flags,
			       const struct sheepdog_inode *i, void *data)
{
	uint64_t *size = data;

	if (is_current(i))
		*size += i->vdi_size;
}
Beispiel #12
0
void Camera2D::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_FIXED_PROCESS: {

			_update_scroll();

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {


			if (!is_fixed_processing())
				_update_scroll();

		} break;
		case NOTIFICATION_ENTER_SCENE: {

			viewport = NULL;
			Node *n=this;
			while(n){

				viewport = n->cast_to<Viewport>();
				if (viewport)
					break;
				n=n->get_parent();
			}

			canvas = get_canvas();

			RID vp = viewport->get_viewport();

			group_name = "__cameras_"+itos(vp.get_id());
			canvas_group_name ="__cameras_c"+itos(canvas.get_id());
			add_to_group(group_name);
			add_to_group(canvas_group_name);

			_update_scroll();
			first=true;


		} break;
		case NOTIFICATION_EXIT_SCENE: {

			if (is_current()) {
				if (viewport) {
					viewport->set_canvas_transform( Matrix32() );
				}
			}
			remove_from_group(group_name);
			remove_from_group(canvas_group_name);
			viewport=NULL;

		} break;
	}
}
Beispiel #13
0
void Camera::_update_camera() {

	Transform tr = get_camera_transform();
	tr.origin += tr.basis.get_axis(1) * v_offset;
	tr.origin += tr.basis.get_axis(0) * h_offset;
	VisualServer::get_singleton()->camera_set_transform(camera, tr);

	// here goes listener stuff
	//	if (viewport_ptr && is_inside_scene() && is_current())
	//		get_viewport()->_camera_transform_changed_notify();

	if (is_inside_tree() && is_current()) {
		get_viewport()->_camera_transform_changed_notify();
	}

	if (is_current() && get_world().is_valid()) {
		get_world()->_update_camera(this);
	}
}
Beispiel #14
0
static void print_vdi_tree(uint32_t vid, char *name, char * tag, uint32_t snapid,
			   uint32_t flags, struct sheepdog_inode *i, void *data)
{
	time_t ti;
	struct tm tm;
	char buf[128];

	if (is_current(i))
		strcpy(buf, "(You Are Here)");
	else {
		ti = i->ctime >> 32;
		localtime_r(&ti, &tm);

		strftime(buf, sizeof(buf),
			 "[%Y-%m-%d %H:%M]", &tm);
	}

	add_vdi_tree(name, buf, vid, i->parent_vdi_id, highlight && is_current(i));
}
Beispiel #15
0
void CPUThread::exit()
{
	if (is_current())
	{
		throw CPUThreadExit{};
	}
	else
	{
		throw EXCEPTION("Unable to exit another thread");
	}
}
Beispiel #16
0
void Camera::_update_camera() {

	Transform tr = get_camera_transform();
	VisualServer::get_singleton()->camera_set_transform( camera, tr );

// here goes listener stuff
//	if (viewport_ptr && is_inside_scene() && is_current())
//		viewport_ptr->_camera_transform_changed_notify();

	if (is_inside_scene() && is_current()) {
		if (viewport_ptr) {
			viewport_ptr->_camera_transform_changed_notify();
		}
	}

	if (is_current() && get_world().is_valid()) {
		get_world()->_update_camera(this);
	}


}
Beispiel #17
0
bool Listener::_get(const StringName &p_name, Variant &r_ret) const {

	if (p_name == "current") {
		if (is_inside_tree() && get_tree()->is_node_being_edited(this)) {
			r_ret = current;
		} else {
			r_ret = is_current();
		}
	} else
		return false;

	return true;
}
Beispiel #18
0
PPUThread::~PPUThread()
{
	if (is_current())
	{
		detach();
	}
	else
	{
		join();
	}

	close_stack();
	ppu_free_tls(m_id);
}
Beispiel #19
0
void Camera::_notification(int p_what) {

	switch(p_what) {
	
		case NOTIFICATION_ENTER_WORLD: {


			bool first_camera = get_viewport()->_camera_add(this);
			if (!get_tree()->is_node_being_edited(this) && (current || first_camera))
				make_current();


		} break;			
		case NOTIFICATION_TRANSFORM_CHANGED: {
		
			_request_camera_update();
		} break;
		case NOTIFICATION_EXIT_WORLD: {
		
			if (!get_tree()->is_node_being_edited(this)) {
				if (is_current()) {
					clear_current();
					current=true; //keep it true

				} else {
					current=false;
				}
			}

			get_viewport()->_camera_remove(this);


		} break;
		case NOTIFICATION_BECAME_CURRENT: {
			if (get_world().is_valid()) {
				get_world()->_register_camera(this);
			}
		} break;
		case NOTIFICATION_LOST_CURRENT: {
			if (get_world().is_valid()) {
				get_world()->_remove_camera(this);
			}
		} break;

	
	}

}
Beispiel #20
0
void
missile(int ydelta, int xdelta)
{
    struct object *obj;
    struct linked_list *item, *nitem;

    /*
     * Get which thing we are hurling
     */
    if ((item = get_item("throw", WEAPON)) == NULL)
	return;
    obj = (struct object *) ldata(item);
    if (!dropcheck(obj) || is_current(obj))
	return;
    /*
     * Get rid of the thing.  If it is a non-multiple item object, or
     * if it is the last thing, just drop it.  Otherwise, create a new
     * item with a count of one.
     */
    if (obj->o_count < 2)
    {
	detach(pack, item);
	inpack--;
    }
    else
    {
	obj->o_count--;
	if (obj->o_group == 0)
	    inpack--;
	nitem = (struct linked_list *) new_item(sizeof *obj);
	obj = (struct object *) ldata(nitem);
	*obj = *((struct object *) ldata(item));
	obj->o_count = 1;
	item = nitem;
    }
    do_motion(obj, ydelta, xdelta);
    /*
     * AHA! Here it has hit something.  If it is a wall or a door,
     * or if it misses (combat) the mosnter, put it on the floor
     */
    if (!ismons(CMVWINCH(mw, obj->o_pos.y, obj->o_pos.x))
	|| !hit_monster(unc(obj->o_pos), obj))
	    fall(item, TRUE);
    mvwaddrawch(cw, hero.y, hero.x, PLAYER);
}
Beispiel #21
0
void CPUThread::step()
{
	if (m_state.atomic_op([](u64& state) -> bool
	{
		const bool was_paused = (state & CPU_STATE_PAUSED) != 0;

		state |= CPU_STATE_STEP;
		state &= ~CPU_STATE_PAUSED;

		return was_paused;
	}))
	{
		if (is_current()) return;

		// lock for reliable notification (only if PAUSE was removed)
		std::lock_guard<std::mutex> lock(mutex);

		cv.notify_one();
	}
}
Beispiel #22
0
void CPUThread::stop()
{
	Emu.SendDbgCommand(DID_STOP_THREAD, this);

	if (is_current())
	{
		throw CPUThreadStop{};
	}
	else
	{
		// lock for reliable notification
		std::lock_guard<std::mutex> lock(mutex);

		m_state |= CPU_STATE_STOPPED;

		cv.notify_one();
	}

	Emu.SendDbgCommand(DID_STOPED_THREAD, this);
}
Beispiel #23
0
void PPUThread::fast_call(u32 addr, u32 rtoc)
{
	if (!is_current())
	{
		throw EXCEPTION("Called from the wrong thread");
	}

	auto old_PC = PC;
	auto old_stack = GPR[1];
	auto old_rtoc = GPR[2];
	auto old_LR = LR;
	auto old_task = std::move(custom_task);

	assert(!old_task || !custom_task);

	PC = addr;
	GPR[2] = rtoc;
	LR = Emu.GetCPUThreadStop();
	custom_task = nullptr;

	try
	{
		task();
	}
	catch (CPUThreadReturn)
	{
	}

	m_state &= ~CPU_STATE_RETURN;

	PC = old_PC;

	if (GPR[1] != old_stack) // GPR[1] shouldn't change
	{
		throw EXCEPTION("Stack inconsistency (addr=0x%x, rtoc=0x%x, SP=0x%llx, old=0x%llx)", addr, rtoc, GPR[1], old_stack);
	}

	GPR[2] = old_rtoc;
	LR = old_LR;
	custom_task = std::move(old_task);
}
void
missile(int ydelta, int xdelta)
{
    THING *obj;

    /*
     * Get which thing we are hurling
     */
    if ((obj = get_item("throw", WEAPON)) == NULL)
	return;
    if (!dropcheck(obj) || is_current(obj))
	return;
    obj = leave_pack(obj, TRUE, FALSE);
    do_motion(obj, ydelta, xdelta);
    /*
     * AHA! Here it has hit something.  If it is a wall or a door,
     * or if it misses (combat) the monster, put it on the floor
     */
    if (moat(obj->o_pos.y, obj->o_pos.x) == NULL ||
	!hit_monster(unc(obj->o_pos), obj))
	    fall(obj, TRUE);
}
Beispiel #25
0
void ARMv7Thread::fast_call(u32 addr)
{
	if (!is_current())
	{
		throw EXCEPTION("Called from the wrong thread");
	}

	auto old_PC = PC;
	auto old_stack = SP;
	auto old_LR = LR;
	auto old_task = std::move(custom_task);

	PC = addr;
	LR = Emu.GetCPUThreadStop();
	custom_task = nullptr;

	try
	{
		task();
	}
	catch (CPUThreadReturn)
	{
	}

	m_state &= ~CPU_STATE_RETURN;

	PC = old_PC;

	if (SP != old_stack) // SP shouldn't change
	{
		throw EXCEPTION("Stack inconsistency (addr=0x%x, SP=0x%x, old=0x%x)", addr, SP, old_stack);
	}

	LR = old_LR;
	custom_task = std::move(old_task);
}
void
wield(void)
{
    struct linked_list *item;
    struct object *obj, *oweapon;

    oweapon = cur_weapon;

    if (!dropcheck(cur_weapon))
    {
        cur_weapon = oweapon;
        return;
    }

    cur_weapon = oweapon;

    if ((item = get_item("wield", WEAPON)) == NULL)
    {
        after = FALSE;
        return;
    }

    obj = OBJPTR(item);

    if (is_current(obj))
    {
        after = FALSE;
        return;
    }

    wield_ok(&player, obj, TRUE);

    msg("You are now wielding %s.", inv_name(obj, LOWERCASE));

    cur_weapon = obj;
}
Beispiel #27
0
void
wield()
{
    struct linked_list *item;
    struct object *obj, *oweapon;

    oweapon = cur_weapon;
    if (!dropcheck(cur_weapon))
    {
	cur_weapon = oweapon;
	return;
    }
    cur_weapon = oweapon;
    if ((item = get_item("wield", WEAPON)) == NULL)
    {
bad:
	after = FALSE;
	return;
    }

    obj = (struct object *) ldata(item);
    if (obj->o_type == ARMOR)
    {
	msg("You can't wield armor");
	goto bad;
    }
    if (is_current(obj))
        goto bad;

    if (terse)
	addmsg("W");
    else
	addmsg("You are now w");
    msg("ielding %s", inv_name(obj, TRUE));
    cur_weapon = obj;
}
Beispiel #28
0
int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
{
	int ret, fd;
	unsigned long nr;
	static struct sheepdog_inode i;
	struct sd_req req;
	static DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
	unsigned int rlen = sizeof(vdi_inuse);

	fd = connect_to(sdhost, sdport);
	if (fd < 0) {
		fprintf(stderr, "Failed to connect to %s:%d\n", sdhost, sdport);
		ret = -1;
		goto out;
	}

	sd_init_req(&req, SD_OP_READ_VDIS);
	req.data_length = sizeof(vdi_inuse);

	ret = collie_exec_req(fd, &req, &vdi_inuse);
	if (ret < 0) {
		fprintf(stderr, "Failed to read VDIs from %s:%d\n",
			sdhost, sdport);
		close(fd);
		goto out;
	}
	close(fd);

	for (nr = 0; nr < SD_NR_VDIS; nr++) {
		uint64_t oid;
		uint32_t snapid;

		if (!test_bit(nr, vdi_inuse))
			continue;

		oid = vid_to_vdi_oid(nr);

		memset(&i, 0, sizeof(i));
		ret = sd_read_object(oid, &i, SD_INODE_HEADER_SIZE, 0, true);
		if (ret != SD_RES_SUCCESS) {
			fprintf(stderr, "Failed to read inode header\n");
			continue;
		}

		if (i.name[0] == '\0') /* this VDI has been deleted */
			continue;

		if (size > SD_INODE_HEADER_SIZE) {
			rlen = DIV_ROUND_UP(i.vdi_size, SD_DATA_OBJ_SIZE) *
				sizeof(i.data_vdi_id[0]);
			if (rlen > size - SD_INODE_HEADER_SIZE)
				rlen = size - SD_INODE_HEADER_SIZE;

			ret = sd_read_object(oid, ((char *)&i) + SD_INODE_HEADER_SIZE,
					     rlen, SD_INODE_HEADER_SIZE, true);

			if (ret != SD_RES_SUCCESS) {
				fprintf(stderr, "Failed to read inode\n");
				continue;
			}
		}

		snapid = is_current(&i) ? 0 : i.snap_id;
		func(i.vdi_id, i.name, i.tag, snapid, 0, &i, data);
	}

out:
	return ret;
}
void
missile(int ydelta, int xdelta, struct linked_list *item, struct thing *tp)
{
    struct object   *obj;
    struct linked_list  *nitem;

    if (item == NULL)   /* Get which thing we are hurling */
        return;

    obj = OBJPTR(item);

    if (!dropcheck(obj) || is_current(obj))
        return;

    /*
     * Get rid of the thing. If it is a non-multiple item object, or if
     * it is the last thing, just drop it. Otherwise, create a new item
     * with a count of one.
    */

    if (obj->o_count < 2)
    {
        if (tp->t_pack == pack)
            rem_pack(obj);
        else
            detach(tp->t_pack, item);
    }
    else
    {
        obj->o_count--;
        nitem = (struct linked_list *) new_item(sizeof *obj);
        obj = OBJPTR(nitem);
        *obj = *(OBJPTR(item));
        obj->o_count = 1;
        item = nitem;
    }

    switch (obj->o_type)
    {
        case ARTIFACT:
            has_artifact &= ~(1 << obj->o_which);
            break;

        case SCROLL:
            if (obj->o_which == S_SCARE && obj->o_flags & ISBLESSED)
                obj->o_flags &= ~ISBLESSED;
            else
                obj->o_flags |= ISCURSED;
    }

    updpack();
    obj->o_pos = do_motion(obj->o_type, ydelta, xdelta, tp);

    /*
     * AHA! Here it has hit something. If it is a wall or a door, or if
     * it misses (combat) the monster, put it on the floor
     */

    if (!hit_monster(obj->o_pos.y, obj->o_pos.x, obj, tp))
    {
        if (obj->o_type == WEAPON && obj->o_which == GRENADE)
        {
            hearmsg("BOOOM!");
            aggravate();

            if (ntraps + 1 < 2 * MAXTRAPS &&
                fallpos(obj->o_pos, &traps[ntraps].tr_pos))
            {
                mvaddch(traps[ntraps].tr_pos.y, traps[ntraps].tr_pos.x,
                    TRAPDOOR);
                traps[ntraps].tr_type = TRAPDOOR;
                traps[ntraps].tr_flags = ISFOUND;
                traps[ntraps].tr_show = TRAPDOOR;
                ntraps++;
                light(&hero);
            }
            discard(item);
        }
        else if (obj->o_flags & ISLOST)
        {
            if (obj->o_type == WEAPON)
                addmsg("The %s", weaps[obj->o_which].w_name);
            else
                addmsg(inv_name(obj, LOWERCASE));

            msg(" vanishes in a puff of greasy smoke.");
            discard(item);
        }
        else
        {
            fall(&player, item, TRUE, TRUE);

            if (obj->o_flags & CANRETURN)
                msg("You have %s.", inv_name(obj, LOWERCASE));
        }
    }
    else if (obj->o_flags & ISOWNED)
    {
        add_pack(item, NOMESSAGE);
        msg("You have %s.", inv_name(obj, LOWERCASE));
    }

    mvwaddch(cw, hero.y, hero.x, PLAYER);
}
Beispiel #30
0
void shape_cd::draw ( draw_vars& dr, stack&, QGraphicsScene& sc)
{
  shapes* prev = get_prev();
  if(prev && prev->type()== QString("shape_e") && dr.drawAsHorisontal())
  {
    return;
  }
    if ( is_current() ) dr.draw_marker ( sc );

    int nSegments = get_n_segment();

    for ( int i = 0 ; i < nSegments; ++i )
    {
        draw_point p_start = dr.get_p_otn();   //Начальная точка сегмента дуги.
        draw_point delta_p = get_delta_p ( i ) * dr.get_masht() ;
        qreal C = abs ( get_c ( i ) );   //Значение параметра кривизны.
        qreal C_sign = get_c ( i ) / C; //Знак параметра кривизны.
        dr.move_coords ( delta_p );
        draw_point p_end = dr.get_p_otn();    //Конечная точка сегмента дуги.

        if (dr.drawWhisOutPenUpMovement() && !dr.get_pero()) ;
        else if ( get_c ( i ) != 0 )
        {
            qreal D = p_start.dist ( p_end );  //Расстояние между конечными точками сегмента.
            qreal H = C * D / qreal ( 2 ) / qreal ( 127 );   //Высота сегмента.
            qreal R = D * D / ( H * qreal ( 8 ) ) + H / qreal ( 2 ); //Радиус дуги.

            qreal ang = p_start.agnle ( p_end );
            draw_point p_mid_hord = p_start.polar ( ang, D / qreal ( 2 ) );
            draw_point p_center = p_mid_hord.polar ( ang + C_sign * M_PI / qreal ( 2 ), R - H );

            draw_point p_radius ( R, R );
            qreal ang_start = draw_point::rtd ( p_center.agnle ( p_start ) );
            qreal ang_4 = draw_point::rtd ( atan2 ( H, D / qreal ( 2 ) ) );
            qreal ang_number = C_sign * ang_4 * qreal ( 4 );
            if ( is_current() )
            {
                QPen pen( QBrush
                          ( QColor ( draw_vars::s_color_cur ), Qt::SolidPattern ),
                          qreal ( draw_vars::s_width_cur ) ,
                          Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
                pen.setCosmetic ( true );
                if ( i == get_current())
                    pen.setColor(QColor ( draw_vars::s_color_9d));
                else
                    pen.setColor(QColor ( draw_vars::s_color_cur));
                {
                    QPainterPath path;
                    path.arcMoveTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start );
                    path.arcTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start , -ang_number );
                    QGraphicsPathItem *pathItem = new QGraphicsPathItem ( path );
                    pathItem->setPen ( pen );
                    sc.addItem ( pathItem );
                }
            }
            else if ( dr.get_pero() )
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_down ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_down ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );

                pen.setCosmetic ( true );
                {
                    QPainterPath path;
                    path.arcMoveTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start );
                    path.arcTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start , -ang_number );
                    QGraphicsPathItem *pathItem = new QGraphicsPathItem ( path );
                    pathItem->setPen ( pen );
                    sc.addItem ( pathItem );
                }
            }
            else
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_up ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_up ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );

                pen.setCosmetic ( true );
                {
                    QPainterPath path;
                    path.arcMoveTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start );
                    path.arcTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start , -ang_number );
                    QGraphicsPathItem *pathItem = new QGraphicsPathItem ( path );
                    pathItem->setPen ( pen );
                    sc.addItem ( pathItem );
                }
            }

        }
        else
        {
            if ( dr.get_pero() )
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_down ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_down ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
                pen.setCosmetic ( true );

                sc.addLine ( p_start.x, p_start.y, p_end.x, p_end.y, pen );
            }
            else
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_up ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_up ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
                pen.setCosmetic ( true );

                sc.addLine ( p_start.x, p_start.y, p_end.x, p_end.y, pen );
            }
        }
    }
}