From 4e9034854d057f745f7449502cbad03a3fe8b76e Mon Sep 17 00:00:00 2001 From: LuisAntonRebollo Date: Sat, 24 Jan 2015 22:08:26 +0100 Subject: [PATCH] Linux implementation. Include changes for gcc x64. --- Engine/lib/opcode/OPC_HybridModel.cpp | 3 +- Engine/lib/opcode/OPC_SweepAndPrune.cpp | 5 +- Engine/source/T3D/cameraSpline.cpp | 2 +- Engine/source/T3D/convexShape.cpp | 2 +- Engine/source/T3D/debris.cpp | 2 +- .../source/T3D/examples/renderMeshExample.cpp | 2 +- Engine/source/T3D/fx/particleEmitter.cpp | 2 +- Engine/source/T3D/fx/ribbon.cpp | 2 +- Engine/source/T3D/lightFlareData.cpp | 2 +- Engine/source/T3D/shapeBase.cpp | 4 +- Engine/source/T3D/shapeImage.cpp | 10 +- Engine/source/T3D/tsStatic.cpp | 2 +- Engine/source/T3D/vehicles/flyingVehicle.cpp | 8 +- Engine/source/T3D/vehicles/hoverVehicle.cpp | 8 +- Engine/source/T3D/vehicles/vehicle.cpp | 4 +- Engine/source/T3D/vehicles/wheeledVehicle.cpp | 4 +- Engine/source/console/engineTypes.h | 2 +- Engine/source/core/util/tDictionary.h | 2 +- Engine/source/environment/meshRoad.cpp | 2 +- Engine/source/forest/editor/forestUndo.cpp | 6 +- Engine/source/gfx/gfxStringEnumTranslate.cpp | 4 +- Engine/source/gfx/gl/gfxGLVertexDecl.cpp | 2 +- Engine/source/gui/controls/guiListBoxCtrl.cpp | 8 +- Engine/source/math/util/matrixSet.cpp | 4 +- Engine/source/platform/types.h | 2 + Engine/source/platformMac/platformMacCarb.h | 2 +- .../platformWin32/winProcessControl.cpp | 3 +- .../nativeDialogs/fileDialog.cpp | 354 ++++ .../source/platformX86UNIX/platformX86UNIX.h | 2 +- .../platformX86UNIX/threads/semaphore.cpp | 46 +- .../source/platformX86UNIX/x86UNIXConsole.cpp | 10 + .../platformX86UNIX/x86UNIXDlibrary.cpp | 83 + .../platformX86UNIX/x86UNIXFont.client.cpp | 23 +- .../platformX86UNIX/x86UNIXGL.client.cpp | 3 +- .../platformX86UNIX/x86UNIXInput.client.cpp | 3 +- .../x86UNIXInputManager.client.cpp | 1835 ----------------- .../platformX86UNIX/x86UNIXInputManager.h | 6 +- Engine/source/platformX86UNIX/x86UNIXMain.cpp | 69 +- .../source/platformX86UNIX/x86UNIXMemory.cpp | 8 +- .../x86UNIXMessageBox.client.cpp | 14 +- .../platformX86UNIX/x86UNIXMessageBox.h | 2 + .../x86UNIXOGLVideo.client.cpp | 4 +- .../platformX86UNIX/x86UNIXOpenAL.client.cpp | 3 +- .../platformX86UNIX/x86UNIXProcessControl.cpp | 5 +- .../source/platformX86UNIX/x86UNIXRedbook.cpp | 216 +- Engine/source/platformX86UNIX/x86UNIXState.h | 6 +- .../platformX86UNIX/x86UNIXStdConsole.h | 2 + .../source/platformX86UNIX/x86UNIXStrings.cpp | 6 +- .../platformX86UNIX/x86UNIXWindow.client.cpp | 859 -------- .../source/sfx/openal/linux/LoadOAL.linux.cpp | 459 +++++ Engine/source/sfx/sfxTypes.cpp | 2 +- Engine/source/ts/loader/tsShapeLoader.cpp | 2 +- Engine/source/ts/tsMesh.cpp | 2 +- Engine/source/ts/tsShape.cpp | 2 +- Tools/CMake/basics.cmake | 3 +- Tools/CMake/torque3d.cmake | 55 +- 56 files changed, 1108 insertions(+), 3075 deletions(-) create mode 100644 Engine/source/platformX86UNIX/nativeDialogs/fileDialog.cpp create mode 100644 Engine/source/platformX86UNIX/x86UNIXDlibrary.cpp delete mode 100644 Engine/source/platformX86UNIX/x86UNIXInputManager.client.cpp delete mode 100644 Engine/source/platformX86UNIX/x86UNIXWindow.client.cpp create mode 100644 Engine/source/sfx/openal/linux/LoadOAL.linux.cpp diff --git a/Engine/lib/opcode/OPC_HybridModel.cpp b/Engine/lib/opcode/OPC_HybridModel.cpp index e86a6cf03..a8e0e9c6e 100644 --- a/Engine/lib/opcode/OPC_HybridModel.cpp +++ b/Engine/lib/opcode/OPC_HybridModel.cpp @@ -82,6 +82,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include "Opcode.h" +#include 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++; diff --git a/Engine/lib/opcode/OPC_SweepAndPrune.cpp b/Engine/lib/opcode/OPC_SweepAndPrune.cpp index 7cb7702e4..b7ee4183e 100644 --- a/Engine/lib/opcode/OPC_SweepAndPrune.cpp +++ b/Engine/lib/opcode/OPC_SweepAndPrune.cpp @@ -17,6 +17,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include "Opcode.h" +#include 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::iterator itr=mTimeMap.begin(); itr != mTimeMap.end(); itr++) { diff --git a/Engine/source/T3D/convexShape.cpp b/Engine/source/T3D/convexShape.cpp index 5719100ad..27a88ef79 100644 --- a/Engine/source/T3D/convexShape.cpp +++ b/Engine/source/T3D/convexShape.cpp @@ -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 ); diff --git a/Engine/source/T3D/debris.cpp b/Engine/source/T3D/debris.cpp index d8ef4f8fa..10c317e7f 100644 --- a/Engine/source/T3D/debris.cpp +++ b/Engine/source/T3D/debris.cpp @@ -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); } diff --git a/Engine/source/T3D/examples/renderMeshExample.cpp b/Engine/source/T3D/examples/renderMeshExample.cpp index 880df57d0..42a5ec950 100644 --- a/Engine/source/T3D/examples/renderMeshExample.cpp +++ b/Engine/source/T3D/examples/renderMeshExample.cpp @@ -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 ); diff --git a/Engine/source/T3D/fx/particleEmitter.cpp b/Engine/source/T3D/fx/particleEmitter.cpp index 99e19294a..6890f3c77 100644 --- a/Engine/source/T3D/fx/particleEmitter.cpp +++ b/Engine/source/T3D/fx/particleEmitter.cpp @@ -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 ); diff --git a/Engine/source/T3D/fx/ribbon.cpp b/Engine/source/T3D/fx/ribbon.cpp index 7f3fd8d2e..2936e7663 100644 --- a/Engine/source/T3D/fx/ribbon.cpp +++ b/Engine/source/T3D/fx/ribbon.cpp @@ -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); } diff --git a/Engine/source/T3D/lightFlareData.cpp b/Engine/source/T3D/lightFlareData.cpp index 8cbad24fc..4a2b9c355 100644 --- a/Engine/source/T3D/lightFlareData.cpp +++ b/Engine/source/T3D/lightFlareData.cpp @@ -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; diff --git a/Engine/source/T3D/shapeBase.cpp b/Engine/source/T3D/shapeBase.cpp index fc0f76998..f1d787f08 100644 --- a/Engine/source/T3D/shapeBase.cpp +++ b/Engine/source/T3D/shapeBase.cpp @@ -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 ) diff --git a/Engine/source/T3D/shapeImage.cpp b/Engine/source/T3D/shapeImage.cpp index 548984ca8..34485bb02 100644 --- a/Engine/source/T3D/shapeImage.cpp +++ b/Engine/source/T3D/shapeImage.cpp @@ -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); diff --git a/Engine/source/T3D/tsStatic.cpp b/Engine/source/T3D/tsStatic.cpp index d1e68a2c2..dffee4c5a 100644 --- a/Engine/source/T3D/tsStatic.cpp +++ b/Engine/source/T3D/tsStatic.cpp @@ -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); diff --git a/Engine/source/T3D/vehicles/flyingVehicle.cpp b/Engine/source/T3D/vehicles/flyingVehicle.cpp index ccd89c621..855850ea8 100644 --- a/Engine/source/T3D/vehicles/flyingVehicle.cpp +++ b/Engine/source/T3D/vehicles/flyingVehicle.cpp @@ -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); } } diff --git a/Engine/source/T3D/vehicles/hoverVehicle.cpp b/Engine/source/T3D/vehicles/hoverVehicle.cpp index b212807e0..a9b0300b8 100644 --- a/Engine/source/T3D/vehicles/hoverVehicle.cpp +++ b/Engine/source/T3D/vehicles/hoverVehicle.cpp @@ -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); } } diff --git a/Engine/source/T3D/vehicles/vehicle.cpp b/Engine/source/T3D/vehicles/vehicle.cpp index df10b2cdc..1f18b426f 100644 --- a/Engine/source/T3D/vehicles/vehicle.cpp +++ b/Engine/source/T3D/vehicles/vehicle.cpp @@ -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); diff --git a/Engine/source/T3D/vehicles/wheeledVehicle.cpp b/Engine/source/T3D/vehicles/wheeledVehicle.cpp index 39556168c..2069be0f2 100644 --- a/Engine/source/T3D/vehicles/wheeledVehicle.cpp +++ b/Engine/source/T3D/vehicles/wheeledVehicle.cpp @@ -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++) diff --git a/Engine/source/console/engineTypes.h b/Engine/source/console/engineTypes.h index 88eff7b3a..9d5a5f005 100644 --- a/Engine/source/console/engineTypes.h +++ b/Engine/source/console/engineTypes.h @@ -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 ) \ diff --git a/Engine/source/core/util/tDictionary.h b/Engine/source/core/util/tDictionary.h index 804d3eabd..8f395fea7 100644 --- a/Engine/source/core/util/tDictionary.h +++ b/Engine/source/core/util/tDictionary.h @@ -95,7 +95,7 @@ namespace DictHash inline U32 hash(const void *data) { - return (U32)data; + return (uintptr_t)data; } template diff --git a/Engine/source/environment/meshRoad.cpp b/Engine/source/environment/meshRoad.cpp index 453250568..eaa627093 100644 --- a/Engine/source/environment/meshRoad.cpp +++ b/Engine/source/environment/meshRoad.cpp @@ -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 ); } diff --git a/Engine/source/forest/editor/forestUndo.cpp b/Engine/source/forest/editor/forestUndo.cpp index 5889bc26b..10d974a61 100644 --- a/Engine/source/forest/editor/forestUndo.cpp +++ b/Engine/source/forest/editor/forestUndo.cpp @@ -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; diff --git a/Engine/source/gfx/gfxStringEnumTranslate.cpp b/Engine/source/gfx/gfxStringEnumTranslate.cpp index ff21e41ac..30cee8318 100644 --- a/Engine/source/gfx/gfxStringEnumTranslate.cpp +++ b/Engine/source/gfx/gfxStringEnumTranslate.cpp @@ -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 ); //------------------------------------------------------------------------------ diff --git a/Engine/source/gfx/gl/gfxGLVertexDecl.cpp b/Engine/source/gfx/gl/gfxGLVertexDecl.cpp index 882c624b9..10eda4401 100644 --- a/Engine/source/gfx/gl/gfxGLVertexDecl.cpp +++ b/Engine/source/gfx/gl/gfxGLVertexDecl.cpp @@ -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 ); } diff --git a/Engine/source/gui/controls/guiListBoxCtrl.cpp b/Engine/source/gui/controls/guiListBoxCtrl.cpp index 6459d5004..54ecadca2 100644 --- a/Engine/source/gui/controls/guiListBoxCtrl.cpp +++ b/Engine/source/gui/controls/guiListBoxCtrl.cpp @@ -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; diff --git a/Engine/source/math/util/matrixSet.cpp b/Engine/source/math/util/matrixSet.cpp index bc2e2ef0d..245a1a726 100644 --- a/Engine/source/math/util/matrixSet.cpp +++ b/Engine/source/math/util/matrixSet.cpp @@ -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; -} \ No newline at end of file +} diff --git a/Engine/source/platform/types.h b/Engine/source/platform/types.h index 8ab3cfe9c..8de7c97ea 100644 --- a/Engine/source/platform/types.h +++ b/Engine/source/platform/types.h @@ -23,6 +23,8 @@ #ifndef _TORQUE_TYPES_H_ #define _TORQUE_TYPES_H_ +#include + ////////////////////////////////////////////////////////////////////////////////////////////////////////// //-----------------------------------------Basic Types--------------------------------------------------// ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Engine/source/platformMac/platformMacCarb.h b/Engine/source/platformMac/platformMacCarb.h index 3a26eb249..d1e783380 100644 --- a/Engine/source/platformMac/platformMacCarb.h +++ b/Engine/source/platformMac/platformMacCarb.h @@ -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 diff --git a/Engine/source/platformWin32/winProcessControl.cpp b/Engine/source/platformWin32/winProcessControl.cpp index 69cab8ad8..db2b347db 100644 --- a/Engine/source/platformWin32/winProcessControl.cpp +++ b/Engine/source/platformWin32/winProcessControl.cpp @@ -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() diff --git a/Engine/source/platformX86UNIX/nativeDialogs/fileDialog.cpp b/Engine/source/platformX86UNIX/nativeDialogs/fileDialog.cpp new file mode 100644 index 000000000..40b40d1db --- /dev/null +++ b/Engine/source/platformX86UNIX/nativeDialogs/fileDialog.cpp @@ -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 \ No newline at end of file diff --git a/Engine/source/platformX86UNIX/platformX86UNIX.h b/Engine/source/platformX86UNIX/platformX86UNIX.h index dc239c37d..19481dd31 100644 --- a/Engine/source/platformX86UNIX/platformX86UNIX.h +++ b/Engine/source/platformX86UNIX/platformX86UNIX.h @@ -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" { diff --git a/Engine/source/platformX86UNIX/threads/semaphore.cpp b/Engine/source/platformX86UNIX/threads/semaphore.cpp index 63d7510ec..6c994af4d 100644 --- a/Engine/source/platformX86UNIX/threads/semaphore.cpp +++ b/Engine/source/platformX86UNIX/threads/semaphore.cpp @@ -22,30 +22,25 @@ #include "platformX86UNIX/platformX86UNIX.h" #include "platform/threads/semaphore.h" -#include -#include -#include -#include -#include +// Instead of that mess that was here before, lets use the SDL lib to deal +// with the semaphores. + +#include +#include 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); } diff --git a/Engine/source/platformX86UNIX/x86UNIXConsole.cpp b/Engine/source/platformX86UNIX/x86UNIXConsole.cpp index 50a319562..5e8f41f85 100644 --- a/Engine/source/platformX86UNIX/x86UNIXConsole.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXConsole.cpp @@ -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) { diff --git a/Engine/source/platformX86UNIX/x86UNIXDlibrary.cpp b/Engine/source/platformX86UNIX/x86UNIXDlibrary.cpp new file mode 100644 index 000000000..fae1564a2 --- /dev/null +++ b/Engine/source/platformX86UNIX/x86UNIXDlibrary.cpp @@ -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 + +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; +} + diff --git a/Engine/source/platformX86UNIX/x86UNIXFont.client.cpp b/Engine/source/platformX86UNIX/x86UNIXFont.client.cpp index 94781d54a..402392c9a 100644 --- a/Engine/source/platformX86UNIX/x86UNIXFont.client.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXFont.client.cpp @@ -35,27 +35,27 @@ #include #include #include -#include // For XRenderColor +//#include // For XRenderColor // Needed for getenv in createFont #include XftFont *loadFont(const char *name, S32 size, Display *display) { XftFont *fontInfo = NULL; - char* fontname = const_cast(name); + const char* fontname = name; if (dStrlen(fontname)==0) fontname = "arial"; - else if (stristr(const_cast(name), "arial") != NULL) + else if (stristr(name, "arial") != NULL) fontname = "arial"; - else if (stristr(const_cast(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(name), "bold") != NULL) + if (stristr(name, "bold") != NULL) weight = "bold"; - if (stristr(const_cast(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))); } - diff --git a/Engine/source/platformX86UNIX/x86UNIXGL.client.cpp b/Engine/source/platformX86UNIX/x86UNIXGL.client.cpp index ff70c247e..f72ff599c 100644 --- a/Engine/source/platformX86UNIX/x86UNIXGL.client.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXGL.client.cpp @@ -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 \ No newline at end of file diff --git a/Engine/source/platformX86UNIX/x86UNIXInput.client.cpp b/Engine/source/platformX86UNIX/x86UNIXInput.client.cpp index e05e910d5..57dd1e3bb 100644 --- a/Engine/source/platformX86UNIX/x86UNIXInput.client.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXInput.client.cpp @@ -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 diff --git a/Engine/source/platformX86UNIX/x86UNIXInputManager.client.cpp b/Engine/source/platformX86UNIX/x86UNIXInputManager.client.cpp deleted file mode 100644 index 749ef6b04..000000000 --- a/Engine/source/platformX86UNIX/x86UNIXInputManager.client.cpp +++ /dev/null @@ -1,1835 +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 "platformX86UNIX/platformX86UNIX.h" -#include "console/consoleTypes.h" -#include "platform/event.h" -#include "platform/gameInterface.h" -#include "platformX86UNIX/x86UNIXState.h" -#include "platformX86UNIX/x86UNIXInputManager.h" -#include "math/mMathFn.h" - -#include -#include -#include -#include - -#include - -// ascii table -AsciiData AsciiTable[NUM_KEYS]; - -// keymap table -static const U32 SDLtoTKeyMapSize = SDLK_LAST; -static U8 SDLtoTKeyMap[SDLtoTKeyMapSize]; -static bool keyMapsInitialized = false; - -// helper functions -static void MapKey(Uint16 SDLkey, U8 tkey, KeySym xkeysym); -static void InitKeyMaps(); -static inline U8 TranslateSDLKeytoTKey(SDLKey keysym); - -// unix platform state -extern x86UNIXPlatformState * x86UNIXState; - -// constants - -static const U32 MouseMask = SDL_MOUSEEVENTMASK; -static const U32 KeyboardMask = SDL_KEYUPMASK | SDL_KEYDOWNMASK; -static const U32 JoystickMask = SDL_JOYEVENTMASK; - -static const U32 AllInputEvents = MouseMask | KeyboardMask | JoystickMask; - -// defined in SDL -extern "C" Uint16 X11_KeyToUnicode( SDLKey keysym, SDLMod modifiers ); - -//============================================================================== -// Static helper functions -//============================================================================== -static void MapKey(Uint16 SDLkey, U8 tkey, KeySym xkeysym) -{ - DisplayPtrManager xdisplay; - Display* display = xdisplay.getDisplayPointer(); - - SDLtoTKeyMap[SDLkey] = tkey; - - Uint16 key = 0; - SDLKey skey = (SDLKey)SDLkey; - SDLMod mod = KMOD_NONE; - // lower case - key = X11_KeyToUnicode( skey, mod ); - AsciiTable[tkey].lower.ascii = key; - // upper case - mod = KMOD_LSHIFT; - key = X11_KeyToUnicode( skey, mod ); - AsciiTable[tkey].upper.ascii = key; - // goofy (i18n) case - mod = KMOD_MODE; - key = X11_KeyToUnicode( skey, mod ); - AsciiTable[tkey].goofy.ascii = key; - -#if 0 - if (xkeysym == 0) - return; - - XKeyPressedEvent fooKey; - const int keybufSize = 256; - char keybuf[keybufSize]; - - // find the x keycode for the keysym - KeyCode xkeycode = XKeysymToKeycode( - display, xkeysym); - -// Display *dpy = XOpenDisplay(NULL); -// KeyCode xkeycode = XKeysymToKeycode( -// dpy, xkeysym); - - if (!xkeycode) - return; - - // create an event with the keycode - dMemset(&fooKey, 0, sizeof(fooKey)); - fooKey.type = KeyPress; - fooKey.display = display; - fooKey.window = DefaultRootWindow(display); - fooKey.time = CurrentTime; - fooKey.keycode = xkeycode; - - // translate the event with no modifiers (yields lowercase) - KeySym dummyKeySym; - int numChars = XLookupString( - &fooKey, keybuf, keybufSize, &dummyKeySym, NULL); - if (numChars) - { - //Con::printf("assigning lowercase string %c", *keybuf); - // ignore everything but first char - AsciiTable[tkey].lower.ascii = *keybuf; - AsciiTable[tkey].goofy.ascii = *keybuf; - } - - // translate the event with shift modifier (yields uppercase) - fooKey.state |= ShiftMask; - numChars = XLookupString(&fooKey, keybuf, keybufSize, &dummyKeySym, NULL); - if (numChars) - { - //Con::printf("assigning uppercase string %c", *keybuf); - // ignore everything but first char - AsciiTable[tkey].upper.ascii = *keybuf; - } -#endif -} - -//------------------------------------------------------------------------------ -void InitKeyMaps() -{ - dMemset( &AsciiTable, 0, sizeof( AsciiTable ) ); - dMemset(SDLtoTKeyMap, KEY_NULL, SDLtoTKeyMapSize); - - // set up the X to Torque key map - // stuff - MapKey(SDLK_BACKSPACE, KEY_BACKSPACE, XK_BackSpace); - MapKey(SDLK_TAB, KEY_TAB, XK_Tab); - MapKey(SDLK_RETURN, KEY_RETURN, XK_Return); - MapKey(SDLK_PAUSE, KEY_PAUSE, XK_Pause); - MapKey(SDLK_CAPSLOCK, KEY_CAPSLOCK, XK_Caps_Lock); - MapKey(SDLK_ESCAPE, KEY_ESCAPE, XK_Escape); - - // more stuff - MapKey(SDLK_SPACE, KEY_SPACE, XK_space); - MapKey(SDLK_PAGEDOWN, KEY_PAGE_DOWN, XK_Page_Down); - MapKey(SDLK_PAGEUP, KEY_PAGE_UP, XK_Page_Up); - MapKey(SDLK_END, KEY_END, XK_End); - MapKey(SDLK_HOME, KEY_HOME, XK_Home); - MapKey(SDLK_LEFT, KEY_LEFT, XK_Left); - MapKey(SDLK_UP, KEY_UP, XK_Up); - MapKey(SDLK_RIGHT, KEY_RIGHT, XK_Right); - MapKey(SDLK_DOWN, KEY_DOWN, XK_Down); - MapKey(SDLK_PRINT, KEY_PRINT, XK_Print); - MapKey(SDLK_INSERT, KEY_INSERT, XK_Insert); - MapKey(SDLK_DELETE, KEY_DELETE, XK_Delete); - - S32 keysym; - S32 tkeycode; - KeySym xkey; - // main numeric keys - for (keysym = SDLK_0, tkeycode = KEY_0, xkey = XK_0; - keysym <= SDLK_9; - ++keysym, ++tkeycode, ++xkey) - MapKey(static_cast(keysym), tkeycode, xkey); - - // lowercase letters - for (keysym = SDLK_a, tkeycode = KEY_A, xkey = XK_a; - keysym <= SDLK_z; - ++keysym, ++tkeycode, ++xkey) - MapKey(static_cast(keysym), tkeycode, xkey); - - // various punctuation - MapKey('|', KEY_TILDE, XK_grave); - MapKey(SDLK_BACKQUOTE, KEY_TILDE, XK_grave); - MapKey(SDLK_MINUS, KEY_MINUS, XK_minus); - MapKey(SDLK_EQUALS, KEY_EQUALS, XK_equal); - MapKey(SDLK_LEFTBRACKET, KEY_LBRACKET, XK_bracketleft); - MapKey('{', KEY_LBRACKET, XK_bracketleft); - MapKey(SDLK_RIGHTBRACKET, KEY_RBRACKET, XK_bracketright); - MapKey('}', KEY_RBRACKET, XK_bracketright); - MapKey(SDLK_BACKSLASH, KEY_BACKSLASH, XK_backslash); - MapKey(SDLK_SEMICOLON, KEY_SEMICOLON, XK_semicolon); - MapKey(SDLK_QUOTE, KEY_APOSTROPHE, XK_apostrophe); - MapKey(SDLK_COMMA, KEY_COMMA, XK_comma); - MapKey(SDLK_PERIOD, KEY_PERIOD, XK_period); - MapKey(SDLK_SLASH, KEY_SLASH, XK_slash); - - // numpad numbers - for (keysym = SDLK_KP0, tkeycode = KEY_NUMPAD0, xkey = XK_KP_0; - keysym <= SDLK_KP9; - ++keysym, ++tkeycode, ++xkey) - MapKey(static_cast(keysym), tkeycode, xkey); - - // other numpad stuff - MapKey(SDLK_KP_MULTIPLY, KEY_MULTIPLY, XK_KP_Multiply); - MapKey(SDLK_KP_PLUS, KEY_ADD, XK_KP_Add); - MapKey(SDLK_KP_EQUALS, KEY_SEPARATOR, XK_KP_Separator); - MapKey(SDLK_KP_MINUS, KEY_SUBTRACT, XK_KP_Subtract); - MapKey(SDLK_KP_PERIOD, KEY_DECIMAL, XK_KP_Decimal); - MapKey(SDLK_KP_DIVIDE, KEY_DIVIDE, XK_KP_Divide); - MapKey(SDLK_KP_ENTER, KEY_NUMPADENTER, XK_KP_Enter); - - // F keys - for (keysym = SDLK_F1, tkeycode = KEY_F1, xkey = XK_F1; - keysym <= SDLK_F15; - ++keysym, ++tkeycode, ++xkey) - MapKey(static_cast(keysym), tkeycode, xkey); - - // various modifiers - MapKey(SDLK_NUMLOCK, KEY_NUMLOCK, XK_Num_Lock); - MapKey(SDLK_SCROLLOCK, KEY_SCROLLLOCK, XK_Scroll_Lock); - MapKey(SDLK_LCTRL, KEY_LCONTROL, XK_Control_L); - MapKey(SDLK_RCTRL, KEY_RCONTROL, XK_Control_R); - MapKey(SDLK_LALT, KEY_LALT, XK_Alt_L); - MapKey(SDLK_RALT, KEY_RALT, XK_Alt_R); - MapKey(313, KEY_RALT, XK_Alt_R); - MapKey(SDLK_LSHIFT, KEY_LSHIFT, XK_Shift_L); - MapKey(SDLK_RSHIFT, KEY_RSHIFT, XK_Shift_R); - MapKey(SDLK_LSUPER, KEY_WIN_LWINDOW, 0); - MapKey(SDLK_RSUPER, KEY_WIN_RWINDOW, 0); - MapKey(SDLK_MENU, KEY_WIN_APPS, 0); - MapKey(SDLK_MODE, KEY_OEM_102, 0); - - keyMapsInitialized = true; -}; - -//------------------------------------------------------------------------------ -U8 TranslateSDLKeytoTKey(SDLKey keysym) -{ - if (!keyMapsInitialized) - { - Con::printf("WARNING: SDLkeysymMap is not initialized"); - return 0; - } - if (keysym < 0 || - static_cast(keysym) >= SDLtoTKeyMapSize) - { - Con::printf("WARNING: invalid keysym: %d", keysym); - return 0; - } - return SDLtoTKeyMap[keysym]; -} - -//------------------------------------------------------------------------------ -// this shouldn't be used, use TranslateSDLKeytoTKey instead -U8 TranslateOSKeyCode(U8 vcode) -{ - Con::printf("WARNING: TranslateOSKeyCode is not supported in unix"); - return 0; -} - -//============================================================================== -// UInputManager -//============================================================================== -UInputManager::UInputManager() -{ - mActive = false; - mEnabled = false; - mLocking = true; // locking enabled by default - mKeyboardEnabled = mMouseEnabled = mJoystickEnabled = false; - mKeyboardActive = mMouseActive = mJoystickActive = false; -} - -//------------------------------------------------------------------------------ -void UInputManager::init() -{ - Con::addVariable( "pref::Input::KeyboardEnabled", - TypeBool, &mKeyboardEnabled ); - Con::addVariable( "pref::Input::MouseEnabled", - TypeBool, &mMouseEnabled ); - Con::addVariable( "pref::Input::JoystickEnabled", - TypeBool, &mJoystickEnabled ); -} - -//------------------------------------------------------------------------------ -bool UInputManager::enable() -{ - disable(); -#ifdef LOG_INPUT - Input::log( "Enabling Input...\n" ); -#endif - - mModifierKeys = 0; - dMemset( mMouseButtonState, 0, sizeof( mMouseButtonState ) ); - dMemset( mKeyboardState, 0, 256 ); - - InitKeyMaps(); - - mJoystickEnabled = false; - initJoystick(); - - mEnabled = true; - mMouseEnabled = true; - mKeyboardEnabled = true; - - SDL_EnableKeyRepeat( - SDL_DEFAULT_REPEAT_DELAY, - SDL_DEFAULT_REPEAT_INTERVAL); - - return true; -} - -//------------------------------------------------------------------------------ -void UInputManager::disable() -{ - deactivate(); - mEnabled = false; - return; -} - -//------------------------------------------------------------------------------ -void UInputManager::initJoystick() -{ - mJoystickList.clear(); - - // initialize SDL joystick system - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) - { - Con::warnf(" Unable to initialize joystick: %s", SDL_GetError()); - return; - } - - int numJoysticks = SDL_NumJoysticks(); - if (numJoysticks == 0) - Con::printf(" No joysticks found."); - - // disable joystick events (use polling instead) - SDL_JoystickEventState(SDL_IGNORE); - - // install joysticks - for(int i = 0; i < numJoysticks; i++ ) - { - JoystickInputDevice* newDevice = new JoystickInputDevice(i); - addObject(newDevice); - mJoystickList.push_back(newDevice); - Con::printf(" %s: %s", - newDevice->getDeviceName(), newDevice->getName()); -#ifdef LOG_INPUT - Input::log(" %s: %s\n", - newDevice->getDeviceName(), newDevice->getName()); -#endif - } - - mJoystickEnabled = true; -} - -//------------------------------------------------------------------------------ -void UInputManager::activate() -{ - if (mEnabled && !isActive()) - { - mActive = true; - SDL_ShowCursor(SDL_DISABLE); - resetInputState(); - // hack; if the mouse or keyboard has been disabled, re-enable them. - // prevents scripts like default.cs from breaking our input, although - // there is probably a better solution - mMouseEnabled = mKeyboardEnabled = true; - activateMouse(); - activateKeyboard(); - activateJoystick(); - if (x86UNIXState->windowLocked()) - lockInput(); - } -} - -//------------------------------------------------------------------------------ -void UInputManager::deactivate() -{ - if (mEnabled && isActive()) - { - unlockInput(); - deactivateKeyboard(); - deactivateMouse(); - deactivateJoystick(); - resetInputState(); - SDL_ShowCursor(SDL_ENABLE); - mActive = false; - } -} - -//------------------------------------------------------------------------------ -void UInputManager::resetKeyboardState() -{ - // unpress any pressed keys; in the future we may want - // to actually sync with the keyboard state - for (int i = 0; i < 256; ++i) - { - if (mKeyboardState[i]) - { - InputEvent event; - - event.deviceInst = 0; - event.deviceType = KeyboardDeviceType; - event.objType = SI_KEY; - event.objInst = i; - event.action = SI_BREAK; - event.fValue = 0.0; - Game->postEvent(event); - } - } - dMemset(mKeyboardState, 0, 256); - - // clear modifier keys - mModifierKeys = 0; -} - -//------------------------------------------------------------------------------ -void UInputManager::resetMouseState() -{ - // unpress any buttons; in the future we may want - // to actually sync with the mouse state - for (int i = 0; i < 3; ++i) - { - if (mMouseButtonState[i]) - { - // add KEY_BUTTON0 to the index to get the real - // button ID - S32 buttonID = i + KEY_BUTTON0; - InputEvent event; - - event.deviceInst = 0; - event.deviceType = MouseDeviceType; - event.objType = SI_BUTTON; - event.objInst = buttonID; - event.action = SI_BREAK; - event.fValue = 0.0; - Game->postEvent(event); - } - } - - dMemset(mMouseButtonState, 0, 3); -} - -//------------------------------------------------------------------------------ -void UInputManager::resetInputState() -{ - resetKeyboardState(); - resetMouseState(); - - // reset joysticks - for (Vector::iterator iter = mJoystickList.begin(); - iter != mJoystickList.end(); - ++iter) - { - (*iter)->reset(); - } - - // JMQTODO: make event arrays be members - // dispose of any lingering SDL input events - static const int MaxEvents = 255; - static SDL_Event events[MaxEvents]; - SDL_PumpEvents(); - SDL_PeepEvents(events, MaxEvents, SDL_GETEVENT, - AllInputEvents); -} - -//------------------------------------------------------------------------------ -void UInputManager::setLocking(bool enabled) -{ - mLocking = enabled; - if (mLocking) - lockInput(); - else - unlockInput(); -} - -//------------------------------------------------------------------------------ -void UInputManager::lockInput() -{ - if (x86UNIXState->windowActive() && x86UNIXState->windowLocked() && - mLocking && - SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) - SDL_WM_GrabInput(SDL_GRAB_ON); -} - -//------------------------------------------------------------------------------ -void UInputManager::unlockInput() -{ - if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON) - SDL_WM_GrabInput(SDL_GRAB_OFF); -} - -//------------------------------------------------------------------------------ -void UInputManager::onDeleteNotify( SimObject* object ) -{ - Parent::onDeleteNotify( object ); -} - -//------------------------------------------------------------------------------ -bool UInputManager::onAdd() -{ - if ( !Parent::onAdd() ) - return false; - - return true; -} - -//------------------------------------------------------------------------------ -void UInputManager::onRemove() -{ - deactivate(); - Parent::onRemove(); -} - -//------------------------------------------------------------------------------ -void UInputManager::mouseMotionEvent(const SDL_Event& event) -{ -// Con::printf("motion event: %d %d %d %d", -// event.motion.xrel, event.motion.yrel, -// event.motion.x, event.motion.y); - if (x86UNIXState->windowLocked()) - { - InputEvent ievent; - ievent.deviceInst = 0; - ievent.deviceType = MouseDeviceType; - ievent.objInst = 0; - ievent.modifier = mModifierKeys; - ievent.ascii = 0; - ievent.action = SI_MOVE; - - // post events if things have changed - if (event.motion.xrel != 0) - { - ievent.objType = SI_XAXIS; - ievent.fValue = event.motion.xrel; - Game->postEvent(ievent); - } - if (event.motion.yrel != 0) - { - ievent.objType = SI_YAXIS; - ievent.fValue = event.motion.yrel; - Game->postEvent(ievent); - } -#ifdef LOG_INPUT -#ifdef LOG_MOUSEMOVE - Input::log( "EVENT (Input): Mouse relative move (%.1f, %.1f).\n", - event.motion.xrel != 0 ? F32(event.motion.xrel) : 0.0, - event.motion.yrel != 0 ? F32(event.motion.yrel) : 0.0); -#endif -#endif - } - else - { - MouseMoveEvent mmevent; - mmevent.xPos = mLastMouseX = event.motion.x; - mmevent.yPos = mLastMouseY = event.motion.y; - mmevent.modifier = mModifierKeys; - Game->postEvent(mmevent); -#ifdef LOG_INPUT -#ifdef LOG_MOUSEMOVE - Input::log( "EVENT (Input): Mouse absolute move (%.1f, %.1f).\n", - F32(event.motion.x), - F32(event.motion.y)); -#endif -#endif - } -} - -//------------------------------------------------------------------------------ -void UInputManager::joyButtonEvent(const SDL_Event& event) -{ - joyButtonEvent(event.jbutton.which, event.jbutton.button, - event.type == SDL_JOYBUTTONDOWN); -} - -//------------------------------------------------------------------------------ -void UInputManager::joyButtonEvent(U8 deviceID, U8 buttonNum, bool pressed) - -{ - S32 action = pressed ? SI_MAKE : SI_BREAK; - S32 objInst = buttonNum + KEY_BUTTON0; - - InputEvent ievent; - - ievent.deviceInst = deviceID; - ievent.deviceType = JoystickDeviceType; - ievent.modifier = mModifierKeys; - ievent.ascii = 0; - ievent.objType = SI_BUTTON; - ievent.objInst = objInst; - ievent.action = action; - ievent.fValue = (action == SI_MAKE) ? 1.0 : 0.0; - - Game->postEvent(ievent); -#ifdef LOG_INPUT - Input::log( "EVENT (Input): joystick%d button%d %s. MODS:%c%c%c \n", - deviceID, - buttonNum, - pressed ? "pressed" : "released", - ( mModifierKeys & SI_SHIFT ? 'S' : '.' ), - ( mModifierKeys & SI_CTRL ? 'C' : '.' ), - ( mModifierKeys & SI_ALT ? 'A' : '.' )); -#endif -} - -//------------------------------------------------------------------------------ -void UInputManager::joyHatEvent(U8 deviceID, U8 hatNum, - U8 prevHatState, U8 currHatState) -{ - if (prevHatState == currHatState) - return; - - InputEvent ievent; - - ievent.deviceInst = deviceID; - ievent.deviceType = JoystickDeviceType; - ievent.modifier = mModifierKeys; - ievent.ascii = 0; - ievent.objType = SI_POV; - - // first break any positions that are no longer valid - ievent.action = SI_BREAK; - ievent.fValue = 0.0; - - if (prevHatState & SDL_HAT_UP && !(currHatState & SDL_HAT_UP)) - { -#ifdef LOG_INPUT - Input::log( "EVENT (Input): Up POV released.\n"); -#endif - ievent.objInst = SI_UPOV; - Game->postEvent(ievent); - } - else if (prevHatState & SDL_HAT_DOWN && !(currHatState & SDL_HAT_DOWN)) - { -#ifdef LOG_INPUT - Input::log( "EVENT (Input): Down POV released.\n"); -#endif - ievent.objInst = SI_DPOV; - Game->postEvent(ievent); - } - if (prevHatState & SDL_HAT_LEFT && !(currHatState & SDL_HAT_LEFT)) - { -#ifdef LOG_INPUT - Input::log( "EVENT (Input): Left POV released.\n"); -#endif - ievent.objInst = SI_LPOV; - Game->postEvent(ievent); - } - else if (prevHatState & SDL_HAT_RIGHT && !(currHatState & SDL_HAT_RIGHT)) - { -#ifdef LOG_INPUT - Input::log( "EVENT (Input): Right POV released.\n"); -#endif - ievent.objInst = SI_RPOV; - Game->postEvent(ievent); - } - - // now do the make events - ievent.action = SI_MAKE; - ievent.fValue = 1.0; - - if (!(prevHatState & SDL_HAT_UP) && currHatState & SDL_HAT_UP) - { -#ifdef LOG_INPUT - Input::log( "EVENT (Input): Up POV pressed.\n"); -#endif - ievent.objInst = SI_UPOV; - Game->postEvent(ievent); - } - else if (!(prevHatState & SDL_HAT_DOWN) && currHatState & SDL_HAT_DOWN) - { -#ifdef LOG_INPUT - Input::log( "EVENT (Input): Down POV pressed.\n"); -#endif - ievent.objInst = SI_DPOV; - Game->postEvent(ievent); - } - if (!(prevHatState & SDL_HAT_LEFT) && currHatState & SDL_HAT_LEFT) - { -#ifdef LOG_INPUT - Input::log( "EVENT (Input): Left POV pressed.\n"); -#endif - ievent.objInst = SI_LPOV; - Game->postEvent(ievent); - } - else if (!(prevHatState & SDL_HAT_RIGHT) && currHatState & SDL_HAT_RIGHT) - { -#ifdef LOG_INPUT - Input::log( "EVENT (Input): Right POV pressed.\n"); -#endif - ievent.objInst = SI_RPOV; - Game->postEvent(ievent); - } -} - -//------------------------------------------------------------------------------ -void UInputManager::joyAxisEvent(const SDL_Event& event) -{ - joyAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); -} - -//------------------------------------------------------------------------------ -void UInputManager::joyAxisEvent(U8 deviceID, U8 axisNum, S16 axisValue) -{ - JoystickInputDevice* stick; - - stick = mJoystickList[deviceID]; - AssertFatal(stick, "JoystickInputDevice* is NULL"); - JoystickAxisInfo axisInfo = stick->getAxisInfo(axisNum); - - if (axisInfo.type == -1) - return; - - // scale the value to [-1,1] - F32 scaledValue = 0; - if (axisValue < 0) - scaledValue = -F32(axisValue) / axisInfo.minValue; - else if (axisValue > 0) - scaledValue = F32(axisValue) / axisInfo.maxValue; - -// F32 range = F32(axisInfo.maxValue - axisInfo.minValue); -// F32 scaledValue = F32((2 * axisValue) - axisInfo.maxValue - -// axisInfo.minValue) / range; - - if (scaledValue > 1.f) - scaledValue = 1.f; - else if (scaledValue < -1.f) - scaledValue = -1.f; - - // create and post the event - InputEvent ievent; - - ievent.deviceInst = deviceID; - ievent.deviceType = JoystickDeviceType; - ievent.modifier = mModifierKeys; - ievent.ascii = 0; - ievent.objType = axisInfo.type; - ievent.objInst = 0; - ievent.action = SI_MOVE; - ievent.fValue = scaledValue; - - Game->postEvent(ievent); - -#ifdef LOG_INPUT - Input::log( "EVENT (Input): joystick axis %d moved: %.1f.\n", - axisNum, ievent.fValue); -#endif - -} - -//------------------------------------------------------------------------------ -void UInputManager::mouseButtonEvent(const SDL_Event& event) -{ - S32 action = (event.type == SDL_MOUSEBUTTONDOWN) ? SI_MAKE : SI_BREAK; - S32 objInst = -1; - // JMQTODO: support wheel delta like windows version? - // JMQTODO: make this value configurable? - S32 wheelDelta = 10; - bool wheel = false; - - switch (event.button.button) - { - case SDL_BUTTON_LEFT: - objInst = KEY_BUTTON0; - break; - case SDL_BUTTON_RIGHT: - objInst = KEY_BUTTON1; - break; - case SDL_BUTTON_MIDDLE: - objInst = KEY_BUTTON2; - break; - case Button4: - wheel = true; - break; - case Button5: - wheel = true; - wheelDelta = -wheelDelta; - break; - } - - if (objInst == -1 && !wheel) - // unsupported button - return; - - InputEvent ievent; - - ievent.deviceInst = 0; - ievent.deviceType = MouseDeviceType; - ievent.modifier = mModifierKeys; - ievent.ascii = 0; - - if (wheel) - { - // SDL generates a button press/release for each wheel move, - // so ignore breaks to translate those into a single event - if (action == SI_BREAK) - return; - ievent.objType = SI_ZAXIS; - ievent.objInst = 0; - ievent.action = SI_MOVE; - ievent.fValue = wheelDelta; -#ifdef LOG_INPUT - Input::log( "EVENT (Input): mouse wheel moved %s: %.1f. MODS:%c%c%c\n", - wheelDelta > 0 ? "up" : "down", - ievent.fValue, - ( mModifierKeys & SI_SHIFT ? 'S' : '.' ), - ( mModifierKeys & SI_CTRL ? 'C' : '.' ), - ( mModifierKeys & SI_ALT ? 'A' : '.' )); -#endif - } - else // regular button - { - S32 buttonID = (objInst - KEY_BUTTON0); - if (buttonID < 3) - mMouseButtonState[buttonID] = ( action == SI_MAKE ) ? true : false; - - ievent.objType = SI_BUTTON; - ievent.objInst = objInst; - ievent.action = action; - ievent.fValue = (action == SI_MAKE) ? 1.0 : 0.0; -#ifdef LOG_INPUT - Input::log( "EVENT (Input): mouse button%d %s. MODS:%c%c%c\n", - buttonID, - action == SI_MAKE ? "pressed" : "released", - ( mModifierKeys & SI_SHIFT ? 'S' : '.' ), - ( mModifierKeys & SI_CTRL ? 'C' : '.' ), - ( mModifierKeys & SI_ALT ? 'A' : '.' )); -#endif - } - - Game->postEvent(ievent); -} - -//------------------------------------------------------------------------------ -const char* getKeyName( U16 key ) -{ - switch ( key ) - { - case KEY_BACKSPACE: return "Backspace"; - case KEY_TAB: return "Tab"; - case KEY_RETURN: return "Return"; - case KEY_PAUSE: return "Pause"; - case KEY_CAPSLOCK: return "CapsLock"; - case KEY_ESCAPE: return "Esc"; - - case KEY_SPACE: return "SpaceBar"; - case KEY_PAGE_DOWN: return "PageDown"; - case KEY_PAGE_UP: return "PageUp"; - case KEY_END: return "End"; - case KEY_HOME: return "Home"; - case KEY_LEFT: return "Left"; - case KEY_UP: return "Up"; - case KEY_RIGHT: return "Right"; - case KEY_DOWN: return "Down"; - case KEY_PRINT: return "PrintScreen"; - case KEY_INSERT: return "Insert"; - case KEY_DELETE: return "Delete"; - case KEY_HELP: return "Help"; - - case KEY_NUMPAD0: return "Numpad 0"; - case KEY_NUMPAD1: return "Numpad 1"; - case KEY_NUMPAD2: return "Numpad 2"; - case KEY_NUMPAD3: return "Numpad 3"; - case KEY_NUMPAD4: return "Numpad 4"; - case KEY_NUMPAD5: return "Numpad 5"; - case KEY_NUMPAD6: return "Numpad 6"; - case KEY_NUMPAD7: return "Numpad 7"; - case KEY_NUMPAD8: return "Numpad 8"; - case KEY_NUMPAD9: return "Numpad 9"; - case KEY_MULTIPLY: return "Multiply"; - case KEY_ADD: return "Add"; - case KEY_SEPARATOR: return "Separator"; - case KEY_SUBTRACT: return "Subtract"; - case KEY_DECIMAL: return "Decimal"; - case KEY_DIVIDE: return "Divide"; - case KEY_NUMPADENTER: return "Numpad Enter"; - - case KEY_F1: return "F1"; - case KEY_F2: return "F2"; - case KEY_F3: return "F3"; - case KEY_F4: return "F4"; - case KEY_F5: return "F5"; - case KEY_F6: return "F6"; - case KEY_F7: return "F7"; - case KEY_F8: return "F8"; - case KEY_F9: return "F9"; - case KEY_F10: return "F10"; - case KEY_F11: return "F11"; - case KEY_F12: return "F12"; - case KEY_F13: return "F13"; - case KEY_F14: return "F14"; - case KEY_F15: return "F15"; - case KEY_F16: return "F16"; - case KEY_F17: return "F17"; - case KEY_F18: return "F18"; - case KEY_F19: return "F19"; - case KEY_F20: return "F20"; - case KEY_F21: return "F21"; - case KEY_F22: return "F22"; - case KEY_F23: return "F23"; - case KEY_F24: return "F24"; - - case KEY_NUMLOCK: return "NumLock"; - case KEY_SCROLLLOCK: return "ScrollLock"; - case KEY_LCONTROL: return "LCtrl"; - case KEY_RCONTROL: return "RCtrl"; - case KEY_LALT: return "LAlt"; - case KEY_RALT: return "RAlt"; - case KEY_LSHIFT: return "LShift"; - case KEY_RSHIFT: return "RShift"; - - case KEY_WIN_LWINDOW: return "LWin"; - case KEY_WIN_RWINDOW: return "RWin"; - case KEY_WIN_APPS: return "Apps"; - } - - static char returnString[5]; - dSprintf( returnString, sizeof( returnString ), "%c", Input::getAscii( key, STATE_UPPER ) ); - return returnString; -} - - -//------------------------------------------------------------------------------ -void UInputManager::keyEvent(const SDL_Event& event) -{ - S32 action = (event.type == SDL_KEYDOWN) ? SI_MAKE : SI_BREAK; - InputEvent ievent; - - ievent.deviceInst = 0; - ievent.deviceType = KeyboardDeviceType; - ievent.objType = SI_KEY; - ievent.objInst = TranslateSDLKeytoTKey(event.key.keysym.sym); - // if the action is a make but this key is already pressed, - // count it as a repeat - if (action == SI_MAKE && mKeyboardState[ievent.objInst]) - action = SI_REPEAT; - ievent.action = action; - ievent.fValue = (action == SI_MAKE || action == SI_REPEAT) ? 1.0 : 0.0; - - processKeyEvent(ievent); - Game->postEvent(ievent); - -#if 0 - if (ievent.action == SI_MAKE) - dPrintf("key event: : %s key pressed. MODS:%c%c%c\n", - getKeyName(ievent.objInst), - ( mModifierKeys & SI_SHIFT ? 'S' : '.' ), - ( mModifierKeys & SI_CTRL ? 'C' : '.' ), - ( mModifierKeys & SI_ALT ? 'A' : '.' )); - else if (ievent.action == SI_REPEAT) - dPrintf("key event: : %s key repeated. MODS:%c%c%c\n", - getKeyName(ievent.objInst), - ( mModifierKeys & SI_SHIFT ? 'S' : '.' ), - ( mModifierKeys & SI_CTRL ? 'C' : '.' ), - ( mModifierKeys & SI_ALT ? 'A' : '.' )); - else if (ievent.action == SI_BREAK) - dPrintf("key event: : %s key released. MODS:%c%c%c\n", - getKeyName(ievent.objInst), - ( mModifierKeys & SI_SHIFT ? 'S' : '.' ), - ( mModifierKeys & SI_CTRL ? 'C' : '.' ), - ( mModifierKeys & SI_ALT ? 'A' : '.' )); - else - dPrintf("unknown key event!\n"); -#endif - -#ifdef LOG_INPUT - Input::log( "EVENT (Input): %s key %s. MODS:%c%c%c\n", - getKeyName(ievent.objInst), - action == SI_MAKE ? "pressed" : "released", - ( mModifierKeys & SI_SHIFT ? 'S' : '.' ), - ( mModifierKeys & SI_CTRL ? 'C' : '.' ), - ( mModifierKeys & SI_ALT ? 'A' : '.' )); -#endif -} - -//------------------------------------------------------------------------------ -// This function was ripped from DInputDevice almost entirely intact. -bool UInputManager::processKeyEvent( InputEvent &event ) -{ - if ( event.deviceType != KeyboardDeviceType || event.objType != SI_KEY ) - return false; - - bool modKey = false; - U8 keyCode = event.objInst; - - if ( event.action == SI_MAKE || event.action == SI_REPEAT) - { - // Maintain the key structure: - mKeyboardState[keyCode] = true; - - switch ( event.objInst ) - { - case KEY_LSHIFT: - mModifierKeys |= SI_LSHIFT; - modKey = true; - break; - - case KEY_RSHIFT: - mModifierKeys |= SI_RSHIFT; - modKey = true; - break; - - case KEY_LCONTROL: - mModifierKeys |= SI_LCTRL; - modKey = true; - break; - - case KEY_RCONTROL: - mModifierKeys |= SI_RCTRL; - modKey = true; - break; - - case KEY_LALT: - mModifierKeys |= SI_LALT; - modKey = true; - break; - - case KEY_RALT: - mModifierKeys |= SI_RALT; - modKey = true; - break; - } - } - else - { - // Maintain the keys structure: - mKeyboardState[keyCode] = false; - - switch ( event.objInst ) - { - case KEY_LSHIFT: - mModifierKeys &= ~SI_LSHIFT; - modKey = true; - break; - - case KEY_RSHIFT: - mModifierKeys &= ~SI_RSHIFT; - modKey = true; - break; - - case KEY_LCONTROL: - mModifierKeys &= ~SI_LCTRL; - modKey = true; - break; - - case KEY_RCONTROL: - mModifierKeys &= ~SI_RCTRL; - modKey = true; - break; - - case KEY_LALT: - mModifierKeys &= ~SI_LALT; - modKey = true; - break; - - case KEY_RALT: - mModifierKeys &= ~SI_RALT; - modKey = true; - break; - } - } - - if ( modKey ) - event.modifier = 0; - else - event.modifier = mModifierKeys; - - // TODO: alter this getAscii call - KEY_STATE state = STATE_LOWER; - if (event.modifier & (SI_CTRL|SI_ALT) ) - { - state = STATE_GOOFY; - } - if ( event.modifier & SI_SHIFT ) - { - state = STATE_UPPER; - } - - event.ascii = Input::getAscii( event.objInst, state ); - - return modKey; -} - -//------------------------------------------------------------------------------ -void UInputManager::setWindowLocked(bool locked) -{ - if (locked) - lockInput(); - else - { - unlockInput(); - // SDL keeps track of abs mouse position in fullscreen mode, which means - // that if you switch to unlocked mode while fullscreen, the mouse will - // suddenly warp to someplace unexpected on screen. To fix this, we - // warp the mouse to the last known Torque abs mouse position. - if (mLastMouseX != -1 && mLastMouseY != -1) - SDL_WarpMouse(mLastMouseX, mLastMouseY); - } -} - -//------------------------------------------------------------------------------ -void UInputManager::process() -{ - if (!mEnabled || !isActive()) - return; - - // JMQTODO: make these be class members - static const int MaxEvents = 255; - static SDL_Event events[MaxEvents]; - - U32 mask = 0; - - // process keyboard and mouse events - if (mMouseActive) - mask |= MouseMask; - if (mKeyboardActive) - mask |= KeyboardMask; - - if (mask != 0) - { - SDL_PumpEvents(); - S32 numEvents = SDL_PeepEvents(events, MaxEvents, SDL_GETEVENT, mask); - - for (int i = 0; i < numEvents; ++i) - { - switch (events[i].type) - { - case SDL_MOUSEMOTION: - mouseMotionEvent(events[i]); - break; - case SDL_MOUSEBUTTONUP: - case SDL_MOUSEBUTTONDOWN: - mouseButtonEvent(events[i]); - break; - case SDL_KEYDOWN: - case SDL_KEYUP: - keyEvent(events[i]); - break; - } - } - } - - // poll joysticks - if (!mJoystickActive) - return; - - SDL_JoystickUpdate(); - - for (Vector::iterator iter = mJoystickList.begin(); - iter != mJoystickList.end(); - ++iter) - { - (*iter)->process(); - } -} - -//------------------------------------------------------------------------------ -bool UInputManager::enableKeyboard() -{ - if ( !isEnabled() ) - return( false ); - - if ( isKeyboardEnabled() && isKeyboardActive() ) - return( true ); - - mKeyboardEnabled = true; - if ( isActive() ) - mKeyboardEnabled = activateKeyboard(); - - if ( mKeyboardEnabled ) - { - Con::printf( "Keyboard enabled." ); -#ifdef LOG_INPUT - Input::log( "Keyboard enabled.\n" ); -#endif - } - else - { - Con::warnf( "Keyboard failed to enable!" ); -#ifdef LOG_INPUT - Input::log( "Keyboard failed to enable!\n" ); -#endif - } - - return( mKeyboardEnabled ); -} - -//------------------------------------------------------------------------------ -void UInputManager::disableKeyboard() -{ - if ( !isEnabled() || !isKeyboardEnabled()) - return; - - deactivateKeyboard(); - mKeyboardEnabled = false; - Con::printf( "Keyboard disabled." ); -#ifdef LOG_INPUT - Input::log( "Keyboard disabled.\n" ); -#endif -} - -//------------------------------------------------------------------------------ -bool UInputManager::activateKeyboard() -{ - if ( !isEnabled() || !isActive() || !isKeyboardEnabled() ) - return( false ); - - mKeyboardActive = true; -#ifdef LOG_INPUT - Input::log( mKeyboardActive ? "Keyboard activated.\n" : "Keyboard failed to activate!\n" ); -#endif - return( mKeyboardActive ); -} - -//------------------------------------------------------------------------------ -void UInputManager::deactivateKeyboard() -{ - if ( isEnabled() && isKeyboardActive() ) - { - mKeyboardActive = false; -#ifdef LOG_INPUT - Input::log( "Keyboard deactivated.\n" ); -#endif - } -} - -//------------------------------------------------------------------------------ -bool UInputManager::enableMouse() -{ - if ( !isEnabled() ) - return( false ); - - if ( isMouseEnabled() && isMouseActive() ) - return( true ); - - mMouseEnabled = true; - if ( isActive() ) - mMouseEnabled = activateMouse(); - - if ( mMouseEnabled ) - { - Con::printf( "Mouse enabled." ); -#ifdef LOG_INPUT - Input::log( "Mouse enabled.\n" ); -#endif - } - else - { - Con::warnf( "Mouse failed to enable!" ); -#ifdef LOG_INPUT - Input::log( "Mouse failed to enable!\n" ); -#endif - } - - return( mMouseEnabled ); -} - -//------------------------------------------------------------------------------ -void UInputManager::disableMouse() -{ - if ( !isEnabled() || !isMouseEnabled()) - return; - - deactivateMouse(); - mMouseEnabled = false; - Con::printf( "Mouse disabled." ); -#ifdef LOG_INPUT - Input::log( "Mouse disabled.\n" ); -#endif -} - -//------------------------------------------------------------------------------ -bool UInputManager::activateMouse() -{ - if ( !isEnabled() || !isActive() || !isMouseEnabled() ) - return( false ); - - mMouseActive = true; -#ifdef LOG_INPUT - Input::log( mMouseActive ? - "Mouse activated.\n" : "Mouse failed to activate!\n" ); -#endif - return( mMouseActive ); -} - -//------------------------------------------------------------------------------ -void UInputManager::deactivateMouse() -{ - if ( isEnabled() && isMouseActive() ) - { - mMouseActive = false; -#ifdef LOG_INPUT - Input::log( "Mouse deactivated.\n" ); -#endif - } -} - -//------------------------------------------------------------------------------ -bool UInputManager::enableJoystick() -{ - if ( !isEnabled() ) - return( false ); - - if ( isJoystickEnabled() && isJoystickActive() ) - return( true ); - - mJoystickEnabled = true; - if ( isActive() ) - mJoystickEnabled = activateJoystick(); - - if ( mJoystickEnabled ) - { - Con::printf( "Joystick enabled." ); -#ifdef LOG_INPUT - Input::log( "Joystick enabled.\n" ); -#endif - } - else - { - Con::warnf( "Joystick failed to enable!" ); -#ifdef LOG_INPUT - Input::log( "Joystick failed to enable!\n" ); -#endif - } - - return( mJoystickEnabled ); -} - -//------------------------------------------------------------------------------ -void UInputManager::disableJoystick() -{ - if ( !isEnabled() || !isJoystickEnabled()) - return; - - deactivateJoystick(); - mJoystickEnabled = false; - Con::printf( "Joystick disabled." ); -#ifdef LOG_INPUT - Input::log( "Joystick disabled.\n" ); -#endif -} - -//------------------------------------------------------------------------------ -bool UInputManager::activateJoystick() -{ - if ( !isEnabled() || !isActive() || !isJoystickEnabled() ) - return( false ); - - mJoystickActive = false; - JoystickInputDevice* dptr; - for ( iterator ptr = begin(); ptr != end(); ptr++ ) - { - dptr = dynamic_cast( *ptr ); - if ( dptr && dptr->getDeviceType() == JoystickDeviceType) - if ( dptr->activate() ) - mJoystickActive = true; - } -#ifdef LOG_INPUT - Input::log( mJoystickActive ? - "Joystick activated.\n" : "Joystick failed to activate!\n" ); -#endif - return( mJoystickActive ); -} - -//------------------------------------------------------------------------------ -void UInputManager::deactivateJoystick() -{ - if ( isEnabled() && isJoystickActive() ) - { - mJoystickActive = false; - JoystickInputDevice* dptr; - for ( iterator ptr = begin(); ptr != end(); ptr++ ) - { - dptr = dynamic_cast( *ptr ); - if ( dptr && dptr->getDeviceType() == JoystickDeviceType) - dptr->deactivate(); - } -#ifdef LOG_INPUT - Input::log( "Joystick deactivated.\n" ); -#endif - } -} - -//------------------------------------------------------------------------------ -const char* UInputManager::getJoystickAxesString( U32 deviceID ) -{ - for (Vector::iterator iter = mJoystickList.begin(); - iter != mJoystickList.end(); - ++iter) - { - if ((*iter)->getDeviceID() == deviceID) - return (*iter)->getJoystickAxesString(); - } - return( "" ); -} - -//============================================================================== -// JoystickInputDevice -//============================================================================== -JoystickInputDevice::JoystickInputDevice(U8 deviceID) -{ - mActive = false; - mStick = NULL; - mAxisList.clear(); - mDeviceID = deviceID; - dSprintf(mName, 29, "joystick%d", mDeviceID); - - mButtonState.clear(); - mHatState.clear(); - mNumAxes = mNumButtons = mNumHats = mNumBalls = 0; - - loadJoystickInfo(); - - // initialize state variables - for (int i = 0; i < mNumButtons; ++i) - mButtonState.push_back(false); // all buttons unpressed initially - - for (int i = 0; i < mNumHats; ++i) - mHatState.push_back(SDL_HAT_CENTERED); // hats centered initially -} - -//------------------------------------------------------------------------------ -JoystickInputDevice::~JoystickInputDevice() -{ - if (isActive()) - deactivate(); -} - -//------------------------------------------------------------------------------ -bool JoystickInputDevice::activate() -{ - if (isActive()) - return true; - - // open the stick - mStick = SDL_JoystickOpen(mDeviceID); - if (mStick == NULL) - { - Con::printf("Unable to activate %s: %s", getDeviceName(), SDL_GetError()); - return false; - } - - // reload axis mapping info - loadAxisInfo(); - - mActive = true; - return true; -} - -//------------------------------------------------------------------------------ -bool JoystickInputDevice::deactivate() -{ - if (!isActive()) - return true; - - if (mStick != NULL) - { - SDL_JoystickClose(mStick); - mStick = NULL; - } - - mActive = false; - return true; -} - -//------------------------------------------------------------------------------ -const char* JoystickInputDevice::getName() -{ - return SDL_JoystickName(mDeviceID); -} - -//------------------------------------------------------------------------------ -void JoystickInputDevice::reset() -{ - UInputManager* manager = dynamic_cast(Input::getManager()); - if (!manager) - return; - - // clear joystick state variables - - // buttons - for (int i = 0; i < mButtonState.size(); ++i) - if (mButtonState[i]) - { - manager->joyButtonEvent(mDeviceID, i, false); - mButtonState[i] = false; - } - - // hats - for (int i = 0; i < mHatState.size(); ++i) - if (mHatState[i] != SDL_HAT_CENTERED) - { - manager->joyHatEvent(mDeviceID, i, mHatState[i], SDL_HAT_CENTERED); - mHatState[i] = SDL_HAT_CENTERED; - } - - // axis and ball state is not maintained -} - -//------------------------------------------------------------------------------ -bool JoystickInputDevice::process() -{ - if (!isActive()) - return false; - - UInputManager* manager = dynamic_cast(Input::getManager()); - if (!manager) - return false; - - // axes - for (int i = 0; i < mNumAxes; ++i) - { - // skip the axis if we don't have a mapping for it - if (mAxisList[i].type == -1) - continue; - manager->joyAxisEvent(mDeviceID, i, SDL_JoystickGetAxis(mStick, i)); - } - - // buttons - for (int i = 0; i < mNumButtons; ++i) - { - if (bool(SDL_JoystickGetButton(mStick, i)) == - mButtonState[i]) - continue; - mButtonState[i] = !mButtonState[i]; - manager->joyButtonEvent(mDeviceID, i, mButtonState[i]); - } - - // hats - for (int i = 0; i < mNumHats; ++i) - { - U8 currHatState = SDL_JoystickGetHat(mStick, i); - if (mHatState[i] == currHatState) - continue; - - manager->joyHatEvent(mDeviceID, i, mHatState[i], currHatState); - mHatState[i] = currHatState; - } - - // ballz - // JMQTODO: how to map ball events (xaxis,yaxis?) - return true; -} - -//------------------------------------------------------------------------------ -static S32 GetAxisType(S32 axisNum, const char* namedType) -{ - S32 axisType = -1; - - if (namedType != NULL) - { - if (dStricmp(namedType, "xaxis")==0) - axisType = SI_XAXIS; - else if (dStricmp(namedType, "yaxis")==0) - axisType = SI_YAXIS; - else if (dStricmp(namedType, "zaxis")==0) - axisType = SI_ZAXIS; - else if (dStricmp(namedType, "rxaxis")==0) - axisType = SI_RXAXIS; - else if (dStricmp(namedType, "ryaxis")==0) - axisType = SI_RYAXIS; - else if (dStricmp(namedType, "rzaxis")==0) - axisType = SI_RZAXIS; - else if (dStricmp(namedType, "slider")==0) - axisType = SI_SLIDER; - } - - if (axisType == -1) - { - // use a hardcoded default mapping if possible - switch (axisNum) - { - case 0: - axisType = SI_XAXIS; - break; - case 1: - axisType = SI_YAXIS; - break; - case 2: - axisType = SI_RZAXIS; - break; - case 3: - axisType = SI_SLIDER; - break; - } - } - - return axisType; -} - -//------------------------------------------------------------------------------ -void JoystickInputDevice::loadJoystickInfo() -{ - bool opened = false; - if (mStick == NULL) - { - mStick = SDL_JoystickOpen(mDeviceID); - if (mStick == NULL) - { - Con::printf("Unable to open %s: %s", getDeviceName(), SDL_GetError()); - return; - } - opened = true; - } - - // get the number of thingies on this joystick - mNumAxes = SDL_JoystickNumAxes(mStick); - mNumButtons = SDL_JoystickNumButtons(mStick); - mNumHats = SDL_JoystickNumHats(mStick); - mNumBalls = SDL_JoystickNumBalls(mStick); - - // load axis mapping info - loadAxisInfo(); - - if (opened) - SDL_JoystickClose(mStick); -} - -//------------------------------------------------------------------------------ -// for each axis on a joystick, torque needs to know the type of the axis -// (SI_XAXIS, etc), the minimum value, and the maximum value. However none of -// this information is generally available with the unix/linux api. All you -// get is a device and axis number and a value. Therefore, -// we allow the user to specify these values in preferences. hopefully -// someday we can implement a gui joystick calibrator that takes care of this -// cruft for the user. -void JoystickInputDevice::loadAxisInfo() -{ - mAxisList.clear(); - - AssertFatal(mStick, "mStick is NULL"); - - static int AxisDefaults[] = { SI_XAXIS, SI_YAXIS, SI_ZAXIS, - SI_RXAXIS, SI_RYAXIS, SI_RZAXIS, - SI_SLIDER }; - - int numAxis = SDL_JoystickNumAxes(mStick); - for (int i = 0; i < numAxis; ++i) - { - JoystickAxisInfo axisInfo; - - // defaults - axisInfo.type = -1; - axisInfo.minValue = -32768; - axisInfo.maxValue = 32767; - - // look in console to see if there is mapping information for this axis - const int TempBufSize = 1024; - char tempBuf[TempBufSize]; - dSprintf(tempBuf, TempBufSize, "$Pref::Input::Joystick%d::Axis%d", - mDeviceID, i); - - const char* axisStr = Con::getVariable(tempBuf); - if (axisStr == NULL || dStrlen(axisStr) == 0) - { - if (i < sizeof(AxisDefaults)) - axisInfo.type = AxisDefaults[i]; - } - else - { - // format is "TorqueAxisName MinValue MaxValue"; - dStrncpy(tempBuf, axisStr, TempBufSize); - char* temp = dStrtok( tempBuf, " \0" ); - if (temp) - { - axisInfo.type = GetAxisType(i, temp); - temp = dStrtok( NULL, " \0" ); - if (temp) - { - axisInfo.minValue = dAtoi(temp); - temp = dStrtok( NULL, "\0" ); - if (temp) - { - axisInfo.maxValue = dAtoi(temp); - } - } - } - } - - mAxisList.push_back(axisInfo); - } -} - -//------------------------------------------------------------------------------ -const char* JoystickInputDevice::getJoystickAxesString() -{ - char buf[64]; - dSprintf( buf, sizeof( buf ), "%d", mAxisList.size()); - - for (Vector::iterator iter = mAxisList.begin(); - iter != mAxisList.end(); - ++iter) - { - switch ((*iter).type) - { - case SI_XAXIS: - dStrcat( buf, "\tX" ); - break; - case SI_YAXIS: - dStrcat( buf, "\tY" ); - break; - case SI_ZAXIS: - dStrcat( buf, "\tZ" ); - break; - case SI_RXAXIS: - dStrcat( buf, "\tR" ); - break; - case SI_RYAXIS: - dStrcat( buf, "\tU" ); - break; - case SI_RZAXIS: - dStrcat( buf, "\tV" ); - break; - case SI_SLIDER: - dStrcat( buf, "\tS" ); - break; - } - } - - char* returnString = Con::getReturnBuffer( dStrlen( buf ) + 1 ); - dStrcpy( returnString, buf ); - return( returnString ); -} - - -//============================================================================== -// Console Functions -//============================================================================== -ConsoleFunction( activateKeyboard, bool, 1, 1, "activateKeyboard()" ) -{ - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr ) - return( mgr->activateKeyboard() ); - - return( false ); -} - -// JMQ: disabled deactivateKeyboard since the script calls it but there is -// no fallback keyboard input in unix, resulting in a permanently disabled -// keyboard -//------------------------------------------------------------------------------ -ConsoleFunction( deactivateKeyboard, void, 1, 1, "deactivateKeyboard()" ) -{ -#if 0 - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr ) - mgr->deactivateKeyboard(); -#endif -} - -//------------------------------------------------------------------------------ -ConsoleFunction( enableMouse, bool, 1, 1, "enableMouse()" ) -{ - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr ) - return( mgr->enableMouse() ); - - return ( false ); -} - -//------------------------------------------------------------------------------ -ConsoleFunction( disableMouse, void, 1, 1, "disableMouse()" ) -{ - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr ) - mgr->disableMouse(); -} - -//------------------------------------------------------------------------------ -ConsoleFunction( enableJoystick, bool, 1, 1, "enableJoystick()" ) -{ - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr ) - return( mgr->enableJoystick() ); - - return ( false ); -} - -//------------------------------------------------------------------------------ -ConsoleFunction( disableJoystick, void, 1, 1, "disableJoystick()" ) -{ - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr ) - mgr->disableJoystick(); -} - -//------------------------------------------------------------------------------ -ConsoleFunction( enableLocking, void, 1, 1, "enableLocking()" ) -{ - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr ) - mgr->setLocking(true); -} - -//------------------------------------------------------------------------------ -ConsoleFunction( disableLocking, void, 1, 1, "disableLocking()" ) -{ - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr ) - mgr->setLocking(false); -} - -//------------------------------------------------------------------------------ -ConsoleFunction( toggleLocking, void, 1, 1, "toggleLocking()" ) -{ - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr ) - mgr->setLocking(!mgr->getLocking()); -} - -//------------------------------------------------------------------------------ -ConsoleFunction( echoInputState, void, 1, 1, "echoInputState()" ) -{ - UInputManager* mgr = dynamic_cast( Input::getManager() ); - if ( mgr && mgr->isEnabled() ) - { - Con::printf( "Input is enabled %s.", - mgr->isActive() ? "and active" : "but inactive" ); - Con::printf( "- Keyboard is %sabled and %sactive.", - mgr->isKeyboardEnabled() ? "en" : "dis", - mgr->isKeyboardActive() ? "" : "in" ); - Con::printf( "- Mouse is %sabled and %sactive.", - mgr->isMouseEnabled() ? "en" : "dis", - mgr->isMouseActive() ? "" : "in" ); - Con::printf( "- Joystick is %sabled and %sactive.", - mgr->isJoystickEnabled() ? "en" : "dis", - mgr->isJoystickActive() ? "" : "in" ); - } - else - Con::printf( "Input is not enabled." ); -} diff --git a/Engine/source/platformX86UNIX/x86UNIXInputManager.h b/Engine/source/platformX86UNIX/x86UNIXInputManager.h index 3420be377..1df78c9a5 100644 --- a/Engine/source/platformX86UNIX/x86UNIXInputManager.h +++ b/Engine/source/platformX86UNIX/x86UNIXInputManager.h @@ -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_ diff --git a/Engine/source/platformX86UNIX/x86UNIXMain.cpp b/Engine/source/platformX86UNIX/x86UNIXMain.cpp index e0f252e0d..1c98ed4e2 100644 --- a/Engine/source/platformX86UNIX/x86UNIXMain.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXMain.cpp @@ -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(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 diff --git a/Engine/source/platformX86UNIX/x86UNIXMemory.cpp b/Engine/source/platformX86UNIX/x86UNIXMemory.cpp index 7567bdb6f..ad08a313f 100644 --- a/Engine/source/platformX86UNIX/x86UNIXMemory.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXMemory.cpp @@ -24,25 +24,25 @@ #include #include -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); } diff --git a/Engine/source/platformX86UNIX/x86UNIXMessageBox.client.cpp b/Engine/source/platformX86UNIX/x86UNIXMessageBox.client.cpp index e54c6eb9b..05d2b17ff 100644 --- a/Engine/source/platformX86UNIX/x86UNIXMessageBox.client.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXMessageBox.client.cpp @@ -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); diff --git a/Engine/source/platformX86UNIX/x86UNIXMessageBox.h b/Engine/source/platformX86UNIX/x86UNIXMessageBox.h index 7e7477700..3d9a7e5d4 100644 --- a/Engine/source/platformX86UNIX/x86UNIXMessageBox.h +++ b/Engine/source/platformX86UNIX/x86UNIXMessageBox.h @@ -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(); diff --git a/Engine/source/platformX86UNIX/x86UNIXOGLVideo.client.cpp b/Engine/source/platformX86UNIX/x86UNIXOGLVideo.client.cpp index edc5d3a17..16f906f69 100644 --- a/Engine/source/platformX86UNIX/x86UNIXOGLVideo.client.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXOGLVideo.client.cpp @@ -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 \ No newline at end of file diff --git a/Engine/source/platformX86UNIX/x86UNIXOpenAL.client.cpp b/Engine/source/platformX86UNIX/x86UNIXOpenAL.client.cpp index e87920f8a..8e0c021ac 100644 --- a/Engine/source/platformX86UNIX/x86UNIXOpenAL.client.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXOpenAL.client.cpp @@ -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 \ No newline at end of file diff --git a/Engine/source/platformX86UNIX/x86UNIXProcessControl.cpp b/Engine/source/platformX86UNIX/x86UNIXProcessControl.cpp index ed0b2aac6..bf246d132 100644 --- a/Engine/source/platformX86UNIX/x86UNIXProcessControl.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXProcessControl.cpp @@ -31,12 +31,15 @@ #include #ifndef TORQUE_DEDICATED -#include +#include #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) diff --git a/Engine/source/platformX86UNIX/x86UNIXRedbook.cpp b/Engine/source/platformX86UNIX/x86UNIXRedbook.cpp index 12a60f068..65741218f 100644 --- a/Engine/source/platformX86UNIX/x86UNIXRedbook.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXRedbook.cpp @@ -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 #endif -#include +#include + +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 @@ -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(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 diff --git a/Engine/source/platformX86UNIX/x86UNIXState.h b/Engine/source/platformX86UNIX/x86UNIXState.h index c39ea00cd..4036f029e 100644 --- a/Engine/source/platformX86UNIX/x86UNIXState.h +++ b/Engine/source/platformX86UNIX/x86UNIXState.h @@ -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; } diff --git a/Engine/source/platformX86UNIX/x86UNIXStdConsole.h b/Engine/source/platformX86UNIX/x86UNIXStdConsole.h index 29d50d905..85a105111 100644 --- a/Engine/source/platformX86UNIX/x86UNIXStdConsole.h +++ b/Engine/source/platformX86UNIX/x86UNIXStdConsole.h @@ -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(); diff --git a/Engine/source/platformX86UNIX/x86UNIXStrings.cpp b/Engine/source/platformX86UNIX/x86UNIXStrings.cpp index 1e19aa9da..f531409d9 100644 --- a/Engine/source/platformX86UNIX/x86UNIXStrings.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXStrings.cpp @@ -27,9 +27,9 @@ #include -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 diff --git a/Engine/source/platformX86UNIX/x86UNIXWindow.client.cpp b/Engine/source/platformX86UNIX/x86UNIXWindow.client.cpp deleted file mode 100644 index aff4d82a2..000000000 --- a/Engine/source/platformX86UNIX/x86UNIXWindow.client.cpp +++ /dev/null @@ -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 -#include -#include -#include // fork, execvp, chdir -#include // nanosleep - -#ifndef TORQUE_DEDICATED -#include -#include - -#include -#include -#include -#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& 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( 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(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 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(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); -} diff --git a/Engine/source/sfx/openal/linux/LoadOAL.linux.cpp b/Engine/source/sfx/openal/linux/LoadOAL.linux.cpp new file mode 100644 index 000000000..d238b6cfe --- /dev/null +++ b/Engine/source/sfx/openal/linux/LoadOAL.linux.cpp @@ -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 +#include +#include +#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); +} diff --git a/Engine/source/sfx/sfxTypes.cpp b/Engine/source/sfx/sfxTypes.cpp index 911a23f24..d12437b53 100644 --- a/Engine/source/sfx/sfxTypes.cpp +++ b/Engine/source/sfx/sfxTypes.cpp @@ -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; } diff --git a/Engine/source/ts/loader/tsShapeLoader.cpp b/Engine/source/ts/loader/tsShapeLoader.cpp index 573ae1ee1..506e8d72b 100644 --- a/Engine/source/ts/loader/tsShapeLoader.cpp +++ b/Engine/source/ts/loader/tsShapeLoader.cpp @@ -382,7 +382,7 @@ void TSShapeLoader::generateSubshapes() bool cmpMeshNameAndSize(const String& key, const Vector& names, void* arg1, void* arg2) { const Vector& meshes = *(Vector*)arg1; - S32 meshSize = (S32)arg2; + S32 meshSize = (intptr_t)arg2; for (S32 i = 0; i < names.size(); i++) { diff --git a/Engine/source/ts/tsMesh.cpp b/Engine/source/ts/tsMesh.cpp index 0bea64e40..fe4231bce 100644 --- a/Engine/source/ts/tsMesh.cpp +++ b/Engine/source/ts/tsMesh.cpp @@ -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(); diff --git a/Engine/source/ts/tsShape.cpp b/Engine/source/ts/tsShape.cpp index 7b160b670..b88b10d04 100644 --- a/Engine/source/ts/tsShape.cpp +++ b/Engine/source/ts/tsShape.cpp @@ -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); } diff --git a/Tools/CMake/basics.cmake b/Tools/CMake/basics.cmake index 403059386..47f04e547 100644 --- a/Tools/CMake/basics.cmake +++ b/Tools/CMake/basics.cmake @@ -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}") diff --git a/Tools/CMake/torque3d.cmake b/Tools/CMake/torque3d.cmake index 7eb69c36e..8827881c5 100644 --- a/Tools/CMake/torque3d.cmake +++ b/Tools/CMake/torque3d.cmake @@ -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)