WIP
This commit is contained in:
parent
c6a88ac4ce
commit
cb6b59ac41
@ -81,7 +81,6 @@ dofile(__buildat_get_path("share").."/client/api.lua")
|
|||||||
dofile(__buildat_get_path("share").."/client/packet.lua")
|
dofile(__buildat_get_path("share").."/client/packet.lua")
|
||||||
dofile(__buildat_get_path("share").."/client/extensions.lua")
|
dofile(__buildat_get_path("share").."/client/extensions.lua")
|
||||||
dofile(__buildat_get_path("share").."/client/sandbox.lua")
|
dofile(__buildat_get_path("share").."/client/sandbox.lua")
|
||||||
dofile(__buildat_get_path("share").."/client/misc.lua")
|
|
||||||
|
|
||||||
local test = require("buildat/extension/test")
|
local test = require("buildat/extension/test")
|
||||||
test.f()
|
test.f()
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
-- Buildat: client/misc.lua
|
|
||||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
-- Copyright 2014 Perttu Ahola <celeron55@gmail.com>
|
|
||||||
local log = buildat.Logger("__client/misc")
|
|
||||||
|
|
||||||
-- Replicated scene from the server
|
|
||||||
__buildat_sync_scene = nil
|
|
||||||
|
|
||||||
-- Called by the client application
|
|
||||||
function __buildat_set_sync_scene(scene)
|
|
||||||
assert(scene)
|
|
||||||
log:verbose("__buildat_set_sync_scene(): ok")
|
|
||||||
__buildat_sync_scene = scene
|
|
||||||
end
|
|
||||||
|
|
||||||
-- vim: set noet ts=4 sw=4:
|
|
@ -7,8 +7,9 @@ local magic = unsafe_magic.safe
|
|||||||
local dump = buildat.dump
|
local dump = buildat.dump
|
||||||
local M = {safe = {}}
|
local M = {safe = {}}
|
||||||
|
|
||||||
|
-- TODO
|
||||||
--M.safe.scene = getmetatable(magic.Scene).wrap(__buildat_sync_scene)
|
--M.safe.scene = getmetatable(magic.Scene).wrap(__buildat_sync_scene)
|
||||||
M.safe.scene = __buildat_sync_scene
|
--M.safe.scene = __buildat_sync_scene
|
||||||
--__buildat_sandbox_debug_check_value(M.safe.scene)
|
--__buildat_sandbox_debug_check_value(M.safe.scene)
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -254,14 +254,32 @@ function M.define(dst, util)
|
|||||||
return util.wrap_instance("Viewport", Viewport:new(scene, camera_component))
|
return util.wrap_instance("Viewport", Viewport:new(scene, camera_component))
|
||||||
end),
|
end),
|
||||||
},
|
},
|
||||||
|
instance = {
|
||||||
|
GetScene = util.wrap_function({"Viewport"},
|
||||||
|
function(self)
|
||||||
|
return util.wrap_instance("Scene", self:GetScene())
|
||||||
|
end
|
||||||
|
),
|
||||||
|
GetCamera = util.wrap_function({"Viewport"},
|
||||||
|
function(self)
|
||||||
|
return util.wrap_instance("Camera", self:GetCamera())
|
||||||
|
end
|
||||||
|
),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
util.wc("Renderer", {
|
util.wc("Renderer", {
|
||||||
instance = {
|
instance = {
|
||||||
SetViewport = util.wrap_function({"Renderer", "number", "Viewport"},
|
SetViewport = util.wrap_function({"Renderer", "number", "Viewport"},
|
||||||
function(self, index, viewport)
|
function(self, index, viewport)
|
||||||
self:SetViewport(index, viewport)
|
self:SetViewport(index, viewport)
|
||||||
end),
|
end
|
||||||
|
),
|
||||||
|
GetViewport = util.wrap_function({"Renderer", "number"},
|
||||||
|
function(self, index)
|
||||||
|
return util.wrap_instance("Viewport", self:GetViewport(index))
|
||||||
|
end
|
||||||
|
),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -6,15 +6,15 @@ local log = buildat.Logger("minigame")
|
|||||||
local dump = buildat.dump
|
local dump = buildat.dump
|
||||||
local cereal = require("buildat/extension/cereal")
|
local cereal = require("buildat/extension/cereal")
|
||||||
local magic = require("buildat/extension/urho3d")
|
local magic = require("buildat/extension/urho3d")
|
||||||
local entitysync = require("buildat/extension/entitysync")
|
|
||||||
|
|
||||||
-- 3D things
|
-- 3D things
|
||||||
|
|
||||||
--scene = magic.Scene()
|
-- Viewport 0 is created in C++. It is set to view the network-synchronized
|
||||||
local scene = entitysync.scene
|
-- scene with one camera.
|
||||||
local plane_node = scene:CreateChild("Plane")
|
-- NOTE: This won't work this way in the future.
|
||||||
--[[
|
local viewport = magic.renderer:GetViewport(0)
|
||||||
scene:CreateComponent("Octree")
|
local scene = viewport:GetScene()
|
||||||
|
local camera = viewport:GetCamera()
|
||||||
|
|
||||||
-- Note that naming the scene nodes is optional
|
-- Note that naming the scene nodes is optional
|
||||||
local plane_node = scene:CreateChild("Plane")
|
local plane_node = scene:CreateChild("Plane")
|
||||||
@ -40,16 +40,6 @@ light = light_node:CreateComponent("Light")
|
|||||||
light.lightType = magic.LIGHT_DIRECTIONAL
|
light.lightType = magic.LIGHT_DIRECTIONAL
|
||||||
light.brightness = 0.2
|
light.brightness = 0.2
|
||||||
|
|
||||||
-- Add a camera so we can look at the scene
|
|
||||||
local camera_node = scene:CreateChild("Camera")
|
|
||||||
camera_node:CreateComponent("Camera")
|
|
||||||
camera_node.position = magic.Vector3(7.0, 7.0, 7.0)
|
|
||||||
--camera_node.rotation = Quaternion(0, 0, 0.0)
|
|
||||||
camera_node:LookAt(magic.Vector3(0, 1, 0))
|
|
||||||
-- And this thing so the camera is shown on the screen
|
|
||||||
local viewport = magic.Viewport:new(scene, camera_node:GetComponent("Camera"))
|
|
||||||
magic.renderer:SetViewport(0, viewport)
|
|
||||||
|
|
||||||
-- Add some text
|
-- Add some text
|
||||||
local title_text = magic.ui.root:CreateChild("Text")
|
local title_text = magic.ui.root:CreateChild("Text")
|
||||||
title_text:SetText("minigame/init.lua")
|
title_text:SetText("minigame/init.lua")
|
||||||
|
@ -25,6 +25,10 @@
|
|||||||
#include <XMLFile.h>
|
#include <XMLFile.h>
|
||||||
#include <Scene.h>
|
#include <Scene.h>
|
||||||
#include <LuaFunction.h>
|
#include <LuaFunction.h>
|
||||||
|
#include <Viewport.h>
|
||||||
|
#include <Camera.h>
|
||||||
|
#include <Renderer.h>
|
||||||
|
#include <Octree.h>
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
@ -59,6 +63,7 @@ struct CApp: public App, public magic::Application
|
|||||||
Options m_options;
|
Options m_options;
|
||||||
|
|
||||||
magic::SharedPtr<magic::Scene> m_scene;
|
magic::SharedPtr<magic::Scene> m_scene;
|
||||||
|
magic::SharedPtr<magic::Node> m_camera_node;
|
||||||
|
|
||||||
CApp(magic::Context *context, const Options &options):
|
CApp(magic::Context *context, const Options &options):
|
||||||
magic::Application(context),
|
magic::Application(context),
|
||||||
@ -287,16 +292,31 @@ struct CApp: public App, public magic::Application
|
|||||||
// files.
|
// files.
|
||||||
buildat_guard_enable(true);
|
buildat_guard_enable(true);
|
||||||
|
|
||||||
// Create a scene that will be synchronized from the server and set it
|
// Create a scene that will be synchronized from the server
|
||||||
// as a global
|
|
||||||
m_scene = new magic::Scene(context_);
|
m_scene = new magic::Scene(context_);
|
||||||
magic::WeakPtr<magic::LuaFunction> f =
|
m_scene->CreateComponent<magic::Octree>();
|
||||||
|
|
||||||
|
// Create a camera and a viewport for the scene. The scene can then be
|
||||||
|
// accessed in Lua by magic.renderer:GetViewport(0):GetScene().
|
||||||
|
m_camera_node = m_scene->CreateChild("Camera", magic::LOCAL);
|
||||||
|
magic::Camera* camera = m_camera_node->CreateComponent<magic::Camera>();
|
||||||
|
camera->SetFarClip(300.0f);
|
||||||
|
m_camera_node->SetPosition(magic::Vector3(7.0, 7.0, 7.0));
|
||||||
|
m_camera_node->LookAt(magic::Vector3(0, 1, 0));
|
||||||
|
|
||||||
|
magic::Renderer* renderer = GetSubsystem<magic::Renderer>();
|
||||||
|
magic::SharedPtr<magic::Viewport> viewport(new magic::Viewport(
|
||||||
|
context_, m_scene, m_camera_node->GetComponent<magic::Camera>()));
|
||||||
|
renderer->SetViewport(0, viewport);
|
||||||
|
|
||||||
|
// Won't work; accessing the resulting value in Lua segfaults.
|
||||||
|
/*magic::WeakPtr<magic::LuaFunction> f =
|
||||||
m_script->GetFunction("__buildat_set_sync_scene");
|
m_script->GetFunction("__buildat_set_sync_scene");
|
||||||
if(!f)
|
if(!f)
|
||||||
throw Exception("__buildat_set_sync_scene not found");
|
throw Exception("__buildat_set_sync_scene not found");
|
||||||
f->BeginCall();
|
f->BeginCall();
|
||||||
f->PushUserType(m_scene.Get(), "Scene");
|
f->PushUserType(m_scene.Get(), "Scene");
|
||||||
f->EndCall();
|
f->EndCall();*/
|
||||||
|
|
||||||
// Launch menu if requested
|
// Launch menu if requested
|
||||||
if(g_client_config.boot_to_menu){
|
if(g_client_config.boot_to_menu){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user