Skip to content

Commit

Permalink
rewrite drawlink
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyangXYZ committed Dec 23, 2023
1 parent 98404c3 commit f4f2e24
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
24 changes: 11 additions & 13 deletions src/hooks/useDrawTopology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,27 +399,24 @@ export function useDrawTopology(dom: HTMLElement) {

const drawEndSystems = () => {}

let drawnLinks: any = {}
let drawnLinks: { [uid: number]: any } = {}
const drawLinks = () => {
for (const n of Network.Nodes.value) {
for (const nn of n.neighbors) {
const linkName = n.id < nn ? `${n.id}-${nn}` : `${nn}-${n.id}`
if (drawnLinks[linkName] == undefined) {
drawLink(n.id, nn, linkName)
}
for (const l of Network.Links.value) {
if (drawnLinks[l.uid] == undefined) {
drawLink(l.uid, l.v1, l.v2)
}
}
}
const drawLink = (src: number, dst: number, name: string) => {
const drawLink = (uid: number, v1: number, v2: number) => {
const p1 = new THREE.Vector3(
Network.Nodes.value[src].pos[0],
Network.Nodes.value[v1].pos[0],
1.6,
Network.Nodes.value[src].pos[1]
Network.Nodes.value[v1].pos[1]
)
const p3 = new THREE.Vector3(
Network.Nodes.value[dst].pos[0],
Network.Nodes.value[v2].pos[0],
1.6,
Network.Nodes.value[dst].pos[1]
Network.Nodes.value[v2].pos[1]
)

const x2 = (p1.x + p3.x) / 2
Expand All @@ -434,7 +431,7 @@ export function useDrawTopology(dom: HTMLElement) {
new THREE.LineBasicMaterial({ color: 'white' })
)
scene.add(mesh)
drawnLinks[name] = { mesh, src, dst }
drawnLinks[uid] = { mesh, v1, v2 }
}
const clearLinks = () => {
for (const i in drawnLinks) {
Expand Down Expand Up @@ -630,6 +627,7 @@ export function useDrawTopology(dom: HTMLElement) {
addLights()
drawGround()
drawNodes()
drawLinks()
// draw5GTower()
animate()

Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import { ref } from 'vue'

// import { TSCHNetwork } from '@/networks/TSCH/network'
// export const Network = new TSCHNetwork()
import { TSCHNetwork } from '@/networks/TSCH/network'
export const Network = new TSCHNetwork()

// import { TSNNetwork } from '@/networks/TSN/network'
// export const Network = new TSNNetwork()

import { FiveGNetwork } from '@/networks/5G/network'
export const Network = new FiveGNetwork()
// import { FiveGNetwork } from '@/networks/5G/network'
// export const Network = new FiveGNetwork()

export const SelectedNode = ref(1)
export const MiniMapMode = ref('scatter')
Expand Down
5 changes: 4 additions & 1 deletion src/networks/5G/network.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ref } from 'vue'
import { Network, NetworkType, NODE_TYPE } from '../common'
import { Network, NetworkType, NODE_TYPE, type LinkMeta } from '../common'
import type { ScheduleConfig, FiveGNodeMeta } from './typedefs'
import { SeededRandom } from '@/hooks/useSeed'

Expand Down Expand Up @@ -53,6 +53,9 @@ export class FiveGNetwork extends Network {
rx_cnt: 0,
w: new Worker(new URL('@/networks/5G/node.ts', import.meta.url), { type: 'module' })
}
// add links
this.Links.value.push(<LinkMeta>{ uid: i * 3, v1: 0, v2: i })

// send init msg
// n.w!.postMessage(<Message>{
// type: MSG_TYPES.INIT,
Expand Down
8 changes: 6 additions & 2 deletions src/networks/TSCH/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import type {
import { ADDR, MSG_TYPES, PKT_TYPES, CELL_TYPES } from './typedefs'
import { SeededRandom } from '@/hooks/useSeed'
import { Network, NetworkType, NODE_TYPE } from '../common'
import type { Packet, Message, MsgHandler } from '../common'
import type { Packet, Message, MsgHandler, LinkMeta } from '../common'

export class TSCHNetwork extends Network {

doneCnt = 0

msgHandlers: { [type: number]: MsgHandler } = {}
Expand Down Expand Up @@ -82,6 +81,11 @@ export class TSCHNetwork extends Network {
this.Nodes.value[node].parent = payload.parent
this.Nodes.value[node].neighbors.push(payload.parent)
this.Nodes.value[payload.parent].neighbors.push(node)
this.Links.value.push(<LinkMeta>{
uid: node * 2 + payload.parent * 3,
v1: node,
v2: payload.parent
})
}

this.Nodes.value[node].queueLen = payload.queue.length
Expand Down
8 changes: 8 additions & 0 deletions src/networks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class Network {
ID: number
Type: number
Nodes: any
Links = ref<LinkMeta[]>([])
EndSystems: any
TopoConfig: Ref<TopologyConfig>
SchConfig: any
Expand Down Expand Up @@ -79,6 +80,13 @@ export interface NodeMeta {
w: Worker | undefined
}

export interface LinkMeta {
// undirected link for visualization
uid: number // uid=v1*2+v2*3
v1: number
v2: number
}

export enum END_SYSTEM_TYPE {
Server,
RoboticArm,
Expand Down

0 comments on commit f4f2e24

Please sign in to comment.