Welcome to mirror list, hosted at ThFree Co, Russian Federation.

itemobject.h « Objects « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b684d5441f851a7463926ae3ec2adbe49f8e296b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//-----------------------------------------------------------------------------
//           Name: itemobject.h
//      Developer: Wolfire Games LLC
//    Description:
//        License: Read below
//-----------------------------------------------------------------------------
//
//   Copyright 2022 Wolfire Games LLC
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
//-----------------------------------------------------------------------------
#pragma once

#include <Online/time_interpolator.h>
#include <Online/online_datastructures.h>

#include <Graphics/drawbatch.h>
#include <Graphics/bloodsurface.h>

#include <Asset/Asset/item.h>
#include <Asset/Asset/objectfile.h>

#include <Objects/object.h>
#include <XML/level_loader.h>
#include <Physics/bulletworld.h>
#include <Game/color_tint_component.h>

#include <vector>
#include <string>
#include <list>

//-----------------------------------------------------------------------------
// Class Definition
//-----------------------------------------------------------------------------

class BulletObject;
class ItemObjectScriptReader;
class ASContext;
struct Flare;
class ItemObject;

class ItemObjectBloodSurfaceTransformedVertexGetter : public BloodSurface::TransformedVertexGetter {
   public:
    ItemObjectBloodSurfaceTransformedVertexGetter(ItemObject* p_item_object) : item_object(p_item_object) {}
    vec3 GetTransformedVertex(int val) override;

   private:
    ItemObject* item_object;
};

class ItemObject : public Object {
   public:
    EntityType GetType() const override { return _item_object; }
    enum ItemState {
        kWielded,
        kSheathed,
        kFree
    };

    ItemObject();
    ~ItemObject() override;

    void Load(const std::string& item_path);
    void GetShaderNames(std::map<std::string, int>& preload_shaders) override;

    bool Initialize() override;
    void Update(float timestep) override;
    void Draw() override;
    void PreDrawFrame(float curr_game_time) override;
    bool ConnectTo(Object& other, bool checking_other = false) override;
    virtual bool Disconnect(Object& other, bool checking_other = false);
    void Moved(Object::MoveType type) override;

    int model_id() const;
    const ItemRef& item_ref() const;
    const vec3& phys_offset() const;
    ItemState state() const;

    void Copied();

    void AddReader(ItemObjectScriptReader* reader);
    void RemoveReader(ItemObjectScriptReader* reader);
    void InvalidateReaders();
    void InvalidateHeldReaders();
    bool IsHeld();
    int StuckInWhom();

    void SetPosition(const vec3& pos);
    vec3 GetPhysicsPosition();
    void SetPhysicsTransform(const mat4& transform);
    void SetVelocities(const vec3& linear_vel, const vec3& angular_vel);
    void SetInterpolation(int count, int period);
    void ActivatePhysics();
    vec3 GetAngularVelocity();
    void SetAngularVelocity(vec3 vel);
    mat4 GetPhysicsTransform();
    mat4 GetPhysicsTransformIncludeOffset();
    void GetPhysicsVel(vec3& linear_vel, vec3& angular_vel);
    void SetLinearVelocity(vec3 vel);
    vec3 GetLinearVelocity();
    void WakeUpPhysics();
    void SleepPhysics();
    btTypedConstraint* AddConstraint(BulletObject* _bullet_object);
    void RemoveConstraint(btTypedConstraint** constraint);

    mat4 GetTransform() const;  // Returns final transform matix, used in multiplayer

    void Collided(const vec3& pos, float impulse, const CollideInfo& collide_info, BulletObject* object) override;
    void GetDesc(EntityDescription& desc) const override;
    void AddBloodDecal(vec3 pos, vec3 dir, float size);
    void CleanBlood();
    void Reset() override;
    void Dispose() override;
    void SetHolderID(int char_id);
    void SetThrown();
    void SetThrownStraight();
    void SetState(ItemState state);
    ScriptParams* ASGetScriptParams();
    int HeldByWhom();
    void ReceiveObjectMessageVAList(OBJECT_MSG::Type type, va_list args) override;
    bool SetFromDesc(const EntityDescription& desc) override;
    const vec3& GetColorTint();
    const float& GetOverbright();
    bool CheckThrownSafe() const;
    void SetSafe();
    vec3 GetTransformedVertex(int which);
    int last_held_char_id_;

    std::list<ItemObjectFrame> incoming_online_item_frames;

   private:
    enum ThrownState {
        kSafe,
        kThrown,
        kThrownStraight,
        kBounced
    };
    enum WeightClass {
        kLightWeight,
        kMediumWeight,
        kHeavyWeight
    };

    uint64_t last_frame = 0;

    // final model matrix. Stored as member variable to use for network interpolation
    mat4 transform;
    bool use_tangent_;
    ColorTintComponent color_tint_component_;
    ItemState state_;
    ThrownState thrown_;
    float active_time_;

    float sun_ray_clear_;
    float new_clear_;
    vec3 last_sun_checked_;

    ItemObjectBloodSurfaceTransformedVertexGetter blood_surface_getter_;
    BloodSurface blood_surface_;
    int shadow_group_id_;
    std::vector<TextureAssetRef> textures_;
    DrawBatch batch_;
    DrawBatch depth_batch_;
    int shader_id_;
    int depth_shader_id_;
    int shadow_catch_shader_id_;
    int model_id_;
    ObjectFileRef ofc_;
    ItemRef item_ref_;

    unsigned long whoosh_sound_handle_;
    std::vector<int> attached_sounds_;
    float impact_sound_delay_;
    float whoosh_sound_delay_;
    float whoosh_volume_;
    float whoosh_pitch_;

    bool using_physics_;
    BulletObject* bullet_object_;
    BulletObject* abstract_bullet_object_;
    vec3 phys_offset_;
    vec3 display_phys_offset_;
    int interp_count_;
    int interp_period_;
    mat4 old_transform_;
    vec3 old_lin_vel_;
    vec3 old_ang_vel_;

    bool stuck_in_environment_;
    bool sticking_collision_occured_;
    vec3 stuck_pos_;
    int stuck_vert_;
    mat4 stuck_transform_;
    CollideInfo stuck_collide_info_;

    Flare* flare_;
    bool flashing_;
    float flash_progress_;
    float flash_delay_;

    std::list<ItemObjectScriptReader*> readers_;
    float char_impact_delay_;

    TextureAssetRef texture_spatterdecal_;
    std::string shader;

    TimeInterpolator network_time_interpolator;

    void DrawDepthMap(const mat4& proj_view_matrix, const vec4* cull_planes, int num_cull_planes, Object::DrawType draw_type) override;
    virtual void HandleMaterialEvent(const std::string& the_event, const vec3& normal, const vec3& event_pos, float gain = 1.0f, float pitch_shift = 1.0f);

    void MakeBulletObject();
    void StickingCollisionOccured(const vec3& pos, int vert, const CollideInfo& collide_info);
    void StickToEnvironment(const vec3& pos, int vert, const CollideInfo& collide_info);
    vec3 WorldToModelPos(const vec3& pos);
    vec3 ModelToWorldPos(const vec3& pos);
    float GetVertSharpness(int vert);
    int GetClosestVert(const vec3& pos);
    vec3 GetVertPos(int vert);
    WeightClass GetWeightClass();
    bool IsStuckInCharacter();
    bool IsConstrained();
    void HandleThrownImpact(const vec3& start, const vec3& end, int char_id, int line_id, const mat4& cur_transform, const mat4& transform);
    void CheckThrownCollisionLine(int line_id, const mat4& cur_transform, const mat4& transform);
    void DrawItem(const mat4& proj_view_matrix, DrawType type);

   public:
    void PlayImpactSound(const vec3& pos, const vec3& normal, float impulse);
};

void DefineItemObjectTypePublic(ASContext* as_context);