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

Already on GitHub? Sign in to your account

Validation #38

Merged
merged 20 commits into from Apr 2, 2013

Conversation

Projects
None yet
2 participants
Owner

crazy2be commented Mar 31, 2013

This pull request includes basic server-side logic for player movement and physics. Currently, there is no client side prediction or interpolation, which occasionally makes movement laggy or jerky.

Although this feature is certainly not done (eventually we probably want to make it like https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization), I'm sending the pull request now to avoid having a HUGE code dump, and make the diffs more manageable.

Please comment regarding silly things I did, your experience trying out this version, bugs you encounter, etc.

crazy2be added some commits Mar 25, 2013

@crazy2be crazy2be Some very rudementry simulation on the server, which is unaware of ph…
…ysics and look direction.
5b05138
@crazy2be crazy2be Fix bug with block changes not properly propagating to all clients, d…
…ue to the new network changes (some fields were changed to uppercase, but the JavaScript was still expecting lowercase).
35be9b1
@crazy2be crazy2be Replicated basic player move logic (sans physics) on server. 0c9e780
@crazy2be crazy2be Reorganized project a bit more to allow creation of multiple packages. 9339fa7
@crazy2be crazy2be Moved map generation code into own package. f451f38
@crazy2be crazy2be Collisions are now working, allowing the server to predict the moveme…
…nts of players with a high degree of accuracy. However, there is still error, and we don't correct for it yet.
6b534f8
@crazy2be crazy2be Made player simulation non-blocking. 00bbeef
@crazy2be crazy2be Clean up inventory. 116ebc0
@crazy2be crazy2be Clean up controls.js, make keyboard layout easily settable with local…
…Storage flag.
e8a9f49
@crazy2be crazy2be Made inventory items activatable again. 926c7c2
@crazy2be crazy2be Entirely server-side prediction is mostly working now. 6f013d7
@crazy2be crazy2be Server uses client frametime for calculations now. This entails trust…
…ing the client (they could just lie about their frametime), but we'll fix that soon enough.
76071e0
@crazy2be crazy2be Cleanup. We no longer trust the client's FrameTime, but we still trus…
…t their Timestamp. Somehow we have to normallize all of the incoming timestamps to one clock. Hmmm.
0d24c2e
@crazy2be crazy2be Remove useless comments. 8fc0f05

@crazy2be crazy2be commented on an outdated diff Mar 31, 2013

client/js/chunks/chunk.js
@@ -1,5 +1,7 @@
var CHUNK_MATERIAL = new THREE.MeshBasicMaterial({
- vertexColors: THREE.VertexColors
+ vertexColors: THREE.VertexColors,
+// transparent: true,
+// opacity: 0.5,
@crazy2be

crazy2be Mar 31, 2013

Owner

These lines shouldn't be here... I swear I removed them.

@crazy2be crazy2be commented on the diff Mar 31, 2013

client/js/chunks/manager.js
@@ -29,8 +29,8 @@ function ChunkManager(scene, player) {
geometryWorker.postMessage({
'kind': 'block-change',
'payload': {
- 'wc': {x: wx, y: wy, z: wz},
- 'type': newType,
+ 'Pos': {X: wx, Y: wy, Z: wz},
+ 'Type': newType,
@crazy2be

crazy2be Mar 31, 2013

Owner

All the network packets now use uppercase field names.

@crazy2be crazy2be commented on the diff Mar 31, 2013

client/js/controls.js
- var movementX = 0;
- var movementY = 0;
+ if (window.localStorage["useDvorak"]) {
@crazy2be

crazy2be Mar 31, 2013

Owner

Eventually we might want to do something more sophisticated here.

@crazy2be crazy2be commented on the diff Mar 31, 2013

client/js/controls.js
-
- lon += movementX * lookSpeed;
- lon %= 2 * Math.PI
- lat -= movementY * lookSpeed;
- lat = clamp(lat, -Math.PI + 0.01, -0.01);
-
- movementX = 0;
- movementY = 0;
-
- // Meh, I don't really like the way this works,
- // but it works for now.
- var state = clone(actions);
- state.lat = lat;
- state.lon = lon;
- return state;
+ return clone(actions);
@crazy2be

crazy2be Mar 31, 2013

Owner

This code is like WAY cleaner. It doesn't look that way from the diff, but look at the raw file. Let me know if anything about how it works is still confusing or strange.

@crazy2be crazy2be commented on an outdated diff Mar 31, 2013

client/js/entities/player.js
@@ -44,9 +37,11 @@ function Player(name, world, conn, controls) {
self.update = function (dt) {
var c = controls.sample();
var p = camera.position;
+ var P = newPlayerPosition;
+ camera.position.set(P.x, P.y, P.z);
@crazy2be

crazy2be Mar 31, 2013

Owner

This code is still pretty wierd. I haven't cleaned it up because I still have to change it a ton for the client prediction logic, so it's messy for now.

@crazy2be crazy2be commented on the diff Mar 31, 2013

client/js/inventory.js
@@ -1,61 +1,61 @@
function WeaponInventory(world, camera) {
var slots = [
- 'pistol',
- ];
-
- var models = [
- Models.pistol(),
+ {
+ name: 'pistol',
+ model: Models.pistol(),
+ action: pistolAction,
+ }
@crazy2be

crazy2be Mar 31, 2013

Owner

I think it's much cleaner to describe each inventory slot with an object like this, rather than three separate objects with a relationship dictated merely by there key indices. Let me know if there's anything strange in here still.

@crazy2be crazy2be and 1 other commented on an outdated diff Mar 31, 2013

client/js/inventory.js
var elm = document.getElementById('weapon-inventory');
- return new Inventory(world, camera, slots, models, actions, elm, 0.05);
+ return new Inventory(world, camera, slots, elm, 0.05, 'nextWeapon', 'activateWeapon');
}
function BlockInventory(world, camera) {
@crazy2be

crazy2be Mar 31, 2013

Owner

"BlockInventory" is kind of a silly name. I mean, it doesn't really hold blocks, it hold shovels and stuff. It's like your civilian inventory. Maybe "ConstructionInventory" would be better? I'm not sure. Any ideas?

@kieve

kieve Apr 1, 2013

Collaborator

UtilityInventory?

@crazy2be

crazy2be Apr 2, 2013

Owner

I was thinking about this some more...

Right now I'm tempted to call them BuildInventory and BlastInventory. Because, you know, why not?

But then It might make sense to switch their location on the screen, so build is on the left, and blast is on the right.

Any thoughts?

@crazy2be crazy2be commented on the diff Mar 31, 2013

client/js/main.js
@@ -24,6 +24,7 @@ window.onload = function () {
var stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
+ stats.domElement.style.right = '0px';
@crazy2be

crazy2be Mar 31, 2013

Owner

We might actually want to put things in the top-left in the future, and this way you don't have two stats counters when you enable the chrome builtin FPS counter.

@crazy2be crazy2be commented on the diff Mar 31, 2013

runserver
if go version; then
+ export GOPATH=`pwd`/server
@crazy2be

crazy2be Mar 31, 2013

Owner

This lets us split code up into modules, which is nice as our server code grows in size.

@crazy2be crazy2be commented on the diff Mar 31, 2013

server/src/buildblast/coords/coords.go
@@ -10,45 +10,57 @@ type Vec3 struct {
Z float64
}
-type WorldCoords struct {
+type World struct {
@crazy2be

crazy2be Mar 31, 2013

Owner

Since all this was moved into it's own "coords" package, the "Coords" suffixes are redundant.

@crazy2be crazy2be commented on the diff Mar 31, 2013

server/src/buildblast/coords/coords.go
X int
Y int
Z int
}
+
+const (
+ CHUNK_WIDTH = 32
+ CHUNK_DEPTH = 32
+ CHUNK_HEIGHT = 32
+)
+
+var CHUNK_SIZE Vec3 = Vec3{
@crazy2be

crazy2be Mar 31, 2013

Owner

This could be in mapgen. Not sure where it belongs really. Thoughts?

@kieve

kieve Apr 1, 2013

Collaborator

Maybe a separate file all together dedicated for constants like this? (Constants that describe the world, we could have more in the future.)

@crazy2be

crazy2be Apr 2, 2013

Owner

On second thought, I'll probably leave these here for now. 4 out of 6 of the occurrences of CHUNK_WIDTH in the source code are in the coords package, so that seems like a logical place for it, and that was probably why I put it there in the first place.

@crazy2be crazy2be commented on the diff Mar 31, 2013

server/src/buildblast/mapgen/mazeArena.go
@@ -0,0 +1,37 @@
+package mapgen
@crazy2be

crazy2be Mar 31, 2013

Owner

BTW, all these different map generation techniques are pretty fun to play with. Perlin noise allows you to create a lot of interesting stuff! You should try making a random map type! (Even if it's just FlatWorld).

@crazy2be crazy2be commented on an outdated diff Mar 31, 2013

server/src/buildblast/server/client.go
}
func (c *Client) handleClientPosition(m *MsgPlayerPosition) {
wc := m.Pos
- positionBroadcast := &MsgEntityPosition{
@crazy2be

crazy2be Mar 31, 2013

Owner

The server-side simulation logic does the broadcasting now.

Owner

crazy2be commented Mar 31, 2013

So it turned out not to be too difficult to add simple client-side prediction for movement, and it made a bunch of things cleaner, and the feature as a whole actually an improvement (in terms of user experience) over what we had previously.

I just added that code (there wasn't too much) to this pull request. That way, you can review the feature as a whole.

Owner

crazy2be commented Mar 31, 2013

Also, we currently only do prediction and server-side validation for player movement, and nothing else yet. However, this gives us the base we need to start moving more stuff to server, with good lag compensation and good anti-cheating measures.

I didn't want to make this pull request TOO huge.

Collaborator

kieve commented Apr 2, 2013

I don't think I can do any meaningful evaluation without building something with it. I'm going to accept it and attempt to finish building the chat on top of this.

@kieve kieve closed this Apr 2, 2013

@kieve kieve reopened this Apr 2, 2013

@kieve kieve added a commit that referenced this pull request Apr 2, 2013

@kieve kieve Merge pull request #38 from crazy2be/validation
Validation
866d460

@kieve kieve merged commit 866d460 into dev Apr 2, 2013

@crazy2be crazy2be deleted the validation branch Apr 2, 2013

Owner

crazy2be commented Apr 2, 2013

Ok. Feel free to ping me if you have any questions about how things work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment