Skip to main content
GameDev.net gamedev.net
🔒 Locked

Dynamic array as static data member

Started by acidleaf Dec 7, 2010 at 11:54 PM 1 replies 650+ views
Original Post
acidleaf
acidleaf
Hello GD! This is my first post here, nice to meet you all! Currently I'm taking baby steps into DirectX, and I have a question that I'm not sure if it fits into this forum...so admins please move it to the correct one if needed! Thanks!

I am making a game where a spaceship is flying through space avoiding asteroids. There are four kinds of asteroids, each differing in shape, and they are loaded in as meshes. I find that loading the mesh each time an asteroid is created is a waste of CPU, so I've decided to make a manager class for it. The manager class will be responsible for loading each mesh at runtime and passing out pointers to these meshes for each instance of the asteroid to be drawn. My first question is, is this approach appropriate?

And my second question, here's my code:

AsteroidManager.h:
class AsteroidManager {	const static int NUM_MESHES = 4;	static LPD3DXMESH _mesh[NUM_MESHES];	static D3DMATERIAL9 **_materials;	static LPDIRECT3DTEXTURE9 **_textures;	static DWORD *_numMat;	public:	static bool loadMeshes();};


AsteroidManager.cpp:
#inclulde "AsteroidManager.h"LPD3DXMESH AsteroidManager::_mesh[NUM_MESHES];D3DMATERIAL9 AsteroidManager::**_materials;LPDIRECT3DTEXTURE9 AsteroidManager::**_textures;DWORD AsteroidManager::*_numMat;bool AsteroidManager::loadMeshes() {	_materials = new D3DMATERIAL9*[NUM_MESHES];	_textures = new LPDIRECT3DTEXTURE9*[NUM_MESHES];	_numMat = new DWORD[NUM_MESHES];	// The rest goes here	// ...	return true;}


loadMeshes is called during initialization of my game. When I compile my program, it gives:
error LNK2001: unresolved external symbol "private: static unsigned long * AsteroidManager::_numMat" (?_numMat@AsteroidManager@@0PAKA)error LNK2001: unresolved external symbol "private: static struct IDirect3DTexture9 * * * AsteroidManager::_textures" (?_textures@AsteroidManager@@0PAPAPAUIDirect3DTexture9@@A)error LNK2001: unresolved external symbol "private: static struct _D3DMATERIAL9 * * AsteroidManager::_materials" (?_materials@MeteorManager@@0PAPAU_D3DMATERIAL9@@A)


Am I declaring my variables correctly? Please guide me :(

Thanks alot for your time!
rip-off
rip-off
The pointer asterisks go before the "AsteroidManager::" part. You are declaring pointers to members with your current setup.
LPD3DXMESH AsteroidManager::_mesh[NUM_MESHES];D3DMATERIAL9 **AsteroidManager::_materials;LPDIRECT3DTEXTURE9 **AsteroidManager::_textures;DWORD *AsteroidManager::_numMat;


Also if all the arrays are going to share the same size consider grouping the data into a structure and having an array of that. Also, consider using std::vector<> rather than maintaining a pointer,count pair.

Finally such static data is usually a bad idea, but one step at a time for the moment, get it working and if you're interested about improving your design come back to us.
acidleaf
acidleaf
Hi! Thanks for your reply. That worked perfectly! I will continue on my design and see if it works.

Thank you :D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.