Coder Social home page Coder Social logo

gmod-nw3's Introduction

NW3 System

The NW3 System is a combination of the NW and NW2 System.
It internally uses the NW2 system for networking, but it allows one to decide if you want to use the PVS or not.
I'm going to make a version using the net library in the future.
You should not use the NW3 System if you set NW3 vars every tick. It aims to improve the performance of all GetNW3 functions at the cost of the SetNW3 functions.
The NW2 System currently collides with the NW3 System. So you can do stuff like this:

Entity(1):SetNW2String("Hello", "World")
print(Entity(1):GetNW3String("Hello")) -- will be faster than GetNW2STring because the var is cached internally.

Entity(1):SetNW3String("Hello", "World")
print(Entity(1):GetNW2String("Hello")) -- you should use GetNW3String because it is way faster.

If you experience engine crashes related to Facepunch/garrysmod-issues#3744 please open an issue here. (should hopefully never happen)

Performance

SetNW3* and SetGlobal3* Performance

They are going to be a bit slower than the equivalent NW2function. The NW3 Cache uses Internally, the hook EntityNetworkedVarChanged is used to cache every NW3 Var.

GetNW3* and GetGlobal3* Performance

2.5-4x better Performance than GetNW2* functions. (Results from test below). GetNW3Var will be the fastest function. It will return the current value from the nw2 registry(cache table.)

Performance Test

if SERVER then
	local nw3 = 0 
	local nw2 = 0
	local nw = 0
	local ent = Entity(1)
	local SysTime = SysTime
	Entity(1):SetNWInt("Test", 10000000) 
	Entity(1):SetNW2Int("Test", 10000000)
	Entity(1):SetNW3Int("Test2", 10000000)  
	for k=1, 10000000 do
		local start = SysTime()
		ent:GetNW3Int("Test", 0)
		local finish = SysTime()  
		nw3 = nw3 + (finish - start)
	end 
 
	for k=1, 10000000 do
		local start = SysTime()
		ent:GetNW2Int("Test2", 0)
		local finish = SysTime()
		nw2 = nw2 + (finish - start)
	end

	for k=1, 10000000 do
		local start = SysTime()
		ent:GetNWInt("Test", 0)
		local finish = SysTime()
		nw = nw + (finish - start)
	end

	print("NW3", nw3)
	print("NW2", nw2)
	print("NW", nw)
end

Output (executed 5 times.):

NW3	0.46445980099816
NW2	1.1991258009039
NW	1.2526921993067

NW3	0.48828999972648
NW2	1.2319813006652
NW	1.2516106997355

NW3	0.44739039998603
NW2	1.2135862994273
NW	1.2454914982427

NW3	0.43265849884483
NW2	1.2111449998883
NW	1.2444628995872

NW3	0.43737039941334
NW2	1.2225386995815
NW	1.3808498018261

Settings

DebugPrints if set to true, it will enable all debug prints.
ReplaceNW if set to true, it will, replace the NW System with the NW3 System.

All other values are used Internally and should not be changes.

Functions

It has all the NW2 functions. serverside all functions have a third argument. PVS. The PVS is disabled by default.

Example

  Entity(1):SetNW3String("Hello", "World", true) -- uses the PVS.

SetGlobal3Table(key, table) (same as Entity(0):SetNW3Table)

gmod-nw3's People

Contributors

raphaelit7 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.