diff --git a/generate_packets.php b/generate_packets.php deleted file mode 100755 index c7294d1..0000000 --- a/generate_packets.php +++ /dev/null @@ -1,198 +0,0 @@ -#!/usr/bin/env php - -#include - -CPP; - - // Generate enum - $header .= "enum class MessageType : uint8_t {\n"; - - // Sort keys for consistent output - $names = array_keys($packets['opcodes']); - sort($names); - - foreach ($names as $i => $name) { - $packet = $packets['opcodes'][$name]; - $header .= sprintf(" %s = %s", $name, $packet['id']); - if ($i < count($names) - 1) { - $header .= ","; - } - $header .= "\n"; - } - $header .= "};\n\n"; - - // Generate packet structures - $header .= "// Packet structure definitions\n"; - $header .= "namespace Packets {\n\n"; - - foreach ($names as $name) { - $packet = $packets['opcodes'][$name]; - if (!empty($packet['fields'])) { - $header .= sprintf("struct %s {\n", $name); - $header .= sprintf(" static constexpr MessageType TYPE = MessageType::%s;\n", $name); - - foreach ($packet['fields'] as $field) { - $cpp_type = ''; - - switch ($field['type']) { - case 'string': - $cpp_type = 'std::string'; - break; - case 'uint8': - $cpp_type = 'uint8_t'; - break; - case 'uint32': - $cpp_type = 'uint32_t'; - break; - case 'float32': - $cpp_type = 'float'; - break; - case 'array': - $header .= sprintf(" // Array field: %s - requires custom handling\n", $field['name']); - continue 2; - } - - $header .= sprintf(" %s %s;\n", $cpp_type, $field['name']); - } - - $header .= "};\n\n"; - } - } - - $header .= "} // namespace Packets\n"; - - return $header; -} - -/** - * Generate Go file with packet definitions - */ -function generate_go_file($packets) { - $go_file = <<getMessage() . "\n"; - exit(1); -} diff --git a/packets.json b/packets.json deleted file mode 100644 index 37636cf..0000000 --- a/packets.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "version": "1.0.0", - "opcodes": { - "Login": { - "id": "0x01", - "fields": [] - }, - "Position": { - "id": "0x02", - "fields": [ - {"name": "x", "type": "float32"}, - {"name": "y", "type": "float32"}, - {"name": "z", "type": "float32"} - ] - }, - "Spawn": { - "id": "0x03", - "fields": [ - {"name": "playerId", "type": "uint32"}, - {"name": "x", "type": "float32"}, - {"name": "y", "type": "float32"}, - {"name": "z", "type": "float32"}, - {"name": "color", "type": "string"} - ] - }, - "Move": { - "id": "0x04", - "fields": [ - {"name": "playerId", "type": "uint32"}, - {"name": "dx", "type": "float32"}, - {"name": "dy", "type": "float32"}, - {"name": "dz", "type": "float32"} - ] - }, - "Update": { - "id": "0x05", - "fields": [ - {"name": "playerId", "type": "uint32"}, - {"name": "x", "type": "float32"}, - {"name": "y", "type": "float32"}, - {"name": "z", "type": "float32"} - ] - }, - "PlayerJoined": { - "id": "0x06", - "fields": [ - {"name": "playerId", "type": "uint32"}, - {"name": "x", "type": "float32"}, - {"name": "y", "type": "float32"}, - {"name": "z", "type": "float32"}, - {"name": "color", "type": "string"} - ] - }, - "PlayerLeft": { - "id": "0x07", - "fields": [ - {"name": "playerId", "type": "uint32"} - ] - }, - "PlayerList": { - "id": "0x08", - "fields": [ - {"name": "count", "type": "uint8"}, - {"name": "players", "type": "array", "itemType": { - "fields": [ - {"name": "playerId", "type": "uint32"}, - {"name": "x", "type": "float32"}, - {"name": "y", "type": "float32"}, - {"name": "z", "type": "float32"}, - {"name": "color", "type": "string"} - ] - }} - ] - }, - "ChangeColor": { - "id": "0x09", - "fields": [ - {"name": "playerId", "type": "uint32"}, - {"name": "color", "type": "string"} - ] - }, - "ColorChanged": { - "id": "0x0A", - "fields": [ - {"name": "playerId", "type": "uint32"}, - {"name": "color", "type": "string"} - ] - } - }, - "types": { - "uint8": {"size": 1, "encoding": "little-endian"}, - "uint32": {"size": 4, "encoding": "little-endian"}, - "float32": {"size": 4, "encoding": "little-endian"}, - "string": {"encoding": "length-prefixed", "lengthType": "uint8"} - } -} \ No newline at end of file diff --git a/server/main.go b/server/main.go index 62577b8..dd0721a 100644 --- a/server/main.go +++ b/server/main.go @@ -149,20 +149,37 @@ func main() { var ( port = flag.String("port", "9999", "UDP port to listen on") worldSize = flag.Int("size", WorldSize, "World size for heightmap generation") - skipGen = flag.Bool("skip-gen", false, "Skip heightmap generation") + skipGen = flag.Bool("skip-gen", false, "Skip heightmap generation (fail if none exists)") + forceGen = flag.Bool("force-gen", false, "Force heightmap regeneration even if one exists") assetsPath = flag.String("assets", "../assets", "Path to assets directory") ) flag.Parse() // Setup logging - log.SetPrefix("[GameServer] ") + log.SetPrefix("[Game] ") log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds) var heightmap [][]float32 + binPath := fmt.Sprintf("%s/heightmap.bin", *assetsPath) - if !*skipGen { - // Generate and save heightmap - log.Printf("Generating %dx%d heightmap...", *worldSize, *worldSize) + // Check if heightmap exists and should be loaded + if _, err := os.Stat(binPath); err == nil && !*forceGen && !*skipGen { + // Heightmap exists and we're not forcing regeneration + log.Printf("Found existing heightmap at %s, loading...", binPath) + heightmap, err = loadHeightmapBinary(binPath) + if err != nil { + log.Printf("Failed to load existing heightmap: %v, generating new one...", err) + heightmap = nil + } else { + log.Printf("Successfully loaded existing heightmap") + } + } else if *forceGen { + log.Printf("Force regeneration requested, ignoring existing heightmap") + } + + // Generate new heightmap if needed (not loaded, force generation, or doesn't exist) + if heightmap == nil && !*skipGen { + log.Printf("Generating new %dx%d heightmap...", *worldSize, *worldSize) heightmap = generateHeightmap(*worldSize) pngPath := fmt.Sprintf("%s/heightmap.png", *assetsPath) @@ -172,20 +189,13 @@ func main() { log.Printf("Saved heightmap PNG to %s", pngPath) } - binPath := fmt.Sprintf("%s/heightmap.bin", *assetsPath) if err := saveHeightmapBinary(heightmap, binPath); err != nil { log.Fatalf("Failed to save binary heightmap: %v", err) } log.Printf("Saved heightmap binary to %s", binPath) - } else { - // Load existing heightmap - binPath := fmt.Sprintf("%s/heightmap.bin", *assetsPath) - log.Printf("Loading existing heightmap from %s", binPath) - var err error - heightmap, err = loadHeightmapBinary(binPath) - if err != nil { - log.Fatalf("Failed to load heightmap: %v", err) - } + } else if *skipGen && heightmap == nil { + // skip-gen was specified but no heightmap exists + log.Fatalf("No existing heightmap found and generation was skipped (--skip-gen flag)") } server, err := net.NewServer(*port, heightmap)