Linux implementation. Include changes for gcc x64.

This commit is contained in:
LuisAntonRebollo 2015-01-24 22:08:26 +01:00
parent 4e52824a42
commit 4e9034854d
56 changed files with 1108 additions and 3075 deletions

View file

@ -82,6 +82,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "Opcode.h"
#include <stdint.h>
using namespace Opcode;
@ -208,7 +209,7 @@ bool HybridModel::Build(const OPCODECREATE& create)
Data->mLeaves[Data->mNbLeaves] = *current->GetAABB();
// Setup leaf data
udword Index = (udword(current->GetPrimitives()) - udword(Data->mBase))/sizeof(udword);
udword Index = (uintptr_t(current->GetPrimitives()) - uintptr_t(Data->mBase))/sizeof(uintptr_t);
Data->mTriangles[Data->mNbLeaves].SetData(current->GetNbPrimitives(), Index);
Data->mNbLeaves++;

View file

@ -17,6 +17,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "Opcode.h"
#include <stdint.h>
using namespace Opcode;
@ -163,7 +164,7 @@ bool SAP_PairData::Init(udword nb_objects)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inline_ void Remap(SAP_Element*& element, udword delta)
{
if(element) element = (SAP_Element*)(udword(element) + delta);
if(element) element = (SAP_Element*)(element + delta);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -199,7 +200,7 @@ SAP_Element* SAP_PairData::GetFreeElem(udword id, SAP_Element* next, udword* rem
// Remap everything
{
udword Delta = udword(NewElems) - udword(mElementPool);
udword Delta = uintptr_t(NewElems) - uintptr_t(mElementPool);
for(udword i=0;i<mNbUsedElements;i++) Remap(NewElems[i].mNext, Delta);
for(udword i=0;i<mNbObjects;i++) Remap(mArray[i], Delta);

View file

@ -193,7 +193,7 @@ void CameraSpline::renderTimeMap()
void *ptr = vb.lock();
if(!ptr) return;
MRandomLCG random(1376312589 * (U32)this);
MRandomLCG random(1376312589 * (uintptr_t)this);
S32 index = 0;
for(Vector<TimeMap>::iterator itr=mTimeMap.begin(); itr != mTimeMap.end(); itr++)
{

View file

@ -573,7 +573,7 @@ void ConvexShape::prepRenderImage( SceneRenderState *state )
// We sort by the material then vertex buffer.
ri->defaultKey = matInst->getStateHint();
ri->defaultKey2 = (U32)ri->vertBuff; // Not 64bit safe!
ri->defaultKey2 = (uintptr_t)ri->vertBuff; // Not 64bit safe!
// Submit our RenderInst to the RenderPassManager
state->getRenderPass()->addInst( ri );

View file

@ -312,7 +312,7 @@ void DebrisData::packData(BitStream* stream)
if( stream->writeFlag( explosion ) )
{
stream->writeRangedU32(packed? SimObjectId(explosion):
stream->writeRangedU32(packed? SimObjectId((uintptr_t)explosion):
explosion->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
}

View file

@ -343,7 +343,7 @@ void RenderMeshExample::prepRenderImage( SceneRenderState *state )
// We sort by the material then vertex buffer
ri->defaultKey = matInst->getStateHint();
ri->defaultKey2 = (U32)ri->vertBuff; // Not 64bit safe!
ri->defaultKey2 = (uintptr_t)ri->vertBuff; // Not 64bit safe!
// Submit our RenderInst to the RenderPassManager
state->getRenderPass()->addInst( ri );

View file

@ -926,7 +926,7 @@ void ParticleEmitter::prepRenderImage(SceneRenderState* state)
ri->softnessDistance = mDataBlock->softnessDistance;
// Sort by texture too.
ri->defaultKey = ri->diffuseTex ? (U32)ri->diffuseTex : (U32)ri->vertBuff;
ri->defaultKey = ri->diffuseTex ? (uintptr_t)ri->diffuseTex : (uintptr_t)ri->vertBuff;
renderManager->addInst( ri );

View file

@ -527,7 +527,7 @@ void Ribbon::prepRenderImage(SceneRenderState *state)
} else {
ri->defaultKey = 1;
}
ri->defaultKey2 = (U32)ri->vertBuff; // Not 64bit safe!
ri->defaultKey2 = (uintptr_t)ri->vertBuff; // Not 64bit safe!
state->getRenderPass()->addInst(ri);
}

View file

@ -608,7 +608,7 @@ void LightFlareData::prepRender( SceneRenderState *state, LightFlareState *flare
ri->blendStyle = ParticleRenderInst::BlendGreyscale;
ri->diffuseTex = mFlareTexture;
ri->softnessDistance = 1.0f;
ri->defaultKey = ri->diffuseTex ? (U32)ri->diffuseTex : (U32)ri->vertBuff; // Sort by texture too.
ri->defaultKey = ri->diffuseTex ? (uintptr_t)ri->diffuseTex : (uintptr_t)ri->vertBuff; // Sort by texture too.
// NOTE: Offscreen partical code is currently disabled.
ri->systemState = PSS_AwaitingHighResDraw;

View file

@ -707,7 +707,7 @@ void ShapeBaseData::packData(BitStream* stream)
if( stream->writeFlag( debris != NULL ) )
{
stream->writeRangedU32(packed? SimObjectId(debris):
stream->writeRangedU32(packed? SimObjectId((uintptr_t)debris):
debris->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
}
@ -2090,7 +2090,7 @@ void ShapeBase::updateAudioState(Sound& st)
{
if ( isGhost() )
{
if ( Sim::findObject( SimObjectId( st.profile ), st.profile ) )
if ( Sim::findObject( SimObjectId((uintptr_t)st.profile), st.profile ) )
{
st.sound = SFX->createSource( st.profile, &getTransform() );
if ( st.sound )

View file

@ -405,12 +405,12 @@ bool ShapeBaseImageData::preload(bool server, String &errorStr)
// Resolve objects transmitted from server
if (!server) {
if (projectile)
if (Sim::findObject(SimObjectId(projectile), projectile) == false)
if (Sim::findObject(SimObjectId((uintptr_t)projectile), projectile) == false)
Con::errorf(ConsoleLogEntry::General, "Error, unable to load projectile for shapebaseimagedata");
for (U32 i = 0; i < MaxStates; i++) {
if (state[i].emitter)
if (!Sim::findObject(SimObjectId(state[i].emitter), state[i].emitter))
if (!Sim::findObject(SimObjectId((uintptr_t)state[i].emitter), state[i].emitter))
Con::errorf(ConsoleLogEntry::General, "Error, unable to load emitter for image datablock");
String str;
@ -1008,7 +1008,7 @@ void ShapeBaseImageData::packData(BitStream* stream)
// Write the projectile datablock
if (stream->writeFlag(projectile))
stream->writeRangedU32(packed? SimObjectId(projectile):
stream->writeRangedU32(packed? SimObjectId((uintptr_t)projectile):
projectile->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
stream->writeFlag(cloakable);
@ -1036,7 +1036,7 @@ void ShapeBaseImageData::packData(BitStream* stream)
if( stream->writeFlag( casing ) )
{
stream->writeRangedU32(packed? SimObjectId(casing):
stream->writeRangedU32(packed? SimObjectId((uintptr_t)casing):
casing->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
}
@ -1125,7 +1125,7 @@ void ShapeBaseImageData::packData(BitStream* stream)
if (stream->writeFlag(s.emitter))
{
stream->writeRangedU32(packed? SimObjectId(s.emitter):
stream->writeRangedU32(packed? SimObjectId((uintptr_t)s.emitter):
s.emitter->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
stream->write(s.emitterTime);

View file

@ -1019,7 +1019,7 @@ void TSStaticPolysoupConvex::getPolyList(AbstractPolyList *list)
list->addPoint(verts[2]);
list->addPoint(verts[1]);
list->begin(0, (U32)idx ^ (U32)mesh);
list->begin(0, (U32)idx ^ (uintptr_t)mesh);
list->vertex(base + 2);
list->vertex(base + 1);
list->vertex(base + 0);

View file

@ -134,11 +134,11 @@ bool FlyingVehicleData::preload(bool server, String &errorStr)
if (!server) {
for (S32 i = 0; i < MaxSounds; i++)
if (sound[i])
Sim::findObject(SimObjectId(sound[i]),sound[i]);
Sim::findObject(SimObjectId((uintptr_t)sound[i]),sound[i]);
for (S32 j = 0; j < MaxJetEmitters; j++)
if (jetEmitter[j])
Sim::findObject(SimObjectId(jetEmitter[j]),jetEmitter[j]);
Sim::findObject(SimObjectId((uintptr_t)jetEmitter[j]),jetEmitter[j]);
}
// Extract collision planes from shape collision detail level
@ -244,7 +244,7 @@ void FlyingVehicleData::packData(BitStream* stream)
{
if (stream->writeFlag(sound[i]))
{
SimObjectId writtenId = packed ? SimObjectId(sound[i]) : sound[i]->getId();
SimObjectId writtenId = packed ? SimObjectId((uintptr_t)sound[i]) : sound[i]->getId();
stream->writeRangedU32(writtenId, DataBlockObjectIdFirst, DataBlockObjectIdLast);
}
}
@ -253,7 +253,7 @@ void FlyingVehicleData::packData(BitStream* stream)
{
if (stream->writeFlag(jetEmitter[j]))
{
SimObjectId writtenId = packed ? SimObjectId(jetEmitter[j]) : jetEmitter[j]->getId();
SimObjectId writtenId = packed ? SimObjectId((uintptr_t)jetEmitter[j]) : jetEmitter[j]->getId();
stream->writeRangedU32(writtenId, DataBlockObjectIdFirst,DataBlockObjectIdLast);
}
}

View file

@ -315,10 +315,10 @@ bool HoverVehicleData::preload(bool server, String &errorStr)
if (!server) {
for (S32 i = 0; i < MaxSounds; i++)
if (sound[i])
Sim::findObject(SimObjectId(sound[i]),sound[i]);
Sim::findObject(SimObjectId((uintptr_t)sound[i]),sound[i]);
for (S32 j = 0; j < MaxJetEmitters; j++)
if (jetEmitter[j])
Sim::findObject(SimObjectId(jetEmitter[j]),jetEmitter[j]);
Sim::findObject(SimObjectId((uintptr_t)jetEmitter[j]),jetEmitter[j]);
}
if( !dustTrailEmitter && dustTrailID != 0 )
@ -364,14 +364,14 @@ void HoverVehicleData::packData(BitStream* stream)
for (S32 i = 0; i < MaxSounds; i++)
if (stream->writeFlag(sound[i]))
stream->writeRangedU32(packed? SimObjectId(sound[i]):
stream->writeRangedU32(packed? SimObjectId((uintptr_t)sound[i]):
sound[i]->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
for (S32 j = 0; j < MaxJetEmitters; j++)
{
if (stream->writeFlag(jetEmitter[j]))
{
SimObjectId writtenId = packed ? SimObjectId(jetEmitter[j]) : jetEmitter[j]->getId();
SimObjectId writtenId = packed ? SimObjectId((uintptr_t)jetEmitter[j]) : jetEmitter[j]->getId();
stream->writeRangedU32(writtenId, DataBlockObjectIdFirst,DataBlockObjectIdLast);
}
}

View file

@ -226,7 +226,7 @@ bool VehicleData::preload(bool server, String &errorStr)
if (!server) {
for (S32 i = 0; i < Body::MaxSounds; i++)
if (body.sound[i])
Sim::findObject(SimObjectId(body.sound[i]),body.sound[i]);
Sim::findObject(SimObjectId((uintptr_t)body.sound[i]),body.sound[i]);
}
if( !dustEmitter && dustID != 0 )
@ -275,7 +275,7 @@ void VehicleData::packData(BitStream* stream)
stream->write(body.friction);
for (i = 0; i < Body::MaxSounds; i++)
if (stream->writeFlag(body.sound[i]))
stream->writeRangedU32(packed? SimObjectId(body.sound[i]):
stream->writeRangedU32(packed? SimObjectId((uintptr_t)body.sound[i]):
body.sound[i]->getId(),DataBlockObjectIdFirst,
DataBlockObjectIdLast);

View file

@ -343,7 +343,7 @@ bool WheeledVehicleData::preload(bool server, String &errorStr)
return false;
if (tireEmitter)
Sim::findObject(SimObjectId(tireEmitter),tireEmitter);
Sim::findObject(SimObjectId((uintptr_t)tireEmitter),tireEmitter);
}
// Extract wheel information from the shape
@ -477,7 +477,7 @@ void WheeledVehicleData::packData(BitStream* stream)
Parent::packData(stream);
if (stream->writeFlag(tireEmitter))
stream->writeRangedU32(packed? SimObjectId(tireEmitter):
stream->writeRangedU32(packed? SimObjectId((uintptr_t)tireEmitter):
tireEmitter->getId(),DataBlockObjectIdFirst,DataBlockObjectIdLast);
for (S32 i = 0; i < MaxSounds; i++)

View file

@ -575,7 +575,7 @@ namespace _Private {
///
#define FIELDOFFSET( fieldName ) \
U32( ( ( const char* ) &( ( ( ThisType* ) 16 )->fieldName ) ) - 16 ) // Artificial offset to avoid compiler warnings.
uintptr_t( ( ( const char* ) &( ( ( ThisType* ) 16 )->fieldName ) ) - 16 ) // Artificial offset to avoid compiler warnings.
///
#define CLASSDOC( className, doc ) \

View file

@ -95,7 +95,7 @@ namespace DictHash
inline U32 hash(const void *data)
{
return (U32)data;
return (uintptr_t)data;
}
template<class A, class B>

View file

@ -864,7 +864,7 @@ void MeshRoad::prepRenderImage( SceneRenderState* state )
// We sort by the material then vertex buffer.
ri->defaultKey = matInst->getStateHint();
ri->defaultKey2 = (U32)ri->vertBuff; // Not 64bit safe!
ri->defaultKey2 = (uintptr_t)ri->vertBuff; // Not 64bit safe!
renderPass->addInst( ri );
}

View file

@ -68,7 +68,7 @@ void ForestCreateUndoAction::redo()
// We store the datablock ID rather than the actual pointer
// since the pointer could go bad.
ForestItemData *data;
if ( !Sim::findObject( (SimObjectId)(item.getData()), data ) )
if ( !Sim::findObject( (SimObjectId)(uintptr_t)(item.getData()), data ) )
{
Con::errorf( "ForestCreateUndoAction::redo() - ForestItemData for item to restore does not seem to exist. Undo stack may be hosed." );
continue;
@ -140,7 +140,7 @@ void ForestDeleteUndoAction::undo()
// We store the datablock ID rather than the actual pointer
// since the pointer could go bad.
ForestItemData *data;
if ( !Sim::findObject( (SimObjectId)(item.getData()), data ) )
if ( !Sim::findObject( (SimObjectId)(uintptr_t)(item.getData()), data ) )
{
Con::errorf( "ForestDeleteUndoAction::undo() - ForestItemData for item to restore does not seem to exist. Undo stack may be hosed." );
continue;
@ -201,7 +201,7 @@ void ForestUpdateAction::_swapState()
// We store the datablock ID rather than the actual pointer
// since the pointer could go bad.
ForestItemData *data;
if ( !Sim::findObject( (SimObjectId)(item.getData()), data ) )
if ( !Sim::findObject( (SimObjectId)(uintptr_t)(item.getData()), data ) )
{
Con::errorf( "ForestUpdateAction::_swapState() - ForestItemData for item to restore does not seem to exist. Undo stack may be hosed." );
continue;

View file

@ -87,9 +87,9 @@ _STRING_VALUE_LOOKUP_FXN(GFXStringBlendOp);
#define VALIDATE_LOOKUPTABLE( tablearray, enumprefix ) \
for( S32 i = enumprefix##_FIRST; i < enumprefix##_COUNT; i++ ) \
if( (S32)tablearray[i] == GFX_UNINIT_VAL ) \
if( (intptr_t)tablearray[i] == GFX_UNINIT_VAL ) \
Con::warnf( "GFXStringEnumTranslate: Unassigned value in " #tablearray ": %i", i ); \
else if( (S32)tablearray[i] == GFX_UNSUPPORTED_VAL ) \
else if( (intptr_t)tablearray[i] == GFX_UNSUPPORTED_VAL ) \
Con::warnf( "GFXStringEnumTranslate: Unsupported value in " #tablearray ": %i", i );
//------------------------------------------------------------------------------

View file

@ -21,7 +21,7 @@ void GFXGLVertexDecl::prepareVertexFormat() const
{
const glVertexAttribData &glElement = glVerticesFormat[i];
glVertexAttribFormat( glElement.attrIndex, glElement.elementCount, glElement.type, glElement.normalized, (U32)glElement.pointerFirst );
glVertexAttribFormat( glElement.attrIndex, glElement.elementCount, glElement.type, glElement.normalized, (uintptr_t)glElement.pointerFirst );
glVertexAttribBinding( glElement.attrIndex, glElement.stream );
}

View file

@ -924,7 +924,7 @@ SimObject* GuiListBoxCtrl::getItemObject( S32 index )
}
SimObject *outObj;
Sim::findObject( (SimObjectId)(mItems[ index ]->itemData), outObj );
Sim::findObject( (SimObjectId)(uintptr_t)(mItems[ index ]->itemData), outObj );
return outObj;
}
@ -1481,7 +1481,7 @@ void GuiListBoxCtrl::_mirror()
for ( U32 i = 0; i < mItems.size(); i++ )
{
curId = (SimObjectId)mItems[i]->itemData;
curId = (SimObjectId)(uintptr_t)mItems[i]->itemData;
Sim::findObject( curId, curObj );
@ -1515,7 +1515,7 @@ void GuiListBoxCtrl::_mirror()
for ( U32 j = 0; j < mItems.size(); j++ )
{
if ( (SimObjectId)(mItems[j]->itemData) == curId )
if ( (SimObjectId)(uintptr_t)(mItems[j]->itemData) == curId )
{
found = true;
break;
@ -1524,7 +1524,7 @@ void GuiListBoxCtrl::_mirror()
for ( U32 j = 0; j < mFilteredItems.size(); j++ )
{
if ( (SimObjectId)(mFilteredItems[j]->itemData) == curId )
if ( (SimObjectId)(uintptr_t)(mFilteredItems[j]->itemData) == curId )
{
found = true;
break;

View file

@ -30,7 +30,7 @@ MatrixSet::MatrixSet()
// this class will provide a place where aligned/specalized matrix math can take place.
// We should be able to plug in any kind of platform-specific optimization
// behind the delgates.
AssertFatal( ((int)this & 0xF) == 0, "MatrixSet has been allocated off a 16-byte boundary!" );
AssertFatal( ((intptr_t)this & 0xF) == 0, "MatrixSet has been allocated off a 16-byte boundary!" );
// Must be initialized by name, not a for(), it's macro magic
MATRIX_SET_BIND_VALUE(ObjectToWorld);
@ -47,4 +47,4 @@ MatrixSet::MatrixSet()
mViewSource = NULL;
mProjectionSource = NULL;
}
}

View file

@ -23,6 +23,8 @@
#ifndef _TORQUE_TYPES_H_
#define _TORQUE_TYPES_H_
#include <stdint.h>
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//-----------------------------------------Basic Types--------------------------------------------------//
//////////////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -29,7 +29,7 @@
#include "platform/platform.h"
#include "math/mMath.h"
#include "gfx/gl/ggl/ggl.h"
#include "gfx/gl/tGL/tGL.h"
#define __gl_h_
#include <AGL/agl.h>

View file

@ -22,11 +22,12 @@
#include "platformWin32/platformWin32.h"
#include "core/strings/stringFunctions.h"
#include "core/util/journal/process.h"
void Platform::postQuitMessage(const S32 in_quitVal)
{
if (!Platform::getWebDeployment())
PostQuitMessage(in_quitVal);
Process::requestShutdown();
}
void Platform::debugBreak()

View file

@ -0,0 +1,354 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/nativeDialogs/fileDialog.h"
#ifdef TORQUE_TOOLS
//-----------------------------------------------------------------------------
// PlatformFileDlgData Implementation
//-----------------------------------------------------------------------------
FileDialogData::FileDialogData()
{
AssertFatal(0, "Not Implemented");
}
FileDialogData::~FileDialogData()
{
}
//-----------------------------------------------------------------------------
// FileDialog Implementation
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(FileDialog);
ConsoleDocClass( FileDialog,
"@brief Base class responsible for displaying an OS file browser.\n\n"
"FileDialog is a platform agnostic dialog interface for querying the user for "
"file locations. It is designed to be used through the exposed scripting interface.\n\n"
"FileDialog is the base class for Native File Dialog controls in Torque. It provides these basic areas of functionality:\n\n"
" - Inherits from SimObject and is exposed to the scripting interface\n"
" - Provides blocking interface to allow instant return to script execution\n"
" - Simple object configuration makes practical use easy and effective\n\n"
"FileDialog is *NOT* intended to be used directly in script and is only exposed to script to expose generic file dialog attributes.\n\n"
"This base class is usable in TorqueScript, but is does not specify what functionality is intended (open or save?). "
"Its children, OpenFileDialog and SaveFileDialog, do make use of DialogStyle flags and do make use of specific funcationality. "
"These are the preferred classes to use\n\n"
"However, the FileDialog base class does contain the key properties and important method for file browing. The most "
"important function is Execute(). This is used by both SaveFileDialog and OpenFileDialog to initiate the browser.\n\n"
"@tsexample\n"
"// NOTE: This is not he preferred class to use, but this still works\n\n"
"// Create the file dialog\n"
"%baseFileDialog = new FileDialog()\n"
"{\n"
" // Allow browsing of all file types\n"
" filters = \"*.*\";\n\n"
" // No default file\n"
" defaultFile = "";\n\n"
" // Set default path relative to project\n"
" defaultPath = \"./\";\n\n"
" // Set the title\n"
" title = \"Durpa\";\n\n"
" // Allow changing of path you are browsing\n"
" changePath = true;\n"
"};\n\n"
" // Launch the file dialog\n"
" %baseFileDialog.Execute();\n"
" \n"
" // Don't forget to cleanup\n"
" %baseFileDialog.delete();\n\n\n"
"@endtsexample\n\n"
"@note FileDialog and its related classes are only availble in a Tools build of Torque.\n\n"
"@see OpenFileDialog for a practical example on opening a file\n"
"@see SaveFileDialog for a practical example of saving a file\n"
"@ingroup FileSystem\n"
);
FileDialog::FileDialog() : mData()
{
AssertFatal(0, "Not Implemented");
}
FileDialog::~FileDialog()
{
}
void FileDialog::initPersistFields()
{
Parent::initPersistFields();
}
//
// Execute Method
//
bool FileDialog::Execute()
{
return false;
}
//-----------------------------------------------------------------------------
// Dialog Filters
//-----------------------------------------------------------------------------
bool FileDialog::setFilters( void *object, const char *index, const char *data )
{
return true;
};
//-----------------------------------------------------------------------------
// Default Path Property - String Validated on Write
//-----------------------------------------------------------------------------
bool FileDialog::setDefaultPath( void *object, const char *index, const char *data )
{
return false;
};
//-----------------------------------------------------------------------------
// Default File Property - String Validated on Write
//-----------------------------------------------------------------------------
bool FileDialog::setDefaultFile( void *object, const char *index, const char *data )
{
return false;
};
//-----------------------------------------------------------------------------
// ChangePath Property - Change working path on successful file selection
//-----------------------------------------------------------------------------
bool FileDialog::setChangePath( void *object, const char *index, const char *data )
{
return true;
};
const char* FileDialog::getChangePath(void* obj, const char* data)
{
return 0;
}
bool FileDialog::setFile( void *object, const char *index, const char *data )
{
return false;
};
//-----------------------------------------------------------------------------
// OpenFileDialog Implementation
//-----------------------------------------------------------------------------
ConsoleDocClass( OpenFileDialog,
"@brief Derived from FileDialog, this class is responsible for opening a file browser with the intention of opening a file.\n\n"
"The core usage of this dialog is to locate a file in the OS and return the path and name. This does not handle "
"the actual file parsing or data manipulation. That functionality is left up to the FileObject class.\n\n"
"@tsexample\n"
" // Create a dialog dedicated to opening files\n"
" %openFileDlg = new OpenFileDialog()\n"
" {\n"
" // Look for jpg image files\n"
" // First part is the descriptor|second part is the extension\n"
" Filters = \"Jepg Files|*.jpg\";\n"
" // Allow browsing through other folders\n"
" ChangePath = true;\n\n"
" // Only allow opening of one file at a time\n"
" MultipleFiles = false;\n"
" };\n\n"
" // Launch the open file dialog\n"
" %result = %openFileDlg.Execute();\n\n"
" // Obtain the chosen file name and path\n"
" if ( %result )\n"
" {\n"
" %seletedFile = %openFileDlg.file;\n"
" }\n"
" else\n"
" {\n"
" %selectedFile = \"\";\n"
" }\n\n"
" // Cleanup\n"
" %openFileDlg.delete();\n\n\n"
"@endtsexample\n\n"
"@note FileDialog and its related classes are only availble in a Tools build of Torque.\n\n"
"@see FileDialog\n"
"@see SaveFileDialog\n"
"@see FileObject\n"
"@ingroup FileSystem\n"
);
OpenFileDialog::OpenFileDialog()
{
AssertFatal(0, "Not Implemented");
}
OpenFileDialog::~OpenFileDialog()
{
}
IMPLEMENT_CONOBJECT(OpenFileDialog);
//-----------------------------------------------------------------------------
// Console Properties
//-----------------------------------------------------------------------------
void OpenFileDialog::initPersistFields()
{
}
//-----------------------------------------------------------------------------
// File Must Exist - Boolean
//-----------------------------------------------------------------------------
bool OpenFileDialog::setMustExist( void *object, const char *index, const char *data )
{
return true;
};
const char* OpenFileDialog::getMustExist(void* obj, const char* data)
{
return 0;
}
//-----------------------------------------------------------------------------
// Can Select Multiple Files - Boolean
//-----------------------------------------------------------------------------
bool OpenFileDialog::setMultipleFiles( void *object, const char *index, const char *data )
{
return true;
};
const char* OpenFileDialog::getMultipleFiles(void* obj, const char* data)
{
return 0;
}
//-----------------------------------------------------------------------------
// SaveFileDialog Implementation
//-----------------------------------------------------------------------------
ConsoleDocClass( SaveFileDialog,
"@brief Derived from FileDialog, this class is responsible for opening a file browser with the intention of saving a file.\n\n"
"The core usage of this dialog is to locate a file in the OS and return the path and name. This does not handle "
"the actual file writing or data manipulation. That functionality is left up to the FileObject class.\n\n"
"@tsexample\n"
" // Create a dialog dedicated to opening file\n"
" %saveFileDlg = new SaveFileDialog()\n"
" {\n"
" // Only allow for saving of COLLADA files\n"
" Filters = \"COLLADA Files (*.dae)|*.dae|\";\n\n"
" // Default save path to where the WorldEditor last saved\n"
" DefaultPath = $pref::WorldEditor::LastPath;\n\n"
" // No default file specified\n"
" DefaultFile = \"\";\n\n"
" // Do not allow the user to change to a new directory\n"
" ChangePath = false;\n\n"
" // Prompt the user if they are going to overwrite an existing file\n"
" OverwritePrompt = true;\n"
" };\n\n"
" // Launch the save file dialog\n"
" %saveFileDlg.Execute();\n\n"
" if ( %result )\n"
" {\n"
" %seletedFile = %openFileDlg.file;\n"
" }\n"
" else\n"
" {\n"
" %selectedFile = \"\";\n"
" }\n\n"
" // Cleanup\n"
" %saveFileDlg.delete();\n"
"@endtsexample\n\n"
"@note FileDialog and its related classes are only availble in a Tools build of Torque.\n\n"
"@see FileDialog\n"
"@see OpenFileDialog\n"
"@see FileObject\n"
"@ingroup FileSystem\n"
);
SaveFileDialog::SaveFileDialog()
{
AssertFatal(0, "Not Implemented");
}
SaveFileDialog::~SaveFileDialog()
{
}
IMPLEMENT_CONOBJECT(SaveFileDialog);
//-----------------------------------------------------------------------------
// Console Properties
//-----------------------------------------------------------------------------
void SaveFileDialog::initPersistFields()
{
Parent::initPersistFields();
}
//-----------------------------------------------------------------------------
// Prompt on Overwrite - Boolean
//-----------------------------------------------------------------------------
bool SaveFileDialog::setOverwritePrompt( void *object, const char *index, const char *data )
{
return true;
};
const char* SaveFileDialog::getOverwritePrompt(void* obj, const char* data)
{
return 0;
}
//-----------------------------------------------------------------------------
// OpenFolderDialog Implementation
//-----------------------------------------------------------------------------
OpenFolderDialog::OpenFolderDialog()
{
AssertFatal(0, "Not Implemented");
}
IMPLEMENT_CONOBJECT(OpenFolderDialog);
ConsoleDocClass( OpenFolderDialog,
"@brief OS level dialog used for browsing folder structures.\n\n"
"This is essentially an OpenFileDialog, but only used for returning directory paths, not files.\n\n"
"@note FileDialog and its related classes are only availble in a Tools build of Torque.\n\n"
"@see OpenFileDialog for more details on functionality.\n\n"
"@ingroup FileSystem\n"
);
void OpenFolderDialog::initPersistFields()
{
Parent::initPersistFields();
}
#endif

View file

@ -59,7 +59,7 @@ void DisplayErrorAlert(const char* errMsg, bool showSDLError = true);
// Just like strstr, except case insensitive
// (Found this function at http://www.codeguru.com/string/stristr.html)
extern char *stristr(char *szStringToBeSearched, const char *szSubstringToSearchFor);
extern const char *stristr(const char *szStringToBeSearched, const char *szSubstringToSearchFor);
extern "C"
{

View file

@ -22,30 +22,25 @@
#include "platformX86UNIX/platformX86UNIX.h"
#include "platform/threads/semaphore.h"
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <semaphore.h>
#include <time.h>
// Instead of that mess that was here before, lets use the SDL lib to deal
// with the semaphores.
#include <SDL.h>
#include <SDL_thread.h>
struct PlatformSemaphore
{
sem_t semaphore;
bool initialized;
SDL_sem *semaphore;
PlatformSemaphore(S32 initialCount)
{
initialized = true;
if (sem_init(&semaphore, 0, initialCount) == -1) {
initialized = false;
AssertFatal(0, "PlatformSemaphore constructor - Failed to create Semaphore.");
}
semaphore = SDL_CreateSemaphore(initialCount);
AssertFatal(semaphore, "PlatformSemaphore constructor - Failed to create SDL Semaphore.");
}
~PlatformSemaphore()
{
sem_destroy(&semaphore);
initialized = false;
SDL_DestroySemaphore(semaphore);
}
};
@ -62,37 +57,28 @@ Semaphore::~Semaphore()
bool Semaphore::acquire(bool block, S32 timeoutMS)
{
AssertFatal(mData && mData->initialized, "Semaphore::acquire - Invalid semaphore.");
AssertFatal(mData && mData->semaphore, "Semaphore::acquire - Invalid semaphore.");
if (block)
{
//SDL was removed so I do not now if this still holds true or not with OS calls but my guess is they are used underneath SDL anyway
// Semaphore acquiring is different from the MacOS/Win realization because SDL_SemWaitTimeout() with "infinite" timeout can be too heavy on some platforms.
// (see "man SDL_SemWaitTimeout(3)" for more info)
// "man" states to avoid the use of SDL_SemWaitTimeout at all, but at current stage this looks like a valid and working solution, so keeping it this way.
// [bank / Feb-2010]
if (timeoutMS == -1)
{
if (sem_wait(&mData->semaphore) < 0)
AssertFatal(false, "Semaphore::acquire - Wait failed.");
if (SDL_SemWait(mData->semaphore) < 0)
AssertFatal(false, "Semaphore::acquie - Wait failed.");
}
else
{
//convert timeoutMS to timespec
timespec ts;
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
AssertFatal(false, "Semaphore::acquire - clock_realtime failed.");
}
ts.tv_sec += timeoutMS / 1000;
ts.tv_nsec += (timeoutMS % 1000) * 1000;
if (sem_timedwait(&mData->semaphore, &ts) < 0)
AssertFatal(false, "Semaphore::acquire - Wait with timeout failed.");
if (SDL_SemWaitTimeout(mData->semaphore, timeoutMS) < 0)
AssertFatal(false, "Semaphore::acquie - Wait with timeout failed.");
}
return (true);
}
else
{
int res = sem_trywait(&mData->semaphore);
int res = SDL_SemTryWait(mData->semaphore);
return (res == 0);
}
}
@ -100,5 +86,5 @@ bool Semaphore::acquire(bool block, S32 timeoutMS)
void Semaphore::release()
{
AssertFatal(mData, "Semaphore::releaseSemaphore - Invalid semaphore.");
sem_post(&mData->semaphore);
SDL_SemPost(mData->semaphore);
}

View file

@ -113,6 +113,11 @@ void StdConsole::enable(bool enabled)
}
}
void StdConsole::enableInput( bool enabled )
{
stdConsoleInputEnabled = enabled;
}
bool StdConsole::isEnabled()
{
if ( stdConsole )
@ -137,6 +142,7 @@ StdConsole::StdConsole()
iCmdIndex = 0;
stdConsoleEnabled = false;
stdConsoleInputEnabled = false;
Con::addConsumer(stdConsoleConsumer);
inpos = 0;
lineOutput = false;
@ -233,6 +239,10 @@ void StdConsole::process()
if (numEvents == -1)
return;
// TODO LINUX, when debug in qtCreator some times we get false console inputs.
if( !stdConsoleInputEnabled )
return;
typedData[numEvents] = '\0';
if (numEvents > 0)
{

View file

@ -0,0 +1,83 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "platform/types.h"
#include "platform/platformDlibrary.h"
#include <dlfcn.h>
class x86UNIXDLibrary: public DLibrary
{
void* mLibHandle;
public:
x86UNIXDLibrary();
virtual ~x86UNIXDLibrary();
bool open(const char* file);
void close();
virtual void *bind(const char *name);
};
x86UNIXDLibrary::x86UNIXDLibrary()
{
mLibHandle = 0;
}
x86UNIXDLibrary::~x86UNIXDLibrary()
{
close();
}
bool x86UNIXDLibrary::open(const char* file)
{
mLibHandle = dlopen(file, RTLD_LAZY);
if( !mLibHandle )
return false;
return true;
}
void x86UNIXDLibrary::close()
{
if( mLibHandle )
{
dlclose(mLibHandle);
mLibHandle = 0;
}
}
void* x86UNIXDLibrary::bind(const char *name)
{
return mLibHandle ? dlsym(mLibHandle, name) : 0;
}
DLibraryRef OsLoadLibrary(const char* file)
{
x86UNIXDLibrary* library = new x86UNIXDLibrary();
if (!library->open(file))
{
delete library;
library = 0;
}
return library;
}

View file

@ -35,27 +35,27 @@
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/Xft/Xft.h>
#include <X11/extensions/Xrender.h> // For XRenderColor
//#include <X11/extensions/Xrender.h> // For XRenderColor
// Needed for getenv in createFont
#include <stdlib.h>
XftFont *loadFont(const char *name, S32 size, Display *display)
{
XftFont *fontInfo = NULL;
char* fontname = const_cast<char*>(name);
const char* fontname = name;
if (dStrlen(fontname)==0)
fontname = "arial";
else if (stristr(const_cast<char*>(name), "arial") != NULL)
else if (stristr(name, "arial") != NULL)
fontname = "arial";
else if (stristr(const_cast<char*>(name), "lucida console") != NULL)
else if (stristr(name, "lucida console") != NULL)
fontname = "lucida console";
char* weight = "medium";
char* slant = "roman"; // no slant
const char* weight = "medium";
const char* slant = "roman"; // no slant
if (stristr(const_cast<char*>(name), "bold") != NULL)
if (stristr(name, "bold") != NULL)
weight = "bold";
if (stristr(const_cast<char*>(name), "italic") != NULL)
if (stristr(name, "italic") != NULL)
slant = "italic";
int mSize = size - 2 - (int)((float)size * 0.1);
@ -76,7 +76,7 @@ XftFont *loadFont(const char *name, S32 size, Display *display)
XftNameUnparse(fontInfo->pattern, xftname, 1024);
#ifdef DEBUG
Con::printf("Font '%s %d' mapped to '%s'\n", name, size, xftname);
Con::printf("Font '%s %d' mapped to '%s'\n", name, size, xftname);
#endif
return fontInfo;
@ -186,7 +186,7 @@ XftFont *loadFont(const char *name, S32 size, Display *display)
// XA: New class for the unix unicode font
PlatformFont *createPlatformFont(const char *name, U32 size, U32 charset /* = TGE_ANSI_CHARSET */)
PlatformFont *createPlatformFont(const char *name, dsize_t size, U32 charset /* = TGE_ANSI_CHARSET */)
{
PlatformFont *retFont = new x86UNIXFont;
@ -204,7 +204,7 @@ x86UNIXFont::~x86UNIXFont()
{}
bool x86UNIXFont::create(const char *name, U32 size, U32 charset)
bool x86UNIXFont::create(const char *name, dsize_t size, U32 charset)
{
Display *display = XOpenDisplay(getenv("DISPLAY"));
if (display == NULL)
@ -345,4 +345,3 @@ PlatformFont::CharInfo &x86UNIXFont::getCharInfo(const UTF8 *str) const
{
return getCharInfo(oneUTF32toUTF16(oneUTF8toUTF32(str,NULL)));
}

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#if 0
#include "platformX86UNIX/platformGL.h"
#include "platformX86UNIX/platformX86UNIX.h"
#include "console/console.h"
@ -389,3 +389,4 @@ bool GL_EXT_Init( )
return true;
}
#endif // 0

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef TORQUE_SDL
#include "platformX86UNIX/platformX86UNIX.h"
#include "platform/platformInput.h"
#include "platform/platformVideo.h"
@ -602,3 +602,4 @@ void XClipboard::handleSelectionRequest(XSelectionRequestEvent& request)
// flush the output buffer to send the event now
XFlush(display);
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@
#ifndef _X86UNIXINPUTMANAGER_H_
#define _X86UNIXINPUTMANAGER_H_
#include "core/tVector.h"
#include "core/util/tVector.h"
#include "platform/platformInput.h"
#include "platformX86UNIX/platformX86UNIX.h"
@ -45,7 +45,7 @@ struct AsciiData
KeyData goofy;
};
typedef struct _SDL_Joystick;
struct _SDL_Joystick;
struct JoystickAxisInfo
{
@ -184,7 +184,7 @@ class UInputManager : public InputManager
void mouseButtonEvent(const SDL_Event& event);
void mouseMotionEvent(const SDL_Event& event);
void keyEvent(const SDL_Event& event);
bool processKeyEvent(InputEvent &event);
bool processKeyEvent(InputEventInfo &event);
};
#endif // _H_X86UNIXINPUTMANAGER_

View file

@ -26,10 +26,19 @@
#include "platformX86UNIX/platformX86UNIX.h"
#include "platformX86UNIX/x86UNIXStdConsole.h"
#include "platformX86UNIX/x86UNIXState.h"
extern void InitWindowingSystem();
//------------------------------------------------------------------------------
void Platform::init()
{
StdConsole::create();
stdConsole->enable(true);
// init process control stuff
ProcessControlInit();
Con::printf("Initializing platform...");
// Set the platform variable for the scripts
@ -42,69 +51,13 @@ void Platform::init()
Con::setVariable( "$platformUnixType", "Unknown" );
#endif
StdConsole::create();
Input::init();
//installRedBookDevices();
#if 0
#ifndef TORQUE_DEDICATED
// if we're not dedicated do more initialization
if (!x86UNIXState->isDedicated())
{
// init SDL
if (!InitSDL())
{
DisplayErrorAlert("Unable to initialize SDL.");
ImmediateShutdown(1);
}
Con::printf( "Video Init:" );
// load gl library
if (!GLLoader::OpenGLInit())
{
DisplayErrorAlert("Unable to initialize OpenGL.");
ImmediateShutdown(1);
}
// initialize video
Video::init();
if ( Video::installDevice( OpenGLDevice::create() ) )
Con::printf( " OpenGL display device detected." );
else
Con::printf( " OpenGL display device not detected." );
Con::printf(" ");
}
#endif
// if we are dedicated, do sleep timing and display results
if (x86UNIXState->isDedicated())
{
const S32 MaxSleepIter = 10;
U32 totalSleepTime = 0;
U32 start;
for (S32 i = 0; i < MaxSleepIter; ++i)
{
start = Platform::getRealMilliseconds();
Sleep(0, 1000000);
totalSleepTime += Platform::getRealMilliseconds() - start;
}
U32 average = static_cast<U32>(totalSleepTime / MaxSleepIter);
Con::printf("Sleep latency: %ums", average);
// dPrintf as well, since console output won't be visible yet
dPrintf("Sleep latency: %ums\n", average);
if (!x86UNIXState->getDSleep() && average < 10)
{
const char* msg = "Sleep latency ok, enabling dsleep for lower cpu " \
"utilization";
Con::printf("%s", msg);
dPrintf("%s\n", msg);
x86UNIXState->setDSleep(true);
}
}
InitWindowingSystem();
#endif
}
@ -143,7 +96,9 @@ extern "C"
extern S32 TorqueMain(S32 argc, const char **argv);
#if !defined(TORQUE_SHARED)
int main(int argc, const char **argv)
{
return TorqueMain(argc, argv);
}
#endif

View file

@ -24,25 +24,25 @@
#include <stdlib.h>
#include <mm_malloc.h>
void* dMemcpy(void *dst, const void *src, unsigned size)
void* dMemcpy(void *dst, const void *src, dsize_t size)
{
return memcpy(dst,src,size);
}
//--------------------------------------
void* dMemmove(void *dst, const void *src, unsigned size)
void* dMemmove(void *dst, const void *src, dsize_t size)
{
return memmove(dst,src,size);
}
//--------------------------------------
void* dMemset(void *dst, S32 c, unsigned size)
void* dMemset(void *dst, S32 c, dsize_t size)
{
return memset(dst,c,size);
}
//--------------------------------------
S32 dMemcmp(const void *ptr1, const void *ptr2, unsigned len)
S32 dMemcmp(const void *ptr1, const void *ptr2, dsize_t len)
{
return memcmp(ptr1, ptr2, len);
}

View file

@ -105,6 +105,18 @@ int XMessageBox::alertRetryCancel(const char *windowTitle, const char *message)
return show();
}
int XMessageBox::alertAssert(const char *windowTitle, const char *message)
{
mMessage = message;
mTitle = windowTitle;
mButtons.clear();
mButtons.push_back(XMessageBoxButton("Exit", OK));
mButtons.push_back(XMessageBoxButton("Ignore", Cancel));
mButtons.push_back(XMessageBoxButton("Ignore All", IgnoreAll));
mButtons.push_back(XMessageBoxButton("Debug", Retry));
return show();
}
void XMessageBox::repaint()
{
int white = WhitePixel(mDisplay, DefaultScreen(mDisplay));
@ -421,7 +433,7 @@ int XMessageBox::show()
XSetWMName(mDisplay, mWin, &wtitle);
// show window
XMapWindow(mDisplay, mWin);
XMapRaised(mDisplay, mWin);
// move it in case some bozo window manager repositioned it
XMoveWindow(mDisplay, mWin,
(mScreenWidth - mMBWidth) / 2, (mScreenHeight - mMBHeight) / 2);

View file

@ -83,6 +83,7 @@ class XMessageBox
static const int OK = 1;
static const int Cancel = 2;
static const int Retry = 3;
static const int IgnoreAll = 4;
XMessageBox(Display* display);
~XMessageBox();
@ -90,6 +91,7 @@ class XMessageBox
int alertOK(const char *windowTitle, const char *message);
int alertOKCancel(const char *windowTitle, const char *message);
int alertRetryCancel(const char *windowTitle, const char *message);
int alertAssert(const char *windowTitle, const char *message);
private:
int show();
void repaint();

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#if 0
#include "console/console.h"
#include "platform/event.h"
#include "platform/gameInterface.h"
@ -503,3 +503,5 @@ DisplayDevice* OpenGLDevice::create()
{
return new OpenGLDevice();
}
#endif // 0

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#if 0
#include "platformX86UNIX/platformX86UNIX.h"
#include "console/console.h"
@ -282,3 +282,4 @@ bool OpenALDLLInit()
} // end namespace Audio
#endif //0

View file

@ -31,12 +31,15 @@
#include <signal.h>
#ifndef TORQUE_DEDICATED
#include <SDL/SDL.h>
#include <SDL.h>
#endif
//-----------------------------------------------------------------------------
// This is a mainly a debugging function for intercepting a nonzero exit code
// and generating a core dump for a stack trace.
// Need an S64 here because postQuitMessage uses a U32, and
// forceshutdown uses an S32. So S64 is needed to
// accomodate them both
static void CheckExitCode(S64 exitCode)
{
if (exitCode != 0)

View file

@ -20,8 +20,6 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// Not needed on dedicated (SDL is not not linked against when dedicated)
#ifndef TORQUE_DEDICATED
#include "console/console.h"
#include "platformX86UNIX/platformX86UNIX.h"
#include "platform/platformRedBook.h"
@ -34,7 +32,9 @@
#include <string.h>
#endif
#include <SDL/SDL.h>
#include <SDL.h>
class SDL_CD; // TODO SDL remove
class UnixRedBookDevice : public RedBookDevice
{
@ -93,24 +93,7 @@ UnixRedBookDevice::~UnixRedBookDevice()
//------------------------------------------------------------------------------
bool UnixRedBookDevice::updateStatus()
{
#if !defined(__FreeBSD__)
AssertFatal(mCD, "mCD is NULL");
CDstatus status = SDL_CDStatus(mCD);
if (status == CD_ERROR)
{
setLastError("Error accessing device");
return(false);
}
else if (status == CD_TRAYEMPTY)
{
setLastError("CD tray empty");
return false;
}
mPlaying = (status == CD_PLAYING);
return true;
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
@ -126,134 +109,31 @@ void UnixRedBookDevice::setDeviceInfo(S32 deviceId, const char *deviceName)
//------------------------------------------------------------------------------
bool UnixRedBookDevice::open()
{
#if !defined(__FreeBSD__)
if(mAcquired)
{
setLastError("Device is already open.");
return(false);
}
// open the device
mCD = SDL_CDOpen(mDeviceId);
if (mCD == NULL)
{
setLastError(SDL_GetError());
return false;
}
mAcquired = true;
openVolume();
setLastError("");
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
bool UnixRedBookDevice::close()
{
#if !defined(__FreeBSD__)
if(!mAcquired)
{
setLastError("Device has not been acquired");
return(false);
}
stop();
closeVolume();
if (mCD != NULL)
{
SDL_CDClose(mCD);
mCD = NULL;
}
mAcquired = false;
setLastError("");
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
bool UnixRedBookDevice::play(U32 track)
{
#if !defined(__FreeBSD__)
if(!mAcquired)
{
setLastError("Device has not been acquired");
return(false);
}
U32 numTracks;
if(!getTrackCount(&numTracks))
return(false);
if(track >= numTracks)
{
setLastError("Track index is out of range");
return(false);
}
if (!updateStatus())
return false;
AssertFatal(mCD, "mCD is NULL");
if (SDL_CDPlayTracks(mCD, track, 0, 1, 0) == -1)
{
setLastError(SDL_GetError());
return false;
}
mPlaying = true;
setLastError("");
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
bool UnixRedBookDevice::stop()
{
#if !defined(__FreeBSD__)
if(!mAcquired)
{
setLastError("Device has not been acquired");
return(false);
}
AssertFatal(mCD, "mCD is NULL");
if (SDL_CDStop(mCD) == -1)
{
setLastError(SDL_GetError());
return(false);
}
mPlaying = false;
setLastError("");
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
//------------------------------------------------------------------------------
bool UnixRedBookDevice::getTrackCount(U32 * numTracks)
{
#if !defined(__FreeBSD__)
if(!mAcquired)
{
setLastError("Device has not been acquired");
return(false);
}
if (!updateStatus())
return false;
AssertFatal(mCD, "mCD is NULL");
*numTracks = mCD->numtracks;
return(true);
#endif // !defined(__FreeBSD__)
return false; // TODO LINUX
}
template <class Type>
@ -283,18 +163,7 @@ bool UnixRedBookDevice::getVolume(F32 * volume)
}
#if defined(__linux__)
AssertFatal(mCD, "mCD is NULL");
setLastError("");
cdrom_volctrl sysvol;
if (ioctl(mCD->id, CDROMVOLREAD, &sysvol) == -1)
{
setLastError(strerror(errno));
return(false);
}
U8 maxVol = max(sysvol.channel0, sysvol.channel1);
// JMQTODO: support different left/right channel volumes?
*volume = static_cast<F32>(maxVol) / 255.f;
AssertFatal(0, "SDL CD not implemented");
return true;
#else
return(false);
@ -319,21 +188,7 @@ bool UnixRedBookDevice::setVolume(F32 volume)
}
#if defined(__linux__)
AssertFatal(mCD, "mCD is NULL");
setLastError("");
cdrom_volctrl sysvol;
volume = volume * 255.f;
if (volume > 255)
volume = 255;
if (volume < 0)
volume = 0;
sysvol.channel0 = sysvol.channel1 = static_cast<__u8>(volume);
if (ioctl(mCD->id, CDROMVOLCTRL, &sysvol) == -1)
{
setLastError(strerror(errno));
return(false);
}
AssertFatal(0, "SDL CD not implemented");
return true;
#else
return(false);
@ -348,17 +203,7 @@ void UnixRedBookDevice::openVolume()
// Its unforunate that we have to do it this way, but SDL does not currently
// support setting CD audio volume
#if defined(__linux__)
AssertFatal(mCD, "mCD is NULL");
setLastError("");
if (ioctl(mCD->id, CDROMVOLREAD, &mOriginalVolume) == -1)
{
setLastError(strerror(errno));
return;
}
mVolumeInitialized = true;
AssertFatal(0, "SDL CD not implemented");
#else
setLastError("Volume failed to initialize");
#endif
@ -372,15 +217,7 @@ void UnixRedBookDevice::closeVolume()
return;
#if defined(__linux__)
AssertFatal(mCD, "mCD is NULL");
setLastError("");
if (ioctl(mCD->id, CDROMVOLCTRL, &mOriginalVolume) == -1)
{
setLastError(strerror(errno));
return;
}
AssertFatal(0, "SDL CD not implemented");
#endif
mVolumeInitialized = false;
@ -398,33 +235,7 @@ void UnixRedBookDevice::setLastError(const char * error)
//------------------------------------------------------------------------------
void InstallRedBookDevices()
{
#if !defined(__FreeBSD__)
Con::printf("CD Audio Init:");
if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
{
Con::printf(" Unable to initialize CD Audio: %s", SDL_GetError());
return;
}
S32 numDrives = SDL_CDNumDrives();
if (numDrives == 0)
{
Con::printf(" No drives found.");
return;
}
for (int i = 0; i < numDrives; ++i)
{
const char * deviceName = SDL_CDName(i);
Con::printf(" Installing CD Audio device: %s", deviceName);
UnixRedBookDevice * device = new UnixRedBookDevice;
device->setDeviceInfo(i, deviceName);
RedBook::installDevice(device);
}
Con::printf(" ");
#endif // !defined(__FreeBSD__)
}
//------------------------------------------------------------------------------
@ -455,4 +266,3 @@ void PollRedbookDevices()
}
#endif // !defined(__FreeBSD__)
}
#endif

View file

@ -67,13 +67,13 @@ class x86UNIXPlatformState
// loop runs in a separate thread. If you need the display pointer,
// use the DisplayPtrManager class. See the clipboard functions in
// x86unixinput.cc for an example.
Display *getDisplayPointer() { return mDisplay; }
//Display *getDisplayPointer() { return mDisplay; }
public:
U32 currentTime;
void setDisplayPointer( Display *displayPointer )
{ mDisplay = displayPointer; }
void setDisplayPointer( Display *displayPointer ) { mDisplay = displayPointer; }
Display* getDisplayPointer() { return mDisplay; }
void setScreenNumber( int newNumber ) { mScreenNumber = newNumber; }
int getScreenNumber() { return mScreenNumber; }

View file

@ -36,6 +36,7 @@
class StdConsole
{
bool stdConsoleEnabled;
bool stdConsoleInputEnabled;
// true if we're running in the background
bool inBackground;
@ -61,6 +62,7 @@ public:
virtual ~StdConsole();
void process();
void enable(bool);
void enableInput(bool enabled);
void processConsoleLine(const char *consoleLine);
static void create();
static void destroy();

View file

@ -27,9 +27,9 @@
#include <stdlib.h>
char *stristr(char *szStringToBeSearched, const char *szSubstringToSearchFor)
const char *stristr(const char *szStringToBeSearched, const char *szSubstringToSearchFor)
{
char *pPos = NULL;
const char *pPos = NULL;
char *szCopy1 = NULL;
char *szCopy2 = NULL;
@ -55,7 +55,7 @@ char *stristr(char *szStringToBeSearched, const char *szSubstringToSearchFor)
return NULL;
}
pPos = strstr(szCopy1, szCopy2);
pPos = strstr((const char*)szCopy1, (const char*)szCopy2);
if ( pPos != NULL ) {
// map to the original string

View file

@ -1,859 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "console/console.h"
#include "core/fileStream.h"
#include "game/resource.h"
#include "game/version.h"
#include "math/mRandom.h"
#include "platformX86UNIX/platformX86UNIX.h"
#include "platformX86UNIX/x86UNIXStdConsole.h"
#include "platform/event.h"
#include "platform/gameInterface.h"
#include "platform/platform.h"
#include "platform/platformAL.h"
#include "platform/platformInput.h"
#include "platform/platformVideo.h"
#include "platform/profiler.h"
#include "platformX86UNIX/platformGL.h"
#include "platformX86UNIX/x86UNIXOGLVideo.h"
#include "platformX86UNIX/x86UNIXState.h"
#ifndef TORQUE_DEDICATED
#include "platformX86UNIX/x86UNIXMessageBox.h"
#include "platformX86UNIX/x86UNIXInputManager.h"
#endif
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h> // fork, execvp, chdir
#include <time.h> // nanosleep
#ifndef TORQUE_DEDICATED
#include <X11/Xlib.h>
#include <X11/Xos.h>
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
#include <SDL/SDL_version.h>
#endif
x86UNIXPlatformState *x86UNIXState;
bool DisplayPtrManager::sgDisplayLocked = false;
LockFunc_t DisplayPtrManager::sgLockFunc = NULL;
LockFunc_t DisplayPtrManager::sgUnlockFunc = NULL;
static U32 lastTimeTick;
static MRandomLCG sgPlatRandom;
#ifndef TORQUE_DEDICATED
extern void InstallRedBookDevices();
extern void PollRedbookDevices();
extern bool InitOpenGL();
// This is called when some X client sends
// a selection event (e.g. SelectionRequest)
// to the window
extern void NotifySelectionEvent(XEvent& event);
#endif
//------------------------------------------------------------------------------
static S32 ParseCommandLine(S32 argc, const char **argv,
Vector<char*>& newCommandLine)
{
x86UNIXState->setExePathName(argv[0]);
bool foundDedicated = false;
for ( int i=0; i < argc; i++ )
{
// look for platform specific args
if (dStrcmp(argv[i], "-version") == 0)
{
dPrintf("%s (built on %s)\n", getVersionString(), getCompileTimeString());
dPrintf("gcc: %s\n", __VERSION__);
return 1;
}
if (dStrcmp(argv[i], "-cdaudio") == 0)
{
x86UNIXState->setCDAudioEnabled(true);
continue;
}
if (dStrcmp(argv[i], "-dedicated") == 0)
{
foundDedicated = true;
// no continue because dedicated is also handled by script
}
if (dStrcmp(argv[i], "-dsleep") == 0)
{
x86UNIXState->setDSleep(true);
continue;
}
if (dStrcmp(argv[i], "-nohomedir") == 0)
{
x86UNIXState->setUseRedirect(false);
continue;
}
if (dStrcmp(argv[i], "-chdir") == 0)
{
if ( ++i >= argc )
{
dPrintf("Follow -chdir option with the desired working directory.\n");
return 1;
}
if (chdir(argv[i]) == -1)
{
dPrintf("Unable to chdir to %s: %s\n", argv[i], strerror(errno));
return 1;
}
continue;
}
// copy the arg into newCommandLine
int argLen = dStrlen(argv[i]) + 1;
char* argBuf = new char[argLen]; // this memory is deleted in main()
dStrncpy(argBuf, argv[i], argLen);
newCommandLine.push_back(argBuf);
}
x86UNIXState->setDedicated(foundDedicated);
#if defined(DEDICATED) && !defined(TORQUE_ENGINE)
if (!foundDedicated)
{
dPrintf("This is a dedicated server build. You must supply the -dedicated command line parameter.\n");
return 1;
}
#endif
return 0;
}
static void DetectWindowingSystem()
{
#ifndef TORQUE_DEDICATED
Display* dpy = XOpenDisplay(NULL);
if (dpy != NULL)
{
x86UNIXState->setXWindowsRunning(true);
XCloseDisplay(dpy);
}
#endif
}
//------------------------------------------------------------------------------
static void InitWindow(const Point2I &initialSize, const char *name)
{
x86UNIXState->setWindowSize(initialSize);
x86UNIXState->setWindowName(name);
}
#ifndef TORQUE_DEDICATED
//------------------------------------------------------------------------------
static bool InitSDL()
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
return false;
atexit(SDL_Quit);
SDL_SysWMinfo sysinfo;
SDL_VERSION(&sysinfo.version);
if (SDL_GetWMInfo(&sysinfo) == 0)
return false;
x86UNIXState->setDisplayPointer(sysinfo.info.x11.display);
DisplayPtrManager::setDisplayLockFunction(sysinfo.info.x11.lock_func);
DisplayPtrManager::setDisplayUnlockFunction(sysinfo.info.x11.unlock_func);
DisplayPtrManager xdisplay;
Display* display = xdisplay.getDisplayPointer();
x86UNIXState->setScreenNumber(
DefaultScreen( display ) );
x86UNIXState->setScreenPointer(
DefaultScreenOfDisplay( display ) );
x86UNIXState->setDesktopSize(
(S32) DisplayWidth(
display,
x86UNIXState->getScreenNumber()),
(S32) DisplayHeight(
display,
x86UNIXState->getScreenNumber())
);
x86UNIXState->setDesktopBpp(
(S32) DefaultDepth(
display,
x86UNIXState->getScreenNumber()));
// indicate that we want sys WM messages
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
return true;
}
//------------------------------------------------------------------------------
static void ProcessSYSWMEvent(const SDL_Event& event)
{
XEvent& xevent = event.syswm.msg->event.xevent;
//Con::printf("xevent : %d", xevent.type);
switch (xevent.type)
{
case SelectionRequest:
// somebody wants our clipboard
NotifySelectionEvent(xevent);
break;
}
}
//------------------------------------------------------------------------------
static void SetAppState()
{
U8 state = SDL_GetAppState();
// if we're not active but we have appactive and inputfocus, set window
// active and reactivate input
if ((!x86UNIXState->windowActive() || !Input::isActive()) &&
state & SDL_APPACTIVE &&
state & SDL_APPINPUTFOCUS)
{
x86UNIXState->setWindowActive(true);
Input::reactivate();
}
// if we are active, but we don't have appactive or input focus,
// deactivate input (if window not locked) and clear windowActive
else if (x86UNIXState->windowActive() &&
!(state & SDL_APPACTIVE && state & SDL_APPINPUTFOCUS))
{
if (x86UNIXState->windowLocked())
Input::deactivate();
x86UNIXState->setWindowActive(false);
}
}
//------------------------------------------------------------------------------
static S32 NumEventsPending()
{
static const int MaxEvents = 255;
static SDL_Event events[MaxEvents];
SDL_PumpEvents();
return SDL_PeepEvents(events, MaxEvents, SDL_PEEKEVENT, SDL_ALLEVENTS);
}
//------------------------------------------------------------------------------
static void PrintSDLEventQueue()
{
static const int MaxEvents = 255;
static SDL_Event events[MaxEvents];
SDL_PumpEvents();
S32 numEvents = SDL_PeepEvents(
events, MaxEvents, SDL_PEEKEVENT, SDL_ALLEVENTS);
if (numEvents <= 0)
{
dPrintf("SDL Event Queue is empty\n");
return;
}
dPrintf("SDL Event Queue:\n");
for (int i = 0; i < numEvents; ++i)
{
const char *eventType;
switch (events[i].type)
{
case SDL_NOEVENT: eventType = "SDL_NOEVENT"; break;
case SDL_ACTIVEEVENT: eventType = "SDL_ACTIVEEVENT"; break;
case SDL_KEYDOWN: eventType = "SDL_KEYDOWN"; break;
case SDL_KEYUP: eventType = "SDL_KEYUP"; break;
case SDL_MOUSEMOTION: eventType = "SDL_MOUSEMOTION"; break;
case SDL_MOUSEBUTTONDOWN: eventType = "SDL_MOUSEBUTTONDOWN"; break;
case SDL_MOUSEBUTTONUP: eventType = "SDL_MOUSEBUTTONUP"; break;
case SDL_JOYAXISMOTION: eventType = "SDL_JOYAXISMOTION"; break;
case SDL_JOYBALLMOTION: eventType = "SDL_JOYBALLMOTION"; break;
case SDL_JOYHATMOTION: eventType = "SDL_JOYHATMOTION"; break;
case SDL_JOYBUTTONDOWN: eventType = "SDL_JOYBUTTONDOWN"; break;
case SDL_JOYBUTTONUP: eventType = "SDL_JOYBUTTONUP"; break;
case SDL_QUIT: eventType = "SDL_QUIT"; break;
case SDL_SYSWMEVENT: eventType = "SDL_SYSWMEVENT"; break;
case SDL_VIDEORESIZE: eventType = "SDL_VIDEORESIZE"; break;
case SDL_VIDEOEXPOSE: eventType = "SDL_VIDEOEXPOSE"; break;
/* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
case SDL_USEREVENT: eventType = "SDL_USEREVENT"; break;
default: eventType = "UNKNOWN!"; break;
}
dPrintf("Event %d: %s\n", i, eventType);
}
}
//------------------------------------------------------------------------------
static bool ProcessMessages()
{
static const int MaxEvents = 255;
static const U32 Mask =
SDL_QUITMASK | SDL_VIDEORESIZEMASK | SDL_VIDEOEXPOSEMASK |
SDL_ACTIVEEVENTMASK | SDL_SYSWMEVENTMASK |
SDL_EVENTMASK(SDL_USEREVENT);
static SDL_Event events[MaxEvents];
SDL_PumpEvents();
S32 numEvents = SDL_PeepEvents(events, MaxEvents, SDL_GETEVENT, Mask);
if (numEvents == 0)
return true;
for (int i = 0; i < numEvents; ++i)
{
SDL_Event& event = events[i];
switch (event.type)
{
case SDL_QUIT:
return false;
break;
case SDL_VIDEORESIZE:
case SDL_VIDEOEXPOSE:
Game->refreshWindow();
break;
case SDL_USEREVENT:
if (event.user.code == TORQUE_SETVIDEOMODE)
{
SetAppState();
// SDL will send a motion event to restore the mouse position
// on the new window. Ignore that if the window is locked.
if (x86UNIXState->windowLocked())
{
SDL_Event tempEvent;
SDL_PeepEvents(&tempEvent, 1, SDL_GETEVENT,
SDL_MOUSEMOTIONMASK);
}
}
break;
case SDL_ACTIVEEVENT:
SetAppState();
break;
case SDL_SYSWMEVENT:
ProcessSYSWMEvent(event);
break;
}
}
return true;
}
//------------------------------------------------------------------------------
// send a destroy window event to the window. assumes
// window is created.
void SendQuitEvent()
{
SDL_Event quitevent;
quitevent.type = SDL_QUIT;
SDL_PushEvent(&quitevent);
}
#endif // DEDICATED
//------------------------------------------------------------------------------
static inline void Sleep(int secs, int nanoSecs)
{
timespec sleeptime;
sleeptime.tv_sec = secs;
sleeptime.tv_nsec = nanoSecs;
nanosleep(&sleeptime, NULL);
}
#ifndef TORQUE_DEDICATED
struct AlertWinState
{
bool fullScreen;
bool cursorHidden;
bool inputGrabbed;
};
//------------------------------------------------------------------------------
void DisplayErrorAlert(const char* errMsg, bool showSDLError)
{
char fullErrMsg[2048];
dStrncpy(fullErrMsg, errMsg, sizeof(fullErrMsg));
if (showSDLError)
{
char* sdlerror = SDL_GetError();
if (sdlerror != NULL && dStrlen(sdlerror) > 0)
{
dStrcat(fullErrMsg, " (Error: ");
dStrcat(fullErrMsg, sdlerror);
dStrcat(fullErrMsg, ")");
}
}
Platform::AlertOK("Error", fullErrMsg);
}
//------------------------------------------------------------------------------
static inline void AlertDisableVideo(AlertWinState& state)
{
state.fullScreen = Video::isFullScreen();
state.cursorHidden = (SDL_ShowCursor(SDL_QUERY) == SDL_DISABLE);
state.inputGrabbed = (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON);
if (state.fullScreen)
SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
if (state.cursorHidden)
SDL_ShowCursor(SDL_ENABLE);
if (state.inputGrabbed)
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
//------------------------------------------------------------------------------
static inline void AlertEnableVideo(AlertWinState& state)
{
if (state.fullScreen)
SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
if (state.cursorHidden)
SDL_ShowCursor(SDL_DISABLE);
if (state.inputGrabbed)
SDL_WM_GrabInput(SDL_GRAB_ON);
}
#endif // DEDICATED
//------------------------------------------------------------------------------
void Platform::AlertOK(const char *windowTitle, const char *message)
{
#ifndef TORQUE_DEDICATED
if (x86UNIXState->isXWindowsRunning())
{
AlertWinState state;
AlertDisableVideo(state);
DisplayPtrManager xdisplay;
XMessageBox mBox(xdisplay.getDisplayPointer());
mBox.alertOK(windowTitle, message);
AlertEnableVideo(state);
}
else
#endif
{
if (Con::isActive() && StdConsole::isEnabled())
Con::printf("Alert: %s %s", windowTitle, message);
else
dPrintf("Alert: %s %s\n", windowTitle, message);
}
}
//------------------------------------------------------------------------------
bool Platform::AlertOKCancel(const char *windowTitle, const char *message)
{
#ifndef TORQUE_DEDICATED
if (x86UNIXState->isXWindowsRunning())
{
AlertWinState state;
AlertDisableVideo(state);
DisplayPtrManager xdisplay;
XMessageBox mBox(xdisplay.getDisplayPointer());
bool val =
mBox.alertOKCancel(windowTitle, message) == XMessageBox::OK;
AlertEnableVideo(state);
return val;
}
else
#endif
{
if (Con::isActive() && StdConsole::isEnabled())
Con::printf("Alert: %s %s", windowTitle, message);
else
dPrintf("Alert: %s %s\n", windowTitle, message);
return false;
}
}
//------------------------------------------------------------------------------
bool Platform::AlertRetry(const char *windowTitle, const char *message)
{
#ifndef TORQUE_DEDICATED
if (x86UNIXState->isXWindowsRunning())
{
AlertWinState state;
AlertDisableVideo(state);
DisplayPtrManager xdisplay;
XMessageBox mBox(xdisplay.getDisplayPointer());
bool val =
mBox.alertRetryCancel(windowTitle, message) == XMessageBox::Retry;
AlertEnableVideo(state);
return val;
}
else
#endif
{
if (Con::isActive() && StdConsole::isEnabled())
Con::printf("Alert: %s %s", windowTitle, message);
else
dPrintf("Alert: %s %s\n", windowTitle, message);
return false;
}
}
//------------------------------------------------------------------------------
bool Platform::excludeOtherInstances(const char *mutexName)
{
return AcquireProcessMutex(mutexName);
}
//------------------------------------------------------------------------------
void Platform::enableKeyboardTranslation(void)
{
#ifndef TORQUE_DEDICATED
// JMQ: not sure if this is needed for i18n keyboards
//SDL_EnableUNICODE( 1 );
// SDL_EnableKeyRepeat(
// SDL_DEFAULT_REPEAT_DELAY,
// SDL_DEFAULT_REPEAT_INTERVAL);
#endif
}
//------------------------------------------------------------------------------
void Platform::disableKeyboardTranslation(void)
{
#ifndef TORQUE_DEDICATED
//SDL_EnableUNICODE( 0 );
// SDL_EnableKeyRepeat(0, 0);
#endif
}
//------------------------------------------------------------------------------
void Platform::setWindowLocked(bool locked)
{
#ifndef TORQUE_DEDICATED
x86UNIXState->setWindowLocked(locked);
UInputManager* uInputManager =
dynamic_cast<UInputManager*>( Input::getManager() );
if ( uInputManager && uInputManager->isEnabled() &&
Input::isActive() )
uInputManager->setWindowLocked(locked);
#endif
}
//------------------------------------------------------------------------------
void Platform::minimizeWindow()
{
#ifndef TORQUE_DEDICATED
if (x86UNIXState->windowCreated())
SDL_WM_IconifyWindow();
#endif
}
//------------------------------------------------------------------------------
void Platform::process()
{
PROFILE_START(XUX_PlatformProcess);
stdConsole->process();
if (x86UNIXState->windowCreated())
{
#ifndef TORQUE_DEDICATED
// process window events
PROFILE_START(XUX_ProcessMessages);
bool quit = !ProcessMessages();
PROFILE_END();
if(quit)
{
// generate a quit event
Event quitEvent;
quitEvent.type = QuitEventType;
Game->postEvent(quitEvent);
}
// process input events
PROFILE_START(XUX_InputProcess);
Input::process();
PROFILE_END();
// poll redbook state
PROFILE_START(XUX_PollRedbookDevices);
PollRedbookDevices();
PROFILE_END();
// if we're not the foreground window, sleep for 1 ms
if (!x86UNIXState->windowActive())
Sleep(0, getBackgroundSleepTime() * 1000000);
#endif
}
else
{
// no window
// if we're not in journal mode, sleep for 1 ms
// JMQ: since linux's minimum sleep latency seems to be 20ms, this can
// increase player pings by 10-20ms in the dedicated server. So
// you have to use -dsleep to enable it. the server sleeps anyway when
// there are no players connected.
// JMQ: recent kernels (such as RH 8.0 2.4.18) reduce the latency
// to 2-4 ms on average.
if (!Game->isJournalReading() && (x86UNIXState->getDSleep() ||
Con::getIntVariable("Server::PlayerCount") -
Con::getIntVariable("Server::BotCount") <= 0))
{
PROFILE_START(XUX_Sleep);
Sleep(0, getBackgroundSleepTime() * 1000000);
PROFILE_END();
}
}
#ifndef TORQUE_DEDICATED
#if 0
// JMQ: disabled this because it may fire mistakenly in some configurations.
// sdl's default event handling scheme should be enough.
// crude check to make sure that we're not loading up events. the sdl
// event queue should never have more than (say) 25 events in it at this
// point
const int MaxEvents = 25;
if (NumEventsPending() > MaxEvents)
{
PrintSDLEventQueue();
AssertFatal(false, "The SDL event queue has too many events!");
}
#endif
#endif
PROFILE_END();
}
// extern U32 calculateCRC(void * buffer, S32 len, U32 crcVal );
// #if defined(DEBUG) || defined(INTERNAL_RELEASE)
// static U32 stubCRC = 0;
// #else
// static U32 stubCRC = 0xEA63F56C;
// #endif
//------------------------------------------------------------------------------
const Point2I &Platform::getWindowSize()
{
return x86UNIXState->getWindowSize();
}
//------------------------------------------------------------------------------
void Platform::setWindowSize( U32 newWidth, U32 newHeight )
{
x86UNIXState->setWindowSize( (S32) newWidth, (S32) newHeight );
}
//------------------------------------------------------------------------------
void Platform::initWindow(const Point2I &initialSize, const char *name)
{
#ifndef TORQUE_DEDICATED
// initialize window
InitWindow(initialSize, name);
if (!InitOpenGL())
ImmediateShutdown(1);
#endif
}
//------------------------------------------------------------------------------
// Web browser function:
//------------------------------------------------------------------------------
bool Platform::openWebBrowser( const char* webAddress )
{
if (!webAddress || dStrlen(webAddress)==0)
return false;
// look for a browser preference variable
// JMQTODO: be nice to implement some UI to customize this
const char* webBrowser = Con::getVariable("Pref::Unix::WebBrowser");
if (dStrlen(webBrowser) == 0)
webBrowser = NULL;
pid_t pid = fork();
if (pid == -1)
{
Con::printf("WARNING: Platform::openWebBrowser failed to fork");
return false;
}
else if (pid != 0)
{
// parent
if (Video::isFullScreen())
Video::toggleFullScreen();
return true;
}
else if (pid == 0)
{
// child
// try to exec konqueror, then netscape
char* argv[3];
argv[0] = "";
argv[1] = const_cast<char*>(webAddress);
argv[2] = 0;
int ok = -1;
// if execvp returns, it means it couldn't execute the program
if (webBrowser != NULL)
ok = execvp(webBrowser, argv);
ok = execvp("konqueror", argv);
ok = execvp("mozilla", argv);
ok = execvp("netscape", argv);
// use dPrintf instead of Con here since we're now in another process,
dPrintf("WARNING: Platform::openWebBrowser: couldn't launch a web browser\n");
_exit(-1);
return false;
}
else
{
Con::printf("WARNING: Platform::openWebBrowser: forking problem");
return false;
}
}
//------------------------------------------------------------------------------
// Login password routines:
//------------------------------------------------------------------------------
const char* Platform::getLoginPassword()
{
Con::printf("WARNING: Platform::getLoginPassword() is unimplemented");
return "";
}
//------------------------------------------------------------------------------
bool Platform::setLoginPassword( const char* password )
{
Con::printf("WARNING: Platform::setLoginPassword is unimplemented");
return false;
}
//-------------------------------------------------------------------------------
void TimeManager::process()
{
U32 curTime = Platform::getRealMilliseconds();
TimeEvent event;
event.elapsedTime = curTime - lastTimeTick;
if(event.elapsedTime > sgTimeManagerProcessInterval)
{
lastTimeTick = curTime;
Game->postEvent(event);
}
}
//------------------------------------------------------------------------------
ConsoleFunction( getDesktopResolution, const char*, 1, 1,
"getDesktopResolution()" )
{
if (!x86UNIXState->windowCreated())
return "0 0 0";
char buffer[256];
char* returnString = Con::getReturnBuffer( dStrlen( buffer ) + 1 );
dSprintf( buffer, sizeof( buffer ), "%d %d %d",
x86UNIXState->getDesktopSize().x,
x86UNIXState->getDesktopSize().y,
x86UNIXState->getDesktopBpp() );
dStrcpy( returnString, buffer );
return( returnString );
}
//------------------------------------------------------------------------------
// Silly Korean registry key checker:
//------------------------------------------------------------------------------
ConsoleFunction( isKoreanBuild, bool, 1, 1, "isKoreanBuild()" )
{
Con::printf("WARNING: isKoreanBuild() is unimplemented");
return false;
}
//------------------------------------------------------------------------------
int main(S32 argc, const char **argv)
{
// init platform state
x86UNIXState = new x86UNIXPlatformState;
// parse the command line for unix-specific params
Vector<char *> newCommandLine;
S32 returnVal = ParseCommandLine(argc, argv, newCommandLine);
if (returnVal != 0)
return returnVal;
// init lastTimeTick for TimeManager::process()
lastTimeTick = Platform::getRealMilliseconds();
// init process control stuff
ProcessControlInit();
// check to see if X is running
DetectWindowingSystem();
// run the game
returnVal = Game->main(newCommandLine.size(),
const_cast<const char**>(newCommandLine.address()));
// dispose of command line
for(U32 i = 0; i < newCommandLine.size(); i++)
delete [] newCommandLine[i];
// dispose of state
delete x86UNIXState;
return returnVal;
}
void Platform::setWindowTitle( const char* title )
{
#ifndef TORQUE_DEDICATED
x86UNIXState->setWindowName(title);
SDL_WM_SetCaption(x86UNIXState->getWindowName(), NULL);
#endif
}
Resolution Video::getDesktopResolution()
{
Resolution Result;
Result.h = x86UNIXState->getDesktopSize().x;
Result.w = x86UNIXState->getDesktopSize().y;
Result.bpp = x86UNIXState->getDesktopBpp();
return Result;
}
//-----------------------------------------------------------------------------
void Platform::restartInstance()
{
if (Game->isRunning() )
{
//Con::errorf( "Error restarting Instance. Game is Still running!");
return;
}
char cmd[2048];
sprintf(cmd, "%s &", x86UNIXState->getExePathName());
system(cmd);
exit(0);
}

View file

@ -0,0 +1,459 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// TODO: Implement OpenAL loading code which is currently stubbed out.
#if defined(__linux__) && !defined(TORQUE_OS_LINUX)
#define TORQUE_OS_LINUX
#endif
#include <dlfcn.h>
#include <err.h>
#include <string.h>
#include "sfx/openal/LoadOAL.h"
#include "console/console.h"
void* openal_library = NULL;
ALboolean LoadOAL10Library(char *szOALFullPathName, LPOPENALFNTABLE lpOALFnTable)
{
if (!lpOALFnTable)
return AL_FALSE;
if (szOALFullPathName)
openal_library = dlopen(szOALFullPathName, RTLD_LAZY);
else
openal_library = dlopen("libopenal.so", RTLD_LAZY);
if (openal_library == NULL) {
Con::errorf("Failed to load OpenAL shared library. Sound will not be available");
return AL_FALSE;
}
memset(lpOALFnTable, 0, sizeof(OPENALFNTABLE));
lpOALFnTable->alEnable = (LPALENABLE)dlsym(openal_library,"alEnable");
if (lpOALFnTable->alEnable == NULL)
{
warn("Failed to retrieve 'alEnable' function address\n");
return AL_FALSE;
}
lpOALFnTable->alDisable = (LPALDISABLE)dlsym(openal_library,"alDisable");
if (lpOALFnTable->alDisable == NULL)
{
warn("Failed to retrieve 'alDisable' function address\n");
return AL_FALSE;
}
lpOALFnTable->alIsEnabled = (LPALISENABLED)dlsym(openal_library,"alIsEnabled");
if (lpOALFnTable->alIsEnabled == NULL)
{
warn("Failed to retrieve 'alIsEnabled' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetBoolean = (LPALGETBOOLEAN)dlsym(openal_library,"alGetBoolean");
if (lpOALFnTable->alGetBoolean == NULL)
{
warn("Failed to retrieve 'alGetBoolean' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetInteger = (LPALGETINTEGER)dlsym(openal_library,"alGetInteger");
if (lpOALFnTable->alGetInteger == NULL)
{
warn("Failed to retrieve 'alGetInteger' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetFloat = (LPALGETFLOAT)dlsym(openal_library,"alGetFloat");
if (lpOALFnTable->alGetFloat == NULL)
{
warn("Failed to retrieve 'alGetFloat' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetDouble = (LPALGETDOUBLE)dlsym(openal_library,"alGetDouble");
if (lpOALFnTable->alGetDouble == NULL)
{
warn("Failed to retrieve 'alGetDouble' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetBooleanv = (LPALGETBOOLEANV)dlsym(openal_library,"alGetBooleanv");
if (lpOALFnTable->alGetBooleanv == NULL)
{
warn("Failed to retrieve 'alGetBooleanv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetIntegerv = (LPALGETINTEGERV)dlsym(openal_library,"alGetIntegerv");
if (lpOALFnTable->alGetIntegerv == NULL)
{
warn("Failed to retrieve 'alGetIntegerv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetFloatv = (LPALGETFLOATV)dlsym(openal_library,"alGetFloatv");
if (lpOALFnTable->alGetFloatv == NULL)
{
warn("Failed to retrieve 'alGetFloatv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetDoublev = (LPALGETDOUBLEV)dlsym(openal_library,"alGetDoublev");
if (lpOALFnTable->alGetDoublev == NULL)
{
warn("Failed to retrieve 'alGetDoublev' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetString = (LPALGETSTRING)dlsym(openal_library,"alGetString");
if (lpOALFnTable->alGetString == NULL)
{
warn("Failed to retrieve 'alGetString' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetError = (LPALGETERROR)dlsym(openal_library,"alGetError");
if (lpOALFnTable->alGetError == NULL)
{
warn("Failed to retrieve 'alGetError' function address\n");
return AL_FALSE;
}
lpOALFnTable->alIsExtensionPresent = (LPALISEXTENSIONPRESENT)dlsym(openal_library,"alIsExtensionPresent");
if (lpOALFnTable->alIsExtensionPresent == NULL)
{
warn("Failed to retrieve 'alIsExtensionPresent' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetProcAddress = (LPALGETPROCADDRESS)dlsym(openal_library,"alGetProcAddress");
if (lpOALFnTable->alGetProcAddress == NULL)
{
warn("Failed to retrieve 'alGetProcAddress' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetEnumValue = (LPALGETENUMVALUE)dlsym(openal_library,"alGetEnumValue");
if (lpOALFnTable->alGetEnumValue == NULL)
{
warn("Failed to retrieve 'alGetEnumValue' function address\n");
return AL_FALSE;
}
lpOALFnTable->alListeneri = (LPALLISTENERI)dlsym(openal_library,"alListeneri");
if (lpOALFnTable->alListeneri == NULL)
{
warn("Failed to retrieve 'alListeneri' function address\n");
return AL_FALSE;
}
lpOALFnTable->alListenerf = (LPALLISTENERF)dlsym(openal_library,"alListenerf");
if (lpOALFnTable->alListenerf == NULL)
{
warn("Failed to retrieve 'alListenerf' function address\n");
return AL_FALSE;
}
lpOALFnTable->alListener3f = (LPALLISTENER3F)dlsym(openal_library,"alListener3f");
if (lpOALFnTable->alListener3f == NULL)
{
warn("Failed to retrieve 'alListener3f' function address\n");
return AL_FALSE;
}
lpOALFnTable->alListenerfv = (LPALLISTENERFV)dlsym(openal_library,"alListenerfv");
if (lpOALFnTable->alListenerfv == NULL)
{
warn("Failed to retrieve 'alListenerfv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetListeneri = (LPALGETLISTENERI)dlsym(openal_library,"alGetListeneri");
if (lpOALFnTable->alGetListeneri == NULL)
{
warn("Failed to retrieve 'alGetListeneri' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetListenerf =(LPALGETLISTENERF)dlsym(openal_library,"alGetListenerf");
if (lpOALFnTable->alGetListenerf == NULL)
{
warn("Failed to retrieve 'alGetListenerf' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetListener3f = (LPALGETLISTENER3F)dlsym(openal_library,"alGetListener3f");
if (lpOALFnTable->alGetListener3f == NULL)
{
warn("Failed to retrieve 'alGetListener3f' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetListenerfv = (LPALGETLISTENERFV)dlsym(openal_library,"alGetListenerfv");
if (lpOALFnTable->alGetListenerfv == NULL)
{
warn("Failed to retrieve 'alGetListenerfv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGenSources = (LPALGENSOURCES)dlsym(openal_library,"alGenSources");
if (lpOALFnTable->alGenSources == NULL)
{
warn("Failed to retrieve 'alGenSources' function address\n");
return AL_FALSE;
}
lpOALFnTable->alDeleteSources = (LPALDELETESOURCES)dlsym(openal_library,"alDeleteSources");
if (lpOALFnTable->alDeleteSources == NULL)
{
warn("Failed to retrieve 'alDeleteSources' function address\n");
return AL_FALSE;
}
lpOALFnTable->alIsSource = (LPALISSOURCE)dlsym(openal_library,"alIsSource");
if (lpOALFnTable->alIsSource == NULL)
{
warn("Failed to retrieve 'alIsSource' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourcei = (LPALSOURCEI)dlsym(openal_library,"alSourcei");
if (lpOALFnTable->alSourcei == NULL)
{
warn("Failed to retrieve 'alSourcei' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourcef = (LPALSOURCEF)dlsym(openal_library,"alSourcef");
if (lpOALFnTable->alSourcef == NULL)
{
warn("Failed to retrieve 'alSourcef' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSource3f = (LPALSOURCE3F)dlsym(openal_library,"alSource3f");
if (lpOALFnTable->alSource3f == NULL)
{
warn("Failed to retrieve 'alSource3f' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourcefv = (LPALSOURCEFV)dlsym(openal_library,"alSourcefv");
if (lpOALFnTable->alSourcefv == NULL)
{
warn("Failed to retrieve 'alSourcefv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetSourcei = (LPALGETSOURCEI)dlsym(openal_library,"alGetSourcei");
if (lpOALFnTable->alGetSourcei == NULL)
{
warn("Failed to retrieve 'alGetSourcei' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetSourcef = (LPALGETSOURCEF)dlsym(openal_library,"alGetSourcef");
if (lpOALFnTable->alGetSourcef == NULL)
{
warn("Failed to retrieve 'alGetSourcef' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetSourcefv = (LPALGETSOURCEFV)dlsym(openal_library,"alGetSourcefv");
if (lpOALFnTable->alGetSourcefv == NULL)
{
warn("Failed to retrieve 'alGetSourcefv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourcePlayv = (LPALSOURCEPLAYV)dlsym(openal_library,"alSourcePlayv");
if (lpOALFnTable->alSourcePlayv == NULL)
{
warn("Failed to retrieve 'alSourcePlayv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourceStopv = (LPALSOURCESTOPV)dlsym(openal_library,"alSourceStopv");
if (lpOALFnTable->alSourceStopv == NULL)
{
warn("Failed to retrieve 'alSourceStopv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourcePlay = (LPALSOURCEPLAY)dlsym(openal_library,"alSourcePlay");
if (lpOALFnTable->alSourcePlay == NULL)
{
warn("Failed to retrieve 'alSourcePlay' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourcePause = (LPALSOURCEPAUSE)dlsym(openal_library,"alSourcePause");
if (lpOALFnTable->alSourcePause == NULL)
{
warn("Failed to retrieve 'alSourcePause' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourceStop = (LPALSOURCESTOP)dlsym(openal_library,"alSourceStop");
if (lpOALFnTable->alSourceStop == NULL)
{
warn("Failed to retrieve 'alSourceStop' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourceRewind = (LPALSOURCEREWIND)dlsym(openal_library,"alSourceRewind");
if (lpOALFnTable->alSourceRewind == NULL)
{
warn("Failed to retrieve 'alSourceRewind' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGenBuffers = (LPALGENBUFFERS)dlsym(openal_library,"alGenBuffers");
if (lpOALFnTable->alGenBuffers == NULL)
{
warn("Failed to retrieve 'alGenBuffers' function address\n");
return AL_FALSE;
}
lpOALFnTable->alDeleteBuffers = (LPALDELETEBUFFERS)dlsym(openal_library,"alDeleteBuffers");
if (lpOALFnTable->alDeleteBuffers == NULL)
{
warn("Failed to retrieve 'alDeleteBuffers' function address\n");
return AL_FALSE;
}
lpOALFnTable->alIsBuffer = (LPALISBUFFER)dlsym(openal_library,"alIsBuffer");
if (lpOALFnTable->alIsBuffer == NULL)
{
warn("Failed to retrieve 'alIsBuffer' function address\n");
return AL_FALSE;
}
lpOALFnTable->alBufferData = (LPALBUFFERDATA)dlsym(openal_library,"alBufferData");
if (lpOALFnTable->alBufferData == NULL)
{
warn("Failed to retrieve 'alBufferData' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetBufferi = (LPALGETBUFFERI)dlsym(openal_library,"alGetBufferi");
if (lpOALFnTable->alGetBufferi == NULL)
{
warn("Failed to retrieve 'alGetBufferi' function address\n");
return AL_FALSE;
}
lpOALFnTable->alGetBufferf = (LPALGETBUFFERF)dlsym(openal_library,"alGetBufferf");
if (lpOALFnTable->alGetBufferf == NULL)
{
warn("Failed to retrieve 'alGetBufferf' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourceQueueBuffers = (LPALSOURCEQUEUEBUFFERS)dlsym(openal_library,"alSourceQueueBuffers");
if (lpOALFnTable->alSourceQueueBuffers == NULL)
{
warn("Failed to retrieve 'alSourceQueueBuffers' function address\n");
return AL_FALSE;
}
lpOALFnTable->alSourceUnqueueBuffers = (LPALSOURCEUNQUEUEBUFFERS)dlsym(openal_library,"alSourceUnqueueBuffers");
if (lpOALFnTable->alSourceUnqueueBuffers == NULL)
{
warn("Failed to retrieve 'alSourceUnqueueBuffers' function address\n");
return AL_FALSE;
}
lpOALFnTable->alDistanceModel = (LPALDISTANCEMODEL)dlsym(openal_library,"alDistanceModel");
if (lpOALFnTable->alDistanceModel == NULL)
{
warn("Failed to retrieve 'alDistanceModel' function address\n");
return AL_FALSE;
}
lpOALFnTable->alDopplerFactor = (LPALDOPPLERFACTOR)dlsym(openal_library,"alDopplerFactor");
if (lpOALFnTable->alDopplerFactor == NULL)
{
warn("Failed to retrieve 'alDopplerFactor' function address\n");
return AL_FALSE;
}
lpOALFnTable->alDopplerVelocity = (LPALDOPPLERVELOCITY)dlsym(openal_library,"alDopplerVelocity");
if (lpOALFnTable->alDopplerVelocity == NULL)
{
warn("Failed to retrieve 'alDopplerVelocity' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcGetString = (LPALCGETSTRING)dlsym(openal_library,"alcGetString");
if (lpOALFnTable->alcGetString == NULL)
{
warn("Failed to retrieve 'alcGetString' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcGetIntegerv = (LPALCGETINTEGERV)dlsym(openal_library,"alcGetIntegerv");
if (lpOALFnTable->alcGetIntegerv == NULL)
{
warn("Failed to retrieve 'alcGetIntegerv' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcOpenDevice = (LPALCOPENDEVICE)dlsym(openal_library,"alcOpenDevice");
if (lpOALFnTable->alcOpenDevice == NULL)
{
warn("Failed to retrieve 'alcOpenDevice' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcCloseDevice = (LPALCCLOSEDEVICE)dlsym(openal_library,"alcCloseDevice");
if (lpOALFnTable->alcCloseDevice == NULL)
{
warn("Failed to retrieve 'alcCloseDevice' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcCreateContext = (LPALCCREATECONTEXT)dlsym(openal_library,"alcCreateContext");
if (lpOALFnTable->alcCreateContext == NULL)
{
warn("Failed to retrieve 'alcCreateContext' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcMakeContextCurrent = (LPALCMAKECONTEXTCURRENT)dlsym(openal_library,"alcMakeContextCurrent");
if (lpOALFnTable->alcMakeContextCurrent == NULL)
{
warn("Failed to retrieve 'alcMakeContextCurrent' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcProcessContext = (LPALCPROCESSCONTEXT)dlsym(openal_library,"alcProcessContext");
if (lpOALFnTable->alcProcessContext == NULL)
{
warn("Failed to retrieve 'alcProcessContext' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcGetCurrentContext = (LPALCGETCURRENTCONTEXT)dlsym(openal_library,"alcGetCurrentContext");
if (lpOALFnTable->alcGetCurrentContext == NULL)
{
warn("Failed to retrieve 'alcGetCurrentContext' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcGetContextsDevice = (LPALCGETCONTEXTSDEVICE)dlsym(openal_library,"alcGetContextsDevice");
if (lpOALFnTable->alcGetContextsDevice == NULL)
{
warn("Failed to retrieve 'alcGetContextsDevice' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcSuspendContext = (LPALCSUSPENDCONTEXT)dlsym(openal_library,"alcSuspendContext");
if (lpOALFnTable->alcSuspendContext == NULL)
{
warn("Failed to retrieve 'alcSuspendContext' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcDestroyContext = (LPALCDESTROYCONTEXT)dlsym(openal_library,"alcDestroyContext");
if (lpOALFnTable->alcDestroyContext == NULL)
{
warn("Failed to retrieve 'alcDestroyContext' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcGetError = (LPALCGETERROR)dlsym(openal_library,"alcGetError");
if (lpOALFnTable->alcGetError == NULL)
{
warn("Failed to retrieve 'alcGetError' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcIsExtensionPresent = (LPALCISEXTENSIONPRESENT)dlsym(openal_library,"alcIsExtensionPresent");
if (lpOALFnTable->alcIsExtensionPresent == NULL)
{
warn("Failed to retrieve 'alcIsExtensionPresent' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcGetProcAddress = (LPALCGETPROCADDRESS)dlsym(openal_library,"alcGetProcAddress");
if (lpOALFnTable->alcGetProcAddress == NULL)
{
warn("Failed to retrieve 'alcGetProcAddress' function address\n");
return AL_FALSE;
}
lpOALFnTable->alcGetEnumValue = (LPALCGETENUMVALUE)dlsym(openal_library,"alcGetEnumValue");
if (lpOALFnTable->alcGetEnumValue == NULL)
{
warn("Failed to retrieve 'alcGetEnumValue' function address\n");
return AL_FALSE;
}
return AL_TRUE;
}
ALvoid UnloadOAL10Library()
{
if (openal_library != NULL)
dlclose(openal_library);
}

View file

@ -59,7 +59,7 @@ inline void sRead( BitStream* stream, T** ptr )
{
StringTableEntry name = stream->readSTString();
AssertFatal( !( U32( name ) & 0x1 ), "sRead - misaligned pointer" ); // StringTableEntry pointers are always word-aligned.
AssertFatal( !( uintptr_t( name ) & 0x1 ), "sRead - misaligned pointer" ); // StringTableEntry pointers are always word-aligned.
*( ( StringTableEntry* ) ptr ) = name;
}

View file

@ -382,7 +382,7 @@ void TSShapeLoader::generateSubshapes()
bool cmpMeshNameAndSize(const String& key, const Vector<String>& names, void* arg1, void* arg2)
{
const Vector<AppMesh*>& meshes = *(Vector<AppMesh*>*)arg1;
S32 meshSize = (S32)arg2;
S32 meshSize = (intptr_t)arg2;
for (S32 i = 0; i < names.size(); i++)
{

View file

@ -206,7 +206,7 @@ void TSMesh::innerRender( TSMaterialList *materials, const TSRenderState &rdata,
coreRI->vertBuff = &vb;
coreRI->primBuff = &pb;
coreRI->defaultKey2 = (U32) coreRI->vertBuff;
coreRI->defaultKey2 = (uintptr_t) coreRI->vertBuff;
coreRI->materialHint = rdata.getMaterialHint();

View file

@ -1171,7 +1171,7 @@ void TSShape::assembleShape()
TSMesh * mesh = TSMesh::assembleMesh(meshType,skip);
if (ptr32)
{
ptr32[i] = skip ? 0 : (S32)mesh;
ptr32[i] = skip ? 0 : (intptr_t)mesh; // @todo 64bit
meshes.push_back(skip ? 0 : mesh);
}

View file

@ -69,7 +69,8 @@ macro(addPath dir)
${dir}/*.c
${dir}/*.cc
${dir}/*.h
${dir}/*.asm)
#${dir}/*.asm
)
LIST(APPEND ${PROJECT_NAME}_files "${tmp_files}")
LIST(APPEND ${PROJECT_NAME}_paths "${dir}")
#message(STATUS "addPath ${PROJECT_NAME} : ${tmp_files}")

View file

@ -23,10 +23,13 @@
project(${TORQUE_APP_NAME})
if(UNIX)
set(CXX_FLAG32 "")
#set(CXX_FLAG32 "-m32") #uncomment for build x32 on OSx64
# default compiler flags
# force compile 32 bit
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -Wall -Wundef -msse -pipe -Wfatal-errors ${TORQUE_ADDITIONAL_LINKER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32 -Wall -Wundef -msse -pipe -Wfatal-errors ${TORQUE_ADDITIONAL_LINKER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAG32} -Wall -Wundef -msse -pipe -Wfatal-errors ${TORQUE_ADDITIONAL_LINKER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CXX_FLAG32} -Wall -Wundef -msse -pipe -Wfatal-errors ${TORQUE_ADDITIONAL_LINKER_FLAGS}")
# for asm files
SET (CMAKE_ASM_NASM_OBJECT_FORMAT "elf")
@ -165,6 +168,20 @@ if(WIN32)
endif()
endif()
# build types
if(NOT MSVC) # handle single-configuration generator
set(CMAKE_BUILD_TYPE ${TORQUE_BUILD_TYPE})
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(TORQUE_DEBUG TRUE)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(TORQUE_RELEASE TRUE)
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(TORQUE_RELEASE TRUE)
else()
message(FATAL_ERROR "Please select Debug, Release or RelWithDebInfo for TORQUE_BUILD_TYPE")
endif()
endif()
###############################################################################
# Always enabled paths first
###############################################################################
@ -353,12 +370,12 @@ if(TORQUE_SDL)
endif()
if(UNIX)
set(CMAKE_SIZEOF_VOID_P 4) #force 32 bit
set(ENV{CFLAGS} "-m32 -g -O3")
#set(CMAKE_SIZEOF_VOID_P 4) #force 32 bit
set(ENV{CFLAGS} "${CXX_FLAG32} -g -O3")
if("${TORQUE_ADDITIONAL_LINKER_FLAGS}" STREQUAL "")
set(ENV{LDFLAGS} "-m32")
set(ENV{LDFLAGS} "${CXX_FLAG32}")
else()
set(ENV{LDFLAGS} "-m32 ${TORQUE_ADDITIONAL_LINKER_FLAGS}")
set(ENV{LDFLAGS} "${CXX_FLAG32} ${TORQUE_ADDITIONAL_LINKER_FLAGS}")
endif()
endif()
@ -455,6 +472,7 @@ if(PS3)
endif()
if(UNIX)
# linux_dedicated
if(TORQUE_DEDICATED)
addPath("${srcDir}/windowManager/dedicated")
# ${srcDir}/platformX86UNIX/*.client.* files are not needed
@ -471,8 +489,9 @@ if(UNIX)
endforeach()
else()
addPath("${srcDir}/platformX86UNIX")
addPath("${srcDir}/platformX86UNIX/nativeDialogs")
endif()
# linux
addPath("${srcDir}/platformX86UNIX/threads")
addPath("${srcDir}/platformPOSIX")
endif()
@ -552,6 +571,15 @@ if(WIN32)
endif()
endif()
if(UNIX)
# copy pasted from T3D build system, some might not be needed
set(TORQUE_EXTERNAL_LIBS "dl Xxf86vm Xext X11 Xft stdc++ pthread GL" CACHE STRING "external libs to link against")
mark_as_advanced(TORQUE_EXTERNAL_LIBS)
string(REPLACE " " ";" TORQUE_EXTERNAL_LIBS_LIST ${TORQUE_EXTERNAL_LIBS})
addLib( "${TORQUE_EXTERNAL_LIBS_LIST}" )
endif()
if(UNIX)
# copy pasted from T3D build system, some might not be needed
set(TORQUE_EXTERNAL_LIBS "rt dl Xxf86vm Xext X11 Xft stdc++ pthread GL" CACHE STRING "external libs to link against")
@ -601,6 +629,10 @@ if(TORQUE_SDL)
addLib(SDL2)
endif()
if(TORQUE_STATIC_CODE_ANALYSIS)
addDef( "ON_FAIL_ASSERTFATAL=exit(1)" )
endif()
###############################################################################
# Include Paths
###############################################################################
@ -623,6 +655,15 @@ if(TORQUE_OPENGL)
addInclude("${libDir}/glew/include")
endif()
if(UNIX)
addInclude("/usr/include/freetype2/freetype")
addInclude("/usr/include/freetype2")
endif()
if(TORQUE_OPENGL)
addInclude("${libDir}/glew/include")
endif()
# external things
if(WIN32)
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INCLUDE_DIRECTORIES $ENV{DXSDK_DIR}/Include)