Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Zip #745

Open
wants to merge 6 commits into
base: indev
Choose a base branch
from
Open

Zip #745

wants to merge 6 commits into from

Conversation

FurkanS1821
Copy link
Member

@FurkanS1821 FurkanS1821 commented Oct 1, 2018

  • .zip file support for content. (Unzipped files may overwrite what is in .zip)

No other mentionable change, except compatibility.
Requires LeagueSandbox/LeagueSandbox-Default#84 to work, because the content has been regenerated.

@@ -110,10 +115,11 @@ public void Load(string name)
HpRegenPerLevel = file.GetFloat("Data", "HPRegenPerLevel", HpRegenPerLevel);
MpRegenPerLevel = file.GetFloat("Data", "MPRegenPerLevel", MpRegenPerLevel);
AttackSpeedPerLevel = file.GetFloat("Data", "AttackSpeedPerLevel", AttackSpeedPerLevel);
IsMelee = file.GetString("Data", "IsMelee", IsMelee ? "Yes" : "No").Equals("yes");
IsMelee = file.GetString("Data", "IsMelee", IsMelee ? "Yes" : "No").ToLower().Equals("yes");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self note: make this ToLowerInvariant() just in case.

@codecov-io
Copy link

codecov-io commented Oct 3, 2018

Codecov Report

Merging #745 into indev will increase coverage by 7.27%.
The diff coverage is 50.56%.

Impacted file tree graph

@@           Coverage Diff            @@
##           indev    #745      +/-   ##
========================================
+ Coverage   1.88%   9.15%   +7.27%     
========================================
  Files        131     131              
  Lines       7798    7742      -56     
  Branches     614     616       +2     
========================================
+ Hits         147     709     +562     
+ Misses      7651    7028     -623     
- Partials       0       5       +5
Impacted Files Coverage Δ
...meServerLib/Exceptions/ContentNotFoundException.cs 0% <ø> (ø)
GameServerLib/Program.cs 0% <ø> (ø) ⬆️
GameServerLib/GameObjects/Missiles/Cone.cs 0% <0%> (ø) ⬆️
GameServerLib/Game.cs 8.28% <0%> (+8.28%) ⬆️
GameServerLib/Content/SpellData.cs 0% <0%> (ø) ⬆️
GameServerLib/GameObjects/Spells/Spell.cs 0% <0%> (ø) ⬆️
GameServerLib/GameObjects/Missiles/Projectile.cs 0% <0%> (ø) ⬆️
GameServerLib/Config.cs 0% <0%> (ø) ⬆️
GameServerLib/Content/CharData.cs 0% <0%> (ø) ⬆️
GameServerLib/GameObjects/Missiles/Laser.cs 0% <0%> (ø) ⬆️
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4055a0f...3678cdf. Read the comment docs.

Copy link
Contributor

@danil179 danil179 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some indexes instead of arrays, don't sure if it's from your PR or was already, but should be changed.

public int RecipeItem1 { get; private set; }
public int RecipeItem2 { get; private set; }
public int RecipeItem3 { get; private set; }
public int RecipeItem4 { get; private set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need only 4? maybe use array? and do RecipeItem[i] = content.GetInt("Data", "RecipeItem{i}", -1),.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, there doesn't seem to be a good reason to limit this to just 4 items. My vote also goes out to arrays (for potential custom content in the future).

itemManager.SafeGetItemType(_owner.RecipeItem1),
itemManager.SafeGetItemType(_owner.RecipeItem2),
itemManager.SafeGetItemType(_owner.RecipeItem3),
itemManager.SafeGetItemType(_owner.RecipeItem4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also use array and loop.

Copy link
Member

@molenzwiebel molenzwiebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now requesting changes because of the recipe and argument name. Do also check if LINQ can make your code cleaner though.

Other than that, what is the memory usage of loading all game data upon startup? I understand that it makes the rest easier, but isn't ZIP a random access format (meaning you should be able to just store offsets/lengths in your dictionary and read from file on demand)? I won't make you change all the stuff, but keep it in mind.

{
contents.Add(directory.Replace('\\', '/').Split('/').Last());
return path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no faster LINQ way to do this? possibilities.First or something?

GameServerLib/Content/ContentManager.cs Outdated Show resolved Hide resolved
throw new ContentNotFoundException($"Spell data for {spellName} was not found.");
if (Content.ContainsKey(path))
{
return path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

public int RecipeItem1 { get; private set; }
public int RecipeItem2 { get; private set; }
public int RecipeItem3 { get; private set; }
public int RecipeItem4 { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, there doesn't seem to be a good reason to limit this to just 4 items. My vote also goes out to arrays (for potential custom content in the future).

if (item != null)
{
_totalPrice += item.TotalPrice;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This most likely can also be a LINQ sum

_game.PacketNotifier.NotifyRemoveItem(_owner, slotId, stackSize);
_owner.RemoveSpell((byte)(slotId + ITEM_ACTIVE_OFFSET));
inventory.RemoveItem(item);
}

private bool AddItem(ItemType itemType)
private bool AddItem(ItemData ıtemData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the proper normal english i here 😋

Copy link
Member

@moonshadow565 moonshadow565 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While i went through your changes i noticed that you also changed some enums and while i'm pretty sure that those changes have nothing to do with .zip support it can be overlooked.

That being said i can't help but notice that the way you implemented this is by loading all file contents in memory as bytes while checking if .zip file is present.
I don't think this is acceptable solution even for a short term.
Aside from performance issues this will cause, it is not really clear how this interacts with multiple packages providing the same file and doesn't provide any mechanism for possible further exstensions.

It would be shame to just drop this PR because of other changes that you made to organize content loading.


private byte[] _data;

public FileEntry(string name, string fullPath, Stream stream)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still storing full content of the file into memory.
However this time you did define a class that describes an interface for a FileEntry.

You should extract this interface so that you can have multiple implementations for FileEntry(example .zip or file system).
And yes this would mean that your ContentManager would have to implement IDisposable to get rid of open .zip handles which should be trivial to implement(store them in list).

So what you should implement is FilesystemFileEntry which should be wraper for IFilerEntry around this class:
https://docs.microsoft.com/en-us/dotnet/api/system.io.fileinfo?view=netframework-4.7.2

For ZipFileEntry you can wrap this class(ZipArchiveEntry):
https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-compress-and-extract-files

Both of those provide you a way to:

  1. File name
  2. File name relative to root path of package
  3. Open or OpenRead which returns a stream

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants