Jump to content

  • Log In with Google      Sign In   
  • Create Account


SiS-Shadowman

Member Since 21 Feb 2006
Offline Last Active Apr 25 2013 11:52 AM
-----

#4865956 Winsock difficulties

Posted by SiS-Shadowman on 26 September 2011 - 12:33 AM

HP: Your hostility is unbelievable. I came to this forum seeking knowledge, not abuse.


I didn't hear such a hostility. He gave you a hint to where to find such knowledge (eg. the library) ;)


Once you have a better understanding of the means of communication you can come back to actually implement it.




#4861904 Component Based Entity System Question

Posted by SiS-Shadowman on 14 September 2011 - 11:21 PM


My system is pretty similar to yours, but instead of the entities holding the attributes, components do. When another component requires the same attribute, it must say so when it's attached to the entity (via requirements). Anyways, I have a big entity system that consists of subsystems. Each subsystem handles ONE specific type of a component. The one system holds all renderables, the other one all collidables, and so forth. This way I can render all renderables "at once" (the subsystem obviously holds an entity => component dictionary) and do collision tests for all components in the other subsystem.

So basically you add one system per component (sometimes I do need a small hierarchy in components, so I've restricted my rule to having one subsystem per DIRECT subclass of component: all further subclasses are put into the same system). If you're interested, I can send you my sources.


It is not completely obvious to me why a sub-system holds a dictionary of entity -> component (I assume by component, it is the actual component the sub-system deals with) that may be because:

A. My components can keep references to attributes that the entity has. (If you need position from the entity in the dictionary)
B. My components have a reference to the entity that contains it.

Do your components not know about their entities?

Yes, in fact they do. This is because my entities don't have a list of components attached to them, instead the subsystems take care of that. I figured that I'll propbably never need to get ALL components of an entity, only a subset.


When creating an entity, it only references the entitysystem it has been created with. Upon adding a component, for examble your Renderable3D, the entity defers the call to the entity system, which in fact defers the call to the right sub-system. It will in return add the (entity, renderable) pair into it's dictionary.

Entity e = entitySystem.CreateEntity();
e.Add(alreadyExistingRenderable3DComponent);

I solved the attribute problem by allowing components to reference other components, in fact, each component type specifies a Template that describes what this component actually requires. For example a renderable would require a transformable (everything that can be rendered must have a translation). This requirement now changes the process a bit. Upon adding the Renderable component, the entitysystem verifies that ALL requirements are met and if they are, the component is added. Otherwise an exception is thrown, containing all requirements that are not met. (The same procedure is done upon removing a component).


Entity e1 = entitySystem.CreateEntity();

e1.Add(new Transformable());

e1.Add(new Renderable3D());

Entity e2 = entitySystem.CreateEntity();

e2.Add(new Renderable3D()); //< throws because the transformable component is missing


That very same template can be used to construct a component (because it is in fact a string => object dictionary + a list of required components) through a subsystem. My subsystems are not only responsible for calling update / draw on their components, the also serve as factories to create a component from a certain template. On top of that I have a template collection that describes an entire entity. This way I can create a template for a starship, store that template somewhere and finally create a thousand starships, only passing that template to the entity system.

var template = new EntityTemplate();
dynamic transformable = ComponentTemplate.FromType<Transformable>();
transformable.Position = new Point(10, 100, -15);
transformable.Orientation = new Quaternion(....);
dynamic renderable = ComponentTemplate.FromType<Renderable>();
renderable.Mesh = "bunny.x";
renderable.Material = "bla"
template.Add(transformable);
template.Add(renderable);

Entity entity = entitySystem.CreateEntity(template);
// Entity now contains 2 components (transformable and renderable)

// Both components will have all properties extracted from the template upon construction



FYI: I'm using IronPython to describe all my components & entities, so I can simply redefine them while the game is running (and hence my c# example using the "dreaded" dynamic).

*edit* I forgot to mention that when retrieving a specific component from an entity, you specify it's type. The entity simply delegates the call to the entity system which in turn delegates it to the subsystem, responsible for that type (this method is mostly used upon entity creation and when components are attached):



Transformable t = e.Component<Transformable>();

Renderable3D r = e.Component<Renderable3D>();


*edit2* So to sum it up, the ENTIRE state is kept in the entity system. All a user has to do is to have a reference to it. The entity system takes care of registering the components with the right sub-system. This way you don't need global access to the renderer because the right sub-system has access to it (because it was given the renderer during construction), no need for global access to the physics simulator because of the very same reason.





#4861535 Component Based Entity System Question

Posted by SiS-Shadowman on 14 September 2011 - 07:25 AM

My system is pretty similar to yours, but instead of the entities holding the attributes, components do. When another component requires the same attribute, it must say so when it's attached to the entity (via requirements). Anyways, I have a big entity system that consists of subsystems. Each subsystem handles ONE specific type of a component. The one system holds all renderables, the other one all collidables, and so forth. This way I can render all renderables "at once" (the subsystem obviously holds an entity => component dictionary) and do collision tests for all components in the other subsystem.

So basically you add one system per component (sometimes I do need a small hierarchy in components, so I've restricted my rule to having one subsystem per DIRECT subclass of component: all further subclasses are put into the same system). If you're interested, I can send you my sources.




#4857523 Home Servers and Source Control

Posted by SiS-Shadowman on 04 September 2011 - 10:02 AM

Assuming you have a standard connection to the internet (ie. a router + dynamic ip address):

You could establish a Virtual Private Network (for example with OpenVPN, etc...) and then setup a dynamic DNS service to bind your dynamic ip to a domain of your choice. Furthermore you forward a port of your choice (whatever your VPN uses) to your linux machine and then configure the router (if supported) to automatically report your ip to the dynamic DNS provider. Your client then simply joins the vpn that has been established by your server.




#4855155 What does GDNet think about my game engine?

Posted by SiS-Shadowman on 29 August 2011 - 12:12 PM

Yes, I agree. The problem is that the project is still in alpha and I really don't see the point in marketing it at the moment... Really this post was simply to see what response I would get from my current progress. The main thing I'm starting to question is if it was really a good idea to open source it...


This thread gave you a lot of invaluable hints on how to improve your code. What point is there to ask other people's opinions if all you want is a pat on the back? You should take those comments at heart and use them for good, but it's up to you. You should also ask yourself why so many people critizice (is that how that word is written!?) your code. Don't take it personally, but for what it is: great advice. I have been there as well, just trying to get things done, but in the end I had to put much more effort into my work, because I screwed up before. I learned from it and don't take the easy way anymore, even if it means working a full month on the foundation without any progress (that can be seen).


#4839915 Define a structure with in a class good or bad idea

Posted by SiS-Shadowman on 25 July 2011 - 03:32 AM

You are defining 2 types, class a and struct a::somemembers. However no instance of a holds an instance of a::somemembers, since there is no "somemembers foo;" within the definition of a. In my opinion it does make sense to define a type (for example a structure, enum or class) within another type if both belong together.


#4839610 ID3D10ShaderResourceView* and std::map

Posted by SiS-Shadowman on 24 July 2011 - 09:18 AM


200-300 FPS down?? How much FPS do you have, 2k?

Never measure time in fps, always use 1/fps to get the actual time of the frame.


While in release build it's about 3000 but it's because there isn't much things in scene: only textured level, and camera for now. But the question is about why storing ID3D19ShaderResourceView* in std::map slows down the game? Not about how large my FPS or how do I measure it.


It slows down the game because more instructions are executed, it's as simple as that. Not that those 300 fps really matter: 3000 fps is 0.33 ms PER frame. 2700 fps is 0.37 ms PER frame, thus your code takes 0.04 ms longer which is no big deal.


However, why do your methods take wstring by value? That always copies the string that is passed in. Even worse is that you are actually passing a const wchar_t* in to the methods, creating another copy while at it. If you have a wstring already, simply pass it to the method, you don't need and should not call .c_str()! You should also change the signature of your methods from method(wstring) to method(const wstring&), which makes them take a reference to a wstring (and thus no copying is involved).





bool TextureManager::addTexture(const wstring& path)
{ 
        checkDevice();
        iter=textures.find(path);
        if(iter==textures.end())
        {           	
        HRESULT hr=D3DX10CreateShaderResourceViewFromFile(md3dDevice, path.c_str(), NULL, NULL, &TexView, NULL);
        if(hr!=S_OK)
                return false;
        textures.insert( make_pair(path,TexView));
        return true;
        }
        
        return false;
}




#4838567 error LNK2001: unresolved external symbol

Posted by SiS-Shadowman on 21 July 2011 - 12:45 PM

Won't that create a new object of the GraphicsEngine? I'm not sure what the & does, but how can the reference know that m_engine actually is graphics_engine?


You seem to be confused about what references are:


When you use & in conjunction with a type, you create a reference which does not create a new object. Instead a reference always points to an already existing object. Whereas a value always copies the existing object, thus creating yet another instance:




GraphicsEngine engine1; //< Now one graphics engine exists

GraphicsEngine engine2 = engine; //< A SECOND engine has been created by copying it from the first

GraphicsEngine& engine1_too = engine; //< this is the SAME as engine



The same applies to function & method parameters: If you place a & after the type, then you are passing by reference, if you ommit it (and don't place a *) then you are passing by value.




#4838538 error LNK2001: unresolved external symbol

Posted by SiS-Shadowman on 21 July 2011 - 11:32 AM


public:
Sprite(GraphicsEngine graphics, LPCWSTR texture_path, float x, float y, float width, float height);
~Sprite(void);


I'm sending a reference from the GraphicsEngine into the Sprite here, right? But then I have to include the GraphicsEngine header file? Or?

No you are not. You are passing graphics engine by value. In this case you would have to include GraphicsEngine.h in Sprite.h, but this will not solve the problem due to a circular dependency. Instead you should try what I write above, ie. "GraphicsEngine& engine" for the constructor and also storing a reference to the engine: "GraphicsEngine& m_engine;".





#4838514 error LNK2001: unresolved external symbol

Posted by SiS-Shadowman on 21 July 2011 - 10:56 AM

I'm not sure I understood the "forward" tecnique... Could you please post a small example? Posted Image


Sure thing:

Sprite.h:
#pragma once

// includes

class GraphicsEngine;
class Sprite
{
....public:

Sprite(GraphicsEngine& engine);

private:

GraphicsEngine&    m_engine;
};


Sprite.cpp
#include "Sprite.h"
#include "GraphicsEngine.h"


The important point is that you cannot use/pass a forward declared type by value, ie "GraphicsEngine engine", but have to use/pass it by reference and/or pointer (GraphicsEngine& engine OR GraphicsEngine* engine): The reason behind this is that the compiler is required to know the size of the object to pass, in order to pass it by value (or use it as a member in a class), which it cannot on forward delcared types. Using references/pointers requires NO knowledge of the underlying type. But note that calling methods on that type or accessing members requires knowledge of the type, hence you are forced to place all code that accesses GraphicsEngine inside Sprite.cpp (and vice verca for GraphicsEngine.cpp if you forward declare Sprite as well).

*edit*

Please note that it also makes sense to pass the engine by reference: You don't want to copy it, but pass a reference TO the SAME object to all sprites, so those sprites can access the shared state of that single engine. Creating a copy of an engine would be a hard thing to implement, since you have to decide whether both instances access & render to the same window, etc... It is easier to forbid copying an engine alltogether by either inheriting from boost::noncopyable or by explicitly declaring the copy constructor private:


class CannotBeCopied

{

public:

...

private:

CannotBeCopied(const CannotBeCopied&);

};






#4838498 error LNK2001: unresolved external symbol

Posted by SiS-Shadowman on 21 July 2011 - 10:24 AM

I'll explain the last post a bit:

The compiler translates each cpp file, and when looking at Sprite.cpp, it couldn't find Sprite because it first included Sprite.h, then GraphicsEngine.h, then Sprite.h again, HOWEVER there's a pragma once, thus it skips the second inclusion and tries to make sense of GraphicsEngine.h. The problem is that the Sprite class is NOT known at that point (remember that you included GraphicsEngine.h BEFORE the compiler actually knew the Sprite class).




You can solve this by forward declaring either one or (sometimes better) both types. Simply put "class GraphicsEngine" right before class Sprite { .... } and/or the other way around. As long as you don't actually USE the type (ie. access methods, pass it by value) from within the header, you are fine.

*edit*

Actually, the preprocessor pastes everything into one big "file" and then the compiler kicks in, however the order in which the compiler finds those types in the big file is the same as described above.




#4766192 Setting Up VS2010 Do Output Release Build In Multiple Locations?

Posted by SiS-Shadowman on 28 January 2011 - 08:55 AM

I tried the command in cmd and it say the command can't find the file specified however I can go to that directory "D:\Coding Projects\Dynamically Linked Libraries\Test\src\TestLibrary\TestLibrary\bin\Debug" and the TestLibrary.dll is there. D:\test also exists. Does anyone see anything wrong with my code?


You should have been using quotation mark, since your path contains spaces. The copy command probably tries to copy "D:\Coding Projects\Dynamically" to "Libary" which makes no sense at all. You should try the following:

copy "D:\Coding Projects\Dynamically Linked Libraries\Test\src\TestLibrary\TestLibrary\bin\Release\TestLibrary.dll" D:\test


However I have no idea how to separate the build events for different configurations: I didn't find a way either.


#4764434 Compiling release version in microsoft visual c++ 2010

Posted by SiS-Shadowman on 25 January 2011 - 07:40 AM

If you set the option in release mode as I have said then you don't need to install anything to make it run.....................


Your program will not run without the redistributable, not even if you wish for it. Chances are another program installed it, but that is not always the case.
However the error mentioned by the OP seems to indicate that he delivered a debug executable, instead of a release one (which is indicated by the d in the dll name: MSVCP100D.dll).

*edit*
It will only work if you link against the static runtime (in which case the runtime is included in your executable), however that has some drawbacks that might be confusing for newcomers.


#4763858 DLLs, classes and VS versions

Posted by SiS-Shadowman on 24 January 2011 - 07:01 AM

Also mixing Debug and Release should not pose any problem (mixing that worked fine with VS 2003).



That totally depends. If you have dlls that link against different runtimes then those will maintain different heaps: You must call delete in the same dll you have called new to obtain that address (which is really annoying when you cannot control which runtime a 3rd party library uses). I would suggest not mixing different runtimes, unless you really know what you are doing. For example, templated containers will most likely cause problems when they're passed accross dll boundaries.



About solving your problem, you most likely need to find a test case that displays the same problem: Either by reducing the original code (doing a binary search through your code probably helps) or by rewriting a test from scratch until it crashes. For example, do you have that problem with every mesh instance? Does it happen sporadically? If the former is the case, then you could post your code: Maybe we can detect a problem.


#4588903 D3D11 Effects [Found possible solution]

Posted by SiS-Shadowman on 16 January 2010 - 07:45 AM

Thanks for the answer, but the debug layer tells me otherwise.
Using TEXOORD0-2 as the semantic name makes it output an error that I need to use the SemanticIndex field to specify my elements.
Using TEXCOORD for my 3 variables in the effect file makes the compiler complain that I can't redeclare my elements.

What's even more annoying is that the BasicHLSL example of D3D11 is running on my laptop, so It must be my code.

*Edit* I'm loosing my faith in the effect framework. Is there anyone who is using that pile of ... successfully? I doesn't compile unless changes to the source code are made, apparently creating an InputLayout from a complete effect is impossible as well (since the d3d11 sample only passes the compiled vertex-shader, and not an entire effect). So if there is someone, would you mind posting how you managed to get this system to work? It was so much easier with D3D9...

*Edit2* I can't even get it to work for a structure that ONLY takes a float4 as a POSITION. I always get the same error: CreateInputLayout returns E_INVALIDARG.

*Edit3* Now I found the error. It seems that one must not pass the compiled effect bytecode to the function, but only the compiled vertex/geometry shader bytecode. I found this by going through the effect frameworks source code myself, and it is mentioned in the documentation, but NOT in the doc of CreateInputLayout, but of the structure that is used to retrieve the vertexshader bytecode from a compiled effect 'D3DX11_EFFECT_SHADER_DESC'.

This is my solution that causes CreateInputLayout to return S_OK:

// Traverse all Techniques
uint32 tIndex = 0;
ID3DX11EffectTechnique* tech = NULL;
while((tech = m_effect->GetTechniqueByIndex(tIndex++))->IsValid())
{
// Traverse all passes
uint32 pIndex = 0;
ID3DX11EffectPass* pass = NULL;
while((pass = tech->GetPassByIndex(pIndex++))->IsValid())
{
D3DX11_PASS_SHADER_DESC vs_desc;
D3D11_API(pass->GetVertexShaderDesc(&vs_desc));
if(0 == vs_desc.pShaderVariable)
throw programming_error("Shouldn't be zero") << debug_info();

D3DX11_EFFECT_SHADER_DESC s_desc;
D3D11_API(vs_desc.pShaderVariable->GetShaderDesc(0, &s_desc));

D3D11_API(m_device->CreateInputLayout(desc,
4,
s_desc.pBytecode,
s_desc.BytecodeLength,
&layout));
}
}


Basically, I'm going through all techniques and their passes to find all vertex-shaders and then use GetShaderDesc to actually get the compiled byte code of the entire shader (I don't use pInputSignature because I couldn't find it's length yet). Of course, this forces an effect to only use one vertex-input layout, but that's easily changed.
This could have really been mentioned on the page of CreateInputLayout, since it took me an entire day to figure it out.

[Edited by - SiS-Shadowman on January 16, 2010 3:45:12 PM]


PARTNERS