This commit is contained in:
Robert Janetzko 2022-04-10 21:27:37 +00:00
parent 5d5ae57cc9
commit ef5c2ca337
6 changed files with 31 additions and 6 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
region*.xml
legendsbrowser
*.pprof
*.png

2
go.mod
View file

@ -5,5 +5,5 @@ go 1.18
require (
github.com/gorilla/mux v1.8.0
github.com/iancoleman/strcase v0.2.0
github.com/sa-/slicefunk v0.1.2
github.com/pkg/profile v1.6.0
)

4
go.sum
View file

@ -2,5 +2,5 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/sa-/slicefunk v0.1.2 h1:uTQiyKCTwc0RKNxXmG6NNlm3J1LF2hKmLgtf9kRAld4=
github.com/sa-/slicefunk v0.1.2/go.mod h1:k0abNpV9EW8LIPl2+Hc9RiKsojKmsUhNNGFyMpjMTCI=
github.com/pkg/profile v1.6.0 h1:hUDfIISABYI59DyeB3OTay/HxSRwTQ8rB/H83k6r5dM=
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=

12
main.go
View file

@ -5,16 +5,26 @@ import (
"legendsbrowser/model"
"legendsbrowser/server"
"net/http"
_ "net/http/pprof"
"runtime"
"github.com/gorilla/mux"
"github.com/pkg/profile"
)
var world model.World
func main() {
defer profile.Start(profile.MemProfile).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
fmt.Println("Hallo Welt!")
world.Load("region1-00152-01-01-legends.xml")
// world.Load("region1-00152-01-01-legends.xml")
world.Load("region2-00195-01-01-legends.xml")
runtime.GC()
world.Process()
model.ListOtherElements(&world.HistoricalEvents)

View file

@ -3,7 +3,7 @@ package model
import (
"encoding/xml"
"fmt"
"io/ioutil"
"io"
"os"
"reflect"
)
@ -36,6 +36,10 @@ type World struct {
EntityMap map[int]*Entity
}
var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ CueaaaaceeeiiiAAEaAooouuyOU faiounN ")
// var cp437 = []byte(" \t\n \r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñÑ ")
func (w *World) Load(file string) {
xmlFile, err := os.Open(file)
if err != nil {
@ -45,9 +49,14 @@ func (w *World) Load(file string) {
fmt.Println("Successfully Opened users.xml")
defer xmlFile.Close()
byteValue, _ := ioutil.ReadAll(xmlFile)
byteValue, _ := io.ReadAll(xmlFile)
fmt.Println(len(byteValue))
copy(byteValue[30:35], []byte("UTF-8"))
for i := range byteValue {
byteValue[i] = cp437[byteValue[i]]
}
err = xml.Unmarshal(byteValue, w)
if err != nil {
fmt.Println(err)

4
sample.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
curl http://localhost:8081/debug/pprof/heap > heap.0.pprof
go tool pprof heap.0.pprof