Jump to content

Naughty Alien

Members
  • Posts

    796
  • Joined

  • Last visited

Blog Entries posted by Naughty Alien

  1. Naughty Alien
    Hello guys. This time, here is small utility, nothing spectacular, just smal library what will let you manage available screen size your GPU support, easy. You can also use it in main menu where you will setup all available resolutions and browse trough list, or automatically detect maximum resolution upon start and set screen, etc. So here are commands.
     
    So, first we need to initialize library.
     
    Global SCREEN_SIZE:TScreenSize
    SCREEN_SIZE = TScreenSize.Create(bitDepth:Int=32)
     
    bitDepth is your screen depth and by default is 32, and it means, supported resolutions will be for 32 bit depth.
     
    Now library is initialized. All available resolutions GPU support are accessible trough screen size modes. Screen size modes are nothing but indexes of array, where screen size is stored, for width and height. So, in order to know how many available resolutions we have, we will use this command:
     
    Global NUMBER_OF_AVAILABLE_RESOLUTIONS:Int
    NUMBER_OF_AVAILABLE_RESOLUTIONS = SCREEN_SIZE.get_number_of_modes_available()
     
    So, if you want to go trough list of all available resolutions,
    you will go from 0 to NUMBER_OF_AVAILABLE_RESOLUTIONS.
     
    If you want to set up screen size, you can do it like this:
    SCREEN_SIZE.size(width:Int=True, height:Int=False,mode_:Int=0,higherRes:Int=False)
     
    If width is true, returned size will be width. If height is true, height size will be returned.
    If mode is provided in range 0 to NUMBER_OF_AVAILABLE_RESOLUTIONS, It will be provided size for that mode, for width or height, depending which one is flagged true.
    If higherRes is true, it will be returned largest screen size for width or height, depending which one is flagged true.
     
    So, for example, if you want to setup your screen upon loading on to maximum resolution, since you dont know in advance what kind of GPU/Monitor will be used, and you want to set it higher so user can later change it, you will do simply this(example with framework):
     
    Global SCREEN_SIZE:TScreenSize
    SCREEN_SIZE = TScreenSize.Create(bitDepth:Int=32)
    Graphics(SCREEN_SIZE.size(,,, True), SCREEN_SIZE.size(False, True,, True), 32)
     
    LogStreamEnabled = False'AppLogMode equivalent
    Global FW:TFramewerk
    FW = TFramewerk.Create()
    If Not FW RuntimeError "Failed to initialize engine."
     
    ..and rest is history . By combining on many ways, you can have many use of it, from menu systems where screens will be detected, up to automatic initializations, etc.. Also, you dont have to sort out screen sizes. They are already sorted (0 means lovest resolution, SCREEN_SIZE.get_number_of_modes_available(), is the highest), so its easy.
     
    Anyway, you can see how to use lib in provided example, so it should be self explanatory. In case it doesnt work, let me know.
     
    INSTALLATION:
    As usual, copy e1.mod to mod folder, and include it as it was done in provided example, and you are good to go..cheerrsss...
     
    DOWNLOAD HERE:
    http://www.leadwerks.com/werkspace/files/file/351-screen-size-utility/
  2. Naughty Alien
    This time, I have decided to introduce character animation control. There are several reasons for that. A lot of people asked me to give some example, and at same time, such library will be essential for following AI tutorials, so having said that, I have decided to introduce AI library, so it will be avoided confusion with corresponding command set in AI tutorials. I would like to also make note that all libraries I have released and Im planning to release, are a lite version of fully fledged feature set in game engine Im planning to sell, after my game is out, so all this is some sort of 'advert' what full version can do, in order to make people more interested about system.
     
    Now, lets go back to topic. During game development, one of important roles are game character animations. From programmer standpoint, control of animations must be very simple, much as possible, with same rules applicable to both, gameplay character, as well as NPC's. Even more, it is important to have ability to have character easy 'switchable' between player control or some other system (cut scene manager, AI control, scripted event). So, how is it done in this library?? Very simple. First of all, during design, you will notice that there are always certain animation 'groups'. Animation inside those groups, should fall under same control scheme. Of course, it is entirely possible to have different control scheme for each animation group, but it is NOT advisable. So what are those 'animation groups' ?? Let me explain on provided example. Lets assume that our character has 2 main pose(im not sure is this proper word). In short, lets say that our character can move in normal way (standing up pose) and crouch pose. Each of this poses I call a 'group' . Animations within each group use (should use, but its not necessary), same command set. For example, when character walk while in stand up pose, we use KEY_UP so character animating in WALK animation. When we switch to CROUCH (let say hit button C as usual in games), then SAME command (KEY_UP) will make character animating in WALK animation BUT in crouch pose. Also, while character doesnt move at all, it should be in 'STOP' animation. That animation plays main idle and if player doesnt do anything, system should play some of side idles, if available and after it plays, go back to main idle (like, Lara Croft, bored and play various animations if player doesnt do a thing)..Library giving ability for creation of infinite number of groups and infinite number of animations within groups, so its up to designer/programmer to utilize system properly Library command set is rather simple, and yet powerful, so lets see command set.
     
    'CREATE ANIMATION FOR CHARACTER
    CHARACTER:Tanimation
    CHARACTER = TAnimation.Create("MyCharacter.gmf",IdleTriggerTime:Int=20000)
     
    MyCharacter.gmf
    Its animated character we want to control.
     
    IdleTriggerTime:Int=20000
    This is time representing how long will be played main idle, before plays one of randomly choosen side idles, if any. So it is time what system will wait player, before switch to one of 'boring' animations. Its exposed in milliseconds, so default value is 20000 what is 20 seconds.
     
    'ADD ANIMATION GROUP('S)
    CHARACTER.extract_sequence("ANIMATION GROUP NAME", "ANIMATION COMMAND NAME", firstFrame:Int, lastFrame:Int,playType:Int=CONTINOUS_LOOP, idleType:Int=MAIN_IDLE, transition:Float=0.0, speed:Float=1.0)
     
    This command will extract animation stored in given frame range, under ANIMATION COMMAND NAME and inside ANIMATION GROUP NAME.
     
    ANIMATION GROUP NAME
    Thisis name of specific animation group, what will contain specific animations.
     
    ANIMATION COMMAND NAME
    This is name of specific animation, what will be used to play specific animation, during gameplay.
     
    firstFrame
    First Frame of animation
     
    lastFrame
    Last Frame of animation
     
    playType
    It is flag representing way animation is played. It should be left in default value (CONTINOUS_LOOP), as other modes are used for internal processing as well as for some other libraries im about to introduce later, during AI lessons. Just for info, available flags are:
     
    -CONTINOUS_LOOP
    -ONE_LOOP_THEN_IDLE
    -ONE_LOOP_THEN_STOP
     
    But as i said, you SHOULD let it be default value only, as others are used for other things, we will see, later.
     
    idleType
    This flag tells to system what kind of animation is one to be loaded and therefore, how it will be treated. If animation is MAIN IDLE then flag is MAIN_IDLE. If animation is idle for 'bored' animation, then flag should be SIDE_IDLE. SIDE_IDLE animations are attached to MAIN_IDLE and after idleTriggerTime is elapsed, one of SIDE_IDLE animations will be played and then go back to MAIN_IDLE. If animation is not any kind of IDLE animations, then it should be flagged as NOT_IDLE. This flag will be our, walk, run, jump, die, etc, animations we control. So possible flags for animation types are:
     
    -MAIN_IDLE
    -SIDE_IDLE
    -NOT_IDLE
     
    transition
    This is value representing transition smoothnes between animations.
     
    speed
    This value representing animation speed. Default value is 1.0.
     
    'INITIALIZE ANIMATION SETUP WE WANT TO START WITH
    CHARACTER.enable_initial_animation("ANIMATION GROUP NAME", "ANIMATION COMMAND NAME")
     
    This command will basically set choosen animation group as default one and play animation from that group with ANIMATION COMMAND NAME when program starts. Usually used to setup main idle play before game starts.
     
    In order to play some animation in runtime, we use command
    CHARACTER.play("ANIMATION COMMAND NAME")
     
    This command has to be called just once and system will play it, long as it is not called any other animation.
     
    During runtime, we want to switch from one animation group, to another. In order to do that, we use this command:
     
    CHARACTER.enable_animation_group("ANIMATION GROUP I WANT TO MAKE ACTIVE")
    CHARACTER.play("INITIAL ANIMATION NAME I WANT FROM JUST SELECTED ANIMATION GROUP")
     
    And thats pretty much all. If you wanna free from memory all stuff, during switching levels and what not, just do this:
     
    CHARACTER.Free()
    CHARACTER=Null
     
    ..and you are freeeeeee... I hope you guys will have some nice use of this library. Stay tuned as MUCH more comming..
     
    NOTE:
    Inside zip file is EXE. you can run it in order to see how it works. EXE contain all shaders, dll's, etc so dont put it together with shader folder of yours. Character seen in EXE example, I cant share, but source code of example is kindly provided, so you just play with your own characters. Also, library consider that all animations are stored along ONE frame line, so keep that in mind.
    Installation is simple..just copy e1.mod folder in to your Bmax mod folder and you are good to go..
     
    Library available here:
    http://www.leadwerks...ion-libraryzip/
  3. Naughty Alien
    Now im going to show how actual things working. My descriptions will be supported by images taken from example im about to show, as well as whole media, source code and binary included, so you can try yourself. So, lets get started.
     
    After library is initialized, next step is to create both, search engine and navigation world, as you can see on pic bellow.
     

     
    After that, if you compile your proggy, it will not be much visible..and you should be able to see image like this.
     

     
    That looks nice, but we still cant see anything related to our pathfinding. So, just to warm up things a bit, lets create small functions called create_markers() and update_markers(), what will create and draw all available navigation nodes our search engine knows about. Details about each added function Ill not describe here as they are all included in source, so ill just say what they do. Now, our code at initial stage should look like this :
     

     
    Now, if we run our proggy again, we should be able to see all searchable nodes exist, as its shown on pic below.
     

     
    This is something B) . Now we see our all nodes we can search for best path. I want to notice that, this particular example is very nice example of very ugly setup for navigation mesh. Reason for that is unnecessary amount of search nodes as plenty of surfaces can be literally connected just with very few nodes actually, especially straight parts of level, without any obstacles. Basically this navigation grid has over 2000 nodes while whole thing can be done with very few (200-300 hundreds max). So, pay attention on way you create your navigation mesh. Now. lets do something more solid. Lets actually search some paths, shall we? In order to do that, Ill create few more functions, just to make things very easy to deal with. Additional functions are:
    pick_start()
    pick_end()
    distance()
    create_path_markers()
    delete_path_markers()
     
    Thats it. Functions are obviously, self explanatory, but ill still just make small note about their purpose.
     
     
    pick_start() is function what will set up our search start position. Its done by moving mouse over level and hitting LEFT MOUSE BUTTON. After that, you will be able to see green color marker used to show start location.
     
    pick_end() is function what will set up our search destination position. Its done by moving mouse over level and hitting RIGHT MOUSE BUTTON. After that, you will be able to see red color marker used to show destination location.
     
    distance() is function what will return distance between two Vec3 . Simple as it is.
     
    create_path_markers() function will create markers, but this time, markers assigned to our result path, so we can actually see how our path look like.
     
    delete_path_markers() function will delete existing path markers before new path is calculated so we can see updated path.
     
    So, after adding this, our code should look like this:
     

     
    So far so good...so lets just test it. Lets determine further distance on this level (diagonal distance). Left mouse click at one diagonal corner, and then right click on opposite one. After that, just hit enter and violaaaa..our path is in fron of our eyes and it should look like this:
     

     
    Niiiceee and fast.. Actual path search is done inside If-Then block i forgot to show, but its all inside source code so you can see yourself. Its very easy and simple. I hope you enjoyed this basics of AI. Next lesson is about steering basics. Stay tuned, and please, let me know if there is any particular area, you are actually interested to hear so i can make much better and useful lessons. Cya..
     
    Download Linky and note:
    You have to copy your Shaders folder in order to compile and run exe. Its compiled against 2.3x, but it should work with any version.
    http://www.mediafire.com/?4nh4go346ecabmf
     
    EDIT:
    As i mentioned , current EXE provided, is compiled against 2.3x, and source code is from that version. Curtesy of Mac, here is updated version of source file, since one i have posted, clashing with newest versions of LE. Its not about AI library but Newton.DLL and way LE is initialized (doesnt work on new LE versions as it is on source i have provided).
    Here is linky for new source file, thanks to Mac .
     
    linky:
    http://www.mediafire.com/?o1nvgh6nao866vr
  4. Naughty Alien
    After initial release of Pathfind Library, I have decided to post few various lessons, covering most fundamental use of library, so people could have easier approach to a whole thing of AI. In order to do that I started this blog where im going to upload every lesson im about to do in future. I think its not good idea to clog Asset store tools area with tutorials. Let me know what you think.
×
×
  • Create New...