Jump to content
  • entries
    51
  • comments
    106
  • views
    31,726

Reorganizing and Defragmenting


reepblue

2,289 views

 Share

After I've returned from Steam Dev Days, I caught a terrible cold, so my first week home was unproductive when it came to LEX or Blue Portals. But besides that, I had a great time! I mentioned briefly in my last blog post before I went that I was giving LEX some reorganizing and defragmenting. This blog post, I'm going to go more into detail.

 

LEX2 has a lot of things going for it. The developer console is really handy, the AssetManager prevents crashes and has the ability to pre-loads things for you and the PostStart() command for entities allows you to make entities do things RIGHT AFTER the map loads instead of during the loading process. All very helpful!

 

Crawler's Den taught me a lot about what I was doing with LEX2, and where I should go. I designed it to be more Lua friendly than the initial release. but also allowed easy C++ classes to be made. Crawler's Den had the challenge of "Make a whole game in Leadwerks using nothing but C++". I know it was do-able, but how hard could it be?

 

Leadwerks today isn't really as optimized to be developed using C++ as it is to Lua. I had to do go through a lot of hoops with somethings that could have been done easily if I just wrote the game in Lua. For instance, making C++ classes required more thought, and to attach my C++ puppeteers (actors) to entities in the editor, I had to make a Lua script that acted like a Hammer fgd file to sync it's keyvalues, inputs and outputs. Oh and on top of that, I had to make sure that each puppeteer got deleted properly. All and all, it was do-able, just not ideal at all!

 

I'm switching back to be more focused to making games with Lua for now. I started by making a new project and re-writing the console system to be more flexible. Instead of defining all ConCommands in one cpp file, ConCommands can be defined anywhere now like:

 


static void ConCommand_SayHi(vector parameters)

{

System::Print("Hi")

}

 

static ConCommand sayhi("sayhi", ConCommand_SayHi);

 

With this system, it may be possible to make your own console commands via lua, but I'd have to look into it.

 

My ExSystem Class is derived from Leadwerks System Class, and it's how to talk to the application directly. It handles the dev console, pausing, resuming, and other states that the application might be in. 90% of ExSystem can be called from Lua.

 

The Developer console is much more powerful than it ever was. You can now make entities fire script functions or outputs by the entity name, or using !picker when looking at it.

 

fire <entityname> <functionname>

 

There are also a lot of Utility functions from the previous codebase. One of my favorites is this function.

 

inline Leadwerks::Entity* UTIL_PickFromCamera(int pDistance, int pCollisionType=0, float pRadius=0)

{

Leadwerks::PickInfo pickinfo = Leadwerks::PickInfo();

Leadwerks::Vec3 p0 = UTIL_GetActiveCamera()->GetPosition(true);

Leadwerks::Vec3 p1 = Leadwerks::Transform::Point(0, 0, pDistance, UTIL_GetActiveCamera(), NULL);

if (UTIL_GetActiveCamera()->world->Pick(p0, p1, pickinfo, pRadius, false, pCollisionType))

{

return pickinfo.entity;

}

 

return nullptr;

}

 

I also made the settings.config file store in the AppData folder instead of the game's root. While I never had any permission issues with the old way, still best to have the user's settings there.

 

I merged both the WindowManager and ContextManager to be one class; There is just a WindowManager now. There was no point to have the context be managed in it's own class; definitely now since I took out my UI code I had in there for the console drawing. I also fixed Screenshots being properly placed in it's own Directory in the game's folder!

 

The World Manager is what got the most fat reduced. Before I had a great chunk of code that was ether commented or ifdef'd out. For example, I had old code for my cubemap factory before the Probes where a thing, and other checks that in the long run might cause more problems later. The World Manager is responsible that when a user want's to load a map, a world get's created or cleared, and PostStart is fired on all entities if they have a script. If the user want's to go back to the menu, the world manager clears, and then releases the world. Something that was 913 lines got reduced to 260, and it does pretty much the exact same thing.

 

I removed the InputManager as at Dev Days I learned that that Steam will later be able to handle that for you, not exclusive to the Steam Controller. Also, the implementation was really confusing and tricky.

 

Finally, I removed a bunch of classes that are no longer needed including the Puppeteer class as the focus is now Lua. I want to keep the scope of things small right now. All you need to convert a game using the standard executables to the LEX is to replace the 2 executables and add this self explanatory Lua script that'll override main.lua.

 

--This function will be called once when the program starts
function App:Start()
return true
end
--This function will be called right after when the program starts.
function App:PostStart()
end
--This is our main program loop and will be called continuously until the program ends
function App:Loop()
return true
end
--This function is called once when the program pauses time.
function App:onpause()
end
--This function is called once when the program resumes time.
function App:onresume()
end
--This function is called while the program is loading a map. (This is where you draw your loading screen!)
function App:OnMapLoad()
end
--This function is called when the program finished loading a map.
function App:OnPostMapLoad()
end
--This function is called when the program disconnected from a map.
function App:OnDisconnect()
end
--This function is called when the program closes.
function App:OnShutdown()
end

 

Since it's really those three files that need to be shipped for the product to work, I can use the the standard Leadwerks Project Manager again. I don't plan on releasing the source code at this time. Maybe when making C++ games becomes more streamlined I'll re-integrate my C++ systems.

 

There are still somethings to do though:

  1. Integrate the dev console to the Leadwerks GUI when that's fully done. The CMD using Cin approach that I'm using now is kind of bad.
  2. Play with the app a few hours a day, fix bugs, build on it a little each week.
  3. Find a good method in distribution, and keeping people up to date.

 

In the future, I also hope to add more classes you can use while making gameplay objects. Somethings like a Beam class, and such to make things much more simpler.

 

I also hacked together this shader that takes in roughness and ao sheets along with the diffuse, normal and spec. My artist gave me some textures right from Mamoset and my goal was to import them to Leadwerks as close as I could. I think they came out really well.

 

roughnessao.png

  • Upvote 4
 Share

2 Comments


Recommended Comments

Interesting thoughts. I can see you are moving towards LUA and that's a good move I think. I started off with just LUA but found that some things as SQL was better done in C++ at this moment. So now I have a bit of same approach with a base in C++ for data store and keeping track of items that needs storage, besides that most things are still LUA. Thanks for this interesting post

  • Upvote 1
Link to comment

I'm also making something that others can use, so It should not conflict too much with the standard API and how Leadwerks is setup out of the box!

Link to comment
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.

×
×
  • Create New...