Browse Source

Needs cleanup, Math macros, Blood need, Sublime build syntax

- Added Math.hpp for some very simple CLAMP, MIN, and MAX macros
- Added Blood need
- Need conditions are now evaluated by the trigger (better abstracted this way)
- Added a sublime-syntax file for my bulid output, because I like colors :)
- Added parameters for Min and Max world height to ProceduralWorld
combatComponentRefactor
Macoy Madson 6 years ago
parent
commit
4a1c44832a
  1. 11
      TODO.txt
  2. 19
      src/game/agent/AgentComponentManager.cpp
  3. 1
      src/game/agent/NeedTypes.hpp
  4. 10
      src/game/agent/Needs.cpp
  5. 18
      src/game/agent/Needs.hpp
  6. 123
      src/project/galavantSublime/JamUnrealBuildOutput.sublime-syntax
  7. 6
      src/project/galavantSublime/galavant.sublime-project
  8. 5
      src/util/Math.hpp
  9. 3
      src/world/ProceduralWorld.hpp

11
TODO.txt

@ -24,20 +24,25 @@ Some sort of resource system
Put HTN Tasks etc. in resource dictionaries? Who owns them?
Sublime "syntax" tag for build systems
Position vs GlobalPosition
As soon as possible, I need to decide if I need Chunk XYZ with Position XYZ
This depends on whether I ever want to support really large worlds
How large? I'd have to do the math (yes, the monster math)
------------------
Doing
------------------
Add player HUD UI - Only needs Minimap, Need bars
------------------
Done
------------------
Sublime "syntax" tag for build systems
Test PlanComponent event stuff
It seems to have broken things

19
src/game/agent/AgentComponentManager.cpp

@ -1,11 +1,13 @@
#include "AgentComponentManager.hpp"
#include "../../util/Logging.hpp"
#include "util/Logging.hpp"
#include "../../entityComponentSystem/PooledComponentManager.hpp"
#include "../../entityComponentSystem/ComponentTypes.hpp"
#include "../../entityComponentSystem/EntityComponentManager.hpp"
#include "../../ai/htn/HTNTaskDb.hpp"
#include "entityComponentSystem/PooledComponentManager.hpp"
#include "entityComponentSystem/ComponentTypes.hpp"
#include "entityComponentSystem/EntityComponentManager.hpp"
#include "ai/htn/HTNTaskDb.hpp"
#include "util/Math.hpp"
namespace gv
{
@ -101,6 +103,8 @@ void AgentComponentManager::Update(float deltaSeconds)
if (needUpdated)
{
CLAMP(need.Level, need.Def->MinLevel, need.Def->MaxLevel);
need.LastUpdateTime = WorldTime;
LOGV_IF(DebugPrint) << "Agent Entity " << currentEntity << " updated need "
@ -108,10 +112,7 @@ void AgentComponentManager::Update(float deltaSeconds)
for (const NeedLevelTrigger& needLevelTrigger : need.Def->LevelTriggers)
{
bool needTriggerHit =
(needLevelTrigger.GreaterThanLevel && need.Level > needLevelTrigger.Level);
if (!needTriggerHit)
if (!needLevelTrigger.ConditionsMet(need))
continue;
if (needLevelTrigger.NeedsResource && needLevelTrigger.WorldResource)

1
src/game/agent/NeedTypes.hpp

@ -7,6 +7,7 @@ enum class NeedType : unsigned int
None = 0,
Hunger,
Blood,
NeedType_Count
};

10
src/game/agent/Needs.cpp

@ -1,6 +1,16 @@
#include "Needs.hpp"
#include <cmath>
namespace gv
{
ResourceDictionary<NeedDef> g_NeedDefDictionary;
bool NeedLevelTrigger::ConditionsMet(Need& need) const
{
return (
(Condition == NeedLevelTrigger::ConditionType::Zero && fabs(need.Level) < 0.01f) ||
(Condition == NeedLevelTrigger::ConditionType::GreaterThanLevel && need.Level > Level) ||
(Condition == NeedLevelTrigger::ConditionType::LessThanLevel && need.Level < Level));
}
}

18
src/game/agent/Needs.hpp

@ -9,10 +9,20 @@
namespace gv
{
struct Need;
struct NeedLevelTrigger
{
// Conditions
bool GreaterThanLevel;
enum class ConditionType
{
None = 0,
Zero,
GreaterThanLevel,
LessThanLevel
};
ConditionType Condition;
float Level;
@ -21,6 +31,8 @@ struct NeedLevelTrigger
WorldResourceType WorldResource;
bool DieNow;
bool ConditionsMet(Need& need) const;
};
typedef std::vector<NeedLevelTrigger> NeedLevelTriggerList;
@ -31,6 +43,10 @@ struct NeedDef
const char* Name;
float InitialLevel;
float MaxLevel;
float MinLevel;
float UpdateRate;
float AddPerUpdate;

123
src/project/galavantSublime/JamUnrealBuildOutput.sublime-syntax

@ -0,0 +1,123 @@
%YAML 1.2
---
name: JamUnrealBuildOutput
file_extensions: [JamUnrealBuildOut]
scope: source.jamunrealbuildout
# To install
# 1. Preferences -> Browse Packages -> User
# 2. Open any JamUnrealBuildout
# 3. Go to View -> Syntax -> Open all with current extension as... -> JamUnrealBuildout (or User -> JamUnrealBuildout)
contexts:
main:
- include: comments
- include: numbers
- include: operators
- include: strings
# Expression control functions
- match: \b(if|else|for|while|endif|elif)\b
scope: keyword.control.jamunrealbuildout
- match: \b(and|in|is|not|or)\b
comment: keyword operators that evaluate to True or False
scope: keyword.operator.logical.jamunrealbuildout
# Expression constants
- match: \b(True|False|true|false)\b
scope: constant.language.jamunrealbuildout
# Operations
- match: \b(Lib|Link|Initializing|Done|mono|found|updating|Clean|updated|Chmod1|C++|Archive|Ranlib|Compile|Using|Performing|make)\b
scope: keyword.control.jamunrealbuildout
# Keywords
- match: \b(clang|undefined|target|Makefile|expected|unknown|type|expression|unused|seconds)\b
scope: storage.type.class.jamunrealbuildout
# Errors
- match: \b(error|warning|Error|Warning|failed|errors)\b
scope: invalid.jamunrealbuildout
comments:
- match: "#"
scope: punctuation.definition.comment.jamunrealbuildout
push:
- meta_scope: comment.line.number-sign.jamunrealbuildout
- match: \n
pop: true
# Copied from Python.sublime-syntax
numbers:
- match: \b(?i:(0x\h*)L)
scope: constant.numeric.integer.long.hexadecimal.jamunrealbuildout
- match: \b(?i:(0x\h*))
scope: constant.numeric.integer.hexadecimal.jamunrealbuildout
- match: '\b(?i:(0[0-7]+)L)'
scope: constant.numeric.integer.long.octal.jamunrealbuildout
- match: '\b(0[0-7]+)'
scope: constant.numeric.integer.octal.jamunrealbuildout
- match: '\b(?i:(((\d+(\.(?=[^a-zA-Z_])\d*)?|\.\d+)(e[\-\+]?\d+)?))J)'
scope: constant.numeric.complex.jamunrealbuildout
- match: '\b(?i:(\d+\.\d*(e[\-\+]?\d+)?))(?=[^a-zA-Z_])'
scope: constant.numeric.float.jamunrealbuildout
- match: '(?i:(\.\d+(e[\-\+]?\d+)?))'
scope: constant.numeric.float.jamunrealbuildout
- match: '\b(?i:(\d+e[\-\+]?\d+))'
scope: constant.numeric.float.jamunrealbuildout
- match: '\b(?i:([1-9]+[0-9]*|0)L)'
scope: constant.numeric.integer.long.decimal.jamunrealbuildout
- match: '\b([1-9]+[0-9]*|0)'
scope: constant.numeric.integer.decimal.jamunrealbuildout
# Copied from Python.sublime-syntax
operators:
- match: <>
scope: invalid.deprecated.operator.jamunrealbuildout
- match: <\=|>\=|\=\=|<|>|\!\=
scope: keyword.operator.comparison.jamunrealbuildout
- match: \+\=|-\=|\*\=|/\=|//\=|%\=|&\=|\|\=|\^\=|>>\=|<<\=|\*\*\=
scope: keyword.operator.assignment.augmented.jamunrealbuildout
- match: \+|\-|\*|\*\*|/|//|%|<<|>>|&|\||\^|~
scope: keyword.operator.arithmetic.jamunrealbuildout
- match: \=
scope: keyword.operator.assignment.jamunrealbuildout
# Copied from Python.sublime-syntax
strings:
- match: '([uU]?)([\"\[])'
captures:
1: storage.type.string.jamunrealbuildout
2: punctuation.definition.string.begin.jamunrealbuildout
push:
- meta_scope: string.quoted.double.block.jamunrealbuildout
- match: '([\"\]])|(\n)'
captures:
1: punctuation.definition.string.end.jamunrealbuildout
2: invalid.illegal.unclosed-string.jamunrealbuildout
pop: true
- include: escaped_unicode_char
- include: escaped_char
- include: constant_placeholder
# Copied from Python.sublime-syntax
escaped_unicode_char:
- match: '(\\U\h{8})|(\\u\h{4})|(\\N\{[a-zA-Z ]+\})'
captures:
1: constant.character.escape.unicode.16-bit-hex.jamunrealbuildout
2: constant.character.escape.unicode.32-bit-hex.jamunrealbuildout
3: constant.character.escape.unicode.name.jamunrealbuildout
# Copied from Python.sublime-syntax
escaped_char:
- match: '(\\x\h{2})|(\\[0-7]{3})|(\\[\\"''abfnrtv])'
captures:
1: constant.character.escape.hex.jamunrealbuildout
2: constant.character.escape.octal.jamunrealbuildout
3: constant.character.escape.jamunrealbuildout
# Copied from Python.sublime-syntax
constant_placeholder:
- match: '(?i:(%(\([a-z_]+\))?#?0?\-?[ ]?\+?([0-9]*|\*)(\.([0-9]*|\*))?[hL]?[a-z%])|(\{([!\[\].:\w ]+)?\}))'
scope: constant.other.placeholder.jamunrealbuildout

6
src/project/galavantSublime/galavant.sublime-project

@ -63,6 +63,7 @@
"shell_cmd": "cd galavant && jam -j4 -q -sUNREAL=true GalavantPseudotarget && cd ../galavant-unreal/GalavantUnreal && make GalavantUnreal",
"working_dir": "$project_path/../../../..",
"file_regex": "^([a-zA-Z\/][^:\n]*):([0-9]+):?([0-9]+)?:? (.*)$",
"syntax":"JamUnrealBuildOutput.sublime-syntax"
},
// Unreal
@ -71,6 +72,7 @@
"shell_cmd": "make GalavantUnreal",
"working_dir": "$project_path/../../../../galavant-unreal/GalavantUnreal",
"file_regex": "^([a-zA-Z\/][^:\n]*):([0-9]+):?([0-9]+)?:? (.*)$",
"syntax":"JamUnrealBuildOutput.sublime-syntax"
},
{
@ -90,24 +92,28 @@
"name": "Jam Current Directory",
"shell_cmd": "jam -j4 -q",
"file_regex": "^([a-zA-Z\/][^:\n]*):([0-9]+):?([0-9]+)?:? (.*)$",
"syntax":"JamUnrealBuildOutput.sublime-syntax"
},
{
"name": "Jam Clean All",
"shell_cmd": "jam clean",
"working_dir": "$project_path/../../..",
"file_regex": "^([a-zA-Z\/][^:\n]*):([0-9]+):?([0-9]+)?:? (.*)$",
"syntax":"JamUnrealBuildOutput.sublime-syntax"
},
{
"name": "Jam Build (not Unreal)",
"shell_cmd": "jam -j4 -q",
"working_dir": "$project_path/../../..",
"file_regex": "^([a-zA-Z\/][^:\n]*):([0-9]+):?([0-9]+)?:? (.*)$",
"syntax":"JamUnrealBuildOutput.sublime-syntax"
},
{
"name": "Jam Build Unreal",
"shell_cmd": "jam -j4 -q -sUNREAL=true GalavantPseudotarget",
"working_dir": "$project_path/../../..",
"file_regex": "^([a-zA-Z\/][^:\n]*):([0-9]+):?([0-9]+)?:? (.*)$",
"syntax":"JamUnrealBuildOutput.sublime-syntax"
},
// Misc. C++ Commands

5
src/util/Math.hpp

@ -0,0 +1,5 @@
#pragma once
#define CLAMP(value, min, max) if (value > max) value = max; else if (value < min) value = min;
#define MIN(a, b) a <= b ? a : b;
#define MAX(a, b) a >= b ? a : b;

3
src/world/ProceduralWorld.hpp

@ -19,6 +19,9 @@ struct ProceduralWorldParams
// The size of a single 3D tile.
float WorldCellTileSize[3];
float WorldCellMaxHeight;
float WorldCellMinHeight;
};
ProceduralWorldParams& GetActiveWorldParams();

Loading…
Cancel
Save