Jump to content

  • Log In with Google      Sign In   
  • Create Account

NightCreature83

Member Since 21 Feb 2008
Offline Last Active Today, 07:38 PM

#5141953 What programming skills for Unreal 4

Posted by NightCreature83 on 25 March 2014 - 04:01 AM

Unreal has always had source licenses for people who could pay about 1M - 500.000 USD for it. Gameplay scripting is done through Blueprint in UE4, Unreal Script doesn't exist anymore. If you do need to add new behaviours it is C++ that you need to code that in.

 

Shaders will likely be in HLSL or CG.




#5139508 Framework or game engine with highest cross platform index?

Posted by NightCreature83 on 16 March 2014 - 12:30 PM

Unreal Engine, runs from mobile phones and browsers all the way up to the next gen consoles.




#5137737 Computer Science vs Software Engineering

Posted by NightCreature83 on 10 March 2014 - 02:20 AM

They are pretty much the same, software engineering might be more oriented on the work space where Computer Science  might be more focused on theory, this is not a hard rule though.




#5137431 How does your Pseudocode look?

Posted by NightCreature83 on 08 March 2014 - 04:41 PM

Mine mostly looks like decision diagrams so that it is easy to translate in to real code, or it just takes the shape of english text. When it is code time it is time to write it in a language :)




#5134068 Operator overloading, passing class a automatically convert to class b

Posted by NightCreature83 on 24 February 2014 - 04:42 AM

If I'm not mistaken, a temporary can't be passed as a reference to another function, only a const reference.

 

However, any solution seems a little meaningless. Isn't this a problem that would require inheritance to make any sense?

 

Even with a const reference that will not work, because the temporary will scope out at the function call. I have been bitten by this stuff before and its not an easy bug to detect.

 

To transform the object you will want to overload the constructor, to take in a B and construct an A from it. I don't recommend this though, implicit conversions lead to weird errors later on, so if you do this mark the constructor with "explicit". This makes it so that you explicitly have to construct on object on the function line, and pass by value instead of reference to make it work correctly.

 

In code the explict does this:

class Test
{
public:
    explicit Test(int x) : m_value(x) {}
 
    int m_value;
}
 
void foo(Test test) { std::cout << test.m_value << std::endl; }
 
void main()
{
    int x = 5
    foo(x); //Compile error due to explicit on the constructor, not having explicit would allow an implicit conversion here.
    foo(Test(x)); //Works fine now.
}



#5132595 I don't get c++11.

Posted by NightCreature83 on 19 February 2014 - 05:00 AM

Pretty comfortable with my c++ code now; I get classes, I get using templates and STL, smart pointers, and to an extent, exceptions. What I don't get is most of the new 2011 standard. Lambdas confuse me, in both their syntax and their purpose.

 

I've looked up articles trying to show practical uses for them, but they seem to go even further above my head than just the word 'lambda'. Rvalue / moving seems confusing just as well; decltype... gah. None of the new stuff makes much of any sense. The only thing I've understood so far is auto, and to a half-way extent: the new for loop style.

 

I've read through a third of C++ Primer 5th, and so far it's not really shed any new light to me. The frustration of these new features and my inability to grasp them has me concerned... How is it some clicked onto the new concepts rather fast? And where can I go to get to that point?

Other people grokked them fast because lambdas aren't new other languages already had these, lambdas in C# for example, they started as nameless delegates. I see lambdas as a delegate/callback function that you specify in the same line as where you pass them to a function that needs a callback. The lambdas in C++11 have a more function approach and I find them easier to read then their C# counterparts, its the capture that is hard.

 

A good use for a lambda is when you want to extend a std::find or std::find_if or std::sort, instead of passing it a functor or callback, you pass it a lambda that specifies what you want the predicate for the function to be. This keeps the code for the predicate and call of that predicate closer together than the functor or callback options.

 

RValue/Move semantics is something that was sorely missed and you had to program around this like reserving the size of your vector if you knew how big it was going to be to avoid an array copy. Move semantics will allow you to care a little less about copy performance if implemented correctly.

 

Decltype is a way in which we can access the type of an expression, this is useful in meta template programming and generic programming where you had to hack around these things before.

 

auto and the new intialiser lists are the most useful features added in C++11 because it allows you to write your code in an easier fashion and avoid a parsing problem.

class Foo
{
};
 
void Bar()
{
    Foo foo(); //The compiler sees this as a function prototype not the instantiation of an instance of Foo
    Foo foo {}; //This is now always seen as creating and instance of Foo
}



#5128821 Gathering information on input systems

Posted by NightCreature83 on 04 February 2014 - 02:41 PM

Hi NightCreature83,

 

thank you for your reply.

Your offered links are pretty interesting and cover a lot of things i was thinking about.

Unfortunately it is based on Windows and i want the input system to be running on other platforms as Linux and Mac as well (sry, i didn't mention this in my initial post).

So in order to this there is a need for some standard that needs to be supported by all of these platforms and USB seems to get it right (on a low level).

 

While looking for some HID APIs, i came across the following one:

http://libusbx.org/

It looks right for testing some stuff and trying to implement a prototype using it.

Actually only the first part is windows only the second link is platform agnostic an can be applied to all platforms, and it is also at that level that you make this code platform unaware.

 

Btw if you want multi-platform in input, you are going to have to write platform specific code, dealing with hardware devices is pretty hardwired into the platforms. Even between console generations of the same manufacturer this is different. The only other way out is writing your own HID interface but even then you run into platform differences, when dealing with hardware on different OSes sadly you will always have to write platform specific code.




#5128784 Gathering information on input systems

Posted by NightCreature83 on 04 February 2014 - 12:52 PM

http://molecularmusings.wordpress.com/2011/09/05/properly-handling-keyboard-input/

http://molecularmusings.wordpress.com/2011/09/29/wiring-physical-devices-to-abstract-inputs/

 

There is no need to have a HWND, the RawInput API on windows allows you to grab the input on the fly. XINPUT doesnt need a hwnd either and is porbably the easiest way to get a controller to work on windows.




#5128546 intrinsics/no intrinsics (in mingw)

Posted by NightCreature83 on 03 February 2014 - 03:31 PM

I think you are misunderstanding what an intrinsic is, it is a specially instruction to the compiler that it should use a particular instruction or group of instructions to transform the code in to asm. For example __m128 as an intrinsic telling the Compiler that if the target you are compiling for supports SSE2 instructions that this should be stored in a SSE2 register instead of normal registers. And yes for intrinsics you need to include headers as well, and they can be compiler specific so look in the help files of your compiler or the online help page.

 

Sin is a function defined in the C runtime and is used to calculate a value that approaches a sin value, how that is implemented and optimised by the compiler depends on the used version of the C runtime and the compile settings you are compiling with.




#5127578 CreateBuffer returns E_INVALIDARG

Posted by NightCreature83 on 30 January 2014 - 04:00 PM

XMMath is a newer version of the math library based of the Xbox math library, So basically it is meant to supersede D3DX math.

Or that is my understanding of it.

Not only is XNAMath (XM, which is now renamed to DirectXMath already) newer it also supports SSE2 by default where D3DXMath didnt, it did if you turned the compile options in VS for it on. DirectXMath actually in the header detects whether the target it is being compiled for supports SSE2 and if so starts using SSE2 intrinsics and all the proper ways of using these.

 

As already pointed out the structure must be 16byte-aligned, this is not the cast with your vector3. You should change it to:

struct ConstantBuffer
{
	D3DXMATRIX matWorld;
	D3DXMATRIX matView;
	D3DXMATRIX matProjection;
	D3DXVECTOR3 vLightDir;
        float padding; // unused
	D3DXVECTOR4 vLightCol;
};

or

struct ConstantBuffer
{
	D3DXMATRIX matWorld;
	D3DXMATRIX matView;
	D3DXMATRIX matProjection;
	D3DXVECTOR4 vLightCol;
	D3DXVECTOR3 vLightDir;
        float padding;
};

or simply modify the return of sizeof(ConstantBuffer) to be a multiple of 16.

You dont need to add padding just :

__declspec( align ( 16 ) ) float;
#define ALIGN16 __declspec( align(16) )
ALIGN16 float

When using the declspec or macro the compiler will automatically add padding when needed without you having to write this explicitly, it keeps your code slightly cleaner and easier to understand.

 

As an example

struct MaterialContent
{
    MaterialContent()
    {
        m_ambient[0] = 0.2f;
        m_ambient[1] = 0.2f;
        m_ambient[2] = 0.2f;
        m_ambient[3] = 1.0f;

        m_diffuse[0] = 0.8f;
        m_diffuse[1] = 0.8f;
        m_diffuse[2] = 0.8f;
        m_diffuse[3] = 1.0f;

        m_specular[0] = 0.0f;
        m_specular[1] = 0.0f;
        m_specular[2] = 0.0f;
        m_specular[3] = 1.0f;

        m_emissive[0] = 0.0f;
        m_emissive[1] = 0.0f;
        m_emissive[2] = 0.0f;
        m_emissive[3] = 1.0f;
        m_shininess = 1000.0f;
    }

    float m_ambient[4];
    float m_diffuse[4];
    float m_specular[4];
    float m_emissive[4];
    ALIGN16 float m_shininess;
};



#5125756 Branching in switch statement

Posted by NightCreature83 on 22 January 2014 - 06:17 PM

You should be able to embed a switch in the code block of a case label if that is what you mean to do.

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int condition = 0;
            switch (condition)
            {
                case 0:
                    {
                        switch (condition)
                        {
                            case 0:
                                Console.Write("Switch in a Switch");
                                break;
                        }
                    }
                    break;
                default:
                    break;
            }
        }



#5125627 using hash_map vs vector....

Posted by NightCreature83 on 22 January 2014 - 06:27 AM

You will not have a 1000 access of the hash_map in one frame, if you have a screen with a 1000s interactable objects on it, start rethinking that screen because you did it wrong. Besides the code to test this stuff has overhead in it that you don't need remeber that clock() also has an overhead when called, its better to do the insertion for say 1 million elements and taking the clock reading outside of your loop.v Also insertion into the hash map has the overhead of having to hash the key, if you are just using numbers you are better of using a normal std::map as mentioned.

 

Choice of your container here all comes down to how you want to access it. In a previous project we split the render data from update data completely and the update side, the render data was stored as a normal scenegraph in which each scene contained a normal map from a hash_value of a node name to the pointer of an actual object. This allowed for efficient dispatch of message to the render nodes in big scenes, in the neighbourhood of a few ns for full address dispatch through deep trees. Message dispatch worked along the lines of:

1.-Can we find the object in the tree?

   -No: Flag error and stop dispatch

   -Yes: Is this the last element in the address?

       -Yes: Dispatch message to actual node.

       -No: is this a new scene node?

           -No: Start at 1 again in this scenes map with the next token in the node.

          -Yes: Start at 1 but use the map of the scene node you just found to look for the next token.

 

This was fast used on big scenes, 100s of nodes active at the same time, address was a list of hash tokens to pass in to a normal std::map::find function, minor RTTI checks to see node types.




#5125301 Struct versus class?

Posted by NightCreature83 on 21 January 2014 - 05:02 AM

I would also like to add that the compiler adds the operator= for any struct, by coping 1-1 all its fields, in a class you generally have to define your own class_name operator=(const class_name right); however there are certain conditions on which the C++ compiler may add that operator automatically (implicitly). If I recall correctly there is yet another difference, but I fail to remember it for the time being, my apologies!

Hope I helped a little

No you dont default copy constructor, default construct/destructor and default assignment operator are generated for a class, as soon as you write one of these the compiler will not generate a default one. There really is no difference between a class or a struct beyond the default access modifiers.




#5125281 Struct versus class?

Posted by NightCreature83 on 21 January 2014 - 02:48 AM

As frob mentioned, in C++ a class and a struct are pretty much identical. The choice of which to use is yours to make, seeing as the following two are very much the same:

struct Vec
{
   float x, y, z;
};

class Vec
{
public:
   float x, y, z;
};

One issue i ran into when i used a mix of structs and classes was when forward declaring them. Sometimes i would simply forget if Vec was a class or a struct. Similar with Color, Rect, Transform, etc. So i settled on using classes only, and if something needs to have all of it's members public, i simply set them as public and not protected/private.

 

Actually they are not pretty much identical they are identical, the code generated from them is exactly the same, a struct can have all the same things as a class.

 




#5123830 Classes and use of 'New'

Posted by NightCreature83 on 15 January 2014 - 04:19 AM

Your first example would be just a pointer which you give later some "life".

something like this is need if you want create dynamically a new object. 

 

For example you have class Car and ask the user how many cars he/she wants

create; how would you do solve that problem? write everytime a new program

or do you want create just dynamically a new Object of type Car with the new operator?

int count;
std::vector<Car*> cars;

//Ask user the amound of cars he/she wants
std::cout<<"Hello Human! How many car Objects do want that i create for you: \n";
std::cin>>count;

for(int i = 0; i < count;i++)
{
     Car* Example = new Car;
     Cars.push_back(Example)
}

And because you create a class it's not necessary to delete it explicit because classes have a destructor which do this job for you, of course you should set the pointer to NULL in the end. explicit deleting you need if you allocating memoryfor  e.g. an array of size X. An array doesn't have an destructor so you have to do this

job per hand. 

 

Your information on allocation and deallocation is wong, when you use a new or new[] you will need to use a delete or delete[] to delete the memory that that allocation needed.

 

Constructors and destructors do other things and only manage the space of the member variables of a class not the allocation of the class itself.

 

In this example you are leaking memory, the amount is count * sizeof(Car).

 

 

Thanks for the reply. I am tryingto get my head around it smile.png

 

Couldn't you push the non 'new' example on to a vector as well though?

 

Vector::push_back makes a copy of the argument you pass it, so in the example it actually only copies the value of the pointer not the object it is pointing at, in other words that vector only stores the addresses of where the objects are actually in memory.






PARTNERS