]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Begin networking
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 17 Apr 2016 01:48:36 +0000 (11:48 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 17 Apr 2016 01:48:36 +0000 (11:48 +1000)
12 files changed:
qcsrc/client/autocvars.qh
qcsrc/client/main.qc
qcsrc/ecs/_mod.inc
qcsrc/ecs/cl_main.qc
qcsrc/ecs/components/physics.qc
qcsrc/ecs/components/physics.qh
qcsrc/ecs/main.qh
qcsrc/lib/_all.inc
qcsrc/lib/csqcmodel/interpolate.qc
qcsrc/lib/net.qh
qcsrc/lib/unsafe.qh
qcsrc/server/cl_client.qc

index c36d451547ca21b5109590575793f149e11193b8..5efd7cb20eb1e6428c23949c28654172cb1301b6 100644 (file)
@@ -420,7 +420,6 @@ float autocvar_cl_eventchase_speed = 1.3;
 vector autocvar_cl_eventchase_maxs = '12 12 8';
 vector autocvar_cl_eventchase_mins = '-12 -12 -8';
 vector autocvar_cl_eventchase_viewoffset = '0 0 20';
-float autocvar_cl_lerpexcess; // TODO: int?
 string autocvar__togglezoom;
 int autocvar_cl_damageeffect;
 float autocvar_cl_damageeffect_ticrate;
index 98b266c6d18410a39a466a66b77b452ee10a9ef5..8114023fde6b0ece4660a0810cde8cb7c7c446a4 100644 (file)
@@ -100,11 +100,6 @@ void CSQC_Init()
                maxclients = i;
        }
 
-       // needs to be done so early because of the constants they create
-       static_init();
-       static_init_late();
-       static_init_precache();
-
        binddb = db_create();
        tempdb = db_create();
        ClientProgsDB = db_load("client.db");
index dd98e07ea2769cb964ba7ecc52ed4cc7737317dc..c509ebffd1b7bd26219e116df44903bc52e32540 100644 (file)
@@ -3,3 +3,6 @@
 #ifdef CSQC
     #include "cl_main.qc"
 #endif
+#ifdef SVQC
+    #include "sv_main.qc"
+#endif
index 6064f7d64a80ef4ed6c0e0423fcbee1f1abf5fb1..b7e638f49b9aefd4a15bcc45664e3eebd956233d 100644 (file)
@@ -3,6 +3,11 @@
 #if !XONOTIC
        entity me;
 
+    /** 6 bits provides up to 64 remembered states */
+    const int SNAP_BITS = 13;
+    .int snap;
+    .float times[1 << SNAP_BITS];
+
        void CSQC_Init()
        {
                entity it = me = spawn();
                it.com_phys_gravity = 800;
        }
 
+       void CSQC_Ent_Update(bool isnew)
+       {
+           SELFPARAM();
+           int id = ReadByte();
+           entity recv = LinkedEntities_from(id);
+        if (isnew) this.classname = recv.netname;
+        if (recv) recv.m_read(this, NULL, isnew);
+       }
+
+       void rec()
+       {
+        me.ARRAY_INDEX(float, times, me.snap) = time;
+        // me.times[me.snap] = time;
+        me.snap = (me.snap + 1) & BITS(SNAP_BITS);
+       }
+
+       NET_HANDLE(ENT_OBJECT, bool isnew)
+       {
+           if (isnew)
+           {
+               this.com_phys = true;
+            precache_model("models/player/erebus.iqm");
+            _setmodel(this, "models/player/erebus.iqm");
+            this.drawmask = MASK_NORMAL;
+           }
+           this.com_phys_pos_prev = this.com_phys_pos;
+           this.com_phys_ang_prev = this.com_phys_ang;
+           serialize(ENT_OBJECT, 0, this);
+           this.com_phys_pos = this.origin;
+           this.com_phys_ang = this.angles;
+        return true;
+       }
+
        void CSQC_UpdateView(float w, float h)
        {
                entity it = me;
index bfca3d1ba3b05c3da56cfe72034087449199e48d..b46b83716cffe5f6fd5de71037504c9d1f265fa2 100644 (file)
@@ -5,6 +5,8 @@ bool autocvar_xon_com_phys_interpolate = true;
 void com_phys_interpolate(entity it, float a)
 {
        if (!autocvar_xon_com_phys_interpolate) a = 1;
+       // TODO: network time
+       // a = bound(0, (time - this.com_phys_time) / a, 1 /* + autocvar_cl_lerpexcess /* extrapolation frame limit */ */);
        it.origin = it.com_phys_pos * a + it.com_phys_pos_prev * (1 - a);
-       // TODO: orientation (slerp it)
+       it.angles = it.com_phys_ang * a + it.com_phys_ang_prev * (1 - a);  // TODO: slerp, not lerp
 }
index 92dae4cc754b8d1564d66e48ff9b2e7eb05e221c..fe22496b59a6bc55ebbaa85738fa38dfe120e7f3 100644 (file)
@@ -1,8 +1,9 @@
 #pragma once
 
+// TODO: store more frames for interpolation
 COMPONENT(phys);
-.vector com_phys_pos;
-.vector com_phys_pos_prev;
+.vector com_phys_pos; .vector com_phys_pos_prev;
+.vector com_phys_ang; .vector com_phys_ang_prev;
 .vector com_phys_vel;
 .vector com_phys_acc;
 
index 9b7bf3523810b7754d0c302682a6d912edb1968f..e1f56a628c31f571ad7535d0c9aaff423e4cde5f 100644 (file)
@@ -1,3 +1,11 @@
 #pragma once
 
+REGISTER_NET_LINKED(ENT_OBJECT);
+
+#define serialize_ENT_OBJECT(stream, this) \
+       MACRO_BEGIN \
+       serialize_vector(stream, this.origin); \
+       serialize_vector(stream, this.angles); \
+       MACRO_END
+
 void systems_update();
index ea1075a6eb593056d1d20493dd78098785f05be5..667371b436bd01f30f2d649a5bc19958f6661b17 100644 (file)
@@ -165,8 +165,8 @@ void    isnt_bool(float this) { print(ftos(this)); }
        void ClientKill() { if (_ClientKill) _ClientKill(); }
        #define ClientKill _ClientKill
 
-       void _PlayerPreThink();
-       void PlayerPreThink() { if (_PlayerPreThink) _PlayerPreThink(); }
+       void _PlayerPreThink(entity this);
+       void PlayerPreThink() { SELFPARAM(); if (_PlayerPreThink) _PlayerPreThink(this); }
        #define PlayerPreThink _PlayerPreThink
 
        void _PlayerPostThink();
@@ -176,7 +176,12 @@ void    isnt_bool(float this) { print(ftos(this)); }
 
 #ifdef CSQC
        void _CSQC_Init();
-       void CSQC_Init() { if (_CSQC_Init) _CSQC_Init(); }
+       void CSQC_Init() {
+        static_init();
+        static_init_late();
+        static_init_precache();
+        if (_CSQC_Init) _CSQC_Init();
+    }
        #define CSQC_Init _CSQC_Init
 
     void _CSQC_Shutdown();
index 4fd138360a3548bea865f8d7292f432e477865f0..bcfbadec75f96ba7d23a03061e78a616534d85aa 100644 (file)
@@ -125,6 +125,8 @@ void InterpolateOrigin_Note(entity this)
        }
 }
 
+float autocvar_cl_lerpexcess;
+
 /** set origin based on iorigin1 (old pos), iorigin2 (desired pos), and time */
 void InterpolateOrigin_Do(entity this)
 {
index faa24e71ae2c20f19d2f6d17f9491fbeb8d4236d..4323a227a411387b9d3fde94762c3ba5d1d7fd8a 100644 (file)
@@ -60,7 +60,7 @@ STATIC_INIT(RegisterTempEntities_renumber) { FOREACH(TempEntities, true, it.m_id
 #endif
 
 REGISTRY(LinkedEntities, BITS(8) - 1)
-#define LinkedEntities_from(i) _LinkedEntities_from(i, NULL)
+#define LinkedEntities_from(i) _LinkedEntities_from((i) - 1, NULL)
 REGISTER_REGISTRY(LinkedEntities)
 REGISTRY_SORT(LinkedEntities)
 REGISTRY_CHECK(LinkedEntities)
@@ -209,6 +209,63 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); }
                } MACRO_END
 #endif
 
+// serialization: new
+
+USING(Stream, int);
+#if defined(SVQC)
+       #define stream_reading(stream) false
+       #define stream_writing(stream) true
+#elif defined(CSQC)
+       #define stream_reading(stream) true
+       #define stream_writing(stream) false
+#endif
+
+#define serialize(T, stream, ...) serialize_##T(stream, __VA_ARGS__)
+
+#if defined(SVQC)
+       #define serialize_byte(stream, this) \
+               MACRO_BEGIN \
+               WriteByte(stream, this); \
+               MACRO_END
+#elif defined(CSQC)
+       #define serialize_byte(stream, this) \
+               MACRO_BEGIN \
+               this = ReadByte(); \
+               MACRO_END
+#endif
+
+#if defined(SVQC)
+       #define serialize_float(stream, this) \
+               MACRO_BEGIN \
+               WriteCoord(stream, this); \
+               MACRO_END
+#elif defined(CSQC)
+       #define serialize_float(stream, this) \
+               MACRO_BEGIN \
+               this = ReadCoord(); \
+               MACRO_END
+#endif
+
+#if defined(SVQC)
+       #define serialize_vector(stream, this) \
+               MACRO_BEGIN \
+               serialize_float(stream, this.x); \
+               serialize_float(stream, this.y); \
+               serialize_float(stream, this.z); \
+               MACRO_END
+#elif defined(CSQC)
+       #define serialize_vector(stream, this) \
+               MACRO_BEGIN \
+               vector _v; \
+               serialize_float(stream, _v.x); \
+               serialize_float(stream, _v.y); \
+               serialize_float(stream, _v.z); \
+               this = _v; \
+               MACRO_END
+#endif
+
+// serialization: old
+
 #define ReadRegistered(r) r##_from(Read_byte())
 #define WriteRegistered(r, to, it) Write_byte(to, it.m_id)
 
@@ -272,7 +329,7 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); }
                #define ReadVector() vec3(ReadFloat(), ReadFloat(), ReadFloat())
                #define ReadVector2D() vec3(ReadFloat(), ReadFloat(), 0)
 
-        float servertime;
+               float servertime;
 
                float ReadApproxPastTime()
                {
index 97e1c7958493f1c5ba6caa3403c7b9ea9e84020d..60ad3d88da517e11174910a1a1d5da29085b5b15 100644 (file)
@@ -1,10 +1,13 @@
 #pragma once
 
 #define reinterpret_cast(T, it) _unsafe_cast_##T(0, it)
-#define X(T) T _unsafe_cast_##T(int dummy, ...) { return ...(0, T); }
+#define X(T) \
+    T _unsafe_cast_##T(int dummy, ...) { return ...(0, T); } \
+    USING(T##_fld, .T); T##_fld _unsafe_cast_##T##_fld(int dummy, ...) { return ...(0, T##_fld); }
 X(bool)
 X(int)
 X(float)
+X(vector)
 X(entity)
 X(string)
 USING(rawfunc, float(...));
@@ -24,3 +27,5 @@ STATIC_INIT(INTEGER_ONE)
 {
     INTEGER_ONE = reinterpret_cast(int, _unsafe_fld2) - reinterpret_cast(int, _unsafe_fld1);
 }
+
+#define ARRAY_INDEX(T, arr, idx) (reinterpret_cast(T##_fld, reinterpret_cast(int, arr[0]) + FTOI(idx)))
index ffbb55087bef4ac48a98e36c8d9402fc9c7eb64c..5e8db5559f3ad7909c1731a26c00c7fbfeec8ce9 100644 (file)
@@ -2071,9 +2071,8 @@ Called every frame for each client before the physics are run
 void() nexball_setstatus;
 .float last_vehiclecheck;
 .int items_added;
-void PlayerPreThink ()
+void PlayerPreThink (entity this)
 {
-    SELFPARAM();
        WarpZone_PlayerPhysics_FixVAngle(this);
 
     STAT(GAMESTARTTIME, this) = game_starttime;