Hi guy, I am making a RPG with SFML and window forms + C#'s picturebox toolbox. So umh, at the moment all my code run properly, they work as intended, but they are really slow;
Im not sure if it because of the way I code it, but my Tile Engine's Tile placement is extremely slow. Sometime it take up to 3 sec of unresponsive before the tile is actually placed. Sometime the program even crash from "not enough memory" and also crash my facebook messager skype and chrome. I am not an expert programmer, just a hobbyist so I do not have any knowledge on code optimization and such, so dont judge me on that. Here is the 2 functions that I think should have something to deal with the speed issue:
//The MapViewer class (which is abbreviated mv)public void Render
() { _mapWindow
.Clear(); foreach (TileLayer tl
in _map
.myLayer) { foreach (Tile t
in tl
.myTile) { Texture tx
= new Texture
(Editor
.Instance.curGame.GM.myResource[Editor
.Instance.curGame.TM.myTileset[t
.TS].ID].myTexture); Sprite sp
= new Sprite
(tx,
new IntRect
(t
.srcX * Editor
.Instance.curGame.TileX, t
.srcY * Editor
.Instance.curGame.TileY, t
.Width, t
.Height)); sp
.Position = new Vector2f
(t
.plcX * Editor
.Instance.curGame.TileX, t
.plcY * Editor
.Instance.curGame.TileY); _mapWindow
.Draw(sp
); } } _mapWindow
.Display(); }//In the actual form:private void picMapViewer_Click
(object sender, EventArgs e
) { if (Map
.myLayer.Count <= 0) return; //Editor.Instance.tilesetPick int pickedX
= mv
.getMouseLoc.X + mv
.xOffSet; int pickedY
= mv
.getMouseLoc.Y + mv
.yOffSet; if (pickedX
>= Map
.maxX * 32) pickedX
= Map
.maxX * 32 - 1; if (pickedY
>= Map
.maxY * 32) pickedY
= Map
.maxX * 32 - 1; pickedX
/= 32; pickedY
/= 32; Tile _newTile
= new Tile
(Editor
.Instance.tilesetPick.PickedX, Editor
.Instance.tilesetPick.PickedY, pickedX, pickedY, Editor
.Instance.tilesetPick.CurTS, Editor
.Instance.curGame.TileX, Editor
.Instance.curGame.TileY,
100); if ((int)available
[lstLayer
.SelectedIndex].GetValue(pickedX, pickedY
) < 0) Map
.myLayer[lstLayer
.SelectedIndex].addTile(_newTile
); else Map
.myLayer[lstLayer
.SelectedIndex].addTile(_newTile,
(int)available
[lstLayer
.SelectedIndex].GetValue(pickedX, pickedY
)); available
[lstLayer
.SelectedIndex].SetValue(Map
.myLayer[lstLayer
.SelectedIndex].myTile.Count - 1, pickedX, pickedY
); mv
.Render(); } Here is the program without the source code, try it and see it for yourself:
https://www.dropbox.com/s/3zw1jv7kag59ztq/Debug.rarThank you all