Basic frame rendering
This commit is contained in:
parent
f4f2d95a62
commit
47e7356a9a
|
@ -54,41 +54,31 @@ func handleConn(conn *net.TCPConn) {
|
||||||
|
|
||||||
func serveClients() {
|
func serveClients() {
|
||||||
World = data.LoadLevel(LevelFile)
|
World = data.LoadLevel(LevelFile)
|
||||||
var oFrame = data.Frame{
|
fCounter := 0
|
||||||
1, 10,
|
|
||||||
[][]rune{
|
|
||||||
[]rune("hallo"),
|
|
||||||
[]rune("das"),
|
|
||||||
[]rune("ist"),
|
|
||||||
[]rune("einTest"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for { // while true
|
for { // while true
|
||||||
for _, k := range clientKeys {
|
for _, k := range clientKeys {
|
||||||
id, client := k, clients[k]
|
id, client := k, clients[k]
|
||||||
if id > 0 {
|
if id > 0 {
|
||||||
|
oFrame := World.GetFrame(0, client.w, fCounter)
|
||||||
|
fCounter++
|
||||||
enc := gob.NewEncoder(client.con)
|
enc := gob.NewEncoder(client.con)
|
||||||
err := enc.Encode(oFrame)
|
err := enc.Encode(oFrame)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// client disconnected
|
// client disconnected
|
||||||
|
|
||||||
//log.Println("BEFORE remove: clients:", clients, " clientKeys:", clientKeys)
|
//log.Println("BEFORE remove: clients:", clients, " clientKeys:", clientKeys)
|
||||||
|
|
||||||
// delete client
|
// delete client
|
||||||
delete(clients, client.id)
|
delete(clients, client.id)
|
||||||
|
|
||||||
// delete client key
|
// delete client key
|
||||||
// ugly as fuck in go to remove from a slice
|
// ugly as fuck in go to remove from a slice
|
||||||
// it *should* work though
|
// it *should* work though
|
||||||
idInKeys := sort.SearchInts(clientKeys, client.id)
|
idInKeys := sort.SearchInts(clientKeys, client.id)
|
||||||
clientKeys = append(clientKeys[:idInKeys], clientKeys[idInKeys+1:]...)
|
clientKeys = append(clientKeys[:idInKeys], clientKeys[idInKeys+1:]...)
|
||||||
|
|
||||||
//log.Println("AFTER remove: clients:", clients, " clientKeys:", clientKeys)
|
//log.Println("AFTER remove: clients:", clients, " clientKeys:", clientKeys)
|
||||||
}
|
}
|
||||||
//log.Println("ID:", id, "Client:", client)
|
//log.Println("ID:", id, "Client:", client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second / 25)
|
time.Sleep(time.Second / time.Duration(World.FPS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,3 +59,39 @@ func LoadLevel(filename string) *Level {
|
||||||
//log.Println(ret.Layers["locomotive"])
|
//log.Println(ret.Layers["locomotive"])
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (lvl *Level) Height() int {
|
||||||
|
max := 0
|
||||||
|
for _, l := range lvl.Layers {
|
||||||
|
for _, f := range l.Frames {
|
||||||
|
if len(f) > max {
|
||||||
|
max = len(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lvl *Level) GetFrame(off, w, frame int) (ret *Frame) {
|
||||||
|
//log.Println(ret)
|
||||||
|
h := lvl.Height()
|
||||||
|
|
||||||
|
ret = &Frame{
|
||||||
|
W: w,
|
||||||
|
H: h,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, l := range lvl.Layers {
|
||||||
|
if l.Z == 0 {
|
||||||
|
for i := 0; i < h; i++ {
|
||||||
|
ret.Data = append(ret.Data, []rune{})
|
||||||
|
f := (frame % len(l.Frames)) + 1
|
||||||
|
if i <= len(l.Frames[f]) {
|
||||||
|
ret.Data[i] = append(ret.Data[i], l.Frames[f][i]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{
|
{
|
||||||
"Name": "The locomotive!",
|
"Name": "The locomotive!",
|
||||||
"FPS": 10,
|
"FPS": 10,
|
||||||
"Layers" : {
|
"Layers" : {
|
||||||
|
@ -8,13 +8,7 @@
|
||||||
"Speed": 2,
|
"Speed": 2,
|
||||||
"Repeat": false,
|
"Repeat": false,
|
||||||
"Transparent": "•"
|
"Transparent": "•"
|
||||||
},
|
|
||||||
"background": {
|
|
||||||
"Z-Index": 1,
|
|
||||||
"Direction": 6,
|
|
||||||
"Speed": 1,
|
|
||||||
"Repeat": true,
|
|
||||||
"Transparent": "•"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user