• Advertisement

C++ Portability and Resource Usage (SFML)

Recommended Posts

SFML is portable on windows Linux and Mac.  So a game created on Windows to be ported to Mac must be compiled on that computer using portable C++ code?

Another problem/question that is more specific:

I am writing a game using Windows C++ and SFML.  Using a resource for the image seems to be possible, but I will have to alter the code when porting because this 'belongs to' Window's Visual Studio C++?  

The other option is to keep the images in a folder that would be viewable and loadable.  This I think would run on Linux and Macintosh.  It just doesn't seem to be to professional.  Any advice?

Thank you,

Josheir

Edited by Josheir

Share this post


Link to post
Share on other sites
Advertisement

C++ is generic. If you're writing code using the window's APIs then that code will need to be modified to use platform agnostic APIs or separated out and rewritten per platform you desire to support.

Regarding resources: OS-X applications have a bundling method, and basically it just uses directories. that are hidden under an application folder. Installation is usually just copying said folder (whose name is usually the name of your application) into the applications folder.

For many games, resources are packaged up into binary bundles which are frequently compressed simply to shrink download sizes and or to "pretend-encrypt" the files. For general development purposes I wouldn't bother until you're actually deciding to ship, but you should definitely be able to use said code paths during development simply for testing. It is also useful as a means of providing demos during development, as you can bundle all of the assets necessary for the demo.

Share this post


Link to post
Share on other sites

But you will need a Linux and MacOS X box/VM to compile your code on for those platforms.  Though I've not played with it, Visual Studios apparently can do all 3 these days but you need a registered Mac machine (on your network) with an Apple Developers license to do so. 

You can also place your files inside a .zip file and use something like zlib (which works on all 3 platforms) to get your art/sound/model assets out of it.

Share this post


Link to post
Share on other sites

You might consider shipping your assets using a virtual file system.  There are readily available ones out there.

There is nothing unprofessional about shipping your assets with your game.  I've played a number of AAA games that do that.

Share this post


Link to post
Share on other sites

just picture?

I hope you use “RGB image”, get decoding data of coded images.

Now, developing codec on different platforms.

Share this post


Link to post
Share on other sites
1 hour ago, dream rz said:

just picture?

I hope you use “RGB image”, get decoding data of coded images.

Now, developing codec on different platforms.

Ummm... What?  Sorry, your post didn't make sense in English (which I assume is not your first language).

There are plenty of libraries available that are cross platform.  stb comes to mind: https://github.com/nothings/stb

But there are plenty of others.  You do not have to develop "codec"s on different platforms, codecs typically refer to video/movie decoding anyway.  Or just picking one format (easy enough to convert them to all to one) and use it's lib (libpng, libjpeg, etc).

Share this post


Link to post
Share on other sites
14 hours ago, Josheir said:

So a game created on Windows to be ported to Mac must be compiled on that computer using portable C++ code?

Yes or a compiler targeting for that system. The C++ source code is the portable bit and not the .o, .lib and .exe files the compiler generates.

As for loading image files.  Agree with what has already been said.  For portability, some kind of virtual file system will help. Either use someone else's or write your own, it doesn't have to be that complicated.

The point is, in your game code you must not make assumptions about where your resource (files) originate from. Keep your reading and writing wrapped in some class.

void LoadGameInfo()
{
	CMemoryBlock* myBlock = myVirtualFileSystem.LoadFile("mydata.dat");
	..

On your PC version of the virtual file system class, it would be loading the file via fopen() / fread() calls, and on Android it would look more like  AAssetManager_open() /  AAsset_read() etc.

Also on portability, PLEASE DO NOT end up with code littered like this

#ifdef _WIN32
...
#elif __APPLE__
...
#elif __linux__
..
#elif __ANDROID__
...
#elif __IOS__
...
#endif

The code will soon become a mess and in a years time you won't understand it.  If you design your game/engine properly you can cut this type of code down to virtually none, even in low level classes like virtual files systems.

Share this post


Link to post
Share on other sites
8 hours ago, desiado said:

As for loading image files.  Agree with what has already been said.  For portability, some kind of virtual file system will help. Either use someone else's or write your own, it doesn't have to be that complicated.

Agreed. I have an engine written in C++ that uses a virtual file system that I created. I created a packing program in C# that generates a custom binary format which packs images, audio, XML, and shaders (really the packing program can pack any file type). The generated file contains blocks of data identifying the name of the file and source contents.

This file can then either be embedded in the EXE, IPA, APK, etc. or it can be included alongside the deliverable and loaded at runtime (I believe in my current implementation, it is loaded at runtime.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By francoisdiy
      So I wrote a programming language called C-Lesh to program games for my game maker Platformisis. It is a scripting language which tiles into the JavaScript game engine via a memory mapper using memory mapped I/O. Currently, I am porting the language as a standalone interpreter to be able to run on the PC and possibly other devices excluding the phone. The interpreter is being written in C++ so for those of you who are C++ fans you can see the different components implemented. Some background of the language and how to program in C-Lesh can be found here:

      http://www.codeloader.net/readme.html
      As I program this thing I will post code from different components and explain.
    • By Manuel Berger
      Hello fellow devs!
      Once again I started working on an 2D adventure game and right now I'm doing the character-movement/animation. I'm not a big math guy and I was happy about my solution, but soon I realized that it's flawed.
      My player has 5 walking-animations, mirrored for the left side: up, upright, right, downright, down. With the atan2 function I get the angle between player and destination. To get an index from 0 to 4, I divide PI by 5 and see how many times it goes into the player-destination angle.

      In Pseudo-Code:
      angle = atan2(destination.x - player.x, destination.y - player.y) //swapped y and x to get mirrored angle around the y axis
      index = (int) (angle / (PI / 5));
      PlayAnimation(index); //0 = up, 1 = up_right, 2 = right, 3 = down_right, 4 = down

      Besides the fact that when angle is equal to PI it produces an index of 5, this works like a charm. Or at least I thought so at first. When I tested it, I realized that the up and down animation is playing more often than the others, which is pretty logical, since they have double the angle.

      What I'm trying to achieve is something like this, but with equal angles, so that up and down has the same range as all other directions.

      I can't get my head around it. Any suggestions? Is the whole approach doomed?

      Thank you in advance for any input!
       
    • By isu diss
      I'm trying to duplicate vertices using std::map to be used in a vertex buffer. I don't get the correct index buffer(myInds) or vertex buffer(myVerts). I can get the index array from FBX but it differs from what I get in the following std::map code. Any help is much appreciated.
      struct FBXVTX { XMFLOAT3 Position; XMFLOAT2 TextureCoord; XMFLOAT3 Normal; }; std::map< FBXVTX, int > myVertsMap; std::vector<FBXVTX> myVerts; std::vector<int> myInds; HRESULT FBXLoader::Open(HWND hWnd, char* Filename, bool UsePositionOnly) { HRESULT hr = S_OK; if (FBXM) { FBXIOS = FbxIOSettings::Create(FBXM, IOSROOT); FBXM->SetIOSettings(FBXIOS); FBXI = FbxImporter::Create(FBXM, ""); if (!(FBXI->Initialize(Filename, -1, FBXIOS))) { hr = E_FAIL; MessageBox(hWnd, (wchar_t*)FBXI->GetStatus().GetErrorString(), TEXT("ALM"), MB_OK); } FBXS = FbxScene::Create(FBXM, "REALMS"); if (!FBXS) { hr = E_FAIL; MessageBox(hWnd, TEXT("Failed to create the scene"), TEXT("ALM"), MB_OK); } if (!(FBXI->Import(FBXS))) { hr = E_FAIL; MessageBox(hWnd, TEXT("Failed to import fbx file content into the scene"), TEXT("ALM"), MB_OK); } FbxAxisSystem OurAxisSystem = FbxAxisSystem::DirectX; FbxAxisSystem SceneAxisSystem = FBXS->GetGlobalSettings().GetAxisSystem(); if(SceneAxisSystem != OurAxisSystem) { FbxAxisSystem::DirectX.ConvertScene(FBXS); } FbxSystemUnit SceneSystemUnit = FBXS->GetGlobalSettings().GetSystemUnit(); if( SceneSystemUnit.GetScaleFactor() != 1.0 ) { FbxSystemUnit::cm.ConvertScene( FBXS ); } if (FBXI) FBXI->Destroy(); FbxNode* MainNode = FBXS->GetRootNode(); int NumKids = MainNode->GetChildCount(); FbxNode* ChildNode = NULL; for (int i=0; i<NumKids; i++) { ChildNode = MainNode->GetChild(i); FbxNodeAttribute* NodeAttribute = ChildNode->GetNodeAttribute(); if (NodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh* Mesh = ChildNode->GetMesh(); if (UsePositionOnly) { NumVertices = Mesh->GetControlPointsCount();//number of vertices MyV = new XMFLOAT3[NumVertices]; for (DWORD j = 0; j < NumVertices; j++) { FbxVector4 Vertex = Mesh->GetControlPointAt(j);//Gets the control point at the specified index. MyV[j] = XMFLOAT3((float)Vertex.mData[0], (float)Vertex.mData[1], (float)Vertex.mData[2]); } NumIndices = Mesh->GetPolygonVertexCount();//number of indices MyI = (DWORD*)Mesh->GetPolygonVertices();//index array } else { FbxLayerElementArrayTemplate<FbxVector2>* uvVertices = NULL; Mesh->GetTextureUV(&uvVertices); int idx = 0; for (int i = 0; i < Mesh->GetPolygonCount(); i++)//polygon(=mostly triangle) count { for (int j = 0; j < Mesh->GetPolygonSize(i); j++)//retrieves number of vertices in a polygon { FBXVTX myVert; int p_index = 3*i+j; int t_index = Mesh->GetTextureUVIndex(i, j); FbxVector4 Vertex = Mesh->GetControlPointAt(p_index);//Gets the control point at the specified index. myVert.Position = XMFLOAT3((float)Vertex.mData[0], (float)Vertex.mData[1], (float)Vertex.mData[2]); FbxVector4 Normal; Mesh->GetPolygonVertexNormal(i, j, Normal); myVert.Normal = XMFLOAT3((float)Normal.mData[0], (float)Normal.mData[1], (float)Normal.mData[2]); FbxVector2 uv = uvVertices->GetAt(t_index); myVert.TextureCoord = XMFLOAT2((float)uv.mData[0], (float)uv.mData[1]); if ( myVertsMap.find( myVert ) != myVertsMap.end() ) myInds.push_back( myVertsMap[ myVert ]); else { myVertsMap.insert( std::pair<FBXVTX, int> (myVert, idx ) ); myVerts.push_back(myVert); myInds.push_back(idx); idx++; } } } } } } } else { hr = E_FAIL; MessageBox(hWnd, TEXT("Failed to create the FBX Manager"), TEXT("ALM"), MB_OK); } return hr; } bool operator < ( const FBXVTX &lValue, const FBXVTX &rValue) { if (lValue.Position.x != rValue.Position.x) return(lValue.Position.x < rValue.Position.x); if (lValue.Position.y != rValue.Position.y) return(lValue.Position.y < rValue.Position.y); if (lValue.Position.z != rValue.Position.z) return(lValue.Position.z < rValue.Position.z); if (lValue.TextureCoord.x != rValue.TextureCoord.x) return(lValue.TextureCoord.x < rValue.TextureCoord.x); if (lValue.TextureCoord.y != rValue.TextureCoord.y) return(lValue.TextureCoord.y < rValue.TextureCoord.y); if (lValue.Normal.x != rValue.Normal.x) return(lValue.Normal.x < rValue.Normal.x); if (lValue.Normal.y != rValue.Normal.y) return(lValue.Normal.y < rValue.Normal.y); return(lValue.Normal.z < rValue.Normal.z); }  
    • By Terry Jin
      Hi everyone! 

      I am from an indie studio that has received funding for our concept and is ready to create the next generation 2D Pokemon-inspired MMORPG called Phantasy World. This ad is for a volunteer position but hopefully will transition into something more. Our vision is to create a game that draws inspiration from the series but is dramatically different in both aesthetics and gameplay as the work would be our own.
       
      We are hoping that you can help us make this a reality and are looking for game developers familiar with the unreal engine and would be happy to work on a 2D top down game. Sprite artists are also welcome as we are in desperate need of talented artists! Join our discord and let's have a chat! https://discord.gg/hfDxwDX

      Here's some of our in game sprites for playable characters while moving around the game world! Hope to see you soon!
       


    • By Sean Meredith
      Hi all, I am starting to develop a tactics game and ran into a problem I had not thought of. I began by drawing a screen with a hex grid, and this is no big deal. I got that working fine. But, I realized it didn't look quite right. This is because in most strategy games, you're not looking straight down. There is a bit of a tilt. Attached is an example of what I mean. The hexagons on bottom are larger than the hexagons on top, and I'm unsure of how to go about adding this effect. Especially when you consider that some maps may be of different sizes. 
      I'm not sure if this is the right place to post something like this, but it seems as though some sort of linear transformation would be applied? No? I don't even know where to begin in a problem like this.
      Thanks.

  • Advertisement