• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Dissipate

Cloned Texture not displayed with Linked List

30 posts in this topic

Aha here is the .log called in the Render() for 3 nodes:
*** Start Drawing Nodes ********************************
iNum = 1
m_pSquare->GetTexture() =39384576
pSprCurrent->GetTexture() =135168096

iNum = 2
m_pSquare->GetTexture() =39384576
pSprCurrent->GetTexture() =135170848

iNum = 3
m_pSquare->GetTexture() =39384576
pSprCurrent->GetTexture() =140321984

 

If you're setting same texture on all sprites, shouldn't those pointers be all the same then, or have I missed something?

0

Share this post


Link to post
Share on other sites

Please note that while I'm giving "rule of thumb" advice here, where it matters one should always measure.

 

 

This depends on the case you're testing for performance, whether it's access or management.

This is a common misconception. Linked lists have a smaller worst case asymptotic complexity for "management" tasks. That isn't the full story.

 

The most glaring weakness is that complexity analysis treats the allocation/deallocation routines as just another O(1) operation, rather than a potentially complex algorithm/data structure in it's own right. Default allocators tend to be "expensive", in that they are not O(1), or otherwise incur asynchronous costs (such as garbage collection in managed languages).

 

A more subtle problem is that it ignores the affects of the cache, which favour contiguity in dynamic arrays and the reduced memory overhead compared to linked list node pointers.

 

Finally, they take a very pessimistic view. Sometimes this is reasonable, but one must also understand that [url="http://en.wikipedia.org/wiki/Pareto_principle"]most[/url] data structures in a typical application never get a chance to reach the sizes where asymptotic complexity dominates. The constant factors that are eliminated can make up a non-negligible amount of time. The OP is probably going to be dealing with a couple of hundred sprites at most, depending on the exact nature of the game. If there were millions, or billions of sprites, then there are lot of other problems to solve, not just the performance of the game but the gameplay affects of all that complexity on the poor player!

 

In any case:

In most cases, where add/insert/delete are being called many times, it's not a correct statement, as every such call causes whole array to be reallocated. 

When implemented using "amortised constant time" algorithms, add/insert rarely causes reallocation. Most implementations do not deallocate when removing entries. The cost of insert/remove is the cost of copying the elements to "fill the gap". This can be offset by a variety of techniques, from "swap and pop", std::partition() to std::remove_if() depending on what you are doing.

 

In comparison, link list add/insert/delete do incur an allocation or deallocation of a node for each operation.

1

Share this post


Link to post
Share on other sites

@rip-off:  I'm looking into making those changes and will give a reply to that when done. (learning and implementing)

 

 In comparison, link list add/insert/delete do incur an allocation or deallocation of a node for each operation.

I bet you can sneakily just 'turn off' some nodes to later reuse them. But with the cost of finding them again. Unless another list is created that points to dead nodes. Or is that extravagent?

 

If you're setting same texture on all sprites, shouldn't those pointers be all the same then, or have I missed something?

This is the bit I don't understand. Even the array of clones (which works fine) has NULL for the m_Texure. I dont copy need to copy the texure (i dont think) as I am just pointing to the vertex buffer of the master - you know how cloneing works !! Or can this not be done the way I am attempting. Maybe I will find out what's happening as I implement a user defined copy constructor and an assignment operator then just try

m_SquareClone = m_pSquare 

Is the memory being moved around inside LPDIRECT3DVERTEXBUFFER9 ? to cause the texture to be lost.

 

0

Share this post


Link to post
Share on other sites

Are you sure that SetVertexBuffer will copy not only texture coords, but the texture resource too?

0

Share this post


Link to post
Share on other sites

 Are you sure that SetVertexBuffer will copy not only texture coords, but the texture resource too?

What that function in Clone does is:

int CSpriteManager::Clone(CSprTex* pSource, CSprTex* pDest)
{
	// vertex and index buffers
	pDest->SetVertexBuffer(pSource->GetVertexBuffer());
	pDest->SetIndexBuffer(pSource->GetIndexBuffer());

	//pDest->m_pVertexBuffer = pSource->m_pVertexBuffer; // It does this
	//pDest->m_pIndexBuffer  = pSource->m_pIndexBuffer;  // It does this

        // Copy Num of vertices, indicies and primitive count
        ...
}

Somehow the texture is tied to the device but I dont understand how see here:

g_App.GetDevice()->SetTexture(0, m_Texture); // get device is LPDIRECT3DDEVICE9

but and again here:

void CShape::Create(int iNumOfVertices, 
	  	    int iNumOfIndicies, 
		    int iPrimCount,
		    CUSTOMVERTEX* pVertices,
		    size_t iSizeOfVertices,
		    short* pIndicies,
		    size_t iSizeOfIndicies)
{	
	// Save the primitive count and number of vertices for the draw function later
	m_iNumOfVertices = iNumOfVertices;
	m_iNumOfIndicies = iNumOfIndicies;
	m_iPrimCount	 = iPrimCount;

    // Create a vertex buffer interface called m_VertexBuffer
    g_App.GetDevice()->CreateVertexBuffer(iNumOfVertices*sizeof(CUSTOMVERTEX),
 					  0,
					  CUSTOMFVF,
					  D3DPOOL_MANAGED,
					  &m_pVertexBuffer,
					  NULL);
...
    // Lock vertex buffer and load the vertices into it
...
    // Create an index buffer interface called i_buffer
...
}

Somehow they reside inside the LPDIRECT3DDEVICE9 attached in some manner. So then how do diffferant objects that call the functions, like create and set, get assigned a differant vertex buffer or texture?

 

(...still working on implementing rip-offs suggestions)

0

Share this post


Link to post
Share on other sites

Posted 24 January 2013 - 05:49 PM

DeleteAllNodes definitely contains a bug, it fails to clear the "head" and "tail" pointers. CNode calls "delete" on a VOID pointer, which is undefined. You should use templates to maintain type safety. The destructor does not deallocate memory.
The lack of copy constructors and assignment operators on the two classes is also problematic. You need to obey the rule of three, or "disable" copying and assignment by declaring the copy constructor and assignment operator as private, and not implementing them.
I don't see any other major bugs, but due to the unencapsulated implementation every single client access needs to be perfectly correct or it could corrupt the loop.
There are a few minor issues too:
(m_uNodeType != CNODE_HEAD) || (m_uNodeType != CNODE_END) is a tautology. Consider, if X is any number, then (X != 1) || (x != 2) is true.
You don't need to check a pointer is NULL before calling delete - delete does the right thing with null pointers and you are duplicating those checks.
You don't need to have two value nodes in the linked list. Most implementations just have a pair of pointers to nodes. Using such "sentinel" nodes isn't necessarily a bad thing, it is a valid implementation strategy, but you should not force client code to reason about this.
You don't need the "node type" concept. Just have the head and tail contain NULL data pointers.
Don't depend on Windows.h: just use void * rather than VOID * if it was necessary
Use an enum rather than #defines for something like "node type", if it was necessary
Main.h is almost always a poor idea.
In general, strive for as few dependencies as possible, particularly for something generic like a linked list. Avoid coupling this implementation to the rest of your project



I have made all the changes you suggested, making a Circular, templated, doubley linked list and applying the rule of three. Implementing this into my project and utilising it does not solve the problem (I'll research dynamic arrays later!). Please can you help me understand whats happening as I can't continue otherwise. Maybe someone can post a short excerpt/code-list on how to clone and draw a textured quad. My D3DXSprite clones fine.
(hoping...!)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0