1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-24 13:47:46 +00:00

fixed high cpu usage caused by spawning stupid amounts of script objects each tick

This commit is contained in:
Tahir Akhlaq 2017-07-18 04:51:35 +01:00
parent 53207a9ff0
commit ddad27a5f9
7 changed files with 41 additions and 27 deletions

View file

@ -18,7 +18,8 @@ namespace FFXIVClassic_Map_Server
public static Logger Log; public static Logger Log;
public static Server Server; public static Server Server;
public static Random Random; public static Random Random;
public static DateTime Tick; public static DateTime LastTick = DateTime.Now;
public static DateTime Tick = DateTime.Now;
static void Main(string[] args) static void Main(string[] args)
{ {

View file

@ -40,7 +40,7 @@ namespace FFXIVClassic_Map_Server
private Server mServer; private Server mServer;
private const int MILIS_LOOPTIME = 10; private const int MILIS_LOOPTIME = 333;
private Timer mZoneTimer; private Timer mZoneTimer;
//Content Groups //Content Groups
@ -1017,6 +1017,7 @@ namespace FFXIVClassic_Map_Server
Program.Tick = DateTime.Now; Program.Tick = DateTime.Now;
foreach (Zone zone in zoneList.Values) foreach (Zone zone in zoneList.Values)
zone.Update(Program.Tick); zone.Update(Program.Tick);
Program.LastTick = Program.Tick;
} }
} }

View file

@ -616,6 +616,9 @@ namespace FFXIVClassic_Map_Server.Actors
{ {
foreach (Actor a in mActorList.Values) foreach (Actor a in mActorList.Values)
a.Update(tick); a.Update(tick);
var deltaTime = (tick - Program.LastTick).Milliseconds;
LuaEngine.GetInstance().CallLuaFunction(null, this, "onUpdate", true, deltaTime);
} }
} }

View file

@ -166,9 +166,9 @@ namespace FFXIVClassic_Map_Server.actors.area
public override void Update(DateTime tick) public override void Update(DateTime tick)
{ {
// todo: again, this is retarded but debug stuff // todo: again, this is retarded but debug stuff
var diffTime = tick - lastUpdate;
base.Update(tick); base.Update(tick);
var diffTime = tick - lastUpdate;
// arbitrary cap // arbitrary cap
if (diffTime.Milliseconds >= 33) if (diffTime.Milliseconds >= 33)
{ {

View file

@ -396,8 +396,7 @@ namespace FFXIVClassic_Map_Server.Actors
public override void Update(DateTime tick) public override void Update(DateTime tick)
{ {
var deltaTime = (tick - aiContainer.GetLatestUpdate()).Milliseconds;
LuaEngine.GetInstance().CallLuaFunction(null, this, "onUpdate", true, deltaTime);
} }
//A party member list packet came, set the party //A party member list packet came, set the party

View file

@ -103,7 +103,7 @@ namespace FFXIVClassic_Map_Server.lua
} }
foreach (Coroutine key in mToAwake) foreach (Coroutine key in mToAwake)
{ {
DynValue value = key.Resume(); DynValue value = key.Resume();
ResolveResume(null, key, value); ResolveResume(null, key, value);
} }
@ -278,7 +278,7 @@ namespace FFXIVClassic_Map_Server.lua
private void CallLuaFunctionNpc(Player player, Npc target, string funcName, bool optional, params object[] args) private void CallLuaFunctionNpc(Player player, Npc target, string funcName, bool optional, params object[] args)
{ {
object[] args2 = new object[args.Length + (player == null ? 1:2)]; object[] args2 = new object[args.Length + (player == null ? 1 : 2)];
Array.Copy(args, 0, args2, (player == null ? 1 : 2), args.Length); Array.Copy(args, 0, args2, (player == null ? 1 : 2), args.Length);
if (player != null) if (player != null)
{ {
@ -329,7 +329,7 @@ namespace FFXIVClassic_Map_Server.lua
catch (ScriptRuntimeException e) catch (ScriptRuntimeException e)
{ {
SendError(player, e.DecoratedMessage); SendError(player, e.DecoratedMessage);
} }
} }
} }
@ -354,9 +354,9 @@ namespace FFXIVClassic_Map_Server.lua
if (script != null) if (script != null)
{ {
if (!script.Globals.Get(funcName).IsNil()) if (!script.Globals.Get(funcName).IsNil())
{ {
//Run Script //Run Script
DynValue result = script.Call(script.Globals[funcName], args2); DynValue result = script.Call(script.Globals[funcName], args2);
List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result); List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
return lparams; return lparams;
} }
@ -386,7 +386,7 @@ namespace FFXIVClassic_Map_Server.lua
DynValue result = script.Call(script.Globals[funcName], args); DynValue result = script.Call(script.Globals[funcName], args);
List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result); List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
return lparams; return lparams;
} }
} }
return null; return null;
} }
@ -434,26 +434,27 @@ namespace FFXIVClassic_Map_Server.lua
lparams.Insert(0, new LuaParam(2, eventStart.triggerName)); lparams.Insert(0, new LuaParam(2, eventStart.triggerName));
if (mSleepingOnPlayerEvent.ContainsKey(player.actorId)) if (mSleepingOnPlayerEvent.ContainsKey(player.actorId))
{ {
Coroutine coroutine = mSleepingOnPlayerEvent[player.actorId]; Coroutine coroutine = mSleepingOnPlayerEvent[player.actorId];
mSleepingOnPlayerEvent.Remove(player.actorId); mSleepingOnPlayerEvent.Remove(player.actorId);
try{ try
{
DynValue value = coroutine.Resume(); DynValue value = coroutine.Resume();
ResolveResume(null, coroutine, value); ResolveResume(null, coroutine, value);
} }
catch (ScriptRuntimeException e) catch (ScriptRuntimeException e)
{ {
LuaEngine.SendError(player, String.Format("OnEventStarted: {0}", e.DecoratedMessage)); LuaEngine.SendError(player, String.Format("OnEventStarted: {0}", e.DecoratedMessage));
player.EndEvent(); player.EndEvent();
} }
} }
else else
{ {
if (target is Director) if (target is Director)
((Director)target).OnEventStart(player, LuaUtils.CreateLuaParamObjectList(lparams)); ((Director)target).OnEventStart(player, LuaUtils.CreateLuaParamObjectList(lparams));
else else
CallLuaFunction(player, target, "onEventStarted", false, LuaUtils.CreateLuaParamObjectList(lparams)); CallLuaFunction(player, target, "onEventStarted", false, LuaUtils.CreateLuaParamObjectList(lparams));
} }
} }
public DynValue ResolveResume(Player player, Coroutine coroutine, DynValue value) public DynValue ResolveResume(Player player, Coroutine coroutine, DynValue value)
@ -462,10 +463,10 @@ namespace FFXIVClassic_Map_Server.lua
return value; return value;
if (player != null && value.String != null && value.String.Equals("_WAIT_EVENT")) if (player != null && value.String != null && value.String.Equals("_WAIT_EVENT"))
{ {
GetInstance().AddWaitEventCoroutine(player, coroutine); GetInstance().AddWaitEventCoroutine(player, coroutine);
} }
else if (player != null && value.Tuple != null && value.Tuple.Length >= 1 && value.Tuple[0].String != null) else if (value.Tuple != null && value.Tuple.Length >= 1 && value.Tuple[0].String != null)
{ {
switch (value.Tuple[0].String) switch (value.Tuple[0].String)
{ {
@ -491,7 +492,7 @@ namespace FFXIVClassic_Map_Server.lua
{ {
bool playerNull = player == null; bool playerNull = player == null;
if (playerNull && param.Length >= 2) if (playerNull && param.Length >= 2)
player = Server.GetWorldManager().GetPCInWorld(param[1] + " " + param[2]); player = Server.GetWorldManager().GetPCInWorld(param[1] + " " + param[2]);
// load from scripts/commands/gm/ directory // load from scripts/commands/gm/ directory
var path = String.Format("./scripts/commands/gm/{0}.lua", cmd.ToLower()); var path = String.Format("./scripts/commands/gm/{0}.lua", cmd.ToLower());
@ -620,9 +621,16 @@ namespace FFXIVClassic_Map_Server.lua
//script.Call(script.Globals["onTrigger"], LuaParam.ToArray()); //script.Call(script.Globals["onTrigger"], LuaParam.ToArray());
// gm commands dont need to be coroutines? // gm commands dont need to be coroutines?
Coroutine coroutine = script.CreateCoroutine(script.Globals["onTrigger"]).Coroutine; try
DynValue value = coroutine.Resume(LuaParam.ToArray()); {
LuaEngine.GetInstance().ResolveResume(player, coroutine, value); Coroutine coroutine = script.CreateCoroutine(script.Globals["onTrigger"]).Coroutine;
DynValue value = coroutine.Resume(LuaParam.ToArray());
GetInstance().ResolveResume(player, coroutine, value);
}
catch (Exception e)
{
Program.Log.Error("LuaEngine.RunGMCommand: {0} - {1}", path, e.Message);
}
return; return;
} }
} }
@ -677,7 +685,6 @@ namespace FFXIVClassic_Map_Server.lua
player.SendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", message); player.SendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", message);
player.QueuePacket(EndEventPacket.BuildPacket(player.actorId, player.currentEventOwner, player.currentEventName)); player.QueuePacket(EndEventPacket.BuildPacket(player.actorId, player.currentEventOwner, player.currentEventName));
} }
} }
} }

View file

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26430.6 VisualStudioVersion = 15.0.26430.15
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FFXIVClassic Map Server", "FFXIVClassic Map Server\FFXIVClassic Map Server.csproj", "{E8FA2784-D4B9-4711-8CC6-712A4B1CD54F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FFXIVClassic Map Server", "FFXIVClassic Map Server\FFXIVClassic Map Server.csproj", "{E8FA2784-D4B9-4711-8CC6-712A4B1CD54F}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
@ -23,6 +23,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher Editor", "Launcher Editor\Launcher Editor.csproj", "{0FFA9D2F-41C6-443C-99B7-665702CF548F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher Editor", "Launcher Editor\Launcher Editor.csproj", "{0FFA9D2F-41C6-443C-99B7-665702CF548F}"
EndProject EndProject
Global Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU