cassius Posted September 12, 2012 Posted September 12, 2012 Hi I am returning to c after a long absence and would like a few tips on how best to code. How much of my actual gameplay code should go in main; At the moment I have all functions in an include file and it works ok; So am I on the right lines? Thanks. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++
Daimour Posted September 13, 2012 Posted September 13, 2012 I think there is no strict rule here. Make as you comfortable to work with. I would try to keep main() as simple as possible. Something like this (pseudo): void main() { InitGraphics(); while(!AppTerminate()) { UpdateWorld(); UpdatePhysics(); Render(); } } Considering files, you can split your code as you want. It's better to split functions to different files if: - you want to group similar functions in "class" manner; - you want to reduce compile time changing little parts of code; - you want to work with teammates on your code and/or use VCS (version control system) with file locking; - you want to separate rarely modified code from often modified; - and many other reasons. Otherwise you can hold all your functions in one big file. I use this approach while project is tiny. But since it's grown I make refactoring and split functions to different files. Quote
cassius Posted September 13, 2012 Author Posted September 13, 2012 Thanks Daimour. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++
Canardia Posted September 13, 2012 Posted September 13, 2012 It makes sense to keep the main file as small as possible, because everything you put in there, can not be directly included into other projects. Try to keep all reusable (somewhat standalone) code in their own .cpp and .h files, so you can choose which features you want in your other projects. 3 Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■
Roland Posted September 13, 2012 Posted September 13, 2012 Well said Metadron Quote Roland Strålberg Website: https://rstralberg.com
cassius Posted September 13, 2012 Author Posted September 13, 2012 Interesting. Thanks. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.