Jump to content
  • Advertisement

Mav

Member
  • Content count

    102
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Mav

  • Rank
    Member
  1. Mav

    Organize 2D with 3D

    are you sure this batching helps? a few months ago i did something like that in openGL, batching all primitives into a vertex array before rendering. after that i implemented immediate mode into my wrapper and did some performance test and the cached version actually was slower most of the time an never significantly faster. i dont know direct3d but i assume vertex buffers are the same as vertex arrays in openGL. their advantage is you don't have to pass every single vertex through function calls but only the pointer to an array or something like that. the point is: batching the vertices into a vertex buffer just does that (passing every single vertex as a function parameter) thus eliminating the advantage of vertex buffers. i think, these are only useful if the data already exists somewhere in memory (eg a model class). but i am not an expert on 3d programming at all. don't know. if you make pure 2d, where everything is rendered in the order the rendering methods are called, you can spare using the z-buffer, thus you don't have to clear it every frame (which is costly).
  2. Mav

    tilemap trouble

    do something like this right after calling glTexImage2D (or when the tileset-texture is bound with glBindTexture): glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); hope this helps.
  3. Mav

    vector to pointer to vector

    class someclass { //yours: std::vector<memberclass*> mem; //Why don't you just store *one* pointer to the vector? std::vector<memberclass> * mem; // you can still access every item of the vector }; someclass::someclass(std::vector<memberclass> & copy) { //or, if you really want to store a vector of pointers, do it like this: std::vector<memberclass>::iterator it; for(it = copy.begin();it != copy.end();++it){ mem.push_back( &(*it) ); } }
  4. Thank you. I've taken a look at the serializer described in the Enginuity series and I think thats the way I'll go.
  5. Hi, I would be very happy if someone could help me. I am working on a client/server architecture for a game engine. I planned to use a abstract class BaseMessage and derive all message the client/server could send/receive from it. BaseMessage looks like this: class BaseMessage{ public: virtual ~BaseMessage() {} virtual Execute() = 0; /* would be overriden by the code to be executed when the message is processed by the server */ virtual Size() const = 0; // gives the size of a derived class }; The server has a std::queue<BaseMessage*> and just calls message_queue.front()->Execute() on every message before poping it. This works fine as long as client and server are on the same machine and I don't use networking. But what will happen if I memcpy a class with virtual members? Enet (which I will use) does this to create packages. What is the deal with the v-table that is contained in virtual classes. It seems a class with virtual members is 4 bytes bigger than a class without. Is this a pointer to the v-table (which would be bad) or is this an index for the v-table that would be the same on another computer? Can I just create an Enet package of my Messages derived from BaseMessage or should I think of another solution?
  6. oliii has some good tutorials on his site. may you want to have a look at them: http://uk.geocities.com/olivier_rebellion/
  7. Mav

    delete this?

    yeah, the heap/stack - thing is good to know. It's somewhat clear, but you could easily forget about that, thanks. I didn't write a copy constructor, because I don't need one. I will only use this class once.
  8. Mav

    delete this?

    Sounds like a good idea. Thank you. Can you explain why exactly you do not want do use "delete this"?
  9. Mav

    delete this?

    I don't see any violations of the rules. (I am allocating memory with 'new', you couldn't know that). bool State::AddInstruction(int name,int clip){ if(FindInstruction(name) != -1) return false; if(!instructions){ instructions = new Instruction(name,clip); //instructions the root of the tree. it's a pointer to Instruction return true; } Instruction * it = instructions; for(;;){ if((*it) < name){ if(it->left_child) {it = it->left_child;} else {it->left_child = new Instruction(name,clip); return true;} }else{ if(it->right_child) {it = it->right_child;} else {it->right_child = new Instruction(name,clip); return true;} } } } Quote: Not only that, the dtor will be called, violating another rule from that link as well. Isn't that the purpose of destructors, to get called on 'delete'? I'm quite sure, the dtor is called before the object is deleted. Quote: The user of your code will not use delete on bla now. If he has a brain. Since the user will only be me, I won't do this ;-) The tree is only part of another class and if the whole thing will be released (if it will), other users are not likely to use this sub-class. I wouldn't make sense. Thank you for your replies!
  10. I am implementing a binary tree and now I want to write a method that deletes the tree. Can I simply call "delete this;" in my method? Here's the code: //don't care about instruction_name and clip_index struct Instruction{ Instruction * left_child, * right_child; int instruction_name; int clip_index; bool operator<(Instruction & i) {return (instruction_name < i.instruction_name);} bool operator<(int name) {return (instruction_name < name);} void Print(int level) { std::cout << "Level: " << level << " Inst_Name: " << instruction_name << " Clip_Index: " << clip_index << '\n'; ++level; if(left_child) left_child->Print(level); if(right_child) right_child->Print(level); } void CopyTree(Instruction ** root){ (*root) = new Instruction(instruction_name,clip_index); if(left_child) left_child->CopyTree(&(*root)->left_child); if(right_child) right_child->CopyTree(&(*root)->right_child); } void DeleteTree(){ if(left_child) left_child->DeleteTree(); if(right_child) right_child->DeleteTree(); std::cout << "Node deleted!\n"; delete this; // will this cause any problems? } Instruction(int name, int clip) {left_child = right_child = 0; instruction_name = name; clip_index = clip;} }
  11. thank you for your replies. Quote: I suggest that you create two implementations of CoreObject: one that implements immediate mode: ImplementationImmediate::TexMap(..){ /* code of TexMapImmidiate(..) */ } And another that implements cached mode: ImplementationCached::TexMap(..){ /* code of TexMapCached(..) */ } You can then keep such an internal object inside your CoreObject instance, use delete/new to change the implementation smoothly at runtime. You can then use: CoreObject::DrawImage(..) { assert( Implementation != 0 ); Implementation->TexMap(..); } Every time. This will have the same performance as the two methods you suggested (and unless you intended to hand-optimize your own methods, it will also be faster), but will provide for either a shorter mode change function than the function pointer method or shorter functions than the if-else method. wouldn't that mean, that I have to derive ImplementationCached and ImplementationImmediate from an Implementation-base-class supporting the TexMap-method? this would mean, I had to use virtual methods, which may be even slower. And I would still have to dereference the pointer to implemenation. But I think, I'll just go with the member function pointers. The mode change function only will have to change three pointers and optimizing here will probably not bring any really speed gain.
  12. Hey, I am currently working on an 2d opengl-wrapper and I want to be able to switch between immidiate-mode and a cached mode, by calling a method (eg. CoreObject.SetMode(ogl_immidiate) or something). the drawing functions should stay the same (CoreObject.DrawImage(...);). I could just do a simple if-statement like: CoreObject::DrawImage(..){ if(immidiate_mode) TexMapImmidiate(..); else TexMapCached(..); } or I could have a member-function-pointer to the fundamental drawing-routines and do it like this: CoreObject::DrawImage(..){ (this->*TexMap)(..); } where the pointer either points to TexMapImmidiate() or TexMapCached() and is only change when SetMode is called. This way I wouldn't have to do the if-statement on every call. My question is: is it faster to dereference the member function pointer or to evaluate the if-statement? I know, it makes a *very* marginal difference, but I have to decide this now. Or which of this ways of solving the problem would you consider "cleaner"? thx
  13. Hi, I am currently working on a wrapper for OpenGL, with focus on 2D graphics. I am fairly new to both, OpenGL and C++, and mainly this wrapper thought for speeding up development of my own games. But I am thinking about releasing it to the public, maybe someone can use it. It is intended to be cross-platform (supporting all platforms GLFW supports, since I use GLFW for the initialization-stuff. This really helps since wouldn't have known how set up an OpenGL-window in linux or solaris or mac os). Would I'd like you to do is making some suggestions, what it should be able to do. Features I have already implemented are: -Setting up a Window and Initializating OpenGL for 2D -A Texture Manager for loading textures and checking whether a texture already is loaded (currently only TGA files can be load, but at least I want to support JPG, BMP, PNG and maybe there will be some kind of PAK-file format). Texture Compression is used if available but can be turned off. -Drawing quads, triangles, lines to the screen. These are sorted by texture to minimize glBindTexture() calls, which should speed up rendering. I use the depthbuffer to keep the drawing order, I am not sure if I will allow the user to give explizit z-coordinates or if that will be done automatically. Maybe at the end it will be something in between, so that automated z-coords will be between 0 and 1, and you can still set explizit z's <0 or >1, where can be sure that they will be drawn behind or in front of the automated ones. I am planning to provide some capability to draw rotated images, provide routines that can rotate a vector, support font-rendering, yeah that's all that comes to my mind right now. I would be happy about some input what people would like to see in such a project. [Edited by - Mav on February 20, 2005 4:36:35 AM]
  14. is there a way to convert spc audiofiles (used by snes-emulators like znes) to mod (or xm or it or s3m or something similar which can be played by the bass audio library)? the spc format seems to be kind of very special. if anyone knew a tool that does a conversion, this would be very nice. otherwise i'd have to convert the music to ogg or mp3, resulting in huge files. i tried to use the spc files directly (winamp can do this with a plugin), but the dll i found for this didn't work with delphi (all the examples served with the dll caused compile errors) thanks in advance
  • 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!