WorldSim  inDev
2D tile-based sandbox RPG with procedurally generated fantasy world simulator 🌏
Driver_Init.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef WORLDSIM_DRIVER_INIT_HPP
3 #define WORLDSIM_DRIVER_INIT_HPP
4 
5 /* WorldSim: Driver_Init.hpp
6 #include "Driver_Init.hpp"
7 
8 Driver initialization goes here.
9 
10 Initialize main menus, start timers, initialise any important data.
11 
12 */
13 
14 #include <File/WTFManager.hpp> // loading raws
15 
16 
17 void init()
18 {
19  std::cout<<"\n*** INIT ***\n";
20  SEEDER.seed(time(NULL));
21  Random::seed();
22  globalRandom.seed(SEEDER);
23  globalNameGen.seed(SEEDER);
24 
25  // load globalSettings
26  globalSettings.load(FileManager::getFileAsString("raw/ini.wtf"));
27 
28  std::cout<<" *** RAWS ***\n";
29  WTFManager wtfManager;
30 
31  // BUILD COLOURS FROM THE RAW
32  // load colours. Used for Flora and anything else with Colour attributes
33  wtfManager.parse(FileManager::getFileAsString("raw/colours.wtf"));
34  // Load creature species.
35  wtfManager.parse(FileManager::getFileAsString("raw/creatures.wtf"));
36  // Load texture raws
37  wtfManager.parse(FileManager::getFileAsString("raw/textures.wtf"));
38 
39  std::cout<<"All raws:\n"<<wtfManager.getAll()<<"\n\n";
40 
41 
42 
43  // LOAD COLOURS
44 
45  WTFNode* node = wtfManager.getRandom("COLOUR", globalRandom);
46  if (node==0)
47  {
48  std::cout<<"Search returned null ptr\n";
49  }
50  else
51  {
52  std::cout<<"Searched node: "<<node->toString()<<"\n";
53 
54  std::cout<<"Getting node RGB.\n";
55  std::cout<<node->getSub("NAME")->toString()<<"\n";
56  std::cout<<node->getSub("RGB")->toString()<<"\n";
57 
58  // alternate: get all colours
59  Vector <WTFNode*>* vNode = wtfManager.getAllSub("COLOUR");
60  for (int i=0;i<vNode->size();++i)
61  {
62  Vector <std::string> * vRGB = (*vNode)(i)->getValues("RGB");
63  std::string colourName = (*vNode)(i)->getValue("NAME");
64 
65  if (vRGB->size() == 3 && colourName != "")
66  {
67  colourManager.makeColour(DataTools::toInt( (*vRGB)(0) ) ,DataTools::toInt( (*vRGB)(1) ),
68  DataTools::toInt( (*vRGB)(2) ),colourName);
69  }
70  else
71  {
72  std::cout<<"Error: Colours are wrong\n";
73  }
74  }
75  std::cout<<"Colours built:\n"<<colourManager.toString()<<"\n";
76  }
77  ColourRGB <unsigned char> c (64,64,64);
78  ColourRGB <unsigned char> * c2 = colourManager.getClosestTo(c);
79 
80  if (c2)
81  {
82  std::cout<<"The closest colour to "<<c.toString()<<" is "<<c2->toString()<<"\n";
83  }
84 
85 
86  // Load texture references
87  textureManager.loadRaw(FileManager::getFileAsString("raw/textures.wtf"));
88 
89  // LOAD CREATURE SPECIES
90  // I'm not sure if we should load raws out here or let the class handle it. For now I'll leave it for the generator
91  // class but I might change it later.
92  creatureGenerator.loadRaw(FileManager::getFileAsString("raw/creatures.wtf"));
93 
94 
95  std::cout<<" *** END RAWS ***\n";
96 
97  // CLEAN_SAVES_ON_EXIT=false;
98  // QUIT_FLAG=true;
99 
100  //Makes cout faster but less reliable
101  if ( FAST_COUT )
102  {
103  std::ios_base::sync_with_stdio(false);
104  std::cin.tie(NULL);
105  }
106 
107  consoleMessage("GAME STARTED");
108 
109  playerCharacter = 0;
110 
111  globalKeyboard.init();
112 
113  /* Load textures (Tex pointers from Driver_TextureList.hpp). */
114  loadTextures();
115 
116  //LOAD RECIPES
119 
120  /* Load font */
121  Png fontPng;
122  int fileSize;
123  unsigned char* fileData = FileManager::getFile("Textures/Font/8x8/8x8 Transparent v3 plus junk.png",&fileSize);
124 
125  if ( fileData == 0 )
126  {
127  std::cout<<"ERROR: Font PNG did not load.\n";
128  }
129  else
130  {
131  fontPng.load(fileData,fileSize);
132  if(font8x8.loadData(&fontPng,8,8)==false)
133  { std::cout<<"ERROR: Font did not load.\n"; }
134  delete [] fileData;
135  }
136 
138  idleManager.add(&world);
139  logicTickManager.add(&world);
140 
142 
143  /* Start timers. */
144  frameRateTimer.init();
145  frameRateTimer.start();
146  pollRateTimer.init();
147  pollRateTimer.start();
148  logicRateTimer.init();
149  logicRateTimer.start();
150  physicsRateTimer.init();
151  physicsRateTimer.start();
152  animationTimer.init();
153  animationTimer.start();
154  debugTimer.init();
155  debugTimer.start();
156 
157  playerKeypressTimer.init();
158  playerKeypressTimer.start();
159 
160  /* Initialise the main menu */
161  menuTitle.setPanel(0,0,RESOLUTIONX,RESOLUTIONY);
162  menuTitle.init();
164  menuTitle.backgroundTexture=&TEX_TITLE;
165  menuTitle.active=true;
166 
167  /* Initialise the options menu */
168  menuOptions.setPanel(0,0,RESOLUTIONX,RESOLUTIONY);
169  menuOptions.init();
171  menuOptions.backgroundTexture=&TEX_TITLE;
172  menuOptions.active=false;
173 
174  /* Initialise the load game menu */
175  menuLoadGame.setPanel(0,0,RESOLUTIONX,RESOLUTIONY);
176  menuLoadGame.init();
178  menuLoadGame.backgroundTexture=&TEX_TITLE;
179  menuLoadGame.active=false;
180 
181  /* Initialise the world generator menu */
185  //menuWorldGenerator.backgroundTexture=&TEX_TITLE;
186  menuWorldGenerator.active=false;
187 
188  /* Initialise the world simulator menu */
192  //menuWorldSimulator.backgroundTexture=&TEX_TITLE;
193  menuWorldSimulator.active=false;
194 
197  menuAdventureMode.setFont(&font8x8);
198  //menuAdventureMode.backgroundTexture=&TEX_TITLE;
199  menuAdventureMode.active=false;
200 
202  //keyboardInterfaceManager.add(&menuTitle);
204 
205  std::cout<<" *** END INIT ***\n\n";
206 }
207 
208 #endif
Texture * backgroundTexture
Definition: Menu_Options.hpp:9
Menu_Options menuOptions
Definition: Driver.cpp:52
void loadTextures()
Definition: Driver_LoadTextures.hpp:56
void init()
Definition: Menu_AdventureMode.hpp:546
Menu_AdventureMode menuAdventureMode
Definition: Driver.cpp:65
void init()
Definition: Menu_Options.hpp:47
Menu_WorldSimulator menuWorldSimulator
Definition: Driver.cpp:62
void init()
Definition: Menu_WorldGenerator.hpp:117
RandomLehmer SEEDER
Definition: Driver_GlobalObjects.hpp:9
World world
Definition: Driver.cpp:43
Recipe_GrilledFish recipeGrilledFish
Definition: Recipe.hpp:158
Recipe_Wall recipeWall
Definition: Recipe.hpp:124
RandomLehmer globalRandom
Definition: Driver_GlobalObjects.hpp:11
Menu_WorldGenerator menuWorldGenerator
Definition: Driver.cpp:59
void init()
Definition: Menu_Title.hpp:67
GUI_Manager globalGuiManager
Definition: Driver_GlobalObjects.hpp:95
ColourManager< unsigned char > colourManager
Definition: Driver_GlobalObjects.hpp:26
Menu_Title menuTitle
Definition: Driver.cpp:49
Wildcat::Font font8x8
Definition: Driver_GlobalObjects.hpp:49
void initCreatureAttacks()
Definition: Creature_Attack.hpp:53
void init()
Definition: Menu_LoadGame.hpp:33
unsigned int RESOLUTIONY
Definition: Driver_Settings.cpp:94
Creature_Generator creatureGenerator
Definition: Driver_GlobalObjects.hpp:70
Keyboard globalKeyboard
Definition: Driver_GlobalObjects.hpp:54
Character * playerCharacter
Definition: Driver_Settings.cpp:105
Timer logicRateTimer
Definition: Driver_GlobalObjects.hpp:59
Timer debugTimer
Definition: Driver_GlobalObjects.hpp:64
void init()
Definition: Driver_Init.hpp:17
Timer physicsRateTimer
Definition: Driver_GlobalObjects.hpp:60
void setFont(Wildcat::Font *_font)
Definition: Menu_WorldGenerator.hpp:103
Texture * backgroundTexture
Definition: Menu_LoadGame.hpp:8
Menu_LoadGame menuLoadGame
Definition: Driver.cpp:55
void consoleMessage(std::string s)
Definition: Driver_GlobalObjects.hpp:36
void setFont(Wildcat::Font *_font)
Definition: Menu_Title.hpp:51
Timer frameRateTimer
Definition: Driver_GlobalObjects.hpp:57
Timer animationTimer
Definition: Driver_GlobalObjects.hpp:61
TextureManager textureManager
Definition: Driver_GlobalObjects.hpp:29
LogicTickManager logicTickManager
Definition: Driver_GlobalObjects.hpp:100
void loadRaw(std::string strRaw)
Definition: TextureManager.hpp:43
unsigned int RESOLUTIONX
Definition: Driver_Settings.cpp:94
Texture * backgroundTexture
Definition: Menu_Title.hpp:42
const bool FAST_COUT
Definition: Driver_Settings.cpp:37
MouseInterfaceManager mouseInterfaceManager
Definition: Driver_GlobalObjects.hpp:84
Timer pollRateTimer
Definition: Driver_GlobalObjects.hpp:58
void load(std::string settingsData)
Definition: Driver_GlobalSettings.cpp:27
IdleTickManager idleManager
Definition: Driver_GlobalObjects.hpp:104
NameGen globalNameGen
Definition: Driver_GlobalObjects.hpp:22
void setFont(Wildcat::Font *_font)
Definition: Menu_WorldSimulator.hpp:127
void loadRaw(std::string strRaw)
Definition: Creature_Generator.cpp:38
GlobalSettings globalSettings
Definition: Driver.cpp:12
void addRecipe(Recipe *_recipe)
Definition: Recipe.hpp:296
Timer playerKeypressTimer
Definition: Driver_GlobalObjects.hpp:62
void setFont(Wildcat::Font *_font)
Definition: Menu_LoadGame.hpp:61
void init()
Definition: Menu_WorldSimulator.hpp:133
void setFont(Wildcat::Font *_font)
Definition: Menu_Options.hpp:35
RecipeManager recipeManager
Definition: Recipe.hpp:395