Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualfir

Posted 06 September 2013 - 01:08 AM

(I wrote it in other topic in the context of topic why are global variables bad, but I would change the context of it and just ask how to redesign some piece of my code, so please let me post it here as a question of how to redesign it - maybe I will met some advices - though I am not sure if redesigning it is easy)

 

I got a global shared Sleep value (in miliseconds) which is used in the winapi dispatch messages loop

It is used yet in my some keyboard handlers module so Icould +- it from keayboard (to incrase/decrease fps and corresponding cpu usage)

I can not clearly decide where this variable should belong
to my keyboard handler module or to dispatch messages loop (?) I placed it yet in the third place in globals as far as I remember.

This 3 places is already a mess for me - it become yet worse becouse I had a system of including and excluding some game modules to my system and in such module sometimes I like to overvrite such Sleep value for debug purposes locally, set it 5 in one module to 15 in other I am working on (other way I would must find a global sleep initialisation and change it there so it it is yet worse)

As described above such global shared Sleep is an example of such global shared variable that brings a trouble (As I said before not all globals make such troble, some of them never do for me really and those troubles are more related to way of treating some globals not to all of them )

So how would someone resolve such (global shared) Sleep trouble ?


#2fir

Posted 06 September 2013 - 12:59 AM

(I wrote it in other topic in the context of topic why are global variables bad, but I would change the context of it and just ask how to redesign some piece of my code, so please let me post it here as a question of how to redesign it - maybe I will met some advices - though I am not sure if redesigning it is easy)

 

I got a global shared Sleep value (in miliseconds) which is used in the winapi dispatch messages loop

It is used yet in my some keyboard handlers module so Icould +- it from keayboard (to incrase/decrease fps and corresponding cpu usage)

I can not clearly decide where this variable should belong
to my keyboard handler module or to dispatch messages loop (?) I placed it yet in the third place in globals as far as I remember.

This 3 places is already a mess for me - it become yet worse becouse I had a system of including and excluding some game modules to my system and in such module sometimes I like to overvrite such Sleep value for debug purposes locally, set it 5 in one module to 15 in other I am working on (other way I would must find a initialisation and change it there so it it is yet worse)

As described above such global shared Sleep is an example of such global shared variable that brings a trouble (As I said before not all globals make such troble, some of them never do for me really and those troubles are more related to way of treating some globals not to all of them )

So how would someone resolve such (global shared) Sleep trouble ?


#1fir

Posted 06 September 2013 - 12:57 AM

(I wrote id in other topic in the context of topic why are global variables bad, but I would change the context of it and just ask how to redesign some piece of my code, so please let me post it here as a wuestion of how to redesign it - maybe I will met some advices - though I am not sure if redesigning it is easy)

 

I got a global shared Sleep value (in miliseconds) which is used in the winapi dispatch messages loop

It is used yet in my some keyboard handlers module so Icould +- it from keayboard (to incrase/decrease fps and corresponding cpu usage)

I can not clearly decide where this variable should belong
to my keyboard handler module or to dispatch messages loop (?) I placed it yet in the third place in globals as far as I remember.

This 3 places is already a mess for me - it become yet worse becouse I had a system of including and excluding some game modules to my system and in such module sometimes I like to overvrite such Sleep value for debug purposes locally, set it 5 in one module to 15 in other I am working on (other way I would must find a initialisation and change it there so it it is yet worse)

As described above such global shared Sleep is an example of such global shared variable that brings a trouble (As I said before not all globals make such troble, some of them never do for me really and those troubles are more related to way of treating some globals not to all of them )

So how would someone resolve such (global shared) Sleep trouble ?

 


PARTNERS