Skip to content

Commit

Permalink
Working Starling layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcdk committed Oct 9, 2023
1 parent 2fb48f5 commit 72f9f2f
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 87 deletions.
37 changes: 19 additions & 18 deletions project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@
<project>
<meta title="Radio Silence" package="com.distractionware.radiosilence" version="1.0.0" />
<app main="Main" file="radiosilence" path="bin" />
<window width="1280" height="720"
orientation="landscape"
vsync="true" fps="60"
hardware="true"
allow-shaders="true"
require-shaders="true"
depth-buffer="false"
stencil-buffer="true"
background="0x000000" />

<window width="1280" height="720"
orientation="landscape"
vsync="true" fps="60"
hardware="true"
allow-shaders="true"
require-shaders="true"
depth-buffer="false"
stencil-buffer="true"
background="0x000000" />

<window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />

<source path="src" />

<haxelib name="openfl" />
<haxelib name="starling" />
<haxelib name="away3d" />

<assets path="data" include="*.awd" type="binary"/>
<assets path="data"/>
<haxelib name="oimophysics" />

<assets path="data" include="*.awd" type="binary" />
<assets path="data" />

<section if="haxeserver">
<haxeflag name="--connect 6000"/>
</section>
<section if="haxeserver">
<haxeflag name="--connect 6000" />
</section>

<config type="windows" output-directory="${platform}-${buildType}" />
<config type="windows" output-directory="${platform}-${buildType}" />
</project>
30 changes: 15 additions & 15 deletions src/Level.hx
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import away3d.primitives.CubeGeometry;
import oimo.dynamics.rigidbody.RigidBodyType;
import away3d.containers.View3D;
import away3d.entities.Mesh;
import away3d.materials.ColorMaterial;
import away3d.materials.lightpickers.StaticLightPicker;
import openfl.geom.Vector3D;

class Level{
class Level {
var view:View3D;
var meshlist:Array<Mesh>;
var ambientlight:Int;
var lightpicker:StaticLightPicker;
public function new(_view:View3D, _ambientlight:Int, _lightpicker:StaticLightPicker){

public function new(_view:View3D, _ambientlight:Int, _lightpicker:StaticLightPicker) {
view = _view;
ambientlight = _ambientlight;
lightpicker = _lightpicker;
meshlist = [];
}
public function add(meshname:String, pos:Vector3D, angle:Float = 0.0, sx:Float = 1.0, sy:Float = 1.0, sz:Float = 1.0):Mesh{

public function add(meshname:String, pos:Vector3D, angle:Float = 0.0, sx:Float = 1.0, sy:Float = 1.0, sz:Float = 1.0):Mesh {
var newmesh:Mesh = MeshLibrary.getmesh(meshname).clone();

newmesh.material = new ColorMaterial(ambientlight);
newmesh.material.lightPicker = lightpicker;

newmesh.position = pos;
newmesh.rotationX = 0;
newmesh.rotationY = (180 + angle) % 360; //Matches Unity coordinates
newmesh.rotationY = (180 + angle) % 360; // Matches Unity coordinates
newmesh.rotationZ = 0;
newmesh.scaleX = sx;
newmesh.scaleY = sy;
newmesh.scaleZ = sz;

meshlist.push(newmesh);
view.scene.addChild(newmesh);

return newmesh;
}

public function cleanup(){

}
}

public function cleanup() {}
}
86 changes: 44 additions & 42 deletions src/Main.hx
Original file line number Diff line number Diff line change
@@ -1,88 +1,90 @@
import away3d.containers.*;
import away3d.entities.*;
import away3d.materials.*;
import away3d.primitives.*;
import away3d.utils.*;
import away3d.core.managers.Stage3DManager;
import away3d.core.managers.Stage3DProxy;
import away3d.events.Stage3DEvent;
import away3d.debug.AwayStats;

import away3d.events.Stage3DEvent;
import oimo.common.Vec3;
import oimo.dynamics.World;
import openfl.display.*;
import openfl.events.*;
import openfl.geom.Vector3D;

import starling.core.*;

class Main extends Sprite {
//engine variables
// engine variables
private var stage3DManager:Stage3DManager;
private var stage3DProxy:Stage3DProxy;
private var away3dview:View3D;

private var starlinglayer:Starling;
//scene objects

// scene objects
private var gamestate:GameState;

public function new(){

private var oimo_world:World;

public function new() {
super();

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;


oimo_world = new World(new Vec3(0, -9.80665, 0));

// first step, must do before anything else !!!
OimoUtils.setWorld(oimo_world);

initProxies();
}

private function initProxies() {
// Define a new Stage3DManager for the Stage3D objects
stage3DManager = Stage3DManager.getInstance(stage);

// Create a new Stage3D proxy to contain the separate views
stage3DProxy = stage3DManager.getFreeStage3DProxy();
stage3DProxy.addEventListener(Stage3DEvent.CONTEXT3D_CREATED, onContextCreated);
}

private function onContextCreated(event:Stage3DEvent) {
// Create the first Away3D view
away3dview = new View3D();
away3dview.stage3DProxy = stage3DProxy;
away3dview.shareContext = true;
//setup the camera

// setup the camera
away3dview.camera.z = -60;
away3dview.camera.y = 20;
away3dview.camera.lookAt(new Vector3D());

MeshLibrary.load(
["island1", "island2", "island3", "island4", "island5",
"big1", "big2", "radio", "small1", "small2", "small3"],
onloadcomplete);


MeshLibrary.load([
"island1", "island2", "island3", "island4", "island5", "big1", "big2", "radio", "small1", "small2", "small3"
], onloadcomplete);

addChild(away3dview);
addChild(new AwayStats(away3dview));
//initStarling();

initStarling();
}
private function onloadcomplete(){

private function onloadcomplete() {
gamestate = new GameState(away3dview, stage);
//setup the render loop
stage.addEventListener(Event.ENTER_FRAME, _onEnterFrame);

// setup the render loop
stage3DProxy.addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}
private function initStarling(){

private function initStarling() {
starlinglayer = new Starling(StarlingLayer, stage, stage3DProxy.viewPort, stage3DProxy.stage3D);
starlinglayer.shareContext = true;
}

private function _onEnterFrame(e:Event) {
stage3DProxy.clear();
OimoUtils.updatePhysics();

gamestate.update();
away3dview.render();
//starlinglayer.nextFrame();

stage3DProxy.present();
StarlingLayer.getInstance().update();
starlinglayer.nextFrame();
}
}
}
Loading

0 comments on commit 72f9f2f

Please sign in to comment.