Browse Source

more work

1870-zone-sprite-atlas
Shaun 2 years ago
parent
commit
279fd40c62
17 changed files with 487 additions and 2381 deletions
  1. BIN
     
  2. BIN
     
  3. +6
    -2
      src/client/js/objects/objects.js
  4. +48
    -28
      src/client/js/rendering/renderLoginBackground.js
  5. +20
    -3
      src/client/js/rendering/renderer.js
  6. +2
    -4
      src/client/js/resources.js
  7. +8
    -30
      src/client/js/system/client.js
  8. +64
    -71
      src/server/clientComponents/lightPatch.js
  9. +61
    -0
      src/server/clientComponents/sprite.js
  10. +1
    -62
      src/server/config/clientConfig.js
  11. +272
    -2136
      src/server/config/maps/cave/map.json
  12. +0
    -5
      src/server/mods/class-necromancer/index.js
  13. +0
    -16
      src/server/package-lock.json
  14. +0
    -1
      src/server/package.json
  15. +0
    -14
      src/server/world/map.js
  16. +5
    -7
      src/server/world/map/builders/object.js
  17. +0
    -2
      src/server/world/map/builders/tile.js

BIN
View File


BIN
View File


+ 6
- 2
src/client/js/objects/objects.js View File

@@ -3,18 +3,22 @@ define([
'js/system/events',
'js/rendering/renderer',
'js/sound/sound',
'js/config'
'js/config',
'js/system/globals'
], function (
objBase,
events,
renderer,
sound,
config
config,
globals
) {
return {
objects: [],

init: function () {
globals.objects = this;

events.on('onChangeHoverTile', this.getLocation.bind(this));

[


+ 48
- 28
src/client/js/rendering/renderLoginBackground.js View File

@@ -3,9 +3,9 @@ define([
], function (
globals
) {
let mRandom = Math.random.bind(Math);
const mRandom = Math.random.bind(Math);

let customRenderer = null;
const customRenderer = null;

const renderCustomLoginBg = async (renderer, path) => {
if (!customRenderer) {
@@ -20,14 +20,7 @@ define([
customRenderer(renderer);
};

const renderLoginBackground = renderer => {
const { loginBgGeneratorPath } = globals.clientConfig;
if (loginBgGeneratorPath) {
renderCustomLoginBg(renderer, loginBgGeneratorPath);

return;
}

const renderDefaultLoginBg = renderer => {
const { width, height, layers } = renderer;

renderer.setPosition({
@@ -35,8 +28,8 @@ define([
y: 0
}, true);

let w = Math.ceil(width / scale) + 1;
let h = Math.ceil(height / scale) + 1;
const w = Math.ceil(width / scale) + 1;
const h = Math.ceil(height / scale) + 1;

const midX = ~~(w / 2);
const midY = ~~(h / 2);
@@ -44,38 +37,54 @@ define([
const rGrass = 10;
const rBeach = 2;
const rShallow = 3;
const rDeeper = 4;

const noiseFactor = 3;

let container = layers.tileSprites;
const container = layers.tileSprites;

for (let i = 0; i < w; i++) {
for (let j = 0; j < h; j++) {
let tile = 5;
//Outside part is deep water
let tile;

let distance = Math.sqrt(Math.pow(i - midX, 2) + Math.pow(j - midY, 2));
const distance = Math.sqrt(Math.pow(i - midX, 2) + Math.pow(j - midY, 2));
//Grass
if (distance < rGrass + (Math.random() * noiseFactor))
tile = 3;
tile = 14;
//Beach
else if (distance < rGrass + rBeach + (Math.random() * noiseFactor))
tile = 4;
tile = 8;
//Shallow water
else if (distance < rGrass + rBeach + rShallow + (Math.random() * noiseFactor))
tile = 53;
tile = 6;
//Deeper water
else if (distance < rGrass + rBeach + rShallow + rDeeper + (Math.random() * noiseFactor))
tile = 2;
//Deepest water
else
tile = 0;

let alpha = mRandom();

if ([5, 53].indexOf(tile) > -1)
alpha *= 2;

if (Math.random() < 0.3) {
tile = {
5: 6,
3: 0,
4: 1,
53: 54
const options = {
//Grass
14: [15],
//Beach
8: [9],
//Shallow water
6: [7, 7, 7, 5],
//Deeper water
2: [3, 3, 3, 4, 5],
//Deepest water
0: [1, 1, 1, 2]
}[tile];

tile = options[~~(Math.random() * options.length)];
}
let sprite = new PIXI.Sprite(renderer.getTexture('sprites', tile));
const sprite = new PIXI.Sprite(renderer.getTexture('tilesLoginBg', tile));

alpha = Math.min(Math.max(0.15, alpha), 0.65);

@@ -95,5 +104,16 @@ define([
}
};

return renderLoginBackground;
const renderLoginBg = renderer => {
const { loginBgGeneratorPath } = globals.clientConfig;
if (loginBgGeneratorPath) {
renderCustomLoginBg(renderer, loginBgGeneratorPath);

return;
}

renderDefaultLoginBg(renderer);
};

return renderLoginBg;
});

+ 20
- 3
src/client/js/rendering/renderer.js View File

@@ -85,7 +85,6 @@ define([
PIXI.settings.SPRITE_MAX_TEXTURES = Math.min(PIXI.settings.SPRITE_MAX_TEXTURES, 16);
PIXI.settings.RESOLUTION = 1;

events.on('onGetMap', this.onGetMap.bind(this));
events.on('onToggleFullscreen', this.toggleScreen.bind(this));
events.on('onMoveSpeedChange', this.adaptCameraMoveSpeed.bind(this));
events.on('resetRenderer', resetRenderer.bind(this));
@@ -154,7 +153,7 @@ define([
buildTitleScreen: function () {
this.titleScreen = true;

//renderLoginBackground(this);
renderLoginBackground(this);
},

onResize: function () {
@@ -391,7 +390,7 @@ define([
) {
//If the hider is an interior, the tile should be hidden if the player is inside the hider
if (interior) {
if (physics.isInPolygon(px, py, area))
if (physics.isInPolygon(px, py, area))
foundHiddenLayer = layer;
}

@@ -718,6 +717,24 @@ define([
obj.sprite.height = obj.h;
},

buildSpriteAsync: async function (config) {
const { sheetName, cell, container, layerName, visible } = config;

const sprite = new PIXI.Sprite();
sprite.visible = visible;

const textureExists = this.textures.hasOwnProperty(sheetName);
if (!textureExists)
await this.loadTexture(sheetName);

sprite.texture = this.getTexture(sheetName, cell);

const spriteContainer = container || this.layers[layerName || sheetName];
spriteContainer.addChild(sprite);

return sprite;
},

buildObject: function (obj) {
const { sheetName, parent: container, layerName, visible = true } = obj;



+ 2
- 4
src/client/js/resources.js View File

@@ -8,11 +8,9 @@ define([

init: async function () {
const { sprites } = this;
const { clientConfig: { resourceList, textureList } } = globals;
const { clientConfig: { textureList } } = globals;

const fullList = [].concat(resourceList, textureList);

return Promise.all(fullList.map(s => {
return Promise.all(textureList.map(s => {
return new Promise(res => {
const spriteSource = s.includes('.png') ? s : `images/${s}.png`;



+ 8
- 30
src/client/js/system/client.js View File

@@ -1,9 +1,11 @@
define([
'socket',
'js/system/events'
'js/system/events',
'js/rendering/renderer'
], function (
io,
events
events,
renderer
) {
let client = {
doneConnect: false,
@@ -24,32 +26,6 @@ define([
});
},

onRezoneStart: function () {
//Fired for mods to listen to
events.emit('rezoneStart');

events.emit('destroyAllObjects');
events.emit('resetRenderer');
events.emit('resetPhysics');
events.emit('clearUis');

client.request({
threadModule: 'rezoneManager',
method: 'clientAck',
data: {}
});
},

onGetMap: function ([msg]) {
events.emit('onGetMap', msg);

client.request({
threadModule: 'instancer',
method: 'clientAck',
data: {}
});
},

onConnected: function (onReady) {
if (this.doneConnect)
this.onDisconnect();
@@ -93,8 +69,10 @@ define([
});
},

getMap: function (eventName, msgs) {
events.emit('onGetMap', msgs[0]);
getMap: async function (eventName, [msgMap]) {
await renderer.onGetMap(msgMap);

events.emit('onGetMap', msgMap);

client.request({
threadModule: 'instancer',


+ 64
- 71
src/server/clientComponents/lightPatch.js View File

@@ -1,122 +1,115 @@
define([
'js/rendering/renderer'
'js/rendering/renderer',
'js/system/globals'
], function (
renderer
renderer,
globals
) {
return {
type: 'lightPatch',

color: 'ffeb38',

patches: [],
rayContainers: [],
rays: [],

init: function (blueprint) {
this.blueprint = this.blueprint || {};

let obj = this.obj;
const { obj, patches, rayContainers, rays, color, isVisible } = this;
const { x, y } = obj;

let x = obj.x;
let y = obj.y;
const maxDistance = Math.sqrt(Math.pow(obj.width / 2, 2) + Math.pow(obj.height / 2, 2));

let maxDistance = Math.sqrt(Math.pow(obj.width / 3, 2) + Math.pow(obj.height / 3, 2));
for (let i = 0; i < obj.width; i++) {
for (let j = 0; j < obj.height; j++) {
let distance = maxDistance - Math.sqrt(Math.pow((obj.width / 2) - i, 2) + Math.pow((obj.width / 2) - j, 2));
const distance = maxDistance - Math.sqrt(Math.pow((obj.width / 3) - i, 2) + Math.pow((obj.width / 3) - j, 2));

const maxAlpha = (distance / maxDistance) * 0.2;
if (maxAlpha <= 0.05)
if (maxAlpha < 0.05)
continue;

let sprite = renderer.buildObject({
x: (x + i),
y: (y + j),
sheetName: 'white',
cell: 0,
layerName: 'lightPatches'
});
sprite.alpha = (maxAlpha * 0.3) + (Math.random() * (maxAlpha * 0.7));
sprite.tint = '0x' + this.color;

const size = (3 + ~~(Math.random() * 6)) * scaleMult;

sprite.width = size;
sprite.height = size;
sprite.x += scaleMult * ~~(Math.random() * 4);
sprite.y += scaleMult * ~~(Math.random() * 4);

sprite.blendMode = PIXI.BLEND_MODES.ADD;
const patch = globals.objects.buildObject({
x: ((x + i) * scale) + (scaleMult * ~~(Math.random() * 4)),
y: ((y + j) * scale) + (scaleMult * ~~(Math.random() * 4)),
width: size,
height: size,
visible: isVisible,
components: [{
type: 'sprite',
sheetName: 'white',
cell: 0,
layerName: 'lightPatches',
alpha: (maxAlpha * 0.3) + (Math.random() * (maxAlpha * 0.7)),
tint: '0x' + color,
blendMode: PIXI.BLEND_MODES.ADD
}]
});

this.patches.push(sprite);
patches.push(patch);
}
}

let rCount = ((obj.width * obj.height) / 10) + ~~(Math.random() + 2);
const rCount = ((obj.width * obj.height) / 10) + ~~(Math.random() + 2);
for (let i = 0; i < rCount; i++) {
let nx = x + 3 + ~~(Math.random() * (obj.width - 1));
let ny = y - 4 + ~~(Math.random() * (obj.height));
let w = 1 + ~~(Math.random() * 2);
let h = 6 + ~~(Math.random() * 13);
let hm = 2;
const nx = x + 3 + ~~(Math.random() * (obj.width - 1));
const ny = y - 4 + ~~(Math.random() * (obj.height));
const w = 1 + ~~(Math.random() * 2);
const h = 6 + ~~(Math.random() * 13);
const hm = 2;

let rContainer = renderer.buildContainer({
const rayContainer = renderer.buildContainer({
layerName: 'lightBeams'
});
this.rays.push(rContainer);
rayContainers.push(rayContainer);

for (let j = 0; j < h; j++) {
let ray = renderer.buildObject({
x: nx,
y: ny,
cell: 0,
sheetName: 'white',
parent: rContainer
const ray = globals.objects.buildObject({
x: ~~((nx * scale) - (scaleMult * j)),
y: (ny * scale) + (scaleMult * j * hm),
width: w * scaleMult,
height: scaleMult * hm,
visible: isVisible,
components: [{
type: 'sprite',
sheetName: 'white',
cell: 0,
parent: rayContainer,
alpha: ((1.0 - (j / h)) * 0.4),
tint: 0xffeb38,
blendMode: PIXI.BLEND_MODES.ADD
}]
});
ray.x = ~~((nx * scale) - (scaleMult * j));
ray.y = (ny * scale) + (scaleMult * j * hm);
ray.alpha = ((1.0 - (j / h)) * 0.4);
ray.width = w * scaleMult;
ray.height = scaleMult * hm;
ray.tint = 0xffeb38;
ray.blendMode = PIXI.BLEND_MODES.ADD;

rays.push(ray);
}
}

this.setVisible(this.obj.isVisible);
},

update: function () {
let rays = this.rays;
let rLen = rays.length;
for (let i = 0; i < rLen; i++) {
let r = rays[i];
const { rays } = this;

rays.forEach(r => {
r.alpha += (Math.random() * 0.03) - 0.015;

if (r.alpha < 0.3)
r.alpha = 0.3;
else if (r.alpha > 1)
r.alpha = 1;
}
},

setVisible: function (visible) {
this.patches.forEach(function (p) {
p.visible = visible;
});

this.rays.forEach(function (r) {
r.visible = visible;
});
},

destroy: function () {
this.patches.forEach(function (p) {
p.parent.removeChild(p);
setVisible: function (isVisible) {
const { rays, patches } = this;

rays.forEach(r => {
r.visible = isVisible;
});
this.patches = [];

this.rays.forEach(function (r) {
r.parent.removeChild(r);
patches.forEach(p => {
p.visible = isVisible;
});
this.rays = [];
}
};
});

+ 61
- 0
src/server/clientComponents/sprite.js View File

@@ -0,0 +1,61 @@
define([
'js/rendering/renderer'
], function (
renderer
) {
return {
type: 'sprite',

sprite: null,

init: function (blueprint) {
this.buildSprite();
},

buildSprite: async function () {
const { layerName, sheetName, cell, parent: container } = this;

this.sprite = await renderer.buildSpriteAsync({
sheetName,
cell,
container,
layerName,
visible: false
});
},

update: function () {
const { sprite, obj } = this;

if (!sprite)
return;

[
'x',
'y',
'visible',
'width',
'height'
].forEach(p => {
const value = obj[p];

if (sprite[p] !== value)
sprite[p] = value;
});

[
'alpha',
'tint'
].forEach(p => {
const value = this[p];

if (sprite[p] !== value)
sprite[p] = value;
});
},

destroy: function () {
}
};
});

+ 1
- 62
src/server/config/clientConfig.js View File

@@ -1,5 +1,3 @@
const imageSize = require('image-size');

const events = require('../misc/events');
const fileLister = require('../misc/fileLister');
const tos = require('./tos');
@@ -7,24 +5,9 @@ const tos = require('./tos');
const config = {
logoPath: null,
loginBgGeneratorPath: null,
resourceList: [],
textureList: [

],
//Textures that are 24x24. The renderer needs to know this
bigTextures: [

'tilesLoginBg'
],
atlasTextureDimensions: {},
atlasTextures: [

],
spriteSizes: {
'images/tiles.png': 8,
'images/walls.png': 8,
'images/objects.png': 8,
'images/mobs.png': 8
},
blockingTileIndices: {
tiles: [6, 7, 54, 55, 62, 63, 154, 189, 190, 192, 193, 194, 195, 196, 197]
},
@@ -213,50 +196,6 @@ module.exports = {
events.emit('onBeforeGetContextMenuActions', config.contextMenuActions);
events.emit('onBeforeGetTermsOfService', config.tos);
events.emit('onBeforeGetTextureList', config.textureList);

await this.calculateAtlasTextureDimensions();
},

//The client needs to know this as well as the map loader
calculateAtlasTextureDimensions: async function () {
const { atlasTextures, atlasTextureDimensions } = config;

for (const tex of atlasTextures) {
if (atlasTextureDimensions[tex])
return;

const path = tex.includes('.png') ? `../${tex}` : `../client/images/${tex}.png`;
const dimensions = await imageSize(path);

delete dimensions.type;

atlasTextureDimensions[tex] = dimensions;
}
},

getTileIndexInAtlas: async function (spriteSheet, tileIndexInSource) {
const { atlasTextures, atlasTextureDimensions } = config;

//We need to perform this check because once mods start adding sheets to atlasTextures,
// things get out of control. We need to fix this in the future as it will become screwy.
if (Object.keys(atlasTextureDimensions).length !== atlasTextures)
await this.calculateAtlasTextureDimensions();

const indexOfSheet = atlasTextures.indexOf(spriteSheet);

let tileCountBeforeSheet = 0;

for (let i = 0; i < indexOfSheet; i++) {
const sheet = atlasTextures[i];
const { width, height } = atlasTextureDimensions[sheet];

tileCountBeforeSheet += ((width / 8) * (height / 8));
}

//Tile index 0 is 'no tile' in map files so we need to increment by 1
const result = tileCountBeforeSheet + tileIndexInSource + 1;

return result;
},

//Used to send to clients


+ 272
- 2136
src/server/config/maps/cave/map.json
File diff suppressed because it is too large
View File


+ 0
- 5
src/server/mods/class-necromancer/index.js View File

@@ -12,7 +12,6 @@ module.exports = {
this.events.on('onBeforeGetSpellsInfo', this.beforeGetSpellsInfo.bind(this));
this.events.on('onBeforeGetSpellsConfig', this.beforeGetSpellsConfig.bind(this));
this.events.on('onBeforeGetSpellTemplate', this.beforeGetSpellTemplate.bind(this));
this.events.on('onBeforeGetClientConfig', this.onBeforeGetClientConfig.bind(this));
this.events.on('onBeforeGetAnimations', this.beforeGetAnimations.bind(this));
this.events.on('onAfterGetZone', this.onAfterGetZone.bind(this));
},
@@ -75,10 +74,6 @@ module.exports = {
};
},

onBeforeGetClientConfig: function ({ resourceList }) {
resourceList.push(`${this.folderName}/images/abilityIcons.png`);
},

beforeGetSpellTemplate: function (spell) {
if (spell.type === 'HarvestLife')
spell.template = require('./spells/spellHarvestLife');


+ 0
- 16
src/server/package-lock.json View File

@@ -1557,14 +1557,6 @@
"resolved": "https://registry.npmjs.org/image-q/-/image-q-1.1.1.tgz",
"integrity": "sha1-/IQJlmRGC5DKhi2TALa/u7+/gFY="
},
"image-size": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/image-size/-/image-size-1.0.0.tgz",
"integrity": "sha512-JLJ6OwBfO1KcA+TvJT+v8gbE6iWbj24LyDNFgFEN0lzegn6cC6a/p3NIDaepMsJjQjlUWqIC7wJv8lBFxPNjcw==",
"requires": {
"queue": "6.0.2"
}
},
"import-fresh": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz",
@@ -1997,14 +1989,6 @@
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
},
"queue": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/queue/-/queue-6.0.2.tgz",
"integrity": "sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==",
"requires": {
"inherits": "~2.0.3"
}
},
"range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",


+ 0
- 1
src/server/package.json View File

@@ -8,7 +8,6 @@
"compression": "^1.7.4",
"express": "^4.17.1",
"express-minify": "^1.0.0",
"image-size": "^1.0.0",
"jimp": "^0.16.1",
"rethinkdbdash": "^2.3.31",
"socket.io": "^4.2.0",


+ 0
- 14
src/server/world/map.js View File

@@ -319,20 +319,6 @@ module.exports = {
}
},

getOffsetCellPos: function (sheetName, cell) {
const { config: { atlasTextureDimensions, atlasTextures } } = clientConfig;
const indexInAtlas = atlasTextures.indexOf(sheetName);

let offset = 0;
for (let i = 0; i < indexInAtlas; i++) {
const dimensions = atlasTextureDimensions[atlasTextures[i]];

offset += (dimensions.width / 8) * (dimensions.height / 8);
}

return cell + offset;
},

getCellInfo: function (gid, x, y, layerName) {
const cellInfoMsg = {
mapName: this.name,


+ 5
- 7
src/server/world/map/builders/object.js View File

@@ -6,8 +6,6 @@ const resourceSpawner = require('../../resourceSpawner');
const mapObjects = require('../mapObjects');
const getObjectifiedProperties = require('../getObjectifiedProperties');

const spriteBuilder = require('../../spriteBuilder/index');

//Helpers
const buildRoom = (mapModule, blueprint) => {
if (blueprint.properties.exit) {
@@ -32,12 +30,12 @@ const buildRoom = (mapModule, blueprint) => {

const buildHiddenRoom = (mapModule, blueprint) => {
const { mapFile } = mapModule;
const { cell } = blueprint;
const { properties } = blueprint;

blueprint.fog = (cell.properties || {}).fog;
blueprint.interior = (cell.properties || {}).interior;
blueprint.discoverable = (cell.properties || {}).discoverable;
blueprint.layer = ~~((cell.properties || {}).layer || 0);
blueprint.fog = (properties || {}).fog;
blueprint.interior = (properties || {}).interior;
blueprint.discoverable = (properties || {}).discoverable;
blueprint.layer = ~~((properties || {}).layer || 0);

if (!mapFile.properties.isRandom)
mapModule.hiddenRooms.push(blueprint);


+ 0
- 2
src/server/world/map/builders/tile.js View File

@@ -18,8 +18,6 @@ const buildTile = (mapModule, tileInfo) => {

const offsetCell = spriteBuilder.track(cellInfo);

//const offsetCell = mapModule.getOffsetCellPos(tileInfo.sheetName, cellInfo.cell);

const isHiddenLayer = layerName.indexOf('hidden') === 0;

if (isHiddenLayer)


Loading…
Cancel
Save