Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles

Similar presentations


Presentation on theme: "Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles"— Presentation transcript:

1 Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles jgiles@artschool.com http://gamestudies.cdis.org/~jgiles

2 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.

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

4 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.

5 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!

6 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.

7 Precaching Data What do they do? The Precache ( pre-load ) the data into memory.

8 Precaching Data There are 2 key functions provided for this. AddPrecacheMaterial AddPrecacheStaticMesh

9 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.

10 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; }

11 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;

12 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.

13 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).

14 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.

15 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.

16 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.

17 Behind the Scenes For more information on dynamic arrays, hit the UDN’s language reference. It’s all there

18 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.

19 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.

20 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.

21 Bringing UT to it’s Knees Our textures. 2048*2048 bmp’s I all their butt ugly glory!

22 Bringing UT to it’s Knees To create a 21MB monstrosity! Import all these in via the editor and create a texture package.

23 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); }

24 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); }

25 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…

26 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(); }

27 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 cpu 533mhz fast bus 512 ddr ram G4 Ti4200 128ram

28 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!

29 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.

30 So what this means to us So how do we uses these new functions?

31 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'); }

32 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…

33 So what this means to us

34 It does still lags out a bit…but no where near as bad. In other words….precaching is your friend…especially for large objects.

35 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.

36 How UT uses them Remember, it’s good for both static meshes and materials (textures). Functionally doing the same thing.

37 End of Precache This should cover all your needs for precaching textures and meshes.


Download ppt "Sega 500 Precaching in UT2003 Jeff “Ezeikeil” Giles"

Similar presentations


Ads by Google