I made another attempt to compile things on Ubuntu. Seems a few more updates are needed.
I pushed the changes to the Makefile for the = versus == POSIX compliance thing, and added the -std=c++11 flag.
I found additional dependencies needed to be installed outside of just the core SDL2 library. The core SDL library (libsdl2-dev) is needed for the sdl-config utility used in the Makefile. Additionally, other libraries are needed by the compiler. The full install set for OutpostHD is:
sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libphysfs-dev libglew-dev
I'm thinking a rule could be added to the Makefile to install these.
I looked into removing some of the warnings. It looks like there are attempts at compile time errors within templates using the familiar negative array index hack. I'm thinking this should be changed to the new static_assert introduced in c++11. Here's an example:
- typedef int ERROR_CantUseHorrible_cast[sizeof(InputClass) == sizeof(u) && sizeof(InputClass) == sizeof(OutputClass) ? 1 : -1];
+ static_assert(sizeof(InputClass) != sizeof(u) || sizeof(InputClass) != sizeof(OutputClass), "Can't use horrible cast");
Note the negated condition. The code with the negative array index hack gives the condition for passing the check, rather than failing the check. The conditions would need to be rewritten as if the "1 : -1" was reversed to "-1 : 1".
There was one odd example I'm not so sure about:
- typedef char ERROR_Unsupported_member_function_pointer_on_this_compiler[N-100];
+ static_assert(N < 100, "Unsupported member function pointer on this compiler");
What is going on with that check against 100? Seems like a hack. What is it doing, and is there a better way to do that?
I noticed a few sections of code similar to the following:
AiVoiceNotifier() {}; // Explicitely Declared Private
AiVoiceNotifier(const AiVoiceNotifier&) {}; // Explicitely Declared Private
AiVoiceNotifier& operator=(const AiVoiceNotifier&) {}; // Explicitely Declared Private
The operator= caused warnings due to no return value from a non-void function. Removing the "{}" removed the warning. It's not called, so not having a body won't produce an error. But this gets more to the heart of the idiom used here. As the function is explicitly being declared private to prevent its use, it would be more clear to use the "= deleted;" syntax introduced in c++11. This would apply to all 3 methods as well, and would give more clear intent.
Another missing return from a non-void function was:
int incrementFuelCellAge() { mFuelCellAge++; }
I'm thinking just change the return type to void. I don't think it needs to return a value. I also noticed it's not called anywhere. Another thought, should the return value actually be desired, it might make more sense to use the pre-increment operator: "return ++mFuelCellAge;". That would return the value after the increment, rather than what the value was before the increment.
It took me a while to realize NAS2D was a separate download. The folder in OutpostHD is really just the development headers. This of course means a new set of challenges.
The Makefile for NAS2D also needed to have the "-std=c++11" flag set.
I needed to install another library:
sudo apt install glee-dev
There was one include I needed to update in src/Renderer/OGL_Renderer.cpp:
-#include "SDL_image.h"
+#include "SDL2/SDL_image.h"
I still get some errors with NAS2D in src/Renderer/OGL_Renderer.cpp:
src/Renderer/OGL_Renderer.cpp: In member function ‘virtual void NAS2D::OGL_Renderer::fullscreen(bool, bool)’:
src/Renderer/OGL_Renderer.cpp:494:44: error: ‘SDL_SetWindowResizable’ was not declared in this scope
SDL_SetWindowResizable(_WINDOW, SDL_FALSE);
^
src/Renderer/OGL_Renderer.cpp: In member function ‘virtual void NAS2D::OGL_Renderer::resizeable(bool)’:
src/Renderer/OGL_Renderer.cpp:518:59: error: ‘SDL_SetWindowResizable’ was not declared in this scope
SDL_SetWindowResizable(_WINDOW, static_cast<SDL_bool>(_r));
^
Makefile:22: recipe for target 'obj/Renderer/OGL_Renderer.o' failed
According to the SDL docs:
This function is available since SDL 2.0.5.
According to the output of apt install:
libsdl2-dev is already the newest version (2.0.4+dfsg1-2ubuntu2).
Looks like the packages available for Ubuntu are too old to contain this function.
I'm stopping here for now.