示例#1
0
static void recurse(AnimObj const& animObj, std::vector<std::future<void>>& futures)
{
    std::unique_ptr<AnimObj::Geom> const& geomPtr = animObj.geom_;
    if (geomPtr)
    {
        std::unique_ptr<AnimObj::Geom::NormalData>& normalDataPtr = geomPtr->normalData_;
        if (normalDataPtr && normalDataPtr->normals_)
        {
            futures.emplace_back(std::async(std::launch::async, optimize, std::ref(*normalDataPtr)));
        }
    }
    else
    {
        AnimObj::AnimData const& animPtr = animObj.anims_;
        if (!animPtr)
        {
            return;
        }
        for (unique_ptr<AnimObj> const& childAnimPtr : *animPtr)
        {
            recurse(*childAnimPtr, futures);
        }
    }
}
示例#2
0
void Evolver::recurse(int &count, const Vector3 &point, const Vector3 &offset, int depth, float size)
{
  for (int i = start; i<end; i++)
  {
    Vector3 pos;
#if defined(SIMPLE_BEND)
    pos = point - bends[i];
    float times = bends[i].magnitudeSquared() / pos.magnitudeSquared();
    pos *= times;
    size *= times;
    pos += bends[i];
#else
    // keep the radius 2 circle where it is
    pos = point - bends[i];
    pos *= 1.0f / pos.magnitudeSquared();
    float near = 1.0f/(mags[i] + 2.0f);
    float far = 1.0f/(mags[i] - 2.0f);
    float avg = (near+far)*0.5f;
    float scale = 4.0 / (far - near);
    pos += bends[i] * avg / mags[i];
    pos *= scale;
#endif
    pos = (shifts[i] + pos - (2.0 * flips[i] * pos.dot(flips[i]))) * scale + offset;
    size *= scale;
    float dist2 = (pos - thresh1).magnitudeSquared() + (pos - thresh2).magnitudeSquared();
    if (dist2 < threshold)
      continue;
    if (depth==0) //size > 15000.0f || depth == -20)
    {
      count++;
      finalPoint = pos;
    }
    else
      recurse(count, pos, offset, depth - 1, size);
  }
}
示例#3
0
    template<typename F> void tree(const F& f, const ChunkState& chunkState)
    {
        const std::size_t coldDepth(m_structure.coldDepthBegin());

        if (chunkState.depth() < coldDepth)
        {
            auto next([this, &f](const ChunkState& chunkState, bool exists)
            {
                if (exists) tree(f, chunkState);
            });

            recurse(next, chunkState);
        }
        else if (chunkState.depth() == coldDepth)
        {
            Branch branch(chunkState.chunkId(), coldDepth);
            buildBranch(branch.node(), chunkState);
            f(branch);
        }
        else
        {
            throw std::runtime_error("Invalid nominal chunk depth");
        }
    }
示例#4
0
float sun_lightmap::recurse(const ray_bundle& r, float ray_power,
                            const world_coordinates& blk,
                            world_lightmap_access& data, bool first) const
{
    float temp(0.0f);
    bool should_recurse(true);
    for (auto& voxel : r.trunk) {
        auto type(data[blk + voxel].type);

        // If the very first block we traverse is a custom block, we
        // skip it.
        if (first) {
            first = false;
            if (material_prop[type].is_custom_block())
                continue;
        }

        temp += opacity(type);
        if (temp >= 1.0f) {
            should_recurse = false;
            break;
        }
    }

    ray_power -= std::min(temp, 1.0f) * r.weight;

    if (ray_power <= 0.01)
        return 0.0;

    if (should_recurse) {
        for (auto& s : r.branches)
            ray_power = recurse(s, ray_power, blk, data, first);
    }

    return ray_power;
}
示例#5
0
void overflow_thread_t::recurse(unsigned overflow, char *sp0, char *last)
{
        /* XXX This is supposed to be a huge stack allocation, don't
           get rid of it */
        char    on_stack[overflowFrameSize];
        memset(on_stack, '\0', overflowFrameSize);

        last = last;    /* create variable use so compilers don't complain */

        int     i;

        i = on_stack[0];        // save it from the optimizer

        /* make sure the context switch checks can catch it */
        for (i = 0; i < 10; i++)
                yield();

        ptrdiff_t       depth = (char*) sp0 - on_stack;
        if (depth < 0)
                depth = -depth;
        if (verbose) {
            OUT << "Recurse to " << depth << endl << flush;
            FLUSHOUT;
        }

        if ((unsigned)depth < overflow) {
                bool    ok = isStackFrameOK(overflowFrameSize);
                if (!ok) {
                        OUT << "will_overflow says yeah!" << endl;
                        FLUSHOUT;
                        return;
                }

                recurse(overflow, sp0, on_stack);
        }
}
示例#6
0
void recurse(int temp, bool *local_sense)
{
#if DEBUG
	printf("TEMP = %d\n",temp);
#endif
	if(temp >= N-1)
	{
		return;
	}	
	else
	{
		#pragma omp critical
		{
			count[temp]--;
		}
		if(count[temp] == 0)
		{
			recurse(temp/2 + N/2,local_sense);
			lock_sense[temp] = *local_sense;
		}
		else
		{
#if DEBUG
			printf("Spinning in thread %d\n",2*(temp-N/2));	
#endif
			while(lock_sense[temp] != *local_sense);
			
#if DEBUG
			printf("lock_Sense[%d] unlocked!!\n",temp);
#endif
		}
		//printf("Leaving thread %d!\n",temp);		
		
	}
//	lock_sense[temp]
}
示例#7
0
 vector<vector<int>> permuteUnique(vector<int>& nums) {
     vector<vector<int>> result;
     recurse(&nums, &result, 0);
     return result;
 }
示例#8
0
int jsui_widget_list		
	(int msg, void * vjdr, JSUI_DIALOG * d, int c)
{
    PEN * newpen;
    int in_container = 0;
    JSUI_DIALOG_RUNNING * jdr = (JSUI_DIALOG_RUNNING *)vjdr;
    int (*proc)(JSUI_DIALOG *, int, int, int, char *);
    int (*recurse)(int, void *, JSUI_DIALOG *, int); 
    int ret = JSUI_R_O_K;
    int voffs = 0;
    int ccc = 0;
    int argc;
    char ** textlist = NULL;

    recurse = d->proc;

    if ( (jdr->mx >= d->x) && (jdr->mx < d->x+d->w) &&
         (jdr->my >= d->y) && (jdr->my < d->y+d->h) )
	in_container = 1;

    switch(msg)
    {
    case (JSUI_MSG_IDLE):
    case (JSUI_MSG_RDRAG):
    case (JSUI_MSG_LDRAG):
    case (JSUI_MSG_MOUSEMOVE):
	if (in_container)
	{
	    int sd1 = d->d1;
	    int sd2 = d->d2;

	    // d1 = selected item
	    // d2 = scroll position
	    if(jdr->my < 2) d->d1 = d->d2-1;

	    if(jdr->mx > d->w - 15)  d->d1 = -1;

	    d->d1 = d->d2 + (jdr->my -2 -7) / 15;

	    if ( (d->d1 != sd1) || (d->d2 != sd2) )
	    {
		recurse(JSUI_MSG_DRAW, vjdr, d, c);
	    }
	}
	break;

    case (JSUI_MSG_RPRESS):
    case (JSUI_MSG_RRELEASE):
    case (JSUI_MSG_LPRESS):
    case (JSUI_MSG_LRELEASE):
	if (d->dp && d->dp3)
	{
	    proc = (int (*)(JSUI_DIALOG*, int, int, int, char *))d->dp3;
	    textlist = (char **) d->dp;
	    ret = proc(d, jdr->focus_obj, msg, d->d1, textlist[d->d1]);
	}
	break;


    case (JSUI_MSG_TIMETICK):
	break;

    case (JSUI_MSG_GOTFOCUS):
	recurse(JSUI_MSG_DRAW, vjdr, d, c);
	break;

    case (JSUI_MSG_LOSTFOCUS):
	recurse(JSUI_MSG_DRAW, vjdr, d, c);
	break;

    case (JSUI_MSG_DRAW):
	if (!jdr) return JSUI_R_O_K;

	primitive_3d_rect_down(jdr->buffer,
	    jdr->vbx + d->x, jdr->vby + d->y, 
	    jdr->vbx + d->x + d->w-1,
	    jdr->vby + d->y + d->h-1,
	    JSUI_C_BG);

	// up "button"
	primitive_3d_rect_up(jdr->buffer,
	    jdr->vbx + d->x + d->w-15, 
	    jdr->vby + d->y + 1, 
	    jdr->vbx + d->x + d->w-2,
	    jdr->vby + d->y + 16,
	    JSUI_C_BG);

	// center "area"
	primitive_3d_rect_down(jdr->buffer,
	    jdr->vbx + d->x + d->w-15, 
	    jdr->vby + d->y + 17, 
	    jdr->vbx + d->x + d->w-2,
	    jdr->vby + d->y + d->h - 17,
	    JSUI_C_BG);

	// down "button"
	primitive_3d_rect_up(jdr->buffer,
	    jdr->vbx + d->x + d->w-15, 
	    jdr->vby + d->y + d->h - 16, 
	    jdr->vbx + d->x + d->w-2,
	    jdr->vby + d->y + d->h-2,
	    JSUI_C_BG);

	newpen = Pen_Create();
	if (d->flags & JSUI_F_DISABLED)
	    newpen->Icolor = JSUI_C_DISABLED;
	else
	    newpen->Icolor = JSUI_C_LOLITE;

	font_render_text_center(jdr->buffer, newpen, newpen, 
		jsui_current_font,
		jdr->vbx + d->x + d->w - 8,
		jdr->vby + d->y + 7,
		"^");

	font_render_text_center(jdr->buffer, newpen, newpen, 
		jsui_current_font,
		jdr->vbx + d->x + d->w - 7,
		jdr->vby + d->y + d->h - 12,
		"v");

	if (d->dp)
	{
	    textlist = (char **) d->dp;
	    for (argc = 0 ; textlist[argc] ; argc++); 

	    if (d->d1 >= argc)  d->d1 = argc-1;
	}

	if (newpen && d && jdr->buffer && d->dp)
	{
	    voffs = 5;

	    if (d->d2 < 0) d->d2 = 0;

	    for (argc = 0 ; textlist[argc] ; argc++); 

	    ccc = d->d2;
	    while (textlist[ccc] && 
		   (ccc < (d->h-5)/15)
		  )
	    {
/*
		if (ccc == d->d1)
		    newpen->Icolor = JSUI_C_HILITE;
		else 
		    newpen->Icolor = JSUI_C_LOLITE;
*/
		font_render_text(jdr->buffer, newpen, newpen, 
			jsui_current_font,
			jdr->vbx + d->x + 5,
			jdr->vby + d->y + 5 + (ccc*15),
			textlist[ccc]);
		ccc++;
	    }
	}
	Pen_Destroy(newpen);

	if (d->flags & JSUI_F_GOTFOCUS && !(d->flags & JSUI_F_DISABLED))
	{
	    if ( (d->d1 >= d->d2) && d->dp)
		primitive_rectangle_fourcolor(jdr->buffer, 
		    primitive_pixel_dotted,
		    jdr->vbx + d->x + 2, 
		    jdr->vby + d->y + 2 + ((d->d1 - d->d2) * 15),
		    jdr->vbx + d->x + d->w-1 - 2 - 15,
		    jdr->vby + d->y + ((d->d1 - d->d2) * 15) + 15,
		    -1,
		    JSUI_C_DARK, JSUI_C_DARK, JSUI_C_DARK, JSUI_C_DARK);
	}

	jdr->flags |= JSUI_F_DIRTY;
	break;

	case (JSUI_MSG_START):
	    printf("list Start\n");
	    break;

	case (JSUI_MSG_END):
	    printf("list End\n");
	    break;
    }

    return( ret );
}
示例#9
0
void recurse(int count)
{
    printf("%d\n", count);
    recurse(count + 1);
}
示例#10
0
void raytracer_app::recurse(int depth)
{
	printf("recuse\n");

	glBindFramebuffer(GL_FRAMEBUFFER, ray_fbo[depth + 1]);

	if(pnt) printf("draw buffers\n");

	glDrawBuffers(6, draw_buffers);

	if(pnt) printf("blend\n");

	glEnablei(GL_BLEND, 0);
	//glEnablei(GL_BLEND, draw_buffers[0]);

	if(pnt) printf("blend\n");

	glBlendFunc(GL_ONE, GL_ONE);
	//glBlendFunci(0, GL_ONE, GL_ONE);
	//glBlendFunci(draw_buffers[0], GL_ONE, GL_ONE);

	// static const float zeros[] = { 0.0f, 0.0f, 0.0f, 0.0f };
	// glClearBufferfv(GL_COLOR, 0, zeros);

	if(pnt) printf("tex_position\n");
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, tex_position[depth]);

	if(pnt) printf("tex_reflected\n");
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, tex_reflected[depth]);

	if(pnt) printf("tex_reflection_intensity\n");
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, tex_reflection_intensity[depth]);

	// Render
	if(pnt) printf("render\n");
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	if (depth != (max_depth - 1))
	{
		recurse(depth + 1);
	}

	/*
	   if (depth != 0)
	   {
	   glBindTexture(GL_TEXTURE_2D, tex_refracted[depth]);
	   glActiveTexture(GL_TEXTURE2);
	   glBindTexture(GL_TEXTURE_2D, tex_refraction_intensity[depth]);

	// Render
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	if (depth != (max_depth - 1))
	{
	recurse(depth + 1);
	}
	}
	*/

	glDisablei(GL_BLEND, 0);
	//glDisablei(GL_BLEND, draw_buffers[0]);

}
示例#11
0
int
main(int argc, char *argv[])
{
	FILE * f;
	char * line;
	size_t linelen;
	PORT ** pp;	/* Array of pointers to PORTs */
	PORT * tmp;
	size_t pplen;	/* Allocated size of array */
	size_t i;

	if (argc != 2)
		usage();
	if ((f = fopen(argv[1], "r")) == NULL)
		err(1, "fopen(%s)", argv[1]);

	pplen = 1024;
	if ((pp = malloc(pplen * sizeof(PORT *))) == NULL)
		err(1, "malloc(pp)");

	/*
	 * 1. Suck in all the data, splitting into fields.
	 */
	for(i = 0; (line = fgetln(f, &linelen)) != NULL; i++) {
		if (line[linelen - 1] != '\n')
			errx(1, "Unterminated line encountered");
		line[linelen - 1] = 0;

		/* Enlarge array if needed */
		if (i >= pplen) {
			pplen *= 2;
			if ((pp = realloc(pp, pplen * sizeof(PORT *))) == NULL)
				err(1, "realloc(pp)");
		}

		pp[i] = portify(line);
	}
	/* Reallocate to the correct size */
	pplen = i;
	if ((pp = realloc(pp, pplen * sizeof(PORT *))) == NULL)
		err(1, "realloc(pp)");

	/* Make sure we actually reached the EOF */
	if (!feof(f))
		err(1, "fgetln(%s)", argv[1]);
	/* Close the describes file */
	if (fclose(f) != 0)
		err(1, "fclose(%s)", argv[1]);

	/*
	 * 1a. If there are no ports, there is no INDEX.
	 */
	if (pplen == 0)
		return 0;

	/*
	 * 2. Sort the ports according to port directory.
	 */
	for (i = pplen; i > 0; i--)
		heapifyports(pp, pplen, i - 1);	/* Build a heap */
	for (i = pplen - 1; i > 0; i--) {
		tmp = pp[0];			/* Extract elements */
		pp[0] = pp[i];
		pp[i] = tmp;
		heapifyports(pp, i, 0);		/* And re-heapify */
	}

	/*
	 * 3. Using a binary search, translate each dependency from a
	 * port directory name into a pointer to a port.
	 */
	for (i = 0; i < pplen; i++)
		translateport(pp, pplen, pp[i]);

	/*
	 * 4. Recursively follow dependencies, expanding the lists of
	 * pointers as needed (using realloc).
	 */
	for (i = 0; i < pplen; i++)
		recurse(pp[i]);

	/*
	 * 5. Iterate through the ports, printing them out (remembering
	 * to list the dependent ports in alphabetical order).
	 */
	for (i = 0; i < pplen; i++)
		printport(pp[i]);

	return 0;
}
 vector<int> findMode(TreeNode* root) {
     int frequency = 0;
     unordered_set<int> modes;
     recurse(root, numeric_limits<long long>::min(), numeric_limits<long long>::max(), frequency, modes);
     return vector<int>(modes.begin(), modes.end());
 }
 int maxPathSum(TreeNode* root) {
     return recurse(root).second;
 }
 bool findTarget(TreeNode* root, int k) {
     vector<int> v;
     return recurse(root, k, v);
 }
示例#15
0
void Connection::onExportDataToCSV (QString const & dir)
{
	qDebug("%s", __FUNCTION__);
	recurse(m_data, ExportAsCSV(dir));
}
示例#16
0
文件: prog4.7.c 项目: tamim/cpbook2
int main()
{
    recurse(1);
    return 0;
}
示例#17
0
文件: chown.c 项目: maandree/sbase
int
main(int argc, char *argv[])
{
	struct group *gr;
	struct passwd *pw;
	struct recursor r = { .fn = chownpwgr, .hist = NULL, .depth = 0, .maxdepth = 1,
	                      .follow = 'P', .flags = 0 };
	char *owner, *group;

	ARGBEGIN {
	case 'h':
		hflag = 1;
		break;
	case 'r':
	case 'R':
		r.maxdepth = 0;
		break;
	case 'H':
	case 'L':
	case 'P':
		r.follow = ARGC();
		break;
	default:
		usage();
	} ARGEND

	if (argc < 2)
		usage();

	owner = argv[0];
	if ((group = strchr(owner, ':')))
		*group++ = '\0';

	if (owner && *owner) {
		errno = 0;
		pw = getpwnam(owner);
		if (pw) {
			uid = pw->pw_uid;
		} else {
			if (errno)
				eprintf("getpwnam %s:", owner);
			uid = estrtonum(owner, 0, UINT_MAX);
		}
	}
	if (group && *group) {
		errno = 0;
		gr = getgrnam(group);
		if (gr) {
			gid = gr->gr_gid;
		} else {
			if (errno)
				eprintf("getgrnam %s:", group);
			gid = estrtonum(group, 0, UINT_MAX);
		}
	}
	if (uid == (uid_t)-1 && gid == (gid_t)-1)
		usage();

	for (argc--, argv++; *argv; argc--, argv++)
		recurse(*argv, NULL, &r);

	return ret || recurse_status;
}
示例#18
0
文件: pattern.c 项目: MUME/mudlle
        "No objects of different types are considered equal. E.g., a float"
        " is never considered equal to a bigint or an integer.\n"
        "Strings, bigints and floats are considered equal if `string_cmp,"
        " `bicmp, and `fcmp return zero, respectively.\n"
        "Symbol name comparisons are case and accent insensitive.\n"
        "Table entries that are `null are considered equivalent to"
        " absent ones.\n"
        "The graph of the container objects (pairs, vectors, symbols, and"
        " tables) in `x0 and `x1 must be homomorphic. This matters if the"
        " same container is referenced more than once.",
        2, (value lhs, value rhs),
        OP_LEAF | OP_NOALLOC | OP_NOESCAPE | OP_STR_READONLY | OP_CONST,
        "xx.n")
{
  struct seen_values seen = { .size = 0 };
  bool result = recurse(lhs, rhs, &seen);

  /* restore modified data */
  for (int i = 0; i < seen.used; ++i)
    {
      seen.seen[i].lhs->size = seen.seen[i].lhs_size;
      seen.seen[i].lhs->flags &= ~OBJ_FLAG_0;
      seen.seen[i].rhs->flags &= ~OBJ_FLAG_1;
    }
  free(seen.seen);

  return makebool(result);
}

void pattern_init(void)
{
示例#19
0
void findstates() {
  memset(statestoid,-1,sizeof(statestoid));
  nid=0;
  recurse(0,0);
}
示例#20
0
文件: pattern.c 项目: MUME/mudlle
static bool recurse(value lhs, value rhs, struct seen_values *seen)
{
  if (!pointerp(lhs))
    return lhs == rhs;

  if (!pointerp(rhs))
    return false;

  struct obj *lhsobj = lhs, *rhsobj = rhs;

  mtype lhstype = lhsobj->type;
  if (lhstype != rhsobj->type)
    return false;

  bool has_seen_lhs = lhsobj->flags & OBJ_FLAG_0;
  bool has_seen_rhs = rhsobj->flags & OBJ_FLAG_1;
  if (has_seen_lhs != has_seen_rhs)
    return false;
  if (has_seen_lhs)
    {
      size_t idx = lhsobj->size;
      return seen->seen[idx].rhs == rhs;
    }

  if (lhs == rhs)
    return true;

  /* update simple_equal?() in optimise.mud as well if more types are
     supported here */
  switch (lhstype)
    {
    case type_symbol:
    case type_vector:
    case type_pair:
    case type_table:
      break;
    case type_string:
      {
        struct string *lhsstr = lhs, *rhsstr = rhs;
        size_t len = string_len(lhsstr);
        return (len == string_len(rhsstr)
                && memcmp(lhsstr->str, rhsstr->str, len) == 0);
      }
    case type_float:
      return (((struct mudlle_float *)lhs)->d
              == ((struct mudlle_float *)rhs)->d);
    case type_bigint:
      check_bigint((struct bigint *)lhs);
      check_bigint((struct bigint *)rhs);
      return mpz_cmp(((struct bigint *)lhs)->mpz,
                     ((struct bigint *)rhs)->mpz) == 0;
    default:
      return false;
    }

  assert(lhsobj->garbage_type != garbage_static_string
         && rhsobj->garbage_type != garbage_static_string);

  if (seen->used == seen->size)
    {
      seen->size = seen->size ? seen->size * 2 : 16;
      seen->seen = realloc(seen->seen, sizeof *seen->seen * seen->size);
    }
  seen->seen[seen->used].lhs = lhs;
  seen->seen[seen->used].rhs = rhs;
  seen->seen[seen->used].lhs_size = lhsobj->size;
  lhsobj->size = seen->used++;
  lhsobj->flags |= OBJ_FLAG_0;
  rhsobj->flags |= OBJ_FLAG_1;

  switch (lhstype) {
  case type_symbol:
    {
      struct symbol *sympat = lhs, *symval = rhs;
      size_t symlen = string_len(sympat->name);
      return (symlen == string_len(symval->name)
              && mem8icmp(sympat->name, symval->name, symlen) == 0
              && recurse(sympat->data, symval->data, seen));
    }
  case type_vector:
    {
      long vl = safe_vlen(lhs, seen);
      if (vl != safe_vlen(rhs, seen))
        return false;
      for (long i = 0; i < vl; ++i)
	if (!recurse(((struct vector *)lhs)->data[i],
		     ((struct vector *)rhs)->data[i],
                     seen))
          return false;
      return true;
    }
  case type_pair:
    return (recurse(((struct list *)lhs)->car,
                    ((struct list *)rhs)->car,
                    seen)
            && recurse(((struct list *)lhs)->cdr,
                       ((struct list *)rhs)->cdr,
                       seen));
  case type_table:
    {
      /* this will work even if the table's bucket vector has been seen already
         as table_exists() doesn't look use its size */
      struct table_data tdata = { .seen = seen, .table = rhs };
      if (table_exists((struct table *)lhs, recurse_symbol, &tdata)
          || table_exists((struct table *)rhs, count_non_null_syms, &tdata))
        return false;
      return tdata.nentries == 0;
    }
  default:
    abort();
  }
}
示例#21
0
void raytracer_app::render(double currentTime)
{
	printf("render\n");

	static const GLfloat zeros[] = { 0.0f, 0.0f, 0.0f, 0.0f };
	static const GLfloat gray[] = { 0.1f, 0.1f, 0.1f, 0.0f };
	static const GLfloat ones[] = { 1.0f };
	static double last_time = 0.0;
	static double total_time = 0.0;

	if (!paused)
		total_time += (currentTime - last_time);
	last_time = currentTime;

	float f = (float)total_time;

	// matricies
	math::vec3 view_position(
			sinf(f * 0.3234f) * 28.0f,
			cosf(f * 0.4234f) * 28.0f,
			cosf(f * 0.1234f) * 28.0f); // sinf(f * 0.2341f) * 20.0f - 8.0f);

	math::vec3 lookat_point(sinf(f * 0.214f) * 8.0f, cosf(f * 0.153f) * 8.0f, sinf(f * 0.734f) * 8.0f);
	math::mat44 view_matrix = math::lookat(view_position,
			lookat_point,
			math::vec3(0.0f, 1.0f, 0.0f));

	glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer);
	uniforms_block * block = (uniforms_block *)glMapBufferRange(GL_UNIFORM_BUFFER,
			0,
			sizeof(uniforms_block),
			GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

	math::mat44 model_matrix;
	model_matrix.SetScale(math::vec3(7.0f,7.0f,7.0f));

	// f = 0.0f;

	block->mv_matrix = view_matrix * model_matrix;
	block->view_matrix = view_matrix;
	block->proj_matrix.SetPerspective(50.0f,
			(float)info.windowWidth / (float)info.windowHeight,
			0.1f,
			1000.0f);

	glUnmapBuffer(GL_UNIFORM_BUFFER);

	// sphere
	glBindBufferBase(GL_UNIFORM_BUFFER, 1, sphere_buffer);
	sphere * s = (sphere *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, 128 * sizeof(sphere), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

	int i;

	for (i = 0; i < 128; i++)
	{
		// float f = 0.0f;
		float fi = (float)i / 128.0f;
		s[i].center = math::vec3(
				sinf(fi * 123.0f + f) * 15.75f,
				cosf(fi * 456.0f + f) * 15.75f,
				(sinf(fi * 300.0f + f) * cosf(fi * 200.0f + f)) * 20.0f);

		s[i].radius = fi * 2.3f + 3.5f;
		float r = fi * 61.0f;
		float g = r + 0.25f;
		float b = g + 0.25f;
		r = (r - floorf(r)) * 0.8f + 0.2f;
		g = (g - floorf(g)) * 0.8f + 0.2f;
		b = (b - floorf(b)) * 0.8f + 0.2f;
		s[i].color = math::vec4(r, g, b, 1.0f);
	}

	glUnmapBuffer(GL_UNIFORM_BUFFER);

	// plane
	glBindBufferBase(GL_UNIFORM_BUFFER, 2, plane_buffer);
	plane * p = (plane *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, 128 * sizeof(plane), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

	//for (i = 0; i < 1; i++)
	{
		p[0].normal = math::vec3(0.0f, 0.0f, -1.0f);
		p[0].d = 30.0f;

		p[1].normal = math::vec3(0.0f, 0.0f, 1.0f);
		p[1].d = 30.0f;

		p[2].normal = math::vec3(-1.0f, 0.0f, 0.0f);
		p[2].d = 30.0f;

		p[3].normal = math::vec3(1.0f, 0.0f, 0.0f);
		p[3].d = 30.0f;

		p[4].normal = math::vec3(0.0f, -1.0f, 0.0f);
		p[4].d = 30.0f;

		p[5].normal = math::vec3(0.0f, 1.0f, 0.0f);
		p[5].d = 30.0f;
	}

	glUnmapBuffer(GL_UNIFORM_BUFFER);

	// lights
	if(pnt) printf("lights\n");
	glBindBufferBase(GL_UNIFORM_BUFFER, 3, light_buffer);
	light * l = (light *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, 128 * sizeof(light), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

	f *= 1.0f;

	for (i = 0; i < 128; i++)
	{
		float fi = 3.33f - (float)i; //  / 35.0f;
		l[i].position = math::vec3(sinf(fi * 2.0f - f) * 15.75f,
				cosf(fi * 5.0f - f) * 5.75f,
				(sinf(fi * 3.0f - f) * cosf(fi * 2.5f - f)) * 19.4f);
	}

	glUnmapBuffer(GL_UNIFORM_BUFFER);

	// prepare
	if(pnt) printf("prepare\n");
	glBindVertexArray(vao);
	glViewport(0, 0, info.windowWidth, info.windowHeight);

	glUseProgram(prepare_program);
	glUniformMatrix4fv(uniforms.ray_lookat, 1, GL_FALSE, view_matrix);
	glUniform3fv(uniforms.ray_origin, 1, view_position);
	glUniform1f(uniforms.aspect, (float)info.windowHeight / (float)info.windowWidth);
	glBindFramebuffer(GL_FRAMEBUFFER, ray_fbo[0]);

	glDrawBuffers(6, draw_buffers);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	// trace
	if(pnt) printf("trace\n");
	glUseProgram(trace_program);
	recurse(0);

	// blit
	if(pnt) printf("blit\n");
	glUseProgram(blit_program);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glDrawBuffer(GL_BACK);

	glActiveTexture(GL_TEXTURE0);
	switch (debug_mode)
	{
		case DEBUG_NONE:
			glBindTexture(GL_TEXTURE_2D, tex_composite);
			break;
		case DEBUG_REFLECTED:
			glBindTexture(GL_TEXTURE_2D, tex_reflected[debug_depth]);
			break;
		case DEBUG_REFRACTED:
			glBindTexture(GL_TEXTURE_2D, tex_refracted[debug_depth]);
			break;
		case DEBUG_REFLECTED_COLOR:
			glBindTexture(GL_TEXTURE_2D, tex_reflection_intensity[debug_depth]);
			break;
		case DEBUG_REFRACTED_COLOR:
			glBindTexture(GL_TEXTURE_2D, tex_refraction_intensity[debug_depth]);
			break;
	}
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	/*
	   glClearBufferfv(GL_COLOR, 0, gray);
	   glClearBufferfv(GL_DEPTH, 0, ones);


	   glBindVertexArray(vao);
	   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	   */

	glutSwapBuffers();
}
示例#22
0
文件: main.cpp 项目: CCJY/coliru
void recurse(Foo& foo)
{
    std::cout << foo.a++ << ' ';
    foo.schedule([&] { recurse(foo); });
};  
 int getMinimumDifference(TreeNode* root) {
     return static_cast<int>(recurse(root, numeric_limits<long long>::min() / 2, numeric_limits<long long>::max() / 2));
 }
示例#24
0
void menu::recurse(QMenu *cm, QFile &istr)
{
	QString p1,p2,p3;
	
	while(! istr.atEnd())
	{
		QTextStream til(istr.readLine(1024));

		til >> p1;  // command 
		if(p1.isEmpty() || p1 == "#")
			continue;
		
		if(p1 == "End")
			return;

		if(p1 == "Separator")
		{
			cm->addSeparator();
			continue;
		}	

		til >> p2;            // menu label
		
		if(p2.isEmpty())
			continue;

		p3 = til.readLine();  // command line

		if(p2[0] == '"')
		{
			if(p2[p2.length()-1] != '"')
			{
				int i = p3.indexOf('"');
				if(i == -1)
					continue;
				
				p2 += p3.left(i);
				p2 = p2.mid(1, p2.length()-1);
				p3 = p3.right(p3.length()-i-1);
			}
			else p2 = p2.mid(1, p2.length()-2);
		}
		
		if(p1 == "Menu")
		{
			QMenu *nm = new QMenu(p2);
			Q_CHECK_PTR(nm);
			cm->addMenu(nm);
			recurse(nm, istr);
			continue;
		}

		if(p1 == "Quit")
		{
			act_quit->setText(p2);
			cm->addAction(act_quit);
			continue;
		}
		
		if(p1 == "Kill")
		{
			act_kill->setText(p2);
			cm->addAction(act_kill);
			continue;
		}	

		if(p1 == "Restart")
		{
			act_rest->setText(p2);
			cm->addAction(act_rest);
			continue;
		}	
		
		if(p1 != "Entry")
			continue;

		p3 = p3.simplified();
		
		if(p3.isEmpty())
			continue;
			
		QAction *act_run = new QAction(p2, cm);
		act_run->setData(QVariant(p3));
		cm->addAction(act_run);
	}
}	
示例#25
0
文件: PA.c 项目: v1j4y/googlecodejam
int main()
{
    int count=0,i=1;
    int fcount=0;
    int n;
    int j,k,l,m;
//  char *string=malloc(16);
    int c;
    char found;
    int *dots;
    dots=malloc(sizeof(int));

    scanf("%d\n",&n);
    do
    {
        i=1;
        *dots=0;
        j=0;
        fcount=0;
        char *string=malloc(16);

        while ((c=getchar())!=EOF && i!=17)
        {
            if(c!='\n')
            {
                string[i++]=(char)c;
            }
        }

        count++;

        if(recurse(string,1,1,1,0,dots)==1)
        {
//          printf("test");
            if(string[1]=='T')
            {
                found=string[2];
            }
            else
            {
                found=string[1];
            }
        }
        else if(recurse(string,1,1,4,0,dots)==1)
        {
//          printf("test");
            if(string[1]=='T')
            {
                found=string[2];
            }
            else
            {
                found=string[1];
            }
        }
        else if(recurse(string,1,1,5,0,dots)==1)
        {
//          printf("test");
            if(string[1]=='T')
            {
                found=string[2];
            }
            else
            {
                found=string[1];
            }
        }
        else if(recurse(string,2,2,4,0,dots)==1)
        {
//          printf("test");
            if(string[2]=='T')
            {
                found=string[6];
            }
            else
            {
                found=string[2];
            }
        }
        else if(recurse(string,3,3,4,0,dots)==1)
        {
//          printf("test");
            if(string[3]=='T')
            {
                found=string[7];
            }
            else
            {
                found=string[3];
            }
        }
        else if(recurse(string,4,4,4,0,dots)==1)
        {
//          printf("test");
            if(string[4]=='T')
            {
                found=string[8];
            }
            else
            {
                found=string[4];
            }
        }
        else if(recurse(string,5,5,1,0,dots)==1)
        {
//          printf("test");
            if(string[5]=='T')
            {
                found=string[6];
            }
            else
            {
                found=string[5];
            }
        }
        else if(recurse(string,9,9,1,0,dots)==1)
        {
//          printf("test");
            if(string[9]=='T')
            {
                found=string[10];
            }
            else
            {
                found=string[9];
            }
        }
        else if(recurse(string,13,13,1,0,dots)==1)
        {
//          printf("test");
            if(string[13]=='T')
            {
                found=string[14];
            }
            else
            {
                found=string[13];
            }
        }
        else if(recurse(string,4,4,3,0,dots)==1)
        {
//          printf("test");
            if(string[4]=='T')
            {
                found=string[7];
            }
            else
            {
                found=string[4];
            }
        }

            if(found=='X' || found=='O')
            {
                printf("Case #%d: %c won",count,found);
            }
            else if(*dots!=0)
            {
                printf("Case #%d: Game has not completed",count);
            }
            else
            {
                printf("Case #%d: Draw",count);
            }

//      }

        printf("\n");
        found='C';
    free(string);

    }while(count<n);

    return 0;
}
示例#26
0
/*This is a child thread that calls appropriatelyGeneral*/
static void *child(void *ignored)
{
    
    recurse(1, 0);
    return NULL;
}
示例#27
0
 vector<string> binaryTreePaths(TreeNode* root) {
     vector<string> r;
     string s;
     recurse(&r, &s, root);
     return r;
 }
 vector<int> splitIntoFibonacci(string S) {
     vector<int> numbers;
     recurse(S, 0, numbers);
     return numbers;
 }
示例#29
0
int main(int argc, char* argv[])
{
  Pooma::initialize(argc,argv);
  Pooma::Tester tester(argc,argv);

  int test_number = 0;

#if POOMA_EXCEPTIONS
  try {
#endif
    tester.out() << "\nTesting resizable DataBlockPtr." 
		 << std::endl;

    RCBlock_t p;
    
    p.reserve(100);
    
    PAssert(p.size() == 0);
    PAssert(p.capacity() == 100);
    PAssert(p.empty());
    
    p.resize(10,RCBlock_t::NoInitTag());
    p.resize(20);
    p.resize(30,100);
    p.resize(10);
    
    PAssert(p.size() == 10);
    PAssert(!p.empty());
    
    RCBlock_t q(100,RCBlock_t::NoInitTag());
    
    PAssert(q.size() == 0);
    PAssert(q.capacity() == 100);
    PAssert(q.empty());
    
    q.resize(10,RCBlock_t::NoInitTag());
    q.resize(20);
    q.resize(30,100);
    q.resize(10);
    
    PAssert(q.size() == 10);
    PAssert(!q.empty());
    
    RCBlock_t bb(100);
    
    PAssert(bb.size() == 100);
    PAssert(bb.capacity() == 100);
    PAssert(!bb.empty());
    
    bb.resize(10,10);
    bb.resize(5,5);
    bb.resize(0);
    
    PAssert(bb.empty());
    
    bb.resize(10);
    
    test_number++;

    PAssert(!p.isShared());
    PAssert(!q.isShared());
    PAssert(!bb.isShared());   
    
    test_number++;

    for (int i = 0; i < 10; i++)
      p[i] = (i-5)*(i-5);

    test_number++;

    print(p,tester);
    print(q,tester);
    print(bb,tester);

#if POOMA_EXCEPTIONS
    test_number++;

    try {

      for (int i = 0; i < 11; i++)
	p[i] = -p[i];

      throw "Bounds checking failed!";
    }
    catch(const Pooma::Assertion &) 
      { 
	tester.out() << "Bounds check worked." << std::endl; 
      }
#endif

    test_number++;

    for (int i = 0; i < 10; i++)
      PInsist( p[i] == *(p+i), "p[i] != *(p+i)" );

    for (int i = 0; i < 10; i++)
      PInsist( p[i] == *(p+i), "p[i] != *(p+i)" );

    test_number++;

    PAssert(!p.isShared());

    test_number++;

    foo(p,tester);
    
    test_number++;

    PAssert(!p.isShared());

    test_number++;

    bar(p,tester);

    PAssert(!p.isShared());

    test_number++;

    print(p,tester);

    test_number++;

    RCBlock_t a(1000,RCBlock_t::NoInitTag());
    a++;

#if POOMA_EXCEPTIONS
    try {
      tester.out() << a[4];
      throw "Bounds checking failed!";
    }
    catch(const Pooma::Assertion &) 
      { 
	tester.out() << "Bounds check worked." << std::endl; 
	tester.check(1);
      }
#endif
      
    // Reset start pointer...
    a--;
    
    a.resize(10,RCBlock_t::NoInitTag());
    
    for (int i = 0; i < 10; i++)
      a[i] = (i-5)*(i-5);
    
    bar(a,tester);
    print(a,tester);
    
    test_number++;

    RCBlock_t q1 = p;

#if POOMA_EXCEPTIONS
    try
      {
	RCBlock_t q2; q2 = p;

	PAssert(q1 == p);
	PAssert(q2 == p);
	PAssert(q1 == q2);

	PAssert(p.isShared());
	PAssert(q1.isShared());
	PAssert(q2.isShared());

	for (int i = 0; i < 10; i++)
	  PAssert(q1[i] == q2[i]);
	
	PAssert(p.capacity() == q1.capacity());
	PAssert(p.capacity() == q2.capacity());
	PAssert(p.size() == q1.size());
	PAssert(p.size() == q2.size());
      }
    catch (...) 
      { 
	tester.out() << "Something is very wrong!" << std::endl; 
	tester.check(0);
      }
#endif

    PAssert(p.isShared());
    PAssert(q1.isShared());

    p[1] = -999;
    PAssert(q1[1] == -999);

    test_number++;

    p.invalidate();

    PAssert(!p.isValid());

#if POOMA_EXCEPTIONS
    try {
      tester.out() << p[3];
      throw "Bounds checking failed!";
    }
    catch(const Pooma::Assertion &) 
      { 
	tester.out() << "Bounds check worked." << std::endl; 
      }
#endif

    PAssert(!q1.isShared());

    test_number++;

    recurse(q1,tester);

    PAssert(!q1.isShared());
    tester.out() << "q1.isShared = " << q1.isShared() << std::endl;

    print(q1,tester);

    test_number++;

    {
      const RCBlock_t r = q1;

      PAssert(r.isShared());

      print(r,tester);

      for (int i = 0; i < 10; i++)
	tester.out() << *(r+i) << " ";

      tester.out() << std::endl;

      p = r;

      PAssert(p.isShared());
    }

    PAssert(p.isShared());

    test_number++;

    q1.invalidate();

    PAssert(!p.isShared());

    test_number++;

    tester.out() << "\nTesting conversions to non-boundschecked" << std::endl;
    RCFBlock_t s = p;

    PAssert(s.isShared());
    PAssert(p.isShared());
    PAssert(s == p);

    print(s,tester);

    recurse(s,tester);

    PAssert(s.isShared());

    test_number++;

    s.makeOwnCopy();
    PAssert(!s.isShared());
    PAssert(!p.isShared());
    PAssert(s != p);

    for (int i = 0; i < 10; i++)
      s[i] = i*i;

    tester.out() << "These should not be the same." << std::endl;

    for (int i = 0; i < 10; i++)
      tester.out() << p[i] << " ";

    tester.out() << std::endl;
    for (int i = 0; i < 10; i++)
      tester.out() << s[i] << " ";

    tester.out() << std::endl;

    tester.out() << "printed ok that time." << std::endl;

    print(s,tester);
    print(p,tester);

    s.invalidate();
    
    PAssert(!p.isShared());

    p.invalidate();

#if POOMA_EXCEPTIONS
  }
  catch(const char *err) 
    { 
      tester.exceptionHandler( err );
      tester.set( false );
    }
  catch(const Pooma::Assertion &err)
    { 
      tester.exceptionHandler( err );
      tester.set( false );
    }
#endif    
    
  tester.out() << "All Done!" << std::endl;
  int res = tester.results("dbptr_test5 ");
  Pooma::finalize();  
  return res;
}
 vector<TreeNode*> findDuplicateSubtrees(TreeNode* root) {
     map<tuple<int, int, int>, pair<int, bool>> seenMap;
     vector<TreeNode*> seenNodes;
     recurse(root, seenMap, seenNodes);
     return seenNodes;
 }