Skip to content

Commit

Permalink
introduced standard js style
Browse files Browse the repository at this point in the history
  • Loading branch information
aidatorajiro committed Mar 22, 2018
1 parent 7f8f7a0 commit af87bb5
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 189 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
"license": "MIT",
"devDependencies": {
"electron": "1.7.9",
"electron-packager": "^11.0.1"
"electron-packager": "^11.0.1",
"standard": "^11.0.1"
},
"dependencies": {
"ffi": "^2.2.0",
"three": "^0.88.0"
},
"standard": {
"globals": [ "THREE", "requestAnimationFrame" ]
}
}
8 changes: 4 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*/

const Game = require("./Game.js")
const Globals = require("./Globals.js")
const Game = require('./Game.js')
const Globals = require('./Globals.js')

window.addEventListener("load", function () {
window.addEventListener('load', function () {
Globals.game = new Game()
Globals.game.init()
})
})
24 changes: 12 additions & 12 deletions src/Character.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*/

const THREE = require("three")
const Globals = require("./Globals")
const THREE = require('three')
const Globals = require('./Globals')

class Character {
constructor () {
Expand All @@ -17,19 +17,19 @@ class Character {
this.velocity = new THREE.Vector2(0, 0)
this.coordinate = new THREE.Vector2(0, 0)

this.material = new THREE.MeshBasicMaterial( { color: 0xffffff } )
this.geometry = new THREE.CircleGeometry( 2.5, 32 )
this.mesh = new THREE.Mesh( this.geometry, this.material )
this.material = new THREE.MeshBasicMaterial({ color: 0xffffff })
this.geometry = new THREE.CircleGeometry(2.5, 32)
this.mesh = new THREE.Mesh(this.geometry, this.material)

Globals.scene.add( this.mesh )
Globals.scene.add(this.mesh)
}

// click event handler
// input: click event position on window
on_click (vec) {
onClick (vec) {
this.eases.push([new THREE.Vector2(
Math.atan((vec.x-Globals.width/2)*0.04)*0.03,
Math.atan((-vec.y+Globals.height/2)*0.04)*0.03
Math.atan((vec.x - Globals.width / 2) * 0.04) * 0.03,
Math.atan((-vec.y + Globals.height / 2) * 0.04) * 0.03
), this.time])
}

Expand All @@ -41,8 +41,8 @@ class Character {
let coefficient = i[0]
let t = this.time - i[1] - 5

this.velocity.x += coefficient.x / (0.1*t*t + 1)
this.velocity.y += coefficient.y / (0.1*t*t + 1)
this.velocity.x += coefficient.x / (0.1 * t * t + 1)
this.velocity.y += coefficient.y / (0.1 * t * t + 1)
}

this.velocity.x *= 0.995
Expand All @@ -55,4 +55,4 @@ class Character {
}
}

module.exports = Character
module.exports = Character
2 changes: 1 addition & 1 deletion src/Config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module.exports = {
}
}
10 changes: 10 additions & 0 deletions src/Footprints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Footprints {
constructor () {

}
update () {

}
}

module.exports = Footprints
59 changes: 29 additions & 30 deletions src/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,76 @@ This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*/

const electron = require('electron')
const win = electron.remote.getCurrentWindow()
const ProcessView = require('./ProcessView')
const ProcessSelect = require('./ProcessSelect')
const Character = require('./Character')
const Footprints = require('./Footprints')

const ProcessView = require("./ProcessView")
const ProcessSelect = require("./ProcessSelect")
const Character = require("./Character")

const Globals = require("./Globals.js")
const Config = require("./Config.js")
const Globals = require('./Globals.js')

class Game {
init () {
// camera / scene / renderer preparation
Globals.camera = new THREE.OrthographicCamera( Globals.width/-2, Globals.width/2, Globals.height/2, Globals.height/-2, 1, 2000 )
Globals.camera = new THREE.OrthographicCamera(Globals.width / -2, Globals.width / 2, Globals.height / 2, Globals.height / -2, 1, 2000)
Globals.camera.position.z = 500

Globals.scene = new THREE.Scene()

Globals.renderer = new THREE.WebGLRenderer( { antialias: false } )
Globals.renderer.setSize( Globals.width, Globals.height )
document.body.appendChild( Globals.renderer.domElement )
Globals.renderer = new THREE.WebGLRenderer({ antialias: false })
Globals.renderer.setSize(Globals.width, Globals.height)
document.body.appendChild(Globals.renderer.domElement)

// event handlers
window.addEventListener('resize', () => { this.resize() }, false )
window.addEventListener('resize', () => { this.resize() }, false)

window.addEventListener( 'mousedown', function (ev) {
Globals.character.on_click(new THREE.Vector2(ev.clientX, ev.clientY))
window.addEventListener('mousedown', function (ev) {
Globals.character.onClick(new THREE.Vector2(ev.clientX, ev.clientY))
}, false)

// construct objects
Globals.character = new Character()
Globals.process_select = new ProcessSelect()
Globals.processSelect = new ProcessSelect()
Globals.footprints = new Footprints()

// call animate func
this.last_time = 0
requestAnimationFrame( (time) => { this.animate(time) } )
requestAnimationFrame((time) => { this.animate(time) })
}

resize () {
Globals.renderer.setSize(Globals.width, Globals.height)
Globals.camera.left = Globals.width/-2
Globals.camera.right = Globals.width/2
Globals.camera.top = Globals.height/2
Globals.camera.bottom = Globals.height/-2
Globals.camera.left = Globals.width / -2
Globals.camera.right = Globals.width / 2
Globals.camera.top = Globals.height / 2
Globals.camera.bottom = Globals.height / -2
Globals.camera.updateProjectionMatrix()
}

animate (time) {
Globals.delta = time - this.last_time
this.last_time = time

Globals.renderer.render( Globals.scene, Globals.camera )
Globals.renderer.render(Globals.scene, Globals.camera)

Globals.camera.position.x = Globals.character.coordinate.x
Globals.camera.position.y = Globals.character.coordinate.y

Globals.character.update()
Globals.footprints.update()

if (Globals.process_select.finished == false) {
Globals.process_select.update()
if (Globals.processSelect.finished === false) {
Globals.processSelect.update()
}

if (Globals.process_select.selected == true) {
if (Globals.process_view === undefined) {
Globals.process_view = new ProcessView(Globals.process_select.pid)
if (Globals.processSelect.selected === true) {
if (Globals.processView === undefined) {
Globals.processView = new ProcessView(Globals.processSelect.pid)
}
Globals.process_view.update()
Globals.processView.update()
}

requestAnimationFrame( (time) => { this.animate(time) } )
requestAnimationFrame((time) => { this.animate(time) })
}
}

module.exports = Game
module.exports = Game
7 changes: 4 additions & 3 deletions src/Globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ module.exports = {
camera: undefined,
renderer: undefined,
game: undefined,
process_select: undefined,
process_view: undefined,
processSelect: undefined,
processView: undefined,
character: undefined,
footprints: undefined,
get width () {
return window.innerWidth
},
get height () {
return window.innerHeight
}
}
}
103 changes: 53 additions & 50 deletions src/MacMemory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,94 @@ This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*/

const ref = require('ref');
const ffi = require('ffi');
const Struct = require('ref-struct');
const ref = require('ref')
const ffi = require('ffi')
const Struct = require('ref-struct')

let RegionInfo = Struct({
'protection': 'uint32',
'max_protection': 'uint32',
'inheritance': 'uint32',
'shared': 'uint32',
'reserved': 'uint32',
'offset': 'ulonglong',
'behavior': 'uint32',
'protection': 'uint32',
'max_protection': 'uint32',
'inheritance': 'uint32',
'shared': 'uint32',
'reserved': 'uint32',
'offset': 'ulonglong',
'behavior': 'uint32',
'user_wired_count': 'ushort'
});
})

let RegionInfoPtr = ref.refType(RegionInfo);
let RegionInfoPtr = ref.refType(RegionInfo)

let libc = ffi.Library("libc", {
"mach_task_self": ["uint", []],
"task_for_pid": ["int", ["uint", "int", "*uint"]],
"mach_vm_region": ["int", ["uint", "*ulong", "*ulong", "int", RegionInfoPtr, "*uint32", "*uint32"]],
"mach_vm_read": ["int", ["uint", "ulonglong", "ulonglong", "*void", "*uint32"]]
let libc = ffi.Library('libc', {
'mach_task_self': ['uint', []],
'task_for_pid': ['int', ['uint', 'int', '*uint']],
'mach_vm_region': ['int', ['uint', '*ulong', '*ulong', 'int', RegionInfoPtr, '*uint32', '*uint32']],
'mach_vm_read': ['int', ['uint', 'ulonglong', 'ulonglong', '*void', '*uint32']]
})

class Memory {
constructor(pid) {
let task_ref = ref.alloc("uint", 0)
constructor (pid) {
let taskRef = ref.alloc('uint', 0)
let mytask = libc.mach_task_self()
let ret = libc.task_for_pid(mytask, pid, task_ref)
if (ret != 0) {
throw new Error("task_for_pid error " + ret);
let ret = libc.task_for_pid(mytask, pid, taskRef)
if (ret !== 0) {
throw new Error('task_for_pid error ' + ret)
}

this.task = task_ref.deref()
this.task = taskRef.deref()
}
get_regions() {

getRegions () {
let regions = []
let address = ref.alloc("ulong", 0)
let mapsize = ref.alloc("ulong", 0)
let name = ref.alloc("uint32", 0)
let count = ref.alloc("uint32", RegionInfo.size / 4)
let info = new RegionInfo()
let address = ref.alloc('ulong', 0)
let mapsize = ref.alloc('ulong', 0)
let name = ref.alloc('uint32', 0)
let count = ref.alloc('uint32', RegionInfo.size / 4)
let info = new RegionInfo()

while (true) {
let ret = libc.mach_vm_region(this.task, address, mapsize, 9, info.ref(), count, name)
if (ret == 1) {
break;
if (ret === 1) {
break
}
if (ret != 0) {
throw new Error("mach_vm_region error " + ret)
if (ret !== 0) {
throw new Error('mach_vm_region error ' + ret)
}

regions.push([address.deref(), mapsize.deref()])

address.writeUInt64LE(address.deref() + mapsize.deref())
}
return regions;

return regions
}

read(address, length) {
let detaref = ref.alloc("*void")
let cnt = ref.alloc("uint32", 0)
read (address, length) {
let detaref = ref.alloc('*void')
let cnt = ref.alloc('uint32', 0)

let ret = libc.mach_vm_read(this.task, address, length, detaref, cnt)
if (ret != 0) {
throw new Error("mach_vm_read error " + ret)
if (ret !== 0) {
throw new Error('mach_vm_read error ' + ret)
}
return detaref.readPointer(0, length)
}

read_async(address, length) {
let detaref = ref.alloc("*void")
let cnt = ref.alloc("uint32", 0)
readAsync (address, length) {
let detaref = ref.alloc('*void')
let cnt = ref.alloc('uint32', 0)

return new Promise((resolve, reject) => {
libc.mach_vm_read.async(this.task, address, length, detaref, cnt, (err, ret) => {
if (ret != 0) {
reject("mach_vm_read error " + ret)
if (err) {
reject(new Error('mach_vm_read error ' + err))
}
if (ret !== 0) {
reject(new Error('mach_vm_read error ' + ret))
}
resolve(detaref.readPointer(0, length))
})
})
}
}

module.exports = Memory
module.exports = Memory
16 changes: 8 additions & 8 deletions src/Memory.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
if (process.platform == "darwin") {
module.exports = require("./MacMemory")
} else if (process.platform == "linux") {
throw new Error("not yet inplemented on linux")
} else if (process.platform == "win32") {
throw new Error("not yet inplemented on windows")
if (process.platform === 'darwin') {
module.exports = require('./MacMemory')
} else if (process.platform === 'linux') {
throw new Error('not yet inplemented on linux')
} else if (process.platform === 'win32') {
throw new Error('not yet inplemented on windows')
} else {
throw new Error("not yet inplemented on your operating system")
}
throw new Error('not yet inplemented on your operating system')
}
Loading

0 comments on commit af87bb5

Please sign in to comment.