Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Console Based AppGameKit Server

Author
Message
Parry
AGK Developer
14
Years of Service
User Offline
Joined: 16th Dec 2009
Location: Swampstone
Posted: 5th Jun 2017 05:47 Edited at: 5th Jun 2017 05:54
I was unaware that the linux version of AppGameKit had a console template. With that it was simple to change "template_windows_vs2015" into a console only for use as a server.

This is Tier 2, not sure if this can be done with Tier 1.

If your interested here is how to do that:

Open the project with Visual Studio and go into the Project Setting.
Go into "Configuration Properties/Linker/System" and change the "SubSystem" from "Windows" to "Console".
Click Okay to save the changes.

1> Open Core.cpp

2> Change:

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)

to:

int main()


3> find this line and comment it out:

HWND hWnd = CreateWin32Window( hInstance, DEVICE_WIDTH, DEVICE_HEIGHT, uString("AGK"), dwCenterWindowX, dwCenterWindowY, FULLSCREEN );

4> replace this line:

agk::InitGL( (void*) hWnd );

with this:

agk::InitConsole();

5> open template.cpp:

6> under:

#include "template.h"

add:

#include <iostream>

7> comment out these lines:

agk::SetVirtualResolution (1024, 768);
agk::SetClearColor( 151,170,204 ); // light blue
agk::SetSyncRate(60,0);
agk::SetScissor(0,0,0,0);

8> replace these lines:

agk:rint( agk::ScreenFPS() );
agk::Sync();

with these:

agk::UpdateInput();
AGKMusicOGG::UpdateAll();
agk::Sleep(33);

10> an example for screen output:

void app::Begin(void)
{
std::cout << "Control-X to exit.\n";
}

11> An example for keyboard input: (this only works in windows)

int app::Loop (void)
{
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
{
if (GetAsyncKeyState(0x58) & 0x8000) return 1;
}

agk::UpdateInput();
AGKMusicOGG::UpdateAll();
agk::Sleep(33);

return 0; // return 1 to close app
}

12> now you can add appgamekit commands to build a server. The examples I give in 10 and 11 can be used for text out and keyboard input.
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 5th Jun 2017 09:22
Great !
Can you provide a compiled Linux version of a little example ? I want to see if it runs correctly on a VPS server
--------------------------------
Join us on dedicated AppGameKit WeeKChat :
https://week.chat/room/AppGameKit
Parry
AGK Developer
14
Years of Service
User Offline
Joined: 16th Dec 2009
Location: Swampstone
Posted: 6th Jun 2017 03:53
Quote: "Great !
Can you provide a compiled Linux version of a little example ? I want to see if it runs correctly on a VPS server "


Sure. This is build in Ubuntu 16.04 with the AppGameKit linux console template and is 64 bit.

FYI: Don't start if from a GUI, make sure you start in a terminal window. After unzipping it start it with "./LinuxApp64".
It will count to 10 in 10 seconds using AppGameKit timer and exit.



Also I edited the console template to make App:Loop into a int and not a void function.

Attachments

Login to view attachments
Xaron
9
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 6th Jun 2017 07:37
Wow, thanks for that! Is there a specific reason for that sleep beyond to give the CPU some time to breath?
Parry
AGK Developer
14
Years of Service
User Offline
Joined: 16th Dec 2009
Location: Swampstone
Posted: 6th Jun 2017 11:38
The sleep(33) was already in the original linux console template. I imagine it does cut way down on cpu usage.
Xaron
9
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 6th Jun 2017 12:22
Yep seems so. I can imagine that this should be removed for a real server application because in that case there's simply no need to throttle it.
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 16th Jun 2017 06:42
it works well from my VPS Servers

--------------------------------
Join us on dedicated AppGameKit WeeKChat :
https://week.chat/room/AppGameKit

Login to post a reply

Server time is: 2024-04-19 04:14:33
Your offset time is: 2024-04-19 04:14:33