Jump to content

  • Log In with Google      Sign In   
  • Create Account


Conny14156

Member Since 27 Nov 2012
Offline Last Active Jul 04 2014 08:26 PM
-----

#5142975 Help to understand my own misstake?

Posted by Conny14156 on 28 March 2014 - 08:08 PM

i feel stupid and thanks >.<




#5141255 Why does this work?(Class prototype?)

Posted by Conny14156 on 22 March 2014 - 11:48 AM

Hi,

I was wondering if anyone could tell me if I should do it this way and why it works

 

I have two classes, class A and class B in two differently headers.

 

in class A header I have

#include "b.h"
class a
{
  b testVar;
}

and in class B Header I have 

#include "a.h"
class b
{
 a testVar;
}

if I do it this way, the compiler gonna complains about alot of stuffs >.<,

but instead of including I somehow(accidently) got

class a;
class b
{
  a testVar;
}

and I was wondering how this worked? is it like extern/global variables? or is it more of a function prototype, but how would class a inside b.h, knows that it got defined inside a.h? and how come those two doesnt clash in name if it doesnt work as a prototype? 




#5038005 return std::map Question[Solved]!

Posted by Conny14156 on 01 March 2013 - 07:48 AM

operator[] is a read + write operation. If the specified key doesn't exist, then it is inserted into the map.

If you want to look up an item that might be in the map, without adding it in cases where it doesn't exist, then use find instead of [].

oh, >.<

Took me so long to write my last post without noticing a new reply thanks, will check it asap to see if that is the case!




#5038004 return std::map Question[Solved]!

Posted by Conny14156 on 01 March 2013 - 07:47 AM

Oh, Sorry It was late at night >.< (Around 4 in the morning XD) Let me try it again.

 

What am trying to do is to avoid loading more than one of each texture file, so I made a std::map wtih the texture name as the key and the value would be a ID3D11ShaderResourceView* that contain the texture.

 

Each time I "Load" a model with materials it would check if the material would already exist inside the map, to avoid loading multipile  time of the same texture.

if the texture already had been loaded i would get it by calling RequestTexture which looks like this

ID3D11ShaderResourceView* GfxHandler::RequestTexture(std::string textureName)
{
    if(TotalTexture.find(textureName) != TotalTexture.end())
    {
        MessageBox(0,"Request Granted",textureName.c_str(),MB_OK);
        TotalTextureCounter[textureName]++;
        return TotalTexture[textureName];
    }
    else
    {
        MessageBox(0,"Request Failed",textureName.c_str(),MB_OK);
    }    
    return false;
}

 

Where the TotalTexture and TotalTexture looks like

std::map<std::string,ID3D11ShaderResourceView*> TotalTexture;
std::map<std::string,int> TotalTextureCounter;

 

The ReqeustTexture returns a shader resource which I assign and insert into a seperate class which I would call the "Model", the model class have its own map which looks like the same except the only texture that gets inserted there would be the materials that the model use, the reason why I try to do this is to avoid unnecessary looping inside the bigger map.

 

This is how I do it inside my LoadModel

Its works great, my Testing does indeed get the same adress as the loaded texture from the map


ID3D11ShaderResourceView* Testing = 0;
Gfx->LoadTextureOld(Model->Texture.Diffuse.Location,Model->Texture.Diffuse.TextureOld,Model->Texture.Diffuse.Sampler);
for(int i = 0; i < Model->Materials.size();i++)
{
	Model->Materials[i].materialName += ".jpg";
	if(Gfx->TotalTexture.find(Model->Materials[i].materialName) == Gfx->TotalTexture.end())
		{
	
		Gfx->LoadTexture(Model->Materials[i].materialName,Testing);
			Model->Texture.Diffuse.Texture.insert(Model->Texture.Diffuse.Texture.end(),std::pair<std::string,ID3D11ShaderResourceView*>(Model->Materials[i].materialName,Model->Texture.Diffuse.TextureOld));
			Gfx->RequestInsertionOfTexture(Model->Materials[i].materialName,Testing);
	//		Gfx->TotalTexture.insert(Gfx->TotalTexture.end(),std::pair<std::string,ID3D11ShaderResourceView*>(Model->Materials[i].materialName,Testing));
			
		}
		else
		{
			Testing = Gfx->RequestTexture(Model->Materials[i].materialName);	
	 		Model->Texture.Diffuse.Texture.insert(Model->Texture.Diffuse.Texture.end(),std::pair<std::string,ID3D11ShaderResourceView*>(Model->Materials[i].materialName,Model->Texture.Diffuse.TextureOld));
			//Gfx->RequestInsertionOfTexture(Model->Materials[i].materialName,Testing);
	//		Gfx->TotalTexture.insert(Gfx->TotalTexture.end(),std::pair<std::string,ID3D11ShaderResourceView*>(Model->Materials[i].materialName,Testing));
			
		}
	}
 

 

Now when Am trying to render my object, I try to change material depending on what group it is.

So I did something like this


for(int i = 0; i < Model->Total.Group; i++)
	{
		if(Model->lastMaterial != Model->groupMaterial[i])
		{
                  //First method
                  Model->lastMaterial = Model->groupMaterial[i];
                  Gfx->D3d11DevCon->PSSetShaderResources(0,1,& Model->Texture.Diffuse.Texture[Model->lastMaterial]);//<---- //Texture
// */

//Second method Model->lastMaterial = Model->groupMaterial[i]; pt = Model->Texture.Diffuse.Texture[Model->lastMaterial]; Gfx->D3d11DevCon->PSSetShaderResources(0,1,&pt);//<---- Texture


         //*/

} Gfx->D3d11DevCon->DrawIndexed ( Model->DrawingIndexIndices.IndexCount[i], Model->DrawingIndexIndices.StartIndex[i], 0 ); }

 

In which case instead of getting the texture it somehow decided to insert the texture 

like this




#5014967 I tried to do a simple factory but ended up with a wierd error?

Posted by Conny14156 on 27 December 2012 - 10:43 PM

Hi,

I tried to do a basic hopefully almost correct factory where its simply just return new "insert class here".

Here the class I want to dublicate/create with my factory

class Enity
{
public:	
        Enity(){};
	std::vector<BaseComponent> ComponentList;
	template<class ComponentType>
	void AddComponent(ComponentType type);
	void Destroy();
};

 

Here the factory class, which Sit in a header btw

class BasicFactory
{
public:
	BasicFactory(){}
	virtual ~BasicFactory(){}

	template<class EnityType>
	EnityType* InstantiateEnity(EnityType type);
};
class EnityFactory : public BasicFactory
{
public:
	EnityFactory(){}
	virtual ~EnityFactory(){}
	template<class EnityType>
	Enity* InstantiateEnity(EnityType type);

};

 

And here I declared the function to the factory

 


template<class EnityType>
Enity* EnityFactory:: InstantiateEnity(EnityType type)
{
	return new type;
}

Seems like even a Idiot guide is to advance for me :(

http://www.codeproject.com/Articles/257589/An-Idiots-Guide-to-Cplusplus-Templates-Part-1

and here's the tutorial I kinda followed

 

 

Here what I tried to do

Enity TestComp;
std::vector<Enity> vEnity;
std::vector<Enity>::iterator vEnityEnd;
int vEnityMax = 10;

EnityFactory eFactory;
int vEnitySize = 0;





void Update()
{
	vEnitySize = vEnity.size();
	vEnityEnd = vEnity.end();
	if(vEnitySize < vEnityMax)
	{
		//MessageBox(0,"Lets hope this work","Enity have NOT Increased by 1 yet!",MB_OK);
TestComp = &eFactory.InstantiateEnity(Enity); <- error of illegal use of this type as an expression
		vEnity.insert(vEnityEnd,TestComp);
		MessageBox(0,"Screw This","Enity Increased by 1!",MB_OK);
	}

	Test.Update(pWCamera);
	TestB.Update(pWCamera);
}

 

 

 




PARTNERS