diff --git a/source/collada/CommonConvert.cpp b/source/collada/CommonConvert.cpp index 60a50cb187..67ee4ee76f 100644 --- a/source/collada/CommonConvert.cpp +++ b/source/collada/CommonConvert.cpp @@ -167,11 +167,11 @@ CommonConvert::CommonConvert(const char* text, std::string& xmlErrors) ////////////////////////////////////////////////////////////////////////// -// HACK: These don't get exported properly from FCollada (3.02, DLL), so define +// HACK: The originals don't get exported properly from FCollada (3.02, DLL), so define // them here instead of fixing it correctly. -const FMVector3 FMVector3::XAxis(1.0f, 0.0f, 0.0f); +const FMVector3 FMVector3_XAxis(1.0f, 0.0f, 0.0f); static float identity[] = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 }; -FMMatrix44 FMMatrix44::Identity(identity); +FMMatrix44 FMMatrix44_Identity(identity); struct FoundInstance { @@ -265,7 +265,7 @@ bool FindSingleInstance(FCDSceneNode* node, FCDEntityInstance*& instance, FMMatr { std::vector instances; - FindInstances(node, instances, FMMatrix44::Identity, true); + FindInstances(node, instances, FMMatrix44_Identity, true); if (instances.size() > 1) { Log(LOG_ERROR, "Found too many export-marked objects"); @@ -273,7 +273,7 @@ bool FindSingleInstance(FCDSceneNode* node, FCDEntityInstance*& instance, FMMatr } if (instances.empty()) { - FindInstances(node, instances, FMMatrix44::Identity, false); + FindInstances(node, instances, FMMatrix44_Identity, false); if (instances.size() > 1) { Log(LOG_ERROR, "Found too many possible objects to convert - try adding the 'export' property to disambiguate one"); diff --git a/source/collada/CommonConvert.h b/source/collada/CommonConvert.h index 76ce22f5be..19103cf676 100644 --- a/source/collada/CommonConvert.h +++ b/source/collada/CommonConvert.h @@ -155,4 +155,6 @@ struct BoneTransform */ void TransformBones(std::vector& bones, const FMMatrix44& scaleTransform, bool yUp); +extern FMMatrix44 FMMatrix44_Identity; + #endif // COMMONCONVERT_H__ diff --git a/source/collada/PMDConvert.cpp b/source/collada/PMDConvert.cpp index 99a5b94f1b..5d2d1077b2 100644 --- a/source/collada/PMDConvert.cpp +++ b/source/collada/PMDConvert.cpp @@ -446,7 +446,7 @@ public: } else { - scaleMatrix = FMMatrix44::Identity; + scaleMatrix = FMMatrix44_Identity; scaledTransform = bindTransform; } diff --git a/source/collada/PSAConvert.cpp b/source/collada/PSAConvert.cpp index db1ee1a320..1123fa0efd 100644 --- a/source/collada/PSAConvert.cpp +++ b/source/collada/PSAConvert.cpp @@ -167,7 +167,7 @@ public: } else { - TransformBones(bones, FMMatrix44::Identity, yUp); + TransformBones(bones, FMMatrix44_Identity, yUp); } } diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index fc7a4f467b..f9346df208 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -611,7 +611,7 @@ static void InitPs(bool setup_gui) if (setup_gui) { // The things here aren't strictly GUI, but they're unnecessary when in Atlas - // because the game doesn't draw any text or handle keys of anything + // because the game doesn't draw any text or handle keys or anything { // console diff --git a/source/tools/atlas/AtlasObject/AtlasObjectXML.cpp b/source/tools/atlas/AtlasObject/AtlasObjectXML.cpp index 12e0f64d46..7e3a0d5dfe 100644 --- a/source/tools/atlas/AtlasObject/AtlasObjectXML.cpp +++ b/source/tools/atlas/AtlasObject/AtlasObjectXML.cpp @@ -63,6 +63,37 @@ private: } }; +template +class StrConv +{ +public: + template StrConv(const S* str) { init(str); } + template StrConv(const std::basic_string& str) { init(str.c_str()); } + + ~StrConv() + { + delete[] data; + } + const T* c_str() + { + return data; + } + +private: + template + void init(S* str) + { + size_t len = 0; + while (str[len] != '\0') + ++len; + data = new T[len+1]; + for (size_t i = 0; i < len+1; ++i) + data[i] = (T)str[i]; + } + + T* data; +}; + // TODO: replace most of the asserts below (e.g. for when it fails to load // a file) with some proper logging/reporting system @@ -70,10 +101,6 @@ static AtSmartPtr ConvertNode(DOMElement* element); AtObj AtlasObject::LoadFromXML(const wchar_t* filename) { - // TODO: Convert wchar_t* to XMLCh* when running under GCC - assert(sizeof(wchar_t) == sizeof(XMLCh)); - - XercesInitialiser::enable(); XercesDOMParser* parser = new XercesDOMParser(); @@ -84,7 +111,7 @@ AtObj AtlasObject::LoadFromXML(const wchar_t* filename) parser->setLoadExternalDTD(false); // because I really don't like bothering with them parser->setCreateEntityReferenceNodes(false); - parser->parse((XMLCh*)filename); + parser->parse(StrConv(filename).c_str()); if (parser->getErrorCount() != 0) { @@ -140,10 +167,7 @@ static AtSmartPtr ConvertNode(DOMElement* element) else if (type == DOMNode::TEXT_NODE) { // Text inside the element. Append it to the current node's string. - - // TODO: Make this work on GCC, where wchar_t != XMLCh - assert(sizeof(wchar_t) == sizeof(XMLCh)); - std::wstring value_wstr (reinterpret_cast(node->getNodeValue())); + std::wstring value_wstr (StrConv(node->getNodeValue()).c_str()); obj->value += value_wstr; } } @@ -157,15 +181,15 @@ static AtSmartPtr ConvertNode(DOMElement* element) { DOMAttr* attr = (DOMAttr*)node; - // Get name and value. (TODO: GCC) + // Get name and value char* name = XMLString::transcode(attr->getName()); - const wchar_t* value = reinterpret_cast(attr->getValue()); + StrConv value (attr->getValue()); // Prefix the name with an @, to differentiate it from an element std::string newName ("@"); newName += name; // Create new node - AtNode* newNode = new AtNode(value); + AtNode* newNode = new AtNode(value.c_str()); // Add to this node's list of children obj->children.insert(AtNode::child_pairtype(newName.c_str(), AtNode::Ptr(newNode))); @@ -208,8 +232,7 @@ static DOMAttr* BuildDOMAttr(DOMDocument* doc, const XMLCh* name, AtNode::Ptr p) DOMAttr* attr = doc->createAttribute(name); - // TODO: make work on GCC - attr->setValue(reinterpret_cast(p->value.c_str())); + attr->setValue(StrConv(p->value).c_str()); return attr; } @@ -221,9 +244,8 @@ static DOMNode* BuildDOMNode(DOMDocument* doc, const XMLCh* name, AtNode::Ptr p) if (p) { - // TODO: make this work on GCC if (p->value.length()) - node->setTextContent(reinterpret_cast(p->value.c_str())); + node->setTextContent(StrConv(p->value).c_str()); XMLCh tempStr[256]; // urgh, nasty fixed-size buffer for (AtNode::child_maptype::const_iterator it = p->children.begin(); it != p->children.end(); ++it) @@ -247,10 +269,6 @@ static DOMNode* BuildDOMNode(DOMDocument* doc, const XMLCh* name, AtNode::Ptr p) bool AtlasObject::SaveToXML(AtObj& obj, const wchar_t* filename) { - // TODO: Convert wchar_t* to XMLCh* when running under GCC - assert(sizeof(wchar_t) == sizeof(XMLCh)); - - XercesInitialiser::enable(); // Why does it take so much work just to create a standard DOMWriter? :-( @@ -282,7 +300,7 @@ bool AtlasObject::SaveToXML(AtObj& obj, const wchar_t* filename) std::auto_ptr doc (impl->createDocument()); doc->appendChild(BuildDOMNode(doc.get(), rootName, firstChild)); - LocalFileFormatTarget formatTarget ((XMLCh*)filename); + LocalFileFormatTarget formatTarget (StrConv(filename).c_str()); writer->writeNode(&formatTarget, *doc); } catch (const XMLException& e) { diff --git a/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp b/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp index c418c10a2e..63bebef61d 100644 --- a/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp +++ b/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp @@ -193,6 +193,10 @@ ActorViewer::ActorViewer(wxWindow* parent) #ifdef __WXMSW__ wglMakeCurrent(NULL, NULL); +#elif defined(__WXGTK__) + // Need to make sure the canvas is realized by GTK, so that its context is valid + Show(true); + wxSafeYield(); #endif POST_MESSAGE(SetCanvas, (static_cast(canvas))); @@ -318,6 +322,13 @@ ActorViewer::ActorViewer(wxWindow* parent) SetActorView(); POST_MESSAGE(RenderEnable, (eRenderView::ACTOR)); + +#ifdef __WXGTK__ + // HACK: because of how we fiddle with stuff earlier to make sure the canvas + // is displayed, the layout gets messed up, and it only seems to be fixable + // by changing the window's size + SetSize(GetSize() + wxSize(1, 0)); +#endif } void ActorViewer::OnClose(wxCloseEvent& WXUNUSED(event)) diff --git a/source/tools/atlas/AtlasUI/CustomControls/Canvas/Canvas.h b/source/tools/atlas/AtlasUI/CustomControls/Canvas/Canvas.h index e98aa36feb..ab214a4bf2 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Canvas/Canvas.h +++ b/source/tools/atlas/AtlasUI/CustomControls/Canvas/Canvas.h @@ -6,12 +6,11 @@ public: Canvas(wxWindow* parent, int* attribList, long style); void InitSize(); - protected: virtual void HandleMouseEvent(wxMouseEvent& evt) = 0; private: - void OnResize(wxSizeEvent&); + void OnResize(wxSizeEvent& evt); void OnMouseCapture(wxMouseCaptureChangedEvent& evt); void OnMouse(wxMouseEvent& evt); diff --git a/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp b/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp index b943dbfc05..6be1ee4425 100644 --- a/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp +++ b/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp @@ -19,6 +19,10 @@ #include "wx/debugrpt.h" #include "wx/file.h" +#ifdef __WXGTK__ +#include +#endif + // Shared memory allocation functions ATLASDLLIMPEXP void* ShareableMalloc(size_t n) { @@ -79,10 +83,19 @@ ATLASDLLIMPEXP void Atlas_SetMessagePasser(MessagePasser* passer) ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type) { g_InitialWindowType = type; - #ifdef __WXMSW__ wxEntry(g_Module); #else +# ifdef __WXGTK__ + // Because we do GL calls from a secondary thread, Xlib needs to + // be told to support multiple threads safely + int status = XInitThreads(); + if (status == 0) + { + fprintf(stderr, "Error enabling thread-safety via XInitThreads\n"); + } +# endif + int argc = 1; char *argv[] = {"atlas", NULL}; wxEntry(argc, argv); diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp index b23cefaab4..231e98f0ad 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp @@ -404,9 +404,6 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent) // Need to make sure the canvas is realized by GTK, so that its context is valid Show(true); wxSafeYield(); - - assert(canvas->GetContext() != NULL); - assert(glXGetCurrentContext() == NULL); #endif // Send setup messages to game engine: @@ -428,6 +425,13 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent) // else to do)) m_Timer.SetOwner(this); m_Timer.Start(20); + +#ifdef __WXGTK__ + // HACK: because of how we fiddle with stuff earlier to make sure the canvas + // is displayed, the layout gets messed up, and it only seems to be fixable + // by changing the window's size + SetSize(GetSize() + wxSize(1, 0)); +#endif } float ScenarioEditor::GetSpeedModifier()