コード例 #1
0
ファイル: trace.c プロジェクト: UIKit0/openlase-1
static void find_edges_thresh(OLTraceCtx *ctx, uint8_t *src, unsigned int stride)
{
	unsigned int thresh = ctx->p.threshold;
	icoord x, y, w, h;
	w = ctx->p.width;
	h = ctx->p.height;

	for (y=2; y<h-2; y++) {
		for (x=2; x<w-2;x++) {
			int idx = y*stride+x;
			int oidx = y*w+x;
			if (src[idx] > thresh && (!(src[idx-stride] > thresh)
			                         || !(src[idx-1] > thresh))) {
				ctx->tracebuf[oidx] = 0xFFFF;
				add_startpoint(ctx, x, y);
#ifdef DEBUG
				dbg[oidx][0] = 64;
				dbg[oidx][1] = 64;
				dbg[oidx][2] = 64;
#endif
			}
			if (src[idx] <= thresh && (!(src[idx-stride] <= thresh)
			                         || !(src[idx-1] <= thresh))) {
				ctx->tracebuf[oidx] = 0xFFFF;
				add_startpoint(ctx, x, y);
#ifdef DEBUG
				dbg[oidx][0] = 64;
				dbg[oidx][1] = 64;
				dbg[oidx][2] = 64;
#endif
			}
		}
	}
}
コード例 #2
0
ファイル: MapLoader.cpp プロジェクト: tinchou/bluesjackrabbit
void MapLoader::load_level() {
  Logger::info("Cargando nivel");

  xmlpp::Node *visible_layer = (*level_)->get_first_child("visible-object-layer");
  const xmlpp::Node::NodeList &rectangles = visible_layer->get_children("rectangle");
  for (std::list<xmlpp::Node *>::const_iterator it = rectangles.begin();
       it != rectangles.end(); ++it) {
    // Lo agrega al engine
    add_floor(*it);
  }

  xmlpp::Node *control_layer = (*level_)->get_first_child("control-object-layer");
  const xmlpp::Node::NodeList &startpoints = control_layer->get_children("startpoint");
  clean_start_points();
  for (std::list<xmlpp::Node *>::const_iterator it = startpoints.begin();
       it != startpoints.end(); ++it) {
    // LO AGREGA EN EL MAP LOADER!!! SE NECESITA LIMPIAR ESTO!!!
    add_startpoint(*it);
  }

  const xmlpp::Node::NodeList &spawnpoints = control_layer->get_children("spawnpoint");
  for (std::list<xmlpp::Node *>::const_iterator it = spawnpoints.begin();
       it != spawnpoints.end(); ++it) {
    // Lo agrega al engine
    add_spawnpoint(*it);
  }

  const xmlpp::Node::NodeList &goals = control_layer->get_children("goal");
  for (std::list<xmlpp::Node *>::const_iterator it = goals.begin();
       it != goals.end(); ++it) {
    // Lo agrega al engine
    add_goal(*it);
  }
}
コード例 #3
0
Level* LevelLoader::load_level(const std::string& level_file_name) {
  parser_.parse_file(level_file_name);
  xmlpp::Node* level_node = parser_.get_document()->get_root_node();
  level_ = new Level(
    level_node->eval_to_string("@title"),
    static_cast<int>(level_node->eval_to_number("@width")),
    static_cast<int>(level_node->eval_to_number("@height")),
    static_cast<int>(level_node->eval_to_number("@players_size")));

  xmlpp::Node *visible_layer = (level_node)->get_first_child("visible-object-layer");
  const xmlpp::Node::NodeList &rectangles = visible_layer->get_children("rectangle");
  for (std::list<xmlpp::Node *>::const_iterator it = rectangles.begin();
       it != rectangles.end(); ++it) {
    add_floor(*it);
  }

  xmlpp::Node *control_layer = (level_node)->get_first_child("control-object-layer");
  const xmlpp::Node::NodeList &startpoints = control_layer->get_children("startpoint");
  for (std::list<xmlpp::Node *>::const_iterator it = startpoints.begin();
       it != startpoints.end(); ++it) {
    add_startpoint(*it);
  }

  const xmlpp::Node::NodeList &spawnpoints = control_layer->get_children("spawnpoint");
  for (std::list<xmlpp::Node *>::const_iterator it = spawnpoints.begin();
       it != spawnpoints.end(); ++it) {
    add_spawnpoint(*it);
  }

  const xmlpp::Node::NodeList &goals = control_layer->get_children("goal");
  for (std::list<xmlpp::Node *>::const_iterator it = goals.begin();
       it != goals.end(); ++it) {
    add_goal(*it);
  }

  return level_;
}
コード例 #4
0
ファイル: trace.c プロジェクト: UIKit0/openlase-1
static void find_edges_canny(OLTraceCtx *ctx, uint8_t *src, unsigned int stride)
{
	icoord x, y;
	
	unsigned int high_t = ctx->p.threshold;
	unsigned int low_t = ctx->p.threshold2;
	if (low_t == 0)
		low_t = high_t;
	if (low_t > high_t) {
		unsigned int tmp = low_t;
		low_t = high_t;
		high_t = tmp;
	}
	
	if (src != ctx->sibuf) {
		uint8_t *p = ctx->sibuf + ctx->aw;
		for (y = 0; y < ctx->p.height; y++) {
			memcpy(p, src, ctx->p.width);
			src += stride;
			p += ctx->aw;
		}
	}

	perform_sobel(ctx, ol_sobel_sse2_gx_v, ol_sobel_sse2_gx_h, ctx->sxbuf);
	perform_sobel(ctx, ol_sobel_sse2_gy_v, ol_sobel_sse2_gy_h, ctx->sybuf);

	uint32_t *pm = ctx->smbuf;
	int16_t *px = ctx->sxbuf;
	int16_t *py = ctx->sybuf;
	unsigned int count = ctx->aw * ctx->p.height;

	while (count--) {
		*pm++ = ABS(*px) + ABS(*py);
		px++;
		py++;
	}

#define TAN45 0.41421356
#define ITAN45 ((int32_t)(TAN45*0x10000))

	int s = ctx->aw;

	for (y = 2; y < (ctx->p.height-2); y++) {
		uint16_t *pt = ctx->tracebuf + y*ctx->p.width + 2;
		px = ctx->sxbuf + y*ctx->aw + 2;
		py = ctx->sybuf + y*ctx->aw + 2;
		pm = ctx->smbuf + y*ctx->aw + 2;
		for (x = 2; x < (ctx->p.width-2); x++) {
			uint32_t gm = *pm;
			if (gm > low_t)  {
				int16_t gx = *px;
				int16_t gy = *py;
				int16_t sign = gx ^ gy;
				gx = ABS(gx);
				gy = ABS(gy);
				int32_t kgy = ITAN45*gy;
				if ((gx<<16) < kgy) {
					// horizontal edge [-]
					if (gm > pm[-s] && gm > pm[s]) {
						*pt = 0xffff;
						if (gm > high_t)
							add_startpoint(ctx, x, y);
					}
				} else if ((gx<<16) > (kgy+(gy<<17))) {
					// vertical edge [|]
					if (gm > pm[-1] && gm > pm[1]) {
						*pt = 0xffff;
						if (gm > high_t)
							add_startpoint(ctx, x, y);
					}
				} else if (sign < 0) {
					// diagonal edge [\]
					if (gm > pm[1-s] && gm > pm[s-1]) {
						*pt = 0xffff;
						if (gm > high_t)
							add_startpoint(ctx, x, y);
					}
				} else {
					// diagonal edge [/]
					if (gm > pm[-1-s] && gm > pm[s+1]) {
						*pt = 0xffff;
						if (gm > high_t)
							add_startpoint(ctx, x, y);
					}
				}
			}
			px++;
			py++;
			pm++;
			pt++;
		}
	}
}