Skip to content

Commit

Permalink
First pass of eventnode system
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbudone committed Jul 26, 2020
1 parent b8dc775 commit 8e505d3
Show file tree
Hide file tree
Showing 16 changed files with 784 additions and 32 deletions.
7 changes: 5 additions & 2 deletions js/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Area
define(
[
'eventful', 'dynamic', 'hookable', 'page', 'movable', 'loggable', 'pathfinding'
'eventful', 'dynamic', 'hookable', 'page', 'movable', 'loggable', 'pathfinding', 'eventnodemgr'
],
(
Eventful, Dynamic, Hookable, Page, Movable, Loggable, Pathfinding
Eventful, Dynamic, Hookable, Page, Movable, Loggable, Pathfinding, EventNodeMgr
) => {

const Area = function(id) {
Expand Down Expand Up @@ -75,6 +75,9 @@ define(
this.movables = {};
this.interactables = {};

this.evtNodeMgr = new EventNodeMgr(this);
this.evtNodeMgr.initialize();


this.checkEntityZoned = (entity) => {

Expand Down
21 changes: 21 additions & 0 deletions js/client/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,14 @@ define(
});
}

// Add EventNodes
if (evtPage.evtnodes) {

evtPage.evtnodes.forEach((eventnode) => {
this.evtNodeMgr.netInitializeNode(eventnode, eventnode.eventnode, page);
});
}

// figure out neighbours..
if ((pageI % this.pagesPerRow) !== 0 && this.pages[pageI - 1]) { // West Neighbour
page.neighbours.west = this.pages[pageI - 1];
Expand Down Expand Up @@ -658,6 +666,7 @@ define(
}

this.pathfinding.addPage(page, pageI);
this.evtNodeMgr.addPage(page, pageI);
});
},

Expand All @@ -672,6 +681,9 @@ define(
_.forEach(this.pages, (page) => {
page.step(time);
});

this.evtNodeMgr.step(time);

this.handlePendingEvents(); // events from pages

const dynamicHandler = this.handler('step');
Expand All @@ -687,13 +699,22 @@ define(
page.unload();
});

this.evtNodeMgr.unload();

this.unloadListener();
if ('unhookAllHooks' in this) {
this.unhookAllHooks();
}
this.unregisterAllHooks();
},

removePage(page, pageI) {
this.pathfinding.removePage(page, pageI);
this.evtNodeMgr.removePage(page, pageI);
page.unload();
delete this.pages[pageI];
},

hasTile(tile) {
const pageY = parseInt(tile.y / Env.pageHeight, 10),
pageX = parseInt(tile.x / Env.pageWidth, 10),
Expand Down
7 changes: 3 additions & 4 deletions js/client/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,10 +1286,9 @@ define(

_(The.area.pages)
.pick(existingPages)
.forIn((page, pageI) => {
The.area.pathfinding.removePage(page, pageI);
page.unload();
delete The.area.pages[pageI];
.forIn((page, _pageI) => {
const pageI = parseInt(_pageI, 10);
The.area.removePage(page, pageI);
});

// Zoning into one of the new pages
Expand Down
29 changes: 29 additions & 0 deletions js/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ define(['loggable'], (Loggable) => {

pageBg.page = null; // Free to use, no page associated with it yet
pageBg.needsUpdate = false;
pageBg.blit = [];
}

this.updatePages();
Expand All @@ -144,6 +145,16 @@ define(['loggable'], (Loggable) => {
const delta = time - this.lastUpdateTime;
this.lastUpdateTime = time;

// Redraw blitted static pages
for (let i = 0; i < this.canvasBackgroundPool.length; ++i) {
const canvasBgPage = this.canvasBackgroundPool[i];
if (canvasBgPage.page && canvasBgPage.blit) {
this.renderPageStatic(canvasBgPage, canvasBgPage.page, 0, 0, Env.pageWidth, Env.pageHeight, 0, 0);
canvasBgPage.needsUpdate = true;
canvasBgPage.blit = [];
}
};

for (let i = this.projectiles.length - 1; i >= 0; --i) {
const projectile = this.projectiles[i];
projectile.timeToDie -= delta;
Expand Down Expand Up @@ -1037,6 +1048,24 @@ define(['loggable'], (Loggable) => {
timeToDie: this.settings.ragdoll.life
});
};

this.redrawPage = (page) => {
const canvasBgPage = this.canvasBackgroundPool.find((p) => p.page === page);
this.renderPageStatic(canvasBgPage, page, 0, 0, Env.pageWidth, Env.pageHeight, 0, 0);
canvasBgPage.needsUpdate = true;
};

this.blitPage = (page, tileX, tileY) => {
const canvasBgPage = this.canvasBackgroundPool.find((p) => p.page === page);

// Game logic may not be aware that the page is still loaded but not in view, so just ignore the blit
// request
if (!canvasBgPage) {
return;
}

canvasBgPage.blit.push({ x: tileX, y: tileY });
};
};


Expand Down
4 changes: 3 additions & 1 deletion js/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ define(function(){
'Player': (logDefault),
'Resources': (logDefault),
'ScriptMgr': (logDefault | LOG_INFO),
'Script': (logDefault),
'Script': (logVerbose),
'User': (logDefault),
'Game': (logDefault),
'Character': (logDefault),
Expand All @@ -134,6 +134,8 @@ define(function(){
'Redis': (logDefault),
'Pathfinding': (logDefault),
'Ability': (logDefault),
'EventNodeMgr': (logVerbose),
'EventNode': (logVerbose),
'Default': (logDefault),
};

Expand Down
Loading

0 comments on commit 8e505d3

Please sign in to comment.