-
Notifications
You must be signed in to change notification settings - Fork 10
/
holostructurelib.txt
154 lines (135 loc) · 5.64 KB
/
holostructurelib.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
@name holostructurelib
@model models/bull/gates/microcontroller1.mdl
@persist HOLOSTRUCTURE_DATA:table HOLOSTRUCTURE_QUEUE:table HOLOSTRUCTURE_SPAWNED:table
#include "betterhololib"
#[ ]#
## E2 Library: holoStructureLib ##
## ##
## Lets you easily define, create, and destroy ##
## groups of holograms called HoloStructures. ##
## ##
## Automatically included with any hologram ##
## structure generated by the VR Holo Designer. ##
#[ ]#
if( first() ){
function supressInitializationWarnings(){
HOLOSTRUCTURE_DATA = table() HOLOSTRUCTURE_QUEUE = table() HOLOSTRUCTURE_SPAWNED = table()
}
###############
##
# registerStructure( Class:string, StructureData:table )
# Registers a hologram structure with the given class.
#
# StructureData details:
# | ["models",array] -> hologram models
# | ["positions",array] -> local hologram positions
# | ["angles",array] -> local hologram angles
# | ["scales",array] -> hologram scales
# | ["colors",array] -> hologram colors
# | ["materials",array] -> hologram materials
# |
# | OPTIONAL:
# | ["spawnChild",string] -> callback function for spawning child holos; the following are passed:
# | | HoloID:number -> the actual holo id
# | | Index:number -> index of child on the template
#
# Spawn your structure class with holoStructCreate("class") !
#
function registerStructure(Class:string, StructureData:table){
HOLOSTRUCTURE_DATA[Class,table] = StructureData
}
###############
##
# holoStructCreate( Class:string, Pos:vector = entity():pos() )
# Creates a HoloStructure of the specified class and queues it for spawning.
# Returns the ID of the created HoloStructure.
#
function number holoStructCreate(Class:string,Pos:vector){
if( !HOLOSTRUCTURE_DATA:exists(Class) ){
error("Attempt to spawn unknown structure '"+Class+"'")
}
local Base = holoAlloc(Pos)
holoAlpha(Base,0)
HOLOSTRUCTURE_QUEUE[Base+"",table] = table(
"template" = HOLOSTRUCTURE_DATA[Class,table],
"progress" = 0,
"children" = array(),
"entity" = holoEntity(Base),
"id" = Base
)
return Base
}
function number holoStructCreate(Class:string){
return holoStructCreate(Class,entity():pos())
}
###############
##
# <HoloStructure>:holoStructFree( )
# Deletes a HoloStructure and all its children.
#
function number:holoStructFree(){
local ThisStr = This+""
if( HOLOSTRUCTURE_SPAWNED:exists(ThisStr) ){ # probably already spawned
local Holos = HOLOSTRUCTURE_SPAWNED[ThisStr,table]["children",array]
foreach(_:number,ID:number=Holos){
ID:holoFree()
}
HOLOSTRUCTURE_SPAWNED:remove(ThisStr)
}
elseif( HOLOSTRUCTURE_QUEUE:exists(ThisStr) ) { # check queue just in case
local Holos = HOLOSTRUCTURE_QUEUE[ThisStr,table]["children",array]
foreach(_:number,ID:number=Holos){
ID:holoFree()
}
}
}
###############
##
# <HoloStructure>:getChildren( )
# Returns an array representing the holo ids of the children of this HoloStructure
#
function array number:getChildren(){
return HOLOSTRUCTURE_SPAWNED[This+"",table]["children",array]
}
if(entity():model() == "models/bull/gates/microcontroller1.mdl"){
selfDestruct()
error("This is a library; #include it in something.")
}
}
event tick(){
foreach(_:string, SpawnStruct:table = HOLOSTRUCTURE_QUEUE){
if( !holoCanCreate() ){ break }
if( opcounter() > softQuota() ){ break }
N = SpawnStruct["id",number]
local Template = SpawnStruct["template",table]
local Models = Template["models",array]
local Positions = Template["positions",array]
local Angles = Template["angles",array]
local Scales = Template["scales",array]
local Colors = Template["colors",array]
local Materials = Template["materials",array]
local Max = Models:count()
local Progress = SpawnStruct["progress",number]
local BaseEntity = SpawnStruct["entity",entity]
while( holoCanCreate() & (Progress < Max) ){
if( opcounter() > softQuota() ){ break }
Progress++
local H = holoAlloc()
holoModel(H,Models[Progress,string])
holoPos(H,BaseEntity:toWorld(Positions[Progress,vector]))
holoAng(H,BaseEntity:toWorld(Angles[Progress,angle]))
holoScale(H,Scales[Progress,vector])
holoColor(H,Colors[Progress,vector])
holoMaterial(H,Materials[Progress,string])
holoParent(H,N)
if( Template:exists("spawnChild") ){
Template["spawnChild",string](H, Progress)
}
SpawnStruct["children",array]:pushNumber(H)
}
SpawnStruct["progress",number] = Progress
if( Progress == Max ){ # done, move it out of the queue
HOLOSTRUCTURE_SPAWNED[N+"",table] = HOLOSTRUCTURE_QUEUE:removeTable(N+"")
}
}
}