Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


MajinMLF

Member Since 21 Nov 2011
Offline Last Active Jul 15 2012 06:21 AM

Topics I've Started

Delayed execution of behavior functions in Lua/C++

09 June 2012 - 04:07 PM

Hello,

i have a game with a mainloop - on each loop i call for every NPC in the game ->ProcessAI() to execute any actions.
This is a server so the call to ProcessAI is not executed on every frame like on a client game! Its also singlethreaded.

Now i wanted to extend the C++ codebase with lua using luabind (maybe, even with boost overhead). So i expose some functions of my NPC class to LUA.

I wanted to create actor scripts for example - boss battles which have more sophisticated behaviour - whenever in my c++ ProcessAI function an event happens - i would delegate this to the corresponding lua script for the specific NPC.

i imagined in my boss.lua script i would have something like this

function OnEngageCombat(NPC)
NPC:say ("Some taunts...")
ScheduleEvent(CastEvilSpell,/*time*/2000,/*numExecutions*/1,)
end

function CastEvilSpell(NPC)
NPC:CastSpell("someSpell")
end

However - i have no idea how to do this - i gather ScheduleEvent should be some C++ function exported to Lua - but what would be the best approach to keep the object reference of the NPC (boss) with this and call a function in that script about 2 seconds later ?

Furthmore along with this delayed execution - i want that NPCs can interact with each other - my current idea is to have an actor behavior script for each special NPC.

Now what i imagined is to initiate a conversation between two NPCs e.g.

function DoGossip(NPC)
// check if NPC1 is close to NPC2
if NPC:DistanceToNpc("SomeGuy") < 10 then
StartConversation1()
end

function StartConversation1(NPC)
NPC:Say("Hello ...")
// wait a moment now trigger NPC to reply
????

Basically - how do i call a function from lua scriptA which exists in lua scriptB which is the behavior script for NPC2.
What would be a good design?

Thanks

Adding FPS Limiter for Draw7 using Blt + BackBuffer

29 November 2011 - 12:52 PM

I have an old game i like to add an FPS limiter while in windowed mode - the game uses direct7x IDDraw7 - i was able to hook into the ID3DXContext_UpdateFrame the game called and added a sleep(x) there and that worked fine, the FPS has been reduced - but i figured there is a better way todo this with the standard APIs - however as far as i gathered the default vsync with ddx7 was very cpu consuming?

Windowed IDDraw7 App still receives keyboard input while not focused/forground

21 November 2011 - 10:40 AM

I hooked an old game to enable windowed mode which uses DirectDrawCreateEx (by basically hooking CreateWindowExA, the game itself has already code for windowed mode i hooked too, so its enabled) - this works - however for some reason it still receives input while not focused.
I hooked into the container windows wndproc function and even made sure that no keypresses are dispatched whatsover when the app is not in forground - it didnt help.

My theory is, that through DirectInput the keyboard will still be queried through non WIn32 msg calls - however i debugged this and

IDDraw7::SetCooperativeLevel

is not using BACKGROUND or EXCLUSIVE bits - its just using DDSCL_NORMAL

Its not receiving mouse input only keyboard tho (maybe its a software mouse and only the keyboard is directinput, no idea). - Also weird is that while the game has focus - i can see the window desktop mouse moving - even when using SetCursor null - i worked around this issue and set the cursor rectangle to be at windowed game size - at least its hidden behind the window now - still not optimal.


Additionally, i tried to hook the DirectDrawCreateEx call - that works, but for some reason i cant use the object myself


HRESULT WINAPI Hook_DirectDrawCreateEx(GUID FAR * lpGuid, LPVOID  *lplpDD, REFIID  iid, IUnknown FAR *pUnkOuter) {
	debug_print("Hook_DirectDrawCreateEx\n");

	HRESULT res = Real_DirectDrawCreateEx(lpGuid,lplpDD,iid,pUnkOuter);


	//LPDIRECTDRAW7  testlplpDD;
	//testlplpDD = (LPDIRECTDRAW7)lplpDD;

	// Crash
	//testlplpDD->SetCooperativeLevel( 0, DDSCL_NORMAL );

	return res;
}


when i try to use any function it crashes here with an access violation - however just proxxying this works fine!

Any hints?

Thanks!





EDIT: Alright - i was confused about the IDDraw7::SetCooperativeLevel - thats actually for the display - the game uses IDirectInputDevice7::SetCooperativeLevel(DISCL_BACKGROUND) which is the issue why its receiving input while not focused - switching to FORGROUND fixes that



PARTNERS