Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports OpenTK.Graphics.OpenGL
- Imports OpenTK
- Public Class OpenGL_Render
- Private m As New map
- Private Sub OpenGL_Render_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- m.Load(Populous.Populous.Info.InstallPath & "\levels\levl2007.dat", map.MapType.DAT)
- TribeCust.Show()
- End Sub
- Private OpenGL_Load = False
- Private Sub GlControl1_Load(sender As Object, e As EventArgs) Handles GlControl1.Load
- OpenGL_Load = True
- GL.ClearColor(Color.Black)
- End Sub
- Private Sub GlControl1_Paint(sender As Object, e As PaintEventArgs) Handles GlControl1.Paint
- ' render graphics
- GL.Clear(ClearBufferMask.ColorBufferBit Or ClearBufferMask.DepthBufferBit)
- 'Basic Setup for viewing
- Dim perspective As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(1, 1, 1, 10000) 'Setup Perspective
- Dim lookat As Matrix4 = Matrix4.LookAt(0, 0, -116, 0, 0, 0, 0, 1, 0) 'Setup camera
- GL.MatrixMode(MatrixMode.Projection) 'Load Perspective
- GL.LoadIdentity()
- GL.LoadMatrix(perspective)
- GL.MatrixMode(MatrixMode.Modelview) 'Load Camera
- GL.LoadIdentity()
- GL.LoadMatrix(lookat)
- GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height) 'Size of window
- GL.Enable(EnableCap.DepthTest) 'Enable correct Z Drawings
- GL.DepthFunc(DepthFunction.Less) 'Enable correct Z Drawings
- ' GL.Rotate(mousepos.X, 0, 1, 0)
- ' GL.Rotate(mousepos.Y, 0, 0, 1)
- 'GL.Rotate(0, 0, 1, 0)
- GL.Translate(New Vector3(-64, -64, 0))
- GL.Begin(PrimitiveType.Points)
- For Each point In m.Map_Loaded
- If point.height > 0 Then
- GL.Color3(Color.FromArgb(0, 100, 0))
- GL.Vertex3(point.X, point.Y, point.height / 50)
- Else
- GL.Color3(Color.FromArgb(0, 0, 100))
- GL.Vertex3(point.X, point.Y, 0)
- End If
- Next
- GL.[End]()
- GlControl1.SwapBuffers()
- End Sub
- Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
- Dim savefiledialog As New OpenFileDialog()
- savefiledialog.InitialDirectory = Populous.Populous.Info.InstallPath & "\levels\"
- savefiledialog.Filter = "Populous Levels (levl*.dat)|levl*.dat|XML (levl*.xml)|levl*.xml|CSV (levl*.csv)|levl*.csv|Bitmap (levl*.bmp)|levl*.bmp|All files (*.*)|*.*"
- savefiledialog.FilterIndex = 0
- savefiledialog.RestoreDirectory = True
- If savefiledialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
- Try
- If Path.GetExtension(savefiledialog.FileName).ToLower.Contains(".dat") Then
- m.Load(savefiledialog.FileName, map.MapType.DAT)
- GlControl1.Invalidate()
- Else
- MsgBox("Invalid Format!")
- End If
- Catch Ex As Exception
- MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
- End Try
- End If
- End Sub
- Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
- Dim savefiledialog As New SaveFileDialog()
- savefiledialog.InitialDirectory = Populous.Populous.Info.InstallPath & "\levels\"
- savefiledialog.Filter = "Populous Levels (levl*.dat)|levl*.dat|XML (levl*.xml)|levl*.xml|CSV (levl*.csv)|levl*.csv|Bitmap (levl*.bmp)|levl*.bmp|All files (*.*)|*.*"
- savefiledialog.FilterIndex = 0
- savefiledialog.RestoreDirectory = True
- If savefiledialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
- Try
- If Path.GetExtension(savefiledialog.FileName).ToLower.Contains(".dat") Then
- m.Save(savefiledialog.FileName, map.MapType.DAT)
- Else
- MsgBox("Invalid Format!")
- End If
- Catch Ex As Exception
- MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
- End Try
- End If
- End Sub
- Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
- End
- End Sub
- End Class
- Public Class map
- Public Structure Points
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public height As Short
- End Structure
- Public Structure Objects
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public height As Short
- End Structure
- Public Structure NoAccessBlocks
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public disabled As Integer
- End Structure
- Public Structure SunLightBlocks
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public disabled As Integer
- End Structure
- Public Structure SavePlayerInfo
- Public ID As Integer
- Public X As Integer
- Public Y As Integer
- Public tribe As Populous.Populous.tribe
- End Structure
- Private MapSize As Size = New Size(128, 128)
- Public Map_Loaded(MapSize.Height * MapSize.Width) As Points
- Public NoAccess(MapSize.Height * MapSize.Width) As NoAccessBlocks
- Public SunLight(MapSize.Height * MapSize.Width) As SunLightBlocks
- Public SavePlayer(64) As SavePlayerInfo
- Public Obj(2000 - 1) As Objects
- Public Enum MapType
- DAT
- XML
- CSV
- BITMAP
- End Enum
- Public Sub Load(ByVal filepath As String, ByVal filetypep As MapType)
- If filetypep = MapType.DAT Then
- Dim reader As New BinaryReader(File.Open(filepath, FileMode.Open))
- Dim Point = 0
- For x As Integer = 0 To MapSize.Height - 1
- For y As Integer = 0 To MapSize.Width - 1
- ' Load height UShort is unsigned Word, and Short is signed word
- Dim Height As Short = reader.ReadUInt16()
- If Point > 0 Then
- Map_Loaded(Point).ID = Point + 1
- End If
- Map_Loaded(Point).X = x
- Map_Loaded(Point).Y = y
- Map_Loaded(Point).height = Height
- Point = Point + 1
- Next
- Next
- reader.Close()
- ElseIf filetypep = MapType.XML Then
- ElseIf filetypep = MapType.CSV Then
- ElseIf filetypep = MapType.BITMAP Then
- End If
- End Sub
- Public Sub Save(ByVal filepath As String, ByVal filetypep As MapType)
- If filetypep = MapType.DAT Then
- If Not My.Computer.FileSystem.FileExists(filepath) Then
- File.Create(filepath).Dispose()
- End If
- Dim writer As New BinaryWriter(File.Open(filepath, FileMode.Open))
- For x As Integer = 0 To MapSize.Width - 1
- For y As Integer = 0 To MapSize.Height - 1
- For Point = 0 To Map_Loaded.Length - 1
- If (Map_Loaded(Point).X = x And Map_Loaded(Point).Y = y) Then
- writer.Write(Map_Loaded(Point).height)
- Exit For
- End If
- Next
- Next
- Next
- ' Unused Data, 0 byte it
- Do Until (writer.BaseStream.Position >= 65535)
- writer.Write(0)
- Loop
- ' No Access Blocks 1 = No Access 0 = Free Roam
- Do Until (writer.BaseStream.Position >= 81983)
- writer.Write(0)
- Loop
- ' Save Player Info
- Do Until (writer.BaseStream.Position >= 81919)
- writer.Write(0)
- Loop
- ' Sunlight Info
- Do Until (writer.BaseStream.Position >= 81986)
- writer.Write(0)
- Loop
- ' Objects
- Do Until (writer.BaseStream.Position >= 191986)
- writer.Write(0)
- Loop
- ' End Padding
- Do Until (writer.BaseStream.Position >= 192136)
- writer.Write(0)
- Loop
- writer.Close()
- ElseIf filetypep = MapType.XML Then
- ElseIf filetypep = MapType.CSV Then
- ElseIf filetypep = MapType.BITMAP Then
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement