123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2013 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 "platformAndroid/platformAndroid.h"
- #include "platformAndroid/AndroidEvents.h"
- #include "platformAndroid/AndroidUtil.h"
- #include "platform/threads/thread.h"
- #include "game/gameInterface.h"
- #include "io/fileObject.h"
- extern void clearPendingMultitouchEvents( void );
- S32 gLastStart = 0;
- bool appIsRunning = true;
- //TODO: android
- int _AndroidRunTorqueMain()
- {
- /*
- UIApplication *app = [UIApplication sharedApplication];
- platState.viewController = viewController;
-
- platState.appID = appID;
- platState.firstThreadId = ThreadManager::getCurrentThreadId();
- platState.Window = Window;
- platState.application = app;
-
- // Hidden by default.
- platState.application.statusBarHidden = YES;
-
- printf("performing mainInit()\n");
-
- platState.lastTimeTick = Platform::getRealMilliseconds();
-
- if(!Game->mainInitialize(platState.argc, platState.argv))
- {
- return 0;
- }
- */
- }
- void _AndroidGameInnerLoop()
- {
- if (!appIsRunning)
- {
- return;
- }
- else if (Game->isRunning())
- {
- S32 start = Platform::getRealMilliseconds();
-
- Game->mainLoop();
-
- gLastStart = start;
-
- }
- else
- {
- Game->mainShutdown();
-
- // Need to actually exit the application now
- exit(0);
- }
- }
- void _AndroidGameResignActive()
- {
- if ( Con::isFunction("onAndroidResignActive") )
- Con::executef( 1, "onAndroidResignActive" );
-
- appIsRunning = false;
- }
- void _AndroidGameBecomeActive()
- {
- clearPendingMultitouchEvents( );
-
- if ( Con::isFunction("onAndroidBecomeActive") )
- Con::executef( 1, "onAndroidBecomeActive" );
-
- appIsRunning = true;
- }
- void _AndroidGameWillTerminate()
- {
- if ( Con::isFunction("onAndroidWillTerminate") )
- Con::executef( 1, "onAndroidWillTerminate" );
-
- Con::executef( 1, "onExit" );
-
- Game->mainShutdown();
- }
- // Store current orientation for easy access
- void _AndroidGameChangeOrientation(S32 newOrientation)
- {
- _AndroidGameSetCurrentOrientation(newOrientation);
-
- return;
- /*
- bool enableAutoOrientation = Con::getBoolVariable("$pref::Android::EnableOrientationRotation");
- int screenOrientation = Con::getIntVariable("$pref::Android::ScreenOrientation");
- bool allowOtherOrientation = Con::getBoolVariable("$pref::Android::EnableOtherOrientationRotation");
- // The rotation matching the project orientation must be allowed for any to occur
- if (enableAutoOrientation)
- {
- // Start "collecting animations"
- [UIView beginAnimations: nil context: nil];
-
- // If the project is designed for landscape or it allows landscape rotation
- if (screenOrientation == 0 || allowOtherOrientation)
- {
- if (newOrientation == UIDeviceOrientationLandscapeLeft)
- {
- platState.Window.transform = CGAffineTransformMakeRotation(M_PI*1.5);
- Con::executef(1, "onAndroidOrientationToLandscapeLeft");
- // Show animations
- [UIView commitAnimations];
-
- return;
- }
-
- if (newOrientation == UIDeviceOrientationLandscapeRight)
- {
- platState.Window.transform = CGAffineTransformMakeRotation(M_PI_2);
- Con::executef(1, "onAndroidOrientationToLandscapeRight");
- // Show animations
- [UIView commitAnimations];
-
- return;
- }
- }
-
- // If the project is designed for portrait or it allows portrait rotation
- if (screenOrientation == 1 || allowOtherOrientation)
- {
- if (newOrientation == UIDeviceOrientationPortrait)
- {
- platState.Window.transform = CGAffineTransformMakeRotation(M_PI*1.5);
- Con::executef(1, "onAndroidOrientationToPortrait");
- // Show animations
- [UIView commitAnimations];
-
- return;
- }
-
- if (newOrientation == UIDeviceOrientationPortraitUpsideDown)
- {
- platState.Window.transform = CGAffineTransformMakeRotation(M_PI_2);
- Con::executef(1, "onAndroidOrientationToPortraitUpsideDown");
- // Show animations
- [UIView commitAnimations];
-
- return;
- }
- }
-
- // Show animations
- [UIView commitAnimations];
- }*/
- }
- static void _AndroidGetTxtFileArgs(int &argc, char** argv, int maxargc)
- {
- argc = 0;
-
- const U32 kMaxTextLen = 2048;
-
- U32 textLen;
-
- char* text = new char[kMaxTextLen];
-
- // Open the file, kick out if we can't
- File cmdfile;
-
- File::Status err = cmdfile.open("AndroidCmdLine.txt", cmdfile.Read);
-
- // Re-organise function to handle memory deletion better
- if (err == File::Ok)
- {
- // read in the first kMaxTextLen bytes, kick out if we get errors or no data
- err = cmdfile.read(kMaxTextLen-1, text, &textLen);
-
- if (((err == File::Ok || err == File::EOS) || textLen > 0))
- {
- // Null terminate
- text[textLen++] = '\0';
-
- // Truncate to the 1st line of the file
- for(int i = 0; i < textLen; i++)
- {
- if( text[i] == '\n' || text[i] == '\r' )
- {
- text[i] = '\0';
- textLen = i+1;
- break;
- }
- }
-
- // Tokenize the args with nulls, save them in argv, count them in argc
- char* tok;
-
- for(tok = dStrtok(text, " "); tok && argc < maxargc; tok = dStrtok(NULL, " "))
- argv[argc++] = tok;
- }
- }
-
- // Close file and delete memory before returning
- cmdfile.close();
-
- delete[] text;
-
- text = NULL;
- }
- int main(int argc, char *argv[])
- {
- //TODO: android
- /*
- int kMaxCmdlineArgs = 32; //Arbitrary
-
- printf("Initial Command Line\n");
-
- for( int i = 0; i < argc; i++ )
- {
- printf("%i : %s", i, argv[i] );
- }
-
- NSString *nsStrVersion = [UIDevice currentDevice ].systemVersion;
- const char *strVersion = [nsStrVersion UTF8String ];
- platState.osVersion = dAtof( strVersion);
-
- // Find Main.cs .
- const char* cwd = Platform::getMainDotCsDir();
-
- // Change to the directory that contains main.cs
- Platform::setCurrentDirectory(cwd);
-
- // get the actual command line args
- S32 newArgc = argc;
-
- const char* newArgv[kMaxCmdlineArgs];
-
- for(int i=0; i < argc && i < kMaxCmdlineArgs; i++)
- newArgv[i] = argv[i];
-
- // get the text file args
- S32 textArgc;
- char* textArgv[kMaxCmdlineArgs];
-
- _AndroidGetTxtFileArgs(textArgc, textArgv, kMaxCmdlineArgs);
-
- // merge them
- int i=0;
-
- while(i < textArgc && newArgc < kMaxCmdlineArgs)
- newArgv[newArgc++] = textArgv[i++];
-
- // store them in platState
- platState.argc = newArgc;
- platState.argv = newArgv;
-
- printf("\nMerged Command Line\n");
-
- for( int i = 0; i < platState.argc; i++ )
- {
- printf("%i : %s", i, platState.argv[i] );
- }
-
- printf("\n");
-
- // now, we run UIApplication which calls back and starts thread or timer
- platState.appReturn = UIApplicationMain(argc, argv, nil, NSStringFromClass([T2DAppDelegate class]));
-
- printf("exiting...\n");
- return(platState.appReturn);
- */
- }
|