Creating Entities with CaWE

A forum about everything related to the Cafu World Editor CaWE: mapping, editing, scripting, making GUIs and fonts, using the BSP, PVS and Light compilers.
Post Reply
SoulRider
Posts: 95
Joined: 2014-04-06, 00:16

Creating Entities with CaWE

Post by SoulRider » 2014-08-25, 03:16

Currently, you create a new entity and add the relevant components to it via the editor to make the entity you want. This is great and very helpful, but has some drawbacks when it comes to using standardized entities.

I am looking for a way to be able to pre-define entities and allow mappers to place them in the map, with editable properties. As an example, I have created a CompTeamStart. It is based on the CompPlayerStart, using the bounding box for the map entity, although a different color, and I have added the team number component to it, so that each TeamStart can be set for a particular team.

The problem is that when I add the TeamStart component to a new entity, it doesn't add the team number component automatically, so I have to add it myself. While it isn't too much hassle for a simple entity such as a team spawn, it becomes more of a problem with complicated entities.

Is there a simple way to create pre-defined entities for use in CaWE? Or would it require an overhaul of CaWE and the game code?

I think the concepts behind CaWE and the building entities etc has huge benefit to singleplayer games, but without prefab entities, multiplayer games are a bit more repetitive when it comes to creating them. I'd also like to make it easier for any mappers I may get on the team in the future :)
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Creating Entities with CaWE

Post by Carsten » 2014-08-25, 15:07

Hi SoulRider,

you are absolutely right: among all features of the newly introduced component system, prefabs is the single most important aspect that is still missing (others are the entities' representation and selection behavior in the Map Editor that I'm currently working on and which is largely done, and better support for "copy & paste").

The key idea for prefabs is this (outline only, this is not yet implemented):
  • In the Map Editor, in order to save an entity as a prefab, you'd select it first, then choose either from the main menu or from a right-click context menu the menu item "Save as prefab...".
  • This would save the entity into a directory such as Games/DeathMatch/[b]Prefabs[/b]/ in the same file format as entire maps are saved. However, these "mini maps" would only contain a single entity each (of course including all child entities, all components and all primitives).
  • Another menu item such as "Load prefab" or "Insert prefab" would do the opposite, namely load one of the mini maps from the Prefabs directory and add the entity that is described therein as a child entity to the Map (the root entity), or the currently selected entity, if there is one.
  • As an extra, it would even be possible to use sub-menus and sub-sub-menus etc. that mirror the contents of the Prefabs directory for extra convenience: The user could simply and quickly pick one of the existing prefabs without a need for the generic "File open" dialog.
For the beginning, that would be all. Extras, such as "coupling" between an entity in the map and the prefab it was created from (so that later updates to the prefab may update all entities that were ever created from it) would be considered in a separate step.

For the schedule, while I understand that this is a very important feature, I still would like to properly finish my current work regarding the "Entity Hierarchy" first. (The changes to the "Entity Hierarchy" involve the subsuming of the "Groups": the still existing "Groups" dialog will be removed, or rather, integrated into the "Entity Hierarchy".)

This will be done quite soon, probably this week (there is still a lot of polishing to be done, but that can easily be postponed until later). Thereafter, I can immediately start with the Prefabs feature as outlined above, and I'm quite sure that it will not require a revolution or ages of time to get it done. :up:
Best regards,
Carsten
SoulRider
Posts: 95
Joined: 2014-04-06, 00:16

Re: Creating Entities with CaWE

Post by SoulRider » 2014-08-25, 16:25

Thanks for the reply Carsten, that really helps. I really appreciate the fantastic work you continue to do on the engine, and your never-ending support for questions and problems.

I am aware the current system is designed so that all entities are created and controlled through lua scripts, but I was wondering if there is any way to create C++ entities?

With the system designed as it is, being able to create basic entities in C++ using components, for map entities, would help me, as while they could be added to in the editor, and extended through lua, there is no direct need for lua to be used in many of their cases.

Potentially, using these in hardcoded C++ would be more beneficial for things like performance in the long run. I am aware that is not the route you planned to go, but it would be of benefit to me, particularly when the number of map based entities begins to rise.

Having a lot of experience with lua through NS2, I am aware that lua performance can be a bottleneck at times, particularly when heavy processing occurs, and for me, having the base map enitities such as triggers, spawn points and the like written as complete C++, with the option to extend in lua, is a solution I'd like to use. I'd love to know if it is possible, and a rough idea of what I'd need to do to get it to work.
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Creating Entities with CaWE

Post by Carsten » 2014-08-26, 18:41

Hi SoulRider,
SoulRider wrote:I am aware the current system is designed so that all entities are created and controlled through lua scripts, but I was wondering if there is any way to create C++ entities?
Yes, this is possible. In fact, although Lua is certainly in the foreground for map designers (because it's easy to learn and easy to use, which is what most people want, especially in the early phases of a project), underneath the C++ and Lua support are "at least" on par.

Actually, I'm a big proponent of C++, Cafu is at its basics a C++ project, and the C++ code is actually the framework in which the Lua code lives (i.e. the Lua "alter egos" of the entities). That especially means that everything that can be done in Lua can also be done in C++ (and more). :up:
With the system designed as it is, being able to create basic entities in C++ using components, for map entities, would help me, as while they could be added to in the editor, and extended through lua, there is no direct need for lua to be used in many of their cases.
Can you please describe in greater detail what exactly you want to achieve?
For example, do you want to create new entities in C++ in the Map Editor, in the game engine, or elsewhere?
As mentioned above, it's really not difficult, and works using plain C++ constructors exactly as one would expect. If you let me know more details about your intentions, I may be able to point you to or come up with a matching example.
Potentially, using these in hardcoded C++ would be more beneficial for things like performance in the long run. I am aware that is not the route you planned to go, but it would be of benefit to me, particularly when the number of map based entities begins to rise.
Don't worry. If it was up only to me, Cafu would still be a C++-only project :cheesy: (but I've learned to love Lua, too). ;-)
I embrace Lua because together with the component system it forms a very flexible and broad solution that works great for everyone: The overall result is that if you don't like C++, you don't have to use it, because lots and lots can be done with Lua alone. But if you want to use C++, you can do that at any time, and there is nothing about the Lua support that makes the C++ code more difficult or more cumbersome to use.
Having a lot of experience with lua through NS2, I am aware that lua performance can be a bottleneck at times, particularly when heavy processing occurs, and for me, having the base map enitities such as triggers, spawn points and the like written as complete C++, with the option to extend in lua, is a solution I'd like to use. I'd love to know if it is possible, and a rough idea of what I'd need to do to get it to work.
Well, of course, Lua can cause bottlenecks, but I believe that they're easy to overcome, because, for example, if your custom behavior script is too slow, you can simply implement another component that does exactly the same, but in C++. As another example, if only a specific method is too slow, it is really easy to implement this method in C++ rather than in Lua for the better performance, and you can still continue calling it from other Lua code.

Also note that most of the processing actually is in C++ anyways. For example, detecting whether an entity is inside a trigger volume is implemented in C++. Only then is a callback made into Lua, so that the Lua code can decide on any consequences / actions / behavior that the entity may take as a result from being inside the trigger volume. Thus, overall, the amount of time spent in the Lua code is really quite small.

(I have no hard facts, and this is just a guess, but I believe that graphics rendering and especially inherent limitations of network synchronization / bandwidth can drive any online / multiplayer game faster into bottlenecks than Lua code.)

So in summary, just let me know a few more details about your intentions, and I will be able to tell you more about it. :up:
Best regards,
Carsten
SoulRider
Posts: 95
Joined: 2014-04-06, 00:16

Re: Creating Entities with CaWE

Post by SoulRider » 2014-08-27, 20:09

The intention would be to create entities that appear in a list for use in the editor, like you have currently for components. They would be map entities, but they would also be part of the game, for example as mentioned spawn points and triggers, initially it is those that I am interested in. This may be expanded further at a later date, but for my initial project, it is those I want to concentrate on.

The entities would still be component based of course, but all the code would be in C++. As previously mentioned, C++ is new to me, my history is really with lua, so I am still trying to work out some of the basics, trial and error :)
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Creating Entities with CaWE

Post by Carsten » 2014-08-27, 21:45

SoulRider wrote:The intention would be to create entities that appear in a list for use in the editor, like you have currently for components. They would be map entities, but they would also be part of the game, for example as mentioned spawn points and triggers, initially it is those that I am interested in.
This very much sounds like the "prefabs" feature outlined above...(?) :P

If you can wait just a bit longer, as mentioned above, prefabs will be the very next issue I'll be looking into. It will certainly be much faster than inventing a custom "shortcut" system first, then doing the same work in a more general ("prefab") form again.
Best regards,
Carsten
SoulRider
Posts: 95
Joined: 2014-04-06, 00:16

Re: Creating Entities with CaWE

Post by SoulRider » 2014-08-29, 17:53

As I am learning, I decided to plow on with my idea, to help me gain knowledge in general. I have created myself an EntTeamStart. This is a sub-class of Entity, which is a member of GetGameSysEntityTIM(). I have had to do a few things to get it working, but I am not sure why.. I get an error when trying to create the constructor and copy constructor. The code I try and use in the cpp file is -

Code: Select all

EntityTeamStartT::EntityTeamStartT()
    : EntityT()
{
}


EntityTeamStartT::EntityTeamStartT(const EntityTeamStartT& Ent)
    : EntityT(Ent)
{
}
The relevant in the hpp file is -

Code: Select all

/// The constructor.
EntityTeamStartT();

/// The copy constructor.
/// @param Comp   The component to create a copy of.
EntityTeamStartT(const EntityTeamStartT& Ent);
I have to comment out the code above from the cpp for it it work or I get an error about cf::gamesys::EntityT not having a valid constructor. I've attached the full files so you can check them out for yourself.

I have also created an AllEntities which is for holding the members of GetGameSysEntityTIM(). I would like to be able to get this list to show in the editor as you have with the components list, but cannot find the relevant CaWE code. Where is that held?

I've attached these files too. If you have the chance to give them a quick look that would be great :D
Attachments
AllEntities.cpp
(3.48 KiB) Downloaded 101 times
AllEntities.hpp
(801 Bytes) Downloaded 106 times
EntTeamStart.cpp
(2.17 KiB) Downloaded 104 times
EntTeamStart.hpp
(1.93 KiB) Downloaded 100 times
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Creating Entities with CaWE

Post by Carsten » 2014-08-30, 15:07

SoulRider wrote:I have created myself an EntTeamStart. This is a sub-class of Entity
Why do you derive from EntityT?

The whole idea behind the component system is exactly to not do that, because entities are only considered as containers for components. Both in theory and in practice that basic idea seems to work exceptionally well, so that deriving from EntityT is not needed (and probably more counteracts than helps the desired goals).

Any (game-related) functionality and features that you wish to add should be implemented in components. That is, the right approach is to derive from ComponentBaseT (and add that component to a "plain" EntityT instance wherever required or desired).
I would like to be able to get this list to show in the editor as you have with the components list, but cannot find the relevant CaWE code. Where is that held?
The Map Editor's main menu is assembled in file CaWE/MapEditor/ChildFrame.cpp in the constructor of class ChildFrameT.

You can easily add new menu items there (you also need a handler (callback function) that gets called when the related menu item is selected, see the other menu items for how it is done), but in the handler you should really create a plain, generic EntityT instance and then add the desired component instances, rather than attempt to derive a custom class from EntityT.
Best regards,
Carsten
User avatar
Carsten
Site Admin
Posts: 2160
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Creating Entities with CaWE

Post by Carsten » 2014-09-12, 17:34

Hi,

just as a quick info, this:
Carsten wrote:
  • In the Map Editor, in order to save an entity as a prefab, you'd select it first, then choose either from the main menu or from a right-click context menu the menu item "Save as prefab...".
  • This would save the entity into a directory such as Games/DeathMatch/[b]Prefabs[/b]/ in the same file format as entire maps are saved. However, these "mini maps" would only contain a single entity each (of course including all child entities, all components and all primitives).
  • Another menu item such as "Load prefab" or "Insert prefab" would do the opposite, namely load one of the mini maps from the Prefabs directory and add the entity that is described therein as a child entity to the Map (the root entity), or the currently selected entity, if there is one.
  • As an extra, it would even be possible to use sub-menus and sub-sub-menus etc. that mirror the contents of the Prefabs directory for extra convenience: The user could simply and quickly pick one of the existing prefabs without a need for the generic "File open" dialog.
For the beginning, that would be all. Extras, such as "coupling" between an entity in the map and the prefab it was created from (so that later updates to the prefab may update all entities that were ever created from it) would be considered in a separate step.
is now implemented in the latest commits in branch "master", just as described above: check out the new "Prefabs" menu in the Map Editor. :up:

For the "quick-load" feature, I did not employ sub-menus and sub-sub-menus however, but plain menu items with paths relative to a game's Prefabs directory. This is a bit simpler for code and users, and works equally well.

The mentioned "coupling" or "syncing" is, as described, subject to future implementation.

At this time, caveats exist with prefabs that include primitives and/or child entities, because after loading a prefab, it can happen that its origin is in the proper location, but its primitives have an unwanted offset (the original world-space position...), and because child entities are not properly selected, so that dragging them updates the locations of the "parts" of the prefab only partially.

So the basic "prefabs" functionality is there and can be used, and I'll next address the above mentioned and any other known issues.
Best regards,
Carsten
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests