Commit for 2022.06.04 23-47-01.7z
This commit is contained in:
parent
6418a76456
commit
82390c927b
12
Makefile
12
Makefile
@ -56,7 +56,7 @@ ifneq (,$(findstring win64,$(ARCH)))
|
||||
FLAGS +=
|
||||
DEPS += -lgdi32
|
||||
else ifneq (,$(findstring dreamcast,$(ARCH)))
|
||||
REQ_DEPS += simd opengl gldc json:nlohmann lua reactphysics png zlib ctti ogg openal aldc # gltf freetype bullet meshoptimizer draco luajit ultralight-ux ncurses curl openvr discord
|
||||
REQ_DEPS += simd opengl gldc json:nlohmann reactphysics png zlib ctti # lua ogg openal aldc gltf freetype bullet meshoptimizer draco luajit ultralight-ux ncurses curl openvr discord
|
||||
endif
|
||||
ifneq (,$(findstring vulkan,$(REQ_DEPS)))
|
||||
FLAGS += -DVK_USE_PLATFORM_WIN32_KHR -DUF_USE_VULKAN
|
||||
@ -99,6 +99,14 @@ ifneq (,$(findstring png,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_PNG -DUF_USE_ZLIB
|
||||
DEPS += -lpng -lz
|
||||
endif
|
||||
ifneq (,$(findstring lz4,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_LZ4
|
||||
DEPS += -llz4
|
||||
endif
|
||||
ifneq (,$(findstring xz,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_XZ -DUF_USE_LZMA
|
||||
DEPS += -lxz -llzma
|
||||
endif
|
||||
ifneq (,$(findstring openal,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_OPENAL -DUF_USE_ALUT
|
||||
ifneq (,$(findstring dreamcast,$(ARCH)))
|
||||
@ -307,6 +315,7 @@ clean:
|
||||
@-rm ./bin/dreamcast/build/*
|
||||
@-rm ./bin/dreamcast/romdisk.*
|
||||
@-rm ./bin/dreamcast/$(TARGET_NAME).*
|
||||
# @-find ./bin/data/ -name "*.gz" -type f -delete
|
||||
|
||||
run:
|
||||
$(KOS_EMU) ./bin/dreamcast/$(TARGET_NAME).cdi
|
||||
@ -319,6 +328,7 @@ clean:
|
||||
@-rm -f $(OBJS_DLL)
|
||||
@-rm -f $(OBJS_EXT_DLL)
|
||||
@-rm -f $(OBJS)
|
||||
@-find ./bin/data/ -name "*.gz" -type f -delete
|
||||
|
||||
run:
|
||||
./program.sh
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"engine": {
|
||||
"scenes": {
|
||||
"start": "SS2",
|
||||
"meshes": { "interleave": true },
|
||||
"meshes": { "interleaved": false },
|
||||
"matrix": { "reverseInfinite": true },
|
||||
"lights": { "enabled": true,
|
||||
"useLightmaps": false,
|
||||
@ -14,7 +14,7 @@
|
||||
"max": 6,
|
||||
"samples": 2,
|
||||
"experimental mode": 1
|
||||
},
|
||||
},
|
||||
"textures": {
|
||||
"max": {
|
||||
"2D": 1024,
|
||||
@ -23,16 +23,18 @@
|
||||
}
|
||||
},
|
||||
"vxgi": {
|
||||
"limiter": 2,
|
||||
"size": 96,
|
||||
"limiter": 1,
|
||||
"size": 86,
|
||||
"dispatch": 8,
|
||||
"cascades": 2,
|
||||
"cascades": 4,
|
||||
"cascadePower": 4,
|
||||
"granularity": 8,
|
||||
"voxelizeScale": 1,
|
||||
"occlusionFalloff": 2,
|
||||
"shadows": 0,
|
||||
"granularity": 4,
|
||||
"extents": {
|
||||
"min": [ -1.5, -1.5, -1.5 ],
|
||||
"max": [ 1.5, 1.5, 1.5 ]
|
||||
"min": [ -4, -4, -4 ],
|
||||
"max": [ 4, 4, 4 ]
|
||||
}
|
||||
},
|
||||
"bloom": {
|
||||
@ -156,6 +158,10 @@
|
||||
"json": "/json.lua"
|
||||
}
|
||||
},
|
||||
"json": {
|
||||
"encoding": "msgpack",
|
||||
"compression": "gz"
|
||||
},
|
||||
"reactphysics": {
|
||||
"timescale": 0.01666666666,
|
||||
"interpolate": false,
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
}
|
||||
},
|
||||
// "filter": "NEAREST",
|
||||
"lightmap": true,
|
||||
"lightmap": "auto",
|
||||
"flags": {
|
||||
"ATLAS": false,
|
||||
"INVERT": false,
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
],
|
||||
"metadata": {
|
||||
"model": {
|
||||
// "lightmap": false,
|
||||
"baking": {
|
||||
"enabled": true,
|
||||
"resolution": 2048,
|
||||
|
||||
@ -34,10 +34,11 @@
|
||||
"exposure": 1.0,
|
||||
"gamma": 1.0,
|
||||
"brightnessThreshold": 1.2,
|
||||
"ambient": [ 0.1, 0.1, 0.1 ],
|
||||
// "ambient": [ 1.0, 1.0, 1.0 ],
|
||||
"ambient": [ 0, 0, 0 ],
|
||||
// "ambient": [ 0.1, 0.1, 0.1 ],
|
||||
// "ambient": [ 0.4, 0.4, 0.4 ],
|
||||
|
||||
"fog": {
|
||||
"fog-": {
|
||||
"color": [ 0.5, 0.5, 0.5 ],
|
||||
"range": [ 16, 32 ],
|
||||
"step scale": 2,
|
||||
@ -54,7 +55,24 @@
|
||||
"shadows": true
|
||||
},
|
||||
"noise": {
|
||||
"size": [ 64, 64, 64 ]
|
||||
"size": [ 32, 32, 32 ]
|
||||
},
|
||||
"vxgi": {
|
||||
/*
|
||||
"limiter": 1,
|
||||
"size": 96,
|
||||
"dispatch": 8,
|
||||
"cascades": 2,
|
||||
"cascadePower": 4,
|
||||
"voxelizeScale": 1,
|
||||
"shadows": 0,
|
||||
*/
|
||||
"occlusionFalloff": 2,
|
||||
"granularity": 4,
|
||||
"extents": {
|
||||
"min": [ -1.5, -1.5, -1.5 ],
|
||||
"max": [ 1.5, 1.5, 1.5 ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,14 +10,13 @@
|
||||
// { "filename": "./models/micro_sci/graph.json" }
|
||||
|
||||
// { "filename": "./models/msci.glb" }
|
||||
// { "filename": "./models/msci/graph.json" }
|
||||
{ "filename": "./models/msci/graph.json" }
|
||||
|
||||
// { "filename": "./models/medsci.glb" }
|
||||
{ "filename": "./models/medsci/graph.json" }
|
||||
// { "filename": "./models/medsci/graph.json" }
|
||||
],
|
||||
"metadata": {
|
||||
"model": {
|
||||
// "lightmap": false,
|
||||
"baking": {
|
||||
"enabled": true,
|
||||
"resolution": 1024
|
||||
|
||||
@ -177,8 +177,13 @@ struct Vxgi {
|
||||
|
||||
float cascadePower;
|
||||
float granularity;
|
||||
float voxelizeScale;
|
||||
float occlusionFalloff;
|
||||
|
||||
uint shadows;
|
||||
uint padding1;
|
||||
uint padding2;
|
||||
uint padding3;
|
||||
};
|
||||
struct Voxel {
|
||||
uvec2 id;
|
||||
|
||||
@ -17,7 +17,7 @@ vec4 voxelTrace( inout Ray ray, float aperture, float maxDistance ) {
|
||||
#endif
|
||||
const float granularityRecip = ubo.vxgi.granularity; //2.0; // 0.25f * (CASCADES - cascade);
|
||||
const float granularity = 1.0f / granularityRecip;
|
||||
const float occlusionFalloff = 128.0f;
|
||||
const float occlusionFalloff = ubo.vxgi.occlusionFalloff; //128.0f;
|
||||
const vec3 voxelBounds = voxelInfo.max - voxelInfo.min;
|
||||
const vec3 voxelBoundsRecip = 1.0f / voxelBounds;
|
||||
const float coneCoefficient = 2.0 * tan(aperture * 0.5);
|
||||
@ -150,7 +150,7 @@ void indirectLighting() {
|
||||
indirectDiffuse += voxelConeTrace( ray, DIFFUSE_CONE_APERTURE ) * weight;
|
||||
weight = PI * 0.15f;
|
||||
}
|
||||
surface.material.occlusion = 1.0 - clamp(indirectDiffuse.a, 0.0, 1.0);
|
||||
surface.material.occlusion += 1.0 - clamp(indirectDiffuse.a, 0.0, 1.0);
|
||||
// outFragColor.rgb = indirectDiffuse.rgb; return;
|
||||
// outFragColor.rgb = vec3(surface.material.occlusion); return;
|
||||
}
|
||||
|
||||
@ -22,10 +22,16 @@ layout (location = 8) flat out uvec4 outId;
|
||||
|
||||
layout (binding = 4) uniform UBO {
|
||||
mat4 voxel;
|
||||
|
||||
float cascadePower;
|
||||
float padding1;
|
||||
float padding2;
|
||||
float padding3;
|
||||
float granularity;
|
||||
float voxelizeScale;
|
||||
float occlusionFalloff;
|
||||
|
||||
uint shadows;
|
||||
uint padding1;
|
||||
uint padding2;
|
||||
uint padding3;
|
||||
} ubo;
|
||||
|
||||
float cascadePower( uint x ) {
|
||||
@ -33,10 +39,9 @@ float cascadePower( uint x ) {
|
||||
// return max( 1, x * ubo.cascadePower );
|
||||
}
|
||||
|
||||
#define USE_CROSS 0
|
||||
void main(){
|
||||
const float RENDER_RESOLUTION = 256.0;
|
||||
const float PIXEL_SCALE = 2.0;
|
||||
const float HALF_PIXEL = 1.0 / (RENDER_RESOLUTION * PIXEL_SCALE);
|
||||
const float HALF_PIXEL = ubo.voxelizeScale;
|
||||
const vec3 C = ( inPosition[0] + inPosition[1] + inPosition[2] ) / 3.0;
|
||||
|
||||
#if USE_CROSS
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
{
|
||||
"import": "/model.json",
|
||||
"assets": [
|
||||
// { "filename": "./models/gm_construct.glb", "delay": 0, "single threaded": false }
|
||||
// { "filename": "./models/gm_construct/graph.json", "delay": 0, "single threaded": false, "category": "models" }
|
||||
{ "filename": "./models/gm_construct/graph.json.gz", "delay": 0, "single threaded": false, "category": "models" }
|
||||
],
|
||||
"metadata": {
|
||||
"model": {
|
||||
"tags": {
|
||||
"worldspawn_2": { "physics": { "type": "mesh", "dynamic": false } },
|
||||
"info_player_spawn": {
|
||||
"action": "attach",
|
||||
"filename": "./player.json",
|
||||
"preserve orientation": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
{
|
||||
"name": "Gui: Loading",
|
||||
"type": "Object",
|
||||
"behaviors": [
|
||||
"GuiBehavior"
|
||||
],
|
||||
"assets": [
|
||||
{ "filename": "./gm_construct.json", "delay": 0 }
|
||||
],
|
||||
"ignore": false,
|
||||
"transform": {
|
||||
"position": [ -0.830591, -0.699509, 0 ],
|
||||
"rotation": {
|
||||
"axis": [ 1, 0, 0 ],
|
||||
"angle": 0
|
||||
},
|
||||
"scale": [ 0.258737, 0.115371, 1 ]
|
||||
},
|
||||
"metadata": {
|
||||
"uv": [ 0, 0, 1, 1 ],
|
||||
"color": [ 1, 1, 1, 0.1 ],
|
||||
"location": "",
|
||||
"scaling": "relative",
|
||||
"text settings": {
|
||||
"stroke": [ 1, 0.749, 0.368, 1 ],
|
||||
"color": [ 1, 0.749, 0.368, 1 ],
|
||||
|
||||
"string": "Loading...",
|
||||
"string1": "コマンド"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
{
|
||||
"import": "/player.json",
|
||||
"assets": [
|
||||
// { "filename": "/gui/hud/hud.json", "delay": 0 }
|
||||
],
|
||||
"metadata": {
|
||||
"overlay": {
|
||||
"floating": true
|
||||
},
|
||||
"collider": true,
|
||||
"light": {
|
||||
"should": false,
|
||||
"color": [1, 1, 1],
|
||||
"position": [ 0, 2.5, 0 ],
|
||||
"power": 1,
|
||||
"radius": [0.001, 32]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
{
|
||||
"import": "/scene.json",
|
||||
"assets": [
|
||||
"./loading.json"
|
||||
],
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
},
|
||||
"renderer": {
|
||||
"clear values": [
|
||||
[ 0, 0, 0, 0 ]
|
||||
],
|
||||
"shader": {
|
||||
"mode": 1,
|
||||
"scalar": 16,
|
||||
"parameters": [ 0, 0, 0, "time" ]
|
||||
}
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"menus": {
|
||||
"pause": "/gui/pause/menu.json"
|
||||
},
|
||||
"light": {
|
||||
"exposure": 1.0,
|
||||
"gamma": 1.0,
|
||||
|
||||
"ambient": [ 0.15, 0.15, 0.15 ],
|
||||
|
||||
"fog": {
|
||||
"color": [ 0.5, 0.5, 0.5 ],
|
||||
"range": [ 64, 256 ],
|
||||
"step scale": 2,
|
||||
"absorbtion": 0.07,
|
||||
"density": {
|
||||
"threshold": 0.35,
|
||||
"multiplier": 5.0,
|
||||
"scale": 25.0,
|
||||
"offset": [0.2, 0, 1],
|
||||
"timescale": 8
|
||||
}
|
||||
},
|
||||
"should": true,
|
||||
"shadows": true
|
||||
},
|
||||
"noise": {
|
||||
"size": [ 32, 32, 32 ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "Craeture",
|
||||
"behaviors": [ "CraetureBehavior" ],
|
||||
"assets": [
|
||||
"./textures/craeture.jpg"
|
||||
],
|
||||
"transform": {
|
||||
"position": [9.62326, 1.1872, -40.8126],
|
||||
"scale": [8, 8, 8]
|
||||
},
|
||||
"metadata": {
|
||||
"model": {
|
||||
"cull mode": "none"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
{
|
||||
"assets": ["./scripts/door.lua"],
|
||||
"system": {
|
||||
"physics": {
|
||||
"type": "bounding box",
|
||||
"recenter": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
{
|
||||
"name": "Gui: Loading",
|
||||
"type": "Object",
|
||||
"behaviors": [
|
||||
// "GuiBehavior"
|
||||
],
|
||||
"assets": [
|
||||
{ "filename": "./mcdonalds.json", "delay": 0 }
|
||||
],
|
||||
"ignore": false,
|
||||
"transform": {
|
||||
"position": [ -0.830591, -0.699509, 0 ],
|
||||
"rotation": {
|
||||
"axis": [ 1, 0, 0 ],
|
||||
"angle": 0
|
||||
},
|
||||
"scale": [ 0.258737, 0.115371, 1 ]
|
||||
},
|
||||
"metadata": {
|
||||
"uv": [ 0, 0, 1, 1 ],
|
||||
"color": [ 1, 1, 1, 0.1 ],
|
||||
"location": "",
|
||||
"scaling": "relative",
|
||||
"text settings": {
|
||||
"stroke": [ 1, 0.749, 0.368, 1 ],
|
||||
"color": [ 1, 0.749, 0.368, 1 ],
|
||||
|
||||
"string": "Loading...",
|
||||
"string1": "コマンド"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "Marker",
|
||||
"type": "Gui",
|
||||
"ignore": false,
|
||||
"transform": {
|
||||
"position": [ 0, 0, 0 ],
|
||||
"rotation": {
|
||||
"axis": [ 1, 0, 0 ],
|
||||
"angle": 0
|
||||
},
|
||||
"scale": [ 1, 1, 1 ]
|
||||
},
|
||||
"metadata": {
|
||||
"uv": [ 0, 0, 1, 1 ],
|
||||
"color": [ 1, 1, 1, 0.8 ],
|
||||
"location": "",
|
||||
"scaling": [ 1, 1 ],
|
||||
"world": true,
|
||||
"gui layer": false
|
||||
},
|
||||
"assets": [
|
||||
"https://cdn..xyz//unity/Android/sprite/sprite_magiccircle_in2.png"
|
||||
]
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
{
|
||||
"import": "/model.json",
|
||||
"assets": [
|
||||
// { "filename": "./static.json", "delay": 8 },
|
||||
|
||||
// { "filename": "./models/mcdonalds.glb", "delay": 0, "single threaded": false }
|
||||
// { "filename": "./models/mcdonalds/graph.json", "delay": 0, "single threaded": false, "category": "models" }
|
||||
{ "filename": "./models/mcdonalds/graph.json.gz", "delay": 0, "single threaded": false, "category": "models" }
|
||||
|
||||
// { "filename": "./models/mini_mcd.glb", "delay": 0, "single threaded": false }
|
||||
// { "filename": "./models/mini_mcd/graph.json.gz", "delay": 0, "single threaded": false, "category": "models" }
|
||||
],
|
||||
"metadata": {
|
||||
"model": {
|
||||
// "grid": { "/^worldspawn/": { "size": 1 } },
|
||||
"cull mode": "none",
|
||||
"tags": {
|
||||
"worldspawn": { "physics": { "type": "mesh", "static": true } },
|
||||
"info_player_spawn": { "action": "attach", "filename": "./player.json", "preserve orientation": true },
|
||||
|
||||
"func_door_rotating_5409": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5487": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle": 1.570795, "normal": [ 1,0,0] } } },
|
||||
"func_door_rotating_5495": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle": 1.570795, "normal": [ 1,0,0] } } },
|
||||
"func_door_rotating_5568": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5568": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5576": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5584": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5656": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle": 1.570795, "normal": [ 1,0,0] } } },
|
||||
"func_door_rotating_5664": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5689": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5698": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5712": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
|
||||
"func_physbox_5212": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_physbox_5548": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_physbox_5931": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
{
|
||||
"import": "/player.json",
|
||||
"assets": [
|
||||
// { "filename": "/gui/hud/hud.json", "delay": 0 }
|
||||
],
|
||||
"metadata": {
|
||||
"overlay": {
|
||||
"floating": true
|
||||
},
|
||||
"collider": true,
|
||||
"light": {
|
||||
"should": false,
|
||||
"color": [1, 1, 1],
|
||||
"position": [ 0, 2.5, 0 ],
|
||||
"power": 1,
|
||||
"radius": [0.001, 32]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
{
|
||||
"import": "/scene.json",
|
||||
"assets": [
|
||||
"./audio/soundscape/ambience.ogg",
|
||||
"./loading.json",
|
||||
"./static.json"
|
||||
],
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
},
|
||||
"renderer": {
|
||||
"shader": {
|
||||
"mode": 1,
|
||||
"scalar": 16,
|
||||
"parameters": [ 0, 0, 0, "time" ]
|
||||
},
|
||||
"clear values": [
|
||||
[ 1, 1, 1, 0 ]
|
||||
]
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"menus": {
|
||||
"pause": "/gui/pause/menu.json"
|
||||
},
|
||||
"bloom": {
|
||||
"scale": 6.0,
|
||||
"strength": 0.125,
|
||||
"sigma": 0.125,
|
||||
"samples": 8
|
||||
},
|
||||
"light": {
|
||||
"exposure": 1.0,
|
||||
"gamma": 1.0,
|
||||
"brightnessThreshold": 1.2,
|
||||
"ambient": [ 0.1, 0.1, 0.1 ],
|
||||
|
||||
"fog": {
|
||||
"color": [ 0.5, 0.5, 0.5 ],
|
||||
"range": [ 16, 32 ],
|
||||
"step scale": 2,
|
||||
"absorbtion": 0.07,
|
||||
"density": {
|
||||
"threshold": 0.35,
|
||||
"multiplier": 5.0,
|
||||
"scale": 25.0,
|
||||
"offset": [0, -1, 1],
|
||||
"timescale": 8
|
||||
}
|
||||
},
|
||||
"should": true,
|
||||
"shadows": true
|
||||
},
|
||||
"noise": {
|
||||
"size": [ 16, 16, 16 ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,110 +0,0 @@
|
||||
local scene = entities.currentScene()
|
||||
local controller = entities.controller()
|
||||
|
||||
local timer = Timer.new()
|
||||
if not timer:running() then
|
||||
timer:start();
|
||||
end
|
||||
|
||||
local polarity = 1
|
||||
local state = 0
|
||||
local targetAlpha = 1
|
||||
local alpha = 0
|
||||
local target = Vector3f(0,0,0)
|
||||
local transform = ent:getComponent("Transform")
|
||||
local metadata = ent:getComponent("Metadata")
|
||||
local speed = metadata["speed"] or 1.0
|
||||
local normal = Vector3f(0,0,-1)
|
||||
if metadata["normal"] ~= nil then
|
||||
local sign = -1
|
||||
if metadata["angle"] < 0 then sign = 1 end
|
||||
normal = Vector3f( metadata["normal"][1] * sign, metadata["normal"][2] * sign, metadata["normal"][3] * sign ):normalize()
|
||||
end
|
||||
local starting = Quaternion(transform.orientation)
|
||||
local ending = transform.orientation:multiply(Quaternion.axisAngle( Vector3f(0,1,0), metadata["angle"] ))
|
||||
local soundEmitter = ent:loadChild("./sound.json",true)
|
||||
local playSound = function( key, loop )
|
||||
if not loop then loop = false end
|
||||
local url = "/door/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Emit.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"]),
|
||||
spatial = true,
|
||||
streamed = true,
|
||||
volume = "sfx",
|
||||
loop = loop
|
||||
}, 0)
|
||||
end
|
||||
local stopSound = function( key )
|
||||
local url = "/door/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Stop.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"])
|
||||
}, 0)
|
||||
end
|
||||
local playSoundscape = function( key )
|
||||
local url = "/soundscape/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Emit.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"]),
|
||||
spatial = false,
|
||||
volume = "sfx",
|
||||
loop = true,
|
||||
streamed = true
|
||||
}, 0)
|
||||
end
|
||||
local stopSoundscape = function( key )
|
||||
local url = "/soundscape/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Stop.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"])
|
||||
}, 0)
|
||||
end
|
||||
soundEmitter:getComponent("Transform"):setReference( transform )
|
||||
-- on tick
|
||||
ent:bind( "tick", function(self)
|
||||
-- transform.orientation = starting:slerp( ending, math.cos(time.current() * speed) * 0.5 + 0.5 )
|
||||
if state == 1 then
|
||||
alpha = alpha + time.delta() * speed
|
||||
|
||||
if alpha > targetAlpha then
|
||||
state = 2
|
||||
alpha = targetAlpha
|
||||
playSound("default_stop")
|
||||
end
|
||||
|
||||
end
|
||||
if state == 3 then
|
||||
alpha = alpha - time.delta() * speed
|
||||
|
||||
if alpha < 0 then
|
||||
state = 0
|
||||
alpha = 0
|
||||
playSound("default_stop")
|
||||
end
|
||||
end
|
||||
|
||||
if state > 0 then
|
||||
transform.orientation = starting:slerp( ending, alpha * polarity )
|
||||
end
|
||||
end )
|
||||
-- on use
|
||||
ent:addHook( "entity:Use.%UID%", function( payload )
|
||||
if state == 0 then
|
||||
state = 1
|
||||
playSound("default_move")
|
||||
if payload.uid ~= nil then
|
||||
local player = entities.get( payload.uid )
|
||||
local pTransform = player:getComponent("Transform")
|
||||
local delta = transform.position - pTransform.position
|
||||
local side = normal:dot(delta)
|
||||
if side > 0 then
|
||||
polarity = 1
|
||||
elseif side < 0 then
|
||||
polarity = -1
|
||||
end
|
||||
end
|
||||
io.print(ent:name())
|
||||
end
|
||||
if state == 2 then
|
||||
state = 3
|
||||
playSound("default_move")
|
||||
end
|
||||
io.print( state, json.encode( payload ) )
|
||||
end )
|
||||
@ -1,22 +0,0 @@
|
||||
local scene = entities.currentScene()
|
||||
local controller = entities.controller()
|
||||
|
||||
local timer = Timer.new()
|
||||
if not timer:running() then
|
||||
timer:start();
|
||||
end
|
||||
|
||||
local transform = ent:getComponent("Transform")
|
||||
-- on tick
|
||||
ent:bind( "tick", function(self)
|
||||
local offset = Vector3f(0,0,0)
|
||||
if window.keyPressed("J") then offset.x = offset.x - time.delta() end
|
||||
if window.keyPressed("L") then offset.x = offset.x + time.delta() end
|
||||
if window.keyPressed("N") then offset.y = offset.y - time.delta() end
|
||||
if window.keyPressed("M") then offset.y = offset.y + time.delta() end
|
||||
if window.keyPressed("I") then offset.z = offset.z - time.delta() end
|
||||
if window.keyPressed("K") then offset.z = offset.z + time.delta() end
|
||||
if offset:magnitude() > 0.0001 then
|
||||
transform.position = transform.position + offset
|
||||
end
|
||||
end )
|
||||
@ -1,90 +0,0 @@
|
||||
local scene = entities.currentScene()
|
||||
local controller = entities.controller()
|
||||
|
||||
local timer = Timer.new()
|
||||
if not timer:running() then
|
||||
timer:start();
|
||||
end
|
||||
-- release control
|
||||
--[[
|
||||
hooks.call("window:Mouse.CursorVisibility", { state = true })
|
||||
hooks.call("window:Mouse.Lock", {});
|
||||
]]
|
||||
-- on tick
|
||||
ent:bind( "tick", function(self)
|
||||
-- update static effect
|
||||
local metadatas = {
|
||||
ent = ent:getComponent("Metadata"),
|
||||
scene = scene:getComponent("Metadata")
|
||||
}
|
||||
local transforms = {
|
||||
ent = ent:getComponent("Transform"),
|
||||
controller = controller:getComponent("Transform")
|
||||
}
|
||||
local distanceSquared = transforms.controller.position:distance( transforms.ent.position )
|
||||
distanceSquared = distanceSquared * distanceSquared
|
||||
if type(metadatas.ent["static"]["scale"]) == "number" then
|
||||
distanceSquared = distanceSquared * metadatas.ent["static"]["scale"]
|
||||
end
|
||||
local lo = type(metadatas.ent["static"]["range"][1]) == "number" and metadatas.ent["static"]["range"][1] or 0.1
|
||||
local hi = type(metadatas.ent["static"]["range"][2]) == "number" and metadatas.ent["static"]["range"][2] or 0.5
|
||||
local staticBlend = distanceSquared > 1 and 1.0 / distanceSquared or 1.0
|
||||
staticBlend = math.clamp( staticBlend, lo, hi )
|
||||
|
||||
local flicker = type(metadatas.ent["static"]["flicker"]) == "number" and metadatas.ent["static"]["flicker"] or 0.001
|
||||
local pieces = type(metadatas.ent["static"]["pieces"]) == "number" and metadatas.ent["static"]["pieces"] or 1000
|
||||
|
||||
local payload = {
|
||||
mode = 2,
|
||||
parameters = {
|
||||
[1] = flicker,
|
||||
[2] = pieces,
|
||||
[3] = staticBlend,
|
||||
[4] = "time"
|
||||
}
|
||||
}
|
||||
scene:callHook("shader:Update.%UID%", payload)
|
||||
end )
|
||||
|
||||
--[[
|
||||
local hud = ent:loadChild("/hud.json", true)
|
||||
hud:bind( "tick", function(self)
|
||||
-- update distance HUD element
|
||||
if timer:elapsed() <= 0.0125 then return end
|
||||
timer:reset()
|
||||
|
||||
local metadata = self:getComponent("Metadata")
|
||||
local transforms = {
|
||||
controller = controller:getComponent("Transform"),
|
||||
source = ent:getComponent("Transform")
|
||||
}
|
||||
local distance = transforms.controller.position:distance( transforms.source.position )
|
||||
--distance = string.si( distance, "m" )
|
||||
local maximum = 40
|
||||
local value = math.floor(distance/maximum * 100)
|
||||
if value >= 100 then value = 100 end
|
||||
distance = "Sanity: " .. value .. "%"
|
||||
--distance = math.floor((15-distance)/15 * 100) .. "%"
|
||||
if metadata["text settings"]["string"] ~= distance then
|
||||
self:callHook( "gui:UpdateString.%UID%", {
|
||||
string = distance
|
||||
} )
|
||||
end
|
||||
end )
|
||||
]]
|
||||
--[[
|
||||
local marker = ent:loadChild("./marker.json", true)
|
||||
marker:bind( "tick", function(self)
|
||||
local transform = marker:getComponent("Transform")
|
||||
local parentTransform = ent:getComponent("Transform")
|
||||
local controllerTransform = controller:getComponent("Transform")
|
||||
|
||||
local controllerCamera = controller:getComponent("Camera")
|
||||
local controllerCameraTransform = controllerCamera:getTransform()
|
||||
|
||||
transform.position = parentTransform.position + Vector3f(0,3,0)
|
||||
transform.orientation = Quaternion.lookAt( transform.position - controllerTransform.position, Vector3f(0,1,0) )
|
||||
-- transform.orientation = transform.orientation:normalize()
|
||||
-- transform.model = controllerCamera:getProjection() * controllerCamera:getView() * Matrix4f.translate( transform.position ) * transform.orientation:matrix()
|
||||
end )
|
||||
]]
|
||||
@ -1,34 +0,0 @@
|
||||
{
|
||||
"type": "Object",
|
||||
"name": "Sound Emitter",
|
||||
"ignore": false,
|
||||
"assets": [
|
||||
],
|
||||
"behaviors": [
|
||||
"SoundEmitterBehavior"
|
||||
],
|
||||
"transform": {
|
||||
"reference": true
|
||||
},
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
},
|
||||
"defaults": {
|
||||
"render": true,
|
||||
"asset load": true
|
||||
},
|
||||
"load": {
|
||||
"ignore": true
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"audio": {
|
||||
"spatial": true,
|
||||
"loop": false,
|
||||
"volume": 1,
|
||||
"rolloffFactor": 0.5,
|
||||
"epsilon": 0.5
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
{
|
||||
"type": "Object",
|
||||
"name": "Static Emitter",
|
||||
"ignore": false,
|
||||
"assets": [
|
||||
"/overworld/static.ogg",
|
||||
"./scripts/static.lua"
|
||||
],
|
||||
"behaviors": [
|
||||
"SoundEmitterBehavior"
|
||||
],
|
||||
"transform": {
|
||||
"position": [ -13.4342, 2.43658, 298.797 ],
|
||||
"rotation": {
|
||||
"axis": [ 0, 1, 0 ],
|
||||
"angle": 0
|
||||
},
|
||||
"scale": [ 1, 1, 1 ]
|
||||
},
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
},
|
||||
"defaults": {
|
||||
"render": true,
|
||||
"asset load": true
|
||||
},
|
||||
"load": {
|
||||
"ignore": true
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"audio": {
|
||||
"spatial": true,
|
||||
"loop": true,
|
||||
"streamed": false,
|
||||
"volume": 1.6,
|
||||
"rolloffFactor": 2
|
||||
},
|
||||
"static": {
|
||||
"range": [ 0.0025, 1 ],
|
||||
"flicker": 0.5,
|
||||
"pieces": 16,
|
||||
"scale": 0.4
|
||||
},
|
||||
"distance": false
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "Craeture",
|
||||
"behaviors": [ "CraetureBehavior" ],
|
||||
"assets": [
|
||||
"./textures/craeture.jpg"
|
||||
],
|
||||
"transform": {
|
||||
"position": [19.9875, 1.54269, -2.97276],
|
||||
"scale": [1.5, 2, 1.5]
|
||||
},
|
||||
"metadata": {
|
||||
"model": {
|
||||
"cull mode": "none"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
{
|
||||
"assets": ["./scripts/door.lua"],
|
||||
"system": {
|
||||
"physics": {
|
||||
"mass": 0,
|
||||
"inertia": [0, 0, 0],
|
||||
"type": "bounding box",
|
||||
"recenter": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
{
|
||||
"name": "Gui: Loading",
|
||||
"type": "Object",
|
||||
"behaviors": [
|
||||
// "GuiBehavior"
|
||||
],
|
||||
"assets": [
|
||||
{ "filename": "./sh2_mcdonalds.json", "delay": 0 }
|
||||
],
|
||||
"ignore": false,
|
||||
"transform": {
|
||||
"position": [ -0.830591, -0.699509, 0 ],
|
||||
"rotation": {
|
||||
"axis": [ 1, 0, 0 ],
|
||||
"angle": 0
|
||||
},
|
||||
"scale": [ 0.258737, 0.115371, 1 ]
|
||||
},
|
||||
"metadata": {
|
||||
"uv": [ 0, 0, 1, 1 ],
|
||||
"color": [ 1, 1, 1, 0.1 ],
|
||||
"location": "",
|
||||
"scaling": "relative",
|
||||
"text settings": {
|
||||
"stroke": [ 1, 0.749, 0.368, 1 ],
|
||||
"color": [ 1, 0.749, 0.368, 1 ],
|
||||
|
||||
"string": "Loading...",
|
||||
"string1": "コマンド"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "Marker",
|
||||
"type": "Gui",
|
||||
"ignore": false,
|
||||
"transform": {
|
||||
"position": [ 0, 0, 0 ],
|
||||
"rotation": {
|
||||
"axis": [ 1, 0, 0 ],
|
||||
"angle": 0
|
||||
},
|
||||
"scale": [ 1, 1, 1 ]
|
||||
},
|
||||
"metadata": {
|
||||
"uv": [ 0, 0, 1, 1 ],
|
||||
"color": [ 1, 1, 1, 0.8 ],
|
||||
"location": "",
|
||||
"scaling": [ 1, 1 ],
|
||||
"world": true,
|
||||
"gui layer": false
|
||||
},
|
||||
"assets": [
|
||||
"https://cdn..xyz//unity/Android/sprite/sprite_magiccircle_in2.png"
|
||||
]
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
{
|
||||
"import": "/player.json",
|
||||
"assets": [
|
||||
// { "filename": "/gui/hud/hud.json", "delay": 0 }
|
||||
"./playerLight.json"
|
||||
],
|
||||
"metadata": {
|
||||
"overlay": {
|
||||
"floating": true
|
||||
},
|
||||
"collider": true,
|
||||
"light": {
|
||||
"should": false,
|
||||
"color": [1, 1, 1],
|
||||
"position": [ 0, 2.5, 0 ],
|
||||
"power": 1,
|
||||
"radius": [0.001, 32]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
{
|
||||
"import": "/light.json",
|
||||
"ignore": true,
|
||||
"assets": [
|
||||
],
|
||||
"transform": {
|
||||
"track": "parent",
|
||||
"position": [ 0, 1.7, 0 ]
|
||||
},
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"light": {
|
||||
"type": "point",
|
||||
"color": [1, 1, 1],
|
||||
"power": 15,
|
||||
"fov": 90,
|
||||
"bias": {
|
||||
"constant": 1.25,
|
||||
"slope": 1.75,
|
||||
"shader": 0.000005 //0.000000005
|
||||
},
|
||||
"radius": [0.001, 0],
|
||||
"resolution": 1024,
|
||||
"shadows": false,
|
||||
"static": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
{
|
||||
"assets": [],
|
||||
"system": {
|
||||
"physics": {
|
||||
"mass": 0,
|
||||
"inertia": [0, 0, 0],
|
||||
"type": "bounding box",
|
||||
"recenter": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
{
|
||||
"import": "/scene.json",
|
||||
"assets": [
|
||||
"./audio/soundscape/ambience.ogg",
|
||||
"./loading.json"
|
||||
// "./static.json"
|
||||
],
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
},
|
||||
"renderer": {
|
||||
"shader": {
|
||||
"mode": 1,
|
||||
"scalar": 16,
|
||||
"parameters": [ 0, 0, 0, "time" ]
|
||||
},
|
||||
"clear values": [
|
||||
[ 1, 1, 1, 0 ]
|
||||
]
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"menus": {
|
||||
"pause": "/gui/pause/menu.json"
|
||||
},
|
||||
"bloom": {
|
||||
"scale": 1.0,
|
||||
"strength": 1.0,
|
||||
"sigma": 2.0,
|
||||
"samples": 2
|
||||
},
|
||||
"light": {
|
||||
"exposure": 1.0,
|
||||
"gamma": 1.0,
|
||||
"brightnessThreshold": 1.2,
|
||||
|
||||
"ambient": [ 0.15, 0.15, 0.15 ],
|
||||
|
||||
"fog": {
|
||||
"color": [ 0.5, 0.5, 0.5 ],
|
||||
"range": [ 8, 256 ],
|
||||
"step scale": 2,
|
||||
"absorbtion": 0.07,
|
||||
"density": {
|
||||
"threshold": 0.35,
|
||||
"multiplier": 5.0,
|
||||
"scale": 25.0,
|
||||
"offset": [0.2, 0, 1],
|
||||
"timescale": 8
|
||||
}
|
||||
},
|
||||
"should": true,
|
||||
"shadows": true
|
||||
},
|
||||
"noise": {
|
||||
"size": [ 16, 16, 16 ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,107 +0,0 @@
|
||||
local scene = entities.currentScene()
|
||||
local controller = entities.controller()
|
||||
|
||||
local timer = Timer.new()
|
||||
if not timer:running() then
|
||||
timer:start();
|
||||
end
|
||||
|
||||
local polarity = 1
|
||||
local state = 0
|
||||
local targetAlpha = 1
|
||||
local alpha = 0
|
||||
local target = Vector3f(0,0,0)
|
||||
local transform = ent:getComponent("Transform")
|
||||
local metadata = ent:getComponent("Metadata")
|
||||
local speed = metadata["speed"] or 1.0
|
||||
local normal = Vector3f(0,0,-1)
|
||||
if metadata["normal"] ~= nil then
|
||||
local sign = -1
|
||||
if metadata["angle"] < 0 then sign = 1 end
|
||||
normal = Vector3f( metadata["normal"][1] * sign, metadata["normal"][2] * sign, metadata["normal"][3] * sign ):normalize()
|
||||
end
|
||||
local starting = Quaternion(transform.orientation)
|
||||
local ending = transform.orientation:multiply(Quaternion.axisAngle( Vector3f(0,1,0), metadata["angle"] ))
|
||||
local soundEmitter = ent:loadChild("./sound.json",true)
|
||||
local playSound = function( key, loop )
|
||||
if not loop then loop = false end
|
||||
local url = "/door/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Emit.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"]),
|
||||
spatial = true,
|
||||
streamed = true,
|
||||
volume = "sfx",
|
||||
loop = loop
|
||||
}, 0)
|
||||
end
|
||||
local stopSound = function( key )
|
||||
local url = "/door/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Stop.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"])
|
||||
}, 0)
|
||||
end
|
||||
local playSoundscape = function( key )
|
||||
local url = "/soundscape/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Emit.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"]),
|
||||
spatial = false,
|
||||
volume = "sfx",
|
||||
loop = true,
|
||||
streamed = true
|
||||
}, 0)
|
||||
end
|
||||
local stopSoundscape = function( key )
|
||||
local url = "/soundscape/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Stop.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"])
|
||||
}, 0)
|
||||
end
|
||||
soundEmitter:getComponent("Transform"):setReference( transform )
|
||||
-- on tick
|
||||
ent:bind( "tick", function(self)
|
||||
-- transform.orientation = starting:slerp( ending, math.cos(time.current() * speed) * 0.5 + 0.5 )
|
||||
if state == 1 then
|
||||
alpha = alpha + time.delta() * speed
|
||||
|
||||
if alpha > targetAlpha then
|
||||
state = 2
|
||||
alpha = targetAlpha
|
||||
playSound("default_stop")
|
||||
end
|
||||
|
||||
end
|
||||
if state == 3 then
|
||||
alpha = alpha - time.delta() * speed
|
||||
|
||||
if alpha < 0 then
|
||||
state = 0
|
||||
alpha = 0
|
||||
playSound("default_stop")
|
||||
end
|
||||
end
|
||||
|
||||
if state > 0 then
|
||||
transform.orientation = starting:slerp( ending, alpha * polarity )
|
||||
end
|
||||
end )
|
||||
-- on use
|
||||
ent:addHook( "entity:Use.%UID%", function( payload )
|
||||
if state == 0 or state == 3 then
|
||||
state = 1
|
||||
playSound("default_move")
|
||||
if payload.uid ~= nil then
|
||||
local player = entities.get( payload.uid )
|
||||
local pTransform = player:getComponent("Transform")
|
||||
local delta = transform.position - pTransform.position
|
||||
local side = normal:dot(delta)
|
||||
if side > 0 then
|
||||
polarity = 1
|
||||
elseif side < 0 then
|
||||
polarity = -1
|
||||
end
|
||||
end
|
||||
elseif state == 2 or state == 1 then
|
||||
state = 3
|
||||
playSound("default_move")
|
||||
end
|
||||
end )
|
||||
@ -1,22 +0,0 @@
|
||||
local scene = entities.currentScene()
|
||||
local controller = entities.controller()
|
||||
|
||||
local timer = Timer.new()
|
||||
if not timer:running() then
|
||||
timer:start();
|
||||
end
|
||||
|
||||
local transform = ent:getComponent("Transform")
|
||||
-- on tick
|
||||
ent:bind( "tick", function(self)
|
||||
local offset = Vector3f(0,0,0)
|
||||
if window.keyPressed("J") then offset.x = offset.x - time.delta() end
|
||||
if window.keyPressed("L") then offset.x = offset.x + time.delta() end
|
||||
if window.keyPressed("N") then offset.y = offset.y - time.delta() end
|
||||
if window.keyPressed("M") then offset.y = offset.y + time.delta() end
|
||||
if window.keyPressed("I") then offset.z = offset.z - time.delta() end
|
||||
if window.keyPressed("K") then offset.z = offset.z + time.delta() end
|
||||
if offset:magnitude() > 0.0001 then
|
||||
transform.position = transform.position + offset
|
||||
end
|
||||
end )
|
||||
@ -1,90 +0,0 @@
|
||||
local scene = entities.currentScene()
|
||||
local controller = entities.controller()
|
||||
|
||||
local timer = Timer.new()
|
||||
if not timer:running() then
|
||||
timer:start();
|
||||
end
|
||||
-- release control
|
||||
--[[
|
||||
hooks.call("window:Mouse.CursorVisibility", { state = true })
|
||||
hooks.call("window:Mouse.Lock", {});
|
||||
]]
|
||||
-- on tick
|
||||
ent:bind( "tick", function(self)
|
||||
-- update static effect
|
||||
local metadatas = {
|
||||
ent = ent:getComponent("Metadata"),
|
||||
scene = scene:getComponent("Metadata")
|
||||
}
|
||||
local transforms = {
|
||||
ent = ent:getComponent("Transform"),
|
||||
controller = controller:getComponent("Transform")
|
||||
}
|
||||
local distanceSquared = transforms.controller.position:distance( transforms.ent.position )
|
||||
distanceSquared = distanceSquared * distanceSquared
|
||||
if type(metadatas.ent["static"]["scale"]) == "number" then
|
||||
distanceSquared = distanceSquared * metadatas.ent["static"]["scale"]
|
||||
end
|
||||
local lo = type(metadatas.ent["static"]["range"][1]) == "number" and metadatas.ent["static"]["range"][1] or 0.1
|
||||
local hi = type(metadatas.ent["static"]["range"][2]) == "number" and metadatas.ent["static"]["range"][2] or 0.5
|
||||
local staticBlend = distanceSquared > 1 and 1.0 / distanceSquared or 1.0
|
||||
staticBlend = math.clamp( staticBlend, lo, hi )
|
||||
|
||||
local flicker = type(metadatas.ent["static"]["flicker"]) == "number" and metadatas.ent["static"]["flicker"] or 0.001
|
||||
local pieces = type(metadatas.ent["static"]["pieces"]) == "number" and metadatas.ent["static"]["pieces"] or 1000
|
||||
|
||||
local payload = {
|
||||
mode = 2,
|
||||
parameters = {
|
||||
[1] = flicker,
|
||||
[2] = pieces,
|
||||
[3] = staticBlend,
|
||||
[4] = "time"
|
||||
}
|
||||
}
|
||||
scene:callHook("shader:Update.%UID%", payload)
|
||||
end )
|
||||
|
||||
--[[
|
||||
local hud = ent:loadChild("/hud.json", true)
|
||||
hud:bind( "tick", function(self)
|
||||
-- update distance HUD element
|
||||
if timer:elapsed() <= 0.0125 then return end
|
||||
timer:reset()
|
||||
|
||||
local metadata = self:getComponent("Metadata")
|
||||
local transforms = {
|
||||
controller = controller:getComponent("Transform"),
|
||||
source = ent:getComponent("Transform")
|
||||
}
|
||||
local distance = transforms.controller.position:distance( transforms.source.position )
|
||||
--distance = string.si( distance, "m" )
|
||||
local maximum = 40
|
||||
local value = math.floor(distance/maximum * 100)
|
||||
if value >= 100 then value = 100 end
|
||||
distance = "Sanity: " .. value .. "%"
|
||||
--distance = math.floor((15-distance)/15 * 100) .. "%"
|
||||
if metadata["text settings"]["string"] ~= distance then
|
||||
self:callHook( "gui:UpdateString.%UID%", {
|
||||
string = distance
|
||||
} )
|
||||
end
|
||||
end )
|
||||
]]
|
||||
--[[
|
||||
local marker = ent:loadChild("./marker.json", true)
|
||||
marker:bind( "tick", function(self)
|
||||
local transform = marker:getComponent("Transform")
|
||||
local parentTransform = ent:getComponent("Transform")
|
||||
local controllerTransform = controller:getComponent("Transform")
|
||||
|
||||
local controllerCamera = controller:getComponent("Camera")
|
||||
local controllerCameraTransform = controllerCamera:getTransform()
|
||||
|
||||
transform.position = parentTransform.position + Vector3f(0,3,0)
|
||||
transform.orientation = Quaternion.lookAt( transform.position - controllerTransform.position, Vector3f(0,1,0) )
|
||||
-- transform.orientation = transform.orientation:normalize()
|
||||
-- transform.model = controllerCamera:getProjection() * controllerCamera:getView() * Matrix4f.translate( transform.position ) * transform.orientation:matrix()
|
||||
end )
|
||||
]]
|
||||
@ -1,11 +0,0 @@
|
||||
local scene = entities.currentScene()
|
||||
local controller = entities.controller()
|
||||
|
||||
local transform = ent:getComponent("Transform")
|
||||
local controllerTransform = controller:getComponent("Transform")
|
||||
local offset = Vector3f(0,1,0) -- transform.position
|
||||
io.print("TRACKING PLAYER")
|
||||
-- on tick
|
||||
ent:bind( "tick", function(self)
|
||||
transform.position = offset + controllerTransform.position
|
||||
end )
|
||||
@ -1,110 +0,0 @@
|
||||
{
|
||||
"import": "/model.json",
|
||||
"assets": [
|
||||
// { "filename": "./static.json", "delay": 8 },
|
||||
|
||||
{ "filename": "./models/sh_mcd.glb", "delay": 0, "single threaded": false }
|
||||
// { "filename": "./models/sh_mcd/graph.json", "delay": 0, "single threaded": false, "category": "models" }
|
||||
// { "filename": "./models/sh_mcd/graph.json.gz", "delay": 0, "single threaded": false, "category": "models" }
|
||||
],
|
||||
"metadata": {
|
||||
"model": {
|
||||
"cull mode": "none",
|
||||
"alpha mode": "BLEND",
|
||||
"grid": {
|
||||
"/^worldspawn/": {
|
||||
"size": [4,4,4],
|
||||
// "epsilon": 0.01,
|
||||
"cleanup": true,
|
||||
"print": true
|
||||
},
|
||||
"/^worldspawn_sh2/": {
|
||||
"size": [32,32,32],
|
||||
// "epsilon": 0.01,
|
||||
"cleanup": true,
|
||||
"print": true
|
||||
}
|
||||
},
|
||||
"tags": {
|
||||
"worldspawn": { "physics": { "type": "mesh", "static": true } },
|
||||
// "worldspawn_sh2": { "physics": { "type": "mesh", "static": true } },
|
||||
"info_player_spawn": { "action": "attach", "filename": "./player.json", "preserve orientation": true },
|
||||
|
||||
"func_door_rotating_5409": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5487": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle": 1.570795, "normal": [ 1,0,0] } } },
|
||||
"func_door_rotating_5495": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle": 1.570795, "normal": [ 1,0,0] } } },
|
||||
"func_door_rotating_5656": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle": 1.570795, "normal": [ 1,0,0] } } },
|
||||
"func_door_rotating_5664": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5689": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5698": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5712": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
|
||||
"func_physbox_5212": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_physbox_5548": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_physbox_5931": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
|
||||
"func_door_rotating_5568": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5576": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
"func_door_rotating_5584": { "action": "load", "payload": { "import": "./door.json", "metadata": { "angle":-1.570795, "normal": [-1,0,0] } } },
|
||||
|
||||
"func_physbox_5212": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_5548": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_5931": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5839": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5848": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5857": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5864": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5872": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5879": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5886": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5893": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5905": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"func_physbox_multiplayer_5913": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5563": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5564": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5687": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5719": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5721": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5722": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5815": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5816": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5817": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5818": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5819": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5820": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_multiplayer_5821": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5227": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5373": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5374": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5375": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5545": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5546": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5565": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5566": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5591": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5675": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5680": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5681": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5682": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5683": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5684": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5685": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5696": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5707": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5723": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5749": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5750": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5760": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5764": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5787": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5807": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5808": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5809": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5810": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5814": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5822": { "action": "load", "payload": { "import": "./prop.json" } },
|
||||
"prop_physics_override_5824": { "action": "load", "payload": { "import": "./prop.json" } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
{
|
||||
"type": "Object",
|
||||
"name": "Sound Emitter",
|
||||
"ignore": false,
|
||||
"assets": [
|
||||
],
|
||||
"behaviors": [
|
||||
"SoundEmitterBehavior"
|
||||
],
|
||||
"transform": {
|
||||
"reference": true
|
||||
},
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
},
|
||||
"defaults": {
|
||||
"render": true,
|
||||
"asset load": true
|
||||
},
|
||||
"load": {
|
||||
"ignore": true
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"audio": {
|
||||
"spatial": true,
|
||||
"loop": false,
|
||||
"volume": 1,
|
||||
"rolloffFactor": 0.5,
|
||||
"epsilon": 0.5
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
{
|
||||
"type": "Object",
|
||||
"name": "Static Emitter",
|
||||
"ignore": false,
|
||||
"assets": [
|
||||
"/overworld/static.ogg",
|
||||
"./scripts/static.lua"
|
||||
],
|
||||
"behaviors": [
|
||||
"SoundEmitterBehavior"
|
||||
],
|
||||
"transform": {
|
||||
"position": [ -13.4342, 2.43658, 298.797 ],
|
||||
"rotation": {
|
||||
"axis": [ 0, 1, 0 ],
|
||||
"angle": 0
|
||||
},
|
||||
"scale": [ 1, 1, 1 ]
|
||||
},
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
},
|
||||
"defaults": {
|
||||
"render": true,
|
||||
"asset load": true
|
||||
},
|
||||
"load": {
|
||||
"ignore": true
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"audio": {
|
||||
"spatial": true,
|
||||
"loop": true,
|
||||
"streamed": false,
|
||||
"volume": 1.6,
|
||||
"rolloffFactor": 2
|
||||
},
|
||||
"static": {
|
||||
"range": [ 0.0025, 1 ],
|
||||
"flicker": 0.5,
|
||||
"pieces": 16,
|
||||
"scale": 0.4
|
||||
},
|
||||
"distance": false
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
{
|
||||
"behaviors": [ "SoundEmitterBehavior" ],
|
||||
"metadata": {
|
||||
"audio": {
|
||||
"spatial": true,
|
||||
"loop": true,
|
||||
"volume": 1,
|
||||
"rolloffFactor": 1,
|
||||
"streamed": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
{
|
||||
"assets": [
|
||||
"./scripts/camera.lua",
|
||||
"./audio/soundscape/camera.ogg"
|
||||
],
|
||||
"metadata": {
|
||||
"audio": {
|
||||
"rolloffFactor": 4,
|
||||
"volume": 1.0
|
||||
},
|
||||
"sensitivity": 10
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "Craeture",
|
||||
"behaviors": [ "CraetureBehavior" ],
|
||||
"assets": [
|
||||
"./textures/craeture.png"
|
||||
],
|
||||
"transform": {
|
||||
"position": [18.3785, 2.41477, 0.859857],
|
||||
"scale": [8, 8, 8]
|
||||
},
|
||||
"metadata": {
|
||||
"model": {
|
||||
"cull mode": "none"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
{
|
||||
"assets": [ "./scripts/lift.lua" ],
|
||||
"system": {
|
||||
"physics": {
|
||||
"type": "bounding box",
|
||||
"recenter": true,
|
||||
|
||||
"mass": 100,
|
||||
"restitution": 0,
|
||||
"friction": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
{
|
||||
"name": "Gui: Loading",
|
||||
"type": "Object",
|
||||
"behaviors": [
|
||||
"GuiBehavior"
|
||||
],
|
||||
"assets": [
|
||||
{ "filename": "./medsci.json", "delay": 0 }
|
||||
],
|
||||
"ignore": false,
|
||||
"transform": {
|
||||
"position": [ -0.830591, -0.699509, 0 ],
|
||||
"rotation": {
|
||||
"axis": [ 1, 0, 0 ],
|
||||
"angle": 0
|
||||
},
|
||||
"scale": [ 0.258737, 0.115371, 1 ]
|
||||
},
|
||||
"metadata": {
|
||||
"uv": [ 0, 0, 1, 1 ],
|
||||
"color": [ 1, 1, 1, 0.1 ],
|
||||
"location": "",
|
||||
"scaling": "relative",
|
||||
"text settings": {
|
||||
"stroke": [ 1, 0.749, 0.368, 1 ],
|
||||
"color": [ 1, 0.749, 0.368, 1 ],
|
||||
|
||||
"string": "Loading...",
|
||||
"string1": "コマンド"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
{
|
||||
"import": "/model.json",
|
||||
"assets": [
|
||||
// { "filename": "./models/tiny_msci.glb", "delay": 0, "single threaded": false, "category": "models" }
|
||||
// { "filename": "./models/tiny_msci/graph.json", "delay": 0, "single threaded": false, "category": "models" }
|
||||
{ "filename": "./models/tiny_msci/graph.json.gz", "delay": 0, "single threaded": false, "category": "models" }
|
||||
|
||||
// { "filename": "./models/micro_sci.glb", "delay": 0, "single threaded": false, "category": "models" }
|
||||
// { "filename": "./models/micro_sci/graph.json", "delay": 0, "single threaded": false, "category": "models" }
|
||||
// { "filename": "./models/micro_sci/graph.json.gz", "delay": 0, "single threaded": false, "category": "models" }
|
||||
// { "filename": "./craeture.json", "delay": 1 }
|
||||
|
||||
// { "filename": "./models/msci.glb", "delay": 0, "single threaded": false, "category": "models" }
|
||||
// { "filename": "./models/msci/graph.json", "delay": 0, "single threaded": false, "category": "models" }
|
||||
// { "filename": "./models/msci/graph.json.gz", "delay": 0, "single threaded": false, "category": "models" }
|
||||
|
||||
// { "filename": "./models/medsci.glb", "delay": 0, "single threaded": false }
|
||||
// { "filename": "./models/medsci/graph.json", "delay": 0, "single threaded": false, "category": "models" }
|
||||
// { "filename": "./models/medsci/graph.json.gz", "delay": 0, "single threaded": false, "category": "models" }
|
||||
],
|
||||
"metadata": {
|
||||
"model": {
|
||||
"exporter": {
|
||||
"enabled": false
|
||||
},
|
||||
"baking": {
|
||||
"enabled": false,
|
||||
"resolution": 8192,
|
||||
"shadows": 1024,
|
||||
"trigger": { "mode": "rendered" },
|
||||
"output": "./lightmap.png"
|
||||
},
|
||||
// "lightmap": "./lightmap.min.png",
|
||||
"filter": "NEAREST",
|
||||
"tags": {
|
||||
"worldspawn": { "physics": { "type": "mesh", "static": true } },
|
||||
"worldspawn_20": { "physics": { "type": "mesh", "static": true } },
|
||||
// "worldspawn": { "physics": { "type": "bounding boxes", "static": true } },
|
||||
"info_player_spawn": {
|
||||
"action": "attach",
|
||||
"filename": "./player.json",
|
||||
"preserve orientation": true
|
||||
},
|
||||
"ambience_xerxes": { "action": "load", "payload": { "import": "./ambience.json", "assets": [ "./audio/soundscape/xerxes.ogg" ], "metadata": { "audio": { "rolloffFactor": 0.5, "volume": 1.0 } } } },
|
||||
|
||||
"light_30145": { "light": { "power": 120 } },
|
||||
|
||||
"prop_camera_103001_light": { "light": { "shadows": false, "static": false, "dynamic": true, "power": 30 } },
|
||||
"prop_camera_103118_light": { "light": { "shadows": false, "static": false, "dynamic": true, "power": 30 } },
|
||||
"prop_camera_103001": { "action": "load", "payload": { "import": "./camera.json" } },
|
||||
"prop_camera_103118": { "action": "load", "payload": { "import": "./camera.json" } },
|
||||
"func_movelinear_57637": { "action": "load", "payload": { "import": "./lift.json", "metadata": { "delta": [ 0,8.6,0 ] } } },
|
||||
"func_movelinear_82820": { "action": "load", "payload": { "import": "./lift.json", "metadata": { "delta": [ 0,9.2,0 ] } } },
|
||||
"func_movelinear_103114": { "action": "load", "payload": { "import": "./lift.json", "metadata": { "delta": [ 0,-3.0,0 ] } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "Test",
|
||||
"assets": [],
|
||||
"behaviors": [
|
||||
"RenderBehavior",
|
||||
"NoiseBehavior"
|
||||
],
|
||||
"transform": {
|
||||
"position": [ 10, 4, 4 ],
|
||||
"orientation": [0, 0, 0, 1]
|
||||
},
|
||||
"metadata": {
|
||||
"size": [ 256, 256, 256 ],
|
||||
"coefficients": [ 3, 3, 3 ],
|
||||
"amplitude": 1.5,
|
||||
"speed": 0.125
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
{
|
||||
"import": "/player.json",
|
||||
"assets": [
|
||||
// { "filename": "/gui/hud/hud.json", "delay": 0 }
|
||||
],
|
||||
"transform": {
|
||||
"position": [ 0, 0, 0 ],
|
||||
"rotation": {
|
||||
"axis": [ 0, 1, 0 ],
|
||||
"angle": 3.1415926
|
||||
},
|
||||
"scale": [ 1, 1, 1 ]
|
||||
},
|
||||
"metadata": {
|
||||
"overlay": {
|
||||
"floating": true
|
||||
},
|
||||
"collider": true,
|
||||
"light": {
|
||||
"should": false,
|
||||
"color": [1, 1, 1],
|
||||
"position": [ 0, 2.5, 0 ],
|
||||
"power": 1,
|
||||
"radius": [0.001, 32]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
{
|
||||
"import": "/scene.json",
|
||||
"assets": [
|
||||
{ "filename": "./audio/music/medsci1.ogg", "category": "audio-stream", "override": true, "streamed": true },
|
||||
"./loading.json"
|
||||
],
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
},
|
||||
"renderer": {
|
||||
"clear values": [
|
||||
[ 0, 0, 0, 0 ]
|
||||
],
|
||||
"shader": {
|
||||
"mode": 1,
|
||||
"scalar": 16,
|
||||
"parameters": [ 0, 0, 0, "time" ]
|
||||
}
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"menus": {
|
||||
"pause": "/gui/pause/menu.json"
|
||||
},
|
||||
"bloom": {
|
||||
"scale": 1.0,
|
||||
"strength": 0.125,
|
||||
"sigma": 0.8,
|
||||
"samples": 5
|
||||
},
|
||||
"light": {
|
||||
"exposure": 1.0,
|
||||
"gamma": 1.0,
|
||||
"brightnessThreshold": 1.2,
|
||||
|
||||
"ambient": [ 0.0, 0.0, 0.0 ],
|
||||
|
||||
"fog": {
|
||||
"color": [ 0.025, 0.025, 0.1 ],
|
||||
"step scale": 0.0,
|
||||
"range": [ 1, 1 ],
|
||||
"absorbtion": 0.85,
|
||||
"density": {
|
||||
"threshold": 0.5,
|
||||
"multiplier": 5.0,
|
||||
"scale": 50.0,
|
||||
"offset": "time"
|
||||
}
|
||||
},
|
||||
"should": true,
|
||||
"shadows": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,191 +0,0 @@
|
||||
local scene = entities.currentScene()
|
||||
local controller = entities.controller()
|
||||
local controllerTransform = controller:getComponent("Transform")
|
||||
local timer = Timer.new()
|
||||
if not timer:running() then
|
||||
timer:start();
|
||||
end
|
||||
local metadata = ent:getComponent("Metadata")
|
||||
local soundEmitter = ent:loadChild("./sound.json",true)
|
||||
local playSound = function( key )
|
||||
if not loop then loop = false end
|
||||
local url = "./audio/sfx/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Emit.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"]),
|
||||
spatial = true,
|
||||
loop = loop,
|
||||
volume = "sfx",
|
||||
streamed = true
|
||||
}, 0)
|
||||
end
|
||||
local playSoundscape = function( key )
|
||||
local url = "./audio/soundscape/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Emit.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"]),
|
||||
spatial = false,
|
||||
volume = "sfx",
|
||||
loop = true,
|
||||
streamed = true
|
||||
}, 0)
|
||||
end
|
||||
local stopSoundscape = function( key )
|
||||
local url = "./audio/soundscape/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Stop.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"])
|
||||
}, 0)
|
||||
end
|
||||
|
||||
local target = Vector3f(0,0,0)
|
||||
local transform = ent:getComponent("Transform")
|
||||
local speed = metadata["speed"] or 1.0 / 3.0
|
||||
local angle = metadata["angle"] or 1.5
|
||||
transform.orientation = Quaternion.axisAngle( Vector3f(0,1,0), 1.5 )
|
||||
local starting = transform.orientation:multiply(Quaternion.axisAngle( Vector3f(0,1,0), -angle ))
|
||||
local ending = transform.orientation:multiply(Quaternion.axisAngle( Vector3f(0,1,0), angle ))
|
||||
-- on tick
|
||||
local delta = 0
|
||||
local watch = 0
|
||||
local alerted = false
|
||||
local light = nil
|
||||
local lightOffset = nil
|
||||
|
||||
for k, v in pairs(ent:getChildren()) do
|
||||
if v:uid() ~= soundEmitter:uid() then
|
||||
light = v
|
||||
local transform = v:getComponent("Transform")
|
||||
lightOffset = Vector3f(transform.position) --:magnitude()
|
||||
end
|
||||
end
|
||||
|
||||
ent:bind( "tick", function(self)
|
||||
soundEmitter:getComponent("Transform").position = transform.position
|
||||
|
||||
local angleThreshold = metadata["sensitivity"] or 20
|
||||
|
||||
local controllerPosition = Vector3f(controllerTransform.position.x, 0, controllerTransform.position.z)
|
||||
local cameraPosition = Vector3f(transform.position.x, 0, transform.position.z)
|
||||
local distance = cameraPosition:distance(controllerPosition)
|
||||
local direction = cameraPosition - controllerPosition
|
||||
|
||||
local lightTransform = light and light:getComponent("Transform") or nil
|
||||
local lightMetadata = light and light:getComponent("Metadata") or {}
|
||||
if lightTransform ~= nil then
|
||||
lightTransform.position = transform.orientation:rotate( lightOffset );
|
||||
if lightMetadata and lightMetadata["light"] and lightMetadata["light"]["static"] then
|
||||
lightTransform.position = lightTransform.position + transform.position
|
||||
end
|
||||
end
|
||||
|
||||
local angle = math.acos(transform.orientation:rotate( Vector3f(0,0,1):normalize() ):dot( direction:normalize() )) * 180.0 / 3.1415926
|
||||
if angle < angleThreshold and distance < 16 then
|
||||
if watch == 0 then
|
||||
watch = 6
|
||||
playSound("camera_see")
|
||||
if light then
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.color",
|
||||
value = {
|
||||
[1] = 1,
|
||||
[2] = 1,
|
||||
[3] = 0
|
||||
}
|
||||
} )
|
||||
end
|
||||
end
|
||||
watch = watch + time.delta()
|
||||
if watch > 12 and not alerted then
|
||||
playSound("camera_alert")
|
||||
playSound("xerxes_alert")
|
||||
playSoundscape("alarm")
|
||||
alerted = true
|
||||
timer:reset()
|
||||
if light then
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.color",
|
||||
value = {
|
||||
[1] = 1,
|
||||
[2] = 0,
|
||||
[3] = 0
|
||||
}
|
||||
} )
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.fade",
|
||||
value = {
|
||||
rate = 1,
|
||||
power = 0.01,
|
||||
timeout= 0.5
|
||||
}
|
||||
} )
|
||||
end
|
||||
end
|
||||
else
|
||||
if watch > 0 and not alerted then
|
||||
watch = watch - time.delta()
|
||||
if watch < 0 then
|
||||
io.print("CAMERA LOST")
|
||||
watch = 0
|
||||
speed = metadata["speed"] or 1.0 / 3.0
|
||||
if light then
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.color",
|
||||
value = {
|
||||
[1] = 0,
|
||||
[2] = 1,
|
||||
[3] = 0
|
||||
}
|
||||
} )
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.fade",
|
||||
value = nil
|
||||
} )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if not alerted and watch > 0 and light then
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.fade.rate",
|
||||
value = math.floor(watch / 2),
|
||||
} )
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.fade.power",
|
||||
value = 0.01,
|
||||
} )
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.fade.timeout",
|
||||
value = 0.5,
|
||||
} )
|
||||
end
|
||||
if alerted and timer:elapsed() >= 60 then
|
||||
timer:reset()
|
||||
alerted = false
|
||||
watch = 0
|
||||
io.print("ALERT OVER")
|
||||
playSound("camera_lost")
|
||||
stopSoundscape("alarm");
|
||||
if light then
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.color",
|
||||
value = {
|
||||
[1] = 0,
|
||||
[2] = 1,
|
||||
[3] = 0
|
||||
}
|
||||
} )
|
||||
light:callHook( "object:UpdateMetadata.%UID%", {
|
||||
path = "light.fade",
|
||||
value = nil
|
||||
} )
|
||||
end
|
||||
end
|
||||
|
||||
delta = delta + time.delta() * speed
|
||||
local nextRotation = starting:slerp( ending, math.cos(delta) * 0.5 + 0.5 )
|
||||
-- stop if we are going to look away from player
|
||||
local angleNext = math.acos(nextRotation:rotate( Vector3f(0,0,1):normalize() ):dot( direction:normalize() )) * 180.0 / 3.1415926
|
||||
if watch > 0 and angleNext > angle then
|
||||
delta = delta - time.delta() * speed * 3
|
||||
nextRotation = starting:slerp( ending, math.cos(delta) * 0.5 + 0.5 )
|
||||
end
|
||||
transform.orientation = nextRotation
|
||||
end )
|
||||
@ -1,84 +0,0 @@
|
||||
local scene = entities.currentScene()
|
||||
local controller = entities.controller()
|
||||
|
||||
local timer = Timer.new()
|
||||
if not timer:running() then
|
||||
timer:start();
|
||||
end
|
||||
|
||||
local target = Vector3f(0,0,0)
|
||||
local transform = ent:getComponent("Transform")
|
||||
local metadata = ent:getComponent("Metadata")
|
||||
local physics = ent:getComponent("Physics")
|
||||
local bullet = ent:getComponent("Bullet")
|
||||
-- local velocty = physics:linearVelocity()
|
||||
local speed = metadata["speed"] or 1.0
|
||||
local starting = transform.position + Vector3f(0,0,0)
|
||||
local ending = transform.position + Vector3f( metadata["delta"][1], metadata["delta"][2], metadata["delta"][3] )
|
||||
local wait = 0
|
||||
local direction = 1.0 / math.abs(starting:distance(ending))
|
||||
local alpha = 0
|
||||
local startingSound = true
|
||||
|
||||
local soundEmitter = ent:loadChild("./sound.json",true)
|
||||
local playSound = function( key, loop )
|
||||
if not loop then loop = false end
|
||||
local url = "./audio/sfx/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Emit.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"]),
|
||||
spatial = true,
|
||||
streamed = true,
|
||||
volume = "sfx",
|
||||
loop = loop
|
||||
}, 0)
|
||||
end
|
||||
local stopSound = function( key )
|
||||
local url = "./audio/sfx/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Stop.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"])
|
||||
}, 0)
|
||||
end
|
||||
local playSoundscape = function( key )
|
||||
local url = "./audio/soundscape/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Emit.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"]),
|
||||
spatial = false,
|
||||
volume = "sfx",
|
||||
loop = true,
|
||||
streamed = true
|
||||
}, 0)
|
||||
end
|
||||
local stopSoundscape = function( key )
|
||||
local url = "./audio/soundscape/" .. key .. ".ogg"
|
||||
soundEmitter:queueHook("sound:Stop.%UID%", {
|
||||
filename = string.resolveURI(url, metadata["system"]["root"])
|
||||
}, 0)
|
||||
end
|
||||
soundEmitter:getComponent("Transform"):setReference( transform )
|
||||
-- on tick
|
||||
ent:bind( "tick", function(self)
|
||||
|
||||
if wait > 0 then
|
||||
wait = wait - time.delta()
|
||||
else
|
||||
if startingSound then
|
||||
playSound("lift_start", true)
|
||||
startingSound = false
|
||||
end
|
||||
alpha = alpha + time.delta() * speed * direction
|
||||
if alpha <= 0 or alpha >= 1 then
|
||||
alpha = math.clamp( alpha, 0.0, 1.0 )
|
||||
direction = -direction
|
||||
wait = 6
|
||||
stopSound("lift_start")
|
||||
playSound("lift_stop")
|
||||
startingSound = true
|
||||
-- bullet:setVelocity( Vector3f(0,0,0) )
|
||||
-- physics:setLinearVelocity( Vector3f(0,0,0) )
|
||||
else
|
||||
-- bullet:setVelocity( Vector3f(0,direction,0) )
|
||||
-- physics:setLinearVelocity( Vector3f(0,direction / math.abs(direction),0) )
|
||||
end
|
||||
end
|
||||
transform.position = Vector3f.lerp( starting, ending, alpha )
|
||||
end )
|
||||
@ -1,34 +0,0 @@
|
||||
{
|
||||
"type": "Object",
|
||||
"name": "Sound Emitter",
|
||||
"ignore": false,
|
||||
"assets": [
|
||||
],
|
||||
"behaviors": [
|
||||
"SoundEmitterBehavior"
|
||||
],
|
||||
"transform": {
|
||||
"reference": true
|
||||
},
|
||||
"system": {
|
||||
"hot reload": {
|
||||
"enabled": true
|
||||
},
|
||||
"defaults": {
|
||||
"render": true,
|
||||
"asset load": true
|
||||
},
|
||||
"load": {
|
||||
"ignore": true
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"audio": {
|
||||
"spatial": true,
|
||||
"loop": false,
|
||||
"volume": 1,
|
||||
"rolloffFactor": 0.5,
|
||||
"epsilon": 0.5
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,6 @@
|
||||
],
|
||||
"metadata": {
|
||||
"model": {
|
||||
// "lightmap": false,
|
||||
"baking": {
|
||||
"enabled": true,
|
||||
"resolution": 1024,
|
||||
@ -4,13 +4,12 @@
|
||||
// { "filename": "./static.json", "delay": 8 },
|
||||
|
||||
// { "filename": "./models/sh_mcd.glb" }
|
||||
{ "filename": "./models/sh_mcd/graph.json.gz" }
|
||||
{ "filename": "./models/sh_mcd/graph.json" }
|
||||
],
|
||||
"metadata": {
|
||||
"model": {
|
||||
"cull mode": "none",
|
||||
"alpha mode": "BLEND",
|
||||
// "lightmap": false,
|
||||
"baking": {
|
||||
"enabled": true,
|
||||
"resolution": 1024,
|
||||
@ -2,11 +2,11 @@
|
||||
"engine": {
|
||||
"scenes": {
|
||||
"start": "SS2",
|
||||
"meshes": { "interleaved": true },
|
||||
"meshes": { "interleaved": false },
|
||||
"matrix": { "reverseInfinite": false },
|
||||
"lights": {
|
||||
"max": 2,
|
||||
"enabled": false
|
||||
"lights": { "enabled": false,
|
||||
"useLightmaps": true,
|
||||
"max": 2
|
||||
},
|
||||
"shadows": {
|
||||
"enabled": false,
|
||||
@ -63,6 +63,10 @@
|
||||
"json": "/json.lua"
|
||||
}
|
||||
},
|
||||
"json": {
|
||||
"encoding": "msgpack",
|
||||
"compression": "gz"
|
||||
},
|
||||
"reactphysics": {
|
||||
"timescale": 0.03333333333,
|
||||
"interpolate": false,
|
||||
@ -98,12 +102,7 @@
|
||||
"component": "96 KiB"
|
||||
}
|
||||
},
|
||||
"render modes": {
|
||||
"gui": true,
|
||||
"deferred": true,
|
||||
"stereo deferred": false,
|
||||
"multiview stereo deferred": false
|
||||
},
|
||||
"render modes": { "gui": true, "deferred": true },
|
||||
"limiters": {
|
||||
"deltaTime": 5,
|
||||
"framerate": 60
|
||||
@ -126,6 +125,9 @@
|
||||
"entity": {
|
||||
"delete children on destroy": false,
|
||||
"delete components on destroy": false
|
||||
},
|
||||
"loader": {
|
||||
"assert": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -8,15 +8,6 @@
|
||||
#include <uf/utils/memory/pool.h>
|
||||
#include <filesystem>
|
||||
|
||||
#if UF_NO_EXCEPTIONS
|
||||
#define HANDLE_EXCEPTIONS 0
|
||||
#else
|
||||
#define HANDLE_EXCEPTIONS 1
|
||||
#endif
|
||||
|
||||
#if UFENV_DREAMCAST
|
||||
#include <arch/dreamcast/kernel/stack.h>
|
||||
#endif
|
||||
#include <signal.h>
|
||||
|
||||
namespace {
|
||||
@ -77,7 +68,7 @@ int main(int argc, char** argv){
|
||||
}
|
||||
}
|
||||
while ( client::ready && ext::ready ) {
|
||||
#if HANDLE_EXCEPTIONS
|
||||
#if UF_EXCEPTIONS
|
||||
try {
|
||||
#endif
|
||||
/*
|
||||
@ -107,7 +98,7 @@ int main(int argc, char** argv){
|
||||
ext::tick();
|
||||
ext::render();
|
||||
#endif
|
||||
#if HANDLE_EXCEPTIONS
|
||||
#if UF_EXCEPTIONS
|
||||
} catch ( std::runtime_error& e ) {
|
||||
UF_MSG_ERROR("RUNTIME ERROR: " << e.what());
|
||||
abort();
|
||||
|
||||
@ -154,7 +154,7 @@ namespace uf {
|
||||
|
||||
pod::Graph UF_API load( const uf::stl::string&, const uf::Serializer& = ext::json::null() );
|
||||
pod::Graph& UF_API convert( uf::Object&, bool = false );
|
||||
void UF_API save( const pod::Graph&, const uf::stl::string& );
|
||||
uf::stl::string UF_API save( const pod::Graph&, const uf::stl::string& );
|
||||
|
||||
uf::stl::string UF_API print( const pod::Graph& graph );
|
||||
uf::Serializer UF_API stats( const pod::Graph& graph );
|
||||
|
||||
@ -4,12 +4,6 @@
|
||||
|
||||
#if defined(UF_JSON_USE_NLOHMANN) && UF_JSON_USE_NLOHMANN
|
||||
#include "nlohmann.h"
|
||||
#elif defined(UF_JSON_USE_JSONCPP) && UF_JSON_USE_JSONCPP
|
||||
#include "jsoncpp.h"
|
||||
#elif defined(UF_JSON_USE_RAPIDJSON) && UF_JSON_USE_RAPIDJSON
|
||||
#include "rapidjson.h"
|
||||
#elif defined(UF_JSON_USE_LUA) && UF_JSON_USE_LUA
|
||||
#include "lua.h"
|
||||
#else
|
||||
#error "JSON implementation not defined"
|
||||
#endif
|
||||
@ -55,12 +49,84 @@ namespace ext {
|
||||
ext::json::Value UF_API reencode( const ext::json::Value& json, const ext::json::EncodingSettings& settings );
|
||||
ext::json::Value& UF_API reencode( ext::json::Value& json, const ext::json::EncodingSettings& settings );
|
||||
|
||||
uf::stl::string UF_API encode( const ext::json::Value& json, bool pretty = true );
|
||||
uf::stl::string UF_API encode( const ext::json::Value& json, const ext::json::EncodingSettings& settings );
|
||||
template<typename T> T& encode( const ext::json::Value& json, T& output, const ext::json::EncodingSettings& settings = {} );
|
||||
template<typename T> ext::json::Value& decode( ext::json::Value& json, const T& input, const DecodingSettings& settings = {} );
|
||||
|
||||
inline uf::stl::string UF_API encode( const ext::json::Value& json, const ext::json::EncodingSettings& settings = {} ) {
|
||||
uf::stl::string output;
|
||||
encode( json, output, settings );
|
||||
return output;
|
||||
}
|
||||
/*
|
||||
uf::stl::string& UF_API encode( const ext::json::Value& json, uf::stl::string&, const ext::json::EncodingSettings& settings = {} );
|
||||
uf::stl::vector<uint8_t>& UF_API encode( const ext::json::Value& json, uf::stl::vector<uint8_t>&, const ext::json::EncodingSettings& settings = {} );
|
||||
|
||||
ext::json::Value& UF_API decode( ext::json::Value& json, const uf::stl::string& str, const DecodingSettings& = {} );
|
||||
ext::json::Value& UF_API decode( ext::json::Value& json, const uf::stl::vector<uint8_t>& str, const DecodingSettings& = {} );
|
||||
*/
|
||||
|
||||
#if UF_USE_LUA
|
||||
uf::stl::string UF_API encode( const sol::table& table );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& ext::json::encode( const ext::json::Value& json, T& output, const ext::json::EncodingSettings& settings ) {
|
||||
// ext::json::Value json = ext::json::reencode( _json, settings );
|
||||
|
||||
#define UF_JSON_PARSE_ENCODING(ENC)\
|
||||
if ( settings.encoding == #ENC ) {\
|
||||
auto buffer = nlohmann::json::to_ ## ENC( (const ext::json::base_value&) (json) );\
|
||||
output = T( buffer.begin(), buffer.end() );\
|
||||
}
|
||||
|
||||
if ( settings.encoding == "" || settings.encoding == "json" ) {
|
||||
output = settings.pretty ? json.dump(1, '\t') : json.dump();
|
||||
}
|
||||
else UF_JSON_PARSE_ENCODING(bson)
|
||||
else UF_JSON_PARSE_ENCODING(cbor)
|
||||
else UF_JSON_PARSE_ENCODING(msgpack)
|
||||
else UF_JSON_PARSE_ENCODING(ubjson)
|
||||
else UF_JSON_PARSE_ENCODING(bjdata)
|
||||
else {
|
||||
// should probably default to json, not my problem
|
||||
UF_MSG_ERROR("invalid encoding requested: " << settings.encoding);
|
||||
}
|
||||
return output;
|
||||
#undef UF_JSON_PARSE_ENCODING
|
||||
}
|
||||
template<typename T>
|
||||
ext::json::Value& ext::json::decode( ext::json::Value& json, const T& input, const DecodingSettings& settings ) {
|
||||
#define UF_JSON_PARSE_ENCODING(ENC)\
|
||||
if ( settings.encoding == #ENC ) {\
|
||||
json = nlohmann::json::from_ ## ENC(input, strict, exceptions);\
|
||||
}
|
||||
|
||||
constexpr bool comments = true;
|
||||
constexpr bool strict = true;
|
||||
constexpr bool exceptions = true;
|
||||
#if UF_EXCEPTIONS
|
||||
try {
|
||||
#endif
|
||||
if ( settings.encoding == "" || settings.encoding == "json" ) {
|
||||
json = nlohmann::json::parse(input, nullptr, exceptions, comments);
|
||||
}
|
||||
else UF_JSON_PARSE_ENCODING(bson)
|
||||
else UF_JSON_PARSE_ENCODING(cbor)
|
||||
else UF_JSON_PARSE_ENCODING(msgpack)
|
||||
else UF_JSON_PARSE_ENCODING(ubjson)
|
||||
else UF_JSON_PARSE_ENCODING(bjdata)
|
||||
else {
|
||||
// should probably default to json, not my problem
|
||||
UF_MSG_ERROR("invalid encoding requested: " << settings.encoding);
|
||||
}
|
||||
#if UF_EXCEPTIONS
|
||||
} catch ( nlohmann::json::parse_error& e ) {
|
||||
UF_MSG_ERROR("JSON error: " << e.what());
|
||||
}
|
||||
#endif
|
||||
return json;
|
||||
|
||||
#undef UF_JSON_PARSE_ENCODING
|
||||
}
|
||||
@ -5,31 +5,51 @@
|
||||
#include <uf/utils/memory/vector.h>
|
||||
#include <uf/utils/memory/string.h>
|
||||
|
||||
#if !UF_EXCEPTIONS
|
||||
#define JSON_NOEXCEPTION 1
|
||||
#endif
|
||||
// #define NDEBUG 1
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <nlohmann/fifo_map.hpp>
|
||||
|
||||
#define UF_JSON_NLOHMANN_ORDERED 1
|
||||
#define UF_JSON_NLOHMANN_ORDERED 0
|
||||
#define UF_JSON_NLOHMANN_FIFO_MAP 0
|
||||
|
||||
namespace uf {
|
||||
class UF_API Serializer;
|
||||
}
|
||||
|
||||
namespace ext {
|
||||
namespace json {
|
||||
class UF_API Value;
|
||||
|
||||
#if UF_JSON_NLOHMANN_ORDERED
|
||||
#if UF_JSON_NLOHMANN_FIFO_MAP
|
||||
template<class K, class V, class dummy_compare, class A>
|
||||
using fifo_map = nlohmann::fifo_map<K, V, nlohmann::fifo_map_compare<K>, A>;
|
||||
typedef nlohmann::basic_json<fifo_map> base_value;
|
||||
#else
|
||||
typedef nlohmann::ordered_json base_value;
|
||||
#endif
|
||||
#else
|
||||
typedef nlohmann::json base_value;
|
||||
#endif
|
||||
|
||||
typedef Value Document;
|
||||
class UF_API Value : public base_value {
|
||||
public:
|
||||
Value& operator=( const uf::Serializer& );
|
||||
Value& operator=( const Value& );
|
||||
|
||||
template<typename... Args> Value& operator[]( Args... args );
|
||||
template<typename... Args> const Value& operator[]( Args... args ) const;
|
||||
template<typename... Args> Value& operator=( Args... args );
|
||||
// template<typename Arg> Value& operator=( Arg arg );
|
||||
|
||||
// template<typename... Args> Value& emplace_back( Args... args );
|
||||
template<typename T> Value& emplace_back( const T& v );
|
||||
Value& emplace_back( const ext::json::Value& = {} );
|
||||
Value& emplace_back( const uf::Serializer& );
|
||||
|
||||
template<typename T> inline bool is( bool = false ) const = delete;
|
||||
template<typename T> inline T as() const;
|
||||
@ -43,8 +63,8 @@ namespace ext {
|
||||
inline bool isArray( const Value& v ) { return v.is_array(); }
|
||||
inline bool isNull( const Value& v ) { return v.is_null(); }
|
||||
|
||||
inline Value array() { return Value::array(); }
|
||||
inline Value object() { return Value::object(); }
|
||||
inline Value array() { return Value/*::array*/(); } // nu-nlohmann json bitches about `[json.exception.type_error.302] type must be string, but is array`
|
||||
inline Value object() { return Value/*::object*/(); } // nu-nlohmann json bitches about `[json.exception.type_error.302] type must be string, but is array`
|
||||
inline Value null() { return Value(); }
|
||||
Value& UF_API reserve( Value& value, size_t size );
|
||||
|
||||
@ -77,11 +97,21 @@ template<typename... Args> ext::json::Value& ext::json::Value::operator[]( Args.
|
||||
template<typename... Args> const ext::json::Value& ext::json::Value::operator[]( Args... args ) const {
|
||||
return (const ext::json::Value&) ext::json::base_value::operator[](args...);
|
||||
}
|
||||
|
||||
template<typename... Args> ext::json::Value& ext::json::Value::operator=( Args... args ) {
|
||||
ext::json::base_value::operator=(args...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T> ext::json::Value& ext::json::Value::emplace_back( const T& v ) {
|
||||
return (ext::json::Value&) ext::json::base_value::emplace_back(v);
|
||||
}
|
||||
/*
|
||||
template<> ext::json::Value& ext::json::Value::emplace_back<ext::json::Value>( const ext::json::Value& value ) {
|
||||
return (ext::json::Value&) ext::json::base_value::emplace_back( (const ext::json::base_value&) value );
|
||||
}
|
||||
*/
|
||||
|
||||
template<> inline bool ext::json::Value::is<bool>(bool strict) const { return is_boolean(); }
|
||||
template<> inline bool ext::json::Value::is<int8_t>(bool strict) const { return strict ? is_number_integer() : is_number(); }
|
||||
template<> inline bool ext::json::Value::is<int16_t>(bool strict) const { return strict ? is_number_integer() : is_number(); }
|
||||
|
||||
@ -58,6 +58,7 @@
|
||||
#define UF_EXCEPTION(X) { UF_MSG_ERROR(X); std::abort(); }
|
||||
#else
|
||||
#define UF_NO_EXCEPTIONS 0
|
||||
#define UF_EXCEPTIONS 1
|
||||
#define UF_EXCEPTION(X) {\
|
||||
uf::stl::stringstream str;\
|
||||
str << X;\
|
||||
|
||||
@ -10,23 +10,25 @@
|
||||
#include <type_traits>
|
||||
|
||||
namespace uf {
|
||||
class UF_API Serializer : public ext::json::Document {
|
||||
protected:
|
||||
uf::stl::string m_filename = "";
|
||||
class UF_API Serializer : public ext::json::Value {
|
||||
public:
|
||||
typedef uf::stl::string output_t;
|
||||
typedef uf::stl::string input_t;
|
||||
|
||||
Serializer( const uf::stl::string& str = "{}" );
|
||||
Serializer();
|
||||
Serializer( const uf::stl::string& str );
|
||||
Serializer( const ext::json::base_value& );
|
||||
Serializer( const ext::json::Value& );
|
||||
#if UF_USE_LUA
|
||||
Serializer( const sol::table& );
|
||||
#endif
|
||||
|
||||
Serializer::output_t serialize( bool pretty = false ) const;
|
||||
Serializer::output_t serialize( const ext::json::EncodingSettings& ) const;
|
||||
void deserialize( const uf::stl::string&, const ext::json::DecodingSettings& = {} );
|
||||
Serializer::output_t serialize( const ext::json::EncodingSettings& = {} ) const;
|
||||
|
||||
template<typename T>
|
||||
void deserialize( const T& input, const ext::json::DecodingSettings& settings = {} ) {
|
||||
ext::json::decode( *this, input, settings );
|
||||
}
|
||||
|
||||
// serializeable
|
||||
template<typename T>
|
||||
@ -70,7 +72,6 @@ namespace uf {
|
||||
void import( const uf::Serializer& other );
|
||||
ext::json::Value& path( const uf::stl::string& );
|
||||
|
||||
operator Serializer::output_t();
|
||||
operator Serializer::output_t() const;
|
||||
uf::Serializer& operator=( const uf::stl::string& str );
|
||||
uf::Serializer& operator=( const ext::json::base_value& json );
|
||||
|
||||
@ -181,7 +181,7 @@ void uf::Asset::load( const uf::stl::string& callback, const uf::Asset::Payload&
|
||||
|
||||
uf::Asset::Payload uf::Asset::resolveToPayload( const uf::stl::string& uri, const uf::stl::string& mime ) {
|
||||
uf::stl::string extension = uf::string::lowercase( uf::io::extension( uri, -1 ) );
|
||||
uf::stl::string basename = uf::string::lowercase( uf::string::replace( uf::io::filename( uri ), "/.(?:gz|lz)$/", "" ) );
|
||||
uf::stl::string basename = uf::string::lowercase( uf::string::replace( uf::io::filename( uri ), "/.(?:gz|lz4?)$/", "" ) );
|
||||
uf::Asset::Payload payload;
|
||||
|
||||
static uf::stl::unordered_map<uf::stl::string,uf::Asset::Type> typemap = {
|
||||
@ -194,6 +194,9 @@ uf::Asset::Payload uf::Asset::resolveToPayload( const uf::stl::string& uri, cons
|
||||
{ "json", uf::Asset::Type::JSON },
|
||||
{ "bson", uf::Asset::Type::JSON },
|
||||
{ "cbor", uf::Asset::Type::JSON },
|
||||
{ "msgpack",uf::Asset::Type::JSON },
|
||||
{ "ubjson", uf::Asset::Type::JSON },
|
||||
{ "bjdata", uf::Asset::Type::JSON },
|
||||
|
||||
{ "lua", uf::Asset::Type::LUA },
|
||||
|
||||
@ -209,8 +212,11 @@ uf::Asset::Payload uf::Asset::resolveToPayload( const uf::stl::string& uri, cons
|
||||
|
||||
if ( typemap.count( extension ) == 1 ) payload.type = typemap[extension];
|
||||
if ( basename == "graph.json" ) payload.type = uf::Asset::Type::GRAPH;
|
||||
if ( basename == "graph.bson" ) payload.type = uf::Asset::Type::GRAPH;
|
||||
if ( basename == "graph.cbor" ) payload.type = uf::Asset::Type::GRAPH;
|
||||
else if ( basename == "graph.bson" ) payload.type = uf::Asset::Type::GRAPH;
|
||||
else if ( basename == "graph.cbor" ) payload.type = uf::Asset::Type::GRAPH;
|
||||
else if ( basename == "graph.msgpack" ) payload.type = uf::Asset::Type::GRAPH;
|
||||
else if ( basename == "graph.ubjson" ) payload.type = uf::Asset::Type::GRAPH;
|
||||
else if ( basename == "graph.bjdata" ) payload.type = uf::Asset::Type::GRAPH;
|
||||
|
||||
return payload;
|
||||
}
|
||||
@ -237,7 +243,7 @@ uf::stl::string uf::Asset::cache( const uf::Asset::Payload& payload ) {
|
||||
}
|
||||
filename = cached;
|
||||
} else {
|
||||
// do implicit loading of json files (could be encoded as bson, cbor, and compressed as gz, lz)
|
||||
// do implicit loading of json files (could be encoded as bson, cbor, and compressed as gz, lz4)
|
||||
if ( extension == "json" ) {
|
||||
filename = uf::Serializer::resolveFilename( filename );
|
||||
extension = uf::io::extension( extension );
|
||||
@ -260,12 +266,16 @@ uf::stl::string uf::Asset::cache( const uf::Asset::Payload& payload ) {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
#if UF_ENV_DREAMCAST
|
||||
UF_MSG_DEBUG("Preloading " << filename);
|
||||
DC_STATS();
|
||||
#endif
|
||||
return filename;
|
||||
}
|
||||
uf::stl::string uf::Asset::load(const uf::Asset::Payload& payload ) {
|
||||
uf::stl::string filename = payload.filename;
|
||||
uf::stl::string extension = uf::string::lowercase(uf::io::extension( payload.filename, -1 ));
|
||||
uf::stl::string basename = uf::string::lowercase( uf::string::replace( uf::io::filename( payload.filename ), "/.(?:gz|lz)$/", "" ) );
|
||||
uf::stl::string basename = uf::string::lowercase( uf::string::replace( uf::io::filename( payload.filename ), "/.(?:gz|lz4?)$/", "" ) );
|
||||
if ( payload.filename.substr(0,5) == "https" ) {
|
||||
uf::stl::string hash = uf::string::sha256( payload.filename );
|
||||
uf::stl::string cached = uf::io::root + "/cache/http/" + hash + "." + extension;
|
||||
@ -279,7 +289,7 @@ uf::stl::string uf::Asset::load(const uf::Asset::Payload& payload ) {
|
||||
}
|
||||
filename = cached;
|
||||
} else {
|
||||
// do implicit loading of json files (could be encoded as bson, cbor, and compressed as gz, lz)
|
||||
// do implicit loading of json files (could be encoded as bson, cbor, and compressed as gz, lz4)
|
||||
if ( extension == "json" ) {
|
||||
filename = uf::Serializer::resolveFilename( filename );
|
||||
extension = uf::io::extension( extension );
|
||||
@ -303,6 +313,11 @@ uf::stl::string uf::Asset::load(const uf::Asset::Payload& payload ) {
|
||||
return "";
|
||||
}
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
UF_MSG_DEBUG("Loading " << filename);
|
||||
DC_STATS();
|
||||
#endif
|
||||
|
||||
auto& map = this->getComponent<uf::Serializer>();
|
||||
#define UF_ASSET_REGISTER(type)\
|
||||
auto& container = this->getContainer<type>();\
|
||||
@ -353,6 +368,11 @@ uf::stl::string uf::Asset::load(const uf::Asset::Payload& payload ) {
|
||||
}
|
||||
}
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
UF_MSG_DEBUG("Loaded " << filename);
|
||||
DC_STATS();
|
||||
#endif
|
||||
|
||||
return filename;
|
||||
}
|
||||
uf::stl::string uf::Asset::getOriginal( const uf::stl::string& uri ) {
|
||||
|
||||
@ -298,6 +298,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
graph.instances.emplace_back(name);
|
||||
UF_MSG_DEBUG( name );
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load images
|
||||
@ -308,6 +311,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
/*graph.storage*/uf::graph::storage.primitives[name] = decodePrimitives( value, graph );
|
||||
graph.primitives.emplace_back(name);
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load images
|
||||
@ -318,6 +324,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
/*graph.storage*/uf::graph::storage.drawCommands[name] = decodeDrawCommands( value, graph );
|
||||
graph.drawCommands.emplace_back(name);
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load mesh information
|
||||
@ -328,6 +337,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
/*graph.storage*/uf::graph::storage.meshes[name] = decodeMesh( value, graph );
|
||||
graph.meshes.emplace_back(name);
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load images
|
||||
@ -338,6 +350,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
/*graph.storage*/uf::graph::storage.images[name] = decodeImage( value, graph );
|
||||
graph.images.emplace_back(name);
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
#if 0 && !UF_ENV_DREAMCAST
|
||||
if ( !ext::json::isNull( serializer["atlas"] ) ) {
|
||||
UF_DEBUG_TIMER_MULTITRACE("Reading atlas...");
|
||||
@ -362,6 +377,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
/*graph.storage*/uf::graph::storage.textures[name] = decodeTexture( value, graph );
|
||||
graph.textures.emplace_back(name);
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load sampler information
|
||||
@ -372,6 +390,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
/*graph.storage*/uf::graph::storage.samplers[name] = decodeSampler( value, graph );
|
||||
graph.samplers.emplace_back(name);
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load material information
|
||||
@ -382,6 +403,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
/*graph.storage*/uf::graph::storage.materials[name] = decodeMaterial( value, graph );
|
||||
graph.materials.emplace_back(name);
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load light information
|
||||
@ -391,6 +415,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
auto name = value["name"].as<uf::stl::string>();
|
||||
graph.lights[name] = decodeLight( value, graph );
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load animation information
|
||||
@ -407,6 +434,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
}
|
||||
graph.animations.emplace_back(name);
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load skin information
|
||||
@ -417,6 +447,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
/*graph.storage*/uf::graph::storage.skins[name] = decodeSkin( value, graph );
|
||||
graph.skins.emplace_back(name);
|
||||
});
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
jobs.emplace_back([&]{
|
||||
// load node information
|
||||
@ -426,6 +459,9 @@ pod::Graph uf::graph::load( const uf::stl::string& filename, const uf::Serialize
|
||||
graph.nodes.emplace_back(decodeNode( value, graph ));
|
||||
});
|
||||
graph.root = decodeNode( serializer["root"], graph );
|
||||
#if UF_ENV_DREAMCAST
|
||||
DC_STATS();
|
||||
#endif
|
||||
});
|
||||
#if UF_GRAPH_LOAD_MULTITHREAD
|
||||
if ( !jobs.empty() ) uf::thread::batchWorkers_Async( jobs );
|
||||
|
||||
@ -217,7 +217,7 @@ namespace {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
void uf::graph::save( const pod::Graph& graph, const uf::stl::string& filename ) {
|
||||
uf::stl::string uf::graph::save( const pod::Graph& graph, const uf::stl::string& filename ) {
|
||||
uf::stl::string directory = uf::io::directory( filename ) + "/" + uf::io::basename(filename) + "/";
|
||||
uf::stl::string target = uf::io::directory( filename ) + "/" + uf::io::basename(filename) + ".graph";
|
||||
|
||||
@ -239,7 +239,7 @@ void uf::graph::save( const pod::Graph& graph, const uf::stl::string& filename )
|
||||
};
|
||||
|
||||
if ( settings.encoding == "auto" ) settings.encoding = ext::json::PREFERRED_ENCODING;
|
||||
if ( settings.compression == "auto" ) settings.compression = ext::json::PREFERRED_COMPRESSION;
|
||||
if ( settings.compression == "auto" ) settings.compression = ext::json::PREFERRED_COMPRESSION;
|
||||
|
||||
if ( !settings.combined ) uf::io::mkdir(directory);
|
||||
#if UF_USE_XATLAS
|
||||
@ -299,10 +299,9 @@ void uf::graph::save( const pod::Graph& graph, const uf::stl::string& filename )
|
||||
auto& mesh = /*graph.storage*/uf::graph::storage.meshes.map.at(name);
|
||||
if ( !s.encodeBuffers ) {
|
||||
s.filename = directory+"/mesh."+std::to_string(i)+".json";
|
||||
encode(mesh, s).writeToFile(s.filename, settings);
|
||||
encode(mesh, s).writeToFile(s.filename);
|
||||
uf::Serializer json;
|
||||
json["name"] = name;
|
||||
// json["filename"] = uf::io::filename(s.filename + (settings.compress ? ".gz" : ""));
|
||||
json["filename"] = uf::io::filename(s.filename);
|
||||
serializer["meshes"].emplace_back( json );
|
||||
} else {
|
||||
@ -408,8 +407,7 @@ void uf::graph::save( const pod::Graph& graph, const uf::stl::string& filename )
|
||||
auto& name = graph.animations[i];
|
||||
uf::stl::string f = "animation."+std::to_string(i)+".json";
|
||||
auto& animation = /*graph.storage*/uf::graph::storage.animations.map.at(name);
|
||||
encode(animation, settings).writeToFile(directory+"/"+f, settings);
|
||||
// serializer["animations"].emplace_back(f + (settings.compress ? ".gz" : ""));
|
||||
encode(animation, settings).writeToFile(directory+"/"+f);
|
||||
serializer["animations"].emplace_back(f);
|
||||
}
|
||||
} else {
|
||||
@ -440,14 +438,18 @@ void uf::graph::save( const pod::Graph& graph, const uf::stl::string& filename )
|
||||
#endif
|
||||
|
||||
if ( !settings.combined ) target = directory + "/graph.json";
|
||||
serializer.writeToFile( target, settings );
|
||||
serializer.writeToFile( target );
|
||||
UF_MSG_DEBUG("Saving graph to `" << target << "`");
|
||||
|
||||
/*
|
||||
if ( graph.metadata["exporter"]["quit"].as<bool>(true) ) {
|
||||
ext::json::Value payload;
|
||||
payload["message"] = "Termination after gltf conversion requested.";
|
||||
uf::scene::getCurrentScene().queueHook("system:Quit", payload);
|
||||
}
|
||||
*/
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
uf::stl::string uf::graph::print( const pod::Graph& graph ) {
|
||||
|
||||
@ -371,12 +371,8 @@ void uf::graph::process( pod::Graph& graph ) {
|
||||
uf::stl::unordered_map<uf::stl::string, bool> isSrgb;
|
||||
|
||||
// process lightmap
|
||||
#if UF_USE_OPENGL
|
||||
#define UF_GRAPH_DEFAULT_LIGHTMAP "./lightmap.%i.min.dtex"
|
||||
#else
|
||||
#define UF_GRAPH_DEFAULT_LIGHTMAP "./lightmap.%i.png"
|
||||
#endif
|
||||
{
|
||||
constexpr const char* UF_GRAPH_DEFAULT_LIGHTMAP = "./lightmap.%i.png";
|
||||
uf::stl::unordered_map<size_t, uf::stl::string> filenames;
|
||||
uf::stl::unordered_map<size_t, size_t> lightmapIDs;
|
||||
uint32_t lightmapCount = 0;
|
||||
@ -385,16 +381,35 @@ void uf::graph::process( pod::Graph& graph ) {
|
||||
auto& instance = uf::graph::storage.instances[name];
|
||||
filenames[instance.auxID] = uf::string::replace(UF_GRAPH_DEFAULT_LIGHTMAP, "%i", std::to_string(instance.auxID));
|
||||
|
||||
lightmapCount = std::max( lightmapCount, instance.auxID );
|
||||
lightmapCount = std::max( lightmapCount, instance.auxID + 1 );
|
||||
}
|
||||
for ( auto& name : graph.primitives ) {
|
||||
auto& primitives = uf::graph::storage.primitives[name];
|
||||
for ( auto& primitive : primitives ) {
|
||||
filenames[primitive.instance.auxID] = uf::string::replace(UF_GRAPH_DEFAULT_LIGHTMAP, "%i", std::to_string(primitive.instance.auxID));
|
||||
|
||||
lightmapCount = std::max( lightmapCount, primitive.instance.auxID );
|
||||
lightmapCount = std::max( lightmapCount, primitive.instance.auxID + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( graph.metadata["lightmap"].is<uf::stl::string>() && graph.metadata["lightmap"].as<uf::stl::string>() == "auto" ) {
|
||||
uint32_t mtime = uf::io::mtime( graph.name );
|
||||
// lightmaps are considered stale if they're older than the graph's source
|
||||
bool stale = false;
|
||||
for ( auto& pair : filenames ) {
|
||||
uf::stl::string filename = uf::io::sanitize( pair.second, uf::io::directory( graph.name ) );
|
||||
auto time = uf::io::mtime(filename);
|
||||
if ( !uf::io::exists( filename ) ) continue;
|
||||
if ( time < mtime ) {
|
||||
UF_MSG_DEBUG("Stale lightmap detected, disabling use of lightmaps: " << filename);
|
||||
stale = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
graph.metadata["lightmap"] = !stale;
|
||||
}
|
||||
|
||||
|
||||
graph.metadata["baking"]["layers"] = lightmapCount;
|
||||
|
||||
if ( graph.metadata["lightmap"].as<bool>() ) for ( auto& pair : filenames ) {
|
||||
@ -402,7 +417,7 @@ void uf::graph::process( pod::Graph& graph ) {
|
||||
auto f = uf::io::sanitize( pair.second, uf::io::directory( graph.name ) );
|
||||
|
||||
if ( !uf::io::exists( f ) ) {
|
||||
UF_MSG_ERROR( "lightmap does not exist: " << f )
|
||||
UF_MSG_ERROR( "lightmap does not exist: " << i << " " << f )
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@ -190,6 +190,7 @@ void uf::ObjectBehavior::tick( uf::Object& self ) {
|
||||
metadata.deserialize(self, metadataJson);
|
||||
#endif
|
||||
// listen for metadata file changes
|
||||
#if !UF_ENV_DREAMCAST
|
||||
if ( metadata.system.hotReload.enabled ) {
|
||||
size_t mtime = uf::io::mtime( metadata.system.filename );
|
||||
if ( metadata.system.hotReload.mtime < mtime ) {
|
||||
@ -197,6 +198,7 @@ void uf::ObjectBehavior::tick( uf::Object& self ) {
|
||||
this->reload();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( metadata.transform.trackParent && this->hasParent() ) {
|
||||
auto& parent = this->getParent();
|
||||
|
||||
@ -150,16 +150,19 @@ bool uf::Object::load( const uf::Serializer& _json ) {
|
||||
uf::Serializer chain = json;
|
||||
uf::stl::string root = metadata.system.root;
|
||||
uf::Serializer separated;
|
||||
separated["assets"] = json["assets"];
|
||||
separated["behaviors"] = json["behaviors"];
|
||||
separated["assets"] = ext::json::isArray( json["assets"] ) ? json["assets"] : ext::json::array();
|
||||
separated["behaviors"] = ext::json::isArray( json["behaviors"] ) ? json["behaviors"] : ext::json::array();
|
||||
do {
|
||||
uf::stl::string filename = chain["import"].is<uf::stl::string>() ? chain["import"].as<uf::stl::string>() : chain["include"].as<uf::stl::string>();
|
||||
filename = uf::io::resolveURI( filename, root );
|
||||
chain.readFromFile( filename );
|
||||
root = uf::io::directory( filename );
|
||||
ext::json::forEach(chain["assets"], [&](ext::json::Value& value){
|
||||
if ( ext::json::isObject( value ) ) value["filename"] = uf::io::resolveURI( value["filename"].as<uf::stl::string>(), root );
|
||||
else value = uf::io::resolveURI( value.as<uf::stl::string>(), root );
|
||||
if ( ext::json::isObject( value ) ) {
|
||||
value["filename"] = uf::io::resolveURI( value["filename"].as<uf::stl::string>(), root );
|
||||
} else {
|
||||
value = uf::io::resolveURI( value.as<uf::stl::string>(), root );
|
||||
}
|
||||
separated["assets"].emplace_back( value );
|
||||
});
|
||||
ext::json::forEach(chain["behaviors"], [&](ext::json::Value& value){
|
||||
@ -179,8 +182,8 @@ bool uf::Object::load( const uf::Serializer& _json ) {
|
||||
if ( ext::json::isNull( json[key] ) )
|
||||
json[key] = value;
|
||||
});
|
||||
#if UF_ENTITY_METADATA_USE_JSON
|
||||
json["hot reload"]["enabled"] = json["system"]["hot reload"]["enabled"];
|
||||
#if UF_ENV_DREAMCST
|
||||
metadata.system.hotReload.enabled = false;
|
||||
#else
|
||||
metadata.system.hotReload.enabled = json["system"]["hot reload"]["enabled"].as<bool>();
|
||||
#endif
|
||||
|
||||
@ -1,100 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/achievement_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
class AchievementEvents final {
|
||||
public:
|
||||
static void OnUserAchievementUpdate(void* callbackData, DiscordUserAchievement* userAchievement)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->AchievementManager();
|
||||
module.OnUserAchievementUpdate(*reinterpret_cast<UserAchievement const*>(userAchievement));
|
||||
}
|
||||
};
|
||||
|
||||
IDiscordAchievementEvents AchievementManager::events_{
|
||||
&AchievementEvents::OnUserAchievementUpdate,
|
||||
};
|
||||
|
||||
void AchievementManager::SetUserAchievement(Snowflake achievementId,
|
||||
std::int64_t percentComplete,
|
||||
std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->set_user_achievement(
|
||||
internal_, achievementId, percentComplete, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void AchievementManager::FetchUserAchievements(std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->fetch_user_achievements(internal_, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void AchievementManager::CountUserAchievements(std::int32_t* count)
|
||||
{
|
||||
if (!count) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->count_user_achievements(internal_, reinterpret_cast<int32_t*>(count));
|
||||
}
|
||||
|
||||
Result AchievementManager::GetUserAchievement(Snowflake userAchievementId,
|
||||
UserAchievement* userAchievement)
|
||||
{
|
||||
if (!userAchievement) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_user_achievement(
|
||||
internal_, userAchievementId, reinterpret_cast<DiscordUserAchievement*>(userAchievement));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result AchievementManager::GetUserAchievementAt(std::int32_t index,
|
||||
UserAchievement* userAchievement)
|
||||
{
|
||||
if (!userAchievement) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_user_achievement_at(
|
||||
internal_, index, reinterpret_cast<DiscordUserAchievement*>(userAchievement));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,179 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/activity_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
class ActivityEvents final {
|
||||
public:
|
||||
static void OnActivityJoin(void* callbackData, char const* secret)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->ActivityManager();
|
||||
module.OnActivityJoin(static_cast<const char*>(secret));
|
||||
}
|
||||
|
||||
static void OnActivitySpectate(void* callbackData, char const* secret)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->ActivityManager();
|
||||
module.OnActivitySpectate(static_cast<const char*>(secret));
|
||||
}
|
||||
|
||||
static void OnActivityJoinRequest(void* callbackData, DiscordUser* user)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->ActivityManager();
|
||||
module.OnActivityJoinRequest(*reinterpret_cast<User const*>(user));
|
||||
}
|
||||
|
||||
static void OnActivityInvite(void* callbackData,
|
||||
EDiscordActivityActionType type,
|
||||
DiscordUser* user,
|
||||
DiscordActivity* activity)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->ActivityManager();
|
||||
module.OnActivityInvite(static_cast<ActivityActionType>(type),
|
||||
*reinterpret_cast<User const*>(user),
|
||||
*reinterpret_cast<Activity const*>(activity));
|
||||
}
|
||||
};
|
||||
|
||||
IDiscordActivityEvents ActivityManager::events_{
|
||||
&ActivityEvents::OnActivityJoin,
|
||||
&ActivityEvents::OnActivitySpectate,
|
||||
&ActivityEvents::OnActivityJoinRequest,
|
||||
&ActivityEvents::OnActivityInvite,
|
||||
};
|
||||
|
||||
Result ActivityManager::RegisterCommand(char const* command)
|
||||
{
|
||||
auto result = internal_->register_command(internal_, const_cast<char*>(command));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result ActivityManager::RegisterSteam(std::uint32_t steamId)
|
||||
{
|
||||
auto result = internal_->register_steam(internal_, steamId);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void ActivityManager::UpdateActivity(Activity const& activity, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->update_activity(internal_,
|
||||
reinterpret_cast<DiscordActivity*>(const_cast<Activity*>(&activity)),
|
||||
cb.release(),
|
||||
wrapper);
|
||||
}
|
||||
|
||||
void ActivityManager::ClearActivity(std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->clear_activity(internal_, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void ActivityManager::SendRequestReply(UserId userId,
|
||||
ActivityJoinRequestReply reply,
|
||||
std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->send_request_reply(internal_,
|
||||
userId,
|
||||
static_cast<EDiscordActivityJoinRequestReply>(reply),
|
||||
cb.release(),
|
||||
wrapper);
|
||||
}
|
||||
|
||||
void ActivityManager::SendInvite(UserId userId,
|
||||
ActivityActionType type,
|
||||
char const* content,
|
||||
std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->send_invite(internal_,
|
||||
userId,
|
||||
static_cast<EDiscordActivityActionType>(type),
|
||||
const_cast<char*>(content),
|
||||
cb.release(),
|
||||
wrapper);
|
||||
}
|
||||
|
||||
void ActivityManager::AcceptInvite(UserId userId, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->accept_invite(internal_, userId, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,80 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/application_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
void ApplicationManager::ValidateOrExit(std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->validate_or_exit(internal_, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void ApplicationManager::GetCurrentLocale(char locale[128])
|
||||
{
|
||||
if (!locale) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->get_current_locale(internal_, reinterpret_cast<DiscordLocale*>(locale));
|
||||
}
|
||||
|
||||
void ApplicationManager::GetCurrentBranch(char branch[4096])
|
||||
{
|
||||
if (!branch) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->get_current_branch(internal_, reinterpret_cast<DiscordBranch*>(branch));
|
||||
}
|
||||
|
||||
void ApplicationManager::GetOAuth2Token(std::function<void(Result, OAuth2Token const&)> callback)
|
||||
{
|
||||
static auto wrapper =
|
||||
[](void* callbackData, EDiscordResult result, DiscordOAuth2Token* oauth2Token) -> void {
|
||||
std::unique_ptr<std::function<void(Result, OAuth2Token const&)>> cb(
|
||||
reinterpret_cast<std::function<void(Result, OAuth2Token const&)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result), *reinterpret_cast<OAuth2Token const*>(oauth2Token));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result, OAuth2Token const&)>> cb{};
|
||||
cb.reset(new std::function<void(Result, OAuth2Token const&)>(std::move(callback)));
|
||||
internal_->get_oauth2_token(internal_, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void ApplicationManager::GetTicket(std::function<void(Result, char const*)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result, char const* data) -> void {
|
||||
std::unique_ptr<std::function<void(Result, char const*)>> cb(
|
||||
reinterpret_cast<std::function<void(Result, char const*)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result), static_cast<const char*>(data));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result, char const*)>> cb{};
|
||||
cb.reset(new std::function<void(Result, char const*)>(std::move(callback)));
|
||||
internal_->get_ticket(internal_, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,184 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
Result Core::Create(ClientId clientId, std::uint64_t flags, Core** instance)
|
||||
{
|
||||
if (!instance) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
(*instance) = new Core();
|
||||
DiscordCreateParams params{};
|
||||
DiscordCreateParamsSetDefault(¶ms);
|
||||
params.client_id = clientId;
|
||||
params.flags = flags;
|
||||
params.events = nullptr;
|
||||
params.event_data = *instance;
|
||||
params.user_events = &UserManager::events_;
|
||||
params.activity_events = &ActivityManager::events_;
|
||||
params.relationship_events = &RelationshipManager::events_;
|
||||
params.lobby_events = &LobbyManager::events_;
|
||||
params.network_events = &NetworkManager::events_;
|
||||
params.overlay_events = &OverlayManager::events_;
|
||||
params.store_events = &StoreManager::events_;
|
||||
params.voice_events = &VoiceManager::events_;
|
||||
params.achievement_events = &AchievementManager::events_;
|
||||
auto result = DiscordCreate(DISCORD_VERSION, ¶ms, &((*instance)->internal_));
|
||||
if (result != DiscordResult_Ok || !(*instance)->internal_) {
|
||||
delete (*instance);
|
||||
(*instance) = nullptr;
|
||||
}
|
||||
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Core::~Core()
|
||||
{
|
||||
if (internal_) {
|
||||
internal_->destroy(internal_);
|
||||
internal_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Result Core::RunCallbacks()
|
||||
{
|
||||
auto result = internal_->run_callbacks(internal_);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void Core::SetLogHook(LogLevel minLevel, std::function<void(LogLevel, char const*)> hook)
|
||||
{
|
||||
setLogHook_.DisconnectAll();
|
||||
setLogHook_.Connect(std::move(hook));
|
||||
static auto wrapper =
|
||||
[](void* callbackData, EDiscordLogLevel level, char const* message) -> void {
|
||||
auto cb(reinterpret_cast<decltype(setLogHook_)*>(callbackData));
|
||||
if (!cb) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<LogLevel>(level), static_cast<const char*>(message));
|
||||
};
|
||||
|
||||
internal_->set_log_hook(
|
||||
internal_, static_cast<EDiscordLogLevel>(minLevel), &setLogHook_, wrapper);
|
||||
}
|
||||
|
||||
discord::ApplicationManager& Core::ApplicationManager()
|
||||
{
|
||||
if (!applicationManager_.internal_) {
|
||||
applicationManager_.internal_ = internal_->get_application_manager(internal_);
|
||||
}
|
||||
|
||||
return applicationManager_;
|
||||
}
|
||||
|
||||
discord::UserManager& Core::UserManager()
|
||||
{
|
||||
if (!userManager_.internal_) {
|
||||
userManager_.internal_ = internal_->get_user_manager(internal_);
|
||||
}
|
||||
|
||||
return userManager_;
|
||||
}
|
||||
|
||||
discord::ImageManager& Core::ImageManager()
|
||||
{
|
||||
if (!imageManager_.internal_) {
|
||||
imageManager_.internal_ = internal_->get_image_manager(internal_);
|
||||
}
|
||||
|
||||
return imageManager_;
|
||||
}
|
||||
|
||||
discord::ActivityManager& Core::ActivityManager()
|
||||
{
|
||||
if (!activityManager_.internal_) {
|
||||
activityManager_.internal_ = internal_->get_activity_manager(internal_);
|
||||
}
|
||||
|
||||
return activityManager_;
|
||||
}
|
||||
|
||||
discord::RelationshipManager& Core::RelationshipManager()
|
||||
{
|
||||
if (!relationshipManager_.internal_) {
|
||||
relationshipManager_.internal_ = internal_->get_relationship_manager(internal_);
|
||||
}
|
||||
|
||||
return relationshipManager_;
|
||||
}
|
||||
|
||||
discord::LobbyManager& Core::LobbyManager()
|
||||
{
|
||||
if (!lobbyManager_.internal_) {
|
||||
lobbyManager_.internal_ = internal_->get_lobby_manager(internal_);
|
||||
}
|
||||
|
||||
return lobbyManager_;
|
||||
}
|
||||
|
||||
discord::NetworkManager& Core::NetworkManager()
|
||||
{
|
||||
if (!networkManager_.internal_) {
|
||||
networkManager_.internal_ = internal_->get_network_manager(internal_);
|
||||
}
|
||||
|
||||
return networkManager_;
|
||||
}
|
||||
|
||||
discord::OverlayManager& Core::OverlayManager()
|
||||
{
|
||||
if (!overlayManager_.internal_) {
|
||||
overlayManager_.internal_ = internal_->get_overlay_manager(internal_);
|
||||
}
|
||||
|
||||
return overlayManager_;
|
||||
}
|
||||
|
||||
discord::StorageManager& Core::StorageManager()
|
||||
{
|
||||
if (!storageManager_.internal_) {
|
||||
storageManager_.internal_ = internal_->get_storage_manager(internal_);
|
||||
}
|
||||
|
||||
return storageManager_;
|
||||
}
|
||||
|
||||
discord::StoreManager& Core::StoreManager()
|
||||
{
|
||||
if (!storeManager_.internal_) {
|
||||
storeManager_.internal_ = internal_->get_store_manager(internal_);
|
||||
}
|
||||
|
||||
return storeManager_;
|
||||
}
|
||||
|
||||
discord::VoiceManager& Core::VoiceManager()
|
||||
{
|
||||
if (!voiceManager_.internal_) {
|
||||
voiceManager_.internal_ = internal_->get_voice_manager(internal_);
|
||||
}
|
||||
|
||||
return voiceManager_;
|
||||
}
|
||||
|
||||
discord::AchievementManager& Core::AchievementManager()
|
||||
{
|
||||
if (!achievementManager_.internal_) {
|
||||
achievementManager_.internal_ = internal_->get_achievement_manager(internal_);
|
||||
}
|
||||
|
||||
return achievementManager_;
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,59 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/image_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
void ImageManager::Fetch(ImageHandle handle,
|
||||
bool refresh,
|
||||
std::function<void(Result, ImageHandle)> callback)
|
||||
{
|
||||
static auto wrapper =
|
||||
[](void* callbackData, EDiscordResult result, DiscordImageHandle handleResult) -> void {
|
||||
std::unique_ptr<std::function<void(Result, ImageHandle)>> cb(
|
||||
reinterpret_cast<std::function<void(Result, ImageHandle)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result), *reinterpret_cast<ImageHandle const*>(&handleResult));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result, ImageHandle)>> cb{};
|
||||
cb.reset(new std::function<void(Result, ImageHandle)>(std::move(callback)));
|
||||
internal_->fetch(internal_,
|
||||
*reinterpret_cast<DiscordImageHandle const*>(&handle),
|
||||
(refresh ? 1 : 0),
|
||||
cb.release(),
|
||||
wrapper);
|
||||
}
|
||||
|
||||
Result ImageManager::GetDimensions(ImageHandle handle, ImageDimensions* dimensions)
|
||||
{
|
||||
if (!dimensions) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_dimensions(internal_,
|
||||
*reinterpret_cast<DiscordImageHandle const*>(&handle),
|
||||
reinterpret_cast<DiscordImageDimensions*>(dimensions));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result ImageManager::GetData(ImageHandle handle, std::uint8_t* data, std::uint32_t dataLength)
|
||||
{
|
||||
auto result = internal_->get_data(internal_,
|
||||
*reinterpret_cast<DiscordImageHandle const*>(&handle),
|
||||
reinterpret_cast<uint8_t*>(data),
|
||||
dataLength);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,549 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/lobby_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
class LobbyEvents final {
|
||||
public:
|
||||
static void OnLobbyUpdate(void* callbackData, int64_t lobbyId)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->LobbyManager();
|
||||
module.OnLobbyUpdate(lobbyId);
|
||||
}
|
||||
|
||||
static void OnLobbyDelete(void* callbackData, int64_t lobbyId, uint32_t reason)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->LobbyManager();
|
||||
module.OnLobbyDelete(lobbyId, reason);
|
||||
}
|
||||
|
||||
static void OnMemberConnect(void* callbackData, int64_t lobbyId, int64_t userId)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->LobbyManager();
|
||||
module.OnMemberConnect(lobbyId, userId);
|
||||
}
|
||||
|
||||
static void OnMemberUpdate(void* callbackData, int64_t lobbyId, int64_t userId)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->LobbyManager();
|
||||
module.OnMemberUpdate(lobbyId, userId);
|
||||
}
|
||||
|
||||
static void OnMemberDisconnect(void* callbackData, int64_t lobbyId, int64_t userId)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->LobbyManager();
|
||||
module.OnMemberDisconnect(lobbyId, userId);
|
||||
}
|
||||
|
||||
static void OnLobbyMessage(void* callbackData,
|
||||
int64_t lobbyId,
|
||||
int64_t userId,
|
||||
uint8_t* data,
|
||||
uint32_t dataLength)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->LobbyManager();
|
||||
module.OnLobbyMessage(lobbyId, userId, data, dataLength);
|
||||
}
|
||||
|
||||
static void OnSpeaking(void* callbackData, int64_t lobbyId, int64_t userId, bool speaking)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->LobbyManager();
|
||||
module.OnSpeaking(lobbyId, userId, (speaking != 0));
|
||||
}
|
||||
|
||||
static void OnNetworkMessage(void* callbackData,
|
||||
int64_t lobbyId,
|
||||
int64_t userId,
|
||||
uint8_t channelId,
|
||||
uint8_t* data,
|
||||
uint32_t dataLength)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->LobbyManager();
|
||||
module.OnNetworkMessage(lobbyId, userId, channelId, data, dataLength);
|
||||
}
|
||||
};
|
||||
|
||||
IDiscordLobbyEvents LobbyManager::events_{
|
||||
&LobbyEvents::OnLobbyUpdate,
|
||||
&LobbyEvents::OnLobbyDelete,
|
||||
&LobbyEvents::OnMemberConnect,
|
||||
&LobbyEvents::OnMemberUpdate,
|
||||
&LobbyEvents::OnMemberDisconnect,
|
||||
&LobbyEvents::OnLobbyMessage,
|
||||
&LobbyEvents::OnSpeaking,
|
||||
&LobbyEvents::OnNetworkMessage,
|
||||
};
|
||||
|
||||
Result LobbyManager::GetLobbyCreateTransaction(LobbyTransaction* transaction)
|
||||
{
|
||||
if (!transaction) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_lobby_create_transaction(internal_, transaction->Receive());
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetLobbyUpdateTransaction(LobbyId lobbyId, LobbyTransaction* transaction)
|
||||
{
|
||||
if (!transaction) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get_lobby_update_transaction(internal_, lobbyId, transaction->Receive());
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetMemberUpdateTransaction(LobbyId lobbyId,
|
||||
UserId userId,
|
||||
LobbyMemberTransaction* transaction)
|
||||
{
|
||||
if (!transaction) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get_member_update_transaction(internal_, lobbyId, userId, transaction->Receive());
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void LobbyManager::CreateLobby(LobbyTransaction const& transaction,
|
||||
std::function<void(Result, Lobby const&)> callback)
|
||||
{
|
||||
static auto wrapper =
|
||||
[](void* callbackData, EDiscordResult result, DiscordLobby* lobby) -> void {
|
||||
std::unique_ptr<std::function<void(Result, Lobby const&)>> cb(
|
||||
reinterpret_cast<std::function<void(Result, Lobby const&)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result), *reinterpret_cast<Lobby const*>(lobby));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result, Lobby const&)>> cb{};
|
||||
cb.reset(new std::function<void(Result, Lobby const&)>(std::move(callback)));
|
||||
internal_->create_lobby(
|
||||
internal_, const_cast<LobbyTransaction&>(transaction).Internal(), cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void LobbyManager::UpdateLobby(LobbyId lobbyId,
|
||||
LobbyTransaction const& transaction,
|
||||
std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->update_lobby(internal_,
|
||||
lobbyId,
|
||||
const_cast<LobbyTransaction&>(transaction).Internal(),
|
||||
cb.release(),
|
||||
wrapper);
|
||||
}
|
||||
|
||||
void LobbyManager::DeleteLobby(LobbyId lobbyId, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->delete_lobby(internal_, lobbyId, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void LobbyManager::ConnectLobby(LobbyId lobbyId,
|
||||
LobbySecret secret,
|
||||
std::function<void(Result, Lobby const&)> callback)
|
||||
{
|
||||
static auto wrapper =
|
||||
[](void* callbackData, EDiscordResult result, DiscordLobby* lobby) -> void {
|
||||
std::unique_ptr<std::function<void(Result, Lobby const&)>> cb(
|
||||
reinterpret_cast<std::function<void(Result, Lobby const&)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result), *reinterpret_cast<Lobby const*>(lobby));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result, Lobby const&)>> cb{};
|
||||
cb.reset(new std::function<void(Result, Lobby const&)>(std::move(callback)));
|
||||
internal_->connect_lobby(internal_, lobbyId, const_cast<char*>(secret), cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void LobbyManager::ConnectLobbyWithActivitySecret(
|
||||
LobbySecret activitySecret,
|
||||
std::function<void(Result, Lobby const&)> callback)
|
||||
{
|
||||
static auto wrapper =
|
||||
[](void* callbackData, EDiscordResult result, DiscordLobby* lobby) -> void {
|
||||
std::unique_ptr<std::function<void(Result, Lobby const&)>> cb(
|
||||
reinterpret_cast<std::function<void(Result, Lobby const&)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result), *reinterpret_cast<Lobby const*>(lobby));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result, Lobby const&)>> cb{};
|
||||
cb.reset(new std::function<void(Result, Lobby const&)>(std::move(callback)));
|
||||
internal_->connect_lobby_with_activity_secret(
|
||||
internal_, const_cast<char*>(activitySecret), cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void LobbyManager::DisconnectLobby(LobbyId lobbyId, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->disconnect_lobby(internal_, lobbyId, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetLobby(LobbyId lobbyId, Lobby* lobby)
|
||||
{
|
||||
if (!lobby) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_lobby(internal_, lobbyId, reinterpret_cast<DiscordLobby*>(lobby));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetLobbyActivitySecret(LobbyId lobbyId, char secret[128])
|
||||
{
|
||||
if (!secret) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_lobby_activity_secret(
|
||||
internal_, lobbyId, reinterpret_cast<DiscordLobbySecret*>(secret));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetLobbyMetadataValue(LobbyId lobbyId, MetadataKey key, char value[4096])
|
||||
{
|
||||
if (!value) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_lobby_metadata_value(
|
||||
internal_, lobbyId, const_cast<char*>(key), reinterpret_cast<DiscordMetadataValue*>(value));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetLobbyMetadataKey(LobbyId lobbyId, std::int32_t index, char key[256])
|
||||
{
|
||||
if (!key) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_lobby_metadata_key(
|
||||
internal_, lobbyId, index, reinterpret_cast<DiscordMetadataKey*>(key));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::LobbyMetadataCount(LobbyId lobbyId, std::int32_t* count)
|
||||
{
|
||||
if (!count) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->lobby_metadata_count(internal_, lobbyId, reinterpret_cast<int32_t*>(count));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::MemberCount(LobbyId lobbyId, std::int32_t* count)
|
||||
{
|
||||
if (!count) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->member_count(internal_, lobbyId, reinterpret_cast<int32_t*>(count));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetMemberUserId(LobbyId lobbyId, std::int32_t index, UserId* userId)
|
||||
{
|
||||
if (!userId) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get_member_user_id(internal_, lobbyId, index, reinterpret_cast<int64_t*>(userId));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetMemberUser(LobbyId lobbyId, UserId userId, User* user)
|
||||
{
|
||||
if (!user) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get_member_user(internal_, lobbyId, userId, reinterpret_cast<DiscordUser*>(user));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetMemberMetadataValue(LobbyId lobbyId,
|
||||
UserId userId,
|
||||
MetadataKey key,
|
||||
char value[4096])
|
||||
{
|
||||
if (!value) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get_member_metadata_value(internal_,
|
||||
lobbyId,
|
||||
userId,
|
||||
const_cast<char*>(key),
|
||||
reinterpret_cast<DiscordMetadataValue*>(value));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetMemberMetadataKey(LobbyId lobbyId,
|
||||
UserId userId,
|
||||
std::int32_t index,
|
||||
char key[256])
|
||||
{
|
||||
if (!key) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_member_metadata_key(
|
||||
internal_, lobbyId, userId, index, reinterpret_cast<DiscordMetadataKey*>(key));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::MemberMetadataCount(LobbyId lobbyId, UserId userId, std::int32_t* count)
|
||||
{
|
||||
if (!count) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->member_metadata_count(
|
||||
internal_, lobbyId, userId, reinterpret_cast<int32_t*>(count));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void LobbyManager::UpdateMember(LobbyId lobbyId,
|
||||
UserId userId,
|
||||
LobbyMemberTransaction const& transaction,
|
||||
std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->update_member(internal_,
|
||||
lobbyId,
|
||||
userId,
|
||||
const_cast<LobbyMemberTransaction&>(transaction).Internal(),
|
||||
cb.release(),
|
||||
wrapper);
|
||||
}
|
||||
|
||||
void LobbyManager::SendLobbyMessage(LobbyId lobbyId,
|
||||
std::uint8_t* data,
|
||||
std::uint32_t dataLength,
|
||||
std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->send_lobby_message(
|
||||
internal_, lobbyId, reinterpret_cast<uint8_t*>(data), dataLength, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
Result LobbyManager::GetSearchQuery(LobbySearchQuery* query)
|
||||
{
|
||||
if (!query) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_search_query(internal_, query->Receive());
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void LobbyManager::Search(LobbySearchQuery const& query, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->search(
|
||||
internal_, const_cast<LobbySearchQuery&>(query).Internal(), cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void LobbyManager::LobbyCount(std::int32_t* count)
|
||||
{
|
||||
if (!count) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->lobby_count(internal_, reinterpret_cast<int32_t*>(count));
|
||||
}
|
||||
|
||||
Result LobbyManager::GetLobbyId(std::int32_t index, LobbyId* lobbyId)
|
||||
{
|
||||
if (!lobbyId) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_lobby_id(internal_, index, reinterpret_cast<int64_t*>(lobbyId));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void LobbyManager::ConnectVoice(LobbyId lobbyId, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->connect_voice(internal_, lobbyId, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void LobbyManager::DisconnectVoice(LobbyId lobbyId, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->disconnect_voice(internal_, lobbyId, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
Result LobbyManager::ConnectNetwork(LobbyId lobbyId)
|
||||
{
|
||||
auto result = internal_->connect_network(internal_, lobbyId);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::DisconnectNetwork(LobbyId lobbyId)
|
||||
{
|
||||
auto result = internal_->disconnect_network(internal_, lobbyId);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::FlushNetwork()
|
||||
{
|
||||
auto result = internal_->flush_network(internal_);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::OpenNetworkChannel(LobbyId lobbyId, std::uint8_t channelId, bool reliable)
|
||||
{
|
||||
auto result =
|
||||
internal_->open_network_channel(internal_, lobbyId, channelId, (reliable ? 1 : 0));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyManager::SendNetworkMessage(LobbyId lobbyId,
|
||||
UserId userId,
|
||||
std::uint8_t channelId,
|
||||
std::uint8_t* data,
|
||||
std::uint32_t dataLength)
|
||||
{
|
||||
auto result = internal_->send_network_message(
|
||||
internal_, lobbyId, userId, channelId, reinterpret_cast<uint8_t*>(data), dataLength);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,105 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/network_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
class NetworkEvents final {
|
||||
public:
|
||||
static void OnMessage(void* callbackData,
|
||||
DiscordNetworkPeerId peerId,
|
||||
DiscordNetworkChannelId channelId,
|
||||
uint8_t* data,
|
||||
uint32_t dataLength)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->NetworkManager();
|
||||
module.OnMessage(peerId, channelId, data, dataLength);
|
||||
}
|
||||
|
||||
static void OnRouteUpdate(void* callbackData, char const* routeData)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->NetworkManager();
|
||||
module.OnRouteUpdate(static_cast<const char*>(routeData));
|
||||
}
|
||||
};
|
||||
|
||||
IDiscordNetworkEvents NetworkManager::events_{
|
||||
&NetworkEvents::OnMessage,
|
||||
&NetworkEvents::OnRouteUpdate,
|
||||
};
|
||||
|
||||
void NetworkManager::GetPeerId(NetworkPeerId* peerId)
|
||||
{
|
||||
if (!peerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->get_peer_id(internal_, reinterpret_cast<uint64_t*>(peerId));
|
||||
}
|
||||
|
||||
Result NetworkManager::Flush()
|
||||
{
|
||||
auto result = internal_->flush(internal_);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result NetworkManager::OpenPeer(NetworkPeerId peerId, char const* routeData)
|
||||
{
|
||||
auto result = internal_->open_peer(internal_, peerId, const_cast<char*>(routeData));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result NetworkManager::UpdatePeer(NetworkPeerId peerId, char const* routeData)
|
||||
{
|
||||
auto result = internal_->update_peer(internal_, peerId, const_cast<char*>(routeData));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result NetworkManager::ClosePeer(NetworkPeerId peerId)
|
||||
{
|
||||
auto result = internal_->close_peer(internal_, peerId);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result NetworkManager::OpenChannel(NetworkPeerId peerId, NetworkChannelId channelId, bool reliable)
|
||||
{
|
||||
auto result = internal_->open_channel(internal_, peerId, channelId, (reliable ? 1 : 0));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result NetworkManager::CloseChannel(NetworkPeerId peerId, NetworkChannelId channelId)
|
||||
{
|
||||
auto result = internal_->close_channel(internal_, peerId, channelId);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result NetworkManager::SendMessage(NetworkPeerId peerId,
|
||||
NetworkChannelId channelId,
|
||||
std::uint8_t* data,
|
||||
std::uint32_t dataLength)
|
||||
{
|
||||
auto result = internal_->send_message(
|
||||
internal_, peerId, channelId, reinterpret_cast<uint8_t*>(data), dataLength);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,114 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/overlay_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
class OverlayEvents final {
|
||||
public:
|
||||
static void OnToggle(void* callbackData, bool locked)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->OverlayManager();
|
||||
module.OnToggle((locked != 0));
|
||||
}
|
||||
};
|
||||
|
||||
IDiscordOverlayEvents OverlayManager::events_{
|
||||
&OverlayEvents::OnToggle,
|
||||
};
|
||||
|
||||
void OverlayManager::IsEnabled(bool* enabled)
|
||||
{
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->is_enabled(internal_, reinterpret_cast<bool*>(enabled));
|
||||
}
|
||||
|
||||
void OverlayManager::IsLocked(bool* locked)
|
||||
{
|
||||
if (!locked) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->is_locked(internal_, reinterpret_cast<bool*>(locked));
|
||||
}
|
||||
|
||||
void OverlayManager::SetLocked(bool locked, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->set_locked(internal_, (locked ? 1 : 0), cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void OverlayManager::OpenActivityInvite(ActivityActionType type,
|
||||
std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->open_activity_invite(
|
||||
internal_, static_cast<EDiscordActivityActionType>(type), cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void OverlayManager::OpenGuildInvite(char const* code, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->open_guild_invite(internal_, const_cast<char*>(code), cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void OverlayManager::OpenVoiceSettings(std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->open_voice_settings(internal_, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,92 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/relationship_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
class RelationshipEvents final {
|
||||
public:
|
||||
static void OnRefresh(void* callbackData)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->RelationshipManager();
|
||||
module.OnRefresh();
|
||||
}
|
||||
|
||||
static void OnRelationshipUpdate(void* callbackData, DiscordRelationship* relationship)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->RelationshipManager();
|
||||
module.OnRelationshipUpdate(*reinterpret_cast<Relationship const*>(relationship));
|
||||
}
|
||||
};
|
||||
|
||||
IDiscordRelationshipEvents RelationshipManager::events_{
|
||||
&RelationshipEvents::OnRefresh,
|
||||
&RelationshipEvents::OnRelationshipUpdate,
|
||||
};
|
||||
|
||||
void RelationshipManager::Filter(std::function<bool(Relationship const&)> filter)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, DiscordRelationship* relationship) -> bool {
|
||||
auto cb(reinterpret_cast<std::function<bool(Relationship const&)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return {};
|
||||
}
|
||||
return (*cb)(*reinterpret_cast<Relationship const*>(relationship));
|
||||
};
|
||||
std::unique_ptr<std::function<bool(Relationship const&)>> cb{};
|
||||
cb.reset(new std::function<bool(Relationship const&)>(std::move(filter)));
|
||||
internal_->filter(internal_, cb.get(), wrapper);
|
||||
}
|
||||
|
||||
Result RelationshipManager::Count(std::int32_t* count)
|
||||
{
|
||||
if (!count) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->count(internal_, reinterpret_cast<int32_t*>(count));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result RelationshipManager::Get(UserId userId, Relationship* relationship)
|
||||
{
|
||||
if (!relationship) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get(internal_, userId, reinterpret_cast<DiscordRelationship*>(relationship));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result RelationshipManager::GetAt(std::uint32_t index, Relationship* relationship)
|
||||
{
|
||||
if (!relationship) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get_at(internal_, index, reinterpret_cast<DiscordRelationship*>(relationship));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,160 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/storage_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
Result StorageManager::Read(char const* name,
|
||||
std::uint8_t* data,
|
||||
std::uint32_t dataLength,
|
||||
std::uint32_t* read)
|
||||
{
|
||||
if (!read) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->read(internal_,
|
||||
const_cast<char*>(name),
|
||||
reinterpret_cast<uint8_t*>(data),
|
||||
dataLength,
|
||||
reinterpret_cast<uint32_t*>(read));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void StorageManager::ReadAsync(char const* name,
|
||||
std::function<void(Result, std::uint8_t*, std::uint32_t)> callback)
|
||||
{
|
||||
static auto wrapper =
|
||||
[](void* callbackData, EDiscordResult result, uint8_t* data, uint32_t dataLength) -> void {
|
||||
std::unique_ptr<std::function<void(Result, std::uint8_t*, std::uint32_t)>> cb(
|
||||
reinterpret_cast<std::function<void(Result, std::uint8_t*, std::uint32_t)>*>(
|
||||
callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result), data, dataLength);
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result, std::uint8_t*, std::uint32_t)>> cb{};
|
||||
cb.reset(new std::function<void(Result, std::uint8_t*, std::uint32_t)>(std::move(callback)));
|
||||
internal_->read_async(internal_, const_cast<char*>(name), cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void StorageManager::ReadAsyncPartial(
|
||||
char const* name,
|
||||
std::uint64_t offset,
|
||||
std::uint64_t length,
|
||||
std::function<void(Result, std::uint8_t*, std::uint32_t)> callback)
|
||||
{
|
||||
static auto wrapper =
|
||||
[](void* callbackData, EDiscordResult result, uint8_t* data, uint32_t dataLength) -> void {
|
||||
std::unique_ptr<std::function<void(Result, std::uint8_t*, std::uint32_t)>> cb(
|
||||
reinterpret_cast<std::function<void(Result, std::uint8_t*, std::uint32_t)>*>(
|
||||
callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result), data, dataLength);
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result, std::uint8_t*, std::uint32_t)>> cb{};
|
||||
cb.reset(new std::function<void(Result, std::uint8_t*, std::uint32_t)>(std::move(callback)));
|
||||
internal_->read_async_partial(
|
||||
internal_, const_cast<char*>(name), offset, length, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
Result StorageManager::Write(char const* name, std::uint8_t* data, std::uint32_t dataLength)
|
||||
{
|
||||
auto result = internal_->write(
|
||||
internal_, const_cast<char*>(name), reinterpret_cast<uint8_t*>(data), dataLength);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void StorageManager::WriteAsync(char const* name,
|
||||
std::uint8_t* data,
|
||||
std::uint32_t dataLength,
|
||||
std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->write_async(internal_,
|
||||
const_cast<char*>(name),
|
||||
reinterpret_cast<uint8_t*>(data),
|
||||
dataLength,
|
||||
cb.release(),
|
||||
wrapper);
|
||||
}
|
||||
|
||||
Result StorageManager::Delete(char const* name)
|
||||
{
|
||||
auto result = internal_->delete_(internal_, const_cast<char*>(name));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result StorageManager::Exists(char const* name, bool* exists)
|
||||
{
|
||||
if (!exists) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->exists(internal_, const_cast<char*>(name), reinterpret_cast<bool*>(exists));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void StorageManager::Count(std::int32_t* count)
|
||||
{
|
||||
if (!count) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->count(internal_, reinterpret_cast<int32_t*>(count));
|
||||
}
|
||||
|
||||
Result StorageManager::Stat(char const* name, FileStat* stat)
|
||||
{
|
||||
if (!stat) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->stat(internal_, const_cast<char*>(name), reinterpret_cast<DiscordFileStat*>(stat));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result StorageManager::StatAt(std::int32_t index, FileStat* stat)
|
||||
{
|
||||
if (!stat) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->stat_at(internal_, index, reinterpret_cast<DiscordFileStat*>(stat));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result StorageManager::GetPath(char path[4096])
|
||||
{
|
||||
if (!path) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_path(internal_, reinterpret_cast<DiscordPath*>(path));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,162 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/store_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
class StoreEvents final {
|
||||
public:
|
||||
static void OnEntitlementCreate(void* callbackData, DiscordEntitlement* entitlement)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->StoreManager();
|
||||
module.OnEntitlementCreate(*reinterpret_cast<Entitlement const*>(entitlement));
|
||||
}
|
||||
|
||||
static void OnEntitlementDelete(void* callbackData, DiscordEntitlement* entitlement)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->StoreManager();
|
||||
module.OnEntitlementDelete(*reinterpret_cast<Entitlement const*>(entitlement));
|
||||
}
|
||||
};
|
||||
|
||||
IDiscordStoreEvents StoreManager::events_{
|
||||
&StoreEvents::OnEntitlementCreate,
|
||||
&StoreEvents::OnEntitlementDelete,
|
||||
};
|
||||
|
||||
void StoreManager::FetchSkus(std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->fetch_skus(internal_, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void StoreManager::CountSkus(std::int32_t* count)
|
||||
{
|
||||
if (!count) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->count_skus(internal_, reinterpret_cast<int32_t*>(count));
|
||||
}
|
||||
|
||||
Result StoreManager::GetSku(Snowflake skuId, Sku* sku)
|
||||
{
|
||||
if (!sku) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_sku(internal_, skuId, reinterpret_cast<DiscordSku*>(sku));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result StoreManager::GetSkuAt(std::int32_t index, Sku* sku)
|
||||
{
|
||||
if (!sku) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_sku_at(internal_, index, reinterpret_cast<DiscordSku*>(sku));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void StoreManager::FetchEntitlements(std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->fetch_entitlements(internal_, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
void StoreManager::CountEntitlements(std::int32_t* count)
|
||||
{
|
||||
if (!count) {
|
||||
return;
|
||||
}
|
||||
|
||||
internal_->count_entitlements(internal_, reinterpret_cast<int32_t*>(count));
|
||||
}
|
||||
|
||||
Result StoreManager::GetEntitlement(Snowflake entitlementId, Entitlement* entitlement)
|
||||
{
|
||||
if (!entitlement) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_entitlement(
|
||||
internal_, entitlementId, reinterpret_cast<DiscordEntitlement*>(entitlement));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result StoreManager::GetEntitlementAt(std::int32_t index, Entitlement* entitlement)
|
||||
{
|
||||
if (!entitlement) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_entitlement_at(
|
||||
internal_, index, reinterpret_cast<DiscordEntitlement*>(entitlement));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result StoreManager::HasSkuEntitlement(Snowflake skuId, bool* hasEntitlement)
|
||||
{
|
||||
if (!hasEntitlement) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->has_sku_entitlement(internal_, skuId, reinterpret_cast<bool*>(hasEntitlement));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void StoreManager::StartPurchase(Snowflake skuId, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->start_purchase(internal_, skuId, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,771 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/types.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
void User::SetId(UserId id)
|
||||
{
|
||||
internal_.id = id;
|
||||
}
|
||||
|
||||
UserId User::GetId() const
|
||||
{
|
||||
return internal_.id;
|
||||
}
|
||||
|
||||
void User::SetUsername(char const* username)
|
||||
{
|
||||
strncpy(internal_.username, username, 256);
|
||||
internal_.username[256 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* User::GetUsername() const
|
||||
{
|
||||
return internal_.username;
|
||||
}
|
||||
|
||||
void User::SetDiscriminator(char const* discriminator)
|
||||
{
|
||||
strncpy(internal_.discriminator, discriminator, 8);
|
||||
internal_.discriminator[8 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* User::GetDiscriminator() const
|
||||
{
|
||||
return internal_.discriminator;
|
||||
}
|
||||
|
||||
void User::SetAvatar(char const* avatar)
|
||||
{
|
||||
strncpy(internal_.avatar, avatar, 128);
|
||||
internal_.avatar[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* User::GetAvatar() const
|
||||
{
|
||||
return internal_.avatar;
|
||||
}
|
||||
|
||||
void User::SetBot(bool bot)
|
||||
{
|
||||
internal_.bot = bot;
|
||||
}
|
||||
|
||||
bool User::GetBot() const
|
||||
{
|
||||
return internal_.bot != 0;
|
||||
}
|
||||
|
||||
void OAuth2Token::SetAccessToken(char const* accessToken)
|
||||
{
|
||||
strncpy(internal_.access_token, accessToken, 128);
|
||||
internal_.access_token[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* OAuth2Token::GetAccessToken() const
|
||||
{
|
||||
return internal_.access_token;
|
||||
}
|
||||
|
||||
void OAuth2Token::SetScopes(char const* scopes)
|
||||
{
|
||||
strncpy(internal_.scopes, scopes, 1024);
|
||||
internal_.scopes[1024 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* OAuth2Token::GetScopes() const
|
||||
{
|
||||
return internal_.scopes;
|
||||
}
|
||||
|
||||
void OAuth2Token::SetExpires(Timestamp expires)
|
||||
{
|
||||
internal_.expires = expires;
|
||||
}
|
||||
|
||||
Timestamp OAuth2Token::GetExpires() const
|
||||
{
|
||||
return internal_.expires;
|
||||
}
|
||||
|
||||
void ImageHandle::SetType(ImageType type)
|
||||
{
|
||||
internal_.type = static_cast<EDiscordImageType>(type);
|
||||
}
|
||||
|
||||
ImageType ImageHandle::GetType() const
|
||||
{
|
||||
return static_cast<ImageType>(internal_.type);
|
||||
}
|
||||
|
||||
void ImageHandle::SetId(std::int64_t id)
|
||||
{
|
||||
internal_.id = id;
|
||||
}
|
||||
|
||||
std::int64_t ImageHandle::GetId() const
|
||||
{
|
||||
return internal_.id;
|
||||
}
|
||||
|
||||
void ImageHandle::SetSize(std::uint32_t size)
|
||||
{
|
||||
internal_.size = size;
|
||||
}
|
||||
|
||||
std::uint32_t ImageHandle::GetSize() const
|
||||
{
|
||||
return internal_.size;
|
||||
}
|
||||
|
||||
void ImageDimensions::SetWidth(std::uint32_t width)
|
||||
{
|
||||
internal_.width = width;
|
||||
}
|
||||
|
||||
std::uint32_t ImageDimensions::GetWidth() const
|
||||
{
|
||||
return internal_.width;
|
||||
}
|
||||
|
||||
void ImageDimensions::SetHeight(std::uint32_t height)
|
||||
{
|
||||
internal_.height = height;
|
||||
}
|
||||
|
||||
std::uint32_t ImageDimensions::GetHeight() const
|
||||
{
|
||||
return internal_.height;
|
||||
}
|
||||
|
||||
void ActivityTimestamps::SetStart(Timestamp start)
|
||||
{
|
||||
internal_.start = start;
|
||||
}
|
||||
|
||||
Timestamp ActivityTimestamps::GetStart() const
|
||||
{
|
||||
return internal_.start;
|
||||
}
|
||||
|
||||
void ActivityTimestamps::SetEnd(Timestamp end)
|
||||
{
|
||||
internal_.end = end;
|
||||
}
|
||||
|
||||
Timestamp ActivityTimestamps::GetEnd() const
|
||||
{
|
||||
return internal_.end;
|
||||
}
|
||||
|
||||
void ActivityAssets::SetLargeImage(char const* largeImage)
|
||||
{
|
||||
strncpy(internal_.large_image, largeImage, 128);
|
||||
internal_.large_image[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* ActivityAssets::GetLargeImage() const
|
||||
{
|
||||
return internal_.large_image;
|
||||
}
|
||||
|
||||
void ActivityAssets::SetLargeText(char const* largeText)
|
||||
{
|
||||
strncpy(internal_.large_text, largeText, 128);
|
||||
internal_.large_text[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* ActivityAssets::GetLargeText() const
|
||||
{
|
||||
return internal_.large_text;
|
||||
}
|
||||
|
||||
void ActivityAssets::SetSmallImage(char const* smallImage)
|
||||
{
|
||||
strncpy(internal_.small_image, smallImage, 128);
|
||||
internal_.small_image[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* ActivityAssets::GetSmallImage() const
|
||||
{
|
||||
return internal_.small_image;
|
||||
}
|
||||
|
||||
void ActivityAssets::SetSmallText(char const* smallText)
|
||||
{
|
||||
strncpy(internal_.small_text, smallText, 128);
|
||||
internal_.small_text[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* ActivityAssets::GetSmallText() const
|
||||
{
|
||||
return internal_.small_text;
|
||||
}
|
||||
|
||||
void PartySize::SetCurrentSize(std::int32_t currentSize)
|
||||
{
|
||||
internal_.current_size = currentSize;
|
||||
}
|
||||
|
||||
std::int32_t PartySize::GetCurrentSize() const
|
||||
{
|
||||
return internal_.current_size;
|
||||
}
|
||||
|
||||
void PartySize::SetMaxSize(std::int32_t maxSize)
|
||||
{
|
||||
internal_.max_size = maxSize;
|
||||
}
|
||||
|
||||
std::int32_t PartySize::GetMaxSize() const
|
||||
{
|
||||
return internal_.max_size;
|
||||
}
|
||||
|
||||
void ActivityParty::SetId(char const* id)
|
||||
{
|
||||
strncpy(internal_.id, id, 128);
|
||||
internal_.id[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* ActivityParty::GetId() const
|
||||
{
|
||||
return internal_.id;
|
||||
}
|
||||
|
||||
PartySize& ActivityParty::GetSize()
|
||||
{
|
||||
return reinterpret_cast<PartySize&>(internal_.size);
|
||||
}
|
||||
|
||||
PartySize const& ActivityParty::GetSize() const
|
||||
{
|
||||
return reinterpret_cast<PartySize const&>(internal_.size);
|
||||
}
|
||||
|
||||
void ActivitySecrets::SetMatch(char const* match)
|
||||
{
|
||||
strncpy(internal_.match, match, 128);
|
||||
internal_.match[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* ActivitySecrets::GetMatch() const
|
||||
{
|
||||
return internal_.match;
|
||||
}
|
||||
|
||||
void ActivitySecrets::SetJoin(char const* join)
|
||||
{
|
||||
strncpy(internal_.join, join, 128);
|
||||
internal_.join[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* ActivitySecrets::GetJoin() const
|
||||
{
|
||||
return internal_.join;
|
||||
}
|
||||
|
||||
void ActivitySecrets::SetSpectate(char const* spectate)
|
||||
{
|
||||
strncpy(internal_.spectate, spectate, 128);
|
||||
internal_.spectate[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* ActivitySecrets::GetSpectate() const
|
||||
{
|
||||
return internal_.spectate;
|
||||
}
|
||||
|
||||
void Activity::SetType(ActivityType type)
|
||||
{
|
||||
internal_.type = static_cast<EDiscordActivityType>(type);
|
||||
}
|
||||
|
||||
ActivityType Activity::GetType() const
|
||||
{
|
||||
return static_cast<ActivityType>(internal_.type);
|
||||
}
|
||||
|
||||
void Activity::SetApplicationId(std::int64_t applicationId)
|
||||
{
|
||||
internal_.application_id = applicationId;
|
||||
}
|
||||
|
||||
std::int64_t Activity::GetApplicationId() const
|
||||
{
|
||||
return internal_.application_id;
|
||||
}
|
||||
|
||||
void Activity::SetName(char const* name)
|
||||
{
|
||||
strncpy(internal_.name, name, 128);
|
||||
internal_.name[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* Activity::GetName() const
|
||||
{
|
||||
return internal_.name;
|
||||
}
|
||||
|
||||
void Activity::SetState(char const* state)
|
||||
{
|
||||
strncpy(internal_.state, state, 128);
|
||||
internal_.state[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* Activity::GetState() const
|
||||
{
|
||||
return internal_.state;
|
||||
}
|
||||
|
||||
void Activity::SetDetails(char const* details)
|
||||
{
|
||||
strncpy(internal_.details, details, 128);
|
||||
internal_.details[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* Activity::GetDetails() const
|
||||
{
|
||||
return internal_.details;
|
||||
}
|
||||
|
||||
ActivityTimestamps& Activity::GetTimestamps()
|
||||
{
|
||||
return reinterpret_cast<ActivityTimestamps&>(internal_.timestamps);
|
||||
}
|
||||
|
||||
ActivityTimestamps const& Activity::GetTimestamps() const
|
||||
{
|
||||
return reinterpret_cast<ActivityTimestamps const&>(internal_.timestamps);
|
||||
}
|
||||
|
||||
ActivityAssets& Activity::GetAssets()
|
||||
{
|
||||
return reinterpret_cast<ActivityAssets&>(internal_.assets);
|
||||
}
|
||||
|
||||
ActivityAssets const& Activity::GetAssets() const
|
||||
{
|
||||
return reinterpret_cast<ActivityAssets const&>(internal_.assets);
|
||||
}
|
||||
|
||||
ActivityParty& Activity::GetParty()
|
||||
{
|
||||
return reinterpret_cast<ActivityParty&>(internal_.party);
|
||||
}
|
||||
|
||||
ActivityParty const& Activity::GetParty() const
|
||||
{
|
||||
return reinterpret_cast<ActivityParty const&>(internal_.party);
|
||||
}
|
||||
|
||||
ActivitySecrets& Activity::GetSecrets()
|
||||
{
|
||||
return reinterpret_cast<ActivitySecrets&>(internal_.secrets);
|
||||
}
|
||||
|
||||
ActivitySecrets const& Activity::GetSecrets() const
|
||||
{
|
||||
return reinterpret_cast<ActivitySecrets const&>(internal_.secrets);
|
||||
}
|
||||
|
||||
void Activity::SetInstance(bool instance)
|
||||
{
|
||||
internal_.instance = instance;
|
||||
}
|
||||
|
||||
bool Activity::GetInstance() const
|
||||
{
|
||||
return internal_.instance != 0;
|
||||
}
|
||||
|
||||
void Presence::SetStatus(Status status)
|
||||
{
|
||||
internal_.status = static_cast<EDiscordStatus>(status);
|
||||
}
|
||||
|
||||
Status Presence::GetStatus() const
|
||||
{
|
||||
return static_cast<Status>(internal_.status);
|
||||
}
|
||||
|
||||
Activity& Presence::GetActivity()
|
||||
{
|
||||
return reinterpret_cast<Activity&>(internal_.activity);
|
||||
}
|
||||
|
||||
Activity const& Presence::GetActivity() const
|
||||
{
|
||||
return reinterpret_cast<Activity const&>(internal_.activity);
|
||||
}
|
||||
|
||||
void Relationship::SetType(RelationshipType type)
|
||||
{
|
||||
internal_.type = static_cast<EDiscordRelationshipType>(type);
|
||||
}
|
||||
|
||||
RelationshipType Relationship::GetType() const
|
||||
{
|
||||
return static_cast<RelationshipType>(internal_.type);
|
||||
}
|
||||
|
||||
User& Relationship::GetUser()
|
||||
{
|
||||
return reinterpret_cast<User&>(internal_.user);
|
||||
}
|
||||
|
||||
User const& Relationship::GetUser() const
|
||||
{
|
||||
return reinterpret_cast<User const&>(internal_.user);
|
||||
}
|
||||
|
||||
Presence& Relationship::GetPresence()
|
||||
{
|
||||
return reinterpret_cast<Presence&>(internal_.presence);
|
||||
}
|
||||
|
||||
Presence const& Relationship::GetPresence() const
|
||||
{
|
||||
return reinterpret_cast<Presence const&>(internal_.presence);
|
||||
}
|
||||
|
||||
void Lobby::SetId(LobbyId id)
|
||||
{
|
||||
internal_.id = id;
|
||||
}
|
||||
|
||||
LobbyId Lobby::GetId() const
|
||||
{
|
||||
return internal_.id;
|
||||
}
|
||||
|
||||
void Lobby::SetType(LobbyType type)
|
||||
{
|
||||
internal_.type = static_cast<EDiscordLobbyType>(type);
|
||||
}
|
||||
|
||||
LobbyType Lobby::GetType() const
|
||||
{
|
||||
return static_cast<LobbyType>(internal_.type);
|
||||
}
|
||||
|
||||
void Lobby::SetOwnerId(UserId ownerId)
|
||||
{
|
||||
internal_.owner_id = ownerId;
|
||||
}
|
||||
|
||||
UserId Lobby::GetOwnerId() const
|
||||
{
|
||||
return internal_.owner_id;
|
||||
}
|
||||
|
||||
void Lobby::SetSecret(LobbySecret secret)
|
||||
{
|
||||
strncpy(internal_.secret, secret, 128);
|
||||
internal_.secret[128 - 1] = '\0';
|
||||
}
|
||||
|
||||
LobbySecret Lobby::GetSecret() const
|
||||
{
|
||||
return internal_.secret;
|
||||
}
|
||||
|
||||
void Lobby::SetCapacity(std::uint32_t capacity)
|
||||
{
|
||||
internal_.capacity = capacity;
|
||||
}
|
||||
|
||||
std::uint32_t Lobby::GetCapacity() const
|
||||
{
|
||||
return internal_.capacity;
|
||||
}
|
||||
|
||||
void Lobby::SetLocked(bool locked)
|
||||
{
|
||||
internal_.locked = locked;
|
||||
}
|
||||
|
||||
bool Lobby::GetLocked() const
|
||||
{
|
||||
return internal_.locked != 0;
|
||||
}
|
||||
|
||||
void FileStat::SetFilename(char const* filename)
|
||||
{
|
||||
strncpy(internal_.filename, filename, 260);
|
||||
internal_.filename[260 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* FileStat::GetFilename() const
|
||||
{
|
||||
return internal_.filename;
|
||||
}
|
||||
|
||||
void FileStat::SetSize(std::uint64_t size)
|
||||
{
|
||||
internal_.size = size;
|
||||
}
|
||||
|
||||
std::uint64_t FileStat::GetSize() const
|
||||
{
|
||||
return internal_.size;
|
||||
}
|
||||
|
||||
void FileStat::SetLastModified(std::uint64_t lastModified)
|
||||
{
|
||||
internal_.last_modified = lastModified;
|
||||
}
|
||||
|
||||
std::uint64_t FileStat::GetLastModified() const
|
||||
{
|
||||
return internal_.last_modified;
|
||||
}
|
||||
|
||||
void Entitlement::SetId(Snowflake id)
|
||||
{
|
||||
internal_.id = id;
|
||||
}
|
||||
|
||||
Snowflake Entitlement::GetId() const
|
||||
{
|
||||
return internal_.id;
|
||||
}
|
||||
|
||||
void Entitlement::SetType(EntitlementType type)
|
||||
{
|
||||
internal_.type = static_cast<EDiscordEntitlementType>(type);
|
||||
}
|
||||
|
||||
EntitlementType Entitlement::GetType() const
|
||||
{
|
||||
return static_cast<EntitlementType>(internal_.type);
|
||||
}
|
||||
|
||||
void Entitlement::SetSkuId(Snowflake skuId)
|
||||
{
|
||||
internal_.sku_id = skuId;
|
||||
}
|
||||
|
||||
Snowflake Entitlement::GetSkuId() const
|
||||
{
|
||||
return internal_.sku_id;
|
||||
}
|
||||
|
||||
void SkuPrice::SetAmount(std::uint32_t amount)
|
||||
{
|
||||
internal_.amount = amount;
|
||||
}
|
||||
|
||||
std::uint32_t SkuPrice::GetAmount() const
|
||||
{
|
||||
return internal_.amount;
|
||||
}
|
||||
|
||||
void SkuPrice::SetCurrency(char const* currency)
|
||||
{
|
||||
strncpy(internal_.currency, currency, 16);
|
||||
internal_.currency[16 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* SkuPrice::GetCurrency() const
|
||||
{
|
||||
return internal_.currency;
|
||||
}
|
||||
|
||||
void Sku::SetId(Snowflake id)
|
||||
{
|
||||
internal_.id = id;
|
||||
}
|
||||
|
||||
Snowflake Sku::GetId() const
|
||||
{
|
||||
return internal_.id;
|
||||
}
|
||||
|
||||
void Sku::SetType(SkuType type)
|
||||
{
|
||||
internal_.type = static_cast<EDiscordSkuType>(type);
|
||||
}
|
||||
|
||||
SkuType Sku::GetType() const
|
||||
{
|
||||
return static_cast<SkuType>(internal_.type);
|
||||
}
|
||||
|
||||
void Sku::SetName(char const* name)
|
||||
{
|
||||
strncpy(internal_.name, name, 256);
|
||||
internal_.name[256 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* Sku::GetName() const
|
||||
{
|
||||
return internal_.name;
|
||||
}
|
||||
|
||||
SkuPrice& Sku::GetPrice()
|
||||
{
|
||||
return reinterpret_cast<SkuPrice&>(internal_.price);
|
||||
}
|
||||
|
||||
SkuPrice const& Sku::GetPrice() const
|
||||
{
|
||||
return reinterpret_cast<SkuPrice const&>(internal_.price);
|
||||
}
|
||||
|
||||
void InputMode::SetType(InputModeType type)
|
||||
{
|
||||
internal_.type = static_cast<EDiscordInputModeType>(type);
|
||||
}
|
||||
|
||||
InputModeType InputMode::GetType() const
|
||||
{
|
||||
return static_cast<InputModeType>(internal_.type);
|
||||
}
|
||||
|
||||
void InputMode::SetShortcut(char const* shortcut)
|
||||
{
|
||||
strncpy(internal_.shortcut, shortcut, 256);
|
||||
internal_.shortcut[256 - 1] = '\0';
|
||||
}
|
||||
|
||||
char const* InputMode::GetShortcut() const
|
||||
{
|
||||
return internal_.shortcut;
|
||||
}
|
||||
|
||||
void UserAchievement::SetUserId(Snowflake userId)
|
||||
{
|
||||
internal_.user_id = userId;
|
||||
}
|
||||
|
||||
Snowflake UserAchievement::GetUserId() const
|
||||
{
|
||||
return internal_.user_id;
|
||||
}
|
||||
|
||||
void UserAchievement::SetAchievementId(Snowflake achievementId)
|
||||
{
|
||||
internal_.achievement_id = achievementId;
|
||||
}
|
||||
|
||||
Snowflake UserAchievement::GetAchievementId() const
|
||||
{
|
||||
return internal_.achievement_id;
|
||||
}
|
||||
|
||||
void UserAchievement::SetPercentComplete(std::uint8_t percentComplete)
|
||||
{
|
||||
internal_.percent_complete = percentComplete;
|
||||
}
|
||||
|
||||
std::uint8_t UserAchievement::GetPercentComplete() const
|
||||
{
|
||||
return internal_.percent_complete;
|
||||
}
|
||||
|
||||
void UserAchievement::SetUnlockedAt(DateTime unlockedAt)
|
||||
{
|
||||
strncpy(internal_.unlocked_at, unlockedAt, 64);
|
||||
internal_.unlocked_at[64 - 1] = '\0';
|
||||
}
|
||||
|
||||
DateTime UserAchievement::GetUnlockedAt() const
|
||||
{
|
||||
return internal_.unlocked_at;
|
||||
}
|
||||
|
||||
Result LobbyTransaction::SetType(LobbyType type)
|
||||
{
|
||||
auto result = internal_->set_type(internal_, static_cast<EDiscordLobbyType>(type));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyTransaction::SetOwner(UserId ownerId)
|
||||
{
|
||||
auto result = internal_->set_owner(internal_, ownerId);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyTransaction::SetCapacity(std::uint32_t capacity)
|
||||
{
|
||||
auto result = internal_->set_capacity(internal_, capacity);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyTransaction::SetMetadata(MetadataKey key, MetadataValue value)
|
||||
{
|
||||
auto result =
|
||||
internal_->set_metadata(internal_, const_cast<char*>(key), const_cast<char*>(value));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyTransaction::DeleteMetadata(MetadataKey key)
|
||||
{
|
||||
auto result = internal_->delete_metadata(internal_, const_cast<char*>(key));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyTransaction::SetLocked(bool locked)
|
||||
{
|
||||
auto result = internal_->set_locked(internal_, (locked ? 1 : 0));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyMemberTransaction::SetMetadata(MetadataKey key, MetadataValue value)
|
||||
{
|
||||
auto result =
|
||||
internal_->set_metadata(internal_, const_cast<char*>(key), const_cast<char*>(value));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbyMemberTransaction::DeleteMetadata(MetadataKey key)
|
||||
{
|
||||
auto result = internal_->delete_metadata(internal_, const_cast<char*>(key));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbySearchQuery::Filter(MetadataKey key,
|
||||
LobbySearchComparison comparison,
|
||||
LobbySearchCast cast,
|
||||
MetadataValue value)
|
||||
{
|
||||
auto result = internal_->filter(internal_,
|
||||
const_cast<char*>(key),
|
||||
static_cast<EDiscordLobbySearchComparison>(comparison),
|
||||
static_cast<EDiscordLobbySearchCast>(cast),
|
||||
const_cast<char*>(value));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbySearchQuery::Sort(MetadataKey key, LobbySearchCast cast, MetadataValue value)
|
||||
{
|
||||
auto result = internal_->sort(internal_,
|
||||
const_cast<char*>(key),
|
||||
static_cast<EDiscordLobbySearchCast>(cast),
|
||||
const_cast<char*>(value));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbySearchQuery::Limit(std::uint32_t limit)
|
||||
{
|
||||
auto result = internal_->limit(internal_, limit);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result LobbySearchQuery::Distance(LobbySearchDistance distance)
|
||||
{
|
||||
auto result =
|
||||
internal_->distance(internal_, static_cast<EDiscordLobbySearchDistance>(distance));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,82 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/user_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
class UserEvents final {
|
||||
public:
|
||||
static void OnCurrentUserUpdate(void* callbackData)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->UserManager();
|
||||
module.OnCurrentUserUpdate();
|
||||
}
|
||||
};
|
||||
|
||||
IDiscordUserEvents UserManager::events_{
|
||||
&UserEvents::OnCurrentUserUpdate,
|
||||
};
|
||||
|
||||
Result UserManager::GetCurrentUser(User* currentUser)
|
||||
{
|
||||
if (!currentUser) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get_current_user(internal_, reinterpret_cast<DiscordUser*>(currentUser));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void UserManager::GetUser(UserId userId, std::function<void(Result, User const&)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result, DiscordUser* user) -> void {
|
||||
std::unique_ptr<std::function<void(Result, User const&)>> cb(
|
||||
reinterpret_cast<std::function<void(Result, User const&)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result), *reinterpret_cast<User const*>(user));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result, User const&)>> cb{};
|
||||
cb.reset(new std::function<void(Result, User const&)>(std::move(callback)));
|
||||
internal_->get_user(internal_, userId, cb.release(), wrapper);
|
||||
}
|
||||
|
||||
Result UserManager::GetCurrentUserPremiumType(PremiumType* premiumType)
|
||||
{
|
||||
if (!premiumType) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->get_current_user_premium_type(
|
||||
internal_, reinterpret_cast<EDiscordPremiumType*>(premiumType));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result UserManager::CurrentUserHasFlag(UserFlag flag, bool* hasFlag)
|
||||
{
|
||||
if (!hasFlag) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->current_user_has_flag(
|
||||
internal_, static_cast<EDiscordUserFlag>(flag), reinterpret_cast<bool*>(hasFlag));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -1,126 +0,0 @@
|
||||
#if defined(UF_USE_DISCORD)
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <discord/voice_manager.h>
|
||||
|
||||
#include <discord/core.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace discord {
|
||||
|
||||
class VoiceEvents final {
|
||||
public:
|
||||
static void OnSettingsUpdate(void* callbackData)
|
||||
{
|
||||
auto* core = reinterpret_cast<Core*>(callbackData);
|
||||
if (!core) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& module = core->VoiceManager();
|
||||
module.OnSettingsUpdate();
|
||||
}
|
||||
};
|
||||
|
||||
IDiscordVoiceEvents VoiceManager::events_{
|
||||
&VoiceEvents::OnSettingsUpdate,
|
||||
};
|
||||
|
||||
Result VoiceManager::GetInputMode(InputMode* inputMode)
|
||||
{
|
||||
if (!inputMode) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get_input_mode(internal_, reinterpret_cast<DiscordInputMode*>(inputMode));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
void VoiceManager::SetInputMode(InputMode inputMode, std::function<void(Result)> callback)
|
||||
{
|
||||
static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
|
||||
std::unique_ptr<std::function<void(Result)>> cb(
|
||||
reinterpret_cast<std::function<void(Result)>*>(callbackData));
|
||||
if (!cb || !(*cb)) {
|
||||
return;
|
||||
}
|
||||
(*cb)(static_cast<Result>(result));
|
||||
};
|
||||
std::unique_ptr<std::function<void(Result)>> cb{};
|
||||
cb.reset(new std::function<void(Result)>(std::move(callback)));
|
||||
internal_->set_input_mode(
|
||||
internal_, *reinterpret_cast<DiscordInputMode const*>(&inputMode), cb.release(), wrapper);
|
||||
}
|
||||
|
||||
Result VoiceManager::IsSelfMute(bool* mute)
|
||||
{
|
||||
if (!mute) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->is_self_mute(internal_, reinterpret_cast<bool*>(mute));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result VoiceManager::SetSelfMute(bool mute)
|
||||
{
|
||||
auto result = internal_->set_self_mute(internal_, (mute ? 1 : 0));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result VoiceManager::IsSelfDeaf(bool* deaf)
|
||||
{
|
||||
if (!deaf) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->is_self_deaf(internal_, reinterpret_cast<bool*>(deaf));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result VoiceManager::SetSelfDeaf(bool deaf)
|
||||
{
|
||||
auto result = internal_->set_self_deaf(internal_, (deaf ? 1 : 0));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result VoiceManager::IsLocalMute(Snowflake userId, bool* mute)
|
||||
{
|
||||
if (!mute) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result = internal_->is_local_mute(internal_, userId, reinterpret_cast<bool*>(mute));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result VoiceManager::SetLocalMute(Snowflake userId, bool mute)
|
||||
{
|
||||
auto result = internal_->set_local_mute(internal_, userId, (mute ? 1 : 0));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result VoiceManager::GetLocalVolume(Snowflake userId, std::uint8_t* volume)
|
||||
{
|
||||
if (!volume) {
|
||||
return Result::InternalError;
|
||||
}
|
||||
|
||||
auto result =
|
||||
internal_->get_local_volume(internal_, userId, reinterpret_cast<uint8_t*>(volume));
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
Result VoiceManager::SetLocalVolume(Snowflake userId, std::uint8_t volume)
|
||||
{
|
||||
auto result = internal_->set_local_volume(internal_, userId, volume);
|
||||
return static_cast<Result>(result);
|
||||
}
|
||||
|
||||
} // namespace discord
|
||||
#endif
|
||||
@ -540,10 +540,12 @@ pod::Graph ext::gltf::load( const uf::stl::string& filename, const uf::Serialize
|
||||
#endif
|
||||
|
||||
if ( graph.metadata["exporter"]["enabled"].as<bool>() ) {
|
||||
uf::graph::save( graph, filename );
|
||||
// disable baking, doesn't output right if baking from a gltf imported model
|
||||
graph.metadata["baking"]["enabled"] = false;
|
||||
// disable lightmap loading, 99.999% of the time a previously baked lightmap will not work due to changing STs
|
||||
graph.name = uf::graph::save( graph, filename );
|
||||
|
||||
// disable baking, doesn't output right if baking from a gltf imported model
|
||||
// graph.metadata["baking"]["enabled"] = false;
|
||||
|
||||
// disable lightmap loading, 99.999% of the time a previously baked lightmap will not work due to changing STs
|
||||
graph.metadata["lightmap"] = false;
|
||||
}
|
||||
return graph;
|
||||
|
||||
@ -2,24 +2,36 @@
|
||||
#include <uf/utils/io/iostream.h>
|
||||
#include <iomanip>
|
||||
|
||||
uf::stl::string ext::json::PREFERRED_COMPRESSION = "";
|
||||
uf::stl::string ext::json::PREFERRED_ENCODING = "json";
|
||||
|
||||
ext::json::Value& ext::json::Value::operator=( const uf::Serializer& json ) {
|
||||
return *this = (const ext::json::Value&) json;
|
||||
}
|
||||
|
||||
ext::json::Value& ext::json::Value::operator=( const ext::json::Value& json ) {
|
||||
ext::json::base_value::operator=( (const ext::json::base_value&) json );
|
||||
return *this;
|
||||
}
|
||||
|
||||
ext::json::Value& ext::json::Value::emplace_back( const ext::json::Value& json ) {
|
||||
return (ext::json::Value&) ext::json::base_value::emplace_back( (const ext::json::base_value&) json );
|
||||
}
|
||||
ext::json::Value& ext::json::Value::emplace_back( const uf::Serializer& json ) {
|
||||
return (ext::json::Value&) ext::json::base_value::emplace_back( (const ext::json::base_value&) json );
|
||||
}
|
||||
|
||||
ext::json::Value& ext::json::reserve( ext::json::Value& value, size_t size ) {
|
||||
if ( !ext::json::isArray( value ) ) value = ext::json::array();
|
||||
value.reserve(size);
|
||||
return value;
|
||||
}
|
||||
|
||||
#if UF_JSON_USE_NLOHMANN
|
||||
ext::json::Value& ext::json::Value::reserve( size_t n ) {
|
||||
auto* ptr = this->get_ptr<ext::json::base_value::array_t*>();
|
||||
if ( ptr ) ptr->reserve(n);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ext::json::forEach( ext::json::Value& json, const std::function<void(ext::json::Value&)>& function ) {
|
||||
// UF_ASSERT_SAFE( ext::json::isArray(json) || ext::json::isObject(json) );
|
||||
@ -111,7 +123,6 @@ void ext::json::forEach( const ext::json::Value& json, const std::function<void(
|
||||
}
|
||||
}
|
||||
|
||||
#if UF_JSON_USE_NLOHMANN
|
||||
uf::stl::vector<uf::stl::string> ext::json::keys( const ext::json::Value& v ) {
|
||||
uf::stl::vector<uf::stl::string> keys;
|
||||
if ( !ext::json::isObject( v ) ) return keys;
|
||||
@ -120,9 +131,6 @@ uf::stl::vector<uf::stl::string> ext::json::keys( const ext::json::Value& v ) {
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
#elif UF_JSON_USE_RAPIDJSON
|
||||
rapidjson::Document::AllocatorType ext::json::allocator;
|
||||
#endif
|
||||
|
||||
ext::json::Value ext::json::reencode( const ext::json::Value& _x, const EncodingSettings& settings ) {
|
||||
if ( settings.precision == 0 ) return _x;
|
||||
@ -150,61 +158,8 @@ ext::json::Value& ext::json::reencode( ext::json::Value& x, const EncodingSettin
|
||||
return x;
|
||||
}
|
||||
|
||||
uf::stl::string ext::json::PREFERRED_COMPRESSION = "gz";
|
||||
uf::stl::string ext::json::PREFERRED_ENCODING = "bson";
|
||||
|
||||
uf::stl::string ext::json::encode( const ext::json::Value& json, bool pretty ) {
|
||||
return ext::json::encode( json, ext::json::EncodingSettings{ .pretty = true } );
|
||||
}
|
||||
uf::stl::string ext::json::encode( const ext::json::Value& _json, const ext::json::EncodingSettings& settings ) {
|
||||
ext::json::Value json = ext::json::reencode( _json, settings );
|
||||
#if UF_JSON_USE_NLOHMANN
|
||||
// emit raw json
|
||||
if ( settings.encoding == "" || settings.encoding == "json" ) {
|
||||
return settings.pretty ? json.dump(1, '\t') : json.dump();
|
||||
}
|
||||
// emit bson
|
||||
if ( settings.encoding == "bson" ) {
|
||||
auto buffer = nlohmann::json::to_bson( static_cast<ext::json::base_value>(json) );
|
||||
return uf::stl::string( buffer.begin(), buffer.end() );
|
||||
}
|
||||
// emit cbor
|
||||
if ( settings.encoding == "cbor" ) {
|
||||
auto buffer = nlohmann::json::to_cbor( static_cast<ext::json::base_value>(json) );
|
||||
return uf::stl::string( buffer.begin(), buffer.end() );
|
||||
}
|
||||
// should probably default to json, not my problem
|
||||
UF_MSG_ERROR("invalid encoding requested: " << settings.encoding);
|
||||
return "";
|
||||
#elif UF_JSON_USE_LUA
|
||||
return ext::lua::state["json"]["encode"]( _json );
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UF_USE_LUA
|
||||
uf::stl::string ext::json::encode( const sol::table& table ) {
|
||||
return ext::lua::state["json"]["encode"]( table );
|
||||
}
|
||||
#endif
|
||||
ext::json::Value& ext::json::decode( ext::json::Value& json, const uf::stl::string& str, const DecodingSettings& settings ) {
|
||||
#if UF_JSON_USE_NLOHMANN
|
||||
#if !UF_NO_EXCEPTIONS
|
||||
bool exceptions = true;
|
||||
try {
|
||||
#endif
|
||||
if ( settings.encoding == "" || settings.encoding == "json" )
|
||||
json = nlohmann::json::parse(str, nullptr, exceptions, true);
|
||||
else if ( settings.encoding == "bson" )
|
||||
json = nlohmann::json::from_bson(str, exceptions, true);
|
||||
else if ( settings.encoding == "cbor" )
|
||||
json = nlohmann::json::from_cbor(str, exceptions, true);
|
||||
#if !UF_NO_EXCEPTIONS
|
||||
} catch ( nlohmann::json::parse_error& e ) {
|
||||
UF_MSG_ERROR("JSON error: " << e.what() << "\tAttempted to parse: " << str)
|
||||
}
|
||||
#endif
|
||||
#elif UF_JSON_USE_LUA
|
||||
json = ext::lua::state["json"]["decode"]( str );
|
||||
#endif
|
||||
return json;
|
||||
}
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user