From 07badfb40024fe376fab6fe1cbe7138d1df3ed4b Mon Sep 17 00:00:00 2001 From: Null Date: Sat, 24 Oct 2015 12:24:31 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8C=BA=E5=9D=97=E5=88=97=E8=A1=A8"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f731106986ee22c9f0edf5cf89cee880de040007. --- source/Chunk.cpp | 22 ++-- source/Chunk.h | 4 +- source/Definitions.h | 5 +- source/NEWorld.cpp | 245 ++++++++++++++++++------------------------- source/Particles.h | 3 +- source/Player.cpp | 22 +--- source/Player.h | 13 ++- source/Renderer.cpp | 8 +- source/Renderer.h | 11 +- source/Textures.cpp | 2 +- source/World.cpp | 68 ++++++------ source/World.h | 35 ++----- source/stdinclude.h | 5 +- 13 files changed, 176 insertions(+), 267 deletions(-) diff --git a/source/Chunk.cpp b/source/Chunk.cpp index b10895c..f7d46bd 100644 --- a/source/Chunk.cpp +++ b/source/Chunk.cpp @@ -31,8 +31,8 @@ namespace world{ delete[] pbrightness; pblocks = nullptr; pbrightness = nullptr; - //updated = false; - unloadedChunksCounter++; + updated = false; + unloadedChunks++; } void chunk::build(){ @@ -104,8 +104,7 @@ namespace world{ build(); #endif if (Empty)destroy(); - //else updated = true; - else world::setChunkUpdated(cx, cy, cz); + else updated = true; } void chunk::Unload(){ @@ -133,8 +132,8 @@ namespace world{ file.close(); } - bool chunk::buildRender(){ - if (Empty) return false; + void chunk::buildRender(){ + if (Empty) return; #ifdef NEWORLD_DEBUG_CONSOLE_OUTPUT if (pblocks == nullptr || pbrightness == nullptr){ DebugWarning("Empty pointer when building vertex buffers!"); @@ -147,14 +146,14 @@ namespace world{ for (y = -1; y <= 1; y++) { for (z = -1; z <= 1; z++) { if (x == 0 && y == 0 && z == 0) continue; - if (chunkOutOfBound(cx + x, cy + y, cz + z)) continue; - if (!chunkLoaded(cx + x, cy + y, cz + z)) return false; + if (chunkOutOfBound(cx + x, cy + y, cz + z)) continue; + if (!chunkLoaded(cx + x, cy + y, cz + z)) return; } } } - //rebuiltChunksCounter++; - updatedChunksCounter++; + rebuiltChunks++; + updatedChunks++; if (renderBuilt == false){ renderBuilt = true; @@ -196,9 +195,8 @@ namespace world{ } } renderer::Flush(vbuffer[2], vertexes[2]); - //updated = false; + updated = false; - return true; } void chunk::destroyRender(){ diff --git a/source/Chunk.h b/source/Chunk.h index 7efcaae..61d74d1 100644 --- a/source/Chunk.h +++ b/source/Chunk.h @@ -8,7 +8,7 @@ namespace world{ extern string worldname; extern brightness BRIGHTNESSMIN; extern brightness skylight; - + class chunk{ private: @@ -46,7 +46,7 @@ namespace world{ } void LoadFromFile(); void SaveToFile(); - bool buildRender(); + void buildRender(); void destroyRender(); inline block getblock(int x, int y, int z) { diff --git a/source/Definitions.h b/source/Definitions.h index bfc5e53..5cfc2f8 100644 --- a/source/Definitions.h +++ b/source/Definitions.h @@ -6,13 +6,12 @@ /* #define NEWORLD_COMPILE_DISABLE_SECURE +#ifndef nullptr #define nullptr NULL -#ifndef M_PI -#define M_PI 3.14159265898 #endif */ -//#define NEWORLD_DEBUG +#define NEWORLD_DEBUG #ifdef NEWORLD_DEBUG #define NEWORLD_DEBUG_CONSOLE_OUTPUT #define NEWORLD_DEBUG_NO_FILEIO diff --git a/source/NEWorld.cpp b/source/NEWorld.cpp index e0e4d62..34d8e77 100644 --- a/source/NEWorld.cpp +++ b/source/NEWorld.cpp @@ -1,5 +1,5 @@ -//============================== Initialize ================================// -//==============================ʼ()================================// +//============================== Initialize ================================// +//==============================初始化(包括闪屏)================================// #include "Definitions.h" @@ -80,19 +80,19 @@ bool selce; int selbx, selby, selbz, selcx, selcy, selcz; #if 0 - woca, עͶУ - (벻ȥͯЬFB汾ò - ҵIJһ⼸ע͵ɡ) + woca, 这样注释都行?! + (这儿编译不过去的童鞋,你的FB编译器版本貌似 + 和我的不一样,把这几行注释掉吧。。。) ======================================= - ȵȲ԰ijc++ˡ˵FB - C++Ӧò23333333 + 等等不对啊!!!明明都改成c++了。。。还说是FB。。。 + C++编译器应该不会在这儿报错吧23333333 #endif //============================== Main Program ================================// -//============================== ================================// +//============================== 主程序 ================================// int main(){ - //Բڽmainˣĵһ̣ + //卧槽终于进入main函数了!激动人心的一刻!!! #ifndef NEWORLD_USE_WINAPI setlocale(LC_ALL, "zh_CN.UTF-8"); @@ -140,7 +140,7 @@ int main(){ MutexLock(Mutex); updateThread = ThreadCreate(&updateThreadFunc, NULL); - //ʼϷ״̬ + //初始化游戏状态 printf("[Console][Game]"); printf("Init player...\n"); player::InitHitbox(); @@ -163,7 +163,7 @@ int main(){ printf("[Console][Game]"); printf("Game start!\n"); - //Ϸʼ! + //这才是游戏开始! glClearColor(skycolorR, skycolorG, skycolorB, 1.0); glfwSetInputMode(MainWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED); mxl = mx; myl = my; @@ -173,7 +173,7 @@ int main(){ fctime = uctime = lastupdate = timer(); do{ - //ѭ򻯳Ҳ̶ð + //主循环,被简化成这样,惨不忍睹啊! MutexUnlock(Mutex); MutexLock(Mutex); @@ -219,16 +219,16 @@ int main(){ ThreadDestroy(updateThread); MutexDestroy(Mutex); - //ɾҲûϵ _²FBglfwУ - //԰ⲻFBڵVC++ - //¥ϵ¥Ϲ˵ģ + //结束程序,删了也没关系 ←_←(吐槽FB和glfw中) + //不对啊这不是FB!!!这是正宗的VC++!!!!!! + //楼上的楼上在瞎说!!!别信他的!!! glfwTerminate(); return 0; //This is the END of the program! } ThreadFunc updateThreadFunc(void*){ - //Ϸ̺߳ + //游戏更新线程函数 //Wait until start... MutexLock(Mutex); @@ -245,7 +245,6 @@ ThreadFunc updateThreadFunc(void*){ while (updateThreadRun){ MutexUnlock(Mutex); - Sleep(1); MutexLock(Mutex); while (updateThreadPaused){ @@ -357,7 +356,7 @@ void splashscreen(){ void setupscreen() { - //OpenGL + //OpenGL参数设置 glViewport(0, 0, windowwidth, windowheight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -374,7 +373,7 @@ void setupscreen() { glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); glDepthFunc(GL_LEQUAL); - glAlphaFunc(GL_GREATER, 0.0); //<--һȣ(濴ȵĶ) + glAlphaFunc(GL_GREATER, 0.0); //<--这家伙在卖萌?(往后面看看,卖萌的多着呢) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); @@ -390,7 +389,7 @@ void setupscreen() { } void InitGL() { - //ȡOpenGL汾 + //获取OpenGL版本 GLVersionMajor = glfwGetWindowAttrib(MainWindow, GLFW_CONTEXT_VERSION_MAJOR); GLVersionMinor = glfwGetWindowAttrib(MainWindow, GLFW_CONTEXT_VERSION_MINOR); GLVersionRev = glfwGetWindowAttrib(MainWindow, GLFW_CONTEXT_REVISION); @@ -428,7 +427,7 @@ void setupNormalFog() { } void LoadTextures(){ - // + //载入纹理 Textures::Init(); guiImage[1] = Textures::LoadRGBATexture("Textures\\gui\\MainMenu.bmp", ""); @@ -472,13 +471,13 @@ void updategame(){ static double Wprstm; static bool WP; - //static double mxl, myl; + static double mxl, myl; glfwGetCursorPos(MainWindow, &mx, &my); player::BlockInHand = player::inventorybox[3][player::itemInHand]; //world::unloadedChunks=0 - //world::rebuiltChunksCount = 0; - //world::updatedChunksCount = 0; + world::rebuiltChunks = 0; + world::updatedChunks = 0; //ciArray move if (world::cpArrayAval){ @@ -494,22 +493,20 @@ void updategame(){ if (FirstUpdateThisFrame){ world::sortChunkLoadUnloadList(RoundInt(player::xpos), RoundInt(player::ypos), RoundInt(player::zpos)); - //ж(Unload chunks) + //卸载区块(Unload chunks) int sumUnload; sumUnload = world::chunkUnloads > 4 ? 4 : world::chunkUnloads; for (int i = 0; i < sumUnload; i++) { - int cx = world::chunkUnloadList[i][1]; - int cy = world::chunkUnloadList[i][2]; - int cz = world::chunkUnloadList[i][3]; - world::chunk* cp = world::getChunkPtr(cx, cy, cz); + world::chunk* cp = world::chunkUnloadList[i].first; #ifdef NEWORLD_DEBUG if (cp == nullptr)DebugError("Unload error!"); #endif + int cx = cp->cx, cy = cp->cy, cz = cp->cz; cp->Unload(); world::DeleteChunk(cx, cy, cz); } - //(Load chunks) + //加载区块(Load chunks) int sumLoad; sumLoad = world::chunkLoads > 4 ? 4 : world::chunkLoads; for (int i = 0; i < sumLoad; i++){ @@ -521,7 +518,7 @@ void updategame(){ } - //ض + //加载动画 for (int i = 0; i < world::loadedChunks; i++){ world::chunk* cp = world::chunks[i]; if (cp->loadAnim <= 0.3f) @@ -530,7 +527,7 @@ void updategame(){ cp->loadAnim *= 0.6f; } - //״̬ + //随机状态更新 /* for (int i = 0; i < world::loadedChunks; i++){ int x, y, z; @@ -561,7 +558,7 @@ void updategame(){ } */ - //жѡеķ + //判断选中的方块 double lx, ly, lz, sidedist[7]; int sidedistmin; lx = player::xpos; ly = player::ypos + player::height + player::heightExt; lz = player::zpos; @@ -577,17 +574,17 @@ void updategame(){ selcz = 0; selb = 0; selbr = 0; - bool puted = false; //׼chinglishɡҪputѾFBΪؼˡ --ȵȲ԰Ѿc++ˣ + bool puted = false; //标准的chinglish吧。。。主要是put已经被FB作为关键字了。。 --等等不对啊!这已经是c++了!!! if (!bagOpened) { - //λ÷һ߶ + //从玩家位置发射一条线段 for (int i = 0; i < selectPrecision*selectDistance; i++) { - //߶ + //线段延伸 lx += sin(M_PI / 180 * (player::heading - 180))*sin(M_PI / 180 * (player::lookupdown + 90)) / (double)selectPrecision; ly += cos(M_PI / 180 * (player::lookupdown + 90)) / (double)selectPrecision; lz += cos(M_PI / 180 * (player::heading - 180))*sin(M_PI / 180 * (player::lookupdown + 90)) / (double)selectPrecision; - // + //碰到方块 if (BlockInfo(world::getblock(RoundInt(lx), RoundInt(ly), RoundInt(lz))).isSolid()) { int x, y, z; x = RoundInt(lx); @@ -596,7 +593,7 @@ void updategame(){ selx = x; sely = y; selz = z; - //ҷ鼰λ + //找方块所在区块及位置 selcx = getchunkpos(x); selbx = getblockpos(x); selcy = getchunkpos(y); @@ -604,13 +601,13 @@ void updategame(){ selcz = getchunkpos(z); selbz = getblockpos(z); - sidedist[1] = abs(y + 0.5 - ly); // - sidedist[2] = abs(y - 0.5 - ly); // - sidedist[3] = abs(x + 0.5 - lx); // - sidedist[4] = abs(x - 0.5 - lx); // - sidedist[5] = abs(z + 0.5 - lz); //ǰ - sidedist[6] = abs(z - 0.5 - lz); // - sidedistmin = 1; //ĸ + sidedist[1] = abs(y + 0.5 - ly); //顶面 + sidedist[2] = abs(y - 0.5 - ly); //底面 + sidedist[3] = abs(x + 0.5 - lx); //左面 + sidedist[4] = abs(x - 0.5 - lx); //右面 + sidedist[5] = abs(z + 0.5 - lz); //前面 + sidedist[6] = abs(z - 0.5 - lz); //后面 + sidedistmin = 1; //离哪个面最近 for (int j = 2; j <= 6; j++) { if (sidedist[j] < sidedist[sidedistmin]) sidedistmin = j; } @@ -667,7 +664,7 @@ void updategame(){ world::pickblock(x, y, z); } } - //÷ + //放置方块 if (((mb == 2 && mbp == false) || isPressed(GLFW_KEY_TAB)) && player::inventorypcs[3][player::itemInHand] > 0) { puted = true; switch (sidedistmin) { @@ -708,7 +705,7 @@ void updategame(){ player::intypos = RoundInt(player::ypos); player::intzpos = RoundInt(player::zpos); - //תͷκҶľ׵ + //转头!你治好了我多年的颈椎病! player::xlookspeed = player::ylookspeed = 0.0; if (mx != mxl)player::xlookspeed -= (mx - mxl)*mousemove; if (my != myl)player::ylookspeed += (my - myl)*mousemove; @@ -727,7 +724,7 @@ void updategame(){ player::heading += player::xlookspeed; player::lookupdown += player::ylookspeed; - //ƽǶȣͷת _ + //限制角度,别把头转掉下来了 ←_← if (player::lookupdown < -90){ player::lookupdown = -90; player::ylookspeed = 0.0; @@ -738,14 +735,14 @@ void updategame(){ } mxl = mx; myl = my; - //ƶ(˶) - if (glfwGetKey(MainWindow, GLFW_KEY_W)) { + //移动!(生命在于运动) + if (glfwGetKey(MainWindow, GLFW_KEY_W) || player::gliding()) { if (!WP) { if (Wprstm == 0.0) { Wprstm = timer(); } else { - if (timer() - Wprstm <= 0.5 && !player::gliding()) { player::Running = true; Wprstm = 0.0; } + if (timer() - Wprstm <= 0.5) { player::Running = true; Wprstm = 0.0; } else Wprstm = timer(); } } @@ -755,9 +752,11 @@ void updategame(){ player::xa = -sin(player::heading*M_PI / 180.0) * player::speed; player::za = -cos(player::heading*M_PI / 180.0) * player::speed; } - else{ - player::wingsAngle += 1.0; - if (player::wingsAngle > 90.0)player::wingsAngle = 90.0; + else { + player::xa = sin(M_PI / 180 * (player::heading - 180))*sin(M_PI / 180 * (player::lookupdown + 90)) * player::glidingSpeed * speedCast; + player::ya = cos(M_PI / 180 * (player::lookupdown + 90)) * player::glidingSpeed * speedCast; + player::za = cos(M_PI / 180 * (player::heading - 180))*sin(M_PI / 180 * (player::lookupdown + 90)) * player::glidingSpeed * speedCast; + if (player::ya < 0) player::ya *= 2; } } else { @@ -767,16 +766,10 @@ void updategame(){ if (player::Running)player::speed = runspeed; else player::speed = walkspeed; - if (glfwGetKey(MainWindow, GLFW_KEY_S) == GLFW_PRESS) { - if (!player::gliding()) { - player::xa = sin(player::heading*M_PI / 180.0) * player::speed; - player::za = cos(player::heading*M_PI / 180.0) * player::speed; - Wprstm = 0.0; - } - else{ - player::wingsAngle -= 1.0; - if (player::wingsAngle < -90.0)player::wingsAngle = -90.0; - } + if (glfwGetKey(MainWindow, GLFW_KEY_S) == GLFW_PRESS&&!player::gliding()) { + player::xa = sin(player::heading*M_PI / 180.0) * player::speed; + player::za = cos(player::heading*M_PI / 180.0) * player::speed; + Wprstm = 0.0; } if (glfwGetKey(MainWindow, GLFW_KEY_A) == GLFW_PRESS&&!player::gliding()) { @@ -815,12 +808,12 @@ void updategame(){ } } - //л + //切换方块 if (isPressed(GLFW_KEY_Z) && player::itemInHand > 0) player::itemInHand--; if (isPressed(GLFW_KEY_X) && player::itemInHand < 9) player::itemInHand++; mwl = mw; - // + //起跳! if (isPressed(GLFW_KEY_SPACE)){ if (!player::inWater) { if ((player::OnGround || player::AirJumps < MaxAirJumps) && FLY == false && CROSS == false){ @@ -836,10 +829,6 @@ void updategame(){ } } - if (glfwGetKey(MainWindow, GLFW_KEY_SPACE) == GLFW_PRESS && player::gliding()){ - player::glidingSpeed += 0.03; - } - if ((glfwGetKey(MainWindow, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(MainWindow, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS) && !player::gliding()) { if (CROSS || FLY) { player::ya -= walkspeed; @@ -850,7 +839,14 @@ void updategame(){ Wprstm = 0.0; } - //л + if (glfwGetKey(MainWindow, GLFW_KEY_K)&&canGliding&&!player::OnGround&&!player::gliding()) { + double h = player::ypos + player::height + player::heightExt; + player::glidingEnergy = g*h; + player::glidingSpeed = 0; + player::glidingNow = true; + } + + //各种设置切换 if (isPressed(GLFW_KEY_F1)){ FLY = !FLY; @@ -865,7 +861,7 @@ void updategame(){ } if (isPressed(GLFW_KEY_F4) == GLFW_PRESS) CROSS = !CROSS; if (isPressed(GLFW_KEY_F5) == GLFW_PRESS) GUIrenderswitch = !GUIrenderswitch; - if (isPressed(GLFW_KEY_F6) == GLFW_PRESS && player::OnGround) canGliding = !canGliding; + if (isPressed(GLFW_KEY_F6) == GLFW_PRESS) canGliding = !canGliding; } if (glfwGetKey(MainWindow, GLFW_KEY_E) == GLFW_PRESS && ep == false){ @@ -885,7 +881,7 @@ void updategame(){ if (isPressed(GLFW_KEY_L)) world::saveAllChunks(); } - //Ծ + //跳跃 if (!player::gliding()) { if (!player::inWater) { if (!FLY && !CROSS && !player::gliding() && !glfwGetKey(MainWindow, GLFW_KEY_R) && !glfwGetKey(MainWindow, GLFW_KEY_F)) { @@ -896,7 +892,7 @@ void updategame(){ isPressed(GLFW_KEY_SPACE, true); } else { - // + //自由落体计算 player::ya = player::jump + 0.5 * 0.6 * 1 / 900; player::jump -= 0.025; } @@ -917,28 +913,22 @@ void updategame(){ } } - //ǽ + //爬墙 //if (player::NearWall && FLY == false && CROSS == false){ // player::ya += walkspeed // player::jump = 0.0 //} - //ӵĻ - if (player::gliding() && !player::OnGround) { - - double ma = 50.0; // - double speed = sqrt(player::xd*player::xd + player::yd*player::yd + player::zd*player::zd); //ٶ - double qs = 1.2*speed*speed/2.0*1.0; //ѹ*ο - double lc = player::getLiftCoefficient(); //ϵ - //double ld = player::getDragCoefficient(); //ϵ - player::glidingSpeed *= 0.98; - player::ya *= 0.98; - player::ya += lc*qs / ma; - player::ya -= 0.025 / ma; - player::xa = sin(M_PI / 180 * (player::heading - 180)) * player::glidingSpeed; - player::za = cos(M_PI / 180 * (player::heading - 180)) * player::glidingSpeed; - //player::wingsAngle *= 0.99; - + if (player::gliding()) { + double& E = player::glidingEnergy; + double oldh = player::ypos + player::height + player::heightExt + player::ya; + double h = oldh; + if (E - glidingMinimumSpeed < h*g) { //小于最小速度 + h = (E - glidingMinimumSpeed) / g; + } + player::glidingSpeed = sqrt(2 * (E - g*h)); + E -= EDrop; + player::ya += h - oldh; } mbp = mb; @@ -972,14 +962,14 @@ void debugText(string s, bool init) { } void drawMain() { - // + //画场景 // Time_renderscene_ = timer(); - + double curtime = timer(); double TimeDelta; double xpos, ypos, zpos; int renderedChunk = 0; - + if (player::Running){ if (FOVyExt < 9.8){ TimeDelta = curtime - SpeedupAnimTimer; @@ -999,7 +989,7 @@ void drawMain() { SpeedupAnimTimer = curtime; if (player::OnGround){ - //Ч + //半蹲特效 if (player::jump < -0.005){ if (player::jump <= -(player::height - 0.5f)) player::heightExt = -(player::height - 0.5f); @@ -1037,30 +1027,15 @@ void drawMain() { player::cyt = getchunkpos((int)player::ypos); player::czt = getchunkpos((int)player::zpos); - //ʾб - world::chunkBuildRenders = world::updatedChunks.size(); - std::sort(world::updatedChunks.begin(), world::updatedChunks.end()); - int brl = world::chunkBuildRenders > 4 ? 4 : world::chunkBuildRenders; - for (int i = world::chunkBuildRenders - 1; i >= world::chunkBuildRenders - brl; i--) { - world::chunk* cp = world::updatedChunks[i].ptr; - if (cp->buildRender()){ - for (int j = i + 1; j < world::chunkBuildRenders; j++) { - world::updatedChunks[j - 1] = world::updatedChunks[j]; - } - world::updatedChunks.pop_back(); - world::chunkBuildRenders--; - } - } - /* + //更新区块显示列表 world::sortChunkBuildRenderList(RoundInt(player::xpos), RoundInt(player::ypos), RoundInt(player::zpos)); int brl = world::chunkBuildRenders > 4 ? 4 : world::chunkBuildRenders; for (int i = 0; i < brl; i++) { int ci = world::chunkBuildRenderList[i][1]; world::chunks[ci]->buildRender(); } - */ - //ɾжVBO + //删除已卸载区块的VBO if (world::vbuffersShouldDelete.size() > 0){ glDeleteBuffersARB(world::vbuffersShouldDelete.size(), world::vbuffersShouldDelete.data()); world::vbuffersShouldDelete.clear(); @@ -1097,8 +1072,7 @@ void drawMain() { if (cr.vtxs[0] == 0) continue; glPushMatrix(); glTranslated(cr.cx * 16.0 - xpos, cr.cy * 16.0 - cr.loadAnim - ypos, cr.cz * 16.0 - zpos); - //renderer::renderbuffer(cr.vbuffers[0], cr.vtxs[0], true, true); - renderer::renderbuffer_opt(cr.vbuffers[0], cr.vtxs[0]); + renderer::renderbuffer(cr.vbuffers[0], cr.vtxs[0], true, true); glPopMatrix(); } @@ -1141,8 +1115,7 @@ void drawMain() { if (cr.vtxs[1] == 0) continue; glPushMatrix(); glTranslated(cr.cx * 16.0 - xpos, cr.cy * 16.0 - cr.loadAnim - ypos, cr.cz * 16.0 - zpos); - //renderer::renderbuffer(cr.vbuffers[1], cr.vtxs[1], true, true); - renderer::renderbuffer_opt(cr.vbuffers[1], cr.vtxs[1]); + renderer::renderbuffer(cr.vbuffers[1], cr.vtxs[1], true, true); glPopMatrix(); } glDisable(GL_CULL_FACE); @@ -1151,8 +1124,7 @@ void drawMain() { if (cr.vtxs[2] == 0) continue; glPushMatrix(); glTranslated(cr.cx * 16.0 - xpos, cr.cy * 16.0 - cr.loadAnim - ypos, cr.cz * 16.0 - zpos); - //renderer::renderbuffer(cr.vbuffers[2], cr.vtxs[2], true, true); - renderer::renderbuffer_opt(cr.vbuffers[2], cr.vtxs[2]); + renderer::renderbuffer(cr.vbuffers[2], cr.vtxs[2], true, true); glPopMatrix(); } @@ -1202,7 +1174,7 @@ void drawMain() { #else localtime_s(timeinfo, &t); #endif - strftime(tmp, sizeof(tmp), "%Y%m%d%Hʱ%M%S", timeinfo); + strftime(tmp, sizeof(tmp), "%Y年%m月%d日%H时%M分%S秒", timeinfo); std::stringstream ss; ss << "\\screenshots\\" << tmp << ".bmp"; saveScreenshot(0, 0, windowwidth, windowheight, ss.str()); @@ -1212,7 +1184,7 @@ void drawMain() { createThumbnail(); } - //Ļˢ£ǧɾԸ + //屏幕刷新,千万别删,后果自负!!! //====refresh====// MutexUnlock(Mutex); glfwSwapBuffers(MainWindow); @@ -1225,8 +1197,8 @@ void drawMain() { } void drawBorder(int x, int y, int z) { - //ѡ߿򣬽GL_LINE_LOOPѧQAQ - static float extrize = 0.002f; //ʵ߿ӦñȷһЩѿ + //绘制选择边框,建议用GL_LINE_LOOP,别学我QAQ + static float extrize = 0.002f; //实际上这个边框应该比方块大一些,否则很难看 glEnable(GL_LINE_SMOOTH); glLineWidth(1.0f); glColor3f(0.2f, 0.2f, 0.2f); @@ -1304,16 +1276,6 @@ void drawGUI(){ glDepthFunc(GL_ALWAYS); glDisable(GL_TEXTURE_2D); glEnable(GL_LINE_SMOOTH); - - if (player::gliding()){ - glLineWidth(1); - glBegin(GL_LINES); - glColor4f(gui::FgR, gui::FgG, gui::FgB, 0.8f); - glVertex2i(windowwidth / 2, windowheight / 2); - glVertex2i(windowwidth / 2 + int(cos(player::wingsAngle*M_PI / 180.0)*50.0), windowheight / 2 - int(sin(player::wingsAngle*M_PI / 180.0)*50.0)); - glEnd(); - } - int seldes_100 = int(seldes / 100); if (DebugMode) { @@ -1499,9 +1461,9 @@ void drawGUI(){ ss << world::loadedChunks << " / " << world::chunkArraySize << " chunks loaded"; debugText(ss.str()); ss.str(""); - ss << world::unloadedChunksCount << " chunks unloaded"; + ss << world::unloadedChunks << " chunks unloaded"; debugText(ss.str()); ss.str(""); - ss << world::updatedChunksCount << " chunks updated"; + ss << world::updatedChunks << " chunks updated"; debugText(ss.str()); ss.str(""); #ifdef NEWORLD_DEBUG_PERFORMANCE_REC @@ -1530,12 +1492,10 @@ void drawGUI(){ } - //֡ + //检测帧速率 if (timer() - fctime >= 1) { fps = fpsc; fpsc = 0; - world::updatedChunksCount = world::updatedChunksCounter; - world::updatedChunksCounter = 0; fctime = timer(); } fpsc++; @@ -1651,7 +1611,7 @@ void renderDestroy(float level, int x, int y, int z) { } void drawBag() { - // + //背包界面 static int si, sj, sf; int leftp = (windowwidth - 392) / 2; int upp = windowheight - 152 - 16; @@ -1660,19 +1620,19 @@ void drawBag() { static block pcsselected = 0; glClearColor(skycolorR, skycolorG, skycolorB, 1.0); glfwSetInputMode(MainWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL); - + mousew = mw; mouseb = mb; glDepthFunc(GL_ALWAYS); glDisable(GL_CULL_FACE); glDisable(GL_TEXTURE_2D); - + glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, windowwidth, windowheight, 0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - + glColor4f(0.2f, 0.2f, 0.2f, 0.6f); glBegin(GL_QUADS); glVertex2i(0, 0); @@ -1680,7 +1640,7 @@ void drawBag() { glVertex2i(windowwidth, windowheight); glVertex2i(0, windowheight); glEnd(); - + glEnable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); sf = 0; @@ -1794,4 +1754,3 @@ void createThumbnail(){ ss << "Worlds\\" << world::worldname << "\\Thumbnail.bmp"; saveScreenshot(0, 0, windowwidth, windowheight, ss.str()); } - diff --git a/source/Particles.h b/source/Particles.h index e3f7cea..b9afbeb 100644 --- a/source/Particles.h +++ b/source/Particles.h @@ -18,4 +18,5 @@ namespace particles{ void render(particle &ptc); void renderall(); void throwParticle(block pt, float x, float y, float z, float xs, float ys, float zs, float psz, int last); -} + +} \ No newline at end of file diff --git a/source/Player.cpp b/source/Player.cpp index ce0877c..e0d6a9a 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -4,6 +4,7 @@ bool canGliding = false; // bool FLY; // bool CROSS; //ǽ _ (Superman!) +double glidingMinimumSpeed = pow(1, 2) / 2; namespace player{ Hitbox::AABB playerbox; @@ -14,6 +15,7 @@ namespace player{ bool Running = false; bool NearWall = false; bool inWater = false; + bool glidingNow = false; double glidingEnergy, glidingSpeed; double speed; int AirJumps; @@ -21,7 +23,6 @@ namespace player{ double lookupdown, heading, xpos, ypos, zpos, xposold, yposold, zposold, jump; double xlookspeed, ylookspeed; int intxpos, intypos, intzpos, intxposold, intyposold, intzposold; - double wingsAngle; block BlockInHand = blocks::AIR; ubyte itemInHand = 0; @@ -89,6 +90,7 @@ namespace player{ OnGround = true; player::glidingEnergy = 0; player::glidingSpeed = 0; + player::glidingNow = false; } else OnGround = false; if (ya != yal && yal>0.0) jump = 0.0; @@ -201,22 +203,4 @@ namespace player{ } } - double getLiftCoefficient(){ - //ȡϵ - double a = wingsAngle; - return sin(2.0*a*M_PI/180.0); - } - - double getDragCoefficient(){ - //ȡϵ - double a = wingsAngle; - return 1.0-cos(2.0*a*M_PI/180.0); - } - - double getDragCoefficientY(){ - //ȡֱϵ - double a = abs(wingsAngle + 90.0); - return 1.0-cos(2.0*a*M_PI/180.0); - } - } diff --git a/source/Player.h b/source/Player.h index f76e0b9..94eea77 100644 --- a/source/Player.h +++ b/source/Player.h @@ -2,10 +2,16 @@ #include "Definitions.h" #include "Hitbox.h" +const double g = 9.8; +const double EDrop = 0.1; +const double speedCast = 1 / 20.0; + extern bool canGliding; // extern bool FLY; // extern bool CROSS; //ǽ _ (Superman!) +extern double glidingMinimumSpeed; + namespace player{ void InitHitbox(); @@ -17,9 +23,6 @@ namespace player{ void save(string worldn); void load(string worldn); void additem(block itemname); - double getLiftCoefficient(); - double getDragCoefficient(); - double getDragCoefficientY(); extern Hitbox::AABB playerbox; @@ -28,6 +31,7 @@ namespace player{ extern bool Running; extern bool NearWall; extern bool inWater; + extern bool glidingNow; extern double speed; extern int AirJumps; @@ -35,7 +39,6 @@ namespace player{ extern double lookupdown, heading, xpos, ypos, zpos, xposold, yposold, zposold, jump; extern double xlookspeed, ylookspeed; extern int intxpos, intypos, intzpos, intxposold, intyposold, intzposold; - extern double wingsAngle; extern float height; extern float heightExt; @@ -46,6 +49,6 @@ namespace player{ extern block inventorypcs[4][10]; extern double glidingEnergy, glidingSpeed; - inline bool gliding() { return canGliding&&!OnGround; } + inline bool gliding() { return glidingNow; } } diff --git a/source/Renderer.cpp b/source/Renderer.cpp index 0ecb56d..535978c 100644 --- a/source/Renderer.cpp +++ b/source/Renderer.cpp @@ -30,8 +30,8 @@ namespace renderer { TexCoord2f((float)x, (float)y); } - void Color3d(double r_, double g_, double b_){ - Color3f((float)r_, (float)g_, (float)b_); + void Color3d(double r, double g, double b){ + Color3f((float)r, (float)g, (float)b); } void Vertex3f(float x, float y, float z) { @@ -109,7 +109,7 @@ namespace renderer { } - void renderbuffer(unsigned int buffer, int vtxs, bool ftex, bool fcol){ + void renderbuffer(unsigned int buffer, int vtxs, bool ftex, bool fcol) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer); @@ -139,7 +139,7 @@ namespace renderer { //================================ } - + //GLhandleARB loadShader(string filename, uint mode){ //GLhandleARB shader; diff --git a/source/Renderer.h b/source/Renderer.h index 702ad41..e499c50 100644 --- a/source/Renderer.h +++ b/source/Renderer.h @@ -6,17 +6,10 @@ namespace renderer{ void Init(); void Vertex3d(double x, double y, double z); void TexCoord2d(double x, double y); - void Color3d(double r_, double g_, double b_); + void Color3d(double r, double g, double b); void Vertex3f(float x, float y, float z); void TexCoord2f(float x, float y); - void Color3f(float r_, float g_, float b_); + void Color3f(float r, float g, float b); void Flush(unsigned int& buffer, int& vtxs); void renderbuffer(unsigned int buffer, int vtxs, bool ftex, bool fcol); - inline void renderbuffer_opt(unsigned int buffer, int vtxs){ - glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer); - glTexCoordPointer(2, GL_FLOAT, 8 * sizeof(float), (float*)0); - glColorPointer(3, GL_FLOAT, 8 * sizeof(float), (float*)(2 * sizeof(float))); - glVertexPointer(3, GL_FLOAT, 8 * sizeof(float), (float*)(5 * sizeof(float))); - glDrawArrays(GL_QUADS, 0, vtxs); - } } diff --git a/source/Textures.cpp b/source/Textures.cpp index b42f08a..5adb5ba 100644 --- a/source/Textures.cpp +++ b/source/Textures.cpp @@ -238,4 +238,4 @@ namespace Textures { return ret; } -} +} \ No newline at end of file diff --git a/source/World.cpp b/source/World.cpp index 3d04817..d3430e8 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -24,12 +24,12 @@ namespace world{ chunkPtrArray cpArray; HeightMap HMap; int cloud[128][128]; - int updatedChunksCount, updatedChunksCounter; - int unloadedChunksCount, unloadedChunksCounter; - //int chunkBuildRenderList[256][2] - vector updatedChunks; + int rebuiltChunks, rebuiltChunksCount; + int updatedChunks, updatedChunksCount; + int unloadedChunks, unloadedChunksCount; + int chunkBuildRenderList[256][2]; int chunkLoadList[256][4]; - int chunkUnloadList[256][4]; + pair chunkUnloadList[256]; vector vbuffersShouldDelete; int chunkBuildRenders, chunkLoads, chunkUnloads; bool* loadedChunkArray = nullptr; //Accelerate sort @@ -43,7 +43,7 @@ namespace world{ ss.clear(); ss.str(""); ss << "mkdir Worlds\\" << worldname << "\\chunks"; system(ss.str().c_str()); - + WorldGen::perlinNoiseInit(3404); cpCachePtr = nullptr; cpCacheID = 0; @@ -141,7 +141,7 @@ namespace world{ if (chunks[middle]->id > cid) last = middle - 1; else first = middle + 1; middle = (first + last) / 2; } - if (chunks[middle]->id == cid)return middle; + if (chunks[middle]->id == cid) return middle; #ifdef NEWORLD_DEBUG DebugError("getChunkPtrIndex Error!"); #endif @@ -477,7 +477,6 @@ namespace world{ } } - vector getHitboxes(Hitbox::AABB box){ //boxཻзAABB @@ -599,7 +598,7 @@ namespace world{ else{ //Opaque block - getChunkPtr(cx, cy, cz)->setbrightness(bx, by, bz, 0); + cptr->setbrightness(bx, by, bz, 0); if (getblock(x, y, z) == blocks::GLOWSTONE || getblock(x, y, z) == blocks::LAVA){ cptr->setbrightness(bx, by, bz, BRIGHTNESSMAX); } @@ -618,13 +617,13 @@ namespace world{ updateblock(x, y, z - 1, false); } - setChunkUpdated(cx, cy, cz); - if (bx == 15 && cx-worldsize) setChunkUpdated(cx - 1, cy, cz); - if (by == 15 && cy-worldheight) setChunkUpdated(cx, cy - 1, cz); - if (bz == 15 && cz-worldsize) setChunkUpdated(cx, cy, cz - 1); + setChunkUpdated(cx, cy, cz, true); + if (bx == 15 && cx-worldsize) setChunkUpdated(cx - 1, cy, cz, true); + if (by == 15 && cy-worldheight) setChunkUpdated(cx, cy - 1, cz, true); + if (bz == 15 && cz-worldsize) setChunkUpdated(cx, cy, cz - 1, true); } } @@ -641,7 +640,7 @@ namespace world{ return cptr->getblock(bx, by, bz); } chunk* ci = getChunkPtr(cx, cy, cz); - if (ci != nullptr)return ci->getblock(bx, by, bz); + if (ci != nullptr) return ci->getblock(bx, by, bz); return mask; } @@ -734,22 +733,19 @@ namespace world{ } - /* void sortChunkBuildRenderList(int xpos, int ypos, int zpos) { int cxp, cyp, czp, cx, cy, cz, p = 0; int xd, yd, zd, distsqr; - chunk* cp; - + cxp = getchunkpos(xpos); cyp = getchunkpos(ypos); czp = getchunkpos(zpos); - + for (int ci = 0; ci < loadedChunks; ci++) { if (chunks[ci]->updated) { - cp = chunks[ci]; - cx = cp->cx; - cy = cp->cy; - cz = cp->cz; + cx = chunks[ci]->cx; + cy = chunks[ci]->cy; + cz = chunks[ci]->cz; if (!chunkInRange(cx, cy, cz, cxp, cyp, czp, viewdistance)) continue; xd = cx * 16 + 7 - xpos; yd = cy * 16 + 7 - ypos; @@ -771,7 +767,6 @@ namespace world{ } chunkBuildRenders = p; } - */ void sortChunkLoadUnloadList(int xpos, int ypos, int zpos) { @@ -798,22 +793,18 @@ namespace world{ first = 0; last = pl - 1; while (first <= last) { middle = (first + last) / 2; - if (distsqr > chunkUnloadList[middle][0])last = middle - 1; + if (distsqr > chunkUnloadList[middle].second)last = middle - 1; else first = middle + 1; } if (first > pl || first >= 4) continue; i = first; for (int j = 3; j > i; j--) { - chunkUnloadList[j][0] = chunkUnloadList[j - 1][0]; - chunkUnloadList[j][1] = chunkUnloadList[j - 1][1]; - chunkUnloadList[j][2] = chunkUnloadList[j - 1][2]; - chunkUnloadList[j][3] = chunkUnloadList[j - 1][3]; + chunkUnloadList[j].first = chunkUnloadList[j - 1].first; + chunkUnloadList[j].second = chunkUnloadList[j - 1].second; } - chunkUnloadList[i][0] = distsqr; - chunkUnloadList[i][1] = cx; - chunkUnloadList[i][2] = cy; - chunkUnloadList[i][3] = cz; + chunkUnloadList[i].first = chunks[ci]; + chunkUnloadList[i].second = distsqr; if (pl < 4) pl++; } @@ -891,9 +882,10 @@ namespace world{ if(cpArrayAval)cpArray.destroy(); HMap.destroy(); - updatedChunksCount = 0; updatedChunksCounter = 0; - unloadedChunksCount = 0; unloadedChunksCounter = 0; - updatedChunks.clear(); + rebuiltChunks = 0; rebuiltChunksCount = 0; + updatedChunks = 0; updatedChunksCount = 0; + unloadedChunks = 0; unloadedChunksCount = 0; + memset(chunkBuildRenderList, 0, 256 * 2 * sizeof(int)); memset(chunkLoadList, 0, 256 * 4 * sizeof(int)); memset(chunkUnloadList, 0, 256 * 4 * sizeof(int)); chunkBuildRenders = 0; chunkLoads = 0; chunkUnloads = 0; diff --git a/source/World.h b/source/World.h index d5ae539..6e73dec 100644 --- a/source/World.h +++ b/source/World.h @@ -5,24 +5,8 @@ #include "Chunk.h" #include "Hitbox.h" -namespace player { - extern double xpos, ypos, zpos; -} - namespace world{ - struct updatedChunksItem{ - chunk* ptr; - int x, y, z; - updatedChunksItem(){} - updatedChunksItem(chunk* _ptr, int _x,int _y,int _z):ptr(_ptr), x(_x),y(_y),z(_z) {} - bool operator< (const updatedChunksItem& uci) const { - int xd = (int)player::xpos - x, yd = (int)player::ypos - y, zd = (int)player::zpos - z; - int xd1 = (int)player::xpos - uci.x, yd1 = (int)player::ypos - uci.y, zd1 = (int)player::zpos - uci.z; - return sqrt(xd*xd + yd*yd + zd*zd) > sqrt(xd1*xd1 + yd1*yd1 + zd1*zd1); - } - }; - extern string worldname; const int worldsize = 134217728; const int worldheight = 8; @@ -43,12 +27,12 @@ namespace world{ extern bool cpArrayAval; extern int cloud[128][128]; - extern int updatedChunksCount, updatedChunksCounter; - extern int unloadedChunksCount, unloadedChunksCounter; - //extern int chunkBuildRenderList[256][2]; - extern vector updatedChunks; //˵ + extern int rebuiltChunks, rebuiltChunksCount; + extern int updatedChunks, updatedChunksCount; + extern int unloadedChunks, unloadedChunksCount; + extern int chunkBuildRenderList[256][2]; extern int chunkLoadList[256][4]; - extern int chunkUnloadList[256][4]; + extern pair chunkUnloadList[256]; extern vector vbuffersShouldDelete; extern int chunkBuildRenders, chunkLoads, chunkUnloads; extern bool* loadedChunkArray; @@ -84,14 +68,11 @@ namespace world{ inline bool chunkUpdated(int x, int y, int z){ return getChunkPtr(x, y, z)->updated; } - inline void setChunkUpdated(int x, int y, int z){ + inline void setChunkUpdated(int x, int y, int z, bool value){ chunk* i = getChunkPtr(x, y, z); - if (i != nullptr) { - i->updated = true; - updatedChunks.push_back(updatedChunksItem(i, x * 16 + 7, y * 16 + 7, z * 16 + 7)); - } + if (i != nullptr) i->updated = value; } - //void sortChunkBuildRenderList(int xpos, int ypos, int zpos); + void sortChunkBuildRenderList(int xpos, int ypos, int zpos); void sortChunkLoadUnloadList(int xpos, int ypos, int zpos); void saveAllChunks(); diff --git a/source/stdinclude.h b/source/stdinclude.h index 7cafbec..01cea3e 100644 --- a/source/stdinclude.h +++ b/source/stdinclude.h @@ -20,9 +20,8 @@ #include #include #include -//#include +#include #include -#include using std::string; using std::vector; @@ -40,4 +39,4 @@ using std::endl; //#pragma warning(pop) //#pragma warning(disable:4820) //ԲҪľ棺ݽṹ -//#pragma warning(disable:4365) //ԲҪľ棺з/޷Ųƥ +//#pragma warning(disable:4365) //ԲҪľ棺з/޷Ųƥ \ No newline at end of file