cassius Posted September 29, 2012 Share Posted September 29, 2012 Hi When I press the W key my character moves forward but every minute or so it stalls and wont move for a few seconds, and I hear a windows ringing noise ( warning sound) then it moves ok until it happens again. Not sure if its my program or a windows problem.Can anyone help? The include file func.h is not relevant here as it only contains anim functions and a struct. #include "engine.h" #include "func.h" TEntity scene; int main(int argc, char** argv) { Initialize(); RegisterAbstractPath("c:/mygame"); Graphics(1024,768); AFilter(4) ; TFilter(1) ; TFramework framework=CreateFramework(); if (!framework) { MessageBoxA(0,"Error","Failed to create framework.",0); return Terminate(); } TLayer layer = GetFrameworkLayer(0); TCamera cam=GetLayerCamera(layer); //Set Lua variable BP L=GetLuaState(); lua_pushobject(L,framework); lua_setglobal(L,"fw"); lua_pop(L,1); // Post Processing FX SetGodRays(0); SetHDR(0); SetSSAO(0); SetBloom(0); SetAntialias(0); SetStats(1); SetReflectionElements(ENTITY_RENDERABLE); scene = LoadScene("abstract::gamescene.sbx"); jane.model = LoadMesh("abstract::femwarrior.gmf"); villager.model = LoadMesh("abstract::actors_villager.gmf"); PositionEntity (villager.model,Vec3(42.6,1.39,-183.93)); RotateEntity( villager.model,Vec3(0,-90.0,0)); // Main character controller TController player=CreateController(); EntityType(player, 1); SetBodyMass(player, 60); SetBodyDamping(player,0.0); SetWorldGravity(Vec3(0,-20,0)); PositionEntity(player, Vec3(102.57,2.2,-192)); // Skybox SetSkybox(LoadMaterial("abstract::NiceSky.mat")); SetBackgroundColor(Vec4(1.0f, 1.0f, 1.0f, 1)); //SetBackgroundColor(Vec4(1.12f, 0.92f, 0.92f, 1)); // Movement vars float move=0.0, strafe=0.0; TVec3 camrotation=Vec3(0); float mx=0, my=0; HideMouse(); MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2); AmbientLight(Vec3(0.6)); // play music TSound theme = (LoadSound("abstract::Destination.ogg")); TSource source = (CreateSource(theme,SOURCE_LOOP)); PlaySource(source); badguy_controller(); badguy.health = 150; badguy.stopanim = false; badguy.k_framebegin = 836; badguy.k_frameend = 873; float dist; // ************************* Game loop ****************** while( !KeyHit() && !AppTerminate() ) { if( !AppSuspended() ) { mx=Curve(MouseX()-GraphicsWidth()/2,mx,6); my=Curve(MouseY()-GraphicsHeight()/2,my,6); MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2); camrotation.X=camrotation.X+my/10.0; camrotation.Y=camrotation.Y-mx/10.0; RotateEntity(cam,camrotation); move = 3.5 * (KeyDown(KEY_W) - KeyDown(KEY_S)); strafe = 3 * (KeyDown(KEY_D) - KeyDown(KEY_A)); float jump=0.0; if (KeyHit(KEY_SPACE)) { if (!ControllerAirborne(player)) { jump=8.0; } } // move faster if(MouseDown(MOUSE_RIGHT)) { if (!ControllerAirborne(player)) { move*=3.0; strafe*=2.0; } } //position enemy characters PositionEntity(badguy.model,EntityPosition(badguy.control)); MoveEntity (badguy.model,Vec3(0,1.1,0)); //Position camera and 3rd person main character TVec3 playerpos=EntityPosition(player); TVec3 camerapos=EntityPosition(cam); camerapos.Y=Curve(playerpos.Y+1.75,camerapos.Y,2.0); camerapos=Vec3(playerpos.X,camerapos.Y,playerpos.Z); camerapos=Vec3(playerpos.X,camerapos.Y,playerpos.Z); PositionEntity(cam,camerapos); MoveEntity(cam,Vec3(0,-0.1,-2.5)); PositionEntity(jane.model,(playerpos)); MoveEntity(jane.model,Vec3(0,1.3,0)); RotateEntity(jane.model,camrotation); // animate main character walking if(KeyDown(KEY_W) || KeyDown(KEY_S)) { jane.framebegin = 1483; jane.frameend = 1533; animate_jane(); } UpdateController(player, camrotation.Y, move, strafe, jump, 500.0f); // animate villager if(EntityDistance(jane.model,villager.model) < 8 ){ animate_villager(); } // badguy walk anim if(badguy.stopanim == false) { dist = EntityDistance(player,badguy.control); if (dist > 2.0 && dist < 16){ PointEntity(badguy.model, jane.model,3,1,0); badguy.framebegin = 77 ; badguy.frameend = 115 ; animate_badguy(); UpdateController(badguy.control,EntityRotation(badguy.model,1).Y, 2.5,0, 0, 500,1,0); } } // badguy attack if(badguy.stopanim == false) { if(EntityDistance(player,badguy.control) < 2.0) { badguy.framebegin = 291; badguy.frameend = 411; jane.framebegin = 924; jane.frameend = 1031; animate_badguy(); animate_jane(); badguy.health = badguy.health - 0.1; if(badguy.health < 1.0) kill_badguy(); } } if(badguy.stopanim ==true) FreeEntity(badguy.control); //*************************** UpdateFramework(); RenderFramework(); Flip(0) ; } } } // main Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Daimour Posted September 29, 2012 Share Posted September 29, 2012 Try to replace while( !KeyHit() && !AppTerminate() ) with while( !AppTerminate() ) And try to remove: if( !AppSuspended() ) Quote Link to comment Share on other sites More sharing options...
cassius Posted September 29, 2012 Author Share Posted September 29, 2012 Thanks. That didn't work but thanks for taking the time to look. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
ChrisMAN Posted September 29, 2012 Share Posted September 29, 2012 Wireless keyboard? Check your batteries? Quote Link to comment Share on other sites More sharing options...
cassius Posted September 29, 2012 Author Share Posted September 29, 2012 No its a normal desktop keyboard exept it has large lettering and no numpad. ( I have bad eyesight.).I switched off sticky keys option in control panel. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
cassius Posted September 29, 2012 Author Share Posted September 29, 2012 I just noticed that this w key problem only occurs when I hold the key down for a long time. If I let go of it every few seconds the problem is gone.Its as though the keys operate in some kind of buffer which has to be refreshed by letting the key go occasionaly. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
cassius Posted September 29, 2012 Author Share Posted September 29, 2012 My apoligies daimour. Your solution was correct. Problem solved Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ 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.