Jump to content

  • Log In with Google      Sign In   
  • Create Account


NightCreature83

Member Since 21 Feb 2008
Offline Last Active Today, 01:53 AM
*****

#5147686 What's the point of floats in C?

Posted by NightCreature83 on 17 April 2014 - 11:05 AM

in x64 the first 4 floats are passed through the XMM0 - XMM3 registers which which are actually 128bits wide and are SSE registers. The rest are passed through the stack.




#5147681 String help in C

Posted by NightCreature83 on 17 April 2014 - 10:51 AM

So here is a fixed up C version:

const char* randomString = "Once there was this really old man who tranformed into dust. The end!";
size_t frequency[256];
ZeroMemory(frequency, 256 * sizeof(size_t));
for (size_t counter = 0; counter < strlen(randomString); ++counter)
{
    ++frequency[(unsigned char)randomString[counter]];
}
 
size_t numberOfDs = frequency[(unsigned char)'d'];
//Same linear runtime but you have all of the frequencies of chars for the string, of course this only works for ASCII strings

All fixes to this code are trivial to transform from C++11 to C. You were right in the fact that i missed out one element in the frequency array and that you can have negative numbers in char, so the cast to unsigned char will fix this. And if we are going to exclude the use of ZeroMemory we can replace that with a memset which has a set value of 0.

 

In all fairness all I wanted to do is show a more generic solution to what was asked, which has a O(1) lookup at the end for all characters of a string.

 

Ow and if we are really honest here we are answering what is most likely a school assignment.




#5147639 Graph layout

Posted by NightCreature83 on 17 April 2014 - 08:31 AM

Have you looked into graphviz and dot, doxygen uses this to generate their callgraphs and dependency grahps, which are clickable html.




#5147635 String help in C

Posted by NightCreature83 on 17 April 2014 - 08:25 AM

std::string randomString = "Once there was this really old man who tranformed into dust. The end!";
size_t frequency[255];
ZeroMemory(frequency, 255 * sizeof(size_t))
for (size_t counter = 0; counter < randomString.size(); ++counter)
{
    ++frequency[randomString[counter]];
}
 
auto numberOfDs = frequency['d'];
//Same linear runtime but you have all of the frequencies of chars for the string, of course this only works for ASCII strings



#5147059 tinyxml2 and how to read files

Posted by NightCreature83 on 15 April 2014 - 01:56 AM

There is no need for you to call ToElement on child, because the for loop makes sure its an element already. And with FirstAttribute on an element you can actually iterate over the attributes of an element cleaning this code up a bit. Also it is better to use FindAttribute on element than just Attribute, you are not trying to match an Attribute with name and value, so FindAttribute actually expresses your intent better and makes your code more maintainable.




#5146964 Great laptop for game development? (Budget of +1200,- euros)

Posted by NightCreature83 on 14 April 2014 - 01:43 PM

Not sure where you from but if you can read this Dutch Tweakers bi-montly laptop guide might be a good start for you. http://tweakers.net/reviews/3479/laptop-best-buy-guide-april-2014.html the ranges you are looking at this would be either a multi-media laptop or main stream laptop. Do you mean to have 8 real cores in the CPU or is a hyper threaded quad core good enough, because there are no 8 core(as in not hyper threaded) intel chips at the moment.




#5145590 Trying to understand vertex shaders better

Posted by NightCreature83 on 09 April 2014 - 01:28 AM

If you need an online math resource this one is decent: http://www.euclideanspace.com/maths/algebra/index.htm




#5145291 directxmath osx/linux?

Posted by NightCreature83 on 08 April 2014 - 05:15 AM

I expect you will run in to some compile issues with WORD, DWORD and such, also probably you will have to do something about the intrinsics and compiler support in the header files which try to figure out if your CPU supports SSE2, but other than that it should be possible.




#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.






PARTNERS