1
0
forked from 0ad/0ad

# Fixed Atlas on Linux

Added call to XInitThreads, for required thread safety.
Fixed conversions between wchar_t and XMLCh strings. (Not tested much
yet.)
Fixed COLLADA too.

This was SVN commit r4964.
This commit is contained in:
Ykkrosh 2007-03-20 01:06:34 +00:00
parent b2978c42f6
commit 38a5e807ff
10 changed files with 82 additions and 35 deletions

View File

@ -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<FoundInstance> 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");

View File

@ -155,4 +155,6 @@ struct BoneTransform
*/
void TransformBones(std::vector<BoneTransform>& bones, const FMMatrix44& scaleTransform, bool yUp);
extern FMMatrix44 FMMatrix44_Identity;
#endif // COMMONCONVERT_H__

View File

@ -446,7 +446,7 @@ public:
}
else
{
scaleMatrix = FMMatrix44::Identity;
scaleMatrix = FMMatrix44_Identity;
scaledTransform = bindTransform;
}

View File

@ -167,7 +167,7 @@ public:
}
else
{
TransformBones(bones, FMMatrix44::Identity, yUp);
TransformBones(bones, FMMatrix44_Identity, yUp);
}
}

View File

@ -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

View File

@ -63,6 +63,37 @@ private:
}
};
template <typename T>
class StrConv
{
public:
template <typename S> StrConv(const S* str) { init(str); }
template <typename S> StrConv(const std::basic_string<S>& str) { init(str.c_str()); }
~StrConv()
{
delete[] data;
}
const T* c_str()
{
return data;
}
private:
template <typename S>
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<AtNode> 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<XMLCh>(filename).c_str());
if (parser->getErrorCount() != 0)
{
@ -140,10 +167,7 @@ static AtSmartPtr<AtNode> 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<const wchar_t*>(node->getNodeValue()));
std::wstring value_wstr (StrConv<wchar_t>(node->getNodeValue()).c_str());
obj->value += value_wstr;
}
}
@ -157,15 +181,15 @@ static AtSmartPtr<AtNode> 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<const wchar_t*>(attr->getValue());
StrConv<wchar_t> 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<const XMLCh*>(p->value.c_str()));
attr->setValue(StrConv<XMLCh>(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<const XMLCh*>(p->value.c_str()));
node->setTextContent(StrConv<XMLCh>(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<DOMDocument> doc (impl->createDocument());
doc->appendChild(BuildDOMNode(doc.get(), rootName, firstChild));
LocalFileFormatTarget formatTarget ((XMLCh*)filename);
LocalFileFormatTarget formatTarget (StrConv<XMLCh>(filename).c_str());
writer->writeNode(&formatTarget, *doc);
}
catch (const XMLException& e) {

View File

@ -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<wxGLCanvas*>(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))

View File

@ -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);

View File

@ -19,6 +19,10 @@
#include "wx/debugrpt.h"
#include "wx/file.h"
#ifdef __WXGTK__
#include <X11/Xlib.h>
#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);

View File

@ -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()