• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

129 Neutral

About MajinMLF

  • Rank
  1. [quote name='Gambini' timestamp='1339366157' post='4948021'] This is one heck of a question. I am not familliar with luabind, so I will go over the general ideas, and maybe hit some specifics. [/quote] Aye, and thanks alot for taking the time to lay out all that - i checked this post yesterday regularly but there wasnt a reply and in the meantime i got the idea to the solution myself which is basically similar to your pseudo code - however there is a gist - first the basic schedule function was pretty easy - its just a callback which - as you said i check the time in c++ - here it is for completion [CODE] void NPC::AddSE(const luabind::objectluabind::object &fn,int millisec) { if(luabind::type(fn) == LUA_TFUNCTION) { ScheduledEvent sEvent; sEvent.eventFunction = fn; sEvent.time = GetMilliCount() + millisec; printf("AddScheduledEvent\n"); m_scheduledEventFunctions.push_back(sEvent); } } void NPC::CheckForScheduledEvents() { std::vector<ScheduledEvent>::iterator sEvent = m_scheduledEventFunctions.begin(); while (sEvent != m_scheduledEventFunctions.end()) { if(sEvent->time < GetMilliCount()) { if(sEvent->eventFunction.is_valid()) { luabind::call_function<void>(sEvent->eventFunction); } // erase returns the new iterator sEvent = m_scheduledEventFunctions.erase(sEvent); } else { ++sEvent; } } } [/CODE] Now the hard part was having scheduled movie like events with delays in between for scheduled events e.g. NPC:Say("Hello") WaitTime(1000) NPC:Say("Continue after 1sec") That without letting the mainloop sleep! I got around this with the unique function of lua = coroutines - basically if WaitTime calls yield(x) the x will be returned to my lua_resume function - and in my code i will schedule the next call to resume after XX amount of time. [quote name='Gambini' timestamp='1339366157' post='4948021'] To answer your second question: The functions are in the same scope as long as they are loaded (luaL_dofile) with the same lua_State. So you can call those functions any time you want. However, I do suggest that you create tables named after each NPC behavior to hold those functions to avoid name conflicts. [/quote] Yes - thats what i want todo - is there a scope for a lua_state ? i dont like to name my functions unqiuely in each lua script - e.g. there should be no collision - how can i export one lua script to a specific scope only valid for one NPC ? Lets say all NPCs have an ID instead of doing luabind::globals(myLuaState)["npc"] = npc; i somehow have to put this NPC only in the scope of the loaded script - which brings the next problem if i use Lual_doFile or similar luaL_dostring(myLuaState, "code...") how put this in a scope ? I dont want that the scripts need to make namespaces or something similar - this should be safely done in c++ code. To reach the script of another NPC i would just expose an object to lua e.g. npc->GetScript()->CallFunction(luabind::object)... (I gather best practise is to have one lua_state for all NPCs and not multiple) Any idea? And thanks again =)
  2. Help me with ASM

    This is a ida pro dump (CODE XREF: gives it away) - so why not use hexrays to give you pseudo c
  3. 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
  4. 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?
  5. 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 [code] 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; } [/code] 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
  • Advertisement