Re: Contest 2 Announcement:

new topic     » goto parent     » topic index » view thread      » older message » newer message

Patrick Barnes wrote:
> 
> On Sat, 27 Nov 2004 19:38:54 -0800, cklester <guest at rapideuphoria.com>
> wrote:
> > 
> > posted by: cklester <cklester at yahoo.com>
> > 
> > Patrick Barnes wrote:
> > >
> > > if validId(mainWindow) then
> > >       hWnd = getHandle(mainWindow)
> > > else
> > >       hWnd = 0
> > > end if
> > 
> > That helped. :)\
> > 
> > > > The preliminary framework contains a program called engine.exw, that
> > > > can be used to run matches.
> > > > This means you can actually test your programs with it... so get
> > > > downloading.
> > 
> > Can you make a way to stop a game without leaving those extra processes
> > running? Or is there already a way? ESCAPE key, perhaps? :)
> 
> It should work... 'q'... 
> It's possible that the bot processes remain after the Arena quits, if
> they get stuck inside the get_orders procedure and therefore don't
> head the MSG_STOP message...
> 
> -- 

Here is an alternative way to execute the bots:

--------------------------------
-- child_process.e
--------------------------------
include w32engin.ew

without warning

object void

global function child_process(sequence cmdline)
atom piProcInfo, siStartInfo, addr, hChildProcess
integer bFuncRetn

addr = allocate_string(cmdline) -- command to run child program ("exw
program.exw")

	-- Set up members of the PROCESS_INFORMATION structure.
	piProcInfo = struc("PROCESS_INFORMATION")


	-- Set up members of the STARTUPINFO structure.
	siStartInfo = struc("STARTUPINFO")
	put(siStartInfo,"cb",sizeof("STARTUPINFO"))


	-- Create the child process.
   bFuncRetn = CreateProcessA({
      0,			-- app name (we use command line instead)
      addr,			-- command-line
      0,			-- process security attributes
      0,			-- primary thread security attributes
      0,			-- handles are not inherited
      0,			-- creation flags
      0,			-- use parent's environment
      0,			-- use parent's current directory
      siStartInfo,	-- STARTUPINFO pointer
      piProcInfo})   -- receives PROCESS_INFORMATION

	free(addr)

	if bFuncRetn = 0 then
		free_mem(siStartInfo)
		free_mem(piProcInfo)
		return 0 -- error
	else
		hChildProcess = grab(piProcInfo,"hProcess")
		void = CloseHandle(grab(piProcInfo,"hThread"))
		free_mem(siStartInfo)
		free_mem(piProcInfo)
		return hChildProcess -- return handle to process
	end if

end function

-- kill the child process
global procedure child_kill(atom hChildProcess)
	if hChildProcess then
		void = TerminateProcess({hChildProcess,0})
		void = CloseHandle(hChildProcess)
	end if
end procedure

-- just closes the handle to the process
-- doesn't kill or affect the child process at all
global procedure child_close(atom hChildProcess)
	if hChildProcess then
		void = CloseHandle(hChildProcess)
	end if
end procedure

-- you can use this if you don't want to keep
-- track of the child and therefore don't
-- need the handle
global procedure child_exec(sequence cmdline)
	child_close(child_process(cmdline))
end procedure

----------------------------------------------

It uses the win32engin.ew, so you'd have to resolve conflicts with win32lib
possibly.  To start up a process, just use:

h = child_process("exw program.exw")

and it gives you a handle h (or 0 if it doesn't work).  Now if the child program
doesn't shut down like it is supposed to when you send it a message, you can
explicitly kill it with child_kill(h)...

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu