Problems Encountered While Developing a Game Engine

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Problems Encountered While Developing a Game Engine

Post by lotios611 »

I have been working on a game engine and have come across a few problems.

Problem #1
In order to be able to use the regular main() function on windows with SDL, you need to use SDLmain.lib. The problem is, I want my engine to be as simple to use as possible, which means that I only want the user to have to link to my engine, and not both my engine and SDLmain.lib. Is there anyway to do this? I'm using VC++ 2008 Express edition, in case that makes any difference.

Problem #2
I would like it if the user does not have to return any values from their main function.

Instead of this:

Code: Select all

#include <cstdio>

int main()
{
        //Code
	return EXIT_SUCCESS;
}
I want the user's main.cpp to look like this:

Code: Select all

#include "Engine.h"

int main()
{
	Engine engine;
}
Is there any way to achieve this?
Last edited by lotios611 on Mon Dec 27, 2010 6:23 pm, edited 1 time in total.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

Re: Game Engine Troubles

Post by MadPumpkin »

Are you saying that you just don't want it to require you to have SDL.dll with the program? Because if so, this is not legal. It discusses this as one of the terms of use on the SDL website.
If you would like you can just build your engine with many SDL specifics and include them in the engine files so that you don't have to in your main, you would still have to have SDL.dll though. But I recommend just doing it the original way.
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: Game Engine Troubles

Post by X Abstract X »

So what are you trying to accomplish? You simply don't want your users to have to return a value or add parameters to their main function? If so, I wrote this really ugly code that will help. I know it's not the ideal solution but it works heh. The obvious downfall as far as user friendliness is concerned is that they have to declare Engine globally and pass in their main function. Maybe someone else can come up with a nicer solution?

But really, why not just let the user define the main function? Surely they know enough to be able to do that? If you're linking against SDL and SDLMain in your Engine I'm pretty sure the user won't have to link to SDLMain.

GameMain.cpp

Code: Select all

#include "Engine.h"

Engine engine(&mainFunction);

void mainFunction() {
    bool gameRunning = true;

    while (gameRunning)
        engine.doSomethingCool();
}
EngineMain.cpp

Code: Select all

#include "Engine.h"

int main(int argc, char* argv[]) {
    if (Engine::newestInstance())
        Engine::newestInstance()->run();

    return 0;
}
Engine.h

Code: Select all

#ifndef Engine_h
#define Engine_h

void mainFunction();

class Engine {
private:
    void (*_mainFunction)();

    static Engine* _newestInstance;

public:
    Engine(void (*mainFunction)());
    ~Engine() {}

    void doSomethingCool();
    void run();

    static Engine* newestInstance() {
        return _newestInstance;
    }
};

#endif
Engine.cpp

Code: Select all

#include "Engine.h"
#include <iostream>

Engine* Engine::_newestInstance = 0;

Engine::Engine(void (*mainFunction)()) : _mainFunction(mainFunction) {
    _newestInstance = this;
}

void Engine::doSomethingCool()  {
    std::cout << "Hello World!\n";
}

void Engine::run() {
    (*_mainFunction)();
}
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Game Engine Troubles

Post by lotios611 »

I can live with the user having to return a value in main(), the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error:
LINK : fatal error LNK1561: entry point must be defined
This is my main.cpp:

Code: Select all

#include <cstdio>
#include "SE_Engine.h"
#include "SE_Window.h"

int main(int argc, char *args[])
{
	SE::Engine engine;
	SE::Window window;
	return EXIT_SUCCESS;
}
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Zer0XoL
ES Beta Backer
ES Beta Backer
Posts: 54
Joined: Fri Apr 24, 2009 1:18 pm
Current Project: Zelda untitled multiplayer game
Favorite Gaming Platforms: PC, GBA, N64
Programming Language of Choice: C++, Lua
Location: Sweden
Contact:

Re: Game Engine Troubles

Post by Zer0XoL »

lotios611 wrote:I can live with the user having to return a value in main(), the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error:
LINK : fatal error LNK1561: entry point must be defined
This is my main.cpp:

Code: Select all

#include <cstdio>
#include "SE_Engine.h"
#include "SE_Window.h"

int main(int argc, char *args[])
{
	SE::Engine engine;
	SE::Window window;
	return EXIT_SUCCESS;
}
project properties > Linker > System > set SubSystem to Windows (or console, will make both the sdl window and a console window) :)
Image
Im Blue
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Game Engine Troubles

Post by lotios611 »

Zer0XoL wrote:
lotios611 wrote:I can live with the user having to return a value in main(), the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error:
LINK : fatal error LNK1561: entry point must be defined
This is my main.cpp:

Code: Select all

#include <cstdio>
#include "SE_Engine.h"
#include "SE_Window.h"

int main(int argc, char *args[])
{
	SE::Engine engine;
	SE::Window window;
	return EXIT_SUCCESS;
}
project properties > Linker > System > set SubSystem to Windows (or console, will make both the sdl window and a console window) :)
I've tried doing that, but when I compile my test game I still get the same error.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
combatant936
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 39
Joined: Wed Jul 29, 2009 11:11 pm
Current Project: It's a secret!!
Favorite Gaming Platforms: N64, SNES, PS2, PC
Programming Language of Choice: C++, 65816 asm
Location: Pennsylvania
Contact:

Re: Game Engine Troubles

Post by combatant936 »

lotios611 wrote:the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error
...
It compiles and links fine until you "test out" the engine... Then it doesn't link right. What do you mean by testing it out? If you get a linker error when you "test out" the engine, but normally you don't, I can only assume that by this you mean you are building under release? I'm just guessing lol but if you are make sure under project properties that you changed what is says next to configuration at the top from debug to release and then add SDLmain.lib to the linker... I could be completely wrong though haha but this is just what I see could be happening.
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Game Engine Troubles

Post by lotios611 »

combatant936 wrote:
lotios611 wrote:the main problem is that I link SDLmain.lib in my engine and everything compiles/links fine, but when I test out my engine, I get this error
...
It compiles and links fine until you "test out" the engine... Then it doesn't link right. What do you mean by testing it out? If you get a linker error when you "test out" the engine, but normally you don't, I can only assume that by this you mean you are building under release? I'm just guessing lol but if you are make sure under project properties that you changed what is says next to configuration at the top from debug to release and then add SDLmain.lib to the linker... I could be completely wrong though haha but this is just what I see could be happening.
My engine is compiled into a debug .lib file. I am writing a game using my engine, and in that game I get the error.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
combatant936
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 39
Joined: Wed Jul 29, 2009 11:11 pm
Current Project: It's a secret!!
Favorite Gaming Platforms: N64, SNES, PS2, PC
Programming Language of Choice: C++, 65816 asm
Location: Pennsylvania
Contact:

Re: Game Engine Troubles

Post by combatant936 »

Oh okay good to know.
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Game Engine Troubles

Post by lotios611 »

I've uploaded a .rar of both my engine and my test game to rapidshare. The folder is 7.7mb, so it might be a little slow to download.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Game Engine Troubles

Post by lotios611 »

Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Game Engine Troubles

Post by Falco Girgis »

lotios611 wrote:Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
Are you adding those libraries to your librarian's linker input for your engine? I swear that Visual Studio lets me statically link to just one .lib containing the others...

As for not wanting the application utilizing your engine to not have to return a value... tough shit. That's how exiting an application and returning to the operating system works. However, I'm pretty sure that want you want to do is this:

Code: Select all

int main() {
Engine engine;

return engine.exec();
So that your engine is the one returning to the operating system...
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Game Engine Troubles

Post by lotios611 »

GyroVorbis wrote:
lotios611 wrote:Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
Are you adding those libraries to your librarian's linker input for your engine? I swear that Visual Studio lets me statically link to just one .lib containing the others...
Well, the problem is that I don't know. When I try to add the stuff to the linker settings when building a .lib, I can't find the linker settings, so I change the project to compile as an .exe, change the linker settings, and then change the project back to compiling as a .lib.

I've just tried going into the project file for my engine and manually editing the linker settings from there, but it still doesn't work.
I get these error messages in my test game now:
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Init referenced in function "public: __thiscall SE::Engine::Engine(void)" (??0Engine@SE@@QAE@XZ)
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Quit referenced in function "public: __thiscall SE::Engine::~Engine(void)" (??1Engine@SE@@QAE@XZ)
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Programming\C++\Splinter Games\Pickin' Sticks\Debug\Pickin' Sticks.exe : fatal error LNK1120: 3 unresolved externals
I've pretty much given up on problem #2.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Game Engine Troubles

Post by Falco Girgis »

lotios611 wrote:
GyroVorbis wrote:
lotios611 wrote:Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
Are you adding those libraries to your librarian's linker input for your engine? I swear that Visual Studio lets me statically link to just one .lib containing the others...
Well, the problem is that I don't know. When I try to add the stuff to the linker settings when building a .lib, I can't find the linker settings, so I change the project to compile as an .exe, change the linker settings, and then change the project back to compiling as a .lib.

I've just tried going into the project file for my engine and manually editing the linker settings from there, but it still doesn't work.
I get these error messages in my test game now:
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Init referenced in function "public: __thiscall SE::Engine::Engine(void)" (??0Engine@SE@@QAE@XZ)
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Quit referenced in function "public: __thiscall SE::Engine::~Engine(void)" (??1Engine@SE@@QAE@XZ)
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Programming\C++\Splinter Games\Pickin' Sticks\Debug\Pickin' Sticks.exe : fatal error LNK1120: 3 unresolved externals
Fuck only knows what's going on there... you aren't ever supposed to do that. I'm guessing you probably didn't also include the corresponding paths to these libraries? You need to find out how to link against additional libraries with your static library (under "librarian" settings).
I've pretty much given up on problem #2.
Why? The code snippet that I posted is literally THE way to handle that scenario...
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: Game Engine Troubles

Post by lotios611 »

GyroVorbis wrote:
lotios611 wrote:
GyroVorbis wrote:
lotios611 wrote:Well, I got everything to compile and link fine, the only problem is that I have to add SplinterEngine.lib SDL.lib SDLmain.lib SDL_image.lib SDL_mixer.lib SDL_ttf.lib to my linker settings and I have to set the subsystem to windows in my test game. Is there any way to get around having to do that and just being able to link to SplinterEngine.lib? Splinter Engine is the name of my game engine by the way.
Are you adding those libraries to your librarian's linker input for your engine? I swear that Visual Studio lets me statically link to just one .lib containing the others...
Well, the problem is that I don't know. When I try to add the stuff to the linker settings when building a .lib, I can't find the linker settings, so I change the project to compile as an .exe, change the linker settings, and then change the project back to compiling as a .lib.

I've just tried going into the project file for my engine and manually editing the linker settings from there, but it still doesn't work.
I get these error messages in my test game now:
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Init referenced in function "public: __thiscall SE::Engine::Engine(void)" (??0Engine@SE@@QAE@XZ)
SplinterEngine.lib(SE_Engine.obj) : error LNK2019: unresolved external symbol _SDL_Quit referenced in function "public: __thiscall SE::Engine::~Engine(void)" (??1Engine@SE@@QAE@XZ)
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Programming\C++\Splinter Games\Pickin' Sticks\Debug\Pickin' Sticks.exe : fatal error LNK1120: 3 unresolved externals
Fuck only knows what's going on there... you aren't ever supposed to do that. I'm guessing you probably didn't also include the corresponding paths to these libraries? You need to find out how to link against additional libraries with your static library (under "librarian" settings).
I tried doing that, and now I get these warnings when I compile my library:
SDL_image.lib(SDL_image.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in SDL.lib(SDL.dll); second definition ignored
SDL_image.lib(SDL_image.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible
SDL_mixer.lib(SDL_mixer.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in SDL.lib(SDL.dll); second definition ignored
SDL_mixer.lib(SDL_mixer.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible
SDL_ttf.lib(SDL_ttf.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in SDL.lib(SDL.dll); second definition ignored
SDL_ttf.lib(SDL_ttf.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible
I've pretty much given up on problem #2.
Why? The code snippet that I posted is literally THE way to handle that scenario...
I realized that would be the way to handle it a while ago, and decided that I didn't want to design my engine like that.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
Post Reply