So tell me why are theese scripts causing the game to lag a lot

Started by pawel345, October 15, 2013, 10:47:53 AM

Previous topic - Next topic

pawel345

# Make terrain.crpl
# Created on: 10/12/2013 1:25:39 PM
# ------------------------------------------
# Allow the core to connect to the network and not be counted towards victory.
$xstart:15
$ystart:20
$xlenght:3
$ylenght:3
$TerrainH:10

#ShowTraceLog
once
Self CONST_COUNTSFORVICTORY 0 SetUnitAttribute
Self CONST_CANREQUESTAMMO 1 SetUnitAttribute
Self CONST_CONNECTABLE  1 SetUnitAttribute
Self CONST_SHOWAMMOBAR  1 SetUnitAttribute
Self CONST_MAXAMMO 50 SetUnitAttribute
Self CONST_AMMO 0 SetUnitAttribute
Self CONST_PACKETREQUESTDELAY  0 SetUnitAttribute
Self CONST_REQUESTPACKETS  1 SetUnitAttribute
Self CONST_SNIPERTARGET 0 SetUnitAttribute
Self CONST_NULLIFIERDAMAGES  0 SetUnitAttribute
Self CONST_THORTARGET  0 SetUnitAttribute

endonce


Self CONST_AMMO GetUnitAttribute 2 gt if
   #<-xstart <-ystart GetTerrain not if
   <-xlenght 0 do
      <-ylenght 0 do
   <-xstart J add <-ystart I add <-TerrainH SetTerrain
   
      loop
   loop
#endif
   Self CONST_AMMO GetUnitAttribute ->ammo
   
   Self CONST_AMMO <-ammo 2 sub SetUnitAttribute
   else   
   #<-xstart <-ystart GetTerrain if
   <-xlenght 0 do
      <-ylenght 0 do
   <-xstart J add <-ystart I add SetVoid
   <-xstart J add <-ystart I add 1 GetUnitsInRange
                  0 do
                      2 Destroy
                     loop
   
      loop
   loop
endif
20 delay 

#endif

# Gate.crpl
# Created on: 10/12/2013 5:40:36 PM
# ------------------------------------------
$width:3
$height:3
$maxammo:20
$Theight:8
#ShowTracelog
once
Self CONST_CELLHEIGHT <-height SetUnitAttribute
Self CONST_CELLWIDTH  <-width SetUnitAttribute
Self CONST_CONNECTABLE  1 SetUnitAttribute
Self CONST_CANREQUESTAMMO  1 SetUnitAttribute
Self CONST_PACKETREQUESTDELAY 20 SetUnitAttribute
Self CONST_MAXAMMO  <-maxammo SetUnitAttribute
Self CONST_SHOWAMMOBAR 1 SetUnitAttribute
Self CONST_AMMO 0 SetUnitAttribute
Self CONST_REQUESTPACKETS  1 SetUnitAttribute
Self CONST_CREATEPZ  0 SetUnitAttribute
Self CONST_SNIPERTARGET 0 SetUnitAttribute
Self CONST_NULLIFIERDAMAGES  0 SetUnitAttribute
Self CONST_THORTARGET  0 SetUnitAttribute
Self "main" <-width 3 div <-height 3 div SetImageScale
endonce


Self CONST_AMMO GetUnitAttribute <-maxammo 1 sub gt if
   <-width 0 do
      <-height 0 do
         CurrentX <-width 2 div floor sub J add
         CurrentY <-height 2 div floor sub I add <-Theight SetTerrain
      loop
   loop   
      Self 2 Destroy
else
<-width 0 do
   <-height 0 do
         CurrentX <-width 2 div floor sub J add
         CurrentY <-height 2 div floor sub I add  SetVoid
      loop
   loop      
Self CONST_AMMO GetUnitAttribute ->ammo if
Self CONST_AMMO <-ammo 0.2 sub SetUnitAttribute
endif
endif
20 Delay


The delay was put there to make the game run more smoothly but it makes just a big pause every now and then. The map I'm using these scripts:



knucracker

SetTerrain....
That is a beast of inefficiency (at least currently).

It was only ever really meant for making small changes to the terrain spread out over time (kind of how Terps work).  Every time it is called, the texture for the modified cell has to get redrawn and pushed to the GPU.  This can take milliseconds (an eternity).  Do it for a cell every game frame and all is well.  Do it for hundreds of cells per game frame and lag.

Now there are some things I can do to make it more efficient to update nearby cells within the same frame, and I may get to them in the next few weeks so they will be part of the first major update with Colonial Space.  But SetTerrain will still remain a things to be used cautiously.

pawel345

Ok I will try to keep that in mind^^ but right now a piece of void long enough for the relays not to reach is the only thing that can be used as "gates".


Eketek

Quote from: virgilw on October 15, 2013, 10:52:43 AM
SetTerrain....
That is a beast of inefficiency (at least currently).

It was only ever really meant for making small changes to the terrain spread out over time (kind of how Terps work).  Every time it is called, the texture for the modified cell has to get redrawn and pushed to the GPU.  This can take milliseconds (an eternity).  Do it for a cell every game frame and all is well.  Do it for hundreds of cells per game frame and lag.

Now there are some things I can do to make it more efficient to update nearby cells within the same frame, and I may get to them in the next few weeks so they will be part of the first major update with Colonial Space.  But SetTerrain will still remain a things to be used cautiously.

Implementing effects by computing new textures and pushing them out to the GPU is kind of a bad idea, since modern GPUs are actually supposed to handle most graphical effects, in addition to providing a lot of matrix math (and they are quite good at it).  If at all possible, I would advise using shaders for this, so that you can just change the input parameters and not have to play with heavyweight graphics effects.  Quite possibly, you can even pre-compute all possible edges, then use a compositing shader to combine them, so that you can fully cache the terrain, then only change the terrain texture and give it new texture coordinates for the edge effect.  (You can even make edge effects available for easy modification in the map editor this way)

Also, if, as I now suspect, there isn't much else going on behind the level load other than texture generation, this change would make levels load almost instantly, regardless of size (assuming you don't use the freed resources for more sophisticated graphics).