Skip to content

Commit

Permalink
Perf improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamKenneth committed Feb 6, 2018
1 parent e5d4a8b commit 6c46f57
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 66 deletions.
2 changes: 1 addition & 1 deletion MIMWebClient/Controllers/gameStatsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public string GetWhoList()
level = player.Level,
name = player.Name,
race = player.Race,
location = Areas.ListOfRooms().FirstOrDefault(x => x.areaId == player.AreaId && x.area == player.Area && x.region == player.Region).title ?? "Unknown",
location = Startup.ReturnRooms.FirstOrDefault(x => x.areaId == player.AreaId && x.area == player.Area && x.region == player.Region).title ?? "Unknown",
playingTime = Math.Round((DateTime.Now - player.LastLoginTime).TotalHours) + " hours(s)",
idle = Math.Round((DateTime.Now - player.LastCommandTime).TotalMinutes) + " minutes(s)"

Expand Down
6 changes: 3 additions & 3 deletions MIMWebClient/Core/AI/BreadthFirstSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace MIMWebClient.Core.AI
public class BreadthFirstSearch
{
//Contains all the areas in the game
private static List<Room.Room> AreaList { get; set; } = Areas.ListOfRooms();
private static List<Room.Room> AreaList { get; set; } = Startup.ReturnRooms;
private List<Room.Room> CompletedRooms { get; set; } = new List<Room.Room>();

/// <summary>
Expand All @@ -29,11 +29,11 @@ public class BreadthFirstSearch

if (string.IsNullOrEmpty(area) || string.IsNullOrEmpty(region))
{
startingLoc = Areas.ListOfRooms().FirstOrDefault(x => x.areaId == 0 && x.area == area);
startingLoc = Startup.ReturnRooms.FirstOrDefault(x => x.areaId == 0 && x.area == area);
}
else
{
AreaList = Areas.ListOfRooms().Where(x => x.area == area && x.region == region).ToList();
AreaList = Startup.ReturnRooms.Where(x => x.area == area && x.region == region).ToList();
startingLoc = AreaList.FirstOrDefault(x => x.areaId == 0 && x.area == area);


Expand Down
4 changes: 2 additions & 2 deletions MIMWebClient/Core/AI/Pathfinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static List<Pathfinding> SearchExits(Room.Room room, int destId)
////starting path?
// var list = new List<Pathfinding>();
// var prevStep = mob.AreaId;
// var areass = Areas.ListOfRooms().OrderByDescending(i => i.areaId == mob.AreaId).ToList();
// var areass = Startup.ReturnRooms.OrderByDescending(i => i.areaId == mob.AreaId).ToList();
// foreach (var searchRoom in areass)

// foreach (var exit in searchRoom.exits.OrderBy(x => Helpers.Rand(0, searchRoom.exits.Count)).ToList())
Expand Down Expand Up @@ -158,7 +158,7 @@ public Dictionary<string, int> SearchRooms(int destId, Room.Exit exit, Room.Room
{

var newExit = new Dictionary<string, int>();
var getNewRoom = Areas.ListOfRooms().FirstOrDefault(x => x.area == exit.area && x.areaId == exit.areaId);
var getNewRoom = Startup.ReturnRooms.FirstOrDefault(x => x.area == exit.area && x.areaId == exit.areaId);

if (getNewRoom != null)
{
Expand Down
2 changes: 1 addition & 1 deletion MIMWebClient/Core/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static Dictionary<string, Action> Commands(string commandOptions, string
{
var context = HubContext.Instance;

var commandList = new Dictionary<String, Action>
var commandList = new Dictionary<string, Action>
{
{"north", () => Movement.Move(playerData, room, "North")},
{"south", () => Movement.Move(playerData, room, "South")},
Expand Down
2 changes: 1 addition & 1 deletion MIMWebClient/Core/Player/Spells/Teleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static async Task DoTeleport(Player attacker, Room room)

HubContext.Instance.SendToClient(castingTextAttacker, attacker.HubGuid);

var goToRoom = Areas.ListOfRoomsCanTeleport()[Helpers.diceRoll.Next(Areas.ListOfRooms().Count)];
var goToRoom = Areas.ListOfRoomsCanTeleport()[Helpers.diceRoll.Next(Startup.ReturnRooms.Count)];


foreach (var character in room.players)
Expand Down
28 changes: 14 additions & 14 deletions MIMWebClient/Core/Update/RestoreVitals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace MIMWebClient.Core.Update
using MIMWebClient.Core.Item;
using MIMWebClient.Core.PlayerSetup;
using MIMWebClient.Core.Room;
using MIMWebClient.Core.World.Anker;


public static class RestoreVitals
{
Expand Down Expand Up @@ -133,7 +133,7 @@ public static void UpdateRooms()
x =>
x.areaId == corpse.Recall.AreaId && x.area == corpse.Recall.Area &&
x.region == corpse.Recall.Region);
var originalArea = World.Areas.ListOfRooms().FirstOrDefault(x =>
var originalArea = Startup.ReturnRooms.FirstOrDefault(x =>
x.area == mobRoomOrigin.area && x.areaId == mobRoomOrigin.areaId &&
x.region == mobRoomOrigin.region);

Expand Down Expand Up @@ -214,45 +214,45 @@ public static void UpdateRooms()

#region add Items back

for (int j = World.Areas.ListOfRooms().Count - 1; j >= 0; j--)
for (int j = Startup.ReturnRooms.Count - 1; j >= 0; j--)
{
if (World.Areas.ListOfRooms()[j].area == room.area &&
World.Areas.ListOfRooms()[j].areaId == room.areaId &&
World.Areas.ListOfRooms()[j].region == room.region)
if (Startup.ReturnRooms[j].area == room.area &&
Startup.ReturnRooms[j].areaId == room.areaId &&
Startup.ReturnRooms[j].region == room.region)
{

for (int k = World.Areas.ListOfRooms()[j].items.Count - 1; k >= 0; k--)
for (int k = Startup.ReturnRooms[j].items.Count - 1; k >= 0; k--)
{
var itemAlreadyThere =
room.items.Find(x => x.name.Equals(World.Areas.ListOfRooms()[j].items[k].name));
room.items.Find(x => x.name.Equals(Startup.ReturnRooms[j].items[k].name));

if (itemAlreadyThere == null)
{
room.items.Add(World.Areas.ListOfRooms()[j].items[k]);
room.items.Add(Startup.ReturnRooms[j].items[k]);
}

if (room.items.Count(x => x.name.Equals(World.Areas.ListOfRooms()[j].items[k].name)) < World.Areas.ListOfRooms()[j].items.Count(x => x.name.Equals(World.Areas.ListOfRooms()[j].items[k].name)))
if (room.items.Count(x => x.name.Equals(Startup.ReturnRooms[j].items[k].name)) < Startup.ReturnRooms[j].items.Count(x => x.name.Equals(Startup.ReturnRooms[j].items[k].name)))
{
room.items.Add(World.Areas.ListOfRooms()[j].items[k]);
room.items.Add(Startup.ReturnRooms[j].items[k]);
}

if (itemAlreadyThere?.container == true)
{


for (int l = World.Areas.ListOfRooms()[j].items[k].containerItems.Count - 1; l >= 0; l--)
for (int l = Startup.ReturnRooms[j].items[k].containerItems.Count - 1; l >= 0; l--)
{

var containerItemAlreadyThere =
itemAlreadyThere.containerItems.Find(
x =>
x.name.Equals(
World.Areas.ListOfRooms()[j].items[k].containerItems[l].name));
Startup.ReturnRooms[j].items[k].containerItems[l].name));

if (containerItemAlreadyThere == null)
{
itemAlreadyThere.containerItems.Add(
World.Areas.ListOfRooms()[j].items[k].containerItems[l]);
Startup.ReturnRooms[j].items[k].containerItems[l]);
}

}
Expand Down
2 changes: 1 addition & 1 deletion MIMWebClient/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected void Application_Start()
UpdateWorld.UpdateMob();
PlayerName.GenerateHumanNames();

foreach (var area in Areas.ListOfRooms())
foreach (var area in Startup.ReturnRooms)
{

var room = new Tuple<string, string, int>(area.region, area.area, area.areaId);
Expand Down
25 changes: 24 additions & 1 deletion MIMWebClient/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
using Owin;
using System;
using System.Collections.Generic;
using Owin;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using MIMWebClient.Core;
using MIMWebClient.Core.Room;
using MIMWebClient.Core.World;

[assembly: OwinStartup("MIMWebClientConfig", typeof(MIMWebClient.Startup))]

namespace MIMWebClient
{
public class Startup
{

private static List<Room> _listOfRooms;
private static Dictionary<string, Action> _commands;

public static List<Room> ReturnRooms
{
get
{
if (_listOfRooms == null)
{
_listOfRooms = Areas.ListOfRooms();
}

return _listOfRooms;
}
}


public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
Expand Down
87 changes: 45 additions & 42 deletions MIMWebClient/Web.config
Original file line number Diff line number Diff line change
@@ -1,88 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
--><configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<appSettings>
<add key="database" value="MyData.db" />
<add key="owin:appStartup" value="MIMWebClientConfig" />
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="owin:AutomaticAppStartup" value="true" />
</appSettings>
<add key="database" value="MyData.db"/>
<add key="owin:appStartup" value="MIMWebClientConfig"/>
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
<add key="owin:AutomaticAppStartup" value="true"/>

<add key="Microsoft.VisualStudio.Enterprise.AspNetHelper.VsInstrLocation" value="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools\vsinstr.exe"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<compilation debug="true" targetFramework="4.5.2" assemblyPostProcessorType="Microsoft.VisualStudio.Enterprise.Common.AspPerformanceInstrumenter, Microsoft.VisualStudio.Enterprise.AspNetHelper, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<httpRuntime targetFramework="4.5.2"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
</dependentAssembly>
</assemblyBinding>

<dependentAssembly>
<assemblyIdentity name="Microsoft.VisualStudio.Enterprise.AspNetHelper" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<codeBase version="14.0.0.0" href="file:///C:/Program%20Files%20(x86)/Microsoft%20Visual%20Studio%2014.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.AspNetHelper.DLL"/></dependentAssembly></assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler"/>
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<remove name="OPTIONSVerbHandler"/>
<remove name="TRACEVerbHandler"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
<parameter value="mssqllocaldb"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
Loading

0 comments on commit 6c46f57

Please sign in to comment.