2024-08-04 15:20:11 -05:00
globalThis . gamestate = { } ;
2024-07-25 17:53:53 -05:00
global . check _registers = function ( obj ) {
for ( var reg in Register . registries ) {
2024-09-26 11:36:09 -05:00
if ( typeof obj [ reg ] === "function" ) {
2024-07-25 17:53:53 -05:00
var fn = obj [ reg ] . bind ( obj ) ;
2024-09-13 10:27:01 -05:00
fn . layer = obj [ reg ] . layer ;
2024-07-25 17:53:53 -05:00
var name = obj . ur ? obj . ur . name : obj . toString ( ) ;
obj . timers . push ( Register . registries [ reg ] . register ( fn , name ) ) ;
}
}
2024-09-26 11:36:09 -05:00
2024-07-25 17:53:53 -05:00
for ( var k in obj ) {
if ( ! k . startsWith ( "on_" ) ) continue ;
var signal = k . fromfirst ( "on_" ) ;
Event . observe ( signal , obj , obj [ k ] ) ;
}
} ;
global . obscure ( "global" ) ;
global . mixin ( "scripts/render" ) ;
global . mixin ( "scripts/debug" ) ;
2024-08-08 13:25:47 -05:00
global . mixin ( "scripts/repl" ) ;
2024-07-25 17:53:53 -05:00
var frame _t = profile . secs ( profile . now ( ) ) ;
var sim = { } ;
sim . mode = "play" ;
sim . play = function ( ) {
this . mode = "play" ;
os . reindex _static ( ) ;
2024-08-29 16:55:01 -05:00
game . all _objects ( o => {
if ( ! o . _started ) {
o . _started = true ;
o . start ? . ( ) ;
}
} ) ;
2024-07-25 17:53:53 -05:00
} ;
sim . playing = function ( ) {
return this . mode === "play" ;
} ;
sim . pause = function ( ) {
this . mode = "pause" ;
} ;
sim . paused = function ( ) {
return this . mode === "pause" ;
} ;
sim . step = function ( ) {
this . mode = "step" ;
} ;
sim . stepping = function ( ) {
return this . mode === "step" ;
} ;
var physlag = 0 ;
var gggstart = game . engine _start ;
game . engine _start = function ( s ) {
game . startengine = 1 ;
gggstart (
function ( ) {
global . mixin ( "scripts/sound.js" ) ;
world _start ( ) ;
2024-10-05 08:43:51 -05:00
window . set _icon ( game . texture ( "moon" ) . texture ) ;
2024-07-25 17:53:53 -05:00
Object . readonly ( window . _ _proto _ _ , "vsync" ) ;
Object . readonly ( window . _ _proto _ _ , "enable_dragndrop" ) ;
Object . readonly ( window . _ _proto _ _ , "enable_clipboard" ) ;
Object . readonly ( window . _ _proto _ _ , "high_dpi" ) ;
Object . readonly ( window . _ _proto _ _ , "sample_count" ) ;
2024-08-22 13:31:00 -05:00
prosperon . camera = prosperon . make _camera ( ) ;
var camera = prosperon . camera ;
2024-09-26 11:36:09 -05:00
camera . transform . pos = [ 0 , 0 , - 100 ] ;
2024-08-22 13:31:00 -05:00
camera . mode = "keep" ;
camera . break = "fit" ;
camera . size = game . size ;
gamestate . camera = camera ;
2024-09-01 13:59:34 -05:00
globalThis . imgui = render . imgui _init ( ) ;
2024-09-26 11:36:09 -05:00
2024-07-25 17:53:53 -05:00
s ( ) ;
shape . quad = {
2024-10-03 09:31:06 -05:00
pos : os . make _buffer ( [
0 , 0 , 0 ,
0 , 1 , 0 ,
1 , 0 , 0 ,
1 , 1 , 0 ] , 0 ) ,
2024-07-25 17:53:53 -05:00
verts : 4 ,
2024-10-03 17:36:29 -05:00
uv : os . make _buffer ( [
0 , 1 ,
2024-10-18 12:51:21 -05:00
0 , 0 ,
1 , 1 ,
1 , 0 ] , 2 ) ,
2024-10-03 17:36:29 -05:00
index : os . make _buffer ( [ 0 , 1 , 2 , 2 , 1 , 3 ] , 1 ) ,
count : 6 ,
} ;
2024-07-25 17:53:53 -05:00
shape . triangle = {
pos : os . make _buffer ( [ 0 , 0 , 0 , 0.5 , 1 , 0 , 1 , 0 , 0 ] , 0 ) ,
uv : os . make _buffer ( [ 0 , 0 , 0.5 , 1 , 1 , 0 ] , 2 ) ,
verts : 3 ,
count : 3 ,
2024-10-03 09:31:06 -05:00
index : os . make _buffer ( [ 0 , 1 , 2 ] , 1 ) ,
2024-07-25 17:53:53 -05:00
} ;
2024-09-26 11:36:09 -05:00
2024-07-25 17:53:53 -05:00
shape . centered _quad = {
2024-10-03 09:31:06 -05:00
pos : os . make _buffer ( [
- 0.5 , - 0.5 , - 0.5 ,
- 0.5 , 0.5 , - 0.5 ,
0.5 , - 0.5 , - 0.5 ,
0.5 , 0.5 , - 0.5 ] , 0 ) ,
2024-07-25 17:53:53 -05:00
verts : 4 ,
2024-10-03 17:36:29 -05:00
uv : os . make _buffer ( [
0 , 1 ,
2024-10-18 12:51:21 -05:00
0 , 0 ,
1 , 1 ,
1 , 0 ] , 2 ) ,
2024-09-26 11:36:09 -05:00
index : os . make _buffer ( [ 0 , 1 , 2 , 2 , 1 , 3 ] , 1 ) ,
count : 6 ,
2024-07-25 17:53:53 -05:00
} ;
render . init ( ) ;
} ,
prosperon . process ,
window . size . x ,
window . size . y ,
) ;
} ;
game . startengine = 0 ;
2024-09-26 11:36:09 -05:00
prosperon . release _mode = function ( ) {
2024-07-25 17:53:53 -05:00
prosperon . debug = false ;
debug . kill ( ) ;
2024-09-26 11:36:09 -05:00
} ;
2024-07-25 17:53:53 -05:00
prosperon . debug = true ;
game . timescale = 1 ;
var eachobj = function ( obj , fn ) {
var val = fn ( obj ) ;
if ( val ) return val ;
for ( var o in obj . objects ) {
2024-09-26 11:36:09 -05:00
if ( obj . objects [ o ] === obj ) console . error ( ` Object ${ obj . toString ( ) } is referenced by itself. ` ) ;
2024-07-25 17:53:53 -05:00
val = eachobj ( obj . objects [ o ] , fn ) ;
if ( val ) return val ;
}
} ;
game . all _objects = function ( fn , startobj = world ) {
return eachobj ( startobj , fn ) ;
} ;
game . find _object = function ( fn , startobj = world ) { } ;
game . tags = { } ;
game . tag _add = function ( tag , obj ) {
game . tags [ tag ] ? ? = { } ;
game . tags [ tag ] [ obj . guid ] = obj ;
} ;
game . tag _rm = function ( tag , obj ) {
delete game . tags [ tag ] [ obj . guid ] ;
} ;
game . tag _clear _guid = function ( guid ) {
for ( var tag in game . tags ) delete game . tags [ tag ] [ guid ] ;
} ;
game . objects _with _tag = function ( tag ) {
if ( ! game . tags [ tag ] ) return [ ] ;
return Object . values ( game . tags [ tag ] ) ;
} ;
game . doc = { } ;
game . doc . object = "Returns the entity belonging to a given id." ;
game . doc . pause = "Pause game simulation." ;
game . doc . play = "Resume or start game simulation." ;
game . doc . camera = "Current camera." ;
2024-09-26 11:36:09 -05:00
game . tex _hotreload = function ( ) {
2024-08-12 15:19:34 -05:00
for ( var path in game . texture . cache ) {
if ( io . mod ( path ) > game . texture . time _cache [ path ] ) {
var tex = game . texture . cache [ path ] ;
game . texture . time _cache [ path ] = io . mod ( path ) ;
2024-10-02 09:55:32 -05:00
SpriteAnim . hotreload ( path ) ;
2024-08-12 15:19:34 -05:00
os . texture _swap ( path , game . texture . cache [ path ] ) ;
2024-08-22 14:41:01 -05:00
for ( var sprite of Object . values ( allsprites ) ) {
if ( sprite . texture == tex ) {
2024-09-26 11:36:09 -05:00
sprite . tex _sync ( ) ;
}
2024-08-22 14:41:01 -05:00
}
2024-08-12 15:19:34 -05:00
}
}
2024-09-26 11:36:09 -05:00
} ;
2024-07-25 17:53:53 -05:00
2024-10-05 08:43:51 -05:00
var image = { } ;
image . dimensions = function ( )
{
return [ this . texture . width , this . texture . height ] . scale ( [ this . rect [ 2 ] , this . rect [ 3 ] ] ) ;
}
texture _proto . copy = function ( src , pos , rect )
{
var pixel _rect = {
2024-10-17 22:59:59 -05:00
x : rect . x * src . width ,
y : rect . y * src . height ,
width : rect . width * src . width ,
height : rect . height * src . height
2024-10-05 08:43:51 -05:00
} ;
this . blit ( src , {
x : pos [ 0 ] ,
y : pos [ 1 ] ,
2024-10-17 22:59:59 -05:00
width : rect . width * src . width ,
height : rect . height * src . height
2024-10-05 08:43:51 -05:00
} , pixel _rect , false ) ;
}
var spritesheet ;
var sheet _frames = [ ] ;
var sheetsize = 1024 ;
function pack _into _sheet ( images )
{
2024-10-19 05:34:08 -05:00
return ;
2024-10-05 08:43:51 -05:00
if ( ! Array . isArray ( images ) ) images = [ images ] ;
2024-10-17 22:59:59 -05:00
if ( images [ 0 ] . texture . width > 300 && images [ 0 ] . texture . height > 300 ) return ;
2024-10-05 08:43:51 -05:00
sheet _frames = sheet _frames . concat ( images ) ;
2024-10-17 22:59:59 -05:00
var sizes = sheet _frames . map ( x => [ x . rect . width * x . texture . width , x . rect . height * x . texture . height ] ) ;
2024-10-05 08:43:51 -05:00
var pos = os . rectpack ( sheetsize , sheetsize , sizes ) ;
if ( ! pos ) {
console . error ( ` did not make spritesheet properly from images ${ images } ` ) ;
console . info ( sizes ) ;
return ;
}
var newsheet = os . make _tex _data ( sheetsize , sheetsize ) ;
for ( var i = 0 ; i < pos . length ; i ++ ) {
// Copy the texture to the new sheet
newsheet . copy ( sheet _frames [ i ] . texture , pos [ i ] , sheet _frames [ i ] . rect ) ;
// Update the frame's rect to the new position in normalized coordinates
2024-10-17 22:59:59 -05:00
sheet _frames [ i ] . rect . x = pos [ i ] [ 0 ] / newsheet . width ;
sheet _frames [ i ] . rect . y = pos [ i ] [ 1 ] / newsheet . height ;
sheet _frames [ i ] . rect . width = sizes [ i ] [ 0 ] / newsheet . width ;
sheet _frames [ i ] . rect . height = sizes [ i ] [ 1 ] / newsheet . height ;
2024-10-05 08:43:51 -05:00
sheet _frames [ i ] . texture = newsheet ;
}
newsheet . load _gpu ( ) ;
spritesheet = newsheet ;
return spritesheet ;
}
2024-10-19 05:34:08 -05:00
// The game texture cache is a cache of all images that have been loaded. It looks like this ...
// Any request to it returns an image, which is a texture and rect. But they can
2024-08-12 15:19:34 -05:00
game . texture = function ( path ) {
2024-09-29 06:10:42 -05:00
if ( ! path ) return game . texture ( "icons/no_tex.gif" ) ;
2024-10-18 12:51:21 -05:00
var parts = path . split ( ':' ) ;
path = Resources . find _image ( parts [ 0 ] ) ;
2024-09-26 11:36:09 -05:00
2024-07-25 17:53:53 -05:00
if ( ! io . exists ( path ) ) {
2024-08-27 13:57:38 -05:00
console . error ( ` Missing texture: ${ path } ` ) ;
2024-07-25 17:53:53 -05:00
game . texture . cache [ path ] = game . texture ( "icons/no_tex.gif" ) ;
2024-08-12 15:19:34 -05:00
game . texture . time _cache [ path ] = io . mod ( path ) ;
return game . texture . cache [ path ] ;
}
2024-10-19 05:34:08 -05:00
2024-10-18 12:51:21 -05:00
var frame ;
var anim _str ;
if ( parts . length > 1 ) {
// it's an animation
parts = parts [ 1 ] . split ( '_' ) ; // For a gif, it might be 'water.gif:3', but for an ase it might be 'water.ase:run_3', meaning the third frame of the 'run' animation
if ( parts . length === 1 )
frame = Number ( parts [ 0 ] ) ;
else {
anim _str = parts [ 0 ] ;
frame = Number ( parts [ 1 ] ) ;
}
} else
parts = undefined ;
2024-10-19 05:34:08 -05:00
var ret ;
if ( ret = game . texture . cache [ path ] ) {
if ( ret . texture ) return ret ;
if ( ! parts ) return ret ;
2024-10-18 12:51:21 -05:00
2024-10-19 05:34:08 -05:00
return ret [ anim _str ] . frames [ frame ] ;
}
var ext = path . ext ( ) ;
if ( ext === 'ase' || ext === 'aseprite' ) {
anim = os . make _aseprite ( path ) ;
if ( ! anim ) return ;
// load all into gpu
for ( var a in anim )
for ( let frame of anim [ a ] . frames )
frame . texture . load _gpu ( ) ;
game . texture . cache [ path ] = anim ;
ret = game . texture . cache [ path ] ;
if ( ! parts ) return ret ;
return ret [ anim _str ] . frames [ frame ] ;
}
if ( ext === 'gif' ) {
console . info ( path ) ;
anim = os . make _gif ( path ) ;
if ( ! anim ) return ;
if ( anim . frames . length === 1 ) {
anim . texture = anim . frames [ 0 ] . texture ;
anim . rect = anim . frames [ 0 ] . rect ;
}
game . texture . cache [ path ] = anim ;
console . info ( "LOADING INTO GPU" ) ;
anim . frames [ 0 ] . texture . load _gpu ( ) ;
console . info ( json . encode ( anim ) ) ;
return anim ;
}
var tex = os . make _texture ( path ) ;
2024-10-18 12:51:21 -05:00
if ( ! tex ) return ;
2024-10-05 08:43:51 -05:00
2024-10-18 12:51:21 -05:00
var image ;
var ext = path . ext ( ) ;
var anim ;
2024-10-19 05:34:08 -05:00
2024-10-05 08:43:51 -05:00
if ( ! anim ) {
image = {
texture : tex ,
2024-10-17 22:59:59 -05:00
rect : { x : 0 , y : 0 , width : 1 , height : 1 }
2024-10-05 08:43:51 -05:00
} ;
if ( pack _into _sheet ( [ image ] ) )
tex = spritesheet ;
} else if ( Object . keys ( anim ) . length === 1 ) {
image = Object . values ( anim ) [ 0 ] . frames ;
image . forEach ( x => x . texture = tex ) ;
if ( pack _into _sheet ( image ) )
tex = spritesheet ;
} else {
image = { } ;
var packs = [ ] ;
for ( var a in anim ) {
image [ a ] = anim [ a ] . frames . slice ( ) ;
image [ a ] . forEach ( x => x . texture = tex ) ;
packs = packs . concat ( image [ a ] ) ;
}
if ( pack _into _sheet ( packs ) )
tex = spritesheet ;
}
2024-10-19 05:34:08 -05:00
game . texture . cache [ path ] = image ;
2024-08-12 15:19:34 -05:00
game . texture . time _cache [ path ] = io . mod ( path ) ;
2024-10-05 08:43:51 -05:00
tex . load _gpu ( ) ;
2024-10-19 05:34:08 -05:00
return game . texture . cache [ path ] ;
2024-07-25 17:53:53 -05:00
} ;
game . texture . cache = { } ;
2024-08-12 15:19:34 -05:00
game . texture . time _cache = { } ;
2024-07-25 17:53:53 -05:00
2024-09-29 06:10:42 -05:00
game . texture . total _size = function ( )
{
var size = 0 ;
2024-10-05 08:43:51 -05:00
// Object.values(game.texture.cache).forEach(x => size += x.texture.inram() ? x..texture.width*x.texture.height*4 : 0);
2024-09-29 06:10:42 -05:00
return size ;
}
game . texture . total _vram = function ( )
{
var vram = 0 ;
2024-10-05 08:43:51 -05:00
// Object.values(game.texture.cache).forEach(x => vram += x.vram);
2024-09-29 06:10:42 -05:00
return vram ;
}
2024-07-25 17:53:53 -05:00
prosperon . semver = { } ;
prosperon . semver . valid = function ( v , range ) {
v = v . split ( "." ) ;
range = range . split ( "." ) ;
if ( v . length !== 3 ) return undefined ;
if ( range . length !== 3 ) return undefined ;
if ( range [ 0 ] [ 0 ] === "^" ) {
range [ 0 ] = range [ 0 ] . slice ( 1 ) ;
if ( parseInt ( v [ 0 ] ) >= parseInt ( range [ 0 ] ) ) return true ;
return false ;
}
if ( range [ 0 ] === "~" ) {
range [ 0 ] = range [ 0 ] . slice ( 1 ) ;
2024-09-26 11:36:09 -05:00
for ( var i = 0 ; i < 2 ; i ++ ) if ( parseInt ( v [ i ] ) < parseInt ( range [ i ] ) ) return false ;
2024-07-25 17:53:53 -05:00
return true ;
}
return prosperon . semver . cmp ( v . join ( "." ) , range . join ( "." ) ) === 0 ;
} ;
prosperon . semver . cmp = function ( v1 , v2 ) {
var ver1 = v1 . split ( "." ) ;
var ver2 = v2 . split ( "." ) ;
for ( var i = 0 ; i < 3 ; i ++ ) {
var n1 = parseInt ( ver1 [ i ] ) ;
var n2 = parseInt ( ver2 [ i ] ) ;
if ( n1 > n2 ) return 1 ;
else if ( n1 < n2 ) return - 1 ;
}
return 0 ;
} ;
2024-09-26 11:36:09 -05:00
prosperon . semver . cmp . doc = "Compare two semantic version numbers, given like X.X.X." ;
2024-07-25 17:53:53 -05:00
prosperon . semver . valid . doc = ` Test if semantic version v is valid, given a range.
Range is given by a semantic versioning number , prefixed with nothing , a ~ , or a ^ .
~ means that MAJOR and MINOR must match exactly , but any PATCH greater or equal is valid .
^ means that MAJOR must match exactly , but any MINOR and PATCH greater or equal is valid . ` ;
prosperon . iconified = function ( icon ) { } ;
prosperon . focus = function ( focus ) { } ;
prosperon . resize = function ( dimensions ) {
window . size . x = dimensions . x ;
window . size . y = dimensions . y ;
} ;
prosperon . suspended = function ( sus ) { } ;
prosperon . mouseenter = function ( ) { } ;
prosperon . mouseleave = function ( ) { } ;
prosperon . touchpress = function ( touches ) { } ;
prosperon . touchrelease = function ( touches ) { } ;
prosperon . touchmove = function ( touches ) { } ;
prosperon . clipboardpaste = function ( str ) { } ;
prosperon . quit = function ( ) {
2024-08-25 00:18:30 -05:00
prosperon . quit _hook ? . ( ) ;
2024-07-25 17:53:53 -05:00
} ;
window . size = [ 640 , 480 ] ;
window . mode = "keep" ;
2024-09-26 11:36:09 -05:00
window . toggle _fullscreen = function ( ) {
window . fullscreen = ! window . fullscreen ;
} ;
2024-07-25 17:53:53 -05:00
window . set _icon . doc = "Set the icon of the window using the PNG image at path." ;
window . doc = { } ;
window . doc . dimensions = "Window width and height packaged in an array [width,height]" ;
window . doc . title = "Name in the title bar of the window." ;
window . doc . boundingbox = "Boundingbox of the window, with top and right being its height and width." ;
2024-09-26 11:36:09 -05:00
window . _ _proto _ _ . toJSON = function ( ) {
2024-08-25 06:35:04 -05:00
return {
size : this . size ,
fullscreen : this . fullscreen ,
2024-09-26 11:36:09 -05:00
title : this . title ,
} ;
} ;
2024-07-25 17:53:53 -05:00
global . mixin ( "scripts/input" ) ;
global . mixin ( "scripts/std" ) ;
global . mixin ( "scripts/diff" ) ;
global . mixin ( "scripts/color" ) ;
global . mixin ( "scripts/tween" ) ;
global . mixin ( "scripts/ai" ) ;
global . mixin ( "scripts/particle" ) ;
global . mixin ( "scripts/physics" ) ;
2024-09-26 11:36:09 -05:00
global . mixin ( "scripts/geometry" ) ;
2024-10-17 17:25:03 -05:00
global . mixin ( "scripts/layout" ) ;
2024-07-25 17:53:53 -05:00
/ *
Factory for creating registries . Register one with 'X.register' ,
which returns a function that , when invoked , cancels the registry .
* /
var Register = {
registries : [ ] ,
2024-09-13 10:27:01 -05:00
add _cb ( name , e _event = false , flush = undefined ) {
2024-07-25 17:53:53 -05:00
var n = { } ;
2024-09-13 10:27:01 -05:00
var fns = [ ] ;
2024-07-25 17:53:53 -05:00
n . register = function ( fn , oname ) {
if ( ! ( fn instanceof Function ) ) return ;
2024-09-26 11:36:09 -05:00
2024-08-02 20:52:50 -05:00
var guid = prosperon . guid ( ) ;
2024-07-25 17:53:53 -05:00
2024-09-26 11:36:09 -05:00
var dofn = function ( ... args ) {
2024-10-02 09:55:32 -05:00
profile . report ( ` call_ ${ name } _ ${ oname } ` ) ;
2024-07-25 17:53:53 -05:00
var st = profile . now ( ) ;
fn ( ... args ) ;
2024-10-02 09:55:32 -05:00
profile . endreport ( ` call_ ${ name } _ ${ oname } ` ) ;
2024-09-26 11:36:09 -05:00
} ;
2024-09-13 10:27:01 -05:00
2024-09-26 23:12:30 -05:00
var left = 0 ;
var right = fns . length - 1 ;
2024-09-13 10:27:01 -05:00
dofn . layer = fn . layer ;
dofn . layer ? ? = 0 ;
2024-09-26 23:12:30 -05:00
while ( left <= right ) {
var mid = Math . floor ( ( left + right ) / 2 ) ;
if ( fns [ mid ] === dofn . layer ) {
left = mid ;
break ;
} else if ( fns [ mid ] . layer < dofn . layer ) left = mid + 1 ;
else right = mid - 1 ;
}
fns . splice ( left , 0 , dofn ) ;
2024-09-26 11:36:09 -05:00
2024-07-25 17:53:53 -05:00
return function ( ) {
2024-09-13 10:27:01 -05:00
fns . remove ( dofn ) ;
2024-07-25 17:53:53 -05:00
} ;
} ;
2024-09-13 10:27:01 -05:00
if ( ! flush ) {
2024-09-26 11:36:09 -05:00
prosperon [ name ] = function ( ... args ) {
2024-10-17 17:23:33 -05:00
profile . report ( name ) ;
2024-09-13 10:27:01 -05:00
fns . forEach ( fn => fn ( ... args ) ) ;
2024-10-17 17:23:33 -05:00
profile . endreport ( name ) ;
2024-09-26 11:36:09 -05:00
} ;
} else
prosperon [ name ] = function ( ... args ) {
2024-10-17 17:23:33 -05:00
profile . report ( name ) ;
2024-09-13 10:27:01 -05:00
var layer = undefined ;
for ( var fn of fns ) {
2024-09-26 11:36:09 -05:00
if ( layer !== fn . layer ) {
flush ( ) ;
layer = fn . layer ;
}
fn ( ) ;
2024-09-13 10:27:01 -05:00
}
2024-10-17 17:23:33 -05:00
profile . endreport ( name ) ;
2024-09-26 11:36:09 -05:00
} ;
2024-07-25 17:53:53 -05:00
prosperon [ name ] . fns = fns ;
n . clear = function ( ) {
fns = [ ] ;
} ;
Register [ name ] = n ;
Register . registries [ name ] = n ;
return n ;
} ,
} ;
Register . add _cb ( "appupdate" , true ) ;
Register . add _cb ( "update" , true ) . doc = "Called once per frame." ;
Register . add _cb ( "physupdate" , true ) ;
Register . add _cb ( "gui" , true ) ;
2024-09-13 10:27:01 -05:00
Register . add _cb ( "hud" , true , render . flush ) ;
2024-10-06 17:18:18 -05:00
Register . add _cb ( "draw" , true , render . flush ) ;
Register . add _cb ( "imgui" , true , render . flush ) ;
2024-10-17 17:23:33 -05:00
Register . add _cb ( "app" , true , render . flush ) ;
2024-07-25 17:53:53 -05:00
var Event = {
events : { } ,
observe ( name , obj , fn ) {
this . events [ name ] ? ? = [ ] ;
this . events [ name ] . push ( [ obj , fn ] ) ;
} ,
unobserve ( name , obj ) {
2024-09-26 11:36:09 -05:00
this . events [ name ] = this . events [ name ] . filter ( x => x [ 0 ] !== obj ) ;
2024-07-25 17:53:53 -05:00
} ,
rm _obj ( obj ) {
2024-09-26 11:36:09 -05:00
Object . keys ( this . events ) . forEach ( name => Event . unobserve ( name , obj ) ) ;
2024-07-25 17:53:53 -05:00
} ,
notify ( name , ... args ) {
if ( ! this . events [ name ] ) return ;
this . events [ name ] . forEach ( function ( x ) {
x [ 1 ] . call ( x [ 0 ] , ... args ) ;
} ) ;
} ,
} ;
2024-09-30 10:14:56 -05:00
prosperon . add _timer = function ( obj , fn , seconds )
{
var timers = obj . timers ;
var stop = function ( ) {
timers . remove ( stop ) ;
timer . fn = undefined ;
timer = undefined ;
} ;
function execute ( ) {
if ( fn )
timer . remain = fn ( stop . seconds ) ;
if ( ! timer . remain )
stop ( ) ;
else
stop . seconds = timer . remain ;
}
var timer = os . make _timer ( execute ) ;
timer . remain = seconds ;
stop . remain = seconds ;
stop . seconds = seconds ;
timers . push ( stop ) ;
return stop ;
}
2024-07-25 17:53:53 -05:00
global . mixin ( "scripts/spline" ) ;
global . mixin ( "scripts/components" ) ;
global . mixin ( "scripts/actor" ) ;
global . mixin ( "scripts/entity" ) ;
function world _start ( ) {
globalThis . world = Object . create ( entity ) ;
world . transform = os . make _transform ( ) ;
world . objects = { } ;
world . toString = function ( ) {
return "world" ;
} ;
world . ur = "world" ;
world . kill = function ( ) {
this . clear ( ) ;
} ;
world . phys = 2 ;
world . zoom = 1 ;
world . _ed = { selectable : false } ;
world . ur = { } ;
world . ur . fresh = { } ;
game . cam = world ;
}
global . mixin ( "scripts/physics" ) ;
2024-10-17 17:25:03 -05:00
2024-07-25 17:53:53 -05:00
window . title = ` Prosperon v ${ prosperon . version } ` ;
window . size = [ 500 , 500 ] ;
return {
Register ,
sim ,
frame _t ,
physlag ,
2024-09-26 11:36:09 -05:00
Event ,
} ;