cytopiateam / cytopia Goto Github PK
View Code? Open in Web Editor NEW:deciduous_tree::house_with_garden::office::evergreen_tree: A city building simulation game
Home Page: https://www.cytopia.net
License: GNU General Public License v3.0
:deciduous_tree::house_with_garden::office::evergreen_tree: A city building simulation game
Home Page: https://www.cytopia.net
License: GNU General Public License v3.0
The event handling is fragmented now. There is the eventHandler class, which currently only handles mouse clicks for the UI and the old eventhandler code in game.cxx in the gameloop.
The Resources class has many responsibilities, maintains multiple global variables, and provides many different functions. It would be nice to refactor these into separate modules.
For example, there is no reason for convertIsoToScreenCoordinates to be a part of the Resources class. It can simply be a free function. The current design is much closer to Java than C++.
It also seems a little strange that zoom level, the SDL window, the camera offset, etc. are considered "resources". Typically, the resource system in a game engine has to do with the resources loaded from the file system (e.g., the 2D images for tiles).
I think the class should be split up into separate modules (not necessarily classes - free functions are appropriate here too) to simplify the design.
Add editMode variable that determines if texture highlighting is active or not.
RCI Zones should be placable in rectangular zones.
When a tile is clicked and the mouse button is being held down, draw a rectangular zone to the end position when the mouse button is released.
The tiles in the zone should also be highlighted during the mousebutton held down event.
Add "showSplashscreen" variable to settings and show a splashscreen when the image is done.
This need #51 as a prerequiste
Draw a rectangle with with a nice border (by drawing multime rects with offsets?)
The rectangle could either have a solid background (for a button menu) or have just the frame (to lay over other stuff like a solidrect (button without image))
Attributes:
The Log class is a little difficult for me to understand at first. Right now, the constructor creates a string stream and logs a timestamp and any additional information (e.g., ERROR), then the ostream operator outputs the message to the stringstream, then the destructor outputs the stringstream to std::cout.
This is pretty complex, and doesn't really fit idiomatic C++. I was thinking of one of two alternatives:
SDL_Log - SDL2 already has facilities for logging. While they are not overly advanced, they are well-designed and consistent. You can override the output function of SDL_Log calls with SDL_LogSetOutputFunction, which would allow you to include the timestamp information that is currently shown in the log.
Use a library - There are multiple libraries out there that can do logging. For example, spdlog's default output format is similar to the one currently in the engine. The format can be even further customized. It is much more advanced than SDL_Log, but would require us to introduce another dependency in the ThirdParty folder.
Ui Elements should provide a registerCallbackFunction(std::function<void()) function.
This function should connect the cb function to a signal, that is emitted when the button is clicked.
It's enough to provide a mechanism for void() functions. If other function signatures are needed, it still can be expanded.
Currently each of the elements are checked if the pixel color is transparent at the the clicked coordinates (with camera offsets and zoomlevel taken into account and if it's not, it's iso coordinates are returned.
It takes between 2 and 3 ms to calculate the isometric coordinates at a given screen coordinate this way and this is not viable. And certainly not for getting the current mouse over iso coordinates.
First attempt to improve performance.
Check all elements for SDL_PointInRect which should be way cheaper. If a collision occurs, check for pixel-alpha collision. If it's not the correct tile, use the next one in the list.
Further investiagtion showed that the performance penalty comes from iterating through all the tiles. Find a smarter way to do this.
Add a dropdown ui element
The current engine crashes at runtime when trying to load a font. The resources/fonts
directory contains a file named ARCADECLASSIC.TTF
. Meanwhile, the uiElement class tries to load resources/fonts/arcadeclassics.ttf
. Note the difference in case (one is ALL_CAPS) and the missing "s" before the extension.
The case should be the same to avoid issues with case-sensitive operating system. In addition, the filename should be fixed, though I'm not sure which one is correct (arcadeclassic vs arcadeclassics).
Add a settings menu dialog.
The settings menu can be opened by a button in the game menu (reached by pressing the ESC key).
Maybe an attribute for the parent - children relation should be added.
Add SDL2 Libraries as git submodule to the project so Cytopia can be built without having to download any dependencies.
The README states that CMake version 3.9 is required. However, the CMakelists.txt provided in the repo uses the very old (now discouraged) style for CMake. For example, the use of include_directories instead of target_include_directories.
There will also be issues with compiling on Windows because the find_package calls are confined only to Unix-based operating systems. Ideally, find_package should be used regardless of the operating system.
There are many blog posts online if you search "modern CMake". Here is one that is well done: https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
Implement procedural terrain generations.
Use https://github.com/utilForever/PolyMapGenerator library for that.
Considerations:
Virtual functions for events should be provided by the UIElement base class, with a ref to SDL_Event as parameter:
void onMouseButtonUp(const SDL_Event &event) override;
void onMouseButtonDown(const SDL_Event &event) override;
void onMouseEnter(const SDL_Event &event) override;
void onMouseLeave(const SDL_Event &event) override;
Texture / Button states should be handled within these functions instead of an external function
Add a scaling factor (1x, 1,5x, 2x, ...) for the UI to support different resolutions.
This scaling factor should be configurable in an ui dialog in settings.
The intension behind this is, so user could double / half the size of ui elements, in case someone wants a bigger / smaller ui.
This should be independent from the ui scale that is applied when resizing the game window
The current code for initializing SDL2 is incorrect:
if ( SDL_Init(SDL_INIT_VIDEO != 0) )
{
LOG(LOG_ERROR) << "Failed to Init SDL\nSDL Error:" << SDL_GetError();
return 0;
}
I'm pretty sure you mean: if(SDL_Init(SDL_INIT_VIDEO) != 0)
. Note the bracket placement.
Add a selection mode variable (bool). If its value is true, the tile beneath the mouse cursor should change it's color to something grey-ish.
Use SDL_SetTextureColorMod() to accomplish that.
As the rendering of each mapnode is handled in the sprite object, the coloring should go there too.
Add a function to tint the textures in the mapnode class, so it could be colored via the map class or the engine class.
Currently the Point class contains getters and setters for x, y, z, and height. However, it doesn't really do anything other than store data. This is fine - but it can be simplified into simply having all public data members to avoid code bloat. For example:
struct Point {
int x;
int y;
int z;
int height;
};
I have omitted the _
prefix since these are public data members, as opposed to private ones.
You can then ensure a Point object is not modified in a function by passing it with const
. If the Point object is to be modified, then omit const
.
In the renderloop, only call the render() function for what's visible on screen to improve Performance.
Currently, the visibility of UI groups (defined in the uilayout.json file) are toggled in a seperate UI Manager functions.
With callbacks and event-functions in the ui elements, it could be done there.
Move Camera in the MOUSE_MOTION event by applying the traversed x, y coordinates while holding down the right mouse button.
Add a feature that levels the terrain by clicking (and holding) at a tile to get the source height from the node where the mousebutton down event was triggered), and then drag the mouse over to elevate the terrain beneath the cursor to the source height.
This should not create a preview but instantly elevate the neighboring tiles.
Instead of having a thread running in each timer, the timer should register itself with the EventManager class when it's constructed.
The EventManager class should have a container for timers, and update their time, if active, in each loop.
Find a name for the game and rename the repository and all files.
Add a background image to the submenu buttons.
Implement sprite animations.
Suggestions:
There is tag v0.1
.
Remove tag 0.1
or retag as v0.0.1
.
Since we have our own theme song now, add playback of music to the engine.
Add a variations key to the tileData Json file, where alternate images for the same tile ID can be specified.
When creating the terrain (floor tiles), use variations of the "ground" sprite (randomly pick one of the sprites from the variations list)
Add mouseOver and pressed parameters to the ui json file and implement the change of texture on mouse over / click
Needs #20 as prerequisite
Instead of providing a function to get a mapNodes neighbors in the map class, the (3x3) neighbors could be stored as pointers in the mapNode itself to avoid having to call the function every time neighbors need to be accessed.
It's probably not worth the effort performance wise, but it'd be cleaner this way and the responsiblity of tracking it's neighbors would go to the mapNode class.
To manage tiles, a seperate class should be added.
A Mapcell can ask the Tile class, for a tile of type "terrain". The mapclass checks the elevation bitmask of the node and returns the correct texture.
It would be good to have a tool take care of different style-related things in the code, such as indentation and spacing. clang-format can do this, and you can create a configuration online or use an existing configuration (e.g., LLVM, Google, Chromium, Mozilla, Webkit).
Once a style is decided on, you can then apply it to a file manually or with a shortcut in your IDE. Alternatively, you can create a build target that formats all files at once.
Move settings from the resources class into its own class.
The class should be responsible for
Add a class for handling layouting. Maybe different classes for specific tasks.
We need a class, that layouts the menu bar. Following requirements:
Compiling the application causes warnings for every header file with the extension .hxx. The warnings look like this:
cc1plus: warning: /home/badrmari/personal/software/IsometricEngine/src/engine/cell.hxx: not a directory
I am running Ubuntu 16.04 and using gcc version 6.4.0 with CLion 2018 v1.3 as my IDE.
Refactoring the header files to have a .hpp extension instead of .hxx takes care of the warnings. If you would like, I could submit a pull request with the change. If you agree with the change, you may also want to change cxx to cpp to be consistent, though gcc does not complain about the cxx extension.
Add checkboxes
Add a type that can display a string in multiple languages.
Language - string mappings could be stored in a json file.
Add a FPS Counter. Can be toggled via F11 Button
Add a container class for storing Buttons.
Show tooltips when hovering over a UI element that hast the attribute „Tooltip“ set in the UILayout JSON File.
vectorMatrix should be split into Map class and (if necessary) some template class or typedef for a container
Map class should handle all map related functions. (except procedural terrain generation, this should be handled in an own class)
This includes:
Point Engine::findCellAt(const Point &screenCoordinates)
Basically it should suffice to export the content of mapcell matrix to a json file an load it again.
Class design suggestion:
JSON Structure suggestion:
{
"id": "terrain",
"type": "ground",
"tiles": {
"tilemap": "resources/images/terrain/terrain_tiles.png",
"count": 3,
"clip_width": 32,
"clip_height": 16
},
"cornerTiles": {
"tilemap": "resources/images/terrain/terrain_slopes.png",
"count": 13,
"clip_width": 32,
"clip_height": 32
},
"title": "Terrain",
"description": "Terrain tiles",
"price": 0,
"upkeep cost": 0,
"power": 0,
"water": 0,
"author": "Kingtut 101",
"draw ground": false
}
The colors (active / hovered / isclicked) used for drawing certain ui shapes (like frame / button) should be configurable.
Either make that configurable in the UiLayout json per element (and use default values if no values are supplied) or a global setting for UI colors
TextureManager:
Implement map rotation.
The mapnode matrix should be rotated in 4 positions (by 90° only).
We need to rotate the iso coordinates of the mapnodes (draw the nodes to another destionation), + the nodes it self (drawing order) and then probably run updateTextures to recalculate the destRect where the nodes are drawn
I've started to work on this at this branch:
https://github.com/JimmySnails/IsometricEngine/tree/rotateMap
My approach was to rotate the whole map cell matrix, which didn't turn out the way it should have.
Add water tiles to the engine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.