Space Nerds In Space

Re: Space Nerds In Space

Postby smcameron » 12 Mar 2020, 23:41

Just a brief dev update for 2020-03-12, nothing revolutionary, just incremental progress:

Image
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby MCMic » 13 Mar 2020, 11:57

smcameron {l Wrote}:Not sure it's a great idea to invite people at a conference to touch your keyboards with this corona virus thing out there.


They just annouced schools and university will be closed starting monday.
Most likely the event will be canceled, but they did not annouce it yet. It’s in one month, we’ll see.

[EDIT] It’s just been officially canceled.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Space Nerds In Space

Postby CapnRobberts » 14 Mar 2020, 16:25

Can anyone clarify the space_partition system to me?

It looks like space_partition is a 2D Grid of space_partition_entry structures stored in the content handle.
where the space_partition_entry is a linked list of entries.
There is an offset stored from where the entry pointer is back to the actual start of the entity structure so that you can get from an entity to it's entry struct.

Does that sounds correct?

I see that the common pointer on the partition is used, but I don't see where it is ever initialized.

I'm still just trying to understand what all is going on in the server.

Thanks.
[CapnRobberts]
User avatar
CapnRobberts
 
Posts: 17
Joined: 08 Feb 2020, 17:27

Re: Space Nerds In Space

Postby smcameron » 15 Mar 2020, 04:00

You've probably already seen this, but I'll post the link if not: Collision Detection in Space Nerds in Space.

It's been awhile since I've looked at this code. You're correct it's a 2D grid of cells. The "common" cell is for things that wander outside the area mapped into this 2D grid of cells as a "catch all". Normally there shouldn't be much if anything in the common cell.

The common pointer is initialized in add_sp_entry().

{l Code}: {l Select All Code}
static void add_sp_entry(struct space_partition *p, struct space_partition_entry *e, int cell)
{
        struct space_partition_entry **c;

        if (cell < 0)
                c = &p->common; <--- notice the ampersand here.  c is the address of common.
        else
                c = &p->content[cell];

        e->cell = cell;
        if (!(*c)) {
                (*c) = e;  <--- common gets initialized here.
                e->next = NULL;
                e->prev = NULL;
                return;
        }
        (*c)->prev = e;
        e->next = *c;
        e->prev = NULL;
        (*c) = e;
}


add_sp_entry() is called by space_partition_update(), which is part of the space partition API and is called whenever a snis_entity has its position updated (see set_object_location() in snis_server.c). Common will get updated if space_partition_update() calls get_cell() and gets -1 back, which happens if the item being added into the space partition has x, y coords that are "out of bounds".

Yes, p->offset is essentially a constant value that is the offset into the struct snis_entity at which the entity's space_partition_entry resides. This is kind of like the how the berkeley queue thing works (see output of "man 3 queue" if you're curious about that.) This kind of thing is called an "intrusive data structure".

This allows me to pass a pointer to a struct snis_entity into space_partition_update(), but the space_partition code does not need to know what a snis_entity is, it only needs to know the offset into it where it can find the space_partitition_entry to store its data. In theory, I could use this space partition code for any game, as it is totally self-contained (notice space-part.h and space-part.c do not #include any other files apart from standard library stuff.)

And then later, space_partition_process() via process_cell() can subtract this p->offset to get the struct snis_entity pointer to pass along through the function pointer supplied as a parameter.

So, it's a really old-school way of writing generic code. A C++ programmer would probably do it with templates instead. It should no doubt have more comments in there, esp. in space-part.h to explain how the thing is supposed to be used.

Chasing around all those pointers is probably horrible for cache misses. OTOH, once you've got the space_partition_entry, you probably also have the snis_entity in the cache already because the space_partition_entry is inside the snis_entity.

I won't pretend that any of this is *good* code. But it works well enough. (and just looked at the git history and there are 2 commits for space-part.c and space-part.h, the initial commit in 2013, and one commit in 2019 to fix an unused variable warning, so it must not be too terrible since it's needed very close to zero maintenance in 7 years.)

Hope that helps.
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby CapnRobberts » 15 Mar 2020, 04:38

That does help, thanks.

I'm not sure that templates/generics would be the right way in C++, maybe a polymorphic interface, but I can see how this would be functional for straight C.
[CapnRobberts]
User avatar
CapnRobberts
 
Posts: 17
Joined: 08 Feb 2020, 17:27

Re: Space Nerds In Space

Postby smcameron » 15 Mar 2020, 05:00

smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby CapnRobberts » 15 Mar 2020, 23:37

{l Code}: {l Select All Code}
p = &go[i];
   if (p->type != OBJTYPE_PLANET) {
      /* This can happen if a planet gets destroyed and another object re-uses the ID. */
      o->tsd.starbase.associated_planet_id = -1;
      return;
   }


Is there any technical reason a starbase can't orbit something else like an asteroid?
[CapnRobberts]
User avatar
CapnRobberts
 
Posts: 17
Joined: 08 Feb 2020, 17:27

Re: Space Nerds In Space

Postby smcameron » 16 Mar 2020, 01:44

Not really, other than that it wasn't designed this way. (Though if you are asking if you stick the ID of an asteroid into a planet's associated_planet_id and set starbases_orbit = 1, will it work? The answer is no. The asteroids move. Planets do not, the orbit of the starbase would be miscalculated, I think (he says, without looking at the code.))

But there are actually two concepts of how starbases "orbit" planets, the original conception, and a relatively new, failed experiment. I think you are asking about the new failed experiment (but maybe you don't realize it is a failed experiment). The "failed experiment" variant doesn't really even work right, and is not active by default. I mean, the starbases do orbit -- actually move in a circle around the planet -- contingent upon running "set STARBASES_ORBIT=1" on the demon screen -- however, NPC ships don't really know how to deal with this, so they congregate around the place the starbase used to be. So having starbases orbit planets in the sense of "actually move in a circle around the planet" falls into the "failed experiment" category. Some discussion of it here..

In the original conception of "orbit", with "STARBASES_ORBIT == 0" (which is the default), then starbases do not move around planets or move at all, but they may still have an "associated planet", which they are placed nearby, but stationary, as if they were in orbit. The way they detect the situation that their planet has been destroyed (e.g. by the game master) is to find out that the ID they record for this object no longer exists or is not a planet. Now that I think about it, the ID should not get re-used (contrary to the comments, aka "lies") as they are monotonically increasing. I suppose the ID could wrap around after 2-billion or so, but then we've got other problems. In any case, in this original conception of "orbiting" an associated planet, mostly what the associated planet is used for is in messages describing where the starbase is, and the code that generates those messages assume that whatever's in associated_planet_id refers to a planet if it isn't -1.

Starbases can be in deep space, not orbiting anything, in which case the associated planet id is -1.

You should probably forget about the notion of orbiting starbases except to mean only "hovering near a stationary object.".
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby CapnRobberts » 21 Mar 2020, 00:13

Yes, I see how the AI logic only stores fixed coordinate points, not an offset relative to an entity.
[CapnRobberts]
User avatar
CapnRobberts
 
Posts: 17
Joined: 08 Feb 2020, 17:27

Re: Space Nerds In Space

Postby smcameron » 31 Mar 2020, 14:25

There's a new starsystem, "Zaurno". Execute "make update-assets" to get it.
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby smcameron » 02 Apr 2020, 00:10

Daid mentioned over on bridgesim.net that he had added voice chat to Empty Epsilon. Now, that is a good idea. An idea worth borrowing. And so I have. Now you can press-to-talk F12 and you voice will be delivered to your crew-mates, or CTRL-F12, and your voice will be delivered to all players within the snis_server instance. I will say this hasn't been very well tested, I don't really have a good way to test it properly, but it does work for what little testing I've done (two clients both running on the same machine). I'm using libopus to do the audio compression, and it seems to do a pretty good job, it doesn't take a huge amount of bandwidth or anything. Took about a day to code up, and 6 days to debug, lol.
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby smcameron » 02 Apr 2020, 18:33

Realized the voice chat code I committed yesterday would not behave well if multiple clients transmitted audio concurrently. I was using a single stream for all VOIP decoding and mixing on each client, so it would interleave audio packets from different clients in this single stream, and the decoder is not stateless, so this would confuse the decoder anyway, probably making it produce even worse sounds than you might expect. It would work ok, so long as two clients didn't try to talk at the same time.

So I fixed it today, so that as many as 4 clients may transmit audio concurrently, and they will be decoded and mixed from separate streams within each client receiving them. In theory. Haven't really tested it much at all.
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby smcameron » 03 Apr 2020, 03:17

So I tried out my voice chat over the internet, and uncovered a little problem... makes a bit of horrible noise. Up to now I had only tried it locally, and it seems to work fine that way for me. So, still some work for me to do there.

OTOH, I got some video of what it's like to run with the clients local (in Virginia) and the server remote (in New York). About 25ms latency, about 21.5k/sec per client (43k /sec total) bandwidth usage if I "set npc_ship_count = 100", "set asteroid_count = 0", and "regenerate" on the demon screen to cut out a lot of stuff. And it seemed more or less... totally playable? Color me surprised. Here's a video:

Image
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby smcameron » 03 Apr 2020, 19:52

So voice chat may be working fine after all. I remembered that I've heard that "horrible noise" before, in contexts unrelated to SNIS (playing youtube videos), and that I've previously solved it by unplugging and re-plugging my USB audio interface. Today I was unable to recreate the "horrible noise" problem and voice chat seemed to work fine going from Virginia to New York and back again. Quick demo: https://youtu.be/XngYX7ncPeA

Also, I wrote up some instructions for running SNIS in the cloud
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby smcameron » 07 Apr 2020, 21:17

Quick little demo of planetary lightning effect. It really makes the atmospheres of the planets come alive, especially on the dark sides.

https://youtu.be/U4qt-avWa7s

Youtube really compresses the dark areas of the video pretty heavily, so I'm not sure it comes across very well in this video. it's a fairly subtle effect in any case.

Edit: Here's a still shot with exaggerated amounts of lightning just to show the effect. Captured in a still shot it's a little less convincing than when they just flash briefly.

Image
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby charlie » 08 Apr 2020, 14:26

Wow. That looks awesome. :shock:
Free Gamer - it's the dogz
Vexi - web UI platform
User avatar
charlie
Global Moderator
 
Posts: 2131
Joined: 02 Dec 2009, 11:56
Location: Manchester, UK

Re: Space Nerds In Space

Postby smcameron » 09 Apr 2020, 02:12

Another quick update. Added a warp gate effect, not a big deal but better than the nothing that was there before, and also now NPC ships are respawned at warp gates instead of at just random locations.

https://youtu.be/t1Vhyg9SCjU
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby MCMic » 09 Apr 2020, 12:54

smcameron {l Wrote}:Another quick update. Added a warp gate effect, not a big deal but better than the nothing that was there before, and also now NPC ships are respawned at warp gates instead of at just random locations.

https://youtu.be/t1Vhyg9SCjU


Regarding the constant battle, should’nt ships respawn in a warpgate situated in area controlled by their faction, or get assigned the faction which controls the area where they respawn, whatever seems better?

There are weird behavior of lighting from explosions on the planet in the video, like this:
Screenshot_20200409_135304.png


Also at https://youtu.be/t1Vhyg9SCjU?t=90 there is a visible line on the left of the planet.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Space Nerds In Space

Postby smcameron » 09 Apr 2020, 14:25

Yeah, I'm going to do something about the constantly fighting bugs in a jar, not sure quite what, but something.

As for that weird effect of the explosion, ha, that's just because the explosion is made of billboards and what you're seeing is a giant billboard intersecting the planet.

Particularly explosions start off with one *giant* spark that rapidly shrinks in size to give the impression of an initial blast, and I think you captured that giant spark intersecting the planet.

The code is this:
{l Code}: {l Select All Code}
        if (nsparks > 40) { /* a big explosion, add one big freakin' stationary spark that fades quickly */
                        add_spark(x, y, z, 0, 0, 0, 15, color, &spark_material, 0.8, 0, 250.0);


The size of that spark could be as much as 1000 units. hmm, that planet has a radius of 6506 though (diameter 13012) so no spark should be *that* big, so hmm, that is weird.

Edit: Oh, the billboard mesh used is 50x50 units, so that spark could be as big as 50000x50000 units, so yeah now it makes sense.
{l Code}: {l Select All Code}
        particle_mesh = mesh_fabricate_billboard(50.0f, 50.0f);


Edit again: The visible line on the left of the planet is a rendering artifact due to the two render passes for near and far objects to get enough z-buffer precision. It used to be a lot worse than it is now. There is a closed issue for this: https://github.com/smcameron/space-nerd ... /issues/80

Now we dynamically choose the distance at which the boundary between these render passes exists from a few candidate distances, and try to choose it such that it does not intersect any large objects to avoid this artifact. Sometimes it's not possible to avoid all large objects so we choose the distance which intersects the fewest large objects, so sometimes there are still artifacts.

Code is in entity.c, in render_entities(). It could be that "500" as the dividing line between "big" and "small" entities is too small, as the planet atmosphere and planet rings are where you notice these artifacts the most, and they are both *much* bigger than 500.

{l Code}: {l Select All Code}
                        /* For each boundary candidate, count large object intersections */
                        if (pass == 0 && n_passes > 1) {
                                if (e->m->radius * max_scale < 500)
                                        continue; /* ignore small objects in choosing render pass boundary */
                                camera_to_entity.v.x = e->x - camera_pos.v.x;
                                camera_to_entity.v.y = e->y - camera_pos.v.y;
                                camera_to_entity.v.z = e->z - camera_pos.v.z;

                                float zdist = vec3_dot(&camera_to_entity, &camera_look);
                                if (zdist < 0)
                                        continue; /* behind camera, ignore (should already be frustum culled). */
                                if (e->m->geometry_mode == MESH_GEOMETRY_POINTS) /* Ignore fake stars, etc. */
                                        continue;
                                if (e->m->radius * max_scale >= 299999.0)
                                        continue; /* Hack to ignore warp tunnels (r=300000) */

                                /* Check each candidate boundary for intersection with this object */
                                for (k = 0; k < 3; k++)
                                        if (fabsf(zdist - boundary_candidate[k]) < e->m->radius * max_scale)
                                                boundary_intersects[k]++;
                        }
                }

                if (pass == 0 && n_passes > 1) {
                        /* Find the boundary candidate with the fewest large object intersections */
                        last_candidate = candidate;
                        candidate = 0;
                        if (boundary_intersects[candidate] != 0) {
                                /* Test for less than or *equal* so we choose the *farthest* among equals so
                                 * that any resulting artifacts are more likely to occupy less screen space
                                 * and be less obnoxious. With a little luck, it will even move it to a place
                                 * that is invisible, like the back side of a planet.
                                 */
                                if (boundary_intersects[1] <= boundary_intersects[candidate])
                                        candidate = 1;
                                if (boundary_intersects[2] <= boundary_intersects[candidate])
                                        candidate = 2;
                        }

                        if (last_candidate != candidate) {
                                /* Recalculate the camera transforms if the render pass boundary was changed
                                   to avoid some intersecting object */
                                render_pass_boundary = boundary_candidate[candidate];
                                calculate_camera_transform_near_far(&cx->camera, &rendering_pass[0],
                                                                render_pass_boundary, cx->camera.far);
                                calculate_camera_transform_near_far(&cx->camera, &rendering_pass[1],
                                        cx->camera.near, render_pass_boundary + render_pass_boundary / 1000.0);
                        }
                }


The more you know about how all this stuff works, the more flaws you will see. It's all smoke and mirrors.
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby smcameron » 09 Apr 2020, 22:15

Ok, I made the respawning choose a warp gate based on faction (although sometimes a faction has no warp gates) and 1/3rd of the time a respawn will happen the old way (no warp gate just random positioning). This helps some with the excessive fighting.

I also made it so that now NPC ships will chase after and collect cargo containers if they are close enough and slow moving enough relative to the ship's max speed. This cuts down on the growth of the number of objects (and thus also on network traffic) but at the expense that loose cargo containers are quite a bit scarcer than they used to be. Also ships used to be spawned with their cargo bays completely filled. Now they spawn half-filled so they have some empty bays to allow for picking up floating cargo. That also means there are less total cargo bays floating around because when a ship is destroyed whatever is in its hold is released. Now there's half the total cargo containers to be potentially released, and of those which are released, some will be scooped up by other NPC ships.
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby smcameron » 12 Apr 2020, 22:53

After integrating a pull request from Byron Roosa, Space Nerds in Space now builds and runs on Mac OSX (Mojave) I'm told. You can see the pull request discussion here, there might be some tips about how to build it in there (I don't have a Mac or any knowledge of how things are done on a Mac myself). https://github.com/smcameron/space-nerd ... e/pull/276
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby smcameron » 18 Apr 2020, 18:43

Lately I have been experimenting with porting snis_client from GTK2 to SDL2 (guided by a patch my friend Jeremy wrote 5 years ago.) I have just about everything working except if you resize the window, it doesn't clamp things to a fixed aspect ratio. Other than that, I think everything else is working (of course there might be bugs that I don't know about.)

With these patches (which I haven't committed yet), this does mean the limited client doesn't exist anymore, which is unfortunate. (Is it possible to use SDL without opengl? I'm not sure. If it is, maybe the limited client can continue to exist with a bit more work.)

Moving to SDL2 has some potential benefits. Perhaps a windows port would be easier, in case someone wants to try that. Perhaps webassembly might be a possibility.

For now, the patches are here, in case anybody wants to play with them: https://github.com/smcameron/space-nerd ... -615894494
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby CapnRobberts » 18 Apr 2020, 20:36

You would need some form of networking middle-ware library to get a native Windows version working. The Winsock API is not 100% function level compatible with Berkeley sockets. SDL Net provides a platform independent interface to sockets.
[CapnRobberts]
User avatar
CapnRobberts
 
Posts: 17
Joined: 08 Feb 2020, 17:27

Re: Space Nerds In Space

Postby smcameron » 19 Apr 2020, 00:49

According to this, it doesn't look to be too badly different: https://tangentsoft.net/wskfaq/articles ... ility.html
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: Space Nerds In Space

Postby CapnRobberts » 19 Apr 2020, 00:52

Yes you can write your own dual purpose code with #defs for the different parts, many open source games have gone that route and constatnly reinvent the wheel :) if you are going to merge SDL into a branch on the repository, just using SDLs networking layer may be simpler.
[CapnRobberts]
User avatar
CapnRobberts
 
Posts: 17
Joined: 08 Feb 2020, 17:27

Who is online

Users browsing this forum: No registered users and 1 guest