PDA

View Full Version : Creating New Functions & Game Loop



fallingbrickwork
11-17-2009, 12:25 PM
Hi all,

I'm starting to look through all the UTGame classes etc to try and get my head around where everything is but have a quick question on creating new functions and where to call them from.

I understand inheritance and that i can extend classes and create a MyClass version, but lets say I want to create a totally new function or class?!

Just say I want to create a function called 'function OutputME()' that just outputs variables that get updated EVERY screen refresh to screen, does this still need to be in a class that gets extended? Is there a 'gameloop' type class for these sorts of things, and therefore, where does the function get called?

Many many thanks in advance,
Matt.

Taxxem
11-17-2009, 01:54 PM
I am not a 100% perfect unrealscript guy and have myself been picking this up for the lsat 2 weeks, so anyone is welcome to correct me.

Updating something per a refresh rate you need to look into the tick() function. This function basically runs every frame update. However be careful not to overload the function too much because you can actually cause game lag from making it do too much. If you want to make something set on a timer you use a settimer function along with either timer ( ) or the name of the timer you want to use. For example say you want to run a timer that will log something every 1 second then you would use basically...

settimer(1.0,true, 'UseLogFunction');

function UseLogFunction
{
`log("Logging");
}

This would need to be placed where you want the timer to start. It could be a postprocessing thing or it could happen do to an action.

As for classes and extending from classes. I haven't tried it but I would guess you could technically make a class that doesn't extend to anything. I would mention that if you want to make a very primitive class you can always extend from Object. The problem is your really losing a lot of functionality and the great inheritence that comes with extending. I wouldn't suggest going that way unless you had no choice... (if you can even do it.). Most things at least extend from Actor.

To answer you on functions you can easily make a function just by making one in the script. Simply put together a function and toss it where it should be run.

TheSpaceMan
11-17-2009, 01:57 PM
Can only replay to that partly. I think the minimum extending you need to do is from Object, writing my parser it was clear that as good as every object extends from here.

As for making your entire new game loop i do not know.
But i would guess that one of the lowest levels to look at would be engine. It containts the lowest level of all implemented object. Aka a kind of core Vehicle.uc The Actor.uc etc.

I guess you could go even lower and extend from the implementation in core. But then I think you would loose the easy use of the map editor etc, loose all default input and physics implementation. I am not sure how well this would work.

Solid Snake
11-17-2009, 02:07 PM
You do not need to make your own game loop.

fallingbrickwork
11-17-2009, 02:44 PM
You do not need to make your own game loop.

Yeah, I don't need to make a game loop, i'm just not sure which functions get called when, if that makes sense, and which class to place new functions into?!

Just say for a hypothetical example, I wanted to output the camera XYZ position to screen using a created function like Taxxam described (this is purely hypothetical, there may already be a function for this), would i just place this function in a camera-related extended class or could it just as easily go in a new class i had made extending from Actor or Object.

I think maybe i'm thinking about this a bit too deeply and making it harder than it really is.

Regards,
Matt.

neai
11-17-2009, 02:49 PM
For displaying on screen look into functions like PostRender. Logging is slow but fine to do every frame (or even more often) if you're temporarily debugging something.

neai
11-17-2009, 02:55 PM
I wanted to output the camera XYZ position to screen

Try the ShowDebug console command. You can add your own things to the display by overriding the DisplayDebug function in one of the relevant subclasses.

fallingbrickwork
11-17-2009, 02:57 PM
Many thanks for everyone's help with this... it has moved me a little bit further forward.

Kind Regards,
Matt.

Solid Snake
11-17-2009, 04:57 PM
In simple terms, a big list of actors are stored within the engine. On each update which can be between 16ms to 32ms (depends on your frame rate), every actor in this list is 'ticked'. This will call the Tick event within the Actor. Actors all have a default implementation of Tick that does nothing. You can remove an actor from the list by declaring it static and some actors by default never Tick. A good example is a static mesh actor. Timers are checked natively during this tick as well, so timers are mostly accurate, but may miss by a few ms.

However, there are many events that are called to an actor from the internals of the engine. Good examples are Touch, UnTouch, PreBeginPlay, BeginPlay, PostBeginPlay and so on. Most of these are tagged as 'Event' from within Unrealscript. Check out Actor.uc for lots of examples.

To cover all bases, event and function are no different in Unrealscript. When you write 'native' (C++) code, there is a difference then as you call events and not functions.

So to answer your original question, you can subclass the HUD and in your custom GameInfo you get all player controllers to use your HUD subclass. Within HUD there is a PostRender(Canvas) event (from memory it is an event) that you can use. From here, you can either retrieve all actors by using the AllActors iterator (not recommended as it can be slow). Once you have all the actors you want you can then render debug information.

fallingbrickwork
11-17-2009, 07:08 PM
@Solid Snake - Thank you for your very informative reply, it has certainly put a lot of things into place and I now have a clearer understanding.

Thanks again,
Matt.

TheSpaceMan
11-19-2009, 07:00 AM
This brings me to another question, is there a way to retrive specific actors if you for instance subclassed them or retrive actors based on a flag? In this example say that you just want to do specific debug renders of specific actors you subclassed and not all of them?

Or does this simply require you to check if you can "cast" them somehow...

Ah. Nevermind me asking. To find out the different iteratortypes you can look in Actor.UC

Line: 1892 to 1983 (unless you edit the file you bad boy!)