Skip to content

Commit

Permalink
Fix game and addon mounting (now file.Find works for them) + add Game…
Browse files Browse the repository at this point in the history
…Events and Sounds bindings+ additions to Predictions, enumerations,
  • Loading branch information
luttje committed Aug 18, 2024
1 parent 1cda9df commit 688ed3d
Show file tree
Hide file tree
Showing 40 changed files with 1,071 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tags:
- needs-verification
- needs-example
lua:
library: PhysicsSurfacePropertiesHandle
library: PhysicsSurfaceProperties
function: ParseSurfaceData
realm: shared
description: "Parses surface data"
Expand All @@ -20,5 +20,5 @@ lua:
---

<div class="lua__search__keywords">
PhysicsSurfacePropertiesHandle:ParseSurfaceData &#x2013; Parses surface data
PhysicsSurfaceProperties:ParseSurfaceData &#x2013; Parses surface data
</div>
1 change: 1 addition & 0 deletions docs/general/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Additionally, we use the following conventions:
- `Vcd` (short for Valve Choreography Data) and other valve formats (e.g.
`Vmt`, `Vtf`, `Vpk`, `Mdl`, etc.)
- `Vgui`
- `Vs` for versus

- Abbreviations should be treated as words when capitalizing:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
template: lua-hook.html
title: EntityKeyValue
icon: lua-shared
icon: lua-server
tags:
- lua
- shared
- server
- needs-verification
- needs-example
lua:
function: EntityKeyValue
realm: shared
realm: server
description: ""
arguments:
- name: "this"
- name: "pNode"
description: ""
type: Entity
- name: "szKeyName"
Expand Down
42 changes: 42 additions & 0 deletions docs/hooks/shared/CalcViewModelView.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
template: lua-hook.html
title: CalcViewModelView
icon: lua-shared
tags:
- lua
- shared
- needs-verification
- needs-example
lua:
function: CalcViewModelView
realm: shared
description: "Allows overriding the view model's position and angles."
arguments:
- name: "weapon"
description: ""
type: Entity
- name: "viewModel"
description: ""
type: Entity
- name: "eyePosition"
description: ""
type: Vector
- name: "eyeAngles"
description: ""
type: Angle
- name: "vmorigin"
description: ""
type: Vector
- name: "vmangles"
description: ""
type: Angle
returns:
- type: Vector
description: "replacement origin"
- type: Angle
description: "replacement angles"
---

<div class="lua__search__keywords">
hook CalcViewModelView &#x2013; "Allows overriding the view model's position and angles."
</div>
16 changes: 8 additions & 8 deletions docs/hooks/shared/ShouldCollide.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ tags:
lua:
function: ShouldCollide
realm: shared
description: ""
description: "Called when two entities are about to collide. Return false to prevent the collision."
arguments:
- name: "collisionGroup0"
description: ""
type: number
- name: "collisionGroup1"
description: ""
type: number
- name: "entity1"
description: "The entity colliding"
type: Entity
- name: "entity2"
description: "The entity colliding with entity1"
type: Entity
returns:
- type: unknown
description: ""
---

<div class="lua__search__keywords">
hook ShouldCollide &#x2013; ""
hook ShouldCollide &#x2013; "Called when two entities are about to collide. Return false to prevent the collision."
</div>
25 changes: 25 additions & 0 deletions docs/libraries/GameEvents/Listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
template: lua-library-function.html
title: Listen
icon: lua-shared
tags:
- lua
- shared
- needs-verification
- needs-example
lua:
library: GameEvents
function: Listen
realm: shared
description: "Call a hook for this game event name, when the event occurs."

arguments:
- name: "eventName"
type: string
returns:

---

<div class="lua__search__keywords">
GameEvents.Listen &#x2013; Call a hook for this game event name, when the event occurs.
</div>
24 changes: 24 additions & 0 deletions docs/libraries/Predictions/IsFirstTimePredicted.server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
template: lua-library-function.html
title: IsFirstTimePredicted
icon: lua-server
tags:
- lua
- server
- needs-verification
- needs-example
lua:
library: Predictions
function: IsFirstTimePredicted
realm: server
description: "Always returns true on the server. TODO: what should it do?"


returns:
- type: boolean
description: "Always true on the server."
---

<div class="lua__search__keywords">
Predictions.IsFirstTimePredicted &#x2013; Always returns true on the server. TODO: what should it do?
</div>
25 changes: 25 additions & 0 deletions docs/libraries/Sounds/Add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
template: lua-library-function.html
title: Add
icon: lua-shared
tags:
- lua
- shared
- needs-verification
- needs-example
lua:
library: Sounds
function: Add
realm: shared
description: "Creates a sound script."

arguments:
- name: "soundData"
type: table
returns:

---

<div class="lua__search__keywords">
Sounds.Add &#x2013; Creates a sound script.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ local enumsToMergeWithKey = {
MOVE_TYPE = "MOVETYPE",
OBSERVER_MODE = "OBS_MODE",
SOLID = "SOLID",
SOUND_CHANNEL = "CHAN",
SURFACE = "SURF",

DAMAGE_TYPE = {"DMG", stripUnderscores},
HIT_GROUP = {"HITGROUP", stripUnderscores},
MATERIAL_TYPE = {"MAT", stripUnderscores},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ system = Systems
vgui = Panels
VMatrix = Matrix
concommand = ConsoleCommands
physenv = PhysicsEnvironments
gameevent = GameEvents
sound = Sounds

Angle = Angles.Create
Color = Colors.Create
Expand Down Expand Up @@ -199,6 +202,7 @@ GetHostName = Engines.GetServerName

PrecacheParticleSystem = ParticleSystems.Precache
GetPredictionPlayer = Predictions.GetPredictionPlayer
IsFirstTimePredicted = Predictions.IsFirstTimePredicted
LerpVector = Vectors.Lerp

RecipientFilter = RecipientFilters.Create
Expand Down Expand Up @@ -295,6 +299,13 @@ for _, languageFile in ipairs(languageFiles) do
end
end

function physenv.AddSurfaceData(surfaceDataKeyValuesString)
-- ParseSurfaceData expects a unique file name, so we generate one
local fakeFileName = "physenv.AddSurfaceData" .. tostring(os.time()) .. ".txt"

return PhysicsSurfaceProperties.ParseSurfaceData(fakeFileName, surfaceDataKeyValuesString)
end

umsg = require("UserMessages")
umsg.Angle = umsg.WriteAngles
umsg.Bool = umsg.WriteBool
Expand Down
4 changes: 4 additions & 0 deletions game/experiment/scripts/game_sounds_manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
game_sounds_manifest
{
"precache_file" "scripts/sounds/lua_procedural.txt"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ local Networks = require("networks")
local Hooks = require("hooks")

local debugPrint = function(...)
if (not EntityNetworkedVariablesDebug) then
return
end
if (not EntityNetworkedVariablesDebug) then
return
end

local prefix = CLIENT and "Client]" or "Server]"
print("[EntityNetworking ", prefix, ...)
Expand All @@ -32,65 +32,70 @@ end
--- @param key string
--- @param value any
function ENTITY_META:SetNetworkedVariable(key, value)
if (not self.__networkedVariables) then
self.__networkedVariables = {}
end
if (not self.__networkedVariables) then
self.__networkedVariables = {}
end

self.__networkedVariables[key] = value
self.__networkedVariables[key] = value

if (not SERVER) then
-- TODO: Okay so the server should be updating the client sometimes,
if (not SERVER) then
-- TODO: Okay so the server should be updating the client sometimes,
-- otherwise clientside SetNetworkedVariables will differ from the server for too long.
return
end
return
end

debugPrint("Setting networked variable", self, key, value)

Networks.Start("EntityNetworkedVariable")
Networks.WriteEntity(self)
Networks.WriteString(key)
Networks.WriteType(value)
Networks.BroadcastPVS(self)
Networks.Start("EntityNetworkedVariable")
Networks.WriteEntity(self)
Networks.WriteString(key)
Networks.WriteType(value)
Networks.BroadcastPVS(self)
end

--- Gets a networked variable from the entity
--- @param key string
--- @param defaultValue any
--- @return any
function ENTITY_META:GetNetworkedVariable(key)
if (not self.__networkedVariables) then
return nil
end
function ENTITY_META:GetNetworkedVariable(key, defaultValue)
if (not self.__networkedVariables) then
return defaultValue
end

return self.__networkedVariables[key]
if (self.__networkedVariables[key] == nil) then
return defaultValue
end

return self.__networkedVariables[key]
end

--- Sets up a callback for when a networked variable changes
--- @param key string
--- @param callback fun(entity: Entity, key: string, oldValue: any, newValue: any)
function ENTITY_META:SetNetworkedVariableCallback(key, callback)
if (not self.__networkedVarCallbacks) then
self.__networkedVarCallbacks = {}
end
if (not self.__networkedVarCallbacks) then
self.__networkedVarCallbacks = {}
end

debugPrint("Setting networked variable callback", key)

self.__networkedVarCallbacks[key] = callback
self.__networkedVarCallbacks[key] = callback
end

--- Calls all callbacks for the provided key on the entity
--- @param key string
--- @param oldValue any
--- @param newValue any
function ENTITY_META:CallNetworkedVariableCallbacks(key, oldValue, newValue)
if (not self.__networkedVarCallbacks) then
return
end
if (not self.__networkedVarCallbacks) then
return
end

debugPrint("Calling networked variable callbacks", key)
debugPrint("Calling networked variable callbacks", key)

for _, callback in pairs(self.__networkedVarCallbacks) do
callback(self, key, oldValue, newValue)
end
for _, callback in pairs(self.__networkedVarCallbacks) do
callback(self, key, oldValue, newValue)
end
end

if (SERVER) then
Expand Down Expand Up @@ -124,15 +129,15 @@ local dataTypes = {
}

for _, dataType in ipairs(dataTypes) do
ENTITY_META["SetNetworked" .. dataType] = ENTITY_META.SetNetworkedVariable
ENTITY_META["SetNetworked2" .. dataType] = ENTITY_META.SetNetworkedVariable
ENTITY_META["SetNW" .. dataType] = ENTITY_META.SetNetworkedVariable
ENTITY_META["SetNW2" .. dataType] = ENTITY_META.SetNetworkedVariable

ENTITY_META["GetNetworked" .. dataType] = ENTITY_META.GetNetworkedVariable
ENTITY_META["GetNetworked2" .. dataType] = ENTITY_META.GetNetworkedVariable
ENTITY_META["GetNW" .. dataType] = ENTITY_META.GetNetworkedVariable
ENTITY_META["GetNW2" .. dataType] = ENTITY_META.GetNetworkedVariable
ENTITY_META["SetNetworked" .. dataType] = ENTITY_META.SetNetworkedVariable
ENTITY_META["SetNetworked2" .. dataType] = ENTITY_META.SetNetworkedVariable
ENTITY_META["SetNW" .. dataType] = ENTITY_META.SetNetworkedVariable
ENTITY_META["SetNW2" .. dataType] = ENTITY_META.SetNetworkedVariable

ENTITY_META["GetNetworked" .. dataType] = ENTITY_META.GetNetworkedVariable
ENTITY_META["GetNetworked2" .. dataType] = ENTITY_META.GetNetworkedVariable
ENTITY_META["GetNW" .. dataType] = ENTITY_META.GetNetworkedVariable
ENTITY_META["GetNW2" .. dataType] = ENTITY_META.GetNetworkedVariable
end

ENTITY_META.SetNetworkedVarProxy = ENTITY_META.SetNetworkedVariableCallback
Expand Down
Loading

0 comments on commit 688ed3d

Please sign in to comment.