Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 09 Jun 2000
Offline Last Active Today, 04:02 PM

#5312173 How to use Unit-Tests

Posted by on Yesterday, 03:44 PM

Well, in order to test my classes, I would have to implement or rather copy them from the original project.
Is that right or is there any possibility to refer to my original files which saves rewriting/copying a class?
As the projects are separated, I doubt this is possible though.

Typically you'd put the thing you want to test into a library project (static lib, dll, whatever).

You would then have an executable project that contains the tests and runs them (depending on the testing framework; some frameworks load dlls into a "test runner")

Finally you have your game executable which just loads your games library and starts it.

So in visual studio, something like
+ SuperAwesomeGameStuff (library)
- all your game code goes here
+ SuperAwesomeGame (exe)
- just basically has a "main" that starts your game
+ SuperAwesomeTests (exe)
- contains all the tests and runs them

#5311571 Why C# all of a sudden?

Posted by on 20 September 2016 - 03:01 AM

Outside of games: You're late. C# has seen widespread use in client software development for a long time.

Not just client. It's been popular in server side for at least 10 years now (between "web methods", WCF, and lately ASP.net web APIs).

#5310639 Why can't I print out my std::string vector?

Posted by on 13 September 2016 - 03:24 PM

Should I still not do this even if many other classes needs MapManager? (sorry for the super late reply...)

You've fallen for the most common misuse of the singleton pattern. The singleton is there is ensure a single instance of an object, not a single point of access.
Everyone who misuses a singleton in this fashion says the same thing: "I don't want to pass my X/Manager/God/Controller/Whatever object everywhere". As @Álvaro said, at least then your dependency is obvious.
If you find that you're passing a certain object everywhere down through layers of code, this is a code smell and a sign that you should refactor your code.
That said, sometimes a global really is the lesser evil. Things like a log object for example.
But let's say you look at your options and you decide that it really would be less painful to not pass MapManager everywhere. In that case, just create a global and own that decision. 
You have you MapManager class defined as normal (MapManager.h/.cpp). These files should know nothing about the global, otherwise you can't use them without it.
Create a header where you will declare your global MapManager

#include "MapManager.h"

// namespaces are great!
namespace InsertGameNameHere
   namespace Globals
      // the global map state
      extern MapManager TheMap;

Then in your main.cpp instantiate TheMap

#include "Globals.h"

// instantiate the map. this should be in exactly one place in the code
MapManager InsertGameNameHere::Globals::TheMap;

int main()
   // do more stuff

Anywhere else you need to access the map, just include Globals.h without instantiating the map.


#include "Globals.h"

namespace InsertGameNameHere
    void SpawnMonster()
       Monster monster;
       // etc.

#5305806 Pre-emptive Solution for 'The application was unable to start correctly (...

Posted by on 14 August 2016 - 04:28 PM

I am linking the static OpenSSL libraries so shouldn't I not need to distribute the dll with my installer? Shouldnt it be packaged into the exe?


My Linker->Input->Additional Dependencies are:










Bear in mind that libraries with a "d" at the end are generally debug libraries, and you probably don't want them being used in the release version of your code. 

#5303860 Xml Parser, C++

Posted by on 03 August 2016 - 03:37 PM


 Advantages of TinyXML-2
Many fewer memory allocation (1/10th to 1/100th), uses less memory (about 40% of TinyXML-1), and faster (~5x on read).



I tried TinyXML-2 and it's still a memory hog. The conversion from TinyXML was very easy.


TinyXML is a DOM based parser. This means it has to load the entire document into memory first. For a lot of applications, that's fine (desirable even).


If memory is an issue, you could look at a SAX based parser, which uses an event-driven model to process the XML. This uses less memory, but it isn't as easy to program with (in general, YMMV).


For C++ sax parsers, you can use Xerces or Libxml++ (there may be others, those are the two I have used).

#5303575 Xml Parser, C++

Posted by on 01 August 2016 - 08:02 PM

One problem that I have with TinyXML is that it takes up 1.6+ GB of RAM to parse a 346MB XML file.

Might be worth looking at TinyXML2 then?

Advantages of TinyXML-2
Many fewer memory allocation (1/10th to 1/100th), uses less memory (about 40% of TinyXML-1), and faster (~5x on read).

#5303559 Xml Parser, C++

Posted by on 01 August 2016 - 04:29 PM

I've even written a C# wrapper for CMarkup, and use it in a number of .NET projects.

What advantages does CMarkup have over the .Net XML libraries? 

#5303040 Xml Parser, C++

Posted by on 28 July 2016 - 10:24 PM

What have you used to parse XML files in C++?

Exactly what do you want to do with these parsed XML files? 


If you just want to read the XML into a data structure, TinyXML is simple and lightweight.


But it doesn't do schema validation or XSL transforms.


Libxml and Xerces will (I think, been a while since I used  them), but it's not as easy to use. 

#5301299 A Struct That Contains A Delegate With Unknown Signature

Posted by on 18 July 2016 - 09:40 PM

Stop and think about what you want to achieve. 
So you want to have commands that invoke delegates that potentially take arguments and return some values.
Where are you going to get the argument values from?
What are you going to do with the return values? 
IF you can explain what you want to achieve better, than we might be able to help you.

#5300081 Finding that balance between optimization and legibility.

Posted by on 10 July 2016 - 10:54 PM

I have the luxury and flexibility to do what I want and try to challenge conventional thinking. In so doing I've discovered pros and cons for going against the norm as well, and i will take the route of least resistance (wether it is a conventional approach, or something to the contrary).

Nothing wrong with that. Just be aware that there are often very good reasons for conventions. They frequently encode a lot of lessons learned the hard way.
By all means, challenge them, but do so understanding why they are conventions in the first place.

For me personally (and in my own subjectivity), I've found working within the confines of the C++ and OOP in general to be quite problematic.

And on the flip side to what I just said... no-one is forcing you to write C++ in an OOP manner. 


If you're writing something and you think it should be a free function/struct/other "non OO" construct, write it as such. 

It is one of the strengths of the language that it doesn't force you into OOP, unlike Java or C#. (I love C#, but I find it stupid that I have to create a static class to write a simple function).


#5297374 what means these error?

Posted by on 20 June 2016 - 03:40 PM

What does your debugger tell you? Not the output, the actual debugger. Step through the program until you get to the line that is causing the problem.

Look at your data. 

#5296765 CrossPlatform Code

Posted by on 15 June 2016 - 10:02 PM

I would go for roughly the second option - define a common interface in a header file, but instead of having #ifdefs sprinkled throughout the implementation, consider having separate .cpp files for each platform. So you might have memory.h, memory_win32.cpp, memory_linux.cpp, memory_x360.cpp, etc. Your compiler toolchain(s) should allow you to make some files compile in some configurations but not in others.

This. and possibly also a memory_common.cpp for platform-agnostic code.

#5296622 How to avoid Singletons/global variables

Posted by on 15 June 2016 - 06:16 AM

...it's use case is obviously for data that needs to be globally accessed, but is NOT expected to mutate much at runtime.

That is NOT what a Singleton is. The Singleton pattern is about insuring there is only ONE instance of an object in a given code space (project/application/library/whatever).

That's it. The pattern has NOTHING to do with global access or mutability of state.

The problem is that idiot programmers see a singleton and think "oh, this is the OO way of doing globals", when that's not the intent of the pattern at all.

Global mutable state is bad (the reasons should be pretty obvious by now).

But singletons are bad in a completely orthogonal way, because they enforce a completely unnecessary restriction. If you only want one object, just create one bloody object!

If you need a global object (mutable or otherwise), first ask yourself if you REALLY need a global object. If you're satisfied that you do, then take responsibility for that decision and don't pretend it's somehow better because it's a singleton.

At least then in the future, when you realise that thing that you knew there would only be one of turns out to require more than one of, you haven't shot yourself in the foot.

#5295889 Do you usually prefix your classes with the letter 'C' or something e...

Posted by on 09 June 2016 - 05:46 PM

 i'm interested why microsoft in MFC uses C prefix, if it not correct for CPP?

MFC is a not a good example to follow when writing C++. 


Aside from the actual design of the library, the coding conventions used are mostly considered bad style these days.

#5295754 Do you usually prefix your classes with the letter 'C' or something e...

Posted by on 09 June 2016 - 04:27 AM

justify why minus in reputation?

Because every time you whinge about your reputation, you get downvoted. It's practically tradition.  :P 

Lowercase, in some cases make code unreadeable

Once again, you need to learn the difference between your subjective opinion and an objective fact.

in C# uppercase letter is part of official code style

Yes, in C# uppercase is part of the language coding conventions, but this thread is about C++, not C#.