reorganised Run
This commit is contained in:
parent
6531d191e2
commit
68ef5dcac5
Before Width: | Height: | Size: 128 B After Width: | Height: | Size: 128 B |
Before Width: | Height: | Size: 128 B After Width: | Height: | Size: 128 B |
|
@ -1,8 +1,10 @@
|
|||
package bloob
|
||||
package run
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
. "git.danitheskunk.com/squishy/blooblib"
|
||||
"git.danitheskunk.com/squishy/blooblib/gui"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"time"
|
||||
)
|
||||
|
@ -13,20 +15,6 @@ type Runnable interface {
|
|||
Update(bloob *Bloob)
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
WindowSize Vec2i
|
||||
Scale int
|
||||
TargetFps int
|
||||
Title string
|
||||
}
|
||||
|
||||
type Bloob struct {
|
||||
MousePos Vec2i
|
||||
Cursor *Image
|
||||
}
|
||||
|
||||
var DefaultCursor *Image
|
||||
|
||||
//go:embed "cursor.png"
|
||||
var defaultCursorBytes []byte
|
||||
|
||||
|
@ -51,6 +39,8 @@ func Run(game Runnable) {
|
|||
|
||||
game.Init(&bloob, &settings)
|
||||
|
||||
gui.InitGui(settings.WindowSize)
|
||||
|
||||
window, _ := sdl.CreateWindow(
|
||||
settings.Title,
|
||||
sdl.WINDOWPOS_CENTERED,
|
||||
|
@ -59,6 +49,7 @@ func Run(game Runnable) {
|
|||
int32(settings.WindowSize.Y*settings.Scale),
|
||||
sdl.WINDOW_SHOWN,
|
||||
)
|
||||
window.SetBordered(false)
|
||||
surface, _ := window.GetSurface()
|
||||
windowImage := NewImageFromPointer(surface.Data(), MulScalar(settings.WindowSize, settings.Scale))
|
||||
screen := NewImage(settings.WindowSize)
|
||||
|
@ -99,6 +90,7 @@ func Run(game Runnable) {
|
|||
if delta2 >= frameDuration {
|
||||
game.Update(&bloob)
|
||||
game.Render(&bloob, screen)
|
||||
gui.DrawGui(screen)
|
||||
if bloob.Cursor != nil {
|
||||
screen.Draw(bloob.Cursor, bloob.MousePos)
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package gui
|
||||
|
||||
import . "git.danitheskunk.com/squishy/blooblib"
|
||||
|
||||
type gui struct {
|
||||
}
|
||||
|
||||
var Gui gui
|
||||
|
||||
func InitGui(size Vec2i) {
|
||||
Gui = gui{}
|
||||
}
|
||||
|
||||
func DrawGui(target *Image) {
|
||||
|
||||
}
|
34
image.go
34
image.go
|
@ -13,20 +13,22 @@ import (
|
|||
)
|
||||
|
||||
type Image struct {
|
||||
Data []uint32
|
||||
Data []Color
|
||||
Size Vec2i
|
||||
Alpha bool
|
||||
}
|
||||
|
||||
type Color = uint32
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var threadProfile = pprof.Lookup("threadcreate")
|
||||
|
||||
func NewImage(size Vec2i) *Image {
|
||||
return &Image{Data: make([]uint32, size.Size()), Size: Vec2i{X: size.X, Y: size.Y}, Alpha: true}
|
||||
return &Image{Data: make([]Color, size.Size()), Size: Vec2i{X: size.X, Y: size.Y}, Alpha: true}
|
||||
}
|
||||
|
||||
func NewImageFromPointer(pointer unsafe.Pointer, size Vec2i) *Image {
|
||||
return &Image{Data: unsafe.Slice((*uint32)(pointer), size.Size()), Size: Vec2i{X: size.X, Y: size.Y}, Alpha: true}
|
||||
return &Image{Data: unsafe.Slice((*Color)(pointer), size.Size()), Size: Vec2i{X: size.X, Y: size.Y}, Alpha: true}
|
||||
}
|
||||
|
||||
func LoadImage(path string) *Image {
|
||||
|
@ -56,7 +58,7 @@ func LoadImageBytes(data []byte) *Image {
|
|||
return img
|
||||
}
|
||||
|
||||
func (image *Image) Clear(color uint32) {
|
||||
func (image *Image) Clear(color Color) {
|
||||
for i := 0; i < image.Size.X*image.Size.Y; i += 1 {
|
||||
image.Data[i] = color
|
||||
}
|
||||
|
@ -89,6 +91,18 @@ func CropToArea(sizeDst Vec2i, rectSrc Recti, posDst Vec2i) (start, end, dst Vec
|
|||
return
|
||||
}
|
||||
|
||||
func (image *Image) DrawHLine(pos Vec2i, length int, color Color) {
|
||||
for i := 0; i < length; i += 1 {
|
||||
image.Data[pos.X+i+pos.Y*image.Size.X] = color
|
||||
}
|
||||
}
|
||||
|
||||
func (image *Image) DrawVLine(pos Vec2i, length int, color Color) {
|
||||
for i := 0; i < length; i += 1 {
|
||||
image.Data[pos.X+(pos.Y+i)*image.Size.X] = color
|
||||
}
|
||||
}
|
||||
|
||||
func (image *Image) Draw(other *Image, dst Vec2i) {
|
||||
image.DrawSub(other, dst, Recti{Size: other.Size})
|
||||
}
|
||||
|
@ -116,11 +130,11 @@ func (image *Image) DrawSub(other *Image, pos Vec2i, rect Recti) {
|
|||
}
|
||||
}
|
||||
|
||||
func (image *Image) DrawColor(other *Image, dst Vec2i, color uint32) {
|
||||
func (image *Image) DrawColor(other *Image, dst Vec2i, color Color) {
|
||||
image.DrawSubColor(other, dst, Recti{Size: other.Size}, color)
|
||||
}
|
||||
|
||||
func (image *Image) DrawSubColor(other *Image, pos Vec2i, rect Recti, color uint32) {
|
||||
func (image *Image) DrawSubColor(other *Image, pos Vec2i, rect Recti, color Color) {
|
||||
start, end, dst := CropToArea(image.Size, rect, pos)
|
||||
for y := start.Y; y < end.Y; y += 1 {
|
||||
for x := start.X; x < end.X; x += 1 {
|
||||
|
@ -250,7 +264,7 @@ func (image *Image) DrawUpscale(other *Image) {
|
|||
}
|
||||
}
|
||||
|
||||
func (image *Image) DrawText(str string, font *Font, pos Vec2i, color uint32) {
|
||||
func (image *Image) DrawText(str string, font *Font, pos Vec2i, color Color) {
|
||||
origX := pos.X
|
||||
for _, ch := range str {
|
||||
c := font.chars[ch]
|
||||
|
@ -264,7 +278,7 @@ func (image *Image) DrawText(str string, font *Font, pos Vec2i, color uint32) {
|
|||
}
|
||||
}
|
||||
|
||||
func (image *Image) DrawTextSin(str string, font *Font, pos Vec2i, color uint32, freq, amplitude, phase float64) {
|
||||
func (image *Image) DrawTextSin(str string, font *Font, pos Vec2i, color Color, freq, amplitude, phase float64) {
|
||||
origX := pos.X
|
||||
for _, ch := range str {
|
||||
c := font.chars[ch]
|
||||
|
@ -278,7 +292,7 @@ func (image *Image) DrawTextSin(str string, font *Font, pos Vec2i, color uint32,
|
|||
}
|
||||
}
|
||||
|
||||
func (image *Image) DrawTextOutline(str string, font *Font, pos Vec2i, color, outlineColor uint32) {
|
||||
func (image *Image) DrawTextOutline(str string, font *Font, pos Vec2i, color, outlineColor Color) {
|
||||
origX := pos.X
|
||||
for _, ch := range str {
|
||||
c := font.chars[ch]
|
||||
|
@ -305,7 +319,7 @@ func (image *Image) DrawTextOutline(str string, font *Font, pos Vec2i, color, ou
|
|||
}
|
||||
}
|
||||
|
||||
func (image *Image) DrawTextOutlineSin(str string, font *Font, pos Vec2i, color, outlineColor uint32, freq, amplitude, phase float64) {
|
||||
func (image *Image) DrawTextOutlineSin(str string, font *Font, pos Vec2i, color, outlineColor Color, freq, amplitude, phase float64) {
|
||||
origX := pos.X
|
||||
for _, ch := range str {
|
||||
c := font.chars[ch]
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package bloob
|
||||
|
||||
type Settings struct {
|
||||
WindowSize Vec2i
|
||||
Scale int
|
||||
TargetFps int
|
||||
Title string
|
||||
}
|
||||
|
||||
type Bloob struct {
|
||||
MousePos Vec2i
|
||||
Cursor *Image
|
||||
}
|
||||
|
||||
var DefaultCursor *Image
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
bloob "git.danitheskunk.com/squishy/blooblib"
|
||||
run "git.danitheskunk.com/squishy/blooblib/Run"
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
}
|
||||
|
||||
func (g Game) Init(bloob *bloob.Bloob, settings *bloob.Settings) {
|
||||
}
|
||||
|
||||
func (g Game) Render(bloob *bloob.Bloob, screen *bloob.Image) {
|
||||
}
|
||||
|
||||
func (g Game) Update(bloob *bloob.Bloob) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
run.Run(&Game{})
|
||||
}
|
Loading…
Reference in New Issue