Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


SeiryuEnder

Member Since 02 Dec 2008
Offline Last Active Jun 28 2014 04:27 PM

Topics I've Started

Server Exception Handling

24 October 2012 - 02:02 AM

Hi,

I'm currently researching exception handling, and will be implementing it on a heavily threaded game server in the near future.

Here is what I will need:
  • Safely unwind stack, high server stability
  • Low overhead
  • Works well in a highly threaded architecture
While I am researching and have used EH before, I haven't gotten very in-depth with it and am not yet very familiar with what happens under the hood. Are there any red flags I should know about, any good book references for this sort of thing, or any ideas about how I can more effectively implement EH rather than just toggling some /EH_ flags? I realize this thread is a bit open ended, the problem I suppose is that I don't yet know what questions I should be asking and hope to pick the brains of those more experienced with this sort of thing.

Thanks~!

Using C++-Allocated Objects in Lua

04 June 2012 - 01:04 PM

Right now I'm using Luna to expose my C++ classes to Lua. The problem I'm having is that I want to allocated and manage my objects in C++, only using Lua to potentially create or manipulate them.

I'm not particularly familiar with Lua. My (rather naive) first attempt was to set up a class as per some Luna tutorials, create that class using a factory, pass that class to Lua using lua_pushlightuserdata, and create an object reference in lua to the pointer in the stack.

As it turns out, Lua doesn't know how to interpret that pointer as it defines 'objects' by metatables which a raw memory address won't have. After giving it some thought, I'm currently considering creating an interface class which contains all of my Lua functions. The constructor will accept a parameter to its target class. Because it is only an interface and doesn't contain any actual data, it doesn't cost much to instantiate it whenever a script is run and let the GC clean it up.

However, not only does this seem inefficient but I completely lose type-safety. The script could theoretically pass anything into the lua interface which can crash the program (or worse). Does anyone more experienced with C++-Lua binding know how I can achieve my original goal of handing a C++ object to lua, or have any more elegant solutions? I'll add some pseudo-code below to make my problem a bit more clear.

Current Attempt:
std::vector<GameObject*> objList;

class GameObject
{
public:
	 void DoThing() {}
	 int Do( lua_State* _state ) { DoThing(); }

	 ... insert Luna binding code
}

int CreateObject( lua_State* _state )
{
	 GameObject* obj = new GameObject();
	 objList.push_back( obj );
	 lua_pushlightuserdata( _state, (void*)obj );
	 return 1;
}


int main()
{
	 lua_State* state = luaL_newstate();
	 lua_register( state, "CreateObject", CreateObject );
	 luaL_loadfile( m_State, "DoSomething.lua" );
	 lua_pcall( state, 0, LUA_MULTRET, 0 );
	 lua_close( state );

	 return 0;
}

DoSomething.lua:
local obj = CreateObject( "LuaScript" )
obj.Do()

...This won't work because Lua doesn't know how to interpret that (void*), I incorrectly thought that it would maintain some sort of VFT-esque behavior.

The method I talked about as a potential solution would be something akin to:
class GameObject
{
public:
	 void DoThing() {}
};

class LIGameObject
{
public:
	 LIGameObject( GameObject* _target ) : m_Target(_target) {}
	 int Do( lua_State* _state ) { m_Target->DoThing(); }
	 ... insert Luna binding code
private:
	 GameObject* m_Target;
};

int CreateObject( lua_State* _state )...
int main()...

DoSomething.lua:
obj = LIGameObject( CreateObject( "LuaScript" ) )
obj.Do()

Defining Entities using XML/Lua

02 June 2012 - 05:24 PM

I've been developing a data-driven Entity/Component system in C++ using Lua. There's been a lot of good documentation out there, but I've hit a bit of a snag with Lua.


-edit 1:

My problem is likely to do with the need to bind classes to Lua rather than using a factory to create components... Still doing research on that


-edit 2:

After some thought and playing with Luna, I'm going to try registering components with my factory and feeding the base pointer address back to Lua.

From there I should be able to call the expected mapped function. I don't know what kind of error handling this will have (if any), but at least it's moving in a direction.



Summarized Question
How do I create objects with a C++ factory using Lua and define necessary parameters while maintaining type-safety?
My goal is to be able to determine at runtime if there is a parameter mismatch when defining a component.

More Information
The system works like this:

Open OnLoad.lua
-OnLoad.lua loads _Level_.lua
--_Level_.lua loads and posititions Entities in the world
---Game parses XML file for (each) Entity definition

[One of two ways to handle this]

A
----Entity tag references _Entity_.lua
-----_Entity_.lua loads components

OR

B
----Entity tag body contains a list of components along with component property definitions

Problem 1:
Not a huge problem, but a mild design question. Method A is more expandable (Lua can perform other actions when loading different types of entities, may be useful), but Method B is simpler and centralized. Right now I'm leaning towards defining entities in Lua to err on the side of caution, as I may need the extra functionality later. Which do you think is the preferable method?

Problem 2:
I'm stuck on how to actually construct the components. I'm sure there's a simple solution, but for some reason it eludes me. Different components may need different parameters. For instance, I may need no parameters at all for a Timer component but will need a name/ID for a Mesh component. I'd like to figure out a way to register the component with my object factory but that would mean having to have a default constructor and defining a different Init(...) function for each type of component. When I create the object with the factory I will get a base class pointer back, so I have no (type-safe) way of knowing what parameters the init function will need. I'm just not making the connection on how to define properties of a component in XML/Lua then pass that information to its appropriate place in C++. I've considered more elaborate methods of defining property tables in my components, but that seems inefficient and overcomplicated.

As always, thanks in advance for any help!

Engine-Tool Runtime Communication

30 May 2012 - 09:58 PM

I'm currently developing a world building tool for my game engine.

The engine is written in C++, and the tool is written in C#.

Ideally, I want to design things so that the engine renders to a surface in the tool and the tool communicates with the engine at runtime for entity creation/placement/etc.

What are the best technical approaches to making this happen? Specifically, what is an efficient and maintainable method I can use to establish communication between the tool and the engine?

-edit
I realize this is something I could probably google, I'm just not entirely sure where to start. So... thank you for your patience and any direction/guidance!

Converting set to multiset

09 March 2012 - 12:34 PM

I have written a set class which acts similarly to the STL set class.
Everything functions properly there.
I am now trying to convert this set class into a multiset.

A set class essentially stores its data as a sorted binary tree.
In order to make this a multiset I assume I just insert duplicate key/value pairs left or right and rebalance the tree.

However, I don't really like to assume things, and I'm not sure about what types of limitations this could impose.
Should I instead make a container in each node or a separate nested node list for identical keys?

For instance, structure with a nested node list:
................A
...........B.......C
........../.|.\...../.|.\
........D.E.F.G.H.I
............|.........|
............J........K

Based on simple sorting:
.................A
...........B.........C
........../...\....../...\
........E....F..H.....I
......./........./
.....J........K
..../......../
..D......G

Where the keys for BEJ are the same, and CHK are the same.

Anyone done something similar? Thoughts on the fastest/best way to implement?

It seems to me that adding a nested node list imposes a pretty significant memory overhead (as nodes without duplicate keys will contain a useless pointer) but will be faster to insert while the simple sorting method will be more memory efficient but take longer to insert.

PARTNERS