# It's usually sufficient to change just the target name and source file list\r
# and be sure that CXX is set to a valid compiler\r
TARGET = test\r
-SOURCE_FILES = irrlichtwrapper.cpp guiPauseMenu.cpp defaultsettings.cpp mapnode.cpp tile.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp client.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp main.cpp test.cpp\r
+SOURCE_FILES = guiInventoryMenu.cpp irrlichtwrapper.cpp guiPauseMenu.cpp defaultsettings.cpp mapnode.cpp tile.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp client.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp main.cpp test.cpp\r
SOURCES = $(addprefix src/, $(SOURCE_FILES))\r
BUILD_DIR = build\r
OBJECTS = $(addprefix $(BUILD_DIR)/, $(SOURCE_FILES:.cpp=.o))\r
$(DESTPATH): $(OBJECTS)\r
$(CXX) -o $@ $(OBJECTS) $(LDFLAGS)\r
\r
-$(FAST_DESTPATH): $(SOURCES)\r
+$(FAST_DESTPATH): $(OBJECTS)\r
$(CXX) -o $@ $(OBJECTS) $(LDFLAGS) -DUNITTEST_DISABLE\r
\r
$(SERVER_DESTPATH): $(SERVER_OBJECTS)\r
RelativePath=".\src\debug.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\src\defaultsettings.cpp"\r
+ >\r
+ </File>\r
<File\r
RelativePath=".\src\environment.cpp"\r
>\r
RelativePath=".\src\inventory.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\src\irrlichtwrapper.cpp"\r
+ >\r
+ </File>\r
<File\r
RelativePath=".\src\light.cpp"\r
>\r
#include "jmutexautolock.h"
#include "main.h"
#include <sstream>
-
-#ifdef _WIN32
- #include <windows.h>
- #define sleep_ms(x) Sleep(x)
-#else
- #include <unistd.h>
- #define sleep_ms(x) usleep(x*1000)
-#endif
+#include "porting.h"
void * ClientUpdateThread::Thread()
{
// Viewing range stuff
//#define FREETIME_RATIO 0.15
-#define FREETIME_RATIO 0.0
+//#define FREETIME_RATIO 0.0
+#define FREETIME_RATIO 0.05
// Sectors are split to SECTOR_HEIGHTMAP_SPLIT^2 heightmaps
#define SECTOR_HEIGHTMAP_SPLIT 2
#include "debug.h"
#include <stdio.h>
#include <stdlib.h>
-
-#ifdef _WIN32
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
- #define sleep_ms(x) Sleep(x)
-#else
- #include <unistd.h>
- #define sleep_ms(x) usleep(x*1000)
-#endif
+#include "porting.h"
/*
Debug output
i != m_players.end(); i++)
{
Player *player = *i;
+
+ v3f playerpos = player->getPosition();
// Apply physics to local player
if(player->isLocal())
*/
player->move(dtime_part, *m_map);
+ /*
+ Update lighting on remote players on client
+ */
+ u8 light = LIGHT_MAX;
+ try{
+ // Get node at feet
+ v3s16 p = floatToInt(playerpos + v3f(0,BS/4,0));
+ MapNode n = m_map->getNode(p);
+ light = n.getLightBlend(m_daynight_ratio);
+ }
+ catch(InvalidPositionException &e) {}
+ player->updateLight(light);
+
/*
Add footsteps to grass
*/
- //TimeTaker footsteptimer("footstep", g_device);
- // 0ms
- v3f playerpos = player->getPosition();
// Get node that is at BS/4 under player
v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0));
try{
catch(InvalidPositionException &e)
{
}
- //footsteptimer.stop();
}
}
while(dtime > 0.001);
\r
\r
#include "guiPauseMenu.h"\r
+#include "debug.h"\r
\r
-void guiPauseMenu::scaleGui() // this function scales gui from the size stored in file to screen size\r
+GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,\r
+ gui::IGUIElement* parent, s32 id,\r
+ IrrlichtDevice *dev):\r
+ IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,\r
+ core::rect<s32>(0,0,100,100))\r
+{\r
+ m_dev = dev;\r
+ m_screensize_old = v2u32(0,0);\r
+ \r
+ resizeGui();\r
+\r
+ setVisible(false);\r
+}\r
+\r
+GUIPauseMenu::~GUIPauseMenu()\r
+{\r
+}\r
+\r
+void GUIPauseMenu::resizeGui()\r
+{\r
+ video::IVideoDriver* driver = Environment->getVideoDriver();\r
+ v2u32 screensize = driver->getScreenSize();\r
+ if(screensize == m_screensize_old)\r
+ return;\r
+ m_screensize_old = screensize;\r
+\r
+ {\r
+ gui::IGUIElement *e = getElementFromId(256);\r
+ if(e != NULL)\r
+ e->remove();\r
+ }\r
+ {\r
+ gui::IGUIElement *e = getElementFromId(257);\r
+ if(e != NULL)\r
+ e->remove();\r
+ }\r
+\r
+ core::rect<s32> rect(\r
+ screensize.X/2 - 560/2,\r
+ screensize.Y/2 - 300/2,\r
+ screensize.X/2 + 560/2,\r
+ screensize.Y/2 + 300/2\r
+ );\r
+ \r
+ DesiredRect = rect;\r
+ recalculateAbsolutePosition(false);\r
+\r
+ v2s32 size = rect.getSize();\r
+\r
+ {\r
+ core::rect<s32> rect(0, 0, 140, 30);\r
+ rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2-25);\r
+ Environment->addButton(rect, this, 256, L"Continue");\r
+ }\r
+ {\r
+ core::rect<s32> rect(0, 0, 140, 30);\r
+ rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);\r
+ Environment->addButton(rect, this, 257, L"Exit");\r
+ }\r
+}\r
+\r
+void GUIPauseMenu::draw()\r
+{\r
+ if(!IsVisible)\r
+ return;\r
+ \r
+ gui::IGUISkin* skin = Environment->getSkin();\r
+ if (!skin)\r
+ return;\r
+ video::IVideoDriver* driver = Environment->getVideoDriver();\r
+ \r
+ video::SColor bgcolor(140,0,0,0);\r
+ driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);\r
+\r
+ gui::IGUIElement::draw();\r
+}\r
+\r
+bool GUIPauseMenu::OnEvent(const SEvent& event)\r
+{\r
+ if(event.EventType==EET_KEY_INPUT_EVENT)\r
+ {\r
+ if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)\r
+ {\r
+ setVisible(false);\r
+ return true;\r
+ }\r
+ }\r
+ if(event.EventType==EET_GUI_EVENT)\r
+ {\r
+ if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST\r
+ && isVisible())\r
+ {\r
+ if(!canTakeFocus(event.GUIEvent.Element))\r
+ {\r
+ dstream<<"GUIPauseMenu: Not allowing focus change."\r
+ <<std::endl;\r
+ // Returning true disables focus change\r
+ return true;\r
+ }\r
+ }\r
+ if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)\r
+ {\r
+ switch(event.GUIEvent.Caller->getID())\r
+ {\r
+ case 256: // continue\r
+ setVisible(false);\r
+ break;\r
+ case 257: // exit\r
+ m_dev->closeDevice();\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ return Parent ? Parent->OnEvent(event) : false;\r
+}\r
+\r
+#if 0\r
+GUIPauseMenu::GUIPauseMenu(IrrlichtDevice *device, IEventReceiver *recv):\r
+ dev(device),\r
+ oldRecv(recv)\r
+{\r
+ if(!dev)\r
+ return;\r
+ guienv=dev->getGUIEnvironment();\r
+\r
+ if (!loadMenu())\r
+ return;\r
+\r
+ device->setEventReceiver(this); // now WE are the input receiver! ahhaha! \r
+}\r
+\r
+GUIPauseMenu::~GUIPauseMenu(void)\r
+{\r
+}\r
+\r
+void GUIPauseMenu::scaleGui() // this function scales gui from the size stored in file to screen size\r
{\r
core::dimension2du screen=dev->getVideoDriver()->getScreenSize();\r
core::vector2di real=root->getAbsolutePosition().LowerRightCorner; // determine gui size stored in file (which is size of my menu root node)\r
float factorY=(float)screen.Height/(float)real.Y;\r
scaleGui(guienv->getRootGUIElement(),factorX,factorY);\r
}\r
-void guiPauseMenu::scaleGui(gui::IGUIElement *node,float factorX,float factorY) // recursive set scale\r
+void GUIPauseMenu::scaleGui(gui::IGUIElement *node,float factorX,float factorY) // recursive set scale\r
{\r
if((node->getParent() && node->getParent()->getID()==255) || node->getID()==255) // modify only menu's elements\r
{\r
scaleGui((*it),factorX,factorY);\r
}\r
\r
-bool guiPauseMenu::loadMenu()\r
+bool GUIPauseMenu::loadMenu()\r
{\r
guienv->loadGUI("../data/pauseMenu.gui");\r
\r
return true;\r
}\r
\r
-guiPauseMenu::guiPauseMenu(IrrlichtDevice *device, IEventReceiver *recv) : dev(device), oldRecv(recv)\r
-{\r
- if(!dev)\r
- return;\r
- guienv=dev->getGUIEnvironment();\r
-\r
- if (!loadMenu())\r
- return;\r
-\r
- device->setEventReceiver(this); // now WE are the input receiver! ahhaha! \r
-}\r
-\r
-bool guiPauseMenu::OnEvent(const SEvent& event)\r
+bool GUIPauseMenu::OnEvent(const SEvent& event)\r
{\r
if(!dev->isWindowFocused())\r
setVisible(true);\r
\r
return false;\r
}\r
+#endif\r
\r
-guiPauseMenu::~guiPauseMenu(void)\r
-{\r
-}\r
#ifndef GUIPAUSEMENU_HEADER\r
#define GUIPAUSEMENU_HEADER\r
\r
-#include <irrlicht.h>\r
-using namespace irr;\r
+#include "common_irrlicht.h"\r
\r
-class guiPauseMenu : public IEventReceiver\r
+class GUIPauseMenu : public gui::IGUIElement\r
{\r
-private:\r
- IrrlichtDevice *dev;\r
- gui::IGUIEnvironment *guienv;\r
- IEventReceiver *oldRecv;\r
+public:\r
+ GUIPauseMenu(gui::IGUIEnvironment* env,\r
+ gui::IGUIElement* parent, s32 id,\r
+ IrrlichtDevice *dev);\r
+ ~GUIPauseMenu();\r
+ \r
+ /*\r
+ Remove and re-add (or reposition) stuff\r
+ */\r
+ void resizeGui();\r
\r
- gui::IGUIStaticText *root;\r
+ void draw();\r
\r
- bool loadMenu();\r
- void scaleGui();\r
- void scaleGui(gui::IGUIElement *node,float factorX,float factorY);\r
+ void launch()\r
+ {\r
+ setVisible(true);\r
+ Environment->setFocus(this);\r
+ }\r
+\r
+ bool canTakeFocus(gui::IGUIElement *e)\r
+ {\r
+ return (e && (e == this || isMyChild(e)));\r
+ }\r
+\r
+ bool OnEvent(const SEvent& event);\r
+ \r
+private:\r
+ IrrlichtDevice *m_dev;\r
+ v2u32 m_screensize_old;\r
+};\r
+\r
+/*class GUIPauseMenu : public IEventReceiver\r
+{\r
public:\r
- guiPauseMenu(IrrlichtDevice *device,IEventReceiver *recv);\r
+ void scaleGui();\r
+\r
+ GUIPauseMenu(IrrlichtDevice *device,IEventReceiver *recv);\r
+ ~GUIPauseMenu(void);\r
\r
void setVisible(bool visible){root->setVisible(visible);};\r
bool isVisible(){return root->isVisible();};\r
\r
bool OnEvent(const SEvent& event);\r
\r
- ~guiPauseMenu(void);\r
-};\r
+private:\r
+ bool loadMenu();\r
+ void scaleGui(gui::IGUIElement *node,float factorX,float factorY);\r
+\r
+ IrrlichtDevice *dev;\r
+ gui::IGUIEnvironment *guienv;\r
+ IEventReceiver *oldRecv;\r
+\r
+ gui::IGUIStaticText *root;\r
+};*/\r
\r
#endif\r
\r
std::string m_inventorystring;
};
-//SUGGESTION: Split into ClientInventory and ServerInventory
class Inventory
{
public:
TODO: TOSERVER_LEAVE\r
\r
TODO: Better handling of objects and mobs\r
- - Update brightness according to day-night blended light of node\r
- in position\r
- Scripting?\r
+ - There has to be some way to do it with less spaghetti code\r
+ - Make separate classes for client and server\r
+ - Client should not discriminate between blocks, server should\r
+ - Make other players utilize the same framework\r
+\r
+SUGG: Split Inventory into ClientInventory and ServerInventory\r
\r
Doing now:\r
======================================================================\r
\r
-TODO: Get rid of g_irrlicht for server build\r
-\r
-TODO: Implement getGlobalTime for server build\r
- - It is needed for controlling the time used for flowing water\r
\r
======================================================================\r
\r
//#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")\r
#endif\r
\r
-#ifdef _WIN32\r
- #define WIN32_LEAN_AND_MEAN\r
- #include <windows.h>\r
- #define sleep_ms(x) Sleep(x)\r
-#else\r
- #include <unistd.h>\r
- #define sleep_ms(x) usleep(x*1000)\r
-#endif\r
-\r
#include <iostream>\r
#include <fstream>\r
#include <jmutexautolock.h>\r
#include "guiPauseMenu.h"\r
#include "irrlichtwrapper.h"\r
#include "gettime.h"\r
+#include "porting.h"\r
+#include "guiInventoryMenu.h"\r
\r
IrrlichtWrapper *g_irrlicht;\r
\r
//u16 g_selected_material = 0;\r
u16 g_selected_item = 0;\r
\r
-bool g_esc_pressed = false;\r
+gui::IGUIEnvironment* guienv = NULL;\r
+GUIPauseMenu *pauseMenu = NULL;\r
+GUIInventoryMenu *inventoryMenu = NULL;\r
\r
std::wstring g_text_buffer;\r
bool g_text_buffer_accepted = false;\r
}\r
}\r
\r
- if(event.KeyInput.Key == irr::KEY_ESCAPE)\r
+ if(pauseMenu != NULL)\r
{\r
- //TODO: Not used anymore?\r
- if(g_game_focused == true)\r
+ if(event.KeyInput.Key == irr::KEY_ESCAPE)\r
{\r
- dstream<<DTIME<<"ESC pressed"<<std::endl;\r
- g_esc_pressed = true;\r
+ if(g_game_focused == true\r
+ && !pauseMenu->isVisible()\r
+ && !inventoryMenu->isVisible())\r
+ {\r
+ dstream<<DTIME<<"MyEventReceiver: "\r
+ <<"Launching pause menu"<<std::endl;\r
+ pauseMenu->launch();\r
+ return true;\r
+ }\r
+ }\r
+ }\r
+\r
+ if(inventoryMenu != NULL)\r
+ {\r
+ if(event.KeyInput.Key == irr::KEY_KEY_I)\r
+ {\r
+ if(g_game_focused == true\r
+ && !inventoryMenu->isVisible()\r
+ && !pauseMenu->isVisible())\r
+ {\r
+ dstream<<DTIME<<"MyEventReceiver: "\r
+ <<"Launching inventory"<<std::endl;\r
+ inventoryMenu->launch();\r
+ return true;\r
+ }\r
}\r
}\r
\r
\r
if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)\r
{\r
+ //dstream<<"MyEventReceiver: mouse input"<<std::endl;\r
left_active = event.MouseInput.isLeftPressed();\r
middle_active = event.MouseInput.isMiddlePressed();\r
right_active = event.MouseInput.isRightPressed();\r
<<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl\r
<<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl\r
<<" \\/ \\/ \\/ \\/ \\/ "<<std::endl\r
- <<std::endl\r
- <<"Now with more waterish water!"\r
<<std::endl;\r
\r
std::cout<<std::endl;\r
\r
scene::ISceneManager* smgr = device->getSceneManager();\r
\r
- // Pause menu\r
- guiPauseMenu pauseMenu(device, &receiver);\r
-\r
- gui::IGUIEnvironment* guienv = device->getGUIEnvironment();\r
+ guienv = device->getGUIEnvironment();\r
gui::IGUISkin* skin = guienv->getSkin();\r
gui::IGUIFont* font = guienv->getFont("../data/fontlucida.png");\r
if(font)\r
\r
gui_loadingtext->remove();\r
\r
- pauseMenu.setVisible(true);\r
-\r
/*\r
Add some gui stuff\r
*/\r
\r
+ // This is a copy of the inventory that the client's environment has\r
+ Inventory local_inventory(PLAYER_INVENTORY_SIZE);\r
+ \r
+ GUIQuickInventory *quick_inventory = new GUIQuickInventory\r
+ (guienv, NULL, v2s32(10, 70), 5, &local_inventory);\r
+ \r
+ /*\r
+ We need some kind of a root node to be able to add\r
+ custom elements directly on the screen.\r
+ Otherwise they won't be automatically drawn.\r
+ */\r
+ gui::IGUIStaticText *root = guienv->addStaticText(L"",\r
+ core::rect<s32>(0, 0, 10000, 10000));\r
+ \r
+ // Pause menu\r
+ pauseMenu = new GUIPauseMenu(guienv, root, -1, device);\r
+ \r
+ // Inventory menu\r
+ inventoryMenu = new GUIInventoryMenu(guienv, root, -1, &local_inventory);\r
+\r
+ pauseMenu->launch();\r
+ //inventoryMenu->launch();\r
+\r
// First line of debug text\r
gui::IGUIStaticText *guitext = guienv->addStaticText(\r
L"Minetest-c55",\r
core::rect<s32>(100, 70, 100+400, 70+(textsize.Y+5)),\r
false, false);\r
\r
- // This is a copy of the inventory that the client's environment has\r
- Inventory local_inventory(PLAYER_INVENTORY_SIZE);\r
- \r
- GUIQuickInventory *quick_inventory = new GUIQuickInventory\r
- (guienv, NULL, v2s32(10, 70), 5, &local_inventory);\r
- \r
/*\r
Some statistics are collected in these\r
*/\r
//gui::IGUIWindow* input_window = NULL;\r
gui::IGUIStaticText* input_guitext = NULL;\r
\r
- /*\r
- Digging animation\r
- */\r
- //f32 \r
-\r
/*\r
Main loop\r
*/\r
*/\r
v2u32 screensize = driver->getScreenSize();\r
core::vector2d<s32> displaycenter(screensize.X/2,screensize.Y/2);\r
+ \r
+ pauseMenu->resizeGui();\r
+ inventoryMenu->resizeGui();\r
\r
// Hilight boxes collected during the loop and displayed\r
core::list< core::aabbox3d<f32> > hilightboxes;\r
{\r
break;\r
}*/\r
+ /*if(g_i_pressed)\r
+ {\r
+ inventoryMenu->setVisible(true);\r
+ g_i_pressed = false;\r
+ }*/\r
\r
/*\r
Player speed control\r
Mouse and camera control\r
*/\r
\r
- if((device->isWindowActive() && g_game_focused && !pauseMenu.isVisible())\r
+ if((device->isWindowActive()\r
+ && g_game_focused\r
+ && !pauseMenu->isVisible()\r
+ && !inventoryMenu->isVisible()\r
+ )\r
|| random_input)\r
{\r
if(!random_input)\r
client.getLocalInventory(local_inventory);\r
quick_inventory->setSelection(g_selected_item);\r
quick_inventory->update();\r
+ inventoryMenu->update();\r
}\r
\r
if(input_guitext != NULL)\r
#include "filesys.h"
#include "utility.h"
#include "voxel.h"
-
-#ifdef _WIN32
- #include <windows.h>
- #define sleep_ms(x) Sleep(x)
-#else
- #include <unistd.h>
- #define sleep_ms(x) usleep(x*1000)
-#endif
+#include "porting.h"
MapBlockPointerCache::MapBlockPointerCache(Map *map)
{
buf->getMaterial().setTexture
(0, driver->getTexture("../data/rat.png"));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
// Add to mesh
mesh->addMeshBuffer(buf);
}
#endif
+#ifndef SERVER
+/*
+ PlayerObject
+*/
+void PlayerObject::addToScene(scene::ISceneManager *smgr)
+{
+ if(m_node != NULL)
+ return;
+
+ video::IVideoDriver* driver = smgr->getVideoDriver();
+
+ // Attach a simple mesh to the player for showing an image
+ scene::SMesh *mesh = new scene::SMesh();
+ { // Front
+ scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+ video::SColor c(255,255,255,255);
+ video::S3DVertex vertices[4] =
+ {
+ video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
+ video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
+ video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
+ video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
+ };
+ u16 indices[] = {0,1,2,2,3,0};
+ buf->append(vertices, 4, indices, 6);
+ // Set material
+ buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+ //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
+ buf->getMaterial().setTexture(0, driver->getTexture("../data/player.png"));
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
+ //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+ buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ // Add to mesh
+ mesh->addMeshBuffer(buf);
+ buf->drop();
+ }
+ { // Back
+ scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+ video::SColor c(255,255,255,255);
+ video::S3DVertex vertices[4] =
+ {
+ video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
+ video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
+ video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
+ video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
+ };
+ u16 indices[] = {0,1,2,2,3,0};
+ buf->append(vertices, 4, indices, 6);
+ // Set material
+ buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+ //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
+ buf->getMaterial().setTexture(0, driver->getTexture("../data/player_back.png"));
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
+ buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ // Add to mesh
+ mesh->addMeshBuffer(buf);
+ buf->drop();
+ }
+
+ m_node = smgr->addMeshSceneNode(mesh, NULL);
+ mesh->drop();
+ updateNodePos();
+}
+#endif
+
/*
MapBlockObjectList
*/
#include "constants.h"
#include "debug.h"
-#define MAPBLOCKOBJECT_TYPE_TEST 0
-#define MAPBLOCKOBJECT_TYPE_TEST2 1
+#define MAPBLOCKOBJECT_TYPE_PLAYER 0
#define MAPBLOCKOBJECT_TYPE_SIGN 2
#define MAPBLOCKOBJECT_TYPE_RAT 3
// Used for handling selecting special stuff
buf->getMaterial().setTexture
(0, driver->getTexture("../data/sign.png"));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
// Add to mesh
mesh->addMeshBuffer(buf);
buf->getMaterial().setTexture
(0, driver->getTexture("../data/sign_back.png"));
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
// Add to mesh
mesh->addMeshBuffer(buf);
float m_counter1;
float m_counter2;
- v3f m_oldpos;
float m_age;
};
+/*
+ NOTE: Not used.
+*/
+class PlayerObject : public MovingObject
+{
+public:
+ PlayerObject(MapBlock *block, s16 id, v3f pos):
+ MovingObject(block, id, pos),
+ m_node(NULL)
+ {
+ m_collision_box = new core::aabbox3d<f32>
+ (-BS*0.3,-BS*.25,-BS*0.3, BS*0.3,BS*0.25,BS*0.3);
+ /*m_selection_box = new core::aabbox3d<f32>
+ (-BS*0.3,-BS*.25,-BS*0.3, BS*0.3,BS*0.25,BS*0.3);*/
+ }
+ virtual ~PlayerObject()
+ {
+ if(m_collision_box)
+ delete m_collision_box;
+ if(m_selection_box)
+ delete m_selection_box;
+ }
+
+ /*
+ Implementation interface
+ */
+ virtual u16 getTypeId() const
+ {
+ return MAPBLOCKOBJECT_TYPE_PLAYER;
+ }
+ virtual void serialize(std::ostream &os, u8 version)
+ {
+ // Object data is generated from actual player
+ }
+ virtual void update(std::istream &is, u8 version)
+ {
+ MovingObject::update(is, version);
+ u8 buf[2];
+
+ // Read yaw * 10
+ is.read((char*)buf, 2);
+ s16 yaw_i = readS16(buf);
+ m_yaw = (f32)yaw_i / 10;
+
+ updateNodePos();
+ }
+
+ virtual bool serverStep(float dtime, u32 daynight_ratio)
+ {
+ // Player is handled elsewhere.
+ // Die.
+ //return true;
+ // Actually, fail very loudly:
+ assert(0);
+ }
+
+#ifndef SERVER
+ virtual void clientStep(float dtime)
+ {
+ MovingObject::simpleMove(dtime);
+
+ updateNodePos();
+ }
+
+ virtual void addToScene(scene::ISceneManager *smgr);
+
+ virtual void removeFromScene()
+ {
+ if(m_node == NULL)
+ return;
+
+ m_node->remove();
+ m_node = NULL;
+ }
+
+ virtual void updateLight(u8 light_at_pos)
+ {
+ if(m_node == NULL)
+ return;
+
+ u8 li = decode_light(light_at_pos);
+ video::SColor color(255,li,li,li);
+
+ scene::IMesh *mesh = m_node->getMesh();
+
+ u16 mc = mesh->getMeshBufferCount();
+ for(u16 j=0; j<mc; j++)
+ {
+ scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
+ video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
+ u16 vc = buf->getVertexCount();
+ for(u16 i=0; i<vc; i++)
+ {
+ vertices[i].Color = color;
+ }
+ }
+ }
+
+#endif
+
+ /*
+ Special methods
+ */
+
+ void updateNodePos()
+ {
+ if(m_node == NULL)
+ return;
+
+ m_node->setPosition(getAbsoluteShowPos());
+ m_node->setRotation(v3f(0, -m_yaw+180, 0));
+ }
+
+protected:
+ scene::IMeshSceneNode *m_node;
+ float m_yaw;
+
+ v3f m_oldpos;
+};
+
struct DistanceSortedObject
{
DistanceSortedObject(MapBlockObject *a_obj, f32 a_d)
{
}
-void Player::move(f32 dtime, Map &map)
+// Y direction is ignored
+void Player::accelerate(v3f target_speed, f32 max_increase)
+{
+ if(m_speed.X < target_speed.X - max_increase)
+ m_speed.X += max_increase;
+ else if(m_speed.X > target_speed.X + max_increase)
+ m_speed.X -= max_increase;
+ else if(m_speed.X < target_speed.X)
+ m_speed.X = target_speed.X;
+ else if(m_speed.X > target_speed.X)
+ m_speed.X = target_speed.X;
+
+ if(m_speed.Z < target_speed.Z - max_increase)
+ m_speed.Z += max_increase;
+ else if(m_speed.Z > target_speed.Z + max_increase)
+ m_speed.Z -= max_increase;
+ else if(m_speed.Z < target_speed.Z)
+ m_speed.Z = target_speed.Z;
+ else if(m_speed.Z > target_speed.Z)
+ m_speed.Z = target_speed.Z;
+}
+
+/*
+ RemotePlayer
+*/
+
+#ifndef SERVER
+
+RemotePlayer::RemotePlayer(
+ scene::ISceneNode* parent,
+ IrrlichtDevice *device,
+ s32 id):
+ scene::ISceneNode(parent, (device==NULL)?NULL:device->getSceneManager(), id),
+ m_text(NULL)
+{
+ m_box = core::aabbox3d<f32>(-BS/2,0,-BS/2,BS/2,BS*2,BS/2);
+
+ if(parent != NULL && device != NULL)
+ {
+ // ISceneNode stores a member called SceneManager
+ scene::ISceneManager* mgr = SceneManager;
+ video::IVideoDriver* driver = mgr->getVideoDriver();
+ gui::IGUIEnvironment* gui = device->getGUIEnvironment();
+
+ // Add a text node for showing the name
+ wchar_t wname[1] = {0};
+ m_text = mgr->addTextSceneNode(gui->getBuiltInFont(),
+ wname, video::SColor(255,255,255,255), this);
+ m_text->setPosition(v3f(0, (f32)BS*2.1, 0));
+
+ // Attach a simple mesh to the player for showing an image
+ scene::SMesh *mesh = new scene::SMesh();
+ { // Front
+ scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+ video::SColor c(255,255,255,255);
+ video::S3DVertex vertices[4] =
+ {
+ video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
+ video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
+ video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
+ video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
+ };
+ u16 indices[] = {0,1,2,2,3,0};
+ buf->append(vertices, 4, indices, 6);
+ // Set material
+ buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+ //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
+ buf->getMaterial().setTexture(0, driver->getTexture("../data/player.png"));
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+ buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ // Add to mesh
+ mesh->addMeshBuffer(buf);
+ buf->drop();
+ }
+ { // Back
+ scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+ video::SColor c(255,255,255,255);
+ video::S3DVertex vertices[4] =
+ {
+ video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
+ video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
+ video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
+ video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
+ };
+ u16 indices[] = {0,1,2,2,3,0};
+ buf->append(vertices, 4, indices, 6);
+ // Set material
+ buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+ //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
+ buf->getMaterial().setTexture(0, driver->getTexture("../data/player_back.png"));
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ // Add to mesh
+ mesh->addMeshBuffer(buf);
+ buf->drop();
+ }
+ m_node = mgr->addMeshSceneNode(mesh, this);
+ mesh->drop();
+ m_node->setPosition(v3f(0,0,0));
+ }
+}
+
+RemotePlayer::~RemotePlayer()
+{
+ if(SceneManager != NULL)
+ ISceneNode::remove();
+}
+
+void RemotePlayer::updateName(const char *name)
+{
+ Player::updateName(name);
+ if(m_text != NULL)
+ {
+ wchar_t wname[PLAYERNAME_SIZE];
+ mbstowcs(wname, m_name, strlen(m_name)+1);
+ m_text->setText(wname);
+ }
+}
+
+void RemotePlayer::move(f32 dtime, Map &map)
+{
+ m_pos_animation_time_counter += dtime;
+ m_pos_animation_counter += dtime;
+ v3f movevector = m_position - m_oldpos;
+ f32 moveratio;
+ if(m_pos_animation_time < 0.001)
+ moveratio = 1.0;
+ else
+ moveratio = m_pos_animation_counter / m_pos_animation_time;
+ if(moveratio > 1.5)
+ moveratio = 1.5;
+ m_showpos = m_oldpos + movevector * moveratio;
+
+ ISceneNode::setPosition(m_showpos);
+}
+
+#endif
+
+#ifndef SERVER
+/*
+ LocalPlayer
+*/
+
+LocalPlayer::LocalPlayer()
+{
+}
+
+LocalPlayer::~LocalPlayer()
+{
+}
+
+void LocalPlayer::move(f32 dtime, Map &map)
{
v3f position = getPosition();
v3f oldpos = position;
setPosition(position);
}
-// Y direction is ignored
-void Player::accelerate(v3f target_speed, f32 max_increase)
-{
- if(m_speed.X < target_speed.X - max_increase)
- m_speed.X += max_increase;
- else if(m_speed.X > target_speed.X + max_increase)
- m_speed.X -= max_increase;
- else if(m_speed.X < target_speed.X)
- m_speed.X = target_speed.X;
- else if(m_speed.X > target_speed.X)
- m_speed.X = target_speed.X;
-
- if(m_speed.Z < target_speed.Z - max_increase)
- m_speed.Z += max_increase;
- else if(m_speed.Z > target_speed.Z + max_increase)
- m_speed.Z -= max_increase;
- else if(m_speed.Z < target_speed.Z)
- m_speed.Z = target_speed.Z;
- else if(m_speed.Z > target_speed.Z)
- m_speed.Z = target_speed.Z;
-}
-
-/*
- RemotePlayer
-*/
-
-#ifndef SERVER
-
-RemotePlayer::RemotePlayer(
- scene::ISceneNode* parent,
- IrrlichtDevice *device,
- s32 id):
- scene::ISceneNode(parent, (device==NULL)?NULL:device->getSceneManager(), id),
- m_text(NULL)
-{
- m_box = core::aabbox3d<f32>(-BS/2,0,-BS/2,BS/2,BS*2,BS/2);
-
- if(parent != NULL && device != NULL)
- {
- // ISceneNode stores a member called SceneManager
- scene::ISceneManager* mgr = SceneManager;
- video::IVideoDriver* driver = mgr->getVideoDriver();
- gui::IGUIEnvironment* gui = device->getGUIEnvironment();
-
- // Add a text node for showing the name
- wchar_t wname[1] = {0};
- m_text = mgr->addTextSceneNode(gui->getBuiltInFont(),
- wname, video::SColor(255,255,255,255), this);
- m_text->setPosition(v3f(0, (f32)BS*2.1, 0));
-
- // Attach a simple mesh to the player for showing an image
- scene::SMesh *mesh = new scene::SMesh();
- { // Front
- scene::IMeshBuffer *buf = new scene::SMeshBuffer();
- video::SColor c(255,255,255,255);
- video::S3DVertex vertices[4] =
- {
- video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
- video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
- video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
- video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
- };
- u16 indices[] = {0,1,2,2,3,0};
- buf->append(vertices, 4, indices, 6);
- // Set material
- buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
- //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
- buf->getMaterial().setTexture(0, driver->getTexture("../data/player.png"));
- buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
- //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
- buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
- // Add to mesh
- mesh->addMeshBuffer(buf);
- buf->drop();
- }
- { // Back
- scene::IMeshBuffer *buf = new scene::SMeshBuffer();
- video::SColor c(255,255,255,255);
- video::S3DVertex vertices[4] =
- {
- video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
- video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
- video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
- video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
- };
- u16 indices[] = {0,1,2,2,3,0};
- buf->append(vertices, 4, indices, 6);
- // Set material
- buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
- //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
- buf->getMaterial().setTexture(0, driver->getTexture("../data/player_back.png"));
- buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
- buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
- // Add to mesh
- mesh->addMeshBuffer(buf);
- buf->drop();
- }
- scene::IMeshSceneNode *node = mgr->addMeshSceneNode(mesh, this);
- mesh->drop();
- node->setPosition(v3f(0,0,0));
- }
-}
-
-RemotePlayer::~RemotePlayer()
-{
- if(SceneManager != NULL)
- ISceneNode::remove();
-}
-
-void RemotePlayer::updateName(const char *name)
-{
- Player::updateName(name);
- if(m_text != NULL)
- {
- wchar_t wname[PLAYERNAME_SIZE];
- mbstowcs(wname, m_name, strlen(m_name)+1);
- m_text->setText(wname);
- }
-}
-
-#endif
-
-#ifndef SERVER
-/*
- LocalPlayer
-*/
-
-LocalPlayer::LocalPlayer()
-{
-}
-
-LocalPlayer::~LocalPlayer()
-{
-}
-
void LocalPlayer::applyControl(float dtime)
{
// Random constants
Player();
virtual ~Player();
- void move(f32 dtime, Map &map);
+ //void move(f32 dtime, Map &map);
+ virtual void move(f32 dtime, Map &map) = 0;
v3f getSpeed()
{
virtual bool isLocal() const = 0;
+ virtual void updateLight(u8 light_at_pos) {};
+
bool touching_ground;
bool in_water;
return false;
}
+ void move(f32 dtime, Map &map)
+ {
+ }
+
private:
};
void setPosition(v3f position)
{
+ m_oldpos = m_showpos;
+
+ if(m_pos_animation_time < 0.001 || m_pos_animation_time > 1.0)
+ m_pos_animation_time = m_pos_animation_time_counter;
+ else
+ m_pos_animation_time = m_pos_animation_time * 0.9
+ + m_pos_animation_time_counter * 0.1;
+ m_pos_animation_time_counter = 0;
+ m_pos_animation_counter = 0;
+
Player::setPosition(position);
- ISceneNode::setPosition(position);
+ //ISceneNode::setPosition(position);
}
virtual void setYaw(f32 yaw)
void updateName(const char *name);
+ virtual void updateLight(u8 light_at_pos)
+ {
+ if(m_node == NULL)
+ return;
+
+ u8 li = decode_light(light_at_pos);
+ video::SColor color(255,li,li,li);
+
+ scene::IMesh *mesh = m_node->getMesh();
+
+ u16 mc = mesh->getMeshBufferCount();
+ for(u16 j=0; j<mc; j++)
+ {
+ scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
+ video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
+ u16 vc = buf->getVertexCount();
+ for(u16 i=0; i<vc; i++)
+ {
+ vertices[i].Color = color;
+ }
+ }
+ }
+
+ void move(f32 dtime, Map &map);
+
private:
+ scene::IMeshSceneNode *m_node;
scene::ITextSceneNode* m_text;
core::aabbox3d<f32> m_box;
+
+ v3f m_oldpos;
+ f32 m_pos_animation_counter;
+ f32 m_pos_animation_time;
+ f32 m_pos_animation_time_counter;
+ v3f m_showpos;
};
#endif
return true;
}
+ void move(f32 dtime, Map &map);
+
void applyControl(float dtime);
PlayerControl control;
#include "common_irrlicht.h"
#include <string>
#include "utility.h"
-
-#ifdef _WIN32
- #include <windows.h>
- #define sleep_ms(x) Sleep(x)
-#else
- #include <unistd.h>
- #define sleep_ms(x) usleep(x*1000)
-#endif
+#include "porting.h"
struct QueuedBlockEmerge
{
<<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl
<<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl
<<" \\/ \\/ \\/ \\/ \\/ "<<std::endl
- <<std::endl
- <<"Now with more waterish water!"
<<std::endl;
std::cout<<std::endl;
#include "serialization.h"
#include "voxel.h"
#include <sstream>
-
-#ifdef _WIN32
- #include <windows.h>
- #define sleep_ms(x) Sleep(x)
-#else
- #include <unistd.h>
- #define sleep_ms(x) usleep(x*1000)
-#endif
+#include "porting.h"
/*
Asserts that the exception occurs
if(stoptime != 0)
{
u32 timenow = getTimeMs();
- if(timenow >= stoptime ||
- (stoptime < 0x80000000 && timenow > 0x80000000))
+ // Well, it is a bit hard to guess because we don't know the
+ // start time...
+ bool overflow = timenow < stoptime - 100000;
+ if(timenow >= stoptime || overflow)
{
dstream<<"flowWater: stoptime reached"<<std::endl;
throw ProcessingLimitException("flowWater stoptime reached");