Linux packages for MeAndMyShadow

Re: Linux packages for MeAndMyShadow

Postby MCMic » 25 Apr 2011, 19:50

You should look into the code of Slime Volley or DivideAndSucceed. In both I store information in the home folder.

It looks like this :
{l Code}: {l Select All Code}
#ifdef WINDOWS
   #define CONFIG_NOM "slime.ini"
   #define SEP "\\"
   #define DOSS_PREFS "USERPROFILE"
#else
   #ifdef MACOS9
      #define CONFIG_NOM "Slime Volley Prefs"
   #else
      #define CONFIG_NOM ".slime"
      #define SEP "/"
      #define DOSS_PREFS "HOME"
   #endif
#endif

char conf_chemin[64] = CONFIG_NOM;

And then for open it :
{l Code}: {l Select All Code}
#ifndef MACOS9
   if(getenv(DOSS_PREFS) != NULL) {
      conf_chemin[0] = '\0';
      strncat(conf_chemin, getenv(DOSS_PREFS), sizeof(conf_chemin));
      strncat(conf_chemin, SEP, sizeof(conf_chemin));
      strncat(conf_chemin, CONFIG_NOM, sizeof(conf_chemin));
   }
#endif

   config_fich = fopen(conf_chemin, "rb");


That's from Slime Volley so it's C, but it works in C++.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Linux packages for MeAndMyShadow

Postby MCMic » 25 Apr 2011, 19:53

For divide and succeed, the define part is the same, but I adapted for C++ the openning part :

{l Code}: {l Select All Code}
config_filename = CONFIG_FILE;
   
#ifndef MACOS9
   if(getenv(PREF_FOLDER) != NULL) {
      stringstream ss;
      ss << getenv(PREF_FOLDER) << SEP << CONFIG_FILE;
      config_filename = ss.str();
   }
#endif
   ifstream conf_file(config_filename.c_str(), ios::in);
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Linux packages for MeAndMyShadow

Postby acme_pjz » 26 Apr 2011, 11:16

Hi MCMic,

MCMic {l Wrote}:You should look into the code of Slime Volley or DivideAndSucceed. In both I store information in the home folder.

...


Did you read my code and test it? I admitted that I don't know about MacOS, and I don't have any machine installed MacOS :| ... So could you add a MacOS case of code?

But I think the Windows and Linux code is (more or less) no problem ... IMHO saving the config file in /home/<username>/.meandmyshadow/ is OK, because some other games (for example X-Moto, Scorched3D) do the same things, too ...
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 665
Joined: 10 Dec 2009, 15:32
Location: PeeKing, China

Re: Linux packages for MeAndMyShadow

Postby Edward_Lii » 26 Apr 2011, 16:29

Hello all,

I've just uploaded a source package of version 0.1.1, it contains an icon I made quickly, just the main character with some black squares behind him. :p
When running `make install` it will place an .desktop file in /usr/share/applications this way the icon will appear in both the KDE and GNOME menu.

acme_pjz {l Wrote}:Did you read my code and test it? I admitted that I don't know about MacOS, and I don't have any machine installed MacOS :| ... So could you add a MacOS case of code?

But I think the Windows and Linux code is (more or less) no problem ... IMHO saving the config file in /home/<username>/.meandmyshadow/ is OK, because some other games (for example X-Moto, Scorched3D) do the same things, too ...

I agree, it seems to work correctly with exception of MacOS X most likely.

I'll build packages with the new source package. ;)
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Re: Linux packages for MeAndMyShadow

Postby KroArtem » 26 Apr 2011, 17:14

While you're discussing package problems here, M&MS doesn't work under ubuntu 11.04, it loads 200% of cpu, all ram and a bit of swap :(
KroArtem
 
Posts: 375
Joined: 26 Aug 2010, 19:04

Re: Linux packages for MeAndMyShadow

Postby MCMic » 26 Apr 2011, 17:15

Sorry, I thought you didn't know how to code the config file part, I must have read too fast the blog posts.
Yeah, the code seems correct for GNU/Linux (the one in the else).

I don't have any Mac OS either for test.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Linux packages for MeAndMyShadow

Postby Edward_Lii » 26 Apr 2011, 17:22

Hello KroArtem,

KroArtem {l Wrote}:While you're discussing package problems here, M&MS doesn't work under ubuntu 11.04, it loads 200% of cpu, all ram and a bit of swap :(

Which version did you try, 0.1, 0.1.1 or from SVN and what is displayed when you run it in terminal?
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Re: Linux packages for MeAndMyShadow

Postby MCMic » 26 Apr 2011, 17:24

Edward_Lii {l Wrote}:Hello all,

I've just uploaded a source package of version 0.1.1, it contains an icon I made quickly, just the main character with some black squares behind him. :p
When running `make install` it will place an .desktop file in /usr/share/applications this way the icon will appear in both the KDE and GNOME menu.

You put all the .svn folders in the archive.

And the game's not working on my computer, it segfaults after installation, and the svn version freezes when I go into the level selection menu.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Linux packages for MeAndMyShadow

Postby Edward_Lii » 26 Apr 2011, 17:43

Hello MCMic,

MCMic {l Wrote}:You put all the .svn folders in the archive.

Oops, I forgot to run svn export! :o
Uploaded new version without the hidden .svn folders.

MCMic {l Wrote}:And the game's not working on my computer, it segfaults after installation, and the svn version freezes when I go into the level selection menu.

How did you compile it, I tried to reproduce your problem by running the following commands:
{l Code}: {l Select All Code}
cmake . && make

When you run the executable meandmyshadow afterwards it can't find the data and somehow stresses the CPU.
This can result in an X server crash, freezing the whole computer until you reboot.

KroArtem {l Wrote}:While you're discussing package problems here, M&MS doesn't work under ubuntu 11.04, it loads 200% of cpu, all ram and a bit of swap :(

This is most likely caused by meandmyshadow unable to find the data files.
It's important that we find out what's causing this!
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Re: Linux packages for MeAndMyShadow

Postby MCMic » 26 Apr 2011, 17:45

I'm first trying to debug the crash of the svn version, it seems when I clic on the first level, the loop at line POASerializer.cpp:109 is infinite.

About the crash of the 0.1.1 installed version, I did cmake, make and make install and gdb says it segfault in GetUserPath.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Linux packages for MeAndMyShadow

Postby KroArtem » 26 Apr 2011, 18:10

Which version did you try, 0.1, 0.1.1 or from SVN and what is displayed when you run it in terminal?

I'm using the version from SVN and I don't have anything in terminal. Is there any option to compile M&MS with debug support?
KroArtem
 
Posts: 375
Joined: 26 Aug 2010, 19:04

Re: Linux packages for MeAndMyShadow

Postby acme_pjz » 27 Apr 2011, 06:20

Hi,

KroArtem {l Wrote}:While you're discussing package problems here, M&MS doesn't work under ubuntu 11.04, it loads 200% of cpu, all ram and a bit of swap :(

MCMic {l Wrote}: ... , and the svn version freezes when I go into the level selection menu.


Where did you encounter this bug? If it's after clicking "Game", I think probably the game couldn't find level list, and there is a bug in Level::Level() so it runs into an infinite loop and add items to vector infinitely ...

MCMic {l Wrote}:And the game's not working on my computer, it segfaults after installation

MCMic {l Wrote}:About the crash of the 0.1.1 installed version, I did cmake, make and make install and gdb says it segfault in GetUserPath.


I searched in Internet and write some code about getting user path under Linux:

{l Code}: {l Select All Code}
std::string GetUserPath(){
   if(m_sUserPath[0]) return m_sUserPath;   <--- (1)
#ifdef WIN32
   ...
#else
   m_sUserPath=getenv("HOME");   <--- (2)
   m_sUserPath+="/.meandmyshadow/";
   mkdir(m_sUserPath.c_str(),0777);
#endif
   return m_sUserPath;
}


I think either (1) or (2) can cause the bug, but I think std::string will initialized with empty string ("\0") automatically, and it works correctly under Windows ... and if getenv("HOME") returns NULL then (2) is buggy (again, I'm not familiar with Linux so I don't know whether getenv("HOME") is a correct code :| )

MCMic {l Wrote}:I'm first trying to debug the crash of the svn version, it seems when I clic on the first level, the loop at line POASerializer.cpp:109 is infinite.


I have no idea about this because POASerializer.cpp:109 is while(!fin.eof()) in ReadNode and function LoadNodeFromFile calls ReadNode, after checking the file is actually open. Maybe there is hidden bug in ReadNode but I can't figure it out :(

KroArtem {l Wrote}:
Which version did you try, 0.1, 0.1.1 or from SVN and what is displayed when you run it in terminal?

I'm using the version from SVN and I don't have anything in terminal. Is there any option to compile M&MS with debug support?


I'm sorry that currently there is no console output code in the game :(
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 665
Joined: 10 Dec 2009, 15:32
Location: PeeKing, China

Re: Linux packages for MeAndMyShadow

Postby MCMic » 27 Apr 2011, 07:32

The problem is "if(m_sUserPath[0]) return m_sUserPath;"
What is this line supposed to do?

I think something like if(!m_sUserPath.empty()) would work if that's what you're trying to test.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Linux packages for MeAndMyShadow

Postby acme_pjz » 27 Apr 2011, 08:19

MCMic {l Wrote}:The problem is "if(m_sUserPath[0]) return m_sUserPath;"
What is this line supposed to do?

I think something like if(!m_sUserPath.empty()) would work if that's what you're trying to test.


You're right :| , if(!m_sUserPath.empty()) is better ... and I think the initialization code should go to another function (for example when the game starts), and GetUserPath simply returns a path ...
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 665
Joined: 10 Dec 2009, 15:32
Location: PeeKing, China

Re: Linux packages for MeAndMyShadow

Postby Edward_Lii » 27 Apr 2011, 14:28

Hello acme_pjz,

When I updated to the latest revision I encountered a compile error:
{l Code}: {l Select All Code}
...
/home/edward/Programming/MeAndMyShadow/src/POASerializer.cpp: In member function ‘virtual void POASerializer::WriteNode(ITreeStorageReader*, std::ostream&, bool, bool)’:
/home/edward/Programming/MeAndMyShadow/src/POASerializer.cpp:324:6: error: ‘fin’ was not declared in this scope
...

When looking at that line I assume you meant to check (!fout) and not (!fin).
So I committed it and now compiling works for me, and the infinite loop has gone! Good work! :)

acme_pjz {l Wrote}:I think either (1) or (2) can cause the bug, but I think std::string will initialized with empty string ("\0") automatically, and it works correctly under Windows ... and if getenv("HOME") returns NULL then (2) is buggy (again, I'm not familiar with Linux so I don't know whether getenv("HOME") is a correct code :| )

AFAIK using getenv("HOME") should work, although it's not recommended by some since the user can change this environment variable.
But I can't think of any other way to retrieve the users home directory.
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Re: Linux packages for MeAndMyShadow

Postby MCMic » 27 Apr 2011, 14:55

No, it IS the good way to retrieve the user home directory, especially because the user can change it! If he changes it, it means that he want to change the folder in which preferences are stored.

About my problem, it seems meandmyshadow try to read from the installation directory even if I don't install it :
{l Code}: {l Select All Code}
Error: Can't load level list /usr/local/share/meandmyshadow/data/level/levellist.txt
ERROR: Can't open image file /usr/local/share/meandmyshadow/data/gfx/dark.png
ERROR: Can't open image file /usr/local/share/meandmyshadow/data/gfx/black.png
ERROR: Can't open image file /usr/local/share/meandmyshadow/data/gfx/menu/menu.png


(I just did cmake . and make, the game should work without doing make install)
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Linux packages for MeAndMyShadow

Postby Edward_Lii » 27 Apr 2011, 15:09

Hello MCMic,

MCMic {l Wrote}:No, it IS the good way to retrieve the user home directory, especially because the user can change it! If he changes it, it means that he want to change the folder in which preferences are stored.

Oh, that makes sence, can't remember where but I read that it wasn't recommended. :?

MCMic {l Wrote}:(I just did cmake . and make, the game should work without doing make install)

I agree, but how should this be implemented, in the config.h.in file it uses this:
{l Code}: {l Select All Code}
#ifndef CONFIG_H
#define CONFIG_H

#ifdef WIN32
#define DATA_PATH
#else
#define DATA_PATH "@CMAKE_INSTALL_PREFIX@/share/meandmyshadow/"
#endif

We can't just change it to "./" or something since then the system install will be unable to find it's files.
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Re: Linux packages for MeAndMyShadow

Postby MCMic » 27 Apr 2011, 15:12

No idea, for divideAndSucceed I chose to make a list of folders and I search for the files in each of them.
So in my CMakeFiles.txt file I have :
add_definitions(-DDATA_DIR=".:${CMAKE_INSTALL_PREFIX}/share/divideandsucceed/")

':' is the separator, '.' is the current folder.
I'm not sure it's the best solution, but it's the one I used ^^
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Linux packages for MeAndMyShadow

Postby acme_pjz » 27 Apr 2011, 15:16

MCMic {l Wrote}:No, it IS the good way to retrieve the user home directory, especially because the user can change it! If he changes it, it means that he want to change the folder in which preferences are stored.

About my problem, it seems meandmyshadow try to read from the installation directory even if I don't install it :
{l Code}: {l Select All Code}
Error: Can't load level list /usr/local/share/meandmyshadow/data/level/levellist.txt
ERROR: Can't open image file /usr/local/share/meandmyshadow/data/gfx/dark.png
ERROR: Can't open image file /usr/local/share/meandmyshadow/data/gfx/black.png
ERROR: Can't open image file /usr/local/share/meandmyshadow/data/gfx/menu/menu.png


(I just did cmake . and make, the game should work without doing make install)


Please check config.h.in and config.h, cnrrently under Linux the DATA_PATH is configured to the install path you specified. If you want to run game directly you should change
{l Code}: {l Select All Code}
#define DATA_PATH "/some/path/"
to
{l Code}: {l Select All Code}
#define DATA_PATH


I think maybe we can add an option to CMakeFiles.txt which enables DATA_PATH to current directory ...
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 665
Joined: 10 Dec 2009, 15:32
Location: PeeKing, China

Re: Linux packages for MeAndMyShadow

Postby Edward_Lii » 27 Apr 2011, 15:53

Hello acme_pjz,

acme_pjz {l Wrote}:I think maybe we can add an option to CMakeFiles.txt which enables DATA_PATH to current directory ...

I'm not sure that's such a good idea.
Currently we can only have one DATA_PATH specified, if we choose the current directory a system wide install will fail to find the data files.
We could however set it to the current directory and change the .desktop files to run `cd /usr/share/meandmyshadow/ && meandmyshadow`.
The downside of this is that when someone wants to see if there are error messages he will most probably only run `meandmyshadow`.

MCMic {l Wrote}:No idea, for divideAndSucceed I chose to make a list of folders and I search for the files in each of them.
So in my CMakeFiles.txt file I have :
add_definitions(-DDATA_DIR=".:${CMAKE_INSTALL_PREFIX}/share/divideandsucceed/")

':' is the separator, '.' is the current folder.
I'm not sure it's the best solution, but it's the one I used ^^

The program will look in two folders if it isn't in the first one, but that isn't that big problem.
Maybe we should implement it the same way?
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Re: Linux packages for MeAndMyShadow

Postby KroArtem » 27 Apr 2011, 17:49

I don't know whether this'll be useful for you, but:
http://pastebin.com/7AV0m8vJ
KroArtem
 
Posts: 375
Joined: 26 Aug 2010, 19:04

Re: Linux packages for MeAndMyShadow

Postby acme_pjz » 28 Apr 2011, 07:27

Hi all,

Edward_Lii {l Wrote}:
MCMic {l Wrote}:No idea, for divideAndSucceed I chose to make a list of folders and I search for the files in each of them.
So in my CMakeFiles.txt file I have :
add_definitions(-DDATA_DIR=".:${CMAKE_INSTALL_PREFIX}/share/divideandsucceed/")

':' is the separator, '.' is the current folder.
I'm not sure it's the best solution, but it's the one I used ^^

The program will look in two folders if it isn't in the first one, but that isn't that big problem.
Maybe we should implement it the same way?


If we search multi folders, we need to change every file open statement :| I think it's a bit ugly ... or we need a FileManager?

I have a bad idea: when the program is starting, first it get its path (using readlink("/proc/self/exe")), then ckeck if its path is equal to install path ... if it's true then loading data files from DATA_PATH, otherwise loading data files from current directory ...

Of course, we can add a command line options to customize data directory ...

To KroArtem :

Are there some data files in /usr/local/share/meandmyshadow/data/ ? If there aren't data files, then the program can't load image files, the function will return NULL, then the program crashes ...
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 665
Joined: 10 Dec 2009, 15:32
Location: PeeKing, China

Re: Linux packages for MeAndMyShadow

Postby MCMic » 28 Apr 2011, 20:47

You can also put the path of the data folder in the config file.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: Linux packages for MeAndMyShadow

Postby acme_pjz » 29 Apr 2011, 11:39

MCMic {l Wrote}:You can also put the path of the data folder in the config file.


Good idea. But we need to create a config file when installing the game, which I don't know how to write CMake scripts :| ...
Some of my open source games on GitHub
User avatar
acme_pjz
 
Posts: 665
Joined: 10 Dec 2009, 15:32
Location: PeeKing, China

Re: Linux packages for MeAndMyShadow

Postby Edward_Lii » 29 Apr 2011, 13:35

Hello acme_pjz,

acme_pjz {l Wrote}:Good idea. But we need to create a config file when installing the game, which I don't know how to write CMake scripts :| ...

I think this is the best solution so far.
The config file should be placed inside the ~/.meandmyshadow/ folder, maybe it can contain more settings like sound enabled?

The question is what will be the default value?
And I think it should be able to changes this with a parameter, something like this:
{l Code}: {l Select All Code}
meandmyshadow --data-dir /usr/share/meandmyshadow
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Who is online

Users browsing this forum: No registered users and 1 guest