Andy Gilbert Posted November 23, 2012 Share Posted November 23, 2012 Hi, Im wanting to put all my physics calculations into a physics fixed update function based on the callback that the document present im a but unsure how i do this as it has a parameter for an entity? Can i not have a single function that does all the physics routines every physics update? Thanks Andy Quote The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d Link to comment Share on other sites More sharing options...
Flexman Posted November 24, 2012 Share Posted November 24, 2012 I don't think there's a global physics update callback. the Entity callback is your best bet. This is called during UpdateWorld(). Assign it to every entity then branch off for specific types in a single function. But you probably did this already. ' INITIALISING ENTITYS IN A LOOP, SET THE PHYSICS CALLBACK ' ... SetEntityCallback(newEntity, UpdatePhysicsCallback, ENTITYCALLBACK_UPDATEPHYSICS) ; ... ... ' CALLED 60 FPS REGARDLESS OF FRAMERATE ' Function UpdatePhysicsCallback(entity:TEntity) if (entity <> Null) if (game.LocalPlayer.entity = entity) UpdateLocalPlayerPhysics(entity) ; Else UpdateRemoteEntityPhysics(entity); End If End If End Function If you have to do this for lots of entities, but have many of a specific type, it would make sense to use caching to your advantage by having specific callback functions for them. Quote 6600 2.4G / GTX 460 280.26 / 4GB Windows 7 Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT Tricubic Studios Ltd. ~ Combat Helo Link to comment Share on other sites More sharing options...
Rick Posted November 24, 2012 Share Posted November 24, 2012 To build off of what Flexman has shown, you could fake 1 update call by having an EntityManager class that stores an entity and a list of entities. Whenever you make an entity you add it to this list. Then you only register the callback to the 1 entity in this class. When that entity update gets called, you cycle through the list of all other entities. class EntityManager { private: TEntity _entity; list<TEntity> _entities; public: EntityManager() { SetEntityCallback(_entity, UpdatePhysicsCallback, ENTITYCALLBACK_UPDATEPHYSICS); SetEntityUserData(_entity, (byte*)this); } list<TEntity>& GetEntities() { return _entities; } void AddEntity(TEntity e) { _entities.push_back(e); } }; void _stdcall UpdatePhysicsCallback(TEntity ent) { EntityManager* mgr = (EntityManager*)GetEntityUserData(ent); // now you can call mgr->GetEntities() and loop over them all to process or maybe just call a function in the EntityManager class that will loop so that yo don't have to expose the list of entities to anything else. } 1 Quote Link to comment Share on other sites More sharing options...
Andy Gilbert Posted November 26, 2012 Author Share Posted November 26, 2012 Thanks for this, i actually only have 1 physics entity, so should be to big a problem to impliment. Thanks Andy Quote The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d Link to comment Share on other sites More sharing options...
Andy Gilbert Posted November 26, 2012 Author Share Posted November 26, 2012 Hi, just wondering how this can be done with lua? Cant seem to get the command to work? Thanks Andy Quote The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d Link to comment Share on other sites More sharing options...
Andy Gilbert Posted December 3, 2012 Author Share Posted December 3, 2012 Does anyone know if the above command works in lua, or is meant to work? Thanks Andy Quote The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d Link to comment Share on other sites More sharing options...
DaDonik Posted December 3, 2012 Share Posted December 3, 2012 Since the Callback functions are only documented for C/C++ and Blitzmax, i don't think it's possible to do that from LUA. To be honest i also never tried... Quote (Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI) Link to comment Share on other sites More sharing options...
Rick Posted December 3, 2012 Share Posted December 3, 2012 No clue, but in LE Lua a model with a script attached to it that is structured in the template that is in the Script folder has a physics update function callback in it. If you just have the 1 model then attached this script to it, put the script in the same dir and name it the same as the model, and then those functions will be automatically called. Quote Link to comment Share on other sites More sharing options...
Canardia Posted December 3, 2012 Share Posted December 3, 2012 You can use the UpdatePhysics hook: require("Scripts/constants/keycodes") require("Scripts/console") local bonks=0 local frames=0 function MyPhysicsHook() bonks=bonks+1 AddConsoleText("PhysicsUpdates: "..bonks.." Frame: "..frames) end --Register abstract path RegisterAbstractPath("") --Set graphics mode if Graphics(1024,768)==0 then Notify("Failed to set graphics mode.",1) return end world=CreateWorld() if world==nil then Notify("Failed to initialize engine.",1) return end fw=CreateFramework() camera=fw.main.camera camera:SetPosition(Vec3(0,0,-2)) light=CreateSpotLight(10) light:SetRotation(Vec3(45,55,0)) light:SetPosition(Vec3(5,5,-5)) model=LoadModel("abstract::oildrum.gmf") ground=CreateBodyBox(10,1,10) groundmesh=CreateCube(ground) groundmesh:SetScale(Vec3(10.0,1.0,10.0)) ground:SetPosition(Vec3(0.0,-2.0,0.0)) groundmesh:Paint(LoadMaterial("abstract::cobblestones.mat")) ground:SetCollisionType(1) Collisions(1,1,1) --DebugPhysics(1) SetStats(0) light=CreateDirectionalLight() light:SetRotation(Vec3(45,45,45)) local timer=AppTime()+1000 consolemode=1 AddHook("UpdatePhysics",MyPhysicsHook) while AppTerminate()==0 do if KeyHit(KEY_ESCAPE)==1 then break end if timer<AppTime() then timer=AppTime()+1000; model=CopyEntity(model) model:SetPosition(Vec3(0,10,0)) end fw:Update() fw:Render() frames=frames+1 DrawText("FPS: "..UPS(),300,0) Flip(0) end Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Andy Gilbert Posted December 3, 2012 Author Share Posted December 3, 2012 ahh that seems good, so does this go back to my original question? All the physics code can go inside that physicshook function? Thanks Andy Quote The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.