Jump to content

How will you program Entites management :


YouGroove
 Share

Recommended Posts

Well in fact i have 10 ennemies , some five are the class (class or method manager in Lua ) : "Wolves" the other 5 are the class "Birds"

I place the models in the world Editor each five have the same name "Wolf", the other 5 have the same name "Bird".

 

So in the main Lua Loop , i'll have to :

-Load the scene

-Load the entities

-Load lights

- Load scene parameters

 

On the initialisation i'll have to :

- Init each five "Wolf" entities variables with Life, Attack, and place that 5 Objects on a table

- Init each five "Bird" entities variables with Life, Attack, and place that 5 Objects on a table

- init the player

 

Than on the main loop method i 'll have to :

- Manage player input and variables

- Manage all 5 Birds

- Manage all 5 Wolf

- Manage main menu if needed

 

Is that the way of having a complete interaction fo player some 10 ennemies ?

 

If someone would have some code example i would be happy also to read it :)

Stop toying and make games

Link to comment
Share on other sites

Actually, when using Lua, you should avoid putting too much code in the main loop, because Lua is a bit slow in looping. Instead, try to put all the code into the model's lua file, because then you get not only more speed, but also your whole game will work with very little changes from C++ also. It will work from C++ and if you need more speed, then you can put the model lua code into the C++ main loop when needed.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

@Metatron :

Thanks for the advice. I'll try tonight or tomorrow depending on free time.

But i think more and more going one more time to the full C++ way with LE2 , it have lot of chances to be as much code could it be Lua or C++, and same complexity to manage

the entities.Actually with LE2 makingt the game in Lua or C++ the benefits and differences are not big if you have to manage entities and their updates, you can manage completly the entity in

C++ i think.

 

Finally i htink the algorithm will be somethign like that :

 

-> Loop throught all entities names

{

if entitie.name = "Wolf"

-> tableEntities = new Wolf();

 

if entitie.name = "Bird"

-> tableEntities = new Bird();

 

i+1;

};

 

On the main loop of the programm i'll call the Wolf Update method :

 

Main Loop {

 

Player.update();

 

for (i =0; tableEntities.size(); i++ ) {

tableEntities.updateFrame();

 

}

 

}

 

I think it's the general idea. And each entity could herit fomr some common Class that would have the methods :

- init()

- FrameUpadet()

- FreeEntity() ;

 

Well thats the wxay i think to make my own framework entitie manager !

Stop toying and make games

Link to comment
Share on other sites

As Metatron suggested, you need to write two class scripts, one on the wolf and one on the bird. Then, initialize its properties from the editor. Open up the atmosphere script as an example. Then there is also no need to maintain a separate table for entities, you can simply find any entity by doing FindChild on the scene.

 

As far as your common methods go, Leadwerks defines several callbacks you can use to run update logic. Take a look here: http://leadwerks.com/wiki/index.php?title=Entities#Callback_Functions Then you don't need to go about defining your own methods. I am not sure they are implemented in Lua though. You can most certainly use them in C/C++.

 

Before you start re-inventing the wheel, I would suggest you write some small (think Pong, Asteroids, Gorillas) clones to get a feel of what Leadwerks can and can't do. It will save you time later.

Link to comment
Share on other sites

As Metatron suggested, you need to write two class scripts, one on the wolf and one on the bird. Then, initialize its properties from the editor. Open up the atmosphere script as an example. Then there is also no need to maintain a separate table for entities, you can simply find any entity by doing FindChild on the scene.

 

As far as your common methods go, Leadwerks defines several callbacks you can use to run update logic. Take a look here: http://leadwerks.com/wiki/index.php?title=Entities#Callback_Functions Then you don't need to go about defining your own methods. I am not sure they are implemented in Lua though. You can most certainly use them in C/C++.

 

Before you start re-inventing the wheel, I would suggest you write some small (think Pong, Asteroids, Gorillas) clones to get a feel of what Leadwerks can and can't do. It will save you time later.

 

Thanks Laurens !

Without the table the algorithm will be like that i think :

 

Loop Entities

if entity.Name.startsWith("wolf"){

entity = WolfClass.update(entity) ;

}

 

if entity.Name.startsWith("Bird"){

entity = BirdClass.update(entity) ;

}

 

End Loop

 

For CallBacks method, the code can become complicated if i put some code on some CallBack method and some other code on thers CallBacks !

Perhaps it's better to put all methods and code in a single Class or method.

Stop toying and make games

Link to comment
Share on other sites

Guest Red Ocktober

interesting thread...

 

As Metatron suggested, you need to write two class scripts, one on the wolf and one on the bird. Then, initialize its properties from the editor. Open up the atmosphere script as an example. Then there is also no need to maintain a separate table for entities, you can simply find any entity by doing FindChild on the scene.

 

i'd tend to agree with Met and Laurens here... ideally, you'd want a base class of animals... each with common traits... and build up from there... but if there's no need, and since wolves and birds would represent two sets of very dissimilar traits and behaviors... i think you can leave out the descendant definitions...

 

that is, unless you're planning a whole world of animals in this and or future projects... then a good base class from which you can draw from might be a real time saver...

 

 

Before you start re-inventing the wheel, I would suggest you write some small (think Pong, Asteroids, Gorillas) clones to get a feel of what Leadwerks can and can't do. It will save you time later.

 

more sound advice... get comfortable with what you're able to do with the language and Leadwerks... in addition to saving you time, you'll have lots of fun as well... :)

 

ok... well, maybe not that much fun...

 

hey... a quick small question (sorry) along the same lines...

 

is it practical to design scene objects (entities like soldiers, sailors, ships, cars, planes, etc) in lua.. and have them interact with other entities and the environment while running their own logic routines, and would this enable you to write a full game that could conceivably run in the editor...

 

(again... apologies to the thread starter here)

 

--Mike

 

 

--Mike

Link to comment
Share on other sites

is it practical to design scene objects (entities like soldiers, sailors, ships, cars, planes, etc) in lua.. and have them interact with other entities and the environment while running their own logic routines, and would this enable you to write a full game that could conceivably run in the editor...

 

I would say yes. This is sort of what I was aiming at with my Thingoids although I was trying to be even more general and give basic building block scripts that the user joins together to make entities. But you could just hardcode all the entity game logic in the models themselves. It just becomes 100% specific to your current game.

 

What Josh is aiming towards in LE 3 is all possible today it doesn't work as easily and look as pretty as the way LE 3 is going to work.

 

My youtube id is rpiller and in there I have a video of thingoids where I did this in a very basic "game" in the editor. I talk about all the model scripts and how I joined them to make some gameplay. I'm at work so can't link to the direct video but I think it worked out pretty well myself :)

Link to comment
Share on other sites

and give basic building block scripts that the user joins together to make entities

Like i said , this seems to be more something like templates in that case ?

For Lua i thaight lot more in script methods that could be "attached" to any entity.

 

Some simple example :

 

For example we would have two methods , one for the Initialisatio nof the entiity , the other called each engine frameUpdate for the entity :

 

 

Method InitialiseMe(){

var life = 100 ;

}

 

Method rotateMe(){

EntityMe.Rotate(10*timeStep) ;

if(EntityMe.Collision == 1 ){

if(EntityMe.Collision.Entity.name == "Bullet") {

EntityMe.life = EntityMe.life -20 ;

if( EntityMe.life == 0 ) {

EntityMe.freeEntity();

}

}

}

}

 

 

So this way of programming , if we would have attached this script to several entities on the level; all of them would rotate each frame , and and disappear if they would be touched (on collision) by some entity whose name would be "bullet".

 

This is lot more like something like "attaching code to entities".

And indeed if you make some code that would behave like an ennemy, each entities taht would have this code attached would behave like an ennemy.

It's more this way i would have seen Lua ?

Stop toying and make games

Link to comment
Share on other sites

For example we would have two methods , one for the Initialisatio nof the entiity , the other called each engine frameUpdate for the entity :

 

This is what callbacks achieve without hardcoding a specific method that all entities must then implement.

Link to comment
Share on other sites

For Lua i thaight lot more in script methods that could be "attached" to any entity.

 

YouGrove, you can think of each model script as 1 method. Each model script has an update method that gets called each frame and so you can create a Rotate model script which takes a message (there is a message method by default) that will start the rotation. You then target this model script to the actual model you want to rotate.

 

Here is the video that shows what I was doing. In this example I use model scripts to do simple functionality. I just make the model of these scripts a invisible model because it's the functionality I want and not the model. I then use the targeting system of LE to basically act like parameters to a function. If the first parameter to my rotation method is the actual model to rotate, then target 0 I link to that actual model. The benefit of this is that you code smaller more general model scripts that can be combined to do some cool stuff.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

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

 Share

×
×
  • Create New...