Skip to content

Commit e39b2dc

Browse files
Merge pull request #1402 from solaris-games/dev
Update 251.1
2 parents 0063338 + f5431dd commit e39b2dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1882
-1496
lines changed

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@popperjs/core": "^2.11.5",
15-
"axios": "^1.7.4",
15+
"axios": "^1.8.3",
1616
"bootstrap": "^5.1.3",
1717
"chart.js": "^4.4.3",
1818
"jquery": "^3.6.0",

client/src/game/carrier.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { Container, Sprite, Graphics, BitmapText, Circle, TextStyle, Text } from 'pixi.js'
22
import TextureService from './texture'
33
import Helpers from './helpers'
4-
import {EventEmitter} from "./eventEmitter.js";
54
import type PathManager from "./PathManager";
6-
import type {UserGameSettings} from "@solaris-common";
5+
import type {UserGameSettings, Location} from "@solaris-common";
76
import type {Carrier as CarrierData, Player as PlayerData} from "../types/game";
87
import type Star from "./star";
98
import type {DrawingContext} from "./container";
9+
import { MapObject } from './mapObject';
1010

11-
export class Carrier extends EventEmitter {
11+
export class Carrier extends MapObject {
1212
static zoomLevel = 140
1313

1414
container: Container;
15-
fixedContainer: Container;
1615
graphics_colour: Sprite | null;
1716
graphics_selected: Graphics;
1817
graphics_ship: Sprite;
@@ -39,7 +38,6 @@ export class Carrier extends EventEmitter {
3938
constructor ( pathManager: PathManager ) {
4039
super()
4140

42-
this.fixedContainer = new Container() // this container isnt affected by culling or user setting scalling
4341
this.container = new Container()
4442
this.container.zIndex = 1
4543
this.container.eventMode = 'static'
@@ -66,6 +64,14 @@ export class Carrier extends EventEmitter {
6664
this.zoomPercent = 100
6765
}
6866

67+
getContainer(): Container {
68+
return this.container!;
69+
}
70+
71+
getLocation(): Location {
72+
return this.data!.location!;
73+
}
74+
6975
setup (data, userSettings, context: DrawingContext, stars, player, lightYearDistance) {
7076
this.data = data
7177
this.stars = stars
@@ -400,7 +406,6 @@ export class Carrier extends EventEmitter {
400406

401407
destroy () {
402408
this.container.destroy()
403-
this.fixedContainer.destroy()
404409
}
405410

406411
select () {

client/src/game/chunks.ts

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import { Container, Graphics } from 'pixi.js';
2+
import type { Game } from '../types/game';
3+
import gameHelper from '../services/gameHelper'
4+
import type Star from './star';
5+
import type Carrier from './carrier';
6+
import type { MapObject } from './mapObject';
7+
8+
const CHUNK_SIZE = 256
9+
10+
class Chunk extends Container {
11+
mapObjects: MapObject[] = [];
12+
visualizer: Graphics | undefined = undefined;
13+
14+
constructor() {
15+
super();
16+
17+
this.sortableChildren = true;
18+
}
19+
}
20+
21+
export class Chunks {
22+
chunks: Chunk[][] = [];
23+
numof_chunkX: number = 0;
24+
numof_chunkY: number = 0;
25+
firstChunkX: number = 0;
26+
firstChunkY: number = 0;
27+
lastChunkX: number = 0;
28+
lastChunkY: number = 0;
29+
minMouseChunkX: number = 0;
30+
maxMouseChunkX: number = 0;
31+
minMouseChunkY: number = 0;
32+
maxMouseChunkY: number = 0;
33+
chunksContainer: Container;
34+
35+
constructor() {
36+
this.chunksContainer = new Container()
37+
this.chunksContainer.zIndex = 7;
38+
}
39+
40+
setup(game: Game, stars: Star[], carriers: Carrier[]) {
41+
this.chunksContainer.removeChildren();
42+
43+
const carrierMinX = gameHelper.calculateMinCarrierX(game)
44+
const carrierMinY = gameHelper.calculateMinCarrierY(game)
45+
const carrierMaxX = gameHelper.calculateMaxCarrierX(game)
46+
const carrierMaxY = gameHelper.calculateMaxCarrierY(game)
47+
48+
const starMinX = gameHelper.calculateMinStarX(game)
49+
const starMinY = gameHelper.calculateMinStarY(game)
50+
const starMaxX = gameHelper.calculateMaxStarX(game)
51+
const starMaxY = gameHelper.calculateMaxStarY(game)
52+
53+
const minX = Math.min(carrierMinX, starMinX)
54+
const minY = Math.min(carrierMinY, starMinY)
55+
const maxX = Math.max(carrierMaxX, starMaxX)
56+
const maxY = Math.max(carrierMaxY, starMaxY)
57+
58+
this.firstChunkX = Math.floor(minX / CHUNK_SIZE)
59+
this.firstChunkY = Math.floor(minY / CHUNK_SIZE)
60+
61+
this.lastChunkX = Math.floor(maxX / CHUNK_SIZE)
62+
this.lastChunkY = Math.floor(maxY / CHUNK_SIZE)
63+
64+
this.numof_chunkX = this.lastChunkX - this.firstChunkX + 1
65+
this.numof_chunkY = this.lastChunkY - this.firstChunkY + 1
66+
67+
let chunkColumns = Array(this.numof_chunkX)
68+
for (let i = 0; i < this.numof_chunkX; i++) { chunkColumns[i] = Array(this.numof_chunkY) }
69+
70+
this.chunks = chunkColumns
71+
72+
for (let ix = 0; ix < this.numof_chunkX; ix++) {
73+
for (let iy = 0; iy < this.numof_chunkY; iy++) {
74+
this.chunks[ix][iy] = new Chunk();
75+
this.chunksContainer!.addChild(this.chunks[ix][iy])
76+
}
77+
}
78+
79+
stars.forEach(s => this.addContainerToChunk(s, this.firstChunkX, this.firstChunkY))
80+
carriers.forEach(c => this.addContainerToChunk(c, this.firstChunkX, this.firstChunkY))
81+
}
82+
83+
onTick (positionChanging: boolean, zoomChanging: boolean, zoomPercent: number, viewport: { left: number, right: number, bottom: number, top: number }) {
84+
const firstX = Math.floor(viewport.left/CHUNK_SIZE)
85+
const firstY = Math.floor(viewport.top/CHUNK_SIZE)
86+
87+
const lastX = Math.floor(viewport.right/CHUNK_SIZE)
88+
const lastY = Math.floor(viewport.bottom/CHUNK_SIZE)
89+
90+
if (!positionChanging && !zoomChanging) {
91+
return;
92+
}
93+
94+
for(let ix=0; ix<this.numof_chunkX; ix++) {
95+
for(let iy=0; iy<this.numof_chunkY; iy++) {
96+
if(
97+
(ix>=(firstX-this.firstChunkX))&&(ix<=(lastX-this.firstChunkX)) &&
98+
(iy>=(firstY-this.firstChunkY))&&(iy<=(lastY-this.firstChunkY))
99+
)
100+
{
101+
if( !this.chunks[ix][iy].visible ) {
102+
this.chunks[ix][iy].visible = true
103+
this.chunks[ix][iy].interactiveChildren = true
104+
//this.chunks[ix][iy].visualizer.visible = true
105+
for( let mapObject of this.chunks[ix][iy].mapObjects ) {
106+
mapObject.onZoomChanging(zoomPercent)
107+
}
108+
}
109+
else {
110+
if( zoomChanging ) {
111+
for( let mapObject of this.chunks[ix][iy].mapObjects ) {
112+
mapObject.onZoomChanging(zoomPercent)
113+
}
114+
}
115+
}
116+
}
117+
else {
118+
this.chunks[ix][iy].visible = false
119+
this.chunks[ix][iy].interactiveChildren = false
120+
//this.chunks[ix][iy].visualizer.visible = false
121+
}
122+
}
123+
}
124+
}
125+
126+
addContainerToChunk(mapObject: MapObject, firstX: number, firstY: number) { // Star or carrier
127+
const chunkX = Math.floor(mapObject.getLocation().x / CHUNK_SIZE)
128+
const chunkY = Math.floor(mapObject.getLocation().y / CHUNK_SIZE)
129+
const ix = chunkX - firstX
130+
const iy = chunkY - firstY
131+
132+
this.chunks[ix][iy].addChild(mapObject.getContainer())
133+
this.chunks[ix][iy].mapObjects.push(mapObject)
134+
}
135+
136+
removeContainerFromChunk(mapObject: MapObject, chunks: Chunk[][], firstX: number, firstY: number) {
137+
const chunkX = Math.floor(mapObject.getLocation().x / CHUNK_SIZE)
138+
const chunkY = Math.floor(mapObject.getLocation().y / CHUNK_SIZE)
139+
const ix = chunkX - firstX
140+
const iy = chunkY - firstY
141+
142+
chunks[ix][iy].removeChild(mapObject.getContainer())
143+
const index = chunks[ix][iy].mapObjects.indexOf(mapObject)
144+
if (index > -1) { chunks[ix][iy].mapObjects.splice(index, 1) }
145+
}
146+
147+
removeMapObjectFromChunks(mapObject: MapObject) {
148+
for (let chunkX of this.chunks) {
149+
for (let chunkY of chunkX) {
150+
if (chunkY.mapObjects.indexOf(mapObject) > -1) {
151+
chunkY.mapObjects.splice(chunkY.mapObjects.indexOf(mapObject), 1)
152+
chunkY.removeChild(mapObject.getContainer())
153+
}
154+
}
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)