Permalink
Browse files

A nice commit. For details read comment.

• Gravel/sand falling fixed
• Added my own epic timer class thing.
• cleaned up some code
• qtcreator auto-fixing some whitespace in mineserver.cpp
• Added fastset.h (might be used in the future hopefully)
• Fixed player teleporting/moving
• added some protocol packet creation overloads for simplicity
  • Loading branch information...
1 parent b4c8fe5 commit 4f30aab7d75d3f7fe574f55dece03ea1659f81ab Eximius committed with Aug 8, 2012
Showing with 108 additions and 172 deletions.
  1. +3 −0 .gitignore
  2. +18 −1 include/protocol.h
  3. +19 −5 include/user.h
  4. +1 −1 src/blocks/falling.cpp
  5. +10 −10 src/mineserver.cpp
  6. +4 −1 src/mineserver.pro
  7. +22 −19 src/physics.cpp
  8. +31 −135 src/user.cpp
View
@@ -9,3 +9,6 @@ include/configure.h
# ignore our compile directory
bin
+
+# qmake .pro(ject) per platform config file
+src/mineserver.pro.user
View
@@ -146,6 +146,15 @@ class Protocol
return ret;
}
+ static Packet entityTeleport(int eid, const position& pos)
+ {
+ Packet ret;
+ ret << (int8_t)PACKET_ENTITY_TELEPORT << (int32_t)eid
+ << (int32_t)(pos.x * 32) << (int32_t)(pos.y * 32) << (int32_t)(pos.z * 32)
+ << (int8_t)pos.yaw << (int8_t)pos.pitch;
+ return ret;
+ }
+
static Packet entityHeadLook(int eid, int head_yaw)
{
Packet ret;
@@ -219,14 +228,22 @@ class Protocol
return ret;
}
- static Packet namedEntitySpawn(int eid, std::string nick, double x, double y, double z, int yaw, int pitch, int item)
+ static Packet namedEntitySpawn(int eid, const std::string& nick, double x, double y, double z, int yaw, int pitch, int item)
{
Packet ret;
ret << (int8_t)PACKET_NAMED_ENTITY_SPAWN << (int32_t)eid << nick
<< (int32_t)(x * 32) << (int32_t)(y * 32) << (int32_t)(z * 32)
<< (int8_t)yaw << (int8_t)pitch << (int16_t)item << (int8_t)0 << (int8_t)0 << (int8_t)127;
return ret;
}
+ static Packet namedEntitySpawn(int eid, const std::string& nick, const position& pos, int item){
+ Packet ret;
+ ret << (int8_t)PACKET_NAMED_ENTITY_SPAWN << (int32_t)eid << nick
+ << (int32_t)(pos.x*32)<<(int32_t)(pos.y * 32) << (int32_t)(pos.z * 32)
+ << (int8_t)pos.yaw << (int8_t)pos.pitch << (int16_t)item
+ << (int8_t)0 << (int8_t)0 << (int8_t)127;
+ return ret;
+ }
static Packet addObject(int eid, int8_t object, double x, double y, double z, int objectData, int16_t speed_x = 0, int16_t speed_y = 0,int16_t speed_z = 0)
{
View
@@ -42,6 +42,8 @@
#include "packets.h"
#include "mineserver.h"
+//#include "chunkmap.h"
+
struct position
{
double x;
@@ -69,22 +71,33 @@ class User
//View distance in chunks -viewDistance <-> viewDistance
static const int viewDistance = 10;
+
+ std::string nick;
+ position pos;
+ int16_t health;
+
+ Item inv[45];
+ int16_t curItem;
+
+ /// updates this user's world (queues chunks, adds/removes entities)
+ void updateWorld();
+
+ /// chunks in use by user
+ //fastset<sChunk*> usedChunks;
+ /// chunk in which user last was during last updateWorld()
+ //sChunk* lastChunk;
+
uint8_t action;
bool waitForData;
uint32_t write_err_count;
bool logged;
bool muted;
bool dnd;
- int16_t health;
uint16_t timeUnderwater;
double fallDistance;
unsigned int UID;
- std::string nick;
std::string temp_nick;
- position pos;
vec curChunk;
- Item inv[45];
- int16_t curItem;
time_t healthtimeout;
Item inventoryHolding;
//Do we have an open _shared_ inventory?
@@ -123,6 +136,7 @@ class User
bool changeNick(std::string _nick);
void checkEnvironmentDamage();
+
bool updatePos(double x, double y, double z, double stance);
bool updatePosM(double x, double y, double z, size_t map, double stance);
/** Check if the user is standing on this block */
View
@@ -169,7 +169,7 @@ void BlockFalling::applyPhysics(User* user, int32_t x, int16_t y, int32_t z, int
it->second->sendPacket(pkt);
//Add to physics loop
- ServerInstance->physics(map)->addFallSimulation(fallblock,vec(x, y+1, z), EID);
+ ServerInstance->physics(map)->addFallSimulation(fallblock,vec(x, y, z), EID);
this->notifyNeighbours(x, y + 1, z, map, "onNeighbourMove", user, fallblock, BLOCK_BOTTOM);
View
@@ -367,7 +367,7 @@ Mineserver::Mineserver(int args, char **argarray)
m_physics.push_back(phy);
RedstoneSimulation* red = new RedstoneSimulation;
- red->map = n;
+ red->map = n;
m_redstone.push_back(red);
int k = m_config->iData((std::string(key) + ".") + (*it));
if ((uint32_t)k >= m_mapGenNames.size())
@@ -435,12 +435,12 @@ Mineserver::~Mineserver()
// Remove the PID file
unlink((config()->sData("system.pid_file")).c_str());
- #ifdef PROTOCOL_ENCRYPTION
+#ifdef PROTOCOL_ENCRYPTION
RSA_free(rsa);
X509_free(x);
pk->pkey.ptr = NULL;
EVP_PKEY_free(pk);
- #endif
+#endif
}
@@ -697,7 +697,7 @@ bool Mineserver::run()
{
// Send server time and keepalive
Packet pkt;
- pkt << Protocol::timeUpdate(m_map[0]->mapTime);
+ pkt << Protocol::timeUpdate(m_map[0]->mapTime);
pkt << Protocol::keepalive(0);
pkt << Protocol::playerlist();
(*User::all().begin())->sendAll(pkt);
@@ -723,9 +723,9 @@ bool Mineserver::run()
// Loop users
for (std::set<User*>::iterator it = users().begin(), it_end = users().end(); it != it_end;)
{
- // NOTE: iterators corrupt when you delete their objects, therefore we have to iterate in a special way - Justasic
- User *u = *it;
- ++it;
+ // NOTE: iterators corrupt when you delete their objects, therefore we have to iterate in a special way - Justasic
+ User *u = *it;
+ ++it;
// No data received in 30s, timeout
if (u->logged && timeNow - u->lastData > 30)
{
@@ -819,11 +819,11 @@ bool Mineserver::run()
client_write((*it));
}
}
- #ifdef WIN32
+#ifdef WIN32
closesocket(m_socketlisten);
- #else
+#else
close(m_socketlisten);
- #endif
+#endif
saveAll();
View
@@ -11,6 +11,8 @@ win32{
LIBS += -lnoise -leay32 -lssleay32 -lssl32 -lpdcurses -lz -levent -lWs2_32 -lwinmm -lpthread
INCLUDEPATH += $$(MINESERVER_WIN32_LIBS)/include
+
+ QMAKE_LFLAGS += -Wl,--large-address-aware
}
unix{
@@ -174,4 +176,5 @@ HEADERS += \
../include/cliScreen.h \
../include/chunkmap.h \
../include/chat.h \
- configure.h
+ configure.h \
+ ../include/stdtime.h
View
@@ -224,20 +224,26 @@ bool Physics::updateFall()
for (int32_t simIt = listSize-1; simIt >= 0; simIt--)
{
- bool hitGround = false;
- double timeInSec = (microTime()-fallSimList[simIt].startTime)/1000000.0;
- fallSimList[simIt].ticks++;
+ Falling& f = fallSimList[simIt];
+
+ double timeInSec = (microTime()-f.startTime)/1000000.0;
+ f.ticks++;
const double gravity = 9.81;
double offset = 0.5*gravity*timeInSec*timeInSec;
- int blockOffset = fallSimList[simIt].pos.y() - fallSimList[simIt].lastY;
- if(blockOffset != (int)offset)
+ int blockOffset = f.pos.y() - f.lastY;
+ if(blockOffset != (int)offset) /// not necessary, doesn't optimize much
{
- for(int ypos = fallSimList[simIt].lastY-1; ypos >= fallSimList[simIt].lastY-((int)offset-blockOffset);ypos--)
+ int yStart = f.pos.y();
+ int x = f.pos.x(); int z = f.pos.z();
+
+ int ypos = f.lastY;
+
+ f.lastY = yStart-(int)offset;
+ for(; ypos >= f.lastY;ypos--)
{
uint8_t block, meta;
- ServerInstance->map(map)->getBlock(fallSimList[simIt].pos.x(),ypos,fallSimList[simIt].pos.z(), &block, &meta);
- fallSimList[simIt].lastY--;
+ ServerInstance->map(map)->getBlock(x,ypos,z, &block, &meta);
switch (block)
{
case BLOCK_AIR:
@@ -250,30 +256,27 @@ bool Physics::updateFall()
//If we hit ground
default:
{
- ServerInstance->map(map)->setBlock(fallSimList[simIt].pos.x(),ypos+1,fallSimList[simIt].pos.z(), fallSimList[simIt].block, 0);
- ServerInstance->map(map)->sendBlockChange(fallSimList[simIt].pos.x(),ypos+1,fallSimList[simIt].pos.z(), fallSimList[simIt].block, 0);
+ ServerInstance->map(map)->setBlock(x, ++ypos, z, f.block, 0);
+ ServerInstance->map(map)->sendBlockChange(x, ypos, z, f.block, 0);
//Despawn entity
- Packet pkt = Protocol::destroyEntity(fallSimList[simIt].EID);
- const int chunk_x = blockToChunk(fallSimList[simIt].pos.x());
- const int chunk_z = blockToChunk(fallSimList[simIt].pos.z());
+ Packet pkt = Protocol::destroyEntity(f.EID);
+ const int chunk_x = blockToChunk(x);
+ const int chunk_z = blockToChunk(z);
const ChunkMap::const_iterator it = ServerInstance->map(map)->chunks.find(Coords(chunk_x, chunk_z));
if (it != ServerInstance->map(map)->chunks.end())
{
it->second->sendPacket(pkt);
}
//Erase from the simulation list
fallSimList.erase(fallSimList.begin()+simIt);
- hitGround = true;
- break;
+ goto breakout;
}
}
- if(hitGround)
- {
- break;
- }
}
}
+breakout:
+ continue;
}
return true;
}
Oops, something went wrong.

0 comments on commit 4f30aab

Please sign in to comment.