cleanup
This commit is contained in:
parent
55817d4511
commit
ac0f65fb3e
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/FooSoft/lazarus/math"
|
"github.com/FooSoft/lazarus/math"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Palette struct {
|
type DatPalette struct {
|
||||||
Colors [256]math.Color3b
|
Colors [256]math.Color3b
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,13 +17,13 @@ type color struct {
|
|||||||
R byte
|
R byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFromReader(reader io.Reader) (*Palette, error) {
|
func NewFromReader(reader io.Reader) (*DatPalette, error) {
|
||||||
var colors [256]color
|
var colors [256]color
|
||||||
if err := binary.Read(reader, binary.LittleEndian, &colors); err != nil {
|
if err := binary.Read(reader, binary.LittleEndian, &colors); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
palette := new(Palette)
|
palette := new(DatPalette)
|
||||||
for i, color := range colors {
|
for i, color := range colors {
|
||||||
palette.Colors[i] = math.Color3b{R: color.R, G: color.G, B: color.B}
|
palette.Colors[i] = math.Color3b{R: color.R, G: color.G, B: color.B}
|
||||||
}
|
}
|
||||||
@ -31,8 +31,8 @@ func NewFromReader(reader io.Reader) (*Palette, error) {
|
|||||||
return palette, nil
|
return palette, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFromGrayscale() *Palette {
|
func NewFromGrayscale() *DatPalette {
|
||||||
palette := new(Palette)
|
palette := new(DatPalette)
|
||||||
for i := 0; i < 256; i++ {
|
for i := 0; i < 256; i++ {
|
||||||
value := uint8(i)
|
value := uint8(i)
|
||||||
palette.Colors[i] = math.Color3b{R: value, G: value, B: value}
|
palette.Colors[i] = math.Color3b{R: value, G: value, B: value}
|
||||||
|
@ -38,12 +38,12 @@ type Frame struct {
|
|||||||
Data []byte
|
Data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type Sprite struct {
|
type Dc6Animation struct {
|
||||||
Directions []Direction
|
Directions []Direction
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFromReader(reader io.ReadSeeker) (*Sprite, error) {
|
func NewFromReader(reader io.ReadSeeker) (*Dc6Animation, error) {
|
||||||
sprite := new(Sprite)
|
sprite := new(Dc6Animation)
|
||||||
|
|
||||||
var fileHead fileHeader
|
var fileHead fileHeader
|
||||||
if err := binary.Read(reader, binary.LittleEndian, &fileHead); err != nil {
|
if err := binary.Read(reader, binary.LittleEndian, &fileHead); err != nil {
|
||||||
|
@ -1,16 +1,7 @@
|
|||||||
package mpq
|
package mpq
|
||||||
|
|
||||||
/*
|
// #cgo windows CFLAGS: -D_MPQ_WINDOWS
|
||||||
|
// #cgo windows LDFLAGS: -Lstormlib -lstorm -lwininet -lz -lbz2 -lstdc++
|
||||||
// Build Tags
|
// #cgo linux CFLAGS: -D_MPQ_LINUX
|
||||||
|
// #cgo linux LDFLAGS: -L./stormlib/ -lstorm -lz -lbz2 -lstdc++
|
||||||
// Windows
|
|
||||||
#cgo windows CFLAGS: -D_MPQ_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -Lstormlib -lstorm -lwininet -lz -lbz2 -lstdc++
|
|
||||||
|
|
||||||
// Linux
|
|
||||||
#cgo linux CFLAGS: -D_MPQ_LINUX
|
|
||||||
#cgo linux LDFLAGS: -L./stormlib/ -lstorm -lz -lbz2 -lstdc++
|
|
||||||
|
|
||||||
*/
|
|
||||||
import "C"
|
import "C"
|
||||||
|
@ -1,15 +1,5 @@
|
|||||||
package mpq
|
package mpq
|
||||||
|
|
||||||
// #ifdef _MPQ_WINDOWS
|
|
||||||
// #include <windows.h>
|
|
||||||
// #include <stdlib.h>
|
|
||||||
// #endif
|
|
||||||
// #ifdef _MPQ_LINUX
|
|
||||||
// #include <stdlib.h>
|
|
||||||
// #define WINAPI
|
|
||||||
// DWORD GetLastError();
|
|
||||||
// #endif
|
|
||||||
//
|
|
||||||
// #define DWORD unsigned int
|
// #define DWORD unsigned int
|
||||||
// #define LPDWORD unsigned int *
|
// #define LPDWORD unsigned int *
|
||||||
// #define LPOVERLAPPED void *
|
// #define LPOVERLAPPED void *
|
||||||
@ -18,13 +8,21 @@ package mpq
|
|||||||
// #define bool unsigned char
|
// #define bool unsigned char
|
||||||
// #define LONG int
|
// #define LONG int
|
||||||
//
|
//
|
||||||
|
// #include <stdlib.h>
|
||||||
|
// #ifdef _MPQ_WINDOWS
|
||||||
|
// #include <windows.h>
|
||||||
|
// #endif
|
||||||
|
// #ifdef _MPQ_LINUX
|
||||||
|
// #define WINAPI
|
||||||
|
// DWORD GetLastError();
|
||||||
|
// #endif
|
||||||
|
//
|
||||||
// bool WINAPI SFileOpenArchive(const TCHAR * szMpqName, DWORD dwPriority, DWORD dwFlags, HANDLE * phMpq);
|
// bool WINAPI SFileOpenArchive(const TCHAR * szMpqName, DWORD dwPriority, DWORD dwFlags, HANDLE * phMpq);
|
||||||
// bool WINAPI SFileCloseArchive(HANDLE hMpq);
|
// bool WINAPI SFileCloseArchive(HANDLE hMpq);
|
||||||
// bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearchScope, HANDLE * phFile);
|
// bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearchScope, HANDLE * phFile);
|
||||||
// DWORD WINAPI SFileSetFilePointer(HANDLE hFile, LONG lFilePos, LONG * plFilePosHigh, DWORD dwMoveMethod);
|
// DWORD WINAPI SFileSetFilePointer(HANDLE hFile, LONG lFilePos, LONG * plFilePosHigh, DWORD dwMoveMethod);
|
||||||
// bool WINAPI SFileReadFile(HANDLE hFile, void * lpBuffer, DWORD dwToRead, LPDWORD pdwRead, LPOVERLAPPED lpOverlapped);
|
// bool WINAPI SFileReadFile(HANDLE hFile, void * lpBuffer, DWORD dwToRead, LPDWORD pdwRead, LPOVERLAPPED lpOverlapped);
|
||||||
// bool WINAPI SFileCloseFile(HANDLE hFile);
|
// bool WINAPI SFileCloseFile(HANDLE hFile);
|
||||||
//
|
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -42,13 +40,13 @@ type File interface {
|
|||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Archive interface {
|
type MpqArchive interface {
|
||||||
OpenFile(path string) (File, error)
|
OpenFile(path string) (File, error)
|
||||||
GetPaths() []string
|
GetPaths() []string
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFromFile(path string) (Archive, error) {
|
func NewFromFile(path string) (MpqArchive, error) {
|
||||||
cs := C.CString(path)
|
cs := C.CString(path)
|
||||||
defer C.free(unsafe.Pointer(cs))
|
defer C.free(unsafe.Pointer(cs))
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ Copy the stormlib folder to an easy to access directory. I used /mingw64/home/th
|
|||||||
|
|
||||||
(from mingw64 console)
|
(from mingw64 console)
|
||||||
|
|
||||||
$ cd /mingw64/home/thegtproject/stormlib
|
|
||||||
$ cmake -DCMAKE_SYSTEM_NAME="windows" -DCMAKE_INSTALL_PREFIX="/mingw64" .
|
$ cmake -DCMAKE_SYSTEM_NAME="windows" -DCMAKE_INSTALL_PREFIX="/mingw64" .
|
||||||
$ make && make install
|
$ make && make install
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/FooSoft/lazarus/formats/dc6"
|
"github.com/FooSoft/lazarus/formats/dc6"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadPalette(path string) (*dat.Palette, error) {
|
func loadPalette(path string) (*dat.DatPalette, error) {
|
||||||
fp, err := os.Open(path)
|
fp, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -23,7 +23,7 @@ func loadPalette(path string) (*dat.Palette, error) {
|
|||||||
return dat.NewFromReader(fp)
|
return dat.NewFromReader(fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadSprite(path string) (*dc6.Sprite, error) {
|
func loadSprite(path string) (*dc6.Dc6Animation, error) {
|
||||||
fp, err := os.Open(path)
|
fp, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -32,7 +32,7 @@ func loadSprite(path string) (*dc6.Sprite, error) {
|
|||||||
return dc6.NewFromReader(fp)
|
return dc6.NewFromReader(fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractSprite(spritePath string, palette *dat.Palette, targetDir string) error {
|
func extractSprite(spritePath string, palette *dat.DatPalette, targetDir string) error {
|
||||||
sprite, err := loadSprite(spritePath)
|
sprite, err := loadSprite(spritePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/FooSoft/lazarus/platform"
|
"github.com/FooSoft/lazarus/platform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadPalette(path string) (*dat.Palette, error) {
|
func loadPalette(path string) (*dat.DatPalette, error) {
|
||||||
fp, err := os.Open(path)
|
fp, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -23,7 +23,7 @@ func loadPalette(path string) (*dat.Palette, error) {
|
|||||||
return dat.NewFromReader(fp)
|
return dat.NewFromReader(fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadSprite(path string) (*dc6.Sprite, error) {
|
func loadAnimation(path string) (*dc6.Dc6Animation, error) {
|
||||||
fp, err := os.Open(path)
|
fp, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -33,9 +33,9 @@ func loadSprite(path string) (*dc6.Sprite, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type scene struct {
|
type scene struct {
|
||||||
sprite *dc6.Sprite
|
animation *dc6.Dc6Animation
|
||||||
palette *dat.Palette
|
palette *dat.DatPalette
|
||||||
texture graphics.Texture
|
texture graphics.Texture
|
||||||
|
|
||||||
directionIndex int
|
directionIndex int
|
||||||
frameIndex int
|
frameIndex int
|
||||||
@ -65,8 +65,8 @@ func (s *scene) Advance(window *platform.Window) error {
|
|||||||
|
|
||||||
imgui.DialogBegin("DC6 Viewer")
|
imgui.DialogBegin("DC6 Viewer")
|
||||||
imgui.Image(s.texture)
|
imgui.Image(s.texture)
|
||||||
direction := s.sprite.Directions[directionIndex]
|
direction := s.animation.Directions[directionIndex]
|
||||||
if imgui.SliderInt("Direction", &directionIndex, 0, len(s.sprite.Directions)-1) {
|
if imgui.SliderInt("Direction", &directionIndex, 0, len(s.animation.Directions)-1) {
|
||||||
frameIndex = 0
|
frameIndex = 0
|
||||||
}
|
}
|
||||||
frame := direction.Frames[frameIndex]
|
frame := direction.Frames[frameIndex]
|
||||||
@ -88,7 +88,7 @@ func (s *scene) Advance(window *platform.Window) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *scene) updateTexture(window *platform.Window) error {
|
func (s *scene) updateTexture(window *platform.Window) error {
|
||||||
frame := s.sprite.Directions[s.directionIndex].Frames[s.frameIndex]
|
frame := s.animation.Directions[s.directionIndex].Frames[s.frameIndex]
|
||||||
colors := make([]math.Color3b, frame.Size.X*frame.Size.Y)
|
colors := make([]math.Color3b, frame.Size.X*frame.Size.Y)
|
||||||
for y := 0; y < frame.Size.Y; y++ {
|
for y := 0; y < frame.Size.Y; y++ {
|
||||||
for x := 0; x < frame.Size.X; x++ {
|
for x := 0; x < frame.Size.X; x++ {
|
||||||
@ -129,13 +129,13 @@ func main() {
|
|||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite, err := loadSprite(flag.Arg(0))
|
animation, err := loadAnimation(flag.Arg(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var palette *dat.Palette
|
var palette *dat.DatPalette
|
||||||
if len(*palettePath) > 0 {
|
if len(*palettePath) > 0 {
|
||||||
palette, err = loadPalette(*palettePath)
|
palette, err = loadPalette(*palettePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -146,7 +146,7 @@ func main() {
|
|||||||
palette = dat.NewFromGrayscale()
|
palette = dat.NewFromGrayscale()
|
||||||
}
|
}
|
||||||
|
|
||||||
scene := &scene{sprite: sprite, palette: palette}
|
scene := &scene{animation: animation, palette: palette}
|
||||||
window, err := platform.NewWindow("Viewer", math.Vec2i{X: 1024, Y: 768}, scene)
|
window, err := platform.NewWindow("Viewer", math.Vec2i{X: 1024, Y: 768}, scene)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user