Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: [1] 2 3

Author Topic: Hypothetical challenge: eliminate lag  (Read 15021 times)

reactorcore

  • Guest
Hypothetical challenge: eliminate lag
« on: February 03, 2014, 05:08:07 AM »

In plenty of video games where you are largely not restricted to do anything you want, including spawning lots of new objects, especially when each of them is enabled with physics behavior and perhaps also have some sort of unique type information stored in them, you run the risk of ending up in a situation of lagging the game severely.

Basically a real-time game simulation can turn into a slideshow, because its trying to compute something too heavy for a computer to handle. This applies to Starsector and similar games with lots of physics/collision enabled objects. This problem alone limits how big battles can be or how complex ships and their systems are allowed to be.

This is a bit of a hypothetical challenge to see if there is a way to come up with some sort of optimization solution, that would allow for larger amounts of objects to exist at once and make mass events not cause severe lag in a game.

Essentially, its an attempt to see if or how lag can be eliminated in a complex real time simulation, such as Starsector, with stuff like ships, asteroids, nebulas, projectiles, beams, trails and explosions, by finding a balance that would still allow the game to uphold the complexity of a Starsector-like simulation while allowing it to simulate much larger events, with more ships and more objects, without generating lag.

This can be done either by creating a convincing illusion using or using some sort of optimization trick that while might sacrifice some accuracy in the physics or rendering calculation of huge epic events, it at least makes them plausible without turning the game into a slideshow or slowing it down significantly.

Look at this image:



In the center there is a player ship, meanwhile around it are lots of asteroids flying randomly. Each asteroid is unique and each of them store information individually on things like Size, What its made from, Direction its flying in and Speed at which it flies at. Everything has the ability to collide or get collided with and they can be influenced by a force, such as gravity to move.

There are a few important rules:
1. No matter is allowed to be destroyed or created, it can only change shape or type. (Asteroids can turn into clouds of harmless dust when shot at or destroyed, but never removed from existence. This dust remains in the background and its possible to collect it to compress new asteroids out of that dust)
2. Each asteroid must retain its uniqueness in the end, even if some sort of simulation accuracy is omitted during the phase at which lag happens.
3. The game must not turn into a slideshow if laggy situation happens.
4. What ever optimizations are done, the game must still feel consistent (from the player's perspective)

The goal is to make the simulation work in the way that it follows the above rules, but must never get to a point where the game will lag.

What can you think of that could achieve this goal? The optimizations can be anything as long as they keep in mind the rules mentioned above and don't break them.
Logged

reactorcore

  • Guest
Re: Hypothetical challenge: eliminate lag
« Reply #1 on: February 03, 2014, 05:14:13 AM »

To throw around some ideas, one optimization trick would be to make asteroids that collide with one another with enough force to merge together, merging them physically into one object, while merging their unique data into a single entity, thus reducing the amount of objects that need to be calculated and kept track of at once.

Same applies to dust clouds from destroyed asteroids. When two or more dust clouds are close to each other, they can merge into a single larger cloud.
Logged

reactorcore

  • Guest
Re: Hypothetical challenge: eliminate lag
« Reply #2 on: February 03, 2014, 05:25:14 AM »

Another thing could be to stop calculating physics all together for objects that get hit by something very potent, like an asteroid with huge mass and speed will not cause smaller asteroids it collides with to calculate their new trajectory or how fast their debris and dust fly off from the overwhelming impact.

If there are particle effects involved, then those can be shut down as well to save rendering performance for the smaller asteroids, as they get obliterated by the huge asteroid while it crashed into them.

This can make a huge performance difference along with the above post's merging optimization solution in an event where there are 1000 tiny asteroids in an area and a single giant asteroid just plows through them with enormous speed and force, colliding with the 1000 tiny asteroids in its path and destroying them by merging their mass with its own.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Hypothetical challenge: eliminate lag
« Reply #3 on: February 03, 2014, 08:41:52 AM »

I think that, in order to offer a prescription, you need to have a proper understanding of the actual problems.

The game's optimization issues are largely not physics-related at all.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

reactorcore

  • Guest
Re: Hypothetical challenge: eliminate lag
« Reply #4 on: February 03, 2014, 10:37:34 AM »

A few more ideas:

Minimum size for certain objects

If asteroids cannot be smaller than a ½m in diameter, then that eliminates the problem of dividing bigger objects into smaller objects infinitely, by setting a standard for objects not to go below that threshold of size. While you can't apply this to everything such as the player ship and the missiles it fires, there are generic objects like asteroids and dust clouds that can use this optimization trick to set a maximum limit of how many of them can fit on the screen at once.


Grouping AI processes

In events of massive amounts of AI controlled units, when a threshold for X amount of units controlled by an AI is surpassed, like-minded or same-team AI units can be made to follow a single directive, instead of having individual units have independently operated AI. Aside from grouping AI processes, temporarily grouping objects with the same behaviour (like a swarm of asteroids flying in the same direction at the same-ish speed) is also another idea as an optimization trick.


Flattening sub-system functionality

For huge spaceship with individually rotating turrets, in events where a computer is unable to handle that complexity of subsystems, the simulation could substitute the detailed space craft with a more simple version, where all of its functionality is flattened. Instead of rendering and calculating the existence of each individual turret, its rotation and status, you'd only have the flattened hull sprite of the ship with the turret already embedded with the base sprite and the game would only remember the offset of the turret, spawning projectiles from that point without bothering to simulate the actual turret itself. Works like the Level of Detail technique used in many games to simulate environments and objects in larger amounts or faster, without having the game to lag. The closer and more scarce you get, the more detail is presented and calculated.


One thing I'm still really not sure how to solve is the problem of lots of very different objects, completely scattered chaotically and moving in random directions and random speeds. What to do with collision in these cases? How to simplify such scenarios without violating any of the rules mention in the OP? I hope its not impossible to think of some type of way to optimize and tame that from dragging a game down to crawl.
Logged

reactorcore

  • Guest
Re: Hypothetical challenge: eliminate lag
« Reply #5 on: February 03, 2014, 10:47:37 AM »

I think that, in order to offer a prescription, you need to have a proper understanding of the actual problems.

The game's optimization issues are largely not physics-related at all.

I agree with the first statement, although since a game designer can shape the behaviour and composition of the universe of a game, pretty much like a god, the problems themselves change at each new theory, making it tricky to identify the actual problems.

For example, a human character can be represented as a single animated sprite in one game, while in another, the human character is made from individual pivoting parts that the code rotates and moves to create an animation. Meanwhile physics can be simulated accurately, but they can also be simulated roughly for better performance at the cost of less detailed results.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Hypothetical challenge: eliminate lag
« Reply #6 on: February 03, 2014, 12:30:52 PM »

I don't get where you're trying to go with this, I guess :) 

I don't think there is some perfect way to optimize any game in any situation that fits all games equally- that seems like a bit of a chimaera and not worth pursuing.  TBH, I think you're committing one of the big no-nos of game development here; starting with a pet premise rather than developing a game and then looking at the weak spots very carefully and scientifically and then choosing what to cut or optimize.

For example, in SS, most of the lag has nothing to do with physics or AI, even though both of these areas can involve quite a lot of math per frame. 

Most of the heavy load is in the fancy stuff that's being done visually, some of which could be simplified but look as good if not better than it does now (but with other costs, namely some time, memory and money being spent on content, instead of using procedural techniques that fit all cases well but are often slower than a content-based approach).
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: Hypothetical challenge: eliminate lag
« Reply #7 on: February 03, 2014, 02:18:29 PM »

Write the entire thing by hand in assembly language, and make direct calls to the GPU, bypassing any API for graphics or physics calls. Make use of parallel processors where possible.   ;D
Logged

c plus one

  • Commander
  • ***
  • Posts: 174
  • 'Make Jumpgates Great Again!'
    • View Profile
Re: Hypothetical challenge: eliminate lag
« Reply #8 on: February 03, 2014, 02:46:27 PM »

Write the entire thing by hand in assembly language, and make direct calls to the GPU, bypassing any API for graphics or physics calls. Make use of parallel processors where possible.   ;D

1984 called; they'd like your time-inten$ive-work-of-art development workflow back. I think we should keep it... :D
Logged
Quote from: Lopunny Zen
you are playing them wrong then..

Don't tell me I'm playing anything wrong in a singleplayer sandbox game. Just don't.

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: Hypothetical challenge: eliminate lag
« Reply #9 on: February 03, 2014, 03:26:07 PM »

 :D following the 1984 theme.

Make it a text adventure!

You see an asteroid coming at you off the port bow. You then:
1. Steer away from the asteroid
2. Accelerate forward to move ahead of the asteroid intercepting
3. Fire teh pew pew at it!
4. Eject!

You choose to: 3

You fire the pew pew at the incoming asteroid!

It explodes!

The fragments of the asteroid follow newtons first law of motion, it tears your ship apart and gives a face full of space rock!

You are dead.  :-[
Logged

c plus one

  • Commander
  • ***
  • Posts: 174
  • 'Make Jumpgates Great Again!'
    • View Profile
Re: Hypothetical challenge: eliminate lag
« Reply #10 on: February 03, 2014, 03:35:24 PM »

:D following the 1984 theme.

Make it a text adventure!

excellent. and to make it even more like one very famous quasi-text adventure in particular.....i have a feeling that I'm in a twisty maze of travel-drive jump gates, all alike. oh, and my Hyperion is about to be eaten by a grue. ::)
Logged
Quote from: Lopunny Zen
you are playing them wrong then..

Don't tell me I'm playing anything wrong in a singleplayer sandbox game. Just don't.

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Hypothetical challenge: eliminate lag
« Reply #11 on: February 03, 2014, 03:45:55 PM »

An Asteroid approaches your ship from 20 degrees starboard.  It is an ordinary-looking asteroid.  The sensors do not report any Grues.

"turn left"

-->That command doesn't work.  The ship drifts closer to the Asteroid.

"TURN LEFT"

-->That command doesn't work.  The Asteroid is very close now.

"Turn Left"

-->You attempt to turn left, but it's too late, and the asteroid crashes into your hull.  You take 300 Armor points of damage in Cell B3; please mark down the state of Cell B3 on the included Ship Diagram.

!@#!@#!@!!!

An enemy ship approaches at 33 degrees to port on your ship's current heading.  It is currently 1200 SU away and is traveling at 238 SU/sec.  

"Fire Guns"

You fire the guns at empty space, missing the enemy ship.  Please perform the necessary trigonometry to aim your cannons and try again.  See the Ship Diagram for the conversion factor to convert SU to meters.  You have 4.21123 seconds before the other ship opens fire.
« Last Edit: February 03, 2014, 03:51:14 PM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Gothars

  • Global Moderator
  • Admiral
  • *****
  • Posts: 4403
  • Eschewing obfuscatory verbosity.
    • View Profile
Re: Hypothetical challenge: eliminate lag
« Reply #12 on: February 03, 2014, 03:53:37 PM »

He. Back in the Battleships Forever days I used to play against the framerate. Make some enemy ships that can reproduce themselves according to different rules, all with (potentially) exponential growth. Then you have to shoot them buggers down and try to limit their growth. As their numbers grow the framerate is getting lower and lower. You lost when the game freezes. More fun that you'd think, quite a bit of strategy involved.

Uh, yeah, only tangential to the problem.



You fire the guns at empty space, missing the enemy ship.  Please perform the necessary trigonometry to aim your cannons and try again.  See the Ship Diagram for the conversion factor to convert SU to meters.  You have 4.21123 seconds before the other ship opens fire.

 ;D
Logged
The game was completed 8 years ago and we get a free expansion every year.

Arranging holidays in an embrace with the Starsector is priceless.

reactorcore

  • Guest
Re: Hypothetical challenge: eliminate lag
« Reply #13 on: February 04, 2014, 02:57:20 AM »

I don't get where you're trying to go with this, I guess :) 

I don't think there is some perfect way to optimize any game in any situation that fits all games equally- that seems like a bit of a chimaera and not worth pursuing.  TBH, I think you're committing one of the big no-nos of game development here; starting with a pet premise rather than developing a game and then looking at the weak spots very carefully and scientifically and then choosing what to cut or optimize.

For example, in SS, most of the lag has nothing to do with physics or AI, even though both of these areas can involve quite a lot of math per frame. 

Most of the heavy load is in the fancy stuff that's being done visually, some of which could be simplified but look as good if not better than it does now (but with other costs, namely some time, memory and money being spent on content, instead of using procedural techniques that fit all cases well but are often slower than a content-based approach).

Its true that each game is different and they all have their own solutions for their problems, but lets say a game like Starsector could be made to work on a seamless universe. As in, there is no seperation between combat and travel, instead it would all happen on the same plane. Basically, imagine if the battle areas in Starsector had no bounds or have a limited space to move in. I'm trying to figure out if that would be possible by using a logical approach with Starsector's combat gameplay as the basis (along with its content-based modular component approach).

While in the current limited sense the biggest bottleneck are the graphics as you said, but what if you're trying to simulate a universe that extends several lightyears with a huge bunch of other objects ranging from ships, nebulae, asteroids, planets, stars and debris?

Now, while you don't have to render objects within the visual range, which means objects out of range are even more lighter than the ones in view, but there might be a very large amount of them, which could potentially be even more computationally intensive than rendering graphics within the visual range.
Logged

Gothars

  • Global Moderator
  • Admiral
  • *****
  • Posts: 4403
  • Eschewing obfuscatory verbosity.
    • View Profile
Re: Hypothetical challenge: eliminate lag
« Reply #14 on: February 04, 2014, 04:15:26 AM »

The limiting factor of an "all at one level" approach is not so much technical as gameplay related. For example, if you had to cross a starsystem at the same scale you're doing fights, it would take a very long time. Or you'd have to have grossly enlarged ships.
Logged
The game was completed 8 years ago and we get a free expansion every year.

Arranging holidays in an embrace with the Starsector is priceless.
Pages: [1] 2 3