add more things for lua and begin working on networking
This commit is contained in:
parent
dc811f7f7f
commit
8a443a7e87
10 changed files with 159 additions and 26 deletions
|
@ -35,6 +35,8 @@ allprojects {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
|
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
|
||||||
|
maven { url "https://repo.codemc.org/repository/maven-public/" }
|
||||||
|
maven { url "https://github.com/JRakNet/WaifUPnP/raw/master" }
|
||||||
maven { url 'https://jitpack.io' }
|
maven { url 'https://jitpack.io' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,5 +63,7 @@ project(":core") {
|
||||||
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
|
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
|
||||||
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||||
compile 'com.github.apsun:luabridge:master-SNAPSHOT'
|
compile 'com.github.apsun:luabridge:master-SNAPSHOT'
|
||||||
|
api 'com.whirvis:jraknet:2.12.3'
|
||||||
|
implementation "com.esotericsoftware:kryo:5.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,7 @@
|
||||||
local world = root:find("World")
|
local world = root:find("World")
|
||||||
world:createCube()
|
|
||||||
|
local cube = object:Cube()
|
||||||
|
|
||||||
|
cube:positionSet(object:Vector3(3, cube:positionGet():yGet() + 10, 3))
|
||||||
|
|
||||||
|
world:add(cube)
|
|
@ -7,7 +7,21 @@ open class Component : ExposedJavaClass() {
|
||||||
val children: ArrayList<Component> = ArrayList()
|
val children: ArrayList<Component> = ArrayList()
|
||||||
|
|
||||||
open var name: String = "Component"
|
open var name: String = "Component"
|
||||||
open var componentType: String = "Component"
|
open val componentType: String = "Component"
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun childrenGet(flatten: Boolean?): ArrayList<Component> {
|
||||||
|
if (flatten == true) {
|
||||||
|
// This is VERY inefficient
|
||||||
|
val flattened: ArrayList<Component> = ArrayList()
|
||||||
|
for (child in children) {
|
||||||
|
if (child.children.count() >= 1) child.children.forEach { flattened.add(it) }
|
||||||
|
flattened.add(child)
|
||||||
|
}
|
||||||
|
return flattened
|
||||||
|
}
|
||||||
|
return children
|
||||||
|
}
|
||||||
|
|
||||||
@ExposeToLua
|
@ExposeToLua
|
||||||
fun find(name: String): Component? {
|
fun find(name: String): Component? {
|
||||||
|
|
|
@ -1,13 +1,38 @@
|
||||||
package com.mygdx.game
|
package com.mygdx.game
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g3d.ModelInstance
|
import com.badlogic.gdx.graphics.g3d.ModelInstance
|
||||||
|
import com.badlogic.gdx.math.Quaternion
|
||||||
|
import com.badlogic.gdx.math.Vector3
|
||||||
|
import com.crossbowffs.luabridge.ExposeToLua
|
||||||
|
|
||||||
class Cube(modelInstance: ModelInstance) : Component() {
|
class Cube(var modelInstance: ModelInstance) : Component() {
|
||||||
override var name: String = "Cube"
|
override var name = "Cube"
|
||||||
override var componentType: String = "Cube"
|
override val componentType = "Cube"
|
||||||
var modelInstance: ModelInstance = modelInstance
|
|
||||||
|
var position: LVector3 = LVector3(0.0f, 0.0f, 0.0f)
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
println("+ cube")
|
println("+ cube")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun sizeSet(vec: LVector3) {
|
||||||
|
modelInstance.transform.scl(vec.m_x, vec.m_y, vec.m_z)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun sizeGet(): LVector3 {
|
||||||
|
return LVector3(modelInstance.transform.scaleX, modelInstance.transform.scaleY, modelInstance.transform.scaleZ)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun positionSet(vec: LVector3) {
|
||||||
|
position = vec
|
||||||
|
modelInstance.transform.translate(vec.m_x, vec.m_y, vec.m_z)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun positionGet(): LVector3 {
|
||||||
|
return position
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -29,6 +29,7 @@ class CubesAndThings : ApplicationAdapter() {
|
||||||
|
|
||||||
val globals = JsePlatform.standardGlobals()
|
val globals = JsePlatform.standardGlobals()
|
||||||
globals.set("root", rootComponent)
|
globals.set("root", rootComponent)
|
||||||
|
globals.set("object", LuaObject())
|
||||||
val chunk = globals.loadfile("scripts/Init.lua")
|
val chunk = globals.loadfile("scripts/Init.lua")
|
||||||
chunk.call()
|
chunk.call()
|
||||||
|
|
||||||
|
@ -53,6 +54,7 @@ class CubesAndThings : ApplicationAdapter() {
|
||||||
cameraController.update()
|
cameraController.update()
|
||||||
Gdx.gl.glViewport(0, 0, Gdx.graphics.width, Gdx.graphics.height)
|
Gdx.gl.glViewport(0, 0, Gdx.graphics.width, Gdx.graphics.height)
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT or GL20.GL_DEPTH_BUFFER_BIT)
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT or GL20.GL_DEPTH_BUFFER_BIT)
|
||||||
|
Gdx.gl.glClearColor(86/255f, 213/255f, 252/255f, 1f)
|
||||||
|
|
||||||
modelBatch.begin(camera)
|
modelBatch.begin(camera)
|
||||||
worldComponent.doBatch(modelBatch, environment)
|
worldComponent.doBatch(modelBatch, environment)
|
||||||
|
|
65
core/src/com/mygdx/game/LuaObject.kt
Normal file
65
core/src/com/mygdx/game/LuaObject.kt
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package com.mygdx.game
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.graphics.VertexAttributes
|
||||||
|
import com.badlogic.gdx.graphics.g3d.Material
|
||||||
|
import com.badlogic.gdx.graphics.g3d.ModelInstance
|
||||||
|
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute
|
||||||
|
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder
|
||||||
|
import com.crossbowffs.luabridge.ExposeToLua
|
||||||
|
import com.crossbowffs.luabridge.ExposedJavaClass
|
||||||
|
|
||||||
|
class LVector3(x: Float, y: Float, z: Float) : ExposedJavaClass() {
|
||||||
|
var m_x: Float = x
|
||||||
|
var m_y: Float = y
|
||||||
|
var m_z: Float = z
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun xGet(): Float {
|
||||||
|
return m_x
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun yGet(): Float {
|
||||||
|
return m_y
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun zGet(): Float {
|
||||||
|
return m_z
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun xSet(newX: Float) {
|
||||||
|
m_x = newX
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun ySet(newY: Float) {
|
||||||
|
m_y = newY
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun zSet(newZ: Float) {
|
||||||
|
m_z = newZ
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LuaObject : ExposedJavaClass() {
|
||||||
|
private val modelBuilder: ModelBuilder = ModelBuilder()
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun Cube(): Cube {
|
||||||
|
val newCube = Cube(ModelInstance(modelBuilder.createBox(
|
||||||
|
5f, 5f, 5f,
|
||||||
|
Material(ColorAttribute.createDiffuse(Color.GREEN)),
|
||||||
|
(VertexAttributes.Usage.Position or VertexAttributes.Usage.Normal).toLong()
|
||||||
|
)))
|
||||||
|
return newCube
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun Vector3(x: Float, y: Float, z: Float): LVector3 {
|
||||||
|
return LVector3(x, y, z)
|
||||||
|
}
|
||||||
|
}
|
13
core/src/com/mygdx/game/NetworkClient.kt
Normal file
13
core/src/com/mygdx/game/NetworkClient.kt
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package com.mygdx.game
|
||||||
|
|
||||||
|
import com.whirvis.jraknet.client.RakNetClient
|
||||||
|
import com.esotericsoftware.kryo.Kryo
|
||||||
|
|
||||||
|
class NetworkClient: Component() {
|
||||||
|
val rakClient = RakNetClient()
|
||||||
|
val kyro = Kryo()
|
||||||
|
|
||||||
|
override fun create() {
|
||||||
|
kyro.register(CubeReplicationPacket)
|
||||||
|
}
|
||||||
|
}
|
16
core/src/com/mygdx/game/NetworkPackets.kt
Normal file
16
core/src/com/mygdx/game/NetworkPackets.kt
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.mygdx.game
|
||||||
|
|
||||||
|
class CubeReplicationNode {
|
||||||
|
var sizeX = 0
|
||||||
|
var sizeY = 0
|
||||||
|
var sizeZ = 0
|
||||||
|
|
||||||
|
var posX = 0
|
||||||
|
var posY = 0
|
||||||
|
var posZ = 0
|
||||||
|
|
||||||
|
var name = "Cube"
|
||||||
|
var replicationTag = "UNTRACKED"
|
||||||
|
}
|
||||||
|
|
||||||
|
class CubeReplicationPacket(var replicationNodes: ArrayList<CubeReplicationNode>)
|
|
@ -1,11 +1,18 @@
|
||||||
package com.mygdx.game
|
package com.mygdx.game
|
||||||
|
|
||||||
|
import com.crossbowffs.luabridge.ExposeToLua
|
||||||
|
|
||||||
class Root : Component() {
|
class Root : Component() {
|
||||||
override var name: String = "Root"
|
override var name: String = "Root"
|
||||||
override var componentType: String = "Root"
|
override val componentType: String = "Root"
|
||||||
private val worldComponent: World = World()
|
private val worldComponent: World = World()
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
add(worldComponent)
|
add(worldComponent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExposeToLua
|
||||||
|
fun connect() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,28 +1,10 @@
|
||||||
package com.mygdx.game
|
package com.mygdx.game
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
|
||||||
import com.badlogic.gdx.graphics.VertexAttributes
|
|
||||||
import com.badlogic.gdx.graphics.g3d.*
|
import com.badlogic.gdx.graphics.g3d.*
|
||||||
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute
|
|
||||||
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder
|
|
||||||
import com.crossbowffs.luabridge.ExposeToLua
|
|
||||||
|
|
||||||
class World : Component() {
|
class World : Component() {
|
||||||
override var name: String = "World"
|
override var name: String = "World"
|
||||||
override var componentType: String = "World"
|
override val componentType: String = "World"
|
||||||
|
|
||||||
private val modelBuilder: ModelBuilder = ModelBuilder()
|
|
||||||
|
|
||||||
@ExposeToLua
|
|
||||||
fun createCube(): Cube {
|
|
||||||
val newCube = Cube(ModelInstance(modelBuilder.createBox(
|
|
||||||
5f, 5f, 5f,
|
|
||||||
Material(ColorAttribute.createDiffuse(Color.GREEN)),
|
|
||||||
(VertexAttributes.Usage.Position or VertexAttributes.Usage.Normal).toLong()
|
|
||||||
)))
|
|
||||||
add(newCube)
|
|
||||||
return newCube
|
|
||||||
}
|
|
||||||
|
|
||||||
fun doBatch(batch: ModelBatch, env: Environment) {
|
fun doBatch(batch: ModelBatch, env: Environment) {
|
||||||
children.forEach {
|
children.forEach {
|
||||||
|
|
Reference in a new issue