Began work on the client
This commit is contained in:
@@ -31,13 +31,6 @@ BaseScene::~BaseScene() {
|
|||||||
//EMPTY
|
//EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseScene::RunFrame() {
|
|
||||||
FrameStart();
|
|
||||||
ProcessEvents();
|
|
||||||
Update();
|
|
||||||
FrameEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::RenderFrame(SDL_Renderer* renderer) {
|
void BaseScene::RenderFrame(SDL_Renderer* renderer) {
|
||||||
//EMPTY
|
//EMPTY
|
||||||
}
|
}
|
||||||
@@ -66,39 +59,6 @@ void BaseScene::FrameStart() {
|
|||||||
//EMPTY
|
//EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseScene::ProcessEvents() {
|
|
||||||
SDL_Event event;
|
|
||||||
while(SDL_PollEvent(&event)) {
|
|
||||||
switch(event.type) {
|
|
||||||
case SDL_QUIT:
|
|
||||||
QuitEvent();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
MouseMotion(event.motion);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
MouseButtonDown(event.button);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
MouseButtonUp(event.button);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
KeyDown(event.key);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_KEYUP:
|
|
||||||
KeyUp(event.key);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//TODO: joystick and controller events
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::Update() {
|
void BaseScene::Update() {
|
||||||
//EMPTY
|
//EMPTY
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,20 +30,12 @@ public:
|
|||||||
BaseScene();
|
BaseScene();
|
||||||
virtual ~BaseScene();
|
virtual ~BaseScene();
|
||||||
|
|
||||||
virtual void RunFrame();
|
|
||||||
virtual void RenderFrame(SDL_Renderer*);
|
virtual void RenderFrame(SDL_Renderer*);
|
||||||
|
|
||||||
static void SetRenderer(SDL_Renderer*);
|
static void SetRenderer(SDL_Renderer*);
|
||||||
SceneSignal GetSceneSignal();
|
SceneSignal GetSceneSignal();
|
||||||
|
|
||||||
protected:
|
|
||||||
//control
|
|
||||||
static SDL_Renderer* GetRenderer();
|
|
||||||
void SetSceneSignal(SceneSignal);
|
|
||||||
|
|
||||||
//frame phases
|
//frame phases
|
||||||
virtual void FrameStart();
|
virtual void FrameStart();
|
||||||
virtual void ProcessEvents();
|
|
||||||
virtual void Update();
|
virtual void Update();
|
||||||
virtual void FrameEnd();
|
virtual void FrameEnd();
|
||||||
|
|
||||||
@@ -58,6 +50,11 @@ protected:
|
|||||||
|
|
||||||
//TODO: joystick and controller events
|
//TODO: joystick and controller events
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//control
|
||||||
|
static SDL_Renderer* GetRenderer();
|
||||||
|
void SetSceneSignal(SceneSignal);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static SDL_Renderer* rendererHandle;
|
static SDL_Renderer* rendererHandle;
|
||||||
SceneSignal sceneSignal = SceneSignal::CONTINUE;
|
SceneSignal sceneSignal = SceneSignal::CONTINUE;
|
||||||
|
|||||||
+154
-76
@@ -24,22 +24,10 @@
|
|||||||
#include "serial_packet.hpp"
|
#include "serial_packet.hpp"
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
//-------------------------
|
|
||||||
//Scene headers
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
//Add the custom scene headers here
|
|
||||||
#include "splash_screen.hpp"
|
|
||||||
#include "main_menu.hpp"
|
|
||||||
#include "options_menu.hpp"
|
|
||||||
#include "lobby_menu.hpp"
|
|
||||||
#include "world.hpp"
|
|
||||||
#include "disconnected_screen.hpp"
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
@@ -53,34 +41,57 @@ void ClientApplication::Init(int argc, char* argv[]) {
|
|||||||
config.Load("rsc/config.cfg", false, argc, argv);
|
config.Load("rsc/config.cfg", false, argc, argv);
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Initialize the APIs
|
//create and check the window
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
//initialize SDL
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO)) {
|
|
||||||
std::ostringstream os;
|
|
||||||
os << "Failed to initialize SDL: " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(os.str()));
|
|
||||||
}
|
|
||||||
std::cout << "Initialized SDL" << std::endl;
|
|
||||||
|
|
||||||
//initialize SDL_net
|
|
||||||
if (SDLNet_Init()) {
|
|
||||||
throw(std::runtime_error("Failed to initialize SDL_net"));
|
|
||||||
}
|
|
||||||
UDPNetworkUtility::GetSingleton().Open(0);
|
|
||||||
std::cout << "Initialized SDL_net" << std::endl;
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//Setup the screen
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
int w = config.Int("client.screen.w");
|
int w = config.Int("client.screen.w");
|
||||||
int h = config.Int("client.screen.h");
|
int h = config.Int("client.screen.h");
|
||||||
int f = config.Bool("client.screen.f") ? SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN : SDL_HWSURFACE|SDL_DOUBLEBUF;
|
int f = config.Bool("client.screen.f") ? SDL_WINDOW_FULLSCREEN : 0;
|
||||||
|
|
||||||
BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f);
|
window = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w ? w : 800, h ? h : 600, f);
|
||||||
std::cout << "Initialized the screen" << std::endl;
|
|
||||||
|
if (!window) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to create the window: " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Initialized the window" << std::endl;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//create and check the renderer
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||||
|
|
||||||
|
if (!renderer) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to create the renderer: " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//screen scaling
|
||||||
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
|
||||||
|
SDL_RenderSetLogicalSize(renderer, w, h);
|
||||||
|
|
||||||
|
//set the hook for the renderer
|
||||||
|
BaseScene::SetRenderer(renderer);
|
||||||
|
|
||||||
|
std::cout << "Initialized the renderer" << std::endl;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Initialize the APIs
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//initialize SDL_net
|
||||||
|
if (SDLNet_Init()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to initialize SDL_net: " << SDL_GetError();
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
UDPNetworkUtility::GetSingleton().Open(0);
|
||||||
|
|
||||||
|
std::cout << "Initialized SDL_net" << std::endl;
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//debug output
|
//debug output
|
||||||
@@ -119,88 +130,155 @@ void ClientApplication::Init(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClientApplication::Proc() {
|
void ClientApplication::Proc() {
|
||||||
LoadScene(SceneList::FIRST);
|
//load the first scene
|
||||||
|
ProcessSceneSignal(SceneSignal::FIRST);
|
||||||
|
|
||||||
//prepare the time system
|
//fixed frame rate
|
||||||
typedef std::chrono::steady_clock Clock;
|
typedef std::chrono::steady_clock Clock;
|
||||||
|
|
||||||
Clock::time_point simTime = Clock::now();
|
Clock::time_point simTime = Clock::now();
|
||||||
Clock::time_point realTime;
|
Clock::time_point realTime;
|
||||||
|
constexpr std::chrono::duration<int, std::milli> frameDelay(16); //~60FPS
|
||||||
|
|
||||||
//The main loop
|
//the game loop continues until the scenes signal QUIT
|
||||||
while(activeScene->GetNextScene() != SceneList::QUIT) {
|
while(activeScene->GetSceneSignal() != SceneSignal::QUIT) {
|
||||||
//switch scenes when necessary
|
//switch scenes if necessary
|
||||||
if (activeScene->GetNextScene() != SceneList::CONTINUE) {
|
if(activeScene->GetSceneSignal() != SceneSignal::CONTINUE) {
|
||||||
LoadScene(activeScene->GetNextScene());
|
ProcessSceneSignal(activeScene->GetSceneSignal());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//update the current time
|
//update the current time
|
||||||
realTime = Clock::now();
|
realTime = Clock::now();
|
||||||
|
|
||||||
//simulate game time
|
//simulate the game or give the machine a break
|
||||||
if (simTime < realTime) {
|
if (simTime < realTime) {
|
||||||
while(simTime < realTime) {
|
while(simTime < realTime) {
|
||||||
//call each user defined function
|
//call the user defined functions
|
||||||
activeScene->RunFrame();
|
activeScene->FrameStart();
|
||||||
//~60 FPS
|
ProcessEvents();
|
||||||
simTime += std::chrono::duration<int, std::milli>(16);
|
activeScene->Update();
|
||||||
|
activeScene->FrameEnd();
|
||||||
|
|
||||||
|
//step to the next frame
|
||||||
|
simTime += frameDelay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//give the machine a break
|
SDL_Delay(1);
|
||||||
SDL_Delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw the game to the screen
|
SDL_RenderClear(renderer);
|
||||||
activeScene->RenderFrame();
|
activeScene->RenderFrame(renderer);
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadScene();
|
//cleanup
|
||||||
|
ClearScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientApplication::Quit() {
|
void ClientApplication::Quit() {
|
||||||
|
//clean up after the program
|
||||||
std::cout << "Shutting down" << std::endl;
|
std::cout << "Shutting down" << std::endl;
|
||||||
UDPNetworkUtility::GetSingleton().Close();
|
UDPNetworkUtility::GetSingleton().Close();
|
||||||
SDLNet_Quit();
|
SDLNet_Quit();
|
||||||
SDL_Quit();
|
BaseScene::SetRenderer(nullptr);
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
std::cout << "Clean exit" << std::endl;
|
std::cout << "Clean exit" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Private access members
|
//Scene management
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void ClientApplication::LoadScene(SceneList sceneIndex) {
|
void ClientApplication::ProcessEvents() {
|
||||||
//BUG: #16 Resources are being reloaded between scenes
|
SDL_Event event;
|
||||||
UnloadScene();
|
while(SDL_PollEvent(&event)) {
|
||||||
switch(sceneIndex) {
|
switch(event.type) {
|
||||||
//add scene creation calls here
|
case SDL_QUIT:
|
||||||
case SceneList::FIRST:
|
activeScene->QuitEvent();
|
||||||
case SceneList::SPLASHSCREEN:
|
|
||||||
activeScene = new SplashScreen();
|
|
||||||
break;
|
break;
|
||||||
case SceneList::MAINMENU:
|
|
||||||
activeScene = new MainMenu();
|
case SDL_MOUSEMOTION:
|
||||||
|
activeScene->MouseMotion(event.motion);
|
||||||
break;
|
break;
|
||||||
case SceneList::OPTIONSMENU:
|
|
||||||
activeScene = new OptionsMenu();
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
activeScene->MouseButtonDown(event.button);
|
||||||
break;
|
break;
|
||||||
case SceneList::LOBBYMENU:
|
|
||||||
activeScene = new LobbyMenu(&clientIndex, &accountIndex);
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
activeScene->MouseButtonUp(event.button);
|
||||||
break;
|
break;
|
||||||
case SceneList::WORLD:
|
|
||||||
activeScene = new World(&clientIndex, &accountIndex);
|
case SDL_MOUSEWHEEL:
|
||||||
|
activeScene->MouseWheel(event.wheel);
|
||||||
break;
|
break;
|
||||||
case SceneList::DISCONNECTEDSCREEN:
|
|
||||||
activeScene = new DisconnectedScreen();
|
case SDL_KEYDOWN:
|
||||||
|
activeScene->KeyDown(event.key);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
throw(std::logic_error("Failed to recognize the scene index"));
|
case SDL_KEYUP:
|
||||||
|
activeScene->KeyUp(event.key);
|
||||||
|
break;
|
||||||
|
|
||||||
|
//TODO: joystick and controller events
|
||||||
|
|
||||||
|
//window events are handled internally
|
||||||
|
case SDL_WINDOWEVENT:
|
||||||
|
switch(event.window.event) {
|
||||||
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
|
SDL_RenderSetLogicalSize(renderer, event.window.data1, event.window.data2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientApplication::UnloadScene() {
|
//Add the custom scene headers here
|
||||||
|
#include "splash_screen.hpp"
|
||||||
|
#include "main_menu.hpp"
|
||||||
|
#include "options_menu.hpp"
|
||||||
|
#include "lobby_menu.hpp"
|
||||||
|
#include "world.hpp"
|
||||||
|
#include "disconnected_screen.hpp"
|
||||||
|
|
||||||
|
void ClientApplication::ProcessSceneSignal(SceneSignal signal) {
|
||||||
|
//BUG: #16 Resources are being reloaded between scenes
|
||||||
|
ClearScene();
|
||||||
|
switch(signal) {
|
||||||
|
//add scene creation calls here
|
||||||
|
case SceneSignal::FIRST:
|
||||||
|
case SceneSignal::SPLASHSCREEN:
|
||||||
|
activeScene = new SplashScreen();
|
||||||
|
break;
|
||||||
|
case SceneSignal::MAINMENU:
|
||||||
|
activeScene = new MainMenu();
|
||||||
|
break;
|
||||||
|
case SceneSignal::OPTIONSMENU:
|
||||||
|
activeScene = new OptionsMenu();
|
||||||
|
break;
|
||||||
|
case SceneSignal::LOBBYMENU:
|
||||||
|
activeScene = new LobbyMenu(&clientIndex, &accountIndex);
|
||||||
|
break;
|
||||||
|
case SceneSignal::WORLD:
|
||||||
|
activeScene = new World(&clientIndex, &accountIndex);
|
||||||
|
break;
|
||||||
|
case SceneSignal::DISCONNECTEDSCREEN:
|
||||||
|
activeScene = new DisconnectedScreen();
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to recognize the scene signal: " << signal;
|
||||||
|
throw(std::logic_error(msg.str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientApplication::ClearScene() {
|
||||||
delete activeScene;
|
delete activeScene;
|
||||||
activeScene = nullptr;
|
activeScene = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,18 +21,15 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "scene_list.hpp"
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
#include "scene_signal.hpp"
|
||||||
|
#include "singleton.hpp"
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
#include "singleton.hpp"
|
#include "SDL2/SDL.h"
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
class ClientApplication: public Singleton<ClientApplication> {
|
class ClientApplication: public Singleton<ClientApplication> {
|
||||||
public:
|
public:
|
||||||
//public methods
|
|
||||||
void Init(int argc, char* argv[]);
|
void Init(int argc, char* argv[]);
|
||||||
void Proc();
|
void Proc();
|
||||||
void Quit();
|
void Quit();
|
||||||
@@ -43,12 +40,17 @@ private:
|
|||||||
ClientApplication() = default;
|
ClientApplication() = default;
|
||||||
~ClientApplication() = default;
|
~ClientApplication() = default;
|
||||||
|
|
||||||
//Private access members
|
//scene management
|
||||||
void LoadScene(SceneList sceneIndex);
|
void ProcessEvents();
|
||||||
void UnloadScene();
|
void ProcessSceneSignal(SceneSignal);
|
||||||
|
void ClearScene();
|
||||||
|
|
||||||
BaseScene* activeScene = nullptr;
|
BaseScene* activeScene = nullptr;
|
||||||
|
|
||||||
|
//TODO: build a "window" class?
|
||||||
|
SDL_Window* window = nullptr;
|
||||||
|
SDL_Renderer* renderer = nullptr;
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
int clientIndex = -1;
|
int clientIndex = -1;
|
||||||
int accountIndex = -1;
|
int accountIndex = -1;
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
#include "tile_sheet.hpp"
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
@@ -54,21 +53,21 @@ public:
|
|||||||
World(int* const argClientIndex, int* const argAccountIndex);
|
World(int* const argClientIndex, int* const argAccountIndex);
|
||||||
~World();
|
~World();
|
||||||
|
|
||||||
protected:
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
//Frame loop
|
|
||||||
void FrameStart();
|
|
||||||
void Update();
|
|
||||||
void FrameEnd();
|
|
||||||
void RenderFrame();
|
|
||||||
void Render(SDL_Surface* const);
|
|
||||||
|
|
||||||
//Event handlers
|
private:
|
||||||
void QuitEvent();
|
//frame phases
|
||||||
void MouseMotion(SDL_MouseMotionEvent const&);
|
void FrameStart() override;
|
||||||
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
void Update() override;
|
||||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
void FrameEnd() override;
|
||||||
void KeyDown(SDL_KeyboardEvent const&);
|
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
//input events
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
|
||||||
//handle incoming traffic
|
//handle incoming traffic
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
@@ -132,7 +131,6 @@ protected:
|
|||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
Image buttonImage;
|
Image buttonImage;
|
||||||
RasterFont font;
|
|
||||||
TileSheet tileSheet;
|
TileSheet tileSheet;
|
||||||
|
|
||||||
//map
|
//map
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ int main(int argc, char* argv[]) {
|
|||||||
app.Proc();
|
app.Proc();
|
||||||
app.Quit();
|
app.Quit();
|
||||||
|
|
||||||
|
//control the position of the app's destructor
|
||||||
ClientApplication::DeleteSingleton();
|
ClientApplication::DeleteSingleton();
|
||||||
|
|
||||||
//delete the singletons
|
//delete the singletons
|
||||||
|
|||||||
+11
-7
@@ -1,5 +1,5 @@
|
|||||||
#include directories
|
#include directories
|
||||||
INCLUDES+=SDL . client_utilities entities gameplay_scenes menu_scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
|
INCLUDES+=. client_utilities entities gameplay_scenes menu_scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
|
||||||
|
|
||||||
#libraries
|
#libraries
|
||||||
#the order of the $(LIBS) is important, at least for MinGW
|
#the order of the $(LIBS) is important, at least for MinGW
|
||||||
@@ -7,10 +7,14 @@ LIBS+=client.a ../libcommon.a -lSDL_net
|
|||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
LIBS+=-lwsock32 -liphlpapi -lmingw32
|
LIBS+=-lwsock32 -liphlpapi -lmingw32
|
||||||
endif
|
endif
|
||||||
LIBS+=-lSDLmain -lSDL -lSDL2_image -lSDL2_ttf
|
LIBS+=-lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf
|
||||||
|
|
||||||
#flags
|
#flags
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
ifeq ($(shell uname), Linux)
|
||||||
|
#read data about the current install
|
||||||
|
CXXFLAGS+=$(shell sdl-config --cflags --static-libs)
|
||||||
|
endif
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
@@ -25,11 +29,11 @@ OUT=$(addprefix $(OUTDIR)/,client)
|
|||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
$(MAKE) -C client_utilities
|
# $(MAKE) -C client_utilities
|
||||||
$(MAKE) -C entities
|
# $(MAKE) -C entities
|
||||||
$(MAKE) -C gameplay_scenes
|
# $(MAKE) -C gameplay_scenes
|
||||||
$(MAKE) -C menu_scenes
|
# $(MAKE) -C menu_scenes
|
||||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
# $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ DisconnectedScreen::~DisconnectedScreen() {
|
|||||||
//Frame loop
|
//Frame loop
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
void DisconnectedScreen::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
void DisconnectedScreen::Update() {
|
void DisconnectedScreen::Update() {
|
||||||
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
|
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
|
||||||
SetNextScene(SceneList::MAINMENU);
|
SetNextScene(SceneList::MAINMENU);
|
||||||
@@ -74,10 +78,14 @@ void DisconnectedScreen::Update() {
|
|||||||
while(UDPNetworkUtility::GetSingleton().Receive());
|
while(UDPNetworkUtility::GetSingleton().Receive());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisconnectedScreen::Render(SDL_Surface* const screen) {
|
void DisconnectedScreen::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) {
|
||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
backButton.DrawTo(screen);
|
backButton.DrawTo(renderer);
|
||||||
font.DrawStringTo(config["client.disconnectMessage"], screen, 50, 30);
|
font.DrawStringTo(config["client.disconnectMessage"], screen, 50, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,10 +93,6 @@ void DisconnectedScreen::Render(SDL_Surface* const screen) {
|
|||||||
//Event handlers
|
//Event handlers
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void DisconnectedScreen::QuitEvent() {
|
|
||||||
SetNextScene(SceneList::QUIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DisconnectedScreen::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
void DisconnectedScreen::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
backButton.MouseMotion(motion);
|
backButton.MouseMotion(motion);
|
||||||
}
|
}
|
||||||
@@ -98,15 +102,15 @@ void DisconnectedScreen::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DisconnectedScreen::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
void DisconnectedScreen::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
|
if (backButton.MouseButtonUp(button) == Button::State::RELEASED) {
|
||||||
SetNextScene(SceneList::MAINMENU);
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisconnectedScreen::KeyDown(SDL_KeyboardEvent const& key) {
|
void DisconnectedScreen::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
switch(key.keysym.sym) {
|
switch(key.keysym.sym) {
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
SetNextScene(SceneList::MAINMENU);
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
//client
|
//client
|
||||||
@@ -38,24 +37,24 @@ public:
|
|||||||
DisconnectedScreen();
|
DisconnectedScreen();
|
||||||
~DisconnectedScreen();
|
~DisconnectedScreen();
|
||||||
|
|
||||||
protected:
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
//Frame loop
|
|
||||||
void Update();
|
|
||||||
void Render(SDL_Surface* const);
|
|
||||||
|
|
||||||
//Event handlers
|
protected:
|
||||||
void QuitEvent();
|
//frame phases
|
||||||
void MouseMotion(SDL_MouseMotionEvent const&);
|
void FrameStart() override;
|
||||||
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
void Update() override;
|
||||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
void FrameEnd() override;
|
||||||
void KeyDown(SDL_KeyboardEvent const&);
|
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
//input events
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
Image image;
|
Image image;
|
||||||
RasterFont font;
|
|
||||||
|
|
||||||
//UI
|
|
||||||
Button backButton;
|
Button backButton;
|
||||||
|
|
||||||
//auto return
|
//auto return
|
||||||
|
|||||||
@@ -99,13 +99,13 @@ void LobbyMenu::FrameEnd() {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::Render(SDL_Surface* const screen) {
|
void ExampleScene::RenderFrame(SDL_Renderer* renderer) {
|
||||||
//TODO: (2) I need a proper UI system for the entire client and the editor
|
//TODO: (2) I need a proper UI system for the entire client and the editor
|
||||||
|
|
||||||
//UI
|
//UI
|
||||||
search.DrawTo(screen);
|
search.DrawTo(renderer);
|
||||||
join.DrawTo(screen);
|
join.DrawTo(renderer);
|
||||||
back.DrawTo(screen);
|
back.DrawTo(renderer);
|
||||||
|
|
||||||
//TODO: (3) draw headers for the server list
|
//TODO: (3) draw headers for the server list
|
||||||
//TODO: (3) ping/delay displayed in the server list
|
//TODO: (3) ping/delay displayed in the server list
|
||||||
@@ -173,10 +173,14 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::MouseWheel(SDL_MouseWheelEvent const& event) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
void LobbyMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
void LobbyMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
switch(key.keysym.sym) {
|
switch(key.keysym.sym) {
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
SetNextScene(SceneList::MAINMENU);
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
//graphics & ui
|
//graphics & ui
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
#include "bounding_box.hpp"
|
#include "bounding_box.hpp"
|
||||||
|
|
||||||
@@ -44,19 +43,21 @@ public:
|
|||||||
LobbyMenu(int* const argClientIndex, int* const argAccountIndex);
|
LobbyMenu(int* const argClientIndex, int* const argAccountIndex);
|
||||||
~LobbyMenu();
|
~LobbyMenu();
|
||||||
|
|
||||||
protected:
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
//Frame loop
|
|
||||||
void FrameStart();
|
|
||||||
void Update();
|
|
||||||
void FrameEnd();
|
|
||||||
void Render(SDL_Surface* const);
|
|
||||||
|
|
||||||
//Event handlers
|
protected:
|
||||||
void MouseMotion(SDL_MouseMotionEvent const&);
|
//frame phases
|
||||||
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
void FrameStart() override;
|
||||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
void Update() override;
|
||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void FrameEnd() override;
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
|
||||||
|
//input events
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
|
||||||
//Network handlers
|
//Network handlers
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
@@ -79,7 +80,6 @@ protected:
|
|||||||
|
|
||||||
//members
|
//members
|
||||||
Image image;
|
Image image;
|
||||||
RasterFont font;
|
|
||||||
Button search;
|
Button search;
|
||||||
Button join;
|
Button join;
|
||||||
Button back;
|
Button back;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
class MainMenu : public BaseScene {
|
class MainMenu : public BaseScene {
|
||||||
@@ -33,23 +32,24 @@ public:
|
|||||||
MainMenu();
|
MainMenu();
|
||||||
~MainMenu();
|
~MainMenu();
|
||||||
|
|
||||||
protected:
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
//Frame loop
|
|
||||||
void FrameStart();
|
|
||||||
void Update();
|
|
||||||
void FrameEnd();
|
|
||||||
void Render(SDL_Surface* const);
|
|
||||||
|
|
||||||
//Event handlers
|
protected:
|
||||||
void MouseMotion(SDL_MouseMotionEvent const&);
|
//frame phases
|
||||||
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
void FrameStart() override;
|
||||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
void Update() override;
|
||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void FrameEnd() override;
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
|
||||||
|
//input events
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Image image;
|
Image image;
|
||||||
RasterFont font;
|
|
||||||
Button startButton;
|
Button startButton;
|
||||||
Button optionsButton;
|
Button optionsButton;
|
||||||
Button quitButton;
|
Button quitButton;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
//NOTE: The options screen needs to be USED
|
//NOTE: The options screen needs to be USED
|
||||||
@@ -34,22 +33,23 @@ public:
|
|||||||
OptionsMenu();
|
OptionsMenu();
|
||||||
~OptionsMenu();
|
~OptionsMenu();
|
||||||
|
|
||||||
protected:
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
//Frame loop
|
|
||||||
void FrameStart();
|
|
||||||
void Update();
|
|
||||||
void FrameEnd();
|
|
||||||
void Render(SDL_Surface* const);
|
|
||||||
|
|
||||||
//Event handlers
|
private:
|
||||||
void MouseMotion(SDL_MouseMotionEvent const&);
|
//frame phases
|
||||||
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
void FrameStart() override;
|
||||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
void Update() override;
|
||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void FrameEnd() override;
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
|
||||||
|
//input events
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
||||||
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Image image;
|
Image image;
|
||||||
RasterFont font;
|
|
||||||
Button backButton;
|
Button backButton;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,12 +40,14 @@ SplashScreen::~SplashScreen() {
|
|||||||
//Frame loop
|
//Frame loop
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void SplashScreen::Update() {
|
void SplashScreen::FrameStart() {
|
||||||
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(1)) {
|
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(1)) {
|
||||||
SetNextScene(SceneList::MAINMENU);
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplashScreen::Render(SDL_Surface* const screen) {
|
void SplashScreen::RenderFrame(SDL_Renderer* renderer) {
|
||||||
logo.DrawTo(screen, (screen->w - logo.GetClipW()) / 2, (screen->h - logo.GetClipH()) / 2);
|
int w = 0, h = 0;
|
||||||
|
SDL_GetLogicalSize(renderer, &w, &h);
|
||||||
|
logo.DrawTo(renderer, (w - logo.GetClipW()) / 2, (h - logo.GetClipH()) / 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,11 @@ public:
|
|||||||
SplashScreen();
|
SplashScreen();
|
||||||
~SplashScreen();
|
~SplashScreen();
|
||||||
|
|
||||||
protected:
|
void RenderFrame(SDL_Renderer* renderer) override;
|
||||||
|
|
||||||
|
private:
|
||||||
//Frame loop
|
//Frame loop
|
||||||
void Update();
|
void FrameStart() override;
|
||||||
void Render(SDL_Surface* const);
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
std::chrono::steady_clock::time_point startTick;
|
std::chrono::steady_clock::time_point startTick;
|
||||||
|
|||||||
@@ -28,5 +28,10 @@ enum SceneSignal {
|
|||||||
FIRST = 1,
|
FIRST = 1,
|
||||||
|
|
||||||
//custom scenes
|
//custom scenes
|
||||||
EXAMPLE_SCENE
|
SPLASHSCREEN,
|
||||||
|
MAINMENU,
|
||||||
|
OPTIONSMENU,
|
||||||
|
LOBBYMENU,
|
||||||
|
WORLD,
|
||||||
|
DISCONNECTEDSCREEN,
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user