smcameron / space-nerds-in-space

Multi-player spaceship bridge simulator game. Captain your starship through adventures with your friends. See https://smcameron.github.io/space-nerds-in-space
GNU General Public License v2.0
731 stars 75 forks source link

laserbeams are often not rendered #240

Open smcameron opened 4 years ago

smcameron commented 4 years ago

The problem may be seen more clearly with this patch, which extends laserbeam duration and increases a starbase's chance of firing the laser.

diff --git a/snis.h b/snis.h
index 0ebf468..c92fa0e 100644
--- a/snis.h
+++ b/snis.h
@@ -398,7 +398,7 @@ struct ship_data {
 #define TURRET_LASER_WAVELENGTH 128
 #define TURRET_FIRE_INTERVAL 150
 #define PATROL_ATTACK_DIST (LASER_RANGE)
-#define LASERBEAM_DURATION 5 
+#define LASERBEAM_DURATION 15
 #define MINING_LASER_DURATION 2 
 #define MINIMUM_ATTACK_SPEED 3.0
 #define MINIMUM_TURN_SPEED 5.0
@@ -622,7 +622,7 @@ struct marketplace_data {
        float refill_rate;
 };

-#define STARBASE_FIRE_CHANCE 25 /* ... out of 1000, 10x per sec */
+#define STARBASE_FIRE_CHANCE 50 /* ... out of 1000, 10x per sec */
 #define STARBASE_SCALE_FACTOR (2.0)
 #define STARBASE_DOCK_TIME (1200) /* 2 minutes */
 struct starbase_data {

You can often see sparks emanating from ships being hit with laserbeams, but the laserbeams themselves are not rendered. It is not entity allocation failure, the enties for the laserbeam are allocated in init_laserbeam_data() in snis_client.c just fine.

Possibly something wrong with the triangle normals due to recent NaN fixes?

smcameron commented 4 years ago

Wonder if I could be hitting OpenGL's 32 texture per draw batch limit? Edit: I do not think this is likely.

smcameron commented 4 years ago

While it is not entity allocation failure (all such allocations succeed), I do nevertheless see that o->entity is sometimes NULL within laserbeam_move() in snis_client.c

I think that shouldn't happen, and I don't know how it is happening.

smcameron commented 4 years ago

I noticed it also has the same problem not rendering the laserbeams when the renderer is in wireframe mode, so this likely means it is not an issue with e.g. alpha blending.

smcameron commented 4 years ago

One possibility: The server sends a laserbeam over before the client knows about the target or the shooter. In this case, the laserbeam's entity will be NULL, and it will not ever be set. I do not think this can account for what I'm seeing though.

smcameron commented 4 years ago

I noticed that using pause/break key to bring up the graphics menu and switch on billboard outlines, the billboard outlines are not drawn when the problem is observed. This leads me to believe it's not a problem with the rendering code in graph_dev_opengl.c, but rather some problem causing the laserbeam objects to be skipped when rendering. NULL entities would be consistent with this, but I am not convinced that's the cause.

smcameron commented 4 years ago

Things that I think it's not:

It's not the material alpha. It's not the laser duration. It's not the entity non-linear scaling. It's not the entity being NULL.

smcameron commented 4 years ago

Hmm, I think it might be the target disappearing on the client so that in laserbeam_move() ...

        if (oid < 0 || tid < 0) {
                if (o->entity)
                        entity_set_mesh(o->entity, NULL);
                return;
        }

because, if on the server side, I make laserbeams inflict no damage, then I don't see the disappearing lasers symptom.

But this doesn't really make sense to me, because the two objects are clearly visible on the screen, and there should be a laserbeam between them, and sparks are emanating from the target. It's as if the target is already dead, but somehow still on the screen, without the laser ever appearing.