sega 500 precaching in ut2003 jeff “ezeikeil” giles

37
Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles [email protected]

Upload: gwendoline-allen

Post on 17-Jan-2018

220 views

Category:

Documents


0 download

DESCRIPTION

Precaching Data But what happens when you absolutely have to create a complicated object at runtime? In a word….”Chug!!!”

TRANSCRIPT

Page 1: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Sega 500

Precaching in UT2003

Jeff “Ezeikeil” [email protected]://gamestudies.cdis.org/~jgiles

Page 2: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Precaching Data

As you no doubt have noticed, UT uses tones of textures, materials and meshes in the average game.

And as you can well imagine, loading all these resources on the fly during runtime can be a bad idea.

Page 3: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Precaching Data

But what happens when you absolutely have to create a complicated object at runtime?

In a word….”Chug!!!”

Page 4: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Precaching Data

What’s happening is, just like in C++, when an object is first created, all it variables have to be initialized and assets assigned.

…and doing so can be a strain on the CPU.

Page 5: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Precaching Data

What we see happen is that, for a brief second (sometimes more) the game seems to “hick-up” or pause as the data for this new object is loaded.

And yeah…This can make game play suck!

Page 6: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Precaching Data

So how do we prevent this from happening?

Well the boys over at epic got clever on this one. They created functionality specifically to deal with this problem.

Page 7: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Precaching Data

What do they do?

The Precache ( pre-load ) the data into memory.

Page 8: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Precaching Data

There are 2 key functions provided for this.

AddPrecacheMaterial AddPrecacheStaticMesh

Page 9: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Behind the Scenes

Both of these are defined in the LevelInfo class as simulated functions.

Simulated, declares that a function may execute on the client-side when an actor is either a simulated proxy or an autonomous proxy. All functions that are both native and final are automatically simulated as well.

Page 10: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Behind the Scenes

Looking at how it’s used

simulated function AddPrecacheMaterial(Material mat){ local int Index;

if (mat == None) return;

Index = Level.PrecacheMaterials.Length; PrecacheMaterials.Insert(Index, 1);

PrecacheMaterials[Index] = mat;}

Page 11: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Behind the Scenes

Pass in the material we wish to store and it gets added to a list.

Note that this list is a dynamically sized. Array.

Index = Level.PrecacheMaterials.Length;PrecacheMaterials.Insert(Index, 1);PrecacheMaterials[Index] = mat;

Page 12: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Behind the Scenes

It actually comes with Insert and remove functionality which is similar to the STL.

Dynamic Arrays provide a way of having Static Array functionality with the ability to change the number of elements during run-time, in order to accommodate changing needs.

Page 13: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Behind the Scenes

Insert(int index_to_insert_at, int how_many_elements_to_insert) – this allows us to tell the array to create more

elements and create them starting at a specific location in the array.

Inserting 5 elements at index 3 will shift up (in index value) all elements in the array starting at index 3 and up (shifting them up by the number of elements to insert).

Page 14: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Behind the Scenes

Remove(int index_to_begin_removing_at, int how_many_elements_to_remove) – this allows us to remove a group of elements from the

array starting at any valid index within the array.

Note that any indexes that are higher than the range to be removed will have their index values changed, keep this in mind if you store index values into dynamic arrays.

Page 15: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Behind the Scenes

Dynamic Arrays also have a variable called Length, which is the current length (number of elements) of the dynamic array.

To access Length, using our example array, we would say -> IntList.Length.

Page 16: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Behind the Scenes

We can not only read the Length variable, but we can also directly set it, allowing us to modify the number of elements in the array.

Page 17: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Behind the Scenes

For more information on dynamic arrays, hit the UDN’s language reference.

It’s all there

Page 18: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

Just to demonstrate the point, I’m going to do something I’d NEVER do for real.

I’m going to load four 2048*2048 AND throw them at the screen at runtime when they are needed …not before.

Page 19: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

Watch that baby chug!

I’m just going to create a simple game type with a custom trigger, that when tripped, all these textures get thrown to the screen.

Page 20: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

To further complicate things, I’m importing all the textures via the editor and not script to ensure that there is as little precaching as possible.

Page 21: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

Our textures.

2048*2048 bmp’s I all their butt ugly glory!

Page 22: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

To create a 21MB monstrosity!

<Shudders>

Import all these in via the editor and create a texture package.

Page 23: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

So in the HUD class, I add the following:

function DrawHud(Canvas c){ super.DrawHud(c);

if(showBigTextures) DrawBIGTextures(c);}

Page 24: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

At the other function

if(DrawBIGTextures(canvas c){ c.SetPos(0,0); c.DrawIcon(texture'goober.bolt',0.16); c.DrawIcon(texture'goober.bolt1',0.08); c.DrawIcon(texture'goober.bolt2',0.04); c.DrawIcon(texture'goober.bolt2',0.02);}

Page 25: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

In effect just drawing these butt-ugly textures to the HUD if I’m touching a trigger.

I simply us the Touch and untouch function calls…

Page 26: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

…And the Untouch function is almost exactly the same…

So what happens?

function Touch(actor Other){ super.Touch(other); if(other.IsA('pawn')) //one ugly cast to access the HUD PrecachHUD(playerController(pawn(other).Controller).myHud).ToggleBigTextures();}

Page 27: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Bringing UT to it’s Knees

The game totally lags out and hangs for about 3 seconds on my home box.

An my PC is no slouch!

And it still chugs!...HARD!

P4 2.4gb cpu533mhz fast bus512 ddr ramG4 Ti4200 128ram

Page 28: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

So what this means to us

Even for a fairly powerful system, 21MB of textures is not a task to sneeze at as all this information still has to go from disk through the bus to the CPU then ram for processing by the game!

Page 29: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

So what this means to us

But notice that if I touch and untouch the trigger again and again, it doesn’t chug anymore.

That’s because these textures are now in memory.

Page 30: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

So what this means to us

So how do we uses these new functions?

Page 31: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

So what this means to us

In my new HUD class I add the following prebeginplay function. (In the sample code it’s in the gametype…both work fine)

simulated function PreBeginPlay(){ Super.PreBeginPlay(); Level.AddPrecacheMaterial(Material'Goober.bolt'); Level.AddPrecacheMaterial(Material'Goober.bolt1'); Level.AddPrecacheMaterial(Material'Goober.bolt2'); Level.AddPrecacheMaterial(Material'Goober.bolt3');}

Page 32: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

So what this means to us

In effect, we tell UT to load these textures into memory BEFORE the game starts.

Watch it run now…

Page 33: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

So what this means to us

Page 34: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

So what this means to us

It does still lags out a bit…but no where near as bad.

In other words….precaching is your friend…especially for large objects.

Page 35: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

How UT uses them

If your curious to see how it’s used in UT2003 presently, look in the gametype classes (bombingrun, deathmatch…) for some good examples.

Page 36: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

How UT uses them

Remember, it’s good for both static meshes and materials (textures).

Functionally doing the same thing.

Page 37: Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

End of Precache

This should cover all your needs for precaching textures and meshes.