From db045c330bc038dd5663d8add9e24388ba78815c Mon Sep 17 00:00:00 2001 From: olsner Date: Sun, 12 Nov 2006 04:02:36 +0000 Subject: [PATCH] # Made Atlas compile on linux graphics: basic terrain passibility atlas: lots of changes to make atlas compile under linux unix/X: more clipboard support - copy from 0AD to other programs unix/debug: use sys_get_executable_name instead of hard-coded paths ... and lots of other misc. changes This was SVN commit r4640. --- source/graphics/ObjectEntry.h | 1 + source/graphics/Terrain.cpp | 13 +- source/graphics/Terrain.h | 3 +- source/graphics/TerrainProperties.cpp | 110 +++++++++++-- source/graphics/TerrainProperties.h | 26 +++- source/lib/cache_adt.h | 2 +- source/lib/res/file/path.cpp | 7 +- source/lib/res/sound/snd_mgr.cpp | 9 +- source/lib/self_test.h | 6 +- source/lib/sysdep/unix/dir_watch_fam.cpp | 4 +- source/lib/sysdep/unix/udbg.cpp | 22 ++- source/lib/sysdep/unix/x.cpp | 146 ++++++++++++++++-- source/lib/tests/test_lib.h | 3 +- source/lib/tests/test_lockfree.h | 6 +- source/lib/tests/test_path_util.h | 55 +++---- source/network/NetMessage.cpp | 2 +- source/ps/CConsole.cpp | 4 +- source/ps/Game.cpp | 24 ++- source/ps/GameAttributes.cpp | 2 +- source/ps/GameSetup/Atlas.cpp | 31 ++-- source/ps/Interact.cpp | 2 +- source/ps/Interact.h | 1 + source/ps/tests/test_CStr.h | 2 +- source/ps/utf16string.h | 9 +- source/simulation/AStarEngine.cpp | 18 ++- source/simulation/AStarEngine.h | 10 +- source/simulation/PathfindEngine.cpp | 2 +- source/simulation/ScriptObject.h | 2 + source/sound/SoundGroup.h | 17 +- .../atlas/AtlasFrontends/ActorEditor.cpp | 21 ++- .../atlas/AtlasFrontends/ArchiveViewer.cpp | 21 ++- .../atlas/AtlasFrontends/ColourTester.cpp | 21 ++- .../atlas/AtlasFrontends/FileConverter.cpp | 21 ++- .../tools/atlas/AtlasFrontends/_template.cpp | 21 ++- source/tools/atlas/AtlasObject/AtlasObject.h | 8 +- .../atlas/AtlasObject/AtlasObjectImpl.cpp | 7 +- .../atlas/AtlasUI/ActorEditor/ActorEditor.cpp | 13 +- .../atlas/AtlasUI/ActorViewer/ActorViewer.cpp | 5 +- .../AtlasUI/ArchiveViewer/ArchiveViewer.cpp | 25 +-- .../AtlasUI/ArchiveViewer/ArchiveViewer.h | 2 + .../AtlasUI/ArchiveViewer/FilePreviewer.cpp | 4 +- .../AtlasUI/ArchiveViewer/FilePreviewer.h | 2 +- .../ColourTester/ColourTesterColourCtrl.cpp | 2 +- .../ColourTester/ColourTesterImageCtrl.cpp | 4 +- .../CustomControls/Buttons/ToolButton.cpp | 4 +- .../CustomControls/Buttons/ToolButton.h | 2 + .../AtlasUI/CustomControls/Canvas/Canvas.cpp | 2 +- .../ColourDialog/ColourDialog.cpp | 9 +- .../ColourDialog/ColourDialog.h | 2 + .../DraggableListCtrlCommands.h | 2 + .../EditableListCtrl/EditableListCtrl.cpp | 8 +- .../EditableListCtrlCommands.h | 2 + .../EditableListCtrl/FieldEditCtrl.cpp | 13 +- .../HighResTimer/HighResTimer.cpp | 12 ++ .../CustomControls/Windows/AtlasWindow.cpp | 4 + .../CustomControls/Windows/AtlasWindow.h | 2 + .../tools/atlas/AtlasUI/General/Datafile.cpp | 2 +- source/tools/atlas/AtlasUI/General/Datafile.h | 2 +- .../tools/atlas/AtlasUI/Misc/DLLInterface.cpp | 17 +- source/tools/atlas/AtlasUI/Misc/stdafx.h | 7 +- .../AtlasUI/ScenarioEditor/ScenarioEditor.cpp | 20 ++- .../AtlasUI/ScenarioEditor/SectionLayout.cpp | 9 +- .../AtlasUI/ScenarioEditor/SectionLayout.h | 4 + .../Sections/Cinematic/Cinematic.cpp | 19 ++- .../Sections/Environment/Environment.cpp | 6 +- .../Sections/Environment/LightControl.cpp | 8 +- .../ScenarioEditor/Sections/Object/Object.cpp | 2 +- .../ScenarioEditor/Tools/Common/Brushes.h | 2 + .../Tools/Common/ObjectSettings.h | 1 + .../ScenarioEditor/Tools/Common/Tools.h | 2 +- source/tools/atlas/DatafileIO/BAR/BAR.cpp | 2 +- source/tools/atlas/DatafileIO/BAR/BAR.h | 4 +- source/tools/atlas/DatafileIO/DDT/DDT.cpp | 49 +++--- source/tools/atlas/DatafileIO/Util.cpp | 15 ++ source/tools/atlas/DatafileIO/Util.h | 17 ++ source/tools/atlas/DatafileIO/XMB/XMB.cpp | 27 ++-- .../tools/atlas/GameInterface/CommandProc.cpp | 1 + .../Handlers/GraphicsSetupHandlers.cpp | 1 + source/tools/atlas/GameInterface/Messages.h | 5 +- source/tools/atlas/GameInterface/Register.cpp | 3 + source/tools/atlas/GameInterface/Shareable.h | 2 + 81 files changed, 756 insertions(+), 249 deletions(-) diff --git a/source/graphics/ObjectEntry.h b/source/graphics/ObjectEntry.h index 9ae2f27817..49f144b6ac 100644 --- a/source/graphics/ObjectEntry.h +++ b/source/graphics/ObjectEntry.h @@ -7,6 +7,7 @@ class CObjectBase; struct SPropPoint; #include +#include #include #include #include "ps/CStr.h" diff --git a/source/graphics/Terrain.cpp b/source/graphics/Terrain.cpp index 01985de846..444212ec49 100644 --- a/source/graphics/Terrain.cpp +++ b/source/graphics/Terrain.cpp @@ -17,6 +17,10 @@ #include "simulation/EntityManager.h" #include "simulation/Entity.h" +#include "TerrainProperties.h" +#include "TextureEntry.h" +#include "TextureManager.h" + #include #include "Terrain.h" #include "Patch.h" @@ -89,10 +93,13 @@ bool CTerrain::isOnMap(const CVector2D& v) const return isOnMap(v.x, v.y); } -bool CTerrain::isPassable(const CVector2D &tileSpaceLoc) const +bool CTerrain::isPassable(const CVector2D &loc/*tile space*/, HEntity entity) const { - // TODO: Take into account the terrain type at this location - return true; + CMiniPatch *pTile = GetTile(loc.x, loc.y); + CTextureEntry *pTexEntry = g_TexMan.FindTexture(pTile->Tex1); + CTerrainPropertiesPtr pProperties = pTexEntry->GetProperties(); + + return pProperties->IsPassable(entity); } /////////////////////////////////////////////////////////////////////////////// diff --git a/source/graphics/Terrain.h b/source/graphics/Terrain.h index 5f3bec46ca..2b769a730e 100644 --- a/source/graphics/Terrain.h +++ b/source/graphics/Terrain.h @@ -13,6 +13,7 @@ #include "maths/Vector3D.h" #include "graphics/SColor.h" +class HEntity; class CEntity; class CPatch; class CMiniPatch; @@ -57,7 +58,7 @@ public: bool isOnMap(const CVector2D& v) const; - bool isPassable(const CVector2D& tileSpaceLoc) const; + bool isPassable(const CVector2D& tileSpaceLoc, HEntity entity) const; void clampCoordToMap(int& index) const { diff --git a/source/graphics/TerrainProperties.cpp b/source/graphics/TerrainProperties.cpp index 4b03a9ea2d..798c0dcfe5 100644 --- a/source/graphics/TerrainProperties.cpp +++ b/source/graphics/TerrainProperties.cpp @@ -1,7 +1,10 @@ #include "precompiled.h" +#include #include +#include "simulation/Entity.h" + #include "TerrainProperties.h" #include "TextureManager.h" #include "ps/Overlay.h" @@ -13,6 +16,8 @@ #include "ps/CLogger.h" #define LOG_CATEGORY "graphics" +using namespace std; + CTerrainProperties::CTerrainProperties(CTerrainPropertiesPtr parent): m_pParent(parent), m_BaseColor(0), @@ -61,7 +66,7 @@ CTerrainPropertiesPtr CTerrainProperties::FromXML(CTerrainPropertiesPtr parent, if (child.getNodeName() == el_terrain) { CTerrainPropertiesPtr ret (new CTerrainProperties(parent)); - ret->LoadXML(child, &XeroFile); + ret->LoadXML(child, &XeroFile, path); return ret; } else @@ -77,21 +82,18 @@ CTerrainPropertiesPtr CTerrainProperties::FromXML(CTerrainPropertiesPtr parent, return CTerrainPropertiesPtr(); } -void CTerrainProperties::LoadXML(XMBElement node, CXeromyces *pFile) +void CTerrainProperties::LoadXML(XMBElement node, CXeromyces *pFile, const char *path) { #define ELMT(x) int elmt_##x = pFile->getElementID(#x) #define ATTR(x) int attr_##x = pFile->getAttributeID(#x) ELMT(doodad); ELMT(passable); + ELMT(impassable); ELMT(event); // Terrain Attribs ATTR(mmap); ATTR(groups); ATTR(properties); - // Passable Attribs - ATTR(type); - ATTR(speed); - ATTR(effect); // Doodad Attribs ATTR(name); ATTR(max); @@ -101,11 +103,8 @@ void CTerrainProperties::LoadXML(XMBElement node, CXeromyces *pFile) #undef ATTR // stomp on "unused" warnings - UNUSED2(attr_effect); UNUSED2(attr_name); - UNUSED2(attr_type); UNUSED2(attr_on); - UNUSED2(attr_speed); UNUSED2(attr_max); UNUSED2(elmt_event); UNUSED2(elmt_passable); @@ -156,8 +155,76 @@ void CTerrainProperties::LoadXML(XMBElement node, CXeromyces *pFile) } } - // TODO Parse information in child nodes (doodads, passable, events) and - // store them somewhere + XMBElementList children = node.getChildNodes(); + for (int i=0; igetAttributeID(#x) + // Passable Attribs + ATTR(type); + ATTR(speed); + ATTR(effect); + ATTR(prints); + #undef ATTR + + STerrainPassability pass(passable); + bool hasType; + bool hasSpeed; + XMBAttributeList attribs = node.getAttributes(); + for (int i=0;i::iterator it=m_Passabilities.begin(); + for (;it != m_Passabilities.end();++it) + { + if (entity->m_classes.IsMember(it->m_Type)) + return *it; + } + return m_DefaultPassability; +} + +bool CTerrainProperties::IsPassable(HEntity entity) +{ + return GetPassability(entity).m_Passable; +} + +double CTerrainProperties::GetSpeedFactor(HEntity entity) +{ + return GetPassability(entity).m_SpeedFactor; +} diff --git a/source/graphics/TerrainProperties.h b/source/graphics/TerrainProperties.h index 5931cb1d59..0e9a715b64 100644 --- a/source/graphics/TerrainProperties.h +++ b/source/graphics/TerrainProperties.h @@ -10,6 +10,7 @@ #ifndef graphics_TerrainProperties_H #define graphics_TerrainProperties_H +#include "simulation/EntityHandles.h" #include "ps/CStr.h" #include @@ -17,9 +18,22 @@ class CTerrainGroup; class XMBElement; class CXeromyces; class CTerrainProperties; +class CEntity; typedef boost::shared_ptr CTerrainPropertiesPtr; +struct STerrainPassability +{ + explicit STerrainPassability(bool passable=true): + m_Type(), m_Passable(passable), m_SpeedFactor(passable?1.0:0.0) + {} + + CStr m_Type; + bool m_Passable; + double m_SpeedFactor; + // TODO Effects +}; + class CTerrainProperties { public: @@ -36,10 +50,16 @@ private: u32 m_BaseColor; bool m_HasBaseColor; + STerrainPassability m_DefaultPassability; + // All terrain type groups we're a member of GroupVector m_Groups; + + // Passability definitions + std::vector m_Passabilities; - void LoadXML(XMBElement node, CXeromyces *pFile); + void ReadPassability(bool passable, XMBElement node, CXeromyces *pFile, const char *path); + void LoadXML(XMBElement node, CXeromyces *pFile, const char *path); public: CTerrainProperties(CTerrainPropertiesPtr parent); @@ -63,6 +83,10 @@ public: // Use HasBaseColor() to see if the value is valid. // The color value is in BGRA format u32 GetBaseColor(); + + double GetSpeedFactor(HEntity entity); + bool IsPassable(HEntity entity); + const STerrainPassability &GetPassability(HEntity entity); const GroupVector &GetGroups() const { return m_Groups; } diff --git a/source/lib/cache_adt.h b/source/lib/cache_adt.h index 860bbbf8e3..097a11d4c3 100644 --- a/source/lib/cache_adt.h +++ b/source/lib/cache_adt.h @@ -27,7 +27,7 @@ #include #include -#include +#include // std::priority_queue /* Cache for items of variable size and value/"cost". diff --git a/source/lib/res/file/path.cpp b/source/lib/res/file/path.cpp index b381a9c003..7100376472 100644 --- a/source/lib/res/file/path.cpp +++ b/source/lib/res/file/path.cpp @@ -189,10 +189,15 @@ LibError file_set_root_dir(const char* argv0, const char* rel_path) // (slight optimization, speeds up path lookup) if(!realpath(n_path, n_root_dir)) return LibError_from_errno(); + // .. append DIR_SEP to simplify code that uses n_root_dir - // (note: already 0-terminated, since it's static) n_root_dir_len = strlen(n_root_dir)+1; // +1 for trailing DIR_SEP + assert((n_root_dir_len+1) < sizeof(n_root_dir)); // Just checking n_root_dir[n_root_dir_len-1] = DIR_SEP; + // You might think that n_root_dir is already 0-terminated, since it's + // static - but that might not be true after calling file_reset_root_dir! + n_root_dir[n_root_dir_len] = 0; + return INFO::OK; } diff --git a/source/lib/res/sound/snd_mgr.cpp b/source/lib/res/sound/snd_mgr.cpp index 40481e75c3..06c0ad75fe 100644 --- a/source/lib/res/sound/snd_mgr.cpp +++ b/source/lib/res/sound/snd_mgr.cpp @@ -251,7 +251,7 @@ static LibError alc_init() // ignore } #else - alc_dev = alcOpenDevice((ALCchar*)alc_dev_name); + alc_dev = alcOpenDevice(alc_dev_name); #endif if(alc_dev) @@ -268,7 +268,12 @@ static LibError alc_init() if(err != ALC_NO_ERROR || !alc_dev || !alc_ctx) { debug_printf("alc_init failed. alc_dev=%p alc_ctx=%p alc_dev_name=%s err=%d\n", alc_dev, alc_ctx, alc_dev_name, err); - ret = ERR::FAIL; +// FIXME Hack to get around exclusive access to the sound device +#if OS_UNIX + ret = INFO::OK; +#else + ret = ERR::FAIL; +#endif } // make note of which sound device is actually being used diff --git a/source/lib/self_test.h b/source/lib/self_test.h index 02f1fe7807..83949d9fcb 100644 --- a/source/lib/self_test.h +++ b/source/lib/self_test.h @@ -106,7 +106,7 @@ For further details, see below. #ifndef SELF_TEST_H__ #define SELF_TEST_H__ -/*/* +/* // a self test is enabled if at the point of its definition // SELF_TEST_ENABLED evaluates to 1 (non-zero). @@ -184,6 +184,10 @@ extern bool self_test_active; #define CXXTEST_HAVE_EH #define CXXTEST_HAVE_STD +// If HAVE_STD wasn't defined at the point the ValueTraits header was included +// this header won't have been included and the default traits will be used for +// all variables... So fix that now ;-) +#include #include #define TS_ASSERT_OK(expr) TS_ASSERT_EQUALS((expr), INFO::OK) diff --git a/source/lib/sysdep/unix/dir_watch_fam.cpp b/source/lib/sysdep/unix/dir_watch_fam.cpp index 947676b183..39a8aa68d5 100644 --- a/source/lib/sysdep/unix/dir_watch_fam.cpp +++ b/source/lib/sysdep/unix/dir_watch_fam.cpp @@ -76,8 +76,8 @@ int dir_get_changed_file(char* fn) { if(initialized == -1) return ERR::FAIL; // NOWARN - if(!initialized) - WARN_RETURN(ERR::LOGIC); + if(!initialized) // XXX Fix Atlas instead of supressing the warning + return ERR::FAIL; //WARN_RETURN(ERR::LOGIC); FAMEvent e; while(FAMPending(&fc) > 0) diff --git a/source/lib/sysdep/unix/udbg.cpp b/source/lib/sysdep/unix/udbg.cpp index 84aaca64ce..1174763676 100644 --- a/source/lib/sysdep/unix/udbg.cpp +++ b/source/lib/sysdep/unix/udbg.cpp @@ -39,6 +39,7 @@ #define PROFILE_RESOLVE_SYMBOL 0 // Hard-coded - yuck :P +// These should only be used as fallbacks #if defined(TESTING) #define EXE_NAME "pyrogenesis_test" #elif defined(NDEBUG) @@ -96,6 +97,7 @@ void udbg_launch_debugger() else if (ret > 0) { // Parent (original) fork: + debug_printf("Sleeping until debugger attaches.\nPlease wait.\n"); sleep(DEBUGGER_WAIT); } else // fork error, ret == -1 @@ -141,7 +143,7 @@ LibError debug_dump_stack(wchar_t* buf, size_t max_chars, uint skip, void* UNUSE char file[DBG_FILE_LEN]; char symbol[DBG_SYMBOL_LEN]; int line; - uint len; + int len; if (debug_resolve_symbol(bt[i], symbol, file, &line) == 0) len = swprintf(bufpos, MAX_OUT_CHARS, L"(0x%08x) %hs:%d %hs\n", bt[i], file, line, symbol); @@ -168,7 +170,7 @@ static int slurp_symtab(symbol_file_context *ctx) bfd *abfd=ctx->abfd; asymbol ***syms=&ctx->syms; long symcount; - unsigned int size=0; + int size=0; if ((bfd_get_file_flags (abfd) & HAS_SYMS) == 0) { @@ -188,9 +190,9 @@ static int slurp_symtab(symbol_file_context *ctx) symcount = bfd_canonicalize_symtab(abfd, *syms); if (symcount == 0) - symcount = bfd_read_minisymbols (abfd, FALSE, (void **)syms, &size); + symcount = bfd_read_minisymbols (abfd, FALSE, (void **)syms, (uint *)&size); if (symcount == 0) - symcount = bfd_read_minisymbols (abfd, TRUE /* dynamic */, (void **)syms, &size); + symcount = bfd_read_minisymbols (abfd, TRUE /* dynamic */, (void **)syms, (uint *)&size); if (symcount < 0) { @@ -243,7 +245,17 @@ static int read_symbols(const char *file_name, symbol_file_context *ctx) void udbg_init(void) { - if (read_symbols(EXE_NAME, &ps_dbg_context)==0) + char n_path[PATH_MAX]; + char *exename=n_path; + if (sys_get_executable_name(n_path, sizeof(n_path)) != INFO::OK) + { + debug_printf("sys_get_executable_name didn't work, using hard-coded guess %s.\n", EXE_NAME); + exename=EXE_NAME; + } + + debug_printf("udbg_init: loading symbols from %s.\n", exename); + + if (read_symbols(exename, &ps_dbg_context)==0) udbg_initialized=true; #if PROFILE_RESOLVE_SYMBOL diff --git a/source/lib/sysdep/unix/x.cpp b/source/lib/sysdep/unix/x.cpp index 56d4199732..15d966b2d4 100644 --- a/source/lib/sysdep/unix/x.cpp +++ b/source/lib/sysdep/unix/x.cpp @@ -26,9 +26,18 @@ #include "lib/lib.h" #include "lib/debug.h" #include "lib/sysdep/gfx.h" +#include "SDL/SDL.h" +#include "SDL/SDL_syswm.h" #include +static Display *SDL_Display; +static Window SDL_Window; +static void (*Lock_Display)(void); +static void (*Unlock_Display)(void); +static wchar_t *selection_data=NULL; +static size_t selection_size=0; + // useful for choosing a video mode. not called by detect(). // if we fail, outputs are unchanged (assumed initialized to defaults) LibError gfx_get_video_mode(int* xres, int* yres, int* bpp, int* freq) @@ -193,19 +202,132 @@ LibError sys_clipboard_free(wchar_t *clip_buf) return INFO::OK; } -/* -Setting the Selection (i.e. "copy") -* Would require overriding the SDL X event handler to receive other apps' - requests for the selection buffer -* Step-by-step: - * Store the selection text in a local buffer - * Tell the X server that we want to own the selection - * Listen for Selection events and respond to them as appropriate -*/ -LibError sys_clipboard_set(const wchar_t *clip_str) +/** + * An SDL Event filter that intercepts other applications' requests for the + * X selection buffer. + * + * @see x11_clipboard_init + * @see sys_clipboard_set + */ +int clipboard_filter(const SDL_Event *event) { - // Not Implemented, see comment before clipboard_get, above - WARN_RETURN(ERR::FAIL); + /* Pass on all non-window manager specific events immediately */ + /* And do nothing if we don't actually have a clip-out to send out */ + if (event->type != SDL_SYSWMEVENT || !selection_data) + return 1; + + /* Handle window-manager specific clipboard events */ + switch (event->syswm.msg->event.xevent.type) { + /* Copy the selection from our buffer to the requested property, and + convert to the requested target format */ + case SelectionRequest: { + XSelectionRequestEvent *req; + XEvent sevent; + + req = &event->syswm.msg->event.xevent.xselectionrequest; + sevent.xselection.type = SelectionNotify; + sevent.xselection.display = req->display; + sevent.xselection.selection = req->selection; + sevent.xselection.target = req->target; + sevent.xselection.property = None; + sevent.xselection.requestor = req->requestor; + sevent.xselection.time = req->time; + // Simply strip all non-Latin1 characters and replace with '?' + // We should support XA_UTF8 + if (req->target == XA_STRING) + { + size_t size = wcslen(selection_data); + u8 *buf = (u8 *)alloca(size); + + for (size_t i=0;irequestor, req->property, + sevent.xselection.target, 8, PropModeReplace, + buf, size); + sevent.xselection.property = req->property; + } + // TODO Add more target formats + XSendEvent(SDL_Display,req->requestor,False,0,&sevent); + XSync(SDL_Display, False); + } + break; + } + + return 1; +} + +/** + * Initialization for X clipboard handling, called on-demand by + * sys_clipboard_set. + */ +LibError x11_clipboard_init() +{ + SDL_SysWMinfo info; + + SDL_VERSION(&info.version); + if ( SDL_GetWMInfo(&info) ) + { + /* Save the information for later use */ + if ( info.subsystem == SDL_SYSWM_X11 ) + { + SDL_Display = info.info.x11.display; + SDL_Window = info.info.x11.window; + Lock_Display = info.info.x11.lock_func; + Unlock_Display = info.info.x11.unlock_func; + + /* Enable the special window hook events */ + SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); + SDL_SetEventFilter(clipboard_filter); + + return INFO::OK; + } + else + { + return ERR::FAIL; + } + } + + return INFO::OK; +} + +/** + * Set the Selection (i.e. "copy") + * + * Step-by-step (X11) + *
    + *
  • Store the selection text in a local buffer + *
  • Tell the X server that we want to own the selection + *
  • Listen for Selection events and respond to them as appropriate + *
+ */ +LibError sys_clipboard_set(const wchar_t *str) +{ + ONCE(x11_clipboard_init()); + + debug_printf("sys_clipboard_set: %ls\n", str); + + if (selection_data) + { + free(selection_data); + selection_data = NULL; + } + + selection_size = (wcslen(str)+1)*sizeof(wchar_t); + selection_data = (wchar_t *)malloc(selection_size); + wcscpy(selection_data, str); + + Lock_Display(); + // Like for the clipboard_get code above, we rather use CLIPBOARD than + // PRIMARY - more windows'y behaviour there. + Atom clipboard_atom = XInternAtom(SDL_Display, "CLIPBOARD", False); + XSetSelectionOwner(SDL_Display, clipboard_atom, SDL_Window, CurrentTime); + XSetSelectionOwner(SDL_Display, XA_PRIMARY, SDL_Window, CurrentTime); + Unlock_Display(); + + return INFO::OK; } #endif // #ifdef HAVE_X diff --git a/source/lib/tests/test_lib.h b/source/lib/tests/test_lib.h index 02a0d80ad4..2d1428c4df 100644 --- a/source/lib/tests/test_lib.h +++ b/source/lib/tests/test_lib.h @@ -222,7 +222,8 @@ public: { uint x = rand(1, 3); // paranoia: don't use array (x might not be 1 or 2 - checked below) - if(x == 1) ones++; if(x == 2) twos++; + if(x == 1) ones++; + if(x == 2) twos++; } TS_ASSERT_EQUALS(ones+twos, 100); TS_ASSERT(ones > 10 && twos > 10); diff --git a/source/lib/tests/test_lockfree.h b/source/lib/tests/test_lockfree.h index ee6ef31af8..4c07a6abd2 100644 --- a/source/lib/tests/test_lockfree.h +++ b/source/lib/tests/test_lockfree.h @@ -188,8 +188,10 @@ class TestMultithread : public CxxTest::TestSuite public: TestMultithread() : is_complete(false), num_active_threads(0), - list(), hash(), - mutex() {} + list(), hash() + { + pthread_mutex_init(&mutex, NULL); + } void disabled_due_to_failure_on_p4_test_multithread() { diff --git a/source/lib/tests/test_path_util.h b/source/lib/tests/test_path_util.h index e9c5784a3c..02a409b086 100644 --- a/source/lib/tests/test_path_util.h +++ b/source/lib/tests/test_path_util.h @@ -3,15 +3,36 @@ #include "lib/path_util.h" -class TestPathUtil : public CxxTest::TestSuite -{ - void TEST_APPEND(const char* path1, const char* path2, uint flags, const char* correct_result) - { - char dst[PATH_MAX] = {0}; - TS_ASSERT_OK(path_append(dst, path1, path2, flags)); - TS_ASSERT_STR_EQUALS(dst, correct_result); +// Macros, not functions, to get proper line number reports when tests fail +#define TEST_APPEND(path1, path2, flags, correct_result) \ + { \ + char dst[PATH_MAX] = {0}; \ + TS_ASSERT_OK(path_append(dst, path1, path2, flags)); \ + TS_ASSERT_STR_EQUALS(dst, correct_result); \ } +#define TEST_NAME_ONLY(path, correct_result) \ +{ \ + const char* result = path_name_only(path); \ + TS_ASSERT_STR_EQUALS(result, correct_result); \ +} + +#define TEST_LAST_COMPONENT(path, correct_result) \ +{ \ + const char* result = path_last_component(path); \ + TS_ASSERT_STR_EQUALS(result, correct_result); \ +} + +#define TEST_STRIP_FN(path_readonly, correct_result) \ +{ \ + char path[PATH_MAX]; \ + path_copy(path, path_readonly); \ + path_strip_fn(path); \ + TS_ASSERT_STR_EQUALS(path, correct_result); \ +} + +class TestPathUtil : public CxxTest::TestSuite +{ // if correct_ret is ERR::FAIL, ignore correct_result. void TEST_REPLACE(const char* src, const char* remove, const char* replace, LibError correct_ret, const char* correct_result) @@ -22,26 +43,6 @@ class TestPathUtil : public CxxTest::TestSuite TS_ASSERT_STR_EQUALS(dst, correct_result); } - void TEST_NAME_ONLY(const char* path, const char* correct_result) - { - const char* result = path_name_only(path); - TS_ASSERT_STR_EQUALS(result, correct_result); - } - - void TEST_LAST_COMPONENT(const char* path, const char* correct_result) - { - const char* result = path_last_component(path); - TS_ASSERT_STR_EQUALS(result, correct_result); - } - - void TEST_STRIP_FN(const char* path_readonly, const char* correct_result) - { - char path[PATH_MAX]; - path_copy(path, path_readonly); - path_strip_fn(path); - TS_ASSERT_STR_EQUALS(path, correct_result); - } - void TEST_PATH_EXT(const char* path, const char* correct_result) { const char* result = path_extension(path); diff --git a/source/network/NetMessage.cpp b/source/network/NetMessage.cpp index 114f713ea3..de2808e7cd 100644 --- a/source/network/NetMessage.cpp +++ b/source/network/NetMessage.cpp @@ -15,7 +15,7 @@ #define LOG_CAT_NET "net" -// NEVER modify the deserializer map outside the ONCE-block in DeserializeMessage +// Please don't modify the deserializer map outside the ONCE-block in DeserializeMessage typedef std::map MessageDeserializerMap; MessageDeserializerMap g_DeserializerMap; diff --git a/source/ps/CConsole.cpp b/source/ps/CConsole.cpp index 17068abcba..7564da133b 100644 --- a/source/ps/CConsole.cpp +++ b/source/ps/CConsole.cpp @@ -751,8 +751,8 @@ void CConsole::SendChatMessage(const wchar_t *szMessage) g_NetClient->Push(msg); else { - msg->m_Sender=g_NetServer->GetServerPlayerName(); - ReceivedChatMessage(msg->m_Sender.c_str(), msg->m_Message.c_str()); + msg->m_Sender=0; + ReceivedChatMessage(g_NetServer->GetServerPlayerName(), msg->m_Message.c_str()); g_NetServer->Broadcast(msg); } } diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index 9dcf8f7287..c3913b750f 100644 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -18,6 +18,11 @@ #include "simulation/Simulation.h" #include "graphics/GameView.h" +#include "network/Client.h" + +class CNetServer; +extern CNetServer *g_NetServer; + extern CConsole* g_Console; extern bool g_GameRestarted; @@ -118,8 +123,12 @@ PSRETURN CGame::StartGame(CGameAttributes *pAttribs) { // JW: this loop is taken from ScEd and fixes lack of player color. // TODO: determine proper number of players. - for (int i=1; i<8; ++i) - pAttribs->GetSlot(i)->AssignLocal(); + // SB: Only do this for non-network games + if (!g_NetClient && !g_NetServer) + { + for (int i=1; i<8; ++i) + pAttribs->GetSlot(i)->AssignLocal(); + } pAttribs->FinalizeSlots(); m_NumPlayers=pAttribs->GetSlotCount(); @@ -130,7 +139,14 @@ PSRETURN CGame::StartGame(CGameAttributes *pAttribs) for (uint i=0;i <= m_NumPlayers;i++) m_Players[i]=pAttribs->GetPlayer(i); - m_pLocalPlayer=m_Players[1]; + if (g_NetClient) + { + // TODO + //m_pLocalPlayer=g_NetClient->GetLocalPlayer(); + debug_assert(m_pLocalPlayer && "Darn it! We weren't assigned to a slot!"); + } + else + m_pLocalPlayer=m_Players[1]; RegisterInit(pAttribs); } @@ -156,7 +172,7 @@ void CGame::Update(double deltaTime) // ^ Quick game over hack is implemented, no summary screen however if ( m_World->GetEntityManager()->GetDeath() ) { - UpdateGameStatus(); + UpdateGameStatus(); if (GameStatus != 0) EndGame(); } diff --git a/source/ps/GameAttributes.cpp b/source/ps/GameAttributes.cpp index 5a3c02c779..ce6a187b7d 100644 --- a/source/ps/GameAttributes.cpp +++ b/source/ps/GameAttributes.cpp @@ -150,7 +150,7 @@ namespace PlayerSlotArray_JS return JS_FALSE; uint index=ToPrimitive(id); - if (index > pInstance->m_NumSlots) + if (index >= pInstance->m_NumSlots) return JS_FALSE; *vp=OBJECT_TO_JSVAL(pInstance->m_PlayerSlots[index]->GetScript()); diff --git a/source/ps/GameSetup/Atlas.cpp b/source/ps/GameSetup/Atlas.cpp index 2f2957ef30..8e2a4223fe 100644 --- a/source/ps/GameSetup/Atlas.cpp +++ b/source/ps/GameSetup/Atlas.cpp @@ -9,8 +9,28 @@ //---------------------------------------------------------------------------- static void* const ATLAS_SO_UNAVAILABLE = (void*)-1; -static void* atlas_so_handle; +static void* atlas_so_handle = NULL; +// Calculate the correct AtlasUI DLL +// TODO Use path_util instead, get the actual path to the ps_dbg exe and append +// the library name. + +// note: on Linux, lib is prepended to the SO file name and we need to add ./ +// to make dlopen look in the current working directory +#if OS_UNIX +# define PREFIX "./lib" +#else +# define PREFIX "" +#endif +// since this SO exports a C++ interface, it is critical that +// compiler options are the same between app and SO; therefore, +// we need to go with the debug version in debug builds. +// note: on Windows, the extension is replaced with .dll by dlopen. +#ifndef NDEBUG +static const char* so_name = PREFIX "AtlasUI_dbg.so"; +#else +static const char* so_name = PREFIX "AtlasUI.so"; +#endif // free reference to Atlas UI SO (avoids resource leak report) void ATLAS_Shutdown() @@ -31,15 +51,6 @@ static bool ATLAS_IsAvailable() // postcondition: atlas_so_handle valid or == ATLAS_SO_UNAVAILABLE. if(atlas_so_handle == 0) { - // since this SO exports a C++ interface, it is critical that - // compiler options are the same between app and SO; therefore, - // we need to go with the debug version in debug builds. - // note: on Windows, the extension is replaced with .dll by dlopen. -#ifndef NDEBUG - const char* so_name = "AtlasUI_dbg.so"; -#else - const char* so_name = "AtlasUI.so"; -#endif // we don't really care when relocations take place, but one of // {RTLD_NOW, RTLD_LAZY} must be passed. go with the former because // it is safer and matches the Windows load behavior. diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index 775e8e7495..59fdbebd0d 100644 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -1130,7 +1130,7 @@ InReaction interactInputHandler( const SDL_Event_* ev ) // SDL_BUTTON_* values; these are verified at compile time. cassert(SDL_BUTTON_LEFT == 1 && SDL_BUTTON_MIDDLE == 2 && SDL_BUTTON_RIGHT == 3 && \ SDL_BUTTON_WHEELUP == 4 && SDL_BUTTON_WHEELDOWN == 5); - const uint SDL_BUTTON_INDEX_COUNT = 6; + const int SDL_BUTTON_INDEX_COUNT = 6; static double lastclicktime[SDL_BUTTON_INDEX_COUNT]; static HEntity lastclickobject[SDL_BUTTON_INDEX_COUNT]; static u8 clicks[SDL_BUTTON_INDEX_COUNT]; diff --git a/source/ps/Interact.h b/source/ps/Interact.h index ca058bc417..b645781e3e 100644 --- a/source/ps/Interact.h +++ b/source/ps/Interact.h @@ -9,6 +9,7 @@ #include #include +#include "CStr.h" #include "Singleton.h" #include "simulation/EntityHandles.h" #include "ps/Vector2D.h" diff --git a/source/ps/tests/test_CStr.h b/source/ps/tests/test_CStr.h index 60f9b20b0d..d6cf3206d8 100644 --- a/source/ps/tests/test_CStr.h +++ b/source/ps/tests/test_CStr.h @@ -37,7 +37,7 @@ public: TS_ASSERT_SAME_DATA(str_utf8.data(), chr_utf8, sizeof(chr_utf8)); CStrW str_utf16b = str_utf8.FromUTF8(); - TS_ASSERT_EQUALS(str_utf16b, str_utf16); + TS_ASSERT_WSTR_EQUALS(str_utf16b, str_utf16); } void test_invalid_utf8() diff --git a/source/ps/utf16string.h b/source/ps/utf16string.h index fa0e2f4b96..b21925e50a 100644 --- a/source/ps/utf16string.h +++ b/source/ps/utf16string.h @@ -48,12 +48,9 @@ namespace std { static const char_type* find(const char_type* s, size_t n, const char_type& a) { - size_t i; - for (i=0;i neighbors; PROFILE_START("get neighbors"); - neighbors = mGoal->getNeighbors(best->coord, player); + neighbors = mGoal->getNeighbors(best->coord, entity); PROFILE_END("get neighbors"); /* Update the neighbors of the best node */ @@ -356,7 +360,7 @@ float AStarGoalLowLevel::getTileCost( const CVector2D& loc1, const CVector2D& lo return (loc2-loc1).length() - radius; } -bool AStarGoalLowLevel::isPassable( const CVector2D &loc, CPlayer* player ) +bool AStarGoalLowLevel::isPassable( const CVector2D &loc, HEntity entity ) { CTerrain* pTerrain = g_Game->GetWorld()->GetTerrain(); int size = pTerrain->GetTilesPerSide(); @@ -366,12 +370,12 @@ bool AStarGoalLowLevel::isPassable( const CVector2D &loc, CPlayer* player ) return false; } - if ( pTerrain->isPassable(loc) ) + if ( pTerrain->isPassable(loc, entity) ) { // If no entity blocking, return true CVector2D wloc = TilespaceToWorldspace(loc); CBoundingBox bounds(wloc.x, wloc.y, 0, CELL_SIZE, CELL_SIZE, 3); - if ( getCollisionObject(&bounds, player) == NULL ) + if ( getCollisionObject(&bounds, entity->GetPlayer()) == NULL ) { return true; } @@ -389,7 +393,7 @@ CVector2D AStarGoalLowLevel::getTile( const CVector2D &loc ) return WorldspaceToTilespace(loc); } -std::vector AStarGoalLowLevel::getNeighbors( const CVector2D &loc, CPlayer* player ) +std::vector AStarGoalLowLevel::getNeighbors( const CVector2D &loc, HEntity entity) { std::vector vec; @@ -401,7 +405,7 @@ std::vector AStarGoalLowLevel::getNeighbors( const CVector2D &loc, CP { CVector2D c = loc; c.x += xdiff; c.y += ydiff; - if ( isPassable(c, player) ) + if ( isPassable(c, entity) ) { vec.push_back(c); } diff --git a/source/simulation/AStarEngine.h b/source/simulation/AStarEngine.h index d1c6143de8..fe25411d00 100644 --- a/source/simulation/AStarEngine.h +++ b/source/simulation/AStarEngine.h @@ -64,7 +64,7 @@ public: void setGoal(AStarGoalBase* goal) { mGoal = goal; } - bool findPath( const CVector2D& src, const CVector2D& dest, CPlayer* player=0, float radius=0.0f ); + bool findPath( const CVector2D& src, const CVector2D& dest, HEntity entity, float radius=0.0f ); std::vector getLastPath(); // The maximum number of nodes that will be expanded before failure is declared @@ -132,8 +132,8 @@ public: virtual float distanceToGoal( const CVector2D& ) = 0; virtual bool atGoal( const CVector2D& ) = 0; virtual float getTileCost( const CVector2D&, const CVector2D& ) = 0; - virtual bool isPassable( const CVector2D&, CPlayer* player=0 ) = 0; - virtual std::vector getNeighbors( const CVector2D&, CPlayer* player=0 ) = 0; + virtual bool isPassable( const CVector2D&, HEntity entity) = 0; + virtual std::vector getNeighbors( const CVector2D&, HEntity entity) = 0; virtual CVector2D getCoord( const CVector2D& ) = 0; virtual CVector2D getTile( const CVector2D& ) = 0; virtual float getRadius() = 0; @@ -148,8 +148,8 @@ public: float distanceToGoal( const CVector2D& loc ); bool atGoal( const CVector2D& loc ); float getTileCost( const CVector2D& loc1, const CVector2D& loc2 ); - bool isPassable( const CVector2D& loc, CPlayer* player=0 ); - std::vector getNeighbors( const CVector2D& loc, CPlayer* player=0 ); + bool isPassable( const CVector2D& loc, HEntity entity); + std::vector getNeighbors( const CVector2D& loc, HEntity entity); CVector2D getCoord( const CVector2D& loc); CVector2D getTile( const CVector2D& loc); float getRadius(); diff --git a/source/simulation/PathfindEngine.cpp b/source/simulation/PathfindEngine.cpp index cdc5fd592b..97f940e54a 100644 --- a/source/simulation/PathfindEngine.cpp +++ b/source/simulation/PathfindEngine.cpp @@ -36,7 +36,7 @@ void CPathfindEngine::requestLowLevelPath( HEntity entity, const CVector2D& dest CVector2D source( entity->m_position.X, entity->m_position.Z ); - if ( mLowPathfinder.findPath(source, destination, entity->GetPlayer(), radius) ) + if ( mLowPathfinder.findPath(source, destination, entity, radius) ) { std::vector path = mLowPathfinder.getLastPath(); if( path.size() > 0 ) diff --git a/source/simulation/ScriptObject.h b/source/simulation/ScriptObject.h index 4f9bc10dec..3e135693b8 100644 --- a/source/simulation/ScriptObject.h +++ b/source/simulation/ScriptObject.h @@ -6,6 +6,8 @@ #ifndef SCRIPTOBJECT_INCLUDED #define SCRIPTOBJECT_INCLUDED +#include "scripting/SpiderMonkey.h" + class CStrW; class CScriptEvent; diff --git a/source/sound/SoundGroup.h b/source/sound/SoundGroup.h index d5c028d3a0..9af6091150 100644 --- a/source/sound/SoundGroup.h +++ b/source/sound/SoundGroup.h @@ -37,14 +37,9 @@ Example SoundGroup.xml */ - - - - #ifndef SOUNDGROUP_H_ #define SOUNDGROUP_H_ - #include "lib/res/handle.h" #include "ps/CStr.h" #include "lib/res/sound/snd_mgr.h" @@ -52,11 +47,16 @@ Example SoundGroup.xml #include using namespace std; -enum eSndGrpFlags{ eRandOrder = 0x01, eRandGain = 0x02, eRandPitch = 0x04, eLoop = 0x08 }; +enum eSndGrpFlags +{ + eRandOrder = 0x01, + eRandGain = 0x02, + eRandPitch = 0x04, + eLoop = 0x08 +}; class CSoundGroup { - size_t m_index; // index of the next sound to play vector snd_group; // we store the handles so we can load now and play later @@ -101,10 +101,7 @@ public: // Test flag, returns true if flag is set. inline bool TestFlag(int flag) { return (m_Flags & flag) == flag;} - }; - - #endif //#ifndef SOUNDGROUP_H_ diff --git a/source/tools/atlas/AtlasFrontends/ActorEditor.cpp b/source/tools/atlas/AtlasFrontends/ActorEditor.cpp index f97596d5c9..6d3ec5edc1 100644 --- a/source/tools/atlas/AtlasFrontends/ActorEditor.cpp +++ b/source/tools/atlas/AtlasFrontends/ActorEditor.cpp @@ -1,16 +1,25 @@ -#define WIN32_LEAN_AND_MEAN -#include +#if OS_WIN + +# define WIN32_LEAN_AND_MEAN +# include // Use WinXP-style controls -#if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) -#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") -#endif +# if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) +# pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") +# endif -#define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +# define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +#else +# define ATLASDLLIMPEXP extern "C" +#endif #include "AtlasUI/Misc/DLLInterface.h" +#if OS_WIN int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int) { +#else +int main() { +#endif Atlas_StartWindow(L"ActorEditor"); return 0; } diff --git a/source/tools/atlas/AtlasFrontends/ArchiveViewer.cpp b/source/tools/atlas/AtlasFrontends/ArchiveViewer.cpp index 2268fafc02..6ba3cd3c91 100644 --- a/source/tools/atlas/AtlasFrontends/ArchiveViewer.cpp +++ b/source/tools/atlas/AtlasFrontends/ArchiveViewer.cpp @@ -1,16 +1,25 @@ -#define WIN32_LEAN_AND_MEAN -#include +#if OS_WIN + +# define WIN32_LEAN_AND_MEAN +# include // Use WinXP-style controls -#if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) -#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") -#endif +# if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) +# pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") +# endif -#define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +# define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +#else +# define ATLASDLLIMPEXP extern "C" +#endif #include "AtlasUI/Misc/DLLInterface.h" +#if OS_WIN int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int) { +#else +int main() { +#endif Atlas_StartWindow(L"ArchiveViewer"); return 0; } diff --git a/source/tools/atlas/AtlasFrontends/ColourTester.cpp b/source/tools/atlas/AtlasFrontends/ColourTester.cpp index c03592157e..ee14b43352 100644 --- a/source/tools/atlas/AtlasFrontends/ColourTester.cpp +++ b/source/tools/atlas/AtlasFrontends/ColourTester.cpp @@ -1,16 +1,25 @@ -#define WIN32_LEAN_AND_MEAN -#include +#if OS_WIN + +# define WIN32_LEAN_AND_MEAN +# include // Use WinXP-style controls -#if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) -#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") -#endif +# if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) +# pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") +# endif -#define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +# define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +#else +# define ATLASDLLIMPEXP extern "C" +#endif #include "AtlasUI/Misc/DLLInterface.h" +#if OS_WIN int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int) { +#else +int main() { +#endif Atlas_StartWindow(L"ColourTester"); return 0; } diff --git a/source/tools/atlas/AtlasFrontends/FileConverter.cpp b/source/tools/atlas/AtlasFrontends/FileConverter.cpp index 8f1e390760..87607521d6 100644 --- a/source/tools/atlas/AtlasFrontends/FileConverter.cpp +++ b/source/tools/atlas/AtlasFrontends/FileConverter.cpp @@ -1,16 +1,25 @@ -#define WIN32_LEAN_AND_MEAN -#include +#if OS_WIN + +# define WIN32_LEAN_AND_MEAN +# include // Use WinXP-style controls -#if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) -#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") -#endif +# if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) +# pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") +# endif -#define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +# define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +#else +# define ATLASDLLIMPEXP extern "C" +#endif #include "AtlasUI/Misc/DLLInterface.h" +#if OS_WIN int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int) { +#else +int main() { +#endif Atlas_StartWindow(L"FileConverter"); return 0; } diff --git a/source/tools/atlas/AtlasFrontends/_template.cpp b/source/tools/atlas/AtlasFrontends/_template.cpp index 964d92bfa9..21f2be7f5d 100644 --- a/source/tools/atlas/AtlasFrontends/_template.cpp +++ b/source/tools/atlas/AtlasFrontends/_template.cpp @@ -1,16 +1,25 @@ -#define WIN32_LEAN_AND_MEAN -#include +#if OS_WIN + +# define WIN32_LEAN_AND_MEAN +# include // Use WinXP-style controls -#if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) -#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") -#endif +# if _MSC_VER >= 1400 // (can't be bothered to implement this for VC7.1...) +# pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"") +# endif -#define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +# define ATLASDLLIMPEXP extern "C" __declspec(dllimport) +#else +# define ATLASDLLIMPEXP extern "C" +#endif #include "AtlasUI/Misc/DLLInterface.h" +#if OS_WIN int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int) { +#else +int main() { +#endif Atlas_StartWindow(L"$$WINDOW_NAME$$"); return 0; } diff --git a/source/tools/atlas/AtlasObject/AtlasObject.h b/source/tools/atlas/AtlasObject/AtlasObject.h index c331f1d0b1..48f9b78d6f 100644 --- a/source/tools/atlas/AtlasObject/AtlasObject.h +++ b/source/tools/atlas/AtlasObject/AtlasObject.h @@ -8,6 +8,7 @@ #define ATLASOBJECT_H__ #include // for wchar_t +#include ////////////////////////////////////////////////////////////////////////// // Mostly-private bits: @@ -80,14 +81,17 @@ public: const AtIter operator [] (const char* key) const; // Return the AtObj currently pointed to by this iterator - operator const AtObj () const; + //operator const AtObj () const; + const AtObj operator *() const; // Return the string value of the AtObj currently pointed to by this iterator operator const wchar_t* () const; + //operator const wxChar* () const { return (const wchar_t*)*this; } #ifdef __WXWINDOWS__ // Wrapper function around 'operator wchar_t*', for convenience in wx programs - operator const wxString () const { return (const wchar_t*)*this; } + //operator wxString () const { return (const wchar_t*)*this; } + //wxString towxString() const { return (const wchar_t*)*this; } #endif // Private implementation. (But not 'private:', because it's a waste of time diff --git a/source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp b/source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp index d81f4f6bec..de4704d0d3 100644 --- a/source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp +++ b/source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp @@ -41,7 +41,8 @@ AtIter::operator const wchar_t* () const return L""; } -AtIter::operator const AtObj () const +//AtIter::operator const AtObj () const +const AtObj AtIter::operator * () const { if (p) { @@ -68,12 +69,12 @@ AtIter& AtIter::operator ++ () bool AtIter::defined() const { - return (p != NULL); + return p; } bool AtIter::hasContent() const { - if (p == NULL) + if (!p) return false; if (! p->iter->second) diff --git a/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp b/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp index 51aead7da9..711f4916c5 100644 --- a/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp +++ b/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp @@ -10,7 +10,7 @@ #include "wx/file.h" BEGIN_EVENT_TABLE(ActorEditor, AtlasWindow) - EVT_MENU(ID_CreateEntity, OnCreateEntity) + EVT_MENU(ID_CreateEntity, ActorEditor::OnCreateEntity) END_EVENT_TABLE() @@ -86,12 +86,12 @@ ActorEditor::ActorEditor(wxWindow* parent) void ActorEditor::ThawData(AtObj& in) { - AtObj actor (in["actor"]); + AtObj actor (*in["actor"]); m_ActorEditorListCtrl->ThawData(actor); m_CastShadows->SetValue(actor["castshadow"].defined()); m_Float->SetValue(actor["float"].defined()); - m_Material->SetValue(actor["material"]); + m_Material->SetValue((wxString)actor["material"]); } AtObj ActorEditor::FreezeData() @@ -112,7 +112,6 @@ AtObj ActorEditor::FreezeData() return out; } - static AtObj ConvertToLatestFormat(AtObj in) { if (! in.defined()) @@ -297,12 +296,12 @@ void ActorEditor::ImportData(AtObj& in) // Copy the data into the appropriate UI controls: - AtObj actor (data["actor"]); + AtObj actor (*data["actor"]); m_ActorEditorListCtrl->ImportData(actor); m_CastShadows->SetValue(actor["castshadow"].defined()); m_Float->SetValue(actor["float"].defined()); - m_Material->SetValue(actor["material"]); + m_Material->SetValue((wxString)actor["material"]); } AtObj ActorEditor::ExportData() @@ -398,7 +397,7 @@ void ActorEditor::OnCreateEntity(wxCommandEvent& WXUNUSED(event)) _T("\t") + actorFilename.GetFullPath(wxPATH_UNIX) + _T("\r\n") _T("\r\n"); - wxFile file (outputEntityFilename.fn_str(), wxFile::write); + wxFile file (outputEntityFilename.c_str(), wxFile::write); if (! file.IsOpened()) { wxLogError(_("Failed to open file")); diff --git a/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp b/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp index 74cef7c15b..157db0a602 100644 --- a/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp +++ b/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp @@ -3,6 +3,7 @@ #include "ActorViewer.h" #include "wx/treectrl.h" +#include "wx/regex.h" #include "General/Datafile.h" @@ -190,7 +191,9 @@ ActorViewer::ActorViewer(wxWindow* parent) splitter->SplitVertically(sidePanel, canvas); +#if OS_WIN wglMakeCurrent(NULL, NULL); +#endif POST_MESSAGE(SetContext, (canvas->GetContext())); POST_MESSAGE(Init, (false)); @@ -255,7 +258,7 @@ ActorViewer::ActorViewer(wxWindow* parent) AtObj animationsList (Datafile::ReadList("animations")); for (AtIter it = animationsList["item"]; it.defined(); ++it) - animations.Add(it); + animations.Add((const wchar_t *)it); m_AnimationBox = new wxComboBox(sidePanel, ID_Animations, _T("Idle"), wxDefaultPosition, wxDefaultSize, animations); diff --git a/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.cpp b/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.cpp index f193a98445..b0055baf23 100644 --- a/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.cpp +++ b/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.cpp @@ -4,6 +4,7 @@ #include "Misc/Version.h" +#include #include #include "DatafileIO/BAR/BAR.h" @@ -15,7 +16,9 @@ using namespace DatafileIO; #include "wx/confbase.h" #include "wx/wfstream.h" #include "wx/tooltip.h" +#ifdef _WIN32 #include "wx/msw/registry.h" +#endif #include "wx/progdlg.h" #include "wx/regex.h" @@ -102,7 +105,7 @@ END_EVENT_TABLE() ArchiveViewer::ArchiveViewer(wxWindow* parent) : wxFrame(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(600, 371)) , m_FileHistory(_T("Archive Viewer")) -, m_WindowTitle(wxString::Format(_("%s - Archive Viewer"), g_ProgramNameVersion)) +, m_WindowTitle(wxString::Format(_("%s - Archive Viewer"), g_ProgramNameVersion.c_str())) , m_BARStream(NULL), m_BARReader(NULL), m_PreviewEnabled(false) { SetIcon(wxIcon(_T("ICON_ArchiveViewer"))); @@ -190,7 +193,7 @@ ArchiveViewer::ArchiveViewer(wxWindow* parent) void ArchiveViewer::OnAbout(wxCommandEvent& WXUNUSED(event)) { - wxMessageBox(wxString::Format(_("%s - created by Philip Taylor (philip@wildfiregames.com / philip@zaynar.demon.co.uk)"), g_ProgramNameVersion), + wxMessageBox(wxString::Format(_("%s - created by Philip Taylor (philip@wildfiregames.com / philip@zaynar.demon.co.uk)"), g_ProgramNameVersion.c_str()), _("About"), wxOK|wxCENTRE|wxICON_INFORMATION); } @@ -303,7 +306,7 @@ void ArchiveViewer::UpdateFileList() for (size_t i = 0; i < files.size(); ++i) { - m_CachedFileData[i].Name = files[i].filename.c_str(); + m_CachedFileData[i].Name = utf16tow(files[i].filename); m_CachedFileData[i].NameLower = m_CachedFileData[i].Name.Lower(); m_CachedFileData[i].Size = wxString::Format(_T("%d"), files[i].filesize); @@ -315,7 +318,11 @@ void ArchiveViewer::UpdateFileList() { wxDateTime date (files[i].modified.day, (wxDateTime::Month)(wxDateTime::Jan + files[i].modified.month-1), files[i].modified.year, files[i].modified.hour, files[i].modified.minute, files[i].modified.second, files[i].modified.msecond); - m_CachedFileData[i].Date = wxString::Format(_T("%s %s.%03d"), date.FormatISODate(), date.FormatISOTime(), date.GetMillisecond()); + m_CachedFileData[i].Date = wxString::Format( + _T("%s %s.%03d"), + date.FormatISODate().c_str(), + date.FormatISOTime().c_str(), + date.GetMillisecond()); } } } @@ -434,7 +441,7 @@ void ArchiveViewer::ExtractFiles(bool onlySelected) for (size_t sel = 0; sel < selection.size(); ++sel) { const BAREntry& file = files[selection[sel]]; - wxString filename = file.filename.c_str(); + wxString filename = utf16tow(file.filename); int lastSlash = filename.Find(_T('\\'), true); if (lastSlash != -1) dirs.insert(filename.Mid(0, lastSlash+1).c_str()); @@ -452,7 +459,7 @@ void ArchiveViewer::ExtractFiles(bool onlySelected) { fullFilePath.AppendDir(filePathDirs[i]); if (! wxDirExists(fullFilePath.GetPath())) - wxMkDir(fullFilePath.GetPath()); + wxMkdir(fullFilePath.GetPath()); } } @@ -473,13 +480,13 @@ void ArchiveViewer::ExtractFiles(bool onlySelected) // Append name-in-archive to target root directory, one dir // at a time, calling mkdir at each step if necessary - wxFileName filePath (file.filename.c_str(), wxPATH_WIN); + wxFileName filePath (utf16tow(file.filename), wxPATH_WIN); filePath.MakeAbsolute(rootDir.GetPath()); // Output to disk wxFFileOutputStream outStream(filePath.GetFullPath()); if (! outStream.Ok()) - wxLogError(wxString::Format(_("Error opening output file %s"), filePath.GetFullPath())); + wxLogError(wxString::Format(_("Error opening output file %s"), filePath.GetFullPath().c_str())); else { SeekableOutputStreamFromWx str (outStream); @@ -544,7 +551,7 @@ void ArchiveViewer::UpdatePreview(long item) const BAREntry& file = m_BARReader->GetFileList()[ m_FileListCtrl->GetItemData(item) ]; SeekableInputStream* str = m_BARReader->GetFile(file); - m_PreviewWindow->PreviewFile(file.filename.c_str(), *str); + m_PreviewWindow->PreviewFile(utf16tow(file.filename), *str); delete str; } diff --git a/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.h b/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.h index 8d28cb691f..67683b9d79 100644 --- a/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.h +++ b/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.h @@ -5,6 +5,8 @@ #include "wx/filename.h" #include "wx/listctrl.h" +#include + namespace DatafileIO { class BARReader; diff --git a/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.cpp b/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.cpp index f809ddaaf4..5353e47c8c 100644 --- a/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.cpp +++ b/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.cpp @@ -74,7 +74,7 @@ void FilePreviewer::PreviewFile(const wxString& filename, SeekableInputStream& s m_MainSizer->Add(m_ContentPanel, wxSizerFlags().Expand().Proportion(1)); wxSizer* sizer = new wxBoxSizer(wxVERTICAL); - wxStaticText* fileInfo = new wxStaticText(m_ContentPanel, wxID_ANY, wxString::Format(_("Filename: %s"), filename)); + wxStaticText* fileInfo = new wxStaticText(m_ContentPanel, wxID_ANY, wxString::Format(_("Filename: %s"), filename.c_str())); sizer->Add(fileInfo, wxSizerFlags().Border(wxALL, 5)); m_ContentPanel->SetSizer(sizer); @@ -179,7 +179,7 @@ void FilePreviewer::PreviewFile(const wxString& filename, SeekableInputStream& s formatString = _("unknown"); extraFileInfo = wxString::Format(_("Format: DDT texture\nSubformat: %d %d %d (%s)"), - file.m_Type_Usage, file.m_Type_Alpha, file.m_Type_Format, formatString); + file.m_Type_Usage, file.m_Type_Alpha, file.m_Type_Format, formatString.c_str()); void* buffer; int width, height; diff --git a/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.h b/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.h index 2ebdaa259e..419c7fa544 100644 --- a/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.h +++ b/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.h @@ -11,4 +11,4 @@ public: private: wxPanel* m_ContentPanel; // gets deleted and rebuilt when previewing a new file wxSizer* m_MainSizer; -}; \ No newline at end of file +}; diff --git a/source/tools/atlas/AtlasUI/ColourTester/ColourTesterColourCtrl.cpp b/source/tools/atlas/AtlasUI/ColourTester/ColourTesterColourCtrl.cpp index 17529bfec1..a7df62c6cc 100644 --- a/source/tools/atlas/AtlasUI/ColourTester/ColourTesterColourCtrl.cpp +++ b/source/tools/atlas/AtlasUI/ColourTester/ColourTesterColourCtrl.cpp @@ -96,7 +96,7 @@ ColourTesterColourCtrl::ColourTesterColourCtrl(wxWindow* parent, ColourTesterIma s >> r >> g >> b; text = wxColour(r,g,b); } - presetColourSizer->Add(new ColouredButton(this, back, text, c["@name"], imgctrl)); + presetColourSizer->Add(new ColouredButton(this, back, text, (wxString)c["@name"], imgctrl)); } presetColourSizer->Add(new CustomColourButton(this, _("Custom"), imgctrl)); diff --git a/source/tools/atlas/AtlasUI/ColourTester/ColourTesterImageCtrl.cpp b/source/tools/atlas/AtlasUI/ColourTester/ColourTesterImageCtrl.cpp index c135e368d0..ec2c15cb1a 100644 --- a/source/tools/atlas/AtlasUI/ColourTester/ColourTesterImageCtrl.cpp +++ b/source/tools/atlas/AtlasUI/ColourTester/ColourTesterImageCtrl.cpp @@ -39,7 +39,7 @@ void ColourTesterImageCtrl::SetImageFile(const wxFileName& fn) ilOriginFunc(IL_ORIGIN_UPPER_LEFT); ilEnable(IL_ORIGIN_SET); - if (! ilLoadImage((TCHAR*)fn.GetFullPath().c_str())) + if (! ilLoadImage((wchar_t*)fn.GetFullPath().c_str())) { m_Valid = false; Refresh(); @@ -83,7 +83,7 @@ wxString ColourTesterImageCtrl::GetImageFiletype() case IL_DXT4: fmt = _T("DXT4"); break; case IL_DXT5: fmt = _T("DXT5"); break; } - return wxString::Format(_T("%s - %dx%d"), fmt, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT)); + return wxString::Format(_T("%s - %dx%d"), fmt.c_str(), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT)); } void ColourTesterImageCtrl::SetColour(const wxColour& colour) diff --git a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp index fdc53ac4dd..96cc171fc7 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp @@ -74,13 +74,13 @@ void ToolButtonBar::AddToolButton(const wxString& shortLabel, const wxString& lo wxFileInputStream fstr (iconPath.GetFullPath()); if (! fstr.Ok()) { - wxLogError(_("Failed to open toolbar icon file '%s'"), iconPath.GetFullPath()); + wxLogError(_("Failed to open toolbar icon file '%s'"), iconPath.GetFullPath().c_str()); return; } wxImage img (fstr, wxBITMAP_TYPE_PNG); if (! img.Ok()) { - wxLogError(_("Failed to load toolbar icon image '%s'"), iconPath.GetFullPath()); + wxLogError(_("Failed to load toolbar icon image '%s'"), iconPath.GetFullPath().c_str()); return; } diff --git a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h index 6bed8cdb35..340fb9048b 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h +++ b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h @@ -1,5 +1,7 @@ //#include "wx/tglbtn.h" +#include + class ITool; class SectionLayout; diff --git a/source/tools/atlas/AtlasUI/CustomControls/Canvas/Canvas.cpp b/source/tools/atlas/AtlasUI/CustomControls/Canvas/Canvas.cpp index 5dd70f63d0..fe0630576e 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Canvas/Canvas.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/Canvas/Canvas.cpp @@ -3,7 +3,7 @@ #include "Canvas.h" #include "GameInterface/Messages.h" -#include "ScenarioEditor/tools/Common/Tools.h" +#include "ScenarioEditor/Tools/Common/Tools.h" Canvas::Canvas(wxWindow* parent, int* attribList, long style) : wxGLCanvas(parent, -1, wxDefaultPosition, wxDefaultSize, style, _T("GLCanvas"), attribList), diff --git a/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.cpp b/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.cpp index 93181d35b5..a47d6f3585 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.cpp @@ -1,5 +1,8 @@ #include "stdafx.h" +#include "wx/regex.h" +#include "wx/config.h" + #include "ColourDialog.h" ColourDialog::ColourDialog(wxWindow* parent, const wxString& customColourConfigPath, const wxColour& defaultColour) @@ -17,7 +20,7 @@ ColourDialog::ColourDialog(wxWindow* parent, const wxString& customColourConfigP for (int i = 0; i < 16; ++i) { wxString customColour; - if (cfg->Read(wxString::Format(_T("%s%d"), m_ConfigPath, i), &customColour) + if (cfg->Read(wxString::Format(_T("%s%d"), m_ConfigPath.c_str(), i), &customColour) && re.Matches(customColour)) { long r, g, b; @@ -42,7 +45,7 @@ int ColourDialog::ShowModal() { for (int i = 0; i < 16; ++i) { - wxString name = wxString::Format(_T("%s%d"), m_ConfigPath, i); + wxString name = wxString::Format(_T("%s%d"), m_ConfigPath.c_str(), i); wxColour colour = GetColourData().GetCustomColour(i); wxString customColour = wxString::Format(_T("%d %d %d"), colour.Red(), colour.Green(), colour.Blue()); @@ -52,4 +55,4 @@ int ColourDialog::ShowModal() } return ret; -} \ No newline at end of file +} diff --git a/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.h b/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.h index fc7947c099..ad98830d3b 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.h +++ b/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.h @@ -1,6 +1,8 @@ #ifndef COLOURDIALOG_H__ #define COLOURDIALOG_H__ +#include + class ColourDialog : public wxColourDialog { public: diff --git a/source/tools/atlas/AtlasUI/CustomControls/DraggableListCtrl/DraggableListCtrlCommands.h b/source/tools/atlas/AtlasUI/CustomControls/DraggableListCtrl/DraggableListCtrlCommands.h index 8e33ac9f62..d3e5bbc0a3 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/DraggableListCtrl/DraggableListCtrlCommands.h +++ b/source/tools/atlas/AtlasUI/CustomControls/DraggableListCtrl/DraggableListCtrlCommands.h @@ -2,6 +2,8 @@ #include "AtlasObject/AtlasObject.h" +#include + class DraggableListCtrl; class DragCommand : public AtlasWindowCommand diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrl.cpp b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrl.cpp index e147a9126f..c90a6b6298 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrl.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrl.cpp @@ -187,7 +187,7 @@ void EditableListCtrl::AddRow(AtObj& obj) void EditableListCtrl::AddRow(AtIter& iter) { - AtObj obj = iter; + AtObj obj = *iter; AddRow(obj); } @@ -221,7 +221,7 @@ wxString EditableListCtrl::GetCellString(long item, long column) const if (item >= (int)m_ListData.size()) return _T(""); - AtObj cell = m_ListData[item][m_ColumnTypes[column].key]; + AtObj cell = *m_ListData[item][m_ColumnTypes[column].key]; return AtlasObject::ConvertToString(cell).c_str(); } @@ -232,7 +232,7 @@ AtObj EditableListCtrl::GetCellObject(long item, long column) const if (item >= (int)m_ListData.size()) return AtObj(); - return m_ListData[item][m_ColumnTypes[column].key]; + return *m_ListData[item][m_ColumnTypes[column].key]; } void EditableListCtrl::SetCellString(long item, long column, wxString& str) @@ -280,7 +280,7 @@ void EditableListCtrl::ThawData(AtObj& in) { m_ListData.clear(); for (AtIter it = in["item"]; it.defined(); ++it) - m_ListData.push_back(it); + m_ListData.push_back(*it); UpdateDisplay(); } diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrlCommands.h b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrlCommands.h index e36324cc4b..a9d294a73e 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrlCommands.h +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/EditableListCtrlCommands.h @@ -2,6 +2,8 @@ #include "AtlasObject/AtlasObject.h" +#include + class EditableListCtrl; class EditCommand_Dialog : public AtlasWindowCommand diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp index 983ba6780d..86aafae88b 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp @@ -26,7 +26,8 @@ void FieldEditCtrl_Text::StartEdit(wxWindow* parent, wxRect rect, long row, int col) { - new QuickTextCtrl(parent, rect, ListCtrlValidator((EditableListCtrl*)parent, row, col)); + ListCtrlValidator validator((EditableListCtrl*)parent, row, col); + new QuickTextCtrl(parent, rect, validator); } ////////////////////////////////////////////////////////////////////////// @@ -74,9 +75,10 @@ void FieldEditCtrl_List::StartEdit(wxWindow* parent, wxRect rect, long row, int AtObj list (Datafile::ReadList(m_ListType)); for (AtIter it = list["item"]; it.defined(); ++it) - choices.Add(it); + choices.Add((wxString)it); - new QuickComboBox(parent, rect, choices, ListCtrlValidator((EditableListCtrl*)parent, row, col)); + ListCtrlValidator validator((EditableListCtrl*)parent, row, col); + new QuickComboBox(parent, rect, choices, validator); } ////////////////////////////////////////////////////////////////////////// @@ -127,5 +129,6 @@ FieldEditCtrl_File::FieldEditCtrl_File(const wxString& rootDir, const wxString& void FieldEditCtrl_File::StartEdit(wxWindow* parent, wxRect rect, long row, int col) { - new QuickFileCtrl(parent, rect, m_RootDir, m_FileMask, m_RememberedDir, ListCtrlValidator((EditableListCtrl*)parent, row, col)); -} \ No newline at end of file + ListCtrlValidator validator((EditableListCtrl*)parent, row, col); + new QuickFileCtrl(parent, rect, m_RootDir, m_FileMask, m_RememberedDir, validator); +} diff --git a/source/tools/atlas/AtlasUI/CustomControls/HighResTimer/HighResTimer.cpp b/source/tools/atlas/AtlasUI/CustomControls/HighResTimer/HighResTimer.cpp index f68d2ccbe6..668d857f8b 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/HighResTimer/HighResTimer.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/HighResTimer/HighResTimer.cpp @@ -2,10 +2,15 @@ #include "HighResTimer.h" +#ifndef _WIN32 +#include +#endif + // TODO: Portability and general betterness. (But it's good enough for now.) HighResTimer::HighResTimer() { +#ifdef _WIN32 LARGE_INTEGER freq; BOOL ok = QueryPerformanceFrequency(&freq); if (! ok) @@ -16,10 +21,12 @@ HighResTimer::HighResTimer() { m_TickLength = freq.QuadPart; } +#endif } double HighResTimer::GetTime() { +#ifdef _WIN32 LARGE_INTEGER count; BOOL ok = QueryPerformanceCounter(&count); if (! ok) @@ -28,4 +35,9 @@ double HighResTimer::GetTime() return 0.0; } return (double)count.QuadPart / (double)m_TickLength.GetValue(); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec+(tv.tv_usec/1000000.0); +#endif } diff --git a/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.cpp b/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.cpp index ec1fe77450..70a769268d 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.cpp @@ -12,6 +12,10 @@ class SaveOnExitDialog : public wxDialog { +#ifndef _WIN32 + #define EndDialog EndModal +#endif + public: SaveOnExitDialog(wxWindow* parent, bool allowCancel) : wxDialog(parent, wxID_ANY, (wxString) _("Save changes?")) diff --git a/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.h b/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.h index cca4f36469..a5d057df80 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.h +++ b/source/tools/atlas/AtlasUI/CustomControls/Windows/AtlasWindow.h @@ -8,6 +8,8 @@ #include "wx/filename.h" +#include + class AtObj; class AtlasWindow : public wxFrame, public IAtlasSerialiser diff --git a/source/tools/atlas/AtlasUI/General/Datafile.cpp b/source/tools/atlas/AtlasUI/General/Datafile.cpp index 46d8eea396..0057c1a15e 100644 --- a/source/tools/atlas/AtlasUI/General/Datafile.cpp +++ b/source/tools/atlas/AtlasUI/General/Datafile.cpp @@ -23,7 +23,7 @@ AtObj Datafile::ReadList(const char* section) AtObj lists (AtlasObject::LoadFromXML(filename.GetFullPath())); - return lists["lists"][section]; + return *lists["lists"][section]; } void Datafile::SetSystemDirectory(const wxString& dir) diff --git a/source/tools/atlas/AtlasUI/General/Datafile.h b/source/tools/atlas/AtlasUI/General/Datafile.h index 03366bdf96..765759394f 100644 --- a/source/tools/atlas/AtlasUI/General/Datafile.h +++ b/source/tools/atlas/AtlasUI/General/Datafile.h @@ -16,4 +16,4 @@ namespace Datafile // Returns a list of files matching the given wildcard (* and ?) filter // inside .../binaries/data/, not recursively. wxArrayString EnumerateDataFiles(const wxString& dir, const wxString& filter); -}; \ No newline at end of file +}; diff --git a/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp b/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp index ac9eecef67..cecd5a4d19 100644 --- a/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp +++ b/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp @@ -41,9 +41,9 @@ namespace AtlasMessage // Global variables, to remember state between DllMain and StartWindow and OnInit wxString g_InitialWindowType; -HINSTANCE g_Module; bool g_IsLoaded = false; - +#ifdef _WIN32 +HINSTANCE g_Module; BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved)) { @@ -64,6 +64,7 @@ BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpRese return TRUE; } +#endif using namespace AtlasMessage; @@ -77,7 +78,13 @@ ATLASDLLIMPEXP void Atlas_SetMessagePasser(MessagePasser* passer) ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type) { g_InitialWindowType = type; +#ifdef _WIN32 wxEntry(g_Module); +#else + int argc=1; + char *argv[]={"atlas", NULL}; + wxEntry(argc, argv); +#endif } ATLASDLLIMPEXP void Atlas_DisplayError(const wchar_t* text, unsigned int WXUNUSED(flags)) @@ -161,6 +168,7 @@ public: bool OpenDirectory(const wxString& dir) { +#ifdef _WIN32 // Code largely copied from wxLaunchDefaultBrowser: // (TODO: portability) @@ -193,6 +201,11 @@ public: ::FreeLibrary(hShellDll); return true; +#else + // Figure out what goes for "default browser" on unix/linux/whatever + // open an xterm perhaps? :) + return false; +#endif } virtual void OnFatalException() diff --git a/source/tools/atlas/AtlasUI/Misc/stdafx.h b/source/tools/atlas/AtlasUI/Misc/stdafx.h index 1c7e789655..58a94a7cec 100644 --- a/source/tools/atlas/AtlasUI/Misc/stdafx.h +++ b/source/tools/atlas/AtlasUI/Misc/stdafx.h @@ -62,8 +62,13 @@ #ifndef HAVE_PCH // If no PCH, just include a load of common headers anyway +# include "wx/defs.h" +# include "wx/string.h" # include "wx/wx.h" #endif - +#ifdef _WIN32 #define ATLASDLLIMPEXP extern "C" __declspec(dllexport) +#else +#define ATLASDLLIMPEXP extern "C" +#endif diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp index f4c59f3034..3d762f05ae 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp @@ -7,6 +7,7 @@ #include "wx/image.h" #include "wx/busyinfo.h" #include "wx/mediactrl.h" +#include "wx/filename.h" #include "General/AtlasEventLoop.h" #include "General/Datafile.h" @@ -18,7 +19,7 @@ #include "GameInterface/MessagePasser.h" #include "GameInterface/Messages.h" -#include "tools/Common/Tools.h" +#include "Tools/Common/Tools.h" static HighResTimer g_Timer; @@ -235,7 +236,7 @@ private: DECLARE_EVENT_TABLE(); }; BEGIN_EVENT_TABLE(MediaPlayer, wxFrame) - EVT_MEDIA_LOADED(wxID_ANY, OnLoad) + EVT_MEDIA_LOADED(wxID_ANY, MediaPlayer::OnLoad) END_EVENT_TABLE() ////////////////////////////////////////////////////////////////////////// @@ -379,10 +380,13 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent) }; Canvas* canvas = new GameCanvas(m_SectionLayout.GetCanvasParent(), glAttribList); m_SectionLayout.SetCanvas(canvas); + +#ifdef _WIN32 // The canvas' context gets made current on creation; but it can only be // current for one thread at a time, and it needs to be current for the // thread that is doing the draw calls, so disable it for this one. wglMakeCurrent(NULL, NULL); +#endif // Set up sidebars: @@ -390,7 +394,13 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent) // Send setup messages to game engine: - POST_MESSAGE(SetContext, (canvas->GetContext())); + /*canvas->Reparent(parent); + //canvas->SetCurrent(); + canvas->Show(TRUE);*/ + + printf("posting setcontext with canvas %p\n", canvas->GetContext()); + if (canvas->GetContext() != 0) + POST_MESSAGE(SetContext, (canvas->GetContext())); POST_MESSAGE(Init, (true)); @@ -558,7 +568,7 @@ void ScenarioEditor::OnSaveAs(wxCommandEvent& WXUNUSED(event)) void ScenarioEditor::SetOpenFilename(const wxString& filename) { SetTitle(wxString::Format(_("Atlas - Scenario Editor - %s"), - filename.IsEmpty() ? _("(untitled)") : filename)); + (filename.IsEmpty() ? wxString(_("(untitled)")) : filename).c_str())); m_OpenFilename = filename; } @@ -627,6 +637,7 @@ static void QueryCallback() // GUI in any other way) when it's running under Atlas, so we wouldn't need // to do any message processing here at all?) +#ifdef _WIN32 AtlasEventLoop* evtLoop = (AtlasEventLoop*)wxEventLoop::GetActive(); // evtLoop might be NULL, particularly if we're still initialising windows @@ -678,6 +689,7 @@ static void QueryCallback() evtLoop->AddMessage(pMsg); } } +#endif } */ void QueryMessage::Post() diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp index bc8f57c8d9..eae5b6accc 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp @@ -1,5 +1,8 @@ #include "stdafx.h" +#include "wx/filename.h" +#include "wx/wfstream.h" + #include "SectionLayout.h" #include "SnapSplitterWindow/SnapSplitterWindow.h" @@ -85,14 +88,14 @@ public: wxFileInputStream fstr (iconPath.GetFullPath()); if (! fstr.Ok()) { - wxLogError(_("Failed to open toolbar icon file '%s'"), iconPath.GetFullPath()); + wxLogError(_("Failed to open toolbar icon file '%s'"), iconPath.GetFullPath().c_str()); } else { img = wxImage(fstr, wxBITMAP_TYPE_PNG); if (! img.Ok()) { - wxLogError(_("Failed to load toolbar icon image '%s'"), iconPath.GetFullPath()); + wxLogError(_("Failed to load toolbar icon image '%s'"), iconPath.GetFullPath().c_str()); img = wxImage (1, 1, true); } } @@ -261,7 +264,7 @@ void SectionLayout::Build() if (sidebar->GetBottomBar()) \ sidebar->GetBottomBar()->Show(false); \ m_SidebarBook->AddPage(sidebar, icon, tooltip); \ - m_PageMappings.insert(std::make_pair(L#classname, (int)m_SidebarBook->GetPageCount()-1)); + m_PageMappings.insert(std::make_pair(L###classname, (int)m_SidebarBook->GetPageCount()-1)); ADD_SIDEBAR(MapSidebar, _T("map.png"), _("Map")); ADD_SIDEBAR(TerrainSidebar, _T("terrain.png"), _("Terrain")); diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.h b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.h index e8744dab90..eb9b77561f 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.h +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.h @@ -1,8 +1,12 @@ #ifndef SECTIONLAYOUT_H__ #define SECTIONLAYOUT_H__ +#include +#include + class SnapSplitterWindow; class SidebarBook; +class wxWindow; class SectionLayout { diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Cinematic/Cinematic.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Cinematic/Cinematic.cpp index 59b3578f17..f61365cced 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Cinematic/Cinematic.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Cinematic/Cinematic.cpp @@ -5,9 +5,14 @@ #include "GameInterface/Messages.h" #include "CustomControls/Buttons/ActionButton.h" //#include "CustomControls/Buttons/FloatingSpinCtrl.h" -#include "General/DataFile.h" +#include "General/Datafile.h" #include "ScenarioEditor/Tools/Common/Tools.h" #include "HighResTimer/HighResTimer.h" + +#include "wx/spinctrl.h" +#include "wx/filename.h" +#include "wx/wfstream.h" + #include using namespace AtlasMessage; @@ -683,7 +688,7 @@ private: DECLARE_EVENT_TABLE(); }; BEGIN_EVENT_TABLE(TrackSlider, wxSlider) - EVT_SCROLL(OnScroll) + EVT_SCROLL(TrackSlider::OnScroll) END_EVENT_TABLE() class PathSlider : public wxSlider @@ -710,7 +715,7 @@ private: DECLARE_EVENT_TABLE(); }; BEGIN_EVENT_TABLE(PathSlider, wxSlider) - EVT_SCROLL(OnScroll) + EVT_SCROLL(PathSlider::OnScroll) END_EVENT_TABLE() class CinemaSliderBox : public wxPanel @@ -765,7 +770,7 @@ private: DECLARE_EVENT_TABLE(); }; BEGIN_EVENT_TABLE(CinemaSliderBox, wxPanel) - EVT_TIMER(wxID_ANY, OnTick) + EVT_TIMER(wxID_ANY, CinemaSliderBox::OnTick) END_EVENT_TABLE() void TrackSlider::OnScroll(wxScrollEvent& WXUNUSED(event)) @@ -1128,14 +1133,14 @@ wxImage CinematicSidebar::LoadIcon(const wxString& filename) wxFileInputStream fstr (iconPath.GetFullPath()); if (! fstr.Ok()) { - wxLogError(_("Failed to open cinematic icon file '%s'"), iconPath.GetFullPath()); + wxLogError(_("Failed to open cinematic icon file '%s'"), iconPath.GetFullPath().c_str()); } else { img = wxImage(fstr, wxBITMAP_TYPE_BMP); if (! img.Ok()) { - wxLogError(_("Failed to load cinematic icon image '%s'"), iconPath.GetFullPath()); + wxLogError(_("Failed to load cinematic icon image '%s'"), iconPath.GetFullPath().c_str()); img = wxImage (1, 1, true); } } @@ -1531,4 +1536,4 @@ float CinematicSidebar::UpdateSelectedPath() } } return m_TimeElapsed; -} \ No newline at end of file +} diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp index abd124b3f7..3056f6294f 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp @@ -54,7 +54,7 @@ private: }; BEGIN_EVENT_TABLE(VariableSliderBox, wxPanel) - EVT_SCROLL(OnScroll) + EVT_SCROLL(VariableSliderBox::OnScroll) END_EVENT_TABLE() ////////////////////////////////////////////////////////////////////////// @@ -109,7 +109,7 @@ private: }; BEGIN_EVENT_TABLE(VariableListBox, wxPanel) - EVT_COMBOBOX(wxID_ANY, OnSelect) + EVT_COMBOBOX(wxID_ANY, VariableListBox::OnSelect) END_EVENT_TABLE() ////////////////////////////////////////////////////////////////////////// @@ -173,7 +173,7 @@ private: }; BEGIN_EVENT_TABLE(VariableColourBox, wxPanel) - EVT_BUTTON(wxID_ANY, OnClick) + EVT_BUTTON(wxID_ANY, VariableColourBox::OnClick) END_EVENT_TABLE() ////////////////////////////////////////////////////////////////////////// diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/LightControl.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/LightControl.cpp index 6e44b730f7..24e3229766 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/LightControl.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/LightControl.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" +#include + #include "LightControl.h" using AtlasMessage::Shareable; @@ -53,7 +55,7 @@ public: float rdotl = rx*lx + ry*ly + rz*lz; int diffuse = (int)std::max(0.f, ndotl*128.f); - int specular = (int)std::min(255.f, 64.f*pow(std::max(0.f, rdotl), 16.f)); + int specular = (int)std::min(255., 64.f*pow(std::max(0.f, rdotl), 16.f)); imgData[0] = std::min(64+diffuse+specular, 255); imgData[1] = std::min(48+diffuse+specular, 255); @@ -70,7 +72,11 @@ public: } wxPaintDC dc(this); + #if OS_WIN dc.DrawBitmap(wxBitmap(img, dc), 0, 0); + #else + dc.DrawBitmap(wxBitmap(img), 0, 0); + #endif } void OnMouse(wxMouseEvent& event) diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp index e020363728..3f33430973 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp @@ -158,7 +158,7 @@ private: DECLARE_EVENT_TABLE(); }; BEGIN_EVENT_TABLE(PlayerComboBox, wxComboBox) - EVT_COMBOBOX(wxID_ANY, OnSelect) + EVT_COMBOBOX(wxID_ANY, PlayerComboBox::OnSelect) END_EVENT_TABLE(); ////////////////////////////////////////////////////////////////////////// diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.h b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.h index 2dc8e5f8f2..88aba42a36 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.h +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.h @@ -5,6 +5,8 @@ class BrushShapeCtrl; class BrushSizeCtrl; class BrushStrengthCtrl; +#include + class Brush { friend class BrushShapeCtrl; diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.h b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.h index 3a7c12aef9..dbc2bcc838 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.h +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.h @@ -1,6 +1,7 @@ #ifndef ObjectSettings_H__ #define ObjectSettings_H__ +#include #include #include "ScenarioEditor/Tools/Common/MiscState.h" diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h index 821fa10276..57bfede516 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h @@ -2,7 +2,7 @@ #define TOOLS_H__ #include "ScenarioEditor/ScenarioEditor.h" -#include "general/AtlasWindowCommand.h" +#include "General/AtlasWindowCommand.h" class wxMouseEvent; class wxKeyEvent; diff --git a/source/tools/atlas/DatafileIO/BAR/BAR.cpp b/source/tools/atlas/DatafileIO/BAR/BAR.cpp index 1ac38ae42a..6b2f38ffec 100644 --- a/source/tools/atlas/DatafileIO/BAR/BAR.cpp +++ b/source/tools/atlas/DatafileIO/BAR/BAR.cpp @@ -48,7 +48,7 @@ bool BARReader::Initialise() m_Stream.Seek(filetableOffset, Stream::FROM_START); - std::wstring rootName = ReadUString(m_Stream); + utf16string rootName = ReadUString(m_Stream); uint32_t numRootFiles; m_Stream.Read(&numRootFiles, 4); CHECK(numRootFiles == numFiles); diff --git a/source/tools/atlas/DatafileIO/BAR/BAR.h b/source/tools/atlas/DatafileIO/BAR/BAR.h index c789e3a45c..3b50a7be6d 100644 --- a/source/tools/atlas/DatafileIO/BAR/BAR.h +++ b/source/tools/atlas/DatafileIO/BAR/BAR.h @@ -1,6 +1,8 @@ #include #include +#include "../Util.h" + namespace DatafileIO { class SeekableInputStream; @@ -8,7 +10,7 @@ namespace DatafileIO struct BAREntry { - std::wstring filename; // includes root name - e.g. "Data\tactics\warwagon.tactics.xmb" + utf16string filename; // includes root name - e.g. "Data\tactics\warwagon.tactics.xmb" size_t filesize; // in bytes struct { unsigned short year, month, day, dayofweek; // 2005 etc, 1..12, 1..31, 0..6 (from Sunday) diff --git a/source/tools/atlas/DatafileIO/DDT/DDT.cpp b/source/tools/atlas/DatafileIO/DDT/DDT.cpp index 7823132973..9b009f8fb9 100644 --- a/source/tools/atlas/DatafileIO/DDT/DDT.cpp +++ b/source/tools/atlas/DatafileIO/DDT/DDT.cpp @@ -34,10 +34,12 @@ struct DDTImage size_t length; }; +#ifdef USE_DEVIL_DXT static void LoadDXT(int dxtType, unsigned char* oldData); static void SaveDXT(int dxtType); // saves the currently bound image -static void ToggleOrigin(); // urgh static void SwizzleAGBR(); +#endif +static void ToggleOrigin(); // urgh bool DDTFile::Read(FileType type) { @@ -110,6 +112,7 @@ bool DDTFile::Read(FileType type) } break; +#ifdef USE_DEVIL_DXT case DXT1: case DXT3: case NORMSPEC: @@ -124,6 +127,7 @@ bool DDTFile::Read(FileType type) delete[] oldData; } break; +#endif case GREY: { @@ -349,6 +353,7 @@ bool DDTFile::SaveFile(OutputStream& stream, FileType outputType) delete[] newData; break; } +#ifdef USE_DEVIL_DXT case DXT1: SaveDXT(1); break; @@ -359,6 +364,7 @@ bool DDTFile::SaveFile(OutputStream& stream, FileType outputType) SwizzleAGBR(); SaveDXT(5); break; +#endif } ilDeleteImages(1, &img); @@ -372,18 +378,6 @@ bool DDTFile::SaveFile(OutputStream& stream, FileType outputType) -static void SwizzleAGBR() -{ - ILubyte* data = ilGetData(); - ILint pixels = ilGetInteger(IL_IMAGE_WIDTH)*ilGetInteger(IL_IMAGE_HEIGHT); - for (ILint i = 0; i < pixels; ++i) - { - ILubyte t = data[i*4+0]; - data[i*4+0] = data[i*4+3]; - data[i*4+3] = t; - } -} - // Evilness: #include "IL/devil_internal_exports.h" extern "C" @@ -392,10 +386,20 @@ extern "C" extern ILboolean DecompressDXT3(); extern ILboolean DecompressDXT5(); extern ILuint Compress(ILimage* Image, ILenum DXTCFormat); + extern ILimage* iCurImage; +} + +static void ToggleOrigin() +{ + iCurImage->Origin = (iCurImage->Origin == IL_ORIGIN_UPPER_LEFT ? IL_ORIGIN_LOWER_LEFT : IL_ORIGIN_UPPER_LEFT); +} + +#ifdef USE_DEVIL_DXT +extern "C" +{ extern ILubyte* CompData; extern ILint Depth, Width, Height; extern ILimage* Image; - extern ILimage* iCurImage; } static void LoadDXT(int dxtType, unsigned char* oldData) @@ -419,12 +423,21 @@ static void LoadDXT(int dxtType, unsigned char* oldData) Image = NULL; } +static void SwizzleAGBR() +{ + ILubyte* data = ilGetData(); + ILint pixels = ilGetInteger(IL_IMAGE_WIDTH)*ilGetInteger(IL_IMAGE_HEIGHT); + for (ILint i = 0; i < pixels; ++i) + { + ILubyte t = data[i*4+0]; + data[i*4+0] = data[i*4+3]; + data[i*4+3] = t; + } +} + static void SaveDXT(int dxtType) { Compress(ilGetCurImage(), dxtType==1 ? IL_DXT1 : dxtType==3 ? IL_DXT3 : IL_DXT5); } -static void ToggleOrigin() -{ - iCurImage->Origin = (iCurImage->Origin == IL_ORIGIN_UPPER_LEFT ? IL_ORIGIN_LOWER_LEFT : IL_ORIGIN_UPPER_LEFT); -} +#endif diff --git a/source/tools/atlas/DatafileIO/Util.cpp b/source/tools/atlas/DatafileIO/Util.cpp index 27034042dc..8eebe660c6 100644 --- a/source/tools/atlas/DatafileIO/Util.cpp +++ b/source/tools/atlas/DatafileIO/Util.cpp @@ -23,3 +23,18 @@ void DatafileIO::WriteUString(OutputStream& stream, const utf16string& string) stream.Write(&length, 4); stream.Write((utf16_t*)&string[0], length*2); } + +#if !OS_WIN +// TODO In reality, these two should be able to de/encode UTF-16 to/from UCS-4 +// instead of just treating UTF-16 as UCS-2 + +std::wstring DatafileIO::utf16tow(const utf16string &str) +{ + return std::wstring(str.begin(), str.end()); +} + +utf16string DatafileIO::wtoutf16(const std::wstring &str) +{ + return utf16string(str.begin(), str.end()); +} +#endif diff --git a/source/tools/atlas/DatafileIO/Util.h b/source/tools/atlas/DatafileIO/Util.h index 1017c33c3f..f1e9452fa4 100644 --- a/source/tools/atlas/DatafileIO/Util.h +++ b/source/tools/atlas/DatafileIO/Util.h @@ -1,5 +1,9 @@ #include #include +#if OS_UNIX +#include "ps/utf16string.h" +#include +#endif #ifndef C_ASSERT #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1] @@ -7,12 +11,17 @@ namespace DatafileIO { +#if OS_WIN // TODO: proper portability typedef int int32_t; typedef unsigned int uint32_t; typedef unsigned short uint16_t; typedef std::wstring utf16string; typedef wchar_t utf16_t; +#else + typedef uint16_t utf16_t; + typedef std::basic_string utf16string; +#endif C_ASSERT(sizeof(int32_t) == 4); C_ASSERT(sizeof(uint32_t) == 4); @@ -25,4 +34,12 @@ namespace DatafileIO // Read/write 4-byte length + UCS-2 string utf16string ReadUString(InputStream& stream); void WriteUString(OutputStream& stream, const utf16string& string); + +#if OS_WIN +# define utf16tow(_str) _str +# define wtoutf16(_str) _str +#else + std::wstring utf16tow(const utf16string &str); + utf16string wtoutf16(const std::wstring &str); +#endif } diff --git a/source/tools/atlas/DatafileIO/XMB/XMB.cpp b/source/tools/atlas/DatafileIO/XMB/XMB.cpp index 0a231ce4f4..00c1aa8142 100644 --- a/source/tools/atlas/DatafileIO/XMB/XMB.cpp +++ b/source/tools/atlas/DatafileIO/XMB/XMB.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -330,11 +331,11 @@ void OutputNode(std::wstring& output, const XMLElement* node, const std::wstring output += L"\n"; output += indent; output += L"<"; - output += node->name; // TODO: utf16->w + output += utf16tow(node->name); for (size_t i = 0; i < node->attrs.size(); ++i) { - std::wstring value = node->attrs[i].value; + std::wstring value = utf16tow(node->attrs[i].value); // Escape funny characters if (value.find_first_of(L"&<>\"") != value.npos) { @@ -345,7 +346,7 @@ void OutputNode(std::wstring& output, const XMLElement* node, const std::wstring } output += L" "; - output += node->attrs[i].name; + output += utf16tow(node->attrs[i].name); output += L"=\""; output += value; output += L"\""; @@ -353,9 +354,10 @@ void OutputNode(std::wstring& output, const XMLElement* node, const std::wstring // Output the element's contents, in an attemptedly nice readable format: + std::wstring name = utf16tow(node->name); if (node->text.length()) { - std::wstring text = node->text; + std::wstring text = utf16tow(node->text); // Wrap text in CDATA when necessary. (Maybe we should use < etc // in some cases?) @@ -392,7 +394,7 @@ void OutputNode(std::wstring& output, const XMLElement* node, const std::wstring output += L"\n"; output += indent; output += L"name; + output += name; output += L">"; } else @@ -401,7 +403,7 @@ void OutputNode(std::wstring& output, const XMLElement* node, const std::wstring output += L">"; output += text; output += L"name; + output += name; output += L">"; } } @@ -419,7 +421,7 @@ void OutputNode(std::wstring& output, const XMLElement* node, const std::wstring output += L"\n"; output += indent; output += L"name; + output += name; output += L">"; } else @@ -482,11 +484,13 @@ public: utf16string getErrorText() { return errorText; } private: bool sawErrors; - std::wstring errorText; + utf16string errorText; void complain(const SAXParseException& err, const wchar_t* severity) { sawErrors = true; - C_ASSERT(sizeof(wchar_t) == sizeof(XMLCh)); - errorText += (std::wstring)L"XML "+severity+L": "+ (wchar_t*)err.getSystemId() + L" / " + (wchar_t*)err.getMessage(); + C_ASSERT(sizeof(utf16_t) == sizeof(XMLCh)); + errorText += wtoutf16(L"XML ")+wtoutf16(severity) + +wtoutf16(L": ")+ (utf16_t*)err.getSystemId() + +wtoutf16(L" / ") + (utf16_t*)err.getMessage(); } }; @@ -539,7 +543,8 @@ XMBFile* DatafileIO::XMLReader::LoadFromXML(InputStream& stream) // Build the XMLElement tree inside the XeroHandler - Parser->parse(XeroInputSource(stream)); + XeroInputSource src(stream); + Parser->parse(src); delete Parser; diff --git a/source/tools/atlas/GameInterface/CommandProc.cpp b/source/tools/atlas/GameInterface/CommandProc.cpp index 6444da5290..248e48d3dc 100644 --- a/source/tools/atlas/GameInterface/CommandProc.cpp +++ b/source/tools/atlas/GameInterface/CommandProc.cpp @@ -2,6 +2,7 @@ #include "CommandProc.h" +#include #include #include diff --git a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp index 69684845bc..edb13c8e0b 100644 --- a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp @@ -112,6 +112,7 @@ MESSAGEHANDLER(SetActorViewer) MESSAGEHANDLER(SetContext) { g_GameLoop->glContext = msg->context; + printf("Setting gl context to %p\n", g_GameLoop->glContext); Atlas_GLSetCurrent((void*)g_GameLoop->glContext); } diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index 9c1f7e6e76..87c8dc6b95 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -5,6 +5,9 @@ #include "MessagesSetup.h" #endif +#include +#include + // TODO: organisation, documentation, etc ////////////////////////////////////////////////////////////////////////// @@ -15,7 +18,7 @@ MESSAGE(Init, MESSAGE(Shutdown, ); -struct eRenderView { enum { NONE, GAME, ACTOR }; }; +struct eRenderView { enum renderViews { NONE, GAME, ACTOR }; }; MESSAGE(RenderEnable, ((int, view)) // eRenderView diff --git a/source/tools/atlas/GameInterface/Register.cpp b/source/tools/atlas/GameInterface/Register.cpp index 5f8c017803..331fc66039 100644 --- a/source/tools/atlas/GameInterface/Register.cpp +++ b/source/tools/atlas/GameInterface/Register.cpp @@ -12,6 +12,9 @@ #include "SharedTypes.h" #include "Shareable.h" +#include +#include + namespace AtlasMessage { diff --git a/source/tools/atlas/GameInterface/Shareable.h b/source/tools/atlas/GameInterface/Shareable.h index caa6967747..bb6401456e 100644 --- a/source/tools/atlas/GameInterface/Shareable.h +++ b/source/tools/atlas/GameInterface/Shareable.h @@ -42,6 +42,8 @@ after their definition. #include "SharedMemory.h" +#include + // We want to use placement new, which breaks when compiling Debug configurations // in the game and in wx, and they both need different workarounds. // (Duplicated in SharedMemory.h)