Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

500 Good

About Grain

  • Rank
    Advanced Member
  1. When I start create my Speaker and feed it data it seems to only play the first buffer. The method that feeds in buffers first checks needbuffers flag and just returns and does nothing if it's false. My setneedbuffers event handler is never called (I set a break point in it) and needbuffers flag never gets set back to true.   If I pause execution and check the state of DynSoundInst it's still set to "playing". DynamicSoundEffectInstance is suposed to stop playback if its starved of data, but that's not the case here. public class Speaker_XNA : Speaker { DynamicSoundEffectInstance DynSoundInst; bool needbuffers = true; short bitspersample; public Speaker_XNA(short BitsPerSample, short Channels, int SamplesPerSecond) { FrameworkDispatcher.Update(); DynSoundInst = new DynamicSoundEffectInstance(SamplesPerSecond, (AudioChannels)Channels); bitspersample = BitsPerSample; DynSoundInst.BufferNeeded += setneedbuffers; } private void setneedbuffers(object sender, EventArgs e) { needbuffers = true; } ... }
  2. Grain

    Digits of Pi

    I like thing that are evenly spaced, or symmetrical or balanced. Irrational and prime numbers bother me just because you can't make them line up evenly with things.
  3. Grain

    Digits of Pi

    I'm kind of OCD and irrational numbers really bother me. So how many digits of Pi would you need to calculate a circle the size of the known universe with the accuracy of the Planck length? That way, at least in a physical sense Pi does have a practical end and I can stop worrying about it.
  4. I am having trouble with this prime number sieve running out of memory.   It fails at Values.Capacity = n; Previously Values was just an array defined like this : bool[] Values = new bool[n]; but had the same result. I am passing primesieve an int.MaxValue. static int[] Primesieve(int n) { List<bool> Values = new List<bool>(); Values.Capacity = n; int[] primes = new int[(int)Math.Sqrt(n)]; int primecount = 0; Values[0] = true; Values[1] = true; for (int i = 0; i < Math.Sqrt(n); i++) { if (Values[i] == false) { for (int j = i * i; j < Values.Count; j += i) Values[j] = true; primes[primecount] = i; primecount++; } } return primes; } I believed my problem to be that since they are bools, a value type they are being created on the stack so I did this to force heap allocation. but it still fails at the same place.     public class Reference<T> {     public T Ref; } static int[] Primesieve(int n) { List<Reference<bool>> Values = new List<Reference<bool>>(); Values.Capacity = n; int[] primes = new int[(int)Math.Sqrt(n)]; int primecount = 0; Values[0].Ref = true; Values[1].Ref = true; for (int i = 0; i < Math.Sqrt(n); i++) { if (Values[i].Ref == false) { for (int j = i * i; j < Values.Count; j += i) Values[j].Ref = true; primes[primecount] = i; primecount++; } } return primes; } My machine has 16gb of ram running win7 64-bit and i even targeted the build specifically to x64. So I know it cat actually be running out of memory as int.MaxValue Booleans should only take around 2gb assuming .Net is not packing 8 of them into 1 byte,  and if it is then it should only really take up 265mb.   Or am I some how still failing to use the heap?
  5.  Same idea as a linked list. Only this can potentially branch.    Is there some method of keeping track of it automatically?   Move to the first child first, then to any of it's children/neighbors next ect, return to the parent when you reach the end, repeat for the next child until there are no more children, move to the neighbor. public class FileParseElement { string token; FileParseElement Neighbor; List<FileParseElement> Children; List<FileParseElement>.Enumerator CurrentChild; public static FileParseElement BuildFullObjectStructure(ref List<string>.Enumerator ittr){...} public static FileParseElement BuildObjectSet(ref List<string>.Enumerator ittr){...} public string Token { get { return token; } } public FPE_Iterator GetIterator() { return new FPE_Iterator(this) { }; } public class FPE_Iterator //this IS a nested class { FileParseElement Head; Stack<FileParseElement> ParrentStack; public FPE_Iterator(FileParseElement FPE) { ParrentStack = new Stack<FileParseElement>(); Head = FPE; } public FileParseElement Current { get { return Head; } } public bool Movenext() { if (Head.Children != null)                 {                     if (Head.CurrentChild != new List<FileParseElement>.Enumerator()) //compiler doesn't allow this                     {                         ParrentStack.Push(Head);                         Head = Head.Children.GetEnumerator().Current;                         return true;                     }                 }                   if (Head.Neighbor != null  /*&& I have no children or finished tracversing them*/)                 {                     Head = Head.Neighbor;                     return true;                 }                 else { //pop a parent off the stack and assign it to Head return false; } } } } Movenext() is what I'm working on now. It's far from compleet
  6. I have a custom container class that is arranged like a tree. Each element can have up-to 1 neighbor element and any number of children elements, these children are stored in a standard library List<T>.   Each element also has a  List<T>.Enumerator so that when I iterate through this container and come to the end of a branch and then back up it will remember which branch it was last down and go to the next branch next, if it exists.  Now not all all elements have children, in fact most don't, so for those I don't even bother creating a List<T> instance and there for don't have anything to attach the Enumerator to. 
  7. In C# how can I check if a List enumerator is valid before using it? Valid meaning it has been attached to a List already. Since enumerator is a struct it's not comparable to null so that option is out. The .Current property can be null even if the enumerator is valid, for example if MoveNext() has not yet been called for the first time or if the end of the list has been reached, so checking that isn't helpful in all cases either.     I can call MoveNext() in a try/catch block, which would tell me if it's valid or not, but if the the enumerator IS valid I don't wan't to move to the next item just yet. I would wan't to check if the .Current property if not null and then work with that item before calling MoveNext(). And I don't really like catching exceptions as part of preforming basic logic anyway, they should be only for error handling. 
  8. Grain

    Vector Projection with zero length

    How about this then?          public static Vector2 Project(this Vector2 A, Vector2 B)         {             float DotOverDot = Vector2.Dot(A, B) / Vector2.Dot(A, A);             if (float.IsNaN(DotOverDot) || float.IsInfinity(DotOverDot))                 return Vector2.Zero;             else                 return Vector2.Multiply(A, DotOverDot);                         }
  9. Grain

    Vector Projection with zero length

      What you are trying to do here is figure out how much of B is pointing in the A direction. This assumes that A is a direction vector. A direction vector is usually required to have a length of 1. Any vector that can be normalized can be a direction vector. However, a zero-length vector cannot be normalized and thus has no direction. If A was correctly normalized your project function simply return Vector2.Dot(A,B). If you should not be projecting zero-length vectors, it seems that there is a problem upstream of this function. Personally, I would get rid of this function and make sure that my direction vector was normalized and use the dot product directly.   -Josh   Normalizing requires a square root call which I'd like to avoid as much as possible, and seeing as I can project just fine while avoiding that I see no benefit in doing so. Also zero vectors are perfectly valid in some cases(a velocity vector for example).  
  10. Grain

    Vector Projection with zero length

    Also I'm projecting B onto A, as where this example projects A onto B.
  11. Grain

    Vector Projection with zero length

    I'm not sure what you mean considering the result should be the same for all lengths of A with the sole exception 0.  
  12. Currently I'm doing this  public static Vector2 Project(this Vector2 A, Vector2 B) { if (A.X != 0f || A.Y != 0) return Vector2.Multiply(A, Vector2.Dot(A, B) / Vector2.Dot(A, A)); else return A; //return B; ??? } Without the zero length check in there every thing blows up because this method returns an effectively infinite length vector.  What is the best thing to return when the length of A is zero?
  13. Either you haven't explicitly defined lifetimes, or you haven't explicitly defined ownership (which goes back to my earlier point, that "shared" is not a valid definition of ownership).   If both are explicitly defined, then there cannot be any other code that refers to dead resources.       And my point is that you should be doing this implementation in C++, too. Skating by with shared ownership semantics only takes you so far.   Ok. Object 1 owns object 2. This is explicit. Object 3 has a reference to object 2 because it needs to work with some data it has. Object 1 dies, so it kills object 2 as well.  This is also explicit.    Now, we still need to inform object 3 that it's reference to object 2 is no longer valid. 
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!