Jump to content

  • Log In with Google      Sign In   
  • Create Account


Nanoha

Member Since 26 Feb 2009
Offline Last Active Dec 07 2011 01:19 PM

Topics I've Started

How to use templated subscript operator? (c++)

02 September 2011 - 01:25 PM

I have a blackboard class that can take Generic types. Originally I had:

class Blackboard
{
	template <class T>
	T&	GetEntry(const std::string &key);
};

// I use it something like:
Blackboard bb;
int &someInt = bb.GetEntry<int>("some_int");
float &someFloat = bb.GetEntry<float>("some_float");
int someOtherInt = 10;
bb.SetEntry("some_other_int", someOtherInt );


I would like to make use of the subscript operator like so instead:

class Blackboard
{
	template <class T>
	T&				operator[](const std::string &key);
};

How do I actually use the second option though? So far I can only do it like:

bb.operator[]<int>("some_int") = 5;

I don't like that, if thats what I have to do then I will stick with my Get/SetEntry method. So is that how you use a templated []operator or is there a slightly nicer way?

Thanks.

Bullet starting location

28 May 2011 - 02:55 AM

Odd question, the barrel of the gun right?

The problem I have, is knowing where the barrel of the gun is (in world space). I'm using Ogre3d with a logic/view split. My player/monsters have a scene node, which has a model, which has a skelington, I attach guns to the palm. The guns also have some bones, one of which is the barrel (I use it to show the muzzle flash/attach rocket to an rpg). I Can work out where this is in world space but only on the "view" side of things.

I had a similar problem working out where the "eyes" are (Since its a camera attached to.. and so on). I solved that by creating a new type of Ogre object that works out its world position and sends it in my message system (It can then be attached like everyhting else). I then pick up the messages and deal with them.

I'm thinking about doing that with my guns but before I do, should bullets come from the gun? I play some games (fps) where if I can see something, I can shoot it - even though there may be a wall between the gun and the target (suggesting bullets come from the eye). Other games, even if I can see a target, if there is an obstacle between the gun and the target then it will hit that obstacle instead (suggesting the shot comes from the gun barrel).

My bullets are just rays but I also have an rpg which looks slightly odd firing from the eye (although making it start a meter away may look ok with all the smoke too). Currently I shoot from the eye and all is sort of well but my monsters don't have cameras and so think they are shooting from (0, 0, 0).

Comments, suggestions, criticisms and so forth all welcome.

One thing I will not do however, is to access my "view" directly, so no direct access to the pistols model or anything.

Thanks

lua runtime error when inheriting from c++ classes

12 March 2011 - 10:17 AM

I have a class that I expose to lua using luabind. I then inherit from this class and overide some of its functionality. All works well and if I don't define a particular function in lua then the default c++ one is called. I'm trying to add another method to this class with more or less the exact same format but this particular method will not work. I get the following error when the method is not defined in lua (if I define the class in lua all works well but I want the defaults):

lua runtime error: No matching overload found, candidates:
void OnRender(custom [class Overkill::GameState]*, unsigned int)

This is how I'm defining/exposing my class. I've included a similar method that does work.

Declaration:
class IGameState
{
public:
   virtual void OnRender(unsigned int elapsedMiliseconds) = 0;
   virtual void OnEnter(GameStateMachine *stateMachine) = 0;   
};

class GameState: public IGameState
{
public:
   virtual void OnRender(unsigned int elapsedMiliseconds);
   virtual void OnEnter(GameStateMachine *stateMachine);  
};

class GameStateWrapper: public GameState, public luabind::wrap_base
{
public:
   virtual void OnEnter(GameStateMachine *stateMachine);
   static void DefaultOnEnter(GameState *ptr, GameStateMachine *stateMachine);

   virtual void OnRender(unsigned int elapsedMiliseconds);
   static void DefaultOnRender(GameState *ptr, unsigned int elapsedMiliseconds);
};

Implementation:
void GameState::OnEnter(GameStateMachine *stateMachine)
{
   assert(!m_Parent && "m_Parent != NULL");
   m_Parent = stateMachine;
}

void GameState::OnRender(unsigned int elapsedMiliseconds)
{
   m_Root->renderOneFrame();
}

void GameStateWrapper::OnEnter(GameStateMachine *stateMachine)
{
   call<void>("OnEnter", stateMachine);
}

void GameStateWrapper::DefaultOnEnter(GameState *ptr, GameStateMachine *stateMachine)
{
   ptr->GameState::OnEnter(stateMachine);
}

void GameStateWrapper::OnRender(unsigned int elapsedMiliseconds)
{
   call<void>("OnRender", elapsedMiliseconds);
}

void GameStateWrapper::DefaultOnRender(GameState *ptr, unsigned int elapsedMiliseconds)
{
   ptr->GameState::OnRender(elapsedMiliseconds);
}

This is how I'm exposing them:
module(state)
[
   namespace_("Overkill")
   [
      class_<GameStateWrapper, GameStatePtr>("GameState")
         .def("OnEnter", &GameState::OnEnter, &GameStateWrapper::DefaultOnEnter)
         .def("OnRender", &IGameState::OnRender, &GameStateWrapper::DefaultOnRender)
   ]
];

I've read around this problem alot, mostly solved but the solutions haven't fixed this. I've tried all sorts, tried changing the function names, changin the parameters, removing the parameters, using free functions, defining the base classes. This is pretty much exactly the same as shown here just with different names. I've also cleaned and rebuilt several times.

If I add this to my script:

function TitleScreenState:OnRender(ms)
   self.root:renderOneFrame();
end

Then all works well, I don't define some of the other methods and they also work ok, its just this OnRender one (althought with completely different names and parameters it still doens't work which is odd).

Thanks

Invalid address specified to RtlValidateHeap with luabind/CEGUI/Ogre

07 March 2011 - 04:27 PM

I have a problem with heap corruption (or so it says) when I close one of my lua states (on exitting my game). This isn't a huge problem as it only occurs when I quit but its hiding my exceptions which is making other things harder.

I have 2 states, one works perfectly and closes correctly (with everything I have exposed to it), main game thing) but I'm trying to get my ui scripted using Ogre/CEGUI. It is this state thats causing me problems. If I don't expose any of my own classes to the state then everything works fine. It seems to be a problem with luabind. CEGUI is using tolua++ to expose itself. Everything works ok appart from when I close the state (indirectly). This is the shortest snippet that will cause the problem:


CEGUI::LuaScriptModule &scriptModule = CEGUI::LuaScriptModule::create();
lua_State *lua = scriptModule.getLuaState();
system->setScriptingModule(&scriptModule);
luabind::open(lua);
luabind::module(lua)
[
   luabind::class_<Test>("Test")
];
CEGUI::LuaScriptModule::destroy(scriptModule);


My output window says:
HEAP[Overkilld.exe]: Invalid address specified to RtlValidateHeap( 028D0000, 00C22E78 )
Windows has triggered a breakpoint in Overkilld.exe.
This may be due to a corruption of the heap, which indicates a bug in Overkilld.exe or any of the DLLs it has loaded.

I've tried passing in my own lua_State (rather than have the script module create its own but it causes the same problem). Its not much to go on I know but is there anything I can try?

Thanks



Where should AI be implemented?

21 January 2011 - 12:13 PM

Hello, I am slightly confused as to where I should put my AI (architecturally). I have a logic/view split where logic is completely seperate from audio/visual/input. They communicate via messages/events. Initially when I was reading about such a split it was a case of making a new "view" for each AI. The AI would see and react to the events and control an entity the same way the player does.

The problem I have is that events aren't really suitable for the task (I could make them more suitable) and that I would have to get alot of data from the logic in order to make the AI function(destroying the split). My events are things like "PlaySound", "UpdateScene?Node, "PlayAnimation" etc and have nothing regarding the entities themself.

MY entities are component based and so adding an AI component would be a logical choice. Any suggestions as to what I should go for (or alternate ideas)? AI as a seperate "view" or AI as a component?

Thanks

PARTNERS