• Content count

  • Joined

  • Last visited

Community Reputation

248 Neutral

About Gorg

  • Rank
    Advanced Member
  1. [quote name='Serapth' timestamp='1314879774' post='4856253'] And the compiler will wistfully allow my stupidity until runtime then BOOM. [/quote] I never found that to be a problem in practice. If it is used with object created by programmers while writing code, unit/integration tests will usually catch the mistake. It only gets problematic if the object type is selected from values from an external source, like say an external file or your JSON example. Then extra validation has to be done before calling the function, but since the type is selected externally, it has to be validated anyway before being used. However, if you do have a large project with a lot of programmers, I certainly would recommend to stick with static typing and only allow a few leads to use dynamic if it would significantly improve the code. My example fits that because the VM I wrote does not deal with types directly, so a switch statement with a type check would have needed to be done for each math operations if I did not use dynamic. [code] result = VMMath.ADD(src1, src2); [/code] instead of say [code] if ( src1 is int ) { result = VMMath.ADDInt(src1,src2) } else if ( src1 is float ) { result = VMMath.ADDFloat(src1,src2) } else if ( src1 is string) { result = VMMath.ADDString(src1,src2) } ..... [/code] A different design can work around that problem and not require dynamic and still be a one liner, but it's all that was required for the VM I built.
  2. I have used it once so far in a little VM. I used it for Mathematical operations. [code] public object Add(dynamic lhs, dynamic rhs) { return lhs + rhs; } [/code] That was a lot faster to code that then having all the overloads for all the existing types. Of course, this might not perform in tight loops. The .NET runtime does perform [url="http://en.wikipedia.org/wiki/Inline_caching"]polymorphic caching[/url], but I never bother to do any benchmark it because the VM was fast enough for its purpose.
  3. [quote name='EJH' timestamp='1314727387' post='4855546'] Can you just make your history list of type "List<Object>"? You can store anything there. Then when someone hits Undo or Redo you just look at the most recent item's type: ... [/quote] Don't do this. The scenario presented by the OP has a clear solution that follows the [url="http://en.wikipedia.org/wiki/Open/closed_principle"]open/closed principle[/url]. With the solution, you can add new commands without modifying the UndoRedo class. In your example, you cannot.
  4. Your interface should not be generic and each memento target bundled in the memento. With that change the UndoRedo class also does not require to be a generic and can handle any memento from anywhere for any instance. [code] public interface IMemento { IMemento Restore(); } class AddTileMemento : IMemento { private int index; Tile[] target; public AddTileMemento(Tile[] target, int index) { this.target = target; this.index = index; } public override IMemento Restore() { Tile removed = target[index]; IMemento inverse = new RemoveTileMemento(target, index, removed); target[index] = null; return inverse; } } class RemoveTileMemento : IMemento { private int index; private Tile removed; Tile[] target; public RemoveTileMemento(Tile[] target, int index, Tile removed) { this.target = target; this.index = index; this.removed = removed; } public override IMemento Restore() { IMemento inverse = new AddTileMemento(target, index); target[index] = removed; return inverse; } } [/code]
  5. Jitters in opengl textures

    [quote] i'm not find GL_TEXTURE_MAX_FILTER may be this is a problem? thanks [/quote] Sorry, I meant GL_TEXTURE_MAG_FILTER. As AndyEsser said, a video would be good or a bunch of quick successive snapshots would work too.
  6. Jitters in opengl textures

    What value are you using for GL_MIN_FILTER and GL_MAX_FILTER for your texture object?
  7. Since you already have an ascending comparer, you can also just create a new comparer that inverts the comparison of an existing one. [code] public class ReverseOrderComparer<T> : IComparer<T> { public ReverseOrderComparer(IComparer<T> comparer) { this.comparer = comparer; } IComparer<T> comparer; public int Compare(T x, T y) { return comparer.Compare(y, x); } } [/code] You use it like this: [code] List<int> i = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; i.Sort(new ReverseOrderComparer<int>(Comparer<int>.Default)); [/code]
  8. You did not pay the full amount of your last bill...
  9. weirdest hardware problem i ever had

    I am just going to throw something out there Do you have a USB wireless dongle? I have had a similar problem with Windows 7. It would simply freeze at some point during boot up. Sometimes I would manage to log-in, but it would freezes some time afterwards. After a few tries, it would boot and stay up. There was nothing in the event log at that time. It kept doing that and at some point stuff started to show up in the event log related to networking. I unplugged the USB dongle and it booted flawlessly after that. So now, everytime I have to reboot, I have to unplug the dongle, wait for windows to boot up and plug it back in. I am just too lazy to buy a new one yet as it works properly after the computer boot. So I am not sure if it applies to you, but maybe it gives you something to try out.
  10. I haven't used glVertexPointer in a long time, but that looks odd gl.glVertexPointer(3, GL.GL_FLOAT, 0, mVertexBuffer); Shouldn't that be gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0) As far as I remember since you bind buffers the last parameter should be the start index inside the bound buffer. Since your are passing mVertexBuffer, the offset will be off by whatever number your buffer is. The same thing applies to your glTexCoordPointer call and glDrawElements.
  11. You are passing GL_UNSIGNED_BYTE to your glDrawElements call but your index buffer is byte. Maybe that's causing the problem? EDIT: I missed the part where you used DrawArrays. So unsigned/signed cannot be your problem completely.
  12. I personally think the word refactoring does not need to exists. We always write bad code. It's almost impossible to have all the right names,function, class when you are writing something. It evolves as you add things and it will most likely end up as somewhat of a mess. The key is once you are done with a piece of code, then *immediately* go back and clean it up. i.e. Break up large functions, rename things that have bad names, create classes for group of functions that works on the same data, etc. The longest one to do is extracting classes because it requires a more in-depth analysis of the functions, but all the others are simply cosmetic. It usually takes no more than 10-20 minutes for the quick polishing. So to me, refactoring *is* software development and as such the word is unnecessary. If you inherit bad code and if management refuses to give you some time to improve it then you are screwed, but it can be slowly revived if you get the opportunity. The key is just doing little things, mostly cosmetic, not trying to change the entire structure. This is how I usually approach this. If you have a function that's too big, then I first read through the function linearly and take every 5-10 lines of code, guessing what they do and create a function with those lines. The beauty of this approach is the code still runs perfectly , especially if you use the "extract method" option in visual studio. After it's all done, you end up with more manageable functions and it is easier to understand what it does and move code around to give it a better structure. If you have a mess of interacting classes, then what I do, is merge them all So if function Y from class A, calls function X on class B, I simply take code from function X and put it inline inside of function Y. If some member variable of B is used in X, then I copy it in A. Also, if function X calls function Z on class C, then I also move the code to class A. It's a judgement call how deep you should go. Once that done, I take the newly created gigantic function in class A and just break it down again. This whole process is much easier if you have tests, because you can do all that and still have the code fully functional by tweaking the tests, but I had success without.
  13. Your inner for loop seems weird to me, but I haven't pass much time trying to understand it. The algorithm I use goes like this(sorry crappy pseudo code): Assuming translation is direction the object is going computed from say controller input and that calls = 0 when the function is first called. Vector DoCollisionCheck( translation, calls ) { if ( 3 == calls ) { return Vector.Zero; } targetTris = GetListOfPotentialCollisions() //this function sorts the triangles so that the one most perpendicular to you and his front facing you //is checked first //So the triangle with the smallest dot(trianglenormal, translation) will be //checked first. The smallest value being -1. which means you a directly perpendicular to that triangle. targetTris.OrderByMoreParellelToDirectionVector( translation) foreach( triangle in targetTris ) { if ( intersect( triangle, object at p + translation ) ) { //correct translation and make object slide //along triangle translation = StickToTriangle(); return DoCollisionCheck(translation, calls + 1); } } return translation; } So it's recursive. Which means you should stop at some point. I personally stop if there 3 recursive calls, which means the object has collided with 3 walls. By stop I mean set the translation to 0. You don't want to use current translation because that could kick you out outside the world. If you stop after 2, then you'll get stuck if you have a small 3 wall corner. So I find 3 works well. [Edited by - Gorg on July 17, 2009 7:18:59 AM]
  14. I can't get into my admin account

    My father had forgot his once and I used this boot CD to blank it out. It was a breeze to use. http://home.eunet.no/~pnordahl/ntpasswd/bootdisk.html The fullset of instructions are here http://home.eunet.no/~pnordahl/ntpasswd/walkthrough.html
  15. Widescreen and 4:3 problem

    You seem to have enough help for your gui, but in case your are not already doing this, I wanted to point out that the resolution and the aspect ratio should not be tied together. I have a 16:10 monitor and for some games, because of performance, I have to run with a 4:3 resolution. At that point, the only choices I have are stretching or letterbox depending on my monitor settings. If the developer would simply have let me pick a 16:10 aspect ratio even though I am using 1024x768, there would be no stretching and no letterboxing. The only game I was seen with those options so far was Call of Duty 2. Also in the Doom 3/Quake 4 engine you could set a console variable to change the aspect ratio without affecting the resolution. In conclusion, if you implement support for wide screen make sure that you can let the user select an aspect ratio independently of the resolution. So w / h in your gluPerspective call should not be based on the resolution, but on the aspect ratio setting.