Jump to content
  • Advertisement

dark_696

Member
  • Content Count

    21
  • Joined

  • Last visited

Community Reputation

138 Neutral

About dark_696

  • Rank
    Member
  1. dark_696

    reference as return type

    Oh, now I understand what was the point of Zahlman's advice. Instead of setting the bounds of dragging rect, I should make two functions, something like SetMouseDownRect(POINTS mousePoints) and SetMouseMoveRect(POINTS mousePoints) and SetMouseUpRect(POINTS mousePoints), instead of returning rect and modify it directly in message processing. Yes, that is very good option, but to be honest I never thought about it. On the other hand, I already have a class, CMessageProcessor which takes care of WM processings, and now it seems useless. I don't know, I'll try like I was said.
  2. dark_696

    use of covariance - java

    Well, then again, when we're at it, what is contravariance and is it supported in C++?
  3. dark_696

    use of covariance - java

    My, now I feel stupid. I use covariance all the time and didn't have a clue I do :-) Thanks.
  4. dark_696

    use of covariance - java

    I always thought of it in other form. More like this (I'll write in Java): public interface Super { Super getInstance(); } public class Child implements Super { @Overrides Child getInstance() { return new Child(); } } Now... If I use Super somewhere, what use is if I don't know what is implementation? Or, if I use Child, why do I need interface, or why do I need method which returns new instance, when I can use constructor then? I thought covariance is somehow a safe way for super type to dynamically cast to child type, so I can get a pointer to super, and then find out what implementation it is and avoid chain of instanceof checks. Oh, I realized, is it maybe good for, example: public class Super { public Super doSomethingAndReturn() { // do something return newInstance; } } public class Child extends Super { public Child doSomethingAndReturn() { super.doSomethingAndReturn(); // do something return newInstance; } } Calling super to initialize object and then add some more inits and returning child type? But its not so useful as I can extend only one class, so we avoid using classes and restrict as much as we can to interfaces.
  5. dark_696

    use of covariance - java

    Nice :-) Can you please explain what is its use and did I define covariance completely and correctly?
  6. As I understand covariance is the ability of overrided class functions to return type that is inherited from the base class. What I don't understand is the use of that. I mentioned java in the thread name because java natively supports covariance, opposed to c++ where I read (I could be wrong) that covariance is gained through use of templates. Anyway, can anyone explain some practical use of it?
  7. dark_696

    reference as return type

    Quote: No, it isn't really. You are still able to do whatever you like with the Rect object, from anywhere in the project, like a global - plus you added complexity with a method call that doesn't actually offer any protection. It would be cleaner to provide an interface from that file (module) to the rest of the code, through which the other code can interact with the Rect without dealing with it directly. E.g. Very true, but I apply this philosophy because when I want to change something (and that happens very ofter) I need only to change one place, not thousands of it. Same happens to class members functions - they all call other class member functions, would they be private or public, because at one point, when I change something in a class, I change only one place, not searching through the file and replacing. I think this is not a bad design (maybe introduces some function calling cost), but then again, what am I developing is application (an Editor), not a game currently, so I do not care much about gaining speed, but fast refactoring. On the other hand, I prefer functions over globals because of the name clashing. I know, I can use namespaces, but as I said, I want to reduce refactoring as much as possible. Then again, when thinking it over again, maybe my design steps are wrong. I am used to play with functions first and then when I'm sure about what functionality I want, I make a class, and plug it in hierarchy. Maybe I should design class hierarchy from the start, but at the times I tried that way, I ended in five-days refactorings that only pushed me away from coding the real thing. I don't know.
  8. dark_696

    reference as return type

    Quote: Your problem is that you return the reference, but then store it in a non-reference type, which makes a copy of the data. If you stored it in a reference type variable, then you'd maintain access to the original variable. I see now, thanks again to you and garyfletcher, but the next questions are now far more important to me, so please help on :-) Quote: The compiler handles the semantics as well as any allocation and deallocation that may occur. I don't really understand this. I understand what do you mean by saying that compiler resolves semantics (I do not have to use pointer-to-member op), but regarding allocation, do you mean for example this case (ie. passing to reference var makes reference, passing to value var makes copy)? This is important to me, because if this is true, then I will convert back to pointers immediately. The reason: if I use pointers, compiler would report invalid levels of indirection in this case, which would report me or remind me of what I wanted to do, instead of copying values by himself. This can cause some bugs that'll take some serious time. And besides, I just HATE when programs are trying to be nice to me and my mistakes instead making clear what I want to do. By the way, is it copying values on the same basis as default copy-constructor? I ask this because I'm passing simple struct around (RECT). And next, what do you mean by compiler handling de-allocation? I thought the reference obeys scope and allocation given by that reference's definition, and the value it is pointing to obeys its own scope and allocation rules. Is that true? If it is, I do not see what compiler has to do with it, as it is the same as any other type, built-in or not. Please, explain.
  9. dark_696

    reference as return type

    Quote:In the original post you are not declaring dragRect as a reference type and you also don't need the void in a function call. Should it be: RECT &dragRect = GetDragRect(); So, when returning reference type, I have to declare reference type variable. Didn't know that, but thats what I wanted to know, thanks. Quote: Problem with returning a reference is that what your returning usually no longer exists in memory. If you are returning a local variables reference, it is dead by the end of the call and therefore does not exist. The scope of the variable prevents it. Try GetDragRect(RECT &rOut); I don't want to pass in buffer rect, I want to operate directly on var, 'cause its not local stack allocated var but file-scope global. One more question. Beside semantics, are there any advantages to using references rather then pointers?
  10. dark_696

    reference as return type

    First, thanks for the tags :-) Next, truly, rect does not exist on heap, but on the stack, but I don't understand; if its file-scope var, it is allocated on the stack, globally, but seen inside the file only, right? So when passing it from a function, like this (this is what GetDragRect(void) does): // someFile.cpp static RECT s_DragRect; RECT& GetDragRect(void) { return s_DragRect; } it should return reference to the global s_DragRect, shouldn't it, not make a copy of some other? And, I forgot, if returned rect is deallocated when leaving function scope, then returnable wouldn't have s_DragRect's values in it, and it does. The only problem is that when I change the values in the returnable, values don't seem to reflect to the static var. I really don't understand why code before this one worked, when reference op should do the same: static RECT s_DragRect; RECT* GetDragRect(void) { return &s_DragRect; }
  11. In one file, I have a file-scope variable I want to be used across the project. Firsty I used getter that returned pointer to the var, so I can change it (yeah, I could make it a global var, but I like this better, it's cleaner), and after a while, I was tempted to try out reference op (never used it before). So, I return the reference to the var: <code>RECT& GetDragRect(void);</code> and use it somewhere like this <code>RECT dragRect = GetDragRect(void); dragRect.left = 100; dragRect.top = 100;</code> but after modifying returnable, it seems that file-scope var stayed the same. When briefly reading through MSDN, it seems to me that pointer returnable is contextually same as pointer, only the semantics change. But I see that I could be wrong. Can someone please direct me?
  12. Thank, no problem for short info, I already have my tilemap engine done long ago. I'm just tuning it now to DirectX (I did first version in GDI+, so I can debug) and wondering how to make it fast... Nevertheless, I'll surely read articles, thanks again...
  13. I would like to extend this question a bit, concerning tilemapping: Sooner or later, you'll have to combine data array with tiles into bitmap that would be blitted to backbuffer (or compose tilemap onto backbuffer directly), and as such, composing algorithm for games like Ultima8 (where character is always in the center of screen and the world scrolls around) would have to be pretty fast if tiles are really small (I am talking about 25x25 in 800x600x32 res minimum). Now, I remember Ultima8 was awfully slow... So, is there any standardized technique, maybe something like buffering about one whole screen in each of eight directions character could move, and use that to keep constant framerate, and then, as player is moving, when there's enough processing time, fill the gaps in those "screen buffers"?
  14. dark_696

    Making everything a subclass

    Its not bad design pattern, but it is bad to design without pre-planning. Having somewhat generic root class that is derived by all other is seen in game logic before (Unreal is the first to expose that, but I may easily be wrong). The bad part is that your Object class has nothing except destructor, so its not usable at all. When you instantiate a class to base class pointer type, you get no functionality from the child class (I assume you know that), and as such, your pointer is pretty much non valuable. On the other hand, if you're going to cast it to child class, why bothering at superclassing at all? My advice is that you should construct your software on a class-per-solution basis, and then, when you find similarities between problems and program code, refactor. Its the way I'm doing my projects, and its working for me.
  15. dark_696

    game loop

    Ahem. General rule is, have as many functions as possible. Function is good if you can describe it in one short sentence. But that produces many function calls and that costs one memory cycle each (a lot of wasted CPU cycles). I suggest putting "inline" infront most of your functions you know you'll call many many many times in very short periods and give compiler a hint that can really speed up some loops or iterations. Search through web or MSDN for "inline" keyword explanation. To exclude myself from flaming (again), anyone please correct me if I'm wrong, cause I use inlines often with such designing pattern when doing speed-critical software, ie. games.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!