From 43a28f04fa3ddf4b612f58c25a896293a01567e3 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 15 Oct 2011 02:28:57 +0300 Subject: mobv2 --- src/game.cpp | 185 ++++++++++++++++++++++------------------------------------- 1 file changed, 69 insertions(+), 116 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 9e54e6ad3..e8d0238a3 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -89,27 +89,6 @@ u16 g_selected_item = 0; Text input system */ -struct TextDestSign : public TextDest -{ - TextDestSign(v3s16 blockpos, s16 id, Client *client) - { - m_blockpos = blockpos; - m_id = id; - m_client = client; - } - void gotText(std::wstring text) - { - std::string ntext = wide_to_narrow(text); - dstream<<"Changing text of a sign object: " - <sendSignText(m_blockpos, m_id, ntext); - } - - v3s16 m_blockpos; - s16 m_id; - Client *m_client; -}; - struct TextDestChat : public TextDest { TextDestChat(Client *client) @@ -298,7 +277,7 @@ void getPointedNode(Client *client, v3f player_position, v3s16 pos_i = floatToInt(player_position, BS); - /*std::cout<<"pos_i=("< server; if(address == ""){ draw_load_screen(L"Creating server...", driver, font); - std::cout<start(port); } @@ -715,7 +694,7 @@ void the_game( */ draw_load_screen(L"Creating client...", driver, font); - std::cout<remove(); @@ -799,12 +778,12 @@ void the_game( { error_message = L"Access denied. Reason: " +client.accessDeniedReason(); - std::cout<remove(); return; @@ -924,8 +903,16 @@ void the_game( core::list frametime_log; + float nodig_delay_counter = 0.0; + float dig_time = 0.0; + u16 dig_index = 0; + v3s16 nodepos_old(-32768,-32768,-32768); + float damage_flash_timer = 0; s16 farmesh_range = 20*MAP_BLOCKSIZE; + + const float object_hit_delay = 0.5; + float object_hit_delay_timer = 0.0; bool invert_mouse = g_settings->getBool("invert_mouse"); @@ -952,7 +939,7 @@ void the_game( { error_message = L"Access denied. Reason: " +client.accessDeniedReason(); - std::cout<getMousePos().Y - displaycenter.Y; if(invert_mouse) dy = -dy; - //std::cout<<"window active, pos difference "<isKeyDown(irr::KEY_UP)) @@ -1391,7 +1382,7 @@ void the_game( if(device->getCursorControl()->isVisible() == false) device->getCursorControl()->setVisible(true); - //std::cout<<"window inactive"< shootline(camera_position, camera_position + camera_direction * BS * (d+1)); - MapBlockObject *selected_object = client.getSelectedObject - (d*BS, camera_position, shootline); - ClientActiveObject *selected_active_object = client.getSelectedActiveObject (d*BS, camera_position, shootline); + + bool left_punch = false; + bool left_punch_muted = false; - if(selected_object != NULL) + if(selected_active_object != NULL) { - //dstream<<"Client returned selected_object != NULL"< box_on_map - = selected_object->getSelectionBoxOnMap(); - - hilightboxes.push_back(box_on_map); - - infotext = narrow_to_wide(selected_object->infoText()); - - if(input->getLeftClicked()) + /* Clear possible cracking animation */ + if(nodepos_old != v3s16(-32768,-32768,-32768)) { - std::cout<getBlock()->getPos(), - selected_object->getId(), g_selected_item); + client.clearTempMod(nodepos_old); + dig_time = 0.0; + nodepos_old = v3s16(-32768,-32768,-32768); } - else if(input->getRightClicked()) - { - std::cout<getTypeId() == MAPBLOCKOBJECT_TYPE_SIGN) - { - dstream<<"Sign object right-clicked"<getBlock()->getPos(), - selected_object->getId(), - &client); - SignObject *sign_object = (SignObject*)selected_object; - - std::wstring wtext = - narrow_to_wide(sign_object->getText()); - - (new GUITextInputMenu(guienv, guiroot, -1, - &g_menumgr, dest, - wtext))->drop(); - } - } - /* - Otherwise pass the event to the server as-is - */ - else - { - client.clickObject(1, selected_object->getBlock()->getPos(), - selected_object->getId(), g_selected_item); - } - } - } - else if(selected_active_object != NULL) - { //dstream<<"Client returned selected_active_object != NULL"< *selection_box @@ -1579,21 +1522,31 @@ void the_game( selection_box->MinEdge + pos, selection_box->MaxEdge + pos ); - - hilightboxes.push_back(box_on_map); + + if(selected_active_object->doShowSelectionBox()) + hilightboxes.push_back(box_on_map); //infotext = narrow_to_wide("A ClientActiveObject"); infotext = narrow_to_wide(selected_active_object->infoText()); - if(input->getLeftClicked()) + //if(input->getLeftClicked()) + if(input->getLeftState()) { - std::cout<getId(), g_selected_item); + if(object_hit_delay_timer <= 0.0){ + dstream<getId(), g_selected_item); + object_hit_delay_timer = object_hit_delay; + left_punch = true; + } else { + dstream<getRightClicked()) { - std::cout<getId(), g_selected_item); } @@ -1616,15 +1569,14 @@ void the_game( nodepos, neighbourpos, nodehilightbox, d); - static float nodig_delay_counter = 0.0; - - if(nodefound) - { - static v3s16 nodepos_old(-32768,-32768,-32768); - - static float dig_time = 0.0; - static u16 dig_index = 0; - + if(!nodefound){ + if(nodepos_old != v3s16(-32768,-32768,-32768)) + { + client.clearTempMod(nodepos_old); + dig_time = 0.0; + nodepos_old = v3s16(-32768,-32768,-32768); + } + } else { /* Visualize selection */ @@ -1661,13 +1613,14 @@ void the_game( { if(nodepos != nodepos_old) { - std::cout<getRightClicked()) { - std::cout<getInventoryDrawSpecString() != "" && !random_input) @@ -1836,7 +1789,7 @@ void the_game( } // selected_object == NULL - if(input->getLeftClicked()) + if(left_punch || (input->getLeftClicked() && !left_punch_muted)) { camera.setDigging(0); // left click animation } @@ -1846,13 +1799,13 @@ void the_game( if(input->getLeftReleased()) { - std::cout<getRightReleased()) { - //std::cout<drawAll()"<drawAll()"< >::Iterator i=hilightboxes.begin(); i != hilightboxes.end(); i++) { - /*std::cout<<"hilightbox min=" + /*dstream<<"hilightbox min=" <<"("<MinEdge.X<<","<MinEdge.Y<<","<MinEdge.Z<<")" <<" max=" <<"("<MaxEdge.X<<","<MaxEdge.Y<<","<MaxEdge.Z<<")" -- cgit v1.2.3