lordimmortal2

Members
  • Content count

    57
  • Joined

  • Last visited

Community Reputation

130 Neutral

About lordimmortal2

  • Rank
    Member
  1.   From what I recall, you can pass in a ID3DXSprite-Pointer to the ID3DXFonts draw method, in which case flushing the text will be drawn in respect to the sprite - you'd want to do that anyway, since it will speed up text rendering, and it should also fix your issue. Unfortunately there really is no other way then to flush whenever you change the clip rect. The only way around it would be to implement your own sprite renderer with a software clip rect, but this tends to be slightly slower than the hardware-equivalent. Yet, if doing so enables you to draw ALL sprites like from your gui in one draw call instead of multiple ones needed in case of the ID3DXSprite, the price might be well worth paying and can actually result in a speedup.   Oh wow. I was already passing in a ID3DXSprite pointer to the ID3DXFonts draw. I guess I didn't put two and two together and realize that it was doing that to actually draw the text =P. I guess I'll just flush every time I need to scissor clip these things. Thanks for the answer, it's working now.
  2. Recently I've been finishing up clipping for my GUI, which is just now being tested. To clip something, I've been trying to use the scissor test in DX9, and I would need it to be applied per draw call (both for something passed to the sprite interface and for text). While messing around with this, I've deduced that DX9 doesn't apply the scissor test every draw call, instead it applies it when its rendering ends or is told to render everything it has.    So, the only way I've gotten the scissor test to work is by calling flush immediately after I draw the sprite, but this wouldn't work with my text objects (on account of the ID3DXFont interface not allowing you to prematurely flush the text to the screen, unless there's something I'm missing), so this isn't a sufficient solution.    Is there an easier way to get the scissor test to work per-draw and if so how? If not, are there any replacements?
  3. That would indeed work. What would be the best way to do this? Push the object into a container to be iterated through next frame with its changes marked somehow?   Just mark the object as dirty and look for that in the update function, if it is dirty it might also need to check the children. Reset the flag after that update iteration and continue on as usual.   Done. And it works. Thanks a bunch for the help.
  4. That would indeed work. What would be the best way to do this? Push the object into a container to be iterated through next frame with its changes marked somehow?
  5. I'm developing a GUI system for my game and I've been in the process of redoing all of the positional information for widgets and I've run into a problem.    All widgets derive from a base class - GuiObject - that contains all positional information needed for an object: widths, heights, points, bounds, etc. Whenever you modify one of these attributes, the function that changes it calls another function - Update - to make sure everything stays in sync.   The problem comes in when trying to extend this to the widgets themselves. A widget sometimes needs to update itself as well - maybe it needs to move a child widget around or adjust its own size based upon some children widgets. My question would be how to handle this as elegantly as possible.   If I were to override the Update function in my derived widget classes like so: void Widget::Update() {     GuiObject::Update(); // Update the underlying GuiObject     // Do updating of the widget itself here } And I tried to put a GuiObject's modification function in this overridden function, like trying to change the size of the underlying GuiObject, then it'll get stuck in an infinite loop and crash from a stack overflow: void Widget::Update() {     GuiObject::Update(); // Update the underlying GuiObject     SetSize(100, 100); // Set width and height to 100 } SetSize will set the width and height of the base GuiObject, and then call Update, which resolves to the Widget::Update overridden function, which calls SetSize, which calls Update, etc.   I've tried various things, like splitting up the implementation of GuiObject::Update, setting a new pure virtual function in GuiObject to call at the end of Update to allow derived classes to put in specialized updating logic, but they all result in the end at an infinite loop.    My current thought would be to make new functions in GuiObject that are versions of the functions that you can use to modify a GuiObject with public access, make them protected, give them a new name, not include the GuiObject::Update() call from their public counterparts, and then only call them from within the Update function of derived widget classes; but that doesn't seem very appealing because it'd be very easy to mess up (calling the public version in a derived class' Update function would result in the infinite loop) and it'd essentially double the amount of functions GuiObject has to maintain.   So what I'm wondering, for everyone who has made it through this moderate wall of text, is there a better way to handle automatic updating of a widget derived from a GuiObject? The least error prone way to do it would be to somehow update the widget whenever a modifying function from the GuiObject is called and I can't seem to figure out anyway to elegantly break the infinite loop.   Thanks for reading and I appreciate any and all replies.
  6. [quote name='yewbie' timestamp='1347469552' post='4979367'] Which functions are you using to draw? DrawPrimitive ? Are you using any Dx9 wrappers or just raw directx? [/quote] There's always something I'm not clear enough on. This is specifically just a 2D game, and I'm using the sprite method of DirectX along with the draw function. I'm not drawing with textured quads. As for if I'm using any DX9 wrappers or just raw DirectX, if I understand you correctly it's the latter. I've created everything besides the calls to the DX and Windows APIs. [quote]Please elaborate on what "nothing" means: none of the sprites show up, or their order is incorrect? Can you get a single sprite to show up?[/quote] I'm sorry that was really horribly worded. To elaborate - I can get things to draw, and sometimes they draw in the correct order but other times they don't. Right now, just for test purposes I have a background sprite draw behind all the GUI elements I need to draw for the main menu, but when I try to draw my options menu within the actual game, it gets drawn behind everything else. I'm drawing everything in the order of bottom to top, from the main menu to the game. Specifically what I'm looking for is just a simplistic list of what you're supposed to do to get this to work, ideally with the z-coordinate. [quote]If you disable reading/checking the depth buffer, and draw your sprites far-to-near, you're doing what you intend to. I would also like to know what you mean by "nothing" And, not to nitpick, but there really is no "2D portion of DX9". It typically depends on the projection matrix how things are displayed, though. I understand what you're saying...[/quote] Again, really horribly worded. I'm not using textured quads to render any of this stuff, just draw calls to a "LPD3DXSPRITE". And by "nothing" I meant "it's not doing what I want it to do, IE drawing things behind something I don't want it to." I need to work on my choice of words.
  7. I'm currently working with DirectX 9 (specifically the 2D portion of it) and would like to draw sprites in front of each other in a particular order. I have tried drawing sprites from bottom to top and also using the Z coordinate of the draw function, but still nothing. I'm probably missing something simple, but anyway you can do it with DX9 would be appreciated. Thanks for reading and any replies.
  8. [quote name='Ripiz' timestamp='1336715904' post='4939215'] This looks like basic mistake. TileContainer is a class, not variable, and you cannot store objects in a class, they're stored in an object. I think you want to do this: [CODE] TileContainer myTileContainer; // probably should be member of TileHandler, not local variable myTileContainer.push_back(tile); [/CODE] [/quote] I believe this fixed it (at least it compiled correctly when I changed it to something like this). Thank you for your help =). [quote]You've got a vector of Tile, but you're trying to push_back a Tile* (pointer to Tile). Perhaps try changing your code to: Tile tile; tile.rowPos = row; tile.colPos = column; tile.rowSpr = rowSpr; tile.colSpr = colSpr; TileContainer.push_back(tile); The whole point of vector is so that you don't have to use pointers and new/delete to store things in an array. All of the heap memory is automatically allocated/deallocated for you by the vector class. Perhaps I'm misreading what you're trying to do, but it doesn't seem like pointers are at all necessary here.[/quote] This is for adding a new tile for my engine to render. The way I'm at least attempting to do it right now is create a new struct of a tile, pushing that into a vector, and then iterating along the vector to render all tiles. [quote] [url="http://www.gamedev.net/index.php?app=forums&module=forums&section=findpost&pid=4939218"][img]http://public.gamedev.net//public/style_images/master/snapback.png[/img][/url]taby, on 11 May 2012 - 12:07 AM, said: You've got a vector of Tile, but you're trying to push_back a Tile* (pointer to Tile). Perhaps try changing your code to: Tile tile; tile.rowPos = row; tile.colPos = column; tile.rowSpr = rowSpr; tile.colSpr = colSpr; TileContainer.push_back(tile); The whole point of vector is so that you don't have to use pointers and new/delete to store things in an array. All of the heap memory is automatically allocated/deallocated for you by the vector class. Perhaps I'm misreading what you're trying to do, but it doesn't seem like pointers are at all necessary here. That is part of the problem yes and the cause of the compile error but as soon as the compile error is fixed another one should pop up informing you that you are using a class definition as a variable. To fix that one have a look at the Ripiz post above as that solution will fix your next problem. For all STL containers, the object value you are trying to put into the container must match the type definition of the container, eg: std::vector<int> m_intVector; //This can only hold variable of type int std::vector<int*> m_intPointerVector; //This will only hold variables of type int* Be carefull with deep and shallow copies of data you push into the vector as the vector will actual make a copy of the object you pass in to [url="http://www.cplusplus.com/reference/stl/vector/push_back/"]push_back[/url] and store that in the vector. [/quote] So can I assume that I'm doing something else wrong more so than trying to use a data type as an object of this data type? =P [quote]First thing: TileContainer is just a redefinition of std::vector<Tile> . So you need to create a TileContainer: TileContainer tileContainer; Second thing: you declare TileContainer to hold a Tile. You then declare a Tile pointer (Tile*) and then dynamically allocate memory for a Tile (new Tile()). Your vector container does not store Tile*, so you would need to need to either do: Tile tile; ... ... tileContainer.push_back(tile); or do: tileContainer.push_back(*tile); // dereference the pointer to put a copy of the object into the vector delete tile; [/quote] Thanks for the catch, really would be bad to have that memory leak in there =P. [quote] [url="http://www.gamedev.net/index.php?app=forums&module=forums&section=findpost&pid=4939406"][img]http://public.gamedev.net//public/style_images/master/snapback.png[/img][/url]taby, on 11 May 2012 - 02:49 PM, said: Clearly I missed something here, because everyone is talking about TileContainer being a class and not a variable? Where was the class defined? What the? The typedef enables the alternative name [i]TileContainer[/i] to be used instead of the more verbose [i]std::vector<Tile*>[/i]: typedef std::vector<Tile> TileContainer; So either the OP intended to declare a variable but mistakenly added the typedef keyword, or he/she forgot to declare a (member) variable of type [i]TileContainer[/i] (or[i] std:vector<Tile*>[/i]) alltogether. [/quote] It was the latter. Stared at this for 20 minutes and nothing popped into my head about what was wrong...been so long since I've programmed last. Thanks everyone for your help I really appreciate it =). I'll post again if I have anymore questions.
  9. In addition to my ignorance on templates, I am also pretty dumb on std::vector =P. I can't figure this bug out as I'm not quite sure why it's not working. TileContainer.cpp: [CODE] void TileHandler::AddTile(int row, int column, int rowSpr, int colSpr) { Tile *tile = new Tile; tile->rowPos = row; tile->colPos = column; tile->rowSpr = rowSpr; tile->colSpr = colSpr; TileContainer.push_back(tile); } [/CODE] TileContainer is of type: [CODE]typedef std::vector<Tile> TileContainer;[/CODE] And the error is: [img]http://i49.tinypic.com/2r27qs6.png[/img] First thought was to mess around and make tile a double pointer, and things of this nature, but nothing worked. If anyone knows what's wrong with it, your answer is very appreciated.
  10. [quote name='Hodgman' timestamp='1336708802' post='4939197'] Where is the class cLinkedList declared? [/quote] That's a good question =P. They were supposed to be free functions, but for some reason I made them a part of a class and then deleted the class and...this is what I get for going back to year-old code. Thanks for the help, should've realized that sooner. Fixed it =).
  11. I have some code that tries to create a linked list out of vectors and using templates for the first time I guess it's inevitable that it'll be wrong =P. The relevance (LinkedList.h): [CODE] #pragma once #include <vector> #include "Main.h" template <typename T> int FindEmptyID(std::vector<T*> &vector) { if(list.empty()) { return DEFAULT_ID; } else { typename std::list<T*>::iterator i = list.begin(); int previousId = (*i)->ID(); i++; for(; i != list.end(); i++) { int currentId = (*i)->ID(); if(currentId - previousId > 1) { return previousId + 1; } previousId = currentId; } return previousId + 1; } } template <typename T> T * cLinkedList <T>::ScanListPrevious(std::vector<T*> &vector, int ID) { T *previous = 0; for(typename std::list<T*>::iterator i = list.begin() ; i != list.end() ; ++i) { T *object = *i; if(object->ID() == ID) { return previous; } previous = object; } return 0; } template <typename T> T * cLinkedList <T>::ScanList(std::vector<T*> &vector, int ID) { for(typename std::list<T *>::iterator i = list.begin(); i != list.end(); ++i) { T *object = *i; if(object->ID() == ID) { return object; } } return 0; } [/CODE] LinkedList.h gets called in (and used only in) TileContainer.h where it's used to typecast some things. TileContainer.h: [CODE] #pragma once #include "LinkedList.h" #include "sSprite.h" class LayerContainer { public: int ID; LayerContainer(); ~LayerContainer(); private: LayerContainer* layers; }; class TileContainer { public: sSprite background, middle, foreground; // Graphical rendering of the tile int rowPos, colPos; // Position of the tile int rowSpr, colSpr; // Position of the sprite from the sprite sheet to render int ID; int layerNum; // Function declarations TileContainer(); ~TileContainer(); void AddTile(int row, int column, int size, int rowSpr, int colSpr); void ChangeTileSprite(sSprite sprite, int depth, int ID); void AddTileLayer(sSprite sprite, int row, int col); void AddTileLayer(sSprite sprite, int ID); private: TileContainer* tiles; }; typedef std::vector<LayerContainer> LayerContainer; typedef std::vector<TileContainer> TileContainer; [/CODE] The errors: [img]http://i50.tinypic.com/1hft3a.png[/img] I'm not quite sure what's wrong with it and the errors don't really help me (perhaps if I knew more about templates), so if anyone could point me in the right direction it'd me much appreciated.
  12. [quote name='bradbobak' timestamp='1327563882' post='4906348'] header guards (or pragma once) just make sure that the header file is read one time per tu (translation unit). so if a.cpp includes it, and b.cpp includes it, and you compile a.cpp and b.cpp separately, there will be 2 instances of 'LogicContainer logic'. Simplest solution is to put 'extern LogicContainer logic' in the header file, and define 'LogicContainer logic' in some .cpp that will be linked in. [/quote] Thanks a lot, that worked. Really should've knew that in the first place but I guess that's what I get for being away from C++ for so long =/. Thanks again! =)
  13. I'm sure it's something really silly but it appears that neither #pragma once nor #ifndef (and the accompanying commands) does not make the file only get defined once with object instances. Case in point: [CODE] #pragma once class LogicContainer { private: public: LogicContainer(); ~LogicContainer(); void Logic(); void Loop(); void GenerateTiles(); void CleanGame(); int GetRandNum(); }; LogicContainer logic;[/CODE] Generates: [quote]1>Main.obj : error LNK2005: "class LogicContainer logic" (?logic@@3VLogicContainer@@A) already defined in LogicContainer.obj[/quote] This file is included in two different files (LogicContainer.cpp for class function defining and in main for class function calling). Shouldn't the "#pragma once" stop "LogicContainer logic;" from being defined twice? I would like for this object to be defined within this file if possible.
  14. I've been trying to teach myself programming for the past 3 years (specifically C++ in relation to video games). And one of the best questions to ask I never really asked so here it is: I've been just trying to create games and see what problems arise and then try to fix them but this is a frustrating way for me to teach myself. So what's the best way to self-teach yourself in game programming? It'll probably be dependent on the type of person, but I'm just wondering about how else I could go about it? As always, all replies are appreciated.
  15. [quote name='rip-off' timestamp='1321010872' post='4882902'] [quote] These worked perfectly until I made them a template. [/quote] Just because they worked doesn't mean that they were a good design! =] [quote] The functions are given the node and then iterate through the entirety until they reach the end. [/quote] Actually, that isn't true. Your functions (apart from ScanListEnd) don't really work if you call them on an arbitrary LinkedList object. The list isn't bi-directional you cannot guarantee you've searched it exhaustively. There is no hint in the API that suggests you must call these functions on the "root" node. Indeed, in your functions you have comments saying "Start at the beginning of the list", but that is an assumption. I recommend you replace this concept of a "head node" with a std::list<> instance. You can then write free functions to implement your search-by-id logic. By separating the container logic from the objects themselves, you can guarantee exhaustive searches - any code that can reach the list can reach the entire list. It also means that the objects themselves don't need to worry about being part of a container. They can concentrate on being individual Tiles, Layers or Entities. Here is an example: [code] template<typename T> int FindEmptyID(std::list<T*> &list) { if(list.empty()) { return DEFAULT_ID; // Might be 0 or 1, or something else, I don't know } else { typename std::list<T*>::iterator i = list.begin(); int previousId = (*i)->ID(); ++i for( ; i != list.end() ; ++i) { int currentId = (*i)->ID(); if(currentId - previousId > 1) { return previousId + 1; } previousId = currentId; } return previousId + 1; } } template<typename T> T * ScanListPrevious(std::list<T*> &list, int ID) { T *previous = 0; for(typename std::list<T*>::iterator i = list.begin() ; i != list.end() ; ++i) { T *object = *i; if(object->ID() == ID) { return previous; } previous = object; } return 0; } template<typename T> T * ScanList(std::list<T *> &list, int ID) { for(typename std::list<T *>::iterator i = list.begin() ; i != list.end() ; ++i) { T *object = *i; if(object->ID() == ID) { return object; } } return 0; } typedef std::list<Tile *> TileContainer; typedef std::list<Layer *> LayerContainer; typedef std::list<Entity *> EntityContainer; [/code] Something like that. I haven't compiled or tested the code, but I expect that it is the correct "shape". Though I'd probably recommend using std::vector over std::list if you expect to be doing lots of searching like that. [hr] As an aside, you really don't want to be writing code that checks if "this" is null, unless it is an assertion perhaps. Relying on undefined behaviour like invoking a member function on a NULL pointer is a brittle way to program. [/quote] Thanks for your replies and code. Could you explain how you would use these and where I would place them? Since you got rid of them being part of cLinkedList.