C code for multiple windows

Hi all.

I’ve written C code to create multiple windows in SDL by invoking child
processes. Works in Linux and Windows (although some limitations in Windows).

If Sam doesn’t mind the bandwidth, I could post the code to the mailing list
(11KB zip file), else if anyone is interested in it, email me directly and
I’ll send it to you.

The current code is just a test of the concept. To be useful, some type of
interprocess communication needs to be added (it’s on my TODO list).

Jeff

If you don’t end up posting to the mailing list, I’d be interested in seeing that.

Thanks,
~ Justin> Hi all.

I’ve written C code to create multiple windows in SDL by invoking child
processes. Works in Linux and Windows (although some limitations in Windows).

If Sam doesn’t mind the bandwidth, I could post the code to the mailing list
(11KB zip file), else if anyone is interested in it, email me directly and
I’ll send it to you.

The current code is just a test of the concept. To be useful, some type of
interprocess communication needs to be added (it’s on my TODO list).

Jeff


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I would also like to see it; shouldn’t be too hard to port it to Mac OS
X
Cheers,
JerichoOn Nov 15, 2003, at 8:07 PM, jaspeers at comcast.net wrote:

If you don’t end up posting to the mailing list, I’d be interested in
seeing that.

Thanks,
~ Justin

Hi all.

I’ve written C code to create multiple windows in SDL by invoking
child
processes. Works in Linux and Windows (although some limitations in
Windows).

If Sam doesn’t mind the bandwidth, I could post the code to the
mailing list
(11KB zip file), else if anyone is interested in it, email me
directly and
I’ll send it to you.

The current code is just a test of the concept. To be useful, some
type of
interprocess communication needs to be added (it’s on my TODO list).

Jeff

Hi all.

I’ve written C code to create multiple windows in SDL by invoking child
processes. Works in Linux and Windows (although some limitations in Windows).

Go ahead and post it to the mailing list.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Here it is. This is the original test code without interprocess
communication. I’ve got IPC working for Linux, but I’m still struggling to
get Windows to do IPC. I’ll post new code when and if I can get that working.
Hope people will find it useful.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdlmwtest.zip
Type: application/x-zip
Size: 11447 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031117/0089b43f/attachment.binOn Monday 17 November 2003 09:15 am, Sam Lantinga wrote:

Go ahead and post it to the mailing list.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

j_post wrote:

Here it is.

I like the comments. Someone enjoying Win32 programming? :*)

Peter

Does anyone? :slight_smile:

Inter-Process Communications is now working in both Linux and Windows. The
attached zip file has the IPC code (and the more acerbic comments have been
removed :wink:

If anyone can port this to Mac and send me the mods, I’d be much obliged.
Hope some of you find this code useful. Now on to build apps with it…

Jeff
-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdlmwipc.zip
Type: application/x-zip
Size: 13201 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031117/8ffb00bb/attachment.binOn Monday 17 November 2003 05:33 pm, Peter Strempel wrote:

I like the comments. Someone enjoying Win32 programming? :*)

This is off topic and on-topic in a roundabout way.

I was looking into making Jeff’s interprocess SDL code run on Mac OS X,
and figured it would be simple since his code uses standard calls.
However, headers like sys/msg.h, mqueue.h are not available on OSX!
Reading through Apple’s documentation, I found that “Interprocess
communication is in a state of transition”. About the only IPC facility
available is signal.h

Do any programmers familiar with OSX/mach have knowledge about this? It
seems like there has to be something at a lower level than cocoa’s
message systems.

Again, I realize this is more suited for an OSX mailing list, but since
I was investigating for a SDL-related project I thought I’d start here.

Thanks, John

Good catch, John. Thanks.On Monday 17 November 2003 09:05 pm, John Philip wrote:

I think your code would be simplified if you include the header
<signal.h> and near the very end of main() if you changed:

if (!child)
{
if (child1)
{
sprintf(message, “kill -9 %d”, child1Pid);
system(message);
}

if (child2)
{
    sprintf(message, "kill -9 %d", child2Pid);
    system(message);
}

if (child3)
{
    sprintf(message, "kill -9 %d", child3Pid);
    system(message);
}

msgctl(msgId, IPC_RMID, 0);

}

to read:

if (!child)
{
if (child1) kill(child1Pid, SIGKILL);
if (child2) kill(child2Pid, SIGKILL);
if (child3) kill(child3Pid, SIGKILL);

msgctl(msgId, IPC_RMID, 0);

}

Hi
Are there any XCode (Mac OS X 10.3 dev-tools) project-templates for SDL?
The ones for Project Builder (which worked fine) seem not to work with
XCode (don’t appear in the list after installing SDL 1.2.6).

Thx
Arne

I’m working on it now.On Nov 18, 2003, at 3:07 PM, Arne Claus wrote:

Hi
Are there any XCode (Mac OS X 10.3 dev-tools) project-templates for
SDL?
The ones for Project Builder (which worked fine) seem not to work with
XCode (don’t appear in the list after installing SDL 1.2.6).

Thx
Arne

Hi
Are there any XCode (Mac OS X 10.3 dev-tools) project-templates for SDL?
The ones for Project Builder (which worked fine) seem not to work with
XCode (don’t appear in the list after installing SDL 1.2.6).

It looks like the XCode templates are the same format as Project Builder.
Darrell is updating the projects (right Darrell?)

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Okay, after mucking around for a while, I have come up with Xcode-savvy
templates. I have updated the “SDL Application” and “SDL OpenGL
Application” templates to have native targets, compile and link under
10.3, and appear in the “New Project…” window.

I have not updated the “SDL Cocoa Application” and “SDL Custom Cocoa
Application” templates, as the former has problems opening MainMenu
from the nib file and the latter cannot find icon.bmp. The creators of
these will need to take a look.
I have not updated the SDL target template file. I do not fully
understand what data belongs in this file, or the format thereof. I
have contacted Apple requesting relevant documentation be created.
Perhaps its creator could also investigate.

Also, it appears that the new Xcode feature “Zero-Link”, which
postpones linking until runtime, is not compatible with SDL and/or
SDL’s Cocoa wrapper. A SDL project with Zero-Link enabled compiles
fine, attempts to launch, and fails with the message “ZeroLink: unknown
symbol ‘_SDL_Init’”. There may be a workaround to use Zero-Link with
SDL, but for now I have disabled Zero-Link in the templates.

It appears that Apple no longer uses the path
"/Developer/ProjectBuilder Extras/Project Templates/" for storing
templates. To Install these, decompress the attached file, and place
the resulting “SDL” folder into “/Library/Application
Support/Apple/Developer Tools/Project Templates”
-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDL_Templates.tar.gzip
Type: application/octet-stream
Size: 39586 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031118/3a35ab0d/attachment.obj

The ZeroLink problem is easily fixed, and it’s a good thin. On my low
end hardware, without ZeroLink, it takes 20 seconds after pressing the
compile button to get into the Atlantis test app. With ZeroLink, 3.5s.

Anyhow, to fix it, you need to add SDL.framework to the project.
(assume a default location of ~/Library/Frameworks). ZeroLink will
only dynamically load libraries that are part of the project, so right
now it fails whenever it tries to call anything in SDL.framework.

Also, any hope of getting the Xcode projects directly into CVS, rather
than in a tgz file? I believe that the .nib and .xcode formats are
both entirely text based, simply to allow easy project file management
using cvs? This would allow much easier updating of the SDL project
(as it was, I had to go manually add the new cpuinfo stuff, which while
not difficult, was a bit annoying until i figured out what was going
on).

Richard SchreyerOn Nov 18, 2003, at 4:49 PM, John Philip wrote:

Okay, after mucking around for a while, I have come up with
Xcode-savvy templates. I have updated the “SDL Application” and “SDL
OpenGL Application” templates to have native targets, compile and link
under 10.3, and appear in the “New Project…” window.

I have not updated the “SDL Cocoa Application” and “SDL Custom Cocoa
Application” templates, as the former has problems opening MainMenu
from the nib file and the latter cannot find icon.bmp. The creators of
these will need to take a look.
I have not updated the SDL target template file. I do not fully
understand what data belongs in this file, or the format thereof. I
have contacted Apple requesting relevant documentation be created.
Perhaps its creator could also investigate.

Also, it appears that the new Xcode feature “Zero-Link”, which
postpones linking until runtime, is not compatible with SDL and/or
SDL’s Cocoa wrapper. A SDL project with Zero-Link enabled compiles
fine, attempts to launch, and fails with the message “ZeroLink:
unknown symbol ‘_SDL_Init’”. There may be a workaround to use
Zero-Link with SDL, but for now I have disabled Zero-Link in the
templates.

It appears that Apple no longer uses the path
"/Developer/ProjectBuilder Extras/Project Templates/" for storing
templates. To Install these, decompress the attached file, and place
the resulting “SDL” folder into “/Library/Application
Support/Apple/Developer Tools/Project Templates”
<SDL_Templates.tar.gzip>

Hi,

I couldn’t help noticing the following part of a comment in your code:

“// Unfortunately, Windoze will create the child process physically on top of
// the parent process, so the user will have to move the child window after
// it’s been created.”

In the function concerned you do :

GetStartupInfo(&startUpInfo);

Then create the new process.

Now, this is not a flame, please do not take it that way.

In the windows documentation the STARTUPINFO struct has two members for setting the window position of the new process ‘dwX’ and ‘dwY’. To get them to work you need to also set the flag STARTF_USEPOSITION

If they are both set to CW_USEDEFAULT then it should place it somewhere sensible. Otherwise set the values to some number.

so you probably want to do the following:

pid_t launch(int number, int id)
{
GetStartupInfo(&startUpInfo);
sprintf(cmdLine, “%s %d %d”, program, number, id);

startUpInfo.dwX=CW_USEDEFAULT;
startUpInfo.dwY=CW_USEDEFAULT;
startUpInfo.dwFlags|=STARTF_USEPOSITION;

etc …
etc …

}

Hopefully that will solve the placement problem.

I haven’t even bothered to test this though. So please inform me if I have just made myself look stupid. Or if I missed the point entirley :slight_smile:

Otherwise I found it to be enlightening code…

Hope this helps,

  • Tom

Now, this is not a flame, please do not take it that way.

Not at all :wink:

If they are both set to CW_USEDEFAULT then it should place it somewhere
sensible. Otherwise set the values to some number.
so you probably want to do the following:

No matter what I do to startUpInfo.dwX, etc, Windows insists on placing the
child processes smack on top of the parent process. I’m compiling on Linux
using mingw32 and testing on WinXP Professional. Perhaps it would be
different if I had a native Windows compiler, but I don’t see how.

Otherwise I found it to be enlightening code…

Thanks :slight_smile:

JeffOn Wednesday 19 November 2003 01:32 pm, Tom Wilson wrote: