|
This thread is locked; no one can reply to it. |
1
2
|
My CPU usage is absurd |
Gabriel Campos
Member #12,034
June 2010
|
i am not using mappy anymore. I created a file with intenger
|
Kris Asick
Member #1,424
July 2001
|
Could also be vsync related. If you're not vsyncing, or your GPU drivers are set to force vsync off by default, that could lead to a massive unnecessary waste of CPU power. --- Kris Asick (Gemini) |
Thomas Fjellstrom
Member #476
June 2000
|
If you're not waiting in your main loop, its going to suck up an entire core, which shows up as 50% on a dual core system (as someone previously mentioned). -- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Gabriel Campos said:
i am not using mappy anymore. I created a file with intenger
Edgar said: Like I said before, mappy doesn't use atlases or held drawing, both of which would speed up your drawing. And are you using atlases or held drawing in your own code? I'm guessing not. You're gonna have to show the code you're using now. We can't guess what's wrong anymore. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Gabriel Campos
Member #12,034
June 2010
|
1#include "LevelManager.h"
2
3LevelManager::LevelManager(void)
4{
5 blockSize = 32;
6}
7
8LevelManager::~LevelManager(void)
9{
10}
11
12void LevelManager::load(const char *filename)
13{
14 int state;
15 enum loadState{TILESET, LAYER_BG, LAYER_LV};
16 std::fstream file(filename);
17 std::vector<int>tempVector;
18
19 if(file.is_open())
20 {
21 std::string line, value;
22
23 while(!file.eof())
24 {
25 std::getline(file, line);
26
27 if(line.find("[tileset]") != std::string::npos)
28 {
29 state = TILESET;
30 continue;
31 }
32
33 else if(line.find("[layer_bg]") != std::string::npos)
34 {
35 state = LAYER_BG;
36 continue;
37 }
38
39 else if(line.find("[layer_lv]") != std::string::npos)
40 {
41 state = LAYER_LV;
42 continue;
43 }
44
45 switch(state)
46 {
47 case TILESET:
48 if(line.length() > 0)
49 tileset = al_load_bitmap(line.c_str());
50
51 al_convert_mask_to_alpha(tileset, al_get_pixel(tileset, 0, 0));
52 break;
53
54 case LAYER_BG:
55 setLayer_bg(line);
56 break;
57
58 case LAYER_LV:
59 setLayer_lv(line);
60 break;
61 }
62
63 }
64 }
65 else
66 {
67 }
68 file.close();
69}
70
71void LevelManager::unload()
72{
73 al_destroy_bitmap(tileset);
74}
75
76void LevelManager::render()
77{
78 int w = al_get_bitmap_width(tileset) / blockSize;
79 int x, y;
80
81// LAYER BACKGROUND
82 for(int i = 0; i < layer_bg.size(); i++)
83 {
84 for(int j = 0; j < layer_bg[i].size(); j++)
85 {
86 x = ((layer_bg[i][j] % w) * blockSize) - blockSize;
87 y = (layer_bg[i][j] / w) * blockSize;
88 al_draw_bitmap_region(tileset, x, y, blockSize, blockSize, j * blockSize, i * blockSize, NULL);
89 }
90 }
91
92// LAYER LEVEL
93 for(int i = 0; i < layer_lv.size(); i++)
94 {
95 for(int j = 0; j < layer_lv[i].size(); j++)
96 {
97 x = ((layer_lv[i][j] % w) * blockSize) - blockSize;
98 y = (layer_lv[i][j] / w) * blockSize;
99 al_draw_bitmap_region(tileset, x, y, blockSize, blockSize, j * blockSize, i * blockSize, NULL);
100 }
101 }
102}
103
104void LevelManager::setLayer_bg(std::string line)
105{
106 std::string value;
107 std::stringstream str(line);
108 std::vector<int>tempVector;
109
110 while(!str.eof())
111 {
112 std::getline(str, value, ',');
113 if(value.length() > 0)
114 tempVector.push_back(atoi(value.c_str()));
115 }
116 layer_bg.push_back(tempVector);
117}
118
119void LevelManager::setLayer_lv(std::string line)
120{
121 std::string value;
122 std::stringstream str(line);
123 std::vector<int>tempVector;
124
125 while(!str.eof())
126 {
127 std::getline(str, value, ',');
128 if(value.length() > 0)
129 tempVector.push_back(atoi(value.c_str()));
130 }
131 layer_lv.push_back(tempVector);
132}
Its simple load the map from a txt file and the render function is called every loop to draw the map.
|
Werwolf696
Member #15,203
June 2013
|
Can you post the code that calls your level manager render routine? |
Gabriel Campos
Member #12,034
June 2010
|
1#include "SceneGame.h"
2
3SceneGame::SceneGame()
4{
5}
6
7SceneGame::~SceneGame()
8{
9}
10
11void SceneGame::load()
12{
13 player.load();
14 levelManager.load("Data/Levels/level00.txt");
15 //music = al_load_sample("Data/Sounds/01_level.ogg");
16 //al_play_sample(music, 1, 0, 1, ALLEGRO_PLAYMODE_LOOP, NULL);
17}
18
19void SceneGame::unload()
20{
21 player.unload();
22 levelManager.unload();
23 //al_destroy_sample(music);
24}
25
26void SceneGame::input(ALLEGRO_EVENT *event)
27{
28 if(inputManager.isKeyPressed(event, ALLEGRO_KEY_Z))
29 Engine::instance().changeScene(new SceneTitle());
30
31 player.input(event);
32}
33
34void SceneGame::logic()
35{
36 player.logic();
37}
38
39void SceneGame::render()
40{
41 levelManager.render();
42 player.render();
43}
|
l j
Member #10,584
January 2009
|
For one you're drawing the whole map completely regardless of how much of it is visible, which might be a problem if your map is Before drawing the tilemap call al_hold_bitmap_drawing(true) and after drawing call al_hold_bitmap_drawing(false). The manual gives a more in-depth explanation of why and when to use it.
|
|
1
2
|