我怎么能画一个平铺图没有我的ram使用或cpu使用的方式上升
How can I draw a tilemap without my ram useage or cpu useage going way up?
我试着用SDL在屏幕上画一个平铺图,我的fps很糟糕。我试过用一种不同的方式在SFML中做这件事,但这种方式使我的ram使用率大大提高。
我试图在SDL中绘制它的方式是有一个我切碎的SDL_Surface *tilemap;
,并像这样渲染:
void apply_surface ( int sourceX, int sourceY, int sourceW, int sourceH, int x, int y, SDL_Surface* source, SDL_Surface* destination ){
// make a temporary rectangle to hold the offsets
SDL_Rect offset;
SDL_Rect sourceRect;
// give the offsets to the rectangle
offset.x = x;
offset.y = y;
sourceRect.x = sourceX;
sourceRect.y = sourceY;
sourceRect.h = sourceH;
sourceRect.w = sourceW;
// blit the surface
SDL_BlitSurface( source, &sourceRect, destination, &offset );
}
void render(){
for(int x = 0; x < lv.width; x++){
for(int y = 0; y < lv.height; y++){
if(x * lv.tileSize < 640 && y * lv.tileSize < 480){
int tileXCoord = 0;
int tileYCoord = 0;
int tileSheetWidth = tilemap->w / lv.tileSize;
if (lv.tile[x][y] != 0)
{
tileXCoord = lv.tile[x][y] % tileSheetWidth;
tileYCoord = lv.tile[x][y] / tileSheetWidth;
}
apply_surface(tileXCoord * lv.tileSize, tileYCoord * lv.tileSize, lv.tileSize, lv.tileSize, x * lv.tileSize, y * lv.tileSize, tilemap, screen);
}
}
}
}
这种方式会提高我的CPU,降低我的FPS。
我尝试在SFML中绘制图像的水平,然后显示该图像(使用裁剪),但这使我的ram高达50,000k。
所以我问的是我怎么能画一个平铺图(在SDL)没有让我的cpu或ram走的方式?
- 请确保在加载tilemap时,将其转换为与屏幕相同的格式,这样比特化就不必执行任何转换。SDL_DisplayFormat为你做这个。
- 在哪里调用渲染()?确保每帧调用一次,不多也不少。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- cmake在我的项目中所需的所有静态库都不成功
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 为什么我的for循环不能正确获取argv
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 0-1背包代码中的错误.我的代码中有什么错误
- 为什么我的 2d 数组的第二行从 RAM 中获取随机值?
- 为什么我的C 代码在Linux上运行,而在Windows上不运行,是否有RAM内存的问题
- 为什么free()没有释放我的Arduino Uno上的RAM
- 出于某种原因,一个int在我的ram上的重量超过了32位
- 我的 265GB RAM 笔记本电脑上的内存是否超过 8GB
- 为什么我的程序设计为用完 RAM 和 CPU 不使用所有 RAM 和 CPU?
- 为什么当我的矢量<矢量<int><矢量> >大于 RAM 时,我的程序会产生正确的输出?
- 我如何使用c++ API从Abaqus odb文件中提取比我的RAM大的数据(fieldOutputs)
- 是我的SDL/C++程序占用了太多RAM内存吗
- 我怎么能画一个平铺图没有我的ram使用或cpu使用的方式上升