Jump to content
  • Advertisement

LowCalorieSoftDrink

Member
  • Content Count

    101
  • Joined

  • Last visited

Community Reputation

154 Neutral

About LowCalorieSoftDrink

  • Rank
    Member
  1. LowCalorieSoftDrink

    Events/Delegates

    One of the things that I've found wanting in wxWidgets is the call-back system. Whilst implementing the (so far) minimal GUI system I found myself pining for a .NET Event Handler/Borland VCL closure like concept. The boost library is an obvious alternative but in the past I've never really got along with boost, I have my reasons but I won't got into them now . I'm a big fan of this style of message passing, there's no interface binding from the producer to the consumer and a minimal binding the other way, making it easier to write modularised code. I had a (very cursory) look around the internet at what others had done, there were a couple of very interesting, in-depth discussions on code-project.com (here and here). Whilst informative these articles focused mainly on the performance penalty of the various approaches. As I don't intend to use these events/delegates in performance sensitive code my main focus was ease of use/clean API rather than performance. I wanted the usage to look similar to C# events/delegates and I am fairly happy with the result. #include #include class Producer { public: Event onPrint; }; class Consumer { public: void print(Producer &p, const std::string &str) { std::cout *ptr)(producer, arg); } //Method Lookup //------------- template class MethodLookup { public: typedef void (C::*MethodPtr) (P&, A); static uintptr_t getMethodID(MethodPtr ptr); private: static std::vector pointers; }; template std::vector MethodLookup::pointers; template uintptr_t MethodLookup::getMethodID(void (C::*ptr)(P&, A)) { //determine whether we've already seen this pointer for (std::vector::iterator it=pointers.begin(); it!=pointers.end(); ++it) { if (*it==ptr) return it-pointers.begin(); } //if not add it to the vector pointers.push_back(ptr); //return the new id return pointers.size()-1; } //Event //----- template class Event { public: typedef void (*FunctionPtr) (P&, A); Event(); ~Event(); Event& operator+= (const FunctionPtr ptr); Event& operator-= (const FunctionPtr ptr); template Event& operator+= (const MethodDelegate &d); template Event& operator-= (const MethodDelegate &d); void clear(); void operator() (P &producer, A arg); private: typedef std::map DelegateMap; DelegateMap delegates; }; template Event::Event() {} template Event::~Event() { clear(); } template Event& Event::operator+= (const FunctionPtr ptr) { //add a new delegate delegates[std::make_pair(static_cast(0), reinterpret_cast(ptr))] = new FunctionDelegate(ptr); //return a reference to this so we can chain it return *this; } template Event& Event::operator-= (const FunctionPtr ptr) { //retrieve the existing delegate DelegateMap::iterator it = delegates.find(std::make_pair(0, static_cast(ptr))); //if it exists remove and delete it if (it!=delegates.end()) { delegates.erase(it); delete it->second; } //return a reference to this so we can chain it return *this; } template template Event& Event::operator+= (const MethodDelegate &d) { //determine the method's unique id uintptr_t methodId = MethodLookup::getMethodID(d.ptr); //add a new delegate delegates[std::make_pair(d.consumer, methodId)] = new MethodDelegate(d); //return a reference to this so we can chain it return *this; } template template Event& Event::operator-= (const MethodDelegate &d) { //determine the method's unique id uintptr_t methodId = MethodLookup::getMethodID(d.ptr); //retrieve the existing delegate DelegateMap::iterator it = delegates.find(std::make_pair(d.consumer, methodId)); //if it exists remove and delete it if (it!=delegates.end()) { //delete the delegate delete it->second; //remove the delegate from the map delegates.erase(it); } //return a reference to this so we can chain it return *this; } template void Event::clear() { while (!delegates.empty()) { DelegateMap::iterator it=delegates.begin(); //delete the delegate delete it->second; //remove the delegate from the map delegates.erase(it); } } template void Event::operator() (P &producer, A arg) { //invoke all the delegates for (DelegateMap::iterator it=delegates.begin(); it!=delegates.end(); ++it) (*(it->second))(producer, arg); } //Utilities //--------- template MethodDelegate operator+ (C &consumer, void (C::*ptr)(P&, A)) { return MethodDelegate(&consumer, ptr); }
  2. LowCalorieSoftDrink

    Asylum

    Screen-shots documenting the development of Asylum.
  3. LowCalorieSoftDrink

    Introduction

    I've been a gamedev.net member for a number of years, mostly reading and quietly appreciating rather than being an active contributor. However spurred on by the recent site overhaul and the availability of the fancy new features I though I might give this blogging thing a go. I'm not sure what I actually want this to be, but I hope it to be a repository and portfolio of my hobbyist development efforts. To that end I'll introduce, Asylum. My intention is for it to be a general purpose, cross platform, graphics scene editor. Where it eventually leads is inevitably subject to my whimsy and chronic lack of focus but It should hopefully prove to be a solid framework for experimentation. The pre-requisite technical details: it's a C++ application using OpenGL for graphics and wxWidgets for the GUI. I look forward to sharing furture progress. Cheers
  4. LowCalorieSoftDrink

    And so it begins...

    I'm very much looking forward to having a play around with this. Will there be any level of IDE integration in the initial release or will it be a solely stand-alone app?
  5. LowCalorieSoftDrink

    Deferred lighting and instant radiosity

    Hi, really informative entry, I've followed your work for some time and you never fail to impress. I may have misunderstood something but surely if you recalculate the z component of the view space normal you don't need to store the sign as it will always be towards the camera?
  6. LowCalorieSoftDrink

    Object selection frustum

    So if I project the screen space rectangle onto the near plane, then use the top-left x and y as the left and top parameters of PerspectiveOffCenterLH and similarly the bottom-right x and y as the bottom and right parameters that should be the correct perspective matrix? Thanks for the help, exactly what I was looking for :) Edit: I can't type
  7. LowCalorieSoftDrink

    Object selection frustum

    Thanks for the answer. I have already found this suggested method in a previous forum post on the subject. I know it will give me the desired result but I was interested to find out if it was possible to derive a projection matrix for the screen space rectangle based on the windows projection and use this in the algorithm outlined in the "plane extraction" paper by Gil Gribb and Klaus Hartmann. If not then I'll use your suggestion
  8. LowCalorieSoftDrink

    Object selection frustum

    Hi, I'll get straight to the point. I know it's possible to derive the 6 planes of a frustum from the combination of your model-view and projection matrix and I have a system set up to do this. If I drag a rectangle over my 3d window of an arbitrary size and position can I calculate a projection matrix that I can use to construct a frustum that represents this object selection volume in 3d? I also know it's possible to project the rectangle onto the near and far plane and construct the 6 planes from these points. That is a reasonable fall back method if the above isn't possible. However if it is possible, from a curiosity point of view, and to aid my understanding of how projection matrices work and are derived I would appreciate any pointers in the right direction. I'm using DirectX in case that is important. Thanks in advance for any help!
  9. LowCalorieSoftDrink

    Starfield video

    That looks amazing, I'm staggeringly impressed by all your work though :)
  10. LowCalorieSoftDrink

    Progress...

    You can fix the texture bleeding problem by setting the wrap mode to clamp to edge //build the texture object here, glTexImage2D etc... glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); plus if you arent scaling the textures you may as well use GL_NEAREST for the filtering glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  11. LowCalorieSoftDrink

    I like templates

    Methods of a class are, for simplicitys sake, stored exactly as normal functions but with a hidden 'this' parameter. The class then stores the address of this function and the compiler passes the necessary class instance for you. So using your example the compiler generates two functions. int getNumber( c* instance ); const char* getName( a* instance ); And then each class gets a lookup table to its methods, so class a has in its lookup table: MethodLUT-Pos-1: getName: 0xAABBCCDD; class c has: MethodLUT-Pos-1: getNumber: 0xBBAACCDD; Now when you cast an instance of c to a the compiler then checks a's method LUT for the address of the function and finds getName. getName in this example doesnt actually reference any memory from the associated instance of a, only a constant, so no memory access violation occurs. I hope thats clear, some of it has been over simplified to hopefully make the explanation a bit clearer.
  12. LowCalorieSoftDrink

    Flipping Y Coordinate

    Im doing 3d (well perspective) and i need to do it because when i render to a texture opengl creates the pixel buffer from the top left, which doesnt correspond with the way a textured quad in 2d would work (there are more complex issues than just this seemingly simple problem). The most elegant maner, considering my project, to avoid special case code would be for me to alter the y coordinates while transforming to NDC. Although I dont think opengl supplies a means to do this.
  13. LowCalorieSoftDrink

    Flipping Y Coordinate

    Is there an simple way to "flip" all the y window coordinates essentially to make the origin of the viewport the top left of the screen instead of the bottom left.
  14. LowCalorieSoftDrink

    Calculating the Interia Tensor

    Thanks alot guys, got it working finally. I read the paper and I understand the principle although the derivation of the final formulas and the adaptation into code was a bit over my head. Anyway thanks again, and one last question... would you recommend using double precision floating point to calculate the inertia tensor?
  15. LowCalorieSoftDrink

    Calculating the Interia Tensor

    Well I have several types of bounding volume, the most complex being a convex hull, an object is an amalgamation of several of these bounding volumes. So the actual body for which i am trying to calculate the inertia tensor of can become quite complicated.
  • Advertisement
×

Important Information

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

GameDev.net 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!