Skip to content
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
56 changes: 19 additions & 37 deletions lib-src/enigma-core/ecl_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "ecl_buffer.hh"
#include <cstring>
#include <iostream>

using namespace ecl;
Expand Down Expand Up @@ -62,8 +63,8 @@ char* Buffer::get_rspace(size_t len) {
int Buffer::read() {
if (good() && rpos < buf + sz)
return *rpos++;
else
return -1;
iostate = State(iostate | FAILBIT | EOFBIT);
return -1;
}

Buffer& Buffer::write(char c) {
Expand Down Expand Up @@ -225,56 +226,37 @@ Buffer& ecl::write(Buffer& buf, Uint64 lvar) {
*/

/* NOTE: we reinterpret floats and doubles as Uint32/Uint64,
** and byte-swap them like integers.
** This is how quake does it, too (except they only use floats).
** I couldn't believe that this worked, so I checked it out
** (PPC <-> x86), and it does. The upside (over multiplying
** with 2048 and converting to int, as it was before) is that
** we have the same rep on both machines, possibly leading to
** less desynchronisation in network games.
** and byte-swap them like integers, so we have the same wire rep
** on both machines. memcpy is the idiomatic spelling — the optimizer
** turns it into a register move — and avoids the type-pun-via-union
** UB.
*/

Buffer& ecl::read(Buffer& buf, float& dvar) {
union {
float f;
Uint32 a;
} t;
if (buf >> t.a)
dvar = t.f;
Uint32 a;
if (buf >> a)
std::memcpy(&dvar, &a, sizeof dvar);
return buf;
}

Buffer& ecl::write(Buffer& buf, float dvar) {
union {
float f;
Uint32 a;
} t;
t.f = dvar;
write(buf, t.a);
Uint32 a;
std::memcpy(&a, &dvar, sizeof dvar);
write(buf, a);
return buf;
}

/*
** === Read and write doubles ===
*/

Buffer& ecl::read(Buffer& buf, double& dvar) {
union {
double d;
Uint64 a;
} t;
if (buf >> t.a)
dvar = t.d;
Uint64 a;
if (buf >> a)
std::memcpy(&dvar, &a, sizeof dvar);
return buf;
}

Buffer& ecl::write(Buffer& buf, double dvar) {
union {
double d;
Uint64 a;
} t;
t.d = dvar;
write(buf, t.a);
Uint64 a;
std::memcpy(&a, &dvar, sizeof dvar);
write(buf, a);
return buf;
}

Expand Down
1 change: 1 addition & 0 deletions lib-src/enigma-core/ecl_buffer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public:
void clear() {
sz = 0;
rpos = wpos = buf;
iostate = GOODBIT;
}

void assign(char* data, size_t size);
Expand Down
2 changes: 1 addition & 1 deletion src/Inventory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef std::vector<Item*> ItemList;
unsigned const Inventory::max_items = 12;


Inventory::Inventory() : m_items () {
Inventory::Inventory() : m_items(), ownerId(-1) {
}


Expand Down
1 change: 1 addition & 0 deletions src/Inventory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace enigma
// ---------- Methods ----------

void assignOwner(int playerId);
int getOwner() const { return ownerId; }

//! The number of items currently in the inventory
size_t size() const;
Expand Down
10 changes: 10 additions & 0 deletions src/MouseCursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ void MouseCursor::hide() {
}
}

void MouseCursor::recapture_background() {
if (visible > 0) {
if (!background)
init_bg();
else
grab_bg();
changed = true;
}
}

Rect MouseCursor::get_rect() const {
return Rect(x - hotx, y - hoty, cursor->width(), cursor->height());
}
Expand Down
5 changes: 5 additions & 0 deletions src/MouseCursor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public:
void draw(); // Draw cursor if visible
void show();
void hide();
// Re-capture the screen pixels under the cursor without first
// restoring the (possibly stale) saved copy. Use this after a
// screen-wide repaint (e.g. menu->game transition) so the next
// cursor move doesn't restore stale pixels.
void recapture_background();
ecl::Rect get_rect() const;
ecl::Rect get_oldrect() const;

Expand Down
8 changes: 8 additions & 0 deletions src/Object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ int Object::getId() const {
return id;
}

int Object::getNextIdSnapshot() {
return next_id;
}

void Object::setNextId(int v) {
next_id = v;
}

std::string Object::getKind() const {
return ObjectValidator::instance()->getKind(this);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Object.hh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public:
static Object *getObject(int id);
int getId() const;

// Snapshot/restore the global id counter. Used by the LAN
// protocol's SV_ACTOR_ADDED dispatcher to land each new actor on
// the host's id, so subsequent SV_ACTOR_MOVED packets resolve.
static int getNextIdSnapshot();
static void setNextId(int v);

/* ---------- depreceated methods ---------- */

const AttribMap &get_attribs() const {
Expand Down
2 changes: 2 additions & 0 deletions src/SoundEffectManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ void sound::DefineSoundEffect(std::string soundset_key, std::string name, std::s
bool sound::EmitSoundEvent (const std::string &eventname, const ecl::V2 &pos,
double volume, bool force_global)
{
enigma::client::NotifySound(eventname, pos, volume, force_global);
return SoundEffectManager::instance()->emitSoundEvent(eventname, pos, volume, force_global);
}

bool sound::EmitSoundEventGlobal (const std::string &eventname, double volume)
{
enigma::client::NotifySound(eventname, ecl::V2(), volume, true);
return SoundEffectManager::instance()->emitSoundEvent(eventname, ecl::V2(), volume, true);
}

Expand Down
2 changes: 2 additions & 0 deletions src/actors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "errors.hh"
#include "client.hh"
#include "enigma.hh"
#include "player.hh"
#include "Inventory.hh"
Expand Down Expand Up @@ -312,6 +313,7 @@ void Actor::move_screen() {

void Actor::set_model(const std::string &name) {
m_sprite.replace_model(display::MakeModel(name));
client::NotifyActorSpriteChanged(getId(), name);
}

void Actor::animcb() {
Expand Down
2 changes: 1 addition & 1 deletion src/actors.hh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public:
virtual void move_screen();
void warp(const ecl::V2 &newpos);
bool sound_event(const char *name, double vol = 1.0);
void set_model(const std::string &modelname);

void respawn();
void set_respawnpos(const ecl::V2 &p);
Expand Down Expand Up @@ -196,7 +197,6 @@ protected:
virtual Object::ObjectType getObjectType() const override { return Object::ACTOR; }

Actor(const ActorTraits &tr);
void set_model(const std::string &modelname);
void set_anim(const std::string &modelname);

display::SpriteHandle &get_sprite() { return m_sprite; }
Expand Down
Loading