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:
parent
53207a9ff0
commit
ddad27a5f9
7 changed files with 41 additions and 27 deletions
|
@ -18,7 +18,8 @@ namespace FFXIVClassic_Map_Server
|
|||
public static Logger Log;
|
||||
public static Server Server;
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace FFXIVClassic_Map_Server
|
|||
|
||||
private Server mServer;
|
||||
|
||||
private const int MILIS_LOOPTIME = 10;
|
||||
private const int MILIS_LOOPTIME = 333;
|
||||
private Timer mZoneTimer;
|
||||
|
||||
//Content Groups
|
||||
|
@ -1017,6 +1017,7 @@ namespace FFXIVClassic_Map_Server
|
|||
Program.Tick = DateTime.Now;
|
||||
foreach (Zone zone in zoneList.Values)
|
||||
zone.Update(Program.Tick);
|
||||
Program.LastTick = Program.Tick;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -616,6 +616,9 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
{
|
||||
foreach (Actor a in mActorList.Values)
|
||||
a.Update(tick);
|
||||
|
||||
var deltaTime = (tick - Program.LastTick).Milliseconds;
|
||||
LuaEngine.GetInstance().CallLuaFunction(null, this, "onUpdate", true, deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -166,9 +166,9 @@ namespace FFXIVClassic_Map_Server.actors.area
|
|||
public override void Update(DateTime tick)
|
||||
{
|
||||
// todo: again, this is retarded but debug stuff
|
||||
var diffTime = tick - lastUpdate;
|
||||
base.Update(tick);
|
||||
|
||||
var diffTime = tick - lastUpdate;
|
||||
// arbitrary cap
|
||||
if (diffTime.Milliseconds >= 33)
|
||||
{
|
||||
|
|
|
@ -396,8 +396,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
|
||||
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
|
||||
|
|
|
@ -103,7 +103,7 @@ namespace FFXIVClassic_Map_Server.lua
|
|||
}
|
||||
|
||||
foreach (Coroutine key in mToAwake)
|
||||
{
|
||||
{
|
||||
DynValue value = key.Resume();
|
||||
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)
|
||||
{
|
||||
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);
|
||||
if (player != null)
|
||||
{
|
||||
|
@ -329,7 +329,7 @@ namespace FFXIVClassic_Map_Server.lua
|
|||
catch (ScriptRuntimeException e)
|
||||
{
|
||||
SendError(player, e.DecoratedMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,9 +354,9 @@ namespace FFXIVClassic_Map_Server.lua
|
|||
if (script != null)
|
||||
{
|
||||
if (!script.Globals.Get(funcName).IsNil())
|
||||
{
|
||||
{
|
||||
//Run Script
|
||||
DynValue result = script.Call(script.Globals[funcName], args2);
|
||||
DynValue result = script.Call(script.Globals[funcName], args2);
|
||||
List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
|
||||
return lparams;
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ namespace FFXIVClassic_Map_Server.lua
|
|||
DynValue result = script.Call(script.Globals[funcName], args);
|
||||
List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
|
||||
return lparams;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -434,26 +434,27 @@ namespace FFXIVClassic_Map_Server.lua
|
|||
lparams.Insert(0, new LuaParam(2, eventStart.triggerName));
|
||||
if (mSleepingOnPlayerEvent.ContainsKey(player.actorId))
|
||||
{
|
||||
Coroutine coroutine = mSleepingOnPlayerEvent[player.actorId];
|
||||
Coroutine coroutine = mSleepingOnPlayerEvent[player.actorId];
|
||||
mSleepingOnPlayerEvent.Remove(player.actorId);
|
||||
|
||||
try{
|
||||
try
|
||||
{
|
||||
DynValue value = coroutine.Resume();
|
||||
ResolveResume(null, coroutine, value);
|
||||
ResolveResume(null, coroutine, value);
|
||||
}
|
||||
catch (ScriptRuntimeException e)
|
||||
{
|
||||
LuaEngine.SendError(player, String.Format("OnEventStarted: {0}", e.DecoratedMessage));
|
||||
player.EndEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target is Director)
|
||||
if (target is Director)
|
||||
((Director)target).OnEventStart(player, LuaUtils.CreateLuaParamObjectList(lparams));
|
||||
else
|
||||
CallLuaFunction(player, target, "onEventStarted", false, LuaUtils.CreateLuaParamObjectList(lparams));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DynValue ResolveResume(Player player, Coroutine coroutine, DynValue value)
|
||||
|
@ -462,10 +463,10 @@ namespace FFXIVClassic_Map_Server.lua
|
|||
return value;
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -491,7 +492,7 @@ namespace FFXIVClassic_Map_Server.lua
|
|||
{
|
||||
bool playerNull = player == null;
|
||||
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
|
||||
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());
|
||||
|
||||
// gm commands dont need to be coroutines?
|
||||
Coroutine coroutine = script.CreateCoroutine(script.Globals["onTrigger"]).Coroutine;
|
||||
DynValue value = coroutine.Resume(LuaParam.ToArray());
|
||||
LuaEngine.GetInstance().ResolveResume(player, coroutine, value);
|
||||
try
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -677,7 +685,6 @@ namespace FFXIVClassic_Map_Server.lua
|
|||
player.SendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", message);
|
||||
player.QueuePacket(EndEventPacket.BuildPacket(player.actorId, player.currentEventOwner, player.currentEventName));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.6
|
||||
VisualStudioVersion = 15.0.26430.15
|
||||
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}"
|
||||
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}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(Performance) = preSolution
|
||||
HasPerformanceSessions = true
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
|
|
Loading…
Add table
Reference in a new issue