131 |
{ |
{ |
132 |
class MouseForce : public ForceField { |
class MouseForce : public ForceField { |
133 |
public: |
public: |
134 |
MouseForce() {maxforce = 150;} |
void set_force(V3 f) { force=f; } |
135 |
|
void add_force(V3 f) { force+=f; } |
136 |
void set_force(V3 f) { force=f; limit_force(); } |
// void set_force(V3 f) { force=f*options::MouseDamping/25.0;} |
137 |
void add_force(V3 f) { force+=f; limit_force(); } |
// void add_force(V3 f) { force+=f*options::MouseDamping/25.0; } |
138 |
|
|
139 |
V3 get_force(Actor *a, V3 x, V3 v, double time) |
V3 get_force(Actor *a, V3 x, V3 v, double time) |
140 |
{ |
{ |
156 |
force *= exp(-dtime*damping); |
force *= exp(-dtime*damping); |
157 |
|
|
158 |
// if (length(force) < 0.01) |
// if (length(force) < 0.01) |
159 |
// force = V3(); |
// force = V3(); |
160 |
} |
} |
161 |
private: |
private: |
|
void limit_force() {} |
|
|
|
|
|
double maxforce; // maximum force possible |
|
162 |
V3 force; |
V3 force; |
163 |
}; |
}; |
164 |
} |
} |
273 |
{ |
{ |
274 |
// Mouse force |
// Mouse force |
275 |
V3 mousef = mouseforce->get_force(a,x,v, time); |
V3 mousef = mouseforce->get_force(a,x,v, time); |
276 |
mousef *= floor->mousefactor(); |
double mf = floor->mousefactor(); |
277 |
|
// if (mf < 0) |
278 |
|
// mousef *= -1; |
279 |
|
mousef *= mf; |
280 |
f += mousef; |
f += mousef; |
281 |
|
|
282 |
// Friction |
// Friction |
284 |
if (vv > 0) { |
if (vv > 0) { |
285 |
V3 frictionf = v * options::FrictionFactor*floor->friction(); |
V3 frictionf = v * options::FrictionFactor*floor->friction(); |
286 |
frictionf /= vv; |
frictionf /= vv; |
287 |
frictionf *= pow(vv, 0.7); |
frictionf *= pow(vv, 0.8); |
288 |
f -= frictionf; |
f -= frictionf; |
289 |
} |
} |
290 |
f += floor->get_force(a); |
f += floor->get_force(a); |
853 |
{ |
{ |
854 |
st_layer.set(p,st); |
st_layer.set(p,st); |
855 |
laser::MaybeRecalcLight(p); |
laser::MaybeRecalcLight(p); |
|
// laser::MaybeRecalcLight(newp); |
|
856 |
changed_stones.push_back(p); |
changed_stones.push_back(p); |
857 |
} |
} |
858 |
|
|
863 |
if (GetStone(newp) == 0) |
if (GetStone(newp) == 0) |
864 |
{ |
{ |
865 |
Stone *st = GetStone(p); |
Stone *st = GetStone(p); |
866 |
if (st && st->on_move()) |
if (st && st->is_movable()) |
867 |
{ |
{ |
868 |
sound::PlaySound("st-move"); |
sound::PlaySound("st-move"); |
869 |
SetStone(newp, YieldStone(p)); |
SetStone(newp, YieldStone(p)); |
870 |
|
st->on_move(); |
871 |
return true; |
return true; |
872 |
} |
} |
873 |
} |
} |
960 |
void |
void |
961 |
world::Tick(double dtime) |
world::Tick(double dtime) |
962 |
{ |
{ |
963 |
for (ActorList::iterator i=actorlist.begin(); i!=actorlist.end(); ++i) { |
const double timestep = 15.0/1000; |
964 |
ActorInfo *ai = (*i)->get_actorinfo(); |
static double timeaccu = 0.0; |
|
if (!ai->grabbed && !(*i)->is_dead()) |
|
|
{ |
|
|
ai->forceacc2 = ai->forceacc; |
|
|
ai->forceacc = V3(); |
|
|
tick_actor(*i, dtime); |
|
|
} |
|
|
} |
|
|
// Tell floors and items about new stones. |
|
|
for (unsigned i=0; i<changed_stones.size(); ++i) |
|
|
stone_change(changed_stones[i]); |
|
|
changed_stones.clear(); |
|
965 |
|
|
966 |
|
timeaccu += dtime; |
967 |
|
|
968 |
|
while (timeaccu >= timestep) { |
969 |
|
for (ActorList::iterator i=actorlist.begin(); i!=actorlist.end(); ++i) { |
970 |
|
ActorInfo *ai = (*i)->get_actorinfo(); |
971 |
|
if (!ai->grabbed && !(*i)->is_dead()) |
972 |
|
{ |
973 |
|
ai->forceacc2 = ai->forceacc; |
974 |
|
ai->forceacc = V3(); |
975 |
|
tick_actor(*i, timestep); |
976 |
|
} |
977 |
|
} |
978 |
|
// Tell floors and items about new stones. |
979 |
|
for (unsigned i=0; i<changed_stones.size(); ++i) |
980 |
|
stone_change(changed_stones[i]); |
981 |
|
changed_stones.clear(); |
982 |
|
|
|
mouseforce->tick(dtime); |
|
|
for_each(forces.begin(), forces.end(), |
|
|
bind2nd(mem_fun(&ForceField::tick), dtime)); |
|
983 |
|
|
984 |
g_timer.tick(dtime); |
mouseforce->tick(timestep); |
985 |
laser::RecalcLightNow(); // recalculate laser beams if necessary |
for_each(forces.begin(), forces.end(), |
986 |
|
bind2nd(mem_fun(&ForceField::tick), timestep)); |
987 |
|
|
988 |
|
g_timer.tick(timestep); |
989 |
|
laser::RecalcLightNow(); // recalculate laser beams if necessary |
990 |
|
timeaccu -= timestep; |
991 |
|
timeaccu = 0; |
992 |
|
} |
993 |
} |
} |
994 |
|
|
995 |
void |
void |