Need advice on game engine architecture

Started by
4 comments, last by AverageJoeSSU 14 years, 7 months ago
Hi everyone. I need some advice. I've started working on a small game engine written entirely in C++ and utilizing the SDL API. I have a pretty good mastery of C++ and fully understand SDL, and I believe I won't have any problem coding the engine in an OOP fashion. What really has me confused is how to go about handling things like quests, items, etc... basically the actual game. I understand how to code the different components, just not how to create the game content without hardcoding it. I keep reading I should be using a scripting language but I haven't found any resources that really tell me what I should be doing. I've recently started reading the book Game Engine Architecture, http://www.amazon.com/Game-Engine-Architecture-Jason-Gregory/dp/1568814135/ref=sr_1_1?ie=UTF8&s=books&qid=1252878622&sr=8-1 and I've learned quite a bit, but there's nothing so far about handling these things. I know at some point I'm probably going to write myself a small level/item editor. Can anyone point me in the right direction? Thanks, Runicode
Advertisement
In general you will still probably have code components for all of your gameside logic, but just enough to provide framework and flexibility to move any slow logic in the scripting language into the c++ engine.

Using a scripting language is almost impossible to avoid now a days. I have not actually implemented a scripting language into an engine, but have used a couple with it already hooked in. In one case I worked in an engine that had Lua and a preprocess step during compile would run on the files and if we had certain tags around our functions that step would generate all of the code necessary to expose our c++ functions to lua. This made the system all but invisible to the other programmers. Some scripting languages may come with these tools, others may have communities which have written them as well. Certainly at the beggining you could always manually do whatever is necessary to expose your functions.

Debugging is also an interesting thing to consider when working with scripting languages. They may not come with one, you may have to find one or resort to "print" type debugging.

In general you will have a host of engine functions exposed to the scripting language like SetObjectStat, ModifyObjectStat, KillObject, CreateObject, AddBuff, AddExperience, etc.

When you have a player equip an item you may start up an instance of that items script. The code may then call a function in the script for any custom logic to be run such as:

void OnItemCreated(item_index) {  item_seed = ITEM.GetItemSeed(item_index);  item_index = item_index;}void OnEquipByObject(object_index){  random_str = RAND.GetValue(item_seed, 0, 12);  OBJECT.ModifyObjectStat(object_index, "Str", random_str);  if (PLAYER.IsPlayer(object_index)  {    CONSOLE.Say("You feel the power of the gods within you!");  }}void OnUnequipByObject(object_index){  random_str = RAND.GetValue(item_seed, 0, 12);  OBJECT.ModifyObjectStat(object_index, "Str", -random_str);}void OnStrikingAnObject(attacker, victim){  random_chance = RAND.GetValue(item_seed, 3, 5);  random_value = RAND.GetValue(0, 100);  if (random_value < random_change) {    OBJECT.AddBuff(attacker, "Invigorated");  }}


Granted adding stats is such a simple concept that almost every item will do that it is probably worth doing in the code. That and I still have the 0 and 12 hardcoded, but it gives a general idea.
// Full Sail graduate with a passion for games// This post in no way indicates my being awake when writing it
You might be interested in watching the ghost toast video tutorials on my website that show you how I handle all the objects in my game.
Quote:Original post by Runicode
What really has me confused is how to go about handling things like quests, items, etc... basically the actual game. I understand how to code the different components, just not how to create the game content without hardcoding it. I keep reading I should be using a scripting language but I haven't found any resources that really tell me what I should be doing. I've recently started reading the book Game Engine Architecture, http://www.amazon.com/Game-Engine-Architecture-Jason-Gregory/dp/1568814135/ref=sr_1_1?ie=UTF8&s=books&qid=1252878622&sr=8-1

and I've learned quite a bit, but there's nothing so far about handling these things. I know at some point I'm probably going to write myself a small level/item editor. Can anyone point me in the right direction?
This is something that depends a lot on the game - on what you want your game to be able to do. I happen to be working on a basic rpg these days, and for almost all content, a simple .csv data format suffices. I am adding npc's and items with a script, but only because that was easier to implement, not because I needed the flexibility that scripting offers. It depends on the game, really. If you have a gazillion different potions that all have a different effect, then you'll want to script that. But if you have only 2 or 3 different potions, or if those gazillion potions all add either strength or health, just different amounts... then hard-coding their effects and storing the names and amounts in a simple data format will suffice.


If it's the first time you're building such a game, then it may be useful to write some prototypes first, to experiment with different approaches. See what works well and what doesn't. It's good to use a language or platform for this that allows rapid development. I would use Python or haXe, but perhaps you're more familiar with another high-level language.
Create-ivity - a game development blog Mouseover for more information.
at this stage you don't need scripting persay, I mean you could create a simple text format that you can parse or something like that.


#default inventory list.inv
#this is a list of items a player starts off with
weapon axe 20 30 34
weapon sword 10 70 15
potion health 10





full lua scripting may be overkill, what you're looking for is to implement some data-driven design aspects.
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
I am using full fledged lua and it is definitely really cool...

I just gave a presentation at my university almost exactly on this subject.

Its not on youtube yet but when the university puts it up I'll post it.

In short, a csv file is not robust enough for game logic.

For me, i have a bunch of core engine types, from cameras to lights, which i have arrays of in my engine. Lua can tell the engine to create instances of these types, along with storing basic functionality or which camera is active and which light is on or whatever.

The important thing here is the engine has no idea what is going on other than the fact that it is displaying what lua tells it to. Lua keeps track of the State of the "game". All data for things like hit points of an object and stuff can be stored in a lua table, and when something collides or is clicked on, an event can be fired (in my event system) and implemented via a listener. I also have iterators for 2d objects and 3d objects. 2d stuff is like buttons and interfaces, where 3d stuff is the game (it actually can go either way).

Thats the gist of it, there is a lot more to it though.

------------------------------

redwoodpixel.com

This topic is closed to new replies.

Advertisement