Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client:Server data separation #69

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

> Kero is a Source Engine game client implementation written in Go.

**This project is primarily tested against Counterstrike: Source, but CS:GO there is limited support for other games**

## Current Features

* BSP rendering with visdata support
* Skybox rendering
* Skybox rendering including 3D skybox
* Lightmap support (incomplete, BSP geometry only)
* Staticprop rendering
* Prop entity rendering (incomplete, models with bones unsupported)
* Bullet physics for brush:physics entity collisions
* Bullet physics for full physics simulation

###### Build Kero, run it by pointing it to a Source Engine game installation, and it *should* just work!

Expand Down
114 changes: 114 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package client

import (
"fmt"

"github.com/galaco/kero/client/gui"
"github.com/galaco/kero/client/input"
"github.com/galaco/kero/client/renderer"
"github.com/galaco/kero/internal/framework/event"
"github.com/galaco/kero/internal/framework/filesystem"
"github.com/galaco/kero/internal/framework/graphics/adapter"
input2 "github.com/galaco/kero/internal/framework/input"
"github.com/galaco/kero/internal/framework/window"
"github.com/galaco/kero/shared/messages"
"github.com/go-gl/mathgl/mgl32"
)

type Client struct {
scene *sceneEntities

renderer *renderer.Renderer
ui *gui.Gui
input *input.Input

isInMenu bool
}

func (c *Client) FixedUpdate(dt float64) {
c.scene.Update(dt)
}

func (c *Client) Update() {
c.input.Poll()
c.renderer.Render()
c.ui.Render()

window.CurrentWindow().SwapBuffers()
c.renderer.FinishFrame()
}

func (c *Client) onKeyRelease(message interface{}) {
key := message.(input2.Key)
if key == input2.KeyEscape {
c.isInMenu = !c.isInMenu
}
}

func (c *Client) onMouseMove(message interface{}) {
if c.isInMenu {
return
}
if c.scene == nil || c.scene.activeCamera == nil {
return
}
msg := message.(mgl32.Vec2)
c.scene.activeCamera.Rotate(msg[0], 0, msg[1])
}

func (c *Client) Initialize() error {
// Find game name for Window title
title := "Kero: A Source Engine Implementation"
gameNameNode, err := filesystem.GameInfo().Find("game")
if err == nil && gameNameNode != nil {
gameName, _ := gameNameNode.AsString()
title = fmt.Sprintf("Kero: %s", gameName)
}

// Creates the Client Game Window
win, err := window.CreateWindow(1920, 1080, title)
if err != nil {
return err
}
win.SetActive()
input2.SetBoundWindow(win)
win.Handle().Handle().Focus()
if err = adapter.Init(); err != nil {
return err
}

// Bind to the input library for window handling
input.InputMiddleware().AddListener(messages.TypeKeyRelease, c.onKeyRelease)
input.InputMiddleware().AddListener(messages.TypeMouseMove, c.onMouseMove)
event.Get().AddListener(messages.TypeEngineQuit, func(interface{}) {
window.CurrentWindow().Close()
})

// Initialize our rendering system
c.renderer.Initialize()
c.ui.Initialize()

// Bind our client data to shared/server resources
c.scene.BindSharedResources()
c.renderer.BindSharedResources()

return nil
}

func (c *Client) ShouldClose() bool {
return window.CurrentWindow() == nil || window.CurrentWindow().ShouldClose()
}

func (c *Client) Cleanup() {
c.renderer.Cleanup()
}

func NewClient() *Client {
return &Client{
renderer: renderer.NewRenderer(),
ui: gui.NewGui(),
input: input.InitializeInput(),
scene: &sceneEntities{},
isInMenu: true, // Client always starts in menu
}
}
33 changes: 33 additions & 0 deletions client/entity/camera/camera.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package camera

import (
"github.com/galaco/kero/internal/framework/graphics"
"github.com/galaco/kero/internal/framework/input"
)

type Camera struct {
boundCamera *graphics.Camera
}

func (cam *Camera) Rotate(x, y, z float32) {
cam.boundCamera.Rotate(x, y, z)
}

func (cam *Camera) Update(dt float64) {
if input.Keyboard().IsKeyPressed(input.KeyW) {
cam.boundCamera.Forwards(dt)
}
if input.Keyboard().IsKeyPressed(input.KeyA) {
cam.boundCamera.Left(dt)
}
if input.Keyboard().IsKeyPressed(input.KeyS) {
cam.boundCamera.Backwards(dt)
}
if input.Keyboard().IsKeyPressed(input.KeyD) {
cam.boundCamera.Right(dt)
}
}

func NewCamera(boundCamera *graphics.Camera) *Camera {
return &Camera{boundCamera: boundCamera}
}
18 changes: 18 additions & 0 deletions client/entity/player/characterController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package player

import (
"github.com/galaco/kero/client/entity/camera"
"github.com/galaco/kero/internal/framework/entity"
)

type CharacterController struct {
entity.Entity
}

func (controller *CharacterController) BindCamera(c *camera.Camera) {

}

func NewCharacterController() *CharacterController {
return &CharacterController{}
}
21 changes: 11 additions & 10 deletions gui/gui.go → client/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package gui

import (
"fmt"
"github.com/galaco/kero/framework/console"
"github.com/galaco/kero/framework/event"
"github.com/galaco/kero/framework/gui"
"github.com/galaco/kero/framework/gui/context"
"github.com/galaco/kero/framework/input"
"github.com/galaco/kero/framework/window"
"github.com/galaco/kero/gui/views"
"github.com/galaco/kero/messages"
"github.com/galaco/kero/middleware"

"github.com/galaco/kero/client/gui/views"
inputMiddleware "github.com/galaco/kero/client/input"
"github.com/galaco/kero/internal/framework/console"
"github.com/galaco/kero/internal/framework/event"
"github.com/galaco/kero/internal/framework/gui"
"github.com/galaco/kero/internal/framework/gui/context"
"github.com/galaco/kero/internal/framework/input"
"github.com/galaco/kero/internal/framework/window"
"github.com/galaco/kero/shared/messages"
)

type Gui struct {
Expand All @@ -35,7 +36,7 @@ func (s *Gui) Initialize() {
console.DisableBufferedLogs()

s.uiContext = context.NewContext(window.CurrentWindow())
middleware.InputMiddleware().AddListener(messages.TypeKeyRelease, s.onKeyRelease)
inputMiddleware.InputMiddleware().AddListener(messages.TypeKeyRelease, s.onKeyRelease)
event.Get().AddListener(messages.TypeLoadingLevelProgress, s.onLoadingLevelProgress)

}
Expand Down
3 changes: 2 additions & 1 deletion gui/views/loading.go → client/gui/views/loading.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package views

import (
"fmt"
"github.com/galaco/kero/framework/gui"

"github.com/galaco/kero/internal/framework/gui"
)

type Loading struct {
Expand Down
12 changes: 6 additions & 6 deletions gui/views/menu.go → client/gui/views/menu.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package views

import (
"github.com/galaco/kero/framework/event"
"github.com/galaco/kero/framework/filesystem"
"github.com/galaco/kero/framework/gui"
"github.com/galaco/kero/framework/gui/dialogs"
"github.com/galaco/kero/gui/views/menu"
"github.com/galaco/kero/messages"
"github.com/galaco/kero/client/gui/views/menu"
"github.com/galaco/kero/internal/framework/event"
"github.com/galaco/kero/internal/framework/filesystem"
"github.com/galaco/kero/internal/framework/gui"
"github.com/galaco/kero/internal/framework/gui/dialogs"
"github.com/galaco/kero/shared/messages"
)

type Menu struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package menu

import (
"github.com/galaco/kero/framework/console"
"github.com/galaco/kero/framework/gui"
"github.com/inkyblackness/imgui-go/v4"
"log"

"github.com/galaco/kero/internal/framework/console"
"github.com/galaco/kero/internal/framework/gui"
"github.com/inkyblackness/imgui-go/v4"
)

type consoleMessage struct {
Expand Down
8 changes: 4 additions & 4 deletions middleware/input.go → client/input/input.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package middleware
package input

import (
"github.com/galaco/kero/framework/event"
"github.com/galaco/kero/framework/input"
"github.com/galaco/kero/messages"
"github.com/galaco/kero/internal/framework/event"
"github.com/galaco/kero/internal/framework/input"
"github.com/galaco/kero/shared/messages"
"github.com/go-gl/mathgl/mgl32"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cache

import (
"github.com/galaco/kero/framework/graphics/adapter"
"github.com/galaco/kero/internal/framework/graphics/adapter"
)

type GpuProp struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cache

import (
"github.com/galaco/kero/framework/graphics"
"github.com/galaco/kero/internal/framework/graphics"
)

const (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cache

import (
"github.com/galaco/kero/framework/graphics/adapter"
"github.com/galaco/kero/internal/framework/graphics/adapter"
)

type Shader struct {
Expand Down
Loading