diff --git a/build/premake/premake.lua b/build/premake/premake.lua index 6052c0351d..f6fdda8706 100755 --- a/build/premake/premake.lua +++ b/build/premake/premake.lua @@ -49,6 +49,8 @@ function setuppackage (projectname) "ps", "ps/scripting", "ps/Network", + "ps/GameSetup", + "ps/XML", "simulation", "simulation/scripting", @@ -70,8 +72,7 @@ function setuppackage (projectname) "terrain", "sound", "scripting", - "i18n", - "tests" + "i18n" } if (projectname ~= "sced") then tconcat(source_dirs, { diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index cab3702efa..d8d16a183a 100755 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -17,7 +17,7 @@ #include "VFSUtil.h" #include "Loader.h" -#include "ps/XMLWriter.h" +#include "ps/XML/XMLWriter.h" #include "simulation/Entity.h" #include "simulation/BaseEntity.h" #include "simulation/BaseEntityCollection.h" diff --git a/source/graphics/MaterialManager.cpp b/source/graphics/MaterialManager.cpp index d5064afd4b..e685266f1d 100755 --- a/source/graphics/MaterialManager.cpp +++ b/source/graphics/MaterialManager.cpp @@ -1,6 +1,6 @@ #include "precompiled.h" #include "ogl.h" -#include "Xeromyces.h" +#include "XML/Xeromyces.h" #include "MaterialManager.h" #define SAFE_DELETE(x) \ diff --git a/source/graphics/ObjectBase.cpp b/source/graphics/ObjectBase.cpp index e8a192472c..cedcce1a6a 100644 --- a/source/graphics/ObjectBase.cpp +++ b/source/graphics/ObjectBase.cpp @@ -3,7 +3,7 @@ #include "ObjectBase.h" #include "ObjectManager.h" -#include "Xeromyces.h" +#include "XML/Xeromyces.h" #include "CLogger.h" #define LOG_CATEGORY "graphics" diff --git a/source/graphics/TerrainProperties.cpp b/source/graphics/TerrainProperties.cpp index 3b1ca4dea2..a2ecccb2c2 100644 --- a/source/graphics/TerrainProperties.cpp +++ b/source/graphics/TerrainProperties.cpp @@ -7,8 +7,8 @@ #include "Overlay.h" #include "Parser.h" -#include "XeroXMB.h" -#include "Xeromyces.h" +#include "ps/XML/XeroXMB.h" +#include "XML/Xeromyces.h" #include "CLogger.h" #define LOG_CATEGORY "graphics" diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 1ee6b1f95b..45c7dbd1ee 100755 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -27,7 +27,7 @@ gee@pyro.nu #include "CTooltip.h" #include "MiniMap.h" -#include "ps/Xeromyces.h" +#include "ps/XML/Xeromyces.h" #include "ps/Font.h" #include "Pyrogenesis.h" diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index 2626938f33..392fffc1a4 100755 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -30,7 +30,7 @@ ERROR_TYPE(GUI, JSOpenFailed); #include "Singleton.h" #include "lib/input.h" -#include "Xeromyces.h" +#include "XML/Xeromyces.h" extern int gui_handler(const SDL_Event* ev); diff --git a/source/gui/IGUIObject.h b/source/gui/IGUIObject.h index 30e9fc5ad6..54e659fc64 100755 --- a/source/gui/IGUIObject.h +++ b/source/gui/IGUIObject.h @@ -37,7 +37,7 @@ gee@pyro.nu #include #include "lib/input.h" // just for EV_PASS -#include "ps/Xeromyces.h" +#include "ps/XML/Xeromyces.h" #include "gui/scripting/JSInterface_IGUIObject.h" diff --git a/source/main.cpp b/source/main.cpp index 25d0dfec60..f7aa8d589a 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -29,7 +29,7 @@ that of Atlas depending on commandline parameters. #include "gui/GUI.h" #include "ps/CConsole.h" #include "ps/Profile.h" -#include "ps/System.h" +#include "ps/Util.h" #include "ps/Game.h" #include "ps/Hotkey.h" #include "ps/Interact.h" diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index b48a1b3a75..745798ed97 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -70,7 +70,7 @@ #include "Atlas.h" #include "Config.h" -#include "ps/System.h" +#include "ps/Util.h" ERROR_GROUP(System); ERROR_TYPE(System, SDLInitFailed); diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp new file mode 100644 index 0000000000..70a0f65344 --- /dev/null +++ b/source/ps/Util.cpp @@ -0,0 +1,201 @@ +#include "precompiled.h" + +#include "lib/res/file/vfs.h" +#include "lib/ogl.h" +#include "lib/timer.h" +#include "lib/detect.h" +#include "lib/res/res.h" +#include "lib/res/graphics/tex.h" + +#include "ps/GameSetup/Config.h" + +static std::string SplitExts(const char *exts) +{ + std::string str = exts; + std::string ret = ""; + size_t idx = str.find_first_of(" "); + while(idx != std::string::npos) + { + if(idx >= str.length() - 1) + { + ret += str; + break; + } + + ret += str.substr(0, idx); + ret += "\n"; + str = str.substr(idx + 1); + idx = str.find_first_of(" "); + } + + return ret; +} + + +void WriteSystemInfo() +{ + TIMER(write_sys_info); + + get_gfx_info(); + // get_cpu_info already called during init - see call site + get_snd_info(); + get_mem_status(); + + struct utsname un; + uname(&un); + + FILE* f = fopen("../logs/system_info.txt", "w"); + if(!f) + return; + + // .. OS + fprintf(f, "OS : %s %s (%s)\n", un.sysname, un.release, un.version); + + // .. CPU + fprintf(f, "CPU : %s, %s", un.machine, cpu_type); + if(cpus > 1) + fprintf(f, " (x%d)", cpus); + if(cpu_freq != 0.0f) + { + if(cpu_freq < 1e9) + fprintf(f, ", %.2f MHz\n", cpu_freq*1e-6); + else + fprintf(f, ", %.2f GHz\n", cpu_freq*1e-9); + } + else + fprintf(f, "\n"); + + // .. memory + fprintf(f, "Memory : %lu MiB; %lu MiB free\n", tot_mem/MiB, avl_mem/MiB); + + // .. graphics + fprintf(f, "Graphics Card : %s\n", gfx_card); + fprintf(f, "OpenGL Drivers : %s; %s\n", glGetString(GL_VERSION), gfx_drv_ver); + fprintf(f, "Video Mode : %dx%d:%d@%d\n", g_xres, g_yres, g_bpp, g_freq); + + // .. sound + fprintf(f, "Sound Card : %s\n", snd_card); + fprintf(f, "Sound Drivers : %s\n", snd_drv_ver); + + + // + // .. network name / ips + // + + // note: can't use un.nodename because it is for an + // "implementation-defined communications network". + char hostname[128] = "(unknown)"; + (void)gethostname(hostname, sizeof(hostname)-1); + // -1 makes sure it's 0-terminated. if the function fails, + // we display "(unknown)" and will skip IP output below. + fprintf(f, "Network Name : %s", hostname); + + { + hostent* host = gethostbyname(hostname); + if(!host) + goto no_ip; + struct in_addr** ips = (struct in_addr**)host->h_addr_list; + if(!ips) + goto no_ip; + + // output all IPs (> 1 if using VMware or dual ethernet) + fprintf(f, " ("); + for(uint i = 0; i < 256 && ips[i]; i++) // safety + { + // separate entries but avoid trailing comma + if(i != 0) + fprintf(f, ", "); + fprintf(f, "%s", inet_ntoa(*ips[i])); + } + fprintf(f, ")"); + } + +no_ip: + fprintf(f, "\n"); + + + // .. OpenGL extensions (write them last, since it's a lot of text) + const char* exts = oglExtList(); + if (!exts) exts = "{unknown}"; + fprintf(f, "\nOpenGL Extensions: \n%s\n", SplitExts(exts).c_str()); + + fclose(f); + f = 0; +} + + + +static const wchar_t* HardcodedErrorString(int err) +{ +#define E(sym) case sym: return L ## #sym; + + switch(err) + { + E(ERR_NO_MEM) + E(ERR_FILE_NOT_FOUND) + E(ERR_INVALID_HANDLE) + E(ERR_INVALID_PARAM) + E(ERR_EOF) + E(ERR_PATH_NOT_FOUND) + E(ERR_PATH_LENGTH) + default: + return 0; + } +} + +const wchar_t* ErrorString(int err) +{ + // language file not available (yet) + return HardcodedErrorString(err); + + // TODO: load from language file +} + + +// identifies the file format that is to be written +// (case-insensitive). examples: "bmp", "png", "jpg". +// BMP is good for quick output at the expense of large files. +void WriteScreenshot(const char* extension) +{ + // determine next screenshot number. + // + // current approach: increment number until that file doesn't yet exist. + // this is fairly slow, but it's typically only done once, since the last + // number is cached. binary search shouldn't be necessary. + // + // known bug: after program restart, holes in the number series are + // filled first. example: add 1st and 2nd; [exit] delete 1st; [restart] + // add 3rd -> it gets number 1, not 3. + // could fix via enumerating all files, but it's not worth it ATM. + char fn[VFS_MAX_PATH]; + + const char* file_format_string = "screenshots/screenshot%04d.%s"; + // %04d -> always 4 digits, so sorting by filename works correctly. + + static int next_num = 1; + do + sprintf(fn, file_format_string, next_num++, extension); + while(vfs_exists(fn)); + + const int w = g_xres, h = g_yres; + const int bpp = 24; + GLenum fmt = GL_RGB; + int flags = TEX_BOTTOM_UP; + // we want writing BMP to be as fast as possible, + // so read data from OpenGL in BMP format to obviate conversion. + if(!stricmp(extension, "bmp")) + { + fmt = GL_BGR; + flags |= TEX_BGR; + } + + const size_t size = w * h * bpp; + void* img = mem_alloc(size); + + glReadPixels(0, 0, w, h, fmt, GL_UNSIGNED_BYTE, img); + + if(tex_write(fn, w, h, bpp, flags, img) < 0) + debug_warn("WriteScreenshot: tex_write failed"); + + mem_free(img); +} diff --git a/source/ps/Util.h b/source/ps/Util.h new file mode 100644 index 0000000000..c2136cb5f5 --- /dev/null +++ b/source/ps/Util.h @@ -0,0 +1,5 @@ +extern void WriteSystemInfo(); + +extern const wchar_t* ErrorString(int err); + +extern void WriteScreenshot(const char* extension); \ No newline at end of file diff --git a/source/ps/XML.h b/source/ps/XML/XML.h similarity index 100% rename from source/ps/XML.h rename to source/ps/XML/XML.h diff --git a/source/ps/XMLUtils.cpp b/source/ps/XML/XMLUtils.cpp similarity index 100% rename from source/ps/XMLUtils.cpp rename to source/ps/XML/XMLUtils.cpp diff --git a/source/ps/XMLWriter.cpp b/source/ps/XML/XMLWriter.cpp similarity index 100% rename from source/ps/XMLWriter.cpp rename to source/ps/XML/XMLWriter.cpp diff --git a/source/ps/XMLWriter.h b/source/ps/XML/XMLWriter.h similarity index 100% rename from source/ps/XMLWriter.h rename to source/ps/XML/XMLWriter.h diff --git a/source/ps/XercesErrorHandler.cpp b/source/ps/XML/XercesErrorHandler.cpp similarity index 100% rename from source/ps/XercesErrorHandler.cpp rename to source/ps/XML/XercesErrorHandler.cpp diff --git a/source/ps/XercesErrorHandler.h b/source/ps/XML/XercesErrorHandler.h similarity index 100% rename from source/ps/XercesErrorHandler.h rename to source/ps/XML/XercesErrorHandler.h diff --git a/source/ps/XeroXMB.cpp b/source/ps/XML/XeroXMB.cpp similarity index 100% rename from source/ps/XeroXMB.cpp rename to source/ps/XML/XeroXMB.cpp diff --git a/source/ps/XeroXMB.h b/source/ps/XML/XeroXMB.h similarity index 100% rename from source/ps/XeroXMB.h rename to source/ps/XML/XeroXMB.h diff --git a/source/ps/Xeromyces.cpp b/source/ps/XML/Xeromyces.cpp similarity index 99% rename from source/ps/Xeromyces.cpp rename to source/ps/XML/Xeromyces.cpp index e3b879075a..b754543c84 100755 --- a/source/ps/Xeromyces.cpp +++ b/source/ps/XML/Xeromyces.cpp @@ -8,9 +8,9 @@ #include #include -#include "ps/Xeromyces.h" #include "ps/CLogger.h" #include "lib/res/file/vfs.h" +#include "Xeromyces.h" #define ZLIB_DLL #include "zlib.h" // for crc32 diff --git a/source/ps/Xeromyces.h b/source/ps/XML/Xeromyces.h similarity index 98% rename from source/ps/Xeromyces.h rename to source/ps/XML/Xeromyces.h index e39da590ac..2f63739c86 100755 --- a/source/ps/Xeromyces.h +++ b/source/ps/XML/Xeromyces.h @@ -16,7 +16,7 @@ ERROR_GROUP(Xeromyces); ERROR_TYPE(Xeromyces, XMLOpenFailed); ERROR_TYPE(Xeromyces, XMLParseError); -#include "ps/XeroXMB.h" +#include "XeroXMB.h" #include "CVFSFile.h" class CXeromyces : public XMBFile diff --git a/source/simulation/BaseEntity.cpp b/source/simulation/BaseEntity.cpp index 291f9217cd..800da5e5f6 100755 --- a/source/simulation/BaseEntity.cpp +++ b/source/simulation/BaseEntity.cpp @@ -4,7 +4,7 @@ #include "ObjectManager.h" #include "CStr.h" -#include "ps/Xeromyces.h" +#include "ps/XML/Xeromyces.h" #include "CLogger.h" #define LOG_CATEGORY "entity" diff --git a/source/simulation/BaseEntity.h b/source/simulation/BaseEntity.h index 8c720af0c7..5d8081cd22 100755 --- a/source/simulation/BaseEntity.h +++ b/source/simulation/BaseEntity.h @@ -25,7 +25,7 @@ #include "EventHandlers.h" #include "EntitySupport.h" #include "ScriptObject.h" -#include "Xeromyces.h" +#include "XML/Xeromyces.h" class CBaseEntity : public CJSComplex, public IEventTarget { diff --git a/source/tools/sced/EditorData.cpp b/source/tools/sced/EditorData.cpp index 0b2cc588e3..dda1358e11 100755 --- a/source/tools/sced/EditorData.cpp +++ b/source/tools/sced/EditorData.cpp @@ -23,7 +23,7 @@ #include "Scheduler.h" #include "Loader.h" -#include "XML.h" +#include "XML/XML.h" #include "Game.h" #include "GameAttributes.h"