Skip to content

Commit

Permalink
1.4.4: disable iNetwork interface by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturas-Alfredas Lapinskas committed Jul 3, 2024
1 parent 6bc20d9 commit 264ac4c
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Javascript Game Engine
# Javascript Game Engine

This engine was designed to simplify creating javascript 2d game applications.

Expand Down
17 changes: 11 additions & 6 deletions dist/index.es6.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.es6.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.es6.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/templates/custom/tmpl/layout.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="expires" content="Wen, 05 Jun 2024 07:01:00 GMT">
<title>JSDoc: <?js= title ?></title>

<script src="scripts/prettify/prettify.js"> </script>
Expand All @@ -22,7 +23,7 @@
</div>

<nav>
<div class="switcher"><ul><li class="active"><a href="/">1.4.31</a></li><li><a href="/1.1.3">1.1.3</a></li><li><a href="/0.3.8">0.3.8</a></li><li><a href="/0.2.3">0.2.3</a></li></ul></div>
<div class="switcher"><ul><li class="active"><a href="/">1.4.32</a></li><li><a href="/1.1.3">1.1.3</a></li><li><a href="/0.3.8">0.3.8</a></li><li><a href="/0.2.3">0.2.3</a></li></ul></div>
<?js= this.nav ?>
</nav>

Expand Down
5 changes: 4 additions & 1 deletion examples/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SpinePage } from "./spine/spinePage.js";
import { BigMap } from "./big_map/bigMap.js";
import { Tanks } from "./tanks/tanks.js";
import { Strategy } from "./strategy/strategy.js";
import { Primitives } from "./primitives/primitives.js";

import { CustomWebGlTestPage } from "./testCustomWebGl/index.js";
import { CustomDrawObject, createCustomDrawObjectInstance, drawCustomObject } from "./testCustomWebGl/TestDrawObject.js";
Expand All @@ -20,7 +21,8 @@ const START_PAGE_NAME = "start",
BIG_MAP = "big_map",
STRATEGY_GAME = "strategy_game",
CUSTOM_WEBGL_PAGE = "custom_webgl",
TANKS_PAGE = "tanks";
TANKS_PAGE = "tanks",
PRIMITIVES_PAGE = "primitives";

const TEST_WEBGL_PROGRAM_KEY = "test",
TEST_CUSTOM_DRAW_OBJECT_KEY = "customDrawObject";
Expand Down Expand Up @@ -218,6 +220,7 @@ function runApp(settings) {
app.registerStage(STRATEGY_GAME, Strategy);
app.registerStage(CUSTOM_WEBGL_PAGE, CustomWebGlTestPage);
app.registerStage(TANKS_PAGE, Tanks);
app.registerStage(PRIMITIVES_PAGE, Primitives)

// пробуем пользовательскую webgl программу
app.iSystem.iExtension.registerAndCompileWebGlProgram(TEST_WEBGL_PROGRAM_KEY, testVertexShader, testFragmentShader, testUniforms, testAttributes);
Expand Down
98 changes: 98 additions & 0 deletions examples/primitives/primitives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { GameStage, CONST, System, SystemSettings } from "../../src/index.js";

export class Primitives extends GameStage {
#keyPressed = { ArrowUp: false, KeyW: false, ArrowLeft: false, KeyA: false, ArrowRight: false, KeyD: false, ArrowDown: false, KeyS: false };
register() {
}
init() {
}
start() {
this.registerListeners();
}

stop() {
this.unregisterListeners();
}

registerListeners() {
this.#registerMouseListeners();
this.#registerKeyboardListeners();
this.#registerSystemEventsListeners();
}

unregisterListeners() {
this.#unregisterMouseListeners();
this.#unregisterKeyboardListeners();
this.#unregisterSystemEventsListeners();
}

#registerKeyboardListeners() {
document.addEventListener("keydown", this.#pressKeyAction);
document.addEventListener("keyup", this.#removeKeyAction);
}

#unregisterKeyboardListeners() {
document.removeEventListener("keydown", this.#pressKeyAction);
document.removeEventListener("keyup", this.#removeKeyAction);
}

#registerMouseListeners() {
document.addEventListener("mousemove", this.#mouseMoveAction);
document.addEventListener("click", this.#mouseClickAction);
}

#unregisterMouseListeners() {
document.removeEventListener("mousemove", this.#mouseMoveAction);
document.removeEventListener("click", this.#mouseClickAction);
}

#pressKeyAction = (event) => {
const code = event.code;
let keyPressed = this.#keyPressed;

keyPressed[code] = true;
};
#removeKeyAction = (event) => {
const code = event.code;
this.#keyPressed[code] = false;
};

#mouseMoveAction = (e) => {
const [xOffset, yOffset] = this.stageData.worldOffset,
x = e.offsetX,
y = e.offsetY,
cursorPosX = x + xOffset,
cursorPosY = y + yOffset;
};


#mouseClickAction = (e) => {

}


#render = () => {
const keyPressed = this.#keyPressed;

if (keyPressed["ArrowUp"] || keyPressed["KeyW"]){
//this.stepMove("forward");
}
if (keyPressed["ArrowLeft"] || keyPressed["KeyA"]) {
//this.stepMove("turn_left");
}
if (keyPressed["ArrowRight"] || keyPressed["KeyD"]) {
//this.stepMove("turn_right");
}
if (keyPressed["ArrowDown"] || keyPressed["KeyS"]){
//this.stepMove("backward");
}

}
#registerSystemEventsListeners() {
this.iSystem.addEventListener(CONST.EVENTS.SYSTEM.RENDER.START, this.#render);
}

#unregisterSystemEventsListeners() {
this.iSystem.removeEventListener(CONST.EVENTS.SYSTEM.RENDER.START, this.#render);
}
}
22 changes: 19 additions & 3 deletions examples/startPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const START_PAGE_NAME = "start",
BIG_MAP = "big_map",
STRATEGY_GAME = "strategy_game",
CUSTOM_WEBGL_PAGE = "custom_webgl",
TANKS_PAGE = "tanks";
TANKS_PAGE = "tanks",
PRIMITIVES_PAGE = "primitives";

const SPINE = {
SpineTexture: "spineTexture",
Expand Down Expand Up @@ -55,6 +56,7 @@ export class StartPage extends GameStage {
this.navItemBigMap = this.draw.text(w/2 + LEFT_SHIFT, h/2 + 70, "Big map", "20px sans-serif", "black");
this.navItemTestCustomWebGl = this.draw.text(w/2 + LEFT_SHIFT, h/2 + 100, "Custom WebGl program", "20px sans-serif", "black");
this.navTanksGame = this.draw.text(w/2 + LEFT_SHIFT, h/2 + 130, "Tanks game", "20px sans-serif", "black");
this.navPrimitivesGame = this.draw.text(w/2 + LEFT_SHIFT, h/2 + 160, "Primitives draw", "20px sans-serif", "black");

//this.#createOptionsBlock();
this.audio.registerAudio(MENU_CLICK_AUDIO_NAME);
Expand Down Expand Up @@ -86,7 +88,8 @@ export class StartPage extends GameStage {
isNav5T = isPointRectIntersect(event.offsetX, event.offsetY, this.navItemBigMap.boundariesBox),
isNav6T = isPointRectIntersect(event.offsetX, event.offsetY, this.navItemTestCustomWebGl.boundariesBox),
isNav7T = isPointRectIntersect(event.offsetX, event.offsetY, this.navTanksGame.boundariesBox),
isNav8T = isPointRectIntersect(event.offsetX, event.offsetY, this.navItemStrategy.boundariesBox);
isNav8T = isPointRectIntersect(event.offsetX, event.offsetY, this.navItemStrategy.boundariesBox),
isNav9T = isPointRectIntersect(event.offsetX, event.offsetY, this.navPrimitivesGame.boundariesBox);

if (isNav1Traversed) {
this.navItemDun.strokeStyle = "rgba(0, 0, 0, 0.3)";
Expand Down Expand Up @@ -136,7 +139,13 @@ export class StartPage extends GameStage {
this.navItemStrategy.strokeStyle = undefined;
}

if (isNav1Traversed || isNavP2PTraversed || isNav3Traversed || isNav4Traversed || isNav5T || isNav6T || isNav7T || isNav8T) {
if (isNav9T) {
this.navPrimitivesGame.strokeStyle = "rgba(0, 0, 0, 0.3)";
} else if (this.navPrimitivesGame.strokeStyle) {
this.navPrimitivesGame.strokeStyle = undefined;
}

if (isNav1Traversed || isNavP2PTraversed || isNav3Traversed || isNav4Traversed || isNav5T || isNav6T || isNav7T || isNav8T || isNav9T) {
canvas.style.cursor = "pointer";
} else {
canvas.style.cursor = "default";
Expand Down Expand Up @@ -195,6 +204,13 @@ export class StartPage extends GameStage {
this.iSystem.startGameStage(STRATEGY_GAME);

}

if (isPointRectIntersect(event.offsetX, event.offsetY, this.navPrimitivesGame.boundariesBox)) {
this.#menuClickMediaElement.play();
this.iSystem.stopGameStage(START_PAGE_NAME);
this.iSystem.startGameStage(PIRATES_GAME);

}
};

#loaderErrorHandler = (error) => {
Expand Down
3 changes: 3 additions & 0 deletions history/history-roadmap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ r: code refactoring
f: fixed defects

# History
1.4.4:
r: disable iNetwork interface by default

1.4.32:
f: Mobile Chrome@125.0.6422.147 issue: "Name conflicts between an uniform and an attribute: a_position"
f: registerStage() type issue
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsge",
"version": "1.4.32",
"version": "1.4.4",
"description": "Javascript Game Engine",
"main": "src/index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/base/IExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class IExtension {
* Register render method for class.
* @param {string} objectClassName - object name registered to DrawObjectFactory
* @param {function(renderObject, gl, pageData, program, vars):Promise<any[]>} objectRenderMethod - should be promise based returns vertices number and draw program
* @param {string=} objectWebGlDrawProgram - a webgl program name previously registered with iExtension.registerAndCompileWebGlProgram()
* @param {string} objectWebGlDrawProgram - a webgl program name previously registered with iExtension.registerAndCompileWebGlProgram()
*/
registerObjectRender(objectClassName, objectRenderMethod, objectWebGlDrawProgram) {
this.#systemReference.iRender._registerObjectRender(objectClassName, objectRenderMethod, objectWebGlDrawProgram);
Expand Down
3 changes: 3 additions & 0 deletions src/base/INetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { SystemEvent } from "./Events/SystemEvent.js";

/**
* Represents Socket connection
*
* From 1.4.4 disabled by default,
* to enable, set settings.network.enabled to true
*/
export class INetwork extends EventTarget {
#systemSettings;
Expand Down
6 changes: 3 additions & 3 deletions src/base/ISystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ISystem {
*/
#iExtension;
/**
* @type {INetwork}
* @type {INetwork | null}
*/
#systemServerConnection;
/**
Expand Down Expand Up @@ -67,7 +67,7 @@ export class ISystem {
this.#systemSettings = systemSettings;

this.#systemAudioInterface = new ISystemAudio(this.iLoader);
this.#systemServerConnection = new INetwork(systemSettings);
this.#systemServerConnection = systemSettings.network.enabled ? new INetwork(systemSettings) : null;
this.#iRender = new IRender(this.systemSettings, this.iLoader, canvasContainer);
this.#iExtension = new IExtension(this, this.#iRender);
this.#registeredStagesReference = registeredStages;
Expand Down Expand Up @@ -108,7 +108,7 @@ export class ISystem {
};

/**
* @type { INetwork }
* @type { INetwork | null }
*/
get iNetwork () {
return this.#systemServerConnection;
Expand Down
2 changes: 1 addition & 1 deletion src/base/System.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class System {
* A main factory method for create GameStage instances, <br>
* register them in a System and call GameStage.register() stage
* @param {string} screenPageName
* @param {typeof GameStage} stage
* @param {GameStage} stage
*/
registerStage(screenPageName, stage) {
if (screenPageName && typeof screenPageName === "string" && screenPageName.trim().length > 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class SystemSettings {
// no other variants only WEBGL for now
library: CONST.LIBRARY.WEBGL,
optimization: CONST.OPTIMIZATION.NATIVE_JS.OPTIMIZED,
optimizationWASMUrl: "/src/wa/calculateBufferDataWat.wasm",
optimizationWASMUrl: "./src/wa/calculateBufferDataWat.wasm",
optimizationAssemblyUrl: "/src/wa/calculateBufferDataAssembly.wasm",
loadingScreen: {
backgroundColor: "rgba(128, 128, 128, 0.6)",
Expand Down Expand Up @@ -51,6 +51,8 @@ export class SystemSettings {


static network = {
// disable INetwork by default
enabled: false,
address: "https://gameserver.reslc.ru:9009",
gatherRoomsInfoInterval: 5000
};
Expand Down

0 comments on commit 264ac4c

Please sign in to comment.