Skip to content

Commit

Permalink
Upgraded webpack config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahAmrSobh committed Sep 22, 2020
1 parent c0d6458 commit 23a4bc1
Show file tree
Hide file tree
Showing 26 changed files with 1,538 additions and 2,253 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.vscode
node_modules
predist
predist/**
dist/bundle.js
dist
target
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### WebGL basic game engine.

3,131 changes: 1,131 additions & 2,000 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
"private": true,
"scripts": {
"dev": "concurrently --kill-others \"webpack watch --dev\" \"tsc --watch\"",
"build": "webpack --config webpack.config.js"
"build": "webpack --config webpack.config.js",
"watchwp": "webpack --watch",
"watchts": "tsc --watch"
},
"author": "Abdullah Amr",
"license": "ISC",
"devDependencies": {
"@types/gl-matrix": "^2.4.5",
"file-loader": "^6.1.0",
"typescript": "^3.6.3",
"webpack": "^4.40.2",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.1"
"webpack": "^5.0.0-rc.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"gl-matrix": "^3.1.0"
Expand Down
8 changes: 3 additions & 5 deletions src/CameraController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { vec3, mat4 } from "gl-matrix";
import { Application } from "./application";
import { IUpdatableSystem } from "./core/SystemsManager";



Expand Down Expand Up @@ -47,7 +47,7 @@ export namespace Projection {
}
}

export class CameraController {
export class CameraController implements IUpdatableSystem {


public viewMatrix: mat4 = mat4.create();
Expand All @@ -66,7 +66,6 @@ export class CameraController {
this.oriantation
);

Application.addNewUpdate(this.onUpdate);
}

public updateCameraMatrix(timestep: number): void {
Expand All @@ -78,8 +77,7 @@ export class CameraController {
);
}

public onUpdate(timestep: number): void {

public update(timestep: number): void {

}
}
Expand Down
37 changes: 37 additions & 0 deletions src/Core/Actors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ISObject } from "Engine/Core/SObject"
import { IUpdatableSystem } from "Engine/core/SystemsManager";
import { Components } from "Engine/Core/CoreComponents/Components";
import { vec3, mat4 } from "gl-matrix";

const zeroVector: vec3 = vec3.fromValues(0, 0, 0);
const unitVector: vec3 = vec3.fromValues(0, 0, 0);

export abstract class Actor implements ISObject {
public modelMatrix: mat4 = mat4.create();

constructor(
public name: string,
public transfrom: Components.Transfrom = new Components.Transfrom(zeroVector, zeroVector, unitVector)
) {
}

public staticMesh!: Components.StaticMesh;
public attachStaticMesh(mesh: Components.StaticMesh): void {
this.staticMesh = mesh
}

abstract onUpdate(timestep: number): void;
}

export class ActorManager implements IUpdatableSystem {
private actors: Actor[] = [];
public update(timestep: number): void {
for (const actor of this.actors) {
actor.onUpdate(timestep);
}
}
public registerActor(actor: Actor): void {
this.actors.push(actor);
}

}
8 changes: 1 addition & 7 deletions src/Core/CoreComponents/Components.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { vec3 } from "gl-matrix";

//todo: remove this file;

export namespace Components {


export class Transfrom {
constructor (
public position: vec3,
public rotation: vec3,
public scale: vec3,


){

}
Expand All @@ -23,12 +19,10 @@ export namespace Components {
textures?: Texture;
}


export interface Matarial {
difuse: number | Texture;
roughness: number | Texture;
normal: number | Texture;
metalic: number | Texture;
}

}
28 changes: 0 additions & 28 deletions src/Core/Objects/Mesh.ts

This file was deleted.

42 changes: 0 additions & 42 deletions src/Core/Objects/SObject.ts

This file was deleted.

11 changes: 11 additions & 0 deletions src/Core/SObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface IComponent {
parant: number;
child: number[];
}
export interface ISObject {

}

export namespace SObject {

}
4 changes: 4 additions & 0 deletions src/Core/SystemsManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IUpdatableSystem
{
update(timestep: number): void;
}
40 changes: 40 additions & 0 deletions src/Core/sceneGraph/sceneGraph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { mat4 } from "gl-matrix";

export class SceneGraph
{
public nodes: SceneGraphNode[] = [];

constructor(subGraph: SceneGraph | null)
{
if(typeof subGraph === null)
{

}
else
{

}
}
}

class SceneGraphNode
{
public parant: number = 0;
public children: number[] = [];
public transform: mat4 = mat4.create();

private static getParant(node: SceneGraphNode, graph: SceneGraphNode[]): SceneGraphNode | boolean {
return node.parant != 0? graph[node.parant] : false;
}

public getRelativeTransform(graph: SceneGraphNode[]): mat4 {
let transform = this.transform;
let currentNode = SceneGraphNode.getParant(this, graph);
if(currentNode !== false)
{
mat4.multiply(transform, transform, (<SceneGraphNode>currentNode).transform);
currentNode = SceneGraphNode.getParant(<SceneGraphNode>currentNode, graph);
}
return transform;
}
}
48 changes: 48 additions & 0 deletions src/Engine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { IUpdatableSystem } from "Engine/core/SystemsManager";


export class Engine {
private lastUpdate: number = 0;

private runningSystems: IUpdatableSystem[] = [];
private runningTasks: CallableFunction[] = [];

constructor(renderingContext: WebGLRenderingContext) {

}
public onInit(context: WebGLRenderingContext): void {

}

public registerNewSystem(system: IUpdatableSystem): void {
this.runningSystems.push(system);
}

public registerNewTask(update: CallableFunction): void {
this.runningTasks.push(update);
}


update(time: number) {
for (const task of this.runningTasks) {
task(time);
}

for (const system of this.runningSystems) {
system.update(time);
}

this.lastUpdate = Date.now();
}


public run(): void {
let that = this;
function loop() {
var time: number = Date.now() - that.lastUpdate;
that.update(time);
requestAnimationFrame(loop);
}
requestAnimationFrame(loop)
}
}
14 changes: 3 additions & 11 deletions src/Game/Scripts/CubeActor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mat4, glMatrix } from "gl-matrix";
import { Actor } from "Engine/Core/Objects/SObject";
import { Actor } from "Engine/Core/Actors";


export class CubeGActor extends Actor {
Expand All @@ -13,20 +13,12 @@ export class CubeGActor extends Actor {
super(name);
}


public onUpdate(timestep: number) {
/*
this.angle = glMatrix.toRadian(timestep)
console.log('Hello');
console.log('Hello', this.angle);
this.angle = glMatrix.toRadian(performance.now() * 0.02 * Math.PI)

mat4.rotate(this.yRotationMatrix, this.identityMatrix, this.angle, [0, 1, 0]);
mat4.rotate(this.xRotationMatrix, this.identityMatrix, this.angle / 4, [1, 0, 0]);
mat4.multiply(this.modelMatrix, this.yRotationMatrix, this.xRotationMatrix);
console.log("updateing rotation");
*/
}



}
}
Loading

0 comments on commit 23a4bc1

Please sign in to comment.