Skip to content

Commit

Permalink
ResourceBuilder rework (getting rid of caching system)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbudone committed Apr 12, 2018
1 parent 91ce077 commit 4d98aaa
Show file tree
Hide file tree
Showing 17 changed files with 1,855 additions and 886 deletions.
25 changes: 6 additions & 19 deletions NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -349,26 +349,9 @@ WORKING ON (was previously working on)
- Fix waitForInspector when we've already connected to the inspector
- NPC inheritance
- NPCs: get rid of "damage"
- Fix: statBuff is not very flexible (eg. cannot have max/cur multiplier for same stat in same buff; tick seems questionable), should validate buffRes on startup to confirm its good. Cleaning this up for scalability could instead allow us to overcomplicate buffs
* - Combat: debuff effects (eg. poison arrows, thrown potions, etc.); how to add this to NPCs too? (NOTE: NPCs we want it % of time to happen)
- effect on the weapon (or projectile for ranged).
- could pass effect into .damage; then handle effect accordingly
- apart of damageData
- check if procs, manipulate data, post effects on character
- weapon: {
dmg: 10,
spd: 12,
lvl: 6,
effects: [
{
type: buff,
buffRes: poison,
chance: 0.2,
args: ...?
},

]
}
- could pre/post hook into effect (see if it procs, perform effects)
- Handle for ranged
- Map: Layers that auto flatten into sprites layer (eg. fenced off area which is in another area, so we can easily modify fence layer later)
- Idle anim; between attack animations also go to idle anim (in same direction)
- Mesh setup:
Expand Down Expand Up @@ -463,6 +446,8 @@ WORKING ON (was previously working on)
- Avatars: Make avatars larger to fit titles, but center the sprites such that they appear on the tile w/ a decent size
- Spawn bodyguard: spawns a bodyguard (w/ some characterTemplate) w/ AI that follows you and aggros enemies -- could have different AI strategies for different bodyguard types
* - Sheet Editor
- Large canvas: move the avatar options to the right and allow avatars list to collapse (if we have a not very wide screen: laptop)
- Large canvas: automatically determine maxWidth (should stretch from left -> avatar options box)
- Anim preview overflows
- Anim flipX
- Scroll up in chatbox, when something new is added it automatically scrolls down (if we manually scroll up then should disable that)
Expand All @@ -478,6 +463,8 @@ WORKING ON (was previously working on)
- Reloading npcs:
- We *CANNOT* cache values from old npcs, or npcs in general, otherwise we keep a stale npcs
- brain/components/etc. of character need to have an initializeNPC routine (find a suitable name!) that runs on startup and when we reload NPCs
- Add all media assets (tilesheets, spritesheets, sounds, images), maybe even all assets entirely? to a global assets list for quick lookup
- Look into media storage for git for dist/ (eg. git-lfs); worth it?


- Browser Debugging Snippets
Expand Down
Binary file modified cache/tilesheet.cache
Binary file not shown.
Binary file modified cache/winterland.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ define(

Resources = (new Resources());
window.Resources = Resources;
Resources.initialize(['cache', 'sheets', 'npcs', 'rules', 'items', 'buffs', 'quests', 'interactions', 'interactables', 'scripts', 'components', 'fx', 'testing']).then((assets) => {
Resources.initialize(['media', 'sheets', 'npcs', 'rules', 'items', 'buffs', 'quests', 'interactions', 'interactables', 'scripts', 'components', 'fx', 'testing']).then((assets) => {
loaded('resources');
})
.catch((e) => { errorInGame(e); });
Expand Down
16 changes: 8 additions & 8 deletions js/resourceProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ define(() => {

readImage: (name) => {
return new Promise((succeeded, failed) => {
const cacheNode = Resources.cache.cacheList.find((el) => el.name === name);
assert(cacheNode, `Could not find cache for ${name}`);
let mediaNode = Resources.sheets[name] || Resources.sprites[name] || Resources.media.list.find((el) => el.name === name);
assert(mediaNode, `Could not find node for ${name}`);

// Has the file been cached? If so then we must send an XHR request in order to open the file in a
// binary format, and process/read it accordingly
if (cacheNode.options.cached) {
if (mediaNode.options.encrypted) {

const assetFile = '/dist/resources/' + cacheNode.asset;
const assetFile = mediaNode.file;

if (!assetFile) {
failed(`Could not find cache for ${file} (${assetFile})`);
failed(`Could not find media for ${file} (${assetFile})`);
}

// TODO: Should offload this stuff into webworkers
Expand All @@ -36,7 +36,7 @@ define(() => {
oReq.onload = (oEvent) => {

if (oReq.response) {
if (cacheNode.options.encrypted) {
if (mediaNode.options.encrypted) {

const encrypted = new Uint8Array(oReq.response),
options = {
Expand Down Expand Up @@ -99,10 +99,10 @@ define(() => {
};

img.onerror = function() {
throw Err(`Error loading img: ${cacheNode.asset}`);
throw Err(`Error loading img: ${mediaNode.file}`);
};

const url = '/dist/resources/' + cacheNode.asset;
const url = mediaNode.file;
img.src = url;
}
});
Expand Down
29 changes: 14 additions & 15 deletions js/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define(['loggable', 'resourceProcessor'], function(Loggable, ResourceProcessor){
components: {},
rules: {},
fx: {},
cache: {},
media: {},
testing: {},

initialize: function(){},
Expand Down Expand Up @@ -288,7 +288,7 @@ define(['loggable', 'resourceProcessor'], function(Loggable, ResourceProcessor){
else if (assetID == 'scripts') return initializeScripts(asset);
else if (assetID == 'world') return initializeWorld(asset);
else if (assetID == 'components') return initializeComponents(asset);
else if (assetID == 'cache') return initializeCache(asset);
else if (assetID == 'media') return initializeMedia(asset);
else if (assetID == 'testing') return initializeTesting(asset);
else return new Error("Unknown asset: "+ assetID);
}),
Expand All @@ -298,12 +298,13 @@ define(['loggable', 'resourceProcessor'], function(Loggable, ResourceProcessor){
var res = JSON.parse(asset);
var makeSheet = function(_sheet){
var sheet = {
file: _sheet.image,
file: '/dist/resources' + _sheet.output,
offset: {
x: parseInt(_sheet.sheet_offset.x),
y: parseInt(_sheet.sheet_offset.y),
},
image: ((Env.isServer||Env.isBot)? null : (new Image())),
options: _sheet.options, // FIXME: It sucks to retain options here (wasted memory), but we need it for knowing if the file is encrypted
data: { }
};

Expand Down Expand Up @@ -365,15 +366,14 @@ define(['loggable', 'resourceProcessor'], function(Loggable, ResourceProcessor){
}
}

this.sheets[_sheet.id] = sheet;
if (!Env.isServer) {
ResourceProcessor.readImage(_sheet.id).then((bitmapImage) => {
sheet.image = bitmapImage;
}, (err) => {
throw Err(err);
});
}

this.sheets[_sheet.id] = sheet;
});

if (Env.isServer || Env.isBot) {
Expand Down Expand Up @@ -514,6 +514,7 @@ define(['loggable', 'resourceProcessor'], function(Loggable, ResourceProcessor){

}.bind(env));

this.sprites[_sheet.id] = sheet;
if (!Env.isServer) {
ResourceProcessor.readImage(_sheet.id).then((bitmapImage) => {
sheet.image = bitmapImage;
Expand All @@ -522,8 +523,6 @@ define(['loggable', 'resourceProcessor'], function(Loggable, ResourceProcessor){
throw Err(err);
});
}

this.sprites[_sheet.id] = sheet;
});

}
Expand Down Expand Up @@ -713,10 +712,10 @@ define(['loggable', 'resourceProcessor'], function(Loggable, ResourceProcessor){
componentsAssets = res;
}.bind(_interface)),

initializeCache = (function(asset){
initializeMedia = (function(asset){

var res = JSON.parse(asset);
this.cache = res;
this.media = res;
}.bind(_interface)),

initializeTesting = (function(asset){
Expand Down Expand Up @@ -764,9 +763,9 @@ define(['loggable', 'resourceProcessor'], function(Loggable, ResourceProcessor){
succeeded(this);
};

const cacheNode = this.cache.cacheList.find((el) => el.name === imageRes);
assert(cacheNode, `Could not find cache for ${imageRes}`);
const url = '/dist/resources/' + cacheNode.asset;
const mediaNode = this.media.list.find((el) => el.name === imageRes);
assert(mediaNode, `Could not find media for ${imageRes}`);
const url = '/dist/resources/' + mediaNode.output;
img.src = url;

// FIXME: Cache asset, then just return that cached image; we only need 1 instance of each image, but
Expand All @@ -780,9 +779,9 @@ define(['loggable', 'resourceProcessor'], function(Loggable, ResourceProcessor){

return new Promise(function(success, fail){

const cacheNode = this.cache.cacheList.find((el) => el.name === soundRes);
assert(cacheNode, `Could not find cache for ${soundRes}`);
const src = '/dist/resources/' + cacheNode.asset;
const mediaNode = this.media.list.find((el) => el.name === soundRes);
assert(mediaNode, `Could not find media for ${soundRes}`);
const src = '/dist/resources/' + mediaNode.output;

const request = new XMLHttpRequest();
request.open('GET', src, true);
Expand Down
6 changes: 4 additions & 2 deletions js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@ requirejs(['keys', 'environment'], (Keys, Environment) => {
The.world = world;

// Load Areas
_.each(json.areas, (areaFile, areaID) => {
_.each(json.areas, (areaDetails, areaID) => {

const areaFile = areaDetails.file;
loading(`area ${areaID}`);
fs.readFile(`dist/resources/maps/${areaFile}`, (e, areaRawData) => {
fs.readFile(`dist/resources/${areaFile}`, (e, areaRawData) => {

if (e) errorInGame(e);

Expand Down
8 changes: 4 additions & 4 deletions js/server/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ define(['loggable'], function(Loggable){

this.registerUser = function(username, password, email, overrideSpawn){

//let spawnArea = 'main';
//let spawnPosition = { x: 53, y: 60 };
let spawnArea = 'mainmap';
let spawnPosition = { x: 774, y: 333 };
let spawnArea = 'main';
let spawnPosition = { x: 53, y: 60 };
//let spawnArea = 'largemap';
//let spawnPosition = { x: 774, y: 333 };

// FIXME: Only allow this on test, and need to double check valid spawn
if (overrideSpawn) {
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,22 @@
},
"dependencies": {
"bluebird": "*",
"brotli": "^1.3.2",
"chalk": "~1.0.0",
"chokidar": "^2.0.0",
"hiredis": "*",
"jquery": "*",
"jsdom": "*",
"jszip": "^3.1.5",
"l1-path-finder": "*",
"lz4": "^0.5.3",
"mongodb": "*",
"node-snappy": "^0.1.4",
"openpgp": "^2.6.1",
"pako": "^1.0.6",
"redis": "*",
"requirejs": "*",
"snappyjs": "^0.6.0",
"underscore": "*",
"ws": "*"
},
Expand Down
Loading

0 comments on commit 4d98aaa

Please sign in to comment.