forked from mirror/openmw-tes3mp
Merge branch 'master' into gui-windows
This commit is contained in:
commit
54996684aa
3 changed files with 131 additions and 5 deletions
|
@ -9,6 +9,10 @@ option(USE_MPG123 "use mpg123 + libsndfile for sound" ON)
|
||||||
set(MORROWIND_DATA_FILES "data"
|
set(MORROWIND_DATA_FILES "data"
|
||||||
CACHE PATH "location of Morrowind data files")
|
CACHE PATH "location of Morrowind data files")
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
option(USE_DEBUG_CONSOLE "whether a debug console should be enabled for debug builds, if false debug output is redirected to Visual Studio output" ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
# We probably support older versions than this.
|
# We probably support older versions than this.
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 2.6)
|
||||||
|
|
||||||
|
@ -300,3 +304,24 @@ option(BUILD_ESMTOOL "build ESM inspector" ON)
|
||||||
if (BUILD_ESMTOOL)
|
if (BUILD_ESMTOOL)
|
||||||
add_subdirectory( apps/esmtool )
|
add_subdirectory( apps/esmtool )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
if (USE_DEBUG_CONSOLE)
|
||||||
|
set_target_properties(openmw PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
|
||||||
|
set_target_properties(openmw PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE")
|
||||||
|
set_target_properties(openmw PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE")
|
||||||
|
else()
|
||||||
|
# Turn off debug console, debug output will be written to visual studio output instead
|
||||||
|
set_target_properties(openmw PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS")
|
||||||
|
set_target_properties(openmw PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:WINDOWS")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Release builds use the debug console
|
||||||
|
set_target_properties(openmw PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:CONSOLE")
|
||||||
|
set_target_properties(openmw PROPERTIES COMPILE_DEFINITIONS_RELEASE "_CONSOLE")
|
||||||
|
set_target_properties(openmw PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:CONSOLE")
|
||||||
|
|
||||||
|
# TODO: At some point release builds should not use the console but rather write to a log file
|
||||||
|
#set_target_properties(openmw PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS")
|
||||||
|
#set_target_properties(openmw PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS")
|
||||||
|
endif()
|
||||||
|
|
|
@ -8,6 +8,22 @@
|
||||||
#include <components/misc/fileops.hpp>
|
#include <components/misc/fileops.hpp>
|
||||||
#include "engine.hpp"
|
#include "engine.hpp"
|
||||||
|
|
||||||
|
#if defined(_WIN32) && !defined(_CONSOLE)
|
||||||
|
#include <boost/iostreams/concepts.hpp>
|
||||||
|
#include <boost/iostreams/stream_buffer.hpp>
|
||||||
|
|
||||||
|
# if !defined(_DEBUG)
|
||||||
|
# include <iostream>
|
||||||
|
# include <fstream>
|
||||||
|
# endif
|
||||||
|
|
||||||
|
// For OutputDebugString
|
||||||
|
#include <Windows.h>
|
||||||
|
// makes __argc and __argv available on windows
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/// Parse command line options and openmw.cfg file (if one exists). Results are directly
|
/// Parse command line options and openmw.cfg file (if one exists). Results are directly
|
||||||
|
@ -80,6 +96,7 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine)
|
||||||
|
|
||||||
int main(int argc, char**argv)
|
int main(int argc, char**argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
OMW::Engine engine;
|
OMW::Engine engine;
|
||||||
|
@ -97,3 +114,71 @@ int main(int argc, char**argv)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Platform specific for Windows when there is no console built into the executable.
|
||||||
|
// Windows will call the WinMain function instead of main in this case, the normal
|
||||||
|
// main function is then called with the __argc and __argv parameters.
|
||||||
|
// In addition if it is a debug build it will redirect cout to the debug console in Visual Studio
|
||||||
|
#if defined(_WIN32) && !defined(_CONSOLE)
|
||||||
|
|
||||||
|
#if defined(_DEBUG)
|
||||||
|
class DebugOutput : public boost::iostreams::sink
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::streamsize write(const char *str, std::streamsize size)
|
||||||
|
{
|
||||||
|
// Make a copy for null termination
|
||||||
|
std::string tmp (str, size);
|
||||||
|
// Write string to Visual Studio Debug output
|
||||||
|
OutputDebugString (tmp.c_str ());
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
class Logger : public boost::iostreams::sink
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Logger(std::ofstream &stream)
|
||||||
|
: out(stream)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::streamsize write(const char *str, std::streamsize size)
|
||||||
|
{
|
||||||
|
out.write (str, size);
|
||||||
|
out.flush();
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::ofstream &out;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||||
|
{
|
||||||
|
std::streambuf* old_rdbuf = std::cout.rdbuf ();
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
|
#if defined(_DEBUG)
|
||||||
|
// Redirect cout to VS debug output when running in debug mode
|
||||||
|
{
|
||||||
|
boost::iostreams::stream_buffer<DebugOutput> sb;
|
||||||
|
sb.open(DebugOutput());
|
||||||
|
#else
|
||||||
|
// Redirect cout to openmw.log
|
||||||
|
std::ofstream logfile ("openmw.log");
|
||||||
|
{
|
||||||
|
boost::iostreams::stream_buffer<Logger> sb;
|
||||||
|
sb.open (Logger (logfile));
|
||||||
|
#endif
|
||||||
|
std::cout.rdbuf (&sb);
|
||||||
|
|
||||||
|
ret = main (__argc, __argv);
|
||||||
|
|
||||||
|
std::cout.rdbuf(old_rdbuf);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -83,12 +83,28 @@ static size_t getLength(const char *arr, const char* input, bool &ascii)
|
||||||
{
|
{
|
||||||
ascii = true;
|
ascii = true;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
unsigned char inp = *input;
|
const char* ptr = input;
|
||||||
|
unsigned char inp = *ptr;
|
||||||
|
|
||||||
|
// Do away with the ascii part of the string first (this is almost
|
||||||
|
// always the entire string.)
|
||||||
|
while(inp && inp < 128)
|
||||||
|
inp = *(++ptr);
|
||||||
|
len += (ptr-input);
|
||||||
|
|
||||||
|
// If we're not at the null terminator at this point, then there
|
||||||
|
// were some non-ascii characters to deal with. Go to slow-mode for
|
||||||
|
// the rest of the string.
|
||||||
|
if(inp)
|
||||||
|
{
|
||||||
|
ascii = false;
|
||||||
while(inp)
|
while(inp)
|
||||||
{
|
{
|
||||||
if(inp > 127) ascii = false;
|
// Find the translated length of this character in the
|
||||||
|
// lookup table.
|
||||||
len += arr[inp*6];
|
len += arr[inp*6];
|
||||||
inp = *(++input);
|
inp = *(++ptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue