Ejemplo n.º 1
0
CORE_PROC(int, RelayInput)( PDATAPATH pdp
												, PTEXT (CPROC *Datacallback)( PDATAPATH pdp, PTEXT pLine ) )
{
	extern int gbTrace;
	if( pdp->pPrior )
	{
		PTEXT p;
		int moved = 0;

		if( gbTrace )
			xlprintf(LOG_NOISE+1)( WIDE("Relay input from %s to %s..........")
										, GetText( pdp->pPrior->pName )
										, GetText( pdp->pName ) );
		do
		{
			if( pdp->pPrior->Read )
			{
				pdp->pPrior->Read( pdp->pPrior );
			}
			if( IsQueueEmpty( &pdp->pPrior->Input ) )
				break;
			//Log( WIDE("Has some input to handle...") );
			while( ( p = (PTEXT)DequeLink( &pdp->pPrior->Input ) ) )
			{
				if( gbTrace )
					lprintf( WIDE("Data is: %s"), GetText( p ) );
				if( Datacallback && !( ( p->flags & TF_RELAY ) == TF_RELAY ) )
				{
					//lprintf( WIDE("Data callback...") );
					for( p = Datacallback( pdp, p ); p; p = Datacallback( pdp, NULL ) )
					{
						moved++;
						if( p != (POINTER)1 )
							EnqueLink( &pdp->Input, p );
						else
							lprintf( WIDE("Data was consumed by datapath.") );
					}
				}
				else
				{
					 PTEXT out = BuildLine( p );
					 Log1( WIDE("Relay In: %s"), GetText( out ) );
					 LineRelease( out );
					moved++;
					EnqueLink( &pdp->Input, p );
				}
			}
			if( gbTrace && !moved && !pdp->pPrior->flags.Closed )
			{
				lprintf( WIDE("Did not result in data, try reading source again, rerelay. %s %s"), GetText( pdp->pName ), GetText( pdp->pPrior->pName ) );
			}
		  } while( !moved &&
					 !pdp->pPrior->flags.Closed );
		// stop relaying closes at datasource points
		//if( !pdp->pPrior->flags.Data_Source )
		pdp->flags.Closed |= pdp->pPrior->flags.Closed;
		return moved;
	}
	return 0;
}
Ejemplo n.º 2
0
int main(void)
{
   OpenServer();
   xlprintf(LOG_ADVISORY)("Entering main.");
	while(1)
	{
		WakeableSleep(SLEEP_FOREVER);
	}
   return 1;
}
Ejemplo n.º 3
0
static int CPROC ServerMateStarted( uint32_t *params, uint32_t param_length
		  , uint32_t *result, uint32_t *result_length )
{
	xlprintf(LOG_ALWAYS)("Got a MateStarted.  Returning %d"
							  , INVALID_INDEX
							  );

  	result[0] = MSG_LASTMESSAGE;
  	result[1] = MSG_LASTEVENT;
  	(*result_length) = 8;
   return 7;
}
Ejemplo n.º 4
0
static int CPROC ServiceFunction( uint32_t *params, uint32_t param_length
		  , uint32_t *result, uint32_t *result_length )
{
	// echo the data we got back to the client...
// most other things will do useful functions in functions.

	//call the libary functions (eg. REgisterIcon) here

   xlprintf(LOG_NOISE)("Ok, got ServiceFjunction");
   *result_length = param_length;
   return 3;
}
Ejemplo n.º 5
0
static int CPROC ServerMateEnded( uint32_t *params, uint32_t param_length
		  , uint32_t *result, uint32_t *result_length )
{
   xlprintf(LOG_ALWAYS)("Got a MateEnded. params is %lu by the way. ", &params);

   if( result_length ) // a close never expects a return, and will pass a NULL for the length.
		(*result_length) = INVALID_INDEX; // but if it happens to want a length, set NO length.
	// return success (if failure, probably does not matter, this is disregarded due to the nature
	// what this message is - the disconnect of a client that is no longer (or will shortly be
	// no longer there) )

   return 6;
}
Ejemplo n.º 6
0
static int CPROC ServerGeneric( uint32_t *params, uint32_t param_length
		  , uint32_t *result, uint32_t *result_length )
{
   xlprintf(LOG_ALWAYS)("Got a generic.  ");

	result[0] = MSG_LASTMESSAGE;
	result[1] = MSG_LASTEVENT;
	(*result_length) = 8;
//     *result_length = param_length;
//     *result_length = INVALID_INDEX; //this generates no responce.

   return 5;
}
Ejemplo n.º 7
0
static int CPROC ServerRegisterIcon( uint32_t *params, uint32_t param_length
		  , uint32_t *result, uint32_t *result_length )
{
	// echo the data we got back to the client...
// most other things will do useful functions in functions.

   xlprintf(LOG_NOISE)("About to RegisterIcon for %s", (char *)params);
	RegisterIcon((char* )params);//since one parameter is known to be passed, the name of the icon

   *result_length = param_length;
   *result_length = INVALID_INDEX; //this generates no responce.

   return 4;
}
Ejemplo n.º 8
0
// Run a program completely detached from the current process
// it runs independantly.  Program does not suspend until it completes.
// No way at all to know if the program works or fails.
SYSTEM_PROC( PTASK_INFO, LaunchPeerProgramExx )( CTEXTSTR program, CTEXTSTR path, PCTEXTSTR args
															  , int flags
															  , TaskOutput OutputHandler
															  , TaskEnd EndNotice
															  , uintptr_t psv
																DBG_PASS
															  )
{
	PTASK_INFO task;
	if( program && program[0] )
	{
#ifdef WIN32
		int launch_flags = ( ( flags & LPP_OPTION_NEW_CONSOLE ) ? CREATE_NEW_CONSOLE : 0 )
		                 | ( ( flags & LPP_OPTION_NEW_GROUP ) ? CREATE_NEW_PROCESS_GROUP : 0 )
			;
		PVARTEXT pvt = VarTextCreateEx( DBG_VOIDRELAY );
		PTEXT cmdline;
		PTEXT final_cmdline;
		LOGICAL needs_quotes;
		TEXTSTR expanded_path = ExpandPath( program );
		char *new_path;
		TEXTSTR expanded_working_path = path?ExpandPath( path ):ExpandPath( WIDE(".") );
		int first = TRUE;
		//TEXTCHAR saved_path[256];
		task = (PTASK_INFO)AllocateEx( sizeof( TASK_INFO ) DBG_RELAY );
		MemSet( task, 0, sizeof( TASK_INFO ) );
		task->psvEnd = psv;
		task->EndNotice = EndNotice;
		if( l.ExternalFindProgram ) {
			new_path = l.ExternalFindProgram( expanded_path );
			if( new_path ) {
				Release( expanded_path );
				expanded_path = new_path;
			}
		}
#ifdef _DEBUG
		xlprintf(LOG_NOISE)( WIDE("%s[%s]"), path, expanded_working_path );
#endif
		if( StrCmp( path, WIDE(".") ) == 0 )
		{
			path = NULL;
			Release( expanded_working_path );
			expanded_working_path = NULL;
		}
		if( expanded_path && StrChr( expanded_path, ' ' ) )
			needs_quotes = TRUE;
		else
			needs_quotes = FALSE;


		if( needs_quotes )
			vtprintf( pvt, WIDE( "\"" ) );

      /*
		if( !IsAbsolutePath( expanded_path ) && expanded_working_path )
		{
			//lprintf( "needs working path too" );
			vtprintf( pvt, WIDE("%s/"), expanded_working_path );
		}
      */
		vtprintf( pvt, WIDE("%s"), expanded_path );

		if( needs_quotes )
			vtprintf( pvt, WIDE( "\"" ) );

		if( flags & LPP_OPTION_FIRST_ARG_IS_ARG )
			;
		else
		{
			if( args && args[0] )// arg[0] is passed with linux programs, and implied with windows.
				args++;
		}
		while( args && args[0] )
		{
			if( args[0][0] == 0 )
				vtprintf( pvt, WIDE( " \"\"" ) );
			else if( StrChr( args[0], ' ' ) )
				vtprintf( pvt, WIDE(" \"%s\""), args[0] );
			else
				vtprintf( pvt, WIDE(" %s"), args[0] );
			first = FALSE;
			args++;
		}
		cmdline = VarTextGet( pvt );
		vtprintf( pvt, WIDE( "cmd.exe /c %s" ), GetText( cmdline ) );
		final_cmdline = VarTextGet( pvt );
		VarTextDestroy( &pvt );
		MemSet( &task->si, 0, sizeof( STARTUPINFO ) );
		task->si.cb = sizeof( STARTUPINFO );

#ifdef _DEBUG
		xlprintf(LOG_NOISE)( WIDE( "quotes?%s path [%s] program [%s]  [cmd.exe (%s)]"), needs_quotes?WIDE( "yes"):WIDE( "no"), expanded_working_path, expanded_path, GetText( final_cmdline ) );
#endif
      /*
		if( path )
		{
			GetCurrentPath( saved_path, sizeof( saved_path ) );
			SetCurrentPath( path );
		}
      */
		task->OutputEvent = OutputHandler;
		if( OutputHandler )
		{
			SECURITY_ATTRIBUTES sa;

			sa.bInheritHandle = TRUE;
			sa.lpSecurityDescriptor = NULL;
			sa.nLength = sizeof( sa );

			CreatePipe( &task->hReadOut, &task->hWriteOut, &sa, 0 );
			//CreatePipe( &hReadErr, &hWriteErr, &sa, 0 );
			CreatePipe( &task->hReadIn, &task->hWriteIn, &sa, 0 );
			task->si.hStdInput = task->hReadIn;
			task->si.hStdError = task->hWriteOut;
			task->si.hStdOutput = task->hWriteOut;
			task->si.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
			if( !( flags & LPP_OPTION_DO_NOT_HIDE ) )
				task->si.wShowWindow = SW_HIDE;
			else
				task->si.wShowWindow = SW_SHOW;
		}
		else
		{
			task->si.dwFlags |= STARTF_USESHOWWINDOW;
			if( !( flags & LPP_OPTION_DO_NOT_HIDE ) )
				task->si.wShowWindow = SW_HIDE;
			else
				task->si.wShowWindow = SW_SHOW;
		}

		{
			HINSTANCE hShellProcess = 0;
			int success = 0;
#ifdef WIN32
			if( flags & LPP_OPTION_IMPERSONATE_EXPLORER )
			{
				HANDLE hExplorer = GetImpersonationToken();
				if( ( CreateProcessAsUser( hExplorer, NULL //program
												 , GetText( cmdline )
												 , NULL, NULL, TRUE
												 , launch_flags | CREATE_NEW_PROCESS_GROUP
												 , NULL
												 , expanded_working_path
												 , &task->si
												 , &task->pi ) || FixHandles(task) || DumpError() ) ||
					( CreateProcessAsUser( hExplorer, program
												, GetText( cmdline )
												, NULL, NULL, TRUE
												, launch_flags | CREATE_NEW_PROCESS_GROUP
												, NULL
												, expanded_working_path
												, &task->si
												, &task->pi ) || FixHandles(task) || DumpError() ) ||
					( CreateProcessAsUser( hExplorer, program
												, NULL // GetText( cmdline )
												, NULL, NULL, TRUE
												, launch_flags | CREATE_NEW_PROCESS_GROUP
												, NULL
												, expanded_working_path
												, &task->si
												, &task->pi ) || FixHandles(task) || DumpError() ) ||
					( CreateProcessAsUser( hExplorer, WIDE( "cmd.exe" )
												, GetText( final_cmdline )
												, NULL, NULL, TRUE
												, launch_flags | CREATE_NEW_PROCESS_GROUP
												, NULL
												, expanded_working_path
												, &task->si
												, &task->pi ) || FixHandles(task) || DumpError() )
				  )
				{
					success = 1;
				}
				CloseHandle( hExplorer );
			}
			else
#endif
			{
				if( ( CreateProcess( NULL //program
										 , GetText( cmdline )
										 , NULL, NULL, TRUE
										 , launch_flags | ( OutputHandler?CREATE_NO_WINDOW:0 )//CREATE_NEW_PROCESS_GROUP
										 , NULL
										 , expanded_working_path
										 , &task->si
										 , &task->pi ) || FixHandles(task) || DumpError() ) ||
					( CreateProcess( program
										, GetText( cmdline )
										, NULL, NULL, TRUE
										, launch_flags | ( OutputHandler?CREATE_NO_WINDOW:0 )//CREATE_NEW_PROCESS_GROUP
										, NULL
										, expanded_working_path
										, &task->si
										, &task->pi ) || FixHandles(task) || DumpError() ) ||
					( CreateProcess( program
										, NULL // GetText( cmdline )
										, NULL, NULL, TRUE
										, launch_flags | ( OutputHandler?CREATE_NO_WINDOW:0 )//CREATE_NEW_PROCESS_GROUP
										, NULL
										, expanded_working_path
										, &task->si
										, &task->pi ) || FixHandles(task) || DumpError() ) ||
					( TryShellExecute( task, expanded_working_path, program, cmdline ) ) ||
					( CreateProcess( NULL//WIDE( "cmd.exe" )
										, GetText( final_cmdline )
										, NULL, NULL, TRUE
										, launch_flags | ( OutputHandler?CREATE_NO_WINDOW:0 )//CREATE_NEW_PROCESS_GROUP
										, NULL
										, expanded_working_path
										, &task->si
										, &task->pi ) || FixHandles(task) || DumpError() ) ||
               0
				  )
				{
					success = 1;
				}
			}
			if( success )
			{
				//CloseHandle( task->hReadIn );
				//CloseHandle( task->hWriteOut );
#ifdef _DEBUG
				xlprintf(LOG_NOISE)( WIDE("Success running %s[%s] in %s (%p): %d"), program, GetText( cmdline ), expanded_working_path, task->pi.hProcess, GetLastError() );
#endif
				if( OutputHandler )
				{
					task->hStdIn.handle 	= task->hWriteIn;
					task->hStdIn.pLine 	= NULL;
					//task->hStdIn.pdp 		= pdp;
					task->hStdIn.hThread  = 0;
					task->hStdIn.bNextNew = TRUE;

					task->hStdOut.handle 	 = task->hReadOut;
					task->hStdOut.pLine 	 = NULL;
					//task->hStdOut.pdp 		 = pdp;
					task->hStdOut.bNextNew = TRUE;
					task->hStdOut.hThread  = ThreadTo( HandleTaskOutput, (uintptr_t)task );
					ThreadTo( WaitForTaskEnd, (uintptr_t)task );
				}
				else
				{
					//task->hThread =
					ThreadTo( WaitForTaskEnd, (uintptr_t)task );
				}
			}
			else
			{
				xlprintf(LOG_NOISE)( WIDE("Failed to run %s[%s]: %d"), program, GetText( cmdline ), GetLastError() );
				CloseHandle( task->hWriteIn );
				CloseHandle( task->hReadIn );
				CloseHandle( task->hWriteOut );
				CloseHandle( task->hReadOut );
				CloseHandle( task->pi.hProcess );
				CloseHandle( task->pi.hThread );
				Release( task );
				task = NULL;
			}
		}
		LineRelease( cmdline );
		LineRelease( final_cmdline );
		Release( expanded_working_path );
		Release( expanded_path );
      /*
      if( path )
		SetCurrentPath( saved_path );
      */
		return task;
#endif
#ifdef __LINUX__
		{
			pid_t newpid;
			TEXTCHAR saved_path[256];
         xlprintf(LOG_ALWAYS)( WIDE("Expand Path was not implemented in linux code!") );
			task = (PTASK_INFO)Allocate( sizeof( TASK_INFO ) );
			MemSet( task, 0, sizeof( TASK_INFO ) );
			task->psvEnd = psv;
			task->EndNotice = EndNotice;
			task->OutputEvent = OutputHandler;
         if( OutputHandler )
			{
				pipe(task->hStdIn.pair);
				task->hStdIn.handle = task->hStdIn.pair[1];

				pipe(task->hStdOut.pair);
				task->hStdOut.handle = task->hStdOut.pair[0];
			}

			// always have to thread to taskend so waitpid can clean zombies.
			ThreadTo( WaitForTaskEnd, (uintptr_t)task );
			if( path )
			{
				GetCurrentPath( saved_path, sizeof( saved_path ) );
				SetCurrentPath( path );
			}
			if( !( newpid = fork() ) )
			{
            char *_program = CStrDup( program );
				// in case exec fails, we need to
				// drop any registered exit procs...
				//close( task->hStdIn.pair[1] );
				//close( task->hStdOut.pair[0] );
				//close( task->hStdErr.pair[0] );
				if( OutputHandler ) {
					dup2( task->hStdIn.pair[0], 0 );
					dup2( task->hStdOut.pair[1], 1 );
					dup2( task->hStdOut.pair[1], 2 );
				}
				DispelDeadstart();

				//usleep( 100000 );
				execve( _program, (char *const*)args, environ );
				lprintf( WIDE( "Direct execute failed... trying along path..." ) );
				{
					char *tmp = strdup( getenv( "PATH" ) );
					char *tok;
					for( tok = strtok( tmp, ":" ); tok; tok = strtok( NULL, ":" ) )
					{
						char fullname[256];
						snprintf( fullname, sizeof( fullname ), "%s/%s", tok, _program );

						lprintf( WIDE( "program:[%s]" ), fullname );
						((char**)args)[0] = fullname;
						execve( fullname, (char*const*)args, environ );
					}
					Release( tmp );
				}
				if( OutputHandler ) {
					close( task->hStdIn.pair[0] );
					close( task->hStdOut.pair[1] );
				}
				//close( task->hWriteErr );
				close( 0 );
				close( 1 );
				close( 2 );
				lprintf( WIDE( "exec failed - and this is ALLL bad... %d" ), errno );
				//DebugBreak();
				// well as long as this runs before
				// the other all will be well...
				task = NULL;
				// shit - what can I do now?!
				exit(0); // just in case exec fails... need to fault this.
			}
			else
			{
				if( OutputHandler ) {
					close( task->hStdIn.pair[0] );
					close( task->hStdOut.pair[1] );
				}
			}
			if( OutputHandler )
				ThreadTo( HandleTaskOutput, (uintptr_t)task );
			task->pid = newpid;
			lprintf( WIDE("Forked, and set the pid..") );
			// how can I know if the command failed?
			// well I can't - but the user's callback will be invoked
			// when the above exits.
			if( path )
			{
				// if path is NULL we didn't change the path...
				SetCurrentPath( saved_path );
			}
			return task;
		}
#endif
	}
	return FALSE;
}
Ejemplo n.º 9
0
static int CPROC ServerUnregisterIcon( uint32_t *params, uint32_t param_length
		  , uint32_t *result, uint32_t *result_length )
{
   xlprintf(LOG_NOISE)("Yeah, right.  Unregister the icon.  Sounds good.");
}
Ejemplo n.º 10
0
void OpenServer( void )
{
	l.MsgBaseServer = RegisterService( WIDE("systray"), functions, NUM_FUNCTIONS );
   xlprintf(LOG_ADVISORY)("l.MsgBaseServer is %lu", l.MsgBaseServer );
}
Ejemplo n.º 11
0
uintptr_t CPROC DrawSectorLines( INDEX pSector, uintptr_t unused )
{
	_POINT o, n;
	POBJECT object = CreateObject();
	INDEX iWorld = DrawThis.iWorld;
	INDEX pStart, pCur;
	int count=0;
	int priorend = unused;
	DrawThis.object = object;
		// origin at z +1
		scale( o, VectorConst_Y, 10.0 );//SetPoint( o, VectorConst_Z );
		// direction z+1
		SetPoint( n, VectorConst_Y );
		AddPlane( object, o, n, 0 );
		Invert( n );
		Invert( o );
		AddPlane( object, o, n, 0 );
		//DrawSpaceLines( display->pImage, pSector->spacenode );
		lprintf( WIDE("Adding Sector %d"), pSector );
	pCur = pStart = GetFirstWall( iWorld, pSector, &priorend );
	do
	{
		_POINT tmp;
      LOGICAL d = IsSectorClockwise( iWorld, pSector );
      //GETWORLD( display->pWorld );
      INDEX iLine;
		PFLATLAND_MYLINESEG Line;
		//VECTOR p1, p2;

      iLine = GetWallLine( iWorld, pCur );

		GetLineData( iWorld, iLine, &Line );
      // stop infinite looping... may be badly linked...
		count++;
		if( count > 20 )
		{
         xlprintf(LOG_ALWAYS)( WIDE("Conservative limit of 20 lines on a wall has been reached!") );
         DebugBreak();
			break;
		}
		{
			_POINT o, n, r;
			//int d;
         o[0] = Line->r.o[0];
         o[1] = Line->r.o[2];
         o[2] = Line->r.o[1];
         tmp[0] = Line->r.n[0];
         tmp[1] = Line->r.n[2];
         tmp[2] = Line->r.n[1];
			if( priorend )
			{
            lprintf( WIDE("prior end causes reversal...") );
				Invert( tmp );
			}
			if( d )
			{
            lprintf( WIDE("Sector clockwise..>") );
				Invert( tmp );
			}
			//SetPoint( o, Line->r.o );
			crossproduct( n, VectorConst_Y, tmp );
         /*
			if( priorend )
			{
            d = 1;
				Invert( n );
			}
			else
			{
				d = 1;
				}
            */
			lprintf( WIDE("Adding plane to object... ") );
			PrintVector( o );
			PrintVector( n );
			AddPlane( DrawThis.object, o, n, (GetMatedWall( iWorld, pCur )==INVALID_INDEX)?0:2 );
		}

		pCur = GetNextWall(l.world
								, pCur, &priorend );
	}while( pCur != pStart );
	if( IntersectObjectPlanes( object ) )
	{
		// destroy these planes, and add new ones.
		//priorend = FALSE;
      //DestroyObject( &object );
	}
	// oh - add lines first one way and then the other... interesting
	// to test both directions of priorend!
	if( !unused )
		DrawSectorLines( pSector, 1 );
	PutIn( object, DrawThis.root );
	{
		PFLATLAND_TEXTURE texture;
		INDEX iTexture = GetSectorTexture( l.world, pSector );
		GetTextureData( l.world, iTexture, &texture );
		SetObjectColor( object, texture->data.color /*BASE_COLOR_BLUE*/ );
	}

	return 0; // continue drawing... non zero breaks loop...
}
Ejemplo n.º 12
0
SaneWinMain( argc, argv )
{
	{
#ifndef BUILD_SERVICE
#ifndef LOAD_LIBNAME
		if( argc > 1 )
		{
			hModule = LoadFunction( libname = argv[1], NULL );
			if( hModule )
				arg_offset++;
		}
#endif

		if( !hModule )
		{
#ifdef LOAD_LIBNAME
			hModule = LoadFunction( libname = _WIDE(LOAD_LIBNAME), NULL );
			if( !hModule )
			{
#ifndef UNDER_CE
				lprintf( WIDE("error: (%")_32fs WIDE(")%s")
						 , GetLastError()
						 , strerror(GetLastError()) );
#endif
				return 0;
			}
			else
				arg_offset = 0;
#else
			lprintf( WIDE("strerror(This is NOT right... what's the GetStrError?): (%ld)%s")
					 , GetLastError()
					 , strerror(GetLastError()) );
			return 0;
#endif
		}
#endif
		my_argc = argc;
		my_argv = argv;

#ifdef BUILD_SERVICE
		{
			// look through command line, and while -L options exist, use thsoe to load more libraries
			// then pass the final remainer to the proc (if used)
#ifdef _WIN32
			for( ; arg_offset < argc; arg_offset++ )
			{
				if( StrCaseCmp( argv[arg_offset], WIDE("install") ) == 0 )
				{
					ServiceInstall( GetProgramName() );
					return 0;
				}
				if( StrCaseCmp( argv[arg_offset], WIDE("uninstall") ) == 0 )
				{
					ServiceUninstall( GetProgramName() );
					return 0;
				}
			}
			// need to do this before windows are created?
#ifdef BUILD_SERVICE_THREAD
			xlprintf(2400)( WIDE("Go To Service. %s"), GetProgramName() );
			SetupServiceThread( (TEXTSTR)GetProgramName(), DoStart2, 0 );
#else
			xlprintf(2400)( WIDE("Go To Service. %s"), GetProgramName() );
			SetupService( (TEXTSTR)GetProgramName(), DoStart2 );
#endif
#endif
		}
#endif
#ifndef BUILD_SERVICE
		{

			Main = (MainFunction)LoadFunction( libname, WIDE( "_Main" ) );
			if( !Main )
				Main = (MainFunction)LoadFunction( libname, WIDE( "Main" ) );
			if( !Main )
				Main = (MainFunction)LoadFunction( libname, WIDE( "Main_" ) );
			if( Main )
			{
				Main( argc-arg_offset, argv+arg_offset, MODE );
			}
			else
			{
				Begin = (BeginFunction)LoadFunction( libname, WIDE( "_Begin" ) );
				if( !Begin )
					Begin = (BeginFunction)LoadFunction( libname, WIDE( "Begin" ) );
				if( !Begin )
					Begin = (BeginFunction)LoadFunction( libname, WIDE( "Begin_" ) );
				if( Begin )
				{
					int xlen, ofs, arg;
					for( arg = arg_offset, xlen = 0; arg < argc; arg++, xlen += snprintf( NULL, 0, WIDE( "%s%s" ), arg?WIDE( " " ):WIDE( "" ), argv[arg] ) );
					x = (TEXTCHAR*)malloc( ++xlen );
					for( arg = arg_offset, ofs = 0; arg < argc; arg++, ofs += snprintf( (TEXTCHAR*)x + ofs, xlen - ofs, WIDE( "%s%s" ), arg?WIDE( " " ):WIDE( "" ), argv[arg] ) );
					Begin( x, MODE ); // pass console defined in Makefile
					free( x );
				}
				else
				{
					Start = (StartFunction)LoadFunction( libname, WIDE( "_Start" ) );
					if( !Start )
						Start = (StartFunction)LoadFunction( libname, WIDE( "Start" ) );
					if( !Start )
						Start = (StartFunction)LoadFunction( libname, WIDE( "Start_" ) );
					if( Start )
					{
						Start( );
					}
				}
			}
		}
#endif
	}
	return 0;
}
Ejemplo n.º 13
0
int main( void )
{
	uint32_t width, height;
	uint32_t imagecount = 0;
	uint32_t testimagesatinitialization = 0;
	Image blank;

	srand( time( NULL ) );

	for(width=0; width< NUM_REELS; width++)
	{
		g.uiSpeedCounter[width] = 0;
		g.uiSpeedStep[width] = 2;
		g.idx[width]= 0;
	}

	g.pdi = GetDisplayInterface();
	g.pii = GetImageInterface();

			//SetSystemLog( SYSLOG_FILE, stdout );
   SetSystemLoggingLevel( 1000 + LOG_NOISE);
	GetDisplaySize( &width, &height );;
	g.render = OpenDisplaySizedAt( 0, width, height, 0, 0 );
	UpdateDisplay(g.render);
	g.surface = GetDisplayImage( g.render );
	SetMouseHandler( g.render, MouseMethod, 0 );

//	blank = LoadImageFile( WIDE("blankimage.jpg"));
	blank = MakeImageFile(96,96);
   ClearImageTo( blank, BASE_COLOR_CYAN );
	g.playagain=LoadImageFile( WIDE("%images%/playagain.jpg"));
	g.playing  =LoadImageFile( WIDE("%images%/playing.jpg"));
   g.background = LoadImageFile( WIDE("%images%/background.jpg") );
//   g.background = blank;
	g.strip = LoadImageFile( WIDE("%images%/slot_strip.jpg") );
	g.nReels = NUM_REELS;


	{
      Image icons[NUM_ICONS];
		int n, m;
      INDEX idx;

		for( n = 0; n < NUM_ICONS; n++ )
		{
			icons[n] = MakeSubImage( g.strip, 96 * n, 0, 96, 96 );
		}
		n =  width = imagecount = height = 0;
		while(imagecount < NUM_IMAGES )
		{
			idx = rand()%NUM_ICONS;
			g.images[imagecount] = icons[idx];
			if( testimagesatinitialization )
			{
				BlotImage( g.surface, g.images[imagecount], width * 96, height * 96 );
				width++;
				if(!( width % 8 ))
				{
					width=0;
					height++;
				}
			}
         imagecount++;
  			for( m = 0; m < (( rand()%2 )  ); m++)
  			{
				g.images[imagecount] = blank;
				if( testimagesatinitialization )
				{
					BlotImage( g.surface, g.images[imagecount], width * 96, height * 96 );
					width++;
					if(!( width % 8 ))
					{
						width=0;
						height++;
					}
				}
				imagecount++;
			}

			if( testimagesatinitialization )
			{
				SyncRender( g.render);
				UpdateDisplay(g.render);
			}

		}
		if( !testimagesatinitialization )
		{
				SyncRender( g.render);
				UpdateDisplay(g.render);
		}


		for( n = 0; n < NUM_BLURS; n++ )
		{
			g.blurs[n] = MakeImageFile( 96, (NUM_PICS) * 96 );
         g.dodges[n] = MakeImageFile( 96, (NUM_PICS) * 96 );
			for( m = 0; m < NUM_IMAGES; m++ )
			{
            idx = rand()%NUM_IMAGES;
				g.reel[0][m] = g.images[idx];
			}
			Blur( g.blurs[n], g.reel[0] );
			DodgeEx( g.dodges[n], g.reel[0] , 2);
		}
		for( n = 0; n < NUM_REELS; n++)
		{
			g.subsurface[n]  = MakeSubImage( g.surface
													 , REEL_OFSX + REEL_STEPX * n
													 ,  REEL_OFSY
													 , REEL_WIDTH, (96 * NUM_PICS_IN_WINDOW) );
			g.testsurface[n] = MakeSubImage( g.surface, REEL_OFSX + REEL_STEPX * n + 480,  REEL_OFSY , REEL_WIDTH, (96 * NUM_PICS) );
		}
		g.statussurface = MakeSubImage( g.surface
												, 490, 10
												, 140,  68
												);


		g.backgroundsurface = MakeSubImage( g.surface
												, 0, 0
												, 640,  460
												);
	}
   g.flags.bBackgroundInitialized = 0;

	ThreadTo( ReadInput, 0 );

	{
		uint32_t start = GetTickCount();
		xlprintf(LOG_NOISE)("Started at %lu"
								 , start);
      g.ofs = 0;
		while( 1 )
		{
			if( g.flags.bSpinning )
			{
				DrawSpinningReels(FALSE);
			}

#ifndef __ARM__
         // scale to approx unit speeds..
  			WakeableSleep( 250 );
			//WakeableSleep( 33);
#endif
		}
	}
	CloseDisplay( g.render );
	UnmakeImageFile( g.strip );
   return 0;
}
Ejemplo n.º 14
0
void DrawSpinningReels( LOGICAL init )
{
//Real sorry about all the static variables.  It does look silly, but
//it is preferable to maintain the static-ly declared variables within this scope.
//could move them to the global, but right now it suits the task.
//Remember, this function is called 4 times a second, and it is only this function
//that uses these variables, so oh well.  Call a spade a spade....they're static to
//keep persistent data.
	int n;
	static LOGICAL bInit[NUM_REELS];  //static to maintain state.
	static uint32_t effectcount = 0;  //static to maintain state.
	static LOGICAL bPlaying = FALSE;  //static to maintain state.
	static int iBobble[5] = {0,-54,32,0,0}; //no need to declare this over and over 4 times a second.
   static INDEX idxBobbleCount[NUM_REELS]; //static to maintain state.
	uint32_t uiSmartYOffset = ( ( NUM_PICS - NUM_PICS_IN_WINDOW ) / 2 );
	static uint32_t bBobbling[NUM_REELS];

//  	xlprintf(LOG_NOISE)("DrawSpinningReels, init is %s   g.flags.bSpinning is %d"
//  							 , (init?"TRUE":"FALSE")
//  							 , g.flags.bSpinning
//    							 );
	for( n = 0; n < g.nReels; n++ )
	{
		if( init )
		{
			bInit[n] = TRUE;
			if( !bPlaying )
			{
				SetReelSpeedStep();
				bPlaying = TRUE;
				BlotScaledImageSizedTo( g.statussurface
											 , g.playing
											 , 0, 0
											 , 140,  68
											 );
			}
		}

		if( g.bReelSpinning[n] )
		{
         //uiStartStep is each reel's random starting order.
			if (  g.uiStartStep[n] )
			{
				g.uiStartStep[n]--;
			}
			else
			{
				{
               //uiSpeedStep demonstrates speed of reel movement (FAST, medium, and ....slllowwww). And stop.stutter.stop.
					if( g.uiSpeedStep[n] == 0 )
					{
  						BlotImageSizedTo( g.subsurface[n]
  											 , g.dodges[rand()%NUM_BLURS]
  											 , 0, 0
  											 , 0, 0, 96,  (96 * NUM_PICS_IN_WINDOW)
											 );
                  //effectcount is how long reels should be speedy-blurry, and normal-blurry.
						if( effectcount < (NUM_ITERATIONS / 2 ) )
						  effectcount++;
						else
						{
							effectcount = 0;
							g.uiSpeedStep[n]++;
						}
					}
					else if( g.uiSpeedStep[n] == 1 )
					{

						BlotImageSizedTo( g.subsurface[n]
  											 , g.blurs[rand()%NUM_BLURS]
											 ,  0 ,0
											 , 0, 0, 96,  (96 * NUM_PICS_IN_WINDOW)
											 );

						if( effectcount < (NUM_ITERATIONS / 2 ) )
						  effectcount++;
						else
						{
							effectcount = 0;
							g.uiSpeedStep[n]++;
						}
					}

					else if( g.uiSpeedStep[n] == 2 )
					{
						if(  g.uiSpeedCounter[n] == 0 )
						{
// could move this entire declaration into the global, and control the init process differently, but for now
// declaring static variable arrays suit the task.  the reason why these arrays are static is that
// state needs to be maintained every time the function is entered and exited, and these variables are
// not really global (that is, this scope is the only scope that counts).

// count[n] counts the number of times the reel has spun before it begins to stop.
// iteration[n] determines the maximum number of times the reel must spin before it begins to stop.
// last[y][x] maintains what the last pic was in that position, and is later incremented to demonstrate movement.
							static INDEX count[NUM_REELS], iteration[NUM_REELS];
							static INDEX last[NUM_REELS][NUM_PICS];

							if( bInit[n] )
							{
								int y;
								idxBobbleCount[n] = uiSmartYOffset;
                        bBobbling[n] = 0;
								for( y = 0; y < NUM_REELS; y++ )
								{
									last[y][0] = GetPositionIndex( TRUE, n );
									last[y][1] = last[y][0] + 1;
									last[y][2] = last[y][1] + 1;
									last[y][3] = last[y][2] + 1;
									last[y][4] = last[y][3] + 1;
								}

												  //this doesn't work yet....or does it?
								{

									IMAGE_RECTANGLE rect;
									rect.x = 0;//REEL_OFSX + REEL_STEPX * n;
									rect.y = 0;//REEL_OFSY;
									rect.width = REEL_WIDTH;
									rect.height = REEL_HEIGHT;
									//FixImagePosition( g.subsurface[n] );
									//SetImageBound( g.subsurface[n], &rect );
								}
								bInit[n] = FALSE;
								count[n] = 0;
								iteration[n] = (rand()%NUM_ITERATIONS) + ITERATIONS_OFFSET;
							}

							{
                        INDEX idx;
								int x;

  								for( x = uiSmartYOffset; x <  ( NUM_PICS_IN_WINDOW + uiSmartYOffset) ; x++)
  								{
									idx = last[n][x];
									DrawPosition( n, idx, x,  0);
								}
//--- This is just quality assurance.--------
//  								for( x = 0; x < NUM_PICS; x++ )
//  								{
//                               idx = last[n][x];
//  									  BlotImageSizedTo( g.testsurface[n]
//  															, g.images[idx]
//  															, 0, ( 96 * x )
//  															, 0, 0, REEL_WIDTH, ( 96 *  NUM_PICS )
//  															);
//  								}
//--- This is just quality assurance.--------

							}

							if( idxBobbleCount[n] == uiSmartYOffset )
							{
//  								xlprintf(LOG_NOISE)("Well, %d is shifting"
//  										  , n
//  										  );
								last[n][4] = last[n][3];
								last[n][3] = last[n][2];
								last[n][2] = last[n][1];
								last[n][1] = last[n][0];
								last[n][0] = GetPositionIndex( FALSE, n );
								count[n]++;
							}
							if(count[n] == (iteration[n] + 2 ) )
							{
								uint32_t x;
								for( x = uiSmartYOffset; x <  ( NUM_PICS_IN_WINDOW + uiSmartYOffset) ; x++)
								{
									DrawPosition( n, last[n][x], x,  iBobble[idxBobbleCount[n]]);
								}
								if( idxBobbleCount[n] >= ( NUM_PICS_IN_WINDOW + uiSmartYOffset) )
								{
                           xlprintf(LOG_NOISE)("Bobbling");
									g.uiSpeedStep[n] = DO_NOT_SPIN;
														  //g.bReelSpinning[n] = 0;
                           bBobbling[n] = 1;
									g.uiSpeedCounter[n] = 0;
                           g.ofs = -7; //might figure out if this is even necessary to maintain later.
									{
										int m;
										for( m = 0; m < NUM_REELS; m++ )
//  											if( g.bReelSpinning[m] )
											if( !bBobbling[m] )
											{
//  												xlprintf(LOG_NOISE)(" %d is * still *  spinning."
//  																		 , m
//  																		 );
												break;
											}
											else
											{
												idxBobbleCount[m] = uiSmartYOffset + 1;
											}

										if( m == NUM_REELS )
										{
											g.flags.bSpinning = 0;
											{
                                    //reset the bobbleness.
												int z;
												for( z = 0; z < NUM_REELS; z++)
												{
													g.bReelSpinning[z] = 0;
													idxBobbleCount[z] = uiSmartYOffset;
												}

											}
											if( bPlaying )
											{
												BlotScaledImageSizedTo( g.statussurface
																			 , g.playagain
																			 , 0 , 0  //490, 10
																			 , 140,  68
																			 );
												UpdateDisplay(g.render);
												bPlaying = FALSE;
											}
										}
									}
								}
								else
								{
									idxBobbleCount[n]++;
								}
							}
							else if( count[n] > iteration[n] )
							{
								g.uiSpeedCounter[n] = count[n] - iteration[n]  ;
							}
						}
						else
                     g.uiSpeedCounter[n]--;
					}
				}
			}
		}
   }
	UpdateDisplayPortion( g.render, REEL_OFSX, REEL_OFSY, REEL_STEPX*(g.nReels-1) + REEL_WIDTH,  REEL_HEIGHT   );
}