Multiplayer game development announcement - Space Chooter
#11
RE: Multiplayer game development announcement - Space Chooter
A question for any experienced developer here:

As an exercise for learning, I decided to convert all the code I've ever created from GLUT to just Xlib. It's going quite well, and it's being very interesting to find out how things are done. As I mentioned before, I've been relying mostly on books, and some of what I'm doing now are just conversions of what I had previously done in GLUT before.

I'm stuck with Xlib with my redraw function. It redraws only when there's some input, but I need that it continuously redraw (it's a game ffs). Here is a summary of it, based mostly on Mark Kilgard's explanations:

Code:
while (1) {
    do {
        XNextEvent(dpy, &event);
        switch (event.type) {
             case ConfigureNotify:
                glViewport(0, 0, event.xconfigure.width, event.xconfigure.height);
                /* if you want to keep the window proportions */
                glMatrixMode(GL_PROJECTION);
                glLoadIdentity();
                gluPerspective(/*FOV*/ 100.0, /* aspect ratio */ (float) event.xconfigure.width / event.xconfigure.height, /*ZNEAR*/ 0.3, /*ZFAR*/ 80.0);
                glMatrixMode(GL_MODELVIEW);
             /* end of proportions */
             case Expose:
                 needRedraw = GL_TRUE;
                 break;
             case MotionNotify:
                 recalcModelView = GL_TRUE;
                 angle -= (lastX - event.xmotion.x);
             case ButtonPress:
                 lastX = event.xbutton.x;
                  break;
             case KeyPress:
                  ks = XLookupKeysym((XKeyEvent *) & event, 0);
                  if (ks == XK_Escape) exit(0);
                  break;
             case ClientMessage:
                 if (event.xclient.data.l[0] == wmDeleteWindow) exit(0);
                 break;
        }
    }
        while (XPending(dpy));
    if (recalcModelView) {
        glPopMatrix();
        glPushMatrix();
        glRotatef(angle, 0.0, 1.0, 0.0);
        glTranslatef(-8, -8, -bodyWidth / 2);
        recalcModelView = GL_FALSE;
        needRedraw = GL_TRUE;
    }
    if (needRedraw) {
        redraw();
       needRedraw = GL_FALSE;
    }
}

I've positioned the redraw function in many places and tried all things in the universe, and still I only get my program to redraw when there's some mouse or keyboard input. I spent 6 hours on this today, went through half of the book and no solution. In GLUT, I was able to easily do that via glutMainLoop.

The rest of the code works ok. I've got collision detection working, camera angles, multiple player tracking code... but the bloody thing only refreshes when there's an input.

Any tips?
Keeping in mind that I am a noob. =)
Shiunbird
Administrator

Trade Count: (1)
Posts: 553
Threads: 45
Joined: Mar 2021
Location: Czech Republic
Find Reply
12-14-2021, 09:51 PM
#12
RE: Multiplayer game development announcement - Space Chooter
Hi Shiun!

Having no experience using GL nor Xlib from a dev POV, just my thoughts after googling and reading some code:

It seems redrawing in Xlib is not done using this function, but "painting" or "drawing" everything (i.e. pixels) on the screen every time you want to refresh your window. Take an example from the handle_expose() event handler from the following doc:

http://ftp.dim13.org/pub/doc/Xlib.pdf

Look at page 59 for the main event loop, and then page 56 for the code of handle_expose(). Everything is redrawn explicitly with XDraw{Point,Arc,Line}, using a buffer or backing store for your pixels (for example an array).

Read also here:

https://stackoverflow.com/questions/5645...n-xwindows


Good luck!
TruHobbyist
Developer

Trade Count: (0)
Posts: 195
Threads: 21
Joined: May 2018
Find Reply
12-14-2021, 11:57 PM
#13
RE: Multiplayer game development announcement - Space Chooter
Thank you!
I will look it out.

I managed to test the collision and drawing codes using GLUT - and they seem ok. I just wanted to check everything with Xlib before I'm too far ahead in writing. The links you sent seem promising.

I'm following the examples from Kilgard's book and in the examples I've seen so far, it makes sense that the screen is not redrawn every time. So far I've seen so far only static visualisation examples. I'm hoping that down the line he will show some animations.
Shiunbird
Administrator

Trade Count: (1)
Posts: 553
Threads: 45
Joined: Mar 2021
Location: Czech Republic
Find Reply
12-15-2021, 08:48 AM
#14
RE: Multiplayer game development announcement - Space Chooter
The stack overflow link did the trick, thank you TruHobbist.

Basically, the difference between an application that draws X (and consequently OpenGL) continuously is whether or not you send a new expose event after redrawing. So I did the following change to my case Expose:


Code:
case Expose:
     needRedraw = GL_TRUE;
     XSendEvent(dpy, win, False, ExposureMask, &event);

and it worked.
Maybe I could use Expose instead of ExposureMask. I don't know what the difference is, but both build and run fine. Thanks once again!
Shiunbird
Administrator

Trade Count: (1)
Posts: 553
Threads: 45
Joined: Mar 2021
Location: Czech Republic
Find Reply
12-15-2021, 10:46 AM
#15
RE: Multiplayer game development announcement - Space Chooter
I did a lot of progress today.

- The basic structure is ready. Basically you fly around asteroids that are at the same time your friend and your enemy: you can use them to take cover, but they can also hit you and destroy your ship.
- The collision detection code is super simple. If the distance between any two given objects is less than the diameter of an object, they collided. I made it in such way that I can later on use pthreads for the server, and the space is also divided in quadrants so collision calculation only happens for objects in the same or neighbouring quadrants, saving CPU power.
- I wrote the dumbest bot system in the history of gaming industry: they move randomly and shoot when crossing line-of-sight. The only use of this is for me to write the aiming and line-of-sight evaluation code, nothing else. The final product won't have bots.
- The bots are basically 2 smaller spheres, until I come up with a model. All visuals are placeholders by now, while I write the game engine. They will be refined later.
- The server offers a visual of the universe, tied to the rendering engine. Once I have the FPS limiter in place, you will be able to run the server in text-mode only.
- The server will not use Motif, for ease of port, and once stripped of the connection to the rendering engine and added of endianness manipulation code, it will run basically anywhere.
- At the end of every work day, I build it on my Mac Pro, on my C8000 and on my Octane.

The client version will be very dumb:
- collision detection and object positioning done on server.
- Player can reduce number of polygons (for example, by not using a sphere for the asteroids, but perhaps a cube)
- Toggle to enable and disable textures and choose number of light sources.
- Simple gameplay: aim with the mouse, move the ship with WASP, shoot clicking.
I aim to fit everything in 115200 with overhead for 20Hz, making me well aware that 99% of the work will be the network code.

Here is a screenshot of my work on HP-UX 11.11 and my C8000:
   
(This post was last modified: 12-17-2021, 05:54 PM by Shiunbird.)
Shiunbird
Administrator

Trade Count: (1)
Posts: 553
Threads: 45
Joined: Mar 2021
Location: Czech Republic
Find Reply
12-17-2021, 05:53 PM
#16
RE: Multiplayer game development announcement - Space Chooter
I'm always jealous of developers. I wish I'd paid more attention when I was younger...no chance now of course.

Congrats on your project @Shiunbird, bloody awesome!

"My answer in answering the question: "What does the red spectrum tell us about quasars",There are various words that need to be defined: what is a spectrum, what is a red one, why is it red, and why is it so frequently linked with quasars?"..."What the hell is a quasar?


Onyx2 Octane2 O2 O2 Origin 200 Indigo2 R10000/IMPACT Indy
defaultrouteuk
Sponsor

Trade Count: (0)
Posts: 111
Threads: 28
Joined: Jul 2020
Location: Dubai
Website Find Reply
12-20-2021, 02:41 PM
#17
RE: Multiplayer game development announcement - Space Chooter
Thank you.

I'm not sure how old you are, but I just decided to learn it. I loved the role of sysadmin, but it is dying and my day job is such misery that I need to somehow reignite my love for computers, so I'm learning the stuff I wish I had known when I was a kid.

(Of course, as a kid I'd never have afforded 30.000 USD workstations XD)
Shiunbird
Administrator

Trade Count: (1)
Posts: 553
Threads: 45
Joined: Mar 2021
Location: Czech Republic
Find Reply
12-20-2021, 08:11 PM
#18
RE: Multiplayer game development announcement - Space Chooter
My progress stalled a bit, for bizarre reasons.
I was writing using my Mac Pro running Mojave and using XCode. Xlib goes well, but I know that Motif is broken and it's way beyond my skill to fix it.
Xlib is enough for the server code, but I realized I'd get truly lost if I were to write all the server code first and then jump over to write the client. The client requires motif.

So I switched to my C8000, which is fine, but for some random reason the only USB keyboard that my C8000 detects is the awful HP German keyboard that came with it. I set it to US keyboard layout but I can't type a pipe. Writing anything quickly became a chore - copying/pasting a pipe every time you need it gets old very fast.

I switched to writing on my Octane, but my girlfriend complained about the noise. =\
Her tolerance ends after 30 minutes.

So I fired up my Power Mac G5, as I know of versions of motif that are known to work with OS X 10.5. However, as you all know, I'm a very beginner programmer and at all not very familiar with the build systems. When I try to build Motif, I get the following:


Code:
/bin/sh ../../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../include -I.. -I./.. -DXMBINDDIR_FALLBACK=\"/usr/X11R6/lib/X11/bindings\" -DINCDIR=\"/usr/X11R6/include/X11\" -DLIBDIR=\"/usr/X11R6/lib/X11\" -I/usr/X11/include  -I/usr/X11/include  -g -O2 -Wall -g -fno-strict-aliasing -Wno-unused -Wno-comment -fno-tree-ter   -MT Label.lo -MD -MP -MF .deps/Label.Tpo -c -o Label.lo Label.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../include -I.. -I./.. -DXMBINDDIR_FALLBACK=\"/usr/X11R6/lib/X11/bindings\" -DINCDIR=\"/usr/X11R6/include/X11\" -DLIBDIR=\"/usr/X11R6/lib/X11\" -I/usr/X11/include -I/usr/X11/include -g -O2 -Wall -g -fno-strict-aliasing -Wno-unused -Wno-comment -fno-tree-ter -MT Label.lo -MD -MP -MF .deps/Label.Tpo -c Label.c  -fno-common -DPIC -o .libs/Label.o
In file included from /usr/X11/include/X11/Xft/Xft.h:41,
                 from XmRenderTI.h:33,
                 from Label.c:77:
/usr/X11/include/ft2build.h:56:38: error: freetype/config/ftheader.h: No such file or directory
In file included from XmRenderTI.h:33,
                 from Label.c:77:
/usr/X11/include/X11/Xft/Xft.h:42:10: error: #include expects "FILENAME" or <FILENAME>
In file included from XmRenderTI.h:33,
                 from Label.c:77:


I have freetype installed (actually, Apple used to distribute it with X11 - they still officially supported it), but I have no idea why make can't find freetype. I already symlinked all around and tried both Apple's freetype and the one I installed from brew (a bit newer). So my questions are:

1. Chance are low, but anyone here with experience in HP-UX who could point me why I can't type a pipe? The same keyboard set to US types a pipe file in every computer I've tried.

2. Does anyone know, from the build commands, where it is trying to find ft2build.h, so I can create the link and help make?

In the meantime, I will go back to copy-paste pipes, because vacations are short and I want to make good use of them. =))

Thanks, as always.
Shiunbird
Administrator

Trade Count: (1)
Posts: 553
Threads: 45
Joined: Mar 2021
Location: Czech Republic
Find Reply
12-21-2021, 12:36 PM
#19
RE: Multiplayer game development announcement - Space Chooter
(12-21-2021, 12:36 PM)Shiunbird Wrote:  1. Chance are low, but anyone here with experience in HP-UX who could point me why I can't type a pipe? The same keyboard set to US types a pipe file in every computer I've tried.


Unless there's some unknown PDC or ISL flags for setting the keyboard layout, which I doubt, you may correct any mapping of your keyboard using xmodmap.

Had the same problem with my HP 9000 because original keyboards cost a hefty amount for having just an HP logo, so you end up using a cheapo one but need to remap some keys.


(12-21-2021, 12:36 PM)Shiunbird Wrote:  2. Does anyone know, from the build commands, where it is trying to find ft2build.h, so I can create the link and help make?


ft2build.h is not the problem, it's the header it is referring to in the code that is not found:

/usr/X11/include/ft2build.h:56:38: error: freetype/config/ftheader.h: No such file or directory

Translated to humanZ language:

Code:
Shiunbird: # make
gcc: Go preprocess Label.c, cpp
|
+-cpp: Oh no! Hey gcc, in file /usr/X11/include/ft2build.h, at line 56 and character offset 38, I can't find an included file named:

freetype/config/ftheader.h: No such file or directory

Could you please tell Shiunbird to tell me where to look for that file using the -I flag?


Shiunbird: # (looks up the header file in the system and includes the corresponding path using an -I flag to gcc)

How is the -I flag set?

In principle, you would just need to hand it over to gcc like so:

Code:
/bin/sh ../../libtool  --tag=CC  --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../include -I.. -I./.. -I/path/to/freetypedirectory


But to achieve this you have to edit the files used by your build system. In the assumption that you are using GNU build system (configure/make) combo, I would recommend to:


Code:
# make distclean
# export CPPFLAGS="-I/path/to/freetypedirectory"
# configure
# make


This way it will add -I/path/to/freetypedirectory to every invocation of gcc but at least you will solve your problem.

BTW, /path/to/freetypedirectory must point to the --> parent directory <-- of the freetype directory in the freetype/config/ftheader.h so the preprocessor can find it.

For example, if this header is stored at /usr/local/include/freetype/config/ftheader.h, don't do:

Code:
# export CPPFLAGS="-I/usr/local/include/freetype/config/ftheader.h"

But do:

Code:
# export CPPFLAGS="-I/usr/local/include"


HTH
TruHobbyist
Developer

Trade Count: (0)
Posts: 195
Threads: 21
Joined: May 2018
Find Reply
12-21-2021, 06:18 PM
#20
RE: Multiplayer game development announcement - Space Chooter
Thanks for the tips! I will try tomorrow (if I don't spend all the day racking my stuff up - the delivery of my rack is late by a day).

I hope xmodmap - I was not aware of the command.
I have 6 keyboards, including an IBM model M from 1986 using DIN-PS2 then PS2-USB adapters - the keyboard works with every single computer I've ever tried in my life EXCEPT the C8000 =\\\\\\\
Shiunbird
Administrator

Trade Count: (1)
Posts: 553
Threads: 45
Joined: Mar 2021
Location: Czech Republic
Find Reply
12-21-2021, 08:19 PM


Forum Jump:


Users browsing this thread: 1 Guest(s)