Skip to content

Commit

Permalink
更改,优化部分代码
Browse files Browse the repository at this point in the history
fps+=200
  • Loading branch information
Null committed Oct 10, 2015
1 parent 5112a6e commit ba36101
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 164 deletions.
7 changes: 3 additions & 4 deletions source/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ namespace world{

rebuiltChunks++;
updatedChunks++;
cindex = getChunkIndex(cx, cy, cz);

if (renderBuilt == false){
renderBuilt = true;
Expand All @@ -167,7 +166,7 @@ namespace world{
for (z = 0; z < 16; z++) {
if (pblocks[x*256 + y*16 + z] == blocks::AIR) continue;
if (!BlockInfo(pblocks[x*256 + y*16 + z]).isTranslucent())
renderblock(x, y, z, cindex);
renderblock(x, y, z, this);
}
}
}
Expand All @@ -179,7 +178,7 @@ namespace world{
for (z = 0; z < 16; z++){
if (pblocks[x*256 + y*16 + z] == blocks::AIR) continue;
if (BlockInfo(pblocks[x*256 + y*16 + z]).isTranslucent() && BlockInfo(pblocks[x*256 + y*16 + z]).isSolid())
renderblock(x, y, z, cindex);
renderblock(x, y, z, this);
}
}
}
Expand All @@ -191,7 +190,7 @@ namespace world{
for (z = 0; z < 16; z++){
if (pblocks[x*256 + y*16 + z] == blocks::AIR) continue;
if (!BlockInfo(pblocks[x*256 + y*16 + z]).isSolid())
renderblock(x, y, z, cindex);
renderblock(x, y, z, this);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion source/Definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ float playerHeightExt;
int windowwidth; //窗口宽度
int windowheight; //窗口宽度
bool gamebegin, bagOpened;
int k;

TextureID BlockTexture[20];
TextureID BlockTextures;
Expand Down
5 changes: 3 additions & 2 deletions source/Definitions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
#pragma comment(linker, "/SUBSYSTEM:\"WINDOWS,5.01\" /ENTRY:\"mainCRTStartup\"")
#ifndef _DEBUG
#pragma comment(linker, "/SUBSYSTEM:\"WINDOWS\" /ENTRY:\"mainCRTStartup\"")
#endif
#include "stdinclude.h"

/*
Expand Down Expand Up @@ -74,7 +76,6 @@ extern float playerHeightExt;
extern int windowwidth;
extern int windowheight;
extern bool gamebegin, bagOpened;
extern int k;

extern TextureID BlockTexture[20];
extern TextureID BlockTextures;
Expand Down
2 changes: 1 addition & 1 deletion source/Frustum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace Frustum {
bool AABBInFrustum(const Hitbox::AABB& aabb) {
for (int i = 0; i < 24; i += 4){
if (frus[i + 0] * aabb.xmin + frus[i + 1] * aabb.ymin + frus[i + 2] * aabb.zmin + frus[i + 3] <= 0.0 &&
frus[i + 0] * aabb.xmax + frus[i + 1] * aabb.ymin + frus[i + 2] * aabb.zmin + frus[i + 3] <= 0.0&&
frus[i + 0] * aabb.xmax + frus[i + 1] * aabb.ymin + frus[i + 2] * aabb.zmin + frus[i + 3] <= 0.0 &&
frus[i + 0] * aabb.xmin + frus[i + 1] * aabb.ymax + frus[i + 2] * aabb.zmin + frus[i + 3] <= 0.0 &&
frus[i + 0] * aabb.xmax + frus[i + 1] * aabb.ymax + frus[i + 2] * aabb.zmin + frus[i + 3] <= 0.0 &&
frus[i + 0] * aabb.xmin + frus[i + 1] * aabb.ymin + frus[i + 2] * aabb.zmax + frus[i + 3] <= 0.0 &&
Expand Down
8 changes: 4 additions & 4 deletions source/Menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void worldmenu(){
vscroll->barpos = 0;
chosenWorldName = "";
//查找所有世界存档
Textures::TEXTURE_RGB* tmb;
Textures::TEXTURE_RGB tmb;
long hFile = 0;
_finddata_t fileinfo;
if ((hFile = _findfirst(string("Worlds\\*").c_str(), &fileinfo)) != -1)
Expand All @@ -298,9 +298,9 @@ void worldmenu(){
glBindTexture(GL_TEXTURE_2D, thumbnails[thumbnails.size() - 1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tmb->sizeX, tmb->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, tmb->buffer);
texSizeX[texSizeX.size() - 1] = tmb->sizeX;
texSizeY[texSizeY.size() - 1] = tmb->sizeY;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tmb.sizeX, tmb.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, tmb.buffer.get());
texSizeX[texSizeX.size() - 1] = tmb.sizeX;
texSizeY[texSizeY.size() - 1] = tmb.sizeY;
}
file.close();
}
Expand Down
33 changes: 5 additions & 28 deletions source/NEWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int selbx, selby, selbz, selcx, selcy, selcz;
和我的不一样,把这几行注释掉吧。。。)
=======================================
等等不对啊!!!明明都改成c++了。。。还说是FB。。。
VC++编译器应该不会在这儿报错吧23333333
C++编译器应该不会在这儿报错吧23333333
#endif

//============================== Main Program ================================//
Expand Down Expand Up @@ -999,7 +999,7 @@ void drawMain() {

//删除已卸载区块的VBO
if (world::vbuffersShouldDelete.size() > 0){
glDeleteBuffersARB(world::vbuffersShouldDelete.size(), &*world::vbuffersShouldDelete.begin());
glDeleteBuffersARB(world::vbuffersShouldDelete.size(), world::vbuffersShouldDelete.data());
world::vbuffersShouldDelete.clear();
}

Expand Down Expand Up @@ -1060,24 +1060,6 @@ void drawMain() {
glTranslated(-selx + xpos, -sely + ypos, -selz + zpos);
}

/*
Hitbox::AABB t;
t.xmin = world::ciArray.originX * 16;
t.xmax = world::ciArray.originX * 16 + world::ciArray.size * 16;
t.ymin = world::ciArray.originY * 16;
t.ymax = world::ciArray.originY * 16 + world::ciArray.size * 16;
t.zmin = world::ciArray.originZ * 16;
t.zmax = world::ciArray.originZ * 16 + world::ciArray.size * 16;
Hitbox::AABB t2;
t2.xmin = world::HMap.originX;
t2.xmax = world::HMap.originX + world::HMap.size;
t2.ymin = 36.0;
t2.ymax = 36.0;
t2.zmin = world::HMap.originZ;
t2.zmax = world::HMap.originZ + world::HMap.size;
*/

MutexUnlock(Mutex);

glLoadIdentity();
Expand Down Expand Up @@ -1117,10 +1099,6 @@ void drawMain() {
glRotated(player::lookupdown, 1, 0, 0);
glRotated(360.0 - player::heading, 0, 1, 0);
glTranslated(-xpos, -ypos, -zpos);
//glDisable(GL_TEXTURE_2D);
//glEnableClientState(GL_VERTEX_ARRAY);
//drawCloud(player::xpos, player::zpos);
//glDisableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D);
glEnable(GL_CULL_FACE);

Expand Down Expand Up @@ -1174,7 +1152,7 @@ void drawMain() {
//屏幕刷新,千万别删,后果自负!!!
//====refresh====//
MutexUnlock(Mutex);
glFinish();
//glFinish();
glfwSwapBuffers(MainWindow);
glfwPollEvents();
MutexLock(Mutex);
Expand Down Expand Up @@ -1731,10 +1709,9 @@ void saveScreenshot(int x, int y, int w, int h, string filename){
while (h % 4 != 0){ h -= 1; }
scrBuffer.sizeX = w;
scrBuffer.sizeY = h;
scrBuffer.buffer = (ubyte*)malloc(w*h * 3);
glReadPixels(x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, scrBuffer.buffer);
scrBuffer.buffer = unique_ptr<ubyte[]>((ubyte*)malloc(w*h * 3));
glReadPixels(x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, scrBuffer.buffer.get());
Textures::SaveRGBImage(filename, scrBuffer);
free(scrBuffer.buffer);
}

void createThumbnail(){
Expand Down
2 changes: 1 addition & 1 deletion source/TextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TextRenderer{
unsigned int Font;
int gloop;
int ww, wh;
float r=0.0f, g=0.0f, b=0.0f, a=1.0f;
float r = 0.0f, g = 0.0f, b = 0.0f, a = 1.0f;
unsigned int unicodeTex[256];
bool unicodeTexAval[256];
bool useUnicodeASCIIFont;
Expand Down
Loading

0 comments on commit ba36101

Please sign in to comment.