Jump to content

OOP's I did it again ....

Marleys Ghost

1,787 views

I started out yesterday morning looking to improve my understanding of types and methods in Blitzmax, and figure out how to use object-oriented programming (OOP) with it. I have only been programming in Blitzmax since the beginning of December last year, and only programming with C++ since the middle of October last year and The Leadwerks Engine since the beginning of October last year. So I am still on a very high learning curve in this regard.

 

As usual, for me, I started out on one thing and ended up on another. I found a link on the old forum for a small tutorial on Object-Oriented Programming in BlitzMax By John Judnich. But by the time I had got to page 6 of 21, I was already off on a tangent and found myself working on a simple NPC type containing a creation method and simple seek behaviour method, after all I was now an expert :) after only 6 pages lol.

 

I had already been "playing" around with some simple AI which showed vague promise, for an Idea for a small project.

 

bugrs.th.png

 

An hour and a few more "tangents" later I had managed to restructure the basic code for NPC creation and basic seek behaviour into an NPC Type using methods. This now allowed the easy creation of an NPC, in this case a rather nifty bug, created by ‘Psionic’, with its walking animation handled by its Lua script on load.

 

 

The test scenes buildings are by GIMPY73 and the Freebeast model is by ‘Psionic’.

 

 

Updated:

Test of Basic NPC creation : Seek : Pursue : Attack Behaviour using OOP in Blitzmax running the Leadwerks Engine. Extra flags added for behaviour to the NPC Type with extra methods to communicate with the NPC model's Lua scripts for animation control. Although I did manage to hardcode a typo in the "Pursuit" flag.

 

Of course this basic AI is nothing like the calibre of AI work being done by Chris Paulson or Pixel Perfect, but I had to start somewhere and this seemed the best place, so far I am pleased with my meagre results.

 

I recall Josh showing interest in integrating Recast into the editor, this would truly be a useful addition. Leadwerks could really use an integrated AI starting point. Thats not a complaint just an observation. ;) Recast integrated into the engine and editor could be that starting point.



14 Comments


Recommended Comments

Looks really good to me, better than my boring vids!

 

Could you explain a little how things are working and what's going on?

Share this comment


Link to comment

Hi Chris, sure I'll give it a shot, basically each NPC is autonomous to the extent of simple collision avoidance a raycast left-forward and right-forward takes care of that. But then the NPC's would just scurry off into the "sunset" eventually. So a third raycast is made for distance to player to act as an anchor, if the NPC is too far away from the player then a course correction back in the general direction of the player is made. There is also a LOS made, if true then that's the heading the NPC will take. It took a lot of tweaking value wise, but turned out better than I thought. Still a WIP but one of the main objectives was to keep the code to a bare min.

Share this comment


Link to comment
@Franck : Thanks .. yes Recast integration would be good

 

 

I guess if you've seen all my previous posts you'd not be shocked if I agreed strongly with this one.

 

If recast (or any other navmesh/pathfinding) was integrated in everyone would have a really big head start on doing AI. We would then we would start seeing real graphics with moving pictures, instead of lots of nice oil paintings.

 

It's a shame that I'm not a blitz/C++/Lua integration wiz else I'd do it tomorrow. It just needs the right person to find the time and it could be done.

 

Trouble is it's not sexy like all the other graphical fluff...

Share this comment


Link to comment

Thanks for your answer Chris, im agree with you, i think that AI programming can be very insteresting and once recast will be in engine we will see a lot of things moving on the screen :)

 

I have a request for you, as i said in private message, it would be good if you were doing a special project to show a simple recast demo (moving a cube trought a path generated with recast for example) in LW engine in c++ :) a small visual c++ project would be excellent.

Share this comment


Link to comment

Great Vid MG :)

 

And thanks for the link to the BlitzMax OOP tutorial.

 

Ive had BlitzMax on my comp for years and still don't know how to use it fully lol

 

Oh i don't think much of the building in the video ( lol ) , but the main character looks great . did you model it yourself ??? :)

Share this comment


Link to comment

I guess if you've seen all my previous posts you'd not be shocked if I agreed strongly with this one.

 

Not shocked at all Chris :)

 

If recast (or any other navmesh/pathfinding) was integrated in everyone would have a really big head start on doing AI. We would then we would start seeing real graphics with moving pictures, instead of lots of nice oil paintings.

 

Yes it certainly would be a really big head start, a good selling point to for the engine. Whilst I do enjoy the great "still life" being generated, gameplay mechanics need a boost too, especially in the AI dept. Even as a "plugin" thats chargable. Torque do a Universal AI plugin for ~$40 its not "Fantastically Awesome" but something like recast/detour integrated into LE would go a long way to being the foundation for great AI in LE, and get some of these great scenes and wonderful characters being created by the community moving.

 

It's a shame that I'm not a blitz/C++/Lua integration wiz else I'd do it tomorrow. It just needs the right person to find the time and it could be done.

 

I'd love to help but you have already read my programming resume lol

Share this comment


Link to comment

That's a great AI implemention MG ...well done mate .. very impressive! Sometimes the simple solutions can be the most effective.

Share this comment


Link to comment

@ Pixel : Thanks, yes I am a fan of K.I.S.S. but only because I can't do the complex stuff :) but you are right sometimes in certain situations a simple solution can work. This will, I think work for the small project I have in mind and was initially coded for, but would be probably unsuitable anywhere else I feel. Hence it would be nice to get something like Recast/Detour integrated into LE and the editor.

Share this comment


Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Blog Entries

    • By Josh in Josh's Dev Blog 2
      I've restructured the plugin SDK for our new engine and created a new repository on Github here:
      https://github.com/Leadwerks/PluginSDK
      The GMF2 format will only be used as an internal data transfer protocol for model loader plugins. Our main supported file format will be GLTF.
      As of now, the plugin system can be used to write texture loaders for different file formats, model loaders, or to modify behavior of particles in the new particle system. The FreeImage texture loader has been moved out of the core engine and into a plugin so you no longer have to include the FreeImage DLL unless you want to use it. The main supported texture format will be DDS, but the FreeImage plugin supports many common image file formats.
    • By Admin in Leadwerks Company Blog 0
      The GMF2 file format provides the fastest possible load times for 3D models. A preliminary specification and SDK for loading and saving files in the GMF2 file format is now available on GitHub here:
      A Quake 3 MD3 model loader is included as an example.
    • By Josh in Josh's Dev Blog 2
      The Leadwerks 5 beta will soon be updated with particle emitters and an example particle system plugin. Previously, I showed some impressive results with physically interactive particles that collide with and exert forces on the environment. I decided to use the plugin system for controlling particle behavior, as this offers the best performance and can be run on the physics thread. 
      A particle system plugin uses some predefined structures and functions to modify the behavior of particles when they are emitted or as they are updated. This allows for unlimited features to be added to the particle system, because anything you want can be added with a plugin. A system for sending settings to the plugin will be implemented in the future so you can adjust the plugin settings and see the results. The default particle settings and features will probably stay pretty barebones and I will just use the plugin system to add any advanced functionality since it is so flexible.
      void EmitParticle(ParticleModifier* mod, ParticleSystem* particlesystem, Particle* particle) { if (mod->emissionshape == EMISSION_SHAPE_BOX) { particle->position[0] = Random(-mod->area[0], mod->area[0]); particle->position[1] = Random(-mod->area[1], mod->area[1]); particle->position[2] = Random(-mod->area[2], mod->area[2]); } else if (mod->emissionshape == EMISSION_SHAPE_CYLINDER) { particle->position[0] = Random(-mod->area[0], mod->area[0]); particle->position[1] = Random(-mod->area[1], mod->area[1]); particle->position[2] = Random(-mod->area[2], mod->area[2]); auto l = sqrt(particle->position[0] * particle->position[0] + particle->position[1] * particle->position[1] + particle->position[2] * particle->position[2]); if (l > 0.0f) { particle->position[0] /= l; particle->position[1] /= l; particle->position[2] /= l; } } particle->position[0] += particlesystem->matrix[12]; particle->position[1] += particlesystem->matrix[13]; particle->position[2] += particlesystem->matrix[14]; } There are three other new Lua examples included. Coroutines.lua shows how a sequence of actions can be added to an entity before the game starts, and the actions will be executed in order:
      --Create model local model = CreateBox(world) --Add some behaviors to be executed in order model:AddCoroutine(MoveToPoint, Vec3(3,0,0), 2) model:AddCoroutine(MoveToPoint, Vec3(-3,0,0), 2) model:AddCoroutine(MoveToPoint, Vec3(0,0,0), 2) --Main loop while window:Closed() == false do world:Update() world:Render(framebuffer) end This is great for setting up cut scenes or other sequences of events.
      An example showing how to enable tessellation is also included. Tessellation is now a per-camera setting.
      camera:SetTessellation(10) The number you input is the size in pixels of the tessellated primitives. Use zero to disable tessellation. Tessellation is disabled by default on all cameras.
      Finally, an example showing how to use a texture loader plugin is included. All you have to do is load the plugin and after that textures can be loaded in VTF format:
      local vtfloader = LoadPlugin("Plugins/VTF.dll") local tex = LoadTexture("Materials/wall01.vtf")  
×
×
  • Create New...